libre-webui 0.19.0 → 0.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/backend/dist/db.d.ts.map +1 -1
  2. package/backend/dist/db.js +2 -0
  3. package/backend/dist/db.js.map +1 -1
  4. package/backend/dist/routes/chat.d.ts.map +1 -1
  5. package/backend/dist/routes/chat.js +41 -3
  6. package/backend/dist/routes/chat.js.map +1 -1
  7. package/backend/dist/services/assistantCompletionService.d.ts +2 -1
  8. package/backend/dist/services/assistantCompletionService.d.ts.map +1 -1
  9. package/backend/dist/services/assistantCompletionService.js +3 -1
  10. package/backend/dist/services/assistantCompletionService.js.map +1 -1
  11. package/backend/dist/services/chatGenerationService.d.ts +2 -1
  12. package/backend/dist/services/chatGenerationService.d.ts.map +1 -1
  13. package/backend/dist/services/chatGenerationService.js +18 -4
  14. package/backend/dist/services/chatGenerationService.js.map +1 -1
  15. package/backend/dist/services/pluginService.d.ts.map +1 -1
  16. package/backend/dist/services/pluginService.js +3 -1
  17. package/backend/dist/services/pluginService.js.map +1 -1
  18. package/backend/dist/services/preferencesService.d.ts.map +1 -1
  19. package/backend/dist/services/preferencesService.js +1 -0
  20. package/backend/dist/services/preferencesService.js.map +1 -1
  21. package/backend/dist/storage.d.ts.map +1 -1
  22. package/backend/dist/storage.js +6 -3
  23. package/backend/dist/storage.js.map +1 -1
  24. package/backend/dist/storageMappers.d.ts +1 -0
  25. package/backend/dist/storageMappers.d.ts.map +1 -1
  26. package/backend/dist/storageMappers.js +3 -0
  27. package/backend/dist/storageMappers.js.map +1 -1
  28. package/backend/dist/types/index.d.ts +4 -0
  29. package/backend/dist/types/index.d.ts.map +1 -1
  30. package/backend/dist/types/index.js.map +1 -1
  31. package/backend/dist/utils/chatContext.d.ts +1 -1
  32. package/backend/dist/utils/chatContext.d.ts.map +1 -1
  33. package/backend/dist/utils/chatContext.js +4 -0
  34. package/backend/dist/utils/chatContext.js.map +1 -1
  35. package/backend/dist/utils/ollamaStreaming.d.ts +1 -0
  36. package/backend/dist/utils/ollamaStreaming.d.ts.map +1 -1
  37. package/backend/dist/utils/ollamaStreaming.js +16 -3
  38. package/backend/dist/utils/ollamaStreaming.js.map +1 -1
  39. package/backend/dist/utils/pluginChatAdapter.d.ts +2 -0
  40. package/backend/dist/utils/pluginChatAdapter.d.ts.map +1 -1
  41. package/backend/dist/utils/pluginChatAdapter.js +9 -1
  42. package/backend/dist/utils/pluginChatAdapter.js.map +1 -1
  43. package/backend/dist/utils/pluginResponse.d.ts +2 -0
  44. package/backend/dist/utils/pluginResponse.d.ts.map +1 -1
  45. package/backend/dist/utils/pluginResponse.js +29 -0
  46. package/backend/dist/utils/pluginResponse.js.map +1 -1
  47. package/backend/dist/utils/pluginStreamAdapter.d.ts.map +1 -1
  48. package/backend/dist/utils/pluginStreamAdapter.js +5 -1
  49. package/backend/dist/utils/pluginStreamAdapter.js.map +1 -1
  50. package/backend/dist/utils/pluginStreaming.d.ts +1 -0
  51. package/backend/dist/utils/pluginStreaming.d.ts.map +1 -1
  52. package/backend/dist/utils/pluginStreaming.js +17 -0
  53. package/backend/dist/utils/pluginStreaming.js.map +1 -1
  54. package/backend/dist/utils/thinkingPhaseTimer.d.ts +2 -0
  55. package/backend/dist/utils/thinkingPhaseTimer.d.ts.map +1 -1
  56. package/backend/dist/utils/thinkingPhaseTimer.js +12 -0
  57. package/backend/dist/utils/thinkingPhaseTimer.js.map +1 -1
  58. package/backend/dist/utils/websocketMessages.d.ts +2 -0
  59. package/backend/dist/utils/websocketMessages.d.ts.map +1 -1
  60. package/backend/dist/utils/websocketMessages.js.map +1 -1
  61. package/backend/dist/websocketServer.d.ts.map +1 -1
  62. package/backend/dist/websocketServer.js +24 -4
  63. package/backend/dist/websocketServer.js.map +1 -1
  64. package/backend/package.json +1 -1
  65. package/frontend/dist/assets/index-B9H3vQ-n.css +1 -0
  66. package/frontend/dist/assets/index-D4LhtFTX.js +38 -0
  67. package/frontend/dist/index.html +9 -9
  68. package/frontend/dist/js/{ArtifactContainer-CjpvtR8G.js → ArtifactContainer-DvuGeXXu.js} +1 -1
  69. package/frontend/dist/js/{ArtifactDemoPage-yrPXLBQo.js → ArtifactDemoPage-BlVBMy6a.js} +1 -1
  70. package/frontend/dist/js/{ArtifactSlideOutPanel-DdsL2AOQ.js → ArtifactSlideOutPanel-CaPMk1Qj.js} +1 -1
  71. package/frontend/dist/js/ChatPage-D4UBhGLk.js +16 -0
  72. package/frontend/dist/js/{FirstTimeSetup-CwLPbHkI.js → FirstTimeSetup-DJiDNTXY.js} +1 -1
  73. package/frontend/dist/js/{GalleryPage-C9DTdo_-.js → GalleryPage-BnaFZERr.js} +1 -1
  74. package/frontend/dist/js/HomePage-BvpoUzGG.js +1 -0
  75. package/frontend/dist/js/{LibreClawPage-B9wWZIz6.js → LibreClawPage-B-6rO5Jl.js} +1 -1
  76. package/frontend/dist/js/{ModelSelector-B0RKEJwC.js → ModelSelector-BV1kuaVg.js} +1 -1
  77. package/frontend/dist/js/{ModelsPage-DJXoIOs8.js → ModelsPage-D5H70fs3.js} +1 -1
  78. package/frontend/dist/js/NotesPage-D9b3JxCx.js +1 -0
  79. package/frontend/dist/js/{PersonasPage--nqoJ-wA.js → PersonasPage-CJOGnyQV.js} +2 -2
  80. package/frontend/dist/js/{PluginUsagePage-BHwm-BBr.js → PluginUsagePage-DHNMWquK.js} +1 -1
  81. package/frontend/dist/js/{RichMessageContent-DYRrXJ75.js → RichMessageContent-C7NG7gs-.js} +1 -1
  82. package/frontend/dist/js/SettingsModal-DEBxDPne.js +1 -0
  83. package/frontend/dist/js/{SystemPage-CHez8h3p.js → SystemPage-BsPen2Qb.js} +1 -1
  84. package/frontend/dist/js/{UserManagementPage-aJhKXQxG.js → UserManagementPage-I9i5r0V3.js} +1 -1
  85. package/frontend/dist/js/{WorkPage-Ccla0MDm.js → WorkPage-e30yqvJe.js} +3 -3
  86. package/frontend/dist/js/{api-DVP8xiYT.js → api-jwjnjqx6.js} +2 -2
  87. package/frontend/dist/js/{appStore-Cw7PmG-J.js → appStore-CLIS0fvz.js} +2 -2
  88. package/frontend/dist/js/{ar-ONXFvOB1.js → ar-B_uYj5Gv.js} +1 -1
  89. package/frontend/dist/js/{authStore-gv_MgDKr.js → authStore-CsCkBmaG.js} +1 -1
  90. package/frontend/dist/js/{bn-BLhREPm6.js → bn-Pd4HHYsG.js} +1 -1
  91. package/frontend/dist/js/chatStore-DRY8C0J1.js +2 -0
  92. package/frontend/dist/js/{cs-Bg8E9fG5.js → cs-CgVXogHE.js} +1 -1
  93. package/frontend/dist/js/{da-ODCU8w4x.js → da-DTUIrClO.js} +1 -1
  94. package/frontend/dist/js/{de-nuGHRJ5N.js → de-CKITtmnY.js} +1 -1
  95. package/frontend/dist/js/{es-DcN_cwum.js → es-DKDhsL9J.js} +1 -1
  96. package/frontend/dist/js/{estree-DJwQLE88.js → estree-CrfVSazx.js} +1 -1
  97. package/frontend/dist/js/{fr-C-L_xGr5.js → fr-CUvNp0pc.js} +1 -1
  98. package/frontend/dist/js/{hi-DUEtwA9G.js → hi-Bwdmc__g.js} +1 -1
  99. package/frontend/dist/js/{html-DdAOfeK4.js → html-BbJLJMaV.js} +1 -1
  100. package/frontend/dist/js/{i18n-xir4Zz7C.js → i18n-ZJQSoIuM.js} +2 -2
  101. package/frontend/dist/js/{id-DNTYhti_.js → id-CWTPw3NJ.js} +1 -1
  102. package/frontend/dist/js/{is-Bx28ymbQ.js → is-4dV6F4Bo.js} +1 -1
  103. package/frontend/dist/js/{it-BjW-JLlS.js → it-8uw2-j2s.js} +1 -1
  104. package/frontend/dist/js/{ja-uThj4Q1w.js → ja-Bl7gd3kp.js} +1 -1
  105. package/frontend/dist/js/{ko-DqgmMYXK.js → ko-C_CYwJnL.js} +1 -1
  106. package/frontend/dist/js/{markdown-RaVsONor.js → markdown-DiMg1QLf.js} +1 -1
  107. package/frontend/dist/js/messageCodeStyles-CfzjQF-R.js +2 -0
  108. package/frontend/dist/js/{ms-R9kt_P0T.js → ms-Dznw3AkA.js} +1 -1
  109. package/frontend/dist/js/{nl-BjmtEgpK.js → nl-fW-4lPWK.js} +1 -1
  110. package/frontend/dist/js/{pl-C8_gU9r1.js → pl-CanprK04.js} +1 -1
  111. package/frontend/dist/js/{pt-7BJForUD.js → pt-JhTaVvKa.js} +1 -1
  112. package/frontend/dist/js/{ru-D2HmhY6Y.js → ru-uPtHQATq.js} +1 -1
  113. package/frontend/dist/js/{standalone-B_aPlu7o.js → standalone-Vs6LnjM6.js} +1 -1
  114. package/frontend/dist/js/{sv-zny3sDBM.js → sv-yr6iqxR-.js} +1 -1
  115. package/frontend/dist/js/{th-CAzEKRz8.js → th-Bx4U5yKy.js} +1 -1
  116. package/frontend/dist/js/{tr-BmYgtmUo.js → tr-C7tCwYuZ.js} +1 -1
  117. package/frontend/dist/js/{typescript-Dz4OUZSl.js → typescript-BhVG1zGU.js} +1 -1
  118. package/frontend/dist/js/{ui-DDlcz2oy.js → ui-Dj9IFugT.js} +2 -2
  119. package/frontend/dist/js/{uk-eiYZ0uRq.js → uk-C4SbiAUn.js} +1 -1
  120. package/frontend/dist/js/{vi-C7SVAWpO.js → vi-C3-TmuzC.js} +1 -1
  121. package/frontend/dist/js/{zh-2Q3cQv3s.js → zh-CRfqIC_I.js} +1 -1
  122. package/package.json +1 -1
  123. package/frontend/dist/assets/index-CFhy8YLA.css +0 -1
  124. package/frontend/dist/assets/index-_lG_lwU-.js +0 -164
  125. package/frontend/dist/js/ChatPage-D9lWGM8g.js +0 -16
  126. package/frontend/dist/js/HomePage-iF44c34e.js +0 -1
  127. package/frontend/dist/js/NotesPage-BTNH6JR2.js +0 -1
  128. package/frontend/dist/js/SettingsModal-y1Nzg55O.js +0 -1
  129. package/frontend/dist/js/chatStore-DmDbolTg.js +0 -2
  130. package/frontend/dist/js/messageCodeStyles-cTX0rQGK.js +0 -2
