libre-webui 0.8.5 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frontend/dist/assets/index-B1qNw5pA.js +52 -0
- package/frontend/dist/assets/index-DnG6512Q.css +1 -0
- package/frontend/dist/assets/ui-CsNe6lFV.css +1 -0
- package/frontend/dist/index.html +15 -6
- package/frontend/dist/js/ArtifactContainer-Com7P5vK.js +24 -0
- package/frontend/dist/js/ArtifactDemoPage-Xd-Ragpf.js +98 -0
- package/frontend/dist/js/Button-D62PCbMW.js +1 -0
- package/frontend/dist/js/ChatPage-01JxVHRP.js +15 -0
- package/frontend/dist/js/GalleryPage-8nHGqKEu.js +1 -0
- package/frontend/dist/js/ModelsPage-C0MLVfwA.js +1 -0
- package/frontend/dist/js/OptimizedSyntaxHighlighter-DjnSqskO.js +1 -0
- package/frontend/dist/js/PersonasPage-D9YKnYz6.js +13 -0
- package/frontend/dist/js/UserManagementPage-b6NZdPTD.js +1 -0
- package/frontend/dist/js/api-B0pf9vdR.js +1 -0
- package/frontend/dist/js/api-BrzQvj_g.js +3 -0
- package/frontend/dist/js/appStore-k_e3JAM3.js +2 -0
- package/frontend/dist/js/authStore-BkobbhZS.js +1 -0
- package/frontend/dist/js/authStore-ge66S03D.js +2 -0
- package/frontend/dist/js/axios-CYrHjdt1.js +1 -0
- package/frontend/dist/js/demoMode-qyEGd_UM.js +1 -0
- package/frontend/dist/js/markdown-vendor-4lCPqxk5.js +22 -0
- package/frontend/dist/js/react-vendor-BUzyfgnZ.js +8 -0
- package/frontend/dist/js/rolldown-runtime-DWy-cpC1.js +1 -0
- package/frontend/dist/js/ui-DuH1cD2f.js +267 -0
- package/frontend/dist/js/ui-vendor-BFOABH-A.js +177 -0
- package/frontend/dist/js/userService-BndgbS1C.js +1 -0
- package/frontend/dist/js/utils-vendor-MBozwMfr.js +6 -0
- package/package.json +5 -5
- package/frontend/dist/assets/index-fnpCaKr_.js +0 -51
- package/frontend/dist/css/index-WfujIMhR.css +0 -1
- package/frontend/dist/js/ArtifactContainer-CW_iHjsN.js +0 -24
- package/frontend/dist/js/ArtifactDemoPage-DkERDKtR.js +0 -98
- package/frontend/dist/js/ChatPage-D9dmPf4t.js +0 -281
- package/frontend/dist/js/GalleryPage-xkvacK1Y.js +0 -1
- package/frontend/dist/js/ModelsPage-CwUkhy1d.js +0 -1
- package/frontend/dist/js/PersonasPage-R8wVg6rE.js +0 -13
- package/frontend/dist/js/UserManagementPage-BbST0j99.js +0 -1
- package/frontend/dist/js/markdown-vendor-B0lXrrRZ.js +0 -22
- package/frontend/dist/js/react-vendor-l0sNRNKZ.js +0 -1
- package/frontend/dist/js/router-vendor-DdQhGl5t.js +0 -10
- package/frontend/dist/js/ui-vendor-C4ZcWovR.js +0 -177
- package/frontend/dist/js/utils-vendor-BFlGJDIj.js +0 -6
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-DWy-cpC1.js";import{m as t,p as n}from"./markdown-vendor-4lCPqxk5.js";import{n as r}from"./react-vendor-BUzyfgnZ.js";import{n as i,t as a}from"./Button-D62PCbMW.js";import{A as o,At as s,Dt as c,E as l,H as u,I as d,J as f,L as p,M as m,Mt as h,N as g,O as _,Ot as v,Pt as y,Q as b,Rt as x,S,T as C,Tt as w,U as T,X as E,_t as D,a as O,bt as k,c as A,ct as j,et as M,g as N,gt as P,ht as F,i as I,it as ee,jt as te,n as L,o as ne,p as R,pt as z,q as B,r as V,rt as re,st as ie,t as H,v as ae,vt as oe,w as se,wt as ce,x as le,xt as ue,yt as de,zt as U}from"./ui-vendor-BFOABH-A.js";import{a as fe,i as pe,n as W,r as me,t as G}from"./appStore-k_e3JAM3.js";import{c as he,l as ge,s as _e}from"./ui-DuH1cD2f.js";import{a as ve,c as ye,d as be,i as xe,o as Se,r as K,s as Ce}from"./api-BrzQvj_g.js";import{n as q,r as J,t as we}from"./authStore-ge66S03D.js";import{a as Y,i as Te,r as Ee}from"../assets/index-B1qNw5pA.js";import{t as X}from"./ArtifactContainer-Com7P5vK.js";var De=e(r(),1),Z=e(t(),1),Q=n(),Oe=({statistics:e,className:t=``})=>{let[n,r]=(0,Z.useState)(!1),{t:a}=i(),o=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},s=e=>e?`${e.toFixed(1)} t/s`:`N/A`,l=e.prompt_eval_count||0,u=e.eval_count||0,d=l+u,f=o(e.total_duration),p=s(e.tokens_per_second);return(0,Q.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,Q.jsx)(B,{size:12,className:`text-primary-500`}),u,` tokens`]}),(0,Q.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:p}),(0,Q.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),e.model&&(0,Q.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,Q.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,Q.jsx)(c,{size:12}):(0,Q.jsx)(w,{size:12}),(0,Q.jsx)(`span`,{children:a(`generationStats.details`)})]}),n&&(0,Q.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.promptTokens`)}),` `,l]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.generatedTokens`)}),` `,u]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.totalTokens`)}),` `,d]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.speed`)}),` `,p]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.promptEval`)}),` `,o(e.prompt_eval_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.generation`)}),` `,o(e.eval_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.modelLoad`)}),` `,o(e.load_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.totalTime`)}),` `,f]})]}),e.created_at&&(0,Q.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:a(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},ke=null,Ae=null,$=0,je=300*1e3;async function Me(){let e=Date.now();return ke!==null&&e-$<je?ke:Ae||(Ae=(async()=>{try{let t=await be.getModels();return t.success&&t.data&&t.data.length>0?(ke=t.data,$=e,t.data):(ke=[],$=e,[])}catch{return ke=[],$=e,[]}finally{Ae=null}})(),Ae)}function Ne(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Pe=({text:e,className:t,size:n=`sm`})=>{let{t:r}=i(),{preferences:a}=G(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)([]),[m,h]=(0,Z.useState)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(!1),v=(0,Z.useRef)([]),y=(0,Z.useRef)(0);(0,Z.useEffect)(()=>{let e=!0;return Me().then(t=>{e&&(p(t),h(t.length>0))}),()=>{e=!1}},[]);let b=(0,Z.useCallback)(async(e,t,n,i)=>{let a=await be.generateBase64({model:t,input:e,voice:n,speed:i,response_format:`mp3`});if(!a.success||!a.data?.audio)throw Error(a.message||r(`ttsButton.generateFailed`));let o=`data:${a.data.mimeType};base64,${a.data.audio}`,s=new Audio(o);return g.current=s,new Promise((e,t)=>{s.onended=()=>{g.current=null,e()},s.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},s.play().catch(t)})},[r]),x=(0,Z.useCallback)(async(e,t,n,r)=>{v.current=e,y.current=0,_.current=!1;let i=null,a=async e=>{try{let i=await be.generateBase64({model:t,input:e,voice:n,speed:r,response_format:`mp3`});return!i.success||!i.data?.audio?null:{audioUrl:`data:${i.data.mimeType};base64,${i.data.audio}`,mimeType:i.data.mimeType}}catch{return null}};e.length>0&&(i=a(e[0]));for(let t=0;t<e.length&&!_.current;t++){y.current=t;try{let n=await i;if(_.current)break;if(i=t+1<e.length?a(e[t+1]):null,!n){console.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);g.current=r,await new Promise((e,t)=>{r.onended=()=>{g.current=null,e()},r.onerror=()=>{g.current=null,e()},r.play().catch(()=>{e()})})}catch(e){console.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Z.useCallback)(()=>{_.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),s(!1),l(!1)},[]),C=async()=>{if(!c){if(o){S();return}l(!0),d(null),_.current=!1;try{let t=a.ttsSettings,n=t?.model||f[0]?.model||`tts-1`,i=t?.voice||f[0]?.config?.default_voice||`alloy`,o=t?.speed||1;if(t?.streamSentences){let t=Ne(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));l(!1),s(!0),await x(t,n,i,o),_.current||s(!1)}else await b(e,n,i,o),l(!1),s(!0),g.current&&(g.current.onended=()=>{s(!1),g.current=null},g.current.onerror=()=>{d(r(`ttsButton.playbackFailed`)),s(!1),g.current=null})}catch(e){d(e instanceof Error?e.message:r(`ttsButton.generateFailed`)),console.error(`TTS error:`,e),s(!1),l(!1)}}};if((0,Z.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},E={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,Q.jsx)(`button`,{onClick:C,disabled:c||!e,title:u||r(o?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:W(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,u?`text-red-500 dark:text-red-400`:o?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,w[n],t),children:c?(0,Q.jsx)(T,{className:W(E[n],`animate-spin`)}):o?(0,Q.jsx)(N,{className:E[n]}):u?(0,Q.jsx)(I,{className:E[n]}):(0,Q.jsx)(O,{className:E[n]})})},Fe=[{regex:/```html\s*\n([\s\S]*?)\n```/gi,type:`html`,getTitle:e=>Re(e)||`HTML Document`},{regex:/```svg\s*\n([\s\S]*?)\n```/gi,type:`svg`,getTitle:e=>`SVG Image`},{regex:/```(?:react|jsx)\s*\n([\s\S]*?)\n```/gi,type:`react`,getTitle:e=>ze(e)||`React Component`},{regex:/```json\s*\n([\s\S]*?)\n```/gi,type:`json`,getTitle:e=>`JSON Data`},{regex:/```python\s*\n([\s\S]*?)\n```/gi,type:`code`,language:`python`,getTitle:e=>Be(e)||`Python Code`},{regex:/```(?:javascript|js)\s*\n([\s\S]*?)\n```/gi,type:`code`,language:`javascript`,getTitle:e=>Ve(e)||`JavaScript Code`},{regex:/```css\s*\n([\s\S]*?)\n```/gi,type:`code`,language:`css`,getTitle:e=>`CSS Styles`},{regex:/```(\w+)\s*\n([\s\S]*?)\n```/gi,type:`code`,getTitle:(e,t)=>`${t.toUpperCase()} Code`}],Ie=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:e[1],title:e[2],content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:e[1],title:`${e[1].toUpperCase()} Artifact`,content:e[2].trim()})}];function Le(e){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}function Re(e){let t=e.match(/<title[^>]*>(.*?)<\/title>/i);if(t)return Le(t[1]).trim();let n=e.match(/<h1[^>]*>(.*?)<\/h1>/i);return n?Le(n[1]).trim():null}function ze(e){let t=e.match(/(?:function|const)\s+(\w+)/);if(t)return t[1];let n=e.match(/class\s+(\w+)/);return n?n[1]:null}function Be(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function Ve(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function He(e,t){if(t===`html`)return/<[^>]+>/.test(e)&&e.trim().length>200;if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Z][^>]*>/.test(e)||/return\s*\(/.test(e);if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
|
|
2
|
+
`).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return!1}function Ue(e){let t=[],n=e;for(let e of Ie){let r;for(;(r=e.regex.exec(n))!==null;){let i=e.extract(r);if(He(i.content,i.type)){let e={id:`artifact-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,type:i.type,title:i.title,content:i.content,createdAt:Date.now(),updatedAt:Date.now()};t.push(e),n=n.replace(r[0],``)}}}for(let e of Fe){let r;for(e.regex.lastIndex=0;(r=e.regex.exec(n))!==null;){let i=r[1]||r[2],a=e.language||(r[1]&&r[2]?r[1]:void 0);if(He(i,e.type)){let o={id:`artifact-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,type:e.type,title:e.getTitle(i,a||`code`),content:i,language:a,createdAt:Date.now(),updatedAt:Date.now()};t.push(o),n=n.replace(r[0],``)}}}return{content:n.trim(),artifacts:t}}var We=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:a})=>{let{t:o}=i(),u=e.role===`user`,d=e.role===`system`,{preferences:f}=G(),{user:p}=we(),{setSystemMessage:h,getCurrentPersona:g}=J(),y=g(),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(e.content),[w,T]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(e.content),[A,j]=(0,Z.useState)(!1),[M,N]=(0,Z.useState)(e.artifacts||[]),[P,F]=(0,Z.useState)(null),[I,ee]=(0,Z.useState)(!1),[te,R]=(0,Z.useState)(!1),[z,B]=(0,Z.useState)(!1),V=(0,Z.useRef)(null),re=(0,Z.useRef)(t),ie=(0,Z.useRef)(!1),H=async()=>{try{await navigator.clipboard.writeText(e.content),B(!0),setTimeout(()=>B(!1),2e3)}catch(e){console.error(`Failed to copy message:`,e)}};(0,Z.useEffect)(()=>{if(!u&&!d&&e.content){let n=fe(e.content);F(n.thinking);let r=n.content;if(e.artifacts&&e.artifacts.length>0)k(r),N(e.artifacts);else if(t)k(r),N([]);else{let e=Ue(r);k(e.content),N(e.artifacts)}}},[e.content,e.artifacts,u,d,t]),(0,Z.useEffect)(()=>{if(!u&&!d&&e.content&&!t){let t=fe(e.content);F(t.thinking);let n=t.content;if(!e.artifacts||e.artifacts.length===0){let e=Ue(n);k(e.content),N(e.artifacts)}}},[t,e.content,e.artifacts,u,d]),(0,Z.useEffect)(()=>{let e=re.current&&!t;return re.current=t,e&&!ie.current&&!u&&!d&&O&&f.ttsSettings?.enabled&&f.ttsSettings?.autoPlay&&(ie.current=!0,(async()=>{R(!0);try{let e=await be.generateBase64({model:f.ttsSettings?.model||`tts-1`,input:O,voice:f.ttsSettings?.voice||`alloy`,speed:f.ttsSettings?.speed||1,response_format:`mp3`});if(e.success&&e.data?.audio){let t=`data:${e.data.mimeType};base64,${e.data.audio}`,n=new Audio(t);V.current=n,n.onended=()=>{R(!1),V.current=null},n.onerror=()=>{R(!1),V.current=null},await n.play()}}catch(e){console.error(`Auto-play TTS failed:`,e),R(!1)}})()),()=>{V.current&&(V.current.pause(),V.current=null)}},[t,u,d,O,f.ttsSettings]);let ae=()=>d?o(`chatMessage.system`):u?f.showUsername&&p?.username?p.username:o(`chatMessage.you`):y?.name?y.name:e.model||o(`chatMessage.assistant`),se=()=>{x(!0),C(e.content)},ue=async()=>{D(!0);try{h(S),x(!1),console.log(`✅ System message updated:`,S)}catch(e){console.error(`Failed to save system message:`,e)}finally{D(!1)}},de=()=>{x(!1),C(e.content)},U=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,pe=d&&e.content.length>100;return(0,Q.jsxs)(`div`,{className:W(`flex transition-colors group my-2`,u?`justify-end`:`justify-start`,n),children:[(0,Q.jsxs)(`div`,{className:W(`flex gap-3 sm:gap-4`,u?`flex-row-reverse max-w-[85%] sm:max-w-[75%]`:d?`w-full`:`max-w-[85%] sm:max-w-[75%]`),children:[!d&&(0,Q.jsx)(`div`,{className:W(`flex shrink-0 items-center justify-center shadow-sm overflow-hidden mt-1`,u?`h-8 w-8 rounded-full bg-primary-600 ophelia:bg-[#9333ea] text-white`:y?.avatar?`h-8 w-8 rounded-full bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]`:`h-8 px-2 rounded-full bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]`),children:u?p?.avatar?(0,Q.jsx)(`img`,{src:p.avatar,alt:p.username,className:`w-full h-full object-cover`}):(0,Q.jsx)(ne,{className:`h-4 w-4`}):y?.avatar?(0,Q.jsx)(`img`,{src:y.avatar,alt:y.name||`Assistant`,className:`w-full h-full object-cover`}):(0,Q.jsx)(`span`,{className:`libre-brand text-xs text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5]`,children:`Libre`})}),(0,Q.jsxs)(`div`,{className:W(`flex-1 min-w-0 rounded-2xl sm:rounded-3xl p-4 sm:p-5`,u?`bg-primary-600/90 dark:bg-primary-700/90 ophelia:bg-[#9333ea]/90 text-white`:d?`bg-transparent p-2 py-3`:`bg-white/95 dark:bg-dark-100/95 ophelia:bg-[#0a0a0a]/95 backdrop-blur-md shadow-sm border border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/60`),children:[!d&&(0,Q.jsxs)(`div`,{className:W(`flex items-center gap-3 mb-2`,u&&`flex-row-reverse`),children:[(0,Q.jsx)(`span`,{className:W(`text-sm font-semibold`,u?`text-white/90`:`text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`),children:ae()}),e.model&&!u&&y?.name&&(0,Q.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-dark-600 ophelia:text-[#737373] bg-gray-100 dark:bg-dark-200 ophelia:bg-[#121212] px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model}),(0,Q.jsx)(`span`,{className:W(`text-xs`,u?`text-white/60`:`text-gray-400 dark:text-dark-500 ophelia:text-[#525252]`),children:me(e.timestamp)}),!u&&!d&&!t&&O&&(0,Q.jsx)(Pe,{text:O,size:`sm`,className:W(`transition-opacity`,te?`opacity-100 text-primary-600 dark:text-primary-400`:`opacity-0 group-hover:opacity-100`)}),!d&&!t&&(0,Q.jsx)(`button`,{onClick:H,className:`p-1 rounded hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(147,51,234,0.2)] transition-opacity opacity-0 group-hover:opacity-100`,title:o(z?`chatMessage.copied`:`chatMessage.copyMessage`),children:z?(0,Q.jsx)(v,{className:`h-3.5 w-3.5 text-green-500 dark:text-green-400`}):(0,Q.jsx)(oe,{className:`h-3.5 w-3.5 text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]`})}),!u&&!d&&!t&&r&&a&&(0,Q.jsx)(`button`,{onClick:a,className:`p-1 rounded hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(147,51,234,0.2)] transition-opacity opacity-0 group-hover:opacity-100`,title:o(`chatMessage.regenerateResponse`),children:(0,Q.jsx)(_,{className:`h-3.5 w-3.5 text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]`})})]}),(0,Q.jsxs)(`div`,{className:W(u?`text-white`:`text-gray-700 dark:text-dark-700 ophelia:text-[#e5e5e5]`),children:[e.images&&e.images.length>0&&(0,Q.jsx)(`div`,{className:`mb-3 grid grid-cols-2 sm:grid-cols-3 gap-2 max-w-lg`,children:e.images.map((e,t)=>(0,Q.jsx)(`div`,{className:`aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:(0,Q.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>T(e)})},t))}),u?(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap leading-relaxed`,children:e.content}):d?(0,Q.jsxs)(`div`,{className:`bg-gray-50/30 dark:bg-dark-50/30 ophelia:bg-[rgba(5,5,5,0.8)] rounded-md p-2 border border-gray-100/50 dark:border-dark-200/50 ophelia:border-[rgba(26,26,26,0.5)] relative z-0`,children:[(0,Q.jsxs)(`div`,{className:`text-xs font-medium mb-1 text-gray-500 dark:text-gray-400 ophelia:text-[#737373] flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(le,{className:`h-2.5 w-2.5 opacity-50`}),o(`chatMessage.system`)]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:b?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:ue,disabled:E,className:`p-1 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(147,51,234,0.2)] rounded transition-colors disabled:opacity-50`,title:o(`chatMessage.saveChanges`),children:(0,Q.jsx)(l,{className:`h-3 w-3 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]`})}),(0,Q.jsx)(`button`,{onClick:de,disabled:E,className:`p-1 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(239,68,68,0.15)] rounded transition-colors disabled:opacity-50`,title:o(`chatMessage.cancelEditing`),children:(0,Q.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400 ophelia:text-[#f87171]`})})]}):(0,Q.jsx)(`button`,{onClick:se,className:`p-1 hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[rgba(147,51,234,0.2)] rounded transition-colors`,title:o(`chatMessage.editSystemMessage`),children:(0,Q.jsx)(m,{className:`h-3 w-3 text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] ophelia:hover:text-[#c084fc]`})})})]}),b?(0,Q.jsx)(`textarea`,{value:S,onChange:e=>C(e.target.value),className:`w-full min-h-[100px] p-3 text-sm text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] bg-gray-50 dark:bg-dark-50 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-primary-500 dark:focus:ring-primary-400 ophelia:focus:ring-[#a855f7] focus:border-transparent`,placeholder:o(`chatMessage.systemMessagePlaceholder`),disabled:E}):(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap leading-relaxed text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]`,children:A?e.content:U(e.content)}),pe&&(0,Q.jsx)(`button`,{onClick:()=>j(!A),className:`mt-1 flex items-center gap-1 text-xs text-gray-400 dark:text-gray-500 ophelia:text-[#737373] hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#c084fc] transition-colors`,children:A?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ce,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(c,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,Q.jsxs)(`div`,{className:`relative`,children:[P&&(0,Q.jsxs)(`div`,{className:`mb-3`,children:[(0,Q.jsxs)(`button`,{onClick:()=>ee(!I),className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#c084fc] transition-colors`,children:[(0,Q.jsx)(s,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:o(`chatMessage.thinking`)}),I?(0,Q.jsx)(ce,{className:`h-4 w-4`}):(0,Q.jsx)(c,{className:`h-4 w-4`})]}),I&&(0,Q.jsx)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 ophelia:bg-[#0a0a0a] rounded-lg border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`,children:(0,Q.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-300 ophelia:text-[#a3a3a3] whitespace-pre-wrap leading-relaxed`,children:P})})]}),(0,Q.jsx)(_e,{content:O}),t&&(0,Q.jsx)(`div`,{className:`inline-block w-2 h-5 bg-primary-500 animate-pulse ml-1 rounded-sm`})]}),!u&&!d&&M.length>0&&(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(X,{artifacts:M})}),!u&&!d&&e.statistics&&(0,Q.jsx)(`div`,{className:`mt-3`,children:(0,Q.jsx)(Oe,{statistics:e.statistics})})]})]})]}),w&&(0,De.createPortal)((0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm`,onClick:()=>T(null),children:[(0,Q.jsx)(`button`,{className:`absolute top-6 right-6 p-3 bg-white/20 hover:bg-white/40 rounded-full text-white transition-all shadow-lg border border-white/30`,onClick:e=>{e.stopPropagation(),T(null)},children:(0,Q.jsx)(L,{className:`h-7 w-7`})}),(0,Q.jsx)(`img`,{src:w,alt:o(`chatMessage.fullSizeImage`),className:`max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Ge=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingMessageId:r,isLastAssistantMessage:i=!1,onRegenerate:a,onSelectBranch:o,className:s})=>{if(e.length===1){let o=e[0],c=t&&r===o.id;return(0,Q.jsx)(We,{message:c&&n?{...o,content:n}:o,isStreaming:c,isLastAssistantMessage:i,onRegenerate:a,className:s})}return(0,Q.jsxs)(`div`,{className:W(`relative py-1`,s),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 pb-2 text-[10px] text-gray-400 dark:text-gray-500 ophelia:text-[#525252]`,children:[(0,Q.jsx)(re,{className:`h-3 w-3`}),(0,Q.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 px-4`,children:e.map((e,s)=>{let c=e.isActive!==!1,l=t&&r===e.id,u=l&&n?{...e,content:n}:e;return(0,Q.jsxs)(`div`,{className:W(`relative rounded-lg overflow-hidden transition-all duration-200`,`border shadow-sm`,c||l?`border-primary-300 dark:border-primary-600 ophelia:border-[#7c3aed] shadow-primary-100 dark:shadow-primary-900/20 ophelia:shadow-[#9333ea]/10`:`border-gray-200 dark:border-dark-300 ophelia:border-[#262626] hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#3f3f46]`,!c&&!l&&`cursor-pointer hover:shadow-md`),onClick:()=>!c&&!l&&o?.(e.id),children:[(0,Q.jsxs)(`div`,{className:W(`flex items-center justify-between px-2.5 py-1 text-[11px]`,c||l?`bg-primary-50/80 dark:bg-primary-900/20 ophelia:bg-[#9333ea]/10 text-primary-600 dark:text-primary-400 ophelia:text-[#c084fc]`:`bg-gray-50/80 dark:bg-dark-100/80 ophelia:bg-[#121212]/80 text-gray-500 dark:text-gray-500 ophelia:text-[#737373]`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:s+1}),l&&(0,Q.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),c&&!l&&(0,Q.jsx)(v,{className:`h-3 w-3`}),!c&&!l&&(0,Q.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,Q.jsx)(`div`,{className:W(`bg-white dark:bg-dark-50 ophelia:bg-[#0a0a0a]`,!c&&!l&&`opacity-80`),children:(0,Q.jsx)(We,{message:u,isStreaming:l,isLastAssistantMessage:i&&(c||l),onRegenerate:c&&!t?a:void 0,className:`!bg-transparent !p-3 !text-sm`})})]},e.id)})})]})},Ke={web_search:C,web_fetch:M,exec:R,browser:M,Read:j,Write:j,Edit:j,image:f,memory_search:P,memory_get:P,working:V,thinking:V,default:V},qe={web_search:`Searching the web`,web_fetch:`Fetching page`,exec:`Running command`,browser:`Using browser`,Read:`Reading file`,Write:`Writing file`,Edit:`Editing file`,image:`Analyzing image`,memory_search:`Searching memory`,memory_get:`Reading memory`,cron:`Managing schedule`,message:`Sending message`,tts:`Generating speech`,nodes:`Checking devices`,sessions_spawn:`Spawning agent`,canvas:`Rendering canvas`,process:`Managing process`,working:`Using tools`,thinking:`Thinking`},Je=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,Q.jsx)(`div`,{className:W(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Ke[e.name]||Ke.default,n=qe[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,Q.jsxs)(`div`,{className:W(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 ophelia:text-[#22c55e] opacity-60`:`text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]`),children:[(0,Q.jsx)(`div`,{className:W(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,Q.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,Q.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})},Ye=({messages:e,streamingMessage:t,streamingMessageId:n,isStreaming:r=!1,toolActivities:a=[],className:o,onRegenerate:s,onSelectBranch:c})=>{let{t:l}=i(),u=(0,Z.useRef)(null),d=(0,Z.useRef)(),f=(0,Z.useRef)(null),p=(0,Z.useRef)(!1),[m,h]=(0,Z.useState)(!1),g=(0,Z.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),_=(0,Z.useCallback)((e=!1)=>{p.current&&!e||u.current?.scrollIntoView({behavior:`smooth`})},[]),v=(0,Z.useCallback)(()=>{let t=f.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i<100;p.current=!a,h(!a&&e.length>0)},[e.length]),b=(0,Z.useRef)(e.length);if((0,Z.useEffect)(()=>{e.length>b.current&&!p.current&&_(),b.current=e.length},[e.length,_]),(0,Z.useEffect)(()=>{r&&t&&!p.current&&requestAnimationFrame(()=>{let e=f.current;e&&(e.scrollTop=e.scrollHeight)})},[r,t]),(0,Z.useEffect)(()=>{let e=d.current;return()=>{e&&clearTimeout(e)}},[]),e.length===0&&!r)return(0,Q.jsx)(`div`,{className:W(`flex-1 flex items-center justify-center p-4 sm:p-8`,o),children:(0,Q.jsxs)(`div`,{className:`text-center text-gray-500 dark:text-dark-600 max-w-md`,children:[(0,Q.jsx)(`div`,{className:`text-5xl sm:text-7xl mb-4 sm:mb-6 opacity-60`,children:`💬`}),(0,Q.jsx)(`h3`,{className:`text-lg sm:text-xl font-semibold mb-2 sm:mb-3 text-gray-700 dark:text-dark-700`,children:l(`chatMessage.startConversation`)}),(0,Q.jsx)(`p`,{className:`text-sm leading-relaxed px-4`,children:l(`chatMessage.startConversationDescription`)})]})});let x=-1;for(let e=g.length-1;e>=0;e--)if(g[e].messages.some(e=>e.role===`assistant`)){x=e;break}return(0,Q.jsxs)(`div`,{ref:f,onScroll:v,className:W(`relative flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`,o),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`,WebkitAppRegion:`no-drag`},children:[(0,Q.jsxs)(`div`,{className:`max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full min-w-0`,children:[g.map((e,i)=>{let a=i===x,o=r&&e.messages.some(e=>e.id===n);if(e.messages.length===1){let o=e.messages[0],c=r&&o.id===n;return(0,Q.jsx)(We,{message:c&&t?{...o,content:t}:o,isStreaming:c,isLastAssistantMessage:a,onRegenerate:a?s:void 0,className:i===0?`mt-3 sm:mt-4 md:mt-6`:``},o.id)}return(0,Q.jsx)(Ge,{messages:e.messages,isStreaming:o,streamingMessage:t,streamingMessageId:n||void 0,isLastAssistantMessage:a,onRegenerate:a?s:void 0,onSelectBranch:c,className:i===0?`mt-3 sm:mt-4 md:mt-6`:``},e.id)}),r&&a.length>0&&(0,Q.jsx)(Je,{tools:a,className:`ml-10 sm:ml-12`}),(0,Q.jsx)(`div`,{ref:u,className:`h-3 sm:h-4 md:h-6`})]}),m&&(0,Q.jsxs)(`button`,{onClick:()=>{p.current=!1,u.current?.scrollIntoView({behavior:`smooth`}),h(!1)},className:W(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3 py-2 rounded-full`,`bg-white/95 dark:bg-dark-100/95 ophelia:bg-[#0a0a0a]/95`,`border border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/60`,`shadow-lg backdrop-blur-sm`,`text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3]`,`hover:bg-gray-50 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]`,`hover:text-gray-900 dark:hover:text-dark-800 ophelia:hover:text-[#fafafa]`,`transition-all duration-200`,`hover:shadow-xl hover:scale-105 active:scale-95`),title:l(`chatMessage.scrollToBottom`),children:[(0,Q.jsx)(y,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:l(`chatMessage.newMessages`)})]})]})};function Xe(e){let t=(e.match(/```/g)||[]).length,n=t%2==1,r=null;if(n){let t=e.lastIndexOf("```");if(t!==-1){let n=e.slice(t+3).match(/^(\w+)/);n&&(r=n[1])}}return{hasCodeBlocks:t>0,isInCodeBlock:n,language:r}}var Ze=Z.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,...o},s)=>{let{hasCodeBlocks:c,isInCodeBlock:l,language:u}=(0,Z.useMemo)(()=>Xe(e),[e]);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`textarea`,{ref:s,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,className:W(`w-full resize-none transition-all duration-200`,l&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50 ophelia:bg-[#0f0f0f]`,`rounded-lg`],n),...o}),c&&(0,Q.jsx)(`div`,{className:`absolute right-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,Q.jsxs)(`div`,{className:W(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]`,`text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3]`,`border border-gray-200/50 dark:border-dark-300/50 ophelia:border-[#262626]/50`,l&&`animate-pulse`),children:[(0,Q.jsx)(k,{className:`h-3 w-3`}),u&&(0,Q.jsx)(`span`,{children:u}),!u&&l&&(0,Q.jsx)(`span`,{children:`code`})]})})]})});Ze.displayName=`CodeAwareTextarea`;var Qe=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:a,disabled:o=!1,className:s})=>{let{t:c}=i(),l=(0,Z.useRef)(null),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)([]),g=async e=>{if(!(!e||o))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await v(n):U.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){U.error(`Maximum ${n} images allowed`);return}if(r.size>10*1024*1024){U.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},v=async e=>{if(e.size>10*1024*1024){U.error(`File size must be less than 10MB`);return}p(!0);try{let t=await xe.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),a?.(n),U.success(`Document "${e.name}" uploaded`)}else U.error(t.error||`Failed to upload document`)}catch(e){console.error(`Document upload error:`,e),U.error(`Failed to upload document`)}finally{p(!1)}},y=e=>{e.preventDefault(),o||d(!0)},b=e=>{e.preventDefault(),d(!1)},x=e=>{e.preventDefault(),d(!1),o||g(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},C=async e=>{try{let t=await xe.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),U.success(`Document removed`)):U.error(t.error||`Failed to remove document`)}catch(e){console.error(`Error removing document:`,e),U.error(`Failed to remove document`)}},w=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(1))+` `+n[r]},E=e.length>0||m.length>0;return(0,Q.jsxs)(`div`,{className:W(`space-y-3`,s),children:[(0,Q.jsxs)(`div`,{className:W(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600 ophelia:border-[#3f3f46]`,`hover:border-primary-400 dark:hover:border-primary-500 ophelia:hover:border-[#9333ea]`,u&&`border-primary-500 dark:border-primary-400 ophelia:border-[#a855f7] bg-primary-50/50 dark:bg-primary-900/10 ophelia:bg-[#9333ea]/10`,o&&`opacity-50 cursor-not-allowed`),onDragOver:y,onDragLeave:b,onDrop:x,onClick:()=>!o&&l.current?.click(),children:[(0,Q.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:o}),(0,Q.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,Q.jsx)(T,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 ophelia:text-[#737373] mb-2 animate-spin`}):(0,Q.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 ophelia:text-[#737373] mb-2`}),(0,Q.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 ophelia:text-[#d4d4d4]`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,Q.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 ophelia:bg-[#1a1a1a] border border-gray-200 dark:border-gray-700 ophelia:border-[#262626]`,children:[(0,Q.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),S(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Q.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,Q.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 ophelia:bg-[#1a1a1a] border border-gray-200 dark:border-gray-700 ophelia:border-[#262626]`,children:[e.fileType===`pdf`?(0,Q.jsx)(j,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,Q.jsx)(ie,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate max-w-[100px]`,children:e.filename}),(0,Q.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:w(e.size)})]}),(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),C(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 ophelia:hover:bg-[#262626] text-gray-500 hover:text-red-500 transition-colors`,children:(0,Q.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},$e=({sessionId:e,className:t=``})=>{let[n,r]=(0,Z.useState)([]);if((0,Z.useEffect)(()=>{e&&(async()=>{try{let t=await xe.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){console.error(`Failed to load documents:`,e)}})()},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,Q.jsxs)(`div`,{className:`
|
|
3
|
+
inline-flex items-center space-x-1 px-2 py-1
|
|
4
|
+
bg-blue-50 dark:bg-blue-900/20
|
|
5
|
+
border border-blue-200 dark:border-blue-800
|
|
6
|
+
rounded-md text-xs
|
|
7
|
+
${t}
|
|
8
|
+
`,title:`${n.length} document(s) available for context - Total: ${(e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(1))+` `+n[r]})(i)}`,children:[(0,Q.jsx)(h,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,Q.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},et=[{key:`none`,value:null},{key:`json`,value:`json`},{key:`list`,value:{type:`object`,properties:{items:{type:`array`,items:{type:`string`}}},required:[`items`]}},{key:`summary`,value:{type:`object`,properties:{title:{type:`string`},summary:{type:`string`},key_points:{type:`array`,items:{type:`string`}}},required:[`title`,`summary`,`key_points`]}},{key:`analysis`,value:{type:`object`,properties:{analysis:{type:`string`},pros:{type:`array`,items:{type:`string`}},cons:{type:`array`,items:{type:`string`}},recommendation:{type:`string`}},required:[`analysis`,`pros`,`cons`,`recommendation`]}},{key:`custom`,value:`custom`}],tt=({format:e,onFormatChange:t,className:n})=>{let{t:r}=i(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(``),u=()=>et.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),d=()=>{let t=u();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},f=e=>{let n=u().find(t=>t.label===e);if(n){if(n.value===`custom`){s(!0);return}s(!1),t(n.value)}};return(0,Q.jsxs)(`div`,{className:W(`space-y-3`,n),children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Q.jsxs)(`div`,{className:`flex items-center`,children:[(0,Q.jsx)(le,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,Q.jsx)(he,{value:d().label,onChange:e=>f(e.target.value),options:u().map(e=>({value:e.label,label:e.label}))}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d().description}),o&&(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(ge,{value:c,onChange:e=>l(e.target.value),placeholder:`{
|
|
9
|
+
"type": "object",
|
|
10
|
+
"properties": {
|
|
11
|
+
"field1": { "type": "string" },
|
|
12
|
+
"field2": { "type": "number" }
|
|
13
|
+
},
|
|
14
|
+
"required": ["field1"]
|
|
15
|
+
}`,rows:8,className:`font-mono text-sm`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(a,{onClick:()=>{try{t(JSON.parse(c)),s(!1)}catch(e){console.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!c.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,Q.jsx)(a,{onClick:()=>{s(!1),l(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=d();return!e.value||e.value===`json`?null:(0,Q.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,Q.jsx)(de,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,Q.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,Q.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,Q.jsx)(j,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},nt=({models:e,selectedModel:t,onModelChange:n,currentPersona:r,className:a,disabled:l=!1,compact:d=!1,showImageGen:p=!1,onModelsRefresh:m})=>{let{t:h}=i(),[g,y]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(``),[w,T]=(0,Z.useState)(`installed`),O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=Te(),{user:j,systemInfo:M}=we(),N=j?.role===`admin`||(M?.allowUserModelPull??!0),[P,I]=(0,Z.useState)([]),[ee,R]=(0,Z.useState)(!1),[B,V]=(0,Z.useState)(`all`),[re,ie]=(0,Z.useState)(``),[oe,se]=(0,Z.useState)([]),[ce,le]=(0,Z.useState)(!1),[de,fe]=(0,Z.useState)(`text-generation`),[pe,me]=(0,Z.useState)(`downloads`),[G,he]=(0,Z.useState)(``),[ge,_e]=(0,Z.useState)(null),[ye,be]=(0,Z.useState)({}),[xe,Se]=(0,Z.useState)(null),[K,q]=(0,Z.useState)(null),[J,Y]=(0,Z.useState)(null),[Ee,X]=(0,Z.useState)(null),Oe=[`all`,`popular`,`chat`,`code`,`vision`,`embedding`],ke=[{type:`personas`,label:h(`modelSelector.personas`),icon:(0,Q.jsx)(ne,{className:`h-4 w-4 text-purple-600 dark:text-purple-400 ophelia:text-[#a855f7]`}),models:e.filter(e=>e.isPersona),color:`purple`},{type:`ollama`,label:h(`modelSelector.ollamaModels`),icon:(0,Q.jsx)(te,{className:`h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]`}),models:e.filter(e=>!e.isPersona&&!e.isPlugin&&!e.name.includes(`embed`)),color:`green`},{type:`plugins`,label:h(`modelSelector.pluginModels`),icon:(0,Q.jsx)(H,{className:`h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]`}),models:e.filter(e=>e.isPlugin),color:`green`}].filter(e=>e.models.length>0).map(e=>({...e,models:e.models.filter(e=>e.name.toLowerCase().includes(x.toLowerCase())||e.personaName&&e.personaName.toLowerCase().includes(x.toLowerCase())||e.pluginName&&e.pluginName.toLowerCase().includes(x.toLowerCase()))})).filter(e=>e.models.length>0),Ae=P.filter(e=>{let t=!x||e.name.toLowerCase().includes(x.toLowerCase())||e.description.toLowerCase().includes(x.toLowerCase()),n=B===`all`||e.category===B;return t&&n}),$=e.find(e=>e.name===t||t.startsWith(`persona:`)&&e.name===t),je=(0,Z.useCallback)(async()=>{R(!0);try{let e=await Ce.getLibraryModels({search:re||void 0,sort:`popular`});e.success&&e.data&&I(e.data)}catch(e){console.error(`Failed to load library:`,e)}finally{R(!1)}},[re]),Me=(0,Z.useCallback)(async()=>{le(!0);try{let e=await ve.getModels({task:de,search:G||void 0,sort:pe,limit:30});e.success&&e.data&&se(e.data)}catch(e){console.error(`Failed to load HuggingFace models:`,e)}finally{le(!1)}},[de,G,pe]),Ne=(0,Z.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){Se(e);try{let r=await ve.getGgufFiles(t,n);r.success&&r.data&&be(t=>({...t,[e]:r.data}))}catch(e){console.error(`Failed to load GGUF files:`,e)}finally{Se(null)}}},[]),Pe=(0,Z.useCallback)(e=>{ge===e?_e(null):(_e(e),ye[e]||Ne(e))},[ge,ye,Ne]),Fe=(0,Z.useCallback)((e,t)=>{if(!N){U.error(h(`modelSelector.pullRestricted`));return}if(!K){q(e),Y({status:`starting`});try{let n=Ce.pullModelStream(e,e=>{Y(e)},()=>{Y(null),q(null),X(null),U.success(`Downloaded ${t}`),m?.()},e=>{Y(null),q(null),X(null),U.error(`Failed to download: ${e}`)});X(()=>n)}catch{Y(null),q(null),U.error(`Failed to start download`)}}},[N,m,K,h]);(0,Z.useEffect)(()=>{let e=setTimeout(()=>{w===`huggingface`?he(x):w===`ollama`&&ie(x)},300);return()=>clearTimeout(e)},[x,w]),(0,Z.useEffect)(()=>{g&&w===`ollama`&&je()},[g,w,re,je]),(0,Z.useEffect)(()=>{g&&w===`huggingface`&&Me()},[g,w,de,G,pe,Me]),(0,Z.useEffect)(()=>{let e=e=>{O.current&&!O.current.contains(e.target)&&(y(!1),S(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,Z.useEffect)(()=>{g&&k.current&&k.current.focus()},[g]);let Ie=async e=>{y(!1),S(``);try{let t=await Ce.listRunningModels();if(t.success&&t.data){let n=t.data;n.length>0&&(n.some(t=>t.name===e||e.startsWith(`persona:`))||await Ce.unloadAllModels())}}catch(e){console.warn(`Failed to unload models before switch:`,e)}n({target:{value:e}})},Le=async e=>{if(!N){U.error(h(`modelSelector.pullRestricted`));return}if(!K){q(e),Y({status:`starting`});try{let t=Ce.pullModelStream(e,e=>{Y(e)},()=>{Y(null),q(null),X(null),U.success(`Downloaded ${e}`),m?.()},e=>{Y(null),q(null),X(null),U.error(`Failed to download: ${e}`)});X(()=>t)}catch{Y(null),q(null),U.error(`Failed to start download`)}}},Re=()=>{Ee&&(Ee(),X(null),q(null),Y(null),U.success(`Download cancelled`))},ze=t=>e.some(e=>e.name===t||e.name.startsWith(t+`:`)),Be=e=>e.isPersona?(0,Q.jsx)(ne,{className:`h-4 w-4 text-purple-600 dark:text-purple-400`}):e.isPlugin?(0,Q.jsx)(H,{className:`h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]`}):(0,Q.jsx)(te,{className:`h-4 w-4 text-green-600 dark:text-green-400 ophelia:text-[#a855f7]`}),Ve=e=>e.isPersona?e.personaName||e.name:e.isPlugin?`${e.name}`:e.name,He=e=>e.isPersona?`via ${e.model}`:e.isPlugin?`via ${e.pluginName}`:null,Ue=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString();return(0,Q.jsxs)(`div`,{className:W(`relative`,a),ref:O,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>!l&&y(!g),disabled:l,className:W(d?`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]`,l?`opacity-50 cursor-not-allowed`:`cursor-pointer`),title:d?$?Ve($):h(`modelSelector.selectModel`):void 0,children:[(()=>{if(!$)return d?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Q.jsx)(te,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium text-gray-400 dark:text-gray-500 truncate`,children:h(`modelSelector.selectModel`)})]}):h(`modelSelector.selectModel`);if(d){let e=Ve($);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[Be($),(0,Q.jsx)(`span`,{className:`text-xs font-medium text-gray-700 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate`,children:e})]})}let e=Ve($),t=He($);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[Be($),(0,Q.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e}),t&&(0,Q.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:t})]}),$.isPersona&&r&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto`,children:[(0,Q.jsx)(s,{className:`h-3 w-3 text-purple-600 dark:text-purple-400`}),r.embedding_model&&(0,Q.jsx)(ae,{className:`h-3 w-3 text-purple-500 dark:text-purple-300`})]})]})})(),(0,Q.jsx)(c,{className:W(d?`h-3 w-3`:`h-4 w-4`,`text-gray-400 flex-shrink-0`,g&&`rotate-180`)})]}),g&&(0,De.createPortal)((0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-start sm:items-center justify-center p-2 sm:p-4`,children:[(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>y(!1)}),(0,Q.jsxs)(`div`,{className:W(`relative bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] shadow-2xl`,`w-full max-w-md sm:w-[480px] sm:max-w-[90vw]`,`mt-2 sm:mt-0 rounded-xl`,`h-[85vh] sm:h-[600px] flex flex-col`),onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(`div`,{className:`flex-shrink-0`,children:[(0,Q.jsx)(`div`,{className:`p-3 border-b border-gray-200 dark:border-dark-200 ophelia:border-[#1a1a1a]`,children:(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(C,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400`}),(0,Q.jsx)(`input`,{ref:k,type:`text`,placeholder:h(w===`installed`?`modelSelector.searchInstalled`:w===`ollama`?`modelSelector.searchOllama`:`modelSelector.searchHuggingFace`),value:x,onChange:e=>S(e.target.value),className:W(`w-full pl-10 pr-4 py-2.5 text-sm bg-gray-50 dark:bg-dark-200 ophelia:bg-[#121212]`,`border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] rounded-lg`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20 ophelia:focus:ring-[#9333ea]/20`,`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,`placeholder-gray-500 ophelia:placeholder-[#737373]`)})]})}),(0,Q.jsxs)(`div`,{className:`flex border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`,children:[(0,Q.jsxs)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),T(`installed`)},className:W(`flex-1 px-4 py-2.5 text-sm font-medium transition-colors`,w===`installed`?`text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]`:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300`),children:[(0,Q.jsx)(b,{className:`h-4 w-4 inline mr-1.5`}),h(`modelSelector.installed`)]}),(0,Q.jsxs)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),T(`ollama`)},className:W(`flex-1 px-4 py-2.5 text-sm font-medium transition-colors`,w===`ollama`?`text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]`:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300`),children:[(0,Q.jsx)(ue,{className:`h-4 w-4 inline mr-1.5`}),`Ollama`]}),(0,Q.jsxs)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),T(`huggingface`)},className:W(`flex-1 px-4 py-2.5 text-sm font-medium transition-colors`,w===`huggingface`?`text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] border-b-2 border-primary-500 ophelia:border-[#9333ea]`:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373] hover:text-gray-700 dark:hover:text-gray-300`),children:[(0,Q.jsx)(H,{className:`h-4 w-4 inline mr-1.5`}),`HuggingFace`]})]})]}),w===`installed`&&(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400`,children:[ke.length>0?ke.map(e=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] bg-gray-100 dark:bg-dark-300 ophelia:bg-[#0a0a0a] border-b border-gray-200 dark:border-dark-400 ophelia:border-[#1a1a1a] sticky top-0`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon,e.label,` (`,e.models.length,`)`]})}),e.models.map(e=>(0,Q.jsx)(`div`,{onMouseDown:t=>{t.preventDefault(),Ie(e.name)},className:W(`px-3 py-3 cursor-pointer border-b border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a] last:border-b-0`,`hover:bg-gray-50 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]`,`bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] transition-colors`,t===e.name&&`bg-primary-50 dark:bg-primary-900/30 ophelia:bg-[rgba(147,51,234,0.15)]`),children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[Be(e),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate`,children:Ve(e)}),He(e)&&(0,Q.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] truncate`,children:He(e)})]}),t===e.name&&(0,Q.jsx)(v,{className:`h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] flex-shrink-0`})]})},e.name))]},e.type)):(0,Q.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:[(0,Q.jsx)(D,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:h(`models.noModelsFound`)})]}),p&&(0,Q.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] bg-gray-100 dark:bg-dark-300 ophelia:bg-[#0a0a0a]`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(o,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),h(`modelSelector.actions`)]})}),(0,Q.jsx)(`div`,{onMouseDown:e=>{e.preventDefault(),y(!1),A(`/gallery`)},className:`px-3 py-3 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-900/20 ophelia:hover:bg-[rgba(147,51,234,0.1)] bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(f,{className:`h-4 w-4 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]`}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:h(`gallery.generate`)}),(0,Q.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:h(`gallery.generateDescription`)})]})]})})]})]}),w===`ollama`&&(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex-shrink-0`,children:(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Oe.map(e=>(0,Q.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),V(e)},className:W(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,B===e?`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:e.charAt(0).toUpperCase()+e.slice(1)},e))})}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[!N&&(0,Q.jsx)(`div`,{className:`mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300`,children:h(`modelSelector.pullRestricted`)}),ee?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Q.jsx)(u,{className:`h-6 w-6 animate-spin text-gray-400`})}):Ae.length===0?(0,Q.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:[(0,Q.jsx)(ue,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:h(`models.noModelsFound`)})]}):(0,Q.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]`,children:Ae.slice(0,50).map(e=>{let t=ze(e.name),n=K===e.name;return(0,Q.jsxs)(`div`,{className:W(`px-3 py-3 bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]`,t&&`bg-green-50/50 dark:bg-green-900/10`),children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`div`,{className:`p-2 rounded-lg bg-cyan-100 dark:bg-cyan-900/30 ophelia:bg-[#06b6d4]/20 flex-shrink-0`,children:(0,Q.jsx)(ue,{className:`h-4 w-4 text-cyan-600 dark:text-cyan-400`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate`,children:e.name}),t&&(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`,children:h(`modelSelector.installed`)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] line-clamp-1 mt-0.5`,children:e.description}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[e.sizes.slice(0,3).map(e=>(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]`,children:e},e)),e.pulls&&(0,Q.jsxs)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1`,children:[(0,Q.jsx)(F,{className:`h-3 w-3`}),e.pulls]})]})]}),(0,Q.jsx)(`div`,{className:`flex-shrink-0`,children:n?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:J?.percent===void 0?`...`:`${J.percent}%`}),(0,Q.jsx)(`button`,{onClick:Re,className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,Q.jsx)(L,{className:`h-4 w-4`})})]}):t?(0,Q.jsx)(`button`,{onClick:()=>Ie(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-900/50`,children:h(`modelSelector.use`)}):N?(0,Q.jsxs)(`button`,{onClick:()=>Le(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20 text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7] hover:bg-primary-200 dark:hover:bg-primary-900/50`,children:[(0,Q.jsx)(F,{className:`h-3 w-3 inline mr-1`}),h(`modelSelector.pull`)]}):(0,Q.jsx)(`span`,{className:`px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`,children:h(`modelSelector.adminOnlyPull`)})})]}),n&&J?.percent!==void 0&&(0,Q.jsx)(`div`,{className:`mt-2 w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${J.percent}%`}})})]},e.name)})})]}),(0,Q.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex items-center justify-between flex-shrink-0`,children:[(0,Q.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1`,children:[(0,Q.jsx)(z,{className:`h-3 w-3`}),h(`modelManager.huggingface.browseAllLink`)]}),(0,Q.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),I([]),je()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]`,children:(0,Q.jsx)(_,{className:W(`h-3.5 w-3.5 text-gray-400`,ee&&`animate-spin`)})})]})]}),w===`huggingface`&&(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex-shrink-0 space-y-2`,children:(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(`select`,{value:de,onChange:e=>fe(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`flex-1 px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border-gray-200 dark:border-dark-300 ophelia:border-[#262626] text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:[(0,Q.jsx)(`option`,{value:`text-generation`,children:h(`modelManager.huggingface.taskTextGeneration`)}),(0,Q.jsx)(`option`,{value:`text-to-speech`,children:h(`modelManager.huggingface.taskTextToSpeech`)}),(0,Q.jsx)(`option`,{value:`text-to-image`,children:h(`modelManager.huggingface.taskTextToImage`)}),(0,Q.jsx)(`option`,{value:`automatic-speech-recognition`,children:h(`modelManager.huggingface.taskSpeechRecognition`)})]}),(0,Q.jsxs)(`select`,{value:pe,onChange:e=>me(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border-gray-200 dark:border-dark-300 ophelia:border-[#262626] text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:[(0,Q.jsx)(`option`,{value:`downloads`,children:h(`modelManager.huggingface.sortDownloads`)}),(0,Q.jsx)(`option`,{value:`likes`,children:h(`modelManager.huggingface.sortLikes`)}),(0,Q.jsx)(`option`,{value:`lastModified`,children:h(`modelManager.huggingface.sortRecent`)})]})]})}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[!N&&(0,Q.jsx)(`div`,{className:`mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300`,children:h(`modelSelector.pullRestricted`)}),ce?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Q.jsx)(u,{className:`h-6 w-6 animate-spin text-gray-400`})}):oe.length===0?(0,Q.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:[(0,Q.jsx)(H,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:h(`modelManager.huggingface.noModelsFound`)})]}):(0,Q.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200 ophelia:divide-[#1a1a1a]`,children:oe.map(e=>{let t=ge===e.id,n=ye[e.id]||[],r=xe===e.id;return(0,Q.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-200 ophelia:hover:bg-[#121212]`,onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),Pe(e.id)},children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`div`,{className:`p-2 rounded-lg bg-yellow-100 dark:bg-yellow-900/30 ophelia:bg-[#eab308]/20 flex-shrink-0`,children:(0,Q.jsx)(H,{className:`h-4 w-4 text-yellow-600 dark:text-yellow-400`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate`,children:e.id}),e.gated&&(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400`,children:`Gated`})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mt-0.5`,children:[`by `,e.author]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 text-xs text-gray-400 dark:text-gray-500`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(F,{className:`h-3 w-3`}),Ue(e.downloads)]}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(E,{className:`h-3 w-3`}),Ue(e.likes)]}),e.pipeline_tag&&(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]`,children:e.pipeline_tag})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,Q.jsx)(`a`,{href:`https://huggingface.co/${e.id}`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]`,children:(0,Q.jsx)(z,{className:`h-4 w-4 text-gray-400`})}),(0,Q.jsx)(c,{className:W(`h-4 w-4 text-gray-400 transition-transform`,t&&`rotate-180`)})]})]})}),t&&(0,Q.jsx)(`div`,{className:`px-3 pb-3 pt-1 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a] bg-gray-50 dark:bg-dark-200 ophelia:bg-[#0d0d0d]`,children:r?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,Q.jsx)(u,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,Q.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:h(`modelManager.huggingface.checkingGguf`)})]}):n.length===0?(0,Q.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:h(`modelManager.huggingface.noGgufAvailable`)}):(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2`,children:h(`modelManager.huggingface.ggufFilesCount`,{count:n.length})}),n.map(e=>{let t=K===e.ollamaCommand;return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate`,children:e.filename}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,Q.jsx)(`span`,{children:e.sizeFormatted}),e.quantization&&(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 ophelia:bg-[#9333ea]/20 text-purple-700 dark:text-purple-400 ophelia:text-[#a855f7]`,children:e.quantization})]})]}),t?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:J?.percent===void 0?`...`:`${J.percent}%`}),(0,Q.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),Re()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,Q.jsx)(L,{className:`h-4 w-4`})})]}):N?(0,Q.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),Fe(e.ollamaCommand,e.filename)},disabled:!!K,className:W(`px-3 py-1.5 rounded-lg text-xs font-medium`,`bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20`,`text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7]`,`hover:bg-primary-200 dark:hover:bg-primary-900/50`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,Q.jsx)(F,{className:`h-3 w-3 inline mr-1`}),h(`models.pull`)]}):(0,Q.jsx)(`span`,{className:`px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`,children:h(`modelSelector.adminOnlyPull`)})]},e.filename)}),K?.startsWith(`hf.co/`)&&K.includes(e.id)&&J?.percent!==void 0&&(0,Q.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,Q.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${J.percent}%`}})})]})})]},e.id)})})]}),(0,Q.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] flex items-center justify-between flex-shrink-0`,children:[(0,Q.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7] hover:underline flex items-center gap-1`,children:[(0,Q.jsx)(z,{className:`h-3 w-3`}),h(`modelManager.huggingface.browseAllLink`)]}),(0,Q.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),Me()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]`,children:(0,Q.jsx)(_,{className:W(`h-3.5 w-3.5 text-gray-400`,ce&&`animate-spin`)})})]})]})]})]}),document.body),(0,Q.jsx)(`select`,{value:t,onChange:n,className:`sr-only`,tabIndex:-1,children:e.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:Ve(e)},e.name))})]})},rt=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r}=i(),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)([]),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),{isGenerating:S,setBackgroundImage:C}=G(),{currentSession:w,models:T}=J(),E=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{(async()=>{try{let e=await Se.getPlugins();b(!!(e.success&&e.data&&e.data.length>0))}catch{b(!1)}})()},[]);let D=t=>{t.preventDefault(),!(!s.trim()||S)&&(e(s.trim(),l.length>0?l:void 0,f||void 0),c(``),u([]))},O=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),D(e))},k=()=>{t()};(0,Z.useEffect)(()=>{let e=E.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[s]),(0,Z.useEffect)(()=>{(async()=>{if(w?.personaId)try{let e=await ye.getPersona(w.personaId);if(e.success&&e.data)v(e.data);else{console.warn(`Persona ${w.personaId} not found, clearing reference`),v(null);let{setCurrentSession:e}=J.getState();e({...w,personaId:void 0})}}catch(e){if(console.error(`Failed to load current persona:`,e),v(null),w){let{setCurrentSession:e}=J.getState();e({...w,personaId:void 0})}}else v(null)})()},[w?.personaId]);let A=async e=>{let t=e.target.value;if(w)try{if(t.startsWith(`persona:`)){let e=t.replace(`persona:`,``),n=await ye.getPersona(e);if(!n.success||!n.data){x.error(`Failed to load persona details`);return}let i=n.data,a=await K.updateSession(w.id,{personaId:e,model:t});if(a.success&&a.data){let{sessions:e}=J.getState(),t=e.map(e=>e.id===w.id?a.data:e);J.setState({sessions:t,currentSession:a.data}),i.background&&C(i.background),x.success(r(`chat.persona.applied`))}}else{let e=await K.updateSession(w.id,{model:t,personaId:void 0});if(e.success&&e.data){let{sessions:t}=J.getState(),n=t.map(t=>t.id===w.id?e.data:t);J.setState({sessions:n,currentSession:e.data}),C(null),x.success(r(`chat.model.updated`))}}}catch(e){console.error(`Failed to update session:`,e),x.error(`Failed to update session`)}},j=l.length>0||f!==null;return(0,Q.jsx)(`div`,{className:`pointer-events-none`,children:(0,Q.jsxs)(`div`,{className:`max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full pointer-events-auto`,children:[m&&(0,Q.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:[(0,Q.jsx)(Qe,{images:l,onImagesChange:u,maxImages:5,sessionId:w?.id,disabled:n}),(0,Q.jsx)(tt,{format:f,onFormatChange:p})]}),(0,Q.jsxs)(`div`,{className:`py-2 sm:py-3`,children:[(0,Q.jsx)(`form`,{onSubmit:D,children:(0,Q.jsxs)(`div`,{className:W(`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:[(0,Q.jsx)(a,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>h(!m),className:W(`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`,j&&`text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]`,m&&`bg-gray-100 dark:bg-dark-200/80 ophelia:bg-[#1a1a1a]`),title:r(`chat.input.attachments`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`0`},children:j?(0,Q.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,Q.jsx)(g,{className:`h-4 w-4`}),(0,Q.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]`})]}):m?(0,Q.jsx)(d,{className:`h-4 w-4`}):(0,Q.jsx)(o,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(Ze,{ref:E,value:s,onChange:e=>c(e.target.value),onKeyDown:O,placeholder:r(`chat.input.placeholder`),disabled:n,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`}})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 flex-shrink-0`,children:[w&&T.length>0&&(0,Q.jsx)(`div`,{className:`hidden sm:block`,children:(0,Q.jsx)(nt,{models:T,selectedModel:w.personaId?`persona:${w.personaId}`:w.model,onModelChange:A,currentPersona:_,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:y})}),S?(0,Q.jsx)(a,{type:`button`,variant:`ghost`,size:`sm`,onClick:k,className:W(`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:r(`chat.input.stopGeneration`),children:(0,Q.jsx)(N,{className:`h-4 w-4`})}):(0,Q.jsx)(a,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!s.trim()||n,className:W(`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()&&!n&&[`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:r(`chat.input.sendMessage`),children:(0,Q.jsx)(se,{className:`h-4 w-4`})})]})]})}),w&&T.length>0&&(0,Q.jsx)(`div`,{className:`sm:hidden mt-3`,children:(0,Q.jsx)(nt,{models:T,selectedModel:w.personaId?`persona:${w.personaId}`:w.model,onModelChange:A,currentPersona:_,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:y})}),(0,Q.jsxs)(`div`,{className:`mt-2 flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-dark-600`,children:[(0,Q.jsx)($e,{sessionId:w?.id}),(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsxs)(`a`,{href:`https://librewebui.org`,target:`_blank`,rel:`noopener noreferrer`,className:`libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 transition-colors`,style:{fontSize:`1.1em`,lineHeight:1},children:[`Libre `,(0,Q.jsx)(`span`,{style:{fontSize:`0.85em`},children:`WebUI`})]}),` `,(0,Q.jsxs)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500`,style:{fontSize:`0.55rem`},children:[`v`,`0.8.6`]}),` `,(0,Q.jsx)(`span`,{className:`text-gray-300 dark:text-gray-600 opacity-50`,children:`•`}),` `,(0,Q.jsx)(`span`,{className:`text-gray-400 dark:text-gray-500`,style:{fontSize:`0.55rem`},children:r(`chat.footer.disclaimer`)}),j&&(0,Q.jsxs)(`span`,{className:`ml-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,l.length>0&&r(`chat.footer.images`,{count:l.length}),l.length>0&&f&&` • `,f&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},it=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Z.useState)(!1),a=(0,Z.useRef)(null),[o,l]=(0,Z.useState)({top:0,left:0});(0,Z.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect();l({top:e.bottom+8,left:e.left})}},[r]);let u=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),d=()=>e.avatar?e.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(e.name)}&background=6366f1&color=fff&size=64`;return(0,Q.jsxs)(`div`,{className:W(`relative`,n),children:[(0,Q.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:W(`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:[(0,Q.jsx)(`img`,{src:d(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),u&&(0,Q.jsx)(ae,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,Q.jsx)(c,{className:W(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,De.createPortal)((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,Q.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,Q.jsxs)(`div`,{className:W(`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:[(0,Q.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,Q.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]`}),(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!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:(0,Q.jsx)(L,{className:`h-3.5 w-3.5 text-white`})}),u&&(0,Q.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:[(0,Q.jsx)(s,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,Q.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,Q.jsx)(`img`,{src:d(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a] shadow-md`})}),(0,Q.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:e.name}),(0,Q.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] flex items-center gap-1 mt-0.5`,children:[(0,Q.jsx)(S,{className:`h-3 w-3`}),e.model]}),e.description&&(0,Q.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,Q.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:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,Q.jsx)(p,{className:`h-2.5 w-2.5 text-gray-400`}),(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,Q.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:[(0,Q.jsx)(H,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,Q.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 `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,Q.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:[(0,Q.jsx)(s,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},at=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:o}=i(),s=(0,Z.useRef)(null),[c,l]=(0,Z.useState)(!1),u=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){U.error(`File ${o.name} is not an image`);continue}if(o.size>10*1024*1024){U.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&U.error(`Only ${a} more images can be added`)},d=e=>{e.preventDefault(),l(!0)},p=e=>{e.preventDefault(),l(!1)},m=e=>{e.preventDefault(),l(!1),u(e.dataTransfer.files)},h=n=>{t(e.filter((e,t)=>t!==n))},g=e.length<n;return(0,Q.jsxs)(`div`,{className:W(`space-y-3`,r),children:[g&&(0,Q.jsxs)(`div`,{className:W(`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`,c&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:d,onDragLeave:p,onDrop:m,children:[(0,Q.jsx)(`input`,{ref:s,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>u(e.target.files),className:`hidden`}),(0,Q.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,Q.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,Q.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[o(`chat.mediaUpload.dropImagesHere`),` `,(0,Q.jsx)(`button`,{onClick:()=>s.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:o(`chat.mediaUpload.browse`)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:o(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,Q.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,Q.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:[(0,Q.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Q.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:(0,Q.jsx)(a,{variant:`ghost`,size:`sm`,onClick:()=>h(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:(0,Q.jsx)(L,{className:`h-4 w-4`})})})]},t))}),g&&e.length>0&&(0,Q.jsxs)(a,{variant:`outline`,size:`sm`,onClick:()=>s.current?.click(),className:`w-full sm:w-auto`,children:[(0,Q.jsx)(f,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},ot=e=>{let[t,n]=(0,Z.useState)(``),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)([]),{addMessage:l,updateMessage:u,updateMessageWithStatistics:d,updateSessionTitle:f,setGeneratingTitleForSession:p}=J(),{setIsGenerating:m,preferences:h}=G(),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(``),y=(0,Z.useRef)(0),b=(0,Z.useRef)();return(0,Z.useEffect)(()=>()=>{q.offMessage(`user_message`),q.offMessage(`assistant_chunk`),q.offMessage(`assistant_complete`),q.offMessage(`tool_status`),q.offMessage(`error`)},[e]),(0,Z.useEffect)(()=>{if(!e){q.offMessage(`user_message`),q.offMessage(`assistant_chunk`),q.offMessage(`assistant_complete`),q.offMessage(`tool_status`),q.offMessage(`error`);return}return q.onMessage(`user_message`,()=>{}),q.onMessage(`assistant_chunk`,t=>{let r=t,i=r.messageId||g.current;i&&(v.current=r.total,n(r.total),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{u(e,i,v.current),y.current=Date.now()},r.done?0:200))}),q.onMessage(`tool_status`,e=>{let t=e;c(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),q.onMessage(`assistant_complete`,t=>{let r=t;console.log(`Hook: Received assistant_complete for session:`,e,`messageId:`,r.messageId,`with statistics:`,!!r.statistics),o(!1),n(``),m(!1),c([]);let i=r.messageId||g.current;r&&i&&d(e,i,v.current||r.content,r.statistics);let a=G.getState().preferences.titleSettings,s=J.getState().currentSession,l=_.current;console.log(`Auto-title check:`,{firstMessage:l,autoTitle:a?.autoTitle,taskModel:a?.taskModel,sessionTitle:s?.title}),l&&a?.autoTitle&&a?.taskModel&&s?.title===`New Chat`&&(console.log(`Triggering auto-title generation...`),p(e),K.generateTitle(e,a.taskModel,l).then(t=>{console.log(`Title generation response:`,t),t.success&&t.data?.title&&f(e,t.data.title)}).catch(e=>{console.error(`Failed to generate title:`,e)}).finally(()=>{p(null)}),_.current=null),g.current=null,v.current=``,b.current&&clearTimeout(b.current),y.current=0}),q.onMessage(`error`,e=>{let t=e;if(o(!1),n(``),m(!1),g.current=null,t.code===`SESSION_NOT_FOUND`){console.warn(`Session not found, redirecting to create new session...`),U.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}U.error(t.error)}),o(!1),n(``),g.current=null,()=>{b.current&&clearTimeout(b.current)}},[e,u,d,m,f,p]),{sendMessage:(0,Z.useCallback)(async(t,r,a)=>{if(!(!e||!t.trim()&&(!r||r.length===0)))try{m(!0),o(!0),n(``),b.current&&clearTimeout(b.current),y.current=Date.now();let s=J.getState().currentSession,c=s?.isPrivate===!0,u=s?.messages?.some(e=>e.role===`user`);!c&&!u&&s?.title===`New Chat`&&(_.current=t.trim()),l(e,{role:`user`,content:t.trim(),images:r});let d=pe();g.current=d,i(d),l(e,{role:`assistant`,content:``,id:d}),q.isConnected||await q.connect();let f=c?s?.messages?.filter(e=>e.role!==`system`&&e.id!==d).map(e=>({role:e.role,content:e.content,images:e.images})):void 0;q.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:r,format:a,options:h.generationOptions,assistantMessageId:d,isPrivate:c,model:c?s?.model:void 0,messageHistory:f}})}catch(e){console.error(`Failed to send message:`,e),o(!1),n(``),i(null),m(!1),g.current=null,U.error(`Failed to send message`)}},[e,l,m,h.generationOptions]),stopGeneration:(0,Z.useCallback)(()=>{o(!1),n(``),i(null),m(!1),g.current=null},[m]),regenerateLastMessage:(0,Z.useCallback)(async()=>{let t=J.getState().currentSession;if(!t||!e)return;let r=t.messages,a=-1,s=-1;for(let e=r.length-1;e>=0;e--)if(r[e].role===`assistant`){s=e;break}if(s>0){for(let e=s-1;e>=0;e--)if(r[e].role===`user`){a=e;break}}if(a===-1||s===-1){U.error(`No message to regenerate`);return}let c=r[a],u=r[s];try{m(!0),o(!0),n(``),b.current&&clearTimeout(b.current),y.current=Date.now();let t=pe();g.current=t,i(t),l(e,{role:`assistant`,content:``,id:t,parentId:u.parentId||u.id,branchIndex:u.siblingCount||1,isActive:!0}),q.isConnected||await q.connect(),q.send({type:`chat_stream`,data:{sessionId:e,content:c.content,images:c.images,options:h.generationOptions,assistantMessageId:t,regenerate:!0,originalMessageId:u.id}})}catch(e){console.error(`Failed to regenerate message:`,e),o(!1),n(``),m(!1),g.current=null,U.error(`Failed to regenerate message`)}},[e,m,l,h.generationOptions]),selectBranch:(0,Z.useCallback)(async t=>{let n=J.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){U.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await K.switchMessageBranch(e,t,a);if(r.success&&r.data){let r=n.messages.map(e=>e.id===i||e.parentId===i?{...e,isActive:e.id===t}:e),o={...n,messages:r,updatedAt:Date.now()};J.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),U.success(`Switched to variant ${a+1}`)}else U.error(r.error||`Failed to select branch`)}catch(e){console.error(`Failed to select branch:`,e),U.error(`Failed to select branch`)}},[e]),isStreaming:a,streamingMessage:t,streamingMessageId:r,toolActivities:s}},st=(e,t)=>{let n=new Date().getHours(),r=e?`, ${e}`:``;return n>=5&&n<12?{greeting:`${t?t(`chat.greeting.morning`):`Good morning`}${r}`,timeSuffix:`today`}:n>=12&&n<17?{greeting:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${r}`,timeSuffix:`today`}:n>=17&&n<21?{greeting:`${t?t(`chat.greeting.evening`):`Good evening`}${r}`,timeSuffix:`tonight`}:{greeting:`${t?t(`chat.greeting.night`):`Good night`}${r}`,timeSuffix:`tonight`}},ct=()=>{let{t:e}=i(),{sessionId:t}=Y(),n=Te(),r=Ee(),{currentSession:s,sessions:c,models:l,selectedModel:u,setSelectedModel:f,createSession:p,setCurrentSession:m,loadSessions:h,getCurrentPersona:_}=J(),{user:v}=we(),{sendMessage:y,stopGeneration:b,regenerateLastMessage:x,selectBranch:S,isStreaming:C,streamingMessage:w,streamingMessageId:T,toolActivities:E}=ot(s?.id||``),D=_(),{greeting:O,timeSuffix:k}=(0,Z.useMemo)(()=>st(v?.username,e),[v?.username,e]),[A,j]=(0,Z.useState)(``),[M,N]=(0,Z.useState)([]),[P,F]=(0,Z.useState)(!1),I=(0,Z.useRef)(null),[te,L]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{c.length===0&&h()},[h,c.length]),(0,Z.useEffect)(()=>{(async()=>{try{let e=await Se.getPlugins();L(!!(e.success&&e.data&&e.data.length>0))}catch{L(!1)}})()},[]),(0,Z.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!s?.isPrivate&&c.length!==0)if(t){let e=c.find(e=>e.id===t);e&&e.id!==s?.id?m(e):e||(console.warn(`Session ${t} not found for current user, redirecting...`),c.length>0?n(`/c/${c[0].id}`,{replace:!0}):n(`/`,{replace:!0}))}else !t&&c.length>0&&r.pathname===`/`&&n(`/c/${c[0].id}`,{replace:!0})})()},[t,c,m,n,s?.id,s?.isPrivate,r.pathname]),(0,Z.useEffect)(()=>{if(s?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{y(t.content,t.images)},100)}catch(e){console.error(`Failed to parse pending message:`,e)}}}},[s?.id,y]),(0,Z.useEffect)(()=>{let e=I.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[A]);let ne=async e=>{if(e.preventDefault(),!A.trim()||!u)return;let t={content:A.trim(),images:M.length>0?M:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(t)),j(``),N([]);let r=await p(u);r&&n(`/c/${r.id}`,{replace:!0})},R=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ne(e))},z=async e=>{let t=e.target.value;f(t)},B=(e,t,n)=>{s&&y(e,t,n)};if(!s){let t=M.length>0;return(0,Q.jsxs)(`div`,{className:`h-full flex-1 flex flex-col items-center justify-center p-4 sm:p-8 relative`,children:[(0,Q.jsxs)(`button`,{onClick:()=>{if(!u&&l.length===0)return;let t=Date.now();m({id:`private-${t}`,title:e(`chat.session.private`),model:u||l[0]?.name||``,messages:[],createdAt:t,updatedAt:t,isPrivate:!0})},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:e(`chat.session.privateTooltip`),children:[(0,Q.jsx)(ee,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`text-sm`,children:e(`chat.session.private`)})]}),(0,Q.jsxs)(`div`,{className:`w-full max-w-2xl mx-auto flex flex-col items-center justify-center`,children:[(0,Q.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:O}),(0,Q.jsx)(`p`,{className:`text-base sm:text-lg text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-8 text-center`,children:e(k===`today`?`chat.welcome.helpToday`:`chat.welcome.helpTonight`)}),l.length>0?(0,Q.jsxs)(`div`,{className:`w-full`,children:[P&&(0,Q.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:(0,Q.jsx)(at,{images:M,onImagesChange:N,maxImages:5})}),(0,Q.jsx)(`form`,{onSubmit:ne,children:(0,Q.jsxs)(`div`,{className:W(`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:[(0,Q.jsx)(a,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>F(!P),className:W(`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`,t&&`text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]`,P&&`bg-gray-200 dark:bg-dark-200 ophelia:bg-[#1a1a1a]`),title:e(`chat.input.attachImages`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`0`},children:t?(0,Q.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,Q.jsx)(g,{className:`h-4 w-4`}),(0,Q.jsx)(`div`,{className:`absolute -top-0.5 -right-0.5 h-1.5 w-1.5 bg-primary-500 ophelia:bg-[#9333ea] rounded-full`})]}):P?(0,Q.jsx)(d,{className:`h-4 w-4`}):(0,Q.jsx)(o,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(Ze,{ref:I,value:A,onChange:e=>j(e.target.value),onKeyDown:R,placeholder:e(`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`}})}),(0,Q.jsx)(`div`,{className:`hidden sm:block`,children:(0,Q.jsx)(nt,{models:l,selectedModel:u,onModelChange:z,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:te})}),(0,Q.jsx)(a,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!A.trim()||!u,className:W(`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`,A.trim()&&u&&`hover:scale-105 active:scale-95`),title:e(`chat.input.sendMessage`),children:(0,Q.jsx)(se,{className:`h-4 w-4`})})]})}),(0,Q.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,Q.jsx)(nt,{models:l,selectedModel:u,onModelChange:z,className:`w-full rounded-xl bg-gray-100 dark:bg-dark-100 ophelia:bg-[#121212] border-0`,compact:!0,showImageGen:te})}),(0,Q.jsxs)(`div`,{className:`mt-4 text-center`,children:[(0,Q.jsxs)(`a`,{href:`https://librewebui.org`,target:`_blank`,rel:`noopener noreferrer`,className:`libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 ophelia:hover:text-[#a855f7] transition-colors text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,style:{fontSize:`0.75rem`,lineHeight:1},children:[`Libre `,(0,Q.jsx)(`span`,{style:{fontSize:`0.6rem`},children:`WebUI`})]}),` `,(0,Q.jsxs)(`span`,{className:`text-gray-400 dark:text-gray-500 ophelia:text-[#525252]`,style:{fontSize:`0.55rem`},children:[`v`,`0.8.6`]}),` `,(0,Q.jsx)(`span`,{className:`text-gray-300 dark:text-gray-600 ophelia:text-[#3f3f46] opacity-50`,children:`•`}),` `,(0,Q.jsx)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500 ophelia:text-[#525252]`,children:e(`chat.footer.disclaimer`)})]})]}):(0,Q.jsx)(`div`,{className:`w-full max-w-md`,children:(0,Q.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:[(0,Q.jsx)(`p`,{className:`text-sm text-gray-700 dark:text-dark-700 ophelia:text-[#a3a3a3] mb-4`,children:e(`chat.model.noModelsDescription`)}),(0,Q.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:e(`chat.model.pullCommand`)})]})})]})]})}return(0,Q.jsxs)(`div`,{className:`flex flex-col h-full relative`,style:D?.background?{backgroundImage:`url(${D.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[D?.background&&(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-white/80 dark:bg-black/80 backdrop-blur-sm`}),(0,Q.jsxs)(`div`,{className:`flex flex-col h-full relative z-10`,children:[s?.isPrivate&&(0,Q.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:(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]`,children:[(0,Q.jsx)(ee,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium`,children:e(`chat.session.privateMode`)}),(0,Q.jsxs)(`span`,{className:`text-xs text-gray-500 dark:text-gray-500 ophelia:text-[#737373]`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),D&&!s?.isPrivate&&(0,Q.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:(0,Q.jsx)(it,{persona:D,onClear:()=>{if(s){let{sessions:e}=J.getState(),t={...s,model:D.model,personaId:void 0},n=e.map(e=>e.id===s.id?t:e);J.setState({sessions:n,currentSession:t})}}})}),(0,Q.jsx)(Ye,{messages:s.messages,streamingMessage:w,streamingMessageId:T,isStreaming:C,toolActivities:E,onRegenerate:x,onSelectBranch:S,className:`flex-1`}),(0,Q.jsx)(rt,{onSendMessage:B,onStopGeneration:b,disabled:!s})]})]})};export{ct as ChatPage,ct as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-DWy-cpC1.js";import{m as t,p as n}from"./markdown-vendor-4lCPqxk5.js";import{n as r}from"./react-vendor-BUzyfgnZ.js";import{n as i,t as a}from"./Button-D62PCbMW.js";import{A as o,J as s,Rt as c,St as l,U as u,Y as d,_t as f,d as p,ht as m,n as h,v as g,z as _}from"./ui-vendor-BFOABH-A.js";import{n as v}from"./appStore-k_e3JAM3.js";import"./ui-DuH1cD2f.js";import{o as y}from"./api-BrzQvj_g.js";var b=e(t(),1),x=e(r(),1),S=n(),C=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:a}=i();return(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[t]),(0,x.createPortal)((0,S.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,S.jsxs)(`div`,{className:`relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4`,onClick:e=>e.stopPropagation(),children:[(0,S.jsx)(`button`,{onClick:t,className:v(`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:(0,S.jsx)(h,{className:`h-6 w-6 text-white`})}),(0,S.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,S.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,S.jsxs)(`div`,{className:v(`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:[(0,S.jsxs)(`div`,{className:`mb-4`,children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-1`,children:a(`gallery.prompt`)}),(0,S.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] text-sm leading-relaxed`,children:e.prompt})]}),(0,S.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,S.jsx)(f,{className:`h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]`}),(0,S.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:[a(`gallery.model`),`:`]}),(0,S.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:e.model})]}),e.size&&(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,S.jsx)(_,{className:`h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]`}),(0,S.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:[a(`gallery.size`),`:`]}),(0,S.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:e.size})]}),e.quality&&(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,S.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`}),(0,S.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:[a(`gallery.quality`),`:`]}),(0,S.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] capitalize`,children:e.quality})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,S.jsx)(l,{className:`h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]`}),(0,S.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:[a(`gallery.created`),`:`]}),(0,S.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:(e=>new Date(e).toLocaleString(void 0,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}))(e.createdAt)})]})]}),(0,S.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#262626]`,children:[(0,S.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:v(`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:[(0,S.jsx)(m,{className:`h-4 w-4`}),a(`gallery.download`)]}),n&&(0,S.jsx)(`button`,{onClick:()=>n(e.id),className:v(`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:(0,S.jsx)(p,{className:`h-4 w-4`})})]})]})]})]}),document.body)},w=({onImageCountChange:e})=>{let{t}=i(),[n,r]=(0,b.useState)([]),[a,o]=(0,b.useState)(0),[s,l]=(0,b.useState)(!0),[f,h]=(0,b.useState)(!1),[g,_]=(0,b.useState)(null),[x,w]=(0,b.useState)(null),T=(0,b.useCallback)(async(n=0,i=!1)=>{try{n===0?l(!0):h(!0);let t=await y.getGallery({limit:20,offset:n});t.success&&t.data&&(r(i?e=>[...e,...t.data.images]:t.data.images),o(t.data.total),e?.(t.data.total))}catch(e){console.error(`Failed to load gallery:`,e),c.error(t(`imageGallery.loadFailed`))}finally{l(!1),h(!1)}},[e,t]);(0,b.useEffect)(()=>{T()},[T]);let E=()=>{T(n.length,!0)},D=async(n,i)=>{if(i.stopPropagation(),!x){w(n);try{(await y.deleteGalleryImage(n)).success?(r(e=>e.filter(e=>e.id!==n)),o(e=>e-1),e?.(a-1),c.success(t(`imageGallery.deleteSuccess`)),g?.id===n&&_(null)):c.error(t(`imageGallery.deleteFailed`))}catch(e){console.error(`Failed to delete image:`,e),c.error(t(`imageGallery.deleteFailed`))}finally{w(null)}}},O=(e,t)=>{t.stopPropagation();let n=document.createElement(`a`);n.href=e.imageData,n.download=`generated-${e.id}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n)},k=e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`});return s?(0,S.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,S.jsx)(u,{className:`h-8 w-8 animate-spin text-gray-400 dark:text-gray-500`})}):n.length===0?(0,S.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-center`,children:[(0,S.jsx)(d,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 ophelia:text-[#404040] mb-4`}),(0,S.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] mb-2`,children:t(`imageGallery.noImages`)}),(0,S.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373] max-w-sm`,children:t(`imageGallery.noImagesHint`)})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:v(`columns-1 sm:columns-2 lg:columns-3 xl:columns-4`,`gap-4 space-y-4`),children:n.map(e=>(0,S.jsxs)(`div`,{className:v(`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:()=>_(e),children:[(0,S.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`w-full h-auto object-cover`,loading:`lazy`}),(0,S.jsxs)(`div`,{className:v(`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:[(0,S.jsx)(`p`,{className:`text-white text-sm line-clamp-2 mb-2`,children:e.prompt}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,S.jsx)(`span`,{className:`text-white/70 text-xs`,children:k(e.createdAt)}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,S.jsx)(`button`,{onClick:t=>O(e,t),className:v(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-white/30`,`transition-colors`),title:t(`imageGallery.download`),children:(0,S.jsx)(m,{className:`h-4 w-4 text-white`})}),(0,S.jsx)(`button`,{onClick:t=>D(e.id,t),disabled:x===e.id,className:v(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-red-500/80`,`transition-colors`,x===e.id&&`opacity-50 cursor-not-allowed`),title:t(`imageGallery.delete`),children:x===e.id?(0,S.jsx)(u,{className:`h-4 w-4 text-white animate-spin`}):(0,S.jsx)(p,{className:`h-4 w-4 text-white`})})]})]})]})]},e.id))}),n.length<a&&(0,S.jsx)(`div`,{className:`flex justify-center mt-8`,children:(0,S.jsx)(`button`,{onClick:E,disabled:f,className:v(`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:f?(0,S.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(u,{className:`h-4 w-4 animate-spin`}),t(`common.loading`)]}):t(`imageGallery.loadMore`,{current:n.length,total:a})})}),g&&(0,S.jsx)(C,{image:g,onClose:()=>_(null),onDelete:e=>{D(e,{stopPropagation:()=>{}})},onDownload:e=>{O(e,{stopPropagation:()=>{}})}})]})},T=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=i(),[o,l]=(0,b.useState)([]),[d,f]=(0,b.useState)(``),[p,_]=(0,b.useState)(``),[C,w]=(0,b.useState)(``),[T,E]=(0,b.useState)(`1024x1024`),[D,O]=(0,b.useState)(`standard`),[k,A]=(0,b.useState)(!1),[j,M]=(0,b.useState)(null),[N,P]=(0,b.useState)([`512x512`,`768x768`,`1024x1024`]),[F,I]=(0,b.useState)([`standard`,`high`]),[L,R]=(0,b.useState)(null);(0,b.useEffect)(()=>{e&&(async()=>{try{let e=await y.getPlugins();if(e.success&&e.data&&(l(e.data),e.data.length>0)){let t=e.data[0];f(t.id),t.models.length>0&&_(t.models[0]),t.config?.sizes&&(P(t.config.sizes),E(t.config.default_size||t.config.sizes[0]||`1024x1024`)),t.config?.qualities&&(I(t.config.qualities),O(t.config.default_quality||t.config.qualities[0]||`standard`)),R(t.config?.max_prompt_length??null)}}catch(e){console.error(`Failed to load image generation plugins:`,e)}})()},[e]),(0,b.useEffect)(()=>{let e=o.find(e=>e.id===d);e&&(e.models.length>0&&!e.models.includes(p)&&_(e.models[0]),e.config?.sizes&&(P(e.config.sizes),e.config.sizes.includes(T)||E(e.config.default_size||e.config.sizes[0])),e.config?.qualities&&(I(e.config.qualities),e.config.qualities.includes(D)||O(e.config.default_quality||e.config.qualities[0])),R(e.config?.max_prompt_length??null))},[d,o,p,T,D]);let z=async()=>{if(!p||!C.trim()){c.error(r(`imageGeneration.enterPrompt`));return}if(L&&C.length>L){c.error(r(`imageGeneration.promptTooLong`,{max:L.toLocaleString()}));return}A(!0),M(null);try{let e=await y.generate({model:p,prompt:C.trim(),size:T,quality:D});if(e.success&&e.data?.images&&e.data.images.length>0){let i=e.data.images[0],a=null;i.b64_json?a=`data:image/png;base64,${i.b64_json}`:i.url&&(a=i.url),a&&(c.success(r(`imageGeneration.success`)),n?(n(a,C.trim(),p),w(``),M(null),t()):M(a))}else c.error(r(`imageGeneration.failed`))}catch(e){console.error(`Image generation failed:`,e);let t=e instanceof Error?e.message:r(`imageGeneration.failed`);c.error(t)}finally{A(!1)}},B=()=>{if(!j)return;let e=document.createElement(`a`);e.href=j,e.download=`generated-image-${Date.now()}.png`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e)return null;let V=o.find(e=>e.id===d);return(0,x.createPortal)((0,S.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-4`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,S.jsxs)(`div`,{className:v(`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:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(s,{className:`h-5 w-5 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]`}),(0,S.jsx)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:r(`imageGeneration.title`)})]}),(0,S.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors`,children:(0,S.jsx)(h,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,S.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:o.length===0?(0,S.jsxs)(`div`,{className:`text-center py-8`,children:[(0,S.jsx)(s,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]`}),(0,S.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`,children:r(`imageGeneration.noModels`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:r(`settings.plugins.title`)}),(0,S.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),className:v(`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(e=>(0,S.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:r(`imageGeneration.model`)}),(0,S.jsx)(`select`,{value:p,onChange:e=>_(e.target.value),className:v(`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:V?.models.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,S.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:r(`imageGeneration.size`)}),(0,S.jsx)(`select`,{value:T,onChange:e=>E(e.target.value),className:v(`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:N.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:r(`imageGeneration.quality`)}),(0,S.jsx)(`select`,{value:D,onChange:e=>O(e.target.value),className:v(`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:F.map(e=>(0,S.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:r(`imageGeneration.prompt`)}),(0,S.jsx)(`textarea`,{value:C,onChange:e=>w(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:v(`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`,L&&C.length>L&&`border-red-500 dark:border-red-500 ophelia:border-red-500`)}),L&&(0,S.jsxs)(`div`,{className:v(`text-xs mt-1 text-right`,C.length>L?`text-red-500`:`text-gray-500 dark:text-gray-400 ophelia:text-[#737373]`),children:[C.length.toLocaleString(),` /`,` `,L.toLocaleString()]})]}),j&&(0,S.jsxs)(`div`,{className:`relative rounded-xl overflow-hidden border border-gray-200 dark:border-dark-300 ophelia:border-[#262626]`,children:[(0,S.jsx)(`img`,{src:j,alt:`Generated`,className:`w-full h-auto`}),(0,S.jsx)(`button`,{onClick:B,className:v(`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:r(`imageGallery.download`),children:(0,S.jsx)(m,{className:`h-5 w-5 text-gray-700 dark:text-gray-200 ophelia:text-[#fafafa]`})})]})]})}),o.length>0&&(0,S.jsx)(`div`,{className:`p-4 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`,children:(0,S.jsx)(a,{onClick:z,disabled:k||!C.trim()||!p,className:v(`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:k?(0,S.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,S.jsx)(u,{className:`h-4 w-4 animate-spin`}),r(`imageGeneration.generating`)]}):(0,S.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,S.jsx)(g,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},E=()=>{let{t:e}=i(),[t,n]=(0,b.useState)(null),[r,s]=(0,b.useState)(!1),[c,l]=(0,b.useState)(0),u=(0,b.useCallback)(()=>{l(e=>e+1)},[]);return(0,S.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,S.jsxs)(`div`,{className:`max-w-7xl mx-auto p-6`,children:[(0,S.jsxs)(`div`,{className:`text-center max-w-md mx-auto mb-8`,children:[(0,S.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:e(`sidebar.navigation.imagine`)}),(0,S.jsxs)(`p`,{className:`text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed`,children:[e(`gallery.subtitle`),t!==null&&t>0&&(0,S.jsxs)(`span`,{className:`text-gray-400 dark:text-gray-500 ophelia:text-[#737373]`,children:[` `,`· `,e(`gallery.imageCount`,{count:t})]})]}),(0,S.jsxs)(a,{onClick:()=>s(!0),className:v(`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:[(0,S.jsx)(o,{className:`h-4 w-4 mr-2`}),e(`gallery.generate`)]})]}),(0,S.jsx)(w,{onImageCountChange:n},c)]}),(0,S.jsx)(T,{isOpen:r,onClose:()=>s(!1),onImageGenerated:u})]})};export{E as GalleryPage,E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-DWy-cpC1.js";import{m as t,p as n}from"./markdown-vendor-4lCPqxk5.js";import{n as r}from"./react-vendor-BUzyfgnZ.js";import{n as i,t as a}from"./Button-D62PCbMW.js";import{C as ee,Dt as o,H as te,It as ne,O as s,Ot as re,Q as c,R as ie,St as ae,T as l,W as oe,X as se,Z as ce,_t as le,at as ue,d as de,f as fe,ht as u,n as d,ot as pe,pt as me,q as he,t as ge,ut as _e,vt as ve,wt as f,x as ye,xt as be,zt as p}from"./ui-vendor-BFOABH-A.js";import{n as m}from"./appStore-k_e3JAM3.js";import{a as xe,s as h}from"./api-BrzQvj_g.js";import{t as Se}from"./authStore-ge66S03D.js";var g=e(t(),1),_=e(r(),1),v=n(),y=()=>{let{t:e}=i(),{user:t,systemInfo:n}=Se(),r=t?.role===`admin`||(n?.allowUserModelPull??!0),[y,b]=(0,g.useState)([]),[x,Ce]=(0,g.useState)([]),[S,we]=(0,g.useState)([]),[Te,Ee]=(0,g.useState)(!1),[De,Oe]=(0,g.useState)(`all`),[C,ke]=(0,g.useState)(``),[Ae,je]=(0,g.useState)(!1),[w,T]=(0,g.useState)(``),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(null),[Me,A]=(0,g.useState)(null),[j,Ne]=(0,g.useState)(null),[Pe,Fe]=(0,g.useState)(``),[Ie,Le]=(0,g.useState)(!1),[Re,ze]=(0,g.useState)(!1),[Be,M]=(0,g.useState)(!1),[N,Ve]=(0,g.useState)(``),[P,He]=(0,g.useState)(``),[F,Ue]=(0,g.useState)(!1),[We,I]=(0,g.useState)(!1),[L,Ge]=(0,g.useState)(``),[R,Ke]=(0,g.useState)(``),[z,qe]=(0,g.useState)(!1),[Je,Ye]=(0,g.useState)(!1),[B,Xe]=(0,g.useState)(``),[V,Ze]=(0,g.useState)(``),[H,Qe]=(0,g.useState)(null),[$e,et]=(0,g.useState)(!1),[tt,nt]=(0,g.useState)(null),[rt,U]=(0,g.useState)(null),[W,it]=(0,g.useState)([]),[at,ot]=(0,g.useState)(!1),[st,ct]=(0,g.useState)(``),[lt,ut]=(0,g.useState)(``),[dt,ft]=(0,g.useState)(`text-generation`),[pt,mt]=(0,g.useState)(`downloads`),[ht,gt]=(0,g.useState)(null),[_t,vt]=(0,g.useState)({}),[yt,bt]=(0,g.useState)(null),[G,K]=(0,g.useState)(null),[q,J]=(0,g.useState)(null),[xt,Y]=(0,g.useState)(null),[X,St]=(0,g.useState)(new Set([`pull`,`local`])),Z=e=>{St(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Q=(0,g.useCallback)(async()=>{je(!0);try{let[e,t,n,r]=await Promise.all([h.getModels(),h.listRunningModels(),h.getVersion(),h.checkHealth()]);e.success&&b(e.data||[]),t.success&&Ce(Array.isArray(t.data)?t.data:[]),n.success&&n.data&&nt(n.data.version),U(r.success)}catch(t){let n=t instanceof Error?t.message:String(t);p.error(e(`modelManager.pull.failed`)+`: `+n),U(!1)}finally{je(!1)}},[e]),Ct=async()=>{Ee(!0);try{let e=await h.getLibraryModels();e.success&&e.data&&we(e.data)}catch(e){console.error(`Failed to load library models:`,e)}finally{Ee(!1)}};(0,g.useEffect)(()=>{Q(),Ct()},[]),(0,g.useEffect)(()=>{let e=setTimeout(()=>{ut(st)},300);return()=>clearTimeout(e)},[st]);let wt=async()=>{ot(!0);try{let e=await xe.getModels({task:dt,search:lt||void 0,sort:pt,limit:30});e.success&&e.data&&it(e.data)}catch(e){console.error(`Failed to load HuggingFace models:`,e)}finally{ot(!1)}};(0,g.useEffect)(()=>{X.has(`huggingface`)&&wt()},[X,dt,lt,pt]);let Tt=(0,g.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){bt(e);try{let r=await xe.getGgufFiles(t,n);r.success&&r.data&&vt(t=>({...t,[e]:r.data}))}catch(e){console.error(`Failed to load GGUF files:`,e)}finally{bt(null)}}},[]),Et=(0,g.useCallback)(e=>{ht===e?gt(null):(gt(e),_t[e]||Tt(e))},[ht,_t,Tt]),Dt=(0,g.useCallback)((t,n)=>{if(!r){p.error(e(`modelManager.pull.restricted`));return}if(!G){K(t),J({status:`starting`});try{let e=h.pullModelStream(t,e=>{J(e)},()=>{J(null),K(null),Y(null),p.success(`Downloaded ${n}`),Q()},e=>{J(null),K(null),Y(null),p.error(`Failed to download: ${e}`)});Y(()=>e)}catch{J(null),K(null),p.error(`Failed to start download`)}}},[r,G,Q,e]),Ot=(0,g.useCallback)(()=>{xt&&(xt(),Y(null),K(null),J(null))},[xt]),kt=async t=>{if(!r){p.error(e(`modelManager.pull.restricted`));return}let n=t||w.trim();if(!n){p.error(e(`modelManager.pull.enterName`));return}t&&T(t),D(!0),k({status:`starting`});try{let t=h.pullModelStream(n,e=>{k(e)},()=>{k(null),D(!1),A(null),p.success(e(`modelManager.pull.success`,{name:n})),T(``),Q()},t=>{k(null),D(!1),A(null),p.error(e(`modelManager.pull.failed`)+`: `+t)});A(()=>t)}catch(t){let n=t instanceof Error?t.message:String(t);p.error(e(`modelManager.pull.failed`)+`: `+n),k(null),D(!1),A(null)}},At=()=>{Me&&(Me(),A(null),D(!1),k(null),p.success(e(`modelManager.pull.cancelled`)))},jt=async t=>{if(confirm(e(`modelManager.local.deleteConfirm`,{name:t})))try{await h.deleteModel(t),p.success(e(`modelManager.local.deleteSuccess`,{name:t})),await Q()}catch(t){let n=t instanceof Error?t.message:String(t);p.error(e(`modelManager.local.deleteFailed`)+`: `+n)}},Mt=async t=>{ze(!0),Fe(t),Le(!0);try{let n=await h.showModel(t,!0);n.success&&n.data?Ne(n.data):p.error(e(`modelManager.modals.details.noDetails`))}catch(t){let n=t instanceof Error?t.message:String(t);p.error(e(`modelManager.modals.details.noDetails`)+`: `+n)}finally{ze(!1)}},Nt=async()=>{if(!N.trim()||!P.trim()){p.error(e(`modelManager.modals.copy.enterBoth`));return}Ue(!0);try{await h.copyModel(N.trim(),P.trim()),p.success(e(`modelManager.modals.copy.success`,{name:P})),M(!1),Ve(``),He(``),await Q()}catch(t){let n=t instanceof Error?t.message:String(t);p.error(e(`modelManager.modals.copy.failed`)+`: `+n)}finally{Ue(!1)}},Pt=async()=>{if(!L.trim()||!R.trim()){p.error(e(`modelManager.modals.create.enterBoth`));return}qe(!0);try{await h.createModel({model:L.trim(),modelfile:R.trim()}),p.success(e(`modelManager.modals.create.success`,{name:L})),I(!1),Ge(``),Ke(``),await Q()}catch(t){let n=t instanceof Error?t.message:String(t);p.error(e(`modelManager.modals.create.failed`)+`: `+n)}finally{qe(!1)}},Ft=async()=>{if(!B.trim()||!V.trim()){p.error(e(`modelManager.modals.embeddings.enterBoth`));return}et(!0),Qe(null);try{let t=await h.generateEmbeddings({model:B.trim(),input:V.trim()});if(t.success&&t.data){let n=t.data.embeddings?.[0]||[];Qe(n),p.success(e(`modelManager.modals.embeddings.success`,{count:n.length}))}}catch(t){let n=t instanceof Error?t.message:String(t);p.error(e(`modelManager.modals.embeddings.failed`)+`: `+n)}finally{et(!1)}},$=e=>{let t=e/(1024*1024*1024);return t>=1?`${t.toFixed(2)} GB`:`${(e/(1024*1024)).toFixed(1)} MB`},It=e=>Array.isArray(x)&&x.some(t=>t.name===e),Lt=()=>y.reduce((e,t)=>e+t.size,0),Rt=()=>x.reduce((e,t)=>e+(t.size_vram||0),0),zt=e=>y.some(t=>t.name===e||t.name.startsWith(e+`:`)),Bt=S.filter(e=>{let t=De===`all`||e.category===De,n=!C||e.name.toLowerCase().includes(C.toLowerCase())||e.description.toLowerCase().includes(C.toLowerCase());return t&&n}),Vt=[`all`,...new Set(S.map(e=>e.category))],Ht=(0,g.useMemo)(()=>S.length>0?S.slice(0,10).map(e=>({name:e.name,category:e.category,size:e.sizes?.[0]||``})):[{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`}],[S]);return Ae?(0,v.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,v.jsxs)(`div`,{className:`flex items-center gap-3 text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3]`,children:[(0,v.jsx)(s,{className:`h-5 w-5 animate-spin`}),e(`modelManager.loading`)]})}):(0,v.jsxs)(`div`,{className:`space-y-4`,children:[(0,v.jsx)(`div`,{className:m(`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:(0,v.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(`div`,{className:m(`w-2.5 h-2.5 rounded-full`,rt?`bg-green-500 ophelia:bg-[#4ade80]`:`bg-red-500 ophelia:bg-[#f87171]`)}),(0,v.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5]`,children:e(rt?`modelManager.systemStatus.online`:`modelManager.systemStatus.offline`)})]}),tt&&(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]`,children:[(0,v.jsx)(ee,{className:`h-4 w-4`}),(0,v.jsxs)(`span`,{children:[`v`,tt]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]`,children:[(0,v.jsx)(c,{className:`h-4 w-4`}),(0,v.jsxs)(`span`,{children:[y.length,` `,y.length===1?e(`modelManager.systemStatus.models`):e(`modelManager.systemStatus.models_plural`)]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]`,children:[(0,v.jsx)(oe,{className:`h-4 w-4`}),(0,v.jsx)(`span`,{children:$(Lt())})]}),x.length>0&&(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-green-600 dark:text-green-400 ophelia:text-[#4ade80]`,children:[(0,v.jsx)(ne,{className:`h-4 w-4`}),(0,v.jsxs)(`span`,{children:[x.length,` `,e(`modelManager.systemStatus.running`),` (`,$(Rt()),` `,e(`modelManager.systemStatus.vram`),`)`]})]})]}),(0,v.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,v.jsxs)(a,{onClick:Q,variant:`outline`,size:`sm`,className:m(`gap-1.5`,`ophelia:border-[#262626] ophelia:text-[#a3a3a3]`,`ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]`),children:[(0,v.jsx)(s,{className:`h-3.5 w-3.5`}),e(`common.refresh`)]})})]})}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`button`,{onClick:()=>Z(`pull`),className:m(`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:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:m(`p-2 rounded-lg`,`bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20`),children:(0,v.jsx)(u,{className:`h-5 w-5 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`,children:e(`modelManager.sections.pull`)})]}),X.has(`pull`)?(0,v.jsx)(f,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`}):(0,v.jsx)(o,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})]}),X.has(`pull`)&&(0,v.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,v.jsxs)(`div`,{className:`flex gap-2`,children:[(0,v.jsxs)(`div`,{className:`relative flex-1`,children:[(0,v.jsx)(l,{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]`}),(0,v.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:e(`modelManager.pull.placeholder`),className:m(`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:E||!r,onKeyDown:e=>e.key===`Enter`&&!E&&r&&kt()})]}),E?(0,v.jsxs)(a,{onClick:At,variant:`outline`,className:m(`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:[(0,v.jsx)(d,{className:`h-4 w-4`}),e(`modelManager.pull.cancel`)]}):(0,v.jsxs)(a,{onClick:()=>kt(),disabled:!w.trim()||!r,className:m(`px-4 py-2.5 gap-2`,`ophelia:bg-[#9333ea] ophelia:hover:bg-[#7c3aed] ophelia:text-white`),children:[(0,v.jsx)(u,{className:`h-4 w-4`}),e(`modelManager.pull.button`)]})]}),E&&O&&(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,v.jsx)(`span`,{className:`text-sm font-medium text-gray-800 dark:text-dark-700 ophelia:text-[#e5e5e5]`,children:O.status===`starting`?e(`modelManager.progress.starting`):O.status.startsWith(`pulling`)?`${e(`modelManager.progress.pullingLayer`)} ${O.status.replace(`pulling `,``)}`:O.status.startsWith(`verifying sha256`)?e(`modelManager.progress.verifyingDigest`):O.status===`writing manifest`?e(`modelManager.progress.writing`):O.status===`removing any unused layers`?e(`modelManager.progress.cleaning`):O.status}),O.percent!==void 0&&(0,v.jsxs)(`span`,{className:`text-sm font-mono text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3]`,children:[O.percent,`%`]})]}),O.percent!==void 0&&(0,v.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-400 ophelia:bg-[#262626] rounded-full h-2 overflow-hidden`,children:(0,v.jsx)(`div`,{className:m(`h-2 rounded-full transition-all duration-300`,`bg-primary-500 dark:bg-primary-400 ophelia:bg-[#9333ea]`),style:{width:`${O.percent}%`}})}),O.total&&O.completed&&(0,v.jsxs)(`div`,{className:`mt-2 text-xs text-gray-600 dark:text-dark-600 ophelia:text-[#737373]`,children:[$(O.completed),` /`,` `,$(O.total)]})]}),!r&&(0,v.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-300`,children:e(`modelManager.pull.restricted`)}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`p`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 ophelia:text-[#737373] mb-2`,children:e(`modelManager.pull.popular`)}),(0,v.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Ht.map(e=>(0,v.jsxs)(`button`,{onClick:()=>T(e.name),disabled:E||!r,className:m(`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:[e.name,(0,v.jsx)(`span`,{className:`ml-1 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]`,children:e.size})]},e.name))})]}),(0,v.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,className:m(`inline-flex items-center gap-1.5 text-xs`,`text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]`,`hover:underline`),children:[(0,v.jsx)(me,{className:`h-3 w-3`}),e(`modelManager.pull.browseAll`)]})]})]}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`button`,{onClick:()=>Z(`library`),className:m(`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:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:m(`p-2 rounded-lg`,`bg-cyan-100 dark:bg-cyan-900/30 ophelia:bg-[#06b6d4]/20`),children:(0,v.jsx)(be,{className:`h-5 w-5 text-cyan-600 dark:text-cyan-400 ophelia:text-[#22d3ee]`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`,children:e(`modelManager.sections.library`)}),(0,v.jsxs)(`span`,{className:m(`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:[S.length,` `,e(`modelManager.library.available`)]})]}),X.has(`library`)?(0,v.jsx)(f,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`}):(0,v.jsx)(o,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})]}),X.has(`library`)&&(0,v.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,v.jsxs)(`div`,{className:`relative flex-1`,children:[(0,v.jsx)(l,{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]`}),(0,v.jsx)(`input`,{type:`text`,value:C,onChange:e=>ke(e.target.value),placeholder:e(`modelManager.library.search`),className:m(`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]`)})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(pe,{className:`h-4 w-4 text-gray-400 ophelia:text-[#525252]`}),(0,v.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Vt.map(e=>(0,v.jsx)(`button`,{onClick:()=>Oe(e),className:m(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,De===e?`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:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),Te?(0,v.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,v.jsx)(s,{className:`h-5 w-5 animate-spin text-gray-400 ophelia:text-[#737373]`})}):Bt.length===0?(0,v.jsx)(`div`,{className:`text-center py-8 text-gray-500 ophelia:text-[#737373]`,children:e(`modelManager.library.noResults`)}):(0,v.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:Bt.map(t=>{let n=zt(t.name);return(0,v.jsxs)(`div`,{className:m(`p-4 rounded-lg border transition-all`,`bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]`,n?`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:[(0,v.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-2`,children:[(0,v.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`,children:t.name}),n&&(0,v.jsxs)(`span`,{className:m(`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:[(0,v.jsx)(re,{className:`h-3 w-3`}),e(`modelManager.library.installed`)]})]}),(0,v.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] mb-3 line-clamp-2`,children:t.description}),(0,v.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[t.sizes.slice(0,4).map(e=>(0,v.jsx)(`span`,{className:m(`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:e},e)),t.sizes.length>4&&(0,v.jsx)(`span`,{className:`text-xs text-gray-400 ophelia:text-[#737373]`,children:e(`modelManager.library.more`,{count:t.sizes.length-4})})]}),(0,v.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-gray-500 ophelia:text-[#737373]`,children:[t.pulls&&(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(u,{className:`h-3 w-3`}),t.pulls]}),(0,v.jsx)(`span`,{className:m(`px-1.5 py-0.5 rounded capitalize`,`bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a]`),children:t.category})]}),(0,v.jsxs)(a,{onClick:()=>{X.has(`pull`)||Z(`pull`),kt(t.name)},variant:`outline`,size:`sm`,disabled:E||!r,className:m(`gap-1 text-xs`,`ophelia:border-[#262626] ophelia:text-[#a3a3a3]`,`ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]`),children:[(0,v.jsx)(u,{className:`h-3 w-3`}),e(`modelManager.pull.button`)]})]})]},t.name)})}),(0,v.jsx)(`div`,{className:`flex justify-center`,children:(0,v.jsxs)(a,{onClick:Ct,variant:`outline`,size:`sm`,disabled:Te,className:m(`gap-1.5`,`ophelia:border-[#262626] ophelia:text-[#a3a3a3]`,`ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]`),children:[(0,v.jsx)(s,{className:m(`h-3.5 w-3.5`,Te&&`animate-spin`)}),e(`modelManager.library.refresh`)]})})]})]}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`button`,{onClick:()=>Z(`huggingface`),className:m(`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:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:m(`p-2 rounded-lg`,`bg-yellow-100 dark:bg-yellow-900/30 ophelia:bg-[#eab308]/20`),children:(0,v.jsx)(ge,{className:`h-5 w-5 text-yellow-600 dark:text-yellow-400 ophelia:text-[#facc15]`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`,children:e(`modelManager.sections.huggingface`,`HuggingFace Hub`)}),W.length>0&&(0,v.jsxs)(`span`,{className:m(`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:[W.length,` `,e(`modelManager.library.available`,`available`)]})]}),X.has(`huggingface`)?(0,v.jsx)(f,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`}):(0,v.jsx)(o,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})]}),X.has(`huggingface`)&&(0,v.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,v.jsxs)(`div`,{className:`relative flex-1`,children:[(0,v.jsx)(l,{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]`}),(0,v.jsx)(`input`,{type:`text`,value:st,onChange:e=>ct(e.target.value),placeholder:e(`modelManager.huggingface.search`,`Search HuggingFace models...`),className:m(`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]`)})]}),(0,v.jsxs)(`select`,{value:dt,onChange:e=>ft(e.target.value),className:m(`px-3 py-2 rounded-lg border text-sm min-w-[160px]`,`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]`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:[(0,v.jsx)(`option`,{value:`text-generation`,children:e(`modelManager.huggingface.tasks.textGen`,`Text Generation`)}),(0,v.jsx)(`option`,{value:`text-to-speech`,children:e(`modelManager.huggingface.tasks.tts`,`Text to Speech`)}),(0,v.jsx)(`option`,{value:`text-to-image`,children:e(`modelManager.huggingface.tasks.image`,`Text to Image`)}),(0,v.jsx)(`option`,{value:`automatic-speech-recognition`,children:e(`modelManager.huggingface.tasks.stt`,`Speech Recognition`)})]}),(0,v.jsxs)(`select`,{value:pt,onChange:e=>mt(e.target.value),className:m(`px-3 py-2 rounded-lg border text-sm min-w-[140px]`,`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]`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:[(0,v.jsx)(`option`,{value:`downloads`,children:e(`modelManager.huggingface.sort.downloads`,`Most Downloads`)}),(0,v.jsx)(`option`,{value:`likes`,children:e(`modelManager.huggingface.sort.likes`,`Most Liked`)}),(0,v.jsx)(`option`,{value:`lastModified`,children:e(`modelManager.huggingface.sort.recent`,`Recently Updated`)})]})]}),!r&&(0,v.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-300`,children:e(`modelManager.pull.restricted`)}),at?(0,v.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,v.jsx)(te,{className:`h-5 w-5 animate-spin text-gray-400 ophelia:text-[#737373]`})}):W.length===0?(0,v.jsx)(`div`,{className:`text-center py-8 text-gray-500 ophelia:text-[#737373]`,children:e(`modelManager.huggingface.noResults`,`No models found. Try adjusting your search or filters.`)}):(0,v.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:W.map(t=>{let n=ht===t.id,i=yt===t.id,a=_t[t.id]||[];return(0,v.jsxs)(`div`,{className:m(`rounded-lg border transition-all overflow-hidden`,`bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]`,`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:[(0,v.jsxs)(`div`,{className:`p-4 cursor-pointer`,onClick:()=>Et(t.id),children:[(0,v.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-2`,children:[(0,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa] truncate`,children:t.id}),t.gated&&(0,v.jsx)(`span`,{className:m(`px-1.5 py-0.5 rounded text-xs`,`bg-yellow-100 dark:bg-yellow-900/30 ophelia:bg-[#eab308]/20`,`text-yellow-700 dark:text-yellow-400 ophelia:text-[#facc15]`),children:e(`modelManager.huggingface.gated`,`Gated`)})]}),(0,v.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 ophelia:text-[#737373] mt-0.5`,children:[e(`modelManager.huggingface.by`,`by`),` `,t.author]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,v.jsx)(`a`,{href:`https://huggingface.co/${t.id}`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg hover:bg-gray-200 dark:hover:bg-dark-300 ophelia:hover:bg-[#262626] transition-colors`,title:e(`modelManager.huggingface.viewOnHF`,`View on HuggingFace`),children:(0,v.jsx)(me,{className:`h-4 w-4 text-gray-400 dark:text-gray-500 ophelia:text-[#525252]`})}),(0,v.jsx)(o,{className:m(`h-4 w-4 text-gray-400 transition-transform`,n&&`rotate-180`)})]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-500 dark:text-dark-600 ophelia:text-[#737373]`,children:[(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(u,{className:`h-3.5 w-3.5`}),t.downloads>=1e6?`${(t.downloads/1e6).toFixed(1)}M`:t.downloads>=1e3?`${(t.downloads/1e3).toFixed(1)}K`:t.downloads]}),(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(se,{className:`h-3.5 w-3.5`}),t.likes>=1e3?`${(t.likes/1e3).toFixed(1)}K`:t.likes]}),t.pipeline_tag&&(0,v.jsx)(`span`,{className:m(`px-1.5 py-0.5 rounded`,`bg-gray-200 dark:bg-dark-300 ophelia:bg-[#262626]`),children:t.pipeline_tag})]})]}),n&&(0,v.jsx)(`div`,{className:`px-4 pb-4 pt-1 border-t border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a] bg-white dark:bg-dark-100 ophelia:bg-[#0d0d0d]`,children:i?(0,v.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,v.jsx)(te,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,v.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:e(`modelManager.huggingface.checkingGguf`)})]}):a.length===0?(0,v.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:e(`modelManager.huggingface.noGgufAvailable`)}):(0,v.jsxs)(`div`,{className:`space-y-2`,children:[(0,v.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2`,children:e(`modelManager.huggingface.ggufFilesCount`,{count:a.length})}),a.map(t=>{let n=G===t.ollamaCommand;return(0,v.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 ophelia:bg-[#0a0a0a] border border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`,children:[(0,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 ophelia:text-[#e5e5e5] truncate`,children:t.filename}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,v.jsx)(`span`,{children:t.sizeFormatted}),t.quantization&&(0,v.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 ophelia:bg-[#9333ea]/20 text-purple-700 dark:text-purple-400 ophelia:text-[#a855f7]`,children:t.quantization})]})]}),n?(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:q?.percent===void 0?`...`:`${q.percent}%`}),(0,v.jsx)(`button`,{onClick:e=>{e.stopPropagation(),Ot()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,v.jsx)(d,{className:`h-4 w-4`})})]}):(0,v.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),Dt(t.ollamaCommand,t.filename)},disabled:!!G||!r,className:m(`px-3 py-1.5 rounded-lg text-xs font-medium`,`bg-primary-100 dark:bg-primary-900/30 ophelia:bg-[#9333ea]/20`,`text-primary-700 dark:text-primary-400 ophelia:text-[#a855f7]`,`hover:bg-primary-200 dark:hover:bg-primary-900/50`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,v.jsx)(u,{className:`h-3 w-3 inline mr-1`}),e(`models.pull`)]})]},t.filename)}),G?.startsWith(`hf.co/`)&&G.includes(t.id)&&q?.percent!==void 0&&(0,v.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,v.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${q.percent}%`}})})]})})]},t.id)})}),(0,v.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[(0,v.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,className:m(`inline-flex items-center gap-1.5 text-xs`,`text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]`,`hover:underline`),children:[(0,v.jsx)(me,{className:`h-3 w-3`}),e(`modelManager.huggingface.browseAll`,`Browse all on HuggingFace`)]}),(0,v.jsxs)(a,{onClick:wt,variant:`outline`,size:`sm`,disabled:at,className:m(`gap-1.5`,`ophelia:border-[#262626] ophelia:text-[#a3a3a3]`,`ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]`),children:[(0,v.jsx)(s,{className:m(`h-3.5 w-3.5`,at&&`animate-spin`)}),e(`modelManager.library.refresh`,`Refresh`)]})]})]})]}),Array.isArray(x)&&x.length>0&&(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,v.jsx)(`div`,{className:m(`p-2 rounded-lg`,`bg-green-100 dark:bg-green-900/30 ophelia:bg-[#22c55e]/20`),children:(0,v.jsx)(ne,{className:`h-5 w-5 text-green-600 dark:text-green-400 ophelia:text-[#4ade80]`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`,children:e(`modelManager.sections.running`)}),(0,v.jsxs)(`span`,{className:m(`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:[x.length,` `,e(`modelManager.systemStatus.running`)]})]}),(0,v.jsx)(`div`,{className:`space-y-2`,children:x.map(t=>(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:m(`w-2 h-2 rounded-full animate-pulse`,`bg-green-500 ophelia:bg-[#4ade80]`)}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`font-medium text-green-800 dark:text-green-400 ophelia:text-[#4ade80]`,children:t.name}),(0,v.jsxs)(`div`,{className:`flex items-center gap-3 text-sm text-green-600 dark:text-green-500 ophelia:text-[#22c55e]/80`,children:[(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(ie,{className:`h-3 w-3`}),e(`modelManager.systemStatus.vram`),`:`,` `,$(t.size_vram||0)]}),t.size&&(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(c,{className:`h-3 w-3`}),e(`models.size`),`: `,$(t.size)]})]})]})]}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsx)(ge,{className:`h-3 w-3`}),e(`modelManager.local.running`)]})]},t.name))})]}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`button`,{onClick:()=>Z(`local`),className:m(`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:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:m(`p-2 rounded-lg`,`bg-blue-100 dark:bg-blue-900/30 ophelia:bg-[#a855f7]/20`),children:(0,v.jsx)(c,{className:`h-5 w-5 text-blue-600 dark:text-blue-400 ophelia:text-[#a855f7]`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`,children:e(`modelManager.sections.local`)}),(0,v.jsxs)(`span`,{className:m(`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:[y.length,` `,e(`modelManager.local.installed`)]})]}),X.has(`local`)?(0,v.jsx)(f,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`}):(0,v.jsx)(o,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})]}),X.has(`local`)&&(0,v.jsx)(`div`,{className:`p-4 pt-0`,children:y.length===0?(0,v.jsxs)(`div`,{className:m(`text-center py-12 rounded-lg border-2 border-dashed`,`border-gray-200 dark:border-dark-300 ophelia:border-[#262626]`),children:[(0,v.jsx)(c,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600 ophelia:text-[#525252]`}),(0,v.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 ophelia:text-[#737373] mb-2`,children:e(`modelManager.local.noModels`)}),(0,v.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-500 ophelia:text-[#525252]`,children:e(`modelManager.local.pullToStart`)})]}):(0,v.jsx)(`div`,{className:`space-y-3`,children:y.map(t=>(0,v.jsx)(`div`,{className:m(`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:(0,v.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,v.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`,children:t.name}),It(t.name)&&(0,v.jsxs)(`span`,{className:m(`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:[(0,v.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500 ophelia:bg-[#4ade80] animate-pulse`}),e(`modelManager.local.running`)]})]}),(0,v.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:[(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(c,{className:`h-3.5 w-3.5`}),$(t.size)]}),t.details?.parameter_size&&(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(le,{className:`h-3.5 w-3.5`}),t.details.parameter_size]}),t.details?.quantization_level&&(0,v.jsx)(`span`,{className:m(`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:t.details.quantization_level}),t.details?.family&&(0,v.jsx)(`span`,{className:`text-gray-500 dark:text-gray-500 ophelia:text-[#737373]`,children:t.details.family})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-400 dark:text-dark-500 ophelia:text-[#525252] mt-2`,children:[(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(ae,{className:`h-3 w-3`}),new Date(t.modified_at).toLocaleDateString()]}),(0,v.jsxs)(`span`,{className:`flex items-center gap-1 font-mono truncate max-w-[200px]`,title:t.digest,children:[(0,v.jsx)(ce,{className:`h-3 w-3`}),t.digest.slice(0,12),`...`]})]})]}),(0,v.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,v.jsxs)(a,{onClick:()=>Mt(t.name),variant:`outline`,size:`sm`,className:m(`gap-1.5`,`ophelia:border-[#262626] ophelia:text-[#a3a3a3]`,`ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]`),children:[(0,v.jsx)(he,{className:`h-3.5 w-3.5`}),e(`modelManager.local.info`)]}),(0,v.jsxs)(a,{onClick:()=>{Ve(t.name),M(!0)},variant:`outline`,size:`sm`,className:m(`gap-1.5`,`ophelia:border-[#262626] ophelia:text-[#a3a3a3]`,`ophelia:hover:bg-[#1a1a1a] ophelia:hover:text-[#fafafa]`),children:[(0,v.jsx)(ve,{className:`h-3.5 w-3.5`}),e(`modelManager.local.copy`)]}),(0,v.jsxs)(a,{onClick:()=>jt(t.name),variant:`outline`,size:`sm`,className:m(`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:[(0,v.jsx)(de,{className:`h-3.5 w-3.5`}),e(`modelManager.local.delete`)]})]})]})},t.name))})})]}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`button`,{onClick:()=>Z(`advanced`),className:m(`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:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:m(`p-2 rounded-lg`,`bg-amber-100 dark:bg-amber-900/30 ophelia:bg-[#f59e0b]/20`),children:(0,v.jsx)(ye,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 ophelia:text-[#fbbf24]`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 ophelia:text-[#fafafa]`,children:e(`modelManager.sections.advanced`)})]}),X.has(`advanced`)?(0,v.jsx)(f,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`}):(0,v.jsx)(o,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})]}),X.has(`advanced`)&&(0,v.jsx)(`div`,{className:`p-4 pt-0`,children:(0,v.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3`,children:[(0,v.jsxs)(a,{onClick:()=>I(!0),variant:`outline`,className:m(`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:[(0,v.jsx)(_e,{className:`h-5 w-5 text-purple-500 ophelia:text-[#a855f7]`}),(0,v.jsxs)(`div`,{className:`text-left`,children:[(0,v.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.createModel`)}),(0,v.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.fromModelfile`)})]})]}),(0,v.jsxs)(a,{onClick:()=>M(!0),variant:`outline`,className:m(`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:[(0,v.jsx)(ve,{className:`h-5 w-5 text-blue-500 ophelia:text-[#60a5fa]`}),(0,v.jsxs)(`div`,{className:`text-left`,children:[(0,v.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.copyModel`)}),(0,v.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.duplicateExisting`)})]})]}),(0,v.jsxs)(a,{onClick:()=>Ye(!0),variant:`outline`,className:m(`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:[(0,v.jsx)(fe,{className:`h-5 w-5 text-green-500 ophelia:text-[#4ade80]`}),(0,v.jsxs)(`div`,{className:`text-left`,children:[(0,v.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.testEmbeddings`)}),(0,v.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.generateVectors`)})]})]}),(0,v.jsxs)(a,{onClick:async()=>{try{(await h.checkHealth()).success&&(U(!0),p.success(e(`modelManager.advanced.healthy`)))}catch{U(!1),p.error(e(`modelManager.systemStatus.offline`))}},variant:`outline`,className:m(`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:[(0,v.jsx)(ue,{className:`h-5 w-5 text-rose-500 ophelia:text-[#fb7185]`}),(0,v.jsxs)(`div`,{className:`text-left`,children:[(0,v.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.healthCheck`)}),(0,v.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.testConnection`)})]})]})]})})]}),Ie&&(0,_.createPortal)((0,v.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-4`,children:[(0,v.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>Le(!1)}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`div`,{className:m(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`),children:[(0,v.jsxs)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:[e(`modelManager.modals.details.title`),`: `,Pe]}),(0,v.jsx)(`button`,{onClick:()=>Le(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]`,children:(0,v.jsx)(d,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})})]}),(0,v.jsx)(`div`,{className:`overflow-y-auto max-h-[calc(85vh-60px)] p-4 space-y-4`,children:Re?(0,v.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,v.jsx)(s,{className:`h-6 w-6 animate-spin text-gray-400 ophelia:text-[#737373]`})}):j?(0,v.jsxs)(v.Fragment,{children:[j.details&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2`,children:e(`modelManager.modals.details.info`)}),(0,v.jsx)(`div`,{className:m(`p-3 rounded-lg text-sm`,`bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212]`),children:(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[j.details.family&&(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{className:`text-gray-500 ophelia:text-[#737373]`,children:[e(`modelManager.modals.details.family`),`:`]}),` `,(0,v.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:j.details.family})]}),j.details.parameter_size&&(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{className:`text-gray-500 ophelia:text-[#737373]`,children:[e(`modelManager.modals.details.parameters`),`:`]}),` `,(0,v.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:j.details.parameter_size})]}),j.details.quantization_level&&(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{className:`text-gray-500 ophelia:text-[#737373]`,children:[e(`modelManager.modals.details.quantization`),`:`]}),` `,(0,v.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:j.details.quantization_level})]}),j.details.format&&(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{className:`text-gray-500 ophelia:text-[#737373]`,children:[e(`modelManager.modals.details.format`),`:`]}),` `,(0,v.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:j.details.format})]})]})})]}),j.system&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2`,children:e(`modelManager.modals.details.systemPrompt`)}),(0,v.jsx)(`pre`,{className:m(`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:j.system})]}),j.template&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2`,children:e(`modelManager.modals.details.template`)}),(0,v.jsx)(`pre`,{className:m(`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:j.template})]}),j.parameters&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2`,children:e(`modelManager.modals.details.parameters`)}),(0,v.jsx)(`pre`,{className:m(`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:j.parameters})]}),j.license&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2`,children:e(`modelManager.modals.details.license`)}),(0,v.jsx)(`pre`,{className:m(`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:j.license})]}),j.modelfile&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-2`,children:e(`modelManager.modals.details.modelfile`)}),(0,v.jsx)(`pre`,{className:m(`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:j.modelfile})]})]}):(0,v.jsx)(`p`,{className:`text-center text-gray-500 ophelia:text-[#737373]`,children:e(`modelManager.modals.details.noDetails`)})})]})]}),document.body),Be&&(0,_.createPortal)((0,v.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-4`,children:[(0,v.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>M(!1)}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`div`,{className:m(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`),children:[(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:e(`modelManager.modals.copy.title`)}),(0,v.jsx)(`button`,{onClick:()=>M(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]`,children:(0,v.jsx)(d,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})})]}),(0,v.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:e(`modelManager.modals.copy.source`)}),(0,v.jsxs)(`select`,{value:N,onChange:e=>Ve(e.target.value),className:m(`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:[(0,v.jsx)(`option`,{value:``,children:e(`modelManager.modals.copy.selectModel`)}),y.map(e=>(0,v.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:e(`modelManager.modals.copy.newName`)}),(0,v.jsx)(`input`,{type:`text`,value:P,onChange:e=>He(e.target.value),placeholder:e(`modelManager.modals.copy.placeholder`),className:m(`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]`)})]}),(0,v.jsxs)(a,{onClick:Nt,disabled:!N.trim()||!P.trim()||F,className:m(`w-full gap-2`,`ophelia:bg-[#9333ea] ophelia:hover:bg-[#7c3aed] ophelia:text-white`),children:[F?(0,v.jsx)(s,{className:`h-4 w-4 animate-spin`}):(0,v.jsx)(ve,{className:`h-4 w-4`}),e(F?`modelManager.modals.copy.copying`:`modelManager.modals.copy.button`)]})]})]})]}),document.body),We&&(0,_.createPortal)((0,v.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-4`,children:[(0,v.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>I(!1)}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`div`,{className:m(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`),children:[(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:e(`modelManager.modals.create.title`)}),(0,v.jsx)(`button`,{onClick:()=>I(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]`,children:(0,v.jsx)(d,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})})]}),(0,v.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:e(`modelManager.modals.create.name`)}),(0,v.jsx)(`input`,{type:`text`,value:L,onChange:e=>Ge(e.target.value),placeholder:e(`modelManager.modals.create.namePlaceholder`),className:m(`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]`)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:e(`modelManager.modals.create.modelfile`)}),(0,v.jsx)(`textarea`,{value:R,onChange:e=>Ke(e.target.value),placeholder:e(`modelManager.modals.create.modelfilePlaceholder`),rows:8,className:m(`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`)}),(0,v.jsxs)(`p`,{className:`mt-1 text-xs text-gray-500 ophelia:text-[#737373]`,children:[e(`modelManager.modals.create.see`),` `,(0,v.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:e(`modelManager.modals.create.docs`)}),` `,e(`modelManager.modals.create.docsLink`)]})]}),(0,v.jsxs)(a,{onClick:Pt,disabled:!L.trim()||!R.trim()||z,className:m(`w-full gap-2`,`ophelia:bg-[#9333ea] ophelia:hover:bg-[#7c3aed] ophelia:text-white`),children:[z?(0,v.jsx)(s,{className:`h-4 w-4 animate-spin`}):(0,v.jsx)(_e,{className:`h-4 w-4`}),e(z?`modelManager.modals.create.creating`:`modelManager.modals.create.button`)]})]})]})]}),document.body),Je&&(0,_.createPortal)((0,v.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-4`,children:[(0,v.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>Ye(!1)}),(0,v.jsxs)(`div`,{className:m(`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:[(0,v.jsxs)(`div`,{className:m(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300 ophelia:border-[#1a1a1a]`),children:[(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa]`,children:e(`modelManager.modals.embeddings.title`)}),(0,v.jsx)(`button`,{onClick:()=>Ye(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a]`,children:(0,v.jsx)(d,{className:`h-5 w-5 text-gray-500 ophelia:text-[#737373]`})})]}),(0,v.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:e(`modelManager.modals.embeddings.model`)}),(0,v.jsxs)(`select`,{value:B,onChange:e=>Xe(e.target.value),className:m(`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:[(0,v.jsx)(`option`,{value:``,children:e(`modelManager.modals.embeddings.selectModel`)}),y.map(e=>(0,v.jsx)(`option`,{value:e.name,children:e.name},e.name))]}),(0,v.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 ophelia:text-[#737373]`,children:e(`modelManager.modals.embeddings.recommended`)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:e(`modelManager.modals.embeddings.input`)}),(0,v.jsx)(`textarea`,{value:V,onChange:e=>Ze(e.target.value),placeholder:e(`modelManager.modals.embeddings.placeholder`),rows:3,className:m(`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`)})]}),(0,v.jsxs)(a,{onClick:Ft,disabled:!B.trim()||!V.trim()||$e,className:m(`w-full gap-2`,`ophelia:bg-[#9333ea] ophelia:hover:bg-[#7c3aed] ophelia:text-white`),children:[$e?(0,v.jsx)(s,{className:`h-4 w-4 animate-spin`}):(0,v.jsx)(fe,{className:`h-4 w-4`}),e($e?`modelManager.modals.embeddings.generating`:`modelManager.modals.embeddings.button`)]}),H&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 ophelia:text-[#a3a3a3] mb-1`,children:e(`modelManager.modals.embeddings.result`,{count:H.length})}),(0,v.jsxs)(`pre`,{className:m(`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:[`[`,H.slice(0,10).join(`, `),H.length>10&&`, ...`,` ]`]})]})]})]})]}),document.body)]})},b=()=>{let{t:e}=i();return(0,v.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,v.jsxs)(`div`,{className:`max-w-6xl mx-auto p-6`,children:[(0,v.jsxs)(`div`,{className:`text-center max-w-md mx-auto mb-8`,children:[(0,v.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:e(`models.title`)}),(0,v.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed`,children:e(`models.subtitle`)})]}),(0,v.jsx)(y,{})]})})};export{b as ModelsPage,b as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./rolldown-runtime-DWy-cpC1.js";import{m as e,n as t,p as n,r,t as i}from"./markdown-vendor-4lCPqxk5.js";import{t as a}from"./appStore-k_e3JAM3.js";e();var o=n(),s={'code[class*="language-"]':{color:`#f8f8f2`,background:`none`,textShadow:`none`,fontFamily:`'JetBrains Mono', Consolas, Monaco, 'Andale Mono', monospace`,fontSize:`1em`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,wordWrap:`normal`,lineHeight:`1.5`,tabSize:4,hyphens:`none`},'pre[class*="language-"]':{color:`#f8f8f2`,background:`#1a1b26`,textShadow:`none`,fontFamily:`'JetBrains Mono', Consolas, Monaco, 'Andale Mono', monospace`,fontSize:`1em`,textAlign:`left`,whiteSpace:`pre`,wordSpacing:`normal`,wordBreak:`normal`,wordWrap:`normal`,lineHeight:`1.5`,tabSize:4,hyphens:`none`,padding:`1em`,margin:`.5em 0`,overflow:`auto`,borderRadius:`0.5rem`},comment:{color:`#6272a4`},prolog:{color:`#6272a4`},doctype:{color:`#6272a4`},cdata:{color:`#6272a4`},punctuation:{color:`#f8f8f2`},property:{color:`#ff79c6`},tag:{color:`#ff79c6`},boolean:{color:`#bd93f9`},number:{color:`#bd93f9`},constant:{color:`#bd93f9`},symbol:{color:`#bd93f9`},deleted:{color:`#ff5555`},selector:{color:`#50fa7b`},"attr-name":{color:`#50fa7b`},string:{color:`#f1fa8c`},char:{color:`#f1fa8c`},builtin:{color:`#8be9fd`},inserted:{color:`#50fa7b`},operator:{color:`#ff79c6`},entity:{color:`#f8f8f2`,cursor:`help`},url:{color:`#8be9fd`},".language-css .token.string":{color:`#f1fa8c`},".style .token.string":{color:`#f1fa8c`},atrule:{color:`#ff79c6`},"attr-value":{color:`#f1fa8c`},keyword:{color:`#ff79c6`},function:{color:`#50fa7b`},"class-name":{color:`#8be9fd`},regex:{color:`#f1fa8c`},important:{color:`#ff5555`,fontWeight:`bold`},variable:{color:`#f8f8f2`}},c={js:`javascript`,ts:`typescript`,py:`python`,sh:`bash`,shell:`bash`,c:`cpp`,"c++":`cpp`},l=[`javascript`,`typescript`,`python`,`java`,`cpp`,`bash`,`json`,`markdown`,`css`,`html`,`jsx`,`xml`],u=({children:e,language:n,isDark:u=!1,className:d=``})=>{let{theme:f}=a(),p=f.mode===`ophelia`,m=c[n.toLowerCase()]||n.toLowerCase();return l.includes(m)?(0,o.jsx)(r,{language:m,style:p?s:u?t:i,className:d,customStyle:{margin:0,padding:`0.75rem`,borderRadius:`0.5rem`,fontSize:`0.875rem`,...p&&{background:`#1a1b26`}},showLineNumbers:!1,children:e}):(0,o.jsx)(`pre`,{className:`bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1b26] p-3 rounded-lg overflow-x-auto text-sm font-mono ${d}`,children:(0,o.jsx)(`code`,{className:`ophelia:text-[#f8f8f2]`,children:e})})};export{u as t};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-DWy-cpC1.js";import{m as t,p as n}from"./markdown-vendor-4lCPqxk5.js";import{n as r,t as i}from"./Button-D62PCbMW.js";import{At as a,Ft as o,J as s,L as c,O as l,Ot as u,Q as d,S as f,St as p,_ as m,c as h,d as g,gt as _,h as v,ht as y,j as b,l as x,lt as S,mt as C,n as w,o as ee,q as T,t as E,u as D,v as O,y as k,zt as A}from"./ui-vendor-BFOABH-A.js";import{n as j}from"./appStore-k_e3JAM3.js";import"./ui-DuH1cD2f.js";import{c as M,s as N}from"./api-BrzQvj_g.js";import{n as P}from"../assets/index-B1qNw5pA.js";var F=e(t(),1),I=n(),L=({persona:e,onEdit:t,onDelete:n,onDownload:s,onSelect:l,onToggleFavorite:u,isSelected:d=!1,compact:p=!1})=>{let{t:h}=r(),[w,ee]=(0,F.useState)(null),[T,D]=(0,F.useState)(!1),[k,N]=(0,F.useState)(!1),P=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),L=(0,F.useCallback)(async()=>{if(P)try{let t=await M.getMemoryStatus(e.id);t.success&&t.data&&ee(t.data)}catch(e){console.error(`Failed to load memory status:`,e)}},[e.id,P]);(0,F.useEffect)(()=>{L()},[L]);let R=async()=>{if(confirm(h(`personaCard.wipeConfirm`))){N(!0);try{let t=await M.wipeMemories(e.id);t.success?(A.success(h(`personaCard.wipeSuccess`,{count:t.data?.deleted_count||0})),await L()):A.error(h(`personaCard.failed`,{action:`wipe memories`}))}catch(e){A.error(h(`personaCard.failed`,{action:`wipe memories`})),console.error(e)}finally{N(!1),D(!1)}}},z=async()=>{N(!0);try{let t=await M.backupPersona(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-backup.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),A.success(h(`personaCard.backupSuccess`))}catch(e){A.error(h(`personaCard.failed`,{action:`backup persona`})),console.error(e)}finally{N(!1),D(!1)}},B=async()=>{N(!0);try{let t=await M.exportPersonaDNA(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-dna.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),A.success(h(`personaCard.dnaSuccess`))}catch(e){A.error(h(`personaCard.failed`,{action:`export persona DNA`})),console.error(e)}finally{N(!1),D(!1)}},V=()=>e.avatar?e.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(e.name)}&background=6366f1&color=fff&size=128`;return p?(0,I.jsxs)(`div`,{className:j(`group relative flex items-center gap-3 p-3 rounded-xl cursor-pointer transition-all duration-200`,`border border-transparent`,`hover:bg-gray-50 dark:hover:bg-dark-100 ophelia:hover:bg-[#1a1a1a]`,d&&[`bg-primary-50 dark:bg-primary-900/20 ophelia:bg-[#9333ea]/10`,`border-primary-200 dark:border-primary-700 ophelia:border-[#7c3aed]`]),onClick:()=>l?.(e),children:[(0,I.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,I.jsx)(`img`,{src:V(),alt:e.name,className:`w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a]`}),P&&(0,I.jsx)(`div`,{className:`absolute -bottom-0.5 -right-0.5 w-4 h-4 bg-gradient-to-br from-purple-500 to-primary-500 rounded-full flex items-center justify-center`,children:(0,I.jsx)(O,{className:`h-2.5 w-2.5 text-white`})})]}),(0,I.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(`h4`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate`,children:e.name}),e.is_favorite&&(0,I.jsx)(v,{className:`h-3 w-3 text-amber-500 fill-amber-500 flex-shrink-0`})]}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] truncate`,children:e.model})]}),d&&(0,I.jsx)(`div`,{className:`flex-shrink-0`,children:(0,I.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-600 ophelia:bg-[#9333ea] flex items-center justify-center`,children:(0,I.jsx)(b,{className:`h-3 w-3 text-white ml-0.5`})})})]}):(0,I.jsxs)(`div`,{className:j(`group relative rounded-2xl overflow-hidden transition-all duration-300`,`bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a]`,`border border-gray-200/60 dark:border-dark-300/60 ophelia:border-[#262626]`,`hover:border-gray-300 dark:hover:border-dark-400 ophelia:hover:border-[#3f3f46]`,`shadow-sm hover:shadow-lg dark:shadow-none`,d&&[`ring-2 ring-primary-500 dark:ring-primary-400 ophelia:ring-[#9333ea]`,`border-primary-300 dark:border-primary-600 ophelia:border-[#7c3aed]`]),children:[(0,I.jsxs)(`div`,{className:`relative h-20`,children:[e.background?(0,I.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,I.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]`}),(0,I.jsx)(`div`,{className:`absolute inset-0 bg-black/10 dark:bg-black/20`}),(0,I.jsxs)(`div`,{className:`absolute top-3 left-3 right-3 flex items-start justify-between`,children:[(0,I.jsx)(`button`,{onClick:t=>{t.stopPropagation(),u?.(e)},className:j(`p-1.5 rounded-full transition-all duration-200`,`bg-white/20 hover:bg-white/30 backdrop-blur-sm`,e.is_favorite&&`bg-amber-500/80 hover:bg-amber-500`),children:(0,I.jsx)(v,{className:j(`h-4 w-4`,e.is_favorite?`text-white fill-white`:`text-white/80 hover:text-white`)})}),P&&(0,I.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,I.jsx)(O,{className:`h-3 w-3`}),h(`personaCard.enhanced`)]})]})]}),(0,I.jsx)(`div`,{className:`relative px-4 -mt-8`,children:(0,I.jsxs)(`div`,{className:`relative inline-block`,children:[(0,I.jsx)(`img`,{src:V(),alt:e.name,className:`w-16 h-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a] shadow-lg`}),P&&(0,I.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 bg-gradient-to-br from-purple-500 to-primary-500 rounded-lg flex items-center justify-center shadow-sm`,children:(0,I.jsx)(a,{className:`h-3.5 w-3.5 text-white`})})]})}),(0,I.jsxs)(`div`,{className:`px-4 pt-3 pb-4`,children:[(0,I.jsxs)(`div`,{className:`mb-3`,children:[(0,I.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] leading-tight`,children:e.name}),(0,I.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] flex items-center gap-1.5 mt-0.5`,children:[(0,I.jsx)(f,{className:`h-3.5 w-3.5`}),e.model]})]}),e.description&&(0,I.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 mb-3`,children:e.description}),e.parameters.system_prompt&&(0,I.jsxs)(`div`,{className:`mb-3 p-2.5 rounded-lg bg-gray-50 dark:bg-dark-50 ophelia:bg-[#121212] border border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1`,children:[(0,I.jsx)(c,{className:`h-3 w-3 text-gray-400 dark:text-gray-500 ophelia:text-[#737373]`}),(0,I.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500 ophelia:text-[#737373]`,children:h(`personaCard.systemPrompt`)})]}),(0,I.jsxs)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]`,children:[(0,I.jsx)(E,{className:`h-3 w-3`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,I.jsxs)(`span`,{className:`inline-flex items-center px-2 py-1 rounded-md text-[11px] 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 `,e.parameters.top_p?.toFixed(1)||`0.9`]}),(0,I.jsxs)(`span`,{className:`inline-flex items-center px-2 py-1 rounded-md text-[11px] font-medium bg-gray-100 dark:bg-dark-200 ophelia:bg-[#1a1a1a] text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3]`,children:[(e.parameters.context_window||4096).toLocaleString(),` ctx`]})]}),P&&w&&(0,I.jsx)(`div`,{className:`mb-3 p-2.5 rounded-lg bg-gradient-to-r from-primary-50 to-purple-50 dark:from-primary-900/20 dark:to-purple-900/20 ophelia:from-[#9333ea]/10 ophelia:to-[#6d28d9]/10 border border-primary-100 dark:border-primary-800/30 ophelia:border-[#7c3aed]/20`,children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(_,{className:`h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]`}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`span`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300 ophelia:text-[#c084fc]`,children:[w.memory_count,` `,h(`personaCard.memories`)]}),(0,I.jsx)(`span`,{className:`text-[10px] text-primary-600/70 dark:text-primary-400/70 ophelia:text-[#a855f7]/70 ml-2`,children:(e=>e<1?`${(e*1024).toFixed(0)} KB`:`${e.toFixed(1)} MB`)(w.size_mb)})]})]}),w.status&&(0,I.jsx)(`span`,{className:j(`text-[10px] px-1.5 py-0.5 rounded-full font-medium`,w.status===`active`?`bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`),children:w.status})]})}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]`,children:[l&&(0,I.jsxs)(i,{onClick:()=>l(e),size:`sm`,className:`bg-primary-500 hover:bg-primary-600 dark:bg-primary-600 dark:hover:bg-primary-500 ophelia:bg-[#9333ea] ophelia:hover:bg-[#a855f7] text-white px-4`,children:[(0,I.jsx)(b,{className:`h-3.5 w-3.5 mr-1.5`}),h(`personaCard.use`)]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto`,children:[(0,I.jsx)(`button`,{onClick:()=>t(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 ophelia:text-[#737373] ophelia:hover:text-[#e5e5e5] hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors`,title:h(`personaCard.editTooltip`),children:(0,I.jsx)(m,{className:`h-4 w-4`})}),(0,I.jsx)(`button`,{onClick:()=>s(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 ophelia:text-[#737373] ophelia:hover:text-[#e5e5e5] hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors`,title:h(`personaCard.downloadTooltip`),children:(0,I.jsx)(y,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`relative`,children:[(0,I.jsx)(`button`,{onClick:()=>D(!T),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 ophelia:text-[#737373] ophelia:hover:text-[#e5e5e5] hover:bg-gray-100 dark:hover:bg-dark-200 ophelia:hover:bg-[#1a1a1a] transition-colors`,children:(0,I.jsx)(C,{className:`h-4 w-4`})}),T&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>D(!1)}),(0,I.jsxs)(`div`,{className:`absolute right-0 bottom-full mb-1 w-44 py-1 bg-white dark:bg-dark-100 ophelia:bg-[#0a0a0a] rounded-xl shadow-lg border border-gray-200 dark:border-dark-300 ophelia:border-[#262626] z-20`,children:[P&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`button`,{onClick:z,disabled:k,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5] hover:bg-gray-50 dark:hover:bg-dark-50 ophelia:hover:bg-[#1a1a1a] disabled:opacity-50`,children:[(0,I.jsx)(o,{className:`h-4 w-4`}),h(`personaCard.backup`)]}),(0,I.jsxs)(`button`,{onClick:B,disabled:k,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 ophelia:text-[#e5e5e5] hover:bg-gray-50 dark:hover:bg-dark-50 ophelia:hover:bg-[#1a1a1a] disabled:opacity-50`,children:[(0,I.jsx)(S,{className:`h-4 w-4`}),h(`personaCard.exportDNA`)]}),w&&w.memory_count>0&&(0,I.jsxs)(`button`,{onClick:R,disabled:k,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 disabled:opacity-50`,children:[(0,I.jsx)(x,{className:`h-4 w-4`}),h(`personaCard.wipeMemories`)]}),(0,I.jsx)(`div`,{className:`my-1 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]`})]}),(0,I.jsxs)(`button`,{onClick:()=>{n(e),D(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20`,children:[(0,I.jsx)(g,{className:`h-4 w-4`}),h(`common.delete`)]})]})]})]})]})]})]})]})},R=({value:e,onChange:t,className:n=``})=>{let{t:a}=r(),o=(0,F.useRef)(null),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),f=async e=>{if(!e.type.startsWith(`image/`)){A.error(a(`personaBackground.invalidFile`));return}if(e.size>5*1024*1024){A.error(a(`personaBackground.fileTooLarge`));return}l(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),A.success(a(`personaBackground.uploaded`))},n.onerror=()=>{A.error(a(`personaBackground.readFailed`))},n.readAsDataURL(e)}catch(e){console.error(`Failed to upload background:`,e),A.error(a(`personaBackground.uploadFailed`))}finally{l(!1)}};return(0,I.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:a(`personaBackground.label`)}),(0,I.jsxs)(`div`,{className:`space-y-3`,children:[e?(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`div`,{className:`w-full h-32 rounded-lg bg-cover bg-center border-2 border-gray-300 dark:border-dark-300`,style:{backgroundImage:`url(${e})`}}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,I.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:a(`personaBackground.customBackground`)}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:a(`personaBackground.clickToChange`)})]}),(0,I.jsx)(i,{variant:`ghost`,size:`sm`,onClick:()=>{t(``),A.success(a(`personaBackground.removed`))},className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,I.jsx)(w,{className:`h-4 w-4`})})]})]}):(0,I.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${u?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:e=>{e.preventDefault(),d(!0)},onDragLeave:e=>{e.preventDefault(),d(!1)},onDrop:e=>{e.preventDefault(),d(!1);let t=e.dataTransfer.files?.[0];t&&f(t)},onClick:()=>o.current?.click(),children:[(0,I.jsx)(s,{className:`h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4`}),(0,I.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:a(`personaBackground.uploadBackgroundImage`)}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:a(`personaBackground.dragAndDrop`)}),(0,I.jsxs)(i,{variant:`outline`,size:`sm`,disabled:c,className:`mx-auto`,children:[(0,I.jsx)(h,{className:`h-4 w-4 mr-2`}),a(c?`personaBackground.uploading`:`personaBackground.chooseImage`)]})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:a(`personaBackground.enterImageUrl`)}),(0,I.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/background.jpg`})]})]}),(0,I.jsx)(`input`,{ref:o,type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];t&&f(t)},className:`hidden`}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:a(`personaBackground.supportedFormats`)})]})})},z=({label:e,value:t,min:n,max:r,step:i,onChange:a,hint:o,format:s=e=>String(e),colorClass:c=`text-gray-700 dark:text-dark-600`})=>{let l=(t-n)/(r-n)*100;return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,I.jsx)(`label`,{className:j(`block text-sm font-medium`,c),children:e}),(0,I.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:s(t),onChange:e=>{let t=parseFloat(e.target.value);isNaN(t)||a(Math.min(r,Math.max(n,t)))},className:`w-20 px-2 py-1 text-sm text-right bg-gray-100 dark:bg-dark-200 border border-gray-300 dark:border-dark-300 rounded focus:outline-none focus:ring-1 focus:ring-primary-500 dark:text-dark-600`})]}),(0,I.jsx)(`input`,{type:`range`,min:n,max:r,step:i,value:t,onChange:e=>a(parseFloat(e.target.value)),className:`w-full h-2 bg-gray-200 dark:bg-dark-200 rounded-lg appearance-none cursor-pointer slider`,style:{"--progress":`${l}%`}}),o&&(0,I.jsx)(`p`,{className:j(`text-xs mt-1`,c.replace(`700`,`500`).replace(`600`,`400`)),children:o})]})},B=({label:e,checked:t,onChange:n,colorClass:r=`text-gray-700 dark:text-dark-600`})=>(0,I.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,I.jsx)(`div`,{className:j(`relative w-10 h-5 rounded-full transition-colors`,t?`bg-primary-500 dark:bg-primary-600`:`bg-gray-300 dark:bg-dark-300`),onClick:()=>n(!t),children:(0,I.jsx)(`div`,{className:j(`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-5`)})}),(0,I.jsx)(`span`,{className:j(`text-sm font-medium`,r),children:e})]}),V={name:``,description:``,model:``,parameters:{temperature:.7,top_p:.9,top_k:40,context_window:4096,max_tokens:1024,system_prompt:``,repeat_penalty:1.1,presence_penalty:0,frequency_penalty:0},avatar:``,background:``,embedding_model:``,memory_settings:{enabled:!1,max_memories:1e3,auto_cleanup:!0,retention_days:90},mutation_settings:{enabled:!1,sensitivity:`medium`,auto_adapt:!0}},H=[`embed`,`e5`,`bge`,`gte`,`minilm`,`multilingual`,`sentence`,`universal`,`instructor`,`jina`,`paraphrase`,`mpnet`,`contriever`],U=({persona:e,onSubmit:t,onCancel:n})=>{let{t:o}=r(),[s,c]=(0,F.useState)(V),[f,m]=(0,F.useState)([]),[h,v]=(0,F.useState)([]),[y,b]=(0,F.useState)(!1),[x,S]=(0,F.useState)(!1),[C,w]=(0,F.useState)(!1),[L,U]=(0,F.useState)(null),[W,te]=(0,F.useState)(`basic`),[G,ne]=(0,F.useState)(null),[re,K]=(0,F.useState)(!1),[q,J]=(0,F.useState)(!1),Y=(0,F.useRef)(!1),X=(0,F.useCallback)((e,t)=>{c(n=>({...n,[e]:t})),U(null)},[]),Z=(0,F.useCallback)((e,t)=>{c(n=>({...n,parameters:{...n.parameters,[e]:t}})),U(null)},[]),Q=(0,F.useCallback)((e,t)=>{c(n=>({...n,[e]:{...n[e],...t}})),U(null)},[]),ie=(0,F.useCallback)(e=>{let t=e.filter(e=>H.some(t=>e.name.toLowerCase().includes(t.toLowerCase()))).map(e=>({id:e.name,name:e.name,description:`${e.details?.parameter_size||`Unknown size`} - ${e.details?.family||`Ollama model`}`,provider:`ollama`,dimensions:768,isDetectedEmbedding:!0})),n=e.filter(e=>!H.some(t=>e.name.toLowerCase().includes(t.toLowerCase()))).map(e=>({id:e.name,name:e.name,description:`${e.details?.parameter_size||`Unknown size`} - ${e.details?.family||`Other model`}`,provider:`ollama`,dimensions:768,isDetectedEmbedding:!1})),r=[...t,...n].reduce((e,t)=>(e.find(e=>e.id===t.id)||e.push(t),e),[]);return r.length>0?r:[{id:`nomic-embed-text`,name:`nomic-embed-text`,description:`Default embedding model (install if needed)`,provider:`ollama`,dimensions:768}]},[]),$=(0,F.useCallback)(async()=>{if(e?.id){K(!0);try{let t=await M.getMemoryStatus(e.id);t.success&&t.data&&ne(t.data)}catch(e){console.error(`Failed to load memory status:`,e)}finally{K(!1)}}},[e?.id]),ae=async()=>{if(e?.id&&confirm(o(`personaForm.memory.wipeConfirm`))){J(!0);try{let t=await M.wipeMemories(e.id);t.success?(A.success(o(`personaForm.memory.wipeSuccess`,{count:t.data?.deleted_count||0})),await $()):A.error(o(`personaForm.error.saveFailed`))}catch{A.error(o(`personaForm.error.saveFailed`))}finally{J(!1)}}};(0,F.useEffect)(()=>{Y.current||(Y.current=!0,(async()=>{b(!0);try{let[t,n]=await Promise.all([N.getModels(),e?Promise.resolve(null):M.getDefaultParameters()]);if(t.success&&t.data){m(t.data);let r=ie(t.data);if(v(r),e){if(c({name:e.name,description:e.description||``,model:e.model,parameters:e.parameters,avatar:e.avatar||``,background:e.background||``,embedding_model:e.embedding_model||r[0]?.id||``,memory_settings:e.memory_settings||V.memory_settings,mutation_settings:e.mutation_settings||V.mutation_settings}),e.embedding_model&&!r.find(t=>t.id===e.embedding_model)){let t=e.embedding_model.split(`:`)[0],n=r.find(e=>e.id.startsWith(t+`:`)||e.id===t);n?c(e=>({...e,embedding_model:n.id})):v(t=>[...t,{id:e.embedding_model,name:e.embedding_model,description:`Previously selected model (not currently installed)`,provider:`ollama`,dimensions:768}])}}else{let e=n?.success?n.data:{};c(t=>({...t,parameters:{...t.parameters,...e},embedding_model:r[0]?.id||``}))}}}catch(e){console.error(`Error loading data:`,e)}finally{b(!1)}})())},[e,ie]),(0,F.useEffect)(()=>{e?.id&&s.memory_settings?.enabled&&$()},[e?.id,s.memory_settings?.enabled,$]);let oe=async n=>{S(!0),w(n);try{let r={name:s.name,description:s.description,model:s.model,parameters:s.parameters,avatar:s.avatar,background:s.background,embedding_model:s.embedding_model,memory_settings:s.memory_settings,mutation_settings:s.mutation_settings},i=e?await M.updatePersona(e.id,r):await M.createPersona(s);i.success?(A.success(o(e?`personaForm.success.updated`:`personaForm.success.created`)),U(new Date),n&&t()):A.error(`${o(`personaForm.error.saveFailed`)}: ${i.error}`)}catch(e){A.error(`${o(`personaForm.error.saveFailed`)}: ${e instanceof Error?e.message:String(e)}`)}finally{S(!1),w(!1)}},se=(0,F.useMemo)(()=>[{id:`basic`,label:o(`personaForm.tabs.basic`),icon:ee},{id:`parameters`,label:o(`personaForm.tabs.parameters`),icon:k},{id:`memory`,label:o(`personaForm.tabs.memory`),icon:O},{id:`advanced`,label:o(`personaForm.tabs.advanced`),icon:a}],[o]),ce=(0,F.useMemo)(()=>[{key:`temperature`,label:o(`personaForm.parameters.temperature`),min:0,max:2,step:.1,hint:o(`personaForm.parameters.temperatureHint`),format:e=>e.toFixed(1)},{key:`top_p`,label:o(`personaForm.parameters.topP`),min:0,max:1,step:.1,hint:o(`personaForm.parameters.topPHint`),format:e=>e.toFixed(1)},{key:`top_k`,label:o(`personaForm.parameters.topK`),min:1,max:100,step:1,hint:o(`personaForm.parameters.topKHint`),format:e=>String(Math.round(e))},{key:`context_window`,label:o(`personaForm.parameters.contextWindow`),min:128,max:131072,step:128,hint:o(`personaForm.parameters.contextWindowHint`),format:e=>String(Math.round(e))},{key:`max_tokens`,label:o(`personaForm.parameters.maxTokens`),min:1,max:8192,step:1,hint:o(`personaForm.parameters.maxTokensHint`),format:e=>String(Math.round(e))},{key:`repeat_penalty`,label:o(`personaForm.parameters.repeatPenalty`),min:.5,max:2,step:.1,hint:o(`personaForm.parameters.repeatPenaltyHint`),format:e=>e.toFixed(1)}],[o]);return y?(0,I.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,I.jsxs)(`div`,{className:`animate-pulse flex items-center gap-3`,children:[(0,I.jsx)(`div`,{className:`w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin`}),(0,I.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:o(`personaForm.loading`)})]})}):(0,I.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,I.jsxs)(`div`,{className:`mb-6`,children:[(0,I.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:o(e?`personaForm.title.edit`:`personaForm.title.create`)}),(0,I.jsxs)(`div`,{className:`flex items-center gap-4 mt-1`,children:[(0,I.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600`,children:o(e?`personaForm.subtitle.edit`:`personaForm.subtitle.create`)}),L&&(0,I.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-green-600 dark:text-green-400`,children:[(0,I.jsx)(`div`,{className:`w-2 h-2 bg-green-500 rounded-full`}),o(`personaForm.saved`),` `,L.toLocaleTimeString()]})]})]}),(0,I.jsxs)(`form`,{onSubmit:e=>e.preventDefault(),className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,I.jsx)(`div`,{className:`flex border-b border-gray-200 dark:border-dark-300`,children:se.map(e=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>te(e.id),className:`flex items-center gap-2 px-6 py-4 text-sm font-medium transition-colors ${W===e.id?`border-b-2 border-primary-500 text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-dark-600 hover:text-gray-700 dark:hover:text-dark-800`}`,children:[(0,I.jsx)(e.icon,{className:`h-4 w-4`}),e.label]},e.id))}),(0,I.jsxs)(`div`,{className:`p-6`,children:[W===`basic`&&(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[o(`personaForm.basic.name`),` *`]}),(0,I.jsx)(`input`,{type:`text`,value:s.name,onChange:e=>X(`name`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,placeholder:o(`personaForm.basic.namePlaceholder`),required:!0})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[o(`personaForm.basic.model`),` *`]}),(0,I.jsxs)(`select`,{value:s.model,onChange:e=>X(`model`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,required:!0,children:[(0,I.jsx)(`option`,{value:``,children:o(`personaForm.basic.selectModel`)}),f.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:o(`personaForm.basic.description`)}),(0,I.jsx)(`textarea`,{value:s.description,onChange:e=>X(`description`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none`,rows:3,placeholder:o(`personaForm.basic.descriptionPlaceholder`)})]}),(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,I.jsx)(P,{value:s.avatar||``,onChange:e=>X(`avatar`,e)}),(0,I.jsx)(R,{value:s.background||``,onChange:e=>X(`background`,e)})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:o(`personaForm.basic.systemPrompt`)}),(0,I.jsx)(`textarea`,{value:s.parameters.system_prompt,onChange:e=>Z(`system_prompt`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none font-mono text-sm`,rows:6,placeholder:o(`personaForm.basic.systemPromptPlaceholder`)}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-2`,children:o(`personaForm.basic.systemPromptHint`)})]})]}),W===`parameters`&&(0,I.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:ce.map(({key:e,label:t,min:n,max:r,step:i,hint:a,format:o})=>(0,I.jsx)(z,{label:t,value:s.parameters[e]||0,min:n,max:r,step:i,hint:a,format:o,onChange:t=>Z(e,t)},e))}),W===`memory`&&(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30`,children:[(0,I.jsx)(`div`,{className:`px-5 py-4 bg-gradient-to-r from-emerald-500 to-teal-500 dark:from-emerald-600 dark:to-teal-600`,children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,I.jsx)(_,{className:`h-5 w-5 text-white`})}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`font-semibold text-white`,children:o(`personaForm.memory.title`)}),(0,I.jsx)(`p`,{className:`text-xs text-white/80`,children:o(`personaForm.memory.subtitle`)})]})]}),(0,I.jsx)(B,{label:``,checked:s.memory_settings?.enabled||!1,onChange:e=>Q(`memory_settings`,{enabled:e})})]})}),s.memory_settings?.enabled&&e?.id&&(0,I.jsx)(`div`,{className:`px-5 py-4 bg-emerald-50 dark:bg-emerald-900/20 border-b border-emerald-100 dark:border-emerald-800/30`,children:re?(0,I.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,I.jsx)(l,{className:`h-4 w-4 animate-spin`}),o(`personaForm.memory.loading`)]}):G?(0,I.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,I.jsx)(_,{className:`h-5 w-5`}),G.memory_count.toLocaleString()]}),(0,I.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:o(`personaForm.memory.memories`)})]}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,I.jsx)(d,{className:`h-5 w-5`}),G.size_mb.toFixed(1)]}),(0,I.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:o(`personaForm.memory.mbUsed`)})]}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,I.jsx)(p,{className:`h-5 w-5`}),G.last_backup?new Date(G.last_backup).toLocaleDateString():o(`personaForm.memory.never`)]}),(0,I.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:o(`personaForm.memory.lastBackup`)})]})]}):(0,I.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,children:o(`personaForm.memory.noData`)})}),s.memory_settings?.enabled&&(0,I.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-4`,children:[(0,I.jsx)(z,{label:o(`personaForm.memory.maxMemories`),value:s.memory_settings.max_memories,min:100,max:1e4,step:100,hint:o(`personaForm.memory.maxMemoriesHint`),format:e=>e.toLocaleString(),colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>Q(`memory_settings`,{max_memories:e})}),(0,I.jsx)(z,{label:o(`personaForm.memory.retention`),value:s.memory_settings.retention_days,min:7,max:365,step:7,hint:o(`personaForm.memory.retentionHint`),format:e=>`${Math.round(e)} days`,colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>Q(`memory_settings`,{retention_days:e})}),(0,I.jsx)(B,{label:o(`personaForm.memory.autoCleanup`),checked:s.memory_settings.auto_cleanup,onChange:e=>Q(`memory_settings`,{auto_cleanup:e}),colorClass:`text-emerald-700 dark:text-emerald-300`}),e?.id&&G&&G.memory_count>0&&(0,I.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800/30`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-300`,children:o(`personaForm.memory.wipeAll`)}),(0,I.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:o(`personaForm.memory.wipeCannot`)})]}),(0,I.jsxs)(`button`,{type:`button`,onClick:ae,disabled:q,className:`px-3 py-1.5 bg-red-500 hover:bg-red-600 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50 flex items-center gap-1.5`,children:[q?(0,I.jsx)(l,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(g,{className:`h-3.5 w-3.5`}),o(q?`personaForm.memory.wiping`:`personaForm.memory.wipeButton`)]})]})})]}),!s.memory_settings?.enabled&&(0,I.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,I.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:o(`personaForm.memory.enableHint`)})})]}),(0,I.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-violet-200/50 dark:border-violet-700/30`,children:[(0,I.jsx)(`div`,{className:`px-5 py-4 bg-gradient-to-r from-violet-500 to-purple-500 dark:from-violet-600 dark:to-purple-600`,children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,I.jsx)(D,{className:`h-5 w-5 text-white`})}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`font-semibold text-white`,children:o(`personaForm.learning.title`)}),(0,I.jsx)(`p`,{className:`text-xs text-white/80`,children:o(`personaForm.learning.subtitle`)})]})]}),(0,I.jsx)(B,{label:``,checked:s.mutation_settings?.enabled||!1,onChange:e=>Q(`mutation_settings`,{enabled:e})})]})}),s.mutation_settings?.enabled&&(0,I.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-5`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`block text-sm font-medium text-violet-700 dark:text-violet-300 mb-3`,children:o(`personaForm.learning.speed`)}),(0,I.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:[{level:`low`,icon:E,label:o(`personaForm.learning.slow`),desc:o(`personaForm.learning.slowDesc`)},{level:`medium`,icon:D,label:o(`personaForm.learning.balanced`),desc:o(`personaForm.learning.balancedDesc`)},{level:`high`,icon:O,label:o(`personaForm.learning.fast`),desc:o(`personaForm.learning.fastDesc`)}].map(({level:e,icon:t,label:n,desc:r})=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>Q(`mutation_settings`,{sensitivity:e}),className:j(`p-3 rounded-xl text-center transition-all border`,s.mutation_settings?.sensitivity===e?`bg-violet-500 border-violet-500 text-white shadow-lg shadow-violet-500/25`:`bg-violet-50 dark:bg-violet-900/20 border-violet-200 dark:border-violet-700/30 text-violet-700 dark:text-violet-300 hover:bg-violet-100 dark:hover:bg-violet-900/30`),children:[(0,I.jsx)(t,{className:`h-5 w-5 mx-auto mb-1`}),(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:n}),(0,I.jsx)(`p`,{className:`text-[10px] opacity-70`,children:r})]},e))})]}),(0,I.jsx)(B,{label:o(`personaForm.learning.autoAdapt`),checked:s.mutation_settings.auto_adapt,onChange:e=>Q(`mutation_settings`,{auto_adapt:e}),colorClass:`text-violet-700 dark:text-violet-300`}),(0,I.jsxs)(`div`,{className:`p-4 bg-violet-50 dark:bg-violet-900/20 rounded-xl`,children:[(0,I.jsxs)(`p`,{className:`text-xs font-medium text-violet-700 dark:text-violet-300 mb-2 flex items-center gap-1.5`,children:[(0,I.jsx)(a,{className:`h-3.5 w-3.5`}),o(`personaForm.learning.whatLearns`)]}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs text-violet-600 dark:text-violet-400`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-violet-400`}),o(`personaForm.learning.conversationTone`)]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-violet-400`}),o(`personaForm.learning.responseStyle`)]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-violet-400`}),o(`personaForm.learning.userPreferences`)]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-violet-400`}),o(`personaForm.learning.topicInterests`)]})]})]})]}),!s.mutation_settings?.enabled&&(0,I.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,I.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:o(`personaForm.learning.enableHint`)})})]})]}),W===`advanced`&&(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`rounded-xl p-5 bg-gradient-to-br from-primary-50 to-primary-100/50 dark:from-primary-900/30 dark:to-primary-800/20 border border-primary-200/50 dark:border-primary-700/30`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,I.jsx)(_,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}),(0,I.jsx)(`h3`,{className:`font-semibold text-primary-900 dark:text-primary-100`,children:o(`personaForm.advanced.embeddingModel`)})]}),(0,I.jsx)(`p`,{className:`text-xs text-primary-600 dark:text-primary-400 mb-3`,children:o(`personaForm.advanced.embeddingHint`)}),(0,I.jsx)(`select`,{value:s.embedding_model,onChange:e=>X(`embedding_model`,e.target.value),className:`w-full px-3 py-2.5 border border-primary-200 dark:border-primary-700 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20`,children:h.length===0?(0,I.jsx)(`option`,{value:``,disabled:!0,children:o(`personaForm.advanced.noModels`)}):(0,I.jsxs)(I.Fragment,{children:[h.filter(e=>e.isDetectedEmbedding).length>0&&(0,I.jsx)(`optgroup`,{label:o(`personaForm.advanced.embeddingModels`),children:h.filter(e=>e.isDetectedEmbedding).map(e=>(0,I.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))}),h.filter(e=>!e.isDetectedEmbedding).length>0&&(0,I.jsx)(`optgroup`,{label:o(`personaForm.advanced.otherModels`),children:h.filter(e=>!e.isDetectedEmbedding).map(e=>(0,I.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))})]})}),h.length===0&&(0,I.jsx)(`div`,{className:`mt-3 p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700/50 rounded-lg`,children:(0,I.jsxs)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:[o(`personaForm.advanced.installHint`),` `,(0,I.jsx)(`code`,{className:`px-1.5 py-0.5 bg-amber-100 dark:bg-amber-900/40 rounded text-xs`,children:`ollama pull nomic-embed-text`})]})}),(0,I.jsx)(`p`,{className:`text-[10px] text-primary-500 dark:text-primary-500 mt-2`,children:o(`personaForm.advanced.recommended`)})]}),(0,I.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(T,{className:`h-5 w-5 text-gray-400 mt-0.5 flex-shrink-0`}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:o(`personaForm.advanced.aboutTitle`)}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:o(`personaForm.advanced.aboutDescription`)})]})]})})]})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(i,{type:`button`,variant:`ghost`,onClick:n,disabled:x,className:`text-gray-600 dark:text-gray-400`,children:o(`personaForm.actions.cancel`)}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[L&&(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,I.jsx)(u,{className:`h-4 w-4`}),(0,I.jsx)(`span`,{children:o(`personaForm.saved`)})]}),(0,I.jsx)(i,{type:`button`,variant:`outline`,onClick:()=>oe(!1),disabled:x,children:o(x&&!C?`personaForm.actions.saving`:`personaForm.actions.save`)}),(0,I.jsx)(i,{type:`button`,onClick:()=>oe(!0),disabled:x,children:o(x&&C?`personaForm.actions.saving`:e?`personaForm.actions.saveClose`:`personaForm.actions.create`)})]})]})]})]})},W=({personas:e,onImport:t,onClose:n})=>{let{t:a}=r(),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(``),u=async e=>{try{let t=await M.exportPersona(e.id),n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.name}.json`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r),A.success(a(`personaImportExport.exportSuccess`,{name:e.name}))}catch(e){let t=e instanceof Error?e.message:String(e);A.error(a(`personaImportExport.exportFailed`)+`: `+t)}};return(0,I.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,I.jsxs)(`div`,{className:`mb-6`,children:[(0,I.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:a(`personaImportExport.title`)}),(0,I.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:a(`personaImportExport.description`)})]}),(0,I.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,I.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,I.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:a(`personaImportExport.exportPersonas`)}),e.length===0?(0,I.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 text-center py-8`,children:a(`personaImportExport.noPersonasToExport`)}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,I.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:a(`personaImportExport.personasAvailable`,{count:e.length})}),(0,I.jsx)(i,{onClick:async()=>{try{let t=e.map(e=>M.exportPersona(e.id)),n=await Promise.all(t),r={personas:n,exportedAt:Date.now(),version:`1.0.0`,count:n.length},i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=`personas-export-${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o),A.success(a(`personaImportExport.exportAllSuccess`,{count:e.length}))}catch(e){let t=e instanceof Error?e.message:String(e);A.error(a(`personaImportExport.exportAllFailed`)+`: `+t)}},variant:`outline`,size:`sm`,className:`px-3 py-1`,children:a(`personaImportExport.exportAll`)})]}),(0,I.jsx)(`div`,{className:`space-y-2 max-h-80 overflow-y-auto`,children:e.map(e=>(0,I.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(`img`,{src:e.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(e.name)}&background=6366f1&color=fff&size=32`,alt:e.name,className:`w-8 h-8 rounded-full`}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),(0,I.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:e.model})]})]}),(0,I.jsx)(i,{onClick:()=>u(e),variant:`outline`,size:`sm`,className:`px-3 py-1`,children:a(`common.export`)})]},e.id))})]})]}),(0,I.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,I.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:a(`personaImportExport.importPersonas`)}),(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:a(`personaImportExport.uploadJsonFile`)}),(0,I.jsx)(`input`,{type:`file`,accept:`.json`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{let t=e.target?.result;typeof t==`string`&&l(t)},e.readAsText(t)}},className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`})]}),(0,I.jsx)(`div`,{className:`text-center text-gray-500 dark:text-dark-500`,children:a(`common.or`).toUpperCase()}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:a(`personaImportExport.pasteJsonLabel`)}),(0,I.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`,rows:8,placeholder:a(`personaImportExport.pasteJsonPlaceholder`)})]}),(0,I.jsx)(i,{onClick:async()=>{if(!c.trim()){A.error(a(`personaImportExport.pasteJsonData`));return}s(!0);try{let e=JSON.parse(c);if(e.personas&&Array.isArray(e.personas)){let t=0,n=0;for(let r of e.personas)try{await M.importPersona(r),t++}catch(e){n++,console.error(`Failed to import persona:`,e)}t>0?(A.success(a(`personaImportExport.importMultipleSuccess`,{count:t})),n>0&&A.error(a(`personaImportExport.importMultipleFailed`,{count:n}))):A.error(a(`personaImportExport.importNoneFailed`))}else await M.importPersona(e),A.success(a(`personaImportExport.importSuccess`));l(``),t()}catch(e){let t=e instanceof Error?e.message:String(e);A.error(a(`personaImportExport.importFailed`)+`: `+t)}finally{s(!1)}},disabled:!c.trim()||o,className:`w-full`,children:a(o?`personaImportExport.importing`:`personaImportExport.importButton`)})]})]})]}),(0,I.jsxs)(`div`,{className:`mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4`,children:[(0,I.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-dark-800 mb-2`,children:a(`personaImportExport.expectedFormat`)}),(0,I.jsx)(`pre`,{className:`text-xs text-gray-600 dark:text-dark-600 overflow-x-auto`,children:`{
|
|
2
|
+
"name": "Assistant Name",
|
|
3
|
+
"description": "Brief description of the assistant's personality",
|
|
4
|
+
"model": "model-name:version",
|
|
5
|
+
"params": {
|
|
6
|
+
"temperature": 0.8,
|
|
7
|
+
"top_p": 0.9,
|
|
8
|
+
"context_window": 4096,
|
|
9
|
+
"system_prompt": "You are a helpful assistant with specific traits..."
|
|
10
|
+
},
|
|
11
|
+
"avatar": "/path/to/avatar.png",
|
|
12
|
+
"background": "/path/to/background.png"
|
|
13
|
+
}`})]}),(0,I.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,I.jsx)(i,{onClick:n,variant:`outline`,children:a(`common.close`)})})]})},te=()=>{let{t:e}=r(),[t,n]=(0,F.useState)([]),[a,o]=(0,F.useState)(!1),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(null),[d,f]=(0,F.useState)(!1),p=async()=>{o(!0);try{let t=await M.getPersonas();t.success?n(t.data||[]):A.error(e(`personaManager.failed`,{action:`load`})+`: `+t.error)}catch(t){let n=t instanceof Error?t.message:String(t);A.error(e(`personaManager.failed`,{action:`load`})+`: `+n)}finally{o(!1)}};(0,F.useEffect)(()=>{p()},[]);let m=()=>{u(null),c(!0)},h=e=>{u(e),c(!0)},g=async t=>{if(confirm(e(`personaManager.deleteConfirm`,{name:t.name})))try{let n=await M.deletePersona(t.id);n.success?(A.success(e(`personaManager.deleteSuccess`,{name:t.name})),await p()):A.error(e(`personaManager.failed`,{action:`delete`})+`: `+n.error)}catch(t){let n=t instanceof Error?t.message:String(t);A.error(e(`personaManager.failed`,{action:`delete`})+`: `+n)}},_=async t=>{try{await M.downloadPersona(t.id,t.name),A.success(e(`personaManager.downloadSuccess`,{name:t.name}))}catch(t){let n=t instanceof Error?t.message:String(t);A.error(e(`personaManager.failed`,{action:`download`})+`: `+n)}};return a?(0,I.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,I.jsx)(`div`,{className:`text-gray-600 dark:text-dark-600`,children:e(`personaManager.loading`)})}):s?(0,I.jsx)(U,{persona:l,onSubmit:async()=>{c(!1),u(null),await p()},onCancel:()=>{c(!1),u(null)}}):d?(0,I.jsx)(W,{personas:t,onImport:p,onClose:()=>f(!1)}):(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:e(`personaManager.title`)}),(0,I.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:e(`personaManager.subtitle`)})]}),(0,I.jsxs)(`div`,{className:`flex gap-3`,children:[(0,I.jsx)(i,{onClick:()=>f(!0),variant:`outline`,className:`px-4 py-2`,children:e(`personaManager.importExport`)}),(0,I.jsx)(i,{onClick:m,className:`px-4 py-2`,children:e(`personaManager.createButton`)})]})]}),(0,I.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`personaManager.stats.title`)}),(0,I.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600`,children:e(`personaManager.stats.count`,{count:t.length})})]}),(0,I.jsx)(`div`,{className:`text-3xl font-bold text-gray-900 dark:text-dark-800`,children:t.length})]})}),t.length===0?(0,I.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-12 shadow-sm border border-gray-200 dark:border-dark-300 text-center`,children:[(0,I.jsx)(`div`,{className:`text-gray-400 dark:text-dark-500 mb-4`,children:(0,I.jsx)(`svg`,{className:`w-16 h-16 mx-auto`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,xmlns:`http://www.w3.org/2000/svg`,children:(0,I.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z`})})}),(0,I.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-2`,children:e(`personaManager.empty.title`)}),(0,I.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mb-6`,children:e(`personaManager.empty.description`)}),(0,I.jsx)(i,{onClick:m,className:`px-6 py-2`,children:e(`personaManager.empty.button`)})]}):(0,I.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:t.map(e=>(0,I.jsx)(L,{persona:e,onEdit:h,onDelete:g,onDownload:_},e.id))})]})},G=()=>{let{t:e}=r();return(0,I.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,I.jsxs)(`div`,{className:`max-w-6xl mx-auto p-6`,children:[(0,I.jsxs)(`div`,{className:`text-center max-w-md mx-auto mb-8`,children:[(0,I.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:e(`personaManager.title`)}),(0,I.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 ophelia:text-[#a3a3a3] leading-relaxed`,children:e(`personaManager.subtitle`)})]}),(0,I.jsx)(te,{})]})})};export{G as PersonasPage,G as default};
|