@runfusion/fusion 0.77.0-beta.0 → 0.77.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 +387 -72
  2. package/dist/child-process-worker.js +2479 -2196
  3. package/dist/client/.vite/manifest.json +262 -262
  4. package/dist/client/assets/{AgentDetailView-0G9qFd4j.js → AgentDetailView-Dew3af1O.js} +1 -1
  5. package/dist/client/assets/{AgentPermissionPolicyEditor-BM68g7wo.js → AgentPermissionPolicyEditor-CxPQffiY.js} +1 -1
  6. package/dist/client/assets/{AgentsView-DkOUZWw4.js → AgentsView-Cr4LDGdt.js} +3 -3
  7. package/dist/client/assets/ChatView-cNYtYx05.js +13 -0
  8. package/dist/client/assets/{CommandCenter-DxRSFWNc.js → CommandCenter-DCC90LOP.js} +1 -1
  9. package/dist/client/assets/{DevServerView-DO-bqJFE.js → DevServerView-B5b520w6.js} +1 -1
  10. package/dist/client/assets/{DirectoryPicker-Cp2gddTE.js → DirectoryPicker-1JvRd5mC.js} +1 -1
  11. package/dist/client/assets/{DocumentsView-D0E-3G96.js → DocumentsView-ksK9f7xt.js} +1 -1
  12. package/dist/client/assets/{EvalsView-BoFVq5hw.js → EvalsView-a3LhgRSo.js} +1 -1
  13. package/dist/client/assets/{ExperimentalAgentOnboardingModal-CS1Sdogm.js → ExperimentalAgentOnboardingModal-vdVa8h7F.js} +1 -1
  14. package/dist/client/assets/{GoalsView-sybf7JY4.js → GoalsView-Dz2o91fd.js} +1 -1
  15. package/dist/client/assets/{InsightsView-nHa7aShn.js → InsightsView-De3R_46d.js} +1 -1
  16. package/dist/client/assets/{MemoryView-D0IG44za.js → MemoryView-Cagk2wZG.js} +1 -1
  17. package/dist/client/assets/{PiExtensionsManager-CU76weJe.js → PiExtensionsManager-C9JABO_4.js} +1 -1
  18. package/dist/client/assets/{PluginManager-DyT8XbcG.js → PluginManager-D2csmdQa.js} +1 -1
  19. package/dist/client/assets/{PullRequestView-CnxWUSen.js → PullRequestView-DT8vTeVi.js} +1 -1
  20. package/dist/client/assets/{ReportModal-CMrmMQjD.js → ReportModal-YMP6V4vu.js} +1 -1
  21. package/dist/client/assets/{ResearchView-BTytQSgy.js → ResearchView-cNsjYu8F.js} +1 -1
  22. package/dist/client/assets/{SecretsView-BuSH5J87.js → SecretsView-BAmf7KyS.js} +1 -1
  23. package/dist/client/assets/{SessionTerminal-D04kYRrT.js → SessionTerminal-BjGcxq22.js} +1 -1
  24. package/dist/client/assets/{SettingsModal-Dm-ngbRr.js → SettingsModal-C_9RiEI7.js} +1 -1
  25. package/dist/client/assets/{SettingsModal-xSLhH7Tr.js → SettingsModal-DLfy2e_5.js} +4 -4
  26. package/dist/client/assets/{SettingsTextareaRow-CHPgocEp.js → SettingsTextareaRow-D8RHSj8b.js} +1 -1
  27. package/dist/client/assets/{SetupWizardModal-y88aXNIQ.js → SetupWizardModal-DRJ96pHQ.js} +2 -2
  28. package/dist/client/assets/{SkillsView-CYyQW1Hv.js → SkillsView-DyeCwYit.js} +1 -1
  29. package/dist/client/assets/{WorkflowNodeEditor-hYeoz1X8.js → WorkflowNodeEditor-C5Jc9w_A.js} +3 -3
  30. package/dist/client/assets/{agent-import-generation-CjiYXzCr.js → agent-import-generation-SCPNeF25.js} +1 -1
  31. package/dist/client/assets/{agentsOrgChartLayout-C0UP_X3z.js → agentsOrgChartLayout-CqKtNCjy.js} +1 -1
  32. package/dist/client/assets/{architectureDiagram-3BPJPVTR-Dd6GPcqM.js → architectureDiagram-3BPJPVTR-Cz2HYn0b.js} +1 -1
  33. package/dist/client/assets/{blockDiagram-GPEHLZMM-CC6pLxlz.js → blockDiagram-GPEHLZMM-IimJVscG.js} +1 -1
  34. package/dist/client/assets/{c4Diagram-AAUBKEIU-DxMP_l6y.js → c4Diagram-AAUBKEIU-C-xii7zn.js} +1 -1
  35. package/dist/client/assets/channel-D-UHgx8G.js +1 -0
  36. package/dist/client/assets/{chunk-2J33WTMH-BKYToL43.js → chunk-2J33WTMH-DQ-9Xccu.js} +1 -1
  37. package/dist/client/assets/{chunk-4BX2VUAB-Bg6rjQb3.js → chunk-4BX2VUAB-DmdAX9Bx.js} +1 -1
  38. package/dist/client/assets/{chunk-55IACEB6-CPUwbbGa.js → chunk-55IACEB6-IF2bk5IL.js} +1 -1
  39. package/dist/client/assets/{chunk-727SXJPM-DScQBCvv.js → chunk-727SXJPM-AeYpIzVu.js} +1 -1
  40. package/dist/client/assets/{chunk-AQP2D5EJ-DbX7uaXK.js → chunk-AQP2D5EJ-DV942DD9.js} +1 -1
  41. package/dist/client/assets/{chunk-FMBD7UC4-DvYKea1c.js → chunk-FMBD7UC4-Bt_riVlZ.js} +1 -1
  42. package/dist/client/assets/{chunk-ND2GUHAM-CH-Tvw7w.js → chunk-ND2GUHAM-CbyjNbXR.js} +1 -1
  43. package/dist/client/assets/{chunk-QZHKN3VN-CbyEvOoM.js → chunk-QZHKN3VN-DqiRniYQ.js} +1 -1
  44. package/dist/client/assets/classDiagram-4FO5ZUOK-Do-8MdAc.js +1 -0
  45. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-Do-8MdAc.js +1 -0
  46. package/dist/client/assets/{cose-bilkent-S5V4N54A-BPB5fV3A.js → cose-bilkent-S5V4N54A-UCvthviL.js} +1 -1
  47. package/dist/client/assets/{dagre-BM42HDAG-CilYJ3rR.js → dagre-BM42HDAG-DnMlT1Oi.js} +1 -1
  48. package/dist/client/assets/{dashboard-view-dChSM_So.js → dashboard-view-C9D0aoRW.js} +1 -1
  49. package/dist/client/assets/dashboard-view-Cz0sp2Wl.js +1 -0
  50. package/dist/client/assets/{dashboard-view-DoLU6FxZ.js → dashboard-view-JysoyDRX.js} +1 -1
  51. package/dist/client/assets/{dashboard-view-DnVf3tmI.js → dashboard-view-myjM9tr8.js} +1 -1
  52. package/dist/client/assets/{diagram-2AECGRRQ-m9u1Qhyx.js → diagram-2AECGRRQ-BYFiqXGw.js} +1 -1
  53. package/dist/client/assets/{diagram-5GNKFQAL-DVr7Kf0N.js → diagram-5GNKFQAL-DZU3pSYq.js} +1 -1
  54. package/dist/client/assets/{diagram-KO2AKTUF-D7sgJDFx.js → diagram-KO2AKTUF-0ybdKuMm.js} +1 -1
  55. package/dist/client/assets/{diagram-LMA3HP47-DNKNDS6r.js → diagram-LMA3HP47-Rxbgnbsp.js} +1 -1
  56. package/dist/client/assets/{diagram-OG6HWLK6-1Bff4FWn.js → diagram-OG6HWLK6-BAU_hTeV.js} +1 -1
  57. package/dist/client/assets/{erDiagram-TEJ5UH35-DGua1UHN.js → erDiagram-TEJ5UH35-zr8HrwTt.js} +1 -1
  58. package/dist/client/assets/{flowDiagram-I6XJVG4X-UDfDtwsE.js → flowDiagram-I6XJVG4X-CrTw0iFw.js} +1 -1
  59. package/dist/client/assets/{folder-open-CteOypVk.js → folder-open-DnAlsXXn.js} +1 -1
  60. package/dist/client/assets/{ganttDiagram-6RSMTGT7-COdmD328.js → ganttDiagram-6RSMTGT7-CCORsxxz.js} +1 -1
  61. package/dist/client/assets/{gitGraphDiagram-PVQCEYII-SUSls7Kw.js → gitGraphDiagram-PVQCEYII-C07wWSjj.js} +1 -1
  62. package/dist/client/assets/index-B_z7OKl4.js +2818 -0
  63. package/dist/client/assets/index-DPo-IAb2.css +1 -0
  64. package/dist/client/assets/{infoDiagram-5YYISTIA-e_DloXj7.js → infoDiagram-5YYISTIA-hAeccD_4.js} +1 -1
  65. package/dist/client/assets/{ishikawaDiagram-YF4QCWOH-DVWqihXg.js → ishikawaDiagram-YF4QCWOH-WLCzv-NH.js} +1 -1
  66. package/dist/client/assets/{journeyDiagram-JHISSGLW-BcPY-XP0.js → journeyDiagram-JHISSGLW-ClnasNhy.js} +1 -1
  67. package/dist/client/assets/{kanban-definition-UN3LZRKU-BCFG2Jle.js → kanban-definition-UN3LZRKU-CAuARhUz.js} +1 -1
  68. package/dist/client/assets/{mermaid.core-5yPje9Bi.js → mermaid.core-Bh02RvfX.js} +4 -4
  69. package/dist/client/assets/{mindmap-definition-RKZ34NQL-DDApeT3K.js → mindmap-definition-RKZ34NQL-KNTlbW4V.js} +1 -1
  70. package/dist/client/assets/{pieDiagram-4H26LBE5-N61_jyeP.js → pieDiagram-4H26LBE5-BouAfBEw.js} +1 -1
  71. package/dist/client/assets/{puzzle-BkaCP30D.js → puzzle-CC8Ur3Cy.js} +1 -1
  72. package/dist/client/assets/{quadrantDiagram-W4KKPZXB-C5qHiApF.js → quadrantDiagram-W4KKPZXB-wTdkCUJU.js} +1 -1
  73. package/dist/client/assets/{requirementDiagram-4Y6WPE33-C71okgzt.js → requirementDiagram-4Y6WPE33-BnjY4Tc_.js} +1 -1
  74. package/dist/client/assets/{sankeyDiagram-5OEKKPKP-B2iKyLjB.js → sankeyDiagram-5OEKKPKP-C-QsS08u.js} +1 -1
  75. package/dist/client/assets/{sequenceDiagram-3UESZ5HK-DfdoYKKk.js → sequenceDiagram-3UESZ5HK-DD36MILE.js} +1 -1
  76. package/dist/client/assets/{shield-alert-BNSeDB8l.js → shield-alert-DcXc56Fy.js} +1 -1
  77. package/dist/client/assets/{standing-instructions-template-pZtzo1lK.js → standing-instructions-template-BF5y1BLz.js} +1 -1
  78. package/dist/client/assets/{stateDiagram-AJRCARHV-lS-sUi12.js → stateDiagram-AJRCARHV-WTq1wQr1.js} +1 -1
  79. package/dist/client/assets/{stateDiagram-v2-BHNVJYJU-DXJNDrV9.js → stateDiagram-v2-BHNVJYJU-eILJdjII.js} +1 -1
  80. package/dist/client/assets/{timeline-definition-PNZ67QCA-CCwvX81K.js → timeline-definition-PNZ67QCA-PRNwI0NR.js} +1 -1
  81. package/dist/client/assets/{upload-CDovVbu2.js → upload-qH_64O-B.js} +1 -1
  82. package/dist/client/assets/{useDiscoveredSkillsCache-BYqP-afh.js → useDiscoveredSkillsCache-C-GPCNaO.js} +1 -1
  83. package/dist/client/assets/{users-CTqECGLo.js → users-D2UesRE4.js} +1 -1
  84. package/dist/client/assets/{vennDiagram-CIIHVFJN-DaiR5nv9.js → vennDiagram-CIIHVFJN-CG2Z4T4O.js} +1 -1
  85. package/dist/client/assets/{wardley-L42UT6IY-hA5IHyPW.js → wardley-L42UT6IY-gO_fGvF9.js} +1 -1
  86. package/dist/client/assets/{wardleyDiagram-YWT4CUSO-CILUNESc.js → wardleyDiagram-YWT4CUSO-BkyNpjUb.js} +1 -1
  87. package/dist/client/assets/{xychartDiagram-2RQKCTM6-72eNMmjz.js → xychartDiagram-2RQKCTM6-CMlZsiPq.js} +1 -1
  88. package/dist/client/index.html +2 -2
  89. package/dist/client/version.json +1 -1
  90. package/dist/droid-cli/package.json +1 -1
  91. package/dist/extension.js +345 -61
  92. package/dist/pi-claude-cli/package.json +1 -1
  93. package/dist/plugin-sdk/index.js +29 -2
  94. package/dist/plugins/fusion-plugin-acp-runtime/bundled.js +269 -16
  95. package/dist/plugins/fusion-plugin-acp-runtime/mcp-schema-server.cjs +171 -0
  96. package/dist/plugins/fusion-plugin-acp-runtime/package.json +1 -1
  97. package/dist/plugins/fusion-plugin-claude-runtime/bundled.js +29 -2
  98. package/dist/plugins/fusion-plugin-claude-runtime/package.json +1 -1
  99. package/dist/plugins/fusion-plugin-cli-printing-press/bundled.js +29 -2
  100. package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
  101. package/dist/plugins/fusion-plugin-compound-engineering/bundled.js +29 -2
  102. package/dist/plugins/fusion-plugin-compound-engineering/package.json +1 -1
  103. package/dist/plugins/fusion-plugin-cursor-runtime/bundled.js +29 -2
  104. package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
  105. package/dist/plugins/fusion-plugin-dependency-graph/bundled.js +29 -2
  106. package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
  107. package/dist/plugins/fusion-plugin-droid-runtime/bundled.js +29 -2
  108. package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
  109. package/dist/plugins/fusion-plugin-grok-runtime/bundled.js +29 -2
  110. package/dist/plugins/fusion-plugin-grok-runtime/package.json +1 -1
  111. package/dist/plugins/fusion-plugin-hermes-runtime/bundled.js +29 -2
  112. package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
  113. package/dist/plugins/fusion-plugin-linear-import/bundled.js +29 -2
  114. package/dist/plugins/fusion-plugin-linear-import/package.json +1 -1
  115. package/dist/plugins/fusion-plugin-omp-runtime/bundled.js +29 -2
  116. package/dist/plugins/fusion-plugin-omp-runtime/package.json +1 -1
  117. package/dist/plugins/fusion-plugin-openclaw-runtime/bundled.js +29 -2
  118. package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
  119. package/dist/plugins/fusion-plugin-paperclip-runtime/bundled.js +29 -2
  120. package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
  121. package/dist/plugins/fusion-plugin-quality/bundled.js +29 -2
  122. package/dist/plugins/fusion-plugin-quality/package.json +1 -1
  123. package/dist/plugins/fusion-plugin-reports/bundled.js +29 -2
  124. package/dist/plugins/fusion-plugin-reports/package.json +1 -1
  125. package/dist/plugins/fusion-plugin-roadmap/bundled.js +29 -2
  126. package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
  127. package/dist/plugins/fusion-plugin-todos/bundled.js +29 -2
  128. package/dist/plugins/fusion-plugin-todos/package.json +1 -1
  129. package/dist/plugins/fusion-plugin-whatsapp-chat/bundled.js +29 -2
  130. package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
  131. package/package.json +1 -1
  132. package/dist/client/assets/ChatView-BPSm2JIH.js +0 -13
  133. package/dist/client/assets/channel-DlCEMoEf.js +0 -1
  134. package/dist/client/assets/classDiagram-4FO5ZUOK-Bc92O8Ks.js +0 -1
  135. package/dist/client/assets/classDiagram-v2-Q7XG4LA2-Bc92O8Ks.js +0 -1
  136. package/dist/client/assets/dashboard-view-BnGe8cWo.js +0 -1
  137. package/dist/client/assets/index-0ovTXt3t.css +0 -1
  138. package/dist/client/assets/index-DpCHwyiD.js +0 -2818
