@runfusion/fusion 0.14.2 → 0.15.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 +949 -138
- package/dist/client/assets/AgentDetailView-B1zViykq.js +18 -0
- package/dist/client/assets/{AgentsView-DkX0tzrN.js → AgentsView-Bl9JH5C8.js} +3 -3
- package/dist/client/assets/{ChatView-CEm2Hw6m.js → ChatView-liNErE53.js} +1 -1
- package/dist/client/assets/{DevServerView-Bumvo_ge.js → DevServerView-CV_PpbnZ.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-CXN11cBp.js → DirectoryPicker-DPfkGnj5.js} +1 -1
- package/dist/client/assets/{DocumentsView-B71IqAxA.js → DocumentsView-CESb6RI7.js} +1 -1
- package/dist/client/assets/{InsightsView-Bs4Rldu6.js → InsightsView-BKhvyEyQ.js} +1 -1
- package/dist/client/assets/{MemoryView-Bs7b_L2Q.js → MemoryView-DB-l2miV.js} +1 -1
- package/dist/client/assets/{NodesView-BvAGTXbO.js → NodesView-DgTXO8mm.js} +1 -1
- package/dist/client/assets/{PiExtensionsManager-3Kcc4uhA.js → PiExtensionsManager-C4fTzemh.js} +1 -1
- package/dist/client/assets/{PluginManager-Ch-Xynlm.js → PluginManager-C2-dExUL.js} +1 -1
- package/dist/client/assets/{ResearchView-Bj6Saqf6.js → ResearchView-CkVwRDVA.js} +1 -1
- package/dist/client/assets/{RoadmapsView-9qT8Vwd0.js → RoadmapsView-Cu85_XrQ.js} +1 -1
- package/dist/client/assets/{SettingsModal-D4ERGQNQ.js → SettingsModal-BGnSAeqa.js} +1 -1
- package/dist/client/assets/SettingsModal-C0DokcId.js +31 -0
- package/dist/client/assets/{SetupWizardModal-Dv0rX2_o.js → SetupWizardModal-C_d9clJp.js} +1 -1
- package/dist/client/assets/{SkillMultiselect-CSkXQzdv.js → SkillMultiselect-DwGWYZi6.js} +1 -1
- package/dist/client/assets/{SkillsView-2srXMOzj.js → SkillsView-C096TB7i.js} +1 -1
- package/dist/client/assets/{TodoView-CxPPIvw2.js → TodoView-CUiAt2mR.js} +1 -1
- package/dist/client/assets/{folder-open-FA1PwpXV.js → folder-open-CKivQd8c.js} +1 -1
- package/dist/client/assets/index-B4StE1qN.js +662 -0
- package/dist/client/assets/index-DYJk0WDc.css +1 -0
- package/dist/client/assets/{list-checks-6EktkUso.js → list-checks-B3oufblU.js} +1 -1
- package/dist/client/assets/{star-B6Th07jw.js → star-damu_EYz.js} +1 -1
- package/dist/client/assets/{upload-BJwuErhV.js → upload-uH6CHlEw.js} +1 -1
- package/dist/client/assets/{users-BrnPTF8H.js → users-CUySbfji.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/version.json +1 -1
- package/dist/extension.js +722 -120
- package/dist/pi-claude-cli/index.ts +2 -2
- package/dist/pi-claude-cli/package.json +1 -1
- package/package.json +1 -1
- package/dist/client/assets/AgentDetailView-C2Iik3Qf.js +0 -18
- package/dist/client/assets/SettingsModal-Zo5qDGOq.js +0 -31
- package/dist/client/assets/index-CEavim6l.js +0 -662
- package/dist/client/assets/index-D1gTSlYB.css +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import{r as t,j as e}from"./vendor-react-K0fH_qHe.js";import{c as We,dk as Hs,dl as Is,dm as Os,dn as _s,L as O,R as Ye,al as hs,Z as Vs,am as Ue,V as Le,W as Ss,N as ks,dp as Us,dq as Js,dr as qs,w as Rs,cx as Gs,ds as Ws,z as q,dt as Ys,du as Cs,dv as ws,s as Ee,B as gs,Q as Ae,U as fs,a$ as ye,X as Ks,F as Se,A as Te,I as Ke,dw as Zs,cr as Qs,aF as Xs,bn as et,an as Ms,Y as st,a1 as tt,a3 as at,dx as qe,j as Fs,dy as nt,r as it,dz as rt,dA as lt,dB as ct,dC as De,a9 as Pe,ab as ze,ac as Be,C as X,a7 as As,dD as ot,dE as dt,i as ut,h as mt,k as ht,dF as Ge,a2 as gt,dG as ft,dH as xt,dI as pt,dJ as vt,dK as bt,dL as Es,dM as jt,dN as Nt,a0 as yt,dO as St,_ as kt,dP as Rt}from"./index-B4StE1qN.js";import{S as Ts}from"./star-damu_EYz.js";import{S as Ct}from"./SkillMultiselect-DwGWYZi6.js";import{L as $s}from"./list-checks-B3oufblU.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
2
|
+
* @license lucide-react v1.7.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const wt=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],$e=We("chart-column",wt);/**
|
|
7
|
+
* @license lucide-react v1.7.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const Mt=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M17 12h-2l-2 5-2-10-2 5H7",key:"15hlnc"}]],Ft=We("square-activity",Mt);/**
|
|
12
|
+
* @license lucide-react v1.7.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const At=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],Et=We("trending-down",At);function xs(s){return s<1e3?`${s}ms`:s<6e4?`${(s/1e3).toFixed(1)}s`:s<36e5?`${Math.floor(s/6e4)}m`:`${(s/36e5).toFixed(1)}h`}function Tt(s){return`${Math.round(s*100)}%`}function ps(s){const a=Date.now(),i=new Date(s).getTime(),d=a-i;if(d<0){const u=Math.abs(d);return u<6e4?"in a moment":u<36e5?`in ${Math.floor(u/6e4)}m`:u<864e5?`in ${Math.floor(u/36e5)}h`:`in ${Math.floor(u/864e5)}d`}return d<6e4?"just now":d<36e5?`${Math.floor(d/6e4)}m ago`:d<864e5?`${Math.floor(d/36e5)}h ago`:`${Math.floor(d/864e5)}d ago`}function $t(s){switch(s){case"periodic":return"Periodic";case"post-task":return"Post-Task";case"manual":return"Manual";case"user-requested":return"User Requested";default:return s}}function je(s){return s instanceof Error&&s.message?s.message:String(s)}function Lt(s){switch(s){case"improving":return"↑ Improving";case"declining":return"↓ Declining";case"stable":return"→ Stable";default:return"Insufficient data"}}function Dt(s){switch(s){case"improving":return"trend-improving";case"declining":return"trend-declining";case"stable":return"trend-stable";default:return"trend-insufficient"}}function vs(s,a=5){return e.jsx("span",{className:"rating-stars",children:Array.from({length:a},(i,d)=>e.jsx(Ts,{size:14,className:d<s?"star-filled":"star-empty",fill:d<s?"currentColor":"none"},d))})}function Pt({agentId:s,projectId:a,addToast:i}){const[d,u]=t.useState([]),[r,N]=t.useState(null),[m,v]=t.useState(null),[x,j]=t.useState([]),[A,f]=t.useState(!0),[E,T]=t.useState(!0),[C,o]=t.useState(!1),[b,k]=t.useState(!1),[$,L]=t.useState(null),[M,y]=t.useState(0),[U,J]=t.useState(""),[G,w]=t.useState(""),B=t.useCallback(async()=>{try{const[l,R]=await Promise.all([Hs(s,20,a),Is(s,void 0,a)]);u(l),N(R)}catch(l){i(`Failed to load reflections: ${je(l)}`,"error")}finally{f(!1)}},[s,a,i]),h=t.useCallback(async()=>{try{const[l,R]=await Promise.all([Os(s,a),_s(s,{limit:50},a)]);v(l),j(R)}catch(l){i(`Failed to load ratings: ${je(l)}`,"error")}finally{T(!1)}},[s,a,i]);t.useEffect(()=>{B(),h()},[B,h]);const _=async()=>{o(!0);try{if(!await Us(s,a)){i("Not enough history to generate a reflection yet","error");return}i("Reflection generated successfully","success"),f(!0),await B()}catch(l){const R=je(l),W=R.toLowerCase();W.includes("agent not found")||W.includes("not found")?i("This agent is no longer available. It may have been deleted.","error"):W.includes("insufficient history")?i("Not enough history to generate a reflection yet","error"):i(`Failed to generate reflection: ${R}`,"error")}finally{o(!1)}},H=async l=>{if(l.preventDefault(),M!==0){k(!0);try{await Js(s,{score:M,category:U||void 0,comment:G||void 0,raterType:"user"},a),y(0),J(""),w(""),i("Rating added","success"),await h()}catch(R){i(`Failed to add rating: ${je(R)}`,"error")}finally{k(!1)}}},I=async l=>{try{await qs(s,l,a),i("Rating deleted","success"),await h()}catch(R){i(`Failed to delete rating: ${je(R)}`,"error")}},c=l=>{L(R=>R===l?null:l)};if(A&&E)return e.jsx("div",{className:"reflections-tab",children:e.jsxs("div",{className:"reflections-loading-indicator",children:[e.jsx(O,{size:16,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading evaluation..."})]})});const z=r&&r.totalTasksCompleted===0&&r.totalTasksFailed===0&&r.recentReflectionCount===0;return e.jsxs("div",{className:"reflections-tab",children:[e.jsxs("div",{className:"reflections-header",children:[e.jsxs("h3",{children:[e.jsx($e,{size:16}),"Performance, Reflections & Ratings"]}),e.jsx("button",{className:"btn btn-secondary",onClick:_,disabled:C,title:"Generate a manual reflection",children:C?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:14,className:"animate-spin"}),"Reflecting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ye,{size:14}),"Reflect Now"]})})]}),r&&!z&&e.jsxs("div",{className:"reflections-stats-grid",children:[e.jsxs("div",{className:"reflections-stat-card",children:[e.jsxs("div",{className:"stat-value",children:[e.jsx(hs,{size:16,style:{color:"var(--color-success)"}}),r.totalTasksCompleted]}),e.jsx("div",{className:"stat-label",children:"Tasks Completed"})]}),e.jsxs("div",{className:"reflections-stat-card",children:[e.jsxs("div",{className:"stat-value",children:[e.jsx(Et,{size:16,style:{color:"var(--color-error)"}}),r.totalTasksFailed]}),e.jsx("div",{className:"stat-label",children:"Tasks Failed"})]}),e.jsxs("div",{className:"reflections-stat-card",children:[e.jsxs("div",{className:"stat-value",children:[e.jsx(Vs,{size:16,style:{color:"var(--in-progress)"}}),xs(r.avgDurationMs)]}),e.jsx("div",{className:"stat-label",children:"Avg Duration"})]}),e.jsxs("div",{className:"reflections-stat-card",children:[e.jsxs("div",{className:"stat-value",children:[e.jsx($e,{size:16,style:{color:r.successRate>=.8?"var(--color-success)":r.successRate>=.5?"var(--color-warning)":"var(--color-error)"}}),Tt(r.successRate)]}),e.jsx("div",{className:"stat-label",children:"Success Rate"})]}),e.jsxs("div",{className:"reflections-stat-card",children:[e.jsxs("div",{className:"stat-value",children:[e.jsx(Ue,{size:16,style:{color:"var(--color-info)"}}),r.recentReflectionCount]}),e.jsx("div",{className:"stat-label",children:"Reflections"})]})]}),z&&e.jsxs("div",{className:"reflections-no-data",children:[e.jsx($e,{size:24,opacity:.3}),e.jsx("p",{children:"No performance data yet"})]}),e.jsxs("div",{className:"reflections-ratings-section",children:[e.jsx("h4",{children:"User Ratings"}),E?e.jsxs("div",{className:"reflections-loading-indicator",children:[e.jsx(O,{size:16,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading ratings..."})]}):e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"rating-summary-card",children:[e.jsxs("div",{className:"rating-score-display",children:[e.jsx("span",{className:"rating-average",children:m.averageScore.toFixed(1)}),vs(Math.round(m.averageScore))]}),e.jsxs("div",{className:"rating-stats",children:[e.jsxs("span",{className:"rating-count",children:[m.totalRatings," ratings"]}),e.jsx("span",{className:`rating-trend-badge ${Dt(m.trend)}`,children:Lt(m.trend)})]})]}),m&&Object.keys(m.categoryAverages).length>0&&e.jsxs("div",{className:"category-breakdown",children:[e.jsx("h4",{children:"Category Averages"}),Object.entries(m.categoryAverages).map(([l,R])=>e.jsxs("div",{className:"category-item",children:[e.jsx("span",{className:"category-name",children:l}),e.jsx("span",{className:"category-score",children:R.toFixed(1)})]},l))]}),e.jsxs("form",{className:"add-rating-form",onSubmit:H,children:[e.jsx("h4",{children:"Add Rating"}),e.jsx("div",{className:"star-selector",children:[1,2,3,4,5].map(l=>e.jsx("button",{type:"button",className:"star-btn touch-target",onClick:()=>y(l),title:`${l} star${l>1?"s":""}`,children:e.jsx(Ts,{size:24,fill:l<=M?"currentColor":"none",className:l<=M?"star-filled":"star-empty"})},l))}),e.jsxs("select",{value:U,onChange:l=>J(l.target.value),className:"select add-rating-category-select",children:[e.jsx("option",{value:"",children:"Select category..."}),e.jsx("option",{value:"quality",children:"Quality"}),e.jsx("option",{value:"speed",children:"Speed"}),e.jsx("option",{value:"communication",children:"Communication"}),e.jsx("option",{value:"reliability",children:"Reliability"}),e.jsx("option",{value:"other",children:"Other"})]}),e.jsx("textarea",{value:G,onChange:l=>w(l.target.value),placeholder:"Optional comment...",className:"input add-rating-comment-input",rows:3}),e.jsx("button",{type:"submit",className:"btn btn-task-create",disabled:M===0||b,children:b?"Submitting...":"Submit Rating"})]}),e.jsxs("div",{className:"rating-history",children:[e.jsx("h4",{children:"Rating History"}),x.length===0?e.jsx("p",{className:"no-ratings",children:"No ratings yet"}):x.map(l=>e.jsxs("div",{className:"rating-history-item",children:[e.jsxs("div",{className:"rating-item-header",children:[vs(l.score),l.category&&e.jsx("span",{className:"rating-category-badge",children:l.category}),e.jsx("span",{className:"rating-time",children:ps(l.createdAt)}),e.jsx("button",{type:"button",className:"rating-delete-btn touch-target",onClick:()=>void I(l.id),title:"Delete rating",children:e.jsx(Le,{size:14})})]}),l.comment&&e.jsx("p",{className:"rating-comment",children:l.comment})]},l.id))]})]})]}),e.jsxs("div",{className:"reflections-list",children:[e.jsx("h4",{children:"Reflection History"}),A?e.jsxs("div",{className:"reflections-loading-indicator",children:[e.jsx(O,{size:16,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading reflections..."})]}):d.length===0?e.jsxs("div",{className:"reflection-empty",children:[e.jsx(Ue,{size:32,opacity:.3}),e.jsx("p",{children:"No reflections yet"}),e.jsx("p",{className:"text-secondary",children:"Trigger a reflection to get started"})]}):e.jsx("div",{className:"reflection-cards",children:d.map(l=>{const R=$===l.id;return e.jsxs("div",{className:`reflection-card ${R?"reflection-card--expanded":""}`,onClick:()=>c(l.id),role:"button",tabIndex:0,onKeyDown:W=>W.key==="Enter"&&c(l.id),children:[e.jsxs("div",{className:"reflection-card-header",children:[e.jsx("span",{className:`reflection-trigger-badge reflection-trigger-${l.trigger}`,children:$t(l.trigger)}),e.jsx("span",{className:"reflection-timestamp",children:ps(l.timestamp)}),e.jsx("span",{className:"reflection-chevron",children:R?e.jsx(Ss,{size:16}):e.jsx(ks,{size:16})})]}),e.jsx("div",{className:"reflection-summary",children:l.summary}),R&&e.jsxs("div",{className:"reflection-details",children:[l.insights.length>0&&e.jsxs("div",{className:"reflection-insights",children:[e.jsxs("h5",{children:[e.jsx(Ue,{size:14})," Insights"]}),e.jsx("ul",{children:l.insights.map((W,ne)=>e.jsx("li",{children:W},ne))})]}),l.suggestedImprovements.length>0&&e.jsxs("div",{className:"reflection-suggestions",children:[e.jsxs("h5",{children:[e.jsx(hs,{size:14})," Suggested Improvements"]}),e.jsx("ul",{children:l.suggestedImprovements.map((W,ne)=>e.jsx("li",{children:W},ne))})]}),l.metrics&&e.jsxs("div",{className:"reflection-metrics",children:[e.jsx("h5",{children:"Metrics"}),e.jsxs("div",{className:"metrics-grid",children:[l.metrics.tasksCompleted!==void 0&&e.jsxs("div",{className:"metric",children:[e.jsx("span",{className:"metric-label",children:"Tasks:"}),e.jsx("span",{className:"metric-value",children:l.metrics.tasksCompleted})]}),l.metrics.tasksFailed!==void 0&&e.jsxs("div",{className:"metric",children:[e.jsx("span",{className:"metric-label",children:"Failed:"}),e.jsx("span",{className:"metric-value",children:l.metrics.tasksFailed})]}),l.metrics.avgDurationMs!==void 0&&e.jsxs("div",{className:"metric",children:[e.jsx("span",{className:"metric-label",children:"Avg Duration:"}),e.jsx("span",{className:"metric-value",children:xs(l.metrics.avgDurationMs)})]}),l.metrics.errorCount!==void 0&&e.jsxs("div",{className:"metric",children:[e.jsx("span",{className:"metric-label",children:"Errors:"}),e.jsx("span",{className:"metric-value",children:l.metrics.errorCount})]})]})]})]})]},l.id)})})]})]})}function se(...s){return s.filter(Boolean).join(" ")}function ke(s){const a=Date.now(),i=new Date(s).getTime(),d=a-i;if(d<0){const u=Math.abs(d);return u<6e4?"in a moment":u<36e5?`in ${Math.floor(u/6e4)}m`:u<864e5?`in ${Math.floor(u/36e5)}h`:`in ${Math.floor(u/864e5)}d`}return d<6e4?"just now":d<36e5?`${Math.floor(d/6e4)}m ago`:d<864e5?`${Math.floor(d/36e5)}h ago`:`${Math.floor(d/864e5)}d ago`}const zt=[{id:"dashboard",label:"Dashboard",icon:Ft},{id:"logs",label:"Logs",icon:Se},{id:"runs",label:"Runs",icon:Te},{id:"tasks",label:"Tasks",icon:$s},{id:"employees",label:"Employees",icon:Ke},{id:"soul",label:"Soul",icon:Zs},{id:"instructions",label:"Instructions",icon:Qs},{id:"memory",label:"Agent Memory",icon:Se},{id:"reflections",label:"Evaluation",icon:$e},{id:"config",label:"Settings",icon:Xs}],Ze={idle:{bg:"var(--state-idle-bg)",text:"var(--state-idle-text)",border:"var(--state-idle-border)"},active:{bg:"var(--state-active-bg)",text:"var(--state-active-text)",border:"var(--state-active-border)"},running:{bg:"var(--state-active-bg)",text:"var(--state-active-text)",border:"var(--state-active-border)"},paused:{bg:"var(--state-paused-bg)",text:"var(--state-paused-text)",border:"var(--state-paused-border)"},error:{bg:"var(--state-error-bg)",text:"var(--state-error-text)",border:"var(--state-error-border)"},terminated:{bg:"var(--state-error-bg)",text:"var(--state-error-text)",border:"var(--state-error-border)"}},bs={completed:{icon:X,color:"var(--color-success, #3fb950)"},failed:{icon:xt,color:"var(--color-error, #f85149)"},active:{icon:O,color:"var(--in-progress, #bc8cff)"},terminated:{icon:ye,color:"var(--text-muted, #8b949e)"}},js={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Bt={"long-term":"Curated durable decisions, conventions, constraints, and pitfalls for this specific agent.",daily:"Raw daily observations and open loops recorded by this agent.",dreams:"Synthesized patterns and emerging themes distilled from this agent's daily memory."},Ht=yt(Ge);function It(s,a){return s.some(i=>i.path===a)?a:s.find(i=>i.layer==="long-term")?.path??s[0]?.path??""}function ca({agentId:s,projectId:a,onClose:i,addToast:d,onChildClick:u}){const[r,N]=t.useState(null),{confirm:m}=Rs(),[v,x]=t.useState([]),[j,A]=t.useState(!0),[f,E]=t.useState("dashboard"),[T,C]=t.useState(!1),[o,b]=t.useState(!1),[k,$]=t.useState(null),L=t.useRef(null),M=t.useRef(null),y=t.useRef(!1);Gs(M,!0,"fusion:agent-detail-modal-size");const U=t.useRef(i),J=t.useRef(d),G=t.useRef(null),w=t.useRef(!1),B=t.useRef(null),h=t.useRef(0),_=t.useRef(s),H=t.useRef(a);U.current=i,J.current=d,G.current=r;const I=t.useCallback(async()=>{G.current===null&&A(!0);try{const V=await Ws(s,a);N(V)}catch(V){J.current(`Failed to load agent: ${q(V)}`,"error"),U.current()}finally{A(!1)}},[s,a]),c=t.useCallback(async()=>{const g=h.current,V=s,K=a,Z=()=>h.current!==g||s!==V||a!==K;try{if(r?.taskId){$(null),B.current=null;const te=await Ys(r.taskId,K,{limit:100});if(Z())return;x(te.entries);return}const oe=await Cs(V,1,K);if(Z())return;const re=oe[0]??null;if($(re),!re){B.current=null,x([]);return}if(B.current===re.id)return;const le=await ws(V,re.id,K);if(Z())return;x([...le].reverse()),B.current=re.id}catch(oe){if(Z())return;console.error("Failed to load agent logs:",oe)}},[r?.taskId,s,a]),z=t.useCallback(g=>{w.current=g},[]);t.useEffect(()=>{I()},[I]),t.useEffect(()=>{const g=setInterval(()=>{I()},3e4);return()=>{clearInterval(g)}},[I]),t.useEffect(()=>{r&&f==="logs"&&c()},[r,f,c]),t.useEffect(()=>{f!=="logs"&&(B.current=null)},[f]),t.useEffect(()=>{if(f!=="logs"||r?.taskId||!k||k.status!=="active")return;const g=h.current,V=s,K=k.id,Z=a?`?projectId=${encodeURIComponent(a)}`:"",oe=Ee(`/api/agents/${encodeURIComponent(V)}/runs/${encodeURIComponent(K)}/logs/stream${Z}`,{events:{"agent:log":re=>{if(h.current===g)try{const le=JSON.parse(re.data);x(te=>[le,...te])}catch{}}},onOpen:()=>{h.current===g&&C(!0)},onError:()=>{h.current===g&&C(!1)}});return()=>{oe(),h.current===g&&C(!1)}},[f,r?.taskId,s,a,k]),t.useEffect(()=>{(_.current!==s||H.current!==a)&&(_.current=s,H.current=a,h.current++,x([]),C(!1),$(null),B.current=null,w.current=!1)},[s,a]),t.useEffect(()=>{const g=a?`?projectId=${encodeURIComponent(a)}`:"",V=h.current;return Ee(`/api/events${g}`,{events:{"agent:updated":K=>{if(h.current===V)try{const Z=JSON.parse(K.data);if(!Z||typeof Z!="object"||Z.id!==s||w.current)return;I()}catch{}}}})},[s,a,I]),t.useEffect(()=>{if(f!=="logs"||!r?.taskId){C(!1);return}const g=h.current,V=r.taskId,K=a?`?projectId=${encodeURIComponent(a)}`:"",Z=Ee(`/api/tasks/${encodeURIComponent(V)}/logs/stream${K}`,{events:{"agent:log":oe=>{if(h.current===g)try{const re=JSON.parse(oe.data);x(te=>[re,...te]);const le=L.current;le&&le.scrollTop<50&&(le.scrollTop=0)}catch{}}},onOpen:()=>{h.current===g&&C(!0)},onError:()=>{h.current===g&&C(!1)}});return()=>{Z(),h.current===g&&C(!1)}},[r?.taskId,f,a]);const l=async g=>{if(o||!G.current)return;const V=G.current.state;if(V!==g){b(!0),N(K=>K&&{...K,state:g});try{await tt(s,g,a),d(`Agent state updated to ${g}`,"success"),I()}catch(K){N(Z=>Z&&{...Z,state:V}),d(`Failed to update state: ${q(K)}`,"error")}finally{b(!1)}}},R=async()=>{if(!(!r||!await m({title:"Delete Agent",message:`Delete agent "${r.name}"? This cannot be undone.`,danger:!0})))try{await at(s,a),d(`Agent "${r.name}" deleted`,"success"),i()}catch(V){d(`Failed to delete agent: ${q(V)}`,"error")}},W=()=>r?st(r):{label:"Unknown",icon:e.jsx(gs,{size:14}),color:"var(--text-muted, #8b949e)",stateDerived:!1},ne=()=>{r&&(navigator.clipboard.writeText(r.id),d("Agent ID copied to clipboard","success"))};if(j)return e.jsx("div",{className:"agent-detail-overlay",onMouseDown:g=>{g.target===g.currentTarget&&(y.current=!0)},onMouseUp:g=>{y.current&&g.target===g.currentTarget&&i(),y.current=!1},role:"dialog","aria-modal":"true",children:e.jsx("div",{className:"agent-detail-modal",ref:M,children:e.jsxs("div",{className:"agent-detail-loading",children:[e.jsx(O,{className:"animate-spin",size:24}),e.jsx("span",{children:"Loading agent..."})]})})});if(!r)return null;const ie=Ze[r.state],p=W();return e.jsx("div",{className:"agent-detail-overlay",onClick:g=>g.target===g.currentTarget&&i(),role:"dialog","aria-modal":"true",children:e.jsxs("div",{className:"agent-detail-modal",children:[e.jsxs("div",{className:"agent-detail-header",children:[e.jsxs("div",{className:"agent-detail-identity",children:[e.jsx("div",{className:"agent-detail-icon",children:e.jsx(gs,{size:20})}),e.jsxs("div",{className:"agent-detail-info",children:[e.jsx("h2",{children:r.name}),e.jsxs("div",{className:"agent-detail-badges",children:[e.jsx("span",{className:"badge",style:{background:ie.bg,color:ie.text,border:`1px solid ${ie.border}`},children:r.state}),e.jsxs("span",{className:"badge",style:{color:p.color},title:p.label,children:[p.icon,!p.stateDerived&&p.label]})]})]})]}),e.jsxs("div",{className:"agent-detail-controls",children:[r.state==="idle"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-task-create btn--compact",onClick:()=>void l("active"),disabled:o,children:[e.jsx(Ae,{size:14}),"Start"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:R,children:[e.jsx(Le,{size:14}),"Delete"]})]}),r.state==="active"&&e.jsxs("button",{className:"btn btn--compact",onClick:()=>void l("paused"),disabled:o,children:[e.jsx(fs,{size:14}),"Pause"]}),r.state==="paused"&&e.jsxs("button",{className:"btn btn-task-create btn--compact",onClick:()=>void l("active"),disabled:o,children:[e.jsx(Ae,{size:14}),"Resume"]}),r.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--compact",onClick:()=>void l("paused"),disabled:o,children:[e.jsx(fs,{size:14}),"Pause"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:()=>void l("terminated"),disabled:o,children:[e.jsx(ye,{size:14}),"Stop"]})]}),r.state==="error"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-task-create btn--compact",onClick:()=>void l("active"),disabled:o,children:[e.jsx(Ae,{size:14}),"Retry"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:()=>void l("terminated"),disabled:o,children:[e.jsx(ye,{size:14}),"Stop"]})]}),r.state==="terminated"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-task-create btn--compact",onClick:()=>void l("active"),disabled:o,children:[e.jsx(Ae,{size:14}),"Start"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:R,children:[e.jsx(Le,{size:14}),"Delete"]})]})]}),e.jsxs("div",{className:"agent-detail-utility-actions",children:[e.jsx("button",{className:"btn-icon",onClick:()=>void I(),title:"Refresh",children:e.jsx(Ye,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:i,"aria-label":"Close",title:"Close",children:e.jsx(Ks,{size:20})})]})]}),e.jsx("div",{className:"agent-detail-tabs",children:zt.map(g=>e.jsxs("button",{className:se("agent-detail-tab",f===g.id&&"active"),onClick:()=>E(g.id),children:[e.jsx(g.icon,{size:16}),g.label]},g.id))}),e.jsxs("div",{className:"agent-detail-content",children:[f==="dashboard"&&e.jsx(Ot,{agent:r,health:p,onChildClick:u,projectId:a}),f==="logs"&&e.jsx(_t,{logs:v,isStreaming:T,containerRef:L,hasTask:!!r.taskId||v.length>0||k!==null,fallbackLabel:!r.taskId&&k?`Latest run · ${k.id.slice(0,8)}`:null}),f==="runs"&&e.jsx(Ut,{addToast:d,agentId:r.id,projectId:a,agentState:r.state,agentName:r.name}),f==="tasks"&&e.jsx(Wt,{agentId:r.id,projectId:a,addToast:d}),f==="employees"&&e.jsx(sa,{agentId:r.id,projectId:a,onChildClick:u}),f==="soul"&&e.jsx(Kt,{agent:r,projectId:a,addToast:d,onSaved:I}),f==="instructions"&&e.jsx(Qt,{agent:r,projectId:a,addToast:d,onSaved:I}),f==="memory"&&e.jsx(Zt,{agent:r,projectId:a,addToast:d,onSaved:I}),f==="reflections"&&e.jsx(Pt,{agentId:r.id,projectId:a,addToast:d}),f==="config"&&e.jsx(ea,{agent:r,projectId:a,addToast:d,onSaved:I,onHasChangesChange:z,onDelete:R})]}),e.jsxs("div",{className:"agent-detail-footer",children:[e.jsx("button",{className:"btn-icon",onClick:ne,title:"Copy Agent ID",children:e.jsx(et,{})}),e.jsx("span",{className:"agent-detail-id",onClick:ne,children:r.id}),r.taskId&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"divider",children:"|"}),e.jsx("span",{className:"text-muted",children:"Working on:"}),e.jsxs("a",{href:`/tasks/${r.taskId}`,className:"link",children:[r.taskId,e.jsx(Ms,{size:12})]})]})]})]})})}function Ot({agent:s,health:a,onChildClick:i,projectId:d}){const u=Ze[s.state],[r,N]=t.useState([]),[m,v]=t.useState(!0),[x,j]=t.useState(null),[A,f]=t.useState([]),E=typeof s.runtimeConfig?.runtimeHint=="string"?s.runtimeConfig.runtimeHint:"",T=(()=>{const o=s.runtimeConfig??{};if(E){const b=A.find(k=>k.runtimeId===E);return b?b.name:E}if(o.modelProvider&&o.modelId)return`${o.modelProvider}/${o.modelId}`;if(typeof o.model=="string"&&o.model.includes("/")){const b=o.model.indexOf("/");return o.model.slice(b+1)}return null})();t.useEffect(()=>{qe(s.id,d).then(j).catch(()=>j(null))},[s.id,d]),t.useEffect(()=>{Fs(d).then(f).catch(()=>f([]))},[d]),t.useEffect(()=>{let o=!1;return v(!0),nt(s.id,d).then(b=>{if(o)return;const k=b.length>0&&b[0]?.id===s.id?[...b].reverse():b;N(k)}).catch(()=>{o||N([])}).finally(()=>{o||v(!1)}),()=>{o=!0}},[s.id,d]);const C=t.useMemo(()=>{const o=s.completedRuns||[],b=new Date;b.setHours(0,0,0,0);const k=o.filter(L=>new Date(L.startedAt)>=b),$=o.filter(L=>L.status==="completed");return{totalRuns:o.length,todayRuns:k.length,successfulRuns:$.length,successRate:o.length>0?Math.round($.length/o.length*100):0}},[s]);return e.jsxs("div",{className:"dashboard-tab",children:[x?.isOverBudget&&e.jsxs("div",{className:"budget-warning-banner",role:"alert",children:[e.jsx("span",{children:"⚠️"}),e.jsxs("span",{children:[e.jsx("strong",{children:"Budget Exhausted:"})," This agent has exceeded its token budget and may be operating with limited functionality."]})]}),e.jsxs("div",{className:"dashboard-section",children:[e.jsx("h3",{children:"Agent Information"}),e.jsxs("div",{className:"info-grid",children:[e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Name"}),e.jsx("span",{className:"info-value",children:s.name})]}),e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Role"}),e.jsx("span",{className:"info-value",children:s.role})]}),e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Skills"}),e.jsx("span",{className:"info-value",children:Array.isArray(s.metadata?.skills)&&s.metadata.skills.length>0?e.jsx("div",{className:"skill-badge-row",children:s.metadata.skills.map(o=>e.jsx("span",{className:"skill-badge",children:o},o))}):"—"})]}),e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"State"}),e.jsx("span",{className:"info-value",children:e.jsx("span",{className:"inline-badge",style:{background:u.bg,color:u.text},children:s.state})})]}),e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Health"}),e.jsx("span",{className:"info-value",style:{color:a.color},title:a.label,children:a.stateDerived?a.icon:a.label})]}),T&&e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:E?"Runtime":"Model"}),e.jsx("span",{className:"info-value",children:T})]}),x?.budgetLimit!=null&&e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Budget"}),e.jsx("span",{className:"info-value",children:e.jsx("span",{className:"budget-badge",style:{background:x.isOverBudget?"var(--state-error-bg, rgba(248,81,73,0.15))":x.isOverThreshold?"var(--state-paused-bg, rgba(227,181,65,0.15))":"var(--state-active-bg, rgba(63,185,80,0.15))",color:x.isOverBudget?"var(--state-error-text, #f85149)":x.isOverThreshold?"var(--state-paused-text, #e3b541)":"var(--state-active-text, #3fb950)",border:`1px solid ${x.isOverBudget?"var(--state-error-border, #f85149)":x.isOverThreshold?"var(--state-paused-border, #e3b541)":"var(--state-active-border, #3fb950)"}`},children:x.isOverBudget?"⚠ Budget Exhausted":`${Math.round(x.usagePercent??0)}% used`})})]}),e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Created"}),e.jsx("span",{className:"info-value",children:new Date(s.createdAt).toLocaleDateString()})]}),e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Last Heartbeat"}),e.jsx("span",{className:"info-value",children:s.lastHeartbeatAt?ke(s.lastHeartbeatAt):"Never"})]}),(()=>{if(!(s.state==="active"||s.state==="running")||!s.lastHeartbeatAt)return null;const b=it(s.runtimeConfig?.heartbeatIntervalMs),k=new Date(new Date(s.lastHeartbeatAt).getTime()+b);return e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Next Heartbeat"}),e.jsx("span",{className:"info-value",title:k.toLocaleString(),children:ke(k.toISOString())})]})})()]})]}),e.jsxs("div",{className:"dashboard-section",children:[e.jsxs("h3",{children:[e.jsx(Ke,{size:16,style:{marginRight:"6px",verticalAlign:"-2px"}}),"Chain of Command"]}),m?e.jsxs("div",{className:"chain-of-command-loading",role:"status","aria-live":"polite",children:[e.jsx(O,{size:14,className:"animate-spin"}),e.jsx("span",{children:"Loading reporting chain..."})]}):r.length<=1?e.jsx("p",{className:"text-muted",children:"No reporting chain"}):e.jsx("div",{className:"chain-of-command-path","aria-label":"Chain of command",children:r.map((o,b)=>{const k=b===r.length-1,$=!k;return e.jsxs("div",{className:"chain-of-command-item",children:[e.jsx("button",{type:"button",className:`chain-of-command-node${k?" chain-of-command-node--current":""}`,onClick:()=>$&&i?.(o.id),disabled:!$||!i,title:k?"Current agent":`View ${o.name}`,children:o.name}),!k&&e.jsx("span",{className:"chain-of-command-separator","aria-hidden":"true",children:"→"})]},o.id)})})]}),e.jsxs("div",{className:"dashboard-section",children:[e.jsx("h3",{children:"Statistics"}),e.jsxs("div",{className:"stats-grid",children:[e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-value",children:C.totalRuns}),e.jsx("div",{className:"stat-label",children:"Total Runs"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-value",children:C.todayRuns}),e.jsx("div",{className:"stat-label",children:"Runs Today"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsxs("div",{className:"stat-value",children:[C.successRate,"%"]}),e.jsx("div",{className:"stat-label",children:"Success Rate"})]})]})]}),s.taskId&&e.jsxs("div",{className:"dashboard-section",children:[e.jsx("h3",{children:"Current Task"}),e.jsxs("div",{className:"current-task",children:[e.jsx("span",{className:"task-badge",children:s.taskId}),e.jsxs("a",{href:`/tasks/${s.taskId}`,className:"btn btn--sm",children:["View Task ",e.jsx(Ms,{size:14})]})]})]}),s.metadata&&Object.keys(s.metadata).length>0&&e.jsxs("div",{className:"dashboard-section",children:[e.jsx("h3",{children:"Metadata"}),e.jsx("pre",{className:"metadata-json",children:JSON.stringify(s.metadata,null,2)})]})]})}function _t({logs:s,isStreaming:a,containerRef:i,hasTask:d,fallbackLabel:u}){return d?e.jsxs("div",{className:"logs-tab",children:[e.jsxs("div",{className:"logs-header",children:[e.jsxs("span",{className:"logs-count",children:[s.length," entries"]}),u&&e.jsx("span",{className:"text-muted",style:{fontSize:"12px"},children:u}),a&&e.jsxs("span",{className:"streaming-indicator",children:[e.jsx("span",{className:"streaming-dot"}),"Live"]})]}),e.jsx("div",{ref:i,className:"logs-container",children:s.length===0?e.jsxs("div",{className:"logs-empty",children:[e.jsx(Se,{size:48,opacity:.3}),e.jsx("p",{children:"No log entries yet"}),e.jsx("p",{className:"text-muted",children:a?"Waiting for activity...":"Logs will appear here when the agent is active"})]}):s.map((r,N)=>{const m=N>0?s[N-1]:void 0,v=!m||m.agent!==r.agent;return e.jsx(Vt,{entry:r,showTimestamp:v},`${r.timestamp}-${N}`)})})]}):e.jsx("div",{className:"logs-tab",children:e.jsxs("div",{className:"logs-empty",children:[e.jsx(Se,{size:48,opacity:.3}),e.jsx("p",{children:"No activity yet"}),e.jsx("p",{className:"text-muted",children:"Agent logs will appear here from the current task or most recent run"})]})})}function Vt({entry:s,showTimestamp:a}){const d=(()=>{switch(s.type){case"tool":return{color:"var(--accent)",borderLeft:"3px solid var(--accent)",background:"var(--log-tool-bg)"};case"tool_result":return{color:"var(--color-success)",borderLeft:"3px solid var(--color-success)",background:"var(--log-success-bg)"};case"tool_error":return{color:"var(--color-error)",borderLeft:"3px solid var(--color-error)",background:"var(--log-error-bg)"};case"thinking":return{color:"var(--text-muted)",fontStyle:"italic",opacity:.7};default:return{color:"var(--text-primary)"}}})(),u=new Date(s.timestamp).toLocaleTimeString();return e.jsxs("div",{className:"log-entry",style:d,children:[a&&e.jsxs("span",{className:"log-timestamp",children:["[",u,"]"]}),s.agent&&e.jsxs("span",{className:"log-agent",children:["[",s.agent,"]"]}),s.type==="tool"&&e.jsx("span",{className:"log-icon",children:"⚡"}),s.type==="tool_result"&&e.jsx("span",{className:"log-icon",children:"✓"}),s.type==="tool_error"&&e.jsx("span",{className:"log-icon",children:"✗"}),e.jsxs("span",{className:"log-text",children:[s.text,s.detail&&e.jsxs("span",{className:"log-detail",children:[" — ",s.detail]})]})]})}function Ut({addToast:s,agentId:a,projectId:i,agentState:d,agentName:u}){const[r,N]=t.useState([]),{confirm:m}=Rs(),[v,x]=t.useState(!0),[j,A]=t.useState(null),[f,E]=t.useState([]),[T,C]=t.useState(!1),[o,b]=t.useState(null),[k,$]=t.useState(!1),L=t.useCallback(async()=>{try{const c=await Cs(a,50,i);N(c)}catch(c){s(`Failed to load runs: ${q(c)}`,"error")}finally{x(!1)}},[a,i,s]);t.useEffect(()=>{L()},[L]);const M=r.some(c=>c.status==="active"),y=j?r.find(c=>c.id===j)?.status:void 0;t.useEffect(()=>{if(!M)return;const c=setInterval(()=>{L()},5e3);return()=>clearInterval(c)},[M,L]),t.useEffect(()=>{if(!j||y!=="active")return;const c=i?`?projectId=${encodeURIComponent(i)}`:"";return Ee(`/api/agents/${encodeURIComponent(a)}/runs/${encodeURIComponent(j)}/logs/stream${c}`,{events:{"agent:log":z=>{try{const l=JSON.parse(z.data);E(R=>[...R,l])}catch{}}}})},[j,y,a,i]);const U=t.useCallback(async c=>{if(j===c){A(null),E([]),b(null);return}A(c),C(!0),$(!0),E([]),b(null);try{const[z,l]=await Promise.all([ws(a,c,i),rt(a,c,i)]);E(z),b(l)}catch(z){s(`Failed to load run details: ${q(z)}`,"error"),E([]),b(null)}finally{C(!1),$(!1)}},[j,a,i,s]),J=async()=>{try{await gt(a,i,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${u??a}`,"success"),x(!0),L()}catch(c){s(`Failed to start heartbeat run: ${q(c)}`,"error")}},G=async()=>{if(await m({title:"Stop Active Run",message:"Stop the active run? The agent's work will be interrupted.",danger:!0}))try{await ft(a,i),s("Run stopped","success"),x(!0),L()}catch(z){s(`Failed to stop run: ${q(z)}`,"error")}},w=d==="active"||d==="idle";if(v&&r.length===0)return e.jsx("div",{className:"runs-tab",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"24px",justifyContent:"center"},children:[e.jsx(O,{size:16,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading runs..."})]})});if(r.length===0)return e.jsxs("div",{className:"runs-tab",children:[w&&e.jsx("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border-color)"},children:e.jsxs("button",{className:"btn btn--sm btn-task-create",onClick:()=>void J(),"aria-label":`Run now for ${u??a}`,children:[e.jsx(Te,{size:14})," Run Now"]})}),e.jsxs("div",{className:"runs-empty",children:[e.jsx(Te,{size:48,opacity:.3}),e.jsx("p",{children:"No runs yet"}),e.jsx("p",{className:"text-muted",children:"Heartbeat runs will appear here"})]})]});const B=[...r].sort((c,z)=>new Date(z.startedAt).getTime()-new Date(c.startedAt).getTime()),h=B.filter(c=>c.status==="active"),_=B.filter(c=>c.status!=="active"),H=c=>c?e.jsxs("div",{style:{fontSize:"12px",color:"var(--text-secondary)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[e.jsxs("span",{children:["Input: ",c.inputTokens.toLocaleString()]}),e.jsxs("span",{children:["Output: ",c.outputTokens.toLocaleString()]}),c.cachedTokens>0&&e.jsxs("span",{children:["Cached: ",c.cachedTokens.toLocaleString()]})]}):null,I=(c,z,l)=>{const R=bs[c.status]||bs.completed,W=R.icon,ne=c.endedAt?Jt(new Date(c.startedAt),new Date(c.endedAt)):"In progress",ie=j===c.id;return e.jsxs("div",{children:[e.jsxs("div",{className:se("run-card",l&&"run-card--active",ie&&"run-card--selected"),onClick:()=>void U(c.id),style:{cursor:"pointer"},role:"button",tabIndex:0,"aria-expanded":ie,"aria-label":`${l?"Active":""} run ${c.id.slice(0,8)}, ${c.status}`,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),U(c.id))},children:[e.jsxs("div",{className:"run-header",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[ie?e.jsx(Ss,{size:14}):e.jsx(ks,{size:14}),l?e.jsxs("span",{className:"run-live-indicator",children:[e.jsx("span",{className:"live-dot"}),"Live Run"]}):e.jsxs("span",{className:"run-id",children:["#",z+1," ",c.id.slice(0,8)]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[c.invocationSource&&e.jsx("span",{className:"badge",style:{fontSize:"10px",padding:"1px 6px"},children:c.invocationSource}),l&&e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:p=>{p.preventDefault(),p.stopPropagation(),G()},"aria-label":"Stop active run",children:[e.jsx(ye,{size:12})," Stop"]}),e.jsxs("span",{className:se("run-status",c.status),children:[e.jsx(W,{size:14,className:R.color,style:c.status==="active"?{color:R.color}:void 0}),c.status]}),c.heartbeatProcedureSource==="custom"&&e.jsx("span",{className:"badge",style:{fontSize:"10px",padding:"1px 6px"},children:"Heartbeat: custom"})]})]}),e.jsxs("div",{className:"run-details",children:[e.jsxs("span",{children:["Started ",ke(c.startedAt)]}),e.jsx("span",{children:"•"}),e.jsx("span",{children:ne}),c.triggerDetail&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{className:"text-muted",children:c.triggerDetail})]})]})]}),ie&&e.jsxs("div",{className:"run-logs-container",children:[k?e.jsxs("div",{className:"run-details-loading-state",children:[e.jsx(O,{size:14,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading details..."})]}):o&&e.jsxs("div",{className:"run-output-sections",children:[e.jsx("div",{className:"run-output-section",children:e.jsxs("details",{children:[e.jsx("summary",{className:"run-output-label",style:{cursor:"pointer",userSelect:"none"},children:"System Prompt"}),o.systemPrompt?e.jsx("pre",{className:"run-output-panel",children:o.systemPrompt}):e.jsx("div",{className:"text-muted run-output-empty",children:"System prompt not captured for this run"})]})}),e.jsx("div",{className:"run-output-section",children:e.jsxs("details",{children:[e.jsx("summary",{className:"run-output-label",style:{cursor:"pointer",userSelect:"none"},children:"Execution Prompt"}),o.executionPrompt?e.jsx("pre",{className:"run-output-panel",children:o.executionPrompt}):e.jsx("div",{className:"text-muted run-output-empty",children:"Execution prompt not captured for this run"})]})}),o.usageJson&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label",children:"Token Usage"}),H(o.usageJson)]}),o.stdoutExcerpt&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label",children:"Output"}),e.jsx("pre",{className:"run-output-panel",children:o.stdoutExcerpt.length>2e3?`${o.stdoutExcerpt.slice(0,2e3)}
|
|
17
|
+
|
|
18
|
+
... (truncated, ${o.stdoutExcerpt.length} chars total)`:o.stdoutExcerpt})]}),o.stderrExcerpt&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label run-output-label--error",children:"Errors"}),e.jsx("pre",{className:"run-output-panel run-output-panel--error",children:o.stderrExcerpt})]}),o.resultJson&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label",children:"Result"}),e.jsx("pre",{className:"run-output-panel",children:JSON.stringify(o.resultJson,null,2)})]}),o.contextSnapshot&&Object.keys(o.contextSnapshot).length>0&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label",children:"Context"}),e.jsx("div",{className:"run-context-grid",children:Object.entries(o.contextSnapshot).map(([p,g])=>e.jsxs("span",{className:"run-context-item",children:[e.jsxs("span",{className:"text-muted",children:[p,":"]})," ",e.jsx("span",{children:String(g)})]},p))})]}),!o.stdoutExcerpt&&!o.stderrExcerpt&&!o.resultJson&&e.jsx("div",{className:"text-muted run-output-empty",children:"No output captured"})]}),e.jsxs("div",{className:"run-agent-logs-section",children:[e.jsx("div",{className:"run-output-label",children:"Agent Logs"}),T?e.jsxs("div",{className:"run-details-loading-state",children:[e.jsx(O,{size:14,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading logs..."})]}):f.length===0?e.jsx("div",{className:"text-muted run-output-empty",children:"No logs available for this run"}):e.jsx(pt,{entries:f,loading:!1})]})]})]},c.id)};return e.jsxs("div",{className:"runs-tab",children:[w&&e.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border-color)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--text-secondary)"},children:[r.length," run",r.length!==1?"s":"",M&&e.jsxs("span",{className:"run-live-indicator",style:{marginLeft:"8px"},children:[e.jsx("span",{className:"live-dot"}),"Live"]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[M&&e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void G(),"aria-label":`Stop active run for ${u??a}`,children:[e.jsx(ye,{size:14})," Stop Run"]}),e.jsxs("button",{className:"btn btn--sm btn-task-create",onClick:()=>void J(),"aria-label":`Run now for ${u??a}`,children:[e.jsx(Te,{size:14})," Run Now"]})]})]}),h.map((c,z)=>I(c,z,!0)),_.map((c,z)=>I(c,h.length+z,!1))]})}function Jt(s,a){const i=Math.floor((a.getTime()-s.getTime())/1e3);return i<60?`${i}s`:i<3600?`${Math.floor(i/60)}m ${i%60}s`:`${Math.floor(i/3600)}h ${Math.floor(i%3600/60)}m`}const qt={triage:"Triage",todo:"Todo","in-progress":"In Progress","in-review":"In Review",done:"Done",archived:"Archived"};function Gt(s){const a=s.title?.trim()||s.description?.trim()||s.id;return a.length>80?`${a.slice(0,77)}...`:a}function Wt({agentId:s,projectId:a,addToast:i}){const[d,u]=t.useState([]),[r,N]=t.useState(!0);return t.useEffect(()=>{let m=!1;return N(!0),lt(s,a).then(v=>{m||u(v)}).catch(v=>{m||(u([]),i(`Failed to load assigned tasks: ${q(v)}`,"error"))}).finally(()=>{m||N(!1)}),()=>{m=!0}},[s,a,i]),r?e.jsxs("div",{className:"agent-tasks-empty",children:[e.jsx(O,{size:16,className:"animate-spin"}),e.jsx("p",{children:"Loading assigned tasks..."})]}):d.length===0?e.jsxs("div",{className:"agent-tasks-empty",children:[e.jsx($s,{size:18}),e.jsx("p",{children:"No tasks assigned to this agent"})]}):e.jsx("div",{className:"agent-tasks-list",children:d.map(m=>e.jsxs("a",{className:"agent-task-item",href:`/tasks/${m.id}`,children:[e.jsxs("div",{className:"agent-task-row",children:[e.jsx("span",{className:"agent-task-id",children:m.id}),e.jsx("span",{className:`agent-task-column column-${m.column}`,children:qt[m.column]})]}),e.jsx("div",{className:"agent-task-title",title:m.title||m.description||m.id,children:Gt(m)}),e.jsxs("div",{className:"agent-task-status",children:[m.status??"idle"," · Updated ",ke(m.updatedAt)]})]},m.id))})}const Ne=[{key:"maxRetries",label:"Max Retries",type:"number",placeholder:"3",hint:"Maximum number of automatic retries on task failure (0–10, default 3)",min:0,max:10},{key:"timeoutMs",label:"Task Timeout (ms)",type:"number",placeholder:"600000",hint:"Maximum time in ms before a task is considered timed out (minimum 60000ms, default 600000ms)",min:6e4,max:864e5},{key:"logLevel",label:"Log Level",type:"select",hint:"Verbosity of agent log output",options:[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warning"},{value:"error",label:"Error"}]}];function Yt(s){const a={};for(const i of Ne){const d=s[i.key]?.trim();if(d){if(i.type==="number"){const u=Number(d);if(Number.isNaN(u)||!Number.isFinite(u)){a[i.key]=`"${i.label}" must be a valid number`;continue}i.min!==void 0&&u<i.min&&(a[i.key]=`"${i.label}" must be at least ${i.min.toLocaleString()}`),i.max!==void 0&&u>i.max&&(a[i.key]=`"${i.label}" must be at most ${i.max.toLocaleString()}`)}if(i.type==="select"){const u=i.options?.map(r=>r.value)??[];u.length>0&&!u.includes(d)&&(a[i.key]=`"${i.label}" must be one of: ${u.join(", ")}`)}}}return a}function Kt({agent:s,projectId:a,addToast:i,onSaved:d}){const[u,r]=t.useState(s.soul??""),[N,m]=t.useState(!1),[v,x]=t.useState(!1),[j,A]=t.useState(!1);t.useEffect(()=>{r(s.soul??""),x(!1),A(!1)},[s.id,s.soul]);const f=u!==(s.soul??""),E=async()=>{if(u.length>1e4){i("Soul must be at most 10,000 characters","error");return}m(!0);try{await vt(s.id,u,a),i("Soul saved","success"),x(!0),setTimeout(()=>x(!1),3e3),await d()}catch(T){i(`Failed to save soul: ${q(T)}`,"error")}finally{m(!1)}};return e.jsx("div",{className:"config-tab",children:e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Soul"}),e.jsx("p",{className:"config-description",children:"Define this agent's personality and identity."}),e.jsx("div",{className:"config-fields",children:e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-soul",children:"Agent Soul"}),e.jsx("div",{className:"agent-content-toolbar",children:e.jsxs("div",{className:"agent-content-mode-toggle",children:[e.jsxs("button",{className:`btn btn-sm ${j?"":"btn-primary"}`,onClick:()=>A(!1),disabled:!j,"aria-label":"Edit mode",children:[e.jsx(De,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${j?"btn-primary":""}`,onClick:()=>A(!0),disabled:j,"aria-label":"Preview mode",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),j?u.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(ze,{remarkPlugins:[Be],children:u})}):e.jsx("div",{className:"agent-content-preview agent-content-placeholder",children:"No soul defined yet. Switch to Edit mode to define the agent's personality."}):e.jsx("textarea",{id:"agent-soul",className:"input",rows:12,placeholder:"Describe this agent's personality, tone, and behavioral traits...",value:u,onChange:T=>{r(T.target.value),x(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!j&&e.jsx("span",{className:"config-hint",children:"Defines the agent's character and identity. Max 10,000 characters."})]})}),!j&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!f||N,onClick:()=>void E(),children:N?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{size:16}),"Save Soul"]})}),!f&&v&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Soul saved"]})]})]})})}function Zt({agent:s,projectId:a,addToast:i,onSaved:d}){const[u,r]=t.useState(s.memory??""),[N,m]=t.useState(!1),[v,x]=t.useState(!1),[j,A]=t.useState(!1),[f,E]=t.useState([]),[T,C]=t.useState(!1),[o,b]=t.useState(""),[k,$]=t.useState(""),[L,M]=t.useState(!1),[y,U]=t.useState(!1),[J,G]=t.useState(!1),[w,B]=t.useState(!1),[h,_]=t.useState(""),H=s.state==="running",I=u!==(s.memory??""),c=t.useMemo(()=>f.find(p=>p.path===o),[f,o]),z=c?Bt[c.layer]:"Select a memory file to view or edit.",l=t.useCallback(async p=>{U(!0);try{const g=await ot(s.id,p,a);b(g.path),$(g.content),M(!1),B(!1)}catch(g){i(`Failed to load agent memory file: ${q(g)}`,"error")}finally{U(!1)}},[s.id,a,i]),R=t.useCallback(async(p="")=>{C(!0);try{const{files:g}=await dt(s.id,a);if(E(g),g.length===0){b(""),$(""),M(!1);return}const V=It(g,p);await l(V)}catch(g){i(`Failed to load memory files: ${q(g)}`,"error"),E([]),b(""),$(""),M(!1)}finally{C(!1)}},[s.id,a,i,l]);t.useEffect(()=>{r(s.memory??""),x(!1),A(!1),_(""),B(!1),R()},[s.id,s.memory,R]);const W=async()=>{if(u.length>5e4){i("Memory must be at most 50,000 characters","error");return}m(!0);try{await jt(s.id,u,a),i("Memory saved","success"),x(!0),setTimeout(()=>x(!1),3e3),await d()}catch(p){i(`Failed to save memory: ${q(p)}`,"error")}finally{m(!1)}},ne=async p=>{if(!(!p||p===o)){if(L){_("Save the current file before switching to another file.");return}_(""),await l(p)}},ie=async()=>{if(o){G(!0);try{await Nt(s.id,o,k,a),M(!1),B(!0),setTimeout(()=>B(!1),3e3),_(""),await R(o),i("Agent memory file saved","success")}catch(p){i(`Failed to save agent memory file: ${q(p)}`,"error")}finally{G(!1)}}};return e.jsx("div",{className:"config-tab",children:e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Agent Memory"}),e.jsx("p",{className:"config-description",children:"Store context that belongs to this agent only. Workspace memory, daily notes, dreams, and qmd search live in project settings under Project Memory."}),H&&e.jsx("p",{className:"config-hint",style:{marginBottom:12},children:"Read-only while this agent is running."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-memory",children:"Inline Memory"}),e.jsx("span",{className:"config-hint",style:{display:"block",marginBottom:8},children:"Short-form memory stored directly on the agent record and injected into prompts."}),e.jsx("div",{className:"agent-content-toolbar",children:e.jsxs("div",{className:"agent-content-mode-toggle",children:[!H&&e.jsxs("button",{className:`btn btn-sm ${j?"":"btn-primary"}`,onClick:()=>A(!1),disabled:!j,"aria-label":"Edit mode",children:[e.jsx(De,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${j?"btn-primary":""}`,onClick:()=>A(!0),disabled:j,"aria-label":"Preview mode",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),j?u.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(ze,{remarkPlugins:[Be],children:u})}):e.jsx("div",{className:"agent-content-preview agent-content-placeholder",children:"No agent memory defined yet. Switch to Edit mode to add memory content."}):e.jsx("textarea",{id:"agent-memory","aria-label":"Agent Memory",className:"input",rows:10,placeholder:"Durable preferences, operating habits, and context this agent should carry across tasks...",value:u,readOnly:H,onChange:p=>{r(p.target.value),x(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!j&&e.jsx("span",{className:"config-hint",children:"This is the inline memory field on the agent JSON record. Max 50,000 characters."})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-memory-file-select",children:"Memory Files"}),e.jsxs("span",{className:"config-hint",style:{display:"block",marginBottom:8},children:["Full OpenClaw memory files at ",e.jsxs("code",{children:[".fusion/agent-memory/",s.id,"/"]})," (MEMORY.md, DREAMS.md, and daily notes)."]}),e.jsx("select",{id:"agent-memory-file-select",className:"select",value:o,disabled:T||y||J||f.length===0,onChange:p=>{ne(p.target.value)},children:f.length===0?e.jsx("option",{value:"",children:"No memory files found"}):f.map(p=>e.jsxs("option",{value:p.path,children:[js[p.layer]," • ",p.label]},p.path))}),T&&e.jsxs("span",{className:"config-hint",style:{display:"inline-flex",gap:6,marginTop:8},children:[e.jsx(O,{size:14,className:"animate-spin"}),"Loading memory files…"]}),c&&e.jsxs("div",{className:"config-hint",style:{marginTop:8},children:[e.jsx("strong",{children:js[c.layer]})," · ",z,e.jsx("br",{}),c.size.toLocaleString()," bytes · Updated ",ke(c.updatedAt)]}),e.jsx("textarea",{className:"input",rows:14,placeholder:"Select a memory file to view and edit its content...",value:k,readOnly:H||!o||y,onChange:p=>{$(p.target.value),M(!0),B(!1),_("")},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical",marginTop:8}}),y&&e.jsxs("span",{className:"config-hint",style:{display:"inline-flex",gap:6,marginTop:8},children:[e.jsx(O,{size:14,className:"animate-spin"}),"Loading file content…"]}),h&&e.jsx("span",{className:"config-hint",style:{display:"block",marginTop:8},children:h})]})]}),e.jsxs("div",{className:"config-actions",children:[!j&&e.jsx("button",{className:"btn btn-task-create",disabled:!I||N||H,onClick:()=>void W(),children:N?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{size:16}),"Save Memory"]})}),e.jsx("button",{className:"btn",disabled:!L||J||!o||H,onClick:()=>void ie(),children:J?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Saving file…"]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{size:16}),"Save Memory File"]})}),!I&&v&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Memory saved"]}),!L&&w&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Memory file saved"]})]})]})})}function Qt({agent:s,projectId:a,addToast:i,onSaved:d}){const[u,r]=t.useState(s.instructionsText??""),[N,m]=t.useState(s.instructionsPath??""),[v,x]=t.useState(!1),[j,A]=t.useState(""),[f,E]=t.useState(!1),[T,C]=t.useState(!1),[o,b]=t.useState(!1),[k,$]=t.useState(!1),[L,M]=t.useState(!1),[y,U]=t.useState(!1);t.useEffect(()=>{const h=N.trim();if(!h){A(""),C(!1);return}E(!0),As("project",h).then(_=>{A(_.content),C(!1)}).catch(_=>{const H=q(_);H.includes("ENOENT")||H.includes("Not found")||H.includes("not found")?(A(""),C(!1)):(i(`Failed to load instructions file: ${H}`,"error"),A(""))}).finally(()=>{E(!1)})},[N,i]),t.useEffect(()=>{r(s.instructionsText??""),m(s.instructionsPath??""),M(!1),U(!1),x(!1)},[s.id,s.instructionsText,s.instructionsPath]);const J=(()=>{const h=u??"",_=s.instructionsText??"",H=N?.trim()??"",I=s.instructionsPath?.trim()??"";return h!==_||H!==I})(),G=async()=>{b(!0);try{await bt(s.id,{instructionsText:u||void 0,instructionsPath:N.trim()||void 0},a),i("Instructions saved","success"),M(!0),setTimeout(()=>M(!1),3e3),await d()}catch(h){i(`Failed to save instructions: ${q(h)}`,"error")}finally{b(!1)}},w=async()=>{const h=N.trim();if(!h){i("No instructions file path set","error");return}$(!0);try{await Es("project",h,j),i("Instructions file saved","success"),C(!1),U(!0),setTimeout(()=>U(!1),3e3)}catch(_){i(`Failed to save instructions file: ${q(_)}`,"error")}finally{$(!1)}},B=!!N.trim();return e.jsxs("div",{className:"config-tab",children:[e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Custom Instructions"}),e.jsx("p",{className:"config-description",children:"Append custom instructions to this agent's system prompt at execution time. Use this to customize behavior, coding style, or project conventions without modifying built-in prompts."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"instructions-text",children:"Inline Instructions"}),e.jsx("div",{className:"agent-content-toolbar",children:e.jsxs("div",{className:"agent-content-mode-toggle",children:[e.jsxs("button",{className:`btn btn-sm ${v?"":"btn-primary"}`,onClick:()=>x(!1),disabled:!v,"aria-label":"Edit mode","data-testid":"instructions-edit-toggle",children:[e.jsx(De,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${v?"btn-primary":""}`,onClick:()=>x(!0),disabled:v,"aria-label":"Preview mode","data-testid":"instructions-preview-toggle",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),v?u.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(ze,{remarkPlugins:[Be],children:u})}):e.jsx("div",{className:"agent-content-preview agent-content-placeholder",children:"No inline instructions defined yet. Switch to Edit mode to add instructions."}):e.jsx("textarea",{id:"instructions-text",className:"input",rows:10,placeholder:"Enter custom instructions to append to this agent's system prompt...",value:u,onChange:h=>{r(h.target.value),M(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!v&&e.jsx("span",{className:"config-hint",children:"Markdown formatting supported. Max 50,000 characters."})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"instructions-path",children:"Instructions File Path"}),e.jsx("input",{id:"instructions-path",type:"text",className:"input",placeholder:"e.g., .fusion/agents/my-agent-instructions.md",value:N,onChange:h=>{m(h.target.value),M(!1)}}),e.jsx("span",{className:"config-hint",children:"Path to a .md file (relative to project root). Contents are read and appended at execution time."})]})]}),!v&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!J||o,onClick:()=>void G(),children:o?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{size:16}),"Save Instructions"]})}),!J&&L&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Instructions saved"]})]})]}),B&&e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Instructions File Editor"}),e.jsx("p",{className:"config-description",children:"Edit the instructions file directly. Changes are saved separately from the path configuration."}),e.jsx("div",{className:"config-fields",children:e.jsxs("div",{className:"config-field",children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[e.jsx("label",{htmlFor:"instructions-file-content",children:"File Content"}),f&&e.jsxs("span",{className:"config-hint",style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(O,{size:12,className:"animate-spin"}),"Loading..."]}),T&&!f&&e.jsx("span",{className:"config-hint",style:{color:"var(--color-warning, #e3b541)"},children:"Unsaved changes"})]}),e.jsx("textarea",{id:"instructions-file-content",className:"input",rows:20,placeholder:"File content will appear here when loaded...",value:j,readOnly:f,onChange:h=>{A(h.target.value),C(!0),U(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),e.jsx("span",{className:"config-hint",children:"Edit the markdown file content directly. Save separately using the button below."})]})}),e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!T||k,onClick:()=>void w(),children:k?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{size:16}),"Save File"]})}),!T&&y&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"File saved"]})]})]})]})}function Ns(s){const a=s??{},i={};return a.heartbeatIntervalMs!==void 0&&a.heartbeatIntervalMs!==null&&(i.heartbeatIntervalMs=String(Number(a.heartbeatIntervalMs)/1e3)),a.heartbeatTimeoutMs!==void 0&&a.heartbeatTimeoutMs!==null&&(i.heartbeatTimeoutMs=String(Number(a.heartbeatTimeoutMs)/1e3)),a.maxConcurrentRuns!==void 0&&a.maxConcurrentRuns!==null&&(i.maxConcurrentRuns=String(a.maxConcurrentRuns)),(a.messageResponseMode==="immediate"||a.messageResponseMode==="on-heartbeat")&&(i.messageResponseMode=a.messageResponseMode),i}function Je(s){return s?.enabled!==!1}function ys(s){const a=(s??{}).budgetConfig,i={};return a&&(a.tokenBudget!==void 0&&a.tokenBudget!==null&&(i.tokenBudget=String(a.tokenBudget)),a.usageThreshold!==void 0&&a.usageThreshold!==null&&(i.usageThreshold=String(Number(a.usageThreshold)*100)),a.budgetPeriod!==void 0&&a.budgetPeriod!==null&&(i.budgetPeriod=String(a.budgetPeriod)),a.resetDay!==void 0&&a.resetDay!==null&&(i.resetDay=String(a.resetDay))),i}function Xt({agent:s,projectId:a,addToast:i,onSaved:d}){const[u,r]=t.useState(!1),[N,m]=t.useState(!1),[v,x]=t.useState(!1),[j,A]=t.useState(!1),[f,E]=t.useState(!1),[T,C]=t.useState(""),[o,b]=t.useState(!1),[k,$]=t.useState(null),[L,M]=t.useState(!1),y=s.heartbeatProcedurePath?.trim(),U=`.fusion/agents/${s.name.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||s.id.toLowerCase().replace(/[^a-z0-9]+/g,"-")||"agent"}-${s.id.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"agent"}/HEARTBEAT.md`,J=`.fusion/agents/${s.id}/HEARTBEAT.md`,G=s.id.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"agent",w=!!(y&&(y===U||y===J||new RegExp(`^\\.fusion/agents/[^/]+-${G}/HEARTBEAT\\.md$`).test(y))),B=!!y,h=t.useCallback(async c=>{x(!0),$(null);try{const z=await As("project",c,a);C(z.content),b(!1)}catch(z){const l=q(z);$(l),i(`Failed to load heartbeat procedure file: ${l}`,"error")}finally{x(!1)}},[i,a]);t.useEffect(()=>{m(!1),E(!1),C(""),b(!1),$(null),x(!1),A(!1),M(!1)},[s.id,y]);const _=async()=>{y&&(m(!0),await h(y))},H=async()=>{if(y){A(!0);try{await Es("project",y,T,a),b(!1),M(!0),i("Heartbeat procedure file saved","success"),setTimeout(()=>M(!1),3e3)}catch(c){i(`Failed to save heartbeat procedure file: ${q(c)}`,"error")}finally{A(!1)}}},I=async()=>{r(!0);try{const c=await Rt(s.id,a);i(c.procedureFileSeeded?`Heartbeat procedure file ready at ${c.heartbeatProcedurePath}`:`Heartbeat procedure path set to ${c.heartbeatProcedurePath}`,"success"),await d()}catch(c){i(`Failed to upgrade heartbeat procedure: ${q(c)}`,"error")}finally{r(!1)}};return e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Heartbeat Procedure"}),e.jsxs("p",{className:"config-description",children:["The per-tick procedure this agent runs every wake. Defaults to a per-agent markdown file (for example ",e.jsx("code",{children:".fusion/agents/ceo-agent2736/HEARTBEAT.md"}),") that you can edit. Legacy id-only default paths remain valid. Resets on every tick — no need to restart the agent after editing."]}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsxs("span",{className:"config-hint",children:["Current path: ",e.jsx("code",{children:y||"(none — using built-in default)"})]}),B&&e.jsx("div",{className:"heartbeat-procedure-actions",children:e.jsx("button",{className:"btn btn-sm",onClick:()=>void _(),disabled:v,children:v?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Loading file…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se,{size:16}),"View Heartbeat Markdown"]})})})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("button",{className:"btn",disabled:u||w,onClick:()=>void I(),"aria-label":"Upgrade agent to default heartbeat procedure file",children:u?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Upgrading…"]}):w?e.jsxs(e.Fragment,{children:[e.jsx(X,{size:16}),"Already on default"]}):"Upgrade to Default Heartbeat Procedure"}),e.jsxs("span",{className:"config-hint",children:["Sets ",e.jsx("code",{children:"heartbeatProcedurePath"})," to"," ",e.jsx("code",{children:U})," ","and seeds the file from the built-in template if it doesn't exist. Each agent gets its own per-agent file, so edits stay scoped to this agent. Operator edits to the file are preserved."]})]})]}),N&&B&&y&&e.jsxs("div",{className:"config-fields heartbeat-procedure-viewer",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"heartbeat-procedure-file-content",children:"Heartbeat Procedure File"}),e.jsxs("div",{className:"agent-content-toolbar",children:[e.jsxs("div",{className:"agent-content-mode-toggle",children:[e.jsxs("button",{className:`btn btn-sm ${f?"":"btn-primary"}`,onClick:()=>E(!1),disabled:!f,"aria-label":"Heartbeat file edit mode",children:[e.jsx(De,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${f?"btn-primary":""}`,onClick:()=>E(!0),disabled:f,"aria-label":"Heartbeat file preview mode",children:[e.jsx(Pe,{size:14}),"Preview"]})]}),v&&e.jsxs("span",{className:"config-hint heartbeat-procedure-status",children:[e.jsx(O,{size:12,className:"animate-spin"}),"Loading..."]}),o&&!v&&e.jsx("span",{className:"config-hint heartbeat-procedure-status heartbeat-procedure-status--warning",children:"Unsaved changes"})]}),f?T.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(ze,{remarkPlugins:[Be],children:T})}):e.jsx("div",{className:"agent-content-preview agent-content-placeholder",children:"No heartbeat procedure markdown content yet."}):e.jsx("textarea",{id:"heartbeat-procedure-file-content",className:"input",rows:16,value:T,readOnly:v,placeholder:"Heartbeat procedure markdown file content will appear here...",onChange:c=>{C(c.target.value),b(!0),M(!1)}}),k&&e.jsxs("span",{className:"config-error",children:["Failed to load file: ",k]}),e.jsxs("span",{className:"config-hint",children:["This editor writes directly to ",e.jsx("code",{children:y}),"."]})]}),!f&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!o||j||v,onClick:()=>void H(),children:j?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{size:16}),"Save Heartbeat File"]})}),!o&&L&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"File saved"]})]})]})]})}function ea({agent:s,projectId:a,addToast:i,onSaved:d,onHasChangesChange:u,onDelete:r}){const[N,m]=t.useState(s.name),[v,x]=t.useState(s.role),[j,A]=t.useState(s.title??""),[f,E]=t.useState(s.icon??""),[T,C]=t.useState(s.reportsTo??""),[o,b]=t.useState([]),[k,$]=t.useState(!1),[L,M]=t.useState(()=>{const n={};for(const F of Ne){const P=s.metadata[F.key];P!=null&&(n[F.key]=String(P))}return n}),[y,U]=t.useState(()=>Ns(s.runtimeConfig)),[J,G]=t.useState(()=>Je(s.runtimeConfig)),[w,B]=t.useState(()=>ys(s.runtimeConfig)),[h,_]=t.useState(s.bundleConfig?.mode??""),[H,I]=t.useState(s.bundleConfig?.entryFile??"AGENTS.md"),[c,z]=t.useState(s.bundleConfig?.externalPath??""),[l,R]=t.useState(s.bundleConfig?.files??[]),[W,ne]=t.useState(Array.isArray(s.metadata?.skills)?s.metadata.skills:[]),[ie,p]=t.useState([]),[g,V]=t.useState(!1),[K,Z]=t.useState([]),[oe,re]=t.useState(!1),le=(()=>{const n=s.runtimeConfig??{};return n.modelProvider&&n.modelId?`${n.modelProvider}/${n.modelId}`:typeof n.model=="string"&&n.model.includes("/")?n.model:""})(),te=typeof s.runtimeConfig?.runtimeHint=="string"?s.runtimeConfig.runtimeHint:"",[de,He]=t.useState(te?"runtime":"model"),[ge,Qe]=t.useState(le),[Re,Ie]=t.useState(te),Ce=T.trim(),Xe=t.useMemo(()=>o.filter(n=>n.id!==s.id),[o,s.id]),Ls=!!Ce&&!Xe.some(n=>n.id===Ce);t.useEffect(()=>{let n=!1;return $(!0),ut(void 0,a).then(F=>{n||b(F)}).catch(()=>{n||b([])}).finally(()=>{n||$(!1)}),()=>{n=!0}},[a]),t.useEffect(()=>{V(!0),mt().then(n=>p(n.models)).catch(()=>{}).finally(()=>V(!1))},[]),t.useEffect(()=>{re(!0),Fs(a).then(Z).catch(()=>Z([])).finally(()=>re(!1))},[a]);const[ue,Oe]=t.useState(null),[es,ss]=t.useState(!1);t.useEffect(()=>{qe(s.id,a).then(Oe).catch(()=>Oe(null))},[s.id,a]);const Ds=async()=>{ss(!0);try{await St(s.id,a),i("Budget usage reset successfully","success");const n=await qe(s.id,a);Oe(n)}catch(n){i(`Failed to reset budget: ${q(n)}`,"error")}finally{ss(!1)}},[ts,as]=t.useState(!1),[D,we]=t.useState({}),[Ps,fe]=t.useState(!1),ns=s.state==="idle"||s.state==="terminated",pe=t.useRef(null),is=t.useRef(null);t.useEffect(()=>()=>{pe.current&&clearTimeout(pe.current)},[]);const me=(()=>{if(N!==s.name||v!==s.role||j!==(s.title??"")||f!==(s.icon??"")||T!==(s.reportsTo??"")||h!==(s.bundleConfig?.mode??"")||H!==(s.bundleConfig?.entryFile??"AGENTS.md")||c!==(s.bundleConfig?.externalPath??"")||JSON.stringify(l)!==JSON.stringify(s.bundleConfig?.files??[]))return!0;for(const Q of Ne){const he=L[Q.key]?.trim()??"",ee=s.metadata[Q.key]!==void 0&&s.metadata[Q.key]!==null?String(s.metadata[Q.key]):"";if(he!==ee)return!0}const n=s.runtimeConfig??{};if(J!==Je(s.runtimeConfig))return!0;for(const Q of["heartbeatIntervalMs","heartbeatTimeoutMs","maxConcurrentRuns","messageResponseMode"]){const he=y[Q]?.trim()??"";let ee=n[Q]!==void 0&&n[Q]!==null?String(n[Q]):"";if((Q==="heartbeatIntervalMs"||Q==="heartbeatTimeoutMs")&&ee&&(ee=String(Number(ee)/1e3)),he!==ee)return!0}const F=n.budgetConfig;for(const Q of["tokenBudget","budgetPeriod","resetDay"]){const he=w[Q]?.trim()??"",ee=F?.[Q]!==void 0&&F?.[Q]!==null?String(F[Q]):"";if(he!==ee)return!0}const P=w.usageThreshold?.trim()??"",ae=F?.usageThreshold!==void 0&&F?.usageThreshold!==null?String(Number(F.usageThreshold)*100):"";if(P!==ae)return!0;const ve=Array.isArray(s.metadata?.skills)?s.metadata.skills:[];return JSON.stringify(W)!==JSON.stringify(ve)||de!==(te?"runtime":"model")||ge!==le||Re!==te})(),rs=t.useRef(null);t.useEffect(()=>{u&&rs.current!==me&&(rs.current=me,u(me))},[me,u]),t.useEffect(()=>()=>{u?.(!1)},[u]),t.useEffect(()=>{const n={id:s.id,updatedAt:s.updatedAt},F=is.current;(!F||F.id!==n.id||F.updatedAt!==n.updatedAt)&&(me||(is.current=n,U(Ns(s.runtimeConfig)),G(Je(s.runtimeConfig)),B(ys(s.runtimeConfig)),Qe(le),Ie(te),He(te?"runtime":"model")))},[s,me,le,te]);const ls=(n,F)=>{M(P=>({...P,[n]:F})),fe(!1),D[n]&&we(P=>{const ae={...P};return delete ae[n],ae})},Me=(n,F)=>{U(P=>({...P,[n]:F})),fe(!1),D[n]&&we(P=>{const ae={...P};return delete ae[n],ae})},zs=n=>{G(n),fe(!1)},Fe=(n,F)=>{B(P=>({...P,[n]:F})),fe(!1),D[n]&&we(P=>{const ae={...P};return delete ae[n],ae})},Bs=async()=>{const n=Yt(L);for(const[S,ce]of Object.entries({heartbeatIntervalMs:{label:"Heartbeat Interval",min:1},heartbeatTimeoutMs:{label:"Heartbeat Timeout",min:5},maxConcurrentRuns:{label:"Max Concurrent Runs",min:1}})){const be=y[S]?.trim();if(!be)continue;const Ve=Number(be);Number.isNaN(Ve)||!Number.isFinite(Ve)?n[S]=`"${ce.label}" must be a valid number`:Ve<ce.min&&(n[S]=`"${ce.label}" must be at least ${ce.min.toLocaleString()}`)}const F=y.messageResponseMode?.trim();F&&!["immediate","on-heartbeat"].includes(F)&&(n.messageResponseMode='"Message Response Mode" must be either immediate or on-heartbeat');const P=w.tokenBudget?.trim();if(P){const S=Number(P);Number.isNaN(S)||!Number.isFinite(S)?n.tokenBudget='"Token Budget" must be a valid number':S<=0&&(n.tokenBudget='"Token Budget" must be greater than 0')}const ae=w.usageThreshold?.trim();if(ae){const S=Number(ae);Number.isNaN(S)||!Number.isFinite(S)?n.usageThreshold='"Usage Threshold" must be a valid number':(S<1||S>100)&&(n.usageThreshold='"Usage Threshold" must be between 1 and 100')}const ve=w.budgetPeriod?.trim();ve&&!["daily","weekly","monthly","lifetime"].includes(ve)&&(n.budgetPeriod='"Budget Period" must be one of: daily, weekly, monthly, lifetime');const Q=w.resetDay?.trim(),he=ve||"lifetime";if(Q){const S=Number(Q);Number.isNaN(S)||!Number.isFinite(S)?n.resetDay='"Reset Day" must be a valid number':he==="weekly"?(S<0||S>6||!Number.isInteger(S))&&(n.resetDay='"Reset Day" must be between 0 (Sunday) and 6 (Saturday) for weekly period'):he==="monthly"&&(S<1||S>31||!Number.isInteger(S))&&(n.resetDay='"Reset Day" must be between 1 and 31 for monthly period')}if(Object.keys(n).length>0){we(n),i("Please fix validation errors before saving","error");return}const ee={...s.metadata};for(const S of Ne){const ce=L[S.key]?.trim();ce?S.type==="number"?ee[S.key]=Number(ce):ee[S.key]=ce:delete ee[S.key]}W.length>0?ee.skills=W:delete ee.skills;const Y={...s.runtimeConfig};Y.enabled=J;for(const S of["heartbeatIntervalMs","heartbeatTimeoutMs","maxConcurrentRuns"]){const ce=y[S]?.trim();if(!ce)delete Y[S];else{const be=Number(ce);Y[S]=S==="maxConcurrentRuns"?be:be*1e3}}const cs=y.messageResponseMode?.trim();if(cs?Y.messageResponseMode=cs:delete Y.messageResponseMode,de==="runtime")Re.trim()?Y.runtimeHint=Re.trim():delete Y.runtimeHint,delete Y.modelProvider,delete Y.modelId,delete Y.model;else if(delete Y.runtimeHint,ge.trim()){const S=ge.indexOf("/");S!==-1&&(Y.modelProvider=ge.slice(0,S),Y.modelId=ge.slice(S+1),Y.model=ge.trim())}else delete Y.modelProvider,delete Y.modelId,delete Y.model;const xe={},os=w.tokenBudget?.trim(),ds=w.usageThreshold?.trim(),us=w.budgetPeriod?.trim(),ms=w.resetDay?.trim();os&&(xe.tokenBudget=Number(os)),ds&&(xe.usageThreshold=Number(ds)/100),us&&(xe.budgetPeriod=us),ms&&(xe.resetDay=Number(ms)),Object.keys(xe).length>0?Y.budgetConfig=xe:delete Y.budgetConfig;let _e;h&&(_e={mode:h,entryFile:H||"AGENTS.md",files:l.length>0?l:["AGENTS.md"]},h==="external"&&c.trim()&&(_e.externalPath=c.trim())),as(!0);try{await kt(s.id,{name:N.trim()||void 0,role:v,title:j.trim()||void 0,icon:f.trim()||void 0,reportsTo:T.trim()||void 0,metadata:ee,runtimeConfig:Y,bundleConfig:_e},a),i("Settings saved","success"),fe(!0),pe.current&&clearTimeout(pe.current),pe.current=setTimeout(()=>fe(!1),3e3),await d()}catch(S){i(`Failed to save settings: ${q(S)}`,"error")}finally{as(!1)}};return e.jsxs("div",{className:"config-tab",children:[e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Agent Configuration"}),e.jsx("p",{className:"config-description",children:"Configure agent settings and behavior."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-name",children:"Name"}),e.jsx("input",{id:"agent-name",type:"text",className:"input",value:N,onChange:n=>m(n.target.value)})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-role",children:"Role"}),e.jsxs("select",{id:"agent-role",className:"select",value:v,onChange:n=>x(n.target.value),children:[e.jsx("option",{value:"triage",children:"Triage"}),e.jsx("option",{value:"executor",children:"Executor"}),e.jsx("option",{value:"reviewer",children:"Reviewer"}),e.jsx("option",{value:"merger",children:"Merger"}),e.jsx("option",{value:"scheduler",children:"Scheduler"}),e.jsx("option",{value:"custom",children:"Custom"})]})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-title",children:"Title"}),e.jsx("input",{id:"agent-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:j,onChange:n=>A(n.target.value)})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-icon",children:"Icon"}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:f,onChange:n=>E(n.target.value)})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-reports-to",children:"Reports To"}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:T,onChange:n=>C(n.target.value),disabled:k,children:[e.jsx("option",{value:"",children:"No manager"}),Ls&&e.jsxs("option",{value:Ce,children:["Unknown manager (",Ce,")"]}),Xe.map(n=>e.jsxs("option",{value:n.id,children:[n.name," (",n.id,")"]},n.id))]})]})]})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Skills"}),e.jsx("p",{className:"config-description",children:"Assign skills to this agent for specialized behavior."}),e.jsx("div",{className:"config-fields",children:e.jsx("div",{className:"config-field",children:e.jsx(Ct,{id:"agent-skills",label:"Skills",value:W,onChange:ne,projectId:a})})})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Model"}),e.jsx("p",{className:"config-description",children:"Choose either a built-in model or a plugin runtime for this agent. These options are mutually exclusive."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{children:"Runtime Source"}),e.jsxs("div",{className:"config-runtime-tabs",role:"tablist","aria-label":"Runtime source",children:[e.jsx("button",{type:"button",className:`config-runtime-tab${de==="model"?" active":""}`,role:"tab","aria-selected":de==="model",tabIndex:de==="model"?0:-1,onClick:()=>{He("model"),Ie("")},children:"Built-in Model"}),e.jsx("button",{type:"button",className:`config-runtime-tab${de==="runtime"?" active":""}`,role:"tab","aria-selected":de==="runtime",tabIndex:de==="runtime"?0:-1,onClick:()=>He("runtime"),children:"Plugin Runtime"})]})]}),de==="model"?e.jsx("div",{className:"config-field",children:e.jsx(ht,{models:ie,value:ge,onChange:Qe,placeholder:"Use global default",label:"Agent Model",disabled:g})}):e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),oe?e.jsx("span",{className:"config-hint",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:Re,onChange:n=>Ie(n.target.value),children:[e.jsx("option",{value:"",children:K.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),K.map(n=>e.jsx("option",{value:n.runtimeId,children:n.description?`${n.name} — ${n.description}`:n.name},`${n.pluginId}:${n.runtimeId}`))]})]})]})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Heartbeat Settings"}),e.jsx("p",{className:"config-description",children:"Configure how this agent's heartbeat is monitored. Leave a field empty to use system defaults."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsxs("label",{className:"checkbox-label",htmlFor:"hb-enabled",children:[e.jsx("input",{id:"hb-enabled",type:"checkbox",checked:J,onChange:n=>zs(n.target.checked)}),"Heartbeat Enabled"]}),e.jsx("span",{className:"config-hint",children:"When enabled, this agent receives scheduled heartbeat runs based on its interval."})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"hb-heartbeatIntervalMs",children:"Heartbeat Interval (s)"}),e.jsx("input",{id:"hb-heartbeatIntervalMs",type:"text",inputMode:"numeric",className:se("input",!!D.heartbeatIntervalMs&&"input--error"),placeholder:String(Ge/1e3),value:y.heartbeatIntervalMs??"",onChange:n=>Me("heartbeatIntervalMs",n.target.value)}),D.heartbeatIntervalMs?e.jsx("span",{className:"config-error",children:D.heartbeatIntervalMs}):e.jsxs("span",{className:"config-hint",children:["How often heartbeats are checked. Leave empty for system default (",Ge/1e3,"s / ",Ht,")."]})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"hb-heartbeatTimeoutMs",children:"Heartbeat Timeout (s)"}),e.jsx("input",{id:"hb-heartbeatTimeoutMs",type:"text",inputMode:"numeric",className:se("input",!!D.heartbeatTimeoutMs&&"input--error"),placeholder:"60",value:y.heartbeatTimeoutMs??"",onChange:n=>Me("heartbeatTimeoutMs",n.target.value)}),D.heartbeatTimeoutMs?e.jsx("span",{className:"config-error",children:D.heartbeatTimeoutMs}):e.jsx("span",{className:"config-hint",children:"Time without heartbeat before agent is considered unresponsive. Leave empty for system default (60s)"})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"hb-maxConcurrentRuns",children:"Max Concurrent Runs"}),e.jsx("input",{id:"hb-maxConcurrentRuns",type:"text",inputMode:"numeric",className:se("input",!!D.maxConcurrentRuns&&"input--error"),placeholder:"1",value:y.maxConcurrentRuns??"",onChange:n=>Me("maxConcurrentRuns",n.target.value)}),D.maxConcurrentRuns?e.jsx("span",{className:"config-error",children:D.maxConcurrentRuns}):e.jsx("span",{className:"config-hint",children:"Maximum simultaneous heartbeat runs for this agent. Leave empty for system default (1)."})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"hb-messageResponseMode",children:"Message Response Mode"}),e.jsxs("select",{id:"hb-messageResponseMode",className:se("select",!!D.messageResponseMode&&"input--error"),value:y.messageResponseMode??"",onChange:n=>Me("messageResponseMode",n.target.value),children:[e.jsx("option",{value:"",children:"System Default (On Heartbeat)"}),e.jsx("option",{value:"on-heartbeat",children:"On Heartbeat"}),e.jsx("option",{value:"immediate",children:"Immediate"})]}),D.messageResponseMode?e.jsx("span",{className:"config-error",children:D.messageResponseMode}):e.jsx("span",{className:"config-hint",children:"How this agent responds to incoming messages. 'Immediate' wakes the agent as soon as a message arrives. 'On Heartbeat' defers processing to the next scheduled heartbeat."})]})]})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Budget Settings"}),e.jsx("p",{className:"config-description",children:"Configure token budget limits for this agent. Leave all fields empty to disable budget tracking."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"budget-tokenBudget",children:"Token Budget"}),e.jsx("input",{id:"budget-tokenBudget",type:"text",inputMode:"numeric",className:se("input",!!D.tokenBudget&&"input--error"),placeholder:"No limit",value:w.tokenBudget??"",onChange:n=>Fe("tokenBudget",n.target.value)}),D.tokenBudget?e.jsx("span",{className:"config-error",children:D.tokenBudget}):e.jsx("span",{className:"config-hint",children:"Total token cap (input + output) for this agent. Leave empty for no limit."})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"budget-usageThreshold",children:"Usage Threshold (%)"}),e.jsx("input",{id:"budget-usageThreshold",type:"text",inputMode:"numeric",className:se("input",!!D.usageThreshold&&"input--error"),placeholder:"80",value:w.usageThreshold??"",onChange:n=>Fe("usageThreshold",n.target.value)}),D.usageThreshold?e.jsx("span",{className:"config-error",children:D.usageThreshold}):e.jsx("span",{className:"config-hint",children:"Warning threshold as a percentage. Agent warns when usage reaches this level. Default: 80%."})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"budget-budgetPeriod",children:"Budget Period"}),e.jsxs("select",{id:"budget-budgetPeriod",className:se("select",!!D.budgetPeriod&&"input--error"),value:w.budgetPeriod??"",onChange:n=>Fe("budgetPeriod",n.target.value),children:[e.jsx("option",{value:"",children:"No reset (lifetime)"}),e.jsx("option",{value:"daily",children:"Daily"}),e.jsx("option",{value:"weekly",children:"Weekly"}),e.jsx("option",{value:"monthly",children:"Monthly"})]}),D.budgetPeriod?e.jsx("span",{className:"config-error",children:D.budgetPeriod}):e.jsx("span",{className:"config-hint",children:"How often the budget counter resets. Leave empty for lifetime budget."})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"budget-resetDay",children:"Reset Day"}),e.jsx("input",{id:"budget-resetDay",type:"text",inputMode:"numeric",className:se("input",!!D.resetDay&&"input--error"),placeholder:"Auto",value:w.resetDay??"",onChange:n=>Fe("resetDay",n.target.value)}),D.resetDay?e.jsx("span",{className:"config-error",children:D.resetDay}):e.jsx("span",{className:"config-hint",children:w.budgetPeriod==="weekly"?"Day of week (0=Sunday to 6=Saturday) for reset.":w.budgetPeriod==="monthly"?"Day of month (1-31) for reset.":"Day for reset (weekly: 0-6, monthly: 1-31). Leave empty for automatic."})]}),ue?.budgetLimit!=null&&e.jsxs("div",{className:"config-field",children:[e.jsx("label",{children:"Current Usage"}),e.jsxs("div",{className:"budget-progress-container",children:[e.jsx("div",{className:"budget-progress-bar",children:e.jsx("div",{className:se("budget-progress-bar__fill",(ue.usagePercent??0)>=100?"budget-progress-bar__fill--red":(ue.usagePercent??0)>=80?"budget-progress-bar__fill--amber":"budget-progress-bar__fill--green"),style:{width:`${Math.min(ue.usagePercent??0,100)}%`}})}),e.jsxs("span",{className:"budget-progress-label",children:[(ue.currentUsage??0).toLocaleString()," / ",(ue.budgetLimit??0).toLocaleString()," tokens (",Math.round(ue.usagePercent??0),"% used)"]})]})]}),ue?.budgetLimit!=null&&e.jsx("div",{className:"config-field",children:e.jsx("button",{className:"btn btn-reset-budget",onClick:()=>void Ds(),disabled:es,children:es?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:14,className:"animate-spin"}),"Resetting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ye,{size:14}),"Reset Budget Usage"]})})})]})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Instruction Bundle"}),e.jsx("p",{className:"config-description",children:"Configure the agent's instruction bundle. Leave empty to use inline instructions only."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"bundle-mode",children:"Bundle Mode"}),e.jsxs("select",{id:"bundle-mode",className:"select",value:h,onChange:n=>_(n.target.value),children:[e.jsx("option",{value:"",children:"None (use inline instructions)"}),e.jsx("option",{value:"managed",children:"Managed (system-managed directory)"}),e.jsx("option",{value:"external",children:"External (user-specified path)"})]}),e.jsxs("span",{className:"config-hint",children:[h==="managed"&&"Files will be stored in a system-managed directory within .fusion/agents/",h==="external"&&"Specify an external directory path for the instruction files",!h&&"Select a mode to enable instruction bundling"]})]}),h&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"bundle-entry-file",children:"Entry File"}),e.jsx("input",{id:"bundle-entry-file",type:"text",className:"input",placeholder:"AGENTS.md",value:H,onChange:n=>I(n.target.value)}),e.jsx("span",{className:"config-hint",children:"Primary instructions file name (default: AGENTS.md)"})]}),h==="external"&&e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"bundle-external-path",children:"External Path"}),e.jsx("input",{id:"bundle-external-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/my-agent",value:c,onChange:n=>z(n.target.value)}),e.jsx("span",{className:"config-hint",children:"Absolute or relative path to the external directory"})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"bundle-files",children:"Files (comma-separated)"}),e.jsx("input",{id:"bundle-files",type:"text",className:"input",placeholder:"AGENTS.md, PROMPTS.md",value:l.join(", "),onChange:n=>R(n.target.value.split(",").map(F=>F.trim()).filter(Boolean))}),e.jsx("span",{className:"config-hint",children:"List of file names in the bundle directory"})]})]})]})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Advanced Settings"}),e.jsx("p",{className:"config-description",children:"Advanced configuration options for this agent. Leave a field empty to use system defaults."}),e.jsx("div",{className:"config-fields",children:Ne.map(n=>{const F=!!D[n.key];return e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:`adv-${n.key}`,children:n.label}),n.type==="select"?e.jsxs("select",{id:`adv-${n.key}`,className:se("select",F&&"input--error"),value:L[n.key]??"",onChange:P=>ls(n.key,P.target.value),children:[e.jsx("option",{value:"",children:"System Default"}),n.options?.map(P=>e.jsx("option",{value:P.value,children:P.label},P.value))]}):e.jsx("input",{id:`adv-${n.key}`,type:"text",inputMode:n.type==="number"?"numeric":void 0,className:se("input",F&&"input--error"),placeholder:n.placeholder,value:L[n.key]??"",onChange:P=>ls(n.key,P.target.value)}),F&&e.jsx("span",{className:"config-error",children:D[n.key]}),!F&&n.hint&&e.jsx("span",{className:"config-hint",children:n.hint})]},n.key)})}),e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!me||ts,onClick:()=>void Bs(),children:ts?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{size:16}),"Save Settings"]})}),!me&&Ps&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Settings saved"]})]})]}),e.jsx(Xt,{agent:s,projectId:a,addToast:i,onSaved:d}),e.jsxs("div",{className:"config-section config-section--danger",children:[e.jsx("h3",{children:"Danger Zone"}),e.jsx("p",{className:"config-description",children:"Permanently delete this agent from the project."}),e.jsx("div",{className:"config-fields",children:e.jsxs("div",{className:"config-field",children:[e.jsxs("button",{className:"btn btn--danger",disabled:!ns||!r,onClick:()=>void r?.(),children:[e.jsx(Le,{size:16}),"Delete Agent"]}),e.jsx("span",{className:"config-danger-note",children:ns?"Deletion is permanent and cannot be undone.":`Agent deletion is only available when state is idle or terminated (current state: ${s.state}).`})]})})]})]})}function sa({agentId:s,projectId:a,onChildClick:i}){const[d,u]=t.useState([]),[r,N]=t.useState(!0);return t.useEffect(()=>{N(!0),ct(s,a).then(u).finally(()=>N(!1))},[s,a]),r?e.jsxs("div",{className:"detail-section",children:[e.jsx("div",{className:"detail-section-header",children:e.jsx("h3",{children:"Employees"})}),e.jsxs("div",{className:"detail-section-body",style:{display:"flex",alignItems:"center",gap:8,padding:16},children:[e.jsx(O,{size:16,className:"spin"}),e.jsx("span",{className:"text-secondary",children:"Loading employees..."})]})]}):e.jsxs("div",{className:"detail-section",children:[e.jsxs("div",{className:"detail-section-header",children:[e.jsx("h3",{children:"Employees"}),e.jsxs("span",{className:"text-secondary",children:["(",d.length,")"]})]}),e.jsx("div",{className:"detail-section-body",children:d.length===0?e.jsxs("div",{className:"agent-empty",style:{padding:24},children:[e.jsx(Ke,{size:32,opacity:.3}),e.jsx("p",{children:"No employees"}),e.jsx("p",{className:"text-secondary",children:"This agent has no employees"})]}):e.jsx("div",{className:"agent-tree__children",children:d.map(m=>{const v=Ze[m.state];return e.jsxs("div",{className:"agent-tree__node agent-is-child",onClick:()=>i?.(m.id),role:"button",tabIndex:0,onKeyDown:x=>x.key==="Enter"&&i?.(m.id),style:{cursor:i?"pointer":"default"},children:[e.jsx("span",{className:"agent-tree__icon",children:m.icon??"🤖"}),e.jsx("span",{className:"agent-tree__name",children:m.name}),e.jsx("span",{className:"agent-tree__badge",style:{background:v?.bg??"var(--state-idle-bg)",color:v?.text??"var(--state-idle-text)",border:`1px solid ${v?.border??"var(--state-idle-border)"}`},children:m.state})]},m.id)})})})]})}export{ca as AgentDetailView};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-
|
|
2
|
-
import{c as Ye,s as yt,A as Te,r as Je,F as Xe,f as wt,C as De,Z as jt,B as et,g as Ze,a as gt,b as Ve,d as kt,e as Nt,h as Ct,i as It,u as nt,P as St,j as At,k as Et,l as Tt,m as Mt,n as Pt,o as Rt,p as _t,q as $t,t as at,G as Ft,S as Lt,L as We,T as Ue,R as Oe,X as st,v as zt,w as Dt,x as Ot,y as Ht,z as be,D as Ke,E as qt,H as Vt,I as Wt,J as Ut,K as Kt,M as Bt,N as ht,O as Gt,Q as $e,U as it,V as Qt,W as Jt,Y as Xt,_ as Fe,$ as Zt,a0 as rt,a1 as Yt,a2 as en,a3 as tn,a4 as nn}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-B1zViykq.js","assets/vendor-react-K0fH_qHe.js","assets/index-B4StE1qN.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-DYJk0WDc.css","assets/star-damu_EYz.js","assets/SkillMultiselect-DwGWYZi6.js","assets/SkillMultiselect-DDHJnrkn.css","assets/list-checks-B3oufblU.js","assets/AgentDetailView-B5tq9ius.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as Ye,s as yt,A as Te,r as Je,F as Xe,f as wt,C as De,Z as jt,B as et,g as Ze,a as gt,b as Ve,d as kt,e as Nt,h as Ct,i as It,u as nt,P as St,j as At,k as Et,l as Tt,m as Mt,n as Pt,o as Rt,p as _t,q as $t,t as at,G as Ft,S as Lt,L as We,T as Ue,R as Oe,X as st,v as zt,w as Dt,x as Ot,y as Ht,z as be,D as Ke,E as qt,H as Vt,I as Wt,J as Ut,K as Kt,M as Bt,N as ht,O as Gt,Q as $e,U as it,V as Qt,W as Jt,Y as Xt,_ as Fe,$ as Zt,a0 as rt,a1 as Yt,a2 as en,a3 as tn,a4 as nn}from"./index-B4StE1qN.js";import{r as a,j as e,a as an}from"./vendor-react-K0fH_qHe.js";import{S as sn}from"./SkillMultiselect-DwGWYZi6.js";import{U as pt}from"./upload-uH6CHlEw.js";import{F as rn}from"./folder-open-CKivQd8c.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
3
3
|
* @license lucide-react v1.7.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -519,4 +519,4 @@ reportsTo: null
|
|
|
519
519
|
skills:
|
|
520
520
|
- review
|
|
521
521
|
---
|
|
522
|
-
Agent instructions go here...`,value:u,onChange:i=>{m("paste"),b([]),p(i.target.value),F(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),se&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),se]})]}),c==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:w})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Xe,{size:14}),e.jsxs("span",{children:[T.length," agent",T.length!==1?"s":""," found"]})]}),T.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(T.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((i,x)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:A.includes(i.name),onChange:()=>Me(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},x))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),S.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Xe,{size:14}),e.jsxs("span",{children:[S.length," skill",S.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_(S.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((i,x)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:E.includes(i.name),onChange:()=>Ie(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${x}`))})]}),J&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),J]})]}),c==="result"&&h&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(De,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:h.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.created.length," created"]})}),h.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skipped.length," skipped (already exist)"]})}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.errors.length," error",h.errors.length!==1?"s":""]})})]}),h.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.created.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))}),h.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.skills.imported.length," skill",h.skills.imported.length!==1?"s":""," imported"]})}),h.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skills.skipped.length," skill",h.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.skills.errors.length," skill",h.skills.errors.length!==1?"s":""," error",h.skills.errors.length!==1?"s":""]})}),h.skills.imported.length===0&&h.skills.skipped.length===0&&h.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.skills.imported.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.skills.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[c==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:Q,children:"Back"}),e.jsx("button",{className:"btn",onClick:H,disabled:Q,children:c==="result"?"Close":"Cancel"}),c==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void re(),disabled:P||(r==="directory"?f.length===0:r==="browse"?!L:!u.trim()),children:P?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),c==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ye(),disabled:Q||O===0&&z===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),le]}):`Import ${Ne}`})]})]})}):null}const Gn=a.lazy(()=>nn(()=>import("./AgentDetailView-C2Iik3Qf.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(s=>({default:s.AgentDetailView}))),ze=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Qe=[.1,.25,.5,1,2,3,5,10];function He(s){switch(s){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function qe(s,l){switch(l){case"running":return`${s}--running`;case"active":return`${s}--active`;case"paused":return`${s}--paused`;case"error":return`${s}--error`;case"terminated":return`${s}--terminated`;case"idle":default:return`${s}--idle`}}function vt({node:s,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m}){const{agent:u,children:p,depth:f}=s,b=c(u.id),w=g(u.id),C=o(u),T=He(u.state),M=qe("agent-tree__node",u.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${M}${u.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(f,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${b===0?" agent-tree__toggle--leaf":""}`,onClick:()=>b>0&&y(u.id),title:b>0?w?"Collapse":"Expand":"No employees","aria-label":b>0?w?"Collapse":"Expand":"No employees",children:b>0?w?e.jsx(Jt,{size:16}):e.jsx(ht,{size:16}):e.jsx(et,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:S=>S.key==="Enter"&&l(u.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(u.role)}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:`agent-tree__badge ${T}`,children:u.state}),e.jsx("span",{className:"agent-tree__health",style:{color:C.color},title:C.label,children:C.icon}),b>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",b,")"]}),(()=>{const S=m(u);return S.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:S.join(", "),children:[S[0],S.length>1&&` +${S.length-1}`]})})()]})]}),w&&p.length>0&&e.jsx("div",{className:"agent-tree__children",children:p.map(S=>e.jsx(vt,{node:S,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m},S.agent.id))})]})}function xt({node:s,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c}){const{agent:o,children:r}=s,m=y(o),u=He(o.state),p=qe("org-chart-node-card",o.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:p,onClick:()=>l(o.id),role:"button",tabIndex:0,onKeyDown:f=>f.key==="Enter"&&l(o.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:g(o.role)}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${u}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:m.color},title:m.label,children:[m.icon,!m.stateDerived&&e.jsx("span",{className:"text-secondary",children:m.label})]}),(()=>{const f=c(o);if(f.length===0)return null;const b=f.slice(0,2),w=f.length-2;return e.jsxs(e.Fragment,{children:[b.map(C=>e.jsx("span",{className:"org-chart-node__skill",children:C},C)),w>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",w]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:r.map(f=>e.jsx(xt,{node:f,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c},f.agent.id))})]})}function ta({addToast:s,projectId:l,onOpenTaskLogs:y,agentOnboardingEnabled:g=!1}){const[c,o]=a.useState(!1),[r,m]=a.useState("all"),{agents:u,stats:p,isLoading:f,loadAgents:b}=zt(l,{filterState:r,showSystemAgents:c}),[w,C]=a.useState(!1),[T,M]=a.useState(!1),[S,j]=a.useState(null),[A,v]=a.useState(!1),[E,_]=a.useState(null),[P,D]=a.useState(()=>{if(typeof window>"u")return"list";const n=Ze("fn-agent-view",l);return n==="list"||n==="board"||n==="tree"||n==="org"?n:"list"}),[Q,q]=a.useState([]),[se,F]=a.useState(!1),[h,I]=a.useState(!1),J=a.useRef(null),{confirm:V}=Dt(),X=a.useRef(null),ie=a.useId();a.useEffect(()=>{const n=Ze("fn-agent-view",l);if(n==="list"||n==="board"||n==="tree"||n==="org"){D(n);return}D("list")},[l]),a.useEffect(()=>{gt("fn-agent-view",P,l)},[P,l]);const[ve,W]=a.useState(null),ne=a.useRef(null),[ke,L]=a.useState(null),[oe,U]=a.useState(null),[ce,ae]=a.useState({}),[K,ue]=a.useState(1),[me,ge]=a.useState(!1),[H,xe]=a.useState(new Set),[Z,he]=a.useState(new Map),re=a.useRef(!0);a.useEffect(()=>(re.current=!0,()=>{re.current=!1}),[]),a.useEffect(()=>{Ot(l).then(n=>{re.current&&ue(n.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const ye=a.useCallback(async n=>{const t=Number.isFinite(n)&&n>0?n:1;ue(t),ge(!0);try{await Ht({heartbeatMultiplier:t},l),s(`Heartbeat speed set to ×${t.toFixed(1)}`,"success")}catch(d){s(`Failed to save heartbeat multiplier: ${be(d)}`,"error")}finally{re.current&&ge(!1)}},[l,s]),O=a.useMemo(()=>Z.size===0?u:u.map(n=>{const t=Z.get(n.id);return t?{...n,state:t}:n}),[u,Z]),z=jn(O,l),de=a.useMemo(()=>O.filter(n=>c||!Ke(n)),[O,c]),we=a.useMemo(()=>O.filter(n=>n.state!=="active"&&n.state!=="running"?!1:c||!Ke(n)),[O,c]),Ne=a.useMemo(()=>{if(c)return Q;const n=t=>Ke(t.agent)?null:{...t,children:t.children.map(n).filter(d=>d!==null)};return Q.map(n).filter(t=>t!==null)},[Q,c]);a.useEffect(()=>{if(P!=="org")return;let n=!1;return F(!0),qt(l,{includeEphemeral:c}).then(t=>{n||q(t)}).catch(t=>{n||(s(`Failed to load org chart: ${be(t)}`,"error"),q([]))}).finally(()=>{n||F(!1)}),()=>{n=!0}},[P,l,c,s]),a.useEffect(()=>{const n=setInterval(()=>{b()},3e4);return()=>{clearInterval(n)}},[b]),a.useEffect(()=>{if(!h)return;const n=d=>{const k=d.target;k&&(J.current?.contains(k)||X.current?.contains(k)||I(!1))},t=d=>{d.key==="Escape"&&(I(!1),X.current?.focus())};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),document.removeEventListener("keydown",t)}},[h]);const le=async(n,t)=>{if(!H.has(n)){xe(d=>new Set(d).add(n)),he(d=>{const k=new Map(d);return k.set(n,t),k});try{await Yt(n,t,l),s(`Agent state updated to ${t}`,"success"),await b(),he(d=>{const k=new Map(d);return k.delete(n),k})}catch(d){he(k=>{const $=new Map(k);return $.delete(n),$}),s(`Failed to update state: ${be(d)}`,"error")}finally{xe(d=>{const k=new Set(d);return k.delete(n),k})}}},Me=async(n,t)=>{if(await V({title:"Delete Agent",message:`Delete agent "${t}"? This cannot be undone.`,danger:!0}))try{await tn(n,l),s(`Agent "${t}" deleted`,"success"),b()}catch(k){s(`Failed to delete agent: ${be(k)}`,"error")}},Ie=async(n,t)=>{const d=u.find(k=>k.id===n);if(d){if(d.role===t){W(null);return}try{await Fe(n,{role:t},l),s(`Agent role updated to ${ze.find(k=>k.value===t)?.label??t}`,"success"),W(null),b()}catch(k){s(`Failed to update role: ${be(k)}`,"error")}}},i=(n,t)=>{n.key==="Escape"&&W(null)},x=async(n,t)=>{oe===n.id&&(U(null),ae(d=>{const k={...d};return delete k[n.id],k})),L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:t}},l),s(`Heartbeat interval updated to ${rt(t)} for ${n.name}`,"success"),b()}catch(d){s(`Failed to update heartbeat interval: ${be(d)}`,"error")}finally{L(null)}},R=async n=>{const t=ce[n.id]??"";if(t.trim()===""){s("Please enter a heartbeat interval in minutes","error");return}const d=Number(t);if(isNaN(d)){s("Heartbeat interval must be a valid number","error");return}if(d<=0){s("Heartbeat interval must be greater than 0","error");return}if(d>=1&&d<5){L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:Zt}},l),s(`Heartbeat interval set to 5 minutes (minimum). ${d} minute${d!==1?"s":""} was below the 5-minute minimum.`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}return}const k=Math.round(d*6e4);L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:k}},l),s(`Heartbeat interval updated to ${rt(k)} for ${n.name}`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}},Y=n=>{const t=Je(n.runtimeConfig?.heartbeatIntervalMs),d=Math.round(t/6e4);U(n.id),ae(k=>({...k,[n.id]:String(d)}))},B=a.useCallback(()=>{_(null)},[]),G=a.useCallback(n=>{_(n)},[]),Pe=async(n,t)=>{try{await en(n,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${t}`,"success"),b()}catch(d){s(`Failed to start heartbeat run: ${be(d)}`,"error")}},pe=n=>ze.find(t=>t.value===n)?.label??n,Se=n=>ze.find(t=>t.value===n)?.icon??"◆",Ae=n=>Array.isArray(n.metadata?.skills)?n.metadata.skills:[],fe=n=>Xt(n),Re=f&&u.length===0,je=a.useCallback(()=>{if(g){M(!0);return}C(!0)},[g]);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(et,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${P==="list"?" active":""}`,onClick:()=>D("list"),title:"List view","aria-label":"List view","aria-pressed":P==="list",children:e.jsx(Vt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="board"?" active":""}`,onClick:()=>D("board"),title:"Board view","aria-label":"Board view","aria-pressed":P==="board",children:e.jsx(Te,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="tree"?" active":""}`,onClick:()=>D("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":P==="tree",children:e.jsx(Wt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="org"?" active":""}`,onClick:()=>D("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":P==="org",children:e.jsx(dn,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:X,className:`btn-icon agent-controls-trigger${h?" agent-controls-trigger--active":""}`,onClick:()=>I(n=>!n),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":h,"aria-controls":ie,children:e.jsx(mn,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void b(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Oe,{size:16,className:f?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{je(),I(!1)},children:[e.jsx(Ut,{size:16}),"New Agent"]})]})]})]}),h&&e.jsxs("div",{ref:J,id:ie,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Kt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:r,onChange:n=>m(n.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"}),e.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:n=>o(n.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{v(!0),I(!1)},children:[e.jsx(pt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:K,onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",K.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Qe.reduce((n,t)=>Math.abs(t-K)<Math.abs(n-K)?t:n,Qe[0])),onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me,"aria-label":"Heartbeat speed preset",children:Qe.map(n=>e.jsxs("option",{value:String(n),children:["×",n]},n))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(xn,{agents:de})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(vn,{stats:p}),e.jsx(fn,{agents:we,projectId:l,onAgentSelect:_,onOpenTaskLogs:y}),e.jsx(Wn,{isOpen:w,onClose:()=>{C(!1),j(null)},onCreated:()=>{C(!1),j(null),b()},projectId:l,prefillDraft:S}),e.jsx(Un,{isOpen:T,onClose:()=>M(!1),onUseDraft:n=>{j(n),M(!1),C(!0)},projectId:l,existingAgents:u}),e.jsx(Bn,{isOpen:A,onClose:()=>v(!1),onImported:()=>void b(),projectId:l}),Re?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):P==="tree"?e.jsx("div",{className:"agent-tree__view",children:de.length===0?e.jsx(Le,{onCtaClick:je}):z.rootNodes.map(n=>e.jsx(vt,{node:n,onSelect:_,onToggle:z.toggleExpand,isExpanded:z.isExpanded,getChildCount:t=>z.getChildren(t).length,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:se?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):Ne.length===0?e.jsx(Le,{onCtaClick:je}):Ne.map(n=>e.jsx(xt,{node:n,onSelect:_,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="board"?e.jsx("div",{className:"agent-board",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-board-card",n.state);return e.jsx("div",{className:`agent-board-card ${k}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:$=>$.key==="Enter"&&_(n.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:Se(n.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:pe(n.role)}),e.jsx("span",{className:`agent-board-badge badge ${d}`,children:n.state})]}),e.jsx("div",{className:"agent-board-name",children:n.name}),e.jsx("div",{className:"agent-board-id",children:n.id}),e.jsxs("div",{className:"agent-board-health",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]})]})},n.id)})}):e.jsx("div",{className:"agent-list",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-card",n.state),$=Je(n.runtimeConfig?.heartbeatIntervalMs),ee=Bt($),_e=ke===n.id;return e.jsxs("div",{className:`agent-card ${k}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:N=>N.key==="Enter"&&_(n.id),children:[ve===n.id?e.jsx("select",{ref:ne,className:"select agent-role-select",value:n.role,onChange:N=>void Ie(n.id,N.target.value),onKeyDown:N=>i(N,n.id),onBlur:()=>W(null),autoFocus:!0,children:ze.map(N=>e.jsxs("option",{value:N.value,children:[N.icon," ",N.label]},N.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:N=>{N.stopPropagation(),W(n.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.stopPropagation(),W(n.id))},children:Se(n.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:n.name}),e.jsx("span",{className:"agent-id text-secondary",children:n.id})]}),e.jsx(ht,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${d}`,children:n.state}),e.jsxs("span",{className:"badge",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]}),e.jsx("span",{className:"badge text-secondary",children:pe(n.role)}),(()=>{const N=Ae(n);if(N.length===0)return null;const te=N.slice(0,2),Ce=N.length-2;return e.jsxs(e.Fragment,{children:[te.map(tt=>e.jsx("span",{className:"badge badge-skill",children:tt},tt)),Ce>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",Ce]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[n.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:n.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),oe===n.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:ce[n.id]??"",onChange:N=>ae(te=>({...te,[n.id]:N.target.value})),onKeyDown:N=>{N.key==="Enter"?R(n):N.key==="Escape"&&(U(null),ae(te=>{const Ce={...te};return delete Ce[n.id],Ce}))},disabled:_e,"aria-label":`Custom heartbeat interval in minutes for ${n.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void R(n),disabled:_e,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{U(null),ae(N=>{const te={...N};return delete te[n.id],te})},disabled:_e,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:$,onChange:N=>{const te=N.target.value;te==="__custom__"?Y(n):x(n,Number(te))},disabled:_e,"aria-label":`Set heartbeat interval for ${n.name}`,children:[ee.map(N=>e.jsx("option",{value:N.value,children:N.label},N.value)),Gt.some(N=>N.value===$)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),_e&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),n.lastHeartbeatAt&&(()=>{const N=new Date(n.lastHeartbeatAt),te=new Date(N.getTime()+$),Ce=n.state==="active"||n.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:N.toLocaleString(),children:["Last: ",N.toLocaleTimeString()]}),Ce&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:te.toLocaleString(),children:["Next: ",te.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[n.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Activate",children:[e.jsx($e,{size:14})," Start"]}),n.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void Pe(n.id,n.name),disabled:H.has(n.id),title:"Run Now","aria-label":`Run now for ${n.name}`,children:[e.jsx(Te,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Resume",children:[e.jsx($e,{size:14})," Resume"]}),n.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${n.name}`,children:[e.jsx(Te,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Retry",children:[e.jsx($e,{size:14})," Retry"]}),n.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Start",children:[e.jsx($e,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>_(n.id),title:`View details for ${n.name}`,"aria-label":`View details for ${n.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void Me(n.id,n.name),title:"Delete",children:[e.jsx(Qt,{size:14})," Delete"]})]})]},n.id)})})]}),E&&e.jsx(a.Suspense,{fallback:null,children:e.jsx(Gn,{agentId:E,projectId:l,onClose:B,addToast:s,onChildClick:G})})]})}export{ta as AgentsView};
|
|
522
|
+
Agent instructions go here...`,value:u,onChange:i=>{m("paste"),b([]),p(i.target.value),F(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),se&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),se]})]}),c==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:w})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Xe,{size:14}),e.jsxs("span",{children:[T.length," agent",T.length!==1?"s":""," found"]})]}),T.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(T.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((i,x)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:A.includes(i.name),onChange:()=>Me(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},x))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),S.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Xe,{size:14}),e.jsxs("span",{children:[S.length," skill",S.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_(S.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((i,x)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:E.includes(i.name),onChange:()=>Ie(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${x}`))})]}),J&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),J]})]}),c==="result"&&h&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(De,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:h.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.created.length," created"]})}),h.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skipped.length," skipped (already exist)"]})}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.errors.length," error",h.errors.length!==1?"s":""]})})]}),h.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.created.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))}),h.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.skills.imported.length," skill",h.skills.imported.length!==1?"s":""," imported"]})}),h.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skills.skipped.length," skill",h.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.skills.errors.length," skill",h.skills.errors.length!==1?"s":""," error",h.skills.errors.length!==1?"s":""]})}),h.skills.imported.length===0&&h.skills.skipped.length===0&&h.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.skills.imported.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.skills.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[c==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:Q,children:"Back"}),e.jsx("button",{className:"btn",onClick:H,disabled:Q,children:c==="result"?"Close":"Cancel"}),c==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void re(),disabled:P||(r==="directory"?f.length===0:r==="browse"?!L:!u.trim()),children:P?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),c==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ye(),disabled:Q||O===0&&z===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),le]}):`Import ${Ne}`})]})]})}):null}const Gn=a.lazy(()=>nn(()=>import("./AgentDetailView-B1zViykq.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(s=>({default:s.AgentDetailView}))),ze=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Qe=[.1,.25,.5,1,2,3,5,10];function He(s){switch(s){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function qe(s,l){switch(l){case"running":return`${s}--running`;case"active":return`${s}--active`;case"paused":return`${s}--paused`;case"error":return`${s}--error`;case"terminated":return`${s}--terminated`;case"idle":default:return`${s}--idle`}}function vt({node:s,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m}){const{agent:u,children:p,depth:f}=s,b=c(u.id),w=g(u.id),C=o(u),T=He(u.state),M=qe("agent-tree__node",u.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${M}${u.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(f,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${b===0?" agent-tree__toggle--leaf":""}`,onClick:()=>b>0&&y(u.id),title:b>0?w?"Collapse":"Expand":"No employees","aria-label":b>0?w?"Collapse":"Expand":"No employees",children:b>0?w?e.jsx(Jt,{size:16}):e.jsx(ht,{size:16}):e.jsx(et,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:S=>S.key==="Enter"&&l(u.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(u.role)}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:`agent-tree__badge ${T}`,children:u.state}),e.jsx("span",{className:"agent-tree__health",style:{color:C.color},title:C.label,children:C.icon}),b>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",b,")"]}),(()=>{const S=m(u);return S.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:S.join(", "),children:[S[0],S.length>1&&` +${S.length-1}`]})})()]})]}),w&&p.length>0&&e.jsx("div",{className:"agent-tree__children",children:p.map(S=>e.jsx(vt,{node:S,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m},S.agent.id))})]})}function xt({node:s,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c}){const{agent:o,children:r}=s,m=y(o),u=He(o.state),p=qe("org-chart-node-card",o.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:p,onClick:()=>l(o.id),role:"button",tabIndex:0,onKeyDown:f=>f.key==="Enter"&&l(o.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:g(o.role)}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${u}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:m.color},title:m.label,children:[m.icon,!m.stateDerived&&e.jsx("span",{className:"text-secondary",children:m.label})]}),(()=>{const f=c(o);if(f.length===0)return null;const b=f.slice(0,2),w=f.length-2;return e.jsxs(e.Fragment,{children:[b.map(C=>e.jsx("span",{className:"org-chart-node__skill",children:C},C)),w>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",w]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:r.map(f=>e.jsx(xt,{node:f,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c},f.agent.id))})]})}function ta({addToast:s,projectId:l,onOpenTaskLogs:y,agentOnboardingEnabled:g=!1}){const[c,o]=a.useState(!1),[r,m]=a.useState("all"),{agents:u,stats:p,isLoading:f,loadAgents:b}=zt(l,{filterState:r,showSystemAgents:c}),[w,C]=a.useState(!1),[T,M]=a.useState(!1),[S,j]=a.useState(null),[A,v]=a.useState(!1),[E,_]=a.useState(null),[P,D]=a.useState(()=>{if(typeof window>"u")return"list";const n=Ze("fn-agent-view",l);return n==="list"||n==="board"||n==="tree"||n==="org"?n:"list"}),[Q,q]=a.useState([]),[se,F]=a.useState(!1),[h,I]=a.useState(!1),J=a.useRef(null),{confirm:V}=Dt(),X=a.useRef(null),ie=a.useId();a.useEffect(()=>{const n=Ze("fn-agent-view",l);if(n==="list"||n==="board"||n==="tree"||n==="org"){D(n);return}D("list")},[l]),a.useEffect(()=>{gt("fn-agent-view",P,l)},[P,l]);const[ve,W]=a.useState(null),ne=a.useRef(null),[ke,L]=a.useState(null),[oe,U]=a.useState(null),[ce,ae]=a.useState({}),[K,ue]=a.useState(1),[me,ge]=a.useState(!1),[H,xe]=a.useState(new Set),[Z,he]=a.useState(new Map),re=a.useRef(!0);a.useEffect(()=>(re.current=!0,()=>{re.current=!1}),[]),a.useEffect(()=>{Ot(l).then(n=>{re.current&&ue(n.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const ye=a.useCallback(async n=>{const t=Number.isFinite(n)&&n>0?n:1;ue(t),ge(!0);try{await Ht({heartbeatMultiplier:t},l),s(`Heartbeat speed set to ×${t.toFixed(1)}`,"success")}catch(d){s(`Failed to save heartbeat multiplier: ${be(d)}`,"error")}finally{re.current&&ge(!1)}},[l,s]),O=a.useMemo(()=>Z.size===0?u:u.map(n=>{const t=Z.get(n.id);return t?{...n,state:t}:n}),[u,Z]),z=jn(O,l),de=a.useMemo(()=>O.filter(n=>c||!Ke(n)),[O,c]),we=a.useMemo(()=>O.filter(n=>n.state!=="active"&&n.state!=="running"?!1:c||!Ke(n)),[O,c]),Ne=a.useMemo(()=>{if(c)return Q;const n=t=>Ke(t.agent)?null:{...t,children:t.children.map(n).filter(d=>d!==null)};return Q.map(n).filter(t=>t!==null)},[Q,c]);a.useEffect(()=>{if(P!=="org")return;let n=!1;return F(!0),qt(l,{includeEphemeral:c}).then(t=>{n||q(t)}).catch(t=>{n||(s(`Failed to load org chart: ${be(t)}`,"error"),q([]))}).finally(()=>{n||F(!1)}),()=>{n=!0}},[P,l,c,s]),a.useEffect(()=>{const n=setInterval(()=>{b()},3e4);return()=>{clearInterval(n)}},[b]),a.useEffect(()=>{if(!h)return;const n=d=>{const k=d.target;k&&(J.current?.contains(k)||X.current?.contains(k)||I(!1))},t=d=>{d.key==="Escape"&&(I(!1),X.current?.focus())};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),document.removeEventListener("keydown",t)}},[h]);const le=async(n,t)=>{if(!H.has(n)){xe(d=>new Set(d).add(n)),he(d=>{const k=new Map(d);return k.set(n,t),k});try{await Yt(n,t,l),s(`Agent state updated to ${t}`,"success"),await b(),he(d=>{const k=new Map(d);return k.delete(n),k})}catch(d){he(k=>{const $=new Map(k);return $.delete(n),$}),s(`Failed to update state: ${be(d)}`,"error")}finally{xe(d=>{const k=new Set(d);return k.delete(n),k})}}},Me=async(n,t)=>{if(await V({title:"Delete Agent",message:`Delete agent "${t}"? This cannot be undone.`,danger:!0}))try{await tn(n,l),s(`Agent "${t}" deleted`,"success"),b()}catch(k){s(`Failed to delete agent: ${be(k)}`,"error")}},Ie=async(n,t)=>{const d=u.find(k=>k.id===n);if(d){if(d.role===t){W(null);return}try{await Fe(n,{role:t},l),s(`Agent role updated to ${ze.find(k=>k.value===t)?.label??t}`,"success"),W(null),b()}catch(k){s(`Failed to update role: ${be(k)}`,"error")}}},i=(n,t)=>{n.key==="Escape"&&W(null)},x=async(n,t)=>{oe===n.id&&(U(null),ae(d=>{const k={...d};return delete k[n.id],k})),L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:t}},l),s(`Heartbeat interval updated to ${rt(t)} for ${n.name}`,"success"),b()}catch(d){s(`Failed to update heartbeat interval: ${be(d)}`,"error")}finally{L(null)}},R=async n=>{const t=ce[n.id]??"";if(t.trim()===""){s("Please enter a heartbeat interval in minutes","error");return}const d=Number(t);if(isNaN(d)){s("Heartbeat interval must be a valid number","error");return}if(d<=0){s("Heartbeat interval must be greater than 0","error");return}if(d>=1&&d<5){L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:Zt}},l),s(`Heartbeat interval set to 5 minutes (minimum). ${d} minute${d!==1?"s":""} was below the 5-minute minimum.`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}return}const k=Math.round(d*6e4);L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:k}},l),s(`Heartbeat interval updated to ${rt(k)} for ${n.name}`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}},Y=n=>{const t=Je(n.runtimeConfig?.heartbeatIntervalMs),d=Math.round(t/6e4);U(n.id),ae(k=>({...k,[n.id]:String(d)}))},B=a.useCallback(()=>{_(null)},[]),G=a.useCallback(n=>{_(n)},[]),Pe=async(n,t)=>{try{await en(n,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${t}`,"success"),b()}catch(d){s(`Failed to start heartbeat run: ${be(d)}`,"error")}},pe=n=>ze.find(t=>t.value===n)?.label??n,Se=n=>ze.find(t=>t.value===n)?.icon??"◆",Ae=n=>Array.isArray(n.metadata?.skills)?n.metadata.skills:[],fe=n=>Xt(n),Re=f&&u.length===0,je=a.useCallback(()=>{if(g){M(!0);return}C(!0)},[g]);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(et,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${P==="list"?" active":""}`,onClick:()=>D("list"),title:"List view","aria-label":"List view","aria-pressed":P==="list",children:e.jsx(Vt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="board"?" active":""}`,onClick:()=>D("board"),title:"Board view","aria-label":"Board view","aria-pressed":P==="board",children:e.jsx(Te,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="tree"?" active":""}`,onClick:()=>D("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":P==="tree",children:e.jsx(Wt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="org"?" active":""}`,onClick:()=>D("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":P==="org",children:e.jsx(dn,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:X,className:`btn-icon agent-controls-trigger${h?" agent-controls-trigger--active":""}`,onClick:()=>I(n=>!n),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":h,"aria-controls":ie,children:e.jsx(mn,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void b(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Oe,{size:16,className:f?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{je(),I(!1)},children:[e.jsx(Ut,{size:16}),"New Agent"]})]})]})]}),h&&e.jsxs("div",{ref:J,id:ie,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Kt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:r,onChange:n=>m(n.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"}),e.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:n=>o(n.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{v(!0),I(!1)},children:[e.jsx(pt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:K,onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",K.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Qe.reduce((n,t)=>Math.abs(t-K)<Math.abs(n-K)?t:n,Qe[0])),onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me,"aria-label":"Heartbeat speed preset",children:Qe.map(n=>e.jsxs("option",{value:String(n),children:["×",n]},n))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(xn,{agents:de})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(vn,{stats:p}),e.jsx(fn,{agents:we,projectId:l,onAgentSelect:_,onOpenTaskLogs:y}),e.jsx(Wn,{isOpen:w,onClose:()=>{C(!1),j(null)},onCreated:()=>{C(!1),j(null),b()},projectId:l,prefillDraft:S}),e.jsx(Un,{isOpen:T,onClose:()=>M(!1),onUseDraft:n=>{j(n),M(!1),C(!0)},projectId:l,existingAgents:u}),e.jsx(Bn,{isOpen:A,onClose:()=>v(!1),onImported:()=>void b(),projectId:l}),Re?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):P==="tree"?e.jsx("div",{className:"agent-tree__view",children:de.length===0?e.jsx(Le,{onCtaClick:je}):z.rootNodes.map(n=>e.jsx(vt,{node:n,onSelect:_,onToggle:z.toggleExpand,isExpanded:z.isExpanded,getChildCount:t=>z.getChildren(t).length,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:se?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):Ne.length===0?e.jsx(Le,{onCtaClick:je}):Ne.map(n=>e.jsx(xt,{node:n,onSelect:_,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="board"?e.jsx("div",{className:"agent-board",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-board-card",n.state);return e.jsx("div",{className:`agent-board-card ${k}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:$=>$.key==="Enter"&&_(n.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:Se(n.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:pe(n.role)}),e.jsx("span",{className:`agent-board-badge badge ${d}`,children:n.state})]}),e.jsx("div",{className:"agent-board-name",children:n.name}),e.jsx("div",{className:"agent-board-id",children:n.id}),e.jsxs("div",{className:"agent-board-health",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]})]})},n.id)})}):e.jsx("div",{className:"agent-list",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-card",n.state),$=Je(n.runtimeConfig?.heartbeatIntervalMs),ee=Bt($),_e=ke===n.id;return e.jsxs("div",{className:`agent-card ${k}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:N=>N.key==="Enter"&&_(n.id),children:[ve===n.id?e.jsx("select",{ref:ne,className:"select agent-role-select",value:n.role,onChange:N=>void Ie(n.id,N.target.value),onKeyDown:N=>i(N,n.id),onBlur:()=>W(null),autoFocus:!0,children:ze.map(N=>e.jsxs("option",{value:N.value,children:[N.icon," ",N.label]},N.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:N=>{N.stopPropagation(),W(n.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.stopPropagation(),W(n.id))},children:Se(n.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:n.name}),e.jsx("span",{className:"agent-id text-secondary",children:n.id})]}),e.jsx(ht,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${d}`,children:n.state}),e.jsxs("span",{className:"badge",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]}),e.jsx("span",{className:"badge text-secondary",children:pe(n.role)}),(()=>{const N=Ae(n);if(N.length===0)return null;const te=N.slice(0,2),Ce=N.length-2;return e.jsxs(e.Fragment,{children:[te.map(tt=>e.jsx("span",{className:"badge badge-skill",children:tt},tt)),Ce>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",Ce]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[n.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:n.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),oe===n.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:ce[n.id]??"",onChange:N=>ae(te=>({...te,[n.id]:N.target.value})),onKeyDown:N=>{N.key==="Enter"?R(n):N.key==="Escape"&&(U(null),ae(te=>{const Ce={...te};return delete Ce[n.id],Ce}))},disabled:_e,"aria-label":`Custom heartbeat interval in minutes for ${n.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void R(n),disabled:_e,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{U(null),ae(N=>{const te={...N};return delete te[n.id],te})},disabled:_e,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:$,onChange:N=>{const te=N.target.value;te==="__custom__"?Y(n):x(n,Number(te))},disabled:_e,"aria-label":`Set heartbeat interval for ${n.name}`,children:[ee.map(N=>e.jsx("option",{value:N.value,children:N.label},N.value)),Gt.some(N=>N.value===$)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),_e&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),n.lastHeartbeatAt&&(()=>{const N=new Date(n.lastHeartbeatAt),te=new Date(N.getTime()+$),Ce=n.state==="active"||n.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:N.toLocaleString(),children:["Last: ",N.toLocaleTimeString()]}),Ce&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:te.toLocaleString(),children:["Next: ",te.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[n.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Activate",children:[e.jsx($e,{size:14})," Start"]}),n.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void Pe(n.id,n.name),disabled:H.has(n.id),title:"Run Now","aria-label":`Run now for ${n.name}`,children:[e.jsx(Te,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Resume",children:[e.jsx($e,{size:14})," Resume"]}),n.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${n.name}`,children:[e.jsx(Te,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Retry",children:[e.jsx($e,{size:14})," Retry"]}),n.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Start",children:[e.jsx($e,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>_(n.id),title:`View details for ${n.name}`,"aria-label":`View details for ${n.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void Me(n.id,n.name),title:"Delete",children:[e.jsx(Qt,{size:14})," Delete"]})]})]},n.id)})})]}),E&&e.jsx(a.Suspense,{fallback:null,children:e.jsx(Gn,{agentId:E,projectId:l,onClose:B,addToast:s,onChildClick:G})})]})}export{ta as AgentsView};
|