@runfusion/fusion 0.4.1 → 1.0.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 +34074 -34923
- package/dist/client/assets/{AgentDetailView-sy6Hg1Xr.js → AgentDetailView-dhJd4os0.js} +6 -11
- package/dist/client/assets/{AgentsView-DpEpW88a.js → AgentsView-CYVTv2_l.js} +3 -3
- package/dist/client/assets/{ChatView-BUt3C4cf.js → ChatView-ByPhfQZ6.js} +1 -1
- package/dist/client/assets/{DevServerView-BOyWtQJM.js → DevServerView-CD7mgC11.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-BJyEEso5.js → DirectoryPicker-Cm0FCC9M.js} +1 -1
- package/dist/client/assets/{DocumentsView-Dx0M1YHw.js → DocumentsView-oB319uCj.js} +1 -1
- package/dist/client/assets/{InsightsView-BtXdAo7D.js → InsightsView-BHdMNnOa.js} +1 -1
- package/dist/client/assets/{MemoryView-kKPuqmwf.js → MemoryView-BDJMlzlM.js} +1 -1
- package/dist/client/assets/{NodesView-B_ZwUORz.js → NodesView-BfOlOj-Q.js} +1 -1
- package/dist/client/assets/{PiExtensionsManager-Db0EGr0Q.js → PiExtensionsManager-D-IznnkU.js} +2 -2
- package/dist/client/assets/{PluginManager-mOwWndfg.js → PluginManager-D40uAE-p.js} +1 -1
- package/dist/client/assets/{RoadmapsView-DbUzBLeF.js → RoadmapsView-DtgL8yl3.js} +1 -1
- package/dist/client/assets/{SettingsModal-TRJu_mTn.js → SettingsModal-0IyoaKEv.js} +1 -1
- package/dist/client/assets/SettingsModal-D1vZdAS4.js +31 -0
- package/dist/client/assets/{SetupWizardModal-D1bmCQrf.js → SetupWizardModal-BaQ8VkZm.js} +1 -1
- package/dist/client/assets/{SkillsView-Dzzpd5Md.js → SkillsView-DAvaRl37.js} +1 -1
- package/dist/client/assets/TodoView-BXRQSmSw.js +1 -0
- package/dist/client/assets/TodoView-DNi8blBB.css +1 -0
- package/dist/client/assets/{folder-open-BcuByk6U.js → folder-open-BJ4SvamV.js} +1 -1
- package/dist/client/assets/index-B7TDbn3p.css +1 -0
- package/dist/client/assets/index-CGW6tOaX.js +631 -0
- package/dist/client/assets/list-checks-CpGwz9gV.js +6 -0
- package/dist/client/assets/{upload-BzNbXYEj.js → upload-DJYyvab0.js} +1 -1
- package/dist/client/assets/{users-BvIqhSXp.js → users-ndAFpylb.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/client/version.json +1 -1
- package/dist/extension.js +3262 -599
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/pi-claude-cli/src/__tests__/process-manager.test.ts +50 -17
- package/dist/pi-claude-cli/src/__tests__/setup-test-isolation.test.ts +30 -0
- package/dist/pi-claude-cli/src/__tests__/setup-test-isolation.ts +6 -0
- package/package.json +5 -5
- package/skill/fusion/references/extension-tools.md +5 -5
- package/skill/fusion/references/fusion-capabilities.md +5 -5
- package/dist/client/assets/SettingsModal-Bs_lNs5B.js +0 -31
- package/dist/client/assets/index-BipedNj4.css +0 -1
- package/dist/client/assets/index-k2c4LrUr.js +0 -616
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{c as
|
|
1
|
+
import{r as a,j as e}from"./vendor-react-K0fH_qHe.js";import{c as we,cs as ks,ct as Cs,cu as ws,cv as Rs,L as O,R as Ee,af as ts,Z as Ms,ag as Te,I as ke,K as hs,D as gs,cw as Fs,cx as Ts,cy as As,cz as Ls,p as W,cA as Ds,s as as,B as ns,E as ye,J as is,aJ as ge,X as Es,F as Ce,A as Ne,v as ze,cB as zs,bR as $s,aq as Ps,b4 as Bs,ah as fs,M as Is,U as Os,V as _s,cC as Le,cD as Hs,y as Vs,cE as Us,cF as Js,cG as Ws,cH as Gs,cI as qs,cJ as $e,a3 as Pe,a5 as Be,a6 as Ie,C as X,a1 as Ks,cK as Ys,cL as Qs,i as Zs,h as Xs,j as et,cM as De,W as st,cN as tt,cO as at,cP as nt,cQ as it,cR as rt,cS as lt,cT as ot,cU as ct,Q as dt,cV as ut,N as mt}from"./index-CGW6tOaX.js";import{S as ht}from"./AgentsView-CYVTv2_l.js";import{L as xs}from"./list-checks-CpGwz9gV.js";import"./vendor-xterm-DzcZoU0P.js";import"./upload-DJYyvab0.js";import"./folder-open-BJ4SvamV.js";/**
|
|
2
2
|
* @license lucide-react v1.7.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const gt=[["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"}]],
|
|
6
|
+
*/const gt=[["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"}]],Se=we("chart-column",gt);/**
|
|
7
7
|
* @license lucide-react v1.7.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const ft=[["
|
|
11
|
+
*/const ft=[["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"}]],xt=we("square-activity",ft);/**
|
|
12
12
|
* @license lucide-react v1.7.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const
|
|
16
|
+
*/const pt=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],ps=we("star",pt);/**
|
|
17
17
|
* @license lucide-react v1.7.0 - ISC
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the ISC license.
|
|
20
20
|
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const vt=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],ps=xe("star",vt);/**
|
|
22
|
-
* @license lucide-react v1.7.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const bt=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],jt=xe("trending-down",bt);function rs(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 yt(s){return`${Math.round(s*100)}%`}function ls(s){const t=Date.now(),i=new Date(s).getTime(),d=t-i;if(d<0){const c=Math.abs(d);return c<6e4?"in a moment":c<36e5?`in ${Math.floor(c/6e4)}m`:c<864e5?`in ${Math.floor(c/36e5)}h`:`in ${Math.floor(c/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 Nt(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 me(s){return s instanceof Error&&s.message?s.message:String(s)}function St(s){switch(s){case"improving":return"↑ Improving";case"declining":return"↓ Declining";case"stable":return"→ Stable";default:return"Insufficient data"}}function kt(s){switch(s){case"improving":return"trend-improving";case"declining":return"trend-declining";case"stable":return"trend-stable";default:return"trend-insufficient"}}function os(s,t=5){return e.jsx("span",{className:"rating-stars",children:Array.from({length:t},(i,d)=>e.jsx(ps,{size:14,className:d<s?"star-filled":"star-empty",fill:d<s?"currentColor":"none"},d))})}function Ct({agentId:s,projectId:t,addToast:i}){const[d,c]=a.useState([]),[r,N]=a.useState(null),[u,j]=a.useState(null),[b,k]=a.useState([]),[x,R]=a.useState(!0),[g,f]=a.useState(!0),[h,C]=a.useState(!1),[_,q]=a.useState(!1),[P,M]=a.useState(null),[z,E]=a.useState(0),[F,V]=a.useState(""),[G,S]=a.useState(""),H=a.useCallback(async()=>{try{const[l,y]=await Promise.all([ks(s,20,t),Cs(s,void 0,t)]);c(l),N(y)}catch(l){i(`Failed to load reflections: ${me(l)}`,"error")}finally{R(!1)}},[s,t,i]),p=a.useCallback(async()=>{try{const[l,y]=await Promise.all([ws(s,t),Rs(s,{limit:50},t)]);j(l),k(y)}catch(l){i(`Failed to load ratings: ${me(l)}`,"error")}finally{f(!1)}},[s,t,i]);a.useEffect(()=>{H(),p()},[H,p]);const B=async()=>{C(!0);try{if(!await Fs(s,t)){i("Not enough history to generate a reflection yet","error");return}i("Reflection generated successfully","success"),R(!0),await H()}catch(l){const y=me(l),$=y.toLowerCase();$.includes("agent not found")||$.includes("not found")?i("This agent is no longer available. It may have been deleted.","error"):$.includes("insufficient history")?i("Not enough history to generate a reflection yet","error"):i(`Failed to generate reflection: ${y}`,"error")}finally{C(!1)}},o=async l=>{if(l.preventDefault(),z!==0){q(!0);try{await Ts(s,{score:z,category:F||void 0,comment:G||void 0,raterType:"user"},t),E(0),V(""),S(""),i("Rating added","success"),await p()}catch(y){i(`Failed to add rating: ${me(y)}`,"error")}finally{q(!1)}}},D=async l=>{try{await As(s,l,t),i("Rating deleted","success"),await p()}catch(y){i(`Failed to delete rating: ${me(y)}`,"error")}},m=l=>{M(y=>y===l?null:l)};if(x&&g)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 I=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(ke,{size:16}),"Performance, Reflections & Ratings"]}),e.jsx("button",{className:"btn btn-secondary",onClick:B,disabled:h,title:"Generate a manual reflection",children:h?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:14,className:"animate-spin"}),"Reflecting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ze,{size:14}),"Reflect Now"]})})]}),r&&!I&&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(ts,{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(jt,{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(Ms,{size:16,style:{color:"var(--in-progress)"}}),rs(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(ke,{size:16,style:{color:r.successRate>=.8?"var(--color-success)":r.successRate>=.5?"var(--color-warning)":"var(--color-error)"}}),yt(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(Te,{size:16,style:{color:"var(--color-info)"}}),r.recentReflectionCount]}),e.jsx("div",{className:"stat-label",children:"Reflections"})]})]}),I&&e.jsxs("div",{className:"reflections-no-data",children:[e.jsx(ke,{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"}),g?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:[u&&e.jsxs("div",{className:"rating-summary-card",children:[e.jsxs("div",{className:"rating-score-display",children:[e.jsx("span",{className:"rating-average",children:u.averageScore.toFixed(1)}),os(Math.round(u.averageScore))]}),e.jsxs("div",{className:"rating-stats",children:[e.jsxs("span",{className:"rating-count",children:[u.totalRatings," ratings"]}),e.jsx("span",{className:`rating-trend-badge ${kt(u.trend)}`,children:St(u.trend)})]})]}),u&&Object.keys(u.categoryAverages).length>0&&e.jsxs("div",{className:"category-breakdown",children:[e.jsx("h4",{children:"Category Averages"}),Object.entries(u.categoryAverages).map(([l,y])=>e.jsxs("div",{className:"category-item",children:[e.jsx("span",{className:"category-name",children:l}),e.jsx("span",{className:"category-score",children:y.toFixed(1)})]},l))]}),e.jsxs("form",{className:"add-rating-form",onSubmit:o,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:()=>E(l),title:`${l} star${l>1?"s":""}`,children:e.jsx(ps,{size:24,fill:l<=z?"currentColor":"none",className:l<=z?"star-filled":"star-empty"})},l))}),e.jsxs("select",{value:F,onChange:l=>V(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=>S(l.target.value),placeholder:"Optional comment...",className:"input add-rating-comment-input",rows:3}),e.jsx("button",{type:"submit",className:"btn btn--primary",disabled:z===0||_,children:_?"Submitting...":"Submit Rating"})]}),e.jsxs("div",{className:"rating-history",children:[e.jsx("h4",{children:"Rating History"}),b.length===0?e.jsx("p",{className:"no-ratings",children:"No ratings yet"}):b.map(l=>e.jsxs("div",{className:"rating-history-item",children:[e.jsxs("div",{className:"rating-item-header",children:[os(l.score),l.category&&e.jsx("span",{className:"rating-category-badge",children:l.category}),e.jsx("span",{className:"rating-time",children:ls(l.createdAt)}),e.jsx("button",{type:"button",className:"rating-delete-btn touch-target",onClick:()=>void D(l.id),title:"Delete rating",children:e.jsx(Ce,{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"}),x?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(Te,{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 y=P===l.id;return e.jsxs("div",{className:`reflection-card ${y?"reflection-card--expanded":""}`,onClick:()=>m(l.id),role:"button",tabIndex:0,onKeyDown:$=>$.key==="Enter"&&m(l.id),children:[e.jsxs("div",{className:"reflection-card-header",children:[e.jsx("span",{className:`reflection-trigger-badge reflection-trigger-${l.trigger}`,children:Nt(l.trigger)}),e.jsx("span",{className:"reflection-timestamp",children:ls(l.timestamp)}),e.jsx("span",{className:"reflection-chevron",children:y?e.jsx(hs,{size:16}):e.jsx(gs,{size:16})})]}),e.jsx("div",{className:"reflection-summary",children:l.summary}),y&&e.jsxs("div",{className:"reflection-details",children:[l.insights.length>0&&e.jsxs("div",{className:"reflection-insights",children:[e.jsxs("h5",{children:[e.jsx(Te,{size:14})," Insights"]}),e.jsx("ul",{children:l.insights.map(($,U)=>e.jsx("li",{children:$},U))})]}),l.suggestedImprovements.length>0&&e.jsxs("div",{className:"reflection-suggestions",children:[e.jsxs("h5",{children:[e.jsx(ts,{size:14})," Suggested Improvements"]}),e.jsx("ul",{children:l.suggestedImprovements.map(($,U)=>e.jsx("li",{children:$},U))})]}),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:rs(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 Z(...s){return s.filter(Boolean).join(" ")}function fe(s){const t=Date.now(),i=new Date(s).getTime(),d=t-i;if(d<0){const c=Math.abs(d);return c<6e4?"in a moment":c<36e5?`in ${Math.floor(c/6e4)}m`:c<864e5?`in ${Math.floor(c/36e5)}h`:`in ${Math.floor(c/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 wt=[{id:"dashboard",label:"Dashboard",icon:pt},{id:"logs",label:"Logs",icon:we},{id:"runs",label:"Runs",icon:Se},{id:"tasks",label:"Tasks",icon:xs},{id:"employees",label:"Employees",icon:Ee},{id:"soul",label:"Soul",icon:Es},{id:"instructions",label:"Instructions",icon:$s},{id:"memory",label:"Agent Memory",icon:we},{id:"reflections",label:"Evaluation",icon:ke},{id:"config",label:"Settings",icon:Ps}],Oe={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)"}},cs={completed:{icon:X,color:"var(--color-success, #3fb950)"},failed:{icon:at,color:"var(--color-error, #f85149)"},active:{icon:O,color:"var(--in-progress, #bc8cff)"},terminated:{icon:ge,color:"var(--text-muted, #8b949e)"}},ds={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Rt={"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."},Mt=dt(De);function Ft(s,t){return s.some(i=>i.path===t)?t:s.find(i=>i.layer==="long-term")?.path??s[0]?.path??""}function Yt({agentId:s,projectId:t,onClose:i,addToast:d,onChildClick:c}){const[r,N]=a.useState(null),[u,j]=a.useState([]),[b,k]=a.useState(!0),[x,R]=a.useState("dashboard"),[g,f]=a.useState(!1),h=a.useRef(null),C=a.useRef(i),_=a.useRef(d),q=a.useRef(null),P=a.useRef(!1),M=a.useRef(0),z=a.useRef(s),E=a.useRef(t);C.current=i,_.current=d,q.current=r;const F=a.useCallback(async()=>{q.current===null&&k(!0);try{const I=await Ls(s,t);N(I)}catch(I){_.current(`Failed to load agent: ${W(I)}`,"error"),C.current()}finally{k(!1)}},[s,t]),V=a.useCallback(async()=>{const m=M.current,I=s,l=t;if(r?.taskId)try{const y=await Ds(r.taskId,l,{limit:100});if(M.current!==m||s!==I||t!==l)return;j(y.entries)}catch(y){if(M.current!==m||s!==I||t!==l)return;console.error("Failed to load task logs:",y)}},[r?.taskId,s,t]),G=a.useCallback(m=>{P.current=m},[]);a.useEffect(()=>{F()},[F]),a.useEffect(()=>{const m=setInterval(()=>{F()},3e4);return()=>{clearInterval(m)}},[F]),a.useEffect(()=>{r?.taskId&&V()},[r?.taskId,V]),a.useEffect(()=>{(z.current!==s||E.current!==t)&&(z.current=s,E.current=t,M.current++,j([]),f(!1),P.current=!1)},[s,t]),a.useEffect(()=>{const m=t?`?projectId=${encodeURIComponent(t)}`:"",I=M.current;return as(`/api/events${m}`,{events:{"agent:updated":l=>{if(M.current===I)try{const y=JSON.parse(l.data);if(!y||typeof y!="object"||y.id!==s||P.current)return;F()}catch{}}}})},[s,t,F]),a.useEffect(()=>{if(x!=="logs"||!r?.taskId){f(!1);return}const m=M.current,I=r.taskId,l=t?`?projectId=${encodeURIComponent(t)}`:"",y=as(`/api/tasks/${encodeURIComponent(I)}/logs/stream${l}`,{events:{"agent:log":$=>{if(M.current===m)try{const U=JSON.parse($.data);j(L=>[U,...L]);const te=h.current;te&&te.scrollTop<50&&(te.scrollTop=0)}catch{}}},onOpen:()=>{M.current===m&&f(!0)},onError:()=>{M.current===m&&f(!1)}});return()=>{y(),M.current===m&&f(!1)}},[r?.taskId,x,t]);const S=async m=>{try{await Os(s,m,t),d(`Agent state updated to ${m}`,"success"),F()}catch(I){d(`Failed to update state: ${W(I)}`,"error")}},H=async()=>{if(!(!r||!confirm(`Delete agent "${r.name}"? This cannot be undone.`)))try{await _s(s,t),d(`Agent "${r.name}" deleted`,"success"),i()}catch(m){d(`Failed to delete agent: ${W(m)}`,"error")}},p=()=>r?Is(r):{label:"Unknown",icon:e.jsx(ns,{size:14}),color:"var(--text-muted, #8b949e)",stateDerived:!1},B=()=>{r&&(navigator.clipboard.writeText(r.id),d("Agent ID copied to clipboard","success"))};if(b)return e.jsx("div",{className:"agent-detail-overlay",onClick:m=>m.target===m.currentTarget&&i(),role:"dialog","aria-modal":"true",children:e.jsx("div",{className:"agent-detail-modal",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 o=Oe[r.state],D=p();return e.jsx("div",{className:"agent-detail-overlay",onClick:m=>m.target===m.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(ns,{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:o.bg,color:o.text,border:`1px solid ${o.border}`},children:r.state}),e.jsxs("span",{className:"badge",style:{color:D.color},title:D.label,children:[D.icon,!D.stateDerived&&D.label]})]})]})]}),e.jsxs("div",{className:"agent-detail-controls",children:[r.state==="idle"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--primary btn--compact",onClick:()=>void S("active"),children:[e.jsx(Ne,{size:14}),"Start"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:H,children:[e.jsx(Ce,{size:14}),"Delete"]})]}),r.state==="active"&&e.jsxs("button",{className:"btn btn--compact",onClick:()=>void S("paused"),children:[e.jsx(is,{size:14}),"Pause"]}),r.state==="paused"&&e.jsxs("button",{className:"btn btn--primary btn--compact",onClick:()=>void S("active"),children:[e.jsx(Ne,{size:14}),"Resume"]}),r.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--compact",onClick:()=>void S("paused"),children:[e.jsx(is,{size:14}),"Pause"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:()=>void S("terminated"),children:[e.jsx(ge,{size:14}),"Stop"]})]}),r.state==="error"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--primary btn--compact",onClick:()=>void S("active"),children:[e.jsx(Ne,{size:14}),"Retry"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:()=>void S("terminated"),children:[e.jsx(ge,{size:14}),"Stop"]})]}),r.state==="terminated"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--primary btn--compact",onClick:()=>void S("active"),children:[e.jsx(Ne,{size:14}),"Start"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:H,children:[e.jsx(Ce,{size:14}),"Delete"]})]})]}),e.jsxs("div",{className:"agent-detail-utility-actions",children:[e.jsx("button",{className:"btn-icon",onClick:()=>void F(),title:"Refresh",children:e.jsx(ze,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:i,"aria-label":"Close",title:"Close",children:e.jsx(zs,{size:20})})]})]}),e.jsx("div",{className:"agent-detail-tabs",children:wt.map(m=>e.jsxs("button",{className:Z("agent-detail-tab",x===m.id&&"active"),onClick:()=>R(m.id),children:[e.jsx(m.icon,{size:16}),m.label]},m.id))}),e.jsxs("div",{className:"agent-detail-content",children:[x==="dashboard"&&e.jsx(Tt,{agent:r,health:D,onChildClick:c,projectId:t}),x==="logs"&&e.jsx(At,{logs:u,isStreaming:g,containerRef:h,hasTask:!!r.taskId}),x==="runs"&&e.jsx(Dt,{addToast:d,agentId:r.id,projectId:t,agentState:r.state,agentName:r.name}),x==="tasks"&&e.jsx(Pt,{agentId:r.id,projectId:t,addToast:d}),x==="employees"&&e.jsx(Vt,{agentId:r.id,projectId:t,onChildClick:c}),x==="soul"&&e.jsx(It,{agent:r,projectId:t,addToast:d,onSaved:F}),x==="instructions"&&e.jsx(_t,{agent:r,projectId:t,addToast:d,onSaved:F}),x==="memory"&&e.jsx(Ot,{agent:r,projectId:t,addToast:d,onSaved:F}),x==="reflections"&&e.jsx(Ct,{agentId:r.id,projectId:t,addToast:d}),x==="config"&&e.jsx(Ht,{agent:r,projectId:t,addToast:d,onSaved:F,onHasChangesChange:G,onDelete:H})]}),e.jsxs("div",{className:"agent-detail-footer",children:[e.jsx("button",{className:"btn-icon",onClick:B,title:"Copy Agent ID",children:e.jsx(Bs,{size:14})}),e.jsx("span",{className:"agent-detail-id",onClick:B,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(fs,{size:12})]})]})]})]})})}function Tt({agent:s,health:t,onChildClick:i,projectId:d}){const c=Oe[s.state],[r,N]=a.useState([]),[u,j]=a.useState(!0),[b,k]=a.useState(null),x=(()=>{const g=s.runtimeConfig??{};if(g.modelProvider&&g.modelId)return`${g.modelProvider}/${g.modelId}`;if(typeof g.model=="string"&&g.model.includes("/")){const f=g.model.indexOf("/");return g.model.slice(f+1)}return null})();a.useEffect(()=>{Le(s.id,d).then(k).catch(()=>k(null))},[s.id,d]),a.useEffect(()=>{let g=!1;return j(!0),Hs(s.id,d).then(f=>{if(g)return;const h=f.length>0&&f[0]?.id===s.id?[...f].reverse():f;N(h)}).catch(()=>{g||N([])}).finally(()=>{g||j(!1)}),()=>{g=!0}},[s.id,d]);const R=a.useMemo(()=>{const g=s.completedRuns||[],f=new Date;f.setHours(0,0,0,0);const h=g.filter(_=>new Date(_.startedAt)>=f),C=g.filter(_=>_.status==="completed");return{totalRuns:g.length,todayRuns:h.length,successfulRuns:C.length,successRate:g.length>0?Math.round(C.length/g.length*100):0}},[s]);return e.jsxs("div",{className:"dashboard-tab",children:[b?.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(g=>e.jsx("span",{className:"skill-badge",children:g},g))}):"—"})]}),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:c.bg,color:c.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:t.color},title:t.label,children:t.stateDerived?t.icon:t.label})]}),x&&e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Model"}),e.jsx("span",{className:"info-value",children:x})]}),b?.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:b.isOverBudget?"var(--state-error-bg, rgba(248,81,73,0.15))":b.isOverThreshold?"var(--state-paused-bg, rgba(227,181,65,0.15))":"var(--state-active-bg, rgba(63,185,80,0.15))",color:b.isOverBudget?"var(--state-error-text, #f85149)":b.isOverThreshold?"var(--state-paused-text, #e3b541)":"var(--state-active-text, #3fb950)",border:`1px solid ${b.isOverBudget?"var(--state-error-border, #f85149)":b.isOverThreshold?"var(--state-paused-border, #e3b541)":"var(--state-active-border, #3fb950)"}`},children:b.isOverBudget?"⚠ Budget Exhausted":`${Math.round(b.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?fe(s.lastHeartbeatAt):"Never"})]}),(()=>{if(!(s.state==="active"||s.state==="running")||!s.lastHeartbeatAt)return null;const f=Vs(s.runtimeConfig?.heartbeatIntervalMs),h=new Date(new Date(s.lastHeartbeatAt).getTime()+f);return e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Next Heartbeat"}),e.jsx("span",{className:"info-value",title:h.toLocaleString(),children:fe(h.toISOString())})]})})()]})]}),e.jsxs("div",{className:"dashboard-section",children:[e.jsxs("h3",{children:[e.jsx(Ee,{size:16,style:{marginRight:"6px",verticalAlign:"-2px"}}),"Chain of Command"]}),u?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((g,f)=>{const h=f===r.length-1,C=!h;return e.jsxs("div",{className:"chain-of-command-item",children:[e.jsx("button",{type:"button",className:`chain-of-command-node${h?" chain-of-command-node--current":""}`,onClick:()=>C&&i?.(g.id),disabled:!C||!i,title:h?"Current agent":`View ${g.name}`,children:g.name}),!h&&e.jsx("span",{className:"chain-of-command-separator","aria-hidden":"true",children:"→"})]},g.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:R.totalRuns}),e.jsx("div",{className:"stat-label",children:"Total Runs"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-value",children:R.todayRuns}),e.jsx("div",{className:"stat-label",children:"Runs Today"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsxs("div",{className:"stat-value",children:[R.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(fs,{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 At({logs:s,isStreaming:t,containerRef:i,hasTask:d}){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"]}),t&&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(we,{size:48,opacity:.3}),e.jsx("p",{children:"No log entries yet"}),e.jsx("p",{className:"text-muted",children:t?"Waiting for activity...":"Logs will appear here when the agent is active"})]}):s.map((c,r)=>{const N=r>0?s[r-1]:void 0,u=!N||N.agent!==c.agent;return e.jsx(Lt,{entry:c,showTimestamp:u},`${c.timestamp}-${r}`)})})]}):e.jsx("div",{className:"logs-tab",children:e.jsxs("div",{className:"logs-empty",children:[e.jsx(we,{size:48,opacity:.3}),e.jsx("p",{children:"No task assigned"}),e.jsx("p",{className:"text-muted",children:"Agent logs are available when the agent is assigned to a task"})]})})}function Lt({entry:s,showTimestamp:t}){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)"}}})(),c=new Date(s.timestamp).toLocaleTimeString();return e.jsxs("div",{className:"log-entry",style:d,children:[t&&e.jsxs("span",{className:"log-timestamp",children:["[",c,"]"]}),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 Dt({addToast:s,agentId:t,projectId:i,agentState:d,agentName:c}){const[r,N]=a.useState([]),[u,j]=a.useState(!0),[b,k]=a.useState(null),[x,R]=a.useState([]),[g,f]=a.useState(!1),[h,C]=a.useState(null),[_,q]=a.useState(!1),P=a.useCallback(async()=>{try{const o=await Us(t,50,i);N(o)}catch(o){s(`Failed to load runs: ${W(o)}`,"error")}finally{j(!1)}},[t,i,s]);a.useEffect(()=>{P()},[P]);const M=r.some(o=>o.status==="active");a.useEffect(()=>{if(!M)return;const o=setInterval(()=>{P()},5e3);return()=>clearInterval(o)},[M,P]);const z=a.useCallback(async o=>{if(b===o){k(null),R([]),C(null);return}k(o),f(!0),q(!0),R([]),C(null);try{const[D,m]=await Promise.all([Js(t,o,i),Ws(t,o,i)]);R(D),C(m)}catch(D){s(`Failed to load run details: ${W(D)}`,"error"),R([]),C(null)}finally{f(!1),q(!1)}},[b,t,i,s]),E=async()=>{try{await st(t,i,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${c??t}`,"success"),j(!0),P()}catch(o){s(`Failed to start heartbeat run: ${W(o)}`,"error")}},F=async()=>{if(confirm("Stop the active run? The agent's work will be interrupted."))try{await tt(t,i),s("Run stopped","success"),j(!0),P()}catch(o){s(`Failed to stop run: ${W(o)}`,"error")}},V=d==="active"||d==="idle";if(u&&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:[V&&e.jsx("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border-color)"},children:e.jsxs("button",{className:"btn btn--sm btn--primary",onClick:()=>void E(),"aria-label":`Run now for ${c??t}`,children:[e.jsx(Se,{size:14})," Run Now"]})}),e.jsxs("div",{className:"runs-empty",children:[e.jsx(Se,{size:48,opacity:.3}),e.jsx("p",{children:"No runs yet"}),e.jsx("p",{className:"text-muted",children:"Heartbeat runs will appear here"})]})]});const G=[...r].sort((o,D)=>new Date(D.startedAt).getTime()-new Date(o.startedAt).getTime()),S=G.filter(o=>o.status==="active"),H=G.filter(o=>o.status!=="active"),p=o=>o?e.jsxs("div",{style:{fontSize:"12px",color:"var(--text-secondary)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[e.jsxs("span",{children:["Input: ",o.inputTokens.toLocaleString()]}),e.jsxs("span",{children:["Output: ",o.outputTokens.toLocaleString()]}),o.cachedTokens>0&&e.jsxs("span",{children:["Cached: ",o.cachedTokens.toLocaleString()]})]}):null,B=(o,D,m)=>{const I=cs[o.status]||cs.completed,l=I.icon,y=o.endedAt?zt(new Date(o.startedAt),new Date(o.endedAt)):"In progress",$=b===o.id;return e.jsxs("div",{children:[e.jsxs("div",{className:Z("run-card",m&&"run-card--active",$&&"run-card--selected"),onClick:()=>void z(o.id),style:{cursor:"pointer"},role:"button",tabIndex:0,"aria-expanded":$,"aria-label":`${m?"Active":""} run ${o.id.slice(0,8)}, ${o.status}`,onKeyDown:U=>{(U.key==="Enter"||U.key===" ")&&(U.preventDefault(),z(o.id))},children:[e.jsxs("div",{className:"run-header",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[$?e.jsx(hs,{size:14}):e.jsx(gs,{size:14}),m?e.jsxs("span",{className:"run-live-indicator",children:[e.jsx("span",{className:"live-dot"}),"Live Run"]}):e.jsxs("span",{className:"run-id",children:["#",D+1," ",o.id.slice(0,8)]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[o.invocationSource&&e.jsx("span",{className:"badge",style:{fontSize:"10px",padding:"1px 6px"},children:o.invocationSource}),m&&e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:U=>{U.preventDefault(),U.stopPropagation(),F()},"aria-label":"Stop active run",children:[e.jsx(ge,{size:12})," Stop"]}),e.jsxs("span",{className:Z("run-status",o.status),children:[e.jsx(l,{size:14,className:I.color,style:o.status==="active"?{color:I.color}:void 0}),o.status]})]})]}),e.jsxs("div",{className:"run-details",children:[e.jsxs("span",{children:["Started ",fe(o.startedAt)]}),e.jsx("span",{children:"•"}),e.jsx("span",{children:y}),o.triggerDetail&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{className:"text-muted",children:o.triggerDetail})]})]})]}),$&&e.jsxs("div",{className:"run-logs-container",style:{padding:"12px",background:"var(--bg-secondary)",borderBottom:"1px solid var(--border-color)",borderTop:"1px solid var(--border-color)"},children:[_?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 0"},children:[e.jsx(O,{size:14,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading details..."})]}):h&&e.jsxs("div",{style:{marginBottom:"12px"},children:[h.usageJson&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Token Usage"}),p(h.usageJson)]}),h.stdoutExcerpt&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Output"}),e.jsx("pre",{style:{background:"var(--bg-tertiary, #161b22)",padding:"8px 12px",borderRadius:"6px",fontSize:"12px",maxHeight:"200px",overflow:"auto",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:h.stdoutExcerpt.length>2e3?`${h.stdoutExcerpt.slice(0,2e3)}
|
|
21
|
+
*/const vt=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],bt=we("trending-down",vt);function rs(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 jt(s){return`${Math.round(s*100)}%`}function ls(s){const t=Date.now(),i=new Date(s).getTime(),d=t-i;if(d<0){const c=Math.abs(d);return c<6e4?"in a moment":c<36e5?`in ${Math.floor(c/6e4)}m`:c<864e5?`in ${Math.floor(c/36e5)}h`:`in ${Math.floor(c/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 yt(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 me(s){return s instanceof Error&&s.message?s.message:String(s)}function Nt(s){switch(s){case"improving":return"↑ Improving";case"declining":return"↓ Declining";case"stable":return"→ Stable";default:return"Insufficient data"}}function St(s){switch(s){case"improving":return"trend-improving";case"declining":return"trend-declining";case"stable":return"trend-stable";default:return"trend-insufficient"}}function os(s,t=5){return e.jsx("span",{className:"rating-stars",children:Array.from({length:t},(i,d)=>e.jsx(ps,{size:14,className:d<s?"star-filled":"star-empty",fill:d<s?"currentColor":"none"},d))})}function kt({agentId:s,projectId:t,addToast:i}){const[d,c]=a.useState([]),[r,N]=a.useState(null),[u,j]=a.useState(null),[b,k]=a.useState([]),[x,R]=a.useState(!0),[g,f]=a.useState(!0),[h,C]=a.useState(!1),[_,G]=a.useState(!1),[P,M]=a.useState(null),[E,z]=a.useState(0),[F,V]=a.useState(""),[q,S]=a.useState(""),H=a.useCallback(async()=>{try{const[l,y]=await Promise.all([ks(s,20,t),Cs(s,void 0,t)]);c(l),N(y)}catch(l){i(`Failed to load reflections: ${me(l)}`,"error")}finally{R(!1)}},[s,t,i]),p=a.useCallback(async()=>{try{const[l,y]=await Promise.all([ws(s,t),Rs(s,{limit:50},t)]);j(l),k(y)}catch(l){i(`Failed to load ratings: ${me(l)}`,"error")}finally{f(!1)}},[s,t,i]);a.useEffect(()=>{H(),p()},[H,p]);const B=async()=>{C(!0);try{if(!await Fs(s,t)){i("Not enough history to generate a reflection yet","error");return}i("Reflection generated successfully","success"),R(!0),await H()}catch(l){const y=me(l),$=y.toLowerCase();$.includes("agent not found")||$.includes("not found")?i("This agent is no longer available. It may have been deleted.","error"):$.includes("insufficient history")?i("Not enough history to generate a reflection yet","error"):i(`Failed to generate reflection: ${y}`,"error")}finally{C(!1)}},o=async l=>{if(l.preventDefault(),E!==0){G(!0);try{await Ts(s,{score:E,category:F||void 0,comment:q||void 0,raterType:"user"},t),z(0),V(""),S(""),i("Rating added","success"),await p()}catch(y){i(`Failed to add rating: ${me(y)}`,"error")}finally{G(!1)}}},D=async l=>{try{await As(s,l,t),i("Rating deleted","success"),await p()}catch(y){i(`Failed to delete rating: ${me(y)}`,"error")}},m=l=>{M(y=>y===l?null:l)};if(x&&g)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 I=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(Se,{size:16}),"Performance, Reflections & Ratings"]}),e.jsx("button",{className:"btn btn-secondary",onClick:B,disabled:h,title:"Generate a manual reflection",children:h?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:14,className:"animate-spin"}),"Reflecting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{size:14}),"Reflect Now"]})})]}),r&&!I&&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(ts,{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(bt,{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(Ms,{size:16,style:{color:"var(--in-progress)"}}),rs(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(Se,{size:16,style:{color:r.successRate>=.8?"var(--color-success)":r.successRate>=.5?"var(--color-warning)":"var(--color-error)"}}),jt(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(Te,{size:16,style:{color:"var(--color-info)"}}),r.recentReflectionCount]}),e.jsx("div",{className:"stat-label",children:"Reflections"})]})]}),I&&e.jsxs("div",{className:"reflections-no-data",children:[e.jsx(Se,{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"}),g?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:[u&&e.jsxs("div",{className:"rating-summary-card",children:[e.jsxs("div",{className:"rating-score-display",children:[e.jsx("span",{className:"rating-average",children:u.averageScore.toFixed(1)}),os(Math.round(u.averageScore))]}),e.jsxs("div",{className:"rating-stats",children:[e.jsxs("span",{className:"rating-count",children:[u.totalRatings," ratings"]}),e.jsx("span",{className:`rating-trend-badge ${St(u.trend)}`,children:Nt(u.trend)})]})]}),u&&Object.keys(u.categoryAverages).length>0&&e.jsxs("div",{className:"category-breakdown",children:[e.jsx("h4",{children:"Category Averages"}),Object.entries(u.categoryAverages).map(([l,y])=>e.jsxs("div",{className:"category-item",children:[e.jsx("span",{className:"category-name",children:l}),e.jsx("span",{className:"category-score",children:y.toFixed(1)})]},l))]}),e.jsxs("form",{className:"add-rating-form",onSubmit:o,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:()=>z(l),title:`${l} star${l>1?"s":""}`,children:e.jsx(ps,{size:24,fill:l<=E?"currentColor":"none",className:l<=E?"star-filled":"star-empty"})},l))}),e.jsxs("select",{value:F,onChange:l=>V(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:q,onChange:l=>S(l.target.value),placeholder:"Optional comment...",className:"input add-rating-comment-input",rows:3}),e.jsx("button",{type:"submit",className:"btn btn--primary",disabled:E===0||_,children:_?"Submitting...":"Submit Rating"})]}),e.jsxs("div",{className:"rating-history",children:[e.jsx("h4",{children:"Rating History"}),b.length===0?e.jsx("p",{className:"no-ratings",children:"No ratings yet"}):b.map(l=>e.jsxs("div",{className:"rating-history-item",children:[e.jsxs("div",{className:"rating-item-header",children:[os(l.score),l.category&&e.jsx("span",{className:"rating-category-badge",children:l.category}),e.jsx("span",{className:"rating-time",children:ls(l.createdAt)}),e.jsx("button",{type:"button",className:"rating-delete-btn touch-target",onClick:()=>void D(l.id),title:"Delete rating",children:e.jsx(ke,{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"}),x?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(Te,{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 y=P===l.id;return e.jsxs("div",{className:`reflection-card ${y?"reflection-card--expanded":""}`,onClick:()=>m(l.id),role:"button",tabIndex:0,onKeyDown:$=>$.key==="Enter"&&m(l.id),children:[e.jsxs("div",{className:"reflection-card-header",children:[e.jsx("span",{className:`reflection-trigger-badge reflection-trigger-${l.trigger}`,children:yt(l.trigger)}),e.jsx("span",{className:"reflection-timestamp",children:ls(l.timestamp)}),e.jsx("span",{className:"reflection-chevron",children:y?e.jsx(hs,{size:16}):e.jsx(gs,{size:16})})]}),e.jsx("div",{className:"reflection-summary",children:l.summary}),y&&e.jsxs("div",{className:"reflection-details",children:[l.insights.length>0&&e.jsxs("div",{className:"reflection-insights",children:[e.jsxs("h5",{children:[e.jsx(Te,{size:14})," Insights"]}),e.jsx("ul",{children:l.insights.map(($,U)=>e.jsx("li",{children:$},U))})]}),l.suggestedImprovements.length>0&&e.jsxs("div",{className:"reflection-suggestions",children:[e.jsxs("h5",{children:[e.jsx(ts,{size:14})," Suggested Improvements"]}),e.jsx("ul",{children:l.suggestedImprovements.map(($,U)=>e.jsx("li",{children:$},U))})]}),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:rs(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 Q(...s){return s.filter(Boolean).join(" ")}function fe(s){const t=Date.now(),i=new Date(s).getTime(),d=t-i;if(d<0){const c=Math.abs(d);return c<6e4?"in a moment":c<36e5?`in ${Math.floor(c/6e4)}m`:c<864e5?`in ${Math.floor(c/36e5)}h`:`in ${Math.floor(c/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 Ct=[{id:"dashboard",label:"Dashboard",icon:xt},{id:"logs",label:"Logs",icon:Ce},{id:"runs",label:"Runs",icon:Ne},{id:"tasks",label:"Tasks",icon:xs},{id:"employees",label:"Employees",icon:ze},{id:"soul",label:"Soul",icon:zs},{id:"instructions",label:"Instructions",icon:$s},{id:"memory",label:"Agent Memory",icon:Ce},{id:"reflections",label:"Evaluation",icon:Se},{id:"config",label:"Settings",icon:Ps}],Oe={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)"}},cs={completed:{icon:X,color:"var(--color-success, #3fb950)"},failed:{icon:at,color:"var(--color-error, #f85149)"},active:{icon:O,color:"var(--in-progress, #bc8cff)"},terminated:{icon:ge,color:"var(--text-muted, #8b949e)"}},ds={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},wt={"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."},Rt=dt(De);function Mt(s,t){return s.some(i=>i.path===t)?t:s.find(i=>i.layer==="long-term")?.path??s[0]?.path??""}function Yt({agentId:s,projectId:t,onClose:i,addToast:d,onChildClick:c}){const[r,N]=a.useState(null),[u,j]=a.useState([]),[b,k]=a.useState(!0),[x,R]=a.useState("dashboard"),[g,f]=a.useState(!1),h=a.useRef(null),C=a.useRef(i),_=a.useRef(d),G=a.useRef(null),P=a.useRef(!1),M=a.useRef(0),E=a.useRef(s),z=a.useRef(t);C.current=i,_.current=d,G.current=r;const F=a.useCallback(async()=>{G.current===null&&k(!0);try{const I=await Ls(s,t);N(I)}catch(I){_.current(`Failed to load agent: ${W(I)}`,"error"),C.current()}finally{k(!1)}},[s,t]),V=a.useCallback(async()=>{const m=M.current,I=s,l=t;if(r?.taskId)try{const y=await Ds(r.taskId,l,{limit:100});if(M.current!==m||s!==I||t!==l)return;j(y.entries)}catch(y){if(M.current!==m||s!==I||t!==l)return;console.error("Failed to load task logs:",y)}},[r?.taskId,s,t]),q=a.useCallback(m=>{P.current=m},[]);a.useEffect(()=>{F()},[F]),a.useEffect(()=>{const m=setInterval(()=>{F()},3e4);return()=>{clearInterval(m)}},[F]),a.useEffect(()=>{r?.taskId&&V()},[r?.taskId,V]),a.useEffect(()=>{(E.current!==s||z.current!==t)&&(E.current=s,z.current=t,M.current++,j([]),f(!1),P.current=!1)},[s,t]),a.useEffect(()=>{const m=t?`?projectId=${encodeURIComponent(t)}`:"",I=M.current;return as(`/api/events${m}`,{events:{"agent:updated":l=>{if(M.current===I)try{const y=JSON.parse(l.data);if(!y||typeof y!="object"||y.id!==s||P.current)return;F()}catch{}}}})},[s,t,F]),a.useEffect(()=>{if(x!=="logs"||!r?.taskId){f(!1);return}const m=M.current,I=r.taskId,l=t?`?projectId=${encodeURIComponent(t)}`:"",y=as(`/api/tasks/${encodeURIComponent(I)}/logs/stream${l}`,{events:{"agent:log":$=>{if(M.current===m)try{const U=JSON.parse($.data);j(L=>[U,...L]);const te=h.current;te&&te.scrollTop<50&&(te.scrollTop=0)}catch{}}},onOpen:()=>{M.current===m&&f(!0)},onError:()=>{M.current===m&&f(!1)}});return()=>{y(),M.current===m&&f(!1)}},[r?.taskId,x,t]);const S=async m=>{try{await Os(s,m,t),d(`Agent state updated to ${m}`,"success"),F()}catch(I){d(`Failed to update state: ${W(I)}`,"error")}},H=async()=>{if(!(!r||!confirm(`Delete agent "${r.name}"? This cannot be undone.`)))try{await _s(s,t),d(`Agent "${r.name}" deleted`,"success"),i()}catch(m){d(`Failed to delete agent: ${W(m)}`,"error")}},p=()=>r?Is(r):{label:"Unknown",icon:e.jsx(ns,{size:14}),color:"var(--text-muted, #8b949e)",stateDerived:!1},B=()=>{r&&(navigator.clipboard.writeText(r.id),d("Agent ID copied to clipboard","success"))};if(b)return e.jsx("div",{className:"agent-detail-overlay",onClick:m=>m.target===m.currentTarget&&i(),role:"dialog","aria-modal":"true",children:e.jsx("div",{className:"agent-detail-modal",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 o=Oe[r.state],D=p();return e.jsx("div",{className:"agent-detail-overlay",onClick:m=>m.target===m.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(ns,{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:o.bg,color:o.text,border:`1px solid ${o.border}`},children:r.state}),e.jsxs("span",{className:"badge",style:{color:D.color},title:D.label,children:[D.icon,!D.stateDerived&&D.label]})]})]})]}),e.jsxs("div",{className:"agent-detail-controls",children:[r.state==="idle"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--primary btn--compact",onClick:()=>void S("active"),children:[e.jsx(ye,{size:14}),"Start"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:H,children:[e.jsx(ke,{size:14}),"Delete"]})]}),r.state==="active"&&e.jsxs("button",{className:"btn btn--compact",onClick:()=>void S("paused"),children:[e.jsx(is,{size:14}),"Pause"]}),r.state==="paused"&&e.jsxs("button",{className:"btn btn--primary btn--compact",onClick:()=>void S("active"),children:[e.jsx(ye,{size:14}),"Resume"]}),r.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--compact",onClick:()=>void S("paused"),children:[e.jsx(is,{size:14}),"Pause"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:()=>void S("terminated"),children:[e.jsx(ge,{size:14}),"Stop"]})]}),r.state==="error"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--primary btn--compact",onClick:()=>void S("active"),children:[e.jsx(ye,{size:14}),"Retry"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:()=>void S("terminated"),children:[e.jsx(ge,{size:14}),"Stop"]})]}),r.state==="terminated"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--primary btn--compact",onClick:()=>void S("active"),children:[e.jsx(ye,{size:14}),"Start"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:H,children:[e.jsx(ke,{size:14}),"Delete"]})]})]}),e.jsxs("div",{className:"agent-detail-utility-actions",children:[e.jsx("button",{className:"btn-icon",onClick:()=>void F(),title:"Refresh",children:e.jsx(Ee,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:i,"aria-label":"Close",title:"Close",children:e.jsx(Es,{size:20})})]})]}),e.jsx("div",{className:"agent-detail-tabs",children:Ct.map(m=>e.jsxs("button",{className:Q("agent-detail-tab",x===m.id&&"active"),onClick:()=>R(m.id),children:[e.jsx(m.icon,{size:16}),m.label]},m.id))}),e.jsxs("div",{className:"agent-detail-content",children:[x==="dashboard"&&e.jsx(Ft,{agent:r,health:D,onChildClick:c,projectId:t}),x==="logs"&&e.jsx(Tt,{logs:u,isStreaming:g,containerRef:h,hasTask:!!r.taskId}),x==="runs"&&e.jsx(Lt,{addToast:d,agentId:r.id,projectId:t,agentState:r.state,agentName:r.name}),x==="tasks"&&e.jsx($t,{agentId:r.id,projectId:t,addToast:d}),x==="employees"&&e.jsx(Ht,{agentId:r.id,projectId:t,onChildClick:c}),x==="soul"&&e.jsx(Bt,{agent:r,projectId:t,addToast:d,onSaved:F}),x==="instructions"&&e.jsx(Ot,{agent:r,projectId:t,addToast:d,onSaved:F}),x==="memory"&&e.jsx(It,{agent:r,projectId:t,addToast:d,onSaved:F}),x==="reflections"&&e.jsx(kt,{agentId:r.id,projectId:t,addToast:d}),x==="config"&&e.jsx(_t,{agent:r,projectId:t,addToast:d,onSaved:F,onHasChangesChange:q,onDelete:H})]}),e.jsxs("div",{className:"agent-detail-footer",children:[e.jsx("button",{className:"btn-icon",onClick:B,title:"Copy Agent ID",children:e.jsx(Bs,{size:14})}),e.jsx("span",{className:"agent-detail-id",onClick:B,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(fs,{size:12})]})]})]})]})})}function Ft({agent:s,health:t,onChildClick:i,projectId:d}){const c=Oe[s.state],[r,N]=a.useState([]),[u,j]=a.useState(!0),[b,k]=a.useState(null),x=(()=>{const g=s.runtimeConfig??{};if(g.modelProvider&&g.modelId)return`${g.modelProvider}/${g.modelId}`;if(typeof g.model=="string"&&g.model.includes("/")){const f=g.model.indexOf("/");return g.model.slice(f+1)}return null})();a.useEffect(()=>{Le(s.id,d).then(k).catch(()=>k(null))},[s.id,d]),a.useEffect(()=>{let g=!1;return j(!0),Hs(s.id,d).then(f=>{if(g)return;const h=f.length>0&&f[0]?.id===s.id?[...f].reverse():f;N(h)}).catch(()=>{g||N([])}).finally(()=>{g||j(!1)}),()=>{g=!0}},[s.id,d]);const R=a.useMemo(()=>{const g=s.completedRuns||[],f=new Date;f.setHours(0,0,0,0);const h=g.filter(_=>new Date(_.startedAt)>=f),C=g.filter(_=>_.status==="completed");return{totalRuns:g.length,todayRuns:h.length,successfulRuns:C.length,successRate:g.length>0?Math.round(C.length/g.length*100):0}},[s]);return e.jsxs("div",{className:"dashboard-tab",children:[b?.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(g=>e.jsx("span",{className:"skill-badge",children:g},g))}):"—"})]}),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:c.bg,color:c.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:t.color},title:t.label,children:t.stateDerived?t.icon:t.label})]}),x&&e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Model"}),e.jsx("span",{className:"info-value",children:x})]}),b?.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:b.isOverBudget?"var(--state-error-bg, rgba(248,81,73,0.15))":b.isOverThreshold?"var(--state-paused-bg, rgba(227,181,65,0.15))":"var(--state-active-bg, rgba(63,185,80,0.15))",color:b.isOverBudget?"var(--state-error-text, #f85149)":b.isOverThreshold?"var(--state-paused-text, #e3b541)":"var(--state-active-text, #3fb950)",border:`1px solid ${b.isOverBudget?"var(--state-error-border, #f85149)":b.isOverThreshold?"var(--state-paused-border, #e3b541)":"var(--state-active-border, #3fb950)"}`},children:b.isOverBudget?"⚠ Budget Exhausted":`${Math.round(b.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?fe(s.lastHeartbeatAt):"Never"})]}),(()=>{if(!(s.state==="active"||s.state==="running")||!s.lastHeartbeatAt)return null;const f=Vs(s.runtimeConfig?.heartbeatIntervalMs),h=new Date(new Date(s.lastHeartbeatAt).getTime()+f);return e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Next Heartbeat"}),e.jsx("span",{className:"info-value",title:h.toLocaleString(),children:fe(h.toISOString())})]})})()]})]}),e.jsxs("div",{className:"dashboard-section",children:[e.jsxs("h3",{children:[e.jsx(ze,{size:16,style:{marginRight:"6px",verticalAlign:"-2px"}}),"Chain of Command"]}),u?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((g,f)=>{const h=f===r.length-1,C=!h;return e.jsxs("div",{className:"chain-of-command-item",children:[e.jsx("button",{type:"button",className:`chain-of-command-node${h?" chain-of-command-node--current":""}`,onClick:()=>C&&i?.(g.id),disabled:!C||!i,title:h?"Current agent":`View ${g.name}`,children:g.name}),!h&&e.jsx("span",{className:"chain-of-command-separator","aria-hidden":"true",children:"→"})]},g.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:R.totalRuns}),e.jsx("div",{className:"stat-label",children:"Total Runs"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-value",children:R.todayRuns}),e.jsx("div",{className:"stat-label",children:"Runs Today"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsxs("div",{className:"stat-value",children:[R.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(fs,{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 Tt({logs:s,isStreaming:t,containerRef:i,hasTask:d}){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"]}),t&&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(Ce,{size:48,opacity:.3}),e.jsx("p",{children:"No log entries yet"}),e.jsx("p",{className:"text-muted",children:t?"Waiting for activity...":"Logs will appear here when the agent is active"})]}):s.map((c,r)=>{const N=r>0?s[r-1]:void 0,u=!N||N.agent!==c.agent;return e.jsx(At,{entry:c,showTimestamp:u},`${c.timestamp}-${r}`)})})]}):e.jsx("div",{className:"logs-tab",children:e.jsxs("div",{className:"logs-empty",children:[e.jsx(Ce,{size:48,opacity:.3}),e.jsx("p",{children:"No task assigned"}),e.jsx("p",{className:"text-muted",children:"Agent logs are available when the agent is assigned to a task"})]})})}function At({entry:s,showTimestamp:t}){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)"}}})(),c=new Date(s.timestamp).toLocaleTimeString();return e.jsxs("div",{className:"log-entry",style:d,children:[t&&e.jsxs("span",{className:"log-timestamp",children:["[",c,"]"]}),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 Lt({addToast:s,agentId:t,projectId:i,agentState:d,agentName:c}){const[r,N]=a.useState([]),[u,j]=a.useState(!0),[b,k]=a.useState(null),[x,R]=a.useState([]),[g,f]=a.useState(!1),[h,C]=a.useState(null),[_,G]=a.useState(!1),P=a.useCallback(async()=>{try{const o=await Us(t,50,i);N(o)}catch(o){s(`Failed to load runs: ${W(o)}`,"error")}finally{j(!1)}},[t,i,s]);a.useEffect(()=>{P()},[P]);const M=r.some(o=>o.status==="active");a.useEffect(()=>{if(!M)return;const o=setInterval(()=>{P()},5e3);return()=>clearInterval(o)},[M,P]);const E=a.useCallback(async o=>{if(b===o){k(null),R([]),C(null);return}k(o),f(!0),G(!0),R([]),C(null);try{const[D,m]=await Promise.all([Js(t,o,i),Ws(t,o,i)]);R(D),C(m)}catch(D){s(`Failed to load run details: ${W(D)}`,"error"),R([]),C(null)}finally{f(!1),G(!1)}},[b,t,i,s]),z=async()=>{try{await st(t,i,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${c??t}`,"success"),j(!0),P()}catch(o){s(`Failed to start heartbeat run: ${W(o)}`,"error")}},F=async()=>{if(confirm("Stop the active run? The agent's work will be interrupted."))try{await tt(t,i),s("Run stopped","success"),j(!0),P()}catch(o){s(`Failed to stop run: ${W(o)}`,"error")}},V=d==="active"||d==="idle";if(u&&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:[V&&e.jsx("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border-color)"},children:e.jsxs("button",{className:"btn btn--sm btn--primary",onClick:()=>void z(),"aria-label":`Run now for ${c??t}`,children:[e.jsx(Ne,{size:14})," Run Now"]})}),e.jsxs("div",{className:"runs-empty",children:[e.jsx(Ne,{size:48,opacity:.3}),e.jsx("p",{children:"No runs yet"}),e.jsx("p",{className:"text-muted",children:"Heartbeat runs will appear here"})]})]});const q=[...r].sort((o,D)=>new Date(D.startedAt).getTime()-new Date(o.startedAt).getTime()),S=q.filter(o=>o.status==="active"),H=q.filter(o=>o.status!=="active"),p=o=>o?e.jsxs("div",{style:{fontSize:"12px",color:"var(--text-secondary)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[e.jsxs("span",{children:["Input: ",o.inputTokens.toLocaleString()]}),e.jsxs("span",{children:["Output: ",o.outputTokens.toLocaleString()]}),o.cachedTokens>0&&e.jsxs("span",{children:["Cached: ",o.cachedTokens.toLocaleString()]})]}):null,B=(o,D,m)=>{const I=cs[o.status]||cs.completed,l=I.icon,y=o.endedAt?Dt(new Date(o.startedAt),new Date(o.endedAt)):"In progress",$=b===o.id;return e.jsxs("div",{children:[e.jsxs("div",{className:Q("run-card",m&&"run-card--active",$&&"run-card--selected"),onClick:()=>void E(o.id),style:{cursor:"pointer"},role:"button",tabIndex:0,"aria-expanded":$,"aria-label":`${m?"Active":""} run ${o.id.slice(0,8)}, ${o.status}`,onKeyDown:U=>{(U.key==="Enter"||U.key===" ")&&(U.preventDefault(),E(o.id))},children:[e.jsxs("div",{className:"run-header",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[$?e.jsx(hs,{size:14}):e.jsx(gs,{size:14}),m?e.jsxs("span",{className:"run-live-indicator",children:[e.jsx("span",{className:"live-dot"}),"Live Run"]}):e.jsxs("span",{className:"run-id",children:["#",D+1," ",o.id.slice(0,8)]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[o.invocationSource&&e.jsx("span",{className:"badge",style:{fontSize:"10px",padding:"1px 6px"},children:o.invocationSource}),m&&e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:U=>{U.preventDefault(),U.stopPropagation(),F()},"aria-label":"Stop active run",children:[e.jsx(ge,{size:12})," Stop"]}),e.jsxs("span",{className:Q("run-status",o.status),children:[e.jsx(l,{size:14,className:I.color,style:o.status==="active"?{color:I.color}:void 0}),o.status]})]})]}),e.jsxs("div",{className:"run-details",children:[e.jsxs("span",{children:["Started ",fe(o.startedAt)]}),e.jsx("span",{children:"•"}),e.jsx("span",{children:y}),o.triggerDetail&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{className:"text-muted",children:o.triggerDetail})]})]})]}),$&&e.jsxs("div",{className:"run-logs-container",style:{padding:"12px",background:"var(--bg-secondary)",borderBottom:"1px solid var(--border-color)",borderTop:"1px solid var(--border-color)"},children:[_?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 0"},children:[e.jsx(O,{size:14,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading details..."})]}):h&&e.jsxs("div",{style:{marginBottom:"12px"},children:[h.usageJson&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Token Usage"}),p(h.usageJson)]}),h.stdoutExcerpt&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Output"}),e.jsx("pre",{style:{background:"var(--bg-tertiary, #161b22)",padding:"8px 12px",borderRadius:"6px",fontSize:"12px",maxHeight:"200px",overflow:"auto",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:h.stdoutExcerpt.length>2e3?`${h.stdoutExcerpt.slice(0,2e3)}
|
|
27
22
|
|
|
28
|
-
... (truncated, ${h.stdoutExcerpt.length} chars total)`:h.stdoutExcerpt})]}),h.stderrExcerpt&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--color-error, #f85149)",marginBottom:"4px"},children:"Errors"}),e.jsx("pre",{style:{background:"rgba(248, 81, 73, 0.1)",color:"var(--color-error, #f85149)",padding:"8px 12px",borderRadius:"6px",fontSize:"12px",maxHeight:"200px",overflow:"auto",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:h.stderrExcerpt})]}),h.resultJson&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Result"}),e.jsx("pre",{style:{background:"var(--bg-tertiary, #161b22)",padding:"8px 12px",borderRadius:"6px",fontSize:"12px",maxHeight:"200px",overflow:"auto",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(h.resultJson,null,2)})]}),h.contextSnapshot&&Object.keys(h.contextSnapshot).length>0&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Context"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 12px",fontSize:"12px"},children:Object.entries(h.contextSnapshot).map(([U,te])=>e.jsxs("span",{children:[e.jsxs("span",{className:"text-muted",children:[U,":"]})," ",e.jsx("span",{children:String(te)})]},U))})]}),!h.stdoutExcerpt&&!h.stderrExcerpt&&!h.resultJson&&e.jsx("div",{className:"text-muted",style:{padding:"8px 0",fontStyle:"italic",fontSize:"12px"},children:"No output captured"})]}),e.jsxs("div",{style:{borderTop:"1px solid var(--border-color)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Agent Logs"}),g?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 0"},children:[e.jsx(O,{size:14,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading logs..."})]}):x.length===0?e.jsx("div",{className:"text-muted",style:{padding:"8px 0",fontStyle:"italic"},children:"No logs available for this run"}):e.jsx(nt,{entries:x,loading:!1})]})]})]},o.id)};return e.jsxs("div",{className:"runs-tab",children:[V&&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 F(),"aria-label":`Stop active run for ${c??t}`,children:[e.jsx(ge,{size:14})," Stop Run"]}),e.jsxs("button",{className:"btn btn--sm btn--primary",onClick:()=>void E(),"aria-label":`Run now for ${c??t}`,children:[e.jsx(Se,{size:14})," Run Now"]})]})]}),S.map((o,D)=>B(o,D,!0)),H.map((o,D)=>B(o,S.length+D,!1))]})}function zt(s,t){const i=Math.floor((t.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 Et={triage:"Triage",todo:"Todo","in-progress":"In Progress","in-review":"In Review",done:"Done",archived:"Archived"};function $t(s){const t=s.title?.trim()||s.description?.trim()||s.id;return t.length>80?`${t.slice(0,77)}...`:t}function Pt({agentId:s,projectId:t,addToast:i}){const[d,c]=a.useState([]),[r,N]=a.useState(!0);return a.useEffect(()=>{let u=!1;return N(!0),qs(s,t).then(j=>{u||c(j)}).catch(j=>{u||(c([]),i(`Failed to load assigned tasks: ${W(j)}`,"error"))}).finally(()=>{u||N(!1)}),()=>{u=!0}},[s,t,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(xs,{size:18}),e.jsx("p",{children:"No tasks assigned to this agent"})]}):e.jsx("div",{className:"agent-tasks-list",children:d.map(u=>e.jsxs("a",{className:"agent-task-item",href:`/tasks/${u.id}`,children:[e.jsxs("div",{className:"agent-task-row",children:[e.jsx("span",{className:"agent-task-id",children:u.id}),e.jsx("span",{className:`agent-task-column column-${u.column}`,children:Et[u.column]})]}),e.jsx("div",{className:"agent-task-title",title:u.title||u.description||u.id,children:$t(u)}),e.jsxs("div",{className:"agent-task-status",children:[u.status??"idle"," · Updated ",fe(u.updatedAt)]})]},u.id))})}const he=[{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 Bt(s){const t={};for(const i of he){const d=s[i.key]?.trim();if(d){if(i.type==="number"){const c=Number(d);if(Number.isNaN(c)||!Number.isFinite(c)){t[i.key]=`"${i.label}" must be a valid number`;continue}i.min!==void 0&&c<i.min&&(t[i.key]=`"${i.label}" must be at least ${i.min.toLocaleString()}`),i.max!==void 0&&c>i.max&&(t[i.key]=`"${i.label}" must be at most ${i.max.toLocaleString()}`)}if(i.type==="select"){const c=i.options?.map(r=>r.value)??[];c.length>0&&!c.includes(d)&&(t[i.key]=`"${i.label}" must be one of: ${c.join(", ")}`)}}}return t}function It({agent:s,projectId:t,addToast:i,onSaved:d}){const[c,r]=a.useState(s.soul??""),[N,u]=a.useState(!1),[j,b]=a.useState(!1),[k,x]=a.useState(!1);a.useEffect(()=>{r(s.soul??""),b(!1),x(!1)},[s.id,s.soul]);const R=c!==(s.soul??""),g=async()=>{if(c.length>1e4){i("Soul must be at most 10,000 characters","error");return}u(!0);try{await it(s.id,c,t),i("Soul saved","success"),b(!0),setTimeout(()=>b(!1),3e3),await d()}catch(f){i(`Failed to save soul: ${W(f)}`,"error")}finally{u(!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 ${k?"":"btn-primary"}`,onClick:()=>x(!1),disabled:!k,"aria-label":"Edit mode",children:[e.jsx($e,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${k?"btn-primary":""}`,onClick:()=>x(!0),disabled:k,"aria-label":"Preview mode",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),k?c.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(Be,{remarkPlugins:[Ie],children:c})}):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:c,onChange:f=>{r(f.target.value),b(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!k&&e.jsx("span",{className:"config-hint",children:"Defines the agent's character and identity. Max 10,000 characters."})]})}),!k&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn--primary",disabled:!R||N,onClick:()=>void g(),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"]})}),!R&&j&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Soul saved"]})]})]})})}function Ot({agent:s,projectId:t,addToast:i,onSaved:d}){const[c,r]=a.useState(s.memory??""),[N,u]=a.useState(!1),[j,b]=a.useState(!1),[k,x]=a.useState(!1),[R,g]=a.useState([]),[f,h]=a.useState(!1),[C,_]=a.useState(""),[q,P]=a.useState(""),[M,z]=a.useState(!1),[E,F]=a.useState(!1),[V,G]=a.useState(!1),[S,H]=a.useState(!1),[p,B]=a.useState(""),o=s.state==="running",D=c!==(s.memory??""),m=a.useMemo(()=>R.find(L=>L.path===C),[R,C]),I=m?Rt[m.layer]:"Select a memory file to view or edit.",l=a.useCallback(async L=>{F(!0);try{const ee=await Ys(s.id,L,t);_(ee.path),P(ee.content),z(!1),H(!1)}catch(ee){i(`Failed to load agent memory file: ${W(ee)}`,"error")}finally{F(!1)}},[s.id,t,i]),y=a.useCallback(async(L="")=>{h(!0);try{const{files:ee}=await Zs(s.id,t);if(g(ee),ee.length===0){_(""),P(""),z(!1);return}const pe=Ft(ee,L);await l(pe)}catch(ee){i(`Failed to load memory files: ${W(ee)}`,"error"),g([]),_(""),P(""),z(!1)}finally{h(!1)}},[s.id,t,i,l]);a.useEffect(()=>{r(s.memory??""),b(!1),x(!1),B(""),H(!1),y()},[s.id,s.memory,y]);const $=async()=>{if(c.length>5e4){i("Memory must be at most 50,000 characters","error");return}u(!0);try{await ot(s.id,c,t),i("Memory saved","success"),b(!0),setTimeout(()=>b(!1),3e3),await d()}catch(L){i(`Failed to save memory: ${W(L)}`,"error")}finally{u(!1)}},U=async L=>{if(!(!L||L===C)){if(M){B("Save the current file before switching to another file.");return}B(""),await l(L)}},te=async()=>{if(C){G(!0);try{await ct(s.id,C,q,t),z(!1),H(!0),setTimeout(()=>H(!1),3e3),B(""),await y(C),i("Agent memory file saved","success")}catch(L){i(`Failed to save agent memory file: ${W(L)}`,"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."}),o&&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:[!o&&e.jsxs("button",{className:`btn btn-sm ${k?"":"btn-primary"}`,onClick:()=>x(!1),disabled:!k,"aria-label":"Edit mode",children:[e.jsx($e,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${k?"btn-primary":""}`,onClick:()=>x(!0),disabled:k,"aria-label":"Preview mode",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),k?c.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(Be,{remarkPlugins:[Ie],children:c})}):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:c,readOnly:o,onChange:L=>{r(L.target.value),b(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!k&&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:C,disabled:f||E||V||R.length===0,onChange:L=>{U(L.target.value)},children:R.length===0?e.jsx("option",{value:"",children:"No memory files found"}):R.map(L=>e.jsxs("option",{value:L.path,children:[ds[L.layer]," • ",L.label]},L.path))}),f&&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…"]}),m&&e.jsxs("div",{className:"config-hint",style:{marginTop:8},children:[e.jsx("strong",{children:ds[m.layer]})," · ",I,e.jsx("br",{}),m.size.toLocaleString()," bytes · Updated ",fe(m.updatedAt)]}),e.jsx("textarea",{className:"input",rows:14,placeholder:"Select a memory file to view and edit its content...",value:q,readOnly:o||!C||E,onChange:L=>{P(L.target.value),z(!0),H(!1),B("")},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical",marginTop:8}}),E&&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…"]}),p&&e.jsx("span",{className:"config-hint",style:{display:"block",marginTop:8},children:p})]})]}),e.jsxs("div",{className:"config-actions",children:[!k&&e.jsx("button",{className:"btn btn--primary",disabled:!D||N||o,onClick:()=>void $(),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:!M||V||!C||o,onClick:()=>void te(),children:V?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"]})}),!D&&j&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Memory saved"]}),!M&&S&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Memory file saved"]})]})]})})}function _t({agent:s,projectId:t,addToast:i,onSaved:d}){const[c,r]=a.useState(s.instructionsText??""),[N,u]=a.useState(s.instructionsPath??""),[j,b]=a.useState(!1),[k,x]=a.useState(""),[R,g]=a.useState(!1),[f,h]=a.useState(!1),[C,_]=a.useState(!1),[q,P]=a.useState(!1),[M,z]=a.useState(!1),[E,F]=a.useState(!1);a.useEffect(()=>{const p=N.trim();if(!p){x(""),h(!1);return}g(!0),Ks("project",p).then(B=>{x(B.content),h(!1)}).catch(B=>{const o=W(B);o.includes("ENOENT")||o.includes("Not found")||o.includes("not found")?(x(""),h(!1)):(i(`Failed to load instructions file: ${o}`,"error"),x(""))}).finally(()=>{g(!1)})},[N,i]),a.useEffect(()=>{r(s.instructionsText??""),u(s.instructionsPath??""),z(!1),F(!1),b(!1)},[s.id,s.instructionsText,s.instructionsPath]);const V=(()=>{const p=c??"",B=s.instructionsText??"",o=N?.trim()??"",D=s.instructionsPath?.trim()??"";return p!==B||o!==D})(),G=async()=>{_(!0);try{await rt(s.id,{instructionsText:c||void 0,instructionsPath:N.trim()||void 0},t),i("Instructions saved","success"),z(!0),setTimeout(()=>z(!1),3e3),await d()}catch(p){i(`Failed to save instructions: ${W(p)}`,"error")}finally{_(!1)}},S=async()=>{const p=N.trim();if(!p){i("No instructions file path set","error");return}P(!0);try{await lt("project",p,k),i("Instructions file saved","success"),h(!1),F(!0),setTimeout(()=>F(!1),3e3)}catch(B){i(`Failed to save instructions file: ${W(B)}`,"error")}finally{P(!1)}},H=!!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 ${j?"":"btn-primary"}`,onClick:()=>b(!1),disabled:!j,"aria-label":"Edit mode","data-testid":"instructions-edit-toggle",children:[e.jsx($e,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${j?"btn-primary":""}`,onClick:()=>b(!0),disabled:j,"aria-label":"Preview mode","data-testid":"instructions-preview-toggle",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),j?c.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(Be,{remarkPlugins:[Ie],children:c})}):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:c,onChange:p=>{r(p.target.value),z(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!j&&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:p=>{u(p.target.value),z(!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."})]})]}),!j&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn--primary",disabled:!V||C,onClick:()=>void G(),children:C?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"]})}),!V&&M&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Instructions saved"]})]})]}),H&&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"}),R&&e.jsxs("span",{className:"config-hint",style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(O,{size:12,className:"animate-spin"}),"Loading..."]}),f&&!R&&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:k,readOnly:R,onChange:p=>{x(p.target.value),h(!0),F(!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--primary",disabled:!f||q,onClick:()=>void S(),children:q?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"]})}),!f&&E&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"File saved"]})]})]})]})}function us(s){const t=s??{},i={};return t.heartbeatIntervalMs!==void 0&&t.heartbeatIntervalMs!==null&&(i.heartbeatIntervalMs=String(Number(t.heartbeatIntervalMs)/1e3)),t.heartbeatTimeoutMs!==void 0&&t.heartbeatTimeoutMs!==null&&(i.heartbeatTimeoutMs=String(Number(t.heartbeatTimeoutMs)/1e3)),t.maxConcurrentRuns!==void 0&&t.maxConcurrentRuns!==null&&(i.maxConcurrentRuns=String(t.maxConcurrentRuns)),(t.messageResponseMode==="immediate"||t.messageResponseMode==="on-heartbeat")&&(i.messageResponseMode=t.messageResponseMode),i}function Ae(s){return s?.enabled!==!1}function ms(s){const t=(s??{}).budgetConfig,i={};return t&&(t.tokenBudget!==void 0&&t.tokenBudget!==null&&(i.tokenBudget=String(t.tokenBudget)),t.usageThreshold!==void 0&&t.usageThreshold!==null&&(i.usageThreshold=String(Number(t.usageThreshold)*100)),t.budgetPeriod!==void 0&&t.budgetPeriod!==null&&(i.budgetPeriod=String(t.budgetPeriod)),t.resetDay!==void 0&&t.resetDay!==null&&(i.resetDay=String(t.resetDay))),i}function Ht({agent:s,projectId:t,addToast:i,onSaved:d,onHasChangesChange:c,onDelete:r}){const[N,u]=a.useState(s.name),[j,b]=a.useState(s.role),[k,x]=a.useState(s.title??""),[R,g]=a.useState(s.icon??""),[f,h]=a.useState(s.reportsTo??""),[C,_]=a.useState([]),[q,P]=a.useState(!1),[M,z]=a.useState(()=>{const n={};for(const w of he){const A=s.metadata[w.key];A!=null&&(n[w.key]=String(A))}return n}),[E,F]=a.useState(()=>us(s.runtimeConfig)),[V,G]=a.useState(()=>Ae(s.runtimeConfig)),[S,H]=a.useState(()=>ms(s.runtimeConfig)),[p,B]=a.useState(s.bundleConfig?.mode??""),[o,D]=a.useState(s.bundleConfig?.entryFile??"AGENTS.md"),[m,I]=a.useState(s.bundleConfig?.externalPath??""),[l,y]=a.useState(s.bundleConfig?.files??[]),[$,U]=a.useState(Array.isArray(s.metadata?.skills)?s.metadata.skills:[]),[te,L]=a.useState([]),[ee,pe]=a.useState(!1),_e=(()=>{const n=s.runtimeConfig??{};return n.modelProvider&&n.modelId?`${n.modelProvider}/${n.modelId}`:typeof n.model=="string"&&n.model.includes("/")?n.model:""})(),[re,vs]=a.useState(_e),ve=f.trim(),He=a.useMemo(()=>C.filter(n=>n.id!==s.id),[C,s.id]),bs=!!ve&&!He.some(n=>n.id===ve);a.useEffect(()=>{let n=!1;return P(!0),Qs(void 0,t).then(w=>{n||_(w)}).catch(()=>{n||_([])}).finally(()=>{n||P(!1)}),()=>{n=!0}},[t]),a.useEffect(()=>{pe(!0),Xs().then(n=>L(n.models)).catch(()=>{}).finally(()=>pe(!1))},[]);const[ae,Re]=a.useState(null),[Ve,Ue]=a.useState(!1);a.useEffect(()=>{Le(s.id,t).then(Re).catch(()=>Re(null))},[s.id,t]);const js=async()=>{Ue(!0);try{await ut(s.id,t),i("Budget usage reset successfully","success");const n=await Le(s.id,t);Re(n)}catch(n){i(`Failed to reset budget: ${W(n)}`,"error")}finally{Ue(!1)}},[Je,We]=a.useState(!1),[T,be]=a.useState({}),[ys,le]=a.useState(!1),qe=s.state==="idle"||s.state==="terminated",ce=a.useRef(null),Ge=a.useRef(null);a.useEffect(()=>()=>{ce.current&&clearTimeout(ce.current)},[]);const ne=(()=>{if(N!==s.name||j!==s.role||k!==(s.title??"")||R!==(s.icon??"")||f!==(s.reportsTo??"")||p!==(s.bundleConfig?.mode??"")||o!==(s.bundleConfig?.entryFile??"AGENTS.md")||m!==(s.bundleConfig?.externalPath??"")||JSON.stringify(l)!==JSON.stringify(s.bundleConfig?.files??[]))return!0;for(const J of he){const ie=M[J.key]?.trim()??"",K=s.metadata[J.key]!==void 0&&s.metadata[J.key]!==null?String(s.metadata[J.key]):"";if(ie!==K)return!0}const n=s.runtimeConfig??{};if(V!==Ae(s.runtimeConfig))return!0;for(const J of["heartbeatIntervalMs","heartbeatTimeoutMs","maxConcurrentRuns","messageResponseMode"]){const ie=E[J]?.trim()??"";let K=n[J]!==void 0&&n[J]!==null?String(n[J]):"";if((J==="heartbeatIntervalMs"||J==="heartbeatTimeoutMs")&&K&&(K=String(Number(K)/1e3)),ie!==K)return!0}const w=n.budgetConfig;for(const J of["tokenBudget","budgetPeriod","resetDay"]){const ie=S[J]?.trim()??"",K=w?.[J]!==void 0&&w?.[J]!==null?String(w[J]):"";if(ie!==K)return!0}const A=S.usageThreshold?.trim()??"",Q=w?.usageThreshold!==void 0&&w?.usageThreshold!==null?String(Number(w.usageThreshold)*100):"";if(A!==Q)return!0;const de=Array.isArray(s.metadata?.skills)?s.metadata.skills:[];return JSON.stringify($)!==JSON.stringify(de)||re!==_e})(),Ke=a.useRef(null);a.useEffect(()=>{c&&Ke.current!==ne&&(Ke.current=ne,c(ne))},[ne,c]),a.useEffect(()=>()=>{c?.(!1)},[c]),a.useEffect(()=>{const n={id:s.id,updatedAt:s.updatedAt},w=Ge.current;(!w||w.id!==n.id||w.updatedAt!==n.updatedAt)&&(ne||(Ge.current=n,F(us(s.runtimeConfig)),G(Ae(s.runtimeConfig)),H(ms(s.runtimeConfig))))},[s,ne]);const Ye=(n,w)=>{z(A=>({...A,[n]:w})),le(!1),T[n]&&be(A=>{const Q={...A};return delete Q[n],Q})},je=(n,w)=>{F(A=>({...A,[n]:w})),le(!1),T[n]&&be(A=>{const Q={...A};return delete Q[n],Q})},Ns=n=>{G(n),le(!1)},ye=(n,w)=>{H(A=>({...A,[n]:w})),le(!1),T[n]&&be(A=>{const Q={...A};return delete Q[n],Q})},Ss=async()=>{const n=Bt(M);for(const[v,se]of Object.entries({heartbeatIntervalMs:{label:"Heartbeat Interval",min:1},heartbeatTimeoutMs:{label:"Heartbeat Timeout",min:5},maxConcurrentRuns:{label:"Max Concurrent Runs",min:1}})){const ue=E[v]?.trim();if(!ue)continue;const Fe=Number(ue);Number.isNaN(Fe)||!Number.isFinite(Fe)?n[v]=`"${se.label}" must be a valid number`:Fe<se.min&&(n[v]=`"${se.label}" must be at least ${se.min.toLocaleString()}`)}const w=E.messageResponseMode?.trim();w&&!["immediate","on-heartbeat"].includes(w)&&(n.messageResponseMode='"Message Response Mode" must be either immediate or on-heartbeat');const A=S.tokenBudget?.trim();if(A){const v=Number(A);Number.isNaN(v)||!Number.isFinite(v)?n.tokenBudget='"Token Budget" must be a valid number':v<=0&&(n.tokenBudget='"Token Budget" must be greater than 0')}const Q=S.usageThreshold?.trim();if(Q){const v=Number(Q);Number.isNaN(v)||!Number.isFinite(v)?n.usageThreshold='"Usage Threshold" must be a valid number':(v<1||v>100)&&(n.usageThreshold='"Usage Threshold" must be between 1 and 100')}const de=S.budgetPeriod?.trim();de&&!["daily","weekly","monthly","lifetime"].includes(de)&&(n.budgetPeriod='"Budget Period" must be one of: daily, weekly, monthly, lifetime');const J=S.resetDay?.trim(),ie=de||"lifetime";if(J){const v=Number(J);Number.isNaN(v)||!Number.isFinite(v)?n.resetDay='"Reset Day" must be a valid number':ie==="weekly"?(v<0||v>6||!Number.isInteger(v))&&(n.resetDay='"Reset Day" must be between 0 (Sunday) and 6 (Saturday) for weekly period'):ie==="monthly"&&(v<1||v>31||!Number.isInteger(v))&&(n.resetDay='"Reset Day" must be between 1 and 31 for monthly period')}if(Object.keys(n).length>0){be(n),i("Please fix validation errors before saving","error");return}const K={...s.metadata};for(const v of he){const se=M[v.key]?.trim();se?v.type==="number"?K[v.key]=Number(se):K[v.key]=se:delete K[v.key]}$.length>0?K.skills=$:delete K.skills;const Y={...s.runtimeConfig};Y.enabled=V;for(const v of["heartbeatIntervalMs","heartbeatTimeoutMs","maxConcurrentRuns"]){const se=E[v]?.trim();if(!se)delete Y[v];else{const ue=Number(se);Y[v]=v==="maxConcurrentRuns"?ue:ue*1e3}}const Ze=E.messageResponseMode?.trim();if(Ze?Y.messageResponseMode=Ze:delete Y.messageResponseMode,re.trim()){const v=re.indexOf("/");v!==-1&&(Y.modelProvider=re.slice(0,v),Y.modelId=re.slice(v+1),Y.model=re.trim())}else delete Y.modelProvider,delete Y.modelId,delete Y.model;const oe={},Qe=S.tokenBudget?.trim(),Xe=S.usageThreshold?.trim(),es=S.budgetPeriod?.trim(),ss=S.resetDay?.trim();Qe&&(oe.tokenBudget=Number(Qe)),Xe&&(oe.usageThreshold=Number(Xe)/100),es&&(oe.budgetPeriod=es),ss&&(oe.resetDay=Number(ss)),Object.keys(oe).length>0?Y.budgetConfig=oe:delete Y.budgetConfig;let Me;p&&(Me={mode:p,entryFile:o||"AGENTS.md",files:l.length>0?l:["AGENTS.md"]},p==="external"&&m.trim()&&(Me.externalPath=m.trim())),We(!0);try{await mt(s.id,{name:N.trim()||void 0,role:j,title:k.trim()||void 0,icon:R.trim()||void 0,reportsTo:f.trim()||void 0,metadata:K,runtimeConfig:Y,bundleConfig:Me},t),i("Settings saved","success"),le(!0),ce.current&&clearTimeout(ce.current),ce.current=setTimeout(()=>le(!1),3e3),await d()}catch(v){i(`Failed to save settings: ${W(v)}`,"error")}finally{We(!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=>u(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:j,onChange:n=>b(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:k,onChange:n=>x(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:R,onChange:n=>g(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:f,onChange:n=>h(n.target.value),disabled:q,children:[e.jsx("option",{value:"",children:"No manager"}),bs&&e.jsxs("option",{value:ve,children:["Unknown manager (",ve,")"]}),He.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(ht,{id:"agent-skills",label:"Skills",value:$,onChange:U,projectId:t})})})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Model"}),e.jsx("p",{className:"config-description",children:"Override the AI model used by this agent. Leave empty to use the global default model."}),e.jsx("div",{className:"config-fields",children:e.jsx("div",{className:"config-field",children:e.jsx(et,{models:te,value:re,onChange:vs,placeholder:"Use global default",label:"Agent Model",disabled:ee})})})]}),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:V,onChange:n=>Ns(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:Z("input",!!T.heartbeatIntervalMs&&"input--error"),placeholder:String(De/1e3),value:E.heartbeatIntervalMs??"",onChange:n=>je("heartbeatIntervalMs",n.target.value)}),T.heartbeatIntervalMs?e.jsx("span",{className:"config-error",children:T.heartbeatIntervalMs}):e.jsxs("span",{className:"config-hint",children:["How often heartbeats are checked. Leave empty for system default (",De/1e3,"s / ",Mt,")."]})]}),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:Z("input",!!T.heartbeatTimeoutMs&&"input--error"),placeholder:"60",value:E.heartbeatTimeoutMs??"",onChange:n=>je("heartbeatTimeoutMs",n.target.value)}),T.heartbeatTimeoutMs?e.jsx("span",{className:"config-error",children:T.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:Z("input",!!T.maxConcurrentRuns&&"input--error"),placeholder:"1",value:E.maxConcurrentRuns??"",onChange:n=>je("maxConcurrentRuns",n.target.value)}),T.maxConcurrentRuns?e.jsx("span",{className:"config-error",children:T.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:Z("select",!!T.messageResponseMode&&"input--error"),value:E.messageResponseMode??"",onChange:n=>je("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"})]}),T.messageResponseMode?e.jsx("span",{className:"config-error",children:T.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:Z("input",!!T.tokenBudget&&"input--error"),placeholder:"No limit",value:S.tokenBudget??"",onChange:n=>ye("tokenBudget",n.target.value)}),T.tokenBudget?e.jsx("span",{className:"config-error",children:T.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:Z("input",!!T.usageThreshold&&"input--error"),placeholder:"80",value:S.usageThreshold??"",onChange:n=>ye("usageThreshold",n.target.value)}),T.usageThreshold?e.jsx("span",{className:"config-error",children:T.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:Z("select",!!T.budgetPeriod&&"input--error"),value:S.budgetPeriod??"",onChange:n=>ye("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"})]}),T.budgetPeriod?e.jsx("span",{className:"config-error",children:T.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:Z("input",!!T.resetDay&&"input--error"),placeholder:"Auto",value:S.resetDay??"",onChange:n=>ye("resetDay",n.target.value)}),T.resetDay?e.jsx("span",{className:"config-error",children:T.resetDay}):e.jsx("span",{className:"config-hint",children:S.budgetPeriod==="weekly"?"Day of week (0=Sunday to 6=Saturday) for reset.":S.budgetPeriod==="monthly"?"Day of month (1-31) for reset.":"Day for reset (weekly: 0-6, monthly: 1-31). Leave empty for automatic."})]}),ae?.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:Z("budget-progress-bar__fill",(ae.usagePercent??0)>=100?"budget-progress-bar__fill--red":(ae.usagePercent??0)>=80?"budget-progress-bar__fill--amber":"budget-progress-bar__fill--green"),style:{width:`${Math.min(ae.usagePercent??0,100)}%`}})}),e.jsxs("span",{className:"budget-progress-label",children:[(ae.currentUsage??0).toLocaleString()," / ",(ae.budgetLimit??0).toLocaleString()," tokens (",Math.round(ae.usagePercent??0),"% used)"]})]})]}),ae?.budgetLimit!=null&&e.jsx("div",{className:"config-field",children:e.jsx("button",{className:"btn btn-reset-budget",onClick:()=>void js(),disabled:Ve,children:Ve?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:14,className:"animate-spin"}),"Resetting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ze,{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:p,onChange:n=>B(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:[p==="managed"&&"Files will be stored in a system-managed directory within .fusion/agents/",p==="external"&&"Specify an external directory path for the instruction files",!p&&"Select a mode to enable instruction bundling"]})]}),p&&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:o,onChange:n=>D(n.target.value)}),e.jsx("span",{className:"config-hint",children:"Primary instructions file name (default: AGENTS.md)"})]}),p==="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:m,onChange:n=>I(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=>y(n.target.value.split(",").map(w=>w.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:he.map(n=>{const w=!!T[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:Z("select",w&&"input--error"),value:M[n.key]??"",onChange:A=>Ye(n.key,A.target.value),children:[e.jsx("option",{value:"",children:"System Default"}),n.options?.map(A=>e.jsx("option",{value:A.value,children:A.label},A.value))]}):e.jsx("input",{id:`adv-${n.key}`,type:"text",inputMode:n.type==="number"?"numeric":void 0,className:Z("input",w&&"input--error"),placeholder:n.placeholder,value:M[n.key]??"",onChange:A=>Ye(n.key,A.target.value)}),w&&e.jsx("span",{className:"config-error",children:T[n.key]}),!w&&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--primary",disabled:!ne||Je,onClick:()=>void Ss(),children:Je?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"]})}),!ne&&ys&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Settings saved"]})]})]}),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:!qe||!r,onClick:()=>void r?.(),children:[e.jsx(Ce,{size:16}),"Delete Agent"]}),e.jsx("span",{className:"config-danger-note",children:qe?"Deletion is permanent and cannot be undone.":`Agent deletion is only available when state is idle or terminated (current state: ${s.state}).`})]})})]})]})}function Vt({agentId:s,projectId:t,onChildClick:i}){const[d,c]=a.useState([]),[r,N]=a.useState(!0);return a.useEffect(()=>{N(!0),Gs(s,t).then(c).finally(()=>N(!1))},[s,t]),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(Ee,{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(u=>{const j=Oe[u.state];return e.jsxs("div",{className:"agent-tree__node agent-is-child",onClick:()=>i?.(u.id),role:"button",tabIndex:0,onKeyDown:b=>b.key==="Enter"&&i?.(u.id),style:{cursor:i?"pointer":"default"},children:[e.jsx("span",{className:"agent-tree__icon",children:u.icon??"🤖"}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:"agent-tree__badge",style:{background:j?.bg??"var(--state-idle-bg)",color:j?.text??"var(--state-idle-text)",border:`1px solid ${j?.border??"var(--state-idle-border)"}`},children:u.state})]},u.id)})})})]})}export{Yt as AgentDetailView};
|
|
23
|
+
... (truncated, ${h.stdoutExcerpt.length} chars total)`:h.stdoutExcerpt})]}),h.stderrExcerpt&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--color-error, #f85149)",marginBottom:"4px"},children:"Errors"}),e.jsx("pre",{style:{background:"rgba(248, 81, 73, 0.1)",color:"var(--color-error, #f85149)",padding:"8px 12px",borderRadius:"6px",fontSize:"12px",maxHeight:"200px",overflow:"auto",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:h.stderrExcerpt})]}),h.resultJson&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Result"}),e.jsx("pre",{style:{background:"var(--bg-tertiary, #161b22)",padding:"8px 12px",borderRadius:"6px",fontSize:"12px",maxHeight:"200px",overflow:"auto",margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(h.resultJson,null,2)})]}),h.contextSnapshot&&Object.keys(h.contextSnapshot).length>0&&e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Context"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 12px",fontSize:"12px"},children:Object.entries(h.contextSnapshot).map(([U,te])=>e.jsxs("span",{children:[e.jsxs("span",{className:"text-muted",children:[U,":"]})," ",e.jsx("span",{children:String(te)})]},U))})]}),!h.stdoutExcerpt&&!h.stderrExcerpt&&!h.resultJson&&e.jsx("div",{className:"text-muted",style:{padding:"8px 0",fontStyle:"italic",fontSize:"12px"},children:"No output captured"})]}),e.jsxs("div",{style:{borderTop:"1px solid var(--border-color)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,textTransform:"uppercase",color:"var(--text-secondary)",marginBottom:"4px"},children:"Agent Logs"}),g?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 0"},children:[e.jsx(O,{size:14,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading logs..."})]}):x.length===0?e.jsx("div",{className:"text-muted",style:{padding:"8px 0",fontStyle:"italic"},children:"No logs available for this run"}):e.jsx(nt,{entries:x,loading:!1})]})]})]},o.id)};return e.jsxs("div",{className:"runs-tab",children:[V&&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 F(),"aria-label":`Stop active run for ${c??t}`,children:[e.jsx(ge,{size:14})," Stop Run"]}),e.jsxs("button",{className:"btn btn--sm btn--primary",onClick:()=>void z(),"aria-label":`Run now for ${c??t}`,children:[e.jsx(Ne,{size:14})," Run Now"]})]})]}),S.map((o,D)=>B(o,D,!0)),H.map((o,D)=>B(o,S.length+D,!1))]})}function Dt(s,t){const i=Math.floor((t.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 Et={triage:"Triage",todo:"Todo","in-progress":"In Progress","in-review":"In Review",done:"Done",archived:"Archived"};function zt(s){const t=s.title?.trim()||s.description?.trim()||s.id;return t.length>80?`${t.slice(0,77)}...`:t}function $t({agentId:s,projectId:t,addToast:i}){const[d,c]=a.useState([]),[r,N]=a.useState(!0);return a.useEffect(()=>{let u=!1;return N(!0),Gs(s,t).then(j=>{u||c(j)}).catch(j=>{u||(c([]),i(`Failed to load assigned tasks: ${W(j)}`,"error"))}).finally(()=>{u||N(!1)}),()=>{u=!0}},[s,t,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(xs,{size:18}),e.jsx("p",{children:"No tasks assigned to this agent"})]}):e.jsx("div",{className:"agent-tasks-list",children:d.map(u=>e.jsxs("a",{className:"agent-task-item",href:`/tasks/${u.id}`,children:[e.jsxs("div",{className:"agent-task-row",children:[e.jsx("span",{className:"agent-task-id",children:u.id}),e.jsx("span",{className:`agent-task-column column-${u.column}`,children:Et[u.column]})]}),e.jsx("div",{className:"agent-task-title",title:u.title||u.description||u.id,children:zt(u)}),e.jsxs("div",{className:"agent-task-status",children:[u.status??"idle"," · Updated ",fe(u.updatedAt)]})]},u.id))})}const he=[{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 Pt(s){const t={};for(const i of he){const d=s[i.key]?.trim();if(d){if(i.type==="number"){const c=Number(d);if(Number.isNaN(c)||!Number.isFinite(c)){t[i.key]=`"${i.label}" must be a valid number`;continue}i.min!==void 0&&c<i.min&&(t[i.key]=`"${i.label}" must be at least ${i.min.toLocaleString()}`),i.max!==void 0&&c>i.max&&(t[i.key]=`"${i.label}" must be at most ${i.max.toLocaleString()}`)}if(i.type==="select"){const c=i.options?.map(r=>r.value)??[];c.length>0&&!c.includes(d)&&(t[i.key]=`"${i.label}" must be one of: ${c.join(", ")}`)}}}return t}function Bt({agent:s,projectId:t,addToast:i,onSaved:d}){const[c,r]=a.useState(s.soul??""),[N,u]=a.useState(!1),[j,b]=a.useState(!1),[k,x]=a.useState(!1);a.useEffect(()=>{r(s.soul??""),b(!1),x(!1)},[s.id,s.soul]);const R=c!==(s.soul??""),g=async()=>{if(c.length>1e4){i("Soul must be at most 10,000 characters","error");return}u(!0);try{await it(s.id,c,t),i("Soul saved","success"),b(!0),setTimeout(()=>b(!1),3e3),await d()}catch(f){i(`Failed to save soul: ${W(f)}`,"error")}finally{u(!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 ${k?"":"btn-primary"}`,onClick:()=>x(!1),disabled:!k,"aria-label":"Edit mode",children:[e.jsx($e,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${k?"btn-primary":""}`,onClick:()=>x(!0),disabled:k,"aria-label":"Preview mode",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),k?c.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(Be,{remarkPlugins:[Ie],children:c})}):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:c,onChange:f=>{r(f.target.value),b(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!k&&e.jsx("span",{className:"config-hint",children:"Defines the agent's character and identity. Max 10,000 characters."})]})}),!k&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn--primary",disabled:!R||N,onClick:()=>void g(),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"]})}),!R&&j&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Soul saved"]})]})]})})}function It({agent:s,projectId:t,addToast:i,onSaved:d}){const[c,r]=a.useState(s.memory??""),[N,u]=a.useState(!1),[j,b]=a.useState(!1),[k,x]=a.useState(!1),[R,g]=a.useState([]),[f,h]=a.useState(!1),[C,_]=a.useState(""),[G,P]=a.useState(""),[M,E]=a.useState(!1),[z,F]=a.useState(!1),[V,q]=a.useState(!1),[S,H]=a.useState(!1),[p,B]=a.useState(""),o=s.state==="running",D=c!==(s.memory??""),m=a.useMemo(()=>R.find(L=>L.path===C),[R,C]),I=m?wt[m.layer]:"Select a memory file to view or edit.",l=a.useCallback(async L=>{F(!0);try{const ee=await Ys(s.id,L,t);_(ee.path),P(ee.content),E(!1),H(!1)}catch(ee){i(`Failed to load agent memory file: ${W(ee)}`,"error")}finally{F(!1)}},[s.id,t,i]),y=a.useCallback(async(L="")=>{h(!0);try{const{files:ee}=await Qs(s.id,t);if(g(ee),ee.length===0){_(""),P(""),E(!1);return}const xe=Mt(ee,L);await l(xe)}catch(ee){i(`Failed to load memory files: ${W(ee)}`,"error"),g([]),_(""),P(""),E(!1)}finally{h(!1)}},[s.id,t,i,l]);a.useEffect(()=>{r(s.memory??""),b(!1),x(!1),B(""),H(!1),y()},[s.id,s.memory,y]);const $=async()=>{if(c.length>5e4){i("Memory must be at most 50,000 characters","error");return}u(!0);try{await ot(s.id,c,t),i("Memory saved","success"),b(!0),setTimeout(()=>b(!1),3e3),await d()}catch(L){i(`Failed to save memory: ${W(L)}`,"error")}finally{u(!1)}},U=async L=>{if(!(!L||L===C)){if(M){B("Save the current file before switching to another file.");return}B(""),await l(L)}},te=async()=>{if(C){q(!0);try{await ct(s.id,C,G,t),E(!1),H(!0),setTimeout(()=>H(!1),3e3),B(""),await y(C),i("Agent memory file saved","success")}catch(L){i(`Failed to save agent memory file: ${W(L)}`,"error")}finally{q(!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."}),o&&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:[!o&&e.jsxs("button",{className:`btn btn-sm ${k?"":"btn-primary"}`,onClick:()=>x(!1),disabled:!k,"aria-label":"Edit mode",children:[e.jsx($e,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${k?"btn-primary":""}`,onClick:()=>x(!0),disabled:k,"aria-label":"Preview mode",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),k?c.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(Be,{remarkPlugins:[Ie],children:c})}):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:c,readOnly:o,onChange:L=>{r(L.target.value),b(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!k&&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:C,disabled:f||z||V||R.length===0,onChange:L=>{U(L.target.value)},children:R.length===0?e.jsx("option",{value:"",children:"No memory files found"}):R.map(L=>e.jsxs("option",{value:L.path,children:[ds[L.layer]," • ",L.label]},L.path))}),f&&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…"]}),m&&e.jsxs("div",{className:"config-hint",style:{marginTop:8},children:[e.jsx("strong",{children:ds[m.layer]})," · ",I,e.jsx("br",{}),m.size.toLocaleString()," bytes · Updated ",fe(m.updatedAt)]}),e.jsx("textarea",{className:"input",rows:14,placeholder:"Select a memory file to view and edit its content...",value:G,readOnly:o||!C||z,onChange:L=>{P(L.target.value),E(!0),H(!1),B("")},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical",marginTop:8}}),z&&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…"]}),p&&e.jsx("span",{className:"config-hint",style:{display:"block",marginTop:8},children:p})]})]}),e.jsxs("div",{className:"config-actions",children:[!k&&e.jsx("button",{className:"btn btn--primary",disabled:!D||N||o,onClick:()=>void $(),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:!M||V||!C||o,onClick:()=>void te(),children:V?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"]})}),!D&&j&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Memory saved"]}),!M&&S&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Memory file saved"]})]})]})})}function Ot({agent:s,projectId:t,addToast:i,onSaved:d}){const[c,r]=a.useState(s.instructionsText??""),[N,u]=a.useState(s.instructionsPath??""),[j,b]=a.useState(!1),[k,x]=a.useState(""),[R,g]=a.useState(!1),[f,h]=a.useState(!1),[C,_]=a.useState(!1),[G,P]=a.useState(!1),[M,E]=a.useState(!1),[z,F]=a.useState(!1);a.useEffect(()=>{const p=N.trim();if(!p){x(""),h(!1);return}g(!0),Ks("project",p).then(B=>{x(B.content),h(!1)}).catch(B=>{const o=W(B);o.includes("ENOENT")||o.includes("Not found")||o.includes("not found")?(x(""),h(!1)):(i(`Failed to load instructions file: ${o}`,"error"),x(""))}).finally(()=>{g(!1)})},[N,i]),a.useEffect(()=>{r(s.instructionsText??""),u(s.instructionsPath??""),E(!1),F(!1),b(!1)},[s.id,s.instructionsText,s.instructionsPath]);const V=(()=>{const p=c??"",B=s.instructionsText??"",o=N?.trim()??"",D=s.instructionsPath?.trim()??"";return p!==B||o!==D})(),q=async()=>{_(!0);try{await rt(s.id,{instructionsText:c||void 0,instructionsPath:N.trim()||void 0},t),i("Instructions saved","success"),E(!0),setTimeout(()=>E(!1),3e3),await d()}catch(p){i(`Failed to save instructions: ${W(p)}`,"error")}finally{_(!1)}},S=async()=>{const p=N.trim();if(!p){i("No instructions file path set","error");return}P(!0);try{await lt("project",p,k),i("Instructions file saved","success"),h(!1),F(!0),setTimeout(()=>F(!1),3e3)}catch(B){i(`Failed to save instructions file: ${W(B)}`,"error")}finally{P(!1)}},H=!!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 ${j?"":"btn-primary"}`,onClick:()=>b(!1),disabled:!j,"aria-label":"Edit mode","data-testid":"instructions-edit-toggle",children:[e.jsx($e,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${j?"btn-primary":""}`,onClick:()=>b(!0),disabled:j,"aria-label":"Preview mode","data-testid":"instructions-preview-toggle",children:[e.jsx(Pe,{size:14}),"Preview"]})]})}),j?c.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(Be,{remarkPlugins:[Ie],children:c})}):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:c,onChange:p=>{r(p.target.value),E(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!j&&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:p=>{u(p.target.value),E(!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."})]})]}),!j&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn--primary",disabled:!V||C,onClick:()=>void q(),children:C?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"]})}),!V&&M&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Instructions saved"]})]})]}),H&&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"}),R&&e.jsxs("span",{className:"config-hint",style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(O,{size:12,className:"animate-spin"}),"Loading..."]}),f&&!R&&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:k,readOnly:R,onChange:p=>{x(p.target.value),h(!0),F(!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--primary",disabled:!f||G,onClick:()=>void S(),children:G?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"]})}),!f&&z&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"File saved"]})]})]})]})}function us(s){const t=s??{},i={};return t.heartbeatIntervalMs!==void 0&&t.heartbeatIntervalMs!==null&&(i.heartbeatIntervalMs=String(Number(t.heartbeatIntervalMs)/1e3)),t.heartbeatTimeoutMs!==void 0&&t.heartbeatTimeoutMs!==null&&(i.heartbeatTimeoutMs=String(Number(t.heartbeatTimeoutMs)/1e3)),t.maxConcurrentRuns!==void 0&&t.maxConcurrentRuns!==null&&(i.maxConcurrentRuns=String(t.maxConcurrentRuns)),(t.messageResponseMode==="immediate"||t.messageResponseMode==="on-heartbeat")&&(i.messageResponseMode=t.messageResponseMode),i}function Ae(s){return s?.enabled!==!1}function ms(s){const t=(s??{}).budgetConfig,i={};return t&&(t.tokenBudget!==void 0&&t.tokenBudget!==null&&(i.tokenBudget=String(t.tokenBudget)),t.usageThreshold!==void 0&&t.usageThreshold!==null&&(i.usageThreshold=String(Number(t.usageThreshold)*100)),t.budgetPeriod!==void 0&&t.budgetPeriod!==null&&(i.budgetPeriod=String(t.budgetPeriod)),t.resetDay!==void 0&&t.resetDay!==null&&(i.resetDay=String(t.resetDay))),i}function _t({agent:s,projectId:t,addToast:i,onSaved:d,onHasChangesChange:c,onDelete:r}){const[N,u]=a.useState(s.name),[j,b]=a.useState(s.role),[k,x]=a.useState(s.title??""),[R,g]=a.useState(s.icon??""),[f,h]=a.useState(s.reportsTo??""),[C,_]=a.useState([]),[G,P]=a.useState(!1),[M,E]=a.useState(()=>{const n={};for(const w of he){const A=s.metadata[w.key];A!=null&&(n[w.key]=String(A))}return n}),[z,F]=a.useState(()=>us(s.runtimeConfig)),[V,q]=a.useState(()=>Ae(s.runtimeConfig)),[S,H]=a.useState(()=>ms(s.runtimeConfig)),[p,B]=a.useState(s.bundleConfig?.mode??""),[o,D]=a.useState(s.bundleConfig?.entryFile??"AGENTS.md"),[m,I]=a.useState(s.bundleConfig?.externalPath??""),[l,y]=a.useState(s.bundleConfig?.files??[]),[$,U]=a.useState(Array.isArray(s.metadata?.skills)?s.metadata.skills:[]),[te,L]=a.useState([]),[ee,xe]=a.useState(!1),_e=(()=>{const n=s.runtimeConfig??{};return n.modelProvider&&n.modelId?`${n.modelProvider}/${n.modelId}`:typeof n.model=="string"&&n.model.includes("/")?n.model:""})(),[re,vs]=a.useState(_e),pe=f.trim(),He=a.useMemo(()=>C.filter(n=>n.id!==s.id),[C,s.id]),bs=!!pe&&!He.some(n=>n.id===pe);a.useEffect(()=>{let n=!1;return P(!0),Zs(void 0,t).then(w=>{n||_(w)}).catch(()=>{n||_([])}).finally(()=>{n||P(!1)}),()=>{n=!0}},[t]),a.useEffect(()=>{xe(!0),Xs().then(n=>L(n.models)).catch(()=>{}).finally(()=>xe(!1))},[]);const[ae,Re]=a.useState(null),[Ve,Ue]=a.useState(!1);a.useEffect(()=>{Le(s.id,t).then(Re).catch(()=>Re(null))},[s.id,t]);const js=async()=>{Ue(!0);try{await ut(s.id,t),i("Budget usage reset successfully","success");const n=await Le(s.id,t);Re(n)}catch(n){i(`Failed to reset budget: ${W(n)}`,"error")}finally{Ue(!1)}},[Je,We]=a.useState(!1),[T,ve]=a.useState({}),[ys,le]=a.useState(!1),Ge=s.state==="idle"||s.state==="terminated",ce=a.useRef(null),qe=a.useRef(null);a.useEffect(()=>()=>{ce.current&&clearTimeout(ce.current)},[]);const ne=(()=>{if(N!==s.name||j!==s.role||k!==(s.title??"")||R!==(s.icon??"")||f!==(s.reportsTo??"")||p!==(s.bundleConfig?.mode??"")||o!==(s.bundleConfig?.entryFile??"AGENTS.md")||m!==(s.bundleConfig?.externalPath??"")||JSON.stringify(l)!==JSON.stringify(s.bundleConfig?.files??[]))return!0;for(const J of he){const ie=M[J.key]?.trim()??"",K=s.metadata[J.key]!==void 0&&s.metadata[J.key]!==null?String(s.metadata[J.key]):"";if(ie!==K)return!0}const n=s.runtimeConfig??{};if(V!==Ae(s.runtimeConfig))return!0;for(const J of["heartbeatIntervalMs","heartbeatTimeoutMs","maxConcurrentRuns","messageResponseMode"]){const ie=z[J]?.trim()??"";let K=n[J]!==void 0&&n[J]!==null?String(n[J]):"";if((J==="heartbeatIntervalMs"||J==="heartbeatTimeoutMs")&&K&&(K=String(Number(K)/1e3)),ie!==K)return!0}const w=n.budgetConfig;for(const J of["tokenBudget","budgetPeriod","resetDay"]){const ie=S[J]?.trim()??"",K=w?.[J]!==void 0&&w?.[J]!==null?String(w[J]):"";if(ie!==K)return!0}const A=S.usageThreshold?.trim()??"",Z=w?.usageThreshold!==void 0&&w?.usageThreshold!==null?String(Number(w.usageThreshold)*100):"";if(A!==Z)return!0;const de=Array.isArray(s.metadata?.skills)?s.metadata.skills:[];return JSON.stringify($)!==JSON.stringify(de)||re!==_e})(),Ke=a.useRef(null);a.useEffect(()=>{c&&Ke.current!==ne&&(Ke.current=ne,c(ne))},[ne,c]),a.useEffect(()=>()=>{c?.(!1)},[c]),a.useEffect(()=>{const n={id:s.id,updatedAt:s.updatedAt},w=qe.current;(!w||w.id!==n.id||w.updatedAt!==n.updatedAt)&&(ne||(qe.current=n,F(us(s.runtimeConfig)),q(Ae(s.runtimeConfig)),H(ms(s.runtimeConfig))))},[s,ne]);const Ye=(n,w)=>{E(A=>({...A,[n]:w})),le(!1),T[n]&&ve(A=>{const Z={...A};return delete Z[n],Z})},be=(n,w)=>{F(A=>({...A,[n]:w})),le(!1),T[n]&&ve(A=>{const Z={...A};return delete Z[n],Z})},Ns=n=>{q(n),le(!1)},je=(n,w)=>{H(A=>({...A,[n]:w})),le(!1),T[n]&&ve(A=>{const Z={...A};return delete Z[n],Z})},Ss=async()=>{const n=Pt(M);for(const[v,se]of Object.entries({heartbeatIntervalMs:{label:"Heartbeat Interval",min:1},heartbeatTimeoutMs:{label:"Heartbeat Timeout",min:5},maxConcurrentRuns:{label:"Max Concurrent Runs",min:1}})){const ue=z[v]?.trim();if(!ue)continue;const Fe=Number(ue);Number.isNaN(Fe)||!Number.isFinite(Fe)?n[v]=`"${se.label}" must be a valid number`:Fe<se.min&&(n[v]=`"${se.label}" must be at least ${se.min.toLocaleString()}`)}const w=z.messageResponseMode?.trim();w&&!["immediate","on-heartbeat"].includes(w)&&(n.messageResponseMode='"Message Response Mode" must be either immediate or on-heartbeat');const A=S.tokenBudget?.trim();if(A){const v=Number(A);Number.isNaN(v)||!Number.isFinite(v)?n.tokenBudget='"Token Budget" must be a valid number':v<=0&&(n.tokenBudget='"Token Budget" must be greater than 0')}const Z=S.usageThreshold?.trim();if(Z){const v=Number(Z);Number.isNaN(v)||!Number.isFinite(v)?n.usageThreshold='"Usage Threshold" must be a valid number':(v<1||v>100)&&(n.usageThreshold='"Usage Threshold" must be between 1 and 100')}const de=S.budgetPeriod?.trim();de&&!["daily","weekly","monthly","lifetime"].includes(de)&&(n.budgetPeriod='"Budget Period" must be one of: daily, weekly, monthly, lifetime');const J=S.resetDay?.trim(),ie=de||"lifetime";if(J){const v=Number(J);Number.isNaN(v)||!Number.isFinite(v)?n.resetDay='"Reset Day" must be a valid number':ie==="weekly"?(v<0||v>6||!Number.isInteger(v))&&(n.resetDay='"Reset Day" must be between 0 (Sunday) and 6 (Saturday) for weekly period'):ie==="monthly"&&(v<1||v>31||!Number.isInteger(v))&&(n.resetDay='"Reset Day" must be between 1 and 31 for monthly period')}if(Object.keys(n).length>0){ve(n),i("Please fix validation errors before saving","error");return}const K={...s.metadata};for(const v of he){const se=M[v.key]?.trim();se?v.type==="number"?K[v.key]=Number(se):K[v.key]=se:delete K[v.key]}$.length>0?K.skills=$:delete K.skills;const Y={...s.runtimeConfig};Y.enabled=V;for(const v of["heartbeatIntervalMs","heartbeatTimeoutMs","maxConcurrentRuns"]){const se=z[v]?.trim();if(!se)delete Y[v];else{const ue=Number(se);Y[v]=v==="maxConcurrentRuns"?ue:ue*1e3}}const Qe=z.messageResponseMode?.trim();if(Qe?Y.messageResponseMode=Qe:delete Y.messageResponseMode,re.trim()){const v=re.indexOf("/");v!==-1&&(Y.modelProvider=re.slice(0,v),Y.modelId=re.slice(v+1),Y.model=re.trim())}else delete Y.modelProvider,delete Y.modelId,delete Y.model;const oe={},Ze=S.tokenBudget?.trim(),Xe=S.usageThreshold?.trim(),es=S.budgetPeriod?.trim(),ss=S.resetDay?.trim();Ze&&(oe.tokenBudget=Number(Ze)),Xe&&(oe.usageThreshold=Number(Xe)/100),es&&(oe.budgetPeriod=es),ss&&(oe.resetDay=Number(ss)),Object.keys(oe).length>0?Y.budgetConfig=oe:delete Y.budgetConfig;let Me;p&&(Me={mode:p,entryFile:o||"AGENTS.md",files:l.length>0?l:["AGENTS.md"]},p==="external"&&m.trim()&&(Me.externalPath=m.trim())),We(!0);try{await mt(s.id,{name:N.trim()||void 0,role:j,title:k.trim()||void 0,icon:R.trim()||void 0,reportsTo:f.trim()||void 0,metadata:K,runtimeConfig:Y,bundleConfig:Me},t),i("Settings saved","success"),le(!0),ce.current&&clearTimeout(ce.current),ce.current=setTimeout(()=>le(!1),3e3),await d()}catch(v){i(`Failed to save settings: ${W(v)}`,"error")}finally{We(!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=>u(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:j,onChange:n=>b(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:k,onChange:n=>x(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:R,onChange:n=>g(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:f,onChange:n=>h(n.target.value),disabled:G,children:[e.jsx("option",{value:"",children:"No manager"}),bs&&e.jsxs("option",{value:pe,children:["Unknown manager (",pe,")"]}),He.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(ht,{id:"agent-skills",label:"Skills",value:$,onChange:U,projectId:t})})})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Model"}),e.jsx("p",{className:"config-description",children:"Override the AI model used by this agent. Leave empty to use the global default model."}),e.jsx("div",{className:"config-fields",children:e.jsx("div",{className:"config-field",children:e.jsx(et,{models:te,value:re,onChange:vs,placeholder:"Use global default",label:"Agent Model",disabled:ee})})})]}),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:V,onChange:n=>Ns(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:Q("input",!!T.heartbeatIntervalMs&&"input--error"),placeholder:String(De/1e3),value:z.heartbeatIntervalMs??"",onChange:n=>be("heartbeatIntervalMs",n.target.value)}),T.heartbeatIntervalMs?e.jsx("span",{className:"config-error",children:T.heartbeatIntervalMs}):e.jsxs("span",{className:"config-hint",children:["How often heartbeats are checked. Leave empty for system default (",De/1e3,"s / ",Rt,")."]})]}),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:Q("input",!!T.heartbeatTimeoutMs&&"input--error"),placeholder:"60",value:z.heartbeatTimeoutMs??"",onChange:n=>be("heartbeatTimeoutMs",n.target.value)}),T.heartbeatTimeoutMs?e.jsx("span",{className:"config-error",children:T.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:Q("input",!!T.maxConcurrentRuns&&"input--error"),placeholder:"1",value:z.maxConcurrentRuns??"",onChange:n=>be("maxConcurrentRuns",n.target.value)}),T.maxConcurrentRuns?e.jsx("span",{className:"config-error",children:T.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:Q("select",!!T.messageResponseMode&&"input--error"),value:z.messageResponseMode??"",onChange:n=>be("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"})]}),T.messageResponseMode?e.jsx("span",{className:"config-error",children:T.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:Q("input",!!T.tokenBudget&&"input--error"),placeholder:"No limit",value:S.tokenBudget??"",onChange:n=>je("tokenBudget",n.target.value)}),T.tokenBudget?e.jsx("span",{className:"config-error",children:T.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:Q("input",!!T.usageThreshold&&"input--error"),placeholder:"80",value:S.usageThreshold??"",onChange:n=>je("usageThreshold",n.target.value)}),T.usageThreshold?e.jsx("span",{className:"config-error",children:T.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:Q("select",!!T.budgetPeriod&&"input--error"),value:S.budgetPeriod??"",onChange:n=>je("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"})]}),T.budgetPeriod?e.jsx("span",{className:"config-error",children:T.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:Q("input",!!T.resetDay&&"input--error"),placeholder:"Auto",value:S.resetDay??"",onChange:n=>je("resetDay",n.target.value)}),T.resetDay?e.jsx("span",{className:"config-error",children:T.resetDay}):e.jsx("span",{className:"config-hint",children:S.budgetPeriod==="weekly"?"Day of week (0=Sunday to 6=Saturday) for reset.":S.budgetPeriod==="monthly"?"Day of month (1-31) for reset.":"Day for reset (weekly: 0-6, monthly: 1-31). Leave empty for automatic."})]}),ae?.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:Q("budget-progress-bar__fill",(ae.usagePercent??0)>=100?"budget-progress-bar__fill--red":(ae.usagePercent??0)>=80?"budget-progress-bar__fill--amber":"budget-progress-bar__fill--green"),style:{width:`${Math.min(ae.usagePercent??0,100)}%`}})}),e.jsxs("span",{className:"budget-progress-label",children:[(ae.currentUsage??0).toLocaleString()," / ",(ae.budgetLimit??0).toLocaleString()," tokens (",Math.round(ae.usagePercent??0),"% used)"]})]})]}),ae?.budgetLimit!=null&&e.jsx("div",{className:"config-field",children:e.jsx("button",{className:"btn btn-reset-budget",onClick:()=>void js(),disabled:Ve,children:Ve?e.jsxs(e.Fragment,{children:[e.jsx(O,{size:14,className:"animate-spin"}),"Resetting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{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:p,onChange:n=>B(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:[p==="managed"&&"Files will be stored in a system-managed directory within .fusion/agents/",p==="external"&&"Specify an external directory path for the instruction files",!p&&"Select a mode to enable instruction bundling"]})]}),p&&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:o,onChange:n=>D(n.target.value)}),e.jsx("span",{className:"config-hint",children:"Primary instructions file name (default: AGENTS.md)"})]}),p==="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:m,onChange:n=>I(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=>y(n.target.value.split(",").map(w=>w.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:he.map(n=>{const w=!!T[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:Q("select",w&&"input--error"),value:M[n.key]??"",onChange:A=>Ye(n.key,A.target.value),children:[e.jsx("option",{value:"",children:"System Default"}),n.options?.map(A=>e.jsx("option",{value:A.value,children:A.label},A.value))]}):e.jsx("input",{id:`adv-${n.key}`,type:"text",inputMode:n.type==="number"?"numeric":void 0,className:Q("input",w&&"input--error"),placeholder:n.placeholder,value:M[n.key]??"",onChange:A=>Ye(n.key,A.target.value)}),w&&e.jsx("span",{className:"config-error",children:T[n.key]}),!w&&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--primary",disabled:!ne||Je,onClick:()=>void Ss(),children:Je?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"]})}),!ne&&ys&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(X,{size:14}),"Settings saved"]})]})]}),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:!Ge||!r,onClick:()=>void r?.(),children:[e.jsx(ke,{size:16}),"Delete Agent"]}),e.jsx("span",{className:"config-danger-note",children:Ge?"Deletion is permanent and cannot be undone.":`Agent deletion is only available when state is idle or terminated (current state: ${s.state}).`})]})})]})]})}function Ht({agentId:s,projectId:t,onChildClick:i}){const[d,c]=a.useState([]),[r,N]=a.useState(!0);return a.useEffect(()=>{N(!0),qs(s,t).then(c).finally(()=>N(!1))},[s,t]),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(ze,{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(u=>{const j=Oe[u.state];return e.jsxs("div",{className:"agent-tree__node agent-is-child",onClick:()=>i?.(u.id),role:"button",tabIndex:0,onKeyDown:b=>b.key==="Enter"&&i?.(u.id),style:{cursor:i?"pointer":"default"},children:[e.jsx("span",{className:"agent-tree__icon",children:u.icon??"🤖"}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:"agent-tree__badge",style:{background:j?.bg??"var(--state-idle-bg)",color:j?.text??"var(--state-idle-text)",border:`1px solid ${j?.border??"var(--state-idle-border)"}`},children:u.state})]},u.id)})})})]})}export{Yt as AgentDetailView};
|