libre-webui 0.36.0 → 0.37.1

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 (379) hide show
  1. package/README.md +59 -0
  2. package/backend/dist/cordis/contracts.d.ts +270 -0
  3. package/backend/dist/cordis/contracts.d.ts.map +1 -0
  4. package/backend/dist/cordis/contracts.js +32 -0
  5. package/backend/dist/cordis/contracts.js.map +1 -0
  6. package/backend/dist/cordis/dsh/chat-model.d.ts +16 -0
  7. package/backend/dist/cordis/dsh/chat-model.d.ts.map +1 -0
  8. package/backend/dist/cordis/dsh/chat-model.js +104 -0
  9. package/backend/dist/cordis/dsh/chat-model.js.map +1 -0
  10. package/backend/dist/cordis/dsh/engine-plugin.d.ts +186 -0
  11. package/backend/dist/cordis/dsh/engine-plugin.d.ts.map +1 -0
  12. package/backend/dist/cordis/dsh/engine-plugin.js +1116 -0
  13. package/backend/dist/cordis/dsh/engine-plugin.js.map +1 -0
  14. package/backend/dist/cordis/dsh/librewebui-llm-adapter.d.ts +175 -0
  15. package/backend/dist/cordis/dsh/librewebui-llm-adapter.d.ts.map +1 -0
  16. package/backend/dist/cordis/dsh/librewebui-llm-adapter.js +480 -0
  17. package/backend/dist/cordis/dsh/librewebui-llm-adapter.js.map +1 -0
  18. package/backend/dist/cordis/dsh/model-identity.d.ts +12 -0
  19. package/backend/dist/cordis/dsh/model-identity.d.ts.map +1 -0
  20. package/backend/dist/cordis/dsh/model-identity.js +87 -0
  21. package/backend/dist/cordis/dsh/model-identity.js.map +1 -0
  22. package/backend/dist/cordis/dsh/native-provider-client.d.ts +44 -0
  23. package/backend/dist/cordis/dsh/native-provider-client.d.ts.map +1 -0
  24. package/backend/dist/cordis/dsh/native-provider-client.js +524 -0
  25. package/backend/dist/cordis/dsh/native-provider-client.js.map +1 -0
  26. package/backend/dist/cordis/dsh/native-provider-plugin.d.ts +11 -0
  27. package/backend/dist/cordis/dsh/native-provider-plugin.d.ts.map +1 -0
  28. package/backend/dist/cordis/dsh/native-provider-plugin.js +416 -0
  29. package/backend/dist/cordis/dsh/native-provider-plugin.js.map +1 -0
  30. package/backend/dist/cordis/dsh/native-provider-protocol.d.ts +37 -0
  31. package/backend/dist/cordis/dsh/native-provider-protocol.d.ts.map +1 -0
  32. package/backend/dist/cordis/dsh/native-provider-protocol.js +325 -0
  33. package/backend/dist/cordis/dsh/native-provider-protocol.js.map +1 -0
  34. package/backend/dist/cordis/dsh/provider-handler.d.ts +36 -0
  35. package/backend/dist/cordis/dsh/provider-handler.d.ts.map +1 -0
  36. package/backend/dist/cordis/dsh/provider-handler.js +582 -0
  37. package/backend/dist/cordis/dsh/provider-handler.js.map +1 -0
  38. package/backend/dist/cordis/dsh/session-files.d.ts +9 -0
  39. package/backend/dist/cordis/dsh/session-files.d.ts.map +1 -0
  40. package/backend/dist/cordis/dsh/session-files.js +60 -0
  41. package/backend/dist/cordis/dsh/session-files.js.map +1 -0
  42. package/backend/dist/cordis/dsh/session-settings.d.ts +15 -0
  43. package/backend/dist/cordis/dsh/session-settings.d.ts.map +1 -0
  44. package/backend/dist/cordis/dsh/session-settings.js +51 -0
  45. package/backend/dist/cordis/dsh/session-settings.js.map +1 -0
  46. package/backend/dist/cordis/dsh/work-driver.d.ts +12 -0
  47. package/backend/dist/cordis/dsh/work-driver.d.ts.map +1 -0
  48. package/backend/dist/cordis/dsh/work-driver.js +402 -0
  49. package/backend/dist/cordis/dsh/work-driver.js.map +1 -0
  50. package/backend/dist/cordis/dsh/workspace-policy.d.ts +10 -0
  51. package/backend/dist/cordis/dsh/workspace-policy.d.ts.map +1 -0
  52. package/backend/dist/cordis/dsh/workspace-policy.js +44 -0
  53. package/backend/dist/cordis/dsh/workspace-policy.js.map +1 -0
  54. package/backend/dist/cordis/host/composition.d.ts +73 -0
  55. package/backend/dist/cordis/host/composition.d.ts.map +1 -0
  56. package/backend/dist/cordis/host/composition.js +205 -0
  57. package/backend/dist/cordis/host/composition.js.map +1 -0
  58. package/backend/dist/cordis/host/config.d.ts +159 -0
  59. package/backend/dist/cordis/host/config.d.ts.map +1 -0
  60. package/backend/dist/cordis/host/config.js +184 -0
  61. package/backend/dist/cordis/host/config.js.map +1 -0
  62. package/backend/dist/cordis/host/host.d.ts +74 -0
  63. package/backend/dist/cordis/host/host.d.ts.map +1 -0
  64. package/backend/dist/cordis/host/host.js +420 -0
  65. package/backend/dist/cordis/host/host.js.map +1 -0
  66. package/backend/dist/cordis/host/loader-entry.d.ts +41 -0
  67. package/backend/dist/cordis/host/loader-entry.d.ts.map +1 -0
  68. package/backend/dist/cordis/host/loader-entry.js +52 -0
  69. package/backend/dist/cordis/host/loader-entry.js.map +1 -0
  70. package/backend/dist/cordis/host/model.d.ts +45 -0
  71. package/backend/dist/cordis/host/model.d.ts.map +1 -0
  72. package/backend/dist/cordis/host/model.js +54 -0
  73. package/backend/dist/cordis/host/model.js.map +1 -0
  74. package/backend/dist/cordis/host/privacy.d.ts +8 -0
  75. package/backend/dist/cordis/host/privacy.d.ts.map +1 -0
  76. package/backend/dist/cordis/host/privacy.js +73 -0
  77. package/backend/dist/cordis/host/privacy.js.map +1 -0
  78. package/backend/dist/cordis/index.d.ts +14 -0
  79. package/backend/dist/cordis/index.d.ts.map +1 -0
  80. package/backend/dist/cordis/index.js +30 -0
  81. package/backend/dist/cordis/index.js.map +1 -0
  82. package/backend/dist/cordis/runtime.d.ts +97 -0
  83. package/backend/dist/cordis/runtime.d.ts.map +1 -0
  84. package/backend/dist/cordis/runtime.js +231 -0
  85. package/backend/dist/cordis/runtime.js.map +1 -0
  86. package/backend/dist/cordis/work-model.d.ts +7 -0
  87. package/backend/dist/cordis/work-model.d.ts.map +1 -0
  88. package/backend/dist/cordis/work-model.js +30 -0
  89. package/backend/dist/cordis/work-model.js.map +1 -0
  90. package/backend/dist/db.js +1 -1
  91. package/backend/dist/index.d.ts.map +1 -1
  92. package/backend/dist/index.js +9 -0
  93. package/backend/dist/index.js.map +1 -1
  94. package/backend/dist/main.js +12 -0
  95. package/backend/dist/main.js.map +1 -1
  96. package/backend/dist/persistence/extensionTypes.d.ts +2 -0
  97. package/backend/dist/persistence/extensionTypes.d.ts.map +1 -1
  98. package/backend/dist/persistence/extensionTypes.js.map +1 -1
  99. package/backend/dist/persistence/postgresExtensionRepositories.d.ts.map +1 -1
  100. package/backend/dist/persistence/postgresExtensionRepositories.js +38 -0
  101. package/backend/dist/persistence/postgresExtensionRepositories.js.map +1 -1
  102. package/backend/dist/persistence/postgresResourceRepositories.d.ts.map +1 -1
  103. package/backend/dist/persistence/postgresResourceRepositories.js +6 -1
  104. package/backend/dist/persistence/postgresResourceRepositories.js.map +1 -1
  105. package/backend/dist/persistence/resourceTypes.d.ts +3 -1
  106. package/backend/dist/persistence/resourceTypes.d.ts.map +1 -1
  107. package/backend/dist/persistence/resourceTypes.js.map +1 -1
  108. package/backend/dist/persistence/sqliteExtensionRepositories.d.ts.map +1 -1
  109. package/backend/dist/persistence/sqliteExtensionRepositories.js +40 -0
  110. package/backend/dist/persistence/sqliteExtensionRepositories.js.map +1 -1
  111. package/backend/dist/persistence/sqliteResourceRepositories.d.ts.map +1 -1
  112. package/backend/dist/persistence/sqliteResourceRepositories.js +7 -1
  113. package/backend/dist/persistence/sqliteResourceRepositories.js.map +1 -1
  114. package/backend/dist/routes/agentCli.d.ts.map +1 -1
  115. package/backend/dist/routes/agentCli.js +34 -2
  116. package/backend/dist/routes/agentCli.js.map +1 -1
  117. package/backend/dist/routes/chat.d.ts.map +1 -1
  118. package/backend/dist/routes/chat.js +9 -1
  119. package/backend/dist/routes/chat.js.map +1 -1
  120. package/backend/dist/routes/cordis.d.ts +3 -0
  121. package/backend/dist/routes/cordis.d.ts.map +1 -0
  122. package/backend/dist/routes/cordis.js +440 -0
  123. package/backend/dist/routes/cordis.js.map +1 -0
  124. package/backend/dist/routes/libreClaw.js +1 -1
  125. package/backend/dist/routes/libreClaw.js.map +1 -1
  126. package/backend/dist/routes/work.d.ts.map +1 -1
  127. package/backend/dist/routes/work.js +23 -8
  128. package/backend/dist/routes/work.js.map +1 -1
  129. package/backend/dist/services/agentAccessService.d.ts +4 -0
  130. package/backend/dist/services/agentAccessService.d.ts.map +1 -1
  131. package/backend/dist/services/agentAccessService.js +48 -16
  132. package/backend/dist/services/agentAccessService.js.map +1 -1
  133. package/backend/dist/services/agentCliService.d.ts +42 -1
  134. package/backend/dist/services/agentCliService.d.ts.map +1 -1
  135. package/backend/dist/services/agentCliService.js +206 -7
  136. package/backend/dist/services/agentCliService.js.map +1 -1
  137. package/backend/dist/services/agentCliUsage.d.ts +22 -0
  138. package/backend/dist/services/agentCliUsage.d.ts.map +1 -0
  139. package/backend/dist/services/agentCliUsage.js +192 -0
  140. package/backend/dist/services/agentCliUsage.js.map +1 -0
  141. package/backend/dist/services/authService.d.ts +3 -0
  142. package/backend/dist/services/authService.d.ts.map +1 -1
  143. package/backend/dist/services/authService.js +4 -1
  144. package/backend/dist/services/authService.js.map +1 -1
  145. package/backend/dist/services/chatGenerationService.d.ts +7 -0
  146. package/backend/dist/services/chatGenerationService.d.ts.map +1 -1
  147. package/backend/dist/services/chatGenerationService.js +32 -1
  148. package/backend/dist/services/chatGenerationService.js.map +1 -1
  149. package/backend/dist/services/cordisAccessService.d.ts +56 -0
  150. package/backend/dist/services/cordisAccessService.d.ts.map +1 -0
  151. package/backend/dist/services/cordisAccessService.js +98 -0
  152. package/backend/dist/services/cordisAccessService.js.map +1 -0
  153. package/backend/dist/services/durableChatGenerationService.d.ts.map +1 -1
  154. package/backend/dist/services/durableChatGenerationService.js +9 -1
  155. package/backend/dist/services/durableChatGenerationService.js.map +1 -1
  156. package/backend/dist/services/emailService.d.ts.map +1 -1
  157. package/backend/dist/services/emailService.js +8 -1
  158. package/backend/dist/services/emailService.js.map +1 -1
  159. package/backend/dist/services/pluginService.d.ts.map +1 -1
  160. package/backend/dist/services/pluginService.js +7 -26
  161. package/backend/dist/services/pluginService.js.map +1 -1
  162. package/backend/dist/services/pluginUsageService.d.ts +52 -0
  163. package/backend/dist/services/pluginUsageService.d.ts.map +1 -1
  164. package/backend/dist/services/pluginUsageService.js +89 -1
  165. package/backend/dist/services/pluginUsageService.js.map +1 -1
  166. package/backend/dist/services/systemSettingsService.d.ts +1 -1
  167. package/backend/dist/services/systemSettingsService.d.ts.map +1 -1
  168. package/backend/dist/services/systemSettingsService.js +1 -1
  169. package/backend/dist/services/systemSettingsService.js.map +1 -1
  170. package/backend/dist/services/thinkingSummaryService.d.ts +3 -0
  171. package/backend/dist/services/thinkingSummaryService.d.ts.map +1 -1
  172. package/backend/dist/services/thinkingSummaryService.js +56 -17
  173. package/backend/dist/services/thinkingSummaryService.js.map +1 -1
  174. package/backend/dist/services/titleGenerationService.d.ts +22 -2
  175. package/backend/dist/services/titleGenerationService.d.ts.map +1 -1
  176. package/backend/dist/services/titleGenerationService.js +63 -8
  177. package/backend/dist/services/titleGenerationService.js.map +1 -1
  178. package/backend/dist/services/workAgentService.d.ts +1 -1
  179. package/backend/dist/services/workAgentService.d.ts.map +1 -1
  180. package/backend/dist/services/workAgentService.js +76 -12
  181. package/backend/dist/services/workAgentService.js.map +1 -1
  182. package/backend/dist/services/workModelProviderService.d.ts +5 -0
  183. package/backend/dist/services/workModelProviderService.d.ts.map +1 -1
  184. package/backend/dist/services/workModelProviderService.js +52 -3
  185. package/backend/dist/services/workModelProviderService.js.map +1 -1
  186. package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
  187. package/backend/dist/services/workRuntimeService.js +4 -1
  188. package/backend/dist/services/workRuntimeService.js.map +1 -1
  189. package/backend/dist/services/workTaskService.d.ts.map +1 -1
  190. package/backend/dist/services/workTaskService.js +6 -6
  191. package/backend/dist/services/workTaskService.js.map +1 -1
  192. package/backend/dist/types/work.d.ts +12 -1
  193. package/backend/dist/types/work.d.ts.map +1 -1
  194. package/backend/dist/utils/pluginStreamAdapter.d.ts.map +1 -1
  195. package/backend/dist/utils/pluginStreamAdapter.js +18 -4
  196. package/backend/dist/utils/pluginStreamAdapter.js.map +1 -1
  197. package/backend/dist/utils/pluginStreaming.d.ts +6 -0
  198. package/backend/dist/utils/pluginStreaming.d.ts.map +1 -1
  199. package/backend/dist/utils/pluginStreaming.js +10 -0
  200. package/backend/dist/utils/pluginStreaming.js.map +1 -1
  201. package/backend/dist/utils/smtpClient.d.ts +5 -1
  202. package/backend/dist/utils/smtpClient.d.ts.map +1 -1
  203. package/backend/dist/utils/smtpClient.js +29 -3
  204. package/backend/dist/utils/smtpClient.js.map +1 -1
  205. package/backend/dist/websocketServer.d.ts.map +1 -1
  206. package/backend/dist/websocketServer.js +4 -0
  207. package/backend/dist/websocketServer.js.map +1 -1
  208. package/backend/package.json +37 -2
  209. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  210. package/frontend/dist/artifact-runtime/framer-motion.js +3 -3
  211. package/frontend/dist/artifact-runtime/lucide-react.js +1 -1
  212. package/frontend/dist/artifact-runtime/react.js +5 -5
  213. package/frontend/dist/artifact-runtime/recharts.js +45 -45
  214. package/frontend/dist/assets/index-BrDSO609.js +20 -0
  215. package/frontend/dist/assets/index-C8_AByBq.css +1 -0
  216. package/frontend/dist/index.html +33 -31
  217. package/frontend/dist/js/{ArtifactContainer-B8tyPtWd.js → ArtifactContainer-B1-GVzVf.js} +1 -1
  218. package/frontend/dist/js/{ArtifactDemoPage-BwRfWoSK.js → ArtifactDemoPage-goftRHdk.js} +1 -1
  219. package/frontend/dist/js/{ArtifactSandboxFrame-Ctcwt_l2.js → ArtifactSandboxFrame-_8RA8_JV.js} +1 -1
  220. package/frontend/dist/js/ArtifactSlideOutPanel-DlkOZI5N.js +1 -0
  221. package/frontend/dist/js/{AutomationModal-mTYs9LrJ.js → AutomationModal-BaaxZF1M.js} +1 -1
  222. package/frontend/dist/js/AutomationsPage-DY2x7zVm.js +1 -0
  223. package/frontend/dist/js/{AvatarUpload-wWUAi3e2.js → AvatarUpload-CH_n1Ef0.js} +1 -1
  224. package/frontend/dist/js/{Button-ZQ6BePid.js → Button-CGMYia4g.js} +1 -1
  225. package/frontend/dist/js/{CalendarPage-Ch4racU2.js → CalendarPage-DLo5nm3Q.js} +1 -1
  226. package/frontend/dist/js/ChannelsPage-DnQI7mzq.js +1 -0
  227. package/frontend/dist/js/ChatPage-BaDkJnEC.js +14 -0
  228. package/frontend/dist/js/ConnectModels-B4dGb5yc.js +1 -0
  229. package/frontend/dist/js/CordisPage-CPiYn2Bx.js +1 -0
  230. package/frontend/dist/js/{EvaluationsPage-DHPnNBkW.js → EvaluationsPage-DpdGpd7x.js} +2 -2
  231. package/frontend/dist/js/{FirstTimeSetup-CoF83yY8.js → FirstTimeSetup-By8OE1JS.js} +1 -1
  232. package/frontend/dist/js/GalleryPage-ByZyIhZQ.js +1 -0
  233. package/frontend/dist/js/HomePage-Btc-Mvin.js +1 -0
  234. package/frontend/dist/js/{LanguageSwitcher-CogfczNm.js → LanguageSwitcher-B3CxRW6J.js} +1 -1
  235. package/frontend/dist/js/LibreClawPage-3Sonm1gu.js +1 -0
  236. package/frontend/dist/js/{Logo-C9fsEUaY.js → Logo-HZvdAk2c.js} +1 -1
  237. package/frontend/dist/js/{LogoMark-Cvu5CQOW.js → LogoMark-GJnfMXsk.js} +1 -1
  238. package/frontend/dist/js/{ModelManagerModals-Bc2Woor7.js → ModelManagerModals-Bk6OQzJI.js} +1 -1
  239. package/frontend/dist/js/NotesPage-lFhfjMqJ.js +3 -0
  240. package/frontend/dist/js/{OptimizedSyntaxHighlighter-aKWyHj_c.js → OptimizedSyntaxHighlighter-CzzV6ONG.js} +1 -1
  241. package/frontend/dist/js/OptimizedSyntaxHighlighter-ajqwyBQm.js +1 -0
  242. package/frontend/dist/js/{PasswordStrengthMeter-BJr4eBbo.js → PasswordStrengthMeter-DasfJa4P.js} +1 -1
  243. package/frontend/dist/js/{PersonasPage-ff5opf9B.js → PersonasPage-nOThOpXp.js} +2 -2
  244. package/frontend/dist/js/PluginUsagePage-BRbHeRf7.js +1 -0
  245. package/frontend/dist/js/{RichMessageContent-BNNylVAb.js → RichMessageContent-BZ7KKJKK.js} +2 -2
  246. package/frontend/dist/js/RichMessageContent-oyydJjgc.js +1 -0
  247. package/frontend/dist/js/SettingsModal-VpsAx2Ns.js +19 -0
  248. package/frontend/dist/js/{SettingsToggle-CKLHOUt-.js → SettingsToggle-oxvw7ulA.js} +1 -1
  249. package/frontend/dist/js/{ShareDialog-DykD70uB.js → ShareDialog-CnxPGPb_.js} +1 -1
  250. package/frontend/dist/js/SystemPage-D2ikvhDp.js +1 -0
  251. package/frontend/dist/js/{TurnstileWidget-BO2ceTt8.js → TurnstileWidget-CVepEMEQ.js} +1 -1
  252. package/frontend/dist/js/{UserManagementPage-Ch-PvYQ9.js → UserManagementPage-2yHv89ZA.js} +1 -1
  253. package/frontend/dist/js/UserManagementPanel-vxpiyiTZ.js +1 -0
  254. package/frontend/dist/js/{WhatsNewModal-Bu4H4MEb.js → WhatsNewModal-DAAFzY0d.js} +1 -1
  255. package/frontend/dist/js/WorkPage-BYpYD9mr.js +8 -0
  256. package/frontend/dist/js/api-C0ligMmL.js +1 -0
  257. package/frontend/dist/js/api-CVUaOaq4.js +14 -0
  258. package/frontend/dist/js/{appNavigation-CVsQuDI1.js → appNavigation-CqtrZ9bm.js} +1 -1
  259. package/frontend/dist/js/{appStore-Din-tTD9.js → appStore-Biw63DtJ.js} +2 -2
  260. package/frontend/dist/js/appVersion-D78eXAb-.js +1 -0
  261. package/frontend/dist/js/ar-Cq-DrSYL.js +2 -0
  262. package/frontend/dist/js/authStore-2DsDTcIu.js +1 -0
  263. package/frontend/dist/js/{authStore-Cm8P6rYs.js → authStore-C5qKrmn4.js} +3 -3
  264. package/frontend/dist/js/bn-BqxLh-KL.js +2 -0
  265. package/frontend/dist/js/chatStore-DQhEqb9F.js +3 -0
  266. package/frontend/dist/js/client-gf5bjBrn.js +2 -0
  267. package/frontend/dist/js/composerStyles-C83jssgZ.js +1 -0
  268. package/frontend/dist/js/{config-DHea4b8N.js → config-CNvgxwAm.js} +1 -1
  269. package/frontend/dist/js/cordisApi-BYjA4EOQ.js +2 -0
  270. package/frontend/dist/js/cs-D2DDNZf-.js +2 -0
  271. package/frontend/dist/js/da-BciY-TSG.js +2 -0
  272. package/frontend/dist/js/de-DjU_eXQ-.js +2 -0
  273. package/frontend/dist/js/es-ChIEs80I.js +2 -0
  274. package/frontend/dist/js/{estree-DCT3Jm65.js → estree-DGmLqopC.js} +17 -17
  275. package/frontend/dist/js/evaluationsApi-Bg12ekHo.js +1 -0
  276. package/frontend/dist/js/fr-Bi8BGRW4.js +2 -0
  277. package/frontend/dist/js/hi-BMsCnWg7.js +2 -0
  278. package/frontend/dist/js/{html-CBXMuS97.js → html-BryNQ_yx.js} +6 -6
  279. package/frontend/dist/js/id-CpcN1vhk.js +2 -0
  280. package/frontend/dist/js/is-DkUy2cmP.js +2 -0
  281. package/frontend/dist/js/it-BglK9DRZ.js +2 -0
  282. package/frontend/dist/js/ja-IrprzwLJ.js +2 -0
  283. package/frontend/dist/js/ko--wwEsMPi.js +2 -0
  284. package/frontend/dist/js/{markdown-Bo71X2X2.js → markdown-CZ1tYEW8.js} +17 -17
  285. package/frontend/dist/js/{markdown-core-BFkBYv2v.js → markdown-core-KjS96SYW.js} +1 -1
  286. package/frontend/dist/js/{markdown-html-CwjnwJbl.js → markdown-html-DQEwrWcf.js} +1 -1
  287. package/frontend/dist/js/{markdown-math-CJvHdD1l.js → markdown-math-CKi32S5d.js} +1 -1
  288. package/frontend/dist/js/{markdownHtml-egpK3_YY.js → markdownHtml-lrXhxBhK.js} +1 -1
  289. package/frontend/dist/js/markdownMath-B0BpyFBS.js +1 -0
  290. package/frontend/dist/js/{messageCodeStyles-euWoxwoo.js → messageCodeStyles-DJZ4QMVq.js} +2 -2
  291. package/frontend/dist/js/ms-BWj59y7-.js +2 -0
  292. package/frontend/dist/js/nl-D-QndW_A.js +2 -0
  293. package/frontend/dist/js/pl-Dw7d7iDV.js +2 -0
  294. package/frontend/dist/js/pt-BI53uHJw.js +2 -0
  295. package/frontend/dist/js/react-vendor-wiHys0m2.js +9 -0
  296. package/frontend/dist/js/router-vendor-HZm4FR0A.js +1 -0
  297. package/frontend/dist/js/ru-JKyTgPg9.js +2 -0
  298. package/frontend/dist/js/{standalone-6z5x8CWe.js → standalone-DbyFjvTU.js} +1 -1
  299. package/frontend/dist/js/sv-BIkBLPSQ.js +2 -0
  300. package/frontend/dist/js/{syntax-highlight-7t8DGG2n.js → syntax-highlight-DNc3FFCa.js} +1 -1
  301. package/frontend/dist/js/{teamEventStream-DGgjrVqw.js → teamEventStream-PXiwR5Kr.js} +1 -1
  302. package/frontend/dist/js/th-CZ_LcCU0.js +2 -0
  303. package/frontend/dist/js/tr-B265byx1.js +2 -0
  304. package/frontend/dist/js/{typescript-CslHIgIJ.js → typescript-DUM5niRM.js} +1 -1
  305. package/frontend/dist/js/{ui-CNcEDQ95.js → ui-DDMjO5dd.js} +2 -2
  306. package/frontend/dist/js/ui-vendor-BhHHyHk3.js +1 -0
  307. package/frontend/dist/js/uk-VTAlChwf.js +2 -0
  308. package/frontend/dist/js/{useChat-YRODF1y1.js → useChat-DaIZ2Dbu.js} +1 -1
  309. package/frontend/dist/js/{useDialogFocus-BQLdAGYH.js → useDialogFocus-BPTG_Zmy.js} +1 -1
  310. package/frontend/dist/js/useDictation-BXyX1U8r.js +1 -0
  311. package/frontend/dist/js/useQuery-hWmQjdLu.js +1 -0
  312. package/frontend/dist/js/{useTranslation-Kn7_iLGj.js → useTranslation-B9kflK9S.js} +1 -1
  313. package/frontend/dist/js/{utils-Dq1w7K0c.js → utils-p8Gt72YP.js} +1 -1
  314. package/frontend/dist/js/{utils-vendor-dx9vGAt3.js → utils-vendor-DISWt2y9.js} +1 -1
  315. package/frontend/dist/js/vi-D8rXh-53.js +2 -0
  316. package/frontend/dist/js/{workStatus-oU04ZrUq.js → work-DmJpVPPO.js} +1 -1
  317. package/frontend/dist/js/workApi-BIS9RxRi.js +1 -0
  318. package/frontend/dist/js/workApi-C3Td_lFD.js +5 -0
  319. package/frontend/dist/js/workModels-MzU2Ab7l.js +1 -0
  320. package/frontend/dist/js/zh-BEGd9iBD.js +2 -0
  321. package/package.json +43 -8
  322. package/scripts/prepare-dsh-provider.mjs +124 -0
  323. package/frontend/dist/assets/index-BXTzjRcS.js +0 -92
  324. package/frontend/dist/assets/index-uzzNXp5R.css +0 -1
  325. package/frontend/dist/js/ArtifactSlideOutPanel-DPWGjHhp.js +0 -1
  326. package/frontend/dist/js/AutomationsPage-DvsLZWtg.js +0 -1
  327. package/frontend/dist/js/ChannelsPage-D252gXwf.js +0 -1
  328. package/frontend/dist/js/ChatPage-D_CzOiHw.js +0 -14
  329. package/frontend/dist/js/ConnectModels-DYOtIOEY.js +0 -1
  330. package/frontend/dist/js/GalleryPage-BpK-vrvd.js +0 -1
  331. package/frontend/dist/js/HomePage-zJkkDNJl.js +0 -1
  332. package/frontend/dist/js/LibreClawPage-CAgNj9GM.js +0 -1
  333. package/frontend/dist/js/NotesPage-CNTqlwNc.js +0 -3
  334. package/frontend/dist/js/OptimizedSyntaxHighlighter-BFjOBavF.js +0 -1
  335. package/frontend/dist/js/PluginUsagePage-Cp4j4-VZ.js +0 -1
  336. package/frontend/dist/js/RichMessageContent-BOY5jqj-.js +0 -1
  337. package/frontend/dist/js/SettingsModal-WAdVG4-g.js +0 -19
  338. package/frontend/dist/js/SystemPage-Dwi8leEQ.js +0 -1
  339. package/frontend/dist/js/UserManagementPanel-CfG67c_k.js +0 -1
  340. package/frontend/dist/js/WorkPage-D_cL9wp4.js +0 -8
  341. package/frontend/dist/js/api-29NO19CP.js +0 -14
  342. package/frontend/dist/js/api-DhafOTdF.js +0 -1
  343. package/frontend/dist/js/appVersion-BNuquyI6.js +0 -1
  344. package/frontend/dist/js/ar-WHne6B0o.js +0 -2
  345. package/frontend/dist/js/authStore-snvjjOuX.js +0 -1
  346. package/frontend/dist/js/bn-BZvCjqwO.js +0 -2
  347. package/frontend/dist/js/chatStore-BPpcL4I5.js +0 -3
  348. package/frontend/dist/js/composerStyles-bNlrIugf.js +0 -1
  349. package/frontend/dist/js/cs-DfSqWQ9V.js +0 -2
  350. package/frontend/dist/js/da-BmMLW4Dl.js +0 -2
  351. package/frontend/dist/js/de-BQMiQwQT.js +0 -2
  352. package/frontend/dist/js/es-DXf6jt4Z.js +0 -2
  353. package/frontend/dist/js/evaluationsApi-Btc9Mg9z.js +0 -1
  354. package/frontend/dist/js/fr-BD6nT1oc.js +0 -2
  355. package/frontend/dist/js/hi-BSuNic-8.js +0 -2
  356. package/frontend/dist/js/id-wodbwt3B.js +0 -2
  357. package/frontend/dist/js/is-CEjw-OJE.js +0 -2
  358. package/frontend/dist/js/it-X_pq8C7q.js +0 -2
  359. package/frontend/dist/js/ja-DWM2HZZd.js +0 -2
  360. package/frontend/dist/js/ko-DFi2khBB.js +0 -2
  361. package/frontend/dist/js/markdownMath-mesq3ZcY.js +0 -1
  362. package/frontend/dist/js/ms-DNQateTR.js +0 -2
  363. package/frontend/dist/js/nl-DSWhi8W8.js +0 -2
  364. package/frontend/dist/js/pl-W9WEDpZ3.js +0 -2
  365. package/frontend/dist/js/pt-DCCGvdNt.js +0 -2
  366. package/frontend/dist/js/react-vendor-D0Ec-185.js +0 -9
  367. package/frontend/dist/js/router-vendor-CM0PhOMl.js +0 -1
  368. package/frontend/dist/js/ru-D-Ww6dXe.js +0 -2
  369. package/frontend/dist/js/sv-B0Iry-H3.js +0 -2
  370. package/frontend/dist/js/th-CEZS0WeE.js +0 -2
  371. package/frontend/dist/js/tr-BFJ8TeYb.js +0 -2
  372. package/frontend/dist/js/ui-vendor-LatG6rFF.js +0 -177
  373. package/frontend/dist/js/uk-BmW3yDel.js +0 -2
  374. package/frontend/dist/js/useQuery-C3O4CZ54.js +0 -1
  375. package/frontend/dist/js/vi-Cu25FXnp.js +0 -2
  376. package/frontend/dist/js/work-DVgm81bJ.js +0 -1
  377. package/frontend/dist/js/workApi-BdUNugC3.js +0 -1
  378. package/frontend/dist/js/workApi-OieM8qEL.js +0 -6
  379. package/frontend/dist/js/zh-CuCAx3oH.js +0 -2
