libre-webui 0.45.2 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/backend/dist/services/agentCliService.d.ts.map +1 -1
  2. package/backend/dist/services/agentCliService.js +2 -0
  3. package/backend/dist/services/agentCliService.js.map +1 -1
  4. package/backend/dist/services/dataArchiveService.d.ts.map +1 -1
  5. package/backend/dist/services/dataArchiveService.js +2 -0
  6. package/backend/dist/services/dataArchiveService.js.map +1 -1
  7. package/backend/dist/services/followUpService.d.ts.map +1 -1
  8. package/backend/dist/services/followUpService.js +11 -1
  9. package/backend/dist/services/followUpService.js.map +1 -1
  10. package/backend/dist/services/preferencesService.d.ts.map +1 -1
  11. package/backend/dist/services/preferencesService.js +1 -0
  12. package/backend/dist/services/preferencesService.js.map +1 -1
  13. package/backend/dist/services/workModelProviderService.d.ts.map +1 -1
  14. package/backend/dist/services/workModelProviderService.js +4 -4
  15. package/backend/dist/services/workModelProviderService.js.map +1 -1
  16. package/backend/dist/types/index.d.ts +1 -0
  17. package/backend/dist/types/index.d.ts.map +1 -1
  18. package/backend/dist/types/index.js.map +1 -1
  19. package/backend/dist/utils/geminiProtocol.d.ts.map +1 -1
  20. package/backend/dist/utils/geminiProtocol.js +6 -2
  21. package/backend/dist/utils/geminiProtocol.js.map +1 -1
  22. package/backend/dist/utils/pluginChatAdapter.d.ts +23 -1
  23. package/backend/dist/utils/pluginChatAdapter.d.ts.map +1 -1
  24. package/backend/dist/utils/pluginChatAdapter.js +61 -9
  25. package/backend/dist/utils/pluginChatAdapter.js.map +1 -1
  26. package/backend/dist/utils/pluginDefinitionTrust.js +5 -5
  27. package/backend/package.json +2 -4
  28. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  29. package/frontend/dist/artifact-runtime/framer-motion.js +1 -1
  30. package/frontend/dist/artifact-runtime/lucide-react.js +1 -1
  31. package/frontend/dist/artifact-runtime/recharts.js +54 -50
  32. package/frontend/dist/assets/index-CjeHi5JU.js +76 -0
  33. package/frontend/dist/assets/index-DyhvMw2T.css +2 -0
  34. package/frontend/dist/index.html +29 -29
  35. package/frontend/dist/js/{ArtifactContainer-CFVJv-mM.js → ArtifactContainer-BaacvZ8q.js} +1 -1
  36. package/frontend/dist/js/{ArtifactDemoPage-DH0FzsNI.js → ArtifactDemoPage-D6pgt8_p.js} +1 -1
  37. package/frontend/dist/js/{ArtifactSandboxFrame-WnLSNpGj.js → ArtifactSandboxFrame-BqfRwsQa.js} +1 -1
  38. package/frontend/dist/js/{ArtifactSlideOutPanel-ASrltUrj.js → ArtifactSlideOutPanel-BUFb1QaC.js} +1 -1
  39. package/frontend/dist/js/{AutomationModal-CyKk0tlC.js → AutomationModal-a9rx93qd.js} +1 -1
  40. package/frontend/dist/js/AutomationsPage-Bhzy71Cq.js +1 -0
  41. package/frontend/dist/js/{AvatarUpload-CndjrKep.js → AvatarUpload-BHHUA-GH.js} +1 -1
  42. package/frontend/dist/js/{Button-D6d7HYoa.js → Button-DeV-GhQr.js} +1 -1
  43. package/frontend/dist/js/CalendarPage-DIlOEXA9.js +1 -0
  44. package/frontend/dist/js/ChannelsPage-BRVs-Kp-.js +1 -0
  45. package/frontend/dist/js/ChatPage-DqEa_l2u.js +14 -0
  46. package/frontend/dist/js/{ConnectModels-BNmJfvfw.js → ConnectModels-dimFaMkn.js} +1 -1
  47. package/frontend/dist/js/{EvaluationsPage-Duxm4ft2.js → EvaluationsPage-BKVxoUaS.js} +1 -1
  48. package/frontend/dist/js/{FirstTimeSetup-BZ4pQGa_.js → FirstTimeSetup-MLU3EUOv.js} +1 -1
  49. package/frontend/dist/js/{GalleryPage-BD_mUDta.js → GalleryPage-BqhTNi2p.js} +1 -1
  50. package/frontend/dist/js/HomePage-B_HbAwgO.js +1 -0
  51. package/frontend/dist/js/LanguageSwitcher-gij6QsCJ.js +1 -0
  52. package/frontend/dist/js/{Logo-DhV6D_3q.js → Logo-BBRSG7mh.js} +1 -1
  53. package/frontend/dist/js/{LogoMark-CmF1lHXT.js → LogoMark-CiSslCTm.js} +1 -1
  54. package/frontend/dist/js/{ModelManagerModals-BjLwU-MI.js → ModelManagerModals-CfcrXIm5.js} +1 -1
  55. package/frontend/dist/js/NotesPage-6qb7awMu.js +3 -0
  56. package/frontend/dist/js/{PasswordStrengthMeter-Cvrt6Q9S.js → PasswordStrengthMeter-MkydwQ8j.js} +1 -1
  57. package/frontend/dist/js/PersonasPage-KRnYk61s.js +13 -0
  58. package/frontend/dist/js/PluginUsagePage-Bm2WXYM5.js +1 -0
  59. package/frontend/dist/js/RichMessageContent-C5hmCcK6.js +3 -0
  60. package/frontend/dist/js/{RichMessageContent-BTq5fi2Q.js → RichMessageContent-fyjhRYjT.js} +1 -1
  61. package/frontend/dist/js/SettingsModal-CgtaiEwd.js +19 -0
  62. package/frontend/dist/js/{SettingsToggle-CNUeo6DO.js → SettingsToggle-XpuugbHi.js} +1 -1
  63. package/frontend/dist/js/{ShareDialog-JrPQi4_S.js → ShareDialog-lkQnQmeI.js} +1 -1
  64. package/frontend/dist/js/{StrandsPage-CG4rywyz.js → StrandsPage-sPvcnqzA.js} +1 -1
  65. package/frontend/dist/js/{SystemPage-DSHe65ZO.js → SystemPage-DwL4p4Rm.js} +1 -1
  66. package/frontend/dist/js/{UserManagementPage-BrogyZDQ.js → UserManagementPage-CzFDrqMr.js} +1 -1
  67. package/frontend/dist/js/{UserManagementPanel-B5p2mcC9.js → UserManagementPanel-Dz8Q_Nv7.js} +1 -1
  68. package/frontend/dist/js/{WhatsNewModal-CeHAg8Uz.js → WhatsNewModal-CSYCRxyb.js} +1 -1
  69. package/frontend/dist/js/WorkPage-zNqtL6D7.js +7 -0
  70. package/frontend/dist/js/{api-R43sAAC-.js → api-B8EjExUU.js} +1 -1
  71. package/frontend/dist/js/api-CCDH67RO.js +1 -0
  72. package/frontend/dist/js/{appNavigation-C59KQTgx.js → appNavigation-C0lNX2LE.js} +1 -1
  73. package/frontend/dist/js/{appStore-DDxf13l_.js → appStore-BEjqPvpR.js} +2 -2
  74. package/frontend/dist/js/appVersion-Dv97-qD1.js +1 -0
  75. package/frontend/dist/js/{ar-Cq-76la4.js → ar-BM7CvBiJ.js} +1 -1
  76. package/frontend/dist/js/authStore-BNu5iRKd.js +1 -0
  77. package/frontend/dist/js/{authStore-RsBcSMMM.js → authStore-BOFcWqii.js} +3 -3
  78. package/frontend/dist/js/{bn-sjvarZOb.js → bn-DZgfamCo.js} +1 -1
  79. package/frontend/dist/js/chatStore-C3c3r8iB.js +3 -0
  80. package/frontend/dist/js/{client-b-EoJr_G.js → client-CQZUgw7R.js} +2 -2
  81. package/frontend/dist/js/{config-cjZnwBYY.js → config-Dz__g4tp.js} +1 -1
  82. package/frontend/dist/js/{cs-HDycqDhD.js → cs-Cx7EJqsO.js} +1 -1
  83. package/frontend/dist/js/{da-BVFJgeVO.js → da-o3xyldjl.js} +1 -1
  84. package/frontend/dist/js/{de-BvHBSBK4.js → de-DtSkfuOa.js} +1 -1
  85. package/frontend/dist/js/decisionsApi-DJWWXd5m.js +1 -0
  86. package/frontend/dist/js/{decisionsApi-CCPE-Qru.js → decisionsApi-DWyjcL8B.js} +1 -1
  87. package/frontend/dist/js/{es-DbVEuhTV.js → es-CNJDAw3s.js} +1 -1
  88. package/frontend/dist/js/{evaluationsApi-Due3Xmlx.js → evaluationsApi-BE2P4V0I.js} +1 -1
  89. package/frontend/dist/js/{fr-B1KGm4dd.js → fr-BfkRYgQd.js} +1 -1
  90. package/frontend/dist/js/{hi-DxJ8DThp.js → hi-BKmbYlM1.js} +1 -1
  91. package/frontend/dist/js/{id-BeHcweMq.js → id-BeP0q360.js} +1 -1
  92. package/frontend/dist/js/{is-g5BLxkpl.js → is-FNrpAg1Q.js} +1 -1
  93. package/frontend/dist/js/{it-Dc4XkI8W.js → it-C6LfJuro.js} +1 -1
  94. package/frontend/dist/js/{ja-CDtOkRnL.js → ja-VGke24PN.js} +1 -1
  95. package/frontend/dist/js/{ko-BBKgPWyC.js → ko-JnCzlETi.js} +1 -1
  96. package/frontend/dist/js/{messageCodeStyles-DQBFoYPS.js → messageCodeStyles-QRyNUcEv.js} +2 -2
  97. package/frontend/dist/js/modelPresentation-BqdYlMRq.js +1 -0
  98. package/frontend/dist/js/{ms-rIHXR3GT.js → ms-JF56ktSS.js} +1 -1
  99. package/frontend/dist/js/{nl-CoQBZ4yX.js → nl-FzrGEt7O.js} +1 -1
  100. package/frontend/dist/js/{pl-DEEj4YnX.js → pl-C6EtLPmh.js} +1 -1
  101. package/frontend/dist/js/{pt-CRlblKN3.js → pt-Clyy_Jz3.js} +1 -1
  102. package/frontend/dist/js/router-vendor-ihzG-2y7.js +1 -0
  103. package/frontend/dist/js/{ru-CWyM0zYW.js → ru-yG8TnHJE.js} +1 -1
  104. package/frontend/dist/js/{strandsApi-dlXURr1J.js → strandsApi-EFMF0J0x.js} +1 -1
  105. package/frontend/dist/js/{sv-BZb9WtOT.js → sv-DSCl8r0m.js} +1 -1
  106. package/frontend/dist/js/{teamEventStream-LCbFl9c-.js → teamEventStream-aQGd68I4.js} +1 -1
  107. package/frontend/dist/js/{th-CyVttEeX.js → th-DiITM0tM.js} +1 -1
  108. package/frontend/dist/js/{tr-8W-DKlX6.js → tr-jQmrBMGA.js} +1 -1
  109. package/frontend/dist/js/ui-CKcr9ReZ.js +2 -0
  110. package/frontend/dist/js/{ui-vendor-CjZizWzb.js → ui-vendor-BanHlKMb.js} +1 -1
  111. package/frontend/dist/js/{uk-CCS3WiT5.js → uk-rPc3yzsm.js} +1 -1
  112. package/frontend/dist/js/{useChat-DJk_sA_g.js → useChat-DFozXoci.js} +1 -1
  113. package/frontend/dist/js/useDictation-D9lyoqUR.js +1 -0
  114. package/frontend/dist/js/useQuery-B-RslgPA.js +1 -0
  115. package/frontend/dist/js/useTranslation-Bu0AxynE.js +1 -0
  116. package/frontend/dist/js/utils-DhBboyBg.js +1 -0
  117. package/frontend/dist/js/utils-vendor-DpFrFwUi.js +1 -0
  118. package/frontend/dist/js/{vi-9LSI-JjZ.js → vi-wT4LDUXd.js} +1 -1
  119. package/frontend/dist/js/{workApi-DoqjHVys.js → workApi-C2R6IiSd.js} +1 -1
  120. package/frontend/dist/js/workApi-CNDPo0bG.js +1 -0
  121. package/frontend/dist/js/{zh-B8TvwSpQ.js → zh-CIASsxyC.js} +1 -1
  122. package/package.json +3 -4
  123. package/plugins/codex-oauth.json +2 -0
  124. package/plugins/gemini.json +1 -0
  125. package/plugins/mlx-lm.json +5 -5
  126. package/plugins/openai.json +3 -1
  127. package/plugins/openrouter.json +2 -0
  128. package/frontend/dist/assets/index-Bi4dLGow.js +0 -32
  129. package/frontend/dist/assets/index-FrFgrp5E.css +0 -2
  130. package/frontend/dist/js/AutomationsPage-DyWCHZB4.js +0 -1
  131. package/frontend/dist/js/CalendarPage-CoUeeBLZ.js +0 -1
  132. package/frontend/dist/js/ChannelsPage-BTtm0zgq.js +0 -1
  133. package/frontend/dist/js/ChatPage-CNVzf1Nh.js +0 -14
  134. package/frontend/dist/js/HomePage-CllRyMmx.js +0 -1
  135. package/frontend/dist/js/LanguageSwitcher-D4QF6lpW.js +0 -1
  136. package/frontend/dist/js/NotesPage-DFL_4FyE.js +0 -3
  137. package/frontend/dist/js/PersonasPage-C0FD_dR6.js +0 -13
  138. package/frontend/dist/js/PluginUsagePage-D5cfifCU.js +0 -1
  139. package/frontend/dist/js/RichMessageContent-BQtj6ZIo.js +0 -3
  140. package/frontend/dist/js/SettingsModal-D4K6DG99.js +0 -19
  141. package/frontend/dist/js/WorkPage-Cq_VMf9T.js +0 -7
  142. package/frontend/dist/js/api-1Ym789zb.js +0 -1
  143. package/frontend/dist/js/appVersion-6CB3OX6W.js +0 -1
  144. package/frontend/dist/js/authStore-KZxTYkaU.js +0 -1
  145. package/frontend/dist/js/chatStore-D-0TPlCx.js +0 -3
  146. package/frontend/dist/js/decisionsApi-6OUw07DU.js +0 -1
  147. package/frontend/dist/js/modelPresentation-ChKS6M4O.js +0 -1
  148. package/frontend/dist/js/router-vendor-DLHZHk4K.js +0 -1
  149. package/frontend/dist/js/ui-CtgjJ55f.js +0 -2
  150. package/frontend/dist/js/useDictation-C5NoYnvs.js +0 -1
  151. package/frontend/dist/js/useQuery-Cs76KYuP.js +0 -1
  152. package/frontend/dist/js/useTranslation-CKqEdZ8j.js +0 -1
  153. package/frontend/dist/js/utils-BXRzbHJC.js +0 -1
  154. package/frontend/dist/js/utils-vendor-B4bGLP5p.js +0 -1
  155. package/frontend/dist/js/workApi-CEjmKHnw.js +0 -1
