libre-webui 0.19.2 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/backend/dist/index.d.ts.map +1 -1
  2. package/backend/dist/index.js +61 -2
  3. package/backend/dist/index.js.map +1 -1
  4. package/backend/dist/routes/artifacts.d.ts +3 -0
  5. package/backend/dist/routes/artifacts.d.ts.map +1 -0
  6. package/backend/dist/routes/artifacts.js +167 -0
  7. package/backend/dist/routes/artifacts.js.map +1 -0
  8. package/backend/package.json +1 -1
  9. package/frontend/dist/apple-touch-icon.png +0 -0
  10. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -0
  11. package/frontend/dist/artifact-runtime/babel.js +613 -0
  12. package/frontend/dist/artifact-runtime/chart.js +3 -0
  13. package/frontend/dist/artifact-runtime/d3.js +5 -0
  14. package/frontend/dist/artifact-runtime/fonts.js +255 -0
  15. package/frontend/dist/artifact-runtime/framer-motion.js +10 -0
  16. package/frontend/dist/artifact-runtime/lodash.js +20 -0
  17. package/frontend/dist/artifact-runtime/lucide-react.js +1 -0
  18. package/frontend/dist/artifact-runtime/mathjs.js +54 -0
  19. package/frontend/dist/artifact-runtime/mermaid.js +3535 -0
  20. package/frontend/dist/artifact-runtime/papaparse.js +10 -0
  21. package/frontend/dist/artifact-runtime/plotly.js +3790 -0
  22. package/frontend/dist/artifact-runtime/react.js +9 -0
  23. package/frontend/dist/artifact-runtime/recharts.js +69 -0
  24. package/frontend/dist/artifact-runtime/runtime.js +1 -0
  25. package/frontend/dist/artifact-runtime/tailwind.js +952 -0
  26. package/frontend/dist/artifact-runtime/three.js +5271 -0
  27. package/frontend/dist/artifact-runtime/tone.js +210 -0
  28. package/frontend/dist/assets/index-ZxtmHZ3Y.js +83 -0
  29. package/frontend/dist/assets/index-mBbb8flG.css +1 -0
  30. package/frontend/dist/favicon-dark.png +0 -0
  31. package/frontend/dist/favicon-light.png +0 -0
  32. package/frontend/dist/favicon.svg +1 -0
  33. package/frontend/dist/fonts/inter.css +254 -0
  34. package/frontend/dist/fonts/v20-UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa0ZL7W0Q5n-wU.woff2 +0 -0
  35. package/frontend/dist/fonts/v20-UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1ZL7W0Q5nw.woff2 +0 -0
  36. package/frontend/dist/fonts/v20-UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1pL7W0Q5n-wU.woff2 +0 -0
  37. package/frontend/dist/fonts/v20-UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa25L7W0Q5n-wU.woff2 +0 -0
  38. package/frontend/dist/fonts/v20-UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2JL7W0Q5n-wU.woff2 +0 -0
  39. package/frontend/dist/fonts/v20-UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2ZL7W0Q5n-wU.woff2 +0 -0
  40. package/frontend/dist/fonts/v20-UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2pL7W0Q5n-wU.woff2 +0 -0
  41. package/frontend/dist/icon-192.png +0 -0
  42. package/frontend/dist/icon-512.png +0 -0
  43. package/frontend/dist/index.html +15 -10
  44. package/frontend/dist/js/ArtifactContainer-DZV5ZT6g.js +1 -0
  45. package/frontend/dist/js/{ArtifactDemoPage-BlVBMy6a.js → ArtifactDemoPage-BX6d2sWa.js} +58 -2
  46. package/frontend/dist/js/ArtifactSandboxFrame-CSDSSxMI.js +151 -0
  47. package/frontend/dist/js/ArtifactSlideOutPanel-BYy4Yv_U.js +1 -0
  48. package/frontend/dist/js/ChatPage-Bk1fO2xt.js +16 -0
  49. package/frontend/dist/js/FirstTimeSetup-ByfcKmYo.js +1 -0
  50. package/frontend/dist/js/{GalleryPage-BnaFZERr.js → GalleryPage-DLLiZj6X.js} +1 -1
  51. package/frontend/dist/js/{HomePage-BvpoUzGG.js → HomePage-DHuuGx-r.js} +1 -1
  52. package/frontend/dist/js/{LibreClawPage-B-6rO5Jl.js → LibreClawPage-BfCXrQ-e.js} +1 -1
  53. package/frontend/dist/js/{ModelSelector-BV1kuaVg.js → ModelSelector-BET34RYg.js} +1 -1
  54. package/frontend/dist/js/{ModelsPage-D5H70fs3.js → ModelsPage-BxLpqELH.js} +1 -1
  55. package/frontend/dist/js/{NotesPage-D9b3JxCx.js → NotesPage-BC62unJU.js} +1 -1
  56. package/frontend/dist/js/{PersonasPage-CJOGnyQV.js → PersonasPage-BsOyNy8l.js} +2 -2
  57. package/frontend/dist/js/{PluginUsagePage-DHNMWquK.js → PluginUsagePage-CLpKYGwg.js} +1 -1
  58. package/frontend/dist/js/{RichMessageContent-C7NG7gs-.js → RichMessageContent-BTcjK7f1.js} +1 -1
  59. package/frontend/dist/js/SettingsModal-ao0lVJHy.js +1 -0
  60. package/frontend/dist/js/{SystemPage-BsPen2Qb.js → SystemPage-ZMCqqgBt.js} +1 -1
  61. package/frontend/dist/js/{UserManagementPage-I9i5r0V3.js → UserManagementPage-6PsAs-Uy.js} +1 -1
  62. package/frontend/dist/js/WorkPage-t7NVWt81.js +5 -0
  63. package/frontend/dist/js/api-F_fsjYA7.js +19 -0
  64. package/frontend/dist/js/{appStore-CLIS0fvz.js → appStore-ne0eCPTX.js} +2 -2
  65. package/frontend/dist/js/{authStore-CsCkBmaG.js → authStore-DqsiGpyN.js} +1 -1
  66. package/frontend/dist/js/{chatStore-DRY8C0J1.js → chatStore-DRg2vRDS.js} +2 -2
  67. package/frontend/dist/js/config-DZsEwEPX.js +1 -0
  68. package/frontend/dist/js/{estree-CrfVSazx.js → estree-CWs-Kavs.js} +1 -1
  69. package/frontend/dist/js/{html-BbJLJMaV.js → html-DrDcdqPC.js} +1 -1
  70. package/frontend/dist/js/{markdown-DiMg1QLf.js → markdown-CbB02VPB.js} +1 -1
  71. package/frontend/dist/js/{messageCodeStyles-CfzjQF-R.js → messageCodeStyles-D1gR4Bnk.js} +1 -1
  72. package/frontend/dist/js/{standalone-Vs6LnjM6.js → standalone-BIvqjowG.js} +1 -1
  73. package/frontend/dist/js/{typescript-BhVG1zGU.js → typescript-kUuRGkxH.js} +1 -1
  74. package/frontend/dist/js/{ui-Dj9IFugT.js → ui-D4PVoJDa.js} +2 -2
  75. package/frontend/dist/logo-dark.png +0 -0
  76. package/frontend/dist/logo-dark.svg +1 -0
  77. package/frontend/dist/logo-light.png +0 -0
  78. package/frontend/dist/logo-light.svg +1 -0
  79. package/frontend/dist/logo.svg +1 -6
  80. package/frontend/dist/maskable-512.png +0 -0
  81. package/package.json +2 -2
  82. package/frontend/dist/assets/index-B9H3vQ-n.css +0 -1
  83. package/frontend/dist/assets/index-D4LhtFTX.js +0 -38
  84. package/frontend/dist/js/ArtifactContainer-DvuGeXXu.js +0 -1
  85. package/frontend/dist/js/ArtifactSlideOutPanel-CaPMk1Qj.js +0 -1
  86. package/frontend/dist/js/ChatPage-D4UBhGLk.js +0 -16
  87. package/frontend/dist/js/FirstTimeSetup-DJiDNTXY.js +0 -1
  88. package/frontend/dist/js/SettingsModal-DEBxDPne.js +0 -1
  89. package/frontend/dist/js/WorkPage-e30yqvJe.js +0 -5
  90. package/frontend/dist/js/api-jwjnjqx6.js +0 -19
  91. package/frontend/dist/js/artifactHtml-C0Hu9I1u.js +0 -41
