@runfusion/fusion 0.76.0-beta.1 → 0.76.0-beta.2

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 (138) hide show
  1. package/dist/bin.js +503 -213
  2. package/dist/child-process-worker.js +466 -207
  3. package/dist/client/.vite/manifest.json +260 -260
  4. package/dist/client/assets/{AgentDetailView-Cbl1sw6i.js → AgentDetailView-gak4EWTI.js} +1 -1
  5. package/dist/client/assets/{AgentPermissionPolicyEditor-DD1U5M9p.js → AgentPermissionPolicyEditor-DP1QbZL-.js} +1 -1
  6. package/dist/client/assets/{AgentsView-BMcCbple.js → AgentsView-DAMRTKzI.js} +3 -3
  7. package/dist/client/assets/ChatView-iE-2gf5P.js +13 -0
  8. package/dist/client/assets/{CommandCenter-D7mcD61V.js → CommandCenter-B6RnkLYm.js} +1 -1
  9. package/dist/client/assets/{DevServerView-DaqCn0p5.js → DevServerView-DcFL_LzK.js} +1 -1
  10. package/dist/client/assets/{DirectoryPicker-CLdqqqYN.js → DirectoryPicker-CtjqrYoO.js} +1 -1
  11. package/dist/client/assets/{DocumentsView-BOROVxPm.js → DocumentsView-BkAe2S4H.js} +1 -1
  12. package/dist/client/assets/{EvalsView-BQMXRUlQ.js → EvalsView-CbGA9dMn.js} +1 -1
  13. package/dist/client/assets/{ExperimentalAgentOnboardingModal-1GNeCIQT.js → ExperimentalAgentOnboardingModal-CMgO_S8T.js} +1 -1
  14. package/dist/client/assets/{GoalsView-Cr3c_2GC.js → GoalsView-_3P9J5sf.js} +1 -1
  15. package/dist/client/assets/{InsightsView-DgVBVQM4.js → InsightsView-DOhO7xH5.js} +1 -1
  16. package/dist/client/assets/{MemoryView-C0VzzMSw.js → MemoryView-DwJas8vi.js} +1 -1
  17. package/dist/client/assets/{PiExtensionsManager-D1kkkVtP.js → PiExtensionsManager-B_LiW_e9.js} +1 -1
  18. package/dist/client/assets/{PluginManager-BW-_Zyo5.js → PluginManager-BkB6WLQc.js} +1 -1
  19. package/dist/client/assets/{PullRequestView-Cmlo4nWA.js → PullRequestView-DcH5tmYc.js} +1 -1
  20. package/dist/client/assets/{ReportModal-BWuaroTF.js → ReportModal-BOEbqtqG.js} +1 -1
  21. package/dist/client/assets/{ResearchView-BmkF_vZU.js → ResearchView-Dp6V42pI.js} +1 -1
  22. package/dist/client/assets/{SecretsView-DVc8Hky0.js → SecretsView-BCqXHB2L.js} +1 -1
  23. package/dist/client/assets/{SessionTerminal-DCXrxA57.js → SessionTerminal-CkdoQv4y.js} +1 -1
  24. package/dist/client/assets/{SettingsModal-DZ32F1c-.js → SettingsModal-D4Fn4GlS.js} +3 -3
  25. package/dist/client/assets/{SettingsModal-DqwpLnDU.js → SettingsModal-Dc7YG6KB.js} +1 -1
  26. package/dist/client/assets/{SettingsTextareaRow-B5spAoOY.js → SettingsTextareaRow-WSkBoAOO.js} +1 -1
  27. package/dist/client/assets/{SetupWizardModal-VTBLyFzr.js → SetupWizardModal-VTrJAsKd.js} +2 -2
  28. package/dist/client/assets/{SkillsView-CR91ey9d.js → SkillsView-CXeXOxfF.js} +1 -1
  29. package/dist/client/assets/{WorkflowNodeEditor-BzGh_Fd9.js → WorkflowNodeEditor-DoxLGPRF.js} +1 -1
  30. package/dist/client/assets/{agent-import-generation-D27NKQsr.js → agent-import-generation-upc0yw-M.js} +1 -1
  31. package/dist/client/assets/{agentsOrgChartLayout-C2K_M3x3.js → agentsOrgChartLayout-C3iumMrW.js} +1 -1
  32. package/dist/client/assets/{architectureDiagram-3BPJPVTR-BQy8UcRx.js → architectureDiagram-3BPJPVTR-D6jqc3fJ.js} +1 -1
  33. package/dist/client/assets/{blockDiagram-GPEHLZMM-CZG1bqFQ.js → blockDiagram-GPEHLZMM-DY3AKuPD.js} +1 -1
  34. package/dist/client/assets/{c4Diagram-AAUBKEIU-CZmO_kg3.js → c4Diagram-AAUBKEIU-CpD52V4g.js} +1 -1
  35. package/dist/client/assets/channel-CaxOu15c.js +1 -0
  36. package/dist/client/assets/{chunk-2J33WTMH-jsad6DTE.js → chunk-2J33WTMH-CPeIHyAX.js} +1 -1
  37. package/dist/client/assets/{chunk-4BX2VUAB-DX7SuvwP.js → chunk-4BX2VUAB-ivAwI4xM.js} +1 -1
  38. package/dist/client/assets/{chunk-55IACEB6-De20xFgU.js → chunk-55IACEB6-BtVQ5XaZ.js} +1 -1
  39. package/dist/client/assets/{chunk-727SXJPM-CNiri9yW.js → chunk-727SXJPM-1eap1vDU.js} +1 -1
  40. package/dist/client/assets/{chunk-AQP2D5EJ-DvDqG-ax.js → chunk-AQP2D5EJ-B2NB3BW9.js} +1 -1
  41. package/dist/client/assets/{chunk-FMBD7UC4-DkMdKaUq.js → chunk-FMBD7UC4-Hk_smNYv.js} +1 -1
  42. package/dist/client/assets/{chunk-ND2GUHAM-Do5BwIrI.js → chunk-ND2GUHAM-BmGCAojk.js} +1 -1
  43. package/dist/client/assets/{chunk-QZHKN3VN-BnJgt9vl.js → chunk-QZHKN3VN-D0aXZ8CV.js} +1 -1
  44. package/dist/client/assets/classDiagram-4FO5ZUOK-DXIkGbsl.js +1 -0
  45. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-DXIkGbsl.js +1 -0
  46. package/dist/client/assets/{cose-bilkent-S5V4N54A-D-ivAzzF.js → cose-bilkent-S5V4N54A-DAbu_gnF.js} +1 -1
  47. package/dist/client/assets/{dagre-BM42HDAG-Bpd9L0or.js → dagre-BM42HDAG-BdmLlrDJ.js} +1 -1
  48. package/dist/client/assets/{dashboard-view-DSvVO6Vr.js → dashboard-view-BoFBSXUn.js} +1 -1
  49. package/dist/client/assets/{dashboard-view-CgBo8Ctn.js → dashboard-view-CULL1yhL.js} +1 -1
  50. package/dist/client/assets/{dashboard-view-C-XU9CVv.js → dashboard-view-CxXMDfNY.js} +1 -1
  51. package/dist/client/assets/{dashboard-view-DbaRE8Ma.js → dashboard-view-PRCWCSLm.js} +1 -1
  52. package/dist/client/assets/{diagram-2AECGRRQ-B6TT1NWU.js → diagram-2AECGRRQ-PpqLbVUA.js} +1 -1
  53. package/dist/client/assets/{diagram-5GNKFQAL-DpRS2yRw.js → diagram-5GNKFQAL-9rkGmTwh.js} +1 -1
  54. package/dist/client/assets/{diagram-KO2AKTUF-BVbZr02C.js → diagram-KO2AKTUF-BT-efOMo.js} +1 -1
  55. package/dist/client/assets/{diagram-LMA3HP47-DzENbfal.js → diagram-LMA3HP47-w79OWFxg.js} +1 -1
  56. package/dist/client/assets/{diagram-OG6HWLK6-BIePG5SY.js → diagram-OG6HWLK6-Bye9I5IO.js} +1 -1
  57. package/dist/client/assets/{erDiagram-TEJ5UH35-CQo3WBwo.js → erDiagram-TEJ5UH35-aodREgDf.js} +1 -1
  58. package/dist/client/assets/{flowDiagram-I6XJVG4X-Ct2H4jYo.js → flowDiagram-I6XJVG4X-D0DKItY3.js} +1 -1
  59. package/dist/client/assets/{folder-open-DAh8mpTX.js → folder-open-CqvaMJvx.js} +1 -1
  60. package/dist/client/assets/{ganttDiagram-6RSMTGT7-DyOLCG4B.js → ganttDiagram-6RSMTGT7-CZVApkvw.js} +1 -1
  61. package/dist/client/assets/{gitGraphDiagram-PVQCEYII-sC28-su3.js → gitGraphDiagram-PVQCEYII-D_ynwJ4p.js} +1 -1
  62. package/dist/client/assets/index-DWRJyaa3.js +2818 -0
  63. package/dist/client/assets/{infoDiagram-5YYISTIA-Q81_5aBZ.js → infoDiagram-5YYISTIA-pJG6zxjk.js} +1 -1
  64. package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-Cwkjs0z5.js → ishikawaDiagram-YF4QCWOH-nFZ5laUo.js} +1 -1
  65. package/dist/client/assets/{journeyDiagram-JHISSGLW-BXcBV1Bc.js → journeyDiagram-JHISSGLW-CWpCaAIe.js} +1 -1
  66. package/dist/client/assets/{kanban-definition-UN3LZRKU-BI7hW892.js → kanban-definition-UN3LZRKU-ATkPspKa.js} +1 -1
  67. package/dist/client/assets/{mermaid.core-B8oDA6jj.js → mermaid.core-CDXPNs7a.js} +4 -4
  68. package/dist/client/assets/{mindmap-definition-RKZ34NQL-COG6_9eD.js → mindmap-definition-RKZ34NQL-BkqS9tpe.js} +1 -1
  69. package/dist/client/assets/{pieDiagram-4H26LBE5-D11brZ_N.js → pieDiagram-4H26LBE5-DEUyVLs-.js} +1 -1
  70. package/dist/client/assets/{puzzle-D3_Z_rlW.js → puzzle-DQ0y1-XK.js} +1 -1
  71. package/dist/client/assets/{quadrantDiagram-W4KKPZXB-jmhDVZcv.js → quadrantDiagram-W4KKPZXB-ESBJNK5c.js} +1 -1
  72. package/dist/client/assets/{requirementDiagram-4Y6WPE33-BKCUWI1E.js → requirementDiagram-4Y6WPE33-CqPs7zcv.js} +1 -1
  73. package/dist/client/assets/{sankeyDiagram-5OEKKPKP-HsZdEl2t.js → sankeyDiagram-5OEKKPKP-CkFN0m14.js} +1 -1
  74. package/dist/client/assets/{sequenceDiagram-3UESZ5HK-CsDf7Fup.js → sequenceDiagram-3UESZ5HK-Dx2nDuMO.js} +1 -1
  75. package/dist/client/assets/{shield-alert-C16k8wNu.js → shield-alert-BS05s4RM.js} +1 -1
  76. package/dist/client/assets/{standing-instructions-template-BqAyftqe.js → standing-instructions-template-xprxYNHm.js} +1 -1
  77. package/dist/client/assets/{stateDiagram-AJRCARHV-fvzWhltB.js → stateDiagram-AJRCARHV-EUPmRFGd.js} +1 -1
  78. package/dist/client/assets/{stateDiagram-v2-BHNVJYJU-cnt42Sr_.js → stateDiagram-v2-BHNVJYJU-DcQ2mhi5.js} +1 -1
  79. package/dist/client/assets/{timeline-definition-PNZ67QCA-DsZFCSMb.js → timeline-definition-PNZ67QCA-D4YO_3V-.js} +1 -1
  80. package/dist/client/assets/{upload-_s5sL5Pq.js → upload-BjyBtxo7.js} +1 -1
  81. package/dist/client/assets/{users-DH1U5ISc.js → users-D5ogZ7WQ.js} +1 -1
  82. package/dist/client/assets/{vennDiagram-CIIHVFJN-B3KDWS-e.js → vennDiagram-CIIHVFJN-BT5_XuQL.js} +1 -1
  83. package/dist/client/assets/{wardley-L42UT6IY-BKs5MtQS.js → wardley-L42UT6IY-X_ZMW457.js} +1 -1
  84. package/dist/client/assets/{wardleyDiagram-YWT4CUSO-CNsEoXVB.js → wardleyDiagram-YWT4CUSO-GK9nONHU.js} +1 -1
  85. package/dist/client/assets/{xychartDiagram-2RQKCTM6-kq_gW4QC.js → xychartDiagram-2RQKCTM6-Dw3zXHAq.js} +1 -1
  86. package/dist/client/index.html +1 -1
  87. package/dist/client/version.json +1 -1
  88. package/dist/droid-cli/package.json +1 -1
  89. package/dist/extension.js +647 -207
  90. package/dist/migrations/0057_fn_9004_project_ownership_default_reconciliation.sql +13 -0
  91. package/dist/migrations/0058_fn_9014_message_archive.sql +13 -0
  92. package/dist/pi-claude-cli/package.json +5 -5
  93. package/dist/plugin-sdk/index.js +69 -23
  94. package/dist/plugins/fusion-plugin-acp-runtime/bundled.js +69 -23
  95. package/dist/plugins/fusion-plugin-acp-runtime/package.json +1 -1
  96. package/dist/plugins/fusion-plugin-claude-runtime/bundled.js +69 -23
  97. package/dist/plugins/fusion-plugin-claude-runtime/package.json +1 -1
  98. package/dist/plugins/fusion-plugin-cli-printing-press/bundled.js +69 -23
  99. package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
  100. package/dist/plugins/fusion-plugin-compound-engineering/bundled.js +69 -23
  101. package/dist/plugins/fusion-plugin-compound-engineering/package.json +1 -1
  102. package/dist/plugins/fusion-plugin-cursor-runtime/bundled.js +69 -23
  103. package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
  104. package/dist/plugins/fusion-plugin-dependency-graph/bundled.js +69 -23
  105. package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
  106. package/dist/plugins/fusion-plugin-droid-runtime/bundled.js +71 -25
  107. package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
  108. package/dist/plugins/fusion-plugin-grok-runtime/bundled.js +69 -23
  109. package/dist/plugins/fusion-plugin-grok-runtime/package.json +1 -1
  110. package/dist/plugins/fusion-plugin-hermes-runtime/bundled.js +69 -23
  111. package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
  112. package/dist/plugins/fusion-plugin-linear-import/bundled.js +69 -23
  113. package/dist/plugins/fusion-plugin-linear-import/package.json +1 -1
  114. package/dist/plugins/fusion-plugin-omp-runtime/bundled.js +69 -23
  115. package/dist/plugins/fusion-plugin-omp-runtime/package.json +1 -1
  116. package/dist/plugins/fusion-plugin-openclaw-runtime/bundled.js +69 -23
  117. package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
  118. package/dist/plugins/fusion-plugin-paperclip-runtime/bundled.js +69 -23
  119. package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
  120. package/dist/plugins/fusion-plugin-quality/bundled.js +69 -23
  121. package/dist/plugins/fusion-plugin-quality/package.json +1 -1
  122. package/dist/plugins/fusion-plugin-reports/bundled.js +69 -23
  123. package/dist/plugins/fusion-plugin-reports/package.json +1 -1
  124. package/dist/plugins/fusion-plugin-roadmap/bundled.js +69 -23
  125. package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
  126. package/dist/plugins/fusion-plugin-todos/bundled.js +69 -23
  127. package/dist/plugins/fusion-plugin-todos/package.json +1 -1
  128. package/dist/plugins/fusion-plugin-whatsapp-chat/bundled.js +69 -23
  129. package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
  130. package/package.json +3 -3
  131. package/skill/fusion/SKILL.md +1 -1
  132. package/skill/fusion/references/extension-tools.md +22 -0
  133. package/skill/fusion/references/fusion-capabilities.md +2 -0
  134. package/dist/client/assets/ChatView-DcM-ARpZ.js +0 -13
  135. package/dist/client/assets/channel-Cwl9FefC.js +0 -1
  136. package/dist/client/assets/classDiagram-4FO5ZUOK-BZtWCoHC.js +0 -1
  137. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-BZtWCoHC.js +0 -1
  138. package/dist/client/assets/index-BlGpMJSZ.js +0 -2818
