libre-webui 0.10.0 → 0.12.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 (298) hide show
  1. package/README.md +75 -61
  2. package/backend/dist/db.d.ts.map +1 -1
  3. package/backend/dist/db.js +21 -19
  4. package/backend/dist/db.js.map +1 -1
  5. package/backend/dist/index.d.ts.map +1 -1
  6. package/backend/dist/index.js +39 -908
  7. package/backend/dist/index.js.map +1 -1
  8. package/backend/dist/middleware/auth.d.ts.map +1 -1
  9. package/backend/dist/middleware/auth.js +4 -2
  10. package/backend/dist/middleware/auth.js.map +1 -1
  11. package/backend/dist/middleware/index.d.ts.map +1 -1
  12. package/backend/dist/middleware/index.js +4 -2
  13. package/backend/dist/middleware/index.js.map +1 -1
  14. package/backend/dist/models/personaModel.d.ts.map +1 -1
  15. package/backend/dist/models/personaModel.js +11 -9
  16. package/backend/dist/models/personaModel.js.map +1 -1
  17. package/backend/dist/routes/auth.d.ts.map +1 -1
  18. package/backend/dist/routes/auth.js +36 -14
  19. package/backend/dist/routes/auth.js.map +1 -1
  20. package/backend/dist/routes/chat.d.ts.map +1 -1
  21. package/backend/dist/routes/chat.js +61 -249
  22. package/backend/dist/routes/chat.js.map +1 -1
  23. package/backend/dist/routes/documents.d.ts.map +1 -1
  24. package/backend/dist/routes/documents.js +10 -8
  25. package/backend/dist/routes/documents.js.map +1 -1
  26. package/backend/dist/routes/imageGen.d.ts.map +1 -1
  27. package/backend/dist/routes/imageGen.js +9 -7
  28. package/backend/dist/routes/imageGen.js.map +1 -1
  29. package/backend/dist/routes/libreClaw.d.ts +3 -0
  30. package/backend/dist/routes/libreClaw.d.ts.map +1 -0
  31. package/backend/dist/routes/libreClaw.js +156 -0
  32. package/backend/dist/routes/libreClaw.js.map +1 -0
  33. package/backend/dist/routes/ollama.d.ts.map +1 -1
  34. package/backend/dist/routes/ollama.js +7 -247
  35. package/backend/dist/routes/ollama.js.map +1 -1
  36. package/backend/dist/routes/plugins.d.ts.map +1 -1
  37. package/backend/dist/routes/plugins.js +7 -105
  38. package/backend/dist/routes/plugins.js.map +1 -1
  39. package/backend/dist/routes/tts.d.ts.map +1 -1
  40. package/backend/dist/routes/tts.js +7 -5
  41. package/backend/dist/routes/tts.js.map +1 -1
  42. package/backend/dist/routes/users.d.ts.map +1 -1
  43. package/backend/dist/routes/users.js +7 -5
  44. package/backend/dist/routes/users.js.map +1 -1
  45. package/backend/dist/services/assistantCompletionService.d.ts +26 -0
  46. package/backend/dist/services/assistantCompletionService.d.ts.map +1 -0
  47. package/backend/dist/services/assistantCompletionService.js +53 -0
  48. package/backend/dist/services/assistantCompletionService.js.map +1 -0
  49. package/backend/dist/services/authService.d.ts +2 -0
  50. package/backend/dist/services/authService.d.ts.map +1 -1
  51. package/backend/dist/services/authService.js +9 -5
  52. package/backend/dist/services/authService.js.map +1 -1
  53. package/backend/dist/services/chatGenerationService.d.ts +32 -0
  54. package/backend/dist/services/chatGenerationService.d.ts.map +1 -0
  55. package/backend/dist/services/chatGenerationService.js +118 -0
  56. package/backend/dist/services/chatGenerationService.js.map +1 -0
  57. package/backend/dist/services/chatRequestService.d.ts +55 -0
  58. package/backend/dist/services/chatRequestService.d.ts.map +1 -0
  59. package/backend/dist/services/chatRequestService.js +103 -0
  60. package/backend/dist/services/chatRequestService.js.map +1 -0
  61. package/backend/dist/services/chatService.d.ts +0 -1
  62. package/backend/dist/services/chatService.d.ts.map +1 -1
  63. package/backend/dist/services/chatService.js +13 -27
  64. package/backend/dist/services/chatService.js.map +1 -1
  65. package/backend/dist/services/documentService.d.ts.map +1 -1
  66. package/backend/dist/services/documentService.js +21 -19
  67. package/backend/dist/services/documentService.js.map +1 -1
  68. package/backend/dist/services/embeddingService.d.ts.map +1 -1
  69. package/backend/dist/services/embeddingService.js +3 -1
  70. package/backend/dist/services/embeddingService.js.map +1 -1
  71. package/backend/dist/services/encryptionService.d.ts.map +1 -1
  72. package/backend/dist/services/encryptionService.js +26 -24
  73. package/backend/dist/services/encryptionService.js.map +1 -1
  74. package/backend/dist/services/galleryService.d.ts.map +1 -1
  75. package/backend/dist/services/galleryService.js +8 -6
  76. package/backend/dist/services/galleryService.js.map +1 -1
  77. package/backend/dist/services/libreClawService.d.ts +105 -0
  78. package/backend/dist/services/libreClawService.d.ts.map +1 -0
  79. package/backend/dist/services/libreClawService.js +169 -0
  80. package/backend/dist/services/libreClawService.js.map +1 -0
  81. package/backend/dist/services/memoryService.d.ts +2 -13
  82. package/backend/dist/services/memoryService.d.ts.map +1 -1
  83. package/backend/dist/services/memoryService.js +37 -198
  84. package/backend/dist/services/memoryService.js.map +1 -1
  85. package/backend/dist/services/memoryUtils.d.ts +29 -0
  86. package/backend/dist/services/memoryUtils.d.ts.map +1 -0
  87. package/backend/dist/services/memoryUtils.js +165 -0
  88. package/backend/dist/services/memoryUtils.js.map +1 -0
  89. package/backend/dist/services/mutationEngineService.d.ts.map +1 -1
  90. package/backend/dist/services/mutationEngineService.js +3 -1
  91. package/backend/dist/services/mutationEngineService.js.map +1 -1
  92. package/backend/dist/services/ollamaService.d.ts.map +1 -1
  93. package/backend/dist/services/ollamaService.js +36 -34
  94. package/backend/dist/services/ollamaService.js.map +1 -1
  95. package/backend/dist/services/personaService.d.ts.map +1 -1
  96. package/backend/dist/services/personaService.js +3 -1
  97. package/backend/dist/services/personaService.js.map +1 -1
  98. package/backend/dist/services/pluginCapabilityRegistryService.d.ts +11 -0
  99. package/backend/dist/services/pluginCapabilityRegistryService.d.ts.map +1 -0
  100. package/backend/dist/services/pluginCapabilityRegistryService.js +70 -0
  101. package/backend/dist/services/pluginCapabilityRegistryService.js.map +1 -0
  102. package/backend/dist/services/pluginCredentialsService.d.ts.map +1 -1
  103. package/backend/dist/services/pluginCredentialsService.js +13 -11
  104. package/backend/dist/services/pluginCredentialsService.js.map +1 -1
  105. package/backend/dist/services/pluginEmbeddingService.d.ts +26 -0
  106. package/backend/dist/services/pluginEmbeddingService.d.ts.map +1 -0
  107. package/backend/dist/services/pluginEmbeddingService.js +159 -0
  108. package/backend/dist/services/pluginEmbeddingService.js.map +1 -0
  109. package/backend/dist/services/pluginImageGenerationService.d.ts +29 -0
  110. package/backend/dist/services/pluginImageGenerationService.d.ts.map +1 -0
  111. package/backend/dist/services/pluginImageGenerationService.js +402 -0
  112. package/backend/dist/services/pluginImageGenerationService.js.map +1 -0
  113. package/backend/dist/services/pluginService.d.ts +9 -18
  114. package/backend/dist/services/pluginService.d.ts.map +1 -1
  115. package/backend/dist/services/pluginService.js +118 -1469
  116. package/backend/dist/services/pluginService.js.map +1 -1
  117. package/backend/dist/services/pluginTTSService.d.ts +28 -0
  118. package/backend/dist/services/pluginTTSService.d.ts.map +1 -0
  119. package/backend/dist/services/pluginTTSService.js +286 -0
  120. package/backend/dist/services/pluginTTSService.js.map +1 -0
  121. package/backend/dist/services/pluginVariablesService.d.ts.map +1 -1
  122. package/backend/dist/services/pluginVariablesService.js +7 -5
  123. package/backend/dist/services/pluginVariablesService.js.map +1 -1
  124. package/backend/dist/services/preferencesService.d.ts.map +1 -1
  125. package/backend/dist/services/preferencesService.js +9 -7
  126. package/backend/dist/services/preferencesService.js.map +1 -1
  127. package/backend/dist/services/simpleGitHubOAuth.d.ts.map +1 -1
  128. package/backend/dist/services/simpleGitHubOAuth.js +10 -8
  129. package/backend/dist/services/simpleGitHubOAuth.js.map +1 -1
  130. package/backend/dist/services/simpleHuggingFaceOAuth.d.ts.map +1 -1
  131. package/backend/dist/services/simpleHuggingFaceOAuth.js +11 -9
  132. package/backend/dist/services/simpleHuggingFaceOAuth.js.map +1 -1
  133. package/backend/dist/services/systemSettingsService.d.ts.map +1 -1
  134. package/backend/dist/services/systemSettingsService.js +4 -2
  135. package/backend/dist/services/systemSettingsService.js.map +1 -1
  136. package/backend/dist/services/titleGenerationService.d.ts +55 -0
  137. package/backend/dist/services/titleGenerationService.d.ts.map +1 -0
  138. package/backend/dist/services/titleGenerationService.js +121 -0
  139. package/backend/dist/services/titleGenerationService.js.map +1 -0
  140. package/backend/dist/services/turnstileService.d.ts +13 -0
  141. package/backend/dist/services/turnstileService.d.ts.map +1 -0
  142. package/backend/dist/services/turnstileService.js +79 -0
  143. package/backend/dist/services/turnstileService.js.map +1 -0
  144. package/backend/dist/storage.d.ts +2 -22
  145. package/backend/dist/storage.d.ts.map +1 -1
  146. package/backend/dist/storage.js +22 -170
  147. package/backend/dist/storage.js.map +1 -1
  148. package/backend/dist/storageMappers.d.ts +82 -0
  149. package/backend/dist/storageMappers.d.ts.map +1 -0
  150. package/backend/dist/storageMappers.js +85 -0
  151. package/backend/dist/storageMappers.js.map +1 -0
  152. package/backend/dist/test-encryption.js +20 -18
  153. package/backend/dist/test-encryption.js.map +1 -1
  154. package/backend/dist/types/index.d.ts.map +1 -1
  155. package/backend/dist/types/index.js.map +1 -1
  156. package/backend/dist/utils/assistantBranching.d.ts +8 -0
  157. package/backend/dist/utils/assistantBranching.d.ts.map +1 -0
  158. package/backend/dist/utils/assistantBranching.js +30 -0
  159. package/backend/dist/utils/assistantBranching.js.map +1 -0
  160. package/backend/dist/utils/chatContext.d.ts +17 -0
  161. package/backend/dist/utils/chatContext.d.ts.map +1 -0
  162. package/backend/dist/utils/chatContext.js +82 -0
  163. package/backend/dist/utils/chatContext.js.map +1 -0
  164. package/backend/dist/utils/chatDocumentContext.d.ts +7 -0
  165. package/backend/dist/utils/chatDocumentContext.d.ts.map +1 -0
  166. package/backend/dist/utils/chatDocumentContext.js +51 -0
  167. package/backend/dist/utils/chatDocumentContext.js.map +1 -0
  168. package/backend/dist/utils/logger.d.ts +12 -0
  169. package/backend/dist/utils/logger.d.ts.map +1 -0
  170. package/backend/dist/utils/logger.js +82 -0
  171. package/backend/dist/utils/logger.js.map +1 -0
  172. package/backend/dist/utils/ollamaLibrary.d.ts +17 -0
  173. package/backend/dist/utils/ollamaLibrary.d.ts.map +1 -0
  174. package/backend/dist/utils/ollamaLibrary.js +253 -0
  175. package/backend/dist/utils/ollamaLibrary.js.map +1 -0
  176. package/backend/dist/utils/ollamaStreaming.d.ts +19 -0
  177. package/backend/dist/utils/ollamaStreaming.d.ts.map +1 -0
  178. package/backend/dist/utils/ollamaStreaming.js +67 -0
  179. package/backend/dist/utils/ollamaStreaming.js.map +1 -0
  180. package/backend/dist/utils/pluginChatAdapter.d.ts +32 -0
  181. package/backend/dist/utils/pluginChatAdapter.d.ts.map +1 -0
  182. package/backend/dist/utils/pluginChatAdapter.js +308 -0
  183. package/backend/dist/utils/pluginChatAdapter.js.map +1 -0
  184. package/backend/dist/utils/pluginChatContext.d.ts +23 -0
  185. package/backend/dist/utils/pluginChatContext.d.ts.map +1 -0
  186. package/backend/dist/utils/pluginChatContext.js +77 -0
  187. package/backend/dist/utils/pluginChatContext.js.map +1 -0
  188. package/backend/dist/utils/pluginResponse.d.ts +6 -0
  189. package/backend/dist/utils/pluginResponse.d.ts.map +1 -0
  190. package/backend/dist/utils/pluginResponse.js +70 -0
  191. package/backend/dist/utils/pluginResponse.js.map +1 -0
  192. package/backend/dist/utils/pluginStreamAdapter.d.ts +16 -0
  193. package/backend/dist/utils/pluginStreamAdapter.d.ts.map +1 -0
  194. package/backend/dist/utils/pluginStreamAdapter.js +141 -0
  195. package/backend/dist/utils/pluginStreamAdapter.js.map +1 -0
  196. package/backend/dist/utils/pluginStreaming.d.ts +24 -0
  197. package/backend/dist/utils/pluginStreaming.d.ts.map +1 -0
  198. package/backend/dist/utils/pluginStreaming.js +106 -0
  199. package/backend/dist/utils/pluginStreaming.js.map +1 -0
  200. package/backend/dist/utils/pluginUpload.d.ts +8 -0
  201. package/backend/dist/utils/pluginUpload.d.ts.map +1 -0
  202. package/backend/dist/utils/pluginUpload.js +51 -0
  203. package/backend/dist/utils/pluginUpload.js.map +1 -0
  204. package/backend/dist/utils/pluginValidation.d.ts +9 -0
  205. package/backend/dist/utils/pluginValidation.d.ts.map +1 -0
  206. package/backend/dist/utils/pluginValidation.js +84 -0
  207. package/backend/dist/utils/pluginValidation.js.map +1 -0
  208. package/backend/dist/utils/pluginVariableValidation.d.ts +10 -0
  209. package/backend/dist/utils/pluginVariableValidation.d.ts.map +1 -0
  210. package/backend/dist/utils/pluginVariableValidation.js +80 -0
  211. package/backend/dist/utils/pluginVariableValidation.js.map +1 -0
  212. package/backend/dist/utils/websocketMessages.d.ts +26 -0
  213. package/backend/dist/utils/websocketMessages.d.ts.map +1 -0
  214. package/backend/dist/utils/websocketMessages.js +74 -0
  215. package/backend/dist/utils/websocketMessages.js.map +1 -0
  216. package/backend/dist/websocketServer.d.ts +3 -0
  217. package/backend/dist/websocketServer.d.ts.map +1 -0
  218. package/backend/dist/websocketServer.js +332 -0
  219. package/backend/dist/websocketServer.js.map +1 -0
  220. package/backend/package.json +2 -2
  221. package/frontend/dist/assets/index-Dc8Q4dJZ.css +1 -0
  222. package/frontend/dist/assets/index-ONn9VIq7.js +5 -0
  223. package/frontend/dist/assets/markdown-math-CYlHEDRF.css +1 -0
  224. package/frontend/dist/index.html +11 -10
  225. package/frontend/dist/js/ArtifactContainer-CqKsiKz0.js +1 -0
  226. package/frontend/dist/js/ArtifactDemoPage-Dd5BjIu2.js +200 -0
  227. package/frontend/dist/js/ArtifactSlideOutPanel-Yc7ttIaY.js +1 -0
  228. package/frontend/dist/js/Button-BUjLpHmR.js +1 -0
  229. package/frontend/dist/js/ChatPage-Cpy7lQ0D.js +16 -0
  230. package/frontend/dist/js/FirstTimeSetup-DcGhm0H0.js +1 -0
  231. package/frontend/dist/js/GalleryPage-DNI2Evvf.js +1 -0
  232. package/frontend/dist/js/LibreClawPage-CmTiROsJ.js +1 -0
  233. package/frontend/dist/js/ModelManagerModals-CfvSeNsT.js +1 -0
  234. package/frontend/dist/js/ModelsPage-CeTGqx4q.js +2 -0
  235. package/frontend/dist/js/OptimizedSyntaxHighlighter-CNjLqj1Z.js +1 -0
  236. package/frontend/dist/js/PersonasPage-BUqu7gJ3.js +13 -0
  237. package/frontend/dist/js/RichMessageContent-B0JO8vkR.js +3 -0
  238. package/frontend/dist/js/SettingsModal-B5aJ5vfV.js +1 -0
  239. package/frontend/dist/js/UserManagementPage-BqIIWX2M.js +1 -0
  240. package/frontend/dist/js/api-CbmZzKBu.js +15 -0
  241. package/frontend/dist/js/ar-BAOdgn6O.js +2 -0
  242. package/frontend/dist/js/artifactHtml-B7Oy2e__.js +27 -0
  243. package/frontend/dist/js/bn-Bp2KS5mx.js +2 -0
  244. package/frontend/dist/js/cs-DOgJ0c5p.js +2 -0
  245. package/frontend/dist/js/da-BCKTkC35.js +2 -0
  246. package/frontend/dist/js/de-BXyECph5.js +2 -0
  247. package/frontend/dist/js/demoMode-BhEpMVh5.js +1 -0
  248. package/frontend/dist/js/es-Db4bDYIF.js +2 -0
  249. package/frontend/dist/js/fr-BPIkf6zH.js +2 -0
  250. package/frontend/dist/js/hi-Bm8D_Aux.js +2 -0
  251. package/frontend/dist/js/id-DiWaH74_.js +2 -0
  252. package/frontend/dist/js/is-DLgJywtZ.js +2 -0
  253. package/frontend/dist/js/it-lldrM8pE.js +2 -0
  254. package/frontend/dist/js/ja-Cfe9uZmQ.js +2 -0
  255. package/frontend/dist/js/ko-BhChO3MQ.js +2 -0
  256. package/frontend/dist/js/logger-BmpKNkls.js +1 -0
  257. package/frontend/dist/js/markdown-core-fkbHPd-g.js +16 -0
  258. package/frontend/dist/js/markdown-math-Ci4QOsf-.js +261 -0
  259. package/frontend/dist/js/ms-SWtmetXo.js +2 -0
  260. package/frontend/dist/js/nl-CUO6I3nO.js +2 -0
  261. package/frontend/dist/js/pl-BUAu96P6.js +2 -0
  262. package/frontend/dist/js/pt-DCHwoWiE.js +2 -0
  263. package/frontend/dist/js/{react-vendor-Dh6nfvM2.js → react-vendor-Co1u1rWb.js} +2 -2
  264. package/frontend/dist/js/ru-Ciz053N7.js +2 -0
  265. package/frontend/dist/js/sv-D38ZHjv-.js +2 -0
  266. package/frontend/dist/js/syntax-highlight-D5wpTVgr.js +8 -0
  267. package/frontend/dist/js/th-D2cAucvn.js +2 -0
  268. package/frontend/dist/js/tr-Go355oDu.js +2 -0
  269. package/frontend/dist/js/ui-vendor-BJAeWL11.js +177 -0
  270. package/frontend/dist/js/uk-cdzjhgya.js +2 -0
  271. package/frontend/dist/js/useBaseQuery-6OJiOiyu.js +1 -0
  272. package/frontend/dist/js/useQuery-DfkI6VAv.js +1 -0
  273. package/frontend/dist/js/utils-BaPYjs_z.js +1 -0
  274. package/frontend/dist/js/utils-vendor-BX3ZwoIK.js +9 -0
  275. package/frontend/dist/js/vi-BSOpE423.js +2 -0
  276. package/frontend/dist/js/zh-BFh6sHZG.js +2 -0
  277. package/package.json +12 -8
  278. package/backend/dist/services/openclawSessionService.d.ts +0 -63
  279. package/backend/dist/services/openclawSessionService.d.ts.map +0 -1
  280. package/backend/dist/services/openclawSessionService.js +0 -307
  281. package/backend/dist/services/openclawSessionService.js.map +0 -1
  282. package/frontend/dist/assets/index-cOuIFv6G.js +0 -314
  283. package/frontend/dist/assets/index-tuVjvNle.css +0 -1
  284. package/frontend/dist/js/ArtifactContainer-DXa2t8GS.js +0 -24
  285. package/frontend/dist/js/ArtifactDemoPage-Dms7P2gI.js +0 -98
  286. package/frontend/dist/js/ChatPage-C6hOVIAS.js +0 -15
  287. package/frontend/dist/js/GalleryPage-CGKPECJV.js +0 -1
  288. package/frontend/dist/js/ModelsPage-CNB-c-JM.js +0 -1
  289. package/frontend/dist/js/PersonasPage-hDiS0Rvl.js +0 -13
  290. package/frontend/dist/js/UserManagementPage-1H9kcHeR.js +0 -1
  291. package/frontend/dist/js/api-MQ7bONaU.js +0 -3
  292. package/frontend/dist/js/appStore-BpzQfKOd.js +0 -2
  293. package/frontend/dist/js/authStore-Cn_WS6Kb.js +0 -2
  294. package/frontend/dist/js/demoMode-PKHbba1m.js +0 -1
  295. package/frontend/dist/js/markdown-vendor-DLzJCMRQ.js +0 -22
  296. package/frontend/dist/js/ui-vendor-ClcVY3m-.js +0 -177
  297. package/frontend/dist/js/utils-vendor-BCQRX-0Q.js +0 -9
  298. package/plugins/openclaw-agent.json +0 -69
