@runfusion/fusion 0.28.0 → 0.29.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 (69) hide show
  1. package/dist/bin.js +3126 -1051
  2. package/dist/client/assets/AgentDetailView-CWyOv8HJ.js +18 -0
  3. package/dist/client/assets/{AgentDetailView-DSpIqBOs.css → AgentDetailView-ChIKbcEi.css} +1 -1
  4. package/dist/client/assets/AgentsView-BI_CESkd.css +1 -0
  5. package/dist/client/assets/AgentsView-DljrBNE1.js +34 -0
  6. package/dist/client/assets/ChatView-BklDUi5_.js +1 -0
  7. package/dist/client/assets/{DevServerView-Diw4hjw0.js → DevServerView-BqcI1wXr.js} +1 -1
  8. package/dist/client/assets/{DirectoryPicker-CWSApoLU.js → DirectoryPicker-Bb3TIWEa.js} +1 -1
  9. package/dist/client/assets/{DocumentsView-1kr0dhsV.js → DocumentsView-BhrdTTh3.js} +1 -1
  10. package/dist/client/assets/{EvalsView-cDfXYiK6.js → EvalsView-DrFp2cLg.js} +1 -1
  11. package/dist/client/assets/{ExperimentalAgentOnboardingModal-lNSf6UtY.js → ExperimentalAgentOnboardingModal-AsmRLMxm.js} +1 -1
  12. package/dist/client/assets/ExperimentalAgentOnboardingModal-BNpveCEk.css +1 -0
  13. package/dist/client/assets/{InsightsView-D2AjxOnu.js → InsightsView-j7J_vUME.js} +1 -1
  14. package/dist/client/assets/{MemoryView-Dq4yjIPI.js → MemoryView-QWiqVDuQ.js} +2 -2
  15. package/dist/client/assets/{NodesView-Cpmkze7n.js → NodesView-Cr4CXr7b.js} +1 -1
  16. package/dist/client/assets/{PiExtensionsManager-oi9FHT0y.js → PiExtensionsManager-CPZ-82Wl.js} +2 -2
  17. package/dist/client/assets/PluginManager-BJQXdUmV.css +1 -0
  18. package/dist/client/assets/{PluginManager-o12KG4e8.js → PluginManager-DShC4UiM.js} +1 -1
  19. package/dist/client/assets/{ResearchView-C9bjVB7-.js → ResearchView-B5wYC1KE.js} +1 -1
  20. package/dist/client/assets/{SettingsModal-CT01a5Rh.js → SettingsModal-8l8vfXns.js} +1 -1
  21. package/dist/client/assets/SettingsModal-BAx4gt2A.css +1 -0
  22. package/dist/client/assets/SettingsModal-CYetgxZj.js +31 -0
  23. package/dist/client/assets/SettingsModal-ChnabMhF.css +1 -0
  24. package/dist/client/assets/{SetupWizardModal-Agi3XNtZ.js → SetupWizardModal-_IK6hTA7.js} +1 -1
  25. package/dist/client/assets/SkillsView-CUbSBeZ2.css +1 -0
  26. package/dist/client/assets/{SkillsView-DmZfbGLs.js → SkillsView-Dilmj1nh.js} +1 -1
  27. package/dist/client/assets/{StashRecoveryView-BwKJQaUW.js → StashRecoveryView-BtL9aAn3.js} +1 -1
  28. package/dist/client/assets/{TodoView-uJRg4Cnl.js → TodoView-rSn0aPsb.js} +1 -1
  29. package/dist/client/assets/{dashboard-view-C7Snlgow.js → dashboard-view-C_G8JVU7.js} +1 -1
  30. package/dist/client/assets/{folder-open-DU-Ec_iC.js → folder-open-Bq_TweLR.js} +1 -1
  31. package/dist/client/assets/index-DjfAYMGG.css +1 -0
  32. package/dist/client/assets/index-tbwUVj8p.js +696 -0
  33. package/dist/client/assets/{star-Qi0GspVN.js → star-Dn0V0Cnq.js} +1 -1
  34. package/dist/client/assets/{upload-Dx_l9Vbu.js → upload-D1y22Www.js} +1 -1
  35. package/dist/client/assets/{users-3Qw_TMah.js → users-UQdBpweI.js} +1 -1
  36. package/dist/client/index.html +2 -2
  37. package/dist/client/version.json +1 -1
  38. package/dist/droid-cli/package.json +1 -1
  39. package/dist/extension.js +2499 -656
  40. package/dist/pi-claude-cli/package.json +1 -1
  41. package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
  42. package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/registration.test.ts +20 -3
  43. package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/workflow-integration.test.ts +103 -8
  44. package/dist/plugins/fusion-plugin-cli-printing-press/src/index.ts +4 -0
  45. package/dist/plugins/fusion-plugin-cli-printing-press/src/workflow-steps.ts +14 -0
  46. package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
  47. package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
  48. package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
  49. package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
  50. package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
  51. package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
  52. package/dist/plugins/fusion-plugin-reports/package.json +1 -1
  53. package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
  54. package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
  55. package/package.json +1 -1
  56. package/skill/fusion/references/extension-tools.md +5 -5
  57. package/skill/fusion/references/fusion-capabilities.md +5 -5
  58. package/dist/client/assets/AgentDetailView-V32TpEe1.js +0 -18
  59. package/dist/client/assets/AgentsView-B3ADnF0D.css +0 -1
  60. package/dist/client/assets/AgentsView-CxITZE-U.js +0 -34
  61. package/dist/client/assets/ChatView-7WPHyB_7.js +0 -1
  62. package/dist/client/assets/ExperimentalAgentOnboardingModal-B-APN_lM.css +0 -1
  63. package/dist/client/assets/PluginManager-C4UoLv4U.css +0 -1
  64. package/dist/client/assets/SettingsModal-Ci0_sqbU.css +0 -1
  65. package/dist/client/assets/SettingsModal-Cu93Jjho.js +0 -31
  66. package/dist/client/assets/SettingsModal-DWKgRxBA.css +0 -1
  67. package/dist/client/assets/SkillsView-Cytf009Z.css +0 -1
  68. package/dist/client/assets/index-CD0_dkME.css +0 -1
  69. package/dist/client/assets/index-DiewofJh.js +0 -692