@@ -0,0 +1,14 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-wiHys0m2.js";import{d as i,f as a,u as o}from"./router-vendor-HZm4FR0A.js";import{a as s,t as c}from"./logger-BR4forr_.js";import{t as l}from"./useTranslation-B9kflK9S.js";import{a as u,i as d,n as f,s as p,t as m}from"./utils-p8Gt72YP.js";import{T as h,_ as g,a as _,d as v,f as y,g as b,h as x,i as S,l as C,n as w,o as T,p as E,r as D,t as O,u as k}from"./chatStore-DQhEqb9F.js";import{Cr as A,Ct as j,Et as M,F as N,Fn as ee,G as te,Gt as ne,H as re,In as P,Jn as F,Kt as ie,L as I,Lt as ae,M as L,O as oe,P as se,Pn as ce,Qn as R,S as z,St as le,V as ue,Y as de,Yn as fe,Z as pe,Zn as me,_n as he,a as ge,ar as _e,b as ve,c as ye,dr as be,et as xe,g as B,gn as V,hr as Se,jn as Ce,kn as we,lt as Te,m as Ee,mr as De,n as H,o as U,on as W,or as Oe,ot as ke,p as Ae,q as G,r as K,rn as je,sn as q,st as Me,t as Ne,tn as Pe,ur as Fe,vr as Ie,wr as J,wt as Le,y as Re,zn as ze}from"./ui-vendor-BhHHyHk3.js";import{M as Be,P as Y,S as Ve,T as He,_ as X,a as Ue,d as We,f as Ge,g as Ke,i as qe,m as Je,n as Ye,p as Xe,t as Ze,y as Qe}from"./api-CVUaOaq4.js";import{t as $e}from"./authStore-C5qKrmn4.js";import{t as et}from"./appStore-Biw63DtJ.js";import{i as tt,r as nt,t as rt}from"./welcomePrompts-to5mv_gx.js";import{l as it}from"./messageCodeStyles-DJZ4QMVq.js";import{t as Z}from"./Button-CGMYia4g.js";import{d as at,f as ot,l as st,p as ct}from"./ui-DDMjO5dd.js";import{t as lt}from"./LogoMark-GJnfMXsk.js";import{a as ut,i as dt,n as ft,o as pt,r as mt}from"./useChat-DaIZ2Dbu.js";import{a as ht,i as gt,o as _t,r as vt,s as yt,t as bt}from"./ttsBatching-kFVEE3Ip.js";import{t as xt}from"./ConnectModels-B4dGb5yc.js";import{i as St,n as Ct,r as wt,t as Tt}from"./thinking-DwlkTfPX.js";import{t as Et}from"./ArtifactContainer-B1-GVzVf.js";import{t as Dt}from"./evaluationsApi-Bg12ekHo.js";import{n as Ot,t as kt}from"./useDictation-BXyX1U8r.js";import{n as At,t as jt}from"./composerStyles-C83jssgZ.js";var Mt=n(),Q=e(t(),1),$=r(),Nt=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},Pt=({status:e})=>e===`running`||e===`awaiting_approval`?(0,$.jsx)(ae,{className:`h-3.5 w-3.5 animate-spin`}):e===`succeeded`?(0,$.jsx)(R,{className:`h-3.5 w-3.5 text-green-600 dark:text-green-400`}):e===`denied`?(0,$.jsx)(H,{className:`h-3.5 w-3.5 text-amber-600 dark:text-amber-400`}):(0,$.jsx)(B,{className:`h-3.5 w-3.5 text-red-500 dark:text-red-400`}),Ft=({call:e})=>{let{t}=l(),[n,r]=(0,Q.useState)(!1),i=t(`tools.callStatus.${e.status}`);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-200 bg-gray-50 dark:bg-dark-50 text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,"aria-expanded":n,children:[n?(0,$.jsx)(me,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(fe,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,$.jsx)(K,{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:m(`ml-auto flex shrink-0 items-center gap-1 text-xs`,e.status===`succeeded`?`text-green-600 dark:text-green-400`:e.status===`failed`?`text-red-500 dark:text-red-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(Pt,{status:e.status}),i]})]}),n&&(0,$.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 dark:border-dark-200`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.arguments`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Nt(e.arguments)}),e.resultPreview!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-2 text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.result`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:e.resultPreview})]})]})]})},It=({calls:e,className:t})=>e.length===0?null:(0,$.jsx)(`div`,{className:m(`flex flex-col gap-1.5`,t),children:e.map(e=>(0,$.jsx)(Ft,{call:e},e.id))}),Lt=({approval:e,onDecide:t,className:n})=>{let{t:r}=l(),[i,a]=(0,Q.useState)(!1),o=(n,r)=>{a(!0),t(e.approvalId,n,r)};return(0,$.jsxs)(`div`,{role:`alertdialog`,"aria-label":r(`tools.approval.title`),className:m(`rounded-lg border border-primary-300/70 bg-primary-50 p-3 text-sm dark:border-primary-700/60 dark:bg-primary-900/20`,n),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-primary-800 dark:text-primary-200`,children:[(0,$.jsx)(I,{className:`h-4 w-4 shrink-0`}),r(`tools.approval.title`)]}),(0,$.jsx)(`p`,{className:`mt-1 text-primary-800/90 dark:text-primary-100/80`,children:r(`tools.approval.description`,{tool:e.toolCall.name,server:e.toolCall.serverName??r(`tools.approval.builtinSource`)})}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded bg-white/70 p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Nt(e.toolCall.arguments)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(Z,{size:`sm`,disabled:i,onClick:()=>o(!0,`once`),children:r(`tools.approval.allowOnce`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>o(!0,`session`),children:r(`tools.approval.allowSession`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>o(!0,`always`),children:r(`tools.approval.allowAlways`)}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>o(!1,`once`),children:r(`tools.approval.deny`)})]})]})},Rt=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i}=l(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,s=e.prompt_eval_count||0,c=e.eval_count||0,u=s+c,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(ne,{size:12,className:`text-primary-500`}),c,` tokens`]}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,$.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,$.jsx)(me,{size:12}):(0,$.jsx)(fe,{size:12,className:`rtl:rotate-180`}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,s]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,c]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},zt=c(`components:ttsbutton`),Bt=null,Vt=null,Ht=0,Ut=3e5;async function Wt(e=!1){let t=Date.now();return!e&&Bt!==null&&t-Ht<Ut?Bt:Vt||(Vt=(async()=>{try{let e=await Ue.getModels();return e.success&&e.data&&e.data.length>0?(Bt=e.data,Ht=t,e.data):(Bt=[],Ht=t,[])}catch{return Bt=[],Ht=t,[]}finally{Vt=null}})(),Vt)}var Gt=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:s}=l(),{preferences:c}=et(),[u,d]=(0,Q.useState)(`idle`),[f,p]=(0,Q.useState)(null),[h,g]=(0,Q.useState)([]),[_,v]=(0,Q.useState)(null),y=(0,Q.useRef)(null),b=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await Wt(),n=Ye(t,c.ttsSettings?.model,c.ttsSettings?.pluginId);c.ttsSettings?.model&&!n&&(t=await Wt(!0)),e&&(g(t),v(t.length>0))})(),()=>{e=!1}},[c.ttsSettings?.model,c.ttsSettings?.pluginId]);let x=()=>{b.current+=1,y.current?.cancel(),y.current=null,d(`idle`)},S=async()=>{if(r===`blocked`||r===`error`){a?.();return}if(r===`loading`||r===`generating`||r===`buffering`||r===`playing`){i?.();return}if(u===`loading`||u===`generating`||u===`buffering`||u===`playing`){x();return}if(y.current){x();return}let t=yt();d(`loading`),p(null);let n=b.current+1;b.current=n;try{let r=await t;if(b.current!==n)return;if(r===`blocked`){d(`blocked`);return}let i=c.ttsSettings,a=qe(h,i?.model,i?.pluginId),l=a?.model||i?.model||`tts-1`,u=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),p=f&&i?.voice||a?.config?.default_voice,m=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,v=Math.max(1,a?.config?.max_characters||600),x=Math.min(v,600),S=i?.streamSentences!==!1||e.length>x?vt(e,{locale:s.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=gt({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>Ue.generate({model:l,pluginId:u,input:e,voice:m?void 0:p||void 0,voiceProfileId:m,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});y.current=C;let w=bt(C);try{await C.play(S)}finally{w(),y.current===C&&(y.current=null)}}catch(e){if(b.current!==n)return;if(ht(e)){d(`idle`);return}if(_t(e)){d(`blocked`);return}let t=e instanceof Error?e.message:o(`ttsButton.generateFailed`);p(t),zt.error(`TTS error:`,e),d(`error`)}};if((0,Q.useEffect)(()=>()=>{b.current+=1,y.current?.cancel(),y.current=null},[]),_===!1||_===null)return null;let C={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},w={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`},T=r&&![`idle`,`ended`,`cancelled`].includes(r)?r:u,E=T===`loading`||T===`generating`||T===`buffering`,D=T===`playing`,O=T===`blocked`,k=!!f||T===`error`,A=f||o(k?`ttsButton.playbackFailed`:O?`ttsButton.enableAudio`:D||E?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,$.jsxs)(`button`,{onClick:S,disabled:!e,title:A,"aria-label":A,"aria-busy":E||void 0,className:m(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,k?`text-red-500 dark:text-red-400`:O?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:D?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!O&&C[n],O&&n===`sm`&&`h-7`,O&&n===`md`&&`h-8`,O&&n===`lg`&&`h-10`,t),children:[E?(0,$.jsx)(ae,{className:m(w[n],`animate-spin`)}):D?(0,$.jsx)(oe,{className:w[n]}):k||O?(0,$.jsx)(ge,{className:w[n]}):(0,$.jsx)(U,{className:w[n]}),O&&(0,$.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},Kt=80,qt=5e3,Jt=15e3;function Yt({sessionId:e,messageId:t,thinking:n,isThinking:r,isPrivate:i}){let a=et(e=>e.preferences.titleSettings),o=(0,Q.useRef)(n),[c,l]=(0,Q.useState)(null),{autoTitle:u,taskModel:d,taskProviderType:f,taskProviderId:p}=a??{};return(0,Q.useEffect)(()=>{o.current=n},[n]),(0,Q.useEffect)(()=>{if(!e||!r||i||!u||!d||s())return;let n=!1,a,c=``,m=new AbortController,h=async()=>{let r=(o.current??``).slice(-4e3).trim();if(r.length<Kt||r===c){n||(a=setTimeout(()=>void h(),400));return}c=r;let i=Date.now(),s=qt;try{let i=await Y.summarizeThinking(e,{model:d,thinking:r,providerType:f,providerId:p},m.signal);if(!i.success||!i.data?.summary?.trim())throw Error(`Thinking summary unavailable`);n||l({sessionId:e,messageId:t,summary:i.data.summary.trim().slice(0,160)})}catch{s=Jt}n||(a=setTimeout(()=>void h(),Math.max(0,s-(Date.now()-i))))};return a=setTimeout(()=>void h(),350),()=>{n=!0,clearTimeout(a),m.abort()}},[e,t,r,i,u,d,f,p]),c&&c.sessionId===e&&c.messageId===t?c.summary:null}var Xt=[`accuracy`,`style`,`incomplete`,`harmful`,`formatting`],Zt=c(`components:chat-message`);function Qt({role:e,user:t,persona:n,modelAvatar:r}){let[i,a]=(0,Q.useState)(null);if(e===`assistant`){if(n)return(0,$.jsx)(`img`,{src:Ke(n,64),alt:n.name,"data-testid":`chat-assistant-avatar`,onError:e=>X(e.currentTarget,n.name,64),className:`mt-0.5 h-8 w-8 shrink-0 rounded-lg object-cover`});let e=r?.trim()??``,t=e.startsWith(`data:`)&&e!==i?e:``;return(0,$.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-sm dark:border-white/[0.09] dark:bg-dark-200 dark:text-dark-950`,children:t?(0,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>a(e)}):e?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,$.jsx)(lt,{label:null,className:`h-4 w-4`})})}let o=t?.username||`User`,s=t?.avatar?.trim()||``,c=!!s&&s!==i;return(0,$.jsx)(`div`,{role:c?void 0:`img`,"aria-label":c?void 0:o,"data-testid":`chat-user-avatar`,className:m(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,c?`border border-black/[0.07] bg-white dark:border-white/[0.09] dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:o,children:c?(0,$.jsx)(`img`,{src:s,alt:o,className:`h-full w-full object-cover`,onError:()=>a(s)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(ye,{"aria-hidden":`true`,className:`h-4 w-4`})})}var $t=Q.memo(({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onFork:a,onEditResend:o})=>{let{t:s,i18n:c}=l(),u=e.role===`user`,f=e.role===`system`,h=f&&_(e.content),g=h?e.content.slice(w.length):e.content,v=et(e=>e.preferences),y=$e(e=>e.user),b=O(e=>e.setSystemMessage),x=O(e=>e.rateMessage),S=O(e=>e.modelMetadata),C=O(e=>e.currentSession?.id),T=O(e=>e.currentSession?.model),E=O(e=>e.currentSession?.isPrivate===!0),D=O(e=>e.getCurrentPersona()),k=e.model||T||``,A=k?S[k]??Object.entries(S).find(([e])=>e.slice(e.indexOf(`/`)+1)===k)?.[1]:void 0,[j,M]=(0,Q.useState)(!1),[N,ee]=(0,Q.useState)(e.content),[te,ne]=(0,Q.useState)(null),[P,ie]=(0,Q.useState)(!1),[I,ae]=(0,Q.useState)(!1),[L,oe]=(0,Q.useState)(!1),se=(0,Q.useId)(),[ce,z]=(0,Q.useState)(`idle`),[le,ue]=(0,Q.useState)(null),[fe,he]=(0,Q.useState)([]),[ge,ye]=(0,Q.useState)(``),[be,xe]=(0,Q.useState)(!1),B=(0,Q.useRef)(null),V=(0,Q.useRef)(0),Se=(0,Q.useRef)(t),we=(0,Q.useRef)(!1),Te=async()=>{try{await navigator.clipboard.writeText(e.content),it(`success`),xe(!0),setTimeout(()=>xe(!1),2e3)}catch(e){Zt.error(`Failed to copy message:`,e)}},{thinkingContent:De,thinkingStreaming:U,parsedContent:W,artifacts:Oe}=(0,Q.useMemo)(()=>{if(u||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}:p(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=pt(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,u,f,t]),ke=U?void 0:e.statistics?.thinking_duration_ms??ut(e.id),Ae=Yt({sessionId:C,messageId:e.id,thinking:De,isThinking:U,isPrivate:E}),K=ke===void 0?s(`chatMessage.thinking`):s(`chatMessage.thoughtFor`,{duration:dt(ke)}),q=(0,Q.useCallback)(async e=>{let t=V.current+1;V.current=t,B.current?.cancel(),B.current=null,z(`loading`);try{if(e){let n=await e;if(V.current!==t)return;if(n===`blocked`){z(`blocked`);return}}let n=await Ue.getModels();if(V.current!==t)return;let r=n.success&&n.data?n.data:[],i=v.ttsSettings,a=qe(r,i?.model,i?.pluginId),o=Ye(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,l=a?.plugin||i?.pluginId,u=o&&i?.voice||a?.config?.default_voice,d=o&&i?.voiceProfileId||void 0,f=Math.max(1,a?.config?.max_characters||600),p=Math.min(f,600),m=i?.streamSentences!==!1||W.length>p?vt(W,{locale:c.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[W.trim()];if(m.length===0){z(`idle`);return}let h=gt({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>Ue.generate({model:s,pluginId:l,input:e,voice:d?void 0:u||void 0,voiceProfileId:d,speed:i?.speed||1,response_format:a?.config?.default_format},{signal:t}),onStateChange:e=>{V.current===t&&z(e)}});if(V.current!==t){h.cancel();return}B.current=h;let g=bt(h);try{await h.play(m)}finally{g(),B.current===h&&(B.current=null),V.current===t&&(h.state===`ended`||h.state===`cancelled`)&&z(`idle`)}}catch(e){if(V.current!==t)return;ht(e)?z(`idle`):_t(e)?z(`blocked`):(Zt.error(`Auto-play TTS failed:`,e),z(`error`))}},[c.language,W,v.ttsSettings]);(0,Q.useEffect)(()=>{let e=Se.current&&!t;Se.current=t,e&&!we.current&&!u&&!f&&W&&v.ttsSettings?.enabled&&v.ttsSettings.autoPlay&&(we.current=!0,q())},[t,u,f,W,v.ttsSettings?.autoPlay,v.ttsSettings?.enabled,q]),(0,Q.useEffect)(()=>()=>{V.current+=1,B.current?.cancel(),B.current=null},[]);let Ne=()=>{let e=yt();q(e)},Pe=()=>{V.current+=1,B.current?.cancel(),B.current=null,z(`idle`)},Fe=()=>h?s(`chatMessage.conversationSummary`):f?s(`chatMessage.system`):u?v.showUsername&&y?.username?y.username:s(`chatMessage.you`):D?.name?D.name:A?.label||k||s(`chatMessage.assistant`),Ie=()=>{M(!0),ee(e.content)},[Le,ze]=(0,Q.useState)(!1),Be=async()=>{if(C&&!Le){ze(!0);try{let t=await Y.restoreCompaction(C,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;O.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){Zt.error(`Failed to restore compacted messages:`,e),J.error(s(`chatMessage.restoreFailed`))}finally{ze(!1)}}},Ve=async()=>{ie(!0);try{b(N),M(!1),Zt.debug(`✅ System message updated:`,N)}catch(e){Zt.error(`Failed to save system message:`,e)}finally{ie(!1)}},He=()=>{M(!1),ee(e.content)},X=()=>{let t=N.trim();M(!1),t&&o?.(e.id,t)},We=t=>{if(!C)return;let n=e.rating===t;if(x(C,e.id,n?void 0:t),!E){if(n){ue(null),Dt.deleteFeedback(e.id).catch(()=>void 0);return}he([]),ye(``),ue(t===1?1:-1),Dt.upsertFeedback({sessionId:C,messageId:e.id,rating:t===1?1:-1}).catch(()=>void 0)}},Ge=()=>{C&&le!==null&&(Dt.upsertFeedback({sessionId:C,messageId:e.id,rating:le,tags:fe,...ge.trim()?{comment:ge.trim()}:{}}).catch(()=>void 0),ue(null))},Ke=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,Je=f&&g.length>100;return(0,$.jsxs)(`div`,{className:m(`group flex py-1.5 transition-colors sm:py-2`,u?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:m(`flex min-w-0 gap-2.5 sm:gap-3`,u?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!u&&!f&&(0,$.jsx)(Qt,{role:`assistant`,persona:D,modelAvatar:A?.avatar}),(0,$.jsxs)(`div`,{className:m(`min-w-0 flex-1`,u?`flex flex-col items-end`:f?`py-1.5`:`py-0.5`),children:[!u&&!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:Fe()}),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:d(e.timestamp,c.language)})]}),(0,$.jsxs)(`div`,{className:m(!u&&!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/[0.06] bg-gray-100 dark:border-white/[0.08] dark:bg-gray-800`,children:(0,$.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>ne(e)})},t))}),u?j?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/[0.08] bg-white p-2 shadow-sm dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{dir:`auto`,value:N,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||(e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),X()):e.key===`Escape`&&He())},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-none dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(`button`,{onClick:He,className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 transition-colors hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:s(`chatMessage.cancelEditing`)}),(0,$.jsx)(`button`,{onClick:X,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white transition-colors hover:bg-gray-700 dark:bg-dark-300 dark:hover:bg-dark-400`,children:s(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{"data-user-bubble":``,className:`rounded-2xl rounded-ee-md border border-black/[0.06] bg-gray-900 px-3.5 py-2 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):f?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[h?(0,$.jsx)(de,{className:`h-2.5 w-2.5 opacity-50`}):(0,$.jsx)(re,{className:`h-2.5 w-2.5 opacity-50`}),s(h?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:h?(0,$.jsx)(`button`,{onClick:()=>void Be(),disabled:Le,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.restoreCompacted`),children:(0,$.jsx)(Ee,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):j?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:Ve,disabled:P,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.saveChanges`),children:(0,$.jsx)(G,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:He,disabled:P,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.cancelEditing`),children:(0,$.jsx)(H,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:Ie,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:s(`chatMessage.editSystemMessage`),children:(0,$.jsx)(Me,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),j?(0,$.jsx)(`textarea`,{dir:`auto`,value:N,onChange:e=>ee(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:s(`chatMessage.systemMessagePlaceholder`),disabled:P}):(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:I?g:Ke(g)}),Je&&(0,$.jsx)(`button`,{onClick:()=>ae(!I),className:`mt-2 flex items-center gap-1 text-xs text-gray-400 transition-colors hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`,children:I?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{className:`h-3 w-3`}),s(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(me,{className:`h-3 w-3`}),s(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(De||U)&&(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":L,"aria-controls":se,onClick:()=>oe(!L),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-none focus-visible:ring-2 focus-visible:ring-primary-500/30`,children:[U?(0,$.jsx)(at,{"data-testid":`thinking-generation-indicator`}):(0,$.jsx)(_e,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{role:`status`,"aria-live":U?`polite`:`off`,"aria-atomic":`true`,className:`min-w-0 [overflow-wrap:anywhere]`,children:[(0,$.jsx)(`span`,{"data-testid":`thinking-summary`,dir:`auto`,className:m(`block font-medium`,U&&`animate-slide-up [animation-duration:140ms] motion-reduce:animate-none`),children:Ae||(U?`${s(`chatMessage.thinking`)}…`:K)},Ae||`thinking`),Ae&&!U&&(0,$.jsx)(`span`,{className:`mt-0.5 block text-ink-subtle`,children:K})]}),L?(0,$.jsx)(F,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}):(0,$.jsx)(me,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`})]}),(0,$.jsx)(`div`,{id:se,"data-testid":`thinking-content`,hidden:!L,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:L&&De&&(0,$.jsx)(st,{content:De,isStreaming:U,className:`text-[13px] text-ink-muted`})})]}),(0,$.jsx)(st,{content:W,isStreaming:t&&!(U&&!W)})]}),!u&&!f&&Oe.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Et,{artifacts:Oe})}),!u&&!f&&Array.isArray(e.providerMetadata?.toolCalls)&&e.providerMetadata.toolCalls.length>0&&(0,$.jsx)(It,{calls:e.providerMetadata.toolCalls,className:`mt-2.5`}),!u&&!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:s(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,$.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,$.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!u&&!f&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(Rt,{statistics:e.statistics})}),!f&&!t&&(0,$.jsxs)(`div`,{className:m(`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`,!u&&[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(ce)?`sm:opacity-100`:`sm:opacity-0`,u?`mt-1 justify-end`:`mt-1`),children:[u&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:d(e.timestamp,c.language),children:[Fe(),` ·`,` `,d(e.timestamp,c.language)]}),!u&&W&&(0,$.jsx)(Gt,{text:W,size:`sm`,externalPlaybackState:ce,onStopExternal:Pe,onRetryExternal:Ne,className:m(`transition-colors`,ce===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),u&&o&&!j&&(0,$.jsx)(`button`,{onClick:()=>{ee(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:s(`chatMessage.edit`),children:(0,$.jsx)(Me,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:Te,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:s(be?`chatMessage.copied`:`chatMessage.copyMessage`),children:be?(0,$.jsx)(R,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(Ce,{className:`h-3.5 w-3.5`})}),!u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>We(1),className:m(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===1&&`text-primary-600 dark:text-primary-400`),title:s(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(Re,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>We(-1),className:m(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===-1&&`text-red-500 dark:text-red-400`),title:s(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(ve,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})}),le!==null&&(0,$.jsxs)(`div`,{className:`ml-1 flex flex-wrap items-center gap-1 rounded-lg border border-gray-200 bg-white px-2 py-1 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`feedback-details`,children:[Xt.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>he(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:m(`rounded-full border px-2 py-0.5 text-[10px]`,fe.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":fe.includes(e),children:s(`chatMessage.feedbackTags.${e}`)},e)),(0,$.jsx)(`input`,{value:ge,onChange:e=>ye(e.target.value),placeholder:s(`chatMessage.feedbackComment`),className:`w-32 rounded border border-gray-300 px-1.5 py-0.5 text-[10px] dark:border-dark-300 dark:bg-dark-50`,maxLength:2e3}),(0,$.jsx)(`button`,{type:`button`,onClick:Ge,className:`rounded bg-gray-900 px-2 py-0.5 text-[10px] text-white dark:bg-white dark:text-gray-900`,children:s(`common.save`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>ue(null),"aria-label":s(`common.close`),className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,children:(0,$.jsx)(H,{className:`h-3 w-3`})})]})]}),!u&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:s(`chatMessage.regenerateResponse`),children:(0,$.jsx)(pe,{className:`h-3.5 w-3.5`})}),a&&(0,$.jsx)(`button`,{onClick:()=>a(e.id),className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:s(`chat.fork.action`),"data-testid":`fork-from-message`,children:(0,$.jsx)(je,{className:`h-3.5 w-3.5`})})]})]})]}),u&&(0,$.jsx)(Qt,{role:`user`,user:y??null})]}),te&&(0,Mt.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":s(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>ne(null),children:[(0,$.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),ne(null)},children:(0,$.jsx)(H,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:te,alt:s(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})});$t.displayName=`ChatMessage`;var en=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,tn=220,nn=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>tn?`${t.slice(0,219).trimEnd()}…`:t},rn=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=l(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[s,c]=(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),c(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:en()?`auto`:`smooth`})},[t]),e.length<3)return null;let h=Math.max(0,e.findIndex(e=>e.id===t)),g=e[h]?.id,_=e.findIndex(e=>e.id===s),v=_>=0?e[_]:null,y=_>=0?`conversation-history-preview-${_}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||c(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let l=t.id===g,u=Math.abs(a-h),d=s===t.id?y:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":l?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===h?0:-1,className:m(`group flex h-4 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||c(null)})},onKeyDown:t=>{if(t.key===`Escape`){c(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:m(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,l?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),v&&(0,$.jsx)(`div`,{id:y,role:`tooltip`,className:m(`pointer-events-none absolute start-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:nn(v.prompt)}),v.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:nn(v.response)})]})})]})}),an=Q.memo(({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)($t,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,$.jsxs)(`div`,{className:m(`relative py-2`,c),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(W,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let l=e.isActive!==!1,u=t&&i===e.id,d=u?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:m(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||u?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!u&&`cursor-pointer`),role:!l&&!u?`button`:void 0,tabIndex:!l&&!u?0:void 0,onClick:()=>!l&&!u&&s?.(e.id),onKeyDown:t=>{!l&&!u&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,$.jsxs)(`div`,{className:m(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||u?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,$.jsx)(R,{className:`h-3 w-3`}),!l&&!u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,$.jsx)(`div`,{className:m(!l&&!u&&`opacity-75`),children:(0,$.jsx)($t,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})});an.displayName=`MessageBranch`;var on={web_search:te,web_fetch:Pe,exec:z,browser:Pe,Read:he,Write:he,Edit:he,image:ie,memory_search:we,memory_get:we,working:K,thinking:K,default:K},sn={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`},cn=({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:m(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=on[e.name]||on.default,n=sn[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:m(`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:m(`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)})})};c(`components:chat-messages`);var ln=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],un=e=>e.messages.every(e=>e.isActive===!1),dn=e=>e.role===`system`&&!_(e.content),fn=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,pn=e=>Math.min(120,e*.28),mn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],activeToolCalls:o,pendingToolApproval:s,onDecideToolApproval:c,className:u,onRegenerate:d,onSelectBranch:f,onEditResend:p,onFork:h,followUpSuggestions:g,onFollowUpSelect:_})=>{let{t:v}=l(),y=(0,Q.useRef)(null),b=(0,Q.useRef)(void 0),x=(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)=>dn(e)&&!dn(t)?-1:dn(t)&&!dn(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 dn(n)&&!dn(r)?-1:dn(r)&&!dn(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=ln(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<A.length;e++){let t=ln(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),P=(0,Q.useCallback)(()=>{let e=x.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+pn(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]),F=(0,Q.useCallback)(()=>{w.current===null&&(w.current=window.requestAnimationFrame(()=>{w.current=null,P()}))},[P]),ie=(0,Q.useCallback)(()=>{let t=x.current;if(b.current&&clearTimeout(b.current),E.current=!1,b.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;D.current=!n,k(!n&&e.length>0),F()},[e.length,F]),I=(0,Q.useCallback)(()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(ie,180)},[ie]),ae=(0,Q.useCallback)((e=!1)=>{(!D.current||e)&&y.current?.scrollIntoView({behavior:fn()})},[]),oe=(0,Q.useCallback)(()=>{let t=x.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(E.current){D.current=!0,k(!o&&e.length>0),F(),I();return}D.current=!o,k(!o&&e.length>0),a<=2&&N.length>0?(T.current=N.length-1,re(N[N.length-1])):F()},[N,e.length,I,F]),se=(0,Q.useCallback)(e=>{let t=x.current,n=C.get(e);if(!t||!n)return;let r=fn();E.current=!0,D.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-pn(t.clientHeight)),behavior:r}),F(),r===`auto`?ie():I()},[ie,C,I,F]),ce=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>ce.current&&!D.current&&ae(),ce.current=e.length},[e.length,ae]),(0,Q.useEffect)(()=>{i&&(t||n)&&!D.current&&requestAnimationFrame(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{F();let e=S.current,t=x.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(F);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,F),()=>{n?.disconnect(),window.removeEventListener(`resize`,F)}},[M,F]),(0,Q.useEffect)(()=>()=>{w.current!==null&&(window.cancelAnimationFrame(w.current),w.current=null)},[]),(0,Q.useEffect)(()=>()=>{b.current&&clearTimeout(b.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:m(`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/[0.06] bg-surface/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(L,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:v(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:v(`chatMessage.startConversationDescription`)})]})});let R=-1;for(let e=A.length-1;e>=0;e--)if(A[e].messages.some(e=>e.role===`assistant`)){R=e;break}return(0,$.jsxs)(`div`,{className:m(`relative min-h-0 flex-1`,u),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:x,"data-testid":`chat-scroll-viewport`,"data-scroll-fade-top":`40`,"data-scroll-fade-bottom":`72`,onScroll:oe,className:m(`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===R,s=ee.has(e.id),c=i&&e.messages.some(e=>e.id===r),l;if(un(e))l=(0,$.jsx)(`div`,{className:`opacity-55`,children:(0,$.jsx)($t,{message:ln(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)($t,{message:u,isStreaming:c,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onEditResend:i?void 0:p,onFork:i?void 0:h,className:a===0?`mt-3 sm:mt-4`:``})}else l=(0,$.jsx)(an,{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)(It,{calls:o??[],className:`pb-2`}),s&&c&&(0,$.jsx)(Lt,{approval:s,onDecide:c,className:`mb-2`}),i&&a.length>0&&(0,$.jsx)(cn,{tools:a,className:`px-0`}),!i&&g&&g.length>0&&_&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-subtle`,children:v(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:g.map(e=>(0,$.jsx)(`button`,{onClick:()=>_(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-ink-muted transition-colors hover:text-ink dark:border-dark-200`,children:e},e))})]}),(0,$.jsx)(`div`,{ref:y,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(rn,{items:j,activeId:ne,onSelect:se}),O&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-new-messages`,onClick:()=>{E.current=!1,b.current&&=(clearTimeout(b.current),void 0),D.current=!1,y.current?.scrollIntoView({behavior:fn()}),k(!1)},className:m(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/[0.08]`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:v(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(Ie,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:v(`chatMessage.newMessages`)})]})]})};function hn(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 gn=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)(()=>hn(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:m(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:m(`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)(P,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});gn.displayName=`CodeAwareTextarea`;var _n=c(`components:media-upload`),vn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:s}=l(),c=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)([]),_=async e=>{if(e&&!a)for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await v(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):J.error(s(`chat.mediaUpload.unsupportedFileType`,{name:n.name}))}},v=async r=>{if(n-e.length<=0){J.error(s(`chat.mediaUpload.maxImagesAllowed`,{count:n}));return}if(r.size>10485760){J.error(s(`chat.mediaUpload.imageTooLarge`,{name:r.name}));return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},y=async e=>{if(e.size>10485760){J.error(s(`documents.fileSizeTooLarge`));return}p(!0);try{let t=await Be.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;g(e=>[...e,n]),i?.(n),J.success(s(`documents.uploadSuccessWithName`,{name:e.name}))}else J.error(t.error||s(`documents.uploadFailed`))}catch(e){_n.error(`Document upload error:`,e),J.error(s(`documents.uploadFailed`))}finally{p(!1)}},b=e=>{e.preventDefault(),a||d(!0)},x=e=>{e.preventDefault(),d(!1)},S=e=>{e.preventDefault(),d(!1),a||_(e.dataTransfer.files)},C=n=>{t(e.filter((e,t)=>t!==n))},w=async e=>{try{let t=await Be.deleteDocument(e);t.success?(g(t=>t.filter(t=>t.id!==e)),J.success(s(`documents.removeSuccess`))):J.error(t.error||s(`documents.removeFailed`))}catch(e){_n.error(`Error removing document:`,e),J.error(s(`documents.removeFailed`))}},T=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},E=e.length>0||h.length>0;return(0,$.jsxs)(`div`,{className:m(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:m(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>!a&&c.current?.click(),children:[(0,$.jsx)(`input`,{ref:c,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{_(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(ae,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,$.jsx)(Ae,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[s(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:s(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:s(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),C(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(H,{className:`h-3 w-3`})})]},`img-${t}`)),h.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(he,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,$.jsx)(V,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:T(e.size)})]}),(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(H,{className:`h-3 w-3`})})]},e.id))]})]})},yn=c(`components:document-indicator`),bn=({sessionId:e,className:t=``})=>{let{t:n}=l(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),u=(0,Q.useRef)(null),d=(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){yn.error(`Failed to load documents:`,e)}},[e]);if((0,Q.useEffect)(()=>{let e=setTimeout(()=>void d(),0),t=()=>void d();return window.addEventListener(`libre:documents-updated`,t),()=>{clearTimeout(e),window.removeEventListener(`libre:documents-updated`,t)}},[d]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{u.current?.contains(e.target)||(o(!1),c(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let p=async e=>{c(null);try{let t=await Be.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){yn.error(`Failed to delete document:`,e),A.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:s===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-red-700 dark:text-red-300`,children:n(`settings.documents.library.deleteConfirm`,{name:e.filename})}),(0,$.jsx)(`button`,{onClick:()=>void p(e.id),className:`shrink-0 text-xs font-medium text-red-600 underline underline-offset-2 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:n(`common.delete`)}),(0,$.jsx)(`button`,{onClick:()=>c(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)(he,{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:[f(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,$.jsx)(`button`,{onClick:()=>c(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)(H,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),c(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`)} - ${f(m)}`,children:[(0,$.jsx)(be,{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`]})]})]})},xn=c(`components:structured-output`),Sn=[{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`}],Cn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=l(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),c=()=>Sn.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),u=()=>{let t=c();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},d=e=>{let n=c().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,$.jsxs)(`div`,{className:m(`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)(re,{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)(ot,{value:u().label,onChange:e=>d(e.target.value),options:c().map(e=>({value:e.label,label:e.label}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(ct,{value:o,onChange:e=>s(e.target.value),placeholder:`{
8
+ "type": "object",
9
+ "properties": {
10
+ "field1": { "type": "string" },
11
+ "field2": { "type": "number" }
12
+ },
13
+ "required": ["field1"]
14
+ }`,rows:8,className:`font-mono text-sm`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Z,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){xn.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(Z,{onClick:()=>{a(!1),s(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=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)(ee,{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)(he,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},wn=({value:e,inheritedValue:t,onChange:n})=>{let{t:r}=l(),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(null),s=e??t,c=Ct(s),u=wt(s),d=wt(e),f=t==null?void 0:wt(t);return(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return window.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[i]),(0,$.jsxs)(`div`,{ref:o,className:`relative flex-shrink-0`,children:[(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>a(e=>!e),className:m(`h-9 rounded-full p-0 flex items-center justify-center gap-1 touch-manipulation transition-colors duration-150`,c?`w-auto px-2.5`:`w-9`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,c&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:c?r(`chat.input.thinkingOn`,{level:r(`settings.generation.thinkingLevels.${u}`)}):r(`chat.input.thinkingOff`),"aria-haspopup":`menu`,"aria-expanded":i,"aria-pressed":c,children:[(0,$.jsx)(_e,{className:`h-4 w-4`}),c&&(0,$.jsx)(`span`,{className:`text-[11px] font-medium`,children:r(`settings.generation.thinkingLevels.${u}`)})]}),i&&(0,$.jsxs)(`div`,{role:`menu`,className:`absolute bottom-full end-0 z-30 mb-2 w-48 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-2 pt-1 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.controls.thinking`)}),Tt.map(e=>{let t=e===d;return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":t,onClick:()=>{n(St(e)),a(!1)},className:m(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:e==="default"&&f!==void 0?r(`settings.generation.thinkingLevels.defaultWith`,{level:r(`settings.generation.thinkingLevels.${f}`)}):r(`settings.generation.thinkingLevels.${e}`)}),t&&(0,$.jsx)(R,{className:`h-3.5 w-3.5 shrink-0`})]},e)})]})]})},Tn=7,En=2*Math.PI*Tn,Dn=e=>`⁨${e}⁩`,On=({usage:e,trainedBudget:t})=>{let{t:n,i18n:r}=l(),[i,a]=(0,Q.useState)(!1),o=typeof e.budget==`number`&&e.budget>0,s=e.ratio??0,c=Math.round(s*100),u=e.measured?``:`~`,d=r.language,f=`${u}${S(e.used,d)}`,p=o?n(`chat.context.tokensUsed`,{used:Dn(f),budget:Dn(S(e.budget,d))}):n(`chat.context.tokensUsedNoBudget`,{used:Dn(f)}),h=t===void 0?void 0:n(`chat.context.capped`,{trained:Dn(S(t,d))}),g=[n(`chat.context.title`),o?n(`chat.context.full`,{percent:c}):void 0,p,h].filter(Boolean).join(` `),_=Math.min(s,1);return(0,$.jsxs)(`div`,{className:`relative flex-shrink-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onFocus:()=>a(!0),onBlur:()=>a(!1),onKeyDown:e=>{e.key===`Escape`&&a(!1)},children:[(0,$.jsx)(`span`,{role:o?`meter`:`img`,tabIndex:0,"aria-label":g,...o?{"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(c,100),"aria-valuetext":g}:{},className:m(`touch-target flex h-9 w-9 items-center justify-center rounded-full text-ink-muted outline-none`,`transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/40`,s>=.8&&s<1&&`text-amber-600 dark:text-amber-400`,s>=1&&`text-red-600 dark:text-red-400`),children:(0,$.jsxs)(`svg`,{viewBox:`0 0 18 18`,className:`h-4 w-4 -rotate-90`,children:[(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:Tn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`opacity-30`,...o?{}:{strokeDasharray:`2 2`}}),o&&_>0&&(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:Tn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:En,strokeDashoffset:En*(1-_)})]})}),i&&(0,$.jsxs)(`div`,{role:`tooltip`,className:m(`pointer-events-none absolute bottom-full left-1/2 z-30 mb-2 -translate-x-1/2`,`whitespace-nowrap rounded-2xl bg-surface/95 px-4 py-3 text-center shadow-lv3 backdrop-blur-xl`,`border border-black/[0.06] dark:border-white/[0.08] dark:bg-dark-100/95`,`animate-scale-in`),children:[(0,$.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.title`)}),o&&(0,$.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.full`,{percent:c})}),(0,$.jsx)(`p`,{className:`text-[13px] tabular-nums text-gray-900 dark:text-dark-900`,children:p}),h&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:h})]})]})},kn=c(`components:prompt-queue`),An=({sessionId:e,queue:t})=>{let{t:n}=l(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),s=t=>mt(e,t),c=async t=>{try{let n=await Y.claimQueuedPrompt(e,t);n.success&&n.data&&s(n.data.queue)}catch(e){kn.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 Y.reorderPromptQueue(e,o);t.success&&t.data&&s(t.data.queue)}catch(e){kn.error(`Failed to reorder the prompt queue:`,e)}},d=async t=>{let r=a.trim();if(r)try{let a=await Y.updateQueuedPrompt(e,t,r);a.success&&a.data?(s(a.data.queue),i(null)):J.error(a.error||n(`chat.queue.updateFailed`))}catch(e){kn.error(`Failed to update the queued prompt:`,e),J.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)(ze,{className:`h-3 w-3`}),n(`chat.queue.title`,{total:t.length})]}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:t.map((e,s)=>(0,$.jsx)(`li`,{className:`flex items-center gap-1.5 rounded-lg border border-black/[0.06] bg-surface/70 px-2 py-1 dark:border-white/[0.08] dark:bg-dark-200/70`,"data-testid":`prompt-queue-entry`,children:r===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:t=>{t.key===`Enter`&&d(e.id),t.key===`Escape`&&i(null)},className:`min-w-0 flex-1 bg-transparent text-[13px] text-gray-900 focus:outline-none dark:text-dark-900`,"data-testid":`prompt-queue-edit-input`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void d(e.id),className:`rounded-md p-1 text-green-600 hover:bg-green-50 dark:hover:bg-green-900/20`,"aria-label":n(`common.save`),children:(0,$.jsx)(R,{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)(Se,{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)(Ie,{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)(ke,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void c(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)(H,{className:`h-3 w-3`})})]})},e.id))})]})},jn=(e,t)=>{let n=[];for(let r of t){let t=k(e,r);t&&n.push({model:t.model,providerType:t.providerType??null,providerId:t.providerId??null})}return n},Mn=({models:e,currentModelKey:t,selectedKeys:n,onChange:r,disabled:i=!1})=>{let{t:a}=l(),[o,s]=(0,Q.useState)(!1),c=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!o)return;let e=e=>{c.current?.contains(e.target)||s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[o]);let u=e.filter(x).map(e=>({model:e,key:C(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:c,children:[(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>s(e=>!e),className:m(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,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)(ce,{className:`h-4 w-4`}),n.length>0&&(0,$.jsxs)(`span`,{className:`absolute -end-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white`,children:[`+`,n.length]})]}),o&&(0,$.jsxs)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 max-h-72 w-72 overflow-y-auto rounded-xl border border-gray-200 bg-white p-2 shadow-lg scrollbar-thin dark:border-dark-200 dark:bg-dark-50`,role:`menu`,"data-testid":`composer-compare-menu`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium text-gray-400 dark:text-dark-500`,children:a(`chat.compare.hint`,{max:3})}),u.map(({model:e,key:t})=>{let r=n.includes(t),i=!r&&n.length>=3;return(0,$.jsxs)(`label`,{className:m(`flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-800 hover:bg-gray-50 dark:text-dark-800 dark:hover:bg-dark-100`,i&&`cursor-not-allowed opacity-40`),children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:r,disabled:i,onChange:()=>d(t),className:`h-3.5 w-3.5 rounded border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate`,children:e.name})]},t)})]})]})},Nn=`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(`,`),Pn=/^\/([a-z0-9-]*)$/,Fn=/(?:^|\s)\$([a-z0-9-]*)$/,In=8,Ln=(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??``}),Rn=({prompt:e,onCancel:t,onInsert:n})=>{let{t:r}=l(),[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(Ln(e.content,e.variables,i)),children:r(`composer.variables.insert`)})]})]})},zn=(0,Q.forwardRef)(({message:e,disabled:t=!1,onApply:n},r)=>{let{t:i}=l(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),[f,p]=(0,Q.useState)(null),h=(0,Q.useRef)({prompts:!1,skills:!1}),g=t?null:Pn.exec(e),_=t||g?null:Fn.exec(e),v=g!==null,y=_!==null;(0,Q.useEffect)(()=>{v&&!h.current.prompts&&(h.current.prompts=!0,Xe.list().then(e=>{o(t=>e.success&&e.data?e.data:t??[])}).catch(()=>o(e=>e??[])).finally(()=>{h.current.prompts=!1}))},[v]),(0,Q.useEffect)(()=>{y&&!h.current.skills&&(h.current.skills=!0,Ge.list().then(e=>{c(t=>e.success&&e.data?e.data:t??[])}).catch(()=>c(e=>e??[])).finally(()=>{h.current.skills=!1}))},[y]);let b=(0,Q.useMemo)(()=>{if(g){let e=g[1];return(a??[]).filter(t=>t.slug.startsWith(e)).slice(0,In).map(e=>({kind:`prompt`,key:e.id,slug:e.slug,label:e.title,detail:e.description,prompt:e}))}if(_){let e=_[1];return(s??[]).filter(t=>t.enabled&&t.slug.startsWith(e)).slice(0,In).map(e=>({kind:`skill`,key:e.id,slug:e.slug,label:e.name,detail:e.description,skill:e}))}return[]},[g,_,a,s]),[x,S]=(0,Q.useState)(e);e!==x&&(S(e),d(0),!g&&f&&p(null));let C=t=>{let r=b[t];if(r){if(r.kind===`prompt`){if(r.prompt.variables.length>0){p(r.prompt);return}n(r.prompt.content);return}if(_){let t=e.length-(_[1].length+1);n(`${e.slice(0,t)}$${r.slug} `)}}};if((0,Q.useImperativeHandle)(r,()=>({handleKeyDown(t){return f?t.key===`Escape`?(t.preventDefault(),p(null),!0):t.key===`Enter`:b.length===0?!1:t.key===`ArrowDown`?(t.preventDefault(),d(e=>(e+1)%b.length),!0):t.key===`ArrowUp`?(t.preventDefault(),d(e=>(e-1+b.length)%b.length),!0):t.key===`Enter`||t.key===`Tab`?(t.preventDefault(),C(u),!0):t.key===`Escape`&&(t.preventDefault(),n(e),!0)}})),f)return(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-variable-form`,children:(0,$.jsx)(Rn,{prompt:f,onCancel:()=>p(null),onInsert:e=>{p(null),n(e)}})});let w=g?`prompt`:_?`skill`:null,T=g?a!==null:s!==null,E=g?g[1]===``:_?_[1]===``:!1;return b.length===0?w&&T&&E?(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md rounded-xl border border-gray-200 bg-white px-3 py-2 text-xs text-gray-500 shadow-lg dark:border-dark-200 dark:bg-dark-50 dark:text-gray-400`,"data-testid":`composer-suggestions-empty`,children:i(w===`prompt`?`composer.promptMenu.empty`:`composer.skillMenu.empty`)}):null:(0,$.jsx)(`div`,{role:`listbox`,"aria-label":i(g?`composer.promptMenu.label`:`composer.skillMenu.label`),className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-suggestions`,children:b.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===u,onMouseEnter:()=>d(t),onMouseDown:e=>{e.preventDefault(),C(t)},className:m(`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)(Fe,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(L,{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))})});zn.displayName=`ComposerSuggestions`;var Bn=(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},Vn=({value:e,onChange:t,disabled:n=!1,buttonClassName:r})=>{let{t:i}=l(),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=!1;return We.getCatalog().then(t=>{!e&&t.success&&t.data&&(d(t.data.available&&t.data.tools.length>0),c(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,h]=(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))}h(Math.max(160,Math.floor(t-n-24)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[a]),!u||!s)return null;let g=s.filter(e=>e.source===`builtin`),_=new Map;for(let e of s)e.serverId&&_.set(e.serverId,e.serverName??e.serverId);let v=[..._.entries()],y=g.map(e=>e.name),b=v.map(([e])=>e),x=new Set(e.builtinTools??y),S=new Set(e.serverIds??b),C=(n,r,i,a,o)=>(0,$.jsxs)(`label`,{className:m(`flex cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-sm hover:bg-gray-50 dark:hover:bg-dark-100`,!e.enabled&&`opacity-50`),onClickCapture:e.enabled?void 0:n=>{n.preventDefault(),n.stopPropagation(),t({...e,enabled:!0})},children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a,disabled:!e.enabled,onChange:o,"data-testid":`composer-tool-option`,className:`mt-0.5 h-3.5 w-3.5 accent-primary-600`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-gray-800 dark:text-gray-200`,dir:`ltr`,children:r}),i&&(0,$.jsx)(`span`,{className:`block truncate text-xs text-gray-500 dark:text-gray-400`,children:i})]})]},n);return(0,$.jsxs)(`div`,{ref:f,className:`relative flex-shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,disabled:n,onClick:()=>o(e=>!e),className:m(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,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)(K,{className:`h-4 w-4`})}),a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full start-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 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:[g.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.builtin`)}),g.map(n=>C(n.name,n.name,void 0,x.has(n.name),()=>t({...e,enabled:!0,builtinTools:Bn(e.builtinTools,y,n.name)})))]}),v.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`)}),v.map(([n,r])=>C(n,r,void 0,S.has(n),()=>t({...e,enabled:!0,serverIds:Bn(e.serverIds,b,n)})))]})]}),(0,$.jsx)(`p`,{className:`mt-1 flex-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`)})]})]})},Hn={enabled:!1,builtinTools:null,serverIds:null},Un=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}:{}}},Wn=c(`components:chat-input`),Gn=560,Kn=({onSendMessage:e,onStopGeneration:t,onCancelComparison:n,onOpenVoiceMode:r,disabled:i=!1})=>{let{t:a}=l(),[o,s]=(0,Q.useState)(``),c=(0,Q.useRef)(``),[u,d]=(0,Q.useState)([]),[f,p]=(0,Q.useState)(null),[h,_]=(0,Q.useState)(!1),[v,x]=(0,Q.useState)(!1),[S,w]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(!1),[ee,te]=(0,Q.useState)([]),ne=O(e=>e.pendingComparisons),[re,P]=(0,Q.useState)(Hn),F=O(e=>e.currentSession?.isPrivate===!0);(0,Q.useEffect)(()=>{let e=!1;return He.getConfig().then(t=>{!e&&t.success&&t.data&&w(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[I,L]=(0,Q.useState)(null),[se,ce]=(0,Q.useState)(!1),[z,ue]=(0,Q.useState)([]),[de,fe]=(0,Q.useState)(!1),[pe,me]=(0,Q.useState)(!1),[ge,_e]=(0,Q.useState)(null),[ve,ye]=(0,Q.useState)(!1),B=(0,Q.useRef)(null),V=(0,Q.useRef)(null),Ce=(0,Q.useRef)(null),[we,Ee]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=Ce.current;if(!e)return;let t=new ResizeObserver(t=>{let n=t[0]?.contentRect.width??e.clientWidth;Ee(n<Gn)});return t.observe(e),()=>t.disconnect()},[]);let{isGenerating:U}=et(),W=et(e=>e.preferences.generationOptions),ke=et(e=>e.preferences.imageGenSettings?.enabled===!0),Ae=ke&&ve,{currentSession:G,models:K}=O(),je=et(e=>G?.model?e.preferences.modelGenerationOptions?.[G.model]:void 0),q=G?.id,[Me,Ne]=(0,Q.useState)(q);Me!==q&&(Ne(q),te([]));let Fe=(0,Q.useRef)(null),Ie=(0,Q.useRef)(null),J=(0,Q.useMemo)(()=>({model:G?.personaId?`persona:${G.personaId}`:G?.model||``,providerType:G?.providerType,providerId:G?.providerId}),[G?.model,G?.personaId,G?.providerId,G?.providerType]),Le=(0,Q.useMemo)(()=>g(K,J),[K,J]),Re=J.model?E(Le,J):``,ze=b(K,J);(0,Q.useEffect)(()=>{let e=!1;return ke&&(async()=>{try{let t=await Ve.getPlugins();if(e)return;ye(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ye(!1)}})(),()=>{e=!0}},[ke]),(0,Q.useEffect)(()=>{if(!v)return;let e=e=>{B.current&&!B.current.contains(e.target)&&(x(!1),L(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[v]);let X=()=>{x(!1),L(null),ce(!1)};(0,Q.useEffect)(()=>{if(!se)return;let e=!1;return Be.getCollections().then(t=>{!e&&t.success&&t.data&&ue(t.data)}).catch(()=>{}),()=>{e=!0}},[se]);let Ue=G?.settings?.generationOptions?.think,We=je?.think??W?.think??null,Ge=(0,Q.useMemo)(()=>K.find(e=>e.name===G?.model),[K,G?.model]),[Ke,qe]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=G?.model;if(!e||K.length===0||!Ge||Ge.isPlugin||Ge.isAgent)return;let t=!1;return Qe.getModelDefaults(e).then(n=>{!t&&n.success&&n.data&&qe({model:e,supportsThinking:n.data.supportsThinking,options:n.data.options??{},trainedContextLength:n.data.trainedContextLength,contextCapped:n.data.contextCapped})}).catch(()=>{}),()=>{t=!0}},[Ge,G?.model,K.length]);let Ye=Ke?.model===G?.model?Ke:null,Xe=Ye?.supportsThinking,Ze=!!(G&&!Ge?.isAgent&&(Ge?.isPlugin?Ge.reasoningSupport!==!1:Xe!==!1)),$e=T({model:Ge,sessionOptions:G?.settings?.generationOptions,pinnedOptions:je,modelDefaults:Ye?.options,globalOptions:W}),tt=O(e=>e.contextWindowMessages),nt=(0,Q.useMemo)(()=>D({messages:G?.messages??[],budget:$e,systemPrompt:ge?.parameters?.system_prompt,windowMessages:tt}),[$e,tt,ge,G?.messages]),rt=async e=>{if(!G)return;let t={...G.settings?.generationOptions??{}};e===null?delete t.think:t.think=e;let n={...G.settings,generationOptions:t};if(O.setState(e=>({currentSession:e.currentSession?.id===G.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===G.id?{...e,settings:n}:e)})),!G.isPrivate)try{await Y.updateSession(G.id,{settings:n})}catch(e){Wn.error(`Failed to update the thinking setting:`,e)}},it=G?.settings?.knowledgeCollectionIds??[],at=async e=>{if(!G)return;let t=it.includes(e)?it.filter(t=>t!==e):[...it,e],n={...G.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(O.setState(e=>({currentSession:e.currentSession?.id===G.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===G.id?{...e,settings:n}:e)})),!G.isPrivate)try{await Y.updateSession(G.id,{settings:n})}catch(e){Wn.error(`Failed to update knowledge collections:`,e),A.error(a(`chat.input.menu.attachFailed`))}},ot=kt({onStart:()=>{c.current=o},onText:e=>{let t=c.current;s(t?`${t} ${e}`:e)},ownerKey:q}),st=ot.phase===`starting`,ct=ot.phase===`recording`,lt=ot.phase===`transcribing`,ut=ot.supported,dt=ot.providerModel,ft=ot.sources.filter(e=>e.kind===`provider`),pt=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){X(),me(!0);try{let e=await Be.uploadDocument(t,G?.id);e.success?(A.success(a(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):A.error(e.error||a(`chat.input.menu.attachFailed`))}catch(e){Wn.error(`Document upload failed:`,e),A.error(a(`chat.input.menu.attachFailed`))}finally{me(!1)}}},ht=async()=>{let e=I?.trim();if(e&&!de){fe(!0);try{let t=await Be.fetchWebpage(e,G?.id);t.success?(A.success(a(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),X()):A.error(t.error||a(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.input.menu.attachFailed`);Wn.error(`Webpage attach failed:`,e),A.error(t)}finally{fe(!1)}}},gt=async e=>{if(q&&!F)try{let t=await Y.enqueuePrompt(q,e);t.success&&t.data?(mt(q,t.data.queue),s(``)):A.error(t.error||a(`chat.queue.enqueueFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.queue.enqueueFailed`);Wn.error(`Failed to queue the prompt:`,e),A.error(t)}},_t=t=>{if(t.preventDefault(),!o.trim())return;if(U){u.length===0&&!F&&q&&gt(o.trim());return}if(!ze){A.error(a(`chat.model.selectBeforeSending`));return}let n=F?{}:Un(re),r=F?[]:jn(K,ee);e(o.trim(),u.length>0?u:void 0,f||void 0,S&&M?!0:void 0,n.tools,n.toolSelection,r.length>0?r:void 0),s(``),d([])},vt=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||Ie.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),_t(e))},bt=()=>{t()};(0,Q.useEffect)(()=>{let e=Fe.current;e&&(e.style.height=`auto`,e.style.height=o?`${Math.min(e.scrollHeight,200)}px`:``)},[o]),(0,Q.useEffect)(()=>{(async()=>{if(G?.personaId)try{let e=await Je.getPersona(G.personaId);if(e.success&&e.data)_e(e.data);else{Wn.warn(`Persona ${G.personaId} not found, clearing reference`),_e(null);let{setCurrentSession:e}=O.getState();e({...G,personaId:void 0})}}catch(e){if(Wn.error(`Failed to load current persona:`,e),_e(null),G){let{setCurrentSession:e}=O.getState();e({...G,personaId:void 0})}}else _e(null)})()},[G?.personaId]);let xt=async e=>{let t=k(Le,e.target.value);if(t&&G)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await Je.getPersona(e);if(!n.success||!n.data){A.error(a(`chat.persona.loadFailed`));return}let r=await Y.updateSession(G.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(r.success&&r.data){let{sessions:e}=O.getState(),t=e.map(e=>e.id===G.id?r.data:e);O.setState({sessions:t,currentSession:r.data}),A.success(a(`chat.persona.applied`))}}else{let e=await Y.updateSession(G.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}=O.getState(),n=t.map(t=>t.id===G.id?e.data:t);O.setState({sessions:n,currentSession:e.data}),A.success(a(`chat.model.updated`))}}}catch(e){Wn.error(`Failed to update session:`,e),A.error(a(`chat.toasts.updateFailed`))}},St=u.length>0||f!==null;return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{ref:Ce,className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[h&&(0,$.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/90`,children:[(0,$.jsx)(vn,{images:u,onImagesChange:d,maxImages:5,sessionId:G?.id,disabled:i}),(0,$.jsx)(Cn,{format:f,onFormatChange:p})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[q&&!F&&(G?.settings?.promptQueue?.length??0)>0&&(0,$.jsx)(An,{sessionId:q,queue:G.settings.promptQueue}),q&&ne.some(e=>e.sessionId===q)&&(0,$.jsx)(`div`,{className:`mx-auto mb-1.5 flex w-full max-w-3xl flex-wrap gap-1.5 px-1`,"data-testid":`pending-comparisons`,children:ne.filter(e=>e.sessionId===q).map(e=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-2.5 py-1 text-[12px] text-gray-600 dark:border-white/[0.08] dark:bg-dark-200/70 dark:text-dark-700`,"data-testid":`pending-comparison`,children:[(0,$.jsx)(ae,{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)(H,{className:`h-3 w-3`})})]},e.assistantMessageId))}),(0,$.jsx)(`form`,{onSubmit:_t,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:At,children:[(0,$.jsx)(zn,{ref:Ie,message:o,disabled:i,onApply:e=>{s(e),Fe.current?.focus()}}),(0,$.jsx)(gn,{ref:Fe,value:o,onChange:e=>s(e.target.value),onKeyDown:vt,placeholder:a(`chat.input.placeholder`),disabled:i,className:`!m-0 block w-full min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-2 !pt-1.5 !pb-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(`div`,{ref:B,className:`relative flex-shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(h){_(!1);return}x(e=>!e),L(null)},className:m(`h-9 w-9 !p-0 rounded-full flex-shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay`,`transition-colors duration-150 touch-manipulation`,St&&`text-primary-600 dark:text-primary-400`,(h||v)&&`bg-hover-solid text-ink`),title:a(`chat.input.attachments`),children:pe||de?(0,$.jsx)(ae,{className:`h-4 w-4 animate-spin`}):St?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Te,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):h?(0,$.jsx)(le,{className:`h-4 w-4`}):(0,$.jsx)(xe,{className:`h-4 w-4`})}),v&&(0,$.jsx)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 w-64 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:se?(0,$.jsxs)(`div`,{className:`p-1`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:a(`chat.input.menu.attachKnowledge`)}),z.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-ink-subtle`,children:a(`chat.input.menu.noCollections`)}):z.map(e=>{let t=it.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void at(e.id),className:m(`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)(be,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(R,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>ce(!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`)})]}):I===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{_(!0),X()},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)(ie,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.uploadImages`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>V.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)(he,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>L(``),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(Pe,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ce(!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)(be,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachKnowledge`)]}),it.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:it.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{_(!0),X()},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`)]}),we&&S&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{N(e=>!e),X()},className:m(`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`,M&&`text-primary-600 dark:text-primary-400`),"aria-pressed":M,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(Pe,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(M?`chat.input.webSearchOn`:`chat.input.webSearchOff`)]}),M&&(0,$.jsx)(R,{className:`h-3.5 w-3.5 shrink-0`})]}),we&&ut&&r&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{yt(),r(),X()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(De,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`voiceMode.open`)]})]}):(0,$.jsxs)(`div`,{className:`p-1.5`,children:[(0,$.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:a(`chat.input.menu.attachWebpage`)}),(0,$.jsx)(`input`,{type:`url`,value:I,onChange:e=>L(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),ht()):e.key===`Escape`&&L(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>L(null),className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:a(`common.cancel`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void ht(),disabled:!I.trim()||de,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white hover:bg-gray-700 disabled:opacity-50 dark:bg-dark-300 dark:hover:bg-dark-400`,children:de?(0,$.jsx)(ae,{className:`h-3.5 w-3.5 animate-spin`}):a(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:V,type:`file`,accept:Nn,className:`hidden`,onChange:e=>void pt(e)})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-1 sm:gap-1.5`,children:[Ze&&(0,$.jsx)(wn,{value:Ue,inheritedValue:We,onChange:e=>void rt(e)}),S&&!we&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>N(e=>!e),className:m(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,M&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:a(M?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":M,children:(0,$.jsx)(Pe,{className:`h-4 w-4`})}),!F&&(0,$.jsx)(Vn,{value:re,onChange:P}),!F&&G&&!we&&(0,$.jsx)(Mn,{models:K,currentModelKey:y({model:G.personaId?`persona:${G.personaId}`:G.model,providerType:G.providerType??null,providerId:G.providerId??null}),selectedKeys:ee,onChange:te,disabled:i}),ft.length>0&&!we&&(0,$.jsx)(`select`,{value:ot.activeSourceKey,onChange:e=>ot.setSourceKey(e.target.value),disabled:st||ct||lt,"aria-label":a(`chat.input.transcriptionSource`),title:dt?a(`chat.input.providerTranscriptionDisclosure`,{provider:dt.plugin}):a(`chat.input.transcriptionSource`),className:`h-8 max-w-32 rounded-lg border border-black/[0.08] bg-transparent px-1.5 text-[11px] text-gray-500 outline-none focus:border-primary-500/40 dark:border-white/[0.09] dark:text-dark-600`,children:ot.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))}),ut&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void ot.toggle(),className:m(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,(st||ct||lt)&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:lt||st?a(`common.cancel`):ct?a(`chat.input.voiceStop`):dt?a(`chat.input.providerTranscriptionDisclosure`,{provider:dt.plugin}):a(`chat.input.voiceInput`),"aria-pressed":st||ct||lt,children:st?(0,$.jsx)(ae,{className:`h-4 w-4 animate-spin`}):lt?(0,$.jsx)(oe,{className:`h-4 w-4`}):(0,$.jsx)(j,{className:`h-4 w-4`})}),ut&&r&&!we&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{yt(),r()},className:m(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`),title:a(`voiceMode.open`),"aria-label":a(`voiceMode.open`),"data-testid":`voice-mode-open`,children:(0,$.jsx)(De,{className:`h-4 w-4`})}),G&&(0,$.jsx)(On,{usage:nt,trainedBudget:Ye?.contextCapped?Ye.trainedContextLength:void 0}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),G&&Le.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Ot,{models:Le,selectedModel:Re,onModelChange:xt,getModelValue:C,currentPersona:ge,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:Ae})}),U?(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:bt,className:m(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:a(`chat.input.stopGeneration`),children:(0,$.jsx)(oe,{className:`h-4 w-4`})}):(0,$.jsx)(Z,{type:`submit`,variant:`primary`,size:`sm`,disabled:!o.trim()||i||!ze,className:jt,title:a(`chat.input.sendMessage`),children:(0,$.jsx)(Se,{className:`h-4 w-4`})})]})]})]})}),dt&&(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:dt.plugin})}),G&&Le.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(Ot,{models:Le,selectedModel:Re,onModelChange:xt,getModelValue:C,currentPersona:ge,className:`w-full`,compact:!0,showImageGen:Ae})}),(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)(bn,{sessionId:G?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:a(`chat.footer.disclaimer`)}),St&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,u.length>0&&a(`chat.footer.images`,{count:u.length}),u.length>0&&f&&` • `,f&&a(`chat.footer.structuredOutput`)]})]})]})]})]})})},qn={phase:`idle`,muted:!1,turn:0,error:null},Jn=e=>({...e,phase:`listening`,turn:e.turn+1});function Yn(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`}:Jn(e):e;case`reply`:return e.phase===`generating`?t.speak?{...e,phase:`speaking`}:Jn(e):e;case`spoken`:case`barge-in`:return e.phase===`speaking`?Jn(e):e;case`fail`:return e.phase===`idle`?e:{...Jn(e),error:t.message}}}var Xn=c(`utils:voice-mode-controller`),Zn=.015,Qn=200,$n=1500,er=6e4,tr=300,nr=18e4,rr=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},ir=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},ar=class{options;state=qn;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([Ze.getModels().catch(()=>({success:!1,data:[]})),Ue.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=>!!ir(e)),i=!!r&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia,a=!!rr();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){Xn.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=Yn(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){Xn.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=rr();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=ir(t);if(!n){this.fail(e,this.options.messages.microphoneFailed);return}try{let t=await this.ensureStream();if(this.staleTurn(e))return;this.chunks=[];let r=new MediaRecorder(t,{mimeType:n});this.recorder=r,r.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},r.onstop=()=>{if(this.staleTurn(e)&&this.state.phase!==`transcribing`)return;let t=new Blob(this.chunks,{type:n});if(this.chunks=[],t.size===0){this.handleTranscript(e,``);return}this.transcribeRecording(e,t)},r.start();let i=0,a=0,o=!1,s=Date.now();this.clearMonitor(),this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearMonitor();return}if(this.state.muted){i=0,a=0;return}this.analyser&&(this.rmsLevel()>Zn?(i+=50,a=0,i>=Qn&&(o=!0)):(i=0,o&&(a+=50))),(o&&a>=$n||Date.now()-s>=er)&&this.finishProviderCapture(e)},50)}catch(t){Xn.warn(`Voice mode microphone failed:`,t),this.fail(e,this.options.messages.microphoneFailed)}}finishProviderCapture(e){this.staleTurn(e)||(this.clearMonitor(),this.send({type:`captured`}).phase===`transcribing`&&this.stopRecorder())}transcribeRecording(e,t){let n=this.sttModel;if(!n){this.fail(e,this.options.messages.transcriptionFailed);return}let r=new AbortController;this.abortController=r,Ze.transcribe(t,n,{language:this.options.locale?.split(`-`)[0],signal:r.signal}).then(t=>this.handleTranscript(e,t.text??``)).catch(t=>{r.signal.aborted||(Xn.warn(`Voice mode transcription failed:`,t),this.fail(e,this.options.messages.transcriptionFailed))})}handleTranscript(e,t){if(this.staleTurn(e))return;let n=this.send({type:`transcript`,text:t});n.phase===`generating`?this.startGeneration(n.turn,t.trim()):n.phase===`listening`&&this.beginTurn(n.turn)}startGeneration(e,t){this.options.onTranscript(t);let n=this.options.snapshot().lastAssistantMessage?.id??null,r=!1,i=Date.now();this.options.sendMessage(t),this.clearPoll(),this.pollTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearPoll();return}let t=this.options.snapshot(),a=t.lastAssistantMessage,o=a!==null&&a.id!==n;if((t.isStreaming||o)&&(r=!0),r&&!t.isStreaming&&o){this.clearPoll();let t=this.ttsModels.length>0&&a.content.trim()!==``,n=this.send({type:`reply`,speak:t});n.phase===`speaking`?this.speakReply(e,a.content):n.phase===`listening`&&this.beginTurn(n.turn);return}Date.now()-i>nr&&(this.clearPoll(),this.fail(e,this.options.messages.replyTimeout))},250)}speakReply(e,t){let n=this.options.snapshot().ttsSettings,r=qe(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=vt(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=gt({concurrency:3,initialBufferSize:Math.min(2,l.length),generate:(e,{signal:t})=>Ue.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=bt(u);this.startBargeInMonitor(e,u),u.play(l).then(()=>{this.staleTurn(e)||this.finishSpeaking(e)}).catch(t=>{this.staleTurn(e)||ht(t)||(Xn.warn(`Voice mode speech failed:`,t),this.finishSpeaking(e))}).finally(()=>{d(),this.ttsSession===u&&(this.ttsSession=null)})}startBargeInMonitor(e,t){if(!this.analyser)return;this.clearMonitor();let n=0;this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)||this.state.muted){n=0;return}if(this.rmsLevel()>Zn){if(n+=50,n>=tr){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)}},or=({onClose:e,onSendMessage:t,isStreaming:n,lastAssistantMessage:r})=>{let{t:i,i18n:a}=l(),{preferences:o}=et(),[s,c]=(0,Q.useState)(qn),[u,d]=(0,Q.useState)(``),[f,p]=(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 ar({locale:a.language,sendMessage:e=>t(e),snapshot:()=>g.current,onState:e=>c(e),onTranscript:e=>d(e),onSupport:e=>p(e),messages:{microphoneFailed:i(`voiceMode.microphoneFailed`),transcriptionFailed:i(`voiceMode.transcriptionFailed`),replyTimeout:i(`voiceMode.replyTimeout`)}});return h.current=e,e.start(),()=>{h.current=null,e.close()}},[]);let _=s.phase,v=f===!1?`voiceMode.unsupported`:_===`listening`?s.muted?`voiceMode.muted`:`voiceMode.listening`:_===`transcribing`?`voiceMode.transcribing`:_===`generating`?`voiceMode.generating`:_===`speaking`?`voiceMode.speaking`:`voiceMode.starting`;return(0,Mt.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":i(`voiceMode.title`),className:`fixed inset-0 z-[70] flex flex-col items-center justify-center gap-6 bg-white/95 p-6 backdrop-blur dark:bg-dark-25/95`,"data-testid":`voice-mode-overlay`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e,"aria-label":i(`voiceMode.close`),className:`absolute right-4 top-4 rounded-full p-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-dark-100`,children:(0,$.jsx)(H,{className:`h-5 w-5`})}),(0,$.jsx)(`div`,{className:m(`flex h-28 w-28 items-center justify-center rounded-full border-4 transition-colors`,_===`listening`&&!s.muted?`border-primary-500 text-primary-500`:_===`speaking`?`border-emerald-500 text-emerald-500`:_===`generating`||_===`transcribing`?`border-amber-500 text-amber-500`:`border-gray-300 text-gray-400 dark:border-dark-300`),children:_===`transcribing`||_===`generating`?(0,$.jsx)(ae,{className:`h-10 w-10 animate-spin`}):s.muted?(0,$.jsx)(Le,{className:`h-10 w-10`}):_===`speaking`?(0,$.jsx)(De,{className:`h-10 w-10`}):(0,$.jsx)(j,{className:`h-10 w-10`})}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`text-base font-medium text-gray-900 dark:text-gray-100`,"data-testid":`voice-mode-status`,children:i(v)}),s.error&&(0,$.jsx)(`p`,{className:`mt-1 text-sm text-red-600 dark:text-red-400`,children:s.error}),u&&(0,$.jsxs)(`p`,{className:`mt-3 max-w-md text-sm text-gray-600 dark:text-gray-300`,children:[`“`,u,`”`]})]}),f!==!1&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.toggleMute(),"aria-label":s.muted?i(`voiceMode.unmute`):i(`voiceMode.mute`),"aria-pressed":s.muted,className:`rounded-full border border-gray-300 p-3 text-gray-700 hover:bg-gray-100 dark:border-dark-300 dark:text-gray-300 dark:hover:bg-dark-100`,children:s.muted?(0,$.jsx)(Le,{className:`h-5 w-5`}):(0,$.jsx)(j,{className:`h-5 w-5`})}),_===`listening`&&!s.muted&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.finishTurn(),"aria-label":i(`voiceMode.finishTurn`),className:`rounded-full border border-primary-500 p-3 text-primary-600 hover:bg-primary-50 dark:hover:bg-primary-950/30`,children:(0,$.jsx)(R,{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)(N,{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)},sr=c(`components:chat-controls-panel`),cr=[{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`}],lr=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i}=l(),a=O(e=>e.draftSessionSettings),o=O(e=>e.setDraftSessionSettings),s=e?.model??t??``,c=et(e=>e.preferences.generationOptions),d=et(e=>e.preferences.modelGenerationOptions?.[s]),[f,p]=(0,Q.useState)({options:{},contextCapped:!1});(0,Q.useEffect)(()=>{if(!n||!s)return;let e=!1;return Qe.getModelDefaults(s).then(t=>{!e&&t.success&&t.data&&p({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,s]);let m=(0,Q.useMemo)(()=>({...c??{},...f.options,...d??{}}),[c,f.options,d]),h=(0,Q.useMemo)(()=>e?.messages.find(e=>e.role===`system`&&!_(e.content)),[e?.messages]),[g,v]=(0,Q.useState)(h?.content??a.systemPrompt??``),[y,b]=(0,Q.useState)(e?.settings?.generationOptions??a.generationOptions??{}),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(e?.settings?.compaction!==!1),[T,E]=(0,Q.useState)(e?.id??`draft`),D=e?.id??`draft`;T!==D&&(E(D),v(h?.content??a.systemPrompt??``),b(e?.settings?.generationOptions??a.generationOptions??{}),w(e?.settings?.compaction!==!1));let k=e=>{b(t=>{let n={...t},r=St(e);return r===null?delete n.think:n.think=r,n})},A=(e,t)=>{b(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},j=async()=>{S(!0);try{let t=g.trim(),n=h?.content??``,a=Object.fromEntries(Object.entries(y).filter(([,e])=>e!==void 0)),s=e?{...e.settings,generationOptions:a}:Object.keys(a).length>0?{generationOptions:a}:void 0;if(s&&e&&(C?delete s.compaction:s.compaction=!1),!e){o({systemPrompt:t||void 0,generationOptions:s?.generationOptions}),J.success(i(`chat.controls.saved`)),r();return}let c=e.messages;if(t!==n.trim()&&(h?c=t?e.messages.map(e=>e.id===h.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==h.id):t&&(c=[{id:u(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)O.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:c,settings:s}:t.currentSession}));else{let t=await Y.updateSession(e.id,{messages:c,settings:s});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;O.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}J.success(i(`chat.controls.saved`)),r()}catch(e){sr.error(`Failed to save chat controls:`,e),J.error(i(`chat.controls.saveFailed`))}finally{S(!1)}};return n?(0,$.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:`flex h-full w-[21rem] shrink-0 flex-col border-s border-black/[0.06] bg-surface/70 backdrop-blur-xl dark:border-white/[0.07] dark:bg-dark-100/70`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:i(`chat.controls.title`)}),(0,$.jsx)(`button`,{onClick:r,className:`rounded-full p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-900`,title:i(`common.close`),children:(0,$.jsx)(H,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.systemPrompt`)}),(0,$.jsx)(`textarea`,{dir:`auto`,value:g,onChange:e=>v(e.target.value),placeholder:i(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/[0.08] bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-think`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.thinking`)}),(0,$.jsx)(`select`,{id:`chat-control-think`,value:wt(y.think),onChange:e=>k(e.target.value),className:`w-full rounded-xl border border-black/[0.08] bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`,children:Tt.map(e=>(0,$.jsx)(`option`,{value:e,children:e==="default"&&m.think!==void 0&&m.think!==null?i(`settings.generation.thinkingLevels.defaultWith`,{level:i(`settings.generation.thinkingLevels.${wt(m.think)}`)}):i(`settings.generation.thinkingLevels.${e}`)},e))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.thinkingDescription`)})]}),e&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-compaction`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.compaction`)}),(0,$.jsxs)(`select`,{id:`chat-control-compaction`,value:C?`default`:`off`,onChange:e=>w(e.target.value!==`off`),className:`w-full rounded-xl border border-black/[0.08] bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`,children:[(0,$.jsx)(`option`,{value:`default`,children:i(`chat.controls.compactionDefault`)}),(0,$.jsx)(`option`,{value:`off`,children:i(`chat.controls.compactionOff`)})]}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.compactionDescription`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.advancedParams`)}),(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.advancedParamsDescription`)}),f.contextCapped&&f.trainedContextLength&&(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-500 dark:text-dark-600`,children:i(`chat.controls.contextCapped`,{context:m.num_ctx?.toLocaleString(),trained:f.trainedContextLength.toLocaleString()})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:cr.map(e=>{let t=y[e.key],n=m[e.key],r=f.options[e.key]!==void 0&&d?.[e.key]===void 0;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`label`,{htmlFor:`chat-control-${e.key}`,className:`text-[13px] text-gray-700 dark:text-dark-700`,children:[i(`chat.controls.params.${e.labelKey}`),r&&(0,$.jsx)(`span`,{title:i(`chat.controls.fromModelHint`),className:`ms-1.5 text-[10px] uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:i(`chat.controls.fromModel`)})]}),(0,$.jsx)(`input`,{id:`chat-control-${e.key}`,type:`number`,inputMode:`decimal`,step:e.step,min:e.min,max:e.max,value:typeof t==`number`?t:``,placeholder:typeof n==`number`?String(n):i(`common.default`),onChange:t=>A(e.key,t.target.value),className:`w-24 rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-black/[0.06] px-4 py-3 dark:border-white/[0.07] lg:pb-16`,children:[(0,$.jsx)(`button`,{onClick:()=>{b({}),v(h?.content??``)},className:`text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:i(`common.reset`)}),(0,$.jsx)(Z,{onClick:()=>void j(),size:`sm`,disabled:x,children:i(x?`common.saving`:`common.save`)})]})]}):null},ur=c(`components:chat-sources-panel`),dr=6,fr=[],pr=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}},mr=({session:e})=>{let{t}=l(),[n,r]=(0,Q.useState)({sessionId:``,docs:fr}),i=!e.isPrivate&&n.sessionId===e.id?n.docs:fr,[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),{webSources:f,ragSources:p,fullContextSkipped:m}=(0,Q.useMemo)(()=>{let t=new Map,n=new Map,r;for(let i of e.messages){let e=i.providerMetadata;if(Array.isArray(e?.webSearchSources))for(let n of e.webSearchSources){let e=n;e&&typeof e.url==`string`&&e.url&&t.set(e.url,{url:e.url,title:typeof e.title==`string`&&e.title?e.title:e.url})}if(Array.isArray(e?.ragSources))for(let t of e.ragSources){let e=t;e&&typeof e.id==`string`&&e.id&&n.set(e.id,{id:e.id,filename:typeof e.filename==`string`&&e.filename?e.filename:e.id,...Array.isArray(e.citations)?{citations:e.citations.filter(e=>!!e&&typeof e==`object`&&typeof e.chunkIndex==`number`)}:{},...e.full===!0?{full:!0}:{}})}let a=e?.ragFullContextSkipped;a&&typeof a.estimatedTokens==`number`&&typeof a.maxTokens==`number`?r={estimatedTokens:a.estimatedTokens,maxTokens:a.maxTokens}:e?.ragSources&&(r=void 0)}return{webSources:Array.from(t.values()),ragSources:Array.from(n.values()),fullContextSkipped:r}},[e.messages]);(0,Q.useEffect)(()=>{if(e.isPrivate)return;let t=!1,n=()=>{Be.getDocuments(e.id).then(n=>{!t&&n.success&&Array.isArray(n.data)&&r({sessionId:e.id,docs:n.data.map(e=>({id:e.id,filename:e.filename,contentChars:e.contentChars}))})}).catch(()=>{})};return n(),window.addEventListener(`libre:documents-updated`,n),()=>{t=!0,window.removeEventListener(`libre:documents-updated`,n)}},[e.id,e.isPrivate]);let h=(0,Q.useMemo)(()=>{let e=new Map;for(let t of i)e.set(t.id,{...t,used:!1});for(let t of p)e.set(t.id,{...e.get(t.id)??{},id:t.id,filename:t.filename,used:!0,...t.citations?.length?{citations:t.citations}:{},...t.full?{full:!0}:{}});return Array.from(e.values())},[i,p]),g=e.settings?.fullDocumentContext===!0,_=(0,Q.useMemo)(()=>i.reduce((e,t)=>e+Math.ceil((t.contentChars??0)/4),0),[i]),v=async()=>{let t={...e.settings,fullDocumentContext:!g||void 0};if(O.setState(n=>({currentSession:n.currentSession?.id===e.id?{...n.currentSession,settings:t}:n.currentSession,sessions:n.sessions.map(n=>n.id===e.id?{...n,settings:t}:n)})),!e.isPrivate)try{await Y.updateSession(e.id,{settings:t})}catch(e){ur.error(`Failed to update the full-document setting:`,e)}},y=e=>{let t=[];for(let n of e){let e=n.location??`#${n.chunkIndex+1}`;if(t.includes(e)||t.push(e),t.length>=4)break}return t.join(` · `)};if(f.length===0&&h.length===0)return null;let b=a?f:f.slice(0,dr),x=s?h:h.slice(0,dr),S=(e,n,r)=>(e>0||n)&&(0,$.jsx)(`button`,{type:`button`,onClick:r,className:`mt-1 flex items-center gap-1 px-1 text-[12px] text-gray-400 transition-colors hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,children:n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{className:`h-3 w-3`}),t(`chatMessage.showLess`,`Show less`)]}):`${t(`chatMessage.showMore`)} (${e})`}),C=(0,$.jsxs)($.Fragment,{children:[f.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:b.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`group -mx-1 flex items-center gap-2.5 rounded-lg px-1 py-1.5 transition-colors hover:bg-black/[0.04] dark:hover:bg-white/[0.05]`,title:e.url,children:[(0,$.jsx)(Pe,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-700 dark:text-dark-500 dark:group-hover:text-dark-800`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.title}),(0,$.jsx)(`span`,{dir:`ltr`,className:`block truncate text-[11px] text-gray-400 dark:text-dark-500`,children:pr(e.url)})]})]})},e.url))}),S(f.length-b.length,a,()=>o(e=>!e))]}),h.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`settings.tabs.documents`,`Documents`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:x.map(e=>(0,$.jsxs)(`li`,{className:`-mx-1 rounded-lg px-1 py-1.5`,title:e.filename,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(he,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.filename}),e.used&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-primary-500`})]}),e.full?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-gray-400 dark:text-dark-500`,"data-testid":`chat-source-citation`,children:t(`documents.fullDocument`,`Full document`)}):e.citations?.length?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-gray-400 dark:text-dark-500`,"data-testid":`chat-source-citation`,children:y(e.citations)}):null]},e.id))}),S(h.length-x.length,s,()=>c(e=>!e)),(0,$.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-center gap-2 px-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:g,onChange:v,"data-testid":`full-document-context-toggle`,className:`h-3.5 w-3.5 rounded border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[t(`documents.fullContextToggle`,`Send full documents`),g&&_>0&&(0,$.jsx)(`span`,{className:`ms-1 text-gray-400 dark:text-dark-500`,children:t(`documents.fullContextEstimate`,{tokens:_.toLocaleString()})})]})]}),g&&m&&(0,$.jsx)(`p`,{className:`mt-1 px-1 text-[11px] text-amber-600 dark:text-amber-400`,"data-testid":`full-document-context-warning`,children:t(`documents.fullContextTooLarge`)})]})]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`aside`,{"data-testid":`chat-sources-panel`,className:`hidden w-72 shrink-0 flex-col gap-7 overflow-y-auto border-s border-black/[0.05] px-5 py-6 scrollbar-thin dark:border-white/[0.06] xl:flex`,children:C}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),"data-testid":`chat-sources-trigger`,className:`absolute end-3 top-[4.25rem] z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 xl:hidden`,title:t(`chat.message.sources`,`Sources`),"aria-haspopup":`dialog`,"aria-expanded":u,children:[(0,$.jsx)(be,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`absolute -end-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white shadow-sm`,children:f.length+h.length})]}),u&&(0,Mt.createPortal)((0,$.jsxs)(`div`,{className:`fixed inset-0 z-[80] xl:hidden`,children:[(0,$.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/35 backdrop-blur-[2px]`,onClick:()=>d(!1),"aria-label":t(`common.close`)}),(0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":t(`chat.message.sources`,`Sources`),className:`absolute inset-x-3 bottom-3 max-h-[75vh] overflow-y-auto rounded-2xl border border-black/[0.08] bg-surface p-5 shadow-[0_20px_70px_rgba(0,0,0,0.3)] scrollbar-thin dark:border-white/[0.09] dark:bg-dark-100`,"data-testid":`chat-sources-sheet`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`rounded-md p-1.5 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":t(`common.close`),children:(0,$.jsx)(H,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:C})]})]}),document.body)]})},hr=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)({top:0,left:0});(0,Q.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect(),t=document.documentElement.dir===`rtl`?e.right-288:e.left;s({top:e.bottom+8,left:Math.min(window.innerWidth-288-8,Math.max(8,t))})}},[r]);let c=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),l=()=>Ke(e,64),u=t=>{X(t.currentTarget,e.name,64)};return(0,$.jsxs)(`div`,{className:m(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:m(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-md object-cover`,onError:u}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,$.jsx)(L,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(me,{className:m(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Mt.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:m(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,$.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,$.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 end-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,$.jsx)(H,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,$.jsxs)(`div`,{className:`absolute top-2 start-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,$.jsx)(_e,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,$.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:u})}),(0,$.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,$.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,$.jsx)(ue,{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)(M,{className:`h-2.5 w-2.5 text-gray-400`}),(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,$.jsx)(Ne,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,$.jsx)(_e,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},gr=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=l(),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)(!1),c=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){J.error(`File ${o.name} is not an image`);continue}if(o.size>10485760){J.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&J.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),s(!0)},d=e=>{e.preventDefault(),s(!1)},f=e=>{e.preventDefault(),s(!1),c(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},h=e.length<n;return(0,$.jsxs)(`div`,{className:m(`space-y-3`,r),children:[h&&(0,$.jsxs)(`div`,{className:m(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:u,onDragLeave:d,onDrop:f,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>c(e.target.files),className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(Ae,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,$.jsx)(H,{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)(ie,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},_r=c(`pages:chat-page`),vr=(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?`}},yr=(e,t,n,r=!1)=>{let i=nt(e);return i===`time`?vr(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},xr=()=>{let{t:e,i18n:t}=l(),{sessionId:n}=a(),r=i(),s=o(),{currentSession:c,sessions:d,models:f,selectedModel:p,selectedProviderType:_,selectedProviderId:y,setSelectedModel:x,createSession:S,setCurrentSession:w,loadSessions:T,getCurrentPersona:D}=O(),{user:A}=$e(),j=et(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:M,stopGeneration:N,cancelComparison:ee,regenerateLastMessage:te,editAndResendMessage:ne,selectBranch:re,isStreaming:P,streamingMessage:F,streamingThinking:ie,streamingMessageId:I,toolActivities:ae,activeToolCalls:L,pendingToolApproval:oe,decideToolApproval:ce}=ft(c?.id||``),R=D(),z=(0,Q.useMemo)(()=>({model:p,providerType:_,providerId:y}),[p,y,_]),ue=(0,Q.useMemo)(()=>g(f,z),[f,z]),de=p?E(ue,z):``,fe=b(f,z),pe=new URLSearchParams(s.search).get(`incognito`)===`1`,[me,he]=(0,Q.useState)(tt),[ge,_e]=(0,Q.useState)(null),[ve,ye]=(0,Q.useState)(!1),be=et(e=>e.preferences.showFollowUpSuggestions!==!1),B=(0,Q.useRef)(null),V=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=c?.id,t=V.current&&!P;if(V.current=P,!e||P||!be||c?.isPrivate||!t)return;let n=c.messages[c.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||B.current===n.id)return;B.current=n.id;let r=!1;return Y.generateFollowUps(e).then(t=>{!r&&t.success&&O.getState().currentSession?.id===e&&_e({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[P,c,be]);let Ce=ge&&ge.sessionId===c?.id?ge.suggestions:[],we=(0,Q.useMemo)(()=>yr(me,A?.username,e,h(t.language)),[t.language,e,A?.username,me]),[Ee,De]=(0,Q.useState)(``),[H,U]=(0,Q.useState)([]),[W,Oe]=(0,Q.useState)(!1),[ke,Ae]=(0,Q.useState)(!1),[G,K]=(0,Q.useState)(Hn),[Me,Ne]=(0,Q.useState)(!1),Fe=(0,Q.useRef)(null),Ie=O(e=>e.draftSessionSettings),Le=O(e=>e.setDraftSessionSettings),Re=Ie.generationOptions?.think,ze=et(e=>(p?e.preferences.modelGenerationOptions?.[p]?.think:void 0)??e.preferences.generationOptions?.think??null),X=(0,Q.useMemo)(()=>f.find(e=>e.name===p),[f,p]),[Ue,We]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!p||f.length===0||!X||X.isPlugin||X.isAgent)return;let e=!1;return Qe.getModelDefaults(p).then(t=>{!e&&t.success&&t.data&&We({model:p,supported:t.data.supportsThinking})}).catch(()=>{}),()=>{e=!0}},[p,X,f.length]);let Ge=!!(p&&!X?.isAgent&&(X?.isPlugin?X.reasoningSupport!==!1:Ue?.model!==p||Ue.supported!==!1)),Ke=e=>{let t=O.getState().draftSessionSettings,n={...t.generationOptions};e===null?delete n.think:n.think=e,Le({...t,generationOptions:Object.keys(n).length?n:void 0})},qe=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){Ne(!0);try{let t=await Be.uploadDocument(n);t.success?(J.success(e(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):J.error(t.error||e(`chat.input.menu.attachFailed`))}catch(t){_r.error(`Document upload failed:`,t),J.error(e(`chat.input.menu.attachFailed`))}finally{Ne(!1)}}};(0,Q.useEffect)(()=>{let e=!1;return He.getConfig().then(t=>{!e&&t.success&&t.data&&Oe(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[Je,Ye]=(0,Q.useState)(!1),Xe=(0,Q.useRef)(null),Ze=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{he(tt())};return window.addEventListener(rt,e),()=>window.removeEventListener(rt,e)},[]);let[nt,at]=(0,Q.useState)(!1),[ot,st]=(0,Q.useState)(!1),ct=br(c?.messages),ut=j&&nt,dt=(0,Q.useCallback)((t=!0)=>{let n=p?z:f[0]?v(f[0]):null;if(!n||!b(f,n))return t&&J.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return w({id:`private-${r}`,title:e(`chat.session.incognito`,`Incognito Chat`),model:n.model,providerType:n.providerType,providerId:n.providerId,messages:[],createdAt:r,updatedAt:r,isPrivate:!0}),!0},[f,p,z,w,e]);(0,Q.useEffect)(()=>{d.length===0&&T()},[T,d.length]),(0,Q.useEffect)(()=>{pe&&!c?.isPrivate&&dt(!1)},[c?.isPrivate,pe,dt]),(0,Q.useEffect)(()=>{let e=!1;return j&&(async()=>{try{let t=await Ve.getPlugins();if(e)return;at(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;at(!1)}})(),()=>{e=!0}},[j]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if((!c?.isPrivate||n)&&d.length!==0){if(n){let e=d.find(e=>e.id===n);e&&e.id!==c?.id?w(e):e||(_r.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&&s.pathname===`/`&&r(`/c/${d[0].id}`,{replace:!0})}})()},[n,d,w,r,c?.id,c?.isPrivate,s.pathname]),(0,Q.useEffect)(()=>{if(c?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{M(t.content,t.images,void 0,t.webSearch===!0,t.tools===!0,t.toolSelection)},100)}catch(e){_r.error(`Failed to parse pending message:`,e)}}}},[c?.id,M]),(0,Q.useEffect)(()=>{let e=Xe.current;e&&(e.style.height=`auto`,e.style.height=Ee?`${Math.min(e.scrollHeight,200)}px`:``)},[Ee]);let pt=async t=>{if(t.preventDefault(),!Ee.trim()||!p)return;if(!fe){J.error(e(`chat.model.selectBeforeSending`));return}it(`impact`);let n={content:Ee.trim(),images:H.length>0?H:void 0,webSearch:W&&ke?!0:void 0,...Un(G)};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),De(``),U([]),Ae(!1),K(Hn);let i=await S(p,void 0,p.startsWith(`persona:`)?p.slice(8):void 0,_,y);i&&(await mt(i),r(`/c/${i.id}`,{replace:!0}))},mt=(0,Q.useCallback)(async e=>{let t=O.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions;if(!n&&!r)return;let i=n?[{id:u(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await Y.updateSession(e.id,{messages:i,settings:r?{generationOptions:r}:void 0});if(t.success&&t.data){let e=t.data;O.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){_r.error(`Failed to apply chat settings to the new session`,e)}finally{O.getState().setDraftSessionSettings({})}},[]),ht=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||Ze.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),pt(e))},gt=async e=>{let t=k(ue,e.target.value);t&&x(t.model,t.providerType,t.providerId)},_t=(e,t,n,r,i,a,o)=>{c&&(it(`impact`),_e(null),M(e,t,n,r,i,a,o))},vt=c?.id,yt=(0,Q.useCallback)(async t=>{if(vt)try{let n=await Y.forkSession(vt,{messageId:t});if(n.success&&n.data){let t=n.data;O.setState(e=>({sessions:[t,...e.sessions]})),J.success(e(`chat.fork.created`)),r(`/c/${t.id}`)}else J.error(n.error||e(`chat.fork.failed`))}catch(t){_r.error(`Failed to fork the chat:`,t),J.error(e(`chat.fork.failed`))}},[vt,r,e]);if(!c){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:()=>ye(e=>!e),className:m(`absolute end-4 top-4 z-10 flex h-9 w-9 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-6 sm:top-6`,ve&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ve,children:(0,$.jsx)(se,{className:`h-4 w-4`})}),(0,$.jsxs)(`button`,{onClick:()=>dt(),disabled:!p&&f.length===0||!!p&&!fe,className:`absolute end-[3.75rem] top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-surface/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-[4.25rem] sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,$.jsx)(q,{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)(lt,{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:we.title})]}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-[15px] leading-relaxed text-ink-subtle`,children:we.subtitle})]},we.id),ue.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[Je&&(0,$.jsxs)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:[(0,$.jsx)(gr,{images:H,onImagesChange:U,maxImages:5}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 border-t border-black/[0.06] pt-3 dark:border-white/[0.07]`,children:[(0,$.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:e(`chat.input.menu.attachDocument`)}),(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:`outline`,disabled:Me,onClick:()=>Fe.current?.click(),className:`shrink-0 whitespace-nowrap`,children:[(0,$.jsx)(Te,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`ms-1.5`,children:e(Me?`documents.uploading`:`chat.input.menu.attach`)})]}),(0,$.jsx)(`input`,{ref:Fe,type:`file`,accept:Nn,className:`hidden`,onChange:e=>void qe(e)})]})]}),(0,$.jsx)(`form`,{onSubmit:pt,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:At,children:[(0,$.jsx)(zn,{ref:Ze,message:Ee,onApply:e=>{De(e),Xe.current?.focus()}}),(0,$.jsx)(gn,{ref:Xe,value:Ee,onChange:e=>De(e.target.value),onKeyDown:ht,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 block w-full min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-2 !pt-1.5 !pb-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Ye(!Je),className:m(`h-9 w-9 !p-0 rounded-full flex-shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,Je&&`bg-hover-solid text-ink`),title:e(`chat.input.attachImages`),children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Te,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):Je?(0,$.jsx)(le,{className:`h-4 w-4`}):(0,$.jsx)(xe,{className:`h-4 w-4`})}),Ge&&(0,$.jsx)(wn,{value:Re,inheritedValue:ze,onChange:Ke}),W&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Ae(e=>!e),className:m(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,ke&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:e(ke?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":ke,children:(0,$.jsx)(Pe,{className:`h-4 w-4`})}),(0,$.jsx)(Vn,{value:G,onChange:K,buttonClassName:`h-9 w-9`}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Ot,{models:ue,selectedModel:de,onModelChange:gt,getModelValue:C,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:ut})}),(0,$.jsx)(Z,{type:`submit`,variant:`primary`,size:`sm`,disabled:!Ee.trim()||!p||!fe,className:jt,title:e(`chat.input.sendMessage`),children:(0,$.jsx)(Se,{className:`h-4 w-4`})})]})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(Ot,{models:ue,selectedModel:de,onModelChange:gt,getModelValue:C,className:`w-full`,compact:!0,showImageGen:ut})}),(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)(xt,{variant:`inline`})]})]})]}),(0,$.jsx)(lr,{draftModel:p,open:ve,onClose:()=>ye(!1)})]})}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:R?.background?{backgroundImage:`url(${R.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[R?.background&&(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,$.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[c?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(q,{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`)]})]})}),R&&!c?.isPrivate&&(0,$.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,$.jsx)(hr,{persona:R,onClear:()=>{c&&Y.updateSession(c.id,{model:R.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);O.setState(t=>({sessions:t.sessions.map(t=>t.id===c.id?e.data:t),currentSession:e.data}))}).catch(t=>{_r.error(`Failed to remove persona:`,t),J.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:()=>ye(e=>!e),className:m(`absolute end-3 top-3 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950`,ve&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ve,children:(0,$.jsx)(se,{className:`h-3.5 w-3.5`})}),c.settings?.forkedFrom&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(`/c/${c.settings.forkedFrom.sessionId}`),className:`mx-auto mt-2 flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-3 py-1 text-[11px] text-gray-500 transition-colors hover:text-gray-800 dark:border-white/[0.08] dark:bg-dark-200/70 dark:text-dark-600 dark:hover:text-dark-900`,"data-testid":`forked-from-banner`,children:[(0,$.jsx)(je,{className:`h-3 w-3`}),e(`chat.fork.origin`,{title:c.settings.forkedFrom.title||e(`chat.fork.originUnknown`)})]}),(0,$.jsx)(mn,{messages:c.messages,streamingMessage:F,streamingThinking:ie,streamingMessageId:I,isStreaming:P,toolActivities:ae,activeToolCalls:L,pendingToolApproval:oe,onDecideToolApproval:ce,onRegenerate:te,onSelectBranch:re,onEditResend:ne,onFork:yt,followUpSuggestions:Ce,onFollowUpSelect:e=>_t(e),className:`flex-1`}),c?.shared?(0,$.jsx)(`div`,{className:`mx-auto mb-4 w-full max-w-3xl rounded-xl border border-black/[0.06] bg-black/[0.02] px-4 py-3 text-center text-[13px] text-gray-500 dark:border-white/[0.08] dark:bg-white/[0.03] dark:text-dark-600`,"data-testid":`chat-shared-readonly`,children:e(`chat.sharedReadOnly`,{owner:c.shared.ownerUserId})}):(0,$.jsx)(Kn,{onSendMessage:_t,onStopGeneration:N,onCancelComparison:ee,onOpenVoiceMode:()=>st(!0),disabled:!c})]}),ot&&c&&(0,$.jsx)(or,{onClose:()=>st(!1),onSendMessage:e=>_t(e),isStreaming:P,lastAssistantMessage:ct}),(0,$.jsx)(mr,{session:c}),(0,$.jsx)(lr,{session:c,open:ve,onClose:()=>ye(!1)})]})]})]})};export{xr as ChatPage,xr as default};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-wiHys0m2.js";import{t as r}from"./logger-BR4forr_.js";import{t as i}from"./useTranslation-B9kflK9S.js";import{t as a}from"./utils-p8Gt72YP.js";import{t as o}from"./chatStore-DQhEqb9F.js";import{$ as s,An as c,Cr as l,Ln as u,Qn as d,U as ee,Wt as f,Yn as p,Z as m,nt as h}from"./ui-vendor-BhHHyHk3.js";import{u as g,y as _}from"./api-CVUaOaq4.js";import{t as v}from"./authStore-C5qKrmn4.js";import{t as y}from"./Button-CGMYia4g.js";import"./ui-DDMjO5dd.js";var b=e(t(),1),x=n(),S=r(`components:connect-models`),C=[{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`}],w=[{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`}],T=({variant:e=`setup`,onDone:t})=>{let{t:n}=i(),{user:r,systemInfo:T}=v(),E=o(e=>e.loadModels),D=r?.role===`admin`||T?.requiresAuth===!1,[O,k]=(0,b.useState)(()=>T?.ollamaEnabled===!1?`disabled`:`checking`),[A,j]=(0,b.useState)(null),[M,N]=(0,b.useState)(C[0]),[P,F]=(0,b.useState)(C[0].baseUrl),[I,L]=(0,b.useState)(``),[R,z]=(0,b.useState)(!1),[B,V]=(0,b.useState)(null),[H,U]=(0,b.useState)(!1),[W,G]=(0,b.useState)(null),[K,q]=(0,b.useState)(``),[J,Y]=(0,b.useState)(!1),X=(0,b.useCallback)(async()=>{try{let e=await _.checkHealth();e.success&&e.data?.status===`disabled`?k(`disabled`):e.success&&e.data?.status===`healthy`?k(`healthy`):k(`offline`)}catch{k(`offline`)}},[]);(0,b.useEffect)(()=>{if(T?.ollamaEnabled===!1)return;let e=window.setTimeout(()=>{X()},0);return()=>window.clearTimeout(e)},[X,T?.ollamaEnabled]);let Z=async e=>{try{(await _.updateSettings({enabled:e})).success?(l.success(n(e?`connectModels.ollama.enabledToast`:`connectModels.ollama.disabledToast`)),e?(k(`checking`),X()):k(`disabled`)):l.error(n(`connectModels.ollama.settingsFailed`))}catch(e){S.error(`Failed to update Ollama settings:`,e),l.error(n(`connectModels.ollama.settingsFailed`))}},te=async()=>{z(!0),V(null);try{let e=await g.probeEndpoint(P,`openai`);e.success&&e.data?.reachable?(V(e.data.models),l.success(n(`connectModels.local.reachable`,{count:e.data.models.length}))):(V([]),l.error(e.message||n(`connectModels.local.unreachable`)))}catch(e){S.error(`Endpoint probe failed:`,e),V([]),l.error(n(`connectModels.local.unreachable`))}finally{z(!1)}},ne=async()=>{U(!0);try{let e=P.replace(/\/+$/,``),r=e.endsWith(`/v1`)?e:`${e}/v1`,i=I.trim().length>0,a=`${M.id.toUpperCase().replace(/-/g,`_`)}_API_KEY`,o={id:M.id,name:M.name,type:`completion`,endpoint:`${r}/chat/completions`,api_mode:`chat_completions`,base_url:r,auth:i?{header:`Authorization`,prefix:`Bearer `,key_env:a}:{header:``,prefix:``,key_env:``},model_map:(B??[]).slice(0,50)};if(!(await g.installPlugin(o)).success&&!(await g.updatePlugin(M.id,o)).success){l.error(n(`connectModels.local.enableFailed`));return}i&&await g.setApiKey(M.id,I.trim()),await g.activatePlugin(M.id),await E({quiet:!0}),l.success(n(`connectModels.local.enabled`,{name:M.name})),t?.()}catch(e){S.error(`Failed to enable local provider:`,e),l.error(n(`connectModels.local.enableFailed`))}finally{U(!1)}},re=async()=>{if(W&&K.trim()){Y(!0);try{if(!(await g.setApiKey(W.id,K.trim())).success){l.error(n(`connectModels.cloud.saveFailed`));return}await g.activatePlugin(W.id),await E({quiet:!0}),l.success(n(`connectModels.cloud.connected`,{name:W.name})),q(``),t?.()}catch(e){S.error(`Failed to connect cloud provider:`,e),l.error(n(`connectModels.cloud.saveFailed`))}finally{Y(!1)}}},Q=`rounded-2xl border border-gray-200/80 bg-white/80 p-4 dark:border-white/10 dark:bg-white/[0.04]`,$=`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-400 focus:outline-none 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`}[O];return(0,x.jsxs)(`div`,{className:a(`flex w-full flex-col gap-3`,`max-w-lg`),children:[(0,x.jsxs)(`div`,{className:Q,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/[0.05]`,children:(0,x.jsx)(c,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,x.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:`Ollama`}),(0,x.jsx)(`span`,{className:a(`h-2 w-2 rounded-full`,ie)})]}),(0,x.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.status.${O}`)})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[O!==`disabled`&&(0,x.jsx)(y,{variant:`ghost`,size:`sm`,onClick:()=>{k(`checking`),X()},title:n(`connectModels.ollama.recheck`),children:(0,x.jsx)(m,{className:a(`h-4 w-4`,O===`checking`&&`animate-spin`)})}),D&&O===`offline`&&(0,x.jsx)(y,{variant:`ghost`,size:`sm`,onClick:()=>void Z(!1),title:n(`connectModels.ollama.disable`),children:(0,x.jsx)(s,{className:`h-4 w-4`})}),D&&O===`disabled`&&(0,x.jsx)(y,{variant:`ghost`,size:`sm`,onClick:()=>void Z(!0),children:n(`connectModels.ollama.enable`)})]})]}),O===`offline`&&(0,x.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.offlineHint`)}),O===`healthy`&&(0,x.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-green-600 dark:text-green-400`,children:n(`connectModels.ollama.healthyHint`)})]}),(0,x.jsxs)(`div`,{className:Q,children:[(0,x.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,onClick:()=>j(A===`local`?null:`local`),children:[(0,x.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/[0.05]`,children:(0,x.jsx)(ee,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,x.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,x.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.local.title`)}),(0,x.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.local.subtitle`)})]}),(0,x.jsx)(p,{className:a(`h-4 w-4 text-gray-400 transition-transform`,A===`local`&&`rotate-90`)})]}),A===`local`&&(0,x.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:D?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,x.jsx)(`button`,{type:`button`,onClick:()=>{N(e),F(e.baseUrl),V(null)},className:a(`rounded-full border px-3 py-1 text-xs transition-colors`,M.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,x.jsx)(`input`,{className:$,value:P,onChange:e=>{F(e.target.value),V(null)},placeholder:`http://localhost:8080/v1`,spellCheck:!1}),(0,x.jsx)(`input`,{className:$,value:I,onChange:e=>L(e.target.value),placeholder:n(`connectModels.local.keyPlaceholder`),type:`password`,autoComplete:`off`}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsxs)(y,{variant:`outline`,size:`sm`,onClick:()=>void te(),disabled:R||!P.trim(),children:[(0,x.jsx)(h,{className:`me-1.5 h-4 w-4`}),n(R?`connectModels.local.testing`:`connectModels.local.test`)]}),(0,x.jsxs)(y,{size:`sm`,onClick:()=>void ne(),disabled:H||!B||B.length===0,children:[(0,x.jsx)(d,{className:`me-1.5 h-4 w-4`}),n(H?`connectModels.local.enabling`:`connectModels.local.enable`)]})]}),B&&B.length>0&&(0,x.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[B.slice(0,8).map(e=>(0,x.jsx)(`span`,{className:`rounded-md bg-gray-100 px-2 py-0.5 font-mono text-[10px] text-gray-700 dark:bg-white/[0.06] dark:text-dark-700`,children:e},e)),B.length>8&&(0,x.jsxs)(`span`,{className:`px-1 text-[10px] text-gray-400`,children:[`+`,B.length-8]})]}),B&&B.length===0&&(0,x.jsx)(`p`,{className:`text-xs text-red-500`,children:n(`connectModels.local.noModels`)})]}):(0,x.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),(0,x.jsxs)(`div`,{className:Q,children:[(0,x.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,onClick:()=>j(A===`cloud`?null:`cloud`),children:[(0,x.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/[0.05]`,children:(0,x.jsx)(u,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,x.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,x.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.cloud.title`)}),(0,x.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.cloud.subtitle`)})]}),(0,x.jsx)(p,{className:a(`h-4 w-4 text-gray-400 transition-transform`,A===`cloud`&&`rotate-90`)})]}),A===`cloud`&&(0,x.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:D?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:w.map(e=>(0,x.jsx)(`button`,{type:`button`,onClick:()=>G(e),className:a(`rounded-full border px-3 py-1 text-xs transition-colors`,W?.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))}),W&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`relative`,children:[(0,x.jsx)(f,{className:`absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,x.jsx)(`input`,{className:a($,`ps-9`),value:K,onChange:e=>q(e.target.value),placeholder:n(`connectModels.cloud.keyPlaceholder`,{name:W.name}),type:`password`,autoComplete:`off`})]}),(0,x.jsx)(`div`,{children:(0,x.jsxs)(y,{size:`sm`,onClick:()=>void re(),disabled:J||!K.trim(),children:[(0,x.jsx)(d,{className:`me-1.5 h-4 w-4`}),n(J?`connectModels.cloud.connecting`:`connectModels.cloud.connect`)]})})]})]}):(0,x.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),e===`setup`&&(0,x.jsx)(`div`,{className:`mt-1 text-center`,children:(0,x.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{T as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-wiHys0m2.js";import{t as r}from"./logger-BR4forr_.js";import{t as i}from"./useTranslation-B9kflK9S.js";import{i as a,t as o}from"./utils-p8Gt72YP.js";import{G as ee,I as te,O as ne,Ot as re,Qn as s,W as ie,Zn as c,jn as ae,lr as oe,r as l,v as se,wr as u}from"./ui-vendor-BhHHyHk3.js";import{a as ce}from"./client-gf5bjBrn.js";import{t as d}from"./Button-CGMYia4g.js";import{f as le,l as f,m as ue,p as de}from"./ui-DDMjO5dd.js";import{t as p}from"./cordisApi-BYjA4EOQ.js";import{n as fe}from"./composerStyles-C83jssgZ.js";var m=e(t(),1),h=n(),g=r(`pages:cordis`),_=`rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`,pe=(e,t)=>{if(ce(e)){let t=e.response?.data;if(typeof t?.error==`string`)return t.error}return e instanceof Error?e.message:t},me=e=>(e.cancellation??=p.cancel(e.sessionId).catch(t=>{throw e.cancellation=void 0,t}),e.cancellation),he=e=>e.role===`system`||e.source===`system`||e.source===`context`,ge=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},_e=(e,t)=>JSON.stringify([e,t]),v=({text:e})=>{let{t}=i();return(0,h.jsxs)(`details`,{className:`mb-3 text-ink-muted`,"data-testid":`cordis-reasoning`,children:[(0,h.jsx)(`summary`,{className:o(`cursor-pointer text-xs`,_),children:t(`chatMessage.thinking`)}),(0,h.jsx)(`div`,{className:`mt-3 border-s border-line ps-3`,children:(0,h.jsx)(f,{content:e})})]})},y=({tool:e})=>{let{t}=i();return(0,h.jsxs)(`details`,{className:`group rounded-xl border border-line bg-surface-subtle`,"data-testid":`cordis-tool-activity`,"data-call-id":e.callId,children:[(0,h.jsxs)(`summary`,{className:o(`flex cursor-pointer items-center gap-2 px-3 py-2.5 text-sm`,_),children:[(0,h.jsx)(l,{className:`h-4 w-4 shrink-0 text-ink-muted`,"aria-hidden":`true`}),(0,h.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate font-mono text-xs text-ink`,children:e.name}),(0,h.jsx)(`span`,{className:`text-xs text-ink-muted`,children:t(`tools.callStatus.${e.status}`)}),(0,h.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 text-ink-muted transition-transform group-open:rotate-180 motion-reduce:transition-none`,"aria-hidden":`true`})]}),(0,h.jsxs)(`div`,{className:`space-y-3 border-t border-line px-3 py-3`,children:[e.arguments&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-1 text-xs text-ink-muted`,children:t(`tools.arguments`)}),(0,h.jsx)(`pre`,{dir:`ltr`,className:`max-h-60 overflow-auto whitespace-pre-wrap break-words font-mono text-xs text-ink`,children:ge(e.arguments)})]}),e.output!==void 0&&(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`mb-1 text-xs text-ink-muted`,children:t(`tools.result`)}),(0,h.jsx)(`pre`,{dir:`ltr`,className:`max-h-80 overflow-auto whitespace-pre-wrap break-words font-mono text-xs text-ink`,children:e.output})]})]})]})},ve=({message:e,streaming:t=!1})=>{let{t:n}=i(),[r,a]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!r)return;let e=window.setTimeout(()=>a(!1),2e3);return()=>window.clearTimeout(e)},[r]);let ee=async()=>{try{await navigator.clipboard.writeText(e.text),a(!0)}catch{u.error(n(`settings.apiKeys.copyFailed`))}};return(0,h.jsxs)(`article`,{"data-role":e.role,"data-testid":t?`cordis-streaming`:`cordis-message`,className:o(`min-w-0 text-sm`,e.role===`user`?`ms-auto max-w-[90%] rounded-2xl bg-surface-subtle px-4 py-3`:`w-full py-2`),children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-ink-muted`,children:[(0,h.jsx)(`span`,{className:`flex-1`,children:n(`cordis.role.${e.role}`)}),!t&&e.text&&(0,h.jsx)(`button`,{type:`button`,className:o(`p-1 text-ink-muted hover:text-ink`,_),"aria-label":n(r?`chatMessage.copied`:`chatMessage.copyMessage`),onClick:()=>void ee(),children:r?(0,h.jsx)(s,{className:`h-3.5 w-3.5`}):(0,h.jsx)(ae,{className:`h-3.5 w-3.5`})})]}),e.reasoning&&(0,h.jsx)(v,{text:e.reasoning}),e.text&&(0,h.jsx)(f,{content:e.text,isStreaming:t})]})},b=()=>{let{t:e}=i(),[t,n]=(0,m.useState)(null),[r,s]=(0,m.useState)([]),[c,ae]=(0,m.useState)([]),[l,ce]=(0,m.useState)({models:[]}),[f,ge]=(0,m.useState)({permissionMode:`read-only`}),[v,b]=(0,m.useState)(null),[x,S]=(0,m.useState)(null),[ye,be]=(0,m.useState)(``),[C,w]=(0,m.useState)(``),[T,xe]=(0,m.useState)(!0),[Se,Ce]=(0,m.useState)(0),[we,Te]=(0,m.useState)(0),[Ee,E]=(0,m.useState)(null),[D,De]=(0,m.useState)(!1),[O,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(!1),[Oe,M]=(0,m.useState)(null),[N,P]=(0,m.useState)(``),[F,I]=(0,m.useState)(``),[ke,L]=(0,m.useState)([]),[R,z]=(0,m.useState)([]),[B,Ae]=(0,m.useState)(null),[je,V]=(0,m.useState)(null),[Me,Ne]=(0,m.useState)(``),H=(0,m.useRef)(null),U=(0,m.useRef)(0),W=(0,m.useRef)(0),Pe=(0,m.useRef)(0),Fe=(0,m.useRef)(null),G=(0,m.useRef)(!0),Ie=(0,m.useRef)(null);(0,m.useEffect)(()=>()=>{let e=H.current;H.current=null,e&&me(e).catch(e=>g.error(`cancelling a departed turn failed`,e)).finally(()=>e.controller.abort())},[]),(0,m.useEffect)(()=>{let t=!1;return p.getHealth().then(async e=>{if(t||(n(e),!e.ready))return;let[r,i,a]=await Promise.all([p.listSessions(),p.listTools(),p.getModels()]);t||(s(r),ae(i),ce({...a,models:a.models.filter(e=>e.providerType===`ollama`&&e.id.startsWith(`lwui:ollama:`)||e.providerType===`plugin`&&e.id.startsWith(`lwui:plugin:`)||e.providerType===`dsh`&&e.id.startsWith(`native:`))}),ge(e=>({...e,model:e.model??a.defaultModel})),b(e=>e??r[0]?.id??null))}).catch(r=>{t||n({enabled:!0,ready:!1,error:pe(r,e(`cordis.unavailableTitle`))})}).finally(()=>{t||xe(!1)}),()=>{t=!0}},[Se,e]),(0,m.useEffect)(()=>{if(!v)return;let e=!1,t=++U.current,n=++W.current;return p.getSession(v).then(r=>{e||t!==U.current||H.current?.sessionId===r.id||(S(r),n===W.current&&z(r.approvals??[]),E(null))}).catch(n=>{!e&&t===U.current&&E(String(n))}),()=>{e=!0}},[v,we]);let K=x?.id===v?x:null,q=D||K?.active===!0;(0,m.useEffect)(()=>{if(!v||!K?.active||D)return;let e=!1,t=!1,n=window.setInterval(()=>{if(t)return;t=!0;let n=++W.current;p.getSession(v).then(t=>{e||n!==W.current||(S(t),z(t.approvals??[]))}).catch(t=>{e||E(String(t))}).finally(()=>{t=!1})},2e3);return()=>{e=!0,window.clearInterval(n)}},[v,K?.active,D]);let J=(0,m.useMemo)(()=>K?.messages??[],[K]),Le=(0,m.useMemo)(()=>J.filter(he),[J]),Y=(0,m.useMemo)(()=>J.filter(e=>!he(e)),[J]),{toolResults:Re,matchedResults:ze,currentPendingCalls:Be}=(0,m.useMemo)(()=>{let e=new Map,t=new Set,n=new Map,r=new Set,i=Y.reduce((e,t,n)=>t.role===`user`?n:e,-1);for(let[a,o]of Y.entries()){for(let e of o.toolCalls??[]){let t=_e(o.id,e.callId);n.set(e.callId,t),a>i&&r.add(t)}for(let r of o.toolResults??[]){let i=n.get(r.callId);i&&(e.set(i,r),t.add(r),n.delete(r.callId))}}return{toolResults:e,matchedResults:t,currentPendingCalls:new Set([...n.values()].filter(e=>r.has(e)))}},[Y]),X=K?.settings??f,Z=T||q||A||t?.ready!==!0||v!==null&&K===null,Ve=Z||v===null,He=r.filter(e=>`${e.title??``} ${e.id}`.toLowerCase().includes(ye.toLowerCase())),Ue=(e,t)=>R.some(n=>n.sessionId===v&&(n.callId?n.callId===e:n.toolName===t))?`awaiting_approval`:`running`;(0,m.useEffect)(()=>{let e=Fe.current;e&&G.current&&(e.scrollTop=e.scrollHeight)},[J,N,F,ke,R]),(0,m.useEffect)(()=>{let e=Ie.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,176)}px`)},[C]);let We=e=>{H.current||A||B||O||(b(e),W.current+=1,V(null),E(null),M(null),z([]),w(``),G.current=!0)},Ge=async()=>{if(!(H.current||A)){j(!0);try{let e=await p.createSession(f);s(t=>[e,...t]),b(e.id),S(e),W.current+=1,z(e.approvals??[]),V(null),E(null),M(null),w(``),G.current=!0}catch(t){g.error(`creating a session failed`,t),u.error(e(`cordis.createFailed`))}finally{j(!1)}}},Ke=async t=>{if(!(H.current||A)){j(!0);try{await p.deleteSession(t),s(e=>e.filter(e=>e.id!==t)),v===t&&(b(null),S(null),W.current+=1,z([]),V(null),E(null),w(``))}catch(t){g.error(`deleting a session failed`,t),u.error(e(`cordis.deleteFailed`))}finally{j(!1)}}},qe=async t=>{if(Z)return;if(!v){ge(e=>({...e,...t}));return}U.current+=1;let n=++W.current;j(!0),M(null);try{let e=await p.updateSettings(v,t);S(e),n===W.current&&z(e.approvals??[])}catch(t){M(pe(t,e(`chat.controls.saveFailed`)))}finally{j(!1)}},Je=async(t,n)=>{W.current+=1,Ae(t.id);try{await p.decideApproval(t.sessionId,t.id,n),W.current+=1,z(e=>e.filter(e=>e.id!==t.id))}catch(n){g.error(`deciding a tool approval failed`,n),u.error(e(`work.approval.failed`));let r=++W.current,i=await p.getSession(t.sessionId).catch(()=>null);i&&r===W.current&&z(i.approvals??[])}finally{Ae(null)}},Q=(0,m.useCallback)(async t=>{let n=(t??C).trim();if(!v||!n||H.current||A||x?.id!==v)return;let r={sessionId:v,controller:new AbortController};U.current+=1,H.current=r;let i=()=>H.current===r;w(``),Ne(n),De(!0),P(``),I(``),L([]),V(null),G.current=!0,S({...x,messages:[...x.messages,{id:`pending-${Date.now()}`,role:`user`,source:`user`,text:n}]});let a=!1;try{await p.sendMessage(v,n,{signal:r.controller.signal,onChunk:e=>{if(i()){if(e.type===`text`&&P(t=>t+e.text),e.type===`reasoning`&&I(t=>t+e.text),e.type===`error`&&(a=!0,V(e.message)),e.type===`tool-call`||e.type===`tool-result`){let t=++Pe.current;L(n=>{if(e.type===`tool-call`)return[...n,{instanceId:t,callId:e.callId,name:e.name,arguments:e.arguments,status:`running`}];let r=n.reduce((t,n,r)=>n.callId===e.callId&&n.status===`running`?r:t,-1),i={instanceId:t,...n[r],callId:e.callId,name:e.name,output:e.output,status:e.isError?`failed`:`succeeded`};return r<0?[...n,i]:n.map((e,t)=>t===r?i:e)})}e.type===`approval-request`&&(W.current+=1,z(t=>[...t.filter(t=>t.id!==e.approval.id),e.approval])),e.type===`approval-decision`&&(W.current+=1,z(t=>t.filter(t=>t.id!==e.approvalId)))}}})}catch(t){i()&&!r.controller.signal.aborted&&!a&&V(t instanceof Error?t.message:e(`cordis.sendFailed`))}finally{if(i()){await r.cancellation?.catch(()=>void 0);try{let e=++W.current,[t,n]=await Promise.all([p.getSession(r.sessionId),p.listSessions()]);i()&&(S(t),s(n),e===W.current&&z(t.approvals??[]))}catch(e){g.error(`refreshing a completed turn failed`,e),i()&&E(String(e))}i()&&(H.current=null,De(!1),k(!1),P(``),I(``),L([]))}}},[C,A,v,x,e]),Ye=async()=>{let t=H.current;if(!(t?.cancellation||!t&&!K?.active)){k(!0);try{if(t)await me(t),t.controller.abort();else if(v){await p.cancel(v);let e=++W.current,t=await p.getSession(v);S(t),e===W.current&&z(t.approvals??[]),k(!1)}}catch(n){g.error(`cancelling a turn failed`,n),H.current===t&&(k(!1),u.error(e(`cordis.sendFailed`)))}}},$=l.models.map(e=>({value:e.id,label:e.providerName?`${e.name} · ${e.providerName}`:e.name}));return X.model&&!$.some(e=>e.value===X.model)&&$.unshift({value:X.model,label:X.model}),$.length||$.push({value:``,label:e(`models.noModelsFound`)}),(0,h.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-surface`,"data-testid":`cordis-page`,children:[(0,h.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between gap-3 border-b border-line px-4 py-3 sm:px-6`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsx)(`h1`,{className:`truncate text-lg font-medium text-ink`,children:e(`cordis.title`)}),(0,h.jsx)(`p`,{className:`truncate text-xs text-ink-muted`,children:K?.title??e(`cordis.description`)})]}),(0,h.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>void Ge(),disabled:T||t?.ready!==!0||D||A||B!==null||O,"data-testid":`cordis-create-session`,children:[(0,h.jsx)(re,{className:`me-2 h-4 w-4`,"aria-hidden":`true`}),e(`cordis.newSession`)]})]}),!T&&t?.ready!==!0&&(0,h.jsxs)(`div`,{role:`status`,"data-testid":`cordis-unavailable`,className:`m-4 rounded-xl border border-line bg-surface-subtle p-4 text-sm`,children:[(0,h.jsx)(`p`,{className:`font-medium text-ink`,children:t?.enabled?e(`cordis.unavailableTitle`):e(`cordis.disabledTitle`)}),(0,h.jsx)(`p`,{className:`mt-1 text-ink-muted`,children:t?.error??e(`cordis.disabledHint`)}),(0,h.jsx)(d,{className:`mt-3`,variant:`outline`,size:`sm`,onClick:()=>{xe(!0),Ce(e=>e+1)},children:e(`common.retry`)})]}),(0,h.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col lg:flex-row`,children:[(0,h.jsxs)(`aside`,{"aria-label":e(`cordis.sessionsHeading`),className:`shrink-0 border-b border-line bg-surface-subtle/30 lg:flex lg:w-64 lg:min-h-0 lg:flex-col lg:border-b-0 lg:border-e`,children:[(0,h.jsxs)(`div`,{className:`hidden px-4 pt-4 lg:block`,children:[(0,h.jsx)(`label`,{className:`sr-only`,htmlFor:`cordis-session-search`,children:e(`common.search`)}),(0,h.jsxs)(`div`,{className:`relative`,children:[(0,h.jsx)(ee,{className:`pointer-events-none absolute start-3 top-3 h-4 w-4 text-ink-muted`,"aria-hidden":`true`}),(0,h.jsx)(ue,{id:`cordis-session-search`,value:ye,onChange:e=>be(e.target.value),placeholder:e(`common.search`),className:`ps-9`})]})]}),(0,h.jsxs)(`div`,{className:`min-h-0 overflow-auto p-2 lg:flex-1 lg:p-3`,children:[(0,h.jsx)(`ul`,{className:`flex gap-1 lg:block lg:space-y-1`,"data-testid":`cordis-session-list`,children:He.map(t=>(0,h.jsx)(`li`,{className:`min-w-44 lg:min-w-0`,children:(0,h.jsxs)(`div`,{className:o(`flex items-center gap-1 rounded-lg px-2 py-2`,v===t.id?`bg-surface-raised`:`hover:bg-surface-subtle`),children:[(0,h.jsxs)(`button`,{type:`button`,onClick:()=>We(t.id),disabled:D||A||B!==null||O,"aria-current":v===t.id,"aria-label":t.title??t.id,className:o(`min-w-0 flex-1 text-start disabled:opacity-60`,_),children:[(0,h.jsx)(`span`,{className:`block truncate text-sm text-ink`,children:t.title??e(`cordis.newSession`)}),(0,h.jsx)(`span`,{className:`mt-0.5 block truncate text-xs text-ink-muted`,children:t.createdAt?a(t.createdAt):e(`cordis.unknownTime`)})]}),(0,h.jsx)(d,{variant:`ghost`,size:`sm`,"aria-label":e(`cordis.deleteSession`),disabled:D||A||B!==null||O,onClick:()=>void Ke(t.id),children:(0,h.jsx)(se,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]})},t.id))}),!r.length&&t?.ready&&(0,h.jsx)(`p`,{className:`p-2 text-xs text-ink-muted`,children:e(`cordis.noSessions`)}),r.length>0&&!He.length&&(0,h.jsx)(`p`,{className:`p-2 text-xs text-ink-muted`,children:e(`common.noResults`)})]}),(0,h.jsxs)(`details`,{className:`hidden shrink-0 border-t border-line p-4 lg:block`,"data-testid":`cordis-tools-disclosure`,children:[(0,h.jsxs)(`summary`,{className:o(`cursor-pointer text-xs text-ink-muted`,_),children:[e(`cordis.toolsHeading`),` (`,c.length,`)`]}),(0,h.jsx)(`ul`,{className:`mt-3 max-h-48 space-y-3 overflow-y-auto`,"data-testid":`cordis-tool-list`,children:c.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`span`,{dir:`ltr`,className:`block font-mono text-xs text-ink`,children:e.name}),(0,h.jsx)(`p`,{className:`mt-1 text-xs text-ink-muted`,children:e.description})]},e.name))}),!c.length&&(0,h.jsx)(`p`,{className:`mt-2 text-xs text-ink-muted`,children:e(`cordis.noTools`)})]})]}),(0,h.jsxs)(`section`,{"aria-label":e(`cordis.transcriptHeading`),className:`flex min-h-0 min-w-0 flex-1 flex-col`,"data-testid":`cordis-transcript`,children:[(0,h.jsx)(`div`,{ref:Fe,"data-testid":`cordis-transcript-scroll`,className:`scroll-region min-h-0 flex-1 px-4 py-5 sm:px-6`,onScroll:e=>{let t=e.currentTarget;G.current=t.scrollHeight-t.scrollTop-t.clientHeight<80},children:(0,h.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-5`,children:[T&&(0,h.jsx)(`p`,{role:`status`,className:`text-sm text-ink-muted`,children:e(`common.loading`)}),v===null&&!T&&(0,h.jsxs)(`div`,{className:`py-12 text-center`,children:[(0,h.jsx)(oe,{className:`mx-auto mb-3 h-7 w-7 text-ink-muted`,"aria-hidden":`true`}),(0,h.jsx)(`p`,{className:`text-sm text-ink-muted`,children:e(`cordis.selectSession`)})]}),Le.length>0&&(0,h.jsxs)(`details`,{"data-testid":`cordis-context`,className:`rounded-xl border border-line bg-surface-subtle p-3`,children:[(0,h.jsx)(`summary`,{className:o(`cursor-pointer text-xs text-ink-muted`,_),children:e(`cordis.context`)}),(0,h.jsx)(`div`,{className:`mt-3 space-y-4`,children:Le.map(e=>(0,h.jsx)(`pre`,{dir:`auto`,className:`max-h-72 overflow-auto whitespace-pre-wrap break-words text-xs text-ink-muted`,children:e.text},e.id))})]}),Y.map(t=>(0,h.jsxs)(`div`,{className:`space-y-3`,children:[(t.text||t.reasoning)&&!t.toolResults?.length&&(0,h.jsx)(ve,{message:t}),t.toolCalls?.map(e=>{let n=_e(t.id,e.callId),r=Re.get(n);return(0,h.jsx)(y,{tool:{...e,output:r?.output,status:r?r.isError?`failed`:`succeeded`:q&&Be.has(n)?Ue(e.callId,e.name):`cancelled`}},e.callId)}),t.toolResults?.filter(e=>!ze.has(e)).map(t=>(0,h.jsx)(y,{tool:{...t,name:t.name??e(`cordis.role.tool`),status:t.isError?`failed`:`succeeded`}},t.callId))]},t.id)),D&&(N||F)&&(0,h.jsx)(ve,{streaming:!0,message:{id:`stream`,role:`assistant`,text:N,reasoning:F}}),ke.map(e=>(0,h.jsx)(y,{tool:e.status===`running`?{...e,status:Ue(e.callId,e.name)}:e},e.instanceId)),R.filter(e=>e.sessionId===v).map(t=>(0,h.jsxs)(`div`,{role:`alert`,"data-testid":`cordis-approval`,className:`rounded-xl border border-warning-500/40 bg-surface-subtle p-4`,children:[(0,h.jsxs)(`p`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-ink`,children:[(0,h.jsx)(te,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`work.approval.title`)]}),(0,h.jsx)(`p`,{className:`text-sm text-ink`,children:e(`work.approval.description`,{tool:t.toolName})}),t.reason&&(0,h.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-xs text-ink-muted`,children:t.reason}),(0,h.jsxs)(`div`,{className:`mt-3 flex gap-2`,children:[(0,h.jsx)(d,{size:`sm`,disabled:B!==null,onClick:()=>void Je(t,`allowed-once`),children:e(`work.approval.allowOnce`)}),(0,h.jsx)(d,{size:`sm`,variant:`outline`,disabled:B!==null,onClick:()=>void Je(t,`rejected`),children:e(`work.approval.deny`)})]})]},t.id)),je&&(0,h.jsxs)(`div`,{role:`alert`,"data-testid":`cordis-turn-error`,className:`rounded-xl border border-error-500/40 bg-error-500/10 p-4 text-sm text-ink`,children:[(0,h.jsx)(`p`,{className:`font-medium`,children:e(`cordis.turnFailed`)}),(0,h.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap break-words`,children:je}),!q&&Me&&(0,h.jsx)(d,{className:`mt-3`,variant:`outline`,size:`sm`,onClick:()=>void Q(Me),children:e(`common.retry`)})]}),Ee&&(0,h.jsxs)(`div`,{role:`alert`,className:`rounded-xl border border-line p-4 text-sm text-ink`,children:[(0,h.jsx)(`p`,{children:Ee}),(0,h.jsx)(d,{className:`mt-2`,size:`sm`,variant:`outline`,disabled:D,onClick:()=>{E(null),Te(e=>e+1)},children:e(`common.retry`)})]}),q&&!N&&!F&&!R.length&&(0,h.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-ink-muted`,children:[(0,h.jsx)(oe,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`cordis.working`)]})]})}),(0,h.jsx)(`form`,{className:`shrink-0 border-t border-line px-4 py-3 sm:px-6`,onSubmit:e=>{e.preventDefault(),Q()},children:(0,h.jsxs)(`div`,{className:`mx-auto max-w-3xl`,children:[(0,h.jsxs)(`div`,{className:`mb-3 grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,h.jsx)(le,{label:e(`cordis.permissions`),"data-testid":`cordis-permission-select`,value:X.permissionMode,options:[{value:`read-only`,label:e(`cordis.readOnly`)},{value:`workspace-write`,label:e(`cordis.workspaceWrite`)}],disabled:Z||v!==null&&K?.capabilities?.permissions!==!0,onChange:e=>void qe({permissionMode:e.target.value}),className:`py-2 text-sm`}),(0,h.jsx)(le,{label:e(`personas.model`),dir:`ltr`,"data-testid":`cordis-model-select`,value:X.model??l.defaultModel??``,options:$,disabled:Z||!l.models.length,onChange:e=>void qe({model:e.target.value}),className:`py-2 text-sm`})]}),(0,h.jsx)(`p`,{className:`mb-3 text-xs text-ink-muted`,children:e(`cordis.permissionHint`)}),K?.workspacePath&&(0,h.jsxs)(`p`,{className:`mb-3 flex min-w-0 gap-2 text-xs text-ink-muted`,"data-testid":`cordis-workspace-scope`,children:[(0,h.jsx)(`span`,{children:e(`work.mobile.workspace`)}),(0,h.jsx)(`code`,{dir:`ltr`,title:K.workspacePath,className:`truncate`,children:K.workspacePath})]}),Oe&&(0,h.jsx)(`p`,{role:`alert`,className:`mb-2 text-xs text-error-600 dark:text-error-400`,children:Oe}),(0,h.jsxs)(`div`,{className:fe,children:[(0,h.jsx)(`label`,{htmlFor:`cordis-composer`,className:`sr-only`,children:e(`cordis.composerLabel`)}),(0,h.jsx)(de,{ref:Ie,id:`cordis-composer`,dir:`auto`,value:C,onChange:e=>w(e.target.value),placeholder:e(`cordis.composerPlaceholder`),rows:2,disabled:Ve,"data-testid":`cordis-composer`,className:`min-h-16 max-h-44 resize-none border-0 bg-transparent shadow-none focus:ring-0`,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Q())}}),(0,h.jsxs)(`div`,{className:`mt-2 flex items-center justify-end gap-2`,children:[A&&(0,h.jsx)(`span`,{role:`status`,className:`me-auto text-xs text-ink-muted`,children:e(`common.saving`)}),q?(0,h.jsxs)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>void Ye(),disabled:O,"data-testid":`cordis-stop`,children:[(0,h.jsx)(ne,{className:`me-2 h-4 w-4`,"aria-hidden":`true`}),e(`cordis.stop`)]}):(0,h.jsxs)(d,{type:`submit`,size:`sm`,disabled:Ve||!C.trim(),"data-testid":`cordis-send`,children:[(0,h.jsx)(ie,{className:`me-2 h-4 w-4`,"aria-hidden":`true`}),e(`cordis.send`)]})]})]})]})})]})]})]})};export{b as CordisPage,b as default};
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./useTranslation-Kn7_iLGj.js";import{t as i}from"./utils-Dq1w7K0c.js";import{t as a}from"./chatStore-BPpcL4I5.js";import{C as o,Dn as s,It as c,Sr as l,et as u,h as d,n as f,rt as p,v as m}from"./ui-vendor-LatG6rFF.js";import{t as h}from"./Button-ZQ6BePid.js";import{a as g,o as ee}from"./ui-CNcEDQ95.js";import{t as _}from"./evaluationsApi-Btc9Mg9z.js";var v=e(t(),1),y=n(),b=`w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50`,x=()=>{let{t:e}=r(),t=a(e=>e.models),n=a(e=>e.loadModels),[x,S]=(0,v.useState)(`arena`),[C,w]=(0,v.useState)(0),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,A]=(0,v.useState)(``),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)([]),[z,B]=(0,v.useState)([]),[V,H]=(0,v.useState)([]),[U,W]=(0,v.useState)([]),[G,K]=(0,v.useState)(``),[q,J]=(0,v.useState)(``),[Y,X]=(0,v.useState)(``);(0,v.useEffect)(()=>{n()},[n]),(0,v.useEffect)(()=>{let t=!1;return Promise.all([_.leaderboard(),_.listSets(),_.listRuns(),_.listFeedback()]).then(([e,n,r,i])=>{t||(e.success&&e.data&&R(e.data),n.success&&n.data&&B(n.data),r.success&&r.data&&H(r.data),i.success&&i.data&&W(i.data))}).catch(()=>l.error(e(`evaluations.loadFailed`))),()=>{t=!0}},[C,e]),(0,v.useEffect)(()=>{if(!V.some(e=>e.status===`queued`||e.status===`running`))return;let e=window.setInterval(()=>w(e=>e+1),4e3);return()=>window.clearInterval(e)},[V]);let Z=t.map(e=>e.name),Q=async()=>{if(T.trim()&&D&&k&&!F){I(!0),M(null),P(!1);try{let e=await _.runArenaMatch({prompt:T.trim(),modelA:D,modelB:k});if(!e.success||!e.data)throw Error(e.message||e.error);M(e.data)}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.matchFailed`))}finally{I(!1)}}},$=async t=>{if(j&&!N)try{let n=j.candidates.find(e=>e.key===`a`)?.model,r=j.candidates.find(e=>e.key===`b`)?.model;if(!n||!r)return;let i=await _.voteArena({compareGroup:j.compareGroup,modelA:n,modelB:r,winner:t});if(!i.success)throw Error(i.message);P(!0),w(e=>e+1),l.success(e(`evaluations.voteRecorded`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.voteFailed`))}},te=async()=>{let t=q.split(`
2
- `).map(e=>e.trim()).filter(Boolean);if(G.trim()&&t.length!==0)try{let n=await _.saveSet({name:G.trim(),items:t.map(e=>({prompt:e}))});if(!n.success)throw Error(n.message);K(``),J(``),w(e=>e+1),l.success(e(`evaluations.setSaved`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},ne=async t=>{if(!Y){l.error(e(`evaluations.pickModel`));return}try{let n=await _.startRun({setId:t,model:Y});if(!n.success)throw Error(n.message);w(e=>e+1),l.success(e(`evaluations.runStarted`))}catch(t){l.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},re=async t=>{try{let e=await _.exportRun(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`eval-run-${t}.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{l.error(e(`evaluations.exportFailed`))}},ie=[{id:`arena`,label:e(`evaluations.tabs.arena`)},{id:`leaderboard`,label:e(`evaluations.tabs.leaderboard`)},{id:`sets`,label:e(`evaluations.tabs.sets`)},{id:`feedback`,label:e(`evaluations.tabs.feedback`)}];return(0,y.jsxs)(ee,{width:`wide`,children:[(0,y.jsx)(g,{title:e(`evaluations.title`),description:e(`evaluations.description`)}),(0,y.jsx)(`div`,{className:`mb-4 inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/[0.08] dark:bg-dark-100/70`,children:ie.map(e=>(0,y.jsx)(`button`,{type:`button`,onClick:()=>S(e.id),className:i(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,x===e.id?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),children:e.label},e.id))}),x===`arena`&&(0,y.jsxs)(`div`,{className:`space-y-4`,"data-testid":`arena-tab`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelA`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:D,onChange:e=>O(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`a-${e}`))]})]}),(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelB`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:k,onChange:e=>A(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`b-${e}`))]})]})]}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:3,placeholder:e(`evaluations.arenaPrompt`),value:T,onChange:e=>E(e.target.value),"data-testid":`arena-prompt`}),(0,y.jsxs)(h,{className:`mt-2`,onClick:()=>void Q(),disabled:F||!T.trim()||!D||!k||D===k,"data-testid":`arena-start`,children:[F?(0,y.jsx)(c,{className:`mr-1 h-4 w-4 animate-spin`}):(0,y.jsx)(o,{className:`mr-1 h-4 w-4`}),e(`evaluations.startMatch`)]}),(0,y.jsx)(`p`,{className:`mt-1 text-xs text-gray-500`,children:e(`evaluations.arenaHint`)})]}),j&&(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[j.candidates.map((t,n)=>(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-3 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-gray-500`,children:N?t.model:e(`evaluations.candidate`,{letter:n+1})}),(0,y.jsx)(`div`,{className:`max-h-80 overflow-y-auto whitespace-pre-wrap text-sm text-gray-800 dark:text-gray-200`,children:t.output||`—`})]},t.key)),!N&&(0,y.jsxs)(`div`,{className:`sm:col-span-2 flex flex-wrap gap-2`,children:[(0,y.jsx)(h,{size:`sm`,onClick:()=>void $(j.candidates[0].key),children:e(`evaluations.voteFirst`)}),(0,y.jsx)(h,{size:`sm`,onClick:()=>void $(j.candidates[1].key),children:e(`evaluations.voteSecond`)}),(0,y.jsx)(h,{size:`sm`,variant:`outline`,onClick:()=>void $(`tie`),children:e(`evaluations.voteTie`)}),(0,y.jsx)(h,{size:`sm`,variant:`outline`,onClick:()=>void $(`both-bad`),children:e(`evaluations.voteBothBad`)})]})]})]}),x===`leaderboard`&&(0,y.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:(0,y.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,y.jsx)(`thead`,{className:`text-xs text-gray-500`,children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:`#`}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.model`)}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.rating`)}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.record`)}),(0,y.jsx)(`th`,{className:`py-1`,children:e(`evaluations.votes`)})]})}),(0,y.jsxs)(`tbody`,{children:[L.map((e,t)=>(0,y.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,y.jsx)(`td`,{className:`py-1.5 pr-2`,children:t===0?(0,y.jsx)(d,{className:`h-4 w-4 text-amber-500`}):t+1}),(0,y.jsx)(`td`,{className:`py-1.5 pr-2 font-medium`,children:e.model}),(0,y.jsx)(`td`,{className:`py-1.5 pr-2`,children:e.rating}),(0,y.jsxs)(`td`,{className:`py-1.5 pr-2 text-xs text-gray-500`,children:[e.wins,`W · `,e.losses,`L · `,e.ties,`T`]}),(0,y.jsx)(`td`,{className:`py-1.5`,children:e.votes})]},e.model)),L.length===0&&(0,y.jsx)(`tr`,{children:(0,y.jsx)(`td`,{colSpan:5,className:`py-3 text-sm text-gray-500`,children:e(`evaluations.noVotes`)})})]})]})}),x===`sets`&&(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:e(`evaluations.newSet`)}),(0,y.jsx)(`input`,{className:b,placeholder:e(`evaluations.setName`),value:G,onChange:e=>K(e.target.value)}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:4,placeholder:e(`evaluations.setPrompts`),value:q,onChange:e=>J(e.target.value)}),(0,y.jsxs)(h,{size:`sm`,className:`mt-2`,onClick:()=>void te(),disabled:!G.trim()||!q.trim(),children:[(0,y.jsx)(u,{className:`mr-1 h-3.5 w-3.5`}),e(`evaluations.saveSet`)]})]}),(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`evaluations.yourSets`)}),(0,y.jsxs)(`select`,{className:`rounded-lg border border-gray-300 bg-white px-2 py-1 text-xs dark:border-dark-300 dark:bg-dark-50`,value:Y,onChange:e=>X(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:e(`evaluations.pickModel`)}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`run-${e}`))]})]}),z.length===0&&(0,y.jsx)(`p`,{className:`text-sm text-gray-500`,children:e(`evaluations.noSets`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:z.map(t=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:[t.name,(0,y.jsx)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:e(`evaluations.itemCount`,{total:t.items.length})})]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,y.jsxs)(h,{size:`sm`,variant:`outline`,onClick:()=>void ne(t.id),children:[(0,y.jsx)(p,{className:`mr-1 h-3 w-3`}),e(`evaluations.run`)]}),(0,y.jsx)(`button`,{onClick:()=>{_.deleteSet(t.id).then(()=>w(e=>e+1)).catch(()=>l.error(e(`evaluations.saveFailed`)))},className:`rounded p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":e(`evaluations.deleteSet`),children:(0,y.jsx)(m,{className:`h-3.5 w-3.5`})})]})]}),V.filter(e=>e.setId===t.id).slice(0,5).map(t=>(0,y.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2 rounded bg-gray-50 px-2 py-1 text-xs dark:bg-dark-50`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate`,children:[t.model,` · `,e(`evaluations.status.${t.status}`),t.error?` — ${t.error}`:``]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(t.status===`queued`||t.status===`running`)&&(0,y.jsx)(`button`,{onClick:()=>{_.cancelRun(t.id).then(()=>w(e=>e+1)).catch(()=>void 0)},className:`rounded p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.cancelRun`),children:(0,y.jsx)(f,{className:`h-3 w-3`})}),t.status===`completed`&&(0,y.jsx)(`button`,{onClick:()=>void re(t.id),className:`rounded p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.exportRun`),children:(0,y.jsx)(s,{className:`h-3 w-3`})})]})]},t.id))]},t.id))})]})]}),x===`feedback`&&(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[U.length===0&&(0,y.jsx)(`p`,{className:`text-sm text-gray-500`,children:e(`evaluations.noFeedback`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:U.map(e=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 text-sm dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-gray-500`,children:[(0,y.jsxs)(`span`,{children:[e.rating===1?`👍`:`👎`,` `,e.model??``,e.tags.length>0&&` · ${e.tags.join(`, `)}`]}),(0,y.jsx)(`span`,{children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.createdAt)})]}),e.snapshot&&(0,y.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-gray-600 dark:text-gray-300`,children:e.snapshot.assistant}),e.comment&&(0,y.jsxs)(`p`,{className:`mt-1 text-xs italic text-gray-500`,children:[`“`,e.comment,`”`]})]},e.id))})]})]})};export{x as EvaluationsPage,x as default};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-wiHys0m2.js";import{t as r}from"./useTranslation-B9kflK9S.js";import{t as i}from"./utils-p8Gt72YP.js";import{t as a}from"./chatStore-DQhEqb9F.js";import{C as o,Cr as s,Lt as c,On as l,et as u,h as d,n as f,rt as p,v as m}from"./ui-vendor-BhHHyHk3.js";import{t as h}from"./Button-CGMYia4g.js";import{a as g,o as ee}from"./ui-DDMjO5dd.js";import{t as _}from"./evaluationsApi-Bg12ekHo.js";var v=e(t(),1),y=n(),b=`w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50`,x=()=>{let{t:e}=r(),t=a(e=>e.models),n=a(e=>e.loadModels),[x,S]=(0,v.useState)(`arena`),[C,w]=(0,v.useState)(0),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(``),[k,A]=(0,v.useState)(``),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)([]),[z,B]=(0,v.useState)([]),[V,H]=(0,v.useState)([]),[U,W]=(0,v.useState)([]),[G,K]=(0,v.useState)(``),[q,J]=(0,v.useState)(``),[Y,X]=(0,v.useState)(``);(0,v.useEffect)(()=>{n()},[n]),(0,v.useEffect)(()=>{let t=!1;return Promise.all([_.leaderboard(),_.listSets(),_.listRuns(),_.listFeedback()]).then(([e,n,r,i])=>{t||(e.success&&e.data&&R(e.data),n.success&&n.data&&B(n.data),r.success&&r.data&&H(r.data),i.success&&i.data&&W(i.data))}).catch(()=>s.error(e(`evaluations.loadFailed`))),()=>{t=!0}},[C,e]),(0,v.useEffect)(()=>{if(!V.some(e=>e.status===`queued`||e.status===`running`))return;let e=window.setInterval(()=>w(e=>e+1),4e3);return()=>window.clearInterval(e)},[V]);let Z=t.map(e=>e.name),Q=async()=>{if(T.trim()&&D&&k&&!F){I(!0),M(null),P(!1);try{let e=await _.runArenaMatch({prompt:T.trim(),modelA:D,modelB:k});if(!e.success||!e.data)throw Error(e.message||e.error);M(e.data)}catch(t){s.error(t instanceof Error?t.message:e(`evaluations.matchFailed`))}finally{I(!1)}}},$=async t=>{if(j&&!N)try{let n=j.candidates.find(e=>e.key===`a`)?.model,r=j.candidates.find(e=>e.key===`b`)?.model;if(!n||!r)return;let i=await _.voteArena({compareGroup:j.compareGroup,modelA:n,modelB:r,winner:t});if(!i.success)throw Error(i.message);P(!0),w(e=>e+1),s.success(e(`evaluations.voteRecorded`))}catch(t){s.error(t instanceof Error?t.message:e(`evaluations.voteFailed`))}},te=async()=>{let t=q.split(`
2
+ `).map(e=>e.trim()).filter(Boolean);if(G.trim()&&t.length!==0)try{let n=await _.saveSet({name:G.trim(),items:t.map(e=>({prompt:e}))});if(!n.success)throw Error(n.message);K(``),J(``),w(e=>e+1),s.success(e(`evaluations.setSaved`))}catch(t){s.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},ne=async t=>{if(!Y){s.error(e(`evaluations.pickModel`));return}try{let n=await _.startRun({setId:t,model:Y});if(!n.success)throw Error(n.message);w(e=>e+1),s.success(e(`evaluations.runStarted`))}catch(t){s.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},re=async t=>{try{let e=await _.exportRun(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`eval-run-${t}.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{s.error(e(`evaluations.exportFailed`))}},ie=[{id:`arena`,label:e(`evaluations.tabs.arena`)},{id:`leaderboard`,label:e(`evaluations.tabs.leaderboard`)},{id:`sets`,label:e(`evaluations.tabs.sets`)},{id:`feedback`,label:e(`evaluations.tabs.feedback`)}];return(0,y.jsxs)(ee,{width:`wide`,children:[(0,y.jsx)(g,{title:e(`evaluations.title`),description:e(`evaluations.description`)}),(0,y.jsx)(`div`,{className:`mb-4 inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/[0.08] dark:bg-dark-100/70`,children:ie.map(e=>(0,y.jsx)(`button`,{type:`button`,onClick:()=>S(e.id),className:i(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,x===e.id?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),children:e.label},e.id))}),x===`arena`&&(0,y.jsxs)(`div`,{className:`space-y-4`,"data-testid":`arena-tab`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelA`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:D,onChange:e=>O(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`a-${e}`))]})]}),(0,y.jsxs)(`label`,{className:`text-xs text-gray-600 dark:text-gray-300`,children:[e(`evaluations.arenaModelB`),(0,y.jsxs)(`select`,{className:`${b} mt-1`,value:k,onChange:e=>A(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`b-${e}`))]})]})]}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:3,placeholder:e(`evaluations.arenaPrompt`),value:T,onChange:e=>E(e.target.value),"data-testid":`arena-prompt`}),(0,y.jsxs)(h,{className:`mt-2`,onClick:()=>void Q(),disabled:F||!T.trim()||!D||!k||D===k,"data-testid":`arena-start`,children:[F?(0,y.jsx)(c,{className:`mr-1 h-4 w-4 animate-spin`}):(0,y.jsx)(o,{className:`mr-1 h-4 w-4`}),e(`evaluations.startMatch`)]}),(0,y.jsx)(`p`,{className:`mt-1 text-xs text-gray-500`,children:e(`evaluations.arenaHint`)})]}),j&&(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[j.candidates.map((t,n)=>(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-3 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-gray-500`,children:N?t.model:e(`evaluations.candidate`,{letter:n+1})}),(0,y.jsx)(`div`,{className:`max-h-80 overflow-y-auto whitespace-pre-wrap text-sm text-gray-800 dark:text-gray-200`,children:t.output||`—`})]},t.key)),!N&&(0,y.jsxs)(`div`,{className:`sm:col-span-2 flex flex-wrap gap-2`,children:[(0,y.jsx)(h,{size:`sm`,onClick:()=>void $(j.candidates[0].key),children:e(`evaluations.voteFirst`)}),(0,y.jsx)(h,{size:`sm`,onClick:()=>void $(j.candidates[1].key),children:e(`evaluations.voteSecond`)}),(0,y.jsx)(h,{size:`sm`,variant:`outline`,onClick:()=>void $(`tie`),children:e(`evaluations.voteTie`)}),(0,y.jsx)(h,{size:`sm`,variant:`outline`,onClick:()=>void $(`both-bad`),children:e(`evaluations.voteBothBad`)})]})]})]}),x===`leaderboard`&&(0,y.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:(0,y.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,y.jsx)(`thead`,{className:`text-xs text-gray-500`,children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:`#`}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.model`)}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.rating`)}),(0,y.jsx)(`th`,{className:`py-1 pr-2`,children:e(`evaluations.record`)}),(0,y.jsx)(`th`,{className:`py-1`,children:e(`evaluations.votes`)})]})}),(0,y.jsxs)(`tbody`,{children:[L.map((e,t)=>(0,y.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,y.jsx)(`td`,{className:`py-1.5 pr-2`,children:t===0?(0,y.jsx)(d,{className:`h-4 w-4 text-amber-500`}):t+1}),(0,y.jsx)(`td`,{className:`py-1.5 pr-2 font-medium`,children:e.model}),(0,y.jsx)(`td`,{className:`py-1.5 pr-2`,children:e.rating}),(0,y.jsxs)(`td`,{className:`py-1.5 pr-2 text-xs text-gray-500`,children:[e.wins,`W · `,e.losses,`L · `,e.ties,`T`]}),(0,y.jsx)(`td`,{className:`py-1.5`,children:e.votes})]},e.model)),L.length===0&&(0,y.jsx)(`tr`,{children:(0,y.jsx)(`td`,{colSpan:5,className:`py-3 text-sm text-gray-500`,children:e(`evaluations.noVotes`)})})]})]})}),x===`sets`&&(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsx)(`h3`,{className:`mb-2 text-sm font-semibold`,children:e(`evaluations.newSet`)}),(0,y.jsx)(`input`,{className:b,placeholder:e(`evaluations.setName`),value:G,onChange:e=>K(e.target.value)}),(0,y.jsx)(`textarea`,{className:`${b} mt-2`,rows:4,placeholder:e(`evaluations.setPrompts`),value:q,onChange:e=>J(e.target.value)}),(0,y.jsxs)(h,{size:`sm`,className:`mt-2`,onClick:()=>void te(),disabled:!G.trim()||!q.trim(),children:[(0,y.jsx)(u,{className:`mr-1 h-3.5 w-3.5`}),e(`evaluations.saveSet`)]})]}),(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[(0,y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`evaluations.yourSets`)}),(0,y.jsxs)(`select`,{className:`rounded-lg border border-gray-300 bg-white px-2 py-1 text-xs dark:border-dark-300 dark:bg-dark-50`,value:Y,onChange:e=>X(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:e(`evaluations.pickModel`)}),Z.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`run-${e}`))]})]}),z.length===0&&(0,y.jsx)(`p`,{className:`text-sm text-gray-500`,children:e(`evaluations.noSets`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:z.map(t=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:[t.name,(0,y.jsx)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:e(`evaluations.itemCount`,{total:t.items.length})})]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,y.jsxs)(h,{size:`sm`,variant:`outline`,onClick:()=>void ne(t.id),children:[(0,y.jsx)(p,{className:`mr-1 h-3 w-3`}),e(`evaluations.run`)]}),(0,y.jsx)(`button`,{onClick:()=>{_.deleteSet(t.id).then(()=>w(e=>e+1)).catch(()=>s.error(e(`evaluations.saveFailed`)))},className:`rounded p-1.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":e(`evaluations.deleteSet`),children:(0,y.jsx)(m,{className:`h-3.5 w-3.5`})})]})]}),V.filter(e=>e.setId===t.id).slice(0,5).map(t=>(0,y.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2 rounded bg-gray-50 px-2 py-1 text-xs dark:bg-dark-50`,children:[(0,y.jsxs)(`span`,{className:`min-w-0 truncate`,children:[t.model,` · `,e(`evaluations.status.${t.status}`),t.error?` — ${t.error}`:``]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(t.status===`queued`||t.status===`running`)&&(0,y.jsx)(`button`,{onClick:()=>{_.cancelRun(t.id).then(()=>w(e=>e+1)).catch(()=>void 0)},className:`rounded p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.cancelRun`),children:(0,y.jsx)(f,{className:`h-3 w-3`})}),t.status===`completed`&&(0,y.jsx)(`button`,{onClick:()=>void re(t.id),className:`rounded p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.exportRun`),children:(0,y.jsx)(l,{className:`h-3 w-3`})})]})]},t.id))]},t.id))})]})]}),x===`feedback`&&(0,y.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,children:[U.length===0&&(0,y.jsx)(`p`,{className:`text-sm text-gray-500`,children:e(`evaluations.noFeedback`)}),(0,y.jsx)(`div`,{className:`space-y-2`,children:U.map(e=>(0,y.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 text-sm dark:border-dark-300`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-gray-500`,children:[(0,y.jsxs)(`span`,{children:[e.rating===1?`👍`:`👎`,` `,e.model??``,e.tags.length>0&&` · ${e.tags.join(`, `)}`]}),(0,y.jsx)(`span`,{children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.createdAt)})]}),e.snapshot&&(0,y.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-gray-600 dark:text-gray-300`,children:e.snapshot.assistant}),e.comment&&(0,y.jsxs)(`p`,{className:`mt-1 text-xs italic text-gray-500`,children:[`“`,e.comment,`”`]})]},e.id))})]})]})};export{x as EvaluationsPage,x as default};