@@ -0,0 +1,14 @@
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{d as i,f as a,u as o}from"./router-vendor-ihzG-2y7.js";import{t as s}from"./useTranslation-Bu0AxynE.js";import{Bt as c,Ct as l,F as u,G as d,Hn as f,J as p,Jt as m,L as h,Ln as g,M as _,Nn as v,O as y,Or as b,P as x,Pn as S,Q as C,Qn as w,Rn as T,Rt as E,S as ee,Tt as D,V as O,X as k,Zn as A,_n as te,_r as ne,a as j,an as re,b as ie,c as M,cr as ae,ct as oe,er as N,g as P,jn as F,kr as I,ln as se,lr as ce,m as le,mr as ue,n as L,o as de,p as fe,pr as pe,qt as me,r as he,rn as ge,sn as _e,st as R,tr as ve,tt as ye,ut as be,v as xe,vr as Se,wt as Ce,xr as we,y as Te,yn as z,zn as Ee}from"./ui-vendor-BanHlKMb.js";import{a as De,i as Oe,n as B,s as ke,t as V}from"./utils-DhBboyBg.js";import{_ as H,f as U,g as Ae,m as je,p as W,u as Me,v as Ne}from"./ui-CKcr9ReZ.js";import{t as Pe}from"./ArtifactContainer-BaacvZ8q.js";import{N as G,_ as K,a as Fe,d as q,f as Ie,g as Le,i as J,j as Re,m as ze,n as Be,p as Ve,t as He,w as Ue,x as We,y as Ge}from"./api-B8EjExUU.js";import{t as Ke}from"./appStore-BEjqPvpR.js";import{a as qe,t as Y}from"./logger-DAQsBb8I.js";import{a as Je,i as Ye,o as Xe,r as Ze,s as Qe,t as $e}from"./ttsBatching-yVvnRS5S.js";import{a as et,i as tt,n as nt,o as rt,r as it}from"./useChat-DFozXoci.js";import{E as at,_ as ot,a as st,d as ct,f as lt,g as ut,h as dt,i as ft,l as pt,m as mt,n as ht,o as gt,p as _t,r as vt,t as X,u as yt,v as bt}from"./chatStore-C3c3r8iB.js";import{t as xt}from"./LogoMark-CiSslCTm.js";import{t as St}from"./authStore-BOFcWqii.js";import{t as Ct}from"./useDialogFocus-DpTun-ZV.js";import{t as wt}from"./evaluationsApi-BE2P4V0I.js";import{l as Tt}from"./messageCodeStyles-QRyNUcEv.js";import{t as Z}from"./Button-DeV-GhQr.js";import{n as Et,r as Dt,t as Ot}from"./useDictation-D9lyoqUR.js";import{d as kt,f as At,l as jt,t as Mt}from"./modelPresentation-BqdYlMRq.js";import{n as Nt,t as Pt}from"./composerStyles-BEx0XAp6.js";import{t as Ft}from"./ConnectModels-dimFaMkn.js";import{i as It,r as Lt,t as Rt}from"./welcomePrompts-to5mv_gx.js";var zt=n(),Q=e(t(),1),$=r(),Bt=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},Vt=({status:e})=>e===`running`||e===`awaiting_approval`?(0,$.jsx)(E,{className:`h-3.5 w-3.5 animate-spin`}):e===`succeeded`?(0,$.jsx)(ve,{className:`h-3.5 w-3.5 text-green-600 dark:text-green-400`}):e===`denied`?(0,$.jsx)(L,{className:`h-3.5 w-3.5 text-amber-600 dark:text-amber-400`}):(0,$.jsx)(P,{className:`h-3.5 w-3.5 text-red-500 dark:text-red-400`}),Ht=({call:e})=>{let{t}=s(),[n,r]=(0,Q.useState)(!1),i=t(`tools.callStatus.${e.status}`);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-200 bg-gray-50 dark:bg-dark-50 text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-start`,"aria-expanded":n,children:[n?(0,$.jsx)(N,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(w,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 rtl:rotate-180`}),(0,$.jsx)(he,{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:V(`ms-auto flex shrink-0 items-center gap-1 text-xs`,e.status===`succeeded`?`text-green-600 dark:text-green-400`:e.status===`failed`?`text-red-500 dark:text-red-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(Vt,{status:e.status}),i]})]}),n&&(0,$.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 dark:border-dark-200`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.arguments`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Bt(e.arguments)}),e.resultPreview!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-2 text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.result`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:e.resultPreview})]})]})]})},Ut=({calls:e,className:t})=>e.length===0?null:(0,$.jsx)(`div`,{className:V(`flex flex-col gap-1.5`,t),children:e.map(e=>(0,$.jsx)(Ht,{call:e},e.id))}),Wt=({approval:e,onDecide:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),o=(0,Q.useId)(),c=async(n,r)=>{a(!0);try{await t(e.approvalId,n,r)}catch{a(!1)}},l=r(`tools.approval.description`,{tool:e.toolCall.name,server:e.toolCall.serverName??r(`tools.approval.builtinSource`)});return(0,$.jsxs)(`div`,{role:`group`,"aria-labelledby":o,className:V(`rounded-lg border border-primary-300/70 bg-primary-50 p-3 text-sm dark:border-primary-700/60 dark:bg-primary-900/20`,n),children:[(0,$.jsxs)(`span`,{className:`sr-only`,role:`alert`,"aria-live":`assertive`,children:[r(`tools.approval.title`),`. `,l]}),(0,$.jsxs)(`div`,{id:o,className:`flex items-center gap-2 font-medium text-primary-800 dark:text-primary-200`,children:[(0,$.jsx)(h,{className:`h-4 w-4 shrink-0`}),r(`tools.approval.title`)]}),(0,$.jsx)(`p`,{className:`mt-1 text-primary-800/90 dark:text-primary-100/80`,children:l}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded-sm bg-white/70 p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Bt(e.toolCall.arguments)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(Z,{size:`sm`,disabled:i,onClick:()=>void c(!0,`once`),children:r(`tools.approval.allowOnce`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void c(!0,`session`),children:r(`tools.approval.allowSession`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void c(!0,`always`),children:r(`tools.approval.allowAlways`)}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>void c(!1,`once`),children:r(`tools.approval.deny`)})]})]})},Gt=({statistics:e,expanded:t,onExpandedChange:n,hideModel:r=!1,className:i})=>{let{t:a,i18n:o}=s(),c=(0,Q.useId)(),l=(e,t)=>e.toLocaleString(o.language,{minimumFractionDigits:t,maximumFractionDigits:t}),u=e=>{if(e==null)return a(`generationStats.notAvailable`);let t=e/1e6;if(t<1e3)return`${Math.round(t).toLocaleString(o.language)}ms`;let n=t/1e3;return`${l(n,2)}s`},d=e=>e?a(`generationStats.tokensPerSecond`,{value:l(e,1)}):a(`generationStats.notAvailable`),f=e.prompt_eval_count||0,p=e.eval_count||0,m=f+p,h=u(e.total_duration),g=d(e.tokens_per_second),_=[[a(`generationStats.promptTokens`),f],[a(`generationStats.generatedTokens`),p],[a(`generationStats.totalTokens`),m],[a(`generationStats.speed`),g],[a(`generationStats.promptEval`),u(e.prompt_eval_duration)],[a(`generationStats.generation`),u(e.eval_duration)],[a(`generationStats.modelLoad`),u(e.load_duration)],[a(`generationStats.totalTime`),h]];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{"data-testid":`generation-stats`,className:V(`flex min-w-0 items-center gap-3 text-xs tabular-nums text-ink-subtle`,i),children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),"aria-expanded":t,"aria-controls":c,title:a(`generationStats.details`),className:`flex items-center gap-1 rounded-md transition-colors hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,children:[(0,$.jsx)(me,{"aria-hidden":`true`,className:`h-3 w-3`}),a(`generationStats.tokenCount`,{tokens:p.toLocaleString(o.language)})]}),(0,$.jsx)(`span`,{children:g}),(0,$.jsx)(`span`,{children:h}),e.model&&!r&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate sm:max-w-48`,title:e.model,children:e.model})]}),t&&(0,$.jsxs)(`div`,{id:c,className:`mt-1.5 basis-full rounded-xl border border-line bg-surface-subtle p-3 text-xs`,children:[(0,$.jsx)(`dl`,{className:`grid max-w-md grid-cols-2 gap-x-4 gap-y-1.5`,children:_.map(([e,t])=>(0,$.jsxs)(`div`,{className:`flex gap-1 text-ink-muted`,children:[(0,$.jsx)(`dt`,{className:`font-medium text-ink`,children:e}),(0,$.jsx)(`dd`,{className:`tabular-nums`,children:t})]},e))}),e.created_at&&(0,$.jsxs)(`p`,{className:`mt-2 border-t border-line pt-2 text-ink-muted`,children:[(0,$.jsx)(`span`,{className:`font-medium text-ink`,children:a(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString(o.language)]})]})]})},Kt={maxQuestions:64,minOptions:2,maxOptions:255,minLevels:2,maxLevels:10},qt=(e=`noul`)=>({type:e,instructions:``,options:[{name:``,description:``},{name:``,description:``}],levels:[``,``,``],trueDescription:``,falseDescription:``});function Jt(e){return Object.values(e??{}).map(e=>{let t=qt(e.type);return t.instructions=e.instructions,e.type===`choice`?t.options=Object.entries(e.criteria).map(([e,t])=>({name:e,description:t??``})):e.type===`score`?t.levels=[...e.criteria]:(t.trueDescription=e.criteria?.true??``,t.falseDescription=e.criteria?.false??``),t})}function Yt(e){if(e.length>Kt.maxQuestions)return{ok:!1,error:{kind:`too-many`}};let t={};for(let[n,r]of e.entries()){let e=n+1,i=r.instructions.trim();if(!i)return{ok:!1,error:{kind:`instructions`,question:e}};if(r.type===`choice`){let n=r.options.map(e=>({name:e.name.trim(),description:e.description.trim()})).filter(e=>e.name||e.description),a=new Set(n.map(e=>e.name));if(n.some(e=>!e.name)||a.size!==n.length||n.length<Kt.minOptions||n.length>Kt.maxOptions)return{ok:!1,error:{kind:`options`,question:e}};t[`q${e}`]={type:`choice`,instructions:i,criteria:Object.fromEntries(n.map(e=>[e.name,e.description||null]))}}else if(r.type===`score`){let n=r.levels.map(e=>e.trim()).filter(Boolean);if(n.length<Kt.minLevels||n.length>Kt.maxLevels)return{ok:!1,error:{kind:`levels`,question:e}};t[`q${e}`]={type:`score`,instructions:i,criteria:n}}else{let n=r.trueDescription.trim(),a=r.falseDescription.trim();t[`q${e}`]=n||a?{type:`noul`,instructions:i,criteria:{...n?{true:n}:{},...a?{false:a}:{}}}:{type:`noul`,instructions:i}}}return{ok:!0,questions:Object.keys(t).length>0?t:void 0}}function Xt(e,t){if(!t||t.type===`refusal`)return{label:``,kind:`refusal`,distribution:[]};if(t.type===`noul`){let e=t.noul>=.5;return{label:``,kind:e?`yes`:`no`,probability:e?t.noul:1-t.noul,distribution:[{label:`yes`,probability:t.noul},{label:`no`,probability:1-t.noul}],...t.confidence===void 0?{}:{confidence:t.confidence}}}let n=Object.entries(t.probabilities).map(([e,n])=>({label:t.type===`score`?t.legend[e]??e:String(e),probability:n})).sort((e,t)=>t.probability-e.probability);if(t.type===`choice`)return{label:t.choice,kind:`choice`,probability:t.probabilities[t.choice],distribution:n,...t.confidence===void 0?{}:{confidence:t.confidence}};let r=e?.type===`score`?e.criteria.length:Object.keys(t.legend).length;return{label:n[0]?.label??``,kind:`score`,probability:n[0]?.probability,score:{value:t.score+1,max:r},distribution:n,...t.confidence===void 0?{}:{confidence:t.confidence}}}var Zt=e=>`${(Math.round(e*1e3)/10).toFixed(1)}%`;function Qt(e){let t=e?.decision;if(!t||typeof t!=`object`)return null;let n=t.kind;return n===`state`||n===`cleared`?{kind:n}:n===`answers`&&typeof t.questions==`object`&&typeof t.answers==`object`?t:null}var $t=({value:e,strong:t})=>(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`h-1.5 w-full overflow-hidden rounded-full bg-gray-100 dark:bg-dark-200`,children:(0,$.jsx)(`div`,{className:V(`h-full rounded-full`,t?`bg-primary-500 dark:bg-primary-400`:`bg-gray-300 dark:bg-dark-400`),style:{width:`${Math.max(0,Math.min(1,e))*100}%`}})}),en=({metadata:e})=>{let{t}=s();if(e.kind!==`answers`)return(0,$.jsx)(`p`,{"data-testid":`decision-result-note`,className:`text-sm text-ink-muted`,children:e.kind===`state`?t(`chat.decision.result.stateSaved`):t(`chat.decision.result.cleared`)});let n=e.usage?.inputTokens;return(0,$.jsxs)(`div`,{"data-testid":`decision-result`,className:`space-y-3`,children:[Object.entries(e.questions).map(([n,r])=>{let i=Xt(r,e.answers[n]),a=i.kind===`refusal`?t(`chat.decision.result.declined`):i.kind===`yes`?t(`chat.decision.result.yes`):i.kind===`no`?t(`chat.decision.result.no`):i.label;return(0,$.jsxs)(`section`,{className:`rounded-xl border border-line px-3 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`min-w-0 text-sm text-ink`,children:r.instructions}),(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-ink-muted`,children:t(`chat.decision.types.${r.type}`)})]}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex items-baseline gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,"data-testid":`decision-answer`,className:`text-base font-semibold text-ink`,children:a}),i.probability!==void 0&&(0,$.jsx)(`span`,{className:`text-sm tabular-nums text-primary-700 dark:text-primary-300`,children:Zt(i.probability)}),i.score&&(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-ink-muted`,children:t(`chat.decision.result.score`,{value:i.score.value.toFixed(2),max:i.score.max})})]}),i.kind!==`refusal`&&i.kind!==`yes`&&i.kind!==`no`&&i.distribution.length>1&&(0,$.jsx)(`ul`,{className:`mt-2 space-y-1`,children:i.distribution.map(e=>(0,$.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,10rem)_1fr_3.5rem] items-center gap-2 text-xs`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`truncate text-ink-muted`,children:e.label}),(0,$.jsx)($t,{value:e.probability,strong:e.label===i.label}),(0,$.jsx)(`span`,{className:`text-end tabular-nums text-ink-muted`,children:Zt(e.probability)})]},e.label))}),(i.kind===`yes`||i.kind===`no`)&&i.probability!==void 0&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)($t,{value:i.probability,strong:!0})})]},n)}),(0,$.jsxs)(`p`,{className:`text-[11px] text-ink-subtle`,children:[t(`chat.decision.result.via`,{model:e.model,provider:e.provider}),n!==void 0&&` · ${t(`chat.decision.result.inputTokens`,{tokens:n})}`]})]})},tn=Y(`components:ttsbutton`),nn=null,rn=null,an=0,on=3e5;async function sn(e=!1){let t=Date.now();return!e&&nn!==null&&t-an<on?nn:rn||(rn=(async()=>{try{let e=await Fe.getModels();return e.success&&e.data&&e.data.length>0?(nn=e.data,an=t,e.data):(nn=[],an=t,[])}catch{return nn=[],an=t,[]}finally{rn=null}})(),rn)}var cn=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:c}=s(),{preferences:l}=Ke(),[u,d]=(0,Q.useState)(`idle`),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),[g,_]=(0,Q.useState)(null),v=(0,Q.useRef)(null),b=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await sn(),n=Be(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await sn(!0)),e&&(h(t),_(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let x=()=>{b.current+=1,v.current?.cancel(),v.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`||v.current){x();return}let t=Qe();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=l.ttsSettings,a=J(m,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,u=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),p=f&&i?.voice||a?.config?.default_voice,h=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,y=Math.max(1,a?.config?.max_characters||600),x=Math.min(y,600),S=i?.streamSentences!==!1||e.length>x?Ze(e,{locale:c.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=Ye({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>Fe.generate({model:s,pluginId:u,input:e,voice:h?void 0:p||void 0,voiceProfileId:h,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});v.current=C;let w=$e(C);try{await C.play(S)}finally{w(),v.current===C&&(v.current=null)}}catch(e){if(b.current!==n)return;if(Je(e)){d(`idle`);return}if(Xe(e)){d(`blocked`);return}p(o(`ttsButton.generateFailed`)),tn.error(`TTS error:`,e),d(`error`)}};if((0,Q.useEffect)(()=>()=>{b.current+=1,v.current?.cancel(),v.current=null},[]),g===!1||g===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,ee=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||ee?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":ee||void 0,className:V(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-hidden focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,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:[ee?(0,$.jsx)(E,{className:V(w[n],`animate-spin`)}):D?(0,$.jsx)(y,{className:w[n]}):k||O?(0,$.jsx)(j,{className:w[n]}):(0,$.jsx)(de,{className:w[n]}),O&&(0,$.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},ln=80,un=5e3,dn=15e3;function fn({sessionId:e,messageId:t,thinking:n,isThinking:r,isPrivate:i}){let a=Ke(e=>e.preferences.titleSettings),o=(0,Q.useRef)(n),[s,c]=(0,Q.useState)(null),{autoTitle:l,taskModel:u,taskProviderType:d,taskProviderId:f}=a??{};return(0,Q.useEffect)(()=>{o.current=n},[n]),(0,Q.useEffect)(()=>{if(!e||!r||i||!l||!u||qe())return;let n=!1,a,s=``,p=new AbortController,m=async()=>{let r=(o.current??``).slice(-4e3).trim();if(r.length<ln||r===s){n||(a=setTimeout(()=>void m(),400));return}s=r;let i=Date.now(),l=un;try{let i=await G.summarizeThinking(e,{model:u,thinking:r,providerType:d,providerId:f},p.signal);if(!i.success||!i.data?.summary?.trim())throw Error(`Thinking summary unavailable`);n||c({sessionId:e,messageId:t,summary:i.data.summary.trim().slice(0,160)})}catch{l=dn}n||(a=setTimeout(()=>void m(),Math.max(0,l-(Date.now()-i))))};return a=setTimeout(()=>void m(),350),()=>{n=!0,clearTimeout(a),p.abort()}},[e,t,r,i,l,u,d,f]),s&&s.sessionId===e&&s.messageId===t?s.summary:null}var pn=[`accuracy`,`style`,`incomplete`,`harmful`,`formatting`],mn=Y(`components:chat-message`);function hn({role:e,user:t,persona:n,modelAvatar:r}){let{t:i}=s(),[a,o]=(0,Q.useState)(null);if(e===`assistant`){if(n)return(0,$.jsx)(`img`,{src:Le(n,64),alt:n.name,"data-testid":`chat-assistant-avatar`,onError:e=>K(e.currentTarget,n.name,64),className:`mt-0.5 h-8 w-8 shrink-0 rounded-lg object-cover`});let e=r?.trim()??``,t=e.startsWith(`data:`)&&e!==a?e:``;return(0,$.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-xs dark:border-white/9 dark:bg-dark-200 dark:text-dark-950`,children:t?(0,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>o(e)}):e?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,$.jsx)(xt,{label:null,className:`h-4 w-4`})})}let c=t?.username||i(`chatMessage.user`),l=t?.avatar?.trim()||``,u=!!l&&l!==a;return(0,$.jsx)(`div`,{role:u?void 0:`img`,"aria-label":u?void 0:c,"data-testid":`chat-user-avatar`,className:V(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,u?`border border-black/[0.07] bg-white dark:border-white/9 dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:c,children:u?(0,$.jsx)(`img`,{src:l,alt:c,className:`h-full w-full object-cover`,onError:()=>o(l)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(M,{"aria-hidden":`true`,className:`h-4 w-4`})})}var gn=Q.memo(({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onFork:a,onEditResend:o})=>{let{t:c,i18n:l}=s(),u=e.role===`user`,d=e.role===`system`,f=d&&st(e.content),m=f?e.content.slice(ht.length):e.content,h=Ke(e=>e.preferences),g=St(e=>e.user),_=X(e=>e.setSystemMessage),v=X(e=>e.rateMessage),y=X(e=>e.modelMetadata),b=X(e=>e.currentSession?.id),x=X(e=>e.currentSession?.model),w=X(e=>e.currentSession?.isPrivate===!0),T=X(e=>e.getCurrentPersona()),E=e.model||x||``,ee=E?y[E]??Object.entries(y).find(([e])=>e.slice(e.indexOf(`/`)+1)===E)?.[1]:void 0,[D,te]=(0,Q.useState)(!1),[ne,j]=(0,Q.useState)(!1),[M,P]=(0,Q.useState)(e.content),[F,se]=(0,Q.useState)(null),ce=(0,Q.useRef)(null);Ct(ce,{enabled:F!==null,onClose:()=>se(null)});let[ue,de]=(0,Q.useState)(!1),[fe,pe]=(0,Q.useState)(!1),[me,he]=(0,Q.useState)(!1),ge=(0,Q.useId)(),[_e,R]=(0,Q.useState)(`idle`),[ye,be]=(0,Q.useState)(null),[xe,Se]=(0,Q.useState)([]),[Ce,we]=(0,Q.useState)(``),[z,Ee]=(0,Q.useState)(!1),De=(0,Q.useRef)(null),B=(0,Q.useRef)(0),H=(0,Q.useRef)(t),Ae=(0,Q.useRef)(!1),je=async()=>{try{await navigator.clipboard.writeText(e.content),Tt(`success`),Ee(!0),setTimeout(()=>Ee(!1),2e3)}catch(e){mn.error(`Failed to copy message:`,e),I.error(c(`chat.message.copyFailed`))}},W=(0,Q.useMemo)(()=>Qt(e.providerMetadata),[e.providerMetadata]),{thinkingContent:Ne,thinkingStreaming:K,parsedContent:q,artifacts:Ie}=(0,Q.useMemo)(()=>{if(u||d||!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}:ke(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=rt(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,d,t]),Le=K?void 0:e.statistics?.thinking_duration_ms??et(e.id),Re=fn({sessionId:b,messageId:e.id,thinking:Ne,isThinking:K,isPrivate:w}),ze=Le===void 0?c(`chatMessage.thinking`):c(`chatMessage.thoughtFor`,{duration:tt(Le)}),Ve=(0,Q.useCallback)(async e=>{let t=B.current+1;B.current=t,De.current?.cancel(),De.current=null,R(`loading`);try{if(e){let n=await e;if(B.current!==t)return;if(n===`blocked`){R(`blocked`);return}}let n=await Fe.getModels();if(B.current!==t)return;let r=n.success&&n.data?n.data:[],i=h.ttsSettings,a=J(r,i?.model,i?.pluginId),o=Be(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,c=a?.plugin||i?.pluginId,u=o&&i?.voice||a?.config?.default_voice,d=o&&i?.voiceProfileId||void 0,f=Math.max(1,a?.config?.max_characters||600),p=Math.min(f,600),m=i?.streamSentences!==!1||q.length>p?Ze(q,{locale:l.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[q.trim()];if(m.length===0){R(`idle`);return}let g=Ye({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>Fe.generate({model:s,pluginId:c,input:e,voice:d?void 0:u||void 0,voiceProfileId:d,speed:i?.speed||1,response_format:a?.config?.default_format},{signal:t}),onStateChange:e=>{B.current===t&&R(e)}});if(B.current!==t){g.cancel();return}De.current=g;let _=$e(g);try{await g.play(m)}finally{_(),De.current===g&&(De.current=null),B.current===t&&(g.state===`ended`||g.state===`cancelled`)&&R(`idle`)}}catch(e){if(B.current!==t)return;Je(e)?R(`idle`):Xe(e)?R(`blocked`):(mn.error(`Auto-play TTS failed:`,e),R(`error`))}},[l.language,q,h.ttsSettings]);(0,Q.useEffect)(()=>{let e=H.current&&!t;H.current=t,e&&!Ae.current&&!u&&!d&&q&&h.ttsSettings?.enabled&&h.ttsSettings.autoPlay&&(Ae.current=!0,Ve())},[t,u,d,q,h.ttsSettings?.autoPlay,h.ttsSettings?.enabled,Ve]),(0,Q.useEffect)(()=>()=>{B.current+=1,De.current?.cancel(),De.current=null},[]);let He=()=>{let e=Qe();Ve(e)},Ue=()=>{B.current+=1,De.current?.cancel(),De.current=null,R(`idle`)},We=()=>f?c(`chatMessage.conversationSummary`):d?c(`chatMessage.system`):u?h.showUsername&&g?.username?g.username:c(`chatMessage.you`):T?.name?T.name:ee?.label||E||c(`chatMessage.assistant`),Ge=()=>{te(!0),P(e.content)},[qe,Y]=(0,Q.useState)(!1),nt=async()=>{if(b&&!qe){Y(!0);try{let t=await G.restoreCompaction(b,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;X.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){mn.error(`Failed to restore compacted messages:`,e),I.error(c(`chatMessage.restoreFailed`))}finally{Y(!1)}}},it=async()=>{de(!0);try{_(M),te(!1),mn.debug(`✅ System message updated:`,M)}catch(e){mn.error(`Failed to save system message:`,e)}finally{de(!1)}},at=()=>{te(!1),P(e.content)},ot=()=>{let t=M.trim();te(!1),t&&o?.(e.id,t)},ct=t=>{if(!b)return;let n=e.rating===t;v(b,e.id,n?void 0:t),w||(n?(be(null),wt.deleteFeedback(e.id).catch(()=>I.error(c(`chatMessage.feedbackFailed`)))):(Se([]),we(``),be(t===1?1:-1),wt.upsertFeedback({sessionId:b,messageId:e.id,rating:t===1?1:-1}).catch(()=>I.error(c(`chatMessage.feedbackFailed`)))))},lt=()=>{b&&ye!==null&&(wt.upsertFeedback({sessionId:b,messageId:e.id,rating:ye,tags:xe,...Ce.trim()?{comment:Ce.trim()}:{}}).catch(()=>I.error(c(`chatMessage.feedbackFailed`))),be(null))},ut=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,dt=d&&m.length>100;return(0,$.jsxs)(`div`,{className:V(`group flex py-1.5 transition-colors sm:py-2`,u?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:V(`flex min-w-0 gap-2.5 sm:gap-3`,u?`max-w-[85%] sm:max-w-[70%] wide:sm:max-w-[min(70%,56rem)]`:`w-full`),children:[!u&&!d&&(0,$.jsx)(hn,{role:`assistant`,persona:T,modelAvatar:ee?.avatar}),(0,$.jsxs)(`div`,{className:V(`min-w-0 flex-1`,u?`flex flex-col items-end`:d?`py-1.5`:`py-0.5`),children:[!u&&!d&&(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:We()}),e.model&&T?.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:Oe(e.timestamp,l.language)})]}),(0,$.jsxs)(`div`,{className:V(!u&&!d&&`text-[0.9375rem] leading-[1.65] text-ink`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/6 bg-gray-100 dark:border-white/8 dark:bg-gray-800`,children:(0,$.jsx)(`button`,{type:`button`,className:`block h-full w-full`,"aria-label":c(`chatMessage.openImage`,{number:t+1}),onClick:()=>se(e),children:(0,$.jsx)(`img`,{src:e,alt:c(`chatMessage.uploadedImageAlt`,{number:t+1}),className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`})})},t))}),u?D?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/8 bg-white p-2 shadow-xs focus-within:border-primary-500 focus-within:ring-2 focus-within:ring-primary-500/30 dark:border-white/8 dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{"aria-label":c(`chatMessage.edit`),dir:`auto`,value:M,onChange:e=>P(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||(e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),ot()):e.key===`Escape`&&at())},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-hidden dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:at,children:c(`chatMessage.cancelEditing`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:ot,children:c(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{"data-user-bubble":``,className:`rounded-2xl rounded-ee-md border border-line bg-surface-subtle px-4 py-2.5 text-ink`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):d?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/6 bg-white/55 p-3 dark:border-white/6 dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[f?(0,$.jsx)(k,{className:`h-2.5 w-2.5 opacity-50`}):(0,$.jsx)(O,{className:`h-2.5 w-2.5 opacity-50`}),c(f?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:f?(0,$.jsx)(`button`,{onClick:()=>void nt(),disabled:qe,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.restoreCompacted`),"aria-label":c(`chatMessage.restoreCompacted`),children:(0,$.jsx)(le,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):D?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:it,disabled:ue,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.saveChanges`),"aria-label":c(`chatMessage.saveChanges`),children:(0,$.jsx)(p,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:at,disabled:ue,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.cancelEditing`),"aria-label":c(`chatMessage.cancelEditing`),children:(0,$.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:Ge,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:c(`chatMessage.editSystemMessage`),"aria-label":c(`chatMessage.editSystemMessage`),children:(0,$.jsx)(oe,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),D?(0,$.jsx)(`textarea`,{"aria-label":c(`chatMessage.editSystemMessage`),dir:`auto`,value:M,onChange:e=>P(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/8 bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-hidden focus:ring-2 focus:ring-primary-500 dark:border-white/8 dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:c(`chatMessage.systemMessagePlaceholder`),disabled:ue}):(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:fe?m:ut(m)}),dt&&(0,$.jsx)(`button`,{type:`button`,"aria-expanded":fe,onClick:()=>pe(!fe),className:`mt-2 flex items-center gap-1 text-xs text-ink-muted transition-colors hover:text-ink`,children:fe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{className:`h-3 w-3`}),c(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`h-3 w-3`}),c(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(Ne||K)&&(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":me,"aria-controls":ge,onClick:()=>he(!me),className:`flex min-h-11 max-w-full items-center gap-1.5 rounded-md py-2 text-start text-xs text-ink-muted transition-colors hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/30`,children:[K?(0,$.jsx)(U,{"data-testid":`thinking-generation-indicator`}):(0,$.jsx)(ae,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{role:`status`,"aria-live":K?`polite`:`off`,"aria-atomic":`true`,className:`min-w-0 wrap-anywhere`,children:[(0,$.jsx)(`span`,{"data-testid":`thinking-summary`,dir:`auto`,className:V(`block font-medium`,K&&`animate-slide-up [animation-duration:140ms] motion-reduce:animate-none`),children:Re||(K?`${c(`chatMessage.thinking`)}…`:ze)},Re||`thinking`),Re&&!K&&(0,$.jsx)(`span`,{className:`mt-0.5 block text-ink-subtle`,children:ze})]}),me?(0,$.jsx)(A,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}):(0,$.jsx)(N,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`})]}),(0,$.jsx)(`div`,{id:ge,"data-testid":`thinking-content`,hidden:!me,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:me&&Ne&&(0,$.jsx)(Me,{content:Ne,isStreaming:K,className:`text-[13px] text-ink-muted`})})]}),W&&!t?(0,$.jsx)(en,{metadata:W}):(0,$.jsx)(Me,{content:q,isStreaming:t&&!(K&&!q)})]}),!u&&!d&&Ie.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Pe,{artifacts:Ie})}),!u&&!d&&Array.isArray(e.providerMetadata?.toolCalls)&&e.providerMetadata.toolCalls.length>0&&(0,$.jsx)(Ut,{calls:e.providerMetadata.toolCalls,className:`mt-2.5`}),!u&&!d&&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:c(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,$.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,$.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!d&&!t&&(0,$.jsxs)(`div`,{"data-testid":`message-action-row`,className:V(`flex flex-wrap 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&&(r||ne||ye!==null||[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(_e))?`sm:opacity-100`:`[@media(hover:hover)]:sm:opacity-0`,u?`mt-1 justify-end`:`mt-1.5`),children:[u&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:Oe(e.timestamp,l.language),children:[We(),` ·`,` `,Oe(e.timestamp,l.language)]}),!u&&q&&(0,$.jsx)(cn,{text:q,size:`sm`,externalPlaybackState:_e,onStopExternal:Ue,onRetryExternal:He,className:V(`transition-colors`,_e===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),u&&o&&!D&&(0,$.jsx)(`button`,{onClick:()=>{P(e.content),te(!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:c(`chatMessage.edit`),"aria-label":c(`chatMessage.edit`),children:(0,$.jsx)(oe,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:je,"aria-label":c(z?`chatMessage.copied`:`chatMessage.copyMessage`),className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:c(z?`chatMessage.copied`:`chatMessage.copyMessage`),children:z?(0,$.jsx)(ve,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(S,{className:`h-3.5 w-3.5`})}),!u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>ct(1),className:V(`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:c(`chatMessage.goodResponse`),"aria-label":c(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(Te,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>ct(-1),className:V(`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:c(`chatMessage.badResponse`),"aria-label":c(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(ie,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})}),ye!==null&&(0,$.jsxs)(`div`,{className:`ms-1 flex flex-wrap items-center gap-1 rounded-lg border border-gray-200 bg-white px-2 py-1 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`feedback-details`,children:[pn.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>Se(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:V(`rounded-full border px-2 py-0.5 text-[10px]`,xe.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":xe.includes(e),children:c(`chatMessage.feedbackTags.${e}`)},e)),(0,$.jsx)(`input`,{value:Ce,onChange:e=>we(e.target.value),placeholder:c(`chatMessage.feedbackComment`),"aria-label":c(`chatMessage.feedbackComment`),className:`w-32 rounded-sm border border-gray-300 px-1.5 py-0.5 text-[10px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,maxLength:2e3}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:lt,className:`h-6 px-2 text-[10px]`,children:c(`common.save`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>be(null),"aria-label":c(`common.close`),className:`rounded-sm p-0.5 text-ink-muted hover:text-ink`,children:(0,$.jsx)(L,{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:c(`chatMessage.regenerateResponse`),"aria-label":c(`chatMessage.regenerateResponse`),children:(0,$.jsx)(C,{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:c(`chat.fork.action`),"aria-label":c(`chat.fork.action`),"data-testid":`fork-from-message`,children:(0,$.jsx)(re,{className:`h-3.5 w-3.5`})}),!u&&e.statistics&&(0,$.jsx)(Gt,{statistics:e.statistics,expanded:ne,onExpandedChange:j,hideModel:!!(e.model&&T?.name),className:`ms-2`})]})]})]}),u&&(0,$.jsx)(hn,{role:`user`,user:g??null})]}),F&&(0,zt.createPortal)((0,$.jsxs)(`div`,{ref:ce,role:`dialog`,"aria-modal":`true`,"aria-label":c(`chatMessage.fullSizeImage`),tabIndex:-1,className:`fixed inset-0 z-9999 flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>se(null),children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":c(`common.close`),className:`absolute inset-e-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),se(null)},children:(0,$.jsx)(L,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:F,alt:c(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})});gn.displayName=`ChatMessage`;var _n=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,vn=220,yn=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>vn?`${t.slice(0,219).trimEnd()}…`:t},bn=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;r&&i&&(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Q.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:_n()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`group/rail pointer-events-none absolute inset-s-[max(0.25rem,calc(50%_-_27rem))] top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9 wide:inset-s-1`,onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 opacity-40 transition-opacity duration-150 scrollbar-none group-hover/rail:opacity-100 group-focus-within/rail:opacity-100 motion-reduce:transition-none [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===h,u=Math.abs(a-m),d=c===t.id?v:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:V(`group flex h-4 w-7 items-center outline-hidden xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-xs`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:V(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,$.jsx)(`div`,{id:v,role:`tooltip`,className:V(`pointer-events-none absolute inset-s-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:yn(_.prompt)}),_.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:yn(_.response)})]})})]})}),xn=Q.memo(({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:c,className:l})=>{let{t:u}=s();if(e.length===1){let s=e[0],c=t&&i===s.id,u=c?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(gn,{message:u,isStreaming:c,isLastAssistantMessage:a,onRegenerate:o,className:l})}return(0,$.jsxs)(`div`,{className:V(`relative py-2`,l),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-muted`,children:[(0,$.jsx)(_e,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:u(`chat.branch.variants`,{count:e.length})})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let l=e.isActive!==!1,d=t&&i===e.id,f=d?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:V(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||d?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!d&&`cursor-pointer`),role:!l&&!d?`button`:void 0,tabIndex:!l&&!d?0:void 0,"aria-label":!l&&!d?u(`chat.branch.selectVariant`,{number:s+1}):void 0,"aria-current":l||d?`true`:void 0,onClick:()=>!l&&!d&&c?.(e.id),onKeyDown:t=>{t.target!==t.currentTarget||l||d||t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),c?.(e.id))},children:[(0,$.jsxs)(`div`,{className:V(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||d?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/5 text-ink-muted dark:border-white/5`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:s+1}),d&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:u(`chat.branch.generating`)})]}),l&&!d&&(0,$.jsx)(ve,{className:`h-3 w-3`}),!l&&!d&&(0,$.jsx)(`span`,{className:`text-[10px]`,children:u(`chat.branch.select`)})]}),(0,$.jsx)(`div`,{className:V(!l&&!d&&`opacity-75`),children:(0,$.jsx)(gn,{message:f,isStreaming:d,isLastAssistantMessage:a&&(l||d),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 text-sm!`})})]},e.id)})})]})});xn.displayName=`MessageBranch`;var Sn={web_search:d,web_fetch:ge,exec:ee,browser:ge,Read:z,Write:z,Edit:z,image:m,memory_search:F,memory_get:F,working:he,thinking:he,default:he},Cn={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`},wn=({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:V(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Sn[e.name]||Sn.default,n=Cn[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:V(`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:V(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};Y(`components:chat-messages`);var Tn=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],En=e=>e.messages.every(e=>e.isActive===!1),Dn=e=>e.role===`system`&&!st(e.content),On=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,kn=e=>Math.min(120,e*.28),An=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],activeToolCalls:o,pendingToolApproval:c,onDecideToolApproval:l,className:u,onRegenerate:d,onSelectBranch:f,onEditResend:p,onFork:m,followUpSuggestions:h,onFollowUpSelect:g})=>{let{t:y}=s(),b=(0,Q.useRef)(null),x=(0,Q.useRef)(void 0),S=(0,Q.useRef)(null),C=(0,Q.useRef)(null),[w]=(0,Q.useState)(()=>new Map),T=(0,Q.useRef)(null),E=(0,Q.useRef)(0),ee=(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]),te=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<A.length;t++){let n=A[t],r=Tn(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<A.length;e++){let t=Tn(A[e]);if(t.role===`user`)break;if(t.role===`assistant`){i=t.content;break}}e.push({id:n.id,prompt:r.content,response:i})}return e},[A]),ne=te.map(e=>e.id).join(``),j=(0,Q.useMemo)(()=>ne?ne.split(``):[],[ne]),re=(0,Q.useMemo)(()=>new Set(j),[j]),ie=(0,Q.useMemo)(()=>{let e=new Map;for(let t of j)e.set(t,e=>{e?w.set(t,e):w.delete(t)});return e},[w,j]),[M,ae]=(0,Q.useState)(null),oe=(0,Q.useCallback)(()=>{let e=S.current;if(!e||j.length===0){ae(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(E.current,j.length-1);if(t<=2)n=j.length-1;else{let t=e.scrollTop+kn(e.clientHeight);for(;n<j.length-1;){let e=w.get(j[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=w.get(j[n]);if(!e||e.offsetTop<=t)break;n--}}E.current=n;let r=j[n];ae(e=>e===r?e:r)},[w,j]),N=(0,Q.useCallback)(()=>{T.current===null&&(T.current=window.requestAnimationFrame(()=>{T.current=null,oe()}))},[oe]),P=(0,Q.useCallback)(()=>{let t=S.current;if(x.current&&clearTimeout(x.current),ee.current=!1,x.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;D.current=!n,k(!n&&e.length>0),N()},[e.length,N]),F=(0,Q.useCallback)(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(P,180)},[P]),I=(0,Q.useCallback)((e=!1)=>{(!D.current||e)&&b.current?.scrollIntoView({behavior:On()})},[]),se=(0,Q.useCallback)(()=>{let t=S.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;ee.current?(D.current=!0,k(!o&&e.length>0),N(),F()):(D.current=!o,k(!o&&e.length>0),a<=2&&j.length>0?(E.current=j.length-1,ae(j[j.length-1])):N())},[j,e.length,F,N]),ce=(0,Q.useCallback)(e=>{let t=S.current,n=w.get(e);if(!t||!n)return;let r=On();ee.current=!0,D.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-kn(t.clientHeight)),behavior:r}),N(),r===`auto`?P():F()},[P,w,F,N]),le=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>le.current&&!D.current&&I(),le.current=e.length},[e.length,I]),(0,Q.useEffect)(()=>{i&&(t||n)&&!D.current&&requestAnimationFrame(()=>{let e=S.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{N();let e=C.current,t=S.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(N);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,N),()=>{n?.disconnect(),window.removeEventListener(`resize`,N)}},[ne,N]),(0,Q.useEffect)(()=>()=>{T.current!==null&&(window.cancelAnimationFrame(T.current),T.current=null)},[]),(0,Q.useEffect)(()=>()=>{x.current&&clearTimeout(x.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:V(`flex-1 flex items-center justify-center p-6 sm:p-10`,u),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-ink-muted`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/6 bg-surface/70 text-gray-500 shadow-xs dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(_,{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:y(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:y(`chatMessage.startConversationDescription`)})]})});let ue=-1;for(let e=A.length-1;e>=0;e--)if(A[e].messages.some(e=>e.role===`assistant`)){ue=e;break}return(0,$.jsxs)(`div`,{className:V(`relative min-h-0 flex-1`,u),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:S,"data-testid":`chat-scroll-viewport`,"aria-busy":i,"data-scroll-fade-top":`40`,"data-scroll-fade-bottom":`72`,onScroll:se,className:V(`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:C,"data-testid":`chat-messages-column`,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8 wide:max-w-none wide:md:px-12`,children:[A.map((e,a)=>{let o=a===ue,s=re.has(e.id),c=i&&e.messages.some(e=>e.id===r),l;if(En(e))l=(0,$.jsx)(`div`,{className:`opacity-55`,children:(0,$.jsx)(gn,{message:Tn(e),isStreaming:!1,isLastAssistantMessage:!1,className:a===0?`mt-3 sm:mt-4`:``})});else if(e.messages.length===1){let s=e.messages[0],c=i&&s.id===r,u=c?{...s,content:t??s.content,thinking:n||s.thinking}:s;l=(0,$.jsx)(gn,{message:u,isStreaming:c,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onEditResend:i?void 0:p,onFork:i?void 0:m,className:a===0?`mt-3 sm:mt-4`:``})}else l=(0,$.jsx)(xn,{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:ie.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)(Ut,{calls:o??[],className:`pb-2`}),c&&l&&(0,$.jsx)(Wt,{approval:c,onDecide:l,className:`mb-2`}),i&&a.length>0&&(0,$.jsx)(wn,{tools:a,className:`px-0`}),!i&&h&&h.length>0&&g&&(0,$.jsx)(`div`,{role:`group`,"aria-label":y(`chat.followUp`),"data-testid":`follow-up-suggestions`,className:`mt-1 flex flex-wrap gap-1.5 pb-2 ps-[2.625rem] sm:ps-11 wide:max-w-[calc(90ch+2.75rem)]`,children:h.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>g(e),dir:`auto`,className:`flex max-w-full items-start gap-1.5 rounded-2xl border border-line px-3 py-1.5 text-start text-[13px] leading-snug text-ink-muted transition-colors hover:border-line-strong hover:bg-interactive-hover hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,children:[(0,$.jsx)(v,{"aria-hidden":`true`,className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-ink-subtle rtl:-scale-x-100`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:e})]},e))}),(0,$.jsx)(`div`,{ref:b,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(bn,{items:te,activeId:M,onSelect:ce}),O&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-new-messages`,onClick:()=>{ee.current=!1,x.current&&=(clearTimeout(x.current),void 0),D.current=!1,b.current?.scrollIntoView({behavior:On()}),k(!1)},className:V(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/8`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:y(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(we,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:y(`chatMessage.newMessages`)})]})]})};function jn(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 Mn=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)(()=>jn(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:V(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute inset-e-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:V(`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)(Ee,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});Mn.displayName=`CodeAwareTextarea`;var Nn=Y(`components:media-upload`),Pn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)([]),g=async r=>{if(!r||a)return;let i=Array.from(r),o=[];for(let t of i)if(t.type.startsWith(`image/`)){let r=await _(t,n-e.length-o.length);r&&o.push(r)}else t.type.includes(`pdf`)||t.type.includes(`text`)?await v(t):I.error(c(`chat.mediaUpload.unsupportedFileType`,{name:t.name}));o.length>0&&t([...e,...o])},_=(e,t)=>t<=0?(I.error(c(`chat.mediaUpload.maxImagesAllowed`,{count:n})),Promise.resolve(null)):e.size>10485760?(I.error(c(`chat.mediaUpload.imageTooLarge`,{name:e.name})),Promise.resolve(null)):new Promise(t=>{let n=new FileReader;n.onload=()=>t(typeof n.result==`string`?n.result:null),n.onerror=()=>{I.error(c(`chat.mediaUpload.readFailed`,{name:e.name})),t(null)},n.readAsDataURL(e)}),v=async e=>{if(e.size>10485760)I.error(c(`documents.fileSizeTooLarge`));else{p(!0);try{let t=await Re.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),I.success(c(`documents.uploadSuccessWithName`,{name:e.name}))}else I.error(t.error||c(`documents.uploadFailed`))}catch(e){Nn.error(`Document upload error:`,e),I.error(c(`documents.uploadFailed`))}finally{p(!1)}}},y=e=>{e.preventDefault(),a||d(!0)},b=e=>{e.preventDefault(),d(!1)},x=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},C=async e=>{try{let t=await Re.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),I.success(c(`documents.removeSuccess`))):I.error(t.error||c(`documents.removeFailed`))}catch(e){Nn.error(`Error removing document:`,e),I.error(c(`documents.removeFailed`))}},w=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},T=e.length>0||m.length>0;return(0,$.jsxs)(`div`,{className:V(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:V(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:y,onDragLeave:b,onDrop:x,role:`button`,tabIndex:a?-1:0,"aria-disabled":a||void 0,"aria-label":`${c(`chat.mediaUpload.dropImagesHere`)} ${c(`chat.mediaUpload.browse`)}`,onClick:()=>!a&&l.current?.click(),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a||l.current?.click())},children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(E,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`,role:`status`,"aria-label":c(`chat.mediaUpload.uploading`)}):(0,$.jsx)(fe,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-ink-muted mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),T&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:c(`chat.mediaUpload.uploadAlt`,{number:t+1}),className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S(t)},"aria-label":c(`chat.mediaUpload.removeImage`,{number:t+1}),className:`absolute top-0.5 inset-e-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(z,{className:`w-4 h-4 text-red-500 shrink-0`}):(0,$.jsx)(te,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-ink-muted`,children:w(e.size)})]}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),C(e.id)},"aria-label":c(`chat.mediaUpload.removeDocument`,{name:e.filename}),className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},Fn=Y(`components:document-indicator`),In=({sessionId:e,className:t=``})=>{let{t:n}=s(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),u=(0,Q.useRef)(null),d=(0,Q.useCallback)(async()=>{try{let t=await Re.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){Fn.error(`Failed to load documents:`,e)}},[e]);if((0,Q.useEffect)(()=>{let e=setTimeout(()=>void 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),l(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let f=async e=>{l(null);try{let t=await Re.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){Fn.error(`Failed to delete document:`,e),b.error(n(`settings.documents.library.deleteFailed`))}},p=r.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{ref:u,className:`relative inline-block ${t}`,children:[a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full left-0 z-50 mb-2 w-80 max-w-[85vw] rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-xs font-medium text-gray-500 dark:text-dark-600`,children:n(`chat.documents.title`)}),(0,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,$.jsx)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-gray-50 dark:hover:bg-dark-200`,children:c===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-red-700 dark:text-red-300`,children:n(`settings.documents.library.deleteConfirm`,{name:e.filename})}),(0,$.jsx)(`button`,{onClick:()=>void f(e.id),className:`shrink-0 text-xs font-medium text-red-600 underline underline-offset-2 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:n(`common.delete`)}),(0,$.jsx)(`button`,{onClick:()=>l(null),className:`shrink-0 text-xs text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,children:n(`common.cancel`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{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:[B(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,$.jsx)(`button`,{onClick:()=>l(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,$.jsx)(L,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),l(null)},className:`
2
+ inline-flex items-center space-x-1 px-2 py-1
3
+ bg-blue-50 dark:bg-blue-900/20
4
+ border border-blue-200 dark:border-blue-800
5
+ rounded-md text-xs
6
+ transition-colors hover:bg-blue-100 dark:hover:bg-blue-900/40
7
+ `,title:`${n(`chat.documents.title`)} - ${B(p)}`,children:[(0,$.jsx)(ue,{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`]})]})]})},Ln=Y(`components:structured-output`),Rn=[{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`}],zn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),[o,c]=(0,Q.useState)(``),l=()=>Rn.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),u=()=>{let t=l();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},d=e=>{let n=l().find(t=>t.label===e);n&&(n.value===`custom`?a(!0):(a(!1),t(n.value)))};return(0,$.jsxs)(`div`,{className:V(`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)(O,{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)(W,{value:u().label,onChange:e=>d(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(je,{value:o,onChange:e=>c(e.target.value),placeholder:`{
8
+ "type": "object",
9
+ "properties": {
10
+ "field1": { "type": "string" },
11
+ "field2": { "type": "number" }
12
+ },
13
+ "required": ["field1"]
14
+ }`,rows:8,className:`font-mono text-sm`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Z,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){Ln.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(Z,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=u();return!e.value||e.value===`json`?null:(0,$.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,$.jsx)(T,{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)(z,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},Bn=7.25,Vn=2.5,Hn=2*Math.PI*Vn,Un=e=>`\u2068${e}\u2069`,Wn=({usage:e,trainedBudget:t})=>{let{t:n,i18n:r}=s(),[i,a]=(0,Q.useState)(!1),o=typeof e.budget==`number`&&e.budget>0,c=e.ratio??0,l=Math.round(c*100),u=e.measured?``:`~`,d=r.language,f=`${u}${ft(e.used,d)}`,p=o?n(`chat.context.tokensUsed`,{used:Un(f),budget:Un(ft(e.budget,d))}):n(`chat.context.tokensUsedNoBudget`,{used:Un(f)}),m=t===void 0?void 0:n(`chat.context.capped`,{trained:Un(ft(t,d))}),h=[n(`chat.context.title`),o?n(`chat.context.full`,{percent:l}):void 0,p,m].filter(Boolean).join(` `),g=Math.min(c,1),_=new Intl.NumberFormat(d,{style:`percent`,maximumFractionDigits:0}).format(c);return(0,$.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onFocus:()=>a(!0),onBlur:()=>a(!1),onKeyDown:e=>{e.key===`Escape`&&a(!1)},children:[(0,$.jsxs)(`span`,{role:o?`meter`:`img`,tabIndex:0,"aria-label":h,...o?{"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(l,100),"aria-valuetext":h}:{},className:V(`touch-target relative flex h-9 min-w-9 items-center justify-center gap-1 rounded-full px-1 text-ink-muted outline-hidden`,`transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/40`,c>=.8&&c<1&&`text-amber-600 dark:text-amber-400`,c>=1&&`text-red-600 dark:text-red-400`),children:[(0,$.jsxs)(`svg`,{viewBox:`0 0 18 18`,"aria-hidden":`true`,className:`h-4 w-4 shrink-0 -rotate-90`,children:[(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:Bn,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,className:`opacity-60`,...o?{}:{strokeDasharray:`2 2`}}),o&&g>0&&(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:Vn,fill:`none`,stroke:`currentColor`,strokeWidth:Vn*2,strokeDasharray:Hn,strokeDashoffset:Hn*(1-g)})]}),o&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-[11px] tabular-nums`,children:Un(_)}),c>=.8&&(0,$.jsx)(P,{className:`absolute inset-e-0 top-0 h-3 w-3`})]}),i&&(0,$.jsxs)(`div`,{role:`tooltip`,className:V(`pointer-events-none absolute bottom-full left-1/2 z-30 mb-2 -translate-x-1/2`,`whitespace-nowrap rounded-2xl bg-surface/95 px-4 py-3 text-center shadow-lv3 backdrop-blur-xl`,`border border-black/6 dark:border-white/8 dark:bg-dark-100/95`,`animate-scale-in`),children:[(0,$.jsx)(`p`,{className:`text-[13px] text-ink-muted`,children:n(`chat.context.title`)}),o&&(0,$.jsx)(`p`,{className:`text-[13px] text-ink-muted`,children:n(`chat.context.full`,{percent:l})}),(0,$.jsx)(`p`,{className:`text-[13px] tabular-nums text-gray-900 dark:text-dark-900`,children:p}),m&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-ink-muted`,children:m})]})]})},Gn=Y(`components:prompt-queue`),Kn=({sessionId:e,queue:t})=>{let{t:n}=s(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),c=t=>it(e,t),l=async t=>{try{let n=await G.claimQueuedPrompt(e,t);n.success&&n.data&&c(n.data.queue)}catch(e){Gn.error(`Failed to remove queued prompt:`,e)}},u=async(n,r)=>{let i=t.findIndex(e=>e.id===n),a=i+r;if(i===-1||a<0||a>=t.length)return;let o=t.map(e=>e.id);[o[i],o[a]]=[o[a],o[i]];try{let t=await G.reorderPromptQueue(e,o);t.success&&t.data&&c(t.data.queue)}catch(e){Gn.error(`Failed to reorder the prompt queue:`,e)}},d=async t=>{let r=a.trim();if(r)try{let a=await G.updateQueuedPrompt(e,t,r);a.success&&a.data?(c(a.data.queue),i(null)):I.error(a.error||n(`chat.queue.updateFailed`))}catch(e){Gn.error(`Failed to update the queued prompt:`,e),I.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 wide:max-w-none`,"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)(f,{className:`h-3 w-3`}),n(`chat.queue.title`,{total:t.length})]}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:t.map((e,s)=>(0,$.jsx)(`li`,{className:`flex items-center gap-1.5 rounded-lg border border-black/6 bg-surface/70 px-2 py-1 dark:border-white/8 dark:bg-dark-200/70`,"data-testid":`prompt-queue-entry`,children:r===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:t=>{t.key===`Enter`&&d(e.id),t.key===`Escape`&&i(null)},className:`min-w-0 flex-1 bg-transparent text-[13px] text-gray-900 focus:outline-hidden dark:text-dark-900`,"data-testid":`prompt-queue-edit-input`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void d(e.id),className:`rounded-md p-1 text-green-600 hover:bg-green-50 dark:hover:bg-green-900/20`,"aria-label":n(`common.save`),children:(0,$.jsx)(ve,{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)(we,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{i(e.id),o(e.content)},className:`rounded-md p-1 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`common.edit`),children:(0,$.jsx)(R,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void l(e.id),className:`rounded-md p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,"aria-label":n(`common.delete`),children:(0,$.jsx)(L,{className:`h-3 w-3`})})]})},e.id))})]})},qn=(e,t)=>e.filter(ut).map(e=>({model:e,key:pt(e)})).filter(e=>e.key!==t),Jn=(e,t)=>{let n=[];for(let r of t){let t=yt(e,r);t&&n.push({model:t.model,providerType:t.providerType??null,providerId:t.providerId??null})}return n},Yn=({models:e,currentModelKey:t,selectedKeys:n,onChange:r,open:i,onOpenChange:a,disabled:o=!1})=>{let{t:c}=s(),l=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{l.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i,a]);let u=qn(e,t);if(u.length===0)return null;let d=e=>{n.includes(e)?r(n.filter(t=>t!==e)):n.length<3&&r([...n,e])};return(0,$.jsxs)(`div`,{className:`relative`,ref:l,children:[(0,$.jsxs)(Z,{type:`button`,variant:`ghost`,size:`sm`,disabled:o,onClick:()=>a(!i),className:V(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,n.length>0&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:c(`chat.compare.title`),"aria-pressed":n.length>0,"aria-expanded":i,"data-testid":`composer-compare-toggle`,children:[(0,$.jsx)(g,{className:`h-4 w-4`}),n.length>0&&(0,$.jsxs)(`span`,{className:`absolute -inset-e-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white`,children:[`+`,n.length]})]}),i&&(0,$.jsxs)(`div`,{className:`absolute bottom-full inset-s-0 z-30 mb-2 max-h-72 w-72 overflow-y-auto rounded-xl border border-gray-200 bg-white p-2 shadow-lg scrollbar-thin dark:border-dark-200 dark:bg-dark-50`,role:`menu`,"data-testid":`composer-compare-menu`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium text-gray-400 dark:text-dark-500`,children:c(`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:V(`flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-800 hover:bg-gray-50 dark:text-dark-800 dark:hover:bg-dark-100`,i&&`cursor-not-allowed opacity-40`),children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:r,disabled:i,onChange:()=>d(t),className:`h-3.5 w-3.5 rounded-sm border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate`,children:e.name})]},t)})]})]})},Xn=`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(`,`),Zn=/^\/([a-z0-9-]*)$/,Qn=/(?:^|\s)\$([a-z0-9-]*)$/,$n=8,er=(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??``}),tr=({prompt:e,onCancel:t,onInsert:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(()=>Object.fromEntries(e.variables.map(e=>[e.name,e.default??(e.type===`boolean`?`false`:``)]))),o=e.variables.filter(e=>e.required===!0&&(i[e.name]===void 0||i[e.name]===``));return(0,$.jsxs)(`div`,{className:`p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-gray-700 dark:text-gray-200`,children:r(`composer.variables.title`,{title:e.title})}),(0,$.jsx)(`div`,{className:`mt-2 flex max-h-56 flex-col gap-2 overflow-y-auto`,children:e.variables.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,dir:`ltr`,children:[e.label||e.name,e.required?` *`:``]}),e.type===`select`?(0,$.jsxs)(`select`,{value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`option`,{value:``,children:`—`}),(e.options??[]).map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))]}):e.type===`boolean`?(0,$.jsxs)(`select`,{value:i[e.name]??`false`,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`option`,{value:`true`,children:r(`common.yes`)}),(0,$.jsx)(`option`,{value:`false`,children:r(`common.no`)})]}):(0,$.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`})]},e.name))}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:t,children:r(`composer.variables.cancel`)}),(0,$.jsx)(Z,{size:`sm`,disabled:o.length>0,title:o.length>0?r(`composer.variables.required`,{name:o[0]?.name??``}):void 0,onClick:()=>n(er(e.content,e.variables,i)),children:r(`composer.variables.insert`)})]})]})},nr=(0,Q.forwardRef)(({message:e,disabled:t=!1,onApply:n},r)=>{let{t:i}=s(),[a,o]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),[f,p]=(0,Q.useState)(null),m=(0,Q.useRef)({prompts:!1,skills:!1}),h=t?null:Zn.exec(e),g=t||h?null:Qn.exec(e),v=h!==null,y=g!==null;(0,Q.useEffect)(()=>{v&&!m.current.prompts&&(m.current.prompts=!0,Ve.list().then(e=>{o(t=>e.success&&e.data?e.data:t??[])}).catch(()=>o(e=>e??[])).finally(()=>{m.current.prompts=!1}))},[v]),(0,Q.useEffect)(()=>{y&&!m.current.skills&&(m.current.skills=!0,Ie.list().then(e=>{l(t=>e.success&&e.data?e.data:t??[])}).catch(()=>l(e=>e??[])).finally(()=>{m.current.skills=!1}))},[y]);let b=(0,Q.useMemo)(()=>{if(h){let e=h[1];return(a??[]).filter(t=>t.slug.startsWith(e)).slice(0,$n).map(e=>({kind:`prompt`,key:e.id,slug:e.slug,label:e.title,detail:e.description,prompt:e}))}if(g){let e=g[1];return(c??[]).filter(t=>t.enabled&&t.slug.startsWith(e)).slice(0,$n).map(e=>({kind:`skill`,key:e.id,slug:e.slug,label:e.name,detail:e.description,skill:e}))}return[]},[h,g,a,c]),[x,S]=(0,Q.useState)(e);e!==x&&(S(e),d(0),!h&&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)}else if(g){let t=e.length-(g[1].length+1);n(`${e.slice(0,t)}$${r.slug} `)}}};if((0,Q.useImperativeHandle)(r,()=>({handleKeyDown(t){return f?t.key===`Escape`?(t.preventDefault(),p(null),!0):t.key===`Enter`: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)(tr,{prompt:f,onCancel:()=>p(null),onInsert:e=>{p(null),n(e)}})});let w=h?`prompt`:g?`skill`:null,T=h?a!==null:c!==null,E=h?h[1]===``:g?g[1]===``:!1;return 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(h?`composer.promptMenu.label`:`composer.skillMenu.label`),className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-suggestions`,children: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:V(`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)(pe,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(_,{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))})});nr.displayName=`ComposerSuggestions`;var rr=(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},ir=({value:e,onChange:t,disabled:n=!1,buttonClassName:r})=>{let{t:i}=s(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=!1;return q.getCatalog().then(t=>{!e&&t.success&&t.data&&(d(t.data.available&&t.data.tools.length>0),l(t.data.tools))}).catch(()=>{}),()=>{e=!0}},[a]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{f.current?.contains(e.target)||o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]);let[p,m]=(0,Q.useState)(void 0);if((0,Q.useLayoutEffect)(()=>{if(!a)return;let e=()=>{let e=f.current;if(!e)return;let t=e.getBoundingClientRect().top,n=0;for(let t=e.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e,overflowX:r}=getComputedStyle(t);(e!==`visible`||r!==`visible`)&&(n=Math.max(n,t.getBoundingClientRect().top))}m(Math.max(160,Math.floor(t-n-24)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[a]),!u||!c)return null;let h=c.filter(e=>e.source===`builtin`),g=new Map;for(let e of c)e.serverId&&g.set(e.serverId,e.serverName??e.serverId);let _=[...g.entries()],v=h.map(e=>e.name),y=_.map(([e])=>e),b=new Set(e.builtinTools??v),x=new Set(e.serverIds??y),S=(n,r,i,a,o)=>(0,$.jsxs)(`label`,{className:V(`flex cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-sm hover:bg-gray-50 dark:hover:bg-dark-100`,!e.enabled&&`opacity-50`),onClickCapture:e.enabled?void 0:n=>{n.preventDefault(),n.stopPropagation(),t({...e,enabled:!0})},children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a,disabled:!e.enabled,onChange:o,"data-testid":`composer-tool-option`,className:`mt-0.5 h-3.5 w-3.5 accent-primary-600`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-gray-800 dark:text-gray-200`,dir:`ltr`,children:r}),i&&(0,$.jsx)(`span`,{className:`block truncate text-xs text-gray-500 dark:text-gray-400`,children:i})]})]},n);return(0,$.jsxs)(`div`,{ref:f,className:`relative shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,disabled:n,onClick:()=>o(e=>!e),className:V(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,e.enabled&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`,r),title:e.enabled?i(`chat.input.toolsOn`):i(`chat.input.toolsOff`),"aria-pressed":e.enabled,"aria-expanded":a,"data-testid":`composer-tools-button`,children:(0,$.jsx)(he,{className:`h-4 w-4`})}),a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full inset-s-0 z-30 mb-2 flex w-72 flex-col rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-200 dark:bg-dark-50`,style:{maxHeight:p},"data-testid":`composer-tools-menu`,children:[(0,$.jsxs)(`label`,{className:`flex shrink-0 cursor-pointer items-center justify-between gap-2 rounded-lg px-2 py-1.5 text-sm font-medium text-gray-800 dark:text-gray-200`,children:[i(`composer.toolsMenu.enable`),(0,$.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>t({...e,enabled:!e.enabled}),"data-testid":`composer-tools-enable`,className:`h-3.5 w-3.5 accent-primary-600`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,"data-testid":`composer-tools-options`,children:[h.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.builtin`)}),h.map(n=>S(n.name,n.name,void 0,b.has(n.name),()=>t({...e,enabled:!0,builtinTools:rr(e.builtinTools,v,n.name)})))]}),_.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.servers`)}),_.map(([n,r])=>S(n,r,void 0,x.has(n),()=>t({...e,enabled:!0,serverIds:rr(e.serverIds,y,n)})))]})]}),(0,$.jsx)(`p`,{className:`mt-1 shrink-0 border-t border-gray-100 px-2 pb-0.5 pt-1.5 text-[11px] leading-4 text-gray-400 dark:border-dark-200 dark:text-dark-500`,children:i(`composer.toolsMenu.hint`)})]})]})},ar={enabled:!1,builtinTools:null,serverIds:null},or=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}:{}}},sr=[`noul`,`choice`,`score`],cr=({questions:e,onSave:t,disabled:n=!1})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),o=Object.values(e??{});return(0,$.jsxs)(`div`,{"data-testid":`decision-questions-bar`,className:`mb-2 flex items-start gap-2 rounded-xl border border-line bg-surface-raised px-3 py-2 text-xs text-ink-muted`,children:[(0,$.jsx)(c,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary-600 dark:text-primary-400`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium text-ink`,children:r(`chat.decision.barTitle`)}),o.length===0?(0,$.jsx)(`p`,{className:`mt-0.5 leading-5`,children:r(`chat.decision.interactiveHint`)}):(0,$.jsx)(`ul`,{className:`mt-1 flex flex-wrap gap-1.5`,children:o.map((e,t)=>(0,$.jsxs)(`li`,{dir:`auto`,className:`max-w-full truncate rounded-md bg-primary-50 px-2 py-0.5 text-primary-700 dark:bg-primary-900/30 dark:text-primary-300`,title:e.instructions,children:[(0,$.jsx)(`span`,{className:`me-1 opacity-70`,children:r(`chat.decision.types.${e.type}`)}),e.instructions]},t))})]}),(0,$.jsx)(Z,{size:`sm`,variant:`outline`,disabled:n,onClick:()=>a(!0),"data-testid":`decision-questions-edit`,children:o.length===0?r(`chat.decision.add`):r(`chat.decision.edit`)}),i&&(0,$.jsx)(ur,{questions:e,onClose:()=>a(!1),onSave:async e=>{await t(e),a(!1)}})]})},lr=(e,t)=>t.kind===`too-many`?e(`chat.decision.errors.tooMany`,{max:Kt.maxQuestions}):e(`chat.decision.errors.${t.kind}`,{number:t.question}),ur=({questions:e,onClose:t,onSave:n})=>{let{t:r}=s(),i=(0,Q.useId)(),a=(0,Q.useId)(),[o,c]=(0,Q.useState)(()=>{let t=Jt(e);return t.length>0?t:[qt()]}),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(!1),p=(e,t)=>{u(null),c(n=>n.map((n,r)=>r===e?t(n):n))},m=async e=>{let t=Yt(e);if(!t.ok)u(lr(r,t.error));else{f(!0);try{await n(t.questions)}finally{f(!1)}}};return(0,$.jsxs)(Ae,{titleId:i,title:r(`chat.decision.dialogTitle`),subtitle:r(`chat.decision.dialogSubtitle`),onClose:t,widthClassName:`max-w-2xl`,testId:`decision-questions-dialog`,footer:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{variant:`ghost`,disabled:d,onClick:()=>void m([]),"data-testid":`decision-questions-interactive`,children:r(`chat.decision.useInteractive`)}),(0,$.jsx)(Z,{variant:`outline`,disabled:d,onClick:t,children:r(`common.cancel`)}),(0,$.jsx)(Z,{disabled:d,onClick:()=>void m(o),"data-testid":`decision-questions-save`,children:r(`common.save`)})]}),children:[o.map((e,t)=>{let n=`${a}-${t}`;return(0,$.jsxs)(`fieldset`,{className:`space-y-3 rounded-2xl border border-line p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium text-ink`,children:r(`chat.decision.questionNumber`,{number:t+1})}),(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`chat.decision.removeQuestion`),title:r(`chat.decision.removeQuestion`),onClick:()=>c(e=>e.filter((e,n)=>n!==t)),className:`rounded-lg p-1.5 text-ink-muted hover:bg-interactive-hover hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500`,children:(0,$.jsx)(xe,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{role:`radiogroup`,"aria-label":r(`chat.decision.typeLabel`),className:`flex flex-wrap gap-1.5`,children:sr.map(n=>(0,$.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":e.type===n,onClick:()=>p(t,e=>({...e,type:n})),className:V(`rounded-full px-2.5 py-1 text-xs font-medium transition-colors`,e.type===n?`bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-300`:`bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-200 dark:text-gray-400 dark:hover:bg-dark-300`),children:r(`chat.decision.types.${n}`)},n))}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`${n}-q`,className:Ne,children:r(`chat.decision.question`)}),(0,$.jsx)(`input`,{id:`${n}-q`,dir:`auto`,value:e.instructions,placeholder:r(`chat.decision.placeholders.${e.type}`),onChange:e=>p(t,t=>({...t,instructions:e.target.value})),className:H})]}),e.type===`noul`&&(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[`trueDescription`,`falseDescription`].map(i=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`${n}-${i}`,className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:r(i===`trueDescription`?`chat.decision.yesMeans`:`chat.decision.noMeans`)}),(0,$.jsx)(`input`,{id:`${n}-${i}`,dir:`auto`,value:e[i],onChange:e=>p(t,t=>({...t,[i]:e.target.value})),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`})]},i))}),e.type===`choice`&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:r(`chat.decision.options`)}),e.options.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{dir:`auto`,"aria-label":r(`chat.decision.optionName`,{number:n+1}),placeholder:r(`chat.decision.optionNamePlaceholder`),value:e.name,onChange:e=>p(t,t=>({...t,options:t.options.map((t,r)=>r===n?{...t,name:e.target.value}:t)})),className:V(`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`,`w-2/5`)}),(0,$.jsx)(`input`,{dir:`auto`,"aria-label":r(`chat.decision.optionDescription`,{number:n+1}),placeholder:r(`chat.decision.optionDescriptionPlaceholder`),value:e.description,onChange:e=>p(t,t=>({...t,options:t.options.map((t,r)=>r===n?{...t,description:e.target.value}:t)})),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`chat.decision.removeOption`,{number:n+1}),onClick:()=>p(t,e=>({...e,options:e.options.filter((e,t)=>t!==n)})),className:`shrink-0 rounded-lg p-1.5 text-ink-muted hover:bg-interactive-hover hover:text-ink`,children:(0,$.jsx)(L,{className:`h-4 w-4`})})]},n)),e.options.length<Kt.maxOptions&&(0,$.jsxs)(Z,{size:`sm`,variant:`ghost`,onClick:()=>p(t,e=>({...e,options:[...e.options,{name:``,description:``}]})),children:[(0,$.jsx)(ye,{className:`me-1 h-3.5 w-3.5`}),r(`chat.decision.addOption`)]})]}),e.type===`score`&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 block text-[11px] font-medium uppercase tracking-wide text-ink-muted rtl:normal-case rtl:tracking-normal`,children:r(`chat.decision.levels`)}),e.levels.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`w-5 shrink-0 text-end text-xs tabular-nums text-ink-muted`,children:n+1}),(0,$.jsx)(`input`,{dir:`auto`,"aria-label":r(`chat.decision.levelLabel`,{number:n+1}),placeholder:r(`chat.decision.levelPlaceholder`),value:e,onChange:e=>p(t,t=>({...t,levels:t.levels.map((t,r)=>r===n?e.target.value:t)})),className:`w-full rounded-lg border border-line bg-surface-raised px-2.5 py-1.5 text-[13px] text-ink placeholder:text-ink-muted transition-[border-color,box-shadow] duration-150 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:focus:border-primary-400 dark:focus:ring-primary-400/30`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":r(`chat.decision.removeLevel`,{number:n+1}),onClick:()=>p(t,e=>({...e,levels:e.levels.filter((e,t)=>t!==n)})),className:`shrink-0 rounded-lg p-1.5 text-ink-muted hover:bg-interactive-hover hover:text-ink`,children:(0,$.jsx)(L,{className:`h-4 w-4`})})]},n)),e.levels.length<Kt.maxLevels&&(0,$.jsxs)(Z,{size:`sm`,variant:`ghost`,onClick:()=>p(t,e=>({...e,levels:[...e.levels,``]})),children:[(0,$.jsx)(ye,{className:`me-1 h-3.5 w-3.5`}),r(`chat.decision.addLevel`)]})]})]},t)}),o.length<Kt.maxQuestions&&(0,$.jsxs)(Z,{variant:`outline`,onClick:()=>c(e=>[...e,qt()]),"data-testid":`decision-questions-add`,children:[(0,$.jsx)(ye,{className:`me-1 h-4 w-4`}),r(`chat.decision.addQuestion`)]}),l&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-red-600 dark:text-red-400`,children:l})]})},dr=Y(`components:chat-input`),fr=560,pr=({onSendMessage:e,onStopGeneration:t,onCancelComparison:n,onOpenVoiceMode:r,disabled:i=!1})=>{let{t:a}=s(),[o,c]=(0,Q.useState)(``),u=(0,Q.useRef)(``),[d,f]=(0,Q.useState)([]),[p,h]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(!1),[T,ee]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)([]),[k,A]=(0,Q.useState)(!1),te=X(e=>e.pendingComparisons),j=X(e=>e.modelMetadata),[re,ie]=(0,Q.useState)(ar),M=X(e=>e.currentSession?.isPrivate===!0);(0,Q.useEffect)(()=>{let e=!1;return Ue.getConfig().then(t=>{!e&&t.success&&t.data&&w(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[ae,oe]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)([]),[se,le]=(0,Q.useState)(!1),[de,fe]=(0,Q.useState)(!1),[pe,me]=(0,Q.useState)(null),[he,_e]=(0,Q.useState)(!1),R=(0,Q.useRef)(null),xe=(0,Q.useRef)(null),we=(0,Q.useRef)(null),[Te,Ee]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=we.current;if(!e)return;let t=new ResizeObserver(t=>{let n=t[0]?.contentRect.width??e.clientWidth;Ee(n<fr)});return t.observe(e),()=>t.disconnect()},[]);let{isGenerating:De}=Ke(),Oe=Ke(e=>e.preferences.generationOptions),B=Ke(e=>e.preferences.imageGenSettings?.enabled===!0),ke=B&&he,{currentSession:H,models:U}=X(),Ae=pe&&pe.id===H?.personaId?pe:null,je=Ke(e=>H?.model?e.preferences.modelGenerationOptions?.[H.model]:void 0),W=H?.id,[Me,Ne]=(0,Q.useState)(W);Me!==W&&(Ne(W),O([]),A(!1));let Pe=(0,Q.useRef)(null),K=(0,Q.useRef)(null),Fe=(0,Q.useMemo)(()=>lt({model:H?.model??``,personaId:H?.personaId,providerType:H?.providerType,providerId:H?.providerId}),[H?.model,H?.personaId,H?.providerId,H?.providerType]),q=(0,Q.useMemo)(()=>bt(U,Fe),[U,Fe]),Ie=Fe.model?mt(q,Fe):``,Le=ot(U,Fe),J=dt(U,Fe)?.isDecision===!0,Be=C&&!J;(0,Q.useEffect)(()=>{let e=!1;return B&&(async()=>{try{let t=await We.getPlugins();if(e)return;_e(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;_e(!1)}})(),()=>{e=!0}},[B]),(0,Q.useEffect)(()=>{if(!x)return;let e=e=>{R.current&&!R.current.contains(e.target)&&(S(!1),oe(null))},t=e=>{e.key!==`Escape`||e.defaultPrevented||(S(!1),oe(null),P(!1),R.current?.querySelector(`button`)?.focus())};return window.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[x]);let Ve=()=>{S(!1),oe(null),P(!1)};(0,Q.useEffect)(()=>{if(!N)return;let e=!1;return Re.getCollections().then(t=>{!e&&t.success&&t.data&&I(t.data)}).catch(()=>{}),()=>{e=!0}},[N]);let He=H?.settings?.generationOptions?.think,qe=je?.think??Oe?.think??null,Y=(0,Q.useMemo)(()=>U.find(e=>e.name===H?.model),[U,H?.model]),[Je,Ye]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=H?.model;if(!e||U.length===0||!Y||Y.isPlugin||Y.isAgent)return;let t=!1;return Ge.getModelDefaults(e).then(n=>{!t&&n.success&&n.data&&Ye({model:e,supportsThinking:n.data.supportsThinking,options:n.data.options??{},trainedContextLength:n.data.trainedContextLength,contextCapped:n.data.contextCapped})}).catch(()=>{}),()=>{t=!0}},[Y,H?.model,U.length]);let Xe=Je?.model===H?.model?Je:null,Ze=Xe?.supportsThinking,$e=!!(H&&!J&&!Y?.isAgent&&(Y?.isPlugin?Y.reasoningSupport!==!1:Ze!==!1)),et=gt({model:Y,sessionOptions:H?.settings?.generationOptions,pinnedOptions:je,modelDefaults:Xe?.options,globalOptions:Oe}),tt=X(e=>e.contextWindowMessages),nt=(0,Q.useMemo)(()=>vt({messages:H?.messages??[],budget:et,systemPrompt:Ae?.parameters?.system_prompt,windowMessages:tt}),[et,tt,Ae,H?.messages]),rt=(e,t,n)=>{let r=e=>({...e,[t]:n});X.setState(t=>({currentSession:t.currentSession?.id===e?{...t.currentSession,settings:r(t.currentSession.settings)}:t.currentSession,sessions:t.sessions.map(t=>t.id===e?{...t,settings:r(t.settings)}:t)}))},at=async e=>{if(!H)return;let t=H.settings?.decisionQuestions,n={...H.settings};if(e?n.decisionQuestions=e:delete n.decisionQuestions,X.setState(e=>({currentSession:e.currentSession?.id===H.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===H.id?{...e,settings:n}:e)})),!H.isPrivate)try{let e=await G.updateSession(H.id,{settings:n});if(!e.success)throw Error(e.error);b.success(a(`chat.decision.saved`))}catch(e){dr.error(`Failed to save the decision questions:`,e),rt(H.id,`decisionQuestions`,t),b.error(a(`chat.decision.saveFailed`))}},st=async e=>{if(!H)return;let t={...H.settings?.generationOptions??{}};e===null?delete t.think:t.think=e;let n={...H.settings,generationOptions:t};if(X.setState(e=>({currentSession:e.currentSession?.id===H.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===H.id?{...e,settings:n}:e)})),!H.isPrivate)try{await G.updateSession(H.id,{settings:n})}catch(e){dr.error(`Failed to update the thinking setting:`,e),rt(H.id,`generationOptions`,H.settings?.generationOptions),b.error(a(`chat.input.thinkingUpdateFailed`))}},ct=H?.settings?.knowledgeCollectionIds??[],ut=async e=>{if(!H)return;let t=ct.includes(e)?ct.filter(t=>t!==e):[...ct,e],n={...H.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(X.setState(e=>({currentSession:e.currentSession?.id===H.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===H.id?{...e,settings:n}:e)})),!H.isPrivate)try{await G.updateSession(H.id,{settings:n})}catch(e){dr.error(`Failed to update knowledge collections:`,e),rt(H.id,`knowledgeCollectionIds`,H.settings?.knowledgeCollectionIds),b.error(a(`chat.input.menu.attachFailed`))}},ft=Ot({onStart:()=>{u.current=o},onText:e=>{let t=u.current;c(t?`${t} ${e}`:e)},ownerKey:W}),ht=ft.phase===`starting`,xt=ft.phase===`recording`,St=ft.phase===`transcribing`,Ct=ft.supported,wt=ft.providerModel,Tt=ft.sources.filter(e=>e.kind===`provider`),kt=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){Ve(),fe(!0);try{let e=await Re.uploadDocument(t,H?.id);e.success?(b.success(a(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):b.error(e.error||a(`chat.input.menu.attachFailed`))}catch(e){dr.error(`Document upload failed:`,e),b.error(a(`chat.input.menu.attachFailed`))}finally{fe(!1)}}},At=async()=>{let e=ae?.trim();if(e&&!se){le(!0);try{let t=await Re.fetchWebpage(e,H?.id);t.success?(b.success(a(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),Ve()):b.error(t.error||a(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.input.menu.attachFailed`);dr.error(`Webpage attach failed:`,e),b.error(t)}finally{le(!1)}}},jt=async e=>{if(W&&!M)try{let t=await G.enqueuePrompt(W,e);t.success&&t.data?(it(W,t.data.queue),c(``)):b.error(t.error||a(`chat.queue.enqueueFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.queue.enqueueFailed`);dr.error(`Failed to queue the prompt:`,e),b.error(t)}},Ft=t=>{if(t.preventDefault(),!o.trim())return;if(De){d.length===0&&!M&&W&&jt(o.trim());return}if(!Le){b.error(a(`chat.model.selectBeforeSending`));return}let n=M||J?{}:or(re),r=M||J?[]:Jn(U,D);e(o.trim(),d.length>0?d:void 0,J?void 0:p||void 0,Be&&T?!0:void 0,n.tools,n.toolSelection,r.length>0?r:void 0),c(``),f([])},It=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||K.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ft(e))},Lt=()=>{t()};(0,Q.useEffect)(()=>{let e=Pe.current;e&&(e.style.height=`auto`,e.style.height=o?`${Math.min(e.scrollHeight,200)}px`:``)},[o]),(0,Q.useEffect)(()=>{let e=H?.id,t=H?.personaId;if(!e||!t)return;let n=!1,r=()=>{let{currentSession:t,setCurrentSession:n}=X.getState();t?.id===e&&n({...t,personaId:void 0})};return(async()=>{try{let e=await ze.getPersona(t);if(n)return;e.success&&e.data?me(e.data):(dr.warn(`Persona ${t} not found, clearing reference`),r())}catch(e){if(n)return;dr.error(`Failed to load current persona:`,e),r()}})(),()=>{n=!0}},[H?.id,H?.personaId]);let Rt=async e=>{let t=yt(q,e.target.value);if(t&&H)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await ze.getPersona(e);if(!n.success||!n.data){b.error(a(`chat.persona.loadFailed`));return}let r=await G.updateSession(H.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(r.success&&r.data){let{sessions:e}=X.getState(),t=e.map(e=>e.id===H.id?r.data:e);X.setState({sessions:t,currentSession:r.data}),b.success(a(`chat.persona.applied`))}}else{let e=await G.updateSession(H.id,{model:t.model,providerType:t.providerType,providerId:(t.providerType===`plugin`||t.providerType===`agent`)&&t.providerId||null,personaId:null});if(e.success&&e.data){let{sessions:t}=X.getState(),n=t.map(t=>t.id===H.id?e.data:t);X.setState({sessions:n,currentSession:e.data}),b.success(a(`chat.model.updated`))}}}catch(e){dr.error(`Failed to update session:`,e),b.error(a(`chat.toasts.updateFailed`))}},zt=d.length>0||p!==null,Bt=Ae?.name||Mt(q.find(e=>pt(e)===Ie),j),Vt=H?_t(lt(H)):``,Ht=!M&&!J&&!!H&&qn(U,Vt).length>0,Ut=a(T?`chat.input.webSearchOn`:`chat.input.webSearchOff`),Wt=St||ht?a(`common.cancel`):xt?a(`chat.input.voiceStop`):wt?a(`chat.input.providerTranscriptionDisclosure`,{provider:wt.plugin}):a(`chat.input.voiceInput`);return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{ref:we,className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8 wide:max-w-none wide:md:px-12`,children:[_&&(0,$.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/8 dark:bg-dark-200/90`,children:[(0,$.jsx)(Pn,{images:d,onImagesChange:f,maxImages:5,sessionId:H?.id,disabled:i}),!J&&(0,$.jsx)(zn,{format:p,onFormatChange:h})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[W&&!M&&(H?.settings?.promptQueue?.length??0)>0&&(0,$.jsx)(Kn,{sessionId:W,queue:H.settings.promptQueue}),W&&te.some(e=>e.sessionId===W)&&(0,$.jsx)(`div`,{className:`mx-auto mb-1.5 flex w-full max-w-3xl flex-wrap gap-1.5 px-1 wide:max-w-none`,"data-testid":`pending-comparisons`,children:te.filter(e=>e.sessionId===W).map(e=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-2.5 py-1 text-[12px] text-gray-600 dark:border-white/8 dark:bg-dark-200/70 dark:text-dark-700`,"data-testid":`pending-comparison`,children:[(0,$.jsx)(E,{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)(L,{className:`h-3 w-3`,"aria-hidden":`true`})})]},e.assistantMessageId))}),J&&H&&(0,$.jsx)(cr,{questions:H.settings?.decisionQuestions,onSave:at,disabled:i}),(0,$.jsx)(`form`,{onSubmit:Ft,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:Nt,children:[(0,$.jsx)(nr,{ref:K,message:o,disabled:i,onApply:e=>{c(e),Pe.current?.focus()}}),(0,$.jsx)(Mn,{ref:Pe,value:o,onChange:e=>c(e.target.value),onKeyDown:It,placeholder:a(`chat.input.placeholder`),"aria-label":a(`chat.input.placeholder`),disabled:i,className:`m-0! block w-full min-h-9 max-h-[160px] resize-none rounded-none! border-0! bg-transparent! px-2! pt-1.5! pb-2! shadow-none! scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:border-0! focus:bg-transparent! focus:shadow-none! focus:ring-0! dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(`div`,{ref:R,className:`relative shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{_?v(!1):(S(e=>!e),oe(null))},className:V(`h-9 w-9 p-0! rounded-full shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay`,`transition-colors duration-150 touch-manipulation`,zt&&`text-primary-600 dark:text-primary-400`,(_||x)&&`bg-hover-solid text-ink`),title:a(`chat.input.attachments`),"aria-label":a(`chat.input.attachments`),"aria-expanded":_||x,children:de||se?(0,$.jsx)(E,{className:`h-4 w-4 animate-spin`}):zt?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(be,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -inset-e-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):_?(0,$.jsx)(l,{className:`h-4 w-4`}):(0,$.jsx)(ye,{className:`h-4 w-4`})}),x&&(0,$.jsx)(`div`,{className:`absolute bottom-full inset-s-0 z-30 mb-2 w-72 rounded-2xl border border-black/8 bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/9 dark:bg-dark-100/95`,children:N?(0,$.jsxs)(`div`,{className:`p-1`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-ink-muted`,children:a(`chat.input.menu.attachKnowledge`)}),F.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-ink-subtle`,children:a(`chat.input.menu.noCollections`)}):F.map(e=>{let t=ct.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void ut(e.id),className:V(`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)(ue,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(ve,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>P(!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`)})]}):ae===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{v(!0),Ve()},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)(m,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.uploadImages`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>xe.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)(z,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>oe(``),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)(ge,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>P(!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)(ue,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachKnowledge`)]}),ct.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:ct.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{v(!0),Ve()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsx)(ce,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.structuredOutput`)]}),Be&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ee(e=>!e),Ve()},className:V(`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`,T&&`text-primary-600 dark:text-primary-400`),"aria-pressed":T,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(ge,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(T?`chat.input.webSearchOn`:`chat.input.webSearchOff`)]}),T&&(0,$.jsx)(ve,{className:`h-3.5 w-3.5 shrink-0`})]}),Ht&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{A(!0),Ve()},"data-testid":`composer-menu-compare`,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)(g,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.compare.title`)]}),D.length>0&&(0,$.jsxs)(`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:[`+`,D.length]})]}),Te&&Ct&&r&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{Qe(),r(),Ve()},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)(ne,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`voiceMode.open`)]})]}):(0,$.jsxs)(`div`,{className:`p-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`chat-attach-webpage-url`,className:`mb-1.5 block text-[11px] font-medium text-ink-muted`,children:a(`chat.input.menu.attachWebpage`)}),(0,$.jsx)(`input`,{id:`chat-attach-webpage-url`,type:`url`,value:ae,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),At()):e.key===`Escape`&&oe(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/8 bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>oe(null),children:a(`common.cancel`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:()=>void At(),disabled:!ae.trim(),loading:se,children:a(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:xe,type:`file`,accept:Xn,className:`hidden`,onChange:e=>void kt(e)})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-1 sm:gap-1.5`,children:[$e&&(0,$.jsx)(Et,{value:He,inheritedValue:qe,onChange:e=>void st(e)}),Be&&T&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ee(e=>!e),className:V(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,T&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:Ut,"aria-label":Ut,"aria-pressed":T,children:(0,$.jsx)(ge,{className:`h-4 w-4`})}),!M&&!J&&(0,$.jsx)(ir,{value:re,onChange:ie}),Ht&&(k||D.length>0)&&(0,$.jsx)(Yn,{models:U,currentModelKey:Vt,selectedKeys:D,onChange:O,open:k,onOpenChange:A,disabled:i}),Tt.length>0&&!Te&&(0,$.jsx)(`select`,{value:ft.activeSourceKey,onChange:e=>ft.setSourceKey(e.target.value),disabled:ht||xt||St,"aria-label":a(`chat.input.transcriptionSource`),title:wt?a(`chat.input.providerTranscriptionDisclosure`,{provider:wt.plugin}):a(`chat.input.transcriptionSource`),className:`h-8 max-w-32 rounded-lg border border-black/8 bg-transparent px-1.5 text-[11px] text-gray-500 outline-hidden focus:border-primary-500 focus:ring-2 focus:ring-primary-500/30 dark:border-white/9 dark:text-dark-600`,children:ft.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))}),Ct&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void ft.toggle(),className:V(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,(ht||xt||St)&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:Wt,"aria-label":Wt,"aria-pressed":ht||xt||St,children:ht?(0,$.jsx)(E,{className:`h-4 w-4 animate-spin`}):St||xt?(0,$.jsx)(y,{className:`h-4 w-4`}):(0,$.jsx)(Ce,{className:`h-4 w-4`})}),Ct&&r&&!Te&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{Qe(),r()},className:V(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`),title:a(`voiceMode.open`),"aria-label":a(`voiceMode.open`),"data-testid":`voice-mode-open`,children:(0,$.jsx)(ne,{className:`h-4 w-4`})}),H&&(0,$.jsx)(Wn,{usage:nt,trainedBudget:Xe?.contextCapped?Xe.trainedContextLength:void 0}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),H&&q.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Dt,{models:q,selectedModel:Ie,onModelChange:Rt,getModelValue:pt,currentPersona:Ae,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:ke})}),De?(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:Lt,className:V(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:a(`chat.input.stopGeneration`),"aria-label":a(`chat.input.stopGeneration`),children:(0,$.jsx)(y,{className:`h-4 w-4`})}):(0,$.jsx)(Z,{type:`submit`,variant:`primary`,size:`sm`,disabled:!o.trim()||i||!Le,className:Pt,title:a(`chat.input.sendMessage`),"aria-label":a(`chat.input.sendMessage`),children:(0,$.jsx)(Se,{className:`h-4 w-4`})})]})]})]})}),wt&&(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:wt.plugin})}),H&&q.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(Dt,{models:q,selectedModel:Ie,onModelChange:Rt,getModelValue:pt,currentPersona:Ae,className:`w-full`,compact:!0,showImageGen:ke})}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-ink-subtle`,children:[(0,$.jsx)(In,{sessionId:H?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:Bt?a(`chat.footer.disclaimerNamed`,{name:Bt}):a(`chat.footer.disclaimer`)}),zt&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,d.length>0&&a(`chat.footer.images`,{count:d.length}),d.length>0&&p&&` • `,p&&a(`chat.footer.structuredOutput`)]})]})]})]})]})})},mr={phase:`idle`,muted:!1,turn:0,error:null},hr=e=>({...e,phase:`listening`,turn:e.turn+1});function gr(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`}:hr(e):e;case`reply`:return e.phase===`generating`?t.speak?{...e,phase:`speaking`}:hr(e):e;case`spoken`:case`barge-in`:return e.phase===`speaking`?hr(e):e;case`fail`:return e.phase===`idle`?e:{...hr(e),error:t.message}}}var _r=Y(`utils:voice-mode-controller`),vr=.015,yr=200,br=1500,xr=6e4,Sr=300,Cr=18e4,wr=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},Tr=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},Er=class{options;state=mr;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([He.getModels().catch(()=>({success:!1,data:[]})),Fe.getModels().catch(()=>({success:!1,data:[]}))]);if(this.closed)return;let n=e.success&&e.data||[];this.ttsModels=t.success&&t.data||[];let r=n.find(e=>!!Tr(e)),i=!!r&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia,a=!!wr();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){_r.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=gr(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){_r.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=wr();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=Tr(t);if(!n)this.fail(e,this.options.messages.microphoneFailed);else try{let t=await this.ensureStream();if(this.staleTurn(e))return;this.chunks=[];let r=new MediaRecorder(t,{mimeType:n});this.recorder=r,r.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},r.onstop=()=>{if(this.staleTurn(e)&&this.state.phase!==`transcribing`)return;let t=new Blob(this.chunks,{type:n});this.chunks=[],t.size===0?this.handleTranscript(e,``):this.transcribeRecording(e,t)},r.start();let i=0,a=0,o=!1,s=Date.now();this.clearMonitor(),this.monitorTimer=window.setInterval(()=>{this.staleTurn(e)?this.clearMonitor():this.state.muted?(i=0,a=0):(this.analyser&&(this.rmsLevel()>vr?(i+=50,a=0,i>=yr&&(o=!0)):(i=0,o&&(a+=50))),(o&&a>=br||Date.now()-s>=xr)&&this.finishProviderCapture(e))},50)}catch(t){_r.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,He.transcribe(t,n,{language:this.options.locale?.split(`-`)[0],signal:r.signal}).then(t=>this.handleTranscript(e,t.text??``)).catch(t=>{r.signal.aborted||(_r.warn(`Voice mode transcription failed:`,t),this.fail(e,this.options.messages.transcriptionFailed))})}handleTranscript(e,t){if(this.staleTurn(e))return;let n=this.send({type:`transcript`,text:t});n.phase===`generating`?this.startGeneration(n.turn,t.trim()):n.phase===`listening`&&this.beginTurn(n.turn)}startGeneration(e,t){this.options.onTranscript(t);let n=this.options.snapshot().lastAssistantMessage?.id??null,r=!1,i=Date.now();this.options.sendMessage(t),this.clearPoll(),this.pollTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearPoll();return}let t=this.options.snapshot(),a=t.lastAssistantMessage,o=a!==null&&a.id!==n;if((t.isStreaming||o)&&(r=!0),r&&!t.isStreaming&&o){this.clearPoll();let t=this.ttsModels.length>0&&a.content.trim()!==``,n=this.send({type:`reply`,speak:t});n.phase===`speaking`?this.speakReply(e,a.content):n.phase===`listening`&&this.beginTurn(n.turn)}else Date.now()-i>Cr&&(this.clearPoll(),this.fail(e,this.options.messages.replyTimeout))},250)}speakReply(e,t){let n=this.options.snapshot().ttsSettings,r=J(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=Ze(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=Ye({concurrency:3,initialBufferSize:Math.min(2,l.length),generate:(e,{signal:t})=>Fe.generate({model:r.model,pluginId:r.plugin,input:e,voice:o?void 0:a||void 0,voiceProfileId:o,speed:n?.speed||1,response_format:r.config?.default_format},{signal:t}),onStateChange:()=>void 0});this.ttsSession=u;let d=$e(u);this.startBargeInMonitor(e,u),u.play(l).then(()=>{this.staleTurn(e)||this.finishSpeaking(e)}).catch(t=>{this.staleTurn(e)||Je(t)||(_r.warn(`Voice mode speech failed:`,t),this.finishSpeaking(e))}).finally(()=>{d(),this.ttsSession===u&&(this.ttsSession=null)})}startBargeInMonitor(e,t){if(!this.analyser)return;this.clearMonitor();let n=0;this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)||this.state.muted)n=0;else if(this.rmsLevel()>vr){if(n+=50,n>=Sr){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)}},Dr=({onClose:e,onSendMessage:t,isStreaming:n,lastAssistantMessage:r})=>{let{t:i,i18n:a}=s(),{preferences:o}=Ke(),[c,l]=(0,Q.useState)(mr),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(null),h=(0,Q.useRef)(null),g=(0,Q.useRef)({isStreaming:!1,lastAssistantMessage:null,ttsSettings:void 0});(0,Q.useEffect)(()=>{g.current={isStreaming:n,lastAssistantMessage:r,ttsSettings:o.ttsSettings}},[n,r,o.ttsSettings]),(0,Q.useEffect)(()=>{let e=new Er({locale:a.language,sendMessage:e=>t(e),snapshot:()=>g.current,onState:e=>l(e),onTranscript:e=>f(e),onSupport:e=>m(e),messages:{microphoneFailed:i(`voiceMode.microphoneFailed`),transcriptionFailed:i(`voiceMode.transcriptionFailed`),replyTimeout:i(`voiceMode.replyTimeout`)}});return h.current=e,e.start(),()=>{h.current=null,e.close()}},[]);let _=c.phase,v=p===!1?`voiceMode.unsupported`:_===`listening`?c.muted?`voiceMode.muted`:`voiceMode.listening`:_===`transcribing`?`voiceMode.transcribing`:_===`generating`?`voiceMode.generating`:_===`speaking`?`voiceMode.speaking`:`voiceMode.starting`;return(0,zt.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":i(`voiceMode.title`),className:`fixed inset-0 z-70 flex flex-col items-center justify-center gap-6 bg-white/95 p-6 backdrop-blur-sm dark:bg-dark-25/95`,"data-testid":`voice-mode-overlay`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e,"aria-label":i(`voiceMode.close`),className:`absolute right-4 top-4 rounded-full p-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-dark-100`,children:(0,$.jsx)(L,{className:`h-5 w-5`})}),(0,$.jsx)(`div`,{className:V(`flex h-28 w-28 items-center justify-center rounded-full border-4 transition-colors`,_===`listening`&&!c.muted?`border-primary-500 text-primary-500`:_===`speaking`?`border-emerald-500 text-emerald-500`:_===`generating`||_===`transcribing`?`border-amber-500 text-amber-500`:`border-gray-300 text-gray-400 dark:border-dark-300`),children:_===`transcribing`||_===`generating`?(0,$.jsx)(E,{className:`h-10 w-10 animate-spin`}):c.muted?(0,$.jsx)(D,{className:`h-10 w-10`}):_===`speaking`?(0,$.jsx)(ne,{className:`h-10 w-10`}):(0,$.jsx)(Ce,{className:`h-10 w-10`})}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`text-base font-medium text-gray-900 dark:text-gray-100`,"data-testid":`voice-mode-status`,children:i(v)}),c.error&&(0,$.jsx)(`p`,{className:`mt-1 text-sm text-red-600 dark:text-red-400`,children:c.error}),d&&(0,$.jsxs)(`p`,{className:`mt-3 max-w-md text-sm text-gray-600 dark:text-gray-300`,children:[`“`,d,`”`]})]}),p!==!1&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.toggleMute(),"aria-label":c.muted?i(`voiceMode.unmute`):i(`voiceMode.mute`),"aria-pressed":c.muted,className:`rounded-full border border-gray-300 p-3 text-gray-700 hover:bg-gray-100 dark:border-dark-300 dark:text-gray-300 dark:hover:bg-dark-100`,children:c.muted?(0,$.jsx)(D,{className:`h-5 w-5`}):(0,$.jsx)(Ce,{className:`h-5 w-5`})}),_===`listening`&&!c.muted&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.finishTurn(),"aria-label":i(`voiceMode.finishTurn`),className:`rounded-full border border-primary-500 p-3 text-primary-600 hover:bg-primary-50 dark:hover:bg-primary-950/30`,children:(0,$.jsx)(ve,{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)(u,{className:`h-5 w-5`})})]}),p===!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)},Or=Y(`components:chat-controls-panel`),kr=[{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`}],Ar=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i,i18n:a}=s(),o=X(e=>e.draftSessionSettings),c=X(e=>e.setDraftSessionSettings),l=e?.model??t??``,u=Ke(e=>e.preferences.generationOptions),d=Ke(e=>e.preferences.modelGenerationOptions?.[l]),f=X(e=>e.models.find(e=>e.name===l)),p=f&&!f.isPlugin&&!f.isAgent&&!f.isPersona?l:``,[m,h]=(0,Q.useState)({options:{},contextCapped:!1});(0,Q.useEffect)(()=>{if(!n||!p)return;let e=!1;return Ge.getModelDefaults(p).then(t=>{!e&&t.success&&t.data&&h({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,p]);let g=(0,Q.useMemo)(()=>({...u??{},...m.options,...d??{}}),[u,m.options,d]),_=(0,Q.useMemo)(()=>e?.messages.find(e=>e.role===`system`&&!st(e.content)),[e?.messages]),[v,y]=(0,Q.useState)(_?.content??o.systemPrompt??``),[b,x]=(0,Q.useState)(e?.settings?.generationOptions??o.generationOptions??{}),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(e?.settings?.compaction!==!1),[E,ee]=(0,Q.useState)(e?.id??`draft`),D=e?.id??`draft`;E!==D&&(ee(D),y(_?.content??o.systemPrompt??``),x(e?.settings?.generationOptions??o.generationOptions??{}),T(e?.settings?.compaction!==!1));let O=e=>{x(t=>{let n={...t},r=At(e);return r===null?delete n.think:n.think=r,n})},k=(e,t)=>{x(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},A=async()=>{C(!0);try{let t=v.trim(),n=_?.content??``,a=Object.fromEntries(Object.entries(b).filter(([,e])=>e!==void 0)),o=e?{...e.settings,generationOptions:a}:Object.keys(a).length>0?{generationOptions:a}:void 0;if(o&&e&&(w?delete o.compaction:o.compaction=!1),!e){c({systemPrompt:t||void 0,generationOptions:o?.generationOptions}),I.success(i(`chat.controls.saved`)),r();return}let s=e.messages;if(t!==n.trim()&&(_?s=t?e.messages.map(e=>e.id===_.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==_.id):t&&(s=[{id:De(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)X.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:s,settings:o}:t.currentSession}));else{let t=await G.updateSession(e.id,{messages:s,settings:o});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;X.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}I.success(i(`chat.controls.saved`)),r()}catch(e){Or.error(`Failed to save chat controls:`,e),I.error(i(`chat.controls.saveFailed`))}finally{C(!1)}};return n?(0,$.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:`flex h-full w-84 shrink-0 flex-col border-s border-black/6 bg-surface/70 backdrop-blur-xl dark:border-white/[0.07] dark:bg-dark-100/70`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:i(`chat.controls.title`)}),(0,$.jsx)(`button`,{type:`button`,onClick:r,className:`rounded-full p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-900`,title:i(`common.close`),"aria-label":i(`common.close`),children:(0,$.jsx)(L,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-system-prompt`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.systemPrompt`)}),(0,$.jsx)(`textarea`,{id:`chat-control-system-prompt`,dir:`auto`,value:v,onChange:e=>y(e.target.value),placeholder:i(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/8 bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-think`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.thinking`)}),(0,$.jsx)(`select`,{id:`chat-control-think`,value:kt(b.think),onChange:e=>O(e.target.value),className:`w-full rounded-xl border border-black/8 bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900`,children:jt.map(e=>(0,$.jsx)(`option`,{value:e,children:e==="default"&&g.think!==void 0&&g.think!==null?i(`settings.generation.thinkingLevels.defaultWith`,{level:i(`settings.generation.thinkingLevels.${kt(g.think)}`)}):i(`settings.generation.thinkingLevels.${e}`)},e))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-ink-muted`,children:i(`chat.controls.thinkingDescription`)})]}),e&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-compaction`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.compaction`)}),(0,$.jsxs)(`select`,{id:`chat-control-compaction`,value:w?`default`:`off`,onChange:e=>T(e.target.value!==`off`),className:`w-full rounded-xl border border-black/8 bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900`,children:[(0,$.jsx)(`option`,{value:`default`,children:i(`chat.controls.compactionDefault`)}),(0,$.jsx)(`option`,{value:`off`,children:i(`chat.controls.compactionOff`)})]}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-ink-muted`,children:i(`chat.controls.compactionDescription`)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.advancedParams`)}),(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-ink-muted`,children:i(`chat.controls.advancedParamsDescription`)}),m.contextCapped&&m.trainedContextLength&&(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-500 dark:text-dark-600`,children:i(`chat.controls.contextCapped`,{context:g.num_ctx?.toLocaleString(a.language),trained:m.trainedContextLength.toLocaleString(a.language)})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:kr.map(e=>{let t=b[e.key],n=g[e.key],r=m.options[e.key]!==void 0&&d?.[e.key]===void 0;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`label`,{htmlFor:`chat-control-${e.key}`,className:`text-[13px] text-gray-700 dark:text-dark-700`,children:[i(`chat.controls.params.${e.labelKey}`),r&&(0,$.jsx)(`span`,{title:i(`chat.controls.fromModelHint`),className:`ms-1.5 text-[10px] uppercase tracking-wide text-ink-muted`,children:i(`chat.controls.fromModel`)})]}),(0,$.jsx)(`input`,{id:`chat-control-${e.key}`,type:`number`,inputMode:`decimal`,step:e.step,min:e.min,max:e.max,value:typeof t==`number`?t:``,placeholder:typeof n==`number`?String(n):i(`common.default`),onChange:t=>k(e.key,t.target.value),className:`w-24 rounded-lg border border-black/8 bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/8 dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-black/6 px-4 py-3 dark:border-white/[0.07] lg:pb-16`,children:[(0,$.jsx)(`button`,{onClick:()=>{x({}),y(_?.content??``)},className:`text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:i(`common.reset`)}),(0,$.jsx)(Z,{onClick:()=>void A(),size:`sm`,disabled:S,children:i(S?`common.saving`:`common.save`)})]})]}):null},jr=Y(`components:chat-sources-panel`),Mr=6,Nr=[],Pr=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}},Fr=({session:e})=>{let{t,i18n:n}=s(),[r,i]=(0,Q.useState)({sessionId:``,docs:Nr}),a=!e.isPrivate&&r.sessionId===e.id?r.docs:Nr,[o,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),p=(0,Q.useRef)(null);Ct(p,{enabled:d,onClose:()=>f(!1)});let{webSources:m,ragSources:h,fullContextSkipped:g}=(0,Q.useMemo)(()=>{let t=new Map,n=new Map,r;for(let i of e.messages){let e=i.providerMetadata;if(Array.isArray(e?.webSearchSources))for(let n of e.webSearchSources){let e=n;e&&typeof e.url==`string`&&e.url&&t.set(e.url,{url:e.url,title:typeof e.title==`string`&&e.title?e.title:e.url})}if(Array.isArray(e?.ragSources))for(let t of e.ragSources){let e=t;e&&typeof e.id==`string`&&e.id&&n.set(e.id,{id:e.id,filename:typeof e.filename==`string`&&e.filename?e.filename:e.id,...Array.isArray(e.citations)?{citations:e.citations.filter(e=>!!e&&typeof e==`object`&&typeof e.chunkIndex==`number`)}:{},...e.full===!0?{full:!0}:{}})}let a=e?.ragFullContextSkipped;a&&typeof a.estimatedTokens==`number`&&typeof a.maxTokens==`number`?r={estimatedTokens:a.estimatedTokens,maxTokens:a.maxTokens}:e?.ragSources&&(r=void 0)}return{webSources:Array.from(t.values()),ragSources:Array.from(n.values()),fullContextSkipped:r}},[e.messages]);(0,Q.useEffect)(()=>{if(e.isPrivate)return;let t=!1,n=()=>{Re.getDocuments(e.id).then(n=>{!t&&n.success&&Array.isArray(n.data)&&i({sessionId:e.id,docs:n.data.map(e=>({id:e.id,filename:e.filename,contentChars:e.contentChars}))})}).catch(()=>{})};return n(),window.addEventListener(`libre:documents-updated`,n),()=>{t=!0,window.removeEventListener(`libre:documents-updated`,n)}},[e.id,e.isPrivate]);let _=(0,Q.useMemo)(()=>{let e=new Map;for(let t of a)e.set(t.id,{...t,used:!1});for(let t of h)e.set(t.id,{...e.get(t.id)??{},id:t.id,filename:t.filename,used:!0,...t.citations?.length?{citations:t.citations}:{},...t.full?{full:!0}:{}});return Array.from(e.values())},[a,h]),v=e.settings?.fullDocumentContext===!0,y=(0,Q.useMemo)(()=>a.reduce((e,t)=>e+Math.ceil((t.contentChars??0)/4),0),[a]),b=async()=>{let n=e.settings?.fullDocumentContext,r={...e.settings,fullDocumentContext:!v||void 0};if(X.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,settings:r}:t.currentSession,sessions:t.sessions.map(t=>t.id===e.id?{...t,settings:r}:t)})),!e.isPrivate)try{await G.updateSession(e.id,{settings:r})}catch(r){jr.error(`Failed to update the full-document setting:`,r);let i=e=>({...e,fullDocumentContext:n});X.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,settings:i(t.currentSession.settings)}:t.currentSession,sessions:t.sessions.map(t=>t.id===e.id?{...t,settings:i(t.settings)}:t)})),I.error(t(`chat.sources.fullContextFailed`))}},x=e=>{let t=[];for(let n of e){let e=n.location??`#${n.chunkIndex+1}`;if(t.includes(e)||t.push(e),t.length>=4)break}return t.join(` · `)};if(m.length===0&&_.length===0)return null;let S=o?m:m.slice(0,Mr),C=l?_:_.slice(0,Mr),w=(e,n,r)=>(e>0||n)&&(0,$.jsx)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`mt-1 flex items-center gap-1 px-1 text-[12px] text-ink-muted transition-colors hover:text-ink`,children:n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{className:`h-3 w-3`}),t(`chatMessage.showLess`,`Show less`)]}):`${t(`chatMessage.showMore`)} (${e})`}),T=(0,$.jsxs)($.Fragment,{children:[m.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-ink-muted`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:S.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`group -mx-1 flex items-center gap-2.5 rounded-lg px-1 py-1.5 transition-colors hover:bg-black/4 dark:hover:bg-white/5`,title:e.url,children:[(0,$.jsx)(ge,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-700 dark:text-dark-500 dark:group-hover:text-dark-800`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.title}),(0,$.jsx)(`span`,{dir:`ltr`,className:`block truncate text-[11px] text-ink-muted`,children:Pr(e.url)})]})]})},e.url))}),w(m.length-S.length,o,()=>c(e=>!e))]}),_.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-ink-muted`,children:t(`settings.tabs.documents`,`Documents`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:C.map(e=>(0,$.jsxs)(`li`,{className:`-mx-1 rounded-lg px-1 py-1.5`,title:e.filename,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(z,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.filename}),e.used&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-primary-500`}),(0,$.jsx)(`span`,{className:`sr-only`,children:t(`chat.sources.usedByRetrieval`)})]})]}),e.full?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-ink-muted`,"data-testid":`chat-source-citation`,children:t(`documents.fullDocument`,`Full document`)}):e.citations?.length?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-ink-muted`,"data-testid":`chat-source-citation`,children:x(e.citations)}):null]},e.id))}),w(_.length-C.length,l,()=>u(e=>!e)),(0,$.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-center gap-2 px-1 text-[12px] text-ink-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:v,onChange:b,"data-testid":`full-document-context-toggle`,className:`h-3.5 w-3.5 rounded-sm border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[t(`documents.fullContextToggle`,`Send full documents`),v&&y>0&&(0,$.jsx)(`span`,{className:`ms-1 text-ink-muted`,children:t(`documents.fullContextEstimate`,{tokens:y.toLocaleString(n.language)})})]})]}),v&&g&&(0,$.jsx)(`p`,{className:`mt-1 px-1 text-[11px] text-amber-600 dark:text-amber-400`,"data-testid":`full-document-context-warning`,children:t(`documents.fullContextTooLarge`)})]})]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`aside`,{"data-testid":`chat-sources-panel`,className:`hidden w-72 shrink-0 flex-col gap-7 overflow-y-auto border-s border-black/5 px-5 py-6 scrollbar-thin dark:border-white/6 xl:flex`,children:T}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(!0),"data-testid":`chat-sources-trigger`,className:`absolute inset-e-12 top-1.5 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 xl:hidden`,title:t(`chat.message.sources`,`Sources`),"aria-label":t(`chat.sources.triggerLabel`,{count:m.length+_.length}),"aria-haspopup":`dialog`,"aria-expanded":d,children:[(0,$.jsx)(ue,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`absolute -inset-e-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white shadow-xs`,children:m.length+_.length})]}),d&&(0,zt.createPortal)((0,$.jsxs)(`div`,{className:`fixed inset-0 z-80 xl:hidden`,children:[(0,$.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/35 backdrop-blur-xs`,onClick:()=>f(!1),"aria-label":t(`common.close`)}),(0,$.jsxs)(`div`,{ref:p,role:`dialog`,"aria-modal":`true`,tabIndex:-1,"aria-label":t(`chat.message.sources`,`Sources`),className:`absolute inset-x-3 bottom-3 max-h-[75vh] overflow-y-auto rounded-2xl border border-black/8 bg-surface p-5 shadow-[0_20px_70px_rgba(0,0,0,0.3)] scrollbar-thin dark:border-white/9 dark:bg-dark-100`,"data-testid":`chat-sources-sheet`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>f(!1),className:`rounded-md p-1.5 text-ink-muted hover:text-ink`,"aria-label":t(`common.close`),children:(0,$.jsx)(L,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:T})]})]}),document.body)]})},Ir=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Q.useRef)(null),[o,c]=(0,Q.useState)(!1),l=e=>new Promise(t=>{let n=new FileReader;n.onload=()=>t(typeof n.result==`string`?n.result:null),n.onerror=()=>{I.error(i(`chat.mediaUpload.readFailed`,{name:e.name})),t(null)},n.readAsDataURL(e)}),u=async r=>{if(!r)return;let a=n-e.length,o=Array.from(r).slice(0,Math.max(a,0)).filter(e=>e.type.startsWith(`image/`)?e.size>10485760?(I.error(i(`chat.mediaUpload.imageTooLarge`,{name:e.name})),!1):!0:(I.error(i(`chat.mediaUpload.unsupportedFileType`,{name:e.name})),!1));r.length>a&&I.error(i(`chat.mediaUpload.maxImagesAllowed`,{count:n}));let s=(await Promise.all(o.map(l))).filter(e=>e!==null);s.length>0&&t([...e,...s])},d=e=>{e.preventDefault(),c(!0)},f=e=>{e.preventDefault(),c(!1)},p=e=>{e.preventDefault(),c(!1),u(e.dataTransfer.files)},h=n=>{t(e.filter((e,t)=>t!==n))},g=e.length<n;return(0,$.jsxs)(`div`,{className:V(`space-y-3`,r),children:[g&&(0,$.jsxs)(`div`,{className:V(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:d,onDragLeave:f,onDrop:p,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>{u(e.target.files),e.target.value=``},className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(fe,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`button`,{type:`button`,onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-ink-muted`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:i(`chat.mediaUpload.uploadAlt`,{number:t+1}),className:`w-full h-full object-cover`}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-black/0 group-hover:bg-black/50 transition-all duration-200 flex items-center justify-center`,children:(0,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>h(t),"aria-label":i(`chat.mediaUpload.removeImage`,{number:t+1}),className:`opacity-0 group-hover:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,$.jsx)(L,{className:`h-4 w-4`})})})]},t))}),g&&e.length>0&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(m,{className:`h-4 w-4`}),i(`chat.mediaUpload.addMore`,{count:e.length,max:n})]})]})},Lr=Y(`pages:chat-page`),Rr=(e,t,n=!1)=>{let r=new Date().getHours(),i=e?`${n?`،`:`,`} \u2068${e}\u2069`:``;return r>=5&&r<12?{id:`time`,title:`${t?t(`chat.greeting.morning`):`Good morning`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=12&&r<17?{id:`time`,title:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=17&&r<21?{id:`time`,title:`${t?t(`chat.greeting.evening`):`Good evening`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}:{id:`time`,title:`${t?t(`chat.greeting.night`):`Good night`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}},zr=(e,t,n,r=!1)=>{let i=Lt(e);return i===`time`?Rr(t,n,r):{id:i,title:n?n(`chat.welcome.variety.${i}.title`):`What should we make?`,subtitle:n?n(`chat.welcome.variety.${i}.subtitle`):`Start with a thought, a sketch, or a stubborn problem.`}},Br=e=>{if(!e)return null;for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`assistant`)return{id:n.id,content:n.content}}return null},Vr=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),c=o(),{currentSession:u,sessions:d,models:f,selectedModel:p,selectedProviderType:m,selectedProviderId:h,setSelectedModel:g,createSession:_,setCurrentSession:v,loadSessions:y,getCurrentPersona:b}=X(),{user:S}=St(),C=Ke(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:w,stopGeneration:T,cancelComparison:E,regenerateLastMessage:ee,editAndResendMessage:D,selectBranch:O,isStreaming:k,streamingMessage:A,streamingThinking:te,streamingMessageId:ne,toolActivities:j,activeToolCalls:ie,pendingToolApproval:M,decideToolApproval:ae}=nt(u?.id||``),oe=b(),N=(0,Q.useMemo)(()=>({model:p,providerType:m,providerId:h}),[p,h,m]),P=(0,Q.useMemo)(()=>bt(f,N),[f,N]),F=dt(f,N)?.isDecision===!0,ce=p?mt(P,N):``,le=X(e=>e.modelMetadata),ue=Mt(P.find(e=>pt(e)===ce),le),L=ot(f,N),de=new URLSearchParams(c.search).get(`incognito`)===`1`,[fe,pe]=(0,Q.useState)(It),[me,he]=(0,Q.useState)(null),[_e,R]=(0,Q.useState)(!1),ve=Ke(e=>e.preferences.showFollowUpSuggestions!==!1),xe=(0,Q.useRef)(null),Ce=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=u?.id,t=Ce.current&&!k;if(Ce.current=k,!e||k||!ve||u?.isPrivate||!t)return;let n=u.messages[u.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||xe.current===n.id)return;xe.current=n.id;let r=!1;return G.generateFollowUps(e).then(t=>{!r&&t.success&&X.getState().currentSession?.id===e&&he({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[k,u,ve]);let we=me&&me.sessionId===u?.id?me.suggestions:[],Te=(0,Q.useMemo)(()=>zr(fe,S?.username,e,at(t.language)),[t.language,e,S?.username,fe]),[z,Ee]=(0,Q.useState)(``),[Oe,B]=(0,Q.useState)([]),[ke,H]=(0,Q.useState)(!1),[U,Ae]=(0,Q.useState)(!1),[je,W]=(0,Q.useState)(ar),[Me,Ne]=(0,Q.useState)(!1),Pe=(0,Q.useRef)(null),K=X(e=>e.draftSessionSettings),Fe=X(e=>e.setDraftSessionSettings),q=K.generationOptions?.think,Ie=Ke(e=>(p?e.preferences.modelGenerationOptions?.[p]?.think:void 0)??e.preferences.generationOptions?.think??null),Le=(0,Q.useMemo)(()=>f.find(e=>e.name===p),[f,p]),[J,ze]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!p||f.length===0||!Le||Le.isPlugin||Le.isAgent)return;let e=!1;return Ge.getModelDefaults(p).then(t=>{!e&&t.success&&t.data&&ze({model:p,supported:t.data.supportsThinking})}).catch(()=>{}),()=>{e=!0}},[p,Le,f.length]);let Be=!!(p&&!F&&!Le?.isAgent&&(Le?.isPlugin?Le.reasoningSupport!==!1:J?.model!==p||J.supported!==!1)),Ve=e=>{let t=X.getState().draftSessionSettings,n={...t.generationOptions};e===null?delete n.think:n.think=e,Fe({...t,generationOptions:Object.keys(n).length?n:void 0})},He=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){Ne(!0);try{let t=await Re.uploadDocument(n);t.success?(I.success(e(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):I.error(t.error||e(`chat.input.menu.attachFailed`))}catch(t){Lr.error(`Document upload failed:`,t),I.error(e(`chat.input.menu.attachFailed`))}finally{Ne(!1)}}};(0,Q.useEffect)(()=>{let e=!1;return Ue.getConfig().then(t=>{!e&&t.success&&t.data&&H(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[qe,Y]=(0,Q.useState)(!1),Je=(0,Q.useRef)(null),Ye=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{pe(It())};return window.addEventListener(Rt,e),()=>window.removeEventListener(Rt,e)},[]);let[Xe,Ze]=(0,Q.useState)(!1),[Qe,$e]=(0,Q.useState)(!1),et=Br(u?.messages),tt=C&&Xe,rt=(0,Q.useCallback)((t=!0)=>{let n=p?N:f[0]?ct(f[0]):null;if(!n||!ot(f,n))return t&&I.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return v({id:`private-${r}`,title:e(`chat.session.incognito`,`Incognito Chat`),model:n.model,providerType:n.providerType,providerId:n.providerId,messages:[],createdAt:r,updatedAt:r,isPrivate:!0}),!0},[f,p,N,v,e]);(0,Q.useEffect)(()=>{d.length===0&&y()},[y,d.length]),(0,Q.useEffect)(()=>{de&&!u?.isPrivate&&rt(!1)},[u?.isPrivate,de,rt]),(0,Q.useEffect)(()=>{let e=!1;return C&&(async()=>{try{let t=await We.getPlugins();if(e)return;Ze(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;Ze(!1)}})(),()=>{e=!0}},[C]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`))sessionStorage.removeItem(`forceWelcomeScreen`);else if((!u?.isPrivate||n)&&d.length!==0){if(n){let e=d.find(e=>e.id===n);e&&e.id!==u?.id?v(e):e||(Lr.warn(`Session ${n} not found for current user, redirecting...`),d.length>0?r(`/c/${d[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else d.length>0&&c.pathname===`/`&&r(`/c/${d[0].id}`,{replace:!0})}})()},[n,d,v,r,u?.id,u?.isPrivate,c.pathname]);let it=Ke(e=>e.setChatWallpaper),st=u&&oe?.background||null;(0,Q.useEffect)(()=>(it(st),()=>it(null)),[st,it]),(0,Q.useEffect)(()=>{if(u?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{w(t.content,t.images,void 0,t.webSearch===!0,t.tools===!0,t.toolSelection)},100)}catch(e){Lr.error(`Failed to parse pending message:`,e)}}}},[u?.id,w]),(0,Q.useEffect)(()=>{let e=Je.current;e&&(e.style.height=`auto`,e.style.height=z?`${Math.min(e.scrollHeight,200)}px`:``)},[z]);let lt=async t=>{if(t.preventDefault(),!z.trim()||!p)return;if(!L){I.error(e(`chat.model.selectBeforeSending`));return}Tt(`impact`);let n={content:z.trim(),images:Oe.length>0?Oe:void 0,webSearch:ke&&U&&!F?!0:void 0,...F?{}:or(je)};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n));let i={message:z,images:Oe,webSearch:U,tools:je};Ee(``),B([]),Ae(!1),W(ar);let a;try{a=await _(p,void 0,p.startsWith(`persona:`)?p.slice(8):void 0,m,h)}catch{a=void 0}a?(await ut(a),r(`/c/${a.id}`,{replace:!0})):(sessionStorage.removeItem(`pendingMessage`),Ee(i.message),B(i.images),Ae(i.webSearch),W(i.tools),X.getState().error||I.error(e(`chat.toasts.createFailed`)))},ut=(0,Q.useCallback)(async e=>{let t=X.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions,i=t.decisionQuestions;if(!n&&!r&&!i)return;let a=n?[{id:De(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await G.updateSession(e.id,{messages:a,settings:r||i?{...r?{generationOptions:r}:{},...i?{decisionQuestions:i}:{}}:void 0});if(t.success&&t.data){let e=t.data;X.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){Lr.error(`Failed to apply chat settings to the new session`,e)}finally{X.getState().setDraftSessionSettings({})}},[]),ft=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||Ye.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),lt(e))},ht=async e=>{let t=yt(P,e.target.value);t&&g(t.model,t.providerType,t.providerId)},gt=(e,t,n,r,i,a,o)=>{u&&(Tt(`impact`),he(null),w(e,t,n,r,i,a,o))},_t=u?.id,vt=(0,Q.useCallback)(async t=>{if(_t)try{let n=await G.forkSession(_t,{messageId:t});if(n.success&&n.data){let t=n.data;X.setState(e=>({sessions:[t,...e.sessions]})),I.success(e(`chat.fork.created`)),r(`/c/${t.id}`)}else I.error(n.error||e(`chat.fork.failed`))}catch(t){Lr.error(`Failed to fork the chat:`,t),I.error(e(`chat.fork.failed`))}},[_t,r,e]);if(!u){let t=Oe.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:()=>R(e=>!e),className:V(`absolute inset-e-4 top-4 z-10 flex h-9 w-9 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:inset-e-6 sm:top-6`,_e&&`text-primary-600 dark:text-primary-400`),type:`button`,title:e(`chat.controls.title`),"aria-label":e(`chat.controls.title`),"aria-expanded":_e,children:(0,$.jsx)(x,{className:`h-4 w-4`})}),(0,$.jsxs)(`button`,{onClick:()=>rt(),disabled:!p&&f.length===0||!!p&&!L,className:`absolute inset-e-15 top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-surface/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:inset-e-17 sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,$.jsx)(se,{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 wide:max-w-none`,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)(xt,{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:Te.title})]}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-[15px] leading-relaxed text-ink-subtle`,children:Te.subtitle})]},Te.id),P.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[qe&&(0,$.jsxs)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-xs backdrop-blur-xl dark:border-white/8 dark:bg-dark-200/80`,children:[(0,$.jsx)(Ir,{images:Oe,onImagesChange:B,maxImages:5}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 border-t border-black/6 pt-3 dark:border-white/[0.07]`,children:[(0,$.jsx)(`span`,{className:`text-xs text-ink-muted`,children:e(`chat.input.menu.attachDocument`)}),(0,$.jsxs)(Z,{type:`button`,size:`sm`,variant:`outline`,disabled:Me,onClick:()=>Pe.current?.click(),className:`shrink-0 whitespace-nowrap`,children:[(0,$.jsx)(be,{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:Pe,type:`file`,accept:Xn,className:`hidden`,onChange:e=>void He(e)})]})]}),F&&(0,$.jsx)(cr,{questions:K.decisionQuestions,onSave:e=>Fe({...X.getState().draftSessionSettings,decisionQuestions:e})}),(0,$.jsx)(`form`,{onSubmit:lt,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:Nt,children:[(0,$.jsx)(nr,{ref:Ye,message:z,onApply:e=>{Ee(e),Je.current?.focus()}}),(0,$.jsx)(Mn,{ref:Je,value:z,onChange:e=>Ee(e.target.value),onKeyDown:ft,placeholder:e(`chat.input.messagePlaceholder`),"aria-label":e(`chat.input.messagePlaceholder`),className:`m-0! block w-full min-h-9 max-h-[160px] resize-none rounded-none! border-0! bg-transparent! px-2! pt-1.5! pb-2! shadow-none! scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:border-0! focus:bg-transparent! focus:shadow-none! focus:ring-0! dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Y(!qe),className:V(`h-9 w-9 p-0! rounded-full shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,qe&&`bg-hover-solid text-ink`),title:e(`chat.input.attachImages`),"aria-label":e(`chat.input.attachImages`),"aria-expanded":qe,children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(be,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -inset-e-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):qe?(0,$.jsx)(l,{className:`h-4 w-4`}):(0,$.jsx)(ye,{className:`h-4 w-4`})}),Be&&(0,$.jsx)(Et,{value:q,inheritedValue:Ie,onChange:Ve}),ke&&!F&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Ae(e=>!e),className:V(`h-9 w-9 p-0 rounded-full shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,U&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:e(U?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-label":e(U?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":U,children:(0,$.jsx)(ge,{className:`h-4 w-4`})}),!F&&(0,$.jsx)(ir,{value:je,onChange:W,buttonClassName:`h-9 w-9`}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Dt,{models:P,selectedModel:ce,onModelChange:ht,getModelValue:pt,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:tt})}),(0,$.jsx)(Z,{type:`submit`,variant:`primary`,size:`sm`,disabled:!z.trim()||!p||!L,className:Pt,title:e(`chat.input.sendMessage`),"aria-label":e(`chat.input.sendMessage`),children:(0,$.jsx)(Se,{className:`h-4 w-4`})})]})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(Dt,{models:P,selectedModel:ce,onModelChange:ht,getModelValue:pt,className:`w-full`,compact:!0,showImageGen:tt})}),(0,$.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-ink-subtle`,children:ue?e(`chat.footer.disclaimerNamed`,{name:ue}):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)(Ft,{variant:`inline`})]})]})]}),(0,$.jsx)(Ar,{draftModel:p,open:_e,onClose:()=>R(!1)})]})}return(0,$.jsx)(`div`,{className:`relative flex h-full flex-col`,children:(0,$.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{"data-testid":`chat-session-header`,className:`flex h-11 shrink-0 items-center gap-2 ps-4 pe-3`,children:[u?.isPrivate&&(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(se,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,$.jsxs)(`span`,{className:`hidden truncate text-[11px] text-ink-subtle sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]}),u.settings?.forkedFrom&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(`/c/${u.settings.forkedFrom.sessionId}`),className:`flex min-w-0 items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-3 py-1 text-[11px] text-gray-500 transition-colors hover:text-gray-800 dark:border-white/8 dark:bg-dark-200/70 dark:text-dark-600 dark:hover:text-dark-900`,"data-testid":`forked-from-banner`,children:[(0,$.jsx)(re,{className:`h-3 w-3 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e(`chat.fork.origin`,{title:u.settings.forkedFrom.title||e(`chat.fork.originUnknown`)})})]}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`w-9 shrink-0 xl:hidden`}),(0,$.jsx)(`button`,{onClick:()=>R(e=>!e),className:V(`flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/8 dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950`,_e&&`text-primary-600 dark:text-primary-400`),type:`button`,title:e(`chat.controls.title`),"aria-label":e(`chat.controls.title`),"aria-expanded":_e,children:(0,$.jsx)(x,{className:`h-3.5 w-3.5`})})]}),(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)(An,{messages:u.messages,streamingMessage:A,streamingThinking:te,streamingMessageId:ne,isStreaming:k,toolActivities:j,activeToolCalls:ie,pendingToolApproval:M,onDecideToolApproval:ae,onRegenerate:ee,onSelectBranch:O,onEditResend:D,onFork:vt,followUpSuggestions:we,onFollowUpSelect:e=>gt(e),className:`flex-1`}),u?.shared?(0,$.jsx)(`div`,{className:`mx-auto mb-4 w-full max-w-3xl rounded-xl border wide:max-w-none border-black/6 bg-black/2 px-4 py-3 text-center text-[13px] text-gray-500 dark:border-white/8 dark:bg-white/3 dark:text-dark-600`,"data-testid":`chat-shared-readonly`,children:e(`chat.sharedReadOnly`,{owner:u.shared.ownerUserId})}):(0,$.jsx)(pr,{onSendMessage:gt,onStopGeneration:T,onCancelComparison:E,onOpenVoiceMode:()=>$e(!0),disabled:!u})]}),Qe&&u&&(0,$.jsx)(Dr,{onClose:()=>$e(!1),onSendMessage:e=>gt(e),isStreaming:k,lastAssistantMessage:et}),(0,$.jsx)(Fr,{session:u}),(0,$.jsx)(Ar,{session:u,open:_e,onClose:()=>R(!1)})]})]})})};export{Vr as ChatPage,Vr as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{Dr as r,Kt as i,Mn as a,Q as o,U as s,Zn as c,er as l,et as ee,rt as te,zn as u}from"./ui-vendor-CjZizWzb.js";import{t as d}from"./useTranslation-CKqEdZ8j.js";import"./ui-CtgjJ55f.js";import{u as f,y as p}from"./api-R43sAAC-.js";import{t as m}from"./authStore-RsBcSMMM.js";import{t as h}from"./Button-D6d7HYoa.js";import{t as g}from"./chatStore-D-0TPlCx.js";import{t as _}from"./utils-BXRzbHJC.js";import{t as v}from"./logger-DAQsBb8I.js";var y=e(t(),1),b=n(),x=v(`components:connect-models`),S=[{id:`llama-cpp`,name:`llama.cpp`,baseUrl:`http://localhost:8080/v1`},{id:`vllm`,name:`vLLM`,baseUrl:`http://localhost:8000/v1`},{id:`llama-swap`,name:`llama-swap`,baseUrl:`http://localhost:8080/v1`},{id:`lm-studio`,name:`LM Studio`,baseUrl:`http://localhost:1234/v1`},{id:`mlx-lm`,name:`mlx-lm`,baseUrl:`http://localhost:8080/v1`}],C=[{id:`openai`,name:`OpenAI`},{id:`anthropic`,name:`Anthropic`},{id:`groq`,name:`Groq`},{id:`openrouter`,name:`OpenRouter`},{id:`gemini`,name:`Google Gemini`},{id:`mistral`,name:`Mistral`},{id:`deepseek`,name:`DeepSeek`},{id:`meta`,name:`Meta`},{id:`modal`,name:`Modal`},{id:`baseten`,name:`Baseten`},{id:`bedrock`,name:`Amazon Bedrock`}],w=({variant:e=`setup`,onDone:t})=>{let{t:n}=d(),{user:v,systemInfo:w}=m(),T=g(e=>e.loadModels),E=v?.role===`admin`||w?.requiresAuth===!1,[D,O]=(0,y.useState)(()=>w?.ollamaEnabled===!1?`disabled`:`checking`),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(S[0]),[N,P]=(0,y.useState)(S[0].baseUrl),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)(!1),[U,W]=(0,y.useState)(null),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=(0,y.useCallback)(async()=>{try{let e=await p.checkHealth();e.success&&e.data?.status===`disabled`?O(`disabled`):e.success&&e.data?.status===`healthy`?O(`healthy`):O(`offline`)}catch{O(`offline`)}},[]);(0,y.useEffect)(()=>{if(w?.ollamaEnabled===!1)return;let e=window.setTimeout(()=>{Y()},0);return()=>window.clearTimeout(e)},[Y,w?.ollamaEnabled]);let X=async e=>{try{(await p.updateSettings({enabled:e})).success?(r.success(n(e?`connectModels.ollama.enabledToast`:`connectModels.ollama.disabledToast`)),e?(O(`checking`),Y()):O(`disabled`)):r.error(n(`connectModels.ollama.settingsFailed`))}catch(e){x.error(`Failed to update Ollama settings:`,e),r.error(n(`connectModels.ollama.settingsFailed`))}},Z=async()=>{R(!0),B(null);try{let e=await f.probeEndpoint(N,`openai`);e.success&&e.data?.reachable?(B(e.data.models),r.success(n(`connectModels.local.reachable`,{count:e.data.models.length}))):(B([]),r.error(e.message||n(`connectModels.local.unreachable`)))}catch(e){x.error(`Endpoint probe failed:`,e),B([]),r.error(n(`connectModels.local.unreachable`))}finally{R(!1)}},ne=async()=>{H(!0);try{let e=N.replace(/\/+$/,``),i=e.endsWith(`/v1`)?e:`${e}/v1`,a=F.trim().length>0,o=`${j.id.toUpperCase().replace(/-/g,`_`)}_API_KEY`,s={id:j.id,name:j.name,type:`completion`,endpoint:`${i}/chat/completions`,api_mode:`chat_completions`,base_url:i,auth:a?{header:`Authorization`,prefix:`Bearer `,key_env:o}:{header:``,prefix:``,key_env:``},model_map:(z??[]).slice(0,50)};if(!(await f.installPlugin(s)).success&&!(await f.updatePlugin(j.id,s)).success){r.error(n(`connectModels.local.enableFailed`));return}a&&await f.setApiKey(j.id,F.trim()),await f.activatePlugin(j.id),await T({quiet:!0}),r.success(n(`connectModels.local.enabled`,{name:j.name})),t?.()}catch(e){x.error(`Failed to enable local provider:`,e),r.error(n(`connectModels.local.enableFailed`))}finally{H(!1)}},re=async()=>{if(U&&G.trim()){J(!0);try{if(!(await f.setApiKey(U.id,G.trim())).success){r.error(n(`connectModels.cloud.saveFailed`));return}await f.activatePlugin(U.id),await T({quiet:!0}),r.success(n(`connectModels.cloud.connected`,{name:U.name})),K(``),t?.()}catch(e){x.error(`Failed to connect cloud provider:`,e),r.error(n(`connectModels.cloud.saveFailed`))}finally{J(!1)}}},Q=`rounded-2xl border border-gray-200/80 bg-white/80 p-4 dark:border-white/10 dark:bg-white/4`,$=`w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800 dark:placeholder-dark-500`,ie={checking:`bg-gray-400 animate-pulse`,healthy:`bg-green-500`,offline:`bg-red-500`,disabled:`bg-gray-400`}[D];return(0,b.jsxs)(`div`,{className:_(`flex w-full flex-col gap-3`,`max-w-lg`),children:[(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(a,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:`Ollama`}),(0,b.jsx)(`span`,{className:_(`h-2 w-2 rounded-full`,ie)})]}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.status.${D}`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[D!==`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>{O(`checking`),Y()},title:n(`connectModels.ollama.recheck`),"aria-label":n(`connectModels.ollama.recheck`),children:(0,b.jsx)(o,{className:_(`h-4 w-4`,D===`checking`&&`animate-spin`)})}),E&&D===`offline`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!1),title:n(`connectModels.ollama.disable`),"aria-label":n(`connectModels.ollama.disable`),children:(0,b.jsx)(ee,{className:`h-4 w-4`})}),E&&D===`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!0),children:n(`connectModels.ollama.enable`)})]})]}),D===`offline`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.offlineHint`)}),D===`healthy`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-success-800 dark:text-success-400`,children:n(`connectModels.ollama.healthyHint`)})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`local`,onClick:()=>A(k===`local`?null:`local`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(s,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.local.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.local.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`local`&&`rotate-90 rtl:rotate-90`)})]}),k===`local`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:S.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>{M(e),P(e.baseUrl),B(null)},"aria-pressed":j.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,j.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),(0,b.jsx)(`input`,{className:$,type:`url`,"aria-label":n(`connectModels.local.urlLabel`),autoCapitalize:`none`,value:N,onChange:e=>{P(e.target.value),B(null)},placeholder:`http://localhost:8080/v1`,spellCheck:!1}),(0,b.jsx)(`input`,{className:$,value:F,onChange:e=>I(e.target.value),placeholder:n(`connectModels.local.keyPlaceholder`),"aria-label":n(`connectModels.local.keyPlaceholder`),type:`password`,autoComplete:`off`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void Z(),disabled:L||!N.trim(),children:[(0,b.jsx)(te,{className:`me-1.5 h-4 w-4`}),n(L?`connectModels.local.testing`:`connectModels.local.test`)]}),(0,b.jsxs)(h,{size:`sm`,onClick:()=>void ne(),disabled:V||!z||z.length===0,children:[(0,b.jsx)(l,{className:`me-1.5 h-4 w-4`}),n(V?`connectModels.local.enabling`:`connectModels.local.enable`)]})]}),z&&z.length>0&&(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[z.slice(0,8).map(e=>(0,b.jsx)(`span`,{className:`rounded-md bg-gray-100 px-2 py-0.5 font-mono text-[10px] text-gray-700 dark:bg-white/6 dark:text-dark-700`,children:e},e)),z.length>8&&(0,b.jsxs)(`span`,{className:`px-1 text-[10px] text-gray-400`,children:[`+`,z.length-8]})]}),z&&z.length===0&&(0,b.jsx)(`p`,{role:`alert`,className:`text-xs text-error-700 dark:text-error-400`,children:n(`connectModels.local.noModels`)})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`cloud`,onClick:()=>A(k===`cloud`?null:`cloud`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(u,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.cloud.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.cloud.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`cloud`&&`rotate-90 rtl:rotate-90`)})]}),k===`cloud`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>W(e),"aria-pressed":U?.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,U?.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),U&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(i,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,b.jsx)(`input`,{className:_($,`ps-9`),value:G,onChange:e=>K(e.target.value),placeholder:n(`connectModels.cloud.keyPlaceholder`,{name:U.name}),"aria-label":n(`connectModels.cloud.keyLabel`,{name:U.name}),type:`password`,autoComplete:`off`})]}),(0,b.jsx)(`div`,{children:(0,b.jsxs)(h,{size:`sm`,onClick:()=>void re(),disabled:q||!G.trim(),children:[(0,b.jsx)(l,{className:`me-1.5 h-4 w-4`}),n(q?`connectModels.cloud.connecting`:`connectModels.cloud.connect`)]})})]})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),e===`setup`&&(0,b.jsx)(`div`,{className:`mt-1 text-center`,children:(0,b.jsx)(`button`,{type:`button`,onClick:()=>t?.(),className:`text-sm text-gray-500 underline-offset-4 hover:underline dark:text-dark-500`,children:n(`connectModels.skip`)})})]})};export{w as t};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{Bn as r,Kt as i,Mn as a,Or as o,Q as s,Qn as c,U as l,et as ee,nt as te,tr as u}from"./ui-vendor-BanHlKMb.js";import{t as d}from"./useTranslation-Bu0AxynE.js";import"./ui-CKcr9ReZ.js";import{u as f,y as p}from"./api-B8EjExUU.js";import{t as m}from"./authStore-BOFcWqii.js";import{t as h}from"./Button-DeV-GhQr.js";import{t as g}from"./chatStore-C3c3r8iB.js";import{t as _}from"./utils-DhBboyBg.js";import{t as v}from"./logger-DAQsBb8I.js";var y=e(t(),1),b=n(),x=v(`components:connect-models`),S=[{id:`llama-cpp`,name:`llama.cpp`,baseUrl:`http://localhost:8080/v1`},{id:`vllm`,name:`vLLM`,baseUrl:`http://localhost:8000/v1`},{id:`llama-swap`,name:`llama-swap`,baseUrl:`http://localhost:8080/v1`},{id:`lm-studio`,name:`LM Studio`,baseUrl:`http://localhost:1234/v1`},{id:`mlx-lm`,name:`mlx-lm`,baseUrl:`http://localhost:8080/v1`}],C=[{id:`openai`,name:`OpenAI`},{id:`anthropic`,name:`Anthropic`},{id:`groq`,name:`Groq`},{id:`openrouter`,name:`OpenRouter`},{id:`gemini`,name:`Google Gemini`},{id:`mistral`,name:`Mistral`},{id:`deepseek`,name:`DeepSeek`},{id:`meta`,name:`Meta`},{id:`modal`,name:`Modal`},{id:`baseten`,name:`Baseten`},{id:`bedrock`,name:`Amazon Bedrock`}],w=({variant:e=`setup`,onDone:t})=>{let{t:n}=d(),{user:v,systemInfo:w}=m(),T=g(e=>e.loadModels),E=v?.role===`admin`||w?.requiresAuth===!1,[D,O]=(0,y.useState)(()=>w?.ollamaEnabled===!1?`disabled`:`checking`),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(S[0]),[N,P]=(0,y.useState)(S[0].baseUrl),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)(!1),[U,W]=(0,y.useState)(null),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=(0,y.useCallback)(async()=>{try{let e=await p.checkHealth();e.success&&e.data?.status===`disabled`?O(`disabled`):e.success&&e.data?.status===`healthy`?O(`healthy`):O(`offline`)}catch{O(`offline`)}},[]);(0,y.useEffect)(()=>{if(w?.ollamaEnabled===!1)return;let e=window.setTimeout(()=>{Y()},0);return()=>window.clearTimeout(e)},[Y,w?.ollamaEnabled]);let X=async e=>{try{(await p.updateSettings({enabled:e})).success?(o.success(n(e?`connectModels.ollama.enabledToast`:`connectModels.ollama.disabledToast`)),e?(O(`checking`),Y()):O(`disabled`)):o.error(n(`connectModels.ollama.settingsFailed`))}catch(e){x.error(`Failed to update Ollama settings:`,e),o.error(n(`connectModels.ollama.settingsFailed`))}},Z=async()=>{R(!0),B(null);try{let e=await f.probeEndpoint(N,`openai`);e.success&&e.data?.reachable?(B(e.data.models),o.success(n(`connectModels.local.reachable`,{count:e.data.models.length}))):(B([]),o.error(e.message||n(`connectModels.local.unreachable`)))}catch(e){x.error(`Endpoint probe failed:`,e),B([]),o.error(n(`connectModels.local.unreachable`))}finally{R(!1)}},ne=async()=>{H(!0);try{let e=N.replace(/\/+$/,``),r=e.endsWith(`/v1`)?e:`${e}/v1`,i=F.trim().length>0,a=`${j.id.toUpperCase().replace(/-/g,`_`)}_API_KEY`,s={id:j.id,name:j.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:(z??[]).slice(0,50)};if(!(await f.installPlugin(s)).success&&!(await f.updatePlugin(j.id,s)).success){o.error(n(`connectModels.local.enableFailed`));return}i&&await f.setApiKey(j.id,F.trim()),await f.activatePlugin(j.id),await T({quiet:!0}),o.success(n(`connectModels.local.enabled`,{name:j.name})),t?.()}catch(e){x.error(`Failed to enable local provider:`,e),o.error(n(`connectModels.local.enableFailed`))}finally{H(!1)}},re=async()=>{if(U&&G.trim()){J(!0);try{if(!(await f.setApiKey(U.id,G.trim())).success){o.error(n(`connectModels.cloud.saveFailed`));return}await f.activatePlugin(U.id),await T({quiet:!0}),o.success(n(`connectModels.cloud.connected`,{name:U.name})),K(``),t?.()}catch(e){x.error(`Failed to connect cloud provider:`,e),o.error(n(`connectModels.cloud.saveFailed`))}finally{J(!1)}}},Q=`rounded-2xl border border-gray-200/80 bg-white/80 p-4 dark:border-white/10 dark:bg-white/4`,$=`w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800 dark:placeholder-dark-500`,ie={checking:`bg-gray-400 animate-pulse`,healthy:`bg-green-500`,offline:`bg-red-500`,disabled:`bg-gray-400`}[D];return(0,b.jsxs)(`div`,{className:_(`flex w-full flex-col gap-3`,`max-w-lg`),children:[(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(a,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:`Ollama`}),(0,b.jsx)(`span`,{className:_(`h-2 w-2 rounded-full`,ie)})]}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.status.${D}`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[D!==`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>{O(`checking`),Y()},title:n(`connectModels.ollama.recheck`),"aria-label":n(`connectModels.ollama.recheck`),children:(0,b.jsx)(s,{className:_(`h-4 w-4`,D===`checking`&&`animate-spin`)})}),E&&D===`offline`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!1),title:n(`connectModels.ollama.disable`),"aria-label":n(`connectModels.ollama.disable`),children:(0,b.jsx)(ee,{className:`h-4 w-4`})}),E&&D===`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!0),children:n(`connectModels.ollama.enable`)})]})]}),D===`offline`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.offlineHint`)}),D===`healthy`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-success-800 dark:text-success-400`,children:n(`connectModels.ollama.healthyHint`)})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`local`,onClick:()=>A(k===`local`?null:`local`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(l,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.local.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.local.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`local`&&`rotate-90 rtl:rotate-90`)})]}),k===`local`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:S.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>{M(e),P(e.baseUrl),B(null)},"aria-pressed":j.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,j.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),(0,b.jsx)(`input`,{className:$,type:`url`,"aria-label":n(`connectModels.local.urlLabel`),autoCapitalize:`none`,value:N,onChange:e=>{P(e.target.value),B(null)},placeholder:`http://localhost:8080/v1`,spellCheck:!1}),(0,b.jsx)(`input`,{className:$,value:F,onChange:e=>I(e.target.value),placeholder:n(`connectModels.local.keyPlaceholder`),"aria-label":n(`connectModels.local.keyPlaceholder`),type:`password`,autoComplete:`off`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void Z(),disabled:L||!N.trim(),children:[(0,b.jsx)(te,{className:`me-1.5 h-4 w-4`}),n(L?`connectModels.local.testing`:`connectModels.local.test`)]}),(0,b.jsxs)(h,{size:`sm`,onClick:()=>void ne(),disabled:V||!z||z.length===0,children:[(0,b.jsx)(u,{className:`me-1.5 h-4 w-4`}),n(V?`connectModels.local.enabling`:`connectModels.local.enable`)]})]}),z&&z.length>0&&(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[z.slice(0,8).map(e=>(0,b.jsx)(`span`,{className:`rounded-md bg-gray-100 px-2 py-0.5 font-mono text-[10px] text-gray-700 dark:bg-white/6 dark:text-dark-700`,children:e},e)),z.length>8&&(0,b.jsxs)(`span`,{className:`px-1 text-[10px] text-gray-400`,children:[`+`,z.length-8]})]}),z&&z.length===0&&(0,b.jsx)(`p`,{role:`alert`,className:`text-xs text-error-700 dark:text-error-400`,children:n(`connectModels.local.noModels`)})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`cloud`,onClick:()=>A(k===`cloud`?null:`cloud`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(r,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.cloud.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.cloud.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`cloud`&&`rotate-90 rtl:rotate-90`)})]}),k===`cloud`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>W(e),"aria-pressed":U?.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,U?.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),U&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(i,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,b.jsx)(`input`,{className:_($,`ps-9`),value:G,onChange:e=>K(e.target.value),placeholder:n(`connectModels.cloud.keyPlaceholder`,{name:U.name}),"aria-label":n(`connectModels.cloud.keyLabel`,{name:U.name}),type:`password`,autoComplete:`off`})]}),(0,b.jsx)(`div`,{children:(0,b.jsxs)(h,{size:`sm`,onClick:()=>void re(),disabled:q||!G.trim(),children:[(0,b.jsx)(u,{className:`me-1.5 h-4 w-4`}),n(q?`connectModels.cloud.connecting`:`connectModels.cloud.connect`)]})})]})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),e===`setup`&&(0,b.jsx)(`div`,{className:`mt-1 text-center`,children:(0,b.jsx)(`button`,{type:`button`,onClick:()=>t?.(),className:`text-sm text-gray-500 underline-offset-4 hover:underline dark:text-dark-500`,children:n(`connectModels.skip`)})})]})};export{w as t};
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{t as r}from"./useTranslation-CKqEdZ8j.js";import{An as i,Bt as a,C as o,Dr as s,Rt as ee,h as c,it as l,n as u,tt as d,v as te,y as ne}from"./ui-vendor-CjZizWzb.js";import{o as re,r as f,s as ie}from"./ui-CtgjJ55f.js";import{t as p}from"./confirmStore-CKkUtP9c.js";import{t as m}from"./Button-D6d7HYoa.js";import{t as h}from"./chatStore-D-0TPlCx.js";import{t as g}from"./evaluationsApi-Due3Xmlx.js";import{t as _}from"./utils-BXRzbHJC.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 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,x=()=>{let{t:e,i18n:t}=r(),n=h(e=>e.models),x=h(e=>e.loadModels),[S,C]=(0,v.useState)(`arena`),[w,T]=(0,v.useState)(0),[E,D]=(0,v.useState)(``),[O,k]=(0,v.useState)(``),[A,ae]=(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,oe]=(0,v.useState)(``);(0,v.useEffect)(()=>{x()},[x]),(0,v.useEffect)(()=>{let t=!1;return Promise.all([g.leaderboard(),g.listSets(),g.listRuns(),g.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}},[w,e]),(0,v.useEffect)(()=>{if(!V.some(e=>e.status===`queued`||e.status===`running`))return;let e=window.setInterval(()=>T(e=>e+1),4e3);return()=>window.clearInterval(e)},[V]);let X=n.map(e=>e.name),se=async()=>{if(E.trim()&&O&&A&&!F){I(!0),M(null),P(!1);try{let e=await g.runArenaMatch({prompt:E.trim(),modelA:O,modelB:A});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)}}},Z=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 g.voteArena({compareGroup:j.compareGroup,modelA:n,modelB:r,winner:t});if(!i.success)throw Error(i.message);P(!0),T(e=>e+1),s.success(e(`evaluations.voteRecorded`))}catch(t){s.error(t instanceof Error?t.message:e(`evaluations.voteFailed`))}},Q=async()=>{let t=q.split(`
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{t as r}from"./useTranslation-Bu0AxynE.js";import{An as i,Bt as a,C as o,Or as s,Rt as ee,h as c,it as l,n as u,tt as d,v as te,y as ne}from"./ui-vendor-BanHlKMb.js";import{o as re,r as f,s as ie}from"./ui-CKcr9ReZ.js";import{t as p}from"./confirmStore-CKkUtP9c.js";import{t as m}from"./Button-DeV-GhQr.js";import{t as h}from"./chatStore-C3c3r8iB.js";import{t as g}from"./evaluationsApi-BE2P4V0I.js";import{t as _}from"./utils-DhBboyBg.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 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,x=()=>{let{t:e,i18n:t}=r(),n=h(e=>e.models),x=h(e=>e.loadModels),[S,C]=(0,v.useState)(`arena`),[w,T]=(0,v.useState)(0),[E,D]=(0,v.useState)(``),[O,k]=(0,v.useState)(``),[A,ae]=(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,oe]=(0,v.useState)(``);(0,v.useEffect)(()=>{x()},[x]),(0,v.useEffect)(()=>{let t=!1;return Promise.all([g.leaderboard(),g.listSets(),g.listRuns(),g.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}},[w,e]),(0,v.useEffect)(()=>{if(!V.some(e=>e.status===`queued`||e.status===`running`))return;let e=window.setInterval(()=>T(e=>e+1),4e3);return()=>window.clearInterval(e)},[V]);let X=n.map(e=>e.name),se=async()=>{if(E.trim()&&O&&A&&!F){I(!0),M(null),P(!1);try{let e=await g.runArenaMatch({prompt:E.trim(),modelA:O,modelB:A});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)}}},Z=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 g.voteArena({compareGroup:j.compareGroup,modelA:n,modelB:r,winner:t});if(!i.success)throw Error(i.message);P(!0),T(e=>e+1),s.success(e(`evaluations.voteRecorded`))}catch(t){s.error(t instanceof Error?t.message:e(`evaluations.voteFailed`))}},Q=async()=>{let t=q.split(`
2
2
  `).map(e=>e.trim()).filter(Boolean);if(G.trim()&&t.length!==0)try{let n=await g.saveSet({name:G.trim(),items:t.map(e=>({prompt:e}))});if(!n.success)throw Error(n.message);K(``),J(``),T(e=>e+1),s.success(e(`evaluations.setSaved`))}catch(t){s.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},ce=async t=>{if(!Y)s.error(e(`evaluations.pickModel`));else try{let n=await g.startRun({setId:t,model:Y});if(!n.success)throw Error(n.message);T(e=>e+1),s.success(e(`evaluations.runStarted`))}catch(t){s.error(t instanceof Error?t.message:e(`evaluations.saveFailed`))}},le=async t=>{try{let e=await g.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`))}},$=[{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)(ie,{width:`wide`,children:[(0,y.jsx)(re,{title:e(`evaluations.title`),description:e(`evaluations.description`)}),(0,y.jsx)(`div`,{role:`tablist`,"aria-label":e(`evaluations.title`),className:`mb-4 inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/8 dark:bg-dark-100/70`,onKeyDown:e=>{let n=$.findIndex(e=>e.id===S),r=t.dir()===`rtl`,i=r?`ArrowLeft`:`ArrowRight`,a=r?`ArrowRight`:`ArrowLeft`,o=-1;e.key===i?o=(n+1)%$.length:e.key===a?o=(n-1+$.length)%$.length:e.key===`Home`?o=0:e.key===`End`&&(o=$.length-1);let s=$[o];s&&(e.preventDefault(),C(s.id),document.getElementById(`evaluations-tab-${s.id}`)?.focus())},children:$.map(e=>(0,y.jsx)(`button`,{id:`evaluations-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":S===e.id,"aria-controls":`evaluations-tabpanel`,tabIndex:S===e.id?0:-1,onClick:()=>C(e.id),className:_(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,S===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))}),S===`arena`&&(0,y.jsxs)(`div`,{id:`evaluations-tabpanel`,role:`tabpanel`,"aria-labelledby":`evaluations-tab-arena`,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:O,onChange:e=>k(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),X.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:A,onChange:e=>ae(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`—`}),X.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`),"aria-label":e(`evaluations.arenaPrompt`),value:E,onChange:e=>D(e.target.value),"data-testid":`arena-prompt`}),(0,y.jsxs)(m,{className:`mt-2`,onClick:()=>void se(),disabled:F||!E.trim()||!O||!A||O===A,"data-testid":`arena-start`,children:[F?(0,y.jsx)(ee,{className:`me-1 h-4 w-4 animate-spin`}):(0,y.jsx)(o,{className:`me-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)(m,{size:`sm`,onClick:()=>void Z(j.candidates[0].key),children:e(`evaluations.voteFirst`)}),(0,y.jsx)(m,{size:`sm`,onClick:()=>void Z(j.candidates[1].key),children:e(`evaluations.voteSecond`)}),(0,y.jsx)(m,{size:`sm`,variant:`outline`,onClick:()=>void Z(`tie`),children:e(`evaluations.voteTie`)}),(0,y.jsx)(m,{size:`sm`,variant:`outline`,onClick:()=>void Z(`both-bad`),children:e(`evaluations.voteBothBad`)})]})]})]}),S===`leaderboard`&&(0,y.jsx)(`div`,{id:`evaluations-tabpanel`,role:`tabpanel`,"aria-labelledby":`evaluations-tab-leaderboard`,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-start 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 pe-2`,children:`#`}),(0,y.jsx)(`th`,{className:`py-1 pe-2`,children:e(`evaluations.model`)}),(0,y.jsx)(`th`,{className:`py-1 pe-2`,children:e(`evaluations.rating`)}),(0,y.jsx)(`th`,{className:`py-1 pe-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 pe-2`,children:t===0?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(c,{className:`h-4 w-4 text-amber-500`}),(0,y.jsx)(`span`,{className:`sr-only`,children:t+1})]}):t+1}),(0,y.jsx)(`td`,{className:`py-1.5 pe-2 font-medium`,children:e.model}),(0,y.jsx)(`td`,{className:`py-1.5 pe-2`,children:e.rating}),(0,y.jsxs)(`td`,{className:`py-1.5 pe-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,children:(0,y.jsx)(f,{icon:c,size:`sm`,title:e(`evaluations.noVotes`)})})})]})]})}),S===`sets`&&(0,y.jsxs)(`div`,{id:`evaluations-tabpanel`,role:`tabpanel`,"aria-labelledby":`evaluations-tab-sets`,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`),"aria-label":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`),"aria-label":e(`evaluations.setPrompts`),value:q,onChange:e=>J(e.target.value)}),(0,y.jsxs)(m,{size:`sm`,className:`mt-2`,onClick:()=>void Q(),disabled:!G.trim()||!q.trim(),children:[(0,y.jsx)(d,{className:`me-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 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,"aria-label":e(`evaluations.pickModel`),value:Y,onChange:e=>oe(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:e(`evaluations.pickModel`)}),X.map(e=>(0,y.jsx)(`option`,{value:e,children:e},`run-${e}`))]})]}),z.length===0&&(0,y.jsx)(f,{icon:a,size:`sm`,title: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:`ms-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)(m,{size:`sm`,variant:`outline`,onClick:()=>void ce(t.id),children:[(0,y.jsx)(l,{className:`me-1 h-3 w-3`}),e(`evaluations.run`)]}),(0,y.jsx)(`button`,{type:`button`,onClick:async()=>{if(await p({title:e(`evaluations.deleteSetConfirmTitle`,{name:t.name}),description:e(`evaluations.deleteSetConfirmDescription`),destructive:!0}))try{await g.deleteSet(t.id),T(e=>e+1)}catch{s.error(e(`evaluations.deleteSetFailed`))}},className:`rounded-sm 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)(te,{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-sm 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?` — ${e(`evaluations.runError`,{detail:t.error})}`:``]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(t.status===`queued`||t.status===`running`)&&(0,y.jsx)(`button`,{type:`button`,onClick:()=>{g.cancelRun(t.id).then(()=>T(e=>e+1)).catch(()=>s.error(e(`evaluations.cancelFailed`)))},className:`rounded-sm p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.cancelRun`),children:(0,y.jsx)(u,{className:`h-3 w-3`})}),t.status===`completed`&&(0,y.jsx)(`button`,{type:`button`,onClick:()=>void le(t.id),className:`rounded-sm p-1 text-gray-500 hover:bg-gray-200 dark:hover:bg-dark-200`,"aria-label":e(`evaluations.exportRun`),children:(0,y.jsx)(i,{className:`h-3 w-3`})})]})]},t.id))]},t.id))})]})]}),S===`feedback`&&(0,y.jsxs)(`div`,{id:`evaluations-tabpanel`,role:`tabpanel`,"aria-labelledby":`evaluations-tab-feedback`,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)(f,{icon:ne,size:`sm`,title: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(t.language,{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};