libre-webui 0.44.1 → 0.45.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 (220) hide show
  1. package/backend/dist/index.d.ts.map +1 -1
  2. package/backend/dist/index.js +2 -0
  3. package/backend/dist/index.js.map +1 -1
  4. package/backend/dist/routes/chat.d.ts.map +1 -1
  5. package/backend/dist/routes/chat.js +10 -2
  6. package/backend/dist/routes/chat.js.map +1 -1
  7. package/backend/dist/routes/decisions.d.ts +3 -0
  8. package/backend/dist/routes/decisions.d.ts.map +1 -0
  9. package/backend/dist/routes/decisions.js +148 -0
  10. package/backend/dist/routes/decisions.js.map +1 -0
  11. package/backend/dist/services/apiTokenService.d.ts.map +1 -1
  12. package/backend/dist/services/apiTokenService.js +2 -0
  13. package/backend/dist/services/apiTokenService.js.map +1 -1
  14. package/backend/dist/services/authorizationService.d.ts +1 -1
  15. package/backend/dist/services/authorizationService.d.ts.map +1 -1
  16. package/backend/dist/services/authorizationService.js +8 -1
  17. package/backend/dist/services/authorizationService.js.map +1 -1
  18. package/backend/dist/services/chatGenerationService.d.ts +24 -2
  19. package/backend/dist/services/chatGenerationService.d.ts.map +1 -1
  20. package/backend/dist/services/chatGenerationService.js +72 -4
  21. package/backend/dist/services/chatGenerationService.js.map +1 -1
  22. package/backend/dist/services/chatRequestService.d.ts +11 -3
  23. package/backend/dist/services/chatRequestService.d.ts.map +1 -1
  24. package/backend/dist/services/chatRequestService.js +19 -3
  25. package/backend/dist/services/chatRequestService.js.map +1 -1
  26. package/backend/dist/services/contextCompactionService.d.ts.map +1 -1
  27. package/backend/dist/services/contextCompactionService.js +8 -0
  28. package/backend/dist/services/contextCompactionService.js.map +1 -1
  29. package/backend/dist/services/decisionAccessService.d.ts +16 -0
  30. package/backend/dist/services/decisionAccessService.d.ts.map +1 -0
  31. package/backend/dist/services/decisionAccessService.js +71 -0
  32. package/backend/dist/services/decisionAccessService.js.map +1 -0
  33. package/backend/dist/services/decisionService.d.ts +128 -0
  34. package/backend/dist/services/decisionService.d.ts.map +1 -0
  35. package/backend/dist/services/decisionService.js +515 -0
  36. package/backend/dist/services/decisionService.js.map +1 -0
  37. package/backend/dist/services/durableChatGenerationService.d.ts.map +1 -1
  38. package/backend/dist/services/durableChatGenerationService.js +13 -2
  39. package/backend/dist/services/durableChatGenerationService.js.map +1 -1
  40. package/backend/dist/services/ollamaService.d.ts +6 -0
  41. package/backend/dist/services/ollamaService.d.ts.map +1 -1
  42. package/backend/dist/services/ollamaService.js +13 -0
  43. package/backend/dist/services/ollamaService.js.map +1 -1
  44. package/backend/dist/types/index.d.ts +38 -1
  45. package/backend/dist/types/index.d.ts.map +1 -1
  46. package/backend/dist/types/index.js.map +1 -1
  47. package/backend/dist/utils/decisionProtocol.d.ts +164 -0
  48. package/backend/dist/utils/decisionProtocol.d.ts.map +1 -0
  49. package/backend/dist/utils/decisionProtocol.js +755 -0
  50. package/backend/dist/utils/decisionProtocol.js.map +1 -0
  51. package/backend/dist/utils/ollamaLibrary.d.ts.map +1 -1
  52. package/backend/dist/utils/ollamaLibrary.js +26 -7
  53. package/backend/dist/utils/ollamaLibrary.js.map +1 -1
  54. package/backend/dist/utils/pluginDefinitionTrust.d.ts.map +1 -1
  55. package/backend/dist/utils/pluginDefinitionTrust.js +51 -7
  56. package/backend/dist/utils/pluginDefinitionTrust.js.map +1 -1
  57. package/backend/dist/utils/pluginModelCatalog.d.ts +4 -2
  58. package/backend/dist/utils/pluginModelCatalog.d.ts.map +1 -1
  59. package/backend/dist/utils/pluginModelCatalog.js +12 -2
  60. package/backend/dist/utils/pluginModelCatalog.js.map +1 -1
  61. package/backend/dist/websocketServer.d.ts.map +1 -1
  62. package/backend/dist/websocketServer.js +23 -6
  63. package/backend/dist/websocketServer.js.map +1 -1
  64. package/backend/package.json +2 -2
  65. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  66. package/frontend/dist/artifact-runtime/babel.js +172 -172
  67. package/frontend/dist/artifact-runtime/framer-motion.js +2 -2
  68. package/frontend/dist/artifact-runtime/lucide-react.js +1 -1
  69. package/frontend/dist/artifact-runtime/papaparse.js +2 -2
  70. package/frontend/dist/artifact-runtime/plotly.js +5 -5
  71. package/frontend/dist/artifact-runtime/tailwind.js +16 -16
  72. package/frontend/dist/assets/index-C2A5Ko4-.js +59 -0
  73. package/frontend/dist/assets/index-FrFgrp5E.css +2 -0
  74. package/frontend/dist/index.html +28 -28
  75. package/frontend/dist/js/{ArtifactContainer-C2PgJwen.js → ArtifactContainer-DCCcjK16.js} +1 -1
  76. package/frontend/dist/js/{ArtifactDemoPage-Dcy-lVrh.js → ArtifactDemoPage-C-1acgxJ.js} +1 -1
  77. package/frontend/dist/js/{ArtifactSandboxFrame-C7gLjHfY.js → ArtifactSandboxFrame-BXWNhmtI.js} +1 -1
  78. package/frontend/dist/js/{ArtifactSlideOutPanel-BKZQ7VwV.js → ArtifactSlideOutPanel-CvfdP_o2.js} +1 -1
  79. package/frontend/dist/js/{AutomationModal-zImHyodn.js → AutomationModal-D7qiRMhj.js} +1 -1
  80. package/frontend/dist/js/{AutomationsPage-BuJ1Y810.js → AutomationsPage-v98Ucl9p.js} +1 -1
  81. package/frontend/dist/js/{AvatarUpload-BECcVNWc.js → AvatarUpload-W41SCHKE.js} +1 -1
  82. package/frontend/dist/js/{Button-BGE6ZJv5.js → Button-D6d7HYoa.js} +1 -1
  83. package/frontend/dist/js/{CalendarPage-hF8Gk80e.js → CalendarPage-DkAa61Pa.js} +1 -1
  84. package/frontend/dist/js/ChannelsPage-0Vnfpgdr.js +1 -0
  85. package/frontend/dist/js/ChatPage-iyMY-uoE.js +14 -0
  86. package/frontend/dist/js/{ConnectModels-DVd2RDUM.js → ConnectModels-CpWO6ALS.js} +1 -1
  87. package/frontend/dist/js/{EvaluationsPage-D_R88N9b.js → EvaluationsPage-C7WHA1MJ.js} +1 -1
  88. package/frontend/dist/js/{FirstTimeSetup-CQQUhpPj.js → FirstTimeSetup-B8wcelBc.js} +1 -1
  89. package/frontend/dist/js/{GalleryPage-BYyAx84l.js → GalleryPage-u7dYKl3q.js} +1 -1
  90. package/frontend/dist/js/{HomePage-BRjiDJZa.js → HomePage-Cjlt3b9n.js} +1 -1
  91. package/frontend/dist/js/{LanguageSwitcher-0vFsK1v-.js → LanguageSwitcher-gbTZY15P.js} +1 -1
  92. package/frontend/dist/js/{Logo-GlNrhpKp.js → Logo-DhV6D_3q.js} +1 -1
  93. package/frontend/dist/js/{LogoMark-rgOHhWo-.js → LogoMark-CmF1lHXT.js} +1 -1
  94. package/frontend/dist/js/{ModelManagerModals-BK0iqnHd.js → ModelManagerModals-12hL-b-U.js} +1 -1
  95. package/frontend/dist/js/{NotesPage-DD6EntAT.js → NotesPage-BQWBA5li.js} +2 -2
  96. package/frontend/dist/js/{PasswordStrengthMeter-DrXjBWiT.js → PasswordStrengthMeter-DdqX0FXA.js} +1 -1
  97. package/frontend/dist/js/PersonasPage-B8mFdWcX.js +13 -0
  98. package/frontend/dist/js/{PluginUsagePage-BBfqotzy.js → PluginUsagePage-Uz6aHPIp.js} +1 -1
  99. package/frontend/dist/js/{RichMessageContent-BcBbr-Q2.js → RichMessageContent-CVk-fp0N.js} +1 -1
  100. package/frontend/dist/js/{RichMessageContent-Cdz4MI7q.js → RichMessageContent-DwMoWuR_.js} +1 -1
  101. package/frontend/dist/js/SettingsModal-CfjxNSmJ.js +19 -0
  102. package/frontend/dist/js/{SettingsToggle-BT6cbOnw.js → SettingsToggle-CNUeo6DO.js} +1 -1
  103. package/frontend/dist/js/{ShareDialog-CTZp6YtI.js → ShareDialog-NwirTDLR.js} +1 -1
  104. package/frontend/dist/js/{StrandsPage-BYY6YV5N.js → StrandsPage-ddHNdb6J.js} +1 -1
  105. package/frontend/dist/js/{SystemPage-DaDG0V07.js → SystemPage-C_1exwI7.js} +1 -1
  106. package/frontend/dist/js/UserManagementPanel-hg7ztEtL.js +1 -0
  107. package/frontend/dist/js/{WhatsNewModal-DgMfeACt.js → WhatsNewModal-yYk7N4KY.js} +1 -1
  108. package/frontend/dist/js/WorkPage-i7yYRAuj.js +7 -0
  109. package/frontend/dist/js/api-BU13N8gU.js +1 -0
  110. package/frontend/dist/js/{api-Bje32kcr.js → api-Dasm8tVY.js} +1 -1
  111. package/frontend/dist/js/{appNavigation-6Vs8h0Iv.js → appNavigation-DqP7fTWU.js} +1 -1
  112. package/frontend/dist/js/{appStore-DmeFFzzj.js → appStore-DCIUnT8X.js} +2 -2
  113. package/frontend/dist/js/appVersion-PJGaVilS.js +1 -0
  114. package/frontend/dist/js/ar-CsCftCVF.js +2 -0
  115. package/frontend/dist/js/authStore-Bp17zKvS.js +1 -0
  116. package/frontend/dist/js/{authStore-DUmjkugT.js → authStore-ac5-hjOH.js} +3 -3
  117. package/frontend/dist/js/babel-C4LPTjCL.js +16 -0
  118. package/frontend/dist/js/bn-CvxUTZ9a.js +2 -0
  119. package/frontend/dist/js/chatStore-GhucyjJu.js +3 -0
  120. package/frontend/dist/js/{client-DIxMEDnJ.js → client-DxPoTB_C.js} +2 -2
  121. package/frontend/dist/js/{config-HBTc75oS.js → config-CQJEcQtz.js} +1 -1
  122. package/frontend/dist/js/cs-BovmMwcD.js +2 -0
  123. package/frontend/dist/js/da-Dof1gmsv.js +2 -0
  124. package/frontend/dist/js/de-CF9CXojW.js +2 -0
  125. package/frontend/dist/js/decisionsApi-BWB64EGn.js +1 -0
  126. package/frontend/dist/js/decisionsApi-CoJtg4PZ.js +1 -0
  127. package/frontend/dist/js/es-BXCt50HZ.js +2 -0
  128. package/frontend/dist/js/estree-DCoUd_wj.js +44 -0
  129. package/frontend/dist/js/{evaluationsApi-CJ9eIoSl.js → evaluationsApi-CBqKkjmI.js} +1 -1
  130. package/frontend/dist/js/fr-B5QcCDIw.js +2 -0
  131. package/frontend/dist/js/hi-BXYwSyKl.js +2 -0
  132. package/frontend/dist/js/html-DMnBrAcs.js +25 -0
  133. package/frontend/dist/js/id-BV3mY5L7.js +2 -0
  134. package/frontend/dist/js/is-BDK4LrQC.js +2 -0
  135. package/frontend/dist/js/it-DAeWl1Fm.js +2 -0
  136. package/frontend/dist/js/ja-DIJV01rA.js +2 -0
  137. package/frontend/dist/js/ko-Btr9-64X.js +2 -0
  138. package/frontend/dist/js/markdown-CQ4enQcD.js +70 -0
  139. package/frontend/dist/js/{messageCodeStyles-C0H1Lad5.js → messageCodeStyles-BugWE4s5.js} +2 -2
  140. package/frontend/dist/js/ms-DgVmv5zF.js +2 -0
  141. package/frontend/dist/js/nl-Dz5HpdLi.js +2 -0
  142. package/frontend/dist/js/pl-CIATY2b0.js +2 -0
  143. package/frontend/dist/js/postcss-CZstCllf.js +62 -0
  144. package/frontend/dist/js/pt-lrDXX76Y.js +2 -0
  145. package/frontend/dist/js/ru-_zovUYcg.js +2 -0
  146. package/frontend/dist/js/standalone-CttwqOis.js +29 -0
  147. package/frontend/dist/js/{strandsApi-Cuqp8JZv.js → strandsApi-Ck7FrcHH.js} +1 -1
  148. package/frontend/dist/js/sv-TkRDWCb8.js +2 -0
  149. package/frontend/dist/js/{teamEventStream-DHeJw2eu.js → teamEventStream-O3qGbUZz.js} +1 -1
  150. package/frontend/dist/js/th-CQyavDiP.js +2 -0
  151. package/frontend/dist/js/tr-CBcFl4_Z.js +2 -0
  152. package/frontend/dist/js/typescript-h2bi7nrV.js +22 -0
  153. package/frontend/dist/js/{ui-BPtWIxXL.js → ui-DxaHE9GD.js} +2 -2
  154. package/frontend/dist/js/{ui-vendor-Bac5e8jE.js → ui-vendor-DsURZnZt.js} +1 -1
  155. package/frontend/dist/js/uk-BNn1cUt8.js +2 -0
  156. package/frontend/dist/js/{useChat-DjRbGblw.js → useChat-1HyAPpCk.js} +1 -1
  157. package/frontend/dist/js/useDictation-B3vNgs5D.js +1 -0
  158. package/frontend/dist/js/{useQuery-DCqz3UJt.js → useQuery-Cs76KYuP.js} +1 -1
  159. package/frontend/dist/js/useTranslation-CKqEdZ8j.js +1 -0
  160. package/frontend/dist/js/utils-BXRzbHJC.js +1 -0
  161. package/frontend/dist/js/{utils-vendor-CsC5rH1J.js → utils-vendor-B4bGLP5p.js} +1 -1
  162. package/frontend/dist/js/vi-Be8GO7e_.js +2 -0
  163. package/frontend/dist/js/{workApi-Dkf48LjA.js → workApi-BNGRSv7q.js} +1 -1
  164. package/frontend/dist/js/workApi-C5jw1ra6.js +1 -0
  165. package/frontend/dist/js/yaml-CBt8G4BX.js +150 -0
  166. package/frontend/dist/js/zh-9CUKyYw5.js +2 -0
  167. package/package.json +4 -4
  168. package/plugins/baseten.json +17 -0
  169. package/plugins/gemini.json +9 -0
  170. package/plugins/llama-cpp.json +13 -0
  171. package/plugins/openai.json +13 -0
  172. package/plugins/openrouter.json +26 -0
  173. package/frontend/dist/assets/index-BM0txgxR.css +0 -2
  174. package/frontend/dist/assets/index-CYJjXpq5.js +0 -34
  175. package/frontend/dist/js/ChannelsPage-Bb7qgmXS.js +0 -1
  176. package/frontend/dist/js/ChatPage-BkMm-S6C.js +0 -14
  177. package/frontend/dist/js/PersonasPage-CkGtixCB.js +0 -13
  178. package/frontend/dist/js/SettingsModal-CKtlOet9.js +0 -19
  179. package/frontend/dist/js/UserManagementPanel-B7SuWPQg.js +0 -1
  180. package/frontend/dist/js/WorkPage-CVcyA61Q.js +0 -7
  181. package/frontend/dist/js/api-BSMl2Tok.js +0 -1
  182. package/frontend/dist/js/appVersion-DWwbhdm2.js +0 -1
  183. package/frontend/dist/js/ar-yKmq_nxn.js +0 -2
  184. package/frontend/dist/js/authStore-DQ-PhUey.js +0 -1
  185. package/frontend/dist/js/babel-BaOs8qJH.js +0 -16
  186. package/frontend/dist/js/bn-DAJjz2xA.js +0 -2
  187. package/frontend/dist/js/chatStore-Di86sm3T.js +0 -3
  188. package/frontend/dist/js/cs-BcctV9SN.js +0 -2
  189. package/frontend/dist/js/da-YtnjzG18.js +0 -2
  190. package/frontend/dist/js/de-BMQofu0d.js +0 -2
  191. package/frontend/dist/js/es-8oFYsnHw.js +0 -2
  192. package/frontend/dist/js/estree-Cw-tQG5d.js +0 -44
  193. package/frontend/dist/js/fr-CnGTnuJK.js +0 -2
  194. package/frontend/dist/js/hi-Ct5Inbp9.js +0 -2
  195. package/frontend/dist/js/html-Drt7kOJE.js +0 -25
  196. package/frontend/dist/js/id-CSqCL3hQ.js +0 -2
  197. package/frontend/dist/js/is-Bg68TmSt.js +0 -2
  198. package/frontend/dist/js/it-ZngXlxOR.js +0 -2
  199. package/frontend/dist/js/ja-DfQEoeFi.js +0 -2
  200. package/frontend/dist/js/ko-IifYVGBy.js +0 -2
  201. package/frontend/dist/js/markdown-C7cnJl_Q.js +0 -70
  202. package/frontend/dist/js/ms-C8jQLzkg.js +0 -2
  203. package/frontend/dist/js/nl-BFEa3rgC.js +0 -2
  204. package/frontend/dist/js/pl-BiPrQGU-.js +0 -2
  205. package/frontend/dist/js/postcss-DB_e0nkW.js +0 -62
  206. package/frontend/dist/js/pt-BziWZm5q.js +0 -2
  207. package/frontend/dist/js/ru-oTAEePGS.js +0 -2
  208. package/frontend/dist/js/standalone-YobQElH8.js +0 -29
  209. package/frontend/dist/js/sv-1_et6OWH.js +0 -2
  210. package/frontend/dist/js/th-DjyLzIKs.js +0 -2
  211. package/frontend/dist/js/tr-CCga9CbK.js +0 -2
  212. package/frontend/dist/js/typescript-2anSzo_N.js +0 -22
  213. package/frontend/dist/js/uk-h80KE68A.js +0 -2
  214. package/frontend/dist/js/useDictation-C31FhomS.js +0 -1
  215. package/frontend/dist/js/useTranslation-D-_KTORQ.js +0 -1
  216. package/frontend/dist/js/utils-DsCVr_wG.js +0 -1
  217. package/frontend/dist/js/vi-CQxzmgwi.js +0 -2
  218. package/frontend/dist/js/workApi-D4JbAtE2.js +0 -1
  219. package/frontend/dist/js/yaml-Breo7DWT.js +0 -154
  220. package/frontend/dist/js/zh-CS3_ndbP.js +0 -2
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r}from"./router-vendor-DLHZHk4K.js";import{t as i}from"./useTranslation-CKqEdZ8j.js";import{$n as a,At as o,Fn as s,H as c,It as l,Or as u,Ot as d,Qt as f,Rt as ee,W as p,Zn as m,at as h,dr as te,er as ne,n as g,r as _,s as re,st as v,tt as y,ut as ie,v as ae,wn as b,yr as oe}from"./ui-vendor-DsURZnZt.js";import{_ as x,g as S,i as se,n as ce,r as C,t as w,v as T}from"./ui-DxaHE9GD.js";import{t as E}from"./confirmStore-CKkUtP9c.js";import{i as D,t as O}from"./utils-BXRzbHJC.js";import{t as k}from"./Button-D6d7HYoa.js";import{D as A}from"./api-Dasm8tVY.js";import{t as le}from"./teamEventStream-O3qGbUZz.js";import{t as ue}from"./authStore-ac5-hjOH.js";import{t as de}from"./chatStore-GhucyjJu.js";import{t as fe}from"./logger-DAQsBb8I.js";var j=e(t(),1),M=n(),pe=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],N=180,me=({calls:e})=>{let{t}=i(),[n,r]=(0,j.useState)(!1),o=e.some(e=>e.status===`denied`);return(0,M.jsxs)(`div`,{className:`mt-1`,"data-testid":`channel-tool-calls`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,className:`flex items-center gap-1 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,"data-testid":`channel-tool-calls-toggle`,children:[n?(0,M.jsx)(a,{className:`h-3 w-3`}):(0,M.jsx)(m,{className:`h-3 w-3`}),(0,M.jsx)(_,{className:`h-3 w-3`}),t(`channels.toolCalls.summary`,{total:e.length})]}),n&&(0,M.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[e.map(e=>(0,M.jsxs)(`div`,{className:`rounded-lg border border-black/6 px-2 py-1 dark:border-white/8`,"data-testid":`channel-tool-call`,children:[(0,M.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,M.jsx)(`span`,{dir:`ltr`,className:`min-w-0 truncate text-[11px] font-medium text-gray-700 dark:text-dark-800`,children:e.name}),(0,M.jsx)(`span`,{className:O(`shrink-0 text-[10px]`,e.status===`succeeded`?`text-emerald-600 dark:text-emerald-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:e.status===`failed`?`text-red-500`:`text-gray-400 dark:text-dark-500`),children:t(`tools.callStatus.${e.status}`)})]}),e.resultPreview&&(0,M.jsx)(`p`,{dir:`ltr`,className:`mt-0.5 whitespace-pre-wrap wrap-break-word font-mono text-[10px] leading-snug text-gray-500 dark:text-dark-600`,children:e.resultPreview.slice(0,N)})]},e.id)),o&&(0,M.jsx)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:t(`channels.toolCalls.deniedHint`)})]})]})},he=({message:e,currentUserId:t,canModerate:n,actions:r,compact:a=!1})=>{let{t:o,i18n:s}=i(),[c,l]=(0,j.useState)(!1),[u,f]=(0,j.useState)(e.content),[p,m]=(0,j.useState)(!1),_=e.authorKind===`model`,re=!_&&e.author?.userId===t&&!e.deleted,y=_?e.model??o(`channels.modelAuthor`):e.author?.username??o(`channels.unknownAuthor`);return(0,M.jsxs)(`div`,{className:O(`group relative rounded-xl px-2.5 py-1.5 hover:bg-black/2.5 dark:hover:bg-white/3`,a&&`px-2 py-1`),"data-testid":`channel-message`,children:[(0,M.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[_&&(0,M.jsx)(te,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,M.jsx)(`span`,{className:O(`shrink-0 text-[13px] font-semibold`,_?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:y}),(0,M.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:D(e.createdAt,s.language)}),e.editedAt&&!e.deleted&&(0,M.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:o(`channels.edited`)}),e.pinnedAt&&(0,M.jsx)(h,{role:`img`,"aria-label":o(`channels.pins`),className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,M.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:o(`channels.deletedMessage`)}):c?(0,M.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,M.jsx)(`textarea`,{value:u,onChange:e=>f(e.target.value),rows:2,"aria-label":o(`channels.edit`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2 py-1 text-[13px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-message-edit`}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,u),l(!1)},"aria-label":o(`channels.confirmEdit`),title:o(`channels.confirmEdit`),className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,M.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>l(!1),"aria-label":o(`channels.cancelEdit`),title:o(`channels.cancelEdit`),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}):(0,M.jsxs)(M.Fragment,{children:[e.pending?(0,M.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,M.jsx)(ee,{className:`h-3.5 w-3.5 animate-spin`}),o(`channels.modelThinking`)]}):e.error?(0,M.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,M.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),_&&(e.toolCalls?.length??0)>0&&(0,M.jsx)(me,{calls:e.toolCalls}),(e.attachments?.length??0)>0&&(0,M.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>void r.onDownload(e.id,e.filename),className:`flex items-center gap-1.5 rounded-lg border border-black/6 px-2 py-1 text-[12px] text-gray-600 hover:bg-black/3 dark:border-white/8 dark:text-dark-700 dark:hover:bg-white/4`,"data-testid":`channel-attachment`,children:[(0,M.jsx)(ie,{className:`h-3 w-3`}),(0,M.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,M.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,M.jsxs)(`button`,{type:`button`,"aria-pressed":t.mine,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/8 text-gray-600 hover:bg-black/3 dark:border-white/10 dark:text-dark-700`),"data-testid":`channel-reaction`,children:[t.emoji,` `,t.count]},t.emoji))}),!a&&(e.replyCount??0)>0&&r.onReply&&(0,M.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,M.jsx)(d,{className:`h-3 w-3`}),o(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!c&&(0,M.jsxs)(`div`,{className:`absolute -top-2.5 inset-e-2 hidden items-center gap-0.5 rounded-lg border border-black/8 bg-white px-1 py-0.5 shadow-xs group-focus-within:flex group-hover:flex [@media(hover:none)]:flex dark:border-white/10 dark:bg-dark-50`,children:[(0,M.jsxs)(`div`,{className:`relative`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.react`),"aria-label":o(`channels.react`),"aria-haspopup":`true`,"aria-expanded":p,"data-testid":`channel-react`,children:(0,M.jsx)(b,{className:`h-3.5 w-3.5`})}),p&&(0,M.jsx)(`div`,{className:`absolute inset-e-0 top-6 z-10 flex gap-0.5 rounded-lg border border-black/8 bg-white p-1 shadow-md dark:border-white/10 dark:bg-dark-50`,children:pe.map(t=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>{let n=!!e.reactions?.find(e=>e.emoji===t)?.mine;r.onReact(e,t,n),m(!1)},"aria-label":o(`channels.reactWith`,{emoji:t}),className:`rounded-sm p-0.5 text-sm hover:bg-black/5 dark:hover:bg-white/8`,children:t},t))})]}),r.onReply&&!e.parentId&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.reply`),"aria-label":o(`channels.reply`),"data-testid":`channel-reply`,children:(0,M.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>void r.onPin(e),className:`rounded-sm p-1 text-gray-400 hover:text-amber-500`,title:e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"aria-label":e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"data-testid":`channel-pin`,children:(0,M.jsx)(h,{className:`h-3.5 w-3.5`})}),re&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>{f(e.content),l(!0)},className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.edit`),"aria-label":o(`channels.edit`),"data-testid":`channel-edit`,children:(0,M.jsx)(v,{className:`h-3.5 w-3.5`})}),(re||n)&&(0,M.jsx)(`button`,{type:`button`,onClick:async()=>{await E({title:o(`channels.deleteMessageConfirmTitle`),description:o(`channels.deleteMessageConfirmDescription`),destructive:!0})&&await r.onDelete(e)},className:`rounded-sm p-1 text-gray-400 hover:text-red-500`,title:o(`channels.deleteMessage`),"aria-label":o(`channels.deleteMessage`),"data-testid":`channel-delete-message`,children:(0,M.jsx)(ae,{className:`h-3.5 w-3.5`})})]})]})},P=fe(`pages:channels`),ge=e=>e.type===`dm`?(0,M.jsx)(o,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,M.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}):(0,M.jsx)(f,{className:`h-3.5 w-3.5 shrink-0`}),F=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,_e=()=>{let{t:e}=i(),t=ue(e=>e.user),n=de(e=>e.models),[a,l]=(0,j.useState)([]),[m,ne]=(0,j.useState)(null),[_,v]=(0,j.useState)(!1),[ae,b]=(0,j.useState)(!1),[x,S]=(0,j.useState)(!0),[w,T]=(0,j.useState)(null),[D,fe]=(0,j.useState)(null),[pe,N]=(0,j.useState)([]),[me,_e]=(0,j.useState)([]),[I,L]=(0,j.useState)(null),[R,z]=(0,j.useState)(null),[Se,Ce]=(0,j.useState)([]),[B,we]=(0,j.useState)(``),[V,Te]=(0,j.useState)(``),[H,Ee]=(0,j.useState)(!1),[U,De]=(0,j.useState)(null),[Oe,ke]=(0,j.useState)(!1),[Ae,je]=(0,j.useState)(!1),[W,Me]=(0,j.useState)(``),[Ne,G]=(0,j.useState)(!1),Pe=(0,j.useRef)(null),Fe=(0,j.useRef)(null),[Ie,Le]=r(),K=(0,j.useMemo)(()=>a.find(e=>e.id===w)??null,[a,w]),[Re,ze]=(0,j.useState)(null);w!==Re&&(ze(w),fe(null),z(null),L(null));let q=K?.role===`owner`,J=(0,j.useCallback)(()=>{A.listMine().then(e=>{e.success&&e.data&&l(e.data)}).catch(e=>P.error(`Failed to load channels:`,e)).finally(()=>S(!1))},[]);(0,j.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=Ie.get(`channel`);Y&&w!==Y&&T(Y),(0,j.useEffect)(()=>{Y&&Le({},{replace:!0})},[Y,Le]);let X=(0,j.useRef)(null);(0,j.useLayoutEffect)(()=>(X.current=w?{channelId:w,requestId:0}:null,()=>{X.current=null}),[w]);let Z=(0,j.useCallback)(t=>{let n=X.current;if(!n||n.channelId!==t)return;let r=++n.requestId;A.listMessages(t,{limit:100}).then(e=>{X.current===n&&n.requestId===r&&e.success&&e.data&&fe(e.data)}).catch(t=>{P.error(`Failed to load messages:`,t),u.error(e(`channels.loadFailed`),{id:`channels-load-failed`})})},[e]),Be=(0,j.useRef)(null);(0,j.useEffect)(()=>{Be.current=R},[R]);let Ve=(0,j.useCallback)(e=>{Z(e),A.markRead(e);let t=Be.current;t&&A.thread(t).then(e=>{e.success&&e.data&&Ce(e.data)}).catch(e=>P.error(`Failed to refresh thread:`,e))},[Z]);(0,j.useEffect)(()=>{if(!w)return;Z(w),A.markRead(w).then(J);let e=new AbortController;return le({path:`/channels/${w}/events`,signal:e.signal,onEvent:()=>Ve(w)}),()=>e.abort()},[w,Z,J,Ve]);let He=D?.length??0;(0,j.useEffect)(()=>{let e=Fe.current;e&&(e.scrollTop=e.scrollHeight)},[He,w]),(0,j.useEffect)(()=>{if(!w||!I)return;let t=t=>{P.error(`Failed to load channel panel:`,t),u.error(e(`channels.loadFailed`))};I===`members`?A.listMembers(w).then(e=>{e.success&&e.data?N(e.data):t(e.error)}).catch(t):A.listPins(w).then(e=>{e.success&&e.data?_e(e.data):t(e.error)}).catch(t)},[w,I,e]),(0,j.useEffect)(()=>{R&&A.thread(R).then(t=>{t.success&&t.data?Ce(t.data):u.error(e(`channels.loadFailed`))}).catch(t=>{P.error(`Failed to load thread:`,t),u.error(e(`channels.loadFailed`))})},[R,e]);let Ue=()=>{v(!0),b(!1),A.listPublic().then(e=>{e.success&&e.data?ne(e.data):b(!0)}).catch(e=>{P.error(`Failed to load public channels:`,e),b(!0)})},Q=async t=>{if(!w||H)return;let n=B.trim();if(n||U){Ee(!0);try{let r=await A.postMessage(w,{content:n,...t?{parentId:t}:{},...U?{attachmentIds:[U.id]}:{},...V?{mentionModel:V}:{}});if(r.success){if(we(``),De(null),Te(``),Z(w),t){let e=await A.thread(t);e.success&&e.data&&Ce(e.data)}}else u.error(r.error||e(`channels.sendFailed`))}catch(t){P.error(`Failed to send message:`,t),u.error(e(`channels.sendFailed`))}finally{Ee(!1)}}},We=async t=>{if(w)try{let n=await A.uploadAttachment(w,t);n.success&&n.data?De({id:n.data.id,filename:n.data.filename}):u.error(n.error||e(`channels.uploadFailed`))}catch(t){P.error(`Failed to upload attachment:`,t),u.error(e(`channels.uploadFailed`))}},Ge=async()=>{if(w&&W.trim()){if((await A.addMember(w,W.trim()).catch(()=>void 0))?.success){Me(``);let t=await A.listMembers(w).catch(()=>void 0);t?.success&&t.data&&N(t.data),u.success(e(`channels.memberAdded`))}else u.error(e(`channels.memberAddFailed`))}},Ke={onReply:e=>z(e.id),onEdit:async(t,n)=>{(await A.editMessage(t.id,n).catch(()=>void 0))?.success?w&&Z(w):u.error(e(`channels.editFailed`))},onDelete:async t=>{(await A.deleteMessage(t.id).catch(()=>void 0))?.success?w&&Z(w):u.error(e(`channels.deleteMessageFailed`))},onPin:async t=>{(await A.setPinned(t.id,!t.pinnedAt).catch(()=>void 0))?.success||u.error(e(`channels.pinFailed`)),w&&Z(w)},onReact:async(t,n,r)=>{(await(r?A.removeReaction(t.id,n):A.addReaction(t.id,n)).catch(()=>void 0))?.success||u.error(e(`channels.reactFailed`)),w&&Z(w)},onDownload:async(t,n)=>{try{let e=await A.downloadAttachment(t),r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch(t){P.error(`Failed to download attachment:`,t),u.error(e(`channels.downloadFailed`))}}},$=Se[0];return(0,M.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,M.jsxs)(`aside`,{className:O(`flex w-64 shrink-0 flex-col border-e border-black/6 dark:border-white/6`,w?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,M.jsx)(se,{title:e(`channels.title`),className:`gap-y-1 px-3`,actions:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`button`,{type:`button`,onClick:Ue,title:e(`channels.browsePublic`),"aria-label":e(`channels.browsePublic`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-browse`,children:(0,M.jsx)(s,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>je(!0),title:e(`channels.newDm`),"aria-label":e(`channels.newDm`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new-dm`,children:(0,M.jsx)(o,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>ke(!0),title:e(`channels.newChannel`),"aria-label":e(`channels.newChannel`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new`,children:(0,M.jsx)(y,{className:`h-4 w-4`})})]})}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:x?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):a.length===0?(0,M.jsx)(C,{icon:f,size:`sm`,title:e(`channels.empty`)}):a.map(t=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>T(t.id),className:O(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-[13px]`,w===t.id?`bg-black/5 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-600 hover:bg-black/3 dark:text-dark-700 dark:hover:bg-white/4`),"data-testid":`channel-item`,children:[ge(t),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:F(t)}),(t.unreadCount??0)>0&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`span`,{className:`rounded-full bg-primary-600 px-1.5 text-[10px] font-semibold leading-4 text-white`,"data-testid":`channel-unread`,"aria-hidden":`true`,children:t.unreadCount}),(0,M.jsx)(`span`,{className:`sr-only`,children:e(`channels.unreadCount`,{total:t.unreadCount})})]})]},t.id))})]}),(0,M.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-black/6 px-4 py-2.5 dark:border-white/6`,children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>T(null),"aria-label":e(`common.back`),title:e(`common.back`),className:`rounded-md p-1 text-gray-500 hover:bg-black/4 md:hidden dark:text-dark-600`,children:(0,M.jsx)(oe,{className:`h-4 w-4 rtl:rotate-180`})}),ge(K),(0,M.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:F(K)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(I===`pins`?null:`pins`),title:e(`channels.pins`),"aria-label":e(`channels.pins`),"aria-pressed":I===`pins`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-pins-toggle`,children:(0,M.jsx)(h,{className:`h-4 w-4`})}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(I===`members`?null:`members`),title:e(`channels.members`),"aria-label":e(`channels.members`),"aria-pressed":I===`members`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-members-toggle`,children:(0,M.jsx)(re,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>G(!0),title:e(`channels.settings`),"aria-label":e(`channels.settings`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-settings`,children:(0,M.jsx)(c,{className:`h-4 w-4`})})]}),(0,M.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,M.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,M.jsx)(`div`,{ref:Fe,className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-4 py-3 scrollbar-thin`,"data-testid":`channel-timeline`,children:D===null?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):D.length===0?(0,M.jsx)(C,{icon:d,size:`sm`,title:e(`channels.noMessages`)}):D.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke},e.id))}),(0,M.jsxs)(`div`,{className:`border-t border-black/6 p-3 dark:border-white/6`,children:[U&&(0,M.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-1.5 text-xs text-gray-600 dark:border-white/8 dark:text-dark-700`,children:[(0,M.jsx)(ie,{className:`h-3.5 w-3.5`}),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:U.filename}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>De(null),"aria-label":e(`channels.removeAttachment`),title:e(`channels.removeAttachment`),className:`rounded-sm p-0.5 text-gray-500 hover:text-red-500`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,M.jsx)(`input`,{ref:Pe,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&We(t),e.target.value=``}}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>Pe.current?.click(),title:e(`channels.attach`),"aria-label":e(`channels.attach`),className:`rounded-md p-2 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-attach`,children:(0,M.jsx)(ie,{className:`h-4 w-4`})}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,M.jsx)(te,{className:O(`h-4 w-4`,V?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,M.jsxs)(`select`,{value:V,onChange:e=>Te(e.target.value),className:`max-w-[130px] rounded-md border border-black/8 bg-transparent px-1 py-1 text-[11px] text-gray-600 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-dark-100 dark:text-dark-700`,title:e(`channels.askModel`),"aria-label":e(`channels.askModel`),"data-testid":`channel-mention-model`,children:[(0,M.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,M.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,M.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Q())},rows:1,placeholder:e(`channels.composerPlaceholder`),"aria-label":e(`channels.composerPlaceholder`),className:`max-h-32 min-w-0 flex-1 resize-none rounded-xl border border-black/8 bg-transparent px-3 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-composer`}),(0,M.jsx)(k,{size:`sm`,disabled:H||!B.trim()&&!U,onClick:()=>void Q(),"aria-label":e(`channels.send`),title:e(`channels.send`),"data-testid":`channel-send`,children:H?(0,M.jsx)(ee,{className:`h-4 w-4 animate-spin`}):(0,M.jsx)(p,{className:`h-4 w-4`})})]})]})]}),R&&(0,M.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-thread`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,M.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>z(null),"aria-label":e(`channels.closeThread`),title:e(`channels.closeThread`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:Se.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:{...Ke,onReply:void 0},compact:!0},e.id))}),(0,M.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/6 p-2 dark:border-white/6`,children:[(0,M.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),$&&Q($.id))},rows:1,placeholder:e(`channels.replyPlaceholder`),"aria-label":e(`channels.replyPlaceholder`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-thread-composer`}),(0,M.jsx)(k,{size:`sm`,disabled:H||!B.trim(),onClick:()=>$&&void Q($.id),"aria-label":e(`channels.send`),title:e(`channels.send`),children:(0,M.jsx)(p,{className:`h-3.5 w-3.5`})})]})]}),I&&(0,M.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-${I}-panel`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,M.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(I===`members`?`channels.members`:`channels.pins`)}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>L(null),"aria-label":e(`common.close`),title:e(`common.close`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,M.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,M.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:I===`members`?(0,M.jsxs)(M.Fragment,{children:[q&&K.type===`private`&&(0,M.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,M.jsx)(`input`,{type:`text`,value:W,onChange:e=>Me(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&Ge()},placeholder:e(`channels.invitePlaceholder`),"aria-label":e(`channels.invitePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent px-2 py-1 text-xs focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-800`,"data-testid":`channel-invite-name`}),(0,M.jsx)(k,{size:`sm`,disabled:!W.trim(),onClick:()=>void Ge(),"aria-label":e(`channels.invite`),title:e(`channels.invite`),"data-testid":`channel-invite-submit`,children:(0,M.jsx)(y,{className:`h-3.5 w-3.5`})})]}),pe.map(n=>(0,M.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,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,M.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,M.jsx)(`button`,{type:`button`,onClick:async()=>{await E({title:e(`channels.removeMemberConfirm`,{name:n.username}),description:e(`channels.removeMemberConfirmDescription`),confirmLabel:e(`common.remove`),destructive:!0})&&((await A.removeMember(K.id,n.userId).catch(()=>void 0))?.success?N(e=>e.filter(e=>e.userId!==n.userId)):u.error(e(`channels.removeMemberFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:e(`channels.removeMember`),"aria-label":e(`channels.removeMemberNamed`,{name:n.username}),children:(0,M.jsx)(g,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,M.jsx)(k,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:async()=>{await E({title:e(`channels.leaveConfirm`,{name:F(K)}),description:e(`channels.leaveConfirmDescription`),confirmLabel:e(`channels.leave`),destructive:!0})&&((await A.removeMember(K.id,t?.id??``).catch(()=>void 0))?.success?(T(null),J()):u.error(e(`channels.leaveFailed`)))},"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):me.length===0?(0,M.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):me.map(e=>(0,M.jsx)(he,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke,compact:!0},e.id))})]})]})]}):(0,M.jsx)(C,{icon:d,title:e(`channels.selectPrompt`),className:`flex-1 justify-center`})}),Oe&&(0,M.jsx)(ve,{onClose:()=>ke(!1),onCreated:e=>{ke(!1),J(),T(e.id)}}),Ae&&(0,M.jsx)(ye,{onClose:()=>je(!1),onOpened:e=>{je(!1),J(),T(e.id)}}),_&&(0,M.jsx)(be,{channels:m,failed:ae,onRetry:Ue,onClose:()=>v(!1),onJoined:e=>{v(!1),J(),T(e)}}),Ne&&K&&(0,M.jsx)(xe,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),T(null),J()}})]})},ve=({onClose:e,onCreated:t})=>{let{t:n}=i(),[r,a]=(0,j.useState)(``),[o,s]=(0,j.useState)(`public`),[c,l]=(0,j.useState)(``),[d,f]=(0,j.useState)(!1);return(0,M.jsxs)(S,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,M.jsx)(k,{size:`sm`,disabled:d||!r.trim(),onClick:()=>{f(!0),A.create({type:o,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):u.error(e.error||n(`channels.createFailed`))}).catch(()=>u.error(n(`channels.createFailed`))).finally(()=>f(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-name`,className:T,children:n(`channels.nameLabel`)}),(0,M.jsx)(`input`,{id:`create-channel-name`,className:x,value:r,onChange:e=>a(e.target.value),"data-testid":`create-channel-name`})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-type`,className:T,children:n(`channels.typeLabel`)}),(0,M.jsxs)(`select`,{id:`create-channel-type`,className:x,value:o,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,M.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,M.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`create-channel-description`,className:T,children:n(`channels.descriptionLabel`)}),(0,M.jsx)(`textarea`,{id:`create-channel-description`,className:x,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},ye=({onClose:e,onOpened:t})=>{let{t:n}=i(),[r,a]=(0,j.useState)(``),[o,s]=(0,j.useState)(!1),c=()=>{r.trim()&&(s(!0),A.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):u.error(e.error||n(`channels.dmFailed`))}).catch(()=>u.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,M.jsx)(S,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,M.jsx)(k,{size:`sm`,disabled:o||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,M.jsx)(`input`,{className:x,value:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"aria-label":n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},be=({channels:e,failed:t,onRetry:n,onClose:r,onJoined:a})=>{let{t:o}=i();return(0,M.jsx)(S,{titleId:`browse-channels-title`,title:o(`channels.browsePublic`),onClose:r,testId:`browse-channels-modal`,children:t&&e===null?(0,M.jsx)(w,{size:`sm`,message:o(`channels.loadFailed`),onRetry:n}):e===null?(0,M.jsx)(ce,{size:`sm`,srOnly:!0}):e.length===0?(0,M.jsx)(C,{icon:s,size:`sm`,title:o(`channels.noPublic`)}):e.map(e=>(0,M.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-3 py-2 dark:border-white/8`,"data-testid":`browse-channel-item`,children:[(0,M.jsx)(f,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,M.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,M.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:o(`channels.joined`)}):(0,M.jsx)(k,{size:`sm`,onClick:()=>void A.join(e.id).then(t=>{t.success?a(e.id):u.error(o(`channels.joinFailed`))}).catch(()=>u.error(o(`channels.joinFailed`))),"data-testid":`browse-channel-join`,children:o(`channels.join`)})]},e.id))})},xe=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:a}=i(),[o,s]=(0,j.useState)(e.name),[c,l]=(0,j.useState)(e.description??``),[d,f]=(0,j.useState)(!1);return(0,M.jsxs)(S,{titleId:`channel-settings-title`,title:a(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,M.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,M.jsx)(k,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:async()=>{await E({title:a(`channels.deleteConfirm`,{name:e.name}),description:a(`channels.deleteConfirmDescription`),confirmLabel:a(`channels.delete`),destructive:!0})&&((await A.delete(e.id).catch(()=>void 0))?.success?r():u.error(a(`channels.deleteFailed`)))},"data-testid":`channel-delete`,children:a(`channels.delete`)}),(0,M.jsx)(k,{size:`sm`,disabled:d||!o.trim(),onClick:()=>{f(!0),A.update(e.id,{name:o.trim(),description:c.trim()}).then(e=>{e.success?n():u.error(a(`channels.saveFailed`))}).catch(()=>u.error(a(`channels.saveFailed`))).finally(()=>f(!1))},"data-testid":`channel-settings-save`,children:a(`channels.save`)})]}),children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`channel-settings-name`,className:T,children:a(`channels.nameLabel`)}),(0,M.jsx)(`input`,{id:`channel-settings-name`,className:x,value:o,onChange:e=>s(e.target.value)})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{htmlFor:`channel-settings-description`,className:T,children:a(`channels.descriptionLabel`)}),(0,M.jsx)(`textarea`,{id:`channel-settings-description`,className:x,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{_e as default};
@@ -0,0 +1,14 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{d as i,f as a,u as o}from"./router-vendor-DLHZHk4K.js";import{t as s}from"./useTranslation-CKqEdZ8j.js";import{$n as c,Bt as l,Ct as u,Dr as d,Dt as f,F as p,H as m,In as h,J as g,Jt as _,K as v,L as y,Ln as b,M as x,N as S,Nn as C,O as w,Or as T,Q as E,Rn as D,Rt as O,S as k,Tt as A,V as j,Vn as M,X as N,Xn as ee,Zn as te,_r as ne,a as re,an as ie,b as P,br as ae,c as F,cn as I,cr as oe,ct as se,er as ce,fr as L,g as le,gr as ue,jn as de,ln as fe,m as pe,n as R,o as me,p as z,pr as he,qt as ge,r as _e,rn as ve,sr as ye,st as be,t as B,tt as xe,ut as Se,v as V,vn as H,wt as Ce,y as we,yn as Te}from"./ui-vendor-DsURZnZt.js";import{a as Ee,i as U,n as De,s as Oe,t as W}from"./utils-BXRzbHJC.js";import{_ as ke,f as Ae,g as G,m as K,p as je,u as Me,v as Ne}from"./ui-DxaHE9GD.js";import{t as Pe}from"./ArtifactContainer-DCCcjK16.js";import{N as q,_ as J,a as Fe,d as Ie,f as Le,g as Re,i as ze,j as Be,m as Ve,n as He,p as Ue,t as We,w as Ge,x as Ke,y as qe}from"./api-Dasm8tVY.js";import{t as Je}from"./appStore-DCIUnT8X.js";import{a as Ye,t as Y}from"./logger-DAQsBb8I.js";import{a as Xe,i as Ze,o as Qe,r as $e,s as et,t as tt}from"./ttsBatching-yVvnRS5S.js";import{a as nt,i as rt,n as it,o as at,r as ot}from"./useChat-1HyAPpCk.js";import{E as st,_ as ct,a as lt,d as ut,f as dt,g as ft,h as pt,i as mt,l as ht,m as gt,n as _t,o as vt,p as yt,r as bt,t as X,u as xt,v as St}from"./chatStore-GhucyjJu.js";import{t as Ct}from"./LogoMark-CmF1lHXT.js";import{t as wt}from"./authStore-ac5-hjOH.js";import{t as Tt}from"./useDialogFocus-DpTun-ZV.js";import{t as Et}from"./evaluationsApi-CBqKkjmI.js";import{l as Dt}from"./messageCodeStyles-BugWE4s5.js";import{t as Z}from"./Button-D6d7HYoa.js";import{n as Ot,r as kt,t as At}from"./useDictation-B3vNgs5D.js";import{n as jt,t as Mt}from"./composerStyles-BEx0XAp6.js";import{i as Nt,r as Pt,t as Ft}from"./thinking-DwlkTfPX.js";import{t as It}from"./ConnectModels-CpWO6ALS.js";import{i as Lt,r as Rt,t as zt}from"./welcomePrompts-to5mv_gx.js";var Bt=n(),Q=e(t(),1),$=r(),Vt=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},Ht=({status:e})=>e===`running`||e===`awaiting_approval`?(0,$.jsx)(O,{className:`h-3.5 w-3.5 animate-spin`}):e===`succeeded`?(0,$.jsx)(ce,{className:`h-3.5 w-3.5 text-green-600 dark:text-green-400`}):e===`denied`?(0,$.jsx)(R,{className:`h-3.5 w-3.5 text-amber-600 dark:text-amber-400`}):(0,$.jsx)(le,{className:`h-3.5 w-3.5 text-red-500 dark:text-red-400`}),Ut=({call:e})=>{let{t}=s(),[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-start`,"aria-expanded":n,children:[n?(0,$.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(te,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 rtl:rotate-180`}),(0,$.jsx)(_e,{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:W(`ms-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)(Ht,{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-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Vt(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-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:e.resultPreview})]})]})]})},Wt=({calls:e,className:t})=>e.length===0?null:(0,$.jsx)(`div`,{className:W(`flex flex-col gap-1.5`,t),children:e.map(e=>(0,$.jsx)(Ut,{call:e},e.id))}),Gt=({approval:e,onDecide:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),o=(0,Q.useId)(),c=async(n,r)=>{a(!0);try{await t(e.approvalId,n,r)}catch{a(!1)}},l=r(`tools.approval.description`,{tool:e.toolCall.name,server:e.toolCall.serverName??r(`tools.approval.builtinSource`)});return(0,$.jsxs)(`div`,{role:`group`,"aria-labelledby":o,className:W(`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)(`span`,{className:`sr-only`,role:`alert`,"aria-live":`assertive`,children:[r(`tools.approval.title`),`. `,l]}),(0,$.jsxs)(`div`,{id:o,className:`flex items-center gap-2 font-medium text-primary-800 dark:text-primary-200`,children:[(0,$.jsx)(y,{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:l}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded-sm bg-white/70 p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Vt(e.toolCall.arguments)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(Z,{size:`sm`,disabled:i,onClick:()=>void c(!0,`once`),children:r(`tools.approval.allowOnce`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void c(!0,`session`),children:r(`tools.approval.allowSession`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void c(!0,`always`),children:r(`tools.approval.allowAlways`)}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>void c(!1,`once`),children:r(`tools.approval.deny`)})]})]})},Kt=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i,i18n:a}=s(),o=(e,t)=>e.toLocaleString(a.language,{minimumFractionDigits:t,maximumFractionDigits:t}),l=e=>{if(e==null)return i(`generationStats.notAvailable`);let t=e/1e6;if(t<1e3)return`${Math.round(t).toLocaleString(a.language)}ms`;let n=t/1e3;return`${o(n,2)}s`},u=e=>e?i(`generationStats.tokensPerSecond`,{value:o(e,1)}):i(`generationStats.notAvailable`),d=e.prompt_eval_count||0,f=e.eval_count||0,p=d+f,m=l(e.total_duration),h=u(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-ink-muted 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)(ge,{size:12,className:`text-primary-500`}),i(`generationStats.tokenCount`,{tokens:f.toLocaleString(a.language)})]}),(0,$.jsx)(`span`,{className:`text-ink-muted`,children:h}),(0,$.jsx)(`span`,{className:`text-ink-muted`,children:m}),e.model&&(0,$.jsx)(`span`,{className:`text-ink-muted 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`,{type:`button`,onClick:()=>r(!n),"aria-expanded":n,className:`flex items-center gap-1 text-ink-muted hover:text-ink transition-colors`,children:[n?(0,$.jsx)(c,{size:12}):(0,$.jsx)(te,{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`)}),` `,d]}),(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`)}),` `,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.totalTokens`)}),` `,p]}),(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`)}),` `,h]}),(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`)}),` `,l(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`)}),` `,l(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`)}),` `,l(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`)}),` `,m]})]}),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(a.language)]})]})]})},qt={maxQuestions:64,minOptions:2,maxOptions:255,minLevels:2,maxLevels:10},Jt=(e=`noul`)=>({type:e,instructions:``,options:[{name:``,description:``},{name:``,description:``}],levels:[``,``,``],trueDescription:``,falseDescription:``});function Yt(e){return Object.values(e??{}).map(e=>{let t=Jt(e.type);return t.instructions=e.instructions,e.type===`choice`?t.options=Object.entries(e.criteria).map(([e,t])=>({name:e,description:t??``})):e.type===`score`?t.levels=[...e.criteria]:(t.trueDescription=e.criteria?.true??``,t.falseDescription=e.criteria?.false??``),t})}function Xt(e){if(e.length>qt.maxQuestions)return{ok:!1,error:{kind:`too-many`}};let t={};for(let[n,r]of e.entries()){let e=n+1,i=r.instructions.trim();if(!i)return{ok:!1,error:{kind:`instructions`,question:e}};if(r.type===`choice`){let n=r.options.map(e=>({name:e.name.trim(),description:e.description.trim()})).filter(e=>e.name||e.description),a=new Set(n.map(e=>e.name));if(n.some(e=>!e.name)||a.size!==n.length||n.length<qt.minOptions||n.length>qt.maxOptions)return{ok:!1,error:{kind:`options`,question:e}};t[`q${e}`]={type:`choice`,instructions:i,criteria:Object.fromEntries(n.map(e=>[e.name,e.description||null]))}}else if(r.type===`score`){let n=r.levels.map(e=>e.trim()).filter(Boolean);if(n.length<qt.minLevels||n.length>qt.maxLevels)return{ok:!1,error:{kind:`levels`,question:e}};t[`q${e}`]={type:`score`,instructions:i,criteria:n}}else{let n=r.trueDescription.trim(),a=r.falseDescription.trim();t[`q${e}`]=n||a?{type:`noul`,instructions:i,criteria:{...n?{true:n}:{},...a?{false:a}:{}}}:{type:`noul`,instructions:i}}}return{ok:!0,questions:Object.keys(t).length>0?t:void 0}}function Zt(e,t){if(!t||t.type===`refusal`)return{label:``,kind:`refusal`,distribution:[]};if(t.type===`noul`){let e=t.noul>=.5;return{label:``,kind:e?`yes`:`no`,probability:e?t.noul:1-t.noul,distribution:[{label:`yes`,probability:t.noul},{label:`no`,probability:1-t.noul}],...t.confidence===void 0?{}:{confidence:t.confidence}}}let n=Object.entries(t.probabilities).map(([e,n])=>({label:t.type===`score`?t.legend[e]??e:String(e),probability:n})).sort((e,t)=>t.probability-e.probability);if(t.type===`choice`)return{label:t.choice,kind:`choice`,probability:t.probabilities[t.choice],distribution:n,...t.confidence===void 0?{}:{confidence:t.confidence}};let r=e?.type===`score`?e.criteria.length:Object.keys(t.legend).length;return{label:n[0]?.label??``,kind:`score`,probability:n[0]?.probability,score:{value:t.score+1,max:r},distribution:n,...t.confidence===void 0?{}:{confidence:t.confidence}}}var Qt=e=>`${(Math.round(e*1e3)/10).toFixed(1)}%`;function $t(e){let t=e?.decision;if(!t||typeof t!=`object`)return null;let n=t.kind;return n===`state`||n===`cleared`?{kind:n}:n===`answers`&&typeof t.questions==`object`&&typeof t.answers==`object`?t:null}var en=({value:e,strong:t})=>(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`h-1.5 w-full overflow-hidden rounded-full bg-gray-100 dark:bg-dark-200`,children:(0,$.jsx)(`div`,{className:W(`h-full rounded-full`,t?`bg-primary-500 dark:bg-primary-400`:`bg-gray-300 dark:bg-dark-400`),style:{width:`${Math.max(0,Math.min(1,e))*100}%`}})}),tn=({metadata:e})=>{let{t}=s();if(e.kind!==`answers`)return(0,$.jsx)(`p`,{"data-testid":`decision-result-note`,className:`text-sm text-ink-muted`,children:e.kind===`state`?t(`chat.decision.result.stateSaved`):t(`chat.decision.result.cleared`)});let n=e.usage?.inputTokens;return(0,$.jsxs)(`div`,{"data-testid":`decision-result`,className:`space-y-3`,children:[Object.entries(e.questions).map(([n,r])=>{let i=Zt(r,e.answers[n]),a=i.kind===`refusal`?t(`chat.decision.result.declined`):i.kind===`yes`?t(`chat.decision.result.yes`):i.kind===`no`?t(`chat.decision.result.no`):i.label;return(0,$.jsxs)(`section`,{className:`rounded-xl border border-line px-3 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`min-w-0 text-sm text-ink`,children:r.instructions}),(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-ink-muted`,children:t(`chat.decision.types.${r.type}`)})]}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex items-baseline gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,"data-testid":`decision-answer`,className:`text-base font-semibold text-ink`,children:a}),i.probability!==void 0&&(0,$.jsx)(`span`,{className:`text-sm tabular-nums text-primary-700 dark:text-primary-300`,children:Qt(i.probability)}),i.score&&(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-ink-muted`,children:t(`chat.decision.result.score`,{value:i.score.value.toFixed(2),max:i.score.max})})]}),i.kind!==`refusal`&&i.kind!==`yes`&&i.kind!==`no`&&i.distribution.length>1&&(0,$.jsx)(`ul`,{className:`mt-2 space-y-1`,children:i.distribution.map(e=>(0,$.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,10rem)_1fr_3.5rem] items-center gap-2 text-xs`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`truncate text-ink-muted`,children:e.label}),(0,$.jsx)(en,{value:e.probability,strong:e.label===i.label}),(0,$.jsx)(`span`,{className:`text-end tabular-nums text-ink-muted`,children:Qt(e.probability)})]},e.label))}),(i.kind===`yes`||i.kind===`no`)&&i.probability!==void 0&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(en,{value:i.probability,strong:!0})})]},n)}),(0,$.jsxs)(`p`,{className:`text-[11px] text-ink-subtle`,children:[t(`chat.decision.result.via`,{model:e.model,provider:e.provider}),n!==void 0&&` · ${t(`chat.decision.result.inputTokens`,{tokens:n})}`]})]})},nn=Y(`components:ttsbutton`),rn=null,an=null,on=0,sn=3e5;async function cn(e=!1){let t=Date.now();return!e&&rn!==null&&t-on<sn?rn:an||(an=(async()=>{try{let e=await Fe.getModels();return e.success&&e.data&&e.data.length>0?(rn=e.data,on=t,e.data):(rn=[],on=t,[])}catch{return rn=[],on=t,[]}finally{an=null}})(),an)}var ln=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:c}=s(),{preferences:l}=Je(),[u,d]=(0,Q.useState)(`idle`),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),[g,_]=(0,Q.useState)(null),v=(0,Q.useRef)(null),y=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await cn(),n=He(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await cn(!0)),e&&(h(t),_(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let b=()=>{y.current+=1,v.current?.cancel(),v.current=null,d(`idle`)},x=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`||v.current){b();return}let t=et();d(`loading`),p(null);let n=y.current+1;y.current=n;try{let r=await t;if(y.current!==n)return;if(r===`blocked`){d(`blocked`);return}let i=l.ttsSettings,a=ze(m,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,u=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),p=f&&i?.voice||a?.config?.default_voice,h=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,b=Math.max(1,a?.config?.max_characters||600),x=Math.min(b,600),S=i?.streamSentences!==!1||e.length>x?$e(e,{locale:c.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=Ze({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>Fe.generate({model:s,pluginId:u,input:e,voice:h?void 0:p||void 0,voiceProfileId:h,speed:g,response_format:_},{signal:t}),onStateChange:e=>{y.current===n&&d(e)}});v.current=C;let w=tt(C);try{await C.play(S)}finally{w(),v.current===C&&(v.current=null)}}catch(e){if(y.current!==n)return;if(Xe(e)){d(`idle`);return}if(Qe(e)){d(`blocked`);return}p(o(`ttsButton.generateFailed`)),nn.error(`TTS error:`,e),d(`error`)}};if((0,Q.useEffect)(()=>()=>{y.current+=1,v.current?.cancel(),v.current=null},[]),g===!1||g===null)return null;let S={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},C={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`,k=T===`blocked`,A=!!f||T===`error`,j=f||o(A?`ttsButton.playbackFailed`:k?`ttsButton.enableAudio`:D||E?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,$.jsxs)(`button`,{onClick:x,disabled:!e,title:j,"aria-label":j,"aria-busy":E||void 0,className:W(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,A?`text-red-500 dark:text-red-400`:k?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:D?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!k&&S[n],k&&n===`sm`&&`h-7`,k&&n===`md`&&`h-8`,k&&n===`lg`&&`h-10`,t),children:[E?(0,$.jsx)(O,{className:W(C[n],`animate-spin`)}):D?(0,$.jsx)(w,{className:C[n]}):A||k?(0,$.jsx)(re,{className:C[n]}):(0,$.jsx)(me,{className:C[n]}),k&&(0,$.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},un=80,dn=5e3,fn=15e3;function pn({sessionId:e,messageId:t,thinking:n,isThinking:r,isPrivate:i}){let a=Je(e=>e.preferences.titleSettings),o=(0,Q.useRef)(n),[s,c]=(0,Q.useState)(null),{autoTitle:l,taskModel:u,taskProviderType:d,taskProviderId:f}=a??{};return(0,Q.useEffect)(()=>{o.current=n},[n]),(0,Q.useEffect)(()=>{if(!e||!r||i||!l||!u||Ye())return;let n=!1,a,s=``,p=new AbortController,m=async()=>{let r=(o.current??``).slice(-4e3).trim();if(r.length<un||r===s){n||(a=setTimeout(()=>void m(),400));return}s=r;let i=Date.now(),l=dn;try{let i=await q.summarizeThinking(e,{model:u,thinking:r,providerType:d,providerId:f},p.signal);if(!i.success||!i.data?.summary?.trim())throw Error(`Thinking summary unavailable`);n||c({sessionId:e,messageId:t,summary:i.data.summary.trim().slice(0,160)})}catch{l=fn}n||(a=setTimeout(()=>void m(),Math.max(0,l-(Date.now()-i))))};return a=setTimeout(()=>void m(),350),()=>{n=!0,clearTimeout(a),p.abort()}},[e,t,r,i,l,u,d,f]),s&&s.sessionId===e&&s.messageId===t?s.summary:null}var mn=[`accuracy`,`style`,`incomplete`,`harmful`,`formatting`],hn=Y(`components:chat-message`);function gn({role:e,user:t,persona:n,modelAvatar:r}){let{t:i}=s(),[a,o]=(0,Q.useState)(null);if(e===`assistant`){if(n)return(0,$.jsx)(`img`,{src:Re(n,64),alt:n.name,"data-testid":`chat-assistant-avatar`,onError:e=>J(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!==a?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-xs dark:border-white/9 dark:bg-dark-200 dark:text-dark-950`,children:t?(0,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>o(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 c=t?.username||i(`chatMessage.user`),l=t?.avatar?.trim()||``,u=!!l&&l!==a;return(0,$.jsx)(`div`,{role:u?void 0:`img`,"aria-label":u?void 0:c,"data-testid":`chat-user-avatar`,className:W(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,u?`border border-black/[0.07] bg-white dark:border-white/9 dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:c,children:u?(0,$.jsx)(`img`,{src:l,alt:c,className:`h-full w-full object-cover`,onError:()=>o(l)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(F,{"aria-hidden":`true`,className:`h-4 w-4`})})}var _n=Q.memo(({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onFork:a,onEditResend:o})=>{let{t:l,i18n:u}=s(),d=e.role===`user`,f=e.role===`system`,p=f&&lt(e.content),m=p?e.content.slice(_t.length):e.content,h=Je(e=>e.preferences),_=wt(e=>e.user),v=X(e=>e.setSystemMessage),y=X(e=>e.rateMessage),b=X(e=>e.modelMetadata),x=X(e=>e.currentSession?.id),S=X(e=>e.currentSession?.model),w=X(e=>e.currentSession?.isPrivate===!0),D=X(e=>e.getCurrentPersona()),O=e.model||S||``,k=O?b[O]??Object.entries(b).find(([e])=>e.slice(e.indexOf(`/`)+1)===O)?.[1]:void 0,[A,M]=(0,Q.useState)(!1),[te,ne]=(0,Q.useState)(e.content),[re,ae]=(0,Q.useState)(null),F=(0,Q.useRef)(null);Tt(F,{enabled:re!==null,onClose:()=>ae(null)});let[I,oe]=(0,Q.useState)(!1),[L,le]=(0,Q.useState)(!1),[ue,de]=(0,Q.useState)(!1),fe=(0,Q.useId)(),[me,z]=(0,Q.useState)(`idle`),[he,ge]=(0,Q.useState)(null),[_e,ve]=(0,Q.useState)([]),[be,B]=(0,Q.useState)(``),[xe,Se]=(0,Q.useState)(!1),V=(0,Q.useRef)(null),H=(0,Q.useRef)(0),Ce=(0,Q.useRef)(t),Te=(0,Q.useRef)(!1),Ee=async()=>{try{await navigator.clipboard.writeText(e.content),Dt(`success`),Se(!0),setTimeout(()=>Se(!1),2e3)}catch(e){hn.error(`Failed to copy message:`,e),T.error(l(`chat.message.copyFailed`))}},De=(0,Q.useMemo)(()=>$t(e.providerMetadata),[e.providerMetadata]),{thinkingContent:ke,thinkingStreaming:G,parsedContent:K,artifacts:je}=(0,Q.useMemo)(()=>{if(d||f||!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}:Oe(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=at(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,d,f,t]),Ne=G?void 0:e.statistics?.thinking_duration_ms??nt(e.id),J=pn({sessionId:x,messageId:e.id,thinking:ke,isThinking:G,isPrivate:w}),Ie=Ne===void 0?l(`chatMessage.thinking`):l(`chatMessage.thoughtFor`,{duration:rt(Ne)}),Le=(0,Q.useCallback)(async e=>{let t=H.current+1;H.current=t,V.current?.cancel(),V.current=null,z(`loading`);try{if(e){let n=await e;if(H.current!==t)return;if(n===`blocked`){z(`blocked`);return}}let n=await Fe.getModels();if(H.current!==t)return;let r=n.success&&n.data?n.data:[],i=h.ttsSettings,a=ze(r,i?.model,i?.pluginId),o=He(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,c=a?.plugin||i?.pluginId,l=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||K.length>p?$e(K,{locale:u.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[K.trim()];if(m.length===0){z(`idle`);return}let g=Ze({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>Fe.generate({model:s,pluginId:c,input:e,voice:d?void 0:l||void 0,voiceProfileId:d,speed:i?.speed||1,response_format:a?.config?.default_format},{signal:t}),onStateChange:e=>{H.current===t&&z(e)}});if(H.current!==t){g.cancel();return}V.current=g;let _=tt(g);try{await g.play(m)}finally{_(),V.current===g&&(V.current=null),H.current===t&&(g.state===`ended`||g.state===`cancelled`)&&z(`idle`)}}catch(e){if(H.current!==t)return;Xe(e)?z(`idle`):Qe(e)?z(`blocked`):(hn.error(`Auto-play TTS failed:`,e),z(`error`))}},[u.language,K,h.ttsSettings]);(0,Q.useEffect)(()=>{let e=Ce.current&&!t;Ce.current=t,e&&!Te.current&&!d&&!f&&K&&h.ttsSettings?.enabled&&h.ttsSettings.autoPlay&&(Te.current=!0,Le())},[t,d,f,K,h.ttsSettings?.autoPlay,h.ttsSettings?.enabled,Le]),(0,Q.useEffect)(()=>()=>{H.current+=1,V.current?.cancel(),V.current=null},[]);let Re=()=>{let e=et();Le(e)},Be=()=>{H.current+=1,V.current?.cancel(),V.current=null,z(`idle`)},Ve=()=>p?l(`chatMessage.conversationSummary`):f?l(`chatMessage.system`):d?h.showUsername&&_?.username?_.username:l(`chatMessage.you`):D?.name?D.name:k?.label||O||l(`chatMessage.assistant`),Ue=()=>{M(!0),ne(e.content)},[We,Ge]=(0,Q.useState)(!1),Ke=async()=>{if(x&&!We){Ge(!0);try{let t=await q.restoreCompaction(x,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;X.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){hn.error(`Failed to restore compacted messages:`,e),T.error(l(`chatMessage.restoreFailed`))}finally{Ge(!1)}}},qe=async()=>{oe(!0);try{v(te),M(!1),hn.debug(`✅ System message updated:`,te)}catch(e){hn.error(`Failed to save system message:`,e)}finally{oe(!1)}},Ye=()=>{M(!1),ne(e.content)},Y=()=>{let t=te.trim();M(!1),t&&o?.(e.id,t)},it=t=>{if(!x)return;let n=e.rating===t;y(x,e.id,n?void 0:t),w||(n?(ge(null),Et.deleteFeedback(e.id).catch(()=>T.error(l(`chatMessage.feedbackFailed`)))):(ve([]),B(``),ge(t===1?1:-1),Et.upsertFeedback({sessionId:x,messageId:e.id,rating:t===1?1:-1}).catch(()=>T.error(l(`chatMessage.feedbackFailed`)))))},ot=()=>{x&&he!==null&&(Et.upsertFeedback({sessionId:x,messageId:e.id,rating:he,tags:_e,...be.trim()?{comment:be.trim()}:{}}).catch(()=>T.error(l(`chatMessage.feedbackFailed`))),ge(null))},st=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ct=f&&m.length>100;return(0,$.jsxs)(`div`,{className:W(`group flex py-1.5 transition-colors sm:py-2`,d?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:W(`flex min-w-0 gap-2.5 sm:gap-3`,d?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!d&&!f&&(0,$.jsx)(gn,{role:`assistant`,persona:D,modelAvatar:k?.avatar}),(0,$.jsxs)(`div`,{className:W(`min-w-0 flex-1`,d?`flex flex-col items-end`:f?`py-1.5`:`py-0.5`),children:[!d&&!f&&(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-ink-muted rtl:tracking-normal`,children:Ve()}),e.model&&D?.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-ink-subtle`,children:U(e.timestamp,u.language)})]}),(0,$.jsxs)(`div`,{className:W(!d&&!f&&`text-[0.9375rem] leading-[1.65] text-ink`),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/6 bg-gray-100 dark:border-white/8 dark:bg-gray-800`,children:(0,$.jsx)(`button`,{type:`button`,className:`block h-full w-full`,"aria-label":l(`chatMessage.openImage`,{number:t+1}),onClick:()=>ae(e),children:(0,$.jsx)(`img`,{src:e,alt:l(`chatMessage.uploadedImageAlt`,{number:t+1}),className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`})})},t))}),d?A?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/8 bg-white p-2 shadow-xs focus-within:border-primary-500 focus-within:ring-2 focus-within:ring-primary-500/30 dark:border-white/8 dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{"aria-label":l(`chatMessage.edit`),dir:`auto`,value:te,onChange:e=>ne(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||(e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),Y()):e.key===`Escape`&&Ye())},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-hidden dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:Ye,children:l(`chatMessage.cancelEditing`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:Y,children:l(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{"data-user-bubble":``,className:`rounded-2xl rounded-ee-md border border-line bg-surface-subtle px-4 py-2.5 text-ink`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):f?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/6 bg-white/55 p-3 dark:border-white/6 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:[p?(0,$.jsx)(N,{className:`h-2.5 w-2.5 opacity-50`}):(0,$.jsx)(j,{className:`h-2.5 w-2.5 opacity-50`}),l(p?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:p?(0,$.jsx)(`button`,{onClick:()=>void Ke(),disabled:We,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:l(`chatMessage.restoreCompacted`),"aria-label":l(`chatMessage.restoreCompacted`),children:(0,$.jsx)(pe,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):A?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:qe,disabled:I,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:l(`chatMessage.saveChanges`),"aria-label":l(`chatMessage.saveChanges`),children:(0,$.jsx)(g,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:Ye,disabled:I,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:l(`chatMessage.cancelEditing`),"aria-label":l(`chatMessage.cancelEditing`),children:(0,$.jsx)(R,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:Ue,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:l(`chatMessage.editSystemMessage`),"aria-label":l(`chatMessage.editSystemMessage`),children:(0,$.jsx)(se,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),A?(0,$.jsx)(`textarea`,{"aria-label":l(`chatMessage.editSystemMessage`),dir:`auto`,value:te,onChange:e=>ne(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/8 bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-hidden focus:ring-2 focus:ring-primary-500 dark:border-white/8 dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:l(`chatMessage.systemMessagePlaceholder`),disabled:I}):(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:L?m:st(m)}),ct&&(0,$.jsx)(`button`,{type:`button`,"aria-expanded":L,onClick:()=>le(!L),className:`mt-2 flex items-center gap-1 text-xs text-ink-muted transition-colors hover:text-ink`,children:L?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ee,{className:`h-3 w-3`}),l(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(c,{className:`h-3 w-3`}),l(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(ke||G)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`thinking-toggle`,"aria-expanded":ue,"aria-controls":fe,onClick:()=>de(!ue),className:`flex min-h-11 max-w-full items-center gap-1.5 rounded-md py-2 text-start text-xs text-ink-muted transition-colors hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/30`,children:[G?(0,$.jsx)(Ae,{"data-testid":`thinking-generation-indicator`}):(0,$.jsx)(ye,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{role:`status`,"aria-live":G?`polite`:`off`,"aria-atomic":`true`,className:`min-w-0 wrap-anywhere`,children:[(0,$.jsx)(`span`,{"data-testid":`thinking-summary`,dir:`auto`,className:W(`block font-medium`,G&&`animate-slide-up [animation-duration:140ms] motion-reduce:animate-none`),children:J||(G?`${l(`chatMessage.thinking`)}…`:Ie)},J||`thinking`),J&&!G&&(0,$.jsx)(`span`,{className:`mt-0.5 block text-ink-subtle`,children:Ie})]}),ue?(0,$.jsx)(ee,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}):(0,$.jsx)(c,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`})]}),(0,$.jsx)(`div`,{id:fe,"data-testid":`thinking-content`,hidden:!ue,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:ue&&ke&&(0,$.jsx)(Me,{content:ke,isStreaming:G,className:`text-[13px] text-ink-muted`})})]}),De&&!t?(0,$.jsx)(tn,{metadata:De}):(0,$.jsx)(Me,{content:K,isStreaming:t&&!(G&&!K)})]}),!d&&!f&&je.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Pe,{artifacts:je})}),!d&&!f&&Array.isArray(e.providerMetadata?.toolCalls)&&e.providerMetadata.toolCalls.length>0&&(0,$.jsx)(Wt,{calls:e.providerMetadata.toolCalls,className:`mt-2.5`}),!d&&!f&&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-ink-subtle rtl:tracking-normal`,children:l(`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)]}),!d&&!f&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(Kt,{statistics:e.statistics})}),!f&&!t&&(0,$.jsxs)(`div`,{className:W(`flex items-center gap-0.5 text-ink-subtle`,`sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,!d&&[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(me)?`sm:opacity-100`:`[@media(hover:hover)]:sm:opacity-0`,d?`mt-1 justify-end`:`mt-1`),children:[d&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:U(e.timestamp,u.language),children:[Ve(),` ·`,` `,U(e.timestamp,u.language)]}),!d&&K&&(0,$.jsx)(ln,{text:K,size:`sm`,externalPlaybackState:me,onStopExternal:Be,onRetryExternal:Re,className:W(`transition-colors`,me===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),d&&o&&!A&&(0,$.jsx)(`button`,{onClick:()=>{ne(e.content),M(!0)},className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:l(`chatMessage.edit`),"aria-label":l(`chatMessage.edit`),children:(0,$.jsx)(se,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:Ee,"aria-label":l(xe?`chatMessage.copied`:`chatMessage.copyMessage`),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:l(xe?`chatMessage.copied`:`chatMessage.copyMessage`),children:xe?(0,$.jsx)(ce,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(C,{className:`h-3.5 w-3.5`})}),!d&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>it(1),className:W(`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:l(`chatMessage.goodResponse`),"aria-label":l(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(we,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>it(-1),className:W(`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:l(`chatMessage.badResponse`),"aria-label":l(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(P,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})}),he!==null&&(0,$.jsxs)(`div`,{className:`ms-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:[mn.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>ve(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:W(`rounded-full border px-2 py-0.5 text-[10px]`,_e.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":_e.includes(e),children:l(`chatMessage.feedbackTags.${e}`)},e)),(0,$.jsx)(`input`,{value:be,onChange:e=>B(e.target.value),placeholder:l(`chatMessage.feedbackComment`),"aria-label":l(`chatMessage.feedbackComment`),className:`w-32 rounded-sm border border-gray-300 px-1.5 py-0.5 text-[10px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,maxLength:2e3}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:ot,className:`h-6 px-2 text-[10px]`,children:l(`common.save`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>ge(null),"aria-label":l(`common.close`),className:`rounded-sm p-0.5 text-ink-muted hover:text-ink`,children:(0,$.jsx)(R,{className:`h-3 w-3`})})]})]}),!d&&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:l(`chatMessage.regenerateResponse`),"aria-label":l(`chatMessage.regenerateResponse`),children:(0,$.jsx)(E,{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:l(`chat.fork.action`),"aria-label":l(`chat.fork.action`),"data-testid":`fork-from-message`,children:(0,$.jsx)(ie,{className:`h-3.5 w-3.5`})})]})]})]}),d&&(0,$.jsx)(gn,{role:`user`,user:_??null})]}),re&&(0,Bt.createPortal)((0,$.jsxs)(`div`,{ref:F,role:`dialog`,"aria-modal":`true`,"aria-label":l(`chatMessage.fullSizeImage`),tabIndex:-1,className:`fixed inset-0 z-9999 flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>ae(null),children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":l(`common.close`),className:`absolute inset-e-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(),ae(null)},children:(0,$.jsx)(R,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:re,alt:l(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})});_n.displayName=`ChatMessage`;var vn=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,yn=220,bn=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>yn?`${t.slice(0,219).trimEnd()}…`:t},xn=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[c,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)},[]),p=(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:vn()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`: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-none [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===h,u=Math.abs(a-m),d=c===t.id?v: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":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:W(`group flex h-4 w-7 items-center outline-hidden xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-xs`),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(),p(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:W(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,$.jsx)(`div`,{id:v,role:`tooltip`,className:W(`pointer-events-none absolute inset-s-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:bn(_.prompt)}),_.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:bn(_.response)})]})})]})}),Sn=Q.memo(({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:c,className:l})=>{let{t:u}=s();if(e.length===1){let s=e[0],c=t&&i===s.id,u=c?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(_n,{message:u,isStreaming:c,isLastAssistantMessage:a,onRegenerate:o,className:l})}return(0,$.jsxs)(`div`,{className:W(`relative py-2`,l),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-muted`,children:[(0,$.jsx)(I,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:u(`chat.branch.variants`,{count:e.length})})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let l=e.isActive!==!1,d=t&&i===e.id,f=d?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:W(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||d?`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&&!d&&`cursor-pointer`),role:!l&&!d?`button`:void 0,tabIndex:!l&&!d?0:void 0,"aria-label":!l&&!d?u(`chat.branch.selectVariant`,{number:s+1}):void 0,"aria-current":l||d?`true`:void 0,onClick:()=>!l&&!d&&c?.(e.id),onKeyDown:t=>{t.target!==t.currentTarget||l||d||t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),c?.(e.id))},children:[(0,$.jsxs)(`div`,{className:W(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||d?`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/5 text-ink-muted dark:border-white/5`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:s+1}),d&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:u(`chat.branch.generating`)})]}),l&&!d&&(0,$.jsx)(ce,{className:`h-3 w-3`}),!l&&!d&&(0,$.jsx)(`span`,{className:`text-[10px]`,children:u(`chat.branch.select`)})]}),(0,$.jsx)(`div`,{className:W(!l&&!d&&`opacity-75`),children:(0,$.jsx)(_n,{message:f,isStreaming:d,isLastAssistantMessage:a&&(l||d),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 text-sm!`})})]},e.id)})})]})});Sn.displayName=`MessageBranch`;var Cn={web_search:v,web_fetch:ve,exec:k,browser:ve,Read:Te,Write:Te,Edit:Te,image:_,memory_search:de,memory_get:de,working:_e,thinking:_e,default:_e},wn={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`},Tn=({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:W(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Cn[e.name]||Cn.default,n=wn[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:W(`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:W(`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)})})};Y(`components:chat-messages`);var En=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],Dn=e=>e.messages.every(e=>e.isActive===!1),On=e=>e.role===`system`&&!lt(e.content),kn=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,An=e=>Math.min(120,e*.28),jn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],activeToolCalls:o,pendingToolApproval:c,onDecideToolApproval:l,className:u,onRegenerate:d,onSelectBranch:f,onEditResend:p,onFork:m,followUpSuggestions:h,onFollowUpSelect:g})=>{let{t:_}=s(),v=(0,Q.useRef)(null),y=(0,Q.useRef)(void 0),b=(0,Q.useRef)(null),S=(0,Q.useRef)(null),[C]=(0,Q.useState)(()=>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)=>On(e)&&!On(t)?-1:On(t)&&!On(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 On(n)&&!On(r)?-1:On(r)&&!On(n)?1:n.timestamp-r.timestamp})},[e]),j=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<A.length;t++){let n=A[t],r=En(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<A.length;e++){let t=En(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]),M=j.map(e=>e.id).join(``),N=(0,Q.useMemo)(()=>M?M.split(``):[],[M]),ee=(0,Q.useMemo)(()=>new Set(N),[N]),te=(0,Q.useMemo)(()=>{let e=new Map;for(let t of N)e.set(t,e=>{e?C.set(t,e):C.delete(t)});return e},[C,N]),[ne,re]=(0,Q.useState)(null),ie=(0,Q.useCallback)(()=>{let e=b.current;if(!e||N.length===0){re(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(T.current,N.length-1);if(t<=2)n=N.length-1;else{let t=e.scrollTop+An(e.clientHeight);for(;n<N.length-1;){let e=C.get(N[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=C.get(N[n]);if(!e||e.offsetTop<=t)break;n--}}T.current=n;let r=N[n];re(e=>e===r?e:r)},[C,N]),P=(0,Q.useCallback)(()=>{w.current===null&&(w.current=window.requestAnimationFrame(()=>{w.current=null,ie()}))},[ie]),F=(0,Q.useCallback)(()=>{let t=b.current;if(y.current&&clearTimeout(y.current),E.current=!1,y.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)(()=>{y.current&&clearTimeout(y.current),y.current=setTimeout(F,180)},[F]),oe=(0,Q.useCallback)((e=!1)=>{(!D.current||e)&&v.current?.scrollIntoView({behavior:kn()})},[]),se=(0,Q.useCallback)(()=>{let t=b.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;E.current?(D.current=!0,k(!o&&e.length>0),P(),I()):(D.current=!o,k(!o&&e.length>0),a<=2&&N.length>0?(T.current=N.length-1,re(N[N.length-1])):P())},[N,e.length,I,P]),ce=(0,Q.useCallback)(e=>{let t=b.current,n=C.get(e);if(!t||!n)return;let r=kn();E.current=!0,D.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-An(t.clientHeight)),behavior:r}),P(),r===`auto`?F():I()},[F,C,I,P]),L=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>L.current&&!D.current&&oe(),L.current=e.length},[e.length,oe]),(0,Q.useEffect)(()=>{i&&(t||n)&&!D.current&&requestAnimationFrame(()=>{let e=b.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{P();let e=S.current,t=b.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)}},[M,P]),(0,Q.useEffect)(()=>()=>{w.current!==null&&(window.cancelAnimationFrame(w.current),w.current=null)},[]),(0,Q.useEffect)(()=>()=>{y.current&&clearTimeout(y.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:W(`flex-1 flex items-center justify-center p-6 sm:p-10`,u),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-ink-muted`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/6 bg-surface/70 text-gray-500 shadow-xs dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(x,{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:_(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:_(`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:W(`relative min-h-0 flex-1`,u),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:b,"data-testid":`chat-scroll-viewport`,"aria-busy":i,"data-scroll-fade-top":`40`,"data-scroll-fade-bottom":`72`,onScroll:se,className:W(`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=ee.has(e.id),c=i&&e.messages.some(e=>e.id===r),l;if(Dn(e))l=(0,$.jsx)(`div`,{className:`opacity-55`,children:(0,$.jsx)(_n,{message:En(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)(_n,{message:u,isStreaming:c,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onEditResend:i?void 0:p,onFork:i?void 0:m,className:a===0?`mt-3 sm:mt-4`:``})}else l=(0,$.jsx)(Sn,{messages:e.messages,isStreaming:c,streamingMessage:c?t:void 0,streamingThinking:c?n:void 0,streamingMessageId:c&&r||void 0,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onSelectBranch:f,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{className:`[content-visibility:auto] [contain-intrinsic-size:auto_160px]`,ref:te.get(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)(Wt,{calls:o??[],className:`pb-2`}),c&&l&&(0,$.jsx)(Gt,{approval:c,onDecide:l,className:`mb-2`}),i&&a.length>0&&(0,$.jsx)(Tn,{tools:a,className:`px-0`}),!i&&h&&h.length>0&&g&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-subtle`,children:_(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:h.map(e=>(0,$.jsx)(`button`,{onClick:()=>g(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-ink-muted transition-colors hover:text-ink dark:border-dark-200`,children:e},e))})]}),(0,$.jsx)(`div`,{ref:v,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(xn,{items:j,activeId:ne,onSelect:ce}),O&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-new-messages`,onClick:()=>{E.current=!1,y.current&&=(clearTimeout(y.current),void 0),D.current=!1,v.current?.scrollIntoView({behavior:kn()}),k(!1)},className:W(`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/8`,`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:_(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(ae,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:_(`chatMessage.newMessages`)})]})]})};function Mn(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 Nn=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)(()=>Mn(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:W(`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 inset-e-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:W(`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)(D,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});Nn.displayName=`CodeAwareTextarea`;var Pn=Y(`components:media-upload`),Fn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)([]),g=async r=>{if(!r||a)return;let i=Array.from(r),o=[];for(let t of i)if(t.type.startsWith(`image/`)){let r=await _(t,n-e.length-o.length);r&&o.push(r)}else t.type.includes(`pdf`)||t.type.includes(`text`)?await v(t):T.error(c(`chat.mediaUpload.unsupportedFileType`,{name:t.name}));o.length>0&&t([...e,...o])},_=(e,t)=>t<=0?(T.error(c(`chat.mediaUpload.maxImagesAllowed`,{count:n})),Promise.resolve(null)):e.size>10485760?(T.error(c(`chat.mediaUpload.imageTooLarge`,{name:e.name})),Promise.resolve(null)):new Promise(t=>{let n=new FileReader;n.onload=()=>t(typeof n.result==`string`?n.result:null),n.onerror=()=>{T.error(c(`chat.mediaUpload.readFailed`,{name:e.name})),t(null)},n.readAsDataURL(e)}),v=async e=>{if(e.size>10485760)T.error(c(`documents.fileSizeTooLarge`));else{p(!0);try{let t=await Be.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),T.success(c(`documents.uploadSuccessWithName`,{name:e.name}))}else T.error(t.error||c(`documents.uploadFailed`))}catch(e){Pn.error(`Document upload error:`,e),T.error(c(`documents.uploadFailed`))}finally{p(!1)}}},y=e=>{e.preventDefault(),a||d(!0)},b=e=>{e.preventDefault(),d(!1)},x=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},C=async e=>{try{let t=await Be.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),T.success(c(`documents.removeSuccess`))):T.error(t.error||c(`documents.removeFailed`))}catch(e){Pn.error(`Error removing document:`,e),T.error(c(`documents.removeFailed`))}},w=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},E=e.length>0||m.length>0;return(0,$.jsxs)(`div`,{className:W(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:W(`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:y,onDragLeave:b,onDrop:x,role:`button`,tabIndex:a?-1:0,"aria-disabled":a||void 0,"aria-label":`${c(`chat.mediaUpload.dropImagesHere`)} ${c(`chat.mediaUpload.browse`)}`,onClick:()=>!a&&l.current?.click(),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a||l.current?.click())},children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(O,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`,role:`status`,"aria-label":c(`chat.mediaUpload.uploading`)}):(0,$.jsx)(z,{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:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-ink-muted mt-1`,children:c(`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:c(`chat.mediaUpload.uploadAlt`,{number:t+1}),className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S(t)},"aria-label":c(`chat.mediaUpload.removeImage`,{number:t+1}),className:`absolute top-0.5 inset-e-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity`,children:(0,$.jsx)(R,{className:`h-3 w-3`})})]},`img-${t}`)),m.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)(Te,{className:`w-4 h-4 text-red-500 shrink-0`}):(0,$.jsx)(H,{className:`w-4 h-4 text-blue-500 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-ink-muted`,children:w(e.size)})]}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),C(e.id)},"aria-label":c(`chat.mediaUpload.removeDocument`,{name:e.filename}),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)(R,{className:`h-3 w-3`})})]},e.id))]})]})},In=Y(`components:document-indicator`),Ln=({sessionId:e,className:t=``})=>{let{t:n}=s(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),u=(0,Q.useRef)(null),f=(0,Q.useCallback)(async()=>{try{let t=await Be.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){In.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=>{u.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 Be.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){In.error(`Failed to delete document:`,e),d.error(n(`settings.documents.library.deleteFailed`))}},m=r.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{ref:u,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:c===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)(Te,{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:[De(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)(R,{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`)} - ${De(m)}`,children:[(0,$.jsx)(he,{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`]})]})]})},Rn=Y(`components:structured-output`),zn=[{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`}],Bn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),[o,c]=(0,Q.useState)(``),l=()=>zn.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);n&&(n.value===`custom`?a(!0):(a(!1),t(n.value)))};return(0,$.jsxs)(`div`,{className:W(`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)(j,{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)(je,{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)(K,{value:o,onChange:e=>c(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)(Z,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){Rn.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(Z,{onClick:()=>{a(!1),c(``)},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)(b,{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)(Te,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},Vn=7,Hn=2*Math.PI*Vn,Un=e=>`\u2068${e}\u2069`,Wn=({usage:e,trainedBudget:t})=>{let{t:n,i18n:r}=s(),[i,a]=(0,Q.useState)(!1),o=typeof e.budget==`number`&&e.budget>0,c=e.ratio??0,l=Math.round(c*100),u=e.measured?``:`~`,d=r.language,f=`${u}${mt(e.used,d)}`,p=o?n(`chat.context.tokensUsed`,{used:Un(f),budget:Un(mt(e.budget,d))}):n(`chat.context.tokensUsedNoBudget`,{used:Un(f)}),m=t===void 0?void 0:n(`chat.context.capped`,{trained:Un(mt(t,d))}),h=[n(`chat.context.title`),o?n(`chat.context.full`,{percent:l}):void 0,p,m].filter(Boolean).join(` `),g=Math.min(c,1);return(0,$.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onFocus:()=>a(!0),onBlur:()=>a(!1),onKeyDown:e=>{e.key===`Escape`&&a(!1)},children:[(0,$.jsxs)(`span`,{role:o?`meter`:`img`,tabIndex:0,"aria-label":h,...o?{"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(l,100),"aria-valuetext":h}:{},className:W(`touch-target relative flex h-9 w-9 items-center justify-center rounded-full text-ink-muted outline-hidden`,`transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/40`,c>=.8&&c<1&&`text-amber-600 dark:text-amber-400`,c>=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&&g>0&&(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:Vn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:Hn,strokeDashoffset:Hn*(1-g)})]}),c>=.8&&(0,$.jsx)(le,{className:`absolute inset-e-0 top-0 h-3 w-3`})]}),i&&(0,$.jsxs)(`div`,{role:`tooltip`,className:W(`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/6 dark:border-white/8 dark:bg-dark-100/95`,`animate-scale-in`),children:[(0,$.jsx)(`p`,{className:`text-[13px] text-ink-muted`,children:n(`chat.context.title`)}),o&&(0,$.jsx)(`p`,{className:`text-[13px] text-ink-muted`,children:n(`chat.context.full`,{percent:l})}),(0,$.jsx)(`p`,{className:`text-[13px] tabular-nums text-gray-900 dark:text-dark-900`,children:p}),m&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-ink-muted`,children:m})]})]})},Gn=Y(`components:prompt-queue`),Kn=({sessionId:e,queue:t})=>{let{t:n}=s(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),c=t=>ot(e,t),l=async t=>{try{let n=await q.claimQueuedPrompt(e,t);n.success&&n.data&&c(n.data.queue)}catch(e){Gn.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 q.reorderPromptQueue(e,o);t.success&&t.data&&c(t.data.queue)}catch(e){Gn.error(`Failed to reorder the prompt queue:`,e)}},d=async t=>{let r=a.trim();if(r)try{let a=await q.updateQueuedPrompt(e,t,r);a.success&&a.data?(c(a.data.queue),i(null)):T.error(a.error||n(`chat.queue.updateFailed`))}catch(e){Gn.error(`Failed to update the queued prompt:`,e),T.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)(M,{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/6 bg-surface/70 px-2 py-1 dark:border-white/8 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-hidden 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)(ce,{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)(ne,{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)(ae,{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)(be,{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)(R,{className:`h-3 w-3`})})]})},e.id))})]})},qn=(e,t)=>{let n=[];for(let r of t){let t=xt(e,r);t&&n.push({model:t.model,providerType:t.providerType??null,providerId:t.providerId??null})}return n},Jn=({models:e,currentModelKey:t,selectedKeys:n,onChange:r,disabled:i=!1})=>{let{t:a}=s(),[o,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!o)return;let e=e=>{l.current?.contains(e.target)||c(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[o]);let u=e.filter(ft).map(e=>({model:e,key:ht(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)(Z,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>c(e=>!e),className:W(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`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)(h,{className:`h-4 w-4`}),n.length>0&&(0,$.jsxs)(`span`,{className:`absolute -inset-e-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 inset-s-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:W(`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-sm 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)})]})]})},Yn=`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(`,`),Xn=/^\/([a-z0-9-]*)$/,Zn=/(?:^|\s)\$([a-z0-9-]*)$/,Qn=8,$n=(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??``}),er=({prompt:e,onCancel:t,onInsert:n})=>{let{t:r}=s(),[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)(Z,{size:`sm`,variant:`ghost`,onClick:t,children:r(`composer.variables.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:o.length>0,title:o.length>0?r(`composer.variables.required`,{name:o[0]?.name??``}):void 0,onClick:()=>n($n(e.content,e.variables,i)),children:r(`composer.variables.insert`)})]})]})},tr=(0,Q.forwardRef)(({message:e,disabled:t=!1,onApply:n},r)=>{let{t:i}=s(),[a,o]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),[f,p]=(0,Q.useState)(null),m=(0,Q.useRef)({prompts:!1,skills:!1}),h=t?null:Xn.exec(e),g=t||h?null:Zn.exec(e),_=h!==null,v=g!==null;(0,Q.useEffect)(()=>{_&&!m.current.prompts&&(m.current.prompts=!0,Ue.list().then(e=>{o(t=>e.success&&e.data?e.data:t??[])}).catch(()=>o(e=>e??[])).finally(()=>{m.current.prompts=!1}))},[_]),(0,Q.useEffect)(()=>{v&&!m.current.skills&&(m.current.skills=!0,Le.list().then(e=>{l(t=>e.success&&e.data?e.data:t??[])}).catch(()=>l(e=>e??[])).finally(()=>{m.current.skills=!1}))},[v]);let y=(0,Q.useMemo)(()=>{if(h){let e=h[1];return(a??[]).filter(t=>t.slug.startsWith(e)).slice(0,Qn).map(e=>({kind:`prompt`,key:e.id,slug:e.slug,label:e.title,detail:e.description,prompt:e}))}if(g){let e=g[1];return(c??[]).filter(t=>t.enabled&&t.slug.startsWith(e)).slice(0,Qn).map(e=>({kind:`skill`,key:e.id,slug:e.slug,label:e.name,detail:e.description,skill:e}))}return[]},[h,g,a,c]),[b,S]=(0,Q.useState)(e);e!==b&&(S(e),d(0),!h&&f&&p(null));let C=t=>{let r=y[t];if(r){if(r.kind===`prompt`){if(r.prompt.variables.length>0){p(r.prompt);return}n(r.prompt.content)}else if(g){let t=e.length-(g[1].length+1);n(`${e.slice(0,t)}$${r.slug} `)}}};if((0,Q.useImperativeHandle)(r,()=>({handleKeyDown(t){return f?t.key===`Escape`?(t.preventDefault(),p(null),!0):t.key===`Enter`:y.length===0?!1:t.key===`ArrowDown`?(t.preventDefault(),d(e=>(e+1)%y.length),!0):t.key===`ArrowUp`?(t.preventDefault(),d(e=>(e-1+y.length)%y.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)(er,{prompt:f,onCancel:()=>p(null),onInsert:e=>{p(null),n(e)}})});let w=h?`prompt`:g?`skill`:null,T=h?a!==null:c!==null,E=h?h[1]===``:g?g[1]===``:!1;return y.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(h?`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:y.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===u,onMouseEnter:()=>d(t),onMouseDown:e=>{e.preventDefault(),C(t)},className:W(`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)(L,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(x,{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))})});tr.displayName=`ComposerSuggestions`;var nr=(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},rr=({value:e,onChange:t,disabled:n=!1,buttonClassName:r})=>{let{t:i}=s(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=!1;return Ie.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]);let[p,m]=(0,Q.useState)(void 0);if((0,Q.useLayoutEffect)(()=>{if(!a)return;let e=()=>{let e=f.current;if(!e)return;let t=e.getBoundingClientRect().top,n=0;for(let t=e.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e,overflowX:r}=getComputedStyle(t);(e!==`visible`||r!==`visible`)&&(n=Math.max(n,t.getBoundingClientRect().top))}m(Math.max(160,Math.floor(t-n-24)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[a]),!u||!c)return null;let h=c.filter(e=>e.source===`builtin`),g=new Map;for(let e of c)e.serverId&&g.set(e.serverId,e.serverName??e.serverId);let _=[...g.entries()],v=h.map(e=>e.name),y=_.map(([e])=>e),b=new Set(e.builtinTools??v),x=new Set(e.serverIds??y),S=(n,r,i,a,o)=>(0,$.jsxs)(`label`,{className:W(`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 shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,disabled:n,onClick:()=>o(e=>!e),className:W(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`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)(_e,{className:`h-4 w-4`})}),a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full inset-s-0 z-30 mb-2 flex w-72 flex-col rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-200 dark:bg-dark-50`,style:{maxHeight:p},"data-testid":`composer-tools-menu`,children:[(0,$.jsxs)(`label`,{className:`flex shrink-0 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`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,"data-testid":`composer-tools-options`,children:[h.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`)}),h.map(n=>S(n.name,n.name,void 0,b.has(n.name),()=>t({...e,enabled:!0,builtinTools:nr(e.builtinTools,v,n.name)})))]}),_.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`)}),_.map(([n,r])=>S(n,r,void 0,x.has(n),()=>t({...e,enabled:!0,serverIds:nr(e.serverIds,y,n)})))]})]}),(0,$.jsx)(`p`,{className:`mt-1 shrink-0 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`)})]})]})},ir={enabled:!1,builtinTools:null,serverIds:null},ar=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}:{}}},or=[`noul`,`choice`,`score`],sr=({questions:e,onSave:t,disabled:n=!1})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),o=Object.values(e??{});return(0,$.jsxs)(`div`,{"data-testid":`decision-questions-bar`,className:`mb-2 flex items-start gap-2 rounded-xl border border-line bg-surface-raised px-3 py-2 text-xs text-ink-muted`,children:[(0,$.jsx)(l,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary-600 dark:text-primary-400`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium text-ink`,children:r(`chat.decision.barTitle`)}),o.length===0?(0,$.jsx)(`p`,{className:`mt-0.5 leading-5`,children:r(`chat.decision.interactiveHint`)}):(0,$.jsx)(`ul`,{className:`mt-1 flex flex-wrap gap-1.5`,children:o.map((e,t)=>(0,$.jsxs)(`li`,{dir:`auto`,className:`max-w-full truncate rounded-md bg-primary-50 px-2 py-0.5 text-primary-700 dark:bg-primary-900/30 dark:text-primary-300`,title:e.instructions,children:[(0,$.jsx)(`span`,{className:`me-1 opacity-70`,children:r(`chat.decision.types.${e.type}`)}),e.instructions]},t))})]}),(0,$.jsx)(Z,{size:`sm`,variant:`outline`,disabled:n,onClick:()=>a(!0),"data-testid":`decision-questions-edit`,children:o.length===0?r(`chat.decision.add`):r(`chat.decision.edit`)}),i&&(0,$.jsx)(lr,{questions:e,onClose:()=>a(!1),onSave:async e=>{await t(e),a(!1)}})]})},cr=(e,t)=>t.kind===`too-many`?e(`chat.decision.errors.tooMany`,{max:qt.maxQuestions}):e(`chat.decision.errors.${t.kind}`,{number:t.question}),lr=({questions:e,onClose:t,onSave:n})=>{let{t:r}=s(),i=(0,Q.useId)(),a=(0,Q.useId)(),[o,c]=(0,Q.useState)(()=>{let t=Yt(e);return t.length>0?t:[Jt()]}),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(!1),p=(e,t)=>{u(null),c(n=>n.map((n,r)=>r===e?t(n):n))},m=async e=>{let t=Xt(e);if(!t.ok)u(cr(r,t.error));else{f(!0);try{await n(t.questions)}finally{f(!1)}}};return(0,$.jsxs)(G,{titleId:i,title:r(`chat.decision.dialogTitle`),subtitle:r(`chat.decision.dialogSubtitle`),onClose:t,widthClassName:`max-w-2xl`,testId:`decision-questions-dialog`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{variant:`ghost`,disabled:d,onClick:()=>void m([]),"data-testid":`decision-questions-interactive`,children:r(`chat.decision.useInteractive`)}),(0,$.jsx)(Z,{variant:`outline`,disabled:d,onClick:t,children:r(`common.cancel`)}),(0,$.jsx)(Z,{disabled:d,onClick:()=>void m(o),"data-testid":`decision-questions-save`,children:r(`common.save`)})]}),children:[o.map((e,t)=>{let n=`${a}-${t}`;return(0,$.jsxs)(`fieldset`,{className:`space-y-3 rounded-2xl border border-line p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium text-ink`,children:r(`chat.decision.questionNumber`,{number:t+1})}),(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`chat.decision.removeQuestion`),title:r(`chat.decision.removeQuestion`),onClick:()=>c(e=>e.filter((e,n)=>n!==t)),className:`rounded-lg p-1.5 text-ink-muted hover:bg-interactive-hover hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500`,children:(0,$.jsx)(V,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{role:`radiogroup`,"aria-label":r(`chat.decision.typeLabel`),className:`flex flex-wrap gap-1.5`,children:or.map(n=>(0,$.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":e.type===n,onClick:()=>p(t,e=>({...e,type:n})),className:W(`rounded-full px-2.5 py-1 text-xs font-medium transition-colors`,e.type===n?`bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-300`:`bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-200 dark:text-gray-400 dark:hover:bg-dark-300`),children:r(`chat.decision.types.${n}`)},n))}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`${n}-q`,className:Ne,children:r(`chat.decision.question`)}),(0,$.jsx)(`input`,{id:`${n}-q`,dir:`auto`,value:e.instructions,placeholder:r(`chat.decision.placeholders.${e.type}`),onChange:e=>p(t,t=>({...t,instructions:e.target.value})),className:ke})]}),e.type===`noul`&&(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[`trueDescription`,`falseDescription`].map(i=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`${n}-${i}`,className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:r(i===`trueDescription`?`chat.decision.yesMeans`:`chat.decision.noMeans`)}),(0,$.jsx)(`input`,{id:`${n}-${i}`,dir:`auto`,value:e[i],onChange:e=>p(t,t=>({...t,[i]:e.target.value})),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`})]},i))}),e.type===`choice`&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:r(`chat.decision.options`)}),e.options.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{dir:`auto`,"aria-label":r(`chat.decision.optionName`,{number:n+1}),placeholder:r(`chat.decision.optionNamePlaceholder`),value:e.name,onChange:e=>p(t,t=>({...t,options:t.options.map((t,r)=>r===n?{...t,name:e.target.value}:t)})),className:W(`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`,`w-2/5`)}),(0,$.jsx)(`input`,{dir:`auto`,"aria-label":r(`chat.decision.optionDescription`,{number:n+1}),placeholder:r(`chat.decision.optionDescriptionPlaceholder`),value:e.description,onChange:e=>p(t,t=>({...t,options:t.options.map((t,r)=>r===n?{...t,description:e.target.value}:t)})),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`chat.decision.removeOption`,{number:n+1}),onClick:()=>p(t,e=>({...e,options:e.options.filter((e,t)=>t!==n)})),className:`shrink-0 rounded-lg p-1.5 text-ink-muted hover:bg-interactive-hover hover:text-ink`,children:(0,$.jsx)(R,{className:`h-4 w-4`})})]},n)),e.options.length<qt.maxOptions&&(0,$.jsxs)(Z,{size:`sm`,variant:`ghost`,onClick:()=>p(t,e=>({...e,options:[...e.options,{name:``,description:``}]})),children:[(0,$.jsx)(xe,{className:`me-1 h-3.5 w-3.5`}),r(`chat.decision.addOption`)]})]}),e.type===`score`&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:r(`chat.decision.levels`)}),e.levels.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`w-5 shrink-0 text-end text-xs tabular-nums text-ink-muted`,children:n+1}),(0,$.jsx)(`input`,{dir:`auto`,"aria-label":r(`chat.decision.levelLabel`,{number:n+1}),placeholder:r(`chat.decision.levelPlaceholder`),value:e,onChange:e=>p(t,t=>({...t,levels:t.levels.map((t,r)=>r===n?e.target.value:t)})),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`chat.decision.removeLevel`,{number:n+1}),onClick:()=>p(t,e=>({...e,levels:e.levels.filter((e,t)=>t!==n)})),className:`shrink-0 rounded-lg p-1.5 text-ink-muted hover:bg-interactive-hover hover:text-ink`,children:(0,$.jsx)(R,{className:`h-4 w-4`})})]},n)),e.levels.length<qt.maxLevels&&(0,$.jsxs)(Z,{size:`sm`,variant:`ghost`,onClick:()=>p(t,e=>({...e,levels:[...e.levels,``]})),children:[(0,$.jsx)(xe,{className:`me-1 h-3.5 w-3.5`}),r(`chat.decision.addLevel`)]})]})]},t)}),o.length<qt.maxQuestions&&(0,$.jsxs)(Z,{variant:`outline`,onClick:()=>c(e=>[...e,Jt()]),"data-testid":`decision-questions-add`,children:[(0,$.jsx)(xe,{className:`me-1 h-4 w-4`}),r(`chat.decision.addQuestion`)]}),l&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-red-600 dark:text-red-400`,children:l})]})},ur=Y(`components:chat-input`),dr=560,fr=({onSendMessage:e,onStopGeneration:t,onCancelComparison:n,onOpenVoiceMode:r,disabled:i=!1})=>{let{t:a}=s(),[o,c]=(0,Q.useState)(``),l=(0,Q.useRef)(``),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(null),[g,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1),[C,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)([]),k=X(e=>e.pendingComparisons),[A,j]=(0,Q.useState)(ir),M=X(e=>e.currentSession?.isPrivate===!0);(0,Q.useEffect)(()=>{let e=!1;return Ge.getConfig().then(t=>{!e&&t.success&&t.data&&S(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[N,ee]=(0,Q.useState)(null),[te,re]=(0,Q.useState)(!1),[ie,P]=(0,Q.useState)([]),[ae,F]=(0,Q.useState)(!1),[I,se]=(0,Q.useState)(!1),[L,le]=(0,Q.useState)(null),[de,fe]=(0,Q.useState)(!1),pe=(0,Q.useRef)(null),me=(0,Q.useRef)(null),z=(0,Q.useRef)(null),[ge,_e]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(t=>{let n=t[0]?.contentRect.width??e.clientWidth;_e(n<dr)});return t.observe(e),()=>t.disconnect()},[]);let{isGenerating:ye}=Je(),be=Je(e=>e.preferences.generationOptions),B=Je(e=>e.preferences.imageGenSettings?.enabled===!0),V=B&&de,{currentSession:H,models:we}=X(),Ee=Je(e=>H?.model?e.preferences.modelGenerationOptions?.[H.model]:void 0),U=H?.id,[De,Oe]=(0,Q.useState)(U);De!==U&&(Oe(U),D([]));let ke=(0,Q.useRef)(null),Ae=(0,Q.useRef)(null),G=(0,Q.useMemo)(()=>dt({model:H?.model??``,personaId:H?.personaId,providerType:H?.providerType,providerId:H?.providerId}),[H?.model,H?.personaId,H?.providerId,H?.providerType]),K=(0,Q.useMemo)(()=>St(we,G),[we,G]),je=G.model?gt(K,G):``,Me=ct(we,G),Ne=pt(we,G)?.isDecision===!0,Pe=x&&!Ne;(0,Q.useEffect)(()=>{let e=!1;return B&&(async()=>{try{let t=await Ke.getPlugins();if(e)return;fe(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;fe(!1)}})(),()=>{e=!0}},[B]),(0,Q.useEffect)(()=>{if(!y)return;let e=e=>{pe.current&&!pe.current.contains(e.target)&&(b(!1),ee(null))},t=e=>{e.key!==`Escape`||e.defaultPrevented||(b(!1),ee(null),re(!1),pe.current?.querySelector(`button`)?.focus())};return window.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[y]);let J=()=>{b(!1),ee(null),re(!1)};(0,Q.useEffect)(()=>{if(!te)return;let e=!1;return Be.getCollections().then(t=>{!e&&t.success&&t.data&&P(t.data)}).catch(()=>{}),()=>{e=!0}},[te]);let Fe=H?.settings?.generationOptions?.think,Ie=Ee?.think??be?.think??null,Le=(0,Q.useMemo)(()=>we.find(e=>e.name===H?.model),[we,H?.model]),[Re,ze]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=H?.model;if(!e||we.length===0||!Le||Le.isPlugin||Le.isAgent)return;let t=!1;return qe.getModelDefaults(e).then(n=>{!t&&n.success&&n.data&&ze({model:e,supportsThinking:n.data.supportsThinking,options:n.data.options??{},trainedContextLength:n.data.trainedContextLength,contextCapped:n.data.contextCapped})}).catch(()=>{}),()=>{t=!0}},[Le,H?.model,we.length]);let He=Re?.model===H?.model?Re:null,Ue=He?.supportsThinking,We=!!(H&&!Ne&&!Le?.isAgent&&(Le?.isPlugin?Le.reasoningSupport!==!1:Ue!==!1)),Ye=vt({model:Le,sessionOptions:H?.settings?.generationOptions,pinnedOptions:Ee,modelDefaults:He?.options,globalOptions:be}),Y=X(e=>e.contextWindowMessages),Xe=(0,Q.useMemo)(()=>bt({messages:H?.messages??[],budget:Ye,systemPrompt:L?.parameters?.system_prompt,windowMessages:Y}),[Ye,Y,L,H?.messages]),Ze=(e,t,n)=>{let r=e=>({...e,[t]:n});X.setState(t=>({currentSession:t.currentSession?.id===e?{...t.currentSession,settings:r(t.currentSession.settings)}:t.currentSession,sessions:t.sessions.map(t=>t.id===e?{...t,settings:r(t.settings)}:t)}))},Qe=async e=>{if(!H)return;let t=H.settings?.decisionQuestions,n={...H.settings};if(e?n.decisionQuestions=e:delete n.decisionQuestions,X.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{let e=await q.updateSession(H.id,{settings:n});if(!e.success)throw Error(e.error);d.success(a(`chat.decision.saved`))}catch(e){ur.error(`Failed to save the decision questions:`,e),Ze(H.id,`decisionQuestions`,t),d.error(a(`chat.decision.saveFailed`))}},$e=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(X.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 q.updateSession(H.id,{settings:n})}catch(e){ur.error(`Failed to update the thinking setting:`,e),Ze(H.id,`generationOptions`,H.settings?.generationOptions),d.error(a(`chat.input.thinkingUpdateFailed`))}},tt=H?.settings?.knowledgeCollectionIds??[],nt=async e=>{if(!H)return;let t=tt.includes(e)?tt.filter(t=>t!==e):[...tt,e],n={...H.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(X.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 q.updateSession(H.id,{settings:n})}catch(e){ur.error(`Failed to update knowledge collections:`,e),Ze(H.id,`knowledgeCollectionIds`,H.settings?.knowledgeCollectionIds),d.error(a(`chat.input.menu.attachFailed`))}},rt=At({onStart:()=>{l.current=o},onText:e=>{let t=l.current;c(t?`${t} ${e}`:e)},ownerKey:U}),it=rt.phase===`starting`,at=rt.phase===`recording`,st=rt.phase===`transcribing`,lt=rt.supported,ut=rt.providerModel,ft=rt.sources.filter(e=>e.kind===`provider`),mt=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){J(),se(!0);try{let e=await Be.uploadDocument(t,H?.id);e.success?(d.success(a(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):d.error(e.error||a(`chat.input.menu.attachFailed`))}catch(e){ur.error(`Document upload failed:`,e),d.error(a(`chat.input.menu.attachFailed`))}finally{se(!1)}}},_t=async()=>{let e=N?.trim();if(e&&!ae){F(!0);try{let t=await Be.fetchWebpage(e,H?.id);t.success?(d.success(a(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),J()):d.error(t.error||a(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.input.menu.attachFailed`);ur.error(`Webpage attach failed:`,e),d.error(t)}finally{F(!1)}}},Ct=async e=>{if(U&&!M)try{let t=await q.enqueuePrompt(U,e);t.success&&t.data?(ot(U,t.data.queue),c(``)):d.error(t.error||a(`chat.queue.enqueueFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.queue.enqueueFailed`);ur.error(`Failed to queue the prompt:`,e),d.error(t)}},wt=t=>{if(t.preventDefault(),!o.trim())return;if(ye){f.length===0&&!M&&U&&Ct(o.trim());return}if(!Me){d.error(a(`chat.model.selectBeforeSending`));return}let n=M||Ne?{}:ar(A),r=M||Ne?[]:qn(we,E);e(o.trim(),f.length>0?f:void 0,Ne?void 0:m||void 0,Pe&&C?!0:void 0,n.tools,n.toolSelection,r.length>0?r:void 0),c(``),p([])},Tt=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||Ae.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),wt(e))},Et=()=>{t()};(0,Q.useEffect)(()=>{let e=ke.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 Ve.getPersona(H.personaId);if(e.success&&e.data)le(e.data);else{ur.warn(`Persona ${H.personaId} not found, clearing reference`),le(null);let{setCurrentSession:e}=X.getState();e({...H,personaId:void 0})}}catch(e){if(ur.error(`Failed to load current persona:`,e),le(null),H){let{setCurrentSession:e}=X.getState();e({...H,personaId:void 0})}}else le(null)})()},[H?.personaId]);let Dt=async e=>{let t=xt(K,e.target.value);if(t&&H)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await Ve.getPersona(e);if(!n.success||!n.data){d.error(a(`chat.persona.loadFailed`));return}let r=await q.updateSession(H.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(r.success&&r.data){let{sessions:e}=X.getState(),t=e.map(e=>e.id===H.id?r.data:e);X.setState({sessions:t,currentSession:r.data}),d.success(a(`chat.persona.applied`))}}else{let e=await q.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}=X.getState(),n=t.map(t=>t.id===H.id?e.data:t);X.setState({sessions:n,currentSession:e.data}),d.success(a(`chat.model.updated`))}}}catch(e){ur.error(`Failed to update session:`,e),d.error(a(`chat.toasts.updateFailed`))}},Nt=f.length>0||m!==null,Pt=a(C?`chat.input.webSearchOn`:`chat.input.webSearchOff`),Ft=st||it?a(`common.cancel`):at?a(`chat.input.voiceStop`):ut?a(`chat.input.providerTranscriptionDisclosure`,{provider:ut.plugin}):a(`chat.input.voiceInput`);return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{ref:z,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/8 dark:bg-dark-200/90`,children:[(0,$.jsx)(Fn,{images:f,onImagesChange:p,maxImages:5,sessionId:H?.id,disabled:i}),!Ne&&(0,$.jsx)(Bn,{format:m,onFormatChange:h})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[U&&!M&&(H?.settings?.promptQueue?.length??0)>0&&(0,$.jsx)(Kn,{sessionId:U,queue:H.settings.promptQueue}),U&&k.some(e=>e.sessionId===U)&&(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:k.filter(e=>e.sessionId===U).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/8 dark:bg-dark-200/70 dark:text-dark-700`,"data-testid":`pending-comparison`,children:[(0,$.jsx)(O,{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)(R,{className:`h-3 w-3`,"aria-hidden":`true`})})]},e.assistantMessageId))}),Ne&&H&&(0,$.jsx)(sr,{questions:H.settings?.decisionQuestions,onSave:Qe,disabled:i}),(0,$.jsx)(`form`,{onSubmit:wt,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:jt,children:[(0,$.jsx)(tr,{ref:Ae,message:o,disabled:i,onApply:e=>{c(e),ke.current?.focus()}}),(0,$.jsx)(Nn,{ref:ke,value:o,onChange:e=>c(e.target.value),onKeyDown:Tt,placeholder:a(`chat.input.placeholder`),"aria-label":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:pe,className:`relative shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{g?v(!1):(b(e=>!e),ee(null))},className:W(`h-9 w-9 p-0! rounded-full 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`,Nt&&`text-primary-600 dark:text-primary-400`,(g||y)&&`bg-hover-solid text-ink`),title:a(`chat.input.attachments`),"aria-label":a(`chat.input.attachments`),"aria-expanded":g||y,children:I||ae?(0,$.jsx)(O,{className:`h-4 w-4 animate-spin`}):Nt?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Se,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -inset-e-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)(u,{className:`h-4 w-4`}):(0,$.jsx)(xe,{className:`h-4 w-4`})}),y&&(0,$.jsx)(`div`,{className:`absolute bottom-full inset-s-0 z-30 mb-2 w-64 rounded-2xl border border-black/8 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/9 dark:bg-dark-100/95`,children:te?(0,$.jsxs)(`div`,{className:`p-1`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-ink-muted`,children:a(`chat.input.menu.attachKnowledge`)}),ie.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-ink-subtle`,children:a(`chat.input.menu.noCollections`)}):ie.map(e=>{let t=tt.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void nt(e.id),className:W(`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)(he,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(ce,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>re(!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`)})]}):N===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{v(!0),J()},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)(_,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.uploadImages`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>me.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)(Te,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ee(``),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)(ve,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>re(!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)(he,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachKnowledge`)]}),tt.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:tt.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{v(!0),J()},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)(oe,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.structuredOutput`)]}),ge&&Pe&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{T(e=>!e),J()},className:W(`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`,C&&`text-primary-600 dark:text-primary-400`),"aria-pressed":C,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(ve,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(C?`chat.input.webSearchOn`:`chat.input.webSearchOff`)]}),C&&(0,$.jsx)(ce,{className:`h-3.5 w-3.5 shrink-0`})]}),ge&&lt&&r&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{et(),r(),J()},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)(ue,{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`,{htmlFor:`chat-attach-webpage-url`,className:`mb-1.5 block text-[11px] font-medium text-ink-muted`,children:a(`chat.input.menu.attachWebpage`)}),(0,$.jsx)(`input`,{id:`chat-attach-webpage-url`,type:`url`,value:N,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),_t()):e.key===`Escape`&&ee(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/8 bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ee(null),children:a(`common.cancel`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:()=>void _t(),disabled:!N.trim(),loading:ae,children:a(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:me,type:`file`,accept:Yn,className:`hidden`,onChange:e=>void mt(e)})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-1 sm:gap-1.5`,children:[We&&(0,$.jsx)(Ot,{value:Fe,inheritedValue:Ie,onChange:e=>void $e(e)}),Pe&&!ge&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>T(e=>!e),className:W(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,C&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:Pt,"aria-label":Pt,"aria-pressed":C,children:(0,$.jsx)(ve,{className:`h-4 w-4`})}),!M&&!Ne&&(0,$.jsx)(rr,{value:A,onChange:j}),!M&&!Ne&&H&&!ge&&(0,$.jsx)(Jn,{models:we,currentModelKey:yt(dt(H)),selectedKeys:E,onChange:D,disabled:i}),ft.length>0&&!ge&&(0,$.jsx)(`select`,{value:rt.activeSourceKey,onChange:e=>rt.setSourceKey(e.target.value),disabled:it||at||st,"aria-label":a(`chat.input.transcriptionSource`),title:ut?a(`chat.input.providerTranscriptionDisclosure`,{provider:ut.plugin}):a(`chat.input.transcriptionSource`),className:`h-8 max-w-32 rounded-lg border border-black/8 bg-transparent px-1.5 text-[11px] text-gray-500 outline-hidden focus:border-primary-500 focus:ring-2 focus:ring-primary-500/30 dark:border-white/9 dark:text-dark-600`,children:rt.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))}),lt&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void rt.toggle(),className:W(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,(it||at||st)&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:Ft,"aria-label":Ft,"aria-pressed":it||at||st,children:it?(0,$.jsx)(O,{className:`h-4 w-4 animate-spin`}):st||at?(0,$.jsx)(w,{className:`h-4 w-4`}):(0,$.jsx)(Ce,{className:`h-4 w-4`})}),lt&&r&&!ge&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{et(),r()},className:W(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`),title:a(`voiceMode.open`),"aria-label":a(`voiceMode.open`),"data-testid":`voice-mode-open`,children:(0,$.jsx)(ue,{className:`h-4 w-4`})}),H&&(0,$.jsx)(Wn,{usage:Xe,trainedBudget:He?.contextCapped?He.trainedContextLength:void 0}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),H&&K.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(kt,{models:K,selectedModel:je,onModelChange:Dt,getModelValue:ht,currentPersona:L,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:V})}),ye?(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:Et,className:W(`h-9 w-9 p-0 rounded-full 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`),"aria-label":a(`chat.input.stopGeneration`),children:(0,$.jsx)(w,{className:`h-4 w-4`})}):(0,$.jsx)(Z,{type:`submit`,variant:`primary`,size:`sm`,disabled:!o.trim()||i||!Me,className:Mt,title:a(`chat.input.sendMessage`),"aria-label":a(`chat.input.sendMessage`),children:(0,$.jsx)(ne,{className:`h-4 w-4`})})]})]})]})}),ut&&(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:ut.plugin})}),H&&K.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(kt,{models:K,selectedModel:je,onModelChange:Dt,getModelValue:ht,currentPersona:L,className:`w-full`,compact:!0,showImageGen:V})}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-ink-subtle`,children:[(0,$.jsx)(Ln,{sessionId:H?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:a(`chat.footer.disclaimer`)}),Nt&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,f.length>0&&a(`chat.footer.images`,{count:f.length}),f.length>0&&m&&` • `,m&&a(`chat.footer.structuredOutput`)]})]})]})]})]})})},pr={phase:`idle`,muted:!1,turn:0,error:null},mr=e=>({...e,phase:`listening`,turn:e.turn+1});function hr(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`}:mr(e):e;case`reply`:return e.phase===`generating`?t.speak?{...e,phase:`speaking`}:mr(e):e;case`spoken`:case`barge-in`:return e.phase===`speaking`?mr(e):e;case`fail`:return e.phase===`idle`?e:{...mr(e),error:t.message}}}var gr=Y(`utils:voice-mode-controller`),_r=.015,vr=200,yr=1500,br=6e4,xr=300,Sr=18e4,Cr=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},wr=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},Tr=class{options;state=pr;closed=!1;useBrowserRecognition=!1;sttModel=null;ttsModels=[];stream=null;recorder=null;chunks=[];audioContext=null;analyser=null;monitorTimer=null;pollTimer=null;recognition=null;ttsSession=null;abortController=null;constructor(e){this.options=e}async start(){try{let[e,t]=await Promise.all([We.getModels().catch(()=>({success:!1,data:[]})),Fe.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=>!!wr(e)),i=!!r&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia,a=!!Cr();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){gr.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),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=hr(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){gr.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=Cr();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=wr(t);if(!n)this.fail(e,this.options.messages.microphoneFailed);else 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});this.chunks=[],t.size===0?this.handleTranscript(e,``):this.transcribeRecording(e,t)},r.start();let i=0,a=0,o=!1,s=Date.now();this.clearMonitor(),this.monitorTimer=window.setInterval(()=>{this.staleTurn(e)?this.clearMonitor():this.state.muted?(i=0,a=0):(this.analyser&&(this.rmsLevel()>_r?(i+=50,a=0,i>=vr&&(o=!0)):(i=0,o&&(a+=50))),(o&&a>=yr||Date.now()-s>=br)&&this.finishProviderCapture(e))},50)}catch(t){gr.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,We.transcribe(t,n,{language:this.options.locale?.split(`-`)[0],signal:r.signal}).then(t=>this.handleTranscript(e,t.text??``)).catch(t=>{r.signal.aborted||(gr.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)}else Date.now()-i>Sr&&(this.clearPoll(),this.fail(e,this.options.messages.replyTimeout))},250)}speakReply(e,t){let n=this.options.snapshot().ttsSettings,r=ze(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=$e(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=Ze({concurrency:3,initialBufferSize:Math.min(2,l.length),generate:(e,{signal:t})=>Fe.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=tt(u);this.startBargeInMonitor(e,u),u.play(l).then(()=>{this.staleTurn(e)||this.finishSpeaking(e)}).catch(t=>{this.staleTurn(e)||Xe(t)||(gr.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;else if(this.rmsLevel()>_r){if(n+=50,n>=xr){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)}},Er=({onClose:e,onSendMessage:t,isStreaming:n,lastAssistantMessage:r})=>{let{t:i,i18n:a}=s(),{preferences:o}=Je(),[c,l]=(0,Q.useState)(pr),[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 Tr({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 _=c.phase,v=f===!1?`voiceMode.unsupported`:_===`listening`?c.muted?`voiceMode.muted`:`voiceMode.listening`:_===`transcribing`?`voiceMode.transcribing`:_===`generating`?`voiceMode.generating`:_===`speaking`?`voiceMode.speaking`:`voiceMode.starting`;return(0,Bt.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-sm 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)(R,{className:`h-5 w-5`})}),(0,$.jsx)(`div`,{className:W(`flex h-28 w-28 items-center justify-center rounded-full border-4 transition-colors`,_===`listening`&&!c.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)(O,{className:`h-10 w-10 animate-spin`}):c.muted?(0,$.jsx)(A,{className:`h-10 w-10`}):_===`speaking`?(0,$.jsx)(ue,{className:`h-10 w-10`}):(0,$.jsx)(Ce,{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)}),c.error&&(0,$.jsx)(`p`,{className:`mt-1 text-sm text-red-600 dark:text-red-400`,children:c.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":c.muted?i(`voiceMode.unmute`):i(`voiceMode.mute`),"aria-pressed":c.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:c.muted?(0,$.jsx)(A,{className:`h-5 w-5`}):(0,$.jsx)(Ce,{className:`h-5 w-5`})}),_===`listening`&&!c.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)(ce,{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)(p,{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)},Dr=Y(`components:chat-controls-panel`),Or=[{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`}],kr=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i,i18n:a}=s(),o=X(e=>e.draftSessionSettings),c=X(e=>e.setDraftSessionSettings),l=e?.model??t??``,u=Je(e=>e.preferences.generationOptions),d=Je(e=>e.preferences.modelGenerationOptions?.[l]),f=X(e=>e.models.find(e=>e.name===l)),p=f&&!f.isPlugin&&!f.isAgent&&!f.isPersona?l:``,[m,h]=(0,Q.useState)({options:{},contextCapped:!1});(0,Q.useEffect)(()=>{if(!n||!p)return;let e=!1;return qe.getModelDefaults(p).then(t=>{!e&&t.success&&t.data&&h({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,p]);let g=(0,Q.useMemo)(()=>({...u??{},...m.options,...d??{}}),[u,m.options,d]),_=(0,Q.useMemo)(()=>e?.messages.find(e=>e.role===`system`&&!lt(e.content)),[e?.messages]),[v,y]=(0,Q.useState)(_?.content??o.systemPrompt??``),[b,x]=(0,Q.useState)(e?.settings?.generationOptions??o.generationOptions??{}),[S,C]=(0,Q.useState)(!1),[w,E]=(0,Q.useState)(e?.settings?.compaction!==!1),[D,O]=(0,Q.useState)(e?.id??`draft`),k=e?.id??`draft`;D!==k&&(O(k),y(_?.content??o.systemPrompt??``),x(e?.settings?.generationOptions??o.generationOptions??{}),E(e?.settings?.compaction!==!1));let A=e=>{x(t=>{let n={...t},r=Nt(e);return r===null?delete n.think:n.think=r,n})},j=(e,t)=>{x(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},M=async()=>{C(!0);try{let t=v.trim(),n=_?.content??``,a=Object.fromEntries(Object.entries(b).filter(([,e])=>e!==void 0)),o=e?{...e.settings,generationOptions:a}:Object.keys(a).length>0?{generationOptions:a}:void 0;if(o&&e&&(w?delete o.compaction:o.compaction=!1),!e){c({systemPrompt:t||void 0,generationOptions:o?.generationOptions}),T.success(i(`chat.controls.saved`)),r();return}let s=e.messages;if(t!==n.trim()&&(_?s=t?e.messages.map(e=>e.id===_.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==_.id):t&&(s=[{id:Ee(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)X.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:s,settings:o}:t.currentSession}));else{let t=await q.updateSession(e.id,{messages:s,settings:o});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;X.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}T.success(i(`chat.controls.saved`)),r()}catch(e){Dr.error(`Failed to save chat controls:`,e),T.error(i(`chat.controls.saveFailed`))}finally{C(!1)}};return n?(0,$.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:`flex h-full w-84 shrink-0 flex-col border-s border-black/6 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`,{type:`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`),"aria-label":i(`common.close`),children:(0,$.jsx)(R,{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`,{htmlFor:`chat-control-system-prompt`,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`,{id:`chat-control-system-prompt`,dir:`auto`,value:v,onChange:e=>y(e.target.value),placeholder:i(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/8 bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 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:Pt(b.think),onChange:e=>A(e.target.value),className:`w-full rounded-xl border border-black/8 bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900`,children:Ft.map(e=>(0,$.jsx)(`option`,{value:e,children:e==="default"&&g.think!==void 0&&g.think!==null?i(`settings.generation.thinkingLevels.defaultWith`,{level:i(`settings.generation.thinkingLevels.${Pt(g.think)}`)}):i(`settings.generation.thinkingLevels.${e}`)},e))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-ink-muted`,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:w?`default`:`off`,onChange:e=>E(e.target.value!==`off`),className:`w-full rounded-xl border border-black/8 bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 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-ink-muted`,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-ink-muted`,children:i(`chat.controls.advancedParamsDescription`)}),m.contextCapped&&m.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:g.num_ctx?.toLocaleString(a.language),trained:m.trainedContextLength.toLocaleString(a.language)})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:Or.map(e=>{let t=b[e.key],n=g[e.key],r=m.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-ink-muted`,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=>j(e.key,t.target.value),className:`w-24 rounded-lg border border-black/8 bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 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/6 px-4 py-3 dark:border-white/[0.07] lg:pb-16`,children:[(0,$.jsx)(`button`,{onClick:()=>{x({}),y(_?.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)(Z,{onClick:()=>void M(),size:`sm`,disabled:S,children:i(S?`common.saving`:`common.save`)})]})]}):null},Ar=Y(`components:chat-sources-panel`),jr=6,Mr=[],Nr=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}},Pr=({session:e})=>{let{t,i18n:n}=s(),[r,i]=(0,Q.useState)({sessionId:``,docs:Mr}),a=!e.isPrivate&&r.sessionId===e.id?r.docs:Mr,[o,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=(0,Q.useRef)(null);Tt(p,{enabled:d,onClose:()=>f(!1)});let{webSources:m,ragSources:h,fullContextSkipped:g}=(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=()=>{Be.getDocuments(e.id).then(n=>{!t&&n.success&&Array.isArray(n.data)&&i({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 _=(0,Q.useMemo)(()=>{let e=new Map;for(let t of a)e.set(t.id,{...t,used:!1});for(let t of h)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())},[a,h]),v=e.settings?.fullDocumentContext===!0,y=(0,Q.useMemo)(()=>a.reduce((e,t)=>e+Math.ceil((t.contentChars??0)/4),0),[a]),b=async()=>{let n=e.settings?.fullDocumentContext,r={...e.settings,fullDocumentContext:!v||void 0};if(X.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,settings:r}:t.currentSession,sessions:t.sessions.map(t=>t.id===e.id?{...t,settings:r}:t)})),!e.isPrivate)try{await q.updateSession(e.id,{settings:r})}catch(r){Ar.error(`Failed to update the full-document setting:`,r);let i=e=>({...e,fullDocumentContext:n});X.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,settings:i(t.currentSession.settings)}:t.currentSession,sessions:t.sessions.map(t=>t.id===e.id?{...t,settings:i(t.settings)}:t)})),T.error(t(`chat.sources.fullContextFailed`))}},x=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(m.length===0&&_.length===0)return null;let S=o?m:m.slice(0,jr),C=l?_:_.slice(0,jr),w=(e,n,r)=>(e>0||n)&&(0,$.jsx)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`mt-1 flex items-center gap-1 px-1 text-[12px] text-ink-muted transition-colors hover:text-ink`,children:n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ee,{className:`h-3 w-3`}),t(`chatMessage.showLess`,`Show less`)]}):`${t(`chatMessage.showMore`)} (${e})`}),E=(0,$.jsxs)($.Fragment,{children:[m.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-ink-muted`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:S.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/4 dark:hover:bg-white/5`,title:e.url,children:[(0,$.jsx)(ve,{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-ink-muted`,children:Nr(e.url)})]})]})},e.url))}),w(m.length-S.length,o,()=>c(e=>!e))]}),_.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-ink-muted`,children:t(`settings.tabs.documents`,`Documents`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:C.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)(Te,{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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-primary-500`}),(0,$.jsx)(`span`,{className:`sr-only`,children:t(`chat.sources.usedByRetrieval`)})]})]}),e.full?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-ink-muted`,"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-ink-muted`,"data-testid":`chat-source-citation`,children:x(e.citations)}):null]},e.id))}),w(_.length-C.length,l,()=>u(e=>!e)),(0,$.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-center gap-2 px-1 text-[12px] text-ink-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:v,onChange:b,"data-testid":`full-document-context-toggle`,className:`h-3.5 w-3.5 rounded-sm 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`),v&&y>0&&(0,$.jsx)(`span`,{className:`ms-1 text-ink-muted`,children:t(`documents.fullContextEstimate`,{tokens:y.toLocaleString(n.language)})})]})]}),v&&g&&(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/5 px-5 py-6 scrollbar-thin dark:border-white/6 xl:flex`,children:E}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(!0),"data-testid":`chat-sources-trigger`,className:`absolute inset-e-3 top-17 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/8 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-label":t(`chat.sources.triggerLabel`,{count:m.length+_.length}),"aria-haspopup":`dialog`,"aria-expanded":d,children:[(0,$.jsx)(he,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`absolute -inset-e-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-xs`,children:m.length+_.length})]}),d&&(0,Bt.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-xs`,onClick:()=>f(!1),"aria-label":t(`common.close`)}),(0,$.jsxs)(`div`,{ref:p,role:`dialog`,"aria-modal":`true`,tabIndex:-1,"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/8 bg-surface p-5 shadow-[0_20px_70px_rgba(0,0,0,0.3)] scrollbar-thin dark:border-white/9 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:()=>f(!1),className:`rounded-md p-1.5 text-ink-muted hover:text-ink`,"aria-label":t(`common.close`),children:(0,$.jsx)(R,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:E})]})]}),document.body)]})},Fr=({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 l=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),u=()=>Re(e,64),d=t=>{J(t.currentTarget,e.name,64)};return(0,$.jsxs)(`div`,{className:W(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:W(`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:u(),alt:e.name,className:`w-5 h-5 rounded-md object-cover`,onError:d}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),l&&(0,$.jsx)(x,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(c,{className:W(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Bt.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:W(`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-linear-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 inset-e-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,$.jsx)(R,{className:`h-3.5 w-3.5 text-white`})}),l&&(0,$.jsxs)(`div`,{className:`absolute top-2 inset-s-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)(ye,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,$.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,$.jsx)(`img`,{src:u(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:d})}),(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)(m,{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)(f,{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-sm text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(B,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-sm 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-sm text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,$.jsx)(ye,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},Ir=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Q.useRef)(null),[o,c]=(0,Q.useState)(!1),l=e=>new Promise(t=>{let n=new FileReader;n.onload=()=>t(typeof n.result==`string`?n.result:null),n.onerror=()=>{T.error(i(`chat.mediaUpload.readFailed`,{name:e.name})),t(null)},n.readAsDataURL(e)}),u=async r=>{if(!r)return;let a=n-e.length,o=Array.from(r).slice(0,Math.max(a,0)).filter(e=>e.type.startsWith(`image/`)?e.size>10485760?(T.error(i(`chat.mediaUpload.imageTooLarge`,{name:e.name})),!1):!0:(T.error(i(`chat.mediaUpload.unsupportedFileType`,{name:e.name})),!1));r.length>a&&T.error(i(`chat.mediaUpload.maxImagesAllowed`,{count:n}));let s=(await Promise.all(o.map(l))).filter(e=>e!==null);s.length>0&&t([...e,...s])},d=e=>{e.preventDefault(),c(!0)},f=e=>{e.preventDefault(),c(!1)},p=e=>{e.preventDefault(),c(!1),u(e.dataTransfer.files)},m=n=>{t(e.filter((e,t)=>t!==n))},h=e.length<n;return(0,$.jsxs)(`div`,{className:W(`space-y-3`,r),children:[h&&(0,$.jsxs)(`div`,{className:W(`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:d,onDragLeave:f,onDrop:p,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>{u(e.target.files),e.target.value=``},className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(z,{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`,{type:`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-ink-muted`,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:i(`chat.mediaUpload.uploadAlt`,{number:t+1}),className:`w-full h-full object-cover`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/0 group-hover:bg-black/50 transition-all duration-200 flex items-center justify-center`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>m(t),"aria-label":i(`chat.mediaUpload.removeImage`,{number:t+1}),className:`opacity-0 group-hover:opacity-100 focus-visible:opacity-100 [@media(hover:none)]: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)(R,{className:`h-4 w-4`})})})]},t))}),h&&e.length>0&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(_,{className:`h-4 w-4`}),i(`chat.mediaUpload.addMore`,{count:e.length,max:n})]})]})},Lr=Y(`pages:chat-page`),Rr=(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?`}},zr=(e,t,n,r=!1)=>{let i=Rt(e);return i===`time`?Rr(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.`}},Br=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},Vr=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),c=o(),{currentSession:l,sessions:d,models:f,selectedModel:p,selectedProviderType:m,selectedProviderId:h,setSelectedModel:g,createSession:_,setCurrentSession:v,loadSessions:y,getCurrentPersona:b}=X(),{user:x}=wt(),C=Je(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:w,stopGeneration:E,cancelComparison:D,regenerateLastMessage:O,editAndResendMessage:k,selectBranch:A,isStreaming:j,streamingMessage:M,streamingThinking:N,streamingMessageId:ee,toolActivities:te,activeToolCalls:re,pendingToolApproval:P,decideToolApproval:ae}=it(l?.id||``),F=b(),I=(0,Q.useMemo)(()=>({model:p,providerType:m,providerId:h}),[p,h,m]),oe=(0,Q.useMemo)(()=>St(f,I),[f,I]),se=pt(f,I)?.isDecision===!0,ce=p?gt(oe,I):``,L=ct(f,I),le=new URLSearchParams(c.search).get(`incognito`)===`1`,[ue,de]=(0,Q.useState)(Lt),[pe,R]=(0,Q.useState)(null),[me,z]=(0,Q.useState)(!1),he=Je(e=>e.preferences.showFollowUpSuggestions!==!1),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=l?.id,t=_e.current&&!j;if(_e.current=j,!e||j||!he||l?.isPrivate||!t)return;let n=l.messages[l.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||ge.current===n.id)return;ge.current=n.id;let r=!1;return q.generateFollowUps(e).then(t=>{!r&&t.success&&X.getState().currentSession?.id===e&&R({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[j,l,he]);let ye=pe&&pe.sessionId===l?.id?pe.suggestions:[],be=(0,Q.useMemo)(()=>zr(ue,x?.username,e,st(t.language)),[t.language,e,x?.username,ue]),[B,V]=(0,Q.useState)(``),[H,Ce]=(0,Q.useState)([]),[we,Te]=(0,Q.useState)(!1),[U,De]=(0,Q.useState)(!1),[Oe,ke]=(0,Q.useState)(ir),[Ae,G]=(0,Q.useState)(!1),K=(0,Q.useRef)(null),je=X(e=>e.draftSessionSettings),Me=X(e=>e.setDraftSessionSettings),Ne=je.generationOptions?.think,Pe=Je(e=>(p?e.preferences.modelGenerationOptions?.[p]?.think:void 0)??e.preferences.generationOptions?.think??null),J=(0,Q.useMemo)(()=>f.find(e=>e.name===p),[f,p]),[Fe,Ie]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!p||f.length===0||!J||J.isPlugin||J.isAgent)return;let e=!1;return qe.getModelDefaults(p).then(t=>{!e&&t.success&&t.data&&Ie({model:p,supported:t.data.supportsThinking})}).catch(()=>{}),()=>{e=!0}},[p,J,f.length]);let Le=!!(p&&!se&&!J?.isAgent&&(J?.isPlugin?J.reasoningSupport!==!1:Fe?.model!==p||Fe.supported!==!1)),Re=e=>{let t=X.getState().draftSessionSettings,n={...t.generationOptions};e===null?delete n.think:n.think=e,Me({...t,generationOptions:Object.keys(n).length?n:void 0})},ze=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){G(!0);try{let t=await Be.uploadDocument(n);t.success?(T.success(e(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):T.error(t.error||e(`chat.input.menu.attachFailed`))}catch(t){Lr.error(`Document upload failed:`,t),T.error(e(`chat.input.menu.attachFailed`))}finally{G(!1)}}};(0,Q.useEffect)(()=>{let e=!1;return Ge.getConfig().then(t=>{!e&&t.success&&t.data&&Te(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[Ve,He]=(0,Q.useState)(!1),Ue=(0,Q.useRef)(null),We=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{de(Lt())};return window.addEventListener(zt,e),()=>window.removeEventListener(zt,e)},[]);let[Ye,Y]=(0,Q.useState)(!1),[Xe,Ze]=(0,Q.useState)(!1),Qe=Br(l?.messages),$e=C&&Ye,et=(0,Q.useCallback)((t=!0)=>{let n=p?I:f[0]?ut(f[0]):null;if(!n||!ct(f,n))return t&&T.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return v({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,p,I,v,e]);(0,Q.useEffect)(()=>{d.length===0&&y()},[y,d.length]),(0,Q.useEffect)(()=>{le&&!l?.isPrivate&&et(!1)},[l?.isPrivate,le,et]),(0,Q.useEffect)(()=>{let e=!1;return C&&(async()=>{try{let t=await Ke.getPlugins();if(e)return;Y(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;Y(!1)}})(),()=>{e=!0}},[C]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`))sessionStorage.removeItem(`forceWelcomeScreen`);else if((!l?.isPrivate||n)&&d.length!==0){if(n){let e=d.find(e=>e.id===n);e&&e.id!==l?.id?v(e):e||(Lr.warn(`Session ${n} not found for current user, redirecting...`),d.length>0?r(`/c/${d[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else d.length>0&&c.pathname===`/`&&r(`/c/${d[0].id}`,{replace:!0})}})()},[n,d,v,r,l?.id,l?.isPrivate,c.pathname]),(0,Q.useEffect)(()=>{if(l?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{w(t.content,t.images,void 0,t.webSearch===!0,t.tools===!0,t.toolSelection)},100)}catch(e){Lr.error(`Failed to parse pending message:`,e)}}}},[l?.id,w]),(0,Q.useEffect)(()=>{let e=Ue.current;e&&(e.style.height=`auto`,e.style.height=B?`${Math.min(e.scrollHeight,200)}px`:``)},[B]);let tt=async t=>{if(t.preventDefault(),!B.trim()||!p)return;if(!L){T.error(e(`chat.model.selectBeforeSending`));return}Dt(`impact`);let n={content:B.trim(),images:H.length>0?H:void 0,webSearch:we&&U&&!se?!0:void 0,...se?{}:ar(Oe)};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n));let i={message:B,images:H,webSearch:U,tools:Oe};V(``),Ce([]),De(!1),ke(ir);let a;try{a=await _(p,void 0,p.startsWith(`persona:`)?p.slice(8):void 0,m,h)}catch{a=void 0}a?(await nt(a),r(`/c/${a.id}`,{replace:!0})):(sessionStorage.removeItem(`pendingMessage`),V(i.message),Ce(i.images),De(i.webSearch),ke(i.tools),X.getState().error||T.error(e(`chat.toasts.createFailed`)))},nt=(0,Q.useCallback)(async e=>{let t=X.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions,i=t.decisionQuestions;if(!n&&!r&&!i)return;let a=n?[{id:Ee(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await q.updateSession(e.id,{messages:a,settings:r||i?{...r?{generationOptions:r}:{},...i?{decisionQuestions:i}:{}}:void 0});if(t.success&&t.data){let e=t.data;X.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){Lr.error(`Failed to apply chat settings to the new session`,e)}finally{X.getState().setDraftSessionSettings({})}},[]),rt=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||We.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),tt(e))},at=async e=>{let t=xt(oe,e.target.value);t&&g(t.model,t.providerType,t.providerId)},ot=(e,t,n,r,i,a,o)=>{l&&(Dt(`impact`),R(null),w(e,t,n,r,i,a,o))},lt=l?.id,dt=(0,Q.useCallback)(async t=>{if(lt)try{let n=await q.forkSession(lt,{messageId:t});if(n.success&&n.data){let t=n.data;X.setState(e=>({sessions:[t,...e.sessions]})),T.success(e(`chat.fork.created`)),r(`/c/${t.id}`)}else T.error(n.error||e(`chat.fork.failed`))}catch(t){Lr.error(`Failed to fork the chat:`,t),T.error(e(`chat.fork.failed`))}},[lt,r,e]);if(!l){let t=H.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,$.jsx)(`button`,{onClick:()=>z(e=>!e),className:W(`absolute inset-e-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/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:inset-e-6 sm:top-6`,me&&`text-primary-600 dark:text-primary-400`),type:`button`,title:e(`chat.controls.title`),"aria-label":e(`chat.controls.title`),"aria-expanded":me,children:(0,$.jsx)(S,{className:`h-4 w-4`})}),(0,$.jsxs)(`button`,{onClick:()=>et(),disabled:!p&&f.length===0||!!p&&!L,className:`absolute inset-e-15 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/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:inset-e-17 sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,$.jsx)(fe,{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:be.title})]}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-[15px] leading-relaxed text-ink-subtle`,children:be.subtitle})]},be.id),oe.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[Ve&&(0,$.jsxs)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-xs backdrop-blur-xl dark:border-white/8 dark:bg-dark-200/80`,children:[(0,$.jsx)(Ir,{images:H,onImagesChange:Ce,maxImages:5}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 border-t border-black/6 pt-3 dark:border-white/[0.07]`,children:[(0,$.jsx)(`span`,{className:`text-xs text-ink-muted`,children:e(`chat.input.menu.attachDocument`)}),(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:`outline`,disabled:Ae,onClick:()=>K.current?.click(),className:`shrink-0 whitespace-nowrap`,children:[(0,$.jsx)(Se,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`ms-1.5`,children:e(Ae?`documents.uploading`:`chat.input.menu.attach`)})]}),(0,$.jsx)(`input`,{ref:K,type:`file`,accept:Yn,className:`hidden`,onChange:e=>void ze(e)})]})]}),se&&(0,$.jsx)(sr,{questions:je.decisionQuestions,onSave:e=>Me({...X.getState().draftSessionSettings,decisionQuestions:e})}),(0,$.jsx)(`form`,{onSubmit:tt,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:jt,children:[(0,$.jsx)(tr,{ref:We,message:B,onApply:e=>{V(e),Ue.current?.focus()}}),(0,$.jsx)(Nn,{ref:Ue,value:B,onChange:e=>V(e.target.value),onKeyDown:rt,placeholder:e(`chat.input.messagePlaceholder`),"aria-label":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)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>He(!Ve),className:W(`h-9 w-9 p-0! rounded-full 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`,Ve&&`bg-hover-solid text-ink`),title:e(`chat.input.attachImages`),"aria-label":e(`chat.input.attachImages`),"aria-expanded":Ve,children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Se,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -inset-e-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):Ve?(0,$.jsx)(u,{className:`h-4 w-4`}):(0,$.jsx)(xe,{className:`h-4 w-4`})}),Le&&(0,$.jsx)(Ot,{value:Ne,inheritedValue:Pe,onChange:Re}),we&&!se&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>De(e=>!e),className:W(`h-9 w-9 p-0 rounded-full 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-label":e(U?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":U,children:(0,$.jsx)(ve,{className:`h-4 w-4`})}),!se&&(0,$.jsx)(rr,{value:Oe,onChange:ke,buttonClassName:`h-9 w-9`}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(kt,{models:oe,selectedModel:ce,onModelChange:at,getModelValue:ht,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:$e})}),(0,$.jsx)(Z,{type:`submit`,variant:`primary`,size:`sm`,disabled:!B.trim()||!p||!L,className:Mt,title:e(`chat.input.sendMessage`),"aria-label":e(`chat.input.sendMessage`),children:(0,$.jsx)(ne,{className:`h-4 w-4`})})]})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(kt,{models:oe,selectedModel:ce,onModelChange:at,getModelValue:ht,className:`w-full`,compact:!0,showImageGen:$e})}),(0,$.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-ink-subtle`,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)(It,{variant:`inline`})]})]})]}),(0,$.jsx)(kr,{draftModel:p,open:me,onClose:()=>z(!1)})]})}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:F?.background?{backgroundImage:`url(${F.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[F?.background&&(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/88 backdrop-blur-sm dark:bg-dark-100/88`}),(0,$.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[l?.isPrivate&&(0,$.jsx)(`div`,{className:`shrink-0 border-b border-black/5 bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/6 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)(fe,{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-ink-subtle sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),F&&!l?.isPrivate&&(0,$.jsx)(`div`,{className:`shrink-0 border-b border-black/5 bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/6 dark:bg-dark-100/55`,children:(0,$.jsx)(Fr,{persona:F,onClear:()=>{l&&q.updateSession(l.id,{model:F.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);X.setState(t=>({sessions:t.sessions.map(t=>t.id===l.id?e.data:t),currentSession:e.data}))}).catch(t=>{Lr.error(`Failed to remove persona:`,t),T.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:()=>z(e=>!e),className:W(`absolute inset-e-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/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950`,me&&`text-primary-600 dark:text-primary-400`),type:`button`,title:e(`chat.controls.title`),"aria-label":e(`chat.controls.title`),"aria-expanded":me,children:(0,$.jsx)(S,{className:`h-3.5 w-3.5`})}),l.settings?.forkedFrom&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(`/c/${l.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/8 dark:bg-dark-200/70 dark:text-dark-600 dark:hover:text-dark-900`,"data-testid":`forked-from-banner`,children:[(0,$.jsx)(ie,{className:`h-3 w-3`}),e(`chat.fork.origin`,{title:l.settings.forkedFrom.title||e(`chat.fork.originUnknown`)})]}),(0,$.jsx)(jn,{messages:l.messages,streamingMessage:M,streamingThinking:N,streamingMessageId:ee,isStreaming:j,toolActivities:te,activeToolCalls:re,pendingToolApproval:P,onDecideToolApproval:ae,onRegenerate:O,onSelectBranch:A,onEditResend:k,onFork:dt,followUpSuggestions:ye,onFollowUpSelect:e=>ot(e),className:`flex-1`}),l?.shared?(0,$.jsx)(`div`,{className:`mx-auto mb-4 w-full max-w-3xl rounded-xl border border-black/6 bg-black/2 px-4 py-3 text-center text-[13px] text-gray-500 dark:border-white/8 dark:bg-white/3 dark:text-dark-600`,"data-testid":`chat-shared-readonly`,children:e(`chat.sharedReadOnly`,{owner:l.shared.ownerUserId})}):(0,$.jsx)(fr,{onSendMessage:ot,onStopGeneration:E,onCancelComparison:D,onOpenVoiceMode:()=>Ze(!0),disabled:!l})]}),Xe&&l&&(0,$.jsx)(Er,{onClose:()=>Ze(!1),onSendMessage:e=>ot(e),isStreaming:j,lastAssistantMessage:Qe}),(0,$.jsx)(Pr,{session:l}),(0,$.jsx)(kr,{session:l,open:me,onClose:()=>z(!1)})]})]})]})};export{Vr as ChatPage,Vr as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{Dr as r,H as i,Kt as a,Mn as o,Q as s,Zn as c,er as l,et as ee,rt as te,zn as u}from"./ui-vendor-Bac5e8jE.js";import{t as d}from"./useTranslation-D-_KTORQ.js";import"./ui-BPtWIxXL.js";import{u as f,y as p}from"./api-Bje32kcr.js";import{t as m}from"./authStore-DUmjkugT.js";import{t as h}from"./Button-BGE6ZJv5.js";import{t as g}from"./chatStore-Di86sm3T.js";import{t as _}from"./utils-DsCVr_wG.js";import{t as v}from"./logger-DAQsBb8I.js";var y=e(t(),1),b=n(),x=v(`components:connect-models`),S=[{id:`llama-cpp`,name:`llama.cpp`,baseUrl:`http://localhost:8080/v1`},{id:`vllm`,name:`vLLM`,baseUrl:`http://localhost:8000/v1`},{id:`llama-swap`,name:`llama-swap`,baseUrl:`http://localhost:8080/v1`},{id:`lm-studio`,name:`LM Studio`,baseUrl:`http://localhost:1234/v1`},{id:`mlx-lm`,name:`mlx-lm`,baseUrl:`http://localhost:8080/v1`}],C=[{id:`openai`,name:`OpenAI`},{id:`anthropic`,name:`Anthropic`},{id:`groq`,name:`Groq`},{id:`openrouter`,name:`OpenRouter`},{id:`gemini`,name:`Google Gemini`},{id:`mistral`,name:`Mistral`},{id:`deepseek`,name:`DeepSeek`},{id:`meta`,name:`Meta`},{id:`modal`,name:`Modal`},{id:`baseten`,name:`Baseten`},{id:`bedrock`,name:`Amazon Bedrock`}],w=({variant:e=`setup`,onDone:t})=>{let{t:n}=d(),{user:v,systemInfo:w}=m(),T=g(e=>e.loadModels),E=v?.role===`admin`||w?.requiresAuth===!1,[D,O]=(0,y.useState)(()=>w?.ollamaEnabled===!1?`disabled`:`checking`),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(S[0]),[N,P]=(0,y.useState)(S[0].baseUrl),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)(!1),[U,W]=(0,y.useState)(null),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=(0,y.useCallback)(async()=>{try{let e=await p.checkHealth();e.success&&e.data?.status===`disabled`?O(`disabled`):e.success&&e.data?.status===`healthy`?O(`healthy`):O(`offline`)}catch{O(`offline`)}},[]);(0,y.useEffect)(()=>{if(w?.ollamaEnabled===!1)return;let e=window.setTimeout(()=>{Y()},0);return()=>window.clearTimeout(e)},[Y,w?.ollamaEnabled]);let X=async e=>{try{(await p.updateSettings({enabled:e})).success?(r.success(n(e?`connectModels.ollama.enabledToast`:`connectModels.ollama.disabledToast`)),e?(O(`checking`),Y()):O(`disabled`)):r.error(n(`connectModels.ollama.settingsFailed`))}catch(e){x.error(`Failed to update Ollama settings:`,e),r.error(n(`connectModels.ollama.settingsFailed`))}},Z=async()=>{R(!0),B(null);try{let e=await f.probeEndpoint(N,`openai`);e.success&&e.data?.reachable?(B(e.data.models),r.success(n(`connectModels.local.reachable`,{count:e.data.models.length}))):(B([]),r.error(e.message||n(`connectModels.local.unreachable`)))}catch(e){x.error(`Endpoint probe failed:`,e),B([]),r.error(n(`connectModels.local.unreachable`))}finally{R(!1)}},ne=async()=>{H(!0);try{let e=N.replace(/\/+$/,``),i=e.endsWith(`/v1`)?e:`${e}/v1`,a=F.trim().length>0,o=`${j.id.toUpperCase().replace(/-/g,`_`)}_API_KEY`,s={id:j.id,name:j.name,type:`completion`,endpoint:`${i}/chat/completions`,api_mode:`chat_completions`,base_url:i,auth:a?{header:`Authorization`,prefix:`Bearer `,key_env:o}:{header:``,prefix:``,key_env:``},model_map:(z??[]).slice(0,50)};if(!(await f.installPlugin(s)).success&&!(await f.updatePlugin(j.id,s)).success){r.error(n(`connectModels.local.enableFailed`));return}a&&await f.setApiKey(j.id,F.trim()),await f.activatePlugin(j.id),await T({quiet:!0}),r.success(n(`connectModels.local.enabled`,{name:j.name})),t?.()}catch(e){x.error(`Failed to enable local provider:`,e),r.error(n(`connectModels.local.enableFailed`))}finally{H(!1)}},re=async()=>{if(U&&G.trim()){J(!0);try{if(!(await f.setApiKey(U.id,G.trim())).success){r.error(n(`connectModels.cloud.saveFailed`));return}await f.activatePlugin(U.id),await T({quiet:!0}),r.success(n(`connectModels.cloud.connected`,{name:U.name})),K(``),t?.()}catch(e){x.error(`Failed to connect cloud provider:`,e),r.error(n(`connectModels.cloud.saveFailed`))}finally{J(!1)}}},Q=`rounded-2xl border border-gray-200/80 bg-white/80 p-4 dark:border-white/10 dark:bg-white/4`,$=`w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800 dark:placeholder-dark-500`,ie={checking:`bg-gray-400 animate-pulse`,healthy:`bg-green-500`,offline:`bg-red-500`,disabled:`bg-gray-400`}[D];return(0,b.jsxs)(`div`,{className:_(`flex w-full flex-col gap-3`,`max-w-lg`),children:[(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(o,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:`Ollama`}),(0,b.jsx)(`span`,{className:_(`h-2 w-2 rounded-full`,ie)})]}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.status.${D}`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[D!==`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>{O(`checking`),Y()},title:n(`connectModels.ollama.recheck`),"aria-label":n(`connectModels.ollama.recheck`),children:(0,b.jsx)(s,{className:_(`h-4 w-4`,D===`checking`&&`animate-spin`)})}),E&&D===`offline`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!1),title:n(`connectModels.ollama.disable`),"aria-label":n(`connectModels.ollama.disable`),children:(0,b.jsx)(ee,{className:`h-4 w-4`})}),E&&D===`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!0),children:n(`connectModels.ollama.enable`)})]})]}),D===`offline`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.offlineHint`)}),D===`healthy`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-success-800 dark:text-success-400`,children:n(`connectModels.ollama.healthyHint`)})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`local`,onClick:()=>A(k===`local`?null:`local`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(i,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.local.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.local.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`local`&&`rotate-90 rtl:rotate-90`)})]}),k===`local`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:S.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>{M(e),P(e.baseUrl),B(null)},"aria-pressed":j.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,j.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),(0,b.jsx)(`input`,{className:$,type:`url`,"aria-label":n(`connectModels.local.urlLabel`),autoCapitalize:`none`,value:N,onChange:e=>{P(e.target.value),B(null)},placeholder:`http://localhost:8080/v1`,spellCheck:!1}),(0,b.jsx)(`input`,{className:$,value:F,onChange:e=>I(e.target.value),placeholder:n(`connectModels.local.keyPlaceholder`),"aria-label":n(`connectModels.local.keyPlaceholder`),type:`password`,autoComplete:`off`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void Z(),disabled:L||!N.trim(),children:[(0,b.jsx)(te,{className:`me-1.5 h-4 w-4`}),n(L?`connectModels.local.testing`:`connectModels.local.test`)]}),(0,b.jsxs)(h,{size:`sm`,onClick:()=>void ne(),disabled:V||!z||z.length===0,children:[(0,b.jsx)(l,{className:`me-1.5 h-4 w-4`}),n(V?`connectModels.local.enabling`:`connectModels.local.enable`)]})]}),z&&z.length>0&&(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[z.slice(0,8).map(e=>(0,b.jsx)(`span`,{className:`rounded-md bg-gray-100 px-2 py-0.5 font-mono text-[10px] text-gray-700 dark:bg-white/6 dark:text-dark-700`,children:e},e)),z.length>8&&(0,b.jsxs)(`span`,{className:`px-1 text-[10px] text-gray-400`,children:[`+`,z.length-8]})]}),z&&z.length===0&&(0,b.jsx)(`p`,{role:`alert`,className:`text-xs text-error-700 dark:text-error-400`,children:n(`connectModels.local.noModels`)})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`cloud`,onClick:()=>A(k===`cloud`?null:`cloud`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(u,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.cloud.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.cloud.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`cloud`&&`rotate-90 rtl:rotate-90`)})]}),k===`cloud`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>W(e),"aria-pressed":U?.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,U?.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),U&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(a,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,b.jsx)(`input`,{className:_($,`ps-9`),value:G,onChange:e=>K(e.target.value),placeholder:n(`connectModels.cloud.keyPlaceholder`,{name:U.name}),"aria-label":n(`connectModels.cloud.keyLabel`,{name:U.name}),type:`password`,autoComplete:`off`})]}),(0,b.jsx)(`div`,{children:(0,b.jsxs)(h,{size:`sm`,onClick:()=>void re(),disabled:q||!G.trim(),children:[(0,b.jsx)(l,{className:`me-1.5 h-4 w-4`}),n(q?`connectModels.cloud.connecting`:`connectModels.cloud.connect`)]})})]})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),e===`setup`&&(0,b.jsx)(`div`,{className:`mt-1 text-center`,children:(0,b.jsx)(`button`,{type:`button`,onClick:()=>t?.(),className:`text-sm text-gray-500 underline-offset-4 hover:underline dark:text-dark-500`,children:n(`connectModels.skip`)})})]})};export{w as t};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{Dr as r,Kt as i,Mn as a,Q as o,U as s,Zn as c,er as l,et as ee,rt as te,zn as u}from"./ui-vendor-DsURZnZt.js";import{t as d}from"./useTranslation-CKqEdZ8j.js";import"./ui-DxaHE9GD.js";import{u as f,y as p}from"./api-Dasm8tVY.js";import{t as m}from"./authStore-ac5-hjOH.js";import{t as h}from"./Button-D6d7HYoa.js";import{t as g}from"./chatStore-GhucyjJu.js";import{t as _}from"./utils-BXRzbHJC.js";import{t as v}from"./logger-DAQsBb8I.js";var y=e(t(),1),b=n(),x=v(`components:connect-models`),S=[{id:`llama-cpp`,name:`llama.cpp`,baseUrl:`http://localhost:8080/v1`},{id:`vllm`,name:`vLLM`,baseUrl:`http://localhost:8000/v1`},{id:`llama-swap`,name:`llama-swap`,baseUrl:`http://localhost:8080/v1`},{id:`lm-studio`,name:`LM Studio`,baseUrl:`http://localhost:1234/v1`},{id:`mlx-lm`,name:`mlx-lm`,baseUrl:`http://localhost:8080/v1`}],C=[{id:`openai`,name:`OpenAI`},{id:`anthropic`,name:`Anthropic`},{id:`groq`,name:`Groq`},{id:`openrouter`,name:`OpenRouter`},{id:`gemini`,name:`Google Gemini`},{id:`mistral`,name:`Mistral`},{id:`deepseek`,name:`DeepSeek`},{id:`meta`,name:`Meta`},{id:`modal`,name:`Modal`},{id:`baseten`,name:`Baseten`},{id:`bedrock`,name:`Amazon Bedrock`}],w=({variant:e=`setup`,onDone:t})=>{let{t:n}=d(),{user:v,systemInfo:w}=m(),T=g(e=>e.loadModels),E=v?.role===`admin`||w?.requiresAuth===!1,[D,O]=(0,y.useState)(()=>w?.ollamaEnabled===!1?`disabled`:`checking`),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(S[0]),[N,P]=(0,y.useState)(S[0].baseUrl),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)(!1),[U,W]=(0,y.useState)(null),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=(0,y.useCallback)(async()=>{try{let e=await p.checkHealth();e.success&&e.data?.status===`disabled`?O(`disabled`):e.success&&e.data?.status===`healthy`?O(`healthy`):O(`offline`)}catch{O(`offline`)}},[]);(0,y.useEffect)(()=>{if(w?.ollamaEnabled===!1)return;let e=window.setTimeout(()=>{Y()},0);return()=>window.clearTimeout(e)},[Y,w?.ollamaEnabled]);let X=async e=>{try{(await p.updateSettings({enabled:e})).success?(r.success(n(e?`connectModels.ollama.enabledToast`:`connectModels.ollama.disabledToast`)),e?(O(`checking`),Y()):O(`disabled`)):r.error(n(`connectModels.ollama.settingsFailed`))}catch(e){x.error(`Failed to update Ollama settings:`,e),r.error(n(`connectModels.ollama.settingsFailed`))}},Z=async()=>{R(!0),B(null);try{let e=await f.probeEndpoint(N,`openai`);e.success&&e.data?.reachable?(B(e.data.models),r.success(n(`connectModels.local.reachable`,{count:e.data.models.length}))):(B([]),r.error(e.message||n(`connectModels.local.unreachable`)))}catch(e){x.error(`Endpoint probe failed:`,e),B([]),r.error(n(`connectModels.local.unreachable`))}finally{R(!1)}},ne=async()=>{H(!0);try{let e=N.replace(/\/+$/,``),i=e.endsWith(`/v1`)?e:`${e}/v1`,a=F.trim().length>0,o=`${j.id.toUpperCase().replace(/-/g,`_`)}_API_KEY`,s={id:j.id,name:j.name,type:`completion`,endpoint:`${i}/chat/completions`,api_mode:`chat_completions`,base_url:i,auth:a?{header:`Authorization`,prefix:`Bearer `,key_env:o}:{header:``,prefix:``,key_env:``},model_map:(z??[]).slice(0,50)};if(!(await f.installPlugin(s)).success&&!(await f.updatePlugin(j.id,s)).success){r.error(n(`connectModels.local.enableFailed`));return}a&&await f.setApiKey(j.id,F.trim()),await f.activatePlugin(j.id),await T({quiet:!0}),r.success(n(`connectModels.local.enabled`,{name:j.name})),t?.()}catch(e){x.error(`Failed to enable local provider:`,e),r.error(n(`connectModels.local.enableFailed`))}finally{H(!1)}},re=async()=>{if(U&&G.trim()){J(!0);try{if(!(await f.setApiKey(U.id,G.trim())).success){r.error(n(`connectModels.cloud.saveFailed`));return}await f.activatePlugin(U.id),await T({quiet:!0}),r.success(n(`connectModels.cloud.connected`,{name:U.name})),K(``),t?.()}catch(e){x.error(`Failed to connect cloud provider:`,e),r.error(n(`connectModels.cloud.saveFailed`))}finally{J(!1)}}},Q=`rounded-2xl border border-gray-200/80 bg-white/80 p-4 dark:border-white/10 dark:bg-white/4`,$=`w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800 dark:placeholder-dark-500`,ie={checking:`bg-gray-400 animate-pulse`,healthy:`bg-green-500`,offline:`bg-red-500`,disabled:`bg-gray-400`}[D];return(0,b.jsxs)(`div`,{className:_(`flex w-full flex-col gap-3`,`max-w-lg`),children:[(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(a,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:`Ollama`}),(0,b.jsx)(`span`,{className:_(`h-2 w-2 rounded-full`,ie)})]}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.status.${D}`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[D!==`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>{O(`checking`),Y()},title:n(`connectModels.ollama.recheck`),"aria-label":n(`connectModels.ollama.recheck`),children:(0,b.jsx)(o,{className:_(`h-4 w-4`,D===`checking`&&`animate-spin`)})}),E&&D===`offline`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!1),title:n(`connectModels.ollama.disable`),"aria-label":n(`connectModels.ollama.disable`),children:(0,b.jsx)(ee,{className:`h-4 w-4`})}),E&&D===`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!0),children:n(`connectModels.ollama.enable`)})]})]}),D===`offline`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.offlineHint`)}),D===`healthy`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-success-800 dark:text-success-400`,children:n(`connectModels.ollama.healthyHint`)})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`local`,onClick:()=>A(k===`local`?null:`local`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(s,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.local.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.local.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`local`&&`rotate-90 rtl:rotate-90`)})]}),k===`local`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:S.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>{M(e),P(e.baseUrl),B(null)},"aria-pressed":j.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,j.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),(0,b.jsx)(`input`,{className:$,type:`url`,"aria-label":n(`connectModels.local.urlLabel`),autoCapitalize:`none`,value:N,onChange:e=>{P(e.target.value),B(null)},placeholder:`http://localhost:8080/v1`,spellCheck:!1}),(0,b.jsx)(`input`,{className:$,value:F,onChange:e=>I(e.target.value),placeholder:n(`connectModels.local.keyPlaceholder`),"aria-label":n(`connectModels.local.keyPlaceholder`),type:`password`,autoComplete:`off`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void Z(),disabled:L||!N.trim(),children:[(0,b.jsx)(te,{className:`me-1.5 h-4 w-4`}),n(L?`connectModels.local.testing`:`connectModels.local.test`)]}),(0,b.jsxs)(h,{size:`sm`,onClick:()=>void ne(),disabled:V||!z||z.length===0,children:[(0,b.jsx)(l,{className:`me-1.5 h-4 w-4`}),n(V?`connectModels.local.enabling`:`connectModels.local.enable`)]})]}),z&&z.length>0&&(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[z.slice(0,8).map(e=>(0,b.jsx)(`span`,{className:`rounded-md bg-gray-100 px-2 py-0.5 font-mono text-[10px] text-gray-700 dark:bg-white/6 dark:text-dark-700`,children:e},e)),z.length>8&&(0,b.jsxs)(`span`,{className:`px-1 text-[10px] text-gray-400`,children:[`+`,z.length-8]})]}),z&&z.length===0&&(0,b.jsx)(`p`,{role:`alert`,className:`text-xs text-error-700 dark:text-error-400`,children:n(`connectModels.local.noModels`)})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`cloud`,onClick:()=>A(k===`cloud`?null:`cloud`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(u,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.cloud.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.cloud.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`cloud`&&`rotate-90 rtl:rotate-90`)})]}),k===`cloud`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>W(e),"aria-pressed":U?.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,U?.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),U&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(i,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,b.jsx)(`input`,{className:_($,`ps-9`),value:G,onChange:e=>K(e.target.value),placeholder:n(`connectModels.cloud.keyPlaceholder`,{name:U.name}),"aria-label":n(`connectModels.cloud.keyLabel`,{name:U.name}),type:`password`,autoComplete:`off`})]}),(0,b.jsx)(`div`,{children:(0,b.jsxs)(h,{size:`sm`,onClick:()=>void re(),disabled:q||!G.trim(),children:[(0,b.jsx)(l,{className:`me-1.5 h-4 w-4`}),n(q?`connectModels.cloud.connecting`:`connectModels.cloud.connect`)]})})]})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),e===`setup`&&(0,b.jsx)(`div`,{className:`mt-1 text-center`,children:(0,b.jsx)(`button`,{type:`button`,onClick:()=>t?.(),className:`text-sm text-gray-500 underline-offset-4 hover:underline dark:text-dark-500`,children:n(`connectModels.skip`)})})]})};export{w as t};