@runfusion/fusion 0.28.0 → 0.28.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 (43) hide show
  1. package/dist/bin.js +0 -27
  2. package/dist/client/assets/{AgentDetailView-V32TpEe1.js → AgentDetailView-DG01uRND.js} +1 -1
  3. package/dist/client/assets/{AgentsView-CxITZE-U.js → AgentsView-B6IKroR1.js} +3 -3
  4. package/dist/client/assets/{ChatView-7WPHyB_7.js → ChatView-DKstOyUm.js} +1 -1
  5. package/dist/client/assets/{DevServerView-Diw4hjw0.js → DevServerView-DQQcGd2N.js} +1 -1
  6. package/dist/client/assets/{DirectoryPicker-CWSApoLU.js → DirectoryPicker-BfShQutV.js} +1 -1
  7. package/dist/client/assets/{DocumentsView-1kr0dhsV.js → DocumentsView-C4Ky-ZkQ.js} +1 -1
  8. package/dist/client/assets/{EvalsView-cDfXYiK6.js → EvalsView-B-z_KLLW.js} +1 -1
  9. package/dist/client/assets/{ExperimentalAgentOnboardingModal-lNSf6UtY.js → ExperimentalAgentOnboardingModal-CtR7eRBv.js} +1 -1
  10. package/dist/client/assets/{InsightsView-D2AjxOnu.js → InsightsView-BGbXkJpz.js} +1 -1
  11. package/dist/client/assets/{MemoryView-Dq4yjIPI.js → MemoryView-CRbaCcG_.js} +1 -1
  12. package/dist/client/assets/{NodesView-Cpmkze7n.js → NodesView-Hjxwv7rE.js} +1 -1
  13. package/dist/client/assets/{PiExtensionsManager-oi9FHT0y.js → PiExtensionsManager-ckNj1Wvv.js} +1 -1
  14. package/dist/client/assets/{PluginManager-o12KG4e8.js → PluginManager-CpY9rYNq.js} +1 -1
  15. package/dist/client/assets/{ResearchView-C9bjVB7-.js → ResearchView-BMxwiVk9.js} +1 -1
  16. package/dist/client/assets/{SettingsModal-Cu93Jjho.js → SettingsModal-3Jxv4PMI.js} +3 -3
  17. package/dist/client/assets/{SettingsModal-CT01a5Rh.js → SettingsModal-Bqfq-gnu.js} +1 -1
  18. package/dist/client/assets/{SetupWizardModal-Agi3XNtZ.js → SetupWizardModal-SVUr5Mpm.js} +1 -1
  19. package/dist/client/assets/{SkillsView-DmZfbGLs.js → SkillsView-COs7muvr.js} +1 -1
  20. package/dist/client/assets/{StashRecoveryView-BwKJQaUW.js → StashRecoveryView-BhB_6Fvq.js} +1 -1
  21. package/dist/client/assets/{TodoView-uJRg4Cnl.js → TodoView-CDtkPdrq.js} +1 -1
  22. package/dist/client/assets/{dashboard-view-C7Snlgow.js → dashboard-view-Czurx3BJ.js} +1 -1
  23. package/dist/client/assets/{folder-open-DU-Ec_iC.js → folder-open-D8Qfxakh.js} +1 -1
  24. package/dist/client/assets/{index-DiewofJh.js → index-u6AOHWO5.js} +5 -5
  25. package/dist/client/assets/{star-Qi0GspVN.js → star-BkCn1oUu.js} +1 -1
  26. package/dist/client/assets/{upload-Dx_l9Vbu.js → upload-BHiYszS2.js} +1 -1
  27. package/dist/client/assets/{users-3Qw_TMah.js → users-Ch_Fnf5M.js} +1 -1
  28. package/dist/client/index.html +1 -1
  29. package/dist/client/version.json +1 -1
  30. package/dist/droid-cli/package.json +1 -1
  31. package/dist/extension.js +0 -27
  32. package/dist/pi-claude-cli/package.json +1 -1
  33. package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
  34. package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
  35. package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
  36. package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
  37. package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
  38. package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
  39. package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
  40. package/dist/plugins/fusion-plugin-reports/package.json +1 -1
  41. package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
  42. package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
  43. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -35535,16 +35535,6 @@ function readStateRows(db) {
35535
35535
  return [];
35536
35536
  }
35537
35537
  }
35538
- function readCommittedReservations(db) {
35539
- if (!hasTable(db, "distributed_task_id_reservations")) {
35540
- return [];
35541
- }
35542
- try {
35543
- return db.prepare("SELECT prefix, taskId, status FROM distributed_task_id_reservations WHERE status = 'committed'").all();
35544
- } catch {
35545
- return [];
35546
- }
35547
- }
35548
35538
  function readDuplicateActiveIds(db) {
35549
35539
  if (!hasTable(db, "tasks")) {
35550
35540
  return [];
@@ -35651,23 +35641,6 @@ function detectTaskIdIntegrityAnomalies(db) {
35651
35641
  }
35652
35642
  }
35653
35643
  }
35654
- const existingIds = new Set(allRows.map((row) => row.id));
35655
- const committedReservationsByPrefix = /* @__PURE__ */ new Map();
35656
- for (const row of readCommittedReservations(db)) {
35657
- if (!existingIds.has(row.taskId)) {
35658
- continue;
35659
- }
35660
- const prefix = row.prefix.trim().toUpperCase() || parseTaskId2(row.taskId)?.prefix || "unknown";
35661
- committedReservationsByPrefix.set(prefix, [...committedReservationsByPrefix.get(prefix) ?? [], row.taskId]);
35662
- }
35663
- for (const [prefix, affectedIds] of committedReservationsByPrefix) {
35664
- anomalies.push({
35665
- kind: "committed_reservation_for_existing_id",
35666
- prefix,
35667
- affectedIds: uniqueSorted(affectedIds),
35668
- details: `Committed reservation rows still reference task IDs that already exist for prefix ${prefix}.`
35669
- });
35670
- }
35671
35644
  return buildReport(checkedAt, anomalies);
