@runfusion/fusion 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/bin.js +438 -235
  2. package/dist/client/assets/{AgentDetailView-Cu4TgvBn.js → AgentDetailView-Dx7T1-gM.js} +3 -3
  3. package/dist/client/assets/AgentPermissionPolicyEditor-Cbd6SG_T.css +1 -0
  4. package/dist/client/assets/AgentPermissionPolicyEditor-Ia7QkynK.js +6 -0
  5. package/dist/client/assets/{AgentsView-CIH4Acck.js → AgentsView-DBbdPWV-.js} +3 -3
  6. package/dist/client/assets/ChatView-DYpoWnCc.js +1 -0
  7. package/dist/client/assets/{DevServerView-Bd8JZ-3C.js → DevServerView-DotHOFZt.js} +1 -1
  8. package/dist/client/assets/{DirectoryPicker-BOGqZNiq.js → DirectoryPicker-CIj3ZGKv.js} +1 -1
  9. package/dist/client/assets/{DocumentsView-B-ELcw4o.js → DocumentsView-Dt27gDYa.js} +1 -1
  10. package/dist/client/assets/{EvalsView-Ccl9QBYN.js → EvalsView-HfWTc8Uv.js} +1 -1
  11. package/dist/client/assets/{ExperimentalAgentOnboardingModal-BM7EnSvJ.js → ExperimentalAgentOnboardingModal-U7fXDhhN.js} +1 -1
  12. package/dist/client/assets/{InsightsView-DLF49bzu.js → InsightsView-C8bsAlMv.js} +1 -1
  13. package/dist/client/assets/{MemoryView-CE1D9euM.js → MemoryView-D-HLtRrr.js} +1 -1
  14. package/dist/client/assets/{NodesView-Zxusnhxu.js → NodesView-w3ms-XX2.js} +1 -1
  15. package/dist/client/assets/{PiExtensionsManager-BlMmxtLZ.js → PiExtensionsManager-DFAZAfNn.js} +2 -2
  16. package/dist/client/assets/{PluginManager-D4eZ0zA4.js → PluginManager-DN1VG7Qm.js} +1 -1
  17. package/dist/client/assets/ReliabilityView-D0Rtd7pX.css +1 -0
  18. package/dist/client/assets/{ResearchView-C14Zh7c9.js → ResearchView-YoxEFtNB.js} +1 -1
  19. package/dist/client/assets/{SettingsModal-BAx4gt2A.css → SettingsModal-1Y8N6MkL.css} +1 -1
  20. package/dist/client/assets/SettingsModal-B86XhYB1.js +31 -0
  21. package/dist/client/assets/{SettingsModal-DRnZ6eBW.js → SettingsModal-BRRPoxku.js} +1 -1
  22. package/dist/client/assets/{SetupWizardModal-BmmRM3g-.js → SetupWizardModal-B4eA3bpz.js} +1 -1
  23. package/dist/client/assets/{SkillsView-DWVtT2-8.js → SkillsView-DZIfZoF5.js} +1 -1
  24. package/dist/client/assets/{StashRecoveryView-CKkaWzzc.js → StashRecoveryView-mKXYsqam.js} +1 -1
  25. package/dist/client/assets/{TodoView-hbD0NOCY.js → TodoView-C6sLLEQu.js} +1 -1
  26. package/dist/client/assets/dashboard-view-DOY8-BIx.js +21 -0
  27. package/dist/client/assets/{folder-open-BTN2_Wuv.js → folder-open-C_fxRMq1.js} +1 -1
  28. package/dist/client/assets/index-DTFPgu6_.js +695 -0
  29. package/dist/client/assets/index-DdvAZIzj.css +1 -0
  30. package/dist/client/assets/{upload-euJEs_N2.js → upload-xjku_93-.js} +1 -1
  31. package/dist/client/assets/{users-B7miEHCZ.js → users-CbALDtDk.js} +1 -1
  32. package/dist/client/index.html +2 -2
  33. package/dist/client/version.json +1 -1
  34. package/dist/droid-cli/package.json +1 -1
  35. package/dist/extension.js +477 -225
  36. package/dist/pi-claude-cli/package.json +1 -1
  37. package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
  38. package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
  39. package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
  40. package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
  41. package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
  42. package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
  43. package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
  44. package/dist/plugins/fusion-plugin-reports/package.json +1 -1
  45. package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
  46. package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
  47. package/package.json +1 -1
  48. package/skill/fusion/SKILL.md +1 -1
  49. package/skill/fusion/references/extension-tools.md +11 -0
  50. package/skill/fusion/references/fusion-capabilities.md +1 -0
  51. package/dist/client/assets/AgentPermissionPolicyEditor-Ceg2Dszn.js +0 -6
  52. package/dist/client/assets/AgentPermissionPolicyEditor-CthjqUL_.css +0 -1
  53. package/dist/client/assets/ChatView-DqJoFquZ.js +0 -1
  54. package/dist/client/assets/ReliabilityView-rxA_HgEG.css +0 -1
  55. package/dist/client/assets/SettingsModal-c1QwWno0.js +0 -31
  56. package/dist/client/assets/dashboard-view-VNPB3ca0.js +0 -21
  57. package/dist/client/assets/index-CZFBq256.css +0 -1
  58. package/dist/client/assets/index-DzSLVOnp.js +0 -695
  59. /package/dist/client/assets/{ReliabilityView-KmH60I_5.js → ReliabilityView-DAuqE-zi.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion/pi-claude-cli",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Fusion vendored fork: pi coding-agent extension that routes LLM calls through the Claude Code CLI. Forked from rchern/pi-claude-cli (MIT). See UPSTREAM.md.",
5
5
  "license": "MIT",
6
6
  "private": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/cli-printing-press",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "CLI Printing Press plugin package for Fusion",
6
6
  "private": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/cursor-runtime",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/dependency-graph",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/droid-runtime",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/hermes-runtime",
3
- "version": "0.2.40",
3
+ "version": "0.2.41",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/openclaw-runtime",
3
- "version": "0.2.40",
3
+ "version": "0.2.41",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/paperclip-runtime",
3
- "version": "0.2.40",
3
+ "version": "0.2.41",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/reports",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "description": "Reports plugin for Fusion",
6
6
  "private": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/roadmap",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fusion-plugin-examples/whatsapp-chat",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "description": "WhatsApp Web (Baileys) chat bridge for Fusion agents",
6
6
  "keywords": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runfusion/fusion",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "license": "MIT",
5
5
  "description": "Fusion CLI: HTTP API server, daemon, dashboard launcher, and task tooling for the Fusion AI coding agent.",
6
6
  "homepage": "https://github.com/Runfusion/Fusion#readme",
@@ -29,7 +29,7 @@ Mission → Milestone → Slice → Feature → Task
29
29
  <!-- BEGIN: tool-categories (auto-generated by scripts/sync-fusion-skill-tools.mjs — do not edit by hand) -->
30
30
  - **Task tools** — `fn_task_create`, `fn_task_update`, `fn_task_list`, `fn_task_show`, `fn_task_attach`, `fn_task_pause`, `fn_task_unpause`, `fn_task_retry`, `fn_task_duplicate`, `fn_task_refine`, `fn_task_archive`, `fn_task_unarchive`, `fn_task_delete`, `fn_task_plan`
31
31
  - **GitHub tools** — `fn_task_import_github`, `fn_task_import_github_issue`, `fn_task_browse_github_issues`
32
- - **Mission tools** — `fn_mission_create`, `fn_mission_list`, `fn_mission_show`, `fn_mission_delete`, `fn_milestone_add`, `fn_slice_add`, `fn_feature_add`, `fn_slice_activate`, `fn_feature_link_task`, `fn_feature_update`
32
+ - **Mission tools** — `fn_mission_create`, `fn_mission_list`, `fn_mission_show`, `fn_mission_delete`, `fn_milestone_add`, `fn_slice_add`, `fn_feature_add`, `fn_slice_activate`, `fn_feature_link_task`, `fn_feature_update`, `fn_milestone_update`
33
33
  - **Agent tools** — `fn_agent_stop`, `fn_agent_start`, `fn_agent_create`, `fn_agent_delete`, `fn_list_agents`, `fn_delegate_task`, `fn_agent_show`, `fn_agent_org_chart`
34
34
  - **Skills tools** — `fn_skills_search`, `fn_skills_install`
35
35
  - **Insight tools** — `fn_insight_list`, `fn_insight_show`, `fn_insight_run_list`, `fn_insight_run_show`
@@ -259,6 +259,17 @@ Update an existing feature's title, description, or acceptance criteria. Partial
259
259
  | `description` | string | — | Updated feature description |
260
260
  | `acceptanceCriteria` | string | — | Updated acceptance criteria for completing the feature |
261
261
 
262
+ ### fn_milestone_update
263
+
264
+ Update an existing milestone's title, description, or acceptance criteria (the structured pass/fail bar, distinct from verification's free-form how-to-confirm notes). Partial patches leave untouched fields intact.
265
+
266
+ | Parameter | Type | Required | Description |
267
+ |-----------|------|----------|-------------|
268
+ | `id` | string | ✓ | Milestone ID to update (e.g., MS-001) |
269
+ | `title` | string | — | Updated milestone title |
270
+ | `description` | string | — | Updated milestone description |
271
+ | `acceptanceCriteria` | string | — | Updated acceptance criteria for completing the milestone |
272
+
262
273
  ## Agent Tools
263
274
 
264
275
  ### fn_agent_stop
@@ -50,6 +50,7 @@ All skill/extension tool invocations in this catalog use the public `fn_*` names
50
50
  | `fn_slice_activate` | Activate a pending slice for implementation. Sets status to 'active' and enables task linking for its features. |
51
51
  | `fn_feature_link_task` | Link a feature to a fn task for implementation. Updates the feature status to 'triaged' and associates it with the task. |
52
52
  | `fn_feature_update` | Update an existing feature's title, description, or acceptance criteria. Partial patches leave untouched fields intact. |
53
+ | `fn_milestone_update` | Update an existing milestone's title, description, or acceptance criteria (the structured pass/fail bar, distinct from verification's free-form how-to-confirm notes). Partial patches leave untouched fields intact. |
53
54
  | `fn_agent_stop` | Stop a running agent — pauses its execution. Transitions the agent from running/active to paused state. |
54
55
  | `fn_agent_start` | Start a stopped agent — resumes its execution. Transitions the agent from paused to active state. |
55
56
  | `fn_agent_create` | Create a new non-ephemeral agent. |