@@ -1,16 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{n as r}from"./react-vendor-DPNXrO-8.js";import{d as i,f as a,u as o}from"./router-vendor-Ca9zqOqT.js";import{t as s}from"./useTranslation-CdeLZqSW.js";import{i as c}from"./i18n-ZJQSoIuM.js";import{$ as l,A as u,B as d,Ct as f,D as p,F as m,G as h,Gt as g,Jt as _,Mt as v,N as y,P as b,Pt as x,R as S,T as C,Tn as w,U as T,Ut as E,a as D,an as O,bt as k,d as A,dn as ee,et as j,fn as M,ft as N,g as P,gn as F,h as te,j as ne,n as I,nn as L,o as R,on as re,pt as ie,qt as ae,r as oe,rn as z,st as se,t as ce,tt as le,v as ue,wn as B,wt as V,x as de,yn as fe}from"./ui-vendor-D_pYT79f.js";import{i as H,t as U}from"./logger-DSXjF4ye.js";import{a as W,d as pe,f as G,g as me,i as he,n as ge,u as _e,x as K,y as ve}from"./api-jwjnjqx6.js";import{a as ye,n as q,r as be,t as J}from"./utils-BhpNrGnR.js";import{a as xe,c as Se,i as Ce,l as we,n as Te,r as Ee,t as Y}from"./chatStore-DRY8C0J1.js";import{n as De,r as X}from"./authStore-CsCkBmaG.js";import{t as Oe}from"./appStore-CLIS0fvz.js";import{i as ke,r as Ae,t as je}from"./welcomePrompts-to5mv_gx.js";import{l as Me}from"./messageCodeStyles-CfzjQF-R.js";import{t as Z}from"./Button-X9TT9gTD.js";import{d as Ne,f as Pe,l as Fe}from"./ui-Dj9IFugT.js";import{a as Ie,o as Le}from"./artifactHtml-C0Hu9I1u.js";import{t as Re}from"./ArtifactContainer-DvuGeXXu.js";import{t as ze}from"./ModelSelector-BV1kuaVg.js";var Be=r(),Q=e(n(),1),$=t(),Ve=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(N,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,$.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,$.jsx)(O,{size:12}):(0,$.jsx)(z,{size:12,className:`rtl:rotate-180`}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},He=U(`components:ttsbutton`),Ue=null,We=null,Ge=0,Ke=3e5;async function qe(e=!1){let t=Date.now();return!e&&Ue!==null&&t-Ge<Ke?Ue:We||(We=(async()=>{try{let e=await W.getModels();return e.success&&e.data&&e.data.length>0?(Ue=e.data,Ge=t,e.data):(Ue=[],Ge=t,[])}catch{return Ue=[],Ge=t,[]}finally{We=null}})(),We)}function Je(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Ye=({text:e,className:t,size:n=`sm`})=>{let{t:r}=s(),{preferences:i}=Oe(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(!1),v=(0,Q.useRef)([]),y=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await qe(),n=ge(t,i.ttsSettings?.model,i.ttsSettings?.pluginId);i.ttsSettings?.model&&!n&&(t=await qe(!0)),e&&(p(t),h(t.length>0))})(),()=>{e=!1}},[i.ttsSettings?.model,i.ttsSettings?.pluginId]);let b=(0,Q.useCallback)(async(e,t,n,i,a,o)=>{let s=await W.generateBase64({model:t,pluginId:n,input:e,voice:i,speed:a,response_format:o});if(!s.success||!s.data?.audio)throw Error(s.message||r(`ttsButton.generateFailed`));let c=`data:${s.data.mimeType};base64,${s.data.audio}`,l=new Audio(c);return g.current=l,new Promise((e,t)=>{l.onended=()=>{g.current=null,e()},l.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},l.play().catch(t)})},[r]),x=(0,Q.useCallback)(async(e,t,n,r,i,a)=>{v.current=e,y.current=0,_.current=!1;let o=null,s=async e=>{try{let o=await W.generateBase64({model:t,pluginId:n,input:e,voice:r,speed:i,response_format:a});return!o.success||!o.data?.audio?null:{audioUrl:`data:${o.data.mimeType};base64,${o.data.audio}`,mimeType:o.data.mimeType}}catch{return null}};e.length>0&&(o=s(e[0]));for(let t=0;t<e.length&&!_.current;t++){y.current=t;try{let n=await o;if(_.current)break;if(o=t+1<e.length?s(e[t+1]):null,!n){He.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);g.current=r,await new Promise((e,t)=>{r.onended=()=>{g.current=null,e()},r.onerror=()=>{g.current=null,e()},r.play().catch(()=>{e()})})}catch(e){He.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Q.useCallback)(()=>{_.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),o(!1),l(!1)},[]),C=async()=>{if(!c){if(a){S();return}l(!0),d(null),_.current=!1;try{let t=i.ttsSettings,n=he(f,t?.model,t?.pluginId),a=n?.model||t?.model||`tts-1`,s=n?.plugin||t?.pluginId,c=n?.model===t?.model&&(!t?.pluginId||n?.plugin===t.pluginId)?t?.voice||n?.config?.default_voice||`alloy`:n?.config?.default_voice||`alloy`,u=t?.speed||1,p=n?.config?.default_format;if(t?.streamSentences){let t=Je(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));l(!1),o(!0),await x(t,a,s,c,u,p),_.current||o(!1)}else await b(e,a,s,c,u,p),l(!1),o(!0),g.current&&(g.current.onended=()=>{o(!1),g.current=null},g.current.onerror=()=>{d(r(`ttsButton.playbackFailed`)),o(!1),g.current=null})}catch(e){let t=e instanceof Error?e.message:r(`ttsButton.generateFailed`);d(t),He.error(`TTS error:`,e),o(!1),l(!1)}}};if((0,Q.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},T={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,$.jsx)(`button`,{onClick:C,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:J(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,u?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,w[n],t),children:c?(0,$.jsx)(se,{className:J(T[n],`animate-spin`)}):a?(0,$.jsx)(de,{className:T[n]}):u?(0,$.jsx)(D,{className:T[n]}):(0,$.jsx)(R,{className:T[n]})})},Xe=new Map;function Ze(e,t,n=``){let r=Xe.get(e);if(n){if((!r||r.state===`none`)&&(Xe.set(e,{state:`open`,startedAt:Date.now()}),!t))return;let n=Xe.get(e);t&&n?.state===`open`&&Xe.set(e,{state:`done`,durationMs:Date.now()-n.startedAt});return}if(r&&r.state!==`open`||!t)return;let i=ye(t);if(!r){i.thinkingComplete?Xe.set(e,{state:`none`}):Xe.set(e,{state:`open`,startedAt:Date.now()});return}i.thinkingComplete&&Xe.set(e,{state:`done`,durationMs:Date.now()-r.startedAt})}function Qe(e){let t=Xe.get(e);if(t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function $e(e){let t=Xe.get(e);if(Xe.delete(e),t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function et(e){let t=e/1e3;if(t<.95)return`${Math.max(.1,Math.round(t*10)/10)}s`;if(t<60)return`${Math.round(t)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return r>0?`${n}m ${r}s`:`${n}m`}var tt=/```([^\n`]*)\n([\s\S]*?)\n```/g,nt=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,rt=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],it=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:ft(e[1]),title:at(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=ft(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function at(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return st(ot(e))}function ot(e){return e.replace(/&(lt|gt|quot|apos|#39);/gi,(e,t)=>{switch(t.toLowerCase()){case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:case`#39`:return`'`;default:return``}}).replace(/&amp;/gi,`&`)}function st(e){let t=``,n=!1,r=null;for(let i=0;i<e.length;i+=1){let a=e[i];if(n){if(r){a===r&&(r=null);continue}if(a===`"`||a===`'`){r=a;continue}a===`>`&&(n=!1);continue}if(a===`<`){let t=e[i+1];if(t&&/[!/A-Za-z?]/.test(t)){n=!0;continue}}t+=a}return t}function ct(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return at(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&at(n[1]).trim()||null}function lt(e){let t=e.match(/(?:function|const)\s+(\w+)/);if(t)return t[1];let n=e.match(/class\s+(\w+)/);return n?n[1]:null}function ut(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function dt(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function ft(e){let t=e.trim().toLowerCase();return rt.includes(t)?t:`text`}function pt(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function mt(e){let t=[],n=new RegExp(tt),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=ht(n,_t(e,r.index));t.push({raw:r[0],info:n,content:r[2].trim(),start:r.index,end:r.index+r[0].length,language:i.language,fileName:i.fileName})}return t}function ht(e,t){let n=gt(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!nt.test(r)&&!r.includes(`=`)?pt(r):void 0)||pt(yt(n)),fileName:n}}function gt(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&nt.test(t[1]))return vt(t[1]);let n=e.match(nt);return n?vt(n[0]):void 0}function _t(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
2
- `).slice(-3).reverse();for(let e of n){let t=e.trim().replace(/^#{1,6}\s*/,``).replace(/^[-*]\s*/,``).replace(/[::]\s*$/,``).match(nt);if(t)return vt(t[0])}}function vt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function yt(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function bt(e){return e?.split(/[\\/]/).pop()}function xt(e){let t=bt(e);if(!t)return null;let n=t.replace(/\.[^.]+$/,``);return/^(index|main|app)$/i.test(n)?null:n.replace(/[-_]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function St(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function Ct(e){let t=pt(e.language)||pt(yt(e.fileName));switch(t){case`html`:return{type:`html`,title:ct(e.content)||xt(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:xt(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:lt(e.content)||xt(e.fileName)||`React Component`,language:`jsx`};case`json`:return{type:`json`,title:xt(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:ut(e.content)||xt(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:xt(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:dt(e.content)||xt(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:xt(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:xt(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function wt(e){return(pt(e.language)||pt(yt(e.fileName)))===`html`}function Tt(e){return(pt(e.language)||pt(yt(e.fileName)))===`css`}function Et(e){return(pt(e.language)||pt(yt(e.fileName)))===`javascript`}function Dt(e){let t=mt(e),n=t.filter(wt);if(n.length===0)return null;let r=t.filter(Tt),i=t.filter(Et);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=Ot(a.content,r,i),s=Le(o,r.map(e=>e.content),i.map(e=>e.content));return Nt(s,`html`)?{artifact:St({type:`html`,title:ct(s)||xt(a.fileName)||`Interactive HTML App`,description:`Bundled generated HTML, CSS, and JavaScript files into one runnable artifact.`,content:s}),ranges:[a,...r,...i]}:null}function Ot(e,t,n){let r=e;for(let e of t){let t=bt(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${Mt(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=bt(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${Mt(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function kt(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=mt(e);if(At(t.index,n))return null;let r=t.index,i=/<\/html>/gi;i.lastIndex=r;let a=i.exec(e),o=a?a.index+a[0].length:e.length,s=e.slice(r,o).trim();return Nt(s,`html`)?{artifact:St({type:`html`,title:ct(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function At(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function jt(e,t){return[...t].sort((e,t)=>t.start-e.start).reduce((e,t)=>`${e.slice(0,t.start)}${e.slice(t.end)}`,e)}function Mt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Nt(e,t){if(t===`html`){let t=e.trim(),n=/<[^>]+>/.test(t),r=/<(canvas|script|style|button|form|input|select|textarea|video|audio)\b/i.test(t)||/\bon(?:click|input|submit|keydown|keyup|mousemove)=/i.test(t);return n&&(Ie(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Z][^>]*>/.test(e)||/return\s*\(/.test(e);if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
3
- `).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return e.trim().length>200}function Pt(e){let t=[],n=e;for(let e of it){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);Nt(n.content,n.type)&&(t.push(St({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=jt(n,r)}let r=Dt(n);for(;r;)t.push(r.artifact),n=jt(n,r.ranges),r=Dt(n);let i=kt(n);i&&(t.push(i.artifact),n=jt(n,i.ranges));let a=mt(n),o=[];for(let e of a){let n=Ct(e);!n||!Nt(e.content,n.type)||(t.push(St({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=jt(n,o),{content:n.trim(),artifacts:t}}var Ft=U(`components:chat-message`),It=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onEditResend:a})=>{let{t:o,i18n:c}=s(),l=e.role===`user`,d=e.role===`system`,{preferences:f}=Oe(),{user:p}=De(),{setSystemMessage:h,getCurrentPersona:_,currentSession:v,rateMessage:y}=Y(),b=_(),[x,C]=(0,Q.useState)(!1),[w,E]=(0,Q.useState)(e.content),[D,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(!1),[F,ne]=(0,Q.useState)(!1),[R,ie]=(0,Q.useState)(!1),[ae,oe]=(0,Q.useState)(!1),z=(0,Q.useRef)(null),se=(0,Q.useRef)(t),ce=(0,Q.useRef)(!1),le=async()=>{try{await navigator.clipboard.writeText(e.content),Me(`success`),oe(!0),setTimeout(()=>oe(!1),2e3)}catch(e){Ft.error(`Failed to copy message:`,e)}},{thinkingContent:ue,thinkingStreaming:B,parsedContent:V,artifacts:de}=(0,Q.useMemo)(()=>{if(l||d||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:ye(e.content),r=n.content,i=t&&!n.thinkingComplete;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:e.artifacts};if(!t){let e=Pt(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,l,d,t]),fe=B?void 0:e.statistics?.thinking_duration_ms??Qe(e.id);(0,Q.useEffect)(()=>{let e=se.current&&!t;return se.current=t,e&&!ce.current&&!l&&!d&&V&&f.ttsSettings?.enabled&&f.ttsSettings?.autoPlay&&(ce.current=!0,(async()=>{ie(!0);try{let e=await W.getModels(),t=e.success&&e.data?e.data:[],n=f.ttsSettings,r=he(t,n?.model,n?.pluginId),i=ge(t,n?.model,n?.pluginId),a=await W.generateBase64({model:r?.model||n?.model||`tts-1`,pluginId:r?.plugin||n?.pluginId,input:V,voice:i?n?.voice||r?.config?.default_voice||`alloy`:r?.config?.default_voice||`alloy`,speed:n?.speed||1,response_format:r?.config?.default_format});if(a.success&&a.data?.audio){let e=`data:${a.data.mimeType};base64,${a.data.audio}`,t=new Audio(e);z.current=t,t.onended=()=>{ie(!1),z.current=null},t.onerror=()=>{ie(!1),z.current=null},await t.play()}}catch(e){Ft.error(`Auto-play TTS failed:`,e),ie(!1)}})()),()=>{z.current&&(z.current.pause(),z.current=null)}},[t,l,d,V,f.ttsSettings]);let H=()=>d?o(`chatMessage.system`):l?f.showUsername&&p?.username?p.username:o(`chatMessage.you`):b?.name?b.name:e.model||o(`chatMessage.assistant`),U=()=>{C(!0),E(e.content)},pe=async()=>{j(!0);try{h(w),C(!1),Ft.debug(`✅ System message updated:`,w)}catch(e){Ft.error(`Failed to save system message:`,e)}finally{j(!1)}},G=()=>{C(!1),E(e.content)},me=()=>{let t=w.trim();C(!1),!(!t||t===e.content)&&a?.(e.id,t)},_e=t=>{v&&y(v.id,e.id,e.rating===t?void 0:t)},K=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ve=d&&e.content.length>100;return(0,$.jsxs)(`div`,{className:J(`group flex py-1.5 transition-colors sm:py-2`,l?`justify-end`:`justify-start`,n),children:[(0,$.jsx)(`div`,{className:J(`flex min-w-0`,l?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:(0,$.jsxs)(`div`,{className:J(`min-w-0 flex-1`,l?`flex flex-col items-end`:d?`py-1.5`:`py-0.5`),children:[!l&&!d&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:H()}),e.model&&b?.name&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,$.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:q(e.timestamp,c.language)})]}),(0,$.jsxs)(`div`,{className:J(!l&&!d&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/[0.06] bg-gray-100 dark:border-white/[0.08] dark:bg-gray-800`,children:(0,$.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>k(e)})},t))}),l?x?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/[0.08] bg-white p-2 shadow-sm dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),me()):e.key===`Escape`&&G()},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-none dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(`button`,{onClick:G,className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 transition-colors hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:o(`chatMessage.cancelEditing`)}),(0,$.jsx)(`button`,{onClick:me,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white transition-colors hover:bg-gray-700 dark:bg-dark-300 dark:hover:bg-dark-400`,children:o(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{className:`rounded-2xl rounded-ee-md border border-black/[0.06] bg-gray-900 px-3.5 py-2 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):d?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(u,{className:`h-2.5 w-2.5 opacity-50`}),o(`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:pe,disabled:A,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.saveChanges`),children:(0,$.jsx)(m,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:G,disabled:A,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.cancelEditing`),children:(0,$.jsx)(I,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:U,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:o(`chatMessage.editSystemMessage`),children:(0,$.jsx)(T,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),x?(0,$.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>E(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:o(`chatMessage.systemMessagePlaceholder`),disabled:A}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:M?e.content:K(e.content)}),ve&&(0,$.jsx)(`button`,{onClick:()=>N(!M),className:`mt-2 flex items-center gap-1 text-xs text-gray-400 transition-colors hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`,children:M?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(L,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(ue||B)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{onClick:()=>ne(!F),className:`flex items-center gap-1.5 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,$.jsx)(ee,{className:J(`h-3.5 w-3.5`,B&&`animate-pulse-subtle motion-reduce:animate-none`)}),B?(0,$.jsxs)(`span`,{className:`animate-shimmer bg-gradient-to-r from-gray-400 via-gray-900 to-gray-400 bg-[length:200%_100%] bg-clip-text font-medium text-transparent motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-gray-500 dark:from-dark-500 dark:via-dark-900 dark:to-dark-500 motion-reduce:dark:text-dark-600`,children:[o(`chatMessage.thinking`),`…`]}):(0,$.jsx)(`span`,{className:`font-medium`,children:fe===void 0?o(`chatMessage.thinking`):o(`chatMessage.thoughtFor`,{duration:et(fe)})}),F?(0,$.jsx)(L,{className:`h-3.5 w-3.5`}):(0,$.jsx)(O,{className:`h-3.5 w-3.5`})]}),F&&ue&&(0,$.jsx)(`div`,{className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 dark:bg-dark-200/60`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[13px] leading-relaxed text-gray-600 dark:text-dark-700`,children:ue})})]}),(0,$.jsx)(Fe,{content:V,isStreaming:t})]}),!l&&!d&&de.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Re,{artifacts:de})}),!l&&!d&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(Ve,{statistics:e.statistics})}),!d&&!t&&(0,$.jsxs)(`div`,{className:J(`flex items-center gap-0.5 text-gray-400 dark:text-dark-500`,`sm:opacity-0 sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,l?`mt-1 justify-end`:`mt-1`),children:[l&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:q(e.timestamp,c.language),children:[H(),` ·`,` `,q(e.timestamp,c.language)]}),!l&&V&&(0,$.jsx)(Ye,{text:V,size:`sm`,className:J(`transition-colors`,R&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),l&&a&&!x&&(0,$.jsx)(`button`,{onClick:()=>{E(e.content),C(!0)},className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.edit`),children:(0,$.jsx)(T,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:le,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(ae?`chatMessage.copied`:`chatMessage.copyMessage`),children:ae?(0,$.jsx)(re,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(g,{className:`h-3.5 w-3.5`})}),!l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>_e(1),className:J(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===1&&`text-primary-600 dark:text-primary-400`),title:o(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(te,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>_e(-1),className:J(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===-1&&`text-red-500 dark:text-red-400`),title:o(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(P,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})})]}),!l&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.regenerateResponse`),children:(0,$.jsx)(S,{className:`h-3.5 w-3.5`})})]})]})]})}),D&&(0,Be.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":o(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>k(null),children:[(0,$.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),k(null)},children:(0,$.jsx)(I,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:D,alt:o(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Lt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Rt=220,zt=e=>{let t=e.slice(0,880).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>Rt?`${t.slice(0,219).trimEnd()}…`:t},Bt=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;!r||!i||(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Q.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:Lt()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===h,u=Math.abs(a-m),d=c===t.id?v:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:J(`group flex h-4 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:J(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,$.jsx)(`div`,{id:v,role:`tooltip`,className:J(`pointer-events-none absolute start-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:zt(_.prompt)}),_.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:zt(_.response)})]})})]})}),Vt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(It,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,$.jsxs)(`div`,{className:J(`relative py-2`,c),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(f,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let l=e.isActive!==!1,u=t&&i===e.id,d=u?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:J(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||u?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!u&&`cursor-pointer`),role:!l&&!u?`button`:void 0,tabIndex:!l&&!u?0:void 0,onClick:()=>!l&&!u&&s?.(e.id),onKeyDown:t=>{!l&&!u&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,$.jsxs)(`div`,{className:J(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||u?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,$.jsx)(re,{className:`h-3 w-3`}),!l&&!u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,$.jsx)(`div`,{className:J(!l&&!u&&`opacity-75`),children:(0,$.jsx)(It,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Ht={web_search:b,web_fetch:k,exec:ue,browser:k,Read:x,Write:x,Edit:x,image:ie,memory_search:E,memory_get:E,working:oe,thinking:oe,default:oe},Ut={web_search:`Searching the web`,web_fetch:`Fetching page`,exec:`Running command`,browser:`Using browser`,Read:`Reading file`,Write:`Writing file`,Edit:`Editing file`,image:`Analyzing image`,memory_search:`Searching memory`,memory_get:`Reading memory`,cron:`Managing schedule`,message:`Sending message`,tts:`Generating speech`,nodes:`Checking devices`,sessions_spawn:`Spawning agent`,canvas:`Rendering canvas`,process:`Managing process`,working:`Using tools`,thinking:`Thinking`},Wt=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,$.jsx)(`div`,{className:J(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Ht[e.name]||Ht.default,n=Ut[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:J(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(`div`,{className:J(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};U(`components:chat-messages`);var Gt=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],Kt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,qt=e=>Math.min(120,e*.28),Jt=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],className:o,onRegenerate:c,onSelectBranch:l,onEditResend:u,followUpSuggestions:d,onFollowUpSelect:f})=>{let{t:p}=s(),m=(0,Q.useRef)(null),h=(0,Q.useRef)(void 0),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(new Map),y=(0,Q.useRef)(null),b=(0,Q.useRef)(0),x=(0,Q.useRef)(!1),S=(0,Q.useRef)(!1),[w,T]=(0,Q.useState)(!1),E=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),D=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<E.length;t++){let n=E[t],r=Gt(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<E.length;e++){let t=Gt(E[e]);if(t.role===`user`)break;if(t.role===`assistant`){i=t.content;break}}e.push({id:n.id,prompt:r.content,response:i})}return e},[E]),O=D.map(e=>e.id).join(``),k=(0,Q.useMemo)(()=>O?O.split(``):[],[O]),A=(0,Q.useMemo)(()=>new Set(k),[k]),[ee,j]=(0,Q.useState)(null),M=(0,Q.useCallback)(()=>{let e=g.current;if(!e||k.length===0){j(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(b.current,k.length-1);if(t<=2)n=k.length-1;else{let t=e.scrollTop+qt(e.clientHeight);for(;n<k.length-1;){let e=v.current.get(k[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=v.current.get(k[n]);if(!e||e.offsetTop<=t)break;n--}}b.current=n;let r=k[n];j(e=>e===r?e:r)},[k]),N=(0,Q.useCallback)(()=>{y.current===null&&(y.current=window.requestAnimationFrame(()=>{y.current=null,M()}))},[M]),P=(0,Q.useCallback)(()=>{let t=g.current;if(h.current&&clearTimeout(h.current),x.current=!1,h.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;S.current=!n,T(!n&&e.length>0),N()},[e.length,N]),F=(0,Q.useCallback)(()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(P,180)},[P]),te=(0,Q.useCallback)((e=!1)=>{S.current&&!e||m.current?.scrollIntoView({behavior:Kt()})},[]),ne=(0,Q.useCallback)(()=>{let t=g.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(x.current){S.current=!0,T(!o&&e.length>0),N(),F();return}S.current=!o,T(!o&&e.length>0),a<=2&&k.length>0?(b.current=k.length-1,j(k[k.length-1])):N()},[k,e.length,F,N]),I=(0,Q.useCallback)(e=>{let t=g.current,n=v.current.get(e);if(!t||!n)return;let r=Kt();x.current=!0,S.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-qt(t.clientHeight)),behavior:r}),N(),r===`auto`?P():F()},[P,F,N]),L=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>L.current&&!S.current&&te(),L.current=e.length},[e.length,te]),(0,Q.useEffect)(()=>{i&&(t||n)&&!S.current&&requestAnimationFrame(()=>{let e=g.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{N();let e=_.current,t=g.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(N);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,N),()=>{n?.disconnect(),window.removeEventListener(`resize`,N)}},[O,N]),(0,Q.useEffect)(()=>()=>{y.current!==null&&(window.cancelAnimationFrame(y.current),y.current=null)},[]),(0,Q.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:J(`flex-1 flex items-center justify-center p-6 sm:p-10`,o),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-surface/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(C,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:p(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:p(`chatMessage.startConversationDescription`)})]})});let R=-1;for(let e=E.length-1;e>=0;e--)if(E[e].messages.some(e=>e.role===`assistant`)){R=e;break}return(0,$.jsxs)(`div`,{className:J(`relative min-h-0 flex-1`,o),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:g,"data-testid":`chat-scroll-viewport`,onScroll:ne,className:J(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,$.jsxs)(`div`,{ref:_,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[E.map((e,a)=>{let o=a===R,s=A.has(e.id),d=i&&e.messages.some(e=>e.id===r),f;if(e.messages.length===1){let s=e.messages[0],l=i&&s.id===r,d=l?{...s,content:t??s.content,thinking:n||s.thinking}:s;f=(0,$.jsx)(It,{message:d,isStreaming:l,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onEditResend:i?void 0:u,className:a===0?`mt-3 sm:mt-4`:``})}else f=(0,$.jsx)(Vt,{messages:e.messages,isStreaming:d,streamingMessage:t,streamingThinking:n,streamingMessageId:r||void 0,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onSelectBranch:l,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{ref:t=>{s&&(t?v.current.set(e.id,t):v.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:f},e.id)}),i&&a.length>0&&(0,$.jsx)(Wt,{tools:a,className:`px-0`}),!i&&d&&d.length>0&&f&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:p(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:d.map(e=>(0,$.jsx)(`button`,{onClick:()=>f(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-gray-600 transition-colors hover:text-gray-900 dark:border-dark-200 dark:text-dark-600 dark:hover:text-dark-900`,children:e},e))})]}),(0,$.jsx)(`div`,{ref:m,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(Bt,{items:D,activeId:ee,onSelect:I}),w&&(0,$.jsxs)(`button`,{onClick:()=>{x.current=!1,h.current&&(clearTimeout(h.current),h.current=void 0),S.current=!1,m.current?.scrollIntoView({behavior:Kt()}),T(!1)},className:J(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/[0.08]`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:p(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(fe,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:p(`chatMessage.newMessages`)})]})]})};function Yt(e){let t=(e.match(/```/g)||[]).length,n=t%2==1,r=null;if(n){let t=e.lastIndexOf("```");if(t!==-1){let n=e.slice(t+3).match(/^(\w+)/);n&&(r=n[1])}}return{hasCodeBlocks:t>0,isInCodeBlock:n,language:r}}var Xt=Q.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Q.useMemo)(()=>Yt(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:J(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:J(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,$.jsx)(_,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});Xt.displayName=`CodeAwareTextarea`;var Zt=U(`components:media-upload`),Qt=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)([]),g=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):w.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){w.error(`Maximum ${n} images allowed`);return}if(r.size>10485760){w.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},y=async e=>{if(e.size>10485760){w.error(`File size must be less than 10MB`);return}p(!0);try{let t=await ve.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),w.success(`Document "${e.name}" uploaded`)}else w.error(t.error||`Failed to upload document`)}catch(e){Zt.error(`Document upload error:`,e),w.error(`Failed to upload document`)}finally{p(!1)}},b=e=>{e.preventDefault(),a||d(!0)},S=e=>{e.preventDefault(),d(!1)},C=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},T=n=>{t(e.filter((e,t)=>t!==n))},E=async e=>{try{let t=await ve.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),w.success(`Document removed`)):w.error(t.error||`Failed to remove document`)}catch(e){Zt.error(`Error removing document:`,e),w.error(`Failed to remove document`)}},D=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},O=e.length>0||m.length>0;return(0,$.jsxs)(`div`,{className:J(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:J(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:b,onDragLeave:S,onDrop:C,onClick:()=>!a&&l.current?.click(),children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(se,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,$.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),O&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),T(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(I,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(x,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,$.jsx)(v,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:D(e.size)})]}),(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),E(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(I,{className:`h-3 w-3`})})]},e.id))]})]})},$t=U(`components:document-indicator`),en=({sessionId:e,className:t=``})=>{let[n,r]=(0,Q.useState)([]);if((0,Q.useEffect)(()=>{if(!e)return;let t=async()=>{try{let t=await ve.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){$t.error(`Failed to load documents:`,e)}};t();let n=()=>void t();return window.addEventListener(`libre:documents-updated`,n),()=>window.removeEventListener(`libre:documents-updated`,n)},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{className:`
4
- inline-flex items-center space-x-1 px-2 py-1
5
- bg-blue-50 dark:bg-blue-900/20
6
- border border-blue-200 dark:border-blue-800
7
- rounded-md text-xs
8
- ${t}
9
- `,title:`${n.length} document(s) available for context - Total: ${(e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]})(i)}`,children:[(0,$.jsx)(F,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,$.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},tn=U(`components:structured-output`),nn=[{key:`none`,value:null},{key:`json`,value:`json`},{key:`list`,value:{type:`object`,properties:{items:{type:`array`,items:{type:`string`}}},required:[`items`]}},{key:`summary`,value:{type:`object`,properties:{title:{type:`string`},summary:{type:`string`},key_points:{type:`array`,items:{type:`string`}}},required:[`title`,`summary`,`key_points`]}},{key:`analysis`,value:{type:`object`,properties:{analysis:{type:`string`},pros:{type:`array`,items:{type:`string`}},cons:{type:`array`,items:{type:`string`}},recommendation:{type:`string`}},required:[`analysis`,`pros`,`cons`,`recommendation`]}},{key:`custom`,value:`custom`}],rn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),[o,c]=(0,Q.useState)(``),l=()=>nn.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),d=()=>{let t=l();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},f=e=>{let n=l().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,$.jsxs)(`div`,{className:J(`space-y-3`,n),children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center`,children:[(0,$.jsx)(u,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,$.jsx)(Ne,{value:d().label,onChange:e=>f(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Pe,{value:o,onChange:e=>c(e.target.value),placeholder:`{
10
- "type": "object",
11
- "properties": {
12
- "field1": { "type": "string" },
13
- "field2": { "type": "number" }
14
- },
15
- "required": ["field1"]
16
- }`,rows:8,className:`font-mono text-sm`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Z,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){tn.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(Z,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=d();return!e.value||e.value===`json`?null:(0,$.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,$.jsx)(ae,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,$.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,$.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,$.jsx)(x,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},an=U(`components:chat-input`),on=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},sn=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r,i18n:i}=s(),[a,o]=(0,Q.useState)(``),[c,u]=(0,Q.useState)(!1),f=(0,Q.useRef)(null),p=(0,Q.useRef)(``),m=(0,Q.useMemo)(()=>!!on(),[]),[g,_]=(0,Q.useState)([]),[v,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null),[O,A]=(0,Q.useState)(!1),[ee,N]=(0,Q.useState)([]),[P,te]=(0,Q.useState)(!1),[ne,I]=(0,Q.useState)(!1),[L,R]=(0,Q.useState)(null),[ae,oe]=(0,Q.useState)(!1),z=(0,Q.useRef)(null),ce=(0,Q.useRef)(null),{isGenerating:le,setBackgroundImage:ue}=Oe(),V=Oe(e=>e.preferences.imageGenSettings?.enabled===!0),fe=V&&ae,{currentSession:H,models:U}=Y(),W=(0,Q.useRef)(null),pe=(0,Q.useMemo)(()=>({model:H?.personaId?`persona:${H.personaId}`:H?.model||``,providerType:H?.providerType,providerId:H?.providerId}),[H?.model,H?.personaId,H?.providerId,H?.providerType]),G=(0,Q.useMemo)(()=>we(U,pe),[U,pe]),he=pe.model?xe(G,pe):``,ge=Se(U,pe);(0,Q.useEffect)(()=>{let e=!1;return V&&(async()=>{try{let t=await me.getPlugins();if(e)return;oe(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;oe(!1)}})(),()=>{e=!0}},[V]),(0,Q.useEffect)(()=>{if(!w)return;let e=e=>{z.current&&!z.current.contains(e.target)&&(T(!1),D(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[w]);let ye=()=>{T(!1),D(null),A(!1)};(0,Q.useEffect)(()=>{if(!O)return;let e=!1;return ve.getCollections().then(t=>{!e&&t.success&&t.data&&N(t.data)}).catch(()=>{}),()=>{e=!0}},[O]);let q=H?.settings?.knowledgeCollectionIds??[],be=async e=>{if(!H)return;let t=q.includes(e)?q.filter(t=>t!==e):[...q,e],n={...H.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(Y.setState(e=>({currentSession:e.currentSession?.id===H.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===H.id?{...e,settings:n}:e)})),!H.isPrivate)try{await K.updateSession(H.id,{settings:n})}catch(e){an.error(`Failed to update knowledge collections:`,e),B.error(r(`chat.input.menu.attachFailed`))}};(0,Q.useEffect)(()=>()=>{f.current?.stop()},[]);let Ce=()=>{if(c){f.current?.stop();return}let e=on();if(!e)return;let t=new e;t.lang=i.language,t.continuous=!0,t.interimResults=!0,p.current=a,t.onresult=e=>{let t=``;for(let n=0;n<e.results.length;n++)t+=e.results[n][0]?.transcript??``;let n=p.current;o(n?`${n} ${t.trim()}`:t.trim())},t.onend=()=>{f.current=null,u(!1)},t.onerror=()=>{f.current=null,u(!1)},f.current=t;try{t.start(),u(!0)}catch(e){an.error(`Failed to start dictation:`,e),f.current=null}},De=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){ye(),I(!0);try{let e=await ve.uploadDocument(t,H?.id);e.success?(B.success(r(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):B.error(e.error||r(`chat.input.menu.attachFailed`))}catch(e){an.error(`Document upload failed:`,e),B.error(r(`chat.input.menu.attachFailed`))}finally{I(!1)}}},X=async()=>{let e=E?.trim();if(!(!e||P)){te(!0);try{let t=await ve.fetchWebpage(e,H?.id);t.success?(B.success(r(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),ye()):B.error(t.error||r(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||r(`chat.input.menu.attachFailed`);an.error(`Webpage attach failed:`,e),B.error(t)}finally{te(!1)}}},ke=t=>{if(t.preventDefault(),!(!a.trim()||le)){if(!ge){B.error(`Select an available model before sending`);return}e(a.trim(),g.length>0?g:void 0,v||void 0),o(``),_([])}},Ae=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ke(e))},je=()=>{t()};(0,Q.useEffect)(()=>{let e=W.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[a]),(0,Q.useEffect)(()=>{(async()=>{if(H?.personaId)try{let e=await _e.getPersona(H.personaId);if(e.success&&e.data)R(e.data);else{an.warn(`Persona ${H.personaId} not found, clearing reference`),R(null);let{setCurrentSession:e}=Y.getState();e({...H,personaId:void 0})}}catch(e){if(an.error(`Failed to load current persona:`,e),R(null),H){let{setCurrentSession:e}=Y.getState();e({...H,personaId:void 0})}}else R(null)})()},[H?.personaId]);let Me=async e=>{let t=Ee(G,e.target.value);if(t&&H)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await _e.getPersona(e);if(!n.success||!n.data){B.error(`Failed to load persona details`);return}let i=n.data,a=await K.updateSession(H.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(a.success&&a.data){let{sessions:e}=Y.getState(),t=e.map(e=>e.id===H.id?a.data:e);Y.setState({sessions:t,currentSession:a.data}),i.background&&ue(i.background),B.success(r(`chat.persona.applied`))}}else{let e=await K.updateSession(H.id,{model:t.model,providerType:t.providerType,providerId:(t.providerType===`plugin`||t.providerType===`agent`)&&t.providerId||null,personaId:null});if(e.success&&e.data){let{sessions:t}=Y.getState(),n=t.map(t=>t.id===H.id?e.data:t);Y.setState({sessions:n,currentSession:e.data}),ue(null),B.success(r(`chat.model.updated`))}}}catch(e){an.error(`Failed to update session:`,e),B.error(`Failed to update session`)}},Ne=g.length>0||v!==null;return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[S&&(0,$.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/90`,children:[(0,$.jsx)(Qt,{images:g,onImagesChange:_,maxImages:5,sessionId:H?.id,disabled:n}),(0,$.jsx)(rn,{format:v,onFormatChange:b})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[(0,$.jsx)(`form`,{onSubmit:ke,children:(0,$.jsxs)(`div`,{className:J(`flex items-end gap-2 rounded-[1.35rem] border p-2 transition-[border-color,box-shadow,background-color] duration-200`,`bg-surface/[0.92] dark:bg-dark-200/[0.92] backdrop-blur-xl`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_14px_42px_rgba(15,23,42,0.08)]`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_52px_rgba(15,23,42,0.11)]`),children:[(0,$.jsxs)(`div`,{ref:z,className:`relative flex-shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(S){C(!1);return}T(e=>!e),D(null)},className:J(`h-8 w-8 sm:h-9 sm:w-9 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,Ne&&`text-primary-600 dark:text-primary-400`,(S||w)&&`bg-gray-100 dark:bg-dark-300`),title:r(`chat.input.attachments`),children:ne||P?(0,$.jsx)(se,{className:`h-4 w-4 animate-spin`}):Ne?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(h,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):S?(0,$.jsx)(l,{className:`h-4 w-4`}):(0,$.jsx)(d,{className:`h-4 w-4`})}),w&&(0,$.jsx)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 w-64 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:O?(0,$.jsxs)(`div`,{className:`p-1`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.input.menu.attachKnowledge`)}),ee.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-gray-400 dark:text-dark-500`,children:r(`chat.input.menu.noCollections`)}):ee.map(e=>{let t=q.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void be(e.id),className:J(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),"aria-pressed":t,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(F,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(re,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>A(!1),className:`mt-1 w-full rounded-lg border-t border-gray-100 px-2.5 py-1.5 text-start text-xs text-gray-500 hover:bg-gray-100 dark:border-dark-300 dark:text-dark-600 dark:hover:bg-dark-200`,children:r(`common.back`)})]}):E===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{C(!0),ye()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(ie,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.uploadImages`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ce.current?.click(),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(x,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>D(``),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(k,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>A(!0),className:`flex w-full items-center justify-between gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(F,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachKnowledge`)]}),q.length>0&&(0,$.jsx)(`span`,{className:`rounded-full bg-primary-50 px-1.5 text-[10px] font-medium tabular-nums text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`,children:q.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{C(!0),ye()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(M,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.structuredOutput`)]})]}):(0,$.jsxs)(`div`,{className:`p-1.5`,children:[(0,$.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.input.menu.attachWebpage`)}),(0,$.jsx)(`input`,{type:`url`,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),X()):e.key===`Escape`&&D(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>D(null),className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:r(`common.cancel`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void X(),disabled:!E.trim()||P,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white hover:bg-gray-700 disabled:opacity-50 dark:bg-dark-300 dark:hover:bg-dark-400`,children:P?(0,$.jsx)(se,{className:`h-3.5 w-3.5 animate-spin`}):r(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:ce,type:`file`,accept:`.pdf,.txt,application/pdf,text/plain`,className:`hidden`,onChange:e=>void De(e)})]}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(Xt,{ref:W,value:a,onChange:e=>o(e.target.value),onKeyDown:Ae,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!m-0 min-h-[36px] max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !p-1.5 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1})}),(0,$.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1 sm:gap-2`,children:[H&&G.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(ze,{models:G,selectedModel:he,onModelChange:Me,getModelValue:Te,currentPersona:L,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:fe})}),m&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:Ce,className:J(`h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,c&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:r(c?`chat.input.voiceStop`:`chat.input.voiceInput`),"aria-pressed":c,children:(0,$.jsx)(j,{className:`h-4 w-4`})}),le?(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:je,className:J(`h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.stopGeneration`),children:(0,$.jsx)(de,{className:`h-4 w-4`})}):(0,$.jsx)(Z,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!a.trim()||n||!ge,className:J(`h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-100 text-gray-400 dark:bg-dark-300 dark:text-dark-500`,`disabled:cursor-not-allowed disabled:opacity-70`,`transition-colors duration-150 touch-manipulation`,a.trim()&&!n&&ge&&[`bg-gray-950 text-white hover:bg-gray-800`,`dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`shadow-sm`]),title:r(`chat.input.sendMessage`),children:(0,$.jsx)(y,{className:`h-4 w-4`})})]})]})}),H&&G.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(ze,{models:G,selectedModel:he,onModelChange:Me,getModelValue:Te,currentPersona:L,className:`w-full`,compact:!0,showImageGen:fe})}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(en,{sessionId:H?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),Ne&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,g.length>0&&r(`chat.footer.images`,{count:g.length}),g.length>0&&v&&` • `,v&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},cn=U(`components:chat-controls-panel`),ln=[{key:`temperature`,labelKey:`temperature`,step:`0.1`,min:0,max:2},{key:`top_p`,labelKey:`topP`,step:`0.05`,min:0,max:1},{key:`top_k`,labelKey:`topK`,step:`1`,min:1},{key:`min_p`,labelKey:`minP`,step:`0.05`,min:0,max:1},{key:`num_predict`,labelKey:`maxTokens`,step:`1`},{key:`repeat_penalty`,labelKey:`repeatPenalty`,step:`0.05`,min:0},{key:`seed`,labelKey:`seed`,step:`1`},{key:`num_ctx`,labelKey:`contextLength`,step:`1`}],un=({session:e,open:t,onClose:n})=>{let{t:r}=s(),i=Oe(e=>e.preferences.generationOptions),a=(0,Q.useMemo)(()=>e.messages.find(e=>e.role===`system`),[e.messages]),[o,c]=(0,Q.useState)(a?.content??``),[l,u]=(0,Q.useState)(e.settings?.generationOptions??{}),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(e.id);p!==e.id&&(m(e.id),c(a?.content??``),u(e.settings?.generationOptions??{}));let h=(e,t)=>{u(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},g=async()=>{f(!0);try{let t=o.trim(),i=a?.content??``,s=Object.fromEntries(Object.entries(l).filter(([,e])=>e!==void 0)),c=Object.keys(s).length>0?{generationOptions:s}:void 0,u=e.messages;if(t!==i.trim()&&(a?u=t?e.messages.map(e=>e.id===a.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==a.id):t&&(u=[{id:be(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)Y.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:u,settings:c}:t.currentSession}));else{let t=await K.updateSession(e.id,{messages:u,settings:c});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;Y.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}w.success(r(`chat.controls.saved`)),n()}catch(e){cn.error(`Failed to save chat controls:`,e),w.error(r(`chat.controls.saveFailed`))}finally{f(!1)}};return(0,$.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:J(`flex h-full w-[21rem] shrink-0 flex-col border-s border-black/[0.06] bg-surface/70 backdrop-blur-xl dark:border-white/[0.07] dark:bg-dark-100/70`,!t&&`hidden`),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:r(`chat.controls.title`)}),(0,$.jsx)(`button`,{onClick:n,className:`rounded-full p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-900`,title:r(`common.close`),children:(0,$.jsx)(I,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:r(`chat.controls.systemPrompt`)}),(0,$.jsx)(`textarea`,{dir:`auto`,value:o,onChange:e=>c(e.target.value),placeholder:r(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/[0.08] bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:r(`chat.controls.advancedParams`)}),(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:r(`chat.controls.advancedParamsDescription`)}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:ln.map(e=>{let t=l[e.key],n=i?.[e.key];return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-${e.key}`,className:`text-[13px] text-gray-700 dark:text-dark-700`,children:r(`chat.controls.params.${e.labelKey}`)}),(0,$.jsx)(`input`,{id:`chat-control-${e.key}`,type:`number`,inputMode:`decimal`,step:e.step,min:e.min,max:e.max,value:typeof t==`number`?t:``,placeholder:typeof n==`number`?String(n):r(`common.default`),onChange:t=>h(e.key,t.target.value),className:`w-24 rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-black/[0.06] px-4 py-3 dark:border-white/[0.07]`,children:[(0,$.jsx)(`button`,{onClick:()=>{u({}),c(a?.content??``)},className:`text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:r(`common.reset`)}),(0,$.jsx)(Z,{onClick:()=>void g(),size:`sm`,disabled:d,children:r(d?`common.saving`:`common.save`)})]})]})},dn=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)({top:0,left:0});(0,Q.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect(),t=document.documentElement.dir===`rtl`?e.right-288:e.left;s({top:e.bottom+8,left:Math.min(window.innerWidth-288-8,Math.max(8,t))})}},[r]);let c=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),l=()=>pe(e,64),u=t=>{G(t.currentTarget,e.name,64)};return(0,$.jsxs)(`div`,{className:J(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:J(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:u}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,$.jsx)(C,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(O,{className:J(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Be.createPortal)((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,$.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,$.jsxs)(`div`,{className:J(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,$.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,$.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,$.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`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 end-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,$.jsx)(I,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,$.jsxs)(`div`,{className:`absolute top-2 start-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,$.jsx)(ee,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,$.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:u})}),(0,$.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,$.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,$.jsx)(ne,{className:`h-3 w-3`}),e.model]}),e.description&&(0,$.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,$.jsxs)(`div`,{className:`mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,$.jsx)(le,{className:`h-2.5 w-2.5 text-gray-400`}),(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(ce,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,$.jsx)(ee,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},fn=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Q.useRef)(null),[o,c]=(0,Q.useState)(!1),l=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){w.error(`File ${o.name} is not an image`);continue}if(o.size>10485760){w.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&w.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),c(!0)},d=e=>{e.preventDefault(),c(!1)},f=e=>{e.preventDefault(),c(!1),l(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},m=e.length<n;return(0,$.jsxs)(`div`,{className:J(`space-y-3`,r),children:[m&&(0,$.jsxs)(`div`,{className:J(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:u,onDragLeave:d,onDrop:f,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,$.jsx)(I,{className:`h-4 w-4`})})})]},t))}),m&&e.length>0&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(ie,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},pn=U(`use-chat`),mn=new Set([`New Chat`,`New Demo Session`]),hn=e=>!e||mn.has(e),gn=e=>{let[t,n]=(0,Q.useState)(``),[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)([]),{addMessage:d,updateMessage:f,updateMessageWithStatistics:p,applySessionTitle:m,setGeneratingTitleForSession:h}=Y(),{setIsGenerating:g,preferences:_}=Oe(),v=(0,Q.useRef)(null),y=(0,Q.useRef)(null),b=(0,Q.useRef)(!1),x=(0,Q.useRef)(null),S=(0,Q.useRef)(``),C=(0,Q.useRef)(``),T=(0,Q.useRef)(0),E=(0,Q.useRef)(void 0),D=(0,Q.useRef)(null),O=(0,Q.useRef)(``),k=(0,Q.useRef)(``),A=(0,Q.useCallback)(()=>{D.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(D.current),D.current=null},[]),ee=(0,Q.useCallback)((e,t=!1,r=``)=>{if(O.current=e,k.current=r,t||typeof window>`u`){A(),n(e),i(r);return}D.current===null&&(D.current=window.requestAnimationFrame(()=>{D.current=null,n(O.current),i(k.current)}))},[A]),j=(0,Q.useCallback)(()=>{A(),O.current=``,k.current=``,n(``),i(``)},[A]),M=(0,Q.useCallback)(()=>{y.current=null,b.current=!1,x.current=null},[]),N=(0,Q.useCallback)(async e=>{let t=Oe.getState().preferences.titleSettings,n=y.current,r=b.current&&x.current===e;if(pn.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),!n||!r||!t?.autoTitle||!t?.taskModel){M();return}M(),pn.debug(`Triggering auto-title generation...`),h(e);try{let r=await K.generateTitle(e,t.taskModel,n,t.taskProviderType,t.taskProviderId);if(pn.debug(`Title generation response:`,r),!r.success||!r.data?.title)throw Error(r.error||`Title generation returned no title`);m(e,r.data.title,r.data.updatedAt),r.data.source===`fallback`?w.error(`Could not generate a title; using the message preview`):w.success(`Chat title generated`)}catch(e){pn.error(`Failed to generate title:`,e),w.error(`Failed to generate chat title`)}finally{h(null)}},[m,M,h]);(0,Q.useEffect)(()=>()=>{X.offMessage(`user_message`),X.offMessage(`assistant_chunk`),X.offMessage(`assistant_complete`),X.offMessage(`tool_status`),X.offMessage(`error`)},[e]),(0,Q.useEffect)(()=>{if(!e){X.offMessage(`user_message`),X.offMessage(`assistant_chunk`),X.offMessage(`assistant_complete`),X.offMessage(`tool_status`),X.offMessage(`error`);return}return X.onMessage(`user_message`,()=>{}),X.onMessage(`assistant_chunk`,t=>{let n=t,r=n.messageId||v.current;r&&(S.current=n.total,typeof n.thinkingTotal==`string`&&(C.current=n.thinkingTotal),Ze(r,n.total,C.current),ee(n.total,n.done,C.current),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{f(e,r,S.current),T.current=Date.now()},n.done?0:200))}),X.onMessage(`tool_status`,e=>{let t=e;u(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),X.onMessage(`assistant_complete`,t=>{let n=t;pn.debug(`Hook: Received assistant_complete for session:`,e,`messageId:`,n.messageId,`with statistics:`,!!n.statistics),c(!1),j(),g(!1),u([]);let r=n.messageId||v.current;if(n&&r){let t=S.current||n.content,i=C.current||n.thinking,a=$e(r),o=n.statistics?.thinking_duration_ms===void 0&&a!==void 0?{...n.statistics,thinking_duration_ms:a}:n.statistics;p(e,r,t,o,n.providerMetadata,i)}N(e),v.current=null,S.current=``,C.current=``,E.current&&clearTimeout(E.current),T.current=0}),X.onMessage(`error`,e=>{let t=e;if(c(!1),j(),g(!1),v.current=null,C.current=``,t.code===`SESSION_NOT_FOUND`){pn.warn(`Session not found, redirecting to create new session...`),w.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}w.error(t.error),M()}),c(!1),j(),v.current=null,C.current=``,()=>{E.current&&clearTimeout(E.current),A()}},[e,f,p,g,ee,j,A,N,M]);let P=(0,Q.useCallback)(async(t,n,r)=>{if(!(!e||!t.trim()&&(!n||n.length===0)))try{let i=Y.getState(),a=i.currentSession,s={model:a?.personaId?`persona:${a.personaId}`:a?.model||``,providerType:a?.providerType,providerId:a?.providerId};if(!Se(i.models,s)){w.error(`Select an available model before sending`);return}g(!0),c(!0),j(),E.current&&clearTimeout(E.current),T.current=Date.now();let l=a?.isPrivate===!0,u=a?.messages?.some(e=>e.role===`user`);!l&&!u&&hn(a?.title)?(y.current=t.trim(),b.current=!0,x.current=e):(y.current=null,b.current=!1,x.current=null),d(e,{role:`user`,content:t.trim(),images:n});let p=be();if(v.current=p,C.current=``,o(p),d(e,{role:`assistant`,content:``,id:p}),H()){let n=`Demo response for: ${t.trim()}`;window.setTimeout(()=>{f(e,p,n),c(!1),j(),o(null),g(!1),N(e),v.current=null,S.current=``,C.current=``},500);return}X.isConnected||await X.connect();let m=l?a?.messages?.filter(e=>e.role!==`system`&&e.id!==p).map(e=>({role:e.role,content:e.content,thinking:e.thinking,images:e.images,providerMetadata:e.providerMetadata})):void 0;X.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:n,format:r,options:{..._.generationOptions,...a?.settings?.generationOptions},assistantMessageId:p,isPrivate:l,...l?{model:a?.model,providerType:a?.providerType,providerId:a?.providerId,messageHistory:m}:{}}})}catch(e){pn.error(`Failed to send message:`,e),c(!1),j(),o(null),g(!1),v.current=null,C.current=``,w.error(`Failed to send message`)}},[e,d,f,g,j,N,_.generationOptions]),F=(0,Q.useCallback)(()=>{c(!1),j(),o(null),g(!1),v.current=null,C.current=``},[g,j]),te=(0,Q.useCallback)(async()=>{let t=Y.getState(),n=t.currentSession;if(!n||!e)return;if(!Se(t.models,{model:n.personaId?`persona:${n.personaId}`:n.model,providerType:n.providerType,providerId:n.providerId})){w.error(`Select an available model before regenerating`);return}let r=n.messages,i=-1,a=-1;for(let e=r.length-1;e>=0;e--)if(r[e].role===`assistant`){a=e;break}if(a>0){for(let e=a-1;e>=0;e--)if(r[e].role===`user`){i=e;break}}if(i===-1||a===-1){w.error(`No message to regenerate`);return}let s=r[i],l=r[a];try{g(!0),c(!0),j(),E.current&&clearTimeout(E.current),T.current=Date.now();let t=be();v.current=t,C.current=``,o(t),d(e,{role:`assistant`,content:``,id:t,parentId:l.parentId||l.id,branchIndex:l.siblingCount||1,isActive:!0}),X.isConnected||await X.connect();let i=n.isPrivate===!0,a=i?r.filter(e=>e.role!==`system`).map(e=>({role:e.role,content:e.content,thinking:e.thinking,images:e.images,providerMetadata:e.providerMetadata})):void 0;X.send({type:`chat_stream`,data:{sessionId:e,content:s.content,images:s.images,options:{..._.generationOptions,...n.settings?.generationOptions},assistantMessageId:t,regenerate:!0,originalMessageId:l.id,isPrivate:i,...i?{model:n.model,providerType:n.providerType,providerId:n.providerId,messageHistory:a}:{}}})}catch(e){pn.error(`Failed to regenerate message:`,e),c(!1),j(),o(null),g(!1),v.current=null,C.current=``,w.error(`Failed to regenerate message`)}},[e,g,j,d,_.generationOptions]),ne=(0,Q.useCallback)(async t=>{let n=Y.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){w.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await K.switchMessageBranch(e,t,a);if(r.success&&r.data){let r=n.messages.map(e=>e.id===i||e.parentId===i?{...e,isActive:e.id===t}:e),o={...n,messages:r,updatedAt:Date.now()};Y.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),w.success(`Switched to variant ${a+1}`)}else w.error(r.error||`Failed to select branch`)}catch(e){pn.error(`Failed to select branch:`,e),w.error(`Failed to select branch`)}},[e]);return{sendMessage:P,stopGeneration:F,regenerateLastMessage:te,editAndResendMessage:(0,Q.useCallback)(async(t,n)=>{if(!e||!n.trim())return;let r=Y.getState(),i=r.currentSession;if(!i||i.id!==e)return;let a=i.messages.findIndex(e=>e.id===t);if(a===-1||i.messages[a].role!==`user`)return;let o=i.messages[a],s=i.messages.slice(0,a);try{i.isPrivate||await K.updateSession(e,{messages:s}),r.truncateMessagesFrom(e,t),await P(n,o.images)}catch(e){pn.error(`Failed to edit message:`,e),w.error(`Failed to edit message`)}},[e,P]),selectBranch:ne,isStreaming:s,streamingMessage:t,streamingThinking:r,streamingMessageId:a,toolActivities:l}},_n=U(`pages:chat-page`),vn=(e,t,n=!1)=>{let r=new Date().getHours(),i=e?`${n?`،`:`,`} \u2068${e}\u2069`:``;return r>=5&&r<12?{id:`time`,title:`${t?t(`chat.greeting.morning`):`Good morning`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=12&&r<17?{id:`time`,title:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=17&&r<21?{id:`time`,title:`${t?t(`chat.greeting.evening`):`Good evening`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}:{id:`time`,title:`${t?t(`chat.greeting.night`):`Good night`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}},yn=(e,t,n,r=!1)=>{let i=Ae(e);return i===`time`?vn(t,n,r):{id:i,title:n?n(`chat.welcome.variety.${i}.title`):`What should we make?`,subtitle:n?n(`chat.welcome.variety.${i}.subtitle`):`Start with a thought, a sketch, or a stubborn problem.`}},bn=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),u=o(),{currentSession:f,sessions:m,models:g,selectedModel:_,selectedProviderType:v,selectedProviderId:b,setSelectedModel:x,createSession:S,setCurrentSession:C,loadSessions:T,getCurrentPersona:E}=Y(),{user:D}=De(),O=Oe(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:k,stopGeneration:A,regenerateLastMessage:ee,editAndResendMessage:j,selectBranch:M,isStreaming:N,streamingMessage:P,streamingThinking:F,streamingMessageId:te,toolActivities:ne}=gn(f?.id||``),I=E(),L=(0,Q.useMemo)(()=>({model:_,providerType:v,providerId:b}),[_,b,v]),R=(0,Q.useMemo)(()=>we(g,L),[g,L]),re=_?xe(R,L):``,ie=Se(g,L),ae=new URLSearchParams(u.search).get(`incognito`)===`1`,[oe,z]=(0,Q.useState)(ke),[se,ce]=(0,Q.useState)(null),[le,ue]=(0,Q.useState)(!1),B=Oe(e=>e.preferences.showFollowUpSuggestions!==!1),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=f?.id,t=fe.current&&!N;if(fe.current=N,!e||N||!B||f?.isPrivate||!t)return;let n=f.messages[f.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||de.current===n.id)return;de.current=n.id;let r=!1;return K.generateFollowUps(e).then(t=>{r||!t.success||Y.getState().currentSession?.id===e&&ce({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[N,f,B]);let H=se&&se.sessionId===f?.id?se.suggestions:[],U=(0,Q.useMemo)(()=>yn(oe,D?.username,e,c(t.language)),[t.language,e,D?.username,oe]),[W,pe]=(0,Q.useState)(``),[G,he]=(0,Q.useState)([]),[ge,_e]=(0,Q.useState)(!1),ve=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{z(ke())};return window.addEventListener(je,e),()=>window.removeEventListener(je,e)},[]);let[ye,q]=(0,Q.useState)(!1),be=O&&ye,X=(0,Q.useCallback)((t=!0)=>{let n=_?L:g[0]?Ce(g[0]):null;if(!n||!Se(g,n))return t&&w.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return C({id:`private-${r}`,title:e(`chat.session.incognito`,`Incognito Chat`),model:n.model,providerType:n.providerType,providerId:n.providerId,messages:[],createdAt:r,updatedAt:r,isPrivate:!0}),!0},[g,_,L,C,e]);(0,Q.useEffect)(()=>{m.length===0&&T()},[T,m.length]),(0,Q.useEffect)(()=>{!ae||f?.isPrivate||X(!1)},[f?.isPrivate,ae,X]),(0,Q.useEffect)(()=>{let e=!1;return O&&(async()=>{try{let t=await me.getPlugins();if(e)return;q(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;q(!1)}})(),()=>{e=!0}},[O]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!(f?.isPrivate&&!n)&&m.length!==0)if(n){let e=m.find(e=>e.id===n);e&&e.id!==f?.id?C(e):e||(_n.warn(`Session ${n} not found for current user, redirecting...`),m.length>0?r(`/c/${m[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&m.length>0&&u.pathname===`/`&&r(`/c/${m[0].id}`,{replace:!0})})()},[n,m,C,r,f?.id,f?.isPrivate,u.pathname]),(0,Q.useEffect)(()=>{if(f?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{k(t.content,t.images)},100)}catch(e){_n.error(`Failed to parse pending message:`,e)}}}},[f?.id,k]),(0,Q.useEffect)(()=>{let e=ve.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[W]);let Ae=async t=>{if(t.preventDefault(),!W.trim()||!_)return;if(!ie){w.error(e(`chat.model.selectBeforeSending`));return}Me(`impact`);let n={content:W.trim(),images:G.length>0?G:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),pe(``),he([]);let i=await S(_,void 0,_.startsWith(`persona:`)?_.slice(8):void 0,v,b);i&&r(`/c/${i.id}`,{replace:!0})},Ne=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ae(e))},Pe=async e=>{let t=Ee(R,e.target.value);t&&x(t.model,t.providerType,t.providerId)},Fe=(e,t,n)=>{f&&(Me(`impact`),ce(null),k(e,t,n))};if(!f){let t=G.length>0;return(0,$.jsxs)(`div`,{className:`relative h-full flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,$.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,$.jsx)(`div`,{className:`absolute left-[12%] top-[18%] h-56 w-56 rounded-full bg-primary-500/[0.035] blur-3xl dark:bg-primary-400/[0.04]`}),(0,$.jsx)(`div`,{className:`absolute bottom-[16%] right-[10%] h-72 w-72 rounded-full bg-gray-900/[0.025] blur-3xl dark:bg-white/[0.025]`}),(0,$.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,$.jsxs)(`button`,{onClick:()=>X(),disabled:!_&&g.length===0||!!_&&!ie,className:`absolute end-4 top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-surface/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-6 sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,$.jsx)(V,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{children:e(`chat.session.incognito`,`Incognito Chat`)})]}),(0,$.jsxs)(`div`,{className:`relative z-[1] mx-auto flex min-h-full w-full max-w-3xl flex-col items-center justify-center`,children:[(0,$.jsxs)(`div`,{className:`mb-10 flex flex-col items-center text-center animate-fade-in sm:mb-12`,"aria-live":`polite`,children:[(0,$.jsx)(`h1`,{className:`mb-4 max-w-3xl text-balance text-[clamp(2.65rem,7vw,5.25rem)] font-light leading-[0.98] tracking-[-0.055em] text-gray-950 dark:text-dark-950 rtl:leading-[1.12] rtl:tracking-normal`,children:U.title}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-base leading-relaxed text-gray-500 dark:text-dark-600 sm:text-lg`,children:U.subtitle})]},U.id),R.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[ge&&(0,$.jsx)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:(0,$.jsx)(fn,{images:G,onImagesChange:he,maxImages:5})}),(0,$.jsx)(`form`,{onSubmit:Ae,children:(0,$.jsxs)(`div`,{className:J(`flex items-end gap-2 rounded-[1.35rem] border p-2 transition-[border-color,box-shadow,background-color] duration-200`,`border-black/[0.08] bg-surface/90 dark:border-white/[0.09] dark:bg-dark-200/90`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_50px_rgba(15,23,42,0.08)] backdrop-blur-xl`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_22px_65px_rgba(15,23,42,0.12)]`),children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>_e(!ge),className:J(`h-8 w-8 sm:h-9 sm:w-9 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300 transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,ge&&`bg-gray-100 dark:bg-dark-300`),title:e(`chat.input.attachImages`),children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(h,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):ge?(0,$.jsx)(l,{className:`h-4 w-4`}):(0,$.jsx)(d,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(Xt,{ref:ve,value:W,onChange:e=>pe(e.target.value),onKeyDown:Ne,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 min-h-[36px] max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !p-1.5 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1})}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(ze,{models:R,selectedModel:re,onModelChange:Pe,getModelValue:Te,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:be})}),(0,$.jsx)(Z,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!W.trim()||!_||!ie,className:J(`h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-950 text-white hover:bg-gray-800 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`disabled:bg-gray-100 disabled:text-gray-400 dark:disabled:bg-dark-300 dark:disabled:text-dark-500 disabled:hover:bg-gray-100 dark:disabled:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,W.trim()&&_&&`shadow-sm`),title:e(`chat.input.sendMessage`),children:(0,$.jsx)(y,{className:`h-4 w-4`})})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(ze,{models:R,selectedModel:re,onModelChange:Pe,getModelValue:Te,className:`w-full`,compact:!0,showImageGen:be})}),(0,$.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,$.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,$.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.07] bg-surface/70 p-6 backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/70`,children:[(0,$.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,$.jsx)(`code`,{className:`block rounded-xl bg-gray-100 p-3 font-mono text-xs text-gray-800 dark:bg-dark-300 dark:text-dark-700`,children:e(`chat.model.pullCommand`)})]})})]})]})}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:I?.background?{backgroundImage:`url(${I.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[I?.background&&(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,$.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[f?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(V,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,$.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),I&&!f?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,$.jsx)(dn,{persona:I,onClear:()=>{f&&K.updateSession(f.id,{model:I.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);Y.setState(t=>({sessions:t.sessions.map(t=>t.id===f.id?e.data:t),currentSession:e.data}))}).catch(t=>{_n.error(`Failed to remove persona:`,t),w.error(e(`chat.persona.removeFailed`))})}})}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`button`,{onClick:()=>ue(e=>!e),className:J(`absolute end-3 top-3 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950`,le&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":le,children:(0,$.jsx)(p,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(Jt,{messages:f.messages,streamingMessage:P,streamingThinking:F,streamingMessageId:te,isStreaming:N,toolActivities:ne,onRegenerate:ee,onSelectBranch:M,onEditResend:j,followUpSuggestions:H,onFollowUpSelect:e=>Fe(e),className:`flex-1`}),(0,$.jsx)(sn,{onSendMessage:Fe,onStopGeneration:A,disabled:!f})]}),(0,$.jsx)(un,{session:f,open:le,onClose:()=>ue(!1)})]})]})]})};export{bn as ChatPage,bn as default};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./useTranslation-CdeLZqSW.js";import{Gt as i,O as a,Rt as o,_n as s,bt as c,dt as ee,f as l,l as u,on as d,t as f,wn as p,zt as m}from"./ui-vendor-D_pYT79f.js";import{t as h}from"./logger-DSXjF4ye.js";import{S as g}from"./api-jwjnjqx6.js";import{n as _}from"./authStore-CsCkBmaG.js";import{i as v,l as y,n as b,r as x}from"../assets/index-D4LhtFTX.js";var S=e(n(),1),C=t(),w=h(`components:first-time-setup`),T=({onComplete:e})=>{let{t}=r(),[n,h]=(0,S.useState)(`welcome`),[T,E]=(0,S.useState)(``),[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)(!1),[N,P]=(0,S.useState)(!1),[F,I]=(0,S.useState)(!1),[L,R]=(0,S.useState)(null),[z,B]=(0,S.useState)(!1),[V,H]=(0,S.useState)(!1),[U,W]=(0,S.useState)(``),{login:G,systemInfo:K}=_(),q=K?.turnstile?.siteKey,J=!!(K?.turnstile?.enabled&&q),Y=(0,S.useCallback)(e=>{W(e)},[]),X=(0,S.useMemo)(()=>F||J&&!U,[F,J,U]);(0,S.useEffect)(()=>{n===`encryption-key`&&!L&&g.getEncryptionKey().then(e=>{e.success&&e.data&&R(e.data.encryptionKey)})},[n,L]);let Z=async e=>{if(e.preventDefault(),!T.trim()||!D.trim()||!k.trim()){p.error(t(`setup.admin.fillAllFields`));return}if(D!==k){p.error(t(`auth.signup.passwordMismatch`));return}let n=x(D);if(n){p.error(n);return}if(J&&!U){p.error(t(`auth.signup.tryAgain`));return}I(!0);try{let e=await g.signup({username:T,password:D,email:``,turnstileToken:U});if(e.success&&e.data){if(!(`token`in e.data)){p.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}G(e.data.user,e.data.token,e.data.systemInfo),p.success(t(`setup.admin.success`)),h(`encryption-key`)}else p.error(e.message||t(`setup.admin.failed`))}catch(e){w.error(`Admin creation error:`,e),p.error(t(`setup.admin.failed`))}finally{W(``),I(!1)}},Q=async()=>{if(L)try{await navigator.clipboard.writeText(L),B(!0),p.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>B(!1),3e3)}catch{p.error(t(`setup.encryptionKey.copyFailed`))}},te=()=>{if(!V){p.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,C.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,C.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,C.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,C.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})})}),(0,C.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,C.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,C.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,C.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,C.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,C.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,C.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,C.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,C.jsx)(a,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,C.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,C.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,C.jsx)(f,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,C.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,C.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,C.jsx)(c,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,C.jsx)(`button`,{onClick:()=>h(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,C.jsxs)(`div`,{className:`flex items-center`,children:[(0,C.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,C.jsx)(s,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,C.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,C.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,C.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,C.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})}),(0,C.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,C.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,C.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,C.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,C.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,C.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,C.jsx)(ee,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,C.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,C.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,C.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,C.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,C.jsx)(l,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,C.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,C.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,C.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,C.jsxs)(`div`,{className:`mb-6`,children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:L||t(`setup.encryptionKey.loading`)}),(0,C.jsx)(`button`,{type:`button`,onClick:Q,disabled:!L,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:z?(0,C.jsx)(d,{className:`h-5 w-5 text-green-500`}):(0,C.jsx)(i,{className:`h-5 w-5`})})]}),(0,C.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,C.jsx)(`div`,{className:`mb-6`,children:(0,C.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:V,onChange:e=>H(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,C.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,C.jsx)(`button`,{onClick:te,disabled:!V,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,C.jsxs)(`div`,{className:`flex items-center`,children:[(0,C.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,C.jsx)(s,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,C.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,C.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,C.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,C.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})}),(0,C.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,C.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,C.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,C.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,C.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,C.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,C.jsxs)(`form`,{onSubmit:Z,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,C.jsx)(`input`,{id:`username`,type:`text`,value:T,onChange:e=>E(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:F})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(`input`,{id:`password`,type:j?`text`:`password`,value:D,onChange:e=>O(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:F}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>M(!j),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:F,children:j?(0,C.jsx)(m,{size:20}):(0,C.jsx)(o,{size:20})})]}),(0,C.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:b})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(`input`,{id:`confirmPassword`,type:N?`text`:`password`,value:k,onChange:e=>A(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:F}),(0,C.jsx)(`button`,{type:`button`,onClick:()=>P(!N),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:F,children:N?(0,C.jsx)(m,{size:20}):(0,C.jsx)(o,{size:20})})]})]}),J&&q&&(0,C.jsx)(v,{siteKey:q,action:`signup`,disabled:F,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:Y}),(0,C.jsxs)(`div`,{className:`flex gap-3`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:()=>h(`welcome`),disabled:F,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,C.jsx)(`button`,{type:`submit`,disabled:X,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:F?(0,C.jsxs)(`div`,{className:`flex items-center`,children:[(0,C.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,C.jsxs)(`div`,{className:`flex items-center`,children:[(0,C.jsx)(u,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,C.jsx)(`div`,{className:`mt-6 text-center`,children:(0,C.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{T as FirstTimeSetup};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./useTranslation-CdeLZqSW.js";import{a as i,n as a,o}from"./i18n-ZJQSoIuM.js";import{Bt as s,Ct as c,E as l,F as u,Ht as d,I as f,P as p,R as m,Rt as h,Tn as g,Ut as _,V as v,Z as y,an as b,bt as x,d as S,dt as C,f as w,ft as T,gn as E,hn as D,m as ee,n as te,nn as ne,o as re,on as O,pt as k,q as A,st as j,tt as M,vt as ie,x as ae,xn as oe,xt as se,y as N,z as ce,zt as le}from"./ui-vendor-D_pYT79f.js";import{t as P}from"./logger-DSXjF4ye.js";import{a as F,b as ue,c as I,g as de,i as fe,l as pe,n as me,p as he,r as ge,y as L}from"./api-jwjnjqx6.js";import{a as _e,o as ve,s as ye,t as be}from"./imageGenModels-Dx_QMLJQ.js";import{n as xe,t as R}from"./utils-BhpNrGnR.js";import{a as Se,d as Ce,f as we,l as Te,n as Ee,o as De,p as Oe,r as ke,t as Ae,u as je}from"./chatStore-DRY8C0J1.js";import{c as Me,n as Ne}from"./authStore-CsCkBmaG.js";import{a as Pe,n as Fe,o as Ie,t as Le}from"./appStore-CLIS0fvz.js";import{l as Re}from"./messageCodeStyles-CfzjQF-R.js";import{t as z}from"./Button-X9TT9gTD.js";import{d as B,f as ze}from"./ui-Dj9IFugT.js";import{d as Be,l as Ve,p as He,t as Ue}from"../assets/index-D4LhtFTX.js";var V=e(n(),1),H=t(),We=[{href:`https://github.com/libre-webui/libre-webui`,icon:c,labelKey:`settings.about.links.github`,descriptionKey:`settings.about.links.githubDescription`},{href:`https://git.kroonen.ai/libre-webui/libre-webui`,icon:se,labelKey:`settings.about.links.gitlab`,descriptionKey:`settings.about.links.gitlabDescription`},{href:`https://librewebui.org`,icon:s,labelKey:`settings.about.links.website`,descriptionKey:`settings.about.links.websiteDescription`},{href:`https://docs.librewebui.org`,icon:E,labelKey:`settings.about.links.documentation`,descriptionKey:`settings.about.links.documentationDescription`},{href:`https://ollama.ai`,icon:D,labelKey:`settings.about.links.ollama`,descriptionKey:`settings.about.links.ollamaDescription`},{href:`https://github.com/libre-webui/libre-webui/issues`,icon:M,labelKey:`settings.about.links.reportIssue`,descriptionKey:`settings.about.links.reportIssueDescription`}],Ge=[`settings.about.features.privacy`,`settings.about.features.openSource`,`settings.about.features.localInference`];function Ke({appVersion:e}){let{t}=r();return(0,H.jsx)(`div`,{className:`space-y-6`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`mb-4`,children:(0,H.jsx)(Ve,{className:`text-gray-900 dark:text-gray-100`})}),(0,H.jsx)(`div`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-6`,children:(0,H.jsx)(`span`,{children:t(`settings.about.title`)})}),(0,H.jsx)(`div`,{className:`bg-gray-50 dark:bg-dark-100 rounded-lg p-6 border border-gray-200 dark:border-dark-300`,children:(0,H.jsx)(`div`,{className:`space-y-4 text-sm text-gray-700 dark:text-gray-300`,children:Ge.map(e=>(0,H.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,H.jsx)(`div`,{className:`w-2 h-2 bg-primary-500 rounded-full mt-2 flex-shrink-0`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`font-semibold text-gray-900 dark:text-gray-100 mb-1`,children:t(`${e}.title`)}),(0,H.jsx)(`p`,{children:t(`${e}.description`)})]})]},e))})}),(0,H.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t(`settings.about.links.title`)}),(0,H.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:We.map(e=>{let n=e.icon;return(0,H.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-3 p-3 bg-white dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg hover:bg-gray-50 dark:hover:bg-dark-200 hover:border-gray-300 dark:hover:border-dark-400 transition-all duration-200 group`,children:[(0,H.jsx)(n,{className:`h-5 w-5 text-gray-600 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-gray-200`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:t(e.labelKey)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(e.descriptionKey)})]}),(0,H.jsx)(s,{className:`h-4 w-4 text-gray-400 ms-auto opacity-0 group-hover:opacity-100 transition-opacity`})]},e.href)})})]}),(0,H.jsx)(`div`,{className:`mt-6 p-4 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg`,children:(0,H.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-gray-500 dark:text-gray-400`,children:[e.includes(`-dev`)?(0,H.jsx)(`span`,{children:t(`settings.about.version`,{version:e})}):(0,H.jsx)(`a`,{href:`https://github.com/libre-webui/libre-webui/releases/tag/v${e}`,target:`_blank`,rel:`noopener noreferrer`,className:`hover:text-primary-600 dark:hover:text-primary-400 transition-colors`,children:t(`settings.about.version`,{version:e})}),(0,H.jsxs)(`span`,{children:[t(`settings.about.openSourceBy`,{company:``}),(0,H.jsx)(`a`,{href:`https://kroonen.ai`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 transition-colors`,children:`Kroonen AI`})]})]})})]})})}var qe=P(`components:background-upload`),Je=({className:e=``})=>{let{t}=r(),{preferences:n,setPreferences:i,backgroundImage:a,uploadBackgroundImage:o,removeBackgroundImage:s}=Le(),c=(0,V.useRef)(null),[l,u]=(0,V.useState)(!1),[d,f]=(0,V.useState)(!1),p=n.backgroundSettings||{enabled:!1,imageUrl:``,blurAmount:10,opacity:.6},m=async e=>{if(!e.type.startsWith(`image/`)){g.error(`Please select a valid image file`);return}if(e.size>5242880){g.error(`Image file size must be less than 5MB`);return}u(!0);try{await o(e),g.success(`Background image uploaded successfully`)}catch(e){qe.error(`Failed to upload background:`,e),g.error(`Failed to upload background image`)}finally{u(!1)}},h=e=>{let t=e.target.files?.[0];t&&m(t)},_=e=>{e.preventDefault(),f(!0)},v=e=>{e.preventDefault(),f(!1)},y=e=>{e.preventDefault(),f(!1);let t=e.dataTransfer.files?.[0];t&&m(t)},b=()=>{s(),g.success(`Background image removed`)},x=async e=>{let t=a||p.imageUrl||``,n={...p,imageUrl:t,enabled:e};if(i({backgroundSettings:n}),t||!e)try{await I.updatePreferences({backgroundSettings:n})}catch(e){qe.error(`Failed to update preferences:`,e)}},C=async e=>{let t=a||p.imageUrl||``,n={...p,imageUrl:t,blurAmount:e};if(i({backgroundSettings:n}),t)try{await I.updatePreferences({backgroundSettings:n})}catch(e){qe.error(`Failed to update preferences:`,e)}},w=async e=>{let t=a||p.imageUrl||``,n={...p,imageUrl:t,opacity:e};if(i({backgroundSettings:n}),t)try{await I.updatePreferences({backgroundSettings:n})}catch(e){qe.error(`Failed to update preferences:`,e)}};return(0,H.jsx)(`div`,{className:`space-y-4 ${e}`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-md font-medium text-gray-900 dark:text-gray-100 mb-3`,children:t(`settings.appearance.background.title`)}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:t(`settings.appearance.background.enable`)}),(0,H.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(`settings.appearance.background.enableDescription`)})]}),(0,H.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,H.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:p.enabled,onChange:e=>x(e.target.checked)}),(0,H.jsx)(`div`,{className:`w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-primary-300 dark:peer-focus:ring-primary-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-primary-600`})]})]}),(0,H.jsxs)(`div`,{className:`space-y-4`,children:[a?(0,H.jsx)(`div`,{className:`relative`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,H.jsx)(`div`,{className:`flex-shrink-0`,children:(0,H.jsx)(`img`,{src:a,alt:`Background preview`,className:`w-12 h-12 object-cover rounded-md`})}),(0,H.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:`Custom background image`}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:`Click to change or remove`})]}),(0,H.jsx)(z,{variant:`ghost`,size:`sm`,onClick:b,className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,H.jsx)(te,{className:`h-4 w-4`})})]})}):(0,H.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${d?`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:_,onDragLeave:v,onDrop:y,onClick:()=>c.current?.click(),children:[(0,H.jsx)(k,{className:`h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4`}),(0,H.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:t(`settings.appearance.background.upload`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:t(`settings.appearance.background.dragDrop`)}),(0,H.jsxs)(z,{variant:`outline`,size:`sm`,disabled:l,className:`mx-auto`,children:[(0,H.jsx)(S,{className:`h-4 w-4 me-2`}),t(l?`common.loading`:`settings.appearance.background.chooseImage`)]})]}),(0,H.jsx)(`input`,{ref:c,type:`file`,accept:`image/*`,onChange:h,className:`hidden`})]}),a&&(0,H.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[t(`settings.appearance.background.blur`),`:`,` `,p.blurAmount,`px`]}),(0,H.jsx)(`input`,{type:`range`,min:`0`,max:`30`,step:`1`,value:p.blurAmount,onChange:e=>C(parseInt(e.target.value)),className:`w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[t(`settings.appearance.background.opacity`),`:`,` `,Math.round(p.opacity*100),`%`]}),(0,H.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.1`,value:p.opacity,onChange:e=>w(parseFloat(e.target.value)),className:`w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700`})]})]})]})})},Ye=()=>{let{t:e,i18n:t}=r();return(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(x,{className:`h-4 w-4 text-gray-500 dark:text-gray-400`}),(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.appearance.language.title`)})]}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`settings.appearance.language.description`)}),(0,H.jsx)(`select`,{"data-testid":`language-switcher-select`,value:i(t.language),onChange:e=>{let t=e.target.value;a(t)},className:`w-full px-3 py-2 text-sm border border-gray-200 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-100 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500`,children:o.map(e=>(0,H.jsxs)(`option`,{value:e.code,children:[e.nativeName,` (`,e.name,`)`]},e.code))})]})};function Xe({theme:e,preferences:t,onThemeChange:n,onAccentChange:i,onCustomAccentChange:a,onAdaptToAccentChange:o,onShowUsernameChange:s,onShowFollowUpsChange:c,onHapticFeedbackChange:l}){let{t:u}=r(),d=e.accent||`blue`,f=e.customAccent||`#2563eb`,p=Pe(e);return(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsx)(Ye,{}),(0,H.jsx)(`div`,{className:`border-t border-gray-200 dark:border-dark-300 pt-6`,children:(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:u(`settings.appearance.title`)})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,H.jsxs)(`button`,{onClick:()=>n(`light`),className:`flex items-center justify-center gap-2 h-12 px-3 py-2.5 text-sm font-medium rounded-xl transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 ${e.mode===`light`?`bg-primary-600 text-white shadow-sm hover:bg-primary-700 hover:shadow-md focus:ring-primary-500`:`border border-gray-300 text-gray-700 bg-white shadow-sm hover:bg-gray-50 hover:border-gray-400 focus:ring-gray-500 dark:border-dark-300 dark:text-dark-700 dark:bg-dark-25 dark:hover:bg-dark-200 dark:hover:border-dark-400`}`,children:[(0,H.jsx)(N,{className:`h-4 w-4`}),u(`settings.appearance.theme.light`)]}),(0,H.jsxs)(`button`,{onClick:()=>n(`dark`),className:`flex items-center justify-center gap-2 h-12 px-3 py-2.5 text-sm font-medium rounded-xl transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 ${e.mode===`dark`?`bg-primary-600 text-white shadow-sm hover:bg-primary-700 hover:shadow-md focus:ring-primary-500`:`border border-gray-300 text-gray-700 bg-white shadow-sm hover:bg-gray-50 hover:border-gray-400 focus:ring-gray-500 dark:border-dark-300 dark:text-dark-700 dark:bg-dark-25 dark:hover:bg-dark-200 dark:hover:border-dark-400`}`,children:[(0,H.jsx)(y,{className:`h-4 w-4`}),u(`settings.appearance.theme.dark`)]})]}),(0,H.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-dark-300 pt-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-4 mb-3`,children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:u(`settings.appearance.accent.title`,{defaultValue:`Accent color`})})}),(0,H.jsx)(`div`,{className:`h-9 w-9 rounded-full border border-gray-200 dark:border-dark-400 shadow-inner flex-shrink-0`,style:{backgroundColor:p},"aria-hidden":`true`})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-5 xs:grid-cols-6 sm:grid-cols-9 gap-2`,children:[Fe.map(e=>{let t=d===e.id;return(0,H.jsx)(`button`,{type:`button`,onClick:()=>i(e.id),className:`relative h-10 rounded-xl border transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 dark:focus:ring-offset-dark-50 ${t?`border-gray-900 dark:border-white shadow-md scale-105`:`border-gray-200 dark:border-dark-400 hover:scale-105 hover:shadow-sm`}`,style:{backgroundColor:e.color},"aria-label":u(`settings.appearance.accent.useColor`,{defaultValue:`Use ${e.label} accent`,color:e.label}),title:e.label,children:t&&(0,H.jsx)(O,{className:`absolute inset-0 m-auto h-4 w-4 drop-shadow`,style:{color:e.foreground}})},e.id)}),(0,H.jsxs)(`label`,{className:`relative h-10 rounded-xl border transition-all duration-200 focus-within:outline-none focus-within:ring-2 focus-within:ring-primary-500 focus-within:ring-offset-2 dark:focus-within:ring-offset-dark-50 overflow-hidden cursor-pointer ${d===`custom`?`border-gray-900 dark:border-white shadow-md scale-105`:`border-gray-200 dark:border-dark-400 hover:scale-105 hover:shadow-sm`}`,title:u(`settings.appearance.accent.custom`,{defaultValue:`Custom color`}),"aria-label":u(`settings.appearance.accent.custom`,{defaultValue:`Custom color`}),children:[(0,H.jsx)(`input`,{type:`color`,value:f,onInput:e=>a(e.currentTarget.value),onChange:e=>a(e.target.value),className:`absolute inset-0 h-full w-full cursor-pointer opacity-0`}),(0,H.jsx)(`span`,{className:`absolute inset-0`,style:{backgroundColor:f},"aria-hidden":`true`}),(0,H.jsx)(A,{className:`absolute inset-0 m-auto h-4 w-4 text-white drop-shadow`})]})]}),(0,H.jsxs)(`div`,{className:`mt-5 border-t border-gray-200 pt-5 dark:border-dark-300`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:u(`settings.appearance.accent.behaviorTitle`)}),(0,H.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:u(`settings.appearance.accent.behaviorDescription`)}),(0,H.jsxs)(`div`,{className:`mt-3 grid grid-cols-2 gap-3`,children:[(0,H.jsxs)(`button`,{type:`button`,"aria-pressed":!e.adaptToAccent,onClick:()=>o(!1),className:`rounded-xl border p-3 text-start transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 dark:focus:ring-offset-dark-50 ${e.adaptToAccent?`border-gray-200 bg-white hover:border-gray-300 hover:bg-gray-50 dark:border-dark-300 dark:bg-dark-100 dark:hover:border-dark-400 dark:hover:bg-dark-200`:`border-primary-500 bg-primary-50/70 shadow-sm dark:border-primary-400 dark:bg-primary-950/25`}`,children:[(0,H.jsx)(`span`,{className:`block text-sm font-medium text-gray-900 dark:text-dark-900`,children:u(`settings.appearance.accent.defaultStyle`)}),(0,H.jsx)(`span`,{className:`mt-1 block text-xs leading-snug text-gray-500 dark:text-dark-500`,children:u(`settings.appearance.accent.defaultStyleDescription`)})]}),(0,H.jsxs)(`button`,{type:`button`,"aria-pressed":e.adaptToAccent===!0,onClick:()=>o(!0),className:`rounded-xl border p-3 text-start transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 dark:focus:ring-offset-dark-50 ${e.adaptToAccent?`border-primary-500 bg-primary-50/70 shadow-sm dark:border-primary-400 dark:bg-primary-950/25`:`border-gray-200 bg-white hover:border-gray-300 hover:bg-gray-50 dark:border-dark-300 dark:bg-dark-100 dark:hover:border-dark-400 dark:hover:bg-dark-200`}`,children:[(0,H.jsx)(`span`,{className:`block text-sm font-medium text-gray-900 dark:text-dark-900`,children:u(`settings.appearance.accent.adaptedStyle`)}),(0,H.jsx)(`span`,{className:`mt-1 block text-xs leading-snug text-gray-500 dark:text-dark-500`,children:u(`settings.appearance.accent.adaptedStyleDescription`)})]})]})]})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-md font-medium text-gray-900 dark:text-gray-100 mb-3`,children:u(`settings.appearance.chatInterface.title`)}),(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:u(`settings.appearance.chatInterface.showUsername`)}),(0,H.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u(`settings.appearance.chatInterface.showUsernameDescription`)})]}),(0,H.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,H.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:t.showUsername,onChange:e=>s(e.target.checked)}),(0,H.jsx)(`div`,{className:`w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-primary-300 dark:peer-focus:ring-primary-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-primary-600`})]})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:u(`settings.appearance.chatInterface.followUpSuggestions`)}),(0,H.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u(`settings.appearance.chatInterface.followUpSuggestionsDescription`)})]}),(0,H.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,H.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:t.showFollowUpSuggestions!==!1,onChange:e=>c(e.target.checked)}),(0,H.jsx)(`div`,{className:`w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-primary-300 dark:peer-focus:ring-primary-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-primary-600`})]})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:u(`settings.appearance.chatInterface.hapticFeedback`,{defaultValue:`Haptic feedback (Android)`})}),(0,H.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u(`settings.appearance.chatInterface.hapticFeedbackDescription`,{defaultValue:`Use subtle vibration for important mobile actions`})})]}),(0,H.jsxs)(`label`,{className:`relative inline-flex shrink-0 cursor-pointer items-center`,children:[(0,H.jsx)(`input`,{type:`checkbox`,"data-testid":`haptic-feedback-toggle`,"aria-label":u(`settings.appearance.chatInterface.hapticFeedback`,{defaultValue:`Haptic feedback (Android)`}),className:`peer sr-only`,checked:t.hapticFeedbackEnabled===!0,onChange:e=>l(e.target.checked)}),(0,H.jsx)(`div`,{className:`peer h-6 w-11 rounded-full bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-primary-300 peer-checked:bg-primary-600 after:absolute after:start-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:border after:border-gray-300 after:bg-white after:content-[''] after:transition-all peer-checked:after:translate-x-full peer-checked:after:border-white dark:border-gray-600 dark:bg-gray-700 dark:peer-focus:ring-primary-800 rtl:peer-checked:after:-translate-x-full`})]})]})]})]}),(0,H.jsx)(Je,{})]})}function Ze(){let{t:e,i18n:t}=r(),{sessions:n,setSessionArchived:i,deleteSession:a}=Ae(),o=n.filter(e=>e.archived);return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:e(`settings.data.archivedChats.title`)}),o.length===0?(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`settings.data.archivedChats.empty`)}):(0,H.jsx)(`div`,{className:`divide-y divide-gray-100 rounded-xl border border-gray-200 dark:divide-dark-300 dark:border-dark-300`,children:o.map(n=>(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`p`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,children:n.title}),(0,H.jsx)(`p`,{className:`text-[11px] tabular-nums text-gray-400 dark:text-dark-500`,children:xe(n.updatedAt,t.language)})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,H.jsxs)(z,{variant:`ghost`,size:`sm`,onClick:()=>i(n.id,!1),className:`h-8 gap-1.5 px-2 text-xs`,title:e(`settings.data.archivedChats.unarchive`),children:[(0,H.jsx)(oe,{className:`h-3.5 w-3.5`}),e(`settings.data.archivedChats.unarchive`)]}),(0,H.jsx)(z,{variant:`ghost`,size:`sm`,onClick:()=>{window.confirm(e(`chat.session.deleteConfirm`))&&a(n.id)},className:`h-8 w-8 p-0 text-red-500 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20`,title:e(`chat.session.deleteChat`),children:(0,H.jsx)(ee,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function Qe({sessionCount:e,loading:t,importing:n,showImportOptions:i,mergeStrategy:a,importResult:o,importFileInputRef:s,onExportData:c,onImportFileSelect:l,onClearAllHistory:u,onMergeStrategyChange:d,onConfirmImport:f,onCancelImport:p,onDismissImportResult:m}){let{t:h}=r();return(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:h(`settings.data.title`)}),(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:h(`settings.data.export`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3 flex-1`,children:h(`settings.data.exportDescription`)}),(0,H.jsx)(z,{onClick:c,variant:`outline`,size:`sm`,className:`w-full`,children:h(`settings.data.exportAll`)})]}),(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:h(`settings.data.import`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3 flex-1`,children:h(`settings.data.importDescription`)}),(0,H.jsx)(`input`,{ref:s,type:`file`,accept:`.json`,onChange:l,className:`hidden`}),(0,H.jsx)(z,{onClick:()=>s.current?.click(),variant:`outline`,size:`sm`,className:`w-full`,disabled:n,children:h(n?`settings.data.importing`:`settings.data.importData`)})]}),(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:h(`settings.data.clearSessions`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3 flex-1`,children:h(`settings.data.clearSessionsDescription`)}),(0,H.jsx)(z,{onClick:u,variant:`outline`,size:`sm`,className:`w-full text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 border-red-200 hover:border-red-300 dark:border-red-800 dark:hover:border-red-700`,disabled:e===0||t,children:t?h(`settings.data.clearing`):h(`settings.data.clearAll`,{count:e})})]})]}),i&&(0,H.jsxs)(`div`,{className:`mt-4 p-4 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg`,children:[(0,H.jsx)(`h5`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-3`,children:h(`settings.data.importOptions`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:h(`settings.data.importOptionsDescription`)}),(0,H.jsxs)(`div`,{className:`space-y-2 mb-4`,children:[(0,H.jsxs)(`label`,{className:`flex items-center`,children:[(0,H.jsx)(`input`,{type:`radio`,name:`mergeStrategy`,value:`skip`,checked:a===`skip`,onChange:e=>d(e.target.value),className:`me-2`}),(0,H.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:h(`settings.data.skipDuplicates`)})]}),(0,H.jsxs)(`label`,{className:`flex items-center`,children:[(0,H.jsx)(`input`,{type:`radio`,name:`mergeStrategy`,value:`overwrite`,checked:a===`overwrite`,onChange:e=>d(e.target.value),className:`me-2`}),(0,H.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:h(`settings.data.overwrite`)})]})]}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(z,{onClick:f,size:`sm`,disabled:n,children:h(n?`settings.data.importing`:`settings.data.import`)}),(0,H.jsx)(z,{onClick:p,variant:`outline`,size:`sm`,children:h(`common.cancel`)})]})]}),o&&(0,H.jsxs)(`div`,{className:`mt-4 p-4 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg`,children:[(0,H.jsx)(`h5`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:h(`settings.data.importResults`)}),(0,H.jsxs)(`div`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1`,children:[(0,H.jsxs)(`div`,{children:[h(`settings.data.preferences`),`:`,` `,o.preferences.imported?h(`settings.data.imported`):h(`settings.data.failed`)]}),(0,H.jsxs)(`div`,{children:[h(`settings.data.sessions`),`:`,` `,o.sessions.imported,` `,h(`settings.data.importedLabel`),`,`,o.sessions.skipped,` `,h(`settings.data.skipped`)]}),(0,H.jsxs)(`div`,{children:[h(`settings.data.documents`),`:`,` `,o.documents.imported,` `,h(`settings.data.importedLabel`),`,`,` `,o.documents.skipped,` `,h(`settings.data.skipped`)]}),(o.sessions.errors.length>0||o.documents.errors.length>0)&&(0,H.jsxs)(`div`,{className:`mt-2`,children:[(0,H.jsxs)(`p`,{className:`font-medium`,children:[h(`settings.data.errors`),`:`]}),o.sessions.errors.map((e,t)=>(0,H.jsxs)(`p`,{className:`text-red-600 dark:text-red-400`,children:[`• `,e]},`session-${t}`)),o.documents.errors.map((e,t)=>(0,H.jsxs)(`p`,{className:`text-red-600 dark:text-red-400`,children:[`• `,e]},`document-${t}`))]})]}),(0,H.jsx)(z,{onClick:m,variant:`outline`,size:`sm`,className:`mt-2`,children:h(`common.close`)})]})]})]}),(0,H.jsx)(Ze,{})]})}function U({checked:e,onChange:t,disabled:n=!1}){return(0,H.jsxs)(`label`,{className:`flex items-center cursor-pointer`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>t(e.target.checked),disabled:n,className:`sr-only`}),(0,H.jsx)(`div`,{className:R(`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,n?`bg-gray-100 dark:bg-dark-200 opacity-50 cursor-not-allowed`:e?`bg-primary-600 dark:bg-primary-500`:`bg-gray-200 dark:bg-dark-300`),children:(0,H.jsx)(`span`,{className:R(`inline-block h-4 w-4 transform rounded-full bg-white transition-transform`,e?`translate-x-6 rtl:-translate-x-6`:`translate-x-1 rtl:-translate-x-1`)})})]})}function $e({settings:e,effectiveSettings:t,modelOptions:n,status:i,regenerating:a,onSettingChange:o,onReset:s,onRegenerate:c,onSave:l}){let{t:u}=r();return(0,H.jsx)(`div`,{className:`space-y-6`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:u(`settings.documents.title`)}),(0,H.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-50 p-4 rounded-lg border border-gray-200 dark:border-dark-300 space-y-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:u(`settings.documents.embeddings.title`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:u(`settings.documents.embeddings.enable`)})]}),(0,H.jsx)(U,{checked:e.enabled,onChange:e=>o(`enabled`,e)})]}),e.enabled&&(0,H.jsxs)(`div`,{className:`space-y-4 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:u(`settings.documents.embeddings.model`)}),(0,H.jsx)(B,{value:t.model,onChange:e=>o(`model`,e.target.value),options:n}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:u(`settings.documents.embeddings.modelDescription`)})]}),(0,H.jsx)(tt,{label:u(`settings.documents.embeddings.chunkSize`),value:e.chunkSize,min:500,max:2e3,step:100,description:u(`settings.documents.embeddings.chunkSizeDescription`),onChange:e=>o(`chunkSize`,e)}),(0,H.jsx)(tt,{label:u(`settings.documents.embeddings.chunkOverlap`),value:e.chunkOverlap,min:50,max:500,step:50,description:u(`settings.documents.embeddings.chunkOverlapDescription`),onChange:e=>o(`chunkOverlap`,e)}),(0,H.jsx)(tt,{label:u(`settings.documents.embeddings.similarityThreshold`),value:e.similarityThreshold,min:.3,max:.9,step:.05,description:u(`settings.documents.embeddings.similarityDescription`),format:e=>e.toFixed(2),onChange:e=>o(`similarityThreshold`,e)})]})]}),i&&(0,H.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-100 p-4 rounded-lg border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:u(`settings.documents.embeddings.status`)}),(0,H.jsxs)(`div`,{className:`text-sm text-gray-700 dark:text-gray-300 space-y-1`,children:[(0,H.jsxs)(`div`,{children:[u(`settings.documents.embeddings.statusLabel`),`:`,` `,(0,H.jsx)(`span`,{className:i.available?`font-medium text-green-600 dark:text-green-400`:`font-medium text-red-600 dark:text-red-400`,children:i.available?u(`settings.documents.embeddings.available`):u(`settings.documents.embeddings.unavailable`)})]}),(0,H.jsxs)(`div`,{children:[u(`settings.documents.embeddings.model`),`:`,` `,(0,H.jsx)(`span`,{className:`font-medium`,children:i.model})]}),(0,H.jsxs)(`div`,{children:[u(`settings.documents.embeddings.chunksWithEmbeddings`),`:`,` `,(0,H.jsxs)(`span`,{className:`font-medium`,children:[i.chunksWithEmbeddings,` / `,i.totalChunks]})]}),i.totalChunks>0&&(0,H.jsxs)(`div`,{children:[u(`settings.documents.embeddings.coverage`),`:`,` `,(0,H.jsxs)(`span`,{className:`font-medium`,children:[Math.round(i.chunksWithEmbeddings/i.totalChunks*100),`%`]})]})]})]}),(0,H.jsxs)(`div`,{className:`flex justify-between items-center pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsxs)(z,{onClick:s,variant:`outline`,className:`flex items-center gap-2`,children:[(0,H.jsx)(f,{size:16}),u(`settings.generation.resetDefaults`)]}),e.enabled&&i&&i.totalChunks>0&&(0,H.jsxs)(z,{onClick:c,disabled:a,variant:`outline`,className:`flex items-center gap-2 text-orange-600 dark:text-orange-400 border-orange-200 dark:border-orange-600 hover:bg-orange-50 dark:hover:bg-orange-900/20`,children:[(0,H.jsx)(_,{size:16}),u(a?`settings.documents.embeddings.regenerating`:`settings.documents.embeddings.regenerate`)]})]}),(0,H.jsxs)(z,{onClick:l,className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{size:16}),u(`settings.saveSettings`)]})]}),(0,H.jsx)(et,{})]})})}function et(){let{t:e}=r(),t=He(),[n,i]=(0,V.useState)(``),{data:a}=Be({queryKey:[`knowledge-collections`],queryFn:async()=>{let[e,t]=await Promise.all([L.getCollections(),L.getDocuments()]);return{collections:e.success&&e.data?e.data:[],documents:t.success&&t.data?t.data:[]}}}),{collections:o=[],documents:s=[]}=a??{},c=()=>t.invalidateQueries({queryKey:[`knowledge-collections`]}),l=async()=>{let e=n.trim();e&&(i(``),(await L.createCollection(e)).success&&await c())},u=async t=>{window.confirm(e(`settings.documents.collections.deleteConfirm`))&&(await L.deleteCollection(t)).success&&await c()},d=async(e,t)=>{(await L.setDocumentCollection(e,t)).success&&await c()};return(0,H.jsxs)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`h4`,{className:`text-md font-medium text-gray-900 dark:text-gray-100 mb-1`,children:e(`settings.documents.collections.title`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:e(`settings.documents.collections.description`)}),(0,H.jsxs)(`div`,{className:`mb-3 flex gap-2`,children:[(0,H.jsx)(`input`,{value:n,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l()},placeholder:e(`settings.documents.collections.namePlaceholder`),className:`flex-1 rounded-lg border border-gray-200 bg-white px-3 py-1.5 text-sm text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-dark-300 dark:bg-dark-50 dark:text-dark-900`}),(0,H.jsx)(z,{size:`sm`,onClick:()=>void l(),disabled:!n.trim(),children:e(`settings.documents.collections.create`)})]}),o.length>0&&(0,H.jsx)(`div`,{className:`mb-4 flex flex-wrap gap-1.5`,children:o.map(t=>(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1 text-xs text-gray-700 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-800`,children:[(0,H.jsx)(E,{className:`h-3 w-3`}),t.name,(0,H.jsx)(`span`,{className:`tabular-nums text-gray-400 dark:text-dark-500`,children:t.documentCount??0}),(0,H.jsx)(`button`,{onClick:()=>void u(t.id),className:`text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:e(`common.delete`),children:(0,H.jsx)(te,{className:`h-3 w-3`})})]},t.id))}),s.length>0&&o.length>0&&(0,H.jsx)(`div`,{className:`divide-y divide-gray-100 rounded-xl border border-gray-200 dark:divide-dark-300 dark:border-dark-300`,children:s.map(t=>(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-2`,children:[(0,H.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-sm text-gray-900 dark:text-dark-900`,children:t.filename}),(0,H.jsxs)(`select`,{value:t.collectionId??``,onChange:e=>void d(t.id,e.target.value||null),className:`rounded-lg border border-gray-200 bg-white px-2 py-1 text-xs text-gray-700 focus:outline-none dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,H.jsx)(`option`,{value:``,children:e(`settings.documents.collections.none`)}),o.map(e=>(0,H.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]},t.id))})]})}function tt({label:e,value:t,min:n,max:r,step:i,description:a,format:o=e=>String(e),onChange:s}){return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[e,`: `,o(t)]}),(0,H.jsx)(`input`,{type:`range`,min:n,max:r,step:i,value:t,onChange:e=>s(Number(e.target.value)),className:`w-full range-slider`}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:a})]})}function nt({generationOptions:e,embeddingSettings:t,effectiveEmbeddingSettings:n,embeddingModelOptions:i,embeddingStatus:a,onGenerationOptionChange:o,onEmbeddingSettingsChange:s,onResetGenerationOptions:c,onSaveGenerationOptions:l,onResetEmbeddingSettings:u,onSaveEmbeddingSettings:d}){let{t:p}=r(),[m,h]=(0,V.useState)(!1),g=(0,V.useId)();return(0,H.jsx)(`div`,{className:`space-y-6`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:p(`settings.generation.title`)}),(0,H.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-6`,children:p(`settings.generation.description`)}),(0,H.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white dark:border-dark-300 dark:bg-dark-100`,children:[(0,H.jsxs)(`button`,{type:`button`,"aria-expanded":m,"aria-controls":g,onClick:()=>h(e=>!e),className:`flex w-full items-center justify-between gap-4 p-4 text-left`,children:[(0,H.jsxs)(`span`,{children:[(0,H.jsx)(`span`,{className:`block text-sm font-medium text-gray-900 dark:text-gray-100`,children:p(`settings.generation.advancedSettings`)}),(0,H.jsx)(`span`,{className:`mt-1 block text-xs text-gray-500 dark:text-gray-400`,children:p(`settings.generation.advancedSettingsDescription`)})]}),(0,H.jsx)(b,{className:R(`h-4 w-4 flex-shrink-0 text-gray-500 transition-transform`,m&&`rotate-180`)})]}),m&&(0,H.jsxs)(`div`,{id:g,className:`space-y-6 border-t border-gray-200 p-4 dark:border-dark-300`,children:[(0,H.jsxs)(rt,{title:p(`settings.generation.coreParameters`),children:[(0,H.jsx)(W,{label:p(`settings.generation.temperature`),hint:`(0.0-2.0)`,min:0,max:2,step:.1,value:e.temperature,placeholder:`0.8`,description:p(`settings.generation.temperatureDescription`),onChange:e=>o(`temperature`,e)}),(0,H.jsx)(W,{label:p(`settings.generation.topP`),hint:`(0.0-1.0)`,min:0,max:1,step:.05,value:e.top_p,placeholder:`0.9`,description:p(`settings.generation.topPDescription`),onChange:e=>o(`top_p`,e)}),(0,H.jsx)(W,{label:p(`settings.generation.topK`),hint:`(1-100)`,min:1,max:100,value:e.top_k,placeholder:`40`,integer:!0,description:p(`settings.generation.topKDescription`),onChange:e=>o(`top_k`,e)}),(0,H.jsx)(W,{label:p(`settings.generation.minP`),hint:`(0.0-1.0)`,min:0,max:1,step:.05,value:e.min_p,placeholder:`0.0`,description:p(`settings.generation.minPDescription`),onChange:e=>o(`min_p`,e)})]}),(0,H.jsxs)(rt,{title:p(`settings.generation.generationControl`),children:[(0,H.jsx)(W,{label:p(`settings.generation.maxTokens`),min:-1,max:4096,value:e.num_predict,placeholder:`128`,integer:!0,description:p(`settings.generation.maxTokensDescription`),onChange:e=>o(`num_predict`,e)}),(0,H.jsx)(W,{label:p(`settings.generation.repeatPenalty`),hint:`(0.0-2.0)`,min:0,max:2,step:.1,value:e.repeat_penalty,placeholder:`1.1`,description:p(`settings.generation.repeatPenaltyDescription`),onChange:e=>o(`repeat_penalty`,e)}),(0,H.jsx)(W,{label:p(`settings.generation.contextLength`),min:512,max:32768,step:512,value:e.num_ctx,placeholder:`2048`,integer:!0,description:p(`settings.generation.contextLengthDescription`),onChange:e=>o(`num_ctx`,e)}),(0,H.jsx)(W,{label:p(`settings.generation.seed`),hint:`(${p(`settings.generation.optional`)})`,value:e.seed,placeholder:p(`settings.generation.random`),integer:!0,description:p(`settings.generation.seedDescription`),onChange:e=>o(`seed`,e)})]}),(0,H.jsxs)(rt,{title:p(`settings.generation.advancedOptions`),children:[(0,H.jsx)(W,{label:p(`settings.generation.presencePenalty`),hint:`(-2.0-2.0)`,min:-2,max:2,step:.1,value:e.presence_penalty,placeholder:`0.0`,description:p(`settings.generation.presencePenaltyDescription`),onChange:e=>o(`presence_penalty`,e)}),(0,H.jsx)(W,{label:p(`settings.generation.frequencyPenalty`),hint:`(-2.0-2.0)`,min:-2,max:2,step:.1,value:e.frequency_penalty,placeholder:`0.0`,description:p(`settings.generation.frequencyPenaltyDescription`),onChange:e=>o(`frequency_penalty`,e)}),(0,H.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,H.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[p(`settings.generation.stopSequences`),(0,H.jsxs)(`span`,{className:`text-xs text-gray-500 ms-1`,children:[`(`,p(`settings.generation.commaSeparated`),`)`]})]}),(0,H.jsx)(`input`,{type:`text`,value:e.stop?.join(`, `)??``,onChange:e=>o(`stop`,e.target.value?e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean):void 0),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white dark:bg-dark-200 text-gray-900 dark:text-gray-100`,placeholder:`\\\\n, ###, STOP`}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:p(`settings.generation.stopSequencesDescription`)})]})]}),(0,H.jsxs)(`div`,{className:`flex justify-between items-center pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,H.jsxs)(z,{onClick:c,variant:`outline`,className:`flex items-center gap-2`,children:[(0,H.jsx)(f,{size:16}),p(`settings.generation.resetDefaults`)]}),(0,H.jsxs)(z,{onClick:l,className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{size:16}),p(`settings.generation.saveOptions`)]})]})]})]}),(0,H.jsx)(`div`,{className:`mt-6`,children:(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:p(`settings.generation.embeddingSettings`)}),(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:p(`settings.generation.enableEmbeddings`)}),(0,H.jsx)(U,{checked:t.enabled,onChange:e=>s(`enabled`,e)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:p(`settings.documents.embeddings.model`)}),(0,H.jsx)(B,{value:n.model,onChange:e=>s(`model`,e.target.value),options:i,disabled:!t.enabled})]}),(0,H.jsx)(it,{label:p(`settings.documents.embeddings.chunkSize`),hint:p(`settings.documents.embeddings.chunkSizeInTokens`),value:t.chunkSize,min:1,disabled:!t.enabled,onChange:e=>s(`chunkSize`,e)}),(0,H.jsx)(it,{label:p(`settings.documents.embeddings.chunkOverlap`),hint:p(`settings.documents.embeddings.chunkOverlapInTokens`),value:t.chunkOverlap,min:0,disabled:!t.enabled,onChange:e=>s(`chunkOverlap`,e)}),(0,H.jsx)(it,{label:p(`settings.documents.embeddings.similarityThreshold`),value:t.similarityThreshold,min:0,max:1,step:.01,disabled:!t.enabled,onChange:e=>s(`similarityThreshold`,e)})]}),a&&(0,H.jsxs)(`div`,{className:`mt-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,H.jsxs)(`span`,{className:`text-gray-700 dark:text-gray-300`,children:[p(`settings.documents.embeddings.status`),`:`]}),(0,H.jsx)(`span`,{className:`font-medium text-gray-900 dark:text-gray-100`,children:a.available?p(`settings.documents.embeddings.available`):p(`settings.documents.embeddings.unavailable`)})]}),a.available&&(0,H.jsxs)(`div`,{className:`flex items-center justify-between text-sm mt-1`,children:[(0,H.jsxs)(`span`,{className:`text-gray-700 dark:text-gray-300`,children:[p(`settings.documents.embeddings.chunksWithEmbeddings`),`:`]}),(0,H.jsxs)(`span`,{className:`font-medium text-gray-900 dark:text-gray-100`,children:[a.chunksWithEmbeddings,` /`,` `,a.totalChunks]})]})]}),(0,H.jsxs)(`div`,{className:`flex justify-between items-center mt-4`,children:[(0,H.jsxs)(z,{onClick:u,variant:`outline`,className:`flex items-center gap-2`,children:[(0,H.jsx)(f,{size:16}),p(`settings.generation.resetDefaults`)]}),(0,H.jsxs)(z,{onClick:d,className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{size:16}),p(`settings.saveSettings`)]})]})]})})]})})}function rt({title:e,children:t}){return(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`h4`,{className:`text-md font-medium text-gray-900 dark:text-gray-100 mb-4`,children:e}),(0,H.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:t})]})}function W({label:e,value:t,placeholder:n,description:r,hint:i,min:a,max:o,step:s,integer:c=!1,onChange:l}){return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[e,i&&(0,H.jsx)(`span`,{className:`text-xs text-gray-500 ms-1`,children:i})]}),(0,H.jsx)(`input`,{type:`number`,min:a,max:o,step:s,value:t??``,placeholder:n,onChange:e=>l(e.target.value?c?parseInt(e.target.value):parseFloat(e.target.value):void 0),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white dark:bg-dark-200 text-gray-900 dark:text-gray-100`}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:r})]})}function it({label:e,value:t,min:n,max:r,step:i,hint:a,disabled:o,onChange:s}){return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[e,a&&(0,H.jsx)(`span`,{className:`text-xs text-gray-500 ms-1`,children:a})]}),(0,H.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:t,onChange:e=>s(Number(e.target.value)),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white dark:bg-dark-200 text-gray-900 dark:text-gray-100`,disabled:o})]})}function at({loading:e,settings:t,effectiveSettings:n,models:i,plugins:a,sizes:o,qualities:s,styles:c,onSettingChange:l,onModelChange:u,onReset:d,onSave:p}){let{t:m}=r(),h=be(i,n.model,n.pluginId);return(0,H.jsx)(`div`,{className:`space-y-6`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:m(`settings.imageGen.title`)}),(0,H.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-6`,children:m(`settings.imageGen.description`)}),e?(0,H.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,H.jsx)(j,{className:`h-8 w-8 animate-spin text-primary-500`}),(0,H.jsx)(`span`,{className:`ms-3 text-gray-600 dark:text-gray-400`,children:m(`settings.imageGen.loadingProviders`)})]}):i.length===0?(0,H.jsx)(`div`,{className:`rounded-lg border border-yellow-200 bg-yellow-500/10 p-4 dark:border-yellow-800 dark:bg-yellow-900/20`,children:(0,H.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,H.jsx)(k,{className:`h-5 w-5 text-yellow-600 dark:text-yellow-400 mt-0.5`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-ink`,children:m(`settings.imageGen.noProviders`)}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-ink-muted`,children:m(`settings.imageGen.noProvidersDescription`)})]})]})}):(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`settings.imageGen.enable`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:m(`settings.imageGen.enableDescription`)})]}),(0,H.jsx)(U,{checked:t.enabled,onChange:e=>l(`enabled`,e)})]})}),(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-4`,children:m(`settings.imageGen.configuration`)}),(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:m(`settings.imageGen.model`)}),(0,H.jsx)(B,{value:h?_e(h):``,onChange:e=>{let t=i.find(t=>_e(t)===e.target.value);t&&u(t.model,t.plugin)},disabled:!t.enabled,options:[{value:``,label:m(`settings.model.selectModel`)},...i.map(e=>({value:_e(e),label:`${e.model} (${e.plugin})`,key:`${e.plugin}:${e.model}`}))]}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:m(`settings.imageGen.modelDescription`)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:h?.config?.size_label||m(`settings.imageGen.size`)}),(0,H.jsx)(B,{value:n.size,onChange:e=>l(`size`,e.target.value),disabled:!t.enabled||o.length===0,options:[...o.length>0?o.map(e=>({value:e,label:e})):[{value:`1024x1024`,label:`1024x1024`},{value:`1792x1024`,label:`1792x1024`},{value:`1024x1792`,label:`1024x1792`}]]}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:m(`settings.imageGen.sizeDescription`)})]}),s.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:m(`settings.imageGen.quality`)}),(0,H.jsx)(B,{value:n.quality,onChange:e=>l(`quality`,e.target.value),disabled:!t.enabled,options:s.map(e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)}))}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:m(`settings.imageGen.qualityDescription`)})]}),c.length>0&&(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:m(`settings.imageGen.style`)}),(0,H.jsx)(B,{value:n.style,onChange:e=>l(`style`,e.target.value),disabled:!t.enabled,options:c.map(e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)}))}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:m(`settings.imageGen.styleDescription`)})]})]})]}),a.length>0&&(0,H.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:m(`settings.imageGen.availableProviders`)}),(0,H.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:a.map(e=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 p-2 bg-white dark:bg-dark-100 rounded border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-green-500`}),(0,H.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:e.name}),(0,H.jsxs)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[`(`,e.models?.length||0,` `,m(`settings.imageGen.models`),`)`]})]},e.id))})]}),(0,H.jsxs)(`div`,{className:`flex justify-between items-center pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,H.jsxs)(z,{onClick:d,variant:`outline`,className:`flex items-center gap-2`,children:[(0,H.jsx)(f,{size:16}),m(`common.reset`)]}),(0,H.jsxs)(z,{onClick:p,className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{size:16}),m(`settings.saveSettings`)]})]})]})]})})}function ot({models:e,selectedModel:t,selectedProviderType:n,selectedProviderId:i,systemMessage:a,tempSystemMessage:o,loading:s,preferences:c,currentVisionModel:l,visionModelOptions:u,currentTaskModel:d,autoTitleTaskModelOptions:f,updatingAllModels:p,updateProgress:m,onModelChange:h,onSystemMessageChange:g,onSystemMessageSave:_,onAutoTitleChange:v,onAutoTitleTaskModelChange:y,onVisionModelChange:b,onUpdateAllModels:x}){let{t:S}=r(),C={model:t,providerType:n,providerId:i},w=Te(e,C),T=t?Se(w,C):``,E=De(w,C);return(0,H.jsx)(`div`,{className:`space-y-6`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:S(`settings.model.title`)}),(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:S(`settings.model.defaultModel`)}),(0,H.jsx)(B,{value:T,onChange:h,options:[{value:``,label:S(`settings.model.selectModel`)},...w.map(e=>({value:Ee(e),label:e.isLegacySelection?`${e.name} (provider not recorded${e.isUnavailable?`, unavailable`:``})`:e.isPersona?`${e.personaName} (${S(`settings.model.persona`)})`:e.isPlugin?`${e.name} (${e.pluginName||e.pluginId}${e.isUnavailable?`, unavailable`:``})`:`${e.name} (Ollama${e.isUnavailable?`, unavailable`:``})`}))]}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:S(`settings.model.defaultModelDescription`)})]}),t&&(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:S(`settings.model.currentModelInfo`)}),(0,H.jsx)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,H.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,H.jsx)(st,{label:`${S(`settings.model.name`)}:`,value:t,truncate:!0}),E?.details&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(st,{label:`${S(`settings.model.size`)}:`,value:E.details.parameter_size}),(0,H.jsx)(st,{label:`${S(`settings.model.family`)}:`,value:E.details.family}),(0,H.jsx)(st,{label:`${S(`settings.model.format`)}:`,value:E.details.format})]})]})})]}),(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:S(`settings.systemMessage.title`)}),(0,H.jsx)(ze,{value:o,onChange:g,placeholder:S(`settings.systemMessage.placeholder`),className:`w-full min-h-[100px] bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,rows:4}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between mt-3`,children:[(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:S(`settings.systemMessage.description`)}),(0,H.jsx)(z,{onClick:_,size:`sm`,disabled:s||o===a,children:S(`common.save`)})]})]})]}),(0,H.jsx)(`div`,{className:`mt-6`,children:(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:S(`settings.model.specializedModels`,{defaultValue:`Specialized Models`})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-5 lg:grid-cols-2`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:S(`settings.model.visionModel`,{defaultValue:`Vision Model`})}),(0,H.jsx)(B,{"data-testid":`vision-model-select`,value:l,onChange:e=>b(e.target.value),options:u}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:S(`settings.model.visionModelDescription`,{defaultValue:`Used automatically whenever the outgoing chat context contains images. Choose a model that supports image input.`})})]}),(0,H.jsxs)(`div`,{className:`lg:border-s lg:border-gray-200 lg:ps-5 dark:lg:border-dark-300`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col pe-4`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:S(`settings.model.autoTitle.enable`)}),(0,H.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:S(`settings.model.autoTitle.enableDescription`)})]}),(0,H.jsx)(U,{checked:c.titleSettings?.autoTitle||!1,onChange:v})]}),c.titleSettings?.autoTitle&&(0,H.jsxs)(`div`,{className:`mt-4`,children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:S(`settings.model.autoTitle.taskModel`)}),(0,H.jsx)(B,{value:d,onChange:e=>y(e.target.value),options:f}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:S(`settings.model.autoTitle.taskModelDescription`)})]})]})]})]})}),(0,H.jsx)(`div`,{className:`mt-6`,children:(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:S(`settings.model.bulkOperations`)}),(0,H.jsx)(`div`,{className:`space-y-3`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:S(`settings.model.updateAll`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:S(`settings.model.updateAllDescription`)}),p&&m&&(0,H.jsx)(ct,{progress:m}),(0,H.jsx)(z,{onClick:x,variant:`outline`,size:`sm`,className:`w-full`,disabled:p||s||e.length===0,children:p?S(`settings.model.updating`):S(`settings.model.updateAllButton`,{count:e.length})})]})})]})})]})})}function st({label:e,value:t,truncate:n=!1}){return(0,H.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-white dark:bg-dark-100 rounded-md border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e}),(0,H.jsx)(`span`,{className:n?`text-sm font-semibold text-gray-900 dark:text-gray-100 truncate ms-2`:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t})]})}function ct({progress:e}){let{t}=r(),n=Math.round(e.current/e.total*100);return(0,H.jsxs)(`div`,{className:`mb-4 space-y-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,H.jsx)(`span`,{className:`text-gray-600 dark:text-dark-600 font-medium`,children:t(`settings.model.updatingModel`,{name:e.modelName,current:e.current,total:e.total})}),(0,H.jsxs)(`span`,{className:`text-primary-600 dark:text-primary-400 font-semibold`,children:[n,`%`]})]}),(0,H.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-3 shadow-subtle`,children:(0,H.jsx)(`div`,{className:`bg-gradient-to-r from-primary-500 to-primary-600 dark:from-primary-400 dark:to-primary-500 h-3 rounded-full transition-all duration-500 ease-out shadow-glow`,style:{width:`${e.current/e.total*100}%`}})}),(0,H.jsxs)(`div`,{className:`text-xs flex items-center justify-between`,children:[(0,H.jsxs)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:[t(`settings.model.status`),`:`,` `,e.status===`starting`?(0,H.jsx)(`span`,{className:`text-accent-500 dark:text-accent-400`,children:t(`settings.model.statusStarting`)}):e.status===`success`?(0,H.jsx)(`span`,{className:`text-success-600 dark:text-success-500`,children:t(`settings.model.statusComplete`)}):e.status===`error`?(0,H.jsxs)(`span`,{className:`text-error-600 dark:text-error-500`,children:[t(`settings.model.statusError`),`: `,e.error]}):``]}),(0,H.jsx)(`span`,{className:`text-gray-400 dark:text-dark-600 text-[10px]`,children:t(`settings.model.modelsProgress`,{current:e.current,total:e.total})})]})]})}var lt=8;function ut(e,t){let n=e.trim();if(!n)return null;let r;try{r=new URL(n)}catch{return`invalid-url`}return r.protocol!==`http:`&&r.protocol!==`https:`?`insecure-url`:t?.toLowerCase().endsWith(`base_url`)&&(r.search||r.hash)?`query-or-fragment`:null}function dt(e){try{return new URL(e.trim()).protocol===`http:`}catch{return!1}}function ft(e){let t=e.toLowerCase();return t===`endpoint`||t===`base_url`||t===`api_url`||t===`models_endpoint`||t.endsWith(`_endpoint`)||t.endsWith(`_base_url`)}function pt(e){let t=e.trim();if(!t.startsWith(`/`)||t.startsWith(`//`)||t.includes(`://`)||t.includes(`\\`)||t.includes(`?`)||t.includes(`#`))return!1;let n=t;for(let e=0;e<=lt;e+=1){let t;try{t=decodeURIComponent(n)}catch{return!1}if(t===n)return!n.includes(`\\`)&&!n.includes(`?`)&&!n.includes(`#`)&&!n.split(`/`).some(e=>e===`.`||e===`..`);if(e===lt)return!1;n=t}return!1}var mt=new Set([`api_mode`,`api_path`,`endpoint`,`base_url`,`api_url`,`image_endpoint`,`embedding_endpoint`,`tts_endpoint`,`model`,`model_id`,`models_endpoint`]);function ht(e){let t=new Set(mt),n=e?.capabilities;for(let e of Object.values(n||{})){let n=e?.config?.endpoint_variable??e?.endpoint_variable;typeof n==`string`&&n.trim()&&t.add(n)}return t}function gt(e,t){return ht(t).has(e)}function _t(e,t){if(e.default!==void 0)return e.default;if(!t)return;if(e.name===`endpoint`||e.name===`api_url`)return t.endpoint||void 0;if(e.name===`base_url`)return t.base_url;if(e.name===`api_path`)return t.api_path;if(e.name===`api_mode`){if(t.api_mode)return t.api_mode;try{return new URL(t.endpoint).pathname.replace(/\/+$/,``).endsWith(`/responses`)?`responses`:`chat_completions`}catch{return`chat_completions`}}let n=t.capabilities;for(let t of Object.values(n||{}))if((t?.config?.endpoint_variable??t?.endpoint_variable)===e.name&&typeof t.endpoint==`string`)return t.endpoint}function vt(e,t){let n=[],r=[];for(let i of e)(gt(i.name,t)?n:r).push(i);return{connection:n,advanced:r}}function yt(e,t){let n={};for(let r of e){let e=t[r.name];n[r.name]=e?.has_value&&!e.is_sensitive?e.value:``}return n}function G(e,t,n,r,i){let a=new Set(e.map(e=>e.name)),o={},s=[];for(let c of n){if(!a.has(c))continue;let n=e.find(e=>e.name===c);if(!n)continue;let l=t[c],u=r[c],d=typeof l==`string`&&l.trim().length===0,f=_t(n,i),p=f!==void 0&&(typeof l==`string`&&typeof f==`string`?l.trim()===f.trim():Object.is(l,f));if(d||p){if(n.sensitive&&u?.has_value)continue;u?.has_value&&s.push(c);continue}o[c]=l}return{variables:o,unset:s}}P(`components:hugging-face-model-browser`);var bt=({plugin:e})=>{let{t}=r(),n=Ne(e=>e.user),i=Ne(e=>e.systemInfo)?.requiresAuth===!1||n?.role===`admin`,{pluginVariables:a,fetchPluginVariables:o,updatePluginVariables:s,resetPluginVariables:c,loadPlugins:l}=Me(),[d,p]=(0,V.useState)({}),[m,_]=(0,V.useState)(!1),[v,y]=(0,V.useState)(!1),[x,S]=(0,V.useState)(new Set),[C,T]=(0,V.useState)({}),[E,D]=(0,V.useState)(new Set),[ee,te]=(0,V.useState)(!1),ne=V.useId(),re=V.useId(),O=(0,V.useMemo)(()=>e.variables||[],[e.variables]),k=(0,V.useMemo)(()=>ht(e),[e]),A=(0,V.useMemo)(()=>i?O:O.filter(e=>!k.has(e.name)),[i,k,O]),j=(0,V.useMemo)(()=>a[e.id]||{},[a,e.id]),M=(0,V.useMemo)(()=>vt(A,e),[e,A]);(0,V.useEffect)(()=>{o(e.id)},[o,e.id]);let ie=JSON.stringify(j),ae=(0,V.useRef)(null);(0,V.useEffect)(()=>{let t=A.map(e=>`${e.name}:${e.type}`).join(`|`),n=`${e.id}:${t}:${ie}`;if(ae.current===n)return;ae.current=n;let r=JSON.parse(ie);p(e=>{let t=yt(A,r);for(let n of E)n in e&&(t[n]=e[n]);return t})},[E,e.id,A,ie]);let oe=async()=>{let n={};for(let r of A){if(!E.has(r.name))continue;let i=d[r.name],a=typeof i==`string`&&i.trim().length===0,o=j[r.name],s=_t(r,e);if(a&&r.required&&s===void 0&&!(r.sensitive&&o?.has_value)){n[r.name]=t(`pluginManager.variables.required`,`A value is required`);continue}if(ft(r.name)&&typeof i==`string`&&!a){let e=ut(i,r.name);e===`invalid-url`?n[r.name]=t(`pluginManager.variables.invalidUrl`,`Enter a valid full API endpoint URL, for example https://provider.example/v1/chat/completions`):e===`insecure-url`?n[r.name]=t(`pluginManager.variables.insecureUrl`,`API endpoints must use HTTP or HTTPS.`):e===`query-or-fragment`&&(n[r.name]=t(`pluginManager.variables.invalidBaseUrl`,`Base URLs cannot contain a query string or fragment.`))}if(r.name===`api_path`&&typeof i==`string`&&i.length>0&&!pt(i)&&(n[r.name]=t(`pluginManager.variables.invalidApiPath`,`Must start with / and contain no URL, query, fragment, or .. segment`)),r.type===`number`&&!a){let e=Number(i);r.min!==void 0&&e<r.min&&(n[r.name]=`Min: ${r.min}`),r.max!==void 0&&e>r.max&&(n[r.name]=`Max: ${r.max}`)}r.type===`string`&&typeof i==`string`&&i.length>2048&&(n[r.name]=t(`pluginManager.variables.tooLong`,`Value is too long`))}if(T(n),Object.keys(n).length>0)return;let r=G(A,d,E,j,e),i=new Set(E),a=Object.fromEntries([...Object.keys(r.variables).map(e=>[e,!0]),...r.unset.map(e=>[e,!0])]);if(Object.keys(r.variables).length===0&&r.unset.length===0){D(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),T(e=>{let t={...e};for(let e of i)delete t[e];return t}),g.success(t(`pluginManager.variables.saved`,`Variables saved`));return}_(!0);try{await s(e.id,r.variables,r.unset)?(Object.keys(a).some(e=>k.has(e))&&await l(),p(e=>{let t={...e};for(let e of A)e.sensitive&&i.has(e.name)&&(t[e.name]=``);return t}),S(e=>{let t=new Set(e);for(let e of A)e.sensitive&&i.has(e.name)&&t.delete(e.name);return t}),D(e=>{let t=new Set(e);for(let e of i)t.delete(e);return t}),T(e=>{let t={...e};for(let e of i)delete t[e];return t}),g.success(t(`pluginManager.variables.saved`,`Variables saved`))):g.error(t(`pluginManager.variables.saveFailed`,`Failed to save variables`))}finally{_(!1)}},se=async()=>{y(!0);try{if(!await c(e.id)){g.error(t(`pluginManager.variables.resetFailed`,`Failed to reset variables`));return}A.some(e=>k.has(e.name))&&await l(),p(yt(A,{})),D(new Set),T({}),S(new Set),g.success(t(`pluginManager.variables.reset`,`Variables reset to defaults`))}finally{y(!1)}},N=(e,t)=>{p(n=>({...n,[e]:t})),D(t=>new Set(t).add(e)),T(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},ce=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=e=>{let t=A.indexOf(e),n=`${re}-${t}`;return{controlId:n,descriptionId:`${n}-description`,errorId:`${n}-error`,warningId:`${n}-http-warning`}},F=t=>{if(!ft(t.name))return!1;let n=d[t.name],r=_t(t,e),i=typeof n==`string`&&n.trim()?n:r;return typeof i==`string`&&dt(i)},ue=n=>{let r=d[n.name],i=n.sensitive??!1,a=x.has(n.name),o=j[n.name],{controlId:s,descriptionId:c,errorId:l,warningId:u}=P(n),f=!!C[n.name],p=F(n),g=n.name===`endpoint`||n.name===`api_url`,_=[n.description||g?c:void 0,p?u:void 0,f?l:void 0].filter(Boolean).join(` `)||void 0,y=_t(n,e),b=y===void 0?t(`pluginManager.variables.inherited`,`Use provider default`):t(`pluginManager.variables.inheritedValue`,{defaultValue:`Use provider default ({{value}})`,value:String(y)}),S=R(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-white dark:bg-dark-100`,`border-gray-300 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`focus:outline-none focus:ring-2 focus:ring-blue-500/20`);switch(n.type){case`boolean`:return(0,H.jsxs)(`select`,{id:s,value:r===``?``:String(!!r),onChange:e=>N(n.name,e.target.value===``?``:e.target.value===`true`),className:S,"aria-invalid":f,"aria-describedby":_,disabled:m||v,children:[(0,H.jsx)(`option`,{value:``,children:b}),(0,H.jsx)(`option`,{value:`true`,children:t(`pluginManager.variables.enabled`,`Enabled`)}),(0,H.jsx)(`option`,{value:`false`,children:t(`pluginManager.variables.disabled`,`Disabled`)})]});case`select`:return(0,H.jsxs)(`select`,{id:s,value:String(r??``),onChange:e=>N(n.name,e.target.value),className:S,"aria-invalid":f,"aria-describedby":_,disabled:m||v,children:[(0,H.jsx)(`option`,{value:``,children:b}),(n.options||[]).map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))]});case`number`:return(0,H.jsx)(`input`,{id:s,type:`number`,value:r===``?``:Number(r),min:n.min,max:n.max,placeholder:b,onChange:e=>N(n.name,e.target.value===``?``:Number(e.target.value)),className:S,"aria-invalid":f,"aria-describedby":_,disabled:m||v});default:return(0,H.jsxs)(`div`,{className:`relative`,children:[(0,H.jsx)(`input`,{id:s,type:i&&!a?`password`:`text`,value:i&&o?.has_value&&r===``?``:String(r??``),placeholder:i&&o?.has_value?t(`pluginManager.variables.sensitiveSet`,`Value is set (enter new value to change)`):b,onChange:e=>N(n.name,e.target.value),className:R(S,i&&`pr-10`),"aria-invalid":f,"aria-describedby":_,disabled:m||v}),i&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>ce(n.name),"aria-controls":s,"aria-label":a?t(`pluginManager.variables.hideValue`,{defaultValue:`Hide {{label}} value`,label:n.label}):t(`pluginManager.variables.showValue`,{defaultValue:`Show {{label}} value`,label:n.label}),disabled:m||v,className:`absolute end-2 top-1/2 -translate-y-1/2 p-1 text-gray-400 hover:text-gray-600 disabled:cursor-not-allowed disabled:opacity-50 dark:hover:text-gray-300`,children:a?(0,H.jsx)(le,{className:`w-4 h-4`}):(0,H.jsx)(h,{className:`w-4 h-4`})})]})}},I=e=>{let{controlId:n,descriptionId:r,errorId:i,warningId:a}=P(e),o=e.name===`endpoint`||e.name===`api_url`,s=F(e);return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`label`,{htmlFor:n,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:[o?t(`pluginManager.variables.fullApiEndpoint`,`Full API endpoint URL`):e.label,e.required&&(0,H.jsx)(`span`,{"aria-hidden":`true`,className:`text-red-500 ml-1`,children:`*`})]}),(e.description||o)&&(0,H.jsxs)(`p`,{id:r,className:`text-xs text-gray-500 dark:text-gray-400 mb-1`,children:[e.description,e.description&&o&&` `,o&&t(`pluginManager.variables.endpointHelp`,`Enter the complete request URL, including its operation path (for example, /v1/chat/completions), not only the provider base URL.`)]}),ue(e),s&&(0,H.jsxs)(`p`,{id:a,role:`status`,className:`mt-1 flex items-start gap-1 text-xs text-amber-700 dark:text-amber-400`,children:[(0,H.jsx)(w,{"aria-hidden":`true`,className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,H.jsx)(`span`,{children:t(`pluginManager.variables.httpWarning`,`HTTP does not encrypt credentials or traffic. Use it only on a trusted network.`)})]}),C[e.name]&&(0,H.jsx)(`p`,{id:i,role:`alert`,className:`text-xs text-red-500 mt-1`,children:C[e.name]})]},e.name)};return(0,H.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-gray-200 dark:border-gray-700`,children:[M.connection.length>0&&(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:t(`pluginManager.variables.connection`,`Connection`)}),M.connection.map(I)]}),M.advanced.length>0&&(0,H.jsxs)(`div`,{className:R(M.connection.length>0&&`mt-4 border-t pt-4`,`border-gray-200 dark:border-gray-700`),children:[(0,H.jsxs)(`button`,{type:`button`,"aria-expanded":ee,"aria-controls":ne,onClick:()=>te(e=>!e),className:`flex w-full items-center justify-between rounded-md py-1 text-left text-sm font-medium text-gray-700 hover:text-gray-950 dark:text-gray-300 dark:hover:text-white`,children:[(0,H.jsxs)(`span`,{children:[t(`pluginManager.variables.advanced`,`Advanced parameters`),` (`,M.advanced.length,`)`]}),(0,H.jsx)(b,{className:R(`h-4 w-4 transition-transform`,ee&&`rotate-180`)})]}),ee&&(0,H.jsx)(`div`,{id:ne,className:`mt-3 space-y-3`,children:M.advanced.map(I)})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2 mt-4`,children:[(0,H.jsxs)(z,{size:`sm`,onClick:oe,disabled:m||v||E.size===0,className:`gap-1.5`,children:[(0,H.jsx)(u,{className:`w-3.5 h-3.5`}),m?t(`pluginManager.variables.saving`,`Saving...`):t(`pluginManager.variables.save`,`Save`)]}),(0,H.jsxs)(z,{variant:`outline`,size:`sm`,onClick:se,disabled:m||v,className:`gap-1.5`,children:[(0,H.jsx)(f,{className:`w-3.5 h-3.5`}),t(`pluginManager.variables.resetDefaults`,`Reset to Defaults`)]})]})]})};function xt({plugins:e,loading:t,uploading:n,error:i,hasKeys:a,showUploadForm:o,showJsonForm:s,jsonInput:c,fileInputRef:l,expandedPluginId:u,pluginApiKeys:d,showApiKey:f,savingApiKey:m,refreshingPluginIds:h,onClearError:g,onShowUploadFormChange:_,onShowJsonFormChange:v,onJsonInputChange:y,onFileUpload:b,onJsonSubmit:x,onExpandedPluginChange:C,onPluginApiKeyChange:w,onShowApiKeyChange:T,onActivatePlugin:E,onDeletePlugin:D,onExportPlugin:ee,onSaveApiKey:ne,onDeleteApiKey:re,onRefreshModels:O}){let{t:k}=r(),A=Ne(e=>e.user),M=Ne(e=>e.systemInfo)?.requiresAuth===!1||A?.role===`admin`,[ie,ae]=(0,V.useState)(``),[oe,se]=(0,V.useState)(null),N=(0,V.useId)(),le=(0,V.useMemo)(()=>e.filter(e=>we(e,ie)),[e,ie]),P=oe&&e.some(e=>e.id===oe)?oe:e[0]?.id??null,F=e.find(e=>e.id===P)??null,ue=e=>{e!==P&&(C(null),se(e))};return(0,H.jsx)(`div`,{className:`space-y-6`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`div`,{className:`mb-4`,children:[(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:k(`settings.plugins.providerConnections`,{defaultValue:`Provider connections`})}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-400`,children:k(`settings.plugins.providerConnectionsDescription`,{defaultValue:`Connect, configure, and inspect model providers through plugins.`})})]}),i&&(0,H.jsx)(`div`,{className:`p-4 bg-primary-50/80 dark:bg-primary-950/25 border border-primary-200 dark:border-primary-800/50 rounded-lg mb-4`,children:(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsx)(`p`,{className:`text-primary-800 dark:text-primary-200`,children:i}),(0,H.jsx)(z,{variant:`ghost`,size:`sm`,onClick:g,className:`text-primary-700 hover:text-primary-900 dark:text-primary-300 dark:hover:text-primary-100`,children:(0,H.jsx)(te,{className:`h-4 w-4`})})]})}),M&&(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300 mb-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:k(`settings.plugins.addNew`)}),(0,H.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,H.jsxs)(z,{variant:`outline`,size:`sm`,onClick:()=>_(!o),disabled:t||n,children:[(0,H.jsx)(S,{className:`h-4 w-4 me-2`}),k(`settings.plugins.upload`)]}),(0,H.jsx)(z,{variant:`outline`,size:`sm`,onClick:()=>v(!s),disabled:t,children:k(`settings.plugins.addJson`)})]})]}),o&&(0,H.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300 mb-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center space-x-4`,children:[(0,H.jsx)(`input`,{ref:l,type:`file`,accept:`.json,.zip`,onChange:b,className:`flex-1 p-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-100 text-gray-900 dark:text-dark-800 file:me-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-medium file:bg-gray-100 file:text-gray-700 dark:file:bg-dark-200 dark:file:text-dark-700 hover:file:bg-gray-200 dark:hover:file:bg-dark-300`,disabled:n}),(0,H.jsx)(z,{variant:`outline`,size:`sm`,onClick:()=>_(!1),disabled:n,children:k(`common.cancel`)})]}),n&&(0,H.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-2`,children:k(`settings.plugins.uploading`)})]}),s&&(0,H.jsx)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsx)(`textarea`,{value:c,onChange:e=>y(e.target.value),placeholder:k(`settings.plugins.jsonPlaceholder`),className:`w-full h-32 p-3 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-100 text-gray-900 dark:text-dark-800 placeholder:text-gray-400 dark:placeholder:text-dark-500 font-mono text-sm`,disabled:t}),(0,H.jsxs)(`div`,{className:`flex items-center justify-end space-x-2`,children:[(0,H.jsx)(z,{variant:`outline`,size:`sm`,onClick:()=>{v(!1),y(``)},children:k(`common.cancel`)}),(0,H.jsx)(z,{size:`sm`,onClick:x,disabled:!c.trim()||t,children:k(`settings.plugins.install`)})]})]})})]}),(0,H.jsx)(`div`,{"data-testid":`provider-workspace`,className:`overflow-hidden rounded-xl border border-gray-200 bg-white dark:border-dark-300 dark:bg-dark-100`,children:(0,H.jsxs)(`div`,{className:`grid min-h-[30rem] grid-cols-1 lg:grid-cols-[minmax(15rem,0.8fr)_minmax(0,1.6fr)]`,children:[(0,H.jsxs)(`section`,{"data-testid":`provider-list`,"aria-label":k(`settings.plugins.providers`,{defaultValue:`Providers`}),className:`border-b border-gray-200 dark:border-dark-300 lg:border-b-0 lg:border-e`,children:[(0,H.jsxs)(`div`,{className:`border-b border-gray-200 p-4 dark:border-dark-300`,children:[(0,H.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:k(`settings.plugins.providers`,{defaultValue:`Providers`})}),(0,H.jsx)(`span`,{className:`rounded-full bg-gray-100 px-2 py-0.5 text-xs text-gray-600 dark:bg-dark-200 dark:text-gray-300`,children:e.length})]}),(0,H.jsx)(`label`,{htmlFor:N,className:`sr-only`,children:k(`settings.plugins.searchProviders`,{defaultValue:`Search providers`})}),(0,H.jsxs)(`div`,{className:`relative`,children:[(0,H.jsx)(p,{"aria-hidden":`true`,className:`absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,H.jsx)(`input`,{id:N,type:`search`,value:ie,onChange:e=>ae(e.target.value),placeholder:k(`settings.plugins.searchProviders`,{defaultValue:`Search providers`}),className:`w-full rounded-lg border border-gray-300 bg-white py-2 pe-3 ps-9 text-sm text-gray-900 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:border-dark-300 dark:bg-dark-50 dark:text-gray-100`})]})]}),(0,H.jsx)(`div`,{className:`max-h-[32rem] space-y-2 overflow-y-auto p-3`,children:t&&e.length===0?(0,H.jsxs)(`div`,{className:`p-6 text-center text-sm text-gray-500 dark:text-gray-400`,children:[(0,H.jsx)(j,{className:`mx-auto mb-2 h-5 w-5 animate-spin`}),k(`settings.plugins.loading`)]}):e.length===0?(0,H.jsxs)(`div`,{className:`p-6 text-center`,children:[(0,H.jsx)(ce,{className:`mx-auto mb-3 h-9 w-9 text-gray-400`}),(0,H.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:k(`settings.plugins.noPlugins`)}),(0,H.jsx)(`p`,{className:`mt-1 text-xs text-gray-400 dark:text-gray-500`,children:k(`settings.plugins.noPluginsDescription`)})]}):le.length===0?(0,H.jsx)(`p`,{className:`p-6 text-center text-sm text-gray-500 dark:text-gray-400`,children:k(`settings.plugins.noProvidersFound`,{defaultValue:`No providers match your search.`})}):le.map(e=>{let t=P===e.id,n=Ce(e).length;return(0,H.jsx)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:()=>ue(e.id),className:`w-full rounded-xl border p-3 text-start transition-colors ${t?`border-blue-500 bg-blue-50/70 dark:border-blue-500 dark:bg-blue-950/20`:`border-gray-200 hover:border-gray-300 hover:bg-gray-50 dark:border-dark-300 dark:hover:border-dark-400 dark:hover:bg-dark-50`}`,children:(0,H.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,H.jsx)(`span`,{"aria-hidden":`true`,className:`mt-1.5 h-2.5 w-2.5 shrink-0 rounded-full ${e.active?`bg-green-500`:`bg-gray-400 dark:bg-gray-500`}`}),(0,H.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`span`,{className:`sr-only`,children:[e.active?k(`settings.plugins.activeLabel`):k(`settings.plugins.inactive`),`.`,` `]}),(0,H.jsx)(`span`,{className:`block truncate text-sm font-medium text-gray-900 dark:text-gray-100`,children:e.name}),(0,H.jsxs)(`span`,{className:`mt-0.5 block text-xs capitalize text-gray-500 dark:text-gray-400`,children:[e.type,` · `,n,` `,k(`settings.plugins.models`)]})]})]})},e.id)})})]}),(0,H.jsx)(`section`,{"data-testid":`provider-detail`,className:`min-w-0 p-4 sm:p-5`,children:F?(0,H.jsx)(St,{plugin:F,loading:t,hasApiKey:a[F.id]||!1,expanded:u===F.id,apiKey:d[F.id]||``,showApiKey:f[F.id]||!1,savingApiKey:m===F.id,refreshingModels:!!h[F.id],canManagePlugin:M,onExpand:()=>C(u===F.id?null:F.id),onActivate:()=>E(F.id),onExport:()=>ee(F.id),onDelete:()=>D(F.id),onRefreshModels:()=>O(F.id),onApiKeyChange:e=>w(F.id,e),onShowApiKeyChange:e=>T(F.id,e),onSaveApiKey:()=>ne(F.id),onDeleteApiKey:()=>re(F.id)}):(0,H.jsx)(`div`,{className:`flex min-h-[24rem] items-center justify-center text-center`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(ce,{className:`mx-auto mb-3 h-10 w-10 text-gray-400`}),(0,H.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:k(`settings.plugins.selectProvider`,{defaultValue:`Select a provider`})}),(0,H.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-gray-400`,children:k(`settings.plugins.selectProviderDescription`,{defaultValue:`Choose a provider to inspect its connection and model catalog.`})})]})})})]})})]})})}function St({plugin:e,loading:t,hasApiKey:n,expanded:i,apiKey:a,showApiKey:o,savingApiKey:s,refreshingModels:c,canManagePlugin:u,onExpand:f,onActivate:p,onExport:m,onDelete:h,onRefreshModels:g,onApiKeyChange:_,onShowApiKeyChange:v,onSaveApiKey:y,onDeleteApiKey:x}){let{t:S}=r(),w=!!(e.auth?.header||e.auth?.key_env),T=ht(e),E=u?e.variables||[]:(e.variables||[]).filter(e=>!T.has(e.name)),D=E.length>0,te=w||D,re=(0,V.useId)(),k=Ce(e),A=e.base_url||e.endpoint;return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 border-b border-gray-200 pb-4 dark:border-dark-300`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-full ${e.active?`bg-green-500`:`bg-gray-400 dark:bg-gray-500`}`}),(0,H.jsx)(`h4`,{className:`truncate text-lg font-semibold text-gray-900 dark:text-gray-100`,children:e.name})]}),(0,H.jsxs)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-gray-400`,children:[e.id,` · `,(0,H.jsx)(`span`,{className:`capitalize`,children:e.type}),w&&n&&(0,H.jsxs)(`span`,{className:`text-green-600`,children:[` `,`· `,S(`settings.plugins.apiKeySet`)]})]})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[te&&(0,H.jsxs)(z,{variant:`outline`,size:`sm`,onClick:f,"aria-expanded":i,"aria-controls":re,title:S(`settings.plugins.configure`),className:n?`text-green-600`:``,children:[w?(0,H.jsx)(C,{className:`h-4 w-4`}):(0,H.jsx)(l,{className:`h-4 w-4`}),S(`settings.plugins.configure`),i?(0,H.jsx)(ne,{className:`h-3 w-3`}):(0,H.jsx)(b,{className:`h-3 w-3`})]}),(0,H.jsx)(z,{variant:`outline`,size:`sm`,onClick:p,disabled:t,className:e.active?`border-green-300 text-green-600`:``,children:e.active?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(O,{className:`h-4 w-4`}),S(`settings.plugins.deactivate`)]}):S(`settings.plugins.activate`)}),u&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(z,{variant:`ghost`,size:`sm`,onClick:m,disabled:t,title:S(`settings.plugins.exportPlugin`,`Export plugin`),className:`px-2`,children:(0,H.jsx)(d,{className:`h-4 w-4`})}),(0,H.jsx)(z,{variant:`ghost`,size:`sm`,onClick:h,disabled:t,className:`px-2 text-red-600 hover:bg-red-50 hover:text-red-700`,title:S(`settings.plugins.deletePlugin`,`Delete plugin`),children:(0,H.jsx)(ee,{className:`h-4 w-4`})})]})]})]}),(0,H.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,H.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:S(`settings.plugins.status`,{defaultValue:`Status`})}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-gray-900 dark:text-gray-100`,children:e.active?S(`settings.plugins.activeLabel`):S(`settings.plugins.inactive`)})]}),(0,H.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:S(`settings.plugins.models`)}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-gray-900 dark:text-gray-100`,children:k.length})]}),(0,H.jsxs)(`div`,{className:`min-w-0 rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:S(`settings.plugins.defaultEndpoint`,{defaultValue:`Default endpoint`})}),(0,H.jsx)(`p`,{className:`mt-1 truncate text-sm text-gray-900 dark:text-gray-100`,title:A,children:A})]})]})]}),i&&te&&(0,H.jsxs)(`div`,{id:re,children:[w&&(0,H.jsx)(K,{plugin:e,hasApiKey:n,apiKey:a,showApiKey:o,savingApiKey:s,onApiKeyChange:_,onShowApiKeyChange:v,onSaveApiKey:y,onDeleteApiKey:x}),D&&(0,H.jsxs)(`div`,{className:`mt-4 rounded-lg border border-gray-200 bg-gray-50 p-4 dark:border-dark-300 dark:bg-dark-50`,children:[(0,H.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,H.jsx)(l,{className:`h-4 w-4 text-gray-500`}),(0,H.jsxs)(`h5`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:[S(`settings.plugins.providerSettings`),` (`,E.length,`)`]})]}),(0,H.jsx)(bt,{plugin:e},e.id)]})]}),(0,H.jsx)(Ct,{catalog:k,canRefresh:Oe(e),refreshing:c,onRefresh:g})]})}function Ct({catalog:e,canRefresh:t,refreshing:n,onRefresh:i}){let{t:a}=r();return(0,H.jsxs)(`section`,{"data-testid":`provider-model-catalog`,className:`mt-5`,children:[(0,H.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h5`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:a(`settings.plugins.modelCatalog`,{defaultValue:`Model catalog`})}),(0,H.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:a(`settings.plugins.modelCatalogDescription`,{defaultValue:`Discovered and configured models for this provider and its capabilities.`})})]}),t&&(0,H.jsxs)(z,{variant:`outline`,size:`sm`,onClick:i,disabled:n,"aria-busy":n,children:[n?(0,H.jsx)(j,{className:`h-4 w-4 animate-spin`}):(0,H.jsx)(m,{className:`h-4 w-4`}),a(`settings.plugins.refreshModels`,{defaultValue:`Refresh models`})]})]}),e.length===0?(0,H.jsx)(`div`,{className:`rounded-lg border border-dashed border-gray-300 p-6 text-center text-sm text-gray-500 dark:border-dark-300 dark:text-gray-400`,children:a(`settings.plugins.noModelsConfigured`,{defaultValue:`No models are configured for this provider.`})}):(0,H.jsx)(`div`,{className:`max-h-[26rem] overflow-auto rounded-lg border border-gray-200 dark:border-dark-300`,children:(0,H.jsxs)(`table`,{className:`w-full min-w-[24rem] text-start text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 z-10 bg-gray-50 text-xs uppercase tracking-wide text-gray-500 dark:bg-dark-50 dark:text-gray-400`,children:(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-start font-medium`,children:a(`settings.plugins.modelId`,{defaultValue:`Model ID`})}),(0,H.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-start font-medium`,children:a(`settings.plugins.capabilities`,{defaultValue:`Capabilities`})})]})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-gray-200 dark:divide-dark-300`,children:e.map(e=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`td`,{className:`px-3 py-2.5 font-mono text-xs text-gray-900 dark:text-gray-100`,children:e.id}),(0,H.jsx)(`td`,{className:`px-3 py-2.5`,children:(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.capabilities.map(e=>(0,H.jsx)(`span`,{className:`rounded-md bg-blue-50 px-2 py-0.5 text-xs text-blue-700 dark:bg-blue-950/30 dark:text-blue-300`,children:a(`settings.plugins.capability.${e.toLowerCase()}`,{defaultValue:e})},e))})})]},e.id))})]})})]})}function K({plugin:e,hasApiKey:t,apiKey:n,showApiKey:i,savingApiKey:a,onApiKeyChange:o,onShowApiKeyChange:s,onSaveApiKey:c,onDeleteApiKey:l}){let{t:u}=r(),d=(0,V.useId)();return(0,H.jsxs)(`div`,{className:`mt-4 p-4 bg-gray-50 dark:bg-dark-50 rounded-lg border border-gray-200 dark:border-dark-300`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,H.jsx)(C,{className:`h-4 w-4 text-gray-500`}),(0,H.jsx)(`h6`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:u(`settings.plugins.apiKeyConfiguration`)})]}),(0,H.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:[u(`settings.plugins.apiKeyDescription`,{name:e.name,defaultValue:`Store a personal API key for {{name}}.`}),e.auth?.key_env&&(0,H.jsxs)(`span`,{className:`block mt-1`,children:[u(`settings.plugins.apiKeyEnvAlternative`),` `,(0,H.jsx)(`code`,{className:`bg-gray-200 dark:bg-dark-200 px-1 rounded`,children:e.auth.key_env}),` `,u(`settings.plugins.environmentVariable`),`.`]})]}),t?(0,H.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{className:`h-4 w-4 text-green-600`}),(0,H.jsx)(`span`,{className:`text-sm text-green-700 dark:text-green-300`,children:u(`settings.plugins.apiKeyConfigured`)})]}),(0,H.jsx)(z,{variant:`outline`,size:`sm`,onClick:l,disabled:a,className:`text-red-600 border-red-300 hover:bg-red-50`,children:a?(0,H.jsx)(j,{className:`h-4 w-4 animate-spin`}):u(`common.remove`)})]}):(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsxs)(`div`,{className:`relative`,children:[(0,H.jsx)(`label`,{htmlFor:d,className:`sr-only`,children:u(`settings.plugins.apiKey.title`)}),(0,H.jsx)(`input`,{id:d,type:i?`text`:`password`,value:n,onChange:e=>o(e.target.value),placeholder:u(`settings.plugins.apiKeyPlaceholder`),disabled:a,className:`w-full p-2 pe-10 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-100 text-gray-900 dark:text-dark-800 placeholder:text-gray-400 dark:placeholder:text-dark-500`}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>s(!i),"aria-controls":d,"aria-label":u(i?`settings.plugins.hideApiKey`:`settings.plugins.showApiKey`),disabled:a,className:`absolute end-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 disabled:cursor-not-allowed disabled:opacity-50`,children:i?(0,H.jsx)(le,{className:`h-4 w-4`}):(0,H.jsx)(h,{className:`h-4 w-4`})})]}),(0,H.jsx)(`div`,{className:`flex justify-end`,children:(0,H.jsx)(z,{size:`sm`,onClick:c,disabled:a||!n.trim(),children:a?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(j,{className:`h-4 w-4 me-2 animate-spin`}),u(`common.saving`)]}):u(`settings.plugins.saveApiKey`)})})]})]})}function wt({loading:e,settings:t,effectiveSettings:n,models:i,plugins:a,voices:o,testing:s,onSettingChange:c,onModelChange:l,onReset:u,onTest:d,onSave:p}){let{t:m}=r(),h=i.find(e=>e.model===n.model&&(!n.pluginId||e.plugin===n.pluginId));return(0,H.jsx)(`div`,{className:`space-y-6`,children:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:m(`settings.tts.title`)}),(0,H.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-6`,children:m(`settings.tts.description`)}),e?(0,H.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,H.jsx)(j,{className:`h-8 w-8 animate-spin text-primary-500`}),(0,H.jsx)(`span`,{className:`ms-3 text-gray-600 dark:text-gray-400`,children:m(`settings.tts.loadingProviders`)})]}):i.length===0?(0,H.jsx)(`div`,{className:`rounded-lg border border-yellow-200 bg-yellow-500/10 p-4 dark:border-yellow-800 dark:bg-yellow-900/20`,children:(0,H.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,H.jsx)(re,{className:`h-5 w-5 text-yellow-600 dark:text-yellow-400 mt-0.5`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-ink`,children:m(`settings.tts.noProviders`)}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-ink-muted`,children:m(`settings.tts.noProvidersDescription`)})]})]})}):(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`settings.tts.enable`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:m(`settings.tts.enableDescription`)})]}),(0,H.jsx)(U,{checked:t.enabled,onChange:e=>c(`enabled`,e)})]})}),(0,H.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`settings.tts.autoPlay`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:m(`settings.tts.autoPlayDescription`)})]}),(0,H.jsx)(U,{checked:t.autoPlay,disabled:!t.enabled,onChange:e=>c(`autoPlay`,e)})]})}),(0,H.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`settings.tts.streamSentences`)}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:m(`settings.tts.streamSentencesDescription`)})]}),(0,H.jsx)(U,{checked:t.streamSentences||!1,disabled:!t.enabled,onChange:e=>c(`streamSentences`,e)})]})}),(0,H.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-4`,children:m(`settings.tts.voiceConfiguration`)}),(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:m(`settings.tts.model`)}),(0,H.jsx)(B,{"aria-label":m(`settings.tts.model`),value:h?ge(h):``,onChange:e=>{let t=i.find(t=>ge(t)===e.target.value);t&&l(t.model,t.plugin)},disabled:!t.enabled,options:[{value:``,label:m(`settings.model.selectModel`)},...i.map(e=>({value:ge(e),label:`${e.model} (${e.plugin})`,key:`${e.plugin}:${e.model}`}))]}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:m(`settings.tts.modelDescription`)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:m(`settings.tts.voice`)}),(0,H.jsx)(B,{"aria-label":m(`settings.tts.voice`),value:n.voice,onChange:e=>c(`voice`,e.target.value),disabled:!t.enabled||o.length===0,options:[{value:``,label:m(`settings.tts.selectVoice`)},...o.map(e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)}))]}),(0,H.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:m(`settings.tts.voiceDescription`)})]})]})]}),a.length>0&&(0,H.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:m(`settings.tts.availableProviders`)}),(0,H.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:a.map(e=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2 p-2 bg-white dark:bg-dark-100 rounded border border-gray-200 dark:border-dark-300`,children:[(0,H.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-green-500`}),(0,H.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:e.name}),(0,H.jsxs)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[`(`,e.models?.length||0,` `,m(`settings.tts.models`),`)`]})]},e.id))})]}),(0,H.jsxs)(`div`,{className:`flex justify-between items-center pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsxs)(z,{onClick:u,variant:`outline`,className:`flex items-center gap-2`,children:[(0,H.jsx)(f,{size:16}),m(`common.reset`)]}),(0,H.jsx)(z,{onClick:d,variant:`outline`,disabled:!t.enabled||!n.model,className:`flex items-center gap-2`,children:s?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(ae,{size:16}),m(`settings.tts.stop`)]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(v,{size:16}),m(`settings.tts.test`)]})})]}),(0,H.jsxs)(z,{onClick:p,className:`flex items-center gap-2`,children:[(0,H.jsx)(O,{size:16}),m(`settings.saveSettings`)]})]})]})]})})}function Tt({preferences:e,sessions:t,loadPreferences:n,loadSessions:r}){let[i,a]=(0,V.useState)(!1),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(`skip`),[u,d]=(0,V.useState)(null),[f,p]=(0,V.useState)(null),m=(0,V.useRef)(null),h=()=>{p(null),m.current&&(m.current.value=``)};return{importing:i,showImportOptions:o,mergeStrategy:c,setMergeStrategy:l,importResult:u,setImportResult:d,importFileInputRef:m,handleExportData:()=>{let n={format:`libre-webui-export`,version:`1.0`,preferences:e,sessions:t,documents:[],exportedAt:new Date().toISOString()},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`libre-webui-export-${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),g.success(`Data exported successfully`)},handleImportFileSelect:e=>{let t=e.target.files?.[0];t&&(p(t),s(!0),d(null))},handleConfirmImport:async()=>{if(f){a(!0);try{let e=await f.text(),t=JSON.parse(e);if(!t.format||t.format!==`libre-webui-export`)throw Error(`Invalid export format. Please use a valid Libre WebUI export file.`);let i=await I.importData(t,c===`overwrite`?`replace`:`merge`);if(i.success&&i.data)d({preferences:{imported:!0,error:null},sessions:{imported:0,skipped:0,errors:[]},documents:{imported:0,skipped:0,errors:[]}}),g.success(`Data imported successfully`),await n(),await r();else throw Error(i.error||`Import failed`)}catch(e){g.error(e instanceof Error?e.message:`Import failed`),d(null)}finally{a(!1),s(!1),h()}}},handleCancelImport:()=>{s(!1),d(null),h()}}}var Et=Ue()||`0.0.0`,Dt=`__current_running_model__`,Ot={enabled:!1,model:`nomic-embed-text`,chunkSize:1e3,chunkOverlap:200,similarityThreshold:.7},kt={enabled:!1,autoPlay:!1,model:``,voice:``,speed:1,pluginId:``,streamSentences:!1},At={enabled:!1,model:``,size:`1024x1024`,quality:`standard`,style:`vivid`,pluginId:``},jt=({isOpen:e,onClose:t})=>{let{models:n,selectedModel:i,selectedProviderType:a,selectedProviderId:o,setSelectedModel:s,systemMessage:c,setSystemMessage:u,clearAllSessions:d,loading:f,sessions:m,loadModels:h,loadSessions:v}=Ae(),{theme:y,updateTheme:b,preferences:x,setPreferences:S,loadPreferences:C}=Le(),{plugins:w,isLoading:E,isUploading:ee,error:ne,loadPlugins:O,uploadPlugin:j,deletePlugin:M,activatePlugin:ae,deactivatePlugin:oe,exportPlugin:se,clearError:N,installPlugin:le}=Me(),{t:P}=r(),ge=V.useId(),_e=Te(n,{model:i,providerType:a,providerId:o}),xe={model:x.titleSettings?.taskModel||``,providerType:x.titleSettings?.taskProviderType,providerId:x.titleSettings?.taskProviderId},Ce=Te(n,xe),we=xe.model===Dt?Dt:xe.model?Se(Ce,xe):``,De={model:x.visionModel||``,providerType:x.visionProviderType,providerId:x.visionProviderId},Oe=Te(n,De),Ne=De.model?Se(Oe,De):``,Pe=[{value:``,label:P(`settings.model.selectVisionModel`,{defaultValue:`Use the current chat model`})},...Oe.map(e=>({value:Ee(e),label:e.isLegacySelection?`${e.name} · provider not recorded${e.isUnavailable?` (unavailable)`:``}`:e.isPersona?`${e.personaName||e.name} (persona)`:e.isPlugin?`${e.name} · ${e.pluginName||e.pluginId}${e.isUnavailable?` (unavailable)`:``}`:e.isAgent?`${e.agentName||e.name} · Agent CLI${e.isUnavailable?` (unavailable)`:``}`:`${e.name} · Ollama${e.isUnavailable?` (unavailable)`:``}`}))],Fe=[{value:``,label:P(`settings.model.autoTitle.selectTaskModel`)},{value:Dt,label:`Use current running model`},...Ce.map(e=>({value:Ee(e),label:e.isLegacySelection?`${e.name} · provider not recorded${e.isUnavailable?` (unavailable)`:``}`:e.isPersona?`${e.personaName||e.name} (persona)`:e.isPlugin?`${e.name} · ${e.pluginName||e.pluginId}${e.isUnavailable?` (unavailable)`:``}`:`${e.name} · Ollama${e.isUnavailable?` (unavailable)`:``}`}))],[B,ze]=(0,V.useState)(`appearance`),[Ve,Ue]=(0,V.useState)(``),[We,Ge]=(0,V.useState)(c),[qe,Je]=(0,V.useState)(!1),[Ye,Ze]=(0,V.useState)(null),[U,et]=(0,V.useState)(!1),[tt,rt]=(0,V.useState)(!1),[W,it]=(0,V.useState)(``),st=(0,V.useRef)(null),[ct,lt]=(0,V.useState)(null),[ut,dt]=(0,V.useState)({}),[ft,pt]=(0,V.useState)({}),[mt,ht]=(0,V.useState)(null),[gt,_t]=(0,V.useState)({}),[vt,yt]=(0,V.useState)(x.generationOptions||{}),[G,bt]=(0,V.useState)(x.embeddingSettings||Ot),[St,Ct]=(0,V.useState)(!1),[K,jt]=(0,V.useState)(x.ttsSettings||kt),[Mt,Nt]=(0,V.useState)(!1),Pt=(0,V.useRef)(null),[q,Ft]=(0,V.useState)(x.imageGenSettings||At),{importing:It,showImportOptions:Lt,mergeStrategy:Rt,setMergeStrategy:zt,importResult:Bt,setImportResult:Vt,importFileInputRef:Ht,handleExportData:Ut,handleImportFileSelect:Wt,handleConfirmImport:Gt,handleCancelImport:Kt}=Tt({preferences:x,sessions:m,loadPreferences:C,loadSessions:v}),J=He(),{data:qt={}}=Be({queryKey:[`plugin-credentials`],queryFn:async()=>{let e=await pe.getCredentials();if(!e.success||!e.data)return{};let t={};for(let n of e.data)t[n.plugin_id]=n.has_api_key;return t},enabled:e}),{data:Jt=[]}=Be({queryKey:[`embedding-models`],queryFn:async()=>{let e=await ue.getModels();return e.success&&e.data?e.data:[]},enabled:e}),Y=(0,V.useMemo)(()=>{let e=Jt.find(e=>e.id===G.model||e.rawModel===G.model);return e&&e.id!==G.model?{...G,model:e.id}:G},[Jt,G]),{data:Yt=null}=Be({queryKey:[`embedding-status`],queryFn:async()=>{let e=await L.getEmbeddingStatus();return e.success&&e.data?e.data:null},enabled:e}),{data:Xt,isLoading:Zt}=Be({queryKey:[`tts-data`],queryFn:async()=>{let[e,t]=await Promise.all([F.getModels(),F.getPlugins()]);return{models:e.success&&e.data?e.data:[],plugins:t.success&&t.data?t.data:[]}},enabled:e}),X=(0,V.useMemo)(()=>Xt?.models??[],[Xt]),Qt=Xt?.plugins??[],$t=(0,V.useMemo)(()=>fe(X,K.model,K.pluginId),[X,K.model,K.pluginId]),Z=(0,V.useMemo)(()=>{if(!$t)return K;let e=me(X,K.model,K.pluginId);return e&&K.pluginId===e.plugin?K:{...K,model:$t.model,pluginId:$t.plugin,voice:$t.config?.default_voice||``}},[$t,X,K]),en=(0,V.useMemo)(()=>me(X,Z.model,Z.pluginId)?.config?.voices??[],[Z,X]),{data:tn,isLoading:nn}=Be({queryKey:[`image-gen-data`],queryFn:async()=>{let[e,t]=await Promise.all([de.getModels(),de.getPlugins()]);return{models:e.success&&e.data?e.data:[],plugins:t.success&&t.data?t.data:[]}},enabled:e}),Q=(0,V.useMemo)(()=>tn?.models??[],[tn]),rn=(0,V.useMemo)(()=>tn?.plugins??[],[tn]),$=(0,V.useMemo)(()=>ve(Q,q.model,q.pluginId),[Q,q.model,q.pluginId]),an=(0,V.useMemo)(()=>{if(!$)return q;let e=be(Q,q.model,q.pluginId);return e&&q.pluginId===e.plugin?q:{...q,model:$.model,pluginId:$.plugin,size:ye($.config?.sizes,q.size,$.config?.default_size,`1024x1024`),quality:ye($.config?.qualities,q.quality,$.config?.default_quality,`standard`),style:ye($.config?.styles,q.style,$.config?.default_style,`vivid`)}},[Q,q,$]),on=$?.config?.sizes??[],sn=$?.config?.qualities??[],cn=$?.config?.styles??[],ln=(0,V.useRef)(!1),un=(0,V.useRef)(c);(0,V.useEffect)(()=>{if(!e){ln.current=!1;return}ln.current&&un.current===c||(ln.current=!0,un.current=c,Ge(c),yt(x.generationOptions||{}),bt(x.embeddingSettings||Ot),jt(x.ttsSettings||kt),Ft(x.imageGenSettings||At))},[e,x.embeddingSettings,x.generationOptions,x.imageGenSettings,x.ttsSettings,c]);let dn=(0,V.useRef)(!1);(0,V.useEffect)(()=>{if(!e){dn.current=!1;return}dn.current||(dn.current=!0,O(),h())},[e,O,h]),(0,V.useEffect)(()=>{if(!e)return;let n=document.body.style.overflow,r=e=>{e.key===`Escape`&&t()};return document.body.style.overflow=`hidden`,document.addEventListener(`keydown`,r),()=>{document.body.style.overflow=n,document.removeEventListener(`keydown`,r)}},[e,t]);let fn=async e=>{let t=ut[e];if(!t?.trim()){g.error(`Please enter an API key`);return}ht(e);try{let n=await pe.setApiKey(e,t.trim());n.success?(g.success(`API key saved successfully`),await J.invalidateQueries({queryKey:[`plugin-credentials`]}),await O(),await J.invalidateQueries({queryKey:[`image-gen-data`]}),dt(t=>({...t,[e]:``})),pt(t=>({...t,[e]:!1}))):g.error(n.error||`Failed to save API key`)}catch{g.error(`Failed to save API key`)}finally{ht(null)}},pn=async e=>{ht(e);try{let t=await pe.deleteApiKey(e);t.success?(g.success(`API key removed`),await J.invalidateQueries({queryKey:[`plugin-credentials`]}),await O(),await J.invalidateQueries({queryKey:[`image-gen-data`]}),dt(t=>({...t,[e]:``}))):g.error(t.error||`Failed to remove API key`)}catch{g.error(`Failed to remove API key`)}finally{ht(null)}},mn=(e,t)=>{let n=me(X,e,t);n&&jt(r=>({...r,model:e,pluginId:t,voice:n.config?.default_voice||r.voice}))},hn=(e,t)=>{let n=be(Q,e,t);n&&Ft(t=>({...t,model:e,pluginId:n.plugin,size:ye(n.config?.sizes,t.size,n.config?.default_size,`1024x1024`),quality:ye(n.config?.qualities,t.quality,n.config?.default_quality,`standard`),style:ye(n.config?.styles,t.style,n.config?.default_style,`vivid`)}))},gn=(e,t)=>{jt(n=>({...n,[e]:t}))},_n=async()=>{try{let e=await I.updatePreferences({ttsSettings:Z});e.success&&e.data&&(S(e.data),g.success(`TTS settings saved successfully`))}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`Failed to save TTS settings: `+t)}},vn=async()=>{if(Mt){let e=Pt.current;e&&(e.pause(),e.currentTime=0,Pt.current=null),Nt(!1);return}Nt(!0);try{let e=await F.generateBase64({model:Z.model||`tts-1`,pluginId:Z.pluginId,input:`Hello! This is a test of the text-to-speech system.`,voice:Z.voice||`alloy`,speed:Z.speed||1,response_format:$t?.config?.default_format});if(e.success&&e.data?.audio){let t=`data:${e.data.mimeType};base64,${e.data.audio}`,n=new Audio(t);Pt.current=n,n.onended=()=>{Nt(!1),Pt.current=null},n.onerror=()=>{g.error(`Failed to play audio`),Nt(!1),Pt.current=null},await n.play()}else throw Error(e.message||`Failed to generate speech`)}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`TTS test failed: `+t),Nt(!1)}},yn=()=>{jt({enabled:!1,autoPlay:!1,model:X[0]?.model||``,voice:X[0]?.config?.default_voice||``,speed:1,pluginId:X[0]?.plugin||``,streamSentences:!1})},bn=(e,t)=>{Ft(n=>({...n,[e]:t}))},xn=async()=>{try{let e=await I.updatePreferences({imageGenSettings:an});e.success&&e.data&&(S(e.data),g.success(`Image generation settings saved successfully`))}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`Failed to save image generation settings: `+t)}},Sn=()=>{Ft({enabled:!1,model:Q[0]?.model||``,size:Q[0]?.config?.default_size||`1024x1024`,quality:Q[0]?.config?.default_quality||`standard`,style:Q[0]?.config?.default_style||`vivid`,pluginId:Q[0]?.plugin||``})},Cn=async()=>{try{Ct(!0),(await L.regenerateEmbeddings()).success&&(g.success(`Embeddings regenerated successfully`),await J.invalidateQueries({queryKey:[`embedding-status`]}))}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`Failed to regenerate embeddings: `+t)}finally{Ct(!1)}},wn=async e=>{try{let t=await I.updatePreferences(e);t.success&&t.data&&(S(t.data),g.success(`Settings updated successfully`))}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`Failed to update settings: `+t)}},Tn=async e=>{let t=e.target.files?.[0];t&&(await j(t),et(!1),st.current&&(st.current.value=``),await h(),await J.invalidateQueries({queryKey:[`image-gen-data`]}))},En=async()=>{try{let e=JSON.parse(W);await le(e),rt(!1),it(``),await h(),await J.invalidateQueries({queryKey:[`image-gen-data`]})}catch{N(),g.error(`Invalid JSON format`)}},Dn=async e=>{w.find(t=>t.id===e)?.active?await oe(e):await ae(e),await h(),await J.invalidateQueries({queryKey:[`image-gen-data`]})},On=async e=>{if(!gt[e]){_t(t=>({...t,[e]:!0}));try{let t=await pe.discoverModels(e);if(!t.success||!t.data){g.error(t.error||P(`settings.plugins.modelCatalogRefreshFailed`));return}await Promise.all([O(),h()]);let{outcome:n,models:r,reason:i}=t.data;n===`updated`?g.success(P(`settings.plugins.modelCatalogUpdated`,{count:r.length})):n===`unchanged`?g.success(P(`settings.plugins.modelCatalogUnchanged`)):n===`missing_credentials`?g.error(i||P(`settings.plugins.modelCatalogNeedsApiKey`)):g.error(i?`${P(`settings.plugins.modelCatalogUnavailable`)} ${i}`:P(`settings.plugins.modelCatalogUnavailable`))}catch(e){g.error(je(e,P(`settings.plugins.modelCatalogRefreshFailed`)))}finally{_t(t=>{let n={...t};return delete n[e],n})}}},kn=async e=>{window.confirm(`Are you sure you want to delete this plugin?`)&&(await M(e),await h(),await J.invalidateQueries({queryKey:[`image-gen-data`]}))},An=async e=>{await se(e)};if(!e)return null;let jn=e=>{let t=Le.getState().theme,n=Ie({...t,mode:e});b(n)},Mn=e=>{let t=Le.getState().theme,n=Ie({...t,accent:e});b(n)},Nn=e=>{let t=Le.getState().theme,n=Ie({...t,accent:`custom`,customAccent:e});b(n)},Pn=e=>{let t=Le.getState().theme,n=Ie({...t,adaptToAccent:e});b(n)},Fn=e=>{S({showUsername:e}),I.updatePreferences({showUsername:e}).catch(e=>{let t=e instanceof Error?e.message:String(e);g.error(`Failed to update settings: `+t)})},In=e=>{S({showFollowUpSuggestions:e}),I.updatePreferences({showFollowUpSuggestions:e}).catch(e=>{let t=e instanceof Error?e.message:String(e);g.error(`Failed to update settings: `+t)})},Ln=e=>{S({hapticFeedbackEnabled:e}),e&&Re(`selection`),I.updatePreferences({hapticFeedbackEnabled:e}).catch(e=>{let t=e instanceof Error?e.message:String(e);g.error(`Failed to update settings: `+t)})},Rn=e=>{if(!e.target.value){Ae.setState({selectedModel:``,selectedProviderType:null,selectedProviderId:null}),wn({defaultModel:``,defaultProviderType:null,defaultProviderId:null});return}let t=ke(_e,e.target.value);t&&(s(t.model,t.providerType,t.providerId),S({defaultModel:t.model,defaultProviderType:t.providerType,defaultProviderId:t.providerId}),g.success(`Default model updated`))},zn=e=>{Ge(e.target.value)},Bn=()=>{u(We),wn({systemMessage:We}),g.success(`System message updated`)},Vn=async()=>{window.confirm(`Are you sure you want to delete all chat history? This action cannot be undone.`)&&(await d(),g.success(`All chat sessions deleted`))},Hn=async()=>{Je(!0),Ze(null),he.pullAllModelsStream(e=>{Ze(e)},()=>{Je(!1),Ze(null),g.success(`All models updated successfully!`),h()},e=>{Je(!1),Ze(null),g.error(`Failed to update models: `+e)})},Un=e=>{let t={...x.titleSettings,autoTitle:e,taskModel:x.titleSettings?.taskModel||``};S({titleSettings:t}),I.updatePreferences({titleSettings:t})},Wn=e=>{if(!e){let e={visionModel:``,visionProviderType:null,visionProviderId:null};S(e),I.updatePreferences(e);return}let t=ke(Oe,e);if(!t?.providerType){g.error(P(`settings.model.visionModelNoProvider`));return}let n={visionModel:t.model,visionProviderType:t.providerType,visionProviderId:t.providerId||null};S(n),I.updatePreferences(n).catch(e=>{let t=e instanceof Error?e.message:String(e);g.error(P(`settings.model.visionModelUpdateFailed`,{error:t}))})},Gn=e=>{let t=e&&e!==Dt?ke(Ce,e):null,n={...x.titleSettings,autoTitle:x.titleSettings?.autoTitle||!1,taskModel:t?.model||e,taskProviderType:t?.providerType||null,taskProviderId:t?.providerType===`plugin`&&t.providerId||null};S({titleSettings:n}),I.updatePreferences({titleSettings:n})},Kn=(e,t)=>{dt(n=>({...n,[e]:t}))},qn=(e,t)=>{pt(n=>({...n,[e]:t}))},Jn=(e,t)=>{yt(n=>({...n,[e]:t}))},Yn=async()=>{try{let e=await I.setGenerationOptions(vt);e.success&&e.data&&(S(e.data),g.success(`Generation options updated successfully`))}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`Failed to update generation options: `+t)}},Xn=async()=>{try{let e=await I.resetGenerationOptions();e.success&&e.data&&(S(e.data),yt(e.data.generationOptions||{}),g.success(`Generation options reset to defaults`))}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`Failed to reset generation options: `+t)}},Zn=(e,t)=>{bt(n=>({...n,[e]:t}))},Qn=[...Jt.map(e=>({value:e.id,label:`${e.name} (${e.pluginName||e.provider})`})),...!Jt.find(e=>e.id===Y.model||e.rawModel===Y.model)&&Y.model?[{value:Y.model,label:`${Y.model} (current)`}]:[]],$n=async()=>{try{let e=await I.setEmbeddingSettings(Y);e.success&&e.data&&(S(e.data),g.success(`Embedding settings updated successfully`))}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`Failed to update embedding settings: `+t)}},er=async()=>{try{let e=await I.resetEmbeddingSettings();e.success&&e.data&&(S(e.data),bt(e.data.embeddingSettings||{}),g.success(`Embedding settings reset to defaults`))}catch(e){let t=e instanceof Error?e.message:String(e);g.error(`Failed to reset embedding settings: `+t)}},tr={appearance:`theme dark light accent color language username follow-up background interface`,data:`export import backup clear history sessions`,about:`version license update`,models:`default model system prompt title vision auto`,generation:`temperature top_p top_k seed tokens context penalty embedding chunk similarity`,documents:`upload pdf rag document embedding`,tts:`voice speech audio speak read aloud`,"image-gen":`image generation size quality style`,plugins:`api key provider connection openai anthropic groq gemini`},nr=Ve.trim().toLowerCase(),rr=e=>!nr||e.label.toLowerCase().includes(nr)||(tr[e.id]||``).includes(nr),ir=[{id:`general`,label:P(`settings.groups.general`,`General`),tabs:[{id:`appearance`,label:P(`settings.tabs.appearance`),icon:A},{id:`data`,label:P(`settings.tabs.data`),icon:ie},{id:`about`,label:P(`settings.tabs.about`),icon:T}]},{id:`chat`,label:P(`settings.groups.chat`,`Chat`),tabs:[{id:`models`,label:P(`settings.tabs.model`),icon:D},{id:`generation`,label:P(`settings.tabs.generation`),icon:l},{id:`documents`,label:P(`settings.tabs.documents`),icon:_}]},{id:`media`,label:P(`settings.groups.media`,`Speech & images`),tabs:[{id:`tts`,label:P(`settings.tabs.tts`),icon:re},{id:`image-gen`,label:P(`settings.tabs.imageGen`),icon:k}]},{id:`connections`,label:P(`settings.groups.connections`,`Connections`),tabs:[{id:`plugins`,label:P(`settings.tabs.plugins`),icon:ce}]}];return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/55 backdrop-blur-sm transition-opacity duration-200`,onClick:t}),(0,H.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-0 sm:p-4 lg:p-6`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":ge,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:(0,H.jsxs)(`div`,{"data-testid":`settings-modal-panel`,className:`flex h-full w-full flex-col overscroll-behavior-contain border border-gray-200/80 bg-surface/95 shadow-2xl backdrop-blur-xl animate-scale-in dark:border-white/10 dark:bg-dark-25/95 sm:max-h-[94vh] sm:max-w-6xl sm:rounded-3xl`,children:[(0,H.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between border-b border-gray-200/70 px-4 py-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:[(0,H.jsx)(`h2`,{id:ge,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950 sm:text-2xl rtl:tracking-normal`,children:P(`settings.title`)}),(0,H.jsx)(z,{variant:`ghost`,size:`sm`,onClick:t,autoFocus:!0,className:`h-9 w-9 touch-manipulation p-0 hover:bg-gray-100 active:bg-gray-200 dark:hover:bg-white/[0.06] dark:active:bg-white/10`,title:P(`common.close`,{defaultValue:`Close`}),children:(0,H.jsx)(te,{className:`h-5 w-5 sm:h-4 sm:w-4`})})]}),(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overscroll-behavior-contain sm:flex-row`,children:[(0,H.jsxs)(`div`,{className:`w-full shrink-0 overflow-x-auto border-b border-gray-200/70 p-2 scrollbar-thin dark:border-white/[0.08] sm:w-56 sm:overflow-x-hidden sm:overflow-y-auto sm:border-b-0 sm:border-e sm:p-3 lg:w-64`,style:{WebkitOverflowScrolling:`touch`},children:[(0,H.jsxs)(`div`,{className:`relative mb-1 hidden sm:block`,children:[(0,H.jsx)(p,{className:`pointer-events-none absolute start-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-ink-subtle`}),(0,H.jsx)(`input`,{type:`search`,value:Ve,onChange:e=>{let t=e.target.value;Ue(t);let n=t.trim().toLowerCase();if(!n)return;let r=ir.flatMap(e=>e.tabs).filter(e=>e.label.toLowerCase().includes(n)||(tr[e.id]||``).includes(n));r.length>0&&!r.some(e=>e.id===B)&&ze(r[0].id)},placeholder:P(`common.search`),className:`w-full rounded-lg border border-transparent bg-black/[0.04] py-1.5 pe-2.5 ps-8 text-[13px] text-ink placeholder:text-ink-subtle focus:border-primary-500/40 focus:outline-none dark:bg-white/[0.05]`})]}),(0,H.jsx)(`nav`,{className:`flex gap-1 sm:flex-col sm:gap-0`,role:`tablist`,"aria-label":P(`settings.title`,`Settings`),children:ir.map(e=>({...e,tabs:e.tabs.filter(rr)})).filter(e=>e.tabs.length>0).map(e=>(0,H.jsxs)(`div`,{className:`flex shrink-0 gap-1 sm:flex-col sm:gap-0.5 sm:pb-2`,children:[(0,H.jsx)(`p`,{"aria-hidden":`true`,className:`hidden px-2.5 pb-1 pt-2 text-[10px] font-medium uppercase tracking-[0.08em] text-ink-subtle sm:block`,children:e.label}),e.tabs.map(e=>{let t=e.icon,n=B===e.id;return(0,H.jsxs)(`button`,{onClick:()=>ze(e.id),className:R(`flex shrink-0 items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-start transition-colors duration-150 touch-manipulation outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40 sm:w-full`,n?`bg-black/[0.06] text-ink dark:bg-white/[0.08]`:`text-ink-muted hover:bg-black/[0.04] hover:text-ink dark:hover:bg-white/[0.05]`),role:`tab`,"aria-selected":n,"aria-controls":`settings-tab-panel`,children:[(0,H.jsx)(t,{className:`h-4 w-4 flex-shrink-0`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`truncate whitespace-nowrap text-[13px]`,children:e.label})]},e.id)})]},e.id))})]}),(0,H.jsx)(`div`,{"data-testid":`settings-scroll-region`,className:`scroll-region min-h-0 flex-1 p-4 scrollbar-thin sm:p-6 lg:p-8`,id:`settings-tab-panel`,role:`tabpanel`,children:(()=>{switch(B){case`appearance`:return(0,H.jsx)(Xe,{theme:y,preferences:x,onThemeChange:jn,onAccentChange:Mn,onCustomAccentChange:Nn,onAdaptToAccentChange:Pn,onShowUsernameChange:Fn,onShowFollowUpsChange:In,onHapticFeedbackChange:Ln});case`models`:return(0,H.jsx)(ot,{models:n,selectedModel:i,selectedProviderType:a,selectedProviderId:o,systemMessage:c,tempSystemMessage:We,loading:f,preferences:x,currentVisionModel:Ne,visionModelOptions:Pe,currentTaskModel:we,autoTitleTaskModelOptions:Fe,updatingAllModels:qe,updateProgress:Ye,onModelChange:Rn,onSystemMessageChange:zn,onSystemMessageSave:Bn,onAutoTitleChange:Un,onAutoTitleTaskModelChange:Gn,onVisionModelChange:Wn,onUpdateAllModels:Hn});case`tts`:return(0,H.jsx)(wt,{loading:Zt,settings:K,effectiveSettings:Z,models:X,plugins:Qt,voices:en,testing:Mt,onSettingChange:gn,onModelChange:mn,onReset:yn,onTest:vn,onSave:_n});case`image-gen`:return(0,H.jsx)(at,{loading:nn,settings:q,effectiveSettings:an,models:Q,plugins:rn,sizes:on,qualities:sn,styles:cn,onSettingChange:bn,onModelChange:hn,onReset:Sn,onSave:xn});case`documents`:return(0,H.jsx)($e,{settings:G,effectiveSettings:Y,modelOptions:Qn,status:Yt,regenerating:St,onSettingChange:Zn,onReset:er,onRegenerate:Cn,onSave:$n});case`plugins`:return(0,H.jsx)(xt,{plugins:w,loading:E,uploading:ee,error:ne,hasKeys:qt,showUploadForm:U,showJsonForm:tt,jsonInput:W,fileInputRef:st,expandedPluginId:ct,pluginApiKeys:ut,showApiKey:ft,savingApiKey:mt,refreshingPluginIds:gt,onClearError:N,onShowUploadFormChange:et,onShowJsonFormChange:rt,onJsonInputChange:it,onFileUpload:Tn,onJsonSubmit:En,onExpandedPluginChange:lt,onPluginApiKeyChange:Kn,onShowApiKeyChange:qn,onActivatePlugin:Dn,onRefreshModels:On,onDeletePlugin:kn,onExportPlugin:An,onSaveApiKey:fn,onDeleteApiKey:pn});case`data`:return(0,H.jsx)(Qe,{sessionCount:m.length,loading:f,importing:It,showImportOptions:Lt,mergeStrategy:Rt,importResult:Bt,importFileInputRef:Ht,onExportData:Ut,onImportFileSelect:Wt,onClearAllHistory:Vn,onMergeStrategyChange:zt,onConfirmImport:Gt,onCancelImport:Kt,onDismissImportResult:()=>Vt(null)});case`about`:return(0,H.jsx)(Ke,{appVersion:Et});case`generation`:return(0,H.jsx)(nt,{generationOptions:vt,embeddingSettings:G,effectiveEmbeddingSettings:Y,embeddingModelOptions:Qn,embeddingStatus:Yt,onGenerationOptionChange:Jn,onEmbeddingSettingsChange:Zn,onResetGenerationOptions:Xn,onSaveGenerationOptions:Yn,onResetEmbeddingSettings:er,onSaveEmbeddingSettings:$n});default:return null}})()})]})]})})]})};export{jt as SettingsModal};