35672
35645
  } catch {
35673
35646
  return buildReport(checkedAt, []);
@@ -1,4 +1,4 @@
1
- import{r as t,j as e}from"./vendor-react-K0fH_qHe.js";import{c as $s,dE as Ct,dF as wt,dG as Rt,dH as Mt,L as V,R as Ns,ar as Vs,Z as At,as as ks,W as bs,a as at,b as nt,dI as Ft,dJ as Et,dK as Tt,v as it,cN as $t,dL as Pt,z as K,dM as Lt,dN as lt,dO as rt,dP as Dt,i as ps,D as Js,s as gs,bt as ot,k as ct,U as Cs,A as vs,V as Ws,aS as Ve,dQ as zt,X as dt,F as es,dR as Bt,ck as ut,dS as mt,dT as Ot,cH as Ht,ap as It,bs as Ut,at as ht,B as Ps,Y as _t,a2 as Gs,a3 as Vt,a4 as Jt,dU as Es,l as ft,dV as Wt,bE as Gt,r as qt,aq as gt,a1 as xt,dW as Kt,C as ue,dX as bt,dY as qs,bv as Ks,dZ as Yt,d_ as Zt,d$ as Xt,e0 as ss,a9 as ts,ab as as,ac as ns,a7 as pt,e1 as Qt,e2 as ea,h as sa,j as Ys,$ as ta,e3 as aa,e4 as na,m as ia,e5 as Ts,e6 as la,e7 as ra,O as oa,e8 as ca,e9 as da,ea as vt,eb as ua,ec as ma,ed as ha,ee as fa,ef as ga}from"./index-DiewofJh.js";import{S as jt}from"./star-Qi0GspVN.js";import{f as ws,S as xa,E as ba}from"./ExperimentalAgentOnboardingModal-lNSf6UtY.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ import{r as t,j as e}from"./vendor-react-K0fH_qHe.js";import{c as $s,dE as Ct,dF as wt,dG as Rt,dH as Mt,L as V,R as Ns,ar as Vs,Z as At,as as ks,W as bs,a as at,b as nt,dI as Ft,dJ as Et,dK as Tt,v as it,cN as $t,dL as Pt,z as K,dM as Lt,dN as lt,dO as rt,dP as Dt,i as ps,D as Js,s as gs,bt as ot,k as ct,U as Cs,A as vs,V as Ws,aS as Ve,dQ as zt,X as dt,F as es,dR as Bt,ck as ut,dS as mt,dT as Ot,cH as Ht,ap as It,bs as Ut,at as ht,B as Ps,Y as _t,a2 as Gs,a3 as Vt,a4 as Jt,dU as Es,l as ft,dV as Wt,bE as Gt,r as qt,aq as gt,a1 as xt,dW as Kt,C as ue,dX as bt,dY as qs,bv as Ks,dZ as Yt,d_ as Zt,d$ as Xt,e0 as ss,a9 as ts,ab as as,ac as ns,a7 as pt,e1 as Qt,e2 as ea,h as sa,j as Ys,$ as ta,e3 as aa,e4 as na,m as ia,e5 as Ts,e6 as la,e7 as ra,O as oa,e8 as ca,e9 as da,ea as vt,eb as ua,ec as ma,ed as ha,ee as fa,ef as ga}from"./index-u6AOHWO5.js";import{S as jt}from"./star-BkCn1oUu.js";import{f as ws,S as xa,E as ba}from"./ExperimentalAgentOnboardingModal-CtR7eRBv.js";import"./vendor-xterm-DzcZoU0P.js";/**
2
2
  * @license lucide-react v1.7.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-V32TpEe1.js","assets/vendor-react-K0fH_qHe.js","assets/index-DiewofJh.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-CD0_dkME.css","assets/star-Qi0GspVN.js","assets/ExperimentalAgentOnboardingModal-lNSf6UtY.js","assets/ExperimentalAgentOnboardingModal-B-APN_lM.css","assets/AgentDetailView-DSpIqBOs.css"])))=>i.map(i=>d[i]);
2
- import{c as Ue,A as De,C as Je,Z as Zt,s as qt,r as ht,F as pt,f as Jt,a as Qt,b as zt,B as xt,u as Dt,d as nt,e as Xt,g as Yt,h as es,i as ts,j as Ct,k as Xe,P as ss,l as as,m as ns,n as ls,o as St,G as is,S as rs,L as lt,T as it,R as Ve,X as At,p as os,q as cs,t as Tt,v as ds,w as us,x as ms,y as gs,z as fe,D as rt,E as hs,H as ps,N as xs,I as Rt,J as bs,M as vs,K as js,O as fs,Q as Ns,U as ot,V as Mt,W as ys,_ as ks,Y as ws,$ as Ze,a0 as Cs,a1 as Et,a2 as Ss,a3 as As,a4 as Ts}from"./index-DiewofJh.js";import{r as a,j as e,a as Rs}from"./vendor-react-K0fH_qHe.js";import{A as Ms,S as Es,E as _s,f as $s}from"./ExperimentalAgentOnboardingModal-lNSf6UtY.js";import{U as bt}from"./upload-Dx_l9Vbu.js";import{F as Ls}from"./folder-open-DU-Ec_iC.js";import"./vendor-xterm-DzcZoU0P.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-DG01uRND.js","assets/vendor-react-K0fH_qHe.js","assets/index-u6AOHWO5.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-CD0_dkME.css","assets/star-BkCn1oUu.js","assets/ExperimentalAgentOnboardingModal-CtR7eRBv.js","assets/ExperimentalAgentOnboardingModal-B-APN_lM.css","assets/AgentDetailView-DSpIqBOs.css"])))=>i.map(i=>d[i]);
2
+ import{c as Ue,A as De,C as Je,Z as Zt,s as qt,r as ht,F as pt,f as Jt,a as Qt,b as zt,B as xt,u as Dt,d as nt,e as Xt,g as Yt,h as es,i as ts,j as Ct,k as Xe,P as ss,l as as,m as ns,n as ls,o as St,G as is,S as rs,L as lt,T as it,R as Ve,X as At,p as os,q as cs,t as Tt,v as ds,w as us,x as ms,y as gs,z as fe,D as rt,E as hs,H as ps,N as xs,I as Rt,J as bs,M as vs,K as js,O as fs,Q as Ns,U as ot,V as Mt,W as ys,_ as ks,Y as ws,$ as Ze,a0 as Cs,a1 as Et,a2 as Ss,a3 as As,a4 as Ts}from"./index-u6AOHWO5.js";import{r as a,j as e,a as Rs}from"./vendor-react-K0fH_qHe.js";import{A as Ms,S as Es,E as _s,f as $s}from"./ExperimentalAgentOnboardingModal-CtR7eRBv.js";import{U as bt}from"./upload-BHiYszS2.js";import{F as Ls}from"./folder-open-D8Qfxakh.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.
@@ -31,4 +31,4 @@ reportsTo: null
31
31
  skills:
32
32
  - review
33
33
  ---
