libre-webui 0.39.0 → 0.40.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 (198) hide show
  1. package/backend/dist/persistence/extensionTypes.d.ts +2 -0
  2. package/backend/dist/persistence/extensionTypes.d.ts.map +1 -1
  3. package/backend/dist/persistence/extensionTypes.js.map +1 -1
  4. package/backend/dist/persistence/postgresExtensionRepositories.d.ts.map +1 -1
  5. package/backend/dist/persistence/postgresExtensionRepositories.js +6 -0
  6. package/backend/dist/persistence/postgresExtensionRepositories.js.map +1 -1
  7. package/backend/dist/persistence/sqliteExtensionRepositories.d.ts.map +1 -1
  8. package/backend/dist/persistence/sqliteExtensionRepositories.js +7 -0
  9. package/backend/dist/persistence/sqliteExtensionRepositories.js.map +1 -1
  10. package/backend/dist/routes/email.d.ts.map +1 -1
  11. package/backend/dist/routes/email.js +51 -1
  12. package/backend/dist/routes/email.js.map +1 -1
  13. package/backend/dist/routes/tts.d.ts.map +1 -1
  14. package/backend/dist/routes/tts.js +6 -1
  15. package/backend/dist/routes/tts.js.map +1 -1
  16. package/backend/dist/services/agentCliService.d.ts.map +1 -1
  17. package/backend/dist/services/agentCliService.js +1 -0
  18. package/backend/dist/services/agentCliService.js.map +1 -1
  19. package/backend/dist/services/emailService.d.ts +17 -3
  20. package/backend/dist/services/emailService.d.ts.map +1 -1
  21. package/backend/dist/services/emailService.js +73 -11
  22. package/backend/dist/services/emailService.js.map +1 -1
  23. package/backend/dist/services/pluginCredentialsService.d.ts +3 -0
  24. package/backend/dist/services/pluginCredentialsService.d.ts.map +1 -1
  25. package/backend/dist/services/pluginCredentialsService.js +18 -5
  26. package/backend/dist/services/pluginCredentialsService.js.map +1 -1
  27. package/backend/dist/services/pluginService.d.ts +9 -0
  28. package/backend/dist/services/pluginService.d.ts.map +1 -1
  29. package/backend/dist/services/pluginService.js +31 -14
  30. package/backend/dist/services/pluginService.js.map +1 -1
  31. package/backend/dist/services/workRuntimeService.d.ts +5 -0
  32. package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
  33. package/backend/dist/services/workRuntimeService.js +243 -84
  34. package/backend/dist/services/workRuntimeService.js.map +1 -1
  35. package/backend/dist/utils/emailMarkdown.js +3 -3
  36. package/backend/dist/utils/emailMarkdown.js.map +1 -1
  37. package/backend/dist/utils/pluginDefinitionTrust.d.ts +7 -0
  38. package/backend/dist/utils/pluginDefinitionTrust.d.ts.map +1 -1
  39. package/backend/dist/utils/pluginDefinitionTrust.js +49 -1
  40. package/backend/dist/utils/pluginDefinitionTrust.js.map +1 -1
  41. package/backend/package.json +1 -1
  42. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  43. package/frontend/dist/artifact-runtime/mermaid.js +366 -366
  44. package/frontend/dist/assets/index-DLfU_qNT.js +75 -0
  45. package/frontend/dist/assets/index-DtS3qhdq.css +2 -0
  46. package/frontend/dist/assets/xterm-B1njb2Cr.css +1 -0
  47. package/frontend/dist/index.html +27 -26
  48. package/frontend/dist/js/ArtifactContainer-BjzltfdU.js +1 -0
  49. package/frontend/dist/js/{ArtifactDemoPage-Ddpy2O_v.js → ArtifactDemoPage-DWua6xj9.js} +1 -1
  50. package/frontend/dist/js/{ArtifactSandboxFrame-CdsAqv8H.js → ArtifactSandboxFrame-CR9ghP0A.js} +1 -1
  51. package/frontend/dist/js/ArtifactSlideOutPanel-DX2nL3AS.js +1 -0
  52. package/frontend/dist/js/AutomationModal-DZe-C2jN.js +1 -0
  53. package/frontend/dist/js/AutomationsPage-CrCcnTyk.js +1 -0
  54. package/frontend/dist/js/AvatarUpload-nPS0QHod.js +1 -0
  55. package/frontend/dist/js/Button-Dh2UJA-B.js +1 -0
  56. package/frontend/dist/js/CalendarPage-D2WiWglM.js +1 -0
  57. package/frontend/dist/js/ChannelsPage-COp2T8FQ.js +1 -0
  58. package/frontend/dist/js/ChatPage-CUfAlpdt.js +14 -0
  59. package/frontend/dist/js/ConnectModels-emc3dv4A.js +1 -0
  60. package/frontend/dist/js/EvaluationsPage-CbyeDkz_.js +2 -0
  61. package/frontend/dist/js/FirstTimeSetup-C4ffQRMN.js +1 -0
  62. package/frontend/dist/js/GalleryPage-D4Ci_3dv.js +1 -0
  63. package/frontend/dist/js/HomePage-C3IhEERN.js +1 -0
  64. package/frontend/dist/js/LanguageSwitcher-BQqDJPwm.js +1 -0
  65. package/frontend/dist/js/ModelManagerModals-DhY8Rme6.js +1 -0
  66. package/frontend/dist/js/NotesPage-j812I1BN.js +3 -0
  67. package/frontend/dist/js/PasswordStrengthMeter-BSEtQBJp.js +1 -0
  68. package/frontend/dist/js/PersonasPage--YWoThqF.js +13 -0
  69. package/frontend/dist/js/PluginUsagePage-CZiMdmjI.js +1 -0
  70. package/frontend/dist/js/{RichMessageContent-BfYbVBFz.js → RichMessageContent-BLI0hhzR.js} +2 -2
  71. package/frontend/dist/js/RichMessageContent-BXv5baJ_.js +1 -0
  72. package/frontend/dist/js/SettingsModal-C6aVzSI-.js +19 -0
  73. package/frontend/dist/js/SettingsToggle-CkLLtFbz.js +1 -0
  74. package/frontend/dist/js/ShareDialog-DQskc17d.js +1 -0
  75. package/frontend/dist/js/StrandsPage-DENhVKcz.js +1 -0
  76. package/frontend/dist/js/SystemPage-C86ypXG4.js +1 -0
  77. package/frontend/dist/js/UserManagementPanel-D1CS0KPn.js +1 -0
  78. package/frontend/dist/js/WhatsNewModal-B31A_UQY.js +1 -0
  79. package/frontend/dist/js/WorkPage-DEXBL5J7.js +7 -0
  80. package/frontend/dist/js/api-DRAKhdz7.js +1 -0
  81. package/frontend/dist/js/{api-BrHW-VGd.js → api-Dcz1G4Ib.js} +4 -2
  82. package/frontend/dist/js/{appNavigation-B6xYIgLi.js → appNavigation-C5A9BF_G.js} +1 -1
  83. package/frontend/dist/js/appStore-0_qlwS8f.js +2 -0
  84. package/frontend/dist/js/appVersion-D5lk_2zb.js +1 -0
  85. package/frontend/dist/js/ar-BZntyucf.js +2 -0
  86. package/frontend/dist/js/authStore-C4dzH1NY.js +1 -0
  87. package/frontend/dist/js/{authStore-DjAsRpNL.js → authStore-COgKeTRv.js} +3 -3
  88. package/frontend/dist/js/bn-BDCaFQu-.js +2 -0
  89. package/frontend/dist/js/chatStore-CVTbkZyb.js +3 -0
  90. package/frontend/dist/js/{client-DppLngAs.js → client-jaxZzn-I.js} +2 -2
  91. package/frontend/dist/js/{composerStyles-C83jssgZ.js → composerStyles-BEx0XAp6.js} +1 -1
  92. package/frontend/dist/js/{config-4_s8hdqO.js → config-Da1yh9sC.js} +1 -1
  93. package/frontend/dist/js/confirmStore-CKkUtP9c.js +1 -0
  94. package/frontend/dist/js/cs-BCmN--jQ.js +2 -0
  95. package/frontend/dist/js/da-B895dAyV.js +2 -0
  96. package/frontend/dist/js/de-B0ZhC0dm.js +2 -0
  97. package/frontend/dist/js/es-D7eaw4_W.js +2 -0
  98. package/frontend/dist/js/{evaluationsApi-DyuW7IJ_.js → evaluationsApi-BwaxBVpl.js} +1 -1
  99. package/frontend/dist/js/fr-DsB0gLW4.js +2 -0
  100. package/frontend/dist/js/hi-CLeU3ung.js +2 -0
  101. package/frontend/dist/js/id-Cdq6tOTi.js +2 -0
  102. package/frontend/dist/js/is-DJ1tHaAT.js +2 -0
  103. package/frontend/dist/js/it-9K1R4CeT.js +2 -0
  104. package/frontend/dist/js/ja-BYP_3M5M.js +2 -0
  105. package/frontend/dist/js/ko-CNtjlaDm.js +2 -0
  106. package/frontend/dist/js/liveAnnouncerStore-B6mS-JWC.js +1 -0
  107. package/frontend/dist/js/messageCodeStyles-D3cWF9XO.js +2 -0
  108. package/frontend/dist/js/ms-A_IVO_qt.js +2 -0
  109. package/frontend/dist/js/nl-CrKWO3ea.js +2 -0
  110. package/frontend/dist/js/pl-BrpSuyDP.js +2 -0
  111. package/frontend/dist/js/pt-BHbpB5BM.js +2 -0
  112. package/frontend/dist/js/ru-DzLsS9zY.js +2 -0
  113. package/frontend/dist/js/{strandsApi-BFbeEpAY.js → strandsApi-COxSPh_5.js} +1 -1
  114. package/frontend/dist/js/sv-VU2CjzNj.js +2 -0
  115. package/frontend/dist/js/{teamEventStream-DsAS6P4m.js → teamEventStream-RNJYm84u.js} +1 -1
  116. package/frontend/dist/js/th-DV2hNXXc.js +2 -0
  117. package/frontend/dist/js/tr-DvVZ9jxF.js +2 -0
  118. package/frontend/dist/js/ui-CI0OdG9q.js +2 -0
  119. package/frontend/dist/js/ui-vendor-6S05F84J.js +1 -0
  120. package/frontend/dist/js/uk-MFFDRo2m.js +2 -0
  121. package/frontend/dist/js/useChat-BSkqxHnH.js +13 -0
  122. package/frontend/dist/js/useDictation-D9whH12W.js +1 -0
  123. package/frontend/dist/js/vi-CfZ-U8Cw.js +2 -0
  124. package/frontend/dist/js/{work-CdbmBok5.js → work-C7MYlv5S.js} +1 -1
  125. package/frontend/dist/js/{workModels-BM2Zyiba.js → workAnnouncements-CAsI8P7c.js} +1 -1
  126. package/frontend/dist/js/workApi-BJfbaV6k.js +1 -0
  127. package/frontend/dist/js/{workApi-UPxumrEF.js → workApi-Ck8nTlJn.js} +1 -1
  128. package/frontend/dist/js/zh-CTl_raYa.js +2 -0
  129. package/package.json +3 -2
  130. package/plugins/codex-oauth.json +1 -0
  131. package/frontend/dist/assets/index-D99DS5c6.js +0 -57
  132. package/frontend/dist/assets/index-Dz1JufgZ.css +0 -1
  133. package/frontend/dist/assets/xterm-B8QFf3JU.css +0 -1
  134. package/frontend/dist/js/ArtifactContainer-Cn7X9HGm.js +0 -1
  135. package/frontend/dist/js/ArtifactSlideOutPanel-cVd9X80o.js +0 -1
  136. package/frontend/dist/js/AutomationModal-B4UaWjkk.js +0 -1
  137. package/frontend/dist/js/AutomationsPage-huCrvLUp.js +0 -1
  138. package/frontend/dist/js/AvatarUpload-CG-w6Mpt.js +0 -1
  139. package/frontend/dist/js/Button-j68Q8KVh.js +0 -1
  140. package/frontend/dist/js/CalendarPage-CZXT1w99.js +0 -1
  141. package/frontend/dist/js/ChannelsPage-DbtdHnSL.js +0 -1
  142. package/frontend/dist/js/ChatPage-BZE65kiq.js +0 -14
  143. package/frontend/dist/js/ConnectModels-DD4bLgdq.js +0 -1
  144. package/frontend/dist/js/EvaluationsPage-Dq53LaXd.js +0 -2
  145. package/frontend/dist/js/FirstTimeSetup-BoJIfuQT.js +0 -1
  146. package/frontend/dist/js/GalleryPage-DKwqeB2A.js +0 -1
  147. package/frontend/dist/js/HomePage-C8bCJfls.js +0 -1
  148. package/frontend/dist/js/LanguageSwitcher-B_YyU5JG.js +0 -1
  149. package/frontend/dist/js/ModelManagerModals-BzjZ-QwL.js +0 -1
  150. package/frontend/dist/js/NotesPage-CnaAp_w_.js +0 -3
  151. package/frontend/dist/js/PasswordStrengthMeter-DI4RDv67.js +0 -1
  152. package/frontend/dist/js/PersonasPage-CH3GUKph.js +0 -13
  153. package/frontend/dist/js/PluginUsagePage-d54K2gAj.js +0 -1
  154. package/frontend/dist/js/RichMessageContent-CDxxs3Tt.js +0 -1
  155. package/frontend/dist/js/SettingsModal-BvtJcvow.js +0 -19
  156. package/frontend/dist/js/SettingsToggle-DrJ0Bapi.js +0 -1
  157. package/frontend/dist/js/ShareDialog-DaSxkTKS.js +0 -1
  158. package/frontend/dist/js/StrandsPage-BQwz0mWq.js +0 -1
  159. package/frontend/dist/js/SystemPage-BqNZoFxR.js +0 -1
  160. package/frontend/dist/js/UserManagementPanel-C3T1ReJJ.js +0 -1
  161. package/frontend/dist/js/WhatsNewModal-CLcU2Ugk.js +0 -1
  162. package/frontend/dist/js/WorkPage-BpjGn--1.js +0 -8
  163. package/frontend/dist/js/api-K_hhqPdx.js +0 -1
  164. package/frontend/dist/js/appStore-DkRdQQeY.js +0 -2
  165. package/frontend/dist/js/appVersion-BVtSqLVj.js +0 -1
  166. package/frontend/dist/js/ar-XTZGEtBr.js +0 -2
  167. package/frontend/dist/js/authStore-DBS6Kbvh.js +0 -1
  168. package/frontend/dist/js/bn-JiK7ZWmy.js +0 -2
  169. package/frontend/dist/js/chatStore-DpVxt9VX.js +0 -3
  170. package/frontend/dist/js/cs-D8ju18CO.js +0 -2
  171. package/frontend/dist/js/da-BJWcAoUc.js +0 -2
  172. package/frontend/dist/js/de-CLJLmy69.js +0 -2
  173. package/frontend/dist/js/es-BvqHEL-3.js +0 -2
  174. package/frontend/dist/js/fr-B8ZoZomI.js +0 -2
  175. package/frontend/dist/js/goober.modern-BaHbaW3_.js +0 -1
  176. package/frontend/dist/js/hi-AzJLALo-.js +0 -2
  177. package/frontend/dist/js/id-DZYGQhvC.js +0 -2
  178. package/frontend/dist/js/is-Da_kvtzW.js +0 -2
  179. package/frontend/dist/js/it-B90zSlqn.js +0 -2
  180. package/frontend/dist/js/ja-DU_K1GOr.js +0 -2
  181. package/frontend/dist/js/ko-DicfoO-e.js +0 -2
  182. package/frontend/dist/js/messageCodeStyles-CuQPkfEK.js +0 -2
  183. package/frontend/dist/js/ms-CfH7wjUY.js +0 -2
  184. package/frontend/dist/js/nl-ELlOz-B3.js +0 -2
  185. package/frontend/dist/js/pl-33dayyUk.js +0 -2
  186. package/frontend/dist/js/pt-aIXSQPCT.js +0 -2
  187. package/frontend/dist/js/ru-BSvGtBtW.js +0 -2
  188. package/frontend/dist/js/sv-B7KOz81W.js +0 -2
  189. package/frontend/dist/js/th-DgpjGxvA.js +0 -2
  190. package/frontend/dist/js/tr-BQTbl2h-.js +0 -2
  191. package/frontend/dist/js/ui-Aq8MP7Ph.js +0 -2
  192. package/frontend/dist/js/ui-vendor-DVTj_sKN.js +0 -1
  193. package/frontend/dist/js/uk-JLymloot.js +0 -2
  194. package/frontend/dist/js/useChat-D3ZAGz70.js +0 -10
  195. package/frontend/dist/js/useDictation-B6l8QzeM.js +0 -1
  196. package/frontend/dist/js/vi-BXdLOJ8q.js +0 -2
  197. package/frontend/dist/js/workApi-D1xtiG3Q.js +0 -1
  198. package/frontend/dist/js/zh-gdUf9sXa.js +0 -2
@@ -0,0 +1,19 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/ModelManagerModals-DhY8Rme6.js","js/rolldown-runtime-hePW80VL.js","js/react-vendor-CR5VJ85Q.js","js/useTranslation-Boi0fB1B.js","js/utils-B-Bhh1pF.js","js/utils-vendor-DPJG-EG_.js","js/ui-vendor-6S05F84J.js","js/appStore-0_qlwS8f.js","js/logger-BR4forr_.js","js/Button-Dh2UJA-B.js","js/useDialogFocus-zSGHkpE4.js","js/UserManagementPanel-D1CS0KPn.js","js/useQuery-BTKpXudI.js","js/chatStore-CVTbkZyb.js","js/api-Dcz1G4Ib.js","js/config-Da1yh9sC.js","js/client-jaxZzn-I.js","js/strandsApi-COxSPh_5.js","js/workApi-Ck8nTlJn.js","js/ui-CI0OdG9q.js","js/messageCodeStyles-D3cWF9XO.js","js/confirmStore-CKkUtP9c.js","js/authStore-COgKeTRv.js","js/PasswordStrengthMeter-BSEtQBJp.js","js/SettingsToggle-CkLLtFbz.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-CR5VJ85Q.js";import{C as r,t as i}from"./useQuery-BTKpXudI.js";import{o as a,t as o}from"./logger-BR4forr_.js";import{_ as s,b as c,c as l,l as u,m as d,p as f,s as p,t as m,u as h,v as g,x as _,y as v}from"./chatStore-CVTbkZyb.js";import{t as y}from"./useTranslation-Boi0fB1B.js";import{i as b,n as x,o as S,t as C}from"./utils-B-Bhh1pF.js";import{c as w,d as T,l as E,n as D,r as O,s as k,t as A,u as j}from"./appStore-0_qlwS8f.js";import{$ as M,$n as N,$t as P,An as F,B as I,Bn as ee,Cn as te,Cr as ne,D as re,Dn as L,Dr as R,Dt as z,E as ie,En as ae,G as oe,Gn as se,Gt as B,Ht as ce,J as le,Jt as ue,K as de,Kn as fe,Kt as pe,Lt as me,Mn as he,N as ge,Nn as _e,Nt as ve,O as ye,Or as V,Q as be,Qt as xe,R as Se,Rt as Ce,Sr as we,T as Te,Tn as Ee,U as De,Ut as Oe,V as ke,Vt as Ae,Wt as je,X as Me,Xn as Ne,Y as Pe,Zn as Fe,Zt as Ie,bn as Le,cn as Re,dn as ze,dr as Be,er as Ve,fr as He,g as Ue,in as We,it as Ge,jn as Ke,jt as qe,mr as Je,n as Ye,nn as Xe,o as Ze,p as Qe,pn as $e,pr as et,pt as tt,q as nt,qt as rt,r as it,rn as at,s as ot,sn as st,st as ct,t as lt,tn as ut,tt as dt,un as ft,v as pt,vt as mt,x as ht,xt as gt,yn as _t,yt as vt,z as yt,zn as bt}from"./ui-vendor-6S05F84J.js";import{t as H}from"./Button-Dh2UJA-B.js";import{t as xt}from"./useDialogFocus-zSGHkpE4.js";import{_ as U,a as W,c as St,g as Ct,h as wt,m as Tt,n as Et,p as Dt,r as Ot,v as G}from"./ui-CI0OdG9q.js";import{t as kt}from"./confirmStore-CKkUtP9c.js";import{t as K}from"./client-jaxZzn-I.js";import{C as At,F as jt,I as Mt,M as Nt,N as Pt,S as Ft,a as It,c as Lt,d as Rt,f as zt,i as Bt,j as Vt,l as Ht,n as Ut,p as Wt,r as Gt,s as q,u as Kt,w as qt,x as Jt,y as J}from"./api-Dcz1G4Ib.js";import{a as Yt,o as Xt,s as Zt,t as Qt}from"./imageGenModels-Dx_QMLJQ.js";import{t as $t,u as en}from"./authStore-COgKeTRv.js";import{l as tn}from"./messageCodeStyles-D3cWF9XO.js";import{t as nn}from"./Logo-DnfVtjgj.js";import{t as Y}from"./LogoMark-BzObGdA9.js";import{t as rn}from"./ShareDialog-DQskc17d.js";import{a as an,i as on,n as sn,s as cn,t as ln}from"./LanguageSwitcher-BQqDJPwm.js";import{s as un}from"./ttsBatching-kFVEE3Ip.js";import{t as dn}from"./appVersion-D5lk_2zb.js";import{t as X}from"./SettingsToggle-CkLLtFbz.js";import{i as Z,r as fn,t as pn}from"./thinking-DwlkTfPX.js";var Q=e(t(),1),$=n();function mn(e){let t=e.match(/^v?(\d+)\.(\d+)\.(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function hn(e,t){for(let n=0;n<3;n++)if(e[n]!==t[n])return e[n]-t[n];return 0}function gn(e){let[t,n]=(0,Q.useState)(`checking`),[r,i]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let t=!1,r=mn(e),a=e.includes(`-dev`);return(async()=>{try{let e=await fetch(`https://api.github.com/repos/libre-webui/libre-webui/releases/latest`,{headers:{Accept:`application/vnd.github+json`}});if(!e.ok)throw Error(`HTTP ${e.status}`);let o=mn((await e.json()).tag_name??``);if(t)return;if(!r||!o){n(`error`);return}i(o.join(`.`));let s=hn(r,o);n(s<0?`behind`:s>0||a?`ahead`:`latest`)}catch{t||n(`error`)}})(),()=>{t=!0}},[e]),{status:t,latestVersion:r}}var _n=[{href:`https://github.com/libre-webui/libre-webui`,icon:Re,labelKey:`settings.about.links.github`,descriptionKey:`settings.about.links.githubDescription`},{href:`https://github.com/libre-webui/libre-webui`,icon:re,labelKey:`settings.about.links.star`,descriptionKey:`settings.about.links.starDescription`},{href:`https://git.kroonen.ai/libre-webui/libre-webui`,icon:We,labelKey:`settings.about.links.forgejo`,descriptionKey:`settings.about.links.forgejoDescription`},{href:`https://librewebui.org`,icon:L,labelKey:`settings.about.links.website`,descriptionKey:`settings.about.links.websiteDescription`},{href:`https://docs.librewebui.org`,icon:et,labelKey:`settings.about.links.documentation`,descriptionKey:`settings.about.links.documentationDescription`},{href:`https://github.com/sponsors/libre-webui`,icon:Ie,labelKey:`settings.about.links.sponsor`,descriptionKey:`settings.about.links.sponsorDescription`},{href:`https://github.com/libre-webui/libre-webui/issues`,icon:z,labelKey:`settings.about.links.reportIssue`,descriptionKey:`settings.about.links.reportIssueDescription`}],vn=[`settings.about.features.privacy`,`settings.about.features.openSource`,`settings.about.features.localInference`];function yn({status:e,latestVersion:t}){let{t:n}=y();return e===`checking`?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-gray-500 dark:text-dark-500`,children:[(0,$.jsx)(Ce,{className:`h-3.5 w-3.5 animate-spin`}),n(`settings.about.updates.checking`)]}):e===`latest`?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-success-600 dark:text-success-400`,children:[(0,$.jsx)(se,{className:`h-3.5 w-3.5`}),n(`settings.about.updates.upToDate`)]}):e===`ahead`?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(st,{className:`h-3.5 w-3.5`}),n(`settings.about.updates.ahead`,{version:t??``})]}):e===`behind`?(0,$.jsxs)(`a`,{href:`https://github.com/libre-webui/libre-webui/releases/latest`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 font-medium text-primary-600 transition-colors hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300`,children:[(0,$.jsx)(fe,{className:`h-3.5 w-3.5`}),n(`settings.about.updates.updateAvailable`,{version:t??``}),(0,$.jsx)(L,{className:`h-3 w-3`})]}):(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:n(`settings.about.updates.checkFailed`)})}function bn({appVersion:e}){let{t}=y(),{status:n,latestVersion:r}=gn(e);return(0,$.jsx)(`div`,{className:`space-y-6`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-4 flex items-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,$.jsx)(Y,{size:`md`,label:null}),(0,$.jsx)(nn,{})]}),(0,$.jsx)(`div`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-6`,children:(0,$.jsx)(`span`,{children:t(`settings.about.title`)})}),(0,$.jsx)(`div`,{className:`bg-gray-50 dark:bg-dark-100 rounded-lg p-6 border border-gray-200 dark:border-dark-300`,children:(0,$.jsx)(`div`,{className:`space-y-4 text-sm text-gray-700 dark:text-gray-300`,children:vn.map(e=>(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 bg-primary-500 rounded-full mt-2 shrink-0`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-semibold text-gray-900 dark:text-gray-100 mb-1`,children:t(`${e}.title`)}),(0,$.jsx)(`p`,{children:t(`${e}.description`)})]})]},e))})}),(0,$.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t(`settings.about.links.title`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:_n.map(e=>{let n=e.icon;return(0,$.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-3 p-3 bg-white dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg hover:bg-gray-50 dark:hover:bg-dark-200 hover:border-gray-300 dark:hover:border-dark-400 transition-all duration-200 group`,children:[(0,$.jsx)(n,{className:`h-5 w-5 text-gray-600 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-gray-200`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:t(e.labelKey)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(e.descriptionKey)})]}),(0,$.jsx)(L,{className:`h-4 w-4 text-gray-400 ms-auto opacity-0 group-hover:opacity-100 transition-opacity`})]},e.labelKey)})})]}),(0,$.jsx)(`div`,{className:`mt-6 p-4 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg`,children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-4 gap-y-2 text-xs`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1.5`,children:[e.includes(`-dev`)?(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:t(`settings.about.version`,{version:e})}):(0,$.jsx)(`a`,{href:`https://github.com/libre-webui/libre-webui/releases/tag/v${e}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-gray-500 hover:text-primary-600 dark:text-gray-400 dark:hover:text-primary-400 transition-colors`,children:t(`settings.about.version`,{version:e})}),(0,$.jsx)(yn,{status:n,latestVersion:r}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>window.dispatchEvent(new Event(`libre:open-whats-new`)),className:`inline-flex items-center gap-1.5 text-gray-500 transition-colors hover:text-gray-900 dark:text-gray-400 dark:hover:text-dark-900`,"data-testid":`about-view-changelog`,children:[(0,$.jsx)(nt,{className:`h-3.5 w-3.5`}),t(`settings.about.updates.viewChangelog`)]})]}),(0,$.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[t(`settings.about.openSourceBy`,{company:``}),(0,$.jsx)(`a`,{href:`https://kroonen.ai`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 transition-colors`,children:`Kroonen AI`})]})]})})]})})}var xn=o(`components:background-upload`),Sn=e=>{let t=$t(e=>e.user?.id);return(0,$.jsx)(Cn,{...e},t??`solo`)},Cn=({className:e=``})=>{let{t,i18n:n}=y(),{preferences:r,backgroundImage:i,updateBackgroundSettings:a,uploadBackgroundImage:o,removeBackgroundImage:s}=A(),c=(0,Q.useId)(),l=(0,Q.useRef)(null),u=(0,Q.useRef)(0),d=(0,Q.useRef)(null),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(`idle`);(0,Q.useEffect)(()=>()=>{u.current+=1,d.current=null},[]);let v=D({...r.backgroundSettings,imageUrl:i||r.backgroundSettings?.imageUrl||``}),b=!!v.imageUrl,x=async e=>{let t=++u.current;d.current=e,_(`saving`);try{await e(),t===u.current&&_(`saved`)}catch(e){if(t!==u.current)return;if(e instanceof DOMException&&e.name===`AbortError`){_(`idle`);return}xn.error(`Failed to save background settings:`,e),_(`error`)}},S=e=>void x(()=>a(e)),w=async e=>{if(!e.type.startsWith(`image/`)){V.error(t(`personaBackground.invalidFile`));return}if(e.size>10485760){V.error(t(`settings.appearance.background.fileTooLarge`));return}p(!0);try{await x(()=>o(e))}finally{p(!1)}},T=c+`-enabled`,E=c+`-blur`,O=c+`-intensity`,k=new Intl.NumberFormat(n.language,{style:`percent`,maximumFractionDigits:0}).format(v.opacity);return(0,$.jsxs)(`div`,{className:C(`space-y-4`,e),"data-testid":`background-upload`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-ink`,children:t(`settings.appearance.background.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-ink-muted`,children:t(`settings.appearance.background.enableDescription`)})]}),(0,$.jsxs)(`label`,{htmlFor:T,className:`touch-target relative inline-flex shrink-0 cursor-pointer items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:t(`settings.appearance.background.enable`)}),(0,$.jsx)(`input`,{id:T,type:`checkbox`,className:`peer sr-only`,checked:v.enabled,onChange:e=>S({enabled:e.target.checked}),"data-testid":`background-enabled`}),(0,$.jsx)(`span`,{className:`relative h-6 w-11 rounded-full bg-surface-raised ring-1 ring-inset ring-line transition-colors peer-checked:bg-primary-600 peer-focus-visible:ring-2 peer-focus-visible:ring-primary-500 peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-surface motion-reduce:transition-none`,children:(0,$.jsx)(`span`,{className:C(`absolute inset-s-1 top-1 h-4 w-4 rounded-full bg-white shadow-subtle transition-transform motion-reduce:transition-none`,v.enabled&&`translate-x-5 rtl:-translate-x-5`)})})]})]}),(0,$.jsxs)(`div`,{className:C(`overflow-hidden rounded-xl border border-line bg-surface-subtle`,m&&`border-primary-500 ring-2 ring-primary-500/20`),onDragOver:e=>{e.preventDefault(),h(!0)},onDragLeave:e=>{(!(e.relatedTarget instanceof Node)||!e.currentTarget.contains(e.relatedTarget))&&h(!1)},onDrop:e=>{e.preventDefault(),h(!1);let t=e.dataTransfer.files?.[0];t&&!f&&w(t)},children:[b?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{role:`img`,"aria-label":t(`settings.appearance.background.preview`),className:`relative aspect-video overflow-hidden bg-canvas`,"data-testid":`background-preview`,children:(0,$.jsx)(cn,{settings:{...v,enabled:!0},testId:`background-preview-layer`})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-t border-line px-3 py-2.5`,children:[(0,$.jsx)(`span`,{className:`text-xs text-ink-muted`,children:t(`settings.appearance.background.preview`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>l.current?.click(),disabled:f,"data-testid":`background-change`,children:[(0,$.jsx)(Qe,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),t(`settings.appearance.background.change`)]}),(0,$.jsxs)(H,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void x(async()=>{await s()}),disabled:f,className:`text-error-600 hover:text-error-700 dark:text-error-400`,"data-testid":`background-remove`,children:[(0,$.jsx)(Ye,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),t(`common.remove`)]})]})]})]}):(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 px-4 py-6 text-center`,children:[(0,$.jsx)(ue,{className:`h-7 w-7 text-ink-subtle`,"aria-hidden":`true`}),(0,$.jsx)(`p`,{className:`text-xs leading-5 text-ink-muted`,children:t(`settings.appearance.background.dragDrop`)}),(0,$.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,disabled:f,onClick:()=>l.current?.click(),"data-testid":`background-change`,children:[(0,$.jsx)(Qe,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),t(f?`common.loading`:`settings.appearance.background.chooseImage`)]})]}),(0,$.jsx)(`input`,{ref:l,type:`file`,accept:`image/*`,disabled:f,className:`hidden`,"data-testid":`background-file-input`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&w(t)}})]}),b&&(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(Dt,{label:t(`settings.appearance.background.effect`),value:v.effect,onChange:e=>S({effect:e.target.value}),options:[{value:`dither`,label:t(`settings.appearance.background.dither`)},{value:`original`,label:t(`settings.appearance.background.original`)},{value:`blur`,label:t(`settings.appearance.background.blurred`)}],"data-testid":`background-effect`}),v.effect===`blur`&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{htmlFor:E,className:`mb-2 flex items-center justify-between gap-3 text-sm text-ink`,children:[(0,$.jsx)(`span`,{children:t(`settings.appearance.background.blur`)}),(0,$.jsxs)(`span`,{dir:`ltr`,className:`text-xs tabular-nums text-ink-muted`,children:[v.blurAmount,`px`]})]}),(0,$.jsx)(`input`,{id:E,type:`range`,min:0,max:30,step:1,value:v.blurAmount,onChange:e=>S({blurAmount:Number(e.target.value)}),className:`h-6 w-full cursor-pointer accent-primary-600`,"data-testid":`background-blur`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{htmlFor:O,className:`mb-2 flex items-center justify-between gap-3 text-sm text-ink`,children:[(0,$.jsx)(`span`,{children:t(`settings.appearance.background.intensity`)}),(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-ink-muted`,children:k})]}),(0,$.jsx)(`input`,{id:O,type:`range`,min:0,max:1,step:.05,value:v.opacity,"aria-valuetext":k,onChange:e=>S({opacity:Number(e.target.value)}),className:`h-6 w-full cursor-pointer accent-primary-600`,"data-testid":`background-intensity`})]}),(0,$.jsx)(`p`,{className:`text-xs leading-5 text-ink-muted`,children:t(`settings.appearance.background.originalPreserved`)})]}),(0,$.jsxs)(`div`,{role:g===`idle`?void 0:g===`error`?`alert`:`status`,className:C(`flex min-h-5 flex-wrap items-center gap-2 text-xs`,g===`error`?`text-error-600 dark:text-error-400`:`text-ink-muted`),"data-testid":`background-save-status`,children:[g===`saving`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ce,{className:`h-3.5 w-3.5 animate-spin motion-reduce:animate-none`,"aria-hidden":`true`}),t(`common.saving`)]}),g===`saved`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ve,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),t(`settings.appearance.background.saved`)]}),g===`error`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:t(`settings.appearance.background.saveFailed`)}),(0,$.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{d.current&&x(d.current)},children:t(`common.retry`)})]})]})]})};function wn({title:e,description:t,children:n}){return(0,$.jsxs)(`div`,{className:`flex items-center gap-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h4`,{className:`text-sm leading-[22px] text-ink`,children:e}),t&&(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-ink-subtle`,children:t})]}),n&&(0,$.jsx)(`div`,{className:`shrink-0`,children:n})]})}function Tn({checked:e,onChange:t,label:n,testId:r}){return(0,$.jsxs)(`label`,{className:`relative inline-flex shrink-0 cursor-pointer items-center`,children:[(0,$.jsx)(`input`,{type:`checkbox`,"data-testid":r,"aria-label":n,className:`peer sr-only`,checked:e,onChange:e=>t(e.target.checked)}),(0,$.jsx)(`div`,{className:`peer h-6 w-11 rounded-full bg-line-strong transition-colors peer-focus:outline-hidden peer-focus-visible:ring-2 peer-focus-visible:ring-primary-500/40 peer-checked:bg-primary-500 after:absolute after:inset-s-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:bg-white after:shadow-xs after:transition-all after:content-[''] peer-checked:after:translate-x-full peer-checked:rtl:after:-translate-x-full`})]})}function En({theme:e,preferences:t,onThemeChange:n,onAccentChange:r,onCustomAccentChange:i,onAdaptToAccentChange:a,onShowUsernameChange:o,onShowFollowUpsChange:s,onAutoOpenArtifactsChange:c,onHapticFeedbackChange:l}){let{t:u}=y(),d=e.accent||`blue`,f=e.customAccent||`#4176e6`,p=k(e),m=j(e=>e.location),h=j(e=>e.weatherEnabled),g=j(e=>e.weather),_=j(e=>e.weatherStatus),v=j(e=>e.setLocation),b=j(e=>e.requestBrowserLocation),x=j(e=>e.setWeatherEnabled),[S,w]=(0,Q.useState)(!1),[D,A]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(``),[P,F]=(0,Q.useState)(``),I=(0,Q.useId)(),ee=async()=>{w(!0),A(!1);let e=await b();w(!1),e||A(!0)},te=()=>{if(!M.trim()||!P.trim())return;let e=Number(M),t=Number(P);T({latitude:e,longitude:t})&&(v({latitude:e,longitude:t}),A(!1),N(``),F(``))},ne=e.mode===`celestial`;(0,Q.useEffect)(()=>()=>E(null),[]);let re=(t,r,i)=>{let a=e.mode===t;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(t),"aria-pressed":a,className:C(`flex flex-1 basis-[180px] flex-col items-center justify-center gap-1 rounded-2xl border px-8 py-5 text-sm leading-[22px] text-ink transition-colors focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,a?`border-line-strong bg-surface-subtle`:`border-line hover:bg-interactive-hover`),children:[(0,$.jsx)(r,{className:`h-4 w-4`}),i]})};return(0,$.jsxs)(`div`,{className:`divide-y divide-line`,children:[(0,$.jsx)(ln,{}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 py-4`,children:[(0,$.jsx)(`h4`,{className:`text-sm leading-[22px] text-ink`,children:u(`settings.appearance.title`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[re(`light`,ie,u(`settings.appearance.theme.light`)),re(`dark`,mt,u(`settings.appearance.theme.dark`)),re(`amoled`,vt,u(`settings.appearance.theme.amoled`)),re(`celestial`,Te,u(`settings.appearance.theme.celestial`))]})]}),ne&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 py-4`,"data-testid":`celestial-preview`,children:[(0,$.jsx)(an,{}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2 rounded-xl border border-line p-3`,"data-testid":`celestial-location`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-start justify-between gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-48`,children:[(0,$.jsx)(`h5`,{className:`text-sm leading-[22px] text-ink`,children:u(`settings.appearance.celestial.location`)}),(0,$.jsx)(`p`,{className:`text-xs leading-5 text-ink-muted`,children:u(`settings.appearance.celestial.locationHint`)})]}),(0,$.jsx)(`output`,{dir:m?`ltr`:`auto`,"aria-live":`polite`,className:`max-w-full wrap-break-word rounded-lg bg-surface-subtle px-2 py-1 font-mono text-xs leading-5 text-ink-muted`,"data-testid":`celestial-location-value`,children:m?`${m.latitude.toFixed(2)}°, ${m.longitude.toFixed(2)}°`:u(`settings.appearance.celestial.approximateDay`)})]}),(0,$.jsxs)(`form`,{className:`mt-1 space-y-3`,onSubmit:e=>{e.preventDefault(),te()},children:[(0,$.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 space-y-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`${I}-latitude`,className:`block text-xs font-medium text-ink-muted`,children:u(`settings.appearance.celestial.latitude`)}),(0,$.jsx)(`input`,{id:`${I}-latitude`,type:`number`,step:`any`,required:!0,min:-90,max:90,dir:`ltr`,value:M,onChange:e=>N(e.target.value),className:`w-full min-w-0 rounded-lg border border-line bg-surface-subtle px-3 py-2 text-[16px] text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40 md:text-sm`,"data-testid":`celestial-latitude`})]}),(0,$.jsxs)(`div`,{className:`min-w-0 space-y-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`${I}-longitude`,className:`block text-xs font-medium text-ink-muted`,children:u(`settings.appearance.celestial.longitude`)}),(0,$.jsx)(`input`,{id:`${I}-longitude`,type:`number`,step:`any`,required:!0,min:-180,max:180,dir:`ltr`,value:P,onChange:e=>F(e.target.value),className:`w-full min-w-0 rounded-lg border border-line bg-surface-subtle px-3 py-2 text-[16px] text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40 md:text-sm`,"data-testid":`celestial-longitude`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`button`,{type:`submit`,className:`rounded-lg border border-line bg-surface-raised px-3 py-2 text-xs font-medium text-ink transition-colors hover:bg-interactive-hover focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,"data-testid":`celestial-apply-location`,children:u(`settings.appearance.celestial.apply`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void ee(),disabled:S,className:`rounded-lg border border-line px-3 py-2 text-xs text-ink transition-colors hover:bg-interactive-hover focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40 disabled:opacity-60`,"data-testid":`celestial-use-location`,children:u(`settings.appearance.celestial.useMyLocation`)}),m&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>v(null),className:`rounded-lg px-3 py-2 text-xs text-ink-muted transition-colors hover:bg-interactive-hover focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,"data-testid":`celestial-clear-location`,children:u(`settings.appearance.celestial.clear`)})]})]}),D&&(0,$.jsx)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:u(`settings.appearance.celestial.locationDenied`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h5`,{className:`text-sm leading-[22px] text-ink`,children:u(`settings.appearance.celestial.weather`)}),(0,$.jsx)(`p`,{className:`text-xs leading-5 text-ink-muted`,children:u(`settings.appearance.celestial.weatherHint`)}),h&&m&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-ink-subtle`,"data-testid":`celestial-weather-status`,children:_===`loading`&&!g?u(`settings.appearance.celestial.weatherLoading`):_===`error`&&!g?u(`settings.appearance.celestial.weatherUnavailable`):g?`${u(`settings.appearance.celestial.kinds.${g.kind}`)} · ${u(`settings.appearance.celestial.wind`,{speed:Math.round(g.windSpeed)})}`:``})]}),(0,$.jsx)(`div`,{"data-testid":`celestial-weather-toggle`,children:(0,$.jsx)(X,{checked:h,onChange:x,disabled:!m,"aria-label":u(`settings.appearance.celestial.weather`)})})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`h4`,{className:`text-sm leading-[22px] text-ink`,children:u(`settings.appearance.accent.title`,{defaultValue:`Accent color`})}),(0,$.jsx)(`div`,{className:`h-6 w-6 shrink-0 rounded-full border border-line`,style:{backgroundColor:p},"aria-hidden":`true`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[O.map(e=>{let t=d===e.id;return(0,$.jsx)(`button`,{type:`button`,onClick:()=>r(e.id),className:C(`relative h-9 w-9 rounded-full transition-all duration-200 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,t?`scale-105 ring-2 ring-ink ring-offset-2 ring-offset-surface`:`hover:scale-110`),style:{backgroundColor:e.color},"aria-label":u(`settings.appearance.accent.useColor`,{defaultValue:`Use ${e.label} accent`,color:e.label}),title:e.label,children:t&&(0,$.jsx)(Ve,{className:`absolute inset-0 m-auto h-4 w-4 drop-shadow-sm`,style:{color:e.foreground}})},e.id)}),(0,$.jsxs)(`label`,{className:C(`relative h-9 w-9 cursor-pointer overflow-hidden rounded-full transition-all duration-200 focus-within:outline-hidden focus-within:ring-2 focus-within:ring-primary-500/40`,d===`custom`?`scale-105 ring-2 ring-ink ring-offset-2 ring-offset-surface`:`hover:scale-110`),title:u(`settings.appearance.accent.custom`,{defaultValue:`Custom color`}),"aria-label":u(`settings.appearance.accent.custom`,{defaultValue:`Custom color`}),children:[(0,$.jsx)(`input`,{type:`color`,value:f,onInput:e=>i(e.currentTarget.value),onChange:e=>i(e.target.value),className:`absolute inset-0 h-full w-full cursor-pointer opacity-0`}),(0,$.jsx)(`span`,{className:`absolute inset-0`,style:{backgroundColor:f},"aria-hidden":`true`}),(0,$.jsx)(tt,{className:`absolute inset-0 m-auto h-4 w-4 text-white drop-shadow-sm`})]})]}),!ne&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{className:`text-sm leading-[22px] text-ink`,children:u(`settings.appearance.accent.behaviorTitle`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-ink-subtle`,children:u(`settings.appearance.accent.behaviorDescription`)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-stretch gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":!e.adaptToAccent,onClick:()=>a(!1),className:C(`flex-1 basis-[180px] rounded-2xl border p-4 text-start transition-colors focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,e.adaptToAccent?`border-line hover:bg-interactive-hover`:`border-line-strong bg-surface-subtle`),children:[(0,$.jsx)(`span`,{className:`block text-sm leading-[22px] text-ink`,children:u(`settings.appearance.accent.defaultStyle`)}),(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-snug text-ink-subtle`,children:u(`settings.appearance.accent.defaultStyleDescription`)})]}),(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":e.adaptToAccent===!0,onClick:()=>a(!0),className:C(`flex-1 basis-[180px] rounded-2xl border p-4 text-start transition-colors focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,e.adaptToAccent?`border-line-strong bg-surface-subtle`:`border-line hover:bg-interactive-hover`),children:[(0,$.jsx)(`span`,{className:`block text-sm leading-[22px] text-ink`,children:u(`settings.appearance.accent.adaptedStyle`)}),(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-snug text-ink-subtle`,children:u(`settings.appearance.accent.adaptedStyleDescription`)})]})]})]})]}),(0,$.jsx)(wn,{title:u(`settings.appearance.chatInterface.showUsername`),description:u(`settings.appearance.chatInterface.showUsernameDescription`),children:(0,$.jsx)(Tn,{checked:t.showUsername,onChange:o,label:u(`settings.appearance.chatInterface.showUsername`)})}),(0,$.jsx)(wn,{title:u(`settings.appearance.chatInterface.followUpSuggestions`),description:u(`settings.appearance.chatInterface.followUpSuggestionsDescription`),children:(0,$.jsx)(Tn,{checked:t.showFollowUpSuggestions!==!1,onChange:s,label:u(`settings.appearance.chatInterface.followUpSuggestions`)})}),(0,$.jsx)(wn,{title:u(`settings.appearance.chatInterface.autoOpenArtifacts`),description:u(`settings.appearance.chatInterface.autoOpenArtifactsDescription`),children:(0,$.jsx)(Tn,{checked:t.autoOpenArtifactPanel!==!1,onChange:c,label:u(`settings.appearance.chatInterface.autoOpenArtifacts`),testId:`auto-open-artifacts-toggle`})}),(0,$.jsx)(wn,{title:u(`settings.appearance.chatInterface.hapticFeedback`,{defaultValue:`Haptic feedback (Android)`}),description:u(`settings.appearance.chatInterface.hapticFeedbackDescription`,{defaultValue:`Use subtle vibration for important mobile actions`}),children:(0,$.jsx)(Tn,{checked:t.hapticFeedbackEnabled===!0,onChange:l,label:u(`settings.appearance.chatInterface.hapticFeedback`,{defaultValue:`Haptic feedback (Android)`}),testId:`haptic-feedback-toggle`})}),(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(Sn,{})})]})}var Dn=({title:e,description:t,actions:n,className:r})=>(0,$.jsxs)(`header`,{className:C(`mb-5 flex flex-wrap items-end justify-between gap-3 border-b border-gray-200/70 pb-4 dark:border-white/8`,r),children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-[1_1_18rem] wrap-anywhere`,children:[(0,$.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-dark-800`,children:e}),t&&(0,$.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm leading-6 text-gray-600 dark:text-dark-600`,children:t})]}),n&&(0,$.jsx)(`div`,{className:`flex max-w-full flex-wrap items-center gap-2 [&>button]:min-h-11 [&>button]:max-w-full`,children:n})]});function On(){let{t:e,i18n:t}=y(),{sessions:n,setSessionArchived:r,deleteSession:i}=m(),a=n.filter(e=>e.archived);return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Dn,{title:e(`settings.data.archivedChats.title`)}),a.length===0?(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`settings.data.archivedChats.empty`)}):(0,$.jsx)(`div`,{className:`divide-y divide-gray-100 rounded-xl border border-gray-200 dark:divide-dark-300 dark:border-dark-300`,children:a.map(n=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,children:n.title}),(0,$.jsx)(`p`,{className:`text-[11px] tabular-nums text-gray-400 dark:text-dark-500`,children:b(n.updatedAt,t.language)})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,$.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>r(n.id,!1),className:`h-8 gap-1.5 px-2 text-xs`,title:e(`settings.data.archivedChats.unarchive`),children:[(0,$.jsx)(we,{className:`h-3.5 w-3.5`}),e(`settings.data.archivedChats.unarchive`)]}),(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>{window.confirm(e(`chat.session.deleteConfirm`))&&i(n.id)},className:`h-8 w-8 p-0 text-error-600 hover:bg-error-500/10 hover:text-error-700 dark:text-error-400 dark:hover:text-error-300`,title:e(`chat.session.deleteChat`),"aria-label":e(`chat.session.deleteChat`),children:(0,$.jsx)(pt,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function kn({sessionCount:e,loading:t,importing:n,preflighting:r,preflight:i,showImportOptions:a,mergeStrategy:o,importResult:s,importFileInputRef:c,onExportData:l,onImportFileSelect:u,onClearAllHistory:d,onMergeStrategyChange:f,onConfirmImport:p,onCancelImport:m,onDismissImportResult:h}){let{t:g}=y();return(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Dn,{title:g(`settings.data.title`)}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:g(`settings.data.export`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3 flex-1`,children:g(`settings.data.exportDescription`)}),(0,$.jsx)(`p`,{className:`mb-3 text-[11px] text-amber-700 dark:text-amber-300`,children:g(`settings.data.archiveScopeV3`,{defaultValue:`Includes preferences, chats, folders, Notes, knowledge collections, and extracted document text. Excludes accounts and secrets, biometric cloned voices, generated media, personas and memory, and Work data or volumes.`})}),(0,$.jsx)(H,{onClick:l,variant:`outline`,size:`sm`,className:`w-full`,children:g(`settings.data.exportAll`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:g(`settings.data.import`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3 flex-1`,children:g(`settings.data.importDescription`)}),(0,$.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,onChange:u,className:`hidden`}),(0,$.jsx)(H,{onClick:()=>c.current?.click(),variant:`outline`,size:`sm`,className:`w-full`,disabled:n,children:g(n?`settings.data.importing`:`settings.data.importData`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:g(`settings.data.clearSessions`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3 flex-1`,children:g(`settings.data.clearSessionsDescription`)}),(0,$.jsx)(H,{onClick:d,variant:`danger`,size:`sm`,className:`w-full`,disabled:e===0||t,children:t?g(`settings.data.clearing`):g(`settings.data.clearAll`,{count:e})})]})]}),a&&(0,$.jsxs)(`div`,{className:`mt-4 p-4 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg`,children:[(0,$.jsx)(`h5`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-3`,children:g(`settings.data.importOptions`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:g(`settings.data.importOptionsDescription`)}),(0,$.jsxs)(`div`,{className:`space-y-2 mb-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`mergeStrategy`,value:`skip`,checked:o===`skip`,onChange:e=>f(e.target.value),className:`me-2`}),(0,$.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:g(`settings.data.skipDuplicates`)})]}),(0,$.jsxs)(`label`,{className:`flex items-center`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`mergeStrategy`,value:`overwrite`,checked:o===`overwrite`,onChange:e=>f(e.target.value),className:`me-2`}),(0,$.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:g(`settings.data.overwrite`)})]})]}),r&&(0,$.jsx)(`p`,{className:`mb-4 text-xs text-gray-600 dark:text-gray-300`,children:g(`settings.data.validatingArchive`,{defaultValue:`Validating archive and calculating changes…`})}),i&&!r&&(0,$.jsxs)(`div`,{className:`mb-4 space-y-2 rounded-md border border-gray-200 bg-white p-3 text-xs text-gray-700 dark:border-dark-300 dark:bg-dark-200 dark:text-gray-300`,children:[(0,$.jsx)(`p`,{className:`font-medium text-gray-900 dark:text-gray-100`,children:g(`settings.data.preflightReport`,{defaultValue:`Import preview`})}),(0,$.jsx)(`p`,{children:g(`settings.data.preflightIncoming`,{defaultValue:`{{folders}} folders · {{sessions}} chats · {{messages}} messages · {{notes}} Notes · {{collections}} collections · {{documents}} documents · {{chunks}} chunks`,folders:i.incoming.sessionFolders,sessions:i.incoming.sessions,messages:i.incoming.messages,notes:i.incoming.notes,collections:i.incoming.knowledgeCollections,documents:i.incoming.documents,chunks:i.incoming.documentChunks})}),(0,$.jsx)(`div`,{className:`space-y-1`,children:[[g(`settings.data.sessionFolders`,{defaultValue:`Session folders`}),i.result.sessionFolders],[g(`settings.data.sessions`),i.result.sessions],[g(`settings.data.notes`,{defaultValue:`Notes`}),i.result.notes],[g(`settings.data.knowledgeCollections`,{defaultValue:`Knowledge collections`}),i.result.knowledgeCollections],[g(`settings.data.documents`),i.result.documents]].map(([e,t])=>(0,$.jsxs)(`p`,{children:[e,`: `,t.imported,` `,g(`settings.data.toCreate`,{defaultValue:`to create`}),`, `,t.overwritten,` `,g(`settings.data.toOverwrite`,{defaultValue:`to overwrite`}),`, `,t.skipped,` `,g(`settings.data.toSkip`,{defaultValue:`to skip`})]},e))}),i.result.remappedIds>0&&(0,$.jsx)(`p`,{className:`text-amber-700 dark:text-amber-300`,children:g(`settings.data.preflightRemappedIds`,{defaultValue:`{{count}} IDs will be remapped to protect another account's data.`,count:i.result.remappedIds})}),i.warnings.map((e,t)=>(0,$.jsxs)(`p`,{className:`text-amber-700 dark:text-amber-300`,children:[`• `,e]},`preflight-warning-${t}`))]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(H,{onClick:p,size:`sm`,disabled:n||r||!i||i.strategy!==o,children:g(n?`settings.data.importing`:`settings.data.import`)}),(0,$.jsx)(H,{onClick:m,variant:`outline`,size:`sm`,children:g(`common.cancel`)})]})]}),s&&(0,$.jsxs)(`div`,{className:`mt-4 p-4 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg`,children:[(0,$.jsx)(`h5`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:g(`settings.data.importResults`)}),(0,$.jsxs)(`div`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1`,children:[(0,$.jsxs)(`div`,{children:[g(`settings.data.preferences`),`:`,` `,s.preferences.imported?g(`settings.data.imported`):g(`settings.data.failed`)]}),(0,$.jsxs)(`div`,{children:[g(`settings.data.sessions`),`:`,` `,s.sessions.imported,` `,g(`settings.data.importedLabel`),`,`,` `,s.sessions.overwritten,` `,g(`settings.data.overwrittenLabel`,{defaultValue:`overwritten`}),`, `,s.sessions.skipped,` `,g(`settings.data.skipped`)]}),(0,$.jsxs)(`div`,{children:[g(`settings.data.documents`),`:`,` `,s.documents.imported,` `,g(`settings.data.importedLabel`),`,`,` `,s.documents.overwritten,` `,g(`settings.data.overwrittenLabel`,{defaultValue:`overwritten`}),`, `,s.documents.skipped,` `,g(`settings.data.skipped`)]}),(0,$.jsxs)(`div`,{children:[g(`settings.data.notes`,{defaultValue:`Notes`}),`:`,` `,s.notes.imported,` `,g(`settings.data.importedLabel`),`,`,` `,s.notes.overwritten,` `,g(`settings.data.overwrittenLabel`,{defaultValue:`overwritten`}),`, `,s.notes.skipped,` `,g(`settings.data.skipped`)]}),(0,$.jsxs)(`div`,{children:[g(`settings.data.sessionFolders`,{defaultValue:`Session folders`}),`: `,s.sessionFolders.imported,` `,g(`settings.data.importedLabel`),`,`,` `,s.sessionFolders.overwritten,` `,g(`settings.data.overwrittenLabel`,{defaultValue:`overwritten`}),`, `,s.sessionFolders.skipped,` `,g(`settings.data.skipped`)]}),(0,$.jsxs)(`div`,{children:[g(`settings.data.knowledgeCollections`,{defaultValue:`Knowledge collections`}),`: `,s.knowledgeCollections.imported,` `,g(`settings.data.importedLabel`),`,`,` `,s.knowledgeCollections.overwritten,` `,g(`settings.data.overwrittenLabel`,{defaultValue:`overwritten`}),`, `,s.knowledgeCollections.skipped,` `,g(`settings.data.skipped`)]}),s.warnings.length>0&&(0,$.jsxs)(`div`,{className:`mt-2`,children:[(0,$.jsxs)(`p`,{className:`font-medium`,children:[g(`settings.data.warnings`,{defaultValue:`Warnings`}),`:`]}),s.warnings.map((e,t)=>(0,$.jsxs)(`p`,{className:`text-amber-700 dark:text-amber-300`,children:[`• `,e]},`warning-${t}`))]})]}),(0,$.jsx)(H,{onClick:h,variant:`outline`,size:`sm`,className:`mt-2`,children:g(`common.close`)})]})]})]}),(0,$.jsx)(On,{})]})}function An({settings:e,effectiveSettings:t,modelOptions:n,status:r,regenerating:i,onSettingChange:a,onReset:o,onRegenerate:s,onSave:c}){let{t:l}=y(),u=(0,Q.useId)(),d=(0,Q.useId)();return(0,$.jsx)(`div`,{className:`space-y-6`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Dn,{title:l(`settings.documents.title`)}),(0,$.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-50 p-4 rounded-lg border border-gray-200 dark:border-dark-300 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{id:u,className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:l(`settings.documents.embeddings.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:l(`settings.documents.embeddings.enable`)})]}),(0,$.jsx)(X,{checked:e.enabled,onChange:e=>a(`enabled`,e),"aria-labelledby":u})]}),e.enabled&&(0,$.jsxs)(`div`,{className:`space-y-4 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:d,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:l(`settings.documents.embeddings.model`)}),(0,$.jsx)(Dt,{id:d,value:t.model,onChange:e=>a(`model`,e.target.value),options:n}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:l(`settings.documents.embeddings.modelDescription`)})]}),(0,$.jsx)(Mn,{label:l(`settings.documents.embeddings.chunkSize`),value:e.chunkSize,min:500,max:2e3,step:100,description:l(`settings.documents.embeddings.chunkSizeDescription`),onChange:e=>a(`chunkSize`,e)}),(0,$.jsx)(Mn,{label:l(`settings.documents.embeddings.chunkOverlap`),value:e.chunkOverlap,min:50,max:500,step:50,description:l(`settings.documents.embeddings.chunkOverlapDescription`),onChange:e=>a(`chunkOverlap`,e)}),(0,$.jsx)(Mn,{label:l(`settings.documents.embeddings.similarityThreshold`),value:e.similarityThreshold,min:.3,max:.9,step:.05,description:l(`settings.documents.embeddings.similarityDescription`),format:e=>e.toFixed(2),onChange:e=>a(`similarityThreshold`,e)})]})]}),r&&(0,$.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-100 p-4 rounded-lg border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:l(`settings.documents.embeddings.status`)}),(0,$.jsxs)(`div`,{className:`text-sm text-gray-700 dark:text-gray-300 space-y-1`,children:[(0,$.jsxs)(`div`,{children:[l(`settings.documents.embeddings.statusLabel`),`:`,` `,(0,$.jsx)(`span`,{className:r.available?`font-medium text-green-600 dark:text-green-400`:`font-medium text-red-600 dark:text-red-400`,children:r.available?l(`settings.documents.embeddings.available`):l(`settings.documents.embeddings.unavailable`)})]}),(0,$.jsxs)(`div`,{children:[l(`settings.documents.embeddings.model`),`:`,` `,(0,$.jsx)(`span`,{className:`font-medium`,children:r.model})]}),(0,$.jsxs)(`div`,{children:[l(`settings.documents.embeddings.chunksWithEmbeddings`),`:`,` `,(0,$.jsxs)(`span`,{className:`font-medium`,children:[r.chunksWithEmbeddings,` / `,r.totalChunks]})]}),r.totalChunks>0&&(0,$.jsxs)(`div`,{children:[l(`settings.documents.embeddings.coverage`),`:`,` `,(0,$.jsxs)(`span`,{className:`font-medium`,children:[Math.round(r.chunksWithEmbeddings/r.totalChunks*100),`%`]})]})]})]}),(0,$.jsxs)(`div`,{className:`flex justify-between items-center pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(H,{onClick:o,variant:`outline`,className:`flex items-center gap-2`,children:[(0,$.jsx)(Pe,{size:16}),l(`settings.generation.resetDefaults`)]}),e.enabled&&r&&r.totalChunks>0&&(0,$.jsxs)(H,{onClick:s,disabled:i,variant:`outline`,className:`flex items-center gap-2 text-orange-600 dark:text-orange-400 border-orange-200 dark:border-orange-600 hover:bg-orange-50 dark:hover:bg-orange-900/20`,children:[(0,$.jsx)(Ke,{size:16}),l(i?`settings.documents.embeddings.regenerating`:`settings.documents.embeddings.regenerate`)]})]}),(0,$.jsxs)(H,{onClick:c,className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{size:16}),l(`settings.saveSettings`)]})]}),(0,$.jsx)(jn,{})]})})}function jn(){let{t:e}=y(),t=r(),[n,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),{data:f}=i({queryKey:[`knowledge-collections`],queryFn:async()=>{let[e,t]=await Promise.all([Vt.getCollections(),Vt.getDocuments()]);return{collections:e.success&&e.data?e.data:[],documents:t.success&&t.data?t.data:[]}}}),{collections:p=[],documents:m=[]}=f??{},h=()=>t.invalidateQueries({queryKey:[`knowledge-collections`]}),g=async()=>{let t=n.trim();if(t){a(``);try{let e=await Vt.createCollection(t);if(!e.success)throw Error(e.error);await h()}catch{R.error(e(`settings.documents.collections.createFailed`))}}},_=async t=>{s(null);try{let e=await Vt.deleteCollection(t);if(!e.success)throw Error(e.error);await h()}catch{R.error(e(`settings.documents.collections.deleteFailed`))}},v=async t=>{d(null);try{let e=await Vt.deleteDocument(t);if(!e.success)throw Error(e.error);window.dispatchEvent(new Event(`libre:documents-updated`)),await h()}catch{R.error(e(`settings.documents.library.deleteFailed`))}},b=async(t,n)=>{try{let e=await Vt.setDocumentCollection(t,n);if(!e.success)throw Error(e.error);await h()}catch{R.error(e(`settings.documents.collections.assignFailed`))}};return(0,$.jsxs)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{className:`text-md font-medium text-gray-900 dark:text-gray-100 mb-1`,children:e(`settings.documents.collections.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:e(`settings.documents.collections.description`)}),(0,$.jsxs)(`div`,{className:`mb-3 flex gap-2`,children:[(0,$.jsx)(`input`,{value:n,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g()},placeholder:e(`settings.documents.collections.namePlaceholder`),"aria-label":e(`settings.documents.collections.namePlaceholder`),className:`flex-1 rounded-lg border border-gray-200 bg-white px-3 py-1.5 text-sm text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-900`}),(0,$.jsx)(H,{size:`sm`,onClick:()=>void g(),disabled:!n.trim(),children:e(`settings.documents.collections.create`)})]}),p.length>0&&(0,$.jsx)(`div`,{className:`mb-4 flex flex-wrap gap-1.5`,children:p.map(t=>o===t.id?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-red-200 bg-red-50 px-2.5 py-1 text-xs text-red-700 dark:border-red-800 dark:bg-red-900/20 dark:text-red-300`,children:[e(`settings.documents.collections.deleteConfirm`),(0,$.jsx)(`button`,{onClick:()=>void _(t.id),className:`font-medium underline decoration-red-400 underline-offset-2 hover:text-red-800 dark:hover:text-red-200`,children:e(`common.delete`)}),(0,$.jsx)(`button`,{onClick:()=>s(null),className:`text-red-400 hover:text-red-600 dark:hover:text-red-300`,title:e(`common.cancel`),"aria-label":e(`common.cancel`),children:(0,$.jsx)(Ye,{className:`h-3 w-3`})})]},t.id):(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1 text-xs text-gray-700 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-800`,children:[(0,$.jsx)(et,{className:`h-3 w-3`}),t.name,(0,$.jsx)(`span`,{className:`tabular-nums text-gray-400 dark:text-dark-500`,children:t.documentCount??0}),t.shared?(0,$.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:e(`settings.documents.collections.shared`)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>l({id:t.id,name:t.name}),className:`text-gray-400 transition-colors hover:text-primary-500 dark:text-dark-500`,title:e(`settings.documents.collections.share`),"aria-label":e(`settings.documents.collections.share`),"data-testid":`collection-share`,children:(0,$.jsx)(I,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{onClick:()=>s(t.id),className:`text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:e(`common.delete`),"aria-label":e(`common.delete`),children:(0,$.jsx)(Ye,{className:`h-3 w-3`})})]})]},t.id))}),(0,$.jsx)(`h4`,{className:`text-md font-medium text-gray-900 dark:text-gray-100 mb-1`,children:e(`settings.documents.library.title`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:e(`settings.documents.library.description`)}),m.length===0?(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`settings.documents.library.empty`)}):(0,$.jsx)(`div`,{className:`divide-y divide-gray-100 rounded-xl border border-gray-200 dark:divide-dark-300 dark:border-dark-300`,children:m.map(t=>(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-2`,children:u===t.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-sm text-red-700 dark:text-red-300`,children:e(`settings.documents.library.deleteConfirm`,{name:t.filename})}),(0,$.jsx)(H,{size:`sm`,variant:`danger`,onClick:()=>void v(t.id),children:e(`common.delete`)}),(0,$.jsx)(H,{size:`sm`,variant:`ghost`,onClick:()=>d(null),children:e(`common.cancel`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_t,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-sm text-gray-900 dark:text-dark-900`,children:t.filename}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:[x(t.size),` · `,t.sessionId?e(`settings.documents.library.chatScope`):e(`settings.documents.library.everyChatScope`)]})]}),t.processingStatus===`failed`&&(0,$.jsx)(`span`,{className:`shrink-0 rounded-full bg-red-100 px-2 py-0.5 text-xs font-medium text-red-700 dark:bg-red-900/30 dark:text-red-300`,title:t.processingError||e(`settings.documents.library.extractionFailed`),children:e(`settings.documents.library.extractionFailed`)}),t.processingStatus===`queued`&&(0,$.jsx)(`span`,{className:`shrink-0 rounded-full bg-gray-100 px-2 py-0.5 text-xs font-medium text-gray-600 dark:bg-dark-200 dark:text-dark-700`,children:e(`settings.documents.library.extractionQueued`)}),p.length>0&&(0,$.jsxs)(`select`,{value:t.collectionId??``,onChange:e=>void b(t.id,e.target.value||null),"aria-label":e(`settings.documents.collections.assignTo`,{name:t.filename}),className:`rounded-lg border border-gray-200 bg-white px-2 py-1 text-xs text-gray-700 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,$.jsx)(`option`,{value:``,children:e(`settings.documents.collections.none`)}),p.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,$.jsx)(`button`,{onClick:()=>d(t.id),className:`text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:e(`common.delete`),"aria-label":e(`common.delete`),children:(0,$.jsx)(pt,{className:`h-4 w-4`})})]})},t.id))}),c&&(0,$.jsx)(rn,{resourceType:`knowledge-collection`,resourceId:c.id,resourceLabel:c.name,onClose:()=>l(null)})]})}function Mn({label:e,value:t,min:n,max:r,step:i,description:a,format:o=e=>String(e),onChange:s}){let c=(0,Q.useId)();return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{htmlFor:c,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[e,`: `,o(t)]}),(0,$.jsx)(`input`,{id:c,type:`range`,"aria-valuetext":o(t),min:n,max:r,step:i,value:t,onChange:e=>s(Number(e.target.value)),className:`w-full range-slider`}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:a})]})}function Nn({generationOptions:e,generationScope:t,scopedModel:n,onGenerationScopeChange:r,embeddingSettings:i,effectiveEmbeddingSettings:a,embeddingModelOptions:o,embeddingStatus:s,onGenerationOptionChange:c,onEmbeddingSettingsChange:l,onResetGenerationOptions:u,onSaveGenerationOptions:d,onResetEmbeddingSettings:f,onSaveEmbeddingSettings:p}){let{t:m}=y(),[h,g]=(0,Q.useState)(!1),_=(0,Q.useId)(),v=(0,Q.useId)(),b=(0,Q.useId)(),x=(0,Q.useId)(),S=(0,Q.useId)(),w=(0,Q.useId)(),T=(0,Q.useId)(),E=[{value:`global`,label:m(`settings.generation.scopeAll`)},...n?[{value:`model`,label:m(`settings.generation.scopeModel`,{model:n})}]:[]];return(0,$.jsx)(`div`,{className:`space-y-6`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Dn,{title:m(`settings.generation.title`),description:m(`settings.generation.description`)}),(0,$.jsxs)(`div`,{className:`mb-6 rounded-lg border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`label`,{htmlFor:v,className:`mb-2 block text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`settings.generation.scopeLabel`)}),(0,$.jsx)(Dt,{id:v,value:t,onChange:e=>r(e.target.value),options:E}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-gray-400`,children:m(t===`model`?`settings.generation.scopeModelHint`:`settings.generation.scopeAllHint`)})]}),(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":h,"aria-controls":_,onClick:()=>g(e=>!e),className:`flex w-full items-center justify-between gap-4 p-4 text-start`,children:[(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`block text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`settings.generation.advancedSettings`)}),(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-gray-500 dark:text-gray-400`,children:m(`settings.generation.advancedSettingsDescription`)})]}),(0,$.jsx)(N,{className:C(`h-4 w-4 shrink-0 text-gray-500 transition-transform`,h&&`rotate-180`)})]}),h&&(0,$.jsxs)(`div`,{id:_,className:`space-y-6 border-t border-gray-200 p-4 dark:border-dark-300`,children:[(0,$.jsxs)(Fn,{title:m(`settings.generation.coreParameters`),children:[(0,$.jsx)(In,{label:m(`settings.generation.temperature`),hint:`(0.0-2.0)`,min:0,max:2,step:.1,value:e.temperature,placeholder:`0.8`,description:m(`settings.generation.temperatureDescription`),onChange:e=>c(`temperature`,e)}),(0,$.jsx)(In,{label:m(`settings.generation.topP`),hint:`(0.0-1.0)`,min:0,max:1,step:.05,value:e.top_p,placeholder:`0.9`,description:m(`settings.generation.topPDescription`),onChange:e=>c(`top_p`,e)}),(0,$.jsx)(In,{label:m(`settings.generation.topK`),hint:`(1-100)`,min:1,max:100,value:e.top_k,placeholder:`40`,integer:!0,description:m(`settings.generation.topKDescription`),onChange:e=>c(`top_k`,e)}),(0,$.jsx)(In,{label:m(`settings.generation.minP`),hint:`(0.0-1.0)`,min:0,max:1,step:.05,value:e.min_p,placeholder:`0.0`,description:m(`settings.generation.minPDescription`),onChange:e=>c(`min_p`,e)})]}),(0,$.jsxs)(Fn,{title:m(`settings.generation.generationControl`),children:[(0,$.jsx)(In,{label:m(`settings.generation.maxTokens`),min:-1,max:4096,value:e.num_predict,placeholder:`128`,integer:!0,description:m(`settings.generation.maxTokensDescription`),onChange:e=>c(`num_predict`,e)}),(0,$.jsx)(In,{label:m(`settings.generation.repeatPenalty`),hint:`(0.0-2.0)`,min:0,max:2,step:.1,value:e.repeat_penalty,placeholder:`1.1`,description:m(`settings.generation.repeatPenaltyDescription`),onChange:e=>c(`repeat_penalty`,e)}),(0,$.jsx)(In,{label:m(`settings.generation.contextLength`),min:512,max:32768,step:512,value:e.num_ctx,placeholder:`2048`,integer:!0,description:m(`settings.generation.contextLengthDescription`),onChange:e=>c(`num_ctx`,e)}),(0,$.jsx)(In,{label:m(`settings.generation.seed`),hint:`(${m(`settings.generation.optional`)})`,value:e.seed,placeholder:m(`settings.generation.random`),integer:!0,description:m(`settings.generation.seedDescription`),onChange:e=>c(`seed`,e)}),(0,$.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,$.jsx)(`label`,{htmlFor:b,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:m(`settings.generation.thinking`)}),(0,$.jsx)(Dt,{id:b,value:fn(e.think),onChange:e=>c(`think`,Z(e.target.value)),options:pn.map(e=>({value:e,label:m(`settings.generation.thinkingLevels.${e}`)}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:m(`settings.generation.thinkingDescription`)})]})]}),(0,$.jsxs)(Fn,{title:m(`settings.generation.advancedOptions`),children:[(0,$.jsx)(In,{label:m(`settings.generation.presencePenalty`),hint:`(-2.0-2.0)`,min:-2,max:2,step:.1,value:e.presence_penalty,placeholder:`0.0`,description:m(`settings.generation.presencePenaltyDescription`),onChange:e=>c(`presence_penalty`,e)}),(0,$.jsx)(In,{label:m(`settings.generation.frequencyPenalty`),hint:`(-2.0-2.0)`,min:-2,max:2,step:.1,value:e.frequency_penalty,placeholder:`0.0`,description:m(`settings.generation.frequencyPenaltyDescription`),onChange:e=>c(`frequency_penalty`,e)}),(0,$.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,$.jsxs)(`label`,{htmlFor:x,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[m(`settings.generation.stopSequences`),(0,$.jsxs)(`span`,{className:`text-xs text-gray-500 ms-1`,children:[`(`,m(`settings.generation.commaSeparated`),`)`]})]}),(0,$.jsx)(`input`,{id:x,type:`text`,value:e.stop?.join(`, `)??``,onChange:e=>c(`stop`,e.target.value?e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean):void 0),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white dark:bg-dark-200 text-gray-900 dark:text-gray-100`,placeholder:`\\\\n, ###, STOP`}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:m(`settings.generation.stopSequencesDescription`)})]})]}),(0,$.jsxs)(`div`,{className:`flex justify-between items-center pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(H,{onClick:u,variant:`outline`,className:`flex items-center gap-2`,children:[(0,$.jsx)(Pe,{size:16}),m(`settings.generation.resetDefaults`)]}),(0,$.jsxs)(H,{onClick:d,className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{size:16}),m(`settings.generation.saveOptions`)]})]})]})]}),(0,$.jsx)(`div`,{className:`mt-6`,children:(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{id:S,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:m(`settings.generation.embeddingSettings`)}),(0,$.jsxs)(`div`,{role:`group`,"aria-labelledby":S,className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`span`,{id:w,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:m(`settings.generation.enableEmbeddings`)}),(0,$.jsx)(X,{checked:i.enabled,onChange:e=>l(`enabled`,e),"aria-labelledby":w})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:T,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:m(`settings.documents.embeddings.model`)}),(0,$.jsx)(Dt,{id:T,value:a.model,onChange:e=>l(`model`,e.target.value),options:o,disabled:!i.enabled})]}),(0,$.jsx)(Ln,{label:m(`settings.documents.embeddings.chunkSize`),hint:m(`settings.documents.embeddings.chunkSizeInTokens`),value:i.chunkSize,min:1,disabled:!i.enabled,onChange:e=>l(`chunkSize`,e)}),(0,$.jsx)(Ln,{label:m(`settings.documents.embeddings.chunkOverlap`),hint:m(`settings.documents.embeddings.chunkOverlapInTokens`),value:i.chunkOverlap,min:0,disabled:!i.enabled,onChange:e=>l(`chunkOverlap`,e)}),(0,$.jsx)(Ln,{label:m(`settings.documents.embeddings.similarityThreshold`),value:i.similarityThreshold,min:0,max:1,step:.01,disabled:!i.enabled,onChange:e=>l(`similarityThreshold`,e)})]}),s&&(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,$.jsxs)(`span`,{className:`text-gray-700 dark:text-gray-300`,children:[m(`settings.documents.embeddings.status`),`:`]}),(0,$.jsx)(`span`,{className:`font-medium text-gray-900 dark:text-gray-100`,children:s.available?m(`settings.documents.embeddings.available`):m(`settings.documents.embeddings.unavailable`)})]}),s.available&&(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-sm mt-1`,children:[(0,$.jsxs)(`span`,{className:`text-gray-700 dark:text-gray-300`,children:[m(`settings.documents.embeddings.chunksWithEmbeddings`),`:`]}),(0,$.jsxs)(`span`,{className:`font-medium text-gray-900 dark:text-gray-100`,children:[s.chunksWithEmbeddings,` /`,` `,s.totalChunks]})]})]}),(0,$.jsxs)(`div`,{className:`flex justify-between items-center mt-4`,children:[(0,$.jsxs)(H,{onClick:f,variant:`outline`,className:`flex items-center gap-2`,children:[(0,$.jsx)(Pe,{size:16}),m(`settings.generation.resetDefaults`)]}),(0,$.jsxs)(H,{onClick:p,className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{size:16}),m(`settings.saveSettings`)]})]})]})}),(0,$.jsx)(Pn,{})]})})}function Pn(){let{t:e}=y(),t=$t(e=>e.user),n=$t(e=>e.systemInfo),r=t?.role===`admin`||n?.requiresAuth===!1,i=m(e=>e.models),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(`8000`),[l,u]=(0,Q.useState)(`8`),[d,f]=(0,Q.useState)(``),[p,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(!1),x=(0,Q.useId)(),S=(0,Q.useId)(),C=(0,Q.useId)(),w=(0,Q.useId)(),T=(0,Q.useId)();if((0,Q.useEffect)(()=>{if(!r)return;let t=!1;return Pt.getCompactionConfig().then(e=>{!t&&e.success&&e.data&&(o(e.data.enabled),c(String(e.data.thresholdTokens)),u(String(e.data.keepRecentMessages)),f(e.data.model),h(e.data.prompt),_(!0))}).catch(()=>{t||R.error(e(`settings.compaction.loadFailed`))}),()=>{t=!0}},[r,e]),!r)return null;let E=i.filter(e=>!e.isPersona&&!e.isAgent),D=[{value:``,label:e(`settings.compaction.sessionModelOption`)},...E.map(e=>({value:e.name,label:e.isPlugin?`${e.name} · ${e.pluginName||e.pluginId}`:`${e.name} · Ollama`})),...d&&!E.some(e=>e.name===d)?[{value:d,label:`${d} (current)`}]:[]],O=async(t=a)=>{let n=Number(s);if(!Number.isInteger(n)||n<500||n>1e6){R.error(e(`settings.compaction.thresholdInvalid`));return}let r=Number(l);if(!Number.isInteger(r)||r<2||r>200){R.error(e(`settings.compaction.keepRecentInvalid`));return}b(!0);try{let i=await Pt.setCompactionConfig({enabled:t,thresholdTokens:n,keepRecentMessages:r,model:d,prompt:p});if(!i.success||!i.data)throw Error(i.error||e(`settings.compaction.saveFailed`));o(i.data.enabled),c(String(i.data.thresholdTokens)),u(String(i.data.keepRecentMessages)),f(i.data.model),h(i.data.prompt),R.success(e(`settings.compaction.saved`))}catch(t){R.error(t instanceof Error&&t.message?t.message:e(`settings.compaction.saveFailed`))}finally{b(!1)}};return(0,$.jsx)(`div`,{className:`mt-6`,children:(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 mb-1`,children:[(0,$.jsx)(`h4`,{id:x,className:`block text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`settings.compaction.title`)}),(0,$.jsx)(X,{"aria-labelledby":x,checked:a,onChange:e=>{O(e)},disabled:v||!g})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:e(`settings.compaction.description`)}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:S,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.compaction.thresholdLabel`)}),(0,$.jsx)(`input`,{id:S,type:`number`,min:500,max:1e6,step:500,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white dark:bg-dark-200 text-gray-900 dark:text-gray-100`}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:e(`settings.compaction.thresholdDescription`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:C,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.compaction.keepRecentLabel`)}),(0,$.jsx)(`input`,{id:C,type:`number`,min:2,max:200,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white dark:bg-dark-200 text-gray-900 dark:text-gray-100`}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:e(`settings.compaction.keepRecentDescription`)})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:w,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.compaction.modelLabel`)}),(0,$.jsx)(Dt,{id:w,value:d,onChange:e=>f(e.target.value),options:D}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:e(`settings.compaction.modelDescription`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:T,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.compaction.promptLabel`)}),(0,$.jsx)(Tt,{id:T,value:p,onChange:e=>h(e.target.value),rows:5,placeholder:e(`settings.compaction.promptPlaceholder`),spellCheck:!1}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:e(`settings.compaction.promptDescription`,{previousSummaryVariable:`{{PREVIOUS_SUMMARY}}`,messagesVariable:`{{MESSAGES}}`})})]})]}),(0,$.jsx)(`div`,{className:`flex justify-end items-center mt-4`,children:(0,$.jsxs)(H,{onClick:()=>void O(),disabled:v||!g,className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{size:16}),e(`settings.saveSettings`)]})})]})})}function Fn({title:e,children:t}){return(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{className:`text-md font-medium text-gray-900 dark:text-gray-100 mb-4`,children:e}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:t})]})}function In({label:e,value:t,placeholder:n,description:r,hint:i,min:a,max:o,step:s,integer:c=!1,onChange:l}){let u=(0,Q.useId)();return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{htmlFor:u,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[e,i&&(0,$.jsx)(`span`,{className:`text-xs text-gray-500 ms-1`,children:i})]}),(0,$.jsx)(`input`,{id:u,type:`number`,min:a,max:o,step:s,value:t??``,placeholder:n,onChange:e=>l(e.target.value?c?parseInt(e.target.value):parseFloat(e.target.value):void 0),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white dark:bg-dark-200 text-gray-900 dark:text-gray-100`}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:r})]})}function Ln({label:e,value:t,min:n,max:r,step:i,hint:a,disabled:o,onChange:s}){let c=(0,Q.useId)();return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{htmlFor:c,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[e,a&&(0,$.jsx)(`span`,{className:`text-xs text-gray-500 ms-1`,children:a})]}),(0,$.jsx)(`input`,{id:c,type:`number`,min:n,max:r,step:i,value:t,onChange:e=>s(Number(e.target.value)),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white dark:bg-dark-200 text-gray-900 dark:text-gray-100`,disabled:o})]})}function Rn({loading:e,settings:t,effectiveSettings:n,models:r,plugins:i,sizes:a,qualities:o,styles:s,onSettingChange:c,onModelChange:l,onReset:u,onSave:d}){let{t:f}=y(),p=(0,Q.useId)(),m=(0,Q.useId)(),h=(0,Q.useId)(),g=(0,Q.useId)(),_=(0,Q.useId)(),v=Qt(r,n.model,n.pluginId);return(0,$.jsx)(`div`,{className:`space-y-6`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Dn,{title:f(`settings.imageGen.title`),description:f(`settings.imageGen.description`)}),e?(0,$.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,$.jsx)(Ce,{className:`h-8 w-8 animate-spin text-primary-500`}),(0,$.jsx)(`span`,{className:`ms-3 text-gray-600 dark:text-gray-400`,children:f(`settings.imageGen.loadingProviders`)})]}):r.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-yellow-200 bg-yellow-500/10 p-4 dark:border-yellow-800 dark:bg-yellow-900/20`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(ue,{className:`h-5 w-5 text-yellow-600 dark:text-yellow-400 mt-0.5`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-ink`,children:f(`settings.imageGen.noProviders`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-ink-muted`,children:f(`settings.imageGen.noProvidersDescription`)})]})]})}):(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{id:p,className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:f(`settings.imageGen.enable`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:f(`settings.imageGen.enableDescription`)})]}),(0,$.jsx)(X,{checked:t.enabled,onChange:e=>c(`enabled`,e),"aria-labelledby":p})]})}),(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-4`,children:f(`settings.imageGen.configuration`)}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:m,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:f(`settings.imageGen.model`)}),(0,$.jsx)(Dt,{id:m,value:v?Yt(v):``,onChange:e=>{let t=r.find(t=>Yt(t)===e.target.value);t&&l(t.model,t.plugin)},disabled:!t.enabled,options:[{value:``,label:f(`settings.model.selectModel`)},...r.map(e=>({value:Yt(e),label:`${e.model} (${e.plugin})`,key:`${e.plugin}:${e.model}`}))]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:f(`settings.imageGen.modelDescription`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:h,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:v?.config?.size_label||f(`settings.imageGen.size`)}),(0,$.jsx)(Dt,{id:h,value:n.size,onChange:e=>c(`size`,e.target.value),disabled:!t.enabled||a.length===0,options:[...a.length>0?a.map(e=>({value:e,label:e})):[{value:`1024x1024`,label:`1024x1024`},{value:`1792x1024`,label:`1792x1024`},{value:`1024x1792`,label:`1024x1792`}]]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:f(`settings.imageGen.sizeDescription`)})]}),o.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:g,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:f(`settings.imageGen.quality`)}),(0,$.jsx)(Dt,{id:g,value:n.quality,onChange:e=>c(`quality`,e.target.value),disabled:!t.enabled,options:o.map(e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:f(`settings.imageGen.qualityDescription`)})]}),s.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:_,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:f(`settings.imageGen.style`)}),(0,$.jsx)(Dt,{id:_,value:n.style,onChange:e=>c(`style`,e.target.value),disabled:!t.enabled,options:s.map(e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:f(`settings.imageGen.styleDescription`)})]})]})]}),i.length>0&&(0,$.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:f(`settings.imageGen.availableProviders`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:i.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 bg-white dark:bg-dark-100 rounded-sm border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-green-500`}),(0,$.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:e.name}),(0,$.jsxs)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[`(`,e.models?.length||0,` `,f(`settings.imageGen.models`),`)`]})]},e.id))})]}),(0,$.jsxs)(`div`,{className:`flex justify-between items-center pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(H,{onClick:u,variant:`outline`,className:`flex items-center gap-2`,children:[(0,$.jsx)(Pe,{size:16}),f(`common.reset`)]}),(0,$.jsxs)(H,{onClick:d,className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{size:16}),f(`settings.saveSettings`)]})]})]})]})})}var zn=192e3,Bn=(e,t)=>e.isPlugin&&e.pluginId?e.pluginId:t,Vn=()=>{let{t:e}=y(),t=m(e=>e.models),n=m(e=>e.loadModels),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)([]),[s,c]=(0,Q.useState)([]),[u,d]=(0,Q.useState)({}),[f,h]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(`all`),[b,x]=(0,Q.useState)(null),[S,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),k=(0,Q.useRef)(null),A=(0,Q.useRef)(null),j=(0,Q.useMemo)(()=>t.filter(e=>!e.isPersona&&!e.isAgent),[t]);(0,Q.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await J.getModelVisibility();if(e||!t.success||!t.data)return;let{hidden:n,order:r,starred:a,metadata:s}=t.data;i(n??[]),o(r??[]),c(a??[]),d(s??{})}catch{}})(),()=>{e=!0}},[]);let M=(0,Q.useMemo)(()=>new Set(r),[r]),N=(0,Q.useMemo)(()=>new Set(s),[s]),P=(0,Q.useMemo)(()=>l(j,a,s),[j,a,s]),F=(0,Q.useMemo)(()=>{let e=f.trim().toLowerCase();return P.filter(t=>{let n=p(t);if(_===`local`&&t.isPlugin||_===`provider`&&!t.isPlugin||_===`hidden`&&!M.has(n))return!1;if(!e)return!0;let r=u[n]?.label??``;return t.name.toLowerCase().includes(e)||r.toLowerCase().includes(e)||Bn(t,`ollama`).toLowerCase().includes(e)})},[P,f,_,M,u]),I=async(e,t)=>{let n=r,a=t?n.filter(t=>t!==e):[...n,e];i(a),await B({hidden:a},()=>i(n))},ee=e=>{let t=new Set(F.map(p)),n=r,a=e?n.filter(e=>!t.has(e)):[...new Set([...n,...t])];i(a),B({hidden:a},()=>i(n))},te=(e,t)=>{let n=s,r=t?[e,...n.filter(t=>t!==e)]:n.filter(t=>t!==e);c(r),B({starred:r},()=>c(n))},ne=(e,t,n)=>{if(e===t)return;let r=P.map(p),i=r.indexOf(e);if(i===-1)return;r.splice(i,1);let s=r.indexOf(t);if(s===-1)return;r.splice(n===`after`?s+1:s,0,e);let c=a;o(r),B({order:r},()=>o(c))},L=(e,t,n)=>{let r={...e,[t]:{...e[t],...n}};return!r[t].label&&!r[t].avatar&&delete r[t],r},z=(e,t,n=!1)=>{let r=u,i=L(r,e,t);d(i),n&&B({metadata:i},()=>d(r))},ie=e=>{A.current=e,k.current?.click()},se=t=>{let n=t.target.files?.[0],r=A.current;if(t.target.value=``,!n||!r)return;if(!n.type.startsWith(`image/`)){R.error(e(`modelManager.catalog.pictureInvalid`));return}if(n.size>zn){R.error(e(`modelManager.catalog.pictureTooLarge`));return}let i=new FileReader;i.onload=()=>{typeof i.result==`string`&&z(r,{avatar:i.result},!0)},i.readAsDataURL(n)},B=async(t,r)=>{w(!0);try{let i=await J.setModelVisibility(t);if(!i.success){r(),R.error(i.error??e(`modelManager.catalog.visibilityFailed`));return}await n()}catch(t){r(),R.error(g(t,e(`modelManager.catalog.visibilityFailed`)))}finally{w(!1)}},ce=[{id:`all`,label:e(`modelManager.catalog.filterAll`)},{id:`local`,label:e(`modelManager.catalog.filterLocal`)},{id:`provider`,label:e(`modelManager.catalog.filterProviders`)},{id:`hidden`,label:e(`modelManager.catalog.filterHidden`)}];return(0,$.jsxs)(`div`,{className:`space-y-3`,"data-testid":`model-catalog`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,$.jsxs)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:[e(`modelManager.sections.catalog`),(0,$.jsx)(`span`,{className:`ms-2 text-xs font-normal text-gray-500 dark:text-gray-400`,children:j.length})]}),S&&(0,$.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`modelManager.catalog.saving`)})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative min-w-[180px] flex-1`,children:[(0,$.jsx)(oe,{className:`pointer-events-none absolute inset-s-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-gray-400`}),(0,$.jsx)(wt,{value:f,onChange:e=>h(e.target.value),placeholder:e(`modelManager.catalog.searchPlaceholder`),"aria-label":e(`modelManager.catalog.searchPlaceholder`),className:`ps-9`})]}),(0,$.jsx)(`select`,{value:_,onChange:e=>v(e.target.value),className:`h-9 rounded-lg border border-gray-200 bg-white px-2 text-xs text-gray-700 dark:border-dark-300 dark:bg-dark-100 dark:text-gray-200`,"aria-label":e(`modelManager.catalog.filterLabel`),children:ce.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.label},e.id))}),(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>ee(!0),children:e(`modelManager.catalog.enableAll`)}),(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>ee(!1),children:e(`modelManager.catalog.disableAll`)})]}),(0,$.jsx)(`input`,{ref:k,type:`file`,accept:`image/*`,onChange:se,className:`hidden`}),(0,$.jsxs)(`div`,{className:`divide-y divide-gray-100 rounded-lg border border-gray-200 dark:divide-dark-200/60 dark:border-dark-300`,children:[F.length===0&&(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-xs text-gray-500 dark:text-gray-400`,children:j.length===0?e(`modelManager.catalog.noModels`):e(`modelManager.catalog.empty`)}),F.map(t=>{let n=p(t),r=u[n]??{},i=!M.has(n),a=N.has(n),o=b===n,s=e(a?`modelManager.catalog.unstar`:`modelManager.catalog.star`,{name:r.label||t.name});return(0,$.jsxs)(`div`,{"data-testid":`model-catalog-row`,draggable:!0,onDragStart:()=>E(n),onDragEnd:()=>{E(null),O(null)},onDragOver:e=>{if(e.preventDefault(),!T||T===n)return;let t=e.currentTarget.getBoundingClientRect(),r=e.clientY-t.top<t.height/2?`before`:`after`;O(e=>e?.key===n&&e.edge===r?e:{key:n,edge:r})},onDrop:e=>{e.preventDefault(),T&&ne(T,n,D?.key===n?D.edge:`before`),E(null),O(null)},className:C(`relative flex flex-col gap-2 px-3 py-2`,T===n&&`opacity-50`),children:[D?.key===n&&T&&T!==n&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:C(`pointer-events-none absolute inset-x-0 h-0.5 bg-primary-500`,D.edge===`before`?`top-0`:`bottom-0`)}),(0,$.jsxs)(`div`,{className:`flex w-full min-w-0 items-center gap-2 pe-1`,children:[(0,$.jsx)(ut,{className:`h-4 w-4 shrink-0 cursor-grab text-gray-300 dark:text-dark-500`,"aria-hidden":`true`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>ie(n),title:e(`modelManager.catalog.setPicture`),"aria-label":e(`modelManager.catalog.setPicture`),className:`flex h-7 w-7 shrink-0 items-center justify-center overflow-hidden rounded-full border border-gray-200 bg-gray-50 text-gray-400 dark:border-dark-300 dark:bg-dark-200`,children:r.avatar?(0,$.jsx)(`img`,{src:r.avatar,alt:``,className:`h-full w-full object-cover`}):(0,$.jsx)(ue,{className:`h-3.5 w-3.5`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm text-gray-900 dark:text-gray-100`,children:r.label||t.name}),(0,$.jsxs)(`span`,{className:`block truncate text-[11px] text-gray-500 dark:text-gray-400`,children:[r.label?`${t.name} · `:``,Bn(t,e(`modelManager.catalog.providerOllama`))]})]}),!i&&(0,$.jsx)(`span`,{className:`shrink-0 rounded-md bg-gray-100 px-1.5 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-gray-400`,children:e(`modelManager.catalog.hidden`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>te(n,!a),"aria-pressed":a,title:s,"aria-label":s,className:C(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors hover:bg-gray-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-1 dark:hover:bg-dark-200 dark:focus-visible:ring-offset-dark-100`,a?`text-primary-600 dark:text-primary-400`:`text-gray-400 hover:text-gray-700 dark:hover:text-gray-200`),children:(0,$.jsx)(re,{className:C(`h-4 w-4`,a&&`fill-current`),"aria-hidden":`true`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>x(o?null:n),title:e(`modelManager.catalog.rename`),"aria-label":e(`modelManager.catalog.rename`),"aria-expanded":o,className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-gray-400 hover:bg-gray-100 hover:text-gray-700 dark:hover:bg-dark-200`,children:o?(0,$.jsx)(Ye,{className:`h-3.5 w-3.5`}):(0,$.jsx)(ct,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void I(n,!i),"aria-pressed":!i,title:e(i?`modelManager.catalog.hide`:`modelManager.catalog.show`),"aria-label":e(i?`modelManager.catalog.hide`:`modelManager.catalog.show`),className:C(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors`,i?`text-gray-400 hover:bg-gray-100 hover:text-gray-700 dark:hover:bg-dark-200`:`text-warning-600 hover:bg-gray-100 dark:text-warning-500 dark:hover:bg-dark-200`),children:i?(0,$.jsx)(Ee,{className:`h-4 w-4`}):(0,$.jsx)(ae,{className:`h-4 w-4`})})]}),o&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ps-8`,children:[(0,$.jsx)(wt,{value:r.label??``,onChange:e=>z(n,{label:e.target.value}),onBlur:e=>z(n,{label:e.target.value},!0),placeholder:t.name,"aria-label":e(`modelManager.catalog.displayName`,{name:t.name}),className:`h-8 max-w-xs text-xs`}),r.avatar&&(0,$.jsx)(H,{size:`sm`,variant:`ghost`,onClick:()=>z(n,{avatar:``},!0),children:e(`modelManager.catalog.clearPicture`)})]})]},n)})]})]})};function Hn(e){return e.isLegacySelection?e.name:e.isPersona?e.personaName||e.name:e.isAgent&&e.agentName||e.name}function Un(e,t){return e.isLegacySelection?t(`modelSelector.legacyProvider`):e.isPersona?t(`settings.model.persona`):e.isAgent?t(`common.agent`):e.isPlugin?e.pluginName||e.pluginId||t(`common.provider`):`Ollama`}function Wn(e,t,n=`parentheses`){let r=Hn(e),i=Un(e,t),a=e.isUnavailable?t(`modelSelector.unavailable`):``;return n===`separator`?`${r} · ${i}${a?` (${a})`:``}`:`${r} (${i}${a?`, ${a}`:``})`}function Gn({models:e,selectedModel:t,selectedProviderType:n,selectedProviderId:r,systemMessage:i,tempSystemMessage:a,loading:o,preferences:c,currentVisionModel:l,visionModelOptions:p,currentTaskModel:m,autoTitleTaskModelOptions:h,onModelChange:g,onSystemMessageChange:_,onSystemMessageSave:v,onAutoTitleChange:b,onAutoTitleTaskModelChange:x,onVisionModelChange:S}){let{user:C,systemInfo:w}=$t(),T=C?.role===`admin`||w?.requiresAuth===!1,{t:E}=y(),D=(0,Q.useId)(),O=(0,Q.useId)(),k=(0,Q.useId)(),A=(0,Q.useId)(),j=(0,Q.useId)(),M={model:t,providerType:n,providerId:r},N=s(e,M),P=t?f(N,M):``,F=d(N,M);return(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Dn,{title:E(`settings.model.title`)}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`label`,{htmlFor:D,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:E(`settings.model.defaultModel`)}),(0,$.jsx)(Dt,{id:D,"aria-label":E(`settings.model.defaultModel`),"data-testid":`default-model-select`,value:P,onChange:g,options:[{value:``,label:E(`settings.model.selectModel`)},...N.map(e=>({value:u(e),label:Wn(e,E)}))]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:E(`settings.model.defaultModelDescription`)})]}),t&&(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,"data-testid":`current-model-info`,children:[(0,$.jsx)(`h4`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:E(`settings.model.currentModelInfo`)}),(0,$.jsx)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,$.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,$.jsx)(Kn,{label:`${E(`settings.model.name`)}:`,value:F?Hn(F):t,truncate:!0}),F&&(0,$.jsx)(Kn,{label:`${E(`common.provider`)}:`,value:Un(F,E)}),F?.details?.parameter_size&&(0,$.jsx)(Kn,{label:`${E(`settings.model.size`)}:`,value:F.details.parameter_size}),F?.details?.family&&(0,$.jsx)(Kn,{label:`${E(`settings.model.family`)}:`,value:F.details.family}),F?.details?.format&&(0,$.jsx)(Kn,{label:`${E(`settings.model.format`)}:`,value:F.details.format})]})})]}),(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`label`,{htmlFor:O,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:E(`settings.systemMessage.title`)}),(0,$.jsx)(Tt,{id:O,value:a,onChange:_,placeholder:E(`settings.systemMessage.placeholder`),className:`w-full min-h-[100px] bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,rows:4}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between mt-3`,children:[(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:E(`settings.systemMessage.description`)}),(0,$.jsx)(H,{onClick:v,size:`sm`,disabled:o||a===i,children:E(`common.save`)})]})]})]}),(0,$.jsx)(`div`,{className:`mt-6`,children:(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:E(`settings.model.specializedModels`,{defaultValue:`Specialized Models`})}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 gap-5 lg:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:k,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:E(`settings.model.visionModel`,{defaultValue:`Vision Model`})}),(0,$.jsx)(Dt,{id:k,"aria-label":E(`settings.model.visionModel`),"data-testid":`vision-model-select`,value:l,onChange:e=>S(e.target.value),options:p}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:E(`settings.model.visionModelDescription`,{defaultValue:`Used automatically whenever the outgoing chat context contains images. Choose a model that supports image input.`})})]}),(0,$.jsxs)(`div`,{className:`lg:border-s lg:border-gray-200 lg:ps-5 dark:lg:border-dark-300`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col pe-4`,children:[(0,$.jsx)(`span`,{id:A,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:E(`settings.model.autoTitle.enable`)}),(0,$.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:E(`settings.model.autoTitle.enableDescription`)})]}),(0,$.jsx)(X,{checked:c.titleSettings?.autoTitle||!1,onChange:b,"aria-labelledby":A})]}),c.titleSettings?.autoTitle&&(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsx)(`label`,{htmlFor:j,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:E(`settings.model.autoTitle.taskModel`)}),(0,$.jsx)(Dt,{id:j,"aria-label":E(`settings.model.autoTitle.taskModel`),"data-testid":`task-model-select`,value:m,onChange:e=>x(e.target.value),options:h}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:E(`settings.model.autoTitle.taskModelDescription`)})]})]})]})]})})]}),T&&(0,$.jsx)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4`,children:(0,$.jsx)(Vn,{})})]})}function Kn({label:e,value:t,truncate:n=!1}){return(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-white dark:bg-dark-100 rounded-md border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e}),(0,$.jsx)(`span`,{className:n?`text-sm font-semibold text-gray-900 dark:text-gray-100 truncate ms-2`:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t})]})}var qn=[{titleKey:`keyboard.groups.general`,rows:[{labelKey:`keyboard.openPalette`,keys:[`mod`,`K`]},{labelKey:`keyboard.openSettings`,keys:[`mod`,`,`]},{labelKey:`keyboard.toggleDarkMode`,keys:[`mod`,`D`]},{labelKey:`keyboard.showShortcuts`,keys:[`?`]},{labelKey:`keyboard.closeModals`,keys:[`Esc`]}]},{titleKey:`keyboard.groups.navigation`,rows:[{labelKey:`keyboard.toggleSidebar`,keys:[`mod`,`B`]},{labelKey:`keyboard.newChat`,keys:[`mod`,`⇧`,`O`]},{labelKey:`keyboard.newWork`,keys:[`mod`,`⇧`,`U`]}]},{titleKey:`keyboard.groups.chat`,rows:[{labelKey:`keyboard.actions.sendMessage`,keys:[`↩`]},{labelKey:`keyboard.actions.newLine`,keys:[`⇧`,`↩`]},{labelKey:`keyboard.actions.saveEdit`,keys:[`↩`]},{labelKey:`keyboard.actions.cancelEdit`,keys:[`Esc`]}]},{titleKey:`keyboard.groups.workspace`,rows:[{labelKey:`keyboard.actions.saveFile`,keys:[`mod`,`S`]},{labelKey:`keyboard.actions.formatCode`,keys:[`⌥`,`⇧`,`F`]}]}];function Jn(){let{t:e}=y(),t=S()?`⌘`:`Ctrl`,n=S()?`⌥`:`Alt`,r=e=>e===`mod`?t:e===`⌥`?n:e;return(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:e(`keyboard.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`keyboard.description`)})]}),qn.map(t=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:e(t.titleKey)}),(0,$.jsx)(`div`,{className:`divide-y divide-gray-200 overflow-hidden rounded-lg border border-gray-200 dark:divide-dark-300 dark:border-dark-300`,children:t.rows.map(n=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 bg-white px-4 py-2.5 dark:bg-dark-100`,children:[(0,$.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:e(n.labelKey)}),(0,$.jsx)(`span`,{className:`flex shrink-0 items-center gap-1`,children:n.keys.map((e,t)=>(0,$.jsx)(`kbd`,{className:`rounded-sm border border-gray-300 bg-gray-100 px-2 py-1 font-mono text-xs text-gray-700 dark:border-dark-400 dark:bg-dark-200 dark:text-gray-300`,children:r(e)},`${n.labelKey}-${e}-${t}`))})]},`${t.titleKey}-${n.labelKey}`))})]},t.titleKey))]})}var Yn=8;function Xn(e,t){let n=e.trim();if(!n)return null;let r;try{r=new URL(n)}catch{return`invalid-url`}return r.protocol!==`http:`&&r.protocol!==`https:`?`insecure-url`:t?.toLowerCase().endsWith(`base_url`)&&(r.search||r.hash)?`query-or-fragment`:null}function Zn(e){try{return new URL(e.trim()).protocol===`http:`}catch{return!1}}function Qn(e){let t=e.toLowerCase();return t===`endpoint`||t===`base_url`||t===`api_url`||t===`models_endpoint`||t.endsWith(`_endpoint`)||t.endsWith(`_base_url`)}function $n(e){let t=e.trim();if(!t.startsWith(`/`)||t.startsWith(`//`)||t.includes(`://`)||t.includes(`\\`)||t.includes(`?`)||t.includes(`#`))return!1;let n=t;for(let e=0;e<=Yn;e+=1){let t;try{t=decodeURIComponent(n)}catch{return!1}if(t===n)return!n.includes(`\\`)&&!n.includes(`?`)&&!n.includes(`#`)&&!n.split(`/`).some(e=>e===`.`||e===`..`);if(e===Yn)return!1;n=t}return!1}var er=new Set([`api_mode`,`api_path`,`endpoint`,`base_url`,`api_url`,`image_endpoint`,`embedding_endpoint`,`tts_endpoint`,`model`,`model_id`,`models_endpoint`]);function tr(e){let t=new Set(er),n=e?.capabilities;for(let e of Object.values(n||{})){let n=e?.config?.endpoint_variable??e?.endpoint_variable;typeof n==`string`&&n.trim()&&t.add(n)}return t}function nr(e,t){return tr(t).has(e)}function rr(e,t){if(e.default!==void 0)return e.default;if(!t)return;if(e.name===`endpoint`||e.name===`api_url`)return t.endpoint||void 0;if(e.name===`base_url`)return t.base_url;if(e.name===`api_path`)return t.api_path;if(e.name===`api_mode`){if(t.api_mode)return t.api_mode;try{return new URL(t.endpoint).pathname.replace(/\/+$/,``).endsWith(`/responses`)?`responses`:`chat_completions`}catch{return`chat_completions`}}let n=t.capabilities;for(let t of Object.values(n||{}))if((t?.config?.endpoint_variable??t?.endpoint_variable)===e.name&&typeof t.endpoint==`string`)return t.endpoint}function ir(e,t){let n=[],r=[];for(let i of e)(nr(i.name,t)?n:r).push(i);return{connection:n,advanced:r}}function ar(e,t){let n={};for(let r of e){let e=t[r.name];n[r.name]=e?.has_value&&!e.is_sensitive?e.value:``}return n}function or(e,t,n,r,i){let a=new Set(e.map(e=>e.name)),o={},s=[];for(let c of n){if(!a.has(c))continue;let n=e.find(e=>e.name===c);if(!n)continue;let l=t[c],u=r[c],d=typeof l==`string`&&l.trim().length===0,f=rr(n,i),p=f!==void 0&&(typeof l==`string`&&typeof f==`string`?l.trim()===f.trim():Object.is(l,f));if(d||p){if(n.sensitive&&u?.has_value)continue;u?.has_value&&s.push(c);continue}o[c]=l}return{variables:o,unset:s}}o(`components:hugging-face-model-browser`);var sr=({plugin:e})=>{let{t}=y(),n=r(),i=$t(e=>e.user),a=$t(e=>e.systemInfo)?.requiresAuth===!1||i?.role===`admin`,{pluginVariables:o,fetchPluginVariables:s,updatePluginVariables:c,resetPluginVariables:l,loadPlugins:u}=en(),[d,f]=(0,Q.useState)({}),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(new Set),[b,x]=(0,Q.useState)({}),[S,w]=(0,Q.useState)(new Set),[T,E]=(0,Q.useState)(!1),D=Q.useId(),O=Q.useId(),k=(0,Q.useMemo)(()=>e.variables||[],[e.variables]),A=(0,Q.useMemo)(()=>tr(e),[e]),j=(0,Q.useMemo)(()=>a?k:k.filter(e=>!A.has(e.name)),[a,A,k]),M=(0,Q.useMemo)(()=>o[e.id]||{},[o,e.id]),P=(0,Q.useMemo)(()=>ir(j,e),[e,j]);(0,Q.useEffect)(()=>{s(e.id)},[s,e.id]);let F=JSON.stringify(M),I=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let t=j.map(e=>`${e.name}:${e.type}`).join(`|`),n=`${e.id}:${t}:${F}`;if(I.current===n)return;I.current=n;let r=JSON.parse(F);f(e=>{let t=ar(j,r);for(let n of S)n in e&&(t[n]=e[n]);return t})},[S,e.id,j,F]);let ee=async()=>{let r={};for(let n of j){if(!S.has(n.name))continue;let i=d[n.name],a=typeof i==`string`&&i.trim().length===0,o=M[n.name],s=rr(n,e);if(a&&n.required&&s===void 0&&!(n.sensitive&&o?.has_value)){r[n.name]=t(`pluginManager.variables.required`,`A value is required`);continue}if(Qn(n.name)&&typeof i==`string`&&!a){let e=Xn(i,n.name);e===`invalid-url`?r[n.name]=t(`pluginManager.variables.invalidUrl`,`Enter a valid full API endpoint URL, for example https://provider.example/v1/chat/completions`):e===`insecure-url`?r[n.name]=t(`pluginManager.variables.insecureUrl`,`API endpoints must use HTTP or HTTPS.`):e===`query-or-fragment`&&(r[n.name]=t(`pluginManager.variables.invalidBaseUrl`,`Base URLs cannot contain a query string or fragment.`))}if(n.name===`api_path`&&typeof i==`string`&&i.length>0&&!$n(i)&&(r[n.name]=t(`pluginManager.variables.invalidApiPath`,`Must start with / and contain no URL, query, fragment, or .. segment`)),n.type===`number`&&!a){let e=Number(i);n.min!==void 0&&e<n.min&&(r[n.name]=`Min: ${n.min}`),n.max!==void 0&&e>n.max&&(r[n.name]=`Max: ${n.max}`)}n.type===`string`&&typeof i==`string`&&i.length>2048&&(r[n.name]=t(`pluginManager.variables.tooLong`,`Value is too long`))}if(x(r),Object.keys(r).length>0)return;let i=or(j,d,S,M,e),a=new Set(S),o=Object.fromEntries([...Object.keys(i.variables).map(e=>[e,!0]),...i.unset.map(e=>[e,!0])]);if(Object.keys(i.variables).length===0&&i.unset.length===0){w(e=>{let t=new Set(e);for(let e of a)t.delete(e);return t}),x(e=>{let t={...e};for(let e of a)delete t[e];return t}),V.success(t(`pluginManager.variables.saved`,`Variables saved`));return}m(!0);try{await c(e.id,i.variables,i.unset)?(Object.keys(o).some(e=>A.has(e))&&(await u(),await Promise.all([n.invalidateQueries({queryKey:[`image-gen-data`]}),n.invalidateQueries({queryKey:[`tts-data`]})])),f(e=>{let t={...e};for(let e of j)e.sensitive&&a.has(e.name)&&(t[e.name]=``);return t}),v(e=>{let t=new Set(e);for(let e of j)e.sensitive&&a.has(e.name)&&t.delete(e.name);return t}),w(e=>{let t=new Set(e);for(let e of a)t.delete(e);return t}),x(e=>{let t={...e};for(let e of a)delete t[e];return t}),V.success(t(`pluginManager.variables.saved`,`Variables saved`))):V.error(t(`pluginManager.variables.saveFailed`,`Failed to save variables`))}finally{m(!1)}},te=async()=>{if(await kt({title:t(`pluginManager.variables.resetConfirmTitle`),description:t(`pluginManager.variables.resetConfirmDescription`,{name:e.name}),confirmLabel:t(`pluginManager.variables.resetDefaults`),destructive:!0})){g(!0);try{if(!await l(e.id)){V.error(t(`pluginManager.variables.resetFailed`,`Failed to reset variables`));return}j.some(e=>A.has(e.name))&&(await u(),await Promise.all([n.invalidateQueries({queryKey:[`image-gen-data`]}),n.invalidateQueries({queryKey:[`tts-data`]})])),f(ar(j,{})),w(new Set),x({}),v(new Set),V.success(t(`pluginManager.variables.reset`,`Variables reset to defaults`))}finally{g(!1)}}},ne=(e,t)=>{f(n=>({...n,[e]:t})),w(t=>new Set(t).add(e)),x(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},re=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},L=e=>{let t=j.indexOf(e),n=`${O}-${t}`;return{controlId:n,descriptionId:`${n}-description`,errorId:`${n}-error`,warningId:`${n}-http-warning`}},R=t=>{if(!Qn(t.name))return!1;let n=d[t.name],r=rr(t,e),i=typeof n==`string`&&n.trim()?n:r;return typeof i==`string`&&Zn(i)},z=n=>{let r=d[n.name],i=n.sensitive??!1,a=_.has(n.name),o=M[n.name],{controlId:s,descriptionId:c,errorId:l,warningId:u}=L(n),f=!!b[n.name],m=R(n),g=n.name===`endpoint`||n.name===`api_url`,v=[n.description||g?c:void 0,m?u:void 0,f?l:void 0].filter(Boolean).join(` `)||void 0,y=rr(n,e),x=y===void 0?t(`pluginManager.variables.inherited`,`Use provider default`):t(`pluginManager.variables.inheritedValue`,{defaultValue:`Use provider default ({{value}})`,value:String(y)}),S=C(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-white dark:bg-dark-100`,`border-gray-300 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30`);switch(n.type){case`boolean`:return(0,$.jsxs)(`select`,{id:s,value:r===``?``:String(!!r),onChange:e=>ne(n.name,e.target.value===``?``:e.target.value===`true`),className:S,"aria-invalid":f,"aria-describedby":v,disabled:p||h,children:[(0,$.jsx)(`option`,{value:``,children:x}),(0,$.jsx)(`option`,{value:`true`,children:t(`pluginManager.variables.enabled`,`Enabled`)}),(0,$.jsx)(`option`,{value:`false`,children:t(`pluginManager.variables.disabled`,`Disabled`)})]});case`select`:return(0,$.jsxs)(`select`,{id:s,value:String(r??``),onChange:e=>ne(n.name,e.target.value),className:S,"aria-invalid":f,"aria-describedby":v,disabled:p||h,children:[(0,$.jsx)(`option`,{value:``,children:x}),(n.options||[]).map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))]});case`number`:return(0,$.jsx)(`input`,{id:s,type:`number`,value:r===``?``:Number(r),min:n.min,max:n.max,placeholder:x,onChange:e=>ne(n.name,e.target.value===``?``:Number(e.target.value)),className:S,"aria-invalid":f,"aria-describedby":v,disabled:p||h});default:return(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`input`,{id:s,type:i&&!a?`password`:`text`,value:i&&o?.has_value&&r===``?``:String(r??``),placeholder:i&&o?.has_value?t(`pluginManager.variables.sensitiveSet`,`Value is set (enter new value to change)`):x,onChange:e=>ne(n.name,e.target.value),className:C(S,i&&`pe-10`),"aria-invalid":f,"aria-describedby":v,disabled:p||h}),i&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>re(n.name),"aria-controls":s,"aria-label":a?t(`pluginManager.variables.hideValue`,{defaultValue:`Hide {{label}} value`,label:n.label}):t(`pluginManager.variables.showValue`,{defaultValue:`Show {{label}} value`,label:n.label}),disabled:p||h,className:`absolute inset-e-2 top-1/2 -translate-y-1/2 p-1 text-gray-400 hover:text-gray-600 disabled:cursor-not-allowed disabled:opacity-50 dark:hover:text-gray-300`,children:a?(0,$.jsx)(ae,{className:`w-4 h-4`}):(0,$.jsx)(Ee,{className:`w-4 h-4`})})]})}},ie=e=>{let{controlId:n,descriptionId:r,errorId:i,warningId:a}=L(e),o=e.name===`endpoint`||e.name===`api_url`,s=R(e);return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{htmlFor:n,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:[o?t(`pluginManager.variables.fullApiEndpoint`,`Full API endpoint URL`):e.label,e.required&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-red-500 ms-1`,children:`*`})]}),(e.description||o)&&(0,$.jsxs)(`p`,{id:r,className:`text-xs text-gray-500 dark:text-gray-400 mb-1`,children:[e.description,e.description&&o&&` `,o&&t(`pluginManager.variables.endpointHelp`,`Enter the complete request URL, including its operation path (for example, /v1/chat/completions), not only the provider base URL.`)]}),z(e),s&&(0,$.jsxs)(`p`,{id:a,role:`status`,className:`mt-1 flex items-start gap-1 text-xs text-amber-700 dark:text-amber-400`,children:[(0,$.jsx)(Ue,{"aria-hidden":`true`,className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{children:t(`pluginManager.variables.httpWarning`,`HTTP does not encrypt credentials or traffic. Use it only on a trusted network.`)})]}),b[e.name]&&(0,$.jsx)(`p`,{id:i,role:`alert`,className:`text-xs text-red-500 mt-1`,children:b[e.name]})]},e.name)};return(0,$.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-gray-200 dark:border-gray-700`,children:[P.connection.length>0&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:t(`pluginManager.variables.connection`,`Connection`)}),P.connection.map(ie)]}),P.advanced.length>0&&(0,$.jsxs)(`div`,{className:C(P.connection.length>0&&`mt-4 border-t pt-4`,`border-gray-200 dark:border-gray-700`),children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":T,"aria-controls":D,onClick:()=>E(e=>!e),className:`flex w-full items-center justify-between rounded-md py-1 text-start text-sm font-medium text-gray-700 hover:text-gray-950 dark:text-gray-300 dark:hover:text-white`,children:[(0,$.jsxs)(`span`,{children:[t(`pluginManager.variables.advanced`,`Advanced parameters`),` (`,P.advanced.length,`)`]}),(0,$.jsx)(N,{className:C(`h-4 w-4 transition-transform`,T&&`rotate-180`)})]}),T&&(0,$.jsx)(`div`,{id:D,className:`mt-3 space-y-3`,children:P.advanced.map(ie)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-4`,children:[(0,$.jsxs)(H,{size:`sm`,onClick:ee,disabled:p||h||S.size===0,className:`gap-1.5`,children:[(0,$.jsx)(le,{className:`w-3.5 h-3.5`}),p?t(`pluginManager.variables.saving`,`Saving...`):t(`pluginManager.variables.save`,`Save`)]}),(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:te,disabled:p||h,className:`gap-1.5`,children:[(0,$.jsx)(Pe,{className:`w-3.5 h-3.5`}),t(`pluginManager.variables.resetDefaults`,`Reset to Defaults`)]})]})]})};function cr({plugins:e,loading:t,uploading:n,error:r,hasKeys:i,showUploadForm:a,showJsonForm:o,jsonInput:s,fileInputRef:l,expandedPluginId:u,pluginApiKeys:d,showApiKey:f,savingApiKey:p,refreshingPluginIds:m,onClearError:h,onShowUploadFormChange:g,onShowJsonFormChange:_,onJsonInputChange:b,onFileUpload:x,onJsonSubmit:S,onExpandedPluginChange:C,onPluginApiKeyChange:w,onShowApiKeyChange:T,onActivatePlugin:E,onDeletePlugin:D,onExportPlugin:O,onSaveApiKey:k,onDeleteApiKey:A,onRefreshModels:j}){let{t:N}=y(),P=$t(e=>e.user),F=$t(e=>e.systemInfo)?.requiresAuth===!1||P?.role===`admin`,[I,ee]=(0,Q.useState)(``),[te,ne]=(0,Q.useState)(null),re=(0,Q.useId)(),L=(0,Q.useMemo)(()=>e.filter(e=>c(e,I)),[e,I]),R=te&&e.some(e=>e.id===te)?te:e[0]?.id??null,z=e.find(e=>e.id===R)??null,ie=e=>{e!==R&&(C(null),ne(e))};return(0,$.jsx)(`div`,{className:`space-y-6`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Dn,{title:N(`settings.plugins.providerConnections`,{defaultValue:`Provider connections`}),description:N(`settings.plugins.providerConnectionsDescription`,{defaultValue:`Connect, configure, and inspect model providers through plugins.`})}),r&&(0,$.jsx)(`div`,{role:`alert`,className:`p-4 bg-error-50 dark:bg-error-900/20 border border-error-200 dark:border-error-800/60 rounded-lg mb-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`p`,{className:`text-error-800 dark:text-error-200`,children:r}),(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:h,"aria-label":N(`settings.plugins.dismissError`),className:`text-error-800 hover:text-error-900 dark:text-error-200 dark:hover:text-error-100`,children:(0,$.jsx)(Ye,{className:`h-4 w-4`})})]})}),F&&(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300 mb-6`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:N(`settings.plugins.addNew`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>g(!a),disabled:t||n,children:[(0,$.jsx)(Qe,{className:`h-4 w-4 me-2`}),N(`settings.plugins.upload`)]}),(0,$.jsx)(H,{variant:`outline`,size:`sm`,onClick:()=>_(!o),disabled:t,children:N(`settings.plugins.addJson`)})]})]}),a&&(0,$.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300 mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(`input`,{ref:l,type:`file`,accept:`.json,.zip`,"aria-label":N(`settings.plugins.upload`),onChange:x,className:`flex-1 p-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-100 text-gray-900 dark:text-dark-800 file:me-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-medium file:bg-gray-100 file:text-gray-700 dark:file:bg-dark-200 dark:file:text-dark-700 hover:file:bg-gray-200 dark:hover:file:bg-dark-300`,disabled:n}),(0,$.jsx)(H,{variant:`outline`,size:`sm`,onClick:()=>g(!1),disabled:n,children:N(`common.cancel`)})]}),n&&(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-2`,children:N(`settings.plugins.uploading`)})]}),o&&(0,$.jsx)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`textarea`,{value:s,onChange:e=>b(e.target.value),placeholder:N(`settings.plugins.jsonPlaceholder`),"aria-label":N(`settings.plugins.addJson`),className:`w-full h-32 p-3 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-100 text-gray-900 dark:text-dark-800 placeholder:text-ink-muted font-mono text-sm`,disabled:t}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(H,{variant:`outline`,size:`sm`,onClick:()=>{_(!1),b(``)},children:N(`common.cancel`)}),(0,$.jsx)(H,{size:`sm`,onClick:S,disabled:!s.trim()||t,children:N(`settings.plugins.install`)})]})]})})]}),(0,$.jsx)(`div`,{"data-testid":`provider-workspace`,className:`overflow-hidden rounded-xl border border-gray-200 bg-white dark:border-dark-300 dark:bg-dark-100`,children:(0,$.jsxs)(`div`,{className:`grid min-h-120 grid-cols-1 lg:grid-cols-[minmax(15rem,0.8fr)_minmax(0,1.6fr)]`,children:[(0,$.jsxs)(`section`,{"data-testid":`provider-list`,"aria-label":N(`settings.plugins.providers`,{defaultValue:`Providers`}),className:`border-b border-gray-200 dark:border-dark-300 lg:flex lg:min-h-0 lg:flex-col lg:border-b-0 lg:border-e`,children:[(0,$.jsxs)(`div`,{className:`border-b border-gray-200 p-4 dark:border-dark-300`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:N(`settings.plugins.providers`,{defaultValue:`Providers`})}),(0,$.jsx)(`span`,{className:`rounded-full bg-gray-100 px-2 py-0.5 text-xs text-gray-600 dark:bg-dark-200 dark:text-gray-300`,children:e.length})]}),(0,$.jsx)(`label`,{htmlFor:re,className:`sr-only`,children:N(`settings.plugins.searchProviders`,{defaultValue:`Search providers`})}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(oe,{"aria-hidden":`true`,className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,$.jsx)(`input`,{id:re,type:`search`,value:I,onChange:e=>ee(e.target.value),placeholder:N(`settings.plugins.searchProviders`,{defaultValue:`Search providers`}),className:`w-full rounded-lg border border-gray-300 bg-white py-2 pe-3 ps-9 text-sm text-gray-900 placeholder:text-ink-muted focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50 dark:text-gray-100`})]})]}),(0,$.jsx)(`div`,{className:`max-h-128 space-y-2 overflow-y-auto p-3 lg:min-h-0 lg:max-h-none lg:flex-1`,children:t&&e.length===0?(0,$.jsx)(Et,{size:`sm`,label:N(`settings.plugins.loading`)}):e.length===0?(0,$.jsx)(Ot,{icon:M,size:`sm`,title:N(`settings.plugins.noPlugins`),description:N(`settings.plugins.noPluginsDescription`)}):L.length===0?(0,$.jsx)(Ot,{icon:de,size:`sm`,title:N(`settings.plugins.noProvidersFound`,{defaultValue:`No providers match your search.`})}):L.map(e=>{let t=R===e.id,n=v(e).length;return(0,$.jsx)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:()=>ie(e.id),className:`w-full rounded-xl border p-3 text-start transition-colors ${t?`border-blue-500 bg-blue-50/70 dark:border-blue-500 dark:bg-blue-950/20`:`border-gray-200 hover:border-gray-300 hover:bg-gray-50 dark:border-dark-300 dark:hover:border-dark-400 dark:hover:bg-dark-50`}`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`mt-1.5 h-2.5 w-2.5 shrink-0 rounded-full ${e.active?`bg-green-500`:`bg-gray-400 dark:bg-gray-500`}`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`span`,{className:`sr-only`,children:[e.active?N(`settings.plugins.activeLabel`):N(`settings.plugins.inactive`),`.`,` `]}),(0,$.jsx)(`span`,{className:`block truncate text-sm font-medium text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`span`,{className:`mt-0.5 block text-xs capitalize text-gray-500 dark:text-gray-400`,children:[e.type,` · `,n,` `,N(`settings.plugins.models`)]})]})]})},e.id)})})]}),(0,$.jsx)(`section`,{"data-testid":`provider-detail`,className:`min-w-0 p-4 sm:p-5`,children:z?(0,$.jsx)(lr,{plugin:z,loading:t,hasApiKey:i[z.id]||!1,expanded:u===z.id,apiKey:d[z.id]||``,showApiKey:f[z.id]||!1,savingApiKey:p===z.id,refreshingModels:!!m[z.id],canManagePlugin:F,onExpand:()=>C(u===z.id?null:z.id),onActivate:()=>E(z.id),onExport:()=>O(z.id),onDelete:()=>D(z.id),onRefreshModels:()=>j(z.id),onApiKeyChange:e=>w(z.id,e),onShowApiKeyChange:e=>T(z.id,e),onSaveApiKey:()=>k(z.id),onDeleteApiKey:()=>A(z.id)}):(0,$.jsx)(`div`,{className:`flex min-h-96 items-center justify-center text-center`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(M,{className:`mx-auto mb-3 h-10 w-10 text-gray-400`}),(0,$.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:N(`settings.plugins.selectProvider`,{defaultValue:`Select a provider`})}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-gray-400`,children:N(`settings.plugins.selectProviderDescription`,{defaultValue:`Choose a provider to inspect its connection and model catalog.`})})]})})})]})})]})})}function lr({plugin:e,loading:t,hasApiKey:n,expanded:r,apiKey:i,showApiKey:a,savingApiKey:o,refreshingModels:s,canManagePlugin:c,onExpand:l,onActivate:u,onExport:d,onDelete:f,onRefreshModels:p,onApiKeyChange:m,onShowApiKeyChange:h,onSaveApiKey:g,onDeleteApiKey:b}){let{t:x}=y(),S=!!(e.auth?.header||e.auth?.key_env),C=tr(e),w=c?e.variables||[]:(e.variables||[]).filter(e=>!C.has(e.name)),T=w.length>0,E=S||T,D=(0,Q.useId)(),O=v(e),k=e.base_url||e.endpoint;return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 border-b border-gray-200 pb-4 dark:border-dark-300`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-full ${e.active?`bg-green-500`:`bg-gray-400 dark:bg-gray-500`}`}),(0,$.jsx)(`h4`,{className:`truncate text-lg font-semibold text-gray-900 dark:text-gray-100`,children:e.name})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-gray-400`,children:[e.id,` · `,(0,$.jsx)(`span`,{className:`capitalize`,children:e.type}),S&&n&&(0,$.jsxs)(`span`,{className:`text-green-600`,children:[` `,`· `,x(`settings.plugins.apiKeySet`)]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[E&&(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:l,"aria-expanded":r,"aria-controls":D,title:x(`settings.plugins.configure`),className:n?`text-green-600`:``,children:[S?(0,$.jsx)(B,{className:`h-4 w-4`}):(0,$.jsx)(ge,{className:`h-4 w-4`}),x(`settings.plugins.configure`),r?(0,$.jsx)(Ne,{className:`h-3 w-3`}):(0,$.jsx)(N,{className:`h-3 w-3`})]}),(0,$.jsx)(H,{variant:`outline`,size:`sm`,onClick:u,disabled:t,className:e.active?`border-green-300 text-green-600`:``,children:e.active?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ve,{className:`h-4 w-4`}),x(`settings.plugins.deactivate`)]}):x(`settings.plugins.activate`)}),c&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:d,disabled:t,title:x(`settings.plugins.exportPlugin`,`Export plugin`),"aria-label":x(`settings.plugins.exportPlugin`,`Export plugin`),className:`px-2`,children:(0,$.jsx)(F,{className:`h-4 w-4`})}),(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:f,disabled:t,className:`px-2 text-error-700 hover:bg-error-500/10 hover:text-error-800 dark:text-error-400 dark:hover:text-error-300`,title:x(`settings.plugins.deletePlugin`,`Delete plugin`),"aria-label":x(`settings.plugins.deletePlugin`,`Delete plugin`),children:(0,$.jsx)(pt,{className:`h-4 w-4`})})]})]})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,$.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:x(`settings.plugins.status`,{defaultValue:`Status`})}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-gray-900 dark:text-gray-100`,children:e.active?x(`settings.plugins.activeLabel`):x(`settings.plugins.inactive`)})]}),(0,$.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:x(`settings.plugins.models`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-gray-900 dark:text-gray-100`,children:O.length})]}),(0,$.jsxs)(`div`,{className:`min-w-0 rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400`,children:x(`settings.plugins.defaultEndpoint`,{defaultValue:`Default endpoint`})}),(0,$.jsx)(`p`,{className:`mt-1 truncate text-sm text-gray-900 dark:text-gray-100`,title:k,children:k})]})]})]}),r&&E&&(0,$.jsxs)(`div`,{id:D,children:[S&&(0,$.jsx)(dr,{plugin:e,hasApiKey:n,apiKey:i,showApiKey:a,savingApiKey:o,onApiKeyChange:m,onShowApiKeyChange:h,onSaveApiKey:g,onDeleteApiKey:b}),T&&(0,$.jsxs)(`div`,{className:`mt-4 rounded-lg border border-gray-200 bg-gray-50 p-4 dark:border-dark-300 dark:bg-dark-50`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,$.jsx)(ge,{className:`h-4 w-4 text-gray-500`}),(0,$.jsxs)(`h5`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:[x(`settings.plugins.providerSettings`),` (`,w.length,`)`]})]}),(0,$.jsx)(sr,{plugin:e},e.id)]})]}),(0,$.jsx)(ur,{catalog:O,canRefresh:_(e),refreshing:s,onRefresh:p})]})}function ur({catalog:e,canRefresh:t,refreshing:n,onRefresh:r}){let{t:i}=y();return(0,$.jsxs)(`section`,{"data-testid":`provider-model-catalog`,className:`mt-5`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h5`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:i(`settings.plugins.modelCatalog`,{defaultValue:`Model catalog`})}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:i(`settings.plugins.modelCatalogDescription`,{defaultValue:`Discovered and configured models for this provider and its capabilities.`})})]}),t&&(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:r,disabled:n,"aria-busy":n,children:[n?(0,$.jsx)(Ce,{className:`h-4 w-4 animate-spin`}):(0,$.jsx)(be,{className:`h-4 w-4`}),i(`settings.plugins.refreshModels`,{defaultValue:`Refresh models`})]})]}),e.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-dashed border-gray-300 p-6 text-center text-sm text-gray-500 dark:border-dark-300 dark:text-gray-400`,children:i(`settings.plugins.noModelsConfigured`,{defaultValue:`No models are configured for this provider.`})}):(0,$.jsx)(`div`,{className:`max-h-104 overflow-auto rounded-lg border border-gray-200 dark:border-dark-300`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[24rem] text-start text-sm`,children:[(0,$.jsx)(`thead`,{className:`sticky top-0 z-10 bg-gray-50 text-xs uppercase tracking-wide text-gray-500 dark:bg-dark-50 dark:text-gray-400`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-start font-medium`,children:i(`settings.plugins.modelId`,{defaultValue:`Model ID`})}),(0,$.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-start font-medium`,children:i(`settings.plugins.capabilities`,{defaultValue:`Capabilities`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-gray-200 dark:divide-dark-300`,children:e.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`px-3 py-2.5 font-mono text-xs text-gray-900 dark:text-gray-100`,children:e.id}),(0,$.jsx)(`td`,{className:`px-3 py-2.5`,children:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.capabilities.map(e=>(0,$.jsx)(`span`,{className:`rounded-md bg-blue-50 px-2 py-0.5 text-xs text-blue-700 dark:bg-blue-950/30 dark:text-blue-300`,children:i(`settings.plugins.capability.${e.toLowerCase()}`,{defaultValue:e})},e))})})]},e.id))})]})})]})}function dr({plugin:e,hasApiKey:t,apiKey:n,showApiKey:r,savingApiKey:i,onApiKeyChange:a,onShowApiKeyChange:o,onSaveApiKey:s,onDeleteApiKey:c}){let{t:l}=y(),u=(0,Q.useId)();return(0,$.jsxs)(`div`,{className:`mt-4 p-4 bg-gray-50 dark:bg-dark-50 rounded-lg border border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,$.jsx)(B,{className:`h-4 w-4 text-gray-500`}),(0,$.jsx)(`h6`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:l(`settings.plugins.apiKeyConfiguration`)})]}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-3`,children:[l(`settings.plugins.apiKeyDescription`,{name:e.name,defaultValue:`Store a personal API key for {{name}}.`}),e.auth?.key_env&&(0,$.jsxs)(`span`,{className:`block mt-1`,children:[l(`settings.plugins.apiKeyEnvAlternative`),` `,(0,$.jsx)(`code`,{className:`bg-gray-200 dark:bg-dark-200 px-1 rounded-sm`,children:e.auth.key_env}),` `,l(`settings.plugins.environmentVariable`),`.`]})]}),t?(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{className:`h-4 w-4 text-green-600`}),(0,$.jsx)(`span`,{className:`text-sm text-green-700 dark:text-green-300`,children:l(`settings.plugins.apiKeyConfigured`)})]}),(0,$.jsx)(H,{variant:`danger`,size:`sm`,onClick:c,disabled:i,children:i?(0,$.jsx)(Ce,{className:`h-4 w-4 animate-spin`}):l(`common.remove`)})]}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`label`,{htmlFor:u,className:`sr-only`,children:l(`settings.plugins.apiKey.title`)}),(0,$.jsx)(`input`,{id:u,type:r?`text`:`password`,value:n,onChange:e=>a(e.target.value),placeholder:l(`settings.plugins.apiKeyPlaceholder`),disabled:i,className:`w-full p-2 pe-10 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-100 text-gray-900 dark:text-dark-800 placeholder:text-ink-muted`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>o(!r),"aria-controls":u,"aria-label":l(r?`settings.plugins.hideApiKey`:`settings.plugins.showApiKey`),disabled:i,className:`absolute inset-e-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 disabled:cursor-not-allowed disabled:opacity-50`,children:r?(0,$.jsx)(ae,{className:`h-4 w-4`}):(0,$.jsx)(Ee,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(H,{size:`sm`,onClick:s,disabled:i||!n.trim(),children:i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ce,{className:`h-4 w-4 me-2 animate-spin`}),l(`common.saving`)]}):l(`settings.plugins.saveApiKey`)})})]})]})}var fr=()=>{let{t:e}=y(),t=(0,Q.useId)(),n=(0,Q.useId)(),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(`6`),[l,u]=(0,Q.useState)(!0),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1;return qt.getConfig().then(t=>{!e&&t.success&&t.data&&(i(t.data.enabled),o(t.data.url??``),typeof t.data.maxResults==`number`&&c(String(t.data.maxResults)),typeof t.data.safeSearch==`boolean`&&u(t.data.safeSearch),f(!0))}).catch(()=>{}),()=>{e=!0}},[]);let _=async(t=r)=>{let n=Number(s);if(!Number.isInteger(n)||n<1||n>100){R.error(e(`settings.search.maxResultsInvalid`));return}m(!0);try{let r=await qt.setConfig(t,a.trim(),{maxResults:n,safeSearch:l});if(!r.success||!r.data)throw Error(r.error||e(`settings.search.saveFailed`));i(r.data.enabled),o(r.data.url??``),typeof r.data.maxResults==`number`&&c(String(r.data.maxResults)),typeof r.data.safeSearch==`boolean`&&u(r.data.safeSearch),R.success(e(`settings.search.saved`))}catch(t){R.error(t instanceof Error&&t.message?t.message:e(`settings.search.saveFailed`))}finally{m(!1)}},v=async()=>{g(!0);try{let t=await qt.test();if(!t.success||!t.data?.ok)throw Error(t.error||e(`settings.search.testFailed`));R.success(e(`settings.search.testOk`,{results:t.data.results}))}catch(t){R.error(t instanceof Error&&t.message?t.message:e(`settings.search.testFailed`))}finally{g(!1)}};return(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsx)(Dn,{className:`mb-0`,title:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(at,{className:`h-5 w-5 text-primary-500`}),e(`settings.search.title`)]}),description:e(`settings.search.description`)}),(0,$.jsx)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{id:t,className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.search.enableLabel`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:e(`settings.search.enableDescription`)})]}),(0,$.jsx)(X,{checked:r,onChange:e=>{i(e),_(e)},disabled:p||!d||!r&&!a.trim(),"aria-labelledby":t})]})}),(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 space-y-3`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.search.urlLabel`)}),(0,$.jsx)(`span`,{className:`mb-2 block text-xs text-gray-500 dark:text-gray-400`,children:e(`settings.search.urlDescription`)}),(0,$.jsx)(wt,{value:a,onChange:e=>o(e.target.value),placeholder:`http://searxng:8080`,spellCheck:!1,dir:`ltr`})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.search.maxResultsLabel`)}),(0,$.jsx)(`span`,{className:`mb-2 block text-xs text-gray-500 dark:text-gray-400`,children:e(`settings.search.maxResultsDescription`)}),(0,$.jsx)(wt,{type:`number`,min:1,max:100,value:s,onChange:e=>c(e.target.value),dir:`ltr`})]}),(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4 sm:pt-1`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{id:n,className:`mb-1 block text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.search.safeSearchLabel`)}),(0,$.jsx)(`span`,{className:`block text-xs text-gray-500 dark:text-gray-400`,children:e(`settings.search.safeSearchDescription`)})]}),(0,$.jsx)(X,{checked:l,onChange:u,disabled:p||!d,"aria-labelledby":n})]})]}),(0,$.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>void v(),disabled:h||p||!r,children:e(h?`settings.search.testing`:`settings.search.test`)}),(0,$.jsx)(H,{size:`sm`,onClick:()=>void _(),disabled:p||!d,children:e(`settings.search.save`)})]})]})]})},pr=e=>e.response?.data?.message,mr=e=>e?new Date(e).toLocaleString():`—`,hr=()=>{let{t:e}=y(),t=(0,Q.useId)(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),g=(0,Q.useCallback)(async()=>{a(!0);try{let e=await Mt.getMfaStatus();e.success&&e.data&&r(e.data)}catch{}finally{a(!1)}},[]);(0,Q.useEffect)(()=>{let e=setTimeout(()=>void g(),0);return()=>clearTimeout(e)},[g]);let _=async()=>{s(!0);try{let t=await Mt.mfaEnroll();t.success&&t.data?(l(t.data),d(``)):R.error(t.message||e(`auth.mfa.enrollFailed`))}catch(t){R.error(pr(t)||e(`auth.mfa.enrollFailed`))}finally{s(!1)}},v=async t=>{if(t.preventDefault(),u.trim()){s(!0);try{let t=await Mt.mfaActivate({code:u.trim()});t.success&&t.data?(l(null),p(t.data.recoveryCodes),R.success(e(`auth.mfa.enabled`)),await g()):R.error(t.message||e(`auth.mfa.invalidCode`))}catch(t){R.error(pr(t)||e(`auth.mfa.invalidCode`))}finally{d(``),s(!1)}}},b=async t=>{if(t.preventDefault(),u.trim()&&m){s(!0);try{if(m===`disable`){let t=await Mt.mfaDisable({code:u.trim()});t.success?(R.success(e(`auth.mfa.disabled`)),p(null)):R.error(t.message||e(`auth.mfa.invalidCode`))}else{let t=await Mt.mfaRegenerateRecoveryCodes({code:u.trim()});t.success&&t.data?(p(t.data.recoveryCodes),R.success(e(`auth.mfa.recoveryCodesRegenerated`))):R.error(t.message||e(`auth.mfa.invalidCode`))}h(null),await g()}catch(t){R.error(pr(t)||e(`auth.mfa.invalidCode`))}finally{d(``),s(!1)}}},x=async()=>{s(!0);try{let t=await Mt.passkeyRegisterOptions();if(!t.success||!t.data){R.error(t.message||e(`auth.passkeys.registerFailed`));return}let n=await sn(t.data.publicKey),r=await Mt.passkeyRegister({challengeToken:t.data.challengeToken,credential:n});r.success?(R.success(e(`auth.passkeys.registered`)),await g()):R.error(r.message||e(`auth.passkeys.registerFailed`))}catch(t){let n=t;if(n.name===`NotAllowedError`||n.name===`AbortError`)return;R.error(pr(t)||e(`auth.passkeys.registerFailed`))}finally{s(!1)}},S=async(t,n)=>{if(await kt({title:e(`auth.passkeys.removeConfirmTitle`),description:e(`auth.passkeys.removeConfirmDescription`,{name:n}),confirmLabel:e(`auth.passkeys.removeButton`),destructive:!0})){s(!0);try{let n=await Mt.deletePasskey(t);n.success?(R.success(e(`auth.passkeys.removed`)),await g()):R.error(n.message||e(`auth.passkeys.removeFailed`))}catch(t){R.error(pr(t)||e(`auth.passkeys.removeFailed`))}finally{s(!1)}}};if(i||!n)return null;let C=`h-9 w-40 rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 px-3 text-sm text-gray-900 dark:text-gray-100 outline-hidden focus:ring-2 focus:ring-primary-500/35`;return(0,$.jsxs)(`div`,{className:`space-y-6`,"data-testid":`settings-mfa-section`,children:[(0,$.jsx)(Dn,{className:`mb-0`,title:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(yt,{className:`h-5 w-5 text-primary-500`}),e(`auth.mfa.sectionTitle`)]}),description:e(`auth.mfa.sectionDescription`)}),(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`auth.mfa.totpTitle`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:n.totpEnabled?e(`auth.mfa.totpEnabledHint`,{count:n.recoveryCodesRemaining}):e(`auth.mfa.totpDisabledHint`)})]}),n.totpEnabled?(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(H,{size:`sm`,variant:`outline`,disabled:o,onClick:()=>{h(`regenerate`),d(``)},children:e(`auth.mfa.regenerateCodes`)}),(0,$.jsx)(H,{size:`sm`,variant:`outline`,disabled:o,onClick:()=>{h(`disable`),d(``)},children:e(`auth.mfa.disableButton`)})]}):!c&&(0,$.jsx)(H,{size:`sm`,disabled:o,onClick:_,children:e(`auth.mfa.enableButton`)})]}),c&&(0,$.jsxs)(`form`,{onSubmit:v,className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`auth.mfa.secretHint`)}),(0,$.jsx)(`code`,{dir:`ltr`,className:`block break-all rounded-lg bg-gray-50 dark:bg-dark-200 p-3 font-mono text-sm text-gray-900 dark:text-gray-100`,children:c.secret}),(0,$.jsx)(`a`,{href:c.otpauthUrl,dir:`ltr`,className:`inline-block text-xs font-medium text-primary-600 hover:text-primary-700 dark:text-primary-400`,children:e(`auth.mfa.openAuthenticator`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,dir:`ltr`,value:u,onChange:e=>d(e.target.value),placeholder:e(`auth.mfa.codePlaceholder`),"aria-label":e(`auth.mfa.codeLabel`),className:C}),(0,$.jsx)(H,{size:`sm`,type:`submit`,disabled:o||!u.trim(),children:e(`auth.mfa.activateButton`)}),(0,$.jsx)(H,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>l(null),children:e(`common.cancel`)})]})]}),m&&(0,$.jsxs)(`form`,{onSubmit:b,className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`label`,{htmlFor:t,className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`auth.mfa.confirmWithCode`)}),(0,$.jsx)(`input`,{id:t,type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,dir:`ltr`,value:u,onChange:e=>d(e.target.value),placeholder:e(`auth.mfa.codePlaceholder`),className:C}),(0,$.jsx)(H,{size:`sm`,type:`submit`,disabled:o||!u.trim(),children:e(m===`disable`?`auth.mfa.disableButton`:`auth.mfa.regenerateCodes`)}),(0,$.jsx)(H,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>h(null),children:e(`common.cancel`)})]}),f&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100`,children:e(`auth.mfa.recoveryCodesTitle`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`auth.mfa.recoveryCodesHint`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-2 rounded-lg bg-gray-50 dark:bg-dark-200 p-3 font-mono text-sm text-gray-900 dark:text-gray-100`,children:f.map(e=>(0,$.jsx)(`span`,{dir:`ltr`,children:e},e))}),(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>p(null),children:e(`auth.mfa.recoveryCodesSaved`)})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-sm font-medium text-gray-900 dark:text-gray-100`,children:[(0,$.jsx)(pe,{className:`h-4 w-4 text-primary-500`}),e(`auth.passkeys.sectionTitle`)]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:e(`auth.passkeys.sectionDescription`)})]}),on()&&(0,$.jsx)(H,{size:`sm`,disabled:o,onClick:x,children:e(`auth.passkeys.addButton`)})]}),n.passkeys.length===0?(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`auth.passkeys.empty`)}):(0,$.jsx)(`div`,{className:`space-y-2`,children:n.passkeys.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-gray-50 dark:bg-dark-200 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`truncate text-sm text-gray-900 dark:text-gray-100`,children:t.name||e(`auth.passkeys.unnamed`)}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`auth.passkeys.createdAt`),`:`,` `,mr(t.createdAt),` · `,e(`auth.passkeys.lastUsedAt`),`:`,` `,mr(t.lastUsedAt)]})]}),(0,$.jsx)(H,{size:`sm`,variant:`ghost`,disabled:o,onClick:()=>void S(t.id,t.name||e(`auth.passkeys.unnamed`)),"aria-label":e(`auth.passkeys.removeButton`),children:(0,$.jsx)(pt,{className:`h-4 w-4`})})]},t.id))})]})]})},gr=e=>e?new Date(e).toLocaleString():`—`,_r=()=>{let{t:e}=y(),[t,n]=(0,Q.useState)([]),[r,i]=(0,Q.useState)(!0),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1),d=(0,Q.useCallback)(async()=>{i(!0),o(!1);try{let e=await Mt.getSessions();if(!e.success||!e.data)throw Error(e.error||`Failed to load sessions.`);n(e.data)}catch{o(!0)}finally{i(!1)}},[]);(0,Q.useEffect)(()=>{let e=setTimeout(()=>void d(),0);return()=>clearTimeout(e)},[d]);let f=async t=>{if(await kt({title:e(`settings.sessions.signOutConfirmTitle`),description:e(`settings.sessions.signOutConfirmDescription`,{device:t.userAgent||e(`settings.sessions.unknownDevice`)}),confirmLabel:e(`settings.sessions.signOut`),destructive:!0})){c(t.id);try{let n=await Mt.revokeSession(t.id);if(!n.success)throw Error(n.error||e(`settings.sessions.revokeFailed`));R.success(e(`settings.sessions.revoked`,`Session signed out.`)),await d()}catch(t){R.error(t instanceof Error&&t.message?t.message:e(`settings.sessions.revokeFailed`,`The session could not be signed out.`))}finally{c(null)}}},p=async()=>{if(await kt({title:e(`settings.sessions.signOutOthersConfirmTitle`),description:e(`settings.sessions.signOutOthersConfirmDescription`,{count:m.length}),confirmLabel:e(`settings.sessions.signOutOthers`),destructive:!0})){u(!0);try{let t=await Mt.revokeOtherSessions();if(!t.success||!t.data)throw Error(t.error||e(`settings.sessions.revokeFailed`));R.success(e(`settings.sessions.othersRevoked`,{count:t.data.revokedCount,defaultValue:`Other sessions signed out: {{count}}`})),await d()}catch(t){R.error(t instanceof Error&&t.message?t.message:e(`settings.sessions.revokeFailed`,`The session could not be signed out.`))}finally{u(!1)}}},m=t.filter(e=>!e.current&&!e.revokedAt);return(0,$.jsxs)(`div`,{className:`space-y-8`,children:[(0,$.jsx)(hr,{}),(0,$.jsx)(Dn,{className:`mb-0`,title:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(gt,{className:`h-5 w-5 text-primary-500`}),e(`settings.sessions.title`,`Sessions`)]}),description:e(`settings.sessions.description`,`Everywhere this account is signed in. Signing a session out takes effect immediately; signing in again restores access.`)}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>void p(),disabled:l||r||m.length===0,children:l?e(`settings.sessions.signingOutOthers`,`Signing out…`):e(`settings.sessions.signOutOthers`,`Sign out other sessions`)})}),r?(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`common.loading`)}):a?(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 flex items-center justify-between gap-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`settings.sessions.loadFailed`,`The sessions could not be loaded.`)}),(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>void d(),children:e(`common.retry`)})]}):t.length===0?(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`settings.sessions.empty`,`No sessions found.`)}):(0,$.jsx)(`div`,{className:`space-y-3`,children:t.map(t=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:t.kind}),t.current&&(0,$.jsx)(`span`,{className:`rounded-full bg-primary-100 dark:bg-primary-900/30 px-2 py-0.5 text-xs font-medium text-primary-700 dark:text-primary-300`,children:e(`settings.sessions.current`,`This session`)}),t.revokedAt&&(0,$.jsx)(`span`,{className:`rounded-full bg-gray-100 dark:bg-dark-200 px-2 py-0.5 text-xs font-medium text-gray-500 dark:text-gray-400`,children:e(`settings.sessions.revokedBadge`,`Signed out`)})]}),(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs text-gray-500 dark:text-gray-400`,children:t.userAgent||e(`settings.sessions.unknownDevice`,`Unknown device`)}),(0,$.jsxs)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-gray-400`,children:[e(`settings.sessions.createdAt`,`Signed in`),`:`,` `,gr(t.createdAt),` · `,e(`settings.sessions.lastSeenAt`,`Last active`),`:`,` `,gr(t.lastSeenAt),t.expiresAt&&(0,$.jsxs)($.Fragment,{children:[` · `,e(`settings.sessions.expiresAt`,`Expires`),`:`,` `,gr(t.expiresAt)]})]})]}),!t.current&&!t.revokedAt&&(0,$.jsx)(`div`,{className:`shrink-0`,children:(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>void f(t),disabled:s===t.id||l,children:s===t.id?e(`settings.sessions.signingOut`,`Signing out…`):e(`settings.sessions.signOut`,`Sign out`)})})]},t.id))})]})},vr={getPublicKey:()=>K.get(`/push/public-key`).then(e=>e.data),listSubscriptions:()=>K.get(`/push/subscriptions`).then(e=>e.data),subscribe:e=>K.post(`/push/subscriptions`,e).then(e=>e.data),unsubscribe:e=>K.delete(`/push/subscriptions`,{data:{endpoint:e}}).then(e=>e.data)},yr=o(`components:settings-notifications`),br=()=>typeof window<`u`&&`serviceWorker`in navigator&&`PushManager`in window&&`Notification`in window,xr=e=>{let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r=atob(n),i=new Uint8Array(new ArrayBuffer(r.length));for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i},Sr=()=>{let{t:e}=y(),t=(0,Q.useId)(),n=(0,Q.useId)(),[r]=(0,Q.useState)(br),[i,a]=(0,Q.useState)(typeof Notification<`u`?Notification.permission:`denied`),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=A(e=>e.preferences.emailNotifications),p=A(e=>e.setPreferences),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=!1;return At.getSettings().then(t=>{e||(t.success&&t.data?h(t.data):_(!0))}).catch(()=>{e||_(!0)}),()=>{e=!0}},[]);let x=async(t,n)=>{let r={channelMentions:f?.channelMentions===!0,automationRuns:f?.automationRuns===!0},i={...r,[t]:n};b(t),p({emailNotifications:i});try{let e=await q.updatePreferences({emailNotifications:i});if(!e.success)throw Error(e.error||`update failed`)}catch(t){p({emailNotifications:r}),R.error(e(`settings.preferences.updateFailed`,{error:t instanceof Error?t.message:String(t)}))}finally{b(null)}},S=(0,Q.useCallback)(async()=>{if(r)try{let e=await navigator.serviceWorker.getRegistration();if(!e){d(!1),s(!1);return}d(!0);let t=await e.pushManager.getSubscription();s(!!t)}catch(e){yr.debug(`Push state read failed`,e)}},[r]);(0,Q.useEffect)(()=>{let e=setTimeout(()=>void S(),0);return()=>clearTimeout(e)},[S]);let C=async()=>{let t=await navigator.serviceWorker.getRegistration();if(!t){R.error(e(`settings.notifications.workerMissing`));return}let n=await Notification.requestPermission();if(a(n),n!==`granted`){R.error(e(`settings.notifications.permissionDenied`));return}let r=await vr.getPublicKey();if(!r.success||!r.data){R.error(r.message||e(`settings.notifications.enableFailed`));return}let i=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:xr(r.data.publicKey)}),o=await vr.subscribe(i.toJSON());if(!o.success){await i.unsubscribe().catch(()=>void 0),R.error(o.message||e(`settings.notifications.enableFailed`));return}s(!0),R.success(e(`settings.notifications.enabled`))},w=async()=>{let t=await(await navigator.serviceWorker.getRegistration())?.pushManager.getSubscription();t&&(await vr.unsubscribe(t.endpoint).catch(()=>void 0),await t.unsubscribe().catch(()=>void 0)),s(!1),R.success(e(`settings.notifications.disabled`))},T=async t=>{l(!0);try{t?await C():await w()}catch(t){yr.error(`Push toggle failed`,t),R.error(e(`settings.notifications.enableFailed`))}finally{l(!1)}},E=g?e(`settings.notifications.emailLoadFailed`):m===null?null:m.available?m.recipient?null:e(`settings.notifications.emailNoAddress`):e(`settings.notifications.emailUnavailable`),D=m?.recipient?e(`settings.notifications.emailHint`,{address:m.recipient}):e(`settings.notifications.emailLoading`),O=r?u?i===`denied`?e(`settings.notifications.permissionDenied`):null:e(`settings.notifications.workerMissing`):e(`settings.notifications.unsupported`);return(0,$.jsxs)(`div`,{className:`space-y-6`,"data-testid":`settings-notifications-tab`,children:[(0,$.jsx)(Dn,{className:`mb-0`,title:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Je,{className:`h-5 w-5 text-primary-500`}),e(`settings.notifications.title`)]}),description:e(`settings.notifications.description`)}),(0,$.jsx)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{id:t,className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.notifications.pushTitle`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:O??e(`settings.notifications.pushHint`)})]}),(0,$.jsx)(X,{checked:o,disabled:c||!(!O||o),onChange:T,"aria-labelledby":t})]})}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`settings.notifications.deviceNote`)}),(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 space-y-4`,"data-testid":`settings-email-notifications`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-sm font-medium text-gray-900 dark:text-gray-100`,children:[(0,$.jsx)(ve,{className:`h-4 w-4 text-primary-500`}),e(`settings.notifications.emailTitle`)]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:E??D})]}),[[`channelMentions`,`emailMentions`,`emailMentionsHint`],[`automationRuns`,`emailAutomations`,`emailAutomationsHint`]].map(([t,r,i])=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,"data-testid":`settings-email-${t}`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{id:`${n}-${t}`,className:`text-sm text-gray-900 dark:text-gray-100`,children:e(`settings.notifications.${r}`)}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:e(`settings.notifications.${i}`)})]}),(0,$.jsx)(X,{checked:f?.[t]===!0,disabled:v!==null||!!E&&f?.[t]!==!0,onChange:e=>void x(t,e),"aria-labelledby":`${n}-${t}`})]},t))]})]})},Cr=e=>e?new Date(e).toLocaleString():`—`,wr=()=>{let{t:e}=y(),t=$t(e=>e.isAdmin)(),[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(null),x=jt.filter(e=>e!==`admin`||t),S=(0,Q.useCallback)(async()=>{a(!0),s(!1);try{let e=await Mt.listApiTokens();if(!e.success||!e.data)throw Error(e.error||`Failed to load API keys.`);r(e.data)}catch{s(!0)}finally{a(!1)}},[]);(0,Q.useEffect)(()=>{let e=setTimeout(()=>void S(),0);return()=>clearTimeout(e)},[S]);let C=e=>{p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},w=async t=>{if(t.preventDefault(),!u.trim()){R.error(e(`settings.apiKeys.nameRequired`,`Give the key a name.`));return}if(f.length===0){R.error(e(`settings.apiKeys.scopesRequired`,`Select at least one scope.`));return}let n;if(m.trim()){let t=Number(m);if(!Number.isInteger(t)||t<1){R.error(e(`settings.apiKeys.expiryInvalid`,`Expiry must be a whole number of days.`));return}n=t}_(!0);try{let t=await Mt.createApiToken({name:u.trim(),scopes:f,expiresInDays:n});if(!t.success||!t.data)throw Error(t.error||e(`settings.apiKeys.createFailed`));b(t.data.token),d(``),p([]),h(``),R.success(e(`settings.apiKeys.created`,`API key created.`)),await S()}catch(t){R.error(t instanceof Error&&t.message?t.message:e(`settings.apiKeys.createFailed`,`The API key could not be created.`))}finally{_(!1)}},T=async()=>{if(v)try{await navigator.clipboard.writeText(v),R.success(e(`settings.apiKeys.copied`,`Copied to clipboard.`))}catch{R.error(e(`settings.apiKeys.copyFailed`,`Copy failed.`))}},E=async t=>{if(await kt({title:e(`settings.apiKeys.revokeConfirmTitle`,{name:t.name}),description:e(`settings.apiKeys.revokeConfirmDescription`),confirmLabel:e(`settings.apiKeys.revoke`),destructive:!0})){l(t.id);try{let n=await Mt.revokeApiToken(t.id);if(!n.success)throw Error(n.error||e(`settings.apiKeys.revokeFailed`));R.success(e(`settings.apiKeys.revoked`,`API key revoked.`)),await S()}catch(t){R.error(t instanceof Error&&t.message?t.message:e(`settings.apiKeys.revokeFailed`,`The API key could not be revoked.`))}finally{l(null)}}};return(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsx)(Dn,{className:`mb-0`,title:(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(pe,{className:`h-5 w-5 text-primary-500`}),e(`settings.apiKeys.title`,`API keys`)]}),description:e(`settings.apiKeys.description`,`Scoped tokens for scripts and integrations. Each key only has access to the scopes you pick.`)}),v&&(0,$.jsxs)(`div`,{className:`rounded-lg border border-primary-500/40 bg-primary-50 dark:bg-primary-900/20 p-4 space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.apiKeys.newKeyTitle`,`Your new API key`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`code`,{dir:`ltr`,className:`min-w-0 flex-1 overflow-x-auto rounded-md bg-white dark:bg-dark-100 border border-gray-200 dark:border-dark-300 px-3 py-2 text-xs text-gray-900 dark:text-gray-100`,"data-testid":`new-api-key`,children:v}),(0,$.jsxs)(H,{size:`sm`,variant:`outline`,onClick:()=>void T(),className:`shrink-0 gap-1.5`,children:[(0,$.jsx)(_e,{size:14}),e(`settings.apiKeys.copy`,`Copy`)]})]}),(0,$.jsx)(`p`,{className:`text-xs text-warning-700 dark:text-warning-400`,children:e(`settings.apiKeys.showOnceWarning`,`Copy it now — it will not be shown again.`)}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(H,{size:`sm`,variant:`ghost`,onClick:()=>b(null),children:e(`settings.apiKeys.dismiss`,`Done`)})})]}),(0,$.jsxs)(`form`,{onSubmit:w,className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 space-y-3`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.apiKeys.createTitle`,`Create a key`)}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.apiKeys.nameLabel`,`Name`)}),(0,$.jsx)(wt,{value:u,onChange:e=>d(e.target.value),placeholder:e(`settings.apiKeys.namePlaceholder`,`e.g. CI pipeline`)})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.apiKeys.expiryLabel`,`Expires in days (optional)`)}),(0,$.jsx)(wt,{type:`number`,min:1,value:m,onChange:e=>h(e.target.value),placeholder:e(`settings.apiKeys.expiryPlaceholder`,`Never`),dir:`ltr`})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`mb-2 block text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`settings.apiKeys.scopesLabel`,`Scopes`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-2`,children:x.map(e=>(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-900 dark:text-gray-100`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:f.includes(e),onChange:()=>C(e),className:`h-4 w-4 rounded-sm border-gray-300 dark:border-dark-300 text-primary-600 focus:ring-primary-500`}),e]},e))})]}),(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(H,{size:`sm`,type:`submit`,disabled:g,children:g?e(`settings.apiKeys.creating`,`Creating…`):e(`settings.apiKeys.create`,`Create key`)})})]}),i?(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`common.loading`)}):o?(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 flex items-center justify-between gap-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`settings.apiKeys.loadFailed`,`The API keys could not be loaded.`)}),(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>void S(),children:e(`common.retry`)})]}):n.length===0?(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`settings.apiKeys.empty`,`No API keys yet.`)}):(0,$.jsx)(`div`,{className:`space-y-3`,children:n.map(t=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100 p-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:t.name}),(0,$.jsxs)(`code`,{dir:`ltr`,className:`rounded-sm bg-gray-100 dark:bg-dark-200 px-1.5 py-0.5 text-xs text-gray-600 dark:text-gray-300`,children:[t.tokenPrefix,`…`]}),t.revokedAt&&(0,$.jsx)(`span`,{className:`rounded-full bg-gray-100 dark:bg-dark-200 px-2 py-0.5 text-xs font-medium text-gray-500 dark:text-gray-400`,children:e(`settings.apiKeys.revokedBadge`,`Revoked`)})]}),(0,$.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:t.scopes.map(e=>(0,$.jsx)(`span`,{className:`rounded-full bg-primary-100 dark:bg-primary-900/30 px-2 py-0.5 text-xs text-primary-700 dark:text-primary-300`,children:e},e))}),(0,$.jsxs)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-gray-400`,children:[e(`settings.apiKeys.createdAt`,`Created`),`:`,` `,Cr(t.createdAt),` · `,e(`settings.apiKeys.lastUsedAt`,`Last used`),`:`,` `,Cr(t.lastUsedAt),` · `,e(`settings.apiKeys.expiresAt`,`Expires`),`:`,` `,t.expiresAt?Cr(t.expiresAt):e(`settings.apiKeys.neverExpires`,`Never`)]})]}),!t.revokedAt&&(0,$.jsx)(`div`,{className:`shrink-0`,children:(0,$.jsx)(H,{size:`sm`,variant:`outline`,onClick:()=>void E(t),disabled:c===t.id,children:c===t.id?e(`settings.apiKeys.revoking`,`Revoking…`):e(`settings.apiKeys.revoke`,`Revoke`)})})]},t.id))})]})};function Tr({loading:e,settings:t,effectiveSettings:n,models:r,plugins:i,voices:a,voiceProfiles:o,selectableVoiceProfiles:s,loadingVoiceProfiles:c,testing:l,onSettingChange:u,onModelChange:d,onVoiceChange:f,onDeleteVoiceProfile:p,onRevokeVoiceProfile:m,onReset:h,onTest:g,onSave:_}){let{t:v}=y(),b=(0,Q.useId)(),x=(0,Q.useId)(),S=(0,Q.useId)(),C=(0,Q.useId)(),w=(0,Q.useId)(),T=r.find(e=>e.model===n.model&&(!n.pluginId||e.plugin===n.pluginId));return(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Dn,{title:v(`settings.tts.title`),description:v(`settings.tts.description`)}),e?(0,$.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,$.jsx)(Ce,{className:`h-8 w-8 animate-spin text-primary-500`}),(0,$.jsx)(`span`,{className:`ms-3 text-gray-600 dark:text-gray-400`,children:v(`settings.tts.loadingProviders`)})]}):r.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-yellow-200 bg-yellow-500/10 p-4 dark:border-yellow-800 dark:bg-yellow-900/20`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(Ze,{className:`h-5 w-5 text-yellow-600 dark:text-yellow-400 mt-0.5`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-ink`,children:v(`settings.tts.noProviders`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-ink-muted`,children:v(`settings.tts.noProvidersDescription`)})]})]})}):(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{id:b,className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:v(`settings.tts.enable`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:v(`settings.tts.enableDescription`)})]}),(0,$.jsx)(X,{checked:t.enabled,onChange:e=>u(`enabled`,e),"aria-labelledby":b})]})}),(0,$.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{id:x,className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:v(`settings.tts.autoPlay`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:v(`settings.tts.autoPlayDescription`)})]}),(0,$.jsx)(X,{checked:t.autoPlay,disabled:!t.enabled,onChange:e=>{e&&un(),u(`autoPlay`,e)},"aria-labelledby":x})]})}),(0,$.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h4`,{id:S,className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:v(`settings.tts.streamSentences`)}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:v(`settings.tts.streamSentencesDescription`)})]}),(0,$.jsx)(X,{checked:t.streamSentences!==!1,disabled:!t.enabled,onChange:e=>u(`streamSentences`,e),"aria-labelledby":S})]})}),(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-4`,children:v(`settings.tts.voiceConfiguration`)}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:C,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:v(`settings.tts.model`)}),(0,$.jsx)(Dt,{id:C,"aria-label":v(`settings.tts.model`),value:T?Gt(T):``,onChange:e=>{let t=r.find(t=>Gt(t)===e.target.value);t&&d(t.model,t.plugin)},disabled:!t.enabled,options:[{value:``,label:v(`settings.model.selectModel`)},...r.map(e=>({value:Gt(e),label:`${e.model} (${e.plugin})`,key:`${e.plugin}:${e.model}`}))]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:v(`settings.tts.modelDescription`)})]}),a.length>0||s.length>0?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:w,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:v(`settings.tts.voice`)}),(0,$.jsx)(Dt,{id:w,"aria-label":v(`settings.tts.voice`),value:n.voiceProfileId?Dr(n.voiceProfileId):n.voice,onChange:e=>{let t=Or(e.target.value);f(t?``:e.target.value,t||``)},disabled:!t.enabled,options:[{value:``,label:v(`settings.tts.selectVoice`)},...a.map(e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)})),...s.map(e=>({value:Dr(e.id),label:v(`settings.tts.savedVoiceOption`,{name:e.name,defaultValue:`{{name}} (saved voice)`}),key:`saved-voice-${e.id}`}))]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 mt-1`,children:v(`settings.tts.voiceDescription`)})]}):c?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-gray-50 p-3 text-xs text-gray-600 dark:bg-dark-50 dark:text-gray-400`,children:[(0,$.jsx)(Ce,{className:`h-3.5 w-3.5 animate-spin`}),v(`settings.tts.loadingSavedVoices`,{defaultValue:`Loading saved voices…`})]}):(0,$.jsx)(`p`,{className:`rounded-lg bg-gray-50 p-3 text-xs text-gray-600 dark:bg-dark-50 dark:text-gray-400`,children:v(`settings.tts.providerDefaultVoice`)})]})]}),T?.config?.supports_voice_cloning&&(0,$.jsxs)(`div`,{className:`rounded-lg border border-primary-500/20 bg-primary-500/6 p-4`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:v(`settings.tts.voiceCloningAvailable`)}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-gray-600 dark:text-gray-400`,children:v(`settings.tts.voiceCloningAvailableDescription`)})]}),i.length>0&&(0,$.jsxs)(`div`,{className:`bg-gray-50 dark:bg-dark-50 rounded-lg p-4 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:v(`settings.tts.availableProviders`)}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:i.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 bg-white dark:bg-dark-100 rounded-sm border border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-green-500`}),(0,$.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:e.name}),(0,$.jsxs)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[`(`,e.models?.length||0,` `,v(`settings.tts.models`),`)`]})]},e.id))})]}),(0,$.jsxs)(`div`,{className:`flex justify-between items-center pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(H,{onClick:h,variant:`outline`,className:`flex items-center gap-2`,children:[(0,$.jsx)(Pe,{size:16}),v(`common.reset`)]}),(0,$.jsx)(H,{onClick:g,variant:`outline`,disabled:!t.enabled||!n.model,className:`flex items-center gap-2`,children:l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ye,{size:16}),v(`settings.tts.stop`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ge,{size:16}),v(`settings.tts.test`)]})})]}),(0,$.jsxs)(H,{onClick:_,className:`flex items-center gap-2`,children:[(0,$.jsx)(Ve,{size:16}),v(`settings.saveSettings`)]})]})]})]}),(c||o.length>0)&&(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:v(`settings.tts.savedVoices`,{defaultValue:`Saved voices`})}),c?(0,$.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(Ce,{className:`h-3.5 w-3.5 animate-spin`}),v(`settings.tts.loadingSavedVoices`,{defaultValue:`Loading saved voices…`})]}):(0,$.jsx)(`div`,{className:`mt-3 space-y-2`,children:o.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 dark:border-dark-300 dark:bg-dark-50`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`p`,{className:`truncate text-sm text-gray-800 dark:text-gray-200`,children:[e.name,e.consentStatus===`revoked`&&(0,$.jsx)(`span`,{className:`ms-2 rounded-sm bg-red-100 px-1.5 py-0.5 text-[10px] font-medium text-red-700 dark:bg-red-950/40 dark:text-red-400`,children:v(`settings.tts.consentRevoked`,{defaultValue:`Consent withdrawn`})}),e.consentStatus===`expired`&&(0,$.jsx)(`span`,{className:`ms-2 rounded-sm bg-amber-100 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:bg-amber-950/40 dark:text-amber-400`,children:v(`settings.tts.consentExpired`,{defaultValue:`Consent expired`})})]}),(0,$.jsxs)(`p`,{className:`truncate text-xs text-gray-500 dark:text-gray-400`,children:[e.pluginId,` · `,e.model,` · `,v(`settings.tts.transferCount`,{total:e.transferCount??0,defaultValue:`sent to provider {{total}}×`}),e.consentExpiresAt&&e.consentStatus===`active`&&(0,$.jsxs)($.Fragment,{children:[` · `,v(`settings.tts.consentExpires`,{date:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.consentExpiresAt),defaultValue:`consent until {{date}}`})]})]})]}),(e.consentStatus??`active`)===`active`&&(0,$.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(e),"aria-label":v(`settings.tts.revokeSavedVoice`,{name:e.name,defaultValue:`Withdraw consent for {{name}}`}),className:`shrink-0 px-2 text-amber-600 hover:bg-amber-50 hover:text-amber-700 dark:hover:bg-amber-950/30`,children:(0,$.jsx)(Se,{className:`h-4 w-4`})}),(0,$.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(e),"aria-label":v(`settings.tts.deleteSavedVoice`,{name:e.name,defaultValue:`Delete saved voice {{name}}`}),className:`shrink-0 px-2 text-red-600 hover:bg-red-50 hover:text-red-700 dark:hover:bg-red-950/30`,children:(0,$.jsx)(pt,{className:`h-4 w-4`})})]},e.id))})]})]})}var Er=`__saved_voice__:`;function Dr(e){return`${Er}${e}`}function Or(e){return e.startsWith(Er)?e.slice(16):void 0}var kr=[`text`,`number`,`select`,`boolean`],Ar=({variables:e,onChange:t})=>{let{t:n}=y(),r=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e));return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:G,children:n(`promptsPage.form.variables`)}),(0,$.jsx)(`p`,{className:`mb-2 text-[11px] text-gray-400 dark:text-dark-500`,children:n(`promptsPage.form.variablesHint`)}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[e.map((i,a)=>(0,$.jsxs)(`div`,{"data-testid":`prompt-variable-row`,className:`rounded-xl border border-black/6 bg-black/2 p-2.5 dark:border-white/[0.07] dark:bg-white/3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,value:i.name,onChange:e=>r(a,{name:e.target.value}),placeholder:n(`promptsPage.form.variableName`),"aria-label":n(`promptsPage.form.variableName`),className:U,maxLength:64}),(0,$.jsx)(`select`,{value:i.type,onChange:e=>r(a,{type:e.target.value,options:e.target.value===`select`?i.options??[]:void 0}),"aria-label":n(`promptsPage.form.variableType`),className:U,children:kr.map(e=>(0,$.jsx)(`option`,{value:e,children:n(`promptsPage.variableTypes.${e}`)},e))}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>t(e.filter((e,t)=>t!==a)),"aria-label":n(`promptsPage.form.removeVariable`),"data-testid":`prompt-variable-remove`,className:`shrink-0 rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-500/10 hover:text-red-500`,children:(0,$.jsx)(pt,{className:`h-3.5 w-3.5`})})]}),(0,$.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,value:i.label??``,onChange:e=>r(a,{label:e.target.value}),placeholder:n(`promptsPage.form.variableLabel`),"aria-label":n(`promptsPage.form.variableLabel`),className:U,maxLength:120}),(0,$.jsx)(`input`,{type:`text`,value:i.default??``,onChange:e=>r(a,{default:e.target.value}),placeholder:n(`promptsPage.form.variableDefault`),"aria-label":n(`promptsPage.form.variableDefault`),className:U,maxLength:500}),(0,$.jsxs)(`label`,{className:`flex shrink-0 items-center gap-1.5 whitespace-nowrap text-[12px] text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:i.required===!0,onChange:e=>r(a,{required:e.target.checked}),className:`h-3.5 w-3.5 rounded-sm border-gray-300 dark:border-dark-400`}),n(`promptsPage.form.variableRequired`)]})]}),i.type===`select`&&(0,$.jsx)(`input`,{type:`text`,value:(i.options??[]).join(`, `),onChange:e=>r(a,{options:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),placeholder:n(`promptsPage.form.variableOptionsPlaceholder`),"aria-label":n(`promptsPage.form.variableOptions`),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30 mt-2`})]},a)),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>t([...e,{name:``,type:`text`}]),"data-testid":`prompt-add-variable`,className:`flex items-center gap-1.5 rounded-lg px-2 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:[(0,$.jsx)(dt,{className:`h-3.5 w-3.5`}),n(`promptsPage.form.addVariable`)]})]})]})},jr=/^[a-z0-9][a-z0-9-]{0,63}$/;function Mr({open:e,prompt:t,prefill:n=null,saving:r,onClose:i,onSave:a}){return e?(0,$.jsx)(Nr,{prompt:t,prefill:n,saving:r,onClose:i,onSave:a},t?.id??(n?`template-${n.slug}`:`new`)):null}function Nr({prompt:e,prefill:t,saving:n,onClose:r,onSave:i}){let{t:a}=y(),o=e??t,[s,c]=(0,Q.useState)(o?.slug??``),[l,u]=(0,Q.useState)(o?.title??``),[d,f]=(0,Q.useState)(o?.description??``),[p,m]=(0,Q.useState)(o?.content??``),[h,g]=(0,Q.useState)(o?.variables??[]),[_,v]=(0,Q.useState)((o?.tags??[]).join(`, `)),b=jr.test(s.trim()),x=b&&l.trim().length>0&&p.trim().length>0;return(0,$.jsxs)(Ct,{titleId:`prompt-modal-title`,title:a(e?`promptsPage.editPrompt`:`promptsPage.newPrompt`),onClose:r,widthClassName:`max-w-2xl`,testId:`prompt-modal`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:r,children:a(`common.cancel`)}),(0,$.jsx)(H,{size:`sm`,onClick:()=>{x&&i({slug:s.trim(),title:l.trim(),description:d.trim()||void 0,content:p,variables:h.filter(e=>e.name.trim().length>0),tags:_.split(`,`).map(e=>e.trim()).filter(Boolean)})},disabled:n||!x,"data-testid":`prompt-save`,children:a(n?`common.saving`:`common.save`)})]}),children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`prompt-slug`,className:G,children:a(`promptsPage.form.slug`)}),(0,$.jsx)(`input`,{id:`prompt-slug`,"data-testid":`prompt-slug`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:a(`promptsPage.form.slugPlaceholder`),className:U,maxLength:64,autoFocus:!0}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:s.trim().length>0&&!b?a(`promptsPage.form.slugInvalid`):a(`promptsPage.form.slugHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`prompt-title`,className:G,children:a(`promptsPage.form.title`)}),(0,$.jsx)(`input`,{id:`prompt-title`,"data-testid":`prompt-title`,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:a(`promptsPage.form.titlePlaceholder`),className:U,maxLength:200})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`prompt-description`,className:G,children:a(`promptsPage.form.description`)}),(0,$.jsx)(`input`,{id:`prompt-description`,type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:a(`promptsPage.form.descriptionPlaceholder`),className:U,maxLength:500})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`prompt-content`,className:G,children:a(`promptsPage.form.content`)}),(0,$.jsx)(`textarea`,{id:`prompt-content`,"data-testid":`prompt-content`,value:p,onChange:e=>m(e.target.value),placeholder:a(`promptsPage.form.contentPlaceholder`),rows:8,className:U,maxLength:5e4}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:a(`promptsPage.form.contentHint`)})]}),(0,$.jsx)(Ar,{variables:h,onChange:g}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`prompt-tags`,className:G,children:a(`promptsPage.form.tags`)}),(0,$.jsx)(`input`,{id:`prompt-tags`,type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:a(`promptsPage.form.tagsPlaceholder`),className:U})]})]})}var Pr=({title:e,cards:t,testId:n,onPick:r})=>t.length===0?null:(0,$.jsxs)(`div`,{className:`mt-8`,children:[(0,$.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:e}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))] gap-2`,children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),"data-testid":n,className:`min-w-0 rounded-2xl border border-black/6 bg-white/40 px-4 py-3 text-start wrap-anywhere transition-colors hover:bg-white/80 dark:border-white/[0.07] dark:bg-dark-100/40 dark:hover:bg-dark-100/80`,children:[(0,$.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:e.name}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[12px] text-gray-500 dark:text-dark-500`,children:e.description}),e.meta&&(0,$.jsx)(`p`,{className:`mt-1.5 font-mono text-[11px] text-gray-400 dark:text-dark-500`,dir:`ltr`,children:e.meta})]},e.id))})]}),Fr=[{id:`reviewPr`,input:{slug:`review-pr`,title:`Pull request review`,description:`Structured code review with adjustable strictness.`,content:`Review the following {{language}} changes with {{strictness}} strictness. Point out bugs first, style second, and end with a one-line verdict.`,variables:[{name:`language`,type:`text`,label:`Language`,required:!0},{name:`strictness`,type:`select`,label:`Strictness`,default:`normal`,options:[`low`,`normal`,`pedantic`]}],tags:[`code`,`review`]}},{id:`summarize`,input:{slug:`summarize`,title:`Summarize for an audience`,description:`Bullet-point summary tuned to a reader.`,content:`Summarize the following in at most {{points}} bullet points for {{audience}}. Keep every bullet self-contained, lead with the most important point, and end with a one-sentence takeaway.`,variables:[{name:`points`,type:`number`,label:`Bullets`,default:`5`},{name:`audience`,type:`text`,label:`Audience`,default:`a technical reader`}],tags:[`writing`]}},{id:`translate`,input:{slug:`translate`,title:`Translate`,description:`Translation that preserves tone and formatting.`,content:`Translate the following into {{target_language}}. Preserve tone, formatting, and markup exactly; keep code, identifiers, and proper names untranslated. If a phrase is ambiguous, pick the most natural reading and note the alternative in brackets.`,variables:[{name:`target_language`,type:`text`,label:`Target language`,required:!0}],tags:[`writing`,`translation`]}},{id:`explainCode`,input:{slug:`explain-code`,title:`Explain code`,description:`Walkthrough plus edge cases and risks.`,content:`Explain what the following {{language}} code does, step by step but briefly. Then list edge cases it mishandles, hidden assumptions, and the one change you would make first.`,variables:[{name:`language`,type:`text`,label:`Language`,required:!0}],tags:[`code`]}}],Ir=({title:e,entries:t,loading:n,currentVersion:r,rollingBackTo:i,onRollback:a,onClose:o,testId:s})=>{let{t:c,i18n:l}=y();return(0,$.jsx)(Ct,{titleId:`version-history-title`,title:e,subtitle:c(`promptsPage.history.subtitle`),onClose:o,widthClassName:`max-w-2xl`,testId:s,footer:(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:o,children:c(`common.close`)}),children:n?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,$.jsx)(Ce,{className:`h-5 w-5 animate-spin text-gray-400`})}):t.length===0?(0,$.jsxs)(`div`,{className:`py-10 text-center`,children:[(0,$.jsx)(Me,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,$.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:c(`promptsPage.history.empty`)})]}):(0,$.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,$.jsxs)(`div`,{"data-testid":`version-history-entry`,className:`rounded-2xl border border-black/6 bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:[c(`promptsPage.versionLabel`,{version:e.version}),e.version===r&&(0,$.jsx)(`span`,{className:`ms-2 rounded-full bg-primary-500/10 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary-600 dark:text-primary-400`,children:c(`promptsPage.history.current`)})]}),(0,$.jsx)(`p`,{className:`mt-0.5 text-[11px] text-gray-400 dark:text-dark-500`,children:b(e.createdAt,l.language)})]}),(0,$.jsx)(H,{size:`sm`,variant:`outline`,disabled:e.version===r||i!==null,onClick:()=>a(e.version),"data-testid":`version-rollback`,children:i===e.version?c(`promptsPage.history.rollingBack`):c(`promptsPage.history.rollback`)})]}),(0,$.jsx)(`pre`,{className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap wrap-break-word rounded-xl bg-black/3 p-2.5 text-[11px] leading-5 text-gray-600 scrollbar-thin dark:bg-white/4 dark:text-dark-600`,children:e.body})]},e.version))})})},Lr=(e,t)=>{let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},Rr=async e=>JSON.parse(await e.text()),zr=(e,t)=>{let n=new Blob([t],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,i.click(),URL.revokeObjectURL(r)},Br=e=>new Promise((t,n)=>{let r=new FileReader;r.onerror=()=>n(r.error),r.onload=()=>t(String(r.result??``)),r.readAsText(e)}),Vr=o(`pages:prompts`),Hr=()=>{let{t:e,i18n:t}=y(),[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),[v,x]=(0,Q.useState)([]),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),E=(0,Q.useRef)(null),[D,O]=(0,Q.useState)(0),k=(0,Q.useCallback)(()=>O(e=>e+1),[]);(0,Q.useEffect)(()=>{let t=!1;return Wt.list().then(n=>{t||(n.success&&n.data?r(n.data):V.error(n.error||e(`promptsPage.loadFailed`)))}).catch(n=>{t||(Vr.error(`Failed to load prompts:`,n),V.error(e(`promptsPage.loadFailed`)))}).finally(()=>{t||a(!1)}),()=>{t=!0}},[D,e]);let A=async t=>{p(!0);try{let n=c?await Wt.update(c.id,t):await Wt.create(t);n.success?(s(!1),d(null),V.success(e(`promptsPage.saved`)),k()):V.error(n.error||e(`promptsPage.saveFailed`))}catch(t){Vr.error(`Failed to save prompt:`,t),V.error(e(`promptsPage.saveFailed`))}finally{p(!1)}},j=async()=>{if(!m)return;let t=m;h(null);try{let n=await Wt.remove(t.id);if(!n.success)throw Error(n.error);V.success(e(`promptsPage.deleted`)),k()}catch(t){Vr.error(`Failed to delete prompt:`,t),V.error(e(`promptsPage.deleteFailed`))}},M=async t=>{try{let e=await Wt.export(t.id);if(!e.success||!e.data)throw Error(e.error);Lr(`${t.slug}.prompt.json`,e.data)}catch(t){Vr.error(`Failed to export prompt:`,t),V.error(e(`promptsPage.exportFailed`))}},N=async t=>{try{let n=await Wt.import(await Rr(t));if(!n.success)throw Error(n.error);V.success(e(`promptsPage.imported`)),k()}catch(t){Vr.error(`Failed to import prompt:`,t),V.error(e(`promptsPage.importFailed`))}},P=async t=>{_(t),C(!0),x([]);try{let n=await Wt.versions(t.id);n.success&&n.data?x(n.data):V.error(n.error||e(`promptsPage.historyFailed`))}catch(t){Vr.error(`Failed to load prompt history:`,t),V.error(e(`promptsPage.historyFailed`))}finally{C(!1)}},I=async t=>{if(g){T(t);try{let n=await Wt.rollback(g.id,t);if(!n.success||!n.data)throw Error(n.error);V.success(e(`promptsPage.rolledBack`)),_(null),k()}catch(t){Vr.error(`Failed to roll the prompt back:`,t),V.error(e(`promptsPage.rollbackFailed`))}finally{T(null)}}};return(0,$.jsxs)(`div`,{"data-testid":`prompts-page`,className:`pb-2`,children:[(0,$.jsx)(Dn,{title:e(`promptsPage.title`),description:e(`promptsPage.description`),actions:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:E,type:`file`,accept:`application/json,.json`,className:`hidden`,"data-testid":`prompt-import-input`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&N(t)}}),(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>E.current?.click(),"data-testid":`prompt-import`,children:[(0,$.jsx)(Qe,{className:`me-1.5 h-3.5 w-3.5`}),e(`common.import`)]}),(0,$.jsxs)(H,{size:`sm`,onClick:()=>{l(null),d(null),s(!0)},"data-testid":`prompt-new`,children:[(0,$.jsx)(dt,{className:`me-1.5 h-3.5 w-3.5`}),e(`promptsPage.newPrompt`)]})]})}),i?(0,$.jsx)(Et,{srOnly:!0}):n.length===0?(0,$.jsx)(Ot,{icon:He,title:e(`promptsPage.empty`),description:e(`promptsPage.emptyHint`)}):(0,$.jsx)(`div`,{className:`space-y-2`,children:n.map(n=>(0,$.jsx)(`div`,{"data-testid":`prompt-row`,className:`rounded-2xl border border-black/6 bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-[1_1_16rem] wrap-anywhere`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`max-w-full text-[14px] font-medium text-gray-900 dark:text-dark-900`,children:n.title}),(0,$.jsxs)(`code`,{className:`max-w-full rounded-md bg-black/4 px-1.5 py-0.5 text-[11px] text-gray-500 dark:bg-white/6 dark:text-dark-500`,children:[`/`,n.slug]}),(0,$.jsx)(`span`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:e(`promptsPage.versionLabel`,{version:n.version})})]}),n.description&&(0,$.jsx)(`p`,{className:`mt-1 text-[12px] text-gray-500 dark:text-dark-500`,children:n.description}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1.5`,children:[n.tags.map(e=>(0,$.jsx)(`span`,{className:`max-w-full rounded-full bg-black/4 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-white/6 dark:text-dark-500`,children:e},e)),(0,$.jsx)(`span`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:e(`promptsPage.updated`,{when:b(n.updatedAt,t.language)})})]})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-full shrink-0 flex-wrap items-center gap-1 [&>button]:inline-flex [&>button]:min-h-11 [&>button]:min-w-11 [&>button]:items-center [&>button]:justify-center`,children:[(0,$.jsx)(W,{icon:Me,label:e(`promptsPage.history.open`),testId:`prompt-history`,onClick:()=>void P(n)}),(0,$.jsx)(W,{icon:F,label:e(`common.export`),testId:`prompt-export`,onClick:()=>void M(n)}),(0,$.jsx)(W,{icon:ct,label:e(`common.edit`),testId:`prompt-edit`,onClick:()=>{l(n),s(!0)}}),(0,$.jsx)(W,{icon:pt,label:e(`common.delete`),testId:`prompt-delete`,destructive:!0,onClick:()=>h(n)})]})]})},n.id))}),!i&&(0,$.jsx)(Pr,{title:e(`promptsPage.templatesTitle`),testId:`prompt-template`,cards:Fr.map(t=>({id:t.id,name:e(`promptsPage.templates.${t.id}.name`),description:e(`promptsPage.templates.${t.id}.description`),meta:`/${t.input.slug}`})),onPick:e=>{let t=Fr.find(t=>t.id===e);t&&(l(null),d(t.input),s(!0))}}),(0,$.jsx)(Mr,{open:o,prompt:c,prefill:u,saving:f,onClose:()=>{s(!1),d(null)},onSave:e=>void A(e)}),g&&(0,$.jsx)(Ir,{title:e(`promptsPage.history.title`,{title:g.title}),entries:v.map(e=>({version:e.version,body:e.content,createdAt:e.createdAt})),loading:S,currentVersion:g.version,rollingBackTo:w,onRollback:e=>void I(e),onClose:()=>_(null),testId:`prompt-history-modal`}),m&&(0,$.jsx)(Ct,{titleId:`prompt-delete-title`,title:e(`promptsPage.deleteTitle`),subtitle:e(`promptsPage.deleteConfirm`,{title:m.title}),onClose:()=>h(null),widthClassName:`max-w-sm`,testId:`prompt-delete-modal`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>h(null),children:e(`common.cancel`)}),(0,$.jsx)(H,{variant:`danger`,size:`sm`,onClick:()=>void j(),"data-testid":`prompt-delete-confirm`,children:e(`common.delete`)})]})})]})},Ur=/^[a-z0-9][a-z0-9-]{0,63}$/,Wr=[`run_command`,`computer_act`,`delete_file`,`move_file`,`message_agent`,`write_file`];function Gr({open:e,skill:t,prefill:n=null,saving:r,onClose:i,onSave:a}){return e?(0,$.jsx)(Kr,{skill:t,prefill:n,saving:r,onClose:i,onSave:a},t?.id??(n?`template-${n.slug}`:`new`)):null}function Kr({skill:e,prefill:t,saving:n,onClose:r,onSave:i}){let{t:a}=y(),o=e??t,[s,c]=(0,Q.useState)(o?.slug??``),[l,u]=(0,Q.useState)(o?.name??``),[d,f]=(0,Q.useState)(o?.description??``),[p,m]=(0,Q.useState)(o?.instructions??``),[h,g]=(0,Q.useState)(o?.enabled??!0),[_,v]=(0,Q.useState)(o?.approvalPolicy??`inherit`),[b,x]=(0,Q.useState)(o?.approvalTools??[]),S=(e,t)=>x(n=>t?[...n,e].filter((e,t,n)=>n.indexOf(e)===t):n.filter(t=>t!==e)),C=Ur.test(s.trim()),w=C&&l.trim().length>0&&d.trim().length>0&&p.trim().length>0;return(0,$.jsxs)(Ct,{titleId:`skill-modal-title`,title:a(e?`skillsPage.editSkill`:`skillsPage.newSkill`),onClose:r,widthClassName:`max-w-2xl`,testId:`skill-modal`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:r,children:a(`common.cancel`)}),(0,$.jsx)(H,{size:`sm`,onClick:()=>{w&&i({slug:s.trim(),name:l.trim(),description:d.trim(),instructions:p,enabled:h,approvalPolicy:_,approvalTools:_===`always`?b:[]})},disabled:n||!w,"data-testid":`skill-save`,children:a(n?`common.saving`:`common.save`)})]}),children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`skill-slug`,className:G,children:a(`skillsPage.form.slug`)}),(0,$.jsx)(`input`,{id:`skill-slug`,"data-testid":`skill-slug`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:a(`skillsPage.form.slugPlaceholder`),className:U,maxLength:64,autoFocus:!0}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:s.trim().length>0&&!C?a(`skillsPage.form.slugInvalid`):a(`skillsPage.form.slugHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`skill-name`,className:G,children:a(`skillsPage.form.name`)}),(0,$.jsx)(`input`,{id:`skill-name`,"data-testid":`skill-name`,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:a(`skillsPage.form.namePlaceholder`),className:U,maxLength:200})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`skill-description`,className:G,children:a(`skillsPage.form.description`)}),(0,$.jsx)(`textarea`,{id:`skill-description`,"data-testid":`skill-description`,value:d,onChange:e=>f(e.target.value),placeholder:a(`skillsPage.form.descriptionPlaceholder`),rows:2,className:U,maxLength:1e3}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:a(`skillsPage.form.descriptionHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`skill-instructions`,className:G,children:a(`skillsPage.form.instructions`)}),(0,$.jsx)(`textarea`,{id:`skill-instructions`,"data-testid":`skill-instructions`,value:p,onChange:e=>m(e.target.value),placeholder:a(`skillsPage.form.instructionsPlaceholder`),rows:10,className:`${U} font-mono`,maxLength:5e4}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:a(`skillsPage.form.instructionsHint`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 rounded-xl border border-black/6 px-3 py-2.5 dark:border-white/[0.07]`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:a(`skillsPage.form.enabled`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:a(`skillsPage.form.enabledHint`)})]}),(0,$.jsx)(St,{checked:h,onChange:g})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-black/6 px-3 py-2.5 dark:border-white/[0.07]`,"data-testid":`skill-approval`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:a(`skillsPage.form.approval`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:a(`skillsPage.form.approvalHint`)})]}),(0,$.jsx)(`span`,{"data-testid":`skill-approval-always`,children:(0,$.jsx)(St,{checked:_===`always`,onChange:e=>v(e?`always`:`inherit`)})})]}),_===`always`&&(0,$.jsxs)(`div`,{className:`mt-2.5 border-t border-black/6 pt-2.5 dark:border-white/[0.07]`,children:[(0,$.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:a(`skillsPage.form.approvalTools`)}),(0,$.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-x-4 gap-y-1.5`,children:Wr.map(e=>(0,$.jsxs)(`label`,{dir:`ltr`,className:`flex cursor-pointer items-center gap-1.5 font-mono text-[12px] text-gray-700 dark:text-dark-800`,children:[(0,$.jsx)(`input`,{type:`checkbox`,"data-testid":`skill-approval-tool-${e}`,checked:b.includes(e),onChange:t=>S(e,t.target.checked),className:`h-3.5 w-3.5 rounded-sm border-line-strong accent-primary-600`}),e]},e))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] text-gray-400 dark:text-dark-500`,children:a(`skillsPage.form.approvalToolsHint`)})]})]}),e&&(0,$.jsx)(qr,{skillId:e.id})]})}function qr({skillId:e}){let{t}=y(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),f=(0,Q.useCallback)(()=>{zt.listFiles(e).then(e=>r(e.success&&e.data?e.data:[])).catch(()=>r([]))},[e]);(0,Q.useEffect)(()=>{f()},[f]);let p=async n=>{if(n===null){a(``),s(``),l(``);return}try{let t=await zt.getFile(e,n);if(!t.success||!t.data)throw Error(t.error);a(n),s(n),l(t.data.content)}catch{V.error(t(`skillsPage.files.loadFailed`))}},m=async()=>{let n=o.trim();if(n){d(!0);try{let t=await zt.putFile(e,n,c);if(!t.success)throw Error(t.error);i&&i!==n&&await zt.deleteFile(e,i),a(null),f()}catch(e){V.error(e instanceof Error&&e.message?e.message:t(`skillsPage.files.saveFailed`))}finally{d(!1)}}},h=async n=>{try{let t=await zt.deleteFile(e,n);if(!t.success)throw Error(t.error);i===n&&a(null),f()}catch{V.error(t(`skillsPage.files.deleteFailed`))}};return(0,$.jsxs)(`div`,{className:`rounded-xl border border-black/6 px-3 py-2.5 dark:border-white/[0.07]`,"data-testid":`skill-files`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:t(`skillsPage.files.title`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:t(`skillsPage.files.hint`)})]}),(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>void p(null),"data-testid":`skill-file-add`,children:[(0,$.jsx)(Le,{className:`me-1.5 h-3.5 w-3.5`}),t(`skillsPage.files.add`)]})]}),n&&n.length>0&&(0,$.jsx)(`ul`,{className:`mt-2 space-y-1`,children:n.map(e=>(0,$.jsxs)(`li`,{"data-testid":`skill-file-row`,className:`flex items-center gap-2 rounded-lg bg-black/3 px-2 py-1.5 dark:bg-white/4`,children:[(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate text-[12px] text-gray-700 dark:text-dark-800`,dir:`ltr`,children:e.path}),(0,$.jsxs)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:[e.size,` B`]}),(0,$.jsx)(W,{icon:ct,label:t(`common.edit`),testId:`skill-file-edit`,onClick:()=>void p(e.path)}),(0,$.jsx)(W,{icon:pt,label:t(`common.delete`),testId:`skill-file-delete`,destructive:!0,onClick:()=>void h(e.path)})]},e.path))}),n&&n.length===0&&i===null&&(0,$.jsx)(`p`,{className:`mt-2 text-[11px] text-gray-400 dark:text-dark-500`,children:t(`skillsPage.files.empty`)}),i!==null&&(0,$.jsxs)(`div`,{className:`mt-2 space-y-2`,"data-testid":`skill-file-editor`,children:[(0,$.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:t(`skillsPage.files.pathPlaceholder`),dir:`ltr`,"data-testid":`skill-file-path`,className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30 font-mono`,maxLength:200}),(0,$.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),placeholder:t(`skillsPage.files.contentPlaceholder`),rows:6,dir:`ltr`,"data-testid":`skill-file-content`,className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30 font-mono`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>a(null),children:t(`common.cancel`)}),(0,$.jsx)(H,{size:`sm`,disabled:u||!o.trim(),onClick:()=>void m(),"data-testid":`skill-file-save`,children:t(u?`common.saving`:`common.save`)})]})]})]})}var Jr=[{id:`citeSources`,input:{slug:`cite-sources`,name:`Cite sources`,description:`How to cite evidence: numbered references with URLs, no unreferenced claims.`,instructions:`# Citing sources
3
+
4
+ - Every factual claim gets a numbered reference like [1].
5
+ - End with a References section: number, title, URL.
6
+ - If no source exists, say so instead of inventing one.
7
+ `}},{id:`releaseNotes`,input:{slug:`release-notes`,name:`Release notes style`,description:`How release notes are written: grouped, user-facing, no internal ticket ids.`,instructions:`# Release notes style
8
+
9
+ - Group entries under Added, Changed, and Fixed.
10
+ - Write for the user: what they can do now, not how it was built.
11
+ - One line per entry, plain language, no internal ticket ids.
12
+ - Call out breaking changes first, with the migration step.
13
+ `}},{id:`meetingNotes`,input:{slug:`meeting-notes`,name:`Meeting notes format`,description:`How to turn a transcript into decisions, actions, and open questions.`,instructions:`# Meeting notes format
14
+
15
+ - Start with a two-sentence summary of the meeting.
16
+ - Then three sections: Decisions, Action items (owner + due date if stated), Open questions.
17
+ - Keep attribution: who decided or committed to what.
18
+ - Drop small talk entirely; never invent owners or dates.
19
+ `}}],Yr=o(`pages:skills`),Xr=()=>{let{t:e,i18n:t}=y(),[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),[v,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)([]),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null),O=(0,Q.useRef)(null),k=(0,Q.useRef)(null),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(``),[P,I]=(0,Q.useState)(!1),[ee,te]=(0,Q.useState)(!1),[ne,re]=(0,Q.useState)(0),L=(0,Q.useCallback)(()=>re(e=>e+1),[]);(0,Q.useEffect)(()=>{let t=!1;return zt.list().then(n=>{t||(n.success&&n.data?r(n.data):V.error(n.error||e(`skillsPage.loadFailed`)))}).catch(n=>{t||(Yr.error(`Failed to load skills:`,n),V.error(e(`skillsPage.loadFailed`)))}).finally(()=>{t||a(!1)}),()=>{t=!0}},[ne,e]);let R=async t=>{p(!0);try{let n=c?await zt.update(c.id,t):await zt.create(t);n.success?(s(!1),d(null),V.success(e(`skillsPage.saved`)),L()):V.error(n.error||e(`skillsPage.saveFailed`))}catch(t){Yr.error(`Failed to save skill:`,t),V.error(e(`skillsPage.saveFailed`))}finally{p(!1)}},z=async(t,n)=>{_(t.id),r(e=>e.map(e=>e.id===t.id?{...e,enabled:n}:e));try{let e=await zt.update(t.id,{enabled:n});if(!e.success)throw Error(e.error)}catch(n){Yr.error(`Failed to toggle skill:`,n),V.error(e(`skillsPage.toggleFailed`)),r(e=>e.map(e=>e.id===t.id?{...e,enabled:t.enabled}:e))}finally{_(null)}},ie=async()=>{if(!m)return;let t=m;h(null);try{let n=await zt.remove(t.id);if(!n.success)throw Error(n.error);V.success(e(`skillsPage.deleted`)),L()}catch(t){Yr.error(`Failed to delete skill:`,t),V.error(e(`skillsPage.deleteFailed`))}},ae=async t=>{try{let e=await zt.export(t.id);if(!e.success||!e.data)throw Error(e.error);e.data.markdown?zr(`${t.slug}.skill.md`,e.data.markdown):Lr(`${t.slug}.skill.json`,e.data)}catch(t){Yr.error(`Failed to export skill:`,t),V.error(e(`skillsPage.exportFailed`))}},oe=async t=>{try{let n=t.name.endsWith(`.md`)?{markdown:await Br(t)}:await Rr(t),r=await zt.import(n);if(!r.success)throw Error(r.error);V.success(e(`skillsPage.imported`)),L()}catch(t){Yr.error(`Failed to import skill:`,t),V.error(e(`skillsPage.importFailed`))}},se=/\.(md|markdown|txt|text|py|js|mjs|cjs|ts|tsx|jsx|sh|bash|zsh|rb|sql|json|yaml|yml|toml|ini|cfg|csv|tsv|xml|html|css|svg|j2|jinja|tmpl|template)$/i,B=async t=>{try{let n=[...t],r=e=>e.webkitRelativePath||e.name,i=n.filter(e=>e.name.toUpperCase()===`SKILL.MD`).sort((e,t)=>r(e).split(`/`).length-r(t).split(`/`).length)[0];if(!i){V.error(e(`skillsPage.folderImport.missingSkillMd`));return}let a=r(i).slice(0,r(i).length-i.name.length),o=await Br(i),s=[];for(let e of n){if(e===i)continue;let t=r(e);if(t.startsWith(a)&&se.test(e.name)&&!(e.size>2e5)){if(s.length>=32)break;s.push({path:t.slice(a.length),content:await Br(e)})}}let c=await zt.import({markdown:o,files:s});if(!c.success)throw Error(c.error);V.success(e(`skillsPage.folderImport.done`,{count:s.length})),L()}catch(t){Yr.error(`Failed to import the skill folder:`,t),V.error(t instanceof Error&&t.message?t.message:e(`skillsPage.importFailed`))}},ce=async()=>{if(M.trim()){te(!0);try{let t=await zt.importFromUrl(M.trim(),{overwriteSlug:P});if(!t.success)throw Error(t.error);V.success(e(`skillsPage.imported`)),j(!1),N(``),I(!1),L()}catch(t){Yr.error(`Failed to import the skill from a URL:`,t),V.error(t instanceof Error&&t.message?t.message:e(`skillsPage.importFailed`))}finally{te(!1)}}},le=async t=>{x(t),T(!0),C([]);try{let n=await zt.versions(t.id);n.success&&n.data?C(n.data):V.error(n.error||e(`skillsPage.historyFailed`))}catch(t){Yr.error(`Failed to load skill history:`,t),V.error(e(`skillsPage.historyFailed`))}finally{T(!1)}},ue=async t=>{if(v){D(t);try{let n=await zt.rollback(v.id,t);if(!n.success||!n.data)throw Error(n.error);V.success(e(`skillsPage.rolledBack`)),x(null),L()}catch(t){Yr.error(`Failed to roll the skill back:`,t),V.error(e(`skillsPage.rollbackFailed`))}finally{D(null)}}};return(0,$.jsxs)(`div`,{"data-testid":`skills-page`,className:`pb-2`,children:[(0,$.jsx)(Dn,{title:e(`skillsPage.title`),description:e(`skillsPage.description`),actions:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{ref:O,type:`file`,accept:`application/json,.json,text/markdown,.md`,className:`hidden`,"data-testid":`skill-import-input`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&oe(t)}}),(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>O.current?.click(),"data-testid":`skill-import`,children:[(0,$.jsx)(Qe,{className:`me-1.5 h-3.5 w-3.5`}),e(`common.import`)]}),(0,$.jsx)(`input`,{ref:k,type:`file`,multiple:!0,className:`hidden`,"data-testid":`skill-import-folder-input`,webkitdirectory:``,directory:``,onChange:e=>{let t=e.target.files;t&&t.length>0&&B(t),e.target.value=``}}),(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>k.current?.click(),"data-testid":`skill-import-folder`,children:[(0,$.jsx)($e,{className:`me-1.5 h-3.5 w-3.5`}),e(`skillsPage.folderImport.button`)]}),(0,$.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>j(!0),"data-testid":`skill-import-url`,children:[(0,$.jsx)(Ae,{className:`me-1.5 h-3.5 w-3.5`}),e(`skillsPage.importUrl.button`)]}),(0,$.jsxs)(H,{size:`sm`,onClick:()=>{l(null),d(null),s(!0)},"data-testid":`skill-new`,children:[(0,$.jsx)(dt,{className:`me-1.5 h-3.5 w-3.5`}),e(`skillsPage.newSkill`)]})]})}),i?(0,$.jsx)(Et,{srOnly:!0}):n.length===0?(0,$.jsx)(Ot,{icon:Xe,title:e(`skillsPage.empty`),description:e(`skillsPage.emptyHint`)}):(0,$.jsx)(`div`,{className:`space-y-2`,children:n.map(n=>(0,$.jsx)(`div`,{"data-testid":`skill-row`,className:`rounded-2xl border border-black/6 bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-[1_1_16rem] wrap-anywhere`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`max-w-full text-[14px] font-medium text-gray-900 dark:text-dark-900`,children:n.name}),(0,$.jsxs)(`code`,{className:`max-w-full rounded-md bg-black/4 px-1.5 py-0.5 text-[11px] text-gray-500 dark:bg-white/6 dark:text-dark-500`,children:[`$`,n.slug]}),(0,$.jsx)(`span`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:e(`skillsPage.versionLabel`,{version:n.version})})]}),(0,$.jsx)(`p`,{className:`mt-1 text-[12px] text-gray-500 dark:text-dark-500`,children:n.description}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] text-gray-400 dark:text-dark-500`,children:e(`skillsPage.updated`,{when:b(n.updatedAt,t.language)})})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-full shrink-0 flex-wrap items-center gap-1 [&>button]:inline-flex [&>button]:min-h-11 [&>button]:min-w-11 [&>button]:items-center [&>button]:justify-center`,children:[(0,$.jsx)(St,{checked:n.enabled,disabled:g===n.id,onChange:e=>void z(n,e),"aria-label":e(`skillsPage.toggleLabel`,{name:n.name})}),(0,$.jsx)(W,{icon:Me,label:e(`skillsPage.history.open`),testId:`skill-history`,onClick:()=>void le(n)}),(0,$.jsx)(W,{icon:F,label:e(`common.export`),testId:`skill-export`,onClick:()=>void ae(n)}),(0,$.jsx)(W,{icon:ct,label:e(`common.edit`),testId:`skill-edit`,onClick:()=>{l(n),s(!0)}}),(0,$.jsx)(W,{icon:pt,label:e(`common.delete`),testId:`skill-delete`,destructive:!0,onClick:()=>h(n)})]})]})},n.id))}),!i&&(0,$.jsx)(Pr,{title:e(`skillsPage.templatesTitle`),testId:`skill-template`,cards:Jr.map(t=>({id:t.id,name:e(`skillsPage.templates.${t.id}.name`),description:e(`skillsPage.templates.${t.id}.description`),meta:`$${t.input.slug}`})),onPick:e=>{let t=Jr.find(t=>t.id===e);t&&(l(null),d(t.input),s(!0))}}),A&&(0,$.jsx)(Ct,{titleId:`skill-import-url-title`,title:e(`skillsPage.importUrl.title`),subtitle:e(`skillsPage.importUrl.hint`),onClose:()=>j(!1),widthClassName:`max-w-lg`,testId:`skill-import-url-modal`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>j(!1),children:e(`common.cancel`)}),(0,$.jsxs)(H,{size:`sm`,disabled:ee||!M.trim(),onClick:()=>void ce(),"data-testid":`skill-import-url-submit`,children:[ee?(0,$.jsx)(Ce,{className:`me-1.5 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(F,{className:`me-1.5 h-3.5 w-3.5`}),e(`common.import`)]})]}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ce()},placeholder:e(`skillsPage.importUrl.placeholder`),dir:`ltr`,autoFocus:!0,"data-testid":`skill-import-url-source`,className:`w-full rounded-lg border border-gray-300 bg-white px-3 py-2 font-mono text-sm dark:border-dark-300 dark:bg-dark-100`}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-xs text-gray-500 dark:text-gray-400`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:P,onChange:()=>I(e=>!e),className:`h-3.5 w-3.5 accent-primary-600`}),e(`skillsPage.importUrl.overwrite`)]})]})}),(0,$.jsx)(Gr,{open:o,skill:c,prefill:u,saving:f,onClose:()=>{s(!1),d(null)},onSave:e=>void R(e)}),v&&(0,$.jsx)(Ir,{title:e(`skillsPage.history.title`,{name:v.name}),entries:S.map(e=>({version:e.version,body:e.instructions,createdAt:e.createdAt})),loading:w,currentVersion:v.version,rollingBackTo:E,onRollback:e=>void ue(e),onClose:()=>x(null),testId:`skill-history-modal`}),m&&(0,$.jsx)(Ct,{titleId:`skill-delete-title`,title:e(`skillsPage.deleteTitle`),subtitle:e(`skillsPage.deleteConfirm`,{name:m.name}),onClose:()=>h(null),widthClassName:`max-w-sm`,testId:`skill-delete-modal`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>h(null),children:e(`common.cancel`)}),(0,$.jsx)(H,{variant:`danger`,size:`sm`,onClick:()=>void ie(),"data-testid":`skill-delete-confirm`,children:e(`common.delete`)})]})})]})},Zr=({approvals:e,servers:t,revoking:n,onRevoke:r})=>{let{t:i,i18n:a}=y(),o=e=>t.find(t=>t.id===e)?.name??i(`toolsPage.builtinSource`);return(0,$.jsxs)(`section`,{className:`mt-10`,children:[(0,$.jsx)(`h2`,{className:`mb-1 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:i(`toolsPage.approvals.title`)}),(0,$.jsx)(`p`,{className:`mb-3 text-[12px] text-gray-500 dark:text-dark-500`,children:i(`toolsPage.approvals.description`)}),e.length===0?(0,$.jsx)(`p`,{className:`rounded-2xl border border-dashed border-black/8 px-4 py-6 text-center text-[12px] text-gray-400 dark:border-white/8 dark:text-dark-500`,children:i(`toolsPage.approvals.empty`)}):(0,$.jsx)(`div`,{className:`space-y-1.5`,"data-testid":`tool-approvals`,children:e.map(e=>(0,$.jsxs)(`div`,{"data-testid":`tool-approval-row`,className:`flex flex-wrap items-center justify-between gap-3 rounded-xl border border-black/5 bg-white/50 px-3 py-2 dark:border-white/6 dark:bg-dark-100/50`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-[1_1_16rem]`,children:[(0,$.jsxs)(`p`,{className:`wrap-break-word text-[13px] text-gray-900 wrap-anywhere dark:text-dark-900`,children:[(0,$.jsx)(`code`,{children:e.toolName}),` · `,o(e.serverId)]}),(0,$.jsxs)(`p`,{className:`truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[i(`toolsPage.approvals.scope.${e.scope}`),` · `,b(e.createdAt,a.language)]})]}),(0,$.jsx)(H,{size:`sm`,variant:`outline`,disabled:n===e.id,onClick:()=>r(e.id),"data-testid":`tool-approval-revoke`,children:i(`toolsPage.approvals.revoke`)})]},e.id))})]})},Qr=o(`components:tools`),$r=e=>e.response?.data?.error||(e instanceof Error&&!(`response`in e)&&e.message?e.message:void 0),ei=({server:e,isAdmin:t,onEdit:n,onDelete:r,onChanged:i})=>{let{t:a}=y(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(``),[v,b]=(0,Q.useState)(!1),x=e.authMode===`oauth`,[S,w]=(0,Q.useState)(null),[T,E]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!x)return;let t=!1;return Rt.getOAuthStatus(e.id).then(e=>{!t&&e.success&&e.data&&w(e.data)}).catch(e=>{Qr.error(`Failed to read the OAuth status:`,e)}),()=>{t=!0}},[x,e.id]);let D=S?.connected??e.hasCredential,O=async()=>{E(!0);try{let t=await Rt.startOAuth(e.id);if(!t.success||!t.data?.authorizeUrl)throw Error(t.error);window.location.assign(t.data.authorizeUrl)}catch(e){Qr.error(`Failed to start the OAuth connection:`,e),V.error($r(e)||a(`toolsPage.oauth.connectFailed`)),E(!1)}},k=async()=>{E(!0);try{let t=await Rt.disconnectOAuth(e.id);if(!t.success)throw Error(t.error);w({connected:!1,configured:!0}),V.success(a(`toolsPage.oauth.disconnected`)),i()}catch(e){Qr.error(`Failed to disconnect the tool server:`,e),V.error($r(e)||a(`toolsPage.oauth.disconnectFailed`))}finally{E(!1)}},A=async()=>{d(!0);try{let t=await Rt.getServer(e.id);t.success&&t.data?l(t.data.tools):V.error(t.error||a(`toolsPage.toolsLoadFailed`))}catch(e){Qr.error(`Failed to load pinned tools:`,e),V.error(a(`toolsPage.toolsLoadFailed`))}finally{d(!1)}},j=()=>{let e=!o;s(e),e&&c.length===0&&A()},M=async()=>{p(!0);try{let t=await Rt.refreshServer(e.id);if(!t.success)throw Error(t.error);V.success(a(`toolsPage.refreshed`)),await A(),i()}catch(e){Qr.error(`Failed to refresh the tool server:`,e),V.error($r(e)||a(`toolsPage.refreshFailed`))}finally{p(!1)}},P=async(t,n)=>{l(e=>e.map(e=>e.name===t.name?{...e,...n}:e));try{let r=await Rt.overrideServerTool(e.id,t.name,n);if(!r.success)throw Error(r.error)}catch(e){Qr.error(`Failed to override the tool:`,e),V.error(a(`toolsPage.overrideFailed`)),l(e=>e.map(e=>e.name===t.name?t:e))}},F=async()=>{if(g.trim()){b(!0);try{let t=await Rt.setCredential(e.id,g);if(!t.success)throw Error(t.error);_(``),h(!1),V.success(a(`toolsPage.credentialSaved`)),i()}catch(e){Qr.error(`Failed to save the credential:`,e),V.error(a(`toolsPage.credentialSaveFailed`))}finally{b(!1)}}},I=async()=>{b(!0);try{let t=await Rt.deleteCredential(e.id);if(!t.success)throw Error(t.error);V.success(a(`toolsPage.credentialRemoved`)),i()}catch(e){Qr.error(`Failed to remove the credential:`,e),V.error(a(`toolsPage.credentialRemoveFailed`))}finally{b(!1)}};return(0,$.jsxs)(`div`,{"data-testid":`tool-server-row`,className:`rounded-2xl border border-black/6 bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-[1_1_16rem]`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`min-w-0 max-w-full wrap-break-word text-[14px] font-medium text-gray-900 wrap-anywhere dark:text-dark-900`,children:e.name}),(0,$.jsx)(`span`,{className:`rounded-full bg-black/4 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-gray-500 dark:bg-white/6 dark:text-dark-500`,children:a(`toolsPage.kinds.${e.kind}`)}),(0,$.jsx)(`span`,{className:C(`rounded-full px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,e.enabled?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`:`bg-gray-500/10 text-gray-500 dark:text-dark-500`),children:e.enabled?a(`common.enabled`):a(`common.disabled`)}),e.authMode!==`none`&&(0,$.jsx)(`span`,{className:C(`rounded-full px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,(x?D:e.hasCredential)?`bg-primary-500/10 text-primary-600 dark:text-primary-400`:`bg-amber-500/10 text-amber-600 dark:text-amber-400`),children:x?a(D?`toolsPage.oauth.connected`:`toolsPage.oauth.notConnected`):e.hasCredential?a(`toolsPage.credentialSet`):a(`toolsPage.credentialMissing`)})]}),e.description&&(0,$.jsx)(`p`,{className:`mt-1 wrap-break-word text-[12px] text-gray-500 wrap-anywhere dark:text-dark-500`,children:e.description}),t&&e.baseUrl&&(0,$.jsxs)(`p`,{className:`mt-1 truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[e.baseUrl,` · `,a(`toolsPage.specRevision`,{revision:e.specRevision}),e.specDigest&&` · ${e.specDigest.slice(0,12)}`]})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 max-w-full shrink-0 flex-wrap items-center gap-1 [&>button]:inline-flex [&>button]:min-h-11 [&>button]:min-w-11 [&>button]:items-center [&>button]:justify-center`,children:[e.authMode!==`none`&&!x&&(0,$.jsx)(W,{icon:pe,label:a(`toolsPage.credential`),testId:`tool-credential-toggle`,onClick:()=>h(e=>!e)}),x&&(0,$.jsx)(W,{icon:ce,label:a(`toolsPage.oauth.title`),testId:`tool-oauth-toggle`,onClick:()=>h(e=>!e)}),t&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(W,{icon:be,label:a(`toolsPage.refresh`),testId:`tool-server-refresh`,disabled:f,onClick:()=>void M()}),(0,$.jsx)(W,{icon:ct,label:a(`common.edit`),testId:`tool-server-edit`,onClick:()=>n(e)}),(0,$.jsx)(W,{icon:pt,label:a(`common.delete`),testId:`tool-server-delete`,destructive:!0,onClick:()=>r(e)}),(0,$.jsx)(W,{icon:o?N:Fe,label:a(`toolsPage.pinnedTools`),testId:`tool-server-expand`,onClick:j})]})]})]}),m&&x&&(0,$.jsxs)(`div`,{"data-testid":`tool-oauth-panel`,className:`mt-3 rounded-xl border border-black/6 bg-black/2 p-3 dark:border-white/[0.07] dark:bg-white/3`,children:[(0,$.jsx)(`p`,{className:`mb-2 text-[11px] text-gray-500 dark:text-dark-500`,children:a(`toolsPage.oauth.hint`)}),D&&S?.expiresAt&&(0,$.jsx)(`p`,{className:`mb-2 text-[11px] text-gray-400 dark:text-dark-500`,children:a(`toolsPage.oauth.expiresAt`,{when:new Date(S.expiresAt).toLocaleString()})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(H,{size:`sm`,disabled:T,onClick:()=>void O(),"data-testid":`tool-oauth-connect`,children:a(D?`toolsPage.oauth.reconnect`:`toolsPage.oauth.connect`)}),D&&(0,$.jsx)(H,{size:`sm`,variant:`outline`,disabled:T,onClick:()=>void k(),"data-testid":`tool-oauth-disconnect`,children:a(`toolsPage.oauth.disconnect`)})]})]}),m&&e.authMode!==`none`&&!x&&(0,$.jsxs)(`div`,{"data-testid":`tool-credential-panel`,className:`mt-3 rounded-xl border border-black/6 bg-black/2 p-3 dark:border-white/[0.07] dark:bg-white/3`,children:[(0,$.jsx)(`p`,{className:`mb-2 text-[11px] text-gray-500 dark:text-dark-500`,children:a(`toolsPage.credentialHint`)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`password`,value:g,onChange:e=>_(e.target.value),placeholder:a(`toolsPage.credentialPlaceholder`),"aria-label":a(`toolsPage.credential`),autoComplete:`off`,"data-testid":`tool-credential-secret`,className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30 min-w-0 max-w-full sm:w-72`}),(0,$.jsx)(H,{size:`sm`,disabled:v||!g.trim(),onClick:()=>void F(),"data-testid":`tool-credential-save`,children:a(`common.save`)}),e.hasCredential&&(0,$.jsx)(H,{size:`sm`,variant:`outline`,disabled:v,onClick:()=>void I(),"data-testid":`tool-credential-remove`,children:a(`toolsPage.credentialRemove`)})]})]}),t&&o&&(0,$.jsxs)(`div`,{className:`mt-3 rounded-xl border border-black/6 p-3 dark:border-white/[0.07]`,children:[(0,$.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:a(`toolsPage.pinnedTools`)}),u?(0,$.jsx)(`div`,{className:`flex justify-center py-6`,children:(0,$.jsx)(Ce,{className:`h-4 w-4 animate-spin text-gray-400`})}):c.length===0?(0,$.jsx)(`p`,{className:`py-4 text-center text-[12px] text-gray-400 dark:text-dark-500`,children:a(`toolsPage.noPinnedTools`)}):(0,$.jsx)(`div`,{className:`space-y-1.5`,children:c.map(e=>(0,$.jsxs)(`div`,{"data-testid":`tool-server-tool`,className:`flex flex-wrap items-center justify-between gap-3 rounded-lg bg-black/2 px-2.5 py-2 dark:bg-white/3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-[1_1_16rem]`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`code`,{className:`min-w-0 max-w-full wrap-break-word text-[12px] text-gray-900 wrap-anywhere dark:text-dark-900`,children:e.name}),e.sideEffect&&(0,$.jsx)(`span`,{className:`rounded-full bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide text-amber-600 dark:text-amber-400`,children:a(`toolsPage.sideEffect`)})]}),e.description&&(0,$.jsx)(`p`,{className:`mt-0.5 wrap-break-word text-[11px] text-gray-500 wrap-anywhere dark:text-dark-500`,children:e.description})]}),(0,$.jsxs)(`div`,{className:`flex max-w-full flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`label`,{className:`flex min-w-0 items-center gap-1.5 text-[11px] text-gray-500 dark:text-dark-500`,children:[a(`toolsPage.sideEffectOverride`),(0,$.jsx)(St,{checked:e.sideEffect,onChange:t=>void P(e,{sideEffect:t})})]}),(0,$.jsxs)(`label`,{className:`flex min-w-0 items-center gap-1.5 text-[11px] text-gray-500 dark:text-dark-500`,children:[a(`common.enabled`),(0,$.jsx)(St,{checked:e.enabled,onChange:t=>void P(e,{enabled:t})})]})]})]},e.name))})]})]})},ti=[`openapi`,`mcp`],ni=[`none`,`bearer`,`header`,`oauth`],ri=[`admins-only`,`all-users`,`granted`];function ii({open:e,server:t,prefill:n=null,saving:r,onClose:i,onSave:a}){return e?(0,$.jsx)(ai,{server:t,prefill:n,saving:r,onClose:i,onSave:a},t?.id??(n?`template-${n.name}`:`new`)):null}function ai({server:e,prefill:t,saving:n,onClose:r,onSave:i}){let{t:a}=y(),o=e!==null,s=e??t,[c,l]=(0,Q.useState)(s?.name??``),[u,d]=(0,Q.useState)(s?.description??``),[f,p]=(0,Q.useState)(s?.kind??`openapi`),[m,h]=(0,Q.useState)(s?.baseUrl??``),[g,_]=(0,Q.useState)(t?.specUrl??``),[v,b]=(0,Q.useState)(s?.authMode??`none`),[x,S]=(0,Q.useState)(s?.authHeader??``),[C,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(``),[D,O]=(0,Q.useState)(s?.accessMode??`admins-only`),[k,A]=(0,Q.useState)(s?.enabled??!0),[j,M]=(0,Q.useState)(e?.timeoutMs?String(e.timeoutMs):``),[N,P]=(0,Q.useState)(e?.maxResponseBytes?String(e.maxResponseBytes):``),F=c.trim().length>0&&(o||m.trim().length>0)&&(v!==`header`||x.trim().length>0),I=e=>{let t=Number(e);return e.trim()&&Number.isFinite(t)&&t>0?t:void 0};return(0,$.jsxs)(Ct,{titleId:`tool-server-modal-title`,title:a(o?`toolsPage.editServer`:`toolsPage.registerServer`),subtitle:o?void 0:a(`toolsPage.registerHint`),onClose:r,widthClassName:`max-w-2xl`,testId:`tool-server-modal`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:r,children:a(`common.cancel`)}),(0,$.jsx)(H,{size:`sm`,onClick:()=>{if(!F)return;let e={name:c.trim(),description:u.trim()||void 0,authMode:v,authHeader:v===`header`?x.trim():void 0,accessMode:D,enabled:k,timeoutMs:I(j),maxResponseBytes:I(N)};if(o){i(e);return}i({...e,kind:f,baseUrl:m.trim(),specUrl:f===`openapi`&&g.trim()?g.trim():void 0,oauthClientId:v===`oauth`&&C.trim()?C.trim():void 0,oauthClientSecret:v===`oauth`&&T.trim()?T.trim():void 0})},disabled:n||!F,"data-testid":`tool-server-save`,children:a(n?`common.saving`:`common.save`)})]}),children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-name`,className:G,children:a(`toolsPage.form.name`)}),(0,$.jsx)(`input`,{id:`tool-server-name`,"data-testid":`tool-server-name`,type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`toolsPage.form.namePlaceholder`),className:U,maxLength:200,autoFocus:!0})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-kind`,className:G,children:a(`toolsPage.form.kind`)}),(0,$.jsx)(`select`,{id:`tool-server-kind`,value:f,disabled:o,onChange:e=>p(e.target.value),className:U,children:ti.map(e=>(0,$.jsx)(`option`,{value:e,children:a(`toolsPage.kinds.${e}`)},e))})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-description`,className:G,children:a(`toolsPage.form.description`)}),(0,$.jsx)(`input`,{id:`tool-server-description`,type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:a(`toolsPage.form.descriptionPlaceholder`),className:U,maxLength:500})]}),!o&&(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-base-url`,className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:a(`toolsPage.form.baseUrl`)}),(0,$.jsx)(`input`,{id:`tool-server-base-url`,"data-testid":`tool-server-base-url`,type:`url`,value:m,onChange:e=>h(e.target.value),placeholder:`https://api.example.com`,className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`})]}),f===`openapi`&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-spec-url`,className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:a(`toolsPage.form.specUrl`)}),(0,$.jsx)(`input`,{id:`tool-server-spec-url`,type:`url`,value:g,onChange:e=>_(e.target.value),placeholder:`https://api.example.com/openapi.json`,className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:a(`toolsPage.form.specUrlHint`)})]})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-auth-mode`,className:G,children:a(`toolsPage.form.authMode`)}),(0,$.jsx)(`select`,{id:`tool-server-auth-mode`,value:v,onChange:e=>b(e.target.value),className:U,children:ni.map(e=>(0,$.jsx)(`option`,{value:e,children:a(`toolsPage.authModes.${e}`)},e))})]}),v===`header`&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-auth-header`,className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:a(`toolsPage.form.authHeader`)}),(0,$.jsx)(`input`,{id:`tool-server-auth-header`,type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`X-Api-Key`,className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`,maxLength:120})]}),v===`oauth`&&!o&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-oauth-client-id`,className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:a(`toolsPage.form.oauthClientId`)}),(0,$.jsx)(`input`,{id:`tool-server-oauth-client-id`,"data-testid":`tool-server-oauth-client-id`,type:`text`,value:C,onChange:e=>w(e.target.value),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`,maxLength:200,autoComplete:`off`}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:a(`toolsPage.form.oauthClientIdHint`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-oauth-client-secret`,className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:a(`toolsPage.form.oauthClientSecret`)}),(0,$.jsx)(`input`,{id:`tool-server-oauth-client-secret`,type:`password`,value:T,onChange:e=>E(e.target.value),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`,maxLength:400,autoComplete:`off`})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-access-mode`,className:G,children:a(`toolsPage.form.accessMode`)}),(0,$.jsx)(`select`,{id:`tool-server-access-mode`,value:D,onChange:e=>O(e.target.value),className:U,children:ri.map(e=>(0,$.jsx)(`option`,{value:e,children:a(`toolsPage.accessModes.${e}`)},e))})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-timeout`,className:G,children:a(`toolsPage.form.timeoutMs`)}),(0,$.jsx)(`input`,{id:`tool-server-timeout`,type:`number`,min:1,value:j,onChange:e=>M(e.target.value),placeholder:a(`toolsPage.form.serverDefault`),className:U})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`tool-server-max-bytes`,className:G,children:a(`toolsPage.form.maxResponseBytes`)}),(0,$.jsx)(`input`,{id:`tool-server-max-bytes`,type:`number`,min:1,value:N,onChange:e=>P(e.target.value),placeholder:a(`toolsPage.form.serverDefault`),className:U})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 rounded-xl border border-black/6 px-3 py-2.5 dark:border-white/[0.07]`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:a(`toolsPage.form.enabled`)}),(0,$.jsx)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:a(`toolsPage.form.enabledHint`)})]}),(0,$.jsx)(St,{checked:k,onChange:A})]})]})}var oi=[{id:`exa`,input:{name:`Exa`,kind:`mcp`,baseUrl:`https://mcp.exa.ai/mcp?tools=web_search_exa,web_fetch_exa`,authMode:`none`,accessMode:`admins-only`}},{id:`internalOpenApi`,input:{name:`Internal API`,description:`A starting point for your own OpenAPI 3.x JSON service. Replace the URLs; internal hostnames also need TOOLS_PRIVATE_NETWORK_ALLOWLIST on the server.`,kind:`openapi`,baseUrl:`https://api.example.internal`,specUrl:`https://api.example.internal/openapi.json`,authMode:`bearer`,accessMode:`admins-only`}},{id:`mcpServer`,input:{name:`MCP server`,description:`A starting point for an MCP server over Streamable HTTP. Replace the URL with your server’s endpoint; its tool list is fetched and pinned when you register.`,kind:`mcp`,baseUrl:`https://mcp.example.com/mcp`,authMode:`header`,authHeader:`X-Api-Key`,accessMode:`admins-only`}}],si=o(`pages:tools`),ci=e=>e.response?.data?.error,li=()=>{let{t:e}=y(),t=$t(e=>e.isAdmin()),[n,r]=(0,Q.useState)([]),[i,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),[v,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(0),C=(0,Q.useCallback)(()=>S(e=>e+1),[]);(0,Q.useEffect)(()=>{let t=new URLSearchParams(window.location.search),n=t.get(`mcpOAuth`);if(!n)return;n===`connected`?V.success(e(`toolsPage.oauth.callbackSuccess`)):V.error(e(`toolsPage.oauth.callbackError`)),t.delete(`mcpOAuth`),t.delete(`serverId`);let r=t.toString();window.history.replaceState({},``,`${window.location.pathname}${r?`?${r}`:``}${window.location.hash}`)},[e]),(0,Q.useEffect)(()=>{let t=!1;return Promise.all([Rt.listServers(),Rt.listApprovals()]).then(([n,i])=>{t||(n.success&&n.data?r(n.data):V.error(n.error||e(`toolsPage.loadFailed`)),i.success&&i.data&&a(i.data.standing))}).catch(n=>{t||(si.error(`Failed to load tool servers:`,n),V.error(e(`toolsPage.loadFailed`)))}).finally(()=>{t||s(!1)}),()=>{t=!0}},[x,e]);let w=async t=>{h(!0);try{let n=u?await Rt.updateServer(u.id,t):await Rt.registerServer(t);n.success?(l(!1),p(null),V.success(e(`toolsPage.saved`)),C()):V.error(n.error||e(`toolsPage.saveFailed`))}catch(t){si.error(`Failed to save the tool server:`,t),V.error(ci(t)||e(`toolsPage.saveFailed`))}finally{h(!1)}},T=async()=>{if(!g)return;let t=g;_(null);try{let n=await Rt.deleteServer(t.id);if(!n.success)throw Error(n.error);V.success(e(`toolsPage.deleted`)),C()}catch(t){si.error(`Failed to delete the tool server:`,t),V.error(ci(t)||e(`toolsPage.deleteFailed`))}},E=async t=>{b(t);try{let n=await Rt.revokeApproval(t);if(!n.success)throw Error(n.error);a(e=>e.filter(e=>e.id!==t)),V.success(e(`toolsPage.approvals.revoked`))}catch(t){si.error(`Failed to revoke the approval:`,t),V.error(e(`toolsPage.approvals.revokeFailed`))}finally{b(null)}};return(0,$.jsxs)(`div`,{"data-testid":`tools-page`,className:`pb-2`,children:[(0,$.jsx)(Dn,{title:e(`toolsPage.title`),description:e(`toolsPage.description`),actions:t?(0,$.jsxs)(H,{size:`sm`,onClick:()=>{d(null),p(null),l(!0)},"data-testid":`tool-server-new`,children:[(0,$.jsx)(dt,{className:`me-1.5 h-3.5 w-3.5`}),e(`toolsPage.registerServer`)]}):void 0}),(0,$.jsx)(`p`,{className:`mb-5 rounded-xl border border-black/6 bg-black/2 px-3.5 py-2.5 text-[12px] leading-5 text-gray-500 dark:border-white/[0.07] dark:bg-white/3 dark:text-dark-500`,children:e(`toolsPage.approvalNotice`)}),o?null:n.length===0?(0,$.jsxs)(`div`,{className:`px-3 py-16 text-center`,children:[(0,$.jsx)(it,{className:`mx-auto mb-3 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:e(`toolsPage.empty`)}),(0,$.jsx)(`p`,{className:`mx-auto mt-2 max-w-md text-[13px] leading-6 text-gray-400 dark:text-dark-500`,children:e(t?`toolsPage.emptyHintAdmin`:`toolsPage.emptyHintUser`)})]}):(0,$.jsx)(`div`,{className:`space-y-2`,children:n.map(e=>(0,$.jsx)(ei,{server:e,isAdmin:t,onEdit:e=>{d(e),l(!0)},onDelete:_,onChanged:C},e.id))}),(0,$.jsx)(Zr,{approvals:i,servers:n,revoking:v,onRevoke:e=>void E(e)}),t&&!o&&(0,$.jsx)(Pr,{title:e(`toolsPage.templatesTitle`),testId:`tool-server-template`,cards:oi.map(t=>({id:t.id,name:e(`toolsPage.templates.${t.id}.name`),description:e(`toolsPage.templates.${t.id}.description`),meta:t.input.baseUrl})),onPick:t=>{let n=oi.find(e=>e.id===t);n&&(d(null),p({...n.input,description:n.input.description??e(`toolsPage.templates.${n.id}.description`)}),l(!0))}}),(0,$.jsx)(ii,{open:c,server:u,prefill:f,saving:m,onClose:()=>{l(!1),p(null)},onSave:e=>void w(e)}),g&&(0,$.jsx)(Ct,{titleId:`tool-server-delete-title`,title:e(`toolsPage.deleteTitle`),subtitle:e(`toolsPage.deleteConfirm`,{name:g.name}),onClose:()=>_(null),widthClassName:`max-w-sm`,testId:`tool-server-delete-modal`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>_(null),children:e(`common.cancel`)}),(0,$.jsx)(H,{variant:`danger`,size:`sm`,onClick:()=>void T(),"data-testid":`tool-server-delete-confirm`,children:e(`common.delete`)})]})})]})};function ui({expanded:e,models:t,search:n,task:r,sort:i,loadingModels:a,canInstallModels:o,expandedModelId:s,loadingGgufModelId:c,ggufFiles:l,pullingModel:u,pullProgress:d,setSearch:f,setTask:p,setSort:m,onToggle:h,onToggleModel:g,onPullGguf:_,onCancelPull:v,onRefresh:b}){let{t:x}=y();return(0,$.jsxs)(`div`,{className:C(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/3`,`border-gray-200/80 dark:border-white/10`),children:[(0,$.jsxs)(`button`,{onClick:h,"aria-expanded":e,className:C(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(lt,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:x(`modelManager.sections.huggingface`,`HuggingFace Hub`)}),t.length>0&&(0,$.jsxs)(`span`,{className:C(`px-2 py-0.5 rounded-full text-xs font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-600 dark:text-gray-400`),children:[t.length,` `,x(`modelManager.library.available`,`available`)]})]}),e?(0,$.jsx)(Ne,{className:`h-5 w-5 text-gray-500`}):(0,$.jsx)(N,{className:`h-5 w-5 text-gray-500`})]}),e&&(0,$.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(oe,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400 dark:text-gray-500`}),(0,$.jsx)(`input`,{type:`text`,value:n,onChange:e=>f(e.target.value),placeholder:x(`modelManager.huggingface.search`,`Search HuggingFace models...`),className:C(`w-full rounded-xl border py-2 pe-4 ps-10 text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`)})]}),(0,$.jsxs)(`select`,{value:r,onChange:e=>p(e.target.value),className:C(`px-3 py-2 rounded-lg border text-sm min-w-[160px]`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`),children:[(0,$.jsx)(`option`,{value:`text-generation`,children:x(`modelManager.huggingface.tasks.textGen`,`Text Generation`)}),(0,$.jsx)(`option`,{value:`text-to-speech`,children:x(`modelManager.huggingface.tasks.tts`,`Text to Speech`)}),(0,$.jsx)(`option`,{value:`text-to-image`,children:x(`modelManager.huggingface.tasks.image`,`Text to Image`)}),(0,$.jsx)(`option`,{value:`automatic-speech-recognition`,children:x(`modelManager.huggingface.tasks.stt`,`Speech Recognition`)})]}),(0,$.jsxs)(`select`,{value:i,onChange:e=>m(e.target.value),className:C(`px-3 py-2 rounded-lg border text-sm min-w-[140px]`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`),children:[(0,$.jsx)(`option`,{value:`downloads`,children:x(`modelManager.huggingface.sort.downloads`,`Most Downloads`)}),(0,$.jsx)(`option`,{value:`likes`,children:x(`modelManager.huggingface.sort.likes`,`Most Liked`)}),(0,$.jsx)(`option`,{value:`lastModified`,children:x(`modelManager.huggingface.sort.recent`,`Recently Updated`)})]})]}),!o&&(0,$.jsx)(`p`,{className:`text-xs text-ink`,children:x(`modelManager.pull.restricted`)}),a?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,$.jsx)(me,{className:`h-5 w-5 animate-spin text-gray-400`})}):t.length===0?(0,$.jsx)(`div`,{className:`text-center py-8 text-gray-500`,children:x(`modelManager.huggingface.noResults`,`No models found. Try adjusting your search or filters.`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:t.map(e=>(0,$.jsx)(di,{model:e,expanded:s===e.id,loadingGguf:c===e.id,ggufFiles:l[e.id]||[],pullingModel:u,pullProgress:d,canInstallModels:o,onToggle:()=>g(e.id),onPullGguf:_,onCancelPull:v},e.id))}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[(0,$.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,className:C(`inline-flex items-center gap-1.5 text-xs`,`text-primary-600 dark:text-primary-400`,`hover:underline`),children:[(0,$.jsx)(L,{className:`h-3 w-3`}),x(`modelManager.huggingface.browseAll`,`Browse all on HuggingFace`)]}),(0,$.jsxs)(H,{onClick:b,variant:`outline`,size:`sm`,disabled:a,className:C(`gap-1.5`,``,``),children:[(0,$.jsx)(be,{className:C(`h-3.5 w-3.5`,a&&`animate-spin`)}),x(`modelManager.library.refresh`,`Refresh`)]})]})]})]})}function di({model:e,expanded:t,loadingGguf:n,ggufFiles:r,pullingModel:i,pullProgress:a,canInstallModels:o,onToggle:s,onPullGguf:c,onCancelPull:l}){let{t:u}=y();return(0,$.jsxs)(`div`,{className:C(`rounded-lg border transition-all overflow-hidden`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`hover:shadow-md hover:border-gray-300 dark:hover:border-dark-400`),children:[(0,$.jsxs)(`div`,{className:`p-4 cursor-pointer`,onClick:s,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-2`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800 truncate`,children:e.id}),e.gated&&(0,$.jsx)(`span`,{className:C(`px-1.5 py-0.5 rounded-sm text-xs`,`bg-yellow-500/20 dark:bg-yellow-900/30`,`text-ink`),children:u(`modelManager.huggingface.gated`,`Gated`)})]}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-0.5`,children:[u(`modelManager.huggingface.by`,`by`),` `,e.author]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,$.jsx)(`a`,{href:`https://huggingface.co/${e.id}`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg hover:bg-gray-200 dark:hover:bg-dark-300 transition-colors`,title:u(`modelManager.huggingface.viewOnHF`,`View on HuggingFace`),children:(0,$.jsx)(L,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`})}),(0,$.jsx)(N,{className:C(`h-4 w-4 text-gray-400 transition-transform`,t&&`rotate-180`)})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-500 dark:text-dark-600`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(F,{className:`h-3.5 w-3.5`}),mi(e.downloads)]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(Ie,{className:`h-3.5 w-3.5`}),mi(e.likes)]}),e.pipeline_tag&&(0,$.jsx)(`span`,{className:C(`px-1.5 py-0.5 rounded-sm`,`bg-gray-200 dark:bg-dark-300`),children:e.pipeline_tag})]})]}),t&&(0,$.jsx)(fi,{modelId:e.id,loading:n,files:r,pullingModel:i,pullProgress:a,canInstallModels:o,onPullGguf:c,onCancelPull:l})]})}function fi({modelId:e,loading:t,files:n,pullingModel:r,pullProgress:i,canInstallModels:a,onPullGguf:o,onCancelPull:s}){let{t:c}=y();return(0,$.jsx)(`div`,{className:`px-4 pb-4 pt-1 border-t border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100`,children:t?(0,$.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,$.jsx)(me,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,$.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:c(`modelManager.huggingface.checkingGguf`)})]}):n.length===0?(0,$.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:c(`modelManager.huggingface.noGgufAvailable`)}):(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 mb-2`,children:c(`modelManager.huggingface.ggufFilesCount`,{count:n.length})}),n.map(e=>(0,$.jsx)(pi,{file:e,pulling:r===e.ollamaCommand,pullProgress:i,canInstallModels:a,disabled:!!r||!a,onPullGguf:o,onCancelPull:s},e.filename)),r?.startsWith(`hf.co/`)&&r.includes(e)&&i?.percent!==void 0&&(0,$.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,$.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${i.percent}%`}})})]})})}function pi({file:e,pulling:t,disabled:n,pullProgress:r,onPullGguf:i,onCancelPull:a}){let{t:o}=y();return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 truncate`,children:e.filename}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,$.jsx)(`span`,{children:e.sizeFormatted}),e.quantization&&(0,$.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-sm bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-400`,children:e.quantization})]})]}),t?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:r?.percent===void 0?`...`:`${r.percent}%`}),(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),a()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,$.jsx)(Ye,{className:`h-4 w-4`})})]}):(0,$.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e.ollamaCommand,e.filename)},disabled:n,className:C(`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,$.jsx)(F,{className:`h-3 w-3 inline mr-1`}),o(`models.pull`)]})]})}function mi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e}function hi({expanded:e,models:t,onToggle:n,isModelRunning:r,formatSize:i,onShowModel:a,onCopyModel:o,onDeleteModel:s}){let{t:c}=y();return(0,$.jsxs)(`div`,{className:C(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/3`,`border-gray-200/80 dark:border-white/10`),children:[(0,$.jsxs)(`button`,{onClick:n,"aria-expanded":e,className:C(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(P,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:c(`modelManager.sections.local`)}),(0,$.jsxs)(`span`,{className:C(`px-2 py-0.5 rounded-full text-xs font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-600 dark:text-gray-400`),children:[t.length,` `,c(`modelManager.local.installed`)]})]}),e?(0,$.jsx)(Ne,{className:`h-5 w-5 text-gray-500`}):(0,$.jsx)(N,{className:`h-5 w-5 text-gray-500`})]}),e&&(0,$.jsx)(`div`,{className:`p-4 pt-0`,children:t.length===0?(0,$.jsxs)(`div`,{className:C(`text-center py-12 rounded-lg border-2 border-dashed`,`border-gray-200 dark:border-dark-300`),children:[(0,$.jsx)(P,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,$.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mb-2`,children:c(`modelManager.local.noModels`)}),(0,$.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-500`,children:c(`modelManager.local.pullToStart`)})]}):(0,$.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,$.jsx)(gi,{model:e,running:r(e.name),formatSize:i,onShowModel:a,onCopyModel:o,onDeleteModel:s},e.name))})})]})}function gi({model:e,running:t,formatSize:n,onShowModel:r,onCopyModel:i,onDeleteModel:a}){let{t:o}=y();return(0,$.jsx)(`div`,{className:C(`p-4 rounded-lg border transition-colors`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`hover:bg-gray-100 dark:hover:bg-dark-200`),children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),t&&(0,$.jsxs)(`span`,{className:C(`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-green-100 dark:bg-green-900/30`,`text-green-700 dark:text-green-400`),children:[(0,$.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse`}),o(`modelManager.local.running`)]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-sm text-gray-600 dark:text-dark-600 mt-2`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(P,{className:`h-3.5 w-3.5`}),n(e.size)]}),e.details?.parameter_size&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(he,{className:`h-3.5 w-3.5`}),e.details.parameter_size]}),e.details?.quantization_level&&(0,$.jsx)(`span`,{className:C(`px-1.5 py-0.5 rounded-sm text-xs`,`bg-gray-200 dark:bg-dark-300`,`text-gray-600 dark:text-gray-400`),children:e.details.quantization_level}),e.details?.family&&(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-gray-500`,children:e.details.family})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-400 dark:text-dark-500 mt-2`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(ee,{className:`h-3 w-3`}),new Date(e.modified_at).toLocaleDateString()]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1 font-mono truncate max-w-[200px]`,title:e.digest,children:[(0,$.jsx)(xe,{className:`h-3 w-3`}),e.digest.slice(0,12),`...`]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,$.jsxs)(H,{onClick:()=>r(e.name),variant:`outline`,size:`sm`,className:C(`gap-1.5`,``,``),children:[(0,$.jsx)(rt,{className:`h-3.5 w-3.5`}),o(`modelManager.local.info`)]}),(0,$.jsxs)(H,{onClick:()=>i(e.name),variant:`outline`,size:`sm`,className:C(`gap-1.5`,``,``),children:[(0,$.jsx)(_e,{className:`h-3.5 w-3.5`}),o(`modelManager.local.copy`)]}),(0,$.jsxs)(H,{onClick:()=>a(e.name),variant:`outline`,size:`sm`,className:C(`gap-1.5`,`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,``,``),children:[(0,$.jsx)(pt,{className:`h-3.5 w-3.5`}),o(`modelManager.local.delete`)]})]})]})})}function _i({expanded:e,models:t,totalAvailable:n,categories:r,filter:i,search:a,loading:o,pulling:s,canInstallModels:c,pullSectionExpanded:l,setFilter:u,setSearch:d,isModelInstalled:f,normalizeCloudPullName:p,onToggle:m,onTogglePullSection:h,onPullModel:g,onRefresh:_}){let{t:v}=y();return(0,$.jsxs)(`div`,{className:C(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/3`,`border-gray-200/80 dark:border-white/10`),children:[(0,$.jsxs)(`button`,{onClick:m,"aria-expanded":e,className:C(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(bt,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:v(`modelManager.sections.library`)}),(0,$.jsxs)(`span`,{className:C(`px-2 py-0.5 rounded-full text-xs font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-600 dark:text-gray-400`),children:[n,` `,v(`modelManager.library.available`)]})]}),e?(0,$.jsx)(Ne,{className:`h-5 w-5 text-gray-500`}):(0,$.jsx)(N,{className:`h-5 w-5 text-gray-500`})]}),e&&(0,$.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(oe,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400 dark:text-gray-500`}),(0,$.jsx)(`input`,{type:`text`,value:a,onChange:e=>d(e.target.value),placeholder:v(`modelManager.library.search`),className:C(`w-full rounded-xl border py-2 pe-4 ps-10 text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`)})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ze,{className:`h-4 w-4 text-gray-400`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>(0,$.jsx)(`button`,{onClick:()=>u(e),className:C(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,i===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))})]})]}),o?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,$.jsx)(be,{className:`h-5 w-5 animate-spin text-gray-400`})}):t.length===0?(0,$.jsx)(`div`,{className:`text-center py-8 text-gray-500`,children:v(`modelManager.library.noResults`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=e.category===`cloud`?p(e.name):e.name,n=f(e.name)||f(t);return(0,$.jsx)(vi,{model:e,installed:n,pulling:s,canInstallModels:c,pullSectionExpanded:l,onTogglePullSection:h,onPullModel:g},e.name)})}),(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsxs)(H,{onClick:_,variant:`outline`,size:`sm`,disabled:o,className:C(`gap-1.5`,``,``),children:[(0,$.jsx)(be,{className:C(`h-3.5 w-3.5`,o&&`animate-spin`)}),v(`modelManager.library.refresh`)]})})]})]})}function vi({model:e,installed:t,pulling:n,canInstallModels:r,pullSectionExpanded:i,onTogglePullSection:a,onPullModel:o}){let{t:s}=y();return(0,$.jsxs)(`div`,{"data-testid":`library-model-card-${e.name}`,className:C(`p-4 rounded-lg border transition-all`,`bg-gray-50 dark:bg-dark-50`,t?`border-green-200 dark:border-green-800/50`:`border-gray-200 dark:border-dark-300`,`hover:shadow-md hover:border-gray-300 dark:hover:border-dark-400`),children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-2`,children:[(0,$.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),t&&(0,$.jsxs)(`span`,{className:C(`flex items-center gap-1 px-1.5 py-0.5 rounded-sm text-xs`,`bg-green-100 dark:bg-green-900/30`,`text-green-700 dark:text-green-400`),children:[(0,$.jsx)(Ve,{className:`h-3 w-3`}),s(`modelManager.library.installed`)]})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-dark-600 mb-3 line-clamp-2`,children:e.description}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.sizes.slice(0,4).map(e=>(0,$.jsx)(`span`,{className:C(`px-1.5 py-0.5 rounded-sm text-xs`,`bg-gray-200 dark:bg-dark-300`,`text-gray-600 dark:text-gray-400`),children:e},e)),e.sizes.length>4&&(0,$.jsx)(`span`,{className:`text-xs text-gray-400`,children:s(`modelManager.library.more`,{count:e.sizes.length-4})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-gray-500`,children:[e.pulls&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(F,{className:`h-3 w-3`}),e.pulls]}),(0,$.jsx)(`span`,{className:C(`px-1.5 py-0.5 rounded-sm capitalize`,e.category===`cloud`?`bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400`:`bg-gray-100 dark:bg-dark-200`),children:e.category})]}),(0,$.jsxs)(H,{"data-testid":`library-model-install-${e.name}`,onClick:()=>{i||a(),o(e.name,e.category)},variant:`outline`,size:`sm`,disabled:n||!r,className:C(`gap-1 text-xs`,``,``),children:[(0,$.jsx)(F,{className:`h-3 w-3`}),s(`modelManager.pull.button`)]})]})]})}function yi({expanded:e,modelName:t,setModelName:n,pulling:r,progress:i,canInstallModels:a,popularModels:o,onToggle:s,onPull:c,onCancelPull:l,formatSize:u}){let{t:d}=y();return(0,$.jsxs)(`div`,{className:C(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/3`,`border-gray-200/80 dark:border-white/10`),children:[(0,$.jsxs)(`button`,{onClick:s,"aria-expanded":e,className:C(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(F,{className:`h-4 w-4 text-primary-600 dark:text-primary-400`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:d(`modelManager.sections.pull`)})]}),e?(0,$.jsx)(Ne,{className:`h-5 w-5 text-gray-500`}):(0,$.jsx)(N,{className:`h-5 w-5 text-gray-500`})]}),e&&(0,$.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(oe,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400 dark:text-gray-500`}),(0,$.jsx)(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:d(`modelManager.pull.placeholder`),className:C(`w-full rounded-xl border py-2.5 pe-4 ps-10 text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`),disabled:r||!a,onKeyDown:e=>{e.key===`Enter`&&!r&&a&&c()}})]}),r?(0,$.jsxs)(H,{onClick:l,variant:`outline`,className:C(`px-4 py-2.5 gap-2`,`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,``,``),children:[(0,$.jsx)(Ye,{className:`h-4 w-4`}),d(`modelManager.pull.cancel`)]}):(0,$.jsxs)(H,{onClick:c,disabled:!t.trim()||!a,className:C(`px-4 py-2.5 gap-2`,``),children:[(0,$.jsx)(F,{className:`h-4 w-4`}),d(`modelManager.pull.button`)]})]}),r&&i&&(0,$.jsx)(bi,{progress:i,formatSize:u}),!a&&(0,$.jsx)(`p`,{className:`text-xs text-ink-muted`,children:d(`modelManager.pull.restricted`)}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 mb-2`,children:d(`modelManager.pull.popular`)}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:o.map(e=>(0,$.jsxs)(`button`,{onClick:()=>n(e.name),disabled:r||!a,className:C(`px-3 py-1.5 rounded-full text-xs font-medium transition-colors`,`bg-gray-100 dark:bg-dark-200`,`text-gray-700 dark:text-gray-300`,`hover:bg-gray-200 dark:hover:bg-dark-300`,`border border-gray-200 dark:border-dark-300`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[e.name,(0,$.jsx)(`span`,{className:`ml-1 text-gray-400 dark:text-gray-500`,children:e.size})]},`${e.name}-${e.size}`))})]}),(0,$.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,className:C(`inline-flex items-center gap-1.5 text-xs`,`text-primary-600 dark:text-primary-400`,`hover:underline`),children:[(0,$.jsx)(L,{className:`h-3 w-3`}),d(`modelManager.pull.browseAll`)]})]})]})}function bi({progress:e,formatSize:t}){let{t:n}=y(),r=e.status===`starting`?n(`modelManager.progress.starting`):e.status.startsWith(`pulling`)?`${n(`modelManager.progress.pullingLayer`)} ${e.status.replace(`pulling `,``)}`:e.status.startsWith(`verifying sha256`)?n(`modelManager.progress.verifyingDigest`):e.status===`writing manifest`?n(`modelManager.progress.writing`):e.status===`removing any unused layers`?n(`modelManager.progress.cleaning`):e.status;return(0,$.jsxs)(`div`,{className:C(`p-4 rounded-lg border`,`bg-gray-50 dark:bg-dark-200`,`border-gray-200 dark:border-dark-300`),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-800 dark:text-dark-700`,children:r}),e.percent!==void 0&&(0,$.jsxs)(`span`,{className:`text-sm font-mono text-gray-600 dark:text-dark-600`,children:[e.percent,`%`]})]}),e.percent!==void 0&&(0,$.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-400 rounded-full h-2 overflow-hidden`,children:(0,$.jsx)(`div`,{className:C(`h-2 rounded-full transition-all duration-300`,`bg-primary-500 dark:bg-primary-400`),style:{width:`${e.percent}%`}})}),e.total&&e.completed&&(0,$.jsxs)(`div`,{className:`mt-2 text-xs text-gray-600 dark:text-dark-600`,children:[t(e.completed),` / `,t(e.total)]})]})}function xi({modelCount:e,updating:t,progress:n,onUpdateAll:r}){let{t:i}=y();return(0,$.jsxs)(`section`,{"data-testid":`model-manager-bulk-operations`,"aria-labelledby":`model-manager-bulk-operations-title`,"aria-busy":t,className:C(`rounded-2xl border p-4`,`bg-white/60 dark:bg-white/3`,`border-gray-200/80 dark:border-white/10`),children:[(0,$.jsx)(`h3`,{id:`model-manager-bulk-operations-title`,className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:i(`settings.model.bulkOperations`)}),(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:i(`settings.model.updateAll`)}),(0,$.jsx)(`p`,{className:`mb-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:i(`settings.model.updateAllDescription`)}),t&&n&&(0,$.jsx)(Si,{progress:n}),(0,$.jsx)(H,{onClick:r,variant:`outline`,size:`sm`,className:`w-full`,disabled:t||e===0,"aria-busy":t,children:t?i(`settings.model.updating`):i(`settings.model.updateAllButton`,{count:e})})]})]})}function Si({progress:e}){let{t}=y(),n=e.total>0?Math.round(e.current/e.total*100):0;return(0,$.jsxs)(`div`,{className:`mb-4 space-y-3`,"aria-live":`polite`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-600 dark:text-dark-600`,children:t(`settings.model.updatingModel`,{name:e.modelName,current:e.current,total:e.total})}),(0,$.jsxs)(`span`,{className:`font-semibold text-primary-600 dark:text-primary-400`,children:[n,`%`]})]}),(0,$.jsx)(`div`,{role:`progressbar`,"aria-label":t(`settings.model.updateAll`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n,className:`h-3 w-full rounded-full bg-gray-200 dark:bg-dark-300`,children:(0,$.jsx)(`div`,{className:`h-3 rounded-full bg-primary-600 transition-[width] duration-150 ease-out motion-reduce:transition-none dark:bg-primary-400`,style:{width:`${n}%`}})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:[t(`settings.model.status`),`:`,` `,e.status===`starting`?(0,$.jsx)(`span`,{className:`text-accent-500 dark:text-accent-400`,children:t(`settings.model.statusStarting`)}):e.status===`success`?(0,$.jsx)(`span`,{className:`text-success-600 dark:text-success-500`,children:t(`settings.model.statusComplete`)}):(0,$.jsxs)(`span`,{className:`text-error-600 dark:text-error-500`,children:[t(`settings.model.statusError`),`: `,e.error]})]}),(0,$.jsx)(`span`,{className:`text-[10px] text-gray-400 dark:text-dark-600`,children:t(`settings.model.modelsProgress`,{current:e.current,total:e.total})})]})]})}var Ci=o(`components:model-manager`),wi=Q.lazy(()=>a(()=>import(`./ModelManagerModals-DhY8Rme6.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]))),Ti=e=>{let t=e.split(`:`).pop()?.toLowerCase();return t===`cloud`||t?.endsWith(`-cloud`)===!0},Ei=e=>{let t=e.trim();if(!t||Ti(t))return t;let n=t.lastIndexOf(`:`);return n===-1?`${t}:cloud`:`${t.slice(0,n)}:${t.slice(n+1)}-cloud`},Di=({updatingAllModels:e,updateProgress:t,onUpdateAllModels:n})=>{let{t:a}=y(),{user:o,systemInfo:s}=$t(),c=o?.role===`admin`||s?.requiresAuth===!1,{data:l}=i({queryKey:[`model-download-access`],queryFn:async()=>{let e=await J.getModelAccess();return e.success&&e.data?e.data:null},staleTime:6e4}),u=c||l?.allowed===!0,d=r(),[f,p]=(0,Q.useState)(`all`),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(``),[v,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(``),[A,j]=(0,Q.useState)(!1),[M,F]=(0,Q.useState)(!1),[I,ee]=(0,Q.useState)(!1),[re,L]=(0,Q.useState)(``),[R,z]=(0,Q.useState)(``),[ie,ae]=(0,Q.useState)(!1),[oe,se]=(0,Q.useState)(!1),[B,ce]=(0,Q.useState)(``),[le,ue]=(0,Q.useState)(``),[de,fe]=(0,Q.useState)(!1),[pe,me]=(0,Q.useState)(!1),[he,ge]=(0,Q.useState)(``),[ve,ye]=(0,Q.useState)(``),[xe,Se]=(0,Q.useState)(null),[Ce,we]=(0,Q.useState)(!1),[Te,Ee]=(0,Q.useState)(``),[Ae,je]=(0,Q.useState)(``),[Me,Pe]=(0,Q.useState)(`text-generation`),[Fe,Ie]=(0,Q.useState)(`downloads`),[Le,Re]=(0,Q.useState)(null),[ze,Be]=(0,Q.useState)({}),[Ve,He]=(0,Q.useState)(null),[Ue,We]=(0,Q.useState)(null),[Ge,Ke]=(0,Q.useState)(null),[Je,Ye]=(0,Q.useState)(null),[Xe,Ze]=(0,Q.useState)(new Set([`pull`,`local`])),Qe=e=>{Ze(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},{data:$e,isLoading:et,refetch:tt}=i({queryKey:[`ollama-state`],queryFn:async()=>{let[e,t,n,r]=await Promise.all([J.getModels(),J.listRunningModels(),J.getVersion(),J.checkHealth()]);return{models:e.success&&e.data||[],runningModels:t.success&&Array.isArray(t.data)?t.data:[],ollamaVersion:n.success&&n.data?n.data.version:null,isHealthy:r.success}}}),nt=$e?.models??[],rt=$e?.runningModels??[],it=$e?.ollamaVersion??null,at=$e?.isHealthy??null,ot=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{let t=ot.current&&!e;ot.current=e,t&&tt()},[tt,e]);let st=(0,Q.useCallback)(async()=>{await tt()},[tt]),{data:ct=[],isLoading:ut}=i({queryKey:[`ollama-library`],queryFn:async()=>{let e=await J.getLibraryModels();return e.success&&e.data?e.data:[]}}),{data:dt=[],isLoading:pt}=i({queryKey:[`ollama-library`,`cloud`],queryFn:async()=>{let e=await J.getLibraryModels({category:`cloud`});return e.success&&e.data?e.data:[]},enabled:f===`cloud`}),mt=()=>d.invalidateQueries({queryKey:[`ollama-library`]});(0,Q.useEffect)(()=>{let e=setTimeout(()=>{je(Te)},300);return()=>clearTimeout(e)},[Te]);let gt=Xe.has(`huggingface`),{data:_t=[],isLoading:vt}=i({queryKey:[`hf-models`,Me,Ae,Fe],queryFn:async()=>{let e=await Ft.getModels({task:Me,search:Ae||void 0,sort:Fe,limit:30});return e.success&&e.data?e.data:[]},enabled:gt}),yt=()=>d.invalidateQueries({queryKey:[`hf-models`,Me,Ae,Fe]}),bt=(0,Q.useCallback)(async e=>{let[t,n]=e.split(`/`);if(t&&n){He(e);try{let r=await Ft.getGgufFiles(t,n);r.success&&r.data&&Be(t=>({...t,[e]:r.data}))}catch(e){Ci.error(`Failed to load GGUF files:`,e)}finally{He(null)}}},[]),xt=(0,Q.useCallback)(e=>{Le===e?Re(null):(Re(e),ze[e]||bt(e))},[Le,ze,bt]),U=(0,Q.useCallback)((e,t)=>{if(!u){V.error(a(`modelManager.pull.restricted`));return}if(!Ue){We(e),Ke({status:`starting`});try{let n=J.pullModelStream(e,e=>{Ke(e)},()=>{Ke(null),We(null),Ye(null),V.success(a(`modelDownload.success`,{name:t})),st()},e=>{Ke(null),We(null),Ye(null),V.error(a(`modelDownload.failed`,{error:e}))});Ye(()=>n)}catch{Ke(null),We(null),V.error(a(`modelDownload.startFailed`))}}},[u,Ue,st,a]),W=(0,Q.useCallback)(()=>{Je&&(Je(),Ye(null),We(null),Ke(null))},[Je]),St=async(e,t)=>{if(!u){V.error(a(`modelManager.pull.restricted`));return}let n=e||g.trim(),r=t===`cloud`||!e&&f===`cloud`?Ei(n):n;if(!r){V.error(a(`modelManager.pull.enterName`));return}e&&_(r),b(!0),S({status:`starting`});try{let e=J.pullModelStream(r,e=>{S(e)},()=>{S(null),b(!1),T(null),V.success(a(`modelManager.pull.success`,{name:r})),_(``),st()},e=>{S(null),b(!1),T(null),V.error(a(`modelManager.pull.failed`)+`: `+e)});T(()=>e)}catch(e){let t=e instanceof Error?e.message:String(e);V.error(a(`modelManager.pull.failed`)+`: `+t),S(null),b(!1),T(null)}},Ct=()=>{w&&(w(),T(null),b(!1),S(null),V.success(a(`modelManager.pull.cancelled`)))},wt=async e=>{if(confirm(a(`modelManager.local.deleteConfirm`,{name:e})))try{await J.deleteModel(e),V.success(a(`modelManager.local.deleteSuccess`,{name:e})),await st()}catch(e){let t=e instanceof Error?e.message:String(e);V.error(a(`modelManager.local.deleteFailed`)+`: `+t)}},Tt=async e=>{F(!0),k(e),j(!0);try{let t=await J.showModel(e,!0);t.success&&t.data?D(t.data):V.error(a(`modelManager.modals.details.noDetails`))}catch(e){let t=e instanceof Error?e.message:String(e);V.error(a(`modelManager.modals.details.noDetails`)+`: `+t)}finally{F(!1)}},Et=async()=>{if(!re.trim()||!R.trim()){V.error(a(`modelManager.modals.copy.enterBoth`));return}ae(!0);try{await J.copyModel(re.trim(),R.trim()),V.success(a(`modelManager.modals.copy.success`,{name:R})),ee(!1),L(``),z(``),await st()}catch(e){let t=e instanceof Error?e.message:String(e);V.error(a(`modelManager.modals.copy.failed`)+`: `+t)}finally{ae(!1)}},Dt=async()=>{if(!B.trim()||!le.trim()){V.error(a(`modelManager.modals.create.enterBoth`));return}fe(!0);try{await J.createModel({model:B.trim(),modelfile:le.trim()}),V.success(a(`modelManager.modals.create.success`,{name:B})),se(!1),ce(``),ue(``),await st()}catch(e){let t=e instanceof Error?e.message:String(e);V.error(a(`modelManager.modals.create.failed`)+`: `+t)}finally{fe(!1)}},Ot=async()=>{if(!he.trim()||!ve.trim()){V.error(a(`modelManager.modals.embeddings.enterBoth`));return}we(!0),Se(null);try{let e=await J.generateEmbeddings({model:he.trim(),input:ve.trim()});if(e.success&&e.data){let t=e.data.embeddings?.[0]||[];Se(t),V.success(a(`modelManager.modals.embeddings.success`,{count:t.length}))}}catch(e){let t=e instanceof Error?e.message:String(e);V.error(a(`modelManager.modals.embeddings.failed`)+`: `+t)}finally{we(!1)}},G=e=>{let t=e/1073741824;return t>=1?`${t.toFixed(2)} GB`:`${(e/1048576).toFixed(1)} MB`},kt=e=>Array.isArray(rt)&&rt.some(t=>t.name===e),K=()=>nt.reduce((e,t)=>e+t.size,0),At=()=>rt.reduce((e,t)=>e+(t.size_vram||0),0),jt=e=>nt.some(t=>t.name===e||t.name.startsWith(e+`:`)),Mt=(f===`cloud`?dt:ct).filter(e=>{let t=f===`all`||f===`cloud`||e.category===f,n=!m||e.name.toLowerCase().includes(m.toLowerCase())||e.description.toLowerCase().includes(m.toLowerCase());return t&&n}),Nt=[`all`,...new Set([...ct.map(e=>e.category),`cloud`])],Pt=(0,Q.useMemo)(()=>ct.length>0?ct.slice(0,10).map(e=>({name:e.name,category:e.category,size:e.sizes?.[0]||``})):[{name:`gemma4`,category:`general`,size:`12B`},{name:`gemma4`,category:`general`,size:`26B`},{name:`gemma4`,category:`general`,size:`31B`},{name:`qwen3.8`,category:`reasoning`,size:`27B`},{name:`nomic-embed-text`,category:`embedding`,size:`137M`}],[ct]),It=A||I||oe||pe;return et?(0,$.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(be,{className:`h-5 w-5 animate-spin`}),a(`modelManager.loading`)]})}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`div`,{className:C(`rounded-2xl border px-4 py-3`,`bg-white/60 dark:bg-white/3`,`border-gray-200/80 dark:border-white/10`),children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:C(`w-2.5 h-2.5 rounded-full`,at?`bg-green-500`:`bg-red-500`)}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:a(at?`modelManager.systemStatus.online`:`modelManager.systemStatus.offline`)})]}),it&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(De,{className:`h-4 w-4`}),(0,$.jsxs)(`span`,{children:[`v`,it]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(P,{className:`h-4 w-4`}),(0,$.jsxs)(`span`,{children:[nt.length,` `,nt.length===1?a(`modelManager.systemStatus.models`):a(`modelManager.systemStatus.models_plural`)]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(Oe,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:G(K())})]}),rt.length>0&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-green-600 dark:text-green-400`,children:[(0,$.jsx)(ne,{className:`h-4 w-4`}),(0,$.jsxs)(`span`,{children:[rt.length,` `,a(`modelManager.systemStatus.running`),` (`,G(At()),` `,a(`modelManager.systemStatus.vram`),`)`]})]})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsxs)(H,{onClick:st,variant:`outline`,size:`sm`,className:C(`gap-1.5`,``,``),children:[(0,$.jsx)(be,{className:`h-3.5 w-3.5`}),a(`common.refresh`)]})})]})}),(0,$.jsx)(yi,{expanded:Xe.has(`pull`),modelName:g,setModelName:_,pulling:v,progress:x,canInstallModels:u,popularModels:Pt,onToggle:()=>Qe(`pull`),onPull:()=>St(),onCancelPull:Ct,formatSize:G}),(0,$.jsx)(_i,{expanded:Xe.has(`library`),models:Mt,totalAvailable:ct.length,categories:Nt,filter:f,search:m,loading:ut||pt,pulling:v,canInstallModels:u,pullSectionExpanded:Xe.has(`pull`),setFilter:p,setSearch:h,isModelInstalled:jt,normalizeCloudPullName:Ei,onToggle:()=>Qe(`library`),onTogglePullSection:()=>Qe(`pull`),onPullModel:St,onRefresh:mt}),(0,$.jsx)(ui,{expanded:Xe.has(`huggingface`),models:_t,search:Te,task:Me,sort:Fe,loadingModels:vt,canInstallModels:u,expandedModelId:Le,loadingGgufModelId:Ve,ggufFiles:ze,pullingModel:Ue,pullProgress:Ge,setSearch:Ee,setTask:Pe,setSort:Ie,onToggle:()=>Qe(`huggingface`),onToggleModel:xt,onPullGguf:U,onCancelPull:W,onRefresh:yt}),Array.isArray(rt)&&rt.length>0&&(0,$.jsxs)(`div`,{className:C(`rounded-2xl border p-4`,`bg-white/60 dark:bg-white/3`,`border-gray-200/80 dark:border-white/10`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,$.jsx)(ne,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:a(`modelManager.sections.running`)}),(0,$.jsxs)(`span`,{className:C(`ms-auto rounded-full px-2 py-0.5 text-xs font-medium`,`border border-gray-200 bg-gray-50 dark:border-white/10 dark:bg-white/4`,`text-gray-600 dark:text-dark-600`),children:[rt.length,` `,a(`modelManager.systemStatus.running`)]})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:rt.map(e=>(0,$.jsxs)(`div`,{className:C(`flex items-center justify-between p-4 rounded-lg border`,`bg-white/50 dark:bg-white/2.5`,`border-gray-200/80 dark:border-white/8`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:C(`w-2 h-2 rounded-full animate-pulse`,`bg-green-500`)}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 text-sm text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(qe,{className:`h-3 w-3`}),a(`modelManager.systemStatus.vram`),`:`,` `,G(e.size_vram||0)]}),e.size&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(P,{className:`h-3 w-3`}),a(`models.size`),`: `,G(e.size)]})]})]})]}),(0,$.jsxs)(`div`,{className:C(`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs font-medium`,`border border-gray-200 bg-gray-50 dark:border-white/10 dark:bg-white/4`,`text-gray-600 dark:text-dark-600`),children:[(0,$.jsx)(lt,{className:`h-3 w-3`}),a(`modelManager.local.running`)]})]},e.name))})]}),(0,$.jsx)(hi,{expanded:Xe.has(`local`),models:nt,onToggle:()=>Qe(`local`),isModelRunning:kt,formatSize:G,onShowModel:Tt,onCopyModel:e=>{L(e),ee(!0)},onDeleteModel:wt}),c&&(0,$.jsx)(xi,{modelCount:nt.length,updating:e,progress:t,onUpdateAll:n}),(0,$.jsxs)(`div`,{className:C(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/3`,`border-gray-200/80 dark:border-white/10`),children:[(0,$.jsxs)(`button`,{onClick:()=>Qe(`advanced`),"aria-expanded":Xe.has(`advanced`),className:C(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(ke,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:a(`modelManager.sections.advanced`)})]}),Xe.has(`advanced`)?(0,$.jsx)(Ne,{className:`h-5 w-5 text-gray-500`}):(0,$.jsx)(N,{className:`h-5 w-5 text-gray-500`})]}),Xe.has(`advanced`)&&(0,$.jsx)(`div`,{className:`p-4 pt-0`,children:(0,$.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3`,children:[(0,$.jsxs)(H,{onClick:()=>se(!0),variant:`outline`,className:C(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,$.jsx)(te,{className:`h-5 w-5 text-gray-500 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`text-start`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:a(`modelManager.advanced.createModel`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:a(`modelManager.advanced.fromModelfile`)})]})]}),(0,$.jsxs)(H,{onClick:()=>ee(!0),variant:`outline`,className:C(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,$.jsx)(_e,{className:`h-5 w-5 text-gray-500 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`text-start`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:a(`modelManager.advanced.copyModel`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:a(`modelManager.advanced.duplicateExisting`)})]})]}),(0,$.jsxs)(H,{onClick:()=>me(!0),variant:`outline`,className:C(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,$.jsx)(ht,{className:`h-5 w-5 text-gray-500 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`text-start`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:a(`modelManager.advanced.testEmbeddings`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:a(`modelManager.advanced.generateVectors`)})]})]}),(0,$.jsxs)(H,{onClick:async()=>{try{(await J.checkHealth()).success&&(await tt(),V.success(a(`modelManager.advanced.healthy`)))}catch{await tt(),V.error(a(`modelManager.systemStatus.offline`))}},variant:`outline`,className:C(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,$.jsx)(ft,{className:`h-5 w-5 text-gray-500 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`text-start`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:a(`modelManager.advanced.healthCheck`)}),(0,$.jsx)(`div`,{className:`text-xs opacity-70`,children:a(`modelManager.advanced.testConnection`)})]})]})]})})]}),It&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(wi,{models:nt,showDetailsModal:A,setShowDetailsModal:j,selectedModelName:O,selectedModelDetails:E,loadingDetails:M,showCopyModal:I,setShowCopyModal:ee,copySource:re,setCopySource:L,copyDestination:R,setCopyDestination:z,copying:ie,handleCopyModel:Et,showCreateModal:oe,setShowCreateModal:se,createModelName:B,setCreateModelName:ce,createModelfile:le,setCreateModelfile:ue,creating:de,handleCreateModel:Dt,showEmbeddingsModal:pe,setShowEmbeddingsModal:me,embeddingsModel:he,setEmbeddingsModel:ge,embeddingsInput:ve,setEmbeddingsInput:ye,embeddingsResult:xe,generatingEmbeddings:Ce,handleGenerateEmbeddings:Ot})})]})};function Oi({loadPreferences:e,loadSessions:t,loadFolders:n}){let{t:r}=y(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(`skip`),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),v=(0,Q.useRef)(null),b=(0,Q.useRef)(0),x=e=>{switch(e.code){case`invalidJson`:return r(`settings.data.archiveErrors.invalidJson`);case`objectRequired`:return r(`settings.data.archiveErrors.objectRequired`);case`unsupportedVersion`:return r(`settings.data.archiveErrors.unsupportedVersion`,{version:String(e.version)});case`unrecognized`:return r(`settings.data.archiveErrors.unrecognized`)}},S=()=>{b.current+=1,l(null),s(!1),_(null),v.current&&(v.current.value=``)},C=async()=>{try{let e=await q.exportData();if(!e.success||!e.data)throw Error(e.error||r(`settings.data.exportFailed`));let t=new Blob([JSON.stringify(e.data,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),i=document.createElement(`a`);i.href=n,i.download=`libre-webui-user-data-v3-${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(n),V.success(r(`settings.data.exportSuccess`))}catch(e){V.error(e instanceof Error?e.message:r(`settings.data.exportFailed`))}},w=async(e,t)=>{let n=b.current+1;b.current=n,s(!0),l(null);try{Ht(await e.text());let i=await q.preflightImport(e,t);if(!i.success||!i.data?.valid)throw Error(i.error||r(`settings.data.archiveValidationFailed`));b.current===n&&l(i.data)}catch(e){b.current===n&&V.error(e instanceof Lt?x(e):e instanceof Error?e.message:r(`settings.data.archiveValidationFailed`))}finally{b.current===n&&s(!1)}};return{importing:i,preflighting:o,preflight:c,showImportOptions:u,mergeStrategy:f,importResult:m,setImportResult:h,importFileInputRef:v,handleExportData:C,handleImportFileSelect:e=>{let t=e.target.files?.[0];t&&(_(t),d(!0),h(null),w(t,f))},handleMergeStrategyChange:e=>{p(e),g&&w(g,e)},handleConfirmImport:async()=>{if(g&&c&&c.strategy===f){a(!0);try{let i=await q.importData(g,f);if(i.success&&i.data)h({preferences:{imported:i.data.preferences.imported,error:null},sessionFolders:i.data.sessionFolders,sessions:i.data.sessions,notes:i.data.notes,knowledgeCollections:i.data.knowledgeCollections,documents:i.data.documents,warnings:i.data.warnings,exclusions:i.data.exclusions}),V.success(r(`settings.data.importSuccess`)),(await Promise.allSettled([e(),t(),n()])).some(e=>e.status===`rejected`)&&V.error(r(`settings.data.refreshAfterImportFailed`)),window.dispatchEvent(new Event(`libre:documents-updated`));else throw Error(i.error||r(`settings.data.importFailed`))}catch(e){V.error(e instanceof Error?e.message:r(`settings.data.importFailed`)),h(null)}finally{a(!1),d(!1),S()}}},handleCancelImport:()=>{d(!1),h(null),S()}}}var ki=Q.lazy(()=>a(()=>import(`./UserManagementPanel-D1CS0KPn.js`),__vite__mapDeps([11,1,2,12,8,13,4,5,6,7,14,15,16,17,18,3,9,19,10,20,21,22,23,24]))),Ai=dn()||`0.0.0`,ji=`__current_running_model__`,Mi={enabled:!1,model:`nomic-embed-text`,chunkSize:1e3,chunkOverlap:200,similarityThreshold:.7},Ni={enabled:!1,autoPlay:!1,model:``,voice:``,voiceProfileId:``,speed:1,pluginId:``,streamSentences:!0},Pi={enabled:!1,model:``,size:`1024x1024`,quality:`standard`,style:`vivid`,pluginId:``},Fi=({isOpen:e,onClose:t,initialTab:n})=>{let{models:a,selectedModel:o,selectedProviderType:c,selectedProviderId:l,setSelectedModel:d,systemMessage:p,setSystemMessage:_,clearAllSessions:v,loading:b,sessions:x,loadModels:S,loadSessions:T,loadFolders:E}=m(),{theme:D,updateTheme:O,preferences:k,setPreferences:j,loadPreferences:N}=A(),{plugins:F,isLoading:I,isUploading:ee,error:te,loadPlugins:ne,uploadPlugin:re,deletePlugin:L,activatePlugin:R,deactivatePlugin:z,exportPlugin:ie,clearError:ae,installPlugin:se}=en(),{t:B}=y(),ce=Q.useId(),le=(0,Q.useRef)(null),de=(0,Q.useRef)(null);xt(le,{onClose:t,enabled:e,initialFocusRef:de});let fe=`${ce}-panel`,me=(0,Q.useRef)(null),[he,_e]=(0,Q.useState)(()=>window.matchMedia(`(min-width: 640px)`).matches);(0,Q.useEffect)(()=>{let e=window.matchMedia(`(min-width: 640px)`),t=()=>_e(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let ve=s(a,{model:o,providerType:c,providerId:l}),ye={model:k.titleSettings?.taskModel||``,providerType:k.titleSettings?.taskProviderType,providerId:k.titleSettings?.taskProviderId},be=ye.model===ji?a:s(a,ye),xe=ye.model===ji?ji:ye.model?f(be,ye):``,Se={model:k.visionModel||``,providerType:k.visionProviderType,providerId:k.visionProviderId},Ce=s(a,Se),we=Se.model?f(Ce,Se):``,Te=[{value:``,label:B(`settings.model.selectVisionModel`,{defaultValue:`Use the current chat model`})},...Ce.map(e=>({value:u(e),label:Wn(e,B,`separator`)}))],Ee=[{value:``,label:B(`settings.model.autoTitle.selectTaskModel`)},{value:ji,label:`Use current running model`},...be.map(e=>({value:u(e),label:Wn(e,B,`separator`)}))],De=$t(e=>e.user),Oe=$t(e=>e.systemInfo),ke=De?.role===`admin`||Oe?.requiresAuth===!1,[Ae,Me]=(0,Q.useState)(n??`appearance`);(0,Q.useEffect)(()=>{me.current&&(me.current.scrollTop=0)},[Ae,e]);let[Ne,Pe]=(0,Q.useState)(`global`),[Fe,Ie]=(0,Q.useState)(``),[Le,Re]=(0,Q.useState)(p),[ze,Ve]=(0,Q.useState)(!1),[Ue,We]=(0,Q.useState)(null),[Ge,qe]=(0,Q.useState)(!1),[Qe,$e]=(0,Q.useState)(!1),[et,nt]=(0,Q.useState)(``),st=(0,Q.useRef)(null),[ct,lt]=(0,Q.useState)(null),[ut,dt]=(0,Q.useState)({}),[ft,pt]=(0,Q.useState)({}),[mt,ht]=(0,Q.useState)(null),[_t,vt]=(0,Q.useState)({}),[yt,bt]=(0,Q.useState)(k.generationOptions||{}),U=(0,Q.useCallback)(async e=>{try{let t=await J.getModelDefaults(e);return t.success?t.data?.options??{}:{}}catch{return{}}},[]);(0,Q.useEffect)(()=>{if(!e)return;let t=Ne===`model`&&!!o,n=!1;return(t?U(o):Promise.resolve({})).then(e=>{n||bt(t?{...k.generationOptions||{},...e,...k.modelGenerationOptions?.[o]||{}}:{...k.generationOptions||{}})}),()=>{n=!0}},[e,Ne,o,U,k.generationOptions,k.modelGenerationOptions]);let[W,St]=(0,Q.useState)(k.embeddingSettings||Mi),[Ct,wt]=(0,Q.useState)(!1),[Tt,Et]=(0,Q.useState)(k.ttsSettings||Ni),[Dt,Ot]=(0,Q.useState)(!1),G=(0,Q.useRef)(null),kt=(0,Q.useRef)(null),[K,At]=(0,Q.useState)(k.imageGenSettings||Pi),{importing:jt,preflighting:Mt,preflight:Pt,showImportOptions:Ft,mergeStrategy:Lt,importResult:Rt,setImportResult:zt,importFileInputRef:Ht,handleExportData:Wt,handleImportFileSelect:Gt,handleMergeStrategyChange:qt,handleConfirmImport:Yt,handleCancelImport:nn}=Oi({loadPreferences:N,loadSessions:T,loadFolders:E}),Y=r(),{data:rn={}}=i({queryKey:[`plugin-credentials`],queryFn:async()=>{let e=await Kt.getCredentials();if(!e.success||!e.data)return{};let t={};for(let n of e.data)t[n.plugin_id]=n.has_api_key;return t},enabled:e}),{data:an=[]}=i({queryKey:[`embedding-models`],queryFn:async()=>{let e=await Nt.getModels();return e.success&&e.data?e.data:[]},enabled:e}),on=(0,Q.useMemo)(()=>{let e=an.find(e=>e.id===W.model||e.rawModel===W.model);return e&&e.id!==W.model?{...W,model:e.id}:W},[an,W]),{data:sn=null}=i({queryKey:[`embedding-status`],queryFn:async()=>{let e=await Vt.getEmbeddingStatus();return e.success&&e.data?e.data:null},enabled:e}),{data:cn,isLoading:ln}=i({queryKey:[`tts-data`],queryFn:async()=>{let[e,t]=await Promise.all([It.getModels(),It.getPlugins()]);return{models:e.success&&Array.isArray(e.data)?e.data:[],plugins:t.success&&Array.isArray(t.data)?t.data:[]}},enabled:e}),un=(0,Q.useMemo)(()=>cn?.models??[],[cn]),dn=cn?.plugins??[],X=(0,Q.useMemo)(()=>Bt(un,Tt.model,Tt.pluginId),[un,Tt.model,Tt.pluginId]),Z=(0,Q.useMemo)(()=>{if(!X)return Tt;let e=Ut(un,Tt.model,Tt.pluginId);return e&&Tt.pluginId===e.plugin?Tt:{...Tt,model:X.model,pluginId:X.plugin,voice:X.config?.default_voice??``,voiceProfileId:``}},[X,un,Tt]),fn=(0,Q.useMemo)(()=>Ut(un,Z.model,Z.pluginId)?.config?.voices??[],[Z,un]),{data:pn=[],isLoading:mn,isSuccess:hn}=i({queryKey:[`tts-voice-profiles`],queryFn:async()=>{let e=await It.getVoiceProfiles();if(!e.success)throw Error(e.message||`Failed to load saved voices`);return e.data??[]},enabled:e}),gn=(0,Q.useMemo)(()=>pn.filter(e=>e.pluginId===Z.pluginId&&e.model===Z.model&&(e.consentStatus??`active`)===`active`),[Z,pn]),_n=(0,Q.useMemo)(()=>{let e=Z.voiceProfileId,t=e?pn.find(t=>t.id===e):void 0,n=!!(e&&X)&&!X?.config?.supports_voice_cloning,r=hn&&!!e&&(!t||t.pluginId!==Z.pluginId||t.model!==Z.model||(t.consentStatus??`active`)!==`active`);return!e||!n&&!r?Z:{...Z,voiceProfileId:``,voice:X?.config?.default_voice??``}},[hn,Z,X,pn]);(0,Q.useEffect)(()=>{let e=Z.voiceProfileId,t=e?pn.find(t=>t.id===e):void 0;e&&(X&&!X?.config?.supports_voice_cloning||hn&&(!t||t.pluginId!==Z.pluginId||t.model!==Z.model))&&e&&kt.current!==e&&(kt.current=e,q.updatePreferences({ttsSettings:_n}).then(e=>{e.success&&e.data&&j(e.data)}).catch(e=>{kt.current=null,V.error(g(e,B(`settings.tts.savedVoiceUnavailableCleanupFailed`)))}))},[_n,hn,Z.model,Z.pluginId,Z.voiceProfileId,X,j,B,pn]);let{data:vn,isLoading:yn}=i({queryKey:[`image-gen-data`],queryFn:async()=>{let[e,t]=await Promise.all([Jt.getModels(),Jt.getPlugins()]);return{models:e.success&&e.data?e.data:[],plugins:t.success&&t.data?t.data:[]}},enabled:e}),xn=(0,Q.useMemo)(()=>vn?.models??[],[vn]),Sn=(0,Q.useMemo)(()=>vn?.plugins??[],[vn]),Cn=(0,Q.useMemo)(()=>Xt(xn,K.model,K.pluginId),[xn,K.model,K.pluginId]),wn=(0,Q.useMemo)(()=>{if(!Cn)return K;let e=Qt(xn,K.model,K.pluginId);return e&&K.pluginId===e.plugin?K:{...K,model:Cn.model,pluginId:Cn.plugin,size:Zt(Cn.config?.sizes,K.size,Cn.config?.default_size,`1024x1024`),quality:Zt(Cn.config?.qualities,K.quality,Cn.config?.default_quality,`standard`),style:Zt(Cn.config?.styles,K.style,Cn.config?.default_style,`vivid`)}},[xn,K,Cn]),Tn=Cn?.config?.sizes??[],On=Cn?.config?.qualities??[],jn=Cn?.config?.styles??[],Mn=(0,Q.useRef)(!1),Pn=(0,Q.useRef)(p);(0,Q.useEffect)(()=>{if(!e){Mn.current=!1;return}Mn.current&&Pn.current===p||(Mn.current=!0,Pn.current=p,Re(p),bt(k.generationOptions||{}),St(k.embeddingSettings||Mi),Et(k.ttsSettings||Ni),At(k.imageGenSettings||Pi))},[e,k.embeddingSettings,k.generationOptions,k.imageGenSettings,k.ttsSettings,p]);let Fn=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(!e){Fn.current=!1;return}Fn.current||(Fn.current=!0,ne(),S())},[e,ne,S]),(0,Q.useEffect)(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e]);let In=async e=>{let t=ut[e];if(!t?.trim()){V.error(B(`settings.plugins.apiKey.enterKey`));return}ht(e);try{let n=await Kt.setApiKey(e,t.trim());n.success?(V.success(B(`settings.plugins.apiKey.saved`)),await Y.invalidateQueries({queryKey:[`plugin-credentials`]}),await ne(),await Promise.all([Y.invalidateQueries({queryKey:[`image-gen-data`]}),Y.invalidateQueries({queryKey:[`tts-data`]})]),dt(t=>({...t,[e]:``})),pt(t=>({...t,[e]:!1}))):V.error(n.error||B(`settings.plugins.apiKey.saveFailed`))}catch{V.error(B(`settings.plugins.apiKey.saveFailed`))}finally{ht(null)}},Ln=async e=>{ht(e);try{let t=await Kt.deleteApiKey(e);t.success?(V.success(B(`settings.plugins.apiKey.removed`)),await Y.invalidateQueries({queryKey:[`plugin-credentials`]}),await ne(),await Promise.all([Y.invalidateQueries({queryKey:[`image-gen-data`]}),Y.invalidateQueries({queryKey:[`tts-data`]})]),dt(t=>({...t,[e]:``}))):V.error(t.error||B(`settings.plugins.apiKey.removeFailed`))}catch{V.error(B(`settings.plugins.apiKey.removeFailed`))}finally{ht(null)}},zn=(e,t)=>{let n=Ut(un,e,t);n&&Et(r=>({...r,model:e,pluginId:t,voice:n.config?.default_voice??``,voiceProfileId:``}))},Bn=(e,t)=>{let n=Qt(xn,e,t);n&&At(t=>({...t,model:e,pluginId:n.plugin,size:Zt(n.config?.sizes,t.size,n.config?.default_size,`1024x1024`),quality:Zt(n.config?.qualities,t.quality,n.config?.default_quality,`standard`),style:Zt(n.config?.styles,t.style,n.config?.default_style,`vivid`)}))},Vn=(e,t)=>{Et(n=>({...n,[e]:t}))},Hn=(e,t)=>{Et(n=>({...n,voice:e,voiceProfileId:t}))},Un=async e=>{if(window.confirm(B(`settings.tts.revokeSavedVoiceConfirm`,{name:e.name,defaultValue:`Withdraw consent for “{{name}}”? The saved voice can no longer be used, but the consent record is kept.`})))try{let t=await It.revokeVoiceProfile(e.id);if(!t.success)throw Error(t.error||B(`settings.tts.savedVoiceRevokeFailed`));let n=t.data;Y.setQueryData([`tts-voice-profiles`],t=>t?.map(t=>t.id===e.id&&n?n:t)??[]),await Y.invalidateQueries({queryKey:[`tts-voice-profiles`]}),V.success(B(`settings.tts.savedVoiceRevoked`,{defaultValue:`Consent withdrawn`}))}catch(e){V.error(g(e,B(`settings.tts.savedVoiceRevokeFailed`,{defaultValue:`Failed to withdraw consent`})))}},Kn=async e=>{if(!window.confirm(B(`settings.tts.deleteSavedVoiceConfirm`,{name:e.name,defaultValue:`Delete the saved voice “{{name}}”? Its reference recording and transcript will be removed.`})))return;try{await It.deleteVoiceProfile(e.id)}catch(e){V.error(g(e,B(`settings.tts.savedVoiceDeleteFailed`,{defaultValue:`Failed to delete saved voice`})));return}let t=X?.config?.default_voice??``;if(Tt.voiceProfileId===e.id&&Et(e=>({...e,voiceProfileId:``,voice:t})),k.ttsSettings?.voiceProfileId===e.id&&j({...k,ttsSettings:{...k.ttsSettings,voiceProfileId:``,voice:t}}),Y.setQueryData([`tts-voice-profiles`],t=>t?.filter(t=>t.id!==e.id)??[]),await Y.invalidateQueries({queryKey:[`tts-voice-profiles`]}),V.success(B(`settings.tts.savedVoiceDeleted`,{defaultValue:`Saved voice deleted`})),k.ttsSettings?.voiceProfileId===e.id)try{let e=await q.updatePreferences({ttsSettings:{...k.ttsSettings,voiceProfileId:``,voice:t}});if(!e.success||!e.data)throw Error(e.error||`Preference update failed`);j(e.data)}catch{V.error(B(`settings.tts.savedVoicePreferenceCleanupFailed`,{defaultValue:`Saved voice deleted, but Speech settings could not be reset`}))}},qn=async()=>{try{let e=await q.updatePreferences({ttsSettings:_n});e.success&&e.data&&(j(e.data),V.success(B(`settings.tts.saveSuccess`)))}catch(e){let t=e instanceof Error?e.message:String(e);V.error(B(`settings.tts.saveFailed`,{error:t}))}},Yn=async()=>{if(Dt){let e=G.current;e&&(e.pause(),e.currentTime=0,G.current=null),Ot(!1);return}Ot(!0);try{let e=await It.generateBase64({model:_n.model||`tts-1`,pluginId:_n.pluginId,input:`Hello! This is a test of the text-to-speech system.`,voice:_n.voiceProfileId?void 0:_n.voice||void 0,voiceProfileId:_n.voiceProfileId||void 0,speed:_n.speed||1,response_format:X?.config?.default_format});if(e.success&&e.data?.audio){let t=`data:${e.data.mimeType};base64,${e.data.audio}`,n=new Audio(t);G.current=n,n.onended=()=>{Ot(!1),G.current=null},n.onerror=()=>{V.error(B(`ttsButton.playbackFailed`)),Ot(!1),G.current=null},await n.play()}else throw Error(e.message||B(`ttsButton.generateFailed`))}catch(e){let t=e instanceof Error?e.message:String(e);V.error(B(`settings.tts.testFailed`,{error:t})),Ot(!1)}},Xn=()=>{Et({enabled:!1,autoPlay:!1,model:un[0]?.model||``,voice:un[0]?.config?.default_voice??``,voiceProfileId:``,speed:1,pluginId:un[0]?.plugin||``,streamSentences:!0})},Zn=(e,t)=>{At(n=>({...n,[e]:t}))},Qn=async()=>{try{let e=await q.updatePreferences({imageGenSettings:wn});e.success&&e.data&&(j(e.data),V.success(B(`settings.imageGen.saveSuccess`)))}catch(e){let t=e instanceof Error?e.message:String(e);V.error(B(`settings.imageGen.saveFailed`,{error:t}))}},$n=()=>{At({enabled:!1,model:xn[0]?.model||``,size:xn[0]?.config?.default_size||`1024x1024`,quality:xn[0]?.config?.default_quality||`standard`,style:xn[0]?.config?.default_style||`vivid`,pluginId:xn[0]?.plugin||``})},er=async()=>{try{wt(!0);let e=await Vt.regenerateEmbeddings();e.success&&e.data&&(V.success(e.data.documentsSkipped>0?B(`settings.documents.embeddings.regeneratePartialSuccess`,{count:e.data.documentsRegenerated,skipped:e.data.documentsSkipped}):B(`settings.documents.embeddings.regenerateSuccess`,{count:e.data.documentsRegenerated})),await Y.invalidateQueries({queryKey:[`embedding-status`]}))}catch(e){let t=e instanceof Error?e.message:String(e);V.error(B(`settings.documents.embeddings.regenerateFailed`,{error:t}))}finally{wt(!1)}},tr=async e=>{let t=e.target.files?.[0];t&&(await re(t),qe(!1),st.current&&(st.current.value=``),await S(),await Promise.all([Y.invalidateQueries({queryKey:[`image-gen-data`]}),Y.invalidateQueries({queryKey:[`tts-data`]})]))},nr=async()=>{try{let e=JSON.parse(et);await se(e),$e(!1),nt(``),await S(),await Promise.all([Y.invalidateQueries({queryKey:[`image-gen-data`]}),Y.invalidateQueries({queryKey:[`tts-data`]})])}catch{ae(),V.error(B(`settings.plugins.invalidJson`))}},rr=async e=>{F.find(t=>t.id===e)?.active?await z(e):await R(e),await S(),await Promise.all([Y.invalidateQueries({queryKey:[`image-gen-data`]}),Y.invalidateQueries({queryKey:[`tts-data`]})])},ir=async e=>{if(!_t[e]){vt(t=>({...t,[e]:!0}));try{let t=await Kt.discoverModels(e);if(!t.success||!t.data){V.error(t.error||B(`settings.plugins.modelCatalogRefreshFailed`));return}await Promise.all([ne(),S()]);let{outcome:n,models:r,reason:i}=t.data;n===`updated`?V.success(B(`settings.plugins.modelCatalogUpdated`,{count:r.length})):n===`unchanged`?V.success(B(`settings.plugins.modelCatalogUnchanged`)):n===`missing_credentials`?V.error(i||B(`settings.plugins.modelCatalogNeedsApiKey`)):V.error(i?`${B(`settings.plugins.modelCatalogUnavailable`)} ${i}`:B(`settings.plugins.modelCatalogUnavailable`))}catch(e){V.error(g(e,B(`settings.plugins.modelCatalogRefreshFailed`)))}finally{vt(t=>{let n={...t};return delete n[e],n})}}},ar=async e=>{window.confirm(B(`pluginManager.confirmDelete`))&&(await L(e),await S(),await Promise.all([Y.invalidateQueries({queryKey:[`image-gen-data`]}),Y.invalidateQueries({queryKey:[`tts-data`]})]))},or=async e=>{await ie(e)};if(!e)return null;let sr=e=>{let t=A.getState().theme,n=w({...t,mode:e});O(n)},lr=e=>{let t=A.getState().theme,n=w({...t,accent:e});O(n)},ur=e=>{let t=A.getState().theme,n=w({...t,accent:`custom`,customAccent:e});O(n)},dr=e=>{let t=A.getState().theme,n=w({...t,adaptToAccent:e});O(n)},pr=e=>{j({showUsername:e}),q.updatePreferences({showUsername:e}).catch(e=>{let t=e instanceof Error?e.message:String(e);V.error(B(`settings.preferences.updateFailed`,{error:t}))})},mr=e=>{j({showFollowUpSuggestions:e}),q.updatePreferences({showFollowUpSuggestions:e}).catch(e=>{let t=e instanceof Error?e.message:String(e);V.error(B(`settings.preferences.updateFailed`,{error:t}))})},hr=e=>{j({autoOpenArtifactPanel:e}),q.updatePreferences({autoOpenArtifactPanel:e}).catch(e=>{let t=e instanceof Error?e.message:String(e);V.error(B(`settings.preferences.updateFailed`,{error:t}))})},gr=e=>{j({hapticFeedbackEnabled:e}),e&&tn(`selection`),q.updatePreferences({hapticFeedbackEnabled:e}).catch(e=>{let t=e instanceof Error?e.message:String(e);V.error(B(`settings.preferences.updateFailed`,{error:t}))})},vr=async e=>{let t=``,n=null,r=null;if(!e.target.value)t=``;else{let i=h(ve,e.target.value);if(!i)return;t=i.model,n=i.providerType??null,r=i.providerId??null}j({defaultModel:t,defaultProviderType:n,defaultProviderId:r});let i=await d(t,n,r);i.success?V.success(B(`settings.model.defaultModelUpdated`)):V.error(B(`settings.preferences.updateFailed`,{error:i.error||B(`errors.generic`)}))},yr=e=>{Re(e.target.value)},br=async()=>{await _(Le)?V.success(B(`settings.systemMessage.saved`)):V.error(B(`settings.systemMessage.saveFailed`))},xr=async()=>{window.confirm(B(`settings.data.clearAllConfirm`))&&await v()},Cr=()=>{Ve(!0),We(null),J.pullAllModelsStream(e=>{We(e)},()=>{Ve(!1),We(null),V.success(B(`settings.model.allModelsUpdated`))},e=>{Ve(!1),We(null),V.error(B(`settings.model.updateAllFailed`,{error:e}))})},Er=e=>{let t={...k.titleSettings,autoTitle:e,taskModel:k.titleSettings?.taskModel||``};j({titleSettings:t}),q.updatePreferences({titleSettings:t})},Dr=e=>{if(!e){let e={visionModel:``,visionProviderType:null,visionProviderId:null};j(e),q.updatePreferences(e);return}let t=h(Ce,e);if(!t?.providerType){V.error(B(`settings.model.visionModelNoProvider`));return}let n={visionModel:t.model,visionProviderType:t.providerType,visionProviderId:t.providerId||null};j(n),q.updatePreferences(n).catch(e=>{let t=e instanceof Error?e.message:String(e);V.error(B(`settings.model.visionModelUpdateFailed`,{error:t}))})},Or=e=>{let t=e&&e!==ji?h(be,e):null,n={...k.titleSettings,autoTitle:k.titleSettings?.autoTitle||!1,taskModel:t?.model||e,taskProviderType:t?.providerType||null,taskProviderId:(t?.providerType===`plugin`||t?.providerType===`agent`)&&t.providerId||null};j({titleSettings:n}),q.updatePreferences({titleSettings:n})},kr=(e,t)=>{dt(n=>({...n,[e]:t}))},Ar=(e,t)=>{pt(n=>({...n,[e]:t}))},jr=(e,t)=>{bt(n=>({...n,[e]:t}))},Mr=async()=>{try{let e=Ne===`model`&&o?await q.setModelGenerationOptions(o,yt):await q.setGenerationOptions(yt);e.success&&e.data&&(j(e.data),V.success(B(`settings.generation.saveSuccess`)))}catch(e){let t=e instanceof Error?e.message:String(e);V.error(B(`settings.generation.saveFailed`,{error:t}))}},Nr=async()=>{try{let e=Ne===`model`&&o?await q.setModelGenerationOptions(o,{}):await q.resetGenerationOptions();if(e.success&&e.data){j(e.data);let t=Ne===`model`&&o,n=t?await U(o):{};bt({...e.data.generationOptions||{},...n}),V.success(t?B(`settings.generation.modelDefaultsLoaded`,{model:o}):B(`settings.generation.resetSuccess`))}}catch(e){let t=e instanceof Error?e.message:String(e);V.error(B(`settings.generation.resetFailed`,{error:t}))}},Pr=(e,t)=>{St(n=>({...n,[e]:t}))},Fr=[...an.map(e=>({value:e.id,label:`${e.name} (${e.pluginName||e.provider})`})),...!an.find(e=>e.id===on.model||e.rawModel===on.model)&&on.model?[{value:on.model,label:`${on.model} (current)`}]:[]],Ir=async()=>{try{let e=await q.setEmbeddingSettings(on);e.success&&e.data&&(j(e.data),V.success(B(`settings.documents.embeddings.saveSuccess`)))}catch(e){let t=e instanceof Error?e.message:String(e);V.error(B(`settings.documents.embeddings.saveFailed`,{error:t}))}},Lr=async()=>{try{let e=await q.resetEmbeddingSettings();e.success&&e.data&&(j(e.data),St(e.data.embeddingSettings||{}),V.success(B(`settings.documents.embeddings.resetSuccess`)))}catch(e){let t=e instanceof Error?e.message:String(e);V.error(B(`settings.documents.embeddings.resetFailed`,{error:t}))}},Rr={appearance:`theme dark light accent color language username follow-up background interface artifact panel auto open`,data:`export import backup clear history sessions`,about:`version license update`,models:`default model system prompt title vision auto`,generation:`temperature top_p top_k seed tokens context penalty embedding chunk similarity`,documents:`upload pdf rag document embedding`,tts:`voice speech audio speak read aloud`,"image-gen":`image generation size quality style`,plugins:`api key provider connection openai anthropic groq gemini deepseek bedrock aws amazon`,search:`web search searxng internet browse sources`,shortcuts:`keyboard keys hotkeys shortcut command palette`,sessions:`sessions devices sign out logout revoke security login`,"api-keys":`api key token scope secret bearer security integration`,"model-manager":`models download pull update bulk refresh delete ollama library huggingface bulk operations update all models ${B(`settings.model.bulkOperations`)} ${B(`settings.model.updateAll`)}`.toLowerCase(),prompts:`prompts slash command template variables library rollback`,skills:`skills manifest instructions slug load_skill rollback`,tools:`tools mcp openapi server credential approval function calling`},zr=Fe.trim().toLowerCase(),Br=e=>!zr||e.label.toLowerCase().includes(zr)||(Rr[e.id]||``).includes(zr),Vr=[{id:`general`,label:B(`settings.groups.general`,`General`),tabs:[{id:`appearance`,label:B(`settings.tabs.appearance`),icon:tt},{id:`data`,label:B(`settings.tabs.data`),icon:P},{id:`sessions`,label:B(`settings.tabs.sessions`,`Sessions`),icon:gt},{id:`notifications`,label:B(`settings.tabs.notifications`,`Notifications`),icon:Je},{id:`api-keys`,label:B(`settings.tabs.apiKeys`,`API keys`),icon:pe},{id:`shortcuts`,label:B(`settings.tabs.shortcuts`),icon:je},{id:`about`,label:B(`settings.tabs.about`),icon:rt}]},{id:`chat`,label:B(`settings.groups.chat`,`Chat`),tabs:[{id:`models`,label:B(`settings.tabs.model`),icon:Be},{id:`model-manager`,label:B(`models.title`),icon:Ke,disabled:Oe?.ollamaEnabled===!1,disabledHint:B(`settings.tabs.ollamaDisabled`)},{id:`generation`,label:B(`settings.tabs.generation`),icon:ge},{id:`documents`,label:B(`settings.tabs.documents`),icon:Ke},{id:`prompts`,label:B(`sidebar.navigation.prompts`),icon:He},{id:`skills`,label:B(`sidebar.navigation.skills`),icon:Xe}]},{id:`media`,label:B(`settings.groups.media`,`Speech & images`),tabs:[{id:`tts`,label:B(`settings.tabs.tts`),icon:Ze},{id:`image-gen`,label:B(`settings.tabs.imageGen`),icon:ue}]},{id:`connections`,label:B(`settings.groups.connections`,`Connections`),tabs:[{id:`plugins`,label:B(`settings.tabs.plugins`),icon:M},{id:`tools`,label:B(`sidebar.navigation.tools`),icon:it},...ke?[{id:`search`,label:B(`settings.tabs.search`),icon:at}]:[]]},...ke?[{id:`admin`,label:B(`settings.groups.admin`,`Administration`),tabs:[{id:`users`,label:B(`userManager.title`),icon:ot}]}]:[]],Ur=Vr.map(e=>({...e,tabs:e.tabs.filter(Br)})).filter(e=>e.tabs.length>0),Wr=Ur.flatMap(e=>e.tabs),Gr=Wr.filter(e=>!e.disabled),Kr=Gr.some(e=>e.id===Ae)?Ae:Gr[0]?.id,qr=Vr.flatMap(e=>e.tabs).find(e=>e.id===Ae)?.label,Jr=(e,t)=>{let n=getComputedStyle(e.currentTarget).direction===`rtl`,r=he?`ArrowDown`:n?`ArrowLeft`:`ArrowRight`;if(![r,he?`ArrowUp`:n?`ArrowRight`:`ArrowLeft`,`Home`,`End`].includes(e.key))return;e.preventDefault();let i=Gr.findIndex(e=>e.id===t),a=e.key===`Home`?0:e.key===`End`?Gr.length-1:(i+(e.key===r?1:-1)+Gr.length)%Gr.length,o=Gr[a];if(!o)return;Me(o.id);let s=document.getElementById(`${ce}-tab-${o.id}`);s?.focus({preventScroll:!0}),s?.scrollIntoView({block:`nearest`,inline:`nearest`})};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-50 bg-(--overlay-mask) backdrop-blur-xs transition-opacity duration-200`,onClick:t}),(0,$.jsx)(`div`,{ref:le,className:`fixed inset-0 z-50 flex items-center justify-center p-0 sm:p-6`,role:`dialog`,tabIndex:-1,"aria-modal":`true`,"aria-labelledby":ce,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:(0,$.jsxs)(`div`,{"data-testid":`settings-modal-panel`,className:`flex h-full w-full flex-col overscroll-behavior-contain bg-surface shadow-lv3 animate-scale-in sm:h-[min(1000px,calc(100vh-2.5rem))] sm:max-w-[1280px] sm:rounded-[24px] sm:border sm:border-black/4 sm:dark:border-white/6`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-line px-4 py-4 sm:hidden`,children:[(0,$.jsx)(`h2`,{className:`text-xl font-medium text-ink`,children:B(`settings.title`)}),(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:t,className:`h-9 w-9 touch-manipulation rounded-full p-0 hover:bg-interactive-hover`,title:B(`common.close`,{defaultValue:`Close`}),"aria-label":B(`common.close`),children:(0,$.jsx)(Ye,{className:`h-5 w-5`})})]}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overscroll-behavior-contain sm:flex-row`,children:[(0,$.jsxs)(`div`,{className:`flex min-h-0 w-full shrink-0 flex-col border-b border-line p-2 sm:w-[210px] sm:border-b-0 sm:px-3 sm:pb-3 sm:pt-[22px]`,children:[(0,$.jsx)(`h2`,{id:ce,className:`hidden shrink-0 px-3 pb-4 text-base font-medium leading-6 text-ink sm:block`,children:B(`settings.title`)}),(0,$.jsxs)(`div`,{className:`relative mb-2 hidden shrink-0 sm:block`,children:[(0,$.jsx)(oe,{className:`pointer-events-none absolute inset-s-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-ink-subtle`}),(0,$.jsx)(`input`,{ref:de,type:`search`,"aria-label":B(`common.search`),value:Fe,onChange:e=>{let t=e.target.value;Ie(t);let n=t.trim().toLowerCase();if(!n)return;let r=Vr.flatMap(e=>e.tabs).filter(e=>!e.disabled&&(e.label.toLowerCase().includes(n)||(Rr[e.id]||``).includes(n)));r.length>0&&!r.some(e=>e.id===Ae)&&Me(r[0].id)},placeholder:B(`common.search`),className:`h-9 w-full rounded-xl border border-transparent bg-surface-subtle pe-2.5 ps-8 text-[13px] text-ink placeholder:text-ink-subtle focus:border-primary-500/40 focus:outline-hidden`})]}),(0,$.jsxs)(`div`,{"data-testid":`settings-navigation-scroll-region`,className:`min-h-0 overflow-x-auto scrollbar-thin sm:overflow-x-hidden sm:overflow-y-auto`,style:{WebkitOverflowScrolling:`touch`},children:[(0,$.jsx)(`nav`,{className:`flex gap-1 sm:flex-col sm:gap-0`,role:`tablist`,"aria-label":B(`settings.title`,`Settings`),"aria-orientation":he?`vertical`:`horizontal`,children:Ur.map(e=>(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-1 sm:flex-col sm:gap-0.5 sm:pb-2`,children:[(0,$.jsx)(`p`,{"aria-hidden":`true`,className:`hidden px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-[0.08em] text-ink-subtle sm:block`,children:e.label}),e.tabs.map(e=>{let t=e.icon,n=Ae===e.id,r=e.disabled===!0;return(0,$.jsxs)(`button`,{id:`${ce}-tab-${e.id}`,"data-testid":`settings-tab-${e.id}`,onClick:()=>Me(e.id),onKeyDown:t=>Jr(t,e.id),tabIndex:e.id===Kr?0:-1,disabled:r,title:r?e.disabledHint:void 0,className:C(`flex h-9 shrink-0 items-center gap-2 rounded-xl px-3 text-start transition-colors duration-150 touch-manipulation outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40 sm:w-full`,r?`cursor-not-allowed text-ink-subtle opacity-60`:n?`bg-nav-active text-ink`:`text-ink hover:bg-hover-solid`),role:`tab`,"aria-selected":n,"aria-disabled":r||void 0,"aria-controls":fe,children:[(0,$.jsx)(t,{className:`h-4 w-4 shrink-0 text-ink-muted`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`truncate whitespace-nowrap text-sm`,children:e.label})]},e.id)})]},e.id))}),Wr.length===0&&(0,$.jsx)(`p`,{role:`status`,className:`px-3 py-4 text-sm text-ink-muted`,children:B(`common.noResults`)})]})]}),(0,$.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`div`,{className:`hidden h-[54px] shrink-0 items-center justify-end px-3.5 pb-2 pt-5 sm:flex`,children:(0,$.jsx)(H,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 w-7 touch-manipulation rounded-full p-0 text-ink hover:bg-interactive-hover`,title:B(`common.close`,{defaultValue:`Close`}),"aria-label":B(`common.close`),children:(0,$.jsx)(Ye,{className:`h-4 w-4`})})}),(0,$.jsx)(`div`,{"data-testid":`settings-scroll-region`,ref:me,className:`scroll-region min-h-0 flex-1 p-4 pt-2 scrollbar-thin sm:px-6 sm:pb-6 sm:pt-0`,id:fe,role:`tabpanel`,"aria-labelledby":Wr.some(e=>e.id===Ae)?`${ce}-tab-${Ae}`:void 0,"aria-label":qr,tabIndex:0,children:(()=>{switch(Ae){case`appearance`:return(0,$.jsx)(En,{theme:D,preferences:k,onThemeChange:sr,onAccentChange:lr,onCustomAccentChange:ur,onAdaptToAccentChange:dr,onShowUsernameChange:pr,onShowFollowUpsChange:mr,onAutoOpenArtifactsChange:hr,onHapticFeedbackChange:gr});case`models`:return(0,$.jsx)(Gn,{models:a,selectedModel:o,selectedProviderType:c,selectedProviderId:l,systemMessage:p,tempSystemMessage:Le,loading:b,preferences:k,currentVisionModel:we,visionModelOptions:Te,currentTaskModel:xe,autoTitleTaskModelOptions:Ee,onModelChange:vr,onSystemMessageChange:yr,onSystemMessageSave:br,onAutoTitleChange:Er,onAutoTitleTaskModelChange:Or,onVisionModelChange:Dr});case`tts`:return(0,$.jsx)(Tr,{loading:ln,settings:Tt,effectiveSettings:_n,models:un,plugins:dn,voices:fn,voiceProfiles:pn,selectableVoiceProfiles:gn,loadingVoiceProfiles:mn,testing:Dt,onSettingChange:Vn,onVoiceChange:Hn,onDeleteVoiceProfile:Kn,onRevokeVoiceProfile:Un,onModelChange:zn,onReset:Xn,onTest:Yn,onSave:qn});case`image-gen`:return(0,$.jsx)(Rn,{loading:yn,settings:K,effectiveSettings:wn,models:xn,plugins:Sn,sizes:Tn,qualities:On,styles:jn,onSettingChange:Zn,onModelChange:Bn,onReset:$n,onSave:Qn});case`documents`:return(0,$.jsx)(An,{settings:W,effectiveSettings:on,modelOptions:Fr,status:sn,regenerating:Ct,onSettingChange:Pr,onReset:Lr,onRegenerate:er,onSave:Ir});case`search`:return(0,$.jsx)(fr,{});case`users`:return(0,$.jsxs)(`div`,{className:`pb-2`,children:[(0,$.jsx)(Dn,{title:B(`userManager.title`),description:B(`userManager.pageDescription`)}),(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(ki,{})})]});case`model-manager`:return(0,$.jsxs)(`div`,{className:`pb-2`,children:[(0,$.jsx)(Dn,{title:B(`models.title`),description:B(`models.subtitle`)}),(0,$.jsx)(Di,{updatingAllModels:ze,updateProgress:Ue,onUpdateAllModels:Cr})]});case`prompts`:return(0,$.jsx)(Hr,{});case`skills`:return(0,$.jsx)(Xr,{});case`tools`:return(0,$.jsx)(li,{});case`sessions`:return(0,$.jsx)(_r,{});case`notifications`:return(0,$.jsx)(Sr,{});case`api-keys`:return(0,$.jsx)(wr,{});case`plugins`:return(0,$.jsx)(cr,{plugins:F,loading:I,uploading:ee,error:te,hasKeys:rn,showUploadForm:Ge,showJsonForm:Qe,jsonInput:et,fileInputRef:st,expandedPluginId:ct,pluginApiKeys:ut,showApiKey:ft,savingApiKey:mt,refreshingPluginIds:_t,onClearError:ae,onShowUploadFormChange:qe,onShowJsonFormChange:$e,onJsonInputChange:nt,onFileUpload:tr,onJsonSubmit:nr,onExpandedPluginChange:lt,onPluginApiKeyChange:kr,onShowApiKeyChange:Ar,onActivatePlugin:rr,onRefreshModels:ir,onDeletePlugin:ar,onExportPlugin:or,onSaveApiKey:In,onDeleteApiKey:Ln});case`data`:return(0,$.jsx)(kn,{sessionCount:x.length,loading:b,importing:jt,preflighting:Mt,preflight:Pt,showImportOptions:Ft,mergeStrategy:Lt,importResult:Rt,importFileInputRef:Ht,onExportData:Wt,onImportFileSelect:Gt,onClearAllHistory:xr,onMergeStrategyChange:qt,onConfirmImport:Yt,onCancelImport:nn,onDismissImportResult:()=>zt(null)});case`shortcuts`:return(0,$.jsx)(Jn,{});case`about`:return(0,$.jsx)(bn,{appVersion:Ai});case`generation`:return(0,$.jsx)(Nn,{generationOptions:yt,generationScope:Ne,scopedModel:o||void 0,onGenerationScopeChange:Pe,embeddingSettings:W,effectiveEmbeddingSettings:on,embeddingModelOptions:Fr,embeddingStatus:sn,onGenerationOptionChange:jr,onEmbeddingSettingsChange:Pr,onResetGenerationOptions:Nr,onSaveGenerationOptions:Mr,onResetEmbeddingSettings:Lr,onSaveEmbeddingSettings:Ir});default:return null}})()})]})]})]})})]})};export{Fi as SettingsModal};