@runfusion/fusion 0.33.0 → 0.35.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/dist/bin.js +1522 -996
- package/dist/client/.vite/manifest.json +63 -62
- package/dist/client/assets/{AgentDetailView-BACu9GYE.js → AgentDetailView-CFX3jxfA.js} +1 -1
- package/dist/client/assets/{AgentPermissionPolicyEditor-tNNlcCDk.js → AgentPermissionPolicyEditor-4tnYHS0-.js} +1 -1
- package/dist/client/assets/{AgentsView-CPpHwjn3.js → AgentsView-DnNWfwiY.js} +5 -5
- package/dist/client/assets/ChatView-rwl2O-s0.js +6 -0
- package/dist/client/assets/{DevServerView-BlxSS8Uu.js → DevServerView-C9fEzcFQ.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-ioTzF36r.js → DirectoryPicker-Cwyr0Sl4.js} +1 -1
- package/dist/client/assets/{DocumentsView-CsDb8dPw.js → DocumentsView-gDWTMU2w.js} +1 -1
- package/dist/client/assets/{EvalsView-I0GhxVhm.js → EvalsView-Cw7D1x0W.js} +1 -1
- package/dist/client/assets/{ExperimentalAgentOnboardingModal-Cr6g_jok.js → ExperimentalAgentOnboardingModal-8yeOcqbX.js} +1 -1
- package/dist/client/assets/{GoalsView-DXJxe6D4.js → GoalsView-kRIhgAA6.js} +1 -1
- package/dist/client/assets/{InsightsView-BaIhzpvX.js → InsightsView-IHHikd5n.js} +1 -1
- package/dist/client/assets/{MemoryView-DlmcI0ca.js → MemoryView-pii3HOba.js} +1 -1
- package/dist/client/assets/{NodesView-vc4T0uCy.js → NodesView-CoDK14B3.js} +1 -1
- package/dist/client/assets/{PiExtensionsManager-C0ljxGbt.js → PiExtensionsManager-vH7EJ5JD.js} +1 -1
- package/dist/client/assets/{PluginManager-D27abRF-.js → PluginManager-PbkFQ0Nu.js} +1 -1
- package/dist/client/assets/{ResearchView-BSpDz8YN.js → ResearchView-Dp4g_BWq.js} +1 -1
- package/dist/client/assets/{SecretsView-BmCemEu8.js → SecretsView-Q8wES8_N.js} +1 -1
- package/dist/client/assets/SettingsModal-127YAB8c.js +31 -0
- package/dist/client/assets/{SettingsModal-DvmwpEUE.js → SettingsModal-DdUztATB.js} +1 -1
- package/dist/client/assets/{SetupWizardModal-CDfZpkB7.js → SetupWizardModal-BSAFiQpJ.js} +1 -1
- package/dist/client/assets/{SkillsView-BCpa_vud.js → SkillsView-Bj8KQQXB.js} +1 -1
- package/dist/client/assets/{StashRecoveryView-BYLja93K.js → StashRecoveryView-DvKN_b_k.js} +1 -1
- package/dist/client/assets/{TodoView-lbnG-8cZ.js → TodoView-C-cabt2D.js} +1 -1
- package/dist/client/assets/{dashboard-view-CY6MGQbI.js → dashboard-view-DrHb8VOl.js} +1 -1
- package/dist/client/assets/{folder-open-CZghG0dv.js → folder-open-CYVKFKAx.js} +1 -1
- package/dist/client/assets/index-Cuh_Pqv0.css +1 -0
- package/dist/client/assets/index-Cze5qbME.js +742 -0
- package/dist/client/assets/{upload-L7aDk8Xn.js → upload-eQh-mH3-.js} +1 -1
- package/dist/client/assets/{users-DoWKt94F.js → users-B5upejXg.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 +1078 -644
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
- 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-reports/src/dashboard/__tests__/ReportsView.test.tsx +15 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/test-setup.ts +9 -1
- package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
- package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
- package/package.json +1 -1
- package/skill/fusion/references/extension-tools.md +2 -0
- package/dist/client/assets/ChatView-CCAUA7HB.js +0 -6
- package/dist/client/assets/SettingsModal-m3KMs_uS.js +0 -31
- package/dist/client/assets/index-lDPXOH7J.css +0 -1
- package/dist/client/assets/index-tJzhtiGM.js +0 -742
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-
|
|
2
|
-
import{c as bt,A as Je,C as pt,Z as Is,s as
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-CFX3jxfA.js","assets/vendor-react-K0fH_qHe.js","assets/index-Cze5qbME.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/vendor-codemirror-jBKmHyH0.js","assets/index-Cuh_Pqv0.css","assets/AgentPermissionPolicyEditor-4tnYHS0-.js","assets/AgentPermissionPolicyEditor-CGxjOr6G.css","assets/ExperimentalAgentOnboardingModal-8yeOcqbX.js","assets/ExperimentalAgentOnboardingModal-BNpveCEk.css","assets/AgentDetailView-CY-O6VkV.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as bt,A as Je,C as pt,Z as Is,s as Fs,r as Et,F as _t,f as zs,a as Os,b as ms,B as Lt,u as gs,d as yt,e as Ds,g as Hs,h as Bs,i as Pt,j as qt,k as xt,P as Ws,l as Gs,m as Vs,n as Ks,o as Zt,G as Us,S as Ys,L as kt,T as wt,R as Ze,X as Jt,p as Xs,q as qs,t as ut,v as Zs,w as Qt,x as Js,y as Qs,z as fe,D as nt,E as ea,M as ta,H as sa,I as es,N as ts,J as ss,K as aa,O as Ct,Q as mt,U as na,V as la,W as ia,Y as ra,_ as oa,$ as as,a0 as ca,a1 as da,a2 as gt,a3 as ua,a4 as ns,a5 as ma,a6 as ga}from"./index-Cze5qbME.js";import{r as s,j as e,a as ha}from"./vendor-react-K0fH_qHe.js";import{A as pa,S as xa,E as ba,f as va}from"./ExperimentalAgentOnboardingModal-8yeOcqbX.js";import{U as It}from"./upload-eQh-mH3-.js";import{F as fa}from"./folder-open-CYVKFKAx.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";/**
|
|
3
3
|
* @license lucide-react v1.7.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -14,16 +14,16 @@ import{c as bt,A as Je,C as pt,Z as Is,s as zs,r as Et,F as _t,f as Fs,a as Os,b
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the ISC license.
|
|
16
16
|
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/const
|
|
17
|
+
*/const wa=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Ca=bt("zoom-in",wa);/**
|
|
18
18
|
* @license lucide-react v1.7.0 - ISC
|
|
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 Sa=[["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"}]],Aa=bt("zoom-out",Sa);function ls(n){return typeof n=="number"&&Number.isFinite(n)?n:0}function Xe(n){return n.toLocaleString()}function Ra({agents:n}){const{rows:r,totalInputTokens:x,totalOutputTokens:g,totalTokens:h}=s.useMemo(()=>{const o=n.map(d=>{const f=ls(d.totalInputTokens),j=ls(d.totalOutputTokens);return{id:d.id,name:d.name,inputTokens:f,outputTokens:j,totalTokens:f+j}}).sort((d,f)=>f.totalTokens-d.totalTokens||d.name.localeCompare(f.name)||d.id.localeCompare(f.id));return{rows:o,totalInputTokens:o.reduce((d,f)=>d+f.inputTokens,0),totalOutputTokens:o.reduce((d,f)=>d+f.outputTokens,0),totalTokens:o.reduce((d,f)=>d+f.totalTokens,0)}},[n]),b=h>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:Xe(x)})]}),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:Xe(g)})]}),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:Xe(h)})]})]}),b?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:r.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:Xe(o.inputTokens)}),e.jsx("td",{children:Xe(o.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:Xe(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 $a=[{icon:Je,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:Na,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:pt,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:Is,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function Ta({stats:n,className:r=""}){return n?e.jsx("div",{className:`agent-metrics-bar ${r}`.trim(),children:$a.map(x=>{const g=x.valueKey==="successRate"?`${Math.round(n.successRate*100)}%`:n[x.valueKey];return e.jsxs("div",{className:`agent-metric-card ${x.className}`,children:[e.jsx(x.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:g}),e.jsx("span",{className:"agent-metric-label",children:x.label})]})]},x.label)})}):null}const is=200;function Ma(n,r){const[x,g]=s.useState([]),[h,b]=s.useState(!1),o=s.useRef(null),d=s.useRef(0),f=s.useRef(n),j=s.useRef(r);return(f.current!==n||j.current!==r)&&(f.current=n,j.current=r,d.current++,o.current&&(o.current(),o.current=null),g([]),b(!1)),s.useEffect(()=>{if(!n){g([]),b(!1);return}const $=d.current;let y=`/api/tasks/${encodeURIComponent(n)}/logs/stream`;r&&(y+=`?projectId=${encodeURIComponent(r)}`);const w=zs(y,{events:{"agent:log":E=>{if(d.current===$)try{const P=JSON.parse(E.data),B={type:P.type??"text",text:P.text??P.content??"",timestamp:P.timestamp,content:P.content};g(T=>{const L=[B,...T];return L.length>is?L.slice(0,is):L})}catch{}}},onOpen:()=>{d.current===$&&b(!0)},onError:()=>{d.current===$&&b(!1)}});return o.current=w,()=>{w(),o.current=null,d.current===$&&b(!1)}},[n,r]),{entries:x,isConnected:h}}const Ea=5e3;function _a({agent:n,projectId:r,onSelect:x,onOpenTaskLogs:g}){const{entries:h,isConnected:b}=Ma(n.taskId,r),[o,d]=s.useState(null);s.useEffect(()=>{if(!n.taskId){d(null);return}let T=!1,L;const v=async()=>{try{const F=await Fs(n.taskId,r);T||d(F)}catch{}finally{T||(L=setTimeout(v,Ea))}};return v(),()=>{T=!0,L&&clearTimeout(L)}},[n.taskId,r]);const f=n.lastHeartbeatAt?Math.floor((Date.now()-new Date(n.lastHeartbeatAt).getTime())/1e3):0,j=(()=>{if(!n.lastHeartbeatAt)return null;const T=Et(n.runtimeConfig?.heartbeatIntervalMs),L=new Date(n.lastHeartbeatAt).getTime()+T,v=Math.round((L-Date.now())/1e3);return Number.isFinite(v)?v<=0?`Heartbeat overdue ${St(-v)}`:`Next heartbeat in ${St(v)}`:null})(),k=o?.steps?.[o.currentStep??0],$=o?.steps?.length??0,y=(o?.currentStep??0)+1,w=o?.modelId,E=()=>{x&&x(n.id)},P=T=>{T.stopPropagation(),n.taskId&&g&&g(n.taskId)},B=T=>{(T.key==="Enter"||T.key===" ")&&(T.preventDefault(),E())};return e.jsxs("div",{className:"live-agent-card",onClick:E,onKeyDown:B,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:h.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 ",y,$?`/${$}`:"",": ",k.name]}),w&&e.jsx("div",{className:"live-agent-card-status-sub",children:w}),e.jsx("div",{className:"live-agent-card-status-sub",children:b?"Waiting for output...":"Connecting to log stream..."})]}):e.jsx("span",{children:b?"Waiting for output...":"Connecting..."}):e.jsx("span",{children:n.state==="running"?"Starting...":"Idle — no task assigned"})}):h.slice(0,20).map((T,L)=>e.jsx("div",{className:"live-agent-card-line",children:T.text},L))}),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:St(f)}),j&&e.jsx("span",{className:"live-agent-card-next-heartbeat",title:j,children:j})]}),e.jsxs("div",{className:"live-agent-card-footer-actions",children:[n.taskId&&g&&e.jsxs("button",{type:"button",className:"live-agent-card-logs-btn",onClick:P,title:"View live run logs","aria-label":`View live logs for ${n.taskId}`,children:[e.jsx(_t,{size:12}),e.jsx("span",{children:"Live logs"})]}),b&&e.jsx(Je,{size:12,className:"live-agent-streaming-dot"})]})]})]})}function St(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 La({agents:n,projectId:r,onAgentSelect:x,onOpenTaskLogs:g,className:h=""}){const b=Array.from(new Map(n.map(o=>[o.id,o])).values());return b.length===0?null:e.jsxs("div",{className:`active-agents-panel ${h}`.trim(),children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(Je,{size:16}),e.jsxs("span",{children:["Active Agents (",b.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:b.map(o=>e.jsx(_a,{agent:o,projectId:r,onSelect:x,onOpenTaskLogs:g},o.id))})]})}function Pa({stats:n,activeAgents:r,projectId:x,isOpen:g,onToggle:h,onSelectAgent:b,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":g,onClick:h,children:[e.jsxs("span",{className:"agents-overview-bar__title-wrap",children:[g?e.jsx(Os,{size:16,"aria-hidden":"true"}):e.jsx(ms,{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:[r.filter(d=>d.state==="active").length," active · ",r.filter(d=>d.state==="running").length," running"]})]}),g?e.jsxs("div",{className:"agents-overview-bar__content",children:[e.jsx(Ta,{stats:n,className:"agents-overview-bar__metrics"}),e.jsx(La,{agents:r,projectId:x,onAgentSelect:b,onOpenTaskLogs:o,className:"agents-overview-bar__active-panel"})]}):null]})}function At({title:n="No agents found",description:r="Create an agent to get started",ctaLabel:x="Create Agent",onCtaClick:g}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(Lt,{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:r}),g?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:g,children:x}):null]})}const rs=3,Rt=1e3;function Ia({isOpen:n,onClose:r,onGenerated:x,projectId:g}){gs(n);const[h,b]=s.useState(""),[o,d]=s.useState({type:"input"}),[f,j]=s.useState(null),[k,$]=s.useState(!1),y=s.useRef(null),w=s.useRef(null);s.useEffect(()=>{n&&o.type==="input"&&w.current?.focus()},[n,o.type]),s.useEffect(()=>{if(!n&&y.current){const v=y.current;y.current=null,yt(v,g).catch(()=>{})}},[n,g]),s.useEffect(()=>{if(!n)return;const v=F=>{F.key==="Escape"&&E()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[n]);const E=s.useCallback(()=>{if(y.current){const v=y.current;y.current=null,yt(v,g).catch(()=>{})}b(""),d({type:"input"}),j(null),$(!1),r()},[r,g]),P=s.useCallback(async()=>{if(!(!h.trim()||h.trim().length<rs)){j(null),d({type:"loading"});try{const{sessionId:v}=await Ds(h.trim(),g);y.current=v;const{spec:F}=await Hs(v,g);d({type:"preview",spec:F,sessionId:v})}catch(v){const F=v instanceof Error?v.message:"Failed to generate agent specification";F.includes("429")||F.toLowerCase().includes("rate limit")?j("Too many requests. Please wait a moment and try again."):j(F),d({type:"input"}),y.current=null}}},[h,g]),B=s.useCallback(async()=>{if(y.current){const v=y.current;y.current=null;try{await yt(v,g)}catch{}}await P()},[P,g]),T=s.useCallback(()=>{o.type==="preview"&&(y.current=null,x(o.spec),b(""),d({type:"input"}),j(null),$(!1),r())},[o,x,r]);if(!n)return null;const L=h.trim().length>=rs&&h.trim().length<=Rt;return e.jsx("div",{className:"agent-dialog-overlay",onClick:v=>{v.target===v.currentTarget&&E()},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:E,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[f&&e.jsx("div",{className:"agent-dialog-error-banner",children:f}),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:h,onChange:v=>b(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&L&&(v.preventDefault(),P())},maxLength:Rt,"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:[h.length,"/",Rt]})]})]})]}),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:()=>$(!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:E,children:"Cancel"}),o.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void P(),disabled:!L,children:"Generate"}),o.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void B(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:T,children:"Use This"})]})]})]})})}const os=[{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:"✦"}],cs=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function za({isOpen:n,onClose:r,onCreated:x,projectId:g,prefillDraft:h=null,agentOnboardingEnabled:b=!1,existingAgents:o=[],onPrefillDraft:d}){const[f,j]=s.useState(0),[k,$]=s.useState("presets"),[y,w]=s.useState(""),[E,P]=s.useState(""),[B,T]=s.useState(""),[L,v]=s.useState("custom"),[F,z]=s.useState(""),[q,je]=s.useState(""),[le,V]=s.useState(""),[ne,ie]=s.useState(""),[O,N]=s.useState(""),[ge,he]=s.useState(""),[A,Z]=s.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[re,Ee]=s.useState(null),[ee,te]=s.useState([]),[Ne,K]=s.useState(!1),[pe,Se]=s.useState(null),[oe,G]=s.useState(!1),[ce,xe]=s.useState(!1),[_e,Fe]=s.useState([]),[Ae,Oe]=s.useState(!1),[be,$e]=s.useState([]),[ve,Le]=s.useState([]),[M,_]=s.useState("model"),[ye,ke]=s.useState(""),[Pe,de]=s.useState([]),[Ie,Te]=s.useState(!1),[i,p]=s.useState([]),[I,J]=s.useState(!1);s.useEffect(()=>{n&&(Oe(!0),Bs().then(a=>{Fe(a.models),$e(a.favoriteProviders),Le(a.favoriteModels)}).catch(()=>{}).finally(()=>Oe(!1)))},[n]),s.useEffect(()=>{n&&(J(!0),p([]),Pt(void 0,g).then(a=>{p(a)}).catch(()=>{p([])}).finally(()=>J(!1)))},[n,g]),s.useEffect(()=>{if(!n)return;const a=Gs;if(typeof a!="function"){de([]),Te(!1);return}Te(!0),de([]),a(g).then(S=>{de(S)}).catch(()=>{de([])}).finally(()=>Te(!1))},[n,g]);const D=A.model.includes("/")?A.model:"",U=s.useCallback(a=>{const S=cs.has(a.role)?a.role:"custom";w(a.title),P(a.description),T(a.icon),v(S),V(a.systemPrompt),Z(se=>({...se,thinkingLevel:a.thinkingLevel,maxTurns:a.maxTurns})),G(!1),j(1)},[]),De=s.useCallback(a=>{Z(S=>({...S,model:a}))},[]),He=s.useCallback(a=>{_(a),a==="model"&&ke("")},[]),vt=s.useCallback(async a=>{const S=be,ue=S.includes(a)?S.filter(Re=>Re!==a):[a,...S];$e(ue);try{await qt({favoriteProviders:ue,favoriteModels:ve})}catch{$e(S)}},[be,ve]),ze=s.useCallback(async a=>{const S=ve,ue=S.includes(a)?S.filter(Re=>Re!==a):[a,...S];Le(ue);try{await qt({favoriteProviders:be,favoriteModels:ue})}catch{Le(S)}},[be,ve]),ft=s.useCallback(a=>{Ee(a.id),w(a.name),T(a.icon),P(a.description??a.title),v(a.role),N(a.soul??""),V(a.instructionsText??""),j(1)},[]),Qe=s.useCallback(a=>{const S=a.runtimeHint?.trim()??"",se=a.model?.trim()||a.modelHint?.trim()||"";j(1),$("custom"),w(a.name??""),P(a.title??""),T(a.icon??""),v(cs.has(a.role)?a.role:"custom"),z(a.reportsTo??""),V(a.instructionsText??""),ie(a.heartbeatProcedurePath??""),N(a.soul??""),he(a.memory??""),te(Array.isArray(a.skills)?a.skills:[]),Z(ue=>({...ue,model:S?"":se,thinkingLevel:a.thinkingLevel??ue.thinkingLevel,maxTurns:a.maxTurns??ue.maxTurns})),S?(_("runtime"),ke(S)):(_("model"),ke(""))},[]);if(s.useEffect(()=>{!n||!h||Qe(h)},[n,h,Qe]),!n)return null;const Ce=()=>{j(0),$("presets"),w(""),P(""),T(""),v("custom"),z(""),je(""),V(""),ie(""),N(""),he(""),Z({model:"",thinkingLevel:"off",maxTurns:1e3}),_("model"),ke(""),Ee(null),te([]),Se(null),G(!1),xe(!1),r()},lt=async()=>{if(y.trim()){K(!0),Se(null);try{const a={};M==="runtime"?ye.trim()&&(a.runtimeHint=ye.trim()):A.model.trim()&&(a.model=A.model.trim()),A.thinkingLevel!=="off"&&(a.thinkingLevel=A.thinkingLevel),A.maxTurns!==1e3&&(a.maxTurns=A.maxTurns),await Ks({name:y.trim(),role:L,...E.trim()?{title:E.trim()}:{},...B.trim()?{icon:B.trim()}:{},...F.trim()?{reportsTo:F.trim()}:{},...q.trim()?{instructionsPath:q.trim()}:{},...le.trim()?{instructionsText:le.trim()}:{},...ne.trim()?{heartbeatProcedurePath:ne.trim()}:{},...O.trim()?{soul:O.trim()}:{},...ge.trim()?{memory:ge.trim()}:{},...Object.keys(a).length>0?{runtimeConfig:a}:{},...ee.length>0?{metadata:{skills:ee}}:{}},g),Ce(),x()}catch(a){Se(a instanceof Error?a.message:"Failed to create agent")}finally{K(!1)}}},Me=os.find(a=>a.value===L),Be=F.trim(),we=Be?i.find(a=>a.id===Be):void 0,We=ye?Pe.find(a=>a.runtimeId===ye):void 0,et=a=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:a,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":a,children:[e.jsxs("label",{className:`agent-runtime-mode-option${M==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:a,value:"model",checked:M==="model",onChange:()=>He("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${M==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:a,value:"runtime",checked:M==="runtime",onChange:()=>He("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),M==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),Ae?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(Vs,{id:"agent-model",label:"Model",value:D,onChange:De,models:_e,placeholder:"Select a model…",favoriteProviders:be,onToggleFavorite:vt,favoriteModels:ve,onToggleModelFavorite:ze})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),Ie?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:ye,onChange:S=>ke(S.target.value),children:[e.jsx("option",{value:"",children:Pe.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),Pe.map(S=>e.jsx("option",{value:S.runtimeId,children:S.description?`${S.name} — ${S.description}`:S.name},`${S.pluginId}:${S.runtimeId}`))]})]})]});return ha.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:a=>{a.target===a.currentTarget&&Ce()},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:Ce,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(a=>e.jsx("div",{className:`agent-dialog-step${a===f?" active":a<f?" completed":""}`,"aria-label":`Step ${a+1}`},a))}),e.jsxs("div",{className:"agent-dialog-body",children:[f===0&&e.jsxs("div",{children:[b&&e.jsx("div",{className:"agent-dialog-step-zero-actions",children:e.jsx("button",{type:"button",className:"btn agent-dialog-interview-btn",onClick:()=>xe(!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:()=>$("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:()=>$("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:pa.map(a=>e.jsxs("button",{type:"button",className:`agent-preset-card${re===a.id?" selected":""}`,"data-testid":`preset-${a.id}`,onClick:()=>ft(a),title:a.title,children:[e.jsx("span",{className:"agent-preset-icon",children:e.jsx(xt,{agent:{id:a.id,icon:a.icon,name:a.name},size:28})}),e.jsx("span",{className:"agent-preset-name",children:a.name}),e.jsx("span",{className:"agent-preset-role",children:a.role}),a.description&&e.jsx("span",{className:"agent-preset-description",children:a.description})]},a.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 ",!re&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:y,onChange:a=>w(a.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:E,onChange:a=>P(a.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:B,onChange:a=>T(a.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:os.map(a=>e.jsxs("button",{type:"button",className:`agent-role-option${L===a.value?" selected":""}`,onClick:()=>v(a.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:a.icon}),e.jsx("span",{className:"agent-role-option-label",children:a.label})]},a.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:F,onChange:a=>z(a.target.value),disabled:I,children:[e.jsx("option",{value:"",children:"No manager"}),i.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.id,")"]},a.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:O,onChange:a=>N(a.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:ge,onChange:a=>he(a.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:q,onChange:a=>je(a.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:ne,onChange:a=>ie(a.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:le,onChange:a=>V(a.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),et("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:()=>G(!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"})]})]})]}),f===1&&e.jsxs("div",{children:[et("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:a=>Z(S=>({...S,thinkingLevel:a.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:a=>Z(S=>({...S,maxTurns:Math.max(1,parseInt(a.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(xa,{id:"agent-skills",label:"Skills",value:ee,onChange:te,projectId:g}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),f===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:[B&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:B}),y]})]}),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:E,onChange:a=>P(a.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:[Me?.icon," ",Me?.label]})]}),Be&&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:we?`${we.name} (${we.id})`:Be})]}),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:O,onChange:a=>N(a.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:ne,onChange:a=>ie(a.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:q,onChange:a=>je(a.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:le,onChange:a=>V(a.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:M==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:M==="runtime"?We?We.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):D?e.jsxs(e.Fragment,{children:[e.jsx(Ws,{provider:D.split("/")[0],size:"sm"})," ",(()=>{const a=D.indexOf("/"),S=D.slice(0,a),se=D.slice(a+1);return _e.find(Re=>Re.provider===S&&Re.id===se)?.name||D})()]}):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})]}),ee.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:[ee.length," skill",ee.length!==1?"s":""," selected"]})]})]}),pe&&e.jsx("p",{className:"agent-dialog-error",children:pe})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[f>0&&e.jsx("button",{className:"btn",onClick:()=>j(a=>a-1),disabled:Ne,children:"Back"}),e.jsx("button",{className:"btn",onClick:Ce,disabled:Ne,children:"Cancel"}),f<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>j(a=>a+1),disabled:f===0&&!y.trim()&&!re,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void lt(),disabled:Ne||!y.trim(),children:Ne?"Creating...":"Create"})]})]}),e.jsx(Ia,{isOpen:oe,onClose:()=>G(!1),onGenerated:U,projectId:g}),e.jsx(ba,{isOpen:ce,onClose:()=>xe(!1),onUseDraft:a=>{d?.(a),d||Qe(a),xe(!1)},projectId:g,existingAgents:o,mode:"create"})]}),document.body)}function Fa(n){const r=n.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!r)throw new Error("Missing YAML frontmatter delimiters (---)");const x=r[1].split(/\r?\n/),g=r[2]??"",h={name:""},b=[];let o=!1;for(const d of x){const j=d.trimEnd().trim();if(!j)continue;if(j.startsWith("skills:")){o=!0;continue}if(o&&j.startsWith("- ")){b.push(j.slice(2).trim());continue}o=!1;const[k,...$]=j.split(":"),w=$.join(":").trim().replace(/^['"]|['"]$/g,"");k==="name"&&(h.name=w),k==="title"&&(h.title=w),k==="icon"&&(h.icon=w),k==="role"&&(h.role=w),k==="reportsTo"&&(h.reportsTo=w)}if(!h.name)throw new Error("Missing required field: name");return b.length>0&&(h.skills=b),g.trim().length>0&&(h.instructionBody=g),h}function Oa({isOpen:n,onClose:r,onImported:x,projectId:g,initialInputMethod:h="paste"}){gs(n);const[b,o]=s.useState("input"),[d,f]=s.useState(h),[j,k]=s.useState(""),[$,y]=s.useState([]),[w,E]=s.useState("Unknown"),[P,B]=s.useState([]),[T,L]=s.useState([]),[v,F]=s.useState([]),[z,q]=s.useState([]),[je,le]=s.useState(!1),[V,ne]=s.useState(!1),[ie,O]=s.useState(null),[N,ge]=s.useState(null),[he,A]=s.useState(null),Z=s.useRef(null),re=s.useRef(null),[Ee,ee]=s.useState([]),[te,Ne]=s.useState(""),[K,pe]=s.useState(null),[Se,oe]=s.useState(!1),[G,ce]=s.useState(null),xe=s.useRef(!1);s.useEffect(()=>{d==="browse"&&!xe.current&&!Se&&(xe.current=!0,oe(!0),ce(null),Zt().then(i=>{i.error?ce(i.error):i.companies.length>0?ee(i.companies):ce("No companies available")}).catch(i=>{ce(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{oe(!1)}))},[d,Se]);const _e=s.useCallback(()=>{xe.current=!0,ce(null),ee([]),pe(null),oe(!0),Zt().then(i=>{i.error?ce(i.error):i.companies.length>0?ee(i.companies):ce("No companies available")}).catch(i=>{ce(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{oe(!1)})},[]),Fe=s.useCallback(()=>{o("input"),f(h),k(""),y([]),E("Unknown"),B([]),L([]),F([]),q([]),le(!1),ne(!1),O(null),ge(null),A(null),ee([]),Ne(""),pe(null),oe(!1),ce(null),xe.current=!1},[h]),Ae=s.useCallback(()=>{Fe(),r()},[Fe,r]),Oe=s.useCallback(i=>{const p=i.target.files?.[0];if(!p)return;const I=new FileReader;I.onload=J=>{const D=J.target?.result;f("file"),y([]),k(D),O(null)},I.onerror=()=>{O("Failed to read file")},I.readAsText(p),i.target.value=""},[]),be=s.useCallback(async i=>{const p=Array.from(i.target.files??[]);if(p.length!==0)try{const I=p.filter(D=>(D.webkitRelativePath||D.name).toLowerCase().endsWith("agents.md")).sort((D,U)=>{const De=D.webkitRelativePath||D.name,He=U.webkitRelativePath||U.name;return De.localeCompare(He)});if(I.length===0){O("Selected directory has no AGENTS.md files");return}const J=[];for(const D of I){const U=await D.text();J.push(Fa(U))}f("directory"),y(J),k(""),O(null)}catch{O("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function $e(i){if(!g)return`/api${i}`;const p=i.includes("?")?"&":"?";return`/api${i}${p}projectId=${encodeURIComponent(g)}`}const ve=s.useCallback(async()=>{if(d==="directory"&&$.length===0){O("Please select a directory containing AGENTS.md files");return}if(d==="browse"&&!K){O("Please select a company from the catalog");return}if(d!=="directory"&&d!=="browse"&&!j.trim()){O("Please provide manifest content");return}le(!0),O(null);try{let i;d==="directory"?i={agents:$,dryRun:!0}:d==="browse"&&K?i={importSource:"companies.sh",companySlug:K.slug,dryRun:!0}:i={manifest:j,dryRun:!0};const p=await fetch($e("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!p.ok){const U=await p.json();throw new Error(U.error??`Parse failed (${p.status})`)}const I=await p.json(),J=I.agents&&I.agents.length>0?I.agents:I.created.map(U=>({name:U,role:"custom"})),D=Array.isArray(I.skills)?I.skills:[];E(I.companyName??"Unknown"),B(J),L(D),F(J.map(U=>U.name)),q(D.map(U=>U.name)),o("preview")}catch(i){O(i instanceof Error?i.message:"Failed to parse manifest")}finally{le(!1)}},[d,$,j,K,g]),Le=s.useCallback(async()=>{ne(!0),A(null);try{let i;d==="directory"?i={agents:$,skipExisting:!0,selectedAgents:v,selectedSkills:z}:d==="browse"&&K?i={importSource:"companies.sh",companySlug:K.slug,skipExisting:!0,selectedAgents:v,selectedSkills:z}:i={manifest:j,skipExisting:!0,selectedAgents:v,selectedSkills:z};const p=await fetch($e("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!p.ok){const J=await p.json();throw new Error(J.error??`Import failed (${p.status})`)}const I=await p.json();ge(I),o("result"),x()}catch(i){A(i instanceof Error?i.message:"Failed to import agents")}finally{ne(!1)}},[d,$,j,K,v,z,g,x]),M=v.length,_=z.length,ye=`${M} Agent${M!==1?"s":""}`,ke=`${_} Skill${_!==1?"s":""}`,Pe=M>0&&_>0?`${ye} + ${ke}`:_>0?ke:ye,de=M>0&&_>0?`Importing ${M} agent${M!==1?"s":""} and ${_} skill${_!==1?"s":""}...`:_>0?`Importing ${_} skill${_!==1?"s":""}...`:`Importing ${M} agent${M!==1?"s":""}...`,Ie=i=>{F(p=>p.includes(i)?p.filter(I=>I!==i):[...p,i])},Te=i=>{q(p=>p.includes(i)?p.filter(I=>I!==i):[...p,i])};return n?e.jsx("div",{className:"agent-dialog-overlay",onClick:i=>{i.target===i.currentTarget&&Ae()},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:Ae,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[b==="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:Z,type:"file",accept:".md,.txt",onChange:Oe,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:re,type:"file",webkitdirectory:"",multiple:!0,onChange:be,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>Z.current?.click(),children:[e.jsx(It,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>re.current?.click(),children:[e.jsx(fa,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{f("browse"),y([]),k(""),pe(null),O(null)},children:[e.jsx(Us,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),d==="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(Ys,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:te,onChange:i=>Ne(i.target.value),"aria-label":"Search companies"})]}),K&&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:K.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>pe(null),children:"Change"})]})]}),Se&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(kt,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),G&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(Ct,{size:16}),e.jsx("span",{children:G}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:_e,children:[e.jsx(Ze,{size:14}),"Retry"]})]}),!Se&&!G&&e.jsxs("div",{className:"agent-import-browse-list",children:[Ee.filter(i=>te===""||i.name.toLowerCase().includes(te.toLowerCase())||(i.tagline?.toLowerCase().includes(te.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${K?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>pe(i),role:"button",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&pe(i)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:i.name}),i.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[i.installs.toLocaleString()," installs"]})]}),i.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:i.tagline}),i.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:i.repo})]},i.slug)),Ee.filter(i=>te===""||i.name.toLowerCase().includes(te.toLowerCase())||(i.tagline?.toLowerCase().includes(te.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:te?"No companies match your search":"No companies available"})]})]}),d!=="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 Sa=[["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"}]],Aa=bt("zoom-out",Sa);function ls(n){return typeof n=="number"&&Number.isFinite(n)?n:0}function Xe(n){return n.toLocaleString()}function Ra({agents:n}){const{rows:r,totalInputTokens:x,totalOutputTokens:g,totalTokens:h}=s.useMemo(()=>{const o=n.map(d=>{const f=ls(d.totalInputTokens),j=ls(d.totalOutputTokens);return{id:d.id,name:d.name,inputTokens:f,outputTokens:j,totalTokens:f+j}}).sort((d,f)=>f.totalTokens-d.totalTokens||d.name.localeCompare(f.name)||d.id.localeCompare(f.id));return{rows:o,totalInputTokens:o.reduce((d,f)=>d+f.inputTokens,0),totalOutputTokens:o.reduce((d,f)=>d+f.outputTokens,0),totalTokens:o.reduce((d,f)=>d+f.totalTokens,0)}},[n]),b=h>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:Xe(x)})]}),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:Xe(g)})]}),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:Xe(h)})]})]}),b?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:r.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:Xe(o.inputTokens)}),e.jsx("td",{children:Xe(o.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:Xe(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 $a=[{icon:Je,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:Na,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:pt,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:Is,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function Ta({stats:n,className:r=""}){return n?e.jsx("div",{className:`agent-metrics-bar ${r}`.trim(),children:$a.map(x=>{const g=x.valueKey==="successRate"?`${Math.round(n.successRate*100)}%`:n[x.valueKey];return e.jsxs("div",{className:`agent-metric-card ${x.className}`,children:[e.jsx(x.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:g}),e.jsx("span",{className:"agent-metric-label",children:x.label})]})]},x.label)})}):null}const is=200;function Ma(n,r){const[x,g]=s.useState([]),[h,b]=s.useState(!1),o=s.useRef(null),d=s.useRef(0),f=s.useRef(n),j=s.useRef(r);return(f.current!==n||j.current!==r)&&(f.current=n,j.current=r,d.current++,o.current&&(o.current(),o.current=null),g([]),b(!1)),s.useEffect(()=>{if(!n){g([]),b(!1);return}const $=d.current;let y=`/api/tasks/${encodeURIComponent(n)}/logs/stream`;r&&(y+=`?projectId=${encodeURIComponent(r)}`);const w=Fs(y,{events:{"agent:log":E=>{if(d.current===$)try{const P=JSON.parse(E.data),W={type:P.type??"text",text:P.text??P.content??"",timestamp:P.timestamp,content:P.content};g(T=>{const L=[W,...T];return L.length>is?L.slice(0,is):L})}catch{}}},onOpen:()=>{d.current===$&&b(!0)},onError:()=>{d.current===$&&b(!1)}});return o.current=w,()=>{w(),o.current=null,d.current===$&&b(!1)}},[n,r]),{entries:x,isConnected:h}}const Ea=5e3;function _a({agent:n,projectId:r,onSelect:x,onOpenTaskLogs:g}){const{entries:h,isConnected:b}=Ma(n.taskId,r),[o,d]=s.useState(null);s.useEffect(()=>{if(!n.taskId){d(null);return}let T=!1,L;const v=async()=>{try{const z=await zs(n.taskId,r);T||d(z)}catch{}finally{T||(L=setTimeout(v,Ea))}};return v(),()=>{T=!0,L&&clearTimeout(L)}},[n.taskId,r]);const f=n.lastHeartbeatAt?Math.floor((Date.now()-new Date(n.lastHeartbeatAt).getTime())/1e3):0,j=(()=>{if(!n.lastHeartbeatAt)return null;const T=Et(n.runtimeConfig?.heartbeatIntervalMs),L=new Date(n.lastHeartbeatAt).getTime()+T,v=Math.round((L-Date.now())/1e3);return Number.isFinite(v)?v<=0?`Heartbeat overdue ${St(-v)}`:`Next heartbeat in ${St(v)}`:null})(),k=o?.steps?.[o.currentStep??0],$=o?.steps?.length??0,y=(o?.currentStep??0)+1,w=o?.modelId,E=()=>{x&&x(n.id)},P=T=>{T.stopPropagation(),n.taskId&&g&&g(n.taskId)},W=T=>{(T.key==="Enter"||T.key===" ")&&(T.preventDefault(),E())};return e.jsxs("div",{className:"live-agent-card",onClick:E,onKeyDown:W,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:h.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 ",y,$?`/${$}`:"",": ",k.name]}),w&&e.jsx("div",{className:"live-agent-card-status-sub",children:w}),e.jsx("div",{className:"live-agent-card-status-sub",children:b?"Waiting for output...":"Connecting to log stream..."})]}):e.jsx("span",{children:b?"Waiting for output...":"Connecting..."}):e.jsx("span",{children:n.state==="running"?"Starting...":"Idle — no task assigned"})}):h.slice(0,20).map((T,L)=>e.jsx("div",{className:"live-agent-card-line",children:T.text},L))}),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:St(f)}),j&&e.jsx("span",{className:"live-agent-card-next-heartbeat",title:j,children:j})]}),e.jsxs("div",{className:"live-agent-card-footer-actions",children:[n.taskId&&g&&e.jsxs("button",{type:"button",className:"live-agent-card-logs-btn",onClick:P,title:"View live run logs","aria-label":`View live logs for ${n.taskId}`,children:[e.jsx(_t,{size:12}),e.jsx("span",{children:"Live logs"})]}),b&&e.jsx(Je,{size:12,className:"live-agent-streaming-dot"})]})]})]})}function St(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 La({agents:n,projectId:r,onAgentSelect:x,onOpenTaskLogs:g,className:h=""}){const b=Array.from(new Map(n.map(o=>[o.id,o])).values());return b.length===0?null:e.jsxs("div",{className:`active-agents-panel ${h}`.trim(),children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(Je,{size:16}),e.jsxs("span",{children:["Active Agents (",b.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:b.map(o=>e.jsx(_a,{agent:o,projectId:r,onSelect:x,onOpenTaskLogs:g},o.id))})]})}function Pa({stats:n,activeAgents:r,projectId:x,isOpen:g,onToggle:h,onSelectAgent:b,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":g,onClick:h,children:[e.jsxs("span",{className:"agents-overview-bar__title-wrap",children:[g?e.jsx(Os,{size:16,"aria-hidden":"true"}):e.jsx(ms,{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:[r.filter(d=>d.state==="active").length," active · ",r.filter(d=>d.state==="running").length," running"]})]}),g?e.jsxs("div",{className:"agents-overview-bar__content",children:[e.jsx(Ta,{stats:n,className:"agents-overview-bar__metrics"}),e.jsx(La,{agents:r,projectId:x,onAgentSelect:b,onOpenTaskLogs:o,className:"agents-overview-bar__active-panel"})]}):null]})}function At({title:n="No agents found",description:r="Create an agent to get started",ctaLabel:x="Create Agent",onCtaClick:g}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(Lt,{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:r}),g?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:g,children:x}):null]})}const rs=3,Rt=1e3;function Ia({isOpen:n,onClose:r,onGenerated:x,projectId:g}){gs(n);const[h,b]=s.useState(""),[o,d]=s.useState({type:"input"}),[f,j]=s.useState(null),[k,$]=s.useState(!1),y=s.useRef(null),w=s.useRef(null);s.useEffect(()=>{n&&o.type==="input"&&w.current?.focus()},[n,o.type]),s.useEffect(()=>{if(!n&&y.current){const v=y.current;y.current=null,yt(v,g).catch(()=>{})}},[n,g]),s.useEffect(()=>{if(!n)return;const v=z=>{z.key==="Escape"&&E()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[n]);const E=s.useCallback(()=>{if(y.current){const v=y.current;y.current=null,yt(v,g).catch(()=>{})}b(""),d({type:"input"}),j(null),$(!1),r()},[r,g]),P=s.useCallback(async()=>{if(!(!h.trim()||h.trim().length<rs)){j(null),d({type:"loading"});try{const{sessionId:v}=await Ds(h.trim(),g);y.current=v;const{spec:z}=await Hs(v,g);d({type:"preview",spec:z,sessionId:v})}catch(v){const z=v instanceof Error?v.message:"Failed to generate agent specification";z.includes("429")||z.toLowerCase().includes("rate limit")?j("Too many requests. Please wait a moment and try again."):j(z),d({type:"input"}),y.current=null}}},[h,g]),W=s.useCallback(async()=>{if(y.current){const v=y.current;y.current=null;try{await yt(v,g)}catch{}}await P()},[P,g]),T=s.useCallback(()=>{o.type==="preview"&&(y.current=null,x(o.spec),b(""),d({type:"input"}),j(null),$(!1),r())},[o,x,r]);if(!n)return null;const L=h.trim().length>=rs&&h.trim().length<=Rt;return e.jsx("div",{className:"agent-dialog-overlay",onClick:v=>{v.target===v.currentTarget&&E()},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:E,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[f&&e.jsx("div",{className:"agent-dialog-error-banner",children:f}),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:h,onChange:v=>b(v.target.value),onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&L&&(v.preventDefault(),P())},maxLength:Rt,"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:[h.length,"/",Rt]})]})]})]}),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:()=>$(!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:E,children:"Cancel"}),o.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void P(),disabled:!L,children:"Generate"}),o.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void W(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:T,children:"Use This"})]})]})]})})}const os=[{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:"✦"}],cs=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Fa({isOpen:n,onClose:r,onCreated:x,projectId:g,prefillDraft:h=null,agentOnboardingEnabled:b=!1,existingAgents:o=[],onPrefillDraft:d}){const[f,j]=s.useState(0),[k,$]=s.useState("presets"),[y,w]=s.useState(""),[E,P]=s.useState(""),[W,T]=s.useState(""),[L,v]=s.useState("custom"),[z,F]=s.useState(""),[q,je]=s.useState(""),[le,V]=s.useState(""),[ne,ie]=s.useState(""),[O,N]=s.useState(""),[ge,he]=s.useState(""),[A,Z]=s.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[re,Ee]=s.useState(null),[ee,te]=s.useState([]),[Ne,K]=s.useState(!1),[pe,Se]=s.useState(null),[oe,G]=s.useState(!1),[ce,xe]=s.useState(!1),[_e,ze]=s.useState([]),[Ae,Oe]=s.useState(!1),[be,$e]=s.useState([]),[ve,Le]=s.useState([]),[M,_]=s.useState("model"),[ye,ke]=s.useState(""),[Pe,de]=s.useState([]),[Ie,Te]=s.useState(!1),[i,p]=s.useState([]),[I,J]=s.useState(!1);s.useEffect(()=>{n&&(Oe(!0),Bs().then(a=>{ze(a.models),$e(a.favoriteProviders),Le(a.favoriteModels)}).catch(()=>{}).finally(()=>Oe(!1)))},[n]),s.useEffect(()=>{n&&(J(!0),p([]),Pt(void 0,g).then(a=>{p(a)}).catch(()=>{p([])}).finally(()=>J(!1)))},[n,g]),s.useEffect(()=>{if(!n)return;const a=Gs;if(typeof a!="function"){de([]),Te(!1);return}Te(!0),de([]),a(g).then(S=>{de(S)}).catch(()=>{de([])}).finally(()=>Te(!1))},[n,g]);const D=A.model.includes("/")?A.model:"",U=s.useCallback(a=>{const S=cs.has(a.role)?a.role:"custom";w(a.title),P(a.description),T(a.icon),v(S),V(a.systemPrompt),Z(se=>({...se,thinkingLevel:a.thinkingLevel,maxTurns:a.maxTurns})),G(!1),j(1)},[]),De=s.useCallback(a=>{Z(S=>({...S,model:a}))},[]),He=s.useCallback(a=>{_(a),a==="model"&&ke("")},[]),vt=s.useCallback(async a=>{const S=be,ue=S.includes(a)?S.filter(Re=>Re!==a):[a,...S];$e(ue);try{await qt({favoriteProviders:ue,favoriteModels:ve})}catch{$e(S)}},[be,ve]),Fe=s.useCallback(async a=>{const S=ve,ue=S.includes(a)?S.filter(Re=>Re!==a):[a,...S];Le(ue);try{await qt({favoriteProviders:be,favoriteModels:ue})}catch{Le(S)}},[be,ve]),ft=s.useCallback(a=>{Ee(a.id),w(a.name),T(a.icon),P(a.description??a.title),v(a.role),N(a.soul??""),V(a.instructionsText??""),j(1)},[]),Qe=s.useCallback(a=>{const S=a.runtimeHint?.trim()??"",se=a.model?.trim()||a.modelHint?.trim()||"";j(1),$("custom"),w(a.name??""),P(a.title??""),T(a.icon??""),v(cs.has(a.role)?a.role:"custom"),F(a.reportsTo??""),V(a.instructionsText??""),ie(a.heartbeatProcedurePath??""),N(a.soul??""),he(a.memory??""),te(Array.isArray(a.skills)?a.skills:[]),Z(ue=>({...ue,model:S?"":se,thinkingLevel:a.thinkingLevel??ue.thinkingLevel,maxTurns:a.maxTurns??ue.maxTurns})),S?(_("runtime"),ke(S)):(_("model"),ke(""))},[]);if(s.useEffect(()=>{!n||!h||Qe(h)},[n,h,Qe]),!n)return null;const we=()=>{j(0),$("presets"),w(""),P(""),T(""),v("custom"),F(""),je(""),V(""),ie(""),N(""),he(""),Z({model:"",thinkingLevel:"off",maxTurns:1e3}),_("model"),ke(""),Ee(null),te([]),Se(null),G(!1),xe(!1),r()},lt=async()=>{if(y.trim()){K(!0),Se(null);try{const a={};M==="runtime"?ye.trim()&&(a.runtimeHint=ye.trim()):A.model.trim()&&(a.model=A.model.trim()),A.thinkingLevel!=="off"&&(a.thinkingLevel=A.thinkingLevel),A.maxTurns!==1e3&&(a.maxTurns=A.maxTurns),await Ks({name:y.trim(),role:L,...E.trim()?{title:E.trim()}:{},...W.trim()?{icon:W.trim()}:{},...z.trim()?{reportsTo:z.trim()}:{},...q.trim()?{instructionsPath:q.trim()}:{},...le.trim()?{instructionsText:le.trim()}:{},...ne.trim()?{heartbeatProcedurePath:ne.trim()}:{},...O.trim()?{soul:O.trim()}:{},...ge.trim()?{memory:ge.trim()}:{},...Object.keys(a).length>0?{runtimeConfig:a}:{},...ee.length>0?{metadata:{skills:ee}}:{}},g),we(),x()}catch(a){Se(a instanceof Error?a.message:"Failed to create agent")}finally{K(!1)}}},Me=os.find(a=>a.value===L),Be=z.trim(),Ce=Be?i.find(a=>a.id===Be):void 0,We=ye?Pe.find(a=>a.runtimeId===ye):void 0,et=a=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:a,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":a,children:[e.jsxs("label",{className:`agent-runtime-mode-option${M==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:a,value:"model",checked:M==="model",onChange:()=>He("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${M==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:a,value:"runtime",checked:M==="runtime",onChange:()=>He("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),M==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),Ae?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(Vs,{id:"agent-model",label:"Model",value:D,onChange:De,models:_e,placeholder:"Select a model…",favoriteProviders:be,onToggleFavorite:vt,favoriteModels:ve,onToggleModelFavorite:Fe})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),Ie?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:ye,onChange:S=>ke(S.target.value),children:[e.jsx("option",{value:"",children:Pe.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),Pe.map(S=>e.jsx("option",{value:S.runtimeId,children:S.description?`${S.name} — ${S.description}`:S.name},`${S.pluginId}:${S.runtimeId}`))]})]})]});return ha.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:a=>{a.target===a.currentTarget&&we()},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:we,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(a=>e.jsx("div",{className:`agent-dialog-step${a===f?" active":a<f?" completed":""}`,"aria-label":`Step ${a+1}`},a))}),e.jsxs("div",{className:"agent-dialog-body",children:[f===0&&e.jsxs("div",{children:[b&&e.jsx("div",{className:"agent-dialog-step-zero-actions",children:e.jsx("button",{type:"button",className:"btn agent-dialog-interview-btn",onClick:()=>xe(!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:()=>$("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:()=>$("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:pa.map(a=>e.jsxs("button",{type:"button",className:`agent-preset-card${re===a.id?" selected":""}`,"data-testid":`preset-${a.id}`,onClick:()=>ft(a),title:a.title,children:[e.jsx("span",{className:"agent-preset-icon",children:e.jsx(xt,{agent:{id:a.id,icon:a.icon,name:a.name},size:28})}),e.jsx("span",{className:"agent-preset-name",children:a.name}),e.jsx("span",{className:"agent-preset-role",children:a.role}),a.description&&e.jsx("span",{className:"agent-preset-description",children:a.description})]},a.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 ",!re&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:y,onChange:a=>w(a.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:E,onChange:a=>P(a.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:W,onChange:a=>T(a.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:os.map(a=>e.jsxs("button",{type:"button",className:`agent-role-option${L===a.value?" selected":""}`,onClick:()=>v(a.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:a.icon}),e.jsx("span",{className:"agent-role-option-label",children:a.label})]},a.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:z,onChange:a=>F(a.target.value),disabled:I,children:[e.jsx("option",{value:"",children:"No manager"}),i.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.id,")"]},a.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:O,onChange:a=>N(a.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:ge,onChange:a=>he(a.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:q,onChange:a=>je(a.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:ne,onChange:a=>ie(a.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:le,onChange:a=>V(a.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),et("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:()=>G(!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"})]})]})]}),f===1&&e.jsxs("div",{children:[et("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:a=>Z(S=>({...S,thinkingLevel:a.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:a=>Z(S=>({...S,maxTurns:Math.max(1,parseInt(a.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(xa,{id:"agent-skills",label:"Skills",value:ee,onChange:te,projectId:g}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),f===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 agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-name",children:"Name"}),e.jsx("input",{id:"agent-review-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:y,onChange:a=>w(a.target.value)})]}),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:E,onChange:a=>P(a.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:[Me?.icon," ",Me?.label]})]}),Be&&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:Ce?`${Ce.name} (${Ce.id})`:Be})]}),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:O,onChange:a=>N(a.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:ne,onChange:a=>ie(a.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:q,onChange:a=>je(a.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:le,onChange:a=>V(a.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:M==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:M==="runtime"?We?We.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):D?e.jsxs(e.Fragment,{children:[e.jsx(Ws,{provider:D.split("/")[0],size:"sm"})," ",(()=>{const a=D.indexOf("/"),S=D.slice(0,a),se=D.slice(a+1);return _e.find(Re=>Re.provider===S&&Re.id===se)?.name||D})()]}):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})]}),ee.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:[ee.length," skill",ee.length!==1?"s":""," selected"]})]})]}),pe&&e.jsx("p",{className:"agent-dialog-error",children:pe})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[f>0&&e.jsx("button",{className:"btn",onClick:()=>j(a=>a-1),disabled:Ne,children:"Back"}),e.jsx("button",{className:"btn",onClick:we,disabled:Ne,children:"Cancel"}),f<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>j(a=>a+1),disabled:f===0&&!y.trim()&&!re,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void lt(),disabled:Ne||!y.trim(),children:Ne?"Creating...":"Create"})]})]}),e.jsx(Ia,{isOpen:oe,onClose:()=>G(!1),onGenerated:U,projectId:g}),e.jsx(ba,{isOpen:ce,onClose:()=>xe(!1),onUseDraft:a=>{d?.(a),d||Qe(a),xe(!1)},projectId:g,existingAgents:o,mode:"create"})]}),document.body)}function za(n){const r=n.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!r)throw new Error("Missing YAML frontmatter delimiters (---)");const x=r[1].split(/\r?\n/),g=r[2]??"",h={name:""},b=[];let o=!1;for(const d of x){const j=d.trimEnd().trim();if(!j)continue;if(j.startsWith("skills:")){o=!0;continue}if(o&&j.startsWith("- ")){b.push(j.slice(2).trim());continue}o=!1;const[k,...$]=j.split(":"),w=$.join(":").trim().replace(/^['"]|['"]$/g,"");k==="name"&&(h.name=w),k==="title"&&(h.title=w),k==="icon"&&(h.icon=w),k==="role"&&(h.role=w),k==="reportsTo"&&(h.reportsTo=w)}if(!h.name)throw new Error("Missing required field: name");return b.length>0&&(h.skills=b),g.trim().length>0&&(h.instructionBody=g),h}function Oa({isOpen:n,onClose:r,onImported:x,projectId:g,initialInputMethod:h="paste"}){gs(n);const[b,o]=s.useState("input"),[d,f]=s.useState(h),[j,k]=s.useState(""),[$,y]=s.useState([]),[w,E]=s.useState("Unknown"),[P,W]=s.useState([]),[T,L]=s.useState([]),[v,z]=s.useState([]),[F,q]=s.useState([]),[je,le]=s.useState(!1),[V,ne]=s.useState(!1),[ie,O]=s.useState(null),[N,ge]=s.useState(null),[he,A]=s.useState(null),Z=s.useRef(null),re=s.useRef(null),[Ee,ee]=s.useState([]),[te,Ne]=s.useState(""),[K,pe]=s.useState(null),[Se,oe]=s.useState(!1),[G,ce]=s.useState(null),xe=s.useRef(!1);s.useEffect(()=>{d==="browse"&&!xe.current&&!Se&&(xe.current=!0,oe(!0),ce(null),Zt().then(i=>{i.error?ce(i.error):i.companies.length>0?ee(i.companies):ce("No companies available")}).catch(i=>{ce(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{oe(!1)}))},[d,Se]);const _e=s.useCallback(()=>{xe.current=!0,ce(null),ee([]),pe(null),oe(!0),Zt().then(i=>{i.error?ce(i.error):i.companies.length>0?ee(i.companies):ce("No companies available")}).catch(i=>{ce(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{oe(!1)})},[]),ze=s.useCallback(()=>{o("input"),f(h),k(""),y([]),E("Unknown"),W([]),L([]),z([]),q([]),le(!1),ne(!1),O(null),ge(null),A(null),ee([]),Ne(""),pe(null),oe(!1),ce(null),xe.current=!1},[h]),Ae=s.useCallback(()=>{ze(),r()},[ze,r]),Oe=s.useCallback(i=>{const p=i.target.files?.[0];if(!p)return;const I=new FileReader;I.onload=J=>{const D=J.target?.result;f("file"),y([]),k(D),O(null)},I.onerror=()=>{O("Failed to read file")},I.readAsText(p),i.target.value=""},[]),be=s.useCallback(async i=>{const p=Array.from(i.target.files??[]);if(p.length!==0)try{const I=p.filter(D=>(D.webkitRelativePath||D.name).toLowerCase().endsWith("agents.md")).sort((D,U)=>{const De=D.webkitRelativePath||D.name,He=U.webkitRelativePath||U.name;return De.localeCompare(He)});if(I.length===0){O("Selected directory has no AGENTS.md files");return}const J=[];for(const D of I){const U=await D.text();J.push(za(U))}f("directory"),y(J),k(""),O(null)}catch{O("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function $e(i){if(!g)return`/api${i}`;const p=i.includes("?")?"&":"?";return`/api${i}${p}projectId=${encodeURIComponent(g)}`}const ve=s.useCallback(async()=>{if(d==="directory"&&$.length===0){O("Please select a directory containing AGENTS.md files");return}if(d==="browse"&&!K){O("Please select a company from the catalog");return}if(d!=="directory"&&d!=="browse"&&!j.trim()){O("Please provide manifest content");return}le(!0),O(null);try{let i;d==="directory"?i={agents:$,dryRun:!0}:d==="browse"&&K?i={importSource:"companies.sh",companySlug:K.slug,dryRun:!0}:i={manifest:j,dryRun:!0};const p=await fetch($e("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!p.ok){const U=await p.json();throw new Error(U.error??`Parse failed (${p.status})`)}const I=await p.json(),J=I.agents&&I.agents.length>0?I.agents:I.created.map(U=>({name:U,role:"custom"})),D=Array.isArray(I.skills)?I.skills:[];E(I.companyName??"Unknown"),W(J),L(D),z(J.map(U=>U.name)),q(D.map(U=>U.name)),o("preview")}catch(i){O(i instanceof Error?i.message:"Failed to parse manifest")}finally{le(!1)}},[d,$,j,K,g]),Le=s.useCallback(async()=>{ne(!0),A(null);try{let i;d==="directory"?i={agents:$,skipExisting:!0,selectedAgents:v,selectedSkills:F}:d==="browse"&&K?i={importSource:"companies.sh",companySlug:K.slug,skipExisting:!0,selectedAgents:v,selectedSkills:F}:i={manifest:j,skipExisting:!0,selectedAgents:v,selectedSkills:F};const p=await fetch($e("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!p.ok){const J=await p.json();throw new Error(J.error??`Import failed (${p.status})`)}const I=await p.json();ge(I),o("result"),x()}catch(i){A(i instanceof Error?i.message:"Failed to import agents")}finally{ne(!1)}},[d,$,j,K,v,F,g,x]),M=v.length,_=F.length,ye=`${M} Agent${M!==1?"s":""}`,ke=`${_} Skill${_!==1?"s":""}`,Pe=M>0&&_>0?`${ye} + ${ke}`:_>0?ke:ye,de=M>0&&_>0?`Importing ${M} agent${M!==1?"s":""} and ${_} skill${_!==1?"s":""}...`:_>0?`Importing ${_} skill${_!==1?"s":""}...`:`Importing ${M} agent${M!==1?"s":""}...`,Ie=i=>{z(p=>p.includes(i)?p.filter(I=>I!==i):[...p,i])},Te=i=>{q(p=>p.includes(i)?p.filter(I=>I!==i):[...p,i])};return n?e.jsx("div",{className:"agent-dialog-overlay",onClick:i=>{i.target===i.currentTarget&&Ae()},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:Ae,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[b==="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:Z,type:"file",accept:".md,.txt",onChange:Oe,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:re,type:"file",webkitdirectory:"",multiple:!0,onChange:be,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>Z.current?.click(),children:[e.jsx(It,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>re.current?.click(),children:[e.jsx(fa,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{f("browse"),y([]),k(""),pe(null),O(null)},children:[e.jsx(Us,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),d==="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(Ys,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:te,onChange:i=>Ne(i.target.value),"aria-label":"Search companies"})]}),K&&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:K.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>pe(null),children:"Change"})]})]}),Se&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(kt,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),G&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(wt,{size:16}),e.jsx("span",{children:G}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:_e,children:[e.jsx(Ze,{size:14}),"Retry"]})]}),!Se&&!G&&e.jsxs("div",{className:"agent-import-browse-list",children:[Ee.filter(i=>te===""||i.name.toLowerCase().includes(te.toLowerCase())||(i.tagline?.toLowerCase().includes(te.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${K?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>pe(i),role:"button",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&pe(i)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:i.name}),i.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[i.installs.toLocaleString()," installs"]})]}),i.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:i.tagline}),i.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:i.repo})]},i.slug)),Ee.filter(i=>te===""||i.name.toLowerCase().includes(te.toLowerCase())||(i.tagline?.toLowerCase().includes(te.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:te?"No companies match your search":"No companies available"})]})]}),d!=="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:j,onChange:i=>{f("paste"),y([]),k(i.target.value),O(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",d]}),ie&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ct,{size:14}),ie]})]}),b==="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(_t,{size:14}),e.jsxs("span",{children:[P.length," agent",P.length!==1?"s":""," found"]})]}),P.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>F(P.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>F([]),children:"Clear agents"})]}),P.length>0?e.jsx("div",{className:"agent-import-agent-list",children:P.map((i,p)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:v.includes(i.name),onChange:()=>Ie(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},p))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),T.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(_t,{size:14}),e.jsxs("span",{children:[T.length," skill",T.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>q(T.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>q([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:T.map((i,p)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:z.includes(i.name),onChange:()=>Te(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${p}`))})]}),he&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ct,{size:14}),he]})]}),b==="result"&&N&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(pt,{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:N.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[N.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[N.created.length," created"]})}),N.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[N.skipped.length," skipped (already exist)"]})}),N.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[N.errors.length," error",N.errors.length!==1?"s":""]})})]}),N.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:N.created.map((i,p)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(pt,{size:12}),e.jsx("span",{children:i.name})]},p))}),N.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.errors.map((i,p)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Jt,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},p))}),N.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:[N.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[N.skills.imported.length," skill",N.skills.imported.length!==1?"s":""," imported"]})}),N.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[N.skills.skipped.length," skill",N.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),N.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[N.skills.errors.length," skill",N.skills.errors.length!==1?"s":""," error",N.skills.errors.length!==1?"s":""]})}),N.skills.imported.length===0&&N.skills.skipped.length===0&&N.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"})})]}),N.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:N.skills.imported.map((i,p)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(pt,{size:12}),e.jsx("span",{children:i.name})]},p))}),N.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.skills.errors.map((i,p)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Jt,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},p))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[b==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:V,children:"Back"}),e.jsx("button",{className:"btn",onClick:Ae,disabled:V,children:b==="result"?"Close":"Cancel"}),b==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ve(),disabled:je||(d==="directory"?$.length===0:d==="browse"?!K:!j.trim()),children:je?e.jsxs(e.Fragment,{children:[e.jsx(kt,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),b==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void Le(),disabled:V||M===0&&_===0,children:V?e.jsxs(e.Fragment,{children:[e.jsx(kt,{size:14,className:"spin"}),de]}):`Import ${Pe}`})]})]})}):null}const $t="fn-agent-org-chart-layout";function ds(n){return n==="auto"||n==="horizontal"||n==="vertical"}const Da=768,Ha={nodeWidth:220,siblingGap:24,rootGap:24,chartPadding:24},Ba={nodeWidth:160,siblingGap:8,rootGap:8,chartPadding:8};function hs(n){return n.children.length===0?1:n.children.reduce((r,x)=>r+hs(x),0)}function Wa(n){return n<=Da?Ba:Ha}function Ga(n,r){const x=hs(n);return x*r.nodeWidth+Math.max(0,x-1)*r.siblingGap}function Va(n,r=Number.POSITIVE_INFINITY){const x=Wa(r);if(n.length===0)return x.nodeWidth;const h=n.map(o=>Ga(o,x)).reduce((o,d)=>o+d,0),b=Math.max(0,n.length-1)*x.rootGap;return h+b+x.chartPadding*2}function Ka(n){const r=n.preference??"auto";if(r!=="auto")return r;const x=Number.isFinite(n.availableWidth)&&n.availableWidth>0?n.availableWidth:0;return x===0||n.tree.length<=1?"horizontal":Va(n.tree,x)>x?"vertical":"horizontal"}const us=s.lazy(()=>ca(()=>import("./AgentDetailView-BACu9GYE.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(n=>({default:n.AgentDetailView}))),Tt=[{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],Ua=.25,Ya=3,ht=16,qe=32;function zt(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 Ft(n,r){switch(r){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 ps(n){return n.children.length===0?1:n.children.reduce((r,x)=>r+ps(x),0)}function Ot(n,r){return n.state==="error"?{title:void 0,label:"Error"}:{title:r.reason??r.label,label:r.stateDerived?null:r.label}}function xs({node:n,onSelect:r,getHealthStatus:x,selectedAgentId:g,registerNodeElement:h,linksRef:b}){const{agent:o,children:d}=n,f=x(o),j=Ot(o,f),k=zt(o.state),$=Ft("org-chart-node-card",o.state),y=ps(n),w={"--org-chart-subtree-leaves":String(y)};return e.jsxs("div",{className:`org-chart-node${d.length>0?" org-chart-node--has-children":""}`,style:w,children:[e.jsxs("div",{ref:E=>h(o.id,E),"data-agent-id":o.id,className:`org-chart-node-card ${$}${g===o.id?" agent-card--selected":""}`,onClick:()=>r(o.id),role:"button",tabIndex:0,onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.key===" "&&E.preventDefault(),r(o.id))},children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:e.jsx(xt,{agent:o,size:20})}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${k}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:f.color},title:j.title,children:[f.icon,j.label&&e.jsx("span",{className:"text-secondary",children:j.label})]})]})]}),d.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:d.map(E=>(b.current.push({parentId:o.id,childId:E.agent.id}),e.jsx(xs,{node:E,onSelect:r,getHealthStatus:x,selectedAgentId:g,registerNodeElement:h,linksRef:b},E.agent.id)))})]})}function Xa({links:n,nodeElements:r,canvasRef:x,viewportRef:g,layoutMode:h,transform:b}){const[o,d]=s.useState([]);return s.useLayoutEffect(()=>{const f=x.current,j=g.current;if(!f||!j||n.length===0){d([]);return}const k=()=>{const y=f.getBoundingClientRect(),w=n.flatMap(({parentId:E,childId:P})=>{const B=r.get(E),T=r.get(P);if(!B||!T)return[];const L=B.getBoundingClientRect(),v=T.getBoundingClientRect(),F=(L.left-y.left)/b.scale,z=(L.top-y.top)/b.scale,q=(v.left-y.left)/b.scale,je=(v.top-y.top)/b.scale;if(h==="vertical"){const N=F,ge=z+L.height/b.scale/2,he=q,A=je+v.height/b.scale/2,Z=N-(N-he)/2;return[`M ${N} ${ge} L ${Z} ${ge} L ${Z} ${A} L ${he} ${A}`]}const le=F+L.width/b.scale/2,V=z+L.height/b.scale,ne=q+v.width/b.scale/2,ie=je,O=V+(ie-V)/2;return[`M ${le} ${V} L ${le} ${O} L ${ne} ${O} L ${ne} ${ie}`]});d(w)};k();const $=new ResizeObserver(k);return $.observe(f),$.observe(j),r.forEach(y=>$.observe(y)),()=>$.disconnect()},[x,h,n,r,b.scale,g]),e.jsx("svg",{className:"agent-org-chart-connectors","aria-hidden":"true",children:o.map((f,j)=>e.jsx("path",{d:f},`${j}-${f}`))})}function an({addToast:n,projectId:r,onOpenTaskLogs:x,agentOnboardingEnabled:g=!1}){const[h,b]=s.useState(!1),d=Xs()==="mobile",[f,j]=s.useState("all"),{agents:k,stats:$,isLoading:y,loadAgents:w,refreshAgents:E}=qs(r,{filterState:f,showSystemAgents:h}),[P,B]=s.useState(!1),[T,L]=s.useState(null),[v,F]=s.useState(!1),[z,q]=s.useState(null),[je,le]=s.useState(null),V=d&&!!z,[ne,ie]=s.useState("dashboard"),[O,N]=s.useState(null),[ge,he]=s.useState(!1),[A,Z]=s.useState(()=>{if(typeof window>"u")return"list";const t=ut("fn-agent-view",r);return t==="list"||t==="board"||t==="org"?t:"list"}),[re,Ee]=s.useState(()=>{if(typeof window>"u")return"auto";const t=ut($t,r);return ds(t)?t:"auto"}),[ee,te]=s.useState([]),[Ne,K]=s.useState(!1),[pe,Se]=s.useState(0),[oe,G]=s.useState(!1),[ce,xe]=s.useState(!1),[_e,Fe]=s.useState(!1),[Ae,Oe]=s.useState(!1),[be,$e]=s.useState(0),[ve,Le]=s.useState(0),[M,_]=s.useState({scale:1,x:0,y:0}),[ye,ke]=s.useState(!1),Pe=s.useRef(null),de=s.useRef(null),Ie=s.useRef(null),Te=s.useRef(new Map),i=s.useRef([]),p=s.useRef(new Map),I=s.useRef(null),J=s.useRef(null),D=s.useRef(!1),{confirm:U}=Zs(),De=s.useRef(null),He=s.useId();s.useEffect(()=>{const t=ut("fn-agent-view",r);if(t==="list"||t==="board"||t==="org"){Z(t);return}Z("list")},[r]),s.useEffect(()=>{Qt("fn-agent-view",A,r)},[A,r]),s.useEffect(()=>{const t=ut($t,r);Ee(ds(t)?t:"auto")},[r]),s.useEffect(()=>{Qt($t,re,r)},[re,r]);const[vt,ze]=s.useState(null),ft=s.useRef(null),[Qe,Ce]=s.useState(null),[lt,Me]=s.useState(null),[Be,we]=s.useState({}),[We,et]=s.useState(1),[a,S]=s.useState(!1),[se,ue]=s.useState(new Set),[Re,Ue]=s.useState(new Map),it=s.useRef(!0);s.useEffect(()=>(it.current=!0,()=>{it.current=!1}),[]),s.useEffect(()=>{Js(r).then(t=>{it.current&&et(t.heartbeatMultiplier??1)}).catch(()=>{})},[r]);const Dt=s.useCallback(async t=>{const l=Number.isFinite(t)&&t>0?t:1;et(l),S(!0);try{await Qs({heartbeatMultiplier:l},r),n(`Heartbeat speed set to ×${l.toFixed(1)}`,"success")}catch(c){n(`Failed to save heartbeat multiplier: ${fe(c)}`,"error")}finally{it.current&&S(!1)}},[r,n]),rt=s.useMemo(()=>Re.size===0?k:k.map(t=>{const l=Re.get(t.id);return l?{...t,state:l}:t}),[k,Re]),tt=s.useMemo(()=>rt.filter(t=>h||!nt(t)),[rt,h]),bs=s.useMemo(()=>rt.filter(t=>t.state!=="active"&&t.state!=="running"?!1:h||!nt(t)),[rt,h]),Ge=s.useMemo(()=>{if(h)return ee;const t=l=>nt(l.agent)?null:{...l,children:l.children.map(t).filter(c=>c!==null)};return ee.map(t).filter(l=>l!==null)},[ee,h]);s.useEffect(()=>{if(A!=="org")return;const t=de.current;if(!t)return;const l=()=>{Se(t.clientWidth)};l();const c=typeof ResizeObserver<"u"?new ResizeObserver(l):null;return c?.observe(t),window.addEventListener("resize",l),()=>{c?.disconnect(),window.removeEventListener("resize",l)}},[A,Ge.length]),s.useEffect(()=>{if(A!=="org")return;let t=!1;return K(!0),ea(r,{includeEphemeral:h}).then(l=>{t||te(l)}).catch(l=>{t||(n(`Failed to load org chart: ${fe(l)}`,"error"),te([]))}).finally(()=>{t||K(!1)}),()=>{t=!0}},[A,r,h,n]),s.useEffect(()=>{const t=setInterval(()=>{w()},3e4);return()=>{clearInterval(t)}},[w]),s.useEffect(()=>{if(!oe)return;let t=!1;Oe(!0),Pt(void 0,r).then(u=>{if(t)return;const C=u.filter(R=>!nt(R));$e(C.filter(R=>R.state==="active"||R.state==="running").length),Le(C.filter(R=>R.state==="paused").length)}).catch(u=>{t||($e(0),Le(0),n(`Failed to load bulk agent actions: ${fe(u)}`,"error"))}).finally(()=>{t||Oe(!1)});const l=u=>{const C=u.target;C&&(Pe.current?.contains(C)||De.current?.contains(C)||G(!1))},c=u=>{u.key==="Escape"&&(G(!1),De.current?.focus())};return document.addEventListener("mousedown",l),document.addEventListener("touchstart",l),document.addEventListener("keydown",c),()=>{t=!0,document.removeEventListener("mousedown",l),document.removeEventListener("touchstart",l),document.removeEventListener("keydown",c)}},[n,oe,r]);const Ht=async t=>{if(!_e){Fe(!0);try{const c=(await Pt(void 0,r)).filter(W=>!nt(W)),u=c.filter(W=>t==="paused"?W.state==="active"||W.state==="running":W.state==="paused"),C=c.length-u.length;if(u.length===0){n(`No agents eligible to ${t==="paused"?"pause":"resume"}`,"error");return}if(!await U({title:t==="paused"?"Pause All Agents":"Resume All Agents",message:`${t==="paused"?"Pause":"Resume"} ${u.length} agent${u.length===1?"":"s"} in this project?`,danger:t==="paused"}))return;const ae=await Promise.allSettled(u.map(W=>as(W.id,t,r))),Q=ae.map((W,dt)=>({result:W,agent:u[dt]})).filter(W=>W.result.status==="rejected"),m=ae.length-Q.length,H=Q.length,X=`${t==="paused"?"Paused":"Resumed"} ${m} agent${m===1?"":"s"}; skipped ${C}`;if(H>0){const W=Q.slice(0,3).map(({agent:dt,result:Ps})=>`${dt.name||dt.id}: ${fe(Ps.reason)}`).join("; ");n(`${X}; failed ${H}${W?` (${W})`:""}`,"error")}else n(X,"success");await w()}catch(l){n(`Failed to ${t==="paused"?"pause":"resume"} agents: ${fe(l)}`,"error")}finally{Fe(!1)}}},st=async(t,l)=>{if(!se.has(t)){ue(c=>new Set(c).add(t)),Ue(c=>{const u=new Map(c);return u.set(t,l),u});try{await as(t,l,r),n(`Agent state updated to ${l}`,"success"),await w(),Ue(c=>{const u=new Map(c);return u.delete(t),u})}catch(c){Ue(u=>{const C=new Map(u);return C.delete(t),C}),n(`Failed to update state: ${fe(c)}`,"error")}finally{ue(c=>{const u=new Set(c);return u.delete(t),u})}}},vs=async(t,l)=>{if(await U({title:"Delete Agent",message:`Delete agent "${l}"? This cannot be undone.`,danger:!0}))try{await ga(t,r),n(`Agent "${l}" deleted`,"success"),await w()}catch(u){n(`Failed to delete agent: ${fe(u)}`,"error")}},fs=async(t,l)=>{const c=k.find(u=>u.id===t);if(c){if(c.role===l){ze(null);return}try{await gt(t,{role:l},r),n(`Agent role updated to ${Tt.find(u=>u.value===l)?.label??l}`,"success"),ze(null),w()}catch(u){n(`Failed to update role: ${fe(u)}`,"error")}}},js=(t,l)=>{t.key==="Escape"&&ze(null)},Ns=async(t,l)=>{lt===t.id&&(Me(null),we(c=>{const u={...c};return delete u[t.id],u})),Ce(t.id);try{await gt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:l}},r),n(`Heartbeat interval updated to ${ns(l)} for ${t.name}`,"success"),w()}catch(c){n(`Failed to update heartbeat interval: ${fe(c)}`,"error")}finally{Ce(null)}},Bt=async t=>{const l=Be[t.id]??"";if(l.trim()===""){n("Please enter a heartbeat interval in minutes","error");return}const c=Number(l);if(isNaN(c)){n("Heartbeat interval must be a valid number","error");return}if(c<=0){n("Heartbeat interval must be greater than 0","error");return}if(c>=1&&c<5){Ce(t.id);try{await gt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:ua}},r),n(`Heartbeat interval set to 5 minutes (minimum). ${c} minute${c!==1?"s":""} was below the 5-minute minimum.`,"success"),Me(null),we(C=>{const R={...C};return delete R[t.id],R}),w()}catch(C){n(`Failed to update heartbeat interval: ${fe(C)}`,"error")}finally{Ce(null)}return}const u=Math.round(c*6e4);Ce(t.id);try{await gt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:u}},r),n(`Heartbeat interval updated to ${ns(u)} for ${t.name}`,"success"),Me(null),we(C=>{const R={...C};return delete R[t.id],R}),w()}catch(C){n(`Failed to update heartbeat interval: ${fe(C)}`,"error")}finally{Ce(null)}},ys=t=>{const l=Et(t.runtimeConfig?.heartbeatIntervalMs),c=Math.round(l/6e4);Me(t.id),we(u=>({...u,[t.id]:String(c)}))},me=s.useCallback((t,l)=>{q(t),ie(l?.initialTab??"dashboard"),N(l?.initialRunId??null),he(l?.preferActiveRun??!1)},[]),Ve=s.useCallback(()=>{q(null),ie("dashboard"),N(null),he(!1)},[]),Wt=s.useCallback(t=>{me(t)},[me]),ks=s.useCallback(t=>{le(t),me(t)},[me]),Cs=s.useCallback(async({agentId:t,deleted:l})=>{await E(),l&&z===t&&Ve()},[E,z,Ve]),ws=s.useCallback(t=>{me(t),d&&xe(!1)},[d,me]),Ss=async(t,l)=>{Ue(c=>{const u=new Map(c);return u.set(t,"running"),u});try{await ma(t,r,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),n(`Heartbeat run started for ${l}`,"success"),await w(),Ue(c=>{const u=new Map(c);return u.delete(t),u})}catch(c){Ue(u=>{const C=new Map(u);return C.delete(t),C}),n(`Failed to start heartbeat run: ${fe(c)}`,"error")}},Ke=s.useCallback(t=>Math.min(Ya,Math.max(Ua,t)),[]),Y=s.useCallback(t=>{const l=de.current,c=Ie.current?.querySelector(".agent-org-chart");if(!l||!c)return{...t,scale:Ke(t.scale)};const u=Ke(t.scale),C=c.scrollWidth*u,R=c.scrollHeight*u,ae=l.clientWidth,Q=l.clientHeight,m=Math.min(qe,ae-C-qe),H=qe,X=Math.min(qe,Q-R-qe),W=qe;return{scale:u,x:Math.max(m,Math.min(H,t.x)),y:Math.max(X,Math.min(W,t.y))}},[Ke]),ot=s.useCallback((t,l,c)=>{const u=de.current;u&&_(C=>{const R=Ke(t),ae=u.getBoundingClientRect(),Q=l-ae.left,m=c-ae.top,H=(Q-C.x)/C.scale,X=(m-C.y)/C.scale;return Y({scale:R,x:Q-H*R,y:m-X*R})})},[Ke,Y]),Ye=s.useCallback(()=>{const t=de.current,l=Ie.current?.querySelector(".agent-org-chart");if(!t||!l)return;const c=t.clientWidth,u=t.clientHeight,C=l.scrollWidth,R=l.scrollHeight;if(C<=0||R<=0)return;const ae=Ke(Math.min(c/C,u/R,1)),Q=(c-C*ae)/2,m=(u-R*ae)/2;_(Y({scale:ae,x:Q,y:m}))},[Ke,Y]),jt=s.useCallback(t=>{Z(t),t!=="org"&&_({scale:1,x:0,y:0}),d&&z&&Ve()},[Ve,d,z]),Gt=t=>Tt.find(l=>l.value===t)?.label??t,ct=s.useMemo(()=>Ka({tree:Ge,availableWidth:pe,preference:re}),[Ge,re,pe]),Vt=s.useCallback(t=>{Ee(t),_({scale:1,x:0,y:0})},[]);s.useEffect(()=>{_({scale:1,x:0,y:0}),D.current=!1},[r,ct]),s.useLayoutEffect(()=>{A!=="org"||Ne||Ge.length===0||D.current||(Ye(),D.current=!0)},[A,Ge.length,Ye,Ne]);const As=s.useCallback((t,l)=>{l?Te.current.set(t,l):Te.current.delete(t)},[]),Kt=s.useCallback(()=>e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>_(t=>Y({...t,scale:t.scale*.9})),"aria-label":"Zoom out org chart",title:"Zoom out",children:e.jsx(Aa,{size:16})}),e.jsxs("span",{className:"agent-org-chart-controls__zoom-label","aria-live":"polite",children:[Math.round(M.scale*100),"%"]}),e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>_(t=>Y({...t,scale:t.scale*1.1})),"aria-label":"Zoom in org chart",title:"Zoom in",children:e.jsx(wa,{size:16})}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm agent-org-chart-controls__fit-btn",onClick:Ye,"aria-label":"Fit org chart",title:"Fit org chart",children:[e.jsx(ta,{size:16}),"Fit"]}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm",onClick:()=>_(t=>Y({...t,x:0,y:0})),"aria-label":"Center org chart",title:"Center org chart",children:[e.jsx(sa,{size:16}),"Center"]})]}),[Y,Ye,M.scale]),Rs=s.useCallback(t=>{if(!(t.ctrlKey||t.metaKey))return;t.preventDefault();const l=t.deltaY>0?.9:1.1;ot(M.scale*l,t.clientX,t.clientY)},[M.scale,ot]),$s=s.useCallback(t=>{if(t.target.closest(".org-chart-node-card"))return;if(t.currentTarget.setPointerCapture?.(t.pointerId),p.current.set(t.pointerId,{x:t.clientX,y:t.clientY}),p.current.size===1){I.current={x:t.clientX-M.x,y:t.clientY-M.y,pointerId:t.pointerId},ke(!0);return}if(p.current.size===2){const c=Array.from(p.current.values()),u=c[0].x-c[1].x,C=c[0].y-c[1].y;J.current={distance:Math.hypot(u,C),scale:M.scale,centerX:(c[0].x+c[1].x)/2,centerY:(c[0].y+c[1].y)/2},I.current=null}},[M.scale,M.x,M.y]),Ts=s.useCallback(t=>{if(p.current.has(t.pointerId)){if(p.current.set(t.pointerId,{x:t.clientX,y:t.clientY}),p.current.size>=2){const l=Array.from(p.current.values()),c=J.current;if(!c)return;const u=l[0].x-l[1].x,C=l[0].y-l[1].y,R=Math.hypot(u,C),ae=c.scale*(R/c.distance);ot(ae,c.centerX,c.centerY);return}!I.current||I.current.pointerId!==t.pointerId||_(l=>Y({...l,x:t.clientX-I.current.x,y:t.clientY-I.current.y}))}},[Y,ot]),Ut=s.useCallback(t=>{p.current.delete(t.pointerId),p.current.size<2&&(J.current=null),p.current.size===0&&(I.current=null,ke(!1))},[]),Ms=s.useCallback(t=>{if(t.key==="ArrowLeft")_(l=>Y({...l,x:l.x+ht}));else if(t.key==="ArrowRight")_(l=>Y({...l,x:l.x-ht}));else if(t.key==="ArrowUp")_(l=>Y({...l,y:l.y+ht}));else if(t.key==="ArrowDown")_(l=>Y({...l,y:l.y-ht}));else if(t.key==="+"||t.key==="=")_(l=>Y({...l,scale:l.scale*1.1}));else if(t.key==="-")_(l=>Y({...l,scale:l.scale*.9}));else if(t.key==="0")Ye();else if(t.key==="Home")_({scale:1,x:0,y:0});else return;t.preventDefault()},[Y,Ye]),Yt=s.useCallback(()=>{const t=[{value:"horizontal",label:"Horizontal",icon:e.jsx(ts,{size:16}),ariaLabel:"Horizontal layout"},{value:"vertical",label:"Vertical",icon:e.jsx(es,{size:16}),ariaLabel:"Vertical layout"},{value:"auto",label:"Auto",icon:e.jsx(Ze,{size:16}),ariaLabel:"Automatic layout"}];return e.jsx("div",{className:"agent-org-chart-layout-toggle","data-testid":"agent-org-chart-layout-toggle",children:t.map(l=>{const c=re===l.value;return e.jsxs("button",{type:"button",className:`btn-icon touch-target agent-org-chart-layout-toggle__button${c?" btn-icon--active":""}`,onClick:()=>Vt(l.value),"aria-pressed":c,"aria-label":l.ariaLabel,title:l.ariaLabel,"data-layout-value":l.value,children:[l.icon,e.jsx("span",{className:"agent-org-chart-layout-toggle__text",children:l.label})]},l.value)})})},[Vt,re]),Es=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],Nt=t=>da(t),_s=Ae||_e||be===0,Ls=Ae||_e||ve===0,Xt=y&&k.length===0,at=s.useCallback(()=>{B(!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(Lt,{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:()=>jt("list"),title:"List view","aria-label":"List view","aria-pressed":A==="list",children:e.jsx(es,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="board"?" active":""}`,onClick:()=>jt("board"),title:"Board view","aria-label":"Board view","aria-pressed":A==="board",children:e.jsx(Je,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="org"?" active":""}`,onClick:()=>jt("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":A==="org",children:e.jsx(ts,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:De,className:`btn-icon agent-controls-trigger${oe?" agent-controls-trigger--active":""}`,onClick:()=>G(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":oe,"aria-controls":He,children:e.jsx(ka,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void w(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Ze,{size:16,className:y?"spin":void 0})}),!d&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{F(!0),G(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(It,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{at(),G(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(ss,{size:16}),"New Agent"]})]}),oe&&e.jsxs("div",{ref:Pe,id:He,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(aa,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:f,onChange:t=>j(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:h,onChange:t=>b(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]})}),d&&e.jsxs("div",{className:"agent-controls-mobile-actions",children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{F(!0),G(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(It,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{at(),G(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(ss,{size:16}),"New Agent"]})]}),e.jsxs("div",{className:"agent-controls-bulk-actions",role:"menu","aria-label":"Bulk agent actions",children:[e.jsxs("button",{type:"button",className:"agent-detail-bulk-menu-item",role:"menuitem",disabled:_s,onClick:()=>{G(!1),Ht("paused")},children:[e.jsxs("span",{className:"agent-controls-bulk-actions__label",children:[e.jsx(wt,{}),e.jsx("span",{children:"Pause All Agents"})]}),e.jsx("span",{className:"agent-detail-bulk-menu-item-hint",children:Ae?"Loading eligibility…":be===0?"No active or running project agents to pause":`Pause ${be} active/running agent${be===1?"":"s"}`})]}),e.jsxs("button",{type:"button",className:"agent-detail-bulk-menu-item",role:"menuitem",disabled:Ls,onClick:()=>{G(!1),Ht("active")},children:[e.jsxs("span",{className:"agent-controls-bulk-actions__label",children:[e.jsx(mt,{}),e.jsx("span",{children:"Resume All Agents"})]}),e.jsx("span",{className:"agent-detail-bulk-menu-item-hint",children:Ae?"Loading eligibility…":ve===0?"No paused project agents to resume":`Resume ${ve} paused agent${ve===1?"":"s"}`})]})]}),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:We,onChange:t=>{const l=Number(t.target.value);Dt(Number.isFinite(l)&&l>0?l:1)},disabled:a}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",We.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Mt.reduce((t,l)=>Math.abs(l-We)<Math.abs(t-We)?l:t,Mt[0])),onChange:t=>{const l=Number(t.target.value);Dt(Number.isFinite(l)&&l>0?l:1)},disabled:a,"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(Ra,{agents:tt})]})]})]})]}),e.jsx(za,{isOpen:P,onClose:()=>{B(!1),L(null)},onCreated:()=>{B(!1),L(null),w()},projectId:r,prefillDraft:T,agentOnboardingEnabled:g,existingAgents:k,onPrefillDraft:L}),e.jsx(Oa,{isOpen:v,onClose:()=>F(!1),onImported:()=>void w(),projectId:r}),e.jsx(Pa,{stats:$,activeAgents:bs,projectId:r,isOpen:ce,onToggle:()=>xe(t=>!t),onSelectAgent:ws,onOpenTaskLogs:x}),A==="org"?e.jsx("div",{className:"agents-org-full-view",children:e.jsx("div",{className:"agents-view-content agents-view-content--org-full",children:z?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:Ve,"aria-label":"Back to org chart",children:"Back to org chart"}),e.jsx(s.Suspense,{fallback:null,children:e.jsx(us,{inline:!0,showInlineBackButton:!1,agentId:z,projectId:r,onClose:Ve,addToast:n,onChildClick:Wt,initialTab:ne,initialRunId:O,preferActiveRun:ge},z)})]}):Xt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ze,{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:[d?e.jsxs("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:[Yt(),Kt()]}):e.jsxs("div",{className:"agent-org-chart-toolbar",children:[Yt(),e.jsx("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:Kt()})]}),e.jsx("div",{ref:de,className:"agent-org-chart-viewport","data-testid":"agent-org-chart-viewport",tabIndex:0,role:"region","aria-label":"Org chart canvas",onWheel:Rs,onPointerDown:$s,onPointerMove:Ts,onPointerUp:Ut,onPointerCancel:Ut,onKeyDown:Ms,"data-panning":ye?"true":"false",children:e.jsxs("div",{ref:Ie,className:`agent-org-chart-canvas agent-org-chart-canvas--zoom-${Math.round((M.scale??1)*100)}`,"data-panning":ye?"true":"false",style:{transform:`translate(${M.x}px, ${M.y}px) scale(${M.scale})`},children:[e.jsx("div",{className:`agent-org-chart${ct==="vertical"?" agent-org-chart--vertical":""}`,"data-testid":"agent-org-chart","data-layout-mode":ct,children:Ne?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Ze,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):Ge.length===0?e.jsx(At,{onCtaClick:at}):(i.current=[],Ge.map(t=>e.jsx(xs,{node:t,onSelect:ks,getHealthStatus:Nt,selectedAgentId:je,registerNodeElement:As,linksRef:i},t.agent.id)))}),e.jsx(Xa,{links:i.current,nodeElements:Te.current,canvasRef:Ie,viewportRef:de,layoutMode:ct,transform:M})]})})]})})}):e.jsxs("div",{className:"agents-split-layout",children:[e.jsx("div",{className:`agents-split-sidebar${V?" agents-split-sidebar--hidden-mobile":""}`,children:e.jsx("div",{className:"agents-view-content",children:Xt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ze,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):A==="board"?e.jsx("div",{className:"agent-board",children:tt.length===0?e.jsx(At,{onCtaClick:at}):tt.map(t=>{const l=Nt(t),c=Ot(t,l),u=zt(t.state),C=Ft("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${C}${z===t.id?" agent-card--selected":""}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>me(t.id),role:"button",tabIndex:0,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.key===" "&&R.preventDefault(),me(t.id))},children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:e.jsx(xt,{agent:t,size:20})}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:Gt(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${u}`,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:l.color},title:c.title,children:[l.icon,c.label?` ${c.label}`:""]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:tt.length===0?e.jsx(At,{onCtaClick:at}):tt.map(t=>{const l=Nt(t),c=Ot(t,l),u=zt(t.state),C=Ft("agent-card",t.state),R=Et(t.runtimeConfig?.heartbeatIntervalMs),ae=na(R),Q=Qe===t.id;return e.jsxs("div",{className:`agent-card agent-card--clickable ${C}${z===t.id?" agent-card--selected":""}`,onClick:m=>{const H=m.target;if(H===m.currentTarget){me(t.id);return}const X=H.closest('button, select, input, [role="button"]');X&&X!==m.currentTarget||me(t.id)},role:"button",tabIndex:0,onKeyDown:m=>{m.target===m.currentTarget&&(m.key==="Enter"||m.key===" ")&&(m.key===" "&&m.preventDefault(),me(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:[vt===t.id?e.jsx("select",{ref:ft,className:"select agent-role-select",value:t.role,onChange:m=>void fs(t.id,m.target.value),onKeyDown:m=>js(m,t.id),onBlur:()=>ze(null),autoFocus:!0,children:Tt.map(m=>e.jsxs("option",{value:m.value,children:[m.icon," ",m.label]},m.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:m=>{m.stopPropagation(),ze(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.stopPropagation(),ze(t.id))},children:e.jsx(xt,{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(ms,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${u}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:l.color},title:c.title,children:[l.icon,c.label?` ${c.label}`:""]}),e.jsx("span",{className:"badge text-secondary",children:Gt(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 m=Es(t);if(m.length===0)return null;const H=m.slice(0,2),X=m.length-2;return e.jsxs(e.Fragment,{children:[H.map(W=>e.jsx("span",{className:"badge badge-skill",title:W,children:va(W)},W)),X>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",X]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.state==="error"&&t.lastError?e.jsx(la,{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:"}),lt===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Be[t.id]??"",onChange:m=>we(H=>({...H,[t.id]:m.target.value})),onKeyDown:m=>{m.key==="Enter"?Bt(t):m.key==="Escape"&&(Me(null),we(H=>{const X={...H};return delete X[t.id],X}))},disabled:Q,"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 Bt(t),disabled:Q,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>{Me(null),we(m=>{const H={...m};return delete H[t.id],H})},disabled:Q,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:R,onChange:m=>{const H=m.target.value;H==="__custom__"?ys(t):Ns(t,Number(H))},disabled:Q,"aria-label":`Set heartbeat interval for ${t.name}`,children:[ae.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value)),ia.some(m=>m.value===R)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),Q&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const m=new Date(t.lastHeartbeatAt),H=new Date(m.getTime()+R),X=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:m.toLocaleString(),children:["Last: ",m.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),X&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:H.toLocaleString(),children:["Next: ",H.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--primary",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"active"),disabled:se.has(t.id),title:"Activate",children:[e.jsx(mt,{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 Ss(t.id,t.name),disabled:se.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(Je,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Run Now"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"paused"),disabled:se.has(t.id),title:"Pause",children:[e.jsx(wt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"active"),disabled:se.has(t.id),title:"Resume",children:[e.jsx(mt,{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:()=>me(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(Je,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Running"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"paused"),disabled:se.has(t.id),title:"Pause",children:[e.jsx(wt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"active"),disabled:se.has(t.id),title:"Retry",children:[e.jsx(mt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Retry"})]})]}),e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--secondary",children:[e.jsxs("button",{className:"btn btn-sm agent-card-details-btn",onClick:()=>me(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:[e.jsx(ra,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Details"})]}),(t.state==="idle"||t.state==="paused")&&e.jsxs("button",{className:"btn btn-sm btn-danger",onClick:()=>void vs(t.id,t.name),title:"Delete",children:[e.jsx(oa,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Delete"})]})]})]})]},t.id)})})})}),e.jsx("div",{className:`agents-split-detail${d&&!z?" agents-split-detail--hidden-mobile":""}`,children:z?e.jsx(s.Suspense,{fallback:null,children:e.jsx(us,{inline:!0,showInlineBackButton:d,agentId:z,projectId:r,onClose:Ve,addToast:n,onChildClick:Wt,initialTab:ne,initialRunId:O,preferActiveRun:ge,onMutationSuccess:Cs},z)}):e.jsxs("div",{className:"agents-detail-empty-state",children:[e.jsx(Lt,{size:48}),e.jsx("h3",{children:"Select an agent"}),e.jsx("p",{children:"Choose an agent from the sidebar to view details"})]})})]})]})}export{an as AgentsView};
|
|
29
|
+
Agent instructions go here...`,value:j,onChange:i=>{f("paste"),y([]),k(i.target.value),O(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",d]}),ie&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(wt,{size:14}),ie]})]}),b==="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(_t,{size:14}),e.jsxs("span",{children:[P.length," agent",P.length!==1?"s":""," found"]})]}),P.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>z(P.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>z([]),children:"Clear agents"})]}),P.length>0?e.jsx("div",{className:"agent-import-agent-list",children:P.map((i,p)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:v.includes(i.name),onChange:()=>Ie(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},p))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),T.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(_t,{size:14}),e.jsxs("span",{children:[T.length," skill",T.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>q(T.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>q([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:T.map((i,p)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:F.includes(i.name),onChange:()=>Te(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${p}`))})]}),he&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(wt,{size:14}),he]})]}),b==="result"&&N&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(pt,{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:N.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[N.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[N.created.length," created"]})}),N.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[N.skipped.length," skipped (already exist)"]})}),N.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[N.errors.length," error",N.errors.length!==1?"s":""]})})]}),N.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:N.created.map((i,p)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(pt,{size:12}),e.jsx("span",{children:i.name})]},p))}),N.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.errors.map((i,p)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Jt,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},p))}),N.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:[N.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[N.skills.imported.length," skill",N.skills.imported.length!==1?"s":""," imported"]})}),N.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[N.skills.skipped.length," skill",N.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),N.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[N.skills.errors.length," skill",N.skills.errors.length!==1?"s":""," error",N.skills.errors.length!==1?"s":""]})}),N.skills.imported.length===0&&N.skills.skipped.length===0&&N.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"})})]}),N.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:N.skills.imported.map((i,p)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(pt,{size:12}),e.jsx("span",{children:i.name})]},p))}),N.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.skills.errors.map((i,p)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Jt,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},p))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[b==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:V,children:"Back"}),e.jsx("button",{className:"btn",onClick:Ae,disabled:V,children:b==="result"?"Close":"Cancel"}),b==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ve(),disabled:je||(d==="directory"?$.length===0:d==="browse"?!K:!j.trim()),children:je?e.jsxs(e.Fragment,{children:[e.jsx(kt,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),b==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void Le(),disabled:V||M===0&&_===0,children:V?e.jsxs(e.Fragment,{children:[e.jsx(kt,{size:14,className:"spin"}),de]}):`Import ${Pe}`})]})]})}):null}const $t="fn-agent-org-chart-layout";function ds(n){return n==="auto"||n==="horizontal"||n==="vertical"}const Da=768,Ha={nodeWidth:220,siblingGap:24,rootGap:24,chartPadding:24},Ba={nodeWidth:160,siblingGap:8,rootGap:8,chartPadding:8};function hs(n){return n.children.length===0?1:n.children.reduce((r,x)=>r+hs(x),0)}function Wa(n){return n<=Da?Ba:Ha}function Ga(n,r){const x=hs(n);return x*r.nodeWidth+Math.max(0,x-1)*r.siblingGap}function Va(n,r=Number.POSITIVE_INFINITY){const x=Wa(r);if(n.length===0)return x.nodeWidth;const h=n.map(o=>Ga(o,x)).reduce((o,d)=>o+d,0),b=Math.max(0,n.length-1)*x.rootGap;return h+b+x.chartPadding*2}function Ka(n){const r=n.preference??"auto";if(r!=="auto")return r;const x=Number.isFinite(n.availableWidth)&&n.availableWidth>0?n.availableWidth:0;return x===0||n.tree.length<=1?"horizontal":Va(n.tree,x)>x?"vertical":"horizontal"}const us=s.lazy(()=>ca(()=>import("./AgentDetailView-CFX3jxfA.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(n=>({default:n.AgentDetailView}))),Tt=[{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],Ua=.25,Ya=3,ht=16,qe=32;function Ft(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 zt(n,r){switch(r){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 ps(n){return n.children.length===0?1:n.children.reduce((r,x)=>r+ps(x),0)}function Ot(n,r){return n.state==="error"?{title:void 0,label:"Error"}:{title:r.reason??r.label,label:r.stateDerived?null:r.label}}function xs({node:n,onSelect:r,getHealthStatus:x,selectedAgentId:g,registerNodeElement:h,linksRef:b}){const{agent:o,children:d}=n,f=x(o),j=Ot(o,f),k=Ft(o.state),$=zt("org-chart-node-card",o.state),y=ps(n),w={"--org-chart-subtree-leaves":String(y)};return e.jsxs("div",{className:`org-chart-node${d.length>0?" org-chart-node--has-children":""}`,style:w,children:[e.jsxs("div",{ref:E=>h(o.id,E),"data-agent-id":o.id,className:`org-chart-node-card ${$}${g===o.id?" agent-card--selected":""}`,onClick:()=>r(o.id),role:"button",tabIndex:0,onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&(E.key===" "&&E.preventDefault(),r(o.id))},children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:e.jsx(xt,{agent:o,size:20})}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${k}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:f.color},title:j.title,children:[f.icon,j.label&&e.jsx("span",{className:"text-secondary",children:j.label})]})]})]}),d.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:d.map(E=>(b.current.push({parentId:o.id,childId:E.agent.id}),e.jsx(xs,{node:E,onSelect:r,getHealthStatus:x,selectedAgentId:g,registerNodeElement:h,linksRef:b},E.agent.id)))})]})}function Xa({links:n,nodeElements:r,canvasRef:x,viewportRef:g,layoutMode:h,transform:b}){const[o,d]=s.useState([]);return s.useLayoutEffect(()=>{const f=x.current,j=g.current;if(!f||!j||n.length===0){d([]);return}const k=()=>{const y=f.getBoundingClientRect(),w=n.flatMap(({parentId:E,childId:P})=>{const W=r.get(E),T=r.get(P);if(!W||!T)return[];const L=W.getBoundingClientRect(),v=T.getBoundingClientRect(),z=(L.left-y.left)/b.scale,F=(L.top-y.top)/b.scale,q=(v.left-y.left)/b.scale,je=(v.top-y.top)/b.scale;if(h==="vertical"){const N=z,ge=F+L.height/b.scale/2,he=q,A=je+v.height/b.scale/2,Z=N-(N-he)/2;return[`M ${N} ${ge} L ${Z} ${ge} L ${Z} ${A} L ${he} ${A}`]}const le=z+L.width/b.scale/2,V=F+L.height/b.scale,ne=q+v.width/b.scale/2,ie=je,O=V+(ie-V)/2;return[`M ${le} ${V} L ${le} ${O} L ${ne} ${O} L ${ne} ${ie}`]});d(w)};k();const $=new ResizeObserver(k);return $.observe(f),$.observe(j),r.forEach(y=>$.observe(y)),()=>$.disconnect()},[x,h,n,r,b.scale,g]),e.jsx("svg",{className:"agent-org-chart-connectors","aria-hidden":"true",children:o.map((f,j)=>e.jsx("path",{d:f},`${j}-${f}`))})}function an({addToast:n,projectId:r,onOpenTaskLogs:x,agentOnboardingEnabled:g=!1}){const[h,b]=s.useState(!1),d=Xs()==="mobile",[f,j]=s.useState("all"),{agents:k,stats:$,isLoading:y,loadAgents:w,refreshAgents:E}=qs(r,{filterState:f,showSystemAgents:h}),[P,W]=s.useState(!1),[T,L]=s.useState(null),[v,z]=s.useState(!1),[F,q]=s.useState(null),[je,le]=s.useState(null),V=d&&!!F,[ne,ie]=s.useState("dashboard"),[O,N]=s.useState(null),[ge,he]=s.useState(!1),[A,Z]=s.useState(()=>{if(typeof window>"u")return"list";const t=ut("fn-agent-view",r);return t==="list"||t==="board"||t==="org"?t:"list"}),[re,Ee]=s.useState(()=>{if(typeof window>"u")return"auto";const t=ut($t,r);return ds(t)?t:"auto"}),[ee,te]=s.useState([]),[Ne,K]=s.useState(!1),[pe,Se]=s.useState(0),[oe,G]=s.useState(!1),[ce,xe]=s.useState(!1),[_e,ze]=s.useState(!1),[Ae,Oe]=s.useState(!1),[be,$e]=s.useState(0),[ve,Le]=s.useState(0),[M,_]=s.useState({scale:1,x:0,y:0}),[ye,ke]=s.useState(!1),Pe=s.useRef(null),de=s.useRef(null),Ie=s.useRef(null),Te=s.useRef(new Map),i=s.useRef([]),p=s.useRef(new Map),I=s.useRef(null),J=s.useRef(null),D=s.useRef(!1),{confirm:U}=Zs(),De=s.useRef(null),He=s.useId();s.useEffect(()=>{const t=ut("fn-agent-view",r);if(t==="list"||t==="board"||t==="org"){Z(t);return}Z("list")},[r]),s.useEffect(()=>{Qt("fn-agent-view",A,r)},[A,r]),s.useEffect(()=>{const t=ut($t,r);Ee(ds(t)?t:"auto")},[r]),s.useEffect(()=>{Qt($t,re,r)},[re,r]);const[vt,Fe]=s.useState(null),ft=s.useRef(null),[Qe,we]=s.useState(null),[lt,Me]=s.useState(null),[Be,Ce]=s.useState({}),[We,et]=s.useState(1),[a,S]=s.useState(!1),[se,ue]=s.useState(new Set),[Re,Ue]=s.useState(new Map),it=s.useRef(!0);s.useEffect(()=>(it.current=!0,()=>{it.current=!1}),[]),s.useEffect(()=>{Js(r).then(t=>{it.current&&et(t.heartbeatMultiplier??1)}).catch(()=>{})},[r]);const Dt=s.useCallback(async t=>{const l=Number.isFinite(t)&&t>0?t:1;et(l),S(!0);try{await Qs({heartbeatMultiplier:l},r),n(`Heartbeat speed set to ×${l.toFixed(1)}`,"success")}catch(c){n(`Failed to save heartbeat multiplier: ${fe(c)}`,"error")}finally{it.current&&S(!1)}},[r,n]),rt=s.useMemo(()=>Re.size===0?k:k.map(t=>{const l=Re.get(t.id);return l?{...t,state:l}:t}),[k,Re]),tt=s.useMemo(()=>rt.filter(t=>h||!nt(t)),[rt,h]),bs=s.useMemo(()=>rt.filter(t=>t.state!=="active"&&t.state!=="running"?!1:h||!nt(t)),[rt,h]),Ge=s.useMemo(()=>{if(h)return ee;const t=l=>nt(l.agent)?null:{...l,children:l.children.map(t).filter(c=>c!==null)};return ee.map(t).filter(l=>l!==null)},[ee,h]);s.useEffect(()=>{if(A!=="org")return;const t=de.current;if(!t)return;const l=()=>{Se(t.clientWidth)};l();const c=typeof ResizeObserver<"u"?new ResizeObserver(l):null;return c?.observe(t),window.addEventListener("resize",l),()=>{c?.disconnect(),window.removeEventListener("resize",l)}},[A,Ge.length]),s.useEffect(()=>{if(A!=="org")return;let t=!1;return K(!0),ea(r,{includeEphemeral:h}).then(l=>{t||te(l)}).catch(l=>{t||(n(`Failed to load org chart: ${fe(l)}`,"error"),te([]))}).finally(()=>{t||K(!1)}),()=>{t=!0}},[A,r,h,n]),s.useEffect(()=>{const t=setInterval(()=>{w()},3e4);return()=>{clearInterval(t)}},[w]),s.useEffect(()=>{if(!oe)return;let t=!1;Oe(!0),Pt(void 0,r).then(u=>{if(t)return;const C=u.filter(R=>!nt(R));$e(C.filter(R=>R.state==="active"||R.state==="running").length),Le(C.filter(R=>R.state==="paused").length)}).catch(u=>{t||($e(0),Le(0),n(`Failed to load bulk agent actions: ${fe(u)}`,"error"))}).finally(()=>{t||Oe(!1)});const l=u=>{const C=u.target;C&&(Pe.current?.contains(C)||De.current?.contains(C)||G(!1))},c=u=>{u.key==="Escape"&&(G(!1),De.current?.focus())};return document.addEventListener("mousedown",l),document.addEventListener("touchstart",l),document.addEventListener("keydown",c),()=>{t=!0,document.removeEventListener("mousedown",l),document.removeEventListener("touchstart",l),document.removeEventListener("keydown",c)}},[n,oe,r]);const Ht=async t=>{if(!_e){ze(!0);try{const c=(await Pt(void 0,r)).filter(B=>!nt(B)),u=c.filter(B=>t==="paused"?B.state==="active"||B.state==="running":B.state==="paused"),C=c.length-u.length;if(u.length===0){n(`No agents eligible to ${t==="paused"?"pause":"resume"}`,"error");return}if(!await U({title:t==="paused"?"Pause All Agents":"Resume All Agents",message:`${t==="paused"?"Pause":"Resume"} ${u.length} agent${u.length===1?"":"s"} in this project?`,danger:t==="paused"}))return;const ae=await Promise.allSettled(u.map(B=>as(B.id,t,r))),Q=ae.map((B,dt)=>({result:B,agent:u[dt]})).filter(B=>B.result.status==="rejected"),m=ae.length-Q.length,H=Q.length,X=`${t==="paused"?"Paused":"Resumed"} ${m} agent${m===1?"":"s"}; skipped ${C}`;if(H>0){const B=Q.slice(0,3).map(({agent:dt,result:Ps})=>`${dt.name||dt.id}: ${fe(Ps.reason)}`).join("; ");n(`${X}; failed ${H}${B?` (${B})`:""}`,"error")}else n(X,"success");await w()}catch(l){n(`Failed to ${t==="paused"?"pause":"resume"} agents: ${fe(l)}`,"error")}finally{ze(!1)}}},st=async(t,l)=>{if(!se.has(t)){ue(c=>new Set(c).add(t)),Ue(c=>{const u=new Map(c);return u.set(t,l),u});try{await as(t,l,r),n(`Agent state updated to ${l}`,"success"),await w(),Ue(c=>{const u=new Map(c);return u.delete(t),u})}catch(c){Ue(u=>{const C=new Map(u);return C.delete(t),C}),n(`Failed to update state: ${fe(c)}`,"error")}finally{ue(c=>{const u=new Set(c);return u.delete(t),u})}}},vs=async(t,l)=>{if(await U({title:"Delete Agent",message:`Delete agent "${l}"? This cannot be undone.`,danger:!0}))try{await ga(t,r),n(`Agent "${l}" deleted`,"success"),await w()}catch(u){n(`Failed to delete agent: ${fe(u)}`,"error")}},fs=async(t,l)=>{const c=k.find(u=>u.id===t);if(c){if(c.role===l){Fe(null);return}try{await gt(t,{role:l},r),n(`Agent role updated to ${Tt.find(u=>u.value===l)?.label??l}`,"success"),Fe(null),w()}catch(u){n(`Failed to update role: ${fe(u)}`,"error")}}},js=(t,l)=>{t.key==="Escape"&&Fe(null)},Ns=async(t,l)=>{lt===t.id&&(Me(null),Ce(c=>{const u={...c};return delete u[t.id],u})),we(t.id);try{await gt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:l}},r),n(`Heartbeat interval updated to ${ns(l)} for ${t.name}`,"success"),w()}catch(c){n(`Failed to update heartbeat interval: ${fe(c)}`,"error")}finally{we(null)}},Bt=async t=>{const l=Be[t.id]??"";if(l.trim()===""){n("Please enter a heartbeat interval in minutes","error");return}const c=Number(l);if(isNaN(c)){n("Heartbeat interval must be a valid number","error");return}if(c<=0){n("Heartbeat interval must be greater than 0","error");return}if(c>=1&&c<5){we(t.id);try{await gt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:ua}},r),n(`Heartbeat interval set to 5 minutes (minimum). ${c} minute${c!==1?"s":""} was below the 5-minute minimum.`,"success"),Me(null),Ce(C=>{const R={...C};return delete R[t.id],R}),w()}catch(C){n(`Failed to update heartbeat interval: ${fe(C)}`,"error")}finally{we(null)}return}const u=Math.round(c*6e4);we(t.id);try{await gt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:u}},r),n(`Heartbeat interval updated to ${ns(u)} for ${t.name}`,"success"),Me(null),Ce(C=>{const R={...C};return delete R[t.id],R}),w()}catch(C){n(`Failed to update heartbeat interval: ${fe(C)}`,"error")}finally{we(null)}},ys=t=>{const l=Et(t.runtimeConfig?.heartbeatIntervalMs),c=Math.round(l/6e4);Me(t.id),Ce(u=>({...u,[t.id]:String(c)}))},me=s.useCallback((t,l)=>{q(t),ie(l?.initialTab??"dashboard"),N(l?.initialRunId??null),he(l?.preferActiveRun??!1)},[]),Ve=s.useCallback(()=>{q(null),ie("dashboard"),N(null),he(!1)},[]),Wt=s.useCallback(t=>{me(t)},[me]),ks=s.useCallback(t=>{le(t),me(t)},[me]),ws=s.useCallback(async({agentId:t,deleted:l})=>{await E(),l&&F===t&&Ve()},[E,F,Ve]),Cs=s.useCallback(t=>{me(t),d&&xe(!1)},[d,me]),Ss=async(t,l)=>{Ue(c=>{const u=new Map(c);return u.set(t,"running"),u});try{await ma(t,r,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),n(`Heartbeat run started for ${l}`,"success"),await w(),Ue(c=>{const u=new Map(c);return u.delete(t),u})}catch(c){Ue(u=>{const C=new Map(u);return C.delete(t),C}),n(`Failed to start heartbeat run: ${fe(c)}`,"error")}},Ke=s.useCallback(t=>Math.min(Ya,Math.max(Ua,t)),[]),Y=s.useCallback(t=>{const l=de.current,c=Ie.current?.querySelector(".agent-org-chart");if(!l||!c)return{...t,scale:Ke(t.scale)};const u=Ke(t.scale),C=c.scrollWidth*u,R=c.scrollHeight*u,ae=l.clientWidth,Q=l.clientHeight,m=Math.min(qe,ae-C-qe),H=qe,X=Math.min(qe,Q-R-qe),B=qe;return{scale:u,x:Math.max(m,Math.min(H,t.x)),y:Math.max(X,Math.min(B,t.y))}},[Ke]),ot=s.useCallback((t,l,c)=>{const u=de.current;u&&_(C=>{const R=Ke(t),ae=u.getBoundingClientRect(),Q=l-ae.left,m=c-ae.top,H=(Q-C.x)/C.scale,X=(m-C.y)/C.scale;return Y({scale:R,x:Q-H*R,y:m-X*R})})},[Ke,Y]),Ye=s.useCallback(()=>{const t=de.current,l=Ie.current?.querySelector(".agent-org-chart");if(!t||!l)return;const c=t.clientWidth,u=t.clientHeight,C=l.scrollWidth,R=l.scrollHeight;if(C<=0||R<=0)return;const ae=Ke(Math.min(c/C,u/R,1)),Q=(c-C*ae)/2,m=(u-R*ae)/2;_(Y({scale:ae,x:Q,y:m}))},[Ke,Y]),jt=s.useCallback(t=>{Z(t),t!=="org"&&_({scale:1,x:0,y:0}),d&&F&&Ve()},[Ve,d,F]),Gt=t=>Tt.find(l=>l.value===t)?.label??t,ct=s.useMemo(()=>Ka({tree:Ge,availableWidth:pe,preference:re}),[Ge,re,pe]),Vt=s.useCallback(t=>{Ee(t),_({scale:1,x:0,y:0})},[]);s.useEffect(()=>{_({scale:1,x:0,y:0}),D.current=!1},[r,ct]),s.useLayoutEffect(()=>{A!=="org"||Ne||Ge.length===0||D.current||(Ye(),D.current=!0)},[A,Ge.length,Ye,Ne]);const As=s.useCallback((t,l)=>{l?Te.current.set(t,l):Te.current.delete(t)},[]),Kt=s.useCallback(()=>e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>_(t=>Y({...t,scale:t.scale*.9})),"aria-label":"Zoom out org chart",title:"Zoom out",children:e.jsx(Aa,{size:16})}),e.jsxs("span",{className:"agent-org-chart-controls__zoom-label","aria-live":"polite",children:[Math.round(M.scale*100),"%"]}),e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>_(t=>Y({...t,scale:t.scale*1.1})),"aria-label":"Zoom in org chart",title:"Zoom in",children:e.jsx(Ca,{size:16})}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm agent-org-chart-controls__fit-btn",onClick:Ye,"aria-label":"Fit org chart",title:"Fit org chart",children:[e.jsx(ta,{size:16}),"Fit"]}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm",onClick:()=>_(t=>Y({...t,x:0,y:0})),"aria-label":"Center org chart",title:"Center org chart",children:[e.jsx(sa,{size:16}),"Center"]})]}),[Y,Ye,M.scale]),Rs=s.useCallback(t=>{if(!(t.ctrlKey||t.metaKey))return;t.preventDefault();const l=t.deltaY>0?.9:1.1;ot(M.scale*l,t.clientX,t.clientY)},[M.scale,ot]),$s=s.useCallback(t=>{if(t.target.closest(".org-chart-node-card"))return;if(t.currentTarget.setPointerCapture?.(t.pointerId),p.current.set(t.pointerId,{x:t.clientX,y:t.clientY}),p.current.size===1){I.current={x:t.clientX-M.x,y:t.clientY-M.y,pointerId:t.pointerId},ke(!0);return}if(p.current.size===2){const c=Array.from(p.current.values()),u=c[0].x-c[1].x,C=c[0].y-c[1].y;J.current={distance:Math.hypot(u,C),scale:M.scale,centerX:(c[0].x+c[1].x)/2,centerY:(c[0].y+c[1].y)/2},I.current=null}},[M.scale,M.x,M.y]),Ts=s.useCallback(t=>{if(p.current.has(t.pointerId)){if(p.current.set(t.pointerId,{x:t.clientX,y:t.clientY}),p.current.size>=2){const l=Array.from(p.current.values()),c=J.current;if(!c)return;const u=l[0].x-l[1].x,C=l[0].y-l[1].y,R=Math.hypot(u,C),ae=c.scale*(R/c.distance);ot(ae,c.centerX,c.centerY);return}!I.current||I.current.pointerId!==t.pointerId||_(l=>Y({...l,x:t.clientX-I.current.x,y:t.clientY-I.current.y}))}},[Y,ot]),Ut=s.useCallback(t=>{p.current.delete(t.pointerId),p.current.size<2&&(J.current=null),p.current.size===0&&(I.current=null,ke(!1))},[]),Ms=s.useCallback(t=>{if(t.key==="ArrowLeft")_(l=>Y({...l,x:l.x+ht}));else if(t.key==="ArrowRight")_(l=>Y({...l,x:l.x-ht}));else if(t.key==="ArrowUp")_(l=>Y({...l,y:l.y+ht}));else if(t.key==="ArrowDown")_(l=>Y({...l,y:l.y-ht}));else if(t.key==="+"||t.key==="=")_(l=>Y({...l,scale:l.scale*1.1}));else if(t.key==="-")_(l=>Y({...l,scale:l.scale*.9}));else if(t.key==="0")Ye();else if(t.key==="Home")_({scale:1,x:0,y:0});else return;t.preventDefault()},[Y,Ye]),Yt=s.useCallback(()=>{const t=[{value:"horizontal",label:"Horizontal",icon:e.jsx(ts,{size:16}),ariaLabel:"Horizontal layout"},{value:"vertical",label:"Vertical",icon:e.jsx(es,{size:16}),ariaLabel:"Vertical layout"},{value:"auto",label:"Auto",icon:e.jsx(Ze,{size:16}),ariaLabel:"Automatic layout"}];return e.jsx("div",{className:"agent-org-chart-layout-toggle","data-testid":"agent-org-chart-layout-toggle",children:t.map(l=>{const c=re===l.value;return e.jsxs("button",{type:"button",className:`btn-icon touch-target agent-org-chart-layout-toggle__button${c?" btn-icon--active":""}`,onClick:()=>Vt(l.value),"aria-pressed":c,"aria-label":l.ariaLabel,title:l.ariaLabel,"data-layout-value":l.value,children:[l.icon,e.jsx("span",{className:"agent-org-chart-layout-toggle__text",children:l.label})]},l.value)})})},[Vt,re]),Es=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],Nt=t=>da(t),_s=Ae||_e||be===0,Ls=Ae||_e||ve===0,Xt=y&&k.length===0,at=s.useCallback(()=>{W(!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(Lt,{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:()=>jt("list"),title:"List view","aria-label":"List view","aria-pressed":A==="list",children:e.jsx(es,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="board"?" active":""}`,onClick:()=>jt("board"),title:"Board view","aria-label":"Board view","aria-pressed":A==="board",children:e.jsx(Je,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="org"?" active":""}`,onClick:()=>jt("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":A==="org",children:e.jsx(ts,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:De,className:`btn-icon agent-controls-trigger${oe?" agent-controls-trigger--active":""}`,onClick:()=>G(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":oe,"aria-controls":He,children:e.jsx(ka,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void w(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Ze,{size:16,className:y?"spin":void 0})}),!d&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{z(!0),G(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(It,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{at(),G(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(ss,{size:16}),"New Agent"]})]}),oe&&e.jsxs("div",{ref:Pe,id:He,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(aa,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:f,onChange:t=>j(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:h,onChange:t=>b(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]})}),d&&e.jsxs("div",{className:"agent-controls-mobile-actions",children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{z(!0),G(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(It,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{at(),G(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(ss,{size:16}),"New Agent"]})]}),e.jsxs("div",{className:"agent-controls-bulk-actions",role:"menu","aria-label":"Bulk agent actions",children:[e.jsxs("button",{type:"button",className:"agent-detail-bulk-menu-item",role:"menuitem",disabled:_s,onClick:()=>{G(!1),Ht("paused")},children:[e.jsxs("span",{className:"agent-controls-bulk-actions__label",children:[e.jsx(Ct,{}),e.jsx("span",{children:"Pause All Agents"})]}),e.jsx("span",{className:"agent-detail-bulk-menu-item-hint",children:Ae?"Loading eligibility…":be===0?"No active or running project agents to pause":`Pause ${be} active/running agent${be===1?"":"s"}`})]}),e.jsxs("button",{type:"button",className:"agent-detail-bulk-menu-item",role:"menuitem",disabled:Ls,onClick:()=>{G(!1),Ht("active")},children:[e.jsxs("span",{className:"agent-controls-bulk-actions__label",children:[e.jsx(mt,{}),e.jsx("span",{children:"Resume All Agents"})]}),e.jsx("span",{className:"agent-detail-bulk-menu-item-hint",children:Ae?"Loading eligibility…":ve===0?"No paused project agents to resume":`Resume ${ve} paused agent${ve===1?"":"s"}`})]})]}),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:We,onChange:t=>{const l=Number(t.target.value);Dt(Number.isFinite(l)&&l>0?l:1)},disabled:a}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",We.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Mt.reduce((t,l)=>Math.abs(l-We)<Math.abs(t-We)?l:t,Mt[0])),onChange:t=>{const l=Number(t.target.value);Dt(Number.isFinite(l)&&l>0?l:1)},disabled:a,"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(Ra,{agents:tt})]})]})]})]}),e.jsx(Fa,{isOpen:P,onClose:()=>{W(!1),L(null)},onCreated:()=>{W(!1),L(null),w()},projectId:r,prefillDraft:T,agentOnboardingEnabled:g,existingAgents:k,onPrefillDraft:L}),e.jsx(Oa,{isOpen:v,onClose:()=>z(!1),onImported:()=>void w(),projectId:r}),e.jsx(Pa,{stats:$,activeAgents:bs,projectId:r,isOpen:ce,onToggle:()=>xe(t=>!t),onSelectAgent:Cs,onOpenTaskLogs:x}),A==="org"?e.jsx("div",{className:"agents-org-full-view",children:e.jsx("div",{className:"agents-view-content agents-view-content--org-full",children:F?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:Ve,"aria-label":"Back to org chart",children:"Back to org chart"}),e.jsx(s.Suspense,{fallback:null,children:e.jsx(us,{inline:!0,showInlineBackButton:!1,agentId:F,projectId:r,onClose:Ve,addToast:n,onChildClick:Wt,initialTab:ne,initialRunId:O,preferActiveRun:ge},F)})]}):Xt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ze,{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:[d?e.jsxs("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:[Yt(),Kt()]}):e.jsxs("div",{className:"agent-org-chart-toolbar",children:[Yt(),e.jsx("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:Kt()})]}),e.jsx("div",{ref:de,className:"agent-org-chart-viewport","data-testid":"agent-org-chart-viewport",tabIndex:0,role:"region","aria-label":"Org chart canvas",onWheel:Rs,onPointerDown:$s,onPointerMove:Ts,onPointerUp:Ut,onPointerCancel:Ut,onKeyDown:Ms,"data-panning":ye?"true":"false",children:e.jsxs("div",{ref:Ie,className:`agent-org-chart-canvas agent-org-chart-canvas--zoom-${Math.round((M.scale??1)*100)}`,"data-panning":ye?"true":"false",style:{transform:`translate(${M.x}px, ${M.y}px) scale(${M.scale})`},children:[e.jsx("div",{className:`agent-org-chart${ct==="vertical"?" agent-org-chart--vertical":""}`,"data-testid":"agent-org-chart","data-layout-mode":ct,children:Ne?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Ze,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):Ge.length===0?e.jsx(At,{onCtaClick:at}):(i.current=[],Ge.map(t=>e.jsx(xs,{node:t,onSelect:ks,getHealthStatus:Nt,selectedAgentId:je,registerNodeElement:As,linksRef:i},t.agent.id)))}),e.jsx(Xa,{links:i.current,nodeElements:Te.current,canvasRef:Ie,viewportRef:de,layoutMode:ct,transform:M})]})})]})})}):e.jsxs("div",{className:"agents-split-layout",children:[e.jsx("div",{className:`agents-split-sidebar${V?" agents-split-sidebar--hidden-mobile":""}`,children:e.jsx("div",{className:"agents-view-content",children:Xt?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Ze,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):A==="board"?e.jsx("div",{className:"agent-board",children:tt.length===0?e.jsx(At,{onCtaClick:at}):tt.map(t=>{const l=Nt(t),c=Ot(t,l),u=Ft(t.state),C=zt("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${C}${F===t.id?" agent-card--selected":""}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>me(t.id),role:"button",tabIndex:0,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.key===" "&&R.preventDefault(),me(t.id))},children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:e.jsx(xt,{agent:t,size:20})}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:Gt(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${u}`,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:l.color},title:c.title,children:[l.icon,c.label?` ${c.label}`:""]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:tt.length===0?e.jsx(At,{onCtaClick:at}):tt.map(t=>{const l=Nt(t),c=Ot(t,l),u=Ft(t.state),C=zt("agent-card",t.state),R=Et(t.runtimeConfig?.heartbeatIntervalMs),ae=na(R),Q=Qe===t.id;return e.jsxs("div",{className:`agent-card agent-card--clickable ${C}${F===t.id?" agent-card--selected":""}`,onClick:m=>{const H=m.target;if(H===m.currentTarget){me(t.id);return}const X=H.closest('button, select, input, [role="button"]');X&&X!==m.currentTarget||me(t.id)},role:"button",tabIndex:0,onKeyDown:m=>{m.target===m.currentTarget&&(m.key==="Enter"||m.key===" ")&&(m.key===" "&&m.preventDefault(),me(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:[vt===t.id?e.jsx("select",{ref:ft,className:"select agent-role-select",value:t.role,onChange:m=>void fs(t.id,m.target.value),onKeyDown:m=>js(m,t.id),onBlur:()=>Fe(null),autoFocus:!0,children:Tt.map(m=>e.jsxs("option",{value:m.value,children:[m.icon," ",m.label]},m.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:m=>{m.stopPropagation(),Fe(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.stopPropagation(),Fe(t.id))},children:e.jsx(xt,{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(ms,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${u}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:l.color},title:c.title,children:[l.icon,c.label?` ${c.label}`:""]}),e.jsx("span",{className:"badge text-secondary",children:Gt(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 m=Es(t);if(m.length===0)return null;const H=m.slice(0,2),X=m.length-2;return e.jsxs(e.Fragment,{children:[H.map(B=>e.jsx("span",{className:"badge badge-skill",title:B,children:va(B)},B)),X>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",X]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.state==="error"&&t.lastError?e.jsx(la,{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:"}),lt===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Be[t.id]??"",onChange:m=>Ce(H=>({...H,[t.id]:m.target.value})),onKeyDown:m=>{m.key==="Enter"?Bt(t):m.key==="Escape"&&(Me(null),Ce(H=>{const X={...H};return delete X[t.id],X}))},disabled:Q,"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 Bt(t),disabled:Q,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>{Me(null),Ce(m=>{const H={...m};return delete H[t.id],H})},disabled:Q,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:R,onChange:m=>{const H=m.target.value;H==="__custom__"?ys(t):Ns(t,Number(H))},disabled:Q,"aria-label":`Set heartbeat interval for ${t.name}`,children:[ae.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value)),ia.some(m=>m.value===R)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),Q&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const m=new Date(t.lastHeartbeatAt),H=new Date(m.getTime()+R),X=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:m.toLocaleString(),children:["Last: ",m.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),X&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:H.toLocaleString(),children:["Next: ",H.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--primary",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"active"),disabled:se.has(t.id),title:"Activate",children:[e.jsx(mt,{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 Ss(t.id,t.name),disabled:se.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(Je,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Run Now"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"paused"),disabled:se.has(t.id),title:"Pause",children:[e.jsx(Ct,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"active"),disabled:se.has(t.id),title:"Resume",children:[e.jsx(mt,{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:()=>me(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(Je,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Running"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"paused"),disabled:se.has(t.id),title:"Pause",children:[e.jsx(Ct,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void st(t.id,"active"),disabled:se.has(t.id),title:"Retry",children:[e.jsx(mt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Retry"})]})]}),e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--secondary",children:[e.jsxs("button",{className:"btn btn-sm agent-card-details-btn",onClick:()=>me(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:[e.jsx(ra,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Details"})]}),(t.state==="idle"||t.state==="paused")&&e.jsxs("button",{className:"btn btn-sm btn-danger",onClick:()=>void vs(t.id,t.name),title:"Delete",children:[e.jsx(oa,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Delete"})]})]})]})]},t.id)})})})}),e.jsx("div",{className:`agents-split-detail${d&&!F?" agents-split-detail--hidden-mobile":""}`,children:F?e.jsx(s.Suspense,{fallback:null,children:e.jsx(us,{inline:!0,showInlineBackButton:d,agentId:F,projectId:r,onClose:Ve,addToast:n,onChildClick:Wt,initialTab:ne,initialRunId:O,preferActiveRun:ge,onMutationSuccess:ws},F)}):e.jsxs("div",{className:"agents-detail-empty-state",children:[e.jsx(Lt,{size:48}),e.jsx("h3",{children:"Select an agent"}),e.jsx("p",{children:"Choose an agent from the sidebar to view details"})]})})]})]})}export{an as AgentsView};
|