libre-webui 0.8.3 → 0.8.4
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/backend/dist/index.d.ts.map +1 -1
- package/backend/dist/index.js +15 -0
- package/backend/dist/index.js.map +1 -1
- package/frontend/dist/assets/{index-CT6_wIIb.js → index-DW8C1vVk.js} +29 -29
- package/frontend/dist/css/index-WfujIMhR.css +1 -0
- package/frontend/dist/index.html +6 -6
- package/frontend/dist/js/{ArtifactContainer-BLwdP4Y4.js → ArtifactContainer-Bm-Y-U-r.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-CYKT3Mxr.js → ArtifactDemoPage-C8k9scC2.js} +1 -1
- package/frontend/dist/js/ChatPage-Ct1Kuyoh.js +281 -0
- package/frontend/dist/js/{GalleryPage-CeV6Xikm.js → GalleryPage-Ci46MnQP.js} +1 -1
- package/frontend/dist/js/{ModelsPage-BEHsiMmV.js → ModelsPage-Bmk7Bjt4.js} +1 -1
- package/frontend/dist/js/{PersonasPage-D92Q-9GN.js → PersonasPage-B4ZtuJcO.js} +1 -1
- package/frontend/dist/js/{UserManagementPage-ir6FoUIm.js → UserManagementPage-B5I2sjsB.js} +1 -1
- package/frontend/dist/js/{markdown-vendor-QwEm2Xso.js → markdown-vendor-B0lXrrRZ.js} +2 -2
- package/frontend/dist/js/router-vendor-DdQhGl5t.js +10 -0
- package/frontend/dist/js/{ui-vendor-DsBonqC3.js → ui-vendor-C4ZcWovR.js} +2 -2
- package/frontend/dist/js/utils-vendor-BFlGJDIj.js +6 -0
- package/package.json +5 -3
- package/frontend/dist/css/index-eoCzaqbg.css +0 -1
- package/frontend/dist/js/ChatPage-5pmqke2e.js +0 -281
- package/frontend/dist/js/router-vendor-CmbUVdlE.js +0 -10
- package/frontend/dist/js/utils-vendor-3oAsqusP.js +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./markdown-vendor-QwEm2Xso.js";import{r as n}from"./router-vendor-CmbUVdlE.js";import{a as T,g as C,c as L,B as P,A as ce,o as me}from"../assets/index-CT6_wIIb.js";import{u as O,av as ee,m as ae,a4 as K,aj as xe,M as pe,$ as oe,D as $,aw as ge,k as he,ax as ue,ay as be,az as ye,Y as ke,T as de,z as i,X as fe,I as ve,U as je,q as Ne,b as we,a3 as re,ab as Fe,aq as Ce,aA as te,d as _e,C as Se}from"./ui-vendor-DsBonqC3.js";import"./utils-vendor-3oAsqusP.js";const Me=({persona:r,onEdit:b,onDelete:N,onDownload:a,onSelect:o,onToggleFavorite:f,isSelected:k=!1,compact:E=!1})=>{const{t:d}=T(),[y,D]=n.useState(null),[j,s]=n.useState(!1),[m,p]=n.useState(!1),l=!!(r.memory_settings?.enabled||r.mutation_settings?.enabled),c=n.useCallback(async()=>{if(l)try{const g=await C.getMemoryStatus(r.id);g.success&&g.data&&D(g.data)}catch(g){console.error("Failed to load memory status:",g)}},[r.id,l]);n.useEffect(()=>{c()},[c]);const w=async()=>{if(confirm(d("personaCard.wipeConfirm"))){p(!0);try{const g=await C.wipeMemories(r.id);g.success?(i.success(d("personaCard.wipeSuccess",{count:g.data?.deleted_count||0})),await c()):i.error(d("personaCard.failed",{action:"wipe memories"}))}catch(g){i.error(d("personaCard.failed",{action:"wipe memories"})),console.error(g)}finally{p(!1),s(!1)}}},x=async()=>{p(!0);try{const g=await C.backupPersona(r.id),U=window.URL.createObjectURL(g),_=document.createElement("a");_.href=U,_.download=`${r.name.toLowerCase().replace(/\s+/g,"-")}-backup.json`,document.body.appendChild(_),_.click(),window.URL.revokeObjectURL(U),document.body.removeChild(_),i.success(d("personaCard.backupSuccess"))}catch(g){i.error(d("personaCard.failed",{action:"backup persona"})),console.error(g)}finally{p(!1),s(!1)}},F=async()=>{p(!0);try{const g=await C.exportPersonaDNA(r.id),U=window.URL.createObjectURL(g),_=document.createElement("a");_.href=U,_.download=`${r.name.toLowerCase().replace(/\s+/g,"-")}-dna.json`,document.body.appendChild(_),_.click(),window.URL.revokeObjectURL(U),document.body.removeChild(_),i.success(d("personaCard.dnaSuccess"))}catch(g){i.error(d("personaCard.failed",{action:"export persona DNA"})),console.error(g)}finally{p(!1),s(!1)}},M=()=>r.avatar?r.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(r.name)}&background=6366f1&color=fff&size=128`,H=g=>g<1?`${(g*1024).toFixed(0)} KB`:`${g.toFixed(1)} MB`;return E?e.jsxs("div",{className:L("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]",k&&["bg-primary-50 dark:bg-primary-900/20 ophelia:bg-[#9333ea]/10","border-primary-200 dark:border-primary-700 ophelia:border-[#7c3aed]"]),onClick:()=>o?.(r),children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("img",{src:M(),alt:r.name,className:"w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a]"}),l&&e.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:e.jsx(O,{className:"h-2.5 w-2.5 text-white"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("h4",{className:"font-medium text-sm text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:r.name}),r.is_favorite&&e.jsx(ee,{className:"h-3 w-3 text-amber-500 fill-amber-500 flex-shrink-0"})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] truncate",children:r.model})]}),k&&e.jsx("div",{className:"flex-shrink-0",children:e.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:e.jsx(ae,{className:"h-3 w-3 text-white ml-0.5"})})})]}):e.jsxs("div",{className:L("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",k&&["ring-2 ring-primary-500 dark:ring-primary-400 ophelia:ring-[#9333ea]","border-primary-300 dark:border-primary-600 ophelia:border-[#7c3aed]"]),children:[e.jsxs("div",{className:"relative h-20",children:[r.background?e.jsx("div",{className:"absolute inset-0 bg-cover bg-center",style:{backgroundImage:`url(${r.background})`}}):e.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]"}),e.jsx("div",{className:"absolute inset-0 bg-black/10 dark:bg-black/20"}),e.jsxs("div",{className:"absolute top-3 left-3 right-3 flex items-start justify-between",children:[e.jsx("button",{onClick:g=>{g.stopPropagation(),f?.(r)},className:L("p-1.5 rounded-full transition-all duration-200","bg-white/20 hover:bg-white/30 backdrop-blur-sm",r.is_favorite&&"bg-amber-500/80 hover:bg-amber-500"),children:e.jsx(ee,{className:L("h-4 w-4",r.is_favorite?"text-white fill-white":"text-white/80 hover:text-white")})}),l&&e.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:[e.jsx(O,{className:"h-3 w-3"}),d("personaCard.enhanced")]})]})]}),e.jsx("div",{className:"relative px-4 -mt-8",children:e.jsxs("div",{className:"relative inline-block",children:[e.jsx("img",{src:M(),alt:r.name,className:"w-16 h-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a] shadow-lg"}),l&&e.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:e.jsx(K,{className:"h-3.5 w-3.5 text-white"})})]})}),e.jsxs("div",{className:"px-4 pt-3 pb-4",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] leading-tight",children:r.name}),e.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:[e.jsx(xe,{className:"h-3.5 w-3.5"}),r.model]})]}),r.description&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 mb-3",children:r.description}),r.parameters.system_prompt&&e.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:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(pe,{className:"h-3 w-3 text-gray-400 dark:text-gray-500 ophelia:text-[#737373]"}),e.jsx("span",{className:"text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500 ophelia:text-[#737373]",children:d("personaCard.systemPrompt")})]}),e.jsxs("p",{className:"text-xs text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 italic",children:["“",r.parameters.system_prompt,"”"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[e.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:[e.jsx(oe,{className:"h-3 w-3"}),r.parameters.temperature?.toFixed(1)||"0.7"]}),e.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 ",r.parameters.top_p?.toFixed(1)||"0.9"]}),e.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:[(r.parameters.context_window||4096).toLocaleString()," ctx"]})]}),l&&y&&e.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:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]"}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-xs font-medium text-primary-700 dark:text-primary-300 ophelia:text-[#c084fc]",children:[y.memory_count," ",d("personaCard.memories")]}),e.jsx("span",{className:"text-[10px] text-primary-600/70 dark:text-primary-400/70 ophelia:text-[#a855f7]/70 ml-2",children:H(y.size_mb)})]})]}),y.status&&e.jsx("span",{className:L("text-[10px] px-1.5 py-0.5 rounded-full font-medium",y.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:y.status})]})}),e.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]",children:[o&&e.jsxs(P,{onClick:()=>o(r),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:[e.jsx(ae,{className:"h-3.5 w-3.5 mr-1.5"}),d("personaCard.use")]}),e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx("button",{onClick:()=>b(r),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:d("personaCard.editTooltip"),children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>a(r),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:d("personaCard.downloadTooltip"),children:e.jsx(he,{className:"h-4 w-4"})}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>s(!j),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:e.jsx(ue,{className:"h-4 w-4"})}),j&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),e.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:[l&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:x,disabled:m,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:[e.jsx(be,{className:"h-4 w-4"}),d("personaCard.backup")]}),e.jsxs("button",{onClick:F,disabled:m,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:[e.jsx(ye,{className:"h-4 w-4"}),d("personaCard.exportDNA")]}),y&&y.memory_count>0&&e.jsxs("button",{onClick:w,disabled:m,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:[e.jsx(ke,{className:"h-4 w-4"}),d("personaCard.wipeMemories")]}),e.jsx("div",{className:"my-1 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]"})]}),e.jsxs("button",{onClick:()=>{N(r),s(!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:[e.jsx(de,{className:"h-4 w-4"}),d("common.delete")]})]})]})]})]})]})]})]})},Ee=({value:r,onChange:b,className:N=""})=>{const{t:a}=T(),o=n.useRef(null),[f,k]=n.useState(!1),[E,d]=n.useState(!1),y=async l=>{if(!l.type.startsWith("image/")){i.error(a("personaBackground.invalidFile"));return}if(l.size>5*1024*1024){i.error(a("personaBackground.fileTooLarge"));return}k(!0);try{const c=new FileReader;c.onload=w=>{const x=w.target?.result;b(x),i.success(a("personaBackground.uploaded"))},c.onerror=()=>{i.error(a("personaBackground.readFailed"))},c.readAsDataURL(l)}catch(c){console.error("Failed to upload background:",c),i.error(a("personaBackground.uploadFailed"))}finally{k(!1)}},D=l=>{const c=l.target.files?.[0];c&&y(c)},j=l=>{l.preventDefault(),d(!0)},s=l=>{l.preventDefault(),d(!1)},m=l=>{l.preventDefault(),d(!1);const c=l.dataTransfer.files?.[0];c&&y(c)},p=()=>{b(""),i.success(a("personaBackground.removed"))};return e.jsx("div",{className:`space-y-4 ${N}`,children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:a("personaBackground.label")}),e.jsxs("div",{className:"space-y-3",children:[r?e.jsxs("div",{className:"space-y-3",children:[e.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(${r})`}}),e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:a("personaBackground.customBackground")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:a("personaBackground.clickToChange")})]}),e.jsx(P,{variant:"ghost",size:"sm",onClick:p,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:e.jsx(fe,{className:"h-4 w-4"})})]})]}):e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${E?"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:j,onDragLeave:s,onDrop:m,onClick:()=>o.current?.click(),children:[e.jsx(ve,{className:"h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4"}),e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 mb-2",children:a("personaBackground.uploadBackgroundImage")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4",children:a("personaBackground.dragAndDrop")}),e.jsxs(P,{variant:"outline",size:"sm",disabled:f,className:"mx-auto",children:[e.jsx(je,{className:"h-4 w-4 mr-2"}),a(f?"personaBackground.uploading":"personaBackground.chooseImage")]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1",children:a("personaBackground.enterImageUrl")}),e.jsx("input",{type:"url",value:r,onChange:l=>b(l.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"})]})]}),e.jsx("input",{ref:o,type:"file",accept:"image/*",onChange:D,className:"hidden"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-2",children:a("personaBackground.supportedFormats")})]})})},J=({label:r,value:b,min:N,max:a,step:o,onChange:f,hint:k,format:E=y=>String(y),colorClass:d="text-gray-700 dark:text-dark-600"})=>{const y=(b-N)/(a-N)*100,D=j=>{const s=parseFloat(j.target.value);if(!isNaN(s)){const m=Math.min(a,Math.max(N,s));f(m)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:L("block text-sm font-medium",d),children:r}),e.jsx("input",{type:"number",min:N,max:a,step:o,value:E(b),onChange:D,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"})]}),e.jsx("input",{type:"range",min:N,max:a,step:o,value:b,onChange:j=>f(parseFloat(j.target.value)),className:"w-full h-2 bg-gray-200 dark:bg-dark-200 rounded-lg appearance-none cursor-pointer slider",style:{"--progress":`${y}%`}}),k&&e.jsx("p",{className:L("text-xs mt-1",d.replace("700","500").replace("600","400")),children:k})]})},z=({label:r,checked:b,onChange:N,colorClass:a="text-gray-700 dark:text-dark-600"})=>e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("div",{className:L("relative w-10 h-5 rounded-full transition-colors",b?"bg-primary-500 dark:bg-primary-600":"bg-gray-300 dark:bg-dark-300"),onClick:()=>N(!b),children:e.jsx("div",{className:L("absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform",b&&"translate-x-5")})}),e.jsx("span",{className:L("text-sm font-medium",a),children:r})]}),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}},se=["embed","e5","bge","gte","minilm","multilingual","sentence","universal","instructor","jina","paraphrase","mpnet","contriever"],Pe=({persona:r,onSubmit:b,onCancel:N})=>{const{t:a}=T(),[o,f]=n.useState(V),[k,E]=n.useState([]),[d,y]=n.useState([]),[D,j]=n.useState(!1),[s,m]=n.useState(!1),[p,l]=n.useState(!1),[c,w]=n.useState(null),[x,F]=n.useState("basic"),[M,H]=n.useState(null),[g,U]=n.useState(!1),[_,Y]=n.useState(!1),G=n.useRef(!1),R=n.useCallback((t,u)=>{f(v=>({...v,[t]:u})),w(null)},[]),X=n.useCallback((t,u)=>{f(v=>({...v,parameters:{...v.parameters,[t]:u}})),w(null)},[]),B=n.useCallback((t,u)=>{f(v=>({...v,[t]:{...v[t],...u}})),w(null)},[]),Z=n.useCallback(t=>{const u=t.filter(h=>se.some(S=>h.name.toLowerCase().includes(S.toLowerCase()))).map(h=>({id:h.name,name:h.name,description:`${h.details?.parameter_size||"Unknown size"} - ${h.details?.family||"Ollama model"}`,provider:"ollama",dimensions:768,isDetectedEmbedding:!0})),v=t.filter(h=>!se.some(S=>h.name.toLowerCase().includes(S.toLowerCase()))).map(h=>({id:h.name,name:h.name,description:`${h.details?.parameter_size||"Unknown size"} - ${h.details?.family||"Other model"}`,provider:"ollama",dimensions:768,isDetectedEmbedding:!1})),I=[...u,...v].reduce((h,S)=>(h.find(q=>q.id===S.id)||h.push(S),h),[]);return I.length>0?I:[{id:"nomic-embed-text",name:"nomic-embed-text",description:"Default embedding model (install if needed)",provider:"ollama",dimensions:768}]},[]),W=n.useCallback(async()=>{if(r?.id){U(!0);try{const t=await C.getMemoryStatus(r.id);t.success&&t.data&&H(t.data)}catch(t){console.error("Failed to load memory status:",t)}finally{U(!1)}}},[r?.id]),ne=async()=>{if(r?.id&&confirm(a("personaForm.memory.wipeConfirm"))){Y(!0);try{const t=await C.wipeMemories(r.id);t.success?(i.success(a("personaForm.memory.wipeSuccess",{count:t.data?.deleted_count||0})),await W()):i.error(a("personaForm.error.saveFailed"))}catch{i.error(a("personaForm.error.saveFailed"))}finally{Y(!1)}}};n.useEffect(()=>{if(G.current)return;G.current=!0,(async()=>{j(!0);try{const[u,v]=await Promise.all([me.getModels(),r?Promise.resolve(null):C.getDefaultParameters()]);if(u.success&&u.data){E(u.data);const A=Z(u.data);if(y(A),r){if(f({name:r.name,description:r.description||"",model:r.model,parameters:r.parameters,avatar:r.avatar||"",background:r.background||"",embedding_model:r.embedding_model||A[0]?.id||"",memory_settings:r.memory_settings||V.memory_settings,mutation_settings:r.mutation_settings||V.mutation_settings}),r.embedding_model&&!A.find(I=>I.id===r.embedding_model)){const I=r.embedding_model.split(":")[0],h=A.find(S=>S.id.startsWith(I+":")||S.id===I);h?f(S=>({...S,embedding_model:h.id})):y(S=>[...S,{id:r.embedding_model,name:r.embedding_model,description:"Previously selected model (not currently installed)",provider:"ollama",dimensions:768}])}}else{const I=v?.success?v.data:{};f(h=>({...h,parameters:{...h.parameters,...I},embedding_model:A[0]?.id||""}))}}}catch(u){console.error("Error loading data:",u)}finally{j(!1)}})()},[r,Z]),n.useEffect(()=>{r?.id&&o.memory_settings?.enabled&&W()},[r?.id,o.memory_settings?.enabled,W]);const Q=async t=>{m(!0),l(t);try{const u={name:o.name,description:o.description,model:o.model,parameters:o.parameters,avatar:o.avatar,background:o.background,embedding_model:o.embedding_model,memory_settings:o.memory_settings,mutation_settings:o.mutation_settings},v=r?await C.updatePersona(r.id,u):await C.createPersona(o);v.success?(i.success(a(r?"personaForm.success.updated":"personaForm.success.created")),w(new Date),t&&b()):i.error(`${a("personaForm.error.saveFailed")}: ${v.error}`)}catch(u){i.error(`${a("personaForm.error.saveFailed")}: ${u instanceof Error?u.message:String(u)}`)}finally{m(!1),l(!1)}},le=n.useMemo(()=>[{id:"basic",label:a("personaForm.tabs.basic"),icon:Ne},{id:"parameters",label:a("personaForm.tabs.parameters"),icon:we},{id:"memory",label:a("personaForm.tabs.memory"),icon:O},{id:"advanced",label:a("personaForm.tabs.advanced"),icon:K}],[a]),ie=n.useMemo(()=>[{key:"temperature",label:a("personaForm.parameters.temperature"),min:0,max:2,step:.1,hint:a("personaForm.parameters.temperatureHint"),format:t=>t.toFixed(1)},{key:"top_p",label:a("personaForm.parameters.topP"),min:0,max:1,step:.1,hint:a("personaForm.parameters.topPHint"),format:t=>t.toFixed(1)},{key:"top_k",label:a("personaForm.parameters.topK"),min:1,max:100,step:1,hint:a("personaForm.parameters.topKHint"),format:t=>String(Math.round(t))},{key:"context_window",label:a("personaForm.parameters.contextWindow"),min:128,max:131072,step:128,hint:a("personaForm.parameters.contextWindowHint"),format:t=>String(Math.round(t))},{key:"max_tokens",label:a("personaForm.parameters.maxTokens"),min:1,max:8192,step:1,hint:a("personaForm.parameters.maxTokensHint"),format:t=>String(Math.round(t))},{key:"repeat_penalty",label:a("personaForm.parameters.repeatPenalty"),min:.5,max:2,step:.1,hint:a("personaForm.parameters.repeatPenaltyHint"),format:t=>t.toFixed(1)}],[a]);return D?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsxs("div",{className:"animate-pulse flex items-center gap-3",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:a("personaForm.loading")})]})}):e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-dark-800",children:a(r?"personaForm.title.edit":"personaForm.title.create")}),e.jsxs("div",{className:"flex items-center gap-4 mt-1",children:[e.jsx("p",{className:"text-gray-600 dark:text-dark-600",children:a(r?"personaForm.subtitle.edit":"personaForm.subtitle.create")}),c&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),a("personaForm.saved")," ",c.toLocaleTimeString()]})]})]}),e.jsxs("form",{onSubmit:t=>t.preventDefault(),className:"space-y-6",children:[e.jsxs("div",{className:"bg-white dark:bg-dark-100 rounded-lg shadow-sm border border-gray-200 dark:border-dark-300",children:[e.jsx("div",{className:"flex border-b border-gray-200 dark:border-dark-300",children:le.map(t=>e.jsxs("button",{type:"button",onClick:()=>F(t.id),className:`flex items-center gap-2 px-6 py-4 text-sm font-medium transition-colors ${x===t.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:[e.jsx(t.icon,{className:"h-4 w-4"}),t.label]},t.id))}),e.jsxs("div",{className:"p-6",children:[x==="basic"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:[a("personaForm.basic.name")," *"]}),e.jsx("input",{type:"text",value:o.name,onChange:t=>R("name",t.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:a("personaForm.basic.namePlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:[a("personaForm.basic.model")," *"]}),e.jsxs("select",{value:o.model,onChange:t=>R("model",t.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:[e.jsx("option",{value:"",children:a("personaForm.basic.selectModel")}),k.map(t=>e.jsx("option",{value:t.name,children:t.name},t.name))]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:a("personaForm.basic.description")}),e.jsx("textarea",{value:o.description,onChange:t=>R("description",t.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:a("personaForm.basic.descriptionPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(ce,{value:o.avatar||"",onChange:t=>R("avatar",t)}),e.jsx(Ee,{value:o.background||"",onChange:t=>R("background",t)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:a("personaForm.basic.systemPrompt")}),e.jsx("textarea",{value:o.parameters.system_prompt,onChange:t=>X("system_prompt",t.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:a("personaForm.basic.systemPromptPlaceholder")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-dark-600 mt-2",children:a("personaForm.basic.systemPromptHint")})]})]}),x==="parameters"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:ie.map(({key:t,label:u,min:v,max:A,step:I,hint:h,format:S})=>e.jsx(J,{label:u,value:o.parameters[t]||0,min:v,max:A,step:I,hint:h,format:S,onChange:q=>X(t,q)},t))}),x==="memory"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30",children:[e.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:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx($,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-white",children:a("personaForm.memory.title")}),e.jsx("p",{className:"text-xs text-white/80",children:a("personaForm.memory.subtitle")})]})]}),e.jsx(z,{label:"",checked:o.memory_settings?.enabled||!1,onChange:t=>B("memory_settings",{enabled:t})})]})}),o.memory_settings?.enabled&&r?.id&&e.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:g?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400",children:[e.jsx(re,{className:"h-4 w-4 animate-spin"}),a("personaForm.memory.loading")]}):M?e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300",children:[e.jsx($,{className:"h-5 w-5"}),M.memory_count.toLocaleString()]}),e.jsx("p",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:a("personaForm.memory.memories")})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300",children:[e.jsx(Fe,{className:"h-5 w-5"}),M.size_mb.toFixed(1)]}),e.jsx("p",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:a("personaForm.memory.mbUsed")})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300",children:[e.jsx(Ce,{className:"h-5 w-5"}),M.last_backup?new Date(M.last_backup).toLocaleDateString():a("personaForm.memory.never")]}),e.jsx("p",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:a("personaForm.memory.lastBackup")})]})]}):e.jsx("p",{className:"text-sm text-emerald-600 dark:text-emerald-400",children:a("personaForm.memory.noData")})}),o.memory_settings?.enabled&&e.jsxs("div",{className:"p-5 bg-white dark:bg-dark-100 space-y-4",children:[e.jsx(J,{label:a("personaForm.memory.maxMemories"),value:o.memory_settings.max_memories,min:100,max:1e4,step:100,hint:a("personaForm.memory.maxMemoriesHint"),format:t=>t.toLocaleString(),colorClass:"text-emerald-700 dark:text-emerald-300",onChange:t=>B("memory_settings",{max_memories:t})}),e.jsx(J,{label:a("personaForm.memory.retention"),value:o.memory_settings.retention_days,min:7,max:365,step:7,hint:a("personaForm.memory.retentionHint"),format:t=>`${Math.round(t)} days`,colorClass:"text-emerald-700 dark:text-emerald-300",onChange:t=>B("memory_settings",{retention_days:t})}),e.jsx(z,{label:a("personaForm.memory.autoCleanup"),checked:o.memory_settings.auto_cleanup,onChange:t=>B("memory_settings",{auto_cleanup:t}),colorClass:"text-emerald-700 dark:text-emerald-300"}),r?.id&&M&&M.memory_count>0&&e.jsx("div",{className:"pt-4 border-t border-gray-200 dark:border-dark-300",children:e.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:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:a("personaForm.memory.wipeAll")}),e.jsx("p",{className:"text-xs text-red-600 dark:text-red-400",children:a("personaForm.memory.wipeCannot")})]}),e.jsxs("button",{type:"button",onClick:ne,disabled:_,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:[_?e.jsx(re,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(de,{className:"h-3.5 w-3.5"}),a(_?"personaForm.memory.wiping":"personaForm.memory.wipeButton")]})]})})]}),!o.memory_settings?.enabled&&e.jsx("div",{className:"p-5 bg-gray-50 dark:bg-dark-50",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 text-center",children:a("personaForm.memory.enableHint")})})]}),e.jsxs("div",{className:"rounded-xl overflow-hidden border border-violet-200/50 dark:border-violet-700/30",children:[e.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:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx(te,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-white",children:a("personaForm.learning.title")}),e.jsx("p",{className:"text-xs text-white/80",children:a("personaForm.learning.subtitle")})]})]}),e.jsx(z,{label:"",checked:o.mutation_settings?.enabled||!1,onChange:t=>B("mutation_settings",{enabled:t})})]})}),o.mutation_settings?.enabled&&e.jsxs("div",{className:"p-5 bg-white dark:bg-dark-100 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-violet-700 dark:text-violet-300 mb-3",children:a("personaForm.learning.speed")}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{level:"low",icon:oe,label:a("personaForm.learning.slow"),desc:a("personaForm.learning.slowDesc")},{level:"medium",icon:te,label:a("personaForm.learning.balanced"),desc:a("personaForm.learning.balancedDesc")},{level:"high",icon:O,label:a("personaForm.learning.fast"),desc:a("personaForm.learning.fastDesc")}].map(({level:t,icon:u,label:v,desc:A})=>e.jsxs("button",{type:"button",onClick:()=>B("mutation_settings",{sensitivity:t}),className:L("p-3 rounded-xl text-center transition-all border",o.mutation_settings?.sensitivity===t?"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:[e.jsx(u,{className:"h-5 w-5 mx-auto mb-1"}),e.jsx("p",{className:"text-sm font-medium",children:v}),e.jsx("p",{className:"text-[10px] opacity-70",children:A})]},t))})]}),e.jsx(z,{label:a("personaForm.learning.autoAdapt"),checked:o.mutation_settings.auto_adapt,onChange:t=>B("mutation_settings",{auto_adapt:t}),colorClass:"text-violet-700 dark:text-violet-300"}),e.jsxs("div",{className:"p-4 bg-violet-50 dark:bg-violet-900/20 rounded-xl",children:[e.jsxs("p",{className:"text-xs font-medium text-violet-700 dark:text-violet-300 mb-2 flex items-center gap-1.5",children:[e.jsx(K,{className:"h-3.5 w-3.5"}),a("personaForm.learning.whatLearns")]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs text-violet-600 dark:text-violet-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-violet-400"}),a("personaForm.learning.conversationTone")]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-violet-400"}),a("personaForm.learning.responseStyle")]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-violet-400"}),a("personaForm.learning.userPreferences")]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-violet-400"}),a("personaForm.learning.topicInterests")]})]})]})]}),!o.mutation_settings?.enabled&&e.jsx("div",{className:"p-5 bg-gray-50 dark:bg-dark-50",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 text-center",children:a("personaForm.learning.enableHint")})})]})]}),x==="advanced"&&e.jsxs("div",{className:"space-y-6",children:[e.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:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx($,{className:"h-5 w-5 text-primary-600 dark:text-primary-400"}),e.jsx("h3",{className:"font-semibold text-primary-900 dark:text-primary-100",children:a("personaForm.advanced.embeddingModel")})]}),e.jsx("p",{className:"text-xs text-primary-600 dark:text-primary-400 mb-3",children:a("personaForm.advanced.embeddingHint")}),e.jsx("select",{value:o.embedding_model,onChange:t=>R("embedding_model",t.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:d.length===0?e.jsx("option",{value:"",disabled:!0,children:a("personaForm.advanced.noModels")}):e.jsxs(e.Fragment,{children:[d.filter(t=>t.isDetectedEmbedding).length>0&&e.jsx("optgroup",{label:a("personaForm.advanced.embeddingModels"),children:d.filter(t=>t.isDetectedEmbedding).map(t=>e.jsxs("option",{value:t.id,children:[t.name," - ",t.description]},t.id))}),d.filter(t=>!t.isDetectedEmbedding).length>0&&e.jsx("optgroup",{label:a("personaForm.advanced.otherModels"),children:d.filter(t=>!t.isDetectedEmbedding).map(t=>e.jsxs("option",{value:t.id,children:[t.name," - ",t.description]},t.id))})]})}),d.length===0&&e.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:e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-200",children:[a("personaForm.advanced.installHint")," ",e.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"})]})}),e.jsx("p",{className:"text-[10px] text-primary-500 dark:text-primary-500 mt-2",children:a("personaForm.advanced.recommended")})]}),e.jsx("div",{className:"p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(_e,{className:"h-5 w-5 text-gray-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:a("personaForm.advanced.aboutTitle")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:a("personaForm.advanced.aboutDescription")})]})]})})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(P,{type:"button",variant:"ghost",onClick:N,disabled:s,className:"text-gray-600 dark:text-gray-400",children:a("personaForm.actions.cancel")}),e.jsxs("div",{className:"flex items-center gap-3",children:[c&&e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-emerald-600 dark:text-emerald-400",children:[e.jsx(Se,{className:"h-4 w-4"}),e.jsx("span",{children:a("personaForm.saved")})]}),e.jsx(P,{type:"button",variant:"outline",onClick:()=>Q(!1),disabled:s,children:a(s&&!p?"personaForm.actions.saving":"personaForm.actions.save")}),e.jsx(P,{type:"button",onClick:()=>Q(!0),disabled:s,children:a(s&&p?"personaForm.actions.saving":r?"personaForm.actions.saveClose":"personaForm.actions.create")})]})]})]})]})},De=({personas:r,onImport:b,onClose:N})=>{const{t:a}=T(),[o,f]=n.useState(!1),[k,E]=n.useState(""),d=async s=>{try{const m=await C.exportPersona(s.id),p=new Blob([JSON.stringify(m,null,2)],{type:"application/json"}),l=URL.createObjectURL(p),c=document.createElement("a");c.href=l,c.download=`${s.name}.json`,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(l),i.success(a("personaImportExport.exportSuccess",{name:s.name}))}catch(m){const p=m instanceof Error?m.message:String(m);i.error(a("personaImportExport.exportFailed")+": "+p)}},y=async()=>{try{const s=r.map(x=>C.exportPersona(x.id)),m=await Promise.all(s),p={personas:m,exportedAt:Date.now(),version:"1.0.0",count:m.length},l=new Blob([JSON.stringify(p,null,2)],{type:"application/json"}),c=URL.createObjectURL(l),w=document.createElement("a");w.href=c,w.download=`personas-export-${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(c),i.success(a("personaImportExport.exportAllSuccess",{count:r.length}))}catch(s){const m=s instanceof Error?s.message:String(s);i.error(a("personaImportExport.exportAllFailed")+": "+m)}},D=async()=>{if(!k.trim()){i.error(a("personaImportExport.pasteJsonData"));return}f(!0);try{const s=JSON.parse(k);if(s.personas&&Array.isArray(s.personas)){let m=0,p=0;for(const l of s.personas)try{await C.importPersona(l),m++}catch(c){p++,console.error("Failed to import persona:",c)}m>0?(i.success(a("personaImportExport.importMultipleSuccess",{count:m})),p>0&&i.error(a("personaImportExport.importMultipleFailed",{count:p}))):i.error(a("personaImportExport.importNoneFailed"))}else await C.importPersona(s),i.success(a("personaImportExport.importSuccess"));E(""),b()}catch(s){const m=s instanceof Error?s.message:String(s);i.error(a("personaImportExport.importFailed")+": "+m)}finally{f(!1)}},j=s=>{const m=s.target.files?.[0];if(m){const p=new FileReader;p.onload=l=>{const c=l.target?.result;typeof c=="string"&&E(c)},p.readAsText(m)}};return e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-dark-800",children:a("personaImportExport.title")}),e.jsx("p",{className:"text-gray-600 dark:text-dark-600 mt-1",children:a("personaImportExport.description")})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4",children:a("personaImportExport.exportPersonas")}),r.length===0?e.jsx("p",{className:"text-gray-600 dark:text-dark-600 text-center py-8",children:a("personaImportExport.noPersonasToExport")}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-gray-600 dark:text-dark-600",children:a("personaImportExport.personasAvailable",{count:r.length})}),e.jsx(P,{onClick:y,variant:"outline",size:"sm",className:"px-3 py-1",children:a("personaImportExport.exportAll")})]}),e.jsx("div",{className:"space-y-2 max-h-80 overflow-y-auto",children:r.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:s.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(s.name)}&background=6366f1&color=fff&size=32`,alt:s.name,className:"w-8 h-8 rounded-full"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-dark-800",children:s.name}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-dark-500",children:s.model})]})]}),e.jsx(P,{onClick:()=>d(s),variant:"outline",size:"sm",className:"px-3 py-1",children:a("common.export")})]},s.id))})]})]}),e.jsxs("div",{className:"bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4",children:a("personaImportExport.importPersonas")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2",children:a("personaImportExport.uploadJsonFile")}),e.jsx("input",{type:"file",accept:".json",onChange:j,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"})]}),e.jsx("div",{className:"text-center text-gray-500 dark:text-dark-500",children:a("common.or").toUpperCase()}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2",children:a("personaImportExport.pasteJsonLabel")}),e.jsx("textarea",{value:k,onChange:s=>E(s.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")})]}),e.jsx(P,{onClick:D,disabled:!k.trim()||o,className:"w-full",children:a(o?"personaImportExport.importing":"personaImportExport.importButton")})]})]})]}),e.jsxs("div",{className:"mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-dark-800 mb-2",children:a("personaImportExport.expectedFormat")}),e.jsx("pre",{className:"text-xs text-gray-600 dark:text-dark-600 overflow-x-auto",children:`{
|
|
1
|
+
import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as n}from"./router-vendor-DdQhGl5t.js";import{a as T,g as C,c as L,B as P,A as ce,o as me}from"../assets/index-DW8C1vVk.js";import{u as O,av as ee,m as ae,a4 as K,aj as xe,M as pe,$ as oe,D as $,aw as ge,k as he,ax as ue,ay as be,az as ye,Y as ke,T as de,z as i,X as fe,I as ve,U as je,q as Ne,b as we,a3 as re,ab as Fe,aq as Ce,aA as te,d as _e,C as Se}from"./ui-vendor-C4ZcWovR.js";import"./utils-vendor-BFlGJDIj.js";const Me=({persona:r,onEdit:b,onDelete:N,onDownload:a,onSelect:o,onToggleFavorite:f,isSelected:k=!1,compact:E=!1})=>{const{t:d}=T(),[y,D]=n.useState(null),[j,s]=n.useState(!1),[m,p]=n.useState(!1),l=!!(r.memory_settings?.enabled||r.mutation_settings?.enabled),c=n.useCallback(async()=>{if(l)try{const g=await C.getMemoryStatus(r.id);g.success&&g.data&&D(g.data)}catch(g){console.error("Failed to load memory status:",g)}},[r.id,l]);n.useEffect(()=>{c()},[c]);const w=async()=>{if(confirm(d("personaCard.wipeConfirm"))){p(!0);try{const g=await C.wipeMemories(r.id);g.success?(i.success(d("personaCard.wipeSuccess",{count:g.data?.deleted_count||0})),await c()):i.error(d("personaCard.failed",{action:"wipe memories"}))}catch(g){i.error(d("personaCard.failed",{action:"wipe memories"})),console.error(g)}finally{p(!1),s(!1)}}},x=async()=>{p(!0);try{const g=await C.backupPersona(r.id),U=window.URL.createObjectURL(g),_=document.createElement("a");_.href=U,_.download=`${r.name.toLowerCase().replace(/\s+/g,"-")}-backup.json`,document.body.appendChild(_),_.click(),window.URL.revokeObjectURL(U),document.body.removeChild(_),i.success(d("personaCard.backupSuccess"))}catch(g){i.error(d("personaCard.failed",{action:"backup persona"})),console.error(g)}finally{p(!1),s(!1)}},F=async()=>{p(!0);try{const g=await C.exportPersonaDNA(r.id),U=window.URL.createObjectURL(g),_=document.createElement("a");_.href=U,_.download=`${r.name.toLowerCase().replace(/\s+/g,"-")}-dna.json`,document.body.appendChild(_),_.click(),window.URL.revokeObjectURL(U),document.body.removeChild(_),i.success(d("personaCard.dnaSuccess"))}catch(g){i.error(d("personaCard.failed",{action:"export persona DNA"})),console.error(g)}finally{p(!1),s(!1)}},M=()=>r.avatar?r.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(r.name)}&background=6366f1&color=fff&size=128`,H=g=>g<1?`${(g*1024).toFixed(0)} KB`:`${g.toFixed(1)} MB`;return E?e.jsxs("div",{className:L("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]",k&&["bg-primary-50 dark:bg-primary-900/20 ophelia:bg-[#9333ea]/10","border-primary-200 dark:border-primary-700 ophelia:border-[#7c3aed]"]),onClick:()=>o?.(r),children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("img",{src:M(),alt:r.name,className:"w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a]"}),l&&e.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:e.jsx(O,{className:"h-2.5 w-2.5 text-white"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("h4",{className:"font-medium text-sm text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] truncate",children:r.name}),r.is_favorite&&e.jsx(ee,{className:"h-3 w-3 text-amber-500 fill-amber-500 flex-shrink-0"})]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 ophelia:text-[#a3a3a3] truncate",children:r.model})]}),k&&e.jsx("div",{className:"flex-shrink-0",children:e.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:e.jsx(ae,{className:"h-3 w-3 text-white ml-0.5"})})})]}):e.jsxs("div",{className:L("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",k&&["ring-2 ring-primary-500 dark:ring-primary-400 ophelia:ring-[#9333ea]","border-primary-300 dark:border-primary-600 ophelia:border-[#7c3aed]"]),children:[e.jsxs("div",{className:"relative h-20",children:[r.background?e.jsx("div",{className:"absolute inset-0 bg-cover bg-center",style:{backgroundImage:`url(${r.background})`}}):e.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]"}),e.jsx("div",{className:"absolute inset-0 bg-black/10 dark:bg-black/20"}),e.jsxs("div",{className:"absolute top-3 left-3 right-3 flex items-start justify-between",children:[e.jsx("button",{onClick:g=>{g.stopPropagation(),f?.(r)},className:L("p-1.5 rounded-full transition-all duration-200","bg-white/20 hover:bg-white/30 backdrop-blur-sm",r.is_favorite&&"bg-amber-500/80 hover:bg-amber-500"),children:e.jsx(ee,{className:L("h-4 w-4",r.is_favorite?"text-white fill-white":"text-white/80 hover:text-white")})}),l&&e.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:[e.jsx(O,{className:"h-3 w-3"}),d("personaCard.enhanced")]})]})]}),e.jsx("div",{className:"relative px-4 -mt-8",children:e.jsxs("div",{className:"relative inline-block",children:[e.jsx("img",{src:M(),alt:r.name,className:"w-16 h-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100 ophelia:ring-[#0a0a0a] shadow-lg"}),l&&e.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:e.jsx(K,{className:"h-3.5 w-3.5 text-white"})})]})}),e.jsxs("div",{className:"px-4 pt-3 pb-4",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 ophelia:text-[#fafafa] leading-tight",children:r.name}),e.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:[e.jsx(xe,{className:"h-3.5 w-3.5"}),r.model]})]}),r.description&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 mb-3",children:r.description}),r.parameters.system_prompt&&e.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:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(pe,{className:"h-3 w-3 text-gray-400 dark:text-gray-500 ophelia:text-[#737373]"}),e.jsx("span",{className:"text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500 ophelia:text-[#737373]",children:d("personaCard.systemPrompt")})]}),e.jsxs("p",{className:"text-xs text-gray-600 dark:text-gray-400 ophelia:text-[#a3a3a3] line-clamp-2 italic",children:["“",r.parameters.system_prompt,"”"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[e.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:[e.jsx(oe,{className:"h-3 w-3"}),r.parameters.temperature?.toFixed(1)||"0.7"]}),e.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 ",r.parameters.top_p?.toFixed(1)||"0.9"]}),e.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:[(r.parameters.context_window||4096).toLocaleString()," ctx"]})]}),l&&y&&e.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:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{className:"h-4 w-4 text-primary-600 dark:text-primary-400 ophelia:text-[#a855f7]"}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-xs font-medium text-primary-700 dark:text-primary-300 ophelia:text-[#c084fc]",children:[y.memory_count," ",d("personaCard.memories")]}),e.jsx("span",{className:"text-[10px] text-primary-600/70 dark:text-primary-400/70 ophelia:text-[#a855f7]/70 ml-2",children:H(y.size_mb)})]})]}),y.status&&e.jsx("span",{className:L("text-[10px] px-1.5 py-0.5 rounded-full font-medium",y.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:y.status})]})}),e.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]",children:[o&&e.jsxs(P,{onClick:()=>o(r),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:[e.jsx(ae,{className:"h-3.5 w-3.5 mr-1.5"}),d("personaCard.use")]}),e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx("button",{onClick:()=>b(r),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:d("personaCard.editTooltip"),children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>a(r),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:d("personaCard.downloadTooltip"),children:e.jsx(he,{className:"h-4 w-4"})}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>s(!j),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:e.jsx(ue,{className:"h-4 w-4"})}),j&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),e.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:[l&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:x,disabled:m,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:[e.jsx(be,{className:"h-4 w-4"}),d("personaCard.backup")]}),e.jsxs("button",{onClick:F,disabled:m,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:[e.jsx(ye,{className:"h-4 w-4"}),d("personaCard.exportDNA")]}),y&&y.memory_count>0&&e.jsxs("button",{onClick:w,disabled:m,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:[e.jsx(ke,{className:"h-4 w-4"}),d("personaCard.wipeMemories")]}),e.jsx("div",{className:"my-1 border-t border-gray-100 dark:border-dark-200 ophelia:border-[#1a1a1a]"})]}),e.jsxs("button",{onClick:()=>{N(r),s(!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:[e.jsx(de,{className:"h-4 w-4"}),d("common.delete")]})]})]})]})]})]})]})]})},Ee=({value:r,onChange:b,className:N=""})=>{const{t:a}=T(),o=n.useRef(null),[f,k]=n.useState(!1),[E,d]=n.useState(!1),y=async l=>{if(!l.type.startsWith("image/")){i.error(a("personaBackground.invalidFile"));return}if(l.size>5*1024*1024){i.error(a("personaBackground.fileTooLarge"));return}k(!0);try{const c=new FileReader;c.onload=w=>{const x=w.target?.result;b(x),i.success(a("personaBackground.uploaded"))},c.onerror=()=>{i.error(a("personaBackground.readFailed"))},c.readAsDataURL(l)}catch(c){console.error("Failed to upload background:",c),i.error(a("personaBackground.uploadFailed"))}finally{k(!1)}},D=l=>{const c=l.target.files?.[0];c&&y(c)},j=l=>{l.preventDefault(),d(!0)},s=l=>{l.preventDefault(),d(!1)},m=l=>{l.preventDefault(),d(!1);const c=l.dataTransfer.files?.[0];c&&y(c)},p=()=>{b(""),i.success(a("personaBackground.removed"))};return e.jsx("div",{className:`space-y-4 ${N}`,children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:a("personaBackground.label")}),e.jsxs("div",{className:"space-y-3",children:[r?e.jsxs("div",{className:"space-y-3",children:[e.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(${r})`}}),e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:a("personaBackground.customBackground")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:a("personaBackground.clickToChange")})]}),e.jsx(P,{variant:"ghost",size:"sm",onClick:p,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:e.jsx(fe,{className:"h-4 w-4"})})]})]}):e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${E?"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:j,onDragLeave:s,onDrop:m,onClick:()=>o.current?.click(),children:[e.jsx(ve,{className:"h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4"}),e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 mb-2",children:a("personaBackground.uploadBackgroundImage")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-4",children:a("personaBackground.dragAndDrop")}),e.jsxs(P,{variant:"outline",size:"sm",disabled:f,className:"mx-auto",children:[e.jsx(je,{className:"h-4 w-4 mr-2"}),a(f?"personaBackground.uploading":"personaBackground.chooseImage")]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1",children:a("personaBackground.enterImageUrl")}),e.jsx("input",{type:"url",value:r,onChange:l=>b(l.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"})]})]}),e.jsx("input",{ref:o,type:"file",accept:"image/*",onChange:D,className:"hidden"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-2",children:a("personaBackground.supportedFormats")})]})})},J=({label:r,value:b,min:N,max:a,step:o,onChange:f,hint:k,format:E=y=>String(y),colorClass:d="text-gray-700 dark:text-dark-600"})=>{const y=(b-N)/(a-N)*100,D=j=>{const s=parseFloat(j.target.value);if(!isNaN(s)){const m=Math.min(a,Math.max(N,s));f(m)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:L("block text-sm font-medium",d),children:r}),e.jsx("input",{type:"number",min:N,max:a,step:o,value:E(b),onChange:D,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"})]}),e.jsx("input",{type:"range",min:N,max:a,step:o,value:b,onChange:j=>f(parseFloat(j.target.value)),className:"w-full h-2 bg-gray-200 dark:bg-dark-200 rounded-lg appearance-none cursor-pointer slider",style:{"--progress":`${y}%`}}),k&&e.jsx("p",{className:L("text-xs mt-1",d.replace("700","500").replace("600","400")),children:k})]})},z=({label:r,checked:b,onChange:N,colorClass:a="text-gray-700 dark:text-dark-600"})=>e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("div",{className:L("relative w-10 h-5 rounded-full transition-colors",b?"bg-primary-500 dark:bg-primary-600":"bg-gray-300 dark:bg-dark-300"),onClick:()=>N(!b),children:e.jsx("div",{className:L("absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform",b&&"translate-x-5")})}),e.jsx("span",{className:L("text-sm font-medium",a),children:r})]}),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}},se=["embed","e5","bge","gte","minilm","multilingual","sentence","universal","instructor","jina","paraphrase","mpnet","contriever"],Pe=({persona:r,onSubmit:b,onCancel:N})=>{const{t:a}=T(),[o,f]=n.useState(V),[k,E]=n.useState([]),[d,y]=n.useState([]),[D,j]=n.useState(!1),[s,m]=n.useState(!1),[p,l]=n.useState(!1),[c,w]=n.useState(null),[x,F]=n.useState("basic"),[M,H]=n.useState(null),[g,U]=n.useState(!1),[_,Y]=n.useState(!1),G=n.useRef(!1),R=n.useCallback((t,u)=>{f(v=>({...v,[t]:u})),w(null)},[]),X=n.useCallback((t,u)=>{f(v=>({...v,parameters:{...v.parameters,[t]:u}})),w(null)},[]),B=n.useCallback((t,u)=>{f(v=>({...v,[t]:{...v[t],...u}})),w(null)},[]),Z=n.useCallback(t=>{const u=t.filter(h=>se.some(S=>h.name.toLowerCase().includes(S.toLowerCase()))).map(h=>({id:h.name,name:h.name,description:`${h.details?.parameter_size||"Unknown size"} - ${h.details?.family||"Ollama model"}`,provider:"ollama",dimensions:768,isDetectedEmbedding:!0})),v=t.filter(h=>!se.some(S=>h.name.toLowerCase().includes(S.toLowerCase()))).map(h=>({id:h.name,name:h.name,description:`${h.details?.parameter_size||"Unknown size"} - ${h.details?.family||"Other model"}`,provider:"ollama",dimensions:768,isDetectedEmbedding:!1})),I=[...u,...v].reduce((h,S)=>(h.find(q=>q.id===S.id)||h.push(S),h),[]);return I.length>0?I:[{id:"nomic-embed-text",name:"nomic-embed-text",description:"Default embedding model (install if needed)",provider:"ollama",dimensions:768}]},[]),W=n.useCallback(async()=>{if(r?.id){U(!0);try{const t=await C.getMemoryStatus(r.id);t.success&&t.data&&H(t.data)}catch(t){console.error("Failed to load memory status:",t)}finally{U(!1)}}},[r?.id]),ne=async()=>{if(r?.id&&confirm(a("personaForm.memory.wipeConfirm"))){Y(!0);try{const t=await C.wipeMemories(r.id);t.success?(i.success(a("personaForm.memory.wipeSuccess",{count:t.data?.deleted_count||0})),await W()):i.error(a("personaForm.error.saveFailed"))}catch{i.error(a("personaForm.error.saveFailed"))}finally{Y(!1)}}};n.useEffect(()=>{if(G.current)return;G.current=!0,(async()=>{j(!0);try{const[u,v]=await Promise.all([me.getModels(),r?Promise.resolve(null):C.getDefaultParameters()]);if(u.success&&u.data){E(u.data);const A=Z(u.data);if(y(A),r){if(f({name:r.name,description:r.description||"",model:r.model,parameters:r.parameters,avatar:r.avatar||"",background:r.background||"",embedding_model:r.embedding_model||A[0]?.id||"",memory_settings:r.memory_settings||V.memory_settings,mutation_settings:r.mutation_settings||V.mutation_settings}),r.embedding_model&&!A.find(I=>I.id===r.embedding_model)){const I=r.embedding_model.split(":")[0],h=A.find(S=>S.id.startsWith(I+":")||S.id===I);h?f(S=>({...S,embedding_model:h.id})):y(S=>[...S,{id:r.embedding_model,name:r.embedding_model,description:"Previously selected model (not currently installed)",provider:"ollama",dimensions:768}])}}else{const I=v?.success?v.data:{};f(h=>({...h,parameters:{...h.parameters,...I},embedding_model:A[0]?.id||""}))}}}catch(u){console.error("Error loading data:",u)}finally{j(!1)}})()},[r,Z]),n.useEffect(()=>{r?.id&&o.memory_settings?.enabled&&W()},[r?.id,o.memory_settings?.enabled,W]);const Q=async t=>{m(!0),l(t);try{const u={name:o.name,description:o.description,model:o.model,parameters:o.parameters,avatar:o.avatar,background:o.background,embedding_model:o.embedding_model,memory_settings:o.memory_settings,mutation_settings:o.mutation_settings},v=r?await C.updatePersona(r.id,u):await C.createPersona(o);v.success?(i.success(a(r?"personaForm.success.updated":"personaForm.success.created")),w(new Date),t&&b()):i.error(`${a("personaForm.error.saveFailed")}: ${v.error}`)}catch(u){i.error(`${a("personaForm.error.saveFailed")}: ${u instanceof Error?u.message:String(u)}`)}finally{m(!1),l(!1)}},le=n.useMemo(()=>[{id:"basic",label:a("personaForm.tabs.basic"),icon:Ne},{id:"parameters",label:a("personaForm.tabs.parameters"),icon:we},{id:"memory",label:a("personaForm.tabs.memory"),icon:O},{id:"advanced",label:a("personaForm.tabs.advanced"),icon:K}],[a]),ie=n.useMemo(()=>[{key:"temperature",label:a("personaForm.parameters.temperature"),min:0,max:2,step:.1,hint:a("personaForm.parameters.temperatureHint"),format:t=>t.toFixed(1)},{key:"top_p",label:a("personaForm.parameters.topP"),min:0,max:1,step:.1,hint:a("personaForm.parameters.topPHint"),format:t=>t.toFixed(1)},{key:"top_k",label:a("personaForm.parameters.topK"),min:1,max:100,step:1,hint:a("personaForm.parameters.topKHint"),format:t=>String(Math.round(t))},{key:"context_window",label:a("personaForm.parameters.contextWindow"),min:128,max:131072,step:128,hint:a("personaForm.parameters.contextWindowHint"),format:t=>String(Math.round(t))},{key:"max_tokens",label:a("personaForm.parameters.maxTokens"),min:1,max:8192,step:1,hint:a("personaForm.parameters.maxTokensHint"),format:t=>String(Math.round(t))},{key:"repeat_penalty",label:a("personaForm.parameters.repeatPenalty"),min:.5,max:2,step:.1,hint:a("personaForm.parameters.repeatPenaltyHint"),format:t=>t.toFixed(1)}],[a]);return D?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsxs("div",{className:"animate-pulse flex items-center gap-3",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:a("personaForm.loading")})]})}):e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-dark-800",children:a(r?"personaForm.title.edit":"personaForm.title.create")}),e.jsxs("div",{className:"flex items-center gap-4 mt-1",children:[e.jsx("p",{className:"text-gray-600 dark:text-dark-600",children:a(r?"personaForm.subtitle.edit":"personaForm.subtitle.create")}),c&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-600 dark:text-green-400",children:[e.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),a("personaForm.saved")," ",c.toLocaleTimeString()]})]})]}),e.jsxs("form",{onSubmit:t=>t.preventDefault(),className:"space-y-6",children:[e.jsxs("div",{className:"bg-white dark:bg-dark-100 rounded-lg shadow-sm border border-gray-200 dark:border-dark-300",children:[e.jsx("div",{className:"flex border-b border-gray-200 dark:border-dark-300",children:le.map(t=>e.jsxs("button",{type:"button",onClick:()=>F(t.id),className:`flex items-center gap-2 px-6 py-4 text-sm font-medium transition-colors ${x===t.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:[e.jsx(t.icon,{className:"h-4 w-4"}),t.label]},t.id))}),e.jsxs("div",{className:"p-6",children:[x==="basic"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:[a("personaForm.basic.name")," *"]}),e.jsx("input",{type:"text",value:o.name,onChange:t=>R("name",t.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:a("personaForm.basic.namePlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:[a("personaForm.basic.model")," *"]}),e.jsxs("select",{value:o.model,onChange:t=>R("model",t.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:[e.jsx("option",{value:"",children:a("personaForm.basic.selectModel")}),k.map(t=>e.jsx("option",{value:t.name,children:t.name},t.name))]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:a("personaForm.basic.description")}),e.jsx("textarea",{value:o.description,onChange:t=>R("description",t.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:a("personaForm.basic.descriptionPlaceholder")})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(ce,{value:o.avatar||"",onChange:t=>R("avatar",t)}),e.jsx(Ee,{value:o.background||"",onChange:t=>R("background",t)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2",children:a("personaForm.basic.systemPrompt")}),e.jsx("textarea",{value:o.parameters.system_prompt,onChange:t=>X("system_prompt",t.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:a("personaForm.basic.systemPromptPlaceholder")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-dark-600 mt-2",children:a("personaForm.basic.systemPromptHint")})]})]}),x==="parameters"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:ie.map(({key:t,label:u,min:v,max:A,step:I,hint:h,format:S})=>e.jsx(J,{label:u,value:o.parameters[t]||0,min:v,max:A,step:I,hint:h,format:S,onChange:q=>X(t,q)},t))}),x==="memory"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30",children:[e.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:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx($,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-white",children:a("personaForm.memory.title")}),e.jsx("p",{className:"text-xs text-white/80",children:a("personaForm.memory.subtitle")})]})]}),e.jsx(z,{label:"",checked:o.memory_settings?.enabled||!1,onChange:t=>B("memory_settings",{enabled:t})})]})}),o.memory_settings?.enabled&&r?.id&&e.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:g?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400",children:[e.jsx(re,{className:"h-4 w-4 animate-spin"}),a("personaForm.memory.loading")]}):M?e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300",children:[e.jsx($,{className:"h-5 w-5"}),M.memory_count.toLocaleString()]}),e.jsx("p",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:a("personaForm.memory.memories")})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300",children:[e.jsx(Fe,{className:"h-5 w-5"}),M.size_mb.toFixed(1)]}),e.jsx("p",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:a("personaForm.memory.mbUsed")})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300",children:[e.jsx(Ce,{className:"h-5 w-5"}),M.last_backup?new Date(M.last_backup).toLocaleDateString():a("personaForm.memory.never")]}),e.jsx("p",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:a("personaForm.memory.lastBackup")})]})]}):e.jsx("p",{className:"text-sm text-emerald-600 dark:text-emerald-400",children:a("personaForm.memory.noData")})}),o.memory_settings?.enabled&&e.jsxs("div",{className:"p-5 bg-white dark:bg-dark-100 space-y-4",children:[e.jsx(J,{label:a("personaForm.memory.maxMemories"),value:o.memory_settings.max_memories,min:100,max:1e4,step:100,hint:a("personaForm.memory.maxMemoriesHint"),format:t=>t.toLocaleString(),colorClass:"text-emerald-700 dark:text-emerald-300",onChange:t=>B("memory_settings",{max_memories:t})}),e.jsx(J,{label:a("personaForm.memory.retention"),value:o.memory_settings.retention_days,min:7,max:365,step:7,hint:a("personaForm.memory.retentionHint"),format:t=>`${Math.round(t)} days`,colorClass:"text-emerald-700 dark:text-emerald-300",onChange:t=>B("memory_settings",{retention_days:t})}),e.jsx(z,{label:a("personaForm.memory.autoCleanup"),checked:o.memory_settings.auto_cleanup,onChange:t=>B("memory_settings",{auto_cleanup:t}),colorClass:"text-emerald-700 dark:text-emerald-300"}),r?.id&&M&&M.memory_count>0&&e.jsx("div",{className:"pt-4 border-t border-gray-200 dark:border-dark-300",children:e.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:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:a("personaForm.memory.wipeAll")}),e.jsx("p",{className:"text-xs text-red-600 dark:text-red-400",children:a("personaForm.memory.wipeCannot")})]}),e.jsxs("button",{type:"button",onClick:ne,disabled:_,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:[_?e.jsx(re,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(de,{className:"h-3.5 w-3.5"}),a(_?"personaForm.memory.wiping":"personaForm.memory.wipeButton")]})]})})]}),!o.memory_settings?.enabled&&e.jsx("div",{className:"p-5 bg-gray-50 dark:bg-dark-50",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 text-center",children:a("personaForm.memory.enableHint")})})]}),e.jsxs("div",{className:"rounded-xl overflow-hidden border border-violet-200/50 dark:border-violet-700/30",children:[e.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:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx(te,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-white",children:a("personaForm.learning.title")}),e.jsx("p",{className:"text-xs text-white/80",children:a("personaForm.learning.subtitle")})]})]}),e.jsx(z,{label:"",checked:o.mutation_settings?.enabled||!1,onChange:t=>B("mutation_settings",{enabled:t})})]})}),o.mutation_settings?.enabled&&e.jsxs("div",{className:"p-5 bg-white dark:bg-dark-100 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-violet-700 dark:text-violet-300 mb-3",children:a("personaForm.learning.speed")}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{level:"low",icon:oe,label:a("personaForm.learning.slow"),desc:a("personaForm.learning.slowDesc")},{level:"medium",icon:te,label:a("personaForm.learning.balanced"),desc:a("personaForm.learning.balancedDesc")},{level:"high",icon:O,label:a("personaForm.learning.fast"),desc:a("personaForm.learning.fastDesc")}].map(({level:t,icon:u,label:v,desc:A})=>e.jsxs("button",{type:"button",onClick:()=>B("mutation_settings",{sensitivity:t}),className:L("p-3 rounded-xl text-center transition-all border",o.mutation_settings?.sensitivity===t?"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:[e.jsx(u,{className:"h-5 w-5 mx-auto mb-1"}),e.jsx("p",{className:"text-sm font-medium",children:v}),e.jsx("p",{className:"text-[10px] opacity-70",children:A})]},t))})]}),e.jsx(z,{label:a("personaForm.learning.autoAdapt"),checked:o.mutation_settings.auto_adapt,onChange:t=>B("mutation_settings",{auto_adapt:t}),colorClass:"text-violet-700 dark:text-violet-300"}),e.jsxs("div",{className:"p-4 bg-violet-50 dark:bg-violet-900/20 rounded-xl",children:[e.jsxs("p",{className:"text-xs font-medium text-violet-700 dark:text-violet-300 mb-2 flex items-center gap-1.5",children:[e.jsx(K,{className:"h-3.5 w-3.5"}),a("personaForm.learning.whatLearns")]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs text-violet-600 dark:text-violet-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-violet-400"}),a("personaForm.learning.conversationTone")]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-violet-400"}),a("personaForm.learning.responseStyle")]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-violet-400"}),a("personaForm.learning.userPreferences")]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1 h-1 rounded-full bg-violet-400"}),a("personaForm.learning.topicInterests")]})]})]})]}),!o.mutation_settings?.enabled&&e.jsx("div",{className:"p-5 bg-gray-50 dark:bg-dark-50",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 text-center",children:a("personaForm.learning.enableHint")})})]})]}),x==="advanced"&&e.jsxs("div",{className:"space-y-6",children:[e.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:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx($,{className:"h-5 w-5 text-primary-600 dark:text-primary-400"}),e.jsx("h3",{className:"font-semibold text-primary-900 dark:text-primary-100",children:a("personaForm.advanced.embeddingModel")})]}),e.jsx("p",{className:"text-xs text-primary-600 dark:text-primary-400 mb-3",children:a("personaForm.advanced.embeddingHint")}),e.jsx("select",{value:o.embedding_model,onChange:t=>R("embedding_model",t.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:d.length===0?e.jsx("option",{value:"",disabled:!0,children:a("personaForm.advanced.noModels")}):e.jsxs(e.Fragment,{children:[d.filter(t=>t.isDetectedEmbedding).length>0&&e.jsx("optgroup",{label:a("personaForm.advanced.embeddingModels"),children:d.filter(t=>t.isDetectedEmbedding).map(t=>e.jsxs("option",{value:t.id,children:[t.name," - ",t.description]},t.id))}),d.filter(t=>!t.isDetectedEmbedding).length>0&&e.jsx("optgroup",{label:a("personaForm.advanced.otherModels"),children:d.filter(t=>!t.isDetectedEmbedding).map(t=>e.jsxs("option",{value:t.id,children:[t.name," - ",t.description]},t.id))})]})}),d.length===0&&e.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:e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-200",children:[a("personaForm.advanced.installHint")," ",e.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"})]})}),e.jsx("p",{className:"text-[10px] text-primary-500 dark:text-primary-500 mt-2",children:a("personaForm.advanced.recommended")})]}),e.jsx("div",{className:"p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(_e,{className:"h-5 w-5 text-gray-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:a("personaForm.advanced.aboutTitle")}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:a("personaForm.advanced.aboutDescription")})]})]})})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(P,{type:"button",variant:"ghost",onClick:N,disabled:s,className:"text-gray-600 dark:text-gray-400",children:a("personaForm.actions.cancel")}),e.jsxs("div",{className:"flex items-center gap-3",children:[c&&e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-emerald-600 dark:text-emerald-400",children:[e.jsx(Se,{className:"h-4 w-4"}),e.jsx("span",{children:a("personaForm.saved")})]}),e.jsx(P,{type:"button",variant:"outline",onClick:()=>Q(!1),disabled:s,children:a(s&&!p?"personaForm.actions.saving":"personaForm.actions.save")}),e.jsx(P,{type:"button",onClick:()=>Q(!0),disabled:s,children:a(s&&p?"personaForm.actions.saving":r?"personaForm.actions.saveClose":"personaForm.actions.create")})]})]})]})]})},De=({personas:r,onImport:b,onClose:N})=>{const{t:a}=T(),[o,f]=n.useState(!1),[k,E]=n.useState(""),d=async s=>{try{const m=await C.exportPersona(s.id),p=new Blob([JSON.stringify(m,null,2)],{type:"application/json"}),l=URL.createObjectURL(p),c=document.createElement("a");c.href=l,c.download=`${s.name}.json`,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(l),i.success(a("personaImportExport.exportSuccess",{name:s.name}))}catch(m){const p=m instanceof Error?m.message:String(m);i.error(a("personaImportExport.exportFailed")+": "+p)}},y=async()=>{try{const s=r.map(x=>C.exportPersona(x.id)),m=await Promise.all(s),p={personas:m,exportedAt:Date.now(),version:"1.0.0",count:m.length},l=new Blob([JSON.stringify(p,null,2)],{type:"application/json"}),c=URL.createObjectURL(l),w=document.createElement("a");w.href=c,w.download=`personas-export-${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(c),i.success(a("personaImportExport.exportAllSuccess",{count:r.length}))}catch(s){const m=s instanceof Error?s.message:String(s);i.error(a("personaImportExport.exportAllFailed")+": "+m)}},D=async()=>{if(!k.trim()){i.error(a("personaImportExport.pasteJsonData"));return}f(!0);try{const s=JSON.parse(k);if(s.personas&&Array.isArray(s.personas)){let m=0,p=0;for(const l of s.personas)try{await C.importPersona(l),m++}catch(c){p++,console.error("Failed to import persona:",c)}m>0?(i.success(a("personaImportExport.importMultipleSuccess",{count:m})),p>0&&i.error(a("personaImportExport.importMultipleFailed",{count:p}))):i.error(a("personaImportExport.importNoneFailed"))}else await C.importPersona(s),i.success(a("personaImportExport.importSuccess"));E(""),b()}catch(s){const m=s instanceof Error?s.message:String(s);i.error(a("personaImportExport.importFailed")+": "+m)}finally{f(!1)}},j=s=>{const m=s.target.files?.[0];if(m){const p=new FileReader;p.onload=l=>{const c=l.target?.result;typeof c=="string"&&E(c)},p.readAsText(m)}};return e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-dark-800",children:a("personaImportExport.title")}),e.jsx("p",{className:"text-gray-600 dark:text-dark-600 mt-1",children:a("personaImportExport.description")})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4",children:a("personaImportExport.exportPersonas")}),r.length===0?e.jsx("p",{className:"text-gray-600 dark:text-dark-600 text-center py-8",children:a("personaImportExport.noPersonasToExport")}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm text-gray-600 dark:text-dark-600",children:a("personaImportExport.personasAvailable",{count:r.length})}),e.jsx(P,{onClick:y,variant:"outline",size:"sm",className:"px-3 py-1",children:a("personaImportExport.exportAll")})]}),e.jsx("div",{className:"space-y-2 max-h-80 overflow-y-auto",children:r.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:s.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(s.name)}&background=6366f1&color=fff&size=32`,alt:s.name,className:"w-8 h-8 rounded-full"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-dark-800",children:s.name}),e.jsx("div",{className:"text-sm text-gray-500 dark:text-dark-500",children:s.model})]})]}),e.jsx(P,{onClick:()=>d(s),variant:"outline",size:"sm",className:"px-3 py-1",children:a("common.export")})]},s.id))})]})]}),e.jsxs("div",{className:"bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4",children:a("personaImportExport.importPersonas")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2",children:a("personaImportExport.uploadJsonFile")}),e.jsx("input",{type:"file",accept:".json",onChange:j,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"})]}),e.jsx("div",{className:"text-center text-gray-500 dark:text-dark-500",children:a("common.or").toUpperCase()}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2",children:a("personaImportExport.pasteJsonLabel")}),e.jsx("textarea",{value:k,onChange:s=>E(s.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")})]}),e.jsx(P,{onClick:D,disabled:!k.trim()||o,className:"w-full",children:a(o?"personaImportExport.importing":"personaImportExport.importButton")})]})]})]}),e.jsxs("div",{className:"mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-dark-800 mb-2",children:a("personaImportExport.expectedFormat")}),e.jsx("pre",{className:"text-xs text-gray-600 dark:text-dark-600 overflow-x-auto",children:`{
|
|
2
2
|
"name": "Assistant Name",
|
|
3
3
|
"description": "Brief description of the assistant's personality",
|
|
4
4
|
"model": "model-name:version",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./markdown-vendor-QwEm2Xso.js";import{r as h}from"./router-vendor-CmbUVdlE.js";import{F as m,t as T,y as A,q as L,aw as P,T as H}from"./ui-vendor-DsBonqC3.js";import{a as E,b as I,l as y,B as g,I as p}from"../assets/index-CT6_wIIb.js";import"./utils-vendor-3oAsqusP.js";const o=({children:r,htmlFor:d,className:x=""})=>e.jsx("label",{htmlFor:d,className:`text-sm font-medium text-gray-700 dark:text-gray-300 ${x}`,children:r}),b=({children:r,className:d=""})=>e.jsx("div",{className:`bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 rounded-xl shadow-card hover:shadow-card-hover transition-shadow duration-200 ${d}`,children:r}),f=({children:r,className:d=""})=>e.jsx("div",{className:`flex flex-col space-y-1.5 p-6 ${d}`,children:r}),v=({children:r,className:d=""})=>e.jsx("h3",{className:`text-lg font-semibold leading-none tracking-tight text-gray-900 dark:text-dark-950 ${d}`,children:r}),N=({children:r,className:d=""})=>e.jsx("p",{className:`text-sm text-gray-500 dark:text-dark-500 ${d}`,children:r}),w=({children:r,className:d=""})=>e.jsx("div",{className:`p-6 pt-0 ${d}`,children:r}),R=()=>{const{t:r}=E(),[d,x]=h.useState([]),[F,M]=h.useState(!0),[C,k]=h.useState(!1),[c,j]=h.useState(null),[s,i]=h.useState({username:"",email:"",password:"",role:"user"}),{user:u}=I();h.useEffect(()=>{U()},[]);const U=async()=>{try{M(!0);const a=await y.getUsers();a.success&&a.data&&x(a.data)}catch(a){console.error("Error loading users:",a),m.error(r("errors.generic"))}finally{M(!1)}},S=async a=>{a.preventDefault();try{const t=await y.createUser(s);t.success&&t.data&&(x([...d,t.data]),i({username:"",email:"",password:"",role:"user"}),k(!1),m.success(r("userManager.form.createSuccess")))}catch(t){console.error("Error creating user:",t);let n=r("userManager.form.createFailed");t instanceof Error&&"response"in t&&(n=t.response?.data?.message||r("userManager.form.createFailed")),m.error(n)}},D=async a=>{if(a.preventDefault(),!!c)try{const t={username:s.username,email:s.email,role:s.role};s.password&&s.password.trim()!==""&&(t.password=s.password);const n=await y.updateUser(c.id,t);n.success&&n.data&&(x(d.map(l=>l.id===c.id?n.data:l)),j(null),i({username:"",email:"",password:"",role:"user"}),m.success(r("userManager.form.updateSuccess")))}catch(t){console.error("Error updating user:",t);let n=r("userManager.form.updateFailed");t instanceof Error&&"response"in t&&(n=t.response?.data?.message||r("userManager.form.updateFailed")),m.error(n)}},q=async(a,t)=>{if(confirm(r("userManager.deleteConfirm",{name:t})))try{(await y.deleteUser(a)).success&&(x(d.filter(l=>l.id!==a)),m.success(r("userManager.deleteSuccess")))}catch(n){console.error("Error deleting user:",n);let l=r("userManager.deleteFailed");n instanceof Error&&"response"in n&&(l=n.response?.data?.message||r("userManager.deleteFailed")),m.error(l)}},$=a=>{j(a),i({username:a.username,email:a.email||"",password:"",role:a.role})},z=()=>{j(null),i({username:"",email:"",password:"",role:"user"})},B=()=>{i({username:"",email:"",password:"",role:"user"}),k(!1)};return F?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"w-8 h-8 border-4 border-gray-200 dark:border-gray-600 border-t-primary-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{}),e.jsxs(g,{onClick:()=>k(!C),className:"flex items-center space-x-2 bg-primary-600 hover:bg-primary-700 dark:bg-primary-500 dark:hover:bg-primary-600",children:[e.jsx(T,{size:16}),e.jsx("span",{children:r("userManager.createUser")})]})]}),C&&e.jsxs(b,{className:"bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg",children:[e.jsxs(f,{children:[e.jsx(v,{className:"text-gray-900 dark:text-gray-100",children:r("userManager.form.title.create")}),e.jsx(N,{className:"text-gray-600 dark:text-gray-400",children:r("userManager.subtitle")})]}),e.jsx(w,{children:e.jsxs("form",{onSubmit:S,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(o,{htmlFor:"username",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.username")}),e.jsx(p,{id:"username",value:s.username,onChange:a=>i({...s,username:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"email",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.email")}),e.jsx(p,{id:"email",type:"email",value:s.email,onChange:a=>i({...s,email:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(o,{htmlFor:"password",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.password")}),e.jsx(p,{id:"password",type:"password",value:s.password,onChange:a=>i({...s,password:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"role",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.role")}),e.jsxs("select",{id:"role",value:s.role,onChange:a=>i({...s,role:a.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 bg-white dark:bg-dark-100 text-gray-900 dark:text-gray-100 transition-colors duration-200",children:[e.jsx("option",{value:"user",children:r("userManager.roles.user")}),e.jsx("option",{value:"admin",children:r("userManager.roles.admin")})]})]})]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{type:"submit",children:r("userManager.form.createButton")}),e.jsx(g,{type:"button",variant:"outline",onClick:B,children:r("common.cancel")})]})]})})]}),c&&e.jsxs(b,{className:"bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg",children:[e.jsxs(f,{children:[e.jsxs(v,{className:"text-gray-900 dark:text-gray-100",children:[r("userManager.form.title.edit"),": ",c.username]}),e.jsx(N,{className:"text-gray-600 dark:text-gray-400",children:r("userManager.subtitle")})]}),e.jsx(w,{children:e.jsxs("form",{onSubmit:D,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(o,{htmlFor:"edit-username",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.username")}),e.jsx(p,{id:"edit-username",value:s.username,onChange:a=>i({...s,username:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"edit-email",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.email")}),e.jsx(p,{id:"edit-email",type:"email",value:s.email,onChange:a=>i({...s,email:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(o,{htmlFor:"edit-password",className:"text-gray-700 dark:text-gray-300",children:[r("userManager.form.password")," (",r("common.optional"),")"]}),e.jsx(p,{id:"edit-password",type:"password",value:s.password,onChange:a=>i({...s,password:a.target.value}),placeholder:r("userManager.form.passwordHint"),className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"edit-role",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.role")}),e.jsxs("select",{id:"edit-role",value:s.role,onChange:a=>i({...s,role:a.target.value}),disabled:c?.id===u?.id&&u?.role==="admin",className:"w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 bg-white dark:bg-dark-100 text-gray-900 dark:text-gray-100 transition-colors duration-200 disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("option",{value:"user",children:r("userManager.roles.user")}),e.jsx("option",{value:"admin",children:r("userManager.roles.admin")})]}),c?.id===u?.id&&u?.role==="admin"&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 mt-1",children:r("userManager.cannotDeleteSelf")})]})]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{type:"submit",children:r("userManager.form.updateButton")}),e.jsx(g,{type:"button",variant:"outline",onClick:z,children:r("common.cancel")})]})]})})]}),e.jsxs(b,{className:"bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg",children:[e.jsxs(f,{children:[e.jsxs(v,{className:"text-gray-900 dark:text-gray-100",children:[r("userManager.title")," (",d.length,")"]}),e.jsx(N,{className:"text-gray-600 dark:text-gray-400",children:r("userManager.subtitle")})]}),e.jsx(w,{children:e.jsx("div",{className:"space-y-3",children:d.map(a=>e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-300",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"p-2 bg-primary-100 dark:bg-primary-900/20 rounded-lg",children:a.role==="admin"?e.jsx(A,{className:"h-5 w-5 text-primary-600 dark:text-primary-400"}):e.jsx(L,{className:"h-5 w-5 text-primary-600 dark:text-primary-400"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-gray-900 dark:text-gray-100",children:[a.username,a.id===u?.id&&e.jsxs("span",{className:"ml-2 text-xs text-primary-600 dark:text-primary-400 font-normal",children:["(",r("chatMessage.you"),")"]})]}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:[a.email||r("userManager.noEmail")," •"," ",a.role==="admin"?r("userManager.roles.admin"):r("userManager.roles.user")]}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-500",children:[r("userManager.columns.created"),":"," ",new Date(a.createdAt).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{variant:"outline",size:"sm",onClick:()=>$(a),className:"text-gray-600 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400",children:e.jsx(P,{size:16})}),e.jsx(g,{variant:"outline",size:"sm",onClick:()=>q(a.id,a.username),disabled:a.id===u?.id,className:"text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-900/20",children:e.jsx(H,{size:16})})]})]},a.id))})})]})]})},W=()=>{const{t:r}=E();return e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("div",{className:"max-w-6xl mx-auto p-6",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-gray-100 mb-2",children:r("userManager.title")}),e.jsx("p",{className:"text-gray-700 dark:text-gray-300",children:r("userManager.pageDescription")})]}),e.jsx(R,{})]})})};export{W as UserManagementPage,W as default};
|
|
1
|
+
import{j as e}from"./markdown-vendor-B0lXrrRZ.js";import{r as h}from"./router-vendor-DdQhGl5t.js";import{F as m,t as T,y as A,q as L,aw as P,T as H}from"./ui-vendor-C4ZcWovR.js";import{a as E,b as I,l as y,B as g,I as p}from"../assets/index-DW8C1vVk.js";import"./utils-vendor-BFlGJDIj.js";const o=({children:r,htmlFor:d,className:x=""})=>e.jsx("label",{htmlFor:d,className:`text-sm font-medium text-gray-700 dark:text-gray-300 ${x}`,children:r}),b=({children:r,className:d=""})=>e.jsx("div",{className:`bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 rounded-xl shadow-card hover:shadow-card-hover transition-shadow duration-200 ${d}`,children:r}),f=({children:r,className:d=""})=>e.jsx("div",{className:`flex flex-col space-y-1.5 p-6 ${d}`,children:r}),v=({children:r,className:d=""})=>e.jsx("h3",{className:`text-lg font-semibold leading-none tracking-tight text-gray-900 dark:text-dark-950 ${d}`,children:r}),N=({children:r,className:d=""})=>e.jsx("p",{className:`text-sm text-gray-500 dark:text-dark-500 ${d}`,children:r}),w=({children:r,className:d=""})=>e.jsx("div",{className:`p-6 pt-0 ${d}`,children:r}),R=()=>{const{t:r}=E(),[d,x]=h.useState([]),[F,M]=h.useState(!0),[C,k]=h.useState(!1),[c,j]=h.useState(null),[s,i]=h.useState({username:"",email:"",password:"",role:"user"}),{user:u}=I();h.useEffect(()=>{U()},[]);const U=async()=>{try{M(!0);const a=await y.getUsers();a.success&&a.data&&x(a.data)}catch(a){console.error("Error loading users:",a),m.error(r("errors.generic"))}finally{M(!1)}},S=async a=>{a.preventDefault();try{const t=await y.createUser(s);t.success&&t.data&&(x([...d,t.data]),i({username:"",email:"",password:"",role:"user"}),k(!1),m.success(r("userManager.form.createSuccess")))}catch(t){console.error("Error creating user:",t);let n=r("userManager.form.createFailed");t instanceof Error&&"response"in t&&(n=t.response?.data?.message||r("userManager.form.createFailed")),m.error(n)}},D=async a=>{if(a.preventDefault(),!!c)try{const t={username:s.username,email:s.email,role:s.role};s.password&&s.password.trim()!==""&&(t.password=s.password);const n=await y.updateUser(c.id,t);n.success&&n.data&&(x(d.map(l=>l.id===c.id?n.data:l)),j(null),i({username:"",email:"",password:"",role:"user"}),m.success(r("userManager.form.updateSuccess")))}catch(t){console.error("Error updating user:",t);let n=r("userManager.form.updateFailed");t instanceof Error&&"response"in t&&(n=t.response?.data?.message||r("userManager.form.updateFailed")),m.error(n)}},q=async(a,t)=>{if(confirm(r("userManager.deleteConfirm",{name:t})))try{(await y.deleteUser(a)).success&&(x(d.filter(l=>l.id!==a)),m.success(r("userManager.deleteSuccess")))}catch(n){console.error("Error deleting user:",n);let l=r("userManager.deleteFailed");n instanceof Error&&"response"in n&&(l=n.response?.data?.message||r("userManager.deleteFailed")),m.error(l)}},$=a=>{j(a),i({username:a.username,email:a.email||"",password:"",role:a.role})},z=()=>{j(null),i({username:"",email:"",password:"",role:"user"})},B=()=>{i({username:"",email:"",password:"",role:"user"}),k(!1)};return F?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"w-8 h-8 border-4 border-gray-200 dark:border-gray-600 border-t-primary-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{}),e.jsxs(g,{onClick:()=>k(!C),className:"flex items-center space-x-2 bg-primary-600 hover:bg-primary-700 dark:bg-primary-500 dark:hover:bg-primary-600",children:[e.jsx(T,{size:16}),e.jsx("span",{children:r("userManager.createUser")})]})]}),C&&e.jsxs(b,{className:"bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg",children:[e.jsxs(f,{children:[e.jsx(v,{className:"text-gray-900 dark:text-gray-100",children:r("userManager.form.title.create")}),e.jsx(N,{className:"text-gray-600 dark:text-gray-400",children:r("userManager.subtitle")})]}),e.jsx(w,{children:e.jsxs("form",{onSubmit:S,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(o,{htmlFor:"username",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.username")}),e.jsx(p,{id:"username",value:s.username,onChange:a=>i({...s,username:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"email",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.email")}),e.jsx(p,{id:"email",type:"email",value:s.email,onChange:a=>i({...s,email:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(o,{htmlFor:"password",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.password")}),e.jsx(p,{id:"password",type:"password",value:s.password,onChange:a=>i({...s,password:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"role",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.role")}),e.jsxs("select",{id:"role",value:s.role,onChange:a=>i({...s,role:a.target.value}),className:"w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 bg-white dark:bg-dark-100 text-gray-900 dark:text-gray-100 transition-colors duration-200",children:[e.jsx("option",{value:"user",children:r("userManager.roles.user")}),e.jsx("option",{value:"admin",children:r("userManager.roles.admin")})]})]})]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{type:"submit",children:r("userManager.form.createButton")}),e.jsx(g,{type:"button",variant:"outline",onClick:B,children:r("common.cancel")})]})]})})]}),c&&e.jsxs(b,{className:"bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg",children:[e.jsxs(f,{children:[e.jsxs(v,{className:"text-gray-900 dark:text-gray-100",children:[r("userManager.form.title.edit"),": ",c.username]}),e.jsx(N,{className:"text-gray-600 dark:text-gray-400",children:r("userManager.subtitle")})]}),e.jsx(w,{children:e.jsxs("form",{onSubmit:D,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(o,{htmlFor:"edit-username",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.username")}),e.jsx(p,{id:"edit-username",value:s.username,onChange:a=>i({...s,username:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"edit-email",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.email")}),e.jsx(p,{id:"edit-email",type:"email",value:s.email,onChange:a=>i({...s,email:a.target.value}),required:!0,className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(o,{htmlFor:"edit-password",className:"text-gray-700 dark:text-gray-300",children:[r("userManager.form.password")," (",r("common.optional"),")"]}),e.jsx(p,{id:"edit-password",type:"password",value:s.password,onChange:a=>i({...s,password:a.target.value}),placeholder:r("userManager.form.passwordHint"),className:"bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100"})]}),e.jsxs("div",{children:[e.jsx(o,{htmlFor:"edit-role",className:"text-gray-700 dark:text-gray-300",children:r("userManager.form.role")}),e.jsxs("select",{id:"edit-role",value:s.role,onChange:a=>i({...s,role:a.target.value}),disabled:c?.id===u?.id&&u?.role==="admin",className:"w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 bg-white dark:bg-dark-100 text-gray-900 dark:text-gray-100 transition-colors duration-200 disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("option",{value:"user",children:r("userManager.roles.user")}),e.jsx("option",{value:"admin",children:r("userManager.roles.admin")})]}),c?.id===u?.id&&u?.role==="admin"&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 mt-1",children:r("userManager.cannotDeleteSelf")})]})]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{type:"submit",children:r("userManager.form.updateButton")}),e.jsx(g,{type:"button",variant:"outline",onClick:z,children:r("common.cancel")})]})]})})]}),e.jsxs(b,{className:"bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg",children:[e.jsxs(f,{children:[e.jsxs(v,{className:"text-gray-900 dark:text-gray-100",children:[r("userManager.title")," (",d.length,")"]}),e.jsx(N,{className:"text-gray-600 dark:text-gray-400",children:r("userManager.subtitle")})]}),e.jsx(w,{children:e.jsx("div",{className:"space-y-3",children:d.map(a=>e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-300",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"p-2 bg-primary-100 dark:bg-primary-900/20 rounded-lg",children:a.role==="admin"?e.jsx(A,{className:"h-5 w-5 text-primary-600 dark:text-primary-400"}):e.jsx(L,{className:"h-5 w-5 text-primary-600 dark:text-primary-400"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-gray-900 dark:text-gray-100",children:[a.username,a.id===u?.id&&e.jsxs("span",{className:"ml-2 text-xs text-primary-600 dark:text-primary-400 font-normal",children:["(",r("chatMessage.you"),")"]})]}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:[a.email||r("userManager.noEmail")," •"," ",a.role==="admin"?r("userManager.roles.admin"):r("userManager.roles.user")]}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-500",children:[r("userManager.columns.created"),":"," ",new Date(a.createdAt).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(g,{variant:"outline",size:"sm",onClick:()=>$(a),className:"text-gray-600 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400",children:e.jsx(P,{size:16})}),e.jsx(g,{variant:"outline",size:"sm",onClick:()=>q(a.id,a.username),disabled:a.id===u?.id,className:"text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-900/20",children:e.jsx(H,{size:16})})]})]},a.id))})})]})]})},W=()=>{const{t:r}=E();return e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("div",{className:"max-w-6xl mx-auto p-6",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 dark:text-gray-100 mb-2",children:r("userManager.title")}),e.jsx("p",{className:"text-gray-700 dark:text-gray-300",children:r("userManager.pageDescription")})]}),e.jsx(R,{})]})})};export{W as UserManagementPage,W as default};
|