libre-webui 0.24.0 → 0.25.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 (244) hide show
  1. package/README.md +26 -15
  2. package/backend/dist/index.d.ts.map +1 -1
  3. package/backend/dist/index.js +9 -0
  4. package/backend/dist/index.js.map +1 -1
  5. package/backend/dist/persistence/postgresMigrationRegistry.d.ts.map +1 -1
  6. package/backend/dist/persistence/postgresMigrationRegistry.js +2 -0
  7. package/backend/dist/persistence/postgresMigrationRegistry.js.map +1 -1
  8. package/backend/dist/persistence/postgresPersonalAutomationsMigration.d.ts +8 -0
  9. package/backend/dist/persistence/postgresPersonalAutomationsMigration.d.ts.map +1 -0
  10. package/backend/dist/persistence/postgresPersonalAutomationsMigration.js +98 -0
  11. package/backend/dist/persistence/postgresPersonalAutomationsMigration.js.map +1 -0
  12. package/backend/dist/persistence/postgresResourceRepositories.d.ts.map +1 -1
  13. package/backend/dist/persistence/postgresResourceRepositories.js +274 -0
  14. package/backend/dist/persistence/postgresResourceRepositories.js.map +1 -1
  15. package/backend/dist/persistence/resourceTypes.d.ts +83 -2
  16. package/backend/dist/persistence/resourceTypes.d.ts.map +1 -1
  17. package/backend/dist/persistence/resourceTypes.js.map +1 -1
  18. package/backend/dist/persistence/sqliteMigrations.d.ts +1 -0
  19. package/backend/dist/persistence/sqliteMigrations.d.ts.map +1 -1
  20. package/backend/dist/persistence/sqliteMigrations.js +181 -0
  21. package/backend/dist/persistence/sqliteMigrations.js.map +1 -1
  22. package/backend/dist/persistence/sqliteResourceRepositories.d.ts.map +1 -1
  23. package/backend/dist/persistence/sqliteResourceRepositories.js +233 -0
  24. package/backend/dist/persistence/sqliteResourceRepositories.js.map +1 -1
  25. package/backend/dist/persistence/sqliteToPostgresMigration.d.ts.map +1 -1
  26. package/backend/dist/persistence/sqliteToPostgresMigration.js +41 -0
  27. package/backend/dist/persistence/sqliteToPostgresMigration.js.map +1 -1
  28. package/backend/dist/platform/jobs/domainJobContracts.d.ts +3 -0
  29. package/backend/dist/platform/jobs/domainJobContracts.d.ts.map +1 -1
  30. package/backend/dist/platform/jobs/domainJobContracts.js +3 -0
  31. package/backend/dist/platform/jobs/domainJobContracts.js.map +1 -1
  32. package/backend/dist/platform/jobs/domainJobHandlers.d.ts.map +1 -1
  33. package/backend/dist/platform/jobs/domainJobHandlers.js +101 -1
  34. package/backend/dist/platform/jobs/domainJobHandlers.js.map +1 -1
  35. package/backend/dist/routes/automations.d.ts +3 -0
  36. package/backend/dist/routes/automations.d.ts.map +1 -0
  37. package/backend/dist/routes/automations.js +232 -0
  38. package/backend/dist/routes/automations.js.map +1 -0
  39. package/backend/dist/routes/calendar.d.ts +3 -0
  40. package/backend/dist/routes/calendar.d.ts.map +1 -0
  41. package/backend/dist/routes/calendar.js +206 -0
  42. package/backend/dist/routes/calendar.js.map +1 -0
  43. package/backend/dist/routes/chat.d.ts.map +1 -1
  44. package/backend/dist/routes/chat.js +99 -7
  45. package/backend/dist/routes/chat.js.map +1 -1
  46. package/backend/dist/routes/ollama.d.ts.map +1 -1
  47. package/backend/dist/routes/ollama.js +4 -1
  48. package/backend/dist/routes/ollama.js.map +1 -1
  49. package/backend/dist/routes/search.d.ts.map +1 -1
  50. package/backend/dist/routes/search.js +5 -3
  51. package/backend/dist/routes/search.js.map +1 -1
  52. package/backend/dist/services/automationSchedulerService.d.ts +28 -0
  53. package/backend/dist/services/automationSchedulerService.d.ts.map +1 -0
  54. package/backend/dist/services/automationSchedulerService.js +191 -0
  55. package/backend/dist/services/automationSchedulerService.js.map +1 -0
  56. package/backend/dist/services/automationService.d.ts +53 -0
  57. package/backend/dist/services/automationService.d.ts.map +1 -0
  58. package/backend/dist/services/automationService.js +224 -0
  59. package/backend/dist/services/automationService.js.map +1 -0
  60. package/backend/dist/services/chatGenerationService.d.ts.map +1 -1
  61. package/backend/dist/services/chatGenerationService.js +7 -1
  62. package/backend/dist/services/chatGenerationService.js.map +1 -1
  63. package/backend/dist/services/chatService.d.ts +9 -1
  64. package/backend/dist/services/chatService.d.ts.map +1 -1
  65. package/backend/dist/services/chatService.js +91 -13
  66. package/backend/dist/services/chatService.js.map +1 -1
  67. package/backend/dist/services/contextCompactionService.d.ts +11 -6
  68. package/backend/dist/services/contextCompactionService.d.ts.map +1 -1
  69. package/backend/dist/services/contextCompactionService.js +127 -27
  70. package/backend/dist/services/contextCompactionService.js.map +1 -1
  71. package/backend/dist/services/durableChatGenerationService.d.ts.map +1 -1
  72. package/backend/dist/services/durableChatGenerationService.js +15 -3
  73. package/backend/dist/services/durableChatGenerationService.js.map +1 -1
  74. package/backend/dist/services/ollamaService.d.ts.map +1 -1
  75. package/backend/dist/services/ollamaService.js +9 -2
  76. package/backend/dist/services/ollamaService.js.map +1 -1
  77. package/backend/dist/services/pluginService.d.ts +10 -0
  78. package/backend/dist/services/pluginService.d.ts.map +1 -1
  79. package/backend/dist/services/pluginService.js +42 -7
  80. package/backend/dist/services/pluginService.js.map +1 -1
  81. package/backend/dist/services/preferencesService.d.ts.map +1 -1
  82. package/backend/dist/services/preferencesService.js +3 -0
  83. package/backend/dist/services/preferencesService.js.map +1 -1
  84. package/backend/dist/services/titleGenerationService.d.ts.map +1 -1
  85. package/backend/dist/services/titleGenerationService.js +5 -1
  86. package/backend/dist/services/titleGenerationService.js.map +1 -1
  87. package/backend/dist/services/webSearchPlanService.d.ts +18 -0
  88. package/backend/dist/services/webSearchPlanService.d.ts.map +1 -0
  89. package/backend/dist/services/webSearchPlanService.js +160 -0
  90. package/backend/dist/services/webSearchPlanService.js.map +1 -0
  91. package/backend/dist/services/webSearchService.d.ts +9 -3
  92. package/backend/dist/services/webSearchService.d.ts.map +1 -1
  93. package/backend/dist/services/webSearchService.js +8 -2
  94. package/backend/dist/services/webSearchService.js.map +1 -1
  95. package/backend/dist/storage.d.ts +7 -1
  96. package/backend/dist/storage.d.ts.map +1 -1
  97. package/backend/dist/storage.js +65 -1
  98. package/backend/dist/storage.js.map +1 -1
  99. package/backend/dist/types/index.d.ts +79 -0
  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/utils/automationSchedule.d.ts +26 -0
  103. package/backend/dist/utils/automationSchedule.d.ts.map +1 -0
  104. package/backend/dist/utils/automationSchedule.js +231 -0
  105. package/backend/dist/utils/automationSchedule.js.map +1 -0
  106. package/backend/dist/utils/chatContext.d.ts +7 -0
  107. package/backend/dist/utils/chatContext.d.ts.map +1 -1
  108. package/backend/dist/utils/chatContext.js +13 -2
  109. package/backend/dist/utils/chatContext.js.map +1 -1
  110. package/backend/dist/utils/openAIResponsesAdapter.d.ts.map +1 -1
  111. package/backend/dist/utils/openAIResponsesAdapter.js +3 -1
  112. package/backend/dist/utils/openAIResponsesAdapter.js.map +1 -1
  113. package/backend/dist/utils/pluginChatAdapter.d.ts +1 -0
  114. package/backend/dist/utils/pluginChatAdapter.d.ts.map +1 -1
  115. package/backend/dist/utils/pluginChatAdapter.js +82 -19
  116. package/backend/dist/utils/pluginChatAdapter.js.map +1 -1
  117. package/backend/dist/utils/pluginModelCatalog.d.ts +20 -0
  118. package/backend/dist/utils/pluginModelCatalog.d.ts.map +1 -1
  119. package/backend/dist/utils/pluginModelCatalog.js +101 -9
  120. package/backend/dist/utils/pluginModelCatalog.js.map +1 -1
  121. package/backend/dist/utils/resourceLimits.d.ts +7 -0
  122. package/backend/dist/utils/resourceLimits.d.ts.map +1 -1
  123. package/backend/dist/utils/resourceLimits.js +7 -0
  124. package/backend/dist/utils/resourceLimits.js.map +1 -1
  125. package/backend/dist/utils/thinkingOptions.d.ts +23 -3
  126. package/backend/dist/utils/thinkingOptions.d.ts.map +1 -1
  127. package/backend/dist/utils/thinkingOptions.js +35 -9
  128. package/backend/dist/utils/thinkingOptions.js.map +1 -1
  129. package/backend/dist/websocketServer.d.ts.map +1 -1
  130. package/backend/dist/websocketServer.js +9 -3
  131. package/backend/dist/websocketServer.js.map +1 -1
  132. package/backend/package.json +1 -1
  133. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  134. package/frontend/dist/assets/index-6o-Hc2wS.js +41 -0
  135. package/frontend/dist/assets/index-D-pM957b.css +1 -0
  136. package/frontend/dist/index.html +12 -12
  137. package/frontend/dist/js/ArtifactContainer-CpUi6ekF.js +1 -0
  138. package/frontend/dist/js/{ArtifactDemoPage-TONeQvof.js → ArtifactDemoPage-BeNs3gHp.js} +1 -1
  139. package/frontend/dist/js/{ArtifactSandboxFrame-CV2XXu_t.js → ArtifactSandboxFrame-qsj_Y3LV.js} +2 -2
  140. package/frontend/dist/js/ArtifactSlideOutPanel-CSFRluWA.js +1 -0
  141. package/frontend/dist/js/AutomationsPage-KUeWoZNv.js +1 -0
  142. package/frontend/dist/js/CalendarPage-D9I972w8.js +1 -0
  143. package/frontend/dist/js/ChatPage-CmBx4oAL.js +16 -0
  144. package/frontend/dist/js/{FirstTimeSetup-smhj0X6o.js → FirstTimeSetup-Df0YJni3.js} +1 -1
  145. package/frontend/dist/js/GalleryPage-bLCrdJN_.js +1 -0
  146. package/frontend/dist/js/HomePage-Uc6PEg-U.js +1 -0
  147. package/frontend/dist/js/{LibreClawPage-CRKei1MM.js → LibreClawPage-CG63DHg1.js} +1 -1
  148. package/frontend/dist/js/{ModelManagerModals-D0amaOnl.js → ModelManagerModals-DcLGYN3l.js} +1 -1
  149. package/frontend/dist/js/ModelSelector-yxJC64rM.js +1 -0
  150. package/frontend/dist/js/ModelsPage-1R_TxgmJ.js +2 -0
  151. package/frontend/dist/js/NotesPage-L65j5HoW.js +1 -0
  152. package/frontend/dist/js/PersonasPage-CKeBpHIH.js +13 -0
  153. package/frontend/dist/js/PluginUsagePage-BX1SKMbW.js +1 -0
  154. package/frontend/dist/js/{RichMessageContent-Bxi_u0gC.js → RichMessageContent-DiySVYGB.js} +1 -1
  155. package/frontend/dist/js/SettingsModal-68SG1uZ2.js +1 -0
  156. package/frontend/dist/js/SystemPage-CytpZiQV.js +1 -0
  157. package/frontend/dist/js/UserManagementPage-BzJBvZiS.js +1 -0
  158. package/frontend/dist/js/WorkPage-C8gr0QJe.js +6 -0
  159. package/frontend/dist/js/api-BDtqBtqw.js +14 -0
  160. package/frontend/dist/js/{appStore-CJtomipz.js → appStore-0JnCUlEq.js} +2 -2
  161. package/frontend/dist/js/ar-CSpi37Gr.js +2 -0
  162. package/frontend/dist/js/{authStore-BckFDL70.js → authStore-DbMdvNgJ.js} +3 -3
  163. package/frontend/dist/js/{babel-D24oDI9y.js → babel-BsYoxD-7.js} +1 -1
  164. package/frontend/dist/js/bn-CyH1BeDD.js +2 -0
  165. package/frontend/dist/js/calendarDates-Co3o_05Y.js +1 -0
  166. package/frontend/dist/js/chatStore-CHQ2uINS.js +3 -0
  167. package/frontend/dist/js/{config-CNVNpf_q.js → config-DSOYQ9a3.js} +1 -1
  168. package/frontend/dist/js/cs-Cv2NfRK5.js +2 -0
  169. package/frontend/dist/js/da-D6D6IvPK.js +2 -0
  170. package/frontend/dist/js/de-BNoJJTrT.js +2 -0
  171. package/frontend/dist/js/es-kzo9C7q_.js +2 -0
  172. package/frontend/dist/js/{estree-D1TYSBcf.js → estree-BcnBcOAx.js} +7 -7
  173. package/frontend/dist/js/fr-CjHYvJRp.js +2 -0
  174. package/frontend/dist/js/hi-BU98AdCQ.js +2 -0
  175. package/frontend/dist/js/{html-Dmddj0zf.js → html-DkY55Jys.js} +10 -10
  176. package/frontend/dist/js/id-CpdedejX.js +2 -0
  177. package/frontend/dist/js/is-Cp5dDWBH.js +2 -0
  178. package/frontend/dist/js/it-CuH_cK4U.js +2 -0
  179. package/frontend/dist/js/ja-BWXXXiHn.js +2 -0
  180. package/frontend/dist/js/ko-DQgv2M1t.js +2 -0
  181. package/frontend/dist/js/{markdown-Bl_LsHEk.js → markdown-IZSI9DXw.js} +6 -6
  182. package/frontend/dist/js/{messageCodeStyles-CgKxn4tN.js → messageCodeStyles-BFNR9Wv6.js} +2 -2
  183. package/frontend/dist/js/ms-DCcRoIcX.js +2 -0
  184. package/frontend/dist/js/nl-CbKR1_EU.js +2 -0
  185. package/frontend/dist/js/pl-CRyJZccn.js +2 -0
  186. package/frontend/dist/js/{postcss-Bx9CTcIc.js → postcss-BJ0okz7n.js} +1 -1
  187. package/frontend/dist/js/pt-BXYmHFGH.js +2 -0
  188. package/frontend/dist/js/{router-vendor-CbPDks39.js → router-vendor-DGFGM3EP.js} +1 -1
  189. package/frontend/dist/js/ru-M9SyZG4b.js +2 -0
  190. package/frontend/dist/js/{standalone-BWau8hEE.js → standalone-Csw3jfJ_.js} +5 -5
  191. package/frontend/dist/js/sv-DJ486LTU.js +2 -0
  192. package/frontend/dist/js/th-Ch7gKtZv.js +2 -0
  193. package/frontend/dist/js/tr-ClehWhSC.js +2 -0
  194. package/frontend/dist/js/{typescript-DxGn3Yn-.js → typescript-CnF4UVx7.js} +2 -2
  195. package/frontend/dist/js/{ui-jlx9WA5A.js → ui-CC-K19wO.js} +2 -2
  196. package/frontend/dist/js/ui-vendor-B1UgO3vd.js +177 -0
  197. package/frontend/dist/js/uk-BqAd5zHF.js +2 -0
  198. package/frontend/dist/js/{vi-BgRaIrQC.js → vi-D9gjlDVB.js} +2 -2
  199. package/frontend/dist/js/{workApi-DWRpZ_cq.js → workApi-C3uy9EDT.js} +3 -3
  200. package/frontend/dist/js/{yaml-DioTxVLA.js → yaml-DzT5hBSH.js} +5 -5
  201. package/frontend/dist/js/zh-DKTyHkiR.js +2 -0
  202. package/package.json +2 -2
  203. package/frontend/dist/assets/index-BlTbxYPP.js +0 -33
  204. package/frontend/dist/assets/index-CbiWSGOj.css +0 -1
  205. package/frontend/dist/js/ArtifactContainer-C-n1vPsA.js +0 -1
  206. package/frontend/dist/js/ArtifactSlideOutPanel-2exw7YqL.js +0 -1
  207. package/frontend/dist/js/ChatPage-wnyG_TyC.js +0 -23
  208. package/frontend/dist/js/GalleryPage-BZfeWlBg.js +0 -1
  209. package/frontend/dist/js/HomePage-gf4GgI6z.js +0 -1
  210. package/frontend/dist/js/ModelSelector-C5Tn6y0p.js +0 -1
  211. package/frontend/dist/js/ModelsPage-Rbags4Xq.js +0 -2
  212. package/frontend/dist/js/NotesPage-9NR9HZZ8.js +0 -1
  213. package/frontend/dist/js/PersonasPage-DYP67Qiy.js +0 -13
  214. package/frontend/dist/js/PluginUsagePage-QtCgymRu.js +0 -1
  215. package/frontend/dist/js/SettingsModal-B4RelkLP.js +0 -1
  216. package/frontend/dist/js/SystemPage-xFSTYdBS.js +0 -1
  217. package/frontend/dist/js/UserManagementPage-Cp430WCP.js +0 -1
  218. package/frontend/dist/js/WorkPage-DFES41Qm.js +0 -6
  219. package/frontend/dist/js/api-DUUxxx_B.js +0 -14
  220. package/frontend/dist/js/ar-DMH3qbt6.js +0 -2
  221. package/frontend/dist/js/bn-CGDX8khx.js +0 -2
  222. package/frontend/dist/js/chatStore-DK-_wd-j.js +0 -3
  223. package/frontend/dist/js/cs-CJLgUk3m.js +0 -2
  224. package/frontend/dist/js/da-DnZMnCVM.js +0 -2
  225. package/frontend/dist/js/de-CWpguVQ5.js +0 -2
  226. package/frontend/dist/js/es-DVU1vjm0.js +0 -2
  227. package/frontend/dist/js/fr-pWnSnypD.js +0 -2
  228. package/frontend/dist/js/hi-B6xDfxA5.js +0 -2
  229. package/frontend/dist/js/id-BThSTUAG.js +0 -2
  230. package/frontend/dist/js/is-BOohDFie.js +0 -2
  231. package/frontend/dist/js/it-BdRArcCC.js +0 -2
  232. package/frontend/dist/js/ja-5Cq35sMr.js +0 -2
  233. package/frontend/dist/js/ko-BlzNRtpQ.js +0 -2
  234. package/frontend/dist/js/ms-CtGeurkZ.js +0 -2
  235. package/frontend/dist/js/nl-MKPHGjVF.js +0 -2
  236. package/frontend/dist/js/pl-BwBrqCey.js +0 -2
  237. package/frontend/dist/js/pt-CKzoHWBB.js +0 -2
  238. package/frontend/dist/js/ru-BQC4jh0Y.js +0 -2
  239. package/frontend/dist/js/sv-Cm0qXxzM.js +0 -2
  240. package/frontend/dist/js/th-DUPbiRI2.js +0 -2
  241. package/frontend/dist/js/tr-AsFu_Br5.js +0 -2
  242. package/frontend/dist/js/ui-vendor-54SgntkX.js +0 -177
  243. package/frontend/dist/js/uk-DrMMOZ17.js +0 -2
  244. package/frontend/dist/js/zh-B4rcgcAy.js +0 -2
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{t as i}from"./useTranslation-Bho4HCyg.js";import{t as a}from"./utils-D9W1Lnkn.js";import{C as ee,t as o}from"./chatStore-CHQ2uINS.js";import{$t as te,Dt as ne,Ht as s,Jt as re,Kt as ie,Ot as ae,Xt as oe,_n as se,hn as c,m as l,mn as u,n as d,nn as f,tn as p}from"./ui-vendor-B1UgO3vd.js";import{t as m}from"./logger-DSXjF4ye.js";import{t as ce}from"./appStore-0JnCUlEq.js";import{t as h}from"./Button-BPf_pOxH.js";import{t as g}from"./OptimizedSyntaxHighlighter-Dz7D1LPB.js";import{a as le,i as ue,l as de,n as _,o as fe,r as v,t as y}from"./ArtifactSandboxFrame-qsj_Y3LV.js";var b=e(t(),1),pe=r(),x=n(),S=m(`components:artifact-slide-out-panel`),C=320,w=.9,me=600,T=()=>{let{t:e,i18n:t}=i(),n=ee(t.language),{artifactPanelOpen:r,artifactPanelArtifact:m,openArtifactPanel:T,closeArtifactPanel:E,theme:D}=ce(),O=o(e=>e.currentSession),k=b.useMemo(()=>{if(!m)return[];let e=m.title.trim().toLowerCase(),t=(O?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===m.id)?t:[...t,m]},[O,m]),A=k.findIndex(e=>e.id===m?.id),[he,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(`preview`),[P,F]=(0,b.useState)(me),[I,L]=(0,b.useState)(!1),R=(0,b.useRef)(null),z=(0,b.useRef)(null),B=(0,b.useRef)(0),V=(0,b.useRef)(0),H=(0,b.useRef)(null),U=(0,b.useRef)(null),W=(0,b.useRef)(P),G=m?.id??null;G!==z.current&&(z.current=G,M!==`preview`&&N(`preview`));let K=(0,b.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,F(W.current)}))},[]),q=(0,b.useCallback)(()=>{H.current=null,L(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,F(W.current))},[]),ge=(0,b.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=P,B.current=e.clientX,W.current=P,e.currentTarget.setPointerCapture(e.pointerId),L(!0)},[P]),J=(0,b.useCallback)(e=>{if(!I||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=window.innerWidth*w,i=Math.min(r,Math.max(C,V.current+t));K(i)},[I,n,K]);if((0,b.useEffect)(()=>{if(!I){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[I,J,q]),(0,b.useEffect)(()=>{let e=()=>{let e=window.innerWidth*w;P>e&&F(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[P]),(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r&&E()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,E]),(0,b.useEffect)(()=>{let e=e=>{I||R.current&&!R.current.contains(e.target)&&r&&E()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,E,I]),!m)return null;let Y=m,_e=async e=>{try{await navigator.clipboard.writeText(e),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){S.error(`Failed to copy:`,e)}},ve=()=>{let e=Y.type===`html`?le(Y.content,Y.title):Y.content,t=new Blob([e],{type:ye(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${be(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ye=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},be=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},xe=()=>{switch(Y.type){case`html`:return(0,x.jsx)(ae,{className:`h-5 w-5`});case`react`:return(0,x.jsx)(p,{className:`h-5 w-5`});case`svg`:return(0,x.jsx)(s,{className:`h-5 w-5`});case`code`:return(0,x.jsx)(p,{className:`h-5 w-5`});default:return(0,x.jsx)(s,{className:`h-5 w-5`})}},X=()=>(0,x.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,x.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,x.jsx)(l,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,x.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,x.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,x.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>N(`code`),className:`mt-4`,children:[(0,x.jsx)(f,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Se=async()=>{try{let e=await v(_(Y.type)??`html`,Y.content,Y.title,{colorScheme:D.mode===`dark`?`dark`:`light`});de(e,ue,Y.title)}catch(e){S.error(`Failed to open the artifact preview:`,e)}},Z=e=>Y.content.trim()?(0,x.jsx)(y,{content:Y.content,title:Y.title,kind:e,colorScheme:D.mode===`dark`?`dark`:`light`,className:a(`w-full h-full border-0 rounded-lg bg-white`,I&&`pointer-events-none`),fallback:X()}):X(),Ce=()=>(0,x.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:fe(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(g,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:Y.content})}),we=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(g,{language:`json`,isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,x.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,x.jsxs)(`div`,{className:`text-center`,children:[(0,x.jsx)(l,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},Te=()=>{if(M===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return Ce();case`json`:return we();default:return Q()}},Ee=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,De=$?`100%`:`${P}px`,Oe=(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:a(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),I&&(0,x.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,x.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:De},className:a(`fixed top-0 end-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,x.jsxs)(`div`,{onPointerDown:ge,"data-testid":`artifact-resize-handle`,className:a(`absolute start-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,x.jsx)(`div`,{className:a(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,I&&`bg-primary-500 h-24`)}),(0,x.jsx)(`div`,{className:a(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,I&&`opacity-100`),children:(0,x.jsx)(ne,{className:`h-4 w-4`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,x.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:xe()}),(0,x.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:Y.title}),(0,x.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:Y.type.toUpperCase()})]}),(0,x.jsx)(h,{variant:`ghost`,size:`sm`,onClick:E,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,x.jsx)(d,{className:`h-5 w-5`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[k.length>1&&A!==-1&&(0,x.jsxs)(`div`,{className:`me-1 flex items-center gap-0.5`,children:[(0,x.jsx)(h,{variant:`ghost`,size:`sm`,disabled:A===0,onClick:()=>T(k[A-1]),className:`h-8 w-8 p-0`,title:e(`artifacts.previousVersion`),children:(0,x.jsx)(c,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,x.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:A+1,total:k.length})}),(0,x.jsx)(h,{variant:`ghost`,size:`sm`,disabled:A===k.length-1,onClick:()=>T(k[A+1]),className:`h-8 w-8 p-0`,title:e(`artifacts.nextVersion`),children:(0,x.jsx)(u,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Ee()&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(h,{variant:M===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,x.jsx)(ie,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.preview`)]}),(0,x.jsxs)(h,{variant:M===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,x.jsx)(f,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,x.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>_e(Y.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:he?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(se,{className:`h-3.5 w-3.5 me-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(te,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.copyButton`)]})}),(0,x.jsxs)(h,{variant:`ghost`,size:`sm`,onClick:ve,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,x.jsx)(oe,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.download`)]}),_(Y.type)&&(0,x.jsxs)(h,{variant:`ghost`,size:`sm`,onClick:()=>Se(),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.openInNewWindow`),children:[(0,x.jsx)(re,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.open`)]})]})]}),Y.description&&(0,x.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:Y.description})}),(0,x.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:Te()}),(0,x.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:(0,x.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,x.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(Y.createdAt).toLocaleString()]}),!$&&(0,x.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]});return(0,pe.createPortal)(Oe,document.body)};export{T as ArtifactSlideOutPanel};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{d as i}from"./router-vendor-DGFGM3EP.js";import{t as a}from"./useTranslation-Bho4HCyg.js";import{r as o,t as s}from"./utils-D9W1Lnkn.js";import{t as c}from"./chatStore-CHQ2uINS.js";import{B as l,Rn as u,U as d,W as f,Y as p,Yt as m,cn as h,g,in as _,mt as v,n as y,on as b,q as x,sn as S,t as C}from"./ui-vendor-B1UgO3vd.js";import{t as w}from"./logger-DSXjF4ye.js";import{x as T}from"./api-BDtqBtqw.js";import{t as E}from"./Button-BPf_pOxH.js";import"./ui-CC-K19wO.js";import{c as D,d as O,l as k,n as A}from"./calendarDates-Co3o_05Y.js";var j=e(t(),1),M=r(),N=(e,t,n)=>new Intl.DateTimeFormat(n,{hour:`numeric`,minute:`2-digit`}).format(new Date(2024,0,1,e,t)),P=(e,t)=>new Intl.DateTimeFormat(t,{weekday:`long`}).format(new Date(2024,0,7+e)),F=(e,t,n)=>new Intl.DateTimeFormat(n,{month:`long`,day:`numeric`}).format(new Date(2024,e-1,t));function I(e,t,n){switch(e.kind){case`once`:return n(`automations.trigger.once`,{when:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.at))});case`hourly`:{let t=e.startHour!==void 0||e.endHour!==void 0?` (${e.startHour??0}–${e.endHour??23})`:``;return n(`automations.trigger.hourly`,{minute:String(e.minute).padStart(2,`0`)})+t}case`daily`:return n(`automations.trigger.daily`,{time:N(e.hour,e.minute,t)});case`weekly`:return n(`automations.trigger.weekly`,{day:P(e.dayOfWeek,t),time:N(e.hour,e.minute,t)});case`monthly`:return n(`automations.trigger.monthly`,{day:e.dayOfMonth,time:N(e.hour,e.minute,t)});case`yearly`:return n(`automations.trigger.yearly`,{date:F(e.month,e.dayOfMonth,t),time:N(e.hour,e.minute,t)})}}function L(e,t,n){return e.map(e=>I(e,t,n)).join(` · `)}function R(e){let t=(e,t,n)=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=t&&e<=n;switch(e.kind){case`once`:return t(e.at,0,864e13);case`hourly`:return t(e.minute,0,59)&&(e.startHour===void 0||t(e.startHour,0,23))&&(e.endHour===void 0||t(e.endHour,0,23))&&(e.startHour===void 0||e.endHour===void 0||e.endHour>=e.startHour);case`daily`:return t(e.hour,0,23)&&t(e.minute,0,59);case`weekly`:return t(e.dayOfWeek,0,6)&&t(e.hour,0,23)&&t(e.minute,0,59);case`monthly`:return t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);case`yearly`:return t(e.month,1,12)&&t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);default:return!1}}var z=n(),B=[`once`,`hourly`,`daily`,`weekly`,`monthly`,`yearly`],V=`rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,H=(e,t)=>`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`,U=e=>{switch(e){case`once`:{let e=new Date;return e.setHours(e.getHours()+1,0,0,0),{kind:`once`,at:e.getTime()}}case`hourly`:return{kind:`hourly`,minute:0};case`daily`:return{kind:`daily`,hour:8,minute:0};case`weekly`:return{kind:`weekly`,dayOfWeek:1,hour:9,minute:0};case`monthly`:return{kind:`monthly`,dayOfMonth:1,hour:9,minute:0};case`yearly`:return{kind:`yearly`,month:1,dayOfMonth:1,hour:9,minute:0}}};function W({trigger:e,onChange:t,onRemove:n}){let{t:r,i18n:i}=a(),o=O(i.language,`short`),s=new Intl.DateTimeFormat(i.language,{month:`long`}),c=n=>{let[r,i]=(n||`00:00`).split(`:`).map(Number);e.kind!==`hourly`&&e.kind!==`once`&&t({...e,hour:r,minute:i})},l=e.kind!==`once`&&e.kind!==`hourly`?(0,z.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:H(e.hour,e.minute),onChange:e=>c(e.target.value),className:V}):null;return(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-black/[0.06] bg-black/[0.02] px-2.5 py-2 dark:border-white/[0.06] dark:bg-white/[0.03]`,"data-testid":`automation-trigger`,children:[(0,z.jsx)(_,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,z.jsx)(`select`,{"aria-label":r(`automations.form.frequency`),value:e.kind,onChange:e=>t(U(e.target.value)),className:V,"data-testid":`automation-trigger-kind`,children:B.map(e=>(0,z.jsx)(`option`,{value:e,children:r(`automations.kind.${e}`)},e))}),e.kind===`once`&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`input`,{type:`date`,"aria-label":r(`calendar.date`),value:D(e.at),onChange:n=>t({...e,at:A(n.target.value,k(e.at))}),className:V}),(0,z.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:k(e.at),onChange:n=>t({...e,at:A(D(e.at),n.target.value)}),className:V})]}),e.kind===`hourly`&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.minute`),(0,z.jsx)(`input`,{type:`number`,min:0,max:59,value:e.minute,onChange:n=>t({...e,minute:Math.min(59,Math.max(0,Number(n.target.value)))}),className:`${V} w-16`})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.fromHour`),(0,z.jsx)(`input`,{type:`number`,min:0,max:23,value:e.startHour??0,onChange:n=>t({...e,startHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${V} w-16`})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.toHour`),(0,z.jsx)(`input`,{type:`number`,min:0,max:23,value:e.endHour??23,onChange:n=>t({...e,endHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${V} w-16`})]})]}),e.kind===`weekly`&&(0,z.jsx)(`select`,{"aria-label":r(`automations.form.weekday`),value:e.dayOfWeek,onChange:n=>t({...e,dayOfWeek:Number(n.target.value)}),className:V,children:o.map((e,t)=>(0,z.jsx)(`option`,{value:t,children:e},e))}),(e.kind===`monthly`||e.kind===`yearly`)&&(0,z.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.dayOfMonth`),(0,z.jsx)(`input`,{type:`number`,min:1,max:31,value:e.dayOfMonth,onChange:n=>t({...e,dayOfMonth:Math.min(31,Math.max(1,Number(n.target.value)))}),className:`${V} w-16`})]}),e.kind===`yearly`&&(0,z.jsx)(`select`,{"aria-label":r(`automations.form.month`),value:e.month,onChange:n=>t({...e,month:Number(n.target.value)}),className:V,children:Array.from({length:12},(e,t)=>(0,z.jsx)(`option`,{value:t+1,children:s.format(new Date(2024,t,1))},t+1))}),l,n&&(0,z.jsx)(`button`,{type:`button`,onClick:n,"aria-label":r(`common.delete`),className:`ms-auto rounded-md p-1 text-red-500 transition-colors hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,z.jsx)(g,{className:`h-3.5 w-3.5`})})]})}var G=`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,K=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,q=e=>e.isPlugin&&e.pluginId?`plugin:${e.pluginId}`:e.isAgent&&e.agentId?`agent:${e.agentId}`:`ollama`;function ee({open:e,automation:t,initial:n,models:r,saving:i,onClose:a,onSave:o}){return e?(0,z.jsx)(J,{automation:t,initial:n,models:r,saving:i,onClose:a,onSave:o},t?.id??n?.name??`new`):null}function J({automation:e,initial:t,models:n,saving:r,onClose:i,onSave:o}){let{t:s}=a(),[c,l]=(0,j.useState)(e?.name??t?.name??``),[u,f]=(0,j.useState)(e?.instructions??t?.instructions??``),[p,m]=(0,j.useState)(e?.triggers??t?.triggers??[{kind:`daily`,hour:8,minute:0}]),[h,g]=(0,j.useState)(e?.model??``),[_,v]=(0,j.useState)(e?.notify??`app`),b=c.trim().length>0&&u.trim().length>0&&p.length>0&&p.every(R);return(0,M.createPortal)((0,z.jsx)(`div`,{className:`fixed inset-0 z-[2147483647] flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:i,children:(0,z.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`automation-modal-title`,"data-testid":`automation-modal`,className:`max-h-[90vh] w-full max-w-lg overflow-y-auto rounded-3xl border border-black/[0.07] bg-white p-6 shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in scrollbar-thin dark:border-white/[0.08] dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,z.jsx)(`h3`,{id:`automation-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:s(e?`automations.editAutomation`:`automations.newAutomation`)}),(0,z.jsx)(`button`,{onClick:i,"aria-label":s(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,z.jsx)(y,{size:20,className:`text-gray-500`})})]}),(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`automation-name`,className:K,children:s(`automations.form.name`)}),(0,z.jsx)(`input`,{id:`automation-name`,"data-testid":`automation-name`,type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:s(`automations.form.namePlaceholder`),className:G,maxLength:200,autoFocus:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:K,children:s(`automations.form.triggers`)}),(0,z.jsxs)(`div`,{className:`space-y-2`,children:[p.map((e,t)=>(0,z.jsx)(W,{trigger:e,onChange:e=>m(n=>n.map((n,r)=>r===t?e:n)),onRemove:p.length>1?()=>m(e=>e.filter((e,n)=>n!==t)):void 0},t)),p.length<5&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>[...e,{kind:`daily`,hour:8,minute:0}]),"data-testid":`automation-add-trigger`,className:`flex items-center gap-1.5 rounded-lg px-2 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:[(0,z.jsx)(d,{className:`h-3.5 w-3.5`}),s(`automations.form.addTrigger`)]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`automation-instructions`,className:K,children:s(`automations.form.instructions`)}),(0,z.jsx)(`textarea`,{id:`automation-instructions`,"data-testid":`automation-instructions`,value:u,onChange:e=>f(e.target.value),placeholder:s(`automations.form.instructionsPlaceholder`),rows:5,className:G,maxLength:2e4})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`automation-model`,className:K,children:s(`automations.form.model`)}),(0,z.jsxs)(`select`,{id:`automation-model`,value:h,onChange:e=>g(e.target.value),className:G,children:[(0,z.jsx)(`option`,{value:``,children:s(`automations.form.modelAuto`)}),n.map(e=>(0,z.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`automation-notify`,className:K,children:s(`automations.form.notification`)}),(0,z.jsxs)(`select`,{id:`automation-notify`,value:_,onChange:e=>v(e.target.value),className:G,children:[(0,z.jsx)(`option`,{value:`app`,children:s(`automations.form.notifyApp`)}),(0,z.jsx)(`option`,{value:`off`,children:s(`automations.form.notifyOff`)})]})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[(0,z.jsx)(`button`,{onClick:i,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:s(`common.cancel`)}),(0,z.jsx)(`button`,{onClick:()=>{if(!b)return;let e=n.find(e=>e.name===h);o({name:c.trim(),instructions:u.trim(),triggers:p,...e?{provider:q(e),model:e.name}:{},notify:_})},disabled:r||!b,"data-testid":`automation-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:s(r?`common.saving`:`common.save`)})]})]})]})}),document.body)}function te({days:e,locale:t}){let{t:n}=a(),r=e.reduce((e,t)=>e+t.succeeded,0),i=e.reduce((e,t)=>e+t.failed,0),o=Math.max(1,...e.map(e=>e.succeeded+e.failed)),s=new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}),c=new Date,l=e=>s.format(new Date(c.getFullYear(),c.getMonth(),c.getDate()-29+e));return(0,z.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.06] bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,"data-testid":`automation-run-strip`,children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,z.jsx)(`p`,{className:`text-[12px] font-medium text-gray-700 dark:text-dark-700`,children:n(`automations.runHistory`)}),(0,z.jsxs)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:[(0,z.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[r,` `,n(`automations.succeeded`)]}),` · `,(0,z.jsxs)(`span`,{className:`text-red-500 dark:text-red-400`,children:[i,` `,n(`automations.failed`)]})]})]}),(0,z.jsx)(`div`,{className:`flex h-12 items-end gap-[3px]`,children:e.map((e,t)=>{let n=e.succeeded+e.failed;if(n===0)return(0,z.jsx)(`div`,{title:l(t),className:`h-[3px] flex-1 rounded-sm bg-black/[0.06] dark:bg-white/[0.08]`},t);let r=Math.max(6,Math.round(n/o*48)),i=Math.round(e.failed/n*r);return(0,z.jsxs)(`div`,{title:`${l(t)}: ${e.succeeded}✓ ${e.failed}✗`,className:`flex flex-1 flex-col justify-end overflow-hidden rounded-sm`,style:{height:r},children:[(0,z.jsx)(`div`,{className:`w-full bg-emerald-500/80`,style:{height:r-i}}),i>0&&(0,z.jsx)(`div`,{className:`w-full bg-red-500/80`,style:{height:i}})]},t)})})]})}var ne=[{id:`morningBrief`,instructions:`Put together my morning brief: the top world, business, and tech headlines from the last 24 hours with one-line summaries, and one story worth reading in depth and why. Keep the whole thing scannable.`,triggers:[{kind:`daily`,hour:7,minute:30}]},{id:`newsDigest`,instructions:`Summarize the most important AI news from the last 24 hours: model releases, notable research papers, funding rounds, and policy changes. For each item add one sentence on why it matters. Skip minor product updates and rumors.`,triggers:[{kind:`daily`,hour:8,minute:0}]},{id:`weeklyReview`,instructions:`Help me wrap the week: prompt me to reflect on what I accomplished, what is still open, and what the top priorities for next week should be. Structure it as a short template I can fill in.`,triggers:[{kind:`weekly`,dayOfWeek:5,hour:16,minute:0}]},{id:`monthlyReport`,instructions:`Draft a monthly status report outline: key accomplishments, metrics to review, risks, and goals for the next month. Leave placeholders where my specifics belong.`,triggers:[{kind:`monthly`,dayOfMonth:1,hour:9,minute:0}]}],Y=w(`pages:automations`),X=()=>{let{t:e,i18n:t}=a(),n=i(),r=c(e=>e.models),_=c(e=>e.loadModels),[y,w]=(0,j.useState)(`automations`),[D,O]=(0,j.useState)([]),[k,A]=(0,j.useState)([]),[M,N]=(0,j.useState)(null),[P,F]=(0,j.useState)(!0),[I,R]=(0,j.useState)(!1),[B,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(null),[W,G]=(0,j.useState)(!1),[K,q]=(0,j.useState)(null),[J,X]=(0,j.useState)(0),Q=(0,j.useCallback)(()=>X(e=>e+1),[]);(0,j.useEffect)(()=>{let t=!1;return Promise.all([T.getAutomations(),T.getRuns(),T.getRunsSummary()]).then(([e,n,r])=>{t||(e.success&&e.data&&O(e.data),n.success&&n.data&&A(n.data),r.success&&r.data&&N(r.data))}).catch(n=>{t||(Y.error(`Failed to load automations:`,n),u.error(e(`automations.loadFailed`)))}).finally(()=>{t||F(!1)}),()=>{t=!0}},[J,e]),(0,j.useEffect)(()=>{r.length===0&&_({quiet:!0})},[r.length,_]),(0,j.useEffect)(()=>{y===`runs`&&T.markRunsSeen().then(()=>T.getRunsSummary()).then(e=>{e.success&&e.data&&N(e.data)}).catch(()=>void 0)},[y,k.length]);let re=()=>{V(null),U(null),R(!0)},ie=t=>{V(null),U({name:e(`automations.templates.${t.id}.name`),instructions:t.instructions,triggers:t.triggers}),R(!0)},ae=e=>{V(e),U(null),q(null),R(!0)},oe=async t=>{G(!0);try{let n=B?await T.updateAutomation(B.id,t):await T.createAutomation(t);n.success?(R(!1),Q()):u.error(n.error||e(`automations.saveFailed`))}catch(t){Y.error(`Failed to save automation:`,t),u.error(e(`automations.saveFailed`))}finally{G(!1)}},$=async(t,n)=>{q(null);try{n===`pause`?await T.pauseAutomation(t.id):n===`resume`?await T.resumeAutomation(t.id):n===`run`?(await T.runAutomationNow(t.id),u.success(e(`automations.runQueued`))):await T.deleteAutomation(t.id),Q()}catch(t){Y.error(`Automation ${n} failed:`,t),u.error(e(`automations.actionFailed`))}},se=e=>e.status===`succeeded`?(0,z.jsx)(h,{className:`h-4 w-4 text-emerald-500`}):e.status===`failed`?(0,z.jsx)(b,{className:`h-4 w-4 text-red-500`}):(0,z.jsx)(v,{className:`h-4 w-4 animate-spin text-gray-400`}),ce=t=>D.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`);return(0,z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`automations-page`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-black/[0.06] px-4 py-3 dark:border-white/[0.07]`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`automations.title`)}),(0,z.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/[0.04] p-0.5 dark:bg-white/[0.06]`,children:[`automations`,`runs`].map(t=>(0,z.jsx)(`button`,{onClick:()=>w(t),"data-testid":`automations-tab-${t}`,className:s(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors`,y===t?`bg-white text-gray-900 shadow-sm dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`automations.tab.${t}`)},t))})]}),(0,z.jsxs)(E,{size:`sm`,onClick:re,"data-testid":`automation-new`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,z.jsx)(d,{className:`h-3.5 w-3.5`}),e(`automations.newAutomation`)]})]}),(0,z.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-4 scrollbar-thin`,children:[y===`automations`?P?null:D.length===0?(0,z.jsxs)(`div`,{className:`px-3 py-16 text-center`,children:[(0,z.jsx)(C,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,z.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:e(`automations.empty`)})]}):(0,z.jsx)(`div`,{className:`mx-auto w-full max-w-3xl space-y-2`,children:D.map(n=>(0,z.jsx)(`div`,{"data-testid":`automation-row`,className:`rounded-2xl border border-black/[0.06] bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`p`,{className:`truncate text-[14px] font-medium text-gray-900 dark:text-dark-900`,children:n.name}),(0,z.jsx)(`span`,{className:s(`rounded-full px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,n.status===`active`?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`:`bg-gray-500/10 text-gray-500 dark:text-dark-500`),children:e(`automations.status.${n.status}`)})]}),(0,z.jsxs)(`p`,{className:`mt-0.5 truncate text-[12px] text-gray-500 dark:text-dark-500`,children:[L(n.triggers,t.language,e),n.nextRunAt&&(0,z.jsxs)(z.Fragment,{children:[` · `,e(`automations.nextRun`,{when:new Intl.DateTimeFormat(t.language,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(n.nextRunAt)})]})]})]}),(0,z.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,z.jsx)(`button`,{onClick:()=>q(e=>e===n.id?null:n.id),"aria-label":e(`automations.actions`),"data-testid":`automation-menu`,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-black/[0.04] hover:text-gray-700 dark:hover:bg-white/[0.06] dark:hover:text-dark-800`,children:(0,z.jsx)(m,{className:`h-4 w-4`})}),K===n.id&&(0,z.jsxs)(`div`,{className:`absolute end-0 top-8 z-20 w-44 rounded-xl border border-black/[0.07] bg-white p-1 shadow-lg dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,z.jsx)(Z,{icon:x,label:e(`common.edit`),onClick:()=>ae(n)}),n.status===`active`?(0,z.jsx)(Z,{icon:p,label:e(`automations.pause`),onClick:()=>$(n,`pause`)}):(0,z.jsx)(Z,{icon:f,label:e(`automations.resume`),onClick:()=>$(n,`resume`)}),(0,z.jsx)(Z,{icon:l,label:e(`automations.runNow`),onClick:()=>$(n,`run`)}),(0,z.jsx)(Z,{icon:g,label:e(`common.delete`),destructive:!0,onClick:()=>$(n,`delete`)})]})]})]})},n.id))}):null,y===`automations`&&!P&&(0,z.jsxs)(`div`,{className:`mx-auto mt-8 w-full max-w-3xl`,children:[(0,z.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e(`automations.templatesTitle`)}),(0,z.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:ne.map(n=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>ie(n),"data-testid":`automation-template`,className:`rounded-2xl border border-black/[0.06] bg-white/40 px-4 py-3 text-start transition-colors hover:bg-white/80 dark:border-white/[0.07] dark:bg-dark-100/40 dark:hover:bg-dark-100/80`,children:[(0,z.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:e(`automations.templates.${n.id}.name`)}),(0,z.jsx)(`p`,{className:`mt-0.5 text-[12px] text-gray-500 dark:text-dark-500`,children:e(`automations.templates.${n.id}.description`)}),(0,z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-gray-400 dark:text-dark-500`,children:L(n.triggers,t.language,e)})]},n.id))})]}),y===`runs`&&(0,z.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl space-y-4`,children:[M&&(0,z.jsx)(te,{days:M.days,locale:t.language}),k.length===0?(0,z.jsxs)(`div`,{className:`px-3 py-12 text-center`,children:[(0,z.jsx)(S,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,z.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:e(`automations.noRuns`)})]}):(0,z.jsx)(`div`,{className:`space-y-1`,"data-testid":`automation-run-list`,children:k.map(r=>(0,z.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-black/[0.05] bg-white/50 px-3 py-2 dark:border-white/[0.06] dark:bg-dark-100/50`,children:[se(r),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`truncate text-[13px] text-gray-900 dark:text-dark-900`,children:ce(r.automationId)}),(0,z.jsxs)(`p`,{className:`truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[o(r.scheduledFor,t.language),r.error&&(0,z.jsxs)(z.Fragment,{children:[` · `,(0,z.jsx)(`span`,{className:`text-red-500`,children:r.error})]})]})]}),r.sessionId&&(0,z.jsx)(`button`,{onClick:()=>n(`/c/${r.sessionId}`),"data-testid":`automation-run-open`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openChat`)})]},r.id))})]})]}),(0,z.jsx)(ee,{open:I,automation:B,initial:H,models:r,saving:W,onClose:()=>R(!1),onSave:e=>void oe(e)})]})};function Z({icon:e,label:t,destructive:n,onClick:r}){return(0,z.jsxs)(`button`,{onClick:r,className:s(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-start text-[13px] transition-colors`,n?`text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`:`text-gray-700 hover:bg-black/[0.04] dark:text-dark-700 dark:hover:bg-white/[0.06]`),children:[(0,z.jsx)(e,{className:`h-3.5 w-3.5`}),t]})}export{X as default};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{d as i}from"./router-vendor-DGFGM3EP.js";import{t as a}from"./useTranslation-Bho4HCyg.js";import{t as o}from"./utils-D9W1Lnkn.js";import{Rn as s,U as c,g as l,hn as u,mn as d,n as f}from"./ui-vendor-B1UgO3vd.js";import{t as p}from"./logger-DSXjF4ye.js";import{S as m,x as h}from"./api-BDtqBtqw.js";import{t as g}from"./Button-BPf_pOxH.js";import"./ui-CC-K19wO.js";import{a as _,c as v,d as y,i as b,l as x,n as S,o as C,r as w,s as T,t as E,u as D}from"./calendarDates-Co3o_05Y.js";var O=e(t(),1),k=n(),A={event:`bg-primary-500/15 text-primary-700 hover:bg-primary-500/25 dark:text-primary-300`,automation:`bg-amber-500/15 text-amber-700 hover:bg-amber-500/25 dark:text-amber-300`,runSucceeded:`bg-emerald-500/15 text-emerald-700 hover:bg-emerald-500/25 dark:text-emerald-300`,runFailed:`bg-red-500/15 text-red-700 hover:bg-red-500/25 dark:text-red-300`};function j({event:e,label:t,onClick:n}){return(0,k.jsx)(`button`,{type:`button`,"data-testid":`calendar-event-chip`,"data-variant":e.variant??`event`,title:e.title,onClick:e=>{e.stopPropagation(),n()},className:o(`w-full truncate rounded-md px-1.5 py-0.5 text-start text-[11px] leading-4 transition-colors`,A[e.variant??`event`],e.baseEventId&&`opacity-75`),children:t})}var M=3;function N({year:e,monthIndex:t,events:n,onDayClick:r,onEventClick:i}){let{t:s,i18n:c}=a(),l=(0,O.useMemo)(()=>w(e,t),[e,t]),u=new Date,d=(0,O.useMemo)(()=>{let e=new Map;for(let t of n){let n=new Date(t.startAt),r=`${n.getFullYear()}-${n.getMonth()}-${n.getDate()}`,i=e.get(r);i?i.push(t):e.set(r,[t])}return e},[n]),f=(0,O.useMemo)(()=>y(c.language),[c.language]);return(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-testid":`calendar-month-grid`,children:[(0,k.jsx)(`div`,{className:`grid grid-cols-7 border-b border-black/[0.06] dark:border-white/[0.07]`,children:f.map(e=>(0,k.jsx)(`div`,{className:`px-2 py-1.5 text-center text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e},e))}),(0,k.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-7 grid-rows-6`,children:l.map(e=>{let n=e.getMonth()===t,a=b(e,u),l=`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`,f=d.get(l)??[],p=f.length-M;return(0,k.jsxs)(`div`,{role:`gridcell`,"data-testid":`calendar-day-cell`,onClick:()=>r(e),className:o(`flex min-h-0 cursor-pointer flex-col gap-0.5 border-b border-e border-black/[0.04] p-1 transition-colors hover:bg-black/[0.02] dark:border-white/[0.04] dark:hover:bg-white/[0.03]`,!n&&`opacity-40`),children:[(0,k.jsx)(`span`,{className:o(`flex h-6 w-6 items-center justify-center rounded-full text-[12px]`,a?`bg-primary-500 font-semibold text-white`:`text-gray-600 dark:text-dark-600`),children:e.getDate()}),(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-0.5 overflow-hidden`,children:[f.slice(0,M).map(e=>(0,k.jsx)(j,{event:e,label:e.allDay?e.title:`${T(e.startAt,c.language)} ${e.title}`,onClick:()=>i(e)},e.id)),p>0&&(0,k.jsx)(`span`,{className:`px-1 text-[10px] text-gray-400 dark:text-dark-500`,children:s(`calendar.more`,{n:p})})]})]},l)})})]})}var P=48;function F({anchor:e,events:t,onDayClick:n,onEventClick:r}){let{i18n:i}=a(),s=(0,O.useMemo)(()=>D(e),[e]),c=new Date,l=(0,O.useMemo)(()=>new Intl.DateTimeFormat(i.language,{hour:`numeric`}),[i.language]),u=(0,O.useMemo)(()=>new Intl.DateTimeFormat(i.language,{weekday:`short`,day:`numeric`}),[i.language]),d=e=>t.filter(t=>t.allDay&&b(new Date(t.startAt),e)),f=e=>t.filter(t=>!t.allDay&&b(new Date(t.startAt),e));return(0,k.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto scrollbar-thin`,"data-testid":`calendar-week-grid`,children:(0,k.jsxs)(`div`,{className:`grid grid-cols-[3.5rem_repeat(7,1fr)]`,children:[(0,k.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-black/[0.06] bg-surface dark:border-white/[0.07]`}),s.map(e=>(0,k.jsxs)(`div`,{className:`sticky top-0 z-10 border-b border-e border-black/[0.06] bg-surface px-1 py-1.5 dark:border-white/[0.07]`,children:[(0,k.jsx)(`span`,{className:o(`block truncate text-center text-[11px] font-medium`,b(e,c)?`text-primary-600 dark:text-primary-400`:`text-gray-500 dark:text-dark-500`),children:u.format(e)}),(0,k.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:d(e).map(e=>(0,k.jsx)(j,{event:e,label:e.title,onClick:()=>r(e)},e.id))})]},e.toISOString())),Array.from({length:24},(e,t)=>(0,k.jsxs)(O.Fragment,{children:[(0,k.jsx)(`div`,{className:`relative border-b border-black/[0.04] pe-1.5 text-end text-[10px] text-gray-400 dark:border-white/[0.04] dark:text-dark-500`,children:(0,k.jsx)(`span`,{className:`relative -top-1.5`,children:t>0?l.format(new Date(2024,0,1,t)):``})}),s.map(e=>{let a=f(e).filter(e=>new Date(e.startAt).getHours()===t);return(0,k.jsx)(`div`,{onClick:()=>n(e,t),style:{height:P},className:`cursor-pointer space-y-0.5 overflow-hidden border-b border-e border-black/[0.04] p-0.5 transition-colors hover:bg-black/[0.02] dark:border-white/[0.04] dark:hover:bg-white/[0.03]`,children:a.map(e=>(0,k.jsx)(j,{event:e,label:`${T(e.startAt,i.language)} ${e.title}`,onClick:()=>r(e)},e.id))},`${e.toISOString()}-${t}`)})]},t))]})})}var I=r(),L=e=>!e||e.kind===`once`||e.kind===`hourly`?`none`:e.kind,R=(e,t)=>{let n=new Date(t),r=n.getHours(),i=n.getMinutes();switch(e){case`daily`:return{kind:`daily`,hour:r,minute:i};case`weekly`:return{kind:`weekly`,dayOfWeek:n.getDay(),hour:r,minute:i};case`monthly`:return{kind:`monthly`,dayOfMonth:n.getDate(),hour:r,minute:i};case`yearly`:return{kind:`yearly`,month:n.getMonth()+1,dayOfMonth:n.getDate(),hour:r,minute:i};default:return null}},z=`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,B=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`;function V({open:e,event:t,initialStartAt:n,saving:r,onClose:i,onSave:a,onDelete:o}){return e?(0,k.jsx)(H,{event:t,initialStartAt:n,saving:r,onClose:i,onSave:a,onDelete:o},`${t?.id??`new`}:${n}`):null}function H({event:e,initialStartAt:t,saving:n,onClose:r,onSave:i,onDelete:o}){let{t:s}=a(),c=e?.startAt??t,[u,d]=(0,O.useState)(e?.title??``),[p,m]=(0,O.useState)(e?.notes??``),[h,g]=(0,O.useState)(v(c)),[_,y]=(0,O.useState)(e?x(c):`09:00`),[b,C]=(0,O.useState)(e?.endAt===void 0?``:x(e.endAt)),[w,T]=(0,O.useState)(e?.allDay??!1),[E,D]=(0,O.useState)(L(e?.recurrence)),A=()=>{if(!u.trim()||!h)return;let e=S(h,w?``:_),t=!w&&b?S(h,b):null;i({title:u.trim(),notes:p.trim()?p.trim():void 0,startAt:e,endAt:t!==null&&t>e?t:null,allDay:w,recurrence:R(E,e)})},j=[{value:`none`,label:s(`calendar.repeatNone`)},{value:`daily`,label:s(`calendar.repeatDaily`)},{value:`weekly`,label:s(`calendar.repeatWeekly`)},{value:`monthly`,label:s(`calendar.repeatMonthly`)},{value:`yearly`,label:s(`calendar.repeatYearly`)}];return(0,I.createPortal)((0,k.jsx)(`div`,{className:`fixed inset-0 z-[2147483647] flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:r,children:(0,k.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`calendar-event-modal-title`,"data-testid":`calendar-event-modal`,className:`w-full max-w-md rounded-3xl border border-black/[0.07] bg-white p-6 shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/[0.08] dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,k.jsx)(`h3`,{id:`calendar-event-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:s(e?`calendar.editEvent`:`calendar.newEvent`)}),(0,k.jsx)(`button`,{onClick:r,"aria-label":s(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,k.jsx)(f,{size:20,className:`text-gray-500`})})]}),(0,k.jsxs)(`div`,{className:`space-y-3`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{htmlFor:`calendar-event-title`,className:B,children:s(`calendar.eventTitle`)}),(0,k.jsx)(`input`,{id:`calendar-event-title`,"data-testid":`calendar-event-title`,type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:s(`calendar.titlePlaceholder`),className:z,maxLength:200,autoFocus:!0})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{htmlFor:`calendar-event-date`,className:B,children:s(`calendar.date`)}),(0,k.jsx)(`input`,{id:`calendar-event-date`,type:`date`,value:h,onChange:e=>g(e.target.value),className:z})]}),(0,k.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,k.jsxs)(`label`,{className:`flex items-center gap-2 text-[13px] text-gray-700 dark:text-dark-700`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`h-4 w-4 rounded accent-primary-500`}),s(`calendar.allDay`)]})})]}),!w&&(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{htmlFor:`calendar-event-start`,className:B,children:s(`calendar.start`)}),(0,k.jsx)(`input`,{id:`calendar-event-start`,type:`time`,value:_,onChange:e=>y(e.target.value),className:z})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{htmlFor:`calendar-event-end`,className:B,children:s(`calendar.end`)}),(0,k.jsx)(`input`,{id:`calendar-event-end`,type:`time`,value:b,onChange:e=>C(e.target.value),className:z})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{htmlFor:`calendar-event-repeat`,className:B,children:s(`calendar.repeat`)}),(0,k.jsx)(`select`,{id:`calendar-event-repeat`,value:E,onChange:e=>D(e.target.value),className:z,children:j.map(e=>(0,k.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{htmlFor:`calendar-event-notes`,className:B,children:s(`calendar.notes`)}),(0,k.jsx)(`textarea`,{id:`calendar-event-notes`,value:p,onChange:e=>m(e.target.value),rows:3,className:z,maxLength:1e4})]}),(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[e&&o?(0,k.jsxs)(`button`,{onClick:o,"data-testid":`calendar-event-delete`,className:`flex items-center gap-1.5 rounded-xl px-3 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`,children:[(0,k.jsx)(l,{className:`h-4 w-4`}),s(`common.delete`)]}):(0,k.jsx)(`span`,{}),(0,k.jsxs)(`div`,{className:`flex gap-3`,children:[(0,k.jsx)(`button`,{onClick:r,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:s(`common.cancel`)}),(0,k.jsx)(`button`,{onClick:A,disabled:n||!u.trim(),"data-testid":`calendar-event-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:s(n?`common.saving`:`common.save`)})]})]})]})]})}),document.body)}var U=p(`pages:calendar`),W=()=>{let{t:e,i18n:t}=a(),n=i(),[r,l]=(0,O.useState)(`month`),[f,p]=(0,O.useState)(()=>new Date),[v,y]=(0,O.useState)([]),[b,x]=(0,O.useState)([]),[S,w]=(0,O.useState)(!1),[T,D]=(0,O.useState)(null),[A,j]=(0,O.useState)(()=>Date.now()),[M,P]=(0,O.useState)(!1),I=(0,O.useMemo)(()=>{if(r===`month`){let e=new Date(f.getFullYear(),f.getMonth(),1),t=C(e);return{from:t.getTime(),to:E(t,42).getTime()}}let e=C(f);return{from:e.getTime(),to:E(e,7).getTime()}},[f,r]),[L,R]=(0,O.useState)(0),z=(0,O.useCallback)(()=>R(e=>e+1),[]);(0,O.useEffect)(()=>{let t=!1;return m.getEvents(I.from,I.to).then(e=>{t||e.success&&e.data&&y(e.data)}).catch(n=>{t||(U.error(`Failed to load calendar events:`,n),s.error(e(`calendar.loadFailed`)))}),Promise.all([h.getOccurrences(I.from,I.to),h.getRuns({from:I.from,to:I.to}),h.getAutomations()]).then(([n,r,i])=>{if(t)return;let a=Date.now(),o=t=>i.data?.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`),s=[];for(let e of n.data??[])e.at<=a||s.push({id:`automation:${e.automationId}:${e.at}`,title:e.name,startAt:e.at,allDay:!1,createdAt:e.at,updatedAt:e.at,variant:`automation`});for(let e of r.data??[])(e.status===`succeeded`||e.status===`failed`)&&s.push({id:`run:${e.id}`,title:o(e.automationId),startAt:e.scheduledFor,allDay:!1,createdAt:e.createdAt,updatedAt:e.createdAt,variant:e.status===`succeeded`?`runSucceeded`:`runFailed`,...e.sessionId?{sessionId:e.sessionId}:{}});x(s)}).catch(e=>{t||U.error(`Failed to project automations onto the calendar:`,e)}),()=>{t=!0}},[I.from,I.to,L,e]);let B=(0,O.useMemo)(()=>[...v,...b].sort((e,t)=>e.startAt-t.startAt),[v,b]),H=e=>{p(t=>r===`month`?new Date(t.getFullYear(),t.getMonth()+e,1):E(t,e*7))},W=(e,t=9)=>{D(null),j(new Date(e.getFullYear(),e.getMonth(),e.getDate(),t,0).getTime()),w(!0)},G=e=>{if(e.variant===`runSucceeded`||e.variant===`runFailed`){e.sessionId?n(`/c/${e.sessionId}`):n(`/automations`);return}if(e.variant===`automation`){n(`/automations`);return}if(e.baseEventId){let t=v.find(t=>t.id===e.baseEventId);D(t??e)}else D(e);w(!0)},K=async t=>{P(!0);try{let n=T?await m.updateEvent(T.id,t):await m.createEvent(t);n.success?(w(!1),z()):s.error(n.error||e(`calendar.saveFailed`))}catch(t){U.error(`Failed to save calendar event:`,t),s.error(e(`calendar.saveFailed`))}finally{P(!1)}},q=async()=>{if(T){P(!0);try{let t=await m.deleteEvent(T.id);t.success?(w(!1),z()):s.error(t.error||e(`calendar.deleteFailed`))}catch(t){U.error(`Failed to delete calendar event:`,t),s.error(e(`calendar.deleteFailed`))}finally{P(!1)}}},J=r===`month`?_(f.getFullYear(),f.getMonth(),t.language):new Intl.DateTimeFormat(t.language,{month:`long`,day:`numeric`,year:`numeric`}).format(C(f));return(0,k.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`calendar-page`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-black/[0.06] px-4 py-3 dark:border-white/[0.07]`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`calendar.title`)}),(0,k.jsx)(`span`,{className:`text-sm text-gray-500 dark:text-dark-500`,"data-testid":`calendar-range-label`,children:J})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/[0.04] p-0.5 dark:bg-white/[0.06]`,children:[`month`,`week`].map(t=>(0,k.jsx)(`button`,{onClick:()=>l(t),"data-testid":`calendar-view-${t}`,className:o(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors`,r===t?`bg-white text-gray-900 shadow-sm dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`calendar.${t}`)},t))}),(0,k.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,k.jsx)(g,{size:`sm`,variant:`ghost`,onClick:()=>H(-1),className:`h-7 w-7 p-0`,title:e(`calendar.previous`),children:(0,k.jsx)(u,{className:`h-4 w-4`})}),(0,k.jsx)(g,{size:`sm`,variant:`ghost`,onClick:()=>p(new Date),className:`h-7 px-2 text-[12px]`,children:e(`calendar.today`)}),(0,k.jsx)(g,{size:`sm`,variant:`ghost`,onClick:()=>H(1),className:`h-7 w-7 p-0`,title:e(`calendar.next`),children:(0,k.jsx)(d,{className:`h-4 w-4`})})]}),(0,k.jsxs)(g,{size:`sm`,onClick:()=>W(f),"data-testid":`calendar-new-event`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,k.jsx)(c,{className:`h-3.5 w-3.5`}),e(`calendar.newEvent`)]})]})]}),r===`month`?(0,k.jsx)(N,{year:f.getFullYear(),monthIndex:f.getMonth(),events:B,onDayClick:e=>W(e),onEventClick:G}):(0,k.jsx)(F,{anchor:f,events:B,onDayClick:(e,t)=>W(e,t),onEventClick:G}),(0,k.jsx)(V,{open:S,event:T,initialStartAt:A,saving:M,onClose:()=>w(!1),onSave:e=>void K(e),onDelete:()=>void q()})]})};export{W as default};
@@ -0,0 +1,16 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{d as i,f as a,u as o}from"./router-vendor-DGFGM3EP.js";import{t as s}from"./useTranslation-Bho4HCyg.js";import{i as c,n as l,o as u,r as d,t as f}from"./utils-D9W1Lnkn.js";import{C as p,a as m,c as h,d as g,h as _,i as v,l as y,m as b,n as x,o as S,r as C,t as w,u as T}from"./chatStore-CHQ2uINS.js";import{$t as E,C as D,Cn as O,D as k,F as A,Ht as j,J as ee,L as te,Ln as M,M as N,Mn as ne,Mt as P,Nt as re,On as ie,Ot as ae,P as oe,Rn as F,U as se,V as ce,Vt as le,X as ue,Zt as I,_ as L,_n as de,a as fe,b as R,bt as z,c as pe,ct as B,f as V,gn as me,k as he,kn as ge,mn as _e,mt as ve,n as H,nn as ye,o as U,ot as be,p as xe,pn as Se,r as W,st as Ce,t as G,tn as we,v as Te,wn as Ee,xt as De,z as Oe}from"./ui-vendor-B1UgO3vd.js";import{t as K}from"./logger-DSXjF4ye.js";import{E as ke,a as Ae,b as je,d as Me,f as Ne,h as Pe,n as Fe,o as Ie,p as Le,r as q,v as Re,w as ze}from"./api-BDtqBtqw.js";import{n as Be}from"./authStore-DbMdvNgJ.js";import{t as Ve}from"./appStore-0JnCUlEq.js";import{i as He,r as Ue,t as We}from"./welcomePrompts-to5mv_gx.js";import{l as Ge}from"./messageCodeStyles-BFNR9Wv6.js";import{t as J}from"./Button-BPf_pOxH.js";import{d as Ke,f as qe,l as Je}from"./ui-CC-K19wO.js";import{a as Ye,c as Xe,g as Y,h as Ze,l as Qe,m as $e,o as et,s as tt,u as nt,v as rt}from"../assets/index-6o-Hc2wS.js";import{c as it,s as at}from"./ArtifactSandboxFrame-qsj_Y3LV.js";import{i as ot,n as st,r as X,t as ct}from"./thinking-DwlkTfPX.js";import{t as lt}from"./ArtifactContainer-CpUi6ekF.js";import{t as ut}from"./ModelSelector-yxJC64rM.js";var dt=r(),Z=e(t(),1),Q=n(),ft=({statistics:e,className:t=``})=>{let[n,r]=(0,Z.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,Q.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,Q.jsx)(z,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,Q.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,Q.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,Q.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,Q.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,Q.jsx)(me,{size:12}):(0,Q.jsx)(_e,{size:12,className:`rtl:rotate-180`}),(0,Q.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,Q.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,Q.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,Q.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},pt=K(`components:ttsbutton`),mt=null,ht=null,gt=0,_t=3e5;async function vt(e=!1){let t=Date.now();return!e&&mt!==null&&t-gt<_t?mt:ht||(ht=(async()=>{try{let e=await Ie.getModels();return e.success&&e.data&&e.data.length>0?(mt=e.data,gt=t,e.data):(mt=[],gt=t,[])}catch{return mt=[],gt=t,[]}finally{ht=null}})(),ht)}var yt=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:c}=s(),{preferences:l}=Ve(),[u,d]=(0,Z.useState)(`idle`),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)([]),[_,v]=(0,Z.useState)(null),y=(0,Z.useRef)(null),b=(0,Z.useRef)(0);(0,Z.useEffect)(()=>{let e=!0;return(async()=>{let t=await vt(),n=q(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await vt(!0)),e&&(g(t),v(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let x=()=>{b.current+=1,y.current?.cancel(),y.current=null,d(`idle`)},S=async()=>{if(r===`blocked`||r===`error`){a?.();return}if(r===`loading`||r===`generating`||r===`buffering`||r===`playing`){i?.();return}if(u===`loading`||u===`generating`||u===`buffering`||u===`playing`){x();return}if(y.current){x();return}let t=nt();d(`loading`),m(null);let n=b.current+1;b.current=n;try{let r=await t;if(b.current!==n)return;if(r===`blocked`){d(`blocked`);return}let i=l.ttsSettings,a=Ae(h,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,u=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),p=f&&i?.voice||a?.config?.default_voice,m=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,v=Math.max(1,a?.config?.max_characters||600),x=Math.min(v,600),S=i?.streamSentences!==!1||e.length>x?et(e,{locale:c.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=tt({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>Ie.generate({model:s,pluginId:u,input:e,voice:m?void 0:p||void 0,voiceProfileId:m,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});y.current=C;let w=Ye(C);try{await C.play(S)}finally{w(),y.current===C&&(y.current=null)}}catch(e){if(b.current!==n)return;if(Xe(e)){d(`idle`);return}if(Qe(e)){d(`blocked`);return}let t=e instanceof Error?e.message:o(`ttsButton.generateFailed`);m(t),pt.error(`TTS error:`,e),d(`error`)}};if((0,Z.useEffect)(()=>()=>{b.current+=1,y.current?.cancel(),y.current=null},[]),_===!1||_===null)return null;let C={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},w={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`},T=r&&![`idle`,`ended`,`cancelled`].includes(r)?r:u,E=T===`loading`||T===`generating`||T===`buffering`,O=T===`playing`,k=T===`blocked`,A=!!p||T===`error`,j=p||o(A?`ttsButton.playbackFailed`:k?`ttsButton.enableAudio`:O||E?O?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,Q.jsxs)(`button`,{onClick:S,disabled:!e,title:j,"aria-label":j,"aria-busy":E||void 0,className:f(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,A?`text-red-500 dark:text-red-400`:k?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:O?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!k&&C[n],k&&n===`sm`&&`h-7`,k&&n===`md`&&`h-8`,k&&n===`lg`&&`h-10`,t),children:[E?(0,Q.jsx)(ve,{className:f(w[n],`animate-spin`)}):O?(0,Q.jsx)(D,{className:w[n]}):A||k?(0,Q.jsx)(fe,{className:w[n]}):(0,Q.jsx)(U,{className:w[n]}),k&&(0,Q.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},bt=/```([^\n`]*)\n([\s\S]*?)\n```/g,$=/^(?:%%|flowchart|graph|sequenceDiagram|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|mindmap|timeline|gitGraph|quadrantChart|requirementDiagram|sankey-beta|xychart-beta|block-beta|architecture-beta|packet-beta|kanban|radar-beta|treemap-beta|C4Context)\b/i,xt=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,St=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],Ct=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:Mt(e[1]),title:wt(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=Mt(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function wt(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return Et(Tt(e))}function Tt(e){return e.replace(/&(lt|gt|quot|apos|#39);/gi,(e,t)=>{switch(t.toLowerCase()){case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:case`#39`:return`'`;default:return``}}).replace(/&amp;/gi,`&`)}function Et(e){let t=``,n=!1,r=null;for(let i=0;i<e.length;i+=1){let a=e[i];if(n){if(r){a===r&&(r=null);continue}if(a===`"`||a===`'`){r=a;continue}a===`>`&&(n=!1);continue}if(a===`<`){let t=e[i+1];if(t&&/[!/A-Za-z?]/.test(t)){n=!0;continue}}t+=a}return t}function Dt(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return wt(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&wt(n[1]).trim()||null}function Ot(e){for(let t of[/export\s+default\s+(?:function|class)\s+([A-Z]\w*)/,/export\s+default\s+([A-Z]\w*)\s*(?:;|$)/m,/(?:function|class)\s+([A-Z]\w*)/,/const\s+([A-Z]\w*)\s*[:=]/,/(?:function|const|class)\s+(\w+)/]){let n=e.match(t);if(n)return n[1]}return null}function kt(e){let t=e.match(/^\s*title\s+(.+)$/im);if(t)return t[1].trim();let n=e.trim().match(/^([A-Za-z][\w-]*)/);if(!n)return null;let r=n[1].replace(/-(?:beta|v2)$/i,``).replace(/([a-z])([A-Z])/g,`$1 $2`);return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function At(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function jt(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function Mt(e){let t=e.trim().toLowerCase();return St.includes(t)?t:`text`}function Nt(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function Pt(e){let t=[],n=new RegExp(bt),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=Ft(n,Lt(e,r.index));t.push({raw:r[0],info:n,content:r[2].trim(),start:r.index,end:r.index+r[0].length,language:i.language,fileName:i.fileName})}return t}function Ft(e,t){let n=It(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!xt.test(r)&&!r.includes(`=`)?Nt(r):void 0)||Nt(zt(n)),fileName:n}}function It(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&xt.test(t[1]))return Rt(t[1]);let n=e.match(xt);return n?Rt(n[0]):void 0}function Lt(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
2
+ `).slice(-3).reverse();for(let e of n){let t=e.trim().replace(/^#{1,6}\s*/,``).replace(/^[-*]\s*/,``).replace(/[::]\s*$/,``).match(xt);if(t)return Rt(t[0])}}function Rt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function zt(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function Bt(e){return e?.split(/[\\/]/).pop()}function Vt(e){let t=Bt(e);if(!t)return null;let n=t.replace(/\.[^.]+$/,``);return/^(index|main|app)$/i.test(n)?null:n.replace(/[-_]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Ht(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function Ut(e){let t=Nt(e.language)||Nt(zt(e.fileName));switch(t){case`html`:return{type:`html`,title:Dt(e.content)||Vt(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:Vt(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:Ot(e.content)||Vt(e.fileName)||`React Component`,language:`jsx`};case`mermaid`:return{type:`mermaid`,title:kt(e.content)||`Diagram`,language:`mermaid`};case`json`:return{type:`json`,title:Vt(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:At(e.content)||Vt(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:Vt(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:jt(e.content)||Vt(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:Vt(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:Vt(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function Wt(e){return(Nt(e.language)||Nt(zt(e.fileName)))===`html`}function Gt(e){return(Nt(e.language)||Nt(zt(e.fileName)))===`css`}function Kt(e){return(Nt(e.language)||Nt(zt(e.fileName)))===`javascript`}function qt(e){let t=Pt(e),n=t.filter(Wt);if(n.length===0)return null;let r=t.filter(Gt),i=t.filter(Kt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=Jt(a.content,r,i),s=it(o,r.map(e=>e.content),i.map(e=>e.content));return $t(s,`html`)?{artifact:Ht({type:`html`,title:Dt(s)||Vt(a.fileName)||`Interactive HTML App`,description:`Bundled generated HTML, CSS, and JavaScript files into one runnable artifact.`,content:s}),ranges:[a,...r,...i]}:null}function Jt(e,t,n){let r=e;for(let e of t){let t=Bt(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${Qt(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=Bt(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${Qt(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function Yt(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=Pt(e);if(Xt(t.index,n))return null;let r=t.index,i=/<\/html>/gi;i.lastIndex=r;let a=i.exec(e),o=a?a.index+a[0].length:e.length,s=e.slice(r,o).trim();return $t(s,`html`)?{artifact:Ht({type:`html`,title:Dt(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function Xt(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function Zt(e,t){return[...t].sort((e,t)=>t.start-e.start).reduce((e,t)=>`${e.slice(0,t.start)}${e.slice(t.end)}`,e)}function Qt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function $t(e,t){if(t===`html`){let t=e.trim(),n=/<[^>]+>/.test(t),r=/<(canvas|script|style|button|form|input|select|textarea|video|audio)\b/i.test(t)||/\bon(?:click|input|submit|keydown|keyup|mousemove)=/i.test(t);return n&&(at(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Za-z][^>]*>/.test(e)&&/\b(?:export\s+default|return\s*[(<]|=>\s*[(<]|createRoot|render\s*\()/.test(e);if(t===`mermaid`)return $.test(e.trim());if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
3
+ `).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return e.trim().length>200}function en(e){let t=[],n=e;for(let e of Ct){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);$t(n.content,n.type)&&(t.push(Ht({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=Zt(n,r)}let r=qt(n);for(;r;)t.push(r.artifact),n=Zt(n,r.ranges),r=qt(n);let i=Yt(n);i&&(t.push(i.artifact),n=Zt(n,i.ranges));let a=Pt(n),o=[];for(let e of a){let n=Ut(e);!n||!$t(e.content,n.type)||(t.push(Ht({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=Zt(n,o),{content:n.trim(),artifacts:t}}var tn=K(`components:chat-message`);function nn({role:e,user:t,personaAvatar:n,modelAvatar:r}){let[i,a]=(0,Z.useState)(null);if(e===`assistant`){let e=(n?.trim()||r?.trim())??``,t=e.startsWith(`data:`)&&e!==i?e:``;return(0,Q.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-sm dark:border-white/[0.09] dark:bg-dark-200 dark:text-dark-950`,children:t?(0,Q.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>a(e)}):e?(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,Q.jsx)(rt,{label:null,className:`h-4 w-4`})})}let o=t?.username||`User`,s=t?.avatar?.trim()||``,c=!!s&&s!==i;return(0,Q.jsx)(`div`,{role:c?void 0:`img`,"aria-label":c?void 0:o,"data-testid":`chat-user-avatar`,className:f(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,c?`border border-black/[0.07] bg-white dark:border-white/[0.09] dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:o,children:c?(0,Q.jsx)(`img`,{src:s,alt:o,className:`h-full w-full object-cover`,onError:()=>a(s)}):t?.username?(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,Q.jsx)(pe,{"aria-hidden":`true`,className:`h-4 w-4`})})}var rn=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onEditResend:a})=>{let{t:o,i18n:c}=s(),l=e.role===`user`,p=e.role===`system`,h=p&&m(e.content),g=h?e.content.slice(x.length):e.content,{preferences:_}=Ve(),{user:v}=Be(),{setSystemMessage:y,getCurrentPersona:b,currentSession:S,rateMessage:C,modelMetadata:T}=w(),D=b(),k=e.model||S?.model||``,A=k?T[k]??Object.entries(T).find(([e])=>e.slice(e.indexOf(`/`)+1)===k)?.[1]:void 0,[j,M]=(0,Z.useState)(!1),[ne,P]=(0,Z.useState)(e.content),[re,ie]=(0,Z.useState)(null),[ae,oe]=(0,Z.useState)(!1),[se,le]=(0,Z.useState)(!1),[ue,I]=(0,Z.useState)(!1),[fe,R]=(0,Z.useState)(`idle`),[z,pe]=(0,Z.useState)(!1),B=(0,Z.useRef)(null),V=(0,Z.useRef)(0),he=(0,Z.useRef)(t),ge=(0,Z.useRef)(!1),_e=async()=>{try{await navigator.clipboard.writeText(e.content),Ge(`success`),pe(!0),setTimeout(()=>pe(!1),2e3)}catch(e){tn.error(`Failed to copy message:`,e)}},{thinkingContent:ve,thinkingStreaming:ye,parsedContent:U,artifacts:be}=(0,Z.useMemo)(()=>{if(l||p||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:u(e.content),r=n.content,i=t&&!n.thinkingComplete;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:e.artifacts};if(!t){let e=en(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,l,p,t]),W=ye?void 0:e.statistics?.thinking_duration_ms??Y(e.id),Ce=(0,Z.useCallback)(async e=>{let t=V.current+1;V.current=t,B.current?.cancel(),B.current=null,R(`loading`);try{if(e){let n=await e;if(V.current!==t)return;if(n===`blocked`){R(`blocked`);return}}let n=await Ie.getModels();if(V.current!==t)return;let r=n.success&&n.data?n.data:[],i=_.ttsSettings,a=Ae(r,i?.model,i?.pluginId),o=q(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,l=a?.plugin||i?.pluginId,u=o&&i?.voice||a?.config?.default_voice,d=o&&i?.voiceProfileId||void 0,f=Math.max(1,a?.config?.max_characters||600),p=Math.min(f,600),m=i?.streamSentences!==!1||U.length>p?et(U,{locale:c.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[U.trim()];if(m.length===0){R(`idle`);return}let h=tt({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>Ie.generate({model:s,pluginId:l,input:e,voice:d?void 0:u||void 0,voiceProfileId:d,speed:i?.speed||1,response_format:a?.config?.default_format},{signal:t}),onStateChange:e=>{V.current===t&&R(e)}});if(V.current!==t){h.cancel();return}B.current=h;let g=Ye(h);try{await h.play(m)}finally{g(),B.current===h&&(B.current=null),V.current===t&&(h.state===`ended`||h.state===`cancelled`)&&R(`idle`)}}catch(e){if(V.current!==t)return;Xe(e)?R(`idle`):Qe(e)?R(`blocked`):(tn.error(`Auto-play TTS failed:`,e),R(`error`))}},[c.language,U,_.ttsSettings]);(0,Z.useEffect)(()=>{let e=he.current&&!t;he.current=t,e&&!ge.current&&!l&&!p&&U&&_.ttsSettings?.enabled&&_.ttsSettings.autoPlay&&(ge.current=!0,Ce())},[t,l,p,U,_.ttsSettings?.autoPlay,_.ttsSettings?.enabled,Ce]),(0,Z.useEffect)(()=>()=>{V.current+=1,B.current?.cancel(),B.current=null},[]);let G=()=>{let e=nt();Ce(e)},we=()=>{V.current+=1,B.current?.cancel(),B.current=null,R(`idle`)},Ee=()=>h?o(`chatMessage.conversationSummary`):p?o(`chatMessage.system`):l?_.showUsername&&v?.username?v.username:o(`chatMessage.you`):D?.name?D.name:A?.label||k||o(`chatMessage.assistant`),De=()=>{M(!0),P(e.content)},[K,je]=(0,Z.useState)(!1),Me=async()=>{if(!(!S||K)){je(!0);try{let t=await ke.restoreCompaction(S.id,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;w.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){tn.error(`Failed to restore compacted messages:`,e),F.error(o(`chatMessage.restoreFailed`))}finally{je(!1)}}},Ne=async()=>{oe(!0);try{y(ne),M(!1),tn.debug(`✅ System message updated:`,ne)}catch(e){tn.error(`Failed to save system message:`,e)}finally{oe(!1)}},Pe=()=>{M(!1),P(e.content)},Fe=()=>{let t=ne.trim();M(!1),t&&a?.(e.id,t)},Le=t=>{S&&C(S.id,e.id,e.rating===t?void 0:t)},Re=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ze=p&&g.length>100;return(0,Q.jsxs)(`div`,{className:f(`group flex py-1.5 transition-colors sm:py-2`,l?`justify-end`:`justify-start`,n),children:[(0,Q.jsxs)(`div`,{className:f(`flex min-w-0 gap-2.5 sm:gap-3`,l?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!l&&!p&&(0,Q.jsx)(nn,{role:`assistant`,personaAvatar:D?.avatar,modelAvatar:A?.avatar}),(0,Q.jsxs)(`div`,{className:f(`min-w-0 flex-1`,l?`flex flex-col items-end`:p?`py-1.5`:`py-0.5`),children:[!l&&!p&&(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:Ee()}),e.model&&D?.name&&(0,Q.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,Q.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:d(e.timestamp,c.language)})]}),(0,Q.jsxs)(`div`,{className:f(!l&&!p&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,Q.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,Q.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/[0.06] bg-gray-100 dark:border-white/[0.08] dark:bg-gray-800`,children:(0,Q.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>ie(e)})},t))}),l?j?(0,Q.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/[0.08] bg-white p-2 shadow-sm dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,Q.jsx)(`textarea`,{dir:`auto`,value:ne,onChange:e=>P(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),Fe()):e.key===`Escape`&&Pe()},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-none dark:text-dark-900`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,Q.jsx)(`button`,{onClick:Pe,className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 transition-colors hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:o(`chatMessage.cancelEditing`)}),(0,Q.jsx)(`button`,{onClick:Fe,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white transition-colors hover:bg-gray-700 dark:bg-dark-300 dark:hover:bg-dark-400`,children:o(`chatMessage.saveAndSubmit`)})]})]}):(0,Q.jsx)(`div`,{className:`rounded-2xl rounded-ee-md border border-black/[0.06] bg-gray-900 px-3.5 py-2 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`,children:(0,Q.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):p?(0,Q.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[h?(0,Q.jsx)(Oe,{className:`h-2.5 w-2.5 opacity-50`}):(0,Q.jsx)(N,{className:`h-2.5 w-2.5 opacity-50`}),o(h?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:h?(0,Q.jsx)(`button`,{onClick:()=>void Me(),disabled:K,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.restoreCompacted`),children:(0,Q.jsx)(xe,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):j?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:Ne,disabled:ae,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.saveChanges`),children:(0,Q.jsx)(te,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,Q.jsx)(`button`,{onClick:Pe,disabled:ae,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.cancelEditing`),children:(0,Q.jsx)(H,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,Q.jsx)(`button`,{onClick:De,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:o(`chatMessage.editSystemMessage`),children:(0,Q.jsx)(ee,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),j?(0,Q.jsx)(`textarea`,{dir:`auto`,value:ne,onChange:e=>P(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:o(`chatMessage.systemMessagePlaceholder`),disabled:ae}):(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:se?g:Re(g)}),ze&&(0,Q.jsx)(`button`,{onClick:()=>le(!se),className:`mt-2 flex items-center gap-1 text-xs text-gray-400 transition-colors hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`,children:se?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Se,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(me,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,Q.jsxs)(`div`,{className:`relative`,children:[(ve||ye)&&(0,Q.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,Q.jsxs)(`button`,{onClick:()=>I(!ue),className:`flex items-center gap-1.5 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,Q.jsx)(O,{className:f(`h-3.5 w-3.5`,ye&&`animate-pulse-subtle motion-reduce:animate-none`)}),ye?(0,Q.jsxs)(`span`,{className:`animate-shimmer bg-gradient-to-r from-gray-400 via-gray-900 to-gray-400 bg-[length:200%_100%] bg-clip-text font-medium text-transparent motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-gray-500 dark:from-dark-500 dark:via-dark-900 dark:to-dark-500 motion-reduce:dark:text-dark-600`,children:[o(`chatMessage.thinking`),`…`]}):(0,Q.jsx)(`span`,{className:`font-medium`,children:W===void 0?o(`chatMessage.thinking`):o(`chatMessage.thoughtFor`,{duration:Ze(W)})}),ue?(0,Q.jsx)(Se,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(me,{className:`h-3.5 w-3.5`})]}),ue&&ve&&(0,Q.jsx)(`div`,{className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 dark:bg-dark-200/60`,children:(0,Q.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[13px] leading-relaxed text-gray-600 dark:text-dark-700`,children:ve})})]}),(0,Q.jsx)(Je,{content:U,isStreaming:t})]}),!l&&!p&&be.length>0&&(0,Q.jsx)(`div`,{className:`mt-3`,children:(0,Q.jsx)(lt,{artifacts:be})}),!l&&!p&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,Q.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:o(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,Q.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,Q.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,Q.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!l&&!p&&e.statistics&&(0,Q.jsx)(`div`,{className:`mt-2`,children:(0,Q.jsx)(ft,{statistics:e.statistics})}),!p&&!t&&(0,Q.jsxs)(`div`,{className:f(`flex items-center gap-0.5 text-gray-400 dark:text-dark-500`,`sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,!l&&[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(fe)?`sm:opacity-100`:`sm:opacity-0`,l?`mt-1 justify-end`:`mt-1`),children:[l&&(0,Q.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:d(e.timestamp,c.language),children:[Ee(),` ·`,` `,d(e.timestamp,c.language)]}),!l&&U&&(0,Q.jsx)(yt,{text:U,size:`sm`,externalPlaybackState:fe,onStopExternal:we,onRetryExternal:G,className:f(`transition-colors`,fe===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),l&&a&&!j&&(0,Q.jsx)(`button`,{onClick:()=>{P(e.content),M(!0)},className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.edit`),children:(0,Q.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:_e,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(z?`chatMessage.copied`:`chatMessage.copyMessage`),children:z?(0,Q.jsx)(de,{className:`h-3.5 w-3.5 text-green-500`}):(0,Q.jsx)(E,{className:`h-3.5 w-3.5`})}),!l&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:()=>Le(1),className:f(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===1&&`text-primary-600 dark:text-primary-400`),title:o(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,Q.jsx)(L,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,Q.jsx)(`button`,{onClick:()=>Le(-1),className:f(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===-1&&`text-red-500 dark:text-red-400`),title:o(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,Q.jsx)(Te,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})})]}),!l&&r&&i&&(0,Q.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.regenerateResponse`),children:(0,Q.jsx)(ce,{className:`h-3.5 w-3.5`})})]})]})]}),l&&(0,Q.jsx)(nn,{role:`user`,user:v??null})]}),re&&(0,dt.createPortal)((0,Q.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":o(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>ie(null),children:[(0,Q.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),ie(null)},children:(0,Q.jsx)(H,{className:`h-7 w-7`})}),(0,Q.jsx)(`img`,{src:re,alt:o(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},an=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,on=220,sn=e=>{let t=e.slice(0,880).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>on?`${t.slice(0,219).trimEnd()}…`:t},cn=Z.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Z.useRef)(null),a=(0,Z.useRef)(null),o=(0,Z.useRef)(new Map),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(0),p=(0,Z.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),m=(0,Z.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;!r||!i||(i.focus(),p(r.id,i),n(r.id))},[e,n,p]);if((0,Z.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:an()?`auto`:`smooth`})},[t]),e.length<3)return null;let h=Math.max(0,e.findIndex(e=>e.id===t)),g=e[h]?.id,_=e.findIndex(e=>e.id===c),v=_>=0?e[_]:null,y=_>=0?`conversation-history-preview-${_}`:void 0;return(0,Q.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,Q.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===g,u=Math.abs(a-h),d=c===t.id?y:void 0;return(0,Q.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,Q.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===h?0:-1,className:f(`group flex h-4 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>p(t.id,e.currentTarget),onFocus:e=>p(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),m(n))},children:(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:f(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),v&&(0,Q.jsx)(`div`,{id:y,role:`tooltip`,className:f(`pointer-events-none absolute start-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,Q.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,Q.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:sn(v.prompt)}),v.response&&(0,Q.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:sn(v.response)})]})})]})}),ln=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,Q.jsx)(rn,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,Q.jsxs)(`div`,{className:f(`relative py-2`,c),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,Q.jsx)(P,{className:`h-3 w-3`}),(0,Q.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let l=e.isActive!==!1,u=t&&i===e.id,d=u?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,Q.jsxs)(`div`,{className:f(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||u?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!u&&`cursor-pointer`),role:!l&&!u?`button`:void 0,tabIndex:!l&&!u?0:void 0,onClick:()=>!l&&!u&&s?.(e.id),onKeyDown:t=>{!l&&!u&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,Q.jsxs)(`div`,{className:f(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||u?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,Q.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,Q.jsx)(de,{className:`h-3 w-3`}),!l&&!u&&(0,Q.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,Q.jsx)(`div`,{className:f(!l&&!u&&`opacity-75`),children:(0,Q.jsx)(rn,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},un={web_search:A,web_fetch:ae,exec:R,browser:ae,Read:j,Write:j,Edit:j,image:De,memory_search:I,memory_get:I,working:W,thinking:W,default:W},dn={web_search:`Searching the web`,web_fetch:`Fetching page`,exec:`Running command`,browser:`Using browser`,Read:`Reading file`,Write:`Writing file`,Edit:`Editing file`,image:`Analyzing image`,memory_search:`Searching memory`,memory_get:`Reading memory`,cron:`Managing schedule`,message:`Sending message`,tts:`Generating speech`,nodes:`Checking devices`,sessions_spawn:`Spawning agent`,canvas:`Rendering canvas`,process:`Managing process`,working:`Using tools`,thinking:`Thinking`},fn=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,Q.jsx)(`div`,{className:f(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=un[e.name]||un.default,n=dn[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,Q.jsxs)(`div`,{className:f(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,Q.jsx)(`div`,{className:f(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,Q.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,Q.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,Q.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};K(`components:chat-messages`);var pn=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],mn=e=>e.messages.every(e=>e.isActive===!1),hn=e=>e.role===`system`&&!m(e.content),gn=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,_n=e=>Math.min(120,e*.28),vn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],className:o,onRegenerate:c,onSelectBranch:l,onEditResend:u,followUpSuggestions:d,onFollowUpSelect:p})=>{let{t:m}=s(),h=(0,Z.useRef)(null),g=(0,Z.useRef)(void 0),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(new Map),b=(0,Z.useRef)(null),x=(0,Z.useRef)(0),S=(0,Z.useRef)(!1),C=(0,Z.useRef)(!1),[w,T]=(0,Z.useState)(!1),E=(0,Z.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>hn(e)&&!hn(t)?-1:hn(t)&&!hn(e)?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return hn(n)&&!hn(r)?-1:hn(r)&&!hn(n)?1:n.timestamp-r.timestamp})},[e]),D=(0,Z.useMemo)(()=>{let e=[];for(let t=0;t<E.length;t++){let n=E[t],r=pn(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<E.length;e++){let t=pn(E[e]);if(t.role===`user`)break;if(t.role===`assistant`){i=t.content;break}}e.push({id:n.id,prompt:r.content,response:i})}return e},[E]),O=D.map(e=>e.id).join(``),A=(0,Z.useMemo)(()=>O?O.split(``):[],[O]),j=(0,Z.useMemo)(()=>new Set(A),[A]),[ee,te]=(0,Z.useState)(null),M=(0,Z.useCallback)(()=>{let e=_.current;if(!e||A.length===0){te(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(x.current,A.length-1);if(t<=2)n=A.length-1;else{let t=e.scrollTop+_n(e.clientHeight);for(;n<A.length-1;){let e=y.current.get(A[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=y.current.get(A[n]);if(!e||e.offsetTop<=t)break;n--}}x.current=n;let r=A[n];te(e=>e===r?e:r)},[A]),N=(0,Z.useCallback)(()=>{b.current===null&&(b.current=window.requestAnimationFrame(()=>{b.current=null,M()}))},[M]),P=(0,Z.useCallback)(()=>{let t=_.current;if(g.current&&clearTimeout(g.current),S.current=!1,g.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;C.current=!n,T(!n&&e.length>0),N()},[e.length,N]),re=(0,Z.useCallback)(()=>{g.current&&clearTimeout(g.current),g.current=setTimeout(P,180)},[P]),ie=(0,Z.useCallback)((e=!1)=>{C.current&&!e||h.current?.scrollIntoView({behavior:gn()})},[]),ae=(0,Z.useCallback)(()=>{let t=_.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(S.current){C.current=!0,T(!o&&e.length>0),N(),re();return}C.current=!o,T(!o&&e.length>0),a<=2&&A.length>0?(x.current=A.length-1,te(A[A.length-1])):N()},[A,e.length,re,N]),oe=(0,Z.useCallback)(e=>{let t=_.current,n=y.current.get(e);if(!t||!n)return;let r=gn();S.current=!0,C.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-_n(t.clientHeight)),behavior:r}),N(),r===`auto`?P():re()},[P,re,N]),F=(0,Z.useRef)(e.length);if((0,Z.useEffect)(()=>{e.length>F.current&&!C.current&&ie(),F.current=e.length},[e.length,ie]),(0,Z.useEffect)(()=>{i&&(t||n)&&!C.current&&requestAnimationFrame(()=>{let e=_.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Z.useEffect)(()=>{N();let e=v.current,t=_.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(N);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,N),()=>{n?.disconnect(),window.removeEventListener(`resize`,N)}},[O,N]),(0,Z.useEffect)(()=>()=>{b.current!==null&&(window.cancelAnimationFrame(b.current),b.current=null)},[]),(0,Z.useEffect)(()=>()=>{g.current&&clearTimeout(g.current)},[]),e.length===0&&!i)return(0,Q.jsx)(`div`,{className:f(`flex-1 flex items-center justify-center p-6 sm:p-10`,o),children:(0,Q.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,Q.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-surface/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,Q.jsx)(k,{className:`h-4 w-4`})}),(0,Q.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:m(`chatMessage.startConversation`)}),(0,Q.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:m(`chatMessage.startConversationDescription`)})]})});let se=-1;for(let e=E.length-1;e>=0;e--)if(E[e].messages.some(e=>e.role===`assistant`)){se=e;break}return(0,Q.jsxs)(`div`,{className:f(`relative min-h-0 flex-1`,o),style:{WebkitAppRegion:`no-drag`},children:[(0,Q.jsx)(`div`,{ref:_,"data-testid":`chat-scroll-viewport`,onScroll:ae,className:f(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,Q.jsxs)(`div`,{ref:v,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[E.map((e,a)=>{let o=a===se,s=j.has(e.id),d=i&&e.messages.some(e=>e.id===r),f;if(mn(e))f=(0,Q.jsx)(`div`,{className:`opacity-55`,children:(0,Q.jsx)(rn,{message:pn(e),isStreaming:!1,isLastAssistantMessage:!1,className:a===0?`mt-3 sm:mt-4`:``})});else if(e.messages.length===1){let s=e.messages[0],l=i&&s.id===r,d=l?{...s,content:t??s.content,thinking:n||s.thinking}:s;f=(0,Q.jsx)(rn,{message:d,isStreaming:l,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onEditResend:i?void 0:u,className:a===0?`mt-3 sm:mt-4`:``})}else f=(0,Q.jsx)(ln,{messages:e.messages,isStreaming:d,streamingMessage:t,streamingThinking:n,streamingMessageId:r||void 0,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onSelectBranch:l,className:a===0?`mt-3 sm:mt-4`:``});return(0,Q.jsx)(`div`,{ref:t=>{s&&(t?y.current.set(e.id,t):y.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:f},e.id)}),i&&a.length>0&&(0,Q.jsx)(fn,{tools:a,className:`px-0`}),!i&&d&&d.length>0&&p&&(0,Q.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,Q.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:m(`chat.followUp`)}),(0,Q.jsx)(`div`,{className:`flex flex-col`,children:d.map(e=>(0,Q.jsx)(`button`,{onClick:()=>p(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-gray-600 transition-colors hover:text-gray-900 dark:border-dark-200 dark:text-dark-600 dark:hover:text-dark-900`,children:e},e))})]}),(0,Q.jsx)(`div`,{ref:h,className:`h-4 sm:h-6`})]})}),(0,Q.jsx)(cn,{items:D,activeId:ee,onSelect:oe}),w&&(0,Q.jsxs)(`button`,{onClick:()=>{S.current=!1,g.current&&(clearTimeout(g.current),g.current=void 0),C.current=!1,h.current?.scrollIntoView({behavior:gn()}),T(!1)},className:f(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/[0.08]`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:m(`chatMessage.scrollToBottom`),children:[(0,Q.jsx)(ne,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:m(`chatMessage.newMessages`)})]})]})};function yn(e){let t=(e.match(/```/g)||[]).length,n=t%2==1,r=null;if(n){let t=e.lastIndexOf("```");if(t!==-1){let n=e.slice(t+3).match(/^(\w+)/);n&&(r=n[1])}}return{hasCodeBlocks:t>0,isInCodeBlock:n,language:r}}var bn=Z.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Z.useMemo)(()=>yn(e),[e]);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:f(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,Q.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,Q.jsxs)(`div`,{className:f(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,Q.jsx)(ye,{className:`h-3 w-3`}),d&&(0,Q.jsx)(`span`,{children:d}),!d&&u&&(0,Q.jsx)(`span`,{children:`code`})]})})]})});bn.displayName=`CodeAwareTextarea`;var xn=K(`components:media-upload`),Sn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Z.useRef)(null),[u,d]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)([]),_=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await v(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):F.error(`File type not supported: ${n.name}`)}},v=async r=>{if(n-e.length<=0){F.error(`Maximum ${n} images allowed`);return}if(r.size>10485760){F.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},y=async e=>{if(e.size>10485760){F.error(`File size must be less than 10MB`);return}m(!0);try{let t=await ze.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;g(e=>[...e,n]),i?.(n),F.success(`Document "${e.name}" uploaded`)}else F.error(t.error||`Failed to upload document`)}catch(e){xn.error(`Document upload error:`,e),F.error(`Failed to upload document`)}finally{m(!1)}},b=e=>{e.preventDefault(),a||d(!0)},x=e=>{e.preventDefault(),d(!1)},S=e=>{e.preventDefault(),d(!1),a||_(e.dataTransfer.files)},C=n=>{t(e.filter((e,t)=>t!==n))},w=async e=>{try{let t=await ze.deleteDocument(e);t.success?(g(t=>t.filter(t=>t.id!==e)),F.success(`Document removed`)):F.error(t.error||`Failed to remove document`)}catch(e){xn.error(`Error removing document:`,e),F.error(`Failed to remove document`)}},T=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},E=e.length>0||h.length>0;return(0,Q.jsxs)(`div`,{className:f(`space-y-3`,o),children:[(0,Q.jsxs)(`div`,{className:f(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>!a&&l.current?.click(),children:[(0,Q.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{_(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,Q.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[p?(0,Q.jsx)(ve,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,Q.jsx)(V,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,Q.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,Q.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,Q.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),C(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Q.jsx)(H,{className:`h-3 w-3`})})]},`img-${t}`)),h.map(e=>(0,Q.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,Q.jsx)(j,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,Q.jsx)(le,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,Q.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:T(e.size)})]}),(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,Q.jsx)(H,{className:`h-3 w-3`})})]},e.id))]})]})},Cn=K(`components:document-indicator`),wn=({sessionId:e,className:t=``})=>{let{t:n}=s(),[r,i]=(0,Z.useState)([]),[a,o]=(0,Z.useState)(!1),[c,u]=(0,Z.useState)(null),d=(0,Z.useRef)(null),f=(0,Z.useCallback)(async()=>{try{let t=await ze.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){Cn.error(`Failed to load documents:`,e)}},[e]);if((0,Z.useEffect)(()=>{let e=setTimeout(()=>void f(),0),t=()=>void f();return window.addEventListener(`libre:documents-updated`,t),()=>{clearTimeout(e),window.removeEventListener(`libre:documents-updated`,t)}},[f]),(0,Z.useEffect)(()=>{if(!a)return;let e=e=>{d.current?.contains(e.target)||(o(!1),u(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let p=async e=>{u(null);try{let t=await ze.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){Cn.error(`Failed to delete document:`,e),M.error(n(`settings.documents.library.deleteFailed`))}},m=r.reduce((e,t)=>e+t.size,0);return(0,Q.jsxs)(`div`,{ref:d,className:`relative inline-block ${t}`,children:[a&&(0,Q.jsxs)(`div`,{className:`absolute bottom-full left-0 z-50 mb-2 w-80 max-w-[85vw] rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-300 dark:bg-dark-100`,children:[(0,Q.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-xs font-medium text-gray-500 dark:text-dark-600`,children:n(`chat.documents.title`)}),(0,Q.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,Q.jsx)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-gray-50 dark:hover:bg-dark-200`,children:c===e.id?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-red-700 dark:text-red-300`,children:n(`settings.documents.library.deleteConfirm`,{name:e.filename})}),(0,Q.jsx)(`button`,{onClick:()=>void p(e.id),className:`shrink-0 text-xs font-medium text-red-600 underline underline-offset-2 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:n(`common.delete`)}),(0,Q.jsx)(`button`,{onClick:()=>u(null),className:`shrink-0 text-xs text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,children:n(`common.cancel`)})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(j,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`truncate text-xs text-gray-900 dark:text-dark-900`,children:e.filename}),(0,Q.jsxs)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:[l(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,Q.jsx)(`button`,{onClick:()=>u(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,Q.jsx)(H,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),u(null)},className:`
4
+ inline-flex items-center space-x-1 px-2 py-1
5
+ bg-blue-50 dark:bg-blue-900/20
6
+ border border-blue-200 dark:border-blue-800
7
+ rounded-md text-xs
8
+ transition-colors hover:bg-blue-100 dark:hover:bg-blue-900/40
9
+ `,title:`${n(`chat.documents.title`)} - ${l(m)}`,children:[(0,Q.jsx)(ie,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,Q.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[r.length,` doc`,r.length===1?``:`s`]})]})]})},Tn=K(`components:structured-output`),En=[{key:`none`,value:null},{key:`json`,value:`json`},{key:`list`,value:{type:`object`,properties:{items:{type:`array`,items:{type:`string`}}},required:[`items`]}},{key:`summary`,value:{type:`object`,properties:{title:{type:`string`},summary:{type:`string`},key_points:{type:`array`,items:{type:`string`}}},required:[`title`,`summary`,`key_points`]}},{key:`analysis`,value:{type:`object`,properties:{analysis:{type:`string`},pros:{type:`array`,items:{type:`string`}},cons:{type:`array`,items:{type:`string`}},recommendation:{type:`string`}},required:[`analysis`,`pros`,`cons`,`recommendation`]}},{key:`custom`,value:`custom`}],Dn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Z.useState)(!1),[o,c]=(0,Z.useState)(``),l=()=>En.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),u=()=>{let t=l();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},d=e=>{let n=l().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,Q.jsxs)(`div`,{className:f(`space-y-3`,n),children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Q.jsxs)(`div`,{className:`flex items-center`,children:[(0,Q.jsx)(N,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,Q.jsx)(Ke,{value:u().label,onChange:e=>d(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u().description}),i&&(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(qe,{value:o,onChange:e=>c(e.target.value),placeholder:`{
10
+ "type": "object",
11
+ "properties": {
12
+ "field1": { "type": "string" },
13
+ "field2": { "type": "number" }
14
+ },
15
+ "required": ["field1"]
16
+ }`,rows:8,className:`font-mono text-sm`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(J,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){Tn.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,Q.jsx)(J,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=u();return!e.value||e.value===`json`?null:(0,Q.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,Q.jsx)(we,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,Q.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,Q.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,Q.jsx)(j,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},On=({value:e,inheritedValue:t,onChange:n})=>{let{t:r}=s(),[i,a]=(0,Z.useState)(!1),o=(0,Z.useRef)(null),c=e??t,l=st(c),u=X(c),d=X(e),p=t==null?void 0:X(t);return(0,Z.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return window.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[i]),(0,Q.jsxs)(`div`,{ref:o,className:`relative flex-shrink-0`,children:[(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>a(e=>!e),className:f(`h-9 rounded-full p-0 flex items-center justify-center gap-1 touch-manipulation transition-colors duration-150`,l?`w-auto px-2.5`:`w-9 sm:h-10 sm:w-10`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,l&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:l?r(`chat.input.thinkingOn`,{level:r(`settings.generation.thinkingLevels.${u}`)}):r(`chat.input.thinkingOff`),"aria-haspopup":`menu`,"aria-expanded":i,"aria-pressed":l,children:[(0,Q.jsx)(O,{className:`h-4 w-4`}),l&&(0,Q.jsx)(`span`,{className:`text-[11px] font-medium`,children:r(`settings.generation.thinkingLevels.${u}`)})]}),i&&(0,Q.jsxs)(`div`,{role:`menu`,className:`absolute bottom-full end-0 z-30 mb-2 w-48 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:[(0,Q.jsx)(`p`,{className:`mb-1 px-2 pt-1 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.controls.thinking`)}),ct.map(e=>{let t=e===d;return(0,Q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":t,onClick:()=>{n(ot(e)),a(!1)},className:f(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),children:[(0,Q.jsx)(`span`,{className:`truncate`,children:e==="default"&&p!==void 0?r(`settings.generation.thinkingLevels.defaultWith`,{level:r(`settings.generation.thinkingLevels.${p}`)}):r(`settings.generation.thinkingLevels.${e}`)}),t&&(0,Q.jsx)(de,{className:`h-3.5 w-3.5 shrink-0`})]},e)})]})]})},kn=7,An=2*Math.PI*kn,jn=e=>`⁨${e}⁩`,Mn=({usage:e,trainedBudget:t})=>{let{t:n,i18n:r}=s(),[i,a]=(0,Z.useState)(!1),o=typeof e.budget==`number`&&e.budget>0,c=e.ratio??0,l=Math.round(c*100),u=e.measured?``:`~`,d=r.language,p=`${u}${v(e.used,d)}`,m=o?n(`chat.context.tokensUsed`,{used:jn(p),budget:jn(v(e.budget,d))}):n(`chat.context.tokensUsedNoBudget`,{used:jn(p)}),h=t===void 0?void 0:n(`chat.context.capped`,{trained:jn(v(t,d))}),g=[n(`chat.context.title`),o?n(`chat.context.full`,{percent:l}):void 0,m,h].filter(Boolean).join(` `),_=Math.min(c,1);return(0,Q.jsxs)(`div`,{className:`relative flex-shrink-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onFocus:()=>a(!0),onBlur:()=>a(!1),onKeyDown:e=>{e.key===`Escape`&&a(!1)},children:[(0,Q.jsx)(`span`,{role:o?`meter`:`img`,tabIndex:0,"aria-label":g,...o?{"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(l,100),"aria-valuetext":g}:{},className:f(`flex h-9 w-9 items-center justify-center rounded-full text-gray-400 outline-none sm:h-10 sm:w-10`,`transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/40`,`dark:text-dark-500`,c>=.8&&c<1&&`text-amber-600 dark:text-amber-400`,c>=1&&`text-red-600 dark:text-red-400`),children:(0,Q.jsxs)(`svg`,{viewBox:`0 0 18 18`,className:`h-4 w-4 -rotate-90`,children:[(0,Q.jsx)(`circle`,{cx:`9`,cy:`9`,r:kn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`opacity-30`,...o?{}:{strokeDasharray:`2 2`}}),o&&_>0&&(0,Q.jsx)(`circle`,{cx:`9`,cy:`9`,r:kn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:An,strokeDashoffset:An*(1-_)})]})}),i&&(0,Q.jsxs)(`div`,{role:`tooltip`,className:f(`pointer-events-none absolute bottom-full left-1/2 z-30 mb-2 -translate-x-1/2`,`whitespace-nowrap rounded-2xl bg-surface/95 px-4 py-3 text-center shadow-lv3 backdrop-blur-xl`,`border border-black/[0.06] dark:border-white/[0.08] dark:bg-dark-100/95`,`animate-scale-in`),children:[(0,Q.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.title`)}),o&&(0,Q.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.full`,{percent:l})}),(0,Q.jsx)(`p`,{className:`text-[13px] tabular-nums text-gray-900 dark:text-dark-900`,children:m}),h&&(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:h})]})]})},Nn=K(`components:chat-input`),Pn=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},Fn=[{mimeType:`audio/webm;codecs=opus`,format:`webm`}],In=300,Ln=.25,Rn=e=>`${encodeURIComponent(e.plugin)}:${encodeURIComponent(e.model)}`;function zn(e){if(typeof MediaRecorder>`u`)return;let t=new Set((e.config?.formats||[]).map(e=>e.toLowerCase()));return Fn.find(e=>(t.size===0||t.has(e.format))&&(typeof MediaRecorder.isTypeSupported!=`function`||MediaRecorder.isTypeSupported(e.mimeType)))?.mimeType}var Bn=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r,i18n:i}=s(),[a,o]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(!1),[v,x]=(0,Z.useState)([]),[T,E]=(0,Z.useState)(()=>typeof window<`u`&&window.isSecureContext&&typeof navigator<`u`&&navigator.mediaDevices&&Pn()?`browser`:``),O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=(0,Z.useRef)(null),ee=(0,Z.useRef)(null),te=(0,Z.useRef)(null),N=(0,Z.useRef)(0),ne=(0,Z.useRef)(`idle`),P=(0,Z.useRef)(void 0),re=(0,Z.useRef)(``),oe=(0,Z.useMemo)(()=>typeof window<`u`&&window.isSecureContext&&typeof navigator<`u`&&!!navigator.mediaDevices&&!!Pn(),[]),F=(0,Z.useMemo)(()=>v.filter(e=>!!zn(e)),[v]),ce=typeof window<`u`&&window.isSecureContext&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia,le=(0,Z.useMemo)(()=>ce?F:[],[F,ce]),I=(0,Z.useMemo)(()=>T===`browser`&&oe||le.some(e=>Rn(e)===T)?T:oe?`browser`:le[0]?Rn(le[0]):``,[oe,le,T]),L=(0,Z.useMemo)(()=>le.find(e=>Rn(e)===I),[I,le]),fe=!!L,R=oe||fe,[z,pe]=(0,Z.useState)([]),[B,V]=(0,Z.useState)(null),[me,he]=(0,Z.useState)(!1),[_e,H]=(0,Z.useState)(!1),[ye,U]=(0,Z.useState)(!1),[xe,Se]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{let e=!1;return je.getConfig().then(t=>{!e&&t.success&&t.data&&U(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]),(0,Z.useEffect)(()=>{let e=!1;return Fe.getModels().then(t=>{!e&&t.success&&t.data&&x(t.data)}).catch(()=>{e||x([])}),()=>{e=!0}},[]);let[W,G]=(0,Z.useState)(null),[we,Te]=(0,Z.useState)(!1),[Oe,K]=(0,Z.useState)([]),[Ae,Ne]=(0,Z.useState)(!1),[Ie,Le]=(0,Z.useState)(!1),[q,Be]=(0,Z.useState)(null),[He,Ue]=(0,Z.useState)(!1),We=(0,Z.useRef)(null),Ge=(0,Z.useRef)(null),{isGenerating:Ke,setBackgroundImage:qe}=Ve(),Je=Ve(e=>e.preferences.generationOptions),Ye=Ve(e=>e.preferences.imageGenSettings?.enabled===!0),Xe=Ye&&He,{currentSession:Y,models:Ze}=w(),Qe=Ve(e=>Y?.model?e.preferences.modelGenerationOptions?.[Y.model]:void 0),$e=Y?.id,et=(0,Z.useRef)(null),tt=(0,Z.useMemo)(()=>({model:Y?.personaId?`persona:${Y.personaId}`:Y?.model||``,providerType:Y?.providerType,providerId:Y?.providerId}),[Y?.model,Y?.personaId,Y?.providerId,Y?.providerType]),nt=(0,Z.useMemo)(()=>_(Ze,tt),[Ze,tt]),rt=tt.model?g(nt,tt):``,it=b(Ze,tt);(0,Z.useEffect)(()=>{let e=!1;return Ye&&(async()=>{try{let t=await Re.getPlugins();if(e)return;Ue(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;Ue(!1)}})(),()=>{e=!0}},[Ye]),(0,Z.useEffect)(()=>{if(!_e)return;let e=e=>{We.current&&!We.current.contains(e.target)&&(H(!1),G(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[_e]);let at=()=>{H(!1),G(null),Te(!1)};(0,Z.useEffect)(()=>{if(!we)return;let e=!1;return ze.getCollections().then(t=>{!e&&t.success&&t.data&&K(t.data)}).catch(()=>{}),()=>{e=!0}},[we]);let ot=Y?.settings?.generationOptions?.think,st=Qe?.think??Je?.think??null,X=(0,Z.useMemo)(()=>Ze.find(e=>e.name===Y?.model),[Ze,Y?.model]),[ct,lt]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{let e=Y?.model;if(!e||Ze.length===0||!X||X.isPlugin||X.isAgent)return;let t=!1;return Pe.getModelDefaults(e).then(n=>{t||!n.success||!n.data||lt({model:e,supportsThinking:n.data.supportsThinking,options:n.data.options??{},trainedContextLength:n.data.trainedContextLength,contextCapped:n.data.contextCapped})}).catch(()=>{}),()=>{t=!0}},[X,Y?.model,Ze.length]);let dt=ct?.model===Y?.model?ct:null,ft=dt?.supportsThinking,pt=!!(Y&&!X?.isAgent&&(X?.isPlugin?X.reasoningSupport!==!1:ft!==!1)),mt=S({model:X,sessionOptions:Y?.settings?.generationOptions,pinnedOptions:Qe,modelDefaults:dt?.options,globalOptions:Je}),ht=w(e=>e.contextWindowMessages),gt=(0,Z.useMemo)(()=>C({messages:Y?.messages??[],budget:mt,systemPrompt:q?.parameters?.system_prompt,windowMessages:ht}),[mt,ht,q,Y?.messages]),_t=async e=>{if(!Y)return;let t={...Y.settings?.generationOptions??{}};e===null?delete t.think:t.think=e;let n={...Y.settings,generationOptions:t};if(w.setState(e=>({currentSession:e.currentSession?.id===Y.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===Y.id?{...e,settings:n}:e)})),!Y.isPrivate)try{await ke.updateSession(Y.id,{settings:n})}catch(e){Nn.error(`Failed to update the thinking setting:`,e)}},vt=Y?.settings?.knowledgeCollectionIds??[],yt=async e=>{if(!Y)return;let t=vt.includes(e)?vt.filter(t=>t!==e):[...vt,e],n={...Y.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(w.setState(e=>({currentSession:e.currentSession?.id===Y.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===Y.id?{...e,settings:n}:e)})),!Y.isPrivate)try{await ke.updateSession(Y.id,{settings:n})}catch(e){Nn.error(`Failed to update knowledge collections:`,e),M.error(r(`chat.input.menu.attachFailed`))}},bt=(0,Z.useCallback)(()=>{te.current!==null&&(window.clearTimeout(te.current),te.current=null)},[]),$=(0,Z.useCallback)(e=>{ne.current=e,l(e===`starting`),d(e===`recording`),m(e===`transcribing`)},[]),xt=(0,Z.useCallback)(()=>{N.current+=1,bt(),O.current?.stop(),O.current=null,ee.current?.abort(),ee.current=null;let e=k.current;k.current=null,e&&(e.ondataavailable=null,e.onerror=null,e.onstop=null,e.state===`recording`&&e.stop()),A.current?.getTracks().forEach(e=>e.stop()),A.current=null,$(`idle`)},[bt,$]);(0,Z.useEffect)(()=>(P.current=$e,xt),[xt,$e]);let St=async()=>{let e=ne.current;if(e===`starting`||e===`transcribing`){xt();return}if(e===`recording`){k.current?.state===`recording`?($(`transcribing`),k.current.stop()):xt();return}let t=L;if(t&&fe){let e=N.current+1;N.current=e;let n=Y?.id;re.current=a,$(`starting`);try{let a=await navigator.mediaDevices.getUserMedia({audio:!0});if(N.current!==e||P.current!==n){a.getTracks().forEach(e=>e.stop());return}A.current=a;let s=zn(t),c=s?new MediaRecorder(a,{mimeType:s}):new MediaRecorder(a),l=[];c.ondataavailable=e=>{e.data.size>0&&l.push(e.data)},c.onerror=()=>{a.getTracks().forEach(e=>e.stop()),bt(),N.current===e&&(k.current=null,A.current=null,$(`idle`),M.error(r(`chat.input.menu.attachFailed`)))},c.onstop=()=>{if(a.getTracks().forEach(e=>e.stop()),bt(),N.current!==e||P.current!==n)return;if(k.current=null,A.current=null,l.length===0){$(`idle`);return}let s=new Blob(l,{type:c.mimeType||l[0].type||`audio/webm`}),u=new AbortController;ee.current=u,$(`transcribing`),Fe.transcribe(s,t,{language:i.language,signal:u.signal}).then(t=>{if(N.current!==e||P.current!==n||u.signal.aborted)return;let r=re.current;o(r?`${r} ${t.text.trim()}`:t.text.trim())}).catch(e=>{u.signal.aborted||(Nn.error(`Provider transcription failed:`,e),M.error(e instanceof Error?e.message:r(`chat.input.menu.attachFailed`)))}).finally(()=>{ee.current===u&&N.current===e&&(ee.current=null,$(`idle`))})},k.current=c,c.start(250);let u=t.config?.max_duration_seconds,d=typeof u==`number`&&u>0?Math.min(u,In):In;te.current=window.setTimeout(()=>{N.current===e&&c.state===`recording`&&c.stop()},Math.max(.1,d-Ln)*1e3),$(`recording`);return}catch(t){if(N.current!==e)return;Nn.error(`Failed to start provider dictation:`,t),bt(),A.current?.getTracks().forEach(e=>e.stop()),A.current=null,k.current=null,$(`idle`),M.error(r(`chat.input.menu.attachFailed`));return}}let n=Pn();if(!n)return;let s=N.current+1;N.current=s;let c=Y?.id,l=new n;l.lang=i.language,l.continuous=!0,l.interimResults=!0,re.current=a,l.onresult=e=>{if(N.current!==s||P.current!==c||O.current!==l)return;let t=``;for(let n=0;n<e.results.length;n++)t+=e.results[n][0]?.transcript??``;let n=re.current;o(n?`${n} ${t.trim()}`:t.trim())},l.onend=()=>{N.current===s&&(O.current=null,$(`idle`))},l.onerror=()=>{N.current===s&&(O.current=null,$(`idle`))},O.current=l,$(`recording`);try{l.start()}catch(e){Nn.error(`Failed to start dictation:`,e),O.current=null,$(`idle`)}},Ct=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){at(),Le(!0);try{let e=await ze.uploadDocument(t,Y?.id);e.success?(M.success(r(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):M.error(e.error||r(`chat.input.menu.attachFailed`))}catch(e){Nn.error(`Document upload failed:`,e),M.error(r(`chat.input.menu.attachFailed`))}finally{Le(!1)}}},wt=async()=>{let e=W?.trim();if(!(!e||Ae)){Ne(!0);try{let t=await ze.fetchWebpage(e,Y?.id);t.success?(M.success(r(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),at()):M.error(t.error||r(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||r(`chat.input.menu.attachFailed`);Nn.error(`Webpage attach failed:`,e),M.error(t)}finally{Ne(!1)}}},Tt=t=>{if(t.preventDefault(),!(!a.trim()||Ke)){if(!it){M.error(r(`chat.model.selectBeforeSending`));return}e(a.trim(),z.length>0?z:void 0,B||void 0,ye&&xe?!0:void 0),o(``),pe([])}},Et=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Tt(e))},Dt=()=>{t()};(0,Z.useEffect)(()=>{let e=et.current;e&&(e.style.height=`auto`,e.style.height=a?`${Math.min(e.scrollHeight,200)}px`:``)},[a]),(0,Z.useEffect)(()=>{(async()=>{if(Y?.personaId)try{let e=await Me.getPersona(Y.personaId);if(e.success&&e.data)Be(e.data);else{Nn.warn(`Persona ${Y.personaId} not found, clearing reference`),Be(null);let{setCurrentSession:e}=w.getState();e({...Y,personaId:void 0})}}catch(e){if(Nn.error(`Failed to load current persona:`,e),Be(null),Y){let{setCurrentSession:e}=w.getState();e({...Y,personaId:void 0})}}else Be(null)})()},[Y?.personaId]);let Ot=async e=>{let t=y(nt,e.target.value);if(t&&Y)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await Me.getPersona(e);if(!n.success||!n.data){M.error(r(`chat.persona.loadFailed`));return}let i=n.data,a=await ke.updateSession(Y.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(a.success&&a.data){let{sessions:e}=w.getState(),t=e.map(e=>e.id===Y.id?a.data:e);w.setState({sessions:t,currentSession:a.data}),i.background&&qe(i.background),M.success(r(`chat.persona.applied`))}}else{let e=await ke.updateSession(Y.id,{model:t.model,providerType:t.providerType,providerId:(t.providerType===`plugin`||t.providerType===`agent`)&&t.providerId||null,personaId:null});if(e.success&&e.data){let{sessions:t}=w.getState(),n=t.map(t=>t.id===Y.id?e.data:t);w.setState({sessions:n,currentSession:e.data}),qe(null),M.success(r(`chat.model.updated`))}}}catch(e){Nn.error(`Failed to update session:`,e),M.error(r(`chat.toasts.updateFailed`))}},kt=z.length>0||B!==null;return(0,Q.jsx)(`div`,{className:`pointer-events-none`,children:(0,Q.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[me&&(0,Q.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/90`,children:[(0,Q.jsx)(Sn,{images:z,onImagesChange:pe,maxImages:5,sessionId:Y?.id,disabled:n}),(0,Q.jsx)(Dn,{format:B,onFormatChange:V})]}),(0,Q.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[(0,Q.jsx)(`form`,{onSubmit:Tt,children:(0,Q.jsxs)(`div`,{className:f(`rounded-[24px] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200`,`bg-surface dark:bg-surface-subtle`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-lv2 focus-within:shadow-lv3`),children:[(0,Q.jsx)(bn,{ref:et,value:a,onChange:e=>o(e.target.value),onKeyDown:Et,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!m-0 block w-full min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-2 !pt-1.5 !pb-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`div`,{ref:We,className:`relative flex-shrink-0`,children:[(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(me){he(!1);return}H(e=>!e),G(null)},className:f(`h-9 w-9 !p-0 rounded-full flex-shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay`,`transition-colors duration-150 touch-manipulation`,kt&&`text-primary-600 dark:text-primary-400`,(me||_e)&&`bg-hover-solid text-ink`),title:r(`chat.input.attachments`),children:Ie||Ae?(0,Q.jsx)(ve,{className:`h-4 w-4 animate-spin`}):kt?(0,Q.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,Q.jsx)(ue,{className:`h-4 w-4`}),(0,Q.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):me?(0,Q.jsx)(be,{className:`h-4 w-4`}):(0,Q.jsx)(se,{className:`h-4 w-4`})}),_e&&(0,Q.jsx)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 w-64 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:we?(0,Q.jsxs)(`div`,{className:`p-1`,children:[(0,Q.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.input.menu.attachKnowledge`)}),Oe.length===0?(0,Q.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-gray-400 dark:text-dark-500`,children:r(`chat.input.menu.noCollections`)}):Oe.map(e=>{let t=vt.includes(e.id);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void yt(e.id),className:f(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),"aria-pressed":t,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(ie,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,Q.jsx)(de,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Te(!1),className:`mt-1 w-full rounded-lg border-t border-gray-100 px-2.5 py-1.5 text-start text-xs text-gray-500 hover:bg-gray-100 dark:border-dark-300 dark:text-dark-600 dark:hover:bg-dark-200`,children:r(`common.back`)})]}):W===null?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{he(!0),at()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Q.jsx)(De,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.uploadImages`)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Ge.current?.click(),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Q.jsx)(j,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachDocument`)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>G(``),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Q.jsx)(ae,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachWebpage`)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Te(!0),className:`flex w-full items-center justify-between gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(ie,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachKnowledge`)]}),vt.length>0&&(0,Q.jsx)(`span`,{className:`rounded-full bg-primary-50 px-1.5 text-[10px] font-medium tabular-nums text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`,children:vt.length})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{he(!0),at()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Q.jsx)(Ee,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.structuredOutput`)]})]}):(0,Q.jsxs)(`div`,{className:`p-1.5`,children:[(0,Q.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.input.menu.attachWebpage`)}),(0,Q.jsx)(`input`,{type:`url`,value:W,onChange:e=>G(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),wt()):e.key===`Escape`&&G(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`}),(0,Q.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>G(null),className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:r(`common.cancel`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>void wt(),disabled:!W.trim()||Ae,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white hover:bg-gray-700 disabled:opacity-50 dark:bg-dark-300 dark:hover:bg-dark-400`,children:Ae?(0,Q.jsx)(ve,{className:`h-3.5 w-3.5 animate-spin`}):r(`chat.input.menu.attach`)})]})]})}),(0,Q.jsx)(`input`,{ref:Ge,type:`file`,accept:`.pdf,.txt,application/pdf,text/plain`,className:`hidden`,onChange:e=>void Ct(e)})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 sm:gap-1.5`,children:[pt&&(0,Q.jsx)(On,{value:ot,inheritedValue:st,onChange:e=>void _t(e)}),ye&&(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Se(e=>!e),className:f(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,xe&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:r(xe?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":xe,children:(0,Q.jsx)(ae,{className:`h-4 w-4`})}),le.length>0&&(0,Q.jsxs)(`select`,{value:I,onChange:e=>E(e.target.value),disabled:c||u||p,"aria-label":r(`chat.input.transcriptionSource`),title:L?r(`chat.input.providerTranscriptionDisclosure`,{provider:L.plugin}):r(`chat.input.transcriptionSource`),className:`h-8 max-w-32 rounded-lg border border-black/[0.08] bg-transparent px-1.5 text-[11px] text-gray-500 outline-none focus:border-primary-500/40 dark:border-white/[0.09] dark:text-dark-600`,children:[oe&&(0,Q.jsx)(`option`,{value:`browser`,children:r(`chat.input.browserSpeech`)}),le.map(e=>(0,Q.jsxs)(`option`,{value:Rn(e),children:[e.plugin,` · `,e.model]},Rn(e)))]}),R&&(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void St(),className:f(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,(c||u||p)&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:p||c?r(`common.cancel`):u?r(`chat.input.voiceStop`):L?r(`chat.input.providerTranscriptionDisclosure`,{provider:L.plugin}):r(`chat.input.voiceInput`),"aria-pressed":c||u||p,children:c?(0,Q.jsx)(ve,{className:`h-4 w-4 animate-spin`}):p?(0,Q.jsx)(D,{className:`h-4 w-4`}):(0,Q.jsx)(Ce,{className:`h-4 w-4`})}),Y&&(0,Q.jsx)(Mn,{usage:gt,trainedBudget:dt?.contextCapped?dt.trainedContextLength:void 0}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`}),Y&&nt.length>0&&(0,Q.jsx)(`div`,{className:`hidden sm:block`,children:(0,Q.jsx)(ut,{models:nt,selectedModel:rt,onModelChange:Ot,getModelValue:h,currentPersona:q,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:Xe})}),Ke?(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:Dt,className:f(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.stopGeneration`),children:(0,Q.jsx)(D,{className:`h-4 w-4`})}):(0,Q.jsx)(J,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!a.trim()||n||!it,className:f(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-primary-500 text-white hover:bg-primary-400`,`disabled:cursor-not-allowed disabled:bg-primary-300/50 disabled:text-white/80 dark:disabled:bg-primary-800/60 dark:disabled:text-white/40 disabled:hover:bg-primary-300/50 dark:disabled:hover:bg-primary-800/60`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.sendMessage`),children:(0,Q.jsx)(ge,{className:`h-4 w-4`})})]})]})]})}),L&&fe&&(0,Q.jsx)(`p`,{role:`note`,className:`mt-1.5 text-center text-[10px] leading-relaxed text-amber-700 dark:text-amber-300`,children:r(`chat.input.providerTranscriptionDisclosure`,{provider:L.plugin})}),Y&&nt.length>0&&(0,Q.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,Q.jsx)(ut,{models:nt,selectedModel:rt,onModelChange:Ot,getModelValue:h,currentPersona:q,className:`w-full`,compact:!0,showImageGen:Xe})}),(0,Q.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,Q.jsx)(wn,{sessionId:Y?.id}),(0,Q.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,Q.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),kt&&(0,Q.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,z.length>0&&r(`chat.footer.images`,{count:z.length}),z.length>0&&B&&` • `,B&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},Vn=K(`components:chat-controls-panel`),Hn=[{key:`temperature`,labelKey:`temperature`,step:`0.1`,min:0,max:2},{key:`top_p`,labelKey:`topP`,step:`0.05`,min:0,max:1},{key:`top_k`,labelKey:`topK`,step:`1`,min:1},{key:`min_p`,labelKey:`minP`,step:`0.05`,min:0,max:1},{key:`num_predict`,labelKey:`maxTokens`,step:`1`},{key:`repeat_penalty`,labelKey:`repeatPenalty`,step:`0.05`,min:0},{key:`seed`,labelKey:`seed`,step:`1`},{key:`num_ctx`,labelKey:`contextLength`,step:`1`}],Un=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i}=s(),a=w(e=>e.draftSessionSettings),o=w(e=>e.setDraftSessionSettings),l=e?.model??t??``,u=Ve(e=>e.preferences.generationOptions),d=Ve(e=>e.preferences.modelGenerationOptions?.[l]),[f,p]=(0,Z.useState)({options:{},contextCapped:!1});(0,Z.useEffect)(()=>{if(!n||!l)return;let e=!1;return Pe.getModelDefaults(l).then(t=>{e||!t.success||!t.data||p({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,l]);let h=(0,Z.useMemo)(()=>({...u??{},...f.options,...d??{}}),[u,f.options,d]),g=(0,Z.useMemo)(()=>e?.messages.find(e=>e.role===`system`&&!m(e.content)),[e?.messages]),[_,v]=(0,Z.useState)(g?.content??a.systemPrompt??``),[y,b]=(0,Z.useState)(e?.settings?.generationOptions??a.generationOptions??{}),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(e?.settings?.compaction!==!1),[E,D]=(0,Z.useState)(e?.id??`draft`),O=e?.id??`draft`;E!==O&&(D(O),v(g?.content??a.systemPrompt??``),b(e?.settings?.generationOptions??a.generationOptions??{}),T(e?.settings?.compaction!==!1));let k=e=>{b(t=>{let n={...t},r=ot(e);return r===null?delete n.think:n.think=r,n})},A=(e,t)=>{b(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},j=async()=>{S(!0);try{let t=_.trim(),n=g?.content??``,a=Object.fromEntries(Object.entries(y).filter(([,e])=>e!==void 0)),s=e?{...e.settings,generationOptions:a}:Object.keys(a).length>0?{generationOptions:a}:void 0;if(s&&e&&(C?delete s.compaction:s.compaction=!1),!e){o({systemPrompt:t||void 0,generationOptions:s?.generationOptions}),F.success(i(`chat.controls.saved`)),r();return}let l=e.messages;if(t!==n.trim()&&(g?l=t?e.messages.map(e=>e.id===g.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==g.id):t&&(l=[{id:c(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)w.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:l,settings:s}:t.currentSession}));else{let t=await ke.updateSession(e.id,{messages:l,settings:s});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;w.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}F.success(i(`chat.controls.saved`)),r()}catch(e){Vn.error(`Failed to save chat controls:`,e),F.error(i(`chat.controls.saveFailed`))}finally{S(!1)}};return n?(0,Q.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:`flex h-full w-[21rem] shrink-0 flex-col border-s border-black/[0.06] bg-surface/70 backdrop-blur-xl dark:border-white/[0.07] dark:bg-dark-100/70`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,Q.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:i(`chat.controls.title`)}),(0,Q.jsx)(`button`,{onClick:r,className:`rounded-full p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-900`,title:i(`common.close`),children:(0,Q.jsx)(H,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.systemPrompt`)}),(0,Q.jsx)(`textarea`,{dir:`auto`,value:_,onChange:e=>v(e.target.value),placeholder:i(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/[0.08] bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{htmlFor:`chat-control-think`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.thinking`)}),(0,Q.jsx)(`select`,{id:`chat-control-think`,value:X(y.think),onChange:e=>k(e.target.value),className:`w-full rounded-xl border border-black/[0.08] bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`,children:ct.map(e=>(0,Q.jsx)(`option`,{value:e,children:e==="default"&&h.think!==void 0&&h.think!==null?i(`settings.generation.thinkingLevels.defaultWith`,{level:i(`settings.generation.thinkingLevels.${X(h.think)}`)}):i(`settings.generation.thinkingLevels.${e}`)},e))}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.thinkingDescription`)})]}),e&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{htmlFor:`chat-control-compaction`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.compaction`)}),(0,Q.jsxs)(`select`,{id:`chat-control-compaction`,value:C?`default`:`off`,onChange:e=>T(e.target.value!==`off`),className:`w-full rounded-xl border border-black/[0.08] bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`,children:[(0,Q.jsx)(`option`,{value:`default`,children:i(`chat.controls.compactionDefault`)}),(0,Q.jsx)(`option`,{value:`off`,children:i(`chat.controls.compactionOff`)})]}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.compactionDescription`)})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.advancedParams`)}),(0,Q.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.advancedParamsDescription`)}),f.contextCapped&&f.trainedContextLength&&(0,Q.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-500 dark:text-dark-600`,children:i(`chat.controls.contextCapped`,{context:h.num_ctx?.toLocaleString(),trained:f.trainedContextLength.toLocaleString()})}),(0,Q.jsx)(`div`,{className:`space-y-1.5`,children:Hn.map(e=>{let t=y[e.key],n=h[e.key],r=f.options[e.key]!==void 0&&d?.[e.key]===void 0;return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`label`,{htmlFor:`chat-control-${e.key}`,className:`text-[13px] text-gray-700 dark:text-dark-700`,children:[i(`chat.controls.params.${e.labelKey}`),r&&(0,Q.jsx)(`span`,{title:i(`chat.controls.fromModelHint`),className:`ms-1.5 text-[10px] uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:i(`chat.controls.fromModel`)})]}),(0,Q.jsx)(`input`,{id:`chat-control-${e.key}`,type:`number`,inputMode:`decimal`,step:e.step,min:e.min,max:e.max,value:typeof t==`number`?t:``,placeholder:typeof n==`number`?String(n):i(`common.default`),onChange:t=>A(e.key,t.target.value),className:`w-24 rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-black/[0.06] px-4 py-3 dark:border-white/[0.07] lg:pb-16`,children:[(0,Q.jsx)(`button`,{onClick:()=>{b({}),v(g?.content??``)},className:`text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:i(`common.reset`)}),(0,Q.jsx)(J,{onClick:()=>void j(),size:`sm`,disabled:x,children:i(x?`common.saving`:`common.save`)})]})]}):null},Wn=6,Gn=[],Kn=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}},qn=({session:e})=>{let{t}=s(),[n,r]=(0,Z.useState)({sessionId:``,docs:Gn}),i=!e.isPrivate&&n.sessionId===e.id?n.docs:Gn,[a,o]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(!1),{webSources:f,ragSources:p}=(0,Z.useMemo)(()=>{let t=new Map,n=new Map;for(let r of e.messages){let e=r.providerMetadata;if(Array.isArray(e?.webSearchSources))for(let n of e.webSearchSources){let e=n;e&&typeof e.url==`string`&&e.url&&t.set(e.url,{url:e.url,title:typeof e.title==`string`&&e.title?e.title:e.url})}if(Array.isArray(e?.ragSources))for(let t of e.ragSources){let e=t;e&&typeof e.id==`string`&&e.id&&n.set(e.id,{id:e.id,filename:typeof e.filename==`string`&&e.filename?e.filename:e.id})}}return{webSources:Array.from(t.values()),ragSources:Array.from(n.values())}},[e.messages]);(0,Z.useEffect)(()=>{if(e.isPrivate)return;let t=!1,n=()=>{ze.getDocuments(e.id).then(n=>{t||!n.success||!Array.isArray(n.data)||r({sessionId:e.id,docs:n.data.map(e=>({id:e.id,filename:e.filename}))})}).catch(()=>{})};return n(),window.addEventListener(`libre:documents-updated`,n),()=>{t=!0,window.removeEventListener(`libre:documents-updated`,n)}},[e.id,e.isPrivate]);let m=(0,Z.useMemo)(()=>{let e=new Map;for(let t of i)e.set(t.id,{...t,used:!1});for(let t of p)e.set(t.id,{id:t.id,filename:t.filename,used:!0});return Array.from(e.values())},[i,p]);if(f.length===0&&m.length===0)return null;let h=a?f:f.slice(0,Wn),g=c?m:m.slice(0,Wn),_=(e,n,r)=>(e>0||n)&&(0,Q.jsx)(`button`,{type:`button`,onClick:r,className:`mt-1 flex items-center gap-1 px-1 text-[12px] text-gray-400 transition-colors hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,children:n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Se,{className:`h-3 w-3`}),t(`chatMessage.showLess`,`Show less`)]}):`${t(`chatMessage.showMore`)} (${e})`}),v=(0,Q.jsxs)(Q.Fragment,{children:[f.length>0&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`chat.message.sources`,`Sources`)}),(0,Q.jsx)(`ul`,{className:`space-y-0.5`,children:h.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`group -mx-1 flex items-center gap-2.5 rounded-lg px-1 py-1.5 transition-colors hover:bg-black/[0.04] dark:hover:bg-white/[0.05]`,title:e.url,children:[(0,Q.jsx)(ae,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-700 dark:text-dark-500 dark:group-hover:text-dark-800`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.title}),(0,Q.jsx)(`span`,{dir:`ltr`,className:`block truncate text-[11px] text-gray-400 dark:text-dark-500`,children:Kn(e.url)})]})]})},e.url))}),_(f.length-h.length,a,()=>o(e=>!e))]}),m.length>0&&(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`settings.tabs.documents`,`Documents`)}),(0,Q.jsx)(`ul`,{className:`space-y-0.5`,children:g.map(e=>(0,Q.jsxs)(`li`,{className:`-mx-1 flex items-center gap-2.5 rounded-lg px-1 py-1.5`,title:e.filename,children:[(0,Q.jsx)(j,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,Q.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.filename}),e.used&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-primary-500`})]},e.id))}),_(m.length-g.length,c,()=>l(e=>!e))]})]});return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`aside`,{"data-testid":`chat-sources-panel`,className:`hidden w-72 shrink-0 flex-col gap-7 overflow-y-auto border-s border-black/[0.05] px-5 py-6 scrollbar-thin dark:border-white/[0.06] xl:flex`,children:v}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),"data-testid":`chat-sources-trigger`,className:`absolute end-3 top-[4.25rem] z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 xl:hidden`,title:t(`chat.message.sources`,`Sources`),"aria-haspopup":`dialog`,"aria-expanded":u,children:[(0,Q.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`absolute -end-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white shadow-sm`,children:f.length+m.length})]}),u&&(0,dt.createPortal)((0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[80] xl:hidden`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/35 backdrop-blur-[2px]`,onClick:()=>d(!1),"aria-label":t(`common.close`)}),(0,Q.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":t(`chat.message.sources`,`Sources`),className:`absolute inset-x-3 bottom-3 max-h-[75vh] overflow-y-auto rounded-2xl border border-black/[0.08] bg-surface p-5 shadow-[0_20px_70px_rgba(0,0,0,0.3)] scrollbar-thin dark:border-white/[0.09] dark:bg-dark-100`,"data-testid":`chat-sources-sheet`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:t(`chat.message.sources`,`Sources`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`rounded-md p-1.5 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":t(`common.close`),children:(0,Q.jsx)(H,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-6`,children:v})]})]}),document.body)]})},Jn=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Z.useState)(!1),a=(0,Z.useRef)(null),[o,s]=(0,Z.useState)({top:0,left:0});(0,Z.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect(),t=document.documentElement.dir===`rtl`?e.right-288:e.left;s({top:e.bottom+8,left:Math.min(window.innerWidth-288-8,Math.max(8,t))})}},[r]);let c=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),l=()=>Ne(e,64),u=t=>{Le(t.currentTarget,e.name,64)};return(0,Q.jsxs)(`div`,{className:f(`relative`,n),children:[(0,Q.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:f(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,Q.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:u}),(0,Q.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,Q.jsx)(k,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,Q.jsx)(me,{className:f(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,dt.createPortal)((0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,Q.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,Q.jsxs)(`div`,{className:f(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,Q.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 end-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,Q.jsx)(H,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,Q.jsxs)(`div`,{className:`absolute top-2 start-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,Q.jsx)(O,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,Q.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,Q.jsx)(`img`,{src:l(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:u})}),(0,Q.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,Q.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,Q.jsx)(oe,{className:`h-3 w-3`}),e.model]}),e.description&&(0,Q.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,Q.jsxs)(`div`,{className:`mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,Q.jsx)(B,{className:`h-2.5 w-2.5 text-gray-400`}),(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,Q.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,Q.jsx)(G,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,Q.jsx)(O,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},Yn=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Z.useRef)(null),[o,c]=(0,Z.useState)(!1),l=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){F.error(`File ${o.name} is not an image`);continue}if(o.size>10485760){F.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&F.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),c(!0)},d=e=>{e.preventDefault(),c(!1)},p=e=>{e.preventDefault(),c(!1),l(e.dataTransfer.files)},m=n=>{t(e.filter((e,t)=>t!==n))},h=e.length<n;return(0,Q.jsxs)(`div`,{className:f(`space-y-3`,r),children:[h&&(0,Q.jsxs)(`div`,{className:f(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:u,onDragLeave:d,onDrop:p,children:[(0,Q.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,Q.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,Q.jsx)(V,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,Q.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,Q.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,Q.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,Q.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>m(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,Q.jsx)(H,{className:`h-4 w-4`})})})]},t))}),h&&e.length>0&&(0,Q.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,Q.jsx)(De,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},Xn=K(`pages:chat-page`),Zn=(e,t,n=!1)=>{let r=new Date().getHours(),i=e?`${n?`،`:`,`} \u2068${e}\u2069`:``;return r>=5&&r<12?{id:`time`,title:`${t?t(`chat.greeting.morning`):`Good morning`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=12&&r<17?{id:`time`,title:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=17&&r<21?{id:`time`,title:`${t?t(`chat.greeting.evening`):`Good evening`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}:{id:`time`,title:`${t?t(`chat.greeting.night`):`Good night`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}},Qn=(e,t,n,r=!1)=>{let i=Ue(e);return i===`time`?Zn(t,n,r):{id:i,title:n?n(`chat.welcome.variety.${i}.title`):`What should we make?`,subtitle:n?n(`chat.welcome.variety.${i}.subtitle`):`Start with a thought, a sketch, or a stubborn problem.`}},$n=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),l=o(),{currentSession:u,sessions:d,models:m,selectedModel:v,selectedProviderType:x,selectedProviderId:S,setSelectedModel:C,createSession:E,setCurrentSession:D,loadSessions:O,getCurrentPersona:k}=w(),{user:A}=Be(),j=Ve(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:ee,stopGeneration:te,regenerateLastMessage:M,editAndResendMessage:N,selectBranch:ne,isStreaming:P,streamingMessage:ie,streamingThinking:oe,streamingMessageId:ce,toolActivities:le}=$e(u?.id||``),I=k(),L=(0,Z.useMemo)(()=>({model:v,providerType:x,providerId:S}),[v,S,x]),de=(0,Z.useMemo)(()=>_(m,L),[m,L]),fe=v?g(de,L):``,R=b(m,L),z=new URLSearchParams(l.search).get(`incognito`)===`1`,[pe,B]=(0,Z.useState)(He),[V,me]=(0,Z.useState)(null),[_e,ve]=(0,Z.useState)(!1),H=Ve(e=>e.preferences.showFollowUpSuggestions!==!1),ye=(0,Z.useRef)(null),U=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{let e=u?.id,t=U.current&&!P;if(U.current=P,!e||P||!H||u?.isPrivate||!t)return;let n=u.messages[u.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||ye.current===n.id)return;ye.current=n.id;let r=!1;return ke.generateFollowUps(e).then(t=>{r||!t.success||w.getState().currentSession?.id===e&&me({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[P,u,H]);let xe=V&&V.sessionId===u?.id?V.suggestions:[],Se=(0,Z.useMemo)(()=>Qn(pe,A?.username,e,p(t.language)),[t.language,e,A?.username,pe]),[W,Ce]=(0,Z.useState)(``),[G,we]=(0,Z.useState)([]),[Te,Ee]=(0,Z.useState)(!1),[De,Oe]=(0,Z.useState)(!1),[K,Ae]=(0,Z.useState)(!1),Me=(0,Z.useRef)(null),Ne=w(e=>e.draftSessionSettings),Fe=w(e=>e.setDraftSessionSettings),Ie=Ne.generationOptions?.think,Le=Ve(e=>(v?e.preferences.modelGenerationOptions?.[v]?.think:void 0)??e.preferences.generationOptions?.think??null),q=(0,Z.useMemo)(()=>m.find(e=>e.name===v),[m,v]),[Ue,Ke]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!v||m.length===0||!q||q.isPlugin||q.isAgent)return;let e=!1;return Pe.getModelDefaults(v).then(t=>{e||!t.success||!t.data||Ke({model:v,supported:t.data.supportsThinking})}).catch(()=>{}),()=>{e=!0}},[v,q,m.length]);let qe=!!(v&&!q?.isAgent&&(q?.isPlugin?q.reasoningSupport!==!1:Ue?.model!==v||Ue.supported!==!1)),Je=e=>{let t=w.getState().draftSessionSettings,n={...t.generationOptions};e===null?delete n.think:n.think=e,Fe({...t,generationOptions:Object.keys(n).length?n:void 0})},Ye=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){Ae(!0);try{let t=await ze.uploadDocument(n);t.success?(F.success(e(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):F.error(t.error||e(`chat.input.menu.attachFailed`))}catch(t){Xn.error(`Document upload failed:`,t),F.error(e(`chat.input.menu.attachFailed`))}finally{Ae(!1)}}};(0,Z.useEffect)(()=>{let e=!1;return je.getConfig().then(t=>{!e&&t.success&&t.data&&Ee(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[Xe,Y]=(0,Z.useState)(!1),Ze=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{let e=()=>{B(He())};return window.addEventListener(We,e),()=>window.removeEventListener(We,e)},[]);let[Qe,et]=(0,Z.useState)(!1),tt=j&&Qe,nt=(0,Z.useCallback)((t=!0)=>{let n=v?L:m[0]?T(m[0]):null;if(!n||!b(m,n))return t&&F.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return D({id:`private-${r}`,title:e(`chat.session.incognito`,`Incognito Chat`),model:n.model,providerType:n.providerType,providerId:n.providerId,messages:[],createdAt:r,updatedAt:r,isPrivate:!0}),!0},[m,v,L,D,e]);(0,Z.useEffect)(()=>{d.length===0&&O()},[O,d.length]),(0,Z.useEffect)(()=>{!z||u?.isPrivate||nt(!1)},[u?.isPrivate,z,nt]),(0,Z.useEffect)(()=>{let e=!1;return j&&(async()=>{try{let t=await Re.getPlugins();if(e)return;et(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;et(!1)}})(),()=>{e=!0}},[j]),(0,Z.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!(u?.isPrivate&&!n)&&d.length!==0)if(n){let e=d.find(e=>e.id===n);e&&e.id!==u?.id?D(e):e||(Xn.warn(`Session ${n} not found for current user, redirecting...`),d.length>0?r(`/c/${d[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&d.length>0&&l.pathname===`/`&&r(`/c/${d[0].id}`,{replace:!0})})()},[n,d,D,r,u?.id,u?.isPrivate,l.pathname]),(0,Z.useEffect)(()=>{if(u?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{ee(t.content,t.images,void 0,t.webSearch===!0)},100)}catch(e){Xn.error(`Failed to parse pending message:`,e)}}}},[u?.id,ee]),(0,Z.useEffect)(()=>{let e=Ze.current;e&&(e.style.height=`auto`,e.style.height=W?`${Math.min(e.scrollHeight,200)}px`:``)},[W]);let it=async t=>{if(t.preventDefault(),!W.trim()||!v)return;if(!R){F.error(e(`chat.model.selectBeforeSending`));return}Ge(`impact`);let n={content:W.trim(),images:G.length>0?G:void 0,webSearch:Te&&De?!0:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),Ce(``),we([]),Oe(!1);let i=await E(v,void 0,v.startsWith(`persona:`)?v.slice(8):void 0,x,S);i&&(await at(i),r(`/c/${i.id}`,{replace:!0}))},at=(0,Z.useCallback)(async e=>{let t=w.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions;if(!n&&!r)return;let i=n?[{id:c(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await ke.updateSession(e.id,{messages:i,settings:r?{generationOptions:r}:void 0});if(t.success&&t.data){let e=t.data;w.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){Xn.error(`Failed to apply chat settings to the new session`,e)}finally{w.getState().setDraftSessionSettings({})}},[]),ot=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),it(e))},st=async e=>{let t=y(de,e.target.value);t&&C(t.model,t.providerType,t.providerId)},X=(e,t,n,r)=>{u&&(Ge(`impact`),me(null),ee(e,t,n,r))};if(!u){let t=G.length>0;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`relative h-full min-w-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,Q.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,Q.jsx)(`div`,{className:`absolute left-[12%] top-[18%] h-56 w-56 rounded-full bg-primary-500/[0.035] blur-3xl dark:bg-primary-400/[0.04]`}),(0,Q.jsx)(`div`,{className:`absolute bottom-[16%] right-[10%] h-72 w-72 rounded-full bg-gray-900/[0.025] blur-3xl dark:bg-white/[0.025]`}),(0,Q.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,Q.jsx)(`button`,{onClick:()=>ve(e=>!e),className:f(`absolute end-4 top-4 z-10 flex h-9 w-9 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-6 sm:top-6`,_e&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":_e,children:(0,Q.jsx)(he,{className:`h-4 w-4`})}),(0,Q.jsxs)(`button`,{onClick:()=>nt(),disabled:!v&&m.length===0||!!v&&!R,className:`absolute end-[3.75rem] top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-surface/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-[4.25rem] sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,Q.jsx)(re,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{children:e(`chat.session.incognito`,`Incognito Chat`)})]}),(0,Q.jsxs)(`div`,{className:`relative z-[1] mx-auto flex min-h-full w-full max-w-3xl flex-col items-center justify-center`,children:[(0,Q.jsxs)(`div`,{className:`mb-8 flex flex-col items-center text-center animate-fade-in sm:mb-10`,"aria-live":`polite`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center justify-center gap-3`,children:[(0,Q.jsx)(rt,{size:`sm`,label:null,className:`h-9 w-9 shrink-0 p-0 text-ink`}),(0,Q.jsx)(`h1`,{className:`max-w-3xl text-balance text-[clamp(1.75rem,3.5vw,2.35rem)] font-medium leading-tight tracking-[-0.02em] text-ink rtl:tracking-normal`,children:Se.title})]}),(0,Q.jsx)(`p`,{className:`max-w-xl text-balance text-[15px] leading-relaxed text-ink-subtle`,children:Se.subtitle})]},Se.id),de.length>0?(0,Q.jsxs)(`div`,{className:`w-full`,children:[Xe&&(0,Q.jsxs)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:[(0,Q.jsx)(Yn,{images:G,onImagesChange:we,maxImages:5}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 border-t border-black/[0.06] pt-3 dark:border-white/[0.07]`,children:[(0,Q.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:e(`chat.input.menu.attachDocument`)}),(0,Q.jsxs)(J,{type:`button`,size:`sm`,variant:`outline`,disabled:K,onClick:()=>Me.current?.click(),className:`shrink-0 whitespace-nowrap`,children:[(0,Q.jsx)(ue,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`ms-1.5`,children:e(K?`documents.uploading`:`chat.input.menu.attach`)})]}),(0,Q.jsx)(`input`,{ref:Me,type:`file`,accept:`.pdf,.txt`,className:`hidden`,onChange:e=>void Ye(e)})]})]}),(0,Q.jsx)(`form`,{onSubmit:it,children:(0,Q.jsxs)(`div`,{className:f(`rounded-[24px] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200`,`border-black/[0.08] bg-surface dark:border-white/[0.09] dark:bg-surface-subtle`,`shadow-lv2 focus-within:shadow-lv3`),children:[(0,Q.jsx)(bn,{ref:Ze,value:W,onChange:e=>Ce(e.target.value),onKeyDown:ot,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 block w-full min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-2 !pt-1.5 !pb-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Y(!Xe),className:f(`h-9 w-9 !p-0 rounded-full flex-shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,Xe&&`bg-hover-solid text-ink`),title:e(`chat.input.attachImages`),children:t?(0,Q.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,Q.jsx)(ue,{className:`h-4 w-4`}),(0,Q.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):Xe?(0,Q.jsx)(be,{className:`h-4 w-4`}):(0,Q.jsx)(se,{className:`h-4 w-4`})}),qe&&(0,Q.jsx)(On,{value:Ie,inheritedValue:Le,onChange:Je}),Te&&(0,Q.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Oe(e=>!e),className:f(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,De&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:e(De?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":De,children:(0,Q.jsx)(ae,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,Q.jsx)(`div`,{className:`hidden sm:block`,children:(0,Q.jsx)(ut,{models:de,selectedModel:fe,onModelChange:st,getModelValue:h,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:tt})}),(0,Q.jsx)(J,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!W.trim()||!v||!R,className:f(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-primary-500 text-white hover:bg-primary-400`,`disabled:bg-primary-300/50 disabled:text-white/80 dark:disabled:bg-primary-800/60 dark:disabled:text-white/40 disabled:hover:bg-primary-300/50 dark:disabled:hover:bg-primary-800/60`,`transition-colors duration-150 touch-manipulation`),title:e(`chat.input.sendMessage`),children:(0,Q.jsx)(ge,{className:`h-4 w-4`})})]})]})}),(0,Q.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,Q.jsx)(ut,{models:de,selectedModel:fe,onModelChange:st,getModelValue:h,className:`w-full`,compact:!0,showImageGen:tt})}),(0,Q.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,Q.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,Q.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.07] bg-surface/70 p-6 backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/70`,children:[(0,Q.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,Q.jsx)(`code`,{className:`block rounded-xl bg-gray-100 p-3 font-mono text-xs text-gray-800 dark:bg-dark-300 dark:text-dark-700`,children:e(`chat.model.pullCommand`)})]})})]})]}),(0,Q.jsx)(Un,{draftModel:v,open:_e,onClose:()=>ve(!1)})]})}return(0,Q.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:I?.background?{backgroundImage:`url(${I.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[I?.background&&(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,Q.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[u?.isPrivate&&(0,Q.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,Q.jsx)(re,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,Q.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),I&&!u?.isPrivate&&(0,Q.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,Q.jsx)(Jn,{persona:I,onClear:()=>{u&&ke.updateSession(u.id,{model:I.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);w.setState(t=>({sessions:t.sessions.map(t=>t.id===u.id?e.data:t),currentSession:e.data}))}).catch(t=>{Xn.error(`Failed to remove persona:`,t),F.error(e(`chat.persona.removeFailed`))})}})}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`button`,{onClick:()=>ve(e=>!e),className:f(`absolute end-3 top-3 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950`,_e&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":_e,children:(0,Q.jsx)(he,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(vn,{messages:u.messages,streamingMessage:ie,streamingThinking:oe,streamingMessageId:ce,isStreaming:P,toolActivities:le,onRegenerate:M,onSelectBranch:ne,onEditResend:N,followUpSuggestions:xe,onFollowUpSelect:e=>X(e),className:`flex-1`}),(0,Q.jsx)(Bn,{onSendMessage:X,onStopGeneration:te,disabled:!u})]}),u&&(0,Q.jsx)(qn,{session:u}),(0,Q.jsx)(Un,{session:u,open:_e,onClose:()=>ve(!1)})]})]})]})};export{$n as ChatPage,$n as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./useTranslation-Bho4HCyg.js";import{An as i,Cn as a,Et as o,Ut as s,Wt as c,Xt as l,dn as u,gt as d,k as f,l as p,p as m,t as h}from"./ui-vendor-54SgntkX.js";import{t as g}from"./logger-DSXjF4ye.js";import{D as _}from"./api-DUUxxx_B.js";import{n as v}from"./authStore-BckFDL70.js";import{g as y,h as b,i as x,n as S,r as C}from"../assets/index-BlTbxYPP.js";var w=e(t(),1),T=n(),E=g(`components:first-time-setup`),D=({onComplete:e})=>{let{t}=r(),[n,g]=(0,w.useState)(`welcome`),[D,O]=(0,w.useState)(``),[k,ee]=(0,w.useState)(``),[A,j]=(0,w.useState)(``),[M,N]=(0,w.useState)(!1),[P,F]=(0,w.useState)(!1),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(null),[B,V]=(0,w.useState)(!1),[H,U]=(0,w.useState)(!1),[W,G]=(0,w.useState)(``),{login:K,systemInfo:q}=v(),J=q?.turnstile?.siteKey,Y=!!(q?.turnstile?.enabled&&J),X=(0,w.useCallback)(e=>{G(e)},[]),Z=(0,w.useMemo)(()=>I||Y&&!W,[I,Y,W]);(0,w.useEffect)(()=>{n===`encryption-key`&&!R&&_.getEncryptionKey().then(e=>{e.success&&e.data&&z(e.data.encryptionKey)})},[n,R]);let Q=async e=>{if(e.preventDefault(),!D.trim()||!k.trim()||!A.trim()){i.error(t(`setup.admin.fillAllFields`));return}if(k!==A){i.error(t(`auth.signup.passwordMismatch`));return}let n=C(k);if(n){i.error(n);return}if(Y&&!W){i.error(t(`auth.signup.tryAgain`));return}L(!0);try{let e=await _.signup({username:D,password:k,email:``,turnstileToken:W});if(e.success&&e.data){if(!(`token`in e.data)){i.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}K(e.data.user,e.data.token,e.data.systemInfo),i.success(t(`setup.admin.success`)),g(`encryption-key`)}else i.error(e.message||t(`setup.admin.failed`))}catch(e){E.error(`Admin creation error:`,e),i.error(t(`setup.admin.failed`))}finally{G(``),L(!1)}},te=async()=>{if(R)try{await navigator.clipboard.writeText(R),V(!0),i.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>V(!1),3e3)}catch{i.error(t(`setup.encryptionKey.copyFailed`))}},ne=()=>{if(!H){i.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]})}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,T.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(f,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(h,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,T.jsx)(`button`,{onClick:()=>g(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,T.jsx)(a,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,T.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsx)(d,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,T.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,T.jsx)(m,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,T.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,T.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,T.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,T.jsxs)(`div`,{className:`mb-6`,children:[(0,T.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:R||t(`setup.encryptionKey.loading`)}),(0,T.jsx)(`button`,{type:`button`,onClick:te,disabled:!R,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:B?(0,T.jsx)(u,{className:`h-5 w-5 text-green-500`}):(0,T.jsx)(l,{className:`h-5 w-5`})})]}),(0,T.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,T.jsx)(`div`,{className:`mb-6`,children:(0,T.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>U(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,T.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,T.jsx)(`button`,{onClick:ne,disabled:!H,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,T.jsx)(a,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,T.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,T.jsx)(`input`,{id:`username`,type:`text`,value:D,onChange:e=>O(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:I})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`password`,type:M?`text`:`password`,value:k,onChange:e=>ee(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:I}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:M?(0,T.jsx)(c,{size:20}):(0,T.jsx)(s,{size:20})})]}),(0,T.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:S})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`confirmPassword`,type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:I}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:P?(0,T.jsx)(c,{size:20}):(0,T.jsx)(s,{size:20})})]})]}),Y&&J&&(0,T.jsx)(x,{siteKey:J,action:`signup`,disabled:I,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:X}),(0,T.jsxs)(`div`,{className:`flex gap-3`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>g(`welcome`),disabled:I,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,T.jsx)(`button`,{type:`submit`,disabled:Z,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:I?(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(p,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,T.jsx)(`div`,{className:`mt-6 text-center`,children:(0,T.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{D as FirstTimeSetup};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./useTranslation-Bho4HCyg.js";import{$t as i,A as a,An as o,Kt as s,Ln as c,Ot as l,_n as u,l as d,m as f,qt as p,t as m,vt as h}from"./ui-vendor-B1UgO3vd.js";import{t as g}from"./logger-DSXjF4ye.js";import{k as _}from"./api-BDtqBtqw.js";import{n as v}from"./authStore-DbMdvNgJ.js";import{i as y,n as b,r as x,v as S,y as C}from"../assets/index-6o-Hc2wS.js";var w=e(t(),1),T=n(),E=g(`components:first-time-setup`),D=({onComplete:e})=>{let{t}=r(),[n,g]=(0,w.useState)(`welcome`),[D,O]=(0,w.useState)(``),[k,ee]=(0,w.useState)(``),[A,j]=(0,w.useState)(``),[M,N]=(0,w.useState)(!1),[P,F]=(0,w.useState)(!1),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(null),[B,V]=(0,w.useState)(!1),[H,U]=(0,w.useState)(!1),[W,G]=(0,w.useState)(``),{login:K,systemInfo:q}=v(),J=q?.turnstile?.siteKey,Y=!!(q?.turnstile?.enabled&&J),X=(0,w.useCallback)(e=>{G(e)},[]),Z=(0,w.useMemo)(()=>I||Y&&!W,[I,Y,W]);(0,w.useEffect)(()=>{n===`encryption-key`&&!R&&_.getEncryptionKey().then(e=>{e.success&&e.data&&z(e.data.encryptionKey)})},[n,R]);let Q=async e=>{if(e.preventDefault(),!D.trim()||!k.trim()||!A.trim()){c.error(t(`setup.admin.fillAllFields`));return}if(k!==A){c.error(t(`auth.signup.passwordMismatch`));return}let n=x(k);if(n){c.error(n);return}if(Y&&!W){c.error(t(`auth.signup.tryAgain`));return}L(!0);try{let e=await _.signup({username:D,password:k,email:``,turnstileToken:W});if(e.success&&e.data){if(!(`token`in e.data)){c.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}K(e.data.user,e.data.token,e.data.systemInfo),c.success(t(`setup.admin.success`)),g(`encryption-key`)}else c.error(e.message||t(`setup.admin.failed`))}catch(e){E.error(`Admin creation error:`,e),c.error(t(`setup.admin.failed`))}finally{G(``),L(!1)}},te=async()=>{if(R)try{await navigator.clipboard.writeText(R),V(!0),c.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>V(!1),3e3)}catch{c.error(t(`setup.encryptionKey.copyFailed`))}},ne=()=>{if(!H){c.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(S,{size:`md`,label:null}),(0,T.jsx)(C,{})]})}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,T.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(a,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(m,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(l,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,T.jsx)(`button`,{onClick:()=>g(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,T.jsx)(o,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(S,{size:`md`,label:null}),(0,T.jsx)(C,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,T.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsx)(h,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,T.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,T.jsx)(f,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,T.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,T.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,T.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,T.jsxs)(`div`,{className:`mb-6`,children:[(0,T.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:R||t(`setup.encryptionKey.loading`)}),(0,T.jsx)(`button`,{type:`button`,onClick:te,disabled:!R,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:B?(0,T.jsx)(u,{className:`h-5 w-5 text-green-500`}):(0,T.jsx)(i,{className:`h-5 w-5`})})]}),(0,T.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,T.jsx)(`div`,{className:`mb-6`,children:(0,T.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>U(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,T.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,T.jsx)(`button`,{onClick:ne,disabled:!H,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,T.jsx)(o,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,T.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(S,{size:`md`,label:null}),(0,T.jsx)(C,{})]}),(0,T.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,T.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,T.jsx)(`input`,{id:`username`,type:`text`,value:D,onChange:e=>O(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:I})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`password`,type:M?`text`:`password`,value:k,onChange:e=>ee(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:I}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:M?(0,T.jsx)(p,{size:20}):(0,T.jsx)(s,{size:20})})]}),(0,T.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:b})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`confirmPassword`,type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:I}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:P?(0,T.jsx)(p,{size:20}):(0,T.jsx)(s,{size:20})})]})]}),Y&&J&&(0,T.jsx)(y,{siteKey:J,action:`signup`,disabled:I,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:X}),(0,T.jsxs)(`div`,{className:`flex gap-3`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>g(`welcome`),disabled:I,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,T.jsx)(`button`,{type:`submit`,disabled:Z,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:I?(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(d,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,T.jsx)(`div`,{className:`mt-6 text-center`,children:(0,T.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{D as FirstTimeSetup};