@runfusion/fusion 0.7.0 → 0.8.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 +4694 -2257
- package/dist/client/assets/{AgentDetailView-Du65-jDo.js → AgentDetailView-C3Xcrxnp.js} +3 -3
- package/dist/client/assets/{AgentDetailView-C1_lTTET.css → AgentDetailView-DIBOY8V-.css} +1 -1
- package/dist/client/assets/AgentsView-C2f7esMv.css +1 -0
- package/dist/client/assets/{AgentsView-BkgNEbNs.js → AgentsView-EjE4y4rM.js} +46 -46
- package/dist/client/assets/{ChatView-LDte0TdV.js → ChatView-DQLvKCYj.js} +1 -1
- package/dist/client/assets/DevServerView-CX7paFRQ.js +1 -0
- package/dist/client/assets/{DirectoryPicker-CSp3G115.js → DirectoryPicker-_cBPx6Nx.js} +1 -1
- package/dist/client/assets/{DocumentsView-DOe0E1WQ.js → DocumentsView-Wz33aYqp.js} +1 -1
- package/dist/client/assets/{InsightsView-DWZbS6z-.js → InsightsView-C7YPnS92.js} +1 -1
- package/dist/client/assets/MemoryView-DKQtFzFQ.js +2 -0
- package/dist/client/assets/{NodesView-DO9jxhM4.js → NodesView-CI4rUQC4.js} +4 -4
- package/dist/client/assets/{NodesView-BYVG2yY-.css → NodesView-DCoS6iYh.css} +1 -1
- package/dist/client/assets/{PiExtensionsManager-CfXZaWl7.js → PiExtensionsManager-BFmdKgHZ.js} +3 -3
- package/dist/client/assets/{PluginManager-r6CWD9u-.js → PluginManager-BGQU1IIw.js} +1 -1
- package/dist/client/assets/{RoadmapsView-CgAM3YfN.js → RoadmapsView-Cts3hoIS.js} +1 -1
- package/dist/client/assets/SettingsModal-D5hLoLXp.css +1 -0
- package/dist/client/assets/{SettingsModal-fmRtzH8z.js → SettingsModal-DXvBGZHf.js} +1 -1
- package/dist/client/assets/SettingsModal-DvRd0ZOE.js +31 -0
- package/dist/client/assets/SetupWizardModal-DRF5fOoR.css +1 -0
- package/dist/client/assets/{SetupWizardModal-oRNpImWR.js → SetupWizardModal-Y2ewEE8Y.js} +1 -1
- package/dist/client/assets/{SkillsView-BhwtL-0_.js → SkillsView-BXvrHzEZ.js} +1 -1
- package/dist/client/assets/{TodoView-CmhUBFNV.js → TodoView-NZHkv9YQ.js} +2 -2
- package/dist/client/assets/{folder-open-CrTagHrr.js → folder-open-Kh0ScTc5.js} +1 -1
- package/dist/client/assets/index-CWz44REw.css +1 -0
- package/dist/client/assets/index-D1gavMG-.js +656 -0
- package/dist/client/assets/{list-checks-DR26h_Io.js → list-checks-CvoT0bwU.js} +1 -1
- package/dist/client/assets/{star-CO_D42zy.js → star-BdfwSLBU.js} +1 -1
- package/dist/client/assets/{upload-BcrgS-iu.js → upload-Bx8Yk_7Q.js} +1 -1
- package/dist/client/assets/{users-4d8al5Sp.js → users-DgVaFEsz.js} +1 -1
- package/dist/client/brands/hermes-logo.svg +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/version.json +1 -1
- package/dist/extension.js +3459 -1459
- package/dist/pi-claude-cli/index.ts +27 -0
- package/dist/pi-claude-cli/package.json +1 -5
- package/dist/pi-claude-cli/src/__tests__/process-manager.test.ts +31 -9
- package/dist/pi-claude-cli/src/__tests__/provider.test.ts +122 -8
- package/dist/pi-claude-cli/src/process-manager.ts +25 -7
- package/dist/pi-claude-cli/src/provider.ts +31 -7
- package/dist/pi-claude-cli/src/types/cross-spawn.d.ts +7 -0
- package/package.json +4 -7
- package/skill/fusion/references/extension-tools.md +1 -0
- package/dist/client/assets/AgentsView-D12CuIFc.css +0 -1
- package/dist/client/assets/DevServerView-AXznq3jv.js +0 -6
- package/dist/client/assets/MemoryView-BxnlhBoa.js +0 -2
- package/dist/client/assets/SettingsModal-DPDQyWim.css +0 -1
- package/dist/client/assets/SettingsModal-GZdRt8fX.js +0 -31
- package/dist/client/assets/SetupWizardModal-BMa6p24b.css +0 -1
- package/dist/client/assets/index-BTeSa6vk.js +0 -646
- package/dist/client/assets/index-S9oR77v2.css +0 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-
|
|
2
|
-
import{c as He,s as
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-C3Xcrxnp.js","assets/vendor-react-K0fH_qHe.js","assets/index-D1gavMG-.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-CWz44REw.css","assets/star-BdfwSLBU.js","assets/list-checks-CvoT0bwU.js","assets/upload-Bx8Yk_7Q.js","assets/folder-open-Kh0ScTc5.js","assets/AgentDetailView-DIBOY8V-.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as He,s as dt,A as Ie,C as Re,Z as ut,B as Ve,g as qe,a as at,b as $e,d as mt,e as ht,f as gt,h as pt,i as ft,u as Ke,P as vt,j as bt,k as xt,l as yt,m as Ue,G as wt,S as jt,L as Fe,T as De,R as _e,F as Be,X as Ge,n as kt,o as Nt,p as It,q as Ct,r as fe,t as Le,v as St,w as Et,x as At,y as Tt,z as Mt,D as Qe,E as Rt,H as it,I as _t,J as Ee,K as Je,M as Pt,N as $t,O as Ft,Q as Ae,U as Dt,V as Xe,W as Lt,Y as zt,_ as Ot,$ as qt}from"./index-D1gavMG-.js";import{r as n,j as e,a as Ht}from"./vendor-react-K0fH_qHe.js";import{U as rt}from"./upload-Bx8Yk_7Q.js";import{F as Vt}from"./folder-open-Kh0ScTc5.js";/**
|
|
3
3
|
* @license lucide-react v1.7.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
6
6
|
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/const
|
|
7
|
+
*/const Wt=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1",key:"cif1o7"}]],Kt=He("list-todo",Wt);/**
|
|
8
8
|
* @license lucide-react v1.7.0 - ISC
|
|
9
9
|
*
|
|
10
10
|
* This source code is licensed under the ISC license.
|
|
11
11
|
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
-
*/const
|
|
12
|
+
*/const Ut=[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]],Bt=He("network",Ut);/**
|
|
13
13
|
* @license lucide-react v1.7.0 - ISC
|
|
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 Bt=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Gt=He("sliders-horizontal",Bt),Ye=200;function Qt(a,l){const[p,h]=n.useState([]),[d,u]=n.useState(!1),r=n.useRef(null),g=n.useRef(0),c=n.useRef(a),m=n.useRef(l);return(c.current!==a||m.current!==l)&&(c.current=a,m.current=l,g.current++,r.current&&(r.current(),r.current=null),h([]),u(!1)),n.useEffect(()=>{if(!a){h([]),u(!1);return}const w=g.current;let k=`/api/tasks/${encodeURIComponent(a)}/logs/stream`;l&&(k+=`?projectId=${encodeURIComponent(l)}`);const A=ut(k,{events:{"agent:log":f=>{if(g.current===w)try{const v=JSON.parse(f.data),E={type:v.type??"text",text:v.text??v.content??"",timestamp:v.timestamp,content:v.content};h(H=>{const M=[E,...H];return M.length>Ye?M.slice(0,Ye):M})}catch{}}},onOpen:()=>{g.current===w&&u(!0)},onError:()=>{g.current===w&&u(!1)}});return r.current=A,()=>{A(),r.current=null,g.current===w&&u(!1)}},[a,l]),{entries:p,isConnected:d}}function Jt({agent:a,projectId:l,onSelect:p}){const{entries:h,isConnected:d}=Qt(a.taskId,l),u=a.lastHeartbeatAt?Math.floor((Date.now()-new Date(a.lastHeartbeatAt).getTime())/1e3):0,r=()=>{p&&p(a.id)},g=c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),r())};return e.jsxs("div",{className:"live-agent-card",onClick:r,onKeyDown:g,role:"button",tabIndex:0,"aria-label":`Select agent ${a.name}`,children:[e.jsxs("div",{className:"live-agent-card-header",children:[e.jsxs("div",{className:"live-agent-card-name",children:[e.jsx("span",{className:"live-agent-pulse"}),e.jsx("span",{children:a.name})]}),a.taskId&&e.jsx("span",{className:"live-agent-task badge",children:a.taskId})]}),e.jsx("div",{className:"live-agent-card-transcript",children:h.length===0?e.jsx("div",{className:"live-agent-card-empty",children:d?"Waiting for output...":"Connecting..."}):h.slice(0,20).map((c,m)=>e.jsx("div",{className:"live-agent-card-line",children:c.text},m))}),e.jsxs("div",{className:"live-agent-card-footer",children:[e.jsx("span",{className:"text-secondary",children:Xt(u)}),d&&e.jsx(Ie,{size:12,className:"live-agent-streaming-dot"})]})]})}function Xt(a){return a<60?`${a}s`:a<3600?`${Math.floor(a/60)}m ${a%60}s`:`${Math.floor(a/3600)}h ${Math.floor(a%3600/60)}m`}function Zt({agents:a,projectId:l,onAgentSelect:p}){const h=Array.from(new Map(a.map(d=>[d.id,d])).values());return h.length===0?null:e.jsxs("div",{className:"active-agents-panel",children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(Ie,{size:16}),e.jsxs("span",{children:["Active Agents (",h.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:h.map(d=>e.jsx(Jt,{agent:d,projectId:l,onSelect:p},d.id))})]})}const Yt=[{icon:Ie,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:Wt,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:Re,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:mt,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function en({stats:a}){return a?e.jsx("div",{className:"agent-metrics-bar",children:Yt.map(l=>{const p=l.valueKey==="successRate"?`${Math.round(a.successRate*100)}%`:a[l.valueKey];return e.jsxs("div",{className:`agent-metric-card ${l.className}`,children:[e.jsx(l.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:p}),e.jsx("span",{className:"agent-metric-label",children:l.label})]})]},l.label)})}):null}function et(a){return typeof a=="number"&&Number.isFinite(a)?a:0}function Ne(a){return a.toLocaleString()}function tn({agents:a}){const{rows:l,totalInputTokens:p,totalOutputTokens:h,totalTokens:d}=n.useMemo(()=>{const r=a.map(g=>{const c=et(g.totalInputTokens),m=et(g.totalOutputTokens);return{id:g.id,name:g.name,inputTokens:c,outputTokens:m,totalTokens:c+m}}).sort((g,c)=>c.totalTokens-g.totalTokens||g.name.localeCompare(c.name)||g.id.localeCompare(c.id));return{rows:r,totalInputTokens:r.reduce((g,c)=>g+c.inputTokens,0),totalOutputTokens:r.reduce((g,c)=>g+c.outputTokens,0),totalTokens:r.reduce((g,c)=>g+c.totalTokens,0)}},[a]),u=d>0;return e.jsxs("section",{className:"agent-token-stats-panel","aria-label":"Agent token usage statistics",children:[e.jsx("header",{className:"agent-token-stats-panel__header",children:e.jsx("h3",{className:"agent-token-stats-panel__title",children:"Token Usage by Agent"})}),e.jsxs("div",{className:"agent-token-stats-panel__totals",role:"list","aria-label":"Token usage totals",children:[e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Input Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ne(p)})]}),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:Ne(h)})]}),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:Ne(d)})]})]}),u?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:l.map(r=>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:r.name}),e.jsx("span",{className:"agent-token-stats-panel__agent-id",children:r.id})]}),e.jsx("td",{children:Ne(r.inputTokens)}),e.jsx("td",{children:Ne(r.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:Ne(r.totalTokens)})]},r.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."})]})}function Te({title:a="No agents found",description:l="Create an agent to get started",ctaLabel:p="Create Agent",onCtaClick:h}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(Ve,{size:48,opacity:.3,className:"agent-empty-state__icon"}),e.jsx("p",{className:"agent-empty-state__title",children:a}),e.jsx("p",{className:"agent-empty-state__description text-secondary",children:l}),h?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:h,children:p}):null]})}const ot="fn-agent-tree-expanded";function tt(a){try{const l=qe(ot,a);if(l){const p=JSON.parse(l);return new Set(Array.isArray(p)?p:[])}}catch{}return new Set}function nn(a,l){try{it(ot,JSON.stringify([...a]),l)}catch{}}function sn(a,l){const p=new Map,h=new Map;for(const u of a)if(p.set(u.id,u),u.reportsTo){const r=h.get(u.reportsTo)??[];r.push(u),h.set(u.reportsTo,r)}function d(u,r){const g=h.get(u.id)??[],c=l.has(u.id)?g.map(m=>d(m,r+1)):[];return{agent:u,children:c,depth:r}}return a.filter(u=>!u.reportsTo||!p.has(u.reportsTo)).map(u=>d(u,0))}function an(a,l){const[p,h]=n.useState(()=>tt(l));n.useEffect(()=>{h(tt(l))},[l]);const d=n.useMemo(()=>sn(a,p),[a,p]),u=n.useCallback(c=>{h(m=>{const j=new Set(m);return j.has(c)?j.delete(c):j.add(c),nn(j,l),j})},[l]),r=n.useCallback(c=>p.has(c),[p]),g=n.useCallback(c=>a.filter(m=>m.reportsTo===c),[a]);return{rootNodes:d,toggleExpand:u,isExpanded:r,getChildren:g,isLoading:!1}}const nt=3,ze=1e3;function rn({isOpen:a,onClose:l,onGenerated:p,projectId:h}){const[d,u]=n.useState(""),[r,g]=n.useState({type:"input"}),[c,m]=n.useState(null),[j,w]=n.useState(!1),k=n.useRef(null),A=n.useRef(null);n.useEffect(()=>{a&&r.type==="input"&&A.current?.focus()},[a,r.type]),n.useEffect(()=>{if(!a&&k.current){const S=k.current;k.current=null,$e(S,h).catch(()=>{})}},[a,h]),n.useEffect(()=>{if(!a)return;const S=R=>{R.key==="Escape"&&f()};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[a]);const f=n.useCallback(()=>{if(k.current){const S=k.current;k.current=null,$e(S,h).catch(()=>{})}u(""),g({type:"input"}),m(null),w(!1),l()},[l,h]),v=n.useCallback(async()=>{if(!(!d.trim()||d.trim().length<nt)){m(null),g({type:"loading"});try{const{sessionId:S}=await ht(d.trim(),h);k.current=S;const{spec:R}=await gt(S,h);g({type:"preview",spec:R,sessionId:S})}catch(S){const R=S instanceof Error?S.message:"Failed to generate agent specification";R.includes("429")||R.toLowerCase().includes("rate limit")?m("Too many requests. Please wait a moment and try again."):m(R),g({type:"input"}),k.current=null}}},[d,h]),E=n.useCallback(async()=>{if(k.current){const S=k.current;k.current=null;try{await $e(S,h)}catch{}}await v()},[v,h]),H=n.useCallback(()=>{r.type==="preview"&&(k.current=null,p(r.spec),u(""),g({type:"input"}),m(null),w(!1),l())},[r,p,l]);if(!a)return null;const M=d.trim().length>=nt&&d.trim().length<=ze;return e.jsx("div",{className:"agent-dialog-overlay",onClick:S=>{S.target===S.currentTarget&&f()},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:f,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[c&&e.jsx("div",{className:"agent-dialog-error-banner",children:c}),r.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:A,id:"agent-role-description",className:"input agent-dialog-textarea",rows:4,placeholder:'e.g. "Senior frontend code reviewer who specializes in React accessibility"',value:d,onChange:S=>u(S.target.value),onKeyDown:S=>{S.key==="Enter"&&!S.shiftKey&&M&&(S.preventDefault(),v())},maxLength:ze,"aria-describedby":"role-description-hint"}),e.jsxs("div",{id:"role-description-hint",className:"agent-dialog-hint",children:[e.jsx("span",{children:"Describe what your agent should do"}),e.jsxs("span",{children:[d.length,"/",ze]})]})]})]}),r.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..."})]}),r.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:[r.spec.icon," ",r.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:r.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:r.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:r.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:r.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:()=>w(!j),children:j?"Collapse":"Expand"})]}),e.jsxs("div",{className:`agent-generation-prompt-box${j?"":" agent-generation-prompt-box--collapsed"}`,children:[r.spec.systemPrompt,!j&&r.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:f,children:"Cancel"}),r.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void v(),disabled:!M,children:"Generate"}),r.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void E(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:H,children:"Use This"})]})]})]})})}const ln=`# Soul: Chief Executive Officer
|
|
17
|
+
*/const Gt=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Qt=He("sliders-horizontal",Gt),Ze=200;function Jt(a,l){const[p,h]=n.useState([]),[d,u]=n.useState(!1),r=n.useRef(null),g=n.useRef(0),c=n.useRef(a),m=n.useRef(l);return(c.current!==a||m.current!==l)&&(c.current=a,m.current=l,g.current++,r.current&&(r.current(),r.current=null),h([]),u(!1)),n.useEffect(()=>{if(!a){h([]),u(!1);return}const w=g.current;let k=`/api/tasks/${encodeURIComponent(a)}/logs/stream`;l&&(k+=`?projectId=${encodeURIComponent(l)}`);const A=dt(k,{events:{"agent:log":f=>{if(g.current===w)try{const v=JSON.parse(f.data),E={type:v.type??"text",text:v.text??v.content??"",timestamp:v.timestamp,content:v.content};h(H=>{const M=[E,...H];return M.length>Ze?M.slice(0,Ze):M})}catch{}}},onOpen:()=>{g.current===w&&u(!0)},onError:()=>{g.current===w&&u(!1)}});return r.current=A,()=>{A(),r.current=null,g.current===w&&u(!1)}},[a,l]),{entries:p,isConnected:d}}function Xt({agent:a,projectId:l,onSelect:p}){const{entries:h,isConnected:d}=Jt(a.taskId,l),u=a.lastHeartbeatAt?Math.floor((Date.now()-new Date(a.lastHeartbeatAt).getTime())/1e3):0,r=()=>{p&&p(a.id)},g=c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),r())};return e.jsxs("div",{className:"live-agent-card",onClick:r,onKeyDown:g,role:"button",tabIndex:0,"aria-label":`Select agent ${a.name}`,children:[e.jsxs("div",{className:"live-agent-card-header",children:[e.jsxs("div",{className:"live-agent-card-name",children:[e.jsx("span",{className:"live-agent-pulse"}),e.jsx("span",{children:a.name})]}),a.taskId&&e.jsx("span",{className:"live-agent-task badge",children:a.taskId})]}),e.jsx("div",{className:"live-agent-card-transcript",children:h.length===0?e.jsx("div",{className:"live-agent-card-empty",children:d?"Waiting for output...":"Connecting..."}):h.slice(0,20).map((c,m)=>e.jsx("div",{className:"live-agent-card-line",children:c.text},m))}),e.jsxs("div",{className:"live-agent-card-footer",children:[e.jsx("span",{className:"text-secondary",children:Zt(u)}),d&&e.jsx(Ie,{size:12,className:"live-agent-streaming-dot"})]})]})}function Zt(a){return a<60?`${a}s`:a<3600?`${Math.floor(a/60)}m ${a%60}s`:`${Math.floor(a/3600)}h ${Math.floor(a%3600/60)}m`}function Yt({agents:a,projectId:l,onAgentSelect:p}){const h=Array.from(new Map(a.map(d=>[d.id,d])).values());return h.length===0?null:e.jsxs("div",{className:"active-agents-panel",children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(Ie,{size:16}),e.jsxs("span",{children:["Active Agents (",h.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:h.map(d=>e.jsx(Xt,{agent:d,projectId:l,onSelect:p},d.id))})]})}const en=[{icon:Ie,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:Kt,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:Re,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:ut,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function tn({stats:a}){return a?e.jsx("div",{className:"agent-metrics-bar",children:en.map(l=>{const p=l.valueKey==="successRate"?`${Math.round(a.successRate*100)}%`:a[l.valueKey];return e.jsxs("div",{className:`agent-metric-card ${l.className}`,children:[e.jsx(l.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:p}),e.jsx("span",{className:"agent-metric-label",children:l.label})]})]},l.label)})}):null}function Ye(a){return typeof a=="number"&&Number.isFinite(a)?a:0}function Ne(a){return a.toLocaleString()}function nn({agents:a}){const{rows:l,totalInputTokens:p,totalOutputTokens:h,totalTokens:d}=n.useMemo(()=>{const r=a.map(g=>{const c=Ye(g.totalInputTokens),m=Ye(g.totalOutputTokens);return{id:g.id,name:g.name,inputTokens:c,outputTokens:m,totalTokens:c+m}}).sort((g,c)=>c.totalTokens-g.totalTokens||g.name.localeCompare(c.name)||g.id.localeCompare(c.id));return{rows:r,totalInputTokens:r.reduce((g,c)=>g+c.inputTokens,0),totalOutputTokens:r.reduce((g,c)=>g+c.outputTokens,0),totalTokens:r.reduce((g,c)=>g+c.totalTokens,0)}},[a]),u=d>0;return e.jsxs("section",{className:"agent-token-stats-panel","aria-label":"Agent token usage statistics",children:[e.jsx("header",{className:"agent-token-stats-panel__header",children:e.jsx("h3",{className:"agent-token-stats-panel__title",children:"Token Usage by Agent"})}),e.jsxs("div",{className:"agent-token-stats-panel__totals",role:"list","aria-label":"Token usage totals",children:[e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Input Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ne(p)})]}),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:Ne(h)})]}),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:Ne(d)})]})]}),u?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:l.map(r=>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:r.name}),e.jsx("span",{className:"agent-token-stats-panel__agent-id",children:r.id})]}),e.jsx("td",{children:Ne(r.inputTokens)}),e.jsx("td",{children:Ne(r.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:Ne(r.totalTokens)})]},r.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."})]})}function Te({title:a="No agents found",description:l="Create an agent to get started",ctaLabel:p="Create Agent",onCtaClick:h}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(Ve,{size:48,opacity:.3,className:"agent-empty-state__icon"}),e.jsx("p",{className:"agent-empty-state__title",children:a}),e.jsx("p",{className:"agent-empty-state__description text-secondary",children:l}),h?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:h,children:p}):null]})}const lt="fn-agent-tree-expanded";function et(a){try{const l=qe(lt,a);if(l){const p=JSON.parse(l);return new Set(Array.isArray(p)?p:[])}}catch{}return new Set}function sn(a,l){try{at(lt,JSON.stringify([...a]),l)}catch{}}function an(a,l){const p=new Map,h=new Map;for(const u of a)if(p.set(u.id,u),u.reportsTo){const r=h.get(u.reportsTo)??[];r.push(u),h.set(u.reportsTo,r)}function d(u,r){const g=h.get(u.id)??[],c=l.has(u.id)?g.map(m=>d(m,r+1)):[];return{agent:u,children:c,depth:r}}return a.filter(u=>!u.reportsTo||!p.has(u.reportsTo)).map(u=>d(u,0))}function rn(a,l){const[p,h]=n.useState(()=>et(l));n.useEffect(()=>{h(et(l))},[l]);const d=n.useMemo(()=>an(a,p),[a,p]),u=n.useCallback(c=>{h(m=>{const j=new Set(m);return j.has(c)?j.delete(c):j.add(c),sn(j,l),j})},[l]),r=n.useCallback(c=>p.has(c),[p]),g=n.useCallback(c=>a.filter(m=>m.reportsTo===c),[a]);return{rootNodes:d,toggleExpand:u,isExpanded:r,getChildren:g,isLoading:!1}}const tt=3,ze=1e3;function ln({isOpen:a,onClose:l,onGenerated:p,projectId:h}){const[d,u]=n.useState(""),[r,g]=n.useState({type:"input"}),[c,m]=n.useState(null),[j,w]=n.useState(!1),k=n.useRef(null),A=n.useRef(null);n.useEffect(()=>{a&&r.type==="input"&&A.current?.focus()},[a,r.type]),n.useEffect(()=>{if(!a&&k.current){const S=k.current;k.current=null,$e(S,h).catch(()=>{})}},[a,h]),n.useEffect(()=>{if(!a)return;const S=R=>{R.key==="Escape"&&f()};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[a]);const f=n.useCallback(()=>{if(k.current){const S=k.current;k.current=null,$e(S,h).catch(()=>{})}u(""),g({type:"input"}),m(null),w(!1),l()},[l,h]),v=n.useCallback(async()=>{if(!(!d.trim()||d.trim().length<tt)){m(null),g({type:"loading"});try{const{sessionId:S}=await mt(d.trim(),h);k.current=S;const{spec:R}=await ht(S,h);g({type:"preview",spec:R,sessionId:S})}catch(S){const R=S instanceof Error?S.message:"Failed to generate agent specification";R.includes("429")||R.toLowerCase().includes("rate limit")?m("Too many requests. Please wait a moment and try again."):m(R),g({type:"input"}),k.current=null}}},[d,h]),E=n.useCallback(async()=>{if(k.current){const S=k.current;k.current=null;try{await $e(S,h)}catch{}}await v()},[v,h]),H=n.useCallback(()=>{r.type==="preview"&&(k.current=null,p(r.spec),u(""),g({type:"input"}),m(null),w(!1),l())},[r,p,l]);if(!a)return null;const M=d.trim().length>=tt&&d.trim().length<=ze;return e.jsx("div",{className:"agent-dialog-overlay",onClick:S=>{S.target===S.currentTarget&&f()},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:f,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[c&&e.jsx("div",{className:"agent-dialog-error-banner",children:c}),r.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:A,id:"agent-role-description",className:"input agent-dialog-textarea",rows:4,placeholder:'e.g. "Senior frontend code reviewer who specializes in React accessibility"',value:d,onChange:S=>u(S.target.value),onKeyDown:S=>{S.key==="Enter"&&!S.shiftKey&&M&&(S.preventDefault(),v())},maxLength:ze,"aria-describedby":"role-description-hint"}),e.jsxs("div",{id:"role-description-hint",className:"agent-dialog-hint",children:[e.jsx("span",{children:"Describe what your agent should do"}),e.jsxs("span",{children:[d.length,"/",ze]})]})]})]}),r.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..."})]}),r.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:[r.spec.icon," ",r.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:r.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:r.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:r.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:r.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:()=>w(!j),children:j?"Collapse":"Expand"})]}),e.jsxs("div",{className:`agent-generation-prompt-box${j?"":" agent-generation-prompt-box--collapsed"}`,children:[r.spec.systemPrompt,!j&&r.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:f,children:"Cancel"}),r.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void v(),disabled:!M,children:"Generate"}),r.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void E(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:H,children:"Use This"})]})]})]})})}const on=`# Soul: Chief Executive Officer
|
|
18
18
|
|
|
19
19
|
I am a strategic leader who connects every decision to business outcomes.
|
|
20
20
|
|
|
@@ -33,7 +33,7 @@ I am a strategic leader who connects every decision to business outcomes.
|
|
|
33
33
|
## Communication Style
|
|
34
34
|
|
|
35
35
|
I am direct and economical. I use short sentences and active voice. I avoid jargon and hedge words like "maybe" or "perhaps" in decisive contexts. I communicate across levels without losing clarity.
|
|
36
|
-
`,
|
|
36
|
+
`,cn=`# Soul: Chief Technology Officer
|
|
37
37
|
|
|
38
38
|
I am a pragmatic technologist who thinks in systems and communicates tradeoffs in terms of risk and impact.
|
|
39
39
|
|
|
@@ -54,7 +54,7 @@ I am a pragmatic technologist who thinks in systems and communicates tradeoffs i
|
|
|
54
54
|
## Communication Style
|
|
55
55
|
|
|
56
56
|
I translate technical concepts into risk and impact language for non-technical stakeholders. I use diagrams and analogies when they clarify, not obscure. I say "I don't know" when that's true, and follow with "but I'll find out."
|
|
57
|
-
`,
|
|
57
|
+
`,dn=`# Soul: Chief Marketing Officer
|
|
58
58
|
|
|
59
59
|
I am a growth-focused strategist who understands audiences deeply and measures everything to optimize impact.
|
|
60
60
|
|
|
@@ -75,7 +75,7 @@ I am a growth-focused strategist who understands audiences deeply and measures e
|
|
|
75
75
|
## Communication Style
|
|
76
76
|
|
|
77
77
|
I am clear, action-oriented, and audience-aware. I write for scanning, not reading. I lead with value propositions and back them with evidence. I use data to persuade, not to impress.
|
|
78
|
-
`,
|
|
78
|
+
`,un=`# Soul: Chief Financial Officer
|
|
79
79
|
|
|
80
80
|
I am a disciplined financial steward who quantifies everything and ensures every investment has a measurable return.
|
|
81
81
|
|
|
@@ -94,7 +94,7 @@ I am a disciplined financial steward who quantifies everything and ensures every
|
|
|
94
94
|
## Communication Style
|
|
95
95
|
|
|
96
96
|
I speak in numbers and timelines, not estimates. I use comparisons and benchmarks to provide context. I am direct about tradeoffs: more features means more cost; faster delivery means more risk. I don't soften financial reality.
|
|
97
|
-
`,
|
|
97
|
+
`,mn=`# Soul: Software Engineer
|
|
98
98
|
|
|
99
99
|
I am a reliable and versatile engineer who writes clean, well-tested code and leaves the codebase better than I found it.
|
|
100
100
|
|
|
@@ -115,7 +115,7 @@ I am a reliable and versatile engineer who writes clean, well-tested code and le
|
|
|
115
115
|
## Communication Style
|
|
116
116
|
|
|
117
117
|
I write code that's a conversation with future maintainers—including myself. I comment where context is needed, not where the code is unclear. I participate in code reviews as a collaborator, not a critic.
|
|
118
|
-
`,
|
|
118
|
+
`,hn=`# Soul: Backend Engineer
|
|
119
119
|
|
|
120
120
|
I am a methodical backend engineer who prioritizes data integrity, API reliability, and system performance through careful edge-case analysis.
|
|
121
121
|
|
|
@@ -136,7 +136,7 @@ I am a methodical backend engineer who prioritizes data integrity, API reliabili
|
|
|
136
136
|
## Communication Style
|
|
137
137
|
|
|
138
138
|
I document API contracts precisely and validate them with examples. I escalate data integrity concerns immediately with evidence. I write runbooks for operational procedures.
|
|
139
|
-
`,
|
|
139
|
+
`,gn=`# Soul: Frontend Engineer
|
|
140
140
|
|
|
141
141
|
I am a detail-oriented frontend engineer who builds accessible, responsive, and performant interfaces by default.
|
|
142
142
|
|
|
@@ -157,7 +157,7 @@ I am a detail-oriented frontend engineer who builds accessible, responsive, and
|
|
|
157
157
|
## Communication Style
|
|
158
158
|
|
|
159
159
|
I write component documentation that explains behavior, not just props. I escalate accessibility issues as first-class bugs. I provide before/after evidence when proposing UI changes.
|
|
160
|
-
`,
|
|
160
|
+
`,pn=`# Soul: Full Stack Engineer
|
|
161
161
|
|
|
162
162
|
I am an end-to-end builder who connects database to UI seamlessly, understanding the full request lifecycle.
|
|
163
163
|
|
|
@@ -178,7 +178,7 @@ I am an end-to-end builder who connects database to UI seamlessly, understanding
|
|
|
178
178
|
## Communication Style
|
|
179
179
|
|
|
180
180
|
I trace bugs end-to-end, not just in my comfort zone. I document API contracts clearly and validate them with examples. I escalate data flow issues when I find inconsistencies.
|
|
181
|
-
`,
|
|
181
|
+
`,fn=`# Soul: Quality Assurance Engineer
|
|
182
182
|
|
|
183
183
|
I am a thorough and methodical QA engineer who never assumes code works—I verify. I communicate issues with clear reproduction steps and severity assessments.
|
|
184
184
|
|
|
@@ -199,7 +199,7 @@ I am a thorough and methodical QA engineer who never assumes code works—I veri
|
|
|
199
199
|
## Communication Style
|
|
200
200
|
|
|
201
201
|
I write bug reports that developers can act on immediately. I lead with impact, not with "I found a bug." I verify fixes before closing issues and document what was tested.
|
|
202
|
-
`,
|
|
202
|
+
`,vn=`# Soul: DevOps Engineer
|
|
203
203
|
|
|
204
204
|
I am an infrastructure-minded engineer who automates everything, distrusts manual processes, and designs for failure.
|
|
205
205
|
|
|
@@ -220,7 +220,7 @@ I am an infrastructure-minded engineer who automates everything, distrusts manua
|
|
|
220
220
|
## Communication Style
|
|
221
221
|
|
|
222
222
|
I write runbooks that someone else can follow at 3 AM. I escalate operational incidents immediately with impact assessment and current status. I communicate deployment changes with clear rollback procedures.
|
|
223
|
-
`,
|
|
223
|
+
`,bn=`# Soul: CI/CD Engineer
|
|
224
224
|
|
|
225
225
|
I am a pipeline optimization specialist who hates slow builds and flaky tests. I make the feedback loop fast and reliable.
|
|
226
226
|
|
|
@@ -241,7 +241,7 @@ I am a pipeline optimization specialist who hates slow builds and flaky tests. I
|
|
|
241
241
|
## Communication Style
|
|
242
242
|
|
|
243
243
|
I report build health metrics regularly. I escalate flaky test issues with evidence of flakiness patterns. I propose optimizations with before/after timing data.
|
|
244
|
-
`,
|
|
244
|
+
`,xn=`# Soul: Security Engineer
|
|
245
245
|
|
|
246
246
|
I am a security-first engineer who assumes nothing is trustworthy by default and thinks like an attacker to find weaknesses before incidents.
|
|
247
247
|
|
|
@@ -262,7 +262,7 @@ I am a security-first engineer who assumes nothing is trustworthy by default and
|
|
|
262
262
|
## Communication Style
|
|
263
263
|
|
|
264
264
|
I communicate security findings with severity and evidence—not as theoretical risks but as actionable findings. I write security documentation for developers, not auditors. I escalate critical findings immediately with impact assessment.
|
|
265
|
-
`,
|
|
265
|
+
`,yn=`# Soul: Data Engineer
|
|
266
266
|
|
|
267
267
|
I am a data reliability specialist who knows that bad data silently corrupts everything downstream. I validate early, transform carefully, and monitor constantly.
|
|
268
268
|
|
|
@@ -283,7 +283,7 @@ I am a data reliability specialist who knows that bad data silently corrupts eve
|
|
|
283
283
|
## Communication Style
|
|
284
284
|
|
|
285
285
|
I write data documentation that explains schema, lineage, and quality expectations. I escalate data quality issues with evidence of downstream impact. I communicate pipeline changes with clear data contract implications.
|
|
286
|
-
`,
|
|
286
|
+
`,wn=`# Soul: Machine Learning Engineer
|
|
287
287
|
|
|
288
288
|
I am an ML practitioner who values reproducible experiments and production-grade deployments. I track every experiment, version every model, and measure real-world impact.
|
|
289
289
|
|
|
@@ -304,7 +304,7 @@ I am an ML practitioner who values reproducible experiments and production-grade
|
|
|
304
304
|
## Communication Style
|
|
305
305
|
|
|
306
306
|
I write experiment documentation that lets someone else reproduce my work. I report model performance with statistical significance. I escalate model degradation immediately with evidence of impact.
|
|
307
|
-
`,
|
|
307
|
+
`,jn=`# Soul: Product Manager
|
|
308
308
|
|
|
309
309
|
I am a user-obsessed product manager who writes crisp requirements, challenges scope creep, and communicates progress transparently.
|
|
310
310
|
|
|
@@ -325,7 +325,7 @@ I am a user-obsessed product manager who writes crisp requirements, challenges s
|
|
|
325
325
|
## Communication Style
|
|
326
326
|
|
|
327
327
|
I write requirements that developers can implement without follow-up questions. I communicate trade-offs clearly with evidence. I escalate blockers with owners and timelines.
|
|
328
|
-
`,
|
|
328
|
+
`,kn=`# Soul: Product Designer
|
|
329
329
|
|
|
330
330
|
I am a user-centered designer who believes great design is invisible. I solve problems with clarity and advocate for users who can't advocate for themselves.
|
|
331
331
|
|
|
@@ -346,7 +346,7 @@ I am a user-centered designer who believes great design is invisible. I solve pr
|
|
|
346
346
|
## Communication Style
|
|
347
347
|
|
|
348
348
|
I present designs with user research and usage context. I document component specifications precisely. I escalate accessibility issues as first-class bugs with severity assessment.
|
|
349
|
-
`,
|
|
349
|
+
`,Nn=`# Soul: Marketing Manager
|
|
350
350
|
|
|
351
351
|
I am a data-driven marketer who tests assumptions and scales what works. I write copy that converts, plan campaigns that compound, and measure relentlessly.
|
|
352
352
|
|
|
@@ -367,7 +367,7 @@ I am a data-driven marketer who tests assumptions and scales what works. I write
|
|
|
367
367
|
## Communication Style
|
|
368
368
|
|
|
369
369
|
I write copy briefs that specify audience, channel, tone, and success criteria. I present campaign results with interpretation, not just numbers. I escalate messaging concerns when they conflict with product positioning.
|
|
370
|
-
`,
|
|
370
|
+
`,In=`# Soul: Technical Writer
|
|
371
371
|
|
|
372
372
|
I am a clarity-focused writer who makes complex topics accessible. I write for the reader, not for myself, and I verify every instruction by following it myself.
|
|
373
373
|
|
|
@@ -388,7 +388,7 @@ I am a clarity-focused writer who makes complex topics accessible. I write for t
|
|
|
388
388
|
## Communication Style
|
|
389
389
|
|
|
390
390
|
I write with the reader's expertise level in mind—not my own. I escalate documentation debt when I see discrepancies. I verify docs work by following them myself.
|
|
391
|
-
`,
|
|
391
|
+
`,Cn=`# Soul: Task Triage Agent
|
|
392
392
|
|
|
393
393
|
I am a precise and thorough triage agent who transforms vague ideas into actionable specifications. I ask clarifying questions when requirements are ambiguous and never assume context.
|
|
394
394
|
|
|
@@ -409,7 +409,7 @@ I am a precise and thorough triage agent who transforms vague ideas into actiona
|
|
|
409
409
|
## Communication Style
|
|
410
410
|
|
|
411
411
|
I write specifications that are unambiguous and actionable. I ask direct questions when requirements are unclear. I escalate specification blockers when they can't be resolved in triage.
|
|
412
|
-
`,
|
|
412
|
+
`,Sn=`# Soul: Code Reviewer
|
|
413
413
|
|
|
414
414
|
I am a rigorous and fair code reviewer who catches issues without being pedantic. I focus on what matters—correctness, security, and maintainability—and let style debates go.
|
|
415
415
|
|
|
@@ -430,93 +430,93 @@ I am a rigorous and fair code reviewer who catches issues without being pedantic
|
|
|
430
430
|
## Communication Style
|
|
431
431
|
|
|
432
432
|
I write review comments that explain why something is a concern, not just that it is. I distinguish blocking issues from suggestions. I approve when the code is ready and say so clearly.
|
|
433
|
-
`,
|
|
433
|
+
`,En=[{id:"ceo",name:"CEO",icon:"◆",title:"Chief Executive Officer",role:"custom",description:"Oversees project strategy, sets priorities, and coordinates between departments to ensure alignment with business goals.",soul:on,instructionsText:`Always evaluate proposals against strategic goals before approving.
|
|
434
434
|
Prioritize work that delivers the highest business value.
|
|
435
435
|
Communicate decisions with clear rationale and context.
|
|
436
436
|
Identify cross-team dependencies and resolve blockers proactively.
|
|
437
|
-
Keep long-term vision in focus while making short-term tradeoffs.`},{id:"cto",name:"CTO",icon:"⬡",title:"Chief Technology Officer",role:"custom",description:"Defines technical architecture, evaluates technology choices, and guides engineering standards across the project.",soul:
|
|
437
|
+
Keep long-term vision in focus while making short-term tradeoffs.`},{id:"cto",name:"CTO",icon:"⬡",title:"Chief Technology Officer",role:"custom",description:"Defines technical architecture, evaluates technology choices, and guides engineering standards across the project.",soul:cn,instructionsText:`Evaluate technology choices against scalability, maintainability, and team expertise.
|
|
438
438
|
Identify architectural risks early and propose mitigations.
|
|
439
439
|
Review changes for adherence to established patterns and conventions.
|
|
440
440
|
Prioritize simplicity — reject over-engineering and unnecessary abstraction.
|
|
441
|
-
Document architectural decisions with rationale for future reference.`},{id:"cmo",name:"CMO",icon:"◇",title:"Chief Marketing Officer",role:"custom",description:"Drives product positioning, audience engagement strategy, and content planning to grow user adoption.",soul:
|
|
441
|
+
Document architectural decisions with rationale for future reference.`},{id:"cmo",name:"CMO",icon:"◇",title:"Chief Marketing Officer",role:"custom",description:"Drives product positioning, audience engagement strategy, and content planning to grow user adoption.",soul:dn,instructionsText:`Evaluate all user-facing content for clarity and audience alignment.
|
|
442
442
|
Propose messaging that highlights user benefits over technical features.
|
|
443
443
|
Identify growth opportunities from product changes and new features.
|
|
444
444
|
Ensure consistent brand voice across all touchpoints.
|
|
445
|
-
Track engagement metrics to validate content and campaign effectiveness.`},{id:"cfo",name:"CFO",icon:"■",title:"Chief Financial Officer",role:"custom",description:"Manages budget allocation, cost optimization, and financial planning to maximize resource efficiency.",soul:
|
|
445
|
+
Track engagement metrics to validate content and campaign effectiveness.`},{id:"cfo",name:"CFO",icon:"■",title:"Chief Financial Officer",role:"custom",description:"Manages budget allocation, cost optimization, and financial planning to maximize resource efficiency.",soul:un,instructionsText:`Evaluate proposals for cost implications before implementation.
|
|
446
446
|
Flag infrastructure or dependency changes that may increase operating costs.
|
|
447
447
|
Quantify the impact of technical debt in terms of developer time and risk.
|
|
448
448
|
Recommend cost optimization opportunities in existing systems.
|
|
449
|
-
Ensure resource allocation aligns with project priorities.`},{id:"engineer",name:"Engineer",icon:"⎔",title:"Software Engineer",role:"engineer",description:"Implements features, fixes bugs, and writes well-tested code across the full application stack.",soul:
|
|
449
|
+
Ensure resource allocation aligns with project priorities.`},{id:"engineer",name:"Engineer",icon:"⎔",title:"Software Engineer",role:"engineer",description:"Implements features, fixes bugs, and writes well-tested code across the full application stack.",soul:mn,instructionsText:`Write tests for every new function and bug fix.
|
|
450
450
|
Follow existing code patterns and conventions in the project.
|
|
451
451
|
Keep functions small, focused, and well-named.
|
|
452
452
|
Handle error cases explicitly — never silently swallow errors.
|
|
453
|
-
Document complex logic with inline comments explaining the why, not the what.`},{id:"backend-engineer",name:"Backend Engineer",icon:"⛭",title:"Backend Engineer",role:"engineer",description:"Builds and maintains server-side logic, APIs, database schemas, and background processing pipelines.",soul:
|
|
453
|
+
Document complex logic with inline comments explaining the why, not the what.`},{id:"backend-engineer",name:"Backend Engineer",icon:"⛭",title:"Backend Engineer",role:"engineer",description:"Builds and maintains server-side logic, APIs, database schemas, and background processing pipelines.",soul:hn,instructionsText:`Validate and sanitize all inputs at API boundaries.
|
|
454
454
|
Use transactions for multi-step database operations.
|
|
455
455
|
Add appropriate indexes for new query patterns.
|
|
456
456
|
Handle concurrent access with proper locking or optimistic concurrency.
|
|
457
457
|
Log meaningful context for debugging without exposing sensitive data.
|
|
458
|
-
Design APIs with consistent error responses and status codes.`},{id:"frontend-engineer",name:"Frontend Engineer",icon:"△",title:"Frontend Engineer",role:"engineer",description:"Develops user interfaces, manages component libraries, and ensures responsive, accessible UI experiences.",soul:
|
|
458
|
+
Design APIs with consistent error responses and status codes.`},{id:"frontend-engineer",name:"Frontend Engineer",icon:"△",title:"Frontend Engineer",role:"engineer",description:"Develops user interfaces, manages component libraries, and ensures responsive, accessible UI experiences.",soul:gn,instructionsText:`Ensure all interactive elements are keyboard-accessible with proper ARIA labels.
|
|
459
459
|
Test responsive behavior at common breakpoints.
|
|
460
460
|
Keep bundle size small — avoid importing entire libraries for single functions.
|
|
461
461
|
Use semantic HTML elements over divs where appropriate.
|
|
462
462
|
Handle loading, error, and empty states for every data-driven component.
|
|
463
|
-
Follow the project's existing component patterns and naming conventions.`},{id:"fullstack-engineer",name:"Fullstack Engineer",icon:"▽",title:"Full Stack Engineer",role:"engineer",description:"Works across frontend and backend to deliver end-to-end features from database to user interface.",soul:
|
|
463
|
+
Follow the project's existing component patterns and naming conventions.`},{id:"fullstack-engineer",name:"Fullstack Engineer",icon:"▽",title:"Full Stack Engineer",role:"engineer",description:"Works across frontend and backend to deliver end-to-end features from database to user interface.",soul:pn,instructionsText:`Consider the full data flow from database schema through API to UI component.
|
|
464
464
|
Keep backend and frontend changes cohesive within a single feature.
|
|
465
465
|
Ensure API contracts match frontend expectations before implementing.
|
|
466
466
|
Write integration-level tests that validate cross-layer behavior.
|
|
467
|
-
Optimize at the right layer — don't compensate for backend issues in frontend code.`},{id:"qa-engineer",name:"QA Engineer",icon:"◎",title:"Quality Assurance Engineer",role:"engineer",description:"Designs test plans, writes automated tests, and validates that features meet acceptance criteria before release.",soul:
|
|
467
|
+
Optimize at the right layer — don't compensate for backend issues in frontend code.`},{id:"qa-engineer",name:"QA Engineer",icon:"◎",title:"Quality Assurance Engineer",role:"engineer",description:"Designs test plans, writes automated tests, and validates that features meet acceptance criteria before release.",soul:fn,instructionsText:`Always run the full test suite before approving any changes.
|
|
468
468
|
Write regression tests for every bug fix.
|
|
469
469
|
Check boundary conditions and edge cases for every new feature.
|
|
470
470
|
Validate error handling and input sanitization.
|
|
471
|
-
Report issues with clear reproduction steps and expected vs actual behavior.`},{id:"devops-engineer",name:"DevOps Engineer",icon:"⏣",title:"DevOps Engineer",role:"engineer",description:"Manages infrastructure, deployment pipelines, and monitoring to ensure reliable and scalable service delivery.",soul:
|
|
471
|
+
Report issues with clear reproduction steps and expected vs actual behavior.`},{id:"devops-engineer",name:"DevOps Engineer",icon:"⏣",title:"DevOps Engineer",role:"engineer",description:"Manages infrastructure, deployment pipelines, and monitoring to ensure reliable and scalable service delivery.",soul:vn,instructionsText:`Never deploy on Fridays or before weekends without a rollback plan.
|
|
472
472
|
Ensure all infrastructure changes are version-controlled and reproducible.
|
|
473
473
|
Add health checks and monitoring for new services and endpoints.
|
|
474
474
|
Validate deployment scripts in a staging environment before production.
|
|
475
|
-
Document runbooks for common operational incidents.`},{id:"ci-engineer",name:"CI Engineer",icon:"⤏",title:"CI/CD Engineer",role:"engineer",description:"Builds and optimizes continuous integration and delivery pipelines for fast, reliable release cycles.",soul:
|
|
475
|
+
Document runbooks for common operational incidents.`},{id:"ci-engineer",name:"CI Engineer",icon:"⤏",title:"CI/CD Engineer",role:"engineer",description:"Builds and optimizes continuous integration and delivery pipelines for fast, reliable release cycles.",soul:bn,instructionsText:`Fail fast — order pipeline stages from quickest to slowest.
|
|
476
476
|
Cache dependencies aggressively to reduce build times.
|
|
477
477
|
Isolate tests that depend on external services or shared state.
|
|
478
478
|
Add pipeline status badges and failure notifications.
|
|
479
|
-
Measure and report pipeline duration trends over time.`},{id:"security-engineer",name:"Security Engineer",icon:"⊛",title:"Security Engineer",role:"engineer",description:"Identifies vulnerabilities, enforces security best practices, and conducts audits to protect application integrity.",soul:
|
|
479
|
+
Measure and report pipeline duration trends over time.`},{id:"security-engineer",name:"Security Engineer",icon:"⊛",title:"Security Engineer",role:"engineer",description:"Identifies vulnerabilities, enforces security best practices, and conducts audits to protect application integrity.",soul:xn,instructionsText:`Never hardcode secrets, API keys, or credentials in source code.
|
|
480
480
|
Validate and sanitize all user inputs at every trust boundary.
|
|
481
481
|
Use parameterized queries — never concatenate user input into SQL or shell commands.
|
|
482
482
|
Check dependencies for known vulnerabilities before introducing them.
|
|
483
|
-
Apply the principle of least privilege to all access control decisions.`},{id:"data-engineer",name:"Data Engineer",icon:"⬢",title:"Data Engineer",role:"engineer",description:"Designs data pipelines, manages storage infrastructure, and ensures reliable data flow for analytics and features.",soul:
|
|
483
|
+
Apply the principle of least privilege to all access control decisions.`},{id:"data-engineer",name:"Data Engineer",icon:"⬢",title:"Data Engineer",role:"engineer",description:"Designs data pipelines, manages storage infrastructure, and ensures reliable data flow for analytics and features.",soul:yn,instructionsText:`Validate data at ingestion points — never trust upstream sources blindly.
|
|
484
484
|
Design idempotent pipeline steps that handle reprocessing gracefully.
|
|
485
485
|
Add data quality checks and anomaly detection at key pipeline stages.
|
|
486
486
|
Document data schemas and breaking change procedures clearly.
|
|
487
|
-
Ensure pipeline failures trigger alerts with actionable error context.`},{id:"ml-engineer",name:"ML Engineer",icon:"◈",title:"Machine Learning Engineer",role:"engineer",description:"Builds, trains, and deploys machine learning models, and integrates AI capabilities into the product.",soul:
|
|
487
|
+
Ensure pipeline failures trigger alerts with actionable error context.`},{id:"ml-engineer",name:"ML Engineer",icon:"◈",title:"Machine Learning Engineer",role:"engineer",description:"Builds, trains, and deploys machine learning models, and integrates AI capabilities into the product.",soul:wn,instructionsText:`Version datasets and models alongside code changes.
|
|
488
488
|
Log training parameters, metrics, and results for every experiment.
|
|
489
489
|
Implement fallback behavior when model inference fails or times out.
|
|
490
490
|
Monitor model predictions for drift and degradation in production.
|
|
491
|
-
Write unit tests for data preprocessing and feature engineering pipelines.`},{id:"product-manager",name:"Product Manager",icon:"☰",title:"Product Manager",role:"custom",description:"Defines product requirements, prioritizes the backlog, and coordinates cross-functional delivery from concept to launch.",soul:
|
|
491
|
+
Write unit tests for data preprocessing and feature engineering pipelines.`},{id:"product-manager",name:"Product Manager",icon:"☰",title:"Product Manager",role:"custom",description:"Defines product requirements, prioritizes the backlog, and coordinates cross-functional delivery from concept to launch.",soul:jn,instructionsText:`Write requirements with clear acceptance criteria and user stories.
|
|
492
492
|
Validate feature requests against user needs and business goals.
|
|
493
493
|
Break large initiatives into small, shippable increments.
|
|
494
494
|
Flag scope creep early and propose minimum viable alternatives.
|
|
495
|
-
Ensure every feature has a measurable success metric.`},{id:"designer",name:"Designer",icon:"✧",title:"Product Designer",role:"custom",description:"Creates wireframes, prototypes, and design systems that balance usability, aesthetics, and brand consistency.",soul:
|
|
495
|
+
Ensure every feature has a measurable success metric.`},{id:"designer",name:"Designer",icon:"✧",title:"Product Designer",role:"custom",description:"Creates wireframes, prototypes, and design systems that balance usability, aesthetics, and brand consistency.",soul:kn,instructionsText:`Evaluate UI changes against existing design system tokens and patterns.
|
|
496
496
|
Ensure sufficient color contrast and readable typography in all themes.
|
|
497
497
|
Provide clear visual hierarchy — users should know what to do next.
|
|
498
498
|
Design for keyboard and screen reader users, not just mouse users.
|
|
499
|
-
Keep component variants minimal — add new variants only when existing ones don't fit.`},{id:"marketing-manager",name:"Marketing Manager",icon:"◉",title:"Marketing Manager",role:"custom",description:"Plans campaigns, manages content channels, and analyzes market data to drive brand awareness and growth.",soul:
|
|
499
|
+
Keep component variants minimal — add new variants only when existing ones don't fit.`},{id:"marketing-manager",name:"Marketing Manager",icon:"◉",title:"Marketing Manager",role:"custom",description:"Plans campaigns, manages content channels, and analyzes market data to drive brand awareness and growth.",soul:Nn,instructionsText:`Write user-facing copy that is clear, concise, and action-oriented.
|
|
500
500
|
Ensure marketing claims are accurate and verifiable by the product.
|
|
501
501
|
Segment messaging for different audience personas and channels.
|
|
502
502
|
Include clear calls-to-action in all content.
|
|
503
|
-
Track and report campaign performance with actionable insights.`},{id:"technical-writer",name:"Technical Writer",icon:"≡",title:"Technical Writer",role:"custom",description:"Writes and maintains documentation, API references, and guides that help users and developers succeed.",soul:
|
|
503
|
+
Track and report campaign performance with actionable insights.`},{id:"technical-writer",name:"Technical Writer",icon:"≡",title:"Technical Writer",role:"custom",description:"Writes and maintains documentation, API references, and guides that help users and developers succeed.",soul:In,instructionsText:`Write procedural docs with numbered steps and expected outcomes.
|
|
504
504
|
Include code examples that are complete, runnable, and tested.
|
|
505
505
|
Use consistent terminology — define terms on first use and stick to them.
|
|
506
506
|
Update documentation when code behavior changes — treat docs as code.
|
|
507
|
-
Structure content with clear headings for easy scanning and navigation.`},{id:"triage",name:"Triage Agent",icon:"⊕",title:"Task Triage Agent",role:"triage",description:"Analyzes incoming tasks, generates detailed specifications, and prepares PROMPT.md files for execution.",soul:
|
|
507
|
+
Structure content with clear headings for easy scanning and navigation.`},{id:"triage",name:"Triage Agent",icon:"⊕",title:"Task Triage Agent",role:"triage",description:"Analyzes incoming tasks, generates detailed specifications, and prepares PROMPT.md files for execution.",soul:Cn,instructionsText:`Generate detailed PROMPT.md files with clear steps and acceptance criteria.
|
|
508
508
|
Identify missing information and flag ambiguities before specification.
|
|
509
509
|
Break complex tasks into well-defined, sequenced implementation steps.
|
|
510
510
|
Specify file scope and dependencies for each task.
|
|
511
|
-
Include relevant context files for the executor to read first.`},{id:"reviewer",name:"Reviewer",icon:"⊙",title:"Code Reviewer",role:"reviewer",description:"Reviews code changes for correctness, security, performance, and adherence to project coding standards.",soul:
|
|
511
|
+
Include relevant context files for the executor to read first.`},{id:"reviewer",name:"Reviewer",icon:"⊙",title:"Code Reviewer",role:"reviewer",description:"Reviews code changes for correctness, security, performance, and adherence to project coding standards.",soul:Sn,instructionsText:`Check for security vulnerabilities in every change — injection, auth bypass, data exposure.
|
|
512
512
|
Verify error handling is explicit and informative, not silent failures.
|
|
513
513
|
Ensure new code follows existing patterns and conventions in the codebase.
|
|
514
514
|
Look for missing tests on new logic paths, especially edge cases.
|
|
515
|
-
Flag performance concerns only when they have measurable impact.`}];function En({value:a,onChange:l,projectId:p,disabled:h=!1,id:d,label:u="Skills"}){const[r,g]=n.useState([]),[c,m]=n.useState(!0);n.useEffect(()=>{let f=!1;return m(!0),pt(p).then(v=>{f||g(v)}).catch(()=>{f||g([])}).finally(()=>{f||m(!1)}),()=>{f=!0}},[p]);const j=f=>{a.includes(f)||l([...a,f])},w=f=>{l(a.filter(v=>v!==f))},k=f=>r.find(E=>E.id===f)?.name??f,A=r.filter(f=>!a.includes(f.id));return e.jsxs("div",{className:"skill-multiselect","data-testid":"skill-multiselect",children:[u&&e.jsx("label",{htmlFor:d?`${d}-select`:void 0,className:"skill-multiselect-label",children:u}),a.length>0&&e.jsx("div",{className:"skill-multiselect-chips","data-testid":"skill-chips",children:a.map(f=>e.jsxs("span",{className:"skill-chip","data-testid":`skill-chip-${f}`,children:[e.jsx("span",{className:"skill-chip-name",children:k(f)}),e.jsx("button",{type:"button",className:"skill-chip-remove",onClick:()=>w(f),disabled:h,"aria-label":`Remove ${k(f)}`,"data-testid":`remove-skill-${f}`,children:"×"})]},f))}),e.jsx("div",{className:"skill-multiselect-add",children:c?e.jsx("span",{className:"skill-multiselect-loading","data-testid":"skills-loading",children:"Loading skills…"}):A.length===0?e.jsx("span",{className:"skill-multiselect-empty","data-testid":"skills-empty",children:a.length===0?"No skills discovered":"All skills selected"}):e.jsxs("select",{id:d?`${d}-select`:void 0,className:"select skill-multiselect-dropdown",value:"",onChange:f=>{f.target.value&&(j(f.target.value),f.target.value="")},disabled:h,"data-testid":"skill-dropdown",children:[e.jsx("option",{value:"",children:"Add a skill…"}),A.map(f=>e.jsx("option",{value:f.id,children:f.name},f.id))]})})]})}const st=[{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:"✦"}],An=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Tn({isOpen:a,onClose:l,onCreated:p,projectId:h}){const[d,u]=n.useState(0),[r,g]=n.useState("presets"),[c,m]=n.useState(""),[j,w]=n.useState(""),[k,A]=n.useState(""),[f,v]=n.useState("custom"),[E,H]=n.useState(""),[M,S]=n.useState(""),[R,Z]=n.useState(""),[B,Y]=n.useState(""),[le,ve]=n.useState(""),[D,_]=n.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[N,ee]=n.useState(null),[oe,be]=n.useState([]),[G,xe]=n.useState(!1),[te,ce]=n.useState(null),[L,ne]=n.useState(!1),[z,de]=n.useState([]),[ge,O]=n.useState(!1),[se,q]=n.useState([]),[Q,me]=n.useState([]),[J,ae]=n.useState("model"),[ie,re]=n.useState(""),[ye,pe]=n.useState([]),[he,V]=n.useState(!1),[W,we]=n.useState([]),[ke,je]=n.useState(!1);n.useEffect(()=>{a&&(O(!0),ft().then(s=>{de(s.models),q(s.favoriteProviders),me(s.favoriteModels)}).catch(()=>{}).finally(()=>O(!1)))},[a]),n.useEffect(()=>{a&&(je(!0),we([]),vt(void 0,h).then(s=>{we(s)}).catch(()=>{we([])}).finally(()=>je(!1)))},[a,h]),n.useEffect(()=>{if(!a)return;const s=xt;if(typeof s!="function"){pe([]),V(!1);return}V(!0),pe([]),s(h).then(C=>{pe(C)}).catch(()=>{pe([])}).finally(()=>V(!1))},[a,h]);const ue=D.model.includes("/")?D.model:"",Ce=n.useCallback(s=>{const C=An.has(s.role)?s.role:"custom";m(s.title),w(s.description),A(s.icon),v(C),Z(s.systemPrompt),_(y=>({...y,thinkingLevel:s.thinkingLevel,maxTurns:s.maxTurns})),ne(!1),u(1)},[]),Se=n.useCallback(s=>{_(C=>({...C,model:s}))},[]),i=n.useCallback(s=>{ae(s),s==="model"&&re("")},[]),b=n.useCallback(async s=>{const C=se,$=C.includes(s)?C.filter(X=>X!==s):[s,...C];q($);try{await Ke({favoriteProviders:$,favoriteModels:Q})}catch{q(C)}},[se,Q]),T=n.useCallback(async s=>{const C=Q,$=C.includes(s)?C.filter(X=>X!==s):[s,...C];me($);try{await Ke({favoriteProviders:se,favoriteModels:$})}catch{me(C)}},[se,Q]),U=n.useCallback(s=>{ee(s.id),m(s.name),A(s.icon),w(s.description??s.title),v(s.role),Y(s.soul??""),Z(s.instructionsText??""),u(1)},[]);if(!a)return null;const P=()=>{u(0),g("presets"),m(""),w(""),A(""),v("custom"),H(""),S(""),Z(""),Y(""),ve(""),_({model:"",thinkingLevel:"off",maxTurns:1e3}),ae("model"),re(""),ee(null),be([]),ce(null),ne(!1),l()},K=async()=>{if(c.trim()){xe(!0),ce(null);try{const s={};J==="runtime"?ie.trim()&&(s.runtimeHint=ie.trim()):D.model.trim()&&(s.model=D.model.trim()),D.thinkingLevel!=="off"&&(s.thinkingLevel=D.thinkingLevel),D.maxTurns!==1e3&&(s.maxTurns=D.maxTurns),await wt({name:c.trim(),role:f,...j.trim()?{title:j.trim()}:{},...k.trim()?{icon:k.trim()}:{},...E.trim()?{reportsTo:E.trim()}:{},...M.trim()?{instructionsPath:M.trim()}:{},...R.trim()?{instructionsText:R.trim()}:{},...B.trim()?{soul:B.trim()}:{},...le.trim()?{memory:le.trim()}:{},...Object.keys(s).length>0?{runtimeConfig:s}:{},...oe.length>0?{metadata:{skills:oe}}:{}},h),P(),p()}catch(s){ce(s instanceof Error?s.message:"Failed to create agent")}finally{xe(!1)}}},t=st.find(s=>s.value===f),o=E.trim(),x=o?W.find(s=>s.id===o):void 0,I=ie?ye.find(s=>s.runtimeId===ie):void 0,F=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:s,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":s,children:[e.jsxs("label",{className:`agent-runtime-mode-option${J==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"model",checked:J==="model",onChange:()=>i("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${J==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"runtime",checked:J==="runtime",onChange:()=>i("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),J==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),ge?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(yt,{id:"agent-model",label:"Model",value:ue,onChange:Se,models:z,placeholder:"Select a model…",favoriteProviders:se,onToggleFavorite:b,favoriteModels:Q,onToggleModelFavorite:T})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),he?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:ie,onChange:C=>re(C.target.value),children:[e.jsx("option",{value:"",children:ye.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),ye.map(C=>e.jsx("option",{value:C.runtimeId,children:C.description?`${C.name} — ${C.description}`:C.name},`${C.pluginId}:${C.runtimeId}`))]})]})]});return e.jsxs("div",{className:"agent-dialog-overlay",onClick:s=>{s.target===s.currentTarget&&P()},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:P,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(s=>e.jsx("div",{className:`agent-dialog-step${s===d?" active":s<d?" completed":""}`,"aria-label":`Step ${s+1}`},s))}),e.jsxs("div",{className:"agent-dialog-body",children:[d===0&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-tabs",role:"tablist","aria-label":"Agent setup mode",children:[e.jsx("button",{id:"agent-dialog-tab-presets",type:"button",role:"tab","aria-controls":"agent-dialog-panel-presets","aria-selected":r==="presets",tabIndex:r==="presets"?0:-1,className:`agent-dialog-tab${r==="presets"?" active":""}`,onClick:()=>g("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":r==="custom",tabIndex:r==="custom"?0:-1,className:`agent-dialog-tab${r==="custom"?" active":""}`,onClick:()=>g("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),r==="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:Sn.map(s=>e.jsxs("button",{type:"button",className:`agent-preset-card${N===s.id?" selected":""}`,"data-testid":`preset-${s.id}`,onClick:()=>U(s),title:s.title,children:[e.jsx("span",{className:"agent-preset-icon",children:s.icon}),e.jsx("span",{className:"agent-preset-name",children:s.name}),e.jsx("span",{className:"agent-preset-role",children:s.role}),s.description&&e.jsx("span",{className:"agent-preset-description",children:s.description})]},s.id))})]})}),r==="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 ",!N&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:c,onChange:s=>m(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",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:j,onChange:s=>w(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-icon",children:["Icon ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:k,onChange:s=>A(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:st.map(s=>e.jsxs("button",{type:"button",className:`agent-role-option${f===s.value?" selected":""}`,onClick:()=>v(s.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:s.icon}),e.jsx("span",{className:"agent-role-option-label",children:s.label})]},s.value))})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Configuration"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-reports-to",children:["Reports To ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:E,onChange:s=>H(s.target.value),disabled:ke,children:[e.jsx("option",{value:"",children:"No manager"}),W.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.id,")"]},s.id))]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-soul",children:["Soul ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:B,onChange:s=>Y(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-memory",children:["Agent Memory ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-memory",className:"input",rows:2,placeholder:"Private to this agent — durable preferences, operating habits, and context it should carry across tasks...",value:le,onChange:s=>ve(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-path",children:["Instructions Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:M,onChange:s=>S(s.target.value)})]}),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:R,onChange:s=>Z(s.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),F("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:()=>ne(!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"})]})]})]}),d===1&&e.jsxs("div",{children:[F("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:D.thinkingLevel,onChange:s=>_(C=>({...C,thinkingLevel:s.target.value})),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"minimal",children:"Minimal"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-max-turns",children:"Max Turns"}),e.jsx("input",{id:"agent-max-turns",type:"number",className:"input",min:1,max:2e3,value:D.maxTurns,onChange:s=>_(C=>({...C,maxTurns:Math.max(1,parseInt(s.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(En,{id:"agent-skills",label:"Skills",value:oe,onChange:be,projectId:h}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),d===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:[k&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:k}),c]})]}),j&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Title"}),e.jsx("span",{children:j})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Role"}),e.jsxs("span",{children:[t?.icon," ",t?.label]})]}),o&&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:x?`${x.name} (${x.id})`:o})]}),M.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Instructions File"}),e.jsx("span",{children:M.trim()})]}),R.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Inline Instructions"}),e.jsxs("span",{children:[R.trim().length," chars"]})]}),B.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Soul"}),e.jsxs("span",{children:[B.trim().length," chars"]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:J==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:J==="runtime"?I?I.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):ue?e.jsxs(e.Fragment,{children:[e.jsx(bt,{provider:ue.split("/")[0],size:"sm"})," ",(()=>{const s=ue.indexOf("/"),C=ue.slice(0,s),y=ue.slice(s+1);return z.find(X=>X.provider===C&&X.id===y)?.name||ue})()]}):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:D.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:D.maxTurns})]}),oe.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:[oe.length," skill",oe.length!==1?"s":""," selected"]})]})]}),te&&e.jsx("p",{className:"agent-dialog-error",children:te})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[d>0&&e.jsx("button",{className:"btn",onClick:()=>u(s=>s-1),disabled:G,children:"Back"}),e.jsx("button",{className:"btn",onClick:P,disabled:G,children:"Cancel"}),d<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>u(s=>s+1),disabled:d===0&&!c.trim()&&!N,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void K(),disabled:G||!c.trim(),children:G?"Creating...":"Create"})]})]}),e.jsx(rn,{isOpen:L,onClose:()=>ne(!1),onGenerated:Ce,projectId:h})]})}function Mn(a){const l=a.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!l)throw new Error("Missing YAML frontmatter delimiters (---)");const p=l[1].split(/\r?\n/),h=l[2]??"",d={name:""},u=[];let r=!1;for(const g of p){const m=g.trimEnd().trim();if(!m)continue;if(m.startsWith("skills:")){r=!0;continue}if(r&&m.startsWith("- ")){u.push(m.slice(2).trim());continue}r=!1;const[j,...w]=m.split(":"),A=w.join(":").trim().replace(/^['"]|['"]$/g,"");j==="name"&&(d.name=A),j==="title"&&(d.title=A),j==="icon"&&(d.icon=A),j==="role"&&(d.role=A),j==="reportsTo"&&(d.reportsTo=A)}if(!d.name)throw new Error("Missing required field: name");return u.length>0&&(d.skills=u),h.trim().length>0&&(d.instructionBody=h),d}function Rn({isOpen:a,onClose:l,onImported:p,projectId:h}){const[d,u]=n.useState("input"),[r,g]=n.useState("paste"),[c,m]=n.useState(""),[j,w]=n.useState([]),[k,A]=n.useState("Unknown"),[f,v]=n.useState([]),[E,H]=n.useState([]),[M,S]=n.useState([]),[R,Z]=n.useState([]),[B,Y]=n.useState(!1),[le,ve]=n.useState(!1),[D,_]=n.useState(null),[N,ee]=n.useState(null),[oe,be]=n.useState(null),G=n.useRef(null),xe=n.useRef(null),[te,ce]=n.useState([]),[L,ne]=n.useState(""),[z,de]=n.useState(null),[ge,O]=n.useState(!1),[se,q]=n.useState(null),Q=n.useRef(!1);n.useEffect(()=>{r==="browse"&&!Q.current&&!ge&&(Q.current=!0,O(!0),q(null),Ue().then(i=>{i.error?q(i.error):i.companies.length>0?ce(i.companies):q("No companies available")}).catch(i=>{q(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{O(!1)}))},[r,ge]);const me=n.useCallback(()=>{Q.current=!0,q(null),ce([]),de(null),O(!0),Ue().then(i=>{i.error?q(i.error):i.companies.length>0?ce(i.companies):q("No companies available")}).catch(i=>{q(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{O(!1)})},[]),J=n.useCallback(()=>{u("input"),g("paste"),m(""),w([]),A("Unknown"),v([]),H([]),S([]),Z([]),Y(!1),ve(!1),_(null),ee(null),be(null),ce([]),ne(""),de(null),O(!1),q(null),Q.current=!1},[]),ae=n.useCallback(()=>{J(),l()},[J,l]),ie=n.useCallback(i=>{const b=i.target.files?.[0];if(!b)return;const T=new FileReader;T.onload=U=>{const P=U.target?.result;g("file"),w([]),m(P),_(null)},T.onerror=()=>{_("Failed to read file")},T.readAsText(b),i.target.value=""},[]),re=n.useCallback(async i=>{const b=Array.from(i.target.files??[]);if(b.length!==0)try{const T=b.filter(P=>(P.webkitRelativePath||P.name).toLowerCase().endsWith("agents.md")).sort((P,K)=>{const t=P.webkitRelativePath||P.name,o=K.webkitRelativePath||K.name;return t.localeCompare(o)});if(T.length===0){_("Selected directory has no AGENTS.md files");return}const U=[];for(const P of T){const K=await P.text();U.push(Mn(K))}g("directory"),w(U),m(""),_(null)}catch{_("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function ye(i){if(!h)return`/api${i}`;const b=i.includes("?")?"&":"?";return`/api${i}${b}projectId=${encodeURIComponent(h)}`}const pe=n.useCallback(async()=>{if(r==="directory"&&j.length===0){_("Please select a directory containing AGENTS.md files");return}if(r==="browse"&&!z){_("Please select a company from the catalog");return}if(r!=="directory"&&r!=="browse"&&!c.trim()){_("Please provide manifest content");return}Y(!0),_(null);try{let i;r==="directory"?i={agents:j,dryRun:!0}:r==="browse"&&z?i={importSource:"companies.sh",companySlug:z.slug,dryRun:!0}:i={manifest:c,dryRun:!0};const b=await fetch(ye("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!b.ok){const K=await b.json();throw new Error(K.error??`Parse failed (${b.status})`)}const T=await b.json(),U=T.agents&&T.agents.length>0?T.agents:T.created.map(K=>({name:K,role:"custom"})),P=Array.isArray(T.skills)?T.skills:[];A(T.companyName??"Unknown"),v(U),H(P),S(U.map(K=>K.name)),Z(P.map(K=>K.name)),u("preview")}catch(i){_(i instanceof Error?i.message:"Failed to parse manifest")}finally{Y(!1)}},[r,j,c,z,h]),he=n.useCallback(async()=>{ve(!0),be(null);try{let i;r==="directory"?i={agents:j,skipExisting:!0,selectedAgents:M,selectedSkills:R}:r==="browse"&&z?i={importSource:"companies.sh",companySlug:z.slug,skipExisting:!0,selectedAgents:M,selectedSkills:R}:i={manifest:c,skipExisting:!0,selectedAgents:M,selectedSkills:R};const b=await fetch(ye("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!b.ok){const U=await b.json();throw new Error(U.error??`Import failed (${b.status})`)}const T=await b.json();ee(T),u("result"),p()}catch(i){be(i instanceof Error?i.message:"Failed to import agents")}finally{ve(!1)}},[r,j,c,z,M,R,h,p]),V=M.length,W=R.length,we=`${V} Agent${V!==1?"s":""}`,ke=`${W} Skill${W!==1?"s":""}`,je=V>0&&W>0?`${we} + ${ke}`:W>0?ke:we,ue=V>0&&W>0?`Importing ${V} agent${V!==1?"s":""} and ${W} skill${W!==1?"s":""}...`:W>0?`Importing ${W} skill${W!==1?"s":""}...`:`Importing ${V} agent${V!==1?"s":""}...`,Ce=i=>{S(b=>b.includes(i)?b.filter(T=>T!==i):[...b,i])},Se=i=>{Z(b=>b.includes(i)?b.filter(T=>T!==i):[...b,i])};return a?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:[d==="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:G,type:"file",accept:".md,.txt",onChange:ie,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:xe,type:"file",webkitdirectory:"",multiple:!0,onChange:re,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>G.current?.click(),children:[e.jsx(lt,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>xe.current?.click(),children:[e.jsx(Ht,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{g("browse"),w([]),m(""),de(null),_(null)},children:[e.jsx(jt,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),r==="browse"&&e.jsxs("div",{className:"agent-import-browse",children:[e.jsxs("div",{className:"agent-import-browse-header",children:[e.jsxs("div",{className:"agent-import-browse-search",children:[e.jsx(kt,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:L,onChange:i=>ne(i.target.value),"aria-label":"Search companies"})]}),z&&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:z.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>de(null),children:"Change"})]})]}),ge&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(Fe,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),se&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(De,{size:16}),e.jsx("span",{children:se}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:me,children:[e.jsx(_e,{size:14}),"Retry"]})]}),!ge&&!se&&e.jsxs("div",{className:"agent-import-browse-list",children:[te.filter(i=>L===""||i.name.toLowerCase().includes(L.toLowerCase())||(i.tagline?.toLowerCase().includes(L.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${z?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>de(i),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&de(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)),te.filter(i=>L===""||i.name.toLowerCase().includes(L.toLowerCase())||(i.tagline?.toLowerCase().includes(L.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:L?"No companies match your search":"No companies available"})]})]}),r!=="browse"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-divider",children:e.jsx("span",{children:"or paste manifest content"})}),e.jsx("textarea",{className:"agent-import-textarea",placeholder:`---
|
|
515
|
+
Flag performance concerns only when they have measurable impact.`}];function An({value:a,onChange:l,projectId:p,disabled:h=!1,id:d,label:u="Skills"}){const[r,g]=n.useState([]),[c,m]=n.useState(!0);n.useEffect(()=>{let f=!1;return m(!0),gt(p).then(v=>{f||g(v)}).catch(()=>{f||g([])}).finally(()=>{f||m(!1)}),()=>{f=!0}},[p]);const j=f=>{a.includes(f)||l([...a,f])},w=f=>{l(a.filter(v=>v!==f))},k=f=>r.find(E=>E.id===f)?.name??f,A=r.filter(f=>!a.includes(f.id));return e.jsxs("div",{className:"skill-multiselect","data-testid":"skill-multiselect",children:[u&&e.jsx("label",{htmlFor:d?`${d}-select`:void 0,className:"skill-multiselect-label",children:u}),a.length>0&&e.jsx("div",{className:"skill-multiselect-chips","data-testid":"skill-chips",children:a.map(f=>e.jsxs("span",{className:"skill-chip","data-testid":`skill-chip-${f}`,children:[e.jsx("span",{className:"skill-chip-name",children:k(f)}),e.jsx("button",{type:"button",className:"skill-chip-remove",onClick:()=>w(f),disabled:h,"aria-label":`Remove ${k(f)}`,"data-testid":`remove-skill-${f}`,children:"×"})]},f))}),e.jsx("div",{className:"skill-multiselect-add",children:c?e.jsx("span",{className:"skill-multiselect-loading","data-testid":"skills-loading",children:"Loading skills…"}):A.length===0?e.jsx("span",{className:"skill-multiselect-empty","data-testid":"skills-empty",children:a.length===0?"No skills discovered":"All skills selected"}):e.jsxs("select",{id:d?`${d}-select`:void 0,className:"select skill-multiselect-dropdown",value:"",onChange:f=>{f.target.value&&(j(f.target.value),f.target.value="")},disabled:h,"data-testid":"skill-dropdown",children:[e.jsx("option",{value:"",children:"Add a skill…"}),A.map(f=>e.jsx("option",{value:f.id,children:f.name},f.id))]})})]})}const nt=[{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:"✦"}],Tn=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Mn({isOpen:a,onClose:l,onCreated:p,projectId:h}){const[d,u]=n.useState(0),[r,g]=n.useState("presets"),[c,m]=n.useState(""),[j,w]=n.useState(""),[k,A]=n.useState(""),[f,v]=n.useState("custom"),[E,H]=n.useState(""),[M,S]=n.useState(""),[R,Z]=n.useState(""),[B,Y]=n.useState(""),[le,ve]=n.useState(""),[D,_]=n.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[N,ee]=n.useState(null),[oe,be]=n.useState([]),[G,xe]=n.useState(!1),[te,ce]=n.useState(null),[L,ne]=n.useState(!1),[z,de]=n.useState([]),[ge,O]=n.useState(!1),[se,q]=n.useState([]),[Q,me]=n.useState([]),[J,ae]=n.useState("model"),[ie,re]=n.useState(""),[ye,pe]=n.useState([]),[he,K]=n.useState(!1),[V,we]=n.useState([]),[ke,je]=n.useState(!1);n.useEffect(()=>{a&&(O(!0),pt().then(s=>{de(s.models),q(s.favoriteProviders),me(s.favoriteModels)}).catch(()=>{}).finally(()=>O(!1)))},[a]),n.useEffect(()=>{a&&(je(!0),we([]),ft(void 0,h).then(s=>{we(s)}).catch(()=>{we([])}).finally(()=>je(!1)))},[a,h]),n.useEffect(()=>{if(!a)return;const s=bt;if(typeof s!="function"){pe([]),K(!1);return}K(!0),pe([]),s(h).then(C=>{pe(C)}).catch(()=>{pe([])}).finally(()=>K(!1))},[a,h]);const ue=D.model.includes("/")?D.model:"",Ce=n.useCallback(s=>{const C=Tn.has(s.role)?s.role:"custom";m(s.title),w(s.description),A(s.icon),v(C),Z(s.systemPrompt),_(y=>({...y,thinkingLevel:s.thinkingLevel,maxTurns:s.maxTurns})),ne(!1),u(1)},[]),Se=n.useCallback(s=>{_(C=>({...C,model:s}))},[]),i=n.useCallback(s=>{ae(s),s==="model"&&re("")},[]),b=n.useCallback(async s=>{const C=se,$=C.includes(s)?C.filter(X=>X!==s):[s,...C];q($);try{await Ke({favoriteProviders:$,favoriteModels:Q})}catch{q(C)}},[se,Q]),T=n.useCallback(async s=>{const C=Q,$=C.includes(s)?C.filter(X=>X!==s):[s,...C];me($);try{await Ke({favoriteProviders:se,favoriteModels:$})}catch{me(C)}},[se,Q]),U=n.useCallback(s=>{ee(s.id),m(s.name),A(s.icon),w(s.description??s.title),v(s.role),Y(s.soul??""),Z(s.instructionsText??""),u(1)},[]);if(!a)return null;const P=()=>{u(0),g("presets"),m(""),w(""),A(""),v("custom"),H(""),S(""),Z(""),Y(""),ve(""),_({model:"",thinkingLevel:"off",maxTurns:1e3}),ae("model"),re(""),ee(null),be([]),ce(null),ne(!1),l()},W=async()=>{if(c.trim()){xe(!0),ce(null);try{const s={};J==="runtime"?ie.trim()&&(s.runtimeHint=ie.trim()):D.model.trim()&&(s.model=D.model.trim()),D.thinkingLevel!=="off"&&(s.thinkingLevel=D.thinkingLevel),D.maxTurns!==1e3&&(s.maxTurns=D.maxTurns),await yt({name:c.trim(),role:f,...j.trim()?{title:j.trim()}:{},...k.trim()?{icon:k.trim()}:{},...E.trim()?{reportsTo:E.trim()}:{},...M.trim()?{instructionsPath:M.trim()}:{},...R.trim()?{instructionsText:R.trim()}:{},...B.trim()?{soul:B.trim()}:{},...le.trim()?{memory:le.trim()}:{},...Object.keys(s).length>0?{runtimeConfig:s}:{},...oe.length>0?{metadata:{skills:oe}}:{}},h),P(),p()}catch(s){ce(s instanceof Error?s.message:"Failed to create agent")}finally{xe(!1)}}},t=nt.find(s=>s.value===f),o=E.trim(),x=o?V.find(s=>s.id===o):void 0,I=ie?ye.find(s=>s.runtimeId===ie):void 0,F=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:s,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":s,children:[e.jsxs("label",{className:`agent-runtime-mode-option${J==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"model",checked:J==="model",onChange:()=>i("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${J==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"runtime",checked:J==="runtime",onChange:()=>i("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),J==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),ge?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(xt,{id:"agent-model",label:"Model",value:ue,onChange:Se,models:z,placeholder:"Select a model…",favoriteProviders:se,onToggleFavorite:b,favoriteModels:Q,onToggleModelFavorite:T})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),he?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:ie,onChange:C=>re(C.target.value),children:[e.jsx("option",{value:"",children:ye.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),ye.map(C=>e.jsx("option",{value:C.runtimeId,children:C.description?`${C.name} — ${C.description}`:C.name},`${C.pluginId}:${C.runtimeId}`))]})]})]});return Ht.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:s=>{s.target===s.currentTarget&&P()},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:P,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(s=>e.jsx("div",{className:`agent-dialog-step${s===d?" active":s<d?" completed":""}`,"aria-label":`Step ${s+1}`},s))}),e.jsxs("div",{className:"agent-dialog-body",children:[d===0&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-tabs",role:"tablist","aria-label":"Agent setup mode",children:[e.jsx("button",{id:"agent-dialog-tab-presets",type:"button",role:"tab","aria-controls":"agent-dialog-panel-presets","aria-selected":r==="presets",tabIndex:r==="presets"?0:-1,className:`agent-dialog-tab${r==="presets"?" active":""}`,onClick:()=>g("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":r==="custom",tabIndex:r==="custom"?0:-1,className:`agent-dialog-tab${r==="custom"?" active":""}`,onClick:()=>g("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),r==="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:En.map(s=>e.jsxs("button",{type:"button",className:`agent-preset-card${N===s.id?" selected":""}`,"data-testid":`preset-${s.id}`,onClick:()=>U(s),title:s.title,children:[e.jsx("span",{className:"agent-preset-icon",children:s.icon}),e.jsx("span",{className:"agent-preset-name",children:s.name}),e.jsx("span",{className:"agent-preset-role",children:s.role}),s.description&&e.jsx("span",{className:"agent-preset-description",children:s.description})]},s.id))})]})}),r==="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 ",!N&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:c,onChange:s=>m(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",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:j,onChange:s=>w(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-icon",children:["Icon ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:k,onChange:s=>A(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:nt.map(s=>e.jsxs("button",{type:"button",className:`agent-role-option${f===s.value?" selected":""}`,onClick:()=>v(s.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:s.icon}),e.jsx("span",{className:"agent-role-option-label",children:s.label})]},s.value))})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Configuration"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-reports-to",children:["Reports To ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:E,onChange:s=>H(s.target.value),disabled:ke,children:[e.jsx("option",{value:"",children:"No manager"}),V.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.id,")"]},s.id))]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-soul",children:["Soul ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:B,onChange:s=>Y(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-memory",children:["Agent Memory ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-memory",className:"input",rows:2,placeholder:"Private to this agent — durable preferences, operating habits, and context it should carry across tasks...",value:le,onChange:s=>ve(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-path",children:["Instructions Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:M,onChange:s=>S(s.target.value)})]}),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:R,onChange:s=>Z(s.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),F("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:()=>ne(!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"})]})]})]}),d===1&&e.jsxs("div",{children:[F("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:D.thinkingLevel,onChange:s=>_(C=>({...C,thinkingLevel:s.target.value})),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"minimal",children:"Minimal"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-max-turns",children:"Max Turns"}),e.jsx("input",{id:"agent-max-turns",type:"number",className:"input",min:1,max:2e3,value:D.maxTurns,onChange:s=>_(C=>({...C,maxTurns:Math.max(1,parseInt(s.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(An,{id:"agent-skills",label:"Skills",value:oe,onChange:be,projectId:h}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),d===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:[k&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:k}),c]})]}),j&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Title"}),e.jsx("span",{children:j})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Role"}),e.jsxs("span",{children:[t?.icon," ",t?.label]})]}),o&&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:x?`${x.name} (${x.id})`:o})]}),M.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Instructions File"}),e.jsx("span",{children:M.trim()})]}),R.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Inline Instructions"}),e.jsxs("span",{children:[R.trim().length," chars"]})]}),B.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Soul"}),e.jsxs("span",{children:[B.trim().length," chars"]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:J==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:J==="runtime"?I?I.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):ue?e.jsxs(e.Fragment,{children:[e.jsx(vt,{provider:ue.split("/")[0],size:"sm"})," ",(()=>{const s=ue.indexOf("/"),C=ue.slice(0,s),y=ue.slice(s+1);return z.find(X=>X.provider===C&&X.id===y)?.name||ue})()]}):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:D.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:D.maxTurns})]}),oe.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:[oe.length," skill",oe.length!==1?"s":""," selected"]})]})]}),te&&e.jsx("p",{className:"agent-dialog-error",children:te})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[d>0&&e.jsx("button",{className:"btn",onClick:()=>u(s=>s-1),disabled:G,children:"Back"}),e.jsx("button",{className:"btn",onClick:P,disabled:G,children:"Cancel"}),d<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>u(s=>s+1),disabled:d===0&&!c.trim()&&!N,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void W(),disabled:G||!c.trim(),children:G?"Creating...":"Create"})]})]}),e.jsx(ln,{isOpen:L,onClose:()=>ne(!1),onGenerated:Ce,projectId:h})]}),document.body)}function Rn(a){const l=a.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!l)throw new Error("Missing YAML frontmatter delimiters (---)");const p=l[1].split(/\r?\n/),h=l[2]??"",d={name:""},u=[];let r=!1;for(const g of p){const m=g.trimEnd().trim();if(!m)continue;if(m.startsWith("skills:")){r=!0;continue}if(r&&m.startsWith("- ")){u.push(m.slice(2).trim());continue}r=!1;const[j,...w]=m.split(":"),A=w.join(":").trim().replace(/^['"]|['"]$/g,"");j==="name"&&(d.name=A),j==="title"&&(d.title=A),j==="icon"&&(d.icon=A),j==="role"&&(d.role=A),j==="reportsTo"&&(d.reportsTo=A)}if(!d.name)throw new Error("Missing required field: name");return u.length>0&&(d.skills=u),h.trim().length>0&&(d.instructionBody=h),d}function _n({isOpen:a,onClose:l,onImported:p,projectId:h}){const[d,u]=n.useState("input"),[r,g]=n.useState("paste"),[c,m]=n.useState(""),[j,w]=n.useState([]),[k,A]=n.useState("Unknown"),[f,v]=n.useState([]),[E,H]=n.useState([]),[M,S]=n.useState([]),[R,Z]=n.useState([]),[B,Y]=n.useState(!1),[le,ve]=n.useState(!1),[D,_]=n.useState(null),[N,ee]=n.useState(null),[oe,be]=n.useState(null),G=n.useRef(null),xe=n.useRef(null),[te,ce]=n.useState([]),[L,ne]=n.useState(""),[z,de]=n.useState(null),[ge,O]=n.useState(!1),[se,q]=n.useState(null),Q=n.useRef(!1);n.useEffect(()=>{r==="browse"&&!Q.current&&!ge&&(Q.current=!0,O(!0),q(null),Ue().then(i=>{i.error?q(i.error):i.companies.length>0?ce(i.companies):q("No companies available")}).catch(i=>{q(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{O(!1)}))},[r,ge]);const me=n.useCallback(()=>{Q.current=!0,q(null),ce([]),de(null),O(!0),Ue().then(i=>{i.error?q(i.error):i.companies.length>0?ce(i.companies):q("No companies available")}).catch(i=>{q(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{O(!1)})},[]),J=n.useCallback(()=>{u("input"),g("paste"),m(""),w([]),A("Unknown"),v([]),H([]),S([]),Z([]),Y(!1),ve(!1),_(null),ee(null),be(null),ce([]),ne(""),de(null),O(!1),q(null),Q.current=!1},[]),ae=n.useCallback(()=>{J(),l()},[J,l]),ie=n.useCallback(i=>{const b=i.target.files?.[0];if(!b)return;const T=new FileReader;T.onload=U=>{const P=U.target?.result;g("file"),w([]),m(P),_(null)},T.onerror=()=>{_("Failed to read file")},T.readAsText(b),i.target.value=""},[]),re=n.useCallback(async i=>{const b=Array.from(i.target.files??[]);if(b.length!==0)try{const T=b.filter(P=>(P.webkitRelativePath||P.name).toLowerCase().endsWith("agents.md")).sort((P,W)=>{const t=P.webkitRelativePath||P.name,o=W.webkitRelativePath||W.name;return t.localeCompare(o)});if(T.length===0){_("Selected directory has no AGENTS.md files");return}const U=[];for(const P of T){const W=await P.text();U.push(Rn(W))}g("directory"),w(U),m(""),_(null)}catch{_("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function ye(i){if(!h)return`/api${i}`;const b=i.includes("?")?"&":"?";return`/api${i}${b}projectId=${encodeURIComponent(h)}`}const pe=n.useCallback(async()=>{if(r==="directory"&&j.length===0){_("Please select a directory containing AGENTS.md files");return}if(r==="browse"&&!z){_("Please select a company from the catalog");return}if(r!=="directory"&&r!=="browse"&&!c.trim()){_("Please provide manifest content");return}Y(!0),_(null);try{let i;r==="directory"?i={agents:j,dryRun:!0}:r==="browse"&&z?i={importSource:"companies.sh",companySlug:z.slug,dryRun:!0}:i={manifest:c,dryRun:!0};const b=await fetch(ye("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!b.ok){const W=await b.json();throw new Error(W.error??`Parse failed (${b.status})`)}const T=await b.json(),U=T.agents&&T.agents.length>0?T.agents:T.created.map(W=>({name:W,role:"custom"})),P=Array.isArray(T.skills)?T.skills:[];A(T.companyName??"Unknown"),v(U),H(P),S(U.map(W=>W.name)),Z(P.map(W=>W.name)),u("preview")}catch(i){_(i instanceof Error?i.message:"Failed to parse manifest")}finally{Y(!1)}},[r,j,c,z,h]),he=n.useCallback(async()=>{ve(!0),be(null);try{let i;r==="directory"?i={agents:j,skipExisting:!0,selectedAgents:M,selectedSkills:R}:r==="browse"&&z?i={importSource:"companies.sh",companySlug:z.slug,skipExisting:!0,selectedAgents:M,selectedSkills:R}:i={manifest:c,skipExisting:!0,selectedAgents:M,selectedSkills:R};const b=await fetch(ye("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!b.ok){const U=await b.json();throw new Error(U.error??`Import failed (${b.status})`)}const T=await b.json();ee(T),u("result"),p()}catch(i){be(i instanceof Error?i.message:"Failed to import agents")}finally{ve(!1)}},[r,j,c,z,M,R,h,p]),K=M.length,V=R.length,we=`${K} Agent${K!==1?"s":""}`,ke=`${V} Skill${V!==1?"s":""}`,je=K>0&&V>0?`${we} + ${ke}`:V>0?ke:we,ue=K>0&&V>0?`Importing ${K} agent${K!==1?"s":""} and ${V} skill${V!==1?"s":""}...`:V>0?`Importing ${V} skill${V!==1?"s":""}...`:`Importing ${K} agent${K!==1?"s":""}...`,Ce=i=>{S(b=>b.includes(i)?b.filter(T=>T!==i):[...b,i])},Se=i=>{Z(b=>b.includes(i)?b.filter(T=>T!==i):[...b,i])};return a?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:[d==="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:G,type:"file",accept:".md,.txt",onChange:ie,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:xe,type:"file",webkitdirectory:"",multiple:!0,onChange:re,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>G.current?.click(),children:[e.jsx(rt,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>xe.current?.click(),children:[e.jsx(Vt,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{g("browse"),w([]),m(""),de(null),_(null)},children:[e.jsx(wt,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),r==="browse"&&e.jsxs("div",{className:"agent-import-browse",children:[e.jsxs("div",{className:"agent-import-browse-header",children:[e.jsxs("div",{className:"agent-import-browse-search",children:[e.jsx(jt,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:L,onChange:i=>ne(i.target.value),"aria-label":"Search companies"})]}),z&&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:z.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>de(null),children:"Change"})]})]}),ge&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(Fe,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),se&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(De,{size:16}),e.jsx("span",{children:se}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:me,children:[e.jsx(_e,{size:14}),"Retry"]})]}),!ge&&!se&&e.jsxs("div",{className:"agent-import-browse-list",children:[te.filter(i=>L===""||i.name.toLowerCase().includes(L.toLowerCase())||(i.tagline?.toLowerCase().includes(L.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${z?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>de(i),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&de(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)),te.filter(i=>L===""||i.name.toLowerCase().includes(L.toLowerCase())||(i.tagline?.toLowerCase().includes(L.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:L?"No companies match your search":"No companies available"})]})]}),r!=="browse"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-divider",children:e.jsx("span",{children:"or paste manifest content"})}),e.jsx("textarea",{className:"agent-import-textarea",placeholder:`---
|
|
516
516
|
name: CEO
|
|
517
517
|
title: Chief Executive Officer
|
|
518
518
|
reportsTo: null
|
|
519
519
|
skills:
|
|
520
520
|
- review
|
|
521
521
|
---
|
|
522
|
-
Agent instructions go here...`,value:c,onChange:i=>{g("paste"),w([]),m(i.target.value),_(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),D&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(De,{size:14}),D]})]}),d==="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:k})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Be,{size:14}),e.jsxs("span",{children:[f.length," agent",f.length!==1?"s":""," found"]})]}),f.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>S(f.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>S([]),children:"Clear agents"})]}),f.length>0?e.jsx("div",{className:"agent-import-agent-list",children:f.map((i,b)=>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:M.includes(i.name),onChange:()=>Ce(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?"...":""]})]})]},b))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),E.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Be,{size:14}),e.jsxs("span",{children:[E.length," skill",E.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>Z(E.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>Z([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:E.map((i,b)=>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:R.includes(i.name),onChange:()=>Se(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}-${b}`))})]}),oe&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(De,{size:14}),oe]})]}),d==="result"&&N&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(Re,{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,b)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Re,{size:12}),e.jsx("span",{children:i.name})]},b))}),N.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.errors.map((i,b)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Ge,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},b))}),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,b)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Re,{size:12}),e.jsx("span",{children:i.name})]},b))}),N.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.skills.errors.map((i,b)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Ge,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},b))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[d==="preview"&&e.jsx("button",{className:"btn",onClick:()=>u("input"),disabled:le,children:"Back"}),e.jsx("button",{className:"btn",onClick:ae,disabled:le,children:d==="result"?"Close":"Cancel"}),d==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void pe(),disabled:B||(r==="directory"?j.length===0:r==="browse"?!z:!c.trim()),children:B?e.jsxs(e.Fragment,{children:[e.jsx(Fe,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),d==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void he(),disabled:le||V===0&&W===0,children:le?e.jsxs(e.Fragment,{children:[e.jsx(Fe,{size:14,className:"spin"}),ue]}):`Import ${je}`})]})]})}):null}const _n=n.lazy(()=>qt(()=>import("./AgentDetailView-Du65-jDo.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(a=>({default:a.AgentDetailView}))),Me=[{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:"✦"}],Oe=[.1,.25,.5,1,2,3,5,10];function Pe(a){switch(a){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function at(a,l){switch(l){case"running":return`${a}--running`;case"active":return`${a}--active`;case"paused":return`${a}--paused`;case"error":return`${a}--error`;case"terminated":return`${a}--terminated`;case"idle":default:return`${a}--idle`}}function ct({node:a,onSelect:l,onToggle:p,isExpanded:h,getChildCount:d,getHealthStatus:u,getRoleIcon:r,getSkillBadges:g}){const{agent:c,children:m,depth:j}=a,w=d(c.id),k=h(c.id),A=u(c),f=Pe(c.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`agent-tree__node${c.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(j,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${w===0?" agent-tree__toggle--leaf":""}`,onClick:()=>w>0&&p(c.id),title:w>0?k?"Collapse":"Expand":"No employees","aria-label":w>0?k?"Collapse":"Expand":"No employees",children:w>0?k?e.jsx($t,{size:16}):e.jsx(rt,{size:16}):e.jsx(Ve,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(c.id),role:"button",tabIndex:0,onKeyDown:v=>v.key==="Enter"&&l(c.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(c.role)}),e.jsx("span",{className:"agent-tree__name",children:c.name}),e.jsx("span",{className:`agent-tree__badge ${f}`,children:c.state}),e.jsx("span",{className:"agent-tree__health",style:{color:A.color},title:A.label,children:A.icon}),w>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",w,")"]}),(()=>{const v=g(c);return v.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:v.join(", "),children:[v[0],v.length>1&&` +${v.length-1}`]})})()]})]}),k&&m.length>0&&e.jsx("div",{className:"agent-tree__children",children:m.map(v=>e.jsx(ct,{node:v,onSelect:l,onToggle:p,isExpanded:h,getChildCount:d,getHealthStatus:u,getRoleIcon:r,getSkillBadges:g},v.agent.id))})]})}function dt({node:a,onSelect:l,getHealthStatus:p,getRoleIcon:h,getSkillBadges:d}){const{agent:u,children:r}=a,g=p(u),c=Pe(u.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:"org-chart-node-card",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:m=>m.key==="Enter"&&l(u.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:h(u.role)}),e.jsx("span",{className:"org-chart-node__name",children:u.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${c}`,children:u.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:g.color},title:g.label,children:[g.icon,!g.stateDerived&&e.jsx("span",{className:"text-secondary",children:g.label})]}),(()=>{const m=d(u);if(m.length===0)return null;const j=m.slice(0,2),w=m.length-2;return e.jsxs(e.Fragment,{children:[j.map(k=>e.jsx("span",{className:"org-chart-node__skill",children:k},k)),w>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",w]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${u.name} employees`,children:r.map(m=>e.jsx(dt,{node:m,onSelect:l,getHealthStatus:p,getRoleIcon:h,getSkillBadges:d},m.agent.id))})]})}function Pn({addToast:a,projectId:l}){const[p,h]=n.useState(!1),[d,u]=n.useState("all"),{agents:r,stats:g,isLoading:c,loadAgents:m}=Nt(l,{filterState:d,showSystemAgents:p}),[j,w]=n.useState(!1),[k,A]=n.useState(!1),[f,v]=n.useState(null),[E,H]=n.useState(()=>{if(typeof window>"u")return"list";const t=qe("fn-agent-view",l);return t==="list"||t==="board"||t==="tree"||t==="org"?t:"list"}),[M,S]=n.useState([]),[R,Z]=n.useState(!1),[B,Y]=n.useState(!1),le=n.useRef(null),{confirm:ve}=It(),D=n.useRef(null),_=n.useId();n.useEffect(()=>{const t=qe("fn-agent-view",l);if(t==="list"||t==="board"||t==="tree"||t==="org"){H(t);return}H("list")},[l]),n.useEffect(()=>{it("fn-agent-view",E,l)},[E,l]);const[N,ee]=n.useState(null),oe=n.useRef(null),[be,G]=n.useState(null),[xe,te]=n.useState(null),[ce,L]=n.useState({}),[ne,z]=n.useState(1),[de,ge]=n.useState(!1),[O,se]=n.useState(new Set),[q,Q]=n.useState(new Map),me=n.useRef(!0);n.useEffect(()=>(me.current=!0,()=>{me.current=!1}),[]),n.useEffect(()=>{Ct(l).then(t=>{me.current&&z(t.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const J=n.useCallback(async t=>{const o=Number.isFinite(t)&&t>0?t:1;z(o),ge(!0);try{await St({heartbeatMultiplier:o},l),a(`Heartbeat speed set to ×${o.toFixed(1)}`,"success")}catch(x){a(`Failed to save heartbeat multiplier: ${fe(x)}`,"error")}finally{me.current&&ge(!1)}},[l,a]),ae=n.useMemo(()=>q.size===0?r:r.map(t=>{const o=q.get(t.id);return o?{...t,state:o}:t}),[r,q]),ie=an(ae,l),re=n.useMemo(()=>ae.filter(t=>p||!Le(t)),[ae,p]),ye=n.useMemo(()=>ae.filter(t=>t.state!=="active"&&t.state!=="running"?!1:p||!Le(t)),[ae,p]),pe=n.useMemo(()=>{if(p)return M;const t=o=>Le(o.agent)?null:{...o,children:o.children.map(t).filter(x=>x!==null)};return M.map(t).filter(o=>o!==null)},[M,p]);n.useEffect(()=>{if(E!=="org")return;let t=!1;return Z(!0),Et(l,{includeEphemeral:p}).then(o=>{t||S(o)}).catch(o=>{t||(a(`Failed to load org chart: ${fe(o)}`,"error"),S([]))}).finally(()=>{t||Z(!1)}),()=>{t=!0}},[E,l,p,a]),n.useEffect(()=>{const t=setInterval(()=>{m()},3e4);return()=>{clearInterval(t)}},[m]),n.useEffect(()=>{if(!B)return;const t=x=>{const I=x.target;I&&(le.current?.contains(I)||D.current?.contains(I)||Y(!1))},o=x=>{x.key==="Escape"&&(Y(!1),D.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",o)}},[B]);const he=async(t,o)=>{if(!O.has(t)){se(x=>new Set(x).add(t)),Q(x=>{const I=new Map(x);return I.set(t,o),I});try{await Lt(t,o,l),a(`Agent state updated to ${o}`,"success"),await m(),Q(x=>{const I=new Map(x);return I.delete(t),I})}catch(x){Q(I=>{const F=new Map(I);return F.delete(t),F}),a(`Failed to update state: ${fe(x)}`,"error")}finally{se(x=>{const I=new Set(x);return I.delete(t),I})}}},V=async(t,o)=>{if(await ve({title:"Delete Agent",message:`Delete agent "${o}"? This cannot be undone.`,danger:!0}))try{await zt(t,l),a(`Agent "${o}" deleted`,"success"),m()}catch(I){a(`Failed to delete agent: ${fe(I)}`,"error")}},W=async(t,o)=>{const x=r.find(I=>I.id===t);if(x){if(x.role===o){ee(null);return}try{await Ae(t,{role:o},l),a(`Agent role updated to ${Me.find(I=>I.value===o)?.label??o}`,"success"),ee(null),m()}catch(I){a(`Failed to update role: ${fe(I)}`,"error")}}},we=(t,o)=>{t.key==="Escape"&&ee(null)},ke=async(t,o)=>{xe===t.id&&(te(null),L(x=>{const I={...x};return delete I[t.id],I})),G(t.id);try{await Ae(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:o}},l),a(`Heartbeat interval updated to ${Ze(o)} for ${t.name}`,"success"),m()}catch(x){a(`Failed to update heartbeat interval: ${fe(x)}`,"error")}finally{G(null)}},je=async t=>{const o=ce[t.id]??"";if(o.trim()===""){a("Please enter a heartbeat interval in minutes","error");return}const x=Number(o);if(isNaN(x)){a("Heartbeat interval must be a valid number","error");return}if(x<=0){a("Heartbeat interval must be greater than 0","error");return}if(x>=1&&x<5){G(t.id);try{await Ae(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:Dt}},l),a(`Heartbeat interval set to 5 minutes (minimum). ${x} minute${x!==1?"s":""} was below the 5-minute minimum.`,"success"),te(null),L(F=>{const s={...F};return delete s[t.id],s}),m()}catch(F){a(`Failed to update heartbeat interval: ${fe(F)}`,"error")}finally{G(null)}return}const I=Math.round(x*6e4);G(t.id);try{await Ae(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:I}},l),a(`Heartbeat interval updated to ${Ze(I)} for ${t.name}`,"success"),te(null),L(F=>{const s={...F};return delete s[t.id],s}),m()}catch(F){a(`Failed to update heartbeat interval: ${fe(F)}`,"error")}finally{G(null)}},ue=t=>{const o=Qe(t.runtimeConfig?.heartbeatIntervalMs),x=Math.round(o/6e4);te(t.id),L(I=>({...I,[t.id]:String(x)}))},Ce=n.useCallback(()=>{v(null)},[]),Se=n.useCallback(t=>{v(t)},[]),i=async(t,o)=>{try{await Ot(t,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),a(`Heartbeat run started for ${o}`,"success"),m()}catch(x){a(`Failed to start heartbeat run: ${fe(x)}`,"error")}},b=t=>Me.find(o=>o.value===t)?.label??t,T=t=>Me.find(o=>o.value===t)?.icon??"◆",U=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],P=t=>Ft(t),K=c&&r.length===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(Ve,{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${E==="list"?" active":""}`,onClick:()=>H("list"),title:"List view","aria-label":"List view","aria-pressed":E==="list",children:e.jsx(At,{size:16})}),e.jsx("button",{className:`view-toggle-btn${E==="board"?" active":""}`,onClick:()=>H("board"),title:"Board view","aria-label":"Board view","aria-pressed":E==="board",children:e.jsx(Ie,{size:16})}),e.jsx("button",{className:`view-toggle-btn${E==="tree"?" active":""}`,onClick:()=>H("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":E==="tree",children:e.jsx(Tt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${E==="org"?" active":""}`,onClick:()=>H("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":E==="org",children:e.jsx(Ut,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:D,className:`btn-icon agent-controls-trigger${B?" agent-controls-trigger--active":""}`,onClick:()=>Y(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":B,"aria-controls":_,children:e.jsx(Gt,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void m(),title:"Refresh","aria-label":"Refresh",children:e.jsx(_e,{size:16,className:c?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{w(!0),Y(!1)},children:[e.jsx(Mt,{size:16}),"New Agent"]})]})]})]}),B&&e.jsxs("div",{ref:le,id:_,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Rt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:d,onChange:t=>u(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.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:t=>h(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{A(!0),Y(!1)},children:[e.jsx(lt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:ne,onChange:t=>{const o=Number(t.target.value);J(Number.isFinite(o)&&o>0?o:1)},disabled:de}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",ne.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Oe.reduce((t,o)=>Math.abs(o-ne)<Math.abs(t-ne)?o:t,Oe[0])),onChange:t=>{const o=Number(t.target.value);J(Number.isFinite(o)&&o>0?o:1)},disabled:de,"aria-label":"Heartbeat speed preset",children:Oe.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(tn,{agents:re})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(en,{stats:g}),e.jsx(Tn,{isOpen:j,onClose:()=>w(!1),onCreated:()=>{w(!1),m()},projectId:l}),e.jsx(Rn,{isOpen:k,onClose:()=>A(!1),onImported:()=>void m(),projectId:l}),K?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(_e,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):E==="tree"?e.jsx("div",{className:"agent-tree__view",children:re.length===0?e.jsx(Te,{onCtaClick:()=>w(!0)}):ie.rootNodes.map(t=>e.jsx(ct,{node:t,onSelect:v,onToggle:ie.toggleExpand,isExpanded:ie.isExpanded,getChildCount:o=>ie.getChildren(o).length,getHealthStatus:P,getRoleIcon:T,getSkillBadges:U},t.agent.id))}):E==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:R?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(_e,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):pe.length===0?e.jsx(Te,{onCtaClick:()=>w(!0)}):pe.map(t=>e.jsx(dt,{node:t,onSelect:v,getHealthStatus:P,getRoleIcon:T,getSkillBadges:U},t.agent.id))}):E==="board"?e.jsx("div",{className:"agent-board",children:re.length===0?e.jsx(Te,{onCtaClick:()=>w(!0)}):re.map(t=>{const o=P(t),x=Pe(t.state),I=at("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${I}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>v(t.id),role:"button",tabIndex:0,onKeyDown:F=>F.key==="Enter"&&v(t.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:T(t.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:b(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${x}`,children:t.state})]}),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:o.color},title:o.label,children:[o.icon,!o.stateDerived&&` ${o.label}`]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:re.length===0?e.jsx(Te,{onCtaClick:()=>w(!0)}):re.map(t=>{const o=P(t),x=Pe(t.state),I=at("agent-card",t.state),F=Qe(t.runtimeConfig?.heartbeatIntervalMs),s=_t(F),C=be===t.id;return e.jsxs("div",{className:`agent-card ${I}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>v(t.id),role:"button",tabIndex:0,onKeyDown:y=>y.key==="Enter"&&v(t.id),children:[N===t.id?e.jsx("select",{ref:oe,className:"select agent-role-select",value:t.role,onChange:y=>void W(t.id,y.target.value),onKeyDown:y=>we(y,t.id),onBlur:()=>ee(null),autoFocus:!0,children:Me.map(y=>e.jsxs("option",{value:y.value,children:[y.icon," ",y.label]},y.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:y=>{y.stopPropagation(),ee(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.stopPropagation(),ee(t.id))},children:T(t.role)}),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(rt,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${x}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:o.color},title:o.label,children:[o.icon,!o.stateDerived&&` ${o.label}`]}),e.jsx("span",{className:"badge text-secondary",children:b(t.role)}),(()=>{const y=U(t);if(y.length===0)return null;const $=y.slice(0,2),X=y.length-2;return e.jsxs(e.Fragment,{children:[$.map(We=>e.jsx("span",{className:"badge badge-skill",children:We},We)),X>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",X]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[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:"}),xe===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:ce[t.id]??"",onChange:y=>L($=>({...$,[t.id]:y.target.value})),onKeyDown:y=>{y.key==="Enter"?je(t):y.key==="Escape"&&(te(null),L($=>{const X={...$};return delete X[t.id],X}))},disabled:C,"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 je(t),disabled:C,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{te(null),L(y=>{const $={...y};return delete $[t.id],$})},disabled:C,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:F,onChange:y=>{const $=y.target.value;$==="__custom__"?ue(t):ke(t,Number($))},disabled:C,"aria-label":`Set heartbeat interval for ${t.name}`,children:[s.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value)),Pt.some(y=>y.value===F)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),C&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const y=new Date(t.lastHeartbeatAt),$=new Date(y.getTime()+F),X=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:y.toLocaleString(),children:["Last: ",y.toLocaleTimeString()]}),X&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:$.toLocaleString(),children:["Next: ",$.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[t.state==="idle"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"active"),disabled:O.has(t.id),title:"Activate",children:[e.jsx(Ee,{size:14})," Start"]}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void V(t.id,t.name),title:"Delete",children:[e.jsx(Je,{size:14})," Delete"]})]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void i(t.id,t.name),disabled:O.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(Ie,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"paused"),disabled:O.has(t.id),title:"Pause",children:[e.jsx(Xe,{size:14})," Pause"]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"active"),disabled:O.has(t.id),title:"Resume",children:[e.jsx(Ee,{size:14})," Resume"]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${t.name}`,children:[e.jsx(Ie,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"paused"),disabled:O.has(t.id),title:"Pause",children:[e.jsx(Xe,{size:14})," Pause"]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"active"),disabled:O.has(t.id),title:"Retry",children:[e.jsx(Ee,{size:14})," Retry"]}),t.state==="terminated"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"active"),disabled:O.has(t.id),title:"Start",children:[e.jsx(Ee,{size:14})," Start"]}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void V(t.id,t.name),title:"Delete",children:[e.jsx(Je,{size:14})," Delete"]})]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>v(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:"View Details"})]})]},t.id)})}),e.jsx(Zt,{agents:ye,projectId:l,onAgentSelect:v})]}),f&&e.jsx(n.Suspense,{fallback:null,children:e.jsx(_n,{agentId:f,projectId:l,onClose:Ce,addToast:a,onChildClick:Se})})]})}const zn=Object.freeze(Object.defineProperty({__proto__:null,AgentsView:Pn},Symbol.toStringTag,{value:"Module"}));export{zn as A,En as S};
|
|
522
|
+
Agent instructions go here...`,value:c,onChange:i=>{g("paste"),w([]),m(i.target.value),_(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),D&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(De,{size:14}),D]})]}),d==="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:k})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Be,{size:14}),e.jsxs("span",{children:[f.length," agent",f.length!==1?"s":""," found"]})]}),f.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>S(f.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>S([]),children:"Clear agents"})]}),f.length>0?e.jsx("div",{className:"agent-import-agent-list",children:f.map((i,b)=>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:M.includes(i.name),onChange:()=>Ce(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?"...":""]})]})]},b))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),E.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Be,{size:14}),e.jsxs("span",{children:[E.length," skill",E.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>Z(E.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>Z([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:E.map((i,b)=>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:R.includes(i.name),onChange:()=>Se(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}-${b}`))})]}),oe&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(De,{size:14}),oe]})]}),d==="result"&&N&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(Re,{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,b)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Re,{size:12}),e.jsx("span",{children:i.name})]},b))}),N.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.errors.map((i,b)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Ge,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},b))}),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,b)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(Re,{size:12}),e.jsx("span",{children:i.name})]},b))}),N.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.skills.errors.map((i,b)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Ge,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},b))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[d==="preview"&&e.jsx("button",{className:"btn",onClick:()=>u("input"),disabled:le,children:"Back"}),e.jsx("button",{className:"btn",onClick:ae,disabled:le,children:d==="result"?"Close":"Cancel"}),d==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void pe(),disabled:B||(r==="directory"?j.length===0:r==="browse"?!z:!c.trim()),children:B?e.jsxs(e.Fragment,{children:[e.jsx(Fe,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),d==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void he(),disabled:le||K===0&&V===0,children:le?e.jsxs(e.Fragment,{children:[e.jsx(Fe,{size:14,className:"spin"}),ue]}):`Import ${je}`})]})]})}):null}const Pn=n.lazy(()=>qt(()=>import("./AgentDetailView-C3Xcrxnp.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(a=>({default:a.AgentDetailView}))),Me=[{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:"✦"}],Oe=[.1,.25,.5,1,2,3,5,10];function Pe(a){switch(a){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function st(a,l){switch(l){case"running":return`${a}--running`;case"active":return`${a}--active`;case"paused":return`${a}--paused`;case"error":return`${a}--error`;case"terminated":return`${a}--terminated`;case"idle":default:return`${a}--idle`}}function ot({node:a,onSelect:l,onToggle:p,isExpanded:h,getChildCount:d,getHealthStatus:u,getRoleIcon:r,getSkillBadges:g}){const{agent:c,children:m,depth:j}=a,w=d(c.id),k=h(c.id),A=u(c),f=Pe(c.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`agent-tree__node${c.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(j,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${w===0?" agent-tree__toggle--leaf":""}`,onClick:()=>w>0&&p(c.id),title:w>0?k?"Collapse":"Expand":"No employees","aria-label":w>0?k?"Collapse":"Expand":"No employees",children:w>0?k?e.jsx($t,{size:16}):e.jsx(it,{size:16}):e.jsx(Ve,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(c.id),role:"button",tabIndex:0,onKeyDown:v=>v.key==="Enter"&&l(c.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(c.role)}),e.jsx("span",{className:"agent-tree__name",children:c.name}),e.jsx("span",{className:`agent-tree__badge ${f}`,children:c.state}),e.jsx("span",{className:"agent-tree__health",style:{color:A.color},title:A.label,children:A.icon}),w>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",w,")"]}),(()=>{const v=g(c);return v.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:v.join(", "),children:[v[0],v.length>1&&` +${v.length-1}`]})})()]})]}),k&&m.length>0&&e.jsx("div",{className:"agent-tree__children",children:m.map(v=>e.jsx(ot,{node:v,onSelect:l,onToggle:p,isExpanded:h,getChildCount:d,getHealthStatus:u,getRoleIcon:r,getSkillBadges:g},v.agent.id))})]})}function ct({node:a,onSelect:l,getHealthStatus:p,getRoleIcon:h,getSkillBadges:d}){const{agent:u,children:r}=a,g=p(u),c=Pe(u.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:"org-chart-node-card",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:m=>m.key==="Enter"&&l(u.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:h(u.role)}),e.jsx("span",{className:"org-chart-node__name",children:u.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${c}`,children:u.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:g.color},title:g.label,children:[g.icon,!g.stateDerived&&e.jsx("span",{className:"text-secondary",children:g.label})]}),(()=>{const m=d(u);if(m.length===0)return null;const j=m.slice(0,2),w=m.length-2;return e.jsxs(e.Fragment,{children:[j.map(k=>e.jsx("span",{className:"org-chart-node__skill",children:k},k)),w>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",w]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${u.name} employees`,children:r.map(m=>e.jsx(ct,{node:m,onSelect:l,getHealthStatus:p,getRoleIcon:h,getSkillBadges:d},m.agent.id))})]})}function $n({addToast:a,projectId:l}){const[p,h]=n.useState(!1),[d,u]=n.useState("all"),{agents:r,stats:g,isLoading:c,loadAgents:m}=kt(l,{filterState:d,showSystemAgents:p}),[j,w]=n.useState(!1),[k,A]=n.useState(!1),[f,v]=n.useState(null),[E,H]=n.useState(()=>{if(typeof window>"u")return"list";const t=qe("fn-agent-view",l);return t==="list"||t==="board"||t==="tree"||t==="org"?t:"list"}),[M,S]=n.useState([]),[R,Z]=n.useState(!1),[B,Y]=n.useState(!1),le=n.useRef(null),{confirm:ve}=Nt(),D=n.useRef(null),_=n.useId();n.useEffect(()=>{const t=qe("fn-agent-view",l);if(t==="list"||t==="board"||t==="tree"||t==="org"){H(t);return}H("list")},[l]),n.useEffect(()=>{at("fn-agent-view",E,l)},[E,l]);const[N,ee]=n.useState(null),oe=n.useRef(null),[be,G]=n.useState(null),[xe,te]=n.useState(null),[ce,L]=n.useState({}),[ne,z]=n.useState(1),[de,ge]=n.useState(!1),[O,se]=n.useState(new Set),[q,Q]=n.useState(new Map),me=n.useRef(!0);n.useEffect(()=>(me.current=!0,()=>{me.current=!1}),[]),n.useEffect(()=>{It(l).then(t=>{me.current&&z(t.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const J=n.useCallback(async t=>{const o=Number.isFinite(t)&&t>0?t:1;z(o),ge(!0);try{await Ct({heartbeatMultiplier:o},l),a(`Heartbeat speed set to ×${o.toFixed(1)}`,"success")}catch(x){a(`Failed to save heartbeat multiplier: ${fe(x)}`,"error")}finally{me.current&&ge(!1)}},[l,a]),ae=n.useMemo(()=>q.size===0?r:r.map(t=>{const o=q.get(t.id);return o?{...t,state:o}:t}),[r,q]),ie=rn(ae,l),re=n.useMemo(()=>ae.filter(t=>p||!Le(t)),[ae,p]),ye=n.useMemo(()=>ae.filter(t=>t.state!=="active"&&t.state!=="running"?!1:p||!Le(t)),[ae,p]),pe=n.useMemo(()=>{if(p)return M;const t=o=>Le(o.agent)?null:{...o,children:o.children.map(t).filter(x=>x!==null)};return M.map(t).filter(o=>o!==null)},[M,p]);n.useEffect(()=>{if(E!=="org")return;let t=!1;return Z(!0),St(l,{includeEphemeral:p}).then(o=>{t||S(o)}).catch(o=>{t||(a(`Failed to load org chart: ${fe(o)}`,"error"),S([]))}).finally(()=>{t||Z(!1)}),()=>{t=!0}},[E,l,p,a]),n.useEffect(()=>{const t=setInterval(()=>{m()},3e4);return()=>{clearInterval(t)}},[m]),n.useEffect(()=>{if(!B)return;const t=x=>{const I=x.target;I&&(le.current?.contains(I)||D.current?.contains(I)||Y(!1))},o=x=>{x.key==="Escape"&&(Y(!1),D.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",o)}},[B]);const he=async(t,o)=>{if(!O.has(t)){se(x=>new Set(x).add(t)),Q(x=>{const I=new Map(x);return I.set(t,o),I});try{await Lt(t,o,l),a(`Agent state updated to ${o}`,"success"),await m(),Q(x=>{const I=new Map(x);return I.delete(t),I})}catch(x){Q(I=>{const F=new Map(I);return F.delete(t),F}),a(`Failed to update state: ${fe(x)}`,"error")}finally{se(x=>{const I=new Set(x);return I.delete(t),I})}}},K=async(t,o)=>{if(await ve({title:"Delete Agent",message:`Delete agent "${o}"? This cannot be undone.`,danger:!0}))try{await Ot(t,l),a(`Agent "${o}" deleted`,"success"),m()}catch(I){a(`Failed to delete agent: ${fe(I)}`,"error")}},V=async(t,o)=>{const x=r.find(I=>I.id===t);if(x){if(x.role===o){ee(null);return}try{await Ae(t,{role:o},l),a(`Agent role updated to ${Me.find(I=>I.value===o)?.label??o}`,"success"),ee(null),m()}catch(I){a(`Failed to update role: ${fe(I)}`,"error")}}},we=(t,o)=>{t.key==="Escape"&&ee(null)},ke=async(t,o)=>{xe===t.id&&(te(null),L(x=>{const I={...x};return delete I[t.id],I})),G(t.id);try{await Ae(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:o}},l),a(`Heartbeat interval updated to ${Xe(o)} for ${t.name}`,"success"),m()}catch(x){a(`Failed to update heartbeat interval: ${fe(x)}`,"error")}finally{G(null)}},je=async t=>{const o=ce[t.id]??"";if(o.trim()===""){a("Please enter a heartbeat interval in minutes","error");return}const x=Number(o);if(isNaN(x)){a("Heartbeat interval must be a valid number","error");return}if(x<=0){a("Heartbeat interval must be greater than 0","error");return}if(x>=1&&x<5){G(t.id);try{await Ae(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:Dt}},l),a(`Heartbeat interval set to 5 minutes (minimum). ${x} minute${x!==1?"s":""} was below the 5-minute minimum.`,"success"),te(null),L(F=>{const s={...F};return delete s[t.id],s}),m()}catch(F){a(`Failed to update heartbeat interval: ${fe(F)}`,"error")}finally{G(null)}return}const I=Math.round(x*6e4);G(t.id);try{await Ae(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:I}},l),a(`Heartbeat interval updated to ${Xe(I)} for ${t.name}`,"success"),te(null),L(F=>{const s={...F};return delete s[t.id],s}),m()}catch(F){a(`Failed to update heartbeat interval: ${fe(F)}`,"error")}finally{G(null)}},ue=t=>{const o=Qe(t.runtimeConfig?.heartbeatIntervalMs),x=Math.round(o/6e4);te(t.id),L(I=>({...I,[t.id]:String(x)}))},Ce=n.useCallback(()=>{v(null)},[]),Se=n.useCallback(t=>{v(t)},[]),i=async(t,o)=>{try{await zt(t,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),a(`Heartbeat run started for ${o}`,"success"),m()}catch(x){a(`Failed to start heartbeat run: ${fe(x)}`,"error")}},b=t=>Me.find(o=>o.value===t)?.label??t,T=t=>Me.find(o=>o.value===t)?.icon??"◆",U=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],P=t=>Ft(t),W=c&&r.length===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(Ve,{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${E==="list"?" active":""}`,onClick:()=>H("list"),title:"List view","aria-label":"List view","aria-pressed":E==="list",children:e.jsx(Et,{size:16})}),e.jsx("button",{className:`view-toggle-btn${E==="board"?" active":""}`,onClick:()=>H("board"),title:"Board view","aria-label":"Board view","aria-pressed":E==="board",children:e.jsx(Ie,{size:16})}),e.jsx("button",{className:`view-toggle-btn${E==="tree"?" active":""}`,onClick:()=>H("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":E==="tree",children:e.jsx(At,{size:16})}),e.jsx("button",{className:`view-toggle-btn${E==="org"?" active":""}`,onClick:()=>H("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":E==="org",children:e.jsx(Bt,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:D,className:`btn-icon agent-controls-trigger${B?" agent-controls-trigger--active":""}`,onClick:()=>Y(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":B,"aria-controls":_,children:e.jsx(Qt,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void m(),title:"Refresh","aria-label":"Refresh",children:e.jsx(_e,{size:16,className:c?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{w(!0),Y(!1)},children:[e.jsx(Tt,{size:16}),"New Agent"]})]})]})]}),B&&e.jsxs("div",{ref:le,id:_,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Mt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:d,onChange:t=>u(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.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:t=>h(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{A(!0),Y(!1)},children:[e.jsx(rt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:ne,onChange:t=>{const o=Number(t.target.value);J(Number.isFinite(o)&&o>0?o:1)},disabled:de}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",ne.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Oe.reduce((t,o)=>Math.abs(o-ne)<Math.abs(t-ne)?o:t,Oe[0])),onChange:t=>{const o=Number(t.target.value);J(Number.isFinite(o)&&o>0?o:1)},disabled:de,"aria-label":"Heartbeat speed preset",children:Oe.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(nn,{agents:re})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(tn,{stats:g}),e.jsx(Mn,{isOpen:j,onClose:()=>w(!1),onCreated:()=>{w(!1),m()},projectId:l}),e.jsx(_n,{isOpen:k,onClose:()=>A(!1),onImported:()=>void m(),projectId:l}),W?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(_e,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):E==="tree"?e.jsx("div",{className:"agent-tree__view",children:re.length===0?e.jsx(Te,{onCtaClick:()=>w(!0)}):ie.rootNodes.map(t=>e.jsx(ot,{node:t,onSelect:v,onToggle:ie.toggleExpand,isExpanded:ie.isExpanded,getChildCount:o=>ie.getChildren(o).length,getHealthStatus:P,getRoleIcon:T,getSkillBadges:U},t.agent.id))}):E==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:R?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(_e,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):pe.length===0?e.jsx(Te,{onCtaClick:()=>w(!0)}):pe.map(t=>e.jsx(ct,{node:t,onSelect:v,getHealthStatus:P,getRoleIcon:T,getSkillBadges:U},t.agent.id))}):E==="board"?e.jsx("div",{className:"agent-board",children:re.length===0?e.jsx(Te,{onCtaClick:()=>w(!0)}):re.map(t=>{const o=P(t),x=Pe(t.state),I=st("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${I}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>v(t.id),role:"button",tabIndex:0,onKeyDown:F=>F.key==="Enter"&&v(t.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:T(t.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:b(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${x}`,children:t.state})]}),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:o.color},title:o.label,children:[o.icon,!o.stateDerived&&` ${o.label}`]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:re.length===0?e.jsx(Te,{onCtaClick:()=>w(!0)}):re.map(t=>{const o=P(t),x=Pe(t.state),I=st("agent-card",t.state),F=Qe(t.runtimeConfig?.heartbeatIntervalMs),s=Rt(F),C=be===t.id;return e.jsxs("div",{className:`agent-card ${I}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>v(t.id),role:"button",tabIndex:0,onKeyDown:y=>y.key==="Enter"&&v(t.id),children:[N===t.id?e.jsx("select",{ref:oe,className:"select agent-role-select",value:t.role,onChange:y=>void V(t.id,y.target.value),onKeyDown:y=>we(y,t.id),onBlur:()=>ee(null),autoFocus:!0,children:Me.map(y=>e.jsxs("option",{value:y.value,children:[y.icon," ",y.label]},y.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:y=>{y.stopPropagation(),ee(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.stopPropagation(),ee(t.id))},children:T(t.role)}),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(it,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${x}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:o.color},title:o.label,children:[o.icon,!o.stateDerived&&` ${o.label}`]}),e.jsx("span",{className:"badge text-secondary",children:b(t.role)}),(()=>{const y=U(t);if(y.length===0)return null;const $=y.slice(0,2),X=y.length-2;return e.jsxs(e.Fragment,{children:[$.map(We=>e.jsx("span",{className:"badge badge-skill",children:We},We)),X>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",X]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[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:"}),xe===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:ce[t.id]??"",onChange:y=>L($=>({...$,[t.id]:y.target.value})),onKeyDown:y=>{y.key==="Enter"?je(t):y.key==="Escape"&&(te(null),L($=>{const X={...$};return delete X[t.id],X}))},disabled:C,"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 je(t),disabled:C,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{te(null),L(y=>{const $={...y};return delete $[t.id],$})},disabled:C,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:F,onChange:y=>{const $=y.target.value;$==="__custom__"?ue(t):ke(t,Number($))},disabled:C,"aria-label":`Set heartbeat interval for ${t.name}`,children:[s.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value)),_t.some(y=>y.value===F)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),C&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const y=new Date(t.lastHeartbeatAt),$=new Date(y.getTime()+F),X=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:y.toLocaleString(),children:["Last: ",y.toLocaleTimeString()]}),X&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:$.toLocaleString(),children:["Next: ",$.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"active"),disabled:O.has(t.id),title:"Activate",children:[e.jsx(Ee,{size:14})," Start"]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void i(t.id,t.name),disabled:O.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(Ie,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"paused"),disabled:O.has(t.id),title:"Pause",children:[e.jsx(Je,{size:14})," Pause"]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"active"),disabled:O.has(t.id),title:"Resume",children:[e.jsx(Ee,{size:14})," Resume"]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${t.name}`,children:[e.jsx(Ie,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"paused"),disabled:O.has(t.id),title:"Pause",children:[e.jsx(Je,{size:14})," Pause"]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"active"),disabled:O.has(t.id),title:"Retry",children:[e.jsx(Ee,{size:14})," Retry"]}),t.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void he(t.id,"active"),disabled:O.has(t.id),title:"Start",children:[e.jsx(Ee,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>v(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void K(t.id,t.name),title:"Delete",children:[e.jsx(Pt,{size:14})," Delete"]})]})]},t.id)})}),e.jsx(Yt,{agents:ye,projectId:l,onAgentSelect:v})]}),f&&e.jsx(n.Suspense,{fallback:null,children:e.jsx(Pn,{agentId:f,projectId:l,onClose:Ce,addToast:a,onChildClick:Se})})]})}const On=Object.freeze(Object.defineProperty({__proto__:null,AgentsView:$n},Symbol.toStringTag,{value:"Module"}));export{On as A,An as S};
|