libre-webui 0.19.6 → 0.20.0

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 (139) hide show
  1. package/README.md +2 -2
  2. package/backend/dist/db.d.ts.map +1 -1
  3. package/backend/dist/db.js +29 -0
  4. package/backend/dist/db.js.map +1 -1
  5. package/backend/dist/index.d.ts.map +1 -1
  6. package/backend/dist/index.js +12 -10
  7. package/backend/dist/index.js.map +1 -1
  8. package/backend/dist/routes/work.d.ts.map +1 -1
  9. package/backend/dist/routes/work.js +138 -4
  10. package/backend/dist/routes/work.js.map +1 -1
  11. package/backend/dist/services/systemDiagnosticsService.d.ts +4 -3
  12. package/backend/dist/services/systemDiagnosticsService.d.ts.map +1 -1
  13. package/backend/dist/services/systemDiagnosticsService.js +35 -34
  14. package/backend/dist/services/systemDiagnosticsService.js.map +1 -1
  15. package/backend/dist/services/workAccessService.d.ts +15 -0
  16. package/backend/dist/services/workAccessService.d.ts.map +1 -0
  17. package/backend/dist/services/workAccessService.js +67 -0
  18. package/backend/dist/services/workAccessService.js.map +1 -0
  19. package/backend/dist/services/workAdminService.d.ts +67 -0
  20. package/backend/dist/services/workAdminService.d.ts.map +1 -0
  21. package/backend/dist/services/workAdminService.js +92 -0
  22. package/backend/dist/services/workAdminService.js.map +1 -0
  23. package/backend/dist/services/workKubernetesDriver.d.ts +74 -0
  24. package/backend/dist/services/workKubernetesDriver.d.ts.map +1 -0
  25. package/backend/dist/services/workKubernetesDriver.js +659 -0
  26. package/backend/dist/services/workKubernetesDriver.js.map +1 -0
  27. package/backend/dist/services/workPolicyService.d.ts +58 -0
  28. package/backend/dist/services/workPolicyService.d.ts.map +1 -0
  29. package/backend/dist/services/workPolicyService.js +249 -0
  30. package/backend/dist/services/workPolicyService.js.map +1 -0
  31. package/backend/dist/services/workPreviewProxyService.d.ts +7 -1
  32. package/backend/dist/services/workPreviewProxyService.d.ts.map +1 -1
  33. package/backend/dist/services/workPreviewProxyService.js +36 -8
  34. package/backend/dist/services/workPreviewProxyService.js.map +1 -1
  35. package/backend/dist/services/workRuntimeDriver.d.ts +166 -0
  36. package/backend/dist/services/workRuntimeDriver.d.ts.map +1 -0
  37. package/backend/dist/services/workRuntimeDriver.js +737 -0
  38. package/backend/dist/services/workRuntimeDriver.js.map +1 -0
  39. package/backend/dist/services/workRuntimeService.d.ts +60 -51
  40. package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
  41. package/backend/dist/services/workRuntimeService.js +310 -658
  42. package/backend/dist/services/workRuntimeService.js.map +1 -1
  43. package/backend/dist/services/workRuntimeShared.d.ts +83 -0
  44. package/backend/dist/services/workRuntimeShared.d.ts.map +1 -0
  45. package/backend/dist/services/workRuntimeShared.js +136 -0
  46. package/backend/dist/services/workRuntimeShared.js.map +1 -0
  47. package/backend/dist/services/workTaskService.d.ts +6 -1
  48. package/backend/dist/services/workTaskService.d.ts.map +1 -1
  49. package/backend/dist/services/workTaskService.js +18 -3
  50. package/backend/dist/services/workTaskService.js.map +1 -1
  51. package/backend/dist/services/workTerminalService.d.ts +2 -22
  52. package/backend/dist/services/workTerminalService.d.ts.map +1 -1
  53. package/backend/dist/services/workTerminalService.js +10 -127
  54. package/backend/dist/services/workTerminalService.js.map +1 -1
  55. package/backend/dist/types/work.d.ts +4 -0
  56. package/backend/dist/types/work.d.ts.map +1 -1
  57. package/backend/dist/utils/dockerEndpoint.d.ts +37 -0
  58. package/backend/dist/utils/dockerEndpoint.d.ts.map +1 -0
  59. package/backend/dist/utils/dockerEndpoint.js +72 -0
  60. package/backend/dist/utils/dockerEndpoint.js.map +1 -0
  61. package/backend/dist/workTerminalServer.d.ts.map +1 -1
  62. package/backend/dist/workTerminalServer.js +6 -5
  63. package/backend/dist/workTerminalServer.js.map +1 -1
  64. package/backend/package.json +2 -1
  65. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  66. package/frontend/dist/assets/index-Z4-oLWDC.js +2 -0
  67. package/frontend/dist/assets/index-tBUyDbHh.css +1 -0
  68. package/frontend/dist/index.html +11 -10
  69. package/frontend/dist/js/{ArtifactContainer-Dy_1KKWg.js → ArtifactContainer-DQRF4rh-.js} +1 -1
  70. package/frontend/dist/js/{ArtifactDemoPage-Big00RwH.js → ArtifactDemoPage-BOlB1lS-.js} +1 -1
  71. package/frontend/dist/js/{ArtifactSandboxFrame-C_S4j076.js → ArtifactSandboxFrame-DqU5GDrI.js} +2 -2
  72. package/frontend/dist/js/{ArtifactSlideOutPanel-B4-D3HkB.js → ArtifactSlideOutPanel-B0I-hCux.js} +1 -1
  73. package/frontend/dist/js/ChatPage-DyV0_oCt.js +16 -0
  74. package/frontend/dist/js/{FirstTimeSetup-C6YxrwR7.js → FirstTimeSetup-ButTmjp0.js} +1 -1
  75. package/frontend/dist/js/{GalleryPage-BtcPs7SO.js → GalleryPage-CaT63b-s.js} +1 -1
  76. package/frontend/dist/js/HomePage-BWyg3nHu.js +1 -0
  77. package/frontend/dist/js/{LibreClawPage-B14Go5Mn.js → LibreClawPage-DUd3tjQE.js} +1 -1
  78. package/frontend/dist/js/ModelSelector-COFcJnMJ.js +1 -0
  79. package/frontend/dist/js/{ModelsPage-Cc3L0ur8.js → ModelsPage-BRbTEXNL.js} +1 -1
  80. package/frontend/dist/js/{NotesPage-BwEMW-Z3.js → NotesPage-CTutDN50.js} +1 -1
  81. package/frontend/dist/js/{PersonasPage-e-CbTxP3.js → PersonasPage-C6iTMI3N.js} +2 -2
  82. package/frontend/dist/js/{PluginUsagePage-CvZMJJwv.js → PluginUsagePage-BQQ0-_PP.js} +1 -1
  83. package/frontend/dist/js/{RichMessageContent-DNl3_CIw.js → RichMessageContent-DPqeqxkQ.js} +1 -1
  84. package/frontend/dist/js/SettingsModal-C_1k75Kv.js +1 -0
  85. package/frontend/dist/js/SettingsToggle-bZ5W4CCf.js +1 -0
  86. package/frontend/dist/js/SystemPage-CUecyRPh.js +1 -0
  87. package/frontend/dist/js/UserManagementPage-CZ4KMOY9.js +1 -0
  88. package/frontend/dist/js/WorkPage-BqDcfXV6.js +5 -0
  89. package/frontend/dist/js/api-iCpOEijB.js +14 -0
  90. package/frontend/dist/js/{appStore-BpoXhleX.js → appStore-DTd6dWg2.js} +2 -2
  91. package/frontend/dist/js/{ar-ClMsdoTH.js → ar-C8YV99Y-.js} +1 -1
  92. package/frontend/dist/js/authStore-CuK4HUVh.js +4 -0
  93. package/frontend/dist/js/{bn-LyPol_AY.js → bn-C9dcls7_.js} +1 -1
  94. package/frontend/dist/js/chatStore-VNT0eHRB.js +2 -0
  95. package/frontend/dist/js/{config-CuXlcWP1.js → config--Xp9rZtJ.js} +1 -1
  96. package/frontend/dist/js/{cs-D98fZaKF.js → cs-DtL8VeeX.js} +1 -1
  97. package/frontend/dist/js/{da-M7ND0GQR.js → da-U3aNn1aF.js} +1 -1
  98. package/frontend/dist/js/{de-BV0q1kzb.js → de-DzuyeVpX.js} +1 -1
  99. package/frontend/dist/js/{es-C7FvsVoN.js → es-OiU8plii.js} +1 -1
  100. package/frontend/dist/js/{estree-BuWOCMW0.js → estree-BAQkciRX.js} +1 -1
  101. package/frontend/dist/js/{fr-5SloN0ok.js → fr-DDa3R8bs.js} +1 -1
  102. package/frontend/dist/js/{hi-C6VeRgeR.js → hi-D8Y0hl34.js} +1 -1
  103. package/frontend/dist/js/{html-D7tW7UvW.js → html-DxA-Bcvi.js} +1 -1
  104. package/frontend/dist/js/{i18n-CLd1FZPx.js → i18n-BqWNFeNo.js} +1 -1
  105. package/frontend/dist/js/{id-CkVp7Z1Z.js → id-BwcWtkBv.js} +1 -1
  106. package/frontend/dist/js/{is-DqxnBX4W.js → is-DzfQHQih.js} +1 -1
  107. package/frontend/dist/js/{it-CiW4_O5V.js → it-C5VU3_Je.js} +1 -1
  108. package/frontend/dist/js/{ja-BZ3Sdund.js → ja-DLhOhxvf.js} +1 -1
  109. package/frontend/dist/js/{ko-CS7LAhfJ.js → ko-CCKiyQD6.js} +1 -1
  110. package/frontend/dist/js/{markdown-CBSxWEtK.js → markdown-IsZpJ5ke.js} +1 -1
  111. package/frontend/dist/js/{messageCodeStyles-BlTi46wI.js → messageCodeStyles-CsV3zwyK.js} +1 -1
  112. package/frontend/dist/js/{ms-URvcYqgz.js → ms-CXXkPvWw.js} +1 -1
  113. package/frontend/dist/js/{nl-CQJpW7wK.js → nl-CA_e0Epl.js} +1 -1
  114. package/frontend/dist/js/{pl-DDMgPMAz.js → pl-BG32wdpx.js} +1 -1
  115. package/frontend/dist/js/{pt-JCqqmGn_.js → pt-BzRGWQXO.js} +1 -1
  116. package/frontend/dist/js/{ru-C_dwMbiK.js → ru-DBjn_Q-Q.js} +1 -1
  117. package/frontend/dist/js/{standalone-CaXys7q3.js → standalone-CK3b5Ktq.js} +1 -1
  118. package/frontend/dist/js/{sv-CW3c9NGx.js → sv-Hz_iRGdF.js} +1 -1
  119. package/frontend/dist/js/{th-9ARgClBr.js → th-MsyXlGH9.js} +1 -1
  120. package/frontend/dist/js/{tr-DNY5_DAg.js → tr-Cofmy_ef.js} +1 -1
  121. package/frontend/dist/js/{typescript-DQ5zi5zo.js → typescript-BMYmVohw.js} +1 -1
  122. package/frontend/dist/js/{ui-DFQiHo_k.js → ui-C2kNYwfG.js} +2 -2
  123. package/frontend/dist/js/{uk-XDh4_7IL.js → uk-B2o05LCR.js} +1 -1
  124. package/frontend/dist/js/{vi-BaoJBXnt.js → vi-CZh8uJgV.js} +1 -1
  125. package/frontend/dist/js/workApi-C33ZrPws.js +6 -0
  126. package/frontend/dist/js/{zh-B202vYJt.js → zh-DhKXi8ZA.js} +1 -1
  127. package/package.json +4 -3
  128. package/frontend/dist/assets/index-Cd0_AoYV.js +0 -23
  129. package/frontend/dist/assets/index-DtkGuqvC.css +0 -1
  130. package/frontend/dist/js/ChatPage-BkFd1iac.js +0 -16
  131. package/frontend/dist/js/HomePage-5PhpAt14.js +0 -1
  132. package/frontend/dist/js/ModelSelector-C1wN91tl.js +0 -1
  133. package/frontend/dist/js/SettingsModal-C8KJJEud.js +0 -1
  134. package/frontend/dist/js/SystemPage-8kEAS71H.js +0 -1
  135. package/frontend/dist/js/UserManagementPage-BSrZ0ucu.js +0 -1
  136. package/frontend/dist/js/WorkPage-spf92PVN.js +0 -5
  137. package/frontend/dist/js/api-MySpmAK8.js +0 -19
  138. package/frontend/dist/js/authStore-DmrydYuS.js +0 -3
  139. package/frontend/dist/js/chatStore-CWqfsOjc.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-CLd1FZPx.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 M,fn as N,ft as P,g as F,gn as I,h as ee,j as te,n as L,nn as R,o as z,on as ne,pt as re,qt as ie,r as ae,rn as B,st as oe,t as se,tt as ce,v as le,wn as V,wt as H,x as ue,yn as de}from"./ui-vendor-D_pYT79f.js";import{i as U,t as W}from"./logger-DSXjF4ye.js";import{S as G,_ as fe,a as K,b as pe,d as q,f as me,i as he,m as ge,n as _e,u as ve}from"./api-MySpmAK8.js";import{a as ye,n as be,r as xe,t as J}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 Y}from"./chatStore-CWqfsOjc.js";import{n as Oe,r as X}from"./authStore-DmrydYuS.js";import{t as ke}from"./appStore-BpoXhleX.js";import{i as Ae,r as je,t as Me}from"./welcomePrompts-to5mv_gx.js";import{l as Ne}from"./messageCodeStyles-BlTi46wI.js";import{t as Z}from"./Button-X9TT9gTD.js";import{d as Pe,f as Fe,l as Ie}from"./ui-DFQiHo_k.js";import{c as Le,s as Re}from"./ArtifactSandboxFrame-C_S4j076.js";import{t as ze}from"./ArtifactContainer-Dy_1KKWg.js";import{t as Be}from"./ModelSelector-C1wN91tl.js";var Ve=r(),Q=e(n(),1),$=t(),He=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(P,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,$.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,$.jsx)(O,{size:12}):(0,$.jsx)(B,{size:12,className:`rtl:rotate-180`}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},Ue=W(`components:ttsbutton`),We=null,Ge=null,Ke=0,qe=3e5;async function Je(e=!1){let t=Date.now();return!e&&We!==null&&t-Ke<qe?We:Ge||(Ge=(async()=>{try{let e=await K.getModels();return e.success&&e.data&&e.data.length>0?(We=e.data,Ke=t,e.data):(We=[],Ke=t,[])}catch{return We=[],Ke=t,[]}finally{Ge=null}})(),Ge)}function Ye(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Xe=({text:e,className:t,size:n=`sm`})=>{let{t:r}=s(),{preferences:i}=ke(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(!1),v=(0,Q.useRef)([]),y=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await Je(),n=_e(t,i.ttsSettings?.model,i.ttsSettings?.pluginId);i.ttsSettings?.model&&!n&&(t=await Je(!0)),e&&(p(t),h(t.length>0))})(),()=>{e=!1}},[i.ttsSettings?.model,i.ttsSettings?.pluginId]);let b=(0,Q.useCallback)(async(e,t,n,i,a,o)=>{let s=await K.generateBase64({model:t,pluginId:n,input:e,voice:i,speed:a,response_format:o});if(!s.success||!s.data?.audio)throw Error(s.message||r(`ttsButton.generateFailed`));let c=`data:${s.data.mimeType};base64,${s.data.audio}`,l=new Audio(c);return g.current=l,new Promise((e,t)=>{l.onended=()=>{g.current=null,e()},l.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},l.play().catch(t)})},[r]),x=(0,Q.useCallback)(async(e,t,n,r,i,a)=>{v.current=e,y.current=0,_.current=!1;let o=null,s=async e=>{try{let o=await K.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){Ue.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){Ue.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Q.useCallback)(()=>{_.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),o(!1),l(!1)},[]),C=async()=>{if(!c){if(a){S();return}l(!0),d(null),_.current=!1;try{let t=i.ttsSettings,n=he(f,t?.model,t?.pluginId),a=n?.model||t?.model||`tts-1`,s=n?.plugin||t?.pluginId,c=n?.model===t?.model&&(!t?.pluginId||n?.plugin===t.pluginId)?t?.voice||n?.config?.default_voice||`alloy`:n?.config?.default_voice||`alloy`,u=t?.speed||1,p=n?.config?.default_format;if(t?.streamSentences){let t=Ye(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),Ue.error(`TTS error:`,e),o(!1),l(!1)}}};if((0,Q.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},T={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,$.jsx)(`button`,{onClick:C,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:J(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,u?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,w[n],t),children:c?(0,$.jsx)(oe,{className:J(T[n],`animate-spin`)}):a?(0,$.jsx)(ue,{className:T[n]}):u?(0,$.jsx)(D,{className:T[n]}):(0,$.jsx)(z,{className:T[n]})})},Ze=new Map;function Qe(e,t,n=``){let r=Ze.get(e);if(n){if((!r||r.state===`none`)&&(Ze.set(e,{state:`open`,startedAt:Date.now()}),!t))return;let n=Ze.get(e);t&&n?.state===`open`&&Ze.set(e,{state:`done`,durationMs:Date.now()-n.startedAt});return}if(r&&r.state!==`open`||!t)return;let i=ye(t);if(!r){i.thinkingComplete?Ze.set(e,{state:`none`}):Ze.set(e,{state:`open`,startedAt:Date.now()});return}i.thinkingComplete&&Ze.set(e,{state:`done`,durationMs:Date.now()-r.startedAt})}function $e(e){let t=Ze.get(e);if(t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function et(e){let t=Ze.get(e);if(Ze.delete(e),t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function tt(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 nt=/```([^\n`]*)\n([\s\S]*?)\n```/g,rt=/^(?:%%|flowchart|graph|sequenceDiagram|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|mindmap|timeline|gitGraph|quadrantChart|requirementDiagram|sankey-beta|xychart-beta|block-beta|architecture-beta|packet-beta|kanban|radar-beta|treemap-beta|C4Context)\b/i,it=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,at=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],ot=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:ht(e[1]),title:st(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=ht(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function st(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return lt(ct(e))}function ct(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 lt(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 ut(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return st(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&st(n[1]).trim()||null}function dt(e){for(let t of[/export\s+default\s+(?:function|class)\s+([A-Z]\w*)/,/export\s+default\s+([A-Z]\w*)\s*(?:;|$)/m,/(?:function|class)\s+([A-Z]\w*)/,/const\s+([A-Z]\w*)\s*[:=]/,/(?:function|const|class)\s+(\w+)/]){let n=e.match(t);if(n)return n[1]}return null}function ft(e){let t=e.match(/^\s*title\s+(.+)$/im);if(t)return t[1].trim();let n=e.trim().match(/^([A-Za-z][\w-]*)/);if(!n)return null;let r=n[1].replace(/-(?:beta|v2)$/i,``).replace(/([a-z])([A-Z])/g,`$1 $2`);return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function pt(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 mt(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 ht(e){let t=e.trim().toLowerCase();return at.includes(t)?t:`text`}function gt(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 _t(e){let t=[],n=new RegExp(nt),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=vt(n,bt(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 vt(e,t){let n=yt(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!it.test(r)&&!r.includes(`=`)?gt(r):void 0)||gt(St(n)),fileName:n}}function yt(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&it.test(t[1]))return xt(t[1]);let n=e.match(it);return n?xt(n[0]):void 0}function bt(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(it);if(t)return xt(t[0])}}function xt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function St(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function Ct(e){return e?.split(/[\\/]/).pop()}function wt(e){let t=Ct(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 Tt(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function Et(e){let t=gt(e.language)||gt(St(e.fileName));switch(t){case`html`:return{type:`html`,title:ut(e.content)||wt(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:wt(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:dt(e.content)||wt(e.fileName)||`React Component`,language:`jsx`};case`mermaid`:return{type:`mermaid`,title:ft(e.content)||`Diagram`,language:`mermaid`};case`json`:return{type:`json`,title:wt(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:pt(e.content)||wt(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:wt(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:mt(e.content)||wt(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:wt(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:wt(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function Dt(e){return(gt(e.language)||gt(St(e.fileName)))===`html`}function Ot(e){return(gt(e.language)||gt(St(e.fileName)))===`css`}function kt(e){return(gt(e.language)||gt(St(e.fileName)))===`javascript`}function At(e){let t=_t(e),n=t.filter(Dt);if(n.length===0)return null;let r=t.filter(Ot),i=t.filter(kt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=jt(a.content,r,i),s=Le(o,r.map(e=>e.content),i.map(e=>e.content));return It(s,`html`)?{artifact:Tt({type:`html`,title:ut(s)||wt(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 jt(e,t,n){let r=e;for(let e of t){let t=Ct(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${Ft(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=Ct(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${Ft(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function Mt(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=_t(e);if(Nt(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 It(s,`html`)?{artifact:Tt({type:`html`,title:ut(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function Nt(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function Pt(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 Ft(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function It(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&&(Re(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Za-z][^>]*>/.test(e)&&/\b(?:export\s+default|return\s*[(<]|=>\s*[(<]|createRoot|render\s*\()/.test(e);if(t===`mermaid`)return rt.test(e.trim());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 Lt(e){let t=[],n=e;for(let e of ot){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);It(n.content,n.type)&&(t.push(Tt({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=Pt(n,r)}let r=At(n);for(;r;)t.push(r.artifact),n=Pt(n,r.ranges),r=At(n);let i=Mt(n);i&&(t.push(i.artifact),n=Pt(n,i.ranges));let a=_t(n),o=[];for(let e of a){let n=Et(e);!n||!It(e.content,n.type)||(t.push(Tt({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=Pt(n,o),{content:n.trim(),artifacts:t}}var Rt=W(`components:chat-message`),zt=({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}=Y(),b=_(),[x,C]=(0,Q.useState)(!1),[w,E]=(0,Q.useState)(e.content),[D,k]=(0,Q.useState)(null),[A,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(!1),[I,te]=(0,Q.useState)(!1),[z,re]=(0,Q.useState)(!1),[ie,ae]=(0,Q.useState)(!1),B=(0,Q.useRef)(null),oe=(0,Q.useRef)(t),se=(0,Q.useRef)(!1),ce=async()=>{try{await navigator.clipboard.writeText(e.content),Ne(`success`),ae(!0),setTimeout(()=>ae(!1),2e3)}catch(e){Rt.error(`Failed to copy message:`,e)}},{thinkingContent:le,thinkingStreaming:V,parsedContent:H,artifacts:ue}=(0,Q.useMemo)(()=>{if(l||d||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:ye(e.content),r=n.content,i=t&&!n.thinkingComplete;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:e.artifacts};if(!t){let e=Lt(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,l,d,t]),de=V?void 0:e.statistics?.thinking_duration_ms??$e(e.id);(0,Q.useEffect)(()=>{let e=oe.current&&!t;return oe.current=t,e&&!se.current&&!l&&!d&&H&&f.ttsSettings?.enabled&&f.ttsSettings?.autoPlay&&(se.current=!0,(async()=>{re(!0);try{let e=await K.getModels(),t=e.success&&e.data?e.data:[],n=f.ttsSettings,r=he(t,n?.model,n?.pluginId),i=_e(t,n?.model,n?.pluginId),a=await K.generateBase64({model:r?.model||n?.model||`tts-1`,pluginId:r?.plugin||n?.pluginId,input:H,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);B.current=t,t.onended=()=>{re(!1),B.current=null},t.onerror=()=>{re(!1),B.current=null},await t.play()}}catch(e){Rt.error(`Auto-play TTS failed:`,e),re(!1)}})()),()=>{B.current&&(B.current.pause(),B.current=null)}},[t,l,d,H,f.ttsSettings]);let U=()=>d?o(`chatMessage.system`):l?f.showUsername&&p?.username?p.username:o(`chatMessage.you`):b?.name?b.name:e.model||o(`chatMessage.assistant`),W=()=>{C(!0),E(e.content)},G=async()=>{M(!0);try{h(w),C(!1),Rt.debug(`✅ System message updated:`,w)}catch(e){Rt.error(`Failed to save system message:`,e)}finally{M(!1)}},fe=()=>{C(!1),E(e.content)},pe=()=>{let t=w.trim();C(!1),!(!t||t===e.content)&&a?.(e.id,t)},q=t=>{v&&y(v.id,e.id,e.rating===t?void 0:t)},me=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ge=d&&e.content.length>100;return(0,$.jsxs)(`div`,{className:J(`group flex py-1.5 transition-colors sm:py-2`,l?`justify-end`:`justify-start`,n),children:[(0,$.jsx)(`div`,{className:J(`flex min-w-0`,l?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:(0,$.jsxs)(`div`,{className:J(`min-w-0 flex-1`,l?`flex flex-col items-end`:d?`py-1.5`:`py-0.5`),children:[!l&&!d&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:U()}),e.model&&b?.name&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,$.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:be(e.timestamp,c.language)})]}),(0,$.jsxs)(`div`,{className:J(!l&&!d&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/[0.06] bg-gray-100 dark:border-white/[0.08] dark:bg-gray-800`,children:(0,$.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>k(e)})},t))}),l?x?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/[0.08] bg-white p-2 shadow-sm dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),pe()):e.key===`Escape`&&fe()},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-none dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(`button`,{onClick:fe,className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 transition-colors hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:o(`chatMessage.cancelEditing`)}),(0,$.jsx)(`button`,{onClick:pe,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white transition-colors hover:bg-gray-700 dark:bg-dark-300 dark:hover:bg-dark-400`,children:o(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{className:`rounded-2xl rounded-ee-md border border-black/[0.06] bg-gray-900 px-3.5 py-2 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):d?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(u,{className:`h-2.5 w-2.5 opacity-50`}),o(`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:G,disabled:A,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.saveChanges`),children:(0,$.jsx)(m,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:fe,disabled:A,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.cancelEditing`),children:(0,$.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:W,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:o(`chatMessage.editSystemMessage`),children:(0,$.jsx)(T,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),x?(0,$.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>E(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:o(`chatMessage.systemMessagePlaceholder`),disabled:A}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:N?e.content:me(e.content)}),ge&&(0,$.jsx)(`button`,{onClick:()=>P(!N),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:N?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(le||V)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{onClick:()=>te(!I),className:`flex items-center gap-1.5 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,$.jsx)(j,{className:J(`h-3.5 w-3.5`,V&&`animate-pulse-subtle motion-reduce:animate-none`)}),V?(0,$.jsxs)(`span`,{className:`animate-shimmer bg-gradient-to-r from-gray-400 via-gray-900 to-gray-400 bg-[length:200%_100%] bg-clip-text font-medium text-transparent motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-gray-500 dark:from-dark-500 dark:via-dark-900 dark:to-dark-500 motion-reduce:dark:text-dark-600`,children:[o(`chatMessage.thinking`),`…`]}):(0,$.jsx)(`span`,{className:`font-medium`,children:de===void 0?o(`chatMessage.thinking`):o(`chatMessage.thoughtFor`,{duration:tt(de)})}),I?(0,$.jsx)(R,{className:`h-3.5 w-3.5`}):(0,$.jsx)(O,{className:`h-3.5 w-3.5`})]}),I&&le&&(0,$.jsx)(`div`,{className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 dark:bg-dark-200/60`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[13px] leading-relaxed text-gray-600 dark:text-dark-700`,children:le})})]}),(0,$.jsx)(Ie,{content:H,isStreaming:t})]}),!l&&!d&&ue.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(ze,{artifacts:ue})}),!l&&!d&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(He,{statistics:e.statistics})}),!d&&!t&&(0,$.jsxs)(`div`,{className:J(`flex items-center gap-0.5 text-gray-400 dark:text-dark-500`,`sm:opacity-0 sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,l?`mt-1 justify-end`:`mt-1`),children:[l&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:be(e.timestamp,c.language),children:[U(),` ·`,` `,be(e.timestamp,c.language)]}),!l&&H&&(0,$.jsx)(Xe,{text:H,size:`sm`,className:J(`transition-colors`,z&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),l&&a&&!x&&(0,$.jsx)(`button`,{onClick:()=>{E(e.content),C(!0)},className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.edit`),children:(0,$.jsx)(T,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:ce,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(ie?`chatMessage.copied`:`chatMessage.copyMessage`),children:ie?(0,$.jsx)(ne,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(g,{className:`h-3.5 w-3.5`})}),!l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>q(1),className:J(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===1&&`text-primary-600 dark:text-primary-400`),title:o(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(ee,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>q(-1),className:J(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===-1&&`text-red-500 dark:text-red-400`),title:o(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(F,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})})]}),!l&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.regenerateResponse`),children:(0,$.jsx)(S,{className:`h-3.5 w-3.5`})})]})]})]})}),D&&(0,Ve.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":o(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>k(null),children:[(0,$.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),k(null)},children:(0,$.jsx)(L,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:D,alt:o(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Bt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Vt=220,Ht=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>Vt?`${t.slice(0,219).trimEnd()}…`:t},Ut=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;!r||!i||(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Q.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:Bt()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===h,u=Math.abs(a-m),d=c===t.id?v:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:J(`group flex h-4 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:J(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,$.jsx)(`div`,{id:v,role:`tooltip`,className:J(`pointer-events-none absolute start-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:Ht(_.prompt)}),_.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:Ht(_.response)})]})})]})}),Wt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(zt,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,$.jsxs)(`div`,{className:J(`relative py-2`,c),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(f,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let l=e.isActive!==!1,u=t&&i===e.id,d=u?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:J(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||u?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!u&&`cursor-pointer`),role:!l&&!u?`button`:void 0,tabIndex:!l&&!u?0:void 0,onClick:()=>!l&&!u&&s?.(e.id),onKeyDown:t=>{!l&&!u&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,$.jsxs)(`div`,{className:J(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||u?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,$.jsx)(ne,{className:`h-3 w-3`}),!l&&!u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,$.jsx)(`div`,{className:J(!l&&!u&&`opacity-75`),children:(0,$.jsx)(zt,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Gt={web_search:b,web_fetch:k,exec:le,browser:k,Read:x,Write:x,Edit:x,image:re,memory_search:E,memory_get:E,working:ae,thinking:ae,default:ae},Kt={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`},qt=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,$.jsx)(`div`,{className:J(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Gt[e.name]||Gt.default,n=Kt[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:J(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(`div`,{className:J(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};W(`components:chat-messages`);var Jt=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],Yt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,Xt=e=>Math.min(120,e*.28),Zt=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],className:o,onRegenerate:c,onSelectBranch:l,onEditResend:u,followUpSuggestions:d,onFollowUpSelect:f})=>{let{t:p}=s(),m=(0,Q.useRef)(null),h=(0,Q.useRef)(void 0),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(new Map),y=(0,Q.useRef)(null),b=(0,Q.useRef)(0),x=(0,Q.useRef)(!1),S=(0,Q.useRef)(!1),[w,T]=(0,Q.useState)(!1),E=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),D=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<E.length;t++){let n=E[t],r=Jt(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<E.length;e++){let t=Jt(E[e]);if(t.role===`user`)break;if(t.role===`assistant`){i=t.content;break}}e.push({id:n.id,prompt:r.content,response:i})}return e},[E]),O=D.map(e=>e.id).join(``),k=(0,Q.useMemo)(()=>O?O.split(``):[],[O]),A=(0,Q.useMemo)(()=>new Set(k),[k]),[j,M]=(0,Q.useState)(null),N=(0,Q.useCallback)(()=>{let e=g.current;if(!e||k.length===0){M(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(b.current,k.length-1);if(t<=2)n=k.length-1;else{let t=e.scrollTop+Xt(e.clientHeight);for(;n<k.length-1;){let e=v.current.get(k[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=v.current.get(k[n]);if(!e||e.offsetTop<=t)break;n--}}b.current=n;let r=k[n];M(e=>e===r?e:r)},[k]),P=(0,Q.useCallback)(()=>{y.current===null&&(y.current=window.requestAnimationFrame(()=>{y.current=null,N()}))},[N]),F=(0,Q.useCallback)(()=>{let t=g.current;if(h.current&&clearTimeout(h.current),x.current=!1,h.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;S.current=!n,T(!n&&e.length>0),P()},[e.length,P]),I=(0,Q.useCallback)(()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(F,180)},[F]),ee=(0,Q.useCallback)((e=!1)=>{S.current&&!e||m.current?.scrollIntoView({behavior:Yt()})},[]),te=(0,Q.useCallback)(()=>{let t=g.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(x.current){S.current=!0,T(!o&&e.length>0),P(),I();return}S.current=!o,T(!o&&e.length>0),a<=2&&k.length>0?(b.current=k.length-1,M(k[k.length-1])):P()},[k,e.length,I,P]),L=(0,Q.useCallback)(e=>{let t=g.current,n=v.current.get(e);if(!t||!n)return;let r=Yt();x.current=!0,S.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-Xt(t.clientHeight)),behavior:r}),P(),r===`auto`?F():I()},[F,I,P]),R=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>R.current&&!S.current&&ee(),R.current=e.length},[e.length,ee]),(0,Q.useEffect)(()=>{i&&(t||n)&&!S.current&&requestAnimationFrame(()=>{let e=g.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{P();let e=_.current,t=g.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(P);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,P),()=>{n?.disconnect(),window.removeEventListener(`resize`,P)}},[O,P]),(0,Q.useEffect)(()=>()=>{y.current!==null&&(window.cancelAnimationFrame(y.current),y.current=null)},[]),(0,Q.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:J(`flex-1 flex items-center justify-center p-6 sm:p-10`,o),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-surface/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(C,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:p(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:p(`chatMessage.startConversationDescription`)})]})});let z=-1;for(let e=E.length-1;e>=0;e--)if(E[e].messages.some(e=>e.role===`assistant`)){z=e;break}return(0,$.jsxs)(`div`,{className:J(`relative min-h-0 flex-1`,o),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:g,"data-testid":`chat-scroll-viewport`,onScroll:te,className:J(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,$.jsxs)(`div`,{ref:_,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[E.map((e,a)=>{let o=a===z,s=A.has(e.id),d=i&&e.messages.some(e=>e.id===r),f;if(e.messages.length===1){let s=e.messages[0],l=i&&s.id===r,d=l?{...s,content:t??s.content,thinking:n||s.thinking}:s;f=(0,$.jsx)(zt,{message:d,isStreaming:l,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onEditResend:i?void 0:u,className:a===0?`mt-3 sm:mt-4`:``})}else f=(0,$.jsx)(Wt,{messages:e.messages,isStreaming:d,streamingMessage:t,streamingThinking:n,streamingMessageId:r||void 0,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onSelectBranch:l,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{ref:t=>{s&&(t?v.current.set(e.id,t):v.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:f},e.id)}),i&&a.length>0&&(0,$.jsx)(qt,{tools:a,className:`px-0`}),!i&&d&&d.length>0&&f&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:p(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:d.map(e=>(0,$.jsx)(`button`,{onClick:()=>f(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-gray-600 transition-colors hover:text-gray-900 dark:border-dark-200 dark:text-dark-600 dark:hover:text-dark-900`,children:e},e))})]}),(0,$.jsx)(`div`,{ref:m,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(Ut,{items:D,activeId:j,onSelect:L}),w&&(0,$.jsxs)(`button`,{onClick:()=>{x.current=!1,h.current&&(clearTimeout(h.current),h.current=void 0),S.current=!1,m.current?.scrollIntoView({behavior:Yt()}),T(!1)},className:J(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/[0.08]`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:p(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(de,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:p(`chatMessage.newMessages`)})]})]})};function Qt(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 $t=Q.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Q.useMemo)(()=>Qt(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:J(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:J(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,$.jsx)(_,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});$t.displayName=`CodeAwareTextarea`;var en=W(`components:media-upload`),tn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)([]),g=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):w.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){w.error(`Maximum ${n} images allowed`);return}if(r.size>10485760){w.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},y=async e=>{if(e.size>10485760){w.error(`File size must be less than 10MB`);return}p(!0);try{let t=await pe.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){en.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 pe.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){en.error(`Error removing document:`,e),w.error(`Failed to remove document`)}},D=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},O=e.length>0||m.length>0;return(0,$.jsxs)(`div`,{className:J(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:J(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:b,onDragLeave:S,onDrop:C,onClick:()=>!a&&l.current?.click(),children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(oe,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,$.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),O&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),T(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(x,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,$.jsx)(v,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:D(e.size)})]}),(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),E(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},nn=W(`components:document-indicator`),rn=({sessionId:e,className:t=``})=>{let[n,r]=(0,Q.useState)([]);if((0,Q.useEffect)(()=>{if(!e)return;let t=async()=>{try{let t=await pe.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){nn.error(`Failed to load documents:`,e)}};t();let n=()=>void t();return window.addEventListener(`libre:documents-updated`,n),()=>window.removeEventListener(`libre:documents-updated`,n)},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{className:`
4
- inline-flex items-center space-x-1 px-2 py-1
5
- bg-blue-50 dark:bg-blue-900/20
6
- border border-blue-200 dark:border-blue-800
7
- rounded-md text-xs
8
- ${t}
9
- `,title:`${n.length} document(s) available for context - Total: ${(e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]})(i)}`,children:[(0,$.jsx)(I,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,$.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},an=W(`components:structured-output`),on=[{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`}],sn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),[o,c]=(0,Q.useState)(``),l=()=>on.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),d=()=>{let t=l();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},f=e=>{let n=l().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,$.jsxs)(`div`,{className:J(`space-y-3`,n),children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center`,children:[(0,$.jsx)(u,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,$.jsx)(Pe,{value:d().label,onChange:e=>f(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Fe,{value:o,onChange:e=>c(e.target.value),placeholder:`{
10
- "type": "object",
11
- "properties": {
12
- "field1": { "type": "string" },
13
- "field2": { "type": "number" }
14
- },
15
- "required": ["field1"]
16
- }`,rows:8,className:`font-mono text-sm`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Z,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){an.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(Z,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=d();return!e.value||e.value===`json`?null:(0,$.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,$.jsx)(ie,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,$.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,$.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,$.jsx)(x,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},cn=W(`components:chat-input`),ln=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},un=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r,i18n:i}=s(),[a,o]=(0,Q.useState)(``),[c,u]=(0,Q.useState)(!1),f=(0,Q.useRef)(null),p=(0,Q.useRef)(``),m=(0,Q.useMemo)(()=>!!ln(),[]),[g,_]=(0,Q.useState)([]),[v,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null),[O,A]=(0,Q.useState)(!1),[j,P]=(0,Q.useState)([]),[F,ee]=(0,Q.useState)(!1),[te,L]=(0,Q.useState)(!1),[R,z]=(0,Q.useState)(null),[ie,ae]=(0,Q.useState)(!1),B=(0,Q.useRef)(null),se=(0,Q.useRef)(null),{isGenerating:ce,setBackgroundImage:le}=ke(),H=ke(e=>e.preferences.imageGenSettings?.enabled===!0),de=H&&ie,{currentSession:U,models:W}=Y(),K=(0,Q.useRef)(null),q=(0,Q.useMemo)(()=>({model:U?.personaId?`persona:${U.personaId}`:U?.model||``,providerType:U?.providerType,providerId:U?.providerId}),[U?.model,U?.personaId,U?.providerId,U?.providerType]),me=(0,Q.useMemo)(()=>Te(W,q),[W,q]),he=q.model?Se(me,q):``,ge=Ce(W,q);(0,Q.useEffect)(()=>{let e=!1;return H&&(async()=>{try{let t=await fe.getPlugins();if(e)return;ae(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ae(!1)}})(),()=>{e=!0}},[H]),(0,Q.useEffect)(()=>{if(!w)return;let e=e=>{B.current&&!B.current.contains(e.target)&&(T(!1),D(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[w]);let _e=()=>{T(!1),D(null),A(!1)};(0,Q.useEffect)(()=>{if(!O)return;let e=!1;return pe.getCollections().then(t=>{!e&&t.success&&t.data&&P(t.data)}).catch(()=>{}),()=>{e=!0}},[O]);let ye=U?.settings?.knowledgeCollectionIds??[],be=async e=>{if(!U)return;let t=ye.includes(e)?ye.filter(t=>t!==e):[...ye,e],n={...U.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(Y.setState(e=>({currentSession:e.currentSession?.id===U.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===U.id?{...e,settings:n}:e)})),!U.isPrivate)try{await G.updateSession(U.id,{settings:n})}catch(e){cn.error(`Failed to update knowledge collections:`,e),V.error(r(`chat.input.menu.attachFailed`))}};(0,Q.useEffect)(()=>()=>{f.current?.stop()},[]);let xe=()=>{if(c){f.current?.stop();return}let e=ln();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){cn.error(`Failed to start dictation:`,e),f.current=null}},we=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){_e(),L(!0);try{let e=await pe.uploadDocument(t,U?.id);e.success?(V.success(r(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):V.error(e.error||r(`chat.input.menu.attachFailed`))}catch(e){cn.error(`Document upload failed:`,e),V.error(r(`chat.input.menu.attachFailed`))}finally{L(!1)}}},Oe=async()=>{let e=E?.trim();if(!(!e||F)){ee(!0);try{let t=await pe.fetchWebpage(e,U?.id);t.success?(V.success(r(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),_e()):V.error(t.error||r(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||r(`chat.input.menu.attachFailed`);cn.error(`Webpage attach failed:`,e),V.error(t)}finally{ee(!1)}}},X=t=>{if(t.preventDefault(),!(!a.trim()||ce)){if(!ge){V.error(`Select an available model before sending`);return}e(a.trim(),g.length>0?g:void 0,v||void 0),o(``),_([])}},Ae=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),X(e))},je=()=>{t()};(0,Q.useEffect)(()=>{let e=K.current;e&&(e.style.height=`auto`,e.style.height=a?`${Math.min(e.scrollHeight,200)}px`:``)},[a]),(0,Q.useEffect)(()=>{(async()=>{if(U?.personaId)try{let e=await ve.getPersona(U.personaId);if(e.success&&e.data)z(e.data);else{cn.warn(`Persona ${U.personaId} not found, clearing reference`),z(null);let{setCurrentSession:e}=Y.getState();e({...U,personaId:void 0})}}catch(e){if(cn.error(`Failed to load current persona:`,e),z(null),U){let{setCurrentSession:e}=Y.getState();e({...U,personaId:void 0})}}else z(null)})()},[U?.personaId]);let Me=async e=>{let t=De(me,e.target.value);if(t&&U)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await ve.getPersona(e);if(!n.success||!n.data){V.error(`Failed to load persona details`);return}let i=n.data,a=await G.updateSession(U.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(a.success&&a.data){let{sessions:e}=Y.getState(),t=e.map(e=>e.id===U.id?a.data:e);Y.setState({sessions:t,currentSession:a.data}),i.background&&le(i.background),V.success(r(`chat.persona.applied`))}}else{let e=await G.updateSession(U.id,{model:t.model,providerType:t.providerType,providerId:(t.providerType===`plugin`||t.providerType===`agent`)&&t.providerId||null,personaId:null});if(e.success&&e.data){let{sessions:t}=Y.getState(),n=t.map(t=>t.id===U.id?e.data:t);Y.setState({sessions:n,currentSession:e.data}),le(null),V.success(r(`chat.model.updated`))}}}catch(e){cn.error(`Failed to update session:`,e),V.error(`Failed to update session`)}},Ne=g.length>0||v!==null;return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[S&&(0,$.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/90`,children:[(0,$.jsx)(tn,{images:g,onImagesChange:_,maxImages:5,sessionId:U?.id,disabled:n}),(0,$.jsx)(sn,{format:v,onFormatChange:b})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[(0,$.jsx)(`form`,{onSubmit:X,children:(0,$.jsxs)(`div`,{className:J(`flex items-end gap-2 rounded-[1.35rem] border p-2 transition-[border-color,box-shadow,background-color] duration-200`,`bg-surface/[0.92] dark:bg-dark-200/[0.92] backdrop-blur-xl`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_14px_42px_rgba(15,23,42,0.08)]`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_52px_rgba(15,23,42,0.11)]`),children:[(0,$.jsxs)(`div`,{ref:B,className:`relative flex-shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(S){C(!1);return}T(e=>!e),D(null)},className:J(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,Ne&&`text-primary-600 dark:text-primary-400`,(S||w)&&`bg-gray-100 dark:bg-dark-300`),title:r(`chat.input.attachments`),children:te||F?(0,$.jsx)(oe,{className:`h-4 w-4 animate-spin`}):Ne?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(h,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):S?(0,$.jsx)(l,{className:`h-4 w-4`}):(0,$.jsx)(d,{className:`h-4 w-4`})}),w&&(0,$.jsx)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 w-64 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:O?(0,$.jsxs)(`div`,{className:`p-1`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.input.menu.attachKnowledge`)}),j.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-gray-400 dark:text-dark-500`,children:r(`chat.input.menu.noCollections`)}):j.map(e=>{let t=ye.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void be(e.id),className:J(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),"aria-pressed":t,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(I,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(ne,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>A(!1),className:`mt-1 w-full rounded-lg border-t border-gray-100 px-2.5 py-1.5 text-start text-xs text-gray-500 hover:bg-gray-100 dark:border-dark-300 dark:text-dark-600 dark:hover:bg-dark-200`,children:r(`common.back`)})]}):E===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{C(!0),_e()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(re,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.uploadImages`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>se.current?.click(),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(x,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>D(``),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(k,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>A(!0),className:`flex w-full items-center justify-between gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(I,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachKnowledge`)]}),ye.length>0&&(0,$.jsx)(`span`,{className:`rounded-full bg-primary-50 px-1.5 text-[10px] font-medium tabular-nums text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`,children:ye.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{C(!0),_e()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(N,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.structuredOutput`)]})]}):(0,$.jsxs)(`div`,{className:`p-1.5`,children:[(0,$.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.input.menu.attachWebpage`)}),(0,$.jsx)(`input`,{type:`url`,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),Oe()):e.key===`Escape`&&D(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>D(null),className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:r(`common.cancel`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void Oe(),disabled:!E.trim()||F,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:F?(0,$.jsx)(oe,{className:`h-3.5 w-3.5 animate-spin`}):r(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:se,type:`file`,accept:`.pdf,.txt,application/pdf,text/plain`,className:`hidden`,onChange:e=>void we(e)})]}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)($t,{ref:K,value:a,onChange:e=>o(e.target.value),onKeyDown:Ae,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!m-0 block min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-1.5 !py-1.5 sm:!min-h-10 sm:!py-2 max-[768px]:!min-h-11 max-[768px]:!py-[10.5px] !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1})}),(0,$.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1 sm:gap-2`,children:[U&&me.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Be,{models:me,selectedModel:he,onModelChange:Me,getModelValue:Ee,currentPersona:R,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:de})}),m&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:xe,className:J(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,c&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:r(c?`chat.input.voiceStop`:`chat.input.voiceInput`),"aria-pressed":c,children:(0,$.jsx)(M,{className:`h-4 w-4`})}),ce?(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:je,className:J(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.stopGeneration`),children:(0,$.jsx)(ue,{className:`h-4 w-4`})}):(0,$.jsx)(Z,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!a.trim()||n||!ge,className:J(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-100 text-gray-400 dark:bg-dark-300 dark:text-dark-500`,`disabled:cursor-not-allowed disabled:opacity-70`,`transition-colors duration-150 touch-manipulation`,a.trim()&&!n&&ge&&[`bg-gray-950 text-white hover:bg-gray-800`,`dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`shadow-sm`]),title:r(`chat.input.sendMessage`),children:(0,$.jsx)(y,{className:`h-4 w-4`})})]})]})}),U&&me.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(Be,{models:me,selectedModel:he,onModelChange:Me,getModelValue:Ee,currentPersona:R,className:`w-full`,compact:!0,showImageGen:de})}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(rn,{sessionId:U?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),Ne&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,g.length>0&&r(`chat.footer.images`,{count:g.length}),g.length>0&&v&&` • `,v&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},dn=W(`components:chat-controls-panel`),fn=[{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`}],pn=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i}=s(),a=Y(e=>e.draftSessionSettings),o=Y(e=>e.setDraftSessionSettings),c=e?.model??t??``,l=ke(e=>e.preferences.generationOptions),u=ke(e=>e.preferences.modelGenerationOptions?.[c]),[d,f]=(0,Q.useState)({options:{},contextCapped:!1});(0,Q.useEffect)(()=>{if(!n||!c)return;let e=!1;return ge.getModelDefaults(c).then(t=>{e||!t.success||!t.data||f({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,c]);let p=(0,Q.useMemo)(()=>({...l??{},...d.options,...u??{}}),[l,d.options,u]),m=(0,Q.useMemo)(()=>e?.messages.find(e=>e.role===`system`),[e?.messages]),[h,g]=(0,Q.useState)(m?.content??a.systemPrompt??``),[_,v]=(0,Q.useState)(e?.settings?.generationOptions??a.generationOptions??{}),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(e?.id??`draft`),C=e?.id??`draft`;x!==C&&(S(C),g(m?.content??a.systemPrompt??``),v(e?.settings?.generationOptions??a.generationOptions??{}));let T=(e,t)=>{v(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},E=async()=>{b(!0);try{let t=h.trim(),n=m?.content??``,a=Object.fromEntries(Object.entries(_).filter(([,e])=>e!==void 0)),s=Object.keys(a).length>0?{generationOptions:a}:void 0;if(!e){o({systemPrompt:t||void 0,generationOptions:s?.generationOptions}),w.success(i(`chat.controls.saved`)),r();return}let c=e.messages;if(t!==n.trim()&&(m?c=t?e.messages.map(e=>e.id===m.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==m.id):t&&(c=[{id:xe(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)Y.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:c,settings:s}:t.currentSession}));else{let t=await G.updateSession(e.id,{messages:c,settings:s});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;Y.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}w.success(i(`chat.controls.saved`)),r()}catch(e){dn.error(`Failed to save chat controls:`,e),w.error(i(`chat.controls.saveFailed`))}finally{b(!1)}};return n?(0,$.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:`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`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:i(`chat.controls.title`)}),(0,$.jsx)(`button`,{onClick:r,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:i(`common.close`),children:(0,$.jsx)(L,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.systemPrompt`)}),(0,$.jsx)(`textarea`,{dir:`auto`,value:h,onChange:e=>g(e.target.value),placeholder:i(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/[0.08] bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.advancedParams`)}),(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.advancedParamsDescription`)}),d.contextCapped&&d.trainedContextLength&&(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-500 dark:text-dark-600`,children:i(`chat.controls.contextCapped`,{context:p.num_ctx?.toLocaleString(),trained:d.trainedContextLength.toLocaleString()})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:fn.map(e=>{let t=_[e.key],n=p[e.key],r=d.options[e.key]!==void 0&&u?.[e.key]===void 0;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`label`,{htmlFor:`chat-control-${e.key}`,className:`text-[13px] text-gray-700 dark:text-dark-700`,children:[i(`chat.controls.params.${e.labelKey}`),r&&(0,$.jsx)(`span`,{title:i(`chat.controls.fromModelHint`),className:`ms-1.5 text-[10px] uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:i(`chat.controls.fromModel`)})]}),(0,$.jsx)(`input`,{id:`chat-control-${e.key}`,type:`number`,inputMode:`decimal`,step:e.step,min:e.min,max:e.max,value:typeof t==`number`?t:``,placeholder:typeof n==`number`?String(n):i(`common.default`),onChange:t=>T(e.key,t.target.value),className:`w-24 rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-black/[0.06] px-4 py-3 dark:border-white/[0.07] lg:pb-16`,children:[(0,$.jsx)(`button`,{onClick:()=>{v({}),g(m?.content??``)},className:`text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:i(`common.reset`)}),(0,$.jsx)(Z,{onClick:()=>void E(),size:`sm`,disabled:y,children:i(y?`common.saving`:`common.save`)})]})]}):null},mn=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)({top:0,left:0});(0,Q.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect(),t=document.documentElement.dir===`rtl`?e.right-288:e.left;s({top:e.bottom+8,left:Math.min(window.innerWidth-288-8,Math.max(8,t))})}},[r]);let c=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),l=()=>q(e,64),u=t=>{me(t.currentTarget,e.name,64)};return(0,$.jsxs)(`div`,{className:J(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:J(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:u}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,$.jsx)(C,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(O,{className:J(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Ve.createPortal)((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,$.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,$.jsxs)(`div`,{className:J(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,$.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,$.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 end-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,$.jsx)(L,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,$.jsxs)(`div`,{className:`absolute top-2 start-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,$.jsx)(j,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,$.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:u})}),(0,$.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,$.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,$.jsx)(te,{className:`h-3 w-3`}),e.model]}),e.description&&(0,$.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,$.jsxs)(`div`,{className:`mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,$.jsx)(ce,{className:`h-2.5 w-2.5 text-gray-400`}),(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(se,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,$.jsx)(j,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},hn=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Q.useRef)(null),[o,c]=(0,Q.useState)(!1),l=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){w.error(`File ${o.name} is not an image`);continue}if(o.size>10485760){w.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&w.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),c(!0)},d=e=>{e.preventDefault(),c(!1)},f=e=>{e.preventDefault(),c(!1),l(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},m=e.length<n;return(0,$.jsxs)(`div`,{className:J(`space-y-3`,r),children:[m&&(0,$.jsxs)(`div`,{className:J(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:u,onDragLeave:d,onDrop:f,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,$.jsx)(L,{className:`h-4 w-4`})})})]},t))}),m&&e.length>0&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(re,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},gn=W(`use-chat`),_n=new Set([`New Chat`,`New Demo Session`]),vn=e=>!e||_n.has(e),yn=e=>{let[t,n]=(0,Q.useState)(``),[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)([]),{addMessage:d,updateMessage:f,updateMessageWithStatistics:p,applySessionTitle:m,setGeneratingTitleForSession:h}=Y(),{setIsGenerating:g}=ke(),_=(0,Q.useRef)(null),v=(0,Q.useRef)(null),y=(0,Q.useRef)(!1),b=(0,Q.useRef)(null),x=(0,Q.useRef)(``),S=(0,Q.useRef)(``),C=(0,Q.useRef)(0),T=(0,Q.useRef)(void 0),E=(0,Q.useRef)(null),D=(0,Q.useRef)(``),O=(0,Q.useRef)(``),k=(0,Q.useCallback)(()=>{E.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(E.current),E.current=null},[]),A=(0,Q.useCallback)((e,t=!1,r=``)=>{if(D.current=e,O.current=r,t||typeof window>`u`){k(),n(e),i(r);return}E.current===null&&(E.current=window.requestAnimationFrame(()=>{E.current=null,n(D.current),i(O.current)}))},[k]),j=(0,Q.useCallback)(()=>{k(),D.current=``,O.current=``,n(``),i(``)},[k]),M=(0,Q.useCallback)(()=>{v.current=null,y.current=!1,b.current=null},[]),N=(0,Q.useCallback)(async e=>{let t=ke.getState().preferences.titleSettings,n=v.current,r=y.current&&b.current===e;if(gn.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),!n||!r||!t?.autoTitle||!t?.taskModel){M();return}M(),gn.debug(`Triggering auto-title generation...`),h(e);try{let r=await G.generateTitle(e,t.taskModel,n,t.taskProviderType,t.taskProviderId);if(gn.debug(`Title generation response:`,r),!r.success||!r.data?.title)throw Error(r.error||`Title generation returned no title`);m(e,r.data.title,r.data.updatedAt),r.data.source===`fallback`?w.error(`Could not generate a title; using the message preview`):w.success(`Chat title generated`)}catch(e){gn.error(`Failed to generate title:`,e),w.error(`Failed to generate chat title`)}finally{h(null)}},[m,M,h]);(0,Q.useEffect)(()=>()=>{X.offMessage(`user_message`),X.offMessage(`assistant_chunk`),X.offMessage(`assistant_complete`),X.offMessage(`tool_status`),X.offMessage(`error`)},[e]),(0,Q.useEffect)(()=>{if(!e){X.offMessage(`user_message`),X.offMessage(`assistant_chunk`),X.offMessage(`assistant_complete`),X.offMessage(`tool_status`),X.offMessage(`error`);return}return X.onMessage(`user_message`,()=>{}),X.onMessage(`assistant_chunk`,t=>{let n=t,r=n.messageId||_.current;r&&(x.current=n.total,typeof n.thinkingTotal==`string`&&(S.current=n.thinkingTotal),Qe(r,n.total,S.current),A(n.total,n.done,S.current),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{f(e,r,x.current),C.current=Date.now()},n.done?0:200))}),X.onMessage(`tool_status`,e=>{let t=e;u(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),X.onMessage(`assistant_complete`,t=>{let n=t;gn.debug(`Hook: Received assistant_complete for session:`,e,`messageId:`,n.messageId,`with statistics:`,!!n.statistics),c(!1),j(),g(!1),u([]);let r=n.messageId||_.current;if(n&&r){let t=x.current||n.content,i=S.current||n.thinking,a=et(r),o=n.statistics?.thinking_duration_ms===void 0&&a!==void 0?{...n.statistics,thinking_duration_ms:a}:n.statistics;p(e,r,t,o,n.providerMetadata,i)}N(e),_.current=null,x.current=``,S.current=``,T.current&&clearTimeout(T.current),C.current=0}),X.onMessage(`error`,e=>{let t=e;if(c(!1),j(),g(!1),_.current=null,S.current=``,t.code===`SESSION_NOT_FOUND`){gn.warn(`Session not found, redirecting to create new session...`),w.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}w.error(t.error),M()}),c(!1),j(),_.current=null,S.current=``,()=>{T.current&&clearTimeout(T.current),k()}},[e,f,p,g,A,j,k,N,M]);let P=(0,Q.useCallback)(async(t,n,r)=>{if(!(!e||!t.trim()&&(!n||n.length===0)))try{let i=Y.getState(),a=i.currentSession,s={model:a?.personaId?`persona:${a.personaId}`:a?.model||``,providerType:a?.providerType,providerId:a?.providerId};if(!Ce(i.models,s)){w.error(`Select an available model before sending`);return}g(!0),c(!0),j(),T.current&&clearTimeout(T.current),C.current=Date.now();let l=a?.isPrivate===!0,u=a?.messages?.some(e=>e.role===`user`);!l&&!u&&vn(a?.title)?(v.current=t.trim(),y.current=!0,b.current=e):(v.current=null,y.current=!1,b.current=null),d(e,{role:`user`,content:t.trim(),images:n});let p=xe();if(_.current=p,S.current=``,o(p),d(e,{role:`assistant`,content:``,id:p}),U()){let n=`Demo response for: ${t.trim()}`;window.setTimeout(()=>{f(e,p,n),c(!1),j(),o(null),g(!1),N(e),_.current=null,x.current=``,S.current=``},500);return}X.isConnected||await X.connect();let m=l?a?.messages?.filter(e=>e.role!==`system`&&e.id!==p).map(e=>({role:e.role,content:e.content,thinking:e.thinking,images:e.images,providerMetadata:e.providerMetadata})):void 0;X.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:n,format:r,options:a?.settings?.generationOptions??{},assistantMessageId:p,isPrivate:l,...l?{model:a?.model,providerType:a?.providerType,providerId:a?.providerId,messageHistory:m}:{}}})}catch(e){gn.error(`Failed to send message:`,e),c(!1),j(),o(null),g(!1),_.current=null,S.current=``,w.error(`Failed to send message`)}},[e,d,f,g,j,N]),F=(0,Q.useCallback)(()=>{c(!1),j(),o(null),g(!1),_.current=null,S.current=``},[g,j]),I=(0,Q.useCallback)(async()=>{let t=Y.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,i=-1,a=-1;for(let e=r.length-1;e>=0;e--)if(r[e].role===`assistant`){a=e;break}if(a>0){for(let e=a-1;e>=0;e--)if(r[e].role===`user`){i=e;break}}if(i===-1||a===-1){w.error(`No message to regenerate`);return}let s=r[i],l=r[a];try{g(!0),c(!0),j(),T.current&&clearTimeout(T.current),C.current=Date.now();let t=xe();_.current=t,S.current=``,o(t),d(e,{role:`assistant`,content:``,id:t,parentId:l.parentId||l.id,branchIndex:l.siblingCount||1,isActive:!0}),X.isConnected||await X.connect();let i=n.isPrivate===!0,a=i?r.filter(e=>e.role!==`system`).map(e=>({role:e.role,content:e.content,thinking:e.thinking,images:e.images,providerMetadata:e.providerMetadata})):void 0;X.send({type:`chat_stream`,data:{sessionId:e,content:s.content,images:s.images,options:n.settings?.generationOptions??{},assistantMessageId:t,regenerate:!0,originalMessageId:l.id,isPrivate:i,...i?{model:n.model,providerType:n.providerType,providerId:n.providerId,messageHistory:a}:{}}})}catch(e){gn.error(`Failed to regenerate message:`,e),c(!1),j(),o(null),g(!1),_.current=null,S.current=``,w.error(`Failed to regenerate message`)}},[e,g,j,d]),ee=(0,Q.useCallback)(async t=>{let n=Y.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){w.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await 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()};Y.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),w.success(`Switched to variant ${a+1}`)}else w.error(r.error||`Failed to select branch`)}catch(e){gn.error(`Failed to select branch:`,e),w.error(`Failed to select branch`)}},[e]);return{sendMessage:P,stopGeneration:F,regenerateLastMessage:I,editAndResendMessage:(0,Q.useCallback)(async(t,n)=>{if(!e||!n.trim())return;let r=Y.getState(),i=r.currentSession;if(!i||i.id!==e)return;let a=i.messages.findIndex(e=>e.id===t);if(a===-1||i.messages[a].role!==`user`)return;let o=i.messages[a],s=i.messages.slice(0,a);try{i.isPrivate||await G.updateSession(e,{messages:s}),r.truncateMessagesFrom(e,t),await P(n,o.images)}catch(e){gn.error(`Failed to edit message:`,e),w.error(`Failed to edit message`)}},[e,P]),selectBranch:ee,isStreaming:s,streamingMessage:t,streamingThinking:r,streamingMessageId:a,toolActivities:l}},bn=W(`pages:chat-page`),xn=(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?`}},Sn=(e,t,n,r=!1)=>{let i=je(e);return i===`time`?xn(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.`}},Cn=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),u=o(),{currentSession:f,sessions:m,models:g,selectedModel:_,selectedProviderType:v,selectedProviderId:b,setSelectedModel:x,createSession:S,setCurrentSession:C,loadSessions:T,getCurrentPersona:E}=Y(),{user:D}=Oe(),O=ke(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:k,stopGeneration:A,regenerateLastMessage:j,editAndResendMessage:M,selectBranch:N,isStreaming:P,streamingMessage:F,streamingThinking:I,streamingMessageId:ee,toolActivities:te}=yn(f?.id||``),L=E(),R=(0,Q.useMemo)(()=>({model:_,providerType:v,providerId:b}),[_,b,v]),z=(0,Q.useMemo)(()=>Te(g,R),[g,R]),ne=_?Se(z,R):``,re=Ce(g,R),ie=new URLSearchParams(u.search).get(`incognito`)===`1`,[ae,B]=(0,Q.useState)(Ae),[oe,se]=(0,Q.useState)(null),[ce,le]=(0,Q.useState)(!1),V=ke(e=>e.preferences.showFollowUpSuggestions!==!1),ue=(0,Q.useRef)(null),de=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=f?.id,t=de.current&&!P;if(de.current=P,!e||P||!V||f?.isPrivate||!t)return;let n=f.messages[f.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||ue.current===n.id)return;ue.current=n.id;let r=!1;return G.generateFollowUps(e).then(t=>{r||!t.success||Y.getState().currentSession?.id===e&&se({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[P,f,V]);let U=oe&&oe.sessionId===f?.id?oe.suggestions:[],W=(0,Q.useMemo)(()=>Sn(ae,D?.username,e,c(t.language)),[t.language,e,D?.username,ae]),[K,pe]=(0,Q.useState)(``),[q,me]=(0,Q.useState)([]),[he,ge]=(0,Q.useState)(!1),_e=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{B(Ae())};return window.addEventListener(Me,e),()=>window.removeEventListener(Me,e)},[]);let[ve,ye]=(0,Q.useState)(!1),be=O&&ve,X=(0,Q.useCallback)((t=!0)=>{let n=_?R: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,_,R,C,e]);(0,Q.useEffect)(()=>{m.length===0&&T()},[T,m.length]),(0,Q.useEffect)(()=>{!ie||f?.isPrivate||X(!1)},[f?.isPrivate,ie,X]),(0,Q.useEffect)(()=>{let e=!1;return O&&(async()=>{try{let t=await fe.getPlugins();if(e)return;ye(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ye(!1)}})(),()=>{e=!0}},[O]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!(f?.isPrivate&&!n)&&m.length!==0)if(n){let e=m.find(e=>e.id===n);e&&e.id!==f?.id?C(e):e||(bn.warn(`Session ${n} not found for current user, redirecting...`),m.length>0?r(`/c/${m[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&m.length>0&&u.pathname===`/`&&r(`/c/${m[0].id}`,{replace:!0})})()},[n,m,C,r,f?.id,f?.isPrivate,u.pathname]),(0,Q.useEffect)(()=>{if(f?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{k(t.content,t.images)},100)}catch(e){bn.error(`Failed to parse pending message:`,e)}}}},[f?.id,k]),(0,Q.useEffect)(()=>{let e=_e.current;e&&(e.style.height=`auto`,e.style.height=K?`${Math.min(e.scrollHeight,200)}px`:``)},[K]);let je=async t=>{if(t.preventDefault(),!K.trim()||!_)return;if(!re){w.error(e(`chat.model.selectBeforeSending`));return}Ne(`impact`);let n={content:K.trim(),images:q.length>0?q:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),pe(``),me([]);let i=await S(_,void 0,_.startsWith(`persona:`)?_.slice(8):void 0,v,b);i&&(await Pe(i),r(`/c/${i.id}`,{replace:!0}))},Pe=(0,Q.useCallback)(async e=>{let t=Y.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions;if(!n&&!r)return;let i=n?[{id:xe(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await G.updateSession(e.id,{messages:i,settings:r?{generationOptions:r}:void 0});if(t.success&&t.data){let e=t.data;Y.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){bn.error(`Failed to apply chat settings to the new session`,e)}finally{Y.getState().setDraftSessionSettings({})}},[]),Fe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),je(e))},Ie=async e=>{let t=De(z,e.target.value);t&&x(t.model,t.providerType,t.providerId)},Le=(e,t,n)=>{f&&(Ne(`impact`),se(null),k(e,t,n))};if(!f){let t=q.length>0;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`relative h-full min-w-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,$.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,$.jsx)(`div`,{className:`absolute left-[12%] top-[18%] h-56 w-56 rounded-full bg-primary-500/[0.035] blur-3xl dark:bg-primary-400/[0.04]`}),(0,$.jsx)(`div`,{className:`absolute bottom-[16%] right-[10%] h-72 w-72 rounded-full bg-gray-900/[0.025] blur-3xl dark:bg-white/[0.025]`}),(0,$.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,$.jsx)(`button`,{onClick:()=>le(e=>!e),className:J(`absolute end-4 top-4 z-10 flex h-9 w-9 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 sm:end-6 sm:top-6`,ce&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ce,children:(0,$.jsx)(p,{className:`h-4 w-4`})}),(0,$.jsxs)(`button`,{onClick:()=>X(),disabled:!_&&g.length===0||!!_&&!re,className:`absolute end-[3.75rem] 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-[4.25rem] sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,$.jsx)(H,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{children:e(`chat.session.incognito`,`Incognito Chat`)})]}),(0,$.jsxs)(`div`,{className:`relative z-[1] mx-auto flex min-h-full w-full max-w-3xl flex-col items-center justify-center`,children:[(0,$.jsxs)(`div`,{className:`mb-10 flex flex-col items-center text-center animate-fade-in sm:mb-12`,"aria-live":`polite`,children:[(0,$.jsx)(`h1`,{className:`mb-4 max-w-3xl text-balance text-[clamp(2.65rem,7vw,5.25rem)] font-light leading-[0.98] tracking-[-0.055em] text-gray-950 dark:text-dark-950 rtl:leading-[1.12] rtl:tracking-normal`,children:W.title}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-base leading-relaxed text-gray-500 dark:text-dark-600 sm:text-lg`,children:W.subtitle})]},W.id),z.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[he&&(0,$.jsx)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:(0,$.jsx)(hn,{images:q,onImagesChange:me,maxImages:5})}),(0,$.jsx)(`form`,{onSubmit:je,children:(0,$.jsxs)(`div`,{className:J(`flex items-end gap-2 rounded-[1.35rem] border p-2 transition-[border-color,box-shadow,background-color] duration-200`,`border-black/[0.08] bg-surface/90 dark:border-white/[0.09] dark:bg-dark-200/90`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_50px_rgba(15,23,42,0.08)] backdrop-blur-xl`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_22px_65px_rgba(15,23,42,0.12)]`),children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ge(!he),className:J(`h-9 w-9 sm:h-10 sm:w-10 !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`,he&&`bg-gray-100 dark:bg-dark-300`),title:e(`chat.input.attachImages`),children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(h,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):he?(0,$.jsx)(l,{className:`h-4 w-4`}):(0,$.jsx)(d,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)($t,{ref:_e,value:K,onChange:e=>pe(e.target.value),onKeyDown:Fe,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 block min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-1.5 !py-1.5 sm:!min-h-10 sm:!py-2 max-[768px]:!min-h-11 max-[768px]:!py-[10.5px] !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1})}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Be,{models:z,selectedModel:ne,onModelChange:Ie,getModelValue:Ee,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:be})}),(0,$.jsx)(Z,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!K.trim()||!_||!re,className:J(`h-9 w-9 sm:h-10 sm:w-10 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`,K.trim()&&_&&`shadow-sm`),title:e(`chat.input.sendMessage`),children:(0,$.jsx)(y,{className:`h-4 w-4`})})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(Be,{models:z,selectedModel:ne,onModelChange:Ie,getModelValue:Ee,className:`w-full`,compact:!0,showImageGen:be})}),(0,$.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,$.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,$.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.07] bg-surface/70 p-6 backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/70`,children:[(0,$.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,$.jsx)(`code`,{className:`block rounded-xl bg-gray-100 p-3 font-mono text-xs text-gray-800 dark:bg-dark-300 dark:text-dark-700`,children:e(`chat.model.pullCommand`)})]})})]})]}),(0,$.jsx)(pn,{draftModel:_,open:ce,onClose:()=>le(!1)})]})}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:L?.background?{backgroundImage:`url(${L.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[L?.background&&(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,$.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[f?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(H,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,$.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),L&&!f?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,$.jsx)(mn,{persona:L,onClear:()=>{f&&G.updateSession(f.id,{model:L.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);Y.setState(t=>({sessions:t.sessions.map(t=>t.id===f.id?e.data:t),currentSession:e.data}))}).catch(t=>{bn.error(`Failed to remove persona:`,t),w.error(e(`chat.persona.removeFailed`))})}})}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`button`,{onClick:()=>le(e=>!e),className:J(`absolute end-3 top-3 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950`,ce&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ce,children:(0,$.jsx)(p,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(Zt,{messages:f.messages,streamingMessage:F,streamingThinking:I,streamingMessageId:ee,isStreaming:P,toolActivities:te,onRegenerate:j,onSelectBranch:N,onEditResend:M,followUpSuggestions:U,onFollowUpSelect:e=>Le(e),className:`flex-1`}),(0,$.jsx)(un,{onSendMessage:Le,onStopGeneration:A,disabled:!f})]}),(0,$.jsx)(pn,{session:f,open:ce,onClose:()=>le(!1)})]})]})]})};export{Cn as ChatPage,Cn 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,Y as s,c,hn as l,tt as u,un as d,wt as f}from"./ui-vendor-D_pYT79f.js";import{i as p,n as m,t as h}from"./utils-BhpNrGnR.js";import{t as g}from"./chatStore-CWqfsOjc.js";import{l as _,n as v}from"./authStore-DmrydYuS.js";import{a as y,c as b,o as x,s as S,t as C}from"../assets/index-Cd0_AoYV.js";import{t as w}from"./work-DVgm81bJ.js";var T=e(n(),1),E=t(),D=e=>e<5?[`home.greeting.night`,`Up late`]:e<12?[`home.greeting.morning`,`Morning`]:e<18?[`home.greeting.afternoon`,`Afternoon`]:[`home.greeting.evening`,`Evening`],O=`mb-2 text-xs font-medium text-gray-500 dark:text-dark-500`,k=`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`,A=()=>{let{t:e,i18n:t}=i(),n=r(),{user:A,systemInfo:j,isAdmin:M}=v(),N=g(e=>e.sessions),P=_(e=>e.tasks),F=_(e=>e.capabilities),I=_(e=>e.loadTasks),L=_(e=>e.loadCapabilities),R=j?.requiresAuth===!1||M(),z=R;(0,T.useEffect)(()=>{R&&(I(!0).catch(()=>{}),L().catch(()=>{}))},[R,I,L]);let[B,V]=D(new Date().getHours()),H=e(B,V),U=A?.username,W=[...N].sort((e,t)=>t.updatedAt-e.updatedAt).slice(0,4),G=[...P].sort((e,t)=>new Date(t.updatedAt).getTime()-new Date(e.updatedAt).getTime()).slice(0,3),K=F?.activeRuntimes?.user??0,q=p()?`⌘`:`Ctrl`,J=W.length>0||G.length>0,Y=C(j?.version);return(0,E.jsx)(`div`,{"data-testid":`home-page`,className:`h-full overflow-y-auto scrollbar-thin`,children:(0,E.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-xl flex-col justify-center px-6 py-12`,children:[(0,E.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-gray-950 dark:text-dark-950`,children:U?`${H}, ${U}.`:`${H}.`}),(0,E.jsxs)(`p`,{"data-testid":`app-version`,className:`mt-1 font-mono text-xs text-gray-400 dark:text-dark-500`,children:[window.location.host||`Libre WebUI`,Y?` · v${Y}`:``]}),(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsx)(`p`,{className:O,children:e(`home.start`,`Start`)}),(0,E.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-new-chat`,className:k,onClick:()=>x(n),children:[(0,E.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,E.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newChat`,`New Chat`)}),(0,E.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:[q,`⇧O`]})]}),(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-incognito-chat`,className:k,onClick:()=>y(n),children:[(0,E.jsx)(f,{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,E.jsx)(`span`,{className:`flex-1`,children:e(`chat.session.incognito`,`Incognito Chat`)})]}),R&&(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-new-work`,className:k,onClick:()=>S(n),children:[(0,E.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,E.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newWork`,`New Work`)}),(0,E.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:[q,`⇧U`]})]})]})]}),J&&(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsxs)(`div`,{className:`mb-2 flex items-baseline justify-between`,children:[(0,E.jsx)(`p`,{className:h(O,`mb-0`),children:e(`home.continue`,`Continue`)}),R&&K>0&&(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,E.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse-subtle rounded-full bg-[rgb(48,121,255)]`}),K,` `,e(`home.active`,`active`)]})]}),(0,E.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[G.map(r=>{let i=b[r.status];return(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-work`,className:k,onClick:()=>n(`/work/${r.id}`),children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:h(`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,E.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`work.tasks.untitled`,`Untitled task`)}),r.hostPath&&(0,E.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,E.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:w(r)?e(i.labelKey,i.label):m(new Date(r.updatedAt).getTime(),t.language)})]},r.id)}),W.map(r=>(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-chat`,className:k,onClick:()=>n(`/c/${r.id}`),children:[(0,E.jsx)(u,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,E.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`tabs.chat`,`Chat`)}),(0,E.jsx)(`span`,{className:`hidden shrink-0 font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,children:r.model}),(0,E.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:m(r.updatedAt,t.language)})]},r.id))]})]}),(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsx)(`p`,{className:O,children:e(`home.explore`,`Explore`)}),(0,E.jsx)(`div`,{className:`-mx-2.5 flex flex-col`,children:[[`/notes`,s,e(`sidebar.navigation.notes`,`Notes`)],[`/models`,o,e(`sidebar.navigation.models`,`Models`)],[`/personas`,c,e(`sidebar.navigation.personas`,`Personas`)],[`/gallery`,a,e(`sidebar.navigation.imagine`,`Imagine`)],...z?[[`/agents`,l,e(`sidebar.navigation.agents`,`Agents`)]]:[]].map(([e,t,r])=>(0,E.jsxs)(`button`,{type:`button`,className:k,onClick:()=>n(e),children:[(0,E.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,E.jsx)(`span`,{className:`flex-1`,children:r})]},e))})]})]})})};export{A as HomePage,A 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{n as r}from"./react-vendor-DPNXrO-8.js";import{d as i}from"./router-vendor-Ca9zqOqT.js";import{t as a}from"./useTranslation-CdeLZqSW.js";import{B as o,Bt as s,Ht as c,P as l,R as u,T as d,Tn as f,Wt as p,Yt as m,an as h,c as g,dn as _,gt as v,hn as y,n as b,on as x,ot as S,pt as C,t as w,v as T,vt as ee}from"./ui-vendor-D_pYT79f.js";import{t as te}from"./logger-DSXjF4ye.js";import{m as E,v as ne}from"./api-MySpmAK8.js";import{t as D}from"./utils-BhpNrGnR.js";import{s as re}from"./chatStore-CWqfsOjc.js";import{n as ie}from"./authStore-DmrydYuS.js";import{f as ae}from"../assets/index-Cd0_AoYV.js";var O=e(n(),1),oe=r(),k=t();function A(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function se({hfTask:e,hfSort:t,canInstallModels:n,loadingHf:r,hfModels:i,expandedHfModel:o,hfGgufFiles:l,loadingGguf:d,pullingModel:f,pullProgress:p,setHfTask:m,setHfSort:g,onToggleHfModel:_,onPullHfGguf:y,onCancelPull:x,onRefreshHfModels:C}){let{t:T}=a();return(0,k.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,k.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0 space-y-2`,children:(0,k.jsxs)(`div`,{className:`flex gap-2`,children:[(0,k.jsxs)(`select`,{value:e,onChange:e=>m(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`flex-1 px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,children:[(0,k.jsx)(`option`,{value:`text-generation`,children:T(`modelManager.huggingface.taskTextGeneration`)}),(0,k.jsx)(`option`,{value:`text-to-speech`,children:T(`modelManager.huggingface.taskTextToSpeech`)}),(0,k.jsx)(`option`,{value:`text-to-image`,children:T(`modelManager.huggingface.taskTextToImage`)}),(0,k.jsx)(`option`,{value:`automatic-speech-recognition`,children:T(`modelManager.huggingface.taskSpeechRecognition`)})]}),(0,k.jsxs)(`select`,{value:t,onChange:e=>g(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,children:[(0,k.jsx)(`option`,{value:`downloads`,children:T(`modelManager.huggingface.sortDownloads`)}),(0,k.jsx)(`option`,{value:`likes`,children:T(`modelManager.huggingface.sortLikes`)}),(0,k.jsx)(`option`,{value:`lastModified`,children:T(`modelManager.huggingface.sortRecent`)})]})]})}),(0,k.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin`,children:[!n&&(0,k.jsx)(`div`,{className:`mx-3 mb-1 mt-3 rounded-lg border border-amber-200 bg-amber-500/10 px-3 py-2 text-xs text-ink dark:border-amber-800 dark:bg-amber-900/20`,children:T(`modelSelector.pullRestricted`)}),r?(0,k.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,k.jsx)(S,{className:`h-6 w-6 animate-spin text-gray-400`})}):i.length===0?(0,k.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,k.jsx)(w,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,k.jsx)(`p`,{className:`text-sm`,children:T(`modelManager.huggingface.noModelsFound`)})]}):(0,k.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:i.map(e=>{let t=o===e.id,r=l[e.id]||[],i=d===e.id;return(0,k.jsxs)(`div`,{className:`bg-white dark:bg-dark-100`,children:[(0,k.jsx)(`div`,{className:`px-3 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-200`,onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),_(e.id)},children:(0,k.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,k.jsx)(`div`,{className:`flex-shrink-0 rounded-lg bg-yellow-500/20 p-2 dark:bg-yellow-900/30`,children:(0,k.jsx)(w,{className:`h-4 w-4 text-yellow-600 dark:text-yellow-400`})}),(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`h4`,{dir:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.id}),e.gated&&(0,k.jsx)(`span`,{className:`rounded bg-yellow-500/20 px-1.5 py-0.5 text-xs text-ink dark:bg-yellow-900/30`,children:`Gated`})]}),(0,k.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-0.5`,children:[`by `,e.author]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 text-xs text-gray-400 dark:text-gray-500`,children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,k.jsx)(c,{className:`h-3 w-3`}),A(e.downloads)]}),(0,k.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,k.jsx)(v,{className:`h-3 w-3`}),A(e.likes)]}),e.pipeline_tag&&(0,k.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200`,children:e.pipeline_tag})]})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,k.jsx)(`a`,{href:`https://huggingface.co/${e.id}`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,k.jsx)(s,{className:`h-4 w-4 text-gray-400`})}),(0,k.jsx)(h,{className:D(`h-4 w-4 text-gray-400 transition-transform`,t&&`rotate-180`)})]})]})}),t&&(0,k.jsx)(`div`,{className:`px-3 pb-3 pt-1 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-200`,children:i?(0,k.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,k.jsx)(S,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,k.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:T(`modelManager.huggingface.checkingGguf`)})]}):r.length===0?(0,k.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:T(`modelManager.huggingface.noGgufAvailable`)}):(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 mb-2`,children:T(`modelManager.huggingface.ggufFilesCount`,{count:r.length})}),r.map(e=>{let t=f===e.ollamaCommand;return(0,k.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-white dark:bg-dark-100 border border-gray-200 dark:border-dark-300`,children:[(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 truncate`,children:e.filename}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,k.jsx)(`span`,{children:e.sizeFormatted}),e.quantization&&(0,k.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-400`,children:e.quantization})]})]}),t?(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:p?.percent===void 0?`...`:`${p.percent}%`}),(0,k.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),x()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,k.jsx)(b,{className:`h-4 w-4`})})]}):n?(0,k.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),y(e.ollamaCommand,e.filename)},disabled:!!f,className:D(`px-3 py-1.5 rounded-lg text-xs font-medium`,`bg-primary-100 dark:bg-primary-900/30`,`text-primary-700 dark:text-primary-400`,`hover:bg-primary-200 dark:hover:bg-primary-900/50`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,k.jsx)(c,{className:`h-3 w-3 inline mr-1`}),T(`models.pull`)]}):(0,k.jsx)(`span`,{className:`rounded bg-amber-500/20 px-2 py-1 text-[11px] font-medium text-ink dark:bg-amber-900/30`,children:T(`modelSelector.adminOnlyPull`)})]},e.filename)}),f?.startsWith(`hf.co/`)&&f.includes(e.id)&&p?.percent!==void 0&&(0,k.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,k.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${p.percent}%`}})})]})})]},e.id)})})]}),(0,k.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 flex items-center justify-between flex-shrink-0`,children:[(0,k.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 hover:underline flex items-center gap-1`,children:[(0,k.jsx)(s,{className:`h-3 w-3`}),T(`modelManager.huggingface.browseAllLink`)]}),(0,k.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),C()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,k.jsx)(u,{className:D(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}function ce({filteredGroups:e,selectedModel:t,showImageGen:n,getModelValue:r,getModelIcon:i,getModelLabel:s,getModelSubLabel:c,onModelSelect:l,onOpenGallery:u}){let{t:d}=a();return(0,k.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400`,children:[e.length>0?e.map(e=>(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-dark-300 border-b border-gray-200 dark:border-dark-400 sticky top-0`,children:(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon,e.label,` (`,e.models.length,`)`]})}),e.models.map(e=>{let n=r(e);return(0,k.jsx)(`button`,{type:`button`,"data-testid":`model-selector-option`,"data-model-value":n,"aria-pressed":t===n,onClick:()=>l(n),className:D(`block w-full cursor-pointer border-b border-gray-100 px-3 py-3 text-start last:border-b-0 dark:border-dark-200`,`hover:bg-gray-50 dark:hover:bg-dark-200`,`bg-white dark:bg-dark-100 transition-colors`,`focus-visible:relative focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500/50`,t===n&&`bg-primary-50 dark:bg-primary-900/30`),children:(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[i(e),(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsx)(`div`,{dir:e.isPersona?`auto`:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:s(e)}),c(e)&&(0,k.jsx)(`div`,{dir:`auto`,className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:c(e)})]}),t===n&&(0,k.jsx)(x,{className:`h-4 w-4 text-primary-600 dark:text-primary-400 flex-shrink-0`})]})},n)})]},e.type)):(0,k.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,k.jsx)(p,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,k.jsx)(`p`,{className:`text-sm`,children:d(`models.noModelsFound`)})]}),n&&(0,k.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-dark-300`,children:[(0,k.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-dark-300`,children:(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(o,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),d(`modelSelector.actions`)]})}),(0,k.jsx)(`div`,{onMouseDown:e=>{e.preventDefault(),u()},className:`px-3 py-3 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-900/20 bg-white dark:bg-dark-100`,children:(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,k.jsx)(C,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),(0,k.jsxs)(`div`,{className:`flex-1`,children:[(0,k.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:d(`gallery.generate`)}),(0,k.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d(`gallery.generateDescription`)})]})]})})]})]})}function le({libraryCategories:e,libraryCategory:t,canInstallModels:n,loadingLibrary:r,filteredLibraryModels:i,pullingModel:o,pullProgress:l,setLibraryCategory:d,isModelInstalled:f,onModelSelect:p,onPullModel:h,onCancelPull:g,onRefreshLibrary:_}){let{t:v}=a();return(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,k.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0`,children:(0,k.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,k.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),d(e)},className:D(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,t===e?`bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-dark-300`),children:e.charAt(0).toUpperCase()+e.slice(1)},e))})}),(0,k.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin`,children:[!n&&(0,k.jsx)(`div`,{className:`mx-3 mb-1 mt-3 rounded-lg border border-amber-200 bg-amber-500/10 px-3 py-2 text-xs text-ink dark:border-amber-800 dark:bg-amber-900/20`,children:v(`modelSelector.pullRestricted`)}),r?(0,k.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,k.jsx)(S,{className:`h-6 w-6 animate-spin text-gray-400`})}):i.length===0?(0,k.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,k.jsx)(m,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,k.jsx)(`p`,{className:`text-sm`,children:v(`models.noModelsFound`)})]}):(0,k.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:i.map(e=>{let t=f(e.name),r=o===e.name;return(0,k.jsxs)(`div`,{className:D(`px-3 py-3 bg-white dark:bg-dark-100`,t&&`bg-green-50/50 dark:bg-green-900/10`),children:[(0,k.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,k.jsx)(`div`,{className:`p-2 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex-shrink-0`,children:(0,k.jsx)(m,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`})}),(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`h4`,{dir:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.name}),t&&(0,k.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`,children:v(`modelSelector.installed`)}),(e.category===`cloud`||e.tags?.includes(`cloud`))&&(0,k.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400 flex items-center gap-1`,children:[(0,k.jsx)(m,{className:`h-3 w-3`}),`Cloud`]})]}),(0,k.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 line-clamp-1 mt-0.5`,children:e.description}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[e.sizes.slice(0,3).map(e=>(0,k.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:e},e)),e.pulls&&(0,k.jsxs)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1`,children:[(0,k.jsx)(c,{className:`h-3 w-3`}),e.pulls]})]})]}),(0,k.jsx)(`div`,{className:`flex-shrink-0`,children:r?(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:l?.percent===void 0?`...`:`${l.percent}%`}),(0,k.jsx)(`button`,{onClick:g,className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,k.jsx)(b,{className:`h-4 w-4`})})]}):t?(0,k.jsx)(`button`,{onClick:()=>p(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-900/50`,children:v(`modelSelector.use`)}):n?(0,k.jsxs)(`button`,{onClick:()=>h(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50`,children:[(0,k.jsx)(c,{className:`h-3 w-3 inline mr-1`}),v(`modelSelector.pull`)]}):(0,k.jsx)(`span`,{className:`rounded bg-amber-500/20 px-2 py-1 text-[11px] font-medium text-ink dark:bg-amber-900/30`,children:v(`modelSelector.adminOnlyPull`)})})]}),r&&l?.percent!==void 0&&(0,k.jsx)(`div`,{className:`mt-2 w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden`,children:(0,k.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${l.percent}%`}})})]},e.name)})})]}),(0,k.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 flex items-center justify-between flex-shrink-0`,children:[(0,k.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 hover:underline flex items-center gap-1`,children:[(0,k.jsx)(s,{className:`h-3 w-3`}),v(`modelManager.huggingface.browseAllLink`)]}),(0,k.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),_()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,k.jsx)(u,{className:D(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}var ue=te(`components:model-selector`),j=({models:e,selectedModel:t,onModelChange:n,currentPersona:r,className:o,disabled:s=!1,compact:c=!1,showImageGen:u=!1,onModelsRefresh:p,getModelValue:v,getModelLabel:x,getModelTitle:S,triggerRef:C,triggerTestId:te,selectTestId:A,ariaLabel:j})=>{let{t:M}=a(),[N,de]=(0,O.useState)(!1),[P,fe]=(0,O.useState)(``),[F,I]=(0,O.useState)(`installed`),pe=(0,O.useRef)(null),L=(0,O.useRef)(null),R=(0,O.useRef)(null),z=(0,O.useRef)(null),me=i(),{user:he,systemInfo:ge}=ie(),B=he?.role===`admin`||ge?.requiresAuth===!1,[V,_e]=(0,O.useState)(`all`),[ve,ye]=(0,O.useState)(``),[H,be]=(0,O.useState)(`text-generation`),[U,xe]=(0,O.useState)(`downloads`),[Se,Ce]=(0,O.useState)(``),[W,we]=(0,O.useState)(null),[G,Te]=(0,O.useState)({}),[Ee,De]=(0,O.useState)(null),[K,q]=(0,O.useState)(null),[Oe,J]=(0,O.useState)(null),[ke,Y]=(0,O.useState)(null),Ae=[`all`,`general`,`coding`,`reasoning`,`vision`,`embedding`,`cloud`],je=[{type:`legacy`,label:M(`modelSelector.providerNotRecorded`,`Provider not recorded`),icon:(0,k.jsx)(_,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isLegacySelection),color:`gray`},{type:`unavailable`,label:M(`modelSelector.unavailableSelections`,`Unavailable selections`),icon:(0,k.jsx)(b,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isUnavailable&&!e.isLegacySelection),color:`gray`},{type:`personas`,label:M(`modelSelector.personas`),icon:(0,k.jsx)(g,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPersona&&!e.isUnavailable),color:`purple`},{type:`agents`,label:M(`modelSelector.agentModels`,`Agents`),icon:(0,k.jsx)(T,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isAgent&&!e.isUnavailable),color:`green`},{type:`ollama`,label:M(`modelSelector.ollamaModels`),icon:(0,k.jsx)(y,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>re(e)&&!e.name.includes(`embed`)),color:`green`},{type:`plugins`,label:M(`modelSelector.pluginModels`),icon:(0,k.jsx)(w,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPlugin&&!e.isUnavailable),color:`green`}].filter(e=>e.models.length>0).map(e=>({...e,models:e.models.filter(e=>e.name.toLowerCase().includes(P.toLowerCase())||e.personaName&&e.personaName.toLowerCase().includes(P.toLowerCase())||e.pluginName&&e.pluginName.toLowerCase().includes(P.toLowerCase()))})).filter(e=>e.models.length>0),X=e=>v?.(e)??e.name,Z=e.find(e=>X(e)===t);(0,O.useImperativeHandle)(C,()=>R.current);let Q=(0,O.useCallback)((e=!0)=>{de(!1),fe(``),e&&window.requestAnimationFrame(()=>R.current?.focus())},[]),{data:Me=[],isLoading:Ne,refetch:Pe}=ae({queryKey:[`ollama-library-selector`,ve,V===`cloud`?`cloud`:`all`],queryFn:async()=>{let e=await E.getLibraryModels({search:ve||void 0,sort:`popular`,category:V===`cloud`?`cloud`:void 0});return e.success&&e.data?e.data:[]},enabled:N&&F===`ollama`}),{data:Fe=[],isLoading:Ie,refetch:Le}=ae({queryKey:[`hf-models-selector`,H,Se,U],queryFn:async()=>{let e=await ne.getModels({task:H,search:Se||void 0,sort:U,limit:30});return e.success&&e.data?e.data:[]},enabled:N&&F===`huggingface`}),Re=Me.filter(e=>{let t=!P||e.name.toLowerCase().includes(P.toLowerCase())||e.description.toLowerCase().includes(P.toLowerCase()),n=V===`all`||e.category===V;return t&&n}),ze=(0,O.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){De(e);try{let r=await ne.getGgufFiles(t,n);r.success&&r.data&&Te(t=>({...t,[e]:r.data}))}catch(e){ue.error(`Failed to load GGUF files:`,e)}finally{De(null)}}},[]),Be=(0,O.useCallback)(e=>{W===e?we(null):(we(e),G[e]||ze(e))},[W,G,ze]),Ve=(0,O.useCallback)((e,t)=>{if(!B){f.error(M(`modelSelector.pullRestricted`));return}if(!K){q(e),J({status:`starting`});try{let n=E.pullModelStream(e,e=>{J(e)},()=>{J(null),q(null),Y(null),f.success(`Downloaded ${t}`),p?.()},e=>{J(null),q(null),Y(null),f.error(`Failed to download: ${e}`)});Y(()=>n)}catch{J(null),q(null),f.error(`Failed to start download`)}}},[B,p,K,M]);(0,O.useEffect)(()=>{let e=setTimeout(()=>{F===`huggingface`?Ce(P):F===`ollama`&&ye(P)},300);return()=>clearTimeout(e)},[P,F]),(0,O.useEffect)(()=>{if(!N)return;let e=e=>{if(e.key===`Escape`){e.preventDefault(),Q();return}if(e.key===`Tab`&&L.current){let t=Array.from(L.current.querySelectorAll(`button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`)).filter(e=>e.offsetParent!==null),n=t[0],r=t[t.length-1];if(!n||!r)return;e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus())}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Q,N]),(0,O.useEffect)(()=>{N&&z.current&&z.current.focus()},[N]);let He=async t=>{let r=e.find(e=>X(e)===t)??e.find(e=>!e.isPlugin&&!e.isPersona&&e.name===t),i=r?X(r):t,a=r?.name??t;Q();try{let e=await E.listRunningModels();if(e.success&&e.data){let t=e.data;t.length>0&&(r?.isPlugin!==!0&&t.some(e=>e.name===a||a.startsWith(`persona:`))||await E.unloadAllModels())}}catch(e){ue.warn(`Failed to unload models before switch:`,e)}n({target:{value:i}})},Ue=async e=>{if(!B){f.error(M(`modelSelector.pullRestricted`));return}if(!K){q(e),J({status:`starting`});try{let t=E.pullModelStream(e,e=>{J(e)},()=>{J(null),q(null),Y(null),f.success(`Downloaded ${e}`),p?.()},e=>{J(null),q(null),Y(null),f.error(`Failed to download: ${e}`)});Y(()=>t)}catch{J(null),q(null),f.error(`Failed to start download`)}}},We=()=>{ke&&(ke(),Y(null),q(null),J(null),f.success(`Download cancelled`))},Ge=t=>e.some(e=>re(e)&&(e.name===t||e.name.startsWith(t+`:`))),Ke=e=>e.isLegacySelection?(0,k.jsx)(_,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):e.isPersona?(0,k.jsx)(g,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):e.isPlugin?(0,k.jsx)(w,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):(0,k.jsx)(y,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),$=e=>x?x(e):e.isLegacySelection?`${e.name} (${M(`modelSelector.legacyProvider`,`provider not recorded`)})`:e.isPersona?e.personaName||e.name:e.isAgent?e.isUnavailable?`${e.agentName||e.name} (${M(`modelSelector.unavailable`,`unavailable`)})`:e.agentName||e.name:(e.isPlugin,e.isUnavailable?`${e.name} (${M(`modelSelector.unavailable`,`unavailable`)})`:e.name),qe=e=>e.isLegacySelection?e.isUnavailable?M(`modelSelector.providerUnavailable`,`provider unavailable`):M(`modelSelector.reselectProvider`,`reselect a provider to pin this model`):e.isPersona?`via ${e.model}`:e.isPlugin?e.isUnavailable?`via ${e.pluginName||e.pluginId} · ${M(`modelSelector.providerUnavailable`,`provider unavailable`)}`:`via ${e.pluginName}`:e.isUnavailable?M(`modelSelector.providerUnavailable`,`provider unavailable`):null;return(0,k.jsxs)(`div`,{className:D(`relative`,o),ref:pe,children:[(0,k.jsxs)(`button`,{ref:R,"data-testid":te,type:`button`,onClick:()=>!s&&de(!N),disabled:s,"aria-haspopup":`dialog`,"aria-expanded":N,"aria-label":j&&Z?`${j}: ${$(Z)}`:j,className:D(c?`h-9 sm:h-10 px-2.5 flex items-center justify-between text-start w-full`:`w-full flex items-center justify-between gap-2 px-3 py-2.5 text-start`,`border border-black/[0.06] bg-gray-100/70 dark:border-white/[0.06] dark:bg-dark-300/70`,`rounded-xl text-sm hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500/40`,s?`opacity-50 cursor-not-allowed`:`cursor-pointer`),title:c?Z?S?.(Z)??$(Z):M(`modelSelector.selectModel`):void 0,children:[(()=>{if(!Z)return c?(0,k.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,k.jsx)(y,{className:`h-4 w-4`}),(0,k.jsx)(`span`,{className:`text-xs font-medium text-gray-400 dark:text-gray-500 truncate`,children:M(`modelSelector.selectModel`)})]}):M(`modelSelector.selectModel`);if(c){let e=$(Z);return(0,k.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[Ke(Z),(0,k.jsx)(`span`,{dir:Z.isPersona?`auto`:`ltr`,className:`text-xs font-medium text-gray-700 dark:text-gray-200 truncate`,children:e})]})}let e=$(Z),t=qe(Z);return(0,k.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[Ke(Z),(0,k.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,k.jsx)(`span`,{dir:Z.isPersona?`auto`:`ltr`,className:`text-sm font-medium truncate`,children:e}),t&&(0,k.jsx)(`span`,{dir:`auto`,className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:t})]}),Z.isPersona&&r&&(0,k.jsxs)(`div`,{className:`flex items-center gap-1 ms-auto`,children:[(0,k.jsx)(_,{className:`h-3 w-3 text-gray-500 dark:text-dark-600`}),r.embedding_model&&(0,k.jsx)(d,{className:`h-3 w-3 text-gray-400 dark:text-dark-500`})]})]})})(),(0,k.jsx)(h,{className:D(c?`h-3 w-3`:`h-4 w-4`,`text-gray-400 flex-shrink-0 transition-transform duration-150`,N&&`rotate-180`)})]}),N&&(0,oe.createPortal)((0,k.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-3 sm:p-6`,children:[(0,k.jsx)(`div`,{className:`absolute inset-0 bg-gray-950/55 backdrop-blur-md`,onClick:()=>Q()}),(0,k.jsxs)(`div`,{ref:L,role:`dialog`,"aria-modal":`true`,"aria-label":M(`modelSelector.selectModel`),className:D(`relative flex w-full max-w-xl flex-col overflow-hidden bg-white/[0.98] dark:bg-dark-25/[0.98]`,`h-[min(620px,88vh)] rounded-[1.5rem] border border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_30px_100px_rgba(0,0,0,0.28)] backdrop-blur-xl animate-scale-in`),onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:`flex-shrink-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4 sm:px-5 sm:pt-5`,children:[(0,k.jsx)(`h2`,{className:`text-lg font-medium tracking-[-0.025em] text-gray-950 dark:text-dark-950 rtl:tracking-normal`,children:M(`modelSelector.selectModel`)}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>Q(),className:`flex h-9 w-9 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-950 dark:text-dark-500 dark:hover:bg-dark-200 dark:hover:text-dark-950`,title:M(`common.close`),children:(0,k.jsx)(b,{className:`h-4 w-4`})})]}),(0,k.jsx)(`div`,{className:`px-4 pb-3 sm:px-5`,children:(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(l,{className:`absolute start-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400`}),(0,k.jsx)(`input`,{ref:z,type:`text`,placeholder:M(F===`installed`?`modelSelector.searchInstalled`:F===`ollama`?`modelSelector.searchOllama`:`modelSelector.searchHuggingFace`),value:P,onChange:e=>fe(e.target.value),className:D(`w-full rounded-xl border border-black/[0.07] bg-gray-100/70 py-2.5 ps-10 pe-4 text-sm dark:border-white/[0.07] dark:bg-dark-200/70`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`text-gray-900 dark:text-dark-900 placeholder:text-gray-400 dark:placeholder:text-dark-500`)})]})}),(0,k.jsxs)(`div`,{className:`mx-4 mb-3 flex rounded-xl bg-gray-100/70 p-1 dark:bg-dark-200/70 sm:mx-5`,children:[(0,k.jsxs)(`button`,{onClick:()=>{I(`installed`)},className:D(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,F===`installed`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":F===`installed`,children:[(0,k.jsx)(ee,{className:`h-4 w-4 inline me-1.5`}),M(`modelSelector.installed`)]}),(0,k.jsxs)(`button`,{onClick:()=>{I(`ollama`)},className:D(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,F===`ollama`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":F===`ollama`,children:[(0,k.jsx)(m,{className:`h-4 w-4 inline me-1.5`}),`Ollama`]}),(0,k.jsxs)(`button`,{onClick:()=>{I(`huggingface`)},className:D(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,F===`huggingface`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":F===`huggingface`,children:[(0,k.jsx)(w,{className:`h-4 w-4 inline me-1.5`}),`HuggingFace`]})]})]}),F===`installed`&&(0,k.jsx)(ce,{filteredGroups:je,selectedModel:t,showImageGen:u,getModelValue:X,getModelIcon:Ke,getModelLabel:$,getModelSubLabel:qe,onModelSelect:He,onOpenGallery:()=>{Q(!1),me(`/gallery`)}}),F===`ollama`&&(0,k.jsx)(le,{libraryCategories:Ae,libraryCategory:V,canInstallModels:B,loadingLibrary:Ne,filteredLibraryModels:Re,pullingModel:K,pullProgress:Oe,setLibraryCategory:_e,isModelInstalled:Ge,onModelSelect:He,onPullModel:Ue,onCancelPull:We,onRefreshLibrary:()=>{Pe()}}),F===`huggingface`&&(0,k.jsx)(se,{hfTask:H,hfSort:U,canInstallModels:B,loadingHf:Ie,hfModels:Fe,expandedHfModel:W,hfGgufFiles:G,loadingGguf:Ee,pullingModel:K,pullProgress:Oe,setHfTask:be,setHfSort:xe,onToggleHfModel:Be,onPullHfGguf:Ve,onCancelPull:We,onRefreshHfModels:()=>{Le()}})]})]}),document.body),(0,k.jsx)(`select`,{"data-testid":A,"aria-label":j,"aria-hidden":`true`,dir:`ltr`,value:t,onChange:n,className:`hidden`,tabIndex:-1,children:e.map(e=>(0,k.jsx)(`option`,{value:X(e),children:$(e)},`${e.isLegacySelection?`legacy`:e.isPersona?`persona`:e.isPlugin?`plugin`:`ollama`}:${e.pluginId||``}:${X(e)}`))})]})};export{j as t};