@runfusion/fusion 0.13.0 → 0.14.1

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 (72) hide show
  1. package/README.md +13 -0
  2. package/dist/bin.js +1332 -528
  3. package/dist/client/assets/AgentDetailView-B3KAsP2O.js +18 -0
  4. package/dist/client/assets/{AgentsView-Dvf_xUkx.js → AgentsView-DoXb_amw.js} +4 -4
  5. package/dist/client/assets/ChatView-BJ2c7wvd.js +1 -0
  6. package/dist/client/assets/{DevServerView-C2qTJch7.js → DevServerView-DbgM4tlT.js} +1 -1
  7. package/dist/client/assets/{DirectoryPicker-DRfhg9zz.js → DirectoryPicker-DfmtfMiu.js} +1 -1
  8. package/dist/client/assets/{DocumentsView-j8ic1xUw.js → DocumentsView-_-Efkx_W.js} +1 -1
  9. package/dist/client/assets/{InsightsView-CpAz3o0i.js → InsightsView-DUjcfW53.js} +1 -1
  10. package/dist/client/assets/{MemoryView-BcQsi_JK.js → MemoryView-DxMPBb0q.js} +1 -1
  11. package/dist/client/assets/{NodesView-Bo_Yhr4N.js → NodesView-BEBTI15s.js} +1 -1
  12. package/dist/client/assets/PiExtensionsManager-BpMYhHH_.js +11 -0
  13. package/dist/client/assets/PluginManager-CPv7yQd3.js +1 -0
  14. package/dist/client/assets/PluginManager-DA_T0GHn.css +1 -0
  15. package/dist/client/assets/{ResearchView-CLyyqAWE.js → ResearchView-BrFvdyXT.js} +1 -1
  16. package/dist/client/assets/{RoadmapsView-tG7IdOoc.js → RoadmapsView-BDjLrtcj.js} +1 -1
  17. package/dist/client/assets/SettingsModal-Cd-QGB0C.js +31 -0
  18. package/dist/client/assets/{SettingsModal-CXUGeZ0_.js → SettingsModal-CxDxiTRy.js} +1 -1
  19. package/dist/client/assets/SettingsModal-D_AFkDJa.css +1 -0
  20. package/dist/client/assets/{SetupWizardModal-BMJL6eNR.js → SetupWizardModal-DFUA4X3z.js} +1 -1
  21. package/dist/client/assets/{SkillMultiselect-ILMft-Kz.js → SkillMultiselect-BUWe5ujb.js} +1 -1
  22. package/dist/client/assets/{SkillsView-x4_YwBz6.js → SkillsView-RAkqGX3y.js} +1 -1
  23. package/dist/client/assets/TodoView-Ceb0wrg1.js +6 -0
  24. package/dist/client/assets/TodoView-SeO9o7km.css +1 -0
  25. package/dist/client/assets/{folder-open-DDdJt8aE.js → folder-open-DcM-Vd6r.js} +1 -1
  26. package/dist/client/assets/index-C1prPuSl.css +1 -0
  27. package/dist/client/assets/index-DH3aprf6.js +661 -0
  28. package/dist/client/assets/{list-checks-DFxQ9biT.js → list-checks-ByGHVQpZ.js} +1 -1
  29. package/dist/client/assets/{star-BKs1bgJN.js → star-DlEYI8GL.js} +1 -1
  30. package/dist/client/assets/{upload-Bb5Pidne.js → upload-DKshabz-.js} +1 -1
  31. package/dist/client/assets/{users-BImNn91Q.js → users-X6tYPPBV.js} +1 -1
  32. package/dist/client/index.html +2 -2
  33. package/dist/client/sw.js +6 -0
  34. package/dist/client/version.json +1 -1
  35. package/dist/droid-cli/index.ts +127 -0
  36. package/dist/droid-cli/package.json +37 -0
  37. package/dist/droid-cli/src/__tests__/control-handler.test.ts +164 -0
  38. package/dist/droid-cli/src/__tests__/event-bridge.test.ts +1318 -0
  39. package/dist/droid-cli/src/__tests__/mcp-config.test.ts +310 -0
  40. package/dist/droid-cli/src/__tests__/process-manager.test.ts +818 -0
  41. package/dist/droid-cli/src/__tests__/prompt-builder.test.ts +1206 -0
  42. package/dist/droid-cli/src/__tests__/provider.test.ts +1894 -0
  43. package/dist/droid-cli/src/__tests__/setup-test-isolation.test.ts +32 -0
  44. package/dist/droid-cli/src/__tests__/setup-test-isolation.ts +14 -0
  45. package/dist/droid-cli/src/__tests__/stream-parser.test.ts +188 -0
  46. package/dist/droid-cli/src/__tests__/thinking-config.test.ts +141 -0
  47. package/dist/droid-cli/src/__tests__/tool-mapping.test.ts +253 -0
  48. package/dist/droid-cli/src/control-handler.ts +82 -0
  49. package/dist/droid-cli/src/event-bridge.ts +397 -0
  50. package/dist/droid-cli/src/mcp-config.ts +144 -0
  51. package/dist/droid-cli/src/mcp-schema-server.cjs +49 -0
  52. package/dist/droid-cli/src/process-manager.ts +358 -0
  53. package/dist/droid-cli/src/prompt-builder.ts +629 -0
  54. package/dist/droid-cli/src/provider.ts +447 -0
  55. package/dist/droid-cli/src/stream-parser.ts +37 -0
  56. package/dist/droid-cli/src/thinking-config.ts +83 -0
  57. package/dist/droid-cli/src/tool-mapping.ts +147 -0
  58. package/dist/droid-cli/src/types.ts +87 -0
  59. package/dist/extension.js +555 -125
  60. package/dist/pi-claude-cli/package.json +1 -1
  61. package/package.json +2 -1
  62. package/dist/client/assets/AgentDetailView-B7j297GT.js +0 -18
  63. package/dist/client/assets/ChatView-BgUt38ty.js +0 -1
  64. package/dist/client/assets/PiExtensionsManager-DHt2zFg8.js +0 -11
  65. package/dist/client/assets/PluginManager-BQhBHWrB.js +0 -1
  66. package/dist/client/assets/PluginManager-jyNkJZSz.css +0 -1
  67. package/dist/client/assets/SettingsModal-9HS8MnmW.css +0 -1
  68. package/dist/client/assets/SettingsModal-UziTDnLh.js +0 -31
  69. package/dist/client/assets/TodoView-BBYcMbXE.js +0 -6
  70. package/dist/client/assets/TodoView-C1g65hJo.css +0 -1
  71. package/dist/client/assets/index-B15xwijw.css +0 -1
  72. package/dist/client/assets/index-DmSs2FGE.js +0 -661
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-B7j297GT.js","assets/vendor-react-K0fH_qHe.js","assets/index-DmSs2FGE.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-B15xwijw.css","assets/star-BKs1bgJN.js","assets/SkillMultiselect-ILMft-Kz.js","assets/SkillMultiselect-DDHJnrkn.css","assets/list-checks-DFxQ9biT.js","assets/AgentDetailView-B5tq9ius.css"])))=>i.map(i=>d[i]);
2
- import{c as Ye,s as yt,A as Te,r as Je,F as Xe,f as wt,C as De,Z as jt,B as et,g as Ze,a as gt,b as Ve,d as kt,e as Nt,h as Ct,i as It,u as nt,P as St,j as At,k as Et,l as Tt,m as Mt,n as Pt,o as Rt,p as _t,q as $t,t as at,G as Ft,S as Lt,L as We,T as Ue,R as Oe,X as st,v as zt,w as Dt,x as Ot,y as Ht,z as be,D as Ke,E as qt,H as Vt,I as Wt,J as Ut,K as Kt,M as Bt,N as ht,O as Gt,Q as $e,U as it,V as Qt,W as Jt,Y as Xt,_ as Fe,$ as Zt,a0 as rt,a1 as Yt,a2 as en,a3 as tn,a4 as nn}from"./index-DmSs2FGE.js";import{r as a,j as e,a as an}from"./vendor-react-K0fH_qHe.js";import{S as sn}from"./SkillMultiselect-ILMft-Kz.js";import{U as pt}from"./upload-Bb5Pidne.js";import{F as rn}from"./folder-open-DDdJt8aE.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-B3KAsP2O.js","assets/vendor-react-K0fH_qHe.js","assets/index-DH3aprf6.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-C1prPuSl.css","assets/star-DlEYI8GL.js","assets/SkillMultiselect-BUWe5ujb.js","assets/SkillMultiselect-DDHJnrkn.css","assets/list-checks-ByGHVQpZ.js","assets/AgentDetailView-B5tq9ius.css"])))=>i.map(i=>d[i]);
2
+ import{c as Ye,s as yt,A as Te,r as Je,F as Xe,f as wt,C as De,Z as jt,B as et,g as Ze,a as gt,b as Ve,d as kt,e as Nt,h as Ct,i as It,u as nt,P as St,j as At,k as Et,l as Tt,m as Mt,n as Pt,o as Rt,p as _t,q as $t,t as at,G as Ft,S as Lt,L as We,T as Ue,R as Oe,X as st,v as zt,w as Dt,x as Ot,y as Ht,z as be,D as Ke,E as qt,H as Vt,I as Wt,J as Ut,K as Kt,M as Bt,N as ht,O as Gt,Q as $e,U as it,V as Qt,W as Jt,Y as Xt,_ as Fe,$ as Zt,a0 as rt,a1 as Yt,a2 as en,a3 as tn,a4 as nn}from"./index-DH3aprf6.js";import{r as a,j as e,a as an}from"./vendor-react-K0fH_qHe.js";import{S as sn}from"./SkillMultiselect-BUWe5ujb.js";import{U as pt}from"./upload-DKshabz-.js";import{F as rn}from"./folder-open-DcM-Vd6r.js";import"./vendor-xterm-DzcZoU0P.js";/**
3
3
  * @license lucide-react v1.7.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -512,11 +512,11 @@ Include relevant context files for the executor to read first.`},{id:"reviewer",
512
512
  Verify error handling is explicit and informative, not silent failures.
513
513
  Ensure new code follows existing patterns and conventions in the codebase.
514
514
  Look for missing tests on new logic paths, especially edge cases.
515
- Flag performance concerns only when they have measurable impact.`}],ut=[{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=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Wn({isOpen:s,onClose:l,onCreated:y,projectId:g,prefillDraft:c=null}){const[o,r]=a.useState(0),[m,u]=a.useState("presets"),[p,f]=a.useState(""),[b,w]=a.useState(""),[C,T]=a.useState(""),[M,S]=a.useState("custom"),[j,A]=a.useState(""),[v,E]=a.useState(""),[_,P]=a.useState(""),[D,Q]=a.useState(""),[q,se]=a.useState(""),[F,h]=a.useState(""),[I,J]=a.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[V,X]=a.useState(null),[ie,ve]=a.useState([]),[W,ne]=a.useState(!1),[ke,L]=a.useState(null),[oe,U]=a.useState(!1),[ce,ae]=a.useState([]),[K,ue]=a.useState(!1),[me,ge]=a.useState([]),[H,xe]=a.useState([]),[Z,he]=a.useState("model"),[re,ye]=a.useState(""),[O,z]=a.useState([]),[de,we]=a.useState(!1),[Ne,le]=a.useState([]),[Me,Ie]=a.useState(!1);a.useEffect(()=>{s&&(ue(!0),Ct().then(t=>{ae(t.models),ge(t.favoriteProviders),xe(t.favoriteModels)}).catch(()=>{}).finally(()=>ue(!1)))},[s]),a.useEffect(()=>{s&&(Ie(!0),le([]),It(void 0,g).then(t=>{le(t)}).catch(()=>{le([])}).finally(()=>Ie(!1)))},[s,g]),a.useEffect(()=>{if(!s)return;const t=At;if(typeof t!="function"){z([]),we(!1);return}we(!0),z([]),t(g).then(d=>{z(d)}).catch(()=>{z([])}).finally(()=>we(!1))},[s,g]);const i=I.model.includes("/")?I.model:"",x=a.useCallback(t=>{const d=mt.has(t.role)?t.role:"custom";f(t.title),w(t.description),T(t.icon),S(d),P(t.systemPrompt),J(k=>({...k,thinkingLevel:t.thinkingLevel,maxTurns:t.maxTurns})),U(!1),r(1)},[]),R=a.useCallback(t=>{J(d=>({...d,model:t}))},[]),Y=a.useCallback(t=>{he(t),t==="model"&&ye("")},[]),B=a.useCallback(async t=>{const d=me,$=d.includes(t)?d.filter(ee=>ee!==t):[t,...d];ge($);try{await nt({favoriteProviders:$,favoriteModels:H})}catch{ge(d)}},[me,H]),G=a.useCallback(async t=>{const d=H,$=d.includes(t)?d.filter(ee=>ee!==t):[t,...d];xe($);try{await nt({favoriteProviders:me,favoriteModels:$})}catch{xe(d)}},[me,H]),Pe=a.useCallback(t=>{X(t.id),f(t.name),T(t.icon),w(t.description??t.title),S(t.role),se(t.soul??""),P(t.instructionsText??""),r(1)},[]);if(a.useEffect(()=>{!s||!c||(r(1),u("custom"),f(c.name??""),w(c.title??""),T(c.icon??""),S(mt.has(c.role)?c.role:"custom"),A(c.reportsTo??""),P(c.instructionsText??""),se(c.soul??""),h(c.memory??""),ve(c.skills??[]),J(t=>({...t,thinkingLevel:c.thinkingLevel??t.thinkingLevel,maxTurns:c.maxTurns??t.maxTurns})))},[s,c]),!s)return null;const pe=()=>{r(0),u("presets"),f(""),w(""),T(""),S("custom"),A(""),E(""),P(""),Q(""),se(""),h(""),J({model:"",thinkingLevel:"off",maxTurns:1e3}),he("model"),ye(""),X(null),ve([]),L(null),U(!1),l()},Se=async()=>{if(p.trim()){ne(!0),L(null);try{const t={};Z==="runtime"?re.trim()&&(t.runtimeHint=re.trim()):I.model.trim()&&(t.model=I.model.trim()),I.thinkingLevel!=="off"&&(t.thinkingLevel=I.thinkingLevel),I.maxTurns!==1e3&&(t.maxTurns=I.maxTurns),await Tt({name:p.trim(),role:M,...b.trim()?{title:b.trim()}:{},...C.trim()?{icon:C.trim()}:{},...j.trim()?{reportsTo:j.trim()}:{},...v.trim()?{instructionsPath:v.trim()}:{},..._.trim()?{instructionsText:_.trim()}:{},...D.trim()?{heartbeatProcedurePath:D.trim()}:{},...q.trim()?{soul:q.trim()}:{},...F.trim()?{memory:F.trim()}:{},...Object.keys(t).length>0?{runtimeConfig:t}:{},...ie.length>0?{metadata:{skills:ie}}:{}},g),pe(),y()}catch(t){L(t instanceof Error?t.message:"Failed to create agent")}finally{ne(!1)}}},Ae=ut.find(t=>t.value===M),fe=j.trim(),Re=fe?Ne.find(t=>t.id===fe):void 0,je=re?O.find(t=>t.runtimeId===re):void 0,n=t=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:t,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":t,children:[e.jsxs("label",{className:`agent-runtime-mode-option${Z==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:t,value:"model",checked:Z==="model",onChange:()=>Y("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${Z==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:t,value:"runtime",checked:Z==="runtime",onChange:()=>Y("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),Z==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),K?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(Et,{id:"agent-model",label:"Model",value:i,onChange:R,models:ce,placeholder:"Select a model…",favoriteProviders:me,onToggleFavorite:B,favoriteModels:H,onToggleModelFavorite:G})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),de?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:re,onChange:d=>ye(d.target.value),children:[e.jsx("option",{value:"",children:O.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),O.map(d=>e.jsx("option",{value:d.runtimeId,children:d.description?`${d.name} — ${d.description}`:d.name},`${d.pluginId}:${d.runtimeId}`))]})]})]});return an.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:t=>{t.target===t.currentTarget&&pe()},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:pe,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(t=>e.jsx("div",{className:`agent-dialog-step${t===o?" active":t<o?" completed":""}`,"aria-label":`Step ${t+1}`},t))}),e.jsxs("div",{className:"agent-dialog-body",children:[o===0&&e.jsxs("div",{children:[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":m==="presets",tabIndex:m==="presets"?0:-1,className:`agent-dialog-tab${m==="presets"?" active":""}`,onClick:()=>u("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":m==="custom",tabIndex:m==="custom"?0:-1,className:`agent-dialog-tab${m==="custom"?" active":""}`,onClick:()=>u("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),m==="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:bt.map(t=>e.jsxs("button",{type:"button",className:`agent-preset-card${V===t.id?" selected":""}`,"data-testid":`preset-${t.id}`,onClick:()=>Pe(t),title:t.title,children:[e.jsx("span",{className:"agent-preset-icon",children:t.icon}),e.jsx("span",{className:"agent-preset-name",children:t.name}),e.jsx("span",{className:"agent-preset-role",children:t.role}),t.description&&e.jsx("span",{className:"agent-preset-description",children:t.description})]},t.id))})]})}),m==="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 ",!V&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:p,onChange:t=>f(t.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:b,onChange:t=>w(t.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:C,onChange:t=>T(t.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:ut.map(t=>e.jsxs("button",{type:"button",className:`agent-role-option${M===t.value?" selected":""}`,onClick:()=>S(t.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:t.icon}),e.jsx("span",{className:"agent-role-option-label",children:t.label})]},t.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:j,onChange:t=>A(t.target.value),disabled:Me,children:[e.jsx("option",{value:"",children:"No manager"}),Ne.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (",t.id,")"]},t.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:q,onChange:t=>se(t.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:F,onChange:t=>h(t.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:v,onChange:t=>E(t.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/my-agent/HEARTBEAT.md",value:D,onChange:t=>Q(t.target.value)}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-field-hint",children:"Path to the agent's heartbeat markdown file, typically .fusion/agents/<agent-id>/HEARTBEAT.md."})]}),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:_,onChange:t=>P(t.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),n("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:()=>U(!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"})]})]})]}),o===1&&e.jsxs("div",{children:[n("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:I.thinkingLevel,onChange:t=>J(d=>({...d,thinkingLevel:t.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:I.maxTurns,onChange:t=>J(d=>({...d,maxTurns:Math.max(1,parseInt(t.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(sn,{id:"agent-skills",label:"Skills",value:ie,onChange:ve,projectId:g}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),o===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:[C&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:C}),p]})]}),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:b,onChange:t=>w(t.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:[Ae?.icon," ",Ae?.label]})]}),fe&&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:Re?`${Re.name} (${Re.id})`:fe})]}),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:q,onChange:t=>se(t.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/my-agent/HEARTBEAT.md",value:D,onChange:t=>Q(t.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:v,onChange:t=>E(t.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:_,onChange:t=>P(t.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:Z==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:Z==="runtime"?je?je.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):i?e.jsxs(e.Fragment,{children:[e.jsx(St,{provider:i.split("/")[0],size:"sm"})," ",(()=>{const t=i.indexOf("/"),d=i.slice(0,t),k=i.slice(t+1);return ce.find(ee=>ee.provider===d&&ee.id===k)?.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:I.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:I.maxTurns})]}),ie.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:[ie.length," skill",ie.length!==1?"s":""," selected"]})]})]}),ke&&e.jsx("p",{className:"agent-dialog-error",children:ke})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[o>0&&e.jsx("button",{className:"btn",onClick:()=>r(t=>t-1),disabled:W,children:"Back"}),e.jsx("button",{className:"btn",onClick:pe,disabled:W,children:"Cancel"}),o<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>r(t=>t+1),disabled:o===0&&!p.trim()&&!V,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void Se(),disabled:W||!p.trim(),children:W?"Creating...":"Create"})]})]}),e.jsx(kn,{isOpen:oe,onClose:()=>U(!1),onGenerated:x,projectId:g})]}),document.body)}function Un({isOpen:s,onClose:l,onUseDraft:y,projectId:g,existingAgents:c}){const[o,r]=a.useState("initial"),[m,u]=a.useState(""),[p,f]=a.useState(null),[b,w]=a.useState(""),[C,T]=a.useState("answer"),[M,S]=a.useState(""),[j,A]=a.useState(null),[v,E]=a.useState(null),[_,P]=a.useState([]),D=a.useCallback(()=>{r("initial"),u(""),f(null),w(""),T("answer"),S(""),A(null),E(null),P([])},[]),Q=a.useMemo(()=>bt.map(h=>({id:h.id,label:h.name,description:h.description})),[]);a.useEffect(()=>{if(!p)return;const h=Mt(p,g,{onThinking:I=>{P(J=>{const V=[...J],X=V[V.length-1];return X&&!X.question?(V[V.length-1]={...X,thinkingOutput:`${X.thinkingOutput??""}${I}`},V):[...V,{response:{},thinkingOutput:I}]})},onQuestion:I=>{w(I.question),T(I.id),r("question")},onSummary:I=>{A(I),r("summary")},onError:I=>{E(I),r("error")}});return()=>h.close()},[p,g]);const q=async()=>{try{p&&await Rt(p,g)}catch{}finally{D(),l()}};if(a.useEffect(()=>{s||D()},[s,D]),!s)return null;const se=async()=>{r("loading"),E(null);try{const h=await _t(m,{existingAgents:c.map(I=>({id:I.id,name:I.name,role:I.role})),templates:Q},g);f(h.sessionId)}catch(h){E(h.message),r("error")}},F=async()=>{if(p){r("loading"),E(null);try{const h={[C]:M};P(I=>[...I,{question:{id:C,type:"text",question:b},response:h}]),await $t(p,h,g),S("")}catch(h){E(h.message),r("error")}}};return e.jsx("div",{className:"modal-overlay open",role:"presentation",children:e.jsxs("div",{className:"modal modal-lg experimental-agent-onboarding-modal",role:"dialog","aria-modal":"true","aria-label":"Experimental agent onboarding",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Experimental Agent Onboarding"}),e.jsx("button",{className:"modal-close",onClick:()=>void q(),"aria-label":"Close",children:"×"})]}),_.length>0&&e.jsx(Pt,{entries:_}),o==="initial"&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-onboarding-intent",children:"What should this new agent own?"}),e.jsx("textarea",{id:"agent-onboarding-intent",className:"input experimental-agent-onboarding-modal__textarea",value:m,onChange:h=>u(h.target.value)}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void q(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",disabled:!m.trim(),onClick:()=>void se(),children:"Start onboarding"})]})]}),(o==="loading"||o==="question")&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-onboarding-answer",children:b||"Thinking..."}),e.jsx("textarea",{id:"agent-onboarding-answer",className:"input experimental-agent-onboarding-modal__textarea",value:M,onChange:h=>S(h.target.value)}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void q(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",disabled:o==="loading"||!M.trim(),onClick:()=>void F(),children:"Continue"})]})]}),o==="summary"&&j&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:"Draft ready for review"}),e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary card",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Name:"})," ",j.name]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Role:"})," ",j.role]}),j.templateId&&e.jsxs("p",{children:[e.jsx("strong",{children:"Template:"})," ",j.templateId]}),j.patternAgentId&&e.jsxs("p",{children:[e.jsx("strong",{children:"Pattern agent:"})," ",j.patternAgentId]}),j.rationale&&e.jsxs("p",{children:[e.jsx("strong",{children:"Why:"})," ",j.rationale]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void q(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",onClick:()=>y(j),children:"Continue to agent form"})]})]}),o==="error"&&v&&e.jsxs("div",{className:"form-group",children:[e.jsx("div",{className:"form-error",children:v}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{className:"btn",onClick:()=>void q(),children:"Close"})})]})]})})}function Kn(s){const l=s.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!l)throw new Error("Missing YAML frontmatter delimiters (---)");const y=l[1].split(/\r?\n/),g=l[2]??"",c={name:""},o=[];let r=!1;for(const m of y){const p=m.trimEnd().trim();if(!p)continue;if(p.startsWith("skills:")){r=!0;continue}if(r&&p.startsWith("- ")){o.push(p.slice(2).trim());continue}r=!1;const[f,...b]=p.split(":"),C=b.join(":").trim().replace(/^['"]|['"]$/g,"");f==="name"&&(c.name=C),f==="title"&&(c.title=C),f==="icon"&&(c.icon=C),f==="role"&&(c.role=C),f==="reportsTo"&&(c.reportsTo=C)}if(!c.name)throw new Error("Missing required field: name");return o.length>0&&(c.skills=o),g.trim().length>0&&(c.instructionBody=g),c}function Bn({isOpen:s,onClose:l,onImported:y,projectId:g}){const[c,o]=a.useState("input"),[r,m]=a.useState("paste"),[u,p]=a.useState(""),[f,b]=a.useState([]),[w,C]=a.useState("Unknown"),[T,M]=a.useState([]),[S,j]=a.useState([]),[A,v]=a.useState([]),[E,_]=a.useState([]),[P,D]=a.useState(!1),[Q,q]=a.useState(!1),[se,F]=a.useState(null),[h,I]=a.useState(null),[J,V]=a.useState(null),X=a.useRef(null),ie=a.useRef(null),[ve,W]=a.useState([]),[ne,ke]=a.useState(""),[L,oe]=a.useState(null),[U,ce]=a.useState(!1),[ae,K]=a.useState(null),ue=a.useRef(!1);a.useEffect(()=>{r==="browse"&&!ue.current&&!U&&(ue.current=!0,ce(!0),K(null),at().then(i=>{i.error?K(i.error):i.companies.length>0?W(i.companies):K("No companies available")}).catch(i=>{K(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{ce(!1)}))},[r,U]);const me=a.useCallback(()=>{ue.current=!0,K(null),W([]),oe(null),ce(!0),at().then(i=>{i.error?K(i.error):i.companies.length>0?W(i.companies):K("No companies available")}).catch(i=>{K(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{ce(!1)})},[]),ge=a.useCallback(()=>{o("input"),m("paste"),p(""),b([]),C("Unknown"),M([]),j([]),v([]),_([]),D(!1),q(!1),F(null),I(null),V(null),W([]),ke(""),oe(null),ce(!1),K(null),ue.current=!1},[]),H=a.useCallback(()=>{ge(),l()},[ge,l]),xe=a.useCallback(i=>{const x=i.target.files?.[0];if(!x)return;const R=new FileReader;R.onload=Y=>{const B=Y.target?.result;m("file"),b([]),p(B),F(null)},R.onerror=()=>{F("Failed to read file")},R.readAsText(x),i.target.value=""},[]),Z=a.useCallback(async i=>{const x=Array.from(i.target.files??[]);if(x.length!==0)try{const R=x.filter(B=>(B.webkitRelativePath||B.name).toLowerCase().endsWith("agents.md")).sort((B,G)=>{const Pe=B.webkitRelativePath||B.name,pe=G.webkitRelativePath||G.name;return Pe.localeCompare(pe)});if(R.length===0){F("Selected directory has no AGENTS.md files");return}const Y=[];for(const B of R){const G=await B.text();Y.push(Kn(G))}m("directory"),b(Y),p(""),F(null)}catch{F("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function he(i){if(!g)return`/api${i}`;const x=i.includes("?")?"&":"?";return`/api${i}${x}projectId=${encodeURIComponent(g)}`}const re=a.useCallback(async()=>{if(r==="directory"&&f.length===0){F("Please select a directory containing AGENTS.md files");return}if(r==="browse"&&!L){F("Please select a company from the catalog");return}if(r!=="directory"&&r!=="browse"&&!u.trim()){F("Please provide manifest content");return}D(!0),F(null);try{let i;r==="directory"?i={agents:f,dryRun:!0}:r==="browse"&&L?i={importSource:"companies.sh",companySlug:L.slug,dryRun:!0}:i={manifest:u,dryRun:!0};const x=await fetch(he("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!x.ok){const G=await x.json();throw new Error(G.error??`Parse failed (${x.status})`)}const R=await x.json(),Y=R.agents&&R.agents.length>0?R.agents:R.created.map(G=>({name:G,role:"custom"})),B=Array.isArray(R.skills)?R.skills:[];C(R.companyName??"Unknown"),M(Y),j(B),v(Y.map(G=>G.name)),_(B.map(G=>G.name)),o("preview")}catch(i){F(i instanceof Error?i.message:"Failed to parse manifest")}finally{D(!1)}},[r,f,u,L,g]),ye=a.useCallback(async()=>{q(!0),V(null);try{let i;r==="directory"?i={agents:f,skipExisting:!0,selectedAgents:A,selectedSkills:E}:r==="browse"&&L?i={importSource:"companies.sh",companySlug:L.slug,skipExisting:!0,selectedAgents:A,selectedSkills:E}:i={manifest:u,skipExisting:!0,selectedAgents:A,selectedSkills:E};const x=await fetch(he("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!x.ok){const Y=await x.json();throw new Error(Y.error??`Import failed (${x.status})`)}const R=await x.json();I(R),o("result"),y()}catch(i){V(i instanceof Error?i.message:"Failed to import agents")}finally{q(!1)}},[r,f,u,L,A,E,g,y]),O=A.length,z=E.length,de=`${O} Agent${O!==1?"s":""}`,we=`${z} Skill${z!==1?"s":""}`,Ne=O>0&&z>0?`${de} + ${we}`:z>0?we:de,le=O>0&&z>0?`Importing ${O} agent${O!==1?"s":""} and ${z} skill${z!==1?"s":""}...`:z>0?`Importing ${z} skill${z!==1?"s":""}...`:`Importing ${O} agent${O!==1?"s":""}...`,Me=i=>{v(x=>x.includes(i)?x.filter(R=>R!==i):[...x,i])},Ie=i=>{_(x=>x.includes(i)?x.filter(R=>R!==i):[...x,i])};return s?e.jsx("div",{className:"agent-dialog-overlay",onClick:i=>{i.target===i.currentTarget&&H()},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:H,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[c==="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:X,type:"file",accept:".md,.txt",onChange:xe,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:ie,type:"file",webkitdirectory:"",multiple:!0,onChange:Z,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>X.current?.click(),children:[e.jsx(pt,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>ie.current?.click(),children:[e.jsx(rn,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{m("browse"),b([]),p(""),oe(null),F(null)},children:[e.jsx(Ft,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),r==="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(Lt,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:ne,onChange:i=>ke(i.target.value),"aria-label":"Search companies"})]}),L&&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:L.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>oe(null),children:"Change"})]})]}),U&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(We,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),ae&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(Ue,{size:16}),e.jsx("span",{children:ae}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:me,children:[e.jsx(Oe,{size:14}),"Retry"]})]}),!U&&!ae&&e.jsxs("div",{className:"agent-import-browse-list",children:[ve.filter(i=>ne===""||i.name.toLowerCase().includes(ne.toLowerCase())||(i.tagline?.toLowerCase().includes(ne.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${L?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>oe(i),role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&oe(i)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:i.name}),i.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[i.installs.toLocaleString()," installs"]})]}),i.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:i.tagline}),i.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:i.repo})]},i.slug)),ve.filter(i=>ne===""||i.name.toLowerCase().includes(ne.toLowerCase())||(i.tagline?.toLowerCase().includes(ne.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:ne?"No companies match your search":"No companies available"})]})]}),r!=="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:`---
515
+ Flag performance concerns only when they have measurable impact.`}],ut=[{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=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Wn({isOpen:s,onClose:l,onCreated:y,projectId:g,prefillDraft:c=null}){const[o,r]=a.useState(0),[m,u]=a.useState("presets"),[p,f]=a.useState(""),[b,w]=a.useState(""),[C,T]=a.useState(""),[M,S]=a.useState("custom"),[j,A]=a.useState(""),[v,E]=a.useState(""),[_,P]=a.useState(""),[D,Q]=a.useState(""),[q,se]=a.useState(""),[F,h]=a.useState(""),[I,J]=a.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[V,X]=a.useState(null),[ie,ve]=a.useState([]),[W,ne]=a.useState(!1),[ke,L]=a.useState(null),[oe,U]=a.useState(!1),[ce,ae]=a.useState([]),[K,ue]=a.useState(!1),[me,ge]=a.useState([]),[H,xe]=a.useState([]),[Z,he]=a.useState("model"),[re,ye]=a.useState(""),[O,z]=a.useState([]),[de,we]=a.useState(!1),[Ne,le]=a.useState([]),[Me,Ie]=a.useState(!1);a.useEffect(()=>{s&&(ue(!0),Ct().then(t=>{ae(t.models),ge(t.favoriteProviders),xe(t.favoriteModels)}).catch(()=>{}).finally(()=>ue(!1)))},[s]),a.useEffect(()=>{s&&(Ie(!0),le([]),It(void 0,g).then(t=>{le(t)}).catch(()=>{le([])}).finally(()=>Ie(!1)))},[s,g]),a.useEffect(()=>{if(!s)return;const t=At;if(typeof t!="function"){z([]),we(!1);return}we(!0),z([]),t(g).then(d=>{z(d)}).catch(()=>{z([])}).finally(()=>we(!1))},[s,g]);const i=I.model.includes("/")?I.model:"",x=a.useCallback(t=>{const d=mt.has(t.role)?t.role:"custom";f(t.title),w(t.description),T(t.icon),S(d),P(t.systemPrompt),J(k=>({...k,thinkingLevel:t.thinkingLevel,maxTurns:t.maxTurns})),U(!1),r(1)},[]),R=a.useCallback(t=>{J(d=>({...d,model:t}))},[]),Y=a.useCallback(t=>{he(t),t==="model"&&ye("")},[]),B=a.useCallback(async t=>{const d=me,$=d.includes(t)?d.filter(ee=>ee!==t):[t,...d];ge($);try{await nt({favoriteProviders:$,favoriteModels:H})}catch{ge(d)}},[me,H]),G=a.useCallback(async t=>{const d=H,$=d.includes(t)?d.filter(ee=>ee!==t):[t,...d];xe($);try{await nt({favoriteProviders:me,favoriteModels:$})}catch{xe(d)}},[me,H]),Pe=a.useCallback(t=>{X(t.id),f(t.name),T(t.icon),w(t.description??t.title),S(t.role),se(t.soul??""),P(t.instructionsText??""),r(1)},[]);if(a.useEffect(()=>{!s||!c||(r(1),u("custom"),f(c.name??""),w(c.title??""),T(c.icon??""),S(mt.has(c.role)?c.role:"custom"),A(c.reportsTo??""),P(c.instructionsText??""),se(c.soul??""),h(c.memory??""),ve(c.skills??[]),J(t=>({...t,thinkingLevel:c.thinkingLevel??t.thinkingLevel,maxTurns:c.maxTurns??t.maxTurns})))},[s,c]),!s)return null;const pe=()=>{r(0),u("presets"),f(""),w(""),T(""),S("custom"),A(""),E(""),P(""),Q(""),se(""),h(""),J({model:"",thinkingLevel:"off",maxTurns:1e3}),he("model"),ye(""),X(null),ve([]),L(null),U(!1),l()},Se=async()=>{if(p.trim()){ne(!0),L(null);try{const t={};Z==="runtime"?re.trim()&&(t.runtimeHint=re.trim()):I.model.trim()&&(t.model=I.model.trim()),I.thinkingLevel!=="off"&&(t.thinkingLevel=I.thinkingLevel),I.maxTurns!==1e3&&(t.maxTurns=I.maxTurns),await Tt({name:p.trim(),role:M,...b.trim()?{title:b.trim()}:{},...C.trim()?{icon:C.trim()}:{},...j.trim()?{reportsTo:j.trim()}:{},...v.trim()?{instructionsPath:v.trim()}:{},..._.trim()?{instructionsText:_.trim()}:{},...D.trim()?{heartbeatProcedurePath:D.trim()}:{},...q.trim()?{soul:q.trim()}:{},...F.trim()?{memory:F.trim()}:{},...Object.keys(t).length>0?{runtimeConfig:t}:{},...ie.length>0?{metadata:{skills:ie}}:{}},g),pe(),y()}catch(t){L(t instanceof Error?t.message:"Failed to create agent")}finally{ne(!1)}}},Ae=ut.find(t=>t.value===M),fe=j.trim(),Re=fe?Ne.find(t=>t.id===fe):void 0,je=re?O.find(t=>t.runtimeId===re):void 0,n=t=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:t,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":t,children:[e.jsxs("label",{className:`agent-runtime-mode-option${Z==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:t,value:"model",checked:Z==="model",onChange:()=>Y("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${Z==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:t,value:"runtime",checked:Z==="runtime",onChange:()=>Y("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),Z==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),K?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(Et,{id:"agent-model",label:"Model",value:i,onChange:R,models:ce,placeholder:"Select a model…",favoriteProviders:me,onToggleFavorite:B,favoriteModels:H,onToggleModelFavorite:G})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),de?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:re,onChange:d=>ye(d.target.value),children:[e.jsx("option",{value:"",children:O.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),O.map(d=>e.jsx("option",{value:d.runtimeId,children:d.description?`${d.name} — ${d.description}`:d.name},`${d.pluginId}:${d.runtimeId}`))]})]})]});return an.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:t=>{t.target===t.currentTarget&&pe()},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:pe,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(t=>e.jsx("div",{className:`agent-dialog-step${t===o?" active":t<o?" completed":""}`,"aria-label":`Step ${t+1}`},t))}),e.jsxs("div",{className:"agent-dialog-body",children:[o===0&&e.jsxs("div",{children:[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":m==="presets",tabIndex:m==="presets"?0:-1,className:`agent-dialog-tab${m==="presets"?" active":""}`,onClick:()=>u("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":m==="custom",tabIndex:m==="custom"?0:-1,className:`agent-dialog-tab${m==="custom"?" active":""}`,onClick:()=>u("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),m==="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:bt.map(t=>e.jsxs("button",{type:"button",className:`agent-preset-card${V===t.id?" selected":""}`,"data-testid":`preset-${t.id}`,onClick:()=>Pe(t),title:t.title,children:[e.jsx("span",{className:"agent-preset-icon",children:t.icon}),e.jsx("span",{className:"agent-preset-name",children:t.name}),e.jsx("span",{className:"agent-preset-role",children:t.role}),t.description&&e.jsx("span",{className:"agent-preset-description",children:t.description})]},t.id))})]})}),m==="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 ",!V&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:p,onChange:t=>f(t.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:b,onChange:t=>w(t.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:C,onChange:t=>T(t.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:ut.map(t=>e.jsxs("button",{type:"button",className:`agent-role-option${M===t.value?" selected":""}`,onClick:()=>S(t.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:t.icon}),e.jsx("span",{className:"agent-role-option-label",children:t.label})]},t.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:j,onChange:t=>A(t.target.value),disabled:Me,children:[e.jsx("option",{value:"",children:"No manager"}),Ne.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (",t.id,")"]},t.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:q,onChange:t=>se(t.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:F,onChange:t=>h(t.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:v,onChange:t=>E(t.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:D,onChange:t=>Q(t.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:_,onChange:t=>P(t.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),n("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:()=>U(!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"})]})]})]}),o===1&&e.jsxs("div",{children:[n("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:I.thinkingLevel,onChange:t=>J(d=>({...d,thinkingLevel:t.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:I.maxTurns,onChange:t=>J(d=>({...d,maxTurns:Math.max(1,parseInt(t.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(sn,{id:"agent-skills",label:"Skills",value:ie,onChange:ve,projectId:g}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),o===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:[C&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:C}),p]})]}),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:b,onChange:t=>w(t.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:[Ae?.icon," ",Ae?.label]})]}),fe&&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:Re?`${Re.name} (${Re.id})`:fe})]}),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:q,onChange:t=>se(t.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:D,onChange:t=>Q(t.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:v,onChange:t=>E(t.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:_,onChange:t=>P(t.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:Z==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:Z==="runtime"?je?je.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):i?e.jsxs(e.Fragment,{children:[e.jsx(St,{provider:i.split("/")[0],size:"sm"})," ",(()=>{const t=i.indexOf("/"),d=i.slice(0,t),k=i.slice(t+1);return ce.find(ee=>ee.provider===d&&ee.id===k)?.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:I.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:I.maxTurns})]}),ie.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:[ie.length," skill",ie.length!==1?"s":""," selected"]})]})]}),ke&&e.jsx("p",{className:"agent-dialog-error",children:ke})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[o>0&&e.jsx("button",{className:"btn",onClick:()=>r(t=>t-1),disabled:W,children:"Back"}),e.jsx("button",{className:"btn",onClick:pe,disabled:W,children:"Cancel"}),o<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>r(t=>t+1),disabled:o===0&&!p.trim()&&!V,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void Se(),disabled:W||!p.trim(),children:W?"Creating...":"Create"})]})]}),e.jsx(kn,{isOpen:oe,onClose:()=>U(!1),onGenerated:x,projectId:g})]}),document.body)}function Un({isOpen:s,onClose:l,onUseDraft:y,projectId:g,existingAgents:c}){const[o,r]=a.useState("initial"),[m,u]=a.useState(""),[p,f]=a.useState(null),[b,w]=a.useState(""),[C,T]=a.useState("answer"),[M,S]=a.useState(""),[j,A]=a.useState(null),[v,E]=a.useState(null),[_,P]=a.useState([]),D=a.useCallback(()=>{r("initial"),u(""),f(null),w(""),T("answer"),S(""),A(null),E(null),P([])},[]),Q=a.useMemo(()=>bt.map(h=>({id:h.id,label:h.name,description:h.description})),[]);a.useEffect(()=>{if(!p)return;const h=Mt(p,g,{onThinking:I=>{P(J=>{const V=[...J],X=V[V.length-1];return X&&!X.question?(V[V.length-1]={...X,thinkingOutput:`${X.thinkingOutput??""}${I}`},V):[...V,{response:{},thinkingOutput:I}]})},onQuestion:I=>{w(I.question),T(I.id),r("question")},onSummary:I=>{A(I),r("summary")},onError:I=>{E(I),r("error")}});return()=>h.close()},[p,g]);const q=async()=>{try{p&&await Rt(p,g)}catch{}finally{D(),l()}};if(a.useEffect(()=>{s||D()},[s,D]),!s)return null;const se=async()=>{r("loading"),E(null);try{const h=await _t(m,{existingAgents:c.map(I=>({id:I.id,name:I.name,role:I.role})),templates:Q},g);f(h.sessionId)}catch(h){E(h.message),r("error")}},F=async()=>{if(p){r("loading"),E(null);try{const h={[C]:M};P(I=>[...I,{question:{id:C,type:"text",question:b},response:h}]),await $t(p,h,g),S("")}catch(h){E(h.message),r("error")}}};return e.jsx("div",{className:"modal-overlay open",role:"presentation",children:e.jsxs("div",{className:"modal modal-lg experimental-agent-onboarding-modal",role:"dialog","aria-modal":"true","aria-label":"Experimental agent onboarding",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Experimental Agent Onboarding"}),e.jsx("button",{className:"modal-close",onClick:()=>void q(),"aria-label":"Close",children:"×"})]}),_.length>0&&e.jsx(Pt,{entries:_}),o==="initial"&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-onboarding-intent",children:"What should this new agent own?"}),e.jsx("textarea",{id:"agent-onboarding-intent",className:"input experimental-agent-onboarding-modal__textarea",value:m,onChange:h=>u(h.target.value)}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void q(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",disabled:!m.trim(),onClick:()=>void se(),children:"Start onboarding"})]})]}),(o==="loading"||o==="question")&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"agent-onboarding-answer",children:b||"Thinking..."}),e.jsx("textarea",{id:"agent-onboarding-answer",className:"input experimental-agent-onboarding-modal__textarea",value:M,onChange:h=>S(h.target.value)}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void q(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",disabled:o==="loading"||!M.trim(),onClick:()=>void F(),children:"Continue"})]})]}),o==="summary"&&j&&e.jsxs("div",{className:"form-group",children:[e.jsx("label",{children:"Draft ready for review"}),e.jsxs("div",{className:"experimental-agent-onboarding-modal__summary card",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Name:"})," ",j.name]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Role:"})," ",j.role]}),j.templateId&&e.jsxs("p",{children:[e.jsx("strong",{children:"Template:"})," ",j.templateId]}),j.patternAgentId&&e.jsxs("p",{children:[e.jsx("strong",{children:"Pattern agent:"})," ",j.patternAgentId]}),j.rationale&&e.jsxs("p",{children:[e.jsx("strong",{children:"Why:"})," ",j.rationale]})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{className:"btn",onClick:()=>void q(),children:"Cancel"}),e.jsx("button",{className:"btn btn-primary",onClick:()=>y(j),children:"Continue to agent form"})]})]}),o==="error"&&v&&e.jsxs("div",{className:"form-group",children:[e.jsx("div",{className:"form-error",children:v}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{className:"btn",onClick:()=>void q(),children:"Close"})})]})]})})}function Kn(s){const l=s.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!l)throw new Error("Missing YAML frontmatter delimiters (---)");const y=l[1].split(/\r?\n/),g=l[2]??"",c={name:""},o=[];let r=!1;for(const m of y){const p=m.trimEnd().trim();if(!p)continue;if(p.startsWith("skills:")){r=!0;continue}if(r&&p.startsWith("- ")){o.push(p.slice(2).trim());continue}r=!1;const[f,...b]=p.split(":"),C=b.join(":").trim().replace(/^['"]|['"]$/g,"");f==="name"&&(c.name=C),f==="title"&&(c.title=C),f==="icon"&&(c.icon=C),f==="role"&&(c.role=C),f==="reportsTo"&&(c.reportsTo=C)}if(!c.name)throw new Error("Missing required field: name");return o.length>0&&(c.skills=o),g.trim().length>0&&(c.instructionBody=g),c}function Bn({isOpen:s,onClose:l,onImported:y,projectId:g}){const[c,o]=a.useState("input"),[r,m]=a.useState("paste"),[u,p]=a.useState(""),[f,b]=a.useState([]),[w,C]=a.useState("Unknown"),[T,M]=a.useState([]),[S,j]=a.useState([]),[A,v]=a.useState([]),[E,_]=a.useState([]),[P,D]=a.useState(!1),[Q,q]=a.useState(!1),[se,F]=a.useState(null),[h,I]=a.useState(null),[J,V]=a.useState(null),X=a.useRef(null),ie=a.useRef(null),[ve,W]=a.useState([]),[ne,ke]=a.useState(""),[L,oe]=a.useState(null),[U,ce]=a.useState(!1),[ae,K]=a.useState(null),ue=a.useRef(!1);a.useEffect(()=>{r==="browse"&&!ue.current&&!U&&(ue.current=!0,ce(!0),K(null),at().then(i=>{i.error?K(i.error):i.companies.length>0?W(i.companies):K("No companies available")}).catch(i=>{K(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{ce(!1)}))},[r,U]);const me=a.useCallback(()=>{ue.current=!0,K(null),W([]),oe(null),ce(!0),at().then(i=>{i.error?K(i.error):i.companies.length>0?W(i.companies):K("No companies available")}).catch(i=>{K(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{ce(!1)})},[]),ge=a.useCallback(()=>{o("input"),m("paste"),p(""),b([]),C("Unknown"),M([]),j([]),v([]),_([]),D(!1),q(!1),F(null),I(null),V(null),W([]),ke(""),oe(null),ce(!1),K(null),ue.current=!1},[]),H=a.useCallback(()=>{ge(),l()},[ge,l]),xe=a.useCallback(i=>{const x=i.target.files?.[0];if(!x)return;const R=new FileReader;R.onload=Y=>{const B=Y.target?.result;m("file"),b([]),p(B),F(null)},R.onerror=()=>{F("Failed to read file")},R.readAsText(x),i.target.value=""},[]),Z=a.useCallback(async i=>{const x=Array.from(i.target.files??[]);if(x.length!==0)try{const R=x.filter(B=>(B.webkitRelativePath||B.name).toLowerCase().endsWith("agents.md")).sort((B,G)=>{const Pe=B.webkitRelativePath||B.name,pe=G.webkitRelativePath||G.name;return Pe.localeCompare(pe)});if(R.length===0){F("Selected directory has no AGENTS.md files");return}const Y=[];for(const B of R){const G=await B.text();Y.push(Kn(G))}m("directory"),b(Y),p(""),F(null)}catch{F("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function he(i){if(!g)return`/api${i}`;const x=i.includes("?")?"&":"?";return`/api${i}${x}projectId=${encodeURIComponent(g)}`}const re=a.useCallback(async()=>{if(r==="directory"&&f.length===0){F("Please select a directory containing AGENTS.md files");return}if(r==="browse"&&!L){F("Please select a company from the catalog");return}if(r!=="directory"&&r!=="browse"&&!u.trim()){F("Please provide manifest content");return}D(!0),F(null);try{let i;r==="directory"?i={agents:f,dryRun:!0}:r==="browse"&&L?i={importSource:"companies.sh",companySlug:L.slug,dryRun:!0}:i={manifest:u,dryRun:!0};const x=await fetch(he("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!x.ok){const G=await x.json();throw new Error(G.error??`Parse failed (${x.status})`)}const R=await x.json(),Y=R.agents&&R.agents.length>0?R.agents:R.created.map(G=>({name:G,role:"custom"})),B=Array.isArray(R.skills)?R.skills:[];C(R.companyName??"Unknown"),M(Y),j(B),v(Y.map(G=>G.name)),_(B.map(G=>G.name)),o("preview")}catch(i){F(i instanceof Error?i.message:"Failed to parse manifest")}finally{D(!1)}},[r,f,u,L,g]),ye=a.useCallback(async()=>{q(!0),V(null);try{let i;r==="directory"?i={agents:f,skipExisting:!0,selectedAgents:A,selectedSkills:E}:r==="browse"&&L?i={importSource:"companies.sh",companySlug:L.slug,skipExisting:!0,selectedAgents:A,selectedSkills:E}:i={manifest:u,skipExisting:!0,selectedAgents:A,selectedSkills:E};const x=await fetch(he("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!x.ok){const Y=await x.json();throw new Error(Y.error??`Import failed (${x.status})`)}const R=await x.json();I(R),o("result"),y()}catch(i){V(i instanceof Error?i.message:"Failed to import agents")}finally{q(!1)}},[r,f,u,L,A,E,g,y]),O=A.length,z=E.length,de=`${O} Agent${O!==1?"s":""}`,we=`${z} Skill${z!==1?"s":""}`,Ne=O>0&&z>0?`${de} + ${we}`:z>0?we:de,le=O>0&&z>0?`Importing ${O} agent${O!==1?"s":""} and ${z} skill${z!==1?"s":""}...`:z>0?`Importing ${z} skill${z!==1?"s":""}...`:`Importing ${O} agent${O!==1?"s":""}...`,Me=i=>{v(x=>x.includes(i)?x.filter(R=>R!==i):[...x,i])},Ie=i=>{_(x=>x.includes(i)?x.filter(R=>R!==i):[...x,i])};return s?e.jsx("div",{className:"agent-dialog-overlay",onClick:i=>{i.target===i.currentTarget&&H()},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:H,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[c==="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:X,type:"file",accept:".md,.txt",onChange:xe,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:ie,type:"file",webkitdirectory:"",multiple:!0,onChange:Z,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>X.current?.click(),children:[e.jsx(pt,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>ie.current?.click(),children:[e.jsx(rn,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{m("browse"),b([]),p(""),oe(null),F(null)},children:[e.jsx(Ft,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),r==="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(Lt,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:ne,onChange:i=>ke(i.target.value),"aria-label":"Search companies"})]}),L&&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:L.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>oe(null),children:"Change"})]})]}),U&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(We,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),ae&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(Ue,{size:16}),e.jsx("span",{children:ae}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:me,children:[e.jsx(Oe,{size:14}),"Retry"]})]}),!U&&!ae&&e.jsxs("div",{className:"agent-import-browse-list",children:[ve.filter(i=>ne===""||i.name.toLowerCase().includes(ne.toLowerCase())||(i.tagline?.toLowerCase().includes(ne.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${L?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>oe(i),role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&oe(i)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:i.name}),i.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[i.installs.toLocaleString()," installs"]})]}),i.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:i.tagline}),i.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:i.repo})]},i.slug)),ve.filter(i=>ne===""||i.name.toLowerCase().includes(ne.toLowerCase())||(i.tagline?.toLowerCase().includes(ne.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:ne?"No companies match your search":"No companies available"})]})]}),r!=="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:`---
516
516
  name: CEO
517
517
  title: Chief Executive Officer
518
518
  reportsTo: null
519
519
  skills:
520
520
  - review
521
521
  ---
522
- Agent instructions go here...`,value:u,onChange:i=>{m("paste"),b([]),p(i.target.value),F(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),se&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),se]})]}),c==="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(Xe,{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:()=>v(T.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((i,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 ${i.name}`,checked:A.includes(i.name),onChange:()=>Me(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.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(Xe,{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:()=>_(S.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((i,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 ${i.name}`,checked:E.includes(i.name),onChange:()=>Ie(i.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:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${x}`))})]}),J&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),J]})]}),c==="result"&&h&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(De,{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:h.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.created.length," created"]})}),h.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skipped.length," skipped (already exist)"]})}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.errors.length," error",h.errors.length!==1?"s":""]})})]}),h.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.created.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))}),h.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:[h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.skills.imported.length," skill",h.skills.imported.length!==1?"s":""," imported"]})}),h.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skills.skipped.length," skill",h.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.skills.errors.length," skill",h.skills.errors.length!==1?"s":""," error",h.skills.errors.length!==1?"s":""]})}),h.skills.imported.length===0&&h.skills.skipped.length===0&&h.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"})})]}),h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.skills.imported.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.skills.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[c==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:Q,children:"Back"}),e.jsx("button",{className:"btn",onClick:H,disabled:Q,children:c==="result"?"Close":"Cancel"}),c==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void re(),disabled:P||(r==="directory"?f.length===0:r==="browse"?!L:!u.trim()),children:P?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),c==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ye(),disabled:Q||O===0&&z===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),le]}):`Import ${Ne}`})]})]})}):null}const Gn=a.lazy(()=>nn(()=>import("./AgentDetailView-B7j297GT.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(s=>({default:s.AgentDetailView}))),ze=[{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:"✦"}],Qe=[.1,.25,.5,1,2,3,5,10];function He(s){switch(s){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"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function qe(s,l){switch(l){case"running":return`${s}--running`;case"active":return`${s}--active`;case"paused":return`${s}--paused`;case"error":return`${s}--error`;case"terminated":return`${s}--terminated`;case"idle":default:return`${s}--idle`}}function vt({node:s,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m}){const{agent:u,children:p,depth:f}=s,b=c(u.id),w=g(u.id),C=o(u),T=He(u.state),M=qe("agent-tree__node",u.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${M}${u.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(f,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${b===0?" agent-tree__toggle--leaf":""}`,onClick:()=>b>0&&y(u.id),title:b>0?w?"Collapse":"Expand":"No employees","aria-label":b>0?w?"Collapse":"Expand":"No employees",children:b>0?w?e.jsx(Jt,{size:16}):e.jsx(ht,{size:16}):e.jsx(et,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:S=>S.key==="Enter"&&l(u.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(u.role)}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:`agent-tree__badge ${T}`,children:u.state}),e.jsx("span",{className:"agent-tree__health",style:{color:C.color},title:C.label,children:C.icon}),b>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",b,")"]}),(()=>{const S=m(u);return S.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:S.join(", "),children:[S[0],S.length>1&&` +${S.length-1}`]})})()]})]}),w&&p.length>0&&e.jsx("div",{className:"agent-tree__children",children:p.map(S=>e.jsx(vt,{node:S,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m},S.agent.id))})]})}function xt({node:s,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c}){const{agent:o,children:r}=s,m=y(o),u=He(o.state),p=qe("org-chart-node-card",o.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:p,onClick:()=>l(o.id),role:"button",tabIndex:0,onKeyDown:f=>f.key==="Enter"&&l(o.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:g(o.role)}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${u}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:m.color},title:m.label,children:[m.icon,!m.stateDerived&&e.jsx("span",{className:"text-secondary",children:m.label})]}),(()=>{const f=c(o);if(f.length===0)return null;const b=f.slice(0,2),w=f.length-2;return e.jsxs(e.Fragment,{children:[b.map(C=>e.jsx("span",{className:"org-chart-node__skill",children:C},C)),w>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",w]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:r.map(f=>e.jsx(xt,{node:f,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c},f.agent.id))})]})}function ta({addToast:s,projectId:l,onOpenTaskLogs:y,agentOnboardingEnabled:g=!1}){const[c,o]=a.useState(!1),[r,m]=a.useState("all"),{agents:u,stats:p,isLoading:f,loadAgents:b}=zt(l,{filterState:r,showSystemAgents:c}),[w,C]=a.useState(!1),[T,M]=a.useState(!1),[S,j]=a.useState(null),[A,v]=a.useState(!1),[E,_]=a.useState(null),[P,D]=a.useState(()=>{if(typeof window>"u")return"list";const n=Ze("fn-agent-view",l);return n==="list"||n==="board"||n==="tree"||n==="org"?n:"list"}),[Q,q]=a.useState([]),[se,F]=a.useState(!1),[h,I]=a.useState(!1),J=a.useRef(null),{confirm:V}=Dt(),X=a.useRef(null),ie=a.useId();a.useEffect(()=>{const n=Ze("fn-agent-view",l);if(n==="list"||n==="board"||n==="tree"||n==="org"){D(n);return}D("list")},[l]),a.useEffect(()=>{gt("fn-agent-view",P,l)},[P,l]);const[ve,W]=a.useState(null),ne=a.useRef(null),[ke,L]=a.useState(null),[oe,U]=a.useState(null),[ce,ae]=a.useState({}),[K,ue]=a.useState(1),[me,ge]=a.useState(!1),[H,xe]=a.useState(new Set),[Z,he]=a.useState(new Map),re=a.useRef(!0);a.useEffect(()=>(re.current=!0,()=>{re.current=!1}),[]),a.useEffect(()=>{Ot(l).then(n=>{re.current&&ue(n.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const ye=a.useCallback(async n=>{const t=Number.isFinite(n)&&n>0?n:1;ue(t),ge(!0);try{await Ht({heartbeatMultiplier:t},l),s(`Heartbeat speed set to ×${t.toFixed(1)}`,"success")}catch(d){s(`Failed to save heartbeat multiplier: ${be(d)}`,"error")}finally{re.current&&ge(!1)}},[l,s]),O=a.useMemo(()=>Z.size===0?u:u.map(n=>{const t=Z.get(n.id);return t?{...n,state:t}:n}),[u,Z]),z=jn(O,l),de=a.useMemo(()=>O.filter(n=>c||!Ke(n)),[O,c]),we=a.useMemo(()=>O.filter(n=>n.state!=="active"&&n.state!=="running"?!1:c||!Ke(n)),[O,c]),Ne=a.useMemo(()=>{if(c)return Q;const n=t=>Ke(t.agent)?null:{...t,children:t.children.map(n).filter(d=>d!==null)};return Q.map(n).filter(t=>t!==null)},[Q,c]);a.useEffect(()=>{if(P!=="org")return;let n=!1;return F(!0),qt(l,{includeEphemeral:c}).then(t=>{n||q(t)}).catch(t=>{n||(s(`Failed to load org chart: ${be(t)}`,"error"),q([]))}).finally(()=>{n||F(!1)}),()=>{n=!0}},[P,l,c,s]),a.useEffect(()=>{const n=setInterval(()=>{b()},3e4);return()=>{clearInterval(n)}},[b]),a.useEffect(()=>{if(!h)return;const n=d=>{const k=d.target;k&&(J.current?.contains(k)||X.current?.contains(k)||I(!1))},t=d=>{d.key==="Escape"&&(I(!1),X.current?.focus())};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),document.removeEventListener("keydown",t)}},[h]);const le=async(n,t)=>{if(!H.has(n)){xe(d=>new Set(d).add(n)),he(d=>{const k=new Map(d);return k.set(n,t),k});try{await Yt(n,t,l),s(`Agent state updated to ${t}`,"success"),await b(),he(d=>{const k=new Map(d);return k.delete(n),k})}catch(d){he(k=>{const $=new Map(k);return $.delete(n),$}),s(`Failed to update state: ${be(d)}`,"error")}finally{xe(d=>{const k=new Set(d);return k.delete(n),k})}}},Me=async(n,t)=>{if(await V({title:"Delete Agent",message:`Delete agent "${t}"? This cannot be undone.`,danger:!0}))try{await tn(n,l),s(`Agent "${t}" deleted`,"success"),b()}catch(k){s(`Failed to delete agent: ${be(k)}`,"error")}},Ie=async(n,t)=>{const d=u.find(k=>k.id===n);if(d){if(d.role===t){W(null);return}try{await Fe(n,{role:t},l),s(`Agent role updated to ${ze.find(k=>k.value===t)?.label??t}`,"success"),W(null),b()}catch(k){s(`Failed to update role: ${be(k)}`,"error")}}},i=(n,t)=>{n.key==="Escape"&&W(null)},x=async(n,t)=>{oe===n.id&&(U(null),ae(d=>{const k={...d};return delete k[n.id],k})),L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:t}},l),s(`Heartbeat interval updated to ${rt(t)} for ${n.name}`,"success"),b()}catch(d){s(`Failed to update heartbeat interval: ${be(d)}`,"error")}finally{L(null)}},R=async n=>{const t=ce[n.id]??"";if(t.trim()===""){s("Please enter a heartbeat interval in minutes","error");return}const d=Number(t);if(isNaN(d)){s("Heartbeat interval must be a valid number","error");return}if(d<=0){s("Heartbeat interval must be greater than 0","error");return}if(d>=1&&d<5){L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:Zt}},l),s(`Heartbeat interval set to 5 minutes (minimum). ${d} minute${d!==1?"s":""} was below the 5-minute minimum.`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}return}const k=Math.round(d*6e4);L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:k}},l),s(`Heartbeat interval updated to ${rt(k)} for ${n.name}`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}},Y=n=>{const t=Je(n.runtimeConfig?.heartbeatIntervalMs),d=Math.round(t/6e4);U(n.id),ae(k=>({...k,[n.id]:String(d)}))},B=a.useCallback(()=>{_(null)},[]),G=a.useCallback(n=>{_(n)},[]),Pe=async(n,t)=>{try{await en(n,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${t}`,"success"),b()}catch(d){s(`Failed to start heartbeat run: ${be(d)}`,"error")}},pe=n=>ze.find(t=>t.value===n)?.label??n,Se=n=>ze.find(t=>t.value===n)?.icon??"◆",Ae=n=>Array.isArray(n.metadata?.skills)?n.metadata.skills:[],fe=n=>Xt(n),Re=f&&u.length===0,je=a.useCallback(()=>{if(g){M(!0);return}C(!0)},[g]);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(et,{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${P==="list"?" active":""}`,onClick:()=>D("list"),title:"List view","aria-label":"List view","aria-pressed":P==="list",children:e.jsx(Vt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="board"?" active":""}`,onClick:()=>D("board"),title:"Board view","aria-label":"Board view","aria-pressed":P==="board",children:e.jsx(Te,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="tree"?" active":""}`,onClick:()=>D("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":P==="tree",children:e.jsx(Wt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="org"?" active":""}`,onClick:()=>D("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":P==="org",children:e.jsx(dn,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:X,className:`btn-icon agent-controls-trigger${h?" agent-controls-trigger--active":""}`,onClick:()=>I(n=>!n),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":h,"aria-controls":ie,children:e.jsx(mn,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void b(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Oe,{size:16,className:f?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{je(),I(!1)},children:[e.jsx(Ut,{size:16}),"New Agent"]})]})]})]}),h&&e.jsxs("div",{ref:J,id:ie,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Kt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:r,onChange:n=>m(n.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.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:n=>o(n.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{v(!0),I(!1)},children:[e.jsx(pt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",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:K,onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",K.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Qe.reduce((n,t)=>Math.abs(t-K)<Math.abs(n-K)?t:n,Qe[0])),onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me,"aria-label":"Heartbeat speed preset",children:Qe.map(n=>e.jsxs("option",{value:String(n),children:["×",n]},n))})]}),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(xn,{agents:de})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(vn,{stats:p}),e.jsx(fn,{agents:we,projectId:l,onAgentSelect:_,onOpenTaskLogs:y}),e.jsx(Wn,{isOpen:w,onClose:()=>{C(!1),j(null)},onCreated:()=>{C(!1),j(null),b()},projectId:l,prefillDraft:S}),e.jsx(Un,{isOpen:T,onClose:()=>M(!1),onUseDraft:n=>{j(n),M(!1),C(!0)},projectId:l,existingAgents:u}),e.jsx(Bn,{isOpen:A,onClose:()=>v(!1),onImported:()=>void b(),projectId:l}),Re?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):P==="tree"?e.jsx("div",{className:"agent-tree__view",children:de.length===0?e.jsx(Le,{onCtaClick:je}):z.rootNodes.map(n=>e.jsx(vt,{node:n,onSelect:_,onToggle:z.toggleExpand,isExpanded:z.isExpanded,getChildCount:t=>z.getChildren(t).length,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:se?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):Ne.length===0?e.jsx(Le,{onCtaClick:je}):Ne.map(n=>e.jsx(xt,{node:n,onSelect:_,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="board"?e.jsx("div",{className:"agent-board",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-board-card",n.state);return e.jsx("div",{className:`agent-board-card ${k}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:$=>$.key==="Enter"&&_(n.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:Se(n.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:pe(n.role)}),e.jsx("span",{className:`agent-board-badge badge ${d}`,children:n.state})]}),e.jsx("div",{className:"agent-board-name",children:n.name}),e.jsx("div",{className:"agent-board-id",children:n.id}),e.jsxs("div",{className:"agent-board-health",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]})]})},n.id)})}):e.jsx("div",{className:"agent-list",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-card",n.state),$=Je(n.runtimeConfig?.heartbeatIntervalMs),ee=Bt($),_e=ke===n.id;return e.jsxs("div",{className:`agent-card ${k}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:N=>N.key==="Enter"&&_(n.id),children:[ve===n.id?e.jsx("select",{ref:ne,className:"select agent-role-select",value:n.role,onChange:N=>void Ie(n.id,N.target.value),onKeyDown:N=>i(N,n.id),onBlur:()=>W(null),autoFocus:!0,children:ze.map(N=>e.jsxs("option",{value:N.value,children:[N.icon," ",N.label]},N.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:N=>{N.stopPropagation(),W(n.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.stopPropagation(),W(n.id))},children:Se(n.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:n.name}),e.jsx("span",{className:"agent-id text-secondary",children:n.id})]}),e.jsx(ht,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${d}`,children:n.state}),e.jsxs("span",{className:"badge",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]}),e.jsx("span",{className:"badge text-secondary",children:pe(n.role)}),(()=>{const N=Ae(n);if(N.length===0)return null;const te=N.slice(0,2),Ce=N.length-2;return e.jsxs(e.Fragment,{children:[te.map(tt=>e.jsx("span",{className:"badge badge-skill",children:tt},tt)),Ce>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",Ce]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[n.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:n.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),oe===n.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:ce[n.id]??"",onChange:N=>ae(te=>({...te,[n.id]:N.target.value})),onKeyDown:N=>{N.key==="Enter"?R(n):N.key==="Escape"&&(U(null),ae(te=>{const Ce={...te};return delete Ce[n.id],Ce}))},disabled:_e,"aria-label":`Custom heartbeat interval in minutes for ${n.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void R(n),disabled:_e,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{U(null),ae(N=>{const te={...N};return delete te[n.id],te})},disabled:_e,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:$,onChange:N=>{const te=N.target.value;te==="__custom__"?Y(n):x(n,Number(te))},disabled:_e,"aria-label":`Set heartbeat interval for ${n.name}`,children:[ee.map(N=>e.jsx("option",{value:N.value,children:N.label},N.value)),Gt.some(N=>N.value===$)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),_e&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),n.lastHeartbeatAt&&(()=>{const N=new Date(n.lastHeartbeatAt),te=new Date(N.getTime()+$),Ce=n.state==="active"||n.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:N.toLocaleString(),children:["Last: ",N.toLocaleTimeString()]}),Ce&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:te.toLocaleString(),children:["Next: ",te.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[n.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Activate",children:[e.jsx($e,{size:14})," Start"]}),n.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void Pe(n.id,n.name),disabled:H.has(n.id),title:"Run Now","aria-label":`Run now for ${n.name}`,children:[e.jsx(Te,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Resume",children:[e.jsx($e,{size:14})," Resume"]}),n.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${n.name}`,children:[e.jsx(Te,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Retry",children:[e.jsx($e,{size:14})," Retry"]}),n.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Start",children:[e.jsx($e,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>_(n.id),title:`View details for ${n.name}`,"aria-label":`View details for ${n.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void Me(n.id,n.name),title:"Delete",children:[e.jsx(Qt,{size:14})," Delete"]})]})]},n.id)})})]}),E&&e.jsx(a.Suspense,{fallback:null,children:e.jsx(Gn,{agentId:E,projectId:l,onClose:B,addToast:s,onChildClick:G})})]})}export{ta as AgentsView};
522
+ Agent instructions go here...`,value:u,onChange:i=>{m("paste"),b([]),p(i.target.value),F(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),se&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),se]})]}),c==="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(Xe,{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:()=>v(T.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((i,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 ${i.name}`,checked:A.includes(i.name),onChange:()=>Me(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.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(Xe,{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:()=>_(S.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((i,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 ${i.name}`,checked:E.includes(i.name),onChange:()=>Ie(i.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:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${x}`))})]}),J&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),J]})]}),c==="result"&&h&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(De,{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:h.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.created.length," created"]})}),h.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skipped.length," skipped (already exist)"]})}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.errors.length," error",h.errors.length!==1?"s":""]})})]}),h.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.created.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))}),h.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:[h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.skills.imported.length," skill",h.skills.imported.length!==1?"s":""," imported"]})}),h.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skills.skipped.length," skill",h.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.skills.errors.length," skill",h.skills.errors.length!==1?"s":""," error",h.skills.errors.length!==1?"s":""]})}),h.skills.imported.length===0&&h.skills.skipped.length===0&&h.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"})})]}),h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.skills.imported.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.skills.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[c==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:Q,children:"Back"}),e.jsx("button",{className:"btn",onClick:H,disabled:Q,children:c==="result"?"Close":"Cancel"}),c==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void re(),disabled:P||(r==="directory"?f.length===0:r==="browse"?!L:!u.trim()),children:P?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),c==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ye(),disabled:Q||O===0&&z===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),le]}):`Import ${Ne}`})]})]})}):null}const Gn=a.lazy(()=>nn(()=>import("./AgentDetailView-B3KAsP2O.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(s=>({default:s.AgentDetailView}))),ze=[{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:"✦"}],Qe=[.1,.25,.5,1,2,3,5,10];function He(s){switch(s){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"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function qe(s,l){switch(l){case"running":return`${s}--running`;case"active":return`${s}--active`;case"paused":return`${s}--paused`;case"error":return`${s}--error`;case"terminated":return`${s}--terminated`;case"idle":default:return`${s}--idle`}}function vt({node:s,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m}){const{agent:u,children:p,depth:f}=s,b=c(u.id),w=g(u.id),C=o(u),T=He(u.state),M=qe("agent-tree__node",u.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${M}${u.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(f,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${b===0?" agent-tree__toggle--leaf":""}`,onClick:()=>b>0&&y(u.id),title:b>0?w?"Collapse":"Expand":"No employees","aria-label":b>0?w?"Collapse":"Expand":"No employees",children:b>0?w?e.jsx(Jt,{size:16}):e.jsx(ht,{size:16}):e.jsx(et,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:S=>S.key==="Enter"&&l(u.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(u.role)}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:`agent-tree__badge ${T}`,children:u.state}),e.jsx("span",{className:"agent-tree__health",style:{color:C.color},title:C.label,children:C.icon}),b>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",b,")"]}),(()=>{const S=m(u);return S.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:S.join(", "),children:[S[0],S.length>1&&` +${S.length-1}`]})})()]})]}),w&&p.length>0&&e.jsx("div",{className:"agent-tree__children",children:p.map(S=>e.jsx(vt,{node:S,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m},S.agent.id))})]})}function xt({node:s,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c}){const{agent:o,children:r}=s,m=y(o),u=He(o.state),p=qe("org-chart-node-card",o.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:p,onClick:()=>l(o.id),role:"button",tabIndex:0,onKeyDown:f=>f.key==="Enter"&&l(o.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:g(o.role)}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${u}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:m.color},title:m.label,children:[m.icon,!m.stateDerived&&e.jsx("span",{className:"text-secondary",children:m.label})]}),(()=>{const f=c(o);if(f.length===0)return null;const b=f.slice(0,2),w=f.length-2;return e.jsxs(e.Fragment,{children:[b.map(C=>e.jsx("span",{className:"org-chart-node__skill",children:C},C)),w>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",w]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:r.map(f=>e.jsx(xt,{node:f,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c},f.agent.id))})]})}function ta({addToast:s,projectId:l,onOpenTaskLogs:y,agentOnboardingEnabled:g=!1}){const[c,o]=a.useState(!1),[r,m]=a.useState("all"),{agents:u,stats:p,isLoading:f,loadAgents:b}=zt(l,{filterState:r,showSystemAgents:c}),[w,C]=a.useState(!1),[T,M]=a.useState(!1),[S,j]=a.useState(null),[A,v]=a.useState(!1),[E,_]=a.useState(null),[P,D]=a.useState(()=>{if(typeof window>"u")return"list";const n=Ze("fn-agent-view",l);return n==="list"||n==="board"||n==="tree"||n==="org"?n:"list"}),[Q,q]=a.useState([]),[se,F]=a.useState(!1),[h,I]=a.useState(!1),J=a.useRef(null),{confirm:V}=Dt(),X=a.useRef(null),ie=a.useId();a.useEffect(()=>{const n=Ze("fn-agent-view",l);if(n==="list"||n==="board"||n==="tree"||n==="org"){D(n);return}D("list")},[l]),a.useEffect(()=>{gt("fn-agent-view",P,l)},[P,l]);const[ve,W]=a.useState(null),ne=a.useRef(null),[ke,L]=a.useState(null),[oe,U]=a.useState(null),[ce,ae]=a.useState({}),[K,ue]=a.useState(1),[me,ge]=a.useState(!1),[H,xe]=a.useState(new Set),[Z,he]=a.useState(new Map),re=a.useRef(!0);a.useEffect(()=>(re.current=!0,()=>{re.current=!1}),[]),a.useEffect(()=>{Ot(l).then(n=>{re.current&&ue(n.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const ye=a.useCallback(async n=>{const t=Number.isFinite(n)&&n>0?n:1;ue(t),ge(!0);try{await Ht({heartbeatMultiplier:t},l),s(`Heartbeat speed set to ×${t.toFixed(1)}`,"success")}catch(d){s(`Failed to save heartbeat multiplier: ${be(d)}`,"error")}finally{re.current&&ge(!1)}},[l,s]),O=a.useMemo(()=>Z.size===0?u:u.map(n=>{const t=Z.get(n.id);return t?{...n,state:t}:n}),[u,Z]),z=jn(O,l),de=a.useMemo(()=>O.filter(n=>c||!Ke(n)),[O,c]),we=a.useMemo(()=>O.filter(n=>n.state!=="active"&&n.state!=="running"?!1:c||!Ke(n)),[O,c]),Ne=a.useMemo(()=>{if(c)return Q;const n=t=>Ke(t.agent)?null:{...t,children:t.children.map(n).filter(d=>d!==null)};return Q.map(n).filter(t=>t!==null)},[Q,c]);a.useEffect(()=>{if(P!=="org")return;let n=!1;return F(!0),qt(l,{includeEphemeral:c}).then(t=>{n||q(t)}).catch(t=>{n||(s(`Failed to load org chart: ${be(t)}`,"error"),q([]))}).finally(()=>{n||F(!1)}),()=>{n=!0}},[P,l,c,s]),a.useEffect(()=>{const n=setInterval(()=>{b()},3e4);return()=>{clearInterval(n)}},[b]),a.useEffect(()=>{if(!h)return;const n=d=>{const k=d.target;k&&(J.current?.contains(k)||X.current?.contains(k)||I(!1))},t=d=>{d.key==="Escape"&&(I(!1),X.current?.focus())};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),document.removeEventListener("keydown",t)}},[h]);const le=async(n,t)=>{if(!H.has(n)){xe(d=>new Set(d).add(n)),he(d=>{const k=new Map(d);return k.set(n,t),k});try{await Yt(n,t,l),s(`Agent state updated to ${t}`,"success"),await b(),he(d=>{const k=new Map(d);return k.delete(n),k})}catch(d){he(k=>{const $=new Map(k);return $.delete(n),$}),s(`Failed to update state: ${be(d)}`,"error")}finally{xe(d=>{const k=new Set(d);return k.delete(n),k})}}},Me=async(n,t)=>{if(await V({title:"Delete Agent",message:`Delete agent "${t}"? This cannot be undone.`,danger:!0}))try{await tn(n,l),s(`Agent "${t}" deleted`,"success"),b()}catch(k){s(`Failed to delete agent: ${be(k)}`,"error")}},Ie=async(n,t)=>{const d=u.find(k=>k.id===n);if(d){if(d.role===t){W(null);return}try{await Fe(n,{role:t},l),s(`Agent role updated to ${ze.find(k=>k.value===t)?.label??t}`,"success"),W(null),b()}catch(k){s(`Failed to update role: ${be(k)}`,"error")}}},i=(n,t)=>{n.key==="Escape"&&W(null)},x=async(n,t)=>{oe===n.id&&(U(null),ae(d=>{const k={...d};return delete k[n.id],k})),L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:t}},l),s(`Heartbeat interval updated to ${rt(t)} for ${n.name}`,"success"),b()}catch(d){s(`Failed to update heartbeat interval: ${be(d)}`,"error")}finally{L(null)}},R=async n=>{const t=ce[n.id]??"";if(t.trim()===""){s("Please enter a heartbeat interval in minutes","error");return}const d=Number(t);if(isNaN(d)){s("Heartbeat interval must be a valid number","error");return}if(d<=0){s("Heartbeat interval must be greater than 0","error");return}if(d>=1&&d<5){L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:Zt}},l),s(`Heartbeat interval set to 5 minutes (minimum). ${d} minute${d!==1?"s":""} was below the 5-minute minimum.`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}return}const k=Math.round(d*6e4);L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:k}},l),s(`Heartbeat interval updated to ${rt(k)} for ${n.name}`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}},Y=n=>{const t=Je(n.runtimeConfig?.heartbeatIntervalMs),d=Math.round(t/6e4);U(n.id),ae(k=>({...k,[n.id]:String(d)}))},B=a.useCallback(()=>{_(null)},[]),G=a.useCallback(n=>{_(n)},[]),Pe=async(n,t)=>{try{await en(n,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${t}`,"success"),b()}catch(d){s(`Failed to start heartbeat run: ${be(d)}`,"error")}},pe=n=>ze.find(t=>t.value===n)?.label??n,Se=n=>ze.find(t=>t.value===n)?.icon??"◆",Ae=n=>Array.isArray(n.metadata?.skills)?n.metadata.skills:[],fe=n=>Xt(n),Re=f&&u.length===0,je=a.useCallback(()=>{if(g){M(!0);return}C(!0)},[g]);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(et,{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${P==="list"?" active":""}`,onClick:()=>D("list"),title:"List view","aria-label":"List view","aria-pressed":P==="list",children:e.jsx(Vt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="board"?" active":""}`,onClick:()=>D("board"),title:"Board view","aria-label":"Board view","aria-pressed":P==="board",children:e.jsx(Te,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="tree"?" active":""}`,onClick:()=>D("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":P==="tree",children:e.jsx(Wt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="org"?" active":""}`,onClick:()=>D("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":P==="org",children:e.jsx(dn,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:X,className:`btn-icon agent-controls-trigger${h?" agent-controls-trigger--active":""}`,onClick:()=>I(n=>!n),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":h,"aria-controls":ie,children:e.jsx(mn,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void b(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Oe,{size:16,className:f?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{je(),I(!1)},children:[e.jsx(Ut,{size:16}),"New Agent"]})]})]})]}),h&&e.jsxs("div",{ref:J,id:ie,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Kt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:r,onChange:n=>m(n.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.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:n=>o(n.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{v(!0),I(!1)},children:[e.jsx(pt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",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:K,onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",K.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Qe.reduce((n,t)=>Math.abs(t-K)<Math.abs(n-K)?t:n,Qe[0])),onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me,"aria-label":"Heartbeat speed preset",children:Qe.map(n=>e.jsxs("option",{value:String(n),children:["×",n]},n))})]}),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(xn,{agents:de})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(vn,{stats:p}),e.jsx(fn,{agents:we,projectId:l,onAgentSelect:_,onOpenTaskLogs:y}),e.jsx(Wn,{isOpen:w,onClose:()=>{C(!1),j(null)},onCreated:()=>{C(!1),j(null),b()},projectId:l,prefillDraft:S}),e.jsx(Un,{isOpen:T,onClose:()=>M(!1),onUseDraft:n=>{j(n),M(!1),C(!0)},projectId:l,existingAgents:u}),e.jsx(Bn,{isOpen:A,onClose:()=>v(!1),onImported:()=>void b(),projectId:l}),Re?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):P==="tree"?e.jsx("div",{className:"agent-tree__view",children:de.length===0?e.jsx(Le,{onCtaClick:je}):z.rootNodes.map(n=>e.jsx(vt,{node:n,onSelect:_,onToggle:z.toggleExpand,isExpanded:z.isExpanded,getChildCount:t=>z.getChildren(t).length,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:se?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):Ne.length===0?e.jsx(Le,{onCtaClick:je}):Ne.map(n=>e.jsx(xt,{node:n,onSelect:_,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="board"?e.jsx("div",{className:"agent-board",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-board-card",n.state);return e.jsx("div",{className:`agent-board-card ${k}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:$=>$.key==="Enter"&&_(n.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:Se(n.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:pe(n.role)}),e.jsx("span",{className:`agent-board-badge badge ${d}`,children:n.state})]}),e.jsx("div",{className:"agent-board-name",children:n.name}),e.jsx("div",{className:"agent-board-id",children:n.id}),e.jsxs("div",{className:"agent-board-health",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]})]})},n.id)})}):e.jsx("div",{className:"agent-list",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-card",n.state),$=Je(n.runtimeConfig?.heartbeatIntervalMs),ee=Bt($),_e=ke===n.id;return e.jsxs("div",{className:`agent-card ${k}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:N=>N.key==="Enter"&&_(n.id),children:[ve===n.id?e.jsx("select",{ref:ne,className:"select agent-role-select",value:n.role,onChange:N=>void Ie(n.id,N.target.value),onKeyDown:N=>i(N,n.id),onBlur:()=>W(null),autoFocus:!0,children:ze.map(N=>e.jsxs("option",{value:N.value,children:[N.icon," ",N.label]},N.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:N=>{N.stopPropagation(),W(n.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.stopPropagation(),W(n.id))},children:Se(n.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:n.name}),e.jsx("span",{className:"agent-id text-secondary",children:n.id})]}),e.jsx(ht,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${d}`,children:n.state}),e.jsxs("span",{className:"badge",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]}),e.jsx("span",{className:"badge text-secondary",children:pe(n.role)}),(()=>{const N=Ae(n);if(N.length===0)return null;const te=N.slice(0,2),Ce=N.length-2;return e.jsxs(e.Fragment,{children:[te.map(tt=>e.jsx("span",{className:"badge badge-skill",children:tt},tt)),Ce>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",Ce]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[n.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:n.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),oe===n.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:ce[n.id]??"",onChange:N=>ae(te=>({...te,[n.id]:N.target.value})),onKeyDown:N=>{N.key==="Enter"?R(n):N.key==="Escape"&&(U(null),ae(te=>{const Ce={...te};return delete Ce[n.id],Ce}))},disabled:_e,"aria-label":`Custom heartbeat interval in minutes for ${n.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void R(n),disabled:_e,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{U(null),ae(N=>{const te={...N};return delete te[n.id],te})},disabled:_e,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:$,onChange:N=>{const te=N.target.value;te==="__custom__"?Y(n):x(n,Number(te))},disabled:_e,"aria-label":`Set heartbeat interval for ${n.name}`,children:[ee.map(N=>e.jsx("option",{value:N.value,children:N.label},N.value)),Gt.some(N=>N.value===$)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),_e&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),n.lastHeartbeatAt&&(()=>{const N=new Date(n.lastHeartbeatAt),te=new Date(N.getTime()+$),Ce=n.state==="active"||n.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:N.toLocaleString(),children:["Last: ",N.toLocaleTimeString()]}),Ce&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:te.toLocaleString(),children:["Next: ",te.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[n.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Activate",children:[e.jsx($e,{size:14})," Start"]}),n.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void Pe(n.id,n.name),disabled:H.has(n.id),title:"Run Now","aria-label":`Run now for ${n.name}`,children:[e.jsx(Te,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Resume",children:[e.jsx($e,{size:14})," Resume"]}),n.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${n.name}`,children:[e.jsx(Te,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Retry",children:[e.jsx($e,{size:14})," Retry"]}),n.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Start",children:[e.jsx($e,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>_(n.id),title:`View details for ${n.name}`,"aria-label":`View details for ${n.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void Me(n.id,n.name),title:"Delete",children:[e.jsx(Qt,{size:14})," Delete"]})]})]},n.id)})})]}),E&&e.jsx(a.Suspense,{fallback:null,children:e.jsx(Gn,{agentId:E,projectId:l,onClose:B,addToast:s,onChildClick:G})})]})}export{ta as AgentsView};
@@ -0,0 +1 @@
1
+ import{r as s,j as t}from"./vendor-react-K0fH_qHe.js";import{i as He,aL as Pt,g as Et,aM as Ft,a as Lt,aN as _t,aO as It,aP as Ot,aQ as Ut,aR as zt,aS as Ht,s as Vt,aT as Bt,aU as qt,aV as Gt,aW as Wt,ab as rt,ac as lt,S as Kt,V as Ze,J as et,ao as Jt,aX as Yt,B as Pe,a8 as ot,a9 as ct,aY as Qt,aZ as Xt,a_ as Zt,a$ as es,b0 as ts,b1 as ss,b2 as ns,b3 as tt,h as as,u as st,k as is}from"./index-DH3aprf6.js";import"./vendor-xterm-DzcZoU0P.js";const ze="kb-chat-active-session";function rs(a){const i=a?.toolCalls;if(!Array.isArray(i))return;const r=i.map(l=>{if(!l||typeof l!="object")return null;const c=l,N=typeof c.toolName=="string"?c.toolName:"";if(!N)return null;const j=c.args;return{toolName:N,...j&&typeof j=="object"?{args:j}:{},isError:!!c.isError,result:c.result,status:"completed"}}).filter(l=>l!==null);return r.length>0?r:void 0}function nt(a){return{id:a.id,sessionId:a.sessionId,role:a.role,content:a.content,thinkingOutput:a.thinkingOutput,toolCalls:rs(a.metadata),attachments:a.attachments,createdAt:a.createdAt}}function ls(a){const[i,r]=s.useState([]),[l,c]=s.useState(null),[N,j]=s.useState(!0),[R,k]=s.useState([]),[P,I]=s.useState(!1),[x,F]=s.useState(!1),[T,$]=s.useState(""),[g,v]=s.useState(""),[C,y]=s.useState([]),[B,E]=s.useState(""),[X,W]=s.useState(""),[L,Y]=s.useState(!0),[h,M]=s.useState(new Map),w=s.useRef(null),_=s.useRef(!1),z=s.useRef(""),te=s.useRef(null),he=s.useRef(i),xe=s.useRef(l),ve=s.useRef(x);he.current=i,xe.current=l,ve.current=x,s.useEffect(()=>{z.current=B},[B]);const we=s.useRef(new Set),me=s.useRef(0),ke=s.useRef(a);ke.current!==a&&(ke.current=a,me.current++),s.useEffect(()=>{const d=me.current;He(void 0,a).then(f=>{if(me.current!==d)return;const p=new Map;for(const S of f)p.set(S.id,S);M(p)}).catch(()=>{})},[a]);const K=s.useCallback(async()=>{j(!0);try{const f=[...(await Pt(a)).sessions].sort((p,S)=>new Date(S.updatedAt).getTime()-new Date(p.updatedAt).getTime());r(f)}catch{}finally{j(!1)}},[a]);s.useEffect(()=>{K()},[K]);const se=s.useRef(()=>{});s.useEffect(()=>{if(N)return;const d=Et(ze,a);d&&i.find(p=>p.id===d)&&se.current(d)},[N,i,a]);const oe=s.useCallback(async(d,f)=>{I(!0);try{const p=await Ft(d,{limit:50,...f},a),S=p.messages.map(nt);f?.offset&&f.offset>0?k(q=>[...S,...q]):k(S),Y(p.messages.length>=50)}catch{}finally{I(!1)}},[a]),ne=s.useCallback(()=>{te.current?.(),te.current=null,z.current="",E(""),$(""),v(""),y([]),F(!1)},[]),ae=s.useCallback((d,f)=>{w.current&&(w.current.close(),w.current=null);const p=f??i.find(S=>S.id===d);c(p||null),ne(),Y(!0),d?oe(d):k([]),d?Lt(ze,d,a):_t(ze,a)},[i,oe,a,ne]);se.current=ae;const fe=s.useCallback(async d=>{const f=await It(d,a);w.current&&(w.current.close(),w.current=null);const p={id:f.session.id,title:f.session.title,agentId:f.session.agentId,status:f.session.status,modelProvider:f.session.modelProvider,modelId:f.session.modelId,createdAt:f.session.createdAt,updatedAt:f.session.updatedAt};return r(S=>S.some(q=>q.id===p.id)?S:[p,...S]),ne(),ae(p.id,p),k([]),p},[a,ne,ae]),Se=s.useCallback(async d=>{await Ot(d,{status:"archived"},a),r(f=>f.filter(p=>p.id!==d)),l?.id===d&&(c(null),k([]))},[l,a]),ce=s.useCallback(async d=>{l?.id===d&&w.current&&(w.current.close(),w.current=null),await Ut(d,a),r(f=>f.filter(p=>p.id!==d)),l?.id===d&&(c(null),k([]))},[l,a]),Z=s.useCallback(async()=>{!l||!L||await oe(l.id,{offset:R.length})},[l,L,oe,R.length]),de=s.useCallback(()=>{l&&(_.current=!0,te.current?.(),te.current=null,w.current?.close(),w.current=null,zt(l.id,a).catch(()=>{}),F(!1),$(""),v(""),y([]))},[l,a]),ye=s.useCallback(()=>{z.current="",E("")},[]),ue=s.useCallback((d,f)=>{if(!l)return;if(x){z.current=d,E(d);return}_.current=!1,w.current&&(w.current.close(),w.current=null);const p=`temp-${Date.now()}`,S={id:p,sessionId:l.id,role:"user",content:d,createdAt:new Date().toISOString()};k(m=>[...m,S]),$(""),v(""),y([]),F(!0);let q="",ge="",O=[],H=null,ie=null;const G=()=>{H=null,$(q)},u=()=>{ie=null,v(ge)},A=()=>{H!==null&&(cancelAnimationFrame(H),H=null),ie!==null&&(cancelAnimationFrame(ie),ie=null)};te.current=A;const V={onThinking:m=>{ge+=m,ie===null&&(ie=requestAnimationFrame(u))},onText:m=>{q+=m,H===null&&(H=requestAnimationFrame(G))},onToolStart:m=>{O=[...O,{toolName:m.toolName,args:m.args,isError:!1,status:"running"}],y(O)},onToolEnd:m=>{const D=[...O];for(let b=D.length-1;b>=0;b--){const ee=D[b];if(ee?.toolName===m.toolName&&ee.status==="running"){D[b]={...ee,status:"completed",isError:m.isError,result:m.result},O=D,y(D);return}}O=[...D,{toolName:m.toolName,isError:m.isError,result:m.result,status:"completed"}],y(O)},onDone:m=>{A();const D={id:m.messageId||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:q,thinkingOutput:ge,toolCalls:O.length>0?O:void 0,createdAt:new Date().toISOString()};we.current.add(D.id),k(ee=>[...ee,D]),$(""),v(""),y([]),F(!1),w.current=null,setTimeout(()=>{we.current.delete(D.id)},1e3),K();const b=z.current.trim();b&&(z.current="",E(""),ue(b))},onError:m=>{if(A(),k(D=>D.filter(b=>b.id!==p)),$(""),v(""),y([]),F(!1),w.current=null,console.error("[useChat] Stream error:",m),!_.current){const D=z.current.trim();D&&(z.current="",E(""),ue(D))}}};w.current=Ht(l.id,d,V,f,a)},[l,x,a,K]),Ne=X?i.filter(d=>d.title?.toLowerCase().includes(X.toLowerCase())||d.agentId.toLowerCase().includes(X.toLowerCase())):i;return s.useEffect(()=>{const d=me.current,f=a?`?projectId=${encodeURIComponent(a)}`:"",p=()=>me.current!==d,S=G=>{if(p())return;const u=JSON.parse(G.data);r(A=>A.some(V=>V.id===u.id)?A:[u,...A])},q=G=>{if(p())return;const u=JSON.parse(G.data);r(A=>[...A.map(m=>m.id===u.id?u:m)]),xe.current?.id===u.id&&c(u)},ge=G=>{if(p())return;const{id:u}=JSON.parse(G.data);r(A=>A.filter(V=>V.id!==u)),xe.current?.id===u&&(c(null),k([]))},O=G=>{if(p())return;const u=JSON.parse(G.data),A=nt(u);we.current.has(A.id)||xe.current?.id===A.sessionId&&!ve.current&&k(V=>V.some(m=>m.id===A.id)?V:[...V,A])},H=G=>{if(p())return;const{id:u}=JSON.parse(G.data);k(A=>A.filter(V=>V.id!==u))};return Vt(`/api/events${f}`,{events:{"chat:session:created":S,"chat:session:updated":q,"chat:session:deleted":ge,"chat:message:added":O,"chat:message:deleted":H}})},[a]),s.useEffect(()=>()=>{w.current&&(w.current.close(),w.current=null)},[]),{sessions:i,activeSession:l,sessionsLoading:N,messages:R,messagesLoading:P,isStreaming:x,streamingText:T,streamingThinking:g,streamingToolCalls:C,pendingMessage:B,selectSession:ae,createSession:fe,archiveSession:Se,deleteSession:ce,sendMessage:ue,stopStreaming:de,clearPendingMessage:ye,loadMoreMessages:Z,hasMoreMessages:L,searchQuery:X,setSearchQuery:W,filteredSessions:Ne,refreshSessions:K,agentsMap:h}}function dt(a){const i=new Date(a),l=new Date().getTime()-i.getTime(),c=Math.floor(l/1e3),N=Math.floor(c/60),j=Math.floor(N/60),R=Math.floor(j/24);return c<60?"just now":N<60?`${N}m ago`:j<24?`${j}h ago`:R<7?`${R}d ago`:i.toLocaleDateString()}function at(a,i){if(!a||!i)return null;const r=i.toLowerCase();if(r.includes("claude")){let c=i.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 c=c.replace(/\s+/g," "),c.length>30?c.slice(0,30)+"…":c}if(r.includes("gpt")||r.includes("openai")){const c=i.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 c.length>30?c.slice(0,30)+"…":c}if(r.includes("gemini")){const c=i.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 c.length>30?c.slice(0,30)+"…":c}const l=i.replace(/-/g," ").replace(/^\w/,c=>c.toUpperCase()).replace(/\s+/g," ").trim();return l.length>30?l.slice(0,30)+"…":l}function Re(a,i){return a.length<=i?a:`${a.slice(0,i)}…`}function os(a){if(!a)return null;const i=Object.entries(a);return i.length===0?null:i.map(([r,l])=>{const c=typeof l=="string"?l:(()=>{try{return JSON.stringify(l)}catch{return String(l)}})();return`${r}=${Re(c,50)}`}).join(", ")}function cs(a){if(a===void 0)return null;if(typeof a=="string")return Re(a,200);try{return Re(JSON.stringify(a),200)}catch{return Re(String(a),200)}}function ut(a){if(!a||a.length===0)return null;const i=(x,F)=>{const T=x.status==="running",$=x.status==="completed"&&x.isError,g=os(x.args),v=cs(x.result),C=T?g:v?`result: ${v}`:g?`args: ${g}`:null,y=T?"running":$?"error":"completed";return t.jsxs("details",{className:`chat-tool-call${T?" chat-tool-call--running":""}${$?" chat-tool-call--error":""}`,open:T,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",children:x.toolName}),C&&t.jsx("span",{className:"chat-tool-call-preview",title:C,children:C}),t.jsx("span",{className:"chat-tool-call-status-text",children:y})]}),t.jsxs("div",{className:"chat-tool-call-content",children:[g&&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:g})]}),v&&t.jsxs("div",{className:`chat-tool-call-row${$?" 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:v})]})]})]},`${x.toolName}-${F}`)},r="chat-tool-calls";if(a.length===1)return t.jsxs("div",{className:r,"data-testid":"chat-tool-calls",children:[t.jsxs("div",{className:"chat-tool-calls-header",children:[t.jsx(tt,{size:12,"aria-hidden":"true"}),t.jsx("span",{children:"Tool calls"})]}),i(a[0],0)]});const l=a.filter(x=>x.status==="running").length,c=a.filter(x=>x.status==="completed"&&x.isError).length,N=l>0,j=Array.from(new Set(a.map(x=>x.toolName))),R=j.slice(0,5),k=Math.max(0,j.length-R.length),P=k>0?`${R.join(", ")}, +${k} more`:R.join(", "),I=N?`(${l} running)`:c>0?`(${c} ${c===1?"error":"errors"})`:null;return t.jsx("div",{className:r,"data-testid":"chat-tool-calls",children:t.jsxs("details",{className:"chat-tool-calls-group","data-testid":"chat-tool-calls-group",open:N,children:[t.jsxs("summary",{className:"chat-tool-calls-group-summary",children:[t.jsx(tt,{size:12,"aria-hidden":"true"}),t.jsxs("span",{children:[a.length," tool calls"]}),t.jsx("span",{className:"chat-tool-calls-names",title:P,children:P}),I&&t.jsx("span",{className:"chat-tool-calls-group-status",children:I})]}),a.map((x,F)=>i(x,F))]})})}const ht={pre:({children:a,...i})=>t.jsx("pre",{...i,className:"chat-markdown-pre",children:a}),table:({children:a,...i})=>t.jsx("table",{...i,className:"chat-markdown-table",children:a})},De="__fn_agent__",ds=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function it(a){const i=/(^|[\s])\/([^\s]*)$/.exec(a);if(!i)return null;const r=i[1]??"",l=i[2]??"",c=i.index+r.length;return{filter:l,start:c,end:a.length}}function us(a,i){const r=a.slice(0,i),l=/(^|[\s\n])@([\w-]*)$/.exec(r);if(!l)return null;const c=l[2]??"",N=r.length-c.length-1;return{filter:c,start:N,end:i}}function hs({projectId:a,onClose:i,onCreate:r}){const[l,c]=s.useState("agent"),[N,j]=s.useState([]),[R,k]=s.useState(!0),[P,I]=s.useState(""),[x,F]=s.useState([]),[T,$]=s.useState(!0),[g,v]=s.useState(""),[C,y]=s.useState([]),[B,E]=s.useState([]);s.useEffect(()=>{let h=!1;return k(!0),He(void 0,a).then(M=>{h||j(M)}).catch(()=>{h||j([])}).finally(()=>{h||k(!1)}),()=>{h=!0}},[a]),s.useEffect(()=>{$(!0),as().then(h=>{F(h.models),y(h.favoriteProviders),E(h.favoriteModels)}).catch(()=>{F([]),y([]),E([])}).finally(()=>{$(!1)})},[]);const X=s.useCallback(async h=>{const M=C,_=M.includes(h)?M.filter(z=>z!==h):[h,...M];y(_);try{await st({favoriteProviders:_,favoriteModels:B})}catch{y(M)}},[C,B]),W=s.useCallback(async h=>{const M=B,_=M.includes(h)?M.filter(z=>z!==h):[h,...M];E(_);try{await st({favoriteProviders:C,favoriteModels:_})}catch{E(M)}},[B,C]),L=h=>{if(h.preventDefault(),l==="agent"){if(!P)return;r({agentId:P});return}if(!g)return;const M=g.indexOf("/");if(M<=0)return;const w=g.slice(0,M),_=g.slice(M+1);r({agentId:De,modelProvider:w,modelId:_})},Y=l==="agent"?!P:!g;return t.jsx("div",{className:"chat-new-dialog-backdrop",onClick:i,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-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${l==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{c("agent"),v("")},children:"Agent"}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{c("model"),I("")},children:"Model"})]}),t.jsxs("form",{onSubmit:L,children:[l==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",R?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):N.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:N.map(h=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${P===h.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>I(h.id),"data-testid":`agent-option-${h.id}`,children:[t.jsx(Pe,{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))})]}),l==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:T?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):t.jsx(is,{models:x,value:g,onChange:v,label:"Model",placeholder:"Select a model",favoriteProviders:C,onToggleFavorite:X,favoriteModels:B,onToggleModelFavorite:W})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:i,children:"Cancel"}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:Y,children:"Create"})]})]})]})})}const ms=s.memo(function({message:i,forcePlain:r,agentName:l,showAssistantModelTag:c,activeModelTag:N,activeSessionId:j,mentionAgentsByName:R,onToggleRender:k}){const P=i.role==="assistant",I=s.useMemo(()=>{if(P)return null;const T=i.content,$=/@([\w-]+)/g,g=[];let v=0,C=$.exec(T);for(;C;){const[y,B=""]=C,E=C.index;E>v&&g.push(T.slice(v,E));const X=B.replace(/_/g," ").toLowerCase(),W=R.get(X);W?g.push(t.jsxs("span",{className:"chat-mention-chip",children:["@",W.name.replace(/\s+/g,"_")]},`${W.id}-${E}`)):g.push(y),v=E+y.length,C=$.exec(T)}return v<T.length&&g.push(T.slice(v)),g.length===0?T:g},[P,i.content,R]),x=s.useMemo(()=>{const T=i.attachments;if(!T||T.length===0||!j)return null;const $=`/api/chat/sessions/${encodeURIComponent(j)}/attachments/`;return t.jsx("div",{className:"chat-message-attachments",children:T.map(g=>{const v=g.mimeType.startsWith("image/"),C=g.id||g.filename,y=`${$}${encodeURIComponent(g.filename)}`;return v?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:y,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:y,alt:g.originalName})},C):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:y,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(ns,{size:14}),t.jsx("span",{children:g.originalName})]},C)})})},[i.attachments,j]),F=s.useMemo(()=>P?r?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:i.content}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(rt,{remarkPlugins:[lt],components:ht,children:i.content})}):null,[P,r,i.content]);return t.jsxs("div",{className:`chat-message chat-message--${i.role}`,"data-testid":`chat-message-${i.id}`,children:[P&&t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(Pe,{size:14}),t.jsx("span",{children:l}),c&&N&&t.jsx("span",{className:"chat-model-tag",children:N}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${r?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":r?"Show rendered markdown":"Show plain text",onClick:()=>k(i.id),children:r?t.jsx(ot,{size:14}):t.jsx(ct,{size:14})})]}),P?F:t.jsx("div",{className:"chat-message-content",children:I}),ut(i.toolCalls),i.thinkingOutput&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:i.thinkingOutput})]}),x,t.jsx("div",{className:"chat-message-time",children:dt(i.createdAt)})]})});function ws({projectId:a,addToast:i}){const{activeSession:r,sessionsLoading:l,messages:c,messagesLoading:N,isStreaming:j,streamingText:R,streamingThinking:k,streamingToolCalls:P,selectSession:I,createSession:x,archiveSession:F,deleteSession:T,sendMessage:$,stopStreaming:g,pendingMessage:v,clearPendingMessage:C,searchQuery:y,setSearchQuery:B,filteredSessions:E}=ls(a),[X,W]=s.useState(!1),[L,Y]=s.useState(""),[h,M]=s.useState(null),[w,_]=s.useState(null),[z,te]=s.useState(!0),[he,xe]=s.useState(new Map),[ve,we]=s.useState([]),[me,ke]=s.useState(!0),[K,se]=s.useState(!1),[oe,ne]=s.useState(""),[ae,fe]=s.useState(0),[Se,ce]=s.useState(""),[Z,de]=s.useState(!1),[ye,ue]=s.useState(0),[Ne,d]=s.useState(-1),[f,p]=s.useState(()=>new Set),[S,q]=s.useState([]),[ge,O]=s.useState(!1),[,H]=s.useState(!1),[ie,G]=s.useState({top:0,left:0}),u=Bt({projectId:a}),A=s.useCallback(e=>{if(!e||!u.mentionActive)return;const n=e.getBoundingClientRect();G({top:n.top-260,left:n.left+8})},[u.mentionActive]),V=s.useRef(null),m=s.useRef(null),D=s.useRef(null),b=s.useRef(null),ee=s.useRef(!1),Me=s.useRef(!1),Ve=s.useRef(null),Be=s.useRef([]),je=s.useRef(0),re=qt()==="mobile",{keyboardOverlap:Ee,viewportHeight:qe,viewportOffsetTop:mt,keyboardOpen:Fe}=Gt({enabled:re&&!!r}),ft=Fe?{"--keyboard-overlap":`${Ee}px`,"--vv-offset-top":`${mt}px`,...qe!==null?{"--vv-height":`${qe}px`}:{}}:{},Q=s.useMemo(()=>{const e=oe.trim().toLowerCase();return(e?ve.filter(o=>o.name.toLowerCase().includes(e)):ve).slice(0,10)},[ve,oe]),be=s.useMemo(()=>Array.from(he.values()),[he]),pe=s.useMemo(()=>{const e=Se.trim().toLowerCase();return e?be.filter(n=>n.name.toLowerCase().includes(e)):be},[be,Se]),gt=s.useMemo(()=>{const e=new Map;for(const n of be)e.set(n.name.toLowerCase(),n);return e},[be]);s.useEffect(()=>{fe(0)},[Q]),s.useEffect(()=>{ue(0)},[Se,Z]),s.useEffect(()=>()=>{m.current!==null&&window.clearTimeout(m.current)},[]),s.useEffect(()=>{const e=D.current;e&&(e.scrollTop=e.scrollHeight)},[c,R]),s.useEffect(()=>{if(Ee<=0)return;const e=D.current;e&&(e.scrollTop=e.scrollHeight)},[Ee]),s.useEffect(()=>{if(!re||!Fe)return;const e=document.documentElement,n=document.body,o={htmlOverflow:e.style.overflow,bodyOverflow:n.style.overflow};return e.style.overflow="hidden",n.style.overflow="hidden",()=>{e.style.overflow=o.htmlOverflow,n.style.overflow=o.bodyOverflow}},[re,Fe]),s.useEffect(()=>{const e=()=>M(null);if(h)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[h]),s.useEffect(()=>{let e=!1;const n=a;return He(void 0,a).then(o=>{if(e||n!==a)return;const U=new Map;for(const J of o)U.set(J.id,J);xe(U)}).catch(()=>{}),()=>{e=!0}},[a]),s.useEffect(()=>{let e=!1;return ke(!0),Wt(a).then(n=>{e||we(n)}).catch(()=>{e||we([])}).finally(()=>{e||ke(!1)}),()=>{e=!0}},[a]),s.useEffect(()=>{Be.current=S},[S]),s.useEffect(()=>()=>{for(const e of Be.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl)},[]);const Te=s.useCallback(e=>{if(!e||e.length===0)return;const n=[];for(const o of Array.from(e)){if(!ds.includes(o.type))continue;const U=o.type.startsWith("image/");n.push({file:o,previewUrl:U?URL.createObjectURL(o):""})}n.length>0&&q(o=>[...o,...n])},[]),pt=s.useCallback(e=>{q(n=>{const o=n[e];return o?.previewUrl&&URL.revokeObjectURL(o.previewUrl),n.filter((U,J)=>J!==e)})},[]),xt=s.useCallback(e=>{const n=e.clipboardData?.files;if(!n||n.length===0)return;const o=Array.from(n).filter(U=>U.type.startsWith("image/"));o.length!==0&&Te(o)},[Te]),vt=s.useCallback(async e=>{try{await x(e),W(!1),re&&te(!1)}catch{i("Failed to create chat session","error")}},[x,i,re]),Le=s.useCallback(()=>{Y(""),se(!1),ne(""),de(!1),ce(""),d(-1),q(e=>{for(const n of e)n.previewUrl&&URL.revokeObjectURL(n.previewUrl);return[]})},[]),Ce=s.useCallback(()=>{const e=L.trim(),n=S.map(o=>o.file);if(!(!e&&n.length===0||!r)){if(e==="/clear"){Le(),g(),C(),x({agentId:r.agentId,modelProvider:r.modelProvider??void 0,modelId:r.modelId??void 0}).catch(()=>{i("Failed to clear conversation","error")});return}Le(),$(e,n)}},[L,S,r,Le,g,C,x,i,$]),Ae=s.useCallback(()=>{if(typeof window>"u"||window.innerWidth>768)return;const e=b.current;if(!e||e.disabled)return;const n=window.scrollX,o=window.scrollY;e.focus({preventScroll:!0}),window.requestAnimationFrame(()=>{(window.scrollX!==n||window.scrollY!==o)&&window.scrollTo(n,o)})},[]),Ge=s.useCallback(()=>{typeof window>"u"||window.innerWidth>768||(ee.current=!0)},[]),_e=s.useCallback(e=>{Y(n=>{const o=it(n);if(!o)return n;const U=`/skill:${e.name} `,J=n.slice(0,o.start)+U+n.slice(o.end);return window.requestAnimationFrame(()=>{b.current&&(b.current.style.height="auto",b.current.style.height=`${Math.min(b.current.scrollHeight,120)}px`,b.current.focus())}),J}),se(!1),ne(""),fe(0)},[]),Ie=s.useCallback(e=>{const n=b.current;if(!n||Ne<0)return;const o=n.selectionStart??je.current,U=n.selectionEnd??o,J=Math.max(o,U),Ye=Math.min(Ne,J),Qe=`${`@${e.name.replace(/\s+/g,"_")}`} `,Dt=L.slice(0,Ye)+Qe+L.slice(J),Xe=Ye+Qe.length;Y(Dt),de(!1),ce(""),ue(0),d(-1),window.requestAnimationFrame(()=>{b.current&&(b.current.style.height="auto",b.current.style.height=`${Math.min(b.current.scrollHeight,120)}px`,b.current.focus(),b.current.setSelectionRange(Xe,Xe))})},[Ne,L]),wt=s.useCallback(e=>{if(je.current=e.currentTarget.selectionStart??je.current,u.mentionActive&&u.files.length>0){if(u.handleKeyDown(e,L),e.key==="Enter"||e.key==="Tab"){const n=u.files[u.selectedIndex];if(n){const o=u.selectFile(n,L);Y(o),u.dismissMention(),H(!1)}}return}if(Z&&e.key==="ArrowDown"){e.preventDefault(),pe.length>0&&ue(n=>(n+1)%pe.length);return}if(Z&&e.key==="ArrowUp"){e.preventDefault(),pe.length>0&&ue(n=>n===0?pe.length-1:n-1);return}if(Z&&e.key==="Enter"){e.preventDefault();const n=pe[ye]??pe[0];n&&Ie(n);return}if(Z&&e.key==="Escape"){e.preventDefault(),de(!1),ce(""),d(-1);return}if(K&&e.key==="ArrowDown"){e.preventDefault(),Q.length>0&&fe(n=>(n+1)%Q.length);return}if(K&&e.key==="ArrowUp"){e.preventDefault(),Q.length>0&&fe(n=>n===0?Q.length-1:n-1);return}if(K&&(e.key==="Enter"||e.key==="Tab")&&Q.length>0){e.preventDefault();const n=Q[ae]??Q[0];n&&_e(n);return}if(K&&e.key==="Escape"){e.preventDefault(),se(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Ce())},[Z,pe,ye,Ie,K,Q,ae,_e,Ce,u,L]),$e=s.useCallback((e,n)=>{const o=us(e,n);if(o){de(!0),ce(o.filter),d(o.start);return}de(!1),ce(""),d(-1)},[]),St=s.useCallback(e=>{const n=e.target,o=n.value,U=n.selectionStart??o.length;je.current=U,Y(o);const J=it(o);J?(se(!0),ne(J.filter)):(se(!1),ne("")),$e(o,U),u.detectMention(o,U),H(u.mentionActive),u.mentionActive&&A(n),n.style.height="auto",n.style.height=`${Math.min(n.scrollHeight,120)}px`},[$e]),Oe=s.useCallback(e=>{const n=e.currentTarget,o=n.selectionStart??n.value.length;je.current=o,$e(n.value,o),u.detectMention(n.value,o),H(u.mentionActive),u.mentionActive&&A(n)},[$e,u,A]),bt=s.useCallback(e=>{e.key!=="Escape"&&Oe(e)},[Oe]),kt=s.useCallback(()=>{if(ee.current){window.requestAnimationFrame(()=>{Ae()});return}m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{se(!1),de(!1),ce(""),d(-1),H(!1),u.dismissMention(),m.current=null},120)},[u,Ae]),yt=s.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),Nt=s.useCallback(async e=>{M(null);try{await F(e),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[F,i]),jt=s.useCallback(async e=>{_(null),M(null);try{await T(e),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[T,i]),Ct=s.useCallback(e=>{I(e),re&&te(!1)},[I,re]),Mt=s.useCallback(()=>{I(""),te(!0)},[I]),Tt=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(ss,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>W(!0),children:[t.jsx(et,{size:16}),"New Chat"]})]}),le=at(r?.modelProvider,r?.modelId),We=r?.agentId===De?le??"Fusion":r?.title||he.get(r?.agentId??"")?.name||r?.agentId||"Chat",At=!!(le&&le!==We),Ue=he.get(r?.agentId??"")?.name||(r?.agentId===De?le??"Fusion":r?.agentId?.slice(0,30)??"Fusion"),Ke=!!(le&&le!==Ue),$t=v.length>50?`${v.slice(0,50)}…`:v,Je=s.useCallback(e=>{p(n=>{const o=new Set(n);return o.has(e)?o.delete(e):o.add(e),o})},[]),Rt=s.useCallback((e,n=!1)=>n?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(rt,{remarkPlugins:[lt],components:ht,children:e})}),[]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${z?"":" chat-sidebar--hidden"}`,children:[t.jsx("div",{className:"chat-sidebar-search",children:t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(Kt,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:y,onChange:e=>B(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:l?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):E.length===0?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):E.map(e=>t.jsxs("div",{className:`chat-session-item${r?.id===e.id?" chat-session-item--active":""}`,onClick:()=>Ct(e.id),onContextMenu:n=>{n.preventDefault(),M({sessionId:e.id,x:n.clientX,y:n.clientY})},"data-testid":`chat-session-${e.id}`,children:[t.jsx("button",{className:"chat-session-delete-btn",onClick:n=>{n.stopPropagation(),_(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(Ze,{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.jsx("span",{children:he.get(e.agentId)?.name||(e.agentId===De?at(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))}),t.jsx("span",{children:e.updatedAt?dt(e.updatedAt):""})]})]},e.id))}),t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>W(!0),"data-testid":"chat-new-btn",children:[t.jsx(et,{size:14}),"New Chat"]})})]}),h&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:h.y,left:h.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>Nt(h.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Jt,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{M(null),_(h.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(Ze,{size:14}),"Delete"]})]}),w&&t.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>_(null),children:t.jsxs("div",{className:"chat-new-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Conversation?"}),t.jsx("p",{style:{fontSize:"14px",color:"var(--text-secondary)",marginBottom:"16px"},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:()=>_(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void jt(w),children:"Delete"})]})]})}),t.jsxs("div",{className:"chat-thread",style:ft,children:[(r||!re)&&t.jsxs("div",{className:"chat-thread-header",children:[re&&r&&t.jsx("button",{className:"btn-icon",onClick:Mt,"data-testid":"chat-back-btn",children:t.jsx(Yt,{size:16})}),t.jsx(Pe,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:We}),At&&t.jsx("span",{className:"chat-model-tag",children:le})]}),t.jsxs("div",{className:"chat-messages",ref:D,children:[N?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):c.length===0&&!r?Tt():c.length===0&&r?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):t.jsxs(t.Fragment,{children:[c.map(e=>t.jsx(ms,{message:e,forcePlain:f.has(e.id),agentName:Ue,showAssistantModelTag:Ke,activeModelTag:le,activeSessionId:r?.id??null,mentionAgentsByName:gt,onToggleRender:Je},e.id)),j&&t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(Pe,{size:14}),t.jsx("span",{children:Ue}),Ke&&t.jsx("span",{className:"chat-model-tag",children:le}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${f.has("__streaming__")?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":f.has("__streaming__")?"Show rendered markdown":"Show plain text",onClick:()=>Je("__streaming__"),children:f.has("__streaming__")?t.jsx(ot,{size:14}):t.jsx(ct,{size:14})})]}),R?Rt(R,f.has("__streaming__")):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:k?"Thinking…":"Connecting…"}),ut(P),k&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:k})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}),t.jsx("div",{ref:V})]}),r&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Ve,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{Te(e.target.files),e.target.value=""}}),K&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:me?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):Q.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:oe?"No skills found":"No skills available"}):Q.map((e,n)=>t.jsxs("button",{type:"button",role:"option","aria-selected":n===ae,className:`chat-skill-menu-item${n===ae?" chat-skill-menu-item--highlighted":""}`,onMouseDown:o=>o.preventDefault(),onMouseEnter:()=>fe(n),onClick:()=>_e(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))}),S.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:S.map((e,n)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${n}`,children:[e.previewUrl?t.jsx("img",{src:e.previewUrl,alt:e.file.name}):t.jsx("span",{className:"chat-attachment-preview-name",children:e.file.name}),t.jsx("button",{type:"button",className:"chat-attachment-remove",onClick:()=>pt(n),"data-testid":`chat-attachment-remove-${n}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${n}`))}),t.jsxs("div",{className:"chat-input-row",children:[t.jsx("button",{type:"button",className:"btn-icon chat-attach-btn","data-testid":"chat-attach-btn","aria-label":"Attach files",onClick:()=>Ve.current?.click(),children:t.jsx(Qt,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${ge?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),O(!0)},onDragLeave:()=>O(!1),onDrop:e=>{e.preventDefault(),O(!1),Te(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:b,className:"chat-input-textarea",placeholder:"Type a message...",value:L,onChange:St,onKeyDown:wt,onKeyUp:bt,onClick:Oe,onBlur:kt,onFocus:yt,onPaste:xt,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(Xt,{agents:be,filter:Se,highlightedIndex:ye,visible:Z,onSelect:Ie,position:"below"}),t.jsx(Zt,{visible:u.mentionActive&&!Z,position:ie,files:u.files,selectedIndex:u.selectedIndex,onSelect:e=>{const n=u.selectFile(e,L);Y(n),u.dismissMention(),H(!1),b.current?.focus()},loading:u.loading}),v&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${$t}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:C,children:"×"})]})]}),j?t.jsx("button",{className:"chat-input-stop",onClick:g,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(es,{size:14})}):t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{typeof window>"u"||window.innerWidth>768||(e.preventDefault(),e.pointerType&&e.pointerType!=="mouse"&&(Me.current=!0,Ge(),Ae(),Ce(),window.setTimeout(()=>{ee.current=!1},1500)))},onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||(e.preventDefault(),Me.current=!0,Ge(),Ae(),Ce(),window.setTimeout(()=>{ee.current=!1},1500))},onMouseDown:e=>{typeof window>"u"||window.innerWidth>768||e.preventDefault()},onClick:()=>{if(Me.current){Me.current=!1;return}Ce()},disabled:!L.trim()&&S.length===0,"data-testid":"chat-send-btn",children:t.jsx(ts,{size:16})})]})]})]}),X&&t.jsx(hs,{projectId:a,onClose:()=>W(!1),onCreate:vt})]})}export{ws as ChatView};