@@ -0,0 +1,13 @@
1
+ import{r as a,j as t}from"./vendor-react-SZ_qB27O.js";import{c as si,S as mn,r as jt,e as Rs,cJ as js,du as Xi,dv as qi,dw as da,b as J,dx as Gi,dy as Dt,dz as At,dA as ya,dB as Qi,dC as Yi,dD as Ji,dE as Zi,dF as eo,dG as to,bh as no,c_ as Ca,dH as Ce,db as ao,cv as ii,c3 as wn,dI as so,dJ as io,ar as yn,dK as oo,dL as ro,bS as co,K as lo,aK as uo,b3 as xn,a2 as mo,d9 as ho,dM as fo,aY as go,dN as po,dO as oi,dP as ri,dQ as vo,dR as bo,W as xo,dS as wo,dT as yo,dU as As,dV as Co,dW as ko,dX as Ts,G as So,dY as Mo,z as No,B as Ro,aI as jo,dZ as ua,C as hn,d_ as fn,d$ as Es,cW as Ds,D as ma,P as pt,V as Ao,bU as Is,de as Ls,dd as To,X as Ps,aJ as Eo,e0 as Do,F as ha,e1 as fa,e2 as Fs,e3 as ga,e4 as $s,e5 as _s,e6 as zs,e7 as Io,dj as ci,e8 as Lo,cV as Bs}from"./index-B_z7OKl4.js";import{u as _e}from"./vendor-i18n-Duky4gdQ.js";import{SessionTerminal as Os}from"./SessionTerminal-BjGcxq22.js";import{u as Po}from"./useDiscoveredSkillsCache-C-GPCNaO.js";import"./vendor-codemirror-CcrtqoCy.js";import"./vendor-reactflow-BlIeoTu4.js";import"./vendor-xterm-BNq00GSj.js";import"./shield-alert-DcXc56Fy.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 Fo=[["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"}]],li=si("hash",Fo);/**
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 $o=[["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"}]],_o=si("tag",$o);function gn(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function zo(){try{typeof import.meta<"u"}catch{}try{if(typeof localStorage<"u")return localStorage.getItem("kb-debug-room-open")==="1"}catch{}return!1}function pa(i,r){const h=zo(),p=r?.warm===!0,m=gn(),f=new Map;let N=!1,k=!1;return{mark(D){N||k||!h||f.has(D)||f.set(D,gn())},complete:D=>{if(!h||N||k){N=!0;return}N=!0,f.set("complete",gn());const I=Array.from(f.entries()).sort((R,M)=>R[1]-M[1]);let S=m;const s={};for(const[R,M]of I)s[R]=Math.max(0,M-S),S=M;const v=Math.max(0,gn()-m);try{console.debug("[room-open]",{roomId:i,warm:p,totalMs:v,phases:s,...D??{}})}catch{}},cancel(){k=!0,N=!0}}}const $e="fusion:chat-active-room";class di extends Error{roomId;constructor(r,h){super(r),this.name="RoomMessageDeliveredButReplyFailedError",this.roomId=h}}function ka(i){return[...i].sort((r,h)=>new Date(h.updatedAt).getTime()-new Date(r.updatedAt).getTime())}function Ge(i,r){const h=i.findIndex(m=>m.id===r.id);if(h===-1)return ka([r,...i]);const p=[...i];return p[h]=r,ka(p)}function Ie(i){try{return JSON.parse(i.data)}catch{return null}}function va(i){return i.slice().reverse()}function Bo(i,r,h){return{id:`temp-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,roomId:i,role:"user",content:r,thinkingOutput:null,metadata:null,senderAgentId:null,mentions:[],...h?.length?{attachments:h}:{},createdAt:new Date().toISOString()}}function Hs(i,r,h){if(i.some(m=>m.id===r.id))return i;const p=h?i.findIndex(m=>m.id===h):-1;if(p>=0){const m=[...i];return m[p]=r,m}if(r.role==="user"){const m=i.findIndex(f=>f.role==="user"&&f.id.startsWith("temp-")&&f.content.trim()===r.content.trim());if(m>=0){const f=[...i];return f[m]=r,f}}return[...i,r]}function Oo(i,r){const{t:h}=_e("app"),p=`${mn.CHAT_ROOMS}:${i??"global"}`,m=`${mn.ACTIVE_CHAT_ROOM_ID}:${i??"global"}`,f=a.useCallback(c=>`${mn.CHAT_ROOM_MESSAGES_PREFIX}${i??"global"}:${c}`,[i]),N=a.useCallback(c=>`${mn.CHAT_ROOM_MEMBERS_PREFIX}${i??"global"}:${c}`,[i]),[k,b]=a.useState(()=>{const c=jt(p,{maxAgeMs:Rs});return Array.isArray(c)?c:[]}),[D,I]=a.useState(()=>k.length===0),[S,s]=a.useState(null),[v,R]=a.useState(()=>{const c=jt(m,{maxAgeMs:js});return c?k.find(C=>C.id===c)??null:null}),[M,y]=a.useState([]),[l,P]=a.useState([]),[$,U]=a.useState(!1),z=a.useRef(k),j=a.useRef(v),G=a.useRef(0),ne=a.useRef(i);z.current=k,j.current=v,ne.current!==i&&(ne.current=i,G.current+=1);const Z=a.useCallback(async c=>{if(!c){y([]),P([]),U(!1);return}const C=pa(c.id,{warm:!1});C.mark("select");const g=jt(f(c.id),{maxAgeMs:Xi}),u=jt(N(c.id),{maxAgeMs:Rs}),A=Array.isArray(g)&&g.length>0,L=Array.isArray(u)&&u.length>0;A||L?(C.mark("cache-hit"),A&&(P(g),C.mark("hydrate")),L&&y(u),U(!1)):(P([]),U(!0));try{const[V,ve]=await Promise.all([qi(c.id,i),da(c.id,{limit:100,order:"desc"},i)]);C.mark("members-fetch"),C.mark("messages-fetch"),J(N(c.id),V.members,{maxBytes:5e5});const ae=va(ve.messages);J(f(c.id),ae,{maxBytes:5e5}),j.current?.id===c.id&&(y(V.members),P(ae),C.mark("hydrate"))}catch{!A&&!L&&(y([]),P([]))}finally{U(!1),C.complete({warm:A,membersCached:L})}},[N,f,i]),T=a.useCallback(async()=>{z.current.length===0&&I(!0);try{const c=await Gi({},i),C=ka(c.rooms);b(C),J(p,C,{maxBytes:5e5}),s(null);const g=jt(m,{maxAgeMs:js})??Dt($e,i);if(g){const u=C.find(A=>A.id===g)??null;u?(R(u),Z(u)):(At($e,i),J(m,"",{maxBytes:5e5}))}}catch(c){const C=c instanceof Error?c.message:h("chatRooms.error.failedToLoad","Failed to load chat rooms");s(C),r?.(C,"error")}finally{I(!1)}},[m,r,Z,i,p]),O=a.useCallback(c=>{if(!c){j.current=null,R(null),At($e,i),J(m,"",{maxBytes:5e5}),Z(null);return}const C=z.current.find(g=>g.id===c)??null;j.current=C,R(C),C&&(ya($e,C.id,i),J(m,C.id,{maxBytes:5e5}),Z(C))},[m,Z,i]),ee=a.useCallback(async c=>{const g=(await Qi({name:c.name,memberAgentIds:c.memberAgentIds},i)).room;return b(u=>Ge(u,g)),j.current=g,R(g),ya($e,g.id,i),J(m,g.id,{maxBytes:5e5}),await Z(g),g},[m,Z,i]),W=a.useCallback(async(c,C)=>{const u=(await Yi(c,C,i)).room;return b(A=>Ge(A,u)),j.current?.id===u.id&&(j.current=u,R(u)),u},[i]),E=a.useCallback(async c=>{await Ji(c,i),b(C=>C.filter(g=>g.id!==c)),J(f(c),[],{maxBytes:5e5}),J(N(c),[],{maxBytes:5e5}),j.current?.id===c&&(j.current=null,R(null),y([]),P([]),At($e,i),J(m,"",{maxBytes:5e5}))},[m,N,f,i]),B=a.useCallback(async(c,C)=>{const g=j.current,u=g?.id;if(!u)throw new Error(h("chatRooms.error.selectRoomFirst","Select a room before sending a message"));const A=pa(u,{warm:!1}),L=C?.files?.map(ae=>({id:`upload-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,filename:ae.name,originalName:ae.name,mimeType:ae.type||"application/octet-stream",size:ae.size,createdAt:new Date().toISOString()})),V=Bo(u,c,L?.length?L:C?.attachments);j.current?.id===u&&P(ae=>{const he=[...ae,V];return J(f(u),he,{maxBytes:5e5}),he});let ve=!1;try{const ae=[];if(C?.files?.length)for(const fe of C.files)try{const ze=await Zi(u,fe,i);ae.push(ze.attachment)}catch{throw new Error(h("chatRooms.error.failedToUpload","Failed to upload attachment: {{filename}}",{filename:fe.name}))}const he=[...C?.attachments??[],...ae],ke=await eo(u,{content:c,...he.length?{attachments:he}:{}},i);ve=!0;try{C?.onDelivered?.()}catch{}ke.message?.createdAt&&g&&b(fe=>Ge(fe,{...g,updatedAt:ke.message.createdAt})),j.current?.id===u&&P(fe=>{const ze=Hs(fe,ke.message,V.id);return J(f(u),ze,{maxBytes:5e5}),ze});const re=await da(u,{limit:100,order:"desc"},i),Le=va(re.messages);if(J(f(u),Le,{maxBytes:5e5}),j.current?.id!==u)return;P(Le),A.mark("hydrate")}catch(ae){let he=null;try{const re=await da(u,{limit:100,order:"desc"},i);he=va(re.messages),J(f(u),he,{maxBytes:5e5}),j.current?.id===u&&(P(he),A.mark("hydrate"))}catch{!ve&&j.current?.id===u&&P(re=>{const Le=re.filter(fe=>fe.id!==V.id);return J(f(u),Le,{maxBytes:5e5}),Le})}const ke=he?.some(re=>re.role==="user"&&re.content.trim()===V.content.trim());if(ve||ke){const re=ae instanceof Error&&ae.message.trim()?ae.message:h("chatRooms.error.deliveredButRefreshFailed","Message delivered, but failed to refresh room replies");throw new di(re,u)}throw ae}finally{A.complete({source:"send-room-message"})}},[f,i]),oe=a.useCallback(async c=>{!c||!z.current.some(C=>C.id===c)||(await to(c,i),J(f(c),[],{maxBytes:5e5}),j.current?.id===c&&P([]))},[f,i]);return a.useEffect(()=>{T()},[T]),a.useEffect(()=>{const c=G.current,C=i?`/api/events?projectId=${encodeURIComponent(i)}`:"/api/events";return no(C,{onReconnect:()=>{Ca({view:"useChatRooms",trigger:"sse-reconnect",projectId:i,replayAttempted:!1});const g=j.current?.id;if(g){const u=pa(g,{warm:!0});u.mark("sse-reconnect-refresh"),T().finally(()=>u.complete({source:"sse-reconnect"}));return}T()},events:{"chat:room:created":g=>{if(G.current!==c)return;const u=Ie(g);u&&b(A=>Ge(A,u))},"chat:room:updated":g=>{if(G.current!==c)return;const u=Ie(g);u&&(b(A=>Ge(A,u)),j.current?.id===u.id&&(j.current=u,R(u)))},"chat:room:deleted":g=>{if(G.current!==c)return;const u=Ie(g);u?.id&&(b(A=>A.filter(L=>L.id!==u.id)),J(f(u.id),[],{maxBytes:5e5}),J(N(u.id),[],{maxBytes:5e5}),j.current?.id===u.id&&(j.current=null,R(null),y([]),P([]),At($e,i),J(m,"",{maxBytes:5e5})))},"chat:room:member:added":g=>{if(G.current!==c)return;const u=Ie(g);!u||j.current?.id!==u.roomId||y(A=>{if(A.some(V=>V.agentId===u.agentId))return A;const L=[...A,u];return J(N(u.roomId),L,{maxBytes:5e5}),L})},"chat:room:member:removed":g=>{if(G.current!==c)return;const u=Ie(g);!u||j.current?.id!==u.roomId||y(A=>{const L=A.filter(V=>V.agentId!==u.agentId);return J(N(u.roomId),L,{maxBytes:5e5}),L})},"chat:room:message:added":g=>{if(G.current!==c)return;const u=Ie(g);u&&(b(A=>{const L=A.find(V=>V.id===u.roomId);return L?Ge(A,{...L,updatedAt:u.createdAt}):A}),j.current?.id===u.roomId&&P(A=>{const L=Hs(A,u);return L===A?A:(J(f(u.roomId),L,{maxBytes:5e5}),L)}))},"chat:room:message:updated":g=>{if(G.current!==c)return;const u=Ie(g);!u||j.current?.id!==u.roomId||P(A=>{const L=A.map(V=>V.id===u.id?u:V);return J(f(u.roomId),L,{maxBytes:5e5}),L})},"chat:room:message:deleted":g=>{if(G.current!==c)return;const u=Ie(g);u?.id&&P(A=>{const L=A.filter(ve=>ve.id!==u.id),V=j.current?.id;return V&&J(f(V),L,{maxBytes:5e5}),L})},"chat:room:messages:cleared":g=>{if(G.current!==c)return;const u=Ie(g);u?.roomId&&(J(f(u.roomId),[],{maxBytes:5e5}),j.current?.id===u.roomId&&P([]),b(A=>{const L=A.find(V=>V.id===u.roomId);return L?Ge(A,{...L,updatedAt:new Date().toISOString()}):A}))}}})},[m,N,f,i,T]),a.useEffect(()=>{v&&(k.some(c=>c.id===v.id)||(j.current=null,R(null),y([]),P([]),At($e,i),J(m,"",{maxBytes:5e5})))},[v,m,i,k]),{rooms:k,roomsLoading:D,roomsError:S,activeRoom:v,activeRoomMembers:M,messages:l,messagesLoading:$,selectRoom:O,createRoom:ee,updateRoomSettings:W,deleteRoom:E,sendRoomMessage:B,clearRoom:oe,refreshRooms:T}}const Tt={direct:"fusion:chat-unread:direct",room:"fusion:chat-unread:rooms"},Us=200;function Sa(i){if(!i)return null;const r=new Date(i).getTime();return Number.isFinite(r)?r:null}function ui(i){const r=Object.entries(i);if(r.length<=Us)return i;const h=r.map(([p,m])=>({id:p,timestamp:m,value:Sa(m)??0})).sort((p,m)=>m.value-p.value).slice(0,Us);return Object.fromEntries(h.map(({id:p,timestamp:m})=>[p,m]))}function pn(i){if(!i)return{};try{const r=JSON.parse(i);if(!r||typeof r!="object")return{};const h={};for(const[p,m]of Object.entries(r))typeof p=="string"&&typeof m=="string"&&(h[p]=m);return ui(h)}catch{return{}}}function Ho(i){const[r,h]=a.useState(()=>{try{return pn(Dt(Tt.direct,i))}catch{return{}}}),[p,m]=a.useState(()=>{try{return pn(Dt(Tt.room,i))}catch{return{}}});a.useEffect(()=>{try{h(pn(Dt(Tt.direct,i)))}catch{h({})}try{m(pn(Dt(Tt.room,i)))}catch{m({})}},[i]);const f=a.useMemo(()=>({direct:r,room:p}),[r,p]),N=a.useCallback((S,s)=>{const v=ui(s);try{ya(Tt[S],JSON.stringify(v),i)}catch{}return v},[i]),k=a.useCallback((S,s)=>{if(S==="direct"){h(v=>N(S,s(v)));return}m(v=>N(S,s(v)))},[N]),b=a.useCallback((S,s,v)=>{const R=Sa(v);if(R===null)return!1;const M=f[S][s],y=Sa(M);return y===null?!0:R>y},[f]),D=a.useCallback((S,s,v)=>{if(!s)return;const R=v??new Date().toISOString();k(S,M=>({...M,[s]:R}))},[k]),I=a.useCallback((S,s)=>{s.length!==0&&k(S,v=>{const R={...v};for(const M of s)M.id&&(R[M.id]=M.lastActivityAt??new Date().toISOString());return R})},[k]);return{isUnread:b,markRead:D,markAllRead:I}}const Uo=["",...so];function Ks({level:i,onChange:r,defaultThinkingLevel:h="off",showTargetSection:p=!0,models:m=[],favoriteProviders:f=[],favoriteModels:N=[],agents:k=[],agentId:b,modelProvider:D,modelId:I,onChangeModel:S,disabled:s=!1}){const{t:v}=_e("app"),[R,M]=a.useState(!1),[y,l]=a.useState(()=>b&&b!==Ce?"agent":"model"),P=a.useRef(null),$=i??"",U=D&&I?`${D}/${I}`:"",z=b&&b!==Ce?b:"",j=$!==""||p&&(!!U||!!z),G="chat-thinking-level-listbox";a.useEffect(()=>{if(!R)return;const c=C=>{const g=C.target;if(!(g instanceof Node))return;!P.current?.contains(g)&&!io(g)&&M(!1)};return document.addEventListener("pointerdown",c),document.addEventListener("touchstart",c),()=>{document.removeEventListener("pointerdown",c),document.removeEventListener("touchstart",c)}},[R]),a.useEffect(()=>{M(!1),l(z?"agent":"model")},[$,z,U]);const ne=a.useMemo(()=>k.find(c=>c.id===z),[k,z]),Z=c=>c===""?v("modelSelection.thinkingDefault","Default ({{level}})",{level:h??"off"}):v(`models.options.${c}`,c==="xhigh"?"Very High":c.charAt(0).toUpperCase()+c.slice(1)),T=c=>{M(!1),r(c)},O=c=>{const C=c.indexOf("/");C<=0||(M(!1),S?.({modelProvider:c.slice(0,C),modelId:c.slice(C+1)}))},ee=c=>{c&&(M(!1),S?.({agentId:c}))},W=c=>{l(c)},E=c=>{c.key==="Escape"&&M(!1)},B=(c,C)=>{if(c.key==="Escape"){c.preventDefault(),M(!1);return}(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),T(C))},oe=(c,C)=>{if(c.key==="Escape"){c.preventDefault(),M(!1);return}(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),ee(C))};return t.jsxs("div",{className:"chat-thinking-level-root",ref:P,children:[t.jsx("button",{type:"button",className:`btn-icon chat-thinking-btn${j?" chat-thinking-btn--active":""}`,"data-testid":"chat-thinking-btn","aria-haspopup":"dialog","aria-expanded":R,"aria-controls":G,"aria-label":v("chat.thinkingLevelButton","Thinking level"),title:v("chat.thinkingLevelButton","Thinking level"),disabled:s,onClick:()=>M(c=>!c),onKeyDown:E,children:t.jsx(ao,{size:16})}),R?t.jsxs("div",{className:"chat-thinking-popover",role:"presentation","data-testid":"chat-thinking-popover",children:[p?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${y==="model"?" chat-thinking-mode-btn--active":""}`,"data-testid":"chat-thinking-mode-model","aria-pressed":y==="model",onPointerDown:c=>{c.button===0&&W("model")},onClick:c=>{c.detail===0&&W("model")},children:v("chat.newChatModeModel","Model")}),t.jsx("button",{type:"button",className:`chat-thinking-mode-btn${y==="agent"?" chat-thinking-mode-btn--active":""}`,"data-testid":"chat-thinking-mode-agent","aria-pressed":y==="agent",onPointerDown:c=>{c.button===0&&W("agent")},onClick:c=>{c.detail===0&&W("agent")},children:v("chat.newChatModeAgent","Agent")})]}),y==="model"?t.jsxs("div",{className:"chat-thinking-model-picker","data-testid":"chat-thinking-model-picker",children:[t.jsx(ii,{models:m,value:U,onChange:O,label:v("chat.newChatModeModel","Model"),placeholder:v("chat.selectModel","Select a model"),disabled:!S||m.length===0,favoriteProviders:f,favoriteModels:N,menuWidth:"readable"}),m.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:k.length===0?t.jsx("div",{className:"chat-thinking-empty","data-testid":"chat-thinking-agent-empty",children:v("chat.noAgentsAvailable","No agents available")}):k.map(c=>{const C=z===c.id;return t.jsxs("button",{type:"button",className:`chat-thinking-agent-item${C?" chat-thinking-agent-item--selected":""}`,"data-testid":`chat-thinking-agent-${c.id}`,"aria-pressed":C,disabled:!S,onClick:()=>ee(c.id),onKeyDown:g=>oe(g,c.id),children:[t.jsx(wn,{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)})}),ne?t.jsx("div",{className:"chat-thinking-current-target","data-testid":"chat-thinking-current-agent",children:v("chat.currentAgentTarget","Current agent: {{name}}",{name:ne.name||ne.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:G,className:"chat-thinking-popover-list",role:"listbox","aria-label":v("chat.thinkingLevelButton","Thinking level"),children:Uo.map(c=>{const C=$===c;return t.jsx("button",{type:"button",role:"option","aria-selected":C,className:`chat-thinking-popover-option${C?" active":""}`,"data-testid":`chat-thinking-option-${c||"default"}`,onClick:()=>T(c),onKeyDown:g=>B(g,c),children:Z(c)},c||"default")})})]})]}):null]})}function Ws(i){return i.trim().toLowerCase().replace(/[\s-]+/g,"_").replace(/_+/g,"_")}function mi(i,r){const h=r.trim();if(!h)return!0;const p=Ws(h);return Ws(i).includes(p)||i.toLowerCase().includes(h.toLowerCase())}function Vs({agents:i,filter:r,highlightedIndex:h,visible:p,onSelect:m,position:f="below",roomMemberIds:N,roomName:k}){const{t:b}=_e("app"),D=a.useMemo(()=>i.filter(M=>mi(M.name,r)),[i,r]),I=!!N,S=I&&r.trim().length>0,s=a.useMemo(()=>I?D.filter(M=>N?.has(M.id)):D,[D,N,I]),v=a.useMemo(()=>I?D.filter(M=>!N?.has(M.id)):[],[D,N,I]),R=S?[...s,...v]:s;return p?t.jsx("div",{className:`agent-mention-popup agent-mention-popup--${f}`,"data-testid":"agent-mention-popup",role:"listbox","aria-label":b("agentMention.suggestionsLabel","Agent mention suggestions"),children:R.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:k?b("agentMention.membersOf","Members of #{{roomName}}",{roomName:k}):b("agentMention.roomMembers","Room members")}),s.map((M,y)=>t.jsxs("button",{type:"button",className:`agent-mention-item${y===h?" agent-mention-item--highlighted":""}`,"data-testid":`agent-mention-item-${M.id}`,onMouseDown:l=>l.preventDefault(),onClick:()=>m(M),role:"option","aria-selected":y===h,children:[t.jsx(yn,{agent:M,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:M.name}),t.jsx("span",{className:"agent-mention-role",children:M.role})]},M.id)),I&&!S&&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&&S&&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((M,y)=>{const l=s.length+y;return t.jsxs("button",{type:"button",className:`agent-mention-item${l===h?" agent-mention-item--highlighted":""}`,"data-testid":`agent-mention-item-${M.id}`,onMouseDown:P=>P.preventDefault(),onClick:()=>m(M),role:"option","aria-selected":l===h,children:[t.jsx(yn,{agent:M,size:20}),t.jsx("span",{className:"agent-mention-name",children:M.name}),t.jsx("span",{className:"agent-mention-role",children:M.role})]},M.id)})]})]})}):null}function Ko(i,r){return i+r}function Wo({visible:i,position:r,tasks:h,files:p,selectedIndex:m,onSelectTask:f,onSelectFile:N,loading:k}){const{t:b}=_e("app");if(!i)return null;const D=h.length>0,I=p.length>0;return t.jsxs("div",{className:"file-mention-popup",style:{top:r.top,left:r.left},"data-testid":"file-mention-popup",onMouseDown:S=>{S.preventDefault()},children:[k&&t.jsx("div",{className:"file-mention-popup-loading","data-testid":"file-mention-loading",children:t.jsx("span",{className:"spinner"})}),!k&&!D&&!I&&t.jsx("div",{className:"file-mention-popup-empty","data-testid":"file-mention-empty",children:b("fileMention.empty","No tasks or files found")}),!k&&(D||I)&&t.jsxs("div",{className:"file-mention-popup-groups",children:[D&&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:h.map((S,s)=>{const v=s;return t.jsxs("li",{className:`file-mention-popup-item${v===m?" file-mention-popup-item--selected":""}`,onClick:()=>f(S),role:"option","aria-selected":v===m,"data-testid":`task-mention-item-${v}`,children:[t.jsx("span",{className:"file-mention-popup-icon",children:t.jsx(li,{})}),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:S.id}),t.jsx("span",{className:`file-mention-popup-column-badge file-mention-popup-column-badge--${S.column}`,children:S.column})]}),t.jsx("span",{className:"file-mention-popup-item-path",children:S.title})]})]},S.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:p.map((S,s)=>{const v=Ko(h.length,s),R=oo(S.path);return t.jsxs("li",{className:`file-mention-popup-item${v===m?" file-mention-popup-item--selected":""}`,onClick:()=>N(S),role:"option","aria-selected":v===m,"data-testid":`file-mention-item-${v}`,children:[t.jsx("span",{className:"file-mention-popup-icon",children:t.jsx(ro,{})}),t.jsxs("div",{className:"file-mention-popup-info",children:[t.jsx("span",{className:"file-mention-popup-item-name",children:S.name}),R&&t.jsx("span",{className:"file-mention-popup-item-path",children:R})]})]},S.path)})})]})]})]})}function Vo(i,r=[],h){const p=i.trim().replace(/^#/,""),m=(N,k)=>h?h(N,k):k;if(!p)return{ok:!1,error:m("createRoom.nameRequired","Room name is required.")};if(/[A-Z]/.test(p))return{ok:!1,error:m("createRoom.lowercase","Use lowercase letters only.")};const f=p.toLowerCase();return f.length>80?{ok:!1,error:m("createRoom.maxLength","Room names can be at most 80 characters.")}:/^[a-z0-9_-]+$/.test(f)?/^[-_]|[-_]$/.test(f)?{ok:!1,error:m("createRoom.noEdgeChars","Room names cannot start or end with a hyphen or underscore.")}:r.some(N=>N.toLowerCase()===f)?{ok:!1,error:m("createRoom.duplicate","A room with this name already exists.")}:{ok:!0,name:f}:{ok:!1,error:m("createRoom.validChars","Use lowercase letters, numbers, hyphens, or underscores only.")}}function Xo({isOpen:i,onClose:r,onCreate:h,projectId:p,existingRoomNames:m=[]}){const{t:f}=_e("app"),[N,k]=a.useState(""),[b,D]=a.useState([]),[I,S]=a.useState(""),[s,v]=a.useState([]),[R,M]=a.useState("idle"),[y,l]=a.useState(null),[P,$]=a.useState(!1),U=a.useRef(null),z=a.useRef(null),j=a.useRef(null),G=a.useRef(0);a.useEffect(()=>{const E=++G.current;if(!i)return;j.current=document.activeElement instanceof HTMLElement?document.activeElement:null,D([]),M("loading"),l(null);let B=!1;const oe=()=>!B&&G.current===E;return co(void 0,p).then(c=>{oe()&&(D(c),v(C=>C.filter(g=>c.some(u=>u.id===g))),M("loaded"))}).catch(()=>{oe()&&(D([]),M("failed"))}),()=>{B=!0,++G.current}},[i,p]),a.useEffect(()=>{if(!i){k(""),S(""),v([]),D([]),M("idle"),l(null),$(!1);return}const E=window.requestAnimationFrame(()=>{const B=document.activeElement;B instanceof HTMLElement&&z.current?.contains(B)||U.current?.focus()});return()=>window.cancelAnimationFrame(E)},[i]),a.useEffect(()=>{if(!i)return;const E=B=>{B.key==="Escape"&&r()};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[i,r]),a.useEffect(()=>{i||j.current?.focus()},[i]);const ne=a.useMemo(()=>Vo(N,m,f),[N,m,f]),Z=a.useMemo(()=>{const E=I.trim().toLowerCase();return E?b.filter(B=>B.name.toLowerCase().includes(E)):b},[b,I]),T=a.useMemo(()=>b.filter(E=>s.includes(E.id)),[b,s]),O=ne.ok&&s.length>0&&!P&&R==="loaded";if(!i)return null;const ee=E=>{P||v(B=>B.includes(E)?B.filter(oe=>oe!==E):[...B,E])},W=async()=>{if(!ne.ok){l(ne.error);return}if(s.length===0){l(f("createRoom.selectMember","Select at least one member."));return}l(null),$(!0);try{await h({name:ne.name,displayName:`#${ne.name}`,memberAgentIds:s}),r()}catch(E){l(E instanceof Error?E.message:f("createRoom.failedCreate","Failed to create room."))}finally{$(!1)}};return t.jsx(lo,{windowKey:"create-room",title:f("createRoom.title","Create room"),ariaLabel:f("createRoom.title","Create room"),onClose:r,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",{ref:z,className:"modal create-room-modal",children:[t.jsxs("div",{className:"modal-header",children:[t.jsx("h3",{children:f("createRoom.title","Create room")}),t.jsx("button",{type:"button",className:"modal-close","aria-label":f("actions.close","Close"),onClick:r,children:"×"})]}),t.jsxs("div",{className:"form-group create-room-modal-name-group",children:[t.jsx("label",{htmlFor:"create-room-name",children:f("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:N,disabled:P,onChange:E=>{const B=E.target.value.replace(/^#/,"").replace(/\s+/g,"-").toLowerCase();k(B)}})]}),!ne.ok&&t.jsx("div",{className:"form-error",children:ne.error})]}),t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"create-room-member-search",children:f("createRoom.members","Members")}),t.jsx("input",{id:"create-room-member-search",className:"input",placeholder:f("createRoom.searchAgents","Search agents"),value:I,disabled:P,onChange:E=>S(E.target.value)})]}),T.length>0&&t.jsx("div",{className:"create-room-modal-selected","data-testid":"create-room-selected-chips",children:T.map(E=>t.jsxs("button",{type:"button",className:"btn btn-sm create-room-modal-chip",onClick:()=>ee(E.id),disabled:P,children:[E.name," ×"]},E.id))}),t.jsx("div",{className:"create-room-modal-member-list","data-testid":"create-room-member-list",children:R==="idle"||R==="loading"?t.jsx("div",{className:"create-room-modal-empty",children:t.jsx(uo,{label:f("createRoom.loadingAgents","Loading agents...")})}):R==="failed"?t.jsx("div",{className:"create-room-modal-empty",children:f("createRoom.failedLoadAgents","Failed to load agents.")}):Z.length===0?t.jsx("div",{className:"create-room-modal-empty",children:b.length===0?f("createRoom.noAgents","No agents in this project yet."):f("createRoom.noMatch","No agents match your search.")}):Z.map(E=>{const B=s.includes(E.id);return t.jsxs("button",{type:"button",className:`create-room-modal-member-row${B?" create-room-modal-member-row--selected":""}`,onClick:()=>ee(E.id),disabled:P,children:[t.jsx(yn,{agent:E,size:20}),t.jsx("span",{children:E.name}),t.jsx("span",{className:"create-room-modal-member-role",children:E.role})]},E.id)})}),y&&t.jsx("div",{className:"form-group",children:t.jsx("div",{className:"form-error",children:y})}),t.jsxs("div",{className:"modal-actions",children:[t.jsx("button",{type:"button",className:"btn",onClick:r,disabled:P,children:f("actions.cancel","Cancel")}),t.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void W(),disabled:!O,children:P?f("createRoom.creating","Creating..."):f("createRoom.create","Create room")})]})]})})}function qo({cliSessionId:i,tier:r,projectId:h,renderTranscript:p,renderComposer:m,queuedCount:f=0,terminalProps:N}){const{t:k}=_e("app"),b=r==="generic",[D,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(Os,{sessionId:i,projectId:h,...N})});const S=D==="terminal";return t.jsxs("div",{className:"cli-chat-surface","data-tier":r,"data-view":D,children:[t.jsxs("div",{className:"cli-chat-surface__toolbar",role:"tablist","aria-label":k("cliChat.viewToggleLabel","Chat view"),children:[t.jsxs("button",{type:"button",role:"tab","aria-selected":!S,className:`cli-chat-surface__tab${S?"":" is-active"}`,onClick:()=>I("transcript"),children:[t.jsx(xn,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:k("cliChat.transcriptTab","Transcript")})]}),t.jsxs("button",{type:"button",role:"tab","aria-selected":S,className:`cli-chat-surface__tab${S?" is-active":""}`,onClick:()=>I("terminal"),children:[t.jsx(mo,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:k("cliChat.terminalTab","Terminal")})]})]}),t.jsx("div",{className:"cli-chat-surface__body",children:S?t.jsx(Os,{sessionId:i,projectId:h,...N}):p()}),!S&&t.jsxs("div",{className:"cli-chat-surface__composer",children:[f>0&&t.jsx("div",{className:"cli-chat-surface__queued",role:"status","aria-live":"polite",children:k("cliChat.queued","{{count}} message queued — will send when the agent is ready",{count:f})}),m()]})]})}const Go=200,Qo=8,Yo=8;function Xs(){return new DOMException("The operation was aborted.","AbortError")}function qs(i,r){return r.aborted?Promise.reject(Xs()):new Promise((h,p)=>{const m=()=>p(Xs());r.addEventListener("abort",m,{once:!0}),i.then(f=>{r.removeEventListener("abort",m),h(f)},f=>{r.removeEventListener("abort",m),p(f)})})}function Gs(i,r,h){const p=i.slice(0,r),m=i.slice(r+1),f=m.match(/[\s]|$/),N=f?f.index??m.length:m.length,k=m.slice(N);return`${p}${h}${k}`}function Jo(i={}){const{projectId:r,workspace:h="project"}=i,[p,m]=a.useState(!1),[f,N]=a.useState(""),[k,b]=a.useState(-1),[D,I]=a.useState([]),[S,s]=a.useState([]),[v,R]=a.useState(!1),[M,y]=a.useState(0),l=a.useRef(null),P=a.useRef(null),$=[...D.map(T=>({kind:"task",task:T})),...S.map(T=>({kind:"file",file:T}))];a.useEffect(()=>()=>{l.current&&clearTimeout(l.current),P.current?.abort()},[]);const U=a.useCallback((T,O)=>{if(O<0||O>T.length){m(!1);return}const ee=W=>/[a-zA-Z0-9/_.-]/.test(W);for(let W=O-1;W>=0;W--){if(T[W]==="#"){if(W===0){const B=T.slice(W+1,O);b(W),N(B),y(0),m(!0);return}const E=T[W-1];if(/[\s,.;:!?'"()[\]{}]/.test(E)){const B=T.slice(W+1,O);b(W),N(B),y(0),m(!0);return}m(!1);return}if(!ee(T[W])){m(!1);return}}m(!1)},[]),z=a.useCallback(()=>{P.current?.abort(),m(!1),N(""),b(-1),I([]),s([]),y(0),R(!1)},[]),j=a.useCallback(async T=>{if(!T.trim()){I([]),s([]),R(!1);return}P.current?.abort();const O=new AbortController;P.current=O;try{R(!0);const[ee,W]=await Promise.allSettled([qs(ho(20,0,r,T),O.signal),qs(fo(T,h,r),O.signal)]);if(O.signal.aborted)return;const E=ee.status==="fulfilled"?ee.value.slice(0,Qo).map(oe=>({id:oe.id,title:oe.title??"",column:oe.column})):[],B=W.status==="fulfilled"?W.value.files.slice(0,Yo):[];I(E),s(B),y(0)}catch(ee){ee.name!=="AbortError"&&(I([]),s([]))}finally{O.signal.aborted||R(!1)}},[h,r]);a.useEffect(()=>{if(p)return l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{j(f)},Go),()=>{l.current&&clearTimeout(l.current)}},[f,p,j]);const G=a.useCallback((T,O)=>!p||k<0?O:Gs(O,k,`#${T.id}`),[p,k]),ne=a.useCallback((T,O)=>!p||k<0?O:Gs(O,k,`#${T.path}`),[p,k]),Z=a.useCallback((T,O)=>{if(!p||$.length===0)return!1;switch(T.key){case"ArrowDown":return T.preventDefault(),y(ee=>Math.min(ee+1,$.length-1)),!0;case"ArrowUp":return T.preventDefault(),y(ee=>Math.max(ee-1,0)),!0;case"Enter":case"Tab":return $[M]?(T.preventDefault(),!0):!1;case"Escape":return T.preventDefault(),z(),!0;default:return!1}},[p,$,M,z]);return{mentionActive:p,tasks:D,files:S,combinedItems:$,loading:v,mentionQuery:f,selectedIndex:M,setSelectedIndex:y,detectMention:U,selectTask:G,selectFile:ne,dismissMention:z,handleKeyDown:Z}}function Zo(i,r){const h=i.reduce((p,m)=>p+(m.content?.length??0),0)+(r?.length??0);return Math.ceil(h/4)}function Qs(i){if(!Number.isFinite(i)||i<=0)return"0";if(i<1e3)return String(Math.round(i));const r=i/1e3;return r<10?`~${Number(r.toFixed(1))}k`:`${Math.round(r)}k`}const Ma=640,er=200,tr=200,vt=8;function yr(i){const r=i.trim();return r?`${r}
12
+
13
+ `:""}function nr(i,r,h,p,m,f,N){const k=Math.max(vt,f-p-vt),b=Math.max(vt,N-m-vt),D=h?i-p:i;return{x:Math.min(Math.max(vt,D),k),y:Math.min(Math.max(vt,r),b)}}const Ys="__SKIP__";let ba=!1;function ar(i,r=Ma){return i>r?"auto":"hidden"}function sr(i,r=Ma){return Math.max(40,Math.min(i,r))}function ir(i,r){const h=new Date(i),m=new Date().getTime()-h.getTime(),f=Math.floor(m/1e3),N=Math.floor(f/60),k=Math.floor(N/60),b=Math.floor(k/24);return f<60?r("chat.relativeTimeJustNow","just now"):N<60?r("chat.relativeTimeMinutes","{{count}}m ago",{count:N}):k<24?r("chat.relativeTimeHours","{{count}}h ago",{count:k}):b<7?r("chat.relativeTimeDays","{{count}}d ago",{count:b}):h.toLocaleDateString()}const or=280,vn=180,bn=500,Js="fusion:chat-sidebar-width",xa="fusion:chat-scope",rr="fusion:chat-draft:";function Zs(i,r){return i.slice(r+1).find(h=>h.role==="user")?.content}function ei(i,r){return r?`${rr}${i}:${r}`:null}function ti(i){if(!i)return"";try{return localStorage.getItem(i)??""}catch{return""}}const cr=["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"],ni="image/png,image/jpeg,image/gif,image/webp,video/mp4,video/webm,video/quicktime,.txt,.md,.json,.yaml,.yml,.toml,.csv,.xml",wa=Io;function lr(i,r){const h=i.slice(0,r),p=/(^|[\s\n])@([\w-]*)$/.exec(h);if(!p)return null;const m=p[2]??"",f=h.length-m.length-1;return{filter:m,start:f,end:r}}function dr(i){const r=i?.runtimeConfig;if(!r||typeof r!="object")return null;const h=Reflect.get(r,"modelProvider"),p=Reflect.get(r,"modelId");return typeof h!="string"||h.trim().length===0||typeof p!="string"||p.trim().length===0?null:{provider:h,modelId:p}}function ai(i,r,h){if(i?.modelProvider&&i?.modelId)return{provider:i.modelProvider,modelId:i.modelId};const p=dr(r??void 0);return p||(h.provider&&h.modelId?{provider:h.provider,modelId:h.modelId}:null)}function ur({projectId:i,defaultModel:r,defaultKind:h,defaultAgentId:p,defaultThinkingLevel:m,defaultSelectedThinkingLevel:f,onClose:N,onCreate:k}){const{t:b}=_e("app"),[D,I]=a.useState(h??"agent"),{agents:S,loading:s}=oi(i),[v,R]=a.useState(p??""),{models:M,favoriteProviders:y,favoriteModels:l,loading:P,refresh:$}=ri(),U=r.provider&&r.modelId?`${r.provider}/${r.modelId}`:"",[z,j]=a.useState(U),[G,ne]=a.useState(f??""),[Z,T]=a.useState(y),[O,ee]=a.useState(l);a.useEffect(()=>{T(y)},[y]),a.useEffect(()=>{ee(l)},[l]),a.useEffect(()=>{h&&I(h)},[h]),a.useEffect(()=>{p&&R(g=>g||p)},[p]),a.useEffect(()=>{U&&j(g=>g||U)},[U]),a.useEffect(()=>{f&&ne(g=>g||f)},[f]);const W=a.useCallback(async g=>{const u=Z,L=u.includes(g)?u.filter(V=>V!==g):[g,...u];T(L);try{await Bs({favoriteProviders:L,favoriteModels:O}),await $()}catch{T(u)}},[Z,O,$]),E=a.useCallback(async g=>{const u=O,L=u.includes(g)?u.filter(V=>V!==g):[g,...u];ee(L);try{await Bs({favoriteProviders:Z,favoriteModels:L}),await $()}catch{ee(u)}},[O,Z,$]),B=z||U,oe=g=>{if(g.preventDefault(),D==="agent"){if(!v)return;k({agentId:v});return}if(!B)return;const u=B.indexOf("/");if(u<=0)return;const A=B.slice(0,u),L=B.slice(u+1);k({agentId:Ce,modelProvider:A,modelId:L,thinkingLevel:G||void 0})},c=D==="agent"?!v:!B,C=ci(N,{enabled:!0});return t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",...C,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:g=>g.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${D==="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${D==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{I("model"),R(""),j(g=>g||U)},children:b("chat.newChatModeModel","Model")})]}),t.jsxs("form",{onSubmit:oe,children:[D==="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...")}):S.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:S.map(g=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${v===g.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>R(g.id),"data-testid":`agent-option-${g.id}`,children:[t.jsx(wn,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:g.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:g.role})]},g.id))})]}),D==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:P?t.jsx("div",{className:"chat-new-dialog-loading",children:b("chat.loadingModels","Loading models...")}):t.jsx(ii,{models:M,value:z,onChange:j,label:b("chat.newChatModeModel","Model"),placeholder:b("chat.selectModel","Select a model"),favoriteProviders:Z,onToggleFavorite:W,favoriteModels:O,onToggleModelFavorite:E,showThinkingLevel:!0,thinkingLevel:G,onThinkingLevelChange:ne,defaultThinkingLevel:m??"off"})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:N,children:b("chat.cancel","Cancel")}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:c,children:b("chat.create","Create")})]})]})]})})}function Et({children:i,onClose:r}){const h=ci(r,{enabled:!0});return t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",...h,children:i})}function Cr({projectId:i,addToast:r,floating:h=!1,compactLayout:p=!1,onPopOut:m,onMaximize:f,onMinimize:N,onClose:k,chatCommandContext:b,initialComposerDraft:D,initialComposerDraftNonce:I,onSendAsReport:S}){const{t:s}=_e("app");a.useEffect(()=>(Ca({view:"ChatView",trigger:ba?"route-active":"remount",projectId:i,replayAttempted:!1}),ba=!1,()=>{ba=!0,Ca({view:"ChatView",trigger:"route-inactive",projectId:i,replayAttempted:!1})}),[i]);const[v,R]=a.useState(null);a.useEffect(()=>{let e=!1;return R(null),go(i).then(n=>{e||R(n)}).catch(()=>{e||R(null)}),()=>{e=!0}},[i]);const M=v?.defaultThinkingLevel??"off",y=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:P,messages:$,messagesLoading:U,isStreaming:z,streamingText:j,streamingThinking:G,streamingToolCalls:ne,selectSession:Z,createSession:T,archiveSession:O,archivedSessions:ee,refreshArchivedSessions:W,unarchiveSession:E,renameSession:B,pinSession:oe,pinnedCount:c,setSessionModel:C,setSessionThinkingLevel:g,deleteSession:u,tags:A=[],selectedTagId:L,setSelectedTagId:V,createTag:ve,renameTag:ae,deleteTag:he,setSessionTags:ke,sendMessage:re,editMessageAndResend:Le,stopStreaming:fe,pendingMessages:ze,clearPendingMessage:Cn,loadMoreMessages:Na,hasMoreMessages:kn,searchQuery:hi,setSearchQuery:fi,filteredSessions:Be,agentsMap:Sn}=po(i,r),[gi,Mn]=a.useState(!1),Oe=!0,[F,Qe]=a.useState(()=>{try{if(localStorage.getItem(xa)==="rooms"&&Oe)return"rooms"}catch{}return"direct"}),w=Oo(i,r),{isUnread:Ra,markRead:ue}=Ho(i),[Q,ce]=a.useState(()=>{const e=ei(F,F==="rooms"?w.activeRoom?.id:l?.id);return ti(e)}),[Y,Se]=a.useState(null),[Ye,pi]=a.useState(!1),Nn=a.useRef(null),ja=(e,n,o,d)=>{typeof window>"u"||Se({sessionId:e,anchorX:n,anchorY:o,anchorRight:d?.anchorRight??!1,x:n,y:o})};a.useLayoutEffect(()=>{if(!Y||!Nn.current||typeof window>"u")return;const e=Nn.current,n=e.getBoundingClientRect(),o=n.width||e.offsetWidth||tr,d=n.height||e.offsetHeight,x=nr(Y.anchorX,Y.anchorY,Y.anchorRight,o,d,window.innerWidth,window.innerHeight);(x.x!==Y.x||x.y!==Y.y)&&Se({...Y,...x})},[Y]);const[It,Lt]=a.useState(null),[Rn,jn]=a.useState(""),[Aa,Pt]=a.useState(null),[Ta,Ft]=a.useState(null),[An,Ea]=a.useState(""),[Tn,bt]=a.useState(null),[En,Da]=a.useState(""),[Ia,$t]=a.useState(null),[xt,He]=a.useState(!0),[Je,Dn]=a.useState(or),[vi,_t]=a.useState(!1),{agentsMap:La}=oi(i),be=a.useMemo(()=>Sn.size>0?Sn:La,[La,Sn]),{models:In,favoriteProviders:bi,favoriteModels:xi,defaultProvider:Pa,defaultModelId:Fa}=ri(),zt=a.useMemo(()=>({provider:Pa,modelId:Fa}),[Fa,Pa]),wi=a.useMemo(()=>y?.kind==="model"?{provider:y.modelProvider,modelId:y.modelId}:zt,[y,zt]),{skills:Ln,loading:yi}=Po(i),[Ze,Ue]=a.useState(!1),[wt,yt]=a.useState(""),[et,Ke]=a.useState(0),[tt,nt]=a.useState(""),[Me,at]=a.useState(!1),[Bt,Ot]=a.useState(0),[Pn,st]=a.useState(-1),[ge,Ht]=a.useState([]),[$a,it]=a.useState(!1),[_a,Ut]=a.useState(!1),[ot,za]=a.useState({}),[Kt,Ne]=a.useState(!1),[Wt,Ct]=a.useState(!1),{pushNav:Ba}=vo(),[,Vt]=a.useState(!1),[Ci,ki]=a.useState({top:0,left:0}),X=Jo({projectId:i}),Fn=a.useCallback(e=>{if(!e||!X.mentionActive)return;const n=e.getBoundingClientRect();ki({top:n.top-260,left:n.left+8})},[X.mentionActive]),Oa=a.useRef(null),Ha=a.useRef(null),Ua=a.useRef(null),Ka=a.useRef(null),de=a.useRef(!1),Xt=a.useRef(null),Wa=a.useRef(null),Pe=a.useRef(null),qt=a.useRef(0),$n=a.useRef(null),kt=a.useRef(null),Re=a.useRef(null),le=a.useRef(null),_n=a.useRef(null),rt=a.useRef(null),[zn,Si]=a.useState(()=>new Set),Gt=a.useRef(!1),je=a.useRef(null),Ae=a.useRef(null),te=a.useRef(null),Qt=a.useRef(null),Va=a.useRef(void 0),Bn=a.useRef(!1),Yt=a.useRef(null),Xa=a.useRef([]),ct=a.useRef(0),St=a.useRef(new Map),On=a.useRef(!1),Jt=bo(),We=Jt==="mobile",Hn=Jt==="tablet",qa=a.useRef(null),[Mi,Ga]=a.useState(!1);a.useLayoutEffect(()=>{if(!h){Ga(!1);return}const e=qa.current;if(!e||typeof ResizeObserver>"u")return;const n=()=>{Ga(e.getBoundingClientRect().width<=768)};n();const o=new ResizeObserver(n);return o.observe(e),()=>o.disconnect()},[h]);const H=We||Mi||p;a.useEffect(()=>{l?.id&&ue("direct",l.id,l.lastMessageAt??l.updatedAt)},[l?.id,l?.lastMessageAt,l?.updatedAt,ue]),a.useEffect(()=>{w.activeRoom?.id&&ue("room",w.activeRoom.id,w.activeRoom.updatedAt)},[w.activeRoom?.id,w.activeRoom?.updatedAt,ue]),a.useEffect(()=>{if(!l?.id||$.length===0)return;const e=$[$.length-1];ue("direct",l.id,e?.createdAt??l.lastMessageAt??l.updatedAt)},[l?.id,l?.lastMessageAt,l?.updatedAt,ue,$]),a.useEffect(()=>{if(!w.activeRoom?.id||w.messages.length===0)return;const e=w.messages[w.messages.length-1];ue("room",w.activeRoom.id,e?.createdAt??w.activeRoom.updatedAt)},[ue,w.activeRoom?.id,w.activeRoom?.updatedAt,w.messages]),a.useEffect(()=>{try{const e=localStorage.getItem(Js);if(!e)return;const n=Number.parseInt(e,10);if(Number.isNaN(n))return;const o=Math.max(vn,Math.min(bn,n));Dn(o)}catch{}},[]),a.useEffect(()=>{try{const e=localStorage.getItem(xa);if(e==="direct"){Qe("direct");return}e==="rooms"&&Oe&&Qe("rooms")}catch{}},[Oe]),a.useEffect(()=>{try{localStorage.setItem(xa,F)}catch{}},[Oe,F]);const me=ei(F,F==="rooms"?w.activeRoom?.id:l?.id),Un=a.useRef(me),Kn=a.useRef(!1);a.useEffect(()=>{if(me!==Un.current){if(Un.current=me,Kn.current){Kn.current=!1;return}ce(ti(me))}},[me]),a.useEffect(()=>{if(!(!me||Un.current!==me))try{if(Q){localStorage.setItem(me,Q);return}localStorage.removeItem(me)}catch{}},[me,Q]);const se=F==="rooms"&&!!w.activeRoom,{keyboardOverlap:Qa,keyboardOpen:Zt}=xo({enabled:(H||Hn)&&(!!l||se),allowNonMobileViewport:Hn}),Mt=Hn&&Zt,en=a.useMemo(()=>{const e=wt.trim().toLowerCase();return(e?Ln.filter(o=>o.name.toLowerCase().includes(e)):Ln).slice(0,10)},[Ln,wt]),Wn=a.useMemo(()=>b?wo(wt,zs):[],[b,wt]),xe=a.useMemo(()=>{const e=Wn.map(o=>({kind:"command",command:o,disabled:!b?.agentRunning})),n=en.map(o=>({kind:"skill",skill:o}));return[...e,...n]},[Wn,en,b]),lt=a.useMemo(()=>Array.from(be.values()),[be]),Te=a.useMemo(()=>F!=="rooms"||!w.activeRoom?null:{roomId:w.activeRoom.id,roomName:w.activeRoom.name,memberIds:new Set(w.activeRoomMembers.map(e=>e.agentId))},[Oe,F,w.activeRoom,w.activeRoomMembers]),Ve=a.useMemo(()=>{const e=lt.filter(d=>mi(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 o=e.filter(d=>!Te.memberIds.has(d.id));return[...n,...o]},[lt,tt,Te]),Vn=a.useMemo(()=>{const e=new Map;for(const n of lt)e.set(n.name.toLowerCase(),n);return e},[lt]),Ni=a.useMemo(()=>en.map(e=>e.id).join("\0"),[en]);a.useEffect(()=>{Ke(0)},[Ni]),a.useEffect(()=>{Ot(0)},[tt,Me]),a.useEffect(()=>()=>{Re.current!==null&&window.clearTimeout(Re.current)},[]),a.useEffect(()=>{const e=Ha.current;if(!e||!kn||U)return;const n=new IntersectionObserver(o=>{o[0].isIntersecting&&Na()},{threshold:.1});return n.observe(e),()=>n.disconnect()},[kn,U,Na]);const dt=a.useCallback(()=>se?w.activeRoom?.id??null:l?.id??null,[se,w.activeRoom?.id,l?.id]),Ya=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,'\\"')}"]`),[]),Ja=a.useCallback(()=>{const e=le.current;if(!e)return;const n=e.getBoundingClientRect().top,o=new Set;e.querySelectorAll(".chat-message--assistant:not(.chat-message--failure)[data-message-id]").forEach(d=>{const x=d.getAttribute("data-message-id");x&&d.getBoundingClientRect().top<n&&o.add(x)}),Si(d=>d.size===o.size&&Array.from(d).every(x=>o.has(x))?d:o)},[]),tn=a.useCallback(()=>{!le.current||rt.current!==null||(rt.current=window.requestAnimationFrame(()=>{rt.current=null,Ja()}))},[Ja]),nn=a.useCallback(()=>{const e=le.current,n=dt();if(!e||!n)return;const o=e.scrollTop,d=e.querySelectorAll(".chat-message[data-message-id]"),x=Array.from(d).find(K=>K.offsetTop+K.offsetHeight>=o)??d[0]??null,_=x?.getAttribute("data-message-id")??null,q=x?x.offsetTop-o:0;kt.current={threadId:n,scrollTop:o,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight,anchorMessageId:_,anchorOffset:q,wasPinnedBefore:!de.current,capturedAtMs:typeof performance<"u"?performance.now():Date.now()}},[dt]),Za=a.useCallback(()=>{const e=le.current;if(!e)return;const o=e.scrollTop+e.clientHeight>=e.scrollHeight-50;Ut(!o),de.current=!o,nn(),tn()},[nn,tn]),Ee=a.useCallback((e,n)=>{if(!e.isConnected||!n?.force&&de.current)return;let o=0,d=0,x=-1;const _=6,q=()=>{if(e.isConnected&&!(!n?.force&&de.current)){if(e.scrollTop=e.scrollHeight,e.scrollHeight===x?d+=1:(d=0,x=e.scrollHeight),o+=1,o>=_||d>=2){Ut(!1),de.current=!1;return}window.requestAnimationFrame(q)}};q()},[]),ut=se?w.messages:$;a.useLayoutEffect(()=>(tn(),()=>{rt.current!==null&&(window.cancelAnimationFrame(rt.current),rt.current=null)}),[ut,tn]),a.useLayoutEffect(()=>{const e=le.current,n=dt(),o=kt.current;if(!e||!n||!o||o.threadId!==n||o.wasPinnedBefore)return;const d=(typeof performance<"u"?performance.now():Date.now())-o.capturedAtMs,x=e.scrollHeight>e.clientHeight,_=d>3e3,q=o.scrollTop<=0&&o.anchorOffset<=0&&x;if(!de.current||_||q){kt.current=null;return}let K=o.scrollTop;if(o.anchorMessageId){const pe=Ya(e,o.anchorMessageId);pe?K=pe.offsetTop-o.anchorOffset:K=o.scrollTop+(e.scrollHeight-o.scrollHeight)}else K=o.scrollTop+(e.scrollHeight-o.scrollHeight);e.scrollTop=Math.max(0,K),de.current=!0,Ut(!0),kt.current=null},[ut,dt,Ya]);const Xn=a.useCallback(e=>{},[ut.length,se]),we=a.useCallback(e=>{Xn(e);const n=le.current;n&&(kt.current=null,de.current=!1,Ee(n))},[Ee,Xn]);a.useLayoutEffect(()=>{Pe.current!==null&&(window.clearTimeout(Pe.current),Pe.current=null);const e=se?w.activeRoom?.id??null:l?.id??null;if(!e){Xt.current=null;return}const n={threadId:e,loaded:se?!w.messagesLoading:!U,hasMessages:se?w.messages.length>0:$.length>0},o=Xt.current,d=o?.threadId!==e,x=o?.threadId===e&&!o.loaded&&n.loaded,_=o?.threadId===e&&!o.hasMessages&&n.hasMessages;if(!(o===null||d||x||_))return;const K=le.current;if(K)return Xn(d?"thread-change":x?"finished-loading":_?"first-messages":"mount"),Ee(K,{force:!0}),se||(Pe.current=window.setTimeout(()=>{if(Pe.current=null,de.current)return;const pe=le.current;pe&&Ee(pe)},250)),Xt.current=n,()=>{Pe.current!==null&&(window.clearTimeout(Pe.current),Pe.current=null)}},[se,w.activeRoom?.id,w.messages.length,w.messagesLoading,l?.id,$.length,U,Ee]),a.useEffect(()=>{!z||de.current||we("streaming")},[z,j,G,we]),a.useEffect(()=>{const e=dt();if(!e){qt.current=0,$n.current=null;return}if($n.current!==e){$n.current=e,qt.current=ut.length;return}const n=qt.current,o=ut.length,d=o>n,x=!de.current;qt.current=o,d&&x&&we("new-message")},[ut,dt,we]),a.useEffect(()=>{Qa<=0||!le.current||we("keyboard")},[Qa,we]),yo(We&&Zt),a.useLayoutEffect(()=>{if(!We||!l&&!se||typeof window>"u")return;const e=_n.current,n=window.visualViewport;if(!e||!n)return;const o=x=>{if(!(x instanceof HTMLElement))return!1;if(x.tagName==="TEXTAREA")return!0;if(x.tagName!=="INPUT")return!1;const _=x.type.toLowerCase();return["","text","search","email","url","tel","password","number"].includes(_)},d=()=>{if(Gt.current){e.classList.remove("chat-thread--keyboard-active"),e.style.setProperty("--chat-keyboard-accessory-clearance","0px"),e.style.transform="",e.style.willChange="";return}const x=Math.max(0,window.innerHeight-n.offsetTop-n.height),_=n.offsetTop||0;e.style.setProperty("--vv-height",`${n.height}px`),e.style.setProperty("--vv-offset-top",`${_}px`),e.style.setProperty("--keyboard-overlap",`${x}px`);const q=(x>0||_>0)&&o(document.activeElement);e.classList.toggle("chat-thread--keyboard-active",q),e.style.setProperty("--chat-keyboard-accessory-clearance",q&&ga()?"calc(var(--space-2xl) + var(--space-md))":"0px"),q&&_>0?(e.style.transform=`translateY(${_}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,We,se]),a.useEffect(()=>{const e=()=>Se(null);if(Y)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[Y]),a.useEffect(()=>{if(!We||!Zt)return;const e=n=>{n.target?.closest(".chat-messages")||n.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>{document.removeEventListener("touchmove",e)}},[We,Zt]),a.useEffect(()=>{const e=Wa.current;if(Wa.current=F,F==="rooms"&&!w.activeRoom){Xt.current=null;return}if(!(F==="direct"&&(e===null||e==="rooms"))&&!(F==="rooms"&&(e===null||e==="direct")))return;const d=le.current;d&&(Ee(d,{force:!0}),de.current=!1,Ut(!1))},[F,w.activeRoom,Ee]),a.useEffect(()=>{if(!l&&!se||se&&!H)return;const e=()=>{const o=!de.current;nn(),o&&H&&le.current&&we("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,We,l,se,nn,we]),a.useEffect(()=>{if(se||typeof ResizeObserver>"u")return;const e=le.current;if(!e)return;const n=new ResizeObserver(()=>{de.current||Ee(e)});return n.observe(e),()=>{n.disconnect()}},[se,Ee,l?.id,F]),a.useEffect(()=>{Xa.current=ge},[ge]),a.useEffect(()=>()=>{for(const e of Xa.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);for(const e of St.current.values())window.clearTimeout(e);St.current.clear()},[]);const mt=a.useCallback(e=>{if(!e||e.length===0)return;const n=[];for(const o of Array.from(e)){if(!cr.includes(o.type))continue;const d=o.type.startsWith("image/");n.push({file:o,previewUrl:d?URL.createObjectURL(o):""})}n.length>0&&Ht(o=>[...o,...n])},[]),es=a.useCallback(e=>{Ht(n=>{const o=n[e];return o?.previewUrl&&URL.revokeObjectURL(o.previewUrl),n.filter((d,x)=>x!==e)})},[]),ts=a.useCallback(e=>{mt(e.clipboardData?.files)},[mt]),ht=a.useCallback(async e=>{try{return await T(e),Mn(!1),H&&He(!1),!0}catch{return r(s("chat.failedToCreateSession","Failed to create chat session"),"error"),!1}},[T,r,H,s]),an=a.useCallback(()=>{if(v?.chatNewSessionMode==="always-default"&&y){if(y.kind==="agent"){ht({agentId:y.agentId});return}ht({agentId:Ce,modelProvider:y.modelProvider,modelId:y.modelId,thinkingLevel:y.thinkingLevel});return}Mn(!0)},[y,v?.chatNewSessionMode,ht]),ie=a.useCallback(e=>{const n=e??te.current;if(!n)return;const o=Jt==="tablet"?er:Ma;n.style.height="auto",n.style.height=`${sr(n.scrollHeight,o)}px`,n.style.overflowY=ar(n.scrollHeight,o)},[Jt]),Ri=As({textareaRef:te,value:Q,onChange:ce,onResize:()=>ie(te.current),projectId:i}),ji=As({textareaRef:Qt,value:Q,onChange:ce,onResize:()=>ie(Qt.current),projectId:i}),Ai=a.useCallback(e=>{te.current=e,e&&ie(e)},[ie]),Ti=a.useCallback(e=>{Qt.current=e,e&&ie(e)},[ie]);a.useLayoutEffect(()=>{ie(F==="rooms"?Qt.current:te.current),Bn.current&&(Bn.current=!1,te.current?.focus())},[F,Q,l?.id,w.activeRoom?.id,ie]),a.useEffect(()=>{if(I===void 0||I===Va.current||!D?.trim())return;Va.current=I;const e=n=>{n&&(Kn.current=!0),Qe("direct"),Bn.current=!0,ce(D)};if(!z&&v?.chatNewSessionMode==="always-default"&&y){const n=y.kind==="agent"?{agentId:y.agentId}:{agentId:Ce,modelProvider:y.modelProvider,modelId:y.modelId,thinkingLevel:y.thinkingLevel};ht(n).then(o=>e(o||F!=="direct"));return}e(F!=="direct")},[y,F,v?.chatNewSessionMode,ht,D,I,z,ie]);const ft=a.useCallback(()=>{if(ce(""),me)try{localStorage.removeItem(me)}catch{}Ue(!1),yt(""),at(!1),nt(""),st(-1),Ht(e=>{for(const n of e)n.previewUrl&&URL.revokeObjectURL(n.previewUrl);return[]})},[me]),Xe=a.useCallback(e=>{Ht(n=>{const o=n.filter(d=>e.has(d.file));for(const d of o)d.previewUrl&&URL.revokeObjectURL(d.previewUrl);return n.filter(d=>!e.has(d.file))})},[]),qn=a.useCallback(()=>{const e=Q.trim(),n=ge.map(d=>d.file);if(!e&&n.length===0||!l)return;if(b){const d=Co(e,zs);if(d){if(!b.agentRunning){r(s("chat.commandNoRunningAgent","No running agent to steer"),"warning");return}if(n.length>0){r(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(()=>{r(s("chat.commandSteerSuccess","Sent to the running agent"),"success")}).catch(x=>{const _=x instanceof Error&&x.message.trim()?x.message:s("chat.commandSteerFailed","Failed to send to the running agent");r(_,"error")});return}}if(e==="/clear"||e==="/new"){if(n.length>0){r(s("chat.clearNoAttachments","Remove the attachments before running /clear or /new — they would be discarded unsent"),"warning");return}if(l.agentId.startsWith(ko)){ft(),r(s("chat.newNotAllowedForTaskChat","This chat is tied to a task — /new and /clear can't clear it"),"warning");return}ft(),Cn(),fe(),T({agentId:l.agentId,modelProvider:l.modelProvider??void 0,modelId:l.modelId??void 0,thinkingLevel:l.thinkingLevel??void 0}).catch(()=>{r(s("chat.failedToClearConversation","Failed to clear conversation"),"error")});return}if(z&&n.length>0){r(s("chat.attachmentsNotQueued","Attachments can't be queued while a reply is streaming — wait for it to finish"),"warning");return}const o=new Set(n);ce("");try{re(e,n,{onAccepted:()=>Xe(o),onDelivered:()=>Xe(o),onFailed:()=>{ce(d=>d||e)}})}catch{ce(e)}},[Q,ge,l,ft,fe,Cn,T,r,re,b,z,Xe,s]),Gn=a.useCallback(async()=>{const e=Q.trim(),n=ge.map(o=>o.file);if(!(!e&&n.length===0)){if(F==="rooms"){if(!w.activeRoom)return;if(e==="/clear"||e==="/new"){if(n.length>0){r(s("chat.clearNoAttachments","Remove the attachments before running /clear or /new — they would be discarded unsent"),"warning");return}ft();try{await w.clearRoom(w.activeRoom.id)}catch{r(s("chat.failedToClearRoomConversation","Failed to clear room conversation"),"error")}return}if(On.current)return;On.current=!0;const o=Q,d=new Set(n);ce("");try{await w.sendRoomMessage(e,{files:n,onDelivered:()=>Xe(d)}),Xe(d)}catch(x){if(x instanceof di){Xe(d);const q=x.message.trim()?x.message:s("chat.messageSentButReplyFailed","Message sent, but assistant reply failed");r(s("chat.messageSentButReplyFailedDetail","Message sent, but assistant reply failed: {{detail}}",{detail:q}),"error");return}ce(o);const _=x instanceof Error&&x.message.trim()?x.message:s("chat.failedToSendRoomMessage","Failed to send room message");r(_,"error")}finally{On.current=!1}return}qn()}},[Q,ge,Oe,F,w,w.clearRoom,ft,r,qn,Xe]),sn=a.useCallback(async e=>{if(F==="rooms"){if(!w.activeRoom)return;try{await w.sendRoomMessage(e)}catch(n){const o=n instanceof Error&&n.message.trim()?n.message:s("chat.failedToSendRoomMessage","Failed to send room message");r(o,"error")}return}l&&re(e)},[l,r,Oe,F,w,re,s]),Qn=a.useCallback(e=>{ce(n=>{const o=wa(n);if(!o)return n;const d=`/skill:${e.name} `,x=n.slice(0,o.start)+d+n.slice(o.end);return window.requestAnimationFrame(()=>{te.current&&(ie(te.current),te.current.focus())}),x}),Ue(!1),yt(""),Ke(0)},[ie]),Yn=a.useCallback((e,n)=>{if(n){r(s("chat.commandNoRunningAgent","No running agent to steer"),"warning");return}ce(o=>{const d=wa(o);if(!d)return o;const x=`${e.trigger} `,_=o.slice(0,d.start)+x+o.slice(d.end);return window.requestAnimationFrame(()=>{te.current&&(ie(te.current),te.current.focus())}),_}),Ue(!1),yt(""),Ke(0)},[ie,r,s]),on=a.useCallback(e=>{const n=te.current;if(!n||Pn<0)return;const o=n.selectionStart??ct.current,d=n.selectionEnd??o,x=Math.max(o,d),_=Math.min(Pn,x),K=`${`@${e.name.replace(/\s+/g,"_")}`} `,pe=Q.slice(0,_)+K+Q.slice(x),gt=_+K.length;ce(pe),at(!1),nt(""),Ot(0),st(-1),window.requestAnimationFrame(()=>{te.current&&(ie(te.current),te.current.focus(),te.current.setSelectionRange(gt,gt))})},[Pn,Q,ie]),Nt=a.useCallback((e,n)=>{const d=te.current?.selectionStart??ct.current,x=Q.lastIndexOf("#",d),_=x>=0?x+n.length:e.length;ce(e),X.dismissMention(),Vt(!1),window.requestAnimationFrame(()=>{te.current&&(ie(te.current),te.current.focus(),te.current.setSelectionRange(_,_))})},[X,Q,ie]),ns=a.useCallback(e=>{if(ct.current=e.currentTarget.selectionStart??ct.current,X.mentionActive&&X.combinedItems.length>0){if(X.handleKeyDown(e,Q),e.key==="Enter"||e.key==="Tab"){const n=X.combinedItems[X.selectedIndex];n?.kind==="task"?Nt(X.selectTask(n.task,Q),`#${n.task.id}`):n?.kind==="file"&&Nt(X.selectFile(n.file,Q),`#${n.file.path}`)}return}if(Me&&e.key==="ArrowDown"){e.preventDefault(),Ve.length>0&&Ot(n=>(n+1)%Ve.length);return}if(Me&&e.key==="ArrowUp"){e.preventDefault(),Ve.length>0&&Ot(n=>n===0?Ve.length-1:n-1);return}if(Me&&e.key==="Enter"){e.preventDefault();const n=Ve[Bt]??Ve[0];n&&on(n);return}if(Me&&e.key==="Escape"){e.preventDefault(),at(!1),nt(""),st(-1);return}if(Ze&&e.key==="ArrowDown"){e.preventDefault(),xe.length>0&&Ke(n=>(n+1)%xe.length);return}if(Ze&&e.key==="ArrowUp"){e.preventDefault(),xe.length>0&&Ke(n=>n===0?xe.length-1:n-1);return}if(Ze&&(e.key==="Enter"||e.key==="Tab")&&xe.length>0){e.preventDefault();const n=xe[et]??xe[0];n?.kind==="skill"?Qn(n.skill):n?.kind==="command"&&Yn(n.command,n.disabled);return}if(Ze&&e.key==="Escape"){e.preventDefault(),Ue(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Gn())},[Me,Ve,Bt,on,Ze,xe,et,Qn,Yn,Gn,X,Nt,Q]),rn=a.useCallback((e,n)=>{const o=lr(e,n);if(o){at(!0),nt(o.filter),st(o.start);return}at(!1),nt(""),st(-1)},[]),as=a.useCallback(e=>{const n=e.target,o=n.value,d=n.selectionStart??o.length;ie(n),ct.current=d,ce(o);const x=wa(o);x?(Ue(!0),yt(x.filter)):(Ue(!1),yt("")),rn(o,d),X.detectMention(o,d),Vt(X.mentionActive),X.mentionActive&&Fn(n)},[rn,ie]),cn=a.useCallback(e=>{const n=e.currentTarget,o=n.selectionStart??n.value.length;ct.current=o,rn(n.value,o),X.detectMention(n.value,o),Vt(X.mentionActive),X.mentionActive&&Fn(n)},[rn,X,Fn]),ss=a.useCallback(e=>{e.key!=="Escape"&&cn(e)},[cn]),is=a.useCallback(()=>{typeof window<"u"&&window.innerWidth<=768&&(Gt.current=!0,je.current!==null&&window.clearTimeout(je.current),je.current=window.setTimeout(()=>{Gt.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),Vt(!1),X.dismissMention(),Re.current=null},120)},[X]),os=a.useCallback(()=>{Gt.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 rs=a.useCallback(async e=>{Se(null);try{await O(e),r(s("chat.conversationArchived","Conversation archived"),"success")}catch{r(s("chat.failedToArchiveConversation","Failed to archive conversation"),"error")}},[O,r]),Ei=a.useCallback(async e=>{try{await E(e),r(s("chat.conversationRestored","Conversation restored"),"success")}catch{r(s("chat.failedToRestoreConversation","Failed to restore conversation"),"error")}},[E,r,s]),cs=a.useCallback(e=>{const n=Be.find(o=>o.id===e)??(l?.id===e?l:null);Se(null),Ne(!1),jn(n?.title??""),Lt({sessionId:e,title:n?.title??""})},[l,Be]),ls=a.useCallback(async()=>{if(It)try{await B(It.sessionId,Rn),Lt(null),jn(""),r(s("chat.conversationRenamed","Conversation renamed"),"success")}catch{}},[r,It,B,Rn,s]),ds=a.useCallback(async(e,n)=>{Se(null),Ne(!1);try{await oe(e,n),r(n?s("chat.conversationPinned","Conversation pinned"):s("chat.conversationUnpinned","Conversation unpinned"),"success")}catch{}},[r,oe,s]),Di=a.useCallback(async e=>{Pt(null),Se(null);try{await u(e),r(s("chat.conversationDeleted","Conversation deleted"),"success")}catch{r(s("chat.failedToDeleteConversation","Failed to delete conversation"),"error")}},[u,r]),Rt=a.useCallback(e=>{try{localStorage.setItem(Js,String(e))}catch{}},[]),Ii=a.useCallback(e=>{if(H||Mt)return;e.preventDefault(),e.stopPropagation();const n=e.currentTarget;typeof n.setPointerCapture=="function"&&n.setPointerCapture(e.pointerId);const o=e.clientX,d=Je;let x=d;document.body.style.userSelect="none";const _=K=>{const pe=K.clientX-o,gt=Math.max(vn,Math.min(bn,d+pe));x=gt,Dn(gt),Rt(gt)},q=K=>{typeof n.releasePointerCapture=="function"&&n.releasePointerCapture(K.pointerId),document.body.style.userSelect="",document.removeEventListener("pointermove",_),document.removeEventListener("pointerup",q),Rt(x)};document.addEventListener("pointermove",_),document.addEventListener("pointerup",q)},[H,Rt,Je,Mt]),Li=a.useCallback(e=>{if(H||Mt||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;e.preventDefault();const n=e.shiftKey?50:10,o=e.key==="ArrowLeft"?-n:n,d=Math.max(vn,Math.min(bn,Je+o));Dn(d),Rt(d)},[H,Rt,Je,Mt]),us=a.useCallback(e=>{const n=Be.find(o=>o.id===e);ue("direct",e,n?.lastMessageAt??n?.updatedAt),Z(e),Ne(!1),H&&He(!1)},[Be,H,ue,Z]),Jn=a.useCallback(()=>{Z(""),He(!0),Ne(!1)},[Z]),Zn=a.useCallback(()=>{w.selectRoom(null),He(!0),Ne(!1)},[w]),Pi=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(xn,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:s("chat.startNewConversation","Start a new conversation")}),t.jsxs("button",{className:"btn btn-primary",onClick:an,children:[t.jsx(pt,{size:16}),s("chat.newChat","New Chat")]})]}),De=ai(l,l?.agentId?be.get(l.agentId)??null:null,zt),ea=a.useMemo(()=>{if(!De?.provider||!De.modelId)return null;const e=In.find(n=>n.provider===De.provider&&n.id===De.modelId);return e?.contextWindow?e.contextWindow:null},[De?.modelId,De?.provider,In]),Fi=a.useMemo(()=>Zo($,z?j:void 0),[z,$,j]),Fe=Ts(De?.provider,De?.modelId),qe=De?.provider??null,ta=!!(l||z||$.length>0),ln=H&&!xt&&(F==="rooms"?se:ta),dn=H?ln:F==="rooms"?se:!!l,ms=a.useRef(dn);a.useEffect(()=>{const e=ms.current;ms.current=dn,H&&(e||!dn||Ba({type:"view",revert:F==="rooms"?Zn:Jn}))},[F,Jn,Zn,dn,H,Ba]);const hs=l?.agentId===Ce?Fe??"Fusion":l?.title||be.get(l?.agentId??"")?.name||l?.agentId||"Chat",$i=l?.title||s("chat.untitledSession","Untitled"),_i=!!(Fe&&Fe!==hs),zi=!H&&ta&&ea!==null,fs=Qs(Fi),un=ea!==null?Qs(ea):null,na=un?s("chat.contextWindowAria","Estimated {{used}} of {{total}} context tokens",{used:fs,total:un}):null,Bi=ln&&F==="direct"&&!!l,gs=ln&&F==="direct",ps=ln&&F==="rooms",aa=be.get(l?.agentId??"")?.name||(l?.agentId===Ce?Fe??"Fusion":l?.agentId?.slice(0,30)??"Fusion"),sa=!1,ia=l?.agentId===Ce,Oi=e=>e.length>50?`${e.slice(0,50)}…`:e;a.useEffect(()=>{if(!Kt)return;const e=n=>{Ua.current?.contains(n.target)||Ne(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[Kt]),a.useEffect(()=>{if(!Wt)return;const e=o=>{Ka.current?.contains(o.target)||Ct(!1)},n=o=>{o.key==="Escape"&&Ct(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",n)}},[Wt]),a.useEffect(()=>{(!H||F!=="direct"||xt)&&Ne(!1)},[H,F,xt]),a.useEffect(()=>{Ct(!1)},[w.activeRoom?.id]);const vs=a.useCallback((e,n)=>{const o=St.current.get(e);o&&window.clearTimeout(o),za(x=>({...x,[e]:n}));const d=window.setTimeout(()=>{za(x=>{const{[e]:_,...q}=x;return q}),St.current.delete(e)},2e3);St.current.set(e,d)},[]),bs=a.useCallback(async(e,n)=>{const o=await So(n);vs(e,o?"success":"error")},[vs]),oa=l?.agentId===Ce,ra=a.useCallback((e,n,o,d,x=!0)=>{const _=oa&&o==="assistant",q=x&&o==="assistant"&&S?Mo(n,s("chat.reportFallbackTitle","Chat report")):null;if(!(!_&&!q?.handoff))return t.jsxs(t.Fragment,{children:[_&&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:()=>{bs(e,n)},children:ot[e]==="success"?t.jsx(No,{size:14}):t.jsx(Ro,{size:14})}),q?.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:()=>{q.truncated&&r(s("chat.reportTrimmed","Message trimmed to 2000 characters for mail"),"warning"),S?.(q.handoff)},children:t.jsx(jo,{size:14})})]})},[r,ot,bs,S,oa,s]),ca=a.useCallback(e=>{const n=le.current;if(!n)return;const o=`[data-testid="chat-message-${e}"]`,d=n.querySelector(o);if(!d)return;const x=d.getBoundingClientRect().top-n.getBoundingClientRect().top+n.scrollTop,_=typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;n.scrollTo({top:x,behavior:_?"auto":"smooth"})},[]),xs=l?.cliExecutorAdapterId??null,la=!!xs,Hi=xs==="generic"?"generic":"hybrid",Ui=l?.cliSessionFile||l?.id||"",ws=!la&&!z,ys=()=>t.jsxs("div",{className:"chat-messages",ref:le,onScroll:Za,children:[t.jsx("div",{ref:Ha,className:"chat-load-more-sentinel",children:kn&&U&&t.jsx("div",{className:"chat-loading-older",children:s("chat.loadingOlderMessages","Loading older messages…")})}),z?t.jsxs(t.Fragment,{children:[$.map((e,n)=>t.jsx(fa,{message:e,forcePlain:!1,agentName:aa,hideAssistantIdentity:ia,showAssistantModelTag:sa,activeModelTag:Fe,activeModelProvider:qe,activeSessionId:l?.id??null,projectId:i,mentionAgentsByName:Vn,roomContext:null,copyAction:ra(e.id,e.content,e.role),onScrollToTop:ca,isTopClipped:zn.has(e.id),isAwaitingQuestionAnswer:e.role==="assistant"&&n===$.length-1&&!z,submittedQuestionAnswer:Zs($,n),onQuestionSubmit:sn,canEdit:ws,onEditMessage:Le},e.id)),t.jsx(Lo,{streamingText:j,streamingThinking:G,streamingToolCalls:ne,forcePlain:!1,agentName:aa,hideAssistantIdentity:ia,showAssistantModelTag:sa,activeModelTag:Fe,activeModelProvider:qe,copyAction:oa&&j?ra("__streaming__",j,"assistant","chat-copy-response-streaming",!1):void 0,onQuestionSubmit:sn})]}):U?t.jsx("div",{className:"chat-empty-state",children:s("chat.loadingMessages","Loading messages...")}):$.length===0&&!l?Pi():$.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:$.map((e,n)=>t.jsx(fa,{message:e,forcePlain:!1,agentName:aa,hideAssistantIdentity:ia,showAssistantModelTag:sa,activeModelTag:Fe,activeModelProvider:qe,activeSessionId:l?.id??null,projectId:i,mentionAgentsByName:Vn,roomContext:null,copyAction:ra(e.id,e.content,e.role),onScrollToTop:ca,isTopClipped:zn.has(e.id),isAwaitingQuestionAnswer:e.role==="assistant"&&n===$.length-1&&!z,submittedQuestionAnswer:Zs($,n),onQuestionSubmit:sn,canEdit:ws,onEditMessage:Le},e.id))}),t.jsx("div",{ref:Oa})]}),Cs=()=>t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Yt,type:"file","data-testid":"chat-file-input",accept:ni,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:yi&&Wn.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:s("chat.loadingSkills","Loading skills…")}):xe.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:wt?s("chat.noSkillsFound","No skills found"):s("chat.noSkillsAvailable","No skills available")}):xe.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:o=>o.preventDefault(),onMouseEnter:()=>Ke(n),onClick:()=>Yn(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:o=>o.preventDefault(),onMouseEnter:()=>Ke(n),onClick:()=>Qn(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:()=>es(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:Oi(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:()=>Yt.current?.click(),children:t.jsx(Fs,{size:16})}),!la&&t.jsx(Ks,{level:l?.thinkingLevel,defaultThinkingLevel:M,models:In,favoriteProviders:bi,favoriteModels:xi,agents:Array.from(be.values()),agentId:l?.agentId,modelProvider:l?.modelProvider,modelId:l?.modelId,onChange:e=>{l&&g(l.id,e)},onChangeModel:e=>{l&&C(l.id,e)},disabled:!l}),t.jsxs("div",{className:`chat-input-wrapper${$a?" 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:Ai,className:"chat-input-textarea",placeholder:s("chat.typeMessage","Type a message..."),value:Q,onChange:as,onKeyDown:ns,onKeyUp:ss,onClick:cn,onBlur:is,onFocus:os,onPaste:ts,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||ga()&&(document.activeElement,e.currentTarget)},rows:1,"data-testid":"chat-input"}),t.jsx(Vs,{agents:lt,filter:tt,highlightedIndex:Bt,visible:Me,onSelect:on,position:"below",roomMemberIds:Te?.memberIds,roomName:Te?.roomName}),t.jsx(Wo,{visible:X.mentionActive&&!Me,position:Ci,tasks:X.tasks,files:X.files,selectedIndex:X.selectedIndex,onSelectTask:e=>{Nt(X.selectTask(e,Q),`#${e.id}`)},onSelectFile:e=>{Nt(X.selectFile(e,Q),`#${e.path}`)},loading:X.loading})]}),t.jsx($s,{...Ri.micProps}),t.jsx(_s,{isStreaming:z,canSend:!!(Q.trim()||ge.length>0),onSend:qn,onStop:fe})]})]}),Ki=H?void 0:{width:`${Je}px`},ks=Ye?ee:Be,Ss=ks.filter(e=>e.pinnedAt!=null),Ms=ks.filter(e=>e.pinnedAt==null),ye=Y?Be.find(e=>e.id===Y.sessionId)??(l?.id===Y.sessionId?l:void 0):void 0,Ns=a.useCallback(async()=>{const e=An.trim();if(!e)return;let n;try{n=await ve(e)}catch{r(s("chat.failedToCreateTag","Failed to create tag"),"error");return}if(Y?.sessionId){const o=(ye?.tags??[]).map(d=>d.id);if(!o.includes(n.id))try{await ke(Y.sessionId,[...o,n.id])}catch{r(s("chat.failedToUpdateTags","Failed to update tags"),"error");return}}Ea("")},[r,Y,ye,ve,An,ke,s]),Wi=Bi?t.jsxs("div",{className:"chat-mobile-session-menu",ref:Ua,children:[t.jsxs("button",{type:"button",className:"btn chat-mobile-session-trigger","data-testid":"chat-mobile-session-trigger","aria-haspopup":"menu","aria-expanded":Kt,onClick:()=>Ne(e=>!e),children:[qe?t.jsx(ua,{provider:qe,size:"md"}):t.jsx(wn,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:$i}),t.jsx(hn,{size:16,"aria-hidden":"true"})]}),Kt&&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:Ss},{id:"recent",label:s("chat.recent","Recent"),testId:"chat-mobile-recent-divider",sessions:Ms}].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:()=>us(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:()=>ds(n.id,!n.pinnedAt),children:n.pinnedAt?t.jsx(Es,{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 rs(n.id),children:t.jsx(Ds,{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:()=>cs(n.id),children:t.jsx(ma,{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),an()},children:[t.jsx(pt,{size:16,"aria-hidden":"true"}),t.jsx("span",{children:s("chat.newChat","New Chat")})]})]})]}):null,Vi=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${F==="direct"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":F==="direct","data-testid":"chat-sidebar-scope-direct",onClick:()=>Qe("direct"),children:[t.jsx(xn,{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${F==="rooms"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":F==="rooms","data-testid":"chat-sidebar-scope-rooms",onClick:()=>Qe("rooms"),children:[t.jsx(li,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:s("chat.scopeRooms","Rooms")})]})]});return t.jsxs("div",{ref:qa,className:`chat-view${h?" chat-view--floating":""}${H?" chat-view--narrow":""}${gs?" chat-view--mobile-direct-thread":""}`,children:[t.jsx(Ao,{icon:xn,title:s("chat.title","Chat"),actions:t.jsxs(t.Fragment,{children:[gs?t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"btn-icon chat-back-btn",onClick:Jn,"data-testid":"chat-back-btn","aria-label":s("chat.backToConversations","Back to conversations"),children:t.jsx(Is,{size:16})}),Wi]}):Vi,H?null:t.jsxs("button",{className:"btn btn-sm btn-primary chat-view-header-new-chat",onClick:an,"data-testid":"chat-new-btn",children:[t.jsx(pt,{size:14}),s("chat.newChat","New Chat")]}),!h&&m?t.jsx("button",{type:"button",className:"btn-icon chat-view-header-icon",onClick:m,"aria-label":s("chat.popOut","Pop out chat"),title:s("chat.popOut","Pop out chat"),"data-testid":"chat-pop-out",children:t.jsx(Ls,{size:16})}):null,h&&f?t.jsx("button",{type:"button",className:"btn-icon chat-view-header-icon",onClick:f,"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(Ls,{size:16})}):null,h&&N?t.jsx("button",{type:"button",className:"btn-icon chat-view-header-icon",onClick:N,"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(To,{size:16})}):null,h&&k?t.jsx("button",{type:"button",className:"btn-icon chat-view-header-icon",onClick:k,"aria-label":s("chat.closeChat","Close chat"),title:s("chat.closeChat","Close chat"),"data-testid":"chat-modal-close",children:t.jsx(Ps,{size:16})}):null]})}),t.jsxs("div",{className:"chat-view__body",children:[t.jsxs("div",{className:`chat-sidebar${xt?"":" chat-sidebar--hidden"}`,style:Ki,children:[F==="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(Eo,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:s("chat.searchConversations","Search conversations..."),value:hi,onChange:e=>fi(e.target.value),"data-testid":"chat-search-input"})]}),t.jsxs("label",{className:"chat-tag-filter",htmlFor:"chat-tag-filter",children:[t.jsx(_o,{size:14,"aria-hidden":"true"}),t.jsxs("select",{id:"chat-tag-filter",value:L??"",onChange:e=>V(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))]}),L?t.jsx("button",{type:"button",className:"btn-icon","aria-label":s("chat.clearTagFilter","Clear tag filter"),onClick:()=>V(null),children:t.jsx(Ps,{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;pi(e),e&&W()},children:Ye?"Active conversations":"Archived conversations"})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:P?t.jsx("div",{className:"chat-empty-state chat-empty-state--padded",children:s("chat.loadingConversations","Loading...")}):(Ye?ee: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:Ss},{id:"recent",label:s("chat.recent","Recent"),testId:"chat-recent-divider",sessions:Ms}].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 o=l?.id===n.id,d=!o&&Ra("direct",n.id,n.lastMessageAt??n.updatedAt),x=ai(n,be.get(n.agentId)??null,zt),_=Ts(x?.provider,x?.modelId)??"Fusion",q=n.title||s("chat.untitledSession","Untitled");return t.jsxs("div",{className:`chat-session-item${o?" chat-session-item--active":""}`,onClick:()=>us(n.id),onContextMenu:K=>{K.preventDefault(),ja(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:q}),"aria-haspopup":"menu","aria-expanded":Y?.sessionId===n.id,onClick:K=>{if(K.stopPropagation(),Y?.sessionId===n.id){Se(null);return}const pe=K.currentTarget.getBoundingClientRect();ja(n.id,pe.right,pe.bottom,{anchorRight:!0})},children:t.jsx(Do,{size:14})}),t.jsxs("div",{className:"chat-session-title",children:[q,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(),Ei(n.id)},children:"Restore"}):null,t.jsxs("div",{className:"chat-session-meta",children:[t.jsxs("span",{className:"chat-session-meta-model",children:[x?.provider?t.jsx(ua,{provider:x.provider,size:"sm"}):null,t.jsx("span",{children:be.get(n.agentId)?.name||(n.agentId===Ce?_:n.agentId.slice(0,30))})]}),t.jsx("span",{children:n.updatedAt?ir(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:()=>_t(!0),children:[t.jsx(pt,{size:14}),s("chat.createRoom","Create room")]})}),w.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:w.rooms.map(e=>{const n=w.activeRoom?.id===e.id,o=!n&&Ra("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:()=>{ue("room",e.id,e.updatedAt),w.selectRoom(e.id),H&&He(!1)},onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),ue("room",e.id,e.updatedAt),w.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]}),o?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:w.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(),Ft(e.id)},children:t.jsx(ha,{size:14})})]},e.id)})})]}),F==="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:()=>_t(!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:an,"data-testid":"chat-new-btn",children:[t.jsx(pt,{size:14}),s("chat.newChat","New Chat")]})}):null]}),!H&&xt&&!Mt&&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:Ii,onKeyDown:Li}),Y&&t.jsxs("div",{className:"chat-session-context-menu",ref:Nn,role:"menu",style:{top:Y.y,left:Y.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>ds(Y.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(Es,{size:14}):t.jsx(fn,{size:14}),ye?.pinnedAt?s("chat.unpin","Unpin"):s("chat.pin","Pin")]}),t.jsxs("button",{onClick:()=>cs(Y.sessionId),"data-testid":"chat-context-rename",children:[t.jsx(ma,{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(o=>o.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 ke(Y.sessionId,n?(ye?.tags??[]).filter(o=>o.id!==e.id).map(o=>o.id):[...(ye?.tags??[]).map(o=>o.id),e.id]).catch(()=>r(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:o=>{o.stopPropagation(),Da(e.name),bt(e)},children:t.jsx(ma,{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:o=>{o.stopPropagation(),$t(e)},children:t.jsx(ha,{size:14})})]},e.id)}),t.jsxs("div",{className:"chat-tag-create-row",children:[t.jsx("input",{className:"input",value:An,placeholder:s("chat.newTag","New tag"),"aria-label":s("chat.newTag","New tag"),onChange:e=>Ea(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),Ns())}}),t.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>void Ns(),children:s("chat.addTag","Add")})]})]}),t.jsxs("button",{onClick:()=>rs(Y.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Ds,{size:14}),s("chat.archive","Archive")]}),t.jsxs("button",{onClick:()=>{Se(null),Pt(Y.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(ha,{size:14}),s("chat.delete","Delete")]})]}),It&&t.jsx(Et,{onClose:()=>Lt(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:Rn,placeholder:s("chat.renamePlaceholder","Untitled"),"data-testid":"chat-rename-input",onChange:e=>jn(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),ls())},autoFocus:!0}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>Lt(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-primary",onClick:()=>void ls(),"data-testid":"chat-rename-save",children:s("chat.save","Save")})]})]})}),Tn&&t.jsx(Et,{onClose:()=>bt(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:En,"data-testid":"chat-rename-tag-input",onChange:e=>Da(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),ae(Tn.id,En).then(()=>bt(null)).catch(()=>r(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:()=>bt(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-primary","data-testid":"chat-rename-tag-save",onClick:()=>void ae(Tn.id,En).then(()=>bt(null)).catch(()=>r(s("chat.failedToRenameTag","Failed to rename tag"),"error")),children:s("chat.save","Save")})]})]})}),Ia&&t.jsx(Et,{onClose:()=>$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(Ia.id).then(()=>$t(null)).catch(()=>r(s("chat.failedToDeleteTag","Failed to delete tag"),"error")),children:s("chat.delete","Delete")})]})]})}),Aa&&t.jsx(Et,{onClose:()=>Pt(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:()=>Pt(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void Di(Aa),children:s("chat.delete","Delete")})]})]})}),Ta&&t.jsx(Et,{onClose:()=>Ft(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:()=>Ft(null),children:s("chat.cancel","Cancel")}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>{(async()=>{try{await w.deleteRoom(Ta),Ft(null)}catch{r(s("chat.failedToDeleteRoom","Failed to delete room"),"error")}})()},children:s("chat.delete","Delete")})]})]})}),F==="rooms"?t.jsxs("div",{ref:_n,className:"chat-thread",children:[w.activeRoom?t.jsxs(t.Fragment,{children:[(!H||ps)&&t.jsxs("div",{className:"chat-room-thread-header",children:[ps&&t.jsx("button",{className:"btn-icon",onClick:Zn,"data-testid":"chat-back-btn",children:t.jsx(Is,{size:16})}),t.jsxs("div",{className:"chat-room-switcher-menu",ref:Ka,children:[t.jsxs("button",{type:"button",className:"chat-room-switcher-trigger","data-testid":"chat-room-switcher-trigger","aria-haspopup":"menu","aria-expanded":Wt,onClick:()=>Ct(e=>!e),children:[t.jsxs("span",{className:"chat-thread-header-title",children:["#",w.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:w.rooms.map(e=>t.jsxs("button",{type:"button",role:"menuitem",className:`chat-room-switcher-option${e.id===w.activeRoom?.id?" chat-room-switcher-option--active":""}`,"data-testid":`chat-room-switcher-option-${e.id}`,onClick:()=>{ue("room",e.id,e.updatedAt),w.selectRoom(e.id),Ct(!1)},children:["#",e.name]},e.id))})]}),t.jsx("div",{className:"chat-room-thread-members",children:w.activeRoomMembers.map(e=>t.jsx(yn,{agent:be.get(e.agentId)??{id:e.agentId,name:e.agentId.slice(0,30)}},e.agentId))})]}),t.jsxs("div",{className:"chat-messages",ref:le,onScroll:Za,children:[w.messagesLoading?t.jsx("div",{className:"chat-empty-state",children:s("chat.loadingMessages","Loading messages...")}):w.messages.filter(e=>e.content.trim()!==Ys).length===0?t.jsx("div",{className:"chat-empty-state",children:s("chat.noMessagesYet","No messages yet. Start the conversation!")}):w.messages.filter(e=>e.content.trim()!==Ys).map(e=>{const n=e.senderAgentId?be.get(e.senderAgentId)?.name??e.senderAgentId.slice(0,30):s("chat.you","You"),o={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(fa,{message:o,forcePlain:!1,agentName:n,hideAssistantIdentity:!1,showAssistantModelTag:!1,activeModelTag:null,activeModelProvider:null,activeSessionId:w.activeRoom?.id??null,projectId:i,mentionAgentsByName:Vn,roomContext:Te,onScrollToTop:ca,isTopClipped:zn.has(e.id),isAwaitingQuestionAnswer:!1,onQuestionSubmit:sn},e.id)}),t.jsx("div",{ref:Oa})]}),w.activeRoom&&_a&&t.jsxs("button",{type:"button",className:"btn btn-sm chat-jump-to-latest","data-testid":"chat-jump-to-latest",onClick:()=>we("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")}),w.activeRoom&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Yt,type:"file",accept:ni,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:()=>es(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:()=>Yt.current?.click(),children:t.jsx(Fs,{size:16})}),t.jsx(Ks,{level:w.activeRoom.thinkingLevel,defaultThinkingLevel:M,showTargetSection:!1,onChange:e=>{w.updateRoomSettings(w.activeRoom.id,{thinkingLevel:e||null}).catch(()=>{r(s("chat.failedToUpdateRoomThinkingLevel","Failed to update room thinking effort"),"error")})}}),t.jsxs("div",{className:`chat-input-wrapper${$a?" 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:Ti,className:"chat-input-textarea",placeholder:s("chat.typeMessage","Type a message..."),value:Q,onChange:as,onKeyDown:ns,onKeyUp:ss,onClick:cn,onBlur:is,onFocus:os,onPaste:ts,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||ga()&&(document.activeElement,e.currentTarget)},rows:1,"data-testid":"chat-input"}),t.jsx(Vs,{agents:lt,filter:tt,highlightedIndex:Bt,visible:Me,onSelect:on,position:"below",roomMemberIds:Te?.memberIds,roomName:Te?.roomName})]}),t.jsx($s,{...ji.micProps}),t.jsx(_s,{isStreaming:!1,canSend:!!(Q.trim()||ge.length>0),onSend:Gn})]})]})]}):t.jsxs("div",{ref:_n,className:"chat-thread",children:[!H&&(ta||!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(ua,{provider:qe,size:"md"}):t.jsx(wn,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:hs}),_i&&t.jsx("span",{className:"chat-model-tag",children:Fe}),zi&&un&&na?t.jsxs("span",{className:"chat-thread-header-context","data-testid":"chat-thread-context-window",title:na,"aria-label":na,children:[fs," / ",un]}):null]})}),la?t.jsx(qo,{cliSessionId:Ui,tier:Hi,projectId:i,renderTranscript:ys,renderComposer:()=>l?Cs():null}):t.jsxs(t.Fragment,{children:[ys(),_a&&t.jsxs("button",{type:"button",className:"btn btn-sm chat-jump-to-latest","data-testid":"chat-jump-to-latest",onClick:()=>we("fab-click"),children:[t.jsx(hn,{size:14}),s("chat.latest","Latest")]}),l&&Cs()]})]}),t.jsx(Xo,{isOpen:vi,onClose:()=>_t(!1),projectId:i,existingRoomNames:w.rooms.map(e=>e.name),onCreate:async e=>{await w.createRoom({name:e.name,memberAgentIds:e.memberAgentIds}),F!=="rooms"&&Qe("rooms"),_t(!1),H&&He(!1)}})]}),gi&&t.jsx(ur,{projectId:i,defaultModel:wi,defaultKind:y?.kind,defaultAgentId:y?.kind==="agent"?y.agentId:void 0,defaultThinkingLevel:M,defaultSelectedThinkingLevel:y?.kind==="model"?y.thinkingLevel:void 0,onClose:()=>Mn(!1),onCreate:ht})]})}export{Cr as ChatView,yr as buildIssueChatPrefill,sr as clampChatInputHeight,nr as resolveChatContextMenuPosition,ar as resolveChatInputOverflowY,ai as resolveSessionProvider};
@@ -1,4 +1,4 @@
1
- import{r as f,j as s,g as mn,a as aj,b as Jl,c as ij}from"./vendor-react-SZ_qB27O.js";import{c as Vt,h5 as sj,dZ as Nh,L as Ql,l as Mi,h6 as Ii,a as fr,w as mr,aX as vn,h7 as ec,h8 as oj,a$ as Zr,as as el,ae as Ph,a3 as La,F as tn,b2 as lj,b4 as cj,P as zn,b0 as uj,h9 as Ah,bV as Di,bh as qa,ag as tc,ha as $u,R as Gt,az as dj,hb as fj,aM as mj,aT as Ri,hc as Oh,ej as vj,aY as Eh,da as _h,bL as hj,aK as rc,bX as pj,hd as yj,ar as gj,fy as bj,he as xj,aj as Th,hf as jj,hg as wj,cV as Fu,hh as Bu,fJ as Cj,gN as Ps,hi as zu,hj as ga,hk as kj,hl as Sj,hm as Nj,hn as Pj,gO as Aj,ho as Oj,hp as Ej,hq as _j,gK as Tj,hr as Mj,G as Ij,aN as Dj,gP as Mh,hs as Rj,c3 as Lj,B as $j,ht as Fj,au as Bj,hu as As,hv as zj,hw as Kj,hx as Vj,hy as Uj,hz as qj,hA as Wj,hB as nc,hC as ac,hD as Ku,c_ as Wa,hE as Vu,hF as tl,hG as Ih,hH as rl,bi as Dh,bW as Rh,bY as Lh,dl as Hj,d6 as Gj,K as ic,C as sc,hI as Xj,hJ as Yj,D as Zj,e_ as Uu,X as $a,E as Jj,y as Qj,b1 as qu,aI as e0,hK as Wu,hL as t0,hM as r0,hN as n0,hO as a0,eh as i0,hP as Os,hQ as s0,hR as o0,hS as l0}from"./index-DpCHwyiD.js";import{u as se}from"./vendor-i18n-Duky4gdQ.js";import{a as $h,b as Fh,p as c0,w as u0}from"./vendor-reactflow-BlIeoTu4.js";import{w as Bh,n as zh,a as Me,A as oc,G as d0,H as f0,l as Kh,t as Li,b as _t,p as nl,s as Ha,c as Vh,q as m0,r as v0,u as h0,v as p0,x as y0,y as g0,z as b0,C as x0,D as j0,k as w0,E as C0,F as k0}from"./step-yuy0qJer.js";import{b as S0,p as N0}from"./band-CquvqAHh.js";import{d as Ga,n as P0,e as A0,f as al,g as Br,h as lc,a as cc,i as Hu,j as Ht,c as O0,k as $i,l as E0,m as _0}from"./linear-Dyk9wory.js";import{i as pr,a as Qt}from"./init-Dmth1JHB.js";import{m as Gu,a as Xu,p as T0,q as M0,u as I0,s as D0,r as R0,v as L0,w as $0,x as F0,y as B0,z as z0,A as K0,B as V0,t as U0}from"./time-2wBVBf9F.js";import{f as q0,b as W0}from"./defaultLocale-DX6XiGOO.js";import{i as H0,o as G0}from"./ordinal-DILIJJjt.js";import{g as X0,i as il,r as Y0}from"./agentsOrgChartLayout-C0UP_X3z.js";import{U as uc}from"./upload-CDovVbu2.js";import{S as Z0}from"./shield-alert-BNSeDB8l.js";import{b as J0}from"./agent-import-generation-CjiYXzCr.js";import{r as Q0,B as ew,R as tw,b as rw,a as nw}from"./ReportModal-CMrmMQjD.js";import{PluginManager as aw}from"./PluginManager-DyT8XbcG.js";import{v as iw}from"./projectDetection-G3XuxD2X.js";import"./vendor-codemirror-CcrtqoCy.js";import"./vendor-xterm-BNq00GSj.js";import"./DirectoryPicker-Cp2gddTE.js";import"./folder-open-CteOypVk.js";/**
1
+ import{r as f,j as s,g as mn,a as aj,b as Jl,c as ij}from"./vendor-react-SZ_qB27O.js";import{c as Vt,h6 as sj,dZ as Nh,L as Ql,l as Mi,h7 as Ii,a as fr,w as mr,aX as vn,h8 as ec,h9 as oj,a$ as Zr,as as el,ae as Ph,a3 as La,F as tn,b2 as lj,b4 as cj,P as zn,b0 as uj,ha as Ah,bV as Di,bh as qa,ag as tc,hb as $u,R as Gt,az as dj,hc as fj,aM as mj,aT as Ri,hd as Oh,ei as vj,aY as Eh,da as _h,bL as hj,aK as rc,bX as pj,he as yj,ar as gj,fw as bj,hf as xj,aj as Th,hg as jj,hh as wj,cV as Fu,hi as Bu,fI as Cj,gM as Ps,hj as zu,hk as ga,hl as kj,hm as Sj,hn as Nj,ho as Pj,gN as Aj,hp as Oj,hq as Ej,hr as _j,gJ as Tj,hs as Mj,G as Ij,aN as Dj,gO as Mh,ht as Rj,c3 as Lj,B as $j,hu as Fj,au as Bj,hv as As,hw as zj,hx as Kj,hy as Vj,hz as Uj,hA as qj,hB as Wj,hC as nc,hD as ac,hE as Ku,c_ as Wa,hF as Vu,hG as tl,hH as Ih,hI as rl,bi as Dh,bW as Rh,bY as Lh,dl as Hj,d6 as Gj,K as ic,C as sc,hJ as Xj,hK as Yj,D as Zj,eZ as Uu,X as $a,E as Jj,y as Qj,b1 as qu,aI as e0,hL as Wu,hM as t0,hN as r0,hO as n0,hP as a0,eg as i0,hQ as Os,hR as s0,hS as o0,hT as l0}from"./index-B_z7OKl4.js";import{u as se}from"./vendor-i18n-Duky4gdQ.js";import{a as $h,b as Fh,p as c0,w as u0}from"./vendor-reactflow-BlIeoTu4.js";import{w as Bh,n as zh,a as Me,A as oc,G as d0,H as f0,l as Kh,t as Li,b as _t,p as nl,s as Ha,c as Vh,q as m0,r as v0,u as h0,v as p0,x as y0,y as g0,z as b0,C as x0,D as j0,k as w0,E as C0,F as k0}from"./step-yuy0qJer.js";import{b as S0,p as N0}from"./band-CquvqAHh.js";import{d as Ga,n as P0,e as A0,f as al,g as Br,h as lc,a as cc,i as Hu,j as Ht,c as O0,k as $i,l as E0,m as _0}from"./linear-Dyk9wory.js";import{i as pr,a as Qt}from"./init-Dmth1JHB.js";import{m as Gu,a as Xu,p as T0,q as M0,u as I0,s as D0,r as R0,v as L0,w as $0,x as F0,y as B0,z as z0,A as K0,B as V0,t as U0}from"./time-2wBVBf9F.js";import{f as q0,b as W0}from"./defaultLocale-DX6XiGOO.js";import{i as H0,o as G0}from"./ordinal-DILIJJjt.js";import{g as X0,i as il,r as Y0}from"./agentsOrgChartLayout-CqKtNCjy.js";import{U as uc}from"./upload-qH_64O-B.js";import{S as Z0}from"./shield-alert-DcXc56Fy.js";import{b as J0}from"./agent-import-generation-SCPNeF25.js";import{r as Q0,B as ew,R as tw,b as rw,a as nw}from"./ReportModal-YMP6V4vu.js";import{PluginManager as aw}from"./PluginManager-D2csmdQa.js";import{v as iw}from"./projectDetection-G3XuxD2X.js";import"./vendor-codemirror-CcrtqoCy.js";import"./vendor-xterm-BNq00GSj.js";import"./DirectoryPicker-1JvRd5mC.js";import"./folder-open-DnAlsXXn.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.