@@ -0,0 +1,13 @@
1
+ import{r as a,j as t}from"./vendor-react-SZ_qB27O.js";import{c as ci,ar as Dt,ap as wt,aq as Ca,bz as Ds,dr as Qi,ds as Yi,dt as ua,av as X,du as Ji,dv as It,dw as Tt,dx as Sa,dy as Zi,dz as eo,dA as to,dB as no,dC as ao,dD as so,bh as io,cZ as Ma,dE as ke,aZ as oo,bN as li,ci as yn,dF as ro,am as kn,dG as co,dH as lo,c6 as uo,F as mo,aJ as ho,b3 as wn,Y as fo,d8 as go,dI as po,dJ as vo,f as bo,aX as wo,dK as xo,dL as di,dM as ui,dN as yo,dO as ko,K as Co,dP as So,dQ as Mo,dR as Is,dS as No,dT as Ro,dU as Ls,y as jo,dV as Ao,q as To,u as Eo,aH as Do,dW as ma,C as hn,dX as fn,dY as Ps,bM as Fs,v as ha,P as pt,V as Io,c8 as $s,db as _s,da as Lo,X as zs,aI as Po,dZ as Fo,x as fa,d_ as ga,d$ as Bs,e0 as pa,e1 as Os,e2 as Hs,e3 as Us,e4 as $o,e5 as _o,bK as Ks}from"./index-DWRJyaa3.js";import{u as _e}from"./vendor-i18n-Duky4gdQ.js";import{SessionTerminal as Vs}from"./SessionTerminal-CkdoQv4y.js";import"./vendor-codemirror-CcrtqoCy.js";import"./vendor-reactflow-BlIeoTu4.js";import"./vendor-xterm-BNq00GSj.js";import"./shield-alert-BS05s4RM.js";/**
2
+ * @license lucide-react v1.7.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const zo=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],mi=ci("hash",zo);/**
7
+ * @license lucide-react v1.7.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Bo=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],Oo=ci("tag",Bo);function gn(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Ho(){try{typeof import.meta<"u"}catch{}try{if(typeof localStorage<"u")return localStorage.getItem("kb-debug-room-open")==="1"}catch{}return!1}function va(i,o){const m=Ho(),g=o?.warm===!0,u=gn(),h=new Map;let k=!1,C=!1;return{mark(j){k||C||!m||h.has(j)||h.set(j,gn())},complete:j=>{if(!m||k||C){k=!0;return}k=!0,h.set("complete",gn());const I=Array.from(h.entries()).sort((E,N)=>E[1]-N[1]);let M=u;const s={};for(const[E,N]of I)s[E]=Math.max(0,N-M),M=N;const v=Math.max(0,gn()-u);try{console.debug("[room-open]",{roomId:i,warm:g,totalMs:v,phases:s,...j??{}})}catch{}},cancel(){C=!0,k=!0}}}const $e="fusion:chat-active-room";class hi extends Error{roomId;constructor(o,m){super(o),this.name="RoomMessageDeliveredButReplyFailedError",this.roomId=m}}function Na(i){return[...i].sort((o,m)=>new Date(m.updatedAt).getTime()-new Date(o.updatedAt).getTime())}function Ge(i,o){const m=i.findIndex(u=>u.id===o.id);if(m===-1)return Na([o,...i]);const g=[...i];return g[m]=o,Na(g)}function Ie(i){try{return JSON.parse(i.data)}catch{return null}}function ba(i){return i.slice().reverse()}function Uo(i,o,m){return{id:`temp-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,roomId:i,role:"user",content:o,thinkingOutput:null,metadata:null,senderAgentId:null,mentions:[],...m?.length?{attachments:m}:{},createdAt:new Date().toISOString()}}function Ws(i,o,m){if(i.some(u=>u.id===o.id))return i;const g=m?i.findIndex(u=>u.id===m):-1;if(g>=0){const u=[...i];return u[g]=o,u}if(o.role==="user"){const u=i.findIndex(h=>h.role==="user"&&h.id.startsWith("temp-")&&h.content.trim()===o.content.trim());if(u>=0){const h=[...i];return h[u]=o,h}}return[...i,o]}function Ko(i,o){const{t:m}=_e("app"),g=`${Dt.CHAT_ROOMS}:${i??"global"}`,u=`${Dt.ACTIVE_CHAT_ROOM_ID}:${i??"global"}`,h=a.useCallback(c=>`${Dt.CHAT_ROOM_MESSAGES_PREFIX}${i??"global"}:${c}`,[i]),k=a.useCallback(c=>`${Dt.CHAT_ROOM_MEMBERS_PREFIX}${i??"global"}:${c}`,[i]),[C,b]=a.useState(()=>{const c=wt(g,{maxAgeMs:Ca});return Array.isArray(c)?c:[]}),[j,I]=a.useState(()=>C.length===0),[M,s]=a.useState(null),[v,E]=a.useState(()=>{const c=wt(u,{maxAgeMs:Ds});return c?C.find(p=>p.id===c)??null:null}),[N,S]=a.useState([]),[l,L]=a.useState([]),[F,U]=a.useState(!1),B=a.useRef(C),T=a.useRef(v),Q=a.useRef(0),se=a.useRef(i);B.current=C,T.current=v,se.current!==i&&(se.current=i,Q.current+=1);const Y=a.useCallback(async c=>{if(!c){S([]),L([]),U(!1);return}const p=va(c.id,{warm:!1});p.mark("select");const y=wt(h(c.id),{maxAgeMs:Qi}),f=wt(k(c.id),{maxAgeMs:Ca}),A=Array.isArray(y)&&y.length>0,_=Array.isArray(f)&&f.length>0;A||_?(p.mark("cache-hit"),A&&(L(y),p.mark("hydrate")),_&&S(f),U(!1)):(L([]),U(!0));try{const[J,ve]=await Promise.all([Yi(c.id,i),ua(c.id,{limit:100,order:"desc"},i)]);p.mark("members-fetch"),p.mark("messages-fetch"),X(k(c.id),J.members,{maxBytes:5e5});const ee=ba(ve.messages);X(h(c.id),ee,{maxBytes:5e5}),T.current?.id===c.id&&(S(J.members),L(ee),p.mark("hydrate"))}catch{!A&&!_&&(S([]),L([]))}finally{U(!1),p.complete({warm:A,membersCached:_})}},[k,h,i]),D=a.useCallback(async()=>{B.current.length===0&&I(!0);try{const c=await Ji({},i),p=Na(c.rooms);b(p),X(g,p,{maxBytes:5e5}),s(null);const y=wt(u,{maxAgeMs:Ds})??It($e,i);if(y){const f=p.find(A=>A.id===y)??null;f?(E(f),Y(f)):(Tt($e,i),X(u,"",{maxBytes:5e5}))}}catch(c){const p=c instanceof Error?c.message:m("chatRooms.error.failedToLoad","Failed to load chat rooms");s(p),o?.(p,"error")}finally{I(!1)}},[u,o,Y,i,g]),O=a.useCallback(c=>{if(!c){T.current=null,E(null),Tt($e,i),X(u,"",{maxBytes:5e5}),Y(null);return}const p=B.current.find(y=>y.id===c)??null;T.current=p,E(p),p&&(Sa($e,p.id,i),X(u,p.id,{maxBytes:5e5}),Y(p))},[u,Y,i]),R=a.useCallback(async c=>{const y=(await Zi({name:c.name,memberAgentIds:c.memberAgentIds},i)).room;return b(f=>Ge(f,y)),T.current=y,E(y),Sa($e,y.id,i),X(u,y.id,{maxBytes:5e5}),await Y(y),y},[u,Y,i]),$=a.useCallback(async(c,p)=>{const f=(await eo(c,p,i)).room;return b(A=>Ge(A,f)),T.current?.id===f.id&&(T.current=f,E(f)),f},[i]),ce=a.useCallback(async c=>{await to(c,i),b(p=>p.filter(y=>y.id!==c)),X(h(c),[],{maxBytes:5e5}),X(k(c),[],{maxBytes:5e5}),T.current?.id===c&&(T.current=null,E(null),S([]),L([]),Tt($e,i),X(u,"",{maxBytes:5e5}))},[u,k,h,i]),ae=a.useCallback(async(c,p)=>{const y=T.current,f=y?.id;if(!f)throw new Error(m("chatRooms.error.selectRoomFirst","Select a room before sending a message"));const A=va(f,{warm:!1}),_=p?.files?.map(ee=>({id:`upload-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,filename:ee.name,originalName:ee.name,mimeType:ee.type||"application/octet-stream",size:ee.size,createdAt:new Date().toISOString()})),J=Uo(f,c,_?.length?_:p?.attachments);T.current?.id===f&&L(ee=>{const he=[...ee,J];return X(h(f),he,{maxBytes:5e5}),he});let ve=!1;try{const ee=[];if(p?.files?.length)for(const fe of p.files)try{const ze=await no(f,fe,i);ee.push(ze.attachment)}catch{throw new Error(m("chatRooms.error.failedToUpload","Failed to upload attachment: {{filename}}",{filename:fe.name}))}const he=[...p?.attachments??[],...ee],Ce=await ao(f,{content:c,...he.length?{attachments:he}:{}},i);ve=!0;try{p?.onDelivered?.()}catch{}Ce.message?.createdAt&&y&&b(fe=>Ge(fe,{...y,updatedAt:Ce.message.createdAt})),T.current?.id===f&&L(fe=>{const ze=Ws(fe,Ce.message,J.id);return X(h(f),ze,{maxBytes:5e5}),ze});const ie=await ua(f,{limit:100,order:"desc"},i),Le=ba(ie.messages);if(X(h(f),Le,{maxBytes:5e5}),T.current?.id!==f)return;L(Le),A.mark("hydrate")}catch(ee){let he=null;try{const ie=await ua(f,{limit:100,order:"desc"},i);he=ba(ie.messages),X(h(f),he,{maxBytes:5e5}),T.current?.id===f&&(L(he),A.mark("hydrate"))}catch{!ve&&T.current?.id===f&&L(ie=>{const Le=ie.filter(fe=>fe.id!==J.id);return X(h(f),Le,{maxBytes:5e5}),Le})}const Ce=he?.some(ie=>ie.role==="user"&&ie.content.trim()===J.content.trim());if(ve||Ce){const ie=ee instanceof Error&&ee.message.trim()?ee.message:m("chatRooms.error.deliveredButRefreshFailed","Message delivered, but failed to refresh room replies");throw new hi(ie,f)}throw ee}finally{A.complete({source:"send-room-message"})}},[h,i]),me=a.useCallback(async c=>{!c||!B.current.some(p=>p.id===c)||(await so(c,i),X(h(c),[],{maxBytes:5e5}),T.current?.id===c&&L([]))},[h,i]);return a.useEffect(()=>{D()},[D]),a.useEffect(()=>{const c=Q.current,p=i?`/api/events?projectId=${encodeURIComponent(i)}`:"/api/events";return io(p,{onReconnect:()=>{Ma({view:"useChatRooms",trigger:"sse-reconnect",projectId:i,replayAttempted:!1});const y=T.current?.id;if(y){const f=va(y,{warm:!0});f.mark("sse-reconnect-refresh"),D().finally(()=>f.complete({source:"sse-reconnect"}));return}D()},events:{"chat:room:created":y=>{if(Q.current!==c)return;const f=Ie(y);f&&b(A=>Ge(A,f))},"chat:room:updated":y=>{if(Q.current!==c)return;const f=Ie(y);f&&(b(A=>Ge(A,f)),T.current?.id===f.id&&(T.current=f,E(f)))},"chat:room:deleted":y=>{if(Q.current!==c)return;const f=Ie(y);f?.id&&(b(A=>A.filter(_=>_.id!==f.id)),X(h(f.id),[],{maxBytes:5e5}),X(k(f.id),[],{maxBytes:5e5}),T.current?.id===f.id&&(T.current=null,E(null),S([]),L([]),Tt($e,i),X(u,"",{maxBytes:5e5})))},"chat:room:member:added":y=>{if(Q.current!==c)return;const f=Ie(y);!f||T.current?.id!==f.roomId||S(A=>{if(A.some(J=>J.agentId===f.agentId))return A;const _=[...A,f];return X(k(f.roomId),_,{maxBytes:5e5}),_})},"chat:room:member:removed":y=>{if(Q.current!==c)return;const f=Ie(y);!f||T.current?.id!==f.roomId||S(A=>{const _=A.filter(J=>J.agentId!==f.agentId);return X(k(f.roomId),_,{maxBytes:5e5}),_})},"chat:room:message:added":y=>{if(Q.current!==c)return;const f=Ie(y);f&&(b(A=>{const _=A.find(J=>J.id===f.roomId);return _?Ge(A,{..._,updatedAt:f.createdAt}):A}),T.current?.id===f.roomId&&L(A=>{const _=Ws(A,f);return _===A?A:(X(h(f.roomId),_,{maxBytes:5e5}),_)}))},"chat:room:message:updated":y=>{if(Q.current!==c)return;const f=Ie(y);!f||T.current?.id!==f.roomId||L(A=>{const _=A.map(J=>J.id===f.id?f:J);return X(h(f.roomId),_,{maxBytes:5e5}),_})},"chat:room:message:deleted":y=>{if(Q.current!==c)return;const f=Ie(y);f?.id&&L(A=>{const _=A.filter(ve=>ve.id!==f.id),J=T.current?.id;return J&&X(h(J),_,{maxBytes:5e5}),_})},"chat:room:messages:cleared":y=>{if(Q.current!==c)return;const f=Ie(y);f?.roomId&&(X(h(f.roomId),[],{maxBytes:5e5}),T.current?.id===f.roomId&&L([]),b(A=>{const _=A.find(J=>J.id===f.roomId);return _?Ge(A,{..._,updatedAt:new Date().toISOString()}):A}))}}})},[u,k,h,i,D]),a.useEffect(()=>{v&&(C.some(c=>c.id===v.id)||(T.current=null,E(null),S([]),L([]),Tt($e,i),X(u,"",{maxBytes:5e5})))},[v,u,i,C]),{rooms:C,roomsLoading:j,roomsError:M,activeRoom:v,activeRoomMembers:N,messages:l,messagesLoading:F,selectRoom:O,createRoom:R,updateRoomSettings:$,deleteRoom:ce,sendRoomMessage:ae,clearRoom:me,refreshRooms:D}}const Et={direct:"fusion:chat-unread:direct",room:"fusion:chat-unread:rooms"},Xs=200;function Ra(i){if(!i)return null;const o=new Date(i).getTime();return Number.isFinite(o)?o:null}function fi(i){const o=Object.entries(i);if(o.length<=Xs)return i;const m=o.map(([g,u])=>({id:g,timestamp:u,value:Ra(u)??0})).sort((g,u)=>u.value-g.value).slice(0,Xs);return Object.fromEntries(m.map(({id:g,timestamp:u})=>[g,u]))}function pn(i){if(!i)return{};try{const o=JSON.parse(i);if(!o||typeof o!="object")return{};const m={};for(const[g,u]of Object.entries(o))typeof g=="string"&&typeof u=="string"&&(m[g]=u);return fi(m)}catch{return{}}}function Vo(i){const[o,m]=a.useState(()=>{try{return pn(It(Et.direct,i))}catch{return{}}}),[g,u]=a.useState(()=>{try{return pn(It(Et.room,i))}catch{return{}}});a.useEffect(()=>{try{m(pn(It(Et.direct,i)))}catch{m({})}try{u(pn(It(Et.room,i)))}catch{u({})}},[i]);const h=a.useMemo(()=>({direct:o,room:g}),[o,g]),k=a.useCallback((M,s)=>{const v=fi(s);try{Sa(Et[M],JSON.stringify(v),i)}catch{}return v},[i]),C=a.useCallback((M,s)=>{if(M==="direct"){m(v=>k(M,s(v)));return}u(v=>k(M,s(v)))},[k]),b=a.useCallback((M,s,v)=>{const E=Ra(v);if(E===null)return!1;const N=h[M][s],S=Ra(N);return S===null?!0:E>S},[h]),j=a.useCallback((M,s,v)=>{if(!s)return;const E=v??new Date().toISOString();C(M,N=>({...N,[s]:E}))},[C]),I=a.useCallback((M,s)=>{s.length!==0&&C(M,v=>{const E={...v};for(const N of s)N.id&&(E[N.id]=N.lastActivityAt??new Date().toISOString());return E})},[C]);return{isUnread:b,markRead:j,markAllRead:I}}const Wo=["",...ro];function qs({level:i,onChange:o,defaultThinkingLevel:m="off",showTargetSection:g=!0,models:u=[],favoriteProviders:h=[],favoriteModels:k=[],agents:C=[],agentId:b,modelProvider:j,modelId:I,onChangeModel:M,disabled:s=!1}){const{t:v}=_e("app"),[E,N]=a.useState(!1),[S,l]=a.useState(()=>b&&b!==ke?"agent":"model"),L=a.useRef(null),F=i??"",U=j&&I?`${j}/${I}`:"",B=b&&b!==ke?b:"",T=F!==""||g&&(!!U||!!B),Q="chat-thinking-level-listbox";a.useEffect(()=>{if(!E)return;const c=p=>{const y=p.target;if(!(y instanceof Node))return;const f=L.current?.contains(y),A=y instanceof Element&&!!y.closest(".model-combobox-dropdown--portal");!f&&!A&&N(!1)};return document.addEventListener("pointerdown",c),()=>document.removeEventListener("pointerdown",c)},[E]),a.useEffect(()=>{N(!1),l(B?"agent":"model")},[F,B,U]);const se=a.useMemo(()=>C.find(c=>c.id===B),[C,B]),Y=c=>c===""?v("modelSelection.thinkingDefault","Default ({{level}})",{level:m??"off"}):v(`models.options.${c}`,c==="xhigh"?"Very High":c.charAt(0).toUpperCase()+c.slice(1)),D=c=>{N(!1),o(c)},O=c=>{const p=c.indexOf("/");p<=0||(N(!1),M?.({modelProvider:c.slice(0,p),modelId:c.slice(p+1)}))},R=c=>{c&&(N(!1),M?.({agentId:c}))},$=c=>{l(c)},ce=c=>{c.key==="Escape"&&N(!1)},ae=(c,p)=>{if(c.key==="Escape"){c.preventDefault(),N(!1);return}(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),D(p))},me=(c,p)=>{if(c.key==="Escape"){c.preventDefault(),N(!1);return}(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),R(p))};return t.jsxs("div",{className:"chat-thinking-level-root",ref:L,children:[t.jsx("button",{type:"button",className:`btn-icon chat-thinking-btn${T?" chat-thinking-btn--active":""}`,"data-testid":"chat-thinking-btn","aria-haspopup":"dialog","aria-expanded":E,"aria-controls":Q,"aria-label":v("chat.thinkingLevelButton","Thinking level"),title:v("chat.thinkingLevelButton","Thinking level"),disabled:s,onClick:()=>N(c=>!c),onKeyDown:ce,children:t.jsx(oo,{size:16})}),E?t.jsxs("div",{className:"chat-thinking-popover",role:"presentation","data-testid":"chat-thinking-popover",children:[g?t.jsxs("section",{className:"chat-thinking-target-section","aria-label":v("chat.modelAgentSection","Model / Agent"),children:[t.jsx("div",{className:"chat-thinking-section-title",children:v("chat.modelAgentSection","Model / Agent")}),t.jsxs("div",{className:"chat-thinking-mode-toggle","data-testid":"chat-thinking-mode-toggle",children:[t.jsx("button",{type:"button",className:`chat-thinking-mode-btn${S==="model"?" chat-thinking-mode-btn--active":""}`,"data-testid":"chat-thinking-mode-model","aria-pressed":S==="model",onPointerDown:c=>{c.button===0&&$("model")},onClick:c=>{c.detail===0&&$("model")},children:v("chat.newChatModeModel","Model")}),t.jsx("button",{type:"button",className:`chat-thinking-mode-btn${S==="agent"?" chat-thinking-mode-btn--active":""}`,"data-testid":"chat-thinking-mode-agent","aria-pressed":S==="agent",onPointerDown:c=>{c.button===0&&$("agent")},onClick:c=>{c.detail===0&&$("agent")},children:v("chat.newChatModeAgent","Agent")})]}),S==="model"?t.jsxs("div",{className:"chat-thinking-model-picker","data-testid":"chat-thinking-model-picker",children:[t.jsx(li,{models:u,value:U,onChange:O,label:v("chat.newChatModeModel","Model"),placeholder:v("chat.selectModel","Select a model"),disabled:!M||u.length===0,favoriteProviders:h,favoriteModels:k,menuWidth:"readable"}),u.length===0?t.jsx("div",{className:"chat-thinking-empty","data-testid":"chat-thinking-model-empty",children:v("chat.noModelsAvailable","No models available")}):null]}):t.jsx("div",{className:"chat-thinking-agent-list","data-testid":"chat-thinking-agent-list",children:C.length===0?t.jsx("div",{className:"chat-thinking-empty","data-testid":"chat-thinking-agent-empty",children:v("chat.noAgentsAvailable","No agents available")}):C.map(c=>{const p=B===c.id;return t.jsxs("button",{type:"button",className:`chat-thinking-agent-item${p?" chat-thinking-agent-item--selected":""}`,"data-testid":`chat-thinking-agent-${c.id}`,"aria-pressed":p,disabled:!M,onClick:()=>R(c.id),onKeyDown:y=>me(y,c.id),children:[t.jsx(yn,{size:16}),t.jsx("span",{className:"chat-thinking-agent-name",children:c.name||c.id}),c.role?t.jsx("span",{className:"chat-thinking-agent-role",children:c.role}):null]},c.id)})}),se?t.jsx("div",{className:"chat-thinking-current-target","data-testid":"chat-thinking-current-agent",children:v("chat.currentAgentTarget","Current agent: {{name}}",{name:se.name||se.id})}):U?t.jsx("div",{className:"chat-thinking-current-target","data-testid":"chat-thinking-current-model",children:v("chat.currentModelTarget","Current model: {{model}}",{model:U})}):t.jsx("div",{className:"chat-thinking-current-target","data-testid":"chat-thinking-current-default",children:v("chat.currentDefaultTarget","Using the default chat target")})]}):null,t.jsxs("section",{className:"chat-thinking-level-section","aria-label":v("chat.thinkingLevelButton","Thinking level"),children:[t.jsx("div",{className:"chat-thinking-section-title",children:v("chat.thinkingLevelSection","Thinking level")}),t.jsx("div",{id:Q,className:"chat-thinking-popover-list",role:"listbox","aria-label":v("chat.thinkingLevelButton","Thinking level"),children:Wo.map(c=>{const p=F===c;return t.jsx("button",{type:"button",role:"option","aria-selected":p,className:`chat-thinking-popover-option${p?" active":""}`,"data-testid":`chat-thinking-option-${c||"default"}`,onClick:()=>D(c),onKeyDown:y=>ae(y,c),children:Y(c)},c||"default")})})]})]}):null]})}function Gs(i){return i.trim().toLowerCase().replace(/[\s-]+/g,"_").replace(/_+/g,"_")}function gi(i,o){const m=o.trim();if(!m)return!0;const g=Gs(m);return Gs(i).includes(g)||i.toLowerCase().includes(m.toLowerCase())}function Qs({agents:i,filter:o,highlightedIndex:m,visible:g,onSelect:u,position:h="below",roomMemberIds:k,roomName:C}){const{t:b}=_e("app"),j=a.useMemo(()=>i.filter(N=>gi(N.name,o)),[i,o]),I=!!k,M=I&&o.trim().length>0,s=a.useMemo(()=>I?j.filter(N=>k?.has(N.id)):j,[j,k,I]),v=a.useMemo(()=>I?j.filter(N=>!k?.has(N.id)):[],[j,k,I]),E=M?[...s,...v]:s;return g?t.jsx("div",{className:`agent-mention-popup agent-mention-popup--${h}`,"data-testid":"agent-mention-popup",role:"listbox","aria-label":b("agentMention.suggestionsLabel","Agent mention suggestions"),children:E.length===0?t.jsx("div",{className:"agent-mention-empty",children:b("agentMention.noAgentsFound","No agents found")}):t.jsxs(t.Fragment,{children:[I&&t.jsx("div",{className:"agent-mention-section-header","data-testid":"agent-mention-members-header",children:C?b("agentMention.membersOf","Members of #{{roomName}}",{roomName:C}):b("agentMention.roomMembers","Room members")}),s.map((N,S)=>t.jsxs("button",{type:"button",className:`agent-mention-item${S===m?" agent-mention-item--highlighted":""}`,"data-testid":`agent-mention-item-${N.id}`,onMouseDown:l=>l.preventDefault(),onClick:()=>u(N),role:"option","aria-selected":S===m,children:[t.jsx(kn,{agent:N,size:20}),I&&t.jsx("span",{className:"status-dot agent-mention-member-dot","aria-label":b("agentMention.roomMemberBadge","Room member")}),t.jsx("span",{className:"agent-mention-name",children:N.name}),t.jsx("span",{className:"agent-mention-role",children:N.role})]},N.id)),I&&!M&&v.length>0&&t.jsx("div",{className:"agent-mention-hint","data-testid":"agent-mention-other-hint",children:b("agentMention.typeToSearch","Type to search other agents")}),I&&M&&v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"agent-mention-section-header","data-testid":"agent-mention-others-header",children:b("agentMention.otherAgents","Other agents")}),v.map((N,S)=>{const l=s.length+S;return t.jsxs("button",{type:"button",className:`agent-mention-item${l===m?" agent-mention-item--highlighted":""}`,"data-testid":`agent-mention-item-${N.id}`,onMouseDown:L=>L.preventDefault(),onClick:()=>u(N),role:"option","aria-selected":l===m,children:[t.jsx(kn,{agent:N,size:20}),t.jsx("span",{className:"agent-mention-name",children:N.name}),t.jsx("span",{className:"agent-mention-role",children:N.role})]},N.id)})]})]})}):null}function Xo(i,o){return i+o}function qo({visible:i,position:o,tasks:m,files:g,selectedIndex:u,onSelectTask:h,onSelectFile:k,loading:C}){const{t:b}=_e("app");if(!i)return null;const j=m.length>0,I=g.length>0;return t.jsxs("div",{className:"file-mention-popup",style:{top:o.top,left:o.left},"data-testid":"file-mention-popup",onMouseDown:M=>{M.preventDefault()},children:[C&&t.jsx("div",{className:"file-mention-popup-loading","data-testid":"file-mention-loading",children:t.jsx("span",{className:"spinner"})}),!C&&!j&&!I&&t.jsx("div",{className:"file-mention-popup-empty","data-testid":"file-mention-empty",children:b("fileMention.empty","No tasks or files found")}),!C&&(j||I)&&t.jsxs("div",{className:"file-mention-popup-groups",children:[j&&t.jsxs("div",{className:"file-mention-popup-group",children:[t.jsx("div",{className:"file-mention-popup-group-header",children:b("fileMention.taskHeader","Tasks")}),t.jsx("ul",{className:"file-mention-popup-list",role:"listbox","aria-label":b("fileMention.taskMatches","Task matches"),children:m.map((M,s)=>{const v=s;return t.jsxs("li",{className:`file-mention-popup-item${v===u?" file-mention-popup-item--selected":""}`,onClick:()=>h(M),role:"option","aria-selected":v===u,"data-testid":`task-mention-item-${v}`,children:[t.jsx("span",{className:"file-mention-popup-icon",children:t.jsx(mi,{})}),t.jsxs("div",{className:"file-mention-popup-info",children:[t.jsxs("div",{className:"file-mention-popup-task-row",children:[t.jsx("span",{className:"file-mention-popup-task-id",children:M.id}),t.jsx("span",{className:`file-mention-popup-column-badge file-mention-popup-column-badge--${M.column}`,children:M.column})]}),t.jsx("span",{className:"file-mention-popup-item-path",children:M.title})]})]},M.id)})})]}),I&&t.jsxs("div",{className:"file-mention-popup-group",children:[t.jsx("div",{className:"file-mention-popup-group-header",children:b("fileMention.fileHeader","Files")}),t.jsx("ul",{className:"file-mention-popup-list",role:"listbox","aria-label":b("fileMention.fileMatches","File matches"),children:g.map((M,s)=>{const v=Xo(m.length,s),E=co(M.path);return t.jsxs("li",{className:`file-mention-popup-item${v===u?" file-mention-popup-item--selected":""}`,onClick:()=>k(M),role:"option","aria-selected":v===u,"data-testid":`file-mention-item-${v}`,children:[t.jsx("span",{className:"file-mention-popup-icon",children:t.jsx(lo,{})}),t.jsxs("div",{className:"file-mention-popup-info",children:[t.jsx("span",{className:"file-mention-popup-item-name",children:M.name}),E&&t.jsx("span",{className:"file-mention-popup-item-path",children:E})]})]},M.path)})})]})]})]})}function Go(i,o=[],m){const g=i.trim().replace(/^#/,""),u=(k,C)=>m?m(k,C):C;if(!g)return{ok:!1,error:u("createRoom.nameRequired","Room name is required.")};if(/[A-Z]/.test(g))return{ok:!1,error:u("createRoom.lowercase","Use lowercase letters only.")};const h=g.toLowerCase();return h.length>80?{ok:!1,error:u("createRoom.maxLength","Room names can be at most 80 characters.")}:/^[a-z0-9_-]+$/.test(h)?/^[-_]|[-_]$/.test(h)?{ok:!1,error:u("createRoom.noEdgeChars","Room names cannot start or end with a hyphen or underscore.")}:o.some(k=>k.toLowerCase()===h)?{ok:!1,error:u("createRoom.duplicate","A room with this name already exists.")}:{ok:!0,name:h}:{ok:!1,error:u("createRoom.validChars","Use lowercase letters, numbers, hyphens, or underscores only.")}}function Qo({isOpen:i,onClose:o,onCreate:m,projectId:g,existingRoomNames:u=[]}){const{t:h}=_e("app"),[k,C]=a.useState(""),[b,j]=a.useState([]),[I,M]=a.useState(""),[s,v]=a.useState([]),[E,N]=a.useState(!1),[S,l]=a.useState(null),[L,F]=a.useState(!1),U=a.useRef(null),B=a.useRef(null);a.useEffect(()=>{i&&(B.current=document.activeElement instanceof HTMLElement?document.activeElement:null,N(!0),l(null),uo(void 0,g).then(R=>j(R)).catch(()=>{j([]),l(h("createRoom.failedLoadAgents","Failed to load agents."))}).finally(()=>N(!1)))},[i,g]),a.useEffect(()=>{if(!i){C(""),M(""),v([]),l(null),F(!1);return}const R=window.requestAnimationFrame(()=>U.current?.focus());return()=>window.cancelAnimationFrame(R)},[i]),a.useEffect(()=>{if(!i)return;const R=$=>{$.key==="Escape"&&o()};return document.addEventListener("keydown",R),()=>document.removeEventListener("keydown",R)},[i,o]),a.useEffect(()=>{i||B.current?.focus()},[i]);const T=a.useMemo(()=>Go(k,u,h),[k,u,h]),Q=a.useMemo(()=>{const R=I.trim().toLowerCase();return R?b.filter($=>$.name.toLowerCase().includes(R)):b},[b,I]),se=a.useMemo(()=>b.filter(R=>s.includes(R.id)),[b,s]),Y=T.ok&&s.length>0&&!L&&!E;if(!i)return null;const D=R=>{L||v($=>$.includes(R)?$.filter(ce=>ce!==R):[...$,R])},O=async()=>{if(!T.ok){l(T.error);return}if(s.length===0){l(h("createRoom.selectMember","Select at least one member."));return}l(null),F(!0);try{await m({name:T.name,displayName:`#${T.name}`,memberAgentIds:s}),o()}catch(R){l(R instanceof Error?R.message:h("createRoom.failedCreate","Failed to create room."))}finally{F(!1)}};return t.jsx(mo,{windowKey:"create-room",title:h("createRoom.title","Create room"),ariaLabel:h("createRoom.title","Create room"),onClose:o,modal:!0,hideHeader:!0,dragHandleSelector:".modal-header",className:"floating-window--create-room",defaultSize:{width:640,height:640},minSize:{width:360,height:400},persistGeometryKey:"floating-window:create-room",suspendGeometryPersistenceOnMobile:!0,suspendGeometryPersistenceOnShortViewport:!0,closeOnOutsidePointerDown:!0,layer:"utility",children:t.jsxs("div",{className:"modal create-room-modal",children:[t.jsxs("div",{className:"modal-header",children:[t.jsx("h3",{children:h("createRoom.title","Create room")}),t.jsx("button",{type:"button",className:"modal-close","aria-label":h("actions.close","Close"),onClick:o,children:"×"})]}),t.jsxs("div",{className:"form-group create-room-modal-name-group",children:[t.jsx("label",{htmlFor:"create-room-name",children:h("createRoom.nameLabel","Room name")}),t.jsxs("div",{className:"create-room-modal-name-field",children:[t.jsx("span",{"aria-hidden":"true",className:"create-room-modal-name-hash",children:"#"}),t.jsx("input",{ref:U,id:"create-room-name",className:"input",value:k,disabled:L,onChange:R=>{const $=R.target.value.replace(/^#/,"").replace(/\s+/g,"-").toLowerCase();C($)}})]}),!T.ok&&t.jsx("div",{className:"form-error",children:T.error})]}),t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"create-room-member-search",children:h("createRoom.members","Members")}),t.jsx("input",{id:"create-room-member-search",className:"input",placeholder:h("createRoom.searchAgents","Search agents"),value:I,disabled:L,onChange:R=>M(R.target.value)})]}),se.length>0&&t.jsx("div",{className:"create-room-modal-selected","data-testid":"create-room-selected-chips",children:se.map(R=>t.jsxs("button",{type:"button",className:"btn btn-sm create-room-modal-chip",onClick:()=>D(R.id),disabled:L,children:[R.name," ×"]},R.id))}),t.jsx("div",{className:"create-room-modal-member-list","data-testid":"create-room-member-list",children:E?t.jsx("div",{className:"create-room-modal-empty",children:t.jsx(ho,{label:h("createRoom.loadingAgents","Loading agents...")})}):Q.length===0?t.jsx("div",{className:"create-room-modal-empty",children:b.length===0?h("createRoom.noAgents","No agents in this project yet."):h("createRoom.noMatch","No agents match your search.")}):Q.map(R=>{const $=s.includes(R.id);return t.jsxs("button",{type:"button",className:`create-room-modal-member-row${$?" create-room-modal-member-row--selected":""}`,onClick:()=>D(R.id),disabled:L,children:[t.jsx(kn,{agent:R,size:20}),t.jsx("span",{children:R.name}),t.jsx("span",{className:"create-room-modal-member-role",children:R.role})]},R.id)})}),S&&t.jsx("div",{className:"form-group",children:t.jsx("div",{className:"form-error",children:S})}),t.jsxs("div",{className:"modal-actions",children:[t.jsx("button",{type:"button",className:"btn",onClick:o,disabled:L,children:h("actions.cancel","Cancel")}),t.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void O(),disabled:!Y,children:L?h("createRoom.creating","Creating..."):h("createRoom.create","Create room")})]})]})})}function Yo({cliSessionId:i,tier:o,projectId:m,renderTranscript:g,renderComposer:u,queuedCount:h=0,terminalProps:k}){const{t:C}=_e("app"),b=o==="generic",[j,I]=a.useState(b?"terminal":"transcript");if(b)return t.jsx("div",{className:"cli-chat-surface cli-chat-surface--generic","data-tier":"generic",children:t.jsx(Vs,{sessionId:i,projectId:m,...k})});const M=j==="terminal";return t.jsxs("div",{className:"cli-chat-surface","data-tier":o,"data-view":j,children:[t.jsxs("div",{className:"cli-chat-surface__toolbar",role:"tablist","aria-label":C("cliChat.viewToggleLabel","Chat view"),children:[t.jsxs("button",{type:"button",role:"tab","aria-selected":!M,className:`cli-chat-surface__tab${M?"":" is-active"}`,onClick:()=>I("transcript"),children:[t.jsx(wn,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:C("cliChat.transcriptTab","Transcript")})]}),t.jsxs("button",{type:"button",role:"tab","aria-selected":M,className:`cli-chat-surface__tab${M?" is-active":""}`,onClick:()=>I("terminal"),children:[t.jsx(fo,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:C("cliChat.terminalTab","Terminal")})]})]}),t.jsx("div",{className:"cli-chat-surface__body",children:M?t.jsx(Vs,{sessionId:i,projectId:m,...k}):g()}),!M&&t.jsxs("div",{className:"cli-chat-surface__composer",children:[h>0&&t.jsx("div",{className:"cli-chat-surface__queued",role:"status","aria-live":"polite",children:C("cliChat.queued","{{count}} message queued — will send when the agent is ready",{count:h})}),u()]})]})}const Jo=200,Zo=8,er=8;function Ys(){return new DOMException("The operation was aborted.","AbortError")}function Js(i,o){return o.aborted?Promise.reject(Ys()):new Promise((m,g)=>{const u=()=>g(Ys());o.addEventListener("abort",u,{once:!0}),i.then(h=>{o.removeEventListener("abort",u),m(h)},h=>{o.removeEventListener("abort",u),g(h)})})}function Zs(i,o,m){const g=i.slice(0,o),u=i.slice(o+1),h=u.match(/[\s]|$/),k=h?h.index??u.length:u.length,C=u.slice(k);return`${g}${m}${C}`}function tr(i={}){const{projectId:o,workspace:m="project"}=i,[g,u]=a.useState(!1),[h,k]=a.useState(""),[C,b]=a.useState(-1),[j,I]=a.useState([]),[M,s]=a.useState([]),[v,E]=a.useState(!1),[N,S]=a.useState(0),l=a.useRef(null),L=a.useRef(null),F=[...j.map(D=>({kind:"task",task:D})),...M.map(D=>({kind:"file",file:D}))];a.useEffect(()=>()=>{l.current&&clearTimeout(l.current),L.current?.abort()},[]);const U=a.useCallback((D,O)=>{if(O<0||O>D.length){u(!1);return}const R=$=>/[a-zA-Z0-9/_.-]/.test($);for(let $=O-1;$>=0;$--){if(D[$]==="#"){if($===0){const ae=D.slice($+1,O);b($),k(ae),S(0),u(!0);return}const ce=D[$-1];if(/[\s,.;:!?'"()[\]{}]/.test(ce)){const ae=D.slice($+1,O);b($),k(ae),S(0),u(!0);return}u(!1);return}if(!R(D[$])){u(!1);return}}u(!1)},[]),B=a.useCallback(()=>{L.current?.abort(),u(!1),k(""),b(-1),I([]),s([]),S(0),E(!1)},[]),T=a.useCallback(async D=>{if(!D.trim()){I([]),s([]),E(!1);return}L.current?.abort();const O=new AbortController;L.current=O;try{E(!0);const[R,$]=await Promise.allSettled([Js(go(20,0,o,D),O.signal),Js(po(D,m,o),O.signal)]);if(O.signal.aborted)return;const ce=R.status==="fulfilled"?R.value.slice(0,Zo).map(me=>({id:me.id,title:me.title??"",column:me.column})):[],ae=$.status==="fulfilled"?$.value.files.slice(0,er):[];I(ce),s(ae),S(0)}catch(R){R.name!=="AbortError"&&(I([]),s([]))}finally{O.signal.aborted||E(!1)}},[m,o]);a.useEffect(()=>{if(g)return l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{T(h)},Jo),()=>{l.current&&clearTimeout(l.current)}},[h,g,T]);const Q=a.useCallback((D,O)=>!g||C<0?O:Zs(O,C,`#${D.id}`),[g,C]),se=a.useCallback((D,O)=>!g||C<0?O:Zs(O,C,`#${D.path}`),[g,C]),Y=a.useCallback((D,O)=>{if(!g||F.length===0)return!1;switch(D.key){case"ArrowDown":return D.preventDefault(),S(R=>Math.min(R+1,F.length-1)),!0;case"ArrowUp":return D.preventDefault(),S(R=>Math.max(R-1,0)),!0;case"Enter":case"Tab":return F[N]?(D.preventDefault(),!0):!1;case"Escape":return D.preventDefault(),B(),!0;default:return!1}},[g,F,N,B]);return{mentionActive:g,tasks:j,files:M,combinedItems:F,loading:v,mentionQuery:h,selectedIndex:N,setSelectedIndex:S,detectMention:U,selectTask:Q,selectFile:se,dismissMention:B,handleKeyDown:Y}}const wa=new Map,xn=new Map;function Aa(i){return i??"global"}function ja(i){return`${Dt.DISCOVERED_SKILLS_PREFIX}${Aa(i)}`}function vt(i){return wt(ja(i),{maxAgeMs:Ca})}function nr(i,o){for(const m of xn.get(i)??[])m(o)}async function ar(i){const o=Aa(i),m=wa.get(o);if(m)return m;const g=bo(i).finally(()=>{wa.delete(o)});return wa.set(o,g),g}function sr(i){const[o,m]=a.useState(()=>vt(i)??[]),[g,u]=a.useState(()=>vt(i)===null),h=a.useRef(vt(i)!==null),k=Aa(i);a.useEffect(()=>{const j=vt(i)??[];m(j),u(vt(i)===null),h.current=vt(i)!==null},[i]),a.useEffect(()=>{const j=xn.get(k)??new Set;return j.add(m),xn.set(k,j),()=>{j.delete(m),j.size===0&&xn.delete(k)}},[k]);const C=a.useCallback(async()=>{try{const j=await ar(i);h.current=!0,X(ja(i),j,{maxBytes:5e5}),nr(k,j)}catch{h.current||vo(ja(i))}finally{u(!1)}},[i,k]);a.useEffect(()=>{C()},[C]);const b=a.useCallback(async()=>{u(!0),await C()},[C]);return{skills:o,loading:g,refresh:b}}function ir(i,o){const m=i.reduce((g,u)=>g+(u.content?.length??0),0)+(o?.length??0);return Math.ceil(m/4)}function ei(i){if(!Number.isFinite(i)||i<=0)return"0";if(i<1e3)return String(Math.round(i));const o=i/1e3;return o<10?`~${Number(o.toFixed(1))}k`:`${Math.round(o)}k`}const Ta=640,or=200,rr=200,bt=8;function Nr(i){const o=i.trim();return o?`${o}
12
+
13
+ `:""}function cr(i,o,m,g,u,h,k){const C=Math.max(bt,h-g-bt),b=Math.max(bt,k-u-bt),j=m?i-g:i;return{x:Math.min(Math.max(bt,j),C),y:Math.min(Math.max(bt,o),b)}}const ti="__SKIP__";let xa=!1;function lr(i,o=Ta){return i>o?"auto":"hidden"}function dr(i,o=Ta){return Math.max(40,Math.min(i,o))}function ur(i,o){const m=new Date(i),u=new Date().getTime()-m.getTime(),h=Math.floor(u/1e3),k=Math.floor(h/60),C=Math.floor(k/60),b=Math.floor(C/24);return h<60?o("chat.relativeTimeJustNow","just now"):k<60?o("chat.relativeTimeMinutes","{{count}}m ago",{count:k}):C<24?o("chat.relativeTimeHours","{{count}}h ago",{count:C}):b<7?o("chat.relativeTimeDays","{{count}}d ago",{count:b}):m.toLocaleDateString()}const mr=280,vn=180,bn=500,ni="fusion:chat-sidebar-width",ya="fusion:chat-scope",hr="fusion:chat-draft:";function ai(i,o){return i.slice(o+1).find(m=>m.role==="user")?.content}function si(i,o){return o?`${hr}${i}:${o}`:null}function ii(i){if(!i)return"";try{return localStorage.getItem(i)??""}catch{return""}}const fr=["image/png","image/jpeg","image/gif","image/webp","video/mp4","video/webm","video/quicktime","text/plain","text/markdown","application/json","text/yaml","text/x-toml","text/csv","application/xml"],oi="image/png,image/jpeg,image/gif,image/webp,video/mp4,video/webm,video/quicktime,.txt,.md,.json,.yaml,.yml,.toml,.csv,.xml",ka=$o;function gr(i,o){const m=i.slice(0,o),g=/(^|[\s\n])@([\w-]*)$/.exec(m);if(!g)return null;const u=g[2]??"",h=m.length-u.length-1;return{filter:u,start:h,end:o}}function pr(i){const o=i?.runtimeConfig;if(!o||typeof o!="object")return null;const m=Reflect.get(o,"modelProvider"),g=Reflect.get(o,"modelId");return typeof m!="string"||m.trim().length===0||typeof g!="string"||g.trim().length===0?null:{provider:m,modelId:g}}function ri(i,o,m){if(i?.modelProvider&&i?.modelId)return{provider:i.modelProvider,modelId:i.modelId};const g=pr(o??void 0);return g||(m.provider&&m.modelId?{provider:m.provider,modelId:m.modelId}:null)}function vr({projectId:i,defaultModel:o,defaultKind:m,defaultAgentId:g,defaultThinkingLevel:u,defaultSelectedThinkingLevel:h,onClose:k,onCreate:C}){const{t:b}=_e("app"),[j,I]=a.useState(m??"agent"),{agents:M,loading:s}=di(i),[v,E]=a.useState(g??""),{models:N,favoriteProviders:S,favoriteModels:l,loading:L,refresh:F}=ui(),U=o.provider&&o.modelId?`${o.provider}/${o.modelId}`:"",[B,T]=a.useState(U),[Q,se]=a.useState(h??""),[Y,D]=a.useState(S),[O,R]=a.useState(l);a.useEffect(()=>{D(S)},[S]),a.useEffect(()=>{R(l)},[l]),a.useEffect(()=>{m&&I(m)},[m]),a.useEffect(()=>{g&&E(p=>p||g)},[g]),a.useEffect(()=>{U&&T(p=>p||U)},[U]),a.useEffect(()=>{h&&se(p=>p||h)},[h]);const $=a.useCallback(async p=>{const y=Y,A=y.includes(p)?y.filter(_=>_!==p):[p,...y];D(A);try{await Ks({favoriteProviders:A,favoriteModels:O}),await F()}catch{D(y)}},[Y,O,F]),ce=a.useCallback(async p=>{const y=O,A=y.includes(p)?y.filter(_=>_!==p):[p,...y];R(A);try{await Ks({favoriteProviders:Y,favoriteModels:A}),await F()}catch{R(y)}},[O,Y,F]),ae=B||U,me=p=>{if(p.preventDefault(),j==="agent"){if(!v)return;C({agentId:v});return}if(!ae)return;const y=ae.indexOf("/");if(y<=0)return;const f=ae.slice(0,y),A=ae.slice(y+1);C({agentId:ke,modelProvider:f,modelId:A,thinkingLevel:Q||void 0})},c=j==="agent"?!v:!ae;return t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:k,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:p=>p.stopPropagation(),children:[t.jsx("h3",{children:b("chat.newChatTitle","New Chat")}),t.jsxs("div",{className:"chat-new-dialog-mode-toggle","data-testid":"chat-new-dialog-mode-toggle",children:[t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${j==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{I("agent")},children:b("chat.newChatModeAgent","Agent")}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${j==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{I("model"),E(""),T(p=>p||U)},children:b("chat.newChatModeModel","Model")})]}),t.jsxs("form",{onSubmit:me,children:[j==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:[b("chat.newChatModeAgent","Agent"),s?t.jsx("div",{className:"chat-new-dialog-loading",children:b("chat.loadingAgents","Loading agents...")}):M.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:b("chat.noAgentsAvailable","No agents available")}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:M.map(p=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${v===p.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>E(p.id),"data-testid":`agent-option-${p.id}`,children:[t.jsx(yn,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:p.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:p.role})]},p.id))})]}),j==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:L?t.jsx("div",{className:"chat-new-dialog-loading",children:b("chat.loadingModels","Loading models...")}):t.jsx(li,{models:N,value:B,onChange:T,label:b("chat.newChatModeModel","Model"),placeholder:b("chat.selectModel","Select a model"),favoriteProviders:Y,onToggleFavorite:$,favoriteModels:O,onToggleModelFavorite:ce,showThinkingLevel:!0,thinkingLevel:Q,onThinkingLevelChange:se,defaultThinkingLevel:u??"off"})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:k,children:b("chat.cancel","Cancel")}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:c,children:b("chat.create","Create")})]})]})]})})}function Rr({projectId:i,addToast:o,floating:m=!1,compactLayout:g=!1,onPopOut:u,onMaximize:h,onMinimize:k,onClose:C,chatCommandContext:b,initialComposerDraft:j,initialComposerDraftNonce:I,onSendAsReport:M}){const{t:s}=_e("app");a.useEffect(()=>(Ma({view:"ChatView",trigger:xa?"route-active":"remount",projectId:i,replayAttempted:!1}),xa=!1,()=>{xa=!0,Ma({view:"ChatView",trigger:"route-inactive",projectId:i,replayAttempted:!1})}),[i]);const[v,E]=a.useState(null);a.useEffect(()=>{let e=!1;return E(null),wo(i).then(n=>{e||E(n)}).catch(()=>{e||E(null)}),()=>{e=!0}},[i]);const N=v?.defaultThinkingLevel??"off",S=a.useMemo(()=>v?.chatDefaultKind==="agent"&&v.chatDefaultAgentId?{kind:"agent",agentId:v.chatDefaultAgentId}:v?.chatDefaultKind==="model"&&v.chatDefaultModelProvider&&v.chatDefaultModelId?{kind:"model",modelProvider:v.chatDefaultModelProvider,modelId:v.chatDefaultModelId,thinkingLevel:v.chatDefaultThinkingLevel}:null,[v]),{activeSession:l,sessionsLoading:L,messages:F,messagesLoading:U,isStreaming:B,streamingText:T,streamingThinking:Q,streamingToolCalls:se,selectSession:Y,createSession:D,archiveSession:O,archivedSessions:R,refreshArchivedSessions:$,unarchiveSession:ce,renameSession:ae,pinSession:me,pinnedCount:c,setSessionModel:p,setSessionThinkingLevel:y,deleteSession:f,tags:A=[],selectedTagId:_,setSelectedTagId:J,createTag:ve,renameTag:ee,deleteTag:he,setSessionTags:Ce,sendMessage:ie,editMessageAndResend:Le,stopStreaming:fe,pendingMessages:ze,clearPendingMessage:Cn,loadMoreMessages:Ea,hasMoreMessages:Sn,searchQuery:pi,setSearchQuery:vi,filteredSessions:Be,agentsMap:Mn}=xo(i,o),[bi,Nn]=a.useState(!1),Oe=!0,[P,Qe]=a.useState(()=>{try{if(localStorage.getItem(ya)==="rooms"&&Oe)return"rooms"}catch{}return"direct"}),x=Ko(i,o),{isUnread:Da,markRead:de}=Vo(i),[q,oe]=a.useState(()=>{const e=si(P,P==="rooms"?x.activeRoom?.id:l?.id);return ii(e)}),[G,Se]=a.useState(null),[Ye,wi]=a.useState(!1),Rn=a.useRef(null),Ia=(e,n,r,d)=>{typeof window>"u"||Se({sessionId:e,anchorX:n,anchorY:r,anchorRight:d?.anchorRight??!1,x:n,y:r})};a.useLayoutEffect(()=>{if(!G||!Rn.current||typeof window>"u")return;const e=Rn.current,n=e.getBoundingClientRect(),r=n.width||e.offsetWidth||rr,d=n.height||e.offsetHeight,w=cr(G.anchorX,G.anchorY,G.anchorRight,r,d,window.innerWidth,window.innerHeight);(w.x!==G.x||w.y!==G.y)&&Se({...G,...w})},[G]);const[Lt,Pt]=a.useState(null),[jn,An]=a.useState(""),[La,Ft]=a.useState(null),[Pa,$t]=a.useState(null),[Tn,Fa]=a.useState(""),[En,xt]=a.useState(null),[Dn,$a]=a.useState(""),[_a,_t]=a.useState(null),[yt,He]=a.useState(!0),[Je,In]=a.useState(mr),[xi,zt]=a.useState(!1),{agentsMap:za}=di(i),be=a.useMemo(()=>Mn.size>0?Mn:za,[za,Mn]),{models:Ln,favoriteProviders:yi,favoriteModels:ki,defaultProvider:Ba,defaultModelId:Oa}=ui(),Bt=a.useMemo(()=>({provider:Ba,modelId:Oa}),[Oa,Ba]),Ci=a.useMemo(()=>S?.kind==="model"?{provider:S.modelProvider,modelId:S.modelId}:Bt,[S,Bt]),{skills:Pn,loading:Si}=sr(i),[Ze,Ue]=a.useState(!1),[kt,Ct]=a.useState(""),[et,Ke]=a.useState(0),[tt,nt]=a.useState(""),[Me,at]=a.useState(!1),[Ot,Ht]=a.useState(0),[Fn,st]=a.useState(-1),[ge,Ut]=a.useState([]),[Ha,it]=a.useState(!1),[Ua,Kt]=a.useState(!1),[ot,Ka]=a.useState({}),[Vt,Ne]=a.useState(!1),[Wt,St]=a.useState(!1),{pushNav:Va}=yo(),[,Xt]=a.useState(!1),[Mi,Ni]=a.useState({top:0,left:0}),V=tr({projectId:i}),$n=a.useCallback(e=>{if(!e||!V.mentionActive)return;const n=e.getBoundingClientRect();Ni({top:n.top-260,left:n.left+8})},[V.mentionActive]),Wa=a.useRef(null),Xa=a.useRef(null),qa=a.useRef(null),Ga=a.useRef(null),le=a.useRef(!1),qt=a.useRef(null),Qa=a.useRef(null),Pe=a.useRef(null),Gt=a.useRef(0),_n=a.useRef(null),Mt=a.useRef(null),Re=a.useRef(null),re=a.useRef(null),zn=a.useRef(null),rt=a.useRef(null),[Bn,Ri]=a.useState(()=>new Set),Qt=a.useRef(!1),je=a.useRef(null),Ae=a.useRef(null),Z=a.useRef(null),Yt=a.useRef(null),Ya=a.useRef(void 0),On=a.useRef(!1),Jt=a.useRef(null),Ja=a.useRef([]),ct=a.useRef(0),Nt=a.useRef(new Map),Hn=a.useRef(!1),Zt=ko(),Ve=Zt==="mobile",Un=Zt==="tablet",Za=a.useRef(null),[ji,es]=a.useState(!1);a.useLayoutEffect(()=>{if(!m){es(!1);return}const e=Za.current;if(!e||typeof ResizeObserver>"u")return;const n=()=>{es(e.getBoundingClientRect().width<=768)};n();const r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[m]);const H=Ve||ji||g;a.useEffect(()=>{l?.id&&de("direct",l.id,l.lastMessageAt??l.updatedAt)},[l?.id,l?.lastMessageAt,l?.updatedAt,de]),a.useEffect(()=>{x.activeRoom?.id&&de("room",x.activeRoom.id,x.activeRoom.updatedAt)},[x.activeRoom?.id,x.activeRoom?.updatedAt,de]),a.useEffect(()=>{if(!l?.id||F.length===0)return;const e=F[F.length-1];de("direct",l.id,e?.createdAt??l.lastMessageAt??l.updatedAt)},[l?.id,l?.lastMessageAt,l?.updatedAt,de,F]),a.useEffect(()=>{if(!x.activeRoom?.id||x.messages.length===0)return;const e=x.messages[x.messages.length-1];de("room",x.activeRoom.id,e?.createdAt??x.activeRoom.updatedAt)},[de,x.activeRoom?.id,x.activeRoom?.updatedAt,x.messages]),a.useEffect(()=>{try{const e=localStorage.getItem(ni);if(!e)return;const n=Number.parseInt(e,10);if(Number.isNaN(n))return;const r=Math.max(vn,Math.min(bn,n));In(r)}catch{}},[]),a.useEffect(()=>{try{const e=localStorage.getItem(ya);if(e==="direct"){Qe("direct");return}e==="rooms"&&Oe&&Qe("rooms")}catch{}},[Oe]),a.useEffect(()=>{try{localStorage.setItem(ya,P)}catch{}},[Oe,P]);const ue=si(P,P==="rooms"?x.activeRoom?.id:l?.id),Kn=a.useRef(ue),Vn=a.useRef(!1);a.useEffect(()=>{if(ue!==Kn.current){if(Kn.current=ue,Vn.current){Vn.current=!1;return}oe(ii(ue))}},[ue]),a.useEffect(()=>{if(!(!ue||Kn.current!==ue))try{if(q){localStorage.setItem(ue,q);return}localStorage.removeItem(ue)}catch{}},[ue,q]);const te=P==="rooms"&&!!x.activeRoom,{keyboardOverlap:ts,keyboardOpen:en}=Co({enabled:(H||Un)&&(!!l||te),allowNonMobileViewport:Un}),Rt=Un&&en,tn=a.useMemo(()=>{const e=kt.trim().toLowerCase();return(e?Pn.filter(r=>r.name.toLowerCase().includes(e)):Pn).slice(0,10)},[Pn,kt]),Wn=a.useMemo(()=>b?So(kt,Us):[],[b,kt]),we=a.useMemo(()=>{const e=Wn.map(r=>({kind:"command",command:r,disabled:!b?.agentRunning})),n=tn.map(r=>({kind:"skill",skill:r}));return[...e,...n]},[Wn,tn,b]),lt=a.useMemo(()=>Array.from(be.values()),[be]),Te=a.useMemo(()=>P!=="rooms"||!x.activeRoom?null:{roomId:x.activeRoom.id,roomName:x.activeRoom.name,memberIds:new Set(x.activeRoomMembers.map(e=>e.agentId))},[Oe,P,x.activeRoom,x.activeRoomMembers]),We=a.useMemo(()=>{const e=lt.filter(d=>gi(d.name,tt));if(!Te)return e;const n=e.filter(d=>Te.memberIds.has(d.id));if(tt.trim().length===0)return n;const r=e.filter(d=>!Te.memberIds.has(d.id));return[...n,...r]},[lt,tt,Te]),Xn=a.useMemo(()=>{const e=new Map;for(const n of lt)e.set(n.name.toLowerCase(),n);return e},[lt]),Ai=a.useMemo(()=>tn.map(e=>e.id).join("\0"),[tn]);a.useEffect(()=>{Ke(0)},[Ai]),a.useEffect(()=>{Ht(0)},[tt,Me]),a.useEffect(()=>()=>{Re.current!==null&&window.clearTimeout(Re.current)},[]),a.useEffect(()=>{const e=Xa.current;if(!e||!Sn||U)return;const n=new IntersectionObserver(r=>{r[0].isIntersecting&&Ea()},{threshold:.1});return n.observe(e),()=>n.disconnect()},[Sn,U,Ea]);const dt=a.useCallback(()=>te?x.activeRoom?.id??null:l?.id??null,[te,x.activeRoom?.id,l?.id]),ns=a.useCallback((e,n)=>typeof CSS<"u"&&typeof CSS.escape=="function"?e.querySelector(`.chat-message[data-message-id="${CSS.escape(n)}"]`):e.querySelector(`.chat-message[data-message-id="${n.replace(/"/g,'\\"')}"]`),[]),as=a.useCallback(()=>{const e=re.current;if(!e)return;const n=e.getBoundingClientRect().top,r=new Set;e.querySelectorAll(".chat-message--assistant:not(.chat-message--failure)[data-message-id]").forEach(d=>{const w=d.getAttribute("data-message-id");w&&d.getBoundingClientRect().top<n&&r.add(w)}),Ri(d=>d.size===r.size&&Array.from(d).every(w=>r.has(w))?d:r)},[]),nn=a.useCallback(()=>{!re.current||rt.current!==null||(rt.current=window.requestAnimationFrame(()=>{rt.current=null,as()}))},[as]),an=a.useCallback(()=>{const e=re.current,n=dt();if(!e||!n)return;const r=e.scrollTop,d=e.querySelectorAll(".chat-message[data-message-id]"),w=Array.from(d).find(K=>K.offsetTop+K.offsetHeight>=r)??d[0]??null,z=w?.getAttribute("data-message-id")??null,W=w?w.offsetTop-r:0;Mt.current={threadId:n,scrollTop:r,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight,anchorMessageId:z,anchorOffset:W,wasPinnedBefore:!le.current,capturedAtMs:typeof performance<"u"?performance.now():Date.now()}},[dt]),ss=a.useCallback(()=>{const e=re.current;if(!e)return;const r=e.scrollTop+e.clientHeight>=e.scrollHeight-50;Kt(!r),le.current=!r,an(),nn()},[an,nn]),Ee=a.useCallback((e,n)=>{if(!e.isConnected||!n?.force&&le.current)return;let r=0,d=0,w=-1;const z=6,W=()=>{if(e.isConnected&&!(!n?.force&&le.current)){if(e.scrollTop=e.scrollHeight,e.scrollHeight===w?d+=1:(d=0,w=e.scrollHeight),r+=1,r>=z||d>=2){Kt(!1),le.current=!1;return}window.requestAnimationFrame(W)}};W()},[]),ut=te?x.messages:F;a.useLayoutEffect(()=>(nn(),()=>{rt.current!==null&&(window.cancelAnimationFrame(rt.current),rt.current=null)}),[ut,nn]),a.useLayoutEffect(()=>{const e=re.current,n=dt(),r=Mt.current;if(!e||!n||!r||r.threadId!==n||r.wasPinnedBefore)return;const d=(typeof performance<"u"?performance.now():Date.now())-r.capturedAtMs,w=e.scrollHeight>e.clientHeight,z=d>3e3,W=r.scrollTop<=0&&r.anchorOffset<=0&&w;if(!le.current||z||W){Mt.current=null;return}let K=r.scrollTop;if(r.anchorMessageId){const pe=ns(e,r.anchorMessageId);pe?K=pe.offsetTop-r.anchorOffset:K=r.scrollTop+(e.scrollHeight-r.scrollHeight)}else K=r.scrollTop+(e.scrollHeight-r.scrollHeight);e.scrollTop=Math.max(0,K),le.current=!0,Kt(!0),Mt.current=null},[ut,dt,ns]);const qn=a.useCallback(e=>{},[ut.length,te]),xe=a.useCallback(e=>{qn(e);const n=re.current;n&&(Mt.current=null,le.current=!1,Ee(n))},[Ee,qn]);a.useLayoutEffect(()=>{Pe.current!==null&&(window.clearTimeout(Pe.current),Pe.current=null);const e=te?x.activeRoom?.id??null:l?.id??null;if(!e){qt.current=null;return}const n={threadId:e,loaded:te?!x.messagesLoading:!U,hasMessages:te?x.messages.length>0:F.length>0},r=qt.current,d=r?.threadId!==e,w=r?.threadId===e&&!r.loaded&&n.loaded,z=r?.threadId===e&&!r.hasMessages&&n.hasMessages;if(!(r===null||d||w||z))return;const K=re.current;if(K)return qn(d?"thread-change":w?"finished-loading":z?"first-messages":"mount"),Ee(K,{force:!0}),te||(Pe.current=window.setTimeout(()=>{if(Pe.current=null,le.current)return;const pe=re.current;pe&&Ee(pe)},250)),qt.current=n,()=>{Pe.current!==null&&(window.clearTimeout(Pe.current),Pe.current=null)}},[te,x.activeRoom?.id,x.messages.length,x.messagesLoading,l?.id,F.length,U,Ee]),a.useEffect(()=>{!B||le.current||xe("streaming")},[B,T,Q,xe]),a.useEffect(()=>{const e=dt();if(!e){Gt.current=0,_n.current=null;return}if(_n.current!==e){_n.current=e,Gt.current=ut.length;return}const n=Gt.current,r=ut.length,d=r>n,w=!le.current;Gt.current=r,d&&w&&xe("new-message")},[ut,dt,xe]),a.useEffect(()=>{ts<=0||!re.current||xe("keyboard")},[ts,xe]),Mo(Ve&&en),a.useLayoutEffect(()=>{if(!Ve||!l&&!te||typeof window>"u")return;const e=zn.current,n=window.visualViewport;if(!e||!n)return;const r=w=>{if(!(w instanceof HTMLElement))return!1;if(w.tagName==="TEXTAREA")return!0;if(w.tagName!=="INPUT")return!1;const z=w.type.toLowerCase();return["","text","search","email","url","tel","password","number"].includes(z)},d=()=>{if(Qt.current){e.classList.remove("chat-thread--keyboard-active"),e.style.setProperty("--chat-keyboard-accessory-clearance","0px"),e.style.transform="",e.style.willChange="";return}const w=Math.max(0,window.innerHeight-n.offsetTop-n.height),z=n.offsetTop||0;e.style.setProperty("--vv-height",`${n.height}px`),e.style.setProperty("--vv-offset-top",`${z}px`),e.style.setProperty("--keyboard-overlap",`${w}px`);const W=(w>0||z>0)&&r(document.activeElement);e.classList.toggle("chat-thread--keyboard-active",W),e.style.setProperty("--chat-keyboard-accessory-clearance",W&&pa()?"calc(var(--space-2xl) + var(--space-md))":"0px"),W&&z>0?(e.style.transform=`translateY(${z}px)`,e.style.willChange="transform"):(e.style.transform="",e.style.willChange="")};return d(),n.addEventListener("resize",d),n.addEventListener("scroll",d),document.addEventListener("focusin",d),document.addEventListener("focusout",d),window.addEventListener("pageshow",d),document.addEventListener("visibilitychange",d),()=>{n.removeEventListener("resize",d),n.removeEventListener("scroll",d),document.removeEventListener("focusin",d),document.removeEventListener("focusout",d),window.removeEventListener("pageshow",d),document.removeEventListener("visibilitychange",d),e.classList.remove("chat-thread--keyboard-active"),e.style.setProperty("--chat-keyboard-accessory-clearance","0px"),e.style.transform="",e.style.willChange=""}},[l,Ve,te]),a.useEffect(()=>{const e=()=>Se(null);if(G)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[G]),a.useEffect(()=>{if(!Ve||!en)return;const e=n=>{n.target?.closest(".chat-messages")||n.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>{document.removeEventListener("touchmove",e)}},[Ve,en]),a.useEffect(()=>{const e=Qa.current;if(Qa.current=P,P==="rooms"&&!x.activeRoom){qt.current=null;return}if(!(P==="direct"&&(e===null||e==="rooms"))&&!(P==="rooms"&&(e===null||e==="direct")))return;const d=re.current;d&&(Ee(d,{force:!0}),le.current=!1,Kt(!1))},[P,x.activeRoom,Ee]),a.useEffect(()=>{if(!l&&!te||te&&!H)return;const e=()=>{const r=!le.current;an(),r&&H&&re.current&&xe("visibility-restore")},n=()=>{document.visibilityState==="visible"&&e()};return document.addEventListener("visibilitychange",n),window.addEventListener("pageshow",e),()=>{document.removeEventListener("visibilitychange",n),window.removeEventListener("pageshow",e)}},[H,Ve,l,te,an,xe]),a.useEffect(()=>{if(te||typeof ResizeObserver>"u")return;const e=re.current;if(!e)return;const n=new ResizeObserver(()=>{le.current||Ee(e)});return n.observe(e),()=>{n.disconnect()}},[te,Ee,l?.id,P]),a.useEffect(()=>{Ja.current=ge},[ge]),a.useEffect(()=>()=>{for(const e of Ja.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);for(const e of Nt.current.values())window.clearTimeout(e);Nt.current.clear()},[]);const mt=a.useCallback(e=>{if(!e||e.length===0)return;const n=[];for(const r of Array.from(e)){if(!fr.includes(r.type))continue;const d=r.type.startsWith("image/");n.push({file:r,previewUrl:d?URL.createObjectURL(r):""})}n.length>0&&Ut(r=>[...r,...n])},[]),is=a.useCallback(e=>{Ut(n=>{const r=n[e];return r?.previewUrl&&URL.revokeObjectURL(r.previewUrl),n.filter((d,w)=>w!==e)})},[]),os=a.useCallback(e=>{mt(e.clipboardData?.files)},[mt]),ht=a.useCallback(async e=>{try{return await D(e),Nn(!1),H&&He(!1),!0}catch{return o(s("chat.failedToCreateSession","Failed to create chat session"),"error"),!1}},[D,o,H,s]),sn=a.useCallback(()=>{if(v?.chatNewSessionMode==="always-default"&&S){if(S.kind==="agent"){ht({agentId:S.agentId});return}ht({agentId:ke,modelProvider:S.modelProvider,modelId:S.modelId,thinkingLevel:S.thinkingLevel});return}Nn(!0)},[S,v?.chatNewSessionMode,ht]),ne=a.useCallback(e=>{const n=e??Z.current;if(!n)return;const r=Zt==="tablet"?or:Ta;n.style.height="auto",n.style.height=`${dr(n.scrollHeight,r)}px`,n.style.overflowY=lr(n.scrollHeight,r)},[Zt]),Ti=Is({textareaRef:Z,value:q,onChange:oe,onResize:()=>ne(Z.current),projectId:i}),Ei=Is({textareaRef:Yt,value:q,onChange:oe,onResize:()=>ne(Yt.current),projectId:i}),Di=a.useCallback(e=>{Z.current=e,e&&ne(e)},[ne]),Ii=a.useCallback(e=>{Yt.current=e,e&&ne(e)},[ne]);a.useLayoutEffect(()=>{ne(P==="rooms"?Yt.current:Z.current),On.current&&(On.current=!1,Z.current?.focus())},[P,q,l?.id,x.activeRoom?.id,ne]),a.useEffect(()=>{if(I===void 0||I===Ya.current||!j?.trim())return;Ya.current=I;const e=n=>{n&&(Vn.current=!0),Qe("direct"),On.current=!0,oe(j)};if(!B&&v?.chatNewSessionMode==="always-default"&&S){const n=S.kind==="agent"?{agentId:S.agentId}:{agentId:ke,modelProvider:S.modelProvider,modelId:S.modelId,thinkingLevel:S.thinkingLevel};ht(n).then(r=>e(r||P!=="direct"));return}e(P!=="direct")},[S,P,v?.chatNewSessionMode,ht,j,I,B,ne]);const ft=a.useCallback(()=>{if(oe(""),ue)try{localStorage.removeItem(ue)}catch{}Ue(!1),Ct(""),at(!1),nt(""),st(-1),Ut(e=>{for(const n of e)n.previewUrl&&URL.revokeObjectURL(n.previewUrl);return[]})},[ue]),Xe=a.useCallback(e=>{Ut(n=>{const r=n.filter(d=>e.has(d.file));for(const d of r)d.previewUrl&&URL.revokeObjectURL(d.previewUrl);return n.filter(d=>!e.has(d.file))})},[]),Gn=a.useCallback(()=>{const e=q.trim(),n=ge.map(d=>d.file);if(!e&&n.length===0||!l)return;if(b){const d=No(e,Us);if(d){if(!b.agentRunning){o(s("chat.commandNoRunningAgent","No running agent to steer"),"warning");return}if(n.length>0){o(s("chat.commandNoAttachments","Attachments aren't supported with commands — remove them before sending"),"warning");return}ft(),d.command.run({taskId:b.taskId,projectId:b.projectId,remainder:d.remainder}).then(()=>{o(s("chat.commandSteerSuccess","Sent to the running agent"),"success")}).catch(w=>{const z=w instanceof Error&&w.message.trim()?w.message:s("chat.commandSteerFailed","Failed to send to the running agent");o(z,"error")});return}}if(e==="/clear"||e==="/new"){if(n.length>0){o(s("chat.clearNoAttachments","Remove the attachments before running /clear or /new — they would be discarded unsent"),"warning");return}if(l.agentId.startsWith(Ro)){ft(),o(s("chat.newNotAllowedForTaskChat","This chat is tied to a task — /new and /clear can't clear it"),"warning");return}ft(),Cn(),fe(),D({agentId:l.agentId,modelProvider:l.modelProvider??void 0,modelId:l.modelId??void 0,thinkingLevel:l.thinkingLevel??void 0}).catch(()=>{o(s("chat.failedToClearConversation","Failed to clear conversation"),"error")});return}if(B&&n.length>0){o(s("chat.attachmentsNotQueued","Attachments can't be queued while a reply is streaming — wait for it to finish"),"warning");return}const r=new Set(n);oe("");try{ie(e,n,{onAccepted:()=>Xe(r),onDelivered:()=>Xe(r),onFailed:()=>{oe(d=>d||e)}})}catch{oe(e)}},[q,ge,l,ft,fe,Cn,D,o,ie,b,B,Xe,s]),Qn=a.useCallback(async()=>{const e=q.trim(),n=ge.map(r=>r.file);if(!(!e&&n.length===0)){if(P==="rooms"){if(!x.activeRoom)return;if(e==="/clear"||e==="/new"){if(n.length>0){o(s("chat.clearNoAttachments","Remove the attachments before running /clear or /new — they would be discarded unsent"),"warning");return}ft();try{await x.clearRoom(x.activeRoom.id)}catch{o(s("chat.failedToClearRoomConversation","Failed to clear room conversation"),"error")}return}if(Hn.current)return;Hn.current=!0;const r=q,d=new Set(n);oe("");try{await x.sendRoomMessage(e,{files:n,onDelivered:()=>Xe(d)}),Xe(d)}catch(w){if(w instanceof hi){Xe(d);const W=w.message.trim()?w.message:s("chat.messageSentButReplyFailed","Message sent, but assistant reply failed");o(s("chat.messageSentButReplyFailedDetail","Message sent, but assistant reply failed: {{detail}}",{detail:W}),"error");return}oe(r);const z=w instanceof Error&&w.message.trim()?w.message:s("chat.failedToSendRoomMessage","Failed to send room message");o(z,"error")}finally{Hn.current=!1}return}Gn()}},[q,ge,Oe,P,x,x.clearRoom,ft,o,Gn,Xe]),on=a.useCallback(async e=>{if(P==="rooms"){if(!x.activeRoom)return;try{await x.sendRoomMessage(e)}catch(n){const r=n instanceof Error&&n.message.trim()?n.message:s("chat.failedToSendRoomMessage","Failed to send room message");o(r,"error")}return}l&&ie(e)},[l,o,Oe,P,x,ie,s]),Yn=a.useCallback(e=>{oe(n=>{const r=ka(n);if(!r)return n;const d=`/skill:${e.name} `,w=n.slice(0,r.start)+d+n.slice(r.end);return window.requestAnimationFrame(()=>{Z.current&&(ne(Z.current),Z.current.focus())}),w}),Ue(!1),Ct(""),Ke(0)},[ne]),Jn=a.useCallback((e,n)=>{if(n){o(s("chat.commandNoRunningAgent","No running agent to steer"),"warning");return}oe(r=>{const d=ka(r);if(!d)return r;const w=`${e.trigger} `,z=r.slice(0,d.start)+w+r.slice(d.end);return window.requestAnimationFrame(()=>{Z.current&&(ne(Z.current),Z.current.focus())}),z}),Ue(!1),Ct(""),Ke(0)},[ne,o,s]),rn=a.useCallback(e=>{const n=Z.current;if(!n||Fn<0)return;const r=n.selectionStart??ct.current,d=n.selectionEnd??r,w=Math.max(r,d),z=Math.min(Fn,w),K=`${`@${e.name.replace(/\s+/g,"_")}`} `,pe=q.slice(0,z)+K+q.slice(w),gt=z+K.length;oe(pe),at(!1),nt(""),Ht(0),st(-1),window.requestAnimationFrame(()=>{Z.current&&(ne(Z.current),Z.current.focus(),Z.current.setSelectionRange(gt,gt))})},[Fn,q,ne]),jt=a.useCallback((e,n)=>{const d=Z.current?.selectionStart??ct.current,w=q.lastIndexOf("#",d),z=w>=0?w+n.length:e.length;oe(e),V.dismissMention(),Xt(!1),window.requestAnimationFrame(()=>{Z.current&&(ne(Z.current),Z.current.focus(),Z.current.setSelectionRange(z,z))})},[V,q,ne]),rs=a.useCallback(e=>{if(ct.current=e.currentTarget.selectionStart??ct.current,V.mentionActive&&V.combinedItems.length>0){if(V.handleKeyDown(e,q),e.key==="Enter"||e.key==="Tab"){const n=V.combinedItems[V.selectedIndex];n?.kind==="task"?jt(V.selectTask(n.task,q),`#${n.task.id}`):n?.kind==="file"&&jt(V.selectFile(n.file,q),`#${n.file.path}`)}return}if(Me&&e.key==="ArrowDown"){e.preventDefault(),We.length>0&&Ht(n=>(n+1)%We.length);return}if(Me&&e.key==="ArrowUp"){e.preventDefault(),We.length>0&&Ht(n=>n===0?We.length-1:n-1);return}if(Me&&e.key==="Enter"){e.preventDefault();const n=We[Ot]??We[0];n&&rn(n);return}if(Me&&e.key==="Escape"){e.preventDefault(),at(!1),nt(""),st(-1);return}if(Ze&&e.key==="ArrowDown"){e.preventDefault(),we.length>0&&Ke(n=>(n+1)%we.length);return}if(Ze&&e.key==="ArrowUp"){e.preventDefault(),we.length>0&&Ke(n=>n===0?we.length-1:n-1);return}if(Ze&&(e.key==="Enter"||e.key==="Tab")&&we.length>0){e.preventDefault();const n=we[et]??we[0];n?.kind==="skill"?Yn(n.skill):n?.kind==="command"&&Jn(n.command,n.disabled);return}if(Ze&&e.key==="Escape"){e.preventDefault(),Ue(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Qn())},[Me,We,Ot,rn,Ze,we,et,Yn,Jn,Qn,V,jt,q]),cn=a.useCallback((e,n)=>{const r=gr(e,n);if(r){at(!0),nt(r.filter),st(r.start);return}at(!1),nt(""),st(-1)},[]),cs=a.useCallback(e=>{const n=e.target,r=n.value,d=n.selectionStart??r.length;ne(n),ct.current=d,oe(r);const w=ka(r);w?(Ue(!0),Ct(w.filter)):(Ue(!1),Ct("")),cn(r,d),V.detectMention(r,d),Xt(V.mentionActive),V.mentionActive&&$n(n)},[cn,ne]),ln=a.useCallback(e=>{const n=e.currentTarget,r=n.selectionStart??n.value.length;ct.current=r,cn(n.value,r),V.detectMention(n.value,r),Xt(V.mentionActive),V.mentionActive&&$n(n)},[cn,V,$n]),ls=a.useCallback(e=>{e.key!=="Escape"&&ln(e)},[ln]),ds=a.useCallback(()=>{typeof window<"u"&&window.innerWidth<=768&&(Qt.current=!0,je.current!==null&&window.clearTimeout(je.current),je.current=window.setTimeout(()=>{Qt.current=!1,je.current=null},450),(window.scrollY!==0||window.scrollX!==0)&&window.scrollTo(0,0),Ae.current!==null&&window.clearTimeout(Ae.current),Ae.current=window.setTimeout(()=>{Ae.current=null,document.activeElement?.tagName!=="TEXTAREA"&&(window.scrollY!==0||window.scrollX!==0)&&window.scrollTo(0,0)},350)),Re.current!==null&&window.clearTimeout(Re.current),Re.current=window.setTimeout(()=>{Ue(!1),at(!1),nt(""),st(-1),Xt(!1),V.dismissMention(),Re.current=null},120)},[V]),us=a.useCallback(()=>{Qt.current=!1,je.current!==null&&(window.clearTimeout(je.current),je.current=null),Re.current!==null&&(window.clearTimeout(Re.current),Re.current=null),Ae.current!==null&&(window.clearTimeout(Ae.current),Ae.current=null)},[]);a.useEffect(()=>()=>{je.current!==null&&window.clearTimeout(je.current),Ae.current!==null&&window.clearTimeout(Ae.current)},[]);const ms=a.useCallback(async e=>{Se(null);try{await O(e),o(s("chat.conversationArchived","Conversation archived"),"success")}catch{o(s("chat.failedToArchiveConversation","Failed to archive conversation"),"error")}},[O,o]),Li=a.useCallback(async e=>{try{await ce(e),o(s("chat.conversationRestored","Conversation restored"),"success")}catch{o(s("chat.failedToRestoreConversation","Failed to restore conversation"),"error")}},[ce,o,s]),hs=a.useCallback(e=>{const n=Be.find(r=>r.id===e)??(l?.id===e?l:null);Se(null),Ne(!1),An(n?.title??""),Pt({sessionId:e,title:n?.title??""})},[l,Be]),fs=a.useCallback(async()=>{if(Lt)try{await ae(Lt.sessionId,jn),Pt(null),An(""),o(s("chat.conversationRenamed","Conversation renamed"),"success")}catch{}},[o,Lt,ae,jn,s]),gs=a.useCallback(async(e,n)=>{Se(null),Ne(!1);try{await me(e,n),o(n?s("chat.conversationPinned","Conversation pinned"):s("chat.conversationUnpinned","Conversation unpinned"),"success")}catch{}},[o,me,s]),Pi=a.useCallback(async e=>{Ft(null),Se(null);try{await f(e),o(s("chat.conversationDeleted","Conversation deleted"),"success")}catch{o(s("chat.failedToDeleteConversation","Failed to delete conversation"),"error")}},[f,o]),At=a.useCallback(e=>{try{localStorage.setItem(ni,String(e))}catch{}},[]),Fi=a.useCallback(e=>{if(H||Rt)return;e.preventDefault(),e.stopPropagation();const n=e.currentTarget;typeof n.setPointerCapture=="function"&&n.setPointerCapture(e.pointerId);const r=e.clientX,d=Je;let w=d;document.body.style.userSelect="none";const z=K=>{const pe=K.clientX-r,gt=Math.max(vn,Math.min(bn,d+pe));w=gt,In(gt),At(gt)},W=K=>{typeof n.releasePointerCapture=="function"&&n.releasePointerCapture(K.pointerId),document.body.style.userSelect="",document.removeEventListener("pointermove",z),document.removeEventListener("pointerup",W),At(w)};document.addEventListener("pointermove",z),document.addEventListener("pointerup",W)},[H,At,Je,Rt]),$i=a.useCallback(e=>{if(H||Rt||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;e.preventDefault();const n=e.shiftKey?50:10,r=e.key==="ArrowLeft"?-n:n,d=Math.max(vn,Math.min(bn,Je+r));In(d),At(d)},[H,At,Je,Rt]),ps=a.useCallback(e=>{const n=Be.find(r=>r.id===e);de("direct",e,n?.lastMessageAt??n?.updatedAt),Y(e),Ne(!1),H&&He(!1)},[Be,H,de,Y]),Zn=a.useCallback(()=>{Y(""),He(!0),Ne(!1)},[Y]),ea=a.useCallback(()=>{x.selectRoom(null),He(!0),Ne(!1)},[x]),_i=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(wn,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:s("chat.startNewConversation","Start a new conversation")}),t.jsxs("button",{className:"btn btn-primary",onClick:sn,children:[t.jsx(pt,{size:16}),s("chat.newChat","New Chat")]})]}),De=ri(l,l?.agentId?be.get(l.agentId)??null:null,Bt),ta=a.useMemo(()=>{if(!De?.provider||!De.modelId)return null;const e=Ln.find(n=>n.provider===De.provider&&n.id===De.modelId);return e?.contextWindow?e.contextWindow:null},[De?.modelId,De?.provider,Ln]),zi=a.useMemo(()=>ir(F,B?T:void 0),[B,F,T]),Fe=Ls(De?.provider,De?.modelId),qe=De?.provider??null,na=!!(l||B||F.length>0),dn=H&&!yt&&(P==="rooms"?te:na),un=H?dn:P==="rooms"?te:!!l,vs=a.useRef(un);a.useEffect(()=>{const e=vs.current;vs.current=un,H&&(e||!un||Va({type:"view",revert:P==="rooms"?ea:Zn}))},[P,Zn,ea,un,H,Va]);const bs=l?.agentId===ke?Fe??"Fusion":l?.title||be.get(l?.agentId??"")?.name||l?.agentId||"Chat",Bi=l?.title||s("chat.untitledSession","Untitled"),Oi=!!(Fe&&Fe!==bs),Hi=!H&&na&&ta!==null,ws=ei(zi),mn=ta!==null?ei(ta):null,aa=mn?s("chat.contextWindowAria","Estimated {{used}} of {{total}} context tokens",{used:ws,total:mn}):null,Ui=dn&&P==="direct"&&!!l,xs=dn&&P==="direct",ys=dn&&P==="rooms",sa=be.get(l?.agentId??"")?.name||(l?.agentId===ke?Fe??"Fusion":l?.agentId?.slice(0,30)??"Fusion"),ia=!1,oa=l?.agentId===ke,Ki=e=>e.length>50?`${e.slice(0,50)}…`:e;a.useEffect(()=>{if(!Vt)return;const e=n=>{qa.current?.contains(n.target)||Ne(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[Vt]),a.useEffect(()=>{if(!Wt)return;const e=r=>{Ga.current?.contains(r.target)||St(!1)},n=r=>{r.key==="Escape"&&St(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",n)}},[Wt]),a.useEffect(()=>{(!H||P!=="direct"||yt)&&Ne(!1)},[H,P,yt]),a.useEffect(()=>{St(!1)},[x.activeRoom?.id]);const ks=a.useCallback((e,n)=>{const r=Nt.current.get(e);r&&window.clearTimeout(r),Ka(w=>({...w,[e]:n}));const d=window.setTimeout(()=>{Ka(w=>{const{[e]:z,...W}=w;return W}),Nt.current.delete(e)},2e3);Nt.current.set(e,d)},[]),Cs=a.useCallback(async(e,n)=>{const r=await jo(n);ks(e,r?"success":"error")},[ks]),ra=l?.agentId===ke,ca=a.useCallback((e,n,r,d,w=!0)=>{const z=ra&&r==="assistant",W=w&&r==="assistant"&&M?Ao(n,s("chat.reportFallbackTitle","Chat report")):null;if(!(!z&&!W?.handoff))return t.jsxs(t.Fragment,{children:[z&&t.jsx("button",{type:"button",className:`btn-icon chat-message-copy-action${ot[e]==="success"?" chat-message-copy-action--success":""}${ot[e]==="error"?" chat-message-copy-action--error":""}`,"data-testid":d??`chat-copy-response-${e}`,"aria-label":ot[e]==="success"?s("chat.responseCopied","Response copied"):ot[e]==="error"?s("chat.copyFailed","Copy failed"):s("chat.copyResponse","Copy response"),onClick:()=>{Cs(e,n)},children:ot[e]==="success"?t.jsx(To,{size:14}):t.jsx(Eo,{size:14})}),W?.handoff&&t.jsx("button",{type:"button",className:"btn-icon","data-testid":`chat-send-as-report-${e}`,"aria-label":s("chat.sendAsReport","Send as report"),onClick:()=>{W.truncated&&o(s("chat.reportTrimmed","Message trimmed to 2000 characters for mail"),"warning"),M?.(W.handoff)},children:t.jsx(Do,{size:14})})]})},[o,ot,Cs,M,ra,s]),la=a.useCallback(e=>{const n=re.current;if(!n)return;const r=`[data-testid="chat-message-${e}"]`,d=n.querySelector(r);if(!d)return;const w=d.getBoundingClientRect().top-n.getBoundingClientRect().top+n.scrollTop,z=typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;n.scrollTo({top:w,behavior:z?"auto":"smooth"})},[]),Ss=l?.cliExecutorAdapterId??null,da=!!Ss,Vi=Ss==="generic"?"generic":"hybrid",Wi=l?.cliSessionFile||l?.id||"",Ms=!da&&!B,Ns=()=>t.jsxs("div",{className:"chat-messages",ref:re,onScroll:ss,children:[t.jsx("div",{ref:Xa,className:"chat-load-more-sentinel",children:Sn&&U&&t.jsx("div",{className:"chat-loading-older",children:s("chat.loadingOlderMessages","Loading older messages…")})}),B?t.jsxs(t.Fragment,{children:[F.map((e,n)=>t.jsx(ga,{message:e,forcePlain:!1,agentName:sa,hideAssistantIdentity:oa,showAssistantModelTag:ia,activeModelTag:Fe,activeModelProvider:qe,activeSessionId:l?.id??null,projectId:i,mentionAgentsByName:Xn,roomContext:null,copyAction:ca(e.id,e.content,e.role),onScrollToTop:la,isTopClipped:Bn.has(e.id),isAwaitingQuestionAnswer:e.role==="assistant"&&n===F.length-1&&!B,submittedQuestionAnswer:ai(F,n),onQuestionSubmit:on,canEdit:Ms,onEditMessage:Le},e.id)),t.jsx(_o,{streamingText:T,streamingThinking:Q,streamingToolCalls:se,forcePlain:!1,agentName:sa,hideAssistantIdentity:oa,showAssistantModelTag:ia,activeModelTag:Fe,activeModelProvider:qe,copyAction:ra&&T?ca("__streaming__",T,"assistant","chat-copy-response-streaming",!1):void 0,onQuestionSubmit:on})]}):U?t.jsx("div",{className:"chat-empty-state",children:s("chat.loadingMessages","Loading messages...")}):F.length===0&&!l?_i():F.length===0&&l?t.jsx("div",{className:"chat-empty-state",children:s("chat.noMessagesYet","No messages yet. Start the conversation!")}):t.jsx(t.Fragment,{children:F.map((e,n)=>t.jsx(ga,{message:e,forcePlain:!1,agentName:sa,hideAssistantIdentity:oa,showAssistantModelTag:ia,activeModelTag:Fe,activeModelProvider:qe,activeSessionId:l?.id??null,projectId:i,mentionAgentsByName:Xn,roomContext:null,copyAction:ca(e.id,e.content,e.role),onScrollToTop:la,isTopClipped:Bn.has(e.id),isAwaitingQuestionAnswer:e.role==="assistant"&&n===F.length-1&&!B,submittedQuestionAnswer:ai(F,n),onQuestionSubmit:on,canEdit:Ms,onEditMessage:Le},e.id))}),t.jsx("div",{ref:Wa})]}),Rs=()=>t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Jt,type:"file","data-testid":"chat-file-input",accept:oi,multiple:!0,style:{display:"none"},onChange:e=>{mt(e.target.files),e.target.value=""}}),Ze&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":s("chat.skillSuggestions","Skill suggestions"),children:Si&&Wn.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:s("chat.loadingSkills","Loading skills…")}):we.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:kt?s("chat.noSkillsFound","No skills found"):s("chat.noSkillsAvailable","No skills available")}):we.map((e,n)=>e.kind==="command"?t.jsxs("button",{type:"button",role:"option","aria-selected":n===et,"aria-disabled":e.disabled,className:`chat-skill-menu-item chat-command-menu-item${n===et?" chat-skill-menu-item--highlighted":""}${e.disabled?" chat-command-menu-item--disabled":""}`,onMouseDown:r=>r.preventDefault(),onMouseEnter:()=>Ke(n),onClick:()=>Jn(e.command,e.disabled),children:[t.jsx("span",{className:"chat-skill-menu-item-name",children:e.command.trigger}),t.jsx("span",{className:"chat-skill-menu-item-description",children:e.disabled?s("chat.commandNoRunningAgentHint","No running agent to steer"):e.command.description})]},`command-${e.command.trigger}`):t.jsxs("button",{type:"button",role:"option","aria-selected":n===et,className:`chat-skill-menu-item${n===et?" chat-skill-menu-item--highlighted":""}`,onMouseDown:r=>r.preventDefault(),onMouseEnter:()=>Ke(n),onClick:()=>Yn(e.skill),children:[t.jsx("span",{className:"chat-skill-menu-item-name",children:e.skill.name}),t.jsx("span",{className:"chat-skill-menu-item-description",title:e.skill.relativePath,children:e.skill.relativePath})]},e.skill.id))}),ge.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:ge.map((e,n)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${n}`,children:[e.previewUrl?t.jsx("img",{src:e.previewUrl,alt:e.file.name}):t.jsx("span",{className:"chat-attachment-preview-name",children:e.file.name}),t.jsx("button",{type:"button",className:"chat-attachment-remove",onClick:()=>is(n),"data-testid":`chat-attachment-remove-${n}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${n}`))}),ze.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"chat-pending-stack","data-testid":"chat-pending-stack",children:ze.map((e,n)=>t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:s("chat.queuedMessage","Queued: {{preview}}",{preview:Ki(e)})}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":s("chat.dismissQueuedMessage","Dismiss queued message"),"data-testid":`chat-pending-dismiss-${n}`,onClick:()=>Cn(n),children:"×"})]},`${n}-${e}`))}),t.jsx("div",{className:"chat-pending-divider","aria-hidden":"true"})]}),t.jsxs("div",{className:"chat-input-row",children:[t.jsx("button",{type:"button",className:"btn-icon chat-attach-btn","data-testid":"chat-attach-btn","aria-label":s("chat.attachFiles","Attach files"),onClick:()=>Jt.current?.click(),children:t.jsx(Bs,{size:16})}),!da&&t.jsx(qs,{level:l?.thinkingLevel,defaultThinkingLevel:N,models:Ln,favoriteProviders:yi,favoriteModels:ki,agents:Array.from(be.values()),agentId:l?.agentId,modelProvider:l?.modelProvider,modelId:l?.modelId,onChange:e=>{l&&y(l.id,e)},onChangeModel:e=>{l&&p(l.id,e)},disabled:!l}),t.jsxs("div",{className:`chat-input-wrapper${Ha?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),it(!0)},onDragLeave:()=>it(!1),onDrop:e=>{e.preventDefault(),it(!1),mt(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:Di,className:"chat-input-textarea",placeholder:s("chat.typeMessage","Type a message..."),value:q,onChange:cs,onKeyDown:rs,onKeyUp:ls,onClick:ln,onBlur:ds,onFocus:us,onPaste:os,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||pa()&&(document.activeElement,e.currentTarget)},rows:1,"data-testid":"chat-input"}),t.jsx(Qs,{agents:lt,filter:tt,highlightedIndex:Ot,visible:Me,onSelect:rn,position:"below",roomMemberIds:Te?.memberIds,roomName:Te?.roomName}),t.jsx(qo,{visible:V.mentionActive&&!Me,position:Mi,tasks:V.tasks,files:V.files,selectedIndex:V.selectedIndex,onSelectTask:e=>{jt(V.selectTask(e,q),`#${e.id}`)},onSelectFile:e=>{jt(V.selectFile(e,q),`#${e.path}`)},loading:V.loading})]}),t.jsx(Os,{...Ti.micProps}),t.jsx(Hs,{isStreaming:B,canSend:!!(q.trim()||ge.length>0),onSend:Gn,onStop:fe})]})]}),Xi=H?void 0:{width:`${Je}px`},js=Ye?R:Be,As=js.filter(e=>e.pinnedAt!=null),Ts=js.filter(e=>e.pinnedAt==null),ye=G?Be.find(e=>e.id===G.sessionId)??(l?.id===G.sessionId?l:void 0):void 0,Es=a.useCallback(async()=>{const e=Tn.trim();if(!e)return;let n;try{n=await ve(e)}catch{o(s("chat.failedToCreateTag","Failed to create tag"),"error");return}if(G?.sessionId){const r=(ye?.tags??[]).map(d=>d.id);if(!r.includes(n.id))try{await Ce(G.sessionId,[...r,n.id])}catch{o(s("chat.failedToUpdateTags","Failed to update tags"),"error");return}}Fa("")},[o,G,ye,ve,Tn,Ce,s]),qi=Ui?t.jsxs("div",{className:"chat-mobile-session-menu",ref:qa,children:[t.jsxs("button",{type:"button",className:"btn chat-mobile-session-trigger","data-testid":"chat-mobile-session-trigger","aria-haspopup":"menu","aria-expanded":Vt,onClick:()=>Ne(e=>!e),children:[qe?t.jsx(ma,{provider:qe,size:"md"}):t.jsx(yn,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:Bi}),t.jsx(hn,{size:16,"aria-hidden":"true"})]}),Vt&&t.jsxs("div",{className:"chat-mobile-session-dropdown",role:"menu","data-testid":"chat-mobile-session-dropdown",children:[[{id:"pinned",label:s("chat.pinned","Pinned"),testId:"chat-mobile-pinned-divider",sessions:As},{id:"recent",label:s("chat.recent","Recent"),testId:"chat-mobile-recent-divider",sessions:Ts}].filter(e=>e.sessions.length>0).map(e=>t.jsxs("section",{className:"chat-session-section","data-testid":`chat-mobile-session-section-${e.id}`,children:[t.jsx("div",{className:"chat-pinned-divider","data-testid":e.testId,children:e.label}),e.sessions.map(n=>t.jsxs("div",{className:`chat-mobile-session-option-row${l?.id===n.id?" chat-mobile-session-option-row--active":""}`,role:"none",children:[t.jsx("button",{type:"button",role:"menuitem",className:`chat-mobile-session-option${l?.id===n.id?" chat-mobile-session-option--active":""}`,"data-testid":`chat-mobile-session-option-${n.id}`,onClick:()=>ps(n.id),children:t.jsxs("span",{className:"chat-mobile-session-option-title",children:[n.title||s("chat.untitledSession","Untitled"),n.pinnedAt?t.jsx(fn,{className:"chat-session-pinned-indicator",size:14,"data-testid":`chat-session-pinned-indicator-${n.id}`,"aria-label":s("chat.pinned","Pinned")}):null]})}),t.jsx("button",{type:"button",className:"btn-icon chat-mobile-session-pin","data-testid":`chat-mobile-session-pin-${n.id}`,"aria-label":n.pinnedAt?s("chat.unpinConversationAria","Unpin conversation {{title}}",{title:n.title||s("chat.untitledSession","Untitled")}):s("chat.pinConversationAria","Pin conversation {{title}}",{title:n.title||s("chat.untitledSession","Untitled")}),title:!n.pinnedAt&&c>=3?s("chat.pinLimit","You can pin up to 3 conversations"):void 0,disabled:!n.pinnedAt&&c>=3,onClick:()=>gs(n.id,!n.pinnedAt),children:n.pinnedAt?t.jsx(Ps,{size:14}):t.jsx(fn,{size:14})}),t.jsx("button",{type:"button",className:"btn-icon chat-mobile-session-archive","data-testid":`chat-mobile-session-archive-${n.id}`,"aria-label":s("chat.archive","Archive"),onClick:()=>void ms(n.id),children:t.jsx(Fs,{size:14})}),t.jsx("button",{type:"button",className:"btn-icon chat-mobile-session-rename","data-testid":`chat-mobile-session-rename-${n.id}`,"aria-label":s("chat.renameConversationAria","Rename conversation {{title}}",{title:n.title||s("chat.untitledSession","Untitled")}),onClick:()=>hs(n.id),children:t.jsx(ha,{size:14})})]},n.id))]},e.id)),t.jsxs("button",{type:"button",role:"menuitem",className:"chat-mobile-session-new","data-testid":"chat-mobile-session-new",onClick:()=>{Ne(!1),sn()},children:[t.jsx(pt,{size:16,"aria-hidden":"true"}),t.jsx("span",{children:s("chat.newChat","New Chat")})]})]})]}):null,Gi=t.jsxs("div",{className:"chat-sidebar-scope-toggle chat-view-header-scope-toggle",role:"tablist","data-testid":"chat-sidebar-scope-toggle",children:[t.jsxs("button",{type:"button",role:"tab",className:`chat-sidebar-scope-btn${P==="direct"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":P==="direct","data-testid":"chat-sidebar-scope-direct",onClick:()=>Qe("direct"),children:[t.jsx(wn,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:s("chat.scopeDirect","Direct")})]}),t.jsxs("button",{type:"button",role:"tab",className:`chat-sidebar-scope-btn${P==="rooms"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":P==="rooms","data-testid":"chat-sidebar-scope-rooms",onClick:()=>Qe("rooms"),children:[t.jsx(mi,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:s("chat.scopeRooms","Rooms")})]})]});return t.jsxs("div",{ref:Za,className:`chat-view${m?" chat-view--floating":""}${H?" chat-view--narrow":""}${xs?" chat-view--mobile-direct-thread":""}`,children:[t.jsx(Io,{icon:wn,title:s("chat.title","Chat"),actions:t.jsxs(t.Fragment,{children:[xs?t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"btn-icon chat-back-btn",onClick:Zn,"data-testid":"chat-back-btn","aria-label":s("chat.backToConversations","Back to conversations"),children:t.jsx($s,{size:16})}),qi]}):Gi,H?null:t.jsxs("button",{className:"btn btn-sm btn-primary chat-view-header-new-chat",onClick:sn,"data-testid":"chat-new-btn",children:[t.jsx(pt,{size:14}),s("chat.newChat","New Chat")]}),!m&&u?t.jsx("button",{type:"button",className:"btn-icon chat-view-header-icon",onClick:u,"aria-label":s("chat.popOut","Pop out chat"),title:s("chat.popOut","Pop out chat"),"data-testid":"chat-pop-out",children:t.jsx(_s,{size:16})}):null,m&&h?t.jsx("button",{type:"button",className:"btn-icon chat-view-header-icon",onClick:h,"aria-label":s("chat.maximizeToChatView","Open in Chat view"),title:s("chat.maximizeToChatView","Open in Chat view"),"data-testid":"chat-modal-maximize",children:t.jsx(_s,{size:16})}):null,m&&k?t.jsx("button",{type:"button",className:"btn-icon chat-view-header-icon",onClick:k,"aria-label":s("chat.minimizeToQuickChat","Minimize to quick chat"),title:s("chat.minimizeToQuickChat","Minimize to quick chat"),"data-testid":"chat-modal-minimize",children:t.jsx(Lo,{size:16})}):null,m&&C?t.jsx("button",{type:"button",className:"btn-icon chat-view-header-icon",onClick:C,"aria-label":s("chat.closeChat","Close chat"),title:s("chat.closeChat","Close chat"),"data-testid":"chat-modal-close",children:t.jsx(zs,{size:16})}):null]})}),t.jsxs("div",{className:"chat-view__body",children:[t.jsxs("div",{className:`chat-sidebar${yt?"":" chat-sidebar--hidden"}`,style:Xi,children:[P==="direct"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"chat-sidebar-search-container",children:[t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(Po,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:s("chat.searchConversations","Search conversations..."),value:pi,onChange:e=>vi(e.target.value),"data-testid":"chat-search-input"})]}),t.jsxs("label",{className:"chat-tag-filter",htmlFor:"chat-tag-filter",children:[t.jsx(Oo,{size:14,"aria-hidden":"true"}),t.jsxs("select",{id:"chat-tag-filter",value:_??"",onChange:e=>J(e.target.value||null),"data-testid":"chat-tag-filter","aria-label":s("chat.filterByTag","Filter conversations by tag"),children:[t.jsx("option",{value:"",children:s("chat.allTags","All tags")}),A.map(e=>t.jsx("option",{value:e.id,children:e.name},e.id))]}),_?t.jsx("button",{type:"button",className:"btn-icon","aria-label":s("chat.clearTagFilter","Clear tag filter"),onClick:()=>J(null),children:t.jsx(zs,{size:14})}):null]})]}),t.jsx("div",{className:"chat-archived-toggle",children:t.jsx("button",{type:"button",className:"btn btn-sm btn-secondary","data-testid":"chat-archived-toggle",onClick:()=>{const e=!Ye;wi(e),e&&$()},children:Ye?"Active conversations":"Archived conversations"})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:L?t.jsx("div",{className:"chat-empty-state chat-empty-state--padded",children:s("chat.loadingConversations","Loading...")}):(Ye?R:Be).length===0?t.jsx("div",{className:"chat-empty-state chat-empty-state--padded",children:s("chat.noConversationsYet","No conversations yet")}):t.jsx(t.Fragment,{children:[{id:"pinned",label:s("chat.pinned","Pinned"),testId:"chat-pinned-divider",sessions:As},{id:"recent",label:s("chat.recent","Recent"),testId:"chat-recent-divider",sessions:Ts}].filter(e=>e.sessions.length>0).map(e=>t.jsxs("section",{className:"chat-session-section","data-testid":`chat-session-section-${e.id}`,children:[t.jsx("div",{className:"chat-pinned-divider","data-testid":e.testId,children:e.label}),e.sessions.map(n=>{const r=l?.id===n.id,d=!r&&Da("direct",n.id,n.lastMessageAt??n.updatedAt),w=ri(n,be.get(n.agentId)??null,Bt),z=Ls(w?.provider,w?.modelId)??"Fusion",W=n.title||s("chat.untitledSession","Untitled");return t.jsxs("div",{className:`chat-session-item${r?" chat-session-item--active":""}`,onClick:()=>ps(n.id),onContextMenu:K=>{K.preventDefault(),Ia(n.id,K.clientX,K.clientY)},"data-testid":Ye?`chat-archived-session-${n.id}`:`chat-session-${n.id}`,children:[t.jsx("button",{type:"button",className:"btn-icon chat-session-menu-btn","data-testid":"chat-session-menu-btn","aria-label":s("chat.conversationActionsAria","Conversation actions for {{title}}",{title:W}),"aria-haspopup":"menu","aria-expanded":G?.sessionId===n.id,onClick:K=>{if(K.stopPropagation(),G?.sessionId===n.id){Se(null);return}const pe=K.currentTarget.getBoundingClientRect();Ia(n.id,pe.right,pe.bottom,{anchorRight:!0})},children:t.jsx(Fo,{size:14})}),t.jsxs("div",{className:"chat-session-title",children:[W,n.pinnedAt?t.jsx(fn,{className:"chat-session-pinned-indicator",size:14,"data-testid":`chat-session-pinned-indicator-${n.id}`,"aria-label":s("chat.pinned","Pinned")}):null,d?t.jsx("span",{className:"chat-unread-dot","data-testid":`chat-unread-dot-${n.id}`,"aria-label":s("chat.unreadMessages","Unread messages")}):null]}),t.jsx("div",{className:"chat-session-preview",children:n.lastMessagePreview||s("chat.noMessages","No messages")}),(n.tags??[]).length>0?t.jsx("div",{className:"chat-session-tags","data-testid":`chat-session-tags-${n.id}`,children:(n.tags??[]).map(K=>t.jsx("span",{className:"chat-session-tag",children:K.name},K.id))}):null,n.matchedMessagePreview?t.jsx("div",{className:"chat-session-preview chat-session-preview--matched","data-testid":`chat-session-matched-preview-${n.id}`,children:s("chat.matchedInMessage",'Matched: "{{preview}}"',{preview:n.matchedMessagePreview})}):null,Ye?t.jsx("button",{type:"button",className:"btn btn-sm btn-secondary","data-testid":`chat-archived-restore-${n.id}`,onClick:K=>{K.stopPropagation(),Li(n.id)},children:"Restore"}):null,t.jsxs("div",{className:"chat-session-meta",children:[t.jsxs("span",{className:"chat-session-meta-model",children:[w?.provider?t.jsx(ma,{provider:w.provider,size:"sm"}):null,t.jsx("span",{children:be.get(n.agentId)?.name||(n.agentId===ke?z:n.agentId.slice(0,30))})]}),t.jsx("span",{children:n.updatedAt?ur(n.updatedAt,s):""})]})]},n.id)})]},e.id))})})]}):t.jsxs("div",{className:"chat-sidebar-rooms","data-testid":"chat-sidebar-rooms",children:[!H&&t.jsx("div",{className:"chat-sidebar-rooms-header","data-testid":"chat-sidebar-rooms-header",children:t.jsxs("button",{type:"button",className:"btn btn-sm btn-primary","data-testid":"chat-create-room-btn",onClick:()=>zt(!0),children:[t.jsx(pt,{size:14}),s("chat.createRoom","Create room")]})}),x.rooms.length===0?t.jsx("div",{className:"chat-sidebar-rooms-empty","data-testid":"chat-sidebar-rooms-empty",children:s("chat.noRoomsYet","No rooms yet.")}):t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:x.rooms.map(e=>{const n=x.activeRoom?.id===e.id,r=!n&&Da("room",e.id,e.updatedAt);return t.jsxs("div",{role:"button",tabIndex:0,className:`chat-room-item${n?" chat-room-item--active":""}`,"data-testid":`chat-room-item-${e.slug}`,onClick:()=>{de("room",e.id,e.updatedAt),x.selectRoom(e.id),H&&He(!1)},onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),de("room",e.id,e.updatedAt),x.selectRoom(e.id),H&&He(!1))},children:[t.jsxs("span",{className:"chat-room-item-details",children:[t.jsxs("span",{className:"chat-room-item-name-row",children:[t.jsxs("span",{className:"chat-room-item-name",children:["#",e.name]}),r?t.jsx("span",{className:"chat-unread-dot","data-testid":`chat-unread-dot-${e.id}`,"aria-label":s("chat.unreadMessages","Unread messages")}):null]}),n?t.jsx("span",{className:"chat-room-item-meta",children:s("chat.roomMemberCount","{{count}} member",{count:x.activeRoomMembers.length,defaultValue_one:"{{count}} member",defaultValue_other:"{{count}} members"})}):null]}),t.jsx("button",{type:"button",className:"btn-icon chat-room-item-delete","data-testid":`chat-room-delete-${e.slug}`,"aria-label":s("chat.deleteRoom","Delete room {{name}}",{name:e.name}),onClick:d=>{d.stopPropagation(),$t(e.id)},children:t.jsx(fa,{size:14})})]},e.id)})})]}),P==="rooms"?H?t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{type:"button",className:"btn btn-sm btn-primary chat-sidebar-footer-btn","data-testid":"chat-create-room-btn",onClick:()=>zt(!0),children:[t.jsx(pt,{size:14}),s("chat.createRoom","Create room")]})}):null:H?t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:sn,"data-testid":"chat-new-btn",children:[t.jsx(pt,{size:14}),s("chat.newChat","New Chat")]})}):null]}),!H&&yt&&!Rt&&t.jsx("div",{className:"chat-sidebar-resize-handle",role:"separator","aria-orientation":"vertical","aria-valuemin":vn,"aria-valuemax":bn,"aria-valuenow":Je,"aria-label":s("chat.resizeSidebar","Resize chat sidebar"),tabIndex:0,onPointerDown:Fi,onKeyDown:$i}),G&&t.jsxs("div",{className:"chat-session-context-menu",ref:Rn,role:"menu",style:{top:G.y,left:G.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>gs(G.sessionId,!ye?.pinnedAt),"data-testid":"chat-context-pin",title:c>=3&&!ye?.pinnedAt?s("chat.pinLimit","You can pin up to 3 conversations"):void 0,disabled:c>=3&&!ye?.pinnedAt,children:[ye?.pinnedAt?t.jsx(Ps,{size:14}):t.jsx(fn,{size:14}),ye?.pinnedAt?s("chat.unpin","Unpin"):s("chat.pin","Pin")]}),t.jsxs("button",{onClick:()=>hs(G.sessionId),"data-testid":"chat-context-rename",children:[t.jsx(ha,{size:14}),s("chat.rename","Rename")]}),t.jsxs("div",{className:"chat-session-tag-menu",role:"group","aria-label":s("chat.conversationTags","Conversation tags"),children:[A.map(e=>{const n=(ye?.tags??[]).some(r=>r.id===e.id);return t.jsxs("div",{className:"chat-tag-menu-item",children:[t.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":n,"data-testid":`chat-context-tag-${e.id}`,onClick:()=>void Ce(G.sessionId,n?(ye?.tags??[]).filter(r=>r.id!==e.id).map(r=>r.id):[...(ye?.tags??[]).map(r=>r.id),e.id]).catch(()=>o(s("chat.failedToUpdateTags","Failed to update tags"),"error")),children:[n?"✓ ":"",e.name]}),t.jsx("button",{type:"button",className:"btn-icon","aria-label":s("chat.renameTag","Rename tag {{name}}",{name:e.name}),"data-testid":`chat-context-rename-tag-${e.id}`,onClick:r=>{r.stopPropagation(),$a(e.name),xt(e)},children:t.jsx(ha,{size:14})}),t.jsx("button",{type:"button",className:"btn-icon","aria-label":s("chat.deleteTag","Delete tag {{name}}",{name:e.name}),"data-testid":`chat-context-delete-tag-${e.id}`,onClick:r=>{r.stopPropagation(),_t(e)},children:t.jsx(fa,{size:14})})]},e.id)}),t.jsxs("div",{className:"chat-tag-create-row",children:[t.jsx("input",{className:"input",value:Tn,placeholder:s("chat.newTag","New tag"),"aria-label":s("chat.newTag","New tag"),onChange:e=>Fa(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),Es())}}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>void Es(),children:s("chat.addTag","Add")})]})]}),t.jsxs("button",{onClick:()=>ms(G.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Fs,{size:14}),s("chat.archive","Archive")]}),t.jsxs("button",{onClick:()=>{Se(null),Ft(G.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(fa,{size:14}),s("chat.delete","Delete")]})]}),Lt&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>Pt(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"chat-rename-dialog-title",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{id:"chat-rename-dialog-title",children:s("chat.renameConversationTitle","Rename Conversation")}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:s("chat.renameConversationBody","Choose a new name for this conversation. Leave it blank to show Untitled.")}),t.jsx("label",{className:"chat-rename-label",htmlFor:"chat-rename-input",children:s("chat.conversationName","Conversation name")}),t.jsx("input",{id:"chat-rename-input",className:"input chat-rename-input",type:"text",value:jn,placeholder:s("chat.renamePlaceholder","Untitled"),"data-testid":"chat-rename-input",onChange:e=>An(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),fs())},autoFocus:!0}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>Pt(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-primary",onClick:()=>void fs(),"data-testid":"chat-rename-save",children:s("chat.save","Save")})]})]})}),En&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>xt(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"chat-rename-tag-dialog-title",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{id:"chat-rename-tag-dialog-title",children:s("chat.renameTagTitle","Rename tag")}),t.jsx("label",{className:"chat-rename-label",htmlFor:"chat-rename-tag-input",children:s("chat.tagName","Tag name")}),t.jsx("input",{id:"chat-rename-tag-input",className:"input chat-rename-input",value:Dn,"data-testid":"chat-rename-tag-input",onChange:e=>$a(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),ee(En.id,Dn).then(()=>xt(null)).catch(()=>o(s("chat.failedToRenameTag","Failed to rename tag"),"error")))},autoFocus:!0}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>xt(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-primary","data-testid":"chat-rename-tag-save",onClick:()=>void ee(En.id,Dn).then(()=>xt(null)).catch(()=>o(s("chat.failedToRenameTag","Failed to rename tag"),"error")),children:s("chat.save","Save")})]})]})}),_a&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>_t(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"chat-delete-tag-dialog-title",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{id:"chat-delete-tag-dialog-title",children:s("chat.deleteTagTitle","Delete tag?")}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:s("chat.deleteTagBody","This removes the tag from all conversations, but does not delete conversations.")}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>_t(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-danger","data-testid":"chat-delete-tag-confirm",onClick:()=>void he(_a.id).then(()=>_t(null)).catch(()=>o(s("chat.failedToDeleteTag","Failed to delete tag"),"error")),children:s("chat.delete","Delete")})]})]})}),La&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>Ft(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:s("chat.deleteConversationTitle","Delete Conversation?")}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:s("chat.deleteConversationBody","This action cannot be undone. All messages in this conversation will be permanently deleted.")}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>Ft(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void Pi(La),children:s("chat.delete","Delete")})]})]})}),Pa&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>$t(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:s("chat.deleteRoomTitle","Delete Room?")}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:s("chat.deleteRoomBody","This action cannot be undone. This room and all its messages will be permanently deleted.")}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>$t(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>{(async()=>{try{await x.deleteRoom(Pa),$t(null)}catch{o(s("chat.failedToDeleteRoom","Failed to delete room"),"error")}})()},children:s("chat.delete","Delete")})]})]})}),P==="rooms"?t.jsxs("div",{ref:zn,className:"chat-thread",children:[x.activeRoom?t.jsxs(t.Fragment,{children:[(!H||ys)&&t.jsxs("div",{className:"chat-room-thread-header",children:[ys&&t.jsx("button",{className:"btn-icon",onClick:ea,"data-testid":"chat-back-btn",children:t.jsx($s,{size:16})}),t.jsxs("div",{className:"chat-room-switcher-menu",ref:Ga,children:[t.jsxs("button",{type:"button",className:"chat-room-switcher-trigger","data-testid":"chat-room-switcher-trigger","aria-haspopup":"menu","aria-expanded":Wt,onClick:()=>St(e=>!e),children:[t.jsxs("span",{className:"chat-thread-header-title",children:["#",x.activeRoom.name]}),t.jsx(hn,{size:16,"aria-hidden":"true"})]}),Wt&&t.jsx("div",{role:"menu",className:"chat-room-switcher-dropdown","data-testid":"chat-room-switcher-dropdown",children:x.rooms.map(e=>t.jsxs("button",{type:"button",role:"menuitem",className:`chat-room-switcher-option${e.id===x.activeRoom?.id?" chat-room-switcher-option--active":""}`,"data-testid":`chat-room-switcher-option-${e.id}`,onClick:()=>{de("room",e.id,e.updatedAt),x.selectRoom(e.id),St(!1)},children:["#",e.name]},e.id))})]}),t.jsx("div",{className:"chat-room-thread-members",children:x.activeRoomMembers.map(e=>t.jsx(kn,{agent:be.get(e.agentId)??{id:e.agentId,name:e.agentId.slice(0,30)}},e.agentId))})]}),t.jsxs("div",{className:"chat-messages",ref:re,onScroll:ss,children:[x.messagesLoading?t.jsx("div",{className:"chat-empty-state",children:s("chat.loadingMessages","Loading messages...")}):x.messages.filter(e=>e.content.trim()!==ti).length===0?t.jsx("div",{className:"chat-empty-state",children:s("chat.noMessagesYet","No messages yet. Start the conversation!")}):x.messages.filter(e=>e.content.trim()!==ti).map(e=>{const n=e.senderAgentId?be.get(e.senderAgentId)?.name??e.senderAgentId.slice(0,30):s("chat.you","You"),r={id:e.id,sessionId:e.roomId,role:e.role,content:e.content,thinkingOutput:e.thinkingOutput??void 0,toolCalls:void 0,fallbackInfo:void 0,attachments:e.attachments,createdAt:e.createdAt};return t.jsx(ga,{message:r,forcePlain:!1,agentName:n,hideAssistantIdentity:!1,showAssistantModelTag:!1,activeModelTag:null,activeModelProvider:null,activeSessionId:x.activeRoom?.id??null,projectId:i,mentionAgentsByName:Xn,roomContext:Te,onScrollToTop:la,isTopClipped:Bn.has(e.id),isAwaitingQuestionAnswer:!1,onQuestionSubmit:on},e.id)}),t.jsx("div",{ref:Wa})]}),x.activeRoom&&Ua&&t.jsxs("button",{type:"button",className:"btn btn-sm chat-jump-to-latest","data-testid":"chat-jump-to-latest",onClick:()=>xe("fab-click"),children:[t.jsx(hn,{size:14}),s("chat.latest","Latest")]})]}):t.jsx("div",{className:"chat-room-empty-pane","data-testid":"chat-rooms-empty-pane",children:s("chat.selectRoomOrCreate","Select a room or create one")}),x.activeRoom&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Jt,type:"file",accept:oi,multiple:!0,style:{display:"none"},onChange:e=>{mt(e.target.files),e.target.value=""}}),ge.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:ge.map((e,n)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${n}`,children:[e.previewUrl?t.jsx("img",{src:e.previewUrl,alt:e.file.name}):t.jsx("span",{className:"chat-attachment-preview-name",children:e.file.name}),t.jsx("button",{type:"button",className:"chat-attachment-remove",onClick:()=>is(n),"data-testid":`chat-attachment-remove-${n}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${n}`))}),t.jsxs("div",{className:"chat-input-row",children:[t.jsx("button",{type:"button",className:"btn-icon chat-attach-btn","data-testid":"chat-attach-btn","aria-label":s("chat.attachFiles","Attach files"),onClick:()=>Jt.current?.click(),children:t.jsx(Bs,{size:16})}),t.jsx(qs,{level:x.activeRoom.thinkingLevel,defaultThinkingLevel:N,showTargetSection:!1,onChange:e=>{x.updateRoomSettings(x.activeRoom.id,{thinkingLevel:e||null}).catch(()=>{o(s("chat.failedToUpdateRoomThinkingLevel","Failed to update room thinking effort"),"error")})}}),t.jsxs("div",{className:`chat-input-wrapper${Ha?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),it(!0)},onDragLeave:()=>it(!1),onDrop:e=>{e.preventDefault(),it(!1),mt(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:Ii,className:"chat-input-textarea",placeholder:s("chat.typeMessage","Type a message..."),value:q,onChange:cs,onKeyDown:rs,onKeyUp:ls,onClick:ln,onBlur:ds,onFocus:us,onPaste:os,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||pa()&&(document.activeElement,e.currentTarget)},rows:1,"data-testid":"chat-input"}),t.jsx(Qs,{agents:lt,filter:tt,highlightedIndex:Ot,visible:Me,onSelect:rn,position:"below",roomMemberIds:Te?.memberIds,roomName:Te?.roomName})]}),t.jsx(Os,{...Ei.micProps}),t.jsx(Hs,{isStreaming:!1,canSend:!!(q.trim()||ge.length>0),onSend:Qn})]})]})]}):t.jsxs("div",{ref:zn,className:"chat-thread",children:[!H&&(na||!H)&&t.jsx("div",{className:"chat-thread-header",children:t.jsxs("div",{className:"chat-thread-header-identity","data-testid":"chat-thread-header-identity",children:[qe?t.jsx(ma,{provider:qe,size:"md"}):t.jsx(yn,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:bs}),Oi&&t.jsx("span",{className:"chat-model-tag",children:Fe}),Hi&&mn&&aa?t.jsxs("span",{className:"chat-thread-header-context","data-testid":"chat-thread-context-window",title:aa,"aria-label":aa,children:[ws," / ",mn]}):null]})}),da?t.jsx(Yo,{cliSessionId:Wi,tier:Vi,projectId:i,renderTranscript:Ns,renderComposer:()=>l?Rs():null}):t.jsxs(t.Fragment,{children:[Ns(),Ua&&t.jsxs("button",{type:"button",className:"btn btn-sm chat-jump-to-latest","data-testid":"chat-jump-to-latest",onClick:()=>xe("fab-click"),children:[t.jsx(hn,{size:14}),s("chat.latest","Latest")]}),l&&Rs()]})]}),t.jsx(Qo,{isOpen:xi,onClose:()=>zt(!1),projectId:i,existingRoomNames:x.rooms.map(e=>e.name),onCreate:async e=>{await x.createRoom({name:e.name,memberAgentIds:e.memberAgentIds}),P!=="rooms"&&Qe("rooms"),zt(!1),H&&He(!1)}})]}),bi&&t.jsx(vr,{projectId:i,defaultModel:Ci,defaultKind:S?.kind,defaultAgentId:S?.kind==="agent"?S.agentId:void 0,defaultThinkingLevel:N,defaultSelectedThinkingLevel:S?.kind==="model"?S.thinkingLevel:void 0,onClose:()=>Nn(!1),onCreate:ht})]})}export{Rr as ChatView,Nr as buildIssueChatPrefill,dr as clampChatInputHeight,cr as resolveChatContextMenuPosition,lr as resolveChatInputOverflowY,ri as resolveSessionProvider};
@@ -1,4 +1,4 @@
1
- import{r as f,j as s,g as mn,a as nj,b as Zl,c as aj}from"./vendor-react-SZ_qB27O.js";import{c as Vt,h2 as ij,dW as Sh,L as Jl,h as Mi,h3 as Ii,a as fr,w as mr,aW as vn,h4 as Ql,h5 as sj,a$ as Zr,an as el,a9 as Nh,_ as La,x as tn,b2 as oj,b4 as lj,P as zn,b0 as cj,h6 as Ph,c9 as Di,bh as qa,ab as ec,h7 as Lu,R as Gt,ay as uj,h8 as dj,aL as fj,aS as Ri,h9 as Ah,eg as mj,aX as Oh,aY as Eh,b$ as vj,aJ as tc,ca as hj,ha as pj,am as yj,fv as gj,hb as bj,ae as _h,hc as xj,hd as jj,bK as $u,he as Fu,fG as wj,gK as Ps,hf as Bu,hg as ga,hh as Cj,hi as kj,hj as Sj,hk as Nj,gL as Pj,hl as Aj,hm as Oj,hn as Ej,gH as _j,ho as Tj,y as Mj,aM as Ij,gM as Th,hp as Dj,ci as Rj,u as Lj,hq as $j,as as Fj,hr as As,hs as Bj,ht as zj,hu as Kj,hv as Vj,hw as Uj,hx as qj,hy as rc,hz as nc,hA as zu,cZ as Wa,hB as Ku,hC as tl,hD as Mh,hE as rl,bi as Ih,bL as Dh,cb as Rh,di as Wj,d5 as Hj,F as ac,C as ic,hF as Gj,hG as Xj,v as Yj,eX as Vu,X as $a,E as Zj,p as Jj,b1 as Uu,aH as Qj,hH as qu,hI as e0,hJ as t0,hK as r0,hL as n0,ee as a0,hM as Os,hN as i0,hO as s0,hP as o0}from"./index-BlGpMJSZ.js";import{u as se}from"./vendor-i18n-Duky4gdQ.js";import{a as Lh,b as $h,p as l0,w as c0}from"./vendor-reactflow-BlIeoTu4.js";import{w as Fh,n as Bh,a as Me,A as sc,G as u0,H as d0,l as zh,t as Li,b as _t,p as nl,s as Ha,c as Kh,q as f0,r as m0,u as v0,v as h0,x as p0,y as y0,z as g0,C as b0,D as x0,k as j0,E as w0,F as C0}from"./step-yuy0qJer.js";import{b as k0,p as S0}from"./band-CquvqAHh.js";import{d as Ga,n as N0,e as P0,f as al,g as Br,h as oc,a as lc,i as Wu,j as Ht,c as A0,k as $i,l as O0,m as E0}from"./linear-Dyk9wory.js";import{i as pr,a as Qt}from"./init-Dmth1JHB.js";import{m as Hu,a as Gu,p as _0,q as T0,u as M0,s as I0,r as D0,v as R0,w as L0,x as $0,y as F0,z as B0,A as z0,B as K0,t as V0}from"./time-2wBVBf9F.js";import{f as U0,b as q0}from"./defaultLocale-DX6XiGOO.js";import{i as W0,o as H0}from"./ordinal-DILIJJjt.js";import{g as G0,r as X0}from"./agentsOrgChartLayout-C2K_M3x3.js";import{U as cc}from"./upload-_s5sL5Pq.js";import{S as Y0}from"./shield-alert-C16k8wNu.js";import{b as Z0}from"./agent-import-generation-D27NKQsr.js";import{r as J0,B as Q0,R as ew,b as tw,a as rw}from"./ReportModal-BWuaroTF.js";import{PluginManager as nw}from"./PluginManager-BW-_Zyo5.js";import{v as aw}from"./projectDetection-G3XuxD2X.js";import"./vendor-codemirror-CcrtqoCy.js";import"./vendor-xterm-BNq00GSj.js";import"./DirectoryPicker-CLdqqqYN.js";import"./folder-open-DAh8mpTX.js";/**
1
+ import{r as f,j as s,g as mn,a as nj,b as Zl,c as aj}from"./vendor-react-SZ_qB27O.js";import{c as Vt,h2 as ij,dW as Sh,L as Jl,h as Mi,h3 as Ii,a as fr,w as mr,aW as vn,h4 as Ql,h5 as sj,a$ as Zr,an as el,a9 as Nh,_ as La,x as tn,b2 as oj,b4 as lj,P as zn,b0 as cj,h6 as Ph,c9 as Di,bh as qa,ab as ec,h7 as Lu,R as Gt,ay as uj,h8 as dj,aL as fj,aS as Ri,h9 as Ah,eg as mj,aX as Oh,aY as Eh,b$ as vj,aJ as tc,ca as hj,ha as pj,am as yj,fv as gj,hb as bj,ae as _h,hc as xj,hd as jj,bK as $u,he as Fu,fG as wj,gK as Ps,hf as Bu,hg as ga,hh as Cj,hi as kj,hj as Sj,hk as Nj,gL as Pj,hl as Aj,hm as Oj,hn as Ej,gH as _j,ho as Tj,y as Mj,aM as Ij,gM as Th,hp as Dj,ci as Rj,u as Lj,hq as $j,as as Fj,hr as As,hs as Bj,ht as zj,hu as Kj,hv as Vj,hw as Uj,hx as qj,hy as rc,hz as nc,hA as zu,cZ as Wa,hB as Ku,hC as tl,hD as Mh,hE as rl,bi as Ih,bL as Dh,cb as Rh,di as Wj,d5 as Hj,F as ac,C as ic,hF as Gj,hG as Xj,v as Yj,eX as Vu,X as $a,E as Zj,p as Jj,b1 as Uu,aH as Qj,hH as qu,hI as e0,hJ as t0,hK as r0,hL as n0,ee as a0,hM as Os,hN as i0,hO as s0,hP as o0}from"./index-DWRJyaa3.js";import{u as se}from"./vendor-i18n-Duky4gdQ.js";import{a as Lh,b as $h,p as l0,w as c0}from"./vendor-reactflow-BlIeoTu4.js";import{w as Fh,n as Bh,a as Me,A as sc,G as u0,H as d0,l as zh,t as Li,b as _t,p as nl,s as Ha,c as Kh,q as f0,r as m0,u as v0,v as h0,x as p0,y as y0,z as g0,C as b0,D as x0,k as j0,E as w0,F as C0}from"./step-yuy0qJer.js";import{b as k0,p as S0}from"./band-CquvqAHh.js";import{d as Ga,n as N0,e as P0,f as al,g as Br,h as oc,a as lc,i as Wu,j as Ht,c as A0,k as $i,l as O0,m as E0}from"./linear-Dyk9wory.js";import{i as pr,a as Qt}from"./init-Dmth1JHB.js";import{m as Hu,a as Gu,p as _0,q as T0,u as M0,s as I0,r as D0,v as R0,w as L0,x as $0,y as F0,z as B0,A as z0,B as K0,t as V0}from"./time-2wBVBf9F.js";import{f as U0,b as q0}from"./defaultLocale-DX6XiGOO.js";import{i as W0,o as H0}from"./ordinal-DILIJJjt.js";import{g as G0,r as X0}from"./agentsOrgChartLayout-C3iumMrW.js";import{U as cc}from"./upload-BjyBtxo7.js";import{S as Y0}from"./shield-alert-BS05s4RM.js";import{b as Z0}from"./agent-import-generation-upc0yw-M.js";import{r as J0,B as Q0,R as ew,b as tw,a as rw}from"./ReportModal-BOEbqtqG.js";import{PluginManager as nw}from"./PluginManager-BkB6WLQc.js";import{v as aw}from"./projectDetection-G3XuxD2X.js";import"./vendor-codemirror-CcrtqoCy.js";import"./vendor-xterm-BNq00GSj.js";import"./DirectoryPicker-CtjqrYoO.js";import"./folder-open-CqvaMJvx.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.