libre-webui 0.31.0 → 0.33.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/backend/dist/index.d.ts.map +1 -1
  2. package/backend/dist/index.js +6 -1
  3. package/backend/dist/index.js.map +1 -1
  4. package/backend/dist/middleware/staticAssets.d.ts +29 -0
  5. package/backend/dist/middleware/staticAssets.d.ts.map +1 -0
  6. package/backend/dist/middleware/staticAssets.js +141 -0
  7. package/backend/dist/middleware/staticAssets.js.map +1 -0
  8. package/backend/dist/routes/artifacts.d.ts.map +1 -1
  9. package/backend/dist/routes/artifacts.js +4 -2
  10. package/backend/dist/routes/artifacts.js.map +1 -1
  11. package/backend/dist/routes/plugins.d.ts.map +1 -1
  12. package/backend/dist/routes/plugins.js +13 -2
  13. package/backend/dist/routes/plugins.js.map +1 -1
  14. package/backend/dist/routes/preferences.d.ts.map +1 -1
  15. package/backend/dist/routes/preferences.js +40 -1
  16. package/backend/dist/routes/preferences.js.map +1 -1
  17. package/backend/dist/services/appearanceSettingsService.d.ts +20 -0
  18. package/backend/dist/services/appearanceSettingsService.d.ts.map +1 -0
  19. package/backend/dist/services/appearanceSettingsService.js +91 -0
  20. package/backend/dist/services/appearanceSettingsService.js.map +1 -0
  21. package/backend/dist/services/authService.d.ts +3 -0
  22. package/backend/dist/services/authService.d.ts.map +1 -1
  23. package/backend/dist/services/authService.js +2 -0
  24. package/backend/dist/services/authService.js.map +1 -1
  25. package/backend/dist/services/ollamaSettingsService.d.ts.map +1 -1
  26. package/backend/dist/services/ollamaSettingsService.js +7 -2
  27. package/backend/dist/services/ollamaSettingsService.js.map +1 -1
  28. package/backend/dist/services/preferencesService.d.ts +5 -0
  29. package/backend/dist/services/preferencesService.d.ts.map +1 -1
  30. package/backend/dist/services/preferencesService.js +15 -2
  31. package/backend/dist/services/preferencesService.js.map +1 -1
  32. package/backend/dist/services/workPreviewProxyService.d.ts.map +1 -1
  33. package/backend/dist/services/workPreviewProxyService.js +4 -2
  34. package/backend/dist/services/workPreviewProxyService.js.map +1 -1
  35. package/backend/dist/types/index.d.ts +1 -1
  36. package/backend/dist/types/index.d.ts.map +1 -1
  37. package/backend/package.json +1 -1
  38. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  39. package/frontend/dist/assets/index-DegYzMyw.js +70 -0
  40. package/frontend/dist/assets/index-gKj8Y1JB.css +1 -0
  41. package/frontend/dist/assets/xterm-B8QFf3JU.css +1 -0
  42. package/frontend/dist/index.html +62 -40
  43. package/frontend/dist/js/ArtifactContainer-BB6A8cT5.js +1 -0
  44. package/frontend/dist/js/{ArtifactDemoPage-BLF8Ok-o.js → ArtifactDemoPage-Bf1dW5Z3.js} +1 -1
  45. package/frontend/dist/js/{ArtifactSandboxFrame-Cs1Gu1WB.js → ArtifactSandboxFrame-DsZW0Axy.js} +1 -1
  46. package/frontend/dist/js/ArtifactSlideOutPanel-Cartcixp.js +1 -0
  47. package/frontend/dist/js/AutomationModal-BI_3nFeg.js +1 -0
  48. package/frontend/dist/js/AutomationsPage-ChMXj4UG.js +1 -0
  49. package/frontend/dist/js/AvatarUpload-gfZ9QWR3.js +1 -0
  50. package/frontend/dist/js/Button-BQ5JnUVj.js +1 -0
  51. package/frontend/dist/js/CalendarPage-Ce1ud5St.js +1 -0
  52. package/frontend/dist/js/ChannelsPage-kl8zJ2HA.js +1 -0
  53. package/frontend/dist/js/ChatPage-Bj98c6rc.js +14 -0
  54. package/frontend/dist/js/ConnectModels-CPftHmE3.js +1 -0
  55. package/frontend/dist/js/{EvaluationsPage-DOJLpauA.js → EvaluationsPage-Cydglp6R.js} +2 -2
  56. package/frontend/dist/js/FirstTimeSetup-C5cc-bc9.js +1 -0
  57. package/frontend/dist/js/GalleryPage-Dvq2GVoH.js +1 -0
  58. package/frontend/dist/js/HomePage-zVjADRoX.js +1 -0
  59. package/frontend/dist/js/LibreClawPage-x0Qmtcnc.js +1 -0
  60. package/frontend/dist/js/Logo-BlcOFpac.js +1 -0
  61. package/frontend/dist/js/LogoMark-CNeQ6eO9.js +1 -0
  62. package/frontend/dist/js/ModelManagerModals-K1oiXMTv.js +1 -0
  63. package/frontend/dist/js/NotesPage-BnqBv-n1.js +3 -0
  64. package/frontend/dist/js/OptimizedSyntaxHighlighter-CtQ_FGCX.js +2 -0
  65. package/frontend/dist/js/OptimizedSyntaxHighlighter-SkJc7ZMe.js +1 -0
  66. package/frontend/dist/js/PasswordStrengthMeter-DVFLKG_-.js +1 -0
  67. package/frontend/dist/js/{PersonasPage-C3D_6lIx.js → PersonasPage-DK9-SDZQ.js} +2 -2
  68. package/frontend/dist/js/PluginUsagePage-DX9uxdRr.js +1 -0
  69. package/frontend/dist/js/RichMessageContent-BzfhfzQ4.js +1 -0
  70. package/frontend/dist/js/RichMessageContent-XMkRvBen.js +3 -0
  71. package/frontend/dist/js/SettingsModal-CMOwEhkG.js +19 -0
  72. package/frontend/dist/js/SettingsToggle-B7UynBmZ.js +1 -0
  73. package/frontend/dist/js/ShareDialog-CZpU1itx.js +1 -0
  74. package/frontend/dist/js/SystemPage-BVaaKTRs.js +1 -0
  75. package/frontend/dist/js/TurnstileWidget-CEJst9eS.js +1 -0
  76. package/frontend/dist/js/UserManagementPage-DdpcN4-Q.js +1 -0
  77. package/frontend/dist/js/UserManagementPanel-BxAvybHj.js +1 -0
  78. package/frontend/dist/js/WhatsNewModal-CoFCdUpf.js +1 -0
  79. package/frontend/dist/js/WorkPage-Du6llCSU.js +7 -0
  80. package/frontend/dist/js/api-CatP45JH.js +1 -0
  81. package/frontend/dist/js/api-DQdJeQjd.js +14 -0
  82. package/frontend/dist/js/{appNavigation-DfHbXBey.js → appNavigation-DRM2Jr4r.js} +1 -1
  83. package/frontend/dist/js/appStore-BXbVcTeo.js +2 -0
  84. package/frontend/dist/js/appVersion-BUroqcki.js +1 -0
  85. package/frontend/dist/js/ar-C8Izi_rT.js +2 -0
  86. package/frontend/dist/js/authStore-DkqtNSYP.js +4 -0
  87. package/frontend/dist/js/authStore-bqAN5v4N.js +1 -0
  88. package/frontend/dist/js/axios-CYkJpKn8.js +1 -0
  89. package/frontend/dist/js/babel-CY5KOv-I.js +16 -0
  90. package/frontend/dist/js/bn-BJJgi-6Q.js +2 -0
  91. package/frontend/dist/js/chatStore-8jYk48hC.js +3 -0
  92. package/frontend/dist/js/{config-DJwXAf8i.js → config-D4dduT3C.js} +1 -1
  93. package/frontend/dist/js/cs-DheVrMUl.js +2 -0
  94. package/frontend/dist/js/da-BLszIs3a.js +2 -0
  95. package/frontend/dist/js/de-BvWdcr7T.js +2 -0
  96. package/frontend/dist/js/es-CQ8Yauda.js +2 -0
  97. package/frontend/dist/js/estree-CuT_pB8K.js +44 -0
  98. package/frontend/dist/js/{evaluationsApi-BKY-maUM.js → evaluationsApi-CBKjxZUn.js} +1 -1
  99. package/frontend/dist/js/fr-BD5h-w8z.js +2 -0
  100. package/frontend/dist/js/goober.modern-BaHbaW3_.js +1 -0
  101. package/frontend/dist/js/hi-IlRhC5IE.js +2 -0
  102. package/frontend/dist/js/html-Cdnr2qzU.js +25 -0
  103. package/frontend/dist/js/i18next-ChipS_AK.js +1 -0
  104. package/frontend/dist/js/id-DalGMQEJ.js +2 -0
  105. package/frontend/dist/js/is-DuQqmHeS.js +2 -0
  106. package/frontend/dist/js/it-DDaqAdB1.js +2 -0
  107. package/frontend/dist/js/ja-CYCu9F9Y.js +2 -0
  108. package/frontend/dist/js/ko-P3JZPOXE.js +2 -0
  109. package/frontend/dist/js/logger-DnuT4jgB.js +1 -0
  110. package/frontend/dist/js/markdown-CByV-4CU.js +70 -0
  111. package/frontend/dist/js/markdown-core-D067gSd8.js +31 -0
  112. package/frontend/dist/js/markdown-html-CQM6wA9G.js +2 -0
  113. package/frontend/dist/js/markdown-math-Dg-WB9ui.js +261 -0
  114. package/frontend/dist/js/markdownHtml-Djpz4yB3.js +1 -0
  115. package/frontend/dist/js/markdownMath-CoDj1i7z.js +1 -0
  116. package/frontend/dist/js/{messageCodeStyles-CkxF6yil.js → messageCodeStyles-0_YpQDk4.js} +2 -2
  117. package/frontend/dist/js/ms-B3ZIqlUn.js +2 -0
  118. package/frontend/dist/js/nl-1Qpsmmz1.js +2 -0
  119. package/frontend/dist/js/pl-ErrMri3_.js +2 -0
  120. package/frontend/dist/js/postcss-CifRAFe1.js +62 -0
  121. package/frontend/dist/js/pt-0T0R9AtX.js +2 -0
  122. package/frontend/dist/js/react-vendor-D0Ec-185.js +9 -0
  123. package/frontend/dist/js/rfb-NV_fh9Db.js +5 -0
  124. package/frontend/dist/js/router-vendor-CMbYTGdh.js +1 -0
  125. package/frontend/dist/js/ru-B34INyPg.js +2 -0
  126. package/frontend/dist/js/standalone-6z5x8CWe.js +29 -0
  127. package/frontend/dist/js/sv-BSqDwAur.js +2 -0
  128. package/frontend/dist/js/syntax-highlight-DTWfgxYh.js +7 -0
  129. package/frontend/dist/js/{teamEventStream-DUodK0-C.js → teamEventStream-RoMYo102.js} +1 -1
  130. package/frontend/dist/js/th-DK9M4-Iy.js +2 -0
  131. package/frontend/dist/js/tr-DUrkEwr1.js +2 -0
  132. package/frontend/dist/js/ttsBatching-kFVEE3Ip.js +2 -0
  133. package/frontend/dist/js/typescript-BPrdIZ70.js +22 -0
  134. package/frontend/dist/js/ui-UU79S5lB.js +2 -0
  135. package/frontend/dist/js/ui-vendor-6y6qiSk5.js +177 -0
  136. package/frontend/dist/js/uk-B5DYTi0e.js +2 -0
  137. package/frontend/dist/js/useChat-ImXXcy0q.js +10 -0
  138. package/frontend/dist/js/useDictation-eMIAncoT.js +1 -0
  139. package/frontend/dist/js/useQuery-BKulzCS7.js +1 -0
  140. package/frontend/dist/js/useTranslation-D0mJ4NnO.js +1 -0
  141. package/frontend/dist/js/{utils-nNyg0lfc.js → utils-Bn0RE9_8.js} +1 -1
  142. package/frontend/dist/js/utils-vendor-BbPbaAuC.js +9 -0
  143. package/frontend/dist/js/vi-CrtPQUIM.js +2 -0
  144. package/frontend/dist/js/workApi-BM8qVq_w.js +1 -0
  145. package/frontend/dist/js/workApi-xhF57amo.js +6 -0
  146. package/frontend/dist/js/xterm-C3BHN0de.js +16 -0
  147. package/frontend/dist/js/yaml-9ltHPDNO.js +154 -0
  148. package/frontend/dist/js/zh-gbOKajYe.js +2 -0
  149. package/frontend/dist/sw.js +3 -3
  150. package/package.json +2 -2
  151. package/frontend/dist/assets/index-B6xMZpzA.js +0 -76
  152. package/frontend/dist/assets/index-BjipfsCP.css +0 -1
  153. package/frontend/dist/assets/xterm-DHcfr8qj.css +0 -1
  154. package/frontend/dist/js/ArtifactContainer-Bn6iJtaJ.js +0 -1
  155. package/frontend/dist/js/ArtifactSlideOutPanel-CuKq5cL0.js +0 -1
  156. package/frontend/dist/js/AutomationModal-Dha4KgLI.js +0 -1
  157. package/frontend/dist/js/AutomationsPage-HcMCRV-D.js +0 -1
  158. package/frontend/dist/js/AvatarUpload-CFrlSszY.js +0 -1
  159. package/frontend/dist/js/Button-CgN11mgY.js +0 -1
  160. package/frontend/dist/js/CalendarPage-D_K-XrG9.js +0 -1
  161. package/frontend/dist/js/ChannelsPage-D3CoImOT.js +0 -1
  162. package/frontend/dist/js/ChatPage-C0iBDbOq.js +0 -14
  163. package/frontend/dist/js/ConnectModels-D_ZbZQub.js +0 -1
  164. package/frontend/dist/js/FirstTimeSetup-DDIP_4Dd.js +0 -1
  165. package/frontend/dist/js/GalleryPage-C8U_F7Ns.js +0 -1
  166. package/frontend/dist/js/HomePage-B_aotoDU.js +0 -1
  167. package/frontend/dist/js/LibreClawPage-cr2N6W00.js +0 -1
  168. package/frontend/dist/js/Logo-B7o7eaPU.js +0 -1
  169. package/frontend/dist/js/LogoMark-D9g6ls0h.js +0 -1
  170. package/frontend/dist/js/ModelManagerModals-C-J1d7GL.js +0 -1
  171. package/frontend/dist/js/NotesPage-Bgr7R_Vm.js +0 -3
  172. package/frontend/dist/js/OptimizedSyntaxHighlighter-BwKLuOu-.js +0 -1
  173. package/frontend/dist/js/OptimizedSyntaxHighlighter-oiyvxgDA.js +0 -1
  174. package/frontend/dist/js/PasswordStrengthMeter-DR-mGbLF.js +0 -1
  175. package/frontend/dist/js/PluginUsagePage-DK7MgSiu.js +0 -1
  176. package/frontend/dist/js/RichMessageContent-7FxrZ4A8.js +0 -1
  177. package/frontend/dist/js/RichMessageContent-CQkLI7Dt.js +0 -3
  178. package/frontend/dist/js/SettingsModal-CIV_Bgsf.js +0 -19
  179. package/frontend/dist/js/SettingsToggle-Cw4OhW7B.js +0 -1
  180. package/frontend/dist/js/ShareDialog-BCEVgtbN.js +0 -1
  181. package/frontend/dist/js/SystemPage-BNVZtLe9.js +0 -1
  182. package/frontend/dist/js/TurnstileWidget-lyEp7A0r.js +0 -1
  183. package/frontend/dist/js/UserManagementPage-pPC_Svj9.js +0 -1
  184. package/frontend/dist/js/WorkPage-Q33nIqkM.js +0 -7
  185. package/frontend/dist/js/api-D-5hpGht.js +0 -14
  186. package/frontend/dist/js/api-WR1CTYO5.js +0 -1
  187. package/frontend/dist/js/appStore-B136FGdu.js +0 -2
  188. package/frontend/dist/js/appVersion-Ck7dYiHe.js +0 -1
  189. package/frontend/dist/js/ar-Cq-nC6v9.js +0 -2
  190. package/frontend/dist/js/authStore-6AJLgQsD.js +0 -1
  191. package/frontend/dist/js/authStore-Ckz37pwu.js +0 -4
  192. package/frontend/dist/js/axios-CUerAKcc.js +0 -1
  193. package/frontend/dist/js/babel-8afoxhZ7.js +0 -16
  194. package/frontend/dist/js/bn-BFSKytYs.js +0 -2
  195. package/frontend/dist/js/chatStore-Dpm3g_Ln.js +0 -3
  196. package/frontend/dist/js/classPrivateMethodInitSpec-DE0XIqc_.js +0 -1
  197. package/frontend/dist/js/cs-BKWXa629.js +0 -2
  198. package/frontend/dist/js/da-Cra_DJnV.js +0 -2
  199. package/frontend/dist/js/de-BQa6_UuE.js +0 -2
  200. package/frontend/dist/js/es-BBOHFrx1.js +0 -2
  201. package/frontend/dist/js/estree-qxY7ACbu.js +0 -44
  202. package/frontend/dist/js/fr-C8kXs5c0.js +0 -2
  203. package/frontend/dist/js/hi-BEef4bjU.js +0 -2
  204. package/frontend/dist/js/html-B_cUU1Gi.js +0 -25
  205. package/frontend/dist/js/i18next-ChNMiFef.js +0 -1
  206. package/frontend/dist/js/id-Djipic7Y.js +0 -2
  207. package/frontend/dist/js/is-pazl6RLG.js +0 -2
  208. package/frontend/dist/js/it-DobPbTwl.js +0 -2
  209. package/frontend/dist/js/ja-DwYNaMNX.js +0 -2
  210. package/frontend/dist/js/ko-BQfXE7_o.js +0 -2
  211. package/frontend/dist/js/logger-CpCQz3Vi.js +0 -1
  212. package/frontend/dist/js/markdown-BAF0w-jL.js +0 -70
  213. package/frontend/dist/js/markdown-core-CsTEqgp1.js +0 -32
  214. package/frontend/dist/js/markdown-math-BhUmos36.js +0 -261
  215. package/frontend/dist/js/ms-CkPQoE5T.js +0 -2
  216. package/frontend/dist/js/nl-X_QsDAtu.js +0 -2
  217. package/frontend/dist/js/pl-CK39gUsy.js +0 -2
  218. package/frontend/dist/js/postcss-B2vYq4-H.js +0 -62
  219. package/frontend/dist/js/pt-C0dWyR_I.js +0 -2
  220. package/frontend/dist/js/react-vendor-BsJBHRYW.js +0 -9
  221. package/frontend/dist/js/rfb-BOfFBtVG.js +0 -5
  222. package/frontend/dist/js/router-vendor-CIwPu612.js +0 -1
  223. package/frontend/dist/js/ru-sNJkEz1G.js +0 -2
  224. package/frontend/dist/js/standalone-BqZmfuRy.js +0 -29
  225. package/frontend/dist/js/sv-Bh-uxdF3.js +0 -2
  226. package/frontend/dist/js/syntax-highlight-DY6Hwrri.js +0 -8
  227. package/frontend/dist/js/th-DPVtwZj2.js +0 -2
  228. package/frontend/dist/js/tr-BYNM_Tm7.js +0 -2
  229. package/frontend/dist/js/ttsBatching-7_-p2nxR.js +0 -2
  230. package/frontend/dist/js/typescript-DokwN-5Y.js +0 -22
  231. package/frontend/dist/js/ui-BK53RPmS.js +0 -2
  232. package/frontend/dist/js/ui-vendor-CPdYrKhz.js +0 -177
  233. package/frontend/dist/js/uk-kvNBuYin.js +0 -2
  234. package/frontend/dist/js/useChat-Czg2p4Rr.js +0 -10
  235. package/frontend/dist/js/useDictation-B2lYEYKn.js +0 -1
  236. package/frontend/dist/js/useQuery-ClAiNxQ7.js +0 -1
  237. package/frontend/dist/js/useTranslation-C7GwbUQA.js +0 -1
  238. package/frontend/dist/js/utils-vendor-CeUf_ngc.js +0 -9
  239. package/frontend/dist/js/vi-CmLoaP0K.js +0 -2
  240. package/frontend/dist/js/workApi-BoJb9aVF.js +0 -1
  241. package/frontend/dist/js/workApi-CFH097y5.js +0 -6
  242. package/frontend/dist/js/xterm-CdjKCQM7.js +0 -16
  243. package/frontend/dist/js/yaml-BXEpxPn2.js +0 -154
  244. package/frontend/dist/js/zh-D2zvmvrj.js +0 -2
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{f as r}from"./router-vendor-CIwPu612.js";import{t as i}from"./useTranslation-C7GwbUQA.js";import{r as a,t as o}from"./utils-nNyg0lfc.js";import{t as s}from"./chatStore-Dpm3g_Ln.js";import{In as c,J as l,Ln as u,Nt as d,Q as f,Rn as p,Sn as m,it as h,ot as g,t as _,tt as ee,v as te,yr as v}from"./ui-vendor-CPdYrKhz.js";import{t as y}from"./logger-CpCQz3Vi.js";import{T as b}from"./api-D-5hpGht.js";import{t as x}from"./Button-CgN11mgY.js";import"./ui-BK53RPmS.js";import{n as S,t as C}from"./AutomationModal-Dha4KgLI.js";var w=e(t(),1),T=n();function E({days:e,locale:t}){let{t:n}=i(),r=e.reduce((e,t)=>e+t.succeeded,0),a=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,T.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,T.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,T.jsx)(`p`,{className:`text-[12px] font-medium text-gray-700 dark:text-dark-700`,children:n(`automations.runHistory`)}),(0,T.jsxs)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:[(0,T.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[r,` `,n(`automations.succeeded`)]}),` · `,(0,T.jsxs)(`span`,{className:`text-red-500 dark:text-red-400`,children:[a,` `,n(`automations.failed`)]})]})]}),(0,T.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,T.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,T.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,T.jsx)(`div`,{className:`w-full bg-emerald-500/80`,style:{height:r-i}}),i>0&&(0,T.jsx)(`div`,{className:`w-full bg-red-500/80`,style:{height:i}})]},t)})})]})}var D=[{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}]}],O=y(`pages:automations`),k=()=>{let{t:e,i18n:t}=i(),n=r(),y=s(e=>e.models),k=s(e=>e.loadModels),[j,M]=(0,w.useState)(`automations`),[N,P]=(0,w.useState)([]),[F,I]=(0,w.useState)([]),[L,R]=(0,w.useState)(null),[z,B]=(0,w.useState)(!0),[V,H]=(0,w.useState)(!1),[U,W]=(0,w.useState)(null),[G,K]=(0,w.useState)(null),[q,J]=(0,w.useState)(!1),[Y,X]=(0,w.useState)(null),[Z,ne]=(0,w.useState)(0),Q=(0,w.useCallback)(()=>ne(e=>e+1),[]);(0,w.useEffect)(()=>{let t=!1;return Promise.all([b.getAutomations(),b.getRuns(),b.getRunsSummary()]).then(([e,n,r])=>{t||(e.success&&e.data&&P(e.data),n.success&&n.data&&I(n.data),r.success&&r.data&&R(r.data))}).catch(n=>{t||(O.error(`Failed to load automations:`,n),v.error(e(`automations.loadFailed`)))}).finally(()=>{t||B(!1)}),()=>{t=!0}},[Z,e]),(0,w.useEffect)(()=>{y.length===0&&k({quiet:!0})},[y.length,k]),(0,w.useEffect)(()=>{j===`runs`&&b.markRunsSeen().then(()=>b.getRunsSummary()).then(e=>{e.success&&e.data&&R(e.data)}).catch(()=>void 0)},[j,F.length]);let re=()=>{W(null),K(null),H(!0)},ie=t=>{W(null),K({name:e(`automations.templates.${t.id}.name`),instructions:t.instructions,triggers:t.triggers}),H(!0)},ae=e=>{W(e),K(null),X(null),H(!0)},oe=async t=>{J(!0);try{let n=U?await b.updateAutomation(U.id,t):await b.createAutomation(t);n.success?(H(!1),Q()):v.error(n.error||e(`automations.saveFailed`))}catch(t){O.error(`Failed to save automation:`,t),v.error(e(`automations.saveFailed`))}finally{J(!1)}},$=async(t,n)=>{X(null);try{n===`pause`?await b.pauseAutomation(t.id):n===`resume`?await b.resumeAutomation(t.id):n===`run`?(await b.runAutomationNow(t.id),v.success(e(`automations.runQueued`))):await b.deleteAutomation(t.id),Q()}catch(t){O.error(`Automation ${n} failed:`,t),v.error(e(`automations.actionFailed`))}},se=e=>e.status===`succeeded`?(0,T.jsx)(p,{className:`h-4 w-4 text-emerald-500`}):e.status===`failed`?(0,T.jsx)(c,{className:`h-4 w-4 text-red-500`}):(0,T.jsx)(d,{className:`h-4 w-4 animate-spin text-gray-400`}),ce=t=>N.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`);return(0,T.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`automations-page`,children:[(0,T.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,T.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,T.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`automations.title`)}),(0,T.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,T.jsx)(`button`,{onClick:()=>M(t),"data-testid":`automations-tab-${t}`,className:o(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors`,j===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,T.jsxs)(x,{size:`sm`,onClick:re,"data-testid":`automation-new`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,T.jsx)(f,{className:`h-3.5 w-3.5`}),e(`automations.newAutomation`)]})]}),(0,T.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-4 scrollbar-thin`,children:[j===`automations`?z?null:N.length===0?(0,T.jsxs)(`div`,{className:`px-3 py-16 text-center`,children:[(0,T.jsx)(_,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,T.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:e(`automations.empty`)})]}):(0,T.jsx)(`div`,{className:`mx-auto w-full max-w-3xl space-y-2`,children:N.map(n=>(0,T.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,T.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`p`,{className:`truncate text-[14px] font-medium text-gray-900 dark:text-dark-900`,children:n.name}),(0,T.jsx)(`span`,{className:o(`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,T.jsxs)(`p`,{className:`mt-0.5 truncate text-[12px] text-gray-500 dark:text-dark-500`,children:[S(n.triggers,t.language,e),n.nextRunAt&&(0,T.jsxs)(T.Fragment,{children:[` · `,e(`automations.nextRun`,{when:new Intl.DateTimeFormat(t.language,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(n.nextRunAt)})]})]})]}),(0,T.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,T.jsx)(`button`,{onClick:()=>X(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,T.jsx)(m,{className:`h-4 w-4`})}),Y===n.id&&(0,T.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,T.jsx)(A,{icon:h,label:e(`common.edit`),onClick:()=>ae(n)}),n.status===`active`?(0,T.jsx)(A,{icon:g,label:e(`automations.pause`),onClick:()=>$(n,`pause`)}):(0,T.jsx)(A,{icon:ee,label:e(`automations.resume`),onClick:()=>$(n,`resume`)}),(0,T.jsx)(A,{icon:l,label:e(`automations.runNow`),onClick:()=>$(n,`run`)}),(0,T.jsx)(A,{icon:te,label:e(`common.delete`),destructive:!0,onClick:()=>$(n,`delete`)})]})]})]})},n.id))}):null,j===`automations`&&!z&&(0,T.jsxs)(`div`,{className:`mx-auto mt-8 w-full max-w-3xl`,children:[(0,T.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e(`automations.templatesTitle`)}),(0,T.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:D.map(n=>(0,T.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,T.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:e(`automations.templates.${n.id}.name`)}),(0,T.jsx)(`p`,{className:`mt-0.5 text-[12px] text-gray-500 dark:text-dark-500`,children:e(`automations.templates.${n.id}.description`)}),(0,T.jsx)(`p`,{className:`mt-1.5 text-[11px] text-gray-400 dark:text-dark-500`,children:S(n.triggers,t.language,e)})]},n.id))})]}),j===`runs`&&(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl space-y-4`,children:[L&&(0,T.jsx)(E,{days:L.days,locale:t.language}),F.length===0?(0,T.jsxs)(`div`,{className:`px-3 py-12 text-center`,children:[(0,T.jsx)(u,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,T.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:e(`automations.noRuns`)})]}):(0,T.jsx)(`div`,{className:`space-y-1`,"data-testid":`automation-run-list`,children:F.map(r=>(0,T.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,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`p`,{className:`truncate text-[13px] text-gray-900 dark:text-dark-900`,children:ce(r.automationId)}),(0,T.jsxs)(`p`,{className:`truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[a(r.scheduledFor,t.language),r.error&&(0,T.jsxs)(T.Fragment,{children:[` · `,(0,T.jsx)(`span`,{className:`text-red-500`,children:r.error})]})]})]}),r.sessionId&&(0,T.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.workTaskId&&(0,T.jsx)(`button`,{onClick:()=>n(`/work/${r.workTaskId}`),"data-testid":`automation-run-open-task`,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.openTask`)})]},r.id))})]})]}),(0,T.jsx)(C,{open:V,automation:U,initial:G,models:y,saving:q,onClose:()=>H(!1),onSave:e=>void oe(e)})]})};function A({icon:e,label:t,destructive:n,onClick:r}){return(0,T.jsxs)(`button`,{onClick:r,className:o(`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,T.jsx)(e,{className:`h-3.5 w-3.5`}),t]})}export{k as default};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{t as r}from"./useTranslation-C7GwbUQA.js";import{c as i,n as a,p as o,yr as s}from"./ui-vendor-CPdYrKhz.js";import{t as c}from"./logger-CpCQz3Vi.js";import{t as l}from"./Button-CgN11mgY.js";import"./ui-BK53RPmS.js";var u=e(t(),1),d=n(),f=c(`components:avatar-upload`),p=({value:e,onChange:t,className:n=``})=>{let{t:c}=r(),p=(0,u.useRef)(null),[m,h]=(0,u.useState)(!1),[g,_]=(0,u.useState)(!1),v=async e=>{if(!e.type.startsWith(`image/`)){s.error(c(`user.avatar.invalidFile`));return}if(e.size>2097152){s.error(c(`user.avatar.fileTooLarge`));return}h(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),s.success(c(`user.avatar.uploaded`))},n.onerror=()=>{s.error(c(`user.avatar.readFailed`))},n.readAsDataURL(e)}catch(e){f.error(`Failed to upload avatar:`,e),s.error(c(`user.avatar.uploadFailed`))}finally{h(!1)}},y=e=>{let t=e.target.files?.[0];t&&v(t)},b=e=>{e.preventDefault(),_(!0)},x=e=>{e.preventDefault(),_(!1)},S=e=>{e.preventDefault(),_(!1);let t=e.dataTransfer.files?.[0];t&&v(t)},C=()=>{t(``),s.success(c(`user.avatar.removed`))},w=()=>e||null;return(0,d.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:c(`user.avatar.label`)}),(0,d.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,d.jsx)(`div`,{className:`flex-shrink-0`,children:(0,d.jsx)(`div`,{className:`w-20 h-20 rounded-full overflow-hidden bg-gray-100 dark:bg-dark-200 border-2 border-gray-300 dark:border-dark-300 flex items-center justify-center`,children:w()?(0,d.jsx)(`img`,{src:w(),alt:`Avatar preview`,className:`w-full h-full object-cover`}):(0,d.jsx)(i,{className:`h-8 w-8 text-gray-400 dark:text-gray-500`})})}),(0,d.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[e?(0,d.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,d.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,d.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:c(`user.avatar.customAvatar`)}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c(`user.avatar.clickToChange`)})]}),(0,d.jsx)(l,{variant:`ghost`,size:`sm`,onClick:C,className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,d.jsx)(a,{className:`h-4 w-4`})})]}):(0,d.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors ${g?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>p.current?.click(),children:[(0,d.jsx)(o,{className:`h-8 w-8 mx-auto text-gray-400 dark:text-gray-500 mb-2`}),(0,d.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:c(`user.avatar.uploadAvatarImage`)}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-2`,children:c(`user.avatar.dragAndDrop`)}),(0,d.jsxs)(l,{variant:`outline`,size:`sm`,disabled:m,className:`mx-auto`,children:[(0,d.jsx)(o,{className:`h-4 w-4 mr-2`}),c(m?`user.avatar.uploading`:`user.avatar.chooseImage`)]})]}),(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:c(`user.avatar.enterImageUrl`)}),(0,d.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/avatar.jpg`})]})]})]}),(0,d.jsx)(`input`,{ref:p,type:`file`,accept:`image/*`,onChange:y,className:`hidden`}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:c(`user.avatar.supportedFormats`)})]})})};export{p as t};
@@ -1 +0,0 @@
1
- import"./rolldown-runtime-hePW80VL.js";import{_ as e,g as t}from"./markdown-core-CsTEqgp1.js";import{t as n}from"./utils-nNyg0lfc.js";e();var r=t(),i=({variant:e=`primary`,size:t=`md`,loading:i=!1,disabled:a,children:o,className:s,...c})=>(0,r.jsxs)(`button`,{className:n(`group relative inline-flex select-none items-center justify-center rounded-xl border font-medium tracking-[-0.01em] transition-[background-color,border-color,color,box-shadow,opacity] duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas dark:focus-visible:ring-primary-400 disabled:cursor-not-allowed disabled:opacity-40 motion-reduce:transition-none`,{primary:`border-transparent bg-ink text-ink-inverse shadow-subtle hover:opacity-90`,secondary:`border-line bg-surface-raised text-ink shadow-subtle hover:border-line-strong hover:bg-surface-subtle`,outline:`border-line bg-transparent text-ink hover:border-line-strong hover:bg-surface-subtle`,ghost:`border-transparent bg-transparent text-ink-muted shadow-none hover:bg-surface-subtle hover:text-ink`,danger:`border-transparent bg-error-600 text-white shadow-subtle hover:bg-error-700 dark:bg-error-500 dark:text-ink-inverse dark:hover:bg-error-400`}[e],{sm:`h-8 px-3 text-sm gap-1.5`,md:`h-10 px-4 text-sm gap-2`,lg:`h-11 px-5 text-base gap-2.5`}[t],s),disabled:a||i,"aria-busy":i||void 0,...c,children:[i&&(0,r.jsxs)(`svg`,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":`true`,fill:`none`,viewBox:`0 0 24 24`,children:[(0,r.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,r.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]}),o]});export{i as t};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{n as r}from"./react-vendor-BsJBHRYW.js";import{f as i}from"./router-vendor-CIwPu612.js";import{t as a}from"./useTranslation-C7GwbUQA.js";import{t as o}from"./utils-nNyg0lfc.js";import{Cn as s,Gn as c,Q as l,R as u,Wn as d,n as f,p,v as m,yr as h}from"./ui-vendor-CPdYrKhz.js";import{t as g}from"./logger-CpCQz3Vi.js";import{O as _,T as v}from"./api-D-5hpGht.js";import{t as y}from"./Button-CgN11mgY.js";import"./ui-BK53RPmS.js";import{t as b}from"./ShareDialog-BCEVgtbN.js";import{a as x,c as S,d as C,i as w,l as T,n as E,o as D,r as O,s as k,t as A,u as j}from"./calendarDates-Co3o_05Y.js";var M=e(t(),1),N=n(),P={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 F({event:e,label:t,onClick:n}){return(0,N.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`,P[e.variant??`event`],e.baseEventId&&`opacity-75`),children:t})}var I=3;function L({year:e,monthIndex:t,events:n,onDayClick:r,onEventClick:i}){let{t:s,i18n:c}=a(),l=(0,M.useMemo)(()=>O(e,t),[e,t]),u=new Date,d=(0,M.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,M.useMemo)(()=>C(c.language),[c.language]);return(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-testid":`calendar-month-grid`,children:[(0,N.jsx)(`div`,{className:`grid grid-cols-7 border-b border-black/[0.06] dark:border-white/[0.07]`,children:f.map(e=>(0,N.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,N.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=w(e,u),l=`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`,f=d.get(l)??[],p=f.length-I;return(0,N.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,N.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,N.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-0.5 overflow-hidden`,children:[f.slice(0,I).map(e=>(0,N.jsx)(F,{event:e,label:e.allDay?e.title:`${k(e.startAt,c.language)} ${e.title}`,onClick:()=>i(e)},e.id)),p>0&&(0,N.jsx)(`span`,{className:`px-1 text-[10px] text-gray-400 dark:text-dark-500`,children:s(`calendar.more`,{n:p})})]})]},l)})})]})}var R=48;function ee({anchor:e,events:t,dayCount:n=7,onDayClick:r,onEventClick:i}){let{i18n:s}=a(),c=(0,M.useMemo)(()=>n===1?[new Date(e.getFullYear(),e.getMonth(),e.getDate())]:j(e),[e,n]),l=new Date,u=(0,M.useMemo)(()=>new Intl.DateTimeFormat(s.language,{hour:`numeric`}),[s.language]),d=(0,M.useMemo)(()=>new Intl.DateTimeFormat(s.language,{weekday:`short`,day:`numeric`}),[s.language]),f=e=>t.filter(t=>t.allDay&&w(new Date(t.startAt),e)),p=e=>t.filter(t=>!t.allDay&&w(new Date(t.startAt),e));return(0,N.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto scrollbar-thin`,"data-testid":`calendar-week-grid`,children:(0,N.jsxs)(`div`,{className:`grid grid-cols-[3.5rem_repeat(7,1fr)]`,children:[(0,N.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-black/[0.06] bg-surface dark:border-white/[0.07]`}),c.map(e=>(0,N.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,N.jsx)(`span`,{className:o(`block truncate text-center text-[11px] font-medium`,w(e,l)?`text-primary-600 dark:text-primary-400`:`text-gray-500 dark:text-dark-500`),children:d.format(e)}),(0,N.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:f(e).map(e=>(0,N.jsx)(F,{event:e,label:e.title,onClick:()=>i(e)},e.id))})]},e.toISOString())),Array.from({length:24},(e,t)=>(0,N.jsxs)(M.Fragment,{children:[(0,N.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,N.jsx)(`span`,{className:`relative -top-1.5`,children:t>0?u.format(new Date(2024,0,1,t)):``})}),c.map(e=>{let n=p(e).filter(e=>new Date(e.startAt).getHours()===t);return(0,N.jsx)(`div`,{onClick:()=>r(e,t),style:{height:R},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:n.map(e=>(0,N.jsx)(F,{event:e,label:`${k(e.startAt,s.language)} ${e.title}`,onClick:()=>i(e)},e.id))},`${e.toISOString()}-${t}`)})]},t))]})})}var z=r(),B=e=>!e||e.kind===`once`||e.kind===`hourly`?`none`:e.kind,V=(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}},H=`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`,U=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`;function te({open:e,event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s}){return e?(0,N.jsx)(W,{event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s},`${t?.id??`new`}:${n}`):null}function W({event:e,initialStartAt:t,calendars:n,saving:r,onClose:i,onSave:o,onDelete:s}){let{t:c}=a(),l=e?.startAt??t,[u,d]=(0,M.useState)(e?.title??``),[p,h]=(0,M.useState)(e?.notes??``),[g,_]=(0,M.useState)(S(l)),[v,y]=(0,M.useState)(e?T(l):`09:00`),[b,x]=(0,M.useState)(e?.endAt===void 0?``:T(e.endAt)),[C,w]=(0,M.useState)(e?.allDay??!1),[D,O]=(0,M.useState)(B(e?.recurrence)),[k,A]=(0,M.useState)(e?.calendarId??``),[j,P]=(0,M.useState)(e?.reminderMinutes===void 0?``:String(e.reminderMinutes)),F=()=>{if(!u.trim()||!g)return;let e=E(g,C?``:v),t=!C&&b?E(g,b):null;o({title:u.trim(),notes:p.trim()?p.trim():void 0,startAt:e,endAt:t!==null&&t>e?t:null,allDay:C,recurrence:V(D,e),calendarId:k||null,reminderMinutes:j?Number(j):null})},I=[{value:``,label:c(`calendar.reminderNone`)},{value:`5`,label:c(`calendar.reminderMinutes`,{minutes:5})},{value:`15`,label:c(`calendar.reminderMinutes`,{minutes:15})},{value:`30`,label:c(`calendar.reminderMinutes`,{minutes:30})},{value:`60`,label:c(`calendar.reminderHour`)},{value:`1440`,label:c(`calendar.reminderDay`)}],L=[{value:`none`,label:c(`calendar.repeatNone`)},{value:`daily`,label:c(`calendar.repeatDaily`)},{value:`weekly`,label:c(`calendar.repeatWeekly`)},{value:`monthly`,label:c(`calendar.repeatMonthly`)},{value:`yearly`,label:c(`calendar.repeatYearly`)}];return(0,z.createPortal)((0,N.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,N.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,N.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,N.jsx)(`h3`,{id:`calendar-event-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:c(e?`calendar.editEvent`:`calendar.newEvent`)}),(0,N.jsx)(`button`,{onClick:i,"aria-label":c(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,N.jsx)(f,{size:20,className:`text-gray-500`})})]}),(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-title`,className:U,children:c(`calendar.eventTitle`)}),(0,N.jsx)(`input`,{id:`calendar-event-title`,"data-testid":`calendar-event-title`,type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:c(`calendar.titlePlaceholder`),className:H,maxLength:200,autoFocus:!0})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-date`,className:U,children:c(`calendar.date`)}),(0,N.jsx)(`input`,{id:`calendar-event-date`,type:`date`,value:g,onChange:e=>_(e.target.value),className:H})]}),(0,N.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,N.jsxs)(`label`,{className:`flex items-center gap-2 text-[13px] text-gray-700 dark:text-dark-700`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:C,onChange:e=>w(e.target.checked),className:`h-4 w-4 rounded accent-primary-500`}),c(`calendar.allDay`)]})})]}),!C&&(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-start`,className:U,children:c(`calendar.start`)}),(0,N.jsx)(`input`,{id:`calendar-event-start`,type:`time`,value:v,onChange:e=>y(e.target.value),className:H})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-end`,className:U,children:c(`calendar.end`)}),(0,N.jsx)(`input`,{id:`calendar-event-end`,type:`time`,value:b,onChange:e=>x(e.target.value),className:H})]})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-repeat`,className:U,children:c(`calendar.repeat`)}),(0,N.jsx)(`select`,{id:`calendar-event-repeat`,value:D,onChange:e=>O(e.target.value),className:H,children:L.map(e=>(0,N.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-notes`,className:U,children:c(`calendar.notes`)}),(0,N.jsx)(`textarea`,{id:`calendar-event-notes`,value:p,onChange:e=>h(e.target.value),rows:3,className:H,maxLength:1e4})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{className:U,children:c(`calendar.calendarLabel`)}),(0,N.jsxs)(`select`,{value:k,onChange:e=>A(e.target.value),className:H,"data-testid":`calendar-event-calendar`,children:[(0,N.jsx)(`option`,{value:``,children:c(`calendar.personalCalendar`)}),n.map(e=>(0,N.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{className:U,children:c(`calendar.reminderLabel`)}),(0,N.jsx)(`select`,{value:j,onChange:e=>P(e.target.value),className:H,"data-testid":`calendar-event-reminder`,children:I.map(e=>(0,N.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[e&&s?(0,N.jsxs)(`button`,{onClick:s,"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,N.jsx)(m,{className:`h-4 w-4`}),c(`common.delete`)]}):(0,N.jsx)(`span`,{}),(0,N.jsxs)(`div`,{className:`flex gap-3`,children:[(0,N.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:c(`common.cancel`)}),(0,N.jsx)(`button`,{onClick:F,disabled:r||!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:c(r?`common.saving`:`common.save`)})]})]})]})]})}),document.body)}var G=g(`pages:calendar`),K=()=>{let{t:e,i18n:t}=a(),n=i(),[r,m]=(0,M.useState)(`month`),[g,S]=(0,M.useState)(()=>new Date),[C,w]=(0,M.useState)([]),[T,E]=(0,M.useState)([]),[O,k]=(0,M.useState)(!1),[j,P]=(0,M.useState)(null),[F,I]=(0,M.useState)(()=>Date.now()),[R,z]=(0,M.useState)(!1),[B,V]=(0,M.useState)([]),[H,U]=(0,M.useState)(``),[W,K]=(0,M.useState)(null),q=M.useRef(null),J=(0,M.useMemo)(()=>{if(r===`month`){let e=new Date(g.getFullYear(),g.getMonth(),1),t=D(e);return{from:t.getTime(),to:A(t,42).getTime()}}if(r===`day`){let e=new Date(g.getFullYear(),g.getMonth(),g.getDate());return{from:e.getTime(),to:A(e,1).getTime()}}let e=D(g);return{from:e.getTime(),to:A(e,7).getTime()}},[g,r]),[Y,ne]=(0,M.useState)(0),X=(0,M.useCallback)(()=>ne(e=>e+1),[]);(0,M.useEffect)(()=>{_.getCalendars().then(e=>{e.success&&e.data&&V(e.data)}).catch(e=>G.error(`Failed to load calendars:`,e))},[Y]),(0,M.useEffect)(()=>{let t=!1;return _.getEvents(J.from,J.to).then(e=>{t||e.success&&e.data&&w(e.data)}).catch(n=>{t||(G.error(`Failed to load calendar events:`,n),h.error(e(`calendar.loadFailed`)))}),Promise.all([v.getOccurrences(J.from,J.to),v.getRuns({from:J.from,to:J.to}),v.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}:{}});E(s)}).catch(e=>{t||G.error(`Failed to project automations onto the calendar:`,e)}),()=>{t=!0}},[J.from,J.to,Y,e]);let Z=(0,M.useMemo)(()=>[...C,...T].sort((e,t)=>e.startAt-t.startAt),[C,T]),Q=e=>{S(t=>r===`month`?new Date(t.getFullYear(),t.getMonth()+e,1):A(t,e*(r===`day`?1:7)))},$=(e,t=9)=>{P(null),I(new Date(e.getFullYear(),e.getMonth(),e.getDate(),t,0).getTime()),k(!0)},re=t=>{if(t.variant===`runSucceeded`||t.variant===`runFailed`){t.sessionId?n(`/c/${t.sessionId}`):n(`/automations`);return}if(t.variant===`automation`){n(`/automations`);return}if(t.shared&&t.shared.permission!==`write`){h(e(`calendar.sharedReadOnly`));return}if(t.baseEventId){let e=C.find(e=>e.id===t.baseEventId);P(e??t)}else P(t);k(!0)},ie=async t=>{z(!0);try{let n=j?await _.updateEvent(j.id,t):await _.createEvent(t);n.success?(k(!1),X()):h.error(n.error||e(`calendar.saveFailed`))}catch(t){G.error(`Failed to save calendar event:`,t),h.error(e(`calendar.saveFailed`))}finally{z(!1)}},ae=async()=>{if(j){z(!0);try{let t=await _.deleteEvent(j.id);t.success?(k(!1),X()):h.error(t.error||e(`calendar.deleteFailed`))}catch(t){G.error(`Failed to delete calendar event:`,t),h.error(e(`calendar.deleteFailed`))}finally{z(!1)}}},oe=r===`month`?x(g.getFullYear(),g.getMonth(),t.language):new Intl.DateTimeFormat(t.language,{month:`long`,day:`numeric`,year:`numeric`}).format(r===`day`?g:D(g)),se=async()=>{let t=H.trim();t&&((await _.createCalendar({name:t}).catch(()=>void 0))?.success?(U(``),X()):h.error(e(`calendar.calendarSaveFailed`)))},ce=async t=>{try{let e=await _.exportIcs(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`calendar.ics`,r.click(),URL.revokeObjectURL(n)}catch(t){G.error(`Failed to export the calendar:`,t),h.error(e(`calendar.exportFailed`))}},le=async t=>{try{let n=await t.text(),r=await _.importIcs(n);r.success&&r.data?(h.success(e(`calendar.importResult`,{total:r.data.imported})),X()):h.error(r.error||e(`calendar.importFailed`))}catch(t){G.error(`Failed to import the calendar:`,t),h.error(e(`calendar.importFailed`))}};return(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`calendar-page`,children:[(0,N.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,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`calendar.title`)}),(0,N.jsx)(`span`,{className:`text-sm text-gray-500 dark:text-dark-500`,"data-testid":`calendar-range-label`,children:oe})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/[0.04] p-0.5 dark:bg-white/[0.06]`,children:[`month`,`week`,`day`].map(t=>(0,N.jsx)(`button`,{onClick:()=>m(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,N.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>Q(-1),className:`h-7 w-7 p-0`,title:e(`calendar.previous`),children:(0,N.jsx)(c,{className:`h-4 w-4`})}),(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>S(new Date),className:`h-7 px-2 text-[12px]`,children:e(`calendar.today`)}),(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>Q(1),className:`h-7 w-7 p-0`,title:e(`calendar.next`),children:(0,N.jsx)(d,{className:`h-4 w-4`})})]}),(0,N.jsxs)(y,{size:`sm`,onClick:()=>$(g),"data-testid":`calendar-new-event`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,N.jsx)(l,{className:`h-3.5 w-3.5`}),e(`calendar.newEvent`)]})]})]}),(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 border-b border-black/[0.06] px-4 py-2 dark:border-white/[0.07]`,children:[B.map(t=>(0,N.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-black/[0.08] px-2.5 py-1 text-xs text-gray-700 dark:border-white/[0.1] dark:text-dark-800`,"data-testid":`calendar-chip`,children:[(0,N.jsx)(`span`,{className:`h-2 w-2 rounded-full`,style:{backgroundColor:t.color??`#8b8b8b`}}),t.name,t.shared?(0,N.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:e(`calendar.sharedBadge`)}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{onClick:()=>K(t),className:`text-gray-400 hover:text-primary-500 dark:text-dark-500`,title:e(`calendar.shareCalendar`),"data-testid":`calendar-share`,children:(0,N.jsx)(u,{className:`h-3 w-3`})}),(0,N.jsx)(`button`,{onClick:()=>void _.deleteCalendar(t.id).then(X),className:`text-gray-400 hover:text-red-500 dark:text-dark-500`,title:e(`common.delete`),children:(0,N.jsx)(f,{className:`h-3 w-3`})})]})]},t.id)),(0,N.jsx)(`input`,{type:`text`,value:H,onChange:e=>U(e.target.value),onKeyDown:e=>{e.key===`Enter`&&se()},placeholder:e(`calendar.newCalendarPlaceholder`),className:`w-36 rounded-full border border-dashed border-black/[0.12] bg-transparent px-2.5 py-1 text-xs text-gray-700 placeholder:text-gray-400 focus:outline-none dark:border-white/[0.16] dark:text-dark-800`,"data-testid":`calendar-new-calendar`}),(0,N.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,N.jsx)(`input`,{ref:q,type:`file`,accept:`.ics,text/calendar`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&le(t),e.target.value=``}}),(0,N.jsxs)(y,{size:`sm`,variant:`ghost`,onClick:()=>q.current?.click(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-import`,children:[(0,N.jsx)(p,{className:`h-3.5 w-3.5`}),e(`calendar.importIcs`)]}),(0,N.jsxs)(y,{size:`sm`,variant:`ghost`,onClick:()=>void ce(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-export`,children:[(0,N.jsx)(s,{className:`h-3.5 w-3.5`}),e(`calendar.exportIcs`)]})]})]}),r===`month`?(0,N.jsx)(L,{year:g.getFullYear(),monthIndex:g.getMonth(),events:Z,onDayClick:e=>$(e),onEventClick:re}):(0,N.jsx)(ee,{anchor:g,events:Z,dayCount:r===`day`?1:7,onDayClick:(e,t)=>$(e,t),onEventClick:re}),W&&(0,N.jsx)(b,{resourceType:`calendar`,resourceId:W.id,resourceLabel:W.name,onClose:()=>K(null)}),(0,N.jsx)(te,{open:O,event:j,initialStartAt:F,calendars:B.filter(e=>!e.shared||e.shared.permission===`write`),saving:R,onClose:()=>k(!1),onSave:e=>void ie(e),onDelete:()=>void ae()})]})};export{K as default};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{i as r}from"./router-vendor-CIwPu612.js";import{t as i}from"./useTranslation-C7GwbUQA.js";import{r as a,t as o}from"./utils-nNyg0lfc.js";import{t as s}from"./chatStore-Dpm3g_Ln.js";import{B as c,Et as l,Gt as u,H as d,Nt as f,On as p,Q as m,Tt as ee,_n as te,fr as ne,ir as re,it as ie,jt as h,n as g,nt as ae,qn as _,s as v,st as y,v as oe,yr as b}from"./ui-vendor-CPdYrKhz.js";import{t as se}from"./logger-CpCQz3Vi.js";import{D as x}from"./api-D-5hpGht.js";import{t as ce}from"./authStore-Ckz37pwu.js";import{t as S}from"./Button-CgN11mgY.js";import{i as C,n as w,r as T}from"./ui-BK53RPmS.js";import{t as le}from"./teamEventStream-DUodK0-C.js";var E=e(t(),1),D=n(),O=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],k=({message:e,currentUserId:t,canModerate:n,actions:r,compact:s=!1})=>{let{t:c,i18n:l}=i(),[u,d]=(0,E.useState)(!1),[p,m]=(0,E.useState)(e.content),[ne,h]=(0,E.useState)(!1),v=e.authorKind===`model`,b=!v&&e.author?.userId===t&&!e.deleted,se=v?e.model??c(`channels.modelAuthor`):e.author?.username??c(`channels.unknownAuthor`);return(0,D.jsxs)(`div`,{className:o(`group relative rounded-xl px-2.5 py-1.5 hover:bg-black/[0.025] dark:hover:bg-white/[0.03]`,s&&`px-2 py-1`),"data-testid":`channel-message`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[v&&(0,D.jsx)(re,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,D.jsx)(`span`,{className:o(`shrink-0 text-[13px] font-semibold`,v?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:se}),(0,D.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:a(e.createdAt,l.language)}),e.editedAt&&!e.deleted&&(0,D.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:c(`channels.edited`)}),e.pinnedAt&&(0,D.jsx)(ae,{className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,D.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:c(`channels.deletedMessage`)}):u?(0,D.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,D.jsx)(`textarea`,{value:p,onChange:e=>m(e.target.value),rows:2,className:`min-w-0 flex-1 resize-none rounded-lg border border-black/[0.08] bg-transparent px-2 py-1 text-[13px] focus:outline-none dark:border-white/[0.1] dark:text-dark-900`,"data-testid":`channel-message-edit`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,p),d(!1)},className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,D.jsx)(_,{className:`h-3.5 w-3.5`})}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,D.jsx)(g,{className:`h-3.5 w-3.5`})})]}):(0,D.jsxs)(D.Fragment,{children:[e.pending?(0,D.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,D.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}),c(`channels.modelThinking`)]}):e.error?(0,D.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,D.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),(e.attachments?.length??0)>0&&(0,D.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,D.jsxs)(`button`,{type:`button`,onClick:()=>void r.onDownload(e.id,e.filename),className:`flex items-center gap-1.5 rounded-lg border border-black/[0.06] px-2 py-1 text-[12px] text-gray-600 hover:bg-black/[0.03] dark:border-white/[0.08] dark:text-dark-700 dark:hover:bg-white/[0.04]`,"data-testid":`channel-attachment`,children:[(0,D.jsx)(y,{className:`h-3 w-3`}),(0,D.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,D.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,D.jsxs)(`button`,{type:`button`,onClick:()=>void r.onReact(e,t.emoji,t.mine),className:o(`rounded-full border px-1.5 py-0.5 text-[11px]`,t.mine?`border-primary-400/50 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-black/[0.08] text-gray-600 hover:bg-black/[0.03] dark:border-white/[0.1] dark:text-dark-700`),"data-testid":`channel-reaction`,children:[t.emoji,` `,t.count]},t.emoji))}),!s&&(e.replyCount??0)>0&&r.onReply&&(0,D.jsxs)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`mt-1 flex items-center gap-1 text-[11px] font-medium text-primary-600 hover:underline dark:text-primary-400`,"data-testid":`channel-reply-count`,children:[(0,D.jsx)(ee,{className:`h-3 w-3`}),c(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!u&&(0,D.jsxs)(`div`,{className:`absolute -top-2.5 right-2 hidden items-center gap-0.5 rounded-lg border border-black/[0.08] bg-white px-1 py-0.5 shadow-sm group-hover:flex dark:border-white/[0.1] dark:bg-dark-50`,children:[(0,D.jsxs)(`div`,{className:`relative`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>h(e=>!e),className:`rounded p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:c(`channels.react`),"data-testid":`channel-react`,children:(0,D.jsx)(te,{className:`h-3.5 w-3.5`})}),ne&&(0,D.jsx)(`div`,{className:`absolute right-0 top-6 z-10 flex gap-0.5 rounded-lg border border-black/[0.08] bg-white p-1 shadow-md dark:border-white/[0.1] dark:bg-dark-50`,children:O.map(t=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>{let n=!!e.reactions?.find(e=>e.emoji===t)?.mine;r.onReact(e,t,n),h(!1)},className:`rounded p-0.5 text-sm hover:bg-black/[0.05] dark:hover:bg-white/[0.08]`,children:t},t))})]}),r.onReply&&!e.parentId&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`rounded p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:c(`channels.reply`),"data-testid":`channel-reply`,children:(0,D.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>void r.onPin(e),className:`rounded p-1 text-gray-400 hover:text-amber-500`,title:e.pinnedAt?c(`channels.unpin`):c(`channels.pin`),"data-testid":`channel-pin`,children:(0,D.jsx)(ae,{className:`h-3.5 w-3.5`})}),b&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>{m(e.content),d(!0)},className:`rounded p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:c(`channels.edit`),"data-testid":`channel-edit`,children:(0,D.jsx)(ie,{className:`h-3.5 w-3.5`})}),(b||n)&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>void r.onDelete(e),className:`rounded p-1 text-gray-400 hover:text-red-500`,title:c(`channels.deleteMessage`),"data-testid":`channel-delete-message`,children:(0,D.jsx)(oe,{className:`h-3.5 w-3.5`})})]})]})},A=se(`pages:channels`),ue=e=>e.type===`dm`?(0,D.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,D.jsx)(h,{className:`h-3.5 w-3.5 shrink-0`}):(0,D.jsx)(u,{className:`h-3.5 w-3.5 shrink-0`}),de=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,fe=()=>{let{t:e}=i(),t=ce(e=>e.user),n=s(e=>e.models),[a,u]=(0,E.useState)([]),[te,ie]=(0,E.useState)(null),[h,_]=(0,E.useState)(!1),[oe,se]=(0,E.useState)(!0),[C,w]=(0,E.useState)(null),[T,O]=(0,E.useState)(null),[fe,j]=(0,E.useState)([]),[_e,ve]=(0,E.useState)([]),[M,N]=(0,E.useState)(null),[P,F]=(0,E.useState)(null),[ye,I]=(0,E.useState)([]),[L,R]=(0,E.useState)(``),[z,be]=(0,E.useState)(``),[B,xe]=(0,E.useState)(!1),[V,H]=(0,E.useState)(null),[Se,U]=(0,E.useState)(!1),[Ce,we]=(0,E.useState)(!1),[W,Te]=(0,E.useState)(``),[Ee,G]=(0,E.useState)(!1),De=(0,E.useRef)(null),Oe=(0,E.useRef)(null),[ke,Ae]=r(),K=(0,E.useMemo)(()=>a.find(e=>e.id===C)??null,[a,C]),[je,Me]=(0,E.useState)(null);C!==je&&(Me(C),O(null),F(null),N(null));let q=K?.role===`owner`,J=(0,E.useCallback)(()=>{x.listMine().then(e=>{e.success&&e.data&&u(e.data)}).catch(e=>A.error(`Failed to load channels:`,e)).finally(()=>se(!1))},[]);(0,E.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=ke.get(`channel`);Y&&C!==Y&&w(Y),(0,E.useEffect)(()=>{Y&&Ae({},{replace:!0})},[Y,Ae]);let X=(0,E.useCallback)(e=>{x.listMessages(e,{limit:100}).then(e=>{e.success&&e.data&&O(e.data)}).catch(e=>A.error(`Failed to load messages:`,e))},[]),Ne=(0,E.useRef)(null);(0,E.useEffect)(()=>{Ne.current=P},[P]);let Pe=(0,E.useCallback)(e=>{X(e),x.markRead(e);let t=Ne.current;t&&x.thread(t).then(e=>{e.success&&e.data&&I(e.data)})},[X]);(0,E.useEffect)(()=>{if(!C)return;X(C),x.markRead(C).then(J);let e=new AbortController;return le({path:`/channels/${C}/events`,signal:e.signal,onEvent:()=>Pe(C)}),()=>e.abort()},[C,X,J,Pe]);let Fe=T?.length??0;(0,E.useEffect)(()=>{let e=Oe.current;e&&(e.scrollTop=e.scrollHeight)},[Fe,C]),(0,E.useEffect)(()=>{!C||!M||(M===`members`?x.listMembers(C).then(e=>{e.success&&e.data&&j(e.data)}):x.listPins(C).then(e=>{e.success&&e.data&&ve(e.data)}))},[C,M]),(0,E.useEffect)(()=>{P&&x.thread(P).then(e=>{e.success&&e.data&&I(e.data)})},[P]);let Ie=()=>{_(!0),x.listPublic().then(e=>{e.success&&e.data&&ie(e.data)})},Z=async t=>{if(!C||B)return;let n=L.trim();if(!(!n&&!V)){xe(!0);try{let r=await x.postMessage(C,{content:n,...t?{parentId:t}:{},...V?{attachmentIds:[V.id]}:{},...z?{mentionModel:z}:{}});if(r.success){if(R(``),H(null),be(``),X(C),t){let e=await x.thread(t);e.success&&e.data&&I(e.data)}}else b.error(r.error||e(`channels.sendFailed`))}catch(t){A.error(`Failed to send message:`,t),b.error(e(`channels.sendFailed`))}finally{xe(!1)}}},Le=async t=>{if(C)try{let n=await x.uploadAttachment(C,t);n.success&&n.data?H({id:n.data.id,filename:n.data.filename}):b.error(n.error||e(`channels.uploadFailed`))}catch(t){A.error(`Failed to upload attachment:`,t),b.error(e(`channels.uploadFailed`))}},Re=async()=>{if(!(!C||!W.trim())){if((await x.addMember(C,W.trim()).catch(()=>void 0))?.success){Te(``);let t=await x.listMembers(C);t.success&&t.data&&j(t.data),b.success(e(`channels.memberAdded`))}else b.error(e(`channels.memberAddFailed`))}},Q={onReply:e=>F(e.id),onEdit:async(e,t)=>{(await x.editMessage(e.id,t).catch(()=>void 0))?.success&&C&&X(C)},onDelete:async e=>{(await x.deleteMessage(e.id).catch(()=>void 0))?.success&&C&&X(C)},onPin:async e=>{await x.setPinned(e.id,!e.pinnedAt).catch(()=>void 0),C&&X(C)},onReact:async(e,t,n)=>{n?await x.removeReaction(e.id,t).catch(()=>void 0):await x.addReaction(e.id,t).catch(()=>void 0),C&&X(C)},onDownload:async(e,t)=>{try{let n=await x.downloadAttachment(e),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}catch(e){A.error(`Failed to download attachment:`,e)}}},$=ye[0];return(0,D.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,D.jsxs)(`aside`,{className:o(`flex w-64 shrink-0 flex-col border-r border-black/[0.06] dark:border-white/[0.06]`,C?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-1 px-3 py-2.5`,children:[(0,D.jsx)(`h1`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`channels.title`)}),(0,D.jsx)(`button`,{type:`button`,onClick:Ie,title:e(`channels.browsePublic`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channels-browse`,children:(0,D.jsx)(p,{className:`h-4 w-4`})}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>we(!0),title:e(`channels.newDm`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channels-new-dm`,children:(0,D.jsx)(l,{className:`h-4 w-4`})}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>U(!0),title:e(`channels.newChannel`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channels-new`,children:(0,D.jsx)(m,{className:`h-4 w-4`})})]}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:oe?(0,D.jsx)(f,{className:`mx-auto mt-6 h-4 w-4 animate-spin text-gray-400`}):a.length===0?(0,D.jsx)(`p`,{className:`px-2 pt-6 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.empty`)}):a.map(e=>(0,D.jsxs)(`button`,{type:`button`,onClick:()=>w(e.id),className:o(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[13px]`,C===e.id?`bg-black/[0.05] text-gray-900 dark:bg-white/[0.08] dark:text-dark-900`:`text-gray-600 hover:bg-black/[0.03] dark:text-dark-700 dark:hover:bg-white/[0.04]`),"data-testid":`channel-item`,children:[ue(e),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:de(e)}),(e.unreadCount??0)>0&&(0,D.jsx)(`span`,{className:`rounded-full bg-primary-500 px-1.5 text-[10px] font-semibold leading-4 text-white`,"data-testid":`channel-unread`,children:e.unreadCount})]},e.id))})]}),(0,D.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-black/[0.06] px-4 py-2.5 dark:border-white/[0.06]`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>w(null),className:`rounded-md p-1 text-gray-500 hover:bg-black/[0.04] md:hidden dark:text-dark-600`,children:(0,D.jsx)(ne,{className:`h-4 w-4`})}),ue(K),(0,D.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,"data-testid":`channel-title`,children:de(K)}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>N(M===`pins`?null:`pins`),title:e(`channels.pins`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channel-pins-toggle`,children:(0,D.jsx)(ae,{className:`h-4 w-4`})}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>N(M===`members`?null:`members`),title:e(`channels.members`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channel-members-toggle`,children:(0,D.jsx)(v,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>G(!0),title:e(`channels.settings`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channel-settings`,children:(0,D.jsx)(c,{className:`h-4 w-4`})})]}),(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,D.jsx)(`div`,{ref:Oe,className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-4 py-3 scrollbar-thin`,"data-testid":`channel-timeline`,children:T===null?(0,D.jsx)(f,{className:`mx-auto mt-6 h-4 w-4 animate-spin text-gray-400`}):T.length===0?(0,D.jsx)(`p`,{className:`pt-8 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noMessages`)}):T.map(e=>(0,D.jsx)(k,{message:e,currentUserId:t?.id,canModerate:q,actions:Q},e.id))}),(0,D.jsxs)(`div`,{className:`border-t border-black/[0.06] p-3 dark:border-white/[0.06]`,children:[V&&(0,D.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-black/[0.06] px-2.5 py-1.5 text-xs text-gray-600 dark:border-white/[0.08] dark:text-dark-700`,children:[(0,D.jsx)(y,{className:`h-3.5 w-3.5`}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:V.filename}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>H(null),className:`text-gray-400 hover:text-red-500`,children:(0,D.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,D.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,D.jsx)(`input`,{ref:De,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Le(t),e.target.value=``}}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>De.current?.click(),title:e(`channels.attach`),className:`rounded-md p-2 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channel-attach`,children:(0,D.jsx)(y,{className:`h-4 w-4`})}),(0,D.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(re,{className:o(`h-4 w-4`,z?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,D.jsxs)(`select`,{value:z,onChange:e=>be(e.target.value),className:`max-w-[130px] rounded-md border border-black/[0.08] bg-transparent px-1 py-1 text-[11px] text-gray-600 focus:outline-none dark:border-white/[0.1] dark:bg-dark-100 dark:text-dark-700`,title:e(`channels.askModel`),"data-testid":`channel-mention-model`,children:[(0,D.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,D.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,D.jsx)(`textarea`,{value:L,onChange:e=>R(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Z())},rows:1,placeholder:e(`channels.composerPlaceholder`),className:`max-h-32 min-w-0 flex-1 resize-none rounded-xl border border-black/[0.08] bg-transparent px-3 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.1] dark:text-dark-900`,"data-testid":`channel-composer`}),(0,D.jsx)(S,{size:`sm`,disabled:B||!L.trim()&&!V,onClick:()=>void Z(),"data-testid":`channel-send`,children:B?(0,D.jsx)(f,{className:`h-4 w-4 animate-spin`}):(0,D.jsx)(d,{className:`h-4 w-4`})})]})]})]}),P&&(0,D.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-l border-black/[0.06] dark:border-white/[0.06]`,"data-testid":`channel-thread`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/[0.06] px-3 py-2 dark:border-white/[0.06]`,children:[(0,D.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>F(null),className:`rounded-md p-1 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,D.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:ye.map(e=>(0,D.jsx)(k,{message:e,currentUserId:t?.id,canModerate:q,actions:{...Q,onReply:void 0},compact:!0},e.id))}),(0,D.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/[0.06] p-2 dark:border-white/[0.06]`,children:[(0,D.jsx)(`textarea`,{value:L,onChange:e=>R(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),$&&Z($.id))},rows:1,placeholder:e(`channels.replyPlaceholder`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/[0.08] bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 focus:outline-none dark:border-white/[0.1] dark:text-dark-900`,"data-testid":`channel-thread-composer`}),(0,D.jsx)(S,{size:`sm`,disabled:B||!L.trim(),onClick:()=>$&&void Z($.id),children:(0,D.jsx)(d,{className:`h-3.5 w-3.5`})})]})]}),M&&(0,D.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-l border-black/[0.06] dark:border-white/[0.06]`,"data-testid":`channel-${M}-panel`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/[0.06] px-3 py-2 dark:border-white/[0.06]`,children:[(0,D.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(M===`members`?`channels.members`:`channels.pins`)}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>N(null),className:`rounded-md p-1 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,D.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:M===`members`?(0,D.jsxs)(D.Fragment,{children:[q&&K.type===`private`&&(0,D.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,D.jsx)(`input`,{type:`text`,value:W,onChange:e=>Te(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Re()},placeholder:e(`channels.invitePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/[0.08] bg-transparent px-2 py-1 text-xs focus:outline-none dark:border-white/[0.1] dark:text-dark-800`,"data-testid":`channel-invite-name`}),(0,D.jsx)(S,{size:`sm`,disabled:!W.trim(),onClick:()=>void Re(),"data-testid":`channel-invite-submit`,children:(0,D.jsx)(m,{className:`h-3.5 w-3.5`})})]}),fe.map(n=>(0,D.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-700 dark:text-dark-800`,"data-testid":`channel-member`,children:[(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,D.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:n.role===`owner`?e(`channels.roleOwner`):``}),q&&n.userId!==t?.id&&K.type!==`dm`&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>void x.removeMember(K.id,n.userId).then(()=>j(e=>e.filter(e=>e.userId!==n.userId))),className:`rounded p-0.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:e(`channels.removeMember`),children:(0,D.jsx)(g,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,D.jsx)(S,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:()=>void x.removeMember(K.id,t?.id??``).then(()=>{w(null),J()}),"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):_e.length===0?(0,D.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):_e.map(e=>(0,D.jsx)(k,{message:e,currentUserId:t?.id,canModerate:q,actions:Q,compact:!0},e.id))})]})]})]}):(0,D.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 text-gray-400 dark:text-dark-500`,children:[(0,D.jsx)(ee,{className:`h-8 w-8`}),(0,D.jsx)(`p`,{className:`text-sm`,children:e(`channels.selectPrompt`)})]})}),Se&&(0,D.jsx)(pe,{onClose:()=>U(!1),onCreated:e=>{U(!1),J(),w(e.id)}}),Ce&&(0,D.jsx)(me,{onClose:()=>we(!1),onOpened:e=>{we(!1),J(),w(e.id)}}),h&&(0,D.jsx)(he,{channels:te,onClose:()=>_(!1),onJoined:e=>{_(!1),J(),w(e)}}),Ee&&K&&(0,D.jsx)(ge,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),w(null),J()}})]})},pe=({onClose:e,onCreated:t})=>{let{t:n}=i(),[r,a]=(0,E.useState)(``),[o,s]=(0,E.useState)(`public`),[c,l]=(0,E.useState)(``),[u,d]=(0,E.useState)(!1);return(0,D.jsxs)(w,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,D.jsx)(S,{size:`sm`,disabled:u||!r.trim(),onClick:()=>{d(!0),x.create({type:o,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):b.error(e.error||n(`channels.createFailed`))}).catch(()=>b.error(n(`channels.createFailed`))).finally(()=>d(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:C,children:n(`channels.nameLabel`)}),(0,D.jsx)(`input`,{className:T,value:r,onChange:e=>a(e.target.value),"data-testid":`create-channel-name`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:C,children:n(`channels.typeLabel`)}),(0,D.jsxs)(`select`,{className:T,value:o,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,D.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,D.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:C,children:n(`channels.descriptionLabel`)}),(0,D.jsx)(`textarea`,{className:T,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},me=({onClose:e,onOpened:t})=>{let{t:n}=i(),[r,a]=(0,E.useState)(``),[o,s]=(0,E.useState)(!1),c=()=>{r.trim()&&(s(!0),x.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):b.error(e.error||n(`channels.dmFailed`))}).catch(()=>b.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,D.jsx)(w,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,D.jsx)(S,{size:`sm`,disabled:o||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,D.jsx)(`input`,{className:T,value:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},he=({channels:e,onClose:t,onJoined:n})=>{let{t:r}=i();return(0,D.jsx)(w,{titleId:`browse-channels-title`,title:r(`channels.browsePublic`),onClose:t,testId:`browse-channels-modal`,children:e===null?(0,D.jsx)(f,{className:`mx-auto h-4 w-4 animate-spin text-gray-400`}):e.length===0?(0,D.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:r(`channels.noPublic`)}):e.map(e=>(0,D.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/[0.06] px-3 py-2 dark:border-white/[0.08]`,"data-testid":`browse-channel-item`,children:[(0,D.jsx)(u,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,D.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:r(`channels.joined`)}):(0,D.jsx)(S,{size:`sm`,onClick:()=>void x.join(e.id).then(()=>n(e.id)),"data-testid":`browse-channel-join`,children:r(`channels.join`)})]},e.id))})},ge=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:a}=i(),[o,s]=(0,E.useState)(e.name),[c,l]=(0,E.useState)(e.description??``),[u,d]=(0,E.useState)(!1);return(0,D.jsxs)(w,{titleId:`channel-settings-title`,title:a(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,D.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,D.jsx)(S,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:()=>void x.delete(e.id).then(e=>{e.success&&r()}),"data-testid":`channel-delete`,children:a(`channels.delete`)}),(0,D.jsx)(S,{size:`sm`,disabled:u||!o.trim(),onClick:()=>{d(!0),x.update(e.id,{name:o.trim(),description:c.trim()}).then(e=>{e.success&&n()}).finally(()=>d(!1))},"data-testid":`channel-settings-save`,children:a(`channels.save`)})]}),children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:C,children:a(`channels.nameLabel`)}),(0,D.jsx)(`input`,{className:T,value:o,onChange:e=>s(e.target.value)})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:C,children:a(`channels.descriptionLabel`)}),(0,D.jsx)(`textarea`,{className:T,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{fe as default};
@@ -1,14 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{_ as t,g as n}from"./markdown-core-CsTEqgp1.js";import{n as r}from"./react-vendor-BsJBHRYW.js";import{d as i,f as a,g as o,p as s}from"./router-vendor-CIwPu612.js";import{t as c}from"./useTranslation-C7GwbUQA.js";import{i as l,n as u,o as d,r as f,t as p}from"./utils-nNyg0lfc.js";import{T as m,_ as h,a as g,d as _,f as v,g as y,h as b,i as x,l as S,n as C,o as w,p as T,r as E,t as D,u as O}from"./chatStore-Dpm3g_Ln.js";import{A as ee,An as k,B as A,Bt as te,E as j,En as M,F as ne,G as re,Hn as ie,Kn as N,M as P,N as F,Nt as I,Pn as ae,Q as oe,Qt as se,S as ce,St as le,U as ue,Vt as de,Wn as fe,Xt as pe,Y as me,a as he,ar as ge,at as _e,b as ve,bt as ye,c as be,dn as xe,er as Se,fn as Ce,g as L,it as R,jn as we,kn as Te,lr as Ee,m as De,n as z,nn as Oe,o as B,or as V,p as ke,pr as H,q as Ae,qn as je,r as U,st as Me,t as W,tn as Ne,tr as Pe,ur as Fe,vr as G,wn as Ie,wt as Le,xt as Re,y as ze,yr as K,z as Be}from"./ui-vendor-CPdYrKhz.js";import{t as q}from"./logger-CpCQz3Vi.js";import{N as J,S as Ve,_ as He,a as Y,d as Ue,f as We,g as Ge,i as Ke,j as qe,m as Je,n as Ye,p as Xe,t as Ze,w as Qe,y as $e}from"./api-D-5hpGht.js";import{t as et}from"./authStore-Ckz37pwu.js";import{t as tt}from"./appStore-B136FGdu.js";import{i as nt,r as rt,t as it}from"./welcomePrompts-to5mv_gx.js";import{l as at}from"./messageCodeStyles-CkxF6yil.js";import{t as X}from"./Button-CgN11mgY.js";import{_ as ot,g as st,m as Z}from"./ui-BK53RPmS.js";import{t as ct}from"./LogoMark-D9g6ls0h.js";import{a as lt,i as ut,n as dt,o as ft,r as pt}from"./useChat-Czg2p4Rr.js";import{a as mt,i as ht,o as gt,r as _t,s as vt,t as yt}from"./ttsBatching-7_-p2nxR.js";import{t as bt}from"./ConnectModels-D_ZbZQub.js";import{i as xt,n as St,r as Ct,t as wt}from"./thinking-DwlkTfPX.js";import{t as Tt}from"./ArtifactContainer-Bn6iJtaJ.js";import{t as Et}from"./evaluationsApi-BKY-maUM.js";import{n as Dt,t as Ot}from"./useDictation-B2lYEYKn.js";var kt=r(),Q=e(t(),1),$=n(),At=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},jt=({status:e})=>e===`running`||e===`awaiting_approval`?(0,$.jsx)(I,{className:`h-3.5 w-3.5 animate-spin`}):e===`succeeded`?(0,$.jsx)(je,{className:`h-3.5 w-3.5 text-green-600 dark:text-green-400`}):e===`denied`?(0,$.jsx)(z,{className:`h-3.5 w-3.5 text-amber-600 dark:text-amber-400`}):(0,$.jsx)(L,{className:`h-3.5 w-3.5 text-red-500 dark:text-red-400`}),Mt=({call:e})=>{let{t}=c(),[n,r]=(0,Q.useState)(!1),i=t(`tools.callStatus.${e.status}`);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-200 bg-gray-50 dark:bg-dark-50 text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,"aria-expanded":n,children:[n?(0,$.jsx)(N,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(fe,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,$.jsx)(U,{className:`h-3.5 w-3.5 shrink-0 text-gray-500 dark:text-gray-400`}),(0,$.jsx)(`span`,{className:`truncate font-medium text-gray-700 dark:text-gray-200`,dir:`ltr`,children:e.name}),e.serverName&&(0,$.jsx)(`span`,{className:`truncate text-xs text-gray-500 dark:text-gray-400`,children:e.serverName}),(0,$.jsxs)(`span`,{className:p(`ml-auto flex shrink-0 items-center gap-1 text-xs`,e.status===`succeeded`?`text-green-600 dark:text-green-400`:e.status===`failed`?`text-red-500 dark:text-red-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(jt,{status:e.status}),i]})]}),n&&(0,$.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 dark:border-dark-200`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.arguments`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:At(e.arguments)}),e.resultPreview!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-2 text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.result`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:e.resultPreview})]})]})]})},Nt=({calls:e,className:t})=>e.length===0?null:(0,$.jsx)(`div`,{className:p(`flex flex-col gap-1.5`,t),children:e.map(e=>(0,$.jsx)(Mt,{call:e},e.id))}),Pt=({approval:e,onDecide:t,className:n})=>{let{t:r}=c(),[i,a]=(0,Q.useState)(!1),o=(n,r)=>{a(!0),t(e.approvalId,n,r)};return(0,$.jsxs)(`div`,{role:`alertdialog`,"aria-label":r(`tools.approval.title`),className:p(`rounded-lg border border-primary-300/70 bg-primary-50 p-3 text-sm dark:border-primary-700/60 dark:bg-primary-900/20`,n),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-primary-800 dark:text-primary-200`,children:[(0,$.jsx)(ne,{className:`h-4 w-4 shrink-0`}),r(`tools.approval.title`)]}),(0,$.jsx)(`p`,{className:`mt-1 text-primary-800/90 dark:text-primary-100/80`,children:r(`tools.approval.description`,{tool:e.toolCall.name,server:e.toolCall.serverName??r(`tools.approval.builtinSource`)})}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded bg-white/70 p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:At(e.toolCall.arguments)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(X,{size:`sm`,disabled:i,onClick:()=>o(!0,`once`),children:r(`tools.approval.allowOnce`)}),(0,$.jsx)(X,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>o(!0,`session`),children:r(`tools.approval.allowSession`)}),(0,$.jsx)(X,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>o(!0,`always`),children:r(`tools.approval.allowAlways`)}),(0,$.jsx)(X,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>o(!1,`once`),children:r(`tools.approval.deny`)})]})]})},Ft=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i}=c(),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`,s=e.prompt_eval_count||0,l=e.eval_count||0,u=s+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(te,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,$.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,$.jsx)(N,{size:12}):(0,$.jsx)(fe,{size:12,className:`rtl:rotate-180`}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,s]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},It=q(`components:ttsbutton`),Lt=null,Rt=null,zt=0,Bt=3e5;async function Vt(e=!1){let t=Date.now();return!e&&Lt!==null&&t-zt<Bt?Lt:Rt||(Rt=(async()=>{try{let e=await Y.getModels();return e.success&&e.data&&e.data.length>0?(Lt=e.data,zt=t,e.data):(Lt=[],zt=t,[])}catch{return Lt=[],zt=t,[]}finally{Rt=null}})(),Rt)}var Ht=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:s}=c(),{preferences:l}=tt(),[u,d]=(0,Q.useState)(`idle`),[f,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)([]),[_,v]=(0,Q.useState)(null),y=(0,Q.useRef)(null),b=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await Vt(),n=Ye(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=vt();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=Ke(h,i?.model,i?.pluginId),c=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?_t(e,{locale:s.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=ht({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>Y.generate({model:c,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=yt(C);try{await C.play(S)}finally{w(),y.current===C&&(y.current=null)}}catch(e){if(b.current!==n)return;if(mt(e)){d(`idle`);return}if(gt(e)){d(`blocked`);return}let t=e instanceof Error?e.message:o(`ttsButton.generateFailed`);m(t),It.error(`TTS error:`,e),d(`error`)}};if((0,Q.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`,D=T===`playing`,O=T===`blocked`,ee=!!f||T===`error`,k=f||o(ee?`ttsButton.playbackFailed`:O?`ttsButton.enableAudio`:D||E?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,$.jsxs)(`button`,{onClick:S,disabled:!e,title:k,"aria-label":k,"aria-busy":E||void 0,className:p(`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`,ee?`text-red-500 dark:text-red-400`:O?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:D?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!O&&C[n],O&&n===`sm`&&`h-7`,O&&n===`md`&&`h-8`,O&&n===`lg`&&`h-10`,t),children:[E?(0,$.jsx)(I,{className:p(w[n],`animate-spin`)}):D?(0,$.jsx)(j,{className:w[n]}):ee||O?(0,$.jsx)(he,{className:w[n]}):(0,$.jsx)(B,{className:w[n]}),O&&(0,$.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},Ut=[`accuracy`,`style`,`incomplete`,`harmful`,`formatting`],Wt=q(`components:chat-message`);function Gt({role:e,user:t,persona:n,modelAvatar:r}){let[i,a]=(0,Q.useState)(null);if(e===`assistant`){if(n)return(0,$.jsx)(`img`,{src:Ge(n,64),alt:n.name,"data-testid":`chat-assistant-avatar`,onError:e=>He(e.currentTarget,n.name,64),className:`mt-0.5 h-8 w-8 shrink-0 rounded-lg object-cover`});let e=r?.trim()??``,t=e.startsWith(`data:`)&&e!==i?e:``;return(0,$.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,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>a(e)}):e?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,$.jsx)(ct,{label:null,className:`h-4 w-4`})})}let o=t?.username||`User`,s=t?.avatar?.trim()||``,c=!!s&&s!==i;return(0,$.jsx)(`div`,{role:c?void 0:`img`,"aria-label":c?void 0:o,"data-testid":`chat-user-avatar`,className:p(`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,$.jsx)(`img`,{src:s,alt:o,className:`h-full w-full object-cover`,onError:()=>a(s)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(be,{"aria-hidden":`true`,className:`h-4 w-4`})})}var Kt=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onFork:a,onEditResend:o})=>{let{t:s,i18n:l}=c(),u=e.role===`user`,m=e.role===`system`,h=m&&g(e.content),_=h?e.content.slice(C.length):e.content,{preferences:v}=tt(),{user:y}=et(),{setSystemMessage:b,getCurrentPersona:x,currentSession:S,rateMessage:w,modelMetadata:T}=D(),E=x(),O=e.model||S?.model||``,ee=O?T[O]??Object.entries(T).find(([e])=>e.slice(e.indexOf(`/`)+1)===O)?.[1]:void 0,[k,A]=(0,Q.useState)(!1),[te,j]=(0,Q.useState)(e.content),[ne,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(!1),[ae,oe]=(0,Q.useState)(!1),[ce,le]=(0,Q.useState)(!1),[ue,de]=(0,Q.useState)(`idle`),[fe,pe]=(0,Q.useState)(null),[he,ge]=(0,Q.useState)([]),[ye,be]=(0,Q.useState)(``),[xe,Ce]=(0,Q.useState)(!1),L=(0,Q.useRef)(null),R=(0,Q.useRef)(0),we=(0,Q.useRef)(t),Te=(0,Q.useRef)(!1),Ee=async()=>{try{await navigator.clipboard.writeText(e.content),at(`success`),Ce(!0),setTimeout(()=>Ce(!1),2e3)}catch(e){Wt.error(`Failed to copy message:`,e)}},{thinkingContent:Oe,thinkingStreaming:B,parsedContent:V,artifacts:ke}=(0,Q.useMemo)(()=>{if(u||m||!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}:d(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=ft(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,u,m,t]),H=B?void 0:e.statistics?.thinking_duration_ms??lt(e.id),U=(0,Q.useCallback)(async e=>{let t=R.current+1;R.current=t,L.current?.cancel(),L.current=null,de(`loading`);try{if(e){let n=await e;if(R.current!==t)return;if(n===`blocked`){de(`blocked`);return}}let n=await Y.getModels();if(R.current!==t)return;let r=n.success&&n.data?n.data:[],i=v.ttsSettings,a=Ke(r,i?.model,i?.pluginId),o=Ye(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,c=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||V.length>p?_t(V,{locale:l.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[V.trim()];if(m.length===0){de(`idle`);return}let h=ht({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>Y.generate({model:s,pluginId:c,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=>{R.current===t&&de(e)}});if(R.current!==t){h.cancel();return}L.current=h;let g=yt(h);try{await h.play(m)}finally{g(),L.current===h&&(L.current=null),R.current===t&&(h.state===`ended`||h.state===`cancelled`)&&de(`idle`)}}catch(e){if(R.current!==t)return;mt(e)?de(`idle`):gt(e)?de(`blocked`):(Wt.error(`Auto-play TTS failed:`,e),de(`error`))}},[l.language,V,v.ttsSettings]);(0,Q.useEffect)(()=>{let e=we.current&&!t;we.current=t,e&&!Te.current&&!u&&!m&&V&&v.ttsSettings?.enabled&&v.ttsSettings.autoPlay&&(Te.current=!0,U())},[t,u,m,V,v.ttsSettings?.autoPlay,v.ttsSettings?.enabled,U]),(0,Q.useEffect)(()=>()=>{R.current+=1,L.current?.cancel(),L.current=null},[]);let Me=()=>{let e=vt();U(e)},W=()=>{R.current+=1,L.current?.cancel(),L.current=null,de(`idle`)},Ne=()=>h?s(`chatMessage.conversationSummary`):m?s(`chatMessage.system`):u?v.showUsername&&y?.username?y.username:s(`chatMessage.you`):E?.name?E.name:ee?.label||O||s(`chatMessage.assistant`),Pe=()=>{A(!0),j(e.content)},[Fe,G]=(0,Q.useState)(!1),Ie=async()=>{if(!(!S||Fe)){G(!0);try{let t=await J.restoreCompaction(S.id,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;D.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){Wt.error(`Failed to restore compacted messages:`,e),K.error(s(`chatMessage.restoreFailed`))}finally{G(!1)}}},Le=async()=>{I(!0);try{b(te),A(!1),Wt.debug(`✅ System message updated:`,te)}catch(e){Wt.error(`Failed to save system message:`,e)}finally{I(!1)}},Re=()=>{A(!1),j(e.content)},q=()=>{let t=te.trim();A(!1),t&&o?.(e.id,t)},Ve=t=>{if(!S)return;let n=e.rating===t;if(w(S.id,e.id,n?void 0:t),!S.isPrivate){if(n){pe(null),Et.deleteFeedback(e.id).catch(()=>void 0);return}ge([]),be(``),pe(t===1?1:-1),Et.upsertFeedback({sessionId:S.id,messageId:e.id,rating:t===1?1:-1}).catch(()=>void 0)}},He=()=>{!S||fe===null||(Et.upsertFeedback({sessionId:S.id,messageId:e.id,rating:fe,tags:he,...ye.trim()?{comment:ye.trim()}:{}}).catch(()=>void 0),pe(null))},Ue=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,We=m&&_.length>100;return(0,$.jsxs)(`div`,{className:p(`group flex py-1.5 transition-colors sm:py-2`,u?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:p(`flex min-w-0 gap-2.5 sm:gap-3`,u?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!u&&!m&&(0,$.jsx)(Gt,{role:`assistant`,persona:E,modelAvatar:ee?.avatar}),(0,$.jsxs)(`div`,{className:p(`min-w-0 flex-1`,u?`flex flex-col items-end`:m?`py-1.5`:`py-0.5`),children:[!u&&!m&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:Ne()}),e.model&&E?.name&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,$.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:f(e.timestamp,l.language)})]}),(0,$.jsxs)(`div`,{className:p(!u&&!m&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/[0.06] bg-gray-100 dark:border-white/[0.08] dark:bg-gray-800`,children:(0,$.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>P(e)})},t))}),u?k?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/[0.08] bg-white p-2 shadow-sm dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{dir:`auto`,value:te,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),q()):e.key===`Escape`&&Re()},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-none dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(`button`,{onClick:Re,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:s(`chatMessage.cancelEditing`)}),(0,$.jsx)(`button`,{onClick:q,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:s(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{className:`rounded-2xl rounded-ee-md border border-black/[0.06] bg-gray-900 px-3.5 py-2 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):m?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[h?(0,$.jsx)(Ae,{className:`h-2.5 w-2.5 opacity-50`}):(0,$.jsx)(Be,{className:`h-2.5 w-2.5 opacity-50`}),s(h?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:h?(0,$.jsx)(`button`,{onClick:()=>void Ie(),disabled:Fe,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.restoreCompacted`),children:(0,$.jsx)(De,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):k?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:Le,disabled:F,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.saveChanges`),children:(0,$.jsx)(re,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:Re,disabled:F,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.cancelEditing`),children:(0,$.jsx)(z,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:Pe,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:s(`chatMessage.editSystemMessage`),children:(0,$.jsx)(_e,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),k?(0,$.jsx)(`textarea`,{dir:`auto`,value:te,onChange:e=>j(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:s(`chatMessage.systemMessagePlaceholder`),disabled:F}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:ae?_:Ue(_)}),We&&(0,$.jsx)(`button`,{onClick:()=>oe(!ae),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:ae?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ie,{className:`h-3 w-3`}),s(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`h-3 w-3`}),s(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(Oe||B)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{onClick:()=>le(!ce),className:`flex items-center gap-1.5 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,$.jsx)(Se,{className:p(`h-3.5 w-3.5`,B&&`animate-pulse-subtle motion-reduce:animate-none`)}),B?(0,$.jsxs)(`span`,{className:`animate-shimmer bg-gradient-to-r from-gray-400 via-gray-900 to-gray-400 bg-[length:200%_100%] bg-clip-text font-medium text-transparent motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-gray-500 dark:from-dark-500 dark:via-dark-900 dark:to-dark-500 motion-reduce:dark:text-dark-600`,children:[s(`chatMessage.thinking`),`…`]}):(0,$.jsx)(`span`,{className:`font-medium`,children:H===void 0?s(`chatMessage.thinking`):s(`chatMessage.thoughtFor`,{duration:ut(H)})}),ce?(0,$.jsx)(ie,{className:`h-3.5 w-3.5`}):(0,$.jsx)(N,{className:`h-3.5 w-3.5`})]}),ce&&Oe&&(0,$.jsx)(`div`,{dir:`auto`,className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 text-[13px] leading-relaxed text-gray-600 dark:bg-dark-200/60 dark:text-dark-700`,children:(0,$.jsx)(Z,{content:Oe,isStreaming:B,className:`text-[13px] text-gray-600 dark:text-dark-700`})})]}),(0,$.jsx)(Z,{content:V,isStreaming:t})]}),!u&&!m&&ke.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Tt,{artifacts:ke})}),!u&&!m&&Array.isArray(e.providerMetadata?.toolCalls)&&e.providerMetadata.toolCalls.length>0&&(0,$.jsx)(Nt,{calls:e.providerMetadata.toolCalls,className:`mt-2.5`}),!u&&!m&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,$.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:s(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,$.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,$.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,$.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!u&&!m&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(Ft,{statistics:e.statistics})}),!m&&!t&&(0,$.jsxs)(`div`,{className:p(`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`,!u&&[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(ue)?`sm:opacity-100`:`sm:opacity-0`,u?`mt-1 justify-end`:`mt-1`),children:[u&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:f(e.timestamp,l.language),children:[Ne(),` ·`,` `,f(e.timestamp,l.language)]}),!u&&V&&(0,$.jsx)(Ht,{text:V,size:`sm`,externalPlaybackState:ue,onStopExternal:W,onRetryExternal:Me,className:p(`transition-colors`,ue===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),u&&o&&!k&&(0,$.jsx)(`button`,{onClick:()=>{j(e.content),A(!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:s(`chatMessage.edit`),children:(0,$.jsx)(_e,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:Ee,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:s(xe?`chatMessage.copied`:`chatMessage.copyMessage`),children:xe?(0,$.jsx)(je,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(M,{className:`h-3.5 w-3.5`})}),!u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>Ve(1),className:p(`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:s(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(ze,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>Ve(-1),className:p(`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:s(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(ve,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})}),fe!==null&&(0,$.jsxs)(`div`,{className:`ml-1 flex flex-wrap items-center gap-1 rounded-lg border border-gray-200 bg-white px-2 py-1 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`feedback-details`,children:[Ut.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>ge(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:p(`rounded-full border px-2 py-0.5 text-[10px]`,he.includes(e)?`border-primary-500 bg-primary-50 text-primary-700 dark:bg-primary-950/40 dark:text-primary-300`:`border-gray-300 text-gray-500 dark:border-dark-300`),"aria-pressed":he.includes(e),children:s(`chatMessage.feedbackTags.${e}`)},e)),(0,$.jsx)(`input`,{value:ye,onChange:e=>be(e.target.value),placeholder:s(`chatMessage.feedbackComment`),className:`w-32 rounded border border-gray-300 px-1.5 py-0.5 text-[10px] dark:border-dark-300 dark:bg-dark-50`,maxLength:2e3}),(0,$.jsx)(`button`,{type:`button`,onClick:He,className:`rounded bg-gray-900 px-2 py-0.5 text-[10px] text-white dark:bg-white dark:text-gray-900`,children:s(`common.save`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>pe(null),"aria-label":s(`common.close`),className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,children:(0,$.jsx)(z,{className:`h-3 w-3`})})]})]}),!u&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:s(`chatMessage.regenerateResponse`),children:(0,$.jsx)(me,{className:`h-3.5 w-3.5`})}),a&&(0,$.jsx)(`button`,{onClick:()=>a(e.id),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:s(`chat.fork.action`),"data-testid":`fork-from-message`,children:(0,$.jsx)(se,{className:`h-3.5 w-3.5`})})]})]})]}),u&&(0,$.jsx)(Gt,{role:`user`,user:y??null})]}),ne&&(0,kt.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":s(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>P(null),children:[(0,$.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),P(null)},children:(0,$.jsx)(z,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:ne,alt:s(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},qt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Jt=220,Yt=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>Jt?`${t.slice(0,219).trimEnd()}…`:t},Xt=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=c(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[s,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),m=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;!r||!i||(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Q.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:qt()?`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===s),v=_>=0?e[_]:null,y=_>=0?`conversation-history-preview-${_}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let c=t.id===g,u=Math.abs(a-h),d=s===t.id?y:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":c?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===h?0:-1,className:p(`group flex h-4 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),m(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:p(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,c?`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,$.jsx)(`div`,{id:y,role:`tooltip`,className:p(`pointer-events-none absolute start-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:Yt(v.prompt)}),v.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:Yt(v.response)})]})})]})}),Zt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(Kt,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,$.jsxs)(`div`,{className:p(`relative py-2`,c),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(Ne,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let l=e.isActive!==!1,u=t&&i===e.id,d=u?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:p(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||u?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!u&&`cursor-pointer`),role:!l&&!u?`button`:void 0,tabIndex:!l&&!u?0:void 0,onClick:()=>!l&&!u&&s?.(e.id),onKeyDown:t=>{!l&&!u&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,$.jsxs)(`div`,{className:p(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||u?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,$.jsx)(je,{className:`h-3 w-3`}),!l&&!u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,$.jsx)(`div`,{className:p(!l&&!u&&`opacity-75`),children:(0,$.jsx)(Kt,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Qt={web_search:ue,web_fetch:pe,exec:ce,browser:pe,Read:Ce,Write:Ce,Edit:Ce,image:de,memory_search:Ie,memory_get:Ie,working:U,thinking:U,default:U},$t={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`},en=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,$.jsx)(`div`,{className:p(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Qt[e.name]||Qt.default,n=$t[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:p(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(`div`,{className:p(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};q(`components:chat-messages`);var tn=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],nn=e=>e.messages.every(e=>e.isActive===!1),rn=e=>e.role===`system`&&!g(e.content),an=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,on=e=>Math.min(120,e*.28),sn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],activeToolCalls:o,pendingToolApproval:s,onDecideToolApproval:l,className:u,onRegenerate:d,onSelectBranch:f,onEditResend:m,onFork:h,followUpSuggestions:g,onFollowUpSelect:_})=>{let{t:v}=c(),y=(0,Q.useRef)(null),b=(0,Q.useRef)(void 0),x=(0,Q.useRef)(null),S=(0,Q.useRef)(null),C=(0,Q.useRef)(new Map),w=(0,Q.useRef)(null),T=(0,Q.useRef)(0),E=(0,Q.useRef)(!1),D=(0,Q.useRef)(!1),[O,k]=(0,Q.useState)(!1),A=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>rn(e)&&!rn(t)?-1:rn(t)&&!rn(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 rn(n)&&!rn(r)?-1:rn(r)&&!rn(n)?1:n.timestamp-r.timestamp})},[e]),te=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<A.length;t++){let n=A[t],r=tn(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<A.length;e++){let t=tn(A[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},[A]),j=te.map(e=>e.id).join(``),M=(0,Q.useMemo)(()=>j?j.split(``):[],[j]),ne=(0,Q.useMemo)(()=>new Set(M),[M]),[re,ie]=(0,Q.useState)(null),N=(0,Q.useCallback)(()=>{let e=x.current;if(!e||M.length===0){ie(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(T.current,M.length-1);if(t<=2)n=M.length-1;else{let t=e.scrollTop+on(e.clientHeight);for(;n<M.length-1;){let e=C.current.get(M[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=C.current.get(M[n]);if(!e||e.offsetTop<=t)break;n--}}T.current=n;let r=M[n];ie(e=>e===r?e:r)},[M]),P=(0,Q.useCallback)(()=>{w.current===null&&(w.current=window.requestAnimationFrame(()=>{w.current=null,N()}))},[N]),F=(0,Q.useCallback)(()=>{let t=x.current;if(b.current&&clearTimeout(b.current),E.current=!1,b.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;D.current=!n,k(!n&&e.length>0),P()},[e.length,P]),I=(0,Q.useCallback)(()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(F,180)},[F]),ae=(0,Q.useCallback)((e=!1)=>{D.current&&!e||y.current?.scrollIntoView({behavior:an()})},[]),oe=(0,Q.useCallback)(()=>{let t=x.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(E.current){D.current=!0,k(!o&&e.length>0),P(),I();return}D.current=!o,k(!o&&e.length>0),a<=2&&M.length>0?(T.current=M.length-1,ie(M[M.length-1])):P()},[M,e.length,I,P]),se=(0,Q.useCallback)(e=>{let t=x.current,n=C.current.get(e);if(!t||!n)return;let r=an();E.current=!0,D.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-on(t.clientHeight)),behavior:r}),P(),r===`auto`?F():I()},[F,I,P]),ce=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>ce.current&&!D.current&&ae(),ce.current=e.length},[e.length,ae]),(0,Q.useEffect)(()=>{i&&(t||n)&&!D.current&&requestAnimationFrame(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{P();let e=S.current,t=x.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(P);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,P),()=>{n?.disconnect(),window.removeEventListener(`resize`,P)}},[j,P]),(0,Q.useEffect)(()=>()=>{w.current!==null&&(window.cancelAnimationFrame(w.current),w.current=null)},[]),(0,Q.useEffect)(()=>()=>{b.current&&clearTimeout(b.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:p(`flex-1 flex items-center justify-center p-6 sm:p-10`,u),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-surface/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(ee,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:v(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:v(`chatMessage.startConversationDescription`)})]})});let le=-1;for(let e=A.length-1;e>=0;e--)if(A[e].messages.some(e=>e.role===`assistant`)){le=e;break}return(0,$.jsxs)(`div`,{className:p(`relative min-h-0 flex-1`,u),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:x,"data-testid":`chat-scroll-viewport`,onScroll:oe,className:p(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,$.jsxs)(`div`,{ref:S,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[A.map((e,a)=>{let o=a===le,s=ne.has(e.id),c=i&&e.messages.some(e=>e.id===r),l;if(nn(e))l=(0,$.jsx)(`div`,{className:`opacity-55`,children:(0,$.jsx)(Kt,{message:tn(e),isStreaming:!1,isLastAssistantMessage:!1,className:a===0?`mt-3 sm:mt-4`:``})});else if(e.messages.length===1){let s=e.messages[0],c=i&&s.id===r,u=c?{...s,content:t??s.content,thinking:n||s.thinking}:s;l=(0,$.jsx)(Kt,{message:u,isStreaming:c,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onEditResend:i?void 0:m,onFork:i?void 0:h,className:a===0?`mt-3 sm:mt-4`:``})}else l=(0,$.jsx)(Zt,{messages:e.messages,isStreaming:c,streamingMessage:t,streamingThinking:n,streamingMessageId:r||void 0,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onSelectBranch:f,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{ref:t=>{s&&(t?C.current.set(e.id,t):C.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:l},e.id)}),i&&(o?.length??0)>0&&(0,$.jsx)(Nt,{calls:o??[],className:`pb-2`}),s&&l&&(0,$.jsx)(Pt,{approval:s,onDecide:l,className:`mb-2`}),i&&a.length>0&&(0,$.jsx)(en,{tools:a,className:`px-0`}),!i&&g&&g.length>0&&_&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:v(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:g.map(e=>(0,$.jsx)(`button`,{onClick:()=>_(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-gray-600 transition-colors hover:text-gray-900 dark:border-dark-200 dark:text-dark-600 dark:hover:text-dark-900`,children:e},e))})]}),(0,$.jsx)(`div`,{ref:y,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(Xt,{items:te,activeId:re,onSelect:se}),O&&(0,$.jsxs)(`button`,{onClick:()=>{E.current=!1,b.current&&(clearTimeout(b.current),b.current=void 0),D.current=!1,y.current?.scrollIntoView({behavior:an()}),k(!1)},className:p(`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:v(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(H,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:v(`chatMessage.newMessages`)})]})]})};function cn(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 ln=Q.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Q.useMemo)(()=>cn(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:p(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:p(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,$.jsx)(we,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});ln.displayName=`CodeAwareTextarea`;var un=q(`components:media-upload`),dn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:s}=c(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,m]=(0,Q.useState)(!1),[h,g]=(0,Q.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):K.error(s(`chat.mediaUpload.unsupportedFileType`,{name:n.name}))}},v=async r=>{if(n-e.length<=0){K.error(s(`chat.mediaUpload.maxImagesAllowed`,{count:n}));return}if(r.size>10485760){K.error(s(`chat.mediaUpload.imageTooLarge`,{name:r.name}));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){K.error(s(`documents.fileSizeTooLarge`));return}m(!0);try{let t=await qe.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;g(e=>[...e,n]),i?.(n),K.success(s(`documents.uploadSuccessWithName`,{name:e.name}))}else K.error(t.error||s(`documents.uploadFailed`))}catch(e){un.error(`Document upload error:`,e),K.error(s(`documents.uploadFailed`))}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 qe.deleteDocument(e);t.success?(g(t=>t.filter(t=>t.id!==e)),K.success(s(`documents.removeSuccess`))):K.error(t.error||s(`documents.removeFailed`))}catch(e){un.error(`Error removing document:`,e),K.error(s(`documents.removeFailed`))}},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,$.jsxs)(`div`,{className:p(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:p(`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,$.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,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(I,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,$.jsx)(ke,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[s(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:s(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:s(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),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,$.jsx)(z,{className:`h-3 w-3`})})]},`img-${t}`)),h.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(Ce,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,$.jsx)(xe,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:T(e.size)})]}),(0,$.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,$.jsx)(z,{className:`h-3 w-3`})})]},e.id))]})]})},fn=q(`components:document-indicator`),pn=({sessionId:e,className:t=``})=>{let{t:n}=c(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(null),d=(0,Q.useRef)(null),f=(0,Q.useCallback)(async()=>{try{let t=await qe.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){fn.error(`Failed to load documents:`,e)}},[e]);if((0,Q.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,Q.useEffect)(()=>{if(!a)return;let e=e=>{d.current?.contains(e.target)||(o(!1),l(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let p=async e=>{l(null);try{let t=await qe.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){fn.error(`Failed to delete document:`,e),G.error(n(`settings.documents.library.deleteFailed`))}},m=r.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{ref:d,className:`relative inline-block ${t}`,children:[a&&(0,$.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,$.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,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,$.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:s===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.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,$.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,$.jsx)(`button`,{onClick:()=>l(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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ce,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-xs text-gray-900 dark:text-dark-900`,children:e.filename}),(0,$.jsxs)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:[u(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,$.jsx)(`button`,{onClick:()=>l(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,$.jsx)(z,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),l(null)},className:`
2
- inline-flex items-center space-x-1 px-2 py-1
3
- bg-blue-50 dark:bg-blue-900/20
4
- border border-blue-200 dark:border-blue-800
5
- rounded-md text-xs
6
- transition-colors hover:bg-blue-100 dark:hover:bg-blue-900/40
7
- `,title:`${n(`chat.documents.title`)} - ${u(m)}`,children:[(0,$.jsx)(V,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,$.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[r.length,` doc`,r.length===1?``:`s`]})]})]})},mn=q(`components:structured-output`),hn=[{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`}],gn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=c(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),l=()=>hn.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,$.jsxs)(`div`,{className:p(`space-y-3`,n),children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center`,children:[(0,$.jsx)(Be,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,$.jsx)(st,{value:u().label,onChange:e=>d(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(ot,{value:o,onChange:e=>s(e.target.value),placeholder:`{
8
- "type": "object",
9
- "properties": {
10
- "field1": { "type": "string" },
11
- "field2": { "type": "number" }
12
- },
13
- "required": ["field1"]
14
- }`,rows:8,className:`font-mono text-sm`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(X,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){mn.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(X,{onClick:()=>{a(!1),s(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=u();return!e.value||e.value===`json`?null:(0,$.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,$.jsx)(k,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,$.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,$.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,$.jsx)(Ce,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},_n=({value:e,inheritedValue:t,onChange:n})=>{let{t:r}=c(),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(null),s=e??t,l=St(s),u=Ct(s),d=Ct(e),f=t==null?void 0:Ct(t);return(0,Q.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,$.jsxs)(`div`,{ref:o,className:`relative flex-shrink-0`,children:[(0,$.jsxs)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>a(e=>!e),className:p(`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,$.jsx)(Se,{className:`h-4 w-4`}),l&&(0,$.jsx)(`span`,{className:`text-[11px] font-medium`,children:r(`settings.generation.thinkingLevels.${u}`)})]}),i&&(0,$.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,$.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`)}),wt.map(e=>{let t=e===d;return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":t,onClick:()=>{n(xt(e)),a(!1)},className:p(`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,$.jsx)(`span`,{className:`truncate`,children:e==="default"&&f!==void 0?r(`settings.generation.thinkingLevels.defaultWith`,{level:r(`settings.generation.thinkingLevels.${f}`)}):r(`settings.generation.thinkingLevels.${e}`)}),t&&(0,$.jsx)(je,{className:`h-3.5 w-3.5 shrink-0`})]},e)})]})]})},vn=7,yn=2*Math.PI*vn,bn=e=>`⁨${e}⁩`,xn=({usage:e,trainedBudget:t})=>{let{t:n,i18n:r}=c(),[i,a]=(0,Q.useState)(!1),o=typeof e.budget==`number`&&e.budget>0,s=e.ratio??0,l=Math.round(s*100),u=e.measured?``:`~`,d=r.language,f=`${u}${x(e.used,d)}`,m=o?n(`chat.context.tokensUsed`,{used:bn(f),budget:bn(x(e.budget,d))}):n(`chat.context.tokensUsedNoBudget`,{used:bn(f)}),h=t===void 0?void 0:n(`chat.context.capped`,{trained:bn(x(t,d))}),g=[n(`chat.context.title`),o?n(`chat.context.full`,{percent:l}):void 0,m,h].filter(Boolean).join(` `),_=Math.min(s,1);return(0,$.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,$.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:p(`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`,s>=.8&&s<1&&`text-amber-600 dark:text-amber-400`,s>=1&&`text-red-600 dark:text-red-400`),children:(0,$.jsxs)(`svg`,{viewBox:`0 0 18 18`,className:`h-4 w-4 -rotate-90`,children:[(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:vn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`opacity-30`,...o?{}:{strokeDasharray:`2 2`}}),o&&_>0&&(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:vn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:yn,strokeDashoffset:yn*(1-_)})]})}),i&&(0,$.jsxs)(`div`,{role:`tooltip`,className:p(`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,$.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.title`)}),o&&(0,$.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.full`,{percent:l})}),(0,$.jsx)(`p`,{className:`text-[13px] tabular-nums text-gray-900 dark:text-dark-900`,children:m}),h&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:h})]})]})},Sn=q(`components:prompt-queue`),Cn=({sessionId:e,queue:t})=>{let{t:n}=c(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),s=t=>pt(e,t),l=async t=>{try{let n=await J.claimQueuedPrompt(e,t);n.success&&n.data&&s(n.data.queue)}catch(e){Sn.error(`Failed to remove queued prompt:`,e)}},u=async(n,r)=>{let i=t.findIndex(e=>e.id===n),a=i+r;if(i===-1||a<0||a>=t.length)return;let o=t.map(e=>e.id);[o[i],o[a]]=[o[a],o[i]];try{let t=await J.reorderPromptQueue(e,o);t.success&&t.data&&s(t.data.queue)}catch(e){Sn.error(`Failed to reorder the prompt queue:`,e)}},d=async t=>{let r=a.trim();if(r)try{let a=await J.updateQueuedPrompt(e,t,r);a.success&&a.data?(s(a.data.queue),i(null)):K.error(a.error||n(`chat.queue.updateFailed`))}catch(e){Sn.error(`Failed to update the queued prompt:`,e),K.error(n(`chat.queue.updateFailed`))}};return t.length===0?null:(0,$.jsxs)(`div`,{className:`mx-auto mb-1.5 w-full max-w-3xl px-1`,"data-testid":`prompt-queue`,children:[(0,$.jsxs)(`p`,{className:`mb-1 flex items-center gap-1.5 px-1 text-[11px] font-medium text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(ae,{className:`h-3 w-3`}),n(`chat.queue.title`,{total:t.length})]}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:t.map((e,s)=>(0,$.jsx)(`li`,{className:`flex items-center gap-1.5 rounded-lg border border-black/[0.06] bg-surface/70 px-2 py-1 dark:border-white/[0.08] dark:bg-dark-200/70`,"data-testid":`prompt-queue-entry`,children:r===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:t=>{t.key===`Enter`&&d(e.id),t.key===`Escape`&&i(null)},className:`min-w-0 flex-1 bg-transparent text-[13px] text-gray-900 focus:outline-none dark:text-dark-900`,"data-testid":`prompt-queue-edit-input`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void d(e.id),className:`rounded-md p-1 text-green-600 hover:bg-green-50 dark:hover:bg-green-900/20`,"aria-label":n(`common.save`),children:(0,$.jsx)(je,{className:`h-3.5 w-3.5`})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-700 dark:text-dark-800`,children:e.content}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void u(e.id,-1),disabled:s===0,className:`rounded-md p-1 text-gray-400 hover:text-gray-700 disabled:opacity-30 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`chat.queue.moveUp`),children:(0,$.jsx)(Fe,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void u(e.id,1),disabled:s===t.length-1,className:`rounded-md p-1 text-gray-400 hover:text-gray-700 disabled:opacity-30 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`chat.queue.moveDown`),children:(0,$.jsx)(H,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{i(e.id),o(e.content)},className:`rounded-md p-1 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`common.edit`),children:(0,$.jsx)(R,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void l(e.id),className:`rounded-md p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,"aria-label":n(`common.delete`),children:(0,$.jsx)(z,{className:`h-3 w-3`})})]})},e.id))})]})},wn=(e,t)=>{let n=[];for(let r of t){let t=O(e,r);t&&n.push({model:t.model,providerType:t.providerType??null,providerId:t.providerId??null})}return n},Tn=({models:e,currentModelKey:t,selectedKeys:n,onChange:r,disabled:i=!1})=>{let{t:a}=c(),[o,s]=(0,Q.useState)(!1),l=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!o)return;let e=e=>{l.current?.contains(e.target)||s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[o]);let u=e.filter(b).map(e=>({model:e,key:S(e)})).filter(e=>e.key!==t);if(u.length===0)return null;let d=e=>{n.includes(e)?r(n.filter(t=>t!==e)):n.length<3&&r([...n,e])};return(0,$.jsxs)(`div`,{className:`relative`,ref:l,children:[(0,$.jsxs)(X,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>s(e=>!e),className:p(`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`,n.length>0&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:a(`chat.compare.title`),"aria-pressed":n.length>0,"aria-expanded":o,"data-testid":`composer-compare-toggle`,children:[(0,$.jsx)(Te,{className:`h-4 w-4`}),n.length>0&&(0,$.jsxs)(`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`,children:[`+`,n.length]})]}),o&&(0,$.jsxs)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 max-h-72 w-72 overflow-y-auto rounded-xl border border-gray-200 bg-white p-2 shadow-lg scrollbar-thin dark:border-dark-200 dark:bg-dark-50`,role:`menu`,"data-testid":`composer-compare-menu`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium text-gray-400 dark:text-dark-500`,children:a(`chat.compare.hint`,{max:3})}),u.map(({model:e,key:t})=>{let r=n.includes(t),i=!r&&n.length>=3;return(0,$.jsxs)(`label`,{className:p(`flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-800 hover:bg-gray-50 dark:text-dark-800 dark:hover:bg-dark-100`,i&&`cursor-not-allowed opacity-40`),children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:r,disabled:i,onChange:()=>d(t),className:`h-3.5 w-3.5 rounded border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate`,children:e.name})]},t)})]})]})},En=`pdf.txt.text.log.md.markdown.mdx.html.htm.xhtml.docx.pptx.xlsx.csv.tsv.ts.tsx.js.jsx.mjs.cjs.py.rb.go.rs.java.kt.swift.c.h.cc.cpp.hpp.cs.php.sh.bash.zsh.sql.r.scala.lua.pl.json.yaml.yml.toml.ini.css.scss.less.xml.graphql.proto.tf.dockerfile.png.jpg.jpeg.webp.gif.wav.webm`.split(`.`).map(e=>`.${e}`).join(`,`),Dn=/^\/([a-z0-9-]*)$/,On=/(?:^|\s)\$([a-z0-9-]*)$/,kn=8,An=(e,t,n)=>e.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g,(e,r)=>{let i=t.find(e=>e.name===r);if(!i)return e;let a=n[r];return a!==void 0&&a!==``?a:i.default??``}),jn=({prompt:e,onCancel:t,onInsert:n})=>{let{t:r}=c(),[i,a]=(0,Q.useState)(()=>Object.fromEntries(e.variables.map(e=>[e.name,e.default??(e.type===`boolean`?`false`:``)]))),o=e.variables.filter(e=>e.required===!0&&(i[e.name]===void 0||i[e.name]===``));return(0,$.jsxs)(`div`,{className:`p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-gray-700 dark:text-gray-200`,children:r(`composer.variables.title`,{title:e.title})}),(0,$.jsx)(`div`,{className:`mt-2 flex max-h-56 flex-col gap-2 overflow-y-auto`,children:e.variables.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,dir:`ltr`,children:[e.label||e.name,e.required?` *`:``]}),e.type===`select`?(0,$.jsxs)(`select`,{value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`option`,{value:``,children:`—`}),(e.options??[]).map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))]}):e.type===`boolean`?(0,$.jsxs)(`select`,{value:i[e.name]??`false`,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`option`,{value:`true`,children:r(`common.yes`)}),(0,$.jsx)(`option`,{value:`false`,children:r(`common.no`)})]}):(0,$.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`})]},e.name))}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,$.jsx)(X,{size:`sm`,variant:`ghost`,onClick:t,children:r(`composer.variables.cancel`)}),(0,$.jsx)(X,{size:`sm`,disabled:o.length>0,title:o.length>0?r(`composer.variables.required`,{name:o[0]?.name??``}):void 0,onClick:()=>n(An(e.content,e.variables,i)),children:r(`composer.variables.insert`)})]})]})},Mn=(0,Q.forwardRef)(({message:e,disabled:t=!1,onApply:n},r)=>{let{t:i}=c(),[a,o]=(0,Q.useState)(null),[s,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),[f,m]=(0,Q.useState)(null),h=(0,Q.useRef)({prompts:!1,skills:!1}),g=t?null:Dn.exec(e),_=t||g?null:On.exec(e),v=g!==null,y=_!==null;(0,Q.useEffect)(()=>{!v||h.current.prompts||(h.current.prompts=!0,Xe.list().then(e=>{o(t=>e.success&&e.data?e.data:t??[])}).catch(()=>o(e=>e??[])).finally(()=>{h.current.prompts=!1}))},[v]),(0,Q.useEffect)(()=>{!y||h.current.skills||(h.current.skills=!0,We.list().then(e=>{l(t=>e.success&&e.data?e.data:t??[])}).catch(()=>l(e=>e??[])).finally(()=>{h.current.skills=!1}))},[y]);let b=(0,Q.useMemo)(()=>{if(g){let e=g[1];return(a??[]).filter(t=>t.slug.startsWith(e)).slice(0,kn).map(e=>({kind:`prompt`,key:e.id,slug:e.slug,label:e.title,detail:e.description,prompt:e}))}if(_){let e=_[1];return(s??[]).filter(t=>t.enabled&&t.slug.startsWith(e)).slice(0,kn).map(e=>({kind:`skill`,key:e.id,slug:e.slug,label:e.name,detail:e.description,skill:e}))}return[]},[g,_,a,s]),[x,S]=(0,Q.useState)(e);e!==x&&(S(e),d(0),!g&&f&&m(null));let C=t=>{let r=b[t];if(r){if(r.kind===`prompt`){if(r.prompt.variables.length>0){m(r.prompt);return}n(r.prompt.content);return}if(_){let t=e.length-(_[1].length+1);n(`${e.slice(0,t)}$${r.slug} `)}}};if((0,Q.useImperativeHandle)(r,()=>({handleKeyDown(t){return f?t.key===`Escape`?(t.preventDefault(),m(null),!0):t.key===`Enter`:b.length===0?!1:t.key===`ArrowDown`?(t.preventDefault(),d(e=>(e+1)%b.length),!0):t.key===`ArrowUp`?(t.preventDefault(),d(e=>(e-1+b.length)%b.length),!0):t.key===`Enter`||t.key===`Tab`?(t.preventDefault(),C(u),!0):t.key===`Escape`&&(t.preventDefault(),n(e),!0)}})),f)return(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-variable-form`,children:(0,$.jsx)(jn,{prompt:f,onCancel:()=>m(null),onInsert:e=>{m(null),n(e)}})});let w=g?`prompt`:_?`skill`:null,T=g?a!==null:s!==null,E=g?g[1]===``:_?_[1]===``:!1;return b.length===0?w&&T&&E?(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md rounded-xl border border-gray-200 bg-white px-3 py-2 text-xs text-gray-500 shadow-lg dark:border-dark-200 dark:bg-dark-50 dark:text-gray-400`,"data-testid":`composer-suggestions-empty`,children:i(w===`prompt`?`composer.promptMenu.empty`:`composer.skillMenu.empty`)}):null:(0,$.jsx)(`div`,{role:`listbox`,"aria-label":i(g?`composer.promptMenu.label`:`composer.skillMenu.label`),className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-suggestions`,children:b.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===u,onMouseEnter:()=>d(t),onMouseDown:e=>{e.preventDefault(),C(t)},className:p(`flex w-full items-center gap-2 px-3 py-2 text-left text-sm`,t===u?`bg-gray-100 dark:bg-dark-200`:`bg-transparent`),children:[e.kind===`prompt`?(0,$.jsx)(ge,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(ee,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,$.jsxs)(`span`,{className:`font-mono text-xs text-gray-500`,dir:`ltr`,children:[e.kind===`prompt`?`/`:`$`,e.slug]}),(0,$.jsx)(`span`,{className:`truncate text-gray-700 dark:text-gray-200`,children:e.label}),e.detail&&(0,$.jsx)(`span`,{className:`ml-auto hidden max-w-[40%] truncate text-xs text-gray-400 sm:block`,children:e.detail})]},e.key))})});Mn.displayName=`ComposerSuggestions`;var Nn=(e,t,n)=>{let r=new Set(e??t);r.has(n)?r.delete(n):r.add(n);let i=t.filter(e=>r.has(e));return i.length===t.length?null:i},Pn=({value:e,onChange:t,disabled:n=!1,buttonClassName:r})=>{let{t:i}=c(),[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null);if((0,Q.useEffect)(()=>{let e=!1;return Ue.getCatalog().then(t=>{e||!t.success||!t.data||(d(t.data.available&&t.data.tools.length>0),l(t.data.tools))}).catch(()=>{}),()=>{e=!0}},[a]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{f.current?.contains(e.target)||o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]),!u||!s)return null;let m=s.filter(e=>e.source===`builtin`),h=new Map;for(let e of s)e.serverId&&h.set(e.serverId,e.serverName??e.serverId);let g=[...h.entries()],_=m.map(e=>e.name),v=g.map(([e])=>e),y=new Set(e.builtinTools??_),b=new Set(e.serverIds??v),x=(n,r,i,a,o)=>(0,$.jsxs)(`label`,{className:p(`flex cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-sm hover:bg-gray-50 dark:hover:bg-dark-100`,!e.enabled&&`opacity-50`),onClickCapture:e.enabled?void 0:n=>{n.preventDefault(),n.stopPropagation(),t({...e,enabled:!0})},children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a,disabled:!e.enabled,onChange:o,"data-testid":`composer-tool-option`,className:`mt-0.5 h-3.5 w-3.5 accent-primary-600`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-gray-800 dark:text-gray-200`,dir:`ltr`,children:r}),i&&(0,$.jsx)(`span`,{className:`block truncate text-xs text-gray-500 dark:text-gray-400`,children:i})]})]},n);return(0,$.jsxs)(`div`,{ref:f,className:`relative flex-shrink-0`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,disabled:n,onClick:()=>o(e=>!e),className:p(`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`,e.enabled&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`,r),title:e.enabled?i(`chat.input.toolsOn`):i(`chat.input.toolsOff`),"aria-pressed":e.enabled,"aria-expanded":a,"data-testid":`composer-tools-button`,children:(0,$.jsx)(U,{className:`h-4 w-4`})}),a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 w-72 rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-tools-menu`,children:[(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center justify-between gap-2 rounded-lg px-2 py-1.5 text-sm font-medium text-gray-800 dark:text-gray-200`,children:[i(`composer.toolsMenu.enable`),(0,$.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>t({...e,enabled:!e.enabled}),"data-testid":`composer-tools-enable`,className:`h-3.5 w-3.5 accent-primary-600`})]}),m.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.builtin`)}),m.map(n=>x(n.name,n.name,void 0,y.has(n.name),()=>t({...e,enabled:!0,builtinTools:Nn(e.builtinTools,_,n.name)})))]}),g.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.servers`)}),g.map(([n,r])=>x(n,r,void 0,b.has(n),()=>t({...e,enabled:!0,serverIds:Nn(e.serverIds,v,n)})))]}),(0,$.jsx)(`p`,{className:`mt-1 border-t border-gray-100 px-2 pb-0.5 pt-1.5 text-[11px] leading-4 text-gray-400 dark:border-dark-200 dark:text-dark-500`,children:i(`composer.toolsMenu.hint`)})]})]})},Fn={enabled:!1,builtinTools:null,serverIds:null},In=e=>{if(!e.enabled)return{};let t={...e.builtinTools===null?{}:{builtinTools:e.builtinTools},...e.serverIds===null?{}:{serverIds:e.serverIds}};return{tools:!0,...Object.keys(t).length>0?{toolSelection:t}:{}}},Ln=q(`components:chat-input`),Rn=560,zn=({onSendMessage:e,onStopGeneration:t,onCancelComparison:n,onOpenVoiceMode:r,disabled:i=!1})=>{let{t:a}=c(),[o,s]=(0,Q.useState)(``),l=(0,Q.useRef)(``),[u,d]=(0,Q.useState)([]),[f,m]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[C,ee]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(!1),[te,M]=(0,Q.useState)([]),ne=D(e=>e.pendingComparisons),[re,ie]=(0,Q.useState)(Fn),N=D(e=>e.currentSession?.isPrivate===!0);(0,Q.useEffect)(()=>{let e=!1;return Qe.getConfig().then(t=>{!e&&t.success&&t.data&&ee(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[P,F]=(0,Q.useState)(null),[ae,se]=(0,Q.useState)(!1),[ce,le]=(0,Q.useState)([]),[ue,fe]=(0,Q.useState)(!1),[me,he]=(0,Q.useState)(!1),[ge,_e]=(0,Q.useState)(null),[ve,be]=(0,Q.useState)(!1),xe=(0,Q.useRef)(null),Se=(0,Q.useRef)(null),L=(0,Q.useRef)(null),[R,we]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=L.current;if(!e)return;let t=new ResizeObserver(t=>{let n=t[0]?.contentRect.width??e.clientWidth;we(n<Rn)});return t.observe(e),()=>t.disconnect()},[]);let{isGenerating:Te,setBackgroundImage:De}=tt(),Oe=tt(e=>e.preferences.generationOptions),B=tt(e=>e.preferences.imageGenSettings?.enabled===!0),ke=B&&ve,{currentSession:H,models:Ae}=D(),U=tt(e=>H?.model?e.preferences.modelGenerationOptions?.[H.model]:void 0),W=H?.id,[Ne,Ie]=(0,Q.useState)(W);Ne!==W&&(Ie(W),M([]));let Le=(0,Q.useRef)(null),ze=(0,Q.useRef)(null),K=(0,Q.useMemo)(()=>({model:H?.personaId?`persona:${H.personaId}`:H?.model||``,providerType:H?.providerType,providerId:H?.providerId}),[H?.model,H?.personaId,H?.providerId,H?.providerType]),Be=(0,Q.useMemo)(()=>h(Ae,K),[Ae,K]),q=K.model?T(Be,K):``,He=y(Ae,K);(0,Q.useEffect)(()=>{let e=!1;return B&&(async()=>{try{let t=await Ve.getPlugins();if(e)return;be(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;be(!1)}})(),()=>{e=!0}},[B]),(0,Q.useEffect)(()=>{if(!b)return;let e=e=>{xe.current&&!xe.current.contains(e.target)&&(x(!1),F(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[b]);let Y=()=>{x(!1),F(null),se(!1)};(0,Q.useEffect)(()=>{if(!ae)return;let e=!1;return qe.getCollections().then(t=>{!e&&t.success&&t.data&&le(t.data)}).catch(()=>{}),()=>{e=!0}},[ae]);let Ue=H?.settings?.generationOptions?.think,We=U?.think??Oe?.think??null,Ge=(0,Q.useMemo)(()=>Ae.find(e=>e.name===H?.model),[Ae,H?.model]),[Ke,Ye]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=H?.model;if(!e||Ae.length===0||!Ge||Ge.isPlugin||Ge.isAgent)return;let t=!1;return $e.getModelDefaults(e).then(n=>{t||!n.success||!n.data||Ye({model:e,supportsThinking:n.data.supportsThinking,options:n.data.options??{},trainedContextLength:n.data.trainedContextLength,contextCapped:n.data.contextCapped})}).catch(()=>{}),()=>{t=!0}},[Ge,H?.model,Ae.length]);let Xe=Ke?.model===H?.model?Ke:null,Ze=Xe?.supportsThinking,et=!!(H&&!Ge?.isAgent&&(Ge?.isPlugin?Ge.reasoningSupport!==!1:Ze!==!1)),nt=w({model:Ge,sessionOptions:H?.settings?.generationOptions,pinnedOptions:U,modelDefaults:Xe?.options,globalOptions:Oe}),rt=D(e=>e.contextWindowMessages),it=(0,Q.useMemo)(()=>E({messages:H?.messages??[],budget:nt,systemPrompt:ge?.parameters?.system_prompt,windowMessages:rt}),[nt,rt,ge,H?.messages]),at=async e=>{if(!H)return;let t={...H.settings?.generationOptions??{}};e===null?delete t.think:t.think=e;let n={...H.settings,generationOptions:t};if(D.setState(e=>({currentSession:e.currentSession?.id===H.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===H.id?{...e,settings:n}:e)})),!H.isPrivate)try{await J.updateSession(H.id,{settings:n})}catch(e){Ln.error(`Failed to update the thinking setting:`,e)}},ot=H?.settings?.knowledgeCollectionIds??[],st=async e=>{if(!H)return;let t=ot.includes(e)?ot.filter(t=>t!==e):[...ot,e],n={...H.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(D.setState(e=>({currentSession:e.currentSession?.id===H.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===H.id?{...e,settings:n}:e)})),!H.isPrivate)try{await J.updateSession(H.id,{settings:n})}catch(e){Ln.error(`Failed to update knowledge collections:`,e),G.error(a(`chat.input.menu.attachFailed`))}},Z=Ot({onStart:()=>{l.current=o},onText:e=>{let t=l.current;s(t?`${t} ${e}`:e)},ownerKey:W}),ct=Z.phase===`starting`,lt=Z.phase===`recording`,ut=Z.phase===`transcribing`,dt=Z.supported,ft=Z.providerModel,mt=Z.sources.filter(e=>e.kind===`provider`),ht=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){Y(),he(!0);try{let e=await qe.uploadDocument(t,H?.id);e.success?(G.success(a(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):G.error(e.error||a(`chat.input.menu.attachFailed`))}catch(e){Ln.error(`Document upload failed:`,e),G.error(a(`chat.input.menu.attachFailed`))}finally{he(!1)}}},gt=async()=>{let e=P?.trim();if(!(!e||ue)){fe(!0);try{let t=await qe.fetchWebpage(e,H?.id);t.success?(G.success(a(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),Y()):G.error(t.error||a(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.input.menu.attachFailed`);Ln.error(`Webpage attach failed:`,e),G.error(t)}finally{fe(!1)}}},_t=async e=>{if(!(!W||N))try{let t=await J.enqueuePrompt(W,e);t.success&&t.data?(pt(W,t.data.queue),s(``)):G.error(t.error||a(`chat.queue.enqueueFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.queue.enqueueFailed`);Ln.error(`Failed to queue the prompt:`,e),G.error(t)}},yt=t=>{if(t.preventDefault(),!o.trim())return;if(Te){u.length===0&&!N&&W&&_t(o.trim());return}if(!He){G.error(a(`chat.model.selectBeforeSending`));return}let n=N?{}:In(re),r=N?[]:wn(Ae,te);e(o.trim(),u.length>0?u:void 0,f||void 0,C&&k?!0:void 0,n.tools,n.toolSelection,r.length>0?r:void 0),s(``),d([])},bt=e=>{ze.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),yt(e))},xt=()=>{t()};(0,Q.useEffect)(()=>{let e=Le.current;e&&(e.style.height=`auto`,e.style.height=o?`${Math.min(e.scrollHeight,200)}px`:``)},[o]),(0,Q.useEffect)(()=>{(async()=>{if(H?.personaId)try{let e=await Je.getPersona(H.personaId);if(e.success&&e.data)_e(e.data);else{Ln.warn(`Persona ${H.personaId} not found, clearing reference`),_e(null);let{setCurrentSession:e}=D.getState();e({...H,personaId:void 0})}}catch(e){if(Ln.error(`Failed to load current persona:`,e),_e(null),H){let{setCurrentSession:e}=D.getState();e({...H,personaId:void 0})}}else _e(null)})()},[H?.personaId]);let St=async e=>{let t=O(Be,e.target.value);if(t&&H)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await Je.getPersona(e);if(!n.success||!n.data){G.error(a(`chat.persona.loadFailed`));return}let r=n.data,i=await J.updateSession(H.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(i.success&&i.data){let{sessions:e}=D.getState(),t=e.map(e=>e.id===H.id?i.data:e);D.setState({sessions:t,currentSession:i.data}),r.background&&De(r.background),G.success(a(`chat.persona.applied`))}}else{let e=await J.updateSession(H.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}=D.getState(),n=t.map(t=>t.id===H.id?e.data:t);D.setState({sessions:n,currentSession:e.data}),De(null),G.success(a(`chat.model.updated`))}}}catch(e){Ln.error(`Failed to update session:`,e),G.error(a(`chat.toasts.updateFailed`))}},Ct=u.length>0||f!==null;return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{ref:L,className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[g&&(0,$.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/90`,children:[(0,$.jsx)(dn,{images:u,onImagesChange:d,maxImages:5,sessionId:H?.id,disabled:i}),(0,$.jsx)(gn,{format:f,onFormatChange:m})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[W&&!N&&(H?.settings?.promptQueue?.length??0)>0&&(0,$.jsx)(Cn,{sessionId:W,queue:H.settings.promptQueue}),W&&ne.some(e=>e.sessionId===W)&&(0,$.jsx)(`div`,{className:`mx-auto mb-1.5 flex w-full max-w-3xl flex-wrap gap-1.5 px-1`,"data-testid":`pending-comparisons`,children:ne.filter(e=>e.sessionId===W).map(e=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-2.5 py-1 text-[12px] text-gray-600 dark:border-white/[0.08] dark:bg-dark-200/70 dark:text-dark-700`,"data-testid":`pending-comparison`,children:[(0,$.jsx)(I,{className:`h-3 w-3 animate-spin`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-[160px] truncate`,children:e.model}),n&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.assistantMessageId),className:`rounded-full p-0.5 text-gray-400 hover:text-red-500`,"aria-label":a(`common.cancel`),children:(0,$.jsx)(z,{className:`h-3 w-3`})})]},e.assistantMessageId))}),(0,$.jsx)(`form`,{onSubmit:yt,children:(0,$.jsxs)(`div`,{className:p(`relative 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,$.jsx)(Mn,{ref:ze,message:o,disabled:i,onApply:e=>{s(e),Le.current?.focus()}}),(0,$.jsx)(ln,{ref:Le,value:o,onChange:e=>s(e.target.value),onKeyDown:bt,placeholder:a(`chat.input.placeholder`),disabled:i,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,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(`div`,{ref:xe,className:`relative flex-shrink-0`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(g){_(!1);return}x(e=>!e),F(null)},className:p(`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`,Ct&&`text-primary-600 dark:text-primary-400`,(g||b)&&`bg-hover-solid text-ink`),title:a(`chat.input.attachments`),children:me||ue?(0,$.jsx)(I,{className:`h-4 w-4 animate-spin`}):Ct?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Me,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):g?(0,$.jsx)(ye,{className:`h-4 w-4`}):(0,$.jsx)(oe,{className:`h-4 w-4`})}),b&&(0,$.jsx)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 w-64 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:ae?(0,$.jsxs)(`div`,{className:`p-1`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:a(`chat.input.menu.attachKnowledge`)}),ce.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-gray-400 dark:text-dark-500`,children:a(`chat.input.menu.noCollections`)}):ce.map(e=>{let t=ot.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void st(e.id),className:p(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),"aria-pressed":t,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(V,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(je,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>se(!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:a(`common.back`)})]}):P===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{_(!0),Y()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(de,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.uploadImages`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>Se.current?.click(),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(Ce,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>F(``),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(pe,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>se(!0),className:`flex w-full items-center justify-between gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(V,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachKnowledge`)]}),ot.length>0&&(0,$.jsx)(`span`,{className:`rounded-full bg-primary-50 px-1.5 text-[10px] font-medium tabular-nums text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`,children:ot.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{_(!0),Y()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(Pe,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.structuredOutput`)]}),R&&C&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{A(e=>!e),Y()},className:p(`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`,k&&`text-primary-600 dark:text-primary-400`),"aria-pressed":k,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(pe,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(k?`chat.input.webSearchOn`:`chat.input.webSearchOff`)]}),k&&(0,$.jsx)(je,{className:`h-3.5 w-3.5 shrink-0`})]}),R&&dt&&r&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{vt(),r(),Y()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(Ee,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`voiceMode.open`)]})]}):(0,$.jsxs)(`div`,{className:`p-1.5`,children:[(0,$.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:a(`chat.input.menu.attachWebpage`)}),(0,$.jsx)(`input`,{type:`url`,value:P,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),gt()):e.key===`Escape`&&F(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>F(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:a(`common.cancel`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void gt(),disabled:!P.trim()||ue,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:ue?(0,$.jsx)(I,{className:`h-3.5 w-3.5 animate-spin`}):a(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:Se,type:`file`,accept:En,className:`hidden`,onChange:e=>void ht(e)})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-1 sm:gap-1.5`,children:[et&&(0,$.jsx)(_n,{value:Ue,inheritedValue:We,onChange:e=>void at(e)}),C&&!R&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>A(e=>!e),className:p(`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`,k&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:a(k?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":k,children:(0,$.jsx)(pe,{className:`h-4 w-4`})}),!N&&(0,$.jsx)(Pn,{value:re,onChange:ie}),!N&&H&&!R&&(0,$.jsx)(Tn,{models:Ae,currentModelKey:v({model:H.personaId?`persona:${H.personaId}`:H.model,providerType:H.providerType??null,providerId:H.providerId??null}),selectedKeys:te,onChange:M,disabled:i}),mt.length>0&&!R&&(0,$.jsx)(`select`,{value:Z.activeSourceKey,onChange:e=>Z.setSourceKey(e.target.value),disabled:ct||lt||ut,"aria-label":a(`chat.input.transcriptionSource`),title:ft?a(`chat.input.providerTranscriptionDisclosure`,{provider:ft.plugin}):a(`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:Z.sources.map(e=>e.kind===`browser`?(0,$.jsx)(`option`,{value:e.key,children:a(`chat.input.browserSpeech`)},e.key):(0,$.jsxs)(`option`,{value:e.key,children:[e.model?.plugin,` · `,e.model?.model]},e.key))}),dt&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void Z.toggle(),className:p(`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`,(ct||lt||ut)&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:ut||ct?a(`common.cancel`):lt?a(`chat.input.voiceStop`):ft?a(`chat.input.providerTranscriptionDisclosure`,{provider:ft.plugin}):a(`chat.input.voiceInput`),"aria-pressed":ct||lt||ut,children:ct?(0,$.jsx)(I,{className:`h-4 w-4 animate-spin`}):ut?(0,$.jsx)(j,{className:`h-4 w-4`}):(0,$.jsx)(Re,{className:`h-4 w-4`})}),dt&&r&&!R&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{vt(),r()},className:p(`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`),title:a(`voiceMode.open`),"aria-label":a(`voiceMode.open`),"data-testid":`voice-mode-open`,children:(0,$.jsx)(Ee,{className:`h-4 w-4`})}),H&&(0,$.jsx)(xn,{usage:it,trainedBudget:Xe?.contextCapped?Xe.trainedContextLength:void 0}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),H&&Be.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Dt,{models:Be,selectedModel:q,onModelChange:St,getModelValue:S,currentPersona:ge,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:ke})}),Te?(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:xt,className:p(`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:a(`chat.input.stopGeneration`),children:(0,$.jsx)(j,{className:`h-4 w-4`})}):(0,$.jsx)(X,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!o.trim()||i||!He,className:p(`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:a(`chat.input.sendMessage`),children:(0,$.jsx)(Fe,{className:`h-4 w-4`})})]})]})]})}),ft&&(0,$.jsx)(`p`,{role:`note`,className:`mt-1.5 text-center text-[10px] leading-relaxed text-amber-700 dark:text-amber-300`,children:a(`chat.input.providerTranscriptionDisclosure`,{provider:ft.plugin})}),H&&Be.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(Dt,{models:Be,selectedModel:q,onModelChange:St,getModelValue:S,currentPersona:ge,className:`w-full`,compact:!0,showImageGen:ke})}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(pn,{sessionId:H?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:a(`chat.footer.disclaimer`)}),Ct&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,u.length>0&&a(`chat.footer.images`,{count:u.length}),u.length>0&&f&&` • `,f&&a(`chat.footer.structuredOutput`)]})]})]})]})]})})},Bn={phase:`idle`,muted:!1,turn:0,error:null},Vn=e=>({...e,phase:`listening`,turn:e.turn+1});function Hn(e,t){switch(t.type){case`start`:return e.phase===`idle`?{phase:`listening`,muted:!1,turn:e.turn+1,error:null}:e;case`stop`:return{...e,phase:`idle`,error:null};case`mute`:return{...e,muted:!0};case`unmute`:return{...e,muted:!1};case`captured`:return e.phase===`listening`&&!e.muted?{...e,phase:`transcribing`,error:null}:e;case`transcript`:return e.phase===`transcribing`?t.text.trim()?{...e,phase:`generating`}:Vn(e):e;case`reply`:return e.phase===`generating`?t.speak?{...e,phase:`speaking`}:Vn(e):e;case`spoken`:case`barge-in`:return e.phase===`speaking`?Vn(e):e;case`fail`:return e.phase===`idle`?e:{...Vn(e),error:t.message}}}var Un=q(`utils:voice-mode-controller`),Wn=.015,Gn=200,Kn=1500,qn=6e4,Jn=300,Yn=18e4,Xn=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},Zn=e=>{if(typeof MediaRecorder>`u`)return;let t=new Set((e.config?.formats||[]).map(e=>e.toLowerCase())),n=`audio/webm;codecs=opus`;if(!(t.size>0&&!t.has(`webm`))&&!(typeof MediaRecorder.isTypeSupported==`function`&&!MediaRecorder.isTypeSupported(n)))return n},Qn=class{constructor(e){o(this,`options`,void 0),o(this,`state`,Bn),o(this,`closed`,!1),o(this,`useBrowserRecognition`,!1),o(this,`sttModel`,null),o(this,`ttsModels`,[]),o(this,`stream`,null),o(this,`recorder`,null),o(this,`chunks`,[]),o(this,`audioContext`,null),o(this,`analyser`,null),o(this,`monitorTimer`,null),o(this,`pollTimer`,null),o(this,`recognition`,null),o(this,`ttsSession`,null),o(this,`abortController`,null),this.options=e}async start(){try{let[e,t]=await Promise.all([Ze.getModels().catch(()=>({success:!1,data:[]})),Y.getModels().catch(()=>({success:!1,data:[]}))]);if(this.closed)return;let n=e.success&&e.data||[];this.ttsModels=t.success&&t.data||[];let r=n.find(e=>!!Zn(e)),i=!!r&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia,a=!!Xn();if(i&&r)this.sttModel=r,this.useBrowserRecognition=!1;else if(a)this.useBrowserRecognition=!0;else{this.options.onSupport(!1);return}if(this.options.onSupport(!0),!this.useBrowserRecognition&&(await this.ensureStream(),this.closed))return;let o=this.send({type:`start`});this.beginTurn(o.turn)}catch(e){Un.warn(`Voice mode failed to start:`,e),this.closed||this.options.onSupport(!1)}}close(){this.closed=!0,this.clearMonitor(),this.clearPoll(),this.stopRecorder(),this.stopRecognition(),this.abortController?.abort(),this.ttsSession?.cancel(),this.ttsSession=null,this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null,this.audioContext&&(this.audioContext.close().catch(()=>void 0),this.audioContext=null)}toggleMute(){if(this.state.muted){let e=this.send({type:`unmute`});e.phase===`listening`&&(this.stopRecorder(),this.stopRecognition(),this.beginTurn(e.turn))}else this.send({type:`mute`})}finishTurn(){this.state.phase!==`listening`||this.state.muted||(this.useBrowserRecognition?this.recognition?.stop():this.finishProviderCapture(this.state.turn))}skipSpeech(){if(this.state.phase!==`speaking`)return;this.ttsSession?.cancel(),this.clearMonitor();let e=this.send({type:`spoken`});e.phase===`listening`&&this.beginTurn(e.turn)}send(e){return this.state=Hn(this.state,e),this.options.onState(this.state),this.state}staleTurn(e){return this.closed||this.state.turn!==e}clearMonitor(){this.monitorTimer!==null&&(window.clearInterval(this.monitorTimer),this.monitorTimer=null)}clearPoll(){this.pollTimer!==null&&(window.clearInterval(this.pollTimer),this.pollTimer=null)}stopRecorder(){let e=this.recorder;if(this.recorder=null,e&&e.state!==`inactive`)try{e.stop()}catch{}}stopRecognition(){let e=this.recognition;if(this.recognition=null,e){e.onresult=null,e.onend=null,e.onerror=null;try{e.stop()}catch{}}}rmsLevel(){if(!this.analyser)return 0;let e=new Float32Array(this.analyser.fftSize);this.analyser.getFloatTimeDomainData(e);let t=0;for(let n=0;n<e.length;n+=1)t+=e[n]*e[n];return Math.sqrt(t/e.length)}async ensureStream(){if(this.stream)return this.stream;let e=await navigator.mediaDevices.getUserMedia({audio:!0});this.stream=e;try{let t=window.AudioContext||window.webkitAudioContext;if(t){let n=new t;n.resume().catch(()=>void 0);let r=n.createMediaStreamSource(e),i=n.createAnalyser();i.fftSize=1024,r.connect(i),this.audioContext=n,this.analyser=i}}catch(e){Un.warn(`Voice mode analyser unavailable:`,e)}return e}fail(e,t){if(this.staleTurn(e))return;this.clearMonitor(),this.clearPoll();let n=this.send({type:`fail`,message:t});n.phase===`listening`&&this.beginTurn(n.turn)}beginTurn(e){this.closed||this.state.turn!==e||this.state.phase===`listening`&&(this.stopRecognition(),this.useBrowserRecognition?this.startBrowserCapture(e):this.startProviderCapture(e))}startBrowserCapture(e){let t=Xn();if(!t)return;let n=new t;n.lang=this.options.locale,n.continuous=!1,n.interimResults=!1;let r=``;n.onresult=e=>{r=Array.from({length:e.results.length},(t,n)=>e.results[n]?.[0]?.transcript??``).join(` `).trim()},n.onend=()=>{this.staleTurn(e)||this.state.muted||this.send({type:`captured`}).phase===`transcribing`&&this.handleTranscript(e,r)},n.onerror=()=>{this.staleTurn(e)||this.fail(e,this.options.messages.microphoneFailed)},this.recognition=n;try{n.start()}catch{this.fail(e,this.options.messages.microphoneFailed)}}async startProviderCapture(e){let t=this.sttModel;if(!t)return;let n=Zn(t);if(!n){this.fail(e,this.options.messages.microphoneFailed);return}try{let t=await this.ensureStream();if(this.staleTurn(e))return;this.chunks=[];let r=new MediaRecorder(t,{mimeType:n});this.recorder=r,r.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},r.onstop=()=>{if(this.staleTurn(e)&&this.state.phase!==`transcribing`)return;let t=new Blob(this.chunks,{type:n});if(this.chunks=[],t.size===0){this.handleTranscript(e,``);return}this.transcribeRecording(e,t)},r.start();let i=0,a=0,o=!1,s=Date.now();this.clearMonitor(),this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearMonitor();return}if(this.state.muted){i=0,a=0;return}this.analyser&&(this.rmsLevel()>Wn?(i+=50,a=0,i>=Gn&&(o=!0)):(i=0,o&&(a+=50))),(o&&a>=Kn||Date.now()-s>=qn)&&this.finishProviderCapture(e)},50)}catch(t){Un.warn(`Voice mode microphone failed:`,t),this.fail(e,this.options.messages.microphoneFailed)}}finishProviderCapture(e){this.staleTurn(e)||(this.clearMonitor(),this.send({type:`captured`}).phase===`transcribing`&&this.stopRecorder())}transcribeRecording(e,t){let n=this.sttModel;if(!n){this.fail(e,this.options.messages.transcriptionFailed);return}let r=new AbortController;this.abortController=r,Ze.transcribe(t,n,{language:this.options.locale?.split(`-`)[0],signal:r.signal}).then(t=>this.handleTranscript(e,t.text??``)).catch(t=>{r.signal.aborted||(Un.warn(`Voice mode transcription failed:`,t),this.fail(e,this.options.messages.transcriptionFailed))})}handleTranscript(e,t){if(this.staleTurn(e))return;let n=this.send({type:`transcript`,text:t});n.phase===`generating`?this.startGeneration(n.turn,t.trim()):n.phase===`listening`&&this.beginTurn(n.turn)}startGeneration(e,t){this.options.onTranscript(t);let n=this.options.snapshot().lastAssistantMessage?.id??null,r=!1,i=Date.now();this.options.sendMessage(t),this.clearPoll(),this.pollTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearPoll();return}let t=this.options.snapshot(),a=t.lastAssistantMessage,o=a!==null&&a.id!==n;if((t.isStreaming||o)&&(r=!0),r&&!t.isStreaming&&o){this.clearPoll();let t=this.ttsModels.length>0&&a.content.trim()!==``,n=this.send({type:`reply`,speak:t});n.phase===`speaking`?this.speakReply(e,a.content):n.phase===`listening`&&this.beginTurn(n.turn);return}Date.now()-i>Yn&&(this.clearPoll(),this.fail(e,this.options.messages.replyTimeout))},250)}speakReply(e,t){let n=this.options.snapshot().ttsSettings,r=Ke(this.ttsModels,n?.model,n?.pluginId);if(!r){this.finishSpeaking(e);return}let i=r.model===n?.model&&(!n?.pluginId||r.plugin===n.pluginId),a=i&&n?.voice||r.config?.default_voice,o=i&&n?.voiceProfileId||void 0,s=Math.max(1,r.config?.max_characters||600),c=Math.min(s,600),l=_t(t,{locale:this.options.locale,maxChars:c,targetChars:Math.min(c,420),minChars:Math.min(c,80)});if(l.length===0){this.finishSpeaking(e);return}let u=ht({concurrency:3,initialBufferSize:Math.min(2,l.length),generate:(e,{signal:t})=>Y.generate({model:r.model,pluginId:r.plugin,input:e,voice:o?void 0:a||void 0,voiceProfileId:o,speed:n?.speed||1,response_format:r.config?.default_format},{signal:t}),onStateChange:()=>void 0});this.ttsSession=u;let d=yt(u);this.startBargeInMonitor(e,u),u.play(l).then(()=>{this.staleTurn(e)||this.finishSpeaking(e)}).catch(t=>{this.staleTurn(e)||mt(t)||(Un.warn(`Voice mode speech failed:`,t),this.finishSpeaking(e))}).finally(()=>{d(),this.ttsSession===u&&(this.ttsSession=null)})}startBargeInMonitor(e,t){if(!this.analyser)return;this.clearMonitor();let n=0;this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)||this.state.muted){n=0;return}if(this.rmsLevel()>Wn){if(n+=50,n>=Jn){this.clearMonitor(),t.cancel();let e=this.send({type:`barge-in`});e.phase===`listening`&&this.beginTurn(e.turn)}}else n=0},50)}finishSpeaking(e){if(this.staleTurn(e))return;this.clearMonitor();let t=this.send({type:`spoken`});t.phase===`listening`&&this.beginTurn(t.turn)}},$n=({onClose:e,onSendMessage:t,isStreaming:n,lastAssistantMessage:r})=>{let{t:i,i18n:a}=c(),{preferences:o}=tt(),[s,l]=(0,Q.useState)(Bn),[u,d]=(0,Q.useState)(``),[f,m]=(0,Q.useState)(null),h=(0,Q.useRef)(null),g=(0,Q.useRef)({isStreaming:!1,lastAssistantMessage:null,ttsSettings:void 0});(0,Q.useEffect)(()=>{g.current={isStreaming:n,lastAssistantMessage:r,ttsSettings:o.ttsSettings}},[n,r,o.ttsSettings]),(0,Q.useEffect)(()=>{let e=new Qn({locale:a.language,sendMessage:e=>t(e),snapshot:()=>g.current,onState:e=>l(e),onTranscript:e=>d(e),onSupport:e=>m(e),messages:{microphoneFailed:i(`voiceMode.microphoneFailed`),transcriptionFailed:i(`voiceMode.transcriptionFailed`),replyTimeout:i(`voiceMode.replyTimeout`)}});return h.current=e,e.start(),()=>{h.current=null,e.close()}},[]);let _=s.phase,v=f===!1?`voiceMode.unsupported`:_===`listening`?s.muted?`voiceMode.muted`:`voiceMode.listening`:_===`transcribing`?`voiceMode.transcribing`:_===`generating`?`voiceMode.generating`:_===`speaking`?`voiceMode.speaking`:`voiceMode.starting`;return(0,kt.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":i(`voiceMode.title`),className:`fixed inset-0 z-[70] flex flex-col items-center justify-center gap-6 bg-white/95 p-6 backdrop-blur dark:bg-dark-25/95`,"data-testid":`voice-mode-overlay`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e,"aria-label":i(`voiceMode.close`),className:`absolute right-4 top-4 rounded-full p-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-dark-100`,children:(0,$.jsx)(z,{className:`h-5 w-5`})}),(0,$.jsx)(`div`,{className:p(`flex h-28 w-28 items-center justify-center rounded-full border-4 transition-colors`,_===`listening`&&!s.muted?`border-primary-500 text-primary-500`:_===`speaking`?`border-emerald-500 text-emerald-500`:_===`generating`||_===`transcribing`?`border-amber-500 text-amber-500`:`border-gray-300 text-gray-400 dark:border-dark-300`),children:_===`transcribing`||_===`generating`?(0,$.jsx)(I,{className:`h-10 w-10 animate-spin`}):s.muted?(0,$.jsx)(le,{className:`h-10 w-10`}):_===`speaking`?(0,$.jsx)(Ee,{className:`h-10 w-10`}):(0,$.jsx)(Re,{className:`h-10 w-10`})}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`text-base font-medium text-gray-900 dark:text-gray-100`,"data-testid":`voice-mode-status`,children:i(v)}),s.error&&(0,$.jsx)(`p`,{className:`mt-1 text-sm text-red-600 dark:text-red-400`,children:s.error}),u&&(0,$.jsxs)(`p`,{className:`mt-3 max-w-md text-sm text-gray-600 dark:text-gray-300`,children:[`“`,u,`”`]})]}),f!==!1&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.toggleMute(),"aria-label":s.muted?i(`voiceMode.unmute`):i(`voiceMode.mute`),"aria-pressed":s.muted,className:`rounded-full border border-gray-300 p-3 text-gray-700 hover:bg-gray-100 dark:border-dark-300 dark:text-gray-300 dark:hover:bg-dark-100`,children:s.muted?(0,$.jsx)(le,{className:`h-5 w-5`}):(0,$.jsx)(Re,{className:`h-5 w-5`})}),_===`listening`&&!s.muted&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.finishTurn(),"aria-label":i(`voiceMode.finishTurn`),className:`rounded-full border border-primary-500 p-3 text-primary-600 hover:bg-primary-50 dark:hover:bg-primary-950/30`,children:(0,$.jsx)(je,{className:`h-5 w-5`})}),_===`speaking`&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.skipSpeech(),"aria-label":i(`voiceMode.skipReply`),className:`rounded-full border border-emerald-500 p-3 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-950/30`,children:(0,$.jsx)(F,{className:`h-5 w-5`})})]}),f===!1&&(0,$.jsx)(`p`,{className:`max-w-md text-center text-sm text-gray-600 dark:text-gray-300`,children:i(`voiceMode.unsupportedHint`)})]}),document.body)},er=q(`components:chat-controls-panel`),tr=[{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`}],nr=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i}=c(),a=D(e=>e.draftSessionSettings),o=D(e=>e.setDraftSessionSettings),s=e?.model??t??``,u=tt(e=>e.preferences.generationOptions),d=tt(e=>e.preferences.modelGenerationOptions?.[s]),[f,p]=(0,Q.useState)({options:{},contextCapped:!1});(0,Q.useEffect)(()=>{if(!n||!s)return;let e=!1;return $e.getModelDefaults(s).then(t=>{e||!t.success||!t.data||p({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,s]);let m=(0,Q.useMemo)(()=>({...u??{},...f.options,...d??{}}),[u,f.options,d]),h=(0,Q.useMemo)(()=>e?.messages.find(e=>e.role===`system`&&!g(e.content)),[e?.messages]),[_,v]=(0,Q.useState)(h?.content??a.systemPrompt??``),[y,b]=(0,Q.useState)(e?.settings?.generationOptions??a.generationOptions??{}),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(e?.settings?.compaction!==!1),[T,E]=(0,Q.useState)(e?.id??`draft`),O=e?.id??`draft`;T!==O&&(E(O),v(h?.content??a.systemPrompt??``),b(e?.settings?.generationOptions??a.generationOptions??{}),w(e?.settings?.compaction!==!1));let ee=e=>{b(t=>{let n={...t},r=xt(e);return r===null?delete n.think:n.think=r,n})},k=(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})},A=async()=>{S(!0);try{let t=_.trim(),n=h?.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}),K.success(i(`chat.controls.saved`)),r();return}let c=e.messages;if(t!==n.trim()&&(h?c=t?e.messages.map(e=>e.id===h.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==h.id):t&&(c=[{id:l(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)D.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:c,settings:s}:t.currentSession}));else{let t=await J.updateSession(e.id,{messages:c,settings:s});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;D.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}K.success(i(`chat.controls.saved`)),r()}catch(e){er.error(`Failed to save chat controls:`,e),K.error(i(`chat.controls.saveFailed`))}finally{S(!1)}};return n?(0,$.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:`flex h-full w-[21rem] shrink-0 flex-col border-s border-black/[0.06] bg-surface/70 backdrop-blur-xl dark:border-white/[0.07] dark:bg-dark-100/70`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:i(`chat.controls.title`)}),(0,$.jsx)(`button`,{onClick:r,className:`rounded-full p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-900`,title:i(`common.close`),children:(0,$.jsx)(z,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.systemPrompt`)}),(0,$.jsx)(`textarea`,{dir:`auto`,value:_,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,$.jsxs)(`div`,{children:[(0,$.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,$.jsx)(`select`,{id:`chat-control-think`,value:Ct(y.think),onChange:e=>ee(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:wt.map(e=>(0,$.jsx)(`option`,{value:e,children:e==="default"&&m.think!==void 0&&m.think!==null?i(`settings.generation.thinkingLevels.defaultWith`,{level:i(`settings.generation.thinkingLevels.${Ct(m.think)}`)}):i(`settings.generation.thinkingLevels.${e}`)},e))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.thinkingDescription`)})]}),e&&(0,$.jsxs)(`div`,{children:[(0,$.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,$.jsxs)(`select`,{id:`chat-control-compaction`,value:C?`default`:`off`,onChange:e=>w(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,$.jsx)(`option`,{value:`default`,children:i(`chat.controls.compactionDefault`)}),(0,$.jsx)(`option`,{value:`off`,children:i(`chat.controls.compactionOff`)})]}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.compactionDescription`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.advancedParams`)}),(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.advancedParamsDescription`)}),f.contextCapped&&f.trainedContextLength&&(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-500 dark:text-dark-600`,children:i(`chat.controls.contextCapped`,{context:m.num_ctx?.toLocaleString(),trained:f.trainedContextLength.toLocaleString()})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:tr.map(e=>{let t=y[e.key],n=m[e.key],r=f.options[e.key]!==void 0&&d?.[e.key]===void 0;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`label`,{htmlFor:`chat-control-${e.key}`,className:`text-[13px] text-gray-700 dark:text-dark-700`,children:[i(`chat.controls.params.${e.labelKey}`),r&&(0,$.jsx)(`span`,{title:i(`chat.controls.fromModelHint`),className:`ms-1.5 text-[10px] uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:i(`chat.controls.fromModel`)})]}),(0,$.jsx)(`input`,{id:`chat-control-${e.key}`,type:`number`,inputMode:`decimal`,step:e.step,min:e.min,max:e.max,value:typeof t==`number`?t:``,placeholder:typeof n==`number`?String(n):i(`common.default`),onChange:t=>k(e.key,t.target.value),className:`w-24 rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-black/[0.06] px-4 py-3 dark:border-white/[0.07] lg:pb-16`,children:[(0,$.jsx)(`button`,{onClick:()=>{b({}),v(h?.content??``)},className:`text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:i(`common.reset`)}),(0,$.jsx)(X,{onClick:()=>void A(),size:`sm`,disabled:x,children:i(x?`common.saving`:`common.save`)})]})]}):null},rr=q(`components:chat-sources-panel`),ir=6,ar=[],or=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}},sr=({session:e})=>{let{t}=c(),[n,r]=(0,Q.useState)({sessionId:``,docs:ar}),i=!e.isPrivate&&n.sessionId===e.id?n.docs:ar,[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),{webSources:f,ragSources:p,fullContextSkipped:m}=(0,Q.useMemo)(()=>{let t=new Map,n=new Map,r;for(let i of e.messages){let e=i.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,...Array.isArray(e.citations)?{citations:e.citations.filter(e=>!!e&&typeof e==`object`&&typeof e.chunkIndex==`number`)}:{},...e.full===!0?{full:!0}:{}})}let a=e?.ragFullContextSkipped;a&&typeof a.estimatedTokens==`number`&&typeof a.maxTokens==`number`?r={estimatedTokens:a.estimatedTokens,maxTokens:a.maxTokens}:e?.ragSources&&(r=void 0)}return{webSources:Array.from(t.values()),ragSources:Array.from(n.values()),fullContextSkipped:r}},[e.messages]);(0,Q.useEffect)(()=>{if(e.isPrivate)return;let t=!1,n=()=>{qe.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,contentChars:e.contentChars}))})}).catch(()=>{})};return n(),window.addEventListener(`libre:documents-updated`,n),()=>{t=!0,window.removeEventListener(`libre:documents-updated`,n)}},[e.id,e.isPrivate]);let h=(0,Q.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,{...e.get(t.id)??{},id:t.id,filename:t.filename,used:!0,...t.citations?.length?{citations:t.citations}:{},...t.full?{full:!0}:{}});return Array.from(e.values())},[i,p]),g=e.settings?.fullDocumentContext===!0,_=(0,Q.useMemo)(()=>i.reduce((e,t)=>e+Math.ceil((t.contentChars??0)/4),0),[i]),v=async()=>{let t={...e.settings,fullDocumentContext:!g||void 0};if(D.setState(n=>({currentSession:n.currentSession?.id===e.id?{...n.currentSession,settings:t}:n.currentSession,sessions:n.sessions.map(n=>n.id===e.id?{...n,settings:t}:n)})),!e.isPrivate)try{await J.updateSession(e.id,{settings:t})}catch(e){rr.error(`Failed to update the full-document setting:`,e)}},y=e=>{let t=[];for(let n of e){let e=n.location??`#${n.chunkIndex+1}`;if(t.includes(e)||t.push(e),t.length>=4)break}return t.join(` · `)};if(f.length===0&&h.length===0)return null;let b=a?f:f.slice(0,ir),x=s?h:h.slice(0,ir),S=(e,n,r)=>(e>0||n)&&(0,$.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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ie,{className:`h-3 w-3`}),t(`chatMessage.showLess`,`Show less`)]}):`${t(`chatMessage.showMore`)} (${e})`}),C=(0,$.jsxs)($.Fragment,{children:[f.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:b.map(e=>(0,$.jsx)(`li`,{children:(0,$.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,$.jsx)(pe,{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,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.title}),(0,$.jsx)(`span`,{dir:`ltr`,className:`block truncate text-[11px] text-gray-400 dark:text-dark-500`,children:or(e.url)})]})]})},e.url))}),S(f.length-b.length,a,()=>o(e=>!e))]}),h.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`settings.tabs.documents`,`Documents`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:x.map(e=>(0,$.jsxs)(`li`,{className:`-mx-1 rounded-lg px-1 py-1.5`,title:e.filename,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(Ce,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.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,$.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-primary-500`})]}),e.full?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-gray-400 dark:text-dark-500`,"data-testid":`chat-source-citation`,children:t(`documents.fullDocument`,`Full document`)}):e.citations?.length?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-gray-400 dark:text-dark-500`,"data-testid":`chat-source-citation`,children:y(e.citations)}):null]},e.id))}),S(h.length-x.length,s,()=>l(e=>!e)),(0,$.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-center gap-2 px-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:g,onChange:v,"data-testid":`full-document-context-toggle`,className:`h-3.5 w-3.5 rounded border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[t(`documents.fullContextToggle`,`Send full documents`),g&&_>0&&(0,$.jsx)(`span`,{className:`ms-1 text-gray-400 dark:text-dark-500`,children:t(`documents.fullContextEstimate`,{tokens:_.toLocaleString()})})]})]}),g&&m&&(0,$.jsx)(`p`,{className:`mt-1 px-1 text-[11px] text-amber-600 dark:text-amber-400`,"data-testid":`full-document-context-warning`,children:t(`documents.fullContextTooLarge`)})]})]});return(0,$.jsxs)($.Fragment,{children:[(0,$.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:C}),(0,$.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,$.jsx)(V,{className:`h-3.5 w-3.5`}),(0,$.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+h.length})]}),u&&(0,kt.createPortal)((0,$.jsxs)(`div`,{className:`fixed inset-0 z-[80] xl:hidden`,children:[(0,$.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/35 backdrop-blur-[2px]`,onClick:()=>d(!1),"aria-label":t(`common.close`)}),(0,$.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,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:t(`chat.message.sources`,`Sources`)}),(0,$.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,$.jsx)(z,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:C})]})]}),document.body)]})},cr=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)({top:0,left:0});(0,Q.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect(),t=document.documentElement.dir===`rtl`?e.right-288:e.left;s({top:e.bottom+8,left:Math.min(window.innerWidth-288-8,Math.max(8,t))})}},[r]);let c=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),l=()=>Ge(e,64),u=t=>{He(t.currentTarget,e.name,64)};return(0,$.jsxs)(`div`,{className:p(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:p(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-md object-cover`,onError:u}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,$.jsx)(ee,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(N,{className:p(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,kt.createPortal)((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,$.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,$.jsxs)(`div`,{className:p(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,$.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,$.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 end-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,$.jsx)(z,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,$.jsxs)(`div`,{className:`absolute top-2 start-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,$.jsx)(Se,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,$.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:u})}),(0,$.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,$.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,$.jsx)(A,{className:`h-3 w-3`}),e.model]}),e.description&&(0,$.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,$.jsxs)(`div`,{className:`mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,$.jsx)(Le,{className:`h-2.5 w-2.5 text-gray-400`}),(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(W,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,$.jsx)(Se,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},lr=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=c(),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)(!1),l=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){K.error(`File ${o.name} is not an image`);continue}if(o.size>10485760){K.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&&K.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),s(!0)},d=e=>{e.preventDefault(),s(!1)},f=e=>{e.preventDefault(),s(!1),l(e.dataTransfer.files)},m=n=>{t(e.filter((e,t)=>t!==n))},h=e.length<n;return(0,$.jsxs)(`div`,{className:p(`space-y-3`,r),children:[h&&(0,$.jsxs)(`div`,{className:p(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:u,onDragLeave:d,onDrop:f,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(ke,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,$.jsx)(X,{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,$.jsx)(z,{className:`h-4 w-4`})})})]},t))}),h&&e.length>0&&(0,$.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(de,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},ur=q(`pages:chat-page`),dr=(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?`}},fr=(e,t,n,r=!1)=>{let i=rt(e);return i===`time`?dr(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.`}},pr=e=>{if(!e)return null;for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`assistant`)return{id:n.id,content:n.content}}return null},mr=()=>{let{t:e,i18n:t}=c(),{sessionId:n}=s(),r=a(),o=i(),{currentSession:u,sessions:d,models:f,selectedModel:g,selectedProviderType:v,selectedProviderId:b,setSelectedModel:x,createSession:C,setCurrentSession:w,loadSessions:E,getCurrentPersona:ee}=D(),{user:k}=et(),A=tt(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:te,stopGeneration:j,cancelComparison:M,regenerateLastMessage:ne,editAndResendMessage:re,selectBranch:ie,isStreaming:N,streamingMessage:F,streamingThinking:I,streamingMessageId:ae,toolActivities:ce,activeToolCalls:le,pendingToolApproval:ue,decideToolApproval:de}=dt(u?.id||``),fe=ee(),me=(0,Q.useMemo)(()=>({model:g,providerType:v,providerId:b}),[g,b,v]),he=(0,Q.useMemo)(()=>h(f,me),[f,me]),ge=g?T(he,me):``,_e=y(f,me),ve=new URLSearchParams(o.search).get(`incognito`)===`1`,[be,xe]=(0,Q.useState)(nt),[Se,Ce]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(!1),we=tt(e=>e.preferences.showFollowUpSuggestions!==!1),Te=(0,Q.useRef)(null),Ee=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=u?.id,t=Ee.current&&!N;if(Ee.current=N,!e||N||!we||u?.isPrivate||!t)return;let n=u.messages[u.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||Te.current===n.id)return;Te.current=n.id;let r=!1;return J.generateFollowUps(e).then(t=>{r||!t.success||D.getState().currentSession?.id===e&&Ce({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[N,u,we]);let De=Se&&Se.sessionId===u?.id?Se.suggestions:[],z=(0,Q.useMemo)(()=>fr(be,k?.username,e,m(t.language)),[t.language,e,k?.username,be]),[B,V]=(0,Q.useState)(``),[ke,H]=(0,Q.useState)([]),[Ae,je]=(0,Q.useState)(!1),[U,W]=(0,Q.useState)(!1),[Ne,Pe]=(0,Q.useState)(Fn),[G,Ie]=(0,Q.useState)(!1),Le=(0,Q.useRef)(null),Re=D(e=>e.draftSessionSettings),ze=D(e=>e.setDraftSessionSettings),Be=Re.generationOptions?.think,q=tt(e=>(g?e.preferences.modelGenerationOptions?.[g]?.think:void 0)??e.preferences.generationOptions?.think??null),He=(0,Q.useMemo)(()=>f.find(e=>e.name===g),[f,g]),[Y,Ue]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!g||f.length===0||!He||He.isPlugin||He.isAgent)return;let e=!1;return $e.getModelDefaults(g).then(t=>{e||!t.success||!t.data||Ue({model:g,supported:t.data.supportsThinking})}).catch(()=>{}),()=>{e=!0}},[g,He,f.length]);let We=!!(g&&!He?.isAgent&&(He?.isPlugin?He.reasoningSupport!==!1:Y?.model!==g||Y.supported!==!1)),Ge=e=>{let t=D.getState().draftSessionSettings,n={...t.generationOptions};e===null?delete n.think:n.think=e,ze({...t,generationOptions:Object.keys(n).length?n:void 0})},Ke=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){Ie(!0);try{let t=await qe.uploadDocument(n);t.success?(K.success(e(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):K.error(t.error||e(`chat.input.menu.attachFailed`))}catch(t){ur.error(`Document upload failed:`,t),K.error(e(`chat.input.menu.attachFailed`))}finally{Ie(!1)}}};(0,Q.useEffect)(()=>{let e=!1;return Qe.getConfig().then(t=>{!e&&t.success&&t.data&&je(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[Je,Ye]=(0,Q.useState)(!1),Xe=(0,Q.useRef)(null),Ze=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{xe(nt())};return window.addEventListener(it,e),()=>window.removeEventListener(it,e)},[]);let[rt,ot]=(0,Q.useState)(!1),[st,Z]=(0,Q.useState)(!1),lt=pr(u?.messages),ut=A&&rt,ft=(0,Q.useCallback)((t=!0)=>{let n=g?me:f[0]?_(f[0]):null;if(!n||!y(f,n))return t&&K.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return w({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},[f,g,me,w,e]);(0,Q.useEffect)(()=>{d.length===0&&E()},[E,d.length]),(0,Q.useEffect)(()=>{!ve||u?.isPrivate||ft(!1)},[u?.isPrivate,ve,ft]),(0,Q.useEffect)(()=>{let e=!1;return A&&(async()=>{try{let t=await Ve.getPlugins();if(e)return;ot(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ot(!1)}})(),()=>{e=!0}},[A]),(0,Q.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?w(e):e||(ur.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&&o.pathname===`/`&&r(`/c/${d[0].id}`,{replace:!0})}})()},[n,d,w,r,u?.id,u?.isPrivate,o.pathname]),(0,Q.useEffect)(()=>{if(u?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{te(t.content,t.images,void 0,t.webSearch===!0,t.tools===!0,t.toolSelection)},100)}catch(e){ur.error(`Failed to parse pending message:`,e)}}}},[u?.id,te]),(0,Q.useEffect)(()=>{let e=Xe.current;e&&(e.style.height=`auto`,e.style.height=B?`${Math.min(e.scrollHeight,200)}px`:``)},[B]);let pt=async t=>{if(t.preventDefault(),!B.trim()||!g)return;if(!_e){K.error(e(`chat.model.selectBeforeSending`));return}at(`impact`);let n={content:B.trim(),images:ke.length>0?ke:void 0,webSearch:Ae&&U?!0:void 0,...In(Ne)};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),V(``),H([]),W(!1),Pe(Fn);let i=await C(g,void 0,g.startsWith(`persona:`)?g.slice(8):void 0,v,b);i&&(await mt(i),r(`/c/${i.id}`,{replace:!0}))},mt=(0,Q.useCallback)(async e=>{let t=D.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions;if(!n&&!r)return;let i=n?[{id:l(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await J.updateSession(e.id,{messages:i,settings:r?{generationOptions:r}:void 0});if(t.success&&t.data){let e=t.data;D.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){ur.error(`Failed to apply chat settings to the new session`,e)}finally{D.getState().setDraftSessionSettings({})}},[]),ht=e=>{Ze.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),pt(e))},gt=async e=>{let t=O(he,e.target.value);t&&x(t.model,t.providerType,t.providerId)},_t=(e,t,n,r,i,a,o)=>{u&&(at(`impact`),Ce(null),te(e,t,n,r,i,a,o))},vt=async t=>{if(u)try{let n=await J.forkSession(u.id,{messageId:t});if(n.success&&n.data){let t=n.data;D.setState(e=>({sessions:[t,...e.sessions]})),K.success(e(`chat.fork.created`)),r(`/c/${t.id}`)}else K.error(n.error||e(`chat.fork.failed`))}catch(t){ur.error(`Failed to fork the chat:`,t),K.error(e(`chat.fork.failed`))}};if(!u){let t=ke.length>0;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`relative h-full min-w-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,$.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,$.jsx)(`div`,{className:`absolute left-[12%] top-[18%] h-56 w-56 rounded-full bg-primary-500/[0.035] blur-3xl dark:bg-primary-400/[0.04]`}),(0,$.jsx)(`div`,{className:`absolute bottom-[16%] right-[10%] h-72 w-72 rounded-full bg-gray-900/[0.025] blur-3xl dark:bg-white/[0.025]`}),(0,$.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,$.jsx)(`button`,{onClick:()=>R(e=>!e),className:p(`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`,L&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":L,children:(0,$.jsx)(P,{className:`h-4 w-4`})}),(0,$.jsxs)(`button`,{onClick:()=>ft(),disabled:!g&&f.length===0||!!g&&!_e,className:`absolute end-[3.75rem] top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-surface/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-[4.25rem] sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,$.jsx)(Oe,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{children:e(`chat.session.incognito`,`Incognito Chat`)})]}),(0,$.jsxs)(`div`,{className:`relative z-[1] mx-auto flex min-h-full w-full max-w-3xl flex-col items-center justify-center`,children:[(0,$.jsxs)(`div`,{className:`mb-8 flex flex-col items-center text-center animate-fade-in sm:mb-10`,"aria-live":`polite`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-center gap-3`,children:[(0,$.jsx)(ct,{size:`sm`,label:null,className:`h-9 w-9 shrink-0 p-0 text-ink`}),(0,$.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:z.title})]}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-[15px] leading-relaxed text-ink-subtle`,children:z.subtitle})]},z.id),he.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[Je&&(0,$.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,$.jsx)(lr,{images:ke,onImagesChange:H,maxImages:5}),(0,$.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,$.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:e(`chat.input.menu.attachDocument`)}),(0,$.jsxs)(X,{type:`button`,size:`sm`,variant:`outline`,disabled:G,onClick:()=>Le.current?.click(),className:`shrink-0 whitespace-nowrap`,children:[(0,$.jsx)(Me,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`ms-1.5`,children:e(G?`documents.uploading`:`chat.input.menu.attach`)})]}),(0,$.jsx)(`input`,{ref:Le,type:`file`,accept:En,className:`hidden`,onChange:e=>void Ke(e)})]})]}),(0,$.jsx)(`form`,{onSubmit:pt,children:(0,$.jsxs)(`div`,{className:p(`relative 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,$.jsx)(Mn,{ref:Ze,message:B,onApply:e=>{V(e),Xe.current?.focus()}}),(0,$.jsx)(ln,{ref:Xe,value:B,onChange:e=>V(e.target.value),onKeyDown:ht,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,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Ye(!Je),className:p(`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`,Je&&`bg-hover-solid text-ink`),title:e(`chat.input.attachImages`),children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Me,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):Je?(0,$.jsx)(ye,{className:`h-4 w-4`}):(0,$.jsx)(oe,{className:`h-4 w-4`})}),We&&(0,$.jsx)(_n,{value:Be,inheritedValue:q,onChange:Ge}),Ae&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>W(e=>!e),className:p(`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`,U&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:e(U?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":U,children:(0,$.jsx)(pe,{className:`h-4 w-4`})}),(0,$.jsx)(Pn,{value:Ne,onChange:Pe,buttonClassName:`h-9 w-9`}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Dt,{models:he,selectedModel:ge,onModelChange:gt,getModelValue:S,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:ut})}),(0,$.jsx)(X,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!B.trim()||!g||!_e,className:p(`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,$.jsx)(Fe,{className:`h-4 w-4`})})]})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(Dt,{models:he,selectedModel:ge,onModelChange:gt,getModelValue:S,className:`w-full`,compact:!0,showImageGen:ut})}),(0,$.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,$.jsxs)(`div`,{className:`flex w-full max-w-lg flex-col items-center gap-4`,children:[(0,$.jsx)(`p`,{className:`text-center text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.connectDescription`)}),(0,$.jsx)(bt,{variant:`inline`})]})]})]}),(0,$.jsx)(nr,{draftModel:g,open:L,onClose:()=>R(!1)})]})}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:fe?.background?{backgroundImage:`url(${fe.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[fe?.background&&(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,$.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[u?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(Oe,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,$.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),fe&&!u?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,$.jsx)(cr,{persona:fe,onClear:()=>{u&&J.updateSession(u.id,{model:fe.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);D.setState(t=>({sessions:t.sessions.map(t=>t.id===u.id?e.data:t),currentSession:e.data}))}).catch(t=>{ur.error(`Failed to remove persona:`,t),K.error(e(`chat.persona.removeFailed`))})}})}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`button`,{onClick:()=>R(e=>!e),className:p(`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`,L&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":L,children:(0,$.jsx)(P,{className:`h-3.5 w-3.5`})}),u.settings?.forkedFrom&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(`/c/${u.settings.forkedFrom.sessionId}`),className:`mx-auto mt-2 flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-3 py-1 text-[11px] text-gray-500 transition-colors hover:text-gray-800 dark:border-white/[0.08] dark:bg-dark-200/70 dark:text-dark-600 dark:hover:text-dark-900`,"data-testid":`forked-from-banner`,children:[(0,$.jsx)(se,{className:`h-3 w-3`}),e(`chat.fork.origin`,{title:u.settings.forkedFrom.title||e(`chat.fork.originUnknown`)})]}),(0,$.jsx)(sn,{messages:u.messages,streamingMessage:F,streamingThinking:I,streamingMessageId:ae,isStreaming:N,toolActivities:ce,activeToolCalls:le,pendingToolApproval:ue,onDecideToolApproval:de,onRegenerate:ne,onSelectBranch:ie,onEditResend:re,onFork:e=>void vt(e),followUpSuggestions:De,onFollowUpSelect:e=>_t(e),className:`flex-1`}),u?.shared?(0,$.jsx)(`div`,{className:`mx-auto mb-4 w-full max-w-3xl rounded-xl border border-black/[0.06] bg-black/[0.02] px-4 py-3 text-center text-[13px] text-gray-500 dark:border-white/[0.08] dark:bg-white/[0.03] dark:text-dark-600`,"data-testid":`chat-shared-readonly`,children:e(`chat.sharedReadOnly`,{owner:u.shared.ownerUserId})}):(0,$.jsx)(zn,{onSendMessage:_t,onStopGeneration:j,onCancelComparison:M,onOpenVoiceMode:()=>Z(!0),disabled:!u})]}),st&&u&&(0,$.jsx)($n,{onClose:()=>Z(!1),onSendMessage:e=>_t(e),isStreaming:N,lastAssistantMessage:lt}),u&&(0,$.jsx)(sr,{session:u}),(0,$.jsx)(nr,{session:u,open:L,onClose:()=>R(!1)})]})]})]})};export{mr as ChatPage,mr as default};