@@ -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-xir4Zz7C.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 j,et as ee,fn as M,ft as N,g as P,gn as te,h as ne,j as F,n as I,nn as L,o as re,on as ie,pt as ae,qt as oe,r as se,rn as R,st as ce,t as le,tt as ue,v as de,wn as z,wt as B,x as fe,yn as pe}from"./ui-vendor-D_pYT79f.js";import{i as V,t as H}from"./logger-DSXjF4ye.js";import{a as me,d as U,f as W,g as he,i as ge,n as _e,u as ve,x as G,y as ye}from"./api-DVP8xiYT.js";import{a as be,n as K,r as xe,t as q}from"./utils-BhpNrGnR.js";import{a as Se,c as Ce,i as we,l as Te,n as Ee,r as De,t as J}from"./chatStore-DmDbolTg.js";import{n as Oe,r as Y}from"./authStore-gv_MgDKr.js";import{t as ke}from"./appStore-Cw7PmG-J.js";import{i as Ae,r as je,t as Me}from"./welcomePrompts-to5mv_gx.js";import{t as X}from"./Button-X9TT9gTD.js";import{d as Ne,f as Pe,l as Fe}from"./ui-DDlcz2oy.js";import{a as Ie,o as Le}from"./artifactHtml-C0Hu9I1u.js";import{t as Re}from"./ArtifactContainer-CjpvtR8G.js";import{t as ze}from"./ModelSelector-B0RKEJwC.js";var Be=r(),Z=e(n(),1),Q=t(),Ve=({statistics:e,className:t=``})=>{let[n,r]=(0,Z.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,Q.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,Q.jsx)(N,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,Q.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,Q.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,Q.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,Q.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,Q.jsx)(O,{size:12}):(0,Q.jsx)(R,{size:12,className:`rtl:rotate-180`}),(0,Q.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,Q.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,Q.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},He=H(`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 me.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}=ke(),[a,o]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)([]),[m,h]=(0,Z.useState)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(!1),v=(0,Z.useRef)([]),y=(0,Z.useRef)(0);(0,Z.useEffect)(()=>{let e=!0;return(async()=>{let t=await qe(),n=_e(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,Z.useCallback)(async(e,t,n,i,a,o)=>{let s=await me.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,Z.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 me.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,Z.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=ge(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,Z.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},T={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,Q.jsx)(`button`,{onClick:C,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:q(`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,Q.jsx)(ce,{className:q(T[n],`animate-spin`)}):a?(0,Q.jsx)(fe,{className:T[n]}):u?(0,Q.jsx)(D,{className:T[n]}):(0,Q.jsx)(re,{className:T[n]})})},Xe=new Map;function Ze(e,t){let n=Xe.get(e);if(n&&n.state!==`open`||!t)return;let r=be(t);if(!n){r.thinkingComplete?Xe.set(e,{state:`none`}):Xe.set(e,{state:`open`,startedAt:Date.now()});return}r.thinkingComplete&&Xe.set(e,{state:`done`,durationMs:Date.now()-n.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 $(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 pt(e){let t=[],n=new RegExp(tt),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=mt(n,gt(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 mt(e,t){let n=ht(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!nt.test(r)&&!r.includes(`=`)?$(r):void 0)||$(vt(n)),fileName:n}}function ht(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&nt.test(t[1]))return _t(t[1]);let n=e.match(nt);return n?_t(n[0]):void 0}function gt(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 _t(t[0])}}function _t(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function vt(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function yt(e){return e?.split(/[\\/]/).pop()}function bt(e){let t=yt(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 xt(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function St(e){let t=$(e.language)||$(vt(e.fileName));switch(t){case`html`:return{type:`html`,title:ct(e.content)||bt(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:bt(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:lt(e.content)||bt(e.fileName)||`React Component`,language:`jsx`};case`json`:return{type:`json`,title:bt(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:ut(e.content)||bt(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:bt(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:dt(e.content)||bt(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:bt(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:bt(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function Ct(e){return($(e.language)||$(vt(e.fileName)))===`html`}function wt(e){return($(e.language)||$(vt(e.fileName)))===`css`}function Tt(e){return($(e.language)||$(vt(e.fileName)))===`javascript`}function Et(e){let t=pt(e),n=t.filter(Ct);if(n.length===0)return null;let r=t.filter(wt),i=t.filter(Tt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=Dt(a.content,r,i),s=Le(o,r.map(e=>e.content),i.map(e=>e.content));return Mt(s,`html`)?{artifact:xt({type:`html`,title:ct(s)||bt(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 Dt(e,t,n){let r=e;for(let e of t){let t=yt(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${jt(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=yt(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${jt(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function Ot(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=pt(e);if(kt(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 Mt(s,`html`)?{artifact:xt({type:`html`,title:ct(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function kt(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function At(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 jt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Mt(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 Nt(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);Mt(n.content,n.type)&&(t.push(xt({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=At(n,r)}let r=Et(n);for(;r;)t.push(r.artifact),n=At(n,r.ranges),r=Et(n);let i=Ot(n);i&&(t.push(i.artifact),n=At(n,i.ranges));let a=pt(n),o=[];for(let e of a){let n=St(e);!n||!Mt(e.content,n.type)||(t.push(xt({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=At(n,o),{content:n.trim(),artifacts:t}}var Pt=H(`components:chat-message`),Ft=({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}=ke(),{user:p}=Oe(),{setSystemMessage:h,getCurrentPersona:_,currentSession:v,rateMessage:y}=J(),b=_(),[x,C]=(0,Z.useState)(!1),[w,E]=(0,Z.useState)(e.content),[D,k]=(0,Z.useState)(null),[A,ee]=(0,Z.useState)(!1),[M,N]=(0,Z.useState)(!1),[te,F]=(0,Z.useState)(!1),[re,ae]=(0,Z.useState)(!1),[oe,se]=(0,Z.useState)(!1),R=(0,Z.useRef)(null),ce=(0,Z.useRef)(t),le=(0,Z.useRef)(!1),ue=async()=>{try{await navigator.clipboard.writeText(e.content),se(!0),setTimeout(()=>se(!1),2e3)}catch(e){Pt.error(`Failed to copy message:`,e)}},{thinkingContent:de,thinkingStreaming:z,parsedContent:B,artifacts:fe}=(0,Z.useMemo)(()=>{if(l||d||!e.content)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=be(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=Nt(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.artifacts,l,d,t]),pe=z?void 0:e.statistics?.thinking_duration_ms??Qe(e.id);(0,Z.useEffect)(()=>{let e=ce.current&&!t;return ce.current=t,e&&!le.current&&!l&&!d&&B&&f.ttsSettings?.enabled&&f.ttsSettings?.autoPlay&&(le.current=!0,(async()=>{ae(!0);try{let e=await me.getModels(),t=e.success&&e.data?e.data:[],n=f.ttsSettings,r=ge(t,n?.model,n?.pluginId),i=_e(t,n?.model,n?.pluginId),a=await me.generateBase64({model:r?.model||n?.model||`tts-1`,pluginId:r?.plugin||n?.pluginId,input:B,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);R.current=t,t.onended=()=>{ae(!1),R.current=null},t.onerror=()=>{ae(!1),R.current=null},await t.play()}}catch(e){Pt.error(`Auto-play TTS failed:`,e),ae(!1)}})()),()=>{R.current&&(R.current.pause(),R.current=null)}},[t,l,d,B,f.ttsSettings]);let V=()=>d?o(`chatMessage.system`):l?f.showUsername&&p?.username?p.username:o(`chatMessage.you`):b?.name?b.name:e.model||o(`chatMessage.assistant`),H=()=>{C(!0),E(e.content)},U=async()=>{ee(!0);try{h(w),C(!1),Pt.debug(`✅ System message updated:`,w)}catch(e){Pt.error(`Failed to save system message:`,e)}finally{ee(!1)}},W=()=>{C(!1),E(e.content)},he=()=>{let t=w.trim();C(!1),!(!t||t===e.content)&&a?.(e.id,t)},ve=t=>{v&&y(v.id,e.id,e.rating===t?void 0:t)},G=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ye=d&&e.content.length>100;return(0,Q.jsxs)(`div`,{className:q(`group flex py-1.5 transition-colors sm:py-2`,l?`justify-end`:`justify-start`,n),children:[(0,Q.jsx)(`div`,{className:q(`flex min-w-0`,l?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:(0,Q.jsxs)(`div`,{className:q(`min-w-0 flex-1`,l?`flex flex-col items-end`:d?`py-1.5`:`py-0.5`),children:[!l&&!d&&(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:V()}),e.model&&b?.name&&(0,Q.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,Q.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:K(e.timestamp,c.language)})]}),(0,Q.jsxs)(`div`,{className:q(!l&&!d&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,Q.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,Q.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,Q.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>k(e)})},t))}),l?x?(0,Q.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,Q.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),he()):e.key===`Escape`&&W()},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,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,Q.jsx)(`button`,{onClick:W,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,Q.jsx)(`button`,{onClick:he,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,Q.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,Q.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):d?(0,Q.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,Q.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,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(u,{className:`h-2.5 w-2.5 opacity-50`}),o(`chatMessage.system`)]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:x?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:U,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,Q.jsx)(m,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,Q.jsx)(`button`,{onClick:W,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,Q.jsx)(I,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,Q.jsx)(`button`,{onClick:H,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:o(`chatMessage.editSystemMessage`),children:(0,Q.jsx)(T,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),x?(0,Q.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,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:M?e.content:G(e.content)}),ye&&(0,Q.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,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(L,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(O,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,Q.jsxs)(`div`,{className:`relative`,children:[(de||z)&&(0,Q.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,Q.jsxs)(`button`,{onClick:()=>F(!te),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,Q.jsx)(j,{className:q(`h-3.5 w-3.5`,z&&`animate-pulse-subtle motion-reduce:animate-none`)}),z?(0,Q.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,Q.jsx)(`span`,{className:`font-medium`,children:pe===void 0?o(`chatMessage.thinking`):o(`chatMessage.thoughtFor`,{duration:et(pe)})}),te?(0,Q.jsx)(L,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(O,{className:`h-3.5 w-3.5`})]}),te&&de&&(0,Q.jsx)(`div`,{className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 dark:bg-dark-200/60`,children:(0,Q.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[13px] leading-relaxed text-gray-600 dark:text-dark-700`,children:de})})]}),(0,Q.jsx)(Fe,{content:B,isStreaming:t})]}),!l&&!d&&fe.length>0&&(0,Q.jsx)(`div`,{className:`mt-3`,children:(0,Q.jsx)(Re,{artifacts:fe})}),!l&&!d&&e.statistics&&(0,Q.jsx)(`div`,{className:`mt-2`,children:(0,Q.jsx)(Ve,{statistics:e.statistics})}),!d&&!t&&(0,Q.jsxs)(`div`,{className:q(`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,Q.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:K(e.timestamp,c.language),children:[V(),` ·`,` `,K(e.timestamp,c.language)]}),!l&&B&&(0,Q.jsx)(Ye,{text:B,size:`sm`,className:q(`transition-colors`,re&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),l&&a&&!x&&(0,Q.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,Q.jsx)(T,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:ue,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(oe?`chatMessage.copied`:`chatMessage.copyMessage`),children:oe?(0,Q.jsx)(ie,{className:`h-3.5 w-3.5 text-green-500`}):(0,Q.jsx)(g,{className:`h-3.5 w-3.5`})}),!l&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:()=>ve(1),className:q(`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,Q.jsx)(ne,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,Q.jsx)(`button`,{onClick:()=>ve(-1),className:q(`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,Q.jsx)(P,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})})]}),!l&&r&&i&&(0,Q.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,Q.jsx)(S,{className:`h-3.5 w-3.5`})})]})]})]})}),D&&(0,Be.createPortal)((0,Q.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,Q.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,Q.jsx)(I,{className:`h-7 w-7`})}),(0,Q.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)]})},It=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Lt=220,Rt=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>Lt?`${t.slice(0,219).trimEnd()}…`:t},zt=Z.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(new Map),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(0),f=(0,Z.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,Z.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,Z.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:It()?`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,Q.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,Q.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,Q.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,Q.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:q(`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,Q.jsx)(`span`,{"aria-hidden":`true`,className:q(`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,Q.jsx)(`div`,{id:v,role:`tooltip`,className:q(`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,Q.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,Q.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:Rt(_.prompt)}),_.response&&(0,Q.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:Rt(_.response)})]})})]})}),Bt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingMessageId:r,isLastAssistantMessage:i=!1,onRegenerate:a,onSelectBranch:o,className:s})=>{if(e.length===1){let o=e[0],c=t&&r===o.id,l=c&&n?{...o,content:n}:o;return(0,Q.jsx)(Ft,{message:l,isStreaming:c,isLastAssistantMessage:i,onRegenerate:a,className:s})}return(0,Q.jsxs)(`div`,{className:q(`relative py-2`,s),children:[(0,Q.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,Q.jsx)(f,{className:`h-3 w-3`}),(0,Q.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let c=e.isActive!==!1,l=t&&r===e.id,u=l&&n?{...e,content:n}:e;return(0,Q.jsxs)(`div`,{className:q(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,c||l?`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`,!c&&!l&&`cursor-pointer`),role:!c&&!l?`button`:void 0,tabIndex:!c&&!l?0:void 0,onClick:()=>!c&&!l&&o?.(e.id),onKeyDown:t=>{!c&&!l&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),o?.(e.id))},children:[(0,Q.jsxs)(`div`,{className:q(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,c||l?`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,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:s+1}),l&&(0,Q.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),c&&!l&&(0,Q.jsx)(ie,{className:`h-3 w-3`}),!c&&!l&&(0,Q.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,Q.jsx)(`div`,{className:q(!c&&!l&&`opacity-75`),children:(0,Q.jsx)(Ft,{message:u,isStreaming:l,isLastAssistantMessage:i&&(c||l),onRegenerate:c&&!t?a:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Vt={web_search:b,web_fetch:k,exec:de,browser:k,Read:x,Write:x,Edit:x,image:ae,memory_search:E,memory_get:E,working:se,thinking:se,default:se},Ht={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`},Ut=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,Q.jsx)(`div`,{className:q(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Vt[e.name]||Vt.default,n=Ht[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,Q.jsxs)(`div`,{className:q(`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,Q.jsx)(`div`,{className:q(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,Q.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,Q.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};H(`components:chat-messages`);var Wt=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],Gt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,Kt=e=>Math.min(120,e*.28),qt=({messages:e,streamingMessage:t,streamingMessageId:n,isStreaming:r=!1,toolActivities:i=[],className:a,onRegenerate:o,onSelectBranch:c,onEditResend:l,followUpSuggestions:u,onFollowUpSelect:d})=>{let{t:f}=s(),p=(0,Z.useRef)(null),m=(0,Z.useRef)(void 0),h=(0,Z.useRef)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(new Map),v=(0,Z.useRef)(null),y=(0,Z.useRef)(0),b=(0,Z.useRef)(!1),x=(0,Z.useRef)(!1),[S,w]=(0,Z.useState)(!1),T=(0,Z.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),E=(0,Z.useMemo)(()=>{let e=[];for(let t=0;t<T.length;t++){let n=T[t],r=Wt(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<T.length;e++){let t=Wt(T[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},[T]),D=E.map(e=>e.id).join(``),O=(0,Z.useMemo)(()=>D?D.split(``):[],[D]),k=(0,Z.useMemo)(()=>new Set(O),[O]),[A,j]=(0,Z.useState)(null),ee=(0,Z.useCallback)(()=>{let e=h.current;if(!e||O.length===0){j(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(y.current,O.length-1);if(t<=2)n=O.length-1;else{let t=e.scrollTop+Kt(e.clientHeight);for(;n<O.length-1;){let e=_.current.get(O[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=_.current.get(O[n]);if(!e||e.offsetTop<=t)break;n--}}y.current=n;let r=O[n];j(e=>e===r?e:r)},[O]),M=(0,Z.useCallback)(()=>{v.current===null&&(v.current=window.requestAnimationFrame(()=>{v.current=null,ee()}))},[ee]),N=(0,Z.useCallback)(()=>{let t=h.current;if(m.current&&clearTimeout(m.current),b.current=!1,m.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;x.current=!n,w(!n&&e.length>0),M()},[e.length,M]),P=(0,Z.useCallback)(()=>{m.current&&clearTimeout(m.current),m.current=setTimeout(N,180)},[N]),te=(0,Z.useCallback)((e=!1)=>{x.current&&!e||p.current?.scrollIntoView({behavior:Gt()})},[]),ne=(0,Z.useCallback)(()=>{let t=h.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(b.current){x.current=!0,w(!o&&e.length>0),M(),P();return}x.current=!o,w(!o&&e.length>0),a<=2&&O.length>0?(y.current=O.length-1,j(O[O.length-1])):M()},[O,e.length,P,M]),F=(0,Z.useCallback)(e=>{let t=h.current,n=_.current.get(e);if(!t||!n)return;let r=Gt();b.current=!0,x.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-Kt(t.clientHeight)),behavior:r}),M(),r===`auto`?N():P()},[N,P,M]),I=(0,Z.useRef)(e.length);if((0,Z.useEffect)(()=>{e.length>I.current&&!x.current&&te(),I.current=e.length},[e.length,te]),(0,Z.useEffect)(()=>{r&&t&&!x.current&&requestAnimationFrame(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)})},[r,t]),(0,Z.useEffect)(()=>{M();let e=g.current,t=h.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(M);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,M),()=>{n?.disconnect(),window.removeEventListener(`resize`,M)}},[D,M]),(0,Z.useEffect)(()=>()=>{v.current!==null&&(window.cancelAnimationFrame(v.current),v.current=null)},[]),(0,Z.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]),e.length===0&&!r)return(0,Q.jsx)(`div`,{className:q(`flex-1 flex items-center justify-center p-6 sm:p-10`,a),children:(0,Q.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,Q.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,Q.jsx)(C,{className:`h-4 w-4`})}),(0,Q.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:f(`chatMessage.startConversation`)}),(0,Q.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:f(`chatMessage.startConversationDescription`)})]})});let L=-1;for(let e=T.length-1;e>=0;e--)if(T[e].messages.some(e=>e.role===`assistant`)){L=e;break}return(0,Q.jsxs)(`div`,{className:q(`relative min-h-0 flex-1`,a),style:{WebkitAppRegion:`no-drag`},children:[(0,Q.jsx)(`div`,{ref:h,"data-testid":`chat-scroll-viewport`,onScroll:ne,className:q(`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,Q.jsxs)(`div`,{ref:g,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[T.map((e,i)=>{let a=i===L,s=k.has(e.id),u=r&&e.messages.some(e=>e.id===n),d;if(e.messages.length===1){let s=e.messages[0],c=r&&s.id===n,u=c&&t?{...s,content:t}:s;d=(0,Q.jsx)(Ft,{message:u,isStreaming:c,isLastAssistantMessage:a,onRegenerate:a?o:void 0,onEditResend:r?void 0:l,className:i===0?`mt-3 sm:mt-4`:``})}else d=(0,Q.jsx)(Bt,{messages:e.messages,isStreaming:u,streamingMessage:t,streamingMessageId:n||void 0,isLastAssistantMessage:a,onRegenerate:a?o:void 0,onSelectBranch:c,className:i===0?`mt-3 sm:mt-4`:``});return(0,Q.jsx)(`div`,{ref:t=>{s&&(t?_.current.set(e.id,t):_.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:d},e.id)}),r&&i.length>0&&(0,Q.jsx)(Ut,{tools:i,className:`px-0`}),!r&&u&&u.length>0&&d&&(0,Q.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,Q.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:f(`chat.followUp`)}),(0,Q.jsx)(`div`,{className:`flex flex-col`,children:u.map(e=>(0,Q.jsx)(`button`,{onClick:()=>d(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,Q.jsx)(`div`,{ref:p,className:`h-4 sm:h-6`})]})}),(0,Q.jsx)(zt,{items:E,activeId:A,onSelect:F}),S&&(0,Q.jsxs)(`button`,{onClick:()=>{b.current=!1,m.current&&(clearTimeout(m.current),m.current=void 0),x.current=!1,p.current?.scrollIntoView({behavior:Gt()}),w(!1)},className:q(`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:f(`chatMessage.scrollToBottom`),children:[(0,Q.jsx)(pe,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:f(`chatMessage.newMessages`)})]})]})};function Jt(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 Yt=Z.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,Z.useMemo)(()=>Jt(e),[e]);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:q(`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,Q.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,Q.jsxs)(`div`,{className:q(`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,Q.jsx)(_,{className:`h-3 w-3`}),d&&(0,Q.jsx)(`span`,{children:d}),!d&&u&&(0,Q.jsx)(`span`,{children:`code`})]})})]})});Yt.displayName=`CodeAwareTextarea`;var Xt=H(`components:media-upload`),Zt=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Z.useRef)(null),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)([]),g=async e=>{if(!(!e||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 ye.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){Xt.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 ye.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){Xt.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,Q.jsxs)(`div`,{className:q(`space-y-3`,o),children:[(0,Q.jsxs)(`div`,{className:q(`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,Q.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,Q.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,Q.jsx)(ce,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,Q.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,Q.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,Q.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),O&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,Q.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Q.jsx)(`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,Q.jsx)(I,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,Q.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,Q.jsx)(x,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,Q.jsx)(v,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,Q.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:D(e.size)})]}),(0,Q.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,Q.jsx)(I,{className:`h-3 w-3`})})]},e.id))]})]})},Qt=H(`components:document-indicator`),$t=({sessionId:e,className:t=``})=>{let[n,r]=(0,Z.useState)([]);if((0,Z.useEffect)(()=>{if(!e)return;let t=async()=>{try{let t=await ye.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){Qt.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,Q.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,Q.jsx)(te,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,Q.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},en=H(`components:structured-output`),tn=[{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`}],nn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Z.useState)(!1),[o,c]=(0,Z.useState)(``),l=()=>tn.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,Q.jsxs)(`div`,{className:q(`space-y-3`,n),children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Q.jsxs)(`div`,{className:`flex items-center`,children:[(0,Q.jsx)(u,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,Q.jsx)(Ne,{value:d().label,onChange:e=>f(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d().description}),i&&(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.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,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(X,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){en.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,Q.jsx)(X,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=d();return!e.value||e.value===`json`?null:(0,Q.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,Q.jsx)(oe,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,Q.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,Q.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,Q.jsx)(x,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},rn=H(`components:chat-input`),an=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},on=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r,i18n:i}=s(),[a,o]=(0,Z.useState)(``),[c,u]=(0,Z.useState)(!1),f=(0,Z.useRef)(null),p=(0,Z.useRef)(``),m=(0,Z.useMemo)(()=>!!an(),[]),[g,_]=(0,Z.useState)([]),[v,b]=(0,Z.useState)(null),[S,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(null),[O,A]=(0,Z.useState)(!1),[j,N]=(0,Z.useState)([]),[P,ne]=(0,Z.useState)(!1),[F,I]=(0,Z.useState)(!1),[L,re]=(0,Z.useState)(null),[oe,se]=(0,Z.useState)(!1),R=(0,Z.useRef)(null),le=(0,Z.useRef)(null),{isGenerating:ue,setBackgroundImage:de}=ke(),B=ke(e=>e.preferences.imageGenSettings?.enabled===!0),pe=B&&oe,{currentSession:V,models:H}=J(),me=(0,Z.useRef)(null),U=(0,Z.useMemo)(()=>({model:V?.personaId?`persona:${V.personaId}`:V?.model||``,providerType:V?.providerType,providerId:V?.providerId}),[V?.model,V?.personaId,V?.providerId,V?.providerType]),W=(0,Z.useMemo)(()=>Te(H,U),[H,U]),ge=U.model?Se(W,U):``,_e=Ce(H,U);(0,Z.useEffect)(()=>{let e=!1;return B&&(async()=>{try{let t=await he.getPlugins();if(e)return;se(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;se(!1)}})(),()=>{e=!0}},[B]),(0,Z.useEffect)(()=>{if(!w)return;let e=e=>{R.current&&!R.current.contains(e.target)&&(T(!1),D(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[w]);let be=()=>{T(!1),D(null),A(!1)};(0,Z.useEffect)(()=>{if(!O)return;let e=!1;return ye.getCollections().then(t=>{!e&&t.success&&t.data&&N(t.data)}).catch(()=>{}),()=>{e=!0}},[O]);let K=V?.settings?.knowledgeCollectionIds??[],xe=async e=>{if(!V)return;let t=K.includes(e)?K.filter(t=>t!==e):[...K,e],n={...V.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(J.setState(e=>({currentSession:e.currentSession?.id===V.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===V.id?{...e,settings:n}:e)})),!V.isPrivate)try{await G.updateSession(V.id,{settings:n})}catch(e){rn.error(`Failed to update knowledge collections:`,e),z.error(r(`chat.input.menu.attachFailed`))}};(0,Z.useEffect)(()=>()=>{f.current?.stop()},[]);let we=()=>{if(c){f.current?.stop();return}let e=an();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){rn.error(`Failed to start dictation:`,e),f.current=null}},Oe=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){be(),I(!0);try{let e=await ye.uploadDocument(t,V?.id);e.success?(z.success(r(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):z.error(e.error||r(`chat.input.menu.attachFailed`))}catch(e){rn.error(`Document upload failed:`,e),z.error(r(`chat.input.menu.attachFailed`))}finally{I(!1)}}},Y=async()=>{let e=E?.trim();if(!(!e||P)){ne(!0);try{let t=await ye.fetchWebpage(e,V?.id);t.success?(z.success(r(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),be()):z.error(t.error||r(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||r(`chat.input.menu.attachFailed`);rn.error(`Webpage attach failed:`,e),z.error(t)}finally{ne(!1)}}},Ae=t=>{if(t.preventDefault(),!(!a.trim()||ue)){if(!_e){z.error(`Select an available model before sending`);return}e(a.trim(),g.length>0?g:void 0,v||void 0),o(``),_([])}},je=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ae(e))},Me=()=>{t()};(0,Z.useEffect)(()=>{let e=me.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[a]),(0,Z.useEffect)(()=>{(async()=>{if(V?.personaId)try{let e=await ve.getPersona(V.personaId);if(e.success&&e.data)re(e.data);else{rn.warn(`Persona ${V.personaId} not found, clearing reference`),re(null);let{setCurrentSession:e}=J.getState();e({...V,personaId:void 0})}}catch(e){if(rn.error(`Failed to load current persona:`,e),re(null),V){let{setCurrentSession:e}=J.getState();e({...V,personaId:void 0})}}else re(null)})()},[V?.personaId]);let Ne=async e=>{let t=De(W,e.target.value);if(t&&V)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await ve.getPersona(e);if(!n.success||!n.data){z.error(`Failed to load persona details`);return}let i=n.data,a=await G.updateSession(V.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(a.success&&a.data){let{sessions:e}=J.getState(),t=e.map(e=>e.id===V.id?a.data:e);J.setState({sessions:t,currentSession:a.data}),i.background&&de(i.background),z.success(r(`chat.persona.applied`))}}else{let e=await G.updateSession(V.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}=J.getState(),n=t.map(t=>t.id===V.id?e.data:t);J.setState({sessions:n,currentSession:e.data}),de(null),z.success(r(`chat.model.updated`))}}}catch(e){rn.error(`Failed to update session:`,e),z.error(`Failed to update session`)}},Pe=g.length>0||v!==null;return(0,Q.jsx)(`div`,{className:`pointer-events-none`,children:(0,Q.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[S&&(0,Q.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,Q.jsx)(Zt,{images:g,onImagesChange:_,maxImages:5,sessionId:V?.id,disabled:n}),(0,Q.jsx)(nn,{format:v,onFormatChange:b})]}),(0,Q.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[(0,Q.jsx)(`form`,{onSubmit:Ae,children:(0,Q.jsxs)(`div`,{className:q(`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,Q.jsxs)(`div`,{ref:R,className:`relative flex-shrink-0`,children:[(0,Q.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(S){C(!1);return}T(e=>!e),D(null)},className:q(`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`,Pe&&`text-primary-600 dark:text-primary-400`,(S||w)&&`bg-gray-100 dark:bg-dark-300`),title:r(`chat.input.attachments`),children:F||P?(0,Q.jsx)(ce,{className:`h-4 w-4 animate-spin`}):Pe?(0,Q.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,Q.jsx)(h,{className:`h-4 w-4`}),(0,Q.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,Q.jsx)(l,{className:`h-4 w-4`}):(0,Q.jsx)(d,{className:`h-4 w-4`})}),w&&(0,Q.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,Q.jsxs)(`div`,{className:`p-1`,children:[(0,Q.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`)}),j.length===0?(0,Q.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-gray-400 dark:text-dark-500`,children:r(`chat.input.menu.noCollections`)}):j.map(e=>{let t=K.includes(e.id);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void xe(e.id),className:q(`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,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(te,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,Q.jsx)(ie,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,Q.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,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{C(!0),be()},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,Q.jsx)(ae,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.uploadImages`)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>le.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,Q.jsx)(x,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachDocument`)]}),(0,Q.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,Q.jsx)(k,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachWebpage`)]}),(0,Q.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,Q.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(te,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachKnowledge`)]}),K.length>0&&(0,Q.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:K.length})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{C(!0),be()},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,Q.jsx)(M,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.structuredOutput`)]})]}):(0,Q.jsxs)(`div`,{className:`p-1.5`,children:[(0,Q.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,Q.jsx)(`input`,{type:`url`,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),Y()):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,Q.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,Q.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,Q.jsx)(`button`,{type:`button`,onClick:()=>void Y(),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,Q.jsx)(ce,{className:`h-3.5 w-3.5 animate-spin`}):r(`chat.input.menu.attach`)})]})]})}),(0,Q.jsx)(`input`,{ref:le,type:`file`,accept:`.pdf,.txt,application/pdf,text/plain`,className:`hidden`,onChange:e=>void Oe(e)})]}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(Yt,{ref:me,value:a,onChange:e=>o(e.target.value),onKeyDown:je,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,Q.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1 sm:gap-2`,children:[V&&W.length>0&&(0,Q.jsx)(`div`,{className:`hidden sm:block`,children:(0,Q.jsx)(ze,{models:W,selectedModel:ge,onModelChange:Ne,getModelValue:Ee,currentPersona:L,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:pe})}),m&&(0,Q.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:we,className:q(`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,Q.jsx)(ee,{className:`h-4 w-4`})}),ue?(0,Q.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:Me,className:q(`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,Q.jsx)(fe,{className:`h-4 w-4`})}):(0,Q.jsx)(X,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!a.trim()||n||!_e,className:q(`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&&_e&&[`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,Q.jsx)(y,{className:`h-4 w-4`})})]})]})}),V&&W.length>0&&(0,Q.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,Q.jsx)(ze,{models:W,selectedModel:ge,onModelChange:Ne,getModelValue:Ee,currentPersona:L,className:`w-full`,compact:!0,showImageGen:pe})}),(0,Q.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,Q.jsx)($t,{sessionId:V?.id}),(0,Q.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,Q.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),Pe&&(0,Q.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`)]})]})]})]})]})})},sn=H(`components:chat-controls-panel`),cn=[{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`}],ln=({session:e,open:t,onClose:n})=>{let{t:r}=s(),i=ke(e=>e.preferences.generationOptions),a=(0,Z.useMemo)(()=>e.messages.find(e=>e.role===`system`),[e.messages]),[o,c]=(0,Z.useState)(a?.content??``),[l,u]=(0,Z.useState)(e.settings?.generationOptions??{}),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.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:xe(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)J.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:u,settings:c}:t.currentSession}));else{let t=await G.updateSession(e.id,{messages:u,settings:c});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;J.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){sn.error(`Failed to save chat controls:`,e),w.error(r(`chat.controls.saveFailed`))}finally{f(!1)}};return(0,Q.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:q(`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,Q.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,Q.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:r(`chat.controls.title`)}),(0,Q.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,Q.jsx)(I,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.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,Q.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,Q.jsxs)(`div`,{children:[(0,Q.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,Q.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:r(`chat.controls.advancedParamsDescription`)}),(0,Q.jsx)(`div`,{className:`space-y-1.5`,children:cn.map(e=>{let t=l[e.key],n=i?.[e.key];return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.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,Q.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,Q.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,Q.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,Q.jsx)(X,{onClick:()=>void g(),size:`sm`,disabled:d,children:r(d?`common.saving`:`common.save`)})]})]})},un=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Z.useState)(!1),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)({top:0,left:0});(0,Z.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=()=>U(e,64),u=t=>{W(t.currentTarget,e.name,64)};return(0,Q.jsxs)(`div`,{className:q(`relative`,n),children:[(0,Q.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:q(`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,Q.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:u}),(0,Q.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,Q.jsx)(C,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,Q.jsx)(O,{className:q(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Be.createPortal)((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,Q.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,Q.jsxs)(`div`,{className:q(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,Q.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 end-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,Q.jsx)(I,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,Q.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,Q.jsx)(j,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,Q.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,Q.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,Q.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,Q.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,Q.jsx)(F,{className:`h-3 w-3`}),e.model]}),e.description&&(0,Q.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,Q.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,Q.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,Q.jsx)(ue,{className:`h-2.5 w-2.5 text-gray-400`}),(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,Q.jsx)(le,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,Q.jsx)(j,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},dn=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Z.useRef)(null),[o,c]=(0,Z.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,Q.jsxs)(`div`,{className:q(`space-y-3`,r),children:[m&&(0,Q.jsxs)(`div`,{className:q(`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,Q.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,Q.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,Q.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,Q.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,Q.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,Q.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,Q.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,Q.jsx)(X,{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,Q.jsx)(I,{className:`h-4 w-4`})})})]},t))}),m&&e.length>0&&(0,Q.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,Q.jsx)(ae,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},fn=H(`use-chat`),pn=new Set([`New Chat`,`New Demo Session`]),mn=e=>!e||pn.has(e),hn=e=>{let[t,n]=(0,Z.useState)(``),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)([]),{addMessage:l,updateMessage:u,updateMessageWithStatistics:d,applySessionTitle:f,setGeneratingTitleForSession:p}=J(),{setIsGenerating:m,preferences:h}=ke(),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(!1),y=(0,Z.useRef)(null),b=(0,Z.useRef)(``),x=(0,Z.useRef)(0),S=(0,Z.useRef)(void 0),C=(0,Z.useRef)(null),T=(0,Z.useRef)(``),E=(0,Z.useCallback)(()=>{C.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(C.current),C.current=null},[]),D=(0,Z.useCallback)((e,t=!1)=>{if(T.current=e,t||typeof window>`u`){E(),n(e);return}C.current===null&&(C.current=window.requestAnimationFrame(()=>{C.current=null,n(T.current)}))},[E]),O=(0,Z.useCallback)(()=>{E(),T.current=``,n(``)},[E]),k=(0,Z.useCallback)(()=>{_.current=null,v.current=!1,y.current=null},[]),A=(0,Z.useCallback)(async e=>{let t=ke.getState().preferences.titleSettings,n=_.current,r=v.current&&y.current===e;if(fn.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),!n||!r||!t?.autoTitle||!t?.taskModel){k();return}k(),fn.debug(`Triggering auto-title generation...`),p(e);try{let r=await G.generateTitle(e,t.taskModel,n,t.taskProviderType,t.taskProviderId);if(fn.debug(`Title generation response:`,r),!r.success||!r.data?.title)throw Error(r.error||`Title generation returned no title`);f(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){fn.error(`Failed to generate title:`,e),w.error(`Failed to generate chat title`)}finally{p(null)}},[f,k,p]);(0,Z.useEffect)(()=>()=>{Y.offMessage(`user_message`),Y.offMessage(`assistant_chunk`),Y.offMessage(`assistant_complete`),Y.offMessage(`tool_status`),Y.offMessage(`error`)},[e]),(0,Z.useEffect)(()=>{if(!e){Y.offMessage(`user_message`),Y.offMessage(`assistant_chunk`),Y.offMessage(`assistant_complete`),Y.offMessage(`tool_status`),Y.offMessage(`error`);return}return Y.onMessage(`user_message`,()=>{}),Y.onMessage(`assistant_chunk`,t=>{let n=t,r=n.messageId||g.current;r&&(b.current=n.total,Ze(r,n.total),D(n.total,n.done),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{u(e,r,b.current),x.current=Date.now()},n.done?0:200))}),Y.onMessage(`tool_status`,e=>{let t=e;c(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),Y.onMessage(`assistant_complete`,t=>{let n=t;fn.debug(`Hook: Received assistant_complete for session:`,e,`messageId:`,n.messageId,`with statistics:`,!!n.statistics),o(!1),O(),m(!1),c([]);let r=n.messageId||g.current;if(n&&r){let t=b.current||n.content,i=$e(r),a=n.statistics?.thinking_duration_ms===void 0&&i!==void 0?{...n.statistics,thinking_duration_ms:i}:n.statistics;d(e,r,t,a,n.providerMetadata)}A(e),g.current=null,b.current=``,S.current&&clearTimeout(S.current),x.current=0}),Y.onMessage(`error`,e=>{let t=e;if(o(!1),O(),m(!1),g.current=null,t.code===`SESSION_NOT_FOUND`){fn.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),k()}),o(!1),O(),g.current=null,()=>{S.current&&clearTimeout(S.current),E()}},[e,u,d,m,D,O,E,A,k]);let j=(0,Z.useCallback)(async(t,n,r)=>{if(!(!e||!t.trim()&&(!n||n.length===0)))try{let a=J.getState(),s=a.currentSession,c={model:s?.personaId?`persona:${s.personaId}`:s?.model||``,providerType:s?.providerType,providerId:s?.providerId};if(!Ce(a.models,c)){w.error(`Select an available model before sending`);return}m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let d=s?.isPrivate===!0,f=s?.messages?.some(e=>e.role===`user`);!d&&!f&&mn(s?.title)?(_.current=t.trim(),v.current=!0,y.current=e):(_.current=null,v.current=!1,y.current=null),l(e,{role:`user`,content:t.trim(),images:n});let p=xe();if(g.current=p,i(p),l(e,{role:`assistant`,content:``,id:p}),V()){let n=`Demo response for: ${t.trim()}`;window.setTimeout(()=>{u(e,p,n),o(!1),O(),i(null),m(!1),A(e),g.current=null,b.current=``},500);return}Y.isConnected||await Y.connect();let C=d?s?.messages?.filter(e=>e.role!==`system`&&e.id!==p).map(e=>({role:e.role,content:e.content,images:e.images,providerMetadata:e.providerMetadata})):void 0;Y.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:n,format:r,options:{...h.generationOptions,...s?.settings?.generationOptions},assistantMessageId:p,isPrivate:d,...d?{model:s?.model,providerType:s?.providerType,providerId:s?.providerId,messageHistory:C}:{}}})}catch(e){fn.error(`Failed to send message:`,e),o(!1),O(),i(null),m(!1),g.current=null,w.error(`Failed to send message`)}},[e,l,u,m,O,A,h.generationOptions]),ee=(0,Z.useCallback)(()=>{o(!1),O(),i(null),m(!1),g.current=null},[m,O]),M=(0,Z.useCallback)(async()=>{let t=J.getState(),n=t.currentSession;if(!n||!e)return;if(!Ce(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,a=-1,s=-1;for(let e=r.length-1;e>=0;e--)if(r[e].role===`assistant`){s=e;break}if(s>0){for(let e=s-1;e>=0;e--)if(r[e].role===`user`){a=e;break}}if(a===-1||s===-1){w.error(`No message to regenerate`);return}let c=r[a],u=r[s];try{m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let t=xe();g.current=t,i(t),l(e,{role:`assistant`,content:``,id:t,parentId:u.parentId||u.id,branchIndex:u.siblingCount||1,isActive:!0}),Y.isConnected||await Y.connect();let a=n.isPrivate===!0,s=a?r.filter(e=>e.role!==`system`).map(e=>({role:e.role,content:e.content,images:e.images,providerMetadata:e.providerMetadata})):void 0;Y.send({type:`chat_stream`,data:{sessionId:e,content:c.content,images:c.images,options:{...h.generationOptions,...n.settings?.generationOptions},assistantMessageId:t,regenerate:!0,originalMessageId:u.id,isPrivate:a,...a?{model:n.model,providerType:n.providerType,providerId:n.providerId,messageHistory:s}:{}}})}catch(e){fn.error(`Failed to regenerate message:`,e),o(!1),O(),i(null),m(!1),g.current=null,w.error(`Failed to regenerate message`)}},[e,m,O,l,h.generationOptions]),N=(0,Z.useCallback)(async t=>{let n=J.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){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 G.switchMessageBranch(e,t,a);if(r.success&&r.data){let r=n.messages.map(e=>e.id===i||e.parentId===i?{...e,isActive:e.id===t}:e),o={...n,messages:r,updatedAt:Date.now()};J.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),w.success(`Switched to variant ${a+1}`)}else w.error(r.error||`Failed to select branch`)}catch(e){fn.error(`Failed to select branch:`,e),w.error(`Failed to select branch`)}},[e]);return{sendMessage:j,stopGeneration:ee,regenerateLastMessage:M,editAndResendMessage:(0,Z.useCallback)(async(t,n)=>{if(!e||!n.trim())return;let r=J.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 G.updateSession(e,{messages:s}),r.truncateMessagesFrom(e,t),await j(n,o.images)}catch(e){fn.error(`Failed to edit message:`,e),w.error(`Failed to edit message`)}},[e,j]),selectBranch:N,isStreaming:a,streamingMessage:t,streamingMessageId:r,toolActivities:s}},gn=H(`pages:chat-page`),_n=(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?`}},vn=(e,t,n,r=!1)=>{let i=je(e);return i===`time`?_n(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.`}},yn=()=>{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}=J(),{user:D}=Oe(),O=ke(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:k,stopGeneration:A,regenerateLastMessage:j,editAndResendMessage:ee,selectBranch:M,isStreaming:N,streamingMessage:P,streamingMessageId:te,toolActivities:ne}=hn(f?.id||``),F=E(),I=(0,Z.useMemo)(()=>({model:_,providerType:v,providerId:b}),[_,b,v]),L=(0,Z.useMemo)(()=>Te(g,I),[g,I]),re=_?Se(L,I):``,ie=Ce(g,I),ae=new URLSearchParams(u.search).get(`incognito`)===`1`,[oe,se]=(0,Z.useState)(Ae),[R,ce]=(0,Z.useState)(null),[le,ue]=(0,Z.useState)(!1),de=ke(e=>e.preferences.showFollowUpSuggestions!==!1),z=(0,Z.useRef)(null),fe=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{let e=f?.id,t=fe.current&&!N;if(fe.current=N,!e||N||!de||f?.isPrivate||!t)return;let n=f.messages[f.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||z.current===n.id)return;z.current=n.id;let r=!1;return G.generateFollowUps(e).then(t=>{r||!t.success||J.getState().currentSession?.id===e&&ce({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[N,f,de]);let pe=R&&R.sessionId===f?.id?R.suggestions:[],V=(0,Z.useMemo)(()=>vn(oe,D?.username,e,c(t.language)),[t.language,e,D?.username,oe]),[H,me]=(0,Z.useState)(``),[U,W]=(0,Z.useState)([]),[ge,_e]=(0,Z.useState)(!1),ve=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{let e=()=>{se(Ae())};return window.addEventListener(Me,e),()=>window.removeEventListener(Me,e)},[]);let[ye,be]=(0,Z.useState)(!1),K=O&&ye,xe=(0,Z.useCallback)((t=!0)=>{let n=_?I:g[0]?we(g[0]):null;if(!n||!Ce(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,_,I,C,e]);(0,Z.useEffect)(()=>{m.length===0&&T()},[T,m.length]),(0,Z.useEffect)(()=>{!ae||f?.isPrivate||xe(!1)},[f?.isPrivate,ae,xe]),(0,Z.useEffect)(()=>{let e=!1;return O&&(async()=>{try{let t=await he.getPlugins();if(e)return;be(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;be(!1)}})(),()=>{e=!0}},[O]),(0,Z.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||(gn.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,Z.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){gn.error(`Failed to parse pending message:`,e)}}}},[f?.id,k]),(0,Z.useEffect)(()=>{let e=ve.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[H]);let Y=async t=>{if(t.preventDefault(),!H.trim()||!_)return;if(!ie){w.error(e(`chat.model.selectBeforeSending`));return}let n={content:H.trim(),images:U.length>0?U:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),me(``),W([]);let i=await S(_,void 0,_.startsWith(`persona:`)?_.slice(8):void 0,v,b);i&&r(`/c/${i.id}`,{replace:!0})},je=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Y(e))},Ne=async e=>{let t=De(L,e.target.value);t&&x(t.model,t.providerType,t.providerId)},Pe=(e,t,n)=>{f&&(ce(null),k(e,t,n))};if(!f){let t=U.length>0;return(0,Q.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,Q.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,Q.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,Q.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,Q.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,Q.jsxs)(`button`,{onClick:()=>xe(),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,Q.jsx)(B,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{children:e(`chat.session.incognito`,`Incognito Chat`)})]}),(0,Q.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,Q.jsxs)(`div`,{className:`mb-10 flex flex-col items-center text-center animate-fade-in sm:mb-12`,"aria-live":`polite`,children:[(0,Q.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:V.title}),(0,Q.jsx)(`p`,{className:`max-w-xl text-balance text-base leading-relaxed text-gray-500 dark:text-dark-600 sm:text-lg`,children:V.subtitle})]},V.id),L.length>0?(0,Q.jsxs)(`div`,{className:`w-full`,children:[ge&&(0,Q.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,Q.jsx)(dn,{images:U,onImagesChange:W,maxImages:5})}),(0,Q.jsx)(`form`,{onSubmit:Y,children:(0,Q.jsxs)(`div`,{className:q(`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,Q.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>_e(!ge),className:q(`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,Q.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,Q.jsx)(h,{className:`h-4 w-4`}),(0,Q.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):ge?(0,Q.jsx)(l,{className:`h-4 w-4`}):(0,Q.jsx)(d,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(Yt,{ref:ve,value:H,onChange:e=>me(e.target.value),onKeyDown:je,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,Q.jsx)(`div`,{className:`hidden sm:block`,children:(0,Q.jsx)(ze,{models:L,selectedModel:re,onModelChange:Ne,getModelValue:Ee,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:K})}),(0,Q.jsx)(X,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!H.trim()||!_||!ie,className:q(`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`,H.trim()&&_&&`shadow-sm`),title:e(`chat.input.sendMessage`),children:(0,Q.jsx)(y,{className:`h-4 w-4`})})]})}),(0,Q.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,Q.jsx)(ze,{models:L,selectedModel:re,onModelChange:Ne,getModelValue:Ee,className:`w-full`,compact:!0,showImageGen:K})}),(0,Q.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,Q.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,Q.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,Q.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,Q.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,Q.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:F?.background?{backgroundImage:`url(${F.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[F?.background&&(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,Q.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[f?.isPrivate&&(0,Q.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,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,Q.jsx)(B,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,Q.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),F&&!f?.isPrivate&&(0,Q.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,Q.jsx)(un,{persona:F,onClear:()=>{f&&G.updateSession(f.id,{model:F.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);J.setState(t=>({sessions:t.sessions.map(t=>t.id===f.id?e.data:t),currentSession:e.data}))}).catch(t=>{gn.error(`Failed to remove persona:`,t),w.error(e(`chat.persona.removeFailed`))})}})}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`button`,{onClick:()=>ue(e=>!e),className:q(`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,Q.jsx)(p,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(qt,{messages:f.messages,streamingMessage:P,streamingMessageId:te,isStreaming:N,toolActivities:ne,onRegenerate:j,onSelectBranch:M,onEditResend:ee,followUpSuggestions:pe,onFollowUpSelect:e=>Pe(e),className:`flex-1`}),(0,Q.jsx)(on,{onSendMessage:Pe,onStopGeneration:A,disabled:!f})]}),(0,Q.jsx)(ln,{session:f,open:le,onClose:()=>ue(!1)})]})]})]})};export{yn as ChatPage,yn 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{d as r}from"./router-vendor-Ca9zqOqT.js";import{t as i}from"./useTranslation-CdeLZqSW.js";import{T as a,Ut as o,c as s,hn as c,tt as l,un as u,wt as d}from"./ui-vendor-D_pYT79f.js";import{i as f,n as p,t as m}from"./utils-BhpNrGnR.js";import{t as h}from"./chatStore-DmDbolTg.js";import{l as g,n as _}from"./authStore-gv_MgDKr.js";import{a as v,i as y,o as b,s as x}from"../assets/index-_lG_lwU-.js";import{t as S}from"./work-DVgm81bJ.js";var C=e(n(),1),w=t(),T=e=>e<5?[`home.greeting.night`,`Up late`]:e<12?[`home.greeting.morning`,`Morning`]:e<18?[`home.greeting.afternoon`,`Afternoon`]:[`home.greeting.evening`,`Evening`],E=`mb-2 text-xs font-medium text-gray-500 dark:text-dark-500`,D=`group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-start text-sm text-gray-700 transition-colors hover:bg-white hover:text-gray-950 dark:text-dark-700 dark:hover:bg-dark-200 dark:hover:text-dark-950 outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`,O=()=>{let{t:e,i18n:t}=i(),n=r(),{user:O,systemInfo:k,isAdmin:A}=_(),j=h(e=>e.sessions),M=g(e=>e.tasks),N=g(e=>e.capabilities),P=g(e=>e.loadTasks),F=g(e=>e.loadCapabilities),I=k?.requiresAuth===!1||A(),L=I;(0,C.useEffect)(()=>{I&&(P(!0).catch(()=>{}),F().catch(()=>{}))},[I,P,F]);let[R,z]=T(new Date().getHours()),B=e(R,z),V=O?.username,H=[...j].sort((e,t)=>t.updatedAt-e.updatedAt).slice(0,4),U=[...M].sort((e,t)=>new Date(t.updatedAt).getTime()-new Date(e.updatedAt).getTime()).slice(0,3),W=N?.activeRuntimes?.user??0,G=f()?`⌘`:`Ctrl`,K=H.length>0||U.length>0;return(0,w.jsx)(`div`,{"data-testid":`home-page`,className:`h-full overflow-y-auto scrollbar-thin`,children:(0,w.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-xl flex-col justify-center px-6 py-12`,children:[(0,w.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-gray-950 dark:text-dark-950`,children:V?`${B}, ${V}.`:`${B}.`}),(0,w.jsxs)(`p`,{className:`mt-1 font-mono text-xs text-gray-400 dark:text-dark-500`,children:[window.location.host||`Libre WebUI`,k?.version?` · v${k.version}`:``]}),(0,w.jsxs)(`div`,{className:`mt-8`,children:[(0,w.jsx)(`p`,{className:E,children:e(`home.start`,`Start`)}),(0,w.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[(0,w.jsxs)(`button`,{type:`button`,"data-testid":`home-new-chat`,className:D,onClick:()=>v(n),children:[(0,w.jsx)(l,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,w.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newChat`,`New Chat`)}),(0,w.jsxs)(`span`,{className:`font-mono text-[10px] tracking-wide text-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,children:[G,`⇧O`]})]}),(0,w.jsxs)(`button`,{type:`button`,"data-testid":`home-incognito-chat`,className:D,onClick:()=>y(n),children:[(0,w.jsx)(d,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,w.jsx)(`span`,{className:`flex-1`,children:e(`chat.session.incognito`,`Incognito Chat`)})]}),I&&(0,w.jsxs)(`button`,{type:`button`,"data-testid":`home-new-work`,className:D,onClick:()=>b(n),children:[(0,w.jsx)(u,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,w.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newWork`,`New Work`)}),(0,w.jsxs)(`span`,{className:`font-mono text-[10px] tracking-wide text-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,children:[G,`⇧U`]})]})]})]}),K&&(0,w.jsxs)(`div`,{className:`mt-8`,children:[(0,w.jsxs)(`div`,{className:`mb-2 flex items-baseline justify-between`,children:[(0,w.jsx)(`p`,{className:m(E,`mb-0`),children:e(`home.continue`,`Continue`)}),I&&W>0&&(0,w.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,w.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse-subtle rounded-full bg-[rgb(48,121,255)]`}),W,` `,e(`home.active`,`active`)]})]}),(0,w.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[U.map(r=>{let i=x[r.status];return(0,w.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-work`,className:D,onClick:()=>n(`/work/${r.id}`),children:[(0,w.jsx)(`span`,{"aria-hidden":`true`,className:m(`h-2 w-2 shrink-0 rounded-full ring-1 ring-black/[0.06] dark:ring-white/[0.1]`,i.animated&&`animate-pulse-subtle`),style:{backgroundColor:i.color}}),(0,w.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`work.tasks.untitled`,`Untitled task`)}),r.hostPath&&(0,w.jsx)(`span`,{className:`hidden max-w-[14rem] shrink-0 truncate font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,title:r.hostPath,children:r.hostPath}),(0,w.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:S(r)?e(i.labelKey,i.label):p(new Date(r.updatedAt).getTime(),t.language)})]},r.id)}),H.map(r=>(0,w.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-chat`,className:D,onClick:()=>n(`/c/${r.id}`),children:[(0,w.jsx)(l,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,w.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`tabs.chat`,`Chat`)}),(0,w.jsx)(`span`,{className:`hidden shrink-0 font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,children:r.model}),(0,w.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:p(r.updatedAt,t.language)})]},r.id))]})]}),(0,w.jsxs)(`div`,{className:`mt-8`,children:[(0,w.jsx)(`p`,{className:E,children:e(`home.explore`,`Explore`)}),(0,w.jsx)(`div`,{className:`-mx-2.5 flex flex-col`,children:[[`/models`,o,e(`sidebar.navigation.models`,`Models`)],[`/personas`,s,e(`sidebar.navigation.personas`,`Personas`)],[`/gallery`,a,e(`sidebar.navigation.imagine`,`Imagine`)],...L?[[`/agents`,c,e(`sidebar.navigation.agents`,`Agents`)]]:[]].map(([e,t,r])=>(0,w.jsxs)(`button`,{type:`button`,className:D,onClick:()=>n(e),children:[(0,w.jsx)(t,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,w.jsx)(`span`,{className:`flex-1`,children:r})]},e))})]})]})})};export{O as HomePage,O 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{B as i,H as a,P as o,Rt as s,Tn as c,Y as l,m as u}from"./ui-vendor-D_pYT79f.js";import{t as d}from"./logger-DSXjF4ye.js";import{v as f}from"./api-DVP8xiYT.js";import{n as p,t as m}from"./utils-BhpNrGnR.js";import{t as h}from"./Button-X9TT9gTD.js";import"./ui-DDlcz2oy.js";import{t as g}from"./RichMessageContent-DYRrXJ75.js";var _=e(n(),1),v=t(),y=d(`pages:notes`),b=800,x=()=>{let{t:e,i18n:t}=r(),[n,d]=(0,_.useState)([]),[x,S]=(0,_.useState)(!0),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(``),[D,O]=(0,_.useState)(``),[k,A]=(0,_.useState)(``),[j,M]=(0,_.useState)(!1),[N,P]=(0,_.useState)(`idle`),F=(0,_.useRef)(null),I=(0,_.useMemo)(()=>n.find(e=>e.id===C)??null,[n,C]);(0,_.useEffect)(()=>{let e=!1;return f.getNotes().then(t=>{e||t.success&&t.data&&d(t.data)}).catch(e=>y.error(`Failed to load notes:`,e)).finally(()=>{e||S(!1)}),()=>{e=!0}},[]);let L=e=>{B(),w(e.id),O(e.title),A(e.content),M(!1),P(`idle`)},R=(e,t,n)=>{F.current!==null&&window.clearTimeout(F.current),P(`saving`),F.current=window.setTimeout(()=>{F.current=null,z(e,t,n)},b)},z=async(t,n,r)=>{try{let e=await f.updateNote(t,{title:n,content:r});if(e.success&&e.data){let n=e.data;d(e=>[n,...e.filter(e=>e.id!==t)].sort((e,t)=>t.updatedAt-e.updatedAt)),P(`saved`)}}catch(t){y.error(`Failed to save note:`,t),c.error(e(`notes.saveFailed`)),P(`idle`)}},B=()=>{F.current!==null&&C&&(window.clearTimeout(F.current),F.current=null,z(C,D,k))};(0,_.useEffect)(()=>()=>{F.current!==null&&window.clearTimeout(F.current)},[]);let V=async()=>{try{let e=await f.createNote(``,``);if(e.success&&e.data){let t=e.data;d(e=>[t,...e]),L(t)}}catch(t){y.error(`Failed to create note:`,t),c.error(e(`notes.createFailed`))}},H=async t=>{if(window.confirm(e(`notes.deleteConfirm`)))try{(await f.deleteNote(t)).success&&(d(e=>e.filter(e=>e.id!==t)),C===t&&w(null))}catch(t){y.error(`Failed to delete note:`,t),c.error(e(`notes.deleteFailed`))}},U=(0,_.useMemo)(()=>{let e=T.trim().toLowerCase();return e?n.filter(t=>t.title.toLowerCase().includes(e)||t.content.toLowerCase().includes(e)):n},[n,T]);return(0,v.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,v.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col border-e border-black/[0.06] dark:border-white/[0.07]`,children:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,v.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`notes.title`)}),(0,v.jsx)(h,{size:`sm`,variant:`ghost`,onClick:()=>void V(),className:`h-7 w-7 p-0`,title:e(`notes.new`),children:(0,v.jsx)(i,{className:`h-4 w-4`})})]}),(0,v.jsxs)(`div`,{className:`relative mx-3 mb-2`,children:[(0,v.jsx)(o,{className:`pointer-events-none absolute start-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-gray-400 dark:text-dark-500`}),(0,v.jsx)(`input`,{type:`search`,value:T,onChange:e=>E(e.target.value),placeholder:e(`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-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:bg-white/[0.05] dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,v.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:x?null:U.length===0?(0,v.jsxs)(`div`,{className:`px-3 py-10 text-center`,children:[(0,v.jsx)(l,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,v.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`notes.empty`)})]}):(0,v.jsx)(`div`,{className:`space-y-0.5`,children:U.map(n=>(0,v.jsxs)(`div`,{onClick:()=>L(n),className:m(`group cursor-pointer rounded-lg px-2.5 py-2 transition-colors`,C===n.id?`bg-white ring-1 ring-black/[0.04] dark:bg-dark-200 dark:ring-white/[0.05]`:`hover:bg-white/60 dark:hover:bg-dark-200/60`),children:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,v.jsx)(`p`,{className:`truncate text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:n.title||e(`notes.untitled`)}),(0,v.jsx)(`button`,{onClick:e=>{e.stopPropagation(),H(n.id)},className:`shrink-0 rounded-md p-1 text-red-500 opacity-0 transition-opacity hover:bg-red-50 group-hover:opacity-100 dark:hover:bg-red-900/20`,title:e(`common.delete`),children:(0,v.jsx)(u,{className:`h-3 w-3`})})]}),(0,v.jsxs)(`p`,{className:`mt-0.5 truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[p(n.updatedAt,t.language),n.content.trim()&&(0,v.jsxs)(v.Fragment,{children:[` · `,n.content.trim().slice(0,60)]})]})]},n.id))})})]}),(0,v.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:I?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/[0.06] px-5 py-3 dark:border-white/[0.07]`,children:[(0,v.jsx)(`input`,{dir:`auto`,value:D,onChange:e=>{O(e.target.value),R(I.id,e.target.value,k)},placeholder:e(`notes.untitled`),className:`min-w-0 flex-1 bg-transparent text-lg font-semibold text-gray-950 placeholder:text-gray-400 focus:outline-none dark:text-dark-950 dark:placeholder:text-dark-500`}),(0,v.jsx)(`span`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:N===`saving`?e(`common.saving`):N===`saved`?e(`notes.saved`):``}),(0,v.jsx)(h,{size:`sm`,variant:`ghost`,onClick:()=>M(e=>!e),className:`h-8 gap-1.5 px-2.5 text-xs`,children:j?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(a,{className:`h-3.5 w-3.5`}),e(`common.edit`)]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(s,{className:`h-3.5 w-3.5`}),e(`artifacts.preview`)]})})]}),j?(0,v.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-5 py-4 scrollbar-thin`,children:(0,v.jsx)(g,{content:k})}):(0,v.jsx)(`textarea`,{dir:`auto`,value:k,onChange:e=>{A(e.target.value),R(I.id,D,e.target.value)},onBlur:B,placeholder:e(`notes.contentPlaceholder`),className:`min-h-0 flex-1 resize-none bg-transparent px-5 py-4 font-mono text-[13.5px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:outline-none dark:text-dark-900 dark:placeholder:text-dark-500`})]}):(0,v.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,v.jsxs)(`div`,{className:`text-center`,children:[(0,v.jsx)(l,{className:`mx-auto mb-3 h-8 w-8 text-gray-300 dark:text-dark-400`}),(0,v.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-dark-600`,children:e(`notes.selectOrCreate`)}),(0,v.jsxs)(h,{size:`sm`,onClick:()=>void V(),className:`mt-4 gap-1.5`,children:[(0,v.jsx)(i,{className:`h-3.5 w-3.5`}),e(`notes.new`)]})]})})})]})};export{x as NotesPage,x 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{a as i,n as a,o}from"./i18n-xir4Zz7C.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-DVP8xiYT.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-DmDbolTg.js";import{c as Me,n as Ne}from"./authStore-gv_MgDKr.js";import{a as Pe,n as Fe,o as Ie,t as Le}from"./appStore-Cw7PmG-J.js";import{t as z}from"./Button-X9TT9gTD.js";import{d as B,f as Re}from"./ui-DDlcz2oy.js";import{c as ze,f as Be,u as Ve}from"../assets/index-_lG_lwU-.js";var V=e(n(),1),H=t(),He=[{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`}],Ue=[`settings.about.features.privacy`,`settings.about.features.openSource`,`settings.about.features.localInference`];function We({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)(ze,{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:Ue.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:He.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 Ge=P(`components:background-upload`),Ke=({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){Ge.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){Ge.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){Ge.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){Ge.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`})]})]})]})})},qe=()=>{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 Je({theme:e,preferences:t,onThemeChange:n,onAccentChange:i,onCustomAccentChange:a,onAdaptToAccentChange:o,onShowUsernameChange:s,onShowFollowUpsChange:c}){let{t:l}=r(),u=e.accent||`blue`,d=e.customAccent||`#2563eb`,f=Pe(e);return(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsx)(qe,{}),(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:l(`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`}),l(`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`}),l(`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:l(`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:f},"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=u===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":l(`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 ${u===`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:l(`settings.appearance.accent.custom`,{defaultValue:`Custom color`}),"aria-label":l(`settings.appearance.accent.custom`,{defaultValue:`Custom color`}),children:[(0,H.jsx)(`input`,{type:`color`,value:d,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:d},"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:l(`settings.appearance.accent.behaviorTitle`)}),(0,H.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:l(`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:l(`settings.appearance.accent.defaultStyle`)}),(0,H.jsx)(`span`,{className:`mt-1 block text-xs leading-snug text-gray-500 dark:text-dark-500`,children:l(`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:l(`settings.appearance.accent.adaptedStyle`)}),(0,H.jsx)(`span`,{className:`mt-1 block text-xs leading-snug text-gray-500 dark:text-dark-500`,children:l(`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:l(`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:l(`settings.appearance.chatInterface.showUsername`)}),(0,H.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l(`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:l(`settings.appearance.chatInterface.followUpSuggestions`)}),(0,H.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l(`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.jsx)(Ke,{})]})}function Ye(){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 Xe({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)(Ye,{})]})}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 Ze({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)($e,{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)($e,{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)($e,{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)(Qe,{})]})})}function Qe(){let{t:e}=r(),t=Be(),[n,i]=(0,V.useState)(``),{data:a}=Ve({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 $e({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 et({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)(tt,{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)(tt,{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)(tt,{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)(nt,{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)(nt,{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)(nt,{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 tt({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 nt({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 rt({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 it({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)(at,{label:`${S(`settings.model.name`)}:`,value:t,truncate:!0}),E?.details&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(at,{label:`${S(`settings.model.size`)}:`,value:E.details.parameter_size}),(0,H.jsx)(at,{label:`${S(`settings.model.family`)}:`,value:E.details.family}),(0,H.jsx)(at,{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)(Re,{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)(ot,{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 at({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 ot({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 st=8;function ct(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 lt(e){try{return new URL(e.trim()).protocol===`http:`}catch{return!1}}function ut(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 dt(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<=st;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===st)return!1;n=t}return!1}var ft=new Set([`api_mode`,`api_path`,`endpoint`,`base_url`,`api_url`,`image_endpoint`,`embedding_endpoint`,`tts_endpoint`,`model`,`model_id`,`models_endpoint`]);function pt(e){let t=new Set(ft),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 mt(e,t){return pt(t).has(e)}function ht(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 gt(e,t){let n=[],r=[];for(let i of e)(mt(i.name,t)?n:r).push(i);return{connection:n,advanced:r}}function _t(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 vt(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=ht(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 G=({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)(()=>pt(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)(()=>gt(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=_t(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=ht(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(ut(r.name)&&typeof i==`string`&&!a){let e=ct(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&&!dt(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=vt(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(_t(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(!ut(t.name))return!1;let n=d[t.name],r=ht(t,e),i=typeof n==`string`&&n.trim()?n:r;return typeof i==`string`&&lt(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=ht(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 yt({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)(bt,{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 bt({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=pt(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)(St,{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)(G,{plugin:e},e.id)]})]}),(0,H.jsx)(xt,{catalog:k,canRefresh:Oe(e),refreshing:c,onRefresh:g})]})}function xt({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 St({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 Ct({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 wt({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 Tt=`0.19.0`,Et=`__current_running_model__`,Dt={enabled:!1,model:`nomic-embed-text`,chunkSize:1e3,chunkOverlap:200,similarityThreshold:.7},Ot={enabled:!1,autoPlay:!1,model:``,voice:``,speed:1,pluginId:``,streamSentences:!1},kt={enabled:!1,model:``,size:`1024x1024`,quality:`standard`,style:`vivid`,pluginId:``},K=({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===Et?Et: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:Et,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,Re]=(0,V.useState)(`appearance`),[ze,He]=(0,V.useState)(``),[Ue,Ge]=(0,V.useState)(c),[Ke,qe]=(0,V.useState)(!1),[Ye,U]=(0,V.useState)(null),[Qe,$e]=(0,V.useState)(!1),[tt,W]=(0,V.useState)(!1),[nt,at]=(0,V.useState)(``),ot=(0,V.useRef)(null),[st,ct]=(0,V.useState)(null),[lt,ut]=(0,V.useState)({}),[dt,ft]=(0,V.useState)({}),[pt,mt]=(0,V.useState)(null),[ht,gt]=(0,V.useState)({}),[_t,vt]=(0,V.useState)(x.generationOptions||{}),[G,bt]=(0,V.useState)(x.embeddingSettings||Dt),[xt,St]=(0,V.useState)(!1),[K,At]=(0,V.useState)(x.ttsSettings||Ot),[jt,Mt]=(0,V.useState)(!1),Nt=(0,V.useRef)(null),[q,Pt]=(0,V.useState)(x.imageGenSettings||kt),{importing:Ft,showImportOptions:It,mergeStrategy:Lt,setMergeStrategy:Rt,importResult:zt,setImportResult:Bt,importFileInputRef:Vt,handleExportData:Ht,handleImportFileSelect:Ut,handleConfirmImport:Wt,handleCancelImport:Gt}=wt({preferences:x,sessions:m,loadPreferences:C,loadSessions:v}),J=Be(),{data:Kt={}}=Ve({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:qt=[]}=Ve({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=qt.find(e=>e.id===G.model||e.rawModel===G.model);return e&&e.id!==G.model?{...G,model:e.id}:G},[qt,G]),{data:Jt=null}=Ve({queryKey:[`embedding-status`],queryFn:async()=>{let e=await L.getEmbeddingStatus();return e.success&&e.data?e.data:null},enabled:e}),{data:Yt,isLoading:Xt}=Ve({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)(()=>Yt?.models??[],[Yt]),Zt=Yt?.plugins??[],Qt=(0,V.useMemo)(()=>fe(X,K.model,K.pluginId),[X,K.model,K.pluginId]),Z=(0,V.useMemo)(()=>{if(!Qt)return K;let e=me(X,K.model,K.pluginId);return e&&K.pluginId===e.plugin?K:{...K,model:Qt.model,pluginId:Qt.plugin,voice:Qt.config?.default_voice||``}},[Qt,X,K]),$t=(0,V.useMemo)(()=>me(X,Z.model,Z.pluginId)?.config?.voices??[],[Z,X]),{data:en,isLoading:tn}=Ve({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)(()=>en?.models??[],[en]),nn=(0,V.useMemo)(()=>en?.plugins??[],[en]),$=(0,V.useMemo)(()=>ve(Q,q.model,q.pluginId),[Q,q.model,q.pluginId]),rn=(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,$]),an=$?.config?.sizes??[],on=$?.config?.qualities??[],sn=$?.config?.styles??[],cn=(0,V.useRef)(!1),ln=(0,V.useRef)(c);(0,V.useEffect)(()=>{if(!e){cn.current=!1;return}cn.current&&ln.current===c||(cn.current=!0,ln.current=c,Ge(c),vt(x.generationOptions||{}),bt(x.embeddingSettings||Dt),At(x.ttsSettings||Ot),Pt(x.imageGenSettings||kt))},[e,x.embeddingSettings,x.generationOptions,x.imageGenSettings,x.ttsSettings,c]);let un=(0,V.useRef)(!1);(0,V.useEffect)(()=>{if(!e){un.current=!1;return}un.current||(un.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 dn=async e=>{let t=lt[e];if(!t?.trim()){g.error(`Please enter an API key`);return}mt(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`]}),ut(t=>({...t,[e]:``})),ft(t=>({...t,[e]:!1}))):g.error(n.error||`Failed to save API key`)}catch{g.error(`Failed to save API key`)}finally{mt(null)}},fn=async e=>{mt(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`]}),ut(t=>({...t,[e]:``}))):g.error(t.error||`Failed to remove API key`)}catch{g.error(`Failed to remove API key`)}finally{mt(null)}},pn=(e,t)=>{let n=me(X,e,t);n&&At(r=>({...r,model:e,pluginId:t,voice:n.config?.default_voice||r.voice}))},mn=(e,t)=>{let n=be(Q,e,t);n&&Pt(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`)}))},hn=(e,t)=>{At(n=>({...n,[e]:t}))},gn=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)}},_n=async()=>{if(jt){let e=Nt.current;e&&(e.pause(),e.currentTime=0,Nt.current=null),Mt(!1);return}Mt(!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:Qt?.config?.default_format});if(e.success&&e.data?.audio){let t=`data:${e.data.mimeType};base64,${e.data.audio}`,n=new Audio(t);Nt.current=n,n.onended=()=>{Mt(!1),Nt.current=null},n.onerror=()=>{g.error(`Failed to play audio`),Mt(!1),Nt.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),Mt(!1)}},vn=()=>{At({enabled:!1,autoPlay:!1,model:X[0]?.model||``,voice:X[0]?.config?.default_voice||``,speed:1,pluginId:X[0]?.plugin||``,streamSentences:!1})},yn=(e,t)=>{Pt(n=>({...n,[e]:t}))},bn=async()=>{try{let e=await I.updatePreferences({imageGenSettings:rn});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)}},xn=()=>{Pt({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||``})},Sn=async()=>{try{St(!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{St(!1)}},Cn=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)}},wn=async e=>{let t=e.target.files?.[0];t&&(await j(t),$e(!1),ot.current&&(ot.current.value=``),await h(),await J.invalidateQueries({queryKey:[`image-gen-data`]}))},Tn=async()=>{try{let e=JSON.parse(nt);await le(e),W(!1),at(``),await h(),await J.invalidateQueries({queryKey:[`image-gen-data`]})}catch{N(),g.error(`Invalid JSON format`)}},En=async e=>{w.find(t=>t.id===e)?.active?await oe(e):await ae(e),await h(),await J.invalidateQueries({queryKey:[`image-gen-data`]})},Dn=async e=>{if(!ht[e]){gt(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{gt(t=>{let n={...t};return delete n[e],n})}}},On=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`]}))},kn=async e=>{await se(e)};if(!e)return null;let An=e=>{let t=Le.getState().theme,n=Ie({...t,mode:e});b(n)},jn=e=>{let t=Le.getState().theme,n=Ie({...t,accent:e});b(n)},Mn=e=>{let t=Le.getState().theme,n=Ie({...t,accent:`custom`,customAccent:e});b(n)},Nn=e=>{let t=Le.getState().theme,n=Ie({...t,adaptToAccent:e});b(n)},Pn=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)})},Fn=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)})},In=e=>{if(!e.target.value){Ae.setState({selectedModel:``,selectedProviderType:null,selectedProviderId:null}),Cn({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`))},Ln=e=>{Ge(e.target.value)},Rn=()=>{u(Ue),Cn({systemMessage:Ue}),g.success(`System message updated`)},zn=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`))},Bn=async()=>{qe(!0),U(null),he.pullAllModelsStream(e=>{U(e)},()=>{qe(!1),U(null),g.success(`All models updated successfully!`),h()},e=>{qe(!1),U(null),g.error(`Failed to update models: `+e)})},Vn=e=>{let t={...x.titleSettings,autoTitle:e,taskModel:x.titleSettings?.taskModel||``};S({titleSettings:t}),I.updatePreferences({titleSettings:t})},Hn=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}))})},Un=e=>{let t=e&&e!==Et?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})},Wn=(e,t)=>{ut(n=>({...n,[e]:t}))},Gn=(e,t)=>{ft(n=>({...n,[e]:t}))},Kn=(e,t)=>{vt(n=>({...n,[e]:t}))},qn=async()=>{try{let e=await I.setGenerationOptions(_t);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)}},Jn=async()=>{try{let e=await I.resetGenerationOptions();e.success&&e.data&&(S(e.data),vt(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)}},Yn=(e,t)=>{bt(n=>({...n,[e]:t}))},Xn=[...qt.map(e=>({value:e.id,label:`${e.name} (${e.pluginName||e.provider})`})),...!qt.find(e=>e.id===Y.model||e.rawModel===Y.model)&&Y.model?[{value:Y.model,label:`${Y.model} (current)`}]:[]],Zn=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)}},Qn=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)}},$n={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`},er=ze.trim().toLowerCase(),tr=e=>!er||e.label.toLowerCase().includes(er)||($n[e.id]||``).includes(er),nr=[{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:ze,onChange:e=>{let t=e.target.value;He(t);let n=t.trim().toLowerCase();if(!n)return;let r=nr.flatMap(e=>e.tabs).filter(e=>e.label.toLowerCase().includes(n)||($n[e.id]||``).includes(n));r.length>0&&!r.some(e=>e.id===B)&&Re(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:nr.map(e=>({...e,tabs:e.tabs.filter(tr)})).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:()=>Re(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)(Je,{theme:y,preferences:x,onThemeChange:An,onAccentChange:jn,onCustomAccentChange:Mn,onAdaptToAccentChange:Nn,onShowUsernameChange:Pn,onShowFollowUpsChange:Fn});case`models`:return(0,H.jsx)(it,{models:n,selectedModel:i,selectedProviderType:a,selectedProviderId:o,systemMessage:c,tempSystemMessage:Ue,loading:f,preferences:x,currentVisionModel:Ne,visionModelOptions:Pe,currentTaskModel:we,autoTitleTaskModelOptions:Fe,updatingAllModels:Ke,updateProgress:Ye,onModelChange:In,onSystemMessageChange:Ln,onSystemMessageSave:Rn,onAutoTitleChange:Vn,onAutoTitleTaskModelChange:Un,onVisionModelChange:Hn,onUpdateAllModels:Bn});case`tts`:return(0,H.jsx)(Ct,{loading:Xt,settings:K,effectiveSettings:Z,models:X,plugins:Zt,voices:$t,testing:jt,onSettingChange:hn,onModelChange:pn,onReset:vn,onTest:_n,onSave:gn});case`image-gen`:return(0,H.jsx)(rt,{loading:tn,settings:q,effectiveSettings:rn,models:Q,plugins:nn,sizes:an,qualities:on,styles:sn,onSettingChange:yn,onModelChange:mn,onReset:xn,onSave:bn});case`documents`:return(0,H.jsx)(Ze,{settings:G,effectiveSettings:Y,modelOptions:Xn,status:Jt,regenerating:xt,onSettingChange:Yn,onReset:Qn,onRegenerate:Sn,onSave:Zn});case`plugins`:return(0,H.jsx)(yt,{plugins:w,loading:E,uploading:ee,error:ne,hasKeys:Kt,showUploadForm:Qe,showJsonForm:tt,jsonInput:nt,fileInputRef:ot,expandedPluginId:st,pluginApiKeys:lt,showApiKey:dt,savingApiKey:pt,refreshingPluginIds:ht,onClearError:N,onShowUploadFormChange:$e,onShowJsonFormChange:W,onJsonInputChange:at,onFileUpload:wn,onJsonSubmit:Tn,onExpandedPluginChange:ct,onPluginApiKeyChange:Wn,onShowApiKeyChange:Gn,onActivatePlugin:En,onRefreshModels:Dn,onDeletePlugin:On,onExportPlugin:kn,onSaveApiKey:dn,onDeleteApiKey:fn});case`data`:return(0,H.jsx)(Xe,{sessionCount:m.length,loading:f,importing:Ft,showImportOptions:It,mergeStrategy:Lt,importResult:zt,importFileInputRef:Vt,onExportData:Ht,onImportFileSelect:Ut,onClearAllHistory:zn,onMergeStrategyChange:Rt,onConfirmImport:Wt,onCancelImport:Gt,onDismissImportResult:()=>Bt(null)});case`about`:return(0,H.jsx)(We,{appVersion:Tt});case`generation`:return(0,H.jsx)(et,{generationOptions:_t,embeddingSettings:G,effectiveEmbeddingSettings:Y,embeddingModelOptions:Xn,embeddingStatus:Jt,onGenerationOptionChange:Kn,onEmbeddingSettingsChange:Yn,onResetGenerationOptions:Jn,onSaveGenerationOptions:qn,onResetEmbeddingSettings:Qn,onSaveEmbeddingSettings:Zn});default:return null}})()})]})]})})]})};export{K as SettingsModal};