@@ -1,15 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{m as t,p as n}from"./markdown-vendor-DLzJCMRQ.js";import{n as r}from"./react-vendor-Dh6nfvM2.js";import{A as i,At as a,Ct as o,E as s,Et as c,H as l,I as u,It as d,J as f,L as p,Lt as m,M as h,Mt as g,N as _,O as v,Ot as y,Q as b,S as x,St as S,T as C,Tt as w,U as T,X as E,_t as ee,a as D,bt as O,c as k,et as A,ft as j,g as te,gt as M,ht as N,i as P,kt as F,mt as I,n as L,nt as ne,o as re,ot as ie,p as ae,q as R,r as oe,rt as se,st as z,t as B,v as ce,vt as le,w as ue,x as de,yt as fe}from"./ui-vendor-ClcVY3m-.js";import{c as pe,l as me,o as V,s as he,t as H}from"./appStore-BpzQfKOd.js";import{c as ge,f as U,i as W,l as G,o as _e,r as K,s as ve}from"./api-MQ7bONaU.js";import{i as q,n as ye,r as J}from"./authStore-Cn_WS6Kb.js";import{_ as be,c as Y,d as xe,g as Se,h as Ce,m as X,p as Z,u as we,v as Te}from"../assets/index-cOuIFv6G.js";import{t as Ee}from"./ArtifactContainer-DXa2t8GS.js";var De=e(r(),1),Q=e(t(),1),$=n(),Oe=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i}=X(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},s=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=s(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(R,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,$.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,$.jsx)(w,{size:12}):(0,$.jsx)(o,{size:12}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},ke=null,Ae=null,je=0,Me=300*1e3;async function Ne(){let e=Date.now();return ke!==null&&e-je<Me?ke:Ae||(Ae=(async()=>{try{let t=await U.getModels();return t.success&&t.data&&t.data.length>0?(ke=t.data,je=e,t.data):(ke=[],je=e,[])}catch{return ke=[],je=e,[]}finally{Ae=null}})(),Ae)}function Pe(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Fe=({text:e,className:t,size:n=`sm`})=>{let{t:r}=X(),{preferences:i}=H(),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)(null),h=(0,Q.useRef)(null),g=(0,Q.useRef)(!1),_=(0,Q.useRef)([]),v=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return Ne().then(t=>{e&&(f(t),m(t.length>0))}),()=>{e=!1}},[]);let y=(0,Q.useCallback)(async(e,t,n,i)=>{let a=await U.generateBase64({model:t,input:e,voice:n,speed:i,response_format:`mp3`});if(!a.success||!a.data?.audio)throw Error(a.message||r(`ttsButton.generateFailed`));let o=`data:${a.data.mimeType};base64,${a.data.audio}`,s=new Audio(o);return h.current=s,new Promise((e,t)=>{s.onended=()=>{h.current=null,e()},s.onerror=()=>{h.current=null,t(Error(r(`ttsButton.playbackFailed`)))},s.play().catch(t)})},[r]),b=(0,Q.useCallback)(async(e,t,n,r)=>{_.current=e,v.current=0,g.current=!1;let i=null,a=async e=>{try{let i=await U.generateBase64({model:t,input:e,voice:n,speed:r,response_format:`mp3`});return!i.success||!i.data?.audio?null:{audioUrl:`data:${i.data.mimeType};base64,${i.data.audio}`,mimeType:i.data.mimeType}}catch{return null}};e.length>0&&(i=a(e[0]));for(let t=0;t<e.length&&!g.current;t++){v.current=t;try{let n=await i;if(g.current)break;if(i=t+1<e.length?a(e[t+1]):null,!n){console.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);h.current=r,await new Promise((e,t)=>{r.onended=()=>{h.current=null,e()},r.onerror=()=>{h.current=null,e()},r.play().catch(()=>{e()})})}catch(e){console.error(`Error playing sentence ${t+1}:`,e)}}},[]),x=(0,Q.useCallback)(()=>{g.current=!0,h.current&&(h.current.pause(),h.current.currentTime=0,h.current=null),o(!1),c(!1)},[]),S=async()=>{if(!s){if(a){x();return}c(!0),u(null),g.current=!1;try{let t=i.ttsSettings,n=t?.model||d[0]?.model||`tts-1`,a=t?.voice||d[0]?.config?.default_voice||`alloy`,s=t?.speed||1;if(t?.streamSentences){let t=Pe(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));c(!1),o(!0),await b(t,n,a,s),g.current||o(!1)}else await y(e,n,a,s),c(!1),o(!0),h.current&&(h.current.onended=()=>{o(!1),h.current=null},h.current.onerror=()=>{u(r(`ttsButton.playbackFailed`)),o(!1),h.current=null})}catch(e){u(e instanceof Error?e.message:r(`ttsButton.generateFailed`)),console.error(`TTS error:`,e),o(!1),c(!1)}}};if((0,Q.useEffect)(()=>()=>{g.current=!0,h.current&&(h.current.pause(),h.current=null)},[]),p===!1||p===null)return null;let C={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},w={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,$.jsx)(`button`,{onClick:S,disabled:s||!e,title:l||r(a?`ttsButton.stopSpeaking`:s?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:V(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,l?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,C[n],t),children:s?(0,$.jsx)(T,{className:V(w[n],`animate-spin`)}):a?(0,$.jsx)(te,{className:w[n]}):l?(0,$.jsx)(P,{className:w[n]}):(0,$.jsx)(D,{className:w[n]})})},Ie=[{regex:/```html\s*\n([\s\S]*?)\n```/gi,type:`html`,getTitle:e=>ze(e)||`HTML Document`},{regex:/```svg\s*\n([\s\S]*?)\n```/gi,type:`svg`,getTitle:e=>`SVG Image`},{regex:/```(?:react|jsx)\s*\n([\s\S]*?)\n```/gi,type:`react`,getTitle:e=>Be(e)||`React Component`},{regex:/```json\s*\n([\s\S]*?)\n```/gi,type:`json`,getTitle:e=>`JSON Data`},{regex:/```python\s*\n([\s\S]*?)\n```/gi,type:`code`,language:`python`,getTitle:e=>Ve(e)||`Python Code`},{regex:/```(?:javascript|js)\s*\n([\s\S]*?)\n```/gi,type:`code`,language:`javascript`,getTitle:e=>He(e)||`JavaScript Code`},{regex:/```css\s*\n([\s\S]*?)\n```/gi,type:`code`,language:`css`,getTitle:e=>`CSS Styles`},{regex:/```(\w+)\s*\n([\s\S]*?)\n```/gi,type:`code`,getTitle:(e,t)=>`${t.toUpperCase()} Code`}],Le=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:e[1],title:e[2],content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:e[1],title:`${e[1].toUpperCase()} Artifact`,content:e[2].trim()})}];function Re(e){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}function ze(e){let t=e.match(/<title[^>]*>(.*?)<\/title>/i);if(t)return Re(t[1]).trim();let n=e.match(/<h1[^>]*>(.*?)<\/h1>/i);return n?Re(n[1]).trim():null}function Be(e){let t=e.match(/(?:function|const)\s+(\w+)/);if(t)return t[1];let n=e.match(/class\s+(\w+)/);return n?n[1]:null}function Ve(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function He(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function Ue(e,t){if(t===`html`)return/<[^>]+>/.test(e)&&e.trim().length>200;if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Z][^>]*>/.test(e)||/return\s*\(/.test(e);if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
2
- `).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return!1}function We(e){let t=[],n=e;for(let e of Le){let r;for(;(r=e.regex.exec(n))!==null;){let i=e.extract(r);if(Ue(i.content,i.type)){let e={id:`artifact-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,type:i.type,title:i.title,content:i.content,createdAt:Date.now(),updatedAt:Date.now()};t.push(e),n=n.replace(r[0],``)}}}for(let e of Ie){let r;for(e.regex.lastIndex=0;(r=e.regex.exec(n))!==null;){let i=r[1]||r[2],a=e.language||(r[1]&&r[2]?r[1]:void 0);if(Ue(i,e.type)){let o={id:`artifact-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,type:e.type,title:e.getTitle(i,a||`code`),content:i,language:a,createdAt:Date.now(),updatedAt:Date.now()};t.push(o),n=n.replace(r[0],``)}}}return{content:n.trim(),artifacts:t}}var Ge=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i})=>{let{t:a}=X(),o=e.role===`user`,l=e.role===`system`,{preferences:u}=H(),{user:d}=ye(),{setSystemMessage:f,getCurrentPersona:p}=q(),m=p(),[g,_]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(e.content),[C,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),[te,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(!1),F=(0,Q.useRef)(null),I=(0,Q.useRef)(t),ne=(0,Q.useRef)(!1),ie=async()=>{try{await navigator.clipboard.writeText(e.content),P(!0),setTimeout(()=>P(!1),2e3)}catch(e){console.error(`Failed to copy message:`,e)}},{thinkingContent:ae,parsedContent:R,artifacts:oe}=(0,Q.useMemo)(()=>{if(o||l||!e.content)return{thinkingContent:null,parsedContent:e.content,artifacts:e.artifacts||[]};let n=me(e.content),r=n.content;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,parsedContent:r,artifacts:e.artifacts};if(!t){let e=We(r);return{thinkingContent:n.thinking,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,parsedContent:r,artifacts:[]}},[e.content,e.artifacts,o,l,t]);(0,Q.useEffect)(()=>{let e=I.current&&!t;return I.current=t,e&&!ne.current&&!o&&!l&&R&&u.ttsSettings?.enabled&&u.ttsSettings?.autoPlay&&(ne.current=!0,(async()=>{M(!0);try{let e=await U.generateBase64({model:u.ttsSettings?.model||`tts-1`,input:R,voice:u.ttsSettings?.voice||`alloy`,speed:u.ttsSettings?.speed||1,response_format:`mp3`});if(e.success&&e.data?.audio){let t=`data:${e.data.mimeType};base64,${e.data.audio}`,n=new Audio(t);F.current=n,n.onended=()=>{M(!1),F.current=null},n.onerror=()=>{M(!1),F.current=null},await n.play()}}catch(e){console.error(`Auto-play TTS failed:`,e),M(!1)}})()),()=>{F.current&&(F.current.pause(),F.current=null)}},[t,o,l,R,u.ttsSettings]);let se=()=>l?a(`chatMessage.system`):o?u.showUsername&&d?.username?d.username:a(`chatMessage.you`):m?.name?m.name:e.model||a(`chatMessage.assistant`),z=()=>{_(!0),x(e.content)},B=async()=>{D(!0);try{f(b),_(!1),console.log(`✅ System message updated:`,b)}catch(e){console.error(`Failed to save system message:`,e)}finally{D(!1)}},ce=()=>{_(!1),x(e.content)},le=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ue=l&&e.content.length>100;return(0,$.jsxs)(`div`,{className:V(`flex transition-colors group my-2`,o?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:V(`flex gap-3 sm:gap-4`,o?`flex-row-reverse max-w-[85%] sm:max-w-[75%]`:l?`w-full`:`max-w-[85%] sm:max-w-[75%]`),children:[!l&&(0,$.jsx)(`div`,{className:V(`flex shrink-0 items-center justify-center shadow-sm overflow-hidden mt-1`,o?`h-8 w-8 rounded-full bg-primary-600 text-white`:m?.avatar?`h-8 w-8 rounded-full bg-white dark:bg-dark-100`:`h-8 px-2 rounded-full bg-white dark:bg-dark-100`),children:o?d?.avatar?(0,$.jsx)(`img`,{src:d.avatar,alt:d.username,className:`w-full h-full object-cover`}):(0,$.jsx)(re,{className:`h-4 w-4`}):m?.avatar?(0,$.jsx)(`img`,{src:m.avatar,alt:m.name||`Assistant`,className:`w-full h-full object-cover`}):(0,$.jsx)(`span`,{className:`libre-brand text-xs text-gray-700 dark:text-gray-200`,children:`Libre`})}),(0,$.jsxs)(`div`,{className:V(`flex-1 min-w-0 rounded-2xl sm:rounded-3xl p-4 sm:p-5`,o?`bg-primary-600/90 dark:bg-primary-700/90 text-white`:l?`bg-transparent p-2 py-3`:`bg-white/95 dark:bg-dark-100/95 backdrop-blur-md shadow-sm border border-gray-200/50 dark:border-dark-300/50`),children:[!l&&(0,$.jsxs)(`div`,{className:V(`flex items-center gap-3 mb-2`,o&&`flex-row-reverse`),children:[(0,$.jsx)(`span`,{className:V(`text-sm font-semibold`,o?`text-white/90`:`text-gray-900 dark:text-dark-800`),children:se()}),e.model&&!o&&m?.name&&(0,$.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-dark-600 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model}),(0,$.jsx)(`span`,{className:V(`text-xs`,o?`text-white/60`:`text-gray-400 dark:text-dark-500`),children:he(e.timestamp)}),!o&&!l&&!t&&R&&(0,$.jsx)(Fe,{text:R,size:`sm`,className:V(`transition-opacity`,te?`opacity-100 text-primary-600 dark:text-primary-400`:`opacity-0 group-hover:opacity-100`)}),!l&&!t&&(0,$.jsx)(`button`,{onClick:ie,className:`p-1 rounded hover:bg-gray-100 dark:hover:bg-dark-200 transition-opacity opacity-0 group-hover:opacity-100`,title:a(N?`chatMessage.copied`:`chatMessage.copyMessage`),children:N?(0,$.jsx)(c,{className:`h-3.5 w-3.5 text-green-500 dark:text-green-400`}):(0,$.jsx)(ee,{className:`h-3.5 w-3.5 text-gray-500 dark:text-gray-400`})}),!o&&!l&&!t&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`p-1 rounded hover:bg-gray-100 dark:hover:bg-dark-200 transition-opacity opacity-0 group-hover:opacity-100`,title:a(`chatMessage.regenerateResponse`),children:(0,$.jsx)(v,{className:`h-3.5 w-3.5 text-gray-500 dark:text-gray-400`})})]}),(0,$.jsxs)(`div`,{className:V(o?`text-white`:`text-gray-700 dark:text-dark-700`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-3 grid grid-cols-2 sm:grid-cols-3 gap-2 max-w-lg`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:(0,$.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>T(e)})},t))}),o?(0,$.jsx)(`p`,{className:`whitespace-pre-wrap leading-relaxed`,children:e.content}):l?(0,$.jsxs)(`div`,{className:`bg-gray-50/30 dark:bg-dark-50/30 rounded-md p-2 border border-gray-100/50 dark:border-dark-200/50 relative z-0`,children:[(0,$.jsxs)(`div`,{className:`text-xs font-medium mb-1 text-gray-500 dark:text-gray-400 flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(de,{className:`h-2.5 w-2.5 opacity-50`}),a(`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:g?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:B,disabled:E,className:`p-1 hover:bg-gray-100 dark:hover:bg-dark-200 rounded transition-colors disabled:opacity-50`,title:a(`chatMessage.saveChanges`),children:(0,$.jsx)(s,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:ce,disabled:E,className:`p-1 hover:bg-gray-100 dark:hover:bg-dark-200 rounded transition-colors disabled:opacity-50`,title:a(`chatMessage.cancelEditing`),children:(0,$.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:z,className:`p-1 hover:bg-gray-100 dark:hover:bg-dark-200 rounded transition-colors`,title:a(`chatMessage.editSystemMessage`),children:(0,$.jsx)(h,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),g?(0,$.jsx)(`textarea`,{value:b,onChange:e=>x(e.target.value),className:`w-full min-h-[100px] p-3 text-sm text-gray-900 dark:text-gray-100 bg-gray-50 dark:bg-dark-50 border border-gray-200 dark:border-dark-300 rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-primary-500 dark:focus:ring-primary-400 focus:border-transparent`,placeholder:a(`chatMessage.systemMessagePlaceholder`),disabled:E}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`whitespace-pre-wrap leading-relaxed text-xs text-gray-500 dark:text-gray-400`,children:O?e.content:le(e.content)}),ue&&(0,$.jsx)(`button`,{onClick:()=>k(!O),className:`mt-1 flex items-center gap-1 text-xs text-gray-400 dark:text-gray-500 hover:text-primary-600 dark:hover:text-primary-400 transition-colors`,children:O?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(S,{className:`h-3 w-3`}),a(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(w,{className:`h-3 w-3`}),a(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[ae&&(0,$.jsxs)(`div`,{className:`mb-3`,children:[(0,$.jsxs)(`button`,{onClick:()=>j(!A),className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 transition-colors`,children:[(0,$.jsx)(y,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`font-medium`,children:a(`chatMessage.thinking`)}),A?(0,$.jsx)(S,{className:`h-4 w-4`}):(0,$.jsx)(w,{className:`h-4 w-4`})]}),A&&(0,$.jsx)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-300`,children:(0,$.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-300 whitespace-pre-wrap leading-relaxed`,children:ae})})]}),(0,$.jsx)(Y,{content:R}),t&&(0,$.jsx)(`div`,{className:`inline-block w-2 h-5 bg-primary-500 animate-pulse ml-1 rounded-sm`})]}),!o&&!l&&oe.length>0&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(Ee,{artifacts:oe})}),!o&&!l&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Oe,{statistics:e.statistics})})]})]})]}),C&&(0,De.createPortal)((0,$.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm`,onClick:()=>T(null),children:[(0,$.jsx)(`button`,{className:`absolute top-6 right-6 p-3 bg-white/20 hover:bg-white/40 rounded-full text-white transition-all shadow-lg border border-white/30`,onClick:e=>{e.stopPropagation(),T(null)},children:(0,$.jsx)(L,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:C,alt:a(`chatMessage.fullSizeImage`),className:`max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Ke=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingMessageId:r,isLastAssistantMessage:i=!1,onRegenerate:a,onSelectBranch:o,className:s})=>{if(e.length===1){let o=e[0],c=t&&r===o.id;return(0,$.jsx)(Ge,{message:c&&n?{...o,content:n}:o,isStreaming:c,isLastAssistantMessage:i,onRegenerate:a,className:s})}return(0,$.jsxs)(`div`,{className:V(`relative py-1`,s),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 pb-2 text-[10px] text-gray-400 dark:text-gray-500`,children:[(0,$.jsx)(ne,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 px-4`,children:e.map((e,s)=>{let l=e.isActive!==!1,u=t&&r===e.id,d=u&&n?{...e,content:n}:e;return(0,$.jsxs)(`div`,{className:V(`relative rounded-lg overflow-hidden transition-all duration-200`,`border shadow-sm`,l||u?`border-primary-300 dark:border-primary-600 shadow-primary-100 dark:shadow-primary-900/20`:`border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,!l&&!u&&`cursor-pointer hover:shadow-md`),onClick:()=>!l&&!u&&o?.(e.id),children:[(0,$.jsxs)(`div`,{className:V(`flex items-center justify-between px-2.5 py-1 text-[11px]`,l||u?`bg-primary-50/80 dark:bg-primary-900/20 text-primary-600 dark:text-primary-400`:`bg-gray-50/80 dark:bg-dark-100/80 text-gray-500 dark:text-gray-500`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:s+1}),u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,$.jsx)(c,{className:`h-3 w-3`}),!l&&!u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,$.jsx)(`div`,{className:V(`bg-white dark:bg-dark-50`,!l&&!u&&`opacity-80`),children:(0,$.jsx)(Ge,{message:d,isStreaming:u,isLastAssistantMessage:i&&(l||u),onRegenerate:l&&!t?a:void 0,className:`!bg-transparent !p-3 !text-sm`})})]},e.id)})})]})},qe={web_search:C,web_fetch:A,exec:ae,browser:A,Read:z,Write:z,Edit:z,image:f,memory_search:N,memory_get:N,working:oe,thinking:oe,default:oe},Je={web_search:`Searching the web`,web_fetch:`Fetching page`,exec:`Running command`,browser:`Using browser`,Read:`Reading file`,Write:`Writing file`,Edit:`Editing file`,image:`Analyzing image`,memory_search:`Searching memory`,memory_get:`Reading memory`,cron:`Managing schedule`,message:`Sending message`,tts:`Generating speech`,nodes:`Checking devices`,sessions_spawn:`Spawning agent`,canvas:`Rendering canvas`,process:`Managing process`,working:`Using tools`,thinking:`Thinking`},Ye=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,$.jsx)(`div`,{className:V(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=qe[e.name]||qe.default,n=Je[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:V(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(`div`,{className:V(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})},Xe=({messages:e,streamingMessage:t,streamingMessageId:n,isStreaming:r=!1,toolActivities:i=[],className:a,onRegenerate:o,onSelectBranch:s})=>{let{t:c}=X(),l=(0,Q.useRef)(null),u=(0,Q.useRef)(),d=(0,Q.useRef)(null),f=(0,Q.useRef)(!1),[p,m]=(0,Q.useState)(!1),h=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),_=(0,Q.useCallback)((e=!1)=>{f.current&&!e||l.current?.scrollIntoView({behavior:`smooth`})},[]),v=(0,Q.useCallback)(()=>{let t=d.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i<100;f.current=!a,m(!a&&e.length>0)},[e.length]),y=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>y.current&&!f.current&&_(),y.current=e.length},[e.length,_]),(0,Q.useEffect)(()=>{r&&t&&!f.current&&requestAnimationFrame(()=>{let e=d.current;e&&(e.scrollTop=e.scrollHeight)})},[r,t]),(0,Q.useEffect)(()=>{let e=u.current;return()=>{e&&clearTimeout(e)}},[]),e.length===0&&!r)return(0,$.jsx)(`div`,{className:V(`flex-1 flex items-center justify-center p-4 sm:p-8`,a),children:(0,$.jsxs)(`div`,{className:`text-center text-gray-500 dark:text-dark-600 max-w-md`,children:[(0,$.jsx)(`div`,{className:`text-5xl sm:text-7xl mb-4 sm:mb-6 opacity-60`,children:`💬`}),(0,$.jsx)(`h3`,{className:`text-lg sm:text-xl font-semibold mb-2 sm:mb-3 text-gray-700 dark:text-dark-700`,children:c(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`text-sm leading-relaxed px-4`,children:c(`chatMessage.startConversationDescription`)})]})});let b=-1;for(let e=h.length-1;e>=0;e--)if(h[e].messages.some(e=>e.role===`assistant`)){b=e;break}return(0,$.jsxs)(`div`,{ref:d,onScroll:v,className:V(`relative flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`,a),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`,WebkitAppRegion:`no-drag`},children:[(0,$.jsxs)(`div`,{className:`max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full min-w-0`,children:[h.map((e,i)=>{let a=i===b,c=r&&e.messages.some(e=>e.id===n);if(e.messages.length===1){let s=e.messages[0],c=r&&s.id===n;return(0,$.jsx)(Ge,{message:c&&t?{...s,content:t}:s,isStreaming:c,isLastAssistantMessage:a,onRegenerate:a?o:void 0,className:i===0?`mt-3 sm:mt-4 md:mt-6`:``},s.id)}return(0,$.jsx)(Ke,{messages:e.messages,isStreaming:c,streamingMessage:t,streamingMessageId:n||void 0,isLastAssistantMessage:a,onRegenerate:a?o:void 0,onSelectBranch:s,className:i===0?`mt-3 sm:mt-4 md:mt-6`:``},e.id)}),r&&i.length>0&&(0,$.jsx)(Ye,{tools:i,className:`ml-10 sm:ml-12`}),(0,$.jsx)(`div`,{ref:l,className:`h-3 sm:h-4 md:h-6`})]}),p&&(0,$.jsxs)(`button`,{onClick:()=>{f.current=!1,l.current?.scrollIntoView({behavior:`smooth`}),m(!1)},className:V(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3 py-2 rounded-full`,`bg-white/95 dark:bg-dark-100/95`,`border border-gray-200/50 dark:border-dark-300/50`,`shadow-lg backdrop-blur-sm`,`text-gray-600 dark:text-dark-600`,`hover:bg-gray-50 dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-all duration-200`,`hover:shadow-xl hover:scale-105 active:scale-95`),title:c(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(g,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:c(`chatMessage.newMessages`)})]})]})};function Ze(e){let t=(e.match(/```/g)||[]).length,n=t%2==1,r=null;if(n){let t=e.lastIndexOf("```");if(t!==-1){let n=e.slice(t+3).match(/^(\w+)/);n&&(r=n[1])}}return{hasCodeBlocks:t>0,isInCodeBlock:n,language:r}}var Qe=Q.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,...o},s)=>{let{hasCodeBlocks:c,isInCodeBlock:l,language:u}=(0,Q.useMemo)(()=>Ze(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:s,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,className:V(`w-full resize-none transition-all duration-200`,l&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...o}),c&&(0,$.jsx)(`div`,{className:`absolute right-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:V(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,l&&`animate-pulse`),children:[(0,$.jsx)(fe,{className:`h-3 w-3`}),u&&(0,$.jsx)(`span`,{children:u}),!u&&l&&(0,$.jsx)(`span`,{children:`code`})]})})]})});Qe.displayName=`CodeAwareTextarea`;var $e=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:s}=X(),c=(0,Q.useRef)(null),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,h]=(0,Q.useState)([]),g=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await v(n):m.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){m.error(`Maximum ${n} images allowed`);return}if(r.size>10*1024*1024){m.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},v=async e=>{if(e.size>10*1024*1024){m.error(`File size must be less than 10MB`);return}f(!0);try{let t=await W.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),m.success(`Document "${e.name}" uploaded`)}else m.error(t.error||`Failed to upload document`)}catch(e){console.error(`Document upload error:`,e),m.error(`Failed to upload document`)}finally{f(!1)}},y=e=>{e.preventDefault(),a||u(!0)},b=e=>{e.preventDefault(),u(!1)},x=e=>{e.preventDefault(),u(!1),a||g(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},C=async e=>{try{let t=await W.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),m.success(`Document removed`)):m.error(t.error||`Failed to remove document`)}catch(e){console.error(`Error removing document:`,e),m.error(`Failed to remove document`)}},w=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},E=e.length>0||p.length>0;return(0,$.jsxs)(`div`,{className:V(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:V(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,l&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:y,onDragLeave:b,onDrop:x,onClick:()=>!a&&c.current?.click(),children:[(0,$.jsx)(`input`,{ref:c,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[d?(0,$.jsx)(T,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,$.jsx)(k,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[s(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:s(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:s(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),S(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),p.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(z,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,$.jsx)(ie,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:w(e.size)})]}),(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),C(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},et=({sessionId:e,className:t=``})=>{let[n,r]=(0,Q.useState)([]);if((0,Q.useEffect)(()=>{e&&(async()=>{try{let t=await W.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){console.error(`Failed to load documents:`,e)}})()},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{className:`
3
- inline-flex items-center space-x-1 px-2 py-1
4
- bg-blue-50 dark:bg-blue-900/20
5
- border border-blue-200 dark:border-blue-800
6
- rounded-md text-xs
7
- ${t}
8
- `,title:`${n.length} document(s) available for context - Total: ${(e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]})(i)}`,children:[(0,$.jsx)(a,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,$.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},tt=[{key:`none`,value:null},{key:`json`,value:`json`},{key:`list`,value:{type:`object`,properties:{items:{type:`array`,items:{type:`string`}}},required:[`items`]}},{key:`summary`,value:{type:`object`,properties:{title:{type:`string`},summary:{type:`string`},key_points:{type:`array`,items:{type:`string`}}},required:[`title`,`summary`,`key_points`]}},{key:`analysis`,value:{type:`object`,properties:{analysis:{type:`string`},pros:{type:`array`,items:{type:`string`}},cons:{type:`array`,items:{type:`string`}},recommendation:{type:`string`}},required:[`analysis`,`pros`,`cons`,`recommendation`]}},{key:`custom`,value:`custom`}],nt=({format:e,onFormatChange:t,className:n})=>{let{t:r}=X(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),c=()=>tt.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),l=()=>{let t=c();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},u=e=>{let n=c().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,$.jsxs)(`div`,{className:V(`space-y-3`,n),children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center`,children:[(0,$.jsx)(de,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,$.jsx)(we,{value:l().label,onChange:e=>u(e.target.value),options:c().map(e=>({value:e.label,label:e.label}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(xe,{value:o,onChange:e=>s(e.target.value),placeholder:`{
9
- "type": "object",
10
- "properties": {
11
- "field1": { "type": "string" },
12
- "field2": { "type": "number" }
13
- },
14
- "required": ["field1"]
15
- }`,rows:8,className:`font-mono text-sm`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Z,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){console.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(Z,{onClick:()=>{a(!1),s(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=l();return!e.value||e.value===`json`?null:(0,$.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,$.jsx)(le,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,$.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,$.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,$.jsx)(z,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},rt=({models:e,selectedModel:t,onModelChange:n,currentPersona:r,className:a,disabled:o=!1,compact:s=!1,showImageGen:u=!1,onModelsRefresh:d})=>{let{t:p}=X(),[h,g]=(0,Q.useState)(!1),[_,x]=(0,Q.useState)(``),[S,T]=(0,Q.useState)(`installed`),ee=(0,Q.useRef)(null),D=(0,Q.useRef)(null),k=Se(),{user:A,systemInfo:te}=ye(),N=A?.role===`admin`||(te?.allowUserModelPull??!0),[P,ne]=(0,Q.useState)(`all`),[ie,ae]=(0,Q.useState)(``),[R,oe]=(0,Q.useState)(`text-generation`),[se,z]=(0,Q.useState)(`downloads`),[le,ue]=(0,Q.useState)(``),[de,fe]=(0,Q.useState)(null),[pe,me]=(0,Q.useState)({}),[he,H]=(0,Q.useState)(null),[U,W]=(0,Q.useState)(null),[G,K]=(0,Q.useState)(null),[ve,q]=(0,Q.useState)(null),J=[`all`,`popular`,`chat`,`code`,`vision`,`embedding`,`cloud`],be=[{type:`personas`,label:p(`modelSelector.personas`),icon:(0,$.jsx)(re,{className:`h-4 w-4 text-purple-600 dark:text-purple-400`}),models:e.filter(e=>e.isPersona),color:`purple`},{type:`ollama`,label:p(`modelSelector.ollamaModels`),icon:(0,$.jsx)(F,{className:`h-4 w-4 text-green-600 dark:text-green-400`}),models:e.filter(e=>!e.isPersona&&!e.isPlugin&&!e.name.includes(`embed`)),color:`green`},{type:`plugins`,label:p(`modelSelector.pluginModels`),icon:(0,$.jsx)(B,{className:`h-4 w-4 text-green-600 dark:text-green-400`}),models:e.filter(e=>e.isPlugin),color:`green`}].filter(e=>e.models.length>0).map(e=>({...e,models:e.models.filter(e=>e.name.toLowerCase().includes(_.toLowerCase())||e.personaName&&e.personaName.toLowerCase().includes(_.toLowerCase())||e.pluginName&&e.pluginName.toLowerCase().includes(_.toLowerCase()))})).filter(e=>e.models.length>0),Y=e.find(e=>e.name===t||t.startsWith(`persona:`)&&e.name===t),{data:xe=[],isLoading:Ce,refetch:Z}=Te({queryKey:[`ollama-library-selector`,ie,P],queryFn:async()=>{let e=await ge.getLibraryModels({search:ie||void 0,sort:`popular`,category:P===`cloud`?`cloud`:void 0});return e.success&&e.data?e.data:[]},enabled:h&&S===`ollama`}),{data:we=[],isLoading:Ee,refetch:Oe}=Te({queryKey:[`hf-models-selector`,R,le,se],queryFn:async()=>{let e=await _e.getModels({task:R,search:le||void 0,sort:se,limit:30});return e.success&&e.data?e.data:[]},enabled:h&&S===`huggingface`}),ke=xe.filter(e=>{let t=!_||e.name.toLowerCase().includes(_.toLowerCase())||e.description.toLowerCase().includes(_.toLowerCase()),n=P===`all`||e.category===P;return t&&n}),Ae=(0,Q.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){H(e);try{let r=await _e.getGgufFiles(t,n);r.success&&r.data&&me(t=>({...t,[e]:r.data}))}catch(e){console.error(`Failed to load GGUF files:`,e)}finally{H(null)}}},[]),je=(0,Q.useCallback)(e=>{de===e?fe(null):(fe(e),pe[e]||Ae(e))},[de,pe,Ae]),Me=(0,Q.useCallback)((e,t)=>{if(!N){m.error(p(`modelSelector.pullRestricted`));return}if(!U){W(e),K({status:`starting`});try{let n=ge.pullModelStream(e,e=>{K(e)},()=>{K(null),W(null),q(null),m.success(`Downloaded ${t}`),d?.()},e=>{K(null),W(null),q(null),m.error(`Failed to download: ${e}`)});q(()=>n)}catch{K(null),W(null),m.error(`Failed to start download`)}}},[N,d,U,p]);(0,Q.useEffect)(()=>{let e=setTimeout(()=>{S===`huggingface`?ue(_):S===`ollama`&&ae(_)},300);return()=>clearTimeout(e)},[_,S]),(0,Q.useEffect)(()=>{let e=e=>{ee.current&&!ee.current.contains(e.target)&&(g(!1),x(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,Q.useEffect)(()=>{h&&D.current&&D.current.focus()},[h]);let Ne=async e=>{g(!1),x(``);try{let t=await ge.listRunningModels();if(t.success&&t.data){let n=t.data;n.length>0&&(n.some(t=>t.name===e||e.startsWith(`persona:`))||await ge.unloadAllModels())}}catch(e){console.warn(`Failed to unload models before switch:`,e)}n({target:{value:e}})},Pe=async e=>{if(!N){m.error(p(`modelSelector.pullRestricted`));return}if(!U){W(e),K({status:`starting`});try{let t=ge.pullModelStream(e,e=>{K(e)},()=>{K(null),W(null),q(null),m.success(`Downloaded ${e}`),d?.()},e=>{K(null),W(null),q(null),m.error(`Failed to download: ${e}`)});q(()=>t)}catch{K(null),W(null),m.error(`Failed to start download`)}}},Fe=()=>{ve&&(ve(),q(null),W(null),K(null),m.success(`Download cancelled`))},Ie=t=>e.some(e=>e.name===t||e.name.startsWith(t+`:`)),Le=e=>e.isPersona?(0,$.jsx)(re,{className:`h-4 w-4 text-purple-600 dark:text-purple-400`}):e.isPlugin?(0,$.jsx)(B,{className:`h-4 w-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(F,{className:`h-4 w-4 text-green-600 dark:text-green-400`}),Re=e=>e.isPersona?e.personaName||e.name:e.isPlugin?`${e.name}`:e.name,ze=e=>e.isPersona?`via ${e.model}`:e.isPlugin?`via ${e.pluginName}`:null,Be=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString();return(0,$.jsxs)(`div`,{className:V(`relative`,a),ref:ee,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>!o&&g(!h),disabled:o,className:V(s?`h-[44px] sm:h-[52px] px-3 flex items-center justify-between text-left w-full `:`w-full flex items-center justify-between gap-2 px-3 py-2 text-left `,`bg-gray-50 dark:bg-dark-200 border border-gray-200 dark:border-dark-300`,`rounded-lg text-sm hover:bg-gray-100 dark:hover:bg-dark-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500`,o?`opacity-50 cursor-not-allowed`:`cursor-pointer`),title:s?Y?Re(Y):p(`modelSelector.selectModel`):void 0,children:[(()=>{if(!Y)return s?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,$.jsx)(F,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium text-gray-400 dark:text-gray-500 truncate`,children:p(`modelSelector.selectModel`)})]}):p(`modelSelector.selectModel`);if(s){let e=Re(Y);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[Le(Y),(0,$.jsx)(`span`,{className:`text-xs font-medium text-gray-700 dark:text-gray-200 truncate`,children:e})]})}let e=Re(Y),t=ze(Y);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[Le(Y),(0,$.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e}),t&&(0,$.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:t})]}),Y.isPersona&&r&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto`,children:[(0,$.jsx)(y,{className:`h-3 w-3 text-purple-600 dark:text-purple-400`}),r.embedding_model&&(0,$.jsx)(ce,{className:`h-3 w-3 text-purple-500 dark:text-purple-300`})]})]})})(),(0,$.jsx)(w,{className:V(s?`h-3 w-3`:`h-4 w-4`,`text-gray-400 flex-shrink-0`,h&&`rotate-180`)})]}),h&&(0,De.createPortal)((0,$.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-start sm:items-center justify-center p-2 sm:p-4`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>g(!1)}),(0,$.jsxs)(`div`,{className:V(`relative bg-white dark:bg-dark-100 border border-gray-200 dark:border-dark-300 shadow-2xl`,`w-full max-w-md sm:w-[480px] sm:max-w-[90vw]`,`mt-2 sm:mt-0 rounded-xl`,`h-[85vh] sm:h-[600px] flex flex-col`),onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex-shrink-0`,children:[(0,$.jsx)(`div`,{className:`p-3 border-b border-gray-200 dark:border-dark-200`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(C,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400`}),(0,$.jsx)(`input`,{ref:D,type:`text`,placeholder:p(S===`installed`?`modelSelector.searchInstalled`:S===`ollama`?`modelSelector.searchOllama`:`modelSelector.searchHuggingFace`),value:_,onChange:e=>x(e.target.value),className:V(`w-full pl-10 pr-4 py-2.5 text-sm bg-gray-50 dark:bg-dark-200`,`border border-gray-200 dark:border-dark-300 rounded-lg`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`)})]})}),(0,$.jsxs)(`div`,{className:`flex border-b border-gray-200 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),T(`installed`)},className:V(`flex-1 px-4 py-2.5 text-sm font-medium transition-colors`,S===`installed`?`text-primary-600 dark:text-primary-400 border-b-2 border-primary-500`:`text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300`),children:[(0,$.jsx)(b,{className:`h-4 w-4 inline mr-1.5`}),p(`modelSelector.installed`)]}),(0,$.jsxs)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),T(`ollama`)},className:V(`flex-1 px-4 py-2.5 text-sm font-medium transition-colors`,S===`ollama`?`text-primary-600 dark:text-primary-400 border-b-2 border-primary-500`:`text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300`),children:[(0,$.jsx)(O,{className:`h-4 w-4 inline mr-1.5`}),`Ollama`]}),(0,$.jsxs)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),T(`huggingface`)},className:V(`flex-1 px-4 py-2.5 text-sm font-medium transition-colors`,S===`huggingface`?`text-primary-600 dark:text-primary-400 border-b-2 border-primary-500`:`text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300`),children:[(0,$.jsx)(B,{className:`h-4 w-4 inline mr-1.5`}),`HuggingFace`]})]})]}),S===`installed`&&(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400`,children:[be.length>0?be.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-dark-300 border-b border-gray-200 dark:border-dark-400 sticky top-0`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon,e.label,` (`,e.models.length,`)`]})}),e.models.map(e=>(0,$.jsx)(`div`,{onMouseDown:t=>{t.preventDefault(),Ne(e.name)},className:V(`px-3 py-3 cursor-pointer border-b border-gray-100 dark:border-dark-200 last:border-b-0`,`hover:bg-gray-50 dark:hover:bg-dark-200`,`bg-white dark:bg-dark-100 transition-colors`,t===e.name&&`bg-primary-50 dark:bg-primary-900/30`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[Le(e),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:Re(e)}),ze(e)&&(0,$.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:ze(e)})]}),t===e.name&&(0,$.jsx)(c,{className:`h-4 w-4 text-primary-600 dark:text-primary-400 flex-shrink-0`})]})},e.name))]},e.type)):(0,$.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,$.jsx)(M,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,$.jsx)(`p`,{className:`text-sm`,children:p(`models.noModelsFound`)})]}),u&&(0,$.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-dark-300`,children:[(0,$.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-dark-300`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(i,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),p(`modelSelector.actions`)]})}),(0,$.jsx)(`div`,{onMouseDown:e=>{e.preventDefault(),g(!1),k(`/gallery`)},className:`px-3 py-3 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-900/20 bg-white dark:bg-dark-100`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(f,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:p(`gallery.generate`)}),(0,$.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:p(`gallery.generateDescription`)})]})]})})]})]}),S===`ollama`&&(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0`,children:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:J.map(e=>(0,$.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),ne(e)},className:V(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,P===e?`bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-dark-300`),children:e.charAt(0).toUpperCase()+e.slice(1)},e))})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[!N&&(0,$.jsx)(`div`,{className:`mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300`,children:p(`modelSelector.pullRestricted`)}),Ce?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,$.jsx)(l,{className:`h-6 w-6 animate-spin text-gray-400`})}):ke.length===0?(0,$.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,$.jsx)(O,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,$.jsx)(`p`,{className:`text-sm`,children:p(`models.noModelsFound`)})]}):(0,$.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:ke.slice(0,50).map(e=>{let t=Ie(e.name),n=U===e.name;return(0,$.jsxs)(`div`,{className:V(`px-3 py-3 bg-white dark:bg-dark-100`,t&&`bg-green-50/50 dark:bg-green-900/10`),children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex-shrink-0`,children:(0,$.jsx)(O,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.name}),t&&(0,$.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`,children:p(`modelSelector.installed`)}),(e.category===`cloud`||e.tags?.includes(`cloud`))&&(0,$.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400 flex items-center gap-1`,children:[(0,$.jsx)(O,{className:`h-3 w-3`}),`Cloud`]})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 line-clamp-1 mt-0.5`,children:e.description}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[e.sizes.slice(0,3).map(e=>(0,$.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:e},e)),e.pulls&&(0,$.jsxs)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1`,children:[(0,$.jsx)(I,{className:`h-3 w-3`}),e.pulls]})]})]}),(0,$.jsx)(`div`,{className:`flex-shrink-0`,children:n?(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:G?.percent===void 0?`...`:`${G.percent}%`}),(0,$.jsx)(`button`,{onClick:Fe,className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,$.jsx)(L,{className:`h-4 w-4`})})]}):t?(0,$.jsx)(`button`,{onClick:()=>Ne(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-900/50`,children:p(`modelSelector.use`)}):N?(0,$.jsxs)(`button`,{onClick:()=>Pe(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50`,children:[(0,$.jsx)(I,{className:`h-3 w-3 inline mr-1`}),p(`modelSelector.pull`)]}):(0,$.jsx)(`span`,{className:`px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`,children:p(`modelSelector.adminOnlyPull`)})})]}),n&&G?.percent!==void 0&&(0,$.jsx)(`div`,{className:`mt-2 w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${G.percent}%`}})})]},e.name)})})]}),(0,$.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 flex items-center justify-between flex-shrink-0`,children:[(0,$.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 hover:underline flex items-center gap-1`,children:[(0,$.jsx)(j,{className:`h-3 w-3`}),p(`modelManager.huggingface.browseAllLink`)]}),(0,$.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),Z()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,$.jsx)(v,{className:V(`h-3.5 w-3.5 text-gray-400`,Ce&&`animate-spin`)})})]})]}),S===`huggingface`&&(0,$.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0 space-y-2`,children:(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(`select`,{value:R,onChange:e=>oe(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`flex-1 px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,children:[(0,$.jsx)(`option`,{value:`text-generation`,children:p(`modelManager.huggingface.taskTextGeneration`)}),(0,$.jsx)(`option`,{value:`text-to-speech`,children:p(`modelManager.huggingface.taskTextToSpeech`)}),(0,$.jsx)(`option`,{value:`text-to-image`,children:p(`modelManager.huggingface.taskTextToImage`)}),(0,$.jsx)(`option`,{value:`automatic-speech-recognition`,children:p(`modelManager.huggingface.taskSpeechRecognition`)})]}),(0,$.jsxs)(`select`,{value:se,onChange:e=>z(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,children:[(0,$.jsx)(`option`,{value:`downloads`,children:p(`modelManager.huggingface.sortDownloads`)}),(0,$.jsx)(`option`,{value:`likes`,children:p(`modelManager.huggingface.sortLikes`)}),(0,$.jsx)(`option`,{value:`lastModified`,children:p(`modelManager.huggingface.sortRecent`)})]})]})}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[!N&&(0,$.jsx)(`div`,{className:`mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300`,children:p(`modelSelector.pullRestricted`)}),Ee?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,$.jsx)(l,{className:`h-6 w-6 animate-spin text-gray-400`})}):we.length===0?(0,$.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,$.jsx)(B,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,$.jsx)(`p`,{className:`text-sm`,children:p(`modelManager.huggingface.noModelsFound`)})]}):(0,$.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:we.map(e=>{let t=de===e.id,n=pe[e.id]||[],r=he===e.id;return(0,$.jsxs)(`div`,{className:`bg-white dark:bg-dark-100`,children:[(0,$.jsx)(`div`,{className:`px-3 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-200`,onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),je(e.id)},children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 rounded-lg bg-yellow-100 dark:bg-yellow-900/30 flex-shrink-0`,children:(0,$.jsx)(B,{className:`h-4 w-4 text-yellow-600 dark:text-yellow-400`})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.id}),e.gated&&(0,$.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400`,children:`Gated`})]}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-0.5`,children:[`by `,e.author]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 text-xs text-gray-400 dark:text-gray-500`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(I,{className:`h-3 w-3`}),Be(e.downloads)]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(E,{className:`h-3 w-3`}),Be(e.likes)]}),e.pipeline_tag&&(0,$.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200`,children:e.pipeline_tag})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,$.jsx)(`a`,{href:`https://huggingface.co/${e.id}`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,$.jsx)(j,{className:`h-4 w-4 text-gray-400`})}),(0,$.jsx)(w,{className:V(`h-4 w-4 text-gray-400 transition-transform`,t&&`rotate-180`)})]})]})}),t&&(0,$.jsx)(`div`,{className:`px-3 pb-3 pt-1 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-200`,children:r?(0,$.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,$.jsx)(l,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,$.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:p(`modelManager.huggingface.checkingGguf`)})]}):n.length===0?(0,$.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:p(`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:p(`modelManager.huggingface.ggufFilesCount`,{count:n.length})}),n.map(e=>{let t=U===e.ollamaCommand;return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-white dark:bg-dark-100 border border-gray-200 dark:border-dark-300`,children:[(0,$.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 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:G?.percent===void 0?`...`:`${G.percent}%`}),(0,$.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),Fe()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,$.jsx)(L,{className:`h-4 w-4`})})]}):N?(0,$.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),Me(e.ollamaCommand,e.filename)},disabled:!!U,className:V(`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)(I,{className:`h-3 w-3 inline mr-1`}),p(`models.pull`)]}):(0,$.jsx)(`span`,{className:`px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`,children:p(`modelSelector.adminOnlyPull`)})]},e.filename)}),U?.startsWith(`hf.co/`)&&U.includes(e.id)&&G?.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:`${G.percent}%`}})})]})})]},e.id)})})]}),(0,$.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 flex items-center justify-between flex-shrink-0`,children:[(0,$.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 hover:underline flex items-center gap-1`,children:[(0,$.jsx)(j,{className:`h-3 w-3`}),p(`modelManager.huggingface.browseAllLink`)]}),(0,$.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),Oe()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,$.jsx)(v,{className:V(`h-3.5 w-3.5 text-gray-400`,Ee&&`animate-spin`)})})]})]})]})]}),document.body),(0,$.jsx)(`select`,{value:t,onChange:n,className:`sr-only`,tabIndex:-1,children:e.map(e=>(0,$.jsx)(`option`,{value:e.name,children:Re(e)},e.name))})]})},it=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r}=X(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)([]),[l,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(!1),{isGenerating:b,setBackgroundImage:x}=H(),{currentSession:S,models:C}=q(),w=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{(async()=>{try{let e=await ve.getPlugins();y(!!(e.success&&e.data&&e.data.length>0))}catch{y(!1)}})()},[]);let T=t=>{t.preventDefault(),!(!a.trim()||b)&&(e(a.trim(),s.length>0?s:void 0,l||void 0),o(``),c([]))},E=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),T(e))},ee=()=>{t()};(0,Q.useEffect)(()=>{let e=w.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[a]),(0,Q.useEffect)(()=>{(async()=>{if(S?.personaId)try{let e=await G.getPersona(S.personaId);if(e.success&&e.data)g(e.data);else{console.warn(`Persona ${S.personaId} not found, clearing reference`),g(null);let{setCurrentSession:e}=q.getState();e({...S,personaId:void 0})}}catch(e){if(console.error(`Failed to load current persona:`,e),g(null),S){let{setCurrentSession:e}=q.getState();e({...S,personaId:void 0})}}else g(null)})()},[S?.personaId]);let D=async e=>{let t=e.target.value;if(S)try{if(t.startsWith(`persona:`)){let e=t.replace(`persona:`,``),n=await G.getPersona(e);if(!n.success||!n.data){d.error(`Failed to load persona details`);return}let i=n.data,a=await K.updateSession(S.id,{personaId:e,model:t});if(a.success&&a.data){let{sessions:e}=q.getState(),t=e.map(e=>e.id===S.id?a.data:e);q.setState({sessions:t,currentSession:a.data}),i.background&&x(i.background),d.success(r(`chat.persona.applied`))}}else{let e=await K.updateSession(S.id,{model:t,personaId:void 0});if(e.success&&e.data){let{sessions:t}=q.getState(),n=t.map(t=>t.id===S.id?e.data:t);q.setState({sessions:n,currentSession:e.data}),x(null),d.success(r(`chat.model.updated`))}}}catch(e){console.error(`Failed to update session:`,e),d.error(`Failed to update session`)}},O=s.length>0||l!==null;return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{className:`max-w-5xl mx-auto px-3 sm:px-4 md:px-6 w-full pointer-events-auto`,children:[p&&(0,$.jsxs)(`div`,{className:`mb-2 p-3 rounded-2xl bg-white/95 dark:bg-dark-100/95 backdrop-blur-md border border-gray-200/50 dark:border-dark-300/50 shadow-lg`,children:[(0,$.jsx)($e,{images:s,onImagesChange:c,maxImages:5,sessionId:S?.id,disabled:n}),(0,$.jsx)(nt,{format:l,onFormatChange:f})]}),(0,$.jsxs)(`div`,{className:`py-2 sm:py-3`,children:[(0,$.jsx)(`form`,{onSubmit:T,children:(0,$.jsxs)(`div`,{className:V(`flex items-center gap-2 p-2 sm:p-3 rounded-2xl sm:rounded-3xl border transition-all duration-300 ease-out shadow-lg`,`bg-white/95 dark:bg-dark-100/95 backdrop-blur-md`,`border-gray-200/50 dark:border-dark-300/50`,`hover:border-gray-300/70 dark:hover:border-dark-400/70`,`focus-within:border-primary-400/70 dark:focus-within:border-primary-500/70`,`focus-within:shadow-xl`),children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(!p),className:V(`h-8 w-8 sm:h-9 sm:w-9 !p-0 rounded-full flex-shrink-0`,`hover:bg-gray-100 dark:hover:bg-dark-200/80`,`transition-all duration-200 touch-manipulation`,`hover:scale-105 active:scale-95`,O&&`text-primary-600 dark:text-primary-400`,p&&`bg-gray-100 dark:bg-dark-200/80`),title:r(`chat.input.attachments`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`0`},children:O?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(_,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -right-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):p?(0,$.jsx)(u,{className:`h-4 w-4`}):(0,$.jsx)(i,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(Qe,{ref:w,value:a,onChange:e=>o(e.target.value),onKeyDown:E,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 text-base sm:text-sm leading-none touch-manipulation`,rows:1,style:{boxShadow:`none !important`,border:`none !important`,outline:`none !important`,padding:`0 !important`,margin:`0 !important`,lineHeight:`1.2 !important`,verticalAlign:`middle`}})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 flex-shrink-0`,children:[S&&C.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(rt,{models:C,selectedModel:S.personaId?`persona:${S.personaId}`:S.model,onModelChange:D,currentPersona:h,className:`min-w-[160px] max-w-[240px] border-0 bg-gray-100/80 dark:bg-dark-100/80 rounded-xl text-sm hover:bg-gray-200/80 dark:hover:bg-dark-200/60 transition-colors duration-200`,compact:!0,showImageGen:v})}),b?(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:ee,className:V(`h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-all duration-200 touch-manipulation`,`hover:scale-105 active:scale-95`),title:r(`chat.input.stopGeneration`),children:(0,$.jsx)(te,{className:`h-4 w-4`})}):(0,$.jsx)(Z,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!a.trim()||n,className:V(`h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-gray-400 dark:text-dark-500`,`disabled:opacity-40 disabled:hover:bg-transparent disabled:cursor-not-allowed`,`transition-all duration-200 touch-manipulation`,a.trim()&&!n&&[`bg-primary-500 dark:bg-primary-600`,`text-white dark:text-white`,`hover:bg-primary-600 dark:hover:bg-primary-500`,`shadow-md hover:shadow-lg`,`hover:scale-105 active:scale-95`]),title:r(`chat.input.sendMessage`),children:(0,$.jsx)(ue,{className:`h-4 w-4`})})]})]})}),S&&C.length>0&&(0,$.jsx)(`div`,{className:`sm:hidden mt-3`,children:(0,$.jsx)(rt,{models:C,selectedModel:S.personaId?`persona:${S.personaId}`:S.model,onModelChange:D,currentPersona:h,className:`w-full rounded-xl bg-gray-100/80 dark:bg-dark-100/80 border-0 transition-colors duration-200`,compact:!0,showImageGen:v})}),(0,$.jsxs)(`div`,{className:`mt-2 flex items-center justify-center gap-2 text-xs text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(et,{sessionId:S?.id}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsxs)(`a`,{href:`https://librewebui.org`,target:`_blank`,rel:`noopener noreferrer`,className:`libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 transition-colors`,style:{fontSize:`1.1em`,lineHeight:1},children:[`Libre `,(0,$.jsx)(`span`,{style:{fontSize:`0.85em`},children:`WebUI`})]}),` `,(0,$.jsxs)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500`,style:{fontSize:`0.55rem`},children:[`v`,`0.10.0`]}),` `,(0,$.jsx)(`span`,{className:`text-gray-300 dark:text-gray-600 opacity-50`,children:`•`}),` `,(0,$.jsx)(`span`,{className:`text-gray-400 dark:text-gray-500`,style:{fontSize:`0.55rem`},children:r(`chat.footer.disclaimer`)}),O&&(0,$.jsxs)(`span`,{className:`ml-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,s.length>0&&r(`chat.footer.images`,{count:s.length}),s.length>0&&l&&` • `,l&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},at=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)({top:0,left:0});(0,Q.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect();s({top:e.bottom+8,left:e.left})}},[r]);let c=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),l=()=>e.avatar?e.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(e.name)}&background=6366f1&color=fff&size=64`;return(0,$.jsxs)(`div`,{className:V(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:V(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,$.jsx)(ce,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(w,{className:V(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,De.createPortal)((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,$.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,$.jsxs)(`div`,{className:V(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,$.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,$.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 right-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,$.jsx)(L,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,$.jsxs)(`div`,{className:`absolute top-2 left-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,$.jsx)(y,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,$.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`})}),(0,$.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,$.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,$.jsx)(x,{className:`h-3 w-3`}),e.model]}),e.description&&(0,$.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,$.jsxs)(`div`,{className:`mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,$.jsx)(p,{className:`h-2.5 w-2.5 text-gray-400`}),(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(B,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,$.jsx)(y,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},ot=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=X(),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)(!1),c=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){m.error(`File ${o.name} is not an image`);continue}if(o.size>10*1024*1024){m.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&m.error(`Only ${a} more images can be added`)},l=e=>{e.preventDefault(),s(!0)},u=e=>{e.preventDefault(),s(!1)},d=e=>{e.preventDefault(),s(!1),c(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},h=e.length<n;return(0,$.jsxs)(`div`,{className:V(`space-y-3`,r),children:[h&&(0,$.jsxs)(`div`,{className:V(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:l,onDragLeave:u,onDrop:d,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>c(e.target.files),className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(k,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,$.jsx)(L,{className:`h-4 w-4`})})})]},t))}),h&&e.length>0&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(f,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},st=e=>{let[t,n]=(0,Q.useState)(``),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)([]),{addMessage:l,updateMessage:u,updateMessageWithStatistics:d,updateSessionTitle:f,setGeneratingTitleForSession:p}=q(),{setIsGenerating:h,preferences:g}=H(),_=(0,Q.useRef)(null),v=(0,Q.useRef)(null),y=(0,Q.useRef)(``),b=(0,Q.useRef)(0),x=(0,Q.useRef)();return(0,Q.useEffect)(()=>()=>{J.offMessage(`user_message`),J.offMessage(`assistant_chunk`),J.offMessage(`assistant_complete`),J.offMessage(`tool_status`),J.offMessage(`error`)},[e]),(0,Q.useEffect)(()=>{if(!e){J.offMessage(`user_message`),J.offMessage(`assistant_chunk`),J.offMessage(`assistant_complete`),J.offMessage(`tool_status`),J.offMessage(`error`);return}return J.onMessage(`user_message`,()=>{}),J.onMessage(`assistant_chunk`,t=>{let r=t,i=r.messageId||_.current;i&&(y.current=r.total,n(r.total),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>{u(e,i,y.current),b.current=Date.now()},r.done?0:200))}),J.onMessage(`tool_status`,e=>{let t=e;c(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),J.onMessage(`assistant_complete`,t=>{let r=t;console.log(`Hook: Received assistant_complete for session:`,e,`messageId:`,r.messageId,`with statistics:`,!!r.statistics),o(!1),n(``),h(!1),c([]);let i=r.messageId||_.current;r&&i&&d(e,i,y.current||r.content,r.statistics);let a=H.getState().preferences.titleSettings,s=q.getState().currentSession,l=v.current;console.log(`Auto-title check:`,{firstMessage:l,autoTitle:a?.autoTitle,taskModel:a?.taskModel,sessionTitle:s?.title}),l&&a?.autoTitle&&a?.taskModel&&s?.title===`New Chat`&&(console.log(`Triggering auto-title generation...`),p(e),K.generateTitle(e,a.taskModel,l).then(t=>{console.log(`Title generation response:`,t),t.success&&t.data?.title&&f(e,t.data.title)}).catch(e=>{console.error(`Failed to generate title:`,e)}).finally(()=>{p(null)}),v.current=null),_.current=null,y.current=``,x.current&&clearTimeout(x.current),b.current=0}),J.onMessage(`error`,e=>{let t=e;if(o(!1),n(``),h(!1),_.current=null,t.code===`SESSION_NOT_FOUND`){console.warn(`Session not found, redirecting to create new session...`),m.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}m.error(t.error)}),o(!1),n(``),_.current=null,()=>{x.current&&clearTimeout(x.current)}},[e,u,d,h,f,p]),{sendMessage:(0,Q.useCallback)(async(t,r,a)=>{if(!(!e||!t.trim()&&(!r||r.length===0)))try{h(!0),o(!0),n(``),x.current&&clearTimeout(x.current),b.current=Date.now();let s=q.getState().currentSession,c=s?.isPrivate===!0,u=s?.messages?.some(e=>e.role===`user`);!c&&!u&&s?.title===`New Chat`&&(v.current=t.trim()),l(e,{role:`user`,content:t.trim(),images:r});let d=pe();_.current=d,i(d),l(e,{role:`assistant`,content:``,id:d}),J.isConnected||await J.connect();let f=c?s?.messages?.filter(e=>e.role!==`system`&&e.id!==d).map(e=>({role:e.role,content:e.content,images:e.images})):void 0;J.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:r,format:a,options:g.generationOptions,assistantMessageId:d,isPrivate:c,model:c?s?.model:void 0,messageHistory:f}})}catch(e){console.error(`Failed to send message:`,e),o(!1),n(``),i(null),h(!1),_.current=null,m.error(`Failed to send message`)}},[e,l,h,g.generationOptions]),stopGeneration:(0,Q.useCallback)(()=>{o(!1),n(``),i(null),h(!1),_.current=null},[h]),regenerateLastMessage:(0,Q.useCallback)(async()=>{let t=q.getState().currentSession;if(!t||!e)return;let r=t.messages,a=-1,s=-1;for(let e=r.length-1;e>=0;e--)if(r[e].role===`assistant`){s=e;break}if(s>0){for(let e=s-1;e>=0;e--)if(r[e].role===`user`){a=e;break}}if(a===-1||s===-1){m.error(`No message to regenerate`);return}let c=r[a],u=r[s];try{h(!0),o(!0),n(``),x.current&&clearTimeout(x.current),b.current=Date.now();let t=pe();_.current=t,i(t),l(e,{role:`assistant`,content:``,id:t,parentId:u.parentId||u.id,branchIndex:u.siblingCount||1,isActive:!0}),J.isConnected||await J.connect(),J.send({type:`chat_stream`,data:{sessionId:e,content:c.content,images:c.images,options:g.generationOptions,assistantMessageId:t,regenerate:!0,originalMessageId:u.id}})}catch(e){console.error(`Failed to regenerate message:`,e),o(!1),n(``),h(!1),_.current=null,m.error(`Failed to regenerate message`)}},[e,h,l,g.generationOptions]),selectBranch:(0,Q.useCallback)(async t=>{let n=q.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){m.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await K.switchMessageBranch(e,t,a);if(r.success&&r.data){let r=n.messages.map(e=>e.id===i||e.parentId===i?{...e,isActive:e.id===t}:e),o={...n,messages:r,updatedAt:Date.now()};q.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),m.success(`Switched to variant ${a+1}`)}else m.error(r.error||`Failed to select branch`)}catch(e){console.error(`Failed to select branch:`,e),m.error(`Failed to select branch`)}},[e]),isStreaming:a,streamingMessage:t,streamingMessageId:r,toolActivities:s}},ct=(e,t)=>{let n=new Date().getHours(),r=e?`, ${e}`:``;return n>=5&&n<12?{greeting:`${t?t(`chat.greeting.morning`):`Good morning`}${r}`,timeSuffix:`today`}:n>=12&&n<17?{greeting:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${r}`,timeSuffix:`today`}:n>=17&&n<21?{greeting:`${t?t(`chat.greeting.evening`):`Good evening`}${r}`,timeSuffix:`tonight`}:{greeting:`${t?t(`chat.greeting.night`):`Good night`}${r}`,timeSuffix:`tonight`}},lt=()=>{let{t:e}=X(),{sessionId:t}=be(),n=Se(),r=Ce(),{currentSession:a,sessions:o,models:s,selectedModel:c,setSelectedModel:l,createSession:d,setCurrentSession:f,loadSessions:p,getCurrentPersona:m}=q(),{user:h}=ye(),{sendMessage:g,stopGeneration:v,regenerateLastMessage:y,selectBranch:b,isStreaming:x,streamingMessage:S,streamingMessageId:C,toolActivities:w}=st(a?.id||``),T=m(),{greeting:E,timeSuffix:ee}=(0,Q.useMemo)(()=>ct(h?.username,e),[h?.username,e]),[D,O]=(0,Q.useState)(``),[k,A]=(0,Q.useState)([]),[j,te]=(0,Q.useState)(!1),M=(0,Q.useRef)(null),[N,P]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{o.length===0&&p()},[p,o.length]),(0,Q.useEffect)(()=>{(async()=>{try{let e=await ve.getPlugins();P(!!(e.success&&e.data&&e.data.length>0))}catch{P(!1)}})()},[]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!a?.isPrivate&&o.length!==0)if(t){let e=o.find(e=>e.id===t);e&&e.id!==a?.id?f(e):e||(console.warn(`Session ${t} not found for current user, redirecting...`),o.length>0?n(`/c/${o[0].id}`,{replace:!0}):n(`/`,{replace:!0}))}else !t&&o.length>0&&r.pathname===`/`&&n(`/c/${o[0].id}`,{replace:!0})})()},[t,o,f,n,a?.id,a?.isPrivate,r.pathname]),(0,Q.useEffect)(()=>{if(a?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{g(t.content,t.images)},100)}catch(e){console.error(`Failed to parse pending message:`,e)}}}},[a?.id,g]),(0,Q.useEffect)(()=>{let e=M.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[D]);let F=async e=>{if(e.preventDefault(),!D.trim()||!c)return;let t={content:D.trim(),images:k.length>0?k:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(t)),O(``),A([]);let r=await d(c);r&&n(`/c/${r.id}`,{replace:!0})},I=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),F(e))},L=async e=>{let t=e.target.value;l(t)},ne=(e,t,n)=>{a&&g(e,t,n)};if(!a){let t=k.length>0;return(0,$.jsxs)(`div`,{className:`h-full flex-1 flex flex-col items-center justify-center p-4 sm:p-8 relative`,children:[(0,$.jsxs)(`button`,{onClick:()=>{if(!c&&s.length===0)return;let t=Date.now();f({id:`private-${t}`,title:e(`chat.session.private`),model:c||s[0]?.name||``,messages:[],createdAt:t,updatedAt:t,isPrivate:!0})},disabled:!c&&s.length===0,className:`absolute top-4 right-4 flex items-center gap-2 px-3 py-1.5 rounded-full border border-gray-300 dark:border-dark-400 bg-transparent hover:bg-gray-100 dark:hover:bg-dark-200 text-gray-500 dark:text-gray-400 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed`,title:e(`chat.session.privateTooltip`),children:[(0,$.jsx)(se,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-sm`,children:e(`chat.session.private`)})]}),(0,$.jsxs)(`div`,{className:`w-full max-w-2xl mx-auto flex flex-col items-center justify-center`,children:[(0,$.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-medium text-gray-800 dark:text-gray-100 mb-2 text-center`,style:{fontWeight:400},children:E}),(0,$.jsx)(`p`,{className:`text-base sm:text-lg text-gray-500 dark:text-gray-400 mb-8 text-center`,children:e(ee===`today`?`chat.welcome.helpToday`:`chat.welcome.helpTonight`)}),s.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[j&&(0,$.jsx)(`div`,{className:`mb-4 p-4 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-2xl`,children:(0,$.jsx)(ot,{images:k,onImagesChange:A,maxImages:5})}),(0,$.jsx)(`form`,{onSubmit:F,children:(0,$.jsxs)(`div`,{className:V(`flex items-center gap-2 p-2 sm:p-3 rounded-2xl sm:rounded-3xl border transition-all duration-200`,`bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300`,`hover:border-gray-300 dark:hover:border-dark-400`,`focus-within:border-primary-400 dark:focus-within:border-primary-500 focus-within:bg-white dark:focus-within:bg-dark-50`,`shadow-sm hover:shadow-md focus-within:shadow-lg`),children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>te(!j),className:V(`h-8 w-8 sm:h-9 sm:w-9 !p-0 rounded-full flex-shrink-0`,`hover:bg-gray-200 dark:hover:bg-dark-200 transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,j&&`bg-gray-200 dark:bg-dark-200`),title:e(`chat.input.attachImages`),style:{display:`flex`,alignItems:`center`,justifyContent:`center`,padding:`0`},children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(_,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -right-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):j?(0,$.jsx)(u,{className:`h-4 w-4`}):(0,$.jsx)(i,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(Qe,{ref:M,value:D,onChange:e=>O(e.target.value),onKeyDown:I,placeholder:e(`chat.input.messagePlaceholder`),className:`!border-0 !bg-transparent !shadow-none !p-0 !m-0 !rounded-none !focus:ring-0 !focus:border-0 !focus:shadow-none !focus:bg-transparent min-h-[32px] sm:min-h-[36px] max-h-[120px] resize-none scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400 focus:outline-none placeholder:text-gray-500 dark:placeholder:text-dark-500 text-base sm:text-sm leading-none touch-manipulation`,rows:1,style:{boxShadow:`none !important`,border:`none !important`,outline:`none !important`,padding:`0 !important`,margin:`0 !important`,lineHeight:`1.2 !important`,verticalAlign:`middle`}})}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(rt,{models:s,selectedModel:c,onModelChange:L,className:`min-w-[140px] max-w-[200px] border-0 bg-gray-100 dark:bg-dark-100 rounded-xl text-sm`,compact:!0,showImageGen:N})}),(0,$.jsx)(Z,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!D.trim()||!c,className:V(`h-8 w-8 sm:h-9 sm:w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`hover:bg-primary-100 dark:hover:bg-primary-900/30 text-primary-600 dark:text-primary-400`,`disabled:text-gray-400 dark:disabled:text-dark-500 disabled:hover:bg-transparent`,`transition-all duration-150 touch-manipulation`,D.trim()&&c&&`hover:scale-105 active:scale-95`),title:e(`chat.input.sendMessage`),children:(0,$.jsx)(ue,{className:`h-4 w-4`})})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(rt,{models:s,selectedModel:c,onModelChange:L,className:`w-full rounded-xl bg-gray-100 dark:bg-dark-100 border-0`,compact:!0,showImageGen:N})}),(0,$.jsxs)(`div`,{className:`mt-4 text-center`,children:[(0,$.jsxs)(`a`,{href:`https://librewebui.org`,target:`_blank`,rel:`noopener noreferrer`,className:`libre-brand underline hover:text-primary-600 dark:hover:text-primary-400 transition-colors text-gray-500 dark:text-gray-400`,style:{fontSize:`0.75rem`,lineHeight:1},children:[`Libre `,(0,$.jsx)(`span`,{style:{fontSize:`0.6rem`},children:`WebUI`})]}),` `,(0,$.jsxs)(`span`,{className:`text-gray-400 dark:text-gray-500`,style:{fontSize:`0.55rem`},children:[`v`,`0.10.0`]}),` `,(0,$.jsx)(`span`,{className:`text-gray-300 dark:text-gray-600 opacity-50`,children:`•`}),` `,(0,$.jsx)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:e(`chat.footer.disclaimer`)})]})]}):(0,$.jsx)(`div`,{className:`w-full max-w-md`,children:(0,$.jsxs)(`div`,{className:`p-6 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-xl`,children:[(0,$.jsx)(`p`,{className:`text-sm text-gray-700 dark:text-dark-700 mb-4`,children:e(`chat.model.noModelsDescription`)}),(0,$.jsx)(`code`,{className:`block text-xs bg-gray-100 dark:bg-dark-200 p-3 rounded-lg font-mono text-gray-800 dark:text-dark-600`,children:e(`chat.model.pullCommand`)})]})})]})]})}return(0,$.jsxs)(`div`,{className:`flex flex-col h-full relative`,style:T?.background?{backgroundImage:`url(${T.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[T?.background&&(0,$.jsx)(`div`,{className:`absolute inset-0 bg-white/80 dark:bg-black/80 backdrop-blur-sm`}),(0,$.jsxs)(`div`,{className:`flex flex-col h-full relative z-10`,children:[a?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-gray-200 dark:border-dark-300 bg-gray-50/80 dark:bg-dark-100/80 backdrop-blur-sm`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(se,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:e(`chat.session.privateMode`)}),(0,$.jsxs)(`span`,{className:`text-xs text-gray-500 dark:text-gray-500`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),T&&!a?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-white/50 dark:bg-dark-100/50 backdrop-blur-sm`,children:(0,$.jsx)(at,{persona:T,onClear:()=>{if(a){let{sessions:e}=q.getState(),t={...a,model:T.model,personaId:void 0},n=e.map(e=>e.id===a.id?t:e);q.setState({sessions:n,currentSession:t})}}})}),(0,$.jsx)(Xe,{messages:a.messages,streamingMessage:S,streamingMessageId:C,isStreaming:x,toolActivities:w,onRegenerate:y,onSelectBranch:b,className:`flex-1`}),(0,$.jsx)(it,{onSendMessage:ne,onStopGeneration:v,disabled:!a})]})]})};export{lt as ChatPage,lt as default};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{m as t,p as n}from"./markdown-vendor-DLzJCMRQ.js";import{n as r}from"./react-vendor-Dh6nfvM2.js";import{A as i,It as a,J as o,U as s,Y as c,d as l,gt as u,mt as d,n as f,v as p,xt as m,z as h}from"./ui-vendor-ClcVY3m-.js";import{o as g}from"./appStore-BpzQfKOd.js";import{s as _}from"./api-MQ7bONaU.js";import{C as v,S as y,b,m as x,p as S,x as C,y as w}from"../assets/index-cOuIFv6G.js";var T=class extends C{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,f=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:y(t,n.data),hasPreviousPage:v(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function E(e,t){return w(e,T,t)}var D=e(t(),1),O=e(r(),1),k=n(),A=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:i}=x();return(0,D.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[t]),(0,O.createPortal)((0,k.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,k.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,k.jsxs)(`div`,{className:`relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4`,onClick:e=>e.stopPropagation(),children:[(0,k.jsx)(`button`,{onClick:t,className:g(`absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10`,`p-2 rounded-full`,`bg-white/10 hover:bg-white/20`,`transition-colors`),children:(0,k.jsx)(f,{className:`h-6 w-6 text-white`})}),(0,k.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,k.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,k.jsxs)(`div`,{className:g(`w-full lg:w-80 flex-shrink-0`,`bg-white dark:bg-dark-100`,`rounded-xl p-4 lg:p-5`,`overflow-y-auto max-h-[25vh] lg:max-h-[90vh]`),children:[(0,k.jsxs)(`div`,{className:`mb-4`,children:[(0,k.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:i(`gallery.prompt`)}),(0,k.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,k.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,k.jsx)(u,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,k.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.model`),`:`]}),(0,k.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,k.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,k.jsx)(h,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,k.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.size`),`:`]}),(0,k.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,k.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,k.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 text-xs font-bold`,children:`Q`}),(0,k.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.quality`),`:`]}),(0,k.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,k.jsx)(m,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,k.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.created`),`:`]}),(0,k.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:(e=>new Date(e).toLocaleString(void 0,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}))(e.createdAt)})]})]}),(0,k.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,k.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:g(`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white font-medium text-sm`,`transition-colors`),children:[(0,k.jsx)(d,{className:`h-4 w-4`}),i(`gallery.download`)]}),n&&(0,k.jsx)(`button`,{onClick:()=>n(e.id),className:g(`p-2.5 rounded-lg`,`bg-gray-100 dark:bg-dark-200`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`text-gray-600 dark:text-gray-300`,`hover:text-red-600 dark:hover:text-red-400`,`transition-colors`),title:`Delete image`,children:(0,k.jsx)(l,{className:`h-4 w-4`})})]})]})]})]}),document.body)},j=({onImageCountChange:e})=>{let{t}=x(),n=b(),[r,i]=(0,D.useState)(null),[o,u]=(0,D.useState)(null),{data:f,fetchNextPage:p,hasNextPage:m,isFetchingNextPage:h,isLoading:v}=E({queryKey:[`image-gallery`],queryFn:async({pageParam:e})=>{let n=await _.getGallery({limit:20,offset:e});if(!n.success||!n.data)throw Error(t(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.images.length,0);return n<e.total?n:void 0}}),y=(0,D.useMemo)(()=>f?.pages.flatMap(e=>e.images)??[],[f]),S=f?.pages[0]?.total??0,C=h;(0,D.useEffect)(()=>{e?.(S)},[S,e]);let w=()=>{p()},T=async(e,s)=>{if(s.stopPropagation(),!o){u(e);try{(await _.deleteGalleryImage(e)).success?(await n.invalidateQueries({queryKey:[`image-gallery`]}),a.success(t(`imageGallery.deleteSuccess`)),r?.id===e&&i(null)):a.error(t(`imageGallery.deleteFailed`))}catch(e){console.error(`Failed to delete image:`,e),a.error(t(`imageGallery.deleteFailed`))}finally{u(null)}}},O=(e,t)=>{t.stopPropagation();let n=document.createElement(`a`);n.href=e.imageData,n.download=`generated-${e.id}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n)},j=e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`});return v?(0,k.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,k.jsx)(s,{className:`h-8 w-8 animate-spin text-gray-400 dark:text-gray-500`})}):y.length===0?(0,k.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-center`,children:[(0,k.jsx)(c,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),(0,k.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-gray-100 mb-2`,children:t(`imageGallery.noImages`)}),(0,k.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400 max-w-sm`,children:t(`imageGallery.noImagesHint`)})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:g(`columns-1 sm:columns-2 lg:columns-3 xl:columns-4`,`gap-4 space-y-4`),children:y.map(e=>(0,k.jsxs)(`div`,{className:g(`break-inside-avoid group relative cursor-pointer`,`rounded-xl overflow-hidden`,`bg-gray-100 dark:bg-dark-200`,`border border-gray-200 dark:border-dark-300`,`hover:border-gray-300 dark:hover:border-dark-400`,`transition-all duration-200`,`hover:shadow-lg dark:hover:shadow-dark-400/20`),onClick:()=>i(e),children:[(0,k.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`w-full h-auto object-cover`,loading:`lazy`}),(0,k.jsxs)(`div`,{className:g(`absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent`,`opacity-0 group-hover:opacity-100 transition-opacity duration-200`,`flex flex-col justify-end p-3`),children:[(0,k.jsx)(`p`,{className:`text-white text-sm line-clamp-2 mb-2`,children:e.prompt}),(0,k.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,k.jsx)(`span`,{className:`text-white/70 text-xs`,children:j(e.createdAt)}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,k.jsx)(`button`,{onClick:t=>O(e,t),className:g(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-white/30`,`transition-colors`),title:t(`imageGallery.download`),children:(0,k.jsx)(d,{className:`h-4 w-4 text-white`})}),(0,k.jsx)(`button`,{onClick:t=>T(e.id,t),disabled:o===e.id,className:g(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-red-500/80`,`transition-colors`,o===e.id&&`opacity-50 cursor-not-allowed`),title:t(`imageGallery.delete`),children:o===e.id?(0,k.jsx)(s,{className:`h-4 w-4 text-white animate-spin`}):(0,k.jsx)(l,{className:`h-4 w-4 text-white`})})]})]})]})]},e.id))}),m&&(0,k.jsx)(`div`,{className:`flex justify-center mt-8`,children:(0,k.jsx)(`button`,{onClick:w,disabled:C,className:g(`px-6 py-2.5 rounded-xl font-medium`,`bg-gray-100 dark:bg-dark-200`,`hover:bg-gray-200 dark:hover:bg-dark-300`,`text-gray-700 dark:text-gray-200`,`border border-gray-200 dark:border-dark-300`,`transition-colors`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:C?(0,k.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(s,{className:`h-4 w-4 animate-spin`}),t(`common.loading`)]}):t(`imageGallery.loadMore`,{current:y.length,total:S})})}),r&&(0,k.jsx)(A,{image:r,onClose:()=>i(null),onDelete:e=>{T(e,{stopPropagation:()=>{}})},onDownload:e=>{O(e,{stopPropagation:()=>{}})}})]})},M=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=x(),[i,c]=(0,D.useState)([]),[l,u]=(0,D.useState)(``),[m,h]=(0,D.useState)(``),[v,y]=(0,D.useState)(``),[b,C]=(0,D.useState)(`1024x1024`),[w,T]=(0,D.useState)(`standard`),[E,A]=(0,D.useState)(!1),[j,M]=(0,D.useState)(null),[N,P]=(0,D.useState)([`512x512`,`768x768`,`1024x1024`]),[F,I]=(0,D.useState)([`standard`,`high`]),[L,R]=(0,D.useState)(null);(0,D.useEffect)(()=>{e&&(async()=>{try{let e=await _.getPlugins();if(e.success&&e.data&&(c(e.data),e.data.length>0)){let t=e.data[0];u(t.id),t.models.length>0&&h(t.models[0]),t.config?.sizes&&(P(t.config.sizes),C(t.config.default_size||t.config.sizes[0]||`1024x1024`)),t.config?.qualities&&(I(t.config.qualities),T(t.config.default_quality||t.config.qualities[0]||`standard`)),R(t.config?.max_prompt_length??null)}}catch(e){console.error(`Failed to load image generation plugins:`,e)}})()},[e]);let[z,B]=(0,D.useState)(l);if(l!==z){B(l);let e=i.find(e=>e.id===l);e&&(e.models.length>0&&!e.models.includes(m)&&h(e.models[0]),e.config?.sizes&&(P(e.config.sizes),e.config.sizes.includes(b)||C(e.config.default_size||e.config.sizes[0])),e.config?.qualities&&(I(e.config.qualities),e.config.qualities.includes(w)||T(e.config.default_quality||e.config.qualities[0])),R(e.config?.max_prompt_length??null))}let V=async()=>{if(!m||!v.trim()){a.error(r(`imageGeneration.enterPrompt`));return}if(L&&v.length>L){a.error(r(`imageGeneration.promptTooLong`,{max:L.toLocaleString()}));return}A(!0),M(null);try{let e=await _.generate({model:m,prompt:v.trim(),size:b,quality:w});if(e.success&&e.data?.images&&e.data.images.length>0){let i=e.data.images[0],o=null;i.b64_json?o=`data:image/png;base64,${i.b64_json}`:i.url&&(o=i.url),o&&(a.success(r(`imageGeneration.success`)),n?(n(o,v.trim(),m),y(``),M(null),t()):M(o))}else a.error(r(`imageGeneration.failed`))}catch(e){console.error(`Image generation failed:`,e);let t=e instanceof Error?e.message:r(`imageGeneration.failed`);a.error(t)}finally{A(!1)}},H=()=>{if(!j)return;let e=document.createElement(`a`);e.href=j,e.download=`generated-image-${Date.now()}.png`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e)return null;let U=i.find(e=>e.id===l);return(0,O.createPortal)((0,k.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-4`,children:[(0,k.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,k.jsxs)(`div`,{className:g(`relative bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`,`rounded-2xl shadow-2xl`,`w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col`),onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-300`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}),(0,k.jsx)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:r(`imageGeneration.title`)})]}),(0,k.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,children:(0,k.jsx)(f,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,k.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:i.length===0?(0,k.jsxs)(`div`,{className:`text-center py-8`,children:[(0,k.jsx)(o,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,k.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,k.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,k.jsx)(`select`,{value:l,onChange:e=>u(e.target.value),className:g(`w-full px-3 py-2 rounded-lg text-sm`,`bg-gray-50 dark:bg-dark-200`,`border border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:i.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,k.jsx)(`select`,{value:m,onChange:e=>h(e.target.value),className:g(`w-full px-3 py-2 rounded-lg text-sm`,`bg-gray-50 dark:bg-dark-200`,`border border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:U?.models.map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.size`)}),(0,k.jsx)(`select`,{value:b,onChange:e=>C(e.target.value),className:g(`w-full px-3 py-2 rounded-lg text-sm`,`bg-gray-50 dark:bg-dark-200`,`border border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:N.map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,k.jsx)(`select`,{value:w,onChange:e=>T(e.target.value),className:g(`w-full px-3 py-2 rounded-lg text-sm`,`bg-gray-50 dark:bg-dark-200`,`border border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:F.map(e=>(0,k.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,k.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:g(`w-full px-3 py-2 rounded-lg text-sm resize-none`,`bg-gray-50 dark:bg-dark-200`,`border border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,L&&v.length>L&&`border-red-500 dark:border-red-500`)}),L&&(0,k.jsxs)(`div`,{className:g(`text-xs mt-1 text-right`,v.length>L?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[v.length.toLocaleString(),` /`,` `,L.toLocaleString()]})]}),j&&(0,k.jsxs)(`div`,{className:`relative rounded-xl overflow-hidden border border-gray-200 dark:border-dark-300`,children:[(0,k.jsx)(`img`,{src:j,alt:`Generated`,className:`w-full h-auto`}),(0,k.jsx)(`button`,{onClick:H,className:g(`absolute bottom-3 right-3 p-2 rounded-lg`,`bg-white/90 dark:bg-dark-100/90`,`hover:bg-white dark:hover:bg-dark-100`,`border border-gray-200 dark:border-dark-300`,`transition-colors`),title:r(`imageGallery.download`),children:(0,k.jsx)(d,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]})}),i.length>0&&(0,k.jsx)(`div`,{className:`p-4 border-t border-gray-200 dark:border-dark-300`,children:(0,k.jsx)(S,{onClick:V,disabled:E||!v.trim()||!m,className:g(`w-full py-2.5 rounded-xl font-medium`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white`,`disabled:opacity-50 disabled:cursor-not-allowed`,`transition-colors`),children:E?(0,k.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,k.jsx)(s,{className:`h-4 w-4 animate-spin`}),r(`imageGeneration.generating`)]}):(0,k.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,k.jsx)(p,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},N=()=>{let{t:e}=x(),[t,n]=(0,D.useState)(null),[r,a]=(0,D.useState)(!1),[o,s]=(0,D.useState)(0),c=(0,D.useCallback)(()=>{s(e=>e+1)},[]);return(0,k.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,k.jsxs)(`div`,{className:`max-w-7xl mx-auto p-6`,children:[(0,k.jsxs)(`div`,{className:`text-center max-w-md mx-auto mb-8`,children:[(0,k.jsx)(`h2`,{className:`libre-brand text-4xl sm:text-5xl font-normal text-gray-900 dark:text-dark-800 mb-3`,style:{fontWeight:300,letterSpacing:`0.01em`},children:e(`sidebar.navigation.imagine`)}),(0,k.jsxs)(`p`,{className:`text-gray-600 dark:text-dark-600 leading-relaxed`,children:[e(`gallery.subtitle`),t!==null&&t>0&&(0,k.jsxs)(`span`,{className:`text-gray-400 dark:text-gray-500`,children:[` `,`· `,e(`gallery.imageCount`,{count:t})]})]}),(0,k.jsxs)(S,{onClick:()=>a(!0),className:g(`mt-4 px-6 py-2.5 rounded-xl font-medium`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white`,`transition-colors`),children:[(0,k.jsx)(i,{className:`h-4 w-4 mr-2`}),e(`gallery.generate`)]})]}),(0,k.jsx)(j,{onImageCountChange:n},o)]}),(0,k.jsx)(M,{isOpen:r,onClose:()=>a(!1),onImageGenerated:c})]})};export{N as GalleryPage,N as default};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{m as t,p as n}from"./markdown-vendor-DLzJCMRQ.js";import{n as r}from"./react-vendor-Dh6nfvM2.js";import{C as ee,Et as i,H as te,Lt as a,O as o,Pt as ne,Q as s,R as re,St as c,T as ie,Tt as l,W as ae,X as oe,Z as se,_t as ce,at as le,bt as ue,d as de,f as fe,ft as pe,gt as me,it as he,lt as ge,mt as u,n as d,q as _e,t as ve,x as ye,xt as be}from"./ui-vendor-ClcVY3m-.js";import{o as f}from"./appStore-BpzQfKOd.js";import{c as p,o as xe}from"./api-MQ7bONaU.js";import{n as Se}from"./authStore-Cn_WS6Kb.js";import{b as Ce,m as we,p as m,v as h}from"../assets/index-cOuIFv6G.js";var g=e(t(),1),_=e(r(),1),v=n(),Te=()=>{let{t:e}=we(),{user:t,systemInfo:n}=Se(),r=t?.role===`admin`||(n?.allowUserModelPull??!0),Te=Ce(),[y,Ee]=(0,g.useState)(`all`),[b,De]=(0,g.useState)(``),[Oe,x]=(0,g.useState)(``),[S,C]=(0,g.useState)(!1),[w,T]=(0,g.useState)(null),[ke,E]=(0,g.useState)(null),[D,Ae]=(0,g.useState)(null),[je,Me]=(0,g.useState)(``),[Ne,Pe]=(0,g.useState)(!1),[Fe,Ie]=(0,g.useState)(!1),[Le,O]=(0,g.useState)(!1),[k,Re]=(0,g.useState)(``),[A,ze]=(0,g.useState)(``),[Be,Ve]=(0,g.useState)(!1),[He,j]=(0,g.useState)(!1),[M,Ue]=(0,g.useState)(``),[N,We]=(0,g.useState)(``),[Ge,Ke]=(0,g.useState)(!1),[qe,Je]=(0,g.useState)(!1),[P,Ye]=(0,g.useState)(``),[F,Xe]=(0,g.useState)(``),[I,Ze]=(0,g.useState)(null),[Qe,$e]=(0,g.useState)(!1),[et,tt]=(0,g.useState)(``),[nt,rt]=(0,g.useState)(``),[L,it]=(0,g.useState)(`text-generation`),[R,at]=(0,g.useState)(`downloads`),[ot,st]=(0,g.useState)(null),[ct,lt]=(0,g.useState)({}),[ut,dt]=(0,g.useState)(null),[z,B]=(0,g.useState)(null),[V,H]=(0,g.useState)(null),[ft,U]=(0,g.useState)(null),[W,pt]=(0,g.useState)(new Set([`pull`,`local`])),G=e=>{pt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},{data:K,isLoading:mt,refetch:q}=h({queryKey:[`ollama-state`],queryFn:async()=>{let[e,t,n,r]=await Promise.all([p.getModels(),p.listRunningModels(),p.getVersion(),p.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}}}),J=K?.models??[],Y=K?.runningModels??[],ht=K?.ollamaVersion??null,gt=K?.isHealthy??null,X=(0,g.useCallback)(async()=>{await q()},[q]),{data:Z=[],isLoading:_t}=h({queryKey:[`ollama-library`],queryFn:async()=>{let e=await p.getLibraryModels();return e.success&&e.data?e.data:[]}}),{data:vt=[],isLoading:yt}=h({queryKey:[`ollama-library`,`cloud`],queryFn:async()=>{let e=await p.getLibraryModels({category:`cloud`});return e.success&&e.data?e.data:[]},enabled:y===`cloud`}),bt=()=>Te.invalidateQueries({queryKey:[`ollama-library`]});(0,g.useEffect)(()=>{let e=setTimeout(()=>{rt(et)},300);return()=>clearTimeout(e)},[et]);let xt=W.has(`huggingface`),{data:Q=[],isLoading:St}=h({queryKey:[`hf-models`,L,nt,R],queryFn:async()=>{let e=await xe.getModels({task:L,search:nt||void 0,sort:R,limit:30});return e.success&&e.data?e.data:[]},enabled:xt}),Ct=()=>Te.invalidateQueries({queryKey:[`hf-models`,L,nt,R]}),wt=(0,g.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){dt(e);try{let r=await xe.getGgufFiles(t,n);r.success&&r.data&&lt(t=>({...t,[e]:r.data}))}catch(e){console.error(`Failed to load GGUF files:`,e)}finally{dt(null)}}},[]),Tt=(0,g.useCallback)(e=>{ot===e?st(null):(st(e),ct[e]||wt(e))},[ot,ct,wt]),Et=(0,g.useCallback)((t,n)=>{if(!r){a.error(e(`modelManager.pull.restricted`));return}if(!z){B(t),H({status:`starting`});try{let e=p.pullModelStream(t,e=>{H(e)},()=>{H(null),B(null),U(null),a.success(`Downloaded ${n}`),X()},e=>{H(null),B(null),U(null),a.error(`Failed to download: ${e}`)});U(()=>e)}catch{H(null),B(null),a.error(`Failed to start download`)}}},[r,z,X,e]),Dt=(0,g.useCallback)(()=>{ft&&(ft(),U(null),B(null),H(null))},[ft]),Ot=async t=>{if(!r){a.error(e(`modelManager.pull.restricted`));return}let n=t||Oe.trim();if(!n){a.error(e(`modelManager.pull.enterName`));return}t&&x(t),C(!0),T({status:`starting`});try{let t=p.pullModelStream(n,e=>{T(e)},()=>{T(null),C(!1),E(null),a.success(e(`modelManager.pull.success`,{name:n})),x(``),X()},t=>{T(null),C(!1),E(null),a.error(e(`modelManager.pull.failed`)+`: `+t)});E(()=>t)}catch(t){let n=t instanceof Error?t.message:String(t);a.error(e(`modelManager.pull.failed`)+`: `+n),T(null),C(!1),E(null)}},kt=()=>{ke&&(ke(),E(null),C(!1),T(null),a.success(e(`modelManager.pull.cancelled`)))},At=async t=>{if(confirm(e(`modelManager.local.deleteConfirm`,{name:t})))try{await p.deleteModel(t),a.success(e(`modelManager.local.deleteSuccess`,{name:t})),await X()}catch(t){let n=t instanceof Error?t.message:String(t);a.error(e(`modelManager.local.deleteFailed`)+`: `+n)}},jt=async t=>{Ie(!0),Me(t),Pe(!0);try{let n=await p.showModel(t,!0);n.success&&n.data?Ae(n.data):a.error(e(`modelManager.modals.details.noDetails`))}catch(t){let n=t instanceof Error?t.message:String(t);a.error(e(`modelManager.modals.details.noDetails`)+`: `+n)}finally{Ie(!1)}},Mt=async()=>{if(!k.trim()||!A.trim()){a.error(e(`modelManager.modals.copy.enterBoth`));return}Ve(!0);try{await p.copyModel(k.trim(),A.trim()),a.success(e(`modelManager.modals.copy.success`,{name:A})),O(!1),Re(``),ze(``),await X()}catch(t){let n=t instanceof Error?t.message:String(t);a.error(e(`modelManager.modals.copy.failed`)+`: `+n)}finally{Ve(!1)}},Nt=async()=>{if(!M.trim()||!N.trim()){a.error(e(`modelManager.modals.create.enterBoth`));return}Ke(!0);try{await p.createModel({model:M.trim(),modelfile:N.trim()}),a.success(e(`modelManager.modals.create.success`,{name:M})),j(!1),Ue(``),We(``),await X()}catch(t){let n=t instanceof Error?t.message:String(t);a.error(e(`modelManager.modals.create.failed`)+`: `+n)}finally{Ke(!1)}},Pt=async()=>{if(!P.trim()||!F.trim()){a.error(e(`modelManager.modals.embeddings.enterBoth`));return}$e(!0),Ze(null);try{let t=await p.generateEmbeddings({model:P.trim(),input:F.trim()});if(t.success&&t.data){let n=t.data.embeddings?.[0]||[];Ze(n),a.success(e(`modelManager.modals.embeddings.success`,{count:n.length}))}}catch(t){let n=t instanceof Error?t.message:String(t);a.error(e(`modelManager.modals.embeddings.failed`)+`: `+n)}finally{$e(!1)}},$=e=>{let t=e/(1024*1024*1024);return t>=1?`${t.toFixed(2)} GB`:`${(e/(1024*1024)).toFixed(1)} MB`},Ft=e=>Array.isArray(Y)&&Y.some(t=>t.name===e),It=()=>J.reduce((e,t)=>e+t.size,0),Lt=()=>Y.reduce((e,t)=>e+(t.size_vram||0),0),Rt=e=>J.some(t=>t.name===e||t.name.startsWith(e+`:`)),zt=(y===`cloud`?vt:Z).filter(e=>{let t=y===`all`||y===`cloud`||e.category===y,n=!b||e.name.toLowerCase().includes(b.toLowerCase())||e.description.toLowerCase().includes(b.toLowerCase());return t&&n}),Bt=[`all`,...new Set([...Z.map(e=>e.category),`cloud`])],Vt=(0,g.useMemo)(()=>Z.length>0?Z.slice(0,10).map(e=>({name:e.name,category:e.category,size:e.sizes?.[0]||``})):[{name:`deepseek-r1`,category:`reasoning`,size:`7B`},{name:`llama3.2`,category:`general`,size:`3B`},{name:`gemma3`,category:`general`,size:`4B`},{name:`qwen2.5`,category:`general`,size:`7B`},{name:`mistral`,category:`general`,size:`7B`},{name:`codellama`,category:`coding`,size:`7B`},{name:`nomic-embed-text`,category:`embedding`,size:`137M`},{name:`llava`,category:`vision`,size:`7B`},{name:`phi3`,category:`general`,size:`3.8B`},{name:`gemma2`,category:`general`,size:`9B`}],[Z]);return mt?(0,v.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,v.jsxs)(`div`,{className:`flex items-center gap-3 text-gray-600 dark:text-dark-600`,children:[(0,v.jsx)(o,{className:`h-5 w-5 animate-spin`}),e(`modelManager.loading`)]})}):(0,v.jsxs)(`div`,{className:`space-y-4`,children:[(0,v.jsx)(`div`,{className:f(`rounded-xl p-4 border`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:(0,v.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(`div`,{className:f(`w-2.5 h-2.5 rounded-full`,gt?`bg-green-500`:`bg-red-500`)}),(0,v.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(gt?`modelManager.systemStatus.online`:`modelManager.systemStatus.offline`)})]}),ht&&(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,v.jsx)(ee,{className:`h-4 w-4`}),(0,v.jsxs)(`span`,{children:[`v`,ht]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,v.jsx)(s,{className:`h-4 w-4`}),(0,v.jsxs)(`span`,{children:[J.length,` `,J.length===1?e(`modelManager.systemStatus.models`):e(`modelManager.systemStatus.models_plural`)]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,v.jsx)(ae,{className:`h-4 w-4`}),(0,v.jsx)(`span`,{children:$(It())})]}),Y.length>0&&(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-green-600 dark:text-green-400`,children:[(0,v.jsx)(ne,{className:`h-4 w-4`}),(0,v.jsxs)(`span`,{children:[Y.length,` `,e(`modelManager.systemStatus.running`),` (`,$(Lt()),` `,e(`modelManager.systemStatus.vram`),`)`]})]})]}),(0,v.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,v.jsxs)(m,{onClick:X,variant:`outline`,size:`sm`,className:f(`gap-1.5`,``,``),children:[(0,v.jsx)(o,{className:`h-3.5 w-3.5`}),e(`common.refresh`)]})})]})}),(0,v.jsxs)(`div`,{className:f(`rounded-xl border overflow-hidden`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`button`,{onClick:()=>G(`pull`),className:f(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:f(`p-2 rounded-lg`,`bg-primary-100 dark:bg-primary-900/30`),children:(0,v.jsx)(u,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`modelManager.sections.pull`)})]}),W.has(`pull`)?(0,v.jsx)(c,{className:`h-5 w-5 text-gray-500`}):(0,v.jsx)(l,{className:`h-5 w-5 text-gray-500`})]}),W.has(`pull`)&&(0,v.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,v.jsxs)(`div`,{className:`flex gap-2`,children:[(0,v.jsxs)(`div`,{className:`relative flex-1`,children:[(0,v.jsx)(ie,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,v.jsx)(`input`,{type:`text`,value:Oe,onChange:e=>x(e.target.value),placeholder:e(`modelManager.pull.placeholder`),className:f(`w-full pl-10 pr-4 py-2.5 rounded-lg border 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-none focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`),disabled:S||!r,onKeyDown:e=>e.key===`Enter`&&!S&&r&&Ot()})]}),S?(0,v.jsxs)(m,{onClick:kt,variant:`outline`,className:f(`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,v.jsx)(d,{className:`h-4 w-4`}),e(`modelManager.pull.cancel`)]}):(0,v.jsxs)(m,{onClick:()=>Ot(),disabled:!Oe.trim()||!r,className:f(`px-4 py-2.5 gap-2`,``),children:[(0,v.jsx)(u,{className:`h-4 w-4`}),e(`modelManager.pull.button`)]})]}),S&&w&&(0,v.jsxs)(`div`,{className:f(`p-4 rounded-lg border`,`bg-gray-50 dark:bg-dark-200`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,v.jsx)(`span`,{className:`text-sm font-medium text-gray-800 dark:text-dark-700`,children:w.status===`starting`?e(`modelManager.progress.starting`):w.status.startsWith(`pulling`)?`${e(`modelManager.progress.pullingLayer`)} ${w.status.replace(`pulling `,``)}`:w.status.startsWith(`verifying sha256`)?e(`modelManager.progress.verifyingDigest`):w.status===`writing manifest`?e(`modelManager.progress.writing`):w.status===`removing any unused layers`?e(`modelManager.progress.cleaning`):w.status}),w.percent!==void 0&&(0,v.jsxs)(`span`,{className:`text-sm font-mono text-gray-600 dark:text-dark-600`,children:[w.percent,`%`]})]}),w.percent!==void 0&&(0,v.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-400 rounded-full h-2 overflow-hidden`,children:(0,v.jsx)(`div`,{className:f(`h-2 rounded-full transition-all duration-300`,`bg-primary-500 dark:bg-primary-400`),style:{width:`${w.percent}%`}})}),w.total&&w.completed&&(0,v.jsxs)(`div`,{className:`mt-2 text-xs text-gray-600 dark:text-dark-600`,children:[$(w.completed),` /`,` `,$(w.total)]})]}),!r&&(0,v.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-300`,children:e(`modelManager.pull.restricted`)}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`p`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 mb-2`,children:e(`modelManager.pull.popular`)}),(0,v.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Vt.map(e=>(0,v.jsxs)(`button`,{onClick:()=>x(e.name),disabled:S||!r,className:f(`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,v.jsx)(`span`,{className:`ml-1 text-gray-400 dark:text-gray-500`,children:e.size})]},e.name))})]}),(0,v.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,className:f(`inline-flex items-center gap-1.5 text-xs`,`text-primary-600 dark:text-primary-400`,`hover:underline`),children:[(0,v.jsx)(pe,{className:`h-3 w-3`}),e(`modelManager.pull.browseAll`)]})]})]}),(0,v.jsxs)(`div`,{className:f(`rounded-xl border overflow-hidden`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`button`,{onClick:()=>G(`library`),className:f(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:f(`p-2 rounded-lg`,`bg-blue-100 dark:bg-blue-900/30`),children:(0,v.jsx)(ue,{className:`h-5 w-5 text-blue-600 dark:text-blue-400`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`modelManager.sections.library`)}),(0,v.jsxs)(`span`,{className:f(`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:[Z.length,` `,e(`modelManager.library.available`)]})]}),W.has(`library`)?(0,v.jsx)(c,{className:`h-5 w-5 text-gray-500`}):(0,v.jsx)(l,{className:`h-5 w-5 text-gray-500`})]}),W.has(`library`)&&(0,v.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,v.jsxs)(`div`,{className:`relative flex-1`,children:[(0,v.jsx)(ie,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,v.jsx)(`input`,{type:`text`,value:b,onChange:e=>De(e.target.value),placeholder:e(`modelManager.library.search`),className:f(`w-full pl-10 pr-4 py-2 rounded-lg border 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-none focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`)})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(le,{className:`h-4 w-4 text-gray-400`}),(0,v.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Bt.map(e=>(0,v.jsx)(`button`,{onClick:()=>Ee(e),className:f(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,y===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))})]})]}),_t||yt?(0,v.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,v.jsx)(o,{className:`h-5 w-5 animate-spin text-gray-400`})}):zt.length===0?(0,v.jsx)(`div`,{className:`text-center py-8 text-gray-500`,children:e(`modelManager.library.noResults`)}):(0,v.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:zt.map(t=>{let n=Rt(t.name);return(0,v.jsxs)(`div`,{className:f(`p-4 rounded-lg border transition-all`,`bg-gray-50 dark:bg-dark-50`,n?`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,v.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-2`,children:[(0,v.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:t.name}),n&&(0,v.jsxs)(`span`,{className:f(`flex items-center gap-1 px-1.5 py-0.5 rounded text-xs`,`bg-green-100 dark:bg-green-900/30`,`text-green-700 dark:text-green-400`),children:[(0,v.jsx)(i,{className:`h-3 w-3`}),e(`modelManager.library.installed`)]})]}),(0,v.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-dark-600 mb-3 line-clamp-2`,children:t.description}),(0,v.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[t.sizes.slice(0,4).map(e=>(0,v.jsx)(`span`,{className:f(`px-1.5 py-0.5 rounded text-xs`,`bg-gray-200 dark:bg-dark-300`,`text-gray-600 dark:text-gray-400`),children:e},e)),t.sizes.length>4&&(0,v.jsx)(`span`,{className:`text-xs text-gray-400`,children:e(`modelManager.library.more`,{count:t.sizes.length-4})})]}),(0,v.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-gray-500`,children:[t.pulls&&(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(u,{className:`h-3 w-3`}),t.pulls]}),(0,v.jsx)(`span`,{className:f(`px-1.5 py-0.5 rounded capitalize`,t.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:t.category})]}),(0,v.jsxs)(m,{onClick:()=>{W.has(`pull`)||G(`pull`),Ot(t.name)},variant:`outline`,size:`sm`,disabled:S||!r,className:f(`gap-1 text-xs`,``,``),children:[(0,v.jsx)(u,{className:`h-3 w-3`}),e(`modelManager.pull.button`)]})]})]},t.name)})}),(0,v.jsx)(`div`,{className:`flex justify-center`,children:(0,v.jsxs)(m,{onClick:bt,variant:`outline`,size:`sm`,disabled:_t,className:f(`gap-1.5`,``,``),children:[(0,v.jsx)(o,{className:f(`h-3.5 w-3.5`,_t&&`animate-spin`)}),e(`modelManager.library.refresh`)]})})]})]}),(0,v.jsxs)(`div`,{className:f(`rounded-xl border overflow-hidden`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`button`,{onClick:()=>G(`huggingface`),className:f(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:f(`p-2 rounded-lg`,`bg-yellow-100 dark:bg-yellow-900/30`),children:(0,v.jsx)(ve,{className:`h-5 w-5 text-yellow-600 dark:text-yellow-400`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`modelManager.sections.huggingface`,`HuggingFace Hub`)}),Q.length>0&&(0,v.jsxs)(`span`,{className:f(`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:[Q.length,` `,e(`modelManager.library.available`,`available`)]})]}),W.has(`huggingface`)?(0,v.jsx)(c,{className:`h-5 w-5 text-gray-500`}):(0,v.jsx)(l,{className:`h-5 w-5 text-gray-500`})]}),W.has(`huggingface`)&&(0,v.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,v.jsxs)(`div`,{className:`relative flex-1`,children:[(0,v.jsx)(ie,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,v.jsx)(`input`,{type:`text`,value:et,onChange:e=>tt(e.target.value),placeholder:e(`modelManager.huggingface.search`,`Search HuggingFace models...`),className:f(`w-full pl-10 pr-4 py-2 rounded-lg border 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-none focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`)})]}),(0,v.jsxs)(`select`,{value:L,onChange:e=>it(e.target.value),className:f(`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-none focus:ring-2 focus:ring-primary-500/20`),children:[(0,v.jsx)(`option`,{value:`text-generation`,children:e(`modelManager.huggingface.tasks.textGen`,`Text Generation`)}),(0,v.jsx)(`option`,{value:`text-to-speech`,children:e(`modelManager.huggingface.tasks.tts`,`Text to Speech`)}),(0,v.jsx)(`option`,{value:`text-to-image`,children:e(`modelManager.huggingface.tasks.image`,`Text to Image`)}),(0,v.jsx)(`option`,{value:`automatic-speech-recognition`,children:e(`modelManager.huggingface.tasks.stt`,`Speech Recognition`)})]}),(0,v.jsxs)(`select`,{value:R,onChange:e=>at(e.target.value),className:f(`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-none focus:ring-2 focus:ring-primary-500/20`),children:[(0,v.jsx)(`option`,{value:`downloads`,children:e(`modelManager.huggingface.sort.downloads`,`Most Downloads`)}),(0,v.jsx)(`option`,{value:`likes`,children:e(`modelManager.huggingface.sort.likes`,`Most Liked`)}),(0,v.jsx)(`option`,{value:`lastModified`,children:e(`modelManager.huggingface.sort.recent`,`Recently Updated`)})]})]}),!r&&(0,v.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-300`,children:e(`modelManager.pull.restricted`)}),St?(0,v.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,v.jsx)(te,{className:`h-5 w-5 animate-spin text-gray-400`})}):Q.length===0?(0,v.jsx)(`div`,{className:`text-center py-8 text-gray-500`,children:e(`modelManager.huggingface.noResults`,`No models found. Try adjusting your search or filters.`)}):(0,v.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:Q.map(t=>{let n=ot===t.id,ee=ut===t.id,i=ct[t.id]||[];return(0,v.jsxs)(`div`,{className:f(`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,v.jsxs)(`div`,{className:`p-4 cursor-pointer`,onClick:()=>Tt(t.id),children:[(0,v.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-2`,children:[(0,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800 truncate`,children:t.id}),t.gated&&(0,v.jsx)(`span`,{className:f(`px-1.5 py-0.5 rounded text-xs`,`bg-yellow-100 dark:bg-yellow-900/30`,`text-yellow-700 dark:text-yellow-400`),children:e(`modelManager.huggingface.gated`,`Gated`)})]}),(0,v.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-0.5`,children:[e(`modelManager.huggingface.by`,`by`),` `,t.author]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,v.jsx)(`a`,{href:`https://huggingface.co/${t.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:e(`modelManager.huggingface.viewOnHF`,`View on HuggingFace`),children:(0,v.jsx)(pe,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`})}),(0,v.jsx)(l,{className:f(`h-4 w-4 text-gray-400 transition-transform`,n&&`rotate-180`)})]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-500 dark:text-dark-600`,children:[(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(u,{className:`h-3.5 w-3.5`}),t.downloads>=1e6?`${(t.downloads/1e6).toFixed(1)}M`:t.downloads>=1e3?`${(t.downloads/1e3).toFixed(1)}K`:t.downloads]}),(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(oe,{className:`h-3.5 w-3.5`}),t.likes>=1e3?`${(t.likes/1e3).toFixed(1)}K`:t.likes]}),t.pipeline_tag&&(0,v.jsx)(`span`,{className:f(`px-1.5 py-0.5 rounded`,`bg-gray-200 dark:bg-dark-300`),children:t.pipeline_tag})]})]}),n&&(0,v.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:ee?(0,v.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,v.jsx)(te,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,v.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:e(`modelManager.huggingface.checkingGguf`)})]}):i.length===0?(0,v.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:e(`modelManager.huggingface.noGgufAvailable`)}):(0,v.jsxs)(`div`,{className:`space-y-2`,children:[(0,v.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 mb-2`,children:e(`modelManager.huggingface.ggufFilesCount`,{count:i.length})}),i.map(t=>{let n=z===t.ollamaCommand;return(0,v.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,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 truncate`,children:t.filename}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,v.jsx)(`span`,{children:t.sizeFormatted}),t.quantization&&(0,v.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-400`,children:t.quantization})]})]}),n?(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:V?.percent===void 0?`...`:`${V.percent}%`}),(0,v.jsx)(`button`,{onClick:e=>{e.stopPropagation(),Dt()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,v.jsx)(d,{className:`h-4 w-4`})})]}):(0,v.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),Et(t.ollamaCommand,t.filename)},disabled:!!z||!r,className:f(`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,v.jsx)(u,{className:`h-3 w-3 inline mr-1`}),e(`models.pull`)]})]},t.filename)}),z?.startsWith(`hf.co/`)&&z.includes(t.id)&&V?.percent!==void 0&&(0,v.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,v.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${V.percent}%`}})})]})})]},t.id)})}),(0,v.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[(0,v.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,className:f(`inline-flex items-center gap-1.5 text-xs`,`text-primary-600 dark:text-primary-400`,`hover:underline`),children:[(0,v.jsx)(pe,{className:`h-3 w-3`}),e(`modelManager.huggingface.browseAll`,`Browse all on HuggingFace`)]}),(0,v.jsxs)(m,{onClick:Ct,variant:`outline`,size:`sm`,disabled:St,className:f(`gap-1.5`,``,``),children:[(0,v.jsx)(o,{className:f(`h-3.5 w-3.5`,St&&`animate-spin`)}),e(`modelManager.library.refresh`,`Refresh`)]})]})]})]}),Array.isArray(Y)&&Y.length>0&&(0,v.jsxs)(`div`,{className:f(`rounded-xl p-4 border`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,v.jsx)(`div`,{className:f(`p-2 rounded-lg`,`bg-green-100 dark:bg-green-900/30`),children:(0,v.jsx)(ne,{className:`h-5 w-5 text-green-600 dark:text-green-400`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`modelManager.sections.running`)}),(0,v.jsxs)(`span`,{className:f(`ml-auto 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:[Y.length,` `,e(`modelManager.systemStatus.running`)]})]}),(0,v.jsx)(`div`,{className:`space-y-2`,children:Y.map(t=>(0,v.jsxs)(`div`,{className:f(`flex items-center justify-between p-4 rounded-lg border`,`bg-green-50 dark:bg-green-900/10`,`border-green-200 dark:border-green-800/50`),children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:f(`w-2 h-2 rounded-full animate-pulse`,`bg-green-500`)}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`font-medium text-green-800 dark:text-green-400`,children:t.name}),(0,v.jsxs)(`div`,{className:`flex items-center gap-3 text-sm text-green-600 dark:text-green-500`,children:[(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(re,{className:`h-3 w-3`}),e(`modelManager.systemStatus.vram`),`:`,` `,$(t.size_vram||0)]}),t.size&&(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(s,{className:`h-3 w-3`}),e(`models.size`),`: `,$(t.size)]})]})]})]}),(0,v.jsxs)(`div`,{className:f(`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs font-medium`,`bg-green-100 dark:bg-green-900/30`,`text-green-700 dark:text-green-400`),children:[(0,v.jsx)(ve,{className:`h-3 w-3`}),e(`modelManager.local.running`)]})]},t.name))})]}),(0,v.jsxs)(`div`,{className:f(`rounded-xl border overflow-hidden`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`button`,{onClick:()=>G(`local`),className:f(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:f(`p-2 rounded-lg`,`bg-blue-100 dark:bg-blue-900/30`),children:(0,v.jsx)(s,{className:`h-5 w-5 text-blue-600 dark:text-blue-400`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`modelManager.sections.local`)}),(0,v.jsxs)(`span`,{className:f(`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:[J.length,` `,e(`modelManager.local.installed`)]})]}),W.has(`local`)?(0,v.jsx)(c,{className:`h-5 w-5 text-gray-500`}):(0,v.jsx)(l,{className:`h-5 w-5 text-gray-500`})]}),W.has(`local`)&&(0,v.jsx)(`div`,{className:`p-4 pt-0`,children:J.length===0?(0,v.jsxs)(`div`,{className:f(`text-center py-12 rounded-lg border-2 border-dashed`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsx)(s,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,v.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mb-2`,children:e(`modelManager.local.noModels`)}),(0,v.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-500`,children:e(`modelManager.local.pullToStart`)})]}):(0,v.jsx)(`div`,{className:`space-y-3`,children:J.map(t=>(0,v.jsx)(`div`,{className:f(`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,v.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,v.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:t.name}),Ft(t.name)&&(0,v.jsxs)(`span`,{className:f(`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,v.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse`}),e(`modelManager.local.running`)]})]}),(0,v.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,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(s,{className:`h-3.5 w-3.5`}),$(t.size)]}),t.details?.parameter_size&&(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(me,{className:`h-3.5 w-3.5`}),t.details.parameter_size]}),t.details?.quantization_level&&(0,v.jsx)(`span`,{className:f(`px-1.5 py-0.5 rounded text-xs`,`bg-gray-200 dark:bg-dark-300`,`text-gray-600 dark:text-gray-400`),children:t.details.quantization_level}),t.details?.family&&(0,v.jsx)(`span`,{className:`text-gray-500 dark:text-gray-500`,children:t.details.family})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-400 dark:text-dark-500 mt-2`,children:[(0,v.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(be,{className:`h-3 w-3`}),new Date(t.modified_at).toLocaleDateString()]}),(0,v.jsxs)(`span`,{className:`flex items-center gap-1 font-mono truncate max-w-[200px]`,title:t.digest,children:[(0,v.jsx)(se,{className:`h-3 w-3`}),t.digest.slice(0,12),`...`]})]})]}),(0,v.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,v.jsxs)(m,{onClick:()=>jt(t.name),variant:`outline`,size:`sm`,className:f(`gap-1.5`,``,``),children:[(0,v.jsx)(_e,{className:`h-3.5 w-3.5`}),e(`modelManager.local.info`)]}),(0,v.jsxs)(m,{onClick:()=>{Re(t.name),O(!0)},variant:`outline`,size:`sm`,className:f(`gap-1.5`,``,``),children:[(0,v.jsx)(ce,{className:`h-3.5 w-3.5`}),e(`modelManager.local.copy`)]}),(0,v.jsxs)(m,{onClick:()=>At(t.name),variant:`outline`,size:`sm`,className:f(`gap-1.5`,`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,``,``),children:[(0,v.jsx)(de,{className:`h-3.5 w-3.5`}),e(`modelManager.local.delete`)]})]})]})},t.name))})})]}),(0,v.jsxs)(`div`,{className:f(`rounded-xl border overflow-hidden`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`button`,{onClick:()=>G(`advanced`),className:f(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,v.jsx)(`div`,{className:f(`p-2 rounded-lg`,`bg-amber-100 dark:bg-amber-900/30`),children:(0,v.jsx)(ye,{className:`h-5 w-5 text-amber-600 dark:text-amber-400`})}),(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`modelManager.sections.advanced`)})]}),W.has(`advanced`)?(0,v.jsx)(c,{className:`h-5 w-5 text-gray-500`}):(0,v.jsx)(l,{className:`h-5 w-5 text-gray-500`})]}),W.has(`advanced`)&&(0,v.jsx)(`div`,{className:`p-4 pt-0`,children:(0,v.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3`,children:[(0,v.jsxs)(m,{onClick:()=>j(!0),variant:`outline`,className:f(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,v.jsx)(ge,{className:`h-5 w-5 text-purple-500`}),(0,v.jsxs)(`div`,{className:`text-left`,children:[(0,v.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.createModel`)}),(0,v.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.fromModelfile`)})]})]}),(0,v.jsxs)(m,{onClick:()=>O(!0),variant:`outline`,className:f(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,v.jsx)(ce,{className:`h-5 w-5 text-blue-500`}),(0,v.jsxs)(`div`,{className:`text-left`,children:[(0,v.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.copyModel`)}),(0,v.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.duplicateExisting`)})]})]}),(0,v.jsxs)(m,{onClick:()=>Je(!0),variant:`outline`,className:f(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,v.jsx)(fe,{className:`h-5 w-5 text-green-500`}),(0,v.jsxs)(`div`,{className:`text-left`,children:[(0,v.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.testEmbeddings`)}),(0,v.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.generateVectors`)})]})]}),(0,v.jsxs)(m,{onClick:async()=>{try{(await p.checkHealth()).success&&(await q(),a.success(e(`modelManager.advanced.healthy`)))}catch{await q(),a.error(e(`modelManager.systemStatus.offline`))}},variant:`outline`,className:f(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,v.jsx)(he,{className:`h-5 w-5 text-rose-500`}),(0,v.jsxs)(`div`,{className:`text-left`,children:[(0,v.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.healthCheck`)}),(0,v.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.testConnection`)})]})]})]})})]}),Ne&&(0,_.createPortal)((0,v.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-4`,children:[(0,v.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>Pe(!1)}),(0,v.jsxs)(`div`,{className:f(`relative w-full max-w-2xl max-h-[85vh] overflow-hidden rounded-xl border shadow-2xl`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`div`,{className:f(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:[e(`modelManager.modals.details.title`),`: `,je]}),(0,v.jsx)(`button`,{onClick:()=>Pe(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,v.jsx)(d,{className:`h-5 w-5 text-gray-500`})})]}),(0,v.jsx)(`div`,{className:`overflow-y-auto max-h-[calc(85vh-60px)] p-4 space-y-4`,children:Fe?(0,v.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,v.jsx)(o,{className:`h-6 w-6 animate-spin text-gray-400`})}):D?(0,v.jsxs)(v.Fragment,{children:[D.details&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`modelManager.modals.details.info`)}),(0,v.jsx)(`div`,{className:f(`p-3 rounded-lg text-sm`,`bg-gray-50 dark:bg-dark-50`),children:(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[D.details.family&&(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{className:`text-gray-500`,children:[e(`modelManager.modals.details.family`),`:`]}),` `,(0,v.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:D.details.family})]}),D.details.parameter_size&&(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{className:`text-gray-500`,children:[e(`modelManager.modals.details.parameters`),`:`]}),` `,(0,v.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:D.details.parameter_size})]}),D.details.quantization_level&&(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{className:`text-gray-500`,children:[e(`modelManager.modals.details.quantization`),`:`]}),` `,(0,v.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:D.details.quantization_level})]}),D.details.format&&(0,v.jsxs)(`div`,{children:[(0,v.jsxs)(`span`,{className:`text-gray-500`,children:[e(`modelManager.modals.details.format`),`:`]}),` `,(0,v.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:D.details.format})]})]})})]}),D.system&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`modelManager.modals.details.systemPrompt`)}),(0,v.jsx)(`pre`,{className:f(`p-3 rounded-lg text-xs overflow-x-auto`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:D.system})]}),D.template&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`modelManager.modals.details.template`)}),(0,v.jsx)(`pre`,{className:f(`p-3 rounded-lg text-xs overflow-x-auto max-h-40`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:D.template})]}),D.parameters&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`modelManager.modals.details.parameters`)}),(0,v.jsx)(`pre`,{className:f(`p-3 rounded-lg text-xs overflow-x-auto`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:D.parameters})]}),D.license&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`modelManager.modals.details.license`)}),(0,v.jsx)(`pre`,{className:f(`p-3 rounded-lg text-xs overflow-x-auto max-h-32`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:D.license})]}),D.modelfile&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`modelManager.modals.details.modelfile`)}),(0,v.jsx)(`pre`,{className:f(`p-3 rounded-lg text-xs overflow-x-auto max-h-60`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:D.modelfile})]})]}):(0,v.jsx)(`p`,{className:`text-center text-gray-500`,children:e(`modelManager.modals.details.noDetails`)})})]})]}),document.body),Le&&(0,_.createPortal)((0,v.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-4`,children:[(0,v.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>O(!1)}),(0,v.jsxs)(`div`,{className:f(`relative w-full max-w-md rounded-xl border shadow-2xl`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`div`,{className:f(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:e(`modelManager.modals.copy.title`)}),(0,v.jsx)(`button`,{onClick:()=>O(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,v.jsx)(d,{className:`h-5 w-5 text-gray-500`})})]}),(0,v.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`modelManager.modals.copy.source`)}),(0,v.jsxs)(`select`,{value:k,onChange:e=>Re(e.target.value),className:f(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`),children:[(0,v.jsx)(`option`,{value:``,children:e(`modelManager.modals.copy.selectModel`)}),J.map(e=>(0,v.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`modelManager.modals.copy.newName`)}),(0,v.jsx)(`input`,{type:`text`,value:A,onChange:e=>ze(e.target.value),placeholder:e(`modelManager.modals.copy.placeholder`),className:f(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`)})]}),(0,v.jsxs)(m,{onClick:Mt,disabled:!k.trim()||!A.trim()||Be,className:f(`w-full gap-2`,``),children:[Be?(0,v.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,v.jsx)(ce,{className:`h-4 w-4`}),e(Be?`modelManager.modals.copy.copying`:`modelManager.modals.copy.button`)]})]})]})]}),document.body),He&&(0,_.createPortal)((0,v.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-4`,children:[(0,v.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>j(!1)}),(0,v.jsxs)(`div`,{className:f(`relative w-full max-w-lg rounded-xl border shadow-2xl`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`div`,{className:f(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:e(`modelManager.modals.create.title`)}),(0,v.jsx)(`button`,{onClick:()=>j(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,v.jsx)(d,{className:`h-5 w-5 text-gray-500`})})]}),(0,v.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`modelManager.modals.create.name`)}),(0,v.jsx)(`input`,{type:`text`,value:M,onChange:e=>Ue(e.target.value),placeholder:e(`modelManager.modals.create.namePlaceholder`),className:f(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`modelManager.modals.create.modelfile`)}),(0,v.jsx)(`textarea`,{value:N,onChange:e=>We(e.target.value),placeholder:e(`modelManager.modals.create.modelfilePlaceholder`),rows:8,className:f(`w-full px-3 py-2 rounded-lg border text-sm font-mono`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`,`resize-none`)}),(0,v.jsxs)(`p`,{className:`mt-1 text-xs text-gray-500`,children:[e(`modelManager.modals.create.see`),` `,(0,v.jsx)(`a`,{href:`https://github.com/ollama/ollama/blob/main/docs/modelfile.md`,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary-600 hover:underline`,children:e(`modelManager.modals.create.docs`)}),` `,e(`modelManager.modals.create.docsLink`)]})]}),(0,v.jsxs)(m,{onClick:Nt,disabled:!M.trim()||!N.trim()||Ge,className:f(`w-full gap-2`,``),children:[Ge?(0,v.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,v.jsx)(ge,{className:`h-4 w-4`}),e(Ge?`modelManager.modals.create.creating`:`modelManager.modals.create.button`)]})]})]})]}),document.body),qe&&(0,_.createPortal)((0,v.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-4`,children:[(0,v.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:()=>Je(!1)}),(0,v.jsxs)(`div`,{className:f(`relative w-full max-w-lg rounded-xl border shadow-2xl`,`bg-white dark:bg-dark-100`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsxs)(`div`,{className:f(`flex items-center justify-between p-4 border-b`,`border-gray-200 dark:border-dark-300`),children:[(0,v.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100`,children:e(`modelManager.modals.embeddings.title`)}),(0,v.jsx)(`button`,{onClick:()=>Je(!1),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,v.jsx)(d,{className:`h-5 w-5 text-gray-500`})})]}),(0,v.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`modelManager.modals.embeddings.model`)}),(0,v.jsxs)(`select`,{value:P,onChange:e=>Ye(e.target.value),className:f(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`),children:[(0,v.jsx)(`option`,{value:``,children:e(`modelManager.modals.embeddings.selectModel`)}),J.map(e=>(0,v.jsx)(`option`,{value:e.name,children:e.name},e.name))]}),(0,v.jsx)(`p`,{className:`mt-1 text-xs text-gray-500`,children:e(`modelManager.modals.embeddings.recommended`)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`modelManager.modals.embeddings.input`)}),(0,v.jsx)(`textarea`,{value:F,onChange:e=>Xe(e.target.value),placeholder:e(`modelManager.modals.embeddings.placeholder`),rows:3,className:f(`w-full px-3 py-2 rounded-lg border text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500`,`resize-none`)})]}),(0,v.jsxs)(m,{onClick:Pt,disabled:!P.trim()||!F.trim()||Qe,className:f(`w-full gap-2`,``),children:[Qe?(0,v.jsx)(o,{className:`h-4 w-4 animate-spin`}):(0,v.jsx)(fe,{className:`h-4 w-4`}),e(Qe?`modelManager.modals.embeddings.generating`:`modelManager.modals.embeddings.button`)]}),I&&(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`modelManager.modals.embeddings.result`,{count:I.length})}),(0,v.jsxs)(`pre`,{className:f(`p-3 rounded-lg text-xs overflow-x-auto max-h-32`,`bg-gray-50 dark:bg-dark-50`,`text-gray-700 dark:text-gray-300`),children:[`[`,I.slice(0,10).join(`, `),I.length>10&&`, ...`,` ]`]})]})]})]})]}),document.body)]})},y=()=>{let{t:e}=we();return(0,v.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,v.jsxs)(`div`,{className:`max-w-6xl mx-auto p-6`,children:[(0,v.jsxs)(`div`,{className:`text-center max-w-md mx-auto mb-8`,children:[(0,v.jsx)(`h2`,{className:`libre-brand text-4xl sm:text-5xl font-normal text-gray-900 dark:text-dark-800 mb-3`,style:{fontWeight:300,letterSpacing:`0.01em`},children:e(`models.title`)}),(0,v.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 leading-relaxed`,children:e(`models.subtitle`)})]}),(0,v.jsx)(Te,{})]})})};export{y as ModelsPage,y as default};
@@ -1,13 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{m as t,p as n}from"./markdown-vendor-DLzJCMRQ.js";import{Et as r,J as i,L as a,Lt as o,Nt as s,O as c,Ot as l,Q as u,S as d,_ as f,c as p,ct as m,d as h,h as g,ht as _,j as v,l as y,mt as b,n as x,o as ee,pt as S,q as C,t as te,u as w,v as T,xt as E,y as D}from"./ui-vendor-ClcVY3m-.js";import{o as O,t as k}from"./appStore-BpzQfKOd.js";import{a as A,c as j,l as M}from"./api-MQ7bONaU.js";import{b as N,m as P,p as F,t as ne,v as I}from"../assets/index-cOuIFv6G.js";var L=e(t(),1),R=n(),z=({persona:e,onEdit:t,onDelete:n,onDownload:r,onSelect:i,onToggleFavorite:c,isSelected:u=!1,compact:p=!1})=>{let{t:x}=P(),ee=N(),[C,w]=(0,L.useState)(!1),[E,D]=(0,L.useState)(!1),k=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),{data:A=null}=I({queryKey:[`persona-memory-status`,e.id],queryFn:async()=>{let t=await M.getMemoryStatus(e.id);return t.success&&t.data?t.data:null},enabled:k}),j=()=>ee.invalidateQueries({queryKey:[`persona-memory-status`,e.id]}),ne=async()=>{if(confirm(x(`personaCard.wipeConfirm`))){D(!0);try{let t=await M.wipeMemories(e.id);t.success?(o.success(x(`personaCard.wipeSuccess`,{count:t.data?.deleted_count||0})),await j()):o.error(x(`personaCard.failed`,{action:`wipe memories`}))}catch(e){o.error(x(`personaCard.failed`,{action:`wipe memories`})),console.error(e)}finally{D(!1),w(!1)}}},z=async()=>{D(!0);try{let t=await M.backupPersona(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-backup.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),o.success(x(`personaCard.backupSuccess`))}catch(e){o.error(x(`personaCard.failed`,{action:`backup persona`})),console.error(e)}finally{D(!1),w(!1)}},B=async()=>{D(!0);try{let t=await M.exportPersonaDNA(e.id),n=window.URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase().replace(/\s+/g,`-`)}-dna.json`,document.body.appendChild(r),r.click(),window.URL.revokeObjectURL(n),document.body.removeChild(r),o.success(x(`personaCard.dnaSuccess`))}catch(e){o.error(x(`personaCard.failed`,{action:`export persona DNA`})),console.error(e)}finally{D(!1),w(!1)}},V=()=>e.avatar?e.avatar:`https://ui-avatars.com/api/?name=${encodeURIComponent(e.name)}&background=6366f1&color=fff&size=128`;return p?(0,R.jsxs)(`div`,{className:O(`group relative flex items-center gap-3 p-3 rounded-xl cursor-pointer transition-all duration-200`,`border border-transparent`,`hover:bg-gray-50 dark:hover:bg-dark-100`,u&&[`bg-primary-50 dark:bg-primary-900/20`,`border-primary-200 dark:border-primary-700`]),onClick:()=>i?.(e),children:[(0,R.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,R.jsx)(`img`,{src:V(),alt:e.name,className:`w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100`}),k&&(0,R.jsx)(`div`,{className:`absolute -bottom-0.5 -right-0.5 w-4 h-4 bg-gradient-to-br from-purple-500 to-primary-500 rounded-full flex items-center justify-center`,children:(0,R.jsx)(T,{className:`h-2.5 w-2.5 text-white`})})]}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`h4`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 truncate`,children:e.name}),e.is_favorite&&(0,R.jsx)(g,{className:`h-3 w-3 text-amber-500 fill-amber-500 flex-shrink-0`})]}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:e.model})]}),u&&(0,R.jsx)(`div`,{className:`flex-shrink-0`,children:(0,R.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-600 flex items-center justify-center`,children:(0,R.jsx)(v,{className:`h-3 w-3 text-white ml-0.5`})})})]}):(0,R.jsxs)(`div`,{className:O(`group relative rounded-2xl overflow-hidden transition-all duration-300`,`bg-white dark:bg-dark-100`,`border border-gray-200/60 dark:border-dark-300/60`,`hover:border-gray-300 dark:hover:border-dark-400`,`shadow-sm hover:shadow-lg dark:shadow-none`,u&&[`ring-2 ring-primary-500 dark:ring-primary-400`,`border-primary-300 dark:border-primary-600`]),children:[(0,R.jsxs)(`div`,{className:`relative h-20`,children:[e.background?(0,R.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,R.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,R.jsx)(`div`,{className:`absolute inset-0 bg-black/10 dark:bg-black/20`}),(0,R.jsxs)(`div`,{className:`absolute top-3 left-3 right-3 flex items-start justify-between`,children:[(0,R.jsx)(`button`,{onClick:t=>{t.stopPropagation(),c?.(e)},className:O(`p-1.5 rounded-full transition-all duration-200`,`bg-white/20 hover:bg-white/30 backdrop-blur-sm`,e.is_favorite&&`bg-amber-500/80 hover:bg-amber-500`),children:(0,R.jsx)(g,{className:O(`h-4 w-4`,e.is_favorite?`text-white fill-white`:`text-white/80 hover:text-white`)})}),k&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,R.jsx)(T,{className:`h-3 w-3`}),x(`personaCard.enhanced`)]})]})]}),(0,R.jsx)(`div`,{className:`relative px-4 -mt-8`,children:(0,R.jsxs)(`div`,{className:`relative inline-block`,children:[(0,R.jsx)(`img`,{src:V(),alt:e.name,className:`w-16 h-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100 shadow-lg`}),k&&(0,R.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 bg-gradient-to-br from-purple-500 to-primary-500 rounded-lg flex items-center justify-center shadow-sm`,children:(0,R.jsx)(l,{className:`h-3.5 w-3.5 text-white`})})]})}),(0,R.jsxs)(`div`,{className:`px-4 pt-3 pb-4`,children:[(0,R.jsxs)(`div`,{className:`mb-3`,children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 leading-tight`,children:e.name}),(0,R.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 flex items-center gap-1.5 mt-0.5`,children:[(0,R.jsx)(d,{className:`h-3.5 w-3.5`}),e.model]})]}),e.description&&(0,R.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 line-clamp-2 mb-3`,children:e.description}),e.parameters.system_prompt&&(0,R.jsxs)(`div`,{className:`mb-3 p-2.5 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1`,children:[(0,R.jsx)(a,{className:`h-3 w-3 text-gray-400 dark:text-gray-500`}),(0,R.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500`,children:x(`personaCard.systemPrompt`)})]}),(0,R.jsxs)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,R.jsx)(te,{className:`h-3 w-3`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,R.jsxs)(`span`,{className:`inline-flex items-center px-2 py-1 rounded-md text-[11px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),(0,R.jsxs)(`span`,{className:`inline-flex items-center px-2 py-1 rounded-md text-[11px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(e.parameters.context_window||4096).toLocaleString(),` ctx`]})]}),k&&A&&(0,R.jsx)(`div`,{className:`mb-3 p-2.5 rounded-lg bg-gradient-to-r from-primary-50 to-purple-50 dark:from-primary-900/20 dark:to-purple-900/20 border border-primary-100 dark:border-primary-800/30`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(_,{className:`h-4 w-4 text-primary-600 dark:text-primary-400`}),(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`span`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300`,children:[A.memory_count,` `,x(`personaCard.memories`)]}),(0,R.jsx)(`span`,{className:`text-[10px] text-primary-600/70 dark:text-primary-400/70 ml-2`,children:(e=>e<1?`${(e*1024).toFixed(0)} KB`:`${e.toFixed(1)} MB`)(A.size_mb)})]})]}),A.status&&(0,R.jsx)(`span`,{className:O(`text-[10px] px-1.5 py-0.5 rounded-full font-medium`,A.status===`active`?`bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`),children:A.status})]})}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-gray-100 dark:border-dark-200`,children:[i&&(0,R.jsxs)(F,{onClick:()=>i(e),size:`sm`,className:`bg-primary-500 hover:bg-primary-600 dark:bg-primary-600 dark:hover:bg-primary-500 text-white px-4`,children:[(0,R.jsx)(v,{className:`h-3.5 w-3.5 mr-1.5`}),x(`personaCard.use`)]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto`,children:[(0,R.jsx)(`button`,{onClick:()=>t(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:x(`personaCard.editTooltip`),children:(0,R.jsx)(f,{className:`h-4 w-4`})}),(0,R.jsx)(`button`,{onClick:()=>r(e),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,title:x(`personaCard.downloadTooltip`),children:(0,R.jsx)(b,{className:`h-4 w-4`})}),(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsx)(`button`,{onClick:()=>w(!C),className:`p-2 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-200 transition-colors`,children:(0,R.jsx)(S,{className:`h-4 w-4`})}),C&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>w(!1)}),(0,R.jsxs)(`div`,{className:`absolute right-0 bottom-full mb-1 w-44 py-1 bg-white dark:bg-dark-100 rounded-xl shadow-lg border border-gray-200 dark:border-dark-300 z-20`,children:[k&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`button`,{onClick:z,disabled:E,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-dark-50 disabled:opacity-50`,children:[(0,R.jsx)(s,{className:`h-4 w-4`}),x(`personaCard.backup`)]}),(0,R.jsxs)(`button`,{onClick:B,disabled:E,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-dark-50 disabled:opacity-50`,children:[(0,R.jsx)(m,{className:`h-4 w-4`}),x(`personaCard.exportDNA`)]}),A&&A.memory_count>0&&(0,R.jsxs)(`button`,{onClick:ne,disabled:E,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 disabled:opacity-50`,children:[(0,R.jsx)(y,{className:`h-4 w-4`}),x(`personaCard.wipeMemories`)]}),(0,R.jsx)(`div`,{className:`my-1 border-t border-gray-100 dark:border-dark-200`})]}),(0,R.jsxs)(`button`,{onClick:()=>{n(e),w(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20`,children:[(0,R.jsx)(h,{className:`h-4 w-4`}),x(`common.delete`)]})]})]})]})]})]})]})]})},B=({value:e,onChange:t,className:n=``})=>{let{t:r}=P(),a=(0,L.useRef)(null),[s,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(!1),d=async e=>{if(!e.type.startsWith(`image/`)){o.error(r(`personaBackground.invalidFile`));return}if(e.size>5*1024*1024){o.error(r(`personaBackground.fileTooLarge`));return}c(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),o.success(r(`personaBackground.uploaded`))},n.onerror=()=>{o.error(r(`personaBackground.readFailed`))},n.readAsDataURL(e)}catch(e){console.error(`Failed to upload background:`,e),o.error(r(`personaBackground.uploadFailed`))}finally{c(!1)}};return(0,R.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:r(`personaBackground.label`)}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[e?(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsx)(`div`,{className:`w-full h-32 rounded-lg bg-cover bg-center border-2 border-gray-300 dark:border-dark-300`,style:{backgroundImage:`url(${e})`}}),(0,R.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:r(`personaBackground.customBackground`)}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:r(`personaBackground.clickToChange`)})]}),(0,R.jsx)(F,{variant:`ghost`,size:`sm`,onClick:()=>{t(``),o.success(r(`personaBackground.removed`))},className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,R.jsx)(x,{className:`h-4 w-4`})})]})]}):(0,R.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${l?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:e=>{e.preventDefault(),u(!0)},onDragLeave:e=>{e.preventDefault(),u(!1)},onDrop:e=>{e.preventDefault(),u(!1);let t=e.dataTransfer.files?.[0];t&&d(t)},onClick:()=>a.current?.click(),children:[(0,R.jsx)(i,{className:`h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4`}),(0,R.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:r(`personaBackground.uploadBackgroundImage`)}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:r(`personaBackground.dragAndDrop`)}),(0,R.jsxs)(F,{variant:`outline`,size:`sm`,disabled:s,className:`mx-auto`,children:[(0,R.jsx)(p,{className:`h-4 w-4 mr-2`}),r(s?`personaBackground.uploading`:`personaBackground.chooseImage`)]})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:r(`personaBackground.enterImageUrl`)}),(0,R.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/background.jpg`})]})]}),(0,R.jsx)(`input`,{ref:a,type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];t&&d(t)},className:`hidden`}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:r(`personaBackground.supportedFormats`)})]})})},V=({label:e,value:t,min:n,max:r,step:i,onChange:a,hint:o,format:s=e=>String(e),colorClass:c=`text-gray-700 dark:text-dark-600`})=>{let l=(t-n)/(r-n)*100;return(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,R.jsx)(`label`,{className:O(`block text-sm font-medium`,c),children:e}),(0,R.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:s(t),onChange:e=>{let t=parseFloat(e.target.value);isNaN(t)||a(Math.min(r,Math.max(n,t)))},className:`w-20 px-2 py-1 text-sm text-right bg-gray-100 dark:bg-dark-200 border border-gray-300 dark:border-dark-300 rounded focus:outline-none focus:ring-1 focus:ring-primary-500 dark:text-dark-600`})]}),(0,R.jsx)(`input`,{type:`range`,min:n,max:r,step:i,value:t,onChange:e=>a(parseFloat(e.target.value)),className:`w-full h-2 bg-gray-200 dark:bg-dark-200 rounded-lg appearance-none cursor-pointer slider`,style:{"--progress":`${l}%`}}),o&&(0,R.jsx)(`p`,{className:O(`text-xs mt-1`,c.replace(`700`,`500`).replace(`600`,`400`)),children:o})]})},H=({label:e,checked:t,onChange:n,colorClass:r=`text-gray-700 dark:text-dark-600`})=>(0,R.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,R.jsx)(`div`,{className:O(`relative w-10 h-5 rounded-full transition-colors`,t?`bg-primary-500 dark:bg-primary-600`:`bg-gray-300 dark:bg-dark-300`),onClick:()=>n(!t),children:(0,R.jsx)(`div`,{className:O(`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-5`)})}),(0,R.jsx)(`span`,{className:O(`text-sm font-medium`,r),children:e})]}),U={name:``,description:``,model:``,parameters:{temperature:.7,top_p:.9,top_k:40,context_window:4096,max_tokens:1024,system_prompt:``,repeat_penalty:1.1,presence_penalty:0,frequency_penalty:0},avatar:``,background:``,embedding_model:``,memory_settings:{enabled:!1,max_memories:1e3,auto_cleanup:!0,retention_days:90},mutation_settings:{enabled:!1,sensitivity:`medium`,auto_adapt:!0}},W=({persona:e,onSubmit:t,onCancel:n})=>{let{preferences:i}=k(),{t:a}=P(),[s,d]=(0,L.useState)(U),[f,p]=(0,L.useState)([]),[m,g]=(0,L.useState)([]),[v,y]=(0,L.useState)(!1),[b,x]=(0,L.useState)(!1),[S,z]=(0,L.useState)(!1),[W,G]=(0,L.useState)(null),[K,q]=(0,L.useState)(`basic`),[J,re]=(0,L.useState)(!1),ie=(0,L.useRef)(!1),Y=(0,L.useCallback)((e,t)=>{d(n=>({...n,[e]:t})),G(null)},[]),ae=(0,L.useCallback)((e,t)=>{d(n=>({...n,parameters:{...n.parameters,[e]:t}})),G(null)},[]),X=(0,L.useCallback)((e,t)=>{d(n=>({...n,[e]:{...n[e],...t}})),G(null)},[]),Z=(0,L.useCallback)(e=>{let t=e.reduce((e,t)=>(e.find(e=>e.id===t.id)||e.push(t),e),[]);return t.length>0?t:[{id:`nomic-embed-text`,name:`nomic-embed-text`,description:`Ollama - Default embedding model`,provider:`ollama`,dimensions:0,isDetectedEmbedding:!0}]},[]),Q=e?.id,oe=!!s.memory_settings?.enabled,se=N(),{data:$=null,isLoading:ce}=I({queryKey:[`persona-memory-status`,Q],queryFn:async()=>{if(!Q)return null;let e=await M.getMemoryStatus(Q);return e.success&&e.data?e.data:null},enabled:!!Q&&oe}),le=()=>se.invalidateQueries({queryKey:[`persona-memory-status`,Q]}),ue=async()=>{if(e?.id&&confirm(a(`personaForm.memory.wipeConfirm`))){re(!0);try{let t=await M.wipeMemories(e.id);t.success?(o.success(a(`personaForm.memory.wipeSuccess`,{count:t.data?.deleted_count||0})),await le()):o.error(a(`personaForm.error.saveFailed`))}catch{o.error(a(`personaForm.error.saveFailed`))}finally{re(!1)}}};(0,L.useEffect)(()=>{ie.current||(ie.current=!0,(async()=>{y(!0);try{let[t,n,r]=await Promise.all([j.getModels(),A.getModels(),e?Promise.resolve(null):M.getDefaultParameters()]);t.success&&t.data&&p(t.data);let a=Z(n.success&&n.data?n.data:[]);g(a);let o=a.find(e=>e.id===i.embeddingSettings?.model||e.rawModel===i.embeddingSettings?.model)?.id||a[0]?.id||``,s=a.find(t=>t.id===e?.embedding_model||t.rawModel===e?.embedding_model)?.id||e?.embedding_model||a[0]?.id||``;if(e)d({name:e.name,description:e.description||``,model:e.model,parameters:e.parameters,avatar:e.avatar||``,background:e.background||``,embedding_model:s,memory_settings:e.memory_settings||U.memory_settings,mutation_settings:e.mutation_settings||U.mutation_settings}),e.embedding_model&&!a.find(t=>t.id===e.embedding_model||t.rawModel===e.embedding_model)&&g(t=>Z([...t,{id:e.embedding_model,name:e.embedding_model,description:`Previously selected model (not currently available)`,provider:`openai`,dimensions:0}]));else{let e=r?.success?r.data:{};d(t=>({...t,parameters:{...t.parameters,...e},embedding_model:o}))}}catch(e){console.error(`Error loading data:`,e)}finally{y(!1)}})())},[e,Z,i.embeddingSettings?.model]);let de=async n=>{x(!0),z(n);try{let r={name:s.name,description:s.description,model:s.model,parameters:s.parameters,avatar:s.avatar,background:s.background,embedding_model:s.embedding_model,memory_settings:s.memory_settings,mutation_settings:s.mutation_settings},i=e?await M.updatePersona(e.id,r):await M.createPersona(s);i.success?(o.success(a(e?`personaForm.success.updated`:`personaForm.success.created`)),G(new Date),n&&t()):o.error(`${a(`personaForm.error.saveFailed`)}: ${i.error}`)}catch(e){o.error(`${a(`personaForm.error.saveFailed`)}: ${e instanceof Error?e.message:String(e)}`)}finally{x(!1),z(!1)}},fe=(0,L.useMemo)(()=>[{id:`basic`,label:a(`personaForm.tabs.basic`),icon:ee},{id:`parameters`,label:a(`personaForm.tabs.parameters`),icon:D},{id:`memory`,label:a(`personaForm.tabs.memory`),icon:T},{id:`advanced`,label:a(`personaForm.tabs.advanced`),icon:l}],[a]),pe=(0,L.useMemo)(()=>[{key:`temperature`,label:a(`personaForm.parameters.temperature`),min:0,max:2,step:.1,hint:a(`personaForm.parameters.temperatureHint`),format:e=>e.toFixed(1)},{key:`top_p`,label:a(`personaForm.parameters.topP`),min:0,max:1,step:.1,hint:a(`personaForm.parameters.topPHint`),format:e=>e.toFixed(1)},{key:`top_k`,label:a(`personaForm.parameters.topK`),min:1,max:100,step:1,hint:a(`personaForm.parameters.topKHint`),format:e=>String(Math.round(e))},{key:`context_window`,label:a(`personaForm.parameters.contextWindow`),min:128,max:131072,step:128,hint:a(`personaForm.parameters.contextWindowHint`),format:e=>String(Math.round(e))},{key:`max_tokens`,label:a(`personaForm.parameters.maxTokens`),min:1,max:8192,step:1,hint:a(`personaForm.parameters.maxTokensHint`),format:e=>String(Math.round(e))},{key:`repeat_penalty`,label:a(`personaForm.parameters.repeatPenalty`),min:.5,max:2,step:.1,hint:a(`personaForm.parameters.repeatPenaltyHint`),format:e=>e.toFixed(1)}],[a]);return v?(0,R.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,R.jsxs)(`div`,{className:`animate-pulse flex items-center gap-3`,children:[(0,R.jsx)(`div`,{className:`w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin`}),(0,R.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:a(`personaForm.loading`)})]})}):(0,R.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,R.jsxs)(`div`,{className:`mb-6`,children:[(0,R.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:a(e?`personaForm.title.edit`:`personaForm.title.create`)}),(0,R.jsxs)(`div`,{className:`flex items-center gap-4 mt-1`,children:[(0,R.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600`,children:a(e?`personaForm.subtitle.edit`:`personaForm.subtitle.create`)}),W&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-green-600 dark:text-green-400`,children:[(0,R.jsx)(`div`,{className:`w-2 h-2 bg-green-500 rounded-full`}),a(`personaForm.saved`),` `,W.toLocaleTimeString()]})]})]}),(0,R.jsxs)(`form`,{onSubmit:e=>e.preventDefault(),className:`space-y-6`,children:[(0,R.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,R.jsx)(`div`,{className:`flex border-b border-gray-200 dark:border-dark-300`,children:fe.map(e=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>q(e.id),className:`flex items-center gap-2 px-6 py-4 text-sm font-medium transition-colors ${K===e.id?`border-b-2 border-primary-500 text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-dark-600 hover:text-gray-700 dark:hover:text-dark-800`}`,children:[(0,R.jsx)(e.icon,{className:`h-4 w-4`}),e.label]},e.id))}),(0,R.jsxs)(`div`,{className:`p-6`,children:[K===`basic`&&(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[a(`personaForm.basic.name`),` *`]}),(0,R.jsx)(`input`,{type:`text`,value:s.name,onChange:e=>Y(`name`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,placeholder:a(`personaForm.basic.namePlaceholder`),required:!0})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[a(`personaForm.basic.model`),` *`]}),(0,R.jsxs)(`select`,{value:s.model,onChange:e=>Y(`model`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors`,required:!0,children:[(0,R.jsx)(`option`,{value:``,children:a(`personaForm.basic.selectModel`)}),f.map(e=>(0,R.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:a(`personaForm.basic.description`)}),(0,R.jsx)(`textarea`,{value:s.description,onChange:e=>Y(`description`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none`,rows:3,placeholder:a(`personaForm.basic.descriptionPlaceholder`)})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,R.jsx)(ne,{value:s.avatar||``,onChange:e=>Y(`avatar`,e)}),(0,R.jsx)(B,{value:s.background||``,onChange:e=>Y(`background`,e)})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:a(`personaForm.basic.systemPrompt`)}),(0,R.jsx)(`textarea`,{value:s.parameters.system_prompt,onChange:e=>ae(`system_prompt`,e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-colors resize-none font-mono text-sm`,rows:6,placeholder:a(`personaForm.basic.systemPromptPlaceholder`)}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-2`,children:a(`personaForm.basic.systemPromptHint`)})]})]}),K===`parameters`&&(0,R.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:pe.map(({key:e,label:t,min:n,max:r,step:i,hint:a,format:o})=>(0,R.jsx)(V,{label:t,value:s.parameters[e]||0,min:n,max:r,step:i,hint:a,format:o,onChange:t=>ae(e,t)},e))}),K===`memory`&&(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30`,children:[(0,R.jsx)(`div`,{className:`px-5 py-4 bg-gradient-to-r from-emerald-500 to-teal-500 dark:from-emerald-600 dark:to-teal-600`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,R.jsx)(_,{className:`h-5 w-5 text-white`})}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{className:`font-semibold text-white`,children:a(`personaForm.memory.title`)}),(0,R.jsx)(`p`,{className:`text-xs text-white/80`,children:a(`personaForm.memory.subtitle`)})]})]}),(0,R.jsx)(H,{label:``,checked:s.memory_settings?.enabled||!1,onChange:e=>X(`memory_settings`,{enabled:e})})]})}),s.memory_settings?.enabled&&e?.id&&(0,R.jsx)(`div`,{className:`px-5 py-4 bg-emerald-50 dark:bg-emerald-900/20 border-b border-emerald-100 dark:border-emerald-800/30`,children:ce?(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,R.jsx)(c,{className:`h-4 w-4 animate-spin`}),a(`personaForm.memory.loading`)]}):$?(0,R.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,R.jsxs)(`div`,{className:`text-center`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,R.jsx)(_,{className:`h-5 w-5`}),$.memory_count.toLocaleString()]}),(0,R.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:a(`personaForm.memory.memories`)})]}),(0,R.jsxs)(`div`,{className:`text-center`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,R.jsx)(u,{className:`h-5 w-5`}),$.size_mb.toFixed(1)]}),(0,R.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:a(`personaForm.memory.mbUsed`)})]}),(0,R.jsxs)(`div`,{className:`text-center`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,R.jsx)(E,{className:`h-5 w-5`}),$.last_backup?new Date($.last_backup).toLocaleDateString():a(`personaForm.memory.never`)]}),(0,R.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:a(`personaForm.memory.lastBackup`)})]})]}):(0,R.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,children:a(`personaForm.memory.noData`)})}),s.memory_settings?.enabled&&(0,R.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-4`,children:[(0,R.jsx)(V,{label:a(`personaForm.memory.maxMemories`),value:s.memory_settings.max_memories,min:100,max:1e4,step:100,hint:a(`personaForm.memory.maxMemoriesHint`),format:e=>e.toLocaleString(),colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>X(`memory_settings`,{max_memories:e})}),(0,R.jsx)(V,{label:a(`personaForm.memory.retention`),value:s.memory_settings.retention_days,min:7,max:365,step:7,hint:a(`personaForm.memory.retentionHint`),format:e=>`${Math.round(e)} days`,colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>X(`memory_settings`,{retention_days:e})}),(0,R.jsx)(H,{label:a(`personaForm.memory.autoCleanup`),checked:s.memory_settings.auto_cleanup,onChange:e=>X(`memory_settings`,{auto_cleanup:e}),colorClass:`text-emerald-700 dark:text-emerald-300`}),e?.id&&$&&$.memory_count>0&&(0,R.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800/30`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-300`,children:a(`personaForm.memory.wipeAll`)}),(0,R.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:a(`personaForm.memory.wipeCannot`)})]}),(0,R.jsxs)(`button`,{type:`button`,onClick:ue,disabled:J,className:`px-3 py-1.5 bg-red-500 hover:bg-red-600 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50 flex items-center gap-1.5`,children:[J?(0,R.jsx)(c,{className:`h-3.5 w-3.5 animate-spin`}):(0,R.jsx)(h,{className:`h-3.5 w-3.5`}),a(J?`personaForm.memory.wiping`:`personaForm.memory.wipeButton`)]})]})})]}),!s.memory_settings?.enabled&&(0,R.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,R.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:a(`personaForm.memory.enableHint`)})})]}),(0,R.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-primary-200/50 dark:border-primary-700/30`,children:[(0,R.jsx)(`div`,{className:`px-5 py-4 bg-primary-600 dark:bg-primary-600`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,R.jsx)(w,{className:`h-5 w-5 text-white`})}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{className:`font-semibold text-white`,children:a(`personaForm.learning.title`)}),(0,R.jsx)(`p`,{className:`text-xs text-white/80`,children:a(`personaForm.learning.subtitle`)})]})]}),(0,R.jsx)(H,{label:``,checked:s.mutation_settings?.enabled||!1,onChange:e=>X(`mutation_settings`,{enabled:e})})]})}),s.mutation_settings?.enabled&&(0,R.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-5`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`block text-sm font-medium text-primary-700 dark:text-primary-300 mb-3`,children:a(`personaForm.learning.speed`)}),(0,R.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:[{level:`low`,icon:te,label:a(`personaForm.learning.slow`),desc:a(`personaForm.learning.slowDesc`)},{level:`medium`,icon:w,label:a(`personaForm.learning.balanced`),desc:a(`personaForm.learning.balancedDesc`)},{level:`high`,icon:T,label:a(`personaForm.learning.fast`),desc:a(`personaForm.learning.fastDesc`)}].map(({level:e,icon:t,label:n,desc:r})=>(0,R.jsxs)(`button`,{type:`button`,onClick:()=>X(`mutation_settings`,{sensitivity:e}),className:O(`p-3 rounded-xl text-center transition-all border`,s.mutation_settings?.sensitivity===e?`bg-primary-600 border-primary-600 text-white shadow-lg`:`bg-primary-50 dark:bg-primary-900/20 border-primary-200 dark:border-primary-700/30 text-primary-700 dark:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/30`),children:[(0,R.jsx)(t,{className:`h-5 w-5 mx-auto mb-1`}),(0,R.jsx)(`p`,{className:`text-sm font-medium`,children:n}),(0,R.jsx)(`p`,{className:`text-[10px] opacity-70`,children:r})]},e))})]}),(0,R.jsx)(H,{label:a(`personaForm.learning.autoAdapt`),checked:s.mutation_settings.auto_adapt,onChange:e=>X(`mutation_settings`,{auto_adapt:e}),colorClass:`text-primary-700 dark:text-primary-300`}),(0,R.jsxs)(`div`,{className:`p-4 bg-primary-50 dark:bg-primary-900/20 rounded-xl`,children:[(0,R.jsxs)(`p`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300 mb-2 flex items-center gap-1.5`,children:[(0,R.jsx)(l,{className:`h-3.5 w-3.5`}),a(`personaForm.learning.whatLearns`)]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs text-primary-600 dark:text-primary-400`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),a(`personaForm.learning.conversationTone`)]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),a(`personaForm.learning.responseStyle`)]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),a(`personaForm.learning.userPreferences`)]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),a(`personaForm.learning.topicInterests`)]})]})]})]}),!s.mutation_settings?.enabled&&(0,R.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,R.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:a(`personaForm.learning.enableHint`)})})]})]}),K===`advanced`&&(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsxs)(`div`,{className:`rounded-xl p-5 bg-gradient-to-br from-primary-50 to-primary-100/50 dark:from-primary-900/30 dark:to-primary-800/20 border border-primary-200/50 dark:border-primary-700/30`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,R.jsx)(_,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}),(0,R.jsx)(`h3`,{className:`font-semibold text-primary-900 dark:text-primary-100`,children:a(`personaForm.advanced.embeddingModel`)})]}),(0,R.jsx)(`p`,{className:`text-xs text-primary-600 dark:text-primary-400 mb-3`,children:a(`personaForm.advanced.embeddingHint`)}),(0,R.jsx)(`select`,{value:s.embedding_model,onChange:e=>Y(`embedding_model`,e.target.value),className:`w-full px-3 py-2.5 border border-primary-200 dark:border-primary-700 rounded-lg bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800 focus:ring-2 focus:ring-primary-500/20`,children:m.length===0?(0,R.jsx)(`option`,{value:``,disabled:!0,children:a(`personaForm.advanced.noModels`)}):(0,R.jsxs)(R.Fragment,{children:[m.filter(e=>e.isDetectedEmbedding).length>0&&(0,R.jsx)(`optgroup`,{label:a(`personaForm.advanced.embeddingModels`),children:m.filter(e=>e.isDetectedEmbedding).map(e=>(0,R.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))}),m.filter(e=>!e.isDetectedEmbedding).length>0&&(0,R.jsx)(`optgroup`,{label:a(`personaForm.advanced.otherModels`),children:m.filter(e=>!e.isDetectedEmbedding).map(e=>(0,R.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))})]})}),m.length===0&&(0,R.jsx)(`div`,{className:`mt-3 p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700/50 rounded-lg`,children:(0,R.jsxs)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:[a(`personaForm.advanced.installHint`),` `,(0,R.jsx)(`code`,{className:`px-1.5 py-0.5 bg-amber-100 dark:bg-amber-900/40 rounded text-xs`,children:`ollama pull nomic-embed-text`})]})}),(0,R.jsx)(`p`,{className:`text-[10px] text-primary-500 dark:text-primary-500 mt-2`,children:a(`personaForm.advanced.recommended`)})]}),(0,R.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300`,children:(0,R.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,R.jsx)(C,{className:`h-5 w-5 text-gray-400 mt-0.5 flex-shrink-0`}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:a(`personaForm.advanced.aboutTitle`)}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:a(`personaForm.advanced.aboutDescription`)})]})]})})]})]})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(F,{type:`button`,variant:`ghost`,onClick:n,disabled:b,className:`text-gray-600 dark:text-gray-400`,children:a(`personaForm.actions.cancel`)}),(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[W&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,R.jsx)(r,{className:`h-4 w-4`}),(0,R.jsx)(`span`,{children:a(`personaForm.saved`)})]}),(0,R.jsx)(F,{type:`button`,variant:`outline`,onClick:()=>de(!1),disabled:b,children:a(b&&!S?`personaForm.actions.saving`:`personaForm.actions.save`)}),(0,R.jsx)(F,{type:`button`,onClick:()=>de(!0),disabled:b,children:a(b&&S?`personaForm.actions.saving`:e?`personaForm.actions.saveClose`:`personaForm.actions.create`)})]})]})]})]})},G=({personas:e,onImport:t,onClose:n})=>{let{t:r}=P(),[i,a]=(0,L.useState)(!1),[s,c]=(0,L.useState)(``),l=async e=>{try{let t=await M.exportPersona(e.id),n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=`${e.name}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),o.success(r(`personaImportExport.exportSuccess`,{name:e.name}))}catch(e){let t=e instanceof Error?e.message:String(e);o.error(r(`personaImportExport.exportFailed`)+`: `+t)}};return(0,R.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,R.jsxs)(`div`,{className:`mb-6`,children:[(0,R.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:r(`personaImportExport.title`)}),(0,R.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:r(`personaImportExport.description`)})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,R.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.exportPersonas`)}),e.length===0?(0,R.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 text-center py-8`,children:r(`personaImportExport.noPersonasToExport`)}):(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,R.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:r(`personaImportExport.personasAvailable`,{count:e.length})}),(0,R.jsx)(F,{onClick:async()=>{try{let t=e.map(e=>M.exportPersona(e.id)),n=await Promise.all(t),i={personas:n,exportedAt:Date.now(),version:`1.0.0`,count:n.length},a=new Blob([JSON.stringify(i,null,2)],{type:`application/json`}),s=URL.createObjectURL(a),c=document.createElement(`a`);c.href=s,c.download=`personas-export-${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(s),o.success(r(`personaImportExport.exportAllSuccess`,{count:e.length}))}catch(e){let t=e instanceof Error?e.message:String(e);o.error(r(`personaImportExport.exportAllFailed`)+`: `+t)}},variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`personaImportExport.exportAll`)})]}),(0,R.jsx)(`div`,{className:`space-y-2 max-h-80 overflow-y-auto`,children:e.map(e=>(0,R.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(`img`,{src:e.avatar||`https://ui-avatars.com/api/?name=${encodeURIComponent(e.name)}&background=6366f1&color=fff&size=32`,alt:e.name,className:`w-8 h-8 rounded-full`}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),(0,R.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:e.model})]})]}),(0,R.jsx)(F,{onClick:()=>l(e),variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`common.export`)})]},e.id))})]})]}),(0,R.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.importPersonas`)}),(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.uploadJsonFile`)}),(0,R.jsx)(`input`,{type:`file`,accept:`.json`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{let t=e.target?.result;typeof t==`string`&&c(t)},e.readAsText(t)}},className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`})]}),(0,R.jsx)(`div`,{className:`text-center text-gray-500 dark:text-dark-500`,children:r(`common.or`).toUpperCase()}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.pasteJsonLabel`)}),(0,R.jsx)(`textarea`,{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 bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-700`,rows:8,placeholder:r(`personaImportExport.pasteJsonPlaceholder`)})]}),(0,R.jsx)(F,{onClick:async()=>{if(!s.trim()){o.error(r(`personaImportExport.pasteJsonData`));return}a(!0);try{let e=JSON.parse(s);if(e.personas&&Array.isArray(e.personas)){let t=0,n=0;for(let r of e.personas)try{await M.importPersona(r),t++}catch(e){n++,console.error(`Failed to import persona:`,e)}t>0?(o.success(r(`personaImportExport.importMultipleSuccess`,{count:t})),n>0&&o.error(r(`personaImportExport.importMultipleFailed`,{count:n}))):o.error(r(`personaImportExport.importNoneFailed`))}else await M.importPersona(e),o.success(r(`personaImportExport.importSuccess`));c(``),t()}catch(e){let t=e instanceof Error?e.message:String(e);o.error(r(`personaImportExport.importFailed`)+`: `+t)}finally{a(!1)}},disabled:!s.trim()||i,className:`w-full`,children:r(i?`personaImportExport.importing`:`personaImportExport.importButton`)})]})]})]}),(0,R.jsxs)(`div`,{className:`mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4`,children:[(0,R.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-dark-800 mb-2`,children:r(`personaImportExport.expectedFormat`)}),(0,R.jsx)(`pre`,{className:`text-xs text-gray-600 dark:text-dark-600 overflow-x-auto`,children:`{
2
- "name": "Assistant Name",
3
- "description": "Brief description of the assistant's personality",
4
- "model": "model-name:version",
5
- "params": {
6
- "temperature": 0.8,
7
- "top_p": 0.9,
8
- "context_window": 4096,
9
- "system_prompt": "You are a helpful assistant with specific traits..."
10
- },
11
- "avatar": "/path/to/avatar.png",
12
- "background": "/path/to/background.png"
13
- }`})]}),(0,R.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,R.jsx)(F,{onClick:n,variant:`outline`,children:r(`common.close`)})})]})},K=()=>{let{t:e}=P(),t=N(),[n,r]=(0,L.useState)(!1),[i,a]=(0,L.useState)(null),[s,c]=(0,L.useState)(!1),{data:l=[],isLoading:u,refetch:d}=I({queryKey:[`personas`],queryFn:async()=>{let e=await M.getPersonas();if(!e.success)throw Error(e.error||`Failed to load personas`);return e.data||[]}}),f=async()=>{await t.invalidateQueries({queryKey:[`personas`]}),await d()},p=()=>{a(null),r(!0)},m=e=>{a(e),r(!0)},h=async t=>{if(confirm(e(`personaManager.deleteConfirm`,{name:t.name})))try{let n=await M.deletePersona(t.id);n.success?(o.success(e(`personaManager.deleteSuccess`,{name:t.name})),await f()):o.error(e(`personaManager.failed`,{action:`delete`})+`: `+n.error)}catch(t){let n=t instanceof Error?t.message:String(t);o.error(e(`personaManager.failed`,{action:`delete`})+`: `+n)}},g=async t=>{try{await M.downloadPersona(t.id,t.name),o.success(e(`personaManager.downloadSuccess`,{name:t.name}))}catch(t){let n=t instanceof Error?t.message:String(t);o.error(e(`personaManager.failed`,{action:`download`})+`: `+n)}};return u?(0,R.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,R.jsx)(`div`,{className:`text-gray-600 dark:text-dark-600`,children:e(`personaManager.loading`)})}):n?(0,R.jsx)(W,{persona:i,onSubmit:async()=>{r(!1),a(null),await f()},onCancel:()=>{r(!1),a(null)}}):s?(0,R.jsx)(G,{personas:l,onImport:f,onClose:()=>c(!1)}):(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:e(`personaManager.title`)}),(0,R.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:e(`personaManager.subtitle`)})]}),(0,R.jsxs)(`div`,{className:`flex gap-3`,children:[(0,R.jsx)(F,{onClick:()=>c(!0),variant:`outline`,className:`px-4 py-2`,children:e(`personaManager.importExport`)}),(0,R.jsx)(F,{onClick:p,className:`px-4 py-2`,children:e(`personaManager.createButton`)})]})]}),(0,R.jsx)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-dark-300`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`personaManager.stats.title`)}),(0,R.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600`,children:e(`personaManager.stats.count`,{count:l.length})})]}),(0,R.jsx)(`div`,{className:`text-3xl font-bold text-gray-900 dark:text-dark-800`,children:l.length})]})}),l.length===0?(0,R.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg p-12 shadow-sm border border-gray-200 dark:border-dark-300 text-center`,children:[(0,R.jsx)(`div`,{className:`text-gray-400 dark:text-dark-500 mb-4`,children:(0,R.jsx)(`svg`,{className:`w-16 h-16 mx-auto`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,xmlns:`http://www.w3.org/2000/svg`,children:(0,R.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z`})})}),(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-2`,children:e(`personaManager.empty.title`)}),(0,R.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mb-6`,children:e(`personaManager.empty.description`)}),(0,R.jsx)(F,{onClick:p,className:`px-6 py-2`,children:e(`personaManager.empty.button`)})]}):(0,R.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:l.map(e=>(0,R.jsx)(z,{persona:e,onEdit:m,onDelete:h,onDownload:g},e.id))})]})},q=()=>{let{t:e}=P();return(0,R.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,R.jsxs)(`div`,{className:`max-w-6xl mx-auto p-6`,children:[(0,R.jsxs)(`div`,{className:`text-center max-w-md mx-auto mb-8`,children:[(0,R.jsx)(`h2`,{className:`libre-brand text-4xl sm:text-5xl font-normal text-gray-900 dark:text-dark-800 mb-3`,style:{fontWeight:300,letterSpacing:`0.01em`},children:e(`personaManager.title`)}),(0,R.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 leading-relaxed`,children:e(`personaManager.subtitle`)})]}),(0,R.jsx)(K,{})]})})};export{q as PersonasPage,q as default};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{m as t,p as n}from"./markdown-vendor-DLzJCMRQ.js";import{A as r,It as i,_ as a,b as o,d as s,o as c}from"./ui-vendor-ClcVY3m-.js";import{p as l}from"./api-MQ7bONaU.js";import{n as u}from"./authStore-Cn_WS6Kb.js";import{a as d,b as f,f as p,i as m,m as h,n as g,o as _,p as v,r as y,s as b,v as x}from"../assets/index-cOuIFv6G.js";var S=e(t(),1),C=n(),w=()=>{let{t:e}=h(),t=f(),[n,w]=(0,S.useState)(!1),[T,E]=(0,S.useState)(null),[D,O]=(0,S.useState)({username:``,email:``,password:``,role:`user`}),{user:k}=u(),{data:A=[],isLoading:j}=x({queryKey:[`users`],queryFn:async()=>{let t=await l.getUsers();if(!t.success||!t.data)throw Error(e(`errors.generic`));return t.data}}),M=()=>t.invalidateQueries({queryKey:[`users`]}),N=async t=>{t.preventDefault();try{let t=await l.createUser(D);t.success&&t.data&&(await M(),O({username:``,email:``,password:``,role:`user`}),w(!1),i.success(e(`userManager.form.createSuccess`)))}catch(t){console.error(`Error creating user:`,t);let n=e(`userManager.form.createFailed`);t instanceof Error&&`response`in t&&(n=t.response?.data?.message||e(`userManager.form.createFailed`)),i.error(n)}},P=async t=>{if(t.preventDefault(),T)try{let t={username:D.username,email:D.email,role:D.role};D.password&&D.password.trim()!==``&&(t.password=D.password);let n=await l.updateUser(T.id,t);n.success&&n.data&&(await M(),E(null),O({username:``,email:``,password:``,role:`user`}),i.success(e(`userManager.form.updateSuccess`)))}catch(t){console.error(`Error updating user:`,t);let n=e(`userManager.form.updateFailed`);t instanceof Error&&`response`in t&&(n=t.response?.data?.message||e(`userManager.form.updateFailed`)),i.error(n)}},F=async(t,n)=>{if(confirm(e(`userManager.deleteConfirm`,{name:n})))try{(await l.deleteUser(t)).success&&(await M(),i.success(e(`userManager.deleteSuccess`)))}catch(t){console.error(`Error deleting user:`,t);let n=e(`userManager.deleteFailed`);t instanceof Error&&`response`in t&&(n=t.response?.data?.message||e(`userManager.deleteFailed`)),i.error(n)}},I=e=>{E(e),O({username:e.username,email:e.email||``,password:``,role:e.role})};return j?(0,C.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,C.jsx)(`div`,{className:`w-8 h-8 border-4 border-gray-200 dark:border-gray-600 border-t-primary-500 rounded-full animate-spin`})}):(0,C.jsxs)(`div`,{className:`space-y-6`,children:[(0,C.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,C.jsx)(`div`,{}),(0,C.jsxs)(v,{onClick:()=>w(!n),className:`flex items-center space-x-2 bg-primary-600 hover:bg-primary-700 dark:bg-primary-500 dark:hover:bg-primary-600`,children:[(0,C.jsx)(r,{size:16}),(0,C.jsx)(`span`,{children:e(`userManager.createUser`)})]})]}),n&&(0,C.jsxs)(g,{className:`bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg`,children:[(0,C.jsxs)(d,{children:[(0,C.jsx)(_,{className:`text-gray-900 dark:text-gray-100`,children:e(`userManager.form.title.create`)}),(0,C.jsx)(m,{className:`text-gray-600 dark:text-gray-400`,children:e(`userManager.subtitle`)})]}),(0,C.jsx)(y,{children:(0,C.jsxs)(`form`,{onSubmit:N,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(b,{htmlFor:`username`,className:`text-gray-700 dark:text-gray-300`,children:e(`userManager.form.username`)}),(0,C.jsx)(p,{id:`username`,value:D.username,onChange:e=>O({...D,username:e.target.value}),required:!0,className:`bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(b,{htmlFor:`email`,className:`text-gray-700 dark:text-gray-300`,children:e(`userManager.form.email`)}),(0,C.jsx)(p,{id:`email`,type:`email`,value:D.email,onChange:e=>O({...D,email:e.target.value}),required:!0,className:`bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100`})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(b,{htmlFor:`password`,className:`text-gray-700 dark:text-gray-300`,children:e(`userManager.form.password`)}),(0,C.jsx)(p,{id:`password`,type:`password`,value:D.password,onChange:e=>O({...D,password:e.target.value}),required:!0,className:`bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(b,{htmlFor:`role`,className:`text-gray-700 dark:text-gray-300`,children:e(`userManager.form.role`)}),(0,C.jsxs)(`select`,{id:`role`,value:D.role,onChange:e=>O({...D,role:e.target.value}),className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 bg-white dark:bg-dark-100 text-gray-900 dark:text-gray-100 transition-colors duration-200`,children:[(0,C.jsx)(`option`,{value:`user`,children:e(`userManager.roles.user`)}),(0,C.jsx)(`option`,{value:`admin`,children:e(`userManager.roles.admin`)})]})]})]}),(0,C.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,C.jsx)(v,{type:`submit`,children:e(`userManager.form.createButton`)}),(0,C.jsx)(v,{type:`button`,variant:`outline`,onClick:()=>{O({username:``,email:``,password:``,role:`user`}),w(!1)},children:e(`common.cancel`)})]})]})})]}),T&&(0,C.jsxs)(g,{className:`bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg`,children:[(0,C.jsxs)(d,{children:[(0,C.jsxs)(_,{className:`text-gray-900 dark:text-gray-100`,children:[e(`userManager.form.title.edit`),`: `,T.username]}),(0,C.jsx)(m,{className:`text-gray-600 dark:text-gray-400`,children:e(`userManager.subtitle`)})]}),(0,C.jsx)(y,{children:(0,C.jsxs)(`form`,{onSubmit:P,className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(b,{htmlFor:`edit-username`,className:`text-gray-700 dark:text-gray-300`,children:e(`userManager.form.username`)}),(0,C.jsx)(p,{id:`edit-username`,value:D.username,onChange:e=>O({...D,username:e.target.value}),required:!0,className:`bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(b,{htmlFor:`edit-email`,className:`text-gray-700 dark:text-gray-300`,children:e(`userManager.form.email`)}),(0,C.jsx)(p,{id:`edit-email`,type:`email`,value:D.email,onChange:e=>O({...D,email:e.target.value}),required:!0,className:`bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100`})]})]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(b,{htmlFor:`edit-password`,className:`text-gray-700 dark:text-gray-300`,children:[e(`userManager.form.password`),` (`,e(`common.optional`),`)`]}),(0,C.jsx)(p,{id:`edit-password`,type:`password`,value:D.password,onChange:e=>O({...D,password:e.target.value}),placeholder:e(`userManager.form.passwordHint`),className:`bg-white dark:bg-dark-100 border-gray-300 dark:border-dark-300 text-gray-900 dark:text-gray-100`})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(b,{htmlFor:`edit-role`,className:`text-gray-700 dark:text-gray-300`,children:e(`userManager.form.role`)}),(0,C.jsxs)(`select`,{id:`edit-role`,value:D.role,onChange:e=>O({...D,role:e.target.value}),disabled:T?.id===k?.id&&k?.role===`admin`,className:`w-full px-3 py-2 border border-gray-300 dark:border-dark-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 bg-white dark:bg-dark-100 text-gray-900 dark:text-gray-100 transition-colors duration-200 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,C.jsx)(`option`,{value:`user`,children:e(`userManager.roles.user`)}),(0,C.jsx)(`option`,{value:`admin`,children:e(`userManager.roles.admin`)})]}),T?.id===k?.id&&k?.role===`admin`&&(0,C.jsx)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400 mt-1`,children:e(`userManager.cannotDeleteSelf`)})]})]}),(0,C.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,C.jsx)(v,{type:`submit`,children:e(`userManager.form.updateButton`)}),(0,C.jsx)(v,{type:`button`,variant:`outline`,onClick:()=>{E(null),O({username:``,email:``,password:``,role:`user`})},children:e(`common.cancel`)})]})]})})]}),(0,C.jsxs)(g,{className:`bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-200 shadow-lg`,children:[(0,C.jsxs)(d,{children:[(0,C.jsxs)(_,{className:`text-gray-900 dark:text-gray-100`,children:[e(`userManager.title`),` (`,A.length,`)`]}),(0,C.jsx)(m,{className:`text-gray-600 dark:text-gray-400`,children:e(`userManager.subtitle`)})]}),(0,C.jsx)(y,{children:(0,C.jsx)(`div`,{className:`space-y-3`,children:A.map(t=>(0,C.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-300`,children:[(0,C.jsxs)(`div`,{className:`flex items-center space-x-3`,children:[(0,C.jsx)(`div`,{className:`p-2 bg-primary-100 dark:bg-primary-900/20 rounded-lg`,children:t.role===`admin`?(0,C.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}):(0,C.jsx)(c,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100`,children:[t.username,t.id===k?.id&&(0,C.jsxs)(`span`,{className:`ml-2 text-xs text-primary-600 dark:text-primary-400 font-normal`,children:[`(`,e(`chatMessage.you`),`)`]})]}),(0,C.jsxs)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:[t.email||e(`userManager.noEmail`),` •`,` `,t.role===`admin`?e(`userManager.roles.admin`):e(`userManager.roles.user`)]}),(0,C.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-500`,children:[e(`userManager.columns.created`),`:`,` `,new Date(t.createdAt).toLocaleDateString()]})]})]}),(0,C.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,C.jsx)(v,{variant:`outline`,size:`sm`,onClick:()=>I(t),className:`text-gray-600 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400`,children:(0,C.jsx)(a,{size:16})}),(0,C.jsx)(v,{variant:`outline`,size:`sm`,onClick:()=>F(t.id,t.username),disabled:t.id===k?.id,className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,C.jsx)(s,{size:16})})]})]},t.id))})})]})]})},T=()=>{let{t:e}=h();return(0,C.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,C.jsxs)(`div`,{className:`max-w-6xl mx-auto p-6`,children:[(0,C.jsxs)(`div`,{className:`mb-8`,children:[(0,C.jsx)(`h1`,{className:`text-3xl font-bold text-gray-900 dark:text-gray-100 mb-2`,children:e(`userManager.title`)}),(0,C.jsx)(`p`,{className:`text-gray-700 dark:text-gray-300`,children:e(`userManager.pageDescription`)})]}),(0,C.jsx)(w,{})]})})};export{T as UserManagementPage,T as default};