libre-webui 0.29.0 → 0.31.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 (261) hide show
  1. package/backend/dist/index.d.ts.map +1 -1
  2. package/backend/dist/index.js +24 -7
  3. package/backend/dist/index.js.map +1 -1
  4. package/backend/dist/persistence/postgresAutomationWebhooksMigration.d.ts +9 -0
  5. package/backend/dist/persistence/postgresAutomationWebhooksMigration.d.ts.map +1 -0
  6. package/backend/dist/persistence/postgresAutomationWebhooksMigration.js +38 -0
  7. package/backend/dist/persistence/postgresAutomationWebhooksMigration.js.map +1 -0
  8. package/backend/dist/persistence/postgresMigrationRegistry.d.ts.map +1 -1
  9. package/backend/dist/persistence/postgresMigrationRegistry.js +4 -0
  10. package/backend/dist/persistence/postgresMigrationRegistry.js.map +1 -1
  11. package/backend/dist/persistence/postgresResourceRepositories.d.ts.map +1 -1
  12. package/backend/dist/persistence/postgresResourceRepositories.js +5 -0
  13. package/backend/dist/persistence/postgresResourceRepositories.js.map +1 -1
  14. package/backend/dist/persistence/postgresWorkApprovalsMigration.d.ts +13 -0
  15. package/backend/dist/persistence/postgresWorkApprovalsMigration.d.ts.map +1 -0
  16. package/backend/dist/persistence/postgresWorkApprovalsMigration.js +69 -0
  17. package/backend/dist/persistence/postgresWorkApprovalsMigration.js.map +1 -0
  18. package/backend/dist/persistence/resourceTypes.d.ts +4 -0
  19. package/backend/dist/persistence/resourceTypes.d.ts.map +1 -1
  20. package/backend/dist/persistence/resourceTypes.js.map +1 -1
  21. package/backend/dist/persistence/sqliteMigrations.d.ts +3 -0
  22. package/backend/dist/persistence/sqliteMigrations.d.ts.map +1 -1
  23. package/backend/dist/persistence/sqliteMigrations.js +156 -2
  24. package/backend/dist/persistence/sqliteMigrations.js.map +1 -1
  25. package/backend/dist/persistence/sqliteResourceRepositories.d.ts.map +1 -1
  26. package/backend/dist/persistence/sqliteResourceRepositories.js +7 -0
  27. package/backend/dist/persistence/sqliteResourceRepositories.js.map +1 -1
  28. package/backend/dist/persistence/sqliteToPostgresMigration.d.ts.map +1 -1
  29. package/backend/dist/persistence/sqliteToPostgresMigration.js +32 -1
  30. package/backend/dist/persistence/sqliteToPostgresMigration.js.map +1 -1
  31. package/backend/dist/platform/workPersistence/postgresWorkPersistence.d.ts +10 -1
  32. package/backend/dist/platform/workPersistence/postgresWorkPersistence.d.ts.map +1 -1
  33. package/backend/dist/platform/workPersistence/postgresWorkPersistence.js +85 -5
  34. package/backend/dist/platform/workPersistence/postgresWorkPersistence.js.map +1 -1
  35. package/backend/dist/platform/workPersistence/sqliteWorkPersistence.d.ts +10 -1
  36. package/backend/dist/platform/workPersistence/sqliteWorkPersistence.d.ts.map +1 -1
  37. package/backend/dist/platform/workPersistence/sqliteWorkPersistence.js +67 -7
  38. package/backend/dist/platform/workPersistence/sqliteWorkPersistence.js.map +1 -1
  39. package/backend/dist/platform/workPersistence/types.d.ts +37 -0
  40. package/backend/dist/platform/workPersistence/types.d.ts.map +1 -1
  41. package/backend/dist/platform/workPersistence/types.js.map +1 -1
  42. package/backend/dist/routes/automations.d.ts.map +1 -1
  43. package/backend/dist/routes/automations.js +83 -1
  44. package/backend/dist/routes/automations.js.map +1 -1
  45. package/backend/dist/routes/ollama.d.ts.map +1 -1
  46. package/backend/dist/routes/ollama.js +64 -0
  47. package/backend/dist/routes/ollama.js.map +1 -1
  48. package/backend/dist/routes/plugins.d.ts.map +1 -1
  49. package/backend/dist/routes/plugins.js +90 -0
  50. package/backend/dist/routes/plugins.js.map +1 -1
  51. package/backend/dist/routes/work.d.ts.map +1 -1
  52. package/backend/dist/routes/work.js +83 -0
  53. package/backend/dist/routes/work.js.map +1 -1
  54. package/backend/dist/services/authService.d.ts +2 -0
  55. package/backend/dist/services/authService.d.ts.map +1 -1
  56. package/backend/dist/services/authService.js +2 -0
  57. package/backend/dist/services/authService.js.map +1 -1
  58. package/backend/dist/services/automationService.d.ts +13 -1
  59. package/backend/dist/services/automationService.d.ts.map +1 -1
  60. package/backend/dist/services/automationService.js +31 -0
  61. package/backend/dist/services/automationService.js.map +1 -1
  62. package/backend/dist/services/notificationService.d.ts.map +1 -1
  63. package/backend/dist/services/notificationService.js +1 -0
  64. package/backend/dist/services/notificationService.js.map +1 -1
  65. package/backend/dist/services/ollamaService.d.ts +12 -0
  66. package/backend/dist/services/ollamaService.d.ts.map +1 -1
  67. package/backend/dist/services/ollamaService.js +26 -0
  68. package/backend/dist/services/ollamaService.js.map +1 -1
  69. package/backend/dist/services/ollamaSettingsService.d.ts +10 -0
  70. package/backend/dist/services/ollamaSettingsService.d.ts.map +1 -0
  71. package/backend/dist/services/ollamaSettingsService.js +83 -0
  72. package/backend/dist/services/ollamaSettingsService.js.map +1 -0
  73. package/backend/dist/services/workAgentGuidance.d.ts +11 -0
  74. package/backend/dist/services/workAgentGuidance.d.ts.map +1 -1
  75. package/backend/dist/services/workAgentGuidance.js +16 -2
  76. package/backend/dist/services/workAgentGuidance.js.map +1 -1
  77. package/backend/dist/services/workAgentService.d.ts +56 -0
  78. package/backend/dist/services/workAgentService.d.ts.map +1 -1
  79. package/backend/dist/services/workAgentService.js +467 -17
  80. package/backend/dist/services/workAgentService.js.map +1 -1
  81. package/backend/dist/services/workApprovalService.d.ts +67 -0
  82. package/backend/dist/services/workApprovalService.d.ts.map +1 -0
  83. package/backend/dist/services/workApprovalService.js +273 -0
  84. package/backend/dist/services/workApprovalService.js.map +1 -0
  85. package/backend/dist/services/workEventService.d.ts.map +1 -1
  86. package/backend/dist/services/workEventService.js +25 -0
  87. package/backend/dist/services/workEventService.js.map +1 -1
  88. package/backend/dist/services/workPolicyService.d.ts +4 -0
  89. package/backend/dist/services/workPolicyService.d.ts.map +1 -1
  90. package/backend/dist/services/workPolicyService.js +19 -0
  91. package/backend/dist/services/workPolicyService.js.map +1 -1
  92. package/backend/dist/services/workRuntimeShared.d.ts +2 -0
  93. package/backend/dist/services/workRuntimeShared.d.ts.map +1 -1
  94. package/backend/dist/services/workRuntimeShared.js.map +1 -1
  95. package/backend/dist/services/workTaskService.d.ts +3 -1
  96. package/backend/dist/services/workTaskService.d.ts.map +1 -1
  97. package/backend/dist/services/workTaskService.js +21 -4
  98. package/backend/dist/services/workTaskService.js.map +1 -1
  99. package/backend/dist/types/index.d.ts +3 -1
  100. package/backend/dist/types/index.d.ts.map +1 -1
  101. package/backend/dist/types/index.js.map +1 -1
  102. package/backend/dist/types/work.d.ts +32 -11
  103. package/backend/dist/types/work.d.ts.map +1 -1
  104. package/backend/dist/websocketServer.d.ts.map +1 -1
  105. package/backend/dist/websocketServer.js +14 -2
  106. package/backend/dist/websocketServer.js.map +1 -1
  107. package/backend/package.json +2 -2
  108. package/deploy/work-computer/Dockerfile +1 -0
  109. package/deploy/work-computer/tint2rc +1 -0
  110. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  111. package/frontend/dist/artifact-runtime/lucide-react.js +1 -1
  112. package/frontend/dist/artifact-runtime/mermaid.js +8 -8
  113. package/frontend/dist/artifact-runtime/papaparse.js +2 -2
  114. package/frontend/dist/artifact-runtime/plotly.js +371 -652
  115. package/frontend/dist/assets/index-B6xMZpzA.js +76 -0
  116. package/frontend/dist/assets/index-BjipfsCP.css +1 -0
  117. package/frontend/dist/index.html +28 -28
  118. package/frontend/dist/js/{ArtifactContainer-CTXxnWRo.js → ArtifactContainer-Bn6iJtaJ.js} +1 -1
  119. package/frontend/dist/js/{ArtifactDemoPage-CEYuIhJA.js → ArtifactDemoPage-BLF8Ok-o.js} +1 -1
  120. package/frontend/dist/js/{ArtifactSandboxFrame-DLOy2VOm.js → ArtifactSandboxFrame-Cs1Gu1WB.js} +1 -1
  121. package/frontend/dist/js/{ArtifactSlideOutPanel-DnTTc1VY.js → ArtifactSlideOutPanel-CuKq5cL0.js} +1 -1
  122. package/frontend/dist/js/AutomationModal-Dha4KgLI.js +1 -0
  123. package/frontend/dist/js/AutomationsPage-HcMCRV-D.js +1 -0
  124. package/frontend/dist/js/{AvatarUpload-DzL00yOL.js → AvatarUpload-CFrlSszY.js} +1 -1
  125. package/frontend/dist/js/{Button--pDOakZx.js → Button-CgN11mgY.js} +1 -1
  126. package/frontend/dist/js/{CalendarPage-Bls3TBeZ.js → CalendarPage-D_K-XrG9.js} +1 -1
  127. package/frontend/dist/js/ChannelsPage-D3CoImOT.js +1 -0
  128. package/frontend/dist/js/ChatPage-C0iBDbOq.js +14 -0
  129. package/frontend/dist/js/ConnectModels-D_ZbZQub.js +1 -0
  130. package/frontend/dist/js/{EvaluationsPage-DSgj9dT5.js → EvaluationsPage-DOJLpauA.js} +2 -2
  131. package/frontend/dist/js/FirstTimeSetup-DDIP_4Dd.js +1 -0
  132. package/frontend/dist/js/GalleryPage-C8U_F7Ns.js +1 -0
  133. package/frontend/dist/js/{HomePage-BebX3v-x.js → HomePage-B_aotoDU.js} +1 -1
  134. package/frontend/dist/js/LibreClawPage-cr2N6W00.js +1 -0
  135. package/frontend/dist/js/{Logo-BE9SvCC5.js → Logo-B7o7eaPU.js} +1 -1
  136. package/frontend/dist/js/{LogoMark-C8x1yyP3.js → LogoMark-D9g6ls0h.js} +1 -1
  137. package/frontend/dist/js/{ModelManagerModals-CpWAltRA.js → ModelManagerModals-C-J1d7GL.js} +1 -1
  138. package/frontend/dist/js/NotesPage-Bgr7R_Vm.js +3 -0
  139. package/frontend/dist/js/{PasswordStrengthMeter-Cdq2oQbc.js → PasswordStrengthMeter-DR-mGbLF.js} +1 -1
  140. package/frontend/dist/js/PersonasPage-C3D_6lIx.js +13 -0
  141. package/frontend/dist/js/{PluginUsagePage-jMrpL2Jb.js → PluginUsagePage-DK7MgSiu.js} +1 -1
  142. package/frontend/dist/js/RichMessageContent-7FxrZ4A8.js +1 -0
  143. package/frontend/dist/js/{RichMessageContent-CC9QZQKd.js → RichMessageContent-CQkLI7Dt.js} +1 -1
  144. package/frontend/dist/js/SettingsModal-CIV_Bgsf.js +19 -0
  145. package/frontend/dist/js/{SettingsToggle-C16gtVyi.js → SettingsToggle-Cw4OhW7B.js} +1 -1
  146. package/frontend/dist/js/ShareDialog-BCEVgtbN.js +1 -0
  147. package/frontend/dist/js/{SystemPage-Drd1neLN.js → SystemPage-BNVZtLe9.js} +1 -1
  148. package/frontend/dist/js/{UserManagementPage-CquciWKV.js → UserManagementPage-pPC_Svj9.js} +1 -1
  149. package/frontend/dist/js/WorkPage-Q33nIqkM.js +7 -0
  150. package/frontend/dist/js/{api-2DulPtq1.js → api-D-5hpGht.js} +3 -3
  151. package/frontend/dist/js/api-WR1CTYO5.js +1 -0
  152. package/frontend/dist/js/{appNavigation-DAGh98Yj.js → appNavigation-DfHbXBey.js} +1 -1
  153. package/frontend/dist/js/{appStore-Ci1X0yA-.js → appStore-B136FGdu.js} +2 -2
  154. package/frontend/dist/js/appVersion-Ck7dYiHe.js +1 -0
  155. package/frontend/dist/js/ar-Cq-nC6v9.js +2 -0
  156. package/frontend/dist/js/authStore-6AJLgQsD.js +1 -0
  157. package/frontend/dist/js/authStore-Ckz37pwu.js +4 -0
  158. package/frontend/dist/js/axios-CUerAKcc.js +1 -0
  159. package/frontend/dist/js/{babel-D7QYvEns.js → babel-8afoxhZ7.js} +1 -1
  160. package/frontend/dist/js/bn-BFSKytYs.js +2 -0
  161. package/frontend/dist/js/chatStore-Dpm3g_Ln.js +3 -0
  162. package/frontend/dist/js/classPrivateMethodInitSpec-DE0XIqc_.js +1 -0
  163. package/frontend/dist/js/config-DJwXAf8i.js +1 -0
  164. package/frontend/dist/js/cs-BKWXa629.js +2 -0
  165. package/frontend/dist/js/da-Cra_DJnV.js +2 -0
  166. package/frontend/dist/js/de-BQa6_UuE.js +2 -0
  167. package/frontend/dist/js/es-BBOHFrx1.js +2 -0
  168. package/frontend/dist/js/{estree-D7xT4AeP.js → estree-qxY7ACbu.js} +3 -3
  169. package/frontend/dist/js/{evaluationsApi-Cu5PH_qi.js → evaluationsApi-BKY-maUM.js} +1 -1
  170. package/frontend/dist/js/fr-C8kXs5c0.js +2 -0
  171. package/frontend/dist/js/hi-BEef4bjU.js +2 -0
  172. package/frontend/dist/js/{html-HvA9vEyn.js → html-B_cUU1Gi.js} +2 -2
  173. package/frontend/dist/js/id-Djipic7Y.js +2 -0
  174. package/frontend/dist/js/is-pazl6RLG.js +2 -0
  175. package/frontend/dist/js/it-DobPbTwl.js +2 -0
  176. package/frontend/dist/js/ja-DwYNaMNX.js +2 -0
  177. package/frontend/dist/js/ko-BQfXE7_o.js +2 -0
  178. package/frontend/dist/js/{markdown-DaF0SXNk.js → markdown-BAF0w-jL.js} +3 -3
  179. package/frontend/dist/js/{messageCodeStyles-DKq3DH1W.js → messageCodeStyles-CkxF6yil.js} +2 -2
  180. package/frontend/dist/js/ms-CkPQoE5T.js +2 -0
  181. package/frontend/dist/js/nl-X_QsDAtu.js +2 -0
  182. package/frontend/dist/js/pl-CK39gUsy.js +2 -0
  183. package/frontend/dist/js/{postcss-RCIJRrFm.js → postcss-B2vYq4-H.js} +1 -1
  184. package/frontend/dist/js/pt-C0dWyR_I.js +2 -0
  185. package/frontend/dist/js/{router-vendor-BGP0k6Y2.js → router-vendor-CIwPu612.js} +1 -1
  186. package/frontend/dist/js/ru-sNJkEz1G.js +2 -0
  187. package/frontend/dist/js/{standalone-BMD7E0jY.js → standalone-BqZmfuRy.js} +2 -2
  188. package/frontend/dist/js/sv-Bh-uxdF3.js +2 -0
  189. package/frontend/dist/js/{teamEventStream-C4u_py2D.js → teamEventStream-DUodK0-C.js} +1 -1
  190. package/frontend/dist/js/th-DPVtwZj2.js +2 -0
  191. package/frontend/dist/js/tr-BYNM_Tm7.js +2 -0
  192. package/frontend/dist/js/{ttsBatching-C9kQXFB1.js → ttsBatching-7_-p2nxR.js} +1 -1
  193. package/frontend/dist/js/{typescript-LOiqVRM1.js → typescript-DokwN-5Y.js} +1 -1
  194. package/frontend/dist/js/{ui-DUzqxWMk.js → ui-BK53RPmS.js} +2 -2
  195. package/frontend/dist/js/ui-vendor-CPdYrKhz.js +177 -0
  196. package/frontend/dist/js/uk-kvNBuYin.js +2 -0
  197. package/frontend/dist/js/{useChat-6yDWZSTz.js → useChat-Czg2p4Rr.js} +1 -1
  198. package/frontend/dist/js/useDictation-B2lYEYKn.js +1 -0
  199. package/frontend/dist/js/useQuery-ClAiNxQ7.js +1 -0
  200. package/frontend/dist/js/{useTranslation-DrnYb6Cx.js → useTranslation-C7GwbUQA.js} +1 -1
  201. package/frontend/dist/js/{utils-D9UstwTG.js → utils-nNyg0lfc.js} +1 -1
  202. package/frontend/dist/js/utils-vendor-CeUf_ngc.js +9 -0
  203. package/frontend/dist/js/vi-CmLoaP0K.js +2 -0
  204. package/frontend/dist/js/workApi-BoJb9aVF.js +1 -0
  205. package/frontend/dist/js/{workApi-BwDBwG62.js → workApi-CFH097y5.js} +3 -3
  206. package/frontend/dist/js/{yaml-CyhEdlt2.js → yaml-BXEpxPn2.js} +2 -2
  207. package/frontend/dist/js/zh-D2zvmvrj.js +2 -0
  208. package/frontend/dist/sw.js +7 -1
  209. package/package.json +5 -5
  210. package/frontend/dist/assets/index-O8rtJINp.css +0 -1
  211. package/frontend/dist/assets/index-f1s6QpC5.js +0 -93
  212. package/frontend/dist/js/AutomationModal-DB3lrK2K.js +0 -1
  213. package/frontend/dist/js/AutomationsPage-D3v0Cra1.js +0 -1
  214. package/frontend/dist/js/ChannelsPage-BnoCniNf.js +0 -1
  215. package/frontend/dist/js/ChatPage-BMcigJWr.js +0 -14
  216. package/frontend/dist/js/FirstTimeSetup-BRysXCjP.js +0 -1
  217. package/frontend/dist/js/GalleryPage-DUcM4dg0.js +0 -1
  218. package/frontend/dist/js/LibreClawPage-A37KF9_G.js +0 -1
  219. package/frontend/dist/js/ModelSelector-C1ipX-44.js +0 -1
  220. package/frontend/dist/js/NotesPage-CXSz7Hde.js +0 -3
  221. package/frontend/dist/js/PersonasPage-CiOBffF3.js +0 -13
  222. package/frontend/dist/js/RichMessageContent-CU6WTuOs.js +0 -1
  223. package/frontend/dist/js/SettingsModal-DP_wKehV.js +0 -19
  224. package/frontend/dist/js/ShareDialog-BW8iGd_i.js +0 -1
  225. package/frontend/dist/js/WorkPage-BgASwAGs.js +0 -6
  226. package/frontend/dist/js/api-BmIdrQfK.js +0 -1
  227. package/frontend/dist/js/appVersion-BRMnr50t.js +0 -1
  228. package/frontend/dist/js/ar-CpmN0TY8.js +0 -2
  229. package/frontend/dist/js/authStore-DIvsSaOt.js +0 -4
  230. package/frontend/dist/js/authStore-DoxafXFR.js +0 -1
  231. package/frontend/dist/js/axios-C8xWfUG8.js +0 -1
  232. package/frontend/dist/js/bn-BwrMg_Oh.js +0 -2
  233. package/frontend/dist/js/chatStore-DkpmZLOG.js +0 -3
  234. package/frontend/dist/js/classPrivateMethodInitSpec-DUpGnGHL.js +0 -1
  235. package/frontend/dist/js/config-Ckn9cand.js +0 -1
  236. package/frontend/dist/js/cs-f72Fnxz3.js +0 -2
  237. package/frontend/dist/js/da-qp8lOgkJ.js +0 -2
  238. package/frontend/dist/js/de-CpcLHr97.js +0 -2
  239. package/frontend/dist/js/es-gZHsxjG4.js +0 -2
  240. package/frontend/dist/js/fr-BY5aUofi.js +0 -2
  241. package/frontend/dist/js/hi-KCn9gIiT.js +0 -2
  242. package/frontend/dist/js/id-C7U6kS0J.js +0 -2
  243. package/frontend/dist/js/is-N9Ek-Usz.js +0 -2
  244. package/frontend/dist/js/it-CqaqWB8D.js +0 -2
  245. package/frontend/dist/js/ja-C5f9HAm1.js +0 -2
  246. package/frontend/dist/js/ko-BuoboDvb.js +0 -2
  247. package/frontend/dist/js/ms-Cu-UWc6j.js +0 -2
  248. package/frontend/dist/js/nl-nOUc4C_i.js +0 -2
  249. package/frontend/dist/js/pl-BKKwFhxj.js +0 -2
  250. package/frontend/dist/js/pt-B18-KYtS.js +0 -2
  251. package/frontend/dist/js/ru-DflEWNyb.js +0 -2
  252. package/frontend/dist/js/sv-CU-nPjr8.js +0 -2
  253. package/frontend/dist/js/th-dOxm2Hhl.js +0 -2
  254. package/frontend/dist/js/tr-7ThM4F8q.js +0 -2
  255. package/frontend/dist/js/ui-vendor-C0KwbTD4.js +0 -177
  256. package/frontend/dist/js/uk-Cl7Pk0Yf.js +0 -2
  257. package/frontend/dist/js/useQuery-CoWV2PmJ.js +0 -1
  258. package/frontend/dist/js/utils-vendor-DtsgPwcz.js +0 -9
  259. package/frontend/dist/js/vi-eljYUBOk.js +0 -2
  260. package/frontend/dist/js/workApi-uXUZSjsf.js +0 -1
  261. package/frontend/dist/js/zh-B0sinUfQ.js +0 -2
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{n as r}from"./react-vendor-BsJBHRYW.js";import{a as i,c as a,i as o,n as s,s as c,t as l}from"./useQuery-CoWV2PmJ.js";import{t as u}from"./useTranslation-DrnYb6Cx.js";import{t as d}from"./utils-D9UstwTG.js";import{A as f,Bt as p,Cn as m,Et as h,gr as g,i as _,jn as v,jt as y,n as b,o as x,sn as S,v as C,xn as w,yn as ee,zt as T}from"./ui-vendor-C0KwbTD4.js";import{t as E}from"./logger-CpCQz3Vi.js";import{S as te,b as D}from"./api-2DulPtq1.js";import{i as O,n as k,r as A,s as j}from"./imageGenModels-Dx_QMLJQ.js";import{t as M}from"./appStore-Ci1X0yA-.js";import{t as N}from"./Button--pDOakZx.js";import{a as P,o as F}from"./ui-DUzqxWMk.js";var I=class extends i{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:o,isError:s,isRefetchError:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=s&&u===`forward`,f=i&&u===`forward`,p=s&&u===`backward`,m=i&&u===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:c(t,n.data),hasPreviousPage:a(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:p,isFetchingPreviousPage:m,isRefetchError:l&&!d&&!p,isRefetching:o&&!f&&!m}}};function L(e,t){return s(e,I,t)}var R=e(t(),1),ne=r(),z=n(),re=E(`components:image-generation-panel`);function ie(e,t={}){let n=e.config?.sizes&&e.config.sizes.length>0?e.config.sizes:[t.size||e.config?.default_size||`1024x1024`],r=e.config?.qualities&&e.config.qualities.length>0?e.config.qualities:e.config?.omit_quality_when_empty?[]:[t.quality||e.config?.default_quality||`standard`],i=e.config?.styles&&e.config.styles.length>0?e.config.styles:[];return{pluginId:e.id,model:j(e.models,t.model,void 0,``),size:j(n,t.size,e.config?.default_size,`1024x1024`),quality:r.length>0?j(r,t.quality,e.config?.default_quality,`standard`):``,style:i.length>0?j(i,t.style,e.config?.default_style,i[0]):``,sizes:n,qualities:r,styles:i,maxPromptLength:e.config?.max_prompt_length??null,sizeLabel:e.config?.size_label||``}}var B=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=u(),i=M(e=>e.preferences.imageGenSettings),a=i?.enabled===!0,[o,s]=(0,R.useState)([]),[c,l]=(0,R.useState)(``),[p,m]=(0,R.useState)(``),[h,_]=(0,R.useState)(``),[v,y]=(0,R.useState)(`1024x1024`),[x,S]=(0,R.useState)(`standard`),[C,ee]=(0,R.useState)(``),[E,D]=(0,R.useState)(!1),[j,P]=(0,R.useState)(null),F=(0,R.useRef)(null),[I,L]=(0,R.useState)([`512x512`,`768x768`,`1024x1024`]),[B,ae]=(0,R.useState)([`standard`,`high`]),[V,H]=(0,R.useState)([]),[U,oe]=(0,R.useState)(null),[se,ce]=(0,R.useState)(``),W=R.useId(),G=(0,R.useCallback)((e,t)=>{let n=ie(e,t);l(n.pluginId),m(n.model),y(n.size),S(n.quality),ee(n.style),L(n.sizes),ae(n.qualities),H(n.styles),oe(n.maxPromptLength),ce(n.sizeLabel)},[]);(0,R.useEffect)(()=>{let t=!1;return e&&a&&(async()=>{try{let e=await te.getPlugins();if(t)return;let n=e.success&&e.data?e.data.filter(e=>e.models.length>0):[];s(n);let r=k(n,i);r?G(r,i):(l(``),m(``))}catch(e){if(t)return;s([]),l(``),m(``),re.error(`Failed to load image generation plugins:`,e)}})(),()=>{t=!0}},[G,a,e,i]),(0,R.useEffect)(()=>{if(!e)return;let n=document.body.style.overflow,r=e=>{e.key===`Escape`&&t()};return document.body.style.overflow=`hidden`,document.addEventListener(`keydown`,r),()=>{document.body.style.overflow=n,document.removeEventListener(`keydown`,r)}},[e,t]),(0,R.useEffect)(()=>()=>{F.current?.abort(),F.current=null},[]),(0,R.useEffect)(()=>{e||F.current?.abort()},[e]);let K=()=>{F.current?.abort(),t()},le=e=>{let t=o.find(t=>t.id===e);t&&G(t,{model:p,size:v,quality:x,style:C})},ue=async()=>{if(!a||!c||!p||!h.trim()){g.error(r(`imageGeneration.enterPrompt`));return}if(U&&h.length>U){g.error(r(`imageGeneration.promptTooLong`,{max:U.toLocaleString()}));return}let e=new AbortController;F.current?.abort(),F.current=e,D(!0),P(null);try{let i=await te.generate({model:p,pluginId:c,prompt:h.trim(),size:v,quality:x,...C?{style:C}:{}},e.signal);if(e.signal.aborted)return;if(i.success&&i.data?.images&&i.data.images.length>0){let e=O(i.data.images[0]);e&&(g.success(r(`imageGeneration.success`)),n?(n(e,h.trim(),p),_(``),P(null),t()):P(e))}else g.error(r(`imageGeneration.failed`))}catch(t){if(e.signal.aborted)return;re.error(`Image generation failed:`,t);let n=t instanceof Error?t.message:r(`imageGeneration.failed`);g.error(n)}finally{F.current===e&&(F.current=null,D(!1))}},de=()=>{F.current?.abort()},fe=()=>{if(!j)return;let e=document.createElement(`a`);e.href=j,e.download=`generated-image-${Date.now()}.${A(j)}`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e||!a)return null;let q=o.find(e=>e.id===c);return(0,ne.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":W,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:K}),(0,z.jsxs)(`div`,{className:d(`relative bg-white/95 dark:bg-dark-25/95`,`border border-gray-200/80 dark:border-white/10`,`rounded-3xl shadow-2xl backdrop-blur-xl`,`flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden`),onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:[(0,z.jsx)(`div`,{children:(0,z.jsx)(`h2`,{id:W,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,z.jsx)(`button`,{onClick:K,className:`rounded-xl p-2 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-500 dark:hover:bg-white/[0.06] dark:hover:text-dark-900`,title:r(`common.close`,{defaultValue:`Close`}),children:(0,z.jsx)(b,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,z.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 p-5 scrollbar-thin sm:p-6`,children:q?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,z.jsx)(`select`,{value:c,onChange:e=>le(e.target.value),className:d(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:o.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,z.jsx)(`select`,{value:p,onChange:e=>m(e.target.value),className:d(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:q?.models.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),V.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.style`)}),(0,z.jsx)(`select`,{value:C,onChange:e=>ee(e.target.value),className:d(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:V.map(e=>(0,z.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:se||r(`imageGeneration.size`)}),(0,z.jsx)(`select`,{value:v,onChange:e=>y(e.target.value),className:d(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:I.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),B.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,z.jsx)(`select`,{value:x,onChange:e=>S(e.target.value),className:d(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:B.map(e=>(0,z.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,z.jsx)(`textarea`,{value:h,onChange:e=>_(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:d(`w-full resize-none rounded-2xl px-4 py-3 text-sm leading-6`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`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`,U&&h.length>U&&`border-red-500 dark:border-red-500`)}),U&&(0,z.jsxs)(`div`,{className:d(`mt-1 text-end text-xs`,h.length>U?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[h.length.toLocaleString(),` /`,` `,U.toLocaleString()]})]}),j&&(0,z.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,z.jsx)(`img`,{src:j,alt:`Generated`,className:`w-full h-auto`}),(0,z.jsx)(`button`,{onClick:fe,className:d(`absolute bottom-3 end-3 rounded-lg p-2`,`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,z.jsx)(w,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]}):(0,z.jsxs)(`div`,{className:`text-center py-8`,children:[(0,z.jsx)(T,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,z.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,z.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]})}),q&&(0,z.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,z.jsx)(N,{onClick:E?de:ue,disabled:!E&&(!a||!h.trim()||!c||!p),className:d(`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,z.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,z.jsx)(b,{className:`h-4 w-4`}),r(`common.cancel`)]}):(0,z.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,z.jsx)(f,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},ae={video:[],audio:[]};function V({isOpen:e,initialKind:t,onClose:n,onGenerated:r}){let{t:i}=u(),a=o(),[s,c]=(0,R.useState)(t),[l,p]=(0,R.useState)(ae),[m,h]=(0,R.useState)(``),[_,v]=(0,R.useState)(``),[C,w]=(0,R.useState)(``),[ee,T]=(0,R.useState)(!1),[E,te]=(0,R.useState)(null),[O,k]=(0,R.useState)(``),[A,j]=(0,R.useState)(!1),[M,P]=(0,R.useState)(``),[F,I]=(0,R.useState)(!1),[L,re]=(0,R.useState)(null),[ie,B]=(0,R.useState)(0),[V,G]=(0,R.useState)(``),[K,le]=(0,R.useState)(``),[ue,de]=(0,R.useState)(``),[fe,q]=(0,R.useState)(!0),[pe,me]=(0,R.useState)(!0),[J,he]=(0,R.useState)(!1),[ge,_e]=(0,R.useState)([]),Y=(0,R.useRef)(null),ve=R.useId(),ye=()=>{T(!1),te(null),k(``),j(!1),P(``),I(!1),B(e=>e+1)},be=()=>{Y.current?.abort(),ye(),n()};(0,R.useEffect)(()=>()=>{Y.current?.abort(),Y.current=null},[]),(0,R.useEffect)(()=>{e||Y.current?.abort()},[e]),(0,R.useEffect)(()=>{if(!e)return;let t=!1;return D.getModels().then(e=>{t||!e.success||!e.data||p(e.data)}).catch(()=>{t||g.error(i(`mediaGeneration.loadFailed`))}).finally(()=>{t||me(!1)}),()=>{t=!0}},[e,i]),(0,R.useEffect)(()=>{if(!e)return;let t=!1;return D.listVideoJobs({limit:100,active:!0}).then(e=>{!t&&e.success&&e.data&&_e(e.data.jobs)}).catch(()=>{t||g.error(i(`mediaGeneration.jobsLoadFailed`,{defaultValue:`Failed to load saved video jobs`}))}),()=>{t=!0}},[e,i]);let X=s===`video`?l.video:l.audio,xe=ge.filter(e=>e.status!==`completed`),Se=X.some(e=>U(e)===m)?m:X[0]?U(X[0]):``,Z=(0,R.useMemo)(()=>X.find(e=>U(e)===Se),[Se,X]),Ce=s===`video`?Z?.config:void 0,Q=s===`audio`?Z:void 0,we=!!(Q?.mode===`speech`&&Q.config?.supports_voice_cloning),Te=!!Q?.config?.clone_requires_transcript,$=we&&ee,Ee=!!(Q?.mode!==`speech`||Q.config?.allows_custom_voice!==!1||Q.config?.voices?.length),De=Q?.mode===`speech`?Q.config?.max_characters:void 0,Oe=async(e,t,n,r=0)=>{if(e.status!==`pending`&&e.status!==`in_progress`)return e;n&&await oe(3e4,t.signal);try{let n=await D.resumeVideoJob(e.id,t.signal);if(!n.success||!n.data)throw Error(n.message||i(`mediaGeneration.failed`));let r=n.data;return _e(e=>[r,...e.filter(e=>e.id!==r.id)]),Oe(r,t,!0)}catch(n){if(t.signal.aborted||r>=4)throw n;return Oe(e,t,!0,r+1)}},ke=async e=>{let t=new AbortController;Y.current?.abort(),Y.current=t,he(!0);try{let n=await Oe(e,t,!1);if(t.signal.aborted)return;if(n.status===`failed`)throw Error(n.error||i(`mediaGeneration.failed`));g.success(i(`mediaGeneration.success`)),r()}catch(e){if(t.signal.aborted)return;g.error(e instanceof Error?e.message:i(`mediaGeneration.failed`))}finally{Y.current===t&&(Y.current=null,he(!1))}},Ae=async e=>{try{let t=await D.cancelVideoJob(e.id);if(!t.success)throw Error(t.message||i(`mediaGeneration.failed`));_e(t=>t.filter(t=>t.id!==e.id)),g.success(i(`mediaGeneration.jobCancelled`,{defaultValue:`Video job cancelled at the provider`}))}catch(e){g.error(e instanceof Error?e.message:i(`mediaGeneration.failed`))}};return e?(0,ne.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,children:[(0,z.jsx)(`button`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:be,"aria-label":i(`common.close`)}),(0,z.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":ve,className:`relative flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-gray-200/80 bg-white/95 shadow-2xl backdrop-blur-xl dark:border-white/10 dark:bg-dark-25/95`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.08] sm:px-5`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{id:ve,className:`text-xl text-gray-950 dark:text-dark-950`,children:i(`mediaGeneration.title`)}),(0,z.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-dark-500`,children:i(`mediaGeneration.description`)})]}),(0,z.jsx)(`button`,{onClick:be,className:`rounded-xl p-2`,children:(0,z.jsx)(b,{className:`h-5 w-5`})})]}),(0,z.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-4 p-4 sm:p-5`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-2 gap-2 rounded-xl bg-gray-100 p-1 dark:bg-white/[0.05]`,children:[`video`,`audio`].map(e=>(0,z.jsxs)(`button`,{type:`button`,disabled:J,onClick:()=>{c(e),h(``),w(``),ye()},className:d(`flex items-center justify-center gap-2 rounded-xl px-3 py-2 text-sm transition-colors`,e===s?`bg-white text-gray-950 shadow-sm dark:bg-white/10 dark:text-white`:`text-gray-500 dark:text-dark-500`,J&&`cursor-not-allowed opacity-50`),children:[e===`video`?(0,z.jsx)(S,{className:`h-4 w-4`}):(0,z.jsx)(x,{className:`h-4 w-4`}),i(`mediaGeneration.${e}`)]},e))}),s===`video`&&xe.length>0&&(0,z.jsxs)(`section`,{className:`space-y-2 rounded-xl border border-gray-200/80 bg-gray-50/80 p-3 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:i(`mediaGeneration.savedJobs`,{defaultValue:`Saved video jobs`})}),(0,z.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:i(`mediaGeneration.savedJobsDescription`,{defaultValue:`Closing this panel only stops waiting. Reopen it to resume any provider job listed here.`})})]}),xe.map(e=>(0,z.jsxs)(`div`,{"data-testid":`video-job-${e.id}`,className:`flex items-center gap-3 rounded-lg border border-gray-200/70 bg-white/80 p-2.5 dark:border-white/10 dark:bg-dark-50/70`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`truncate text-sm text-gray-900 dark:text-gray-100`,children:e.prompt||e.model}),(0,z.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:[e.model,` ·`,` `,i(`mediaGeneration.jobStatus.${e.status}`,{defaultValue:e.status.replace(`_`,` `)})]}),e.error&&(0,z.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-300`,children:e.error})]}),(e.status===`pending`||e.status===`in_progress`)&&(0,z.jsx)(N,{type:`button`,variant:`outline`,size:`sm`,disabled:J,onClick:()=>void ke(e),children:i(`mediaGeneration.resumeJob`,{defaultValue:`Resume`})}),e.cancellable&&(0,z.jsx)(N,{type:`button`,variant:`outline`,size:`sm`,disabled:J,onClick:()=>void Ae(e),children:i(`mediaGeneration.cancelJob`,{defaultValue:`Cancel job`})})]},e.id))]}),pe?(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(y,{className:`h-7 w-7 animate-spin`})}):X.length===0?(0,z.jsx)(`div`,{className:`rounded-xl border border-amber-500/25 bg-amber-500/10 p-4 text-sm text-amber-800 dark:text-amber-200`,children:i(`mediaGeneration.noModels`,{kind:i(`mediaGeneration.${s}`)})}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(H,{label:i(`mediaGeneration.model`),children:(0,z.jsx)(`select`,{value:Se,onChange:e=>{h(e.target.value),w(``),ye(),G(``),le(``),de(``),q(!0)},className:W,children:X.map(e=>(0,z.jsxs)(`option`,{value:U(e),children:[e.model,` (`,e.plugin,`mode`in e?` · ${i(`mediaGeneration.${e.mode}`)}`:``,`)`]},U(e)))})}),s===`audio`&&!$&&Ee?(0,z.jsx)(H,{label:i(`mediaGeneration.voice`),children:(0,z.jsx)(`input`,{value:C,onChange:e=>w(e.target.value),className:W,placeholder:Q?.config?.default_voice||i(`mediaGeneration.providerDefault`)})}):s===`video`?(0,z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[(0,z.jsx)(H,{label:i(`mediaGeneration.resolution`),children:(0,z.jsxs)(`select`,{value:V,onChange:e=>G(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:i(`mediaGeneration.providerDefault`)}),Ce?.resolutions?.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})}),(0,z.jsx)(H,{label:i(`mediaGeneration.aspectRatio`),children:(0,z.jsxs)(`select`,{value:K,onChange:e=>le(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:i(`mediaGeneration.providerDefault`)}),Ce?.aspect_ratios?.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})}),(0,z.jsx)(H,{label:i(`mediaGeneration.duration`),children:(0,z.jsxs)(`select`,{value:ue,onChange:e=>de(e.target.value),className:W,children:[(0,z.jsx)(`option`,{value:``,children:i(`mediaGeneration.providerDefault`)}),Ce?.durations?.map(e=>(0,z.jsxs)(`option`,{value:e,children:[e,`s`]},e))]})})]}):null,we&&(0,z.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-primary-500/20 bg-primary-500/[0.06] p-4`,children:[(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:$,onChange:e=>{e.target.checked?T(!0):ye()},className:`mt-0.5`}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:i(`mediaGeneration.cloneVoice`)}),(0,z.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:i(`mediaGeneration.cloneVoiceDescription`)})]})]}),$&&(0,z.jsxs)(`div`,{className:`space-y-3 border-t border-primary-500/15 pt-3`,children:[(0,z.jsx)(H,{label:i(`mediaGeneration.referenceAudio`),children:(0,z.jsx)(`input`,{type:`file`,accept:Q?.config?.clone_audio_mime_types?.join(`,`)||`audio/wav,audio/mpeg,audio/flac,audio/ogg`,onChange:e=>{let t=e.target.files?.[0]||null,n=Q?.config?.clone_max_audio_bytes;if(t&&n&&t.size>n){g.error(i(`mediaGeneration.referenceAudioTooLarge`,{max:ce(n)})),e.target.value=``,te(null);return}te(t)},className:d(W,`file:me-3 file:rounded-lg file:border-0 file:bg-primary-500/10 file:px-3 file:py-1 file:text-primary-700 dark:file:text-primary-300`)},ie)}),(0,z.jsx)(H,{label:i(`mediaGeneration.referenceTranscript`),children:(0,z.jsx)(`textarea`,{value:O,onChange:e=>k(e.target.value),rows:3,required:Te,className:d(W,`resize-none`),placeholder:i(`mediaGeneration.referenceTranscriptPlaceholder`)})}),(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>{j(e.target.checked),e.target.checked||(P(``),I(!1))},className:`mt-0.5`}),(0,z.jsxs)(`span`,{children:[(0,z.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:i(`mediaGeneration.saveVoiceProfile`,{defaultValue:`Save as a reusable voice`})}),(0,z.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:i(`mediaGeneration.saveVoiceProfileDescription`,{defaultValue:`Store this reference recording and transcript securely. Libre WebUI sends them to the selected provider for every Speech batch that uses this voice.`})})]})]}),A&&(0,z.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-primary-500/15 bg-white/60 p-3 dark:bg-dark-100/50`,children:[(0,z.jsx)(H,{label:i(`mediaGeneration.voiceProfileName`,{defaultValue:`Saved voice name`}),children:(0,z.jsx)(`input`,{type:`text`,value:M,onChange:e=>P(e.target.value),maxLength:80,autoComplete:`off`,className:W,placeholder:i(`mediaGeneration.voiceProfileNamePlaceholder`,{defaultValue:`For example, My voice`})})}),(0,z.jsxs)(`label`,{className:`flex items-start gap-3 text-xs text-amber-700 dark:text-amber-300`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:F,onChange:e=>I(e.target.checked),className:`mt-0.5`}),(0,z.jsx)(`span`,{children:i(`mediaGeneration.voiceStorageConsent`,{defaultValue:`I confirm that I have the speaker’s permission to clone and store this voice. The reference stays saved until I delete it.`})})]}),(0,z.jsx)(H,{label:i(`mediaGeneration.consentTtl.label`,{defaultValue:`Consent duration`}),children:(0,z.jsxs)(`select`,{value:L??``,onChange:e=>re(e.target.value===``?null:Number(e.target.value)),className:W,children:[(0,z.jsx)(`option`,{value:``,children:i(`mediaGeneration.consentTtl.never`,{defaultValue:`Until I withdraw it`})}),(0,z.jsx)(`option`,{value:`30`,children:i(`mediaGeneration.consentTtl.days30`,{defaultValue:`30 days`})}),(0,z.jsx)(`option`,{value:`90`,children:i(`mediaGeneration.consentTtl.days90`,{defaultValue:`90 days`})}),(0,z.jsx)(`option`,{value:`365`,children:i(`mediaGeneration.consentTtl.days365`,{defaultValue:`One year`})})]})})]}),!A&&(0,z.jsx)(`p`,{className:`text-xs font-normal text-amber-700 dark:text-amber-300`,children:i(`mediaGeneration.cloneConsent`)})]})]}),s===`video`&&Ce?.supports_audio&&(0,z.jsxs)(`label`,{className:`flex items-center gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:fe,onChange:e=>q(e.target.checked)}),i(`mediaGeneration.generateAudio`)]}),(0,z.jsxs)(H,{label:s===`video`||Q?.mode===`sound`?i(`mediaGeneration.prompt`):i(`mediaGeneration.text`),children:[(0,z.jsx)(`textarea`,{value:_,onChange:e=>v(e.target.value),rows:6,maxLength:De,className:d(W,`resize-none`),placeholder:i(s===`audio`&&Q?.mode===`sound`?`mediaGeneration.soundPlaceholder`:`mediaGeneration.${s}Placeholder`)}),De&&(0,z.jsxs)(`span`,{className:`block text-end text-xs font-normal text-gray-500 dark:text-dark-500`,children:[_.length,` / `,De]})]})]})]}),X.length>0&&(0,z.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-5`,children:(0,z.jsxs)(N,{onClick:J?()=>{Y.current?.abort()}:async()=>{if(!Z||!_.trim())return;let e=new AbortController;Y.current?.abort(),Y.current=e,he(!0);try{if(s===`audio`){let t=se(Q?.config?.default_format),n=$?await D.cloneVoice({model:Z.model,pluginId:Z.plugin,input:_.trim(),referenceAudio:E,referenceText:O.trim()||void 0,responseFormat:t,saveVoiceName:A?M.trim():void 0,consentToStore:A&&F,consentTtlDays:A&&L!==null?L:void 0},e.signal):Q?.mode===`sound`?await D.generateSound({model:Z.model,pluginId:Z.plugin,prompt:_.trim(),voice:C.trim()||Q?.config?.default_voice||void 0,format:`wav`},e.signal):await D.generateAudio({model:Z.model,pluginId:Z.plugin,input:_.trim(),voice:C.trim()||Q?.config?.default_voice||void 0,response_format:t},e.signal);if(e.signal.aborted)return;if(!n.success)throw Error(n.message);if($&&A&&(await a.invalidateQueries({queryKey:[`tts-voice-profiles`]}),e.signal.aborted))return}else{let t=await D.generateVideo({model:Z.model,pluginId:Z.plugin,prompt:_.trim(),...ue?{duration:Number(ue)}:{},...V?{resolution:V}:{},...K?{aspect_ratio:K}:{},...Ce?.supports_audio?{generate_audio:fe}:{}},e.signal);if(e.signal.aborted)return;if(!t.success||!t.data)throw Error(t.message||i(`mediaGeneration.failed`));let n=t.data;_e(e=>[n,...e.filter(e=>e.id!==n.id)]);let r=await Oe(n,e,!0);if(r.status===`failed`)throw Error(r.error||i(`mediaGeneration.failed`))}if(e.signal.aborted)return;g.success($&&A?i(`mediaGeneration.successWithSavedVoice`,{name:M.trim(),defaultValue:`Media generated and “{{name}}” is now available in Speech settings`}):i(`mediaGeneration.success`)),v(``),ye(),r(),n()}catch(t){if(e.signal.aborted)return;g.error(t instanceof Error?t.message:i(`mediaGeneration.failed`))}finally{Y.current===e&&(Y.current=null,he(!1))}},disabled:J?!1:!Z||!_.trim()||!!(De&&_.length>De)||$&&(!E||Te&&!O.trim()||A&&(!M.trim()||!F)),className:`w-full gap-2`,children:[J?(0,z.jsx)(b,{className:`h-4 w-4`}):(0,z.jsx)(f,{className:`h-4 w-4`}),J?s===`video`?i(`mediaGeneration.stopWaiting`,{defaultValue:`Stop waiting`}):i(`common.cancel`):i(`mediaGeneration.generate`)]})})]})]}),document.body):null}function H({label:e,children:t}){return(0,z.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-gray-700 dark:text-gray-300`,children:[(0,z.jsx)(`span`,{children:e}),t]})}function U(e){return`${e.mode||`default`}::${e.plugin}::${e.model}`}function oe(e,t){return t?.aborted?Promise.reject(t.reason):new Promise((n,r)=>{let i=window.setTimeout(()=>{t?.removeEventListener(`abort`,a),n()},e),a=()=>{window.clearTimeout(i),r(t?.reason)};t?.addEventListener(`abort`,a,{once:!0})})}function se(e){return[`mp3`,`opus`,`aac`,`flac`,`wav`,`pcm`].includes(e||``)?e:`mp3`}function ce(e){return e>=1048576?`${Math.ceil(e/1048576)} MB`:`${Math.ceil(e/1024)} KB`}var W=`w-full rounded-xl border border-gray-200/80 bg-white/70 px-3 py-2.5 text-sm text-gray-900 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.035] dark:text-gray-100`,G=E(`components:image-edit-panel`),K=e=>e.filter(e=>!!e.config?.edit_endpoint),le=({isOpen:e,onClose:t,source:n,onEdited:r})=>{let{t:i}=u(),[a,o]=(0,R.useState)([]),[s,c]=(0,R.useState)(``),[l,d]=(0,R.useState)(``),[f,p]=(0,R.useState)(36),[m,h]=(0,R.useState)([]),[v,x]=(0,R.useState)(!1),[S,C]=(0,R.useState)(null),[w,T]=(0,R.useState)(!1),E=(0,R.useRef)(null),O=(0,R.useRef)(null),k=(0,R.useRef)(null),A=(0,R.useRef)(!1),j=(0,R.useRef)(null),M=a.find(e=>`${e.plugin}:${e.model}`===s);(0,R.useEffect)(()=>{if(!e)return;let t=!1;return te.getModels().then(e=>{if(t||!e.success||!e.data)return;let n=K(e.data);o(n),c(e=>n.some(t=>`${t.plugin}:${t.model}`===e)?e:n[0]?`${n[0].plugin}:${n[0].model}`:``)}),()=>{t=!0}},[e]),(0,R.useEffect)(()=>{if(!e||!n)return;let t=null,r=!1;return D.getGalleryContent(n.id).then(e=>{r||(t=URL.createObjectURL(e),C(t))}).catch(e=>{G.error(`Failed to load the source image:`,e),g.error(i(`imageEdit.loadFailed`))}),()=>{r=!0,t&&URL.revokeObjectURL(t),C(null),T(!1),h([])}},[e,n?.id]),(0,R.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let P=()=>{let e=k.current,t=E.current,n=O.current;if(!e||!t||!n)return;let r=e.getContext(`2d`);r&&(r.clearRect(0,0,e.width,e.height),r.drawImage(t,0,0,e.width,e.height),r.save(),r.globalAlpha=.55,r.drawImage(n,0,0,e.width,e.height),r.restore())},F=()=>{let e=E.current,t=k.current;if(!e||!t)return;let n=e.naturalWidth,r=e.naturalHeight;t.width=n,t.height=r;let i=document.createElement(`canvas`);i.width=n,i.height=r,O.current=i,T(!1),P()},I=e=>{let t=k.current,n=O.current;if(!t||!n)return;let r=t.getBoundingClientRect(),i=(e.clientX-r.left)/r.width*t.width,a=(e.clientY-r.top)/r.height*t.height,o=n.getContext(`2d`);if(!o)return;let s=f/r.width*t.width;o.fillStyle=`rgba(239, 68, 68, 1)`,o.beginPath(),o.arc(i,a,s,0,Math.PI*2),o.fill(),T(!0),P()},L=()=>{let e=O.current;e&&(e.getContext(`2d`)?.clearRect(0,0,e.width,e.height),T(!1),P())},re=async()=>{let e=O.current;if(!e||!w)return null;let t=document.createElement(`canvas`);t.width=e.width,t.height=e.height;let n=t.getContext(`2d`);return n?(n.fillStyle=`#000000`,n.fillRect(0,0,t.width,t.height),n.globalCompositeOperation=`destination-out`,n.drawImage(e,0,0),new Promise(e=>t.toBlob(t=>e(t),`image/png`))):null},ie=async()=>{if(!n||!M||!l.trim()||v)return;x(!0);let e=new AbortController;j.current=e;try{let a=await re(),o=await D.editImage({model:M.model,pluginId:M.plugin,prompt:l.trim(),sourceMediaId:n.id,images:m,...a?{mask:a}:{}},e.signal);if(!o.success)throw Error(o.message||o.error||`Edit failed`);g.success(i(`imageEdit.saved`)),r(),t()}catch(t){e.signal.aborted||(G.error(`Image edit failed:`,t),g.error(t instanceof Error?t.message:i(`imageEdit.failed`)))}finally{x(!1),j.current=null}};if(!e||!n)return null;let B=Math.max(0,(M?.config?.max_reference_images??1)-1);return(0,ne.createPortal)((0,z.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":i(`imageEdit.title`),className:`fixed inset-0 z-[70] flex items-center justify-center bg-black/50 p-4`,"data-testid":`image-edit-panel`,children:(0,z.jsxs)(`div`,{className:`flex max-h-[90vh] w-full max-w-3xl flex-col overflow-hidden rounded-2xl bg-white shadow-xl dark:bg-dark-100`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200 px-4 py-3 dark:border-dark-300`,children:[(0,z.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold text-gray-900 dark:text-gray-100`,children:[(0,z.jsx)(_,{className:`h-4 w-4`}),i(`imageEdit.title`)]}),(0,z.jsx)(`button`,{type:`button`,onClick:t,"aria-label":i(`common.close`),className:`rounded-full p-1.5 text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,z.jsx)(b,{className:`h-5 w-5`})})]}),(0,z.jsx)(`div`,{className:`flex-1 space-y-4 overflow-y-auto p-4`,children:a.length===0?(0,z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:i(`imageEdit.noModels`)}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`relative`,children:S?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`img`,{ref:E,src:S,alt:n.prompt,className:`hidden`,onLoad:F}),(0,z.jsx)(`canvas`,{ref:k,onPointerDown:e=>{A.current=!0,e.currentTarget.setPointerCapture(e.pointerId),I(e)},onPointerMove:e=>{A.current&&I(e)},onPointerUp:()=>{A.current=!1},className:`w-full cursor-crosshair rounded-xl border border-gray-200 dark:border-dark-300`,"data-testid":`image-edit-canvas`})]}):(0,z.jsx)(`div`,{className:`flex h-56 items-center justify-center`,children:(0,z.jsx)(y,{className:`h-6 w-6 animate-spin text-gray-400`})})}),(0,z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`imageEdit.maskHint`)}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-600 dark:text-gray-300`,children:[i(`imageEdit.brushSize`),(0,z.jsx)(`input`,{type:`range`,min:8,max:96,value:f,onChange:e=>p(Number(e.target.value))})]}),(0,z.jsxs)(N,{type:`button`,size:`sm`,variant:`outline`,onClick:L,disabled:!w,children:[(0,z.jsx)(ee,{className:`mr-1 h-3.5 w-3.5`}),i(`imageEdit.clearMask`)]})]}),(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.model`),(0,z.jsx)(`select`,{value:s,onChange:e=>c(e.target.value),className:`mt-1 w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50`,children:a.map(e=>(0,z.jsxs)(`option`,{value:`${e.plugin}:${e.model}`,children:[e.plugin,` · `,e.model]},`${e.plugin}:${e.model}`))})]}),(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.prompt`),(0,z.jsx)(`textarea`,{value:l,onChange:e=>d(e.target.value),rows:3,placeholder:i(`imageEdit.promptPlaceholder`),className:`mt-1 w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50`,"data-testid":`image-edit-prompt`})]}),B>0&&(0,z.jsxs)(`label`,{className:`block text-xs font-medium text-gray-700 dark:text-gray-300`,children:[i(`imageEdit.referenceImages`,{total:B}),(0,z.jsx)(`input`,{type:`file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,onChange:e=>h(Array.from(e.target.files??[]).slice(0,B)),className:`mt-1 block w-full text-xs`})]})]})}),(0,z.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-gray-200 px-4 py-3 dark:border-dark-300`,children:[(0,z.jsx)(N,{type:`button`,variant:`outline`,onClick:t,children:i(`common.cancel`)}),(0,z.jsxs)(N,{type:`button`,onClick:()=>void ie(),disabled:v||!M||!l.trim()||!S,"data-testid":`image-edit-submit`,children:[v?(0,z.jsx)(y,{className:`mr-1 h-4 w-4 animate-spin`}):(0,z.jsx)(_,{className:`mr-1 h-4 w-4`}),i(`imageEdit.apply`)]})]})]})}),document.body)},ue=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:i}=u();return(0,R.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,ne.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,z.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,z.jsx)(`button`,{onClick:t,className:d(`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,z.jsx)(b,{className:`h-6 w-6 text-white`})}),(0,z.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,z.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,z.jsxs)(`div`,{className:d(`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,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:i(`gallery.prompt`)}),(0,z.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,z.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(m,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.model`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(h,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.size`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.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,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.quality`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(v,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.created`),`:`]}),(0,z.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,z.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,z.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.${A(e.imageData)}`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:d(`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,z.jsx)(w,{className:`h-4 w-4`}),i(`gallery.download`)]}),n&&(0,z.jsx)(`button`,{onClick:()=>n(e.id),className:d(`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,z.jsx)(C,{className:`h-4 w-4`})})]})]})]})]}),document.body)};function de({kind:e,refreshKey:t,onCountChange:n,onEditImage:r}){let{t:i}=u(),a=o(),[s,c]=(0,R.useState)(null),[l,d]=(0,R.useState)(null),f=L({queryKey:[`media-gallery`,e||`all`,t||0],queryFn:async({pageParam:t})=>{let n=await D.getGallery({limit:20,offset:t,...e?{kind:e}:{}});if(!n.success||!n.data)throw Error(n.message||i(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.media.length,0);return n<e.total?n:void 0}}),m=(0,R.useMemo)(()=>f.data?.pages.flatMap(e=>e.media)||[],[f.data]),h=f.data?.pages[0]?.total||0;(0,R.useEffect)(()=>n?.(h),[n,h]);let v=async e=>{if(!l){d(e.id);try{let t=await D.deleteGalleryItem(e.id);if(!t.success)throw Error(t.message);c(null),await a.invalidateQueries({queryKey:[`media-gallery`]}),g.success(i(`imageGallery.deleteSuccess`))}catch{g.error(i(`imageGallery.deleteFailed`))}finally{d(null)}}},b=async e=>{let t=await D.getGalleryContent(e.id),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`generated-${e.id}.${pe(e.mimeType)}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)};return f.isLoading?(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(y,{className:`h-8 w-8 animate-spin text-gray-400`})}):m.length===0?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-12 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,z.jsx)(p,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,z.jsx)(`h3`,{className:`text-lg font-medium`,children:i(`mediaGallery.empty`)}),(0,z.jsx)(`p`,{className:`mt-2 max-w-sm text-gray-500 dark:text-gray-400`,children:i(`mediaGallery.emptyHint`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:m.map(e=>(0,z.jsxs)(`article`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/70 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,z.jsx)(fe,{item:e,onOpenImage:t=>c(q(e,t))}),(0,z.jsxs)(`div`,{className:`space-y-3 p-3`,children:[(0,z.jsx)(`p`,{className:`line-clamp-2 text-sm text-gray-800 dark:text-gray-200`,children:e.prompt}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-xs text-gray-500`,children:e.model}),(0,z.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[e.kind===`image`&&r&&(0,z.jsx)(`button`,{onClick:()=>r(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:i(`imageEdit.title`),"data-testid":`edit-image-${e.id}`,children:(0,z.jsx)(_,{className:`h-4 w-4`})}),(0,z.jsx)(`button`,{onClick:()=>void b(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:i(`imageGallery.download`),children:(0,z.jsx)(w,{className:`h-4 w-4`})}),(0,z.jsx)(`button`,{onClick:()=>void v(e),disabled:l===e.id,className:`rounded-lg p-1.5 hover:bg-red-500/15 hover:text-red-500`,title:i(`imageGallery.delete`),children:l===e.id?(0,z.jsx)(y,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(C,{className:`h-4 w-4`})})]})]})]})]},e.id))}),f.hasNextPage&&(0,z.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,z.jsx)(N,{variant:`outline`,disabled:f.isFetchingNextPage,onClick:()=>void f.fetchNextPage(),children:f.isFetchingNextPage?i(`common.loading`):i(`imageGallery.loadMore`,{current:m.length,total:h})})}),s&&(0,z.jsx)(ue,{image:s,onClose:()=>c(null),onDelete:e=>{let t=m.find(t=>t.id===e);t&&v(t)},onDownload:e=>{let t=m.find(t=>t.id===e.id);t&&b(t)}})]})}function fe({item:e,onOpenImage:t}){let{data:n,isLoading:r}=l({queryKey:[`media-gallery-content`,e.id],queryFn:()=>D.getGalleryContent(e.id),staleTime:3e5}),i=(0,R.useMemo)(()=>n?URL.createObjectURL(n):``,[n]);return(0,R.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),r||!i?(0,z.jsx)(`div`,{className:`flex aspect-video items-center justify-center bg-gray-100 dark:bg-white/[0.03]`,children:(0,z.jsx)(y,{className:`h-6 w-6 animate-spin text-gray-400`})}):e.kind===`image`?(0,z.jsx)(`button`,{className:`block aspect-square w-full overflow-hidden`,onClick:()=>t(i),children:(0,z.jsx)(`img`,{src:i,alt:e.prompt,className:`h-full w-full object-cover`,loading:`lazy`})}):e.kind===`video`?(0,z.jsx)(`div`,{className:`aspect-video bg-black`,children:(0,z.jsx)(`video`,{src:i,controls:!0,preload:`metadata`,className:`h-full w-full object-contain`})}):(0,z.jsxs)(`div`,{className:`flex min-h-40 flex-col items-center justify-center gap-3 bg-gradient-to-br from-primary-500/10 to-cyan-500/10 p-4`,children:[(0,z.jsx)(x,{className:`h-9 w-9 text-primary-500`}),(0,z.jsx)(`audio`,{src:i,controls:!0,preload:`metadata`,className:`w-full`})]})}function q(e,t){return{id:e.id,userId:e.userId,prompt:e.prompt,model:e.model,imageData:t,size:e.size,quality:e.quality,createdAt:e.createdAt}}function pe(e){let t=e.split(`/`)[1]?.split(`;`)[0];return t===`mpeg`?e.startsWith(`audio/`)?`mp3`:`mpeg`:t===`svg+xml`?`svg`:t||`bin`}var me=()=>{let{t:e}=u(),[t,n]=(0,R.useState)(null),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(`all`),[l,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(0),h=M(e=>e.preferences.imageGenSettings?.enabled===!0),g=(0,R.useCallback)(()=>{m(e=>e+1)},[]);return(0,z.jsxs)(F,{width:`wide`,children:[(0,z.jsx)(P,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,z.jsx)(`span`,{className:`inline-flex rounded-full border border-gray-200/80 bg-white/60 px-2.5 py-1 text-xs text-gray-500 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-500`,children:e(`mediaGallery.itemCount`,{count:t})}):null,actions:(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.jsxs)(N,{onClick:()=>{h&&i(!0)},disabled:!h,className:`gap-2 px-4`,children:[(0,z.jsx)(T,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]}),(0,z.jsxs)(N,{variant:`outline`,onClick:()=>o(`video`),className:`gap-2 px-4`,children:[(0,z.jsx)(S,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.video`)]}),(0,z.jsxs)(N,{variant:`outline`,onClick:()=>o(`audio`),className:`gap-2 px-4`,children:[(0,z.jsx)(x,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.audio`)]})]})}),(0,z.jsx)(`div`,{className:`mb-5 flex flex-wrap gap-2`,children:[`all`,`image`,`video`,`audio`].map(t=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>c(t),className:d(`rounded-full border px-3 py-1.5 text-sm transition-colors`,s===t?`border-gray-950 bg-gray-950 text-white dark:border-white dark:bg-white dark:text-gray-950`:`border-gray-200 text-gray-600 hover:border-gray-400 dark:border-white/10 dark:text-dark-600`),children:e(`mediaGallery.filters.${t}`)},t))}),(0,z.jsx)(de,{kind:s===`all`?void 0:s,refreshKey:p,onCountChange:n,onEditImage:f}),(0,z.jsx)(le,{isOpen:l!==null,source:l,onClose:()=>f(null),onEdited:g}),(0,z.jsx)(B,{isOpen:r&&h,onClose:()=>i(!1),onImageGenerated:g}),(0,z.jsx)(V,{isOpen:a!==null,initialKind:a||`video`,onClose:()=>o(null),onGenerated:g},a||`closed`)]})};export{me as GalleryPage,me as default};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{n as r}from"./i18next-ChNMiFef.js";import{a as i,i as a,n as o,o as s,r as c,t as l}from"./useTranslation-DrnYb6Cx.js";import{c as u,f as d,t as f,u as p}from"./utils-D9UstwTG.js";import{$ as m,$t as h,E as g,Gn as _,L as v,S as y,Xn as b,Y as x,_r as S,it as C,jn as w,jt as ee,mr as T,n as te,nr as E,v as D,vn as ne}from"./ui-vendor-C0KwbTD4.js";import{t as O}from"./logger-CpCQz3Vi.js";import{x as k}from"./api-2DulPtq1.js";import{t as A}from"./Button--pDOakZx.js";import{a as re,o as j}from"./ui-DUzqxWMk.js";var M={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,"!doctype":!0,"!DOCTYPE":!0},N=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?("[^"]*"|'[^']*')/g;function P(e){let t={type:`tag`,name:``,voidElement:!1,attrs:{},children:[]},n=e.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(t.name=n[1],(M[n[1]]||e.charAt(e.length-2)===`/`)&&(t.voidElement=!0),t.name.startsWith(`!--`))){let t=e.indexOf(`-->`);return{type:`comment`,comment:t===-1?``:e.slice(4,t)}}let r=new RegExp(N),i=null;for(;i=r.exec(e),i!==null;)if(i[0].trim()){if(i[1]){let e=i[1].trim(),n=[e,null],a=e.indexOf(`=`);a>-1&&(n=[e.slice(0,a),e.slice(a+1)]),t.attrs[n[0]]=n[1],r.lastIndex--}else i[2]&&(t.attrs[i[2]]=i[3].trim().substring(1,i[3].length-1))}return t}var F=/<!--[\s\S]*?-->|<[a-zA-Z0-9\-!/](?:"[^"]*"|'[^']*'|[^'">])*>/g,I=/<\/?([^\s]+?)[/\s>]/,ie=/^\s*$/,ae=/^(script|style)$/i,L=`\0`,oe=Object.create(null);function se(e){e.forEach(function(e){if(e.type===`text`){e.content=e.content.split(L).join(`<`);return}if(e.type===`comment`){e.comment=e.comment.split(L).join(`<`);return}for(let t in e.attrs){let n=e.attrs[t];typeof n==`string`&&n.indexOf(L)>-1&&(e.attrs[t]=n.split(L).join(`<`))}e.children.length&&se(e.children)})}function ce(e,t){let n=t&&t.components||oe,r=t&&t.allowedTags,i=!1;if(r){let t=typeof r==`function`?r:function(e){return r.indexOf(e)>-1},n=``,a=0;F.lastIndex=0;let o;for(;o=F.exec(e);){let r=o[0];n+=e.slice(a,o.index);let s=r.match(I);r.startsWith(`<!--`)||s&&t(s[1])?(n+=r,a=o.index+r.length):(i=!0,n+=L,a=o.index+1,F.lastIndex=a)}e=n+e.slice(a)}let a=[],o=[],s,c=-1,l=!1,u=0,d;if(e.indexOf(`<`)!==0){let t=e.indexOf(`<`);a.push({type:`text`,content:t===-1?e:e.substring(0,t)})}let f=[],p;for(;p=F.exec(e);)f.push(p);return f.forEach(function(e,t){let n=e[0];if(!n||n.startsWith(`<!--`))return;let r=0,i=0,a=-1,o=null;for(let e=0;e<n.length;e++){let t=n.charAt(e);o?t===o&&(o=null):t===`"`||t===`'`?o=t:t===`<`?(r++,r===2&&(a=e)):t===`>`&&i++}let s=a>-1&&/[a-zA-Z0-9\-!/]/.test(n.charAt(a+1));if(r>i&&s){let e=n.substring(0,a),r=n.substring(e.length);f[t][0]=r,f[t].index+=e.length}}),f.forEach(function(t,r){let i=t[0];if(!i)return;let p=t.index;if(p<u)return;if(l){if(i!==`</`+s.name+`>`)return;l=!1}let m=i.charAt(1)!==`/`,h=i.startsWith(`<!--`),g=p+i.length,_=e.charAt(g),v=f[r+1],y;if(_===`<`&&v){let t=e.substring(g,v.index);y=t.split(`<`).length>t.split(`>`).length}let b;if(h){let t=P(i);if(c<0)return a.push(t),a;b=o[c],b.children.push(t);let n=e.slice(g,v?v.index:void 0);return n.length>0&&b.children.push({type:`text`,content:n}),a}if(m){c++,s=P(i),s.type===`tag`&&n[s.name]&&(s.type=`component`,l=!0);let t=!1;if(!l&&!s.voidElement&&ae.test(s.name)){t=!0,d||(d=e.toLowerCase());let n=d.indexOf(`</`+s.name.toLowerCase()+`>`,g),r=n===-1?e.length:n,i=e.slice(g,r);i&&s.children.push({type:`text`,content:i}),u=r}!s.voidElement&&!l&&!t&&_&&_!==`<`&&s.children.push({type:`text`,content:e.slice(g,v?v.index:void 0)}),c===0&&a.push(s),b=o[c-1],b&&b.children.push(s),o[c]=s}if((!m||s.voidElement)&&(c>-1&&(s.voidElement||s.name===i.slice(2,-1))&&(c--,s=c===-1?a:o[c]),!l&&(_!==`<`||y)&&_)){b=c===-1?a:o[c].children;let t=v?v.index:-1,n=e.slice(g,t===-1?void 0:t);ie.test(n)&&(n=` `),(t>-1&&c+b.length>=0||n!==` `)&&b.push({type:`text`,content:n})}}),i&&se(a),a}function le(e){let t=[];for(let n in e)e[n]===null?t.push(n):t.push(n+`="`+String(e[n]).replace(/"/g,`&quot;`)+`"`);return t.length?` `+t.join(` `):``}function ue(e,t){switch(t.type){case`text`:return e+t.content;case`tag`:{let n=t.voidElement&&t.name.toLowerCase()!==`!doctype`?`/>`:`>`;return e+=`<`+t.name+(t.attrs?le(t.attrs):``)+n,t.voidElement?e:e+t.children.reduce(ue,``)+`</`+t.name+`>`}case`comment`:return e+=`<!--`+t.comment+`-->`,e}}function de(e){return e.reduce(function(e,t){return e+ue(``,t)},``)}var R={parse:ce,stringify:de},z=e(t()),B=(e,t)=>{if(!e)return!1;let n=e.props?.children??e.children;return t?n.length>0:!!n},V=e=>{if(!e)return[];let t=e.props?.children??e.children;return e.props?.i18nIsDynamicList?H(t):t},fe=e=>Array.isArray(e)&&e.every(z.isValidElement),H=e=>Array.isArray(e)?e:[e],pe=(e,t)=>{let n={...t};return n.props={...t.props,...e.props},n},me=e=>{let t={};if(!e)return t;let n=e=>{H(e).forEach(e=>{a(e)||(B(e)?n(V(e)):c(e)&&!(0,z.isValidElement)(e)&&Object.assign(t,e))})};return n(e),t},U=(e,t,n,r)=>{if(!e)return``;let o=``,s=H(e),l=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return s.forEach((e,s)=>{if(a(e)){o+=`${e}`;return}if((0,z.isValidElement)(e)){let{props:i,type:c}=e,u=Object.keys(i).length,d=l.indexOf(c)>-1,f=i.children;if(!f&&d&&!u){o+=`<${c}/>`;return}if(!f&&(!d||u)||i.i18nIsDynamicList){o+=`<${s}></${s}>`;return}if(d&&u<=1){let e=a(f)?f:U(f,t,n,r);o+=`<${c}>${e}</${c}>`;return}let p=U(f,t,n,r);o+=`<${s}>${p}</${s}>`;return}if(e===null){i(n,`TRANS_NULL_VALUE`,`Passed in a null value as child`,{i18nKey:r});return}if(c(e)){let{format:t,...a}=e,s=Object.keys(a);if(s.length===1){let e=t?`${s[0]}, ${t}`:s[0];o+=`{{${e}}}`;return}i(n,`TRANS_INVALID_OBJ`,`Invalid child - Object should only have keys {{ value, format }} (format is optional).`,{i18nKey:r,child:e});return}i(n,`TRANS_INVALID_VAR`,`Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`,{i18nKey:r,child:e})}),o},W=(e,t,n,r,i,o,s)=>{if(n===``)return[];let l=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(l.map(e=>`<${e}`).join(`|`)).test(n);if(!e&&!t&&!u&&!s)return[n];let f=t??{},m=e=>{H(e).forEach(e=>{a(e)||(B(e)?m(V(e)):c(e)&&!(0,z.isValidElement)(e)&&Object.assign(f,e))})};m(e);let h=Object.keys(f),g=R.parse(`<0>${n}</0>`,{allowedTags:e=>/^\d+$/.test(e)||l.indexOf(e)>-1||h.indexOf(e)>-1}),_={...f,...o},v=(e,t,n)=>{let r=V(e),i=b(r,t.children,n);return fe(r)&&i.length===0||e.props?.i18nIsDynamicList?r:i},y=(e,t,n,r,i)=>{e.dummy?(e.children=t,n.push((0,z.cloneElement)(e,{key:r},i?void 0:t))):n.push(...z.Children.map([e],e=>{if(e.type===z.Fragment||e.props?.i18nIsDynamicList!==void 0){let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t!==`children`&&t!==`i18nIsDynamicList`&&(n[t]=e.props[t])}),(0,z.createElement)(e.type,n,i?null:t)}let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t!==`ref`&&t!==`children`&&(n[t]=e.props[t])}),(0,z.cloneElement)(e,n,i?null:t)}))},b=(e,n,o)=>{let f=H(e),m=H(n),h={};return m.reduce((e,n,m)=>{let g=n.children?.[0]?.content&&r.services.interpolator.interpolate(n.children[0].content,_,r.language);if(n.type===`tag`){let p=f[parseInt(n.name,10)];!p&&t&&(p=t[n.name]),o.length===1&&!p&&(p=o[0][n.name]),p||(p={});let x={...n.attrs};s&&Object.keys(x).forEach(e=>{let t=x[e];a(t)&&(x[e]=d(t))});let S=Object.keys(x).length===0?p:pe({props:x},p),C=(0,z.isValidElement)(S),w=C&&B(n,!0)&&!n.voidElement,ee=u&&c(S)&&S.dummy&&!C,T=c(t)&&Object.hasOwnProperty.call(t,n.name);if(a(S)){let t=r.services.interpolator.interpolate(S,_,r.language);e.push(t)}else if(B(S)||w){let t=v(S,n,o);y(S,t,e,m)}else if(ee){let t=b(f,n.children,o);y(S,t,e,m)}else if(Number.isNaN(parseFloat(n.name))){if(T){let t=v(S,n,o);y(S,t,e,m,n.voidElement)}else if(i.transSupportBasicHtmlNodes&&l.indexOf(n.name)>-1){if(n.voidElement)e.push((0,z.createElement)(n.name,{key:`${n.name}-${m}`}));else{let t=h[n.name]||0;h[n.name]=t+1;let r,i=0;for(let e=0;e<f.length;e+=1){let a=f[e];if((0,z.isValidElement)(a)&&a.type===n.name){if(i===t){r=a;break}i+=1}}let a=r?H(V(r)):f,s=b(a,n.children,o);e.push((0,z.createElement)(n.name,{key:`${n.name}-${m}`},s))}}else if(n.voidElement)e.push(`<${n.name} />`);else{let t=b(f,n.children,o);e.push(`<${n.name}>${t}</${n.name}>`)}}else if(c(S)&&!C){let t=n.children[0]?g:null;t&&e.push(t)}else y(S,g,e,m,n.children.length!==1||!g)}else if(n.type===`text`){let t=i.transWrapTextNodes,a=typeof i.unescape==`function`?i.unescape:p().unescape,o=s?a(r.services.interpolator.interpolate(n.content,_,r.language)):r.services.interpolator.interpolate(n.content,_,r.language);t?e.push((0,z.createElement)(t,{key:`${n.name}-${m}`},o)):e.push(o)}return e},[])};return V(b([{dummy:!0,children:e||[]}],g,H(e||[]))[0])},G=(e,t,n)=>{let r=e.key||t,i=(0,z.cloneElement)(e,{key:r});if(!i.props||!i.props.children||n.indexOf(`${t}/>`)<0&&n.indexOf(`${t} />`)<0)return i;function a(){return(0,z.createElement)(z.Fragment,null,i)}return(0,z.createElement)(a,{key:r})},he=(e,t)=>e.map((e,n)=>G(e,n,t)),ge=(e,t)=>{let n={};return Object.keys(e).forEach(r=>{Object.assign(n,{[r]:G(e[r],r,t)})}),n},_e=(e,t,n,r)=>e?Array.isArray(e)?he(e,t):c(e)?ge(e,t):(s(n,`TRANS_INVALID_COMPONENTS`,`<Trans /> "components" prop expects an object or array`,{i18nKey:r}),null):null,ve=e=>!c(e)||Array.isArray(e)?!1:Object.keys(e).reduce((e,t)=>e&&Number.isNaN(Number.parseFloat(t)),!0);function ye({children:e,count:t,parent:n,i18nKey:i,context:o,tOptions:c={},values:l,defaults:d,components:f,ns:m,i18n:h,t:g,shouldUnescape:_,...v}){let y=h||u();if(!y)return s(y,`NO_I18NEXT_INSTANCE`,`Trans: You need to pass in an i18next instance using initReactI18next or by passing it via props or context. In monorepo setups, make sure there is only one instance of react-i18next.`,{i18nKey:i}),e;let b=g||y.t.bind(y)||(e=>e),x={...p(),...y.options?.react},S=m||b.ns||y.options?.defaultNS;S=a(S)?[S]:S||[`translation`];let{transDefaultProps:C}=x,w=C?.tOptions?{...C.tOptions,...c}:c,ee=_??C?.shouldUnescape,T=C?.values?{...C.values,...l}:l,te=C?.components?{...C.components,...f}:f,E=U(e,x,y,i),D=d||w?.defaultValue||E||x.transEmptyNodeValue||(typeof i==`function`?r(i):i),{hashTransKey:ne}=x,O=i||(ne?ne(E||D):E||D);l=y.options?.interpolation?.defaultVariables?T&&Object.keys(T).length>0?{...T,...y.options.interpolation.defaultVariables}:{...y.options.interpolation.defaultVariables}:T;let k=me(e);k&&typeof k.count==`number`&&t===void 0&&(t=k.count);let A=l||t!==void 0&&!y.options?.interpolation?.alwaysFormat||!e?w.interpolation:{interpolation:{...w.interpolation,prefix:`#$?`,suffix:`?$#`}},re={...w,context:o||w.context,count:t,...l,...A,defaultValue:D,ns:S},j=O?b(O,re):D;j===O&&D&&(j=D);let M=_e(te,j,y,i),N=M||e,P=null;ve(M)&&(P=M,N=e);let F=W(N,P,j,y,x,re,ee),I=n??x.defaultTransParent;return I?(0,z.createElement)(I,v,F):F}function be({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:s,defaults:c,components:l,ns:d,i18n:f,t:p,shouldUnescape:m,...h}){let{i18n:g,defaultNS:_}=(0,z.useContext)(o)||{},v=f||g||u(),y=p||v?.t.bind(v);return ye({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a,values:s,defaults:c,components:l,ns:d||y?.ns||_||v?.options?.defaultNS,i18n:v,t:p,shouldUnescape:m,...h})}var K=n(),q=O(`pages:libre-claw`),xe={queued:`bg-gray-100 text-gray-700 dark:bg-dark-200 dark:text-dark-700`,running:`bg-primary-100 text-primary-700 dark:bg-primary-900/25 dark:text-primary-300`,blocked:`bg-amber-500/20 text-ink dark:bg-amber-900/30`,done:`bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300`,failed:`bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300`,cancelled:`bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300`},Se={assistant_message:`text-primary-600 dark:text-primary-300`,assistant_delta:`text-primary-600 dark:text-primary-300`,user_message:`text-gray-700 dark:text-dark-700`,permission_request:`text-ink`,permission_response:`text-gray-600 dark:text-dark-600`,tool_call:`text-gray-600 dark:text-dark-600`,tool_result:`text-gray-600 dark:text-dark-600`,usage:`text-gray-600 dark:text-dark-600`,error:`text-red-600 dark:text-red-300`,run_finished:`text-emerald-600 dark:text-emerald-300`},Ce=[[`lobster`,`Lobster`],[`lobster-light`,`Lobster Light`],[`github-dark`,`GitHub Dark`],[`github-light`,`GitHub Light`],[`monokai-pro`,`Monokai Pro`],[`night-owl`,`Night Owl`],[`tokyo-night`,`Tokyo Night`],[`ayu`,`Ayu`],[`dracula`,`Dracula`],[`catppuccin-mocha`,`Catppuccin Mocha`],[`catppuccin-latte`,`Catppuccin Latte`],[`gruvbox-dark`,`Gruvbox Dark`],[`nord`,`Nord`],[`solarized-dark`,`Solarized Dark`],[`solarized-light`,`Solarized Light`],[`one-dark-pro`,`One Dark Pro`],[`rose-pine`,`Rose Pine`],[`kanagawa`,`Kanagawa`],[`matrix`,`Matrix`]],we=()=>{let{t:e}=l(),[t,n]=(0,z.useState)(null),[r,i]=(0,z.useState)([]),[a,o]=(0,z.useState)([]),[s,c]=(0,z.useState)([]),[u,d]=(0,z.useState)(null),[p,O]=(0,z.useState)(null),[M,N]=(0,z.useState)(``),[P,F]=(0,z.useState)(null),[I,ie]=(0,z.useState)(!0),[ae,L]=(0,z.useState)(!1),[oe,se]=(0,z.useState)(!1),[ce,le]=(0,z.useState)(!1),[ue,de]=(0,z.useState)(!1),[R,B]=(0,z.useState)(``),[V,fe]=(0,z.useState)(`chat`),[H,pe]=(0,z.useState)(``),[me,U]=(0,z.useState)(``),[W,G]=(0,z.useState)(``),[he,ge]=(0,z.useState)(``),[_e,ve]=(0,z.useState)(!1),[ye,xe]=(0,z.useState)(`lobster`),[Se,we]=(0,z.useState)(!0),[ke,Ae]=(0,z.useState)(``),[je,Y]=(0,z.useState)(``),[X,Fe]=(0,z.useState)(``),[Ie,Le]=(0,z.useState)(`report`),Z=(0,z.useMemo)(()=>r.find(e=>e.run_id===P)||null,[r,P]),Q=(0,z.useMemo)(()=>{let e=new Set(a.filter(e=>e.type===`permission_response`).map(e=>String(e.data.tool_call_id||``)));return a.filter(t=>{if(t.type!==`permission_request`)return!1;let n=String(t.data.tool_call_id||``);return n&&!e.has(n)})},[a]),Re=(0,z.useMemo)(()=>Pe(a,e),[a,e]),$=(0,z.useCallback)(async()=>{try{let[e,t,r,a,o,s]=await Promise.all([k.status(),k.listRuns(30),k.currentModel(),k.currentFallback(),k.usage(``,100),k.listAutomations(50)]);e.success&&e.data&&n(e.data),t.success&&t.data&&(i(t.data.runs),F(e=>e||t.data?.runs[0]?.run_id||null)),r.success&&r.data&&(d(r.data),G(String(r.data.provider||``)),ge(String(r.data.model||``))),a.success&&a.data&&O(a.data),o.success&&o.data&&N(String(o.data.text||``)),s.success&&s.data&&c(s.data.automations)}catch(t){q.error(`Failed to load Libre Claw overview:`,t),S.error(e(`libreClaw.toasts.loadStatusFailed`))}finally{ie(!1)}},[e]),ze=(0,z.useCallback)(async(e,t=!1)=>{let n=t?0:a.length>0&&a[a.length-1]?.event_id||0;try{let r=await k.getEvents(e,n);r.success&&r.data&&o(e=>t?r.data?.events||[]:[...e,...r.data?.events||[]])}catch(e){q.error(`Failed to load Libre Claw events:`,e)}},[a]);(0,z.useEffect)(()=>{let e=window.setTimeout(()=>{$()},0);return()=>window.clearTimeout(e)},[$]),(0,z.useEffect)(()=>{if(!P){let e=window.setTimeout(()=>{o([])},0);return()=>window.clearTimeout(e)}let e=P;k.getEvents(e,0).then(e=>{e.success&&e.data&&o(e.data.events)}).catch(e=>{q.error(`Failed to load Libre Claw events:`,e)})},[P]),(0,z.useEffect)(()=>{if(!P||!Z||![`queued`,`running`,`blocked`].includes(Z.state))return;let e=window.setInterval(()=>{ze(P),k.listRuns(30).then(e=>{e.success&&e.data&&i(e.data.runs)})},1500);return()=>window.clearInterval(e)},[ze,Z,P]);let Be=async()=>{if(!R.trim()){S.error(e(`libreClaw.toasts.enterTask`));return}L(!0);try{let t=await k.startRun({message:R,kind:V,provider:H||void 0,model:me||void 0});if(t.success&&t.data){let n=t.data.run;i(e=>[n,...e.filter(e=>e.run_id!==n.run_id)]),F(n.run_id),B(``),S.success(e(`libreClaw.toasts.runStarted`))}else S.error(t.error||e(`libreClaw.toasts.startRunFailed`))}catch(t){q.error(`Failed to start Libre Claw run:`,t),S.error(e(`libreClaw.toasts.startRunFailed`))}finally{L(!1)}},Ve=async t=>{try{await k.cancelRun(t),await $(),S.success(e(`libreClaw.toasts.runCancelled`))}catch(t){q.error(`Failed to cancel Libre Claw run:`,t),S.error(e(`libreClaw.toasts.cancelRunFailed`))}},He=async(t,n)=>{if(!P)return;let r=String(t.data.tool_call_id||``);if(r)try{await k.resolvePermission(P,r,n),await ze(P,!0),S.success(e(n===`deny`?`libreClaw.toasts.denied`:`libreClaw.toasts.approved`))}catch(t){q.error(`Failed to resolve Libre Claw permission:`,t),S.error(e(`libreClaw.toasts.resolvePermissionFailed`))}},Ue=async()=>{if(!W.trim()||!he.trim()){S.error(e(`libreClaw.toasts.providerModelRequired`));return}se(!0);try{let t=await k.updateModel(W,he,_e);t.success&&t.data?(d(t.data),S.success(e(`libreClaw.toasts.modelUpdated`))):S.error(t.error||e(`libreClaw.toasts.updateModelFailed`))}catch(t){q.error(`Failed to update Libre Claw model:`,t),S.error(e(`libreClaw.toasts.updateModelFailed`))}finally{se(!1)}},We=async()=>{le(!0);try{let t=await k.updateTheme(ye,Se);t.success?S.success(e(`libreClaw.toasts.themeUpdated`)):S.error(t.error||e(`libreClaw.toasts.updateThemeFailed`))}catch(t){q.error(`Failed to update Libre Claw theme:`,t),S.error(e(`libreClaw.toasts.updateThemeFailed`))}finally{le(!1)}},Ge=async()=>{if(!ke.trim()||!je.trim()||!X.trim()){S.error(e(`libreClaw.toasts.automationRequired`));return}de(!0);try{let t=await k.createAutomation({name:ke,schedule:je,prompt:X,route:Ie});t.success?(Ae(``),Y(``),Fe(``),await $(),S.success(e(`libreClaw.toasts.automationCreated`))):S.error(t.error||e(`libreClaw.toasts.createAutomationFailed`))}catch(t){q.error(`Failed to create Libre Claw automation:`,t),S.error(e(`libreClaw.toasts.createAutomationFailed`))}finally{de(!1)}},Ke=async(t,n)=>{try{n===`pause`&&await k.pauseAutomation(t),n===`resume`&&await k.resumeAutomation(t),n===`run`&&await k.runAutomationNow(t),n===`delete`&&await k.deleteAutomation(t),await $(),S.success(e(`libreClaw.toasts.automationUpdated`))}catch(t){q.error(`Failed to update Libre Claw automation:`,t),S.error(e(`libreClaw.toasts.updateAutomationFailed`))}};return(0,K.jsxs)(j,{width:`wide`,contentClassName:`space-y-6`,children:[(0,K.jsx)(re,{className:`mb-0`,title:e(`libreClaw.title`),description:e(`libreClaw.subtitle`),actions:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Te,{status:t,t:e}),(0,K.jsxs)(A,{variant:`secondary`,size:`sm`,onClick:$,children:[(0,K.jsx)(x,{className:`h-4 w-4`}),e(`common.refresh`)]}),(0,K.jsxs)(`a`,{href:t?.dashboardUrl||`http://127.0.0.1:8766/dashboard`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex min-h-9 items-center gap-1.5 rounded-xl border border-gray-200/80 bg-white/70 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-white dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-700 dark:hover:bg-white/[0.08]`,children:[(0,K.jsx)(ne,{className:`h-4 w-4`}),e(`libreClaw.dashboard`)]})]})}),!t?.connected&&!I&&(0,K.jsx)(`section`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-4 text-ink dark:border-amber-800 dark:bg-amber-900/20`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(y,{className:`mt-0.5 h-5 w-5 shrink-0 text-amber-500`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`font-semibold`,children:e(`libreClaw.connection.disconnectedTitle`)}),(0,K.jsx)(`p`,{className:`mt-1 text-sm opacity-90`,children:(0,K.jsx)(be,{i18nKey:`libreClaw.connection.disconnectedDescription`,components:{command:(0,K.jsx)(`code`,{}),env:(0,K.jsx)(`code`,{})}})}),t?.error&&(0,K.jsx)(`p`,{className:`mt-2 text-xs opacity-80`,children:t.error})]})]})}),(0,K.jsxs)(`section`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,K.jsx)(J,{title:e(`libreClaw.startRun.title`),icon:(0,K.jsx)(m,{className:`h-4 w-4`}),children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`textarea`,{value:R,onChange:e=>B(e.target.value),placeholder:e(`libreClaw.startRun.placeholder`),className:`min-h-32 w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 outline-none transition focus:border-primary-400 focus:ring-2 focus:ring-primary-100 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800 dark:focus:border-primary-500 dark:focus:ring-primary-900/30`}),(0,K.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-4`,children:[(0,K.jsxs)(`select`,{value:V,onChange:e=>fe(e.target.value),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,K.jsx)(`option`,{value:`chat`,children:e(`libreClaw.startRun.chatRun`)}),(0,K.jsx)(`option`,{value:`goal`,children:e(`libreClaw.startRun.goalMode`)})]}),(0,K.jsx)(`input`,{value:H,onChange:e=>pe(e.target.value),placeholder:e(`libreClaw.startRun.providerOverride`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,K.jsx)(`input`,{value:me,onChange:e=>U(e.target.value),placeholder:e(`libreClaw.startRun.modelOverride`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,K.jsxs)(A,{onClick:Be,loading:ae,children:[(0,K.jsx)(E,{className:`h-4 w-4`}),e(`libreClaw.startRun.run`)]})]})]})}),(0,K.jsx)(J,{title:e(`libreClaw.modelRoute.title`),icon:(0,K.jsx)(h,{className:`h-4 w-4`}),children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-1`,children:[(0,K.jsx)(`input`,{value:W,onChange:e=>G(e.target.value),placeholder:e(`libreClaw.modelRoute.providerPlaceholder`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,K.jsx)(`input`,{value:he,onChange:e=>ge(e.target.value),placeholder:e(`libreClaw.modelRoute.modelPlaceholder`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-dark-600`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:_e,onChange:e=>ve(e.target.checked),className:`h-4 w-4 rounded border-gray-300 text-primary-600 focus:ring-primary-500`}),e(`libreClaw.modelRoute.persistGlobal`)]}),(0,K.jsx)(A,{variant:`secondary`,onClick:Ue,loading:oe,children:e(`libreClaw.modelRoute.saveModel`)}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 dark:border-dark-200`,children:[(0,K.jsx)(`label`,{className:`mb-1 block text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-500`,children:e(`libreClaw.modelRoute.theme`)}),(0,K.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] lg:grid-cols-1`,children:[(0,K.jsx)(`select`,{value:ye,onChange:e=>xe(e.target.value),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:Ce.map(([e,t])=>(0,K.jsx)(`option`,{value:e,children:t},e))}),(0,K.jsx)(A,{variant:`secondary`,onClick:We,loading:ce,children:e(`libreClaw.modelRoute.saveTheme`)})]}),(0,K.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-sm text-gray-600 dark:text-dark-600`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:Se,onChange:e=>we(e.target.checked),className:`h-4 w-4 rounded border-gray-300 text-primary-600 focus:ring-primary-500`}),e(`libreClaw.modelRoute.persistGlobal`)]})]}),u&&(0,K.jsx)(`pre`,{className:`max-h-32 overflow-auto rounded-lg bg-gray-100 p-2 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:JSON.stringify(u,null,2)})]})})]}),(0,K.jsxs)(`section`,{className:`grid gap-4 xl:grid-cols-[360px_minmax(0,1fr)]`,children:[(0,K.jsx)(J,{title:e(`libreClaw.runs.title`),icon:(0,K.jsx)(T,{className:`h-4 w-4`}),children:(0,K.jsxs)(`div`,{className:`space-y-2`,children:[r.length===0&&(0,K.jsx)(Me,{text:e(`libreClaw.runs.empty`)}),r.map(t=>(0,K.jsxs)(`button`,{onClick:()=>F(t.run_id),className:f(`w-full rounded-xl border p-3 text-start transition`,P===t.run_id?`border-primary-300 bg-primary-50 dark:border-primary-700 dark:bg-primary-900/20`:`border-gray-200 bg-white hover:bg-gray-50 dark:border-dark-300 dark:bg-dark-50 dark:hover:bg-dark-100`),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,children:t.title}),(0,K.jsx)(Ee,{state:t.state,t:e})]}),(0,K.jsxs)(`div`,{className:`mt-1 truncate text-xs text-gray-500 dark:text-dark-500`,children:[t.provider,`:`,t.model]}),(0,K.jsx)(`div`,{className:`mt-1 text-xs text-gray-400 dark:text-dark-500`,children:Ne(t.updated_at)})]},t.run_id))]})}),(0,K.jsxs)(J,{title:Z?Z.title:e(`libreClaw.timeline.title`),icon:(0,K.jsx)(w,{className:`h-4 w-4`}),actions:Z&&[`queued`,`running`,`blocked`].includes(Z.state)?(0,K.jsxs)(A,{variant:`danger`,size:`sm`,onClick:()=>Ve(Z.run_id),children:[(0,K.jsx)(g,{className:`h-4 w-4`}),e(`common.cancel`)]}):null,children:[Q.length>0&&(0,K.jsxs)(`div`,{className:`mb-4 space-y-2 rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800 dark:bg-amber-900/20`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-ink`,children:[(0,K.jsx)(v,{className:`h-4 w-4 text-amber-500`}),e(`libreClaw.approvals.needed`)]}),Q.map(t=>(0,K.jsxs)(`div`,{className:`rounded-lg bg-white/70 p-3 dark:bg-dark-50/70`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:String(t.data.name||e(`libreClaw.fallbacks.tool`))}),(0,K.jsx)(`pre`,{className:`mt-2 max-h-36 overflow-auto rounded bg-gray-100 p-2 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:JSON.stringify(t.data.arguments||{},null,2)}),(0,K.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,K.jsxs)(A,{size:`sm`,onClick:()=>He(t,`allow_once`),children:[(0,K.jsx)(_,{className:`h-4 w-4`}),e(`libreClaw.approvals.allowOnce`)]}),(0,K.jsx)(A,{size:`sm`,variant:`secondary`,onClick:()=>He(t,`always_allow_tool`),children:e(`libreClaw.approvals.alwaysAllowTool`)}),(0,K.jsxs)(A,{size:`sm`,variant:`danger`,onClick:()=>He(t,`deny`),children:[(0,K.jsx)(te,{className:`h-4 w-4`}),e(`libreClaw.approvals.deny`)]})]})]},t.event_id))]}),(0,K.jsxs)(`div`,{className:`space-y-3`,children:[a.length===0&&(0,K.jsx)(Me,{text:e(`libreClaw.timeline.empty`)}),Re.map(t=>(0,K.jsx)(Oe,{item:t,t:e},t.key))]})]})]}),(0,K.jsxs)(`section`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,K.jsx)(J,{title:e(`libreClaw.automations.title`),icon:(0,K.jsx)(b,{className:`h-4 w-4`}),children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,K.jsx)(`input`,{value:ke,onChange:e=>Ae(e.target.value),placeholder:e(`libreClaw.automations.namePlaceholder`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,K.jsx)(`input`,{value:je,onChange:e=>Y(e.target.value),placeholder:e(`libreClaw.automations.schedulePlaceholder`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,K.jsxs)(`select`,{value:Ie,onChange:e=>Le(e.target.value),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,K.jsx)(`option`,{value:`report`,children:e(`libreClaw.automations.routes.report`)}),(0,K.jsx)(`option`,{value:`telegram`,children:e(`libreClaw.automations.routes.telegram`)})]}),(0,K.jsx)(A,{onClick:Ge,loading:ue,children:e(`libreClaw.automations.create`)})]}),(0,K.jsx)(`textarea`,{value:X,onChange:e=>Fe(e.target.value),placeholder:e(`libreClaw.automations.promptPlaceholder`),className:`min-h-24 w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[s.length===0&&(0,K.jsx)(Me,{text:e(`libreClaw.automations.empty`)}),s.map(t=>(0,K.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-3 dark:border-dark-300 dark:bg-dark-50`,children:(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,children:t.name}),(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:[t.schedule,` ·`,` `,e(`libreClaw.automations.routes.${t.route}`,{defaultValue:t.route}),` `,`·`,` `,e(`libreClaw.automations.status.${t.status}`,{defaultValue:t.status})]})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,K.jsx)(De,{title:e(`libreClaw.automations.runNow`),onClick:()=>Ke(t.automation_id,`run`),children:(0,K.jsx)(m,{className:`h-4 w-4`})}),(0,K.jsx)(De,{title:t.status===`paused`?e(`libreClaw.automations.resume`):e(`libreClaw.automations.pause`),onClick:()=>Ke(t.automation_id,t.status===`paused`?`resume`:`pause`),children:t.status===`paused`?(0,K.jsx)(m,{className:`h-4 w-4`}):(0,K.jsx)(C,{className:`h-4 w-4`})}),(0,K.jsx)(De,{title:e(`common.delete`),danger:!0,onClick:()=>Ke(t.automation_id,`delete`),children:(0,K.jsx)(D,{className:`h-4 w-4`})})]})]})},t.automation_id))]})]})}),(0,K.jsx)(J,{title:e(`libreClaw.usageFallback.title`),icon:(0,K.jsx)(T,{className:`h-4 w-4`}),children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`mb-2 text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`libreClaw.usageFallback.usage`)}),(0,K.jsx)(`pre`,{className:`max-h-52 overflow-auto rounded-xl bg-gray-100 p-3 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:M||e(`libreClaw.usageFallback.noUsage`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`mb-2 text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`libreClaw.usageFallback.fallbackRoute`)}),(0,K.jsx)(`pre`,{className:`max-h-52 overflow-auto rounded-xl bg-gray-100 p-3 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:JSON.stringify(p||{},null,2)})]})]})})]}),I&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 flex items-center justify-center bg-white/60 backdrop-blur-sm dark:bg-dark-50/60`,children:(0,K.jsx)(ee,{className:`h-7 w-7 animate-spin text-primary-600`})})]})},Te=({status:e,t})=>{let n=!!e?.connected;return(0,K.jsxs)(`span`,{className:f(`inline-flex items-center gap-2 rounded-full px-3 py-1.5 text-sm font-medium`,n?`bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300`:`bg-amber-500/20 text-ink dark:bg-amber-900/30`),children:[(0,K.jsx)(`span`,{className:f(`h-2 w-2 rounded-full`,n?`bg-emerald-500`:`bg-amber-500`)}),t(n?`libreClaw.status.connected`:`libreClaw.status.disconnected`),e?.health?.active_runs!==void 0&&(0,K.jsxs)(`span`,{className:`opacity-70`,children:[`·`,` `,t(`libreClaw.status.activeRuns`,{count:e.health.active_runs})]})]})},Ee=({state:e,t})=>(0,K.jsx)(`span`,{className:f(`rounded-full px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide`,xe[e]||xe.queued),children:t(`libreClaw.states.${e}`,{defaultValue:e})}),J=({title:e,icon:t,actions:n,children:r})=>(0,K.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/60 dark:border-white/10 dark:bg-white/[0.03]`,children:[(0,K.jsxs)(`header`,{className:`flex items-center justify-between gap-3 border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08]`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-gray-900 dark:text-dark-900`,children:[(0,K.jsx)(`span`,{className:`text-primary-600 dark:text-primary-300`,children:t}),e]}),n]}),(0,K.jsx)(`div`,{className:`p-5`,children:r})]}),De=({title:e,danger:t,onClick:n,children:r})=>(0,K.jsx)(`button`,{type:`button`,title:e,onClick:n,className:f(`inline-flex h-8 w-8 items-center justify-center rounded-lg transition-colors`,t?`text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`:`text-gray-500 hover:bg-gray-100 dark:text-dark-500 dark:hover:bg-dark-200`),children:r}),Oe=({item:e,t})=>(0,K.jsxs)(`article`,{className:f(`rounded-xl border p-3 transition-colors`,e.eventType===`assistant_message`?`border-primary-200 bg-primary-50/60 dark:border-primary-900/60 dark:bg-primary-900/10`:(e.eventType,`border-gray-200/80 bg-white/50 dark:border-white/[0.08] dark:bg-white/[0.025]`)),children:[(0,K.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,K.jsx)(`span`,{className:f(`text-xs font-semibold uppercase tracking-wide`,Se[e.eventType]||`text-gray-500 dark:text-dark-500`),children:e.label}),(0,K.jsxs)(`span`,{className:`shrink-0 text-xs text-gray-400 dark:text-dark-500`,children:[Le(e),` · `,Ne(e.timestamp)]})]}),(0,K.jsx)(ke,{item:e,t})]}),ke=({item:e,t})=>{if(e.kind===`assistant_message`)return(0,K.jsx)(`p`,{className:`whitespace-pre-wrap text-sm leading-6 text-gray-900 dark:text-dark-900`,children:Fe(e.events)||t(`libreClaw.timeline.streaming`)});let n=e.events[0];return n?n.type===`assistant_delta`?(0,K.jsx)(`p`,{className:`whitespace-pre-wrap text-sm text-gray-800 dark:text-dark-800`,children:String(n.data.text||``)}):n.type===`user_message`?(0,K.jsx)(`p`,{className:`whitespace-pre-wrap text-sm text-gray-800 dark:text-dark-800`,children:String(n.data.content||``)}):n.type===`tool_call`?(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:String(n.data.name||t(`libreClaw.fallbacks.tool`))}),(0,K.jsx)(X,{value:n.data.arguments||{}})]}):n.type===`tool_result`?(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:[String(n.data.name||t(`libreClaw.fallbacks.tool`)),` ·`,` `,n.data.is_error?t(`libreClaw.timeline.resultError`):t(`libreClaw.timeline.resultOk`)]}),(0,K.jsx)(`pre`,{className:`mt-2 max-h-56 overflow-auto whitespace-pre-wrap rounded-lg bg-gray-100 p-2 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:String(n.data.content||``)})]}):n.type===`permission_request`?(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:String(n.data.name||t(`libreClaw.approvals.toolApprovalRequested`))}),(0,K.jsx)(X,{value:n.data.arguments||{}})]}):n.type===`permission_response`?(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,K.jsx)(Y,{label:t(`libreClaw.metrics.tool`),value:String(n.data.name||n.data.tool_call_id||t(`libreClaw.fallbacks.tool`))}),(0,K.jsx)(Y,{label:t(`libreClaw.metrics.resolution`),value:String(n.data.resolution||t(`libreClaw.fallbacks.resolved`))})]}):n.type===`usage`?(0,K.jsx)(Ae,{data:n.data,t}):n.type===`run_finished`?(0,K.jsx)(je,{data:n.data,t}):n.type===`error`?(0,K.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:String(n.data.message||t(`libreClaw.fallbacks.unknownError`))}):(0,K.jsx)(X,{value:n.data}):null},Ae=({data:e,t})=>(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,K.jsx)(Y,{label:t(`libreClaw.metrics.provider`),value:String(e.provider||t(`libreClaw.fallbacks.unknown`))}),(0,K.jsx)(Y,{label:t(`libreClaw.metrics.model`),value:String(e.model||t(`libreClaw.fallbacks.unknown`))}),(0,K.jsx)(Y,{label:t(`libreClaw.metrics.input`),value:t(`libreClaw.metrics.tokens`,{count:Z(e.input_tokens),formatted:Q(e.input_tokens)})}),(0,K.jsx)(Y,{label:t(`libreClaw.metrics.output`),value:t(`libreClaw.metrics.tokens`,{count:Z(e.output_tokens),formatted:Q(e.output_tokens)})}),Z(e.cached_tokens)>0&&(0,K.jsx)(Y,{label:t(`libreClaw.metrics.cached`),value:t(`libreClaw.metrics.tokens`,{count:Z(e.cached_tokens),formatted:Q(e.cached_tokens)})}),Z(e.reasoning_tokens)>0&&(0,K.jsx)(Y,{label:t(`libreClaw.metrics.reasoning`),value:t(`libreClaw.metrics.tokens`,{count:Z(e.reasoning_tokens),formatted:Q(e.reasoning_tokens)})}),(0,K.jsx)(Y,{label:t(`libreClaw.metrics.cost`),value:Re(e.cost)})]}),je=({data:e,t})=>(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,K.jsx)(Y,{label:t(`libreClaw.metrics.state`),value:t(`libreClaw.states.${String(e.state||`done`)}`,{defaultValue:String(e.state||`done`)})}),e.stop_reason!==void 0&&(0,K.jsx)(Y,{label:t(`libreClaw.metrics.stopReason`),value:String(e.stop_reason)})]}),Y=({label:e,value:t})=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-gray-200/80 bg-white/50 px-2.5 py-1 text-xs text-gray-700 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-700`,children:[(0,K.jsx)(`span`,{className:`font-semibold text-gray-500 dark:text-dark-500`,children:e}),(0,K.jsx)(`span`,{children:t})]}),X=({value:e})=>(0,K.jsx)(`pre`,{className:`mt-2 max-h-56 overflow-auto rounded-lg bg-gray-100 p-2 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:JSON.stringify(e,null,2)}),Me=({text:e})=>(0,K.jsx)(`div`,{className:`rounded-xl border border-dashed border-gray-300 bg-white/30 px-4 py-8 text-center text-sm text-gray-500 dark:border-white/15 dark:bg-white/[0.02] dark:text-dark-500`,children:e}),Ne=e=>{if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},Pe=(e,t)=>{let n=[],r=0;for(;r<e.length;){let i=e[r];if(!i)break;if(i.type===`assistant_delta`){let i=[];for(;e[r]?.type===`assistant_delta`;){let t=e[r];t&&i.push(t),r+=1}let a=i[0],o=i[i.length-1]||a;a&&o&&n.push({key:`assistant-${a.event_id}-${o.event_id}`,kind:`assistant_message`,eventType:`assistant_message`,label:t(`libreClaw.timeline.assistantResponse`),firstEventId:a.event_id,lastEventId:o.event_id,timestamp:a.timestamp,events:i});continue}n.push({key:`${i.type}-${i.event_id}`,kind:`event`,eventType:i.type,label:Ie(i.type,t),firstEventId:i.event_id,lastEventId:i.event_id,timestamp:i.timestamp,events:[i]}),r+=1}return n},Fe=e=>e.map(e=>String(e.data.text||``)).join(``),Ie=(e,t)=>({user_message:t(`libreClaw.timeline.labels.userMessage`),tool_call:t(`libreClaw.timeline.labels.toolCall`),tool_result:t(`libreClaw.timeline.labels.toolResult`),permission_request:t(`libreClaw.timeline.labels.approvalRequest`),permission_response:t(`libreClaw.timeline.labels.approvalResponse`),run_started:t(`libreClaw.timeline.labels.runStarted`),run_finished:t(`libreClaw.timeline.labels.runFinished`),usage:t(`libreClaw.timeline.labels.usage`),error:t(`libreClaw.timeline.labels.error`)})[e]||e.replace(/_/g,` `),Le=e=>e.firstEventId===e.lastEventId?`#${e.firstEventId}`:`#${e.firstEventId}-#${e.lastEventId}`,Z=e=>{let t=Number(e);return Number.isFinite(t)?t:0},Q=e=>new Intl.NumberFormat().format(Z(e)),Re=e=>{let t=Z(e);return t<=0?`$0.00`:t<.01?`$${t.toFixed(6)}`:`$${t.toFixed(4)}`};export{we as default};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{n as r}from"./react-vendor-BsJBHRYW.js";import{t as i}from"./useQuery-CoWV2PmJ.js";import{f as a}from"./router-vendor-BGP0k6Y2.js";import{t as o}from"./useTranslation-DrnYb6Cx.js";import{t as s}from"./utils-D9UstwTG.js";import{h as c,s as l,t as u}from"./chatStore-DkpmZLOG.js";import{A as d,An as f,At as p,Cn as m,Gn as h,Ht as g,Qn as _,S as ee,U as te,Wn as ne,Wt as v,Y as y,Z as re,_r as b,c as ie,n as x,nr as S,t as C,vn as w,xn as T,zt as ae}from"./ui-vendor-C0KwbTD4.js";import{t as oe}from"./logger-CpCQz3Vi.js";import{C as se,g as ce,y as E}from"./api-2DulPtq1.js";import{t as le}from"./authStore-DIvsSaOt.js";var D=e(t(),1),ue=r(),O=n();function k(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function de({hfTask:e,hfSort:t,canInstallModels:n,loadingHf:r,hfModels:i,expandedHfModel:a,hfGgufFiles:c,loadingGguf:l,pullingModel:u,pullProgress:d,setHfTask:f,setHfSort:m,onToggleHfModel:h,onPullHfGguf:_,onCancelPull:ee,onRefreshHfModels:te}){let{t:v}=o();return(0,O.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,O.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0 space-y-2`,children:(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsxs)(`select`,{value:e,onChange:e=>f(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,O.jsx)(`option`,{value:`text-generation`,children:v(`modelManager.huggingface.taskTextGeneration`)}),(0,O.jsx)(`option`,{value:`text-to-speech`,children:v(`modelManager.huggingface.taskTextToSpeech`)}),(0,O.jsx)(`option`,{value:`text-to-image`,children:v(`modelManager.huggingface.taskTextToImage`)}),(0,O.jsx)(`option`,{value:`automatic-speech-recognition`,children:v(`modelManager.huggingface.taskSpeechRecognition`)})]}),(0,O.jsxs)(`select`,{value:t,onChange:e=>m(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,O.jsx)(`option`,{value:`downloads`,children:v(`modelManager.huggingface.sortDownloads`)}),(0,O.jsx)(`option`,{value:`likes`,children:v(`modelManager.huggingface.sortLikes`)}),(0,O.jsx)(`option`,{value:`lastModified`,children:v(`modelManager.huggingface.sortRecent`)})]})]})}),(0,O.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin`,children:[!n&&(0,O.jsx)(`div`,{className:`mx-3 mb-1 mt-3 rounded-lg border border-amber-200 bg-amber-500/10 px-3 py-2 text-xs text-ink dark:border-amber-800 dark:bg-amber-900/20`,children:v(`modelSelector.pullRestricted`)}),r?(0,O.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,O.jsx)(p,{className:`h-6 w-6 animate-spin text-gray-400`})}):i.length===0?(0,O.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,O.jsx)(C,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,O.jsx)(`p`,{className:`text-sm`,children:v(`modelManager.huggingface.noModelsFound`)})]}):(0,O.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:i.map(e=>{let t=a===e.id,r=c[e.id]||[],i=l===e.id;return(0,O.jsxs)(`div`,{className:`bg-white dark:bg-dark-100`,children:[(0,O.jsx)(`div`,{className:`px-3 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-200`,onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),h(e.id)},children:(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`div`,{className:`flex-shrink-0 rounded-lg bg-yellow-500/20 p-2 dark:bg-yellow-900/30`,children:(0,O.jsx)(C,{className:`h-4 w-4 text-yellow-600 dark:text-yellow-400`})}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`h4`,{dir:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.id}),e.gated&&(0,O.jsx)(`span`,{className:`rounded bg-yellow-500/20 px-1.5 py-0.5 text-xs text-ink dark:bg-yellow-900/30`,children:`Gated`})]}),(0,O.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-0.5`,children:[`by `,e.author]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 text-xs text-gray-400 dark:text-gray-500`,children:[(0,O.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(T,{className:`h-3 w-3`}),k(e.downloads)]}),(0,O.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(g,{className:`h-3 w-3`}),k(e.likes)]}),e.pipeline_tag&&(0,O.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200`,children:e.pipeline_tag})]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,O.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,O.jsx)(w,{className:`h-4 w-4 text-gray-400`})}),(0,O.jsx)(ne,{className:s(`h-4 w-4 text-gray-400 transition-transform`,t&&`rotate-180`)})]})]})}),t&&(0,O.jsx)(`div`,{className:`px-3 pb-3 pt-1 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-200`,children:i?(0,O.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,O.jsx)(p,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,O.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:v(`modelManager.huggingface.checkingGguf`)})]}):r.length===0?(0,O.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:v(`modelManager.huggingface.noGgufAvailable`)}):(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 mb-2`,children:v(`modelManager.huggingface.ggufFilesCount`,{count:r.length})}),r.map(e=>{let t=u===e.ollamaCommand;return(0,O.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,O.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,O.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 truncate`,children:e.filename}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,O.jsx)(`span`,{children:e.sizeFormatted}),e.quantization&&(0,O.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,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:d?.percent===void 0?`...`:`${d.percent}%`}),(0,O.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),ee()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,O.jsx)(x,{className:`h-4 w-4`})})]}):n?(0,O.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),_(e.ollamaCommand,e.filename)},disabled:!!u,className:s(`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,O.jsx)(T,{className:`h-3 w-3 inline mr-1`}),v(`models.pull`)]}):(0,O.jsx)(`span`,{className:`rounded bg-amber-500/20 px-2 py-1 text-[11px] font-medium text-ink dark:bg-amber-900/30`,children:v(`modelSelector.adminOnlyPull`)})]},e.filename)}),u?.startsWith(`hf.co/`)&&u.includes(e.id)&&d?.percent!==void 0&&(0,O.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,O.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${d.percent}%`}})})]})})]},e.id)})})]}),(0,O.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,O.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,O.jsx)(w,{className:`h-3 w-3`}),v(`modelManager.huggingface.browseAllLink`)]}),(0,O.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),te()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,O.jsx)(y,{className:s(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}function fe({filteredGroups:e,selectedModel:t,showImageGen:n,getModelValue:r,getModelIcon:i,getModelLabel:a,getModelSubLabel:c,onModelSelect:l,onOpenGallery:u}){let{t:d}=o();return(0,O.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400`,children:[e.length>0?e.map(e=>(0,O.jsxs)(`div`,{children:[(0,O.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,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon,e.label,` (`,e.models.length,`)`]})}),e.models.map(e=>{let n=r(e);return(0,O.jsx)(`button`,{type:`button`,"data-testid":`model-selector-option`,"data-model-value":n,"aria-pressed":t===n,onClick:()=>l(n),className:s(`block w-full cursor-pointer border-b border-gray-100 px-3 py-3 text-start last:border-b-0 dark:border-dark-200`,`hover:bg-gray-50 dark:hover:bg-dark-200`,`bg-white dark:bg-dark-100 transition-colors`,`focus-visible:relative focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500/50`,t===n&&`bg-primary-50 dark:bg-primary-900/30`),children:(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[i(e),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,O.jsx)(`div`,{dir:e.isPersona?`auto`:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:a(e)}),c(e)&&(0,O.jsx)(`div`,{dir:`auto`,className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:c(e)})]}),t===n&&(0,O.jsx)(h,{className:`h-4 w-4 text-primary-600 dark:text-primary-400 flex-shrink-0`})]})},n)})]},e.type)):(0,O.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,O.jsx)(m,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,O.jsx)(`p`,{className:`text-sm`,children:d(`models.noModelsFound`)})]}),n&&(0,O.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-dark-300`,children:[(0,O.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,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(re,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),d(`modelSelector.actions`)]})}),(0,O.jsx)(`div`,{onMouseDown:e=>{e.preventDefault(),u()},className:`px-3 py-3 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-900/20 bg-white dark:bg-dark-100`,children:(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsx)(ae,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),(0,O.jsxs)(`div`,{className:`flex-1`,children:[(0,O.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:d(`gallery.generate`)}),(0,O.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d(`gallery.generateDescription`)})]})]})})]})]})}function pe({libraryCategories:e,libraryCategory:t,canInstallModels:n,loadingLibrary:r,filteredLibraryModels:i,pullingModel:a,pullProgress:c,setLibraryCategory:l,isModelInstalled:u,onModelSelect:d,onPullModel:m,onCancelPull:h,onRefreshLibrary:g}){let{t:_}=o();return(0,O.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,O.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0`,children:(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,O.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),l(e)},className:s(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,t===e?`bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-dark-300`),children:e.charAt(0).toUpperCase()+e.slice(1)},e))})}),(0,O.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin`,children:[!n&&(0,O.jsx)(`div`,{className:`mx-3 mb-1 mt-3 rounded-lg border border-amber-200 bg-amber-500/10 px-3 py-2 text-xs text-ink dark:border-amber-800 dark:bg-amber-900/20`,children:_(`modelSelector.pullRestricted`)}),r?(0,O.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,O.jsx)(p,{className:`h-6 w-6 animate-spin text-gray-400`})}):i.length===0?(0,O.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,O.jsx)(f,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,O.jsx)(`p`,{className:`text-sm`,children:_(`models.noModelsFound`)})]}):(0,O.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:i.map(e=>{let t=u(e.name),r=a===e.name;return(0,O.jsxs)(`div`,{className:s(`px-3 py-3 bg-white dark:bg-dark-100`,t&&`bg-green-50/50 dark:bg-green-900/10`),children:[(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(`div`,{className:`p-2 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex-shrink-0`,children:(0,O.jsx)(f,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`})}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`h4`,{dir:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.name}),t&&(0,O.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:_(`modelSelector.installed`)}),(e.category===`cloud`||e.tags?.includes(`cloud`))&&(0,O.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,O.jsx)(f,{className:`h-3 w-3`}),`Cloud`]})]}),(0,O.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 line-clamp-1 mt-0.5`,children:e.description}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[e.sizes.slice(0,3).map(e=>(0,O.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,O.jsxs)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1`,children:[(0,O.jsx)(T,{className:`h-3 w-3`}),e.pulls]})]})]}),(0,O.jsx)(`div`,{className:`flex-shrink-0`,children:r?(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:c?.percent===void 0?`...`:`${c.percent}%`}),(0,O.jsx)(`button`,{onClick:h,className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,O.jsx)(x,{className:`h-4 w-4`})})]}):t?(0,O.jsx)(`button`,{onClick:()=>d(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:_(`modelSelector.use`)}):n?(0,O.jsxs)(`button`,{onClick:()=>m(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,O.jsx)(T,{className:`h-3 w-3 inline mr-1`}),_(`modelSelector.pull`)]}):(0,O.jsx)(`span`,{className:`rounded bg-amber-500/20 px-2 py-1 text-[11px] font-medium text-ink dark:bg-amber-900/30`,children:_(`modelSelector.adminOnlyPull`)})})]}),r&&c?.percent!==void 0&&(0,O.jsx)(`div`,{className:`mt-2 w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden`,children:(0,O.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${c.percent}%`}})})]},e.name)})})]}),(0,O.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,O.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,O.jsx)(w,{className:`h-3 w-3`}),_(`modelManager.huggingface.browseAllLink`)]}),(0,O.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),g()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,O.jsx)(y,{className:s(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}var me=oe(`components:model-selector`),A=({models:e,selectedModel:t,onModelChange:n,currentPersona:r,className:p,disabled:m=!1,compact:h=!1,showImageGen:g=!1,onModelsRefresh:y,getModelValue:re,getModelLabel:w,getModelTitle:T,triggerRef:ae,triggerTestId:oe,selectTestId:k,ariaLabel:A})=>{let{t:j}=o(),[M,he]=(0,D.useState)(!1),[N,ge]=(0,D.useState)(``),[P,F]=(0,D.useState)(`installed`),_e=(0,D.useRef)(null),I=(0,D.useRef)(null),L=(0,D.useRef)(null),R=(0,D.useRef)(null),ve=a(),{user:ye,systemInfo:be}=le(),z=ye?.role===`admin`||be?.requiresAuth===!1,[B,xe]=(0,D.useState)(`all`),[Se,Ce]=(0,D.useState)(``),[V,we]=(0,D.useState)(`text-generation`),[H,Te]=(0,D.useState)(`downloads`),[Ee,De]=(0,D.useState)(``),[U,Oe]=(0,D.useState)(null),[W,ke]=(0,D.useState)({}),[Ae,je]=(0,D.useState)(null),[G,K]=(0,D.useState)(null),[Me,q]=(0,D.useState)(null),[Ne,J]=(0,D.useState)(null),Pe=[`all`,`general`,`coding`,`reasoning`,`vision`,`embedding`,`cloud`],Fe=[{type:`legacy`,label:j(`modelSelector.providerNotRecorded`,`Provider not recorded`),icon:(0,O.jsx)(_,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isLegacySelection),color:`gray`},{type:`unavailable`,label:j(`modelSelector.unavailableSelections`,`Unavailable selections`),icon:(0,O.jsx)(x,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isUnavailable&&!e.isLegacySelection),color:`gray`},{type:`personas`,label:j(`modelSelector.personas`),icon:(0,O.jsx)(ie,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPersona&&!e.isUnavailable),color:`purple`},{type:`agents`,label:j(`modelSelector.agentModels`,`Agents`),icon:(0,O.jsx)(ee,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isAgent&&!e.isUnavailable),color:`green`},{type:`ollama`,label:j(`modelSelector.ollamaModels`),icon:(0,O.jsx)(S,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>c(e)&&!e.name.includes(`embed`)),color:`green`},{type:`plugins`,label:j(`modelSelector.pluginModels`),icon:(0,O.jsx)(C,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPlugin&&!e.isUnavailable),color:`green`}].filter(e=>e.models.length>0).map(e=>({...e,models:e.models.filter(e=>e.name.toLowerCase().includes(N.toLowerCase())||e.personaName&&e.personaName.toLowerCase().includes(N.toLowerCase())||e.pluginName&&e.pluginName.toLowerCase().includes(N.toLowerCase()))})).filter(e=>e.models.length>0),Y=e=>re?.(e)??e.name,Ie=u(e=>e.modelMetadata),X=u(e=>e.personas),Z=e.find(e=>Y(e)===t),Le=e=>{if(!e.name.startsWith(`persona:`))return;let t=e.name.slice(8),n=t;try{n=decodeURIComponent(t)}catch{}let r=X[t]??X[n];if(r?.name)return r.name;if(e.personaName&&e.personaName!==t)return e.personaName},Re=e=>{if(!e.name.startsWith(`persona:`))return;let t=e.name.slice(8),n=t;try{n=decodeURIComponent(t)}catch{}return X[t]??X[n]};(0,D.useImperativeHandle)(ae,()=>L.current);let Q=(0,D.useCallback)((e=!0)=>{he(!1),ge(``),e&&window.requestAnimationFrame(()=>L.current?.focus())},[]),{data:ze=[],isLoading:Be,refetch:Ve}=i({queryKey:[`ollama-library-selector`,Se,B===`cloud`?`cloud`:`all`],queryFn:async()=>{let e=await E.getLibraryModels({search:Se||void 0,sort:`popular`,category:B===`cloud`?`cloud`:void 0});return e.success&&e.data?e.data:[]},enabled:M&&P===`ollama`}),{data:He=[],isLoading:Ue,refetch:We}=i({queryKey:[`hf-models-selector`,V,Ee,H],queryFn:async()=>{let e=await se.getModels({task:V,search:Ee||void 0,sort:H,limit:30});return e.success&&e.data?e.data:[]},enabled:M&&P===`huggingface`}),Ge=ze.filter(e=>{let t=!N||e.name.toLowerCase().includes(N.toLowerCase())||e.description.toLowerCase().includes(N.toLowerCase()),n=B===`all`||e.category===B;return t&&n}),Ke=(0,D.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){je(e);try{let r=await se.getGgufFiles(t,n);r.success&&r.data&&ke(t=>({...t,[e]:r.data}))}catch(e){me.error(`Failed to load GGUF files:`,e)}finally{je(null)}}},[]),qe=(0,D.useCallback)(e=>{U===e?Oe(null):(Oe(e),W[e]||Ke(e))},[U,W,Ke]),Je=(0,D.useCallback)((e,t)=>{if(!z){b.error(j(`modelSelector.pullRestricted`));return}if(!G){K(e),q({status:`starting`});try{let n=E.pullModelStream(e,e=>{q(e)},()=>{q(null),K(null),J(null),b.success(j(`modelDownload.success`,{name:t})),y?.()},e=>{q(null),K(null),J(null),b.error(j(`modelDownload.failed`,{error:e}))});J(()=>n)}catch{q(null),K(null),b.error(j(`modelDownload.startFailed`))}}},[z,y,G,j]);(0,D.useEffect)(()=>{let e=setTimeout(()=>{P===`huggingface`?De(N):P===`ollama`&&Ce(N)},300);return()=>clearTimeout(e)},[N,P]),(0,D.useEffect)(()=>{if(!M)return;let e=e=>{if(e.key===`Escape`){e.preventDefault(),Q();return}if(e.key===`Tab`&&I.current){let t=Array.from(I.current.querySelectorAll(`button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`)).filter(e=>e.offsetParent!==null),n=t[0],r=t[t.length-1];if(!n||!r)return;e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus())}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Q,M]),(0,D.useEffect)(()=>{M&&R.current&&R.current.focus()},[M]);let Ye=async t=>{let r=e.find(e=>Y(e)===t)??e.find(e=>!e.isPlugin&&!e.isPersona&&e.name===t),i=r?Y(r):t,a=r?.name??t;Q();try{let e=await E.listRunningModels();if(e.success&&e.data){let t=e.data;t.length>0&&(r?.isPlugin!==!0&&t.some(e=>e.name===a||a.startsWith(`persona:`))||await E.unloadAllModels())}}catch(e){me.warn(`Failed to unload models before switch:`,e)}n({target:{value:i}})},Xe=async e=>{if(!z){b.error(j(`modelSelector.pullRestricted`));return}if(!G){K(e),q({status:`starting`});try{let t=E.pullModelStream(e,e=>{q(e)},()=>{q(null),K(null),J(null),b.success(j(`modelDownload.success`,{name:e})),y?.()},e=>{q(null),K(null),J(null),b.error(j(`modelDownload.failed`,{error:e}))});J(()=>t)}catch{q(null),K(null),b.error(j(`modelDownload.startFailed`))}}},Ze=()=>{Ne&&(Ne(),J(null),K(null),q(null),b.success(j(`modelDownload.cancelled`)))},Qe=t=>e.some(e=>c(e)&&(e.name===t||e.name.startsWith(t+`:`))),$e=e=>{let t=Ie[l(e)]?.avatar;if(t&&!e.isPersona)return(0,O.jsx)(`img`,{src:t,alt:``,className:`h-4 w-4 shrink-0 rounded-full object-cover`});if(e.isPersona||e.isLegacySelection){let t=Re(e);if(t)return(0,O.jsx)(`img`,{src:ce(t,64),alt:``,className:`h-4 w-4 shrink-0 rounded object-cover`})}return e.isLegacySelection?(0,O.jsx)(_,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):e.isPersona?(0,O.jsx)(ie,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):e.isPlugin?(0,O.jsx)(C,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):(0,O.jsx)(S,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`})},$=e=>{if(w)return w(e);let t=Ie[l(e)]?.label;return t&&!e.isPersona?t:e.isLegacySelection?`${Le(e)??e.name} (${j(`modelSelector.legacyProvider`,`provider not recorded`)})`:e.isPersona?Le(e)||e.personaName||e.name:e.isAgent?e.isUnavailable?`${e.agentName||e.name} (${j(`modelSelector.unavailable`,`unavailable`)})`:e.agentName||e.name:(e.isPlugin,e.isUnavailable?`${e.name} (${j(`modelSelector.unavailable`,`unavailable`)})`:e.name)},et=e=>e.isLegacySelection?e.isUnavailable?j(`modelSelector.providerUnavailable`,`provider unavailable`):j(`modelSelector.reselectProvider`,`reselect a provider to pin this model`):e.isPersona?`via ${e.model}`:e.isPlugin?e.isUnavailable?`via ${e.pluginName||e.pluginId} · ${j(`modelSelector.providerUnavailable`,`provider unavailable`)}`:`via ${e.pluginName}`:e.isUnavailable?j(`modelSelector.providerUnavailable`,`provider unavailable`):null;return(0,O.jsxs)(`div`,{className:s(`relative`,p),ref:_e,children:[(0,O.jsxs)(`button`,{ref:L,"data-testid":oe,type:`button`,onClick:()=>!m&&he(!M),disabled:m,"aria-haspopup":`dialog`,"aria-expanded":M,"aria-label":A&&Z?`${A}: ${$(Z)}`:A,className:s(h?`h-9 sm:h-10 px-2.5 flex items-center justify-between text-start w-full`:`w-full flex items-center justify-between gap-2 px-3 py-2.5 text-start`,`border border-black/[0.06] bg-gray-100/70 dark:border-white/[0.06] dark:bg-dark-300/70`,`rounded-xl text-sm hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500/40`,m?`opacity-50 cursor-not-allowed`:`cursor-pointer`),title:h?Z?T?.(Z)??$(Z):j(`modelSelector.selectModel`):void 0,children:[(()=>{if(!Z)return h?(0,O.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,O.jsx)(S,{className:`h-4 w-4`}),(0,O.jsx)(`span`,{className:`text-xs font-medium text-gray-400 dark:text-gray-500 truncate`,children:j(`modelSelector.selectModel`)})]}):j(`modelSelector.selectModel`);if(h){let e=$(Z);return(0,O.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[$e(Z),(0,O.jsx)(`span`,{dir:Z.isPersona?`auto`:`ltr`,className:`text-xs font-medium text-gray-700 dark:text-gray-200 truncate`,children:e})]})}let e=$(Z),t=et(Z);return(0,O.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[$e(Z),(0,O.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,O.jsx)(`span`,{dir:Z.isPersona?`auto`:`ltr`,className:`text-sm font-medium truncate`,children:e}),t&&(0,O.jsx)(`span`,{dir:`auto`,className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:t})]}),Z.isPersona&&r&&(0,O.jsxs)(`div`,{className:`flex items-center gap-1 ms-auto`,children:[(0,O.jsx)(_,{className:`h-3 w-3 text-gray-500 dark:text-dark-600`}),r.embedding_model&&(0,O.jsx)(d,{className:`h-3 w-3 text-gray-400 dark:text-dark-500`})]})]})})(),(0,O.jsx)(ne,{className:s(h?`h-3 w-3`:`h-4 w-4`,`text-gray-400 flex-shrink-0 transition-transform duration-150`,M&&`rotate-180`)})]}),M&&(0,ue.createPortal)((0,O.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-3 sm:p-6`,children:[(0,O.jsx)(`div`,{className:`absolute inset-0 bg-gray-950/55 backdrop-blur-md`,onClick:()=>Q()}),(0,O.jsxs)(`div`,{ref:I,role:`dialog`,"aria-modal":`true`,"aria-label":j(`modelSelector.selectModel`),className:s(`relative flex w-full max-w-xl flex-col overflow-hidden bg-white/[0.98] dark:bg-dark-25/[0.98]`,`h-[min(620px,88vh)] rounded-[1.5rem] border border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_30px_100px_rgba(0,0,0,0.28)] backdrop-blur-xl animate-scale-in`),onClick:e=>e.stopPropagation(),children:[(0,O.jsxs)(`div`,{className:`flex-shrink-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4 sm:px-5 sm:pt-5`,children:[(0,O.jsx)(`h2`,{className:`text-lg font-medium tracking-[-0.025em] text-gray-950 dark:text-dark-950 rtl:tracking-normal`,children:j(`modelSelector.selectModel`)}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>Q(),className:`flex h-9 w-9 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-950 dark:text-dark-500 dark:hover:bg-dark-200 dark:hover:text-dark-950`,title:j(`common.close`),children:(0,O.jsx)(x,{className:`h-4 w-4`})})]}),(0,O.jsx)(`div`,{className:`px-4 pb-3 sm:px-5`,children:(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(te,{className:`absolute start-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400`}),(0,O.jsx)(`input`,{ref:R,type:`text`,placeholder:j(P===`installed`?`modelSelector.searchInstalled`:P===`ollama`?`modelSelector.searchOllama`:`modelSelector.searchHuggingFace`),value:N,onChange:e=>ge(e.target.value),className:s(`w-full rounded-xl border border-black/[0.07] bg-gray-100/70 py-2.5 ps-10 pe-4 text-sm dark:border-white/[0.07] dark:bg-dark-200/70`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`text-gray-900 dark:text-dark-900 placeholder:text-gray-400 dark:placeholder:text-dark-500`)})]})}),(0,O.jsxs)(`div`,{className:`mx-4 mb-3 flex rounded-xl bg-gray-100/70 p-1 dark:bg-dark-200/70 sm:mx-5`,children:[(0,O.jsxs)(`button`,{onClick:()=>{F(`installed`)},className:s(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,P===`installed`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":P===`installed`,children:[(0,O.jsx)(v,{className:`h-4 w-4 inline me-1.5`}),j(`modelSelector.installed`)]}),(0,O.jsxs)(`button`,{onClick:()=>{F(`ollama`)},className:s(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,P===`ollama`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":P===`ollama`,children:[(0,O.jsx)(f,{className:`h-4 w-4 inline me-1.5`}),`Ollama`]}),(0,O.jsxs)(`button`,{onClick:()=>{F(`huggingface`)},className:s(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,P===`huggingface`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":P===`huggingface`,children:[(0,O.jsx)(C,{className:`h-4 w-4 inline me-1.5`}),`HuggingFace`]})]})]}),P===`installed`&&(0,O.jsx)(fe,{filteredGroups:Fe,selectedModel:t,showImageGen:g,getModelValue:Y,getModelIcon:$e,getModelLabel:$,getModelSubLabel:et,onModelSelect:Ye,onOpenGallery:()=>{Q(!1),ve(`/gallery`)}}),P===`ollama`&&(0,O.jsx)(pe,{libraryCategories:Pe,libraryCategory:B,canInstallModels:z,loadingLibrary:Be,filteredLibraryModels:Ge,pullingModel:G,pullProgress:Me,setLibraryCategory:xe,isModelInstalled:Qe,onModelSelect:Ye,onPullModel:Xe,onCancelPull:Ze,onRefreshLibrary:()=>{Ve()}}),P===`huggingface`&&(0,O.jsx)(de,{hfTask:V,hfSort:H,canInstallModels:z,loadingHf:Ue,hfModels:He,expandedHfModel:U,hfGgufFiles:W,loadingGguf:Ae,pullingModel:G,pullProgress:Me,setHfTask:we,setHfSort:Te,onToggleHfModel:qe,onPullHfGguf:Je,onCancelPull:Ze,onRefreshHfModels:()=>{We()}})]})]}),document.body),(0,O.jsx)(`select`,{"data-testid":k,"aria-label":A,"aria-hidden":`true`,dir:`ltr`,value:t,onChange:n,className:`hidden`,tabIndex:-1,children:e.map(e=>(0,O.jsx)(`option`,{value:Y(e),children:$(e)},`${e.isLegacySelection?`legacy`:e.isPersona?`persona`:e.isPlugin?`plugin`:`ollama`}:${e.pluginId||``}:${Y(e)}`))})]})};export{A as t};
@@ -1,3 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{i as r}from"./router-vendor-BGP0k6Y2.js";import{t as i}from"./useTranslation-DrnYb6Cx.js";import{r as a,t as o}from"./utils-D9UstwTG.js";import{t as s}from"./chatStore-DkpmZLOG.js";import{A as c,M as l,R as u,U as ee,Z as d,_r as f,at as p,et as m,gn as h,jt as g,m as _,n as v,nt as te,q as y,s as b,ur as ne,ut as x,v as re,xn as ie}from"./ui-vendor-C0KwbTD4.js";import{t as S}from"./logger-CpCQz3Vi.js";import{A as C,k as w}from"./api-2DulPtq1.js";import{t as T}from"./Button--pDOakZx.js";import"./ui-DUzqxWMk.js";import{t as ae}from"./RichMessageContent-CC9QZQKd.js";var E=e(t(),1),D=4e3,O=(e,t)=>{let n=e.split(`
2
- `),r=t.split(`
3
- `);if(n.length>D||r.length>D)return[...n.map(e=>({type:`removed`,text:e})),...r.map(e=>({type:`added`,text:e}))];let i=Array.from({length:n.length+1},()=>Array(r.length+1).fill(0));for(let e=n.length-1;e>=0;--e)for(let t=r.length-1;t>=0;--t)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({type:`context`,text:n[o]}),o+=1,s+=1):i[o+1][s]>=i[o][s+1]?(a.push({type:`removed`,text:n[o]}),o+=1):(a.push({type:`added`,text:r[s]}),s+=1);for(;o<n.length;)a.push({type:`removed`,text:n[o]}),o+=1;for(;s<r.length;)a.push({type:`added`,text:r[s]}),s+=1;return a},k=e=>e.some(e=>e.type!==`context`),A=n(),j=S(`components:note-tools`),M=({rows:e})=>(0,A.jsx)(`div`,{className:`max-h-64 overflow-auto rounded-lg border border-black/[0.06] font-mono text-[12px] leading-relaxed dark:border-white/[0.08]`,"data-testid":`note-diff-view`,children:e.map((e,t)=>(0,A.jsx)(`div`,{className:o(`whitespace-pre-wrap px-2`,e.type===`added`&&`bg-[rgb(76,212,117)]/[0.12] text-green-800 dark:text-green-300`,e.type===`removed`&&`bg-[rgb(255,61,129)]/[0.10] text-red-800 line-through dark:text-red-300`,e.type===`context`&&`text-gray-600 dark:text-dark-700`),children:e.text||`\xA0`},t))}),N=({note:e,currentContent:t,currentTitle:n,canWrite:r,isOwner:l,initialTab:ee,onClose:d,onApplyContent:m})=>{let{t:h,i18n:te}=i(),[b,ne]=(0,E.useState)(ee),[x,S]=(0,E.useState)(null),[ae,D]=(0,E.useState)(null),[N,P]=(0,E.useState)(null),[oe,F]=(0,E.useState)(!1),I=(0,E.useRef)(null),[L,se]=(0,E.useState)(null),[R,z]=(0,E.useState)(``),[B,V]=(0,E.useState)(`read`),[H,U]=(0,E.useState)(!1),[W,G]=(0,E.useState)(``),[K,ce]=(0,E.useState)(!1),[q,J]=(0,E.useState)(null),Y=s(e=>e.selectedModel),le=s(e=>e.selectedProviderType),ue=s(e=>e.selectedProviderId),X=(0,E.useCallback)(()=>{C.getRevisions(e.id).then(e=>{e.success&&Array.isArray(e.data)&&S(e.data)}).catch(e=>j.error(`Failed to load revisions:`,e))},[e.id]),Z=(0,E.useCallback)(()=>{C.getAttachments(e.id).then(e=>{e.success&&Array.isArray(e.data)&&P(e.data)}).catch(e=>j.error(`Failed to load attachments:`,e))},[e.id]),Q=(0,E.useCallback)(()=>{w.listGrants(`note`,e.id).then(e=>{e.success&&Array.isArray(e.data)&&se(e.data)}).catch(e=>j.error(`Failed to load shares:`,e))},[e.id]);(0,E.useEffect)(()=>{b===`revisions`&&x===null&&X(),b===`attachments`&&N===null&&Z(),b===`share`&&l&&L===null&&Q()},[b,x,N,L,l,X,Z,Q]);let de=async t=>{try{let n=await C.restoreRevision(e.id,t);n.success&&n.data?(m(n.data.content,n.data.title),S(null),D(null),f.success(h(`notes.revisionRestored`))):f.error(n.error||h(`notes.revisionRestoreFailed`))}catch(e){j.error(`Failed to restore revision:`,e),f.error(h(`notes.revisionRestoreFailed`))}},fe=async t=>{if(!(!t||t.length===0)){F(!0);try{let n=await C.uploadAttachment(e.id,t[0]);n.success?(Z(),f.success(h(`notes.attachmentAdded`))):f.error(n.error||h(`notes.attachmentFailed`))}catch(e){j.error(`Failed to upload attachment:`,e),f.error(h(`notes.attachmentFailed`))}finally{F(!1),I.current&&(I.current.value=``)}}},pe=async t=>{try{let n=await C.downloadAttachment(e.id,t.id),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t.filename,i.click(),URL.revokeObjectURL(r)}catch(e){j.error(`Failed to download attachment:`,e),f.error(h(`notes.attachmentDownloadFailed`))}},me=async t=>{try{(await C.deleteAttachment(e.id,t)).success&&Z()}catch(e){j.error(`Failed to delete attachment:`,e)}},he=async()=>{let t=R.trim();if(t){U(!0);try{let n=await w.resolvePrincipal(t);if(!n.success||!n.data){f.error(h(`notes.shareUserNotFound`));return}let r=await w.createGrant({resourceType:`note`,resourceId:e.id,principalType:`user`,principalId:n.data.id,permission:B});r.success?(z(``),Q(),f.success(h(`notes.shareAdded`,{username:t}))):f.error(r.error||h(`notes.shareFailed`))}catch(e){j.error(`Failed to share note:`,e),f.error(h(`notes.shareFailed`))}finally{U(!1)}}},ge=async e=>{try{(await w.deleteGrant(e)).success&&Q()}catch(e){j.error(`Failed to revoke share:`,e)}},_e=async()=>{if(!(!W.trim()||!Y)){ce(!0),J(null);try{let t=await C.assist(e.id,{instruction:W,model:Y,providerType:le,providerId:ue});t.success&&t.data?.content!==void 0?J(t.data.content):f.error(t.error||h(`notes.assistFailed`))}catch(e){j.error(`Note assist failed:`,e),f.error(h(`notes.assistFailed`))}finally{ce(!1)}}},$=(0,E.useMemo)(()=>q===null?null:O(t,q),[q,t]),ve=[{id:`revisions`,icon:(0,A.jsx)(y,{className:`h-3.5 w-3.5`}),label:h(`notes.revisions`)},{id:`attachments`,icon:(0,A.jsx)(p,{className:`h-3.5 w-3.5`}),label:h(`notes.attachments`)},{id:`share`,icon:(0,A.jsx)(u,{className:`h-3.5 w-3.5`}),label:h(`notes.share`),hidden:!l},{id:`assist`,icon:(0,A.jsx)(c,{className:`h-3.5 w-3.5`}),label:h(`notes.assist`),hidden:!r}];return(0,A.jsxs)(`div`,{className:`absolute inset-y-0 end-0 z-30 flex w-full max-w-md flex-col border-s border-black/[0.06] bg-surface shadow-xl dark:border-white/[0.07] dark:bg-dark-100`,"data-testid":`note-tools-drawer`,role:`dialog`,"aria-label":h(`notes.tools`),children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-black/[0.06] px-3 py-2 dark:border-white/[0.07]`,children:[ve.filter(e=>!e.hidden).map(e=>(0,A.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":b===e.id,onClick:()=>ne(e.id),"data-testid":`note-tools-tab-${e.id}`,className:o(`flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[12px] transition-colors`,b===e.id?`bg-black/[0.06] text-gray-900 dark:bg-white/[0.08] dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:[e.icon,e.label]},e.id)),(0,A.jsx)(`button`,{type:`button`,onClick:d,className:`ms-auto rounded-md p-1.5 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":h(`common.close`),"data-testid":`note-tools-close`,children:(0,A.jsx)(v,{className:`h-4 w-4`})})]}),(0,A.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 scrollbar-thin`,children:[b===`revisions`&&(0,A.jsx)(`div`,{className:`space-y-2`,children:x===null?(0,A.jsx)(g,{className:`mx-auto h-4 w-4 animate-spin text-gray-400`}):x.length===0?(0,A.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:h(`notes.noRevisions`)}):x.map(e=>(0,A.jsxs)(`div`,{className:`rounded-lg border border-black/[0.06] p-2.5 dark:border-white/[0.08]`,"data-testid":`note-revision-item`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,A.jsxs)(`button`,{type:`button`,onClick:()=>D(t=>t===e.id?null:e.id),className:`min-w-0 flex-1 truncate text-start text-[13px] text-gray-800 dark:text-dark-800`,children:[a(e.createdAt,te.language),e.title!==n&&(0,A.jsxs)(`span`,{className:`ms-1 text-gray-400 dark:text-dark-500`,children:[`· `,e.title||h(`notes.untitled`)]})]}),r&&(0,A.jsxs)(T,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-[11px]`,onClick:()=>void de(e.id),"data-testid":`note-revision-restore`,children:[(0,A.jsx)(_,{className:`h-3 w-3`}),h(`notes.restore`)]})]}),ae===e.id&&(0,A.jsx)(`div`,{className:`mt-2`,children:(0,A.jsx)(M,{rows:O(e.content,t)})})]},e.id))}),b===`attachments`&&(0,A.jsxs)(`div`,{className:`space-y-2`,children:[r&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`input`,{ref:I,type:`file`,className:`hidden`,onChange:e=>void fe(e.target.files),"data-testid":`note-attachment-input`}),(0,A.jsxs)(T,{size:`sm`,variant:`outline`,className:`w-full gap-1.5`,disabled:oe,onClick:()=>I.current?.click(),"data-testid":`note-attachment-upload`,children:[oe?(0,A.jsx)(g,{className:`h-3.5 w-3.5 animate-spin`}):(0,A.jsx)(p,{className:`h-3.5 w-3.5`}),h(`notes.addAttachment`)]})]}),N===null?(0,A.jsx)(g,{className:`mx-auto h-4 w-4 animate-spin text-gray-400`}):N.length===0?(0,A.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:h(`notes.noAttachments`)}):N.map(e=>(0,A.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/[0.06] px-2.5 py-2 dark:border-white/[0.08]`,"data-testid":`note-attachment-item`,children:[(0,A.jsx)(p,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,A.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.filename}),(0,A.jsxs)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:[Math.max(1,Math.round(e.size/1024)),` KB`]}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>void pe(e),className:`rounded-md p-1 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,title:h(`common.download`),children:(0,A.jsx)(ie,{className:`h-3.5 w-3.5`})}),r&&(0,A.jsx)(`button`,{type:`button`,onClick:()=>void me(e.id),className:`rounded-md p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:h(`common.delete`),children:(0,A.jsx)(re,{className:`h-3.5 w-3.5`})})]},e.id))]}),b===`share`&&l&&(0,A.jsxs)(`div`,{className:`space-y-3`,children:[(0,A.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,A.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),onKeyDown:e=>{e.key===`Enter`&&he()},placeholder:h(`notes.shareUsernamePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/[0.08] bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.1] dark:text-dark-900`,"data-testid":`note-share-username`}),(0,A.jsxs)(`select`,{value:B,onChange:e=>V(e.target.value),className:`rounded-lg border border-black/[0.08] bg-transparent px-2 py-1.5 text-[12px] text-gray-700 focus:outline-none dark:border-white/[0.1] dark:bg-dark-100 dark:text-dark-800`,"data-testid":`note-share-permission`,children:[(0,A.jsx)(`option`,{value:`read`,children:h(`notes.permissionRead`)}),(0,A.jsx)(`option`,{value:`write`,children:h(`notes.permissionWrite`)})]}),(0,A.jsx)(T,{size:`sm`,disabled:H||!R.trim(),onClick:()=>void he(),"data-testid":`note-share-submit`,children:H?(0,A.jsx)(g,{className:`h-3.5 w-3.5 animate-spin`}):h(`notes.shareAction`)})]}),L===null?(0,A.jsx)(g,{className:`mx-auto h-4 w-4 animate-spin text-gray-400`}):L.length===0?(0,A.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:h(`notes.notShared`)}):L.map(e=>(0,A.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/[0.06] px-2.5 py-2 dark:border-white/[0.08]`,"data-testid":`note-share-item`,children:[(0,A.jsx)(u,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,A.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.principalId}),(0,A.jsx)(`span`,{className:`shrink-0 text-[11px] uppercase text-gray-400 dark:text-dark-500`,children:e.permission}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>void ge(e.id),className:`rounded-md p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:h(`notes.revokeShare`),children:(0,A.jsx)(v,{className:`h-3.5 w-3.5`})})]},e.id)),(0,A.jsx)(`p`,{className:`text-[11px] leading-relaxed text-gray-400 dark:text-dark-500`,children:h(`notes.shareHint`)})]}),b===`assist`&&r&&(0,A.jsxs)(`div`,{className:`space-y-3`,children:[(0,A.jsx)(`textarea`,{value:W,onChange:e=>G(e.target.value),placeholder:h(`notes.assistPlaceholder`),rows:3,className:`w-full resize-none rounded-lg border border-black/[0.08] bg-transparent px-2.5 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.1] dark:text-dark-900`,"data-testid":`note-assist-instruction`}),(0,A.jsxs)(T,{size:`sm`,className:`w-full gap-1.5`,disabled:K||!W.trim()||!Y,onClick:()=>void _e(),"data-testid":`note-assist-generate`,children:[K?(0,A.jsx)(g,{className:`h-3.5 w-3.5 animate-spin`}):(0,A.jsx)(c,{className:`h-3.5 w-3.5`}),h(`notes.assistGenerate`)]}),!Y&&(0,A.jsx)(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:h(`notes.assistNoModel`)}),q!==null&&$&&(0,A.jsxs)(`div`,{className:`space-y-2`,children:[k($)?(0,A.jsx)(M,{rows:$}):(0,A.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:h(`notes.assistNoChanges`)}),(0,A.jsxs)(`div`,{className:`flex gap-2`,children:[(0,A.jsx)(T,{size:`sm`,className:`flex-1`,disabled:!k($),onClick:()=>{m(q),J(null),G(``),f.success(h(`notes.assistApplied`))},"data-testid":`note-assist-apply`,children:h(`notes.assistApply`)}),(0,A.jsx)(T,{size:`sm`,variant:`outline`,className:`flex-1`,onClick:()=>J(null),"data-testid":`note-assist-discard`,children:h(`notes.assistDiscard`)})]}),(0,A.jsx)(`p`,{className:`text-[11px] leading-relaxed text-gray-400 dark:text-dark-500`,children:h(`notes.assistRevisionHint`)})]})]})]})]})},P=S(`pages:notes`),oe=800,F=()=>{let{t:e,i18n:t}=i(),[n,s]=(0,E.useState)([]),[c,u]=(0,E.useState)(!0),[p,g]=(0,E.useState)(null),[_,v]=(0,E.useState)(``),[y,S]=(0,E.useState)(``),[w,D]=(0,E.useState)(``),[O,k]=(0,E.useState)(!0),[j,M]=(0,E.useState)(`idle`),[F,I]=(0,E.useState)(null),L=(0,E.useRef)(null),[se,R]=r(),z=(0,E.useMemo)(()=>n.find(e=>e.id===p)??null,[n,p]);(0,E.useEffect)(()=>{let e=!1;return C.getNotes().then(t=>{e||t.success&&t.data&&s(t.data)}).catch(e=>P.error(`Failed to load notes:`,e)).finally(()=>{e||u(!1)}),()=>{e=!0}},[]);let B=se.get(`note`),V=B?n.find(e=>e.id===B):void 0;V&&p!==V.id&&(g(V.id),S(V.title),D(V.content),k(!0),M(`idle`));let H=B!==null&&(V!==void 0||!c);(0,E.useEffect)(()=>{H&&R({},{replace:!0})},[H,R]);let U=!z||!z.shared,W=z?!z.shared||z.shared.permission===`write`:!1,G=(e,t=`preview`)=>{Y(),g(e.id),S(e.title),D(e.content),k(t===`preview`),M(`idle`),I(null)},K=async()=>{if(z)try{let e=await C.updateNote(z.id,{pinned:!z.pinned});if(e.success&&e.data){let t=e.data;s(e=>e.map(e=>e.id===t.id?t:e))}}catch(e){P.error(`Failed to toggle pin:`,e)}},ce=()=>{if(!z)return;let e=new Blob([w],{type:`text/markdown;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${(y||`note`).replace(/[\\/:*?"<>|]/g,`-`)}.md`,n.click(),URL.revokeObjectURL(t)},q=(e,t,n)=>{L.current!==null&&window.clearTimeout(L.current),M(`saving`),L.current=window.setTimeout(()=>{L.current=null,J(e,t,n)},oe)},J=async(t,n,r)=>{try{let e=await C.updateNote(t,{title:n,content:r});if(e.success&&e.data){let n=e.data;s(e=>[n,...e.filter(e=>e.id!==t)].sort((e,t)=>t.updatedAt-e.updatedAt)),M(`saved`)}}catch(t){P.error(`Failed to save note:`,t),f.error(e(`notes.saveFailed`)),M(`idle`)}},Y=()=>{L.current!==null&&p&&(window.clearTimeout(L.current),L.current=null,J(p,y,w))};(0,E.useEffect)(()=>()=>{L.current!==null&&window.clearTimeout(L.current)},[]);let le=async()=>{try{let e=await C.createNote(``,``);if(e.success&&e.data){let t=e.data;s(e=>[t,...e]),G(t,`edit`)}}catch(t){P.error(`Failed to create note:`,t),f.error(e(`notes.createFailed`))}},ue=async t=>{if(window.confirm(e(`notes.deleteConfirm`)))try{(await C.deleteNote(t)).success&&(s(e=>e.filter(e=>e.id!==t)),p===t&&g(null))}catch(t){P.error(`Failed to delete note:`,t),f.error(e(`notes.deleteFailed`))}},X=(0,E.useMemo)(()=>{let e=_.trim().toLowerCase();return e?n.filter(t=>t.title.toLowerCase().includes(e)||t.content.toLowerCase().includes(e)):n},[n,_]);return(0,A.jsxs)(`div`,{className:`relative flex h-full min-h-0 overflow-hidden`,"data-testid":`notes-page`,children:[(0,A.jsxs)(`div`,{"data-testid":`notes-list`,className:o(`min-h-0 w-full shrink-0 flex-col border-e border-black/[0.06] dark:border-white/[0.07] md:w-72`,z?`hidden md:flex`:`flex`),children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,A.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`notes.title`)}),(0,A.jsx)(T,{size:`sm`,variant:`ghost`,onClick:()=>void le(),className:`h-7 w-7 p-0`,title:e(`notes.new`),children:(0,A.jsx)(d,{className:`h-4 w-4`})})]}),(0,A.jsxs)(`div`,{className:`relative mx-3 mb-2`,children:[(0,A.jsx)(ee,{className:`pointer-events-none absolute start-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-gray-400 dark:text-dark-500`}),(0,A.jsx)(`input`,{type:`search`,value:_,onChange:e=>v(e.target.value),placeholder:e(`common.search`),className:`w-full rounded-lg border border-transparent bg-black/[0.04] py-1.5 pe-2.5 ps-8 text-base text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:bg-white/[0.05] dark:text-dark-900 dark:placeholder:text-dark-500 sm:text-[13px]`})]}),(0,A.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:c?null:X.length===0?(0,A.jsxs)(`div`,{className:`px-3 py-10 text-center`,children:[(0,A.jsx)(x,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,A.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`notes.empty`)})]}):(0,A.jsx)(`div`,{className:`space-y-0.5`,children:X.map(n=>(0,A.jsxs)(`div`,{"data-testid":`note-list-item`,onClick:()=>G(n),className:o(`group cursor-pointer rounded-lg px-2.5 py-2 transition-colors`,p===n.id?`bg-white ring-1 ring-black/[0.04] dark:bg-dark-200 dark:ring-white/[0.05]`:`hover:bg-white/60 dark:hover:bg-dark-200/60`),children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,A.jsxs)(`p`,{className:`flex min-w-0 flex-1 items-center gap-1 truncate text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:[n.pinned&&(0,A.jsx)(m,{className:`h-3 w-3 shrink-0 text-primary-500`,"aria-label":e(`notes.pinned`)}),n.shared&&(0,A.jsx)(b,{className:`h-3 w-3 shrink-0 text-gray-400 dark:text-dark-500`,"aria-label":e(`notes.sharedWithYou`)}),(0,A.jsx)(`span`,{className:`truncate`,children:n.title||e(`notes.untitled`)})]}),!n.shared&&(0,A.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ue(n.id)},className:`shrink-0 rounded-md p-1 text-red-500 opacity-100 transition-opacity hover:bg-red-50 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100 dark:hover:bg-red-900/20`,title:e(`common.delete`),children:(0,A.jsx)(re,{className:`h-3 w-3`})})]}),(0,A.jsxs)(`p`,{className:`mt-0.5 truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[a(n.updatedAt,t.language),n.content.trim()&&(0,A.jsxs)(A.Fragment,{children:[` · `,n.content.trim().slice(0,60)]})]})]},n.id))})})]}),(0,A.jsx)(`div`,{"data-testid":`notes-editor`,className:o(`min-w-0 flex-1 flex-col`,z?`flex`:`hidden md:flex`),children:z?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5 border-b border-black/[0.06] px-2.5 py-2.5 dark:border-white/[0.07] sm:gap-2 sm:px-5 sm:py-3`,children:[(0,A.jsx)(T,{size:`sm`,variant:`ghost`,onClick:()=>{Y(),g(null),k(!0)},className:`h-9 w-9 shrink-0 p-0 md:hidden`,title:`${e(`common.back`)}: ${e(`notes.title`)}`,"aria-label":`${e(`common.back`)}: ${e(`notes.title`)}`,"data-testid":`notes-mobile-back`,children:(0,A.jsx)(ne,{className:`h-4 w-4 rtl:rotate-180`})}),O?(0,A.jsx)(`h2`,{"data-testid":`notes-title-preview`,dir:`auto`,className:`min-w-0 flex-1 truncate text-base font-semibold text-gray-950 dark:text-dark-950 sm:text-lg`,children:y||e(`notes.untitled`)}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`input`,{"data-testid":`notes-title-editor`,dir:`auto`,readOnly:!W,value:y,onChange:e=>{S(e.target.value),q(z.id,e.target.value,w)},placeholder:e(`notes.untitled`),className:`min-w-0 flex-1 bg-transparent text-base font-semibold text-gray-950 placeholder:text-gray-400 focus:outline-none dark:text-dark-950 dark:placeholder:text-dark-500 sm:text-lg`}),(0,A.jsx)(`span`,{className:`hidden shrink-0 text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,"aria-live":`polite`,children:j===`saving`?e(`common.saving`):j===`saved`?e(`notes.saved`):``})]}),U&&(0,A.jsx)(T,{size:`sm`,variant:`ghost`,onClick:()=>void K(),className:o(`hidden h-8 w-8 shrink-0 p-0 sm:flex`,z.pinned&&`text-primary-500`),title:z.pinned?e(`notes.unpin`):e(`notes.pin`),"aria-label":z.pinned?e(`notes.unpin`):e(`notes.pin`),"data-testid":`notes-pin-toggle`,children:(0,A.jsx)(m,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(T,{size:`sm`,variant:`ghost`,onClick:ce,className:`hidden h-8 w-8 shrink-0 p-0 sm:flex`,title:e(`notes.export`),"aria-label":e(`notes.export`),"data-testid":`notes-export`,children:(0,A.jsx)(ie,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(T,{size:`sm`,variant:`ghost`,onClick:()=>I(e=>e===null?`revisions`:null),className:`h-9 w-9 shrink-0 p-0 sm:h-8 sm:w-8`,title:e(`notes.tools`),"aria-label":e(`notes.tools`),"aria-expanded":F!==null,"data-testid":`notes-tools-toggle`,children:(0,A.jsx)(l,{className:`h-3.5 w-3.5`})}),(0,A.jsx)(T,{size:`sm`,variant:`ghost`,onClick:()=>{O||Y(),k(e=>!e)},className:`h-9 w-9 shrink-0 gap-1.5 p-0 text-xs sm:h-8 sm:w-auto sm:px-2.5`,title:e(O?`common.edit`:`artifacts.preview`),"aria-label":e(O?`common.edit`:`artifacts.preview`),"data-testid":`notes-preview-toggle`,children:O?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(te,{className:`h-3.5 w-3.5`}),(0,A.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.edit`)})]}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(h,{className:`h-3.5 w-3.5`}),(0,A.jsx)(`span`,{className:`hidden sm:inline`,children:e(`artifacts.preview`)})]})})]}),O?(0,A.jsx)(`div`,{"data-testid":`notes-preview`,className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-3 scrollbar-thin sm:px-5 sm:py-4`,children:(0,A.jsx)(ae,{content:w,allowHtml:!0,className:`mx-auto w-full max-w-5xl pb-12`})}):(0,A.jsx)(`textarea`,{"data-testid":`notes-content-editor`,dir:`auto`,readOnly:!W,value:w,onChange:e=>{D(e.target.value),q(z.id,y,e.target.value)},onBlur:Y,placeholder:e(`notes.contentPlaceholder`),className:`min-h-0 flex-1 resize-none bg-transparent px-4 py-3 font-mono text-base leading-relaxed text-gray-900 placeholder:text-gray-400 focus:outline-none dark:text-dark-900 dark:placeholder:text-dark-500 sm:px-5 sm:py-4 sm:text-[13.5px]`}),F!==null&&(0,A.jsx)(N,{note:z,currentContent:w,currentTitle:y,canWrite:W,isOwner:U,initialTab:F,onClose:()=>I(null),onApplyContent:(e,t)=>{D(e),t!==void 0&&S(t),J(z.id,t===void 0?y:t,e)}})]}):(0,A.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:(0,A.jsxs)(`div`,{className:`text-center`,children:[(0,A.jsx)(x,{className:`mx-auto mb-3 h-8 w-8 text-gray-300 dark:text-dark-400`}),(0,A.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-dark-600`,children:e(`notes.selectOrCreate`)}),(0,A.jsxs)(T,{size:`sm`,onClick:()=>void le(),className:`mt-4 gap-1.5`,children:[(0,A.jsx)(d,{className:`h-3.5 w-3.5`}),e(`notes.new`)]})]})})})]})};export{F as NotesPage,F as default};
@@ -1,13 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{i as r,t as i}from"./useQuery-CoWV2PmJ.js";import{t as a}from"./useTranslation-DrnYb6Cx.js";import{t as o}from"./utils-D9UstwTG.js";import{t as s}from"./chatStore-DkpmZLOG.js";import{$ as c,A as l,B as u,Gn as d,Q as f,Qn as p,R as m,Rt as h,Sn as g,St as _,T as v,Wt as y,Y as b,_ as x,_r as S,bn as C,c as w,fn as T,fr as E,g as D,j as O,jn as k,jt as A,k as ee,n as j,p as M,t as N,v as P,xn as F,zt as I}from"./ui-vendor-C0KwbTD4.js";import{t as L}from"./logger-CpCQz3Vi.js";import{M as te,_ as R,d as z,f as B,g as V,j as H,m as U,p as W}from"./api-2DulPtq1.js";import{t as G}from"./appStore-Ci1X0yA-.js";import{t as K}from"./Button--pDOakZx.js";import{a as ne,o as re}from"./ui-DUzqxWMk.js";import{t as ie}from"./AvatarUpload-DzL00yOL.js";import{t as ae}from"./ShareDialog-BW8iGd_i.js";var q=e(t(),1),J=n(),Y=L(`components:persona-card`),oe=({persona:e,onEdit:t,onDelete:n,onDownload:s,onSelect:d,onToggleFavorite:f,isSelected:h=!1,compact:y=!1})=>{let{t:b}=a(),x=r(),[w,O]=(0,q.useState)(!1),[k,A]=(0,q.useState)(!1),[j,M]=(0,q.useState)(!1),I=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),{data:L=null}=i({queryKey:[`persona-memory-status`,e.id],queryFn:async()=>{let t=await U.getMemoryStatus(e.id);return t.success&&t.data?t.data:null},enabled:I}),te=()=>x.invalidateQueries({queryKey:[`persona-memory-status`,e.id]}),z=async()=>{if(confirm(b(`personaCard.wipeConfirm`))){M(!0);try{let t=await U.wipeMemories(e.id);t.success?(S.success(b(`personaCard.wipeSuccess`,{count:t.data?.deleted_count||0})),await te()):S.error(b(`personaCard.failed`,{action:`wipe memories`}))}catch(e){S.error(b(`personaCard.failed`,{action:`wipe memories`})),Y.error(e)}finally{M(!1),O(!1)}}},B=async()=>{M(!0);try{let t=await U.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),S.success(b(`personaCard.backupSuccess`))}catch(e){S.error(b(`personaCard.failed`,{action:`backup persona`})),Y.error(e)}finally{M(!1),O(!1)}},H=async()=>{M(!0);try{let t=await U.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),S.success(b(`personaCard.dnaSuccess`))}catch(e){S.error(b(`personaCard.failed`,{action:`export persona DNA`})),Y.error(e)}finally{M(!1),O(!1)}},W=(t=128)=>V(e,t),G=(t=128)=>n=>{R(n.currentTarget,e.name,t)};return y?(0,J.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`,h&&[`bg-primary-50 dark:bg-primary-900/20`,`border-primary-200 dark:border-primary-700`]),onClick:()=>d?.(e),children:[(0,J.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,J.jsx)(`img`,{src:W(64),alt:e.name,className:`w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-dark-100`,onError:G(64)}),I&&(0,J.jsx)(`div`,{className:`absolute -bottom-0.5 -end-0.5 flex h-4 w-4 items-center justify-center rounded-full bg-primary-600`,children:(0,J.jsx)(l,{className:`h-2.5 w-2.5 text-white`})})]}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`h4`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100 truncate`,children:e.name}),e.is_favorite&&(0,J.jsx)(v,{className:`h-3 w-3 text-amber-500 fill-amber-500 flex-shrink-0`})]}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:e.model})]}),h&&(0,J.jsx)(`div`,{className:`flex-shrink-0`,children:(0,J.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-600 flex items-center justify-center`,children:(0,J.jsx)(c,{className:`h-3 w-3 text-white rtl:rotate-180`})})})]}):(0,J.jsxs)(`div`,{className:o(`group relative overflow-hidden rounded-2xl transition-[border-color,background-color] duration-200`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`hover:border-gray-300 dark:hover:border-white/20`,h&&[`ring-2 ring-primary-500 dark:ring-primary-400`,`border-primary-300 dark:border-primary-600`]),children:[(0,J.jsxs)(`div`,{className:`relative h-24`,children:[e.background?(0,J.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,J.jsx)(`div`,{className:`absolute inset-0 bg-gray-200 dark:bg-dark-200`}),e.background&&(0,J.jsx)(`div`,{className:`absolute inset-0 bg-black/15 dark:bg-black/25`}),(0,J.jsxs)(`div`,{className:`absolute inset-x-3 top-3 flex items-start justify-between`,children:[(0,J.jsx)(`button`,{onClick:t=>{t.stopPropagation(),f?.(e)},className:o(`p-1.5 rounded-full transition-all duration-200`,`border border-white/30 bg-black/20 text-white backdrop-blur-sm hover:bg-black/30`,e.is_favorite&&`bg-amber-500/80 hover:bg-amber-500`),children:(0,J.jsx)(v,{className:o(`h-4 w-4`,e.is_favorite?`fill-ink text-ink dark:fill-ink-inverse dark:text-ink-inverse`:`text-white/80 hover:text-white`)})}),I&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1 rounded-full border border-white/30 bg-black/20 px-2 py-1 text-[10px] font-medium text-white backdrop-blur-sm`,children:[(0,J.jsx)(l,{className:`h-3 w-3`}),b(`personaCard.enhanced`)]})]})]}),(0,J.jsx)(`div`,{className:`relative -mt-8 px-4`,children:(0,J.jsxs)(`div`,{className:`relative inline-block`,children:[(0,J.jsx)(`img`,{src:W(128),alt:e.name,className:`h-16 w-16 rounded-xl object-cover ring-4 ring-white dark:ring-dark-100`,onError:G(128)}),I&&(0,J.jsx)(`div`,{className:`absolute -bottom-1 -end-1 flex h-6 w-6 items-center justify-center rounded-lg bg-primary-600 ring-2 ring-white dark:ring-dark-100`,children:(0,J.jsx)(p,{className:`h-3.5 w-3.5 text-white`})})]})}),(0,J.jsxs)(`div`,{className:`px-4 pt-3 pb-4`,children:[(0,J.jsxs)(`div`,{className:`mb-3`,children:[(0,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 leading-tight`,children:e.name}),(0,J.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 flex items-center gap-1.5 mt-0.5`,children:[(0,J.jsx)(u,{className:`h-3.5 w-3.5`}),e.model]})]}),e.description&&(0,J.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,J.jsxs)(`div`,{className:`mb-3 rounded-xl border border-gray-200/70 bg-gray-50/70 p-2.5 dark:border-white/[0.08] dark:bg-white/[0.025]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1`,children:[(0,J.jsx)(_,{className:`h-3 w-3 text-gray-400 dark:text-gray-500`}),(0,J.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500`,children:b(`personaCard.systemPrompt`)})]}),(0,J.jsxs)(`p`,{className:`line-clamp-2 text-xs leading-5 text-gray-600 dark:text-gray-400`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[(0,J.jsx)(N,{className:`h-3 w-3`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,J.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),(0,J.jsxs)(`span`,{className:`inline-flex items-center rounded-lg border border-gray-200/70 px-2 py-1 text-[11px] font-medium text-gray-600 dark:border-white/[0.08] dark:text-gray-400`,children:[(e.parameters.context_window||4096).toLocaleString(),` ctx`]})]}),I&&L&&(0,J.jsx)(`div`,{className:`mb-3 rounded-xl border border-primary-200/70 bg-primary-50/50 p-2.5 dark:border-primary-800/40 dark:bg-primary-900/10`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(g,{className:`h-4 w-4 text-primary-600 dark:text-primary-400`}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`span`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300`,children:[L.memory_count,` `,b(`personaCard.memories`)]}),(0,J.jsx)(`span`,{className:`ms-2 text-[10px] text-primary-600/70 dark:text-primary-400/70`,children:(e=>e<1?`${(e*1024).toFixed(0)} KB`:`${e.toFixed(1)} MB`)(L.size_mb)})]})]}),L.status&&(0,J.jsx)(`span`,{className:o(`text-[10px] px-1.5 py-0.5 rounded-full font-medium`,L.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:L.status})]})}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-200/70 pt-3 dark:border-white/[0.08]`,children:[d&&(0,J.jsxs)(K,{onClick:()=>d(e),size:`sm`,className:`px-4`,children:[(0,J.jsx)(c,{className:`me-1.5 h-3.5 w-3.5 rtl:rotate-180`}),b(`personaCard.use`)]}),(0,J.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,J.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:b(`personaCard.editTooltip`),children:(0,J.jsx)(ee,{className:`h-4 w-4`})}),!e.shared&&(0,J.jsx)(`button`,{onClick:()=>A(!0),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:b(`personaCard.shareTooltip`),"data-testid":`persona-share`,children:(0,J.jsx)(m,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{onClick:()=>s(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:b(`personaCard.downloadTooltip`),children:(0,J.jsx)(F,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(`button`,{onClick:()=>O(!w),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:b(`common.more`,{defaultValue:`More`}),children:(0,J.jsx)(C,{className:`h-4 w-4`})}),w&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>O(!1)}),(0,J.jsxs)(`div`,{className:`absolute end-0 bottom-full z-20 mb-1 w-44 rounded-xl border border-gray-200 bg-white py-1 shadow-lg dark:border-white/10 dark:bg-dark-100`,children:[I&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{onClick:B,disabled:j,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,J.jsx)(E,{className:`h-4 w-4`}),b(`personaCard.backup`)]}),(0,J.jsxs)(`button`,{onClick:H,disabled:j,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,J.jsx)(T,{className:`h-4 w-4`}),b(`personaCard.exportDNA`)]}),L&&L.memory_count>0&&(0,J.jsxs)(`button`,{onClick:z,disabled:j,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,J.jsx)(D,{className:`h-4 w-4`}),b(`personaCard.wipeMemories`)]}),(0,J.jsx)(`div`,{className:`my-1 border-t border-gray-100 dark:border-dark-200`})]}),(0,J.jsxs)(`button`,{onClick:()=>{n(e),O(!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,J.jsx)(P,{className:`h-4 w-4`}),b(`common.delete`)]})]})]})]})]})]})]}),k&&(0,J.jsx)(ae,{resourceType:`persona`,resourceId:e.id,resourceLabel:e.name,onClose:()=>A(!1)})]})},X={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}};function se({embeddingModel:e,embeddingModels:t,onEmbeddingModelChange:n}){let{t:r}=a(),i=t.filter(e=>e.isDetectedEmbedding),o=t.filter(e=>!e.isDetectedEmbedding);return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.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,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,J.jsx)(g,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`}),(0,J.jsx)(`h3`,{className:`font-semibold text-primary-900 dark:text-primary-100`,children:r(`personaForm.advanced.embeddingModel`)})]}),(0,J.jsx)(`p`,{className:`text-xs text-primary-600 dark:text-primary-400 mb-3`,children:r(`personaForm.advanced.embeddingHint`)}),(0,J.jsx)(`select`,{value:e,onChange:e=>n(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:t.length===0?(0,J.jsx)(`option`,{value:``,disabled:!0,children:r(`personaForm.advanced.noModels`)}):(0,J.jsxs)(J.Fragment,{children:[i.length>0&&(0,J.jsx)(`optgroup`,{label:r(`personaForm.advanced.embeddingModels`),children:i.map(e=>(0,J.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))}),o.length>0&&(0,J.jsx)(`optgroup`,{label:r(`personaForm.advanced.otherModels`),children:o.map(e=>(0,J.jsxs)(`option`,{value:e.id,children:[e.name,` - `,e.description]},e.id))})]})}),t.length===0&&(0,J.jsx)(`div`,{className:`mt-3 rounded-lg border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-700/50 dark:bg-amber-900/20`,children:(0,J.jsxs)(`p`,{className:`text-sm text-ink`,children:[r(`personaForm.advanced.installHint`),` `,(0,J.jsx)(`code`,{className:`rounded bg-amber-500/20 px-1.5 py-0.5 text-xs dark:bg-amber-900/40`,children:`ollama pull nomic-embed-text`})]})}),(0,J.jsx)(`p`,{className:`text-[10px] text-primary-500 dark:text-primary-500 mt-2`,children:r(`personaForm.advanced.recommended`)})]}),(0,J.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-dark-50 rounded-xl border border-gray-200 dark:border-dark-300`,children:(0,J.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,J.jsx)(h,{className:`h-5 w-5 text-gray-400 mt-0.5 flex-shrink-0`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`personaForm.advanced.aboutTitle`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:r(`personaForm.advanced.aboutDescription`)})]})]})})]})}var ce=L(`components:persona-background-upload`),le=({value:e,onChange:t,className:n=``})=>{let{t:r}=a(),i=(0,q.useRef)(null),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(!1),u=async e=>{if(!e.type.startsWith(`image/`)){S.error(r(`personaBackground.invalidFile`));return}if(e.size>5242880){S.error(r(`personaBackground.fileTooLarge`));return}s(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),S.success(r(`personaBackground.uploaded`))},n.onerror=()=>{S.error(r(`personaBackground.readFailed`))},n.readAsDataURL(e)}catch(e){ce.error(`Failed to upload background:`,e),S.error(r(`personaBackground.uploadFailed`))}finally{s(!1)}};return(0,J.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:r(`personaBackground.label`)}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[e?(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.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,J.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:r(`personaBackground.customBackground`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:r(`personaBackground.clickToChange`)})]}),(0,J.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>{t(``),S.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,J.jsx)(j,{className:`h-4 w-4`})})]})]}):(0,J.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${c?`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(),l(!0)},onDragLeave:e=>{e.preventDefault(),l(!1)},onDrop:e=>{e.preventDefault(),l(!1);let t=e.dataTransfer.files?.[0];t&&u(t)},onClick:()=>i.current?.click(),children:[(0,J.jsx)(I,{className:`h-12 w-12 mx-auto text-gray-400 dark:text-gray-500 mb-4`}),(0,J.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:r(`personaBackground.uploadBackgroundImage`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-4`,children:r(`personaBackground.dragAndDrop`)}),(0,J.jsxs)(K,{variant:`outline`,size:`sm`,disabled:o,className:`mx-auto`,children:[(0,J.jsx)(M,{className:`h-4 w-4 mr-2`}),r(o?`personaBackground.uploading`:`personaBackground.chooseImage`)]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:r(`personaBackground.enterImageUrl`)}),(0,J.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,J.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,onChange:e=>{let t=e.target.files?.[0];t&&u(t)},className:`hidden`}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:r(`personaBackground.supportedFormats`)})]})})};function ue({formData:e,availableModels:t,onFieldChange:n,onParameterChange:r}){let{t:i}=a(),o=(0,q.useMemo)(()=>t.filter(e=>!e.isPlugin),[t]),s=(0,q.useMemo)(()=>{let e=new Map;for(let n of t){if(!n.isPlugin)continue;let t=n.pluginName||n.pluginId||`Provider`,r=e.get(t);r?r.push(n):e.set(t,[n])}return[...e.entries()].sort(([e],[t])=>e.localeCompare(t))},[t]);return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[i(`personaForm.basic.name`),` *`]}),(0,J.jsx)(`input`,{type:`text`,value:e.name,onChange:e=>n(`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:i(`personaForm.basic.namePlaceholder`),required:!0})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:[i(`personaForm.basic.model`),` *`]}),(0,J.jsxs)(`select`,{value:e.model,onChange:e=>n(`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,J.jsx)(`option`,{value:``,children:i(`personaForm.basic.selectModel`)}),e.model&&!t.some(t=>t.name===e.model)&&(0,J.jsx)(`option`,{value:e.model,children:e.model}),o.length>0&&(0,J.jsx)(`optgroup`,{label:`Ollama`,children:o.map(e=>(0,J.jsx)(`option`,{value:e.name,children:e.name},e.name))}),s.map(([e,t])=>(0,J.jsx)(`optgroup`,{label:e,children:t.map(e=>(0,J.jsx)(`option`,{value:e.name,children:e.name},e.name))},e))]})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaForm.basic.description`)}),(0,J.jsx)(`textarea`,{value:e.description,onChange:e=>n(`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:i(`personaForm.basic.descriptionPlaceholder`)})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,J.jsx)(ie,{value:e.avatar||``,onChange:e=>n(`avatar`,e)}),(0,J.jsx)(le,{value:e.background||``,onChange:e=>n(`background`,e)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:i(`personaForm.basic.systemPrompt`)}),(0,J.jsx)(`textarea`,{value:e.parameters.system_prompt,onChange:e=>r(`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:i(`personaForm.basic.systemPromptPlaceholder`)}),(0,J.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-2`,children:i(`personaForm.basic.systemPromptHint`)})]})]})}function de({submitting:e,lastSaved:t,onCancel:n,onSave:r}){let{t:i}=a();return(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(K,{type:`button`,variant:`ghost`,onClick:n,disabled:e,className:`text-gray-600 dark:text-gray-400`,children:i(`personaForm.actions.cancel`)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t&&(0,J.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex items-center gap-1.5 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,J.jsx)(d,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{children:i(`personaForm.saved`)})]}),(0,J.jsx)(K,{type:`button`,onClick:r,disabled:e,children:i(e?`personaForm.actions.saving`:`personaForm.actions.save`)})]})]})}var fe=L(`components:persona-bindings`),pe=[`web_search`,`search_documents`,`list_documents`,`read_document`,`load_skill`];function me({bindings:e,onChange:t}){let{t:n}=a(),[r,i]=(0,q.useState)([]),[o,s]=(0,q.useState)([]),[c,l]=(0,q.useState)([]),[u,d]=(0,q.useState)([]),[f,p]=(0,q.useState)(!0);(0,q.useEffect)(()=>{let e=!1;return Promise.all([z.listServers(),B.list(),W.list(),H.getCollections()]).then(([t,n,r,a])=>{e||(t.success&&t.data&&i(t.data),n.success&&n.data&&s(n.data),r.success&&r.data&&l(r.data),a.success&&a.data&&d(a.data))}).catch(e=>{fe.error(`Failed to load bindable resources:`,e)}).finally(()=>{e||p(!1)}),()=>{e=!0}},[]);let m=n=>t({...e??{},...n}),h=(t,n)=>{let r=e?.[t]??[];m({[t]:r.includes(n)?r.filter(e=>e!==n):[...r,n]})};return f?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-10`,children:(0,J.jsx)(A,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,J.jsxs)(`div`,{className:`space-y-6`,"data-testid":`persona-bindings-tab`,children:[(0,J.jsx)(Z,{title:n(`personaForm.bindings.toolServers`),hint:n(`personaForm.bindings.toolServersHint`),emptyLabel:n(`personaForm.bindings.noToolServers`),options:r.map(e=>({id:e.id,label:e.name,detail:e.description})),selected:e?.tool_server_ids??[],onToggle:e=>h(`tool_server_ids`,e),testId:`persona-binding-tool-servers`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.builtinTools`),hint:n(`personaForm.bindings.builtinToolsHint`),emptyLabel:n(`personaForm.bindings.noBuiltinTools`),options:pe.map(e=>({id:e,label:n(`personaForm.bindings.builtin.${e}`),detail:e})),selected:e?.builtin_tools??[],onToggle:e=>h(`builtin_tools`,e),testId:`persona-binding-builtin-tools`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.skills`),hint:n(`personaForm.bindings.skillsHint`),emptyLabel:n(`personaForm.bindings.noSkills`),options:o.map(e=>({id:e.id,label:e.name,detail:`$${e.slug}`})),selected:e?.skill_ids??[],onToggle:e=>h(`skill_ids`,e),testId:`persona-binding-skills`}),(0,J.jsx)(Z,{title:n(`personaForm.bindings.collections`),hint:n(`personaForm.bindings.collectionsHint`),emptyLabel:n(`personaForm.bindings.noCollections`),options:u.map(e=>({id:e.id,label:e.name})),selected:e?.knowledge_collection_ids??[],onToggle:t=>{let n=e?.knowledge_collection_ids??[];m({knowledge_collection_ids:n.includes(t)?n.filter(e=>e!==t):[...n,t]})},testId:`persona-binding-collections`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:n(`personaForm.bindings.prompt`)}),(0,J.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:n(`personaForm.bindings.promptHint`)}),(0,J.jsxs)(`select`,{value:e?.prompt_id??``,onChange:e=>m({prompt_id:e.target.value||void 0}),"data-testid":`persona-binding-prompt`,"aria-label":n(`personaForm.bindings.prompt`),className:`w-full rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-sm text-gray-900 focus:ring-2 focus:ring-primary-500/20 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,J.jsx)(`option`,{value:``,children:n(`personaForm.bindings.noPrompt`)}),c.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,J.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:n(`personaForm.bindings.version`,{version:e?.version??0})})]})}function Z({title:e,hint:t,emptyLabel:n,options:r,selected:i,onToggle:a,testId:o}){return(0,J.jsxs)(`div`,{"data-testid":o,children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-800`,children:e}),(0,J.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-gray-500 dark:text-dark-600`,children:t}),r.length===0?(0,J.jsx)(`p`,{className:`rounded-lg border border-dashed border-gray-200 px-3 py-4 text-center text-xs text-gray-400 dark:border-dark-300 dark:text-dark-500`,children:n}):(0,J.jsx)(`div`,{className:`space-y-1`,children:r.map(e=>(0,J.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-1.5 transition-colors hover:bg-gray-50 dark:hover:bg-dark-200`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:i.includes(e.id),onChange:()=>a(e.id),className:`h-4 w-4 rounded border-gray-300 dark:border-dark-400`}),(0,J.jsx)(`span`,{className:`text-sm text-gray-900 dark:text-dark-800`,children:e.label}),e.detail&&(0,J.jsx)(`span`,{className:`truncate text-xs text-gray-400 dark:text-dark-500`,children:e.detail})]},e.id))})]})}var Q=({label:e,value:t,min:n,max:r,step:i,onChange:a,hint:s,format:c=e=>String(e),colorClass:l=`text-gray-700 dark:text-dark-600`})=>{let u=(t-n)/(r-n)*100;return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,J.jsx)(`label`,{className:o(`block text-sm font-medium`,l),children:e}),(0,J.jsx)(`input`,{type:`number`,min:n,max:r,step:i,value:c(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,J.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":`${u}%`}}),s&&(0,J.jsx)(`p`,{className:o(`text-xs mt-1`,l.replace(`700`,`500`).replace(`600`,`400`)),children:s})]})},$=({label:e,checked:t,onChange:n,colorClass:r=`text-gray-700 dark:text-dark-600`})=>(0,J.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,J.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,J.jsx)(`div`,{className:o(`absolute top-0.5 start-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-5 rtl:-translate-x-5`)})}),(0,J.jsx)(`span`,{className:o(`text-sm font-medium`,r),children:e})]});function he({formData:e,persona:t,memoryStatus:n,loadingMemoryStatus:r,wipingMemories:i,onSettingsChange:s,onWipeMemories:c}){let{t:u}=a();return(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-emerald-200/50 dark:border-emerald-700/30`,children:[(0,J.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,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,J.jsx)(g,{className:`h-5 w-5 text-white`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`font-semibold text-white`,children:u(`personaForm.memory.title`)}),(0,J.jsx)(`p`,{className:`text-xs text-white/80`,children:u(`personaForm.memory.subtitle`)})]})]}),(0,J.jsx)($,{label:``,checked:e.memory_settings?.enabled||!1,onChange:e=>s(`memory_settings`,{enabled:e})})]})}),e.memory_settings?.enabled&&t?.id&&(0,J.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:r?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-emerald-600 dark:text-emerald-400`,children:[(0,J.jsx)(b,{className:`h-4 w-4 animate-spin`}),u(`personaForm.memory.loading`)]}):n?(0,J.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(g,{className:`h-5 w-5`}),n.memory_count.toLocaleString()]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:u(`personaForm.memory.memories`)})]}),(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(y,{className:`h-5 w-5`}),n.size_mb.toFixed(1)]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:u(`personaForm.memory.mbUsed`)})]}),(0,J.jsxs)(`div`,{className:`text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-2xl font-bold text-emerald-700 dark:text-emerald-300`,children:[(0,J.jsx)(k,{className:`h-5 w-5`}),n.last_backup?new Date(n.last_backup).toLocaleDateString():u(`personaForm.memory.never`)]}),(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400`,children:u(`personaForm.memory.lastBackup`)})]})]}):(0,J.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,children:u(`personaForm.memory.noData`)})}),e.memory_settings?.enabled&&(0,J.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-4`,children:[(0,J.jsx)(Q,{label:u(`personaForm.memory.maxMemories`),value:e.memory_settings.max_memories,min:100,max:1e4,step:100,hint:u(`personaForm.memory.maxMemoriesHint`),format:e=>e.toLocaleString(),colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>s(`memory_settings`,{max_memories:e})}),(0,J.jsx)(Q,{label:u(`personaForm.memory.retention`),value:e.memory_settings.retention_days,min:7,max:365,step:7,hint:u(`personaForm.memory.retentionHint`),format:e=>`${Math.round(e)} days`,colorClass:`text-emerald-700 dark:text-emerald-300`,onChange:e=>s(`memory_settings`,{retention_days:e})}),(0,J.jsx)($,{label:u(`personaForm.memory.autoCleanup`),checked:e.memory_settings.auto_cleanup,onChange:e=>s(`memory_settings`,{auto_cleanup:e}),colorClass:`text-emerald-700 dark:text-emerald-300`}),t?.id&&n&&n.memory_count>0&&(0,J.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-dark-300`,children:(0,J.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,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-300`,children:u(`personaForm.memory.wipeAll`)}),(0,J.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:u(`personaForm.memory.wipeCannot`)})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:c,disabled:i,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:[i?(0,J.jsx)(b,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(P,{className:`h-3.5 w-3.5`}),u(i?`personaForm.memory.wiping`:`personaForm.memory.wipeButton`)]})]})})]}),!e.memory_settings?.enabled&&(0,J.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,J.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:u(`personaForm.memory.enableHint`)})})]}),(0,J.jsxs)(`div`,{className:`rounded-xl overflow-hidden border border-primary-200/50 dark:border-primary-700/30`,children:[(0,J.jsx)(`div`,{className:`px-5 py-4 bg-primary-600 dark:bg-primary-600`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-white/20 flex items-center justify-center`,children:(0,J.jsx)(x,{className:`h-5 w-5 text-white`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`font-semibold text-white`,children:u(`personaForm.learning.title`)}),(0,J.jsx)(`p`,{className:`text-xs text-white/80`,children:u(`personaForm.learning.subtitle`)})]})]}),(0,J.jsx)($,{label:``,checked:e.mutation_settings?.enabled||!1,onChange:e=>s(`mutation_settings`,{enabled:e})})]})}),e.mutation_settings?.enabled&&(0,J.jsxs)(`div`,{className:`p-5 bg-white dark:bg-dark-100 space-y-5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-primary-700 dark:text-primary-300 mb-3`,children:u(`personaForm.learning.speed`)}),(0,J.jsx)(`div`,{className:`grid grid-cols-3 gap-3`,children:[{level:`low`,icon:N,label:u(`personaForm.learning.slow`),desc:u(`personaForm.learning.slowDesc`)},{level:`medium`,icon:x,label:u(`personaForm.learning.balanced`),desc:u(`personaForm.learning.balancedDesc`)},{level:`high`,icon:l,label:u(`personaForm.learning.fast`),desc:u(`personaForm.learning.fastDesc`)}].map(({level:t,icon:n,label:r,desc:i})=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>s(`mutation_settings`,{sensitivity:t}),className:o(`p-3 rounded-xl text-center transition-all border`,e.mutation_settings?.sensitivity===t?`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,J.jsx)(n,{className:`h-5 w-5 mx-auto mb-1`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:r}),(0,J.jsx)(`p`,{className:`text-[10px] opacity-70`,children:i})]},t))})]}),(0,J.jsx)($,{label:u(`personaForm.learning.autoAdapt`),checked:e.mutation_settings.auto_adapt,onChange:e=>s(`mutation_settings`,{auto_adapt:e}),colorClass:`text-primary-700 dark:text-primary-300`}),(0,J.jsxs)(`div`,{className:`p-4 bg-primary-50 dark:bg-primary-900/20 rounded-xl`,children:[(0,J.jsxs)(`p`,{className:`text-xs font-medium text-primary-700 dark:text-primary-300 mb-2 flex items-center gap-1.5`,children:[(0,J.jsx)(p,{className:`h-3.5 w-3.5`}),u(`personaForm.learning.whatLearns`)]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs text-primary-600 dark:text-primary-400`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),u(`personaForm.learning.conversationTone`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),u(`personaForm.learning.responseStyle`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),u(`personaForm.learning.userPreferences`)]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:`w-1 h-1 rounded-full bg-primary-400`}),u(`personaForm.learning.topicInterests`)]})]})]})]}),!e.mutation_settings?.enabled&&(0,J.jsx)(`div`,{className:`p-5 bg-gray-50 dark:bg-dark-50`,children:(0,J.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center`,children:u(`personaForm.learning.enableHint`)})})]})]})}function ge({parameters:e,onParameterChange:t}){let{t:n}=a(),r=(0,q.useMemo)(()=>[{key:`temperature`,label:n(`personaForm.parameters.temperature`),min:0,max:2,step:.1,hint:n(`personaForm.parameters.temperatureHint`),format:e=>e.toFixed(1)},{key:`top_p`,label:n(`personaForm.parameters.topP`),min:0,max:1,step:.1,hint:n(`personaForm.parameters.topPHint`),format:e=>e.toFixed(1)},{key:`top_k`,label:n(`personaForm.parameters.topK`),min:1,max:100,step:1,hint:n(`personaForm.parameters.topKHint`),format:e=>String(Math.round(e))},{key:`context_window`,label:n(`personaForm.parameters.contextWindow`),min:128,max:131072,step:128,hint:n(`personaForm.parameters.contextWindowHint`),format:e=>String(Math.round(e))},{key:`max_tokens`,label:n(`personaForm.parameters.maxTokens`),min:1,max:8192,step:1,hint:n(`personaForm.parameters.maxTokensHint`),format:e=>String(Math.round(e))},{key:`repeat_penalty`,label:n(`personaForm.parameters.repeatPenalty`),min:.5,max:2,step:.1,hint:n(`personaForm.parameters.repeatPenaltyHint`),format:e=>e.toFixed(1)}],[n]);return(0,J.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:r.map(({key:n,label:r,min:i,max:a,step:o,hint:s,format:c})=>(0,J.jsx)(Q,{label:r,value:e[n]||0,min:i,max:a,step:o,hint:s,format:c,onChange:e=>t(n,e)},n))})}var _e=L(`components:persona-form`),ve=({persona:e,onSubmit:t,onCancel:n})=>{let{preferences:c}=G(),{t:u}=a(),[d,m]=(0,q.useState)(X),h=s(e=>e.models),g=s(e=>e.loadModels),_=(0,q.useMemo)(()=>h.filter(e=>!e.isPersona&&!e.isAgent&&!e.isUnavailable&&!e.isLegacySelection),[h]),[v,y]=(0,q.useState)([]),[b,x]=(0,q.useState)(!1),[C,T]=(0,q.useState)(!1),[E,D]=(0,q.useState)(null),[k,A]=(0,q.useState)(`basic`),[ee,j]=(0,q.useState)(!1),M=(0,q.useRef)(!1),N=(0,q.useCallback)((e,t)=>{m(n=>({...n,[e]:t})),D(null)},[]),P=(0,q.useCallback)((e,t)=>{m(n=>({...n,parameters:{...n.parameters,[e]:t}})),D(null)},[]),F=(0,q.useCallback)((e,t)=>{m(n=>({...n,[e]:{...n[e],...t}})),D(null)},[]),I=(0,q.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}]},[]),L=e?.id,R=!!d.memory_settings?.enabled,z=r(),{data:B=null,isLoading:V}=i({queryKey:[`persona-memory-status`,L],queryFn:async()=>{if(!L)return null;let e=await U.getMemoryStatus(L);return e.success&&e.data?e.data:null},enabled:!!L&&R}),H=()=>z.invalidateQueries({queryKey:[`persona-memory-status`,L]}),W=async()=>{if(e?.id&&confirm(u(`personaForm.memory.wipeConfirm`))){j(!0);try{let t=await U.wipeMemories(e.id);t.success?(S.success(u(`personaForm.memory.wipeSuccess`,{count:t.data?.deleted_count||0})),await H()):S.error(u(`personaForm.error.saveFailed`))}catch{S.error(u(`personaForm.error.saveFailed`))}finally{j(!1)}}};(0,q.useEffect)(()=>{M.current||(M.current=!0,(async()=>{x(!0);try{let[t,n]=await Promise.all([te.getModels(),e?Promise.resolve(null):U.getDefaultParameters(),s.getState().models.length===0?g({quiet:!0}):Promise.resolve()]),r=I(t.success&&t.data?t.data:[]);y(r);let i=r.find(e=>e.id===c.embeddingSettings?.model||e.rawModel===c.embeddingSettings?.model)?.id||r[0]?.id||``,a=r.find(t=>t.id===e?.embedding_model||t.rawModel===e?.embedding_model)?.id||e?.embedding_model||r[0]?.id||``;if(e)m({name:e.name,description:e.description||``,model:e.model,parameters:e.parameters,avatar:e.avatar||``,background:e.background||``,embedding_model:a,memory_settings:e.memory_settings||X.memory_settings,mutation_settings:e.mutation_settings||X.mutation_settings,bindings:e.bindings}),e.embedding_model&&!r.find(t=>t.id===e.embedding_model||t.rawModel===e.embedding_model)&&y(t=>I([...t,{id:e.embedding_model,name:e.embedding_model,description:`Previously selected model (not currently available)`,provider:`openai`,dimensions:0}]));else{let e=n?.success?n.data:{};m(t=>({...t,parameters:{...t.parameters,...e},embedding_model:i}))}}catch(e){_e.error(`Error loading data:`,e)}finally{x(!1)}})())},[e,I,g,c.embeddingSettings?.model]);let K=async()=>{T(!0);try{let n={name:d.name,description:d.description,model:d.model,parameters:d.parameters,avatar:d.avatar,background:d.background,embedding_model:d.embedding_model,memory_settings:d.memory_settings,mutation_settings:d.mutation_settings,bindings:d.bindings},r=e?await U.updatePersona(e.id,n):await U.createPersona(d);r.success&&r.data?(S.success(u(e?`personaForm.success.updated`:`personaForm.success.created`)),D(new Date),await t(r.data)):S.error(r.error?`${u(`personaForm.error.saveFailed`)}: ${r.error}`:u(`personaForm.error.saveFailed`))}catch(e){S.error(`${u(`personaForm.error.saveFailed`)}: ${e instanceof Error?e.message:String(e)}`)}finally{T(!1)}},ne=(0,q.useMemo)(()=>[{id:`basic`,label:u(`personaForm.tabs.basic`),icon:w},{id:`parameters`,label:u(`personaForm.tabs.parameters`),icon:O},{id:`memory`,label:u(`personaForm.tabs.memory`),icon:l},{id:`bindings`,label:u(`personaForm.tabs.bindings`),icon:f},{id:`advanced`,label:u(`personaForm.tabs.advanced`),icon:p}],[u]);return b?(0,J.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,J.jsxs)(`div`,{className:`animate-pulse flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-5 h-5 border-2 border-primary-500 border-t-transparent rounded-full animate-spin`}),(0,J.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:u(`personaForm.loading`)})]})}):(0,J.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:u(e?`personaForm.title.edit`:`personaForm.title.create`)}),(0,J.jsx)(`p`,{className:`mt-1 text-gray-600 dark:text-dark-600`,children:u(e?`personaForm.subtitle.edit`:`personaForm.subtitle.create`)})]}),(0,J.jsxs)(`form`,{onSubmit:e=>e.preventDefault(),className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`bg-white dark:bg-dark-100 rounded-lg shadow-sm border border-gray-200 dark:border-dark-300`,children:[(0,J.jsx)(`div`,{className:`flex border-b border-gray-200 dark:border-dark-300`,children:ne.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>A(e.id),className:o(`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,J.jsx)(e.icon,{className:`h-4 w-4`}),e.label]},e.id))}),(0,J.jsxs)(`div`,{className:`p-6`,children:[k===`basic`&&(0,J.jsx)(ue,{formData:d,availableModels:_,onFieldChange:N,onParameterChange:P}),k===`parameters`&&(0,J.jsx)(ge,{parameters:d.parameters,onParameterChange:P}),k===`memory`&&(0,J.jsx)(he,{formData:d,persona:e,memoryStatus:B,loadingMemoryStatus:V,wipingMemories:ee,onSettingsChange:F,onWipeMemories:W}),k===`bindings`&&(0,J.jsx)(me,{bindings:d.bindings,onChange:e=>N(`bindings`,e)}),k===`advanced`&&(0,J.jsx)(se,{embeddingModel:d.embedding_model,embeddingModels:v,onEmbeddingModelChange:e=>N(`embedding_model`,e)})]})]}),(0,J.jsx)(de,{submitting:C,lastSaved:E,onCancel:n,onSave:K})]})]})},ye=L(`components:persona-import-export`),be=({personas:e,onImport:t,onClose:n})=>{let{t:r}=a(),[i,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(``),l=async e=>{try{let t=await U.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),S.success(r(`personaImportExport.exportSuccess`,{name:e.name}))}catch(e){let t=e instanceof Error?e.message:String(e);S.error(r(`personaImportExport.exportFailed`)+`: `+t)}};return(0,J.jsxs)(`div`,{className:`max-w-4xl mx-auto`,children:[(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-dark-800`,children:r(`personaImportExport.title`)}),(0,J.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mt-1`,children:r(`personaImportExport.description`)})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,J.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,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.exportPersonas`)}),e.length===0?(0,J.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 text-center py-8`,children:r(`personaImportExport.noPersonasToExport`)}):(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,J.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:r(`personaImportExport.personasAvailable`,{count:e.length})}),(0,J.jsx)(K,{onClick:async()=>{try{let t=e.map(e=>U.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`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`personas-export-${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o),S.success(r(`personaImportExport.exportAllSuccess`,{count:e.length}))}catch(e){let t=e instanceof Error?e.message:String(e);S.error(r(`personaImportExport.exportAllFailed`)+`: `+t)}},variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`personaImportExport.exportAll`)})]}),(0,J.jsx)(`div`,{className:`space-y-2 max-h-80 overflow-y-auto`,children:e.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-gray-50 dark:bg-dark-200 rounded-md`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`img`,{src:V(e,32),alt:e.name,className:`w-8 h-8 rounded-full`,onError:t=>R(t.currentTarget,e.name,32)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),(0,J.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:e.model})]})]}),(0,J.jsx)(K,{onClick:()=>l(e),variant:`outline`,size:`sm`,className:`px-3 py-1`,children:r(`common.export`)})]},e.id))})]})]}),(0,J.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,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-4`,children:r(`personaImportExport.importPersonas`)}),(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.uploadJsonFile`)}),(0,J.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,J.jsx)(`div`,{className:`text-center text-gray-500 dark:text-dark-500`,children:r(`common.or`).toUpperCase()}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:r(`personaImportExport.pasteJsonLabel`)}),(0,J.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,J.jsx)(K,{onClick:async()=>{if(!s.trim()){S.error(r(`personaImportExport.pasteJsonData`));return}o(!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 U.importPersona(r),t++}catch(e){n++,ye.error(`Failed to import persona:`,e)}t>0?(S.success(r(`personaImportExport.importMultipleSuccess`,{count:t})),n>0&&S.error(r(`personaImportExport.importMultipleFailed`,{count:n}))):S.error(r(`personaImportExport.importNoneFailed`))}else await U.importPersona(e),S.success(r(`personaImportExport.importSuccess`));c(``),t()}catch(e){let t=e instanceof Error?e.message:String(e);S.error(r(`personaImportExport.importFailed`)+`: `+t)}finally{o(!1)}},disabled:!s.trim()||i,className:`w-full`,children:r(i?`personaImportExport.importing`:`personaImportExport.importButton`)})]})]})]}),(0,J.jsxs)(`div`,{className:`mt-6 bg-gray-50 dark:bg-dark-200 rounded-lg p-4`,children:[(0,J.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-dark-800 mb-2`,children:r(`personaImportExport.expectedFormat`)}),(0,J.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,J.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,J.jsx)(K,{onClick:n,variant:`outline`,children:r(`common.close`)})})]})},xe=()=>{let{t:e}=a(),t=r(),[n,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(!1),{data:d=[],isLoading:f,refetch:p}=i({queryKey:[`personas`],queryFn:async()=>{let e=await U.getPersonas();if(!e.success)throw Error(e.error||`Failed to load personas`);return e.data||[]}}),m=async()=>{await t.invalidateQueries({queryKey:[`personas`]}),await p()},h=()=>{c(null),o(!0)},g=e=>{c(e),o(!0)},_=async t=>{if(confirm(e(`personaManager.deleteConfirm`,{name:t.name})))try{let n=await U.deletePersona(t.id);n.success?(S.success(e(`personaManager.deleteSuccess`,{name:t.name})),await m()):S.error(e(`personaManager.failed`,{action:`delete`})+`: `+n.error)}catch(t){let n=t instanceof Error?t.message:String(t);S.error(e(`personaManager.failed`,{action:`delete`})+`: `+n)}},v=async t=>{try{await U.downloadPersona(t.id,t.name),S.success(e(`personaManager.downloadSuccess`,{name:t.name}))}catch(t){let n=t instanceof Error?t.message:String(t);S.error(e(`personaManager.failed`,{action:`download`})+`: `+n)}};return f?(0,J.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,J.jsx)(`div`,{className:`text-gray-600 dark:text-dark-600`,children:e(`personaManager.loading`)})}):n?(0,J.jsx)(ve,{persona:s,onSubmit:async e=>{c(e),await m()},onCancel:()=>{o(!1),c(null)}}):l?(0,J.jsx)(be,{personas:d,onImport:m,onClose:()=>u(!1)}):(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,J.jsxs)(`div`,{className:`text-sm text-gray-500 dark:text-dark-500`,children:[(0,J.jsx)(`span`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e(`personaManager.stats.title`)}),` `,`· `,e(`personaManager.stats.count`,{count:d.length})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(K,{onClick:()=>u(!0),variant:`outline`,className:`px-4`,children:e(`personaManager.importExport`)}),(0,J.jsx)(K,{onClick:h,className:`px-4`,children:e(`personaManager.createButton`)})]})]}),d.length===0?(0,J.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-gray-300 bg-white/40 p-12 text-center dark:border-white/15 dark:bg-white/[0.025]`,children:[(0,J.jsx)(`div`,{className:`text-gray-400 dark:text-dark-500 mb-4`,children:(0,J.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,J.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,J.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800 mb-2`,children:e(`personaManager.empty.title`)}),(0,J.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mb-6`,children:e(`personaManager.empty.description`)}),(0,J.jsx)(K,{onClick:h,className:`px-6 py-2`,children:e(`personaManager.empty.button`)})]}):(0,J.jsx)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3`,children:d.map(e=>(0,J.jsx)(oe,{persona:e,onEdit:g,onDelete:_,onDownload:v},e.id))})]})},Se=()=>{let{t:e}=a();return(0,J.jsxs)(re,{children:[(0,J.jsx)(ne,{title:e(`personaManager.title`),description:e(`personaManager.subtitle`)}),(0,J.jsx)(xe,{})]})};export{Se as PersonasPage,Se as default};
@@ -1 +0,0 @@
1
- import{t as e}from"./RichMessageContent-CC9QZQKd.js";export{e as RichMessageContent,e as default};