34
- Agent instructions go here...`,value:N,onChange:l=>{b("paste"),C([]),k(l.target.value),z(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",o]}),ce&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(it,{size:14}),ce]})]}),g==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:w})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(pt,{size:14}),e.jsxs("span",{children:[T.length," agent",T.length!==1?"s":""," found"]})]}),T.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(T.map(l=>l.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((l,x)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${l.name}`,checked:p.includes(l.name),onChange:()=>Se(l.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:l.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:l.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[l.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[l.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:l.role}),l.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",l.reportsTo]}),l.skills&&l.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",l.skills.join(", ")]})]}),l.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[l.instructionsText.slice(0,100),l.instructionsText.length>100?"...":""]})]})]},x))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),S.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(pt,{size:14}),e.jsxs("span",{children:[S.length," skill",S.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>ee(S.map(l=>l.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>ee([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((l,x)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${l.name}`,checked:$.includes(l.name),onChange:()=>Ae(l.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:l.name}),l.description&&e.jsx("span",{className:"agent-import-skill-description",children:l.description})]})]},`${l.name}-${x}`))})]}),be&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(it,{size:14}),be]})]}),g==="result"&&y&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(Je,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:y.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[y.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[y.created.length," created"]})}),y.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[y.skipped.length," skipped (already exist)"]})}),y.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[y.errors.length," error",y.errors.length!==1?"s":""]})})]}),y.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:y.created.map((l,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Je,{size:12}),e.jsx("span",{children:l.name})]},x))}),y.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:y.errors.map((l,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(At,{size:12}),e.jsxs("span",{children:[l.name,": ",l.error]})]},x))}),y.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[y.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[y.skills.imported.length," skill",y.skills.imported.length!==1?"s":""," imported"]})}),y.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[y.skills.skipped.length," skill",y.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),y.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[y.skills.errors.length," skill",y.skills.errors.length!==1?"s":""," error",y.skills.errors.length!==1?"s":""]})}),y.skills.imported.length===0&&y.skills.skipped.length===0&&y.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),y.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:y.skills.imported.map((l,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Je,{size:12}),e.jsx("span",{children:l.name})]},x))}),y.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:y.skills.errors.map((l,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(At,{size:12}),e.jsxs("span",{children:[l.name,": ",l.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[g==="preview"&&e.jsx("button",{className:"btn",onClick:()=>c("input"),disabled:te,children:"Back"}),e.jsx("button",{className:"btn",onClick:_e,disabled:te,children:g==="result"?"Close":"Cancel"}),g==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void X(),disabled:Ne||(o==="directory"?M.length===0:o==="browse"?!G:!N.trim()),children:Ne?e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),g==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void $e(),disabled:te||H===0&&F===0,children:te?e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:14,className:"spin"}),Y]}):`Import ${Ce}`})]})]})}):null}const Ht=220,aa=24,na=24,la=16;function Ot(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Ot(f),0)}function ia(n){const i=Ot(n);return i*Ht+Math.max(0,i-1)*aa}function ra(n){if(n.length===0)return Ht;const f=n.map(ia).reduce((d,g)=>d+g,0),u=Math.max(0,n.length-1)*na;return f+u+la*2}function oa(n){const i=Number.isFinite(n.availableWidth)&&n.availableWidth>0?n.availableWidth:0;return i===0||n.tree.length<=1?"horizontal":ra(n.tree)>i?"vertical":"horizontal"}const Pt=a.lazy(()=>ks(()=>import("./AgentDetailView-V32TpEe1.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(n=>({default:n.AgentDetailView}))),qe=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],mt=[.1,.25,.5,1,2,3,5,10],gt=[.75,1,1.25,1.5];function vt(n){switch(n){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"idle":default:return"agent-badge--idle"}}function jt(n,i){switch(i){case"running":return`${n}--running`;case"active":return`${n}--active`;case"paused":return`${n}--paused`;case"error":return`${n}--error`;case"idle":default:return`${n}--idle`}}function Qe(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Qe(f),0)}function ft(n,i){return n.state==="error"?{title:void 0,label:"Error"}:{title:i.reason??i.label,label:i.stateDerived?null:i.label}}function Bt({node:n,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d}){const{agent:g,children:c}=n,o=f(g),b=ft(g,o),N=vt(g.state),k=jt("org-chart-node-card",g.state),M=Qe(n),C={"--org-chart-subtree-leaves":String(M)},w=c.length>0?Qe(c[0]):1,P=c.length>0?Qe(c[c.length-1]):1,T={"--org-chart-first-child-leaves":String(w),"--org-chart-last-child-leaves":String(P)};return e.jsxs("div",{className:`org-chart-node${c.length>0?" org-chart-node--has-children":""}`,style:C,children:[e.jsxs("div",{className:`${k}${d===g.id?" agent-card--selected":""}`,onClick:()=>i(g.id),role:"button",tabIndex:0,onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.key===" "&&E.preventDefault(),i(g.id))},children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:e.jsx(Xe,{agent:g,size:20})}),e.jsx("span",{className:"org-chart-node__name",children:g.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${N}`,children:g.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:o.color},title:b.title,children:[o.icon,b.label&&e.jsx("span",{className:"text-secondary",children:b.label})]})]})]}),c.length>0&&e.jsx("div",{className:"org-chart-children",style:T,role:"group","aria-label":`${g.name} employees`,children:c.map(E=>e.jsx(Bt,{node:E,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d},E.agent.id))})]})}function pa({addToast:n,projectId:i,onOpenTaskLogs:f,agentOnboardingEnabled:u=!1}){const[d,g]=a.useState(!1),o=os()==="mobile",[b,N]=a.useState("all"),{agents:k,stats:M,isLoading:C,loadAgents:w,refreshAgents:P}=cs(i,{filterState:b,showSystemAgents:d}),[T,E]=a.useState(!1),[S,_]=a.useState(null),[p,L]=a.useState(!1),[$,ee]=a.useState(null),[Ne,oe]=a.useState(null),te=o&&!!$,[le,ce]=a.useState("dashboard"),[z,y]=a.useState(null),[xe,be]=a.useState(!1),[A,se]=a.useState(()=>{if(typeof window>"u")return"list";const t=Tt("fn-agent-view",i);return t==="list"||t==="board"||t==="org"?t:"list"}),[de,ye]=a.useState([]),[ae,U]=a.useState(!1),[ue,G]=a.useState(0),[W,V]=a.useState(!1),[ve,ie]=a.useState(!1),[K,Q]=a.useState(1),Me=a.useRef(null),Ee=a.useRef(null),{confirm:_e}=ds(),ke=a.useRef(null),me=a.useId();a.useEffect(()=>{const t=Tt("fn-agent-view",i);if(t==="list"||t==="board"||t==="org"){se(t);return}se("list")},[i]),a.useEffect(()=>{us("fn-agent-view",A,i)},[A,i]);const[we,X]=a.useState(null),$e=a.useRef(null),[H,F]=a.useState(null),[re,Z]=a.useState(null),[Ce,Y]=a.useState({}),[Se,Ae]=a.useState(1),[l,x]=a.useState(!1),[R,q]=a.useState(new Set),[I,D]=a.useState(new Map),Te=a.useRef(!0);a.useEffect(()=>(Te.current=!0,()=>{Te.current=!1}),[]),a.useEffect(()=>{ms(i).then(t=>{Te.current&&Ae(t.heartbeatMultiplier??1)}).catch(()=>{})},[i]);const Le=a.useCallback(async t=>{const r=Number.isFinite(t)&&t>0?t:1;Ae(r),x(!0);try{await gs({heartbeatMultiplier:r},i),n(`Heartbeat speed set to ×${r.toFixed(1)}`,"success")}catch(m){n(`Failed to save heartbeat multiplier: ${fe(m)}`,"error")}finally{Te.current&&x(!1)}},[i,n]),Fe=a.useMemo(()=>I.size===0?k:k.map(t=>{const r=I.get(t.id);return r?{...t,state:r}:t}),[k,I]),Ie=a.useMemo(()=>Fe.filter(t=>d||!rt(t)),[Fe,d]),Ye=a.useMemo(()=>Fe.filter(t=>t.state!=="active"&&t.state!=="running"?!1:d||!rt(t)),[Fe,d]),je=a.useMemo(()=>{if(d)return de;const t=r=>rt(r.agent)?null:{...r,children:r.children.map(t).filter(m=>m!==null)};return de.map(t).filter(r=>r!==null)},[de,d]);a.useEffect(()=>{if(A!=="org")return;const t=Ee.current;if(!t)return;const r=()=>{G(t.clientWidth)};r();const m=typeof ResizeObserver<"u"?new ResizeObserver(r):null;return m?.observe(t),window.addEventListener("resize",r),()=>{m?.disconnect(),window.removeEventListener("resize",r)}},[A,je.length]),a.useEffect(()=>{if(A!=="org")return;let t=!1;return U(!0),hs(i,{includeEphemeral:d}).then(r=>{t||ye(r)}).catch(r=>{t||(n(`Failed to load org chart: ${fe(r)}`,"error"),ye([]))}).finally(()=>{t||U(!1)}),()=>{t=!0}},[A,i,d,n]),a.useEffect(()=>{const t=setInterval(()=>{w()},3e4);return()=>{clearInterval(t)}},[w]),a.useEffect(()=>{if(!W)return;const t=m=>{const j=m.target;j&&(Me.current?.contains(j)||ke.current?.contains(j)||V(!1))},r=m=>{m.key==="Escape"&&(V(!1),ke.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",r)}},[W]);const ge=async(t,r)=>{if(!R.has(t)){q(m=>new Set(m).add(t)),D(m=>{const j=new Map(m);return j.set(t,r),j});try{await Ss(t,r,i),n(`Agent state updated to ${r}`,"success"),await w(),D(m=>{const j=new Map(m);return j.delete(t),j})}catch(m){D(j=>{const O=new Map(j);return O.delete(t),O}),n(`Failed to update state: ${fe(m)}`,"error")}finally{q(m=>{const j=new Set(m);return j.delete(t),j})}}},et=async(t,r)=>{if(await _e({title:"Delete Agent",message:`Delete agent "${r}"? This cannot be undone.`,danger:!0}))try{await Ts(t,i),n(`Agent "${r}" deleted`,"success"),await w()}catch(j){n(`Failed to delete agent: ${fe(j)}`,"error")}},We=async(t,r)=>{const m=k.find(j=>j.id===t);if(m){if(m.role===r){X(null);return}try{await Ze(t,{role:r},i),n(`Agent role updated to ${qe.find(j=>j.value===r)?.label??r}`,"success"),X(null),w()}catch(j){n(`Failed to update role: ${fe(j)}`,"error")}}},Pe=(t,r)=>{t.key==="Escape"&&X(null)},He=async(t,r)=>{re===t.id&&(Z(null),Y(m=>{const j={...m};return delete j[t.id],j})),F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:r}},i),n(`Heartbeat interval updated to ${Et(r)} for ${t.name}`,"success"),w()}catch(m){n(`Failed to update heartbeat interval: ${fe(m)}`,"error")}finally{F(null)}},Oe=async t=>{const r=Ce[t.id]??"";if(r.trim()===""){n("Please enter a heartbeat interval in minutes","error");return}const m=Number(r);if(isNaN(m)){n("Heartbeat interval must be a valid number","error");return}if(m<=0){n("Heartbeat interval must be greater than 0","error");return}if(m>=1&&m<5){F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:Cs}},i),n(`Heartbeat interval set to 5 minutes (minimum). ${m} minute${m!==1?"s":""} was below the 5-minute minimum.`,"success"),Z(null),Y(O=>{const J={...O};return delete J[t.id],J}),w()}catch(O){n(`Failed to update heartbeat interval: ${fe(O)}`,"error")}finally{F(null)}return}const j=Math.round(m*6e4);F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:j}},i),n(`Heartbeat interval updated to ${Et(j)} for ${t.name}`,"success"),Z(null),Y(O=>{const J={...O};return delete J[t.id],J}),w()}catch(O){n(`Failed to update heartbeat interval: ${fe(O)}`,"error")}finally{F(null)}},Ke=t=>{const r=ht(t.runtimeConfig?.heartbeatIntervalMs),m=Math.round(r/6e4);Z(t.id),Y(j=>({...j,[t.id]:String(m)}))},s=a.useCallback((t,r)=>{ee(t),ce(r?.initialTab??"dashboard"),y(r?.initialRunId??null),be(r?.preferActiveRun??!1)},[]),v=a.useCallback(()=>{ee(null),ce("dashboard"),y(null),be(!1)},[]),he=a.useCallback(t=>{s(t)},[s]),ne=a.useCallback(t=>{oe(t),s(t)},[s]),Re=a.useCallback(async({agentId:t,deleted:r})=>{await P(),r&&$===t&&v()},[P,$,v]),Gt=a.useCallback(t=>{s(t),o&&ie(!1)},[o,s]),Vt=async(t,r)=>{D(m=>{const j=new Map(m);return j.set(t,"running"),j});try{await As(t,i,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),n(`Heartbeat run started for ${r}`,"success"),await w(),D(m=>{const j=new Map(m);return j.delete(t),j})}catch(m){D(j=>{const O=new Map(j);return O.delete(t),O}),n(`Failed to start heartbeat run: ${fe(m)}`,"error")}},tt=a.useCallback(t=>{se(t),t!=="org"&&Q(1),o&&$&&v()},[v,o,$]),Nt=t=>qe.find(r=>r.value===t)?.label??t,Ut=t=>qe.find(r=>r.value===t)?.icon??"◆",yt=gt[K],kt=a.useMemo(()=>oa({tree:je,availableWidth:ue}),[je,ue]),Wt=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],st=t=>ws(t),wt=C&&k.length===0,Be=a.useCallback(()=>{E(!0)},[]);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(xt,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${A==="list"?" active":""}`,onClick:()=>tt("list"),title:"List view","aria-label":"List view","aria-pressed":A==="list",children:e.jsx(ps,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="board"?" active":""}`,onClick:()=>tt("board"),title:"Board view","aria-label":"Board view","aria-pressed":A==="board",children:e.jsx(De,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="org"?" active":""}`,onClick:()=>tt("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":A==="org",children:e.jsx(xs,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:ke,className:`btn-icon agent-controls-trigger${W?" agent-controls-trigger--active":""}`,onClick:()=>V(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":W,"aria-controls":me,children:e.jsx(Hs,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void w(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Ve,{size:16,className:C?"spin":void 0})}),!o&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{L(!0),V(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(bt,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{Be(),V(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(Rt,{size:16}),"New Agent"]})]}),W&&e.jsxs("div",{ref:Me,id:me,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsx("div",{className:"agent-controls",children:e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(bs,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:b,onChange:t=>N(t.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:t=>g(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]})}),o&&e.jsxs("div",{className:"agent-controls-mobile-actions",children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{L(!0),V(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(bt,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{Be(),V(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(Rt,{size:16}),"New Agent"]})]}),e.jsx("div",{className:"agent-global-controls agent-controls-actions",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:Se,onChange:t=>{const r=Number(t.target.value);Le(Number.isFinite(r)&&r>0?r:1)},disabled:l}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",Se.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(mt.reduce((t,r)=>Math.abs(r-Se)<Math.abs(t-Se)?r:t,mt[0])),onChange:t=>{const r=Number(t.target.value);Le(Number.isFinite(r)&&r>0?r:1)},disabled:l,"aria-label":"Heartbeat speed preset",children:mt.map(t=>e.jsxs("option",{value:String(t),children:["×",t]},t))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(Us,{agents:Ie})]})]})]})]}),e.jsx(ea,{isOpen:T,onClose:()=>{E(!1),_(null)},onCreated:()=>{E(!1),_(null),w()},projectId:i,prefillDraft:S,agentOnboardingEnabled:u,existingAgents:k,onPrefillDraft:_}),e.jsx(sa,{isOpen:p,onClose:()=>L(!1),onImported:()=>void w(),projectId:i}),e.jsx(Xs,{stats:M,activeAgents:Ye,projectId:i,isOpen:ve,onToggle:()=>ie(t=>!t),onSelectAgent:Gt,onOpenTaskLogs:f}),A==="org"?e.jsx("div",{className:"agents-org-full-view",children:e.jsx("div",{className:"agents-view-content agents-view-content--org-full",children:$?e.jsxs("div",{className:"agents-org-detail-view","data-testid":"agents-org-detail-view",children:[e.jsx("button",{type:"button",className:"btn btn-sm agents-org-detail-back",onClick:v,"aria-label":"Back to org chart",children:"Back to org chart"}),e.jsx(a.Suspense,{fallback:null,children:e.jsx(Pt,{inline:!0,showInlineBackButton:!1,agentId:$,projectId:i,onClose:v,addToast:n,onChildClick:he,initialTab:le,initialRunId:z,preferActiveRun:xe},$)})]}):wt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):e.jsxs("div",{className:"agent-org-chart-shell","data-testid":"agent-org-chart-shell",children:[o?e.jsxs("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:[e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>Q(t=>Math.max(0,t-1)),disabled:K===0,"aria-label":"Zoom out org chart",title:"Zoom out",children:e.jsx(Vs,{size:16})}),e.jsxs("span",{className:"agent-org-chart-controls__zoom-label","aria-live":"polite",children:[Math.round(yt*100),"%"]}),e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>Q(t=>Math.min(gt.length-1,t+1)),disabled:K===gt.length-1,"aria-label":"Zoom in org chart",title:"Zoom in",children:e.jsx(Bs,{size:16})}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm agent-org-chart-controls__fit-btn",onClick:()=>Q(1),"aria-label":"Fit org chart",title:"Fit org chart",children:[e.jsx(vs,{size:16}),"Fit"]})]}):null,e.jsx("div",{ref:Ee,className:"agent-org-chart-viewport","data-testid":"agent-org-chart-viewport",children:e.jsx("div",{className:`agent-org-chart-canvas agent-org-chart-canvas--zoom-${Math.round(yt*100)}`,children:e.jsx("div",{className:`agent-org-chart${kt==="vertical"?" agent-org-chart--vertical":""}`,"data-testid":"agent-org-chart","data-layout-mode":kt,children:ae?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):je.length===0?e.jsx(dt,{onCtaClick:Be}):je.map(t=>e.jsx(Bt,{node:t,onSelect:ne,getHealthStatus:st,getRoleIcon:Ut,selectedAgentId:Ne},t.agent.id))})})})]})})}):e.jsxs("div",{className:"agents-split-layout",children:[e.jsx("div",{className:`agents-split-sidebar${te?" agents-split-sidebar--hidden-mobile":""}`,children:e.jsx("div",{className:"agents-view-content",children:wt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):A==="board"?e.jsx("div",{className:"agent-board",children:Ie.length===0?e.jsx(dt,{onCtaClick:Be}):Ie.map(t=>{const r=st(t),m=ft(t,r),j=vt(t.state),O=jt("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${O}${$===t.id?" agent-card--selected":""}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>s(t.id),role:"button",tabIndex:0,onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.key===" "&&J.preventDefault(),s(t.id))},children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:e.jsx(Xe,{agent:t,size:20})}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:Nt(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${j}`,children:t.state}),(t.pendingApprovalCount??0)>0?e.jsxs("span",{className:"agent-board-badge badge agent-approval-badge",title:"Pending approvals",children:[e.jsx("span",{className:"status-dot status-dot--pending"}),t.pendingApprovalCount]}):null]}),e.jsx("div",{className:"agent-board-name",children:t.name}),e.jsx("div",{className:"agent-board-id",children:t.id}),e.jsxs("div",{className:"agent-board-health",style:{color:r.color},title:m.title,children:[r.icon,m.label?` ${m.label}`:""]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:Ie.length===0?e.jsx(dt,{onCtaClick:Be}):Ie.map(t=>{const r=st(t),m=ft(t,r),j=vt(t.state),O=jt("agent-card",t.state),J=ht(t.runtimeConfig?.heartbeatIntervalMs),Kt=js(J),Ge=H===t.id;return e.jsxs("div",{className:`agent-card agent-card--clickable ${O}${$===t.id?" agent-card--selected":""}`,onClick:h=>{const B=h.target;if(B===h.currentTarget){s(t.id);return}const pe=B.closest('button, select, input, [role="button"]');pe&&pe!==h.currentTarget||s(t.id)},role:"button",tabIndex:0,onKeyDown:h=>{h.target===h.currentTarget&&(h.key==="Enter"||h.key===" ")&&(h.key===" "&&h.preventDefault(),s(t.id))},"aria-label":`Open details for ${t.name}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info",children:[we===t.id?e.jsx("select",{ref:$e,className:"select agent-role-select",value:t.role,onChange:h=>void We(t.id,h.target.value),onKeyDown:h=>Pe(h,t.id),onBlur:()=>X(null),autoFocus:!0,children:qe.map(h=>e.jsxs("option",{value:h.value,children:[h.icon," ",h.label]},h.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:h=>{h.stopPropagation(),X(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.stopPropagation(),X(t.id))},children:e.jsx(Xe,{agent:t,size:20})}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:t.name}),e.jsx("span",{className:"agent-id text-secondary",children:t.id})]}),e.jsx(zt,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${j}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:r.color},title:m.title,children:[r.icon,m.label?` ${m.label}`:""]}),e.jsx("span",{className:"badge text-secondary",children:Nt(t.role)}),(t.pendingApprovalCount??0)>0?e.jsxs("span",{className:"badge agent-approval-badge",title:"Pending approvals",children:[e.jsx("span",{className:"status-dot status-dot--pending"}),t.pendingApprovalCount]}):null,(()=>{const h=Wt(t);if(h.length===0)return null;const B=h.slice(0,2),pe=h.length-2;return e.jsxs(e.Fragment,{children:[B.map(at=>e.jsx("span",{className:"badge badge-skill",title:at,children:$s(at)},at)),pe>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",pe]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.state==="error"&&t.lastError?e.jsx(fs,{errorText:t.lastError,issueContext:{surface:"AgentsView list",agentId:t.id,agentName:t.name,agentState:t.state,taskId:t.taskId}}):null,t.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:t.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),re===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Ce[t.id]??"",onChange:h=>Y(B=>({...B,[t.id]:h.target.value})),onKeyDown:h=>{h.key==="Enter"?Oe(t):h.key==="Escape"&&(Z(null),Y(B=>{const pe={...B};return delete pe[t.id],pe}))},disabled:Ge,"aria-label":`Custom heartbeat interval in minutes for ${t.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>void Oe(t),disabled:Ge,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>{Z(null),Y(h=>{const B={...h};return delete B[t.id],B})},disabled:Ge,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:J,onChange:h=>{const B=h.target.value;B==="__custom__"?Ke(t):He(t,Number(B))},disabled:Ge,"aria-label":`Set heartbeat interval for ${t.name}`,children:[Kt.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value)),Ns.some(h=>h.value===J)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),Ge&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const h=new Date(t.lastHeartbeatAt),B=new Date(h.getTime()+J),pe=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:h.toLocaleString(),children:["Last: ",h.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),pe&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:B.toLocaleString(),children:["Next: ",B.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--primary",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Activate",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Start"})]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>void Vt(t.id,t.name),disabled:R.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(De,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Run Now"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"paused"),disabled:R.has(t.id),title:"Pause",children:[e.jsx(Mt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Resume",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Resume"})]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>s(t.id,{initialTab:"runs",initialRunId:null,preferActiveRun:!0}),title:"View live run details","aria-label":`View live run details for ${t.name}`,children:[e.jsx(De,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Running"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"paused"),disabled:R.has(t.id),title:"Pause",children:[e.jsx(Mt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Retry",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Retry"})]})]}),e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--secondary",children:[e.jsxs("button",{className:"btn btn-sm agent-card-details-btn",onClick:()=>s(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:[e.jsx(Fs,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Details"})]}),(t.state==="idle"||t.state==="paused")&&e.jsxs("button",{className:"btn btn-sm btn-danger",onClick:()=>void et(t.id,t.name),title:"Delete",children:[e.jsx(ys,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Delete"})]})]})]})]},t.id)})})})}),e.jsx("div",{className:`agents-split-detail${o&&!$?" agents-split-detail--hidden-mobile":""}`,children:$?e.jsx(a.Suspense,{fallback:null,children:e.jsx(Pt,{inline:!0,showInlineBackButton:o,agentId:$,projectId:i,onClose:v,addToast:n,onChildClick:he,initialTab:le,initialRunId:z,preferActiveRun:xe,onMutationSuccess:Re},$)}):e.jsxs("div",{className:"agents-detail-empty-state",children:[e.jsx(xt,{size:48}),e.jsx("h3",{children:"Select an agent"}),e.jsx("p",{children:"Choose an agent from the sidebar to view details"})]})})]})]})}export{pa as AgentsView};
34
+ Agent instructions go here...`,value:N,onChange:l=>{b("paste"),C([]),k(l.target.value),z(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",o]}),ce&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(it,{size:14}),ce]})]}),g==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:w})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(pt,{size:14}),e.jsxs("span",{children:[T.length," agent",T.length!==1?"s":""," found"]})]}),T.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L(T.map(l=>l.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>L([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((l,x)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${l.name}`,checked:p.includes(l.name),onChange:()=>Se(l.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:l.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:l.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[l.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[l.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:l.role}),l.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",l.reportsTo]}),l.skills&&l.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",l.skills.join(", ")]})]}),l.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[l.instructionsText.slice(0,100),l.instructionsText.length>100?"...":""]})]})]},x))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),S.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(pt,{size:14}),e.jsxs("span",{children:[S.length," skill",S.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>ee(S.map(l=>l.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>ee([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((l,x)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${l.name}`,checked:$.includes(l.name),onChange:()=>Ae(l.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:l.name}),l.description&&e.jsx("span",{className:"agent-import-skill-description",children:l.description})]})]},`${l.name}-${x}`))})]}),be&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(it,{size:14}),be]})]}),g==="result"&&y&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(Je,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:y.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[y.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[y.created.length," created"]})}),y.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[y.skipped.length," skipped (already exist)"]})}),y.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[y.errors.length," error",y.errors.length!==1?"s":""]})})]}),y.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:y.created.map((l,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Je,{size:12}),e.jsx("span",{children:l.name})]},x))}),y.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:y.errors.map((l,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(At,{size:12}),e.jsxs("span",{children:[l.name,": ",l.error]})]},x))}),y.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[y.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[y.skills.imported.length," skill",y.skills.imported.length!==1?"s":""," imported"]})}),y.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[y.skills.skipped.length," skill",y.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),y.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[y.skills.errors.length," skill",y.skills.errors.length!==1?"s":""," error",y.skills.errors.length!==1?"s":""]})}),y.skills.imported.length===0&&y.skills.skipped.length===0&&y.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),y.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:y.skills.imported.map((l,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Je,{size:12}),e.jsx("span",{children:l.name})]},x))}),y.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:y.skills.errors.map((l,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(At,{size:12}),e.jsxs("span",{children:[l.name,": ",l.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[g==="preview"&&e.jsx("button",{className:"btn",onClick:()=>c("input"),disabled:te,children:"Back"}),e.jsx("button",{className:"btn",onClick:_e,disabled:te,children:g==="result"?"Close":"Cancel"}),g==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void X(),disabled:Ne||(o==="directory"?M.length===0:o==="browse"?!G:!N.trim()),children:Ne?e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),g==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void $e(),disabled:te||H===0&&F===0,children:te?e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:14,className:"spin"}),Y]}):`Import ${Ce}`})]})]})}):null}const Ht=220,aa=24,na=24,la=16;function Ot(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Ot(f),0)}function ia(n){const i=Ot(n);return i*Ht+Math.max(0,i-1)*aa}function ra(n){if(n.length===0)return Ht;const f=n.map(ia).reduce((d,g)=>d+g,0),u=Math.max(0,n.length-1)*na;return f+u+la*2}function oa(n){const i=Number.isFinite(n.availableWidth)&&n.availableWidth>0?n.availableWidth:0;return i===0||n.tree.length<=1?"horizontal":ra(n.tree)>i?"vertical":"horizontal"}const Pt=a.lazy(()=>ks(()=>import("./AgentDetailView-DG01uRND.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(n=>({default:n.AgentDetailView}))),qe=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],mt=[.1,.25,.5,1,2,3,5,10],gt=[.75,1,1.25,1.5];function vt(n){switch(n){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"idle":default:return"agent-badge--idle"}}function jt(n,i){switch(i){case"running":return`${n}--running`;case"active":return`${n}--active`;case"paused":return`${n}--paused`;case"error":return`${n}--error`;case"idle":default:return`${n}--idle`}}function Qe(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Qe(f),0)}function ft(n,i){return n.state==="error"?{title:void 0,label:"Error"}:{title:i.reason??i.label,label:i.stateDerived?null:i.label}}function Bt({node:n,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d}){const{agent:g,children:c}=n,o=f(g),b=ft(g,o),N=vt(g.state),k=jt("org-chart-node-card",g.state),M=Qe(n),C={"--org-chart-subtree-leaves":String(M)},w=c.length>0?Qe(c[0]):1,P=c.length>0?Qe(c[c.length-1]):1,T={"--org-chart-first-child-leaves":String(w),"--org-chart-last-child-leaves":String(P)};return e.jsxs("div",{className:`org-chart-node${c.length>0?" org-chart-node--has-children":""}`,style:C,children:[e.jsxs("div",{className:`${k}${d===g.id?" agent-card--selected":""}`,onClick:()=>i(g.id),role:"button",tabIndex:0,onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.key===" "&&E.preventDefault(),i(g.id))},children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:e.jsx(Xe,{agent:g,size:20})}),e.jsx("span",{className:"org-chart-node__name",children:g.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${N}`,children:g.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:o.color},title:b.title,children:[o.icon,b.label&&e.jsx("span",{className:"text-secondary",children:b.label})]})]})]}),c.length>0&&e.jsx("div",{className:"org-chart-children",style:T,role:"group","aria-label":`${g.name} employees`,children:c.map(E=>e.jsx(Bt,{node:E,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d},E.agent.id))})]})}function pa({addToast:n,projectId:i,onOpenTaskLogs:f,agentOnboardingEnabled:u=!1}){const[d,g]=a.useState(!1),o=os()==="mobile",[b,N]=a.useState("all"),{agents:k,stats:M,isLoading:C,loadAgents:w,refreshAgents:P}=cs(i,{filterState:b,showSystemAgents:d}),[T,E]=a.useState(!1),[S,_]=a.useState(null),[p,L]=a.useState(!1),[$,ee]=a.useState(null),[Ne,oe]=a.useState(null),te=o&&!!$,[le,ce]=a.useState("dashboard"),[z,y]=a.useState(null),[xe,be]=a.useState(!1),[A,se]=a.useState(()=>{if(typeof window>"u")return"list";const t=Tt("fn-agent-view",i);return t==="list"||t==="board"||t==="org"?t:"list"}),[de,ye]=a.useState([]),[ae,U]=a.useState(!1),[ue,G]=a.useState(0),[W,V]=a.useState(!1),[ve,ie]=a.useState(!1),[K,Q]=a.useState(1),Me=a.useRef(null),Ee=a.useRef(null),{confirm:_e}=ds(),ke=a.useRef(null),me=a.useId();a.useEffect(()=>{const t=Tt("fn-agent-view",i);if(t==="list"||t==="board"||t==="org"){se(t);return}se("list")},[i]),a.useEffect(()=>{us("fn-agent-view",A,i)},[A,i]);const[we,X]=a.useState(null),$e=a.useRef(null),[H,F]=a.useState(null),[re,Z]=a.useState(null),[Ce,Y]=a.useState({}),[Se,Ae]=a.useState(1),[l,x]=a.useState(!1),[R,q]=a.useState(new Set),[I,D]=a.useState(new Map),Te=a.useRef(!0);a.useEffect(()=>(Te.current=!0,()=>{Te.current=!1}),[]),a.useEffect(()=>{ms(i).then(t=>{Te.current&&Ae(t.heartbeatMultiplier??1)}).catch(()=>{})},[i]);const Le=a.useCallback(async t=>{const r=Number.isFinite(t)&&t>0?t:1;Ae(r),x(!0);try{await gs({heartbeatMultiplier:r},i),n(`Heartbeat speed set to ×${r.toFixed(1)}`,"success")}catch(m){n(`Failed to save heartbeat multiplier: ${fe(m)}`,"error")}finally{Te.current&&x(!1)}},[i,n]),Fe=a.useMemo(()=>I.size===0?k:k.map(t=>{const r=I.get(t.id);return r?{...t,state:r}:t}),[k,I]),Ie=a.useMemo(()=>Fe.filter(t=>d||!rt(t)),[Fe,d]),Ye=a.useMemo(()=>Fe.filter(t=>t.state!=="active"&&t.state!=="running"?!1:d||!rt(t)),[Fe,d]),je=a.useMemo(()=>{if(d)return de;const t=r=>rt(r.agent)?null:{...r,children:r.children.map(t).filter(m=>m!==null)};return de.map(t).filter(r=>r!==null)},[de,d]);a.useEffect(()=>{if(A!=="org")return;const t=Ee.current;if(!t)return;const r=()=>{G(t.clientWidth)};r();const m=typeof ResizeObserver<"u"?new ResizeObserver(r):null;return m?.observe(t),window.addEventListener("resize",r),()=>{m?.disconnect(),window.removeEventListener("resize",r)}},[A,je.length]),a.useEffect(()=>{if(A!=="org")return;let t=!1;return U(!0),hs(i,{includeEphemeral:d}).then(r=>{t||ye(r)}).catch(r=>{t||(n(`Failed to load org chart: ${fe(r)}`,"error"),ye([]))}).finally(()=>{t||U(!1)}),()=>{t=!0}},[A,i,d,n]),a.useEffect(()=>{const t=setInterval(()=>{w()},3e4);return()=>{clearInterval(t)}},[w]),a.useEffect(()=>{if(!W)return;const t=m=>{const j=m.target;j&&(Me.current?.contains(j)||ke.current?.contains(j)||V(!1))},r=m=>{m.key==="Escape"&&(V(!1),ke.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",r)}},[W]);const ge=async(t,r)=>{if(!R.has(t)){q(m=>new Set(m).add(t)),D(m=>{const j=new Map(m);return j.set(t,r),j});try{await Ss(t,r,i),n(`Agent state updated to ${r}`,"success"),await w(),D(m=>{const j=new Map(m);return j.delete(t),j})}catch(m){D(j=>{const O=new Map(j);return O.delete(t),O}),n(`Failed to update state: ${fe(m)}`,"error")}finally{q(m=>{const j=new Set(m);return j.delete(t),j})}}},et=async(t,r)=>{if(await _e({title:"Delete Agent",message:`Delete agent "${r}"? This cannot be undone.`,danger:!0}))try{await Ts(t,i),n(`Agent "${r}" deleted`,"success"),await w()}catch(j){n(`Failed to delete agent: ${fe(j)}`,"error")}},We=async(t,r)=>{const m=k.find(j=>j.id===t);if(m){if(m.role===r){X(null);return}try{await Ze(t,{role:r},i),n(`Agent role updated to ${qe.find(j=>j.value===r)?.label??r}`,"success"),X(null),w()}catch(j){n(`Failed to update role: ${fe(j)}`,"error")}}},Pe=(t,r)=>{t.key==="Escape"&&X(null)},He=async(t,r)=>{re===t.id&&(Z(null),Y(m=>{const j={...m};return delete j[t.id],j})),F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:r}},i),n(`Heartbeat interval updated to ${Et(r)} for ${t.name}`,"success"),w()}catch(m){n(`Failed to update heartbeat interval: ${fe(m)}`,"error")}finally{F(null)}},Oe=async t=>{const r=Ce[t.id]??"";if(r.trim()===""){n("Please enter a heartbeat interval in minutes","error");return}const m=Number(r);if(isNaN(m)){n("Heartbeat interval must be a valid number","error");return}if(m<=0){n("Heartbeat interval must be greater than 0","error");return}if(m>=1&&m<5){F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:Cs}},i),n(`Heartbeat interval set to 5 minutes (minimum). ${m} minute${m!==1?"s":""} was below the 5-minute minimum.`,"success"),Z(null),Y(O=>{const J={...O};return delete J[t.id],J}),w()}catch(O){n(`Failed to update heartbeat interval: ${fe(O)}`,"error")}finally{F(null)}return}const j=Math.round(m*6e4);F(t.id);try{await Ze(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:j}},i),n(`Heartbeat interval updated to ${Et(j)} for ${t.name}`,"success"),Z(null),Y(O=>{const J={...O};return delete J[t.id],J}),w()}catch(O){n(`Failed to update heartbeat interval: ${fe(O)}`,"error")}finally{F(null)}},Ke=t=>{const r=ht(t.runtimeConfig?.heartbeatIntervalMs),m=Math.round(r/6e4);Z(t.id),Y(j=>({...j,[t.id]:String(m)}))},s=a.useCallback((t,r)=>{ee(t),ce(r?.initialTab??"dashboard"),y(r?.initialRunId??null),be(r?.preferActiveRun??!1)},[]),v=a.useCallback(()=>{ee(null),ce("dashboard"),y(null),be(!1)},[]),he=a.useCallback(t=>{s(t)},[s]),ne=a.useCallback(t=>{oe(t),s(t)},[s]),Re=a.useCallback(async({agentId:t,deleted:r})=>{await P(),r&&$===t&&v()},[P,$,v]),Gt=a.useCallback(t=>{s(t),o&&ie(!1)},[o,s]),Vt=async(t,r)=>{D(m=>{const j=new Map(m);return j.set(t,"running"),j});try{await As(t,i,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),n(`Heartbeat run started for ${r}`,"success"),await w(),D(m=>{const j=new Map(m);return j.delete(t),j})}catch(m){D(j=>{const O=new Map(j);return O.delete(t),O}),n(`Failed to start heartbeat run: ${fe(m)}`,"error")}},tt=a.useCallback(t=>{se(t),t!=="org"&&Q(1),o&&$&&v()},[v,o,$]),Nt=t=>qe.find(r=>r.value===t)?.label??t,Ut=t=>qe.find(r=>r.value===t)?.icon??"◆",yt=gt[K],kt=a.useMemo(()=>oa({tree:je,availableWidth:ue}),[je,ue]),Wt=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],st=t=>ws(t),wt=C&&k.length===0,Be=a.useCallback(()=>{E(!0)},[]);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(xt,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${A==="list"?" active":""}`,onClick:()=>tt("list"),title:"List view","aria-label":"List view","aria-pressed":A==="list",children:e.jsx(ps,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="board"?" active":""}`,onClick:()=>tt("board"),title:"Board view","aria-label":"Board view","aria-pressed":A==="board",children:e.jsx(De,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="org"?" active":""}`,onClick:()=>tt("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":A==="org",children:e.jsx(xs,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:ke,className:`btn-icon agent-controls-trigger${W?" agent-controls-trigger--active":""}`,onClick:()=>V(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":W,"aria-controls":me,children:e.jsx(Hs,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void w(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Ve,{size:16,className:C?"spin":void 0})}),!o&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{L(!0),V(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(bt,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{Be(),V(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(Rt,{size:16}),"New Agent"]})]}),W&&e.jsxs("div",{ref:Me,id:me,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsx("div",{className:"agent-controls",children:e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(bs,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:b,onChange:t=>N(t.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:t=>g(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]})}),o&&e.jsxs("div",{className:"agent-controls-mobile-actions",children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{L(!0),V(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(bt,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{Be(),V(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(Rt,{size:16}),"New Agent"]})]}),e.jsx("div",{className:"agent-global-controls agent-controls-actions",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:Se,onChange:t=>{const r=Number(t.target.value);Le(Number.isFinite(r)&&r>0?r:1)},disabled:l}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",Se.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(mt.reduce((t,r)=>Math.abs(r-Se)<Math.abs(t-Se)?r:t,mt[0])),onChange:t=>{const r=Number(t.target.value);Le(Number.isFinite(r)&&r>0?r:1)},disabled:l,"aria-label":"Heartbeat speed preset",children:mt.map(t=>e.jsxs("option",{value:String(t),children:["×",t]},t))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(Us,{agents:Ie})]})]})]})]}),e.jsx(ea,{isOpen:T,onClose:()=>{E(!1),_(null)},onCreated:()=>{E(!1),_(null),w()},projectId:i,prefillDraft:S,agentOnboardingEnabled:u,existingAgents:k,onPrefillDraft:_}),e.jsx(sa,{isOpen:p,onClose:()=>L(!1),onImported:()=>void w(),projectId:i}),e.jsx(Xs,{stats:M,activeAgents:Ye,projectId:i,isOpen:ve,onToggle:()=>ie(t=>!t),onSelectAgent:Gt,onOpenTaskLogs:f}),A==="org"?e.jsx("div",{className:"agents-org-full-view",children:e.jsx("div",{className:"agents-view-content agents-view-content--org-full",children:$?e.jsxs("div",{className:"agents-org-detail-view","data-testid":"agents-org-detail-view",children:[e.jsx("button",{type:"button",className:"btn btn-sm agents-org-detail-back",onClick:v,"aria-label":"Back to org chart",children:"Back to org chart"}),e.jsx(a.Suspense,{fallback:null,children:e.jsx(Pt,{inline:!0,showInlineBackButton:!1,agentId:$,projectId:i,onClose:v,addToast:n,onChildClick:he,initialTab:le,initialRunId:z,preferActiveRun:xe},$)})]}):wt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):e.jsxs("div",{className:"agent-org-chart-shell","data-testid":"agent-org-chart-shell",children:[o?e.jsxs("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:[e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>Q(t=>Math.max(0,t-1)),disabled:K===0,"aria-label":"Zoom out org chart",title:"Zoom out",children:e.jsx(Vs,{size:16})}),e.jsxs("span",{className:"agent-org-chart-controls__zoom-label","aria-live":"polite",children:[Math.round(yt*100),"%"]}),e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>Q(t=>Math.min(gt.length-1,t+1)),disabled:K===gt.length-1,"aria-label":"Zoom in org chart",title:"Zoom in",children:e.jsx(Bs,{size:16})}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm agent-org-chart-controls__fit-btn",onClick:()=>Q(1),"aria-label":"Fit org chart",title:"Fit org chart",children:[e.jsx(vs,{size:16}),"Fit"]})]}):null,e.jsx("div",{ref:Ee,className:"agent-org-chart-viewport","data-testid":"agent-org-chart-viewport",children:e.jsx("div",{className:`agent-org-chart-canvas agent-org-chart-canvas--zoom-${Math.round(yt*100)}`,children:e.jsx("div",{className:`agent-org-chart${kt==="vertical"?" agent-org-chart--vertical":""}`,"data-testid":"agent-org-chart","data-layout-mode":kt,children:ae?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):je.length===0?e.jsx(dt,{onCtaClick:Be}):je.map(t=>e.jsx(Bt,{node:t,onSelect:ne,getHealthStatus:st,getRoleIcon:Ut,selectedAgentId:Ne},t.agent.id))})})})]})})}):e.jsxs("div",{className:"agents-split-layout",children:[e.jsx("div",{className:`agents-split-sidebar${te?" agents-split-sidebar--hidden-mobile":""}`,children:e.jsx("div",{className:"agents-view-content",children:wt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ve,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):A==="board"?e.jsx("div",{className:"agent-board",children:Ie.length===0?e.jsx(dt,{onCtaClick:Be}):Ie.map(t=>{const r=st(t),m=ft(t,r),j=vt(t.state),O=jt("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${O}${$===t.id?" agent-card--selected":""}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>s(t.id),role:"button",tabIndex:0,onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.key===" "&&J.preventDefault(),s(t.id))},children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:e.jsx(Xe,{agent:t,size:20})}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:Nt(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${j}`,children:t.state}),(t.pendingApprovalCount??0)>0?e.jsxs("span",{className:"agent-board-badge badge agent-approval-badge",title:"Pending approvals",children:[e.jsx("span",{className:"status-dot status-dot--pending"}),t.pendingApprovalCount]}):null]}),e.jsx("div",{className:"agent-board-name",children:t.name}),e.jsx("div",{className:"agent-board-id",children:t.id}),e.jsxs("div",{className:"agent-board-health",style:{color:r.color},title:m.title,children:[r.icon,m.label?` ${m.label}`:""]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:Ie.length===0?e.jsx(dt,{onCtaClick:Be}):Ie.map(t=>{const r=st(t),m=ft(t,r),j=vt(t.state),O=jt("agent-card",t.state),J=ht(t.runtimeConfig?.heartbeatIntervalMs),Kt=js(J),Ge=H===t.id;return e.jsxs("div",{className:`agent-card agent-card--clickable ${O}${$===t.id?" agent-card--selected":""}`,onClick:h=>{const B=h.target;if(B===h.currentTarget){s(t.id);return}const pe=B.closest('button, select, input, [role="button"]');pe&&pe!==h.currentTarget||s(t.id)},role:"button",tabIndex:0,onKeyDown:h=>{h.target===h.currentTarget&&(h.key==="Enter"||h.key===" ")&&(h.key===" "&&h.preventDefault(),s(t.id))},"aria-label":`Open details for ${t.name}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info",children:[we===t.id?e.jsx("select",{ref:$e,className:"select agent-role-select",value:t.role,onChange:h=>void We(t.id,h.target.value),onKeyDown:h=>Pe(h,t.id),onBlur:()=>X(null),autoFocus:!0,children:qe.map(h=>e.jsxs("option",{value:h.value,children:[h.icon," ",h.label]},h.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:h=>{h.stopPropagation(),X(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.stopPropagation(),X(t.id))},children:e.jsx(Xe,{agent:t,size:20})}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:t.name}),e.jsx("span",{className:"agent-id text-secondary",children:t.id})]}),e.jsx(zt,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${j}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:r.color},title:m.title,children:[r.icon,m.label?` ${m.label}`:""]}),e.jsx("span",{className:"badge text-secondary",children:Nt(t.role)}),(t.pendingApprovalCount??0)>0?e.jsxs("span",{className:"badge agent-approval-badge",title:"Pending approvals",children:[e.jsx("span",{className:"status-dot status-dot--pending"}),t.pendingApprovalCount]}):null,(()=>{const h=Wt(t);if(h.length===0)return null;const B=h.slice(0,2),pe=h.length-2;return e.jsxs(e.Fragment,{children:[B.map(at=>e.jsx("span",{className:"badge badge-skill",title:at,children:$s(at)},at)),pe>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",pe]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.state==="error"&&t.lastError?e.jsx(fs,{errorText:t.lastError,issueContext:{surface:"AgentsView list",agentId:t.id,agentName:t.name,agentState:t.state,taskId:t.taskId}}):null,t.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:t.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),re===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Ce[t.id]??"",onChange:h=>Y(B=>({...B,[t.id]:h.target.value})),onKeyDown:h=>{h.key==="Enter"?Oe(t):h.key==="Escape"&&(Z(null),Y(B=>{const pe={...B};return delete pe[t.id],pe}))},disabled:Ge,"aria-label":`Custom heartbeat interval in minutes for ${t.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>void Oe(t),disabled:Ge,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>{Z(null),Y(h=>{const B={...h};return delete B[t.id],B})},disabled:Ge,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:J,onChange:h=>{const B=h.target.value;B==="__custom__"?Ke(t):He(t,Number(B))},disabled:Ge,"aria-label":`Set heartbeat interval for ${t.name}`,children:[Kt.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value)),Ns.some(h=>h.value===J)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),Ge&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const h=new Date(t.lastHeartbeatAt),B=new Date(h.getTime()+J),pe=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:h.toLocaleString(),children:["Last: ",h.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),pe&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:B.toLocaleString(),children:["Next: ",B.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--primary",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Activate",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Start"})]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>void Vt(t.id,t.name),disabled:R.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(De,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Run Now"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"paused"),disabled:R.has(t.id),title:"Pause",children:[e.jsx(Mt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Resume",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Resume"})]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>s(t.id,{initialTab:"runs",initialRunId:null,preferActiveRun:!0}),title:"View live run details","aria-label":`View live run details for ${t.name}`,children:[e.jsx(De,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Running"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"paused"),disabled:R.has(t.id),title:"Pause",children:[e.jsx(Mt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"active"),disabled:R.has(t.id),title:"Retry",children:[e.jsx(ot,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Retry"})]})]}),e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--secondary",children:[e.jsxs("button",{className:"btn btn-sm agent-card-details-btn",onClick:()=>s(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:[e.jsx(Fs,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Details"})]}),(t.state==="idle"||t.state==="paused")&&e.jsxs("button",{className:"btn btn-sm btn-danger",onClick:()=>void et(t.id,t.name),title:"Delete",children:[e.jsx(ys,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Delete"})]})]})]})]},t.id)})})})}),e.jsx("div",{className:`agents-split-detail${o&&!$?" agents-split-detail--hidden-mobile":""}`,children:$?e.jsx(a.Suspense,{fallback:null,children:e.jsx(Pt,{inline:!0,showInlineBackButton:o,agentId:$,projectId:i,onClose:v,addToast:n,onChildClick:he,initialTab:le,initialRunId:z,preferActiveRun:xe,onMutationSuccess:Re},$)}):e.jsxs("div",{className:"agents-detail-empty-state",children:[e.jsx(xt,{size:48}),e.jsx("h3",{children:"Select an agent"}),e.jsx("p",{children:"Choose an agent from the sidebar to view details"})]})})]})]})}export{pa as AgentsView};