@@ -1,6 +0,0 @@
1
- import{c as x,dG as _}from"./index-DzSLVOnp.js";import{j as e}from"./vendor-react-K0fH_qHe.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 k=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],A=x("star",k),j=["allow","require-approval","block"],b={git_write:{label:"Git writes",description:"Commits, branch updates, and merge-affecting git changes."},file_write_delete:{label:"File writes/deletes",description:"Create, edit, or remove files in the workspace."},command_execution:{label:"Command execution",description:"Runs shell commands and scripts."},network_api:{label:"Network/API",description:"Outbound network or API access."},task_agent_mutation:{label:"Task/agent mutation",description:"Task state changes, delegation, or agent lifecycle actions."}};function I(){return{git_write:"allow",file_write_delete:"allow",command_execution:"allow",network_api:"allow",task_agent_mutation:"allow"}}const d={unrestricted:{git_write:"allow",file_write_delete:"allow",command_execution:"allow",network_api:"allow",task_agent_mutation:"allow"},"approval-required":{git_write:"require-approval",file_write_delete:"require-approval",command_execution:"require-approval",network_api:"require-approval",task_agent_mutation:"require-approval"},"locked-down":{git_write:"block",file_write_delete:"block",command_execution:"block",network_api:"block",task_agent_mutation:"block"}};function R(r){return d[r]}function p(r,o){return _.every(i=>r[i]===o[i])}function N(r){return p(r,d.unrestricted)?"unrestricted":p(r,d["approval-required"])?"approval-required":p(r,d["locked-down"])?"locked-down":"custom"}function E({value:r,projectDefault:o,mode:i,onChange:a,disabled:m=!1}){const v=r?N(r.rules):"unrestricted",h=i==="agent-override"&&!r?"inherit":r?.presetId==="custom"?v:r?.presetId??"unrestricted",u=r?.rules??I(),g=t=>{if(i==="agent-override"&&t==="inherit"){a(void 0);return}if(t==="custom"){a({presetId:"custom",rules:{...u}});return}a({presetId:t,rules:R(t)})},f=(t,n)=>{if(i==="agent-override"&&n==="inherit"){if(!r)return;const c={...r.rules};c[t]=o?.[t]??"allow",a({presetId:"custom",rules:c});return}const s={...u,[t]:n};a({presetId:"custom",rules:s})};return e.jsxs("div",{className:"agent-policy-editor card",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-policy-preset",children:"Preset"}),e.jsxs("select",{id:"agent-policy-preset",className:"select",value:h,onChange:t=>g(t.target.value),disabled:m,children:[i==="agent-override"?e.jsx("option",{value:"inherit",children:"Inherit project default"}):null,e.jsx("option",{value:"unrestricted",children:"Unrestricted"}),e.jsx("option",{value:"approval-required",children:"Approval Required"}),e.jsx("option",{value:"locked-down",children:"Locked Down"}),e.jsx("option",{value:"custom",children:"Custom"})]})]}),e.jsx("div",{className:"agent-policy-table",role:"table","aria-label":"Permission policy categories",children:_.map(t=>{const n=b[t]??{label:t,description:""},s=o?.[t]??"allow",c=u[t]??"allow",w=i==="agent-override"&&!r?"inherit":c;return e.jsxs("div",{className:"agent-policy-row",role:"row",children:[e.jsxs("div",{className:"agent-policy-cell",children:[e.jsx("strong",{children:n.label}),e.jsx("div",{className:"agent-policy-description",children:n.description})]}),e.jsxs("div",{className:"agent-policy-cell",children:[e.jsxs("select",{className:"select",value:w,onChange:l=>f(t,l.target.value),disabled:m,children:[i==="agent-override"?e.jsx("option",{value:"inherit",children:"Inherit"}):null,j.map(l=>e.jsx("option",{value:l,children:l==="require-approval"?"Require approval":l[0]?.toUpperCase()+l.slice(1)},l))]}),i==="agent-override"&&w==="inherit"?e.jsxs("div",{className:"agent-policy-inherit-note",children:["from project default: ",s==="require-approval"?"Require approval":s]}):null]})]},t)})})]})}export{E as A,A as S};
@@ -1 +0,0 @@
1
- .agent-policy-editor{padding:var(--space-lg);border:1px solid var(--border);border-radius:var(--radius-lg);display:flex;flex-direction:column;gap:var(--space-md)}.agent-policy-table{display:flex;flex-direction:column;gap:var(--space-sm)}.agent-policy-row{display:grid;grid-template-columns:1fr 220px;gap:var(--space-md);padding:var(--space-sm);border:1px solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.agent-policy-cell{display:flex;flex-direction:column;gap:var(--space-xs)}.agent-policy-description{color:var(--text-muted);font-size:.75rem}.agent-policy-inherit-note{color:var(--text-dim);font-size:.75rem}@media(max-width:768px){.agent-policy-row{grid-template-columns:1fr}}
@@ -1 +0,0 @@
1
- import{r as n,a as en,j as t,R as tn}from"./vendor-react-K0fH_qHe.js";import{i as yt,b5 as fs,t as Es,b6 as sn,b7 as gs,b8 as nn,w as Kt,b9 as qe,ba as an,bb as rn,bc as on,bd as cn,be as ln,bf as ps,bg as dn,s as Ds,bh as un,bi as mn,bj as _t,bk as hn,bl as fn,bm as gn,bn as pn,k as $s,bo as bn,bp as vn,p as xn,bq as yn,br as wn,u as Sn,bs as Cn,ac as Is,ad as Ps,bt as Nn,bu as kn,S as jn,Y as Ut,P as it,J as at,ap as Mn,bv as bs,bw as vs,bx as xs,B as ot,a as ys,a9 as Rn,aa as An,aW as xt,by as Tn,bz as En,aT as Dn,bA as ws,bB as $n,T as In,bC as Ss,bD as Pn,h as Ln,j as Cs,m as Fn}from"./index-DzSLVOnp.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";const Ot="kb-chat-active-session";function Ns(s){const r=typeof s=="string"?s.trim():"",l=r.indexOf("/");return!r||l<=0||l>=r.length-1?{}:{modelProvider:r.slice(0,l),modelId:r.slice(l+1)}}function zn(s){const r=s?.toolCalls;if(!Array.isArray(r))return;const l=r.map(i=>{if(!i||typeof i!="object")return null;const u=i,x=typeof u.toolName=="string"?u.toolName:"";if(!x)return null;const R=u.args;return{toolName:x,...R&&typeof R=="object"?{args:R}:{},isError:!!u.isError,result:u.result,status:"completed"}}).filter(i=>i!==null);return l.length>0?l:void 0}function _n(s){const r=s?.fallback;if(!r||typeof r!="object")return;const l=r,i=typeof l.primaryModel=="string"?l.primaryModel:"",u=typeof l.fallbackModel=="string"?l.fallbackModel:"",x=l.triggerPoint;if(!(!i||!u||x!=="session-creation"&&x!=="prompt-time"))return{primaryModel:i,fallbackModel:u,triggerPoint:x}}function Un(s){const r=s?.failureInfo;if(!r||typeof r!="object")return;const l=r,i=typeof l.summary=="string"?l.summary.trim():"";if(!i)return;const u=(()=>{const x=l.reference;if(!x||typeof x!="object")return;const R=x,E=typeof R.kind=="string"?R.kind.trim():"",D=typeof R.id=="string"?R.id.trim():"";if(!(!E||!D))return{kind:E,id:D,...typeof R.label=="string"&&R.label.trim()?{label:R.label.trim()}:{}}})();return{summary:i,...typeof l.errorClass=="string"&&l.errorClass.trim()?{errorClass:l.errorClass.trim()}:{},...typeof l.code=="string"&&l.code.trim()?{code:l.code.trim()}:{},...typeof l.detail=="string"&&l.detail.trim()?{detail:l.detail.trim()}:{},...u?{reference:u}:{}}}function ks(s){return typeof s=="string"?{summary:s.trim()||"Failed to get response"}:{summary:typeof s.summary=="string"&&s.summary.trim()?s.summary.trim():"Failed to get response",...typeof s.errorClass=="string"&&s.errorClass.trim()?{errorClass:s.errorClass.trim()}:{},...typeof s.code=="string"&&s.code.trim()?{code:s.code.trim()}:{},...typeof s.detail=="string"&&s.detail.trim()?{detail:s.detail.trim()}:{},...s.reference?{reference:s.reference}:{}}}function Ht(s){return{id:s.id,sessionId:s.sessionId,role:s.role,content:s.content,thinkingOutput:s.thinkingOutput,toolCalls:zn(s.metadata),fallbackInfo:_n(s.metadata),failureInfo:Un(s.metadata),attachments:s.attachments,createdAt:s.createdAt}}function On(s,r){const[l,i]=n.useState([]),[u,x]=n.useState(null),[R,E]=n.useState(!0),[D,C]=n.useState([]),[Q,S]=n.useState(!1),[L,g]=n.useState(!1),[ee,N]=n.useState(""),[_,b]=n.useState(""),[M,A]=n.useState([]),[T,$]=n.useState(""),[J,Y]=n.useState(""),[z,h]=n.useState(!0),[p,o]=n.useState(new Map),c=n.useRef(null),m=n.useRef(!1),y=n.useRef(""),k=n.useRef(null),Z=n.useRef(l),F=n.useRef(u),G=n.useRef(L);Z.current=l,F.current=u,G.current=L,n.useEffect(()=>{y.current=T},[T]);const ke=n.useRef(new Set),ue=n.useRef(0),ve=n.useRef(s);ve.current!==s&&(ve.current=s,ue.current++),n.useEffect(()=>{const f=ue.current;yt(void 0,s).then(v=>{if(ue.current!==f)return;const w=new Map;for(const P of v)w.set(P.id,P);o(w)}).catch(()=>{})},[s]);const ie=n.useCallback(async()=>{E(!0);try{const v=[...(await fs(s)).sessions].sort((w,P)=>new Date(P.updatedAt).getTime()-new Date(w.updatedAt).getTime());i(v)}catch{}finally{E(!1)}},[s]);n.useEffect(()=>{ie()},[ie]);const Ue=n.useRef(()=>{}),Fe=n.useRef(!1);n.useEffect(()=>{Fe.current=!1},[s]),n.useEffect(()=>{if(R||Fe.current||F.current)return;const f=Es(Ot,s);if(!f){Fe.current=!0;return}const v=l.find(w=>w.id===f);if(v){Fe.current=!0,Ue.current(f,v);return}Fe.current=!0},[R,l,s]);const te=n.useCallback(async(f,v)=>{S(!0);try{const w=await sn(f,{limit:50,...v},s),P=w.messages.map(Ht);v?.offset&&v.offset>0?C(se=>[...P,...se]):C(P),h(w.messages.length>=50)}catch{}finally{S(!1)}},[s]),me=n.useCallback(()=>{k.current?.(),k.current=null,y.current="",$(""),N(""),b(""),A([]),g(!1)},[]),wt=n.useCallback(()=>{y.current="",$("")},[]),ne=n.useCallback(()=>{const f=y.current.trim();f&&(y.current="",$(""),ze.current(f))},[]),oe=n.useCallback((f,v,w)=>{if(c.current||!f)return!0;m.current=!1,v&&(N(v.streamingText),b(v.streamingThinking),A(v.toolCalls)),g(!0);const{handlers:P}=gs({sessionId:f,tempUserMessageId:"",setStreamingText:N,setStreamingThinking:b,setStreamingToolCalls:A,cancelStreamingFlushesRef:k,addToast:w?.silent?void 0:r,onFallbackSession:(H,ae)=>{const U=Ns(H.fallbackModel);i(K=>K.map(W=>W.id===ae?{...W,...U}:W)),x(K=>K&&K.id===ae?{...K,...U}:K)},onDone:()=>{N(""),b(""),A([]),g(!1),G.current=!1,c.current=null,te(f),ne()},onError:H=>{N(""),b(""),A([]),g(!1),G.current=!1,c.current=null;const ae=ks(H);w?.silent||r?.(ae.summary,"error"),te(f),ne()}}),se=nn(f,P,s,{...typeof v?.replayFromEventId=="number"?{lastEventId:v.replayFromEventId}:{}});return c.current=se,!0},[r,te,s,ne]),Oe=n.useCallback((f,v)=>{const w=F.current?.id??null;if(f&&w===f&&!v)return;c.current&&(c.current.close(),c.current=null);const P=v??l.find(se=>se.id===f);x(P||null),me(),h(!0),f?te(f):C([]),P?.isGenerating&&oe(P.id,P.inFlightGeneration),f?Kt(Ot,f,s):qe(Ot,s)},[oe,l,te,s,me]);Ue.current=Oe;const ct=n.useCallback(async f=>{const v=await an(f,s);c.current&&(c.current.close(),c.current=null);const w={id:v.session.id,title:v.session.title,agentId:v.session.agentId,status:v.session.status,modelProvider:v.session.modelProvider,modelId:v.session.modelId,createdAt:v.session.createdAt,updatedAt:v.session.updatedAt};return i(P=>P.some(se=>se.id===w.id)?P:[w,...P]),me(),Oe(w.id,w),C([]),w},[s,me,Oe]),je=n.useCallback(async f=>{await rn(f,{status:"archived"},s),i(v=>v.filter(w=>w.id!==f)),u?.id===f&&(x(null),C([]))},[u,s]),Me=n.useCallback(async f=>{u?.id===f&&c.current&&(c.current.close(),c.current=null),await on(f,s),i(v=>v.filter(w=>w.id!==f)),u?.id===f&&(x(null),C([]))},[u,s]),Je=n.useCallback(async()=>{!u||!z||await te(u.id,{offset:D.length})},[u,z,te,D.length]),He=n.useCallback(()=>{u&&(m.current=!0,k.current?.(),k.current=null,c.current?.close(),c.current=null,cn(u.id,s).catch(()=>{}),g(!1),N(""),b(""),A([]))},[u,s]),ze=n.useRef(()=>{}),Re=ln(),xe=n.useCallback(async f=>{try{await ie();const v=await ps(f,s);F.current?.id===f&&x(w=>!w||w.id!==f?w:{...w,...v.session}),v.session.isGenerating?(N(""),b(""),A([]),g(!0),G.current=!0,oe(f,v.session.inFlightGeneration,{silent:!0})):(N(""),b(""),A([]),g(!1),G.current=!1,await te(f))}catch{}},[oe,te,s,ie]),ye=n.useCallback((f,v)=>{if(!u)return;if(G.current){y.current=f,$(f);return}m.current=!1,c.current&&(c.current.close(),c.current=null);const w=`temp-${Date.now()}`,P={id:w,sessionId:u.id,role:"user",content:f,createdAt:new Date().toISOString()};C(H=>[...H,P]),N(""),b(""),A([]),g(!0);const{handlers:se}=gs({sessionId:u.id,tempUserMessageId:w,setStreamingText:N,setStreamingThinking:b,setStreamingToolCalls:A,cancelStreamingFlushesRef:k,addToast:r,onFallbackSession:(H,ae)=>{const U=Ns(H.fallbackModel);i(K=>K.map(W=>W.id===ae?{...W,...U}:W)),x(K=>K&&K.id===ae?{...K,...U}:K)},onDone:({messageId:H,message:ae,accumulated:U})=>{const K=ae?Ht(ae):{id:H||`msg-${Date.now()}`,sessionId:u.id,role:"assistant",content:U.text,thinkingOutput:U.thinking,toolCalls:U.toolCalls.length>0?U.toolCalls:void 0,fallbackInfo:U.fallbackInfo,createdAt:new Date().toISOString()};ke.current.add(K.id),C(W=>[...W,K]),N(""),b(""),A([]),g(!1),G.current=!1,c.current=null,setTimeout(()=>{ke.current.delete(K.id)},1e3),ie(),ne()},onError:(H,ae)=>{const U=ks(H),K=typeof H=="string"?H:U.summary,W=un(K);C(V=>{const O=V.filter(q=>q.id!==ae);return W?O:[...O,{id:`error-${Date.now()}`,sessionId:u.id,role:"assistant",content:U.summary,failureInfo:U,createdAt:new Date().toISOString()}]}),N(""),b(""),A([]),g(!1),G.current=!1,c.current=null,console.error("[useChat] Stream error:",H),W?(console.info("[useChat] Suppressed tab-suspension stream error:",H),u?.id&&(N(""),b(""),A([]),g(!0),G.current=!0,xe(u.id))):(r?.(U.summary,"error"),ie()),m.current||ne()}});c.current=dn(u.id,f,se,v,s)},[u,s,ie,r,oe,xe,ne]);ze.current=ye;const fe=J?l.filter(f=>f.title?.toLowerCase().includes(J.toLowerCase())||f.agentId.toLowerCase().includes(J.toLowerCase())):l;return n.useEffect(()=>{if(!F.current?.isGenerating||(c.current||oe(F.current.id,F.current.inFlightGeneration),!G.current||c.current||!F.current))return;const f=setInterval(async()=>{if(!G.current||c.current||!F.current){clearInterval(f);return}try{(await fs(s)).sessions.find(P=>P.id===F.current?.id)?.isGenerating||(clearInterval(f),await te(F.current.id),N(""),b(""),A([]),g(!1),G.current=!1,ne())}catch{}},3e3);return()=>clearInterval(f)},[oe,te,s,u,ne]),n.useEffect(()=>Re.onBecameVisible(()=>{const v=F.current;if(!v||c.current)return;const w=ue.current;ps(v.id,s).then(P=>{if(!(ue.current!==w||c.current)){if(P.session.isGenerating){N(""),b(""),A([]),g(!0),G.current=!0,oe(v.id,P.session.inFlightGeneration,{silent:!0});return}G.current&&(N(""),b(""),A([]),g(!1),G.current=!1,ne(),te(v.id))}}).catch(()=>{})}),[oe,te,s,Re,ne]),n.useEffect(()=>{const f=ue.current,v=s?`?projectId=${encodeURIComponent(s)}`:"",w=()=>ue.current!==f,P=W=>{if(w())return;const V=JSON.parse(W.data);i(O=>O.some(q=>q.id===V.id)?O:[V,...O])},se=W=>{if(w())return;const V=JSON.parse(W.data);i(O=>[...O.map(re=>re.id===V.id?V:re)]),F.current?.id===V.id&&(x(V),V.isGenerating&&!c.current&&oe(V.id,V.inFlightGeneration))},H=W=>{if(w())return;const{id:V}=JSON.parse(W.data);i(O=>O.filter(q=>q.id!==V)),F.current?.id===V&&(x(null),C([]))},ae=W=>{if(w())return;const V=JSON.parse(W.data),O=Ht(V);if(!ke.current.has(O.id)){if(F.current?.id===O.sessionId&&G.current&&!c.current&&O.role==="assistant"){C(q=>q.some(re=>re.id===O.id)?q:[...q,O]),N(""),b(""),A([]),g(!1),G.current=!1,ne();return}F.current?.id===O.sessionId&&!G.current&&C(q=>{if(q.some(re=>re.id===O.id))return q;if(O.role==="user"){const re=q.findIndex(we=>we.role==="user"&&we.id.startsWith("temp-")&&we.content.trim()===O.content.trim());if(re>=0){const we=[...q];return we[re]=O,we}}return[...q,O]})}},U=W=>{if(w())return;const{id:V}=JSON.parse(W.data);C(O=>O.filter(q=>q.id!==V))};return Ds(`/api/events${v}`,{events:{"chat:session:created":P,"chat:session:updated":se,"chat:session:deleted":H,"chat:message:added":ae,"chat:message:deleted":U}})},[oe,s,ne]),n.useEffect(()=>()=>{c.current&&(c.current.close(),c.current=null)},[]),{sessions:l,activeSession:u,sessionsLoading:R,messages:D,messagesLoading:Q,isStreaming:L,streamingText:ee,streamingThinking:_,streamingToolCalls:M,pendingMessage:T,selectSession:Oe,createSession:ct,archiveSession:je,deleteSession:Me,sendMessage:ye,stopStreaming:He,clearPendingMessage:wt,loadMoreMessages:Je,hasMoreMessages:z,searchQuery:J,setSearchQuery:Y,filteredSessions:fe,refreshSessions:ie,agentsMap:p}}const Pe="fusion:chat-active-room";function Wt(s){return[...s].sort((r,l)=>new Date(l.updatedAt).getTime()-new Date(r.updatedAt).getTime())}function rt(s,r){const l=s.findIndex(u=>u.id===r.id);if(l===-1)return Wt([r,...s]);const i=[...s];return i[l]=r,Wt(i)}function Le(s){try{return JSON.parse(s.data)}catch{return null}}function Hn(s,r){return{id:`temp-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,roomId:s,role:"user",content:r,thinkingOutput:null,metadata:null,senderAgentId:null,mentions:[],createdAt:new Date().toISOString()}}function Bn(s,r){const[l,i]=n.useState([]),[u,x]=n.useState(!0),[R,E]=n.useState(null),[D,C]=n.useState(null),[Q,S]=n.useState([]),[L,g]=n.useState([]),[ee,N]=n.useState(!1),_=n.useRef(l),b=n.useRef(D),M=n.useRef(0),A=n.useRef(s);_.current=l,b.current=D,A.current!==s&&(A.current=s,M.current+=1);const T=n.useCallback(async(p,o=!0)=>{if(!p){S([]),g([]),N(!1);return}o&&g([]),N(!0);try{const[c,m]=await Promise.all([mn(p.id,s),_t(p.id,{limit:100},s)]);S(c.members),g(m.messages)}catch{S([]),g([])}finally{N(!1)}},[s]),$=n.useCallback(async()=>{x(!0);try{const p=await hn({},s),o=Wt(p.rooms);i(o),E(null);const c=Es(Pe,s);if(c){const m=o.find(y=>y.id===c)??null;m?(C(m),T(m,!0)):qe(Pe,s)}}catch(p){const o=p instanceof Error?p.message:"Failed to load chat rooms";E(o),r?.(o,"error")}finally{x(!1)}},[r,T,s]),J=n.useCallback(p=>{if(!p){C(null),qe(Pe,s),T(null,!0);return}const o=_.current.find(c=>c.id===p)??null;C(o),o&&(Kt(Pe,o.id,s),T(o,!0))},[T,s]),Y=n.useCallback(async p=>{const c=(await fn({name:p.name,memberAgentIds:p.memberAgentIds},s)).room;return i(m=>rt(m,c)),C(c),Kt(Pe,c.id,s),await T(c,!0),c},[T,s]),z=n.useCallback(async p=>{await gn(p,s),i(o=>o.filter(c=>c.id!==p)),b.current?.id===p&&(C(null),S([]),g([]),qe(Pe,s))},[s]),h=n.useCallback(async(p,o)=>{const c=b.current,m=c?.id;if(!m)throw new Error("Select a room before sending a message");const y=Hn(m,p);b.current?.id===m&&g(k=>[...k,y]);try{const k=await pn(m,{content:p,...o?.attachments?{attachments:o.attachments}:{}},s);k.message?.createdAt&&c&&i(F=>rt(F,{...c,updatedAt:k.message.createdAt})),b.current?.id===m&&g(F=>F.map(G=>G.id===y.id?k.message:G));const Z=await _t(m,{limit:100},s);if(b.current?.id!==m)return;g(Z.messages)}catch(k){try{const Z=await _t(m,{limit:100},s);b.current?.id===m&&g(Z.messages)}catch{b.current?.id===m&&g(Z=>Z.filter(F=>F.id!==y.id))}throw k}},[s]);return n.useEffect(()=>{$()},[$]),n.useEffect(()=>{const p=M.current,o=s?`/api/events?projectId=${encodeURIComponent(s)}`:"/api/events";return Ds(o,{onReconnect:()=>{$()},events:{"chat:room:created":c=>{if(M.current!==p)return;const m=Le(c);m&&i(y=>rt(y,m))},"chat:room:updated":c=>{if(M.current!==p)return;const m=Le(c);m&&(i(y=>rt(y,m)),b.current?.id===m.id&&C(m))},"chat:room:deleted":c=>{if(M.current!==p)return;const m=Le(c);m?.id&&(i(y=>y.filter(k=>k.id!==m.id)),b.current?.id===m.id&&(C(null),S([]),g([]),qe(Pe,s)))},"chat:room:member:added":c=>{if(M.current!==p)return;const m=Le(c);!m||b.current?.id!==m.roomId||S(y=>y.some(k=>k.agentId===m.agentId)?y:[...y,m])},"chat:room:member:removed":c=>{if(M.current!==p)return;const m=Le(c);!m||b.current?.id!==m.roomId||S(y=>y.filter(k=>k.agentId!==m.agentId))},"chat:room:message:added":c=>{if(M.current!==p)return;const m=Le(c);m&&(i(y=>{const k=y.find(Z=>Z.id===m.roomId);return k?rt(y,{...k,updatedAt:m.createdAt}):y}),b.current?.id===m.roomId&&g(y=>{if(y.some(k=>k.id===m.id))return y;if(m.role==="user"){const k=y.findIndex(Z=>Z.role==="user"&&Z.id.startsWith("temp-")&&Z.content.trim()===m.content.trim());if(k>=0){const Z=[...y];return Z[k]=m,Z}}return[...y,m]}))},"chat:room:message:updated":c=>{if(M.current!==p)return;const m=Le(c);!m||b.current?.id!==m.roomId||g(y=>y.map(k=>k.id===m.id?m:k))},"chat:room:message:deleted":c=>{if(M.current!==p)return;const m=Le(c);m?.id&&g(y=>y.filter(k=>k.id!==m.id))}}})},[s,$]),n.useEffect(()=>{D&&(l.some(p=>p.id===D.id)||(C(null),S([]),g([]),qe(Pe,s)))},[D,s,l]),{rooms:l,roomsLoading:u,roomsError:R,activeRoom:D,activeRoomMembers:Q,messages:L,messagesLoading:ee,selectRoom:J,createRoom:Y,deleteRoom:z,sendRoomMessage:h,refreshRooms:$}}function Gn(s,r=[]){const l=s.trim().replace(/^#/,"");if(!l)return{ok:!1,error:"Room name is required."};if(/[A-Z]/.test(l))return{ok:!1,error:"Use lowercase letters only."};const i=l.toLowerCase();return i.length>80?{ok:!1,error:"Room names can be at most 80 characters."}:/^[a-z0-9_-]+$/.test(i)?/^[-_]|[-_]$/.test(i)?{ok:!1,error:"Room names cannot start or end with a hyphen or underscore."}:r.some(u=>u.toLowerCase()===i)?{ok:!1,error:"A room with this name already exists."}:{ok:!0,name:i}:{ok:!1,error:"Use lowercase letters, numbers, hyphens, or underscores only."}}function Kn({isOpen:s,onClose:r,onCreate:l,projectId:i,existingRoomNames:u=[]}){const[x,R]=n.useState(""),[E,D]=n.useState([]),[C,Q]=n.useState(""),[S,L]=n.useState([]),[g,ee]=n.useState(!1),[N,_]=n.useState(null),[b,M]=n.useState(!1),A=n.useRef(null),T=n.useRef(null);n.useEffect(()=>{s&&(T.current=document.activeElement instanceof HTMLElement?document.activeElement:null,ee(!0),_(null),yt(void 0,i).then(o=>D(o)).catch(()=>{D([]),_("Failed to load agents.")}).finally(()=>ee(!1)))},[s,i]),n.useEffect(()=>{if(!s){R(""),Q(""),L([]),_(null),M(!1);return}const o=window.requestAnimationFrame(()=>A.current?.focus());return()=>window.cancelAnimationFrame(o)},[s]),n.useEffect(()=>{if(!s)return;const o=c=>{c.key==="Escape"&&r()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[s,r]),n.useEffect(()=>{s||T.current?.focus()},[s]);const $=n.useMemo(()=>Gn(x,u),[x,u]),J=n.useMemo(()=>{const o=C.trim().toLowerCase();return o?E.filter(c=>c.name.toLowerCase().includes(o)):E},[E,C]),Y=n.useMemo(()=>E.filter(o=>S.includes(o.id)),[E,S]),z=$.ok&&S.length>0&&!b&&!g;if(!s)return null;const h=o=>{b||L(c=>c.includes(o)?c.filter(m=>m!==o):[...c,o])},p=async()=>{if(!$.ok){_($.error);return}if(S.length===0){_("Select at least one member.");return}_(null),M(!0);try{await l({name:$.name,displayName:`#${$.name}`,memberAgentIds:S}),r()}catch(o){_(o instanceof Error?o.message:"Failed to create room.")}finally{M(!1)}};return en.createPortal(t.jsx("div",{className:"modal-overlay open",onClick:o=>o.target===o.currentTarget&&r(),children:t.jsxs("div",{className:"modal modal-lg create-room-modal",role:"dialog","aria-modal":"true","aria-label":"Create room",onClick:o=>o.stopPropagation(),children:[t.jsxs("div",{className:"modal-header",children:[t.jsx("h3",{children:"Create room"}),t.jsx("button",{type:"button",className:"modal-close","aria-label":"Close",onClick:r,children:"×"})]}),t.jsxs("div",{className:"form-group create-room-modal-name-group",children:[t.jsx("label",{htmlFor:"create-room-name",children:"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:A,id:"create-room-name",className:"input",value:x,disabled:b,onChange:o=>{const c=o.target.value.replace(/^#/,"").replace(/\s+/g,"-").toLowerCase();R(c)}})]}),!$.ok&&t.jsx("div",{className:"form-error",children:$.error})]}),t.jsxs("div",{className:"form-group",children:[t.jsx("label",{htmlFor:"create-room-member-search",children:"Members"}),t.jsx("input",{id:"create-room-member-search",className:"input",placeholder:"Search agents",value:C,disabled:b,onChange:o=>Q(o.target.value)})]}),Y.length>0&&t.jsx("div",{className:"create-room-modal-selected","data-testid":"create-room-selected-chips",children:Y.map(o=>t.jsxs("button",{type:"button",className:"btn btn-sm create-room-modal-chip",onClick:()=>h(o.id),disabled:b,children:[o.name," ×"]},o.id))}),t.jsx("div",{className:"create-room-modal-member-list","data-testid":"create-room-member-list",children:g?t.jsx("div",{className:"create-room-modal-empty",children:"Loading agents..."}):J.length===0?t.jsx("div",{className:"create-room-modal-empty",children:E.length===0?"No agents in this project yet.":"No agents match your search."}):J.map(o=>{const c=S.includes(o.id);return t.jsxs("button",{type:"button",className:`create-room-modal-member-row${c?" create-room-modal-member-row--selected":""}`,onClick:()=>h(o.id),disabled:b,children:[t.jsx($s,{agent:o,size:20}),t.jsx("span",{children:o.name}),t.jsx("span",{className:"create-room-modal-member-role",children:o.role})]},o.id)})}),N&&t.jsx("div",{className:"form-group",children:t.jsx("div",{className:"form-error",children:N})}),t.jsxs("div",{className:"modal-actions",children:[t.jsx("button",{type:"button",className:"btn",onClick:r,disabled:b,children:"Cancel"}),t.jsx("button",{type:"button",className:"btn btn-primary",onClick:()=>void p(),disabled:!z,children:b?"Creating...":"Create room"})]})]})}),document.body)}const Wn=320;function Vn(s){return Math.min(s,Wn)}function Ls(s){const r=new Date(s),i=new Date().getTime()-r.getTime(),u=Math.floor(i/1e3),x=Math.floor(u/60),R=Math.floor(x/60),E=Math.floor(R/24);return u<60?"just now":x<60?`${x}m ago`:R<24?`${R}h ago`:E<7?`${E}d ago`:r.toLocaleDateString()}function js(s,r){if(!s||!r)return null;const l=r.toLowerCase();if(l.includes("claude")){let u=r.replace(/^claude[- ]/i,"Claude ").replace(/sonnet[- ](\d+)[- ](\d+)/i,"Sonnet $1.$2").replace(/sonnet[- ](\d+)/i,"Sonnet $1").replace(/haiku[- ](\d+)/i,"Haiku $1").replace(/opus[- ](\d+)/i,"Opus $1").replace(/sonnet/i,"Sonnet").replace(/haiku/i,"Haiku").replace(/opus/i,"Opus").replace(/-/g," ").trim();return u=u.replace(/\s+/g," "),u.length>30?u.slice(0,30)+"…":u}if(l.includes("gpt")||l.includes("openai")){const u=r.replace(/^gpt-4-turbo$/i,"GPT-4 Turbo").replace(/^gpt-4o-mini$/i,"GPT-4o Mini").replace(/^gpt-4o$/i,"GPT-4o").replace(/^gpt-4$/i,"GPT-4").replace(/^gpt-o1-preview$/i,"GPT-o1 Preview").replace(/^gpt-o1-mini$/i,"GPT-o1 Mini").replace(/^gpt-o1$/i,"GPT-o1").replace(/^gpt/i,"GPT").trim();return u.length>30?u.slice(0,30)+"…":u}if(l.includes("gemini")){const u=r.replace(/^gemini[- ]/i,"Gemini ").replace(/pro[- ](\d+)[- ](\d+)/i,"Pro $1.$2").replace(/pro[- ](\d+)/i,"Pro $1").replace(/-/g," ").replace(/\s+/g," ").trim();return u.length>30?u.slice(0,30)+"…":u}const i=r.replace(/-/g," ").replace(/^\w/,u=>u.toUpperCase()).replace(/\s+/g," ").trim();return i.length>30?i.slice(0,30)+"…":i}function vt(s,r){return s.length<=r?s:`${s.slice(0,r)}…`}function qn(s){if(!s)return null;const r=Object.entries(s);return r.length===0?null:r.map(([l,i])=>{const u=typeof i=="string"?i:(()=>{try{return JSON.stringify(i)}catch{return String(i)}})();return`${l}=${vt(u,50)}`}).join(", ")}function Xn(s){if(s===void 0)return null;if(typeof s=="string")return vt(s,200);try{return vt(JSON.stringify(s),200)}catch{return vt(String(s),200)}}function Jn(s){if(!s)return null;if(s.kind==="mailbox"||s.kind==="mailbox-message"){const r=typeof window>"u"?"/":window.location.pathname||"/",l=new URLSearchParams(typeof window>"u"?"":window.location.search);return l.set("view","mailbox"),l.set("mailbox-message",s.id),`${r}?${l.toString()}#message-${encodeURIComponent(s.id)}`}return null}function Yn(s){if(!s)return null;const r=s.label??`${s.kind} ${s.id}`,l=Jn(s),i=`chat-failure-reference-${s.kind}-${s.id}`.replace(/[^a-zA-Z0-9_-]+/g,"-").toLowerCase();return t.jsxs("div",{className:"chat-message-failure-reference",children:[t.jsx("span",{className:"chat-message-failure-reference-label",children:"Reference"}),t.jsx("span",{className:"chat-message-failure-reference-value",children:r}),l?t.jsx("a",{className:"btn btn-sm chat-message-failure-reference-link",href:l,children:"Open mailbox message"}):t.jsxs("details",{className:"chat-message-failure-reference-details",children:[t.jsx("summary",{className:"btn btn-sm chat-message-failure-reference-link",children:"View failure details"}),t.jsxs("dl",{className:"chat-message-failure-reference-meta",id:i,children:[t.jsxs("div",{children:[t.jsx("dt",{children:"Kind"}),t.jsx("dd",{children:s.kind})]}),t.jsxs("div",{children:[t.jsx("dt",{children:"ID"}),t.jsx("dd",{children:s.id})]}),s.label&&t.jsxs("div",{children:[t.jsx("dt",{children:"Label"}),t.jsx("dd",{children:s.label})]})]})]})]})}function Fs(s){if(!s||s.length===0)return null;const r=(S,L)=>{const g=S.status==="running",ee=S.status==="completed"&&S.isError,N=qn(S.args),_=Xn(S.result),b=g?N:_?`result: ${_}`:N?`args: ${N}`:null,M=g?"running":ee?"error":"completed";return t.jsxs("details",{className:`chat-tool-call${g?" chat-tool-call--running":""}${ee?" chat-tool-call--error":""}`,open:g,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"chat-tool-call-status-dot","aria-hidden":"true"}),t.jsx("span",{className:"chat-tool-call-name",title:S.toolName,children:S.toolName}),b&&t.jsx("span",{className:"chat-tool-call-preview",title:b,children:b}),t.jsx("span",{className:"chat-tool-call-status-text",children:M})]}),t.jsxs("div",{className:"chat-tool-call-content",children:[N&&t.jsxs("div",{className:"chat-tool-call-row",children:[t.jsx("span",{className:"chat-tool-call-label",children:"args"}),t.jsx("span",{className:"chat-tool-call-value",children:N})]}),_&&t.jsxs("div",{className:`chat-tool-call-row${ee?" chat-tool-call-row--error":""}`,children:[t.jsx("span",{className:"chat-tool-call-label",children:"result"}),t.jsx("span",{className:"chat-tool-call-value",children:_})]})]})]},`${S.toolName}-${L}`)},l="chat-tool-calls";if(s.length===1)return t.jsxs("div",{className:l,"data-testid":"chat-tool-calls",children:[t.jsxs("div",{className:"chat-tool-calls-header",children:[t.jsx(Ss,{size:12,"aria-hidden":"true"}),t.jsx("span",{children:"Tool calls"})]}),r(s[0],0)]});const i=s.filter(S=>S.status==="running").length,u=s.filter(S=>S.status==="completed"&&S.isError).length,x=i>0,R=Array.from(new Set(s.map(S=>S.toolName))),E=R.slice(0,5),D=Math.max(0,R.length-E.length),C=D>0?`${E.join(", ")}, +${D} more`:E.join(", "),Q=x?`(${i} running)`:u>0?`(${u} ${u===1?"error":"errors"})`:null;return t.jsx("div",{className:l,"data-testid":"chat-tool-calls",children:t.jsxs("details",{className:"chat-tool-calls-group","data-testid":"chat-tool-calls-group",open:x,children:[t.jsxs("summary",{className:"chat-tool-calls-group-summary",children:[t.jsx(Ss,{size:12,"aria-hidden":"true"}),t.jsxs("span",{className:"chat-tool-calls-count",children:[s.length," tool calls"]}),t.jsx("span",{className:"chat-tool-calls-names",title:C,children:C}),Q&&t.jsx("span",{className:"chat-tool-calls-group-status",children:Q})]}),s.map((S,L)=>r(S,L))]})})}const zs={p:({children:s,...r})=>t.jsx("p",{...r,children:ws(s)}),li:({children:s,...r})=>t.jsx("li",{...r,children:ws(s)}),pre:({children:s,...r})=>t.jsx("pre",{...r,className:"chat-markdown-pre",children:s}),code:({children:s,...r})=>{const l=typeof s=="string"?s:tn.Children.toArray(s).join(""),i=xt(l);return i.length===1&&typeof i[0]=="string"?t.jsx("code",{...r,children:s}):t.jsx("code",{...r,children:i})},table:({children:s,...r})=>t.jsx("table",{...r,className:"chat-markdown-table",children:s})},Xe="__fn_agent__",Qn=280,pt=180,bt=500,Ms="fusion:chat-sidebar-width",Bt="fusion:chat-scope",Zn="fusion:chat-draft:";function Rs(s,r){return r?`${Zn}${s}:${r}`:null}function As(s){if(!s)return"";try{return localStorage.getItem(s)??""}catch{return""}}const ea=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function Ts(s){const r=/(^|[\s])\/([^\s]*)$/.exec(s);if(!r)return null;const l=r[1]??"",i=r[2]??"",u=r.index+l.length;return{filter:i,start:u,end:s.length}}function ta(s,r){const l=s.slice(0,r),i=/(^|[\s\n])@([\w-]*)$/.exec(l);if(!i)return null;const u=i[2]??"",x=l.length-u.length-1;return{filter:u,start:x,end:r}}function sa({projectId:s,onClose:r,onCreate:l}){const[i,u]=n.useState("agent"),[x,R]=n.useState([]),[E,D]=n.useState(!0),[C,Q]=n.useState(""),[S,L]=n.useState([]),[g,ee]=n.useState(!0),[N,_]=n.useState(""),[b,M]=n.useState([]),[A,T]=n.useState([]);n.useEffect(()=>{let h=!1;return D(!0),yt(void 0,s).then(p=>{h||R(p)}).catch(()=>{h||R([])}).finally(()=>{h||D(!1)}),()=>{h=!0}},[s]),n.useEffect(()=>{ee(!0),Ln().then(h=>{L(h.models),M(h.favoriteProviders),T(h.favoriteModels)}).catch(()=>{L([]),M([]),T([])}).finally(()=>{ee(!1)})},[]);const $=n.useCallback(async h=>{const p=b,c=p.includes(h)?p.filter(m=>m!==h):[h,...p];M(c);try{await Cs({favoriteProviders:c,favoriteModels:A})}catch{M(p)}},[b,A]),J=n.useCallback(async h=>{const p=A,c=p.includes(h)?p.filter(m=>m!==h):[h,...p];T(c);try{await Cs({favoriteProviders:b,favoriteModels:c})}catch{T(p)}},[A,b]),Y=h=>{if(h.preventDefault(),i==="agent"){if(!C)return;l({agentId:C});return}if(!N)return;const p=N.indexOf("/");if(p<=0)return;const o=N.slice(0,p),c=N.slice(p+1);l({agentId:Xe,modelProvider:o,modelId:c})},z=i==="agent"?!C:!N;return t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:r,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:h=>h.stopPropagation(),children:[t.jsx("h3",{children:"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${i==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{u("agent"),_("")},children:"Agent"}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${i==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{u("model"),Q("")},children:"Model"})]}),t.jsxs("form",{onSubmit:Y,children:[i==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",E?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):x.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:x.map(h=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${C===h.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>Q(h.id),"data-testid":`agent-option-${h.id}`,children:[t.jsx(ot,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:h.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:h.role})]},h.id))})]}),i==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:g?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):t.jsx(Fn,{models:S,value:N,onChange:_,label:"Model",placeholder:"Select a model",favoriteProviders:b,onToggleFavorite:$,favoriteModels:A,onToggleModelFavorite:J})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:r,children:"Cancel"}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:z,children:"Create"})]})]})]})})}const Gt=n.memo(function({message:r,forcePlain:l,agentName:i,hideAssistantIdentity:u,showAssistantModelTag:x,activeModelTag:R,activeModelProvider:E,activeSessionId:D,mentionAgentsByName:C,roomContext:Q,copyAction:S}){const L=r.role==="assistant",g=L?r.failureInfo:void 0,ee=L&&(!u||!!g),N=n.useMemo(()=>{if(L)return null;const M=r.content,A=/@([\w-]+)/g,T=[];let $=0,J=A.exec(M);for(;J;){const[Y,z=""]=J,h=J.index;h>$&&T.push(M.slice($,h));const p=z.replace(/_/g," ").toLowerCase(),o=C.get(p);if(o){const c=!!(Q&&!Q.memberIds.has(o.id)),m=c?`Not a member of ${Q?.roomName}`:void 0;T.push(t.jsxs("span",{className:`chat-mention-chip${c?" chat-mention-chip--non-member":""}`,title:m,"aria-label":m,children:["@",o.name.replace(/\s+/g,"_")]},`${o.id}-${h}`))}else T.push(Y);$=h+Y.length,J=A.exec(M)}return $<M.length&&T.push(M.slice($)),T.length===0?M:T},[L,r.content,C,Q]),_=n.useMemo(()=>{const M=r.attachments;if(!M||M.length===0||!D)return null;const A=`/api/chat/sessions/${encodeURIComponent(D)}/attachments/`;return t.jsx("div",{className:"chat-message-attachments",children:M.map(T=>{const $=T.mimeType.startsWith("image/"),J=T.id||T.filename,Y=`${A}${encodeURIComponent(T.filename)}`;return $?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:Y,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:Y,alt:T.originalName})},J):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:Y,target:"_blank",rel:"noopener noreferrer",children:[t.jsx($n,{size:14}),t.jsx("span",{children:T.originalName})]},J)})})},[r.attachments,D]),b=n.useMemo(()=>L?g?t.jsxs("div",{className:"chat-message-content chat-message-content--failure",children:[t.jsxs("div",{className:"chat-message-failure-summary-row",children:[t.jsx("span",{className:"status-dot status-dot--error","aria-hidden":"true"}),t.jsx("span",{className:"chat-message-failure-label",children:"Response failed"})]}),t.jsx("div",{className:"chat-message-failure-summary",children:g.summary}),(g.errorClass||g.code)&&t.jsxs("div",{className:"chat-message-failure-badges",children:[g.errorClass&&t.jsx("span",{className:"chat-message-failure-badge",children:g.errorClass}),g.code&&t.jsx("span",{className:"chat-message-failure-badge",children:g.code})]}),(g.detail||g.reference)&&t.jsxs("details",{className:"chat-message-failure-details",children:[t.jsxs("summary",{children:[t.jsx(In,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:"Failure details"})]}),g.detail&&t.jsx("pre",{className:"chat-message-failure-detail",children:xt(g.detail)}),Yn(g.reference)]})]}):l?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:r.content}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(Is,{remarkPlugins:[Ps],components:zs,children:r.content})}):null,[g,l,L,r.content]);return t.jsxs("div",{className:`chat-message chat-message--${r.role}${g?" chat-message--failure":""}`,"data-testid":`chat-message-${r.id}`,children:[ee&&t.jsxs("div",{className:"chat-message-avatar",children:[E?t.jsx(it,{provider:E,size:"sm"}):t.jsx(ot,{size:14}),t.jsx("span",{children:i}),x&&R&&t.jsx("span",{className:"chat-model-tag",children:R})]}),L?b:t.jsx("div",{className:"chat-message-content",children:N}),!g&&S,Fs(r.toolCalls),r.thinkingOutput&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:xt(r.thinkingOutput)})]}),_,t.jsx("div",{className:"chat-message-time",children:Ls(r.createdAt)})]})});function ca({projectId:s,addToast:r,experimentalFeatures:l}){const{activeSession:i,sessionsLoading:u,messages:x,messagesLoading:R,isStreaming:E,streamingText:D,streamingThinking:C,streamingToolCalls:Q,selectSession:S,createSession:L,archiveSession:g,deleteSession:ee,sendMessage:N,stopStreaming:_,pendingMessage:b,clearPendingMessage:M,searchQuery:A,setSearchQuery:T,filteredSessions:$}=On(s,r),[J,Y]=n.useState(!1),z=l?.chatRooms===!0,[h,p]=n.useState(()=>{try{if(localStorage.getItem(Bt)==="rooms"&&z)return"rooms"}catch{}return"direct"}),o=Bn(s,r),[c,m]=n.useState(()=>{const e=Rs(h,h==="rooms"?o.activeRoom?.id:i?.id);return As(e)}),[y,k]=n.useState(null),[Z,F]=n.useState(null),[G,ke]=n.useState(null),[ue,ve]=n.useState(!0),[ie,Ue]=n.useState(Qn),[Fe,te]=n.useState(!1),[me,wt]=n.useState(new Map),[ne,oe]=n.useState([]),[Oe,ct]=n.useState(!0),[je,Me]=n.useState(!1),[Je,He]=n.useState(""),[ze,Re]=n.useState(0),[xe,ye]=n.useState(""),[fe,f]=n.useState(!1),[v,w]=n.useState(0),[P,se]=n.useState(-1),[H,ae]=n.useState(!1),[U,K]=n.useState([]),[W,V]=n.useState(!1),[O,q]=n.useState(!1),[re,we]=n.useState({}),[lt,Be]=n.useState(!1),{pushNav:Vt}=bn(),[,Ye]=n.useState(!1),[_s,Us]=n.useState({top:0,left:0}),B=vn({projectId:s}),St=n.useCallback(e=>{if(!e||!B.mentionActive)return;const a=e.getBoundingClientRect();Us({top:a.top-260,left:a.left+8})},[B.mentionActive]),qt=n.useRef(null),Xt=n.useRef(null),Ae=n.useRef(!1),Ct=n.useRef(null),Jt=n.useRef(null),Te=n.useRef(null),Ee=n.useRef(null),Se=n.useRef(null),ge=n.useRef(null),ce=n.useRef(null),Yt=n.useRef(null),Qt=n.useRef([]),Qe=n.useRef(0),Ze=n.useRef(new Map),I=xn()==="mobile";n.useEffect(()=>{try{const e=localStorage.getItem(Ms);if(!e)return;const a=Number.parseInt(e,10);if(Number.isNaN(a))return;const d=Math.max(pt,Math.min(bt,a));Ue(d)}catch{}},[]),n.useEffect(()=>{try{const e=localStorage.getItem(Bt);if(e==="direct"){p("direct");return}e==="rooms"&&z&&p("rooms")}catch{}},[z]),n.useEffect(()=>{if(!z&&h==="rooms"){p("direct");return}try{localStorage.setItem(Bt,h)}catch{}},[z,h]);const le=Rs(h,h==="rooms"?o.activeRoom?.id:i?.id),Nt=n.useRef(le);n.useEffect(()=>{le!==Nt.current&&(Nt.current=le,m(As(le)))},[le]),n.useEffect(()=>{if(!(!le||Nt.current!==le))try{if(c){localStorage.setItem(le,c);return}localStorage.removeItem(le)}catch{}},[le,c]);const de=z&&h==="rooms"&&!!o.activeRoom,{keyboardOverlap:dt,viewportHeight:Zt,viewportOffsetTop:es,keyboardOpen:et}=yn({enabled:I&&(!!i||de)}),ts=dt>0||es>0,ss=et&&ts?{"--keyboard-overlap":`${dt}px`,"--vv-offset-top":`${es}px`,...Zt!==null?{"--vv-height":`${Zt}px`}:{}}:{},ns=`chat-thread${et&&ts?" chat-thread--keyboard-active":""}`,pe=n.useMemo(()=>{const e=Je.trim().toLowerCase();return(e?ne.filter(d=>d.name.toLowerCase().includes(e)):ne).slice(0,10)},[ne,Je]),Ge=n.useMemo(()=>Array.from(me.values()),[me]),Ce=n.useMemo(()=>!z||h!=="rooms"||!o.activeRoom?null:{roomId:o.activeRoom.id,roomName:o.activeRoom.name,memberIds:new Set(o.activeRoomMembers.map(e=>e.agentId))},[z,h,o.activeRoom,o.activeRoomMembers]),_e=n.useMemo(()=>{const e=Ge.filter(j=>wn(j.name,xe));if(!Ce)return e;const a=e.filter(j=>Ce.memberIds.has(j.id));if(xe.trim().length===0)return a;const d=e.filter(j=>!Ce.memberIds.has(j.id));return[...a,...d]},[Ge,xe,Ce]),kt=n.useMemo(()=>{const e=new Map;for(const a of Ge)e.set(a.name.toLowerCase(),a);return e},[Ge]);n.useEffect(()=>{Re(0)},[pe]),n.useEffect(()=>{w(0)},[xe,fe]),n.useEffect(()=>()=>{Se.current!==null&&window.clearTimeout(Se.current)},[]);const as=n.useCallback(()=>{const e=ge.current;if(!e)return;const d=e.scrollTop+e.clientHeight>=e.scrollHeight-50;q(!d),Ae.current=!d},[]),he=n.useCallback(e=>{if(!e.isConnected)return;let a=0,d=0,j=-1;const X=6,be=()=>{if(e.isConnected){if(e.scrollTop=e.scrollHeight,e.scrollHeight===j?d+=1:(d=0,j=e.scrollHeight),a+=1,a>=X||d>=2){q(!1),Ae.current=!1;return}window.requestAnimationFrame(be)}};be()},[]),tt=n.useCallback(()=>{const e=ge.current;e&&he(e)},[he]);n.useLayoutEffect(()=>{Ee.current!==null&&(window.clearTimeout(Ee.current),Ee.current=null);const e=de?o.activeRoom?.id??null:i?.id??null;if(!e){Ct.current=null;return}const a={threadId:e,loaded:de?!o.messagesLoading:!R,hasMessages:de?o.messages.length>0:x.length>0},d=Ct.current,j=d?.threadId!==e,X=d?.threadId===e&&!d.loaded&&a.loaded,be=d?.threadId===e&&!d.hasMessages&&a.hasMessages;if(!(d===null||j||X||be))return;const Ne=ge.current;if(Ne)return he(Ne),de||(Ee.current=window.setTimeout(()=>{if(Ee.current=null,Ae.current)return;const We=ge.current;We&&he(We)},250)),Ct.current=a,()=>{Ee.current!==null&&(window.clearTimeout(Ee.current),Ee.current=null)}},[de,o.activeRoom?.id,o.messages.length,o.messagesLoading,i?.id,x.length,R,he]);const Os=de?o.messages:x;n.useEffect(()=>{Ae.current||tt()},[Os,D,C,E,tt]),n.useEffect(()=>{dt<=0||!ge.current||tt()},[dt,tt]),Sn(I&&et),n.useEffect(()=>{const e=()=>k(null);if(y)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[y]),n.useEffect(()=>{if(!I||!et)return;const e=a=>{a.target?.closest(".chat-messages")||a.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>{document.removeEventListener("touchmove",e)}},[I,et]),n.useEffect(()=>{if(!I||!i)return;const e=()=>{const a=ce.current;a&&document.activeElement===a&&(a.blur(),window.setTimeout(()=>{a.focus({preventScroll:!0})},0))};return document.addEventListener("visibilitychange",e),window.addEventListener("pageshow",e),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("pageshow",e)}},[I,i]),n.useEffect(()=>{const e=Jt.current;if(Jt.current=h,h!=="direct"||e!==null&&e!=="rooms")return;const a=ge.current;a&&(he(a),Ae.current=!1,q(!1))},[h,he]),n.useEffect(()=>{if(!i&&!de||de&&!I)return;const e=()=>{const d=ge.current;d&&(he(d),Ae.current=!1,q(!1),Te.current!==null&&(window.clearTimeout(Te.current),Te.current=null),Te.current=window.setTimeout(()=>{if(Te.current=null,Ae.current)return;const j=ge.current;j&&he(j)},250))},a=()=>{document.visibilityState==="visible"&&e()};return document.addEventListener("visibilitychange",a),window.addEventListener("pageshow",e),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("pageshow",e),Te.current!==null&&(window.clearTimeout(Te.current),Te.current=null)}},[I,i,de,he]),n.useEffect(()=>{if(de||typeof ResizeObserver>"u")return;const e=ge.current;if(!e)return;const a=new ResizeObserver(()=>{Ae.current||he(e)});return a.observe(e),()=>{a.disconnect()}},[de,he,i?.id,h]),n.useEffect(()=>{let e=!1;const a=s;return yt(void 0,s).then(d=>{if(e||a!==s)return;const j=new Map;for(const X of d)j.set(X.id,X);wt(j)}).catch(()=>{}),()=>{e=!0}},[s]),n.useEffect(()=>{let e=!1;return ct(!0),Cn(s).then(a=>{e||oe(a)}).catch(()=>{e||oe([])}).finally(()=>{e||ct(!1)}),()=>{e=!0}},[s]),n.useEffect(()=>{Qt.current=U},[U]),n.useEffect(()=>()=>{for(const e of Qt.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);for(const e of Ze.current.values())window.clearTimeout(e);Ze.current.clear()},[]);const ut=n.useCallback(e=>{if(!e||e.length===0)return;const a=[];for(const d of Array.from(e)){if(!ea.includes(d.type))continue;const j=d.type.startsWith("image/");a.push({file:d,previewUrl:j?URL.createObjectURL(d):""})}a.length>0&&K(d=>[...d,...a])},[]),Hs=n.useCallback(e=>{K(a=>{const d=a[e];return d?.previewUrl&&URL.revokeObjectURL(d.previewUrl),a.filter((j,X)=>X!==e)})},[]),Bs=n.useCallback(e=>{const a=e.clipboardData?.files;if(!a||a.length===0)return;const d=Array.from(a).filter(j=>j.type.startsWith("image/"));d.length!==0&&ut(d)},[ut]),Gs=n.useCallback(async e=>{try{await L(e),Y(!1),I&&ve(!1)}catch{r("Failed to create chat session","error")}},[L,r,I]),De=n.useCallback(e=>{const a=e??ce.current;a&&(a.style.height="auto",a.style.height=`${Vn(a.scrollHeight)}px`)},[]);n.useLayoutEffect(()=>{De()},[c,De]);const st=n.useCallback(()=>{if(m(""),le)try{localStorage.removeItem(le)}catch{}Me(!1),He(""),f(!1),ye(""),se(-1),K(e=>{for(const a of e)a.previewUrl&&URL.revokeObjectURL(a.previewUrl);return[]})},[le]),jt=n.useCallback(()=>{const e=c.trim(),a=U.map(d=>d.file);if(!(!e&&a.length===0||!i)){if(e==="/clear"||e==="/new"){st(),_(),M(),L({agentId:i.agentId,modelProvider:i.modelProvider??void 0,modelId:i.modelId??void 0}).catch(()=>{r("Failed to clear conversation","error")});return}st(),N(e,a)}},[c,U,i,st,_,M,L,r,N]),Mt=n.useCallback(async()=>{const e=c.trim();if(e){if(z&&h==="rooms"){if(!o.activeRoom)return;const a=c;st();try{await o.sendRoomMessage(e)}catch(d){m(a);const j=d instanceof Error&&d.message.trim()?d.message:"Failed to send room message";r(j,"error")}return}jt()}},[c,z,h,o,st,r,jt]),Rt=n.useCallback(e=>{m(a=>{const d=Ts(a);if(!d)return a;const j=`/skill:${e.name} `,X=a.slice(0,d.start)+j+a.slice(d.end);return window.requestAnimationFrame(()=>{ce.current&&(De(ce.current),ce.current.focus())}),X}),Me(!1),He(""),Re(0)},[De]),mt=n.useCallback(e=>{const a=ce.current;if(!a||P<0)return;const d=a.selectionStart??Qe.current,j=a.selectionEnd??d,X=Math.max(d,j),be=Math.min(P,X),Ne=`${`@${e.name.replace(/\s+/g,"_")}`} `,We=c.slice(0,be)+Ne+c.slice(X),Ve=be+Ne.length;m(We),f(!1),ye(""),w(0),se(-1),window.requestAnimationFrame(()=>{ce.current&&(De(ce.current),ce.current.focus(),ce.current.setSelectionRange(Ve,Ve))})},[P,c,De]),rs=n.useCallback(e=>{if(Qe.current=e.currentTarget.selectionStart??Qe.current,B.mentionActive&&B.files.length>0){if(B.handleKeyDown(e,c),e.key==="Enter"||e.key==="Tab"){const a=B.files[B.selectedIndex];if(a){const d=B.selectFile(a,c);m(d),B.dismissMention(),Ye(!1)}}return}if(fe&&e.key==="ArrowDown"){e.preventDefault(),_e.length>0&&w(a=>(a+1)%_e.length);return}if(fe&&e.key==="ArrowUp"){e.preventDefault(),_e.length>0&&w(a=>a===0?_e.length-1:a-1);return}if(fe&&e.key==="Enter"){e.preventDefault();const a=_e[v]??_e[0];a&&mt(a);return}if(fe&&e.key==="Escape"){e.preventDefault(),f(!1),ye(""),se(-1);return}if(je&&e.key==="ArrowDown"){e.preventDefault(),pe.length>0&&Re(a=>(a+1)%pe.length);return}if(je&&e.key==="ArrowUp"){e.preventDefault(),pe.length>0&&Re(a=>a===0?pe.length-1:a-1);return}if(je&&(e.key==="Enter"||e.key==="Tab")&&pe.length>0){e.preventDefault();const a=pe[ze]??pe[0];a&&Rt(a);return}if(je&&e.key==="Escape"){e.preventDefault(),Me(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Mt())},[fe,_e,v,mt,je,pe,ze,Rt,Mt,B,c]),ht=n.useCallback((e,a)=>{const d=ta(e,a);if(d){f(!0),ye(d.filter),se(d.start);return}f(!1),ye(""),se(-1)},[]),is=n.useCallback(e=>{const a=e.target,d=a.value,j=a.selectionStart??d.length;Qe.current=j,m(d);const X=Ts(d);X?(Me(!0),He(X.filter)):(Me(!1),He("")),ht(d,j),B.detectMention(d,j),Ye(B.mentionActive),B.mentionActive&&St(a),De(a)},[ht,De]),ft=n.useCallback(e=>{const a=e.currentTarget,d=a.selectionStart??a.value.length;Qe.current=d,ht(a.value,d),B.detectMention(a.value,d),Ye(B.mentionActive),B.mentionActive&&St(a)},[ht,B,St]),os=n.useCallback(e=>{e.key!=="Escape"&&ft(e)},[ft]),cs=n.useCallback(()=>{Se.current!==null&&window.clearTimeout(Se.current),Se.current=window.setTimeout(()=>{Me(!1),f(!1),ye(""),se(-1),Ye(!1),B.dismissMention(),Se.current=null},120)},[B]),ls=n.useCallback(()=>{Se.current!==null&&(window.clearTimeout(Se.current),Se.current=null),typeof window<"u"&&window.innerWidth<=768&&window.setTimeout(()=>{(window.scrollY!==0||window.scrollX!==0)&&window.scrollTo(0,0)},0)},[]),Ks=n.useCallback(async e=>{k(null);try{await g(e),r("Conversation archived","success")}catch{r("Failed to archive conversation","error")}},[g,r]),Ws=n.useCallback(async e=>{F(null),k(null);try{await ee(e),r("Conversation deleted","success")}catch{r("Failed to delete conversation","error")}},[ee,r]),nt=n.useCallback(e=>{try{localStorage.setItem(Ms,String(e))}catch{}},[]),Vs=n.useCallback(e=>{if(I)return;e.preventDefault(),e.stopPropagation();const a=e.currentTarget;typeof a.setPointerCapture=="function"&&a.setPointerCapture(e.pointerId);const d=e.clientX,j=ie;let X=j;document.body.style.userSelect="none";const be=Ne=>{const We=Ne.clientX-d,Ve=Math.max(pt,Math.min(bt,j+We));X=Ve,Ue(Ve),nt(Ve)},Ke=Ne=>{typeof a.releasePointerCapture=="function"&&a.releasePointerCapture(Ne.pointerId),document.body.style.userSelect="",document.removeEventListener("pointermove",be),document.removeEventListener("pointerup",Ke),nt(X)};document.addEventListener("pointermove",be),document.addEventListener("pointerup",Ke)},[I,nt,ie]),qs=n.useCallback(e=>{if(I||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;e.preventDefault();const a=e.shiftKey?50:10,d=e.key==="ArrowLeft"?-a:a,j=Math.max(pt,Math.min(bt,ie+d));Ue(j),nt(j)},[I,nt,ie]),ds=n.useCallback(e=>{S(e),Be(!1),I&&ve(!1)},[S,I]),At=n.useCallback(()=>{S(""),ve(!0),Be(!1)},[S]),Tt=n.useCallback(()=>{o.selectRoom(null),ve(!0),Be(!1)},[o]),Xs=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(Pn,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>Y(!0),children:[t.jsx(at,{size:16}),"New Chat"]})]}),$e=js(i?.modelProvider,i?.modelId),Ie=i?.modelProvider??null,Et=!!(i||E||x.length>0),gt=h==="rooms"?de:!!i,us=n.useRef(gt);n.useEffect(()=>{const e=us.current;us.current=gt,I&&(e||!gt||Vt({type:"view",revert:h==="rooms"?Tt:At}))},[h,At,Tt,gt,I,Vt]);const Dt=i?.agentId===Xe?$e??"Fusion":i?.title||me.get(i?.agentId??"")?.name||i?.agentId||"Chat",ms=!!($e&&$e!==Dt),Js=I&&h==="direct"&&!!i,$t=me.get(i?.agentId??"")?.name||(i?.agentId===Xe?$e??"Fusion":i?.agentId?.slice(0,30)??"Fusion"),It=!1,Pt=i?.agentId===Xe,Ys=b.length>50?`${b.slice(0,50)}…`:b,Qs=n.useCallback(()=>{ae(e=>!e)},[]);n.useEffect(()=>{if(!lt)return;const e=a=>{Xt.current?.contains(a.target)||Be(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[lt]),n.useEffect(()=>{(!I||h!=="direct"||ue)&&Be(!1)},[I,h,ue]);const Lt=n.useCallback((e,a)=>{const d=Ze.current.get(e);d&&window.clearTimeout(d),we(X=>({...X,[e]:a}));const j=window.setTimeout(()=>{we(X=>{const{[e]:be,...Ke}=X;return Ke}),Ze.current.delete(e)},2e3);Ze.current.set(e,j)},[]),hs=n.useCallback(async(e,a)=>{try{if(!navigator.clipboard?.writeText)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(a),Lt(e,"success")}catch{Lt(e,"error")}},[Lt]),Zs=n.useCallback((e,a=!1)=>a?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:e}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(Is,{remarkPlugins:[Ps],components:zs,children:e})}),[]),Ft=i?.agentId===Xe,zt=n.useCallback((e,a,d)=>t.jsx("button",{type:"button",className:`btn-icon chat-message-copy-action${re[e]==="success"?" chat-message-copy-action--success":""}${re[e]==="error"?" chat-message-copy-action--error":""}`,"data-testid":d??`chat-copy-response-${e}`,"aria-label":re[e]==="success"?"Response copied":re[e]==="error"?"Copy failed":"Copy response",onClick:()=>{hs(e,a)},children:re[e]==="success"?t.jsx(Nn,{size:14}):t.jsx(kn,{size:14})}),[re,hs]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${ue?"":" chat-sidebar--hidden"}`,style:I?void 0:{width:`${ie}px`},children:[z&&t.jsxs("div",{className:"chat-sidebar-scope-toggle",role:"tablist","data-testid":"chat-sidebar-scope-toggle",children:[t.jsx("button",{type:"button",role:"tab",className:`chat-sidebar-scope-btn${h==="direct"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":h==="direct","data-testid":"chat-sidebar-scope-direct",onClick:()=>p("direct"),children:"Direct"}),t.jsx("button",{type:"button",role:"tab",className:`chat-sidebar-scope-btn${h==="rooms"?" chat-sidebar-scope-btn--active":""}`,"aria-selected":h==="rooms","data-testid":"chat-sidebar-scope-rooms",onClick:()=>p("rooms"),children:"Rooms"})]}),!z||h==="direct"?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"chat-sidebar-search-container",children:t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(jn,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:A,onChange:e=>T(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:u?t.jsx("div",{className:"chat-empty-state chat-empty-state--padded",children:"Loading..."}):$.length===0?t.jsx("div",{className:"chat-empty-state chat-empty-state--padded",children:"No conversations yet"}):$.map(e=>t.jsxs("div",{className:`chat-session-item${i?.id===e.id?" chat-session-item--active":""}`,onClick:()=>ds(e.id),onContextMenu:a=>{a.preventDefault(),k({sessionId:e.id,x:a.clientX,y:a.clientY})},"data-testid":`chat-session-${e.id}`,children:[t.jsx("button",{className:"chat-session-delete-btn",onClick:a=>{a.stopPropagation(),F(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(Ut,{size:14})}),t.jsx("div",{className:"chat-session-title",children:e.title||"Untitled"}),t.jsx("div",{className:"chat-session-preview",children:e.lastMessagePreview||"No messages"}),t.jsxs("div",{className:"chat-session-meta",children:[t.jsxs("span",{className:"chat-session-meta-model",children:[e.modelProvider&&t.jsx(it,{provider:e.modelProvider,size:"sm"}),t.jsx("span",{children:me.get(e.agentId)?.name||(e.agentId===Xe?js(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))})]}),t.jsx("span",{children:e.updatedAt?Ls(e.updatedAt):""})]})]},e.id))})]}):t.jsxs("div",{className:"chat-sidebar-rooms","data-testid":"chat-sidebar-rooms",children:[!I&&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:()=>te(!0),children:[t.jsx(at,{size:14}),"Create room"]})}),o.rooms.length===0?t.jsx("div",{className:"chat-sidebar-rooms-empty","data-testid":"chat-sidebar-rooms-empty",children:"No rooms yet."}):t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:o.rooms.map(e=>{const a=o.activeRoom?.id===e.id;return t.jsxs("div",{role:"button",tabIndex:0,className:`chat-room-item${a?" chat-room-item--active":""}`,"data-testid":`chat-room-item-${e.slug}`,onClick:()=>{o.selectRoom(e.id),I&&ve(!1)},onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),o.selectRoom(e.id),I&&ve(!1))},children:[t.jsxs("span",{className:"chat-room-item-details",children:[t.jsxs("span",{className:"chat-room-item-name",children:["#",e.name]}),a?t.jsxs("span",{className:"chat-room-item-meta",children:[o.activeRoomMembers.length," ",o.activeRoomMembers.length===1?"member":"members"]}):null]}),t.jsx("button",{type:"button",className:"btn-icon chat-room-item-delete","data-testid":`chat-room-delete-${e.slug}`,"aria-label":`Delete room ${e.name}`,onClick:d=>{d.stopPropagation(),ke(e.id)},children:t.jsx(Ut,{size:14})})]},e.id)})})]}),h==="rooms"?I?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:()=>te(!0),children:[t.jsx(at,{size:14}),"Create room"]})}):null:t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>Y(!0),"data-testid":"chat-new-btn",children:[t.jsx(at,{size:14}),"New Chat"]})})]}),!I&&ue&&t.jsx("div",{className:"chat-sidebar-resize-handle",role:"separator","aria-orientation":"vertical","aria-valuemin":pt,"aria-valuemax":bt,"aria-valuenow":ie,"aria-label":"Resize chat sidebar",tabIndex:0,onPointerDown:Vs,onKeyDown:qs}),y&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:y.y,left:y.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>Ks(y.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Mn,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{k(null),F(y.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(Ut,{size:14}),"Delete"]})]}),Z&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>F(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Conversation?"}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:"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:()=>F(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void Ws(Z),children:"Delete"})]})]})}),z&&G&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>ke(null),children:t.jsxs("div",{className:"chat-new-dialog chat-view-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Room?"}),t.jsx("p",{className:"chat-view-delete-dialog-copy",children:"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:()=>ke(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>{(async()=>{try{await o.deleteRoom(G),ke(null)}catch{r("Failed to delete room","error")}})()},children:"Delete"})]})]})}),z&&h==="rooms"?t.jsxs("div",{className:ns,style:ss,children:[o.activeRoom?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"chat-room-thread-header",children:[I&&t.jsx("button",{className:"btn-icon",onClick:Tt,"data-testid":"chat-back-btn",children:t.jsx(bs,{size:16})}),t.jsxs("div",{className:"chat-thread-header-title",children:["#",o.activeRoom.name]}),t.jsx("div",{className:"chat-room-thread-members",children:o.activeRoomMembers.map(e=>t.jsx($s,{agent:me.get(e.agentId)??{id:e.agentId,name:e.agentId.slice(0,30)}},e.agentId))})]}),t.jsxs("div",{className:"chat-messages",ref:ge,onScroll:as,children:[o.messagesLoading?t.jsx("div",{className:"chat-empty-state",children:"Loading messages..."}):o.messages.length===0?t.jsx("div",{className:"chat-empty-state",children:"No messages yet. Start the conversation!"}):o.messages.map(e=>{const a=e.senderAgentId?me.get(e.senderAgentId)?.name??e.senderAgentId.slice(0,30):"You",d={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(Gt,{message:d,forcePlain:H,agentName:a,hideAssistantIdentity:!1,showAssistantModelTag:!1,activeModelTag:null,activeModelProvider:null,activeSessionId:o.activeRoom?.id??null,mentionAgentsByName:kt,roomContext:Ce},e.id)}),t.jsx("div",{ref:qt})]})]}):t.jsx("div",{className:"chat-room-empty-pane","data-testid":"chat-rooms-empty-pane",children:"Select a room or create one"}),o.activeRoom&&t.jsx("div",{className:"chat-input-area",children:t.jsxs("div",{className:"chat-input-row",children:[t.jsxs("div",{className:"chat-input-wrapper",children:[t.jsx("textarea",{ref:ce,className:"chat-input-textarea",placeholder:"Type a message...",value:c,onChange:is,onKeyDown:rs,onKeyUp:os,onClick:ft,onBlur:cs,onFocus:ls,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||document.activeElement!==e.currentTarget&&(e.preventDefault(),e.currentTarget.focus({preventScroll:!0}))},rows:1,"data-testid":"chat-input"}),t.jsx(vs,{agents:Ge,filter:xe,highlightedIndex:v,visible:fe,onSelect:mt,position:"below",roomMemberIds:Ce?.memberIds,roomName:Ce?.roomName})]}),t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{e.pointerType&&e.pointerType!=="mouse"&&e.preventDefault()},onMouseDown:e=>{e.preventDefault()},onClick:()=>{Mt()},disabled:!c.trim(),"data-testid":"chat-send-btn",style:{touchAction:"manipulation"},children:t.jsx(xs,{size:16})})]})})]}):t.jsxs("div",{className:ns,style:ss,children:[(Et||!I)&&t.jsxs("div",{className:"chat-thread-header",children:[I&&Et&&t.jsx("button",{className:"btn-icon",onClick:At,"data-testid":"chat-back-btn",children:t.jsx(bs,{size:16})}),t.jsx("div",{className:"chat-thread-header-identity","data-testid":"chat-thread-header-identity",children:Js?t.jsxs("div",{className:"chat-mobile-session-menu",ref:Xt,children:[t.jsxs("button",{type:"button",className:"btn chat-mobile-session-trigger","data-testid":"chat-mobile-session-trigger","aria-haspopup":"menu","aria-expanded":lt,onClick:()=>Be(e=>!e),children:[Ie?t.jsx(it,{provider:Ie,size:"md"}):t.jsx(ot,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:Dt}),ms&&t.jsx("span",{className:"chat-model-tag",children:$e}),t.jsx(ys,{size:16,"aria-hidden":"true"})]}),lt&&t.jsx("div",{className:"chat-mobile-session-dropdown",role:"menu","data-testid":"chat-mobile-session-dropdown",children:$.map(e=>t.jsx("button",{type:"button",role:"menuitem",className:`chat-mobile-session-option${i?.id===e.id?" chat-mobile-session-option--active":""}`,"data-testid":`chat-mobile-session-option-${e.id}`,onClick:()=>ds(e.id),children:t.jsx("span",{className:"chat-mobile-session-option-title",children:e.title||"Untitled"})},e.id))})]}):t.jsxs(t.Fragment,{children:[Ie?t.jsx(it,{provider:Ie,size:"md"}):t.jsx(ot,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:Dt}),ms&&t.jsx("span",{className:"chat-model-tag",children:$e})]})}),Et&&t.jsx("button",{type:"button",className:`chat-thread-header-render-toggle${H?" chat-thread-header-render-toggle--plain":""}`,"data-testid":"chat-thread-render-toggle","aria-label":H?"Show all messages as rendered Markdown":"Show all messages as plain text",onClick:Qs,children:H?t.jsx(Rn,{size:14}):t.jsx(An,{size:14})}),!I&&t.jsxs("button",{className:"btn btn-sm btn-primary chat-thread-header-new-chat",onClick:()=>Y(!0),"data-testid":"chat-thread-new-chat-btn",children:[t.jsx(at,{size:14}),"New Chat"]})]}),t.jsxs("div",{className:"chat-messages",ref:ge,onScroll:as,children:[E?t.jsxs(t.Fragment,{children:[x.map(e=>t.jsx(Gt,{message:e,forcePlain:H,agentName:$t,hideAssistantIdentity:Pt,showAssistantModelTag:It,activeModelTag:$e,activeModelProvider:Ie,activeSessionId:i?.id??null,mentionAgentsByName:kt,roomContext:null,copyAction:Ft&&e.role==="assistant"?zt(e.id,e.content):void 0},e.id)),t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[!Pt&&t.jsxs("div",{className:"chat-message-avatar",children:[Ie?t.jsx(it,{provider:Ie,size:"sm"}):t.jsx(ot,{size:14}),t.jsx("span",{children:$t}),It]}),D?Zs(D,H):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:C?"Thinking…":"Connecting…"}),Ft&&D&&zt("__streaming__",D,"chat-copy-response-streaming"),Fs(Q),C&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:xt(C)})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}):R?t.jsx("div",{className:"chat-empty-state",children:"Loading messages..."}):x.length===0&&!i?Xs():x.length===0&&i?t.jsx("div",{className:"chat-empty-state",children:"No messages yet. Start the conversation!"}):t.jsx(t.Fragment,{children:x.map(e=>t.jsx(Gt,{message:e,forcePlain:H,agentName:$t,hideAssistantIdentity:Pt,showAssistantModelTag:It,activeModelTag:$e,activeModelProvider:Ie,activeSessionId:i?.id??null,mentionAgentsByName:kt,roomContext:null,copyAction:Ft&&e.role==="assistant"?zt(e.id,e.content):void 0},e.id))}),t.jsx("div",{ref:qt})]}),O&&t.jsxs("button",{type:"button",className:"btn btn-sm chat-jump-to-latest","data-testid":"chat-jump-to-latest",onClick:tt,children:[t.jsx(ys,{size:14}),"Latest"]}),i&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Yt,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{ut(e.target.files),e.target.value=""}}),je&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:Oe?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):pe.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:Je?"No skills found":"No skills available"}):pe.map((e,a)=>t.jsxs("button",{type:"button",role:"option","aria-selected":a===ze,className:`chat-skill-menu-item${a===ze?" chat-skill-menu-item--highlighted":""}`,onMouseDown:d=>d.preventDefault(),onMouseEnter:()=>Re(a),onClick:()=>Rt(e),children:[t.jsx("span",{className:"chat-skill-menu-item-name",children:e.name}),t.jsx("span",{className:"chat-skill-menu-item-description",title:e.relativePath,children:e.relativePath})]},e.id))}),U.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:U.map((e,a)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${a}`,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:()=>Hs(a),"data-testid":`chat-attachment-remove-${a}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${a}`))}),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":"Attach files",onClick:()=>Yt.current?.click(),children:t.jsx(Tn,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${W?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),V(!0)},onDragLeave:()=>V(!1),onDrop:e=>{e.preventDefault(),V(!1),ut(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:ce,className:"chat-input-textarea",placeholder:"Type a message...",value:c,onChange:is,onKeyDown:rs,onKeyUp:os,onClick:ft,onBlur:cs,onFocus:ls,onPaste:Bs,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||document.activeElement!==e.currentTarget&&(e.preventDefault(),e.currentTarget.focus({preventScroll:!0}))},rows:1,"data-testid":"chat-input"}),t.jsx(vs,{agents:Ge,filter:xe,highlightedIndex:v,visible:fe,onSelect:mt,position:"below",roomMemberIds:Ce?.memberIds,roomName:Ce?.roomName}),t.jsx(En,{visible:B.mentionActive&&!fe,position:_s,files:B.files,selectedIndex:B.selectedIndex,onSelect:e=>{const a=B.selectFile(e,c);m(a),B.dismissMention(),Ye(!1),ce.current?.focus()},loading:B.loading}),b&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${Ys}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:M,children:"×"})]})]}),E?t.jsx("button",{className:"chat-input-stop",onClick:_,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(Dn,{size:14})}):t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{e.pointerType&&e.pointerType!=="mouse"&&e.preventDefault()},onMouseDown:e=>{e.preventDefault()},onClick:()=>{jt()},disabled:!c.trim()&&U.length===0,"data-testid":"chat-send-btn",style:{touchAction:"manipulation"},children:t.jsx(xs,{size:16})})]})]})]}),z&&t.jsx(Kn,{isOpen:Fe,onClose:()=>te(!1),projectId:s,existingRoomNames:o.rooms.map(e=>e.name),onCreate:async e=>{await o.createRoom({name:e.name,memberAgentIds:e.memberAgentIds}),h!=="rooms"&&p("rooms"),te(!1),I&&ve(!1)}}),J&&t.jsx(sa,{projectId:s,onClose:()=>Y(!1),onCreate:Gs})]})}export{ca as ChatView,Vn as clampChatInputHeight};
@@ -1 +0,0 @@
1
- .reliability-view{display:flex;flex-direction:column;gap:var(--space-lg)}.reliability-card{padding:var(--space-lg);border:var(--border-width-thin, .0625rem) solid var(--border);border-radius:var(--radius-md);background:var(--card)}.reliability-headline-card{display:flex;flex-direction:column;gap:var(--space-sm)}.reliability-headline{font-size:var(--font-size-2xl, 1.75rem);font-weight:700}.reliability-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:var(--space-lg)}.reliability-table{width:100%;border-collapse:collapse;margin-top:var(--space-sm)}.reliability-table th,.reliability-table td{text-align:left;padding:var(--space-xs) var(--space-sm);border-bottom:var(--border-width-thin, .0625rem) solid var(--border)}.reliability-stat-row{display:flex;justify-content:space-between;align-items:center;padding:var(--space-xs) 0}.reliability-muted{color:var(--text-muted)}.reliability-histogram{list-style:none;margin:var(--space-sm) 0 0;padding:0;display:flex;flex-direction:column;gap:var(--space-sm)}.reliability-histogram li{display:grid;grid-template-columns:minmax(0,2fr) minmax(0,6fr) minmax(0,1fr);align-items:center;gap:var(--space-sm)}.reliability-histogram-bar-wrap{width:100%;border-radius:var(--radius-pill);background:color-mix(in srgb,var(--color-info) 15%,transparent);overflow:hidden}.reliability-histogram-bar{height:var(--space-md);background:var(--color-info)}@media(max-width:768px){.reliability-grid{grid-template-columns:minmax(0,1fr)}}