@@ -1,34 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-V32TpEe1.js","assets/vendor-react-K0fH_qHe.js","assets/index-DiewofJh.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-CD0_dkME.css","assets/star-Qi0GspVN.js","assets/ExperimentalAgentOnboardingModal-lNSf6UtY.js","assets/ExperimentalAgentOnboardingModal-B-APN_lM.css","assets/AgentDetailView-DSpIqBOs.css"])))=>i.map(i=>d[i]);
2
- import{c as Ue,A as De,C as Je,Z as Zt,s as qt,r as ht,F as pt,f as Jt,a as Qt,b as zt,B as xt,u as Dt,d as nt,e as Xt,g as Yt,h as es,i as ts,j as Ct,k as Xe,P as ss,l as as,m as ns,n as ls,o as St,G as is,S as rs,L as lt,T as it,R as Ve,X as At,p as os,q as cs,t as Tt,v as ds,w as us,x as ms,y as gs,z as fe,D as rt,E as hs,H as ps,N as xs,I as Rt,J as bs,M as vs,K as js,O as fs,Q as Ns,U as ot,V as Mt,W as ys,_ as ks,Y as ws,$ as Ze,a0 as Cs,a1 as Et,a2 as Ss,a3 as As,a4 as Ts}from"./index-DiewofJh.js";import{r as a,j as e,a as Rs}from"./vendor-react-K0fH_qHe.js";import{A as Ms,S as Es,E as _s,f as $s}from"./ExperimentalAgentOnboardingModal-lNSf6UtY.js";import{U as bt}from"./upload-Dx_l9Vbu.js";import{F as Ls}from"./folder-open-DU-Ec_iC.js";import"./vendor-xterm-DzcZoU0P.js";/**
3
- * @license lucide-react v1.7.0 - ISC
4
- *
5
- * This source code is licensed under the ISC license.
6
- * See the LICENSE file in the root directory of this source tree.
7
- */const Is=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],Fs=Ue("info",Is);/**
8
- * @license lucide-react v1.7.0 - ISC
9
- *
10
- * This source code is licensed under the ISC license.
11
- * See the LICENSE file in the root directory of this source tree.
12
- */const Ps=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1",key:"cif1o7"}]],zs=Ue("list-todo",Ps);/**
13
- * @license lucide-react v1.7.0 - ISC
14
- *
15
- * This source code is licensed under the ISC license.
16
- * See the LICENSE file in the root directory of this source tree.
17
- */const Ds=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Hs=Ue("sliders-horizontal",Ds);/**
18
- * @license lucide-react v1.7.0 - ISC
19
- *
20
- * This source code is licensed under the ISC license.
21
- * See the LICENSE file in the root directory of this source tree.
22
- */const Os=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Bs=Ue("zoom-in",Os);/**
23
- * @license lucide-react v1.7.0 - ISC
24
- *
25
- * This source code is licensed under the ISC license.
26
- * See the LICENSE file in the root directory of this source tree.
27
- */const Gs=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Vs=Ue("zoom-out",Gs);function _t(n){return typeof n=="number"&&Number.isFinite(n)?n:0}function ze(n){return n.toLocaleString()}function Us({agents:n}){const{rows:i,totalInputTokens:f,totalOutputTokens:u,totalTokens:d}=a.useMemo(()=>{const c=n.map(o=>{const b=_t(o.totalInputTokens),N=_t(o.totalOutputTokens);return{id:o.id,name:o.name,inputTokens:b,outputTokens:N,totalTokens:b+N}}).sort((o,b)=>b.totalTokens-o.totalTokens||o.name.localeCompare(b.name)||o.id.localeCompare(b.id));return{rows:c,totalInputTokens:c.reduce((o,b)=>o+b.inputTokens,0),totalOutputTokens:c.reduce((o,b)=>o+b.outputTokens,0),totalTokens:c.reduce((o,b)=>o+b.totalTokens,0)}},[n]),g=d>0;return e.jsxs("section",{className:"agent-token-stats-panel","aria-label":"Agent token usage statistics",children:[e.jsx("header",{className:"agent-token-stats-panel__header",children:e.jsx("h3",{className:"agent-token-stats-panel__title",children:"Token Usage by Agent"})}),e.jsxs("div",{className:"agent-token-stats-panel__totals",role:"list","aria-label":"Token usage totals",children:[e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Input Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(f)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Output Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(u)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Combined Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(d)})]})]}),g?e.jsx("div",{className:"agent-token-stats-panel__table-wrapper",children:e.jsxs("table",{className:"agent-token-stats-panel__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"Agent"}),e.jsx("th",{scope:"col",children:"Input"}),e.jsx("th",{scope:"col",children:"Output"}),e.jsx("th",{scope:"col",children:"Total"})]})}),e.jsx("tbody",{children:i.map(c=>e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",className:"agent-token-stats-panel__agent-cell",children:[e.jsx("span",{className:"agent-token-stats-panel__agent-name",children:c.name}),e.jsx("span",{className:"agent-token-stats-panel__agent-id",children:c.id})]}),e.jsx("td",{children:ze(c.inputTokens)}),e.jsx("td",{children:ze(c.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:ze(c.totalTokens)})]},c.id))})]})}):e.jsx("div",{className:"agent-token-stats-panel__empty",role:"status",children:"No token usage recorded yet. Token totals appear here once agents run."})]})}const Ws=[{icon:De,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:zs,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:Je,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:Zt,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function Ks({stats:n,className:i=""}){return n?e.jsx("div",{className:`agent-metrics-bar ${i}`.trim(),children:Ws.map(f=>{const u=f.valueKey==="successRate"?`${Math.round(n.successRate*100)}%`:n[f.valueKey];return e.jsxs("div",{className:`agent-metric-card ${f.className}`,children:[e.jsx(f.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:u}),e.jsx("span",{className:"agent-metric-label",children:f.label})]})]},f.label)})}):null}const $t=200;function Zs(n,i){const[f,u]=a.useState([]),[d,g]=a.useState(!1),c=a.useRef(null),o=a.useRef(0),b=a.useRef(n),N=a.useRef(i);return(b.current!==n||N.current!==i)&&(b.current=n,N.current=i,o.current++,c.current&&(c.current(),c.current=null),u([]),g(!1)),a.useEffect(()=>{if(!n){u([]),g(!1);return}const M=o.current;let C=`/api/tasks/${encodeURIComponent(n)}/logs/stream`;i&&(C+=`?projectId=${encodeURIComponent(i)}`);const w=qt(C,{events:{"agent:log":P=>{if(o.current===M)try{const T=JSON.parse(P.data),E={type:T.type??"text",text:T.text??T.content??"",timestamp:T.timestamp,content:T.content};u(S=>{const _=[E,...S];return _.length>$t?_.slice(0,$t):_})}catch{}}},onOpen:()=>{o.current===M&&g(!0)},onError:()=>{o.current===M&&g(!1)}});return c.current=w,()=>{w(),c.current=null,o.current===M&&g(!1)}},[n,i]),{entries:f,isConnected:d}}const qs=5e3;function Js({agent:n,projectId:i,onSelect:f,onOpenTaskLogs:u}){const{entries:d,isConnected:g}=Zs(n.taskId,i),[c,o]=a.useState(null);a.useEffect(()=>{if(!n.taskId){o(null);return}let S=!1,_;const p=async()=>{try{const L=await Jt(n.taskId,i);S||o(L)}catch{}finally{S||(_=setTimeout(p,qs))}};return p(),()=>{S=!0,_&&clearTimeout(_)}},[n.taskId,i]);const b=n.lastHeartbeatAt?Math.floor((Date.now()-new Date(n.lastHeartbeatAt).getTime())/1e3):0,N=(()=>{if(!n.lastHeartbeatAt)return null;const S=ht(n.runtimeConfig?.heartbeatIntervalMs),_=new Date(n.lastHeartbeatAt).getTime()+S,p=Math.round((_-Date.now())/1e3);return Number.isFinite(p)?p<=0?`Heartbeat overdue ${ct(-p)}`:`Next heartbeat in ${ct(p)}`:null})(),k=c?.steps?.[c.currentStep??0],M=c?.steps?.length??0,C=(c?.currentStep??0)+1,w=c?.modelId,P=()=>{f&&f(n.id)},T=S=>{S.stopPropagation(),n.taskId&&u&&u(n.taskId)},E=S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),P())};return e.jsxs("div",{className:"live-agent-card",onClick:P,onKeyDown:E,role:"button",tabIndex:0,"aria-label":`Select agent ${n.name}`,children:[e.jsxs("div",{className:"live-agent-card-header",children:[e.jsxs("div",{className:"live-agent-card-name",children:[e.jsx("span",{className:`status-dot ${n.state==="running"?"status-dot--pending":"status-dot--online"}`,"aria-hidden":"true"}),e.jsx("span",{children:n.name})]}),n.taskId&&e.jsx("span",{className:"live-agent-task badge",children:n.taskId})]}),e.jsx("div",{className:"live-agent-card-transcript",children:d.length===0?e.jsx("div",{className:"live-agent-card-empty",children:n.taskId?k?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"live-agent-card-status",children:["Step ",C,M?`/${M}`:"",": ",k.name]}),w&&e.jsx("div",{className:"live-agent-card-status-sub",children:w}),e.jsx("div",{className:"live-agent-card-status-sub",children:g?"Waiting for output...":"Connecting to log stream..."})]}):e.jsx("span",{children:g?"Waiting for output...":"Connecting..."}):e.jsx("span",{children:n.state==="running"?"Starting...":"Idle — no task assigned"})}):d.slice(0,20).map((S,_)=>e.jsx("div",{className:"live-agent-card-line",children:S.text},_))}),e.jsxs("div",{className:"live-agent-card-footer",children:[e.jsxs("div",{className:"live-agent-card-footer-meta",children:[e.jsx("span",{className:"text-secondary",title:"Time since last heartbeat",children:ct(b)}),N&&e.jsx("span",{className:"live-agent-card-next-heartbeat",title:N,children:N})]}),e.jsxs("div",{className:"live-agent-card-footer-actions",children:[n.taskId&&u&&e.jsxs("button",{type:"button",className:"live-agent-card-logs-btn",onClick:T,title:"View live run logs","aria-label":`View live logs for ${n.taskId}`,children:[e.jsx(pt,{size:12}),e.jsx("span",{children:"Live logs"})]}),g&&e.jsx(De,{size:12,className:"live-agent-streaming-dot"})]})]})]})}function ct(n){return n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m ${n%60}s`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`}function Qs({agents:n,projectId:i,onAgentSelect:f,onOpenTaskLogs:u,className:d=""}){const g=Array.from(new Map(n.map(c=>[c.id,c])).values());return g.length===0?null:e.jsxs("div",{className:`active-agents-panel ${d}`.trim(),children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(De,{size:16}),e.jsxs("span",{children:["Active Agents (",g.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:g.map(c=>e.jsx(Js,{agent:c,projectId:i,onSelect:f,onOpenTaskLogs:u},c.id))})]})}function Xs({stats:n,activeAgents:i,projectId:f,isOpen:u,onToggle:d,onSelectAgent:g,onOpenTaskLogs:c}){return e.jsxs("section",{className:"agents-overview-bar","aria-label":"Agents overview",children:[e.jsxs("button",{type:"button",className:"agents-overview-bar__toggle","aria-expanded":u,onClick:d,children:[e.jsxs("span",{className:"agents-overview-bar__title-wrap",children:[u?e.jsx(Qt,{size:16,"aria-hidden":"true"}):e.jsx(zt,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"agents-overview-bar__title",children:"Overview"})]}),e.jsxs("span",{className:"agents-overview-bar__meta text-secondary",children:[i.filter(o=>o.state==="active").length," active · ",i.filter(o=>o.state==="running").length," running"]})]}),u?e.jsxs("div",{className:"agents-overview-bar__content",children:[e.jsx(Ks,{stats:n,className:"agents-overview-bar__metrics"}),e.jsx(Qs,{agents:i,projectId:f,onAgentSelect:g,onOpenTaskLogs:c,className:"agents-overview-bar__active-panel"})]}):null]})}function dt({title:n="No agents found",description:i="Create an agent to get started",ctaLabel:f="Create Agent",onCtaClick:u}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(xt,{size:48,opacity:.3,className:"agent-empty-state__icon"}),e.jsx("p",{className:"agent-empty-state__title",children:n}),e.jsx("p",{className:"agent-empty-state__description text-secondary",children:i}),u?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:u,children:f}):null]})}const Lt=3,ut=1e3;function Ys({isOpen:n,onClose:i,onGenerated:f,projectId:u}){Dt(n);const[d,g]=a.useState(""),[c,o]=a.useState({type:"input"}),[b,N]=a.useState(null),[k,M]=a.useState(!1),C=a.useRef(null),w=a.useRef(null);a.useEffect(()=>{n&&c.type==="input"&&w.current?.focus()},[n,c.type]),a.useEffect(()=>{if(!n&&C.current){const p=C.current;C.current=null,nt(p,u).catch(()=>{})}},[n,u]),a.useEffect(()=>{if(!n)return;const p=L=>{L.key==="Escape"&&P()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[n]);const P=a.useCallback(()=>{if(C.current){const p=C.current;C.current=null,nt(p,u).catch(()=>{})}g(""),o({type:"input"}),N(null),M(!1),i()},[i,u]),T=a.useCallback(async()=>{if(!(!d.trim()||d.trim().length<Lt)){N(null),o({type:"loading"});try{const{sessionId:p}=await Xt(d.trim(),u);C.current=p;const{spec:L}=await Yt(p,u);o({type:"preview",spec:L,sessionId:p})}catch(p){const L=p instanceof Error?p.message:"Failed to generate agent specification";L.includes("429")||L.toLowerCase().includes("rate limit")?N("Too many requests. Please wait a moment and try again."):N(L),o({type:"input"}),C.current=null}}},[d,u]),E=a.useCallback(async()=>{if(C.current){const p=C.current;C.current=null;try{await nt(p,u)}catch{}}await T()},[T,u]),S=a.useCallback(()=>{c.type==="preview"&&(C.current=null,f(c.spec),g(""),o({type:"input"}),N(null),M(!1),i())},[c,f,i]);if(!n)return null;const _=d.trim().length>=Lt&&d.trim().length<=ut;return e.jsx("div",{className:"agent-dialog-overlay",onClick:p=>{p.target===p.currentTarget&&P()},children:e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Generate agent with AI",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsxs("span",{className:"agent-dialog-header-title",children:[e.jsx("span",{className:"agent-dialog-header-sparkle",children:"✨"}),"Generate Agent"]}),e.jsx("button",{className:"modal-close",onClick:P,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[b&&e.jsx("div",{className:"agent-dialog-error-banner",children:b}),c.type==="input"&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Describe your agent's role and the AI will generate a complete specification including system prompt, suggested configuration, and more."}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-role-description",children:"Role Description"}),e.jsx("textarea",{ref:w,id:"agent-role-description",className:"input agent-dialog-textarea",rows:4,placeholder:'e.g. "Senior frontend code reviewer who specializes in React accessibility"',value:d,onChange:p=>g(p.target.value),onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&_&&(p.preventDefault(),T())},maxLength:ut,"aria-describedby":"role-description-hint"}),e.jsxs("div",{id:"role-description-hint",className:"agent-dialog-hint",children:[e.jsx("span",{children:"Describe what your agent should do"}),e.jsxs("span",{children:[d.length,"/",ut]})]})]})]}),c.type==="loading"&&e.jsxs("div",{className:"agent-dialog-loading-center",children:[e.jsx("div",{className:"agent-dialog-spinner spin"}),e.jsx("p",{className:"agent-dialog-loading-text",children:"Generating agent specification..."})]}),c.type==="preview"&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-summary agent-dialog-summary--spaced",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Title"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[c.spec.icon," ",c.spec.title]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Role"}),e.jsx("span",{children:c.spec.role})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Description"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--body",children:c.spec.description})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--capitalize",children:c.spec.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Max Turns"}),e.jsx("span",{children:c.spec.maxTurns})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{children:["System Prompt",e.jsx("button",{type:"button",className:"agent-dialog-expand-btn",onClick:()=>M(!k),children:k?"Collapse":"Expand"})]}),e.jsxs("div",{className:`agent-generation-prompt-box${k?"":" agent-generation-prompt-box--collapsed"}`,children:[c.spec.systemPrompt,!k&&c.spec.systemPrompt.length>500&&e.jsx("div",{className:"agent-generation-prompt-fade"})]})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[e.jsx("button",{className:"btn",onClick:P,children:"Cancel"}),c.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void T(),disabled:!_,children:"Generate"}),c.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void E(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:S,children:"Use This"})]})]})]})})}const It=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Ft=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function ea({isOpen:n,onClose:i,onCreated:f,projectId:u,prefillDraft:d=null,agentOnboardingEnabled:g=!1,existingAgents:c=[],onPrefillDraft:o}){const[b,N]=a.useState(0),[k,M]=a.useState("presets"),[C,w]=a.useState(""),[P,T]=a.useState(""),[E,S]=a.useState(""),[_,p]=a.useState("custom"),[L,$]=a.useState(""),[ee,Ne]=a.useState(""),[oe,te]=a.useState(""),[le,ce]=a.useState(""),[z,y]=a.useState(""),[xe,be]=a.useState(""),[A,se]=a.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[de,ye]=a.useState(null),[ae,U]=a.useState([]),[ue,G]=a.useState(!1),[W,V]=a.useState(null),[ve,ie]=a.useState(!1),[K,Q]=a.useState(!1),[Me,Ee]=a.useState([]),[_e,ke]=a.useState(!1),[me,we]=a.useState([]),[X,$e]=a.useState([]),[H,F]=a.useState("model"),[re,Z]=a.useState(""),[Ce,Y]=a.useState([]),[Se,Ae]=a.useState(!1),[l,x]=a.useState([]),[R,q]=a.useState(!1);a.useEffect(()=>{n&&(ke(!0),es().then(s=>{Ee(s.models),we(s.favoriteProviders),$e(s.favoriteModels)}).catch(()=>{}).finally(()=>ke(!1)))},[n]),a.useEffect(()=>{n&&(q(!0),x([]),ts(void 0,u).then(s=>{x(s)}).catch(()=>{x([])}).finally(()=>q(!1)))},[n,u]),a.useEffect(()=>{if(!n)return;const s=as;if(typeof s!="function"){Y([]),Ae(!1);return}Ae(!0),Y([]),s(u).then(v=>{Y(v)}).catch(()=>{Y([])}).finally(()=>Ae(!1))},[n,u]);const I=A.model.includes("/")?A.model:"",D=a.useCallback(s=>{const v=Ft.has(s.role)?s.role:"custom";w(s.title),T(s.description),S(s.icon),p(v),te(s.systemPrompt),se(he=>({...he,thinkingLevel:s.thinkingLevel,maxTurns:s.maxTurns})),ie(!1),N(1)},[]),Te=a.useCallback(s=>{se(v=>({...v,model:s}))},[]),Le=a.useCallback(s=>{F(s),s==="model"&&Z("")},[]),Fe=a.useCallback(async s=>{const v=me,ne=v.includes(s)?v.filter(Re=>Re!==s):[s,...v];we(ne);try{await Ct({favoriteProviders:ne,favoriteModels:X})}catch{we(v)}},[me,X]),Ie=a.useCallback(async s=>{const v=X,ne=v.includes(s)?v.filter(Re=>Re!==s):[s,...v];$e(ne);try{await Ct({favoriteProviders:me,favoriteModels:ne})}catch{$e(v)}},[me,X]),Ye=a.useCallback(s=>{ye(s.id),w(s.name),S(s.icon),T(s.description??s.title),p(s.role),y(s.soul??""),te(s.instructionsText??""),N(1)},[]),je=a.useCallback(s=>{const v=s.runtimeHint?.trim()??"",he=s.model?.trim()||s.modelHint?.trim()||"";N(1),M("custom"),w(s.name??""),T(s.title??""),S(s.icon??""),p(Ft.has(s.role)?s.role:"custom"),$(s.reportsTo??""),te(s.instructionsText??""),ce(s.heartbeatProcedurePath??""),y(s.soul??""),be(s.memory??""),U(Array.isArray(s.skills)?s.skills:[]),se(ne=>({...ne,model:v?"":he,thinkingLevel:s.thinkingLevel??ne.thinkingLevel,maxTurns:s.maxTurns??ne.maxTurns})),v?(F("runtime"),Z(v)):(F("model"),Z(""))},[]);if(a.useEffect(()=>{!n||!d||je(d)},[n,d,je]),!n)return null;const ge=()=>{N(0),M("presets"),w(""),T(""),S(""),p("custom"),$(""),Ne(""),te(""),ce(""),y(""),be(""),se({model:"",thinkingLevel:"off",maxTurns:1e3}),F("model"),Z(""),ye(null),U([]),V(null),ie(!1),Q(!1),i()},et=async()=>{if(C.trim()){G(!0),V(null);try{const s={};H==="runtime"?re.trim()&&(s.runtimeHint=re.trim()):A.model.trim()&&(s.model=A.model.trim()),A.thinkingLevel!=="off"&&(s.thinkingLevel=A.thinkingLevel),A.maxTurns!==1e3&&(s.maxTurns=A.maxTurns),await ls({name:C.trim(),role:_,...P.trim()?{title:P.trim()}:{},...E.trim()?{icon:E.trim()}:{},...L.trim()?{reportsTo:L.trim()}:{},...ee.trim()?{instructionsPath:ee.trim()}:{},...oe.trim()?{instructionsText:oe.trim()}:{},...le.trim()?{heartbeatProcedurePath:le.trim()}:{},...z.trim()?{soul:z.trim()}:{},...xe.trim()?{memory:xe.trim()}:{},...Object.keys(s).length>0?{runtimeConfig:s}:{},...ae.length>0?{metadata:{skills:ae}}:{}},u),ge(),f()}catch(s){V(s instanceof Error?s.message:"Failed to create agent")}finally{G(!1)}}},We=It.find(s=>s.value===_),Pe=L.trim(),He=Pe?l.find(s=>s.id===Pe):void 0,Oe=re?Ce.find(s=>s.runtimeId===re):void 0,Ke=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:s,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":s,children:[e.jsxs("label",{className:`agent-runtime-mode-option${H==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"model",checked:H==="model",onChange:()=>Le("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${H==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"runtime",checked:H==="runtime",onChange:()=>Le("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),H==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),_e?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(ns,{id:"agent-model",label:"Model",value:I,onChange:Te,models:Me,placeholder:"Select a model…",favoriteProviders:me,onToggleFavorite:Fe,favoriteModels:X,onToggleModelFavorite:Ie})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),Se?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:re,onChange:v=>Z(v.target.value),children:[e.jsx("option",{value:"",children:Ce.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),Ce.map(v=>e.jsx("option",{value:v.runtimeId,children:v.description?`${v.name} — ${v.description}`:v.name},`${v.pluginId}:${v.runtimeId}`))]})]})]});return Rs.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:s=>{s.target===s.currentTarget&&ge()},children:[e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Create new agent",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"New Agent"}),e.jsx("button",{className:"btn-icon",onClick:ge,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(s=>e.jsx("div",{className:`agent-dialog-step${s===b?" active":s<b?" completed":""}`,"aria-label":`Step ${s+1}`},s))}),e.jsxs("div",{className:"agent-dialog-body",children:[b===0&&e.jsxs("div",{children:[g&&e.jsx("div",{className:"agent-dialog-step-zero-actions",children:e.jsx("button",{type:"button",className:"btn agent-dialog-interview-btn",onClick:()=>Q(!0),children:"AI Interview"})}),e.jsxs("div",{className:"agent-dialog-tabs",role:"tablist","aria-label":"Agent setup mode",children:[e.jsx("button",{id:"agent-dialog-tab-presets",type:"button",role:"tab","aria-controls":"agent-dialog-panel-presets","aria-selected":k==="presets",tabIndex:k==="presets"?0:-1,className:`agent-dialog-tab${k==="presets"?" active":""}`,onClick:()=>M("presets"),"data-testid":"agent-dialog-tab-presets",children:"Preset personas"}),e.jsx("button",{id:"agent-dialog-tab-custom",type:"button",role:"tab","aria-controls":"agent-dialog-panel-custom","aria-selected":k==="custom",tabIndex:k==="custom"?0:-1,className:`agent-dialog-tab${k==="custom"?" active":""}`,onClick:()=>M("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),k==="presets"&&e.jsx("div",{id:"agent-dialog-panel-presets",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-presets",children:e.jsxs("div",{className:"agent-presets",children:[e.jsx("div",{className:"agent-presets-header",children:"Choose a preset persona to prefill role, identity, soul, and instructions"}),e.jsx("div",{className:"agent-presets-grid",children:Ms.map(s=>e.jsxs("button",{type:"button",className:`agent-preset-card${de===s.id?" selected":""}`,"data-testid":`preset-${s.id}`,onClick:()=>Ye(s),title:s.title,children:[e.jsx("span",{className:"agent-preset-icon",children:e.jsx(Xe,{agent:{id:s.id,icon:s.icon,name:s.name},size:28})}),e.jsx("span",{className:"agent-preset-name",children:s.name}),e.jsx("span",{className:"agent-preset-role",children:s.role}),s.description&&e.jsx("span",{className:"agent-preset-description",children:s.description})]},s.id))})]})}),k==="custom"&&e.jsxs("div",{id:"agent-dialog-panel-custom",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-custom",children:[e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Identity"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-name",children:["Name ",!de&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:C,onChange:s=>w(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field agent-dialog-field--title",children:[e.jsxs("label",{htmlFor:"agent-title",children:["Title ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:P,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-icon",children:["Icon ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:E,onChange:s=>S(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:It.map(s=>e.jsxs("button",{type:"button",className:`agent-role-option${_===s.value?" selected":""}`,onClick:()=>p(s.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:s.icon}),e.jsx("span",{className:"agent-role-option-label",children:s.label})]},s.value))})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Configuration"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-reports-to",children:["Reports To ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:L,onChange:s=>$(s.target.value),disabled:R,children:[e.jsx("option",{value:"",children:"No manager"}),l.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.id,")"]},s.id))]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-soul",children:["Soul ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:z,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-memory",children:["Agent Memory ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-memory",className:"input",rows:2,placeholder:"Private to this agent — durable preferences, operating habits, and context it should carry across tasks...",value:xe,onChange:s=>be(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-path",children:["Instructions Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:ee,onChange:s=>Ne(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-heartbeat-procedure-path",children:["Heartbeat Procedure Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-heartbeat-procedure-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/ceo-agent2736/HEARTBEAT.md",value:le,onChange:s=>ce(s.target.value)}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-field-hint",children:"Path to the agent's heartbeat procedure path, typically .fusion/agents/ceo-agent2736/HEARTBEAT.md. Legacy id-only default paths still work."})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-text",children:["Inline Instructions ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:oe,onChange:s=>te(s.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),Ke("agent-runtime-source-step-0")]}),e.jsxs("div",{className:"agent-dialog-ai-generate",children:[e.jsxs("button",{type:"button",className:"btn btn--ai-generate",onClick:()=>ie(!0),children:[e.jsx("span",{children:"✨"}),"Generate with AI"]}),e.jsx("p",{className:"agent-dialog-ai-hint",children:"Describe your agent's role and let AI generate a specification"})]})]})]}),b===1&&e.jsxs("div",{children:[Ke("agent-runtime-source-step-1"),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-thinking",children:"Thinking Level"}),e.jsxs("select",{id:"agent-thinking",className:"select",value:A.thinkingLevel,onChange:s=>se(v=>({...v,thinkingLevel:s.target.value})),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"minimal",children:"Minimal"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-max-turns",children:"Max Turns"}),e.jsx("input",{id:"agent-max-turns",type:"number",className:"input",min:1,max:2e3,value:A.maxTurns,onChange:s=>se(v=>({...v,maxTurns:Math.max(1,parseInt(s.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(Es,{id:"agent-skills",label:"Skills",value:ae,onChange:U,projectId:u}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),b===2&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Review your agent configuration before creating."}),e.jsxs("div",{className:"agent-dialog-summary",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Name"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[E&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:E}),C]})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable agent-dialog-summary-row--title",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-title",children:"Title"}),e.jsx("input",{id:"agent-review-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:P,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Role"}),e.jsxs("span",{children:[We?.icon," ",We?.label]})]}),Pe&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Reports To"}),e.jsx("span",{children:He?`${He.name} (${He.id})`:Pe})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-soul",children:"Soul"}),e.jsx("textarea",{id:"agent-review-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:z,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-heartbeat-procedure-path",children:"Heartbeat Procedure Path"}),e.jsx("input",{id:"agent-review-heartbeat-procedure-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/ceo-agent2736/HEARTBEAT.md",value:le,onChange:s=>ce(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-instructions-path",children:"Instructions Path"}),e.jsx("input",{id:"agent-review-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:ee,onChange:s=>Ne(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-instructions-text",children:"Inline Instructions"}),e.jsx("textarea",{id:"agent-review-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:oe,onChange:s=>te(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:H==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:H==="runtime"?Oe?Oe.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):I?e.jsxs(e.Fragment,{children:[e.jsx(ss,{provider:I.split("/")[0],size:"sm"})," ",(()=>{const s=I.indexOf("/"),v=I.slice(0,s),he=I.slice(s+1);return Me.find(Re=>Re.provider===v&&Re.id===he)?.name||I})()]}):e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"default"})})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value--capitalize",children:A.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Max Turns"}),e.jsx("span",{children:A.maxTurns})]}),ae.length>0&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Skills"}),e.jsxs("span",{children:[ae.length," skill",ae.length!==1?"s":""," selected"]})]})]}),W&&e.jsx("p",{className:"agent-dialog-error",children:W})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[b>0&&e.jsx("button",{className:"btn",onClick:()=>N(s=>s-1),disabled:ue,children:"Back"}),e.jsx("button",{className:"btn",onClick:ge,disabled:ue,children:"Cancel"}),b<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>N(s=>s+1),disabled:b===0&&!C.trim()&&!de,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void et(),disabled:ue||!C.trim(),children:ue?"Creating...":"Create"})]})]}),e.jsx(Ys,{isOpen:ve,onClose:()=>ie(!1),onGenerated:D,projectId:u}),e.jsx(_s,{isOpen:K,onClose:()=>Q(!1),onUseDraft:s=>{o?.(s),o||je(s),Q(!1)},projectId:u,existingAgents:c,mode:"create"})]}),document.body)}function ta(n){const i=n.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!i)throw new Error("Missing YAML frontmatter delimiters (---)");const f=i[1].split(/\r?\n/),u=i[2]??"",d={name:""},g=[];let c=!1;for(const o of f){const N=o.trimEnd().trim();if(!N)continue;if(N.startsWith("skills:")){c=!0;continue}if(c&&N.startsWith("- ")){g.push(N.slice(2).trim());continue}c=!1;const[k,...M]=N.split(":"),w=M.join(":").trim().replace(/^['"]|['"]$/g,"");k==="name"&&(d.name=w),k==="title"&&(d.title=w),k==="icon"&&(d.icon=w),k==="role"&&(d.role=w),k==="reportsTo"&&(d.reportsTo=w)}if(!d.name)throw new Error("Missing required field: name");return g.length>0&&(d.skills=g),u.trim().length>0&&(d.instructionBody=u),d}function sa({isOpen:n,onClose:i,onImported:f,projectId:u,initialInputMethod:d="paste"}){Dt(n);const[g,c]=a.useState("input"),[o,b]=a.useState(d),[N,k]=a.useState(""),[M,C]=a.useState([]),[w,P]=a.useState("Unknown"),[T,E]=a.useState([]),[S,_]=a.useState([]),[p,L]=a.useState([]),[$,ee]=a.useState([]),[Ne,oe]=a.useState(!1),[te,le]=a.useState(!1),[ce,z]=a.useState(null),[y,xe]=a.useState(null),[be,A]=a.useState(null),se=a.useRef(null),de=a.useRef(null),[ye,ae]=a.useState([]),[U,ue]=a.useState(""),[G,W]=a.useState(null),[V,ve]=a.useState(!1),[ie,K]=a.useState(null),Q=a.useRef(!1);a.useEffect(()=>{o==="browse"&&!Q.current&&!V&&(Q.current=!0,ve(!0),K(null),St().then(l=>{l.error?K(l.error):l.companies.length>0?ae(l.companies):K("No companies available")}).catch(l=>{K(l instanceof Error?l.message:"Failed to load companies")}).finally(()=>{ve(!1)}))},[o,V]);const Me=a.useCallback(()=>{Q.current=!0,K(null),ae([]),W(null),ve(!0),St().then(l=>{l.error?K(l.error):l.companies.length>0?ae(l.companies):K("No companies available")}).catch(l=>{K(l instanceof Error?l.message:"Failed to load companies")}).finally(()=>{ve(!1)})},[]),Ee=a.useCallback(()=>{c("input"),b(d),k(""),C([]),P("Unknown"),E([]),_([]),L([]),ee([]),oe(!1),le(!1),z(null),xe(null),A(null),ae([]),ue(""),W(null),ve(!1),K(null),Q.current=!1},[d]),_e=a.useCallback(()=>{Ee(),i()},[Ee,i]),ke=a.useCallback(l=>{const x=l.target.files?.[0];if(!x)return;const R=new FileReader;R.onload=q=>{const I=q.target?.result;b("file"),C([]),k(I),z(null)},R.onerror=()=>{z("Failed to read file")},R.readAsText(x),l.target.value=""},[]),me=a.useCallback(async l=>{const x=Array.from(l.target.files??[]);if(x.length!==0)try{const R=x.filter(I=>(I.webkitRelativePath||I.name).toLowerCase().endsWith("agents.md")).sort((I,D)=>{const Te=I.webkitRelativePath||I.name,Le=D.webkitRelativePath||D.name;return Te.localeCompare(Le)});if(R.length===0){z("Selected directory has no AGENTS.md files");return}const q=[];for(const I of R){const D=await I.text();q.push(ta(D))}b("directory"),C(q),k(""),z(null)}catch{z("Failed to parse AGENTS.md files from selected directory")}finally{l.target.value=""}},[]);function we(l){if(!u)return`/api${l}`;const x=l.includes("?")?"&":"?";return`/api${l}${x}projectId=${encodeURIComponent(u)}`}const X=a.useCallback(async()=>{if(o==="directory"&&M.length===0){z("Please select a directory containing AGENTS.md files");return}if(o==="browse"&&!G){z("Please select a company from the catalog");return}if(o!=="directory"&&o!=="browse"&&!N.trim()){z("Please provide manifest content");return}oe(!0),z(null);try{let l;o==="directory"?l={agents:M,dryRun:!0}:o==="browse"&&G?l={importSource:"companies.sh",companySlug:G.slug,dryRun:!0}:l={manifest:N,dryRun:!0};const x=await fetch(we("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!x.ok){const D=await x.json();throw new Error(D.error??`Parse failed (${x.status})`)}const R=await x.json(),q=R.agents&&R.agents.length>0?R.agents:R.created.map(D=>({name:D,role:"custom"})),I=Array.isArray(R.skills)?R.skills:[];P(R.companyName??"Unknown"),E(q),_(I),L(q.map(D=>D.name)),ee(I.map(D=>D.name)),c("preview")}catch(l){z(l instanceof Error?l.message:"Failed to parse manifest")}finally{oe(!1)}},[o,M,N,G,u]),$e=a.useCallback(async()=>{le(!0),A(null);try{let l;o==="directory"?l={agents:M,skipExisting:!0,selectedAgents:p,selectedSkills:$}:o==="browse"&&G?l={importSource:"companies.sh",companySlug:G.slug,skipExisting:!0,selectedAgents:p,selectedSkills:$}:l={manifest:N,skipExisting:!0,selectedAgents:p,selectedSkills:$};const x=await fetch(we("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!x.ok){const q=await x.json();throw new Error(q.error??`Import failed (${x.status})`)}const R=await x.json();xe(R),c("result"),f()}catch(l){A(l instanceof Error?l.message:"Failed to import agents")}finally{le(!1)}},[o,M,N,G,p,$,u,f]),H=p.length,F=$.length,re=`${H} Agent${H!==1?"s":""}`,Z=`${F} Skill${F!==1?"s":""}`,Ce=H>0&&F>0?`${re} + ${Z}`:F>0?Z:re,Y=H>0&&F>0?`Importing ${H} agent${H!==1?"s":""} and ${F} skill${F!==1?"s":""}...`:F>0?`Importing ${F} skill${F!==1?"s":""}...`:`Importing ${H} agent${H!==1?"s":""}...`,Se=l=>{L(x=>x.includes(l)?x.filter(R=>R!==l):[...x,l])},Ae=l=>{ee(x=>x.includes(l)?x.filter(R=>R!==l):[...x,l])};return n?e.jsx("div",{className:"agent-dialog-overlay",onClick:l=>{l.target===l.currentTarget&&_e()},children:e.jsxs("div",{className:"agent-dialog agent-import-dialog",role:"dialog","aria-modal":"true","aria-label":"Import agents",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"Import Agents"}),e.jsx("button",{className:"modal-close",onClick:_e,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[g==="input"&&e.jsxs("div",{className:"agent-import-input",children:[e.jsx("p",{className:"agent-import-description",children:"Import agents from an Agent Companies package. Browse the companies.sh catalog to discover published agents, upload an AGENTS.md file, select a directory, or paste manifest content."}),e.jsxs("div",{className:"agent-import-file-upload",children:[e.jsx("input",{ref:se,type:"file",accept:".md,.txt",onChange:ke,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:de,type:"file",webkitdirectory:"",multiple:!0,onChange:me,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>se.current?.click(),children:[e.jsx(bt,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>de.current?.click(),children:[e.jsx(Ls,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{b("browse"),C([]),k(""),W(null),z(null)},children:[e.jsx(is,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),o==="browse"&&e.jsxs("div",{className:"agent-import-browse",children:[e.jsxs("div",{className:"agent-import-browse-header",children:[e.jsxs("div",{className:"agent-import-browse-search",children:[e.jsx(rs,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:U,onChange:l=>ue(l.target.value),"aria-label":"Search companies"})]}),G&&e.jsxs("div",{className:"agent-import-browse-selected",children:[e.jsx("span",{className:"agent-import-browse-selected-label",children:"Selected:"}),e.jsx("span",{className:"agent-import-browse-selected-name",children:G.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>W(null),children:"Change"})]})]}),V&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(lt,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),ie&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(it,{size:16}),e.jsx("span",{children:ie}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Me,children:[e.jsx(Ve,{size:14}),"Retry"]})]}),!V&&!ie&&e.jsxs("div",{className:"agent-import-browse-list",children:[ye.filter(l=>U===""||l.name.toLowerCase().includes(U.toLowerCase())||(l.tagline?.toLowerCase().includes(U.toLowerCase())??!1)).map(l=>e.jsxs("div",{className:`agent-import-browse-item ${G?.slug===l.slug?"agent-import-browse-item--selected":""}`,onClick:()=>W(l),role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&W(l)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:l.name}),l.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[l.installs.toLocaleString()," installs"]})]}),l.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:l.tagline}),l.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:l.repo})]},l.slug)),ye.filter(l=>U===""||l.name.toLowerCase().includes(U.toLowerCase())||(l.tagline?.toLowerCase().includes(U.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:U?"No companies match your search":"No companies available"})]})]}),o!=="browse"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-divider",children:e.jsx("span",{children:"or paste manifest content"})}),e.jsx("textarea",{className:"agent-import-textarea",placeholder:`---
28
- name: CEO
29
- title: Chief Executive Officer
30
- reportsTo: null
31
- skills:
32
- - review
33
- ---
34
- Agent instructions go here...`,value:N,onChange:l=>{b("paste"),C([]),k(l.target.value),z(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",o]}),ce&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(it,{size:14}),ce]})]}),g==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:w})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(pt,{size:14}),e.jsxs("span",{children:[T.length," agent",T.length!==1?"s":""," found"]})]}),T.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(T.map(l=>l.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((l,x)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${l.name}`,checked:p.includes(l.name),onChange:()=>Se(l.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:l.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:l.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[l.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[l.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:l.role}),l.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",l.reportsTo]}),l.skills&&l.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",l.skills.join(", ")]})]}),l.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[l.instructionsText.slice(0,100),l.instructionsText.length>100?"...":""]})]})]},x))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),S.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(pt,{size:14}),e.jsxs("span",{children:[S.length," skill",S.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>ee(S.map(l=>l.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>ee([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((l,x)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${l.name}`,checked:$.includes(l.name),onChange:()=>Ae(l.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:l.name}),l.description&&e.jsx("span",{className:"agent-import-skill-description",children:l.description})]})]},`${l.name}-${x}`))})]}),be&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(it,{size:14}),be]})]}),g==="result"&&y&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(Je,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:y.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[y.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[y.created.length," created"]})}),y.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[y.skipped.length," skipped (already exist)"]})}),y.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[y.errors.length," error",y.errors.length!==1?"s":""]})})]}),y.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:y.created.map((l,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Je,{size:12}),e.jsx("span",{children:l.name})]},x))}),y.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:y.errors.map((l,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(At,{size:12}),e.jsxs("span",{children:[l.name,": ",l.error]})]},x))}),y.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[y.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[y.skills.imported.length," skill",y.skills.imported.length!==1?"s":""," imported"]})}),y.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[y.skills.skipped.length," skill",y.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),y.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[y.skills.errors.length," skill",y.skills.errors.length!==1?"s":""," error",y.skills.errors.length!==1?"s":""]})}),y.skills.imported.length===0&&y.skills.skipped.length===0&&y.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),y.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:y.skills.imported.map((l,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Je,{size:12}),e.jsx("span",{children:l.name})]},x))}),y.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:y.skills.errors.map((l,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(At,{size:12}),e.jsxs("span",{children:[l.name,": ",l.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[g==="preview"&&e.jsx("button",{className:"btn",onClick:()=>c("input"),disabled:te,children:"Back"}),e.jsx("button",{className:"btn",onClick:_e,disabled:te,children:g==="result"?"Close":"Cancel"}),g==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void X(),disabled:Ne||(o==="directory"?M.length===0:o==="browse"?!G:!N.trim()),children:Ne?e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),g==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void $e(),disabled:te||H===0&&F===0,children:te?e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:14,className:"spin"}),Y]}):`Import ${Ce}`})]})]})}):null}const Ht=220,aa=24,na=24,la=16;function Ot(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Ot(f),0)}function ia(n){const i=Ot(n);return i*Ht+Math.max(0,i-1)*aa}function ra(n){if(n.length===0)return Ht;const f=n.map(ia).reduce((d,g)=>d+g,0),u=Math.max(0,n.length-1)*na;return f+u+la*2}function oa(n){const i=Number.isFinite(n.availableWidth)&&n.availableWidth>0?n.availableWidth:0;return i===0||n.tree.length<=1?"horizontal":ra(n.tree)>i?"vertical":"horizontal"}const Pt=a.lazy(()=>ks(()=>import("./AgentDetailView-V32TpEe1.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(n=>({default:n.AgentDetailView}))),qe=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],mt=[.1,.25,.5,1,2,3,5,10],gt=[.75,1,1.25,1.5];function vt(n){switch(n){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"idle":default:return"agent-badge--idle"}}function jt(n,i){switch(i){case"running":return`${n}--running`;case"active":return`${n}--active`;case"paused":return`${n}--paused`;case"error":return`${n}--error`;case"idle":default:return`${n}--idle`}}function Qe(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Qe(f),0)}function ft(n,i){return n.state==="error"?{title:void 0,label:"Error"}:{title:i.reason??i.label,label:i.stateDerived?null:i.label}}function Bt({node:n,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d}){const{agent:g,children:c}=n,o=f(g),b=ft(g,o),N=vt(g.state),k=jt("org-chart-node-card",g.state),M=Qe(n),C={"--org-chart-subtree-leaves":String(M)},w=c.length>0?Qe(c[0]):1,P=c.length>0?Qe(c[c.length-1]):1,T={"--org-chart-first-child-leaves":String(w),"--org-chart-last-child-leaves":String(P)};return e.jsxs("div",{className:`org-chart-node${c.length>0?" org-chart-node--has-children":""}`,style:C,children:[e.jsxs("div",{className:`${k}${d===g.id?" agent-card--selected":""}`,onClick:()=>i(g.id),role:"button",tabIndex:0,onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.key===" "&&E.preventDefault(),i(g.id))},children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:e.jsx(Xe,{agent:g,size:20})}),e.jsx("span",{className:"org-chart-node__name",children:g.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${N}`,children:g.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:o.color},title:b.title,children:[o.icon,b.label&&e.jsx("span",{className:"text-secondary",children:b.label})]})]})]}),c.length>0&&e.jsx("div",{className:"org-chart-children",style:T,role:"group","aria-label":`${g.name} employees`,children:c.map(E=>e.jsx(Bt,{node:E,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d},E.agent.id))})]})}function pa({addToast:n,projectId:i,onOpenTaskLogs:f,agentOnboardingEnabled:u=!1}){const[d,g]=a.useState(!1),o=os()==="mobile",[b,N]=a.useState("all"),{agents:k,stats:M,isLoading:C,loadAgents:w,refreshAgents:P}=cs(i,{filterState:b,showSystemAgents:d}),[T,E]=a.useState(!1),[S,_]=a.useState(null),[p,L]=a.useState(!1),[$,ee]=a.useState(null),[Ne,oe]=a.useState(null),te=o&&!!$,[le,ce]=a.useState("dashboard"),[z,y]=a.useState(null),[xe,be]=a.useState(!1),[A,se]=a.useState(()=>{if(typeof window>"u")return"list";const t=Tt("fn-agent-view",i);return t==="list"||t==="board"||t==="org"?t:"list"}),[de,ye]=a.useState([]),[ae,U]=a.useState(!1),[ue,G]=a.useState(0),[W,V]=a.useState(!1),[ve,ie]=a.useState(!1),[K,Q]=a.useState(1),Me=a.useRef(null),Ee=a.useRef(null),{confirm:_e}=ds(),ke=a.useRef(null),me=a.useId();a.useEffect(()=>{const t=Tt("fn-agent-view",i);if(t==="list"||t==="board"||t==="org"){se(t);return}se("list")},[i]),a.useEffect(()=>{us("fn-agent-view",A,i)},[A,i]);const[we,X]=a.useState(null),$e=a.useRef(null),[H,F]=a.useState(null),[re,Z]=a.useState(null),[Ce,Y]=a.useState({}),[Se,Ae]=a.useState(1),[l,x]=a.useState(!1),[R,q]=a.useState(new Set),[I,D]=a.useState(new Map),Te=a.useRef(!0);a.useEffect(()=>(Te.current=!0,()=>{Te.current=!1}),[]),a.useEffect(()=>{ms(i).then(t=>{Te.current&&Ae(t.heartbeatMultiplier??1)}).catch(()=>{})},[i]);const Le=a.useCallback(async t=>{const r=Number.isFinite(t)&&t>0?t:1;Ae(r),x(!0);try{await gs({heartbeatMultiplier:r},i),n(`Heartbeat speed set to ×${r.toFixed(1)}`,"success")}catch(m){n(`Failed to save heartbeat multiplier: ${fe(m)}`,"error")}finally{Te.current&&x(!1)}},[i,n]),Fe=a.useMemo(()=>I.size===0?k:k.map(t=>{const r=I.get(t.id);return r?{...t,state:r}:t}),[k,I]),Ie=a.useMemo(()=>Fe.filter(t=>d||!rt(t)),[Fe,d]),Ye=a.useMemo(()=>Fe.filter(t=>t.state!=="active"&&t.state!=="running"?!1:d||!rt(t)),[Fe,d]),je=a.useMemo(()=>{if(d)return de;const t=r=>rt(r.agent)?null:{...r,children:r.children.map(t).filter(m=>m!==null)};return de.map(t).filter(r=>r!==null)},[de,d]);a.useEffect(()=>{if(A!=="org")return;const t=Ee.current;if(!t)return;const r=()=>{G(t.clientWidth)};r();const m=typeof ResizeObserver<"u"?new ResizeObserver(r):null;return m?.observe(t),window.addEventListener("resize",r),()=>{m?.disconnect(),window.removeEventListener("resize",r)}},[A,je.length]),a.useEffect(()=>{if(A!=="org")return;let t=!1;return U(!0),hs(i,{includeEphemeral:d}).then(r=>{t||ye(r)}).catch(r=>{t||(n(`Failed to load org chart: ${fe(r)}`,"error"),ye([]))}).finally(()=>{t||U(!1)}),()=>{t=!0}},[A,i,d,n]),a.useEffect(()=>{const t=setInterval(()=>{w()},3e4);return()=>{clearInterval(t)}},[w]),a.useEffect(()=>{if(!W)return;const t=m=>{const j=m.target;j&&(Me.current?.contains(j)||ke.current?.contains(j)||V(!1))},r=m=>{m.key==="Escape"&&(V(!1),ke.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",r)}},[W]);const ge=async(t,r)=>{if(!R.has(t)){q(m=>new Set(m).add(t)),D(m=>{const j=new Map(m);return j.set(t,r),j});try{await Ss(t,r,i),n(`Agent state updated to ${r}`,"success"),await w(),D(m=>{const j=new Map(m);return j.delete(t),j})}catch(m){D(j=>{const O=new Map(j);return O.delete(t),O}),n(`Failed to update state: ${fe(m)}`,"error")}finally{q(m=>{const j=new Set(m);return j.delete(t),j})}}},et=async(t,r)=>{if(await _e({title:"Delete Agent",message:`Delete agent "${r}"? This cannot be undone.`,danger:!0}))try{await Ts(t,i),n(`Agent "${r}" deleted`,"success"),await w()}catch(j){n(`Failed to delete agent: ${fe(j)}`,"error")}},We=async(t,r)=>{const m=k.find(j=>j.id===t);if(m){if(m.role===r){X(null);return}try{await Ze(t,{role:r},i),n(`Agent role updated to ${qe.find(j=>j.value===r)?.label??r}`,"success"),X(null),w()}catch(j){n(`Failed to update role: ${fe(j)}`,"error")}}},Pe=(t,r)=>{t.key==="Escape"&&X(null)},He=async(t,r)=>{re===t.id&&(Z(null),Y(m=>{const j={...m};return delete j[t.id],j})),F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:r}},i),n(`Heartbeat interval updated to ${Et(r)} for ${t.name}`,"success"),w()}catch(m){n(`Failed to update heartbeat interval: ${fe(m)}`,"error")}finally{F(null)}},Oe=async t=>{const r=Ce[t.id]??"";if(r.trim()===""){n("Please enter a heartbeat interval in minutes","error");return}const m=Number(r);if(isNaN(m)){n("Heartbeat interval must be a valid number","error");return}if(m<=0){n("Heartbeat interval must be greater than 0","error");return}if(m>=1&&m<5){F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:Cs}},i),n(`Heartbeat interval set to 5 minutes (minimum). ${m} minute${m!==1?"s":""} was below the 5-minute minimum.`,"success"),Z(null),Y(O=>{const J={...O};return delete J[t.id],J}),w()}catch(O){n(`Failed to update heartbeat interval: ${fe(O)}`,"error")}finally{F(null)}return}const j=Math.round(m*6e4);F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:j}},i),n(`Heartbeat interval updated to ${Et(j)} for ${t.name}`,"success"),Z(null),Y(O=>{const J={...O};return delete J[t.id],J}),w()}catch(O){n(`Failed to update heartbeat interval: ${fe(O)}`,"error")}finally{F(null)}},Ke=t=>{const r=ht(t.runtimeConfig?.heartbeatIntervalMs),m=Math.round(r/6e4);Z(t.id),Y(j=>({...j,[t.id]:String(m)}))},s=a.useCallback((t,r)=>{ee(t),ce(r?.initialTab??"dashboard"),y(r?.initialRunId??null),be(r?.preferActiveRun??!1)},[]),v=a.useCallback(()=>{ee(null),ce("dashboard"),y(null),be(!1)},[]),he=a.useCallback(t=>{s(t)},[s]),ne=a.useCallback(t=>{oe(t),s(t)},[s]),Re=a.useCallback(async({agentId:t,deleted:r})=>{await P(),r&&$===t&&v()},[P,$,v]),Gt=a.useCallback(t=>{s(t),o&&ie(!1)},[o,s]),Vt=async(t,r)=>{D(m=>{const j=new Map(m);return j.set(t,"running"),j});try{await As(t,i,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),n(`Heartbeat run started for ${r}`,"success"),await w(),D(m=>{const j=new Map(m);return j.delete(t),j})}catch(m){D(j=>{const O=new Map(j);return O.delete(t),O}),n(`Failed to start heartbeat run: ${fe(m)}`,"error")}},tt=a.useCallback(t=>{se(t),t!=="org"&&Q(1),o&&$&&v()},[v,o,$]),Nt=t=>qe.find(r=>r.value===t)?.label??t,Ut=t=>qe.find(r=>r.value===t)?.icon??"◆",yt=gt[K],kt=a.useMemo(()=>oa({tree:je,availableWidth:ue}),[je,ue]),Wt=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],st=t=>ws(t),wt=C&&k.length===0,Be=a.useCallback(()=>{E(!0)},[]);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(xt,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${A==="list"?" active":""}`,onClick:()=>tt("list"),title:"List view","aria-label":"List view","aria-pressed":A==="list",children:e.jsx(ps,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="board"?" active":""}`,onClick:()=>tt("board"),title:"Board view","aria-label":"Board view","aria-pressed":A==="board",children:e.jsx(De,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="org"?" active":""}`,onClick:()=>tt("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":A==="org",children:e.jsx(xs,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:ke,className:`btn-icon agent-controls-trigger${W?" agent-controls-trigger--active":""}`,onClick:()=>V(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":W,"aria-controls":me,children:e.jsx(Hs,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void w(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Ve,{size:16,className:C?"spin":void 0})}),!o&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{L(!0),V(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(bt,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{Be(),V(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(Rt,{size:16}),"New Agent"]})]}),W&&e.jsxs("div",{ref:Me,id:me,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsx("div",{className:"agent-controls",children:e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(bs,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:b,onChange:t=>N(t.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:t=>g(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]})}),o&&e.jsxs("div",{className:"agent-controls-mobile-actions",children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{L(!0),V(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(bt,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{Be(),V(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(Rt,{size:16}),"New Agent"]})]}),e.jsx("div",{className:"agent-global-controls agent-controls-actions",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:Se,onChange:t=>{const r=Number(t.target.value);Le(Number.isFinite(r)&&r>0?r:1)},disabled:l}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",Se.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(mt.reduce((t,r)=>Math.abs(r-Se)<Math.abs(t-Se)?r:t,mt[0])),onChange:t=>{const r=Number(t.target.value);Le(Number.isFinite(r)&&r>0?r:1)},disabled:l,"aria-label":"Heartbeat speed preset",children:mt.map(t=>e.jsxs("option",{value:String(t),children:["×",t]},t))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(Us,{agents:Ie})]})]})]})]}),e.jsx(ea,{isOpen:T,onClose:()=>{E(!1),_(null)},onCreated:()=>{E(!1),_(null),w()},projectId:i,prefillDraft:S,agentOnboardingEnabled:u,existingAgents:k,onPrefillDraft:_}),e.jsx(sa,{isOpen:p,onClose:()=>L(!1),onImported:()=>void w(),projectId:i}),e.jsx(Xs,{stats:M,activeAgents:Ye,projectId:i,isOpen:ve,onToggle:()=>ie(t=>!t),onSelectAgent:Gt,onOpenTaskLogs:f}),A==="org"?e.jsx("div",{className:"agents-org-full-view",children:e.jsx("div",{className:"agents-view-content agents-view-content--org-full",children:$?e.jsxs("div",{className:"agents-org-detail-view","data-testid":"agents-org-detail-view",children:[e.jsx("button",{type:"button",className:"btn btn-sm agents-org-detail-back",onClick:v,"aria-label":"Back to org chart",children:"Back to org chart"}),e.jsx(a.Suspense,{fallback:null,children:e.jsx(Pt,{inline:!0,showInlineBackButton:!1,agentId:$,projectId:i,onClose:v,addToast:n,onChildClick:he,initialTab:le,initialRunId:z,preferActiveRun:xe},$)})]}):wt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):e.jsxs("div",{className:"agent-org-chart-shell","data-testid":"agent-org-chart-shell",children:[o?e.jsxs("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:[e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>Q(t=>Math.max(0,t-1)),disabled:K===0,"aria-label":"Zoom out org chart",title:"Zoom out",children:e.jsx(Vs,{size:16})}),e.jsxs("span",{className:"agent-org-chart-controls__zoom-label","aria-live":"polite",children:[Math.round(yt*100),"%"]}),e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>Q(t=>Math.min(gt.length-1,t+1)),disabled:K===gt.length-1,"aria-label":"Zoom in org chart",title:"Zoom in",children:e.jsx(Bs,{size:16})}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm agent-org-chart-controls__fit-btn",onClick:()=>Q(1),"aria-label":"Fit org chart",title:"Fit org chart",children:[e.jsx(vs,{size:16}),"Fit"]})]}):null,e.jsx("div",{ref:Ee,className:"agent-org-chart-viewport","data-testid":"agent-org-chart-viewport",children:e.jsx("div",{className:`agent-org-chart-canvas agent-org-chart-canvas--zoom-${Math.round(yt*100)}`,children:e.jsx("div",{className:`agent-org-chart${kt==="vertical"?" agent-org-chart--vertical":""}`,"data-testid":"agent-org-chart","data-layout-mode":kt,children:ae?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):je.length===0?e.jsx(dt,{onCtaClick:Be}):je.map(t=>e.jsx(Bt,{node:t,onSelect:ne,getHealthStatus:st,getRoleIcon:Ut,selectedAgentId:Ne},t.agent.id))})})})]})})}):e.jsxs("div",{className:"agents-split-layout",children:[e.jsx("div",{className:`agents-split-sidebar${te?" agents-split-sidebar--hidden-mobile":""}`,children:e.jsx("div",{className:"agents-view-content",children:wt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):A==="board"?e.jsx("div",{className:"agent-board",children:Ie.length===0?e.jsx(dt,{onCtaClick:Be}):Ie.map(t=>{const r=st(t),m=ft(t,r),j=vt(t.state),O=jt("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${O}${$===t.id?" agent-card--selected":""}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>s(t.id),role:"button",tabIndex:0,onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.key===" "&&J.preventDefault(),s(t.id))},children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:e.jsx(Xe,{agent:t,size:20})}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:Nt(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${j}`,children:t.state}),(t.pendingApprovalCount??0)>0?e.jsxs("span",{className:"agent-board-badge badge agent-approval-badge",title:"Pending approvals",children:[e.jsx("span",{className:"status-dot status-dot--pending"}),t.pendingApprovalCount]}):null]}),e.jsx("div",{className:"agent-board-name",children:t.name}),e.jsx("div",{className:"agent-board-id",children:t.id}),e.jsxs("div",{className:"agent-board-health",style:{color:r.color},title:m.title,children:[r.icon,m.label?` ${m.label}`:""]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:Ie.length===0?e.jsx(dt,{onCtaClick:Be}):Ie.map(t=>{const r=st(t),m=ft(t,r),j=vt(t.state),O=jt("agent-card",t.state),J=ht(t.runtimeConfig?.heartbeatIntervalMs),Kt=js(J),Ge=H===t.id;return e.jsxs("div",{className:`agent-card agent-card--clickable ${O}${$===t.id?" agent-card--selected":""}`,onClick:h=>{const B=h.target;if(B===h.currentTarget){s(t.id);return}const pe=B.closest('button, select, input, [role="button"]');pe&&pe!==h.currentTarget||s(t.id)},role:"button",tabIndex:0,onKeyDown:h=>{h.target===h.currentTarget&&(h.key==="Enter"||h.key===" ")&&(h.key===" "&&h.preventDefault(),s(t.id))},"aria-label":`Open details for ${t.name}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info",children:[we===t.id?e.jsx("select",{ref:$e,className:"select agent-role-select",value:t.role,onChange:h=>void We(t.id,h.target.value),onKeyDown:h=>Pe(h,t.id),onBlur:()=>X(null),autoFocus:!0,children:qe.map(h=>e.jsxs("option",{value:h.value,children:[h.icon," ",h.label]},h.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:h=>{h.stopPropagation(),X(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.stopPropagation(),X(t.id))},children:e.jsx(Xe,{agent:t,size:20})}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:t.name}),e.jsx("span",{className:"agent-id text-secondary",children:t.id})]}),e.jsx(zt,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${j}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:r.color},title:m.title,children:[r.icon,m.label?` ${m.label}`:""]}),e.jsx("span",{className:"badge text-secondary",children:Nt(t.role)}),(t.pendingApprovalCount??0)>0?e.jsxs("span",{className:"badge agent-approval-badge",title:"Pending approvals",children:[e.jsx("span",{className:"status-dot status-dot--pending"}),t.pendingApprovalCount]}):null,(()=>{const h=Wt(t);if(h.length===0)return null;const B=h.slice(0,2),pe=h.length-2;return e.jsxs(e.Fragment,{children:[B.map(at=>e.jsx("span",{className:"badge badge-skill",title:at,children:$s(at)},at)),pe>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",pe]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.state==="error"&&t.lastError?e.jsx(fs,{errorText:t.lastError,issueContext:{surface:"AgentsView list",agentId:t.id,agentName:t.name,agentState:t.state,taskId:t.taskId}}):null,t.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:t.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),re===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Ce[t.id]??"",onChange:h=>Y(B=>({...B,[t.id]:h.target.value})),onKeyDown:h=>{h.key==="Enter"?Oe(t):h.key==="Escape"&&(Z(null),Y(B=>{const pe={...B};return delete pe[t.id],pe}))},disabled:Ge,"aria-label":`Custom heartbeat interval in minutes for ${t.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>void Oe(t),disabled:Ge,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>{Z(null),Y(h=>{const B={...h};return delete B[t.id],B})},disabled:Ge,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:J,onChange:h=>{const B=h.target.value;B==="__custom__"?Ke(t):He(t,Number(B))},disabled:Ge,"aria-label":`Set heartbeat interval for ${t.name}`,children:[Kt.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value)),Ns.some(h=>h.value===J)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),Ge&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const h=new Date(t.lastHeartbeatAt),B=new Date(h.getTime()+J),pe=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:h.toLocaleString(),children:["Last: ",h.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),pe&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:B.toLocaleString(),children:["Next: ",B.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--primary",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Activate",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Start"})]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>void Vt(t.id,t.name),disabled:R.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(De,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Run Now"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"paused"),disabled:R.has(t.id),title:"Pause",children:[e.jsx(Mt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Resume",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Resume"})]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>s(t.id,{initialTab:"runs",initialRunId:null,preferActiveRun:!0}),title:"View live run details","aria-label":`View live run details for ${t.name}`,children:[e.jsx(De,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Running"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"paused"),disabled:R.has(t.id),title:"Pause",children:[e.jsx(Mt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Retry",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Retry"})]})]}),e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--secondary",children:[e.jsxs("button",{className:"btn btn-sm agent-card-details-btn",onClick:()=>s(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:[e.jsx(Fs,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Details"})]}),(t.state==="idle"||t.state==="paused")&&e.jsxs("button",{className:"btn btn-sm btn-danger",onClick:()=>void et(t.id,t.name),title:"Delete",children:[e.jsx(ys,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Delete"})]})]})]})]},t.id)})})})}),e.jsx("div",{className:`agents-split-detail${o&&!$?" agents-split-detail--hidden-mobile":""}`,children:$?e.jsx(a.Suspense,{fallback:null,children:e.jsx(Pt,{inline:!0,showInlineBackButton:o,agentId:$,projectId:i,onClose:v,addToast:n,onChildClick:he,initialTab:le,initialRunId:z,preferActiveRun:xe,onMutationSuccess:Re},$)}):e.jsxs("div",{className:"agents-detail-empty-state",children:[e.jsx(xt,{size:48}),e.jsx("h3",{children:"Select an agent"}),e.jsx("p",{children:"Choose an agent from the sidebar to view details"})]})})]})]})}export{pa as AgentsView};
@@ -1 +0,0 @@
1
- import{r as n,a as Js,j as t,R as Ys}from"./vendor-react-K0fH_qHe.js";import{i as ft,b4 as us,t as Ms,b5 as Qs,b6 as ms,b7 as Zs,w as Ht,b8 as Oe,b9 as en,ba as tn,bb as sn,bc as nn,bd as an,be as rn,s as Rs,bf as on,bg as cn,bh as Pt,bi as ln,bj as dn,bk as un,bl as mn,k as As,bm as hn,bn as fn,p as gn,bo as pn,bp as bn,u as vn,bq as xn,ab as Es,ac as Ts,br as yn,bs as wn,S as Sn,W as Lt,P as Qe,I as lt,ao as Nn,bt as hs,bu as fs,bv as gs,B as Ze,a as ps,a8 as Cn,a9 as kn,aV as ht,bw as jn,bx as Mn,aS as Rn,by as bs,bz as An,T as En,bA as vs,bB as Tn,h as Dn,j as xs,m as In}from"./index-DiewofJh.js";import"./vendor-xterm-DzcZoU0P.js";const Ft="kb-chat-active-session";function ys(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 $n(s){const r=s?.toolCalls;if(!Array.isArray(r))return;const l=r.map(i=>{if(!i||typeof i!="object")return null;const d=i,v=typeof d.toolName=="string"?d.toolName:"";if(!v)return null;const M=d.args;return{toolName:v,...M&&typeof M=="object"?{args:M}:{},isError:!!d.isError,result:d.result,status:"completed"}}).filter(i=>i!==null);return l.length>0?l:void 0}function Pn(s){const r=s?.fallback;if(!r||typeof r!="object")return;const l=r,i=typeof l.primaryModel=="string"?l.primaryModel:"",d=typeof l.fallbackModel=="string"?l.fallbackModel:"",v=l.triggerPoint;if(!(!i||!d||v!=="session-creation"&&v!=="prompt-time"))return{primaryModel:i,fallbackModel:d,triggerPoint:v}}function Ln(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 d=(()=>{const v=l.reference;if(!v||typeof v!="object")return;const M=v,T=typeof M.kind=="string"?M.kind.trim():"",D=typeof M.id=="string"?M.id.trim():"";if(!(!T||!D))return{kind:T,id:D,...typeof M.label=="string"&&M.label.trim()?{label:M.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()}:{},...d?{reference:d}:{}}}function ws(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 _t(s){return{id:s.id,sessionId:s.sessionId,role:s.role,content:s.content,thinkingOutput:s.thinkingOutput,toolCalls:$n(s.metadata),fallbackInfo:Pn(s.metadata),failureInfo:Ln(s.metadata),attachments:s.attachments,createdAt:s.createdAt}}function Fn(s,r){const[l,i]=n.useState([]),[d,v]=n.useState(null),[M,T]=n.useState(!0),[D,S]=n.useState([]),[Y,w]=n.useState(!1),[_,g]=n.useState(!1),[ee,R]=n.useState(""),[U,b]=n.useState(""),[j,I]=n.useState([]),[A,E]=n.useState(""),[V,q]=n.useState(""),[z,h]=n.useState(!0),[f,o]=n.useState(new Map),c=n.useRef(null),m=n.useRef(!1),x=n.useRef(""),k=n.useRef(null),Q=n.useRef(l),O=n.useRef(d),se=n.useRef(_);Q.current=l,O.current=d,se.current=_,n.useEffect(()=>{x.current=A},[A]);const xe=n.useRef(new Set),ue=n.useRef(0),me=n.useRef(s);me.current!==s&&(me.current=s,ue.current++),n.useEffect(()=>{const p=ue.current;ft(void 0,s).then(y=>{if(ue.current!==p)return;const C=new Map;for(const P of y)C.set(P.id,P);o(C)}).catch(()=>{})},[s]);const re=n.useCallback(async()=>{T(!0);try{const y=[...(await us(s)).sessions].sort((C,P)=>new Date(P.updatedAt).getTime()-new Date(C.updatedAt).getTime());i(y)}catch{}finally{T(!1)}},[s]);n.useEffect(()=>{re()},[re]);const $e=n.useRef(()=>{}),Te=n.useRef(!1);n.useEffect(()=>{Te.current=!1},[s]),n.useEffect(()=>{if(M||Te.current||O.current)return;const p=Ms(Ft,s);if(!p){Te.current=!0;return}const y=l.find(C=>C.id===p);if(y){Te.current=!0,$e.current(p,y);return}Te.current=!0},[M,l,s]);const ae=n.useCallback(async(p,y)=>{w(!0);try{const C=await Qs(p,{limit:50,...y},s),P=C.messages.map(_t);y?.offset&&y.offset>0?S(te=>[...P,...te]):S(P),h(C.messages.length>=50)}catch{}finally{w(!1)}},[s]),oe=n.useCallback(()=>{k.current?.(),k.current=null,x.current="",E(""),R(""),b(""),I([]),g(!1)},[]),he=n.useCallback((p,y)=>{if(c.current||!p)return!0;m.current=!1,y&&(R(y.streamingText),b(y.streamingThinking),I(y.toolCalls)),g(!0);const{handlers:C}=ms({sessionId:p,tempUserMessageId:"",setStreamingText:R,setStreamingThinking:b,setStreamingToolCalls:I,cancelStreamingFlushesRef:k,addToast:r,onFallbackSession:(te,G)=>{const Z=ys(te.fallbackModel);i(L=>L.map(X=>X.id===G?{...X,...Z}:X)),v(L=>L&&L.id===G?{...L,...Z}:L)},onDone:()=>{R(""),b(""),I([]),g(!1),se.current=!1,c.current=null,ae(p)},onError:te=>{R(""),b(""),I([]),g(!1),se.current=!1,c.current=null;const G=ws(te);r?.(G.summary,"error"),ae(p)}}),P=Zs(p,C,s,{...typeof y?.replayFromEventId=="number"?{lastEventId:y.replayFromEventId}:{}});return c.current=P,!0},[r,ae,s]),ye=n.useCallback((p,y)=>{const C=O.current?.id??null;if(p&&C===p&&!y)return;c.current&&(c.current.close(),c.current=null);const P=y??l.find(te=>te.id===p);v(P||null),oe(),h(!0),p?ae(p):S([]),P?.isGenerating&&he(P.id,P.inFlightGeneration),p?Ht(Ft,p,s):Oe(Ft,s)},[he,l,ae,s,oe]);$e.current=ye;const et=n.useCallback(async p=>{const y=await en(p,s);c.current&&(c.current.close(),c.current=null);const C={id:y.session.id,title:y.session.title,agentId:y.session.agentId,status:y.session.status,modelProvider:y.session.modelProvider,modelId:y.session.modelId,createdAt:y.session.createdAt,updatedAt:y.session.updatedAt};return i(P=>P.some(te=>te.id===C.id)?P:[C,...P]),oe(),ye(C.id,C),S([]),C},[s,oe,ye]),gt=n.useCallback(async p=>{await tn(p,{status:"archived"},s),i(y=>y.filter(C=>C.id!==p)),d?.id===p&&(v(null),S([]))},[d,s]),tt=n.useCallback(async p=>{d?.id===p&&c.current&&(c.current.close(),c.current=null),await sn(p,s),i(y=>y.filter(C=>C.id!==p)),d?.id===p&&(v(null),S([]))},[d,s]),we=n.useCallback(async()=>{!d||!z||await ae(d.id,{offset:D.length})},[d,z,ae,D.length]),Se=n.useCallback(()=>{d&&(m.current=!0,k.current?.(),k.current=null,c.current?.close(),c.current=null,nn(d.id,s).catch(()=>{}),g(!1),R(""),b(""),I([]))},[d,s]),Be=n.useCallback(()=>{x.current="",E("")},[]),Ne=n.useRef(()=>{}),Ce=an(),ke=n.useCallback((p,y)=>{if(!d)return;if(se.current){x.current=p,E(p);return}m.current=!1,c.current&&(c.current.close(),c.current=null);const C=`temp-${Date.now()}`,P={id:C,sessionId:d.id,role:"user",content:p,createdAt:new Date().toISOString()};S(G=>[...G,P]),R(""),b(""),I([]),g(!0);const{handlers:te}=ms({sessionId:d.id,tempUserMessageId:C,setStreamingText:R,setStreamingThinking:b,setStreamingToolCalls:I,cancelStreamingFlushesRef:k,addToast:r,onFallbackSession:(G,Z)=>{const L=ys(G.fallbackModel);i(X=>X.map(F=>F.id===Z?{...F,...L}:F)),v(X=>X&&X.id===Z?{...X,...L}:X)},onDone:({messageId:G,message:Z,accumulated:L})=>{const X=Z?_t(Z):{id:G||`msg-${Date.now()}`,sessionId:d.id,role:"assistant",content:L.text,thinkingOutput:L.thinking,toolCalls:L.toolCalls.length>0?L.toolCalls:void 0,fallbackInfo:L.fallbackInfo,createdAt:new Date().toISOString()};xe.current.add(X.id),S(H=>[...H,X]),R(""),b(""),I([]),g(!1),se.current=!1,c.current=null,setTimeout(()=>{xe.current.delete(X.id)},1e3),re();const F=x.current.trim();F&&(x.current="",E(""),Ne.current(F))},onError:(G,Z)=>{const L=ws(G),X=typeof G=="string"&&on(G)&&(Ce.isHiddenNow()||Ce.wasRecentlyHidden(5e3));if(S(F=>{const H=F.filter(B=>B.id!==Z);return X?H:[...H,{id:`error-${Date.now()}`,sessionId:d.id,role:"assistant",content:L.summary,failureInfo:L,createdAt:new Date().toISOString()}]}),R(""),b(""),I([]),g(!1),se.current=!1,c.current=null,console.error("[useChat] Stream error:",G),X?(console.info("[useChat] Suppressed tab-suspension stream error:",G),d?.id&&(d.isGenerating?he(d.id,d.inFlightGeneration):ae(d.id))):(r?.(L.summary,"error"),re()),!m.current){const F=x.current.trim();F&&(x.current="",E(""),Ne.current(F))}}});c.current=rn(d.id,p,te,y,s)},[d,s,re,r,ae,he,Ce]);Ne.current=ke;const je=V?l.filter(p=>p.title?.toLowerCase().includes(V.toLowerCase())||p.agentId.toLowerCase().includes(V.toLowerCase())):l;return n.useEffect(()=>{if(!O.current?.isGenerating||(c.current||he(O.current.id,O.current.inFlightGeneration),!se.current||c.current||!O.current))return;const p=setInterval(async()=>{if(!se.current||c.current||!O.current){clearInterval(p);return}try{(await us(s)).sessions.find(P=>P.id===O.current?.id)?.isGenerating||(clearInterval(p),await ae(O.current.id),R(""),b(""),I([]),g(!1))}catch{}},3e3);return()=>clearInterval(p)},[he,ae,s,d]),n.useEffect(()=>{const p=ue.current,y=s?`?projectId=${encodeURIComponent(s)}`:"",C=()=>ue.current!==p,P=F=>{if(C())return;const H=JSON.parse(F.data);i(B=>B.some(J=>J.id===H.id)?B:[H,...B])},te=F=>{if(C())return;const H=JSON.parse(F.data);i(B=>[...B.map(ce=>ce.id===H.id?H:ce)]),O.current?.id===H.id&&(v(H),H.isGenerating&&!c.current&&he(H.id,H.inFlightGeneration))},G=F=>{if(C())return;const{id:H}=JSON.parse(F.data);i(B=>B.filter(J=>J.id!==H)),O.current?.id===H&&(v(null),S([]))},Z=F=>{if(C())return;const H=JSON.parse(F.data),B=_t(H);if(!xe.current.has(B.id)){if(O.current?.id===B.sessionId&&se.current&&!c.current&&B.role==="assistant"){S(J=>J.some(ce=>ce.id===B.id)?J:[...J,B]),R(""),b(""),I([]),g(!1);return}O.current?.id===B.sessionId&&!se.current&&S(J=>{if(J.some(ce=>ce.id===B.id))return J;if(B.role==="user"){const ce=J.findIndex(fe=>fe.role==="user"&&fe.id.startsWith("temp-")&&fe.content.trim()===B.content.trim());if(ce>=0){const fe=[...J];return fe[ce]=B,fe}}return[...J,B]})}},L=F=>{if(C())return;const{id:H}=JSON.parse(F.data);S(B=>B.filter(J=>J.id!==H))};return Rs(`/api/events${y}`,{events:{"chat:session:created":P,"chat:session:updated":te,"chat:session:deleted":G,"chat:message:added":Z,"chat:message:deleted":L}})},[he,s]),n.useEffect(()=>()=>{c.current&&(c.current.close(),c.current=null)},[]),{sessions:l,activeSession:d,sessionsLoading:M,messages:D,messagesLoading:Y,isStreaming:_,streamingText:ee,streamingThinking:U,streamingToolCalls:j,pendingMessage:A,selectSession:ye,createSession:et,archiveSession:gt,deleteSession:tt,sendMessage:ke,stopStreaming:Se,clearPendingMessage:Be,loadMoreMessages:we,hasMoreMessages:z,searchQuery:V,setSearchQuery:q,filteredSessions:je,refreshSessions:re,agentsMap:f}}const Ae="fusion:chat-active-room";function Bt(s){return[...s].sort((r,l)=>new Date(l.updatedAt).getTime()-new Date(r.updatedAt).getTime())}function Ye(s,r){const l=s.findIndex(d=>d.id===r.id);if(l===-1)return Bt([r,...s]);const i=[...s];return i[l]=r,Bt(i)}function Ee(s){try{return JSON.parse(s.data)}catch{return null}}function _n(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 zn(s,r){const[l,i]=n.useState([]),[d,v]=n.useState(!0),[M,T]=n.useState(null),[D,S]=n.useState(null),[Y,w]=n.useState([]),[_,g]=n.useState([]),[ee,R]=n.useState(!1),U=n.useRef(l),b=n.useRef(D),j=n.useRef(0),I=n.useRef(s);U.current=l,b.current=D,I.current!==s&&(I.current=s,j.current+=1);const A=n.useCallback(async(f,o=!0)=>{if(!f){w([]),g([]),R(!1);return}o&&g([]),R(!0);try{const[c,m]=await Promise.all([cn(f.id,s),Pt(f.id,{limit:100},s)]);w(c.members),g(m.messages)}catch{w([]),g([])}finally{R(!1)}},[s]),E=n.useCallback(async()=>{v(!0);try{const f=await ln({},s),o=Bt(f.rooms);i(o),T(null);const c=Ms(Ae,s);if(c){const m=o.find(x=>x.id===c)??null;m?(S(m),A(m,!0)):Oe(Ae,s)}}catch(f){const o=f instanceof Error?f.message:"Failed to load chat rooms";T(o),r?.(o,"error")}finally{v(!1)}},[r,A,s]),V=n.useCallback(f=>{if(!f){S(null),Oe(Ae,s),A(null,!0);return}const o=U.current.find(c=>c.id===f)??null;S(o),o&&(Ht(Ae,o.id,s),A(o,!0))},[A,s]),q=n.useCallback(async f=>{const c=(await dn({name:f.name,memberAgentIds:f.memberAgentIds},s)).room;return i(m=>Ye(m,c)),S(c),Ht(Ae,c.id,s),await A(c,!0),c},[A,s]),z=n.useCallback(async f=>{await un(f,s),i(o=>o.filter(c=>c.id!==f)),b.current?.id===f&&(S(null),w([]),g([]),Oe(Ae,s))},[s]),h=n.useCallback(async(f,o)=>{const c=b.current,m=c?.id;if(!m)throw new Error("Select a room before sending a message");const x=_n(m,f);b.current?.id===m&&g(k=>[...k,x]);try{const k=await mn(m,{content:f,...o?.attachments?{attachments:o.attachments}:{}},s);k.message?.createdAt&&c&&i(O=>Ye(O,{...c,updatedAt:k.message.createdAt})),b.current?.id===m&&g(O=>O.map(se=>se.id===x.id?k.message:se));const Q=await Pt(m,{limit:100},s);if(b.current?.id!==m)return;g(Q.messages)}catch(k){try{const Q=await Pt(m,{limit:100},s);b.current?.id===m&&g(Q.messages)}catch{b.current?.id===m&&g(Q=>Q.filter(O=>O.id!==x.id))}throw k}},[s]);return n.useEffect(()=>{E()},[E]),n.useEffect(()=>{const f=j.current,o=s?`/api/events?projectId=${encodeURIComponent(s)}`:"/api/events";return Rs(o,{onReconnect:()=>{E()},events:{"chat:room:created":c=>{if(j.current!==f)return;const m=Ee(c);m&&i(x=>Ye(x,m))},"chat:room:updated":c=>{if(j.current!==f)return;const m=Ee(c);m&&(i(x=>Ye(x,m)),b.current?.id===m.id&&S(m))},"chat:room:deleted":c=>{if(j.current!==f)return;const m=Ee(c);m?.id&&(i(x=>x.filter(k=>k.id!==m.id)),b.current?.id===m.id&&(S(null),w([]),g([]),Oe(Ae,s)))},"chat:room:member:added":c=>{if(j.current!==f)return;const m=Ee(c);!m||b.current?.id!==m.roomId||w(x=>x.some(k=>k.agentId===m.agentId)?x:[...x,m])},"chat:room:member:removed":c=>{if(j.current!==f)return;const m=Ee(c);!m||b.current?.id!==m.roomId||w(x=>x.filter(k=>k.agentId!==m.agentId))},"chat:room:message:added":c=>{if(j.current!==f)return;const m=Ee(c);m&&(i(x=>{const k=x.find(Q=>Q.id===m.roomId);return k?Ye(x,{...k,updatedAt:m.createdAt}):x}),b.current?.id===m.roomId&&g(x=>{if(x.some(k=>k.id===m.id))return x;if(m.role==="user"){const k=x.findIndex(Q=>Q.role==="user"&&Q.id.startsWith("temp-")&&Q.content.trim()===m.content.trim());if(k>=0){const Q=[...x];return Q[k]=m,Q}}return[...x,m]}))},"chat:room:message:updated":c=>{if(j.current!==f)return;const m=Ee(c);!m||b.current?.id!==m.roomId||g(x=>x.map(k=>k.id===m.id?m:k))},"chat:room:message:deleted":c=>{if(j.current!==f)return;const m=Ee(c);m?.id&&g(x=>x.filter(k=>k.id!==m.id))}}})},[s,E]),n.useEffect(()=>{D&&(l.some(f=>f.id===D.id)||(S(null),w([]),g([]),Oe(Ae,s)))},[D,s,l]),{rooms:l,roomsLoading:d,roomsError:M,activeRoom:D,activeRoomMembers:Y,messages:_,messagesLoading:ee,selectRoom:V,createRoom:q,deleteRoom:z,sendRoomMessage:h,refreshRooms:E}}function Un(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(d=>d.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 On({isOpen:s,onClose:r,onCreate:l,projectId:i,existingRoomNames:d=[]}){const[v,M]=n.useState(""),[T,D]=n.useState([]),[S,Y]=n.useState(""),[w,_]=n.useState([]),[g,ee]=n.useState(!1),[R,U]=n.useState(null),[b,j]=n.useState(!1),I=n.useRef(null),A=n.useRef(null);n.useEffect(()=>{s&&(A.current=document.activeElement instanceof HTMLElement?document.activeElement:null,ee(!0),U(null),ft(void 0,i).then(o=>D(o)).catch(()=>{D([]),U("Failed to load agents.")}).finally(()=>ee(!1)))},[s,i]),n.useEffect(()=>{if(!s){M(""),Y(""),_([]),U(null),j(!1);return}const o=window.requestAnimationFrame(()=>I.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||A.current?.focus()},[s]);const E=n.useMemo(()=>Un(v,d),[v,d]),V=n.useMemo(()=>{const o=S.trim().toLowerCase();return o?T.filter(c=>c.name.toLowerCase().includes(o)):T},[T,S]),q=n.useMemo(()=>T.filter(o=>w.includes(o.id)),[T,w]),z=E.ok&&w.length>0&&!b&&!g;if(!s)return null;const h=o=>{b||_(c=>c.includes(o)?c.filter(m=>m!==o):[...c,o])},f=async()=>{if(!E.ok){U(E.error);return}if(w.length===0){U("Select at least one member.");return}U(null),j(!0);try{await l({name:E.name,displayName:`#${E.name}`,memberAgentIds:w}),r()}catch(o){U(o instanceof Error?o.message:"Failed to create room.")}finally{j(!1)}};return Js.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:I,id:"create-room-name",className:"input",value:v,disabled:b,onChange:o=>{const c=o.target.value.replace(/^#/,"").replace(/\s+/g,"-").toLowerCase();M(c)}})]}),!E.ok&&t.jsx("div",{className:"form-error",children:E.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:S,disabled:b,onChange:o=>Y(o.target.value)})]}),q.length>0&&t.jsx("div",{className:"create-room-modal-selected","data-testid":"create-room-selected-chips",children:q.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..."}):V.length===0?t.jsx("div",{className:"create-room-modal-empty",children:T.length===0?"No agents in this project yet.":"No agents match your search."}):V.map(o=>{const c=w.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(As,{agent:o,size:20}),t.jsx("span",{children:o.name}),t.jsx("span",{className:"create-room-modal-member-role",children:o.role})]},o.id)})}),R&&t.jsx("div",{className:"form-group",children:t.jsx("div",{className:"form-error",children:R})}),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 f(),disabled:!z,children:b?"Creating...":"Create room"})]})]})}),document.body)}const Hn=320;function zt(s){return Math.min(s,Hn)}function Ds(s){const r=new Date(s),i=new Date().getTime()-r.getTime(),d=Math.floor(i/1e3),v=Math.floor(d/60),M=Math.floor(v/60),T=Math.floor(M/24);return d<60?"just now":v<60?`${v}m ago`:M<24?`${M}h ago`:T<7?`${T}d ago`:r.toLocaleDateString()}function Ss(s,r){if(!s||!r)return null;const l=r.toLowerCase();if(l.includes("claude")){let d=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 d=d.replace(/\s+/g," "),d.length>30?d.slice(0,30)+"…":d}if(l.includes("gpt")||l.includes("openai")){const d=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 d.length>30?d.slice(0,30)+"…":d}if(l.includes("gemini")){const d=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 d.length>30?d.slice(0,30)+"…":d}const i=r.replace(/-/g," ").replace(/^\w/,d=>d.toUpperCase()).replace(/\s+/g," ").trim();return i.length>30?i.slice(0,30)+"…":i}function mt(s,r){return s.length<=r?s:`${s.slice(0,r)}…`}function Bn(s){if(!s)return null;const r=Object.entries(s);return r.length===0?null:r.map(([l,i])=>{const d=typeof i=="string"?i:(()=>{try{return JSON.stringify(i)}catch{return String(i)}})();return`${l}=${mt(d,50)}`}).join(", ")}function Kn(s){if(s===void 0)return null;if(typeof s=="string")return mt(s,200);try{return mt(JSON.stringify(s),200)}catch{return mt(String(s),200)}}function Wn(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 Gn(s){if(!s)return null;const r=s.label??`${s.kind} ${s.id}`,l=Wn(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 Is(s){if(!s||s.length===0)return null;const r=(w,_)=>{const g=w.status==="running",ee=w.status==="completed"&&w.isError,R=Bn(w.args),U=Kn(w.result),b=g?R:U?`result: ${U}`:R?`args: ${R}`:null,j=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:w.toolName,children:w.toolName}),b&&t.jsx("span",{className:"chat-tool-call-preview",title:b,children:b}),t.jsx("span",{className:"chat-tool-call-status-text",children:j})]}),t.jsxs("div",{className:"chat-tool-call-content",children:[R&&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:R})]}),U&&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:U})]})]})]},`${w.toolName}-${_}`)},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(vs,{size:12,"aria-hidden":"true"}),t.jsx("span",{children:"Tool calls"})]}),r(s[0],0)]});const i=s.filter(w=>w.status==="running").length,d=s.filter(w=>w.status==="completed"&&w.isError).length,v=i>0,M=Array.from(new Set(s.map(w=>w.toolName))),T=M.slice(0,5),D=Math.max(0,M.length-T.length),S=D>0?`${T.join(", ")}, +${D} more`:T.join(", "),Y=v?`(${i} running)`:d>0?`(${d} ${d===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:v,children:[t.jsxs("summary",{className:"chat-tool-calls-group-summary",children:[t.jsx(vs,{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:S,children:S}),Y&&t.jsx("span",{className:"chat-tool-calls-group-status",children:Y})]}),s.map((w,_)=>r(w,_))]})})}const $s={p:({children:s,...r})=>t.jsx("p",{...r,children:bs(s)}),li:({children:s,...r})=>t.jsx("li",{...r,children:bs(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:Ys.Children.toArray(s).join(""),i=ht(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})},He="__fn_agent__",Vn=280,dt=180,ut=500,Ns="fusion:chat-sidebar-width",Ut="fusion:chat-scope",qn="fusion:chat-draft:";function Cs(s,r){return r?`${qn}${s}:${r}`:null}function ks(s){if(!s)return"";try{return localStorage.getItem(s)??""}catch{return""}}const Xn=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function js(s){const r=/(^|[\s])\/([^\s]*)$/.exec(s);if(!r)return null;const l=r[1]??"",i=r[2]??"",d=r.index+l.length;return{filter:i,start:d,end:s.length}}function Jn(s,r){const l=s.slice(0,r),i=/(^|[\s\n])@([\w-]*)$/.exec(l);if(!i)return null;const d=i[2]??"",v=l.length-d.length-1;return{filter:d,start:v,end:r}}function Yn({projectId:s,onClose:r,onCreate:l}){const[i,d]=n.useState("agent"),[v,M]=n.useState([]),[T,D]=n.useState(!0),[S,Y]=n.useState(""),[w,_]=n.useState([]),[g,ee]=n.useState(!0),[R,U]=n.useState(""),[b,j]=n.useState([]),[I,A]=n.useState([]);n.useEffect(()=>{let h=!1;return D(!0),ft(void 0,s).then(f=>{h||M(f)}).catch(()=>{h||M([])}).finally(()=>{h||D(!1)}),()=>{h=!0}},[s]),n.useEffect(()=>{ee(!0),Dn().then(h=>{_(h.models),j(h.favoriteProviders),A(h.favoriteModels)}).catch(()=>{_([]),j([]),A([])}).finally(()=>{ee(!1)})},[]);const E=n.useCallback(async h=>{const f=b,c=f.includes(h)?f.filter(m=>m!==h):[h,...f];j(c);try{await xs({favoriteProviders:c,favoriteModels:I})}catch{j(f)}},[b,I]),V=n.useCallback(async h=>{const f=I,c=f.includes(h)?f.filter(m=>m!==h):[h,...f];A(c);try{await xs({favoriteProviders:b,favoriteModels:c})}catch{A(f)}},[I,b]),q=h=>{if(h.preventDefault(),i==="agent"){if(!S)return;l({agentId:S});return}if(!R)return;const f=R.indexOf("/");if(f<=0)return;const o=R.slice(0,f),c=R.slice(f+1);l({agentId:He,modelProvider:o,modelId:c})},z=i==="agent"?!S:!R;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:()=>{d("agent"),U("")},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:()=>{d("model"),Y("")},children:"Model"})]}),t.jsxs("form",{onSubmit:q,children:[i==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",T?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):v.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:v.map(h=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${S===h.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>Y(h.id),"data-testid":`agent-option-${h.id}`,children:[t.jsx(Ze,{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(In,{models:w,value:R,onChange:U,label:"Model",placeholder:"Select a model",favoriteProviders:b,onToggleFavorite:E,favoriteModels:I,onToggleModelFavorite:V})}),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 Ot=n.memo(function({message:r,forcePlain:l,agentName:i,hideAssistantIdentity:d,showAssistantModelTag:v,activeModelTag:M,activeModelProvider:T,activeSessionId:D,mentionAgentsByName:S,roomContext:Y,copyAction:w}){const _=r.role==="assistant",g=_?r.failureInfo:void 0,ee=_&&(!d||!!g),R=n.useMemo(()=>{if(_)return null;const j=r.content,I=/@([\w-]+)/g,A=[];let E=0,V=I.exec(j);for(;V;){const[q,z=""]=V,h=V.index;h>E&&A.push(j.slice(E,h));const f=z.replace(/_/g," ").toLowerCase(),o=S.get(f);if(o){const c=!!(Y&&!Y.memberIds.has(o.id)),m=c?`Not a member of ${Y?.roomName}`:void 0;A.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 A.push(q);E=h+q.length,V=I.exec(j)}return E<j.length&&A.push(j.slice(E)),A.length===0?j:A},[_,r.content,S,Y]),U=n.useMemo(()=>{const j=r.attachments;if(!j||j.length===0||!D)return null;const I=`/api/chat/sessions/${encodeURIComponent(D)}/attachments/`;return t.jsx("div",{className:"chat-message-attachments",children:j.map(A=>{const E=A.mimeType.startsWith("image/"),V=A.id||A.filename,q=`${I}${encodeURIComponent(A.filename)}`;return E?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:q,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:q,alt:A.originalName})},V):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:q,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(An,{size:14}),t.jsx("span",{children:A.originalName})]},V)})})},[r.attachments,D]),b=n.useMemo(()=>_?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(En,{size:14,"aria-hidden":"true"}),t.jsx("span",{children:"Failure details"})]}),g.detail&&t.jsx("pre",{className:"chat-message-failure-detail",children:ht(g.detail)}),Gn(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(Es,{remarkPlugins:[Ts],components:$s,children:r.content})}):null,[g,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:[T?t.jsx(Qe,{provider:T,size:"sm"}):t.jsx(Ze,{size:14}),t.jsx("span",{children:i}),v&&M&&t.jsx("span",{className:"chat-model-tag",children:M})]}),_?b:t.jsx("div",{className:"chat-message-content",children:R}),!g&&w,Is(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:ht(r.thinkingOutput)})]}),U,t.jsx("div",{className:"chat-message-time",children:Ds(r.createdAt)})]})});function sa({projectId:s,addToast:r,experimentalFeatures:l}){const{activeSession:i,sessionsLoading:d,messages:v,messagesLoading:M,isStreaming:T,streamingText:D,streamingThinking:S,streamingToolCalls:Y,selectSession:w,createSession:_,archiveSession:g,deleteSession:ee,sendMessage:R,stopStreaming:U,pendingMessage:b,clearPendingMessage:j,searchQuery:I,setSearchQuery:A,filteredSessions:E}=Fn(s,r),[V,q]=n.useState(!1),z=l?.chatRooms===!0,[h,f]=n.useState(()=>{try{if(localStorage.getItem(Ut)==="rooms"&&z)return"rooms"}catch{}return"direct"}),o=zn(s,r),[c,m]=n.useState(()=>{const e=Cs(h,h==="rooms"?o.activeRoom?.id:i?.id);return ks(e)}),[x,k]=n.useState(null),[Q,O]=n.useState(null),[se,xe]=n.useState(null),[ue,me]=n.useState(!0),[re,$e]=n.useState(Vn),[Te,ae]=n.useState(!1),[oe,he]=n.useState(new Map),[ye,et]=n.useState([]),[gt,tt]=n.useState(!0),[we,Se]=n.useState(!1),[Be,Ne]=n.useState(""),[Ce,ke]=n.useState(0),[je,p]=n.useState(""),[y,C]=n.useState(!1),[P,te]=n.useState(0),[G,Z]=n.useState(-1),[L,X]=n.useState(!1),[F,H]=n.useState([]),[B,J]=n.useState(!1),[ce,fe]=n.useState(!1),[Pe,Kt]=n.useState({}),[st,Le]=n.useState(!1),{pushNav:Wt}=hn(),[,Ke]=n.useState(!1),[Ps,Ls]=n.useState({top:0,left:0}),K=fn({projectId:s}),pt=n.useCallback(e=>{if(!e||!K.mentionActive)return;const a=e.getBoundingClientRect();Ls({top:a.top-260,left:a.left+8})},[K.mentionActive]),Gt=n.useRef(null),Vt=n.useRef(null),bt=n.useRef(!1),vt=n.useRef(null),ge=n.useRef(null),De=n.useRef(null),ne=n.useRef(null),qt=n.useRef(null),Xt=n.useRef([]),We=n.useRef(0),Ge=n.useRef(new Map),$=gn()==="mobile";n.useEffect(()=>{try{const e=localStorage.getItem(Ns);if(!e)return;const a=Number.parseInt(e,10);if(Number.isNaN(a))return;const u=Math.max(dt,Math.min(ut,a));$e(u)}catch{}},[]),n.useEffect(()=>{try{const e=localStorage.getItem(Ut);if(e==="direct"){f("direct");return}e==="rooms"&&z&&f("rooms")}catch{}},[z]),n.useEffect(()=>{if(!z&&h==="rooms"){f("direct");return}try{localStorage.setItem(Ut,h)}catch{}},[z,h]);const ie=Cs(h,h==="rooms"?o.activeRoom?.id:i?.id),xt=n.useRef(ie);n.useEffect(()=>{ie!==xt.current&&(xt.current=ie,m(ks(ie)))},[ie]),n.useEffect(()=>{if(!(!ie||xt.current!==ie))try{if(c){localStorage.setItem(ie,c);return}localStorage.removeItem(ie)}catch{}},[ie,c]);const pe=z&&h==="rooms"&&!!o.activeRoom,{keyboardOverlap:nt,viewportHeight:Jt,viewportOffsetTop:Yt,keyboardOpen:Ve}=pn({enabled:$&&(!!i||pe)}),Qt=nt>0||Yt>0,Zt=Ve&&Qt?{"--keyboard-overlap":`${nt}px`,"--vv-offset-top":`${Yt}px`,...Jt!==null?{"--vv-height":`${Jt}px`}:{}}:{},es=`chat-thread${Ve&&Qt?" chat-thread--keyboard-active":""}`,le=n.useMemo(()=>{const e=Be.trim().toLowerCase();return(e?ye.filter(u=>u.name.toLowerCase().includes(e)):ye).slice(0,10)},[ye,Be]),Fe=n.useMemo(()=>Array.from(oe.values()),[oe]),be=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]),Ie=n.useMemo(()=>{const e=Fe.filter(N=>bn(N.name,je));if(!be)return e;const a=e.filter(N=>be.memberIds.has(N.id));if(je.trim().length===0)return a;const u=e.filter(N=>!be.memberIds.has(N.id));return[...a,...u]},[Fe,je,be]),yt=n.useMemo(()=>{const e=new Map;for(const a of Fe)e.set(a.name.toLowerCase(),a);return e},[Fe]);n.useEffect(()=>{ke(0)},[le]),n.useEffect(()=>{te(0)},[je,y]),n.useEffect(()=>()=>{ge.current!==null&&window.clearTimeout(ge.current)},[]);const ts=n.useCallback(()=>{const e=De.current;if(!e)return;const u=e.scrollTop+e.clientHeight>=e.scrollHeight-50;fe(!u),bt.current=!u},[]),_e=n.useCallback(e=>{if(!e.isConnected)return;let a=0,u=0,N=-1;const W=6,de=()=>{if(e.isConnected){if(e.scrollTop=e.scrollHeight,e.scrollHeight===N?u+=1:(u=0,N=e.scrollHeight),a+=1,a>=W||u>=2){fe(!1),bt.current=!1;return}window.requestAnimationFrame(de)}};de()},[]),qe=n.useCallback(()=>{const e=De.current;e&&_e(e)},[_e]);n.useLayoutEffect(()=>{const e=pe?o.activeRoom?.id??null:i?.id??null;if(!e){vt.current=null;return}const a={threadId:e,loaded:pe?!o.messagesLoading:!M,hasMessages:pe?o.messages.length>0:v.length>0},u=vt.current,N=u?.threadId!==e,W=u?.threadId===e&&!u.loaded&&a.loaded,de=u?.threadId===e&&!u.hasMessages&&a.hasMessages;if(!(u===null||N||W||de))return;const ve=De.current;ve&&(_e(ve),vt.current=a)},[pe,o.activeRoom?.id,o.messages.length,o.messagesLoading,i?.id,v.length,M,_e]);const Fs=pe?o.messages:v;n.useEffect(()=>{bt.current||qe()},[Fs,D,S,T,qe]),n.useEffect(()=>{nt<=0||!De.current||qe()},[nt,qe]),vn($&&Ve),n.useEffect(()=>{const e=()=>k(null);if(x)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[x]),n.useEffect(()=>{if(!$||!Ve)return;const e=a=>{a.target?.closest(".chat-messages")||a.preventDefault()};return document.addEventListener("touchmove",e,{passive:!1}),()=>{document.removeEventListener("touchmove",e)}},[$,Ve]),n.useEffect(()=>{if(!$||!i)return;const e=()=>{const a=ne.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]),n.useEffect(()=>{if(!$||!i&&!pe)return;const e=()=>{const u=De.current;u&&_e(u)},a=()=>{document.visibilityState==="visible"&&e()};return document.addEventListener("visibilitychange",a),window.addEventListener("pageshow",e),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("pageshow",e)}},[$,i,pe,_e]),n.useEffect(()=>{let e=!1;const a=s;return ft(void 0,s).then(u=>{if(e||a!==s)return;const N=new Map;for(const W of u)N.set(W.id,W);he(N)}).catch(()=>{}),()=>{e=!0}},[s]),n.useEffect(()=>{let e=!1;return tt(!0),xn(s).then(a=>{e||et(a)}).catch(()=>{e||et([])}).finally(()=>{e||tt(!1)}),()=>{e=!0}},[s]),n.useEffect(()=>{Xt.current=F},[F]),n.useEffect(()=>()=>{for(const e of Xt.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);for(const e of Ge.current.values())window.clearTimeout(e);Ge.current.clear()},[]);const at=n.useCallback(e=>{if(!e||e.length===0)return;const a=[];for(const u of Array.from(e)){if(!Xn.includes(u.type))continue;const N=u.type.startsWith("image/");a.push({file:u,previewUrl:N?URL.createObjectURL(u):""})}a.length>0&&H(u=>[...u,...a])},[]),_s=n.useCallback(e=>{H(a=>{const u=a[e];return u?.previewUrl&&URL.revokeObjectURL(u.previewUrl),a.filter((N,W)=>W!==e)})},[]),zs=n.useCallback(e=>{const a=e.clipboardData?.files;if(!a||a.length===0)return;const u=Array.from(a).filter(N=>N.type.startsWith("image/"));u.length!==0&&at(u)},[at]),Us=n.useCallback(async e=>{try{await _(e),q(!1),$&&me(!1)}catch{r("Failed to create chat session","error")}},[_,r,$]),Xe=n.useCallback(()=>{if(m(""),ie)try{localStorage.removeItem(ie)}catch{}Se(!1),Ne(""),C(!1),p(""),Z(-1),H(e=>{for(const a of e)a.previewUrl&&URL.revokeObjectURL(a.previewUrl);return[]})},[ie]),wt=n.useCallback(()=>{const e=c.trim(),a=F.map(u=>u.file);if(!(!e&&a.length===0||!i)){if(e==="/clear"||e==="/new"){Xe(),U(),j(),_({agentId:i.agentId,modelProvider:i.modelProvider??void 0,modelId:i.modelId??void 0}).catch(()=>{r("Failed to clear conversation","error")});return}Xe(),R(e,a)}},[c,F,i,Xe,U,j,_,r,R]),St=n.useCallback(async()=>{const e=c.trim();if(e){if(z&&h==="rooms"){if(!o.activeRoom)return;const a=c;Xe();try{await o.sendRoomMessage(e)}catch(u){m(a);const N=u instanceof Error&&u.message.trim()?u.message:"Failed to send room message";r(N,"error")}return}wt()}},[c,z,h,o,Xe,r,wt]),Nt=n.useCallback(e=>{m(a=>{const u=js(a);if(!u)return a;const N=`/skill:${e.name} `,W=a.slice(0,u.start)+N+a.slice(u.end);return window.requestAnimationFrame(()=>{ne.current&&(ne.current.style.height="auto",ne.current.style.height=`${zt(ne.current.scrollHeight)}px`,ne.current.focus())}),W}),Se(!1),Ne(""),ke(0)},[]),rt=n.useCallback(e=>{const a=ne.current;if(!a||G<0)return;const u=a.selectionStart??We.current,N=a.selectionEnd??u,W=Math.max(u,N),de=Math.min(G,W),ve=`${`@${e.name.replace(/\s+/g,"_")}`} `,$t=c.slice(0,de)+ve+c.slice(W),Ue=de+ve.length;m($t),C(!1),p(""),te(0),Z(-1),window.requestAnimationFrame(()=>{ne.current&&(ne.current.style.height="auto",ne.current.style.height=`${zt(ne.current.scrollHeight)}px`,ne.current.focus(),ne.current.setSelectionRange(Ue,Ue))})},[G,c]),ss=n.useCallback(e=>{if(We.current=e.currentTarget.selectionStart??We.current,K.mentionActive&&K.files.length>0){if(K.handleKeyDown(e,c),e.key==="Enter"||e.key==="Tab"){const a=K.files[K.selectedIndex];if(a){const u=K.selectFile(a,c);m(u),K.dismissMention(),Ke(!1)}}return}if(y&&e.key==="ArrowDown"){e.preventDefault(),Ie.length>0&&te(a=>(a+1)%Ie.length);return}if(y&&e.key==="ArrowUp"){e.preventDefault(),Ie.length>0&&te(a=>a===0?Ie.length-1:a-1);return}if(y&&e.key==="Enter"){e.preventDefault();const a=Ie[P]??Ie[0];a&&rt(a);return}if(y&&e.key==="Escape"){e.preventDefault(),C(!1),p(""),Z(-1);return}if(we&&e.key==="ArrowDown"){e.preventDefault(),le.length>0&&ke(a=>(a+1)%le.length);return}if(we&&e.key==="ArrowUp"){e.preventDefault(),le.length>0&&ke(a=>a===0?le.length-1:a-1);return}if(we&&(e.key==="Enter"||e.key==="Tab")&&le.length>0){e.preventDefault();const a=le[Ce]??le[0];a&&Nt(a);return}if(we&&e.key==="Escape"){e.preventDefault(),Se(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),St())},[y,Ie,P,rt,we,le,Ce,Nt,St,K,c]),it=n.useCallback((e,a)=>{const u=Jn(e,a);if(u){C(!0),p(u.filter),Z(u.start);return}C(!1),p(""),Z(-1)},[]),ns=n.useCallback(e=>{const a=e.target,u=a.value,N=a.selectionStart??u.length;We.current=N,m(u);const W=js(u);W?(Se(!0),Ne(W.filter)):(Se(!1),Ne("")),it(u,N),K.detectMention(u,N),Ke(K.mentionActive),K.mentionActive&&pt(a),a.style.height="auto",a.style.height=`${zt(a.scrollHeight)}px`},[it]),ot=n.useCallback(e=>{const a=e.currentTarget,u=a.selectionStart??a.value.length;We.current=u,it(a.value,u),K.detectMention(a.value,u),Ke(K.mentionActive),K.mentionActive&&pt(a)},[it,K,pt]),as=n.useCallback(e=>{e.key!=="Escape"&&ot(e)},[ot]),rs=n.useCallback(()=>{ge.current!==null&&window.clearTimeout(ge.current),ge.current=window.setTimeout(()=>{Se(!1),C(!1),p(""),Z(-1),Ke(!1),K.dismissMention(),ge.current=null},120)},[K]),is=n.useCallback(()=>{ge.current!==null&&(window.clearTimeout(ge.current),ge.current=null),typeof window<"u"&&window.innerWidth<=768&&window.setTimeout(()=>{(window.scrollY!==0||window.scrollX!==0)&&window.scrollTo(0,0)},0)},[]),Os=n.useCallback(async e=>{k(null);try{await g(e),r("Conversation archived","success")}catch{r("Failed to archive conversation","error")}},[g,r]),Hs=n.useCallback(async e=>{O(null),k(null);try{await ee(e),r("Conversation deleted","success")}catch{r("Failed to delete conversation","error")}},[ee,r]),Je=n.useCallback(e=>{try{localStorage.setItem(Ns,String(e))}catch{}},[]),Bs=n.useCallback(e=>{if($)return;e.preventDefault(),e.stopPropagation();const a=e.currentTarget;typeof a.setPointerCapture=="function"&&a.setPointerCapture(e.pointerId);const u=e.clientX,N=re;let W=N;document.body.style.userSelect="none";const de=ve=>{const $t=ve.clientX-u,Ue=Math.max(dt,Math.min(ut,N+$t));W=Ue,$e(Ue),Je(Ue)},ze=ve=>{typeof a.releasePointerCapture=="function"&&a.releasePointerCapture(ve.pointerId),document.body.style.userSelect="",document.removeEventListener("pointermove",de),document.removeEventListener("pointerup",ze),Je(W)};document.addEventListener("pointermove",de),document.addEventListener("pointerup",ze)},[$,Je,re]),Ks=n.useCallback(e=>{if($||e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;e.preventDefault();const a=e.shiftKey?50:10,u=e.key==="ArrowLeft"?-a:a,N=Math.max(dt,Math.min(ut,re+u));$e(N),Je(N)},[$,Je,re]),os=n.useCallback(e=>{w(e),Le(!1),$&&me(!1)},[w,$]),Ct=n.useCallback(()=>{w(""),me(!0),Le(!1)},[w]),kt=n.useCallback(()=>{o.selectRoom(null),me(!0),Le(!1)},[o]),Ws=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(Tn,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>q(!0),children:[t.jsx(lt,{size:16}),"New Chat"]})]}),Me=Ss(i?.modelProvider,i?.modelId),Re=i?.modelProvider??null,jt=!!(i||T||v.length>0),ct=h==="rooms"?pe:!!i,cs=n.useRef(ct);n.useEffect(()=>{const e=cs.current;cs.current=ct,$&&(e||!ct||Wt({type:"view",revert:h==="rooms"?kt:Ct}))},[h,Ct,kt,ct,$,Wt]);const Mt=i?.agentId===He?Me??"Fusion":i?.title||oe.get(i?.agentId??"")?.name||i?.agentId||"Chat",ls=!!(Me&&Me!==Mt),Gs=$&&h==="direct"&&!!i,Rt=oe.get(i?.agentId??"")?.name||(i?.agentId===He?Me??"Fusion":i?.agentId?.slice(0,30)??"Fusion"),At=!1,Et=i?.agentId===He,Vs=b.length>50?`${b.slice(0,50)}…`:b,qs=n.useCallback(()=>{X(e=>!e)},[]);n.useEffect(()=>{if(!st)return;const e=a=>{Vt.current?.contains(a.target)||Le(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[st]),n.useEffect(()=>{(!$||h!=="direct"||ue)&&Le(!1)},[$,h,ue]);const Tt=n.useCallback((e,a)=>{const u=Ge.current.get(e);u&&window.clearTimeout(u),Kt(W=>({...W,[e]:a}));const N=window.setTimeout(()=>{Kt(W=>{const{[e]:de,...ze}=W;return ze}),Ge.current.delete(e)},2e3);Ge.current.set(e,N)},[]),ds=n.useCallback(async(e,a)=>{try{if(!navigator.clipboard?.writeText)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(a),Tt(e,"success")}catch{Tt(e,"error")}},[Tt]),Xs=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(Es,{remarkPlugins:[Ts],components:$s,children:e})}),[]),Dt=i?.agentId===He,It=n.useCallback((e,a,u)=>t.jsx("button",{type:"button",className:`btn-icon chat-message-copy-action${Pe[e]==="success"?" chat-message-copy-action--success":""}${Pe[e]==="error"?" chat-message-copy-action--error":""}`,"data-testid":u??`chat-copy-response-${e}`,"aria-label":Pe[e]==="success"?"Response copied":Pe[e]==="error"?"Copy failed":"Copy response",onClick:()=>{ds(e,a)},children:Pe[e]==="success"?t.jsx(yn,{size:14}):t.jsx(wn,{size:14})}),[Pe,ds]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${ue?"":" chat-sidebar--hidden"}`,style:$?void 0:{width:`${re}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:()=>f("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:()=>f("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(Sn,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:I,onChange:e=>A(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:d?t.jsx("div",{className:"chat-status-copy chat-status-copy--padded",children:"Loading..."}):E.length===0?t.jsx("div",{className:"chat-status-copy chat-status-copy--padded",children:"No conversations yet"}):E.map(e=>t.jsxs("div",{className:`chat-session-item${i?.id===e.id?" chat-session-item--active":""}`,onClick:()=>os(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(),O(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(Lt,{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(Qe,{provider:e.modelProvider,size:"sm"}),t.jsx("span",{children:oe.get(e.agentId)?.name||(e.agentId===He?Ss(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))})]}),t.jsx("span",{children:e.updatedAt?Ds(e.updatedAt):""})]})]},e.id))})]}):t.jsxs("div",{className:"chat-sidebar-rooms","data-testid":"chat-sidebar-rooms",children:[t.jsx("div",{className:"chat-sidebar-rooms-header",children:t.jsxs("button",{type:"button",className:"btn btn-sm btn-primary","data-testid":"chat-create-room-btn",onClick:()=>ae(!0),children:[t.jsx(lt,{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,u=a?o.activeRoomMembers.length:null;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),$&&me(!1)},onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),o.selectRoom(e.id),$&&me(!1))},children:[t.jsxs("span",{className:"chat-room-item-details",children:[t.jsxs("span",{className:"chat-room-item-name",children:["#",e.name]}),u!==null?t.jsxs("span",{className:"chat-room-item-meta",children:[u," ",u===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:N=>{N.stopPropagation(),xe(e.id)},children:t.jsx(Lt,{size:14})})]},e.id)})})]}),t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>q(!0),"data-testid":"chat-new-btn",children:[t.jsx(lt,{size:14}),"New Chat"]})})]}),!$&&ue&&t.jsx("div",{className:"chat-sidebar-resize-handle",role:"separator","aria-orientation":"vertical","aria-valuemin":dt,"aria-valuemax":ut,"aria-valuenow":re,"aria-label":"Resize chat sidebar",tabIndex:0,onPointerDown:Bs,onKeyDown:Ks}),x&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:x.y,left:x.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>Os(x.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Nn,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{k(null),O(x.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(Lt,{size:14}),"Delete"]})]}),Q&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>O(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:()=>O(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void Hs(Q),children:"Delete"})]})]})}),z&&se&&t.jsx("div",{className:"chat-new-dialog-backdrop chat-view-dialog-backdrop",onClick:()=>xe(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:()=>xe(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>{(async()=>{try{await o.deleteRoom(se),xe(null)}catch{r("Failed to delete room","error")}})()},children:"Delete"})]})]})}),z&&h==="rooms"?t.jsxs("div",{className:es,style:Zt,children:[o.activeRoom?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"chat-room-thread-header",children:[$&&t.jsx("button",{className:"btn-icon",onClick:kt,"data-testid":"chat-back-btn",children:t.jsx(hs,{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(As,{agent:oe.get(e.agentId)??{id:e.agentId,name:e.agentId.slice(0,30)}},e.agentId))})]}),t.jsxs("div",{className:"chat-messages",ref:De,onScroll:ts,children:[o.messagesLoading?t.jsx("div",{className:"chat-status-copy",children:"Loading messages..."}):o.messages.length===0?t.jsx("div",{className:"chat-status-copy",children:"No messages yet. Start the conversation!"}):o.messages.map(e=>{const a=e.senderAgentId?oe.get(e.senderAgentId)?.name??e.senderAgentId.slice(0,30):"You",u={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(Ot,{message:u,forcePlain:L,agentName:a,hideAssistantIdentity:!1,showAssistantModelTag:!1,activeModelTag:null,activeModelProvider:null,activeSessionId:o.activeRoom?.id??null,mentionAgentsByName:yt,roomContext:be},e.id)}),t.jsx("div",{ref:Gt})]})]}):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:ne,className:"chat-input-textarea",placeholder:"Type a message...",value:c,onChange:ns,onKeyDown:ss,onKeyUp:as,onClick:ot,onBlur:rs,onFocus:is,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(fs,{agents:Fe,filter:je,highlightedIndex:P,visible:y,onSelect:rt,position:"below",roomMemberIds:be?.memberIds,roomName:be?.roomName})]}),t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{e.pointerType&&e.pointerType!=="mouse"&&e.preventDefault()},onMouseDown:e=>{e.preventDefault()},onClick:()=>{St()},disabled:!c.trim(),"data-testid":"chat-send-btn",style:{touchAction:"manipulation"},children:t.jsx(gs,{size:16})})]})})]}):t.jsxs("div",{className:es,style:Zt,children:[(jt||!$)&&t.jsxs("div",{className:"chat-thread-header",children:[$&&jt&&t.jsx("button",{className:"btn-icon",onClick:Ct,"data-testid":"chat-back-btn",children:t.jsx(hs,{size:16})}),t.jsx("div",{className:"chat-thread-header-identity","data-testid":"chat-thread-header-identity",children:Gs?t.jsxs("div",{className:"chat-mobile-session-menu",ref:Vt,children:[t.jsxs("button",{type:"button",className:"btn chat-mobile-session-trigger","data-testid":"chat-mobile-session-trigger","aria-haspopup":"menu","aria-expanded":st,onClick:()=>Le(e=>!e),children:[Re?t.jsx(Qe,{provider:Re,size:"md"}):t.jsx(Ze,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:Mt}),ls&&t.jsx("span",{className:"chat-model-tag",children:Me}),t.jsx(ps,{size:16,"aria-hidden":"true"})]}),st&&t.jsx("div",{className:"chat-mobile-session-dropdown",role:"menu","data-testid":"chat-mobile-session-dropdown",children:E.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:()=>os(e.id),children:t.jsx("span",{className:"chat-mobile-session-option-title",children:e.title||"Untitled"})},e.id))})]}):t.jsxs(t.Fragment,{children:[Re?t.jsx(Qe,{provider:Re,size:"md"}):t.jsx(Ze,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:Mt}),ls&&t.jsx("span",{className:"chat-model-tag",children:Me})]})}),jt&&t.jsx("button",{type:"button",className:`chat-thread-header-render-toggle${L?" chat-thread-header-render-toggle--plain":""}`,"data-testid":"chat-thread-render-toggle","aria-label":L?"Show all messages as rendered Markdown":"Show all messages as plain text",onClick:qs,children:L?t.jsx(Cn,{size:14}):t.jsx(kn,{size:14})}),!$&&t.jsxs("button",{className:"btn btn-sm btn-primary chat-thread-header-new-chat",onClick:()=>q(!0),"data-testid":"chat-thread-new-chat-btn",children:[t.jsx(lt,{size:14}),"New Chat"]})]}),t.jsxs("div",{className:"chat-messages",ref:De,onScroll:ts,children:[T?t.jsxs(t.Fragment,{children:[v.map(e=>t.jsx(Ot,{message:e,forcePlain:L,agentName:Rt,hideAssistantIdentity:Et,showAssistantModelTag:At,activeModelTag:Me,activeModelProvider:Re,activeSessionId:i?.id??null,mentionAgentsByName:yt,roomContext:null,copyAction:Dt&&e.role==="assistant"?It(e.id,e.content):void 0},e.id)),t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[!Et&&t.jsxs("div",{className:"chat-message-avatar",children:[Re?t.jsx(Qe,{provider:Re,size:"sm"}):t.jsx(Ze,{size:14}),t.jsx("span",{children:Rt}),At]}),D?Xs(D,L):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:S?"Thinking…":"Connecting…"}),Dt&&D&&It("__streaming__",D,"chat-copy-response-streaming"),Is(Y),S&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:ht(S)})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}):M?t.jsx("div",{className:"chat-status-copy",children:"Loading messages..."}):v.length===0&&!i?Ws():v.length===0&&i?t.jsx("div",{className:"chat-status-copy",children:"No messages yet. Start the conversation!"}):t.jsx(t.Fragment,{children:v.map(e=>t.jsx(Ot,{message:e,forcePlain:L,agentName:Rt,hideAssistantIdentity:Et,showAssistantModelTag:At,activeModelTag:Me,activeModelProvider:Re,activeSessionId:i?.id??null,mentionAgentsByName:yt,roomContext:null,copyAction:Dt&&e.role==="assistant"?It(e.id,e.content):void 0},e.id))}),t.jsx("div",{ref:Gt})]}),ce&&t.jsxs("button",{type:"button",className:"btn btn-sm chat-jump-to-latest","data-testid":"chat-jump-to-latest",onClick:qe,children:[t.jsx(ps,{size:14}),"Latest"]}),i&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:qt,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{at(e.target.files),e.target.value=""}}),we&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:gt?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):le.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:Be?"No skills found":"No skills available"}):le.map((e,a)=>t.jsxs("button",{type:"button",role:"option","aria-selected":a===Ce,className:`chat-skill-menu-item${a===Ce?" chat-skill-menu-item--highlighted":""}`,onMouseDown:u=>u.preventDefault(),onMouseEnter:()=>ke(a),onClick:()=>Nt(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))}),F.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:F.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:()=>_s(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:()=>qt.current?.click(),children:t.jsx(jn,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${B?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),J(!0)},onDragLeave:()=>J(!1),onDrop:e=>{e.preventDefault(),J(!1),at(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:ne,className:"chat-input-textarea",placeholder:"Type a message...",value:c,onChange:ns,onKeyDown:ss,onKeyUp:as,onClick:ot,onBlur:rs,onFocus:is,onPaste:zs,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(fs,{agents:Fe,filter:je,highlightedIndex:P,visible:y,onSelect:rt,position:"below",roomMemberIds:be?.memberIds,roomName:be?.roomName}),t.jsx(Mn,{visible:K.mentionActive&&!y,position:Ps,files:K.files,selectedIndex:K.selectedIndex,onSelect:e=>{const a=K.selectFile(e,c);m(a),K.dismissMention(),Ke(!1),ne.current?.focus()},loading:K.loading}),b&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${Vs}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:j,children:"×"})]})]}),T?t.jsx("button",{className:"chat-input-stop",onClick:U,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(Rn,{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:()=>{wt()},disabled:!c.trim()&&F.length===0,"data-testid":"chat-send-btn",style:{touchAction:"manipulation"},children:t.jsx(gs,{size:16})})]})]})]}),z&&t.jsx(On,{isOpen:Te,onClose:()=>ae(!1),projectId:s,existingRoomNames:o.rooms.map(e=>e.name),onCreate:async e=>{await o.createRoom({name:e.name,memberAgentIds:e.memberAgentIds}),h!=="rooms"&&f("rooms"),ae(!1),$&&me(!1)}}),V&&t.jsx(Yn,{projectId:s,onClose:()=>q(!1),onCreate:Us})]})}export{sa as ChatView,zt as clampChatInputHeight};
@@ -1 +0,0 @@
1
- .skill-multiselect{display:flex;flex-direction:column;gap:var(--space-sm)}.skill-multiselect-label{font-size:13px;font-weight:500;color:var(--text-secondary)}.skill-multiselect-chips{display:flex;flex-wrap:wrap;gap:4px}.skill-chip{display:inline-flex;align-items:center;gap:4px;padding:2px 6px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:4px;font-size:12px;line-height:1.4}.skill-chip-name{max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.skill-chip-remove{display:inline-flex;align-items:center;justify-content:center;width:14px;height:14px;padding:0;background:transparent;border:none;border-radius:2px;color:var(--text-muted);font-size:14px;line-height:1;cursor:pointer;transition:color .15s,background .15s}.skill-chip-remove:hover:not(:disabled){color:var(--text-primary);background:var(--bg-hover)}.skill-chip-remove:disabled{opacity:.5;cursor:not-allowed}.skill-multiselect-add{min-height:32px}.skill-multiselect-loading,.skill-multiselect-empty{font-size:13px;color:var(--text-muted);padding:4px 0}.skill-multiselect-dropdown{width:100%;font-size:13px}.agent-dialog-skills-hint{margin-top:4px;font-size:12px}.skill-badge-row{display:flex;flex-wrap:wrap;gap:4px}.skill-badge{display:inline-block;padding:2px 6px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:4px;font-size:11px;line-height:1.4}.badge-skill{background:var(--bg-tertiary);color:var(--text-secondary)}.agent-board-skills{display:flex;flex-wrap:wrap;gap:4px;padding:4px 8px}.skill-badge-sm{display:inline-block;padding:1px 5px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:3px;font-size:10px;line-height:1.4}.skill-badge-extra{background:var(--bg-secondary)}.agent-tree__skill{display:inline-block;padding:1px 5px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:3px;font-size:10px;line-height:1.4;margin-left:6px}.org-chart-node__skill{display:inline-block;padding:1px 5px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:3px;font-size:10px;line-height:1.4}.divider{color:var(--border)}.text-muted{color:var(--text-muted)}.link{display:inline-flex;align-items:center;gap:4px;color:var(--todo);text-decoration:none}.link:hover{text-decoration:underline}.text-secondary{color:var(--text-muted)}.experimental-agent-onboarding-modal__textarea{min-height:calc(var(--space-2xl) * 4)}.experimental-agent-onboarding-modal__summary{display:flex;flex-direction:column;gap:var(--space-lg);padding:var(--space-lg)}.experimental-agent-onboarding-modal__summary-section{display:flex;flex-direction:column;gap:var(--space-sm)}.experimental-agent-onboarding-modal__summary-section h4{margin:0;color:var(--text);font-size:calc(var(--space-md) + var(--space-xs) * .25)}.experimental-agent-onboarding-modal__summary-intro{margin:var(--space-sm) 0;color:var(--text-muted)}.experimental-agent-onboarding-modal__summary-section p{margin:0;color:var(--text-muted)}.experimental-agent-onboarding-modal__summary-list{display:flex;flex-direction:column;gap:var(--space-sm);margin:0}.experimental-agent-onboarding-modal__summary-list>div{display:grid;gap:var(--space-sm);grid-template-columns:minmax(0,calc(var(--space-xl) * 5)) minmax(0,1fr)}.experimental-agent-onboarding-modal__summary-list dt{color:var(--text-muted)}.experimental-agent-onboarding-modal__summary-list dd{margin:0;color:var(--text)}.experimental-agent-onboarding-modal__summary-empty{color:var(--text-dim)}.experimental-agent-onboarding-modal__summary-block{white-space:pre-wrap}@media(max-width:768px){.experimental-agent-onboarding-modal__textarea{min-height:calc(var(--space-2xl) * 3)}.experimental-agent-onboarding-modal__summary{gap:var(--space-md);padding:var(--space-md)}.experimental-agent-onboarding-modal__summary-list>div{grid-template-columns:1fr;gap:var(--space-xs)}}
@@ -1 +0,0 @@
1
- .plugin-manager,.plugin-manager-detail{display:flex;flex-direction:column;gap:var(--space-lg);padding-inline:var(--space-xl);padding-block:var(--space-md)}.plugin-manager-header{display:flex;align-items:center;justify-content:space-between;padding-bottom:var(--space-sm);border-bottom:var(--btn-border-width) solid var(--border);gap:var(--space-sm)}.plugin-manager-header-title{font-size:var(--font-size-sm, .85rem);font-weight:600;color:var(--text);flex:1}.plugin-manager-actions{display:flex;gap:var(--space-sm);align-items:center}.plugin-install-form{display:flex;flex-direction:column;gap:var(--space-sm);padding:var(--space-lg);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.plugin-install-hint{margin:0;font-size:var(--font-size-sm, .85rem);color:var(--text-secondary, var(--text-muted));line-height:1.45}.plugin-install-hint code{padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-sm);background:color-mix(in srgb,var(--text-muted) 12%,transparent);font-size:.85em}.plugin-install-actions{display:flex;gap:var(--space-sm);justify-content:flex-end}.plugin-list{display:flex;flex-direction:column;gap:var(--space-sm)}.plugin-item{display:flex;align-items:center;justify-content:space-between;padding:var(--space-md) var(--space-lg);background:var(--surface);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);transition:border-color var(--transition-fast)}.plugin-item:hover{border-color:var(--text-dim)}.plugin-info{display:flex;align-items:center;gap:var(--space-sm);min-width:0;flex:1}.plugin-copy{display:flex;flex-direction:column;gap:var(--space-xs);min-width:0}.plugin-copy-header{display:flex;align-items:center;gap:var(--space-sm);min-width:0;flex-wrap:wrap}.plugin-name{font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.plugin-version{font-size:var(--font-size-sm, .85rem)}.plugin-state-badge{display:inline-flex;align-items:center;padding:var(--space-xs) var(--space-sm);border-radius:var(--radius-pill);font-size:var(--font-size-3xs, .7rem);font-weight:600;text-transform:uppercase;letter-spacing:.04em;background:color-mix(in srgb,currentColor 12%,transparent)}.plugin-actions{display:flex;align-items:center;gap:var(--space-xs);flex-shrink:0}.plugin-manager-detail-header,.plugin-detail-title{display:flex;align-items:center;gap:var(--space-md);flex-wrap:wrap}.plugin-detail-title-copy{display:flex;flex-direction:column;gap:var(--space-xs);min-width:0}.plugin-detail-name{margin:0}.plugin-error-text{margin:0;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:var(--font-size-xs, .8rem);font-family:var(--font-mono);color:var(--color-error);background:color-mix(in srgb,var(--color-error) 10%,transparent);border-radius:var(--radius-sm);padding:var(--space-xs) var(--space-sm)}.plugin-error-text--detail{max-width:min(100%,32rem);overflow:visible;text-overflow:clip;white-space:normal;overflow-wrap:anywhere;word-break:break-word}.plugin-detail-content{display:flex;flex-direction:column;gap:var(--space-lg)}.plugin-detail-card{background:var(--surface);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);padding:var(--space-lg);display:flex;flex-direction:column;gap:var(--space-md)}.plugin-description{font-size:var(--font-size-md, .95rem);color:var(--text-secondary, var(--text-muted));line-height:1.5}.plugin-detail-meta-row{display:flex;align-items:center;gap:var(--space-xs);font-size:var(--font-size-base, .9rem);color:var(--text-muted)}.plugin-homepage{flex-wrap:wrap;align-items:flex-start}.plugin-homepage a{display:inline-flex;align-items:center;gap:var(--space-xs);color:var(--color-info);font-size:var(--font-size-sm, .85rem);flex-wrap:wrap;overflow-wrap:anywhere}.plugin-detail-section-heading{margin:0;padding:0;border:0;font-size:var(--font-size-md, .95rem)}.plugin-settings-form{display:flex;flex-direction:column;gap:var(--space-lg);margin-top:var(--space-xs)}.plugin-settings-form .form-group{padding:0;margin:0}.plugin-settings-group{display:flex;flex-direction:column;gap:var(--space-md)}.plugin-settings-group-heading{margin:0;font-size:var(--font-size-xs, .8rem);font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:var(--text-muted)}.plugin-settings-array{display:flex;flex-direction:column;gap:var(--space-sm)}.plugin-settings-array-item{display:flex;align-items:center;gap:var(--space-sm)}.plugin-settings-array-item input{flex:1}.plugin-security-row{display:flex;align-items:center;justify-content:space-between;gap:var(--space-sm);flex-wrap:wrap}.plugin-security-results{display:flex;flex-direction:column;gap:var(--space-sm)}.plugin-security-header{display:flex;gap:var(--space-sm);align-items:center}.plugin-security-summary{margin:0}.plugin-security-badge{font-weight:700}.plugin-security-badge--warning,.plugin-security-badge--unavailable{color:var(--color-warning)}.plugin-security-badge--blocked,.plugin-security-badge--error{color:var(--color-error)}.plugin-security-findings{margin:0;padding-inline-start:var(--space-lg);display:flex;flex-direction:column;gap:var(--space-xs)}.plugin-detail-actions{display:flex;gap:var(--space-sm);padding-top:var(--space-md);border-top:var(--btn-border-width) solid var(--border);justify-content:flex-end}.plugin-manager .empty-state,.plugin-manager .loading-state,.plugin-manager .settings-empty-state{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:var(--space-sm);padding:var(--space-2xl);text-align:center;color:var(--text-muted)}.plugin-builtins-section{display:flex;flex-direction:column;gap:var(--space-sm)}.plugin-builtins-header{display:flex;flex-direction:column;gap:var(--space-xs)}.plugin-builtins-heading{margin:0;font-size:var(--font-size-md, .95rem)}.plugin-builtins-description{margin:0;font-size:var(--font-size-sm, .85rem);color:var(--text-muted)}.plugin-builtins-list{width:100%;display:flex;flex-direction:column;gap:var(--space-sm);margin-top:var(--space-sm)}.plugin-builtins-item{display:flex;align-items:center;justify-content:space-between;gap:var(--space-sm);padding:var(--space-sm) var(--space-md);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.plugin-builtins-meta{display:flex;align-items:center;gap:var(--space-sm);row-gap:var(--space-xs);flex-wrap:wrap;min-width:0}.plugin-builtins-name{color:var(--text);font-size:var(--font-size-base, .9rem);font-weight:500}.plugin-builtins-runtime-badge{display:inline-flex;align-items:center;padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-pill);background:var(--status-in-review-bg);color:var(--in-review);font-size:var(--font-size-2xs, .75rem);font-weight:600;text-transform:uppercase}.plugin-builtins-status{display:inline-flex;align-items:center;padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-pill);font-size:var(--font-size-2xs, .75rem);font-weight:600;text-transform:uppercase}.plugin-builtins-status--installed{background:var(--status-done-bg);color:var(--done)}.plugin-builtins-status--available{background:var(--status-todo-bg);color:var(--todo)}.plugin-builtins-setup-status{display:inline-flex;align-items:center;padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-pill);font-size:var(--font-size-2xs, .75rem);font-weight:600;text-transform:uppercase}.plugin-builtins-setup-status--warning{background:var(--status-in-review-bg);color:var(--color-warning)}.plugin-builtins-setup-status--ready{background:var(--status-done-bg);color:var(--color-success)}.plugin-builtins-setup-status--pending{background:var(--status-todo-bg);color:var(--color-warning)}.plugin-builtins-setup-status--deferred{background:var(--status-archived-bg);color:var(--text-muted)}.plugin-builtins-description-text{flex:1 1 100%;color:var(--text-muted);font-size:var(--font-size-sm, .85rem)}.plugin-builtins-metadata-only{color:var(--text-muted);font-size:var(--font-size-xs, .8rem);font-weight:600;text-transform:uppercase}.plugin-bundled-runtime-list{width:100%;display:flex;flex-direction:column;gap:var(--space-sm);margin-top:var(--space-sm)}.plugin-bundled-runtime-item{display:flex;align-items:center;justify-content:space-between;gap:var(--space-sm);padding:var(--space-sm) var(--space-md);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.plugin-bundled-runtime-meta{display:flex;align-items:center;gap:var(--space-sm);row-gap:var(--space-xs);flex-wrap:wrap;min-width:0}.plugin-bundled-runtime-name{color:var(--text);font-size:var(--font-size-base, .9rem);font-weight:500}.plugin-bundled-runtime-badge{display:inline-flex;align-items:center;padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-pill);background:var(--status-in-review-bg);color:var(--in-review);font-size:var(--font-size-2xs, .75rem);font-weight:600;text-transform:uppercase}.plugin-bundled-runtime-section{display:flex;flex-direction:column;gap:var(--space-sm)}.plugin-bundled-runtime-header{display:flex;flex-direction:column;gap:var(--space-xs)}.plugin-bundled-runtime-heading{margin:0;font-size:var(--font-size-md, .95rem)}.plugin-bundled-runtime-description{margin:0;font-size:var(--font-size-sm, .85rem);color:var(--text-muted)}.plugin-bundled-runtime-status{display:inline-flex;align-items:center;padding:var(--btn-border-width) var(--space-xs);border-radius:var(--radius-pill);font-size:var(--font-size-2xs, .75rem);font-weight:600;text-transform:uppercase}@media(min-width:769px){.plugin-builtins-status,.plugin-bundled-runtime-status{margin-left:auto}}.plugin-bundled-runtime-status--installed{background:var(--status-done-bg);color:var(--done)}.plugin-bundled-runtime-status--available{background:var(--status-todo-bg);color:var(--todo)}@media(max-width:768px){.plugin-manager,.plugin-manager-detail{padding-inline:var(--space-sm)}.plugin-manager-detail-header{gap:var(--space-sm)}.plugin-detail-title{gap:var(--space-xs)}.plugin-detail-card{padding:var(--space-md);gap:var(--space-sm)}.plugin-list{gap:var(--space-xs)}.plugin-item{padding:var(--space-md);flex-direction:column;align-items:stretch;gap:var(--space-sm)}.plugin-info{width:100%;flex-wrap:wrap;row-gap:var(--space-xs)}.plugin-name{flex:1 1 100%;white-space:normal}.plugin-actions{width:100%;justify-content:flex-end;flex-wrap:wrap;gap:var(--space-sm)}.plugin-actions .btn-icon,.plugin-actions .toggle-switch{min-width:36px;min-height:36px}.plugin-actions .toggle-switch{display:inline-flex;align-items:center;justify-content:center}.plugin-security-row{align-items:flex-start}.plugin-detail-actions{flex-wrap:wrap;justify-content:flex-start}.plugin-detail-actions button{flex:1 1 auto;min-height:36px}.plugin-builtins-item,.plugin-bundled-runtime-item{flex-direction:column;align-items:stretch}.plugin-builtins-item .btn,.plugin-bundled-runtime-item .btn{min-height:36px}}
@@ -1 +0,0 @@
1
- .settings-header-actions{--settings-header-action-height: calc(var(--space-md) * 2 + var(--space-xs) / 2);display:flex;align-items:stretch;gap:var(--space-xs);margin-left:auto;margin-right:var(--space-sm)}.settings-header-actions>.settings-github-star-btn,.settings-header-actions>.settings-header-help-btn{height:var(--settings-header-action-height);box-sizing:border-box}.settings-header-help-btn{display:inline-flex;align-items:center}@media(max-width:768px){.settings-header-actions{--settings-header-action-height: calc(var(--space-md) * 3)}.settings-header-actions>.btn-icon,.settings-header-actions>.settings-github-star-btn,.settings-header-actions>.settings-header-help-btn{min-height:var(--settings-header-action-height)}.settings-header-actions>.btn-icon{min-width:calc(var(--space-md) * 3)}.settings-github-star-btn__action,.settings-github-star-btn__count{min-height:var(--settings-header-action-height)}}.settings-github-star-btn{display:inline-flex;align-items:stretch;border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-pill);background:var(--card);color:var(--text);font-size:12px;font-weight:500;text-decoration:none;overflow:hidden;transition:border-color var(--transition-fast),background var(--transition-fast)}.settings-github-star-btn:hover{border-color:var(--text-muted);background:var(--card-hover)}.settings-github-star-btn:focus-visible{outline:none;box-shadow:var(--focus-ring-strong);border-color:var(--todo)}.settings-github-star-btn__action{display:inline-flex;align-items:center;gap:var(--space-xs);padding:var(--space-xs) calc(var(--space-sm) + var(--space-xs) / 2)}.settings-github-star-btn__count{display:inline-flex;align-items:center;padding:var(--space-xs) calc(var(--space-sm) + var(--space-xs) / 4);border-left:var(--btn-border-width) solid var(--border);background:color-mix(in srgb,var(--surface) 60%,var(--card));color:var(--text-muted);font-variant-numeric:tabular-nums}.settings-modal{width:min(95vw,1100px);max-width:95vw;min-width:520px;height:80vh;min-height:480px;max-height:calc(100dvh - var(--overlay-padding-top, 10vh) - 16px);overflow:hidden;resize:both}@media(max-width:768px){.modal-overlay.settings-modal-overlay,.modal-overlay:has(.settings-modal){padding:0;inset:0;align-items:stretch;justify-content:stretch}.modal.settings-modal{width:100vw;min-width:0;max-width:100vw;height:100dvh;min-height:100dvh;max-height:100dvh;margin:0;border:none;border-radius:0;resize:none;flex:1 1 auto}.modal.settings-modal[style*=--keyboard-overlap]{height:var(--vv-height, 100dvh);min-height:var(--vv-height, 100dvh);max-height:var(--vv-height, 100dvh);transform:translateY(var(--vv-offset-top, 0px));will-change:transform}}.settings-modal-heading{display:flex;flex-direction:column;gap:var(--space-xs)}.settings-modal-heading h3{margin:0}.settings-modal-version{margin:0;font-size:.85rem;color:var(--text-muted);font-weight:500}.settings-update-check{display:flex;align-items:center;gap:var(--space-sm)}.settings-version-check-btn{--settings-inline-touch-target: calc(var(--space-lg) + var(--space-lg) + var(--space-xs));display:inline-flex;align-items:center;gap:var(--space-xs);margin:0;min-height:var(--settings-inline-touch-target);padding:var(--space-xs) var(--space-sm);border:none;background:transparent;color:var(--text-muted);cursor:pointer;transition:opacity var(--transition-fast),box-shadow var(--transition-fast)}.settings-version-check-btn:hover:not(:disabled){opacity:.85}.settings-version-check-btn:focus-visible{outline:none;box-shadow:var(--focus-ring-strong);border-radius:var(--radius-sm)}.settings-version-check-btn:disabled{cursor:default;opacity:.7}.settings-version-check-btn svg{color:var(--text-muted)}.settings-version-check-btn svg.spinning{animation:settings-update-spin 1s linear infinite}.settings-update-result{font-size:.85rem;font-weight:500}.settings-update-result--up-to-date{color:var(--color-success)}.settings-update-result--available{color:var(--color-info)}.settings-update-result--error{color:var(--text-muted)}.settings-update-result-link{color:var(--color-info);text-decoration:underline;transition:color var(--transition-fast),box-shadow var(--transition-fast)}.settings-update-result-link:hover{color:color-mix(in srgb,var(--color-info) 80%,var(--text))}.settings-update-result-link:focus-visible{outline:none;box-shadow:var(--focus-ring-strong);border-radius:var(--radius-sm)}@keyframes settings-update-spin{to{transform:rotate(360deg)}}.settings-layout{display:flex;flex:1;flex-direction:row;min-height:0;overflow:hidden}.settings-mobile-section-picker{display:none}.settings-sidebar{width:170px;min-width:170px;border-right:1px solid var(--border);display:flex;flex-direction:column;overflow-y:auto;padding:var(--space-sm) var(--space-sm);gap:calc(var(--space-xs) / 2);background:color-mix(in srgb,var(--text) 10%,transparent);scrollbar-color:var(--border) transparent;scrollbar-width:thin}.settings-sidebar::-webkit-scrollbar{width:6px}.settings-sidebar::-webkit-scrollbar-track{background:transparent}.settings-sidebar::-webkit-scrollbar-thumb{background:var(--border);border-radius:var(--radius-sm)}.settings-sidebar::-webkit-scrollbar-thumb:hover{background:var(--text-muted)}.settings-research-source-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:var(--space-sm)}@media(max-width:768px){.settings-research-source-grid{grid-template-columns:1fr}}.settings-nav-item{display:block;width:100%;padding:var(--space-sm) var(--space-md);font-size:13px;font-weight:500;color:var(--text-muted);background:none;border:none;border-left:3px solid transparent;border-radius:0 var(--radius-md) var(--radius-md) 0;cursor:pointer;text-align:left;transition:background var(--transition-fast),color var(--transition-fast),border-color var(--transition-fast)}.settings-nav-item:hover{background:var(--bg);color:var(--text);border-left-color:var(--border)}.settings-nav-item:focus-visible{box-shadow:var(--focus-ring-strong);outline:none}.settings-nav-item.active{background:var(--bg);color:var(--todo);font-weight:600;border-left-color:var(--todo)}.settings-group-header{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;color:var(--text-muted);padding:var(--space-md) var(--space-md) var(--space-xs);margin-top:var(--space-sm);user-select:none}.settings-group-header:first-child{margin-top:0}.settings-content{flex:1;overflow-x:hidden;overflow-y:auto;padding:4px 0 12px;scrollbar-color:var(--border) transparent;scrollbar-width:thin}.settings-content::-webkit-scrollbar{width:6px}.settings-content::-webkit-scrollbar-track{background:transparent}.settings-content::-webkit-scrollbar-thumb{background:var(--border);border-radius:var(--radius-sm)}.settings-content::-webkit-scrollbar-thumb:hover{background:var(--text-muted)}.settings-content>*{animation:settingsFadeIn var(--transition-normal)}@keyframes settingsFadeIn{0%{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}.settings-section-heading{font-size:14px;font-weight:600;padding:var(--space-lg) var(--space-xl) var(--space-md);margin:0 0 var(--space-md);color:var(--text);border-bottom:1px solid var(--border)}.settings-content>.settings-section-heading:first-child,.settings-modal-section>.settings-section-heading:first-child{padding-top:var(--space-md)}.settings-section-heading--spaced{margin-top:var(--space-lg)}.settings-section-description{margin:0;padding:0 var(--space-xl);margin-bottom:var(--space-sm);color:var(--text-muted);font-size:13px;line-height:1.5}.settings-plugins-subsection-toggle{display:inline-flex;gap:var(--space-xs);padding:0 var(--space-xl);margin:var(--space-md) 0}.settings-plugins-subsection-btn{display:inline-flex;align-items:center;justify-content:center;border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-pill);background:var(--surface);color:var(--text-muted);font-size:.85rem;font-weight:600;padding:var(--space-xs) var(--space-md);cursor:pointer;transition:background var(--transition-fast),color var(--transition-fast),border-color var(--transition-fast),box-shadow var(--transition-fast)}.settings-plugins-subsection-btn:hover{background:var(--surface-hover, color-mix(in srgb, var(--text) 6%, transparent));color:var(--text)}.settings-plugins-subsection-btn:focus-visible{outline:none;box-shadow:var(--focus-ring-strong)}.settings-plugins-subsection-btn.active{background:color-mix(in srgb,var(--todo) 14%,transparent);border-color:color-mix(in srgb,var(--todo) 45%,var(--border));color:var(--todo)}.settings-plugins-subsection-panel{padding-bottom:var(--space-md)}.settings-scope-icon{margin-right:6px;display:inline-flex;vertical-align:middle;color:var(--text-muted)}.settings-scope-banner{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-sm) var(--space-xl);margin:0 var(--space-xl) var(--space-xs);font-size:12px;border-radius:var(--radius-md);color:var(--text-muted)}.settings-scope-global{background:color-mix(in srgb,var(--color-info) 8%,transparent);border-left:3px solid color-mix(in srgb,var(--color-info) 40%,transparent)}.settings-scope-project{background:color-mix(in srgb,var(--color-success) 8%,transparent);border-left:3px solid color-mix(in srgb,var(--color-success) 40%,transparent)}.settings-scope-mixed{background:color-mix(in srgb,var(--triage) 8%,transparent);border-left:3px solid color-mix(in srgb,var(--triage) 40%,transparent)}.settings-note{display:block;padding:0 var(--space-xl);margin-top:var(--space-xs);font-size:12px;color:var(--text-muted)}.settings-overlap-ignore-group code{font-family:var(--font-mono);font-size:.9em}.settings-button-row{display:flex;flex-wrap:wrap;gap:var(--space-sm);margin-top:var(--space-sm)}.settings-raw-output{margin:var(--space-sm) 0 0;padding:var(--space-sm);border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--surface);color:var(--text-muted);max-height:calc(var(--space-2xl) * 7);overflow:auto;font-family:var(--font-mono);font-size:calc(var(--space-sm) + var(--space-xs))}.settings-url-output{display:block;margin-top:var(--space-xs);padding:var(--space-sm);border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--surface);color:var(--text-muted);font-family:var(--font-mono);font-size:calc(var(--space-sm) + var(--space-xs));overflow-wrap:anywhere;word-break:break-word;overflow-x:auto;max-width:100%}.settings-qr-preview{margin-top:var(--space-sm);display:flex;flex-direction:column;gap:var(--space-sm)}.settings-qr-preview-label{margin:0;font-size:calc(var(--space-sm) + var(--space-xs));color:var(--text-muted)}.settings-qr-preview-image-wrap{width:fit-content;max-width:100%;padding:var(--space-sm);border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--card)}.settings-qr-preview-image{display:block;width:min(calc(var(--space-2xl) * 6),100%);height:auto;aspect-ratio:1 / 1}.remote-provider-selector{display:flex;gap:var(--space-xs);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);padding:var(--space-xs);background:var(--surface)}.remote-provider-option{position:relative;flex:1;cursor:pointer}.remote-provider-option input{position:absolute;opacity:0;width:0;height:0}.remote-provider-option span{display:block;padding:var(--space-sm) var(--space-md);text-align:center;border-radius:var(--radius-sm);border:var(--btn-border-width) solid transparent;color:var(--text-muted);transition:background var(--transition-fast),color var(--transition-fast),border-color var(--transition-fast)}.remote-provider-option-content{display:inline-flex;align-items:center;gap:var(--space-xs)}.remote-provider-option input:checked+span{background:var(--card);color:var(--text);border-color:var(--border)}.remote-provider-option input:focus-visible+span{box-shadow:var(--focus-ring-strong)}.remote-status-bar{--status-color: var(--text-muted);display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-sm) var(--space-md);border-radius:var(--radius-md);margin:0 var(--space-xl) var(--space-md);background:color-mix(in srgb,var(--status-color) 10%,transparent)}.remote-status-bar--running{--status-color: var(--color-success)}.remote-status-bar--starting{--status-color: var(--color-warning)}.remote-status-bar--error{--status-color: var(--color-error)}.remote-status-bar--stopped{--status-color: var(--text-muted)}.remote-share-block{display:flex;flex-direction:column;gap:var(--space-sm);margin:0 var(--space-xl) var(--space-md);padding:var(--space-sm) var(--space-md);border:1px solid var(--border);border-radius:var(--radius-md);background:color-mix(in srgb,var(--text-muted) 5%,transparent)}.remote-share-row{display:flex;flex-direction:column;gap:var(--space-xs)}.remote-share-row .settings-qr-preview-image{margin-top:var(--space-xs)}.remote-status-dot{width:var(--space-sm);height:var(--space-sm);border-radius:50%;display:inline-block;flex-shrink:0}.remote-status-dot--running{background:var(--color-success)}.remote-status-dot--starting{background:var(--color-warning)}.remote-status-dot--error{background:var(--color-error)}.remote-status-dot--stopped{background:var(--text-muted)}.remote-status-url{margin-left:auto;font-family:var(--font-mono);overflow-wrap:anywhere;word-break:break-word;user-select:all}.remote-provider-settings{display:flex;flex-direction:column;gap:var(--space-sm)}.remote-cli-detection{display:flex;align-items:flex-start;gap:var(--space-sm);margin:0 var(--space-xl) var(--space-md);padding:var(--space-sm) var(--space-md);border-radius:var(--radius-sm)}.remote-cli-detection--available{background:color-mix(in srgb,var(--color-success) 10%,transparent);color:var(--color-success)}.remote-cli-detection--missing{background:color-mix(in srgb,var(--color-warning) 10%,transparent);color:var(--color-warning)}.remote-cli-detection-content{display:flex;flex-direction:column;gap:var(--space-xs);color:var(--text)}.remote-cli-detection .btn{align-self:flex-start}.remote-cli-install-error{color:var(--color-error)}.remote-cli-manual{color:var(--text-dim)}.remote-external-tunnel-panel{display:flex;flex-direction:column;gap:var(--space-sm);margin:0 var(--space-xl) var(--space-md);padding:var(--space-sm) var(--space-md);border:1px solid var(--border);border-radius:var(--radius-md);background:color-mix(in srgb,var(--color-info) 10%,transparent)}.remote-external-tunnel-header{display:flex;align-items:center;gap:var(--space-sm);color:var(--color-info)}.remote-external-tunnel-qr{display:flex;flex-direction:column;gap:var(--space-xs)}.remote-external-tunnel-actions{display:flex;flex-direction:column;gap:var(--space-sm)}.remote-advanced-details{margin:var(--space-lg) var(--space-xl) 0;border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);padding:var(--space-md);background:var(--surface)}.remote-advanced-details>summary{cursor:pointer;color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs));list-style:none}.remote-advanced-details>summary::-webkit-details-marker{display:none}.remote-advanced-details>summary:before{content:"▸";margin-right:var(--space-xs)}.remote-advanced-details[open]>summary:before{content:"▾"}.settings-option-details{margin-top:var(--space-xs)}.settings-option-details>summary{cursor:pointer;color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs));list-style:none}.settings-option-details>summary::-webkit-details-marker{display:none}.settings-option-details>summary:before{content:"▸";margin-right:var(--space-xs)}.settings-option-details[open]>summary:before{content:"▾"}.remote-cf-advanced-details{margin-top:var(--space-xs)}.remote-cf-advanced-details>summary{cursor:pointer;color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs));list-style:none}.remote-cf-advanced-details>summary::-webkit-details-marker{display:none}.remote-cf-advanced-details>summary:before{content:"▸";margin-right:var(--space-xs)}.remote-cf-advanced-details[open]>summary:before{content:"▾"}.remote-cf-advanced-fields{display:flex;flex-direction:column;gap:var(--space-sm);margin-top:var(--space-sm)}.remote-tunnel-actions{margin-top:var(--space-md)}.remote-tunnel-actions .btn{width:100%}.settings-overlap-ignore-list{display:flex;flex-direction:column;gap:var(--space-sm);margin:var(--space-sm) 0}.settings-overlap-ignore-row,.settings-overlap-ignore-path-controls{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:var(--space-sm);align-items:center}.settings-overlap-path-picker-modal{max-width:min(960px,calc(100vw - var(--space-2xl)))}.settings-overlap-path-picker-body{display:flex;flex-direction:column;gap:var(--space-sm);max-height:min(70vh,720px)}.settings-overlap-path-picker-note{margin:0;font-size:12px;color:var(--text-muted)}.settings-section-divider{border-top:1px solid var(--border);margin:var(--space-lg) var(--space-xl)}@media(max-width:768px){.settings-note{padding:0 var(--space-lg)}.settings-overlap-ignore-row,.settings-overlap-ignore-path-controls{grid-template-columns:minmax(0,1fr)}.settings-overlap-ignore-row>.btn{justify-self:start}.settings-overlap-path-picker-modal{max-width:calc(100vw - var(--space-md))}.remote-provider-selector{flex-direction:column}.remote-status-bar{flex-wrap:wrap;margin:0 var(--space-lg) var(--space-md)}.remote-share-block{margin:0 var(--space-lg) var(--space-md)}.remote-status-url{width:100%;margin-left:0;font-size:.8em}.remote-provider-option,.remote-tunnel-actions .btn{min-height:36px}.remote-cli-detection,.remote-external-tunnel-panel{margin:0 var(--space-lg) var(--space-md)}}.ntfy-advanced-disclosure{margin-top:var(--space-md);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.ntfy-advanced-disclosure>summary{cursor:pointer;list-style:none;padding:var(--space-sm) var(--space-md);font-size:12px;font-weight:600;color:var(--text)}.ntfy-advanced-disclosure>summary::-webkit-details-marker{display:none}.ntfy-advanced-content{padding:0 var(--space-md) var(--space-md);display:flex;flex-direction:column;gap:var(--space-sm)}.settings-inline-link{color:var(--todo);text-decoration:none;transition:text-decoration var(--transition-fast)}.settings-inline-link:hover{text-decoration:underline}.settings-inline-link:focus-visible{outline:none;box-shadow:var(--focus-ring-strong);border-radius:var(--radius-sm)}.notification-provider-card{border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-lg);background:var(--surface);margin:0 var(--space-xl) var(--space-lg);overflow:hidden}.notification-provider-header{display:flex;align-items:center;justify-content:space-between;padding:var(--space-md) var(--space-lg);border-bottom:var(--btn-border-width) solid var(--border)}.notification-provider-body{padding:var(--space-lg);display:flex;flex-direction:column;gap:var(--space-lg)}.notification-provider-actions{display:flex;flex-wrap:wrap;gap:var(--space-sm);padding-top:var(--space-md);border-top:var(--btn-border-width) solid var(--border);margin-top:var(--space-md)}.notification-test-feedback{display:flex;flex-direction:column;gap:var(--space-xs);margin-top:var(--space-sm)}.notification-test-feedback-item{border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-sm);padding:var(--space-xs) var(--space-sm)}.notification-test-feedback-item--success{border-color:color-mix(in srgb,var(--color-success) 45%,var(--border));background:color-mix(in srgb,var(--color-success) 8%,transparent);color:var(--color-success)}.notification-test-feedback-item--error{border-color:color-mix(in srgb,var(--color-error) 45%,var(--border));background:color-mix(in srgb,var(--color-error) 8%,transparent);color:var(--color-error)}@media(max-width:768px){.notification-provider-actions{flex-direction:column}.notification-provider-actions .btn{width:100%}}.memory-status-message{display:flex;gap:var(--space-md);align-items:center;justify-content:space-between;margin-bottom:var(--space-md)}.memory-status-message span{min-width:0}.memory-retrieval-test{margin-top:var(--space-lg)}.memory-test-result{margin:0 var(--space-xl) var(--space-lg);padding:var(--space-md);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--card)}.memory-test-result strong,.memory-test-result span{color:var(--text);font-size:12px}.memory-test-result small{display:block;margin-top:var(--space-xs);color:var(--text-muted);font-size:12px}.memory-test-result ul{margin:var(--space-md) 0 0;padding:0;list-style:none}.memory-test-result li{padding-top:var(--space-sm);border-top:var(--btn-border-width) solid var(--border)}.memory-test-result li+li{margin-top:var(--space-sm)}.memory-test-result p{margin:var(--space-xs) 0 0;color:var(--text-muted);font-size:12px;line-height:1.5;overflow-wrap:anywhere}.memory-editor-section{margin-top:var(--space-lg);display:flex;flex:1 1 auto;flex-direction:column;min-height:0}.memory-editor-form-group{display:flex;flex:1 1 auto;flex-direction:column;min-height:0}.memory-file-summary{display:grid;grid-template-columns:auto minmax(0,1fr);gap:var(--space-xs) var(--space-md);align-items:center;margin:0 var(--space-xl) var(--space-md);padding:var(--space-md);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--card)}.memory-file-summary span{display:inline-flex;align-items:center;justify-content:center;padding:var(--space-xs) var(--space-sm);border-radius:var(--radius-pill);color:var(--color-info);background:color-mix(in srgb,var(--color-info) 12%,transparent);font-size:11px;font-weight:600}.memory-file-summary strong{min-width:0;overflow-wrap:anywhere;color:var(--text);font-family:var(--font-mono);font-size:12px}.memory-file-summary small{grid-column:2;color:var(--text-muted);font-size:12px}.memory-editor-frame{min-height:50vh;border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);overflow:hidden;display:flex;flex:1 1 auto;flex-direction:column;min-width:0}.auth-panel-body{padding-inline:var(--space-md)}.auth-section-hint{padding:var(--space-md) var(--space-lg);margin-bottom:var(--space-md);background:var(--bg-tertiary);border-radius:var(--radius-md);font-size:13px;color:var(--text-muted);border-left:3px solid var(--text-muted)}.auth-provider-group{margin-bottom:calc(var(--space-sm) + var(--space-xs) / 2)}.auth-group-label{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.5px;color:var(--text-muted);margin-bottom:var(--space-xs);padding:0 4px}.auth-provider-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);margin-bottom:var(--space-xs);overflow:hidden;transition:border-color var(--transition-fast),box-shadow var(--transition-fast)}.auth-provider-card:hover{border-color:var(--text-dim)}.auth-provider-card--authenticated{border-color:color-mix(in srgb,var(--color-success) 40%,var(--border));background:color-mix(in srgb,var(--color-success) 5%,var(--surface))}.auth-provider-card--authenticated:hover{border-color:color-mix(in srgb,var(--color-success) 60%,var(--border))}.auth-provider-header{display:flex;align-items:center;justify-content:space-between;padding:var(--space-sm) var(--space-md);gap:12px}.auth-provider-info{display:flex;align-items:center;gap:10px;flex-wrap:wrap;flex:1;min-width:0}.auth-provider-info strong{font-weight:500;color:var(--text)}.auth-provider-icon-slot{display:inline-flex;align-items:center;justify-content:center;inline-size:calc(var(--space-md) + var(--space-xs) * 2);block-size:calc(var(--space-md) + var(--space-xs) * 2);flex-shrink:0}.auth-provider-icon-slot .provider-icon{display:inline-flex}.auth-hint{display:block;padding:12px 4px 0;font-size:12px;color:var(--text-muted);border-top:1px solid var(--border);margin-top:8px}.auth-apikey-section{display:flex;flex-direction:column;gap:var(--space-xs);align-items:flex-end;flex-shrink:0}.auth-apikey-input-row{display:flex;gap:6px;align-items:center}.auth-apikey-input{background:var(--bg-input);border:1px solid var(--border);border-radius:6px;color:var(--text);padding:6px 10px;font-size:13px;width:180px;font-family:monospace}.auth-apikey-input:focus{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring)}.auth-apikey-input:disabled{opacity:.6}.auth-apikey-progress{font-size:calc(var(--space-sm) + var(--space-xs) * .75);color:var(--text-muted);padding-right:4px}.auth-apikey-error{font-size:11px;color:var(--color-error);padding-right:4px}.auth-provider-actions-row{display:inline-flex;align-items:center;gap:var(--space-sm)}.auth-key-hint{font-family:var(--font-mono);font-size:12px;color:var(--text-muted);display:inline-block;margin-top:var(--space-xs);user-select:none}.settings-lane-badge{display:inline-flex;align-items:center;padding:2px 8px;border-radius:10px;font-size:11px;font-weight:500;white-space:nowrap}.settings-lane-badge--override{background-color:color-mix(in srgb,var(--color-accent) 20%,transparent);color:var(--color-accent)}.settings-lane-badge--inherited{background-color:color-mix(in srgb,var(--color-text-muted) 15%,transparent);color:var(--text-muted)}.settings-description{font-size:13px;color:var(--text-secondary);padding-inline:var(--space-xl);margin-block:0 var(--space-md);line-height:1.5}.settings-token-cap-row{display:flex;align-items:center;gap:var(--space-sm)}.settings-model-lane-label-row{display:flex;align-items:center;gap:var(--space-sm);margin-bottom:var(--space-xs)}.settings-model-lane-control-row{display:flex;align-items:center;gap:var(--space-sm)}.settings-model-lane-control-main{flex:1}.settings-summarization-actions{justify-content:flex-start}.settings-model-presets{display:flex;flex-direction:column;gap:var(--space-md)}.settings-preset-list{display:flex;flex-direction:column;gap:var(--space-sm)}.settings-preset-item{display:flex;align-items:flex-start;justify-content:space-between;gap:var(--space-md);padding:var(--space-md);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:var(--card)}.settings-preset-item-meta{display:flex;flex-direction:column;gap:var(--space-xs);min-width:0}.settings-preset-item-meta strong{color:var(--text);overflow-wrap:anywhere}.settings-preset-summary{font-size:12px;overflow-wrap:anywhere}.settings-preset-item-actions{display:flex;gap:var(--space-xs);flex-wrap:wrap;justify-content:flex-end}.settings-preset-actions{display:flex;justify-content:flex-start}.settings-preset-editor{display:flex;flex-direction:column;gap:var(--space-md);padding:var(--space-md);border:var(--btn-border-width) solid var(--border);border-radius:var(--radius-md);background:color-mix(in srgb,var(--surface) 85%,var(--card))}.settings-preset-editor-fields{display:flex;flex-direction:column;gap:var(--space-sm)}.settings-preset-editor .form-group{padding:0}.settings-preset-editor-actions{justify-content:flex-start;margin-top:0;padding:0}.settings-preset-auto-select{margin-top:var(--space-sm)}.settings-preset-size-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:var(--space-sm)}.settings-preset-size-row{padding:0}@media(max-width:768px){.settings-layout{flex-direction:column;min-height:0}.settings-mobile-section-picker{display:flex;flex-direction:column;gap:var(--space-xs);padding:var(--space-md) var(--space-lg);border-bottom:var(--btn-border-width) solid var(--border);background:var(--surface)}.settings-mobile-section-picker label{color:var(--text-muted);font-weight:600;text-transform:uppercase}.settings-mobile-section-picker select{width:100%}.settings-mobile-section-picker select:focus-visible{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring-strong)}.settings-sidebar{display:none}.settings-nav-item{display:flex;align-items:center;justify-content:center;gap:var(--space-xs);border-left:none;border-bottom:2px solid transparent;border-radius:var(--radius-md) var(--radius-md) 0 0;padding:calc(var(--space-xs) + var(--space-xs) / 2) var(--space-md);white-space:nowrap}.settings-nav-item:hover{border-left-color:transparent;border-bottom-color:var(--border)}.settings-nav-item.active{border-left-color:transparent;border-bottom-color:var(--todo)}.settings-group-header{display:none}.notification-provider-card{margin:0 var(--space-lg) var(--space-md)}.notification-provider-header{padding:var(--space-sm) var(--space-md)}.notification-provider-body{padding:var(--space-md)}.settings-scope-icon{margin-right:0}.settings-content{flex:1;min-height:0;overflow-x:hidden;overflow-y:auto}.settings-content .form-group small{overflow-wrap:break-word;word-break:break-all}.settings-content input,.settings-content select,.settings-content textarea{font-size:16px}.settings-section-heading{padding:var(--space-lg) var(--space-lg) var(--space-md);margin:0 0 var(--space-md)}.settings-plugins-subsection-toggle{display:flex;width:100%;padding:0 var(--space-lg)}.settings-plugins-subsection-btn{flex:1;min-height:36px}.settings-plugins-subsection-panel{padding-left:var(--space-lg);padding-right:var(--space-lg)}.form-group{padding:0 calc(var(--space-md) + var(--space-xs) / 2)}.settings-scope-banner{padding:var(--space-sm) var(--space-lg)}.memory-editor-frame{min-height:45vh}.memory-file-summary{grid-template-columns:1fr;margin:0 var(--space-lg) var(--space-md)}.memory-status-message{align-items:stretch;flex-direction:column}.memory-file-summary span{justify-content:flex-start}.memory-file-summary small{grid-column:auto}.settings-description{padding:0 var(--space-lg)}.settings-content .btn,.settings-preset-item-actions .btn{min-height:36px}.auth-provider-row{flex-wrap:wrap;padding:var(--space-md) calc(var(--space-md) + var(--space-xs) / 2);gap:var(--space-sm)}.auth-section-hint{margin:0 calc(var(--space-md) + var(--space-xs) / 2) var(--space-md);padding:calc(var(--space-sm) + var(--space-xs) / 2) calc(var(--space-md) + var(--space-xs) / 2)}.auth-provider-group{margin-bottom:var(--space-md)}.auth-group-label{padding:0 calc(var(--space-md) + var(--space-xs) / 2)}.auth-provider-card{margin:0 calc(var(--space-md) + var(--space-xs) / 2) var(--space-sm)}.auth-provider-header{flex-wrap:wrap;padding:calc(var(--space-sm) + var(--space-xs) / 2) calc(var(--space-md) + var(--space-xs) / 2);gap:10px}.auth-provider-header>div:not(.auth-provider-info):not(.auth-apikey-section){margin-left:auto}.auth-provider-actions-row{width:100%;justify-content:flex-end}.auth-provider-info{width:100%;flex-basis:100%}.auth-apikey-section{width:100%;flex-basis:100%;align-items:flex-end}.auth-apikey-input-row{width:100%;flex-wrap:wrap;justify-content:flex-end}.auth-apikey-input{flex:1;min-width:120px;width:auto}.auth-apikey-input-row .btn{flex-shrink:0;margin-left:auto}.auth-hint{padding:var(--space-md) calc(var(--space-md) + var(--space-xs) / 2) 0}.settings-model-presets{gap:var(--space-sm)}.settings-preset-item{flex-direction:column;align-items:stretch;padding:var(--space-sm) var(--space-md)}.settings-preset-item-actions{justify-content:flex-start}.settings-preset-editor{padding:var(--space-sm) var(--space-md)}.settings-preset-editor-actions{flex-wrap:wrap}.settings-preset-size-grid{grid-template-columns:1fr;gap:var(--space-xs)}.settings-node-routing-note{padding:var(--space-sm) var(--space-md);font-size:12px}}.settings-node-routing-note{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);padding:var(--space-md) var(--space-lg);margin-top:var(--space-sm);color:var(--text-muted);font-size:13px;line-height:1.5}.settings-node-status{display:inline-flex;align-items:center;gap:var(--space-xs);margin-top:var(--space-sm);font-size:12px;color:var(--text-muted)}.auth-advanced-disclosure{margin-top:var(--space-md);border:1px solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.auth-advanced-disclosure>summary{cursor:pointer;padding:var(--space-sm) var(--space-md)}.auth-advanced-content{display:flex;flex-direction:column;gap:var(--space-sm);padding:0 var(--space-md) var(--space-md)}.auth-custom-provider-item{display:flex;justify-content:space-between;align-items:center;gap:var(--space-sm)}.auth-custom-provider-actions{display:flex;gap:var(--space-sm)}@media(max-width:768px){.auth-custom-provider-item{flex-direction:column;align-items:flex-start}}