@runfusion/fusion 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/bin.js +47492 -45420
- package/dist/client/assets/{AgentDetailView-ZbHEbYRT.js → AgentDetailView-Cv-vgOj3.js} +3 -3
- package/dist/client/assets/{AgentsView-B3jYk8Kt.js → AgentsView-D6Zi5zfP.js} +4 -4
- package/dist/client/assets/ChatView-CAHjY9uO.js +1 -0
- package/dist/client/assets/{DevServerView-DyGDEiBP.js → DevServerView--_WBvIDQ.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-D5UIeIl6.js → DirectoryPicker-xedtR-Rd.js} +1 -1
- package/dist/client/assets/{DocumentsView-DNHu1T8K.js → DocumentsView-Bg2oaZks.js} +1 -1
- package/dist/client/assets/{EvalsView-CpRobtDi.js → EvalsView-B3uOCXfr.js} +1 -1
- package/dist/client/assets/{ExperimentalAgentOnboardingModal-DOY_oZi7.js → ExperimentalAgentOnboardingModal-Bx6yXVS5.js} +1 -1
- package/dist/client/assets/{InsightsView-vp0RE8Mg.js → InsightsView-Q1zvtF4F.js} +1 -1
- package/dist/client/assets/{MemoryView-PSc5lGJt.js → MemoryView-xcN_eouf.js} +1 -1
- package/dist/client/assets/{NodesView-DMj6HGeC.js → NodesView-RxXg58_Q.js} +1 -1
- package/dist/client/assets/{PiExtensionsManager-DL_QcN56.js → PiExtensionsManager-Cc8aAZXg.js} +2 -2
- package/dist/client/assets/{PluginManager-BtYKm8IT.js → PluginManager-BEkyBajl.js} +1 -1
- package/dist/client/assets/{ResearchView-BzCcDAS4.css → ResearchView-BEI4ZSGs.css} +1 -1
- package/dist/client/assets/ResearchView-CERNf7sJ.js +1 -0
- package/dist/client/assets/{SettingsModal-CUCyaAyE.js → SettingsModal-B1r0yASu.js} +1 -1
- package/dist/client/assets/SettingsModal-BLsac7CJ.js +31 -0
- package/dist/client/assets/SettingsModal-Cis-4Lot.css +1 -0
- package/dist/client/assets/{SetupWizardModal-BKscasuh.js → SetupWizardModal-D1q548_L.js} +1 -1
- package/dist/client/assets/{SkillsView-BdELqTy7.js → SkillsView-ClLM6u6p.js} +1 -1
- package/dist/client/assets/StashRecoveryView-B_8WIQEo.css +1 -0
- package/dist/client/assets/StashRecoveryView-ze0pEZ5U.js +1 -0
- package/dist/client/assets/{TodoView-DFNGBDNV.js → TodoView-CTmIfy2M.js} +1 -1
- package/dist/client/assets/createLucideIcon-BazL2hk5.js +21 -0
- package/dist/client/assets/dashboard-view-4xAN3yO5.js +21 -0
- package/dist/client/assets/dashboard-view-BkTMSZYn.css +1 -0
- package/dist/client/assets/dashboard-view-CyWN-d02.js +63 -0
- package/dist/client/assets/dashboard-view-DdGlfuu-.css +1 -0
- package/dist/client/assets/{folder-open-k1xmUMyr.js → folder-open-BZuKESeq.js} +1 -1
- package/dist/client/assets/index-Bdw6llW6.js +692 -0
- package/dist/client/assets/index-CZGlyJuS.css +1 -0
- package/dist/client/assets/{star-ne32r3Y4.js → star-D75YKEq-.js} +1 -1
- package/dist/client/assets/{upload-MS-2Gx53.js → upload-BYYTgWFj.js} +1 -1
- package/dist/client/assets/{users-C519GSjH.js → users-RS90Aii3.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/version.json +1 -1
- package/dist/droid-cli/package.json +1 -1
- package/dist/extension.js +4340 -3059
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/plugins/fusion-plugin-cli-printing-press/manifest.json +6 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/package.json +26 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/__tests__/manifest.test.ts +20 -0
- package/dist/plugins/fusion-plugin-cli-printing-press/src/index.ts +14 -0
- package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
- package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/package.json +1 -1
- package/dist/plugins/fusion-plugin-roadmap/{src/dashboard/RoadmapsView.css → bundled.css} +13 -219
- package/dist/plugins/fusion-plugin-roadmap/bundled.js +29535 -0
- package/dist/plugins/fusion-plugin-roadmap/package.json +4 -41
- package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
- package/package.json +2 -3
- package/dist/client/assets/ChatView-DhPkiEGs.js +0 -1
- package/dist/client/assets/ResearchView-BhWqfdV0.js +0 -1
- package/dist/client/assets/SettingsModal-BAgB4_AR.js +0 -31
- package/dist/client/assets/SettingsModal-DzsLquBu.css +0 -1
- package/dist/client/assets/index-Qq2JOOWx.css +0 -1
- package/dist/client/assets/index-TFYXEVpn.js +0 -692
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/api-client.test.ts +0 -101
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/index.test.ts +0 -92
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/roadmap-routes.test.ts +0 -48
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/roadmap-suggestions.test.ts +0 -31
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/RoadmapsView.tsx +0 -2559
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/__tests__/RoadmapsView.test.tsx +0 -1144
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/__tests__/useRoadmaps.test.ts +0 -1756
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/api.ts +0 -70
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/test-setup.ts +0 -7
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/types.ts +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useConfirm.ts +0 -8
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useRoadmaps.ts +0 -1188
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useViewportMode.ts +0 -20
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard-view.tsx +0 -6
- package/dist/plugins/fusion-plugin-roadmap/src/index.ts +0 -74
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-routes.ts +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-schema.ts +0 -41
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-suggestions.d.ts +0 -15
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-suggestions.ts +0 -15
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.d.ts +0 -283
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.js +0 -21
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.ts +0 -310
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.d.ts +0 -5
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.js +0 -361
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.ts +0 -408
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.d.ts +0 -68
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.js +0 -300
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.ts +0 -381
- package/dist/plugins/fusion-plugin-roadmap/src/server/index.d.ts +0 -3
- package/dist/plugins/fusion-plugin-roadmap/src/server/index.ts +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-handoff.test.ts +0 -445
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-ordering.test.ts +0 -334
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-store.test.ts +0 -1318
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-handoff.ts +0 -163
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.d.ts +0 -37
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.js +0 -188
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.ts +0 -311
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.d.ts +0 -299
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.d.ts.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.js +0 -765
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.js.map +0 -1
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.ts +0 -1001
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-
|
|
2
|
-
import{c as Xe,A as De,C as qe,Z as Kt,s as Zt,r as ht,F as pt,f as qt,a as Jt,b as Ft,B as xt,u as Pt,d as nt,e as Qt,g as Xt,h as Yt,i as es,j as wt,k as Qe,P as ts,l as ss,m as as,n as ns,o as Ct,G as ls,S as is,L as lt,T as it,R as Ge,X as St,p as rs,q as os,t as At,v as cs,w as ds,x as us,y as ms,z as fe,D as rt,E as gs,H as hs,N as ps,I as xs,J as
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-Cv-vgOj3.js","assets/vendor-react-K0fH_qHe.js","assets/index-Bdw6llW6.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-CZGlyJuS.css","assets/star-D75YKEq-.js","assets/ExperimentalAgentOnboardingModal-Bx6yXVS5.js","assets/ExperimentalAgentOnboardingModal-B-APN_lM.css","assets/AgentDetailView-BwJaLqZh.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as Xe,A as De,C as qe,Z as Kt,s as Zt,r as ht,F as pt,f as qt,a as Jt,b as Ft,B as xt,u as Pt,d as nt,e as Qt,g as Xt,h as Yt,i as es,j as wt,k as Qe,P as ts,l as ss,m as as,n as ns,o as Ct,G as ls,S as is,L as lt,T as it,R as Ge,X as St,p as rs,q as os,t as At,v as cs,w as ds,x as us,y as ms,z as fe,D as rt,E as gs,H as hs,N as ps,I as xs,J as bs,M as vs,K as js,O as fs,Q as Ns,U as ot,V as Tt,W as ys,_ as ks,Y as ws,$ as Ke,a0 as Cs,a1 as Rt,a2 as Ss,a3 as As,a4 as Ts}from"./index-Bdw6llW6.js";import{r as a,j as e,a as Rs}from"./vendor-react-K0fH_qHe.js";import{A as Es,S as Ms,E as _s,f as $s}from"./ExperimentalAgentOnboardingModal-Bx6yXVS5.js";import{U as zt}from"./upload-BYYTgWFj.js";import{F as Ls}from"./folder-open-BZuKESeq.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.
|
|
@@ -19,11 +19,11 @@ import{c as Xe,A as De,C as qe,Z as Kt,s as Zt,r as ht,F as pt,f as qt,a as Jt,b
|
|
|
19
19
|
*
|
|
20
20
|
* This source code is licensed under the ISC license.
|
|
21
21
|
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
-
*/const Os=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Bs=Xe("zoom-out",Os);function Et(n){return typeof n=="number"&&Number.isFinite(n)?n:0}function ze(n){return n.toLocaleString()}function Gs({agents:n}){const{rows:i,totalInputTokens:f,totalOutputTokens:u,totalTokens:d}=a.useMemo(()=>{const o=n.map(c=>{const v=Et(c.totalInputTokens),N=Et(c.totalOutputTokens);return{id:c.id,name:c.name,inputTokens:v,outputTokens:N,totalTokens:v+N}}).sort((c,v)=>v.totalTokens-c.totalTokens||c.name.localeCompare(v.name)||c.id.localeCompare(v.id));return{rows:o,totalInputTokens:o.reduce((c,v)=>c+v.inputTokens,0),totalOutputTokens:o.reduce((c,v)=>c+v.outputTokens,0),totalTokens:o.reduce((c,v)=>c+v.totalTokens,0)}},[n]),g=d>0;return e.jsxs("section",{className:"agent-token-stats-panel","aria-label":"Agent token usage statistics",children:[e.jsx("header",{className:"agent-token-stats-panel__header",children:e.jsx("h3",{className:"agent-token-stats-panel__title",children:"Token Usage by Agent"})}),e.jsxs("div",{className:"agent-token-stats-panel__totals",role:"list","aria-label":"Token usage totals",children:[e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Input Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(f)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Output Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(u)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Combined Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(d)})]})]}),g?e.jsx("div",{className:"agent-token-stats-panel__table-wrapper",children:e.jsxs("table",{className:"agent-token-stats-panel__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"Agent"}),e.jsx("th",{scope:"col",children:"Input"}),e.jsx("th",{scope:"col",children:"Output"}),e.jsx("th",{scope:"col",children:"Total"})]})}),e.jsx("tbody",{children:i.map(o=>e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",className:"agent-token-stats-panel__agent-cell",children:[e.jsx("span",{className:"agent-token-stats-panel__agent-name",children:o.name}),e.jsx("span",{className:"agent-token-stats-panel__agent-id",children:o.id})]}),e.jsx("td",{children:ze(o.inputTokens)}),e.jsx("td",{children:ze(o.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:ze(o.totalTokens)})]},o.id))})]})}):e.jsx("div",{className:"agent-token-stats-panel__empty",role:"status",children:"No token usage recorded yet. Token totals appear here once agents run."})]})}const Vs=[{icon:De,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:Fs,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:qe,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:Kt,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function Us({stats:n,className:i=""}){return n?e.jsx("div",{className:`agent-metrics-bar ${i}`.trim(),children:Vs.map(f=>{const u=f.valueKey==="successRate"?`${Math.round(n.successRate*100)}%`:n[f.valueKey];return e.jsxs("div",{className:`agent-metric-card ${f.className}`,children:[e.jsx(f.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:u}),e.jsx("span",{className:"agent-metric-label",children:f.label})]})]},f.label)})}):null}const Mt=200;function Ws(n,i){const[f,u]=a.useState([]),[d,g]=a.useState(!1),o=a.useRef(null),c=a.useRef(0),v=a.useRef(n),N=a.useRef(i);return(v.current!==n||N.current!==i)&&(v.current=n,N.current=i,c.current++,o.current&&(o.current(),o.current=null),u([]),g(!1)),a.useEffect(()=>{if(!n){u([]),g(!1);return}const E=c.current;let C=`/api/tasks/${encodeURIComponent(n)}/logs/stream`;i&&(C+=`?projectId=${encodeURIComponent(i)}`);const w=Zt(C,{events:{"agent:log":P=>{if(c.current===E)try{const T=JSON.parse(P.data),M={type:T.type??"text",text:T.text??T.content??"",timestamp:T.timestamp,content:T.content};u(S=>{const _=[M,...S];return _.length>Mt?_.slice(0,Mt):_})}catch{}}},onOpen:()=>{c.current===E&&g(!0)},onError:()=>{c.current===E&&g(!1)}});return o.current=w,()=>{w(),o.current=null,c.current===E&&g(!1)}},[n,i]),{entries:f,isConnected:d}}const Ks=5e3;function Zs({agent:n,projectId:i,onSelect:f,onOpenTaskLogs:u}){const{entries:d,isConnected:g}=Ws(n.taskId,i),[o,c]=a.useState(null);a.useEffect(()=>{if(!n.taskId){c(null);return}let S=!1,_;const p=async()=>{try{const I=await qt(n.taskId,i);S||c(I)}catch{}finally{S||(_=setTimeout(p,Ks))}};return p(),()=>{S=!0,_&&clearTimeout(_)}},[n.taskId,i]);const v=n.lastHeartbeatAt?Math.floor((Date.now()-new Date(n.lastHeartbeatAt).getTime())/1e3):0,N=(()=>{if(!n.lastHeartbeatAt)return null;const S=ht(n.runtimeConfig?.heartbeatIntervalMs),_=new Date(n.lastHeartbeatAt).getTime()+S,p=Math.round((_-Date.now())/1e3);return Number.isFinite(p)?p<=0?`Heartbeat overdue ${ct(-p)}`:`Next heartbeat in ${ct(p)}`:null})(),k=o?.steps?.[o.currentStep??0],E=o?.steps?.length??0,C=(o?.currentStep??0)+1,w=o?.modelId,P=()=>{f&&f(n.id)},T=S=>{S.stopPropagation(),n.taskId&&u&&u(n.taskId)},M=S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),P())};return e.jsxs("div",{className:"live-agent-card",onClick:P,onKeyDown:M,role:"button",tabIndex:0,"aria-label":`Select agent ${n.name}`,children:[e.jsxs("div",{className:"live-agent-card-header",children:[e.jsxs("div",{className:"live-agent-card-name",children:[e.jsx("span",{className:`status-dot ${n.state==="running"?"status-dot--pending":"status-dot--online"}`,"aria-hidden":"true"}),e.jsx("span",{children:n.name})]}),n.taskId&&e.jsx("span",{className:"live-agent-task badge",children:n.taskId})]}),e.jsx("div",{className:"live-agent-card-transcript",children:d.length===0?e.jsx("div",{className:"live-agent-card-empty",children:n.taskId?k?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"live-agent-card-status",children:["Step ",C,E?`/${E}`:"",": ",k.name]}),w&&e.jsx("div",{className:"live-agent-card-status-sub",children:w}),e.jsx("div",{className:"live-agent-card-status-sub",children:g?"Waiting for output...":"Connecting to log stream..."})]}):e.jsx("span",{children:g?"Waiting for output...":"Connecting..."}):e.jsx("span",{children:n.state==="running"?"Starting...":"Idle — no task assigned"})}):d.slice(0,20).map((S,_)=>e.jsx("div",{className:"live-agent-card-line",children:S.text},_))}),e.jsxs("div",{className:"live-agent-card-footer",children:[e.jsxs("div",{className:"live-agent-card-footer-meta",children:[e.jsx("span",{className:"text-secondary",title:"Time since last heartbeat",children:ct(v)}),N&&e.jsx("span",{className:"live-agent-card-next-heartbeat",title:N,children:N})]}),e.jsxs("div",{className:"live-agent-card-footer-actions",children:[n.taskId&&u&&e.jsxs("button",{type:"button",className:"live-agent-card-logs-btn",onClick:T,title:"View live run logs","aria-label":`View live logs for ${n.taskId}`,children:[e.jsx(pt,{size:12}),e.jsx("span",{children:"Live logs"})]}),g&&e.jsx(De,{size:12,className:"live-agent-streaming-dot"})]})]})]})}function ct(n){return n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m ${n%60}s`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`}function qs({agents:n,projectId:i,onAgentSelect:f,onOpenTaskLogs:u,className:d=""}){const g=Array.from(new Map(n.map(o=>[o.id,o])).values());return g.length===0?null:e.jsxs("div",{className:`active-agents-panel ${d}`.trim(),children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(De,{size:16}),e.jsxs("span",{children:["Active Agents (",g.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:g.map(o=>e.jsx(Zs,{agent:o,projectId:i,onSelect:f,onOpenTaskLogs:u},o.id))})]})}function Js({stats:n,activeAgents:i,projectId:f,isOpen:u,onToggle:d,onSelectAgent:g,onOpenTaskLogs:o}){return e.jsxs("section",{className:"agents-overview-bar","aria-label":"Agents overview",children:[e.jsxs("button",{type:"button",className:"agents-overview-bar__toggle","aria-expanded":u,onClick:d,children:[e.jsxs("span",{className:"agents-overview-bar__title-wrap",children:[u?e.jsx(Jt,{size:16,"aria-hidden":"true"}):e.jsx(Ft,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"agents-overview-bar__title",children:"Overview"})]}),e.jsxs("span",{className:"agents-overview-bar__meta text-secondary",children:[i.filter(c=>c.state==="active").length," active · ",i.filter(c=>c.state==="running").length," running"]})]}),u?e.jsxs("div",{className:"agents-overview-bar__content",children:[e.jsx(Us,{stats:n,className:"agents-overview-bar__metrics"}),e.jsx(qs,{agents:i,projectId:f,onAgentSelect:g,onOpenTaskLogs:o,className:"agents-overview-bar__active-panel"})]}):null]})}function dt({title:n="No agents found",description:i="Create an agent to get started",ctaLabel:f="Create Agent",onCtaClick:u}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(xt,{size:48,opacity:.3,className:"agent-empty-state__icon"}),e.jsx("p",{className:"agent-empty-state__title",children:n}),e.jsx("p",{className:"agent-empty-state__description text-secondary",children:i}),u?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:u,children:f}):null]})}const _t=3,ut=1e3;function Qs({isOpen:n,onClose:i,onGenerated:f,projectId:u}){Pt(n);const[d,g]=a.useState(""),[o,c]=a.useState({type:"input"}),[v,N]=a.useState(null),[k,E]=a.useState(!1),C=a.useRef(null),w=a.useRef(null);a.useEffect(()=>{n&&o.type==="input"&&w.current?.focus()},[n,o.type]),a.useEffect(()=>{if(!n&&C.current){const p=C.current;C.current=null,nt(p,u).catch(()=>{})}},[n,u]),a.useEffect(()=>{if(!n)return;const p=I=>{I.key==="Escape"&&P()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[n]);const P=a.useCallback(()=>{if(C.current){const p=C.current;C.current=null,nt(p,u).catch(()=>{})}g(""),c({type:"input"}),N(null),E(!1),i()},[i,u]),T=a.useCallback(async()=>{if(!(!d.trim()||d.trim().length<_t)){N(null),c({type:"loading"});try{const{sessionId:p}=await Qt(d.trim(),u);C.current=p;const{spec:I}=await Xt(p,u);c({type:"preview",spec:I,sessionId:p})}catch(p){const I=p instanceof Error?p.message:"Failed to generate agent specification";I.includes("429")||I.toLowerCase().includes("rate limit")?N("Too many requests. Please wait a moment and try again."):N(I),c({type:"input"}),C.current=null}}},[d,u]),M=a.useCallback(async()=>{if(C.current){const p=C.current;C.current=null;try{await nt(p,u)}catch{}}await T()},[T,u]),S=a.useCallback(()=>{o.type==="preview"&&(C.current=null,f(o.spec),g(""),c({type:"input"}),N(null),E(!1),i())},[o,f,i]);if(!n)return null;const _=d.trim().length>=_t&&d.trim().length<=ut;return e.jsx("div",{className:"agent-dialog-overlay",onClick:p=>{p.target===p.currentTarget&&P()},children:e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Generate agent with AI",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsxs("span",{className:"agent-dialog-header-title",children:[e.jsx("span",{className:"agent-dialog-header-sparkle",children:"✨"}),"Generate Agent"]}),e.jsx("button",{className:"modal-close",onClick:P,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[v&&e.jsx("div",{className:"agent-dialog-error-banner",children:v}),o.type==="input"&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Describe your agent's role and the AI will generate a complete specification including system prompt, suggested configuration, and more."}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-role-description",children:"Role Description"}),e.jsx("textarea",{ref:w,id:"agent-role-description",className:"input agent-dialog-textarea",rows:4,placeholder:'e.g. "Senior frontend code reviewer who specializes in React accessibility"',value:d,onChange:p=>g(p.target.value),onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&_&&(p.preventDefault(),T())},maxLength:ut,"aria-describedby":"role-description-hint"}),e.jsxs("div",{id:"role-description-hint",className:"agent-dialog-hint",children:[e.jsx("span",{children:"Describe what your agent should do"}),e.jsxs("span",{children:[d.length,"/",ut]})]})]})]}),o.type==="loading"&&e.jsxs("div",{className:"agent-dialog-loading-center",children:[e.jsx("div",{className:"agent-dialog-spinner spin"}),e.jsx("p",{className:"agent-dialog-loading-text",children:"Generating agent specification..."})]}),o.type==="preview"&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-summary agent-dialog-summary--spaced",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Title"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[o.spec.icon," ",o.spec.title]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Role"}),e.jsx("span",{children:o.spec.role})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Description"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--body",children:o.spec.description})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--capitalize",children:o.spec.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Max Turns"}),e.jsx("span",{children:o.spec.maxTurns})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{children:["System Prompt",e.jsx("button",{type:"button",className:"agent-dialog-expand-btn",onClick:()=>E(!k),children:k?"Collapse":"Expand"})]}),e.jsxs("div",{className:`agent-generation-prompt-box${k?"":" agent-generation-prompt-box--collapsed"}`,children:[o.spec.systemPrompt,!k&&o.spec.systemPrompt.length>500&&e.jsx("div",{className:"agent-generation-prompt-fade"})]})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[e.jsx("button",{className:"btn",onClick:P,children:"Cancel"}),o.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void T(),disabled:!_,children:"Generate"}),o.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void M(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:S,children:"Use This"})]})]})]})})}const $t=[{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:"✦"}],Lt=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Xs({isOpen:n,onClose:i,onCreated:f,projectId:u,prefillDraft:d=null,agentOnboardingEnabled:g=!1,existingAgents:o=[],onPrefillDraft:c}){const[v,N]=a.useState(0),[k,E]=a.useState("presets"),[C,w]=a.useState(""),[P,T]=a.useState(""),[M,S]=a.useState(""),[_,p]=a.useState("custom"),[I,$]=a.useState(""),[ee,Ne]=a.useState(""),[oe,te]=a.useState(""),[le,ce]=a.useState(""),[z,y]=a.useState(""),[xe,ve]=a.useState(""),[A,se]=a.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[de,ye]=a.useState(null),[ae,V]=a.useState([]),[ue,G]=a.useState(!1),[U,J]=a.useState(null),[be,ie]=a.useState(!1),[W,Q]=a.useState(!1),[Ee,Me]=a.useState([]),[_e,ke]=a.useState(!1),[me,we]=a.useState([]),[X,$e]=a.useState([]),[H,F]=a.useState("model"),[re,K]=a.useState(""),[Ce,Y]=a.useState([]),[Se,Ae]=a.useState(!1),[l,x]=a.useState([]),[R,Z]=a.useState(!1);a.useEffect(()=>{n&&(ke(!0),Yt().then(s=>{Me(s.models),we(s.favoriteProviders),$e(s.favoriteModels)}).catch(()=>{}).finally(()=>ke(!1)))},[n]),a.useEffect(()=>{n&&(Z(!0),x([]),es(void 0,u).then(s=>{x(s)}).catch(()=>{x([])}).finally(()=>Z(!1)))},[n,u]),a.useEffect(()=>{if(!n)return;const s=ss;if(typeof s!="function"){Y([]),Ae(!1);return}Ae(!0),Y([]),s(u).then(b=>{Y(b)}).catch(()=>{Y([])}).finally(()=>Ae(!1))},[n,u]);const L=A.model.includes("/")?A.model:"",D=a.useCallback(s=>{const b=Lt.has(s.role)?s.role:"custom";w(s.title),T(s.description),S(s.icon),p(b),te(s.systemPrompt),se(he=>({...he,thinkingLevel:s.thinkingLevel,maxTurns:s.maxTurns})),ie(!1),N(1)},[]),Te=a.useCallback(s=>{se(b=>({...b,model:s}))},[]),Le=a.useCallback(s=>{F(s),s==="model"&&K("")},[]),Fe=a.useCallback(async s=>{const b=me,ne=b.includes(s)?b.filter(Re=>Re!==s):[s,...b];we(ne);try{await wt({favoriteProviders:ne,favoriteModels:X})}catch{we(b)}},[me,X]),Ie=a.useCallback(async s=>{const b=X,ne=b.includes(s)?b.filter(Re=>Re!==s):[s,...b];$e(ne);try{await wt({favoriteProviders:me,favoriteModels:ne})}catch{$e(b)}},[me,X]),Ye=a.useCallback(s=>{ye(s.id),w(s.name),S(s.icon),T(s.description??s.title),p(s.role),y(s.soul??""),te(s.instructionsText??""),N(1)},[]),je=a.useCallback(s=>{const b=s.runtimeHint?.trim()??"",he=s.model?.trim()||s.modelHint?.trim()||"";N(1),E("custom"),w(s.name??""),T(s.title??""),S(s.icon??""),p(Lt.has(s.role)?s.role:"custom"),$(s.reportsTo??""),te(s.instructionsText??""),ce(s.heartbeatProcedurePath??""),y(s.soul??""),ve(s.memory??""),V(Array.isArray(s.skills)?s.skills:[]),se(ne=>({...ne,model:b?"":he,thinkingLevel:s.thinkingLevel??ne.thinkingLevel,maxTurns:s.maxTurns??ne.maxTurns})),b?(F("runtime"),K(b)):(F("model"),K(""))},[]);if(a.useEffect(()=>{!n||!d||je(d)},[n,d,je]),!n)return null;const ge=()=>{N(0),E("presets"),w(""),T(""),S(""),p("custom"),$(""),Ne(""),te(""),ce(""),y(""),ve(""),se({model:"",thinkingLevel:"off",maxTurns:1e3}),F("model"),K(""),ye(null),V([]),J(null),ie(!1),Q(!1),i()},et=async()=>{if(C.trim()){G(!0),J(null);try{const s={};H==="runtime"?re.trim()&&(s.runtimeHint=re.trim()):A.model.trim()&&(s.model=A.model.trim()),A.thinkingLevel!=="off"&&(s.thinkingLevel=A.thinkingLevel),A.maxTurns!==1e3&&(s.maxTurns=A.maxTurns),await ns({name:C.trim(),role:_,...P.trim()?{title:P.trim()}:{},...M.trim()?{icon:M.trim()}:{},...I.trim()?{reportsTo:I.trim()}:{},...ee.trim()?{instructionsPath:ee.trim()}:{},...oe.trim()?{instructionsText:oe.trim()}:{},...le.trim()?{heartbeatProcedurePath:le.trim()}:{},...z.trim()?{soul:z.trim()}:{},...xe.trim()?{memory:xe.trim()}:{},...Object.keys(s).length>0?{runtimeConfig:s}:{},...ae.length>0?{metadata:{skills:ae}}:{}},u),ge(),f()}catch(s){J(s instanceof Error?s.message:"Failed to create agent")}finally{G(!1)}}},Ve=$t.find(s=>s.value===_),Pe=I.trim(),He=Pe?l.find(s=>s.id===Pe):void 0,Oe=re?Ce.find(s=>s.runtimeId===re):void 0,Ue=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:s,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":s,children:[e.jsxs("label",{className:`agent-runtime-mode-option${H==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"model",checked:H==="model",onChange:()=>Le("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${H==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"runtime",checked:H==="runtime",onChange:()=>Le("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),H==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),_e?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(as,{id:"agent-model",label:"Model",value:L,onChange:Te,models:Ee,placeholder:"Select a model…",favoriteProviders:me,onToggleFavorite:Fe,favoriteModels:X,onToggleModelFavorite:Ie})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),Se?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:re,onChange:b=>K(b.target.value),children:[e.jsx("option",{value:"",children:Ce.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),Ce.map(b=>e.jsx("option",{value:b.runtimeId,children:b.description?`${b.name} — ${b.description}`:b.name},`${b.pluginId}:${b.runtimeId}`))]})]})]});return Rs.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:s=>{s.target===s.currentTarget&&ge()},children:[e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Create new agent",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"New Agent"}),e.jsx("button",{className:"btn-icon",onClick:ge,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(s=>e.jsx("div",{className:`agent-dialog-step${s===v?" active":s<v?" completed":""}`,"aria-label":`Step ${s+1}`},s))}),e.jsxs("div",{className:"agent-dialog-body",children:[v===0&&e.jsxs("div",{children:[g&&e.jsx("div",{className:"agent-dialog-step-zero-actions",children:e.jsx("button",{type:"button",className:"btn agent-dialog-interview-btn",onClick:()=>Q(!0),children:"AI Interview"})}),e.jsxs("div",{className:"agent-dialog-tabs",role:"tablist","aria-label":"Agent setup mode",children:[e.jsx("button",{id:"agent-dialog-tab-presets",type:"button",role:"tab","aria-controls":"agent-dialog-panel-presets","aria-selected":k==="presets",tabIndex:k==="presets"?0:-1,className:`agent-dialog-tab${k==="presets"?" active":""}`,onClick:()=>E("presets"),"data-testid":"agent-dialog-tab-presets",children:"Preset personas"}),e.jsx("button",{id:"agent-dialog-tab-custom",type:"button",role:"tab","aria-controls":"agent-dialog-panel-custom","aria-selected":k==="custom",tabIndex:k==="custom"?0:-1,className:`agent-dialog-tab${k==="custom"?" active":""}`,onClick:()=>E("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),k==="presets"&&e.jsx("div",{id:"agent-dialog-panel-presets",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-presets",children:e.jsxs("div",{className:"agent-presets",children:[e.jsx("div",{className:"agent-presets-header",children:"Choose a preset persona to prefill role, identity, soul, and instructions"}),e.jsx("div",{className:"agent-presets-grid",children:Es.map(s=>e.jsxs("button",{type:"button",className:`agent-preset-card${de===s.id?" selected":""}`,"data-testid":`preset-${s.id}`,onClick:()=>Ye(s),title:s.title,children:[e.jsx("span",{className:"agent-preset-icon",children:e.jsx(Qe,{agent:{id:s.id,icon:s.icon,name:s.name},size:28})}),e.jsx("span",{className:"agent-preset-name",children:s.name}),e.jsx("span",{className:"agent-preset-role",children:s.role}),s.description&&e.jsx("span",{className:"agent-preset-description",children:s.description})]},s.id))})]})}),k==="custom"&&e.jsxs("div",{id:"agent-dialog-panel-custom",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-custom",children:[e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Identity"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-name",children:["Name ",!de&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:C,onChange:s=>w(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field agent-dialog-field--title",children:[e.jsxs("label",{htmlFor:"agent-title",children:["Title ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:P,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-icon",children:["Icon ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:M,onChange:s=>S(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:$t.map(s=>e.jsxs("button",{type:"button",className:`agent-role-option${_===s.value?" selected":""}`,onClick:()=>p(s.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:s.icon}),e.jsx("span",{className:"agent-role-option-label",children:s.label})]},s.value))})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Configuration"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-reports-to",children:["Reports To ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:I,onChange:s=>$(s.target.value),disabled:R,children:[e.jsx("option",{value:"",children:"No manager"}),l.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.id,")"]},s.id))]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-soul",children:["Soul ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:z,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-memory",children:["Agent Memory ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-memory",className:"input",rows:2,placeholder:"Private to this agent — durable preferences, operating habits, and context it should carry across tasks...",value:xe,onChange:s=>ve(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-path",children:["Instructions Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:ee,onChange:s=>Ne(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-heartbeat-procedure-path",children:["Heartbeat Procedure Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-heartbeat-procedure-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/ceo-agent2736/HEARTBEAT.md",value:le,onChange:s=>ce(s.target.value)}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-field-hint",children:"Path to the agent's heartbeat procedure path, typically .fusion/agents/ceo-agent2736/HEARTBEAT.md. Legacy id-only default paths still work."})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-text",children:["Inline Instructions ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:oe,onChange:s=>te(s.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),Ue("agent-runtime-source-step-0")]}),e.jsxs("div",{className:"agent-dialog-ai-generate",children:[e.jsxs("button",{type:"button",className:"btn btn--ai-generate",onClick:()=>ie(!0),children:[e.jsx("span",{children:"✨"}),"Generate with AI"]}),e.jsx("p",{className:"agent-dialog-ai-hint",children:"Describe your agent's role and let AI generate a specification"})]})]})]}),v===1&&e.jsxs("div",{children:[Ue("agent-runtime-source-step-1"),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-thinking",children:"Thinking Level"}),e.jsxs("select",{id:"agent-thinking",className:"select",value:A.thinkingLevel,onChange:s=>se(b=>({...b,thinkingLevel:s.target.value})),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"minimal",children:"Minimal"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-max-turns",children:"Max Turns"}),e.jsx("input",{id:"agent-max-turns",type:"number",className:"input",min:1,max:2e3,value:A.maxTurns,onChange:s=>se(b=>({...b,maxTurns:Math.max(1,parseInt(s.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(Ms,{id:"agent-skills",label:"Skills",value:ae,onChange:V,projectId:u}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),v===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:[M&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:M}),C]})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable agent-dialog-summary-row--title",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-title",children:"Title"}),e.jsx("input",{id:"agent-review-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:P,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Role"}),e.jsxs("span",{children:[Ve?.icon," ",Ve?.label]})]}),Pe&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Reports To"}),e.jsx("span",{children:He?`${He.name} (${He.id})`:Pe})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-soul",children:"Soul"}),e.jsx("textarea",{id:"agent-review-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:z,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-heartbeat-procedure-path",children:"Heartbeat Procedure Path"}),e.jsx("input",{id:"agent-review-heartbeat-procedure-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/ceo-agent2736/HEARTBEAT.md",value:le,onChange:s=>ce(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-instructions-path",children:"Instructions Path"}),e.jsx("input",{id:"agent-review-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:ee,onChange:s=>Ne(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-instructions-text",children:"Inline Instructions"}),e.jsx("textarea",{id:"agent-review-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:oe,onChange:s=>te(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:H==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:H==="runtime"?Oe?Oe.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):L?e.jsxs(e.Fragment,{children:[e.jsx(ts,{provider:L.split("/")[0],size:"sm"})," ",(()=>{const s=L.indexOf("/"),b=L.slice(0,s),he=L.slice(s+1);return Ee.find(Re=>Re.provider===b&&Re.id===he)?.name||L})()]}):e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"default"})})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value--capitalize",children:A.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Max Turns"}),e.jsx("span",{children:A.maxTurns})]}),ae.length>0&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Skills"}),e.jsxs("span",{children:[ae.length," skill",ae.length!==1?"s":""," selected"]})]})]}),U&&e.jsx("p",{className:"agent-dialog-error",children:U})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[v>0&&e.jsx("button",{className:"btn",onClick:()=>N(s=>s-1),disabled:ue,children:"Back"}),e.jsx("button",{className:"btn",onClick:ge,disabled:ue,children:"Cancel"}),v<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>N(s=>s+1),disabled:v===0&&!C.trim()&&!de,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void et(),disabled:ue||!C.trim(),children:ue?"Creating...":"Create"})]})]}),e.jsx(Qs,{isOpen:be,onClose:()=>ie(!1),onGenerated:D,projectId:u}),e.jsx(_s,{isOpen:W,onClose:()=>Q(!1),onUseDraft:s=>{c?.(s),c||je(s),Q(!1)},projectId:u,existingAgents:o,mode:"create"})]}),document.body)}function Ys(n){const i=n.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!i)throw new Error("Missing YAML frontmatter delimiters (---)");const f=i[1].split(/\r?\n/),u=i[2]??"",d={name:""},g=[];let o=!1;for(const c of f){const N=c.trimEnd().trim();if(!N)continue;if(N.startsWith("skills:")){o=!0;continue}if(o&&N.startsWith("- ")){g.push(N.slice(2).trim());continue}o=!1;const[k,...E]=N.split(":"),w=E.join(":").trim().replace(/^['"]|['"]$/g,"");k==="name"&&(d.name=w),k==="title"&&(d.title=w),k==="icon"&&(d.icon=w),k==="role"&&(d.role=w),k==="reportsTo"&&(d.reportsTo=w)}if(!d.name)throw new Error("Missing required field: name");return g.length>0&&(d.skills=g),u.trim().length>0&&(d.instructionBody=u),d}function ea({isOpen:n,onClose:i,onImported:f,projectId:u,initialInputMethod:d="paste"}){Pt(n);const[g,o]=a.useState("input"),[c,v]=a.useState(d),[N,k]=a.useState(""),[E,C]=a.useState([]),[w,P]=a.useState("Unknown"),[T,M]=a.useState([]),[S,_]=a.useState([]),[p,I]=a.useState([]),[$,ee]=a.useState([]),[Ne,oe]=a.useState(!1),[te,le]=a.useState(!1),[ce,z]=a.useState(null),[y,xe]=a.useState(null),[ve,A]=a.useState(null),se=a.useRef(null),de=a.useRef(null),[ye,ae]=a.useState([]),[V,ue]=a.useState(""),[G,U]=a.useState(null),[J,be]=a.useState(!1),[ie,W]=a.useState(null),Q=a.useRef(!1);a.useEffect(()=>{c==="browse"&&!Q.current&&!J&&(Q.current=!0,be(!0),W(null),Ct().then(l=>{l.error?W(l.error):l.companies.length>0?ae(l.companies):W("No companies available")}).catch(l=>{W(l instanceof Error?l.message:"Failed to load companies")}).finally(()=>{be(!1)}))},[c,J]);const Ee=a.useCallback(()=>{Q.current=!0,W(null),ae([]),U(null),be(!0),Ct().then(l=>{l.error?W(l.error):l.companies.length>0?ae(l.companies):W("No companies available")}).catch(l=>{W(l instanceof Error?l.message:"Failed to load companies")}).finally(()=>{be(!1)})},[]),Me=a.useCallback(()=>{o("input"),v(d),k(""),C([]),P("Unknown"),M([]),_([]),I([]),ee([]),oe(!1),le(!1),z(null),xe(null),A(null),ae([]),ue(""),U(null),be(!1),W(null),Q.current=!1},[d]),_e=a.useCallback(()=>{Me(),i()},[Me,i]),ke=a.useCallback(l=>{const x=l.target.files?.[0];if(!x)return;const R=new FileReader;R.onload=Z=>{const L=Z.target?.result;v("file"),C([]),k(L),z(null)},R.onerror=()=>{z("Failed to read file")},R.readAsText(x),l.target.value=""},[]),me=a.useCallback(async l=>{const x=Array.from(l.target.files??[]);if(x.length!==0)try{const R=x.filter(L=>(L.webkitRelativePath||L.name).toLowerCase().endsWith("agents.md")).sort((L,D)=>{const Te=L.webkitRelativePath||L.name,Le=D.webkitRelativePath||D.name;return Te.localeCompare(Le)});if(R.length===0){z("Selected directory has no AGENTS.md files");return}const Z=[];for(const L of R){const D=await L.text();Z.push(Ys(D))}v("directory"),C(Z),k(""),z(null)}catch{z("Failed to parse AGENTS.md files from selected directory")}finally{l.target.value=""}},[]);function we(l){if(!u)return`/api${l}`;const x=l.includes("?")?"&":"?";return`/api${l}${x}projectId=${encodeURIComponent(u)}`}const X=a.useCallback(async()=>{if(c==="directory"&&E.length===0){z("Please select a directory containing AGENTS.md files");return}if(c==="browse"&&!G){z("Please select a company from the catalog");return}if(c!=="directory"&&c!=="browse"&&!N.trim()){z("Please provide manifest content");return}oe(!0),z(null);try{let l;c==="directory"?l={agents:E,dryRun:!0}:c==="browse"&&G?l={importSource:"companies.sh",companySlug:G.slug,dryRun:!0}:l={manifest:N,dryRun:!0};const x=await fetch(we("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!x.ok){const D=await x.json();throw new Error(D.error??`Parse failed (${x.status})`)}const R=await x.json(),Z=R.agents&&R.agents.length>0?R.agents:R.created.map(D=>({name:D,role:"custom"})),L=Array.isArray(R.skills)?R.skills:[];P(R.companyName??"Unknown"),M(Z),_(L),I(Z.map(D=>D.name)),ee(L.map(D=>D.name)),o("preview")}catch(l){z(l instanceof Error?l.message:"Failed to parse manifest")}finally{oe(!1)}},[c,E,N,G,u]),$e=a.useCallback(async()=>{le(!0),A(null);try{let l;c==="directory"?l={agents:E,skipExisting:!0,selectedAgents:p,selectedSkills:$}:c==="browse"&&G?l={importSource:"companies.sh",companySlug:G.slug,skipExisting:!0,selectedAgents:p,selectedSkills:$}:l={manifest:N,skipExisting:!0,selectedAgents:p,selectedSkills:$};const x=await fetch(we("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!x.ok){const Z=await x.json();throw new Error(Z.error??`Import failed (${x.status})`)}const R=await x.json();xe(R),o("result"),f()}catch(l){A(l instanceof Error?l.message:"Failed to import agents")}finally{le(!1)}},[c,E,N,G,p,$,u,f]),H=p.length,F=$.length,re=`${H} Agent${H!==1?"s":""}`,K=`${F} Skill${F!==1?"s":""}`,Ce=H>0&&F>0?`${re} + ${K}`:F>0?K:re,Y=H>0&&F>0?`Importing ${H} agent${H!==1?"s":""} and ${F} skill${F!==1?"s":""}...`:F>0?`Importing ${F} skill${F!==1?"s":""}...`:`Importing ${H} agent${H!==1?"s":""}...`,Se=l=>{I(x=>x.includes(l)?x.filter(R=>R!==l):[...x,l])},Ae=l=>{ee(x=>x.includes(l)?x.filter(R=>R!==l):[...x,l])};return n?e.jsx("div",{className:"agent-dialog-overlay",onClick:l=>{l.target===l.currentTarget&&_e()},children:e.jsxs("div",{className:"agent-dialog agent-import-dialog",role:"dialog","aria-modal":"true","aria-label":"Import agents",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"Import Agents"}),e.jsx("button",{className:"modal-close",onClick:_e,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[g==="input"&&e.jsxs("div",{className:"agent-import-input",children:[e.jsx("p",{className:"agent-import-description",children:"Import agents from an Agent Companies package. Browse the companies.sh catalog to discover published agents, upload an AGENTS.md file, select a directory, or paste manifest content."}),e.jsxs("div",{className:"agent-import-file-upload",children:[e.jsx("input",{ref:se,type:"file",accept:".md,.txt",onChange:ke,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:de,type:"file",webkitdirectory:"",multiple:!0,onChange:me,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>se.current?.click(),children:[e.jsx(zt,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>de.current?.click(),children:[e.jsx(Ls,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{v("browse"),C([]),k(""),U(null),z(null)},children:[e.jsx(ls,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),c==="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(is,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:V,onChange:l=>ue(l.target.value),"aria-label":"Search companies"})]}),G&&e.jsxs("div",{className:"agent-import-browse-selected",children:[e.jsx("span",{className:"agent-import-browse-selected-label",children:"Selected:"}),e.jsx("span",{className:"agent-import-browse-selected-name",children:G.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>U(null),children:"Change"})]})]}),J&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(lt,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),ie&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(it,{size:16}),e.jsx("span",{children:ie}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Ee,children:[e.jsx(Ge,{size:14}),"Retry"]})]}),!J&&!ie&&e.jsxs("div",{className:"agent-import-browse-list",children:[ye.filter(l=>V===""||l.name.toLowerCase().includes(V.toLowerCase())||(l.tagline?.toLowerCase().includes(V.toLowerCase())??!1)).map(l=>e.jsxs("div",{className:`agent-import-browse-item ${G?.slug===l.slug?"agent-import-browse-item--selected":""}`,onClick:()=>U(l),role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&U(l)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:l.name}),l.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[l.installs.toLocaleString()," installs"]})]}),l.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:l.tagline}),l.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:l.repo})]},l.slug)),ye.filter(l=>V===""||l.name.toLowerCase().includes(V.toLowerCase())||(l.tagline?.toLowerCase().includes(V.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:V?"No companies match your search":"No companies available"})]})]}),c!=="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:`---
|
|
22
|
+
*/const Os=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Bs=Xe("zoom-out",Os);function Et(n){return typeof n=="number"&&Number.isFinite(n)?n:0}function ze(n){return n.toLocaleString()}function Gs({agents:n}){const{rows:i,totalInputTokens:f,totalOutputTokens:u,totalTokens:d}=a.useMemo(()=>{const o=n.map(c=>{const b=Et(c.totalInputTokens),N=Et(c.totalOutputTokens);return{id:c.id,name:c.name,inputTokens:b,outputTokens:N,totalTokens:b+N}}).sort((c,b)=>b.totalTokens-c.totalTokens||c.name.localeCompare(b.name)||c.id.localeCompare(b.id));return{rows:o,totalInputTokens:o.reduce((c,b)=>c+b.inputTokens,0),totalOutputTokens:o.reduce((c,b)=>c+b.outputTokens,0),totalTokens:o.reduce((c,b)=>c+b.totalTokens,0)}},[n]),g=d>0;return e.jsxs("section",{className:"agent-token-stats-panel","aria-label":"Agent token usage statistics",children:[e.jsx("header",{className:"agent-token-stats-panel__header",children:e.jsx("h3",{className:"agent-token-stats-panel__title",children:"Token Usage by Agent"})}),e.jsxs("div",{className:"agent-token-stats-panel__totals",role:"list","aria-label":"Token usage totals",children:[e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Input Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(f)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Output Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(u)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Combined Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:ze(d)})]})]}),g?e.jsx("div",{className:"agent-token-stats-panel__table-wrapper",children:e.jsxs("table",{className:"agent-token-stats-panel__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"Agent"}),e.jsx("th",{scope:"col",children:"Input"}),e.jsx("th",{scope:"col",children:"Output"}),e.jsx("th",{scope:"col",children:"Total"})]})}),e.jsx("tbody",{children:i.map(o=>e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",className:"agent-token-stats-panel__agent-cell",children:[e.jsx("span",{className:"agent-token-stats-panel__agent-name",children:o.name}),e.jsx("span",{className:"agent-token-stats-panel__agent-id",children:o.id})]}),e.jsx("td",{children:ze(o.inputTokens)}),e.jsx("td",{children:ze(o.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:ze(o.totalTokens)})]},o.id))})]})}):e.jsx("div",{className:"agent-token-stats-panel__empty",role:"status",children:"No token usage recorded yet. Token totals appear here once agents run."})]})}const Vs=[{icon:De,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:Fs,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:qe,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:Kt,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function Us({stats:n,className:i=""}){return n?e.jsx("div",{className:`agent-metrics-bar ${i}`.trim(),children:Vs.map(f=>{const u=f.valueKey==="successRate"?`${Math.round(n.successRate*100)}%`:n[f.valueKey];return e.jsxs("div",{className:`agent-metric-card ${f.className}`,children:[e.jsx(f.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:u}),e.jsx("span",{className:"agent-metric-label",children:f.label})]})]},f.label)})}):null}const Mt=200;function Ws(n,i){const[f,u]=a.useState([]),[d,g]=a.useState(!1),o=a.useRef(null),c=a.useRef(0),b=a.useRef(n),N=a.useRef(i);return(b.current!==n||N.current!==i)&&(b.current=n,N.current=i,c.current++,o.current&&(o.current(),o.current=null),u([]),g(!1)),a.useEffect(()=>{if(!n){u([]),g(!1);return}const E=c.current;let C=`/api/tasks/${encodeURIComponent(n)}/logs/stream`;i&&(C+=`?projectId=${encodeURIComponent(i)}`);const w=Zt(C,{events:{"agent:log":P=>{if(c.current===E)try{const T=JSON.parse(P.data),M={type:T.type??"text",text:T.text??T.content??"",timestamp:T.timestamp,content:T.content};u(S=>{const _=[M,...S];return _.length>Mt?_.slice(0,Mt):_})}catch{}}},onOpen:()=>{c.current===E&&g(!0)},onError:()=>{c.current===E&&g(!1)}});return o.current=w,()=>{w(),o.current=null,c.current===E&&g(!1)}},[n,i]),{entries:f,isConnected:d}}const Ks=5e3;function Zs({agent:n,projectId:i,onSelect:f,onOpenTaskLogs:u}){const{entries:d,isConnected:g}=Ws(n.taskId,i),[o,c]=a.useState(null);a.useEffect(()=>{if(!n.taskId){c(null);return}let S=!1,_;const p=async()=>{try{const I=await qt(n.taskId,i);S||c(I)}catch{}finally{S||(_=setTimeout(p,Ks))}};return p(),()=>{S=!0,_&&clearTimeout(_)}},[n.taskId,i]);const b=n.lastHeartbeatAt?Math.floor((Date.now()-new Date(n.lastHeartbeatAt).getTime())/1e3):0,N=(()=>{if(!n.lastHeartbeatAt)return null;const S=ht(n.runtimeConfig?.heartbeatIntervalMs),_=new Date(n.lastHeartbeatAt).getTime()+S,p=Math.round((_-Date.now())/1e3);return Number.isFinite(p)?p<=0?`Heartbeat overdue ${ct(-p)}`:`Next heartbeat in ${ct(p)}`:null})(),k=o?.steps?.[o.currentStep??0],E=o?.steps?.length??0,C=(o?.currentStep??0)+1,w=o?.modelId,P=()=>{f&&f(n.id)},T=S=>{S.stopPropagation(),n.taskId&&u&&u(n.taskId)},M=S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),P())};return e.jsxs("div",{className:"live-agent-card",onClick:P,onKeyDown:M,role:"button",tabIndex:0,"aria-label":`Select agent ${n.name}`,children:[e.jsxs("div",{className:"live-agent-card-header",children:[e.jsxs("div",{className:"live-agent-card-name",children:[e.jsx("span",{className:`status-dot ${n.state==="running"?"status-dot--pending":"status-dot--online"}`,"aria-hidden":"true"}),e.jsx("span",{children:n.name})]}),n.taskId&&e.jsx("span",{className:"live-agent-task badge",children:n.taskId})]}),e.jsx("div",{className:"live-agent-card-transcript",children:d.length===0?e.jsx("div",{className:"live-agent-card-empty",children:n.taskId?k?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"live-agent-card-status",children:["Step ",C,E?`/${E}`:"",": ",k.name]}),w&&e.jsx("div",{className:"live-agent-card-status-sub",children:w}),e.jsx("div",{className:"live-agent-card-status-sub",children:g?"Waiting for output...":"Connecting to log stream..."})]}):e.jsx("span",{children:g?"Waiting for output...":"Connecting..."}):e.jsx("span",{children:n.state==="running"?"Starting...":"Idle — no task assigned"})}):d.slice(0,20).map((S,_)=>e.jsx("div",{className:"live-agent-card-line",children:S.text},_))}),e.jsxs("div",{className:"live-agent-card-footer",children:[e.jsxs("div",{className:"live-agent-card-footer-meta",children:[e.jsx("span",{className:"text-secondary",title:"Time since last heartbeat",children:ct(b)}),N&&e.jsx("span",{className:"live-agent-card-next-heartbeat",title:N,children:N})]}),e.jsxs("div",{className:"live-agent-card-footer-actions",children:[n.taskId&&u&&e.jsxs("button",{type:"button",className:"live-agent-card-logs-btn",onClick:T,title:"View live run logs","aria-label":`View live logs for ${n.taskId}`,children:[e.jsx(pt,{size:12}),e.jsx("span",{children:"Live logs"})]}),g&&e.jsx(De,{size:12,className:"live-agent-streaming-dot"})]})]})]})}function ct(n){return n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m ${n%60}s`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`}function qs({agents:n,projectId:i,onAgentSelect:f,onOpenTaskLogs:u,className:d=""}){const g=Array.from(new Map(n.map(o=>[o.id,o])).values());return g.length===0?null:e.jsxs("div",{className:`active-agents-panel ${d}`.trim(),children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(De,{size:16}),e.jsxs("span",{children:["Active Agents (",g.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:g.map(o=>e.jsx(Zs,{agent:o,projectId:i,onSelect:f,onOpenTaskLogs:u},o.id))})]})}function Js({stats:n,activeAgents:i,projectId:f,isOpen:u,onToggle:d,onSelectAgent:g,onOpenTaskLogs:o}){return e.jsxs("section",{className:"agents-overview-bar","aria-label":"Agents overview",children:[e.jsxs("button",{type:"button",className:"agents-overview-bar__toggle","aria-expanded":u,onClick:d,children:[e.jsxs("span",{className:"agents-overview-bar__title-wrap",children:[u?e.jsx(Jt,{size:16,"aria-hidden":"true"}):e.jsx(Ft,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"agents-overview-bar__title",children:"Overview"})]}),e.jsxs("span",{className:"agents-overview-bar__meta text-secondary",children:[i.filter(c=>c.state==="active").length," active · ",i.filter(c=>c.state==="running").length," running"]})]}),u?e.jsxs("div",{className:"agents-overview-bar__content",children:[e.jsx(Us,{stats:n,className:"agents-overview-bar__metrics"}),e.jsx(qs,{agents:i,projectId:f,onAgentSelect:g,onOpenTaskLogs:o,className:"agents-overview-bar__active-panel"})]}):null]})}function dt({title:n="No agents found",description:i="Create an agent to get started",ctaLabel:f="Create Agent",onCtaClick:u}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(xt,{size:48,opacity:.3,className:"agent-empty-state__icon"}),e.jsx("p",{className:"agent-empty-state__title",children:n}),e.jsx("p",{className:"agent-empty-state__description text-secondary",children:i}),u?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:u,children:f}):null]})}const _t=3,ut=1e3;function Qs({isOpen:n,onClose:i,onGenerated:f,projectId:u}){Pt(n);const[d,g]=a.useState(""),[o,c]=a.useState({type:"input"}),[b,N]=a.useState(null),[k,E]=a.useState(!1),C=a.useRef(null),w=a.useRef(null);a.useEffect(()=>{n&&o.type==="input"&&w.current?.focus()},[n,o.type]),a.useEffect(()=>{if(!n&&C.current){const p=C.current;C.current=null,nt(p,u).catch(()=>{})}},[n,u]),a.useEffect(()=>{if(!n)return;const p=I=>{I.key==="Escape"&&P()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[n]);const P=a.useCallback(()=>{if(C.current){const p=C.current;C.current=null,nt(p,u).catch(()=>{})}g(""),c({type:"input"}),N(null),E(!1),i()},[i,u]),T=a.useCallback(async()=>{if(!(!d.trim()||d.trim().length<_t)){N(null),c({type:"loading"});try{const{sessionId:p}=await Qt(d.trim(),u);C.current=p;const{spec:I}=await Xt(p,u);c({type:"preview",spec:I,sessionId:p})}catch(p){const I=p instanceof Error?p.message:"Failed to generate agent specification";I.includes("429")||I.toLowerCase().includes("rate limit")?N("Too many requests. Please wait a moment and try again."):N(I),c({type:"input"}),C.current=null}}},[d,u]),M=a.useCallback(async()=>{if(C.current){const p=C.current;C.current=null;try{await nt(p,u)}catch{}}await T()},[T,u]),S=a.useCallback(()=>{o.type==="preview"&&(C.current=null,f(o.spec),g(""),c({type:"input"}),N(null),E(!1),i())},[o,f,i]);if(!n)return null;const _=d.trim().length>=_t&&d.trim().length<=ut;return e.jsx("div",{className:"agent-dialog-overlay",onClick:p=>{p.target===p.currentTarget&&P()},children:e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Generate agent with AI",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsxs("span",{className:"agent-dialog-header-title",children:[e.jsx("span",{className:"agent-dialog-header-sparkle",children:"✨"}),"Generate Agent"]}),e.jsx("button",{className:"modal-close",onClick:P,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[b&&e.jsx("div",{className:"agent-dialog-error-banner",children:b}),o.type==="input"&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Describe your agent's role and the AI will generate a complete specification including system prompt, suggested configuration, and more."}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-role-description",children:"Role Description"}),e.jsx("textarea",{ref:w,id:"agent-role-description",className:"input agent-dialog-textarea",rows:4,placeholder:'e.g. "Senior frontend code reviewer who specializes in React accessibility"',value:d,onChange:p=>g(p.target.value),onKeyDown:p=>{p.key==="Enter"&&!p.shiftKey&&_&&(p.preventDefault(),T())},maxLength:ut,"aria-describedby":"role-description-hint"}),e.jsxs("div",{id:"role-description-hint",className:"agent-dialog-hint",children:[e.jsx("span",{children:"Describe what your agent should do"}),e.jsxs("span",{children:[d.length,"/",ut]})]})]})]}),o.type==="loading"&&e.jsxs("div",{className:"agent-dialog-loading-center",children:[e.jsx("div",{className:"agent-dialog-spinner spin"}),e.jsx("p",{className:"agent-dialog-loading-text",children:"Generating agent specification..."})]}),o.type==="preview"&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-summary agent-dialog-summary--spaced",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Title"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[o.spec.icon," ",o.spec.title]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Role"}),e.jsx("span",{children:o.spec.role})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Description"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--body",children:o.spec.description})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--capitalize",children:o.spec.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Max Turns"}),e.jsx("span",{children:o.spec.maxTurns})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{children:["System Prompt",e.jsx("button",{type:"button",className:"agent-dialog-expand-btn",onClick:()=>E(!k),children:k?"Collapse":"Expand"})]}),e.jsxs("div",{className:`agent-generation-prompt-box${k?"":" agent-generation-prompt-box--collapsed"}`,children:[o.spec.systemPrompt,!k&&o.spec.systemPrompt.length>500&&e.jsx("div",{className:"agent-generation-prompt-fade"})]})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[e.jsx("button",{className:"btn",onClick:P,children:"Cancel"}),o.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void T(),disabled:!_,children:"Generate"}),o.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void M(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:S,children:"Use This"})]})]})]})})}const $t=[{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:"✦"}],Lt=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Xs({isOpen:n,onClose:i,onCreated:f,projectId:u,prefillDraft:d=null,agentOnboardingEnabled:g=!1,existingAgents:o=[],onPrefillDraft:c}){const[b,N]=a.useState(0),[k,E]=a.useState("presets"),[C,w]=a.useState(""),[P,T]=a.useState(""),[M,S]=a.useState(""),[_,p]=a.useState("custom"),[I,$]=a.useState(""),[ee,Ne]=a.useState(""),[oe,te]=a.useState(""),[le,ce]=a.useState(""),[z,y]=a.useState(""),[xe,be]=a.useState(""),[A,se]=a.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[de,ye]=a.useState(null),[ae,V]=a.useState([]),[ue,G]=a.useState(!1),[U,J]=a.useState(null),[ve,ie]=a.useState(!1),[W,Q]=a.useState(!1),[Ee,Me]=a.useState([]),[_e,ke]=a.useState(!1),[me,we]=a.useState([]),[X,$e]=a.useState([]),[H,F]=a.useState("model"),[re,K]=a.useState(""),[Ce,Y]=a.useState([]),[Se,Ae]=a.useState(!1),[l,x]=a.useState([]),[R,Z]=a.useState(!1);a.useEffect(()=>{n&&(ke(!0),Yt().then(s=>{Me(s.models),we(s.favoriteProviders),$e(s.favoriteModels)}).catch(()=>{}).finally(()=>ke(!1)))},[n]),a.useEffect(()=>{n&&(Z(!0),x([]),es(void 0,u).then(s=>{x(s)}).catch(()=>{x([])}).finally(()=>Z(!1)))},[n,u]),a.useEffect(()=>{if(!n)return;const s=ss;if(typeof s!="function"){Y([]),Ae(!1);return}Ae(!0),Y([]),s(u).then(v=>{Y(v)}).catch(()=>{Y([])}).finally(()=>Ae(!1))},[n,u]);const L=A.model.includes("/")?A.model:"",D=a.useCallback(s=>{const v=Lt.has(s.role)?s.role:"custom";w(s.title),T(s.description),S(s.icon),p(v),te(s.systemPrompt),se(he=>({...he,thinkingLevel:s.thinkingLevel,maxTurns:s.maxTurns})),ie(!1),N(1)},[]),Te=a.useCallback(s=>{se(v=>({...v,model:s}))},[]),Le=a.useCallback(s=>{F(s),s==="model"&&K("")},[]),Fe=a.useCallback(async s=>{const v=me,ne=v.includes(s)?v.filter(Re=>Re!==s):[s,...v];we(ne);try{await wt({favoriteProviders:ne,favoriteModels:X})}catch{we(v)}},[me,X]),Ie=a.useCallback(async s=>{const v=X,ne=v.includes(s)?v.filter(Re=>Re!==s):[s,...v];$e(ne);try{await wt({favoriteProviders:me,favoriteModels:ne})}catch{$e(v)}},[me,X]),Ye=a.useCallback(s=>{ye(s.id),w(s.name),S(s.icon),T(s.description??s.title),p(s.role),y(s.soul??""),te(s.instructionsText??""),N(1)},[]),je=a.useCallback(s=>{const v=s.runtimeHint?.trim()??"",he=s.model?.trim()||s.modelHint?.trim()||"";N(1),E("custom"),w(s.name??""),T(s.title??""),S(s.icon??""),p(Lt.has(s.role)?s.role:"custom"),$(s.reportsTo??""),te(s.instructionsText??""),ce(s.heartbeatProcedurePath??""),y(s.soul??""),be(s.memory??""),V(Array.isArray(s.skills)?s.skills:[]),se(ne=>({...ne,model:v?"":he,thinkingLevel:s.thinkingLevel??ne.thinkingLevel,maxTurns:s.maxTurns??ne.maxTurns})),v?(F("runtime"),K(v)):(F("model"),K(""))},[]);if(a.useEffect(()=>{!n||!d||je(d)},[n,d,je]),!n)return null;const ge=()=>{N(0),E("presets"),w(""),T(""),S(""),p("custom"),$(""),Ne(""),te(""),ce(""),y(""),be(""),se({model:"",thinkingLevel:"off",maxTurns:1e3}),F("model"),K(""),ye(null),V([]),J(null),ie(!1),Q(!1),i()},et=async()=>{if(C.trim()){G(!0),J(null);try{const s={};H==="runtime"?re.trim()&&(s.runtimeHint=re.trim()):A.model.trim()&&(s.model=A.model.trim()),A.thinkingLevel!=="off"&&(s.thinkingLevel=A.thinkingLevel),A.maxTurns!==1e3&&(s.maxTurns=A.maxTurns),await ns({name:C.trim(),role:_,...P.trim()?{title:P.trim()}:{},...M.trim()?{icon:M.trim()}:{},...I.trim()?{reportsTo:I.trim()}:{},...ee.trim()?{instructionsPath:ee.trim()}:{},...oe.trim()?{instructionsText:oe.trim()}:{},...le.trim()?{heartbeatProcedurePath:le.trim()}:{},...z.trim()?{soul:z.trim()}:{},...xe.trim()?{memory:xe.trim()}:{},...Object.keys(s).length>0?{runtimeConfig:s}:{},...ae.length>0?{metadata:{skills:ae}}:{}},u),ge(),f()}catch(s){J(s instanceof Error?s.message:"Failed to create agent")}finally{G(!1)}}},Ve=$t.find(s=>s.value===_),Pe=I.trim(),He=Pe?l.find(s=>s.id===Pe):void 0,Oe=re?Ce.find(s=>s.runtimeId===re):void 0,Ue=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:s,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":s,children:[e.jsxs("label",{className:`agent-runtime-mode-option${H==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"model",checked:H==="model",onChange:()=>Le("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${H==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"runtime",checked:H==="runtime",onChange:()=>Le("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),H==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),_e?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(as,{id:"agent-model",label:"Model",value:L,onChange:Te,models:Ee,placeholder:"Select a model…",favoriteProviders:me,onToggleFavorite:Fe,favoriteModels:X,onToggleModelFavorite:Ie})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),Se?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:re,onChange:v=>K(v.target.value),children:[e.jsx("option",{value:"",children:Ce.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),Ce.map(v=>e.jsx("option",{value:v.runtimeId,children:v.description?`${v.name} — ${v.description}`:v.name},`${v.pluginId}:${v.runtimeId}`))]})]})]});return Rs.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:s=>{s.target===s.currentTarget&&ge()},children:[e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Create new agent",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"New Agent"}),e.jsx("button",{className:"btn-icon",onClick:ge,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(s=>e.jsx("div",{className:`agent-dialog-step${s===b?" active":s<b?" completed":""}`,"aria-label":`Step ${s+1}`},s))}),e.jsxs("div",{className:"agent-dialog-body",children:[b===0&&e.jsxs("div",{children:[g&&e.jsx("div",{className:"agent-dialog-step-zero-actions",children:e.jsx("button",{type:"button",className:"btn agent-dialog-interview-btn",onClick:()=>Q(!0),children:"AI Interview"})}),e.jsxs("div",{className:"agent-dialog-tabs",role:"tablist","aria-label":"Agent setup mode",children:[e.jsx("button",{id:"agent-dialog-tab-presets",type:"button",role:"tab","aria-controls":"agent-dialog-panel-presets","aria-selected":k==="presets",tabIndex:k==="presets"?0:-1,className:`agent-dialog-tab${k==="presets"?" active":""}`,onClick:()=>E("presets"),"data-testid":"agent-dialog-tab-presets",children:"Preset personas"}),e.jsx("button",{id:"agent-dialog-tab-custom",type:"button",role:"tab","aria-controls":"agent-dialog-panel-custom","aria-selected":k==="custom",tabIndex:k==="custom"?0:-1,className:`agent-dialog-tab${k==="custom"?" active":""}`,onClick:()=>E("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),k==="presets"&&e.jsx("div",{id:"agent-dialog-panel-presets",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-presets",children:e.jsxs("div",{className:"agent-presets",children:[e.jsx("div",{className:"agent-presets-header",children:"Choose a preset persona to prefill role, identity, soul, and instructions"}),e.jsx("div",{className:"agent-presets-grid",children:Es.map(s=>e.jsxs("button",{type:"button",className:`agent-preset-card${de===s.id?" selected":""}`,"data-testid":`preset-${s.id}`,onClick:()=>Ye(s),title:s.title,children:[e.jsx("span",{className:"agent-preset-icon",children:e.jsx(Qe,{agent:{id:s.id,icon:s.icon,name:s.name},size:28})}),e.jsx("span",{className:"agent-preset-name",children:s.name}),e.jsx("span",{className:"agent-preset-role",children:s.role}),s.description&&e.jsx("span",{className:"agent-preset-description",children:s.description})]},s.id))})]})}),k==="custom"&&e.jsxs("div",{id:"agent-dialog-panel-custom",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-custom",children:[e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Identity"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-name",children:["Name ",!de&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:C,onChange:s=>w(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field agent-dialog-field--title",children:[e.jsxs("label",{htmlFor:"agent-title",children:["Title ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:P,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-icon",children:["Icon ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:M,onChange:s=>S(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:$t.map(s=>e.jsxs("button",{type:"button",className:`agent-role-option${_===s.value?" selected":""}`,onClick:()=>p(s.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:s.icon}),e.jsx("span",{className:"agent-role-option-label",children:s.label})]},s.value))})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Configuration"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-reports-to",children:["Reports To ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:I,onChange:s=>$(s.target.value),disabled:R,children:[e.jsx("option",{value:"",children:"No manager"}),l.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.id,")"]},s.id))]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-soul",children:["Soul ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:z,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-memory",children:["Agent Memory ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-memory",className:"input",rows:2,placeholder:"Private to this agent — durable preferences, operating habits, and context it should carry across tasks...",value:xe,onChange:s=>be(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-path",children:["Instructions Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:ee,onChange:s=>Ne(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-heartbeat-procedure-path",children:["Heartbeat Procedure Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-heartbeat-procedure-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/ceo-agent2736/HEARTBEAT.md",value:le,onChange:s=>ce(s.target.value)}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-field-hint",children:"Path to the agent's heartbeat procedure path, typically .fusion/agents/ceo-agent2736/HEARTBEAT.md. Legacy id-only default paths still work."})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-text",children:["Inline Instructions ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:oe,onChange:s=>te(s.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),Ue("agent-runtime-source-step-0")]}),e.jsxs("div",{className:"agent-dialog-ai-generate",children:[e.jsxs("button",{type:"button",className:"btn btn--ai-generate",onClick:()=>ie(!0),children:[e.jsx("span",{children:"✨"}),"Generate with AI"]}),e.jsx("p",{className:"agent-dialog-ai-hint",children:"Describe your agent's role and let AI generate a specification"})]})]})]}),b===1&&e.jsxs("div",{children:[Ue("agent-runtime-source-step-1"),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-thinking",children:"Thinking Level"}),e.jsxs("select",{id:"agent-thinking",className:"select",value:A.thinkingLevel,onChange:s=>se(v=>({...v,thinkingLevel:s.target.value})),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"minimal",children:"Minimal"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-max-turns",children:"Max Turns"}),e.jsx("input",{id:"agent-max-turns",type:"number",className:"input",min:1,max:2e3,value:A.maxTurns,onChange:s=>se(v=>({...v,maxTurns:Math.max(1,parseInt(s.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(Ms,{id:"agent-skills",label:"Skills",value:ae,onChange:V,projectId:u}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),b===2&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Review your agent configuration before creating."}),e.jsxs("div",{className:"agent-dialog-summary",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Name"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[M&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:M}),C]})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable agent-dialog-summary-row--title",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-title",children:"Title"}),e.jsx("input",{id:"agent-review-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:P,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Role"}),e.jsxs("span",{children:[Ve?.icon," ",Ve?.label]})]}),Pe&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Reports To"}),e.jsx("span",{children:He?`${He.name} (${He.id})`:Pe})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-soul",children:"Soul"}),e.jsx("textarea",{id:"agent-review-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:z,onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-heartbeat-procedure-path",children:"Heartbeat Procedure Path"}),e.jsx("input",{id:"agent-review-heartbeat-procedure-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/ceo-agent2736/HEARTBEAT.md",value:le,onChange:s=>ce(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-instructions-path",children:"Instructions Path"}),e.jsx("input",{id:"agent-review-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:ee,onChange:s=>Ne(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-instructions-text",children:"Inline Instructions"}),e.jsx("textarea",{id:"agent-review-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:oe,onChange:s=>te(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:H==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:H==="runtime"?Oe?Oe.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):L?e.jsxs(e.Fragment,{children:[e.jsx(ts,{provider:L.split("/")[0],size:"sm"})," ",(()=>{const s=L.indexOf("/"),v=L.slice(0,s),he=L.slice(s+1);return Ee.find(Re=>Re.provider===v&&Re.id===he)?.name||L})()]}):e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"default"})})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value--capitalize",children:A.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Max Turns"}),e.jsx("span",{children:A.maxTurns})]}),ae.length>0&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Skills"}),e.jsxs("span",{children:[ae.length," skill",ae.length!==1?"s":""," selected"]})]})]}),U&&e.jsx("p",{className:"agent-dialog-error",children:U})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[b>0&&e.jsx("button",{className:"btn",onClick:()=>N(s=>s-1),disabled:ue,children:"Back"}),e.jsx("button",{className:"btn",onClick:ge,disabled:ue,children:"Cancel"}),b<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>N(s=>s+1),disabled:b===0&&!C.trim()&&!de,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void et(),disabled:ue||!C.trim(),children:ue?"Creating...":"Create"})]})]}),e.jsx(Qs,{isOpen:ve,onClose:()=>ie(!1),onGenerated:D,projectId:u}),e.jsx(_s,{isOpen:W,onClose:()=>Q(!1),onUseDraft:s=>{c?.(s),c||je(s),Q(!1)},projectId:u,existingAgents:o,mode:"create"})]}),document.body)}function Ys(n){const i=n.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!i)throw new Error("Missing YAML frontmatter delimiters (---)");const f=i[1].split(/\r?\n/),u=i[2]??"",d={name:""},g=[];let o=!1;for(const c of f){const N=c.trimEnd().trim();if(!N)continue;if(N.startsWith("skills:")){o=!0;continue}if(o&&N.startsWith("- ")){g.push(N.slice(2).trim());continue}o=!1;const[k,...E]=N.split(":"),w=E.join(":").trim().replace(/^['"]|['"]$/g,"");k==="name"&&(d.name=w),k==="title"&&(d.title=w),k==="icon"&&(d.icon=w),k==="role"&&(d.role=w),k==="reportsTo"&&(d.reportsTo=w)}if(!d.name)throw new Error("Missing required field: name");return g.length>0&&(d.skills=g),u.trim().length>0&&(d.instructionBody=u),d}function ea({isOpen:n,onClose:i,onImported:f,projectId:u,initialInputMethod:d="paste"}){Pt(n);const[g,o]=a.useState("input"),[c,b]=a.useState(d),[N,k]=a.useState(""),[E,C]=a.useState([]),[w,P]=a.useState("Unknown"),[T,M]=a.useState([]),[S,_]=a.useState([]),[p,I]=a.useState([]),[$,ee]=a.useState([]),[Ne,oe]=a.useState(!1),[te,le]=a.useState(!1),[ce,z]=a.useState(null),[y,xe]=a.useState(null),[be,A]=a.useState(null),se=a.useRef(null),de=a.useRef(null),[ye,ae]=a.useState([]),[V,ue]=a.useState(""),[G,U]=a.useState(null),[J,ve]=a.useState(!1),[ie,W]=a.useState(null),Q=a.useRef(!1);a.useEffect(()=>{c==="browse"&&!Q.current&&!J&&(Q.current=!0,ve(!0),W(null),Ct().then(l=>{l.error?W(l.error):l.companies.length>0?ae(l.companies):W("No companies available")}).catch(l=>{W(l instanceof Error?l.message:"Failed to load companies")}).finally(()=>{ve(!1)}))},[c,J]);const Ee=a.useCallback(()=>{Q.current=!0,W(null),ae([]),U(null),ve(!0),Ct().then(l=>{l.error?W(l.error):l.companies.length>0?ae(l.companies):W("No companies available")}).catch(l=>{W(l instanceof Error?l.message:"Failed to load companies")}).finally(()=>{ve(!1)})},[]),Me=a.useCallback(()=>{o("input"),b(d),k(""),C([]),P("Unknown"),M([]),_([]),I([]),ee([]),oe(!1),le(!1),z(null),xe(null),A(null),ae([]),ue(""),U(null),ve(!1),W(null),Q.current=!1},[d]),_e=a.useCallback(()=>{Me(),i()},[Me,i]),ke=a.useCallback(l=>{const x=l.target.files?.[0];if(!x)return;const R=new FileReader;R.onload=Z=>{const L=Z.target?.result;b("file"),C([]),k(L),z(null)},R.onerror=()=>{z("Failed to read file")},R.readAsText(x),l.target.value=""},[]),me=a.useCallback(async l=>{const x=Array.from(l.target.files??[]);if(x.length!==0)try{const R=x.filter(L=>(L.webkitRelativePath||L.name).toLowerCase().endsWith("agents.md")).sort((L,D)=>{const Te=L.webkitRelativePath||L.name,Le=D.webkitRelativePath||D.name;return Te.localeCompare(Le)});if(R.length===0){z("Selected directory has no AGENTS.md files");return}const Z=[];for(const L of R){const D=await L.text();Z.push(Ys(D))}b("directory"),C(Z),k(""),z(null)}catch{z("Failed to parse AGENTS.md files from selected directory")}finally{l.target.value=""}},[]);function we(l){if(!u)return`/api${l}`;const x=l.includes("?")?"&":"?";return`/api${l}${x}projectId=${encodeURIComponent(u)}`}const X=a.useCallback(async()=>{if(c==="directory"&&E.length===0){z("Please select a directory containing AGENTS.md files");return}if(c==="browse"&&!G){z("Please select a company from the catalog");return}if(c!=="directory"&&c!=="browse"&&!N.trim()){z("Please provide manifest content");return}oe(!0),z(null);try{let l;c==="directory"?l={agents:E,dryRun:!0}:c==="browse"&&G?l={importSource:"companies.sh",companySlug:G.slug,dryRun:!0}:l={manifest:N,dryRun:!0};const x=await fetch(we("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!x.ok){const D=await x.json();throw new Error(D.error??`Parse failed (${x.status})`)}const R=await x.json(),Z=R.agents&&R.agents.length>0?R.agents:R.created.map(D=>({name:D,role:"custom"})),L=Array.isArray(R.skills)?R.skills:[];P(R.companyName??"Unknown"),M(Z),_(L),I(Z.map(D=>D.name)),ee(L.map(D=>D.name)),o("preview")}catch(l){z(l instanceof Error?l.message:"Failed to parse manifest")}finally{oe(!1)}},[c,E,N,G,u]),$e=a.useCallback(async()=>{le(!0),A(null);try{let l;c==="directory"?l={agents:E,skipExisting:!0,selectedAgents:p,selectedSkills:$}:c==="browse"&&G?l={importSource:"companies.sh",companySlug:G.slug,skipExisting:!0,selectedAgents:p,selectedSkills:$}:l={manifest:N,skipExisting:!0,selectedAgents:p,selectedSkills:$};const x=await fetch(we("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)});if(!x.ok){const Z=await x.json();throw new Error(Z.error??`Import failed (${x.status})`)}const R=await x.json();xe(R),o("result"),f()}catch(l){A(l instanceof Error?l.message:"Failed to import agents")}finally{le(!1)}},[c,E,N,G,p,$,u,f]),H=p.length,F=$.length,re=`${H} Agent${H!==1?"s":""}`,K=`${F} Skill${F!==1?"s":""}`,Ce=H>0&&F>0?`${re} + ${K}`:F>0?K:re,Y=H>0&&F>0?`Importing ${H} agent${H!==1?"s":""} and ${F} skill${F!==1?"s":""}...`:F>0?`Importing ${F} skill${F!==1?"s":""}...`:`Importing ${H} agent${H!==1?"s":""}...`,Se=l=>{I(x=>x.includes(l)?x.filter(R=>R!==l):[...x,l])},Ae=l=>{ee(x=>x.includes(l)?x.filter(R=>R!==l):[...x,l])};return n?e.jsx("div",{className:"agent-dialog-overlay",onClick:l=>{l.target===l.currentTarget&&_e()},children:e.jsxs("div",{className:"agent-dialog agent-import-dialog",role:"dialog","aria-modal":"true","aria-label":"Import agents",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"Import Agents"}),e.jsx("button",{className:"modal-close",onClick:_e,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[g==="input"&&e.jsxs("div",{className:"agent-import-input",children:[e.jsx("p",{className:"agent-import-description",children:"Import agents from an Agent Companies package. Browse the companies.sh catalog to discover published agents, upload an AGENTS.md file, select a directory, or paste manifest content."}),e.jsxs("div",{className:"agent-import-file-upload",children:[e.jsx("input",{ref:se,type:"file",accept:".md,.txt",onChange:ke,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:de,type:"file",webkitdirectory:"",multiple:!0,onChange:me,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>se.current?.click(),children:[e.jsx(zt,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>de.current?.click(),children:[e.jsx(Ls,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{b("browse"),C([]),k(""),U(null),z(null)},children:[e.jsx(ls,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),c==="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(is,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:V,onChange:l=>ue(l.target.value),"aria-label":"Search companies"})]}),G&&e.jsxs("div",{className:"agent-import-browse-selected",children:[e.jsx("span",{className:"agent-import-browse-selected-label",children:"Selected:"}),e.jsx("span",{className:"agent-import-browse-selected-name",children:G.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>U(null),children:"Change"})]})]}),J&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(lt,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),ie&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(it,{size:16}),e.jsx("span",{children:ie}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:Ee,children:[e.jsx(Ge,{size:14}),"Retry"]})]}),!J&&!ie&&e.jsxs("div",{className:"agent-import-browse-list",children:[ye.filter(l=>V===""||l.name.toLowerCase().includes(V.toLowerCase())||(l.tagline?.toLowerCase().includes(V.toLowerCase())??!1)).map(l=>e.jsxs("div",{className:`agent-import-browse-item ${G?.slug===l.slug?"agent-import-browse-item--selected":""}`,onClick:()=>U(l),role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&U(l)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:l.name}),l.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[l.installs.toLocaleString()," installs"]})]}),l.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:l.tagline}),l.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:l.repo})]},l.slug)),ye.filter(l=>V===""||l.name.toLowerCase().includes(V.toLowerCase())||(l.tagline?.toLowerCase().includes(V.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:V?"No companies match your search":"No companies available"})]})]}),c!=="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:`---
|
|
23
23
|
name: CEO
|
|
24
24
|
title: Chief Executive Officer
|
|
25
25
|
reportsTo: null
|
|
26
26
|
skills:
|
|
27
27
|
- review
|
|
28
28
|
---
|
|
29
|
-
Agent instructions go here...`,value:N,onChange:l=>{v("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: ",c]}),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:()=>I(T.map(l=>l.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>I([]),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}`))})]}),ve&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(it,{size:14}),ve]})]}),g==="result"&&y&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(qe,{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(qe,{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(St,{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(qe,{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(St,{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:()=>o("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||(c==="directory"?E.length===0:c==="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 Dt=220,ta=24,sa=24,aa=16;function Ht(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Ht(f),0)}function na(n){const i=Ht(n);return i*Dt+Math.max(0,i-1)*ta}function la(n){if(n.length===0)return Dt;const f=n.map(na).reduce((d,g)=>d+g,0),u=Math.max(0,n.length-1)*sa;return f+u+aa*2}function ia(n){const i=Number.isFinite(n.availableWidth)&&n.availableWidth>0?n.availableWidth:0;return i===0||n.tree.length<=1?"horizontal":la(n.tree)>i?"vertical":"horizontal"}const It=a.lazy(()=>ks(()=>import("./AgentDetailView-ZbHEbYRT.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(n=>({default:n.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:"✦"}],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 bt(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 Je(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Je(f),0)}function jt(n,i){return n.state==="error"?{title:void 0,label:"Error"}:{title:i.reason??i.label,label:i.stateDerived?null:i.label}}function Ot({node:n,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d}){const{agent:g,children:o}=n,c=f(g),v=jt(g,c),N=vt(g.state),k=bt("org-chart-node-card",g.state),E=Je(n),C={"--org-chart-subtree-leaves":String(E)},w=o.length>0?Je(o[0]):1,P=o.length>0?Je(o[o.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${o.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:M=>{(M.key==="Enter"||M.key===" ")&&(M.key===" "&&M.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(Qe,{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:c.color},title:v.title,children:[c.icon,v.label&&e.jsx("span",{className:"text-secondary",children:v.label})]})]})]}),o.length>0&&e.jsx("div",{className:"org-chart-children",style:T,role:"group","aria-label":`${g.name} employees`,children:o.map(M=>e.jsx(Ot,{node:M,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d},M.agent.id))})]})}function ga({addToast:n,projectId:i,onOpenTaskLogs:f,agentOnboardingEnabled:u=!1}){const[d,g]=a.useState(!1),c=rs()==="mobile",[v,N]=a.useState("all"),{agents:k,stats:E,isLoading:C,loadAgents:w,refreshAgents:P}=os(i,{filterState:v,showSystemAgents:d}),[T,M]=a.useState(!1),[S,_]=a.useState(null),[p,I]=a.useState(!1),[$,ee]=a.useState(null),[Ne,oe]=a.useState(null),te=c&&!!$,[le,ce]=a.useState("dashboard"),[z,y]=a.useState(null),[xe,ve]=a.useState(!1),[A,se]=a.useState(()=>{if(typeof window>"u")return"list";const t=At("fn-agent-view",i);return t==="list"||t==="board"||t==="org"?t:"list"}),[de,ye]=a.useState([]),[ae,V]=a.useState(!1),[ue,G]=a.useState(0),[U,J]=a.useState(!1),[be,ie]=a.useState(!1),[W,Q]=a.useState(1),Ee=a.useRef(null),Me=a.useRef(null),{confirm:_e}=cs(),ke=a.useRef(null),me=a.useId();a.useEffect(()=>{const t=At("fn-agent-view",i);if(t==="list"||t==="board"||t==="org"){se(t);return}se("list")},[i]),a.useEffect(()=>{ds("fn-agent-view",A,i)},[A,i]);const[we,X]=a.useState(null),$e=a.useRef(null),[H,F]=a.useState(null),[re,K]=a.useState(null),[Ce,Y]=a.useState({}),[Se,Ae]=a.useState(1),[l,x]=a.useState(!1),[R,Z]=a.useState(new Set),[L,D]=a.useState(new Map),Te=a.useRef(!0);a.useEffect(()=>(Te.current=!0,()=>{Te.current=!1}),[]),a.useEffect(()=>{us(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 ms({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(()=>L.size===0?k:k.map(t=>{const r=L.get(t.id);return r?{...t,state:r}:t}),[k,L]),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=Me.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 V(!0),gs(i,{includeEphemeral:d}).then(r=>{t||ye(r)}).catch(r=>{t||(n(`Failed to load org chart: ${fe(r)}`,"error"),ye([]))}).finally(()=>{t||V(!1)}),()=>{t=!0}},[A,i,d,n]),a.useEffect(()=>{const t=setInterval(()=>{w()},3e4);return()=>{clearInterval(t)}},[w]),a.useEffect(()=>{if(!U)return;const t=m=>{const j=m.target;j&&(Ee.current?.contains(j)||ke.current?.contains(j)||J(!1))},r=m=>{m.key==="Escape"&&(J(!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)}},[U]);const ge=async(t,r)=>{if(!R.has(t)){Z(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{Z(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")}},Ve=async(t,r)=>{const m=k.find(j=>j.id===t);if(m){if(m.role===r){X(null);return}try{await Ke(t,{role:r},i),n(`Agent role updated to ${Ze.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&&(K(null),Y(m=>{const j={...m};return delete j[t.id],j})),F(t.id);try{await Ke(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:r}},i),n(`Heartbeat interval updated to ${Rt(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 Ke(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"),K(null),Y(O=>{const q={...O};return delete q[t.id],q}),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 Ke(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:j}},i),n(`Heartbeat interval updated to ${Rt(j)} for ${t.name}`,"success"),K(null),Y(O=>{const q={...O};return delete q[t.id],q}),w()}catch(O){n(`Failed to update heartbeat interval: ${fe(O)}`,"error")}finally{F(null)}},Ue=t=>{const r=ht(t.runtimeConfig?.heartbeatIntervalMs),m=Math.round(r/6e4);K(t.id),Y(j=>({...j,[t.id]:String(m)}))},s=a.useCallback((t,r)=>{ee(t),ce(r?.initialTab??"dashboard"),y(r?.initialRunId??null),ve(r?.preferActiveRun??!1)},[]),b=a.useCallback(()=>{ee(null),ce("dashboard"),y(null),ve(!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&&b()},[P,$,b]),Bt=a.useCallback(t=>{s(t),c&&ie(!1)},[c,s]),Gt=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),c&&$&&b()},[b,c,$]),ft=t=>Ze.find(r=>r.value===t)?.label??t,Vt=t=>Ze.find(r=>r.value===t)?.icon??"◆",Nt=gt[W],yt=a.useMemo(()=>ia({tree:je,availableWidth:ue}),[je,ue]),Ut=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],st=t=>ws(t),kt=C&&k.length===0,We=a.useCallback(()=>{M(!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(hs,{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(ps,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:ke,className:`btn-icon agent-controls-trigger${U?" agent-controls-trigger--active":""}`,onClick:()=>J(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":U,"aria-controls":me,children:e.jsx(zs,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void w(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Ge,{size:16,className:C?"spin":void 0})}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>{I(!0),J(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(zt,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{We(),J(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(xs,{size:16}),"New Agent"]})]})]})]}),U&&e.jsxs("div",{ref:Ee,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(vs,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:v,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"]})]})}),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(Gs,{agents:Ie})]}),e.jsx(Xs,{isOpen:T,onClose:()=>{M(!1),_(null)},onCreated:()=>{M(!1),_(null),w()},projectId:i,prefillDraft:S,agentOnboardingEnabled:u,existingAgents:k,onPrefillDraft:_}),e.jsx(ea,{isOpen:p,onClose:()=>I(!1),onImported:()=>void w(),projectId:i}),e.jsx(Js,{stats:E,activeAgents:Ye,projectId:i,isOpen:be,onToggle:()=>ie(t=>!t),onSelectAgent:Bt,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:b,"aria-label":"Back to org chart",children:"Back to org chart"}),e.jsx(a.Suspense,{fallback:null,children:e.jsx(It,{inline:!0,showInlineBackButton:!1,agentId:$,projectId:i,onClose:b,addToast:n,onChildClick:he,initialTab:le,initialRunId:z,preferActiveRun:xe},$)})]}):kt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ge,{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:[c?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:W===0,"aria-label":"Zoom out org chart",title:"Zoom out",children:e.jsx(Bs,{size:16})}),e.jsxs("span",{className:"agent-org-chart-controls__zoom-label","aria-live":"polite",children:[Math.round(Nt*100),"%"]}),e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>Q(t=>Math.min(gt.length-1,t+1)),disabled:W===gt.length-1,"aria-label":"Zoom in org chart",title:"Zoom in",children:e.jsx(Hs,{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(bs,{size:16}),"Fit"]})]}):null,e.jsx("div",{ref:Me,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(Nt*100)}`,children:e.jsx("div",{className:`agent-org-chart${yt==="vertical"?" agent-org-chart--vertical":""}`,"data-testid":"agent-org-chart","data-layout-mode":yt,children:ae?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Ge,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):je.length===0?e.jsx(dt,{onCtaClick:We}):je.map(t=>e.jsx(Ot,{node:t,onSelect:ne,getHealthStatus:st,getRoleIcon:Vt,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:kt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ge,{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:We}):Ie.map(t=>{const r=st(t),m=jt(t,r),j=vt(t.state),O=bt("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:q=>{(q.key==="Enter"||q.key===" ")&&(q.key===" "&&q.preventDefault(),s(t.id))},children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:e.jsx(Qe,{agent:t,size:20})}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:ft(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:We}):Ie.map(t=>{const r=st(t),m=jt(t,r),j=vt(t.state),O=bt("agent-card",t.state),q=ht(t.runtimeConfig?.heartbeatIntervalMs),Wt=js(q),Be=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 Ve(t.id,h.target.value),onKeyDown:h=>Pe(h,t.id),onBlur:()=>X(null),autoFocus:!0,children:Ze.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(Qe,{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(Ft,{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:ft(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=Ut(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"&&(K(null),Y(B=>{const pe={...B};return delete pe[t.id],pe}))},disabled:Be,"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:Be,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>{K(null),Y(h=>{const B={...h};return delete B[t.id],B})},disabled:Be,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:q,onChange:h=>{const B=h.target.value;B==="__custom__"?Ue(t):He(t,Number(B))},disabled:Be,"aria-label":`Set heartbeat interval for ${t.name}`,children:[Wt.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value)),Ns.some(h=>h.value===q)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),Be&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const h=new Date(t.lastHeartbeatAt),B=new Date(h.getTime()+q),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:[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})," Start"]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>void Gt(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})," 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(Tt,{size:14})," 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})," 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})," Running"]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ge(t.id,"paused"),disabled:R.has(t.id),title:"Pause",children:[e.jsx(Tt,{size:14})," 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})," Retry"]}),e.jsx("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:"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})," Delete"]})]})]},t.id)})})})}),e.jsx("div",{className:`agents-split-detail${c&&!$?" agents-split-detail--hidden-mobile":""}`,children:$?e.jsx(a.Suspense,{fallback:null,children:e.jsx(It,{inline:!0,showInlineBackButton:c,agentId:$,projectId:i,onClose:b,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{ga as AgentsView};
|
|
29
|
+
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: ",c]}),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:()=>I(T.map(l=>l.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>I([]),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(qe,{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(qe,{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(St,{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(qe,{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(St,{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:()=>o("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||(c==="directory"?E.length===0:c==="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 Dt=220,ta=24,sa=24,aa=16;function Ht(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Ht(f),0)}function na(n){const i=Ht(n);return i*Dt+Math.max(0,i-1)*ta}function la(n){if(n.length===0)return Dt;const f=n.map(na).reduce((d,g)=>d+g,0),u=Math.max(0,n.length-1)*sa;return f+u+aa*2}function ia(n){const i=Number.isFinite(n.availableWidth)&&n.availableWidth>0?n.availableWidth:0;return i===0||n.tree.length<=1?"horizontal":la(n.tree)>i?"vertical":"horizontal"}const It=a.lazy(()=>ks(()=>import("./AgentDetailView-Cv-vgOj3.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).then(n=>({default:n.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:"✦"}],mt=[.1,.25,.5,1,2,3,5,10],gt=[.75,1,1.25,1.5];function bt(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 vt(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 Je(n){return n.children.length===0?1:n.children.reduce((i,f)=>i+Je(f),0)}function jt(n,i){return n.state==="error"?{title:void 0,label:"Error"}:{title:i.reason??i.label,label:i.stateDerived?null:i.label}}function Ot({node:n,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d}){const{agent:g,children:o}=n,c=f(g),b=jt(g,c),N=bt(g.state),k=vt("org-chart-node-card",g.state),E=Je(n),C={"--org-chart-subtree-leaves":String(E)},w=o.length>0?Je(o[0]):1,P=o.length>0?Je(o[o.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${o.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:M=>{(M.key==="Enter"||M.key===" ")&&(M.key===" "&&M.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(Qe,{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:c.color},title:b.title,children:[c.icon,b.label&&e.jsx("span",{className:"text-secondary",children:b.label})]})]})]}),o.length>0&&e.jsx("div",{className:"org-chart-children",style:T,role:"group","aria-label":`${g.name} employees`,children:o.map(M=>e.jsx(Ot,{node:M,onSelect:i,getHealthStatus:f,getRoleIcon:u,selectedAgentId:d},M.agent.id))})]})}function ga({addToast:n,projectId:i,onOpenTaskLogs:f,agentOnboardingEnabled:u=!1}){const[d,g]=a.useState(!1),c=rs()==="mobile",[b,N]=a.useState("all"),{agents:k,stats:E,isLoading:C,loadAgents:w,refreshAgents:P}=os(i,{filterState:b,showSystemAgents:d}),[T,M]=a.useState(!1),[S,_]=a.useState(null),[p,I]=a.useState(!1),[$,ee]=a.useState(null),[Ne,oe]=a.useState(null),te=c&&!!$,[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=At("fn-agent-view",i);return t==="list"||t==="board"||t==="org"?t:"list"}),[de,ye]=a.useState([]),[ae,V]=a.useState(!1),[ue,G]=a.useState(0),[U,J]=a.useState(!1),[ve,ie]=a.useState(!1),[W,Q]=a.useState(1),Ee=a.useRef(null),Me=a.useRef(null),{confirm:_e}=cs(),ke=a.useRef(null),me=a.useId();a.useEffect(()=>{const t=At("fn-agent-view",i);if(t==="list"||t==="board"||t==="org"){se(t);return}se("list")},[i]),a.useEffect(()=>{ds("fn-agent-view",A,i)},[A,i]);const[we,X]=a.useState(null),$e=a.useRef(null),[H,F]=a.useState(null),[re,K]=a.useState(null),[Ce,Y]=a.useState({}),[Se,Ae]=a.useState(1),[l,x]=a.useState(!1),[R,Z]=a.useState(new Set),[L,D]=a.useState(new Map),Te=a.useRef(!0);a.useEffect(()=>(Te.current=!0,()=>{Te.current=!1}),[]),a.useEffect(()=>{us(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 ms({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(()=>L.size===0?k:k.map(t=>{const r=L.get(t.id);return r?{...t,state:r}:t}),[k,L]),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=Me.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 V(!0),gs(i,{includeEphemeral:d}).then(r=>{t||ye(r)}).catch(r=>{t||(n(`Failed to load org chart: ${fe(r)}`,"error"),ye([]))}).finally(()=>{t||V(!1)}),()=>{t=!0}},[A,i,d,n]),a.useEffect(()=>{const t=setInterval(()=>{w()},3e4);return()=>{clearInterval(t)}},[w]),a.useEffect(()=>{if(!U)return;const t=m=>{const j=m.target;j&&(Ee.current?.contains(j)||ke.current?.contains(j)||J(!1))},r=m=>{m.key==="Escape"&&(J(!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)}},[U]);const ge=async(t,r)=>{if(!R.has(t)){Z(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{Z(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")}},Ve=async(t,r)=>{const m=k.find(j=>j.id===t);if(m){if(m.role===r){X(null);return}try{await Ke(t,{role:r},i),n(`Agent role updated to ${Ze.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&&(K(null),Y(m=>{const j={...m};return delete j[t.id],j})),F(t.id);try{await Ke(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:r}},i),n(`Heartbeat interval updated to ${Rt(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 Ke(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"),K(null),Y(O=>{const q={...O};return delete q[t.id],q}),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 Ke(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:j}},i),n(`Heartbeat interval updated to ${Rt(j)} for ${t.name}`,"success"),K(null),Y(O=>{const q={...O};return delete q[t.id],q}),w()}catch(O){n(`Failed to update heartbeat interval: ${fe(O)}`,"error")}finally{F(null)}},Ue=t=>{const r=ht(t.runtimeConfig?.heartbeatIntervalMs),m=Math.round(r/6e4);K(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]),Bt=a.useCallback(t=>{s(t),c&&ie(!1)},[c,s]),Gt=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),c&&$&&v()},[v,c,$]),ft=t=>Ze.find(r=>r.value===t)?.label??t,Vt=t=>Ze.find(r=>r.value===t)?.icon??"◆",Nt=gt[W],yt=a.useMemo(()=>ia({tree:je,availableWidth:ue}),[je,ue]),Ut=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],st=t=>ws(t),kt=C&&k.length===0,We=a.useCallback(()=>{M(!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(hs,{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(ps,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:ke,className:`btn-icon agent-controls-trigger${U?" agent-controls-trigger--active":""}`,onClick:()=>J(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":U,"aria-controls":me,children:e.jsx(zs,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void w(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Ge,{size:16,className:C?"spin":void 0})}),e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{I(!0),J(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(zt,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{We(),J(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(xs,{size:16}),"New Agent"]})]})]})]}),U&&e.jsxs("div",{ref:Ee,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"]})]})}),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(Gs,{agents:Ie})]}),e.jsx(Xs,{isOpen:T,onClose:()=>{M(!1),_(null)},onCreated:()=>{M(!1),_(null),w()},projectId:i,prefillDraft:S,agentOnboardingEnabled:u,existingAgents:k,onPrefillDraft:_}),e.jsx(ea,{isOpen:p,onClose:()=>I(!1),onImported:()=>void w(),projectId:i}),e.jsx(Js,{stats:E,activeAgents:Ye,projectId:i,isOpen:ve,onToggle:()=>ie(t=>!t),onSelectAgent:Bt,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(It,{inline:!0,showInlineBackButton:!1,agentId:$,projectId:i,onClose:v,addToast:n,onChildClick:he,initialTab:le,initialRunId:z,preferActiveRun:xe},$)})]}):kt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ge,{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:[c?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:W===0,"aria-label":"Zoom out org chart",title:"Zoom out",children:e.jsx(Bs,{size:16})}),e.jsxs("span",{className:"agent-org-chart-controls__zoom-label","aria-live":"polite",children:[Math.round(Nt*100),"%"]}),e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>Q(t=>Math.min(gt.length-1,t+1)),disabled:W===gt.length-1,"aria-label":"Zoom in org chart",title:"Zoom in",children:e.jsx(Hs,{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:Me,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(Nt*100)}`,children:e.jsx("div",{className:`agent-org-chart${yt==="vertical"?" agent-org-chart--vertical":""}`,"data-testid":"agent-org-chart","data-layout-mode":yt,children:ae?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Ge,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):je.length===0?e.jsx(dt,{onCtaClick:We}):je.map(t=>e.jsx(Ot,{node:t,onSelect:ne,getHealthStatus:st,getRoleIcon:Vt,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:kt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ge,{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:We}):Ie.map(t=>{const r=st(t),m=jt(t,r),j=bt(t.state),O=vt("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:q=>{(q.key==="Enter"||q.key===" ")&&(q.key===" "&&q.preventDefault(),s(t.id))},children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:e.jsx(Qe,{agent:t,size:20})}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:ft(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:We}):Ie.map(t=>{const r=st(t),m=jt(t,r),j=bt(t.state),O=vt("agent-card",t.state),q=ht(t.runtimeConfig?.heartbeatIntervalMs),Wt=js(q),Be=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 Ve(t.id,h.target.value),onKeyDown:h=>Pe(h,t.id),onBlur:()=>X(null),autoFocus:!0,children:Ze.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(Qe,{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(Ft,{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:ft(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=Ut(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"&&(K(null),Y(B=>{const pe={...B};return delete pe[t.id],pe}))},disabled:Be,"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:Be,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>{K(null),Y(h=>{const B={...h};return delete B[t.id],B})},disabled:Be,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:q,onChange:h=>{const B=h.target.value;B==="__custom__"?Ue(t):He(t,Number(B))},disabled:Be,"aria-label":`Set heartbeat interval for ${t.name}`,children:[Wt.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value)),Ns.some(h=>h.value===q)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),Be&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const h=new Date(t.lastHeartbeatAt),B=new Date(h.getTime()+q),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:[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 Gt(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(Tt,{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(Tt,{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.jsx("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("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${c&&!$?" agents-split-detail--hidden-mobile":""}`,children:$?e.jsx(a.Suspense,{fallback:null,children:e.jsx(It,{inline:!0,showInlineBackButton:c,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{ga as AgentsView};
|