@runfusion/fusion 0.14.2 → 0.14.3
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 +739 -67
- package/dist/client/assets/AgentDetailView-BBCnqhqI.js +18 -0
- package/dist/client/assets/{AgentsView-DkX0tzrN.js → AgentsView-BY-Yq-Te.js} +3 -3
- package/dist/client/assets/{ChatView-CEm2Hw6m.js → ChatView-DkoJNxFW.js} +1 -1
- package/dist/client/assets/{DevServerView-Bumvo_ge.js → DevServerView-qvs6pp6c.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-CXN11cBp.js → DirectoryPicker-BkAIXNrP.js} +1 -1
- package/dist/client/assets/{DocumentsView-B71IqAxA.js → DocumentsView-BcaUGgaL.js} +1 -1
- package/dist/client/assets/{InsightsView-Bs4Rldu6.js → InsightsView-Dz9Ivclw.js} +1 -1
- package/dist/client/assets/{MemoryView-Bs7b_L2Q.js → MemoryView-BsweARBT.js} +1 -1
- package/dist/client/assets/{NodesView-BvAGTXbO.js → NodesView-bAU-v4bJ.js} +1 -1
- package/dist/client/assets/{PiExtensionsManager-3Kcc4uhA.js → PiExtensionsManager-C_U2g7y3.js} +1 -1
- package/dist/client/assets/{PluginManager-Ch-Xynlm.js → PluginManager-pIDsTk5v.js} +1 -1
- package/dist/client/assets/{ResearchView-Bj6Saqf6.js → ResearchView-D4Eib_uR.js} +1 -1
- package/dist/client/assets/{RoadmapsView-9qT8Vwd0.js → RoadmapsView-BaGwsUGS.js} +1 -1
- package/dist/client/assets/{SettingsModal-D4ERGQNQ.js → SettingsModal-BiZVi3cI.js} +1 -1
- package/dist/client/assets/SettingsModal-CRyg643t.js +31 -0
- package/dist/client/assets/{SetupWizardModal-Dv0rX2_o.js → SetupWizardModal-BcIGBBpA.js} +1 -1
- package/dist/client/assets/{SkillMultiselect-CSkXQzdv.js → SkillMultiselect-DPARHJeQ.js} +1 -1
- package/dist/client/assets/{SkillsView-2srXMOzj.js → SkillsView-Da_d_HPu.js} +1 -1
- package/dist/client/assets/{TodoView-CxPPIvw2.js → TodoView-5rAeqYtV.js} +1 -1
- package/dist/client/assets/{folder-open-FA1PwpXV.js → folder-open-CgjcFqww.js} +1 -1
- package/dist/client/assets/{index-CEavim6l.js → index-DoQ5ALYY.js} +25 -25
- package/dist/client/assets/{list-checks-6EktkUso.js → list-checks-C9YWtF7h.js} +1 -1
- package/dist/client/assets/{star-B6Th07jw.js → star-4nUh67-U.js} +1 -1
- package/dist/client/assets/{upload-BJwuErhV.js → upload-CEt5-Bnq.js} +1 -1
- package/dist/client/assets/{users-BrnPTF8H.js → users-4I0JDmgO.js} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/client/version.json +1 -1
- package/dist/extension.js +518 -51
- package/dist/pi-claude-cli/index.ts +2 -2
- package/dist/pi-claude-cli/package.json +1 -1
- package/package.json +1 -1
- package/dist/client/assets/AgentDetailView-C2Iik3Qf.js +0 -18
- package/dist/client/assets/SettingsModal-Zo5qDGOq.js +0 -31
|
@@ -126,8 +126,8 @@ function ensureMcpConfig(
|
|
|
126
126
|
const configPath = writeMcpConfig(toolDefs, hash);
|
|
127
127
|
cachedMcpConfig = { hash, configPath };
|
|
128
128
|
const toolNames = toolDefs.map((t) => t.name).join(", ");
|
|
129
|
-
|
|
130
|
-
`
|
|
129
|
+
debugMcp(
|
|
130
|
+
`MCP config refreshed with ${toolDefs.length} custom tool(s) [${toolNames}] (hash=${hash})`,
|
|
131
131
|
);
|
|
132
132
|
return configPath;
|
|
133
133
|
} catch (err) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusion/pi-claude-cli",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "Fusion vendored fork: pi coding-agent extension that routes LLM calls through the Claude Code CLI. Forked from rchern/pi-claude-cli (MIT). See UPSTREAM.md.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runfusion/fusion",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Fusion CLI: HTTP API server, daemon, dashboard launcher, and task tooling for the Fusion AI coding agent.",
|
|
6
6
|
"homepage": "https://github.com/Runfusion/Fusion#readme",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import{r as t,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Ge,dk as zs,dl as Bs,dm as Hs,dn as Is,L as _,R as We,al as ms,Z as Os,am as _e,V as Te,W as Ss,N as ks,dp as _s,dq as Vs,dr as Us,w as Cs,cx as Js,ds as Gs,z as q,dt as Ws,s as hs,B as gs,Q as Me,U as fs,a$ as ve,X as qs,F as be,A as Fe,I as qe,du as Ys,cr as Ks,aF as Zs,bn as Qs,an as ws,Y as Xs,a1 as et,a3 as st,dv as Ue,j as Rs,dw as tt,r as at,dx as nt,dy as it,dz as rt,dA as lt,dB as ct,dC as Ee,a9 as Le,ab as De,ac as $e,C as Q,a7 as Ms,dD as ot,dE as dt,i as ut,h as mt,k as ht,dF as Je,a2 as gt,dG as ft,dH as xt,dI as pt,dJ as vt,dK as bt,dL as Fs,dM as jt,dN as Nt,a0 as yt,dO as St,_ as kt,dP as Ct}from"./index-CEavim6l.js";import{S as As}from"./star-B6Th07jw.js";import{S as wt}from"./SkillMultiselect-CSkXQzdv.js";import{L as Ts}from"./list-checks-6EktkUso.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
2
|
-
* @license lucide-react v1.7.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const Rt=[["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"}]],Ae=Ge("chart-column",Rt);/**
|
|
7
|
-
* @license lucide-react v1.7.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Mt=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M17 12h-2l-2 5-2-10-2 5H7",key:"15hlnc"}]],Ft=Ge("square-activity",Mt);/**
|
|
12
|
-
* @license lucide-react v1.7.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const At=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],Tt=Ge("trending-down",At);function xs(s){return s<1e3?`${s}ms`:s<6e4?`${(s/1e3).toFixed(1)}s`:s<36e5?`${Math.floor(s/6e4)}m`:`${(s/36e5).toFixed(1)}h`}function Et(s){return`${Math.round(s*100)}%`}function ps(s){const a=Date.now(),i=new Date(s).getTime(),o=a-i;if(o<0){const d=Math.abs(o);return d<6e4?"in a moment":d<36e5?`in ${Math.floor(d/6e4)}m`:d<864e5?`in ${Math.floor(d/36e5)}h`:`in ${Math.floor(d/864e5)}d`}return o<6e4?"just now":o<36e5?`${Math.floor(o/6e4)}m ago`:o<864e5?`${Math.floor(o/36e5)}h ago`:`${Math.floor(o/864e5)}d ago`}function Lt(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 xe(s){return s instanceof Error&&s.message?s.message:String(s)}function Dt(s){switch(s){case"improving":return"↑ Improving";case"declining":return"↓ Declining";case"stable":return"→ Stable";default:return"Insufficient data"}}function $t(s){switch(s){case"improving":return"trend-improving";case"declining":return"trend-declining";case"stable":return"trend-stable";default:return"trend-insufficient"}}function vs(s,a=5){return e.jsx("span",{className:"rating-stars",children:Array.from({length:a},(i,o)=>e.jsx(As,{size:14,className:o<s?"star-filled":"star-empty",fill:o<s?"currentColor":"none"},o))})}function Pt({agentId:s,projectId:a,addToast:i}){const[o,d]=t.useState([]),[r,j]=t.useState(null),[m,N]=t.useState(null),[p,k]=t.useState([]),[F,f]=t.useState(!0),[z,L]=t.useState(!0),[A,l]=t.useState(!1),[v,C]=t.useState(!1),[B,T]=t.useState(null),[w,y]=t.useState(0),[U,W]=t.useState(""),[H,R]=t.useState(""),G=t.useCallback(async()=>{try{const[c,E]=await Promise.all([zs(s,20,a),Bs(s,void 0,a)]);d(c),j(E)}catch(c){i(`Failed to load reflections: ${xe(c)}`,"error")}finally{f(!1)}},[s,a,i]),h=t.useCallback(async()=>{try{const[c,E]=await Promise.all([Hs(s,a),Is(s,{limit:50},a)]);N(c),k(E)}catch(c){i(`Failed to load ratings: ${xe(c)}`,"error")}finally{L(!1)}},[s,a,i]);t.useEffect(()=>{G(),h()},[G,h]);const J=async()=>{l(!0);try{if(!await _s(s,a)){i("Not enough history to generate a reflection yet","error");return}i("Reflection generated successfully","success"),f(!0),await G()}catch(c){const E=xe(c),V=E.toLowerCase();V.includes("agent not found")||V.includes("not found")?i("This agent is no longer available. It may have been deleted.","error"):V.includes("insufficient history")?i("Not enough history to generate a reflection yet","error"):i(`Failed to generate reflection: ${E}`,"error")}finally{l(!1)}},I=async c=>{if(c.preventDefault(),w!==0){C(!0);try{await Vs(s,{score:w,category:U||void 0,comment:H||void 0,raterType:"user"},a),y(0),W(""),R(""),i("Rating added","success"),await h()}catch(E){i(`Failed to add rating: ${xe(E)}`,"error")}finally{C(!1)}}},u=async c=>{try{await Us(s,c,a),i("Rating deleted","success"),await h()}catch(E){i(`Failed to delete rating: ${xe(E)}`,"error")}},x=c=>{T(E=>E===c?null:c)};if(F&&z)return e.jsx("div",{className:"reflections-tab",children:e.jsxs("div",{className:"reflections-loading-indicator",children:[e.jsx(_,{size:16,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading evaluation..."})]})});const K=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(Ae,{size:16}),"Performance, Reflections & Ratings"]}),e.jsx("button",{className:"btn btn-secondary",onClick:J,disabled:A,title:"Generate a manual reflection",children:A?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:14,className:"animate-spin"}),"Reflecting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14}),"Reflect Now"]})})]}),r&&!K&&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(ms,{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(Tt,{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(Os,{size:16,style:{color:"var(--in-progress)"}}),xs(r.avgDurationMs)]}),e.jsx("div",{className:"stat-label",children:"Avg Duration"})]}),e.jsxs("div",{className:"reflections-stat-card",children:[e.jsxs("div",{className:"stat-value",children:[e.jsx(Ae,{size:16,style:{color:r.successRate>=.8?"var(--color-success)":r.successRate>=.5?"var(--color-warning)":"var(--color-error)"}}),Et(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(_e,{size:16,style:{color:"var(--color-info)"}}),r.recentReflectionCount]}),e.jsx("div",{className:"stat-label",children:"Reflections"})]})]}),K&&e.jsxs("div",{className:"reflections-no-data",children:[e.jsx(Ae,{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"}),z?e.jsxs("div",{className:"reflections-loading-indicator",children:[e.jsx(_,{size:16,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading ratings..."})]}):e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"rating-summary-card",children:[e.jsxs("div",{className:"rating-score-display",children:[e.jsx("span",{className:"rating-average",children:m.averageScore.toFixed(1)}),vs(Math.round(m.averageScore))]}),e.jsxs("div",{className:"rating-stats",children:[e.jsxs("span",{className:"rating-count",children:[m.totalRatings," ratings"]}),e.jsx("span",{className:`rating-trend-badge ${$t(m.trend)}`,children:Dt(m.trend)})]})]}),m&&Object.keys(m.categoryAverages).length>0&&e.jsxs("div",{className:"category-breakdown",children:[e.jsx("h4",{children:"Category Averages"}),Object.entries(m.categoryAverages).map(([c,E])=>e.jsxs("div",{className:"category-item",children:[e.jsx("span",{className:"category-name",children:c}),e.jsx("span",{className:"category-score",children:E.toFixed(1)})]},c))]}),e.jsxs("form",{className:"add-rating-form",onSubmit:I,children:[e.jsx("h4",{children:"Add Rating"}),e.jsx("div",{className:"star-selector",children:[1,2,3,4,5].map(c=>e.jsx("button",{type:"button",className:"star-btn touch-target",onClick:()=>y(c),title:`${c} star${c>1?"s":""}`,children:e.jsx(As,{size:24,fill:c<=w?"currentColor":"none",className:c<=w?"star-filled":"star-empty"})},c))}),e.jsxs("select",{value:U,onChange:c=>W(c.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:H,onChange:c=>R(c.target.value),placeholder:"Optional comment...",className:"input add-rating-comment-input",rows:3}),e.jsx("button",{type:"submit",className:"btn btn-task-create",disabled:w===0||v,children:v?"Submitting...":"Submit Rating"})]}),e.jsxs("div",{className:"rating-history",children:[e.jsx("h4",{children:"Rating History"}),p.length===0?e.jsx("p",{className:"no-ratings",children:"No ratings yet"}):p.map(c=>e.jsxs("div",{className:"rating-history-item",children:[e.jsxs("div",{className:"rating-item-header",children:[vs(c.score),c.category&&e.jsx("span",{className:"rating-category-badge",children:c.category}),e.jsx("span",{className:"rating-time",children:ps(c.createdAt)}),e.jsx("button",{type:"button",className:"rating-delete-btn touch-target",onClick:()=>void u(c.id),title:"Delete rating",children:e.jsx(Te,{size:14})})]}),c.comment&&e.jsx("p",{className:"rating-comment",children:c.comment})]},c.id))]})]})]}),e.jsxs("div",{className:"reflections-list",children:[e.jsx("h4",{children:"Reflection History"}),F?e.jsxs("div",{className:"reflections-loading-indicator",children:[e.jsx(_,{size:16,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading reflections..."})]}):o.length===0?e.jsxs("div",{className:"reflection-empty",children:[e.jsx(_e,{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:o.map(c=>{const E=B===c.id;return e.jsxs("div",{className:`reflection-card ${E?"reflection-card--expanded":""}`,onClick:()=>x(c.id),role:"button",tabIndex:0,onKeyDown:V=>V.key==="Enter"&&x(c.id),children:[e.jsxs("div",{className:"reflection-card-header",children:[e.jsx("span",{className:`reflection-trigger-badge reflection-trigger-${c.trigger}`,children:Lt(c.trigger)}),e.jsx("span",{className:"reflection-timestamp",children:ps(c.timestamp)}),e.jsx("span",{className:"reflection-chevron",children:E?e.jsx(Ss,{size:16}):e.jsx(ks,{size:16})})]}),e.jsx("div",{className:"reflection-summary",children:c.summary}),E&&e.jsxs("div",{className:"reflection-details",children:[c.insights.length>0&&e.jsxs("div",{className:"reflection-insights",children:[e.jsxs("h5",{children:[e.jsx(_e,{size:14})," Insights"]}),e.jsx("ul",{children:c.insights.map((V,g)=>e.jsx("li",{children:V},g))})]}),c.suggestedImprovements.length>0&&e.jsxs("div",{className:"reflection-suggestions",children:[e.jsxs("h5",{children:[e.jsx(ms,{size:14})," Suggested Improvements"]}),e.jsx("ul",{children:c.suggestedImprovements.map((V,g)=>e.jsx("li",{children:V},g))})]}),c.metrics&&e.jsxs("div",{className:"reflection-metrics",children:[e.jsx("h5",{children:"Metrics"}),e.jsxs("div",{className:"metrics-grid",children:[c.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:c.metrics.tasksCompleted})]}),c.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:c.metrics.tasksFailed})]}),c.metrics.avgDurationMs!==void 0&&e.jsxs("div",{className:"metric",children:[e.jsx("span",{className:"metric-label",children:"Avg Duration:"}),e.jsx("span",{className:"metric-value",children:xs(c.metrics.avgDurationMs)})]}),c.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:c.metrics.errorCount})]})]})]})]})]},c.id)})})]})]})}function ee(...s){return s.filter(Boolean).join(" ")}function je(s){const a=Date.now(),i=new Date(s).getTime(),o=a-i;if(o<0){const d=Math.abs(o);return d<6e4?"in a moment":d<36e5?`in ${Math.floor(d/6e4)}m`:d<864e5?`in ${Math.floor(d/36e5)}h`:`in ${Math.floor(d/864e5)}d`}return o<6e4?"just now":o<36e5?`${Math.floor(o/6e4)}m ago`:o<864e5?`${Math.floor(o/36e5)}h ago`:`${Math.floor(o/864e5)}d ago`}const zt=[{id:"dashboard",label:"Dashboard",icon:Ft},{id:"logs",label:"Logs",icon:be},{id:"runs",label:"Runs",icon:Fe},{id:"tasks",label:"Tasks",icon:Ts},{id:"employees",label:"Employees",icon:qe},{id:"soul",label:"Soul",icon:Ys},{id:"instructions",label:"Instructions",icon:Ks},{id:"memory",label:"Agent Memory",icon:be},{id:"reflections",label:"Evaluation",icon:Ae},{id:"config",label:"Settings",icon:Zs}],Ye={idle:{bg:"var(--state-idle-bg)",text:"var(--state-idle-text)",border:"var(--state-idle-border)"},active:{bg:"var(--state-active-bg)",text:"var(--state-active-text)",border:"var(--state-active-border)"},running:{bg:"var(--state-active-bg)",text:"var(--state-active-text)",border:"var(--state-active-border)"},paused:{bg:"var(--state-paused-bg)",text:"var(--state-paused-text)",border:"var(--state-paused-border)"},error:{bg:"var(--state-error-bg)",text:"var(--state-error-text)",border:"var(--state-error-border)"},terminated:{bg:"var(--state-error-bg)",text:"var(--state-error-text)",border:"var(--state-error-border)"}},bs={completed:{icon:Q,color:"var(--color-success, #3fb950)"},failed:{icon:xt,color:"var(--color-error, #f85149)"},active:{icon:_,color:"var(--in-progress, #bc8cff)"},terminated:{icon:ve,color:"var(--text-muted, #8b949e)"}},js={"long-term":"Long-term",daily:"Daily",dreams:"Dreams"},Bt={"long-term":"Curated durable decisions, conventions, constraints, and pitfalls for this specific agent.",daily:"Raw daily observations and open loops recorded by this agent.",dreams:"Synthesized patterns and emerging themes distilled from this agent's daily memory."},Ht=yt(Je);function It(s,a){return s.some(i=>i.path===a)?a:s.find(i=>i.layer==="long-term")?.path??s[0]?.path??""}function ca({agentId:s,projectId:a,onClose:i,addToast:o,onChildClick:d}){const[r,j]=t.useState(null),{confirm:m}=Cs(),[N,p]=t.useState([]),[k,F]=t.useState(!0),[f,z]=t.useState("dashboard"),[L,A]=t.useState(!1),[l,v]=t.useState(!1),C=t.useRef(null),B=t.useRef(null),T=t.useRef(!1);Js(B,!0,"fusion:agent-detail-modal-size");const w=t.useRef(i),y=t.useRef(o),U=t.useRef(null),W=t.useRef(!1),H=t.useRef(0),R=t.useRef(s),G=t.useRef(a);w.current=i,y.current=o,U.current=r;const h=t.useCallback(async()=>{U.current===null&&F(!0);try{const D=await Gs(s,a);j(D)}catch(D){y.current(`Failed to load agent: ${q(D)}`,"error"),w.current()}finally{F(!1)}},[s,a]),J=t.useCallback(async()=>{const g=H.current,D=s,b=a;if(r?.taskId)try{const O=await Ws(r.taskId,b,{limit:100});if(H.current!==g||s!==D||a!==b)return;p(O.entries)}catch(O){if(H.current!==g||s!==D||a!==b)return;console.error("Failed to load task logs:",O)}},[r?.taskId,s,a]),I=t.useCallback(g=>{W.current=g},[]);t.useEffect(()=>{h()},[h]),t.useEffect(()=>{const g=setInterval(()=>{h()},3e4);return()=>{clearInterval(g)}},[h]),t.useEffect(()=>{r?.taskId&&J()},[r?.taskId,J]),t.useEffect(()=>{(R.current!==s||G.current!==a)&&(R.current=s,G.current=a,H.current++,p([]),A(!1),W.current=!1)},[s,a]),t.useEffect(()=>{const g=a?`?projectId=${encodeURIComponent(a)}`:"",D=H.current;return hs(`/api/events${g}`,{events:{"agent:updated":b=>{if(H.current===D)try{const O=JSON.parse(b.data);if(!O||typeof O!="object"||O.id!==s||W.current)return;h()}catch{}}}})},[s,a,h]),t.useEffect(()=>{if(f!=="logs"||!r?.taskId){A(!1);return}const g=H.current,D=r.taskId,b=a?`?projectId=${encodeURIComponent(a)}`:"",O=hs(`/api/tasks/${encodeURIComponent(D)}/logs/stream${b}`,{events:{"agent:log":le=>{if(H.current===g)try{const Ne=JSON.parse(le.data);p(Pe=>[Ne,...Pe]);const de=C.current;de&&de.scrollTop<50&&(de.scrollTop=0)}catch{}}},onOpen:()=>{H.current===g&&A(!0)},onError:()=>{H.current===g&&A(!1)}});return()=>{O(),H.current===g&&A(!1)}},[r?.taskId,f,a]);const u=async g=>{if(l||!U.current)return;const D=U.current.state;if(D!==g){v(!0),j(b=>b&&{...b,state:g});try{await et(s,g,a),o(`Agent state updated to ${g}`,"success"),h()}catch(b){j(O=>O&&{...O,state:D}),o(`Failed to update state: ${q(b)}`,"error")}finally{v(!1)}}},x=async()=>{if(!(!r||!await m({title:"Delete Agent",message:`Delete agent "${r.name}"? This cannot be undone.`,danger:!0})))try{await st(s,a),o(`Agent "${r.name}" deleted`,"success"),i()}catch(D){o(`Failed to delete agent: ${q(D)}`,"error")}},K=()=>r?Xs(r):{label:"Unknown",icon:e.jsx(gs,{size:14}),color:"var(--text-muted, #8b949e)",stateDerived:!1},c=()=>{r&&(navigator.clipboard.writeText(r.id),o("Agent ID copied to clipboard","success"))};if(k)return e.jsx("div",{className:"agent-detail-overlay",onMouseDown:g=>{g.target===g.currentTarget&&(T.current=!0)},onMouseUp:g=>{T.current&&g.target===g.currentTarget&&i(),T.current=!1},role:"dialog","aria-modal":"true",children:e.jsx("div",{className:"agent-detail-modal",ref:B,children:e.jsxs("div",{className:"agent-detail-loading",children:[e.jsx(_,{className:"animate-spin",size:24}),e.jsx("span",{children:"Loading agent..."})]})})});if(!r)return null;const E=Ye[r.state],V=K();return e.jsx("div",{className:"agent-detail-overlay",onClick:g=>g.target===g.currentTarget&&i(),role:"dialog","aria-modal":"true",children:e.jsxs("div",{className:"agent-detail-modal",children:[e.jsxs("div",{className:"agent-detail-header",children:[e.jsxs("div",{className:"agent-detail-identity",children:[e.jsx("div",{className:"agent-detail-icon",children:e.jsx(gs,{size:20})}),e.jsxs("div",{className:"agent-detail-info",children:[e.jsx("h2",{children:r.name}),e.jsxs("div",{className:"agent-detail-badges",children:[e.jsx("span",{className:"badge",style:{background:E.bg,color:E.text,border:`1px solid ${E.border}`},children:r.state}),e.jsxs("span",{className:"badge",style:{color:V.color},title:V.label,children:[V.icon,!V.stateDerived&&V.label]})]})]})]}),e.jsxs("div",{className:"agent-detail-controls",children:[r.state==="idle"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-task-create btn--compact",onClick:()=>void u("active"),disabled:l,children:[e.jsx(Me,{size:14}),"Start"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:x,children:[e.jsx(Te,{size:14}),"Delete"]})]}),r.state==="active"&&e.jsxs("button",{className:"btn btn--compact",onClick:()=>void u("paused"),disabled:l,children:[e.jsx(fs,{size:14}),"Pause"]}),r.state==="paused"&&e.jsxs("button",{className:"btn btn-task-create btn--compact",onClick:()=>void u("active"),disabled:l,children:[e.jsx(Me,{size:14}),"Resume"]}),r.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--compact",onClick:()=>void u("paused"),disabled:l,children:[e.jsx(fs,{size:14}),"Pause"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:()=>void u("terminated"),disabled:l,children:[e.jsx(ve,{size:14}),"Stop"]})]}),r.state==="error"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-task-create btn--compact",onClick:()=>void u("active"),disabled:l,children:[e.jsx(Me,{size:14}),"Retry"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:()=>void u("terminated"),disabled:l,children:[e.jsx(ve,{size:14}),"Stop"]})]}),r.state==="terminated"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-task-create btn--compact",onClick:()=>void u("active"),disabled:l,children:[e.jsx(Me,{size:14}),"Start"]}),e.jsxs("button",{className:"btn btn--danger btn--compact",onClick:x,children:[e.jsx(Te,{size:14}),"Delete"]})]})]}),e.jsxs("div",{className:"agent-detail-utility-actions",children:[e.jsx("button",{className:"btn-icon",onClick:()=>void h(),title:"Refresh",children:e.jsx(We,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:i,"aria-label":"Close",title:"Close",children:e.jsx(qs,{size:20})})]})]}),e.jsx("div",{className:"agent-detail-tabs",children:zt.map(g=>e.jsxs("button",{className:ee("agent-detail-tab",f===g.id&&"active"),onClick:()=>z(g.id),children:[e.jsx(g.icon,{size:16}),g.label]},g.id))}),e.jsxs("div",{className:"agent-detail-content",children:[f==="dashboard"&&e.jsx(Ot,{agent:r,health:V,onChildClick:d,projectId:a}),f==="logs"&&e.jsx(_t,{logs:N,isStreaming:L,containerRef:C,hasTask:!!r.taskId}),f==="runs"&&e.jsx(Ut,{addToast:o,agentId:r.id,projectId:a,agentState:r.state,agentName:r.name}),f==="tasks"&&e.jsx(qt,{agentId:r.id,projectId:a,addToast:o}),f==="employees"&&e.jsx(sa,{agentId:r.id,projectId:a,onChildClick:d}),f==="soul"&&e.jsx(Kt,{agent:r,projectId:a,addToast:o,onSaved:h}),f==="instructions"&&e.jsx(Qt,{agent:r,projectId:a,addToast:o,onSaved:h}),f==="memory"&&e.jsx(Zt,{agent:r,projectId:a,addToast:o,onSaved:h}),f==="reflections"&&e.jsx(Pt,{agentId:r.id,projectId:a,addToast:o}),f==="config"&&e.jsx(ea,{agent:r,projectId:a,addToast:o,onSaved:h,onHasChangesChange:I,onDelete:x})]}),e.jsxs("div",{className:"agent-detail-footer",children:[e.jsx("button",{className:"btn-icon",onClick:c,title:"Copy Agent ID",children:e.jsx(Qs,{})}),e.jsx("span",{className:"agent-detail-id",onClick:c,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(ws,{size:12})]})]})]})]})})}function Ot({agent:s,health:a,onChildClick:i,projectId:o}){const d=Ye[s.state],[r,j]=t.useState([]),[m,N]=t.useState(!0),[p,k]=t.useState(null),[F,f]=t.useState([]),z=typeof s.runtimeConfig?.runtimeHint=="string"?s.runtimeConfig.runtimeHint:"",L=(()=>{const l=s.runtimeConfig??{};if(z){const v=F.find(C=>C.runtimeId===z);return v?v.name:z}if(l.modelProvider&&l.modelId)return`${l.modelProvider}/${l.modelId}`;if(typeof l.model=="string"&&l.model.includes("/")){const v=l.model.indexOf("/");return l.model.slice(v+1)}return null})();t.useEffect(()=>{Ue(s.id,o).then(k).catch(()=>k(null))},[s.id,o]),t.useEffect(()=>{Rs(o).then(f).catch(()=>f([]))},[o]),t.useEffect(()=>{let l=!1;return N(!0),tt(s.id,o).then(v=>{if(l)return;const C=v.length>0&&v[0]?.id===s.id?[...v].reverse():v;j(C)}).catch(()=>{l||j([])}).finally(()=>{l||N(!1)}),()=>{l=!0}},[s.id,o]);const A=t.useMemo(()=>{const l=s.completedRuns||[],v=new Date;v.setHours(0,0,0,0);const C=l.filter(T=>new Date(T.startedAt)>=v),B=l.filter(T=>T.status==="completed");return{totalRuns:l.length,todayRuns:C.length,successfulRuns:B.length,successRate:l.length>0?Math.round(B.length/l.length*100):0}},[s]);return e.jsxs("div",{className:"dashboard-tab",children:[p?.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(l=>e.jsx("span",{className:"skill-badge",children:l},l))}):"—"})]}),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:d.bg,color:d.text},children:s.state})})]}),e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Health"}),e.jsx("span",{className:"info-value",style:{color:a.color},title:a.label,children:a.stateDerived?a.icon:a.label})]}),L&&e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:z?"Runtime":"Model"}),e.jsx("span",{className:"info-value",children:L})]}),p?.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:p.isOverBudget?"var(--state-error-bg, rgba(248,81,73,0.15))":p.isOverThreshold?"var(--state-paused-bg, rgba(227,181,65,0.15))":"var(--state-active-bg, rgba(63,185,80,0.15))",color:p.isOverBudget?"var(--state-error-text, #f85149)":p.isOverThreshold?"var(--state-paused-text, #e3b541)":"var(--state-active-text, #3fb950)",border:`1px solid ${p.isOverBudget?"var(--state-error-border, #f85149)":p.isOverThreshold?"var(--state-paused-border, #e3b541)":"var(--state-active-border, #3fb950)"}`},children:p.isOverBudget?"⚠ Budget Exhausted":`${Math.round(p.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?je(s.lastHeartbeatAt):"Never"})]}),(()=>{if(!(s.state==="active"||s.state==="running")||!s.lastHeartbeatAt)return null;const v=at(s.runtimeConfig?.heartbeatIntervalMs),C=new Date(new Date(s.lastHeartbeatAt).getTime()+v);return e.jsxs("div",{className:"info-item",children:[e.jsx("span",{className:"info-label",children:"Next Heartbeat"}),e.jsx("span",{className:"info-value",title:C.toLocaleString(),children:je(C.toISOString())})]})})()]})]}),e.jsxs("div",{className:"dashboard-section",children:[e.jsxs("h3",{children:[e.jsx(qe,{size:16,style:{marginRight:"6px",verticalAlign:"-2px"}}),"Chain of Command"]}),m?e.jsxs("div",{className:"chain-of-command-loading",role:"status","aria-live":"polite",children:[e.jsx(_,{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((l,v)=>{const C=v===r.length-1,B=!C;return e.jsxs("div",{className:"chain-of-command-item",children:[e.jsx("button",{type:"button",className:`chain-of-command-node${C?" chain-of-command-node--current":""}`,onClick:()=>B&&i?.(l.id),disabled:!B||!i,title:C?"Current agent":`View ${l.name}`,children:l.name}),!C&&e.jsx("span",{className:"chain-of-command-separator","aria-hidden":"true",children:"→"})]},l.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:A.totalRuns}),e.jsx("div",{className:"stat-label",children:"Total Runs"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-value",children:A.todayRuns}),e.jsx("div",{className:"stat-label",children:"Runs Today"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsxs("div",{className:"stat-value",children:[A.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(ws,{size:14})]})]})]}),s.metadata&&Object.keys(s.metadata).length>0&&e.jsxs("div",{className:"dashboard-section",children:[e.jsx("h3",{children:"Metadata"}),e.jsx("pre",{className:"metadata-json",children:JSON.stringify(s.metadata,null,2)})]})]})}function _t({logs:s,isStreaming:a,containerRef:i,hasTask:o}){return o?e.jsxs("div",{className:"logs-tab",children:[e.jsxs("div",{className:"logs-header",children:[e.jsxs("span",{className:"logs-count",children:[s.length," entries"]}),a&&e.jsxs("span",{className:"streaming-indicator",children:[e.jsx("span",{className:"streaming-dot"}),"Live"]})]}),e.jsx("div",{ref:i,className:"logs-container",children:s.length===0?e.jsxs("div",{className:"logs-empty",children:[e.jsx(be,{size:48,opacity:.3}),e.jsx("p",{children:"No log entries yet"}),e.jsx("p",{className:"text-muted",children:a?"Waiting for activity...":"Logs will appear here when the agent is active"})]}):s.map((d,r)=>{const j=r>0?s[r-1]:void 0,m=!j||j.agent!==d.agent;return e.jsx(Vt,{entry:d,showTimestamp:m},`${d.timestamp}-${r}`)})})]}):e.jsx("div",{className:"logs-tab",children:e.jsxs("div",{className:"logs-empty",children:[e.jsx(be,{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 Vt({entry:s,showTimestamp:a}){const o=(()=>{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)"}}})(),d=new Date(s.timestamp).toLocaleTimeString();return e.jsxs("div",{className:"log-entry",style:o,children:[a&&e.jsxs("span",{className:"log-timestamp",children:["[",d,"]"]}),s.agent&&e.jsxs("span",{className:"log-agent",children:["[",s.agent,"]"]}),s.type==="tool"&&e.jsx("span",{className:"log-icon",children:"⚡"}),s.type==="tool_result"&&e.jsx("span",{className:"log-icon",children:"✓"}),s.type==="tool_error"&&e.jsx("span",{className:"log-icon",children:"✗"}),e.jsxs("span",{className:"log-text",children:[s.text,s.detail&&e.jsxs("span",{className:"log-detail",children:[" — ",s.detail]})]})]})}function Ut({addToast:s,agentId:a,projectId:i,agentState:o,agentName:d}){const[r,j]=t.useState([]),{confirm:m}=Cs(),[N,p]=t.useState(!0),[k,F]=t.useState(null),[f,z]=t.useState([]),[L,A]=t.useState(!1),[l,v]=t.useState(null),[C,B]=t.useState(!1),T=t.useCallback(async()=>{try{const u=await nt(a,50,i);j(u)}catch(u){s(`Failed to load runs: ${q(u)}`,"error")}finally{p(!1)}},[a,i,s]);t.useEffect(()=>{T()},[T]);const w=r.some(u=>u.status==="active");t.useEffect(()=>{if(!w)return;const u=setInterval(()=>{T()},5e3);return()=>clearInterval(u)},[w,T]);const y=t.useCallback(async u=>{if(k===u){F(null),z([]),v(null);return}F(u),A(!0),B(!0),z([]),v(null);try{const[x,K]=await Promise.all([it(a,u,i),rt(a,u,i)]);z(x),v(K)}catch(x){s(`Failed to load run details: ${q(x)}`,"error"),z([]),v(null)}finally{A(!1),B(!1)}},[k,a,i,s]),U=async()=>{try{await gt(a,i,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${d??a}`,"success"),p(!0),T()}catch(u){s(`Failed to start heartbeat run: ${q(u)}`,"error")}},W=async()=>{if(await m({title:"Stop Active Run",message:"Stop the active run? The agent's work will be interrupted.",danger:!0}))try{await ft(a,i),s("Run stopped","success"),p(!0),T()}catch(x){s(`Failed to stop run: ${q(x)}`,"error")}},H=o==="active"||o==="idle";if(N&&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(_,{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:[H&&e.jsx("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border-color)"},children:e.jsxs("button",{className:"btn btn--sm btn-task-create",onClick:()=>void U(),"aria-label":`Run now for ${d??a}`,children:[e.jsx(Fe,{size:14})," Run Now"]})}),e.jsxs("div",{className:"runs-empty",children:[e.jsx(Fe,{size:48,opacity:.3}),e.jsx("p",{children:"No runs yet"}),e.jsx("p",{className:"text-muted",children:"Heartbeat runs will appear here"})]})]});const R=[...r].sort((u,x)=>new Date(x.startedAt).getTime()-new Date(u.startedAt).getTime()),G=R.filter(u=>u.status==="active"),h=R.filter(u=>u.status!=="active"),J=u=>u?e.jsxs("div",{style:{fontSize:"12px",color:"var(--text-secondary)",display:"flex",gap:"12px",flexWrap:"wrap"},children:[e.jsxs("span",{children:["Input: ",u.inputTokens.toLocaleString()]}),e.jsxs("span",{children:["Output: ",u.outputTokens.toLocaleString()]}),u.cachedTokens>0&&e.jsxs("span",{children:["Cached: ",u.cachedTokens.toLocaleString()]})]}):null,I=(u,x,K)=>{const c=bs[u.status]||bs.completed,E=c.icon,V=u.endedAt?Jt(new Date(u.startedAt),new Date(u.endedAt)):"In progress",g=k===u.id;return e.jsxs("div",{children:[e.jsxs("div",{className:ee("run-card",K&&"run-card--active",g&&"run-card--selected"),onClick:()=>void y(u.id),style:{cursor:"pointer"},role:"button",tabIndex:0,"aria-expanded":g,"aria-label":`${K?"Active":""} run ${u.id.slice(0,8)}, ${u.status}`,onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),y(u.id))},children:[e.jsxs("div",{className:"run-header",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g?e.jsx(Ss,{size:14}):e.jsx(ks,{size:14}),K?e.jsxs("span",{className:"run-live-indicator",children:[e.jsx("span",{className:"live-dot"}),"Live Run"]}):e.jsxs("span",{className:"run-id",children:["#",x+1," ",u.id.slice(0,8)]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[u.invocationSource&&e.jsx("span",{className:"badge",style:{fontSize:"10px",padding:"1px 6px"},children:u.invocationSource}),K&&e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:D=>{D.preventDefault(),D.stopPropagation(),W()},"aria-label":"Stop active run",children:[e.jsx(ve,{size:12})," Stop"]}),e.jsxs("span",{className:ee("run-status",u.status),children:[e.jsx(E,{size:14,className:c.color,style:u.status==="active"?{color:c.color}:void 0}),u.status]}),u.heartbeatProcedureSource==="custom"&&e.jsx("span",{className:"badge",style:{fontSize:"10px",padding:"1px 6px"},children:"Heartbeat: custom"})]})]}),e.jsxs("div",{className:"run-details",children:[e.jsxs("span",{children:["Started ",je(u.startedAt)]}),e.jsx("span",{children:"•"}),e.jsx("span",{children:V}),u.triggerDetail&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{className:"text-muted",children:u.triggerDetail})]})]})]}),g&&e.jsxs("div",{className:"run-logs-container",children:[C?e.jsxs("div",{className:"run-details-loading-state",children:[e.jsx(_,{size:14,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading details..."})]}):l&&e.jsxs("div",{className:"run-output-sections",children:[e.jsx("div",{className:"run-output-section",children:e.jsxs("details",{children:[e.jsx("summary",{className:"run-output-label",style:{cursor:"pointer",userSelect:"none"},children:"System Prompt"}),l.systemPrompt?e.jsx("pre",{className:"run-output-panel",children:l.systemPrompt}):e.jsx("div",{className:"text-muted run-output-empty",children:"System prompt not captured for this run"})]})}),e.jsx("div",{className:"run-output-section",children:e.jsxs("details",{children:[e.jsx("summary",{className:"run-output-label",style:{cursor:"pointer",userSelect:"none"},children:"Execution Prompt"}),l.executionPrompt?e.jsx("pre",{className:"run-output-panel",children:l.executionPrompt}):e.jsx("div",{className:"text-muted run-output-empty",children:"Execution prompt not captured for this run"})]})}),l.usageJson&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label",children:"Token Usage"}),J(l.usageJson)]}),l.stdoutExcerpt&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label",children:"Output"}),e.jsx("pre",{className:"run-output-panel",children:l.stdoutExcerpt.length>2e3?`${l.stdoutExcerpt.slice(0,2e3)}
|
|
17
|
-
|
|
18
|
-
... (truncated, ${l.stdoutExcerpt.length} chars total)`:l.stdoutExcerpt})]}),l.stderrExcerpt&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label run-output-label--error",children:"Errors"}),e.jsx("pre",{className:"run-output-panel run-output-panel--error",children:l.stderrExcerpt})]}),l.resultJson&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label",children:"Result"}),e.jsx("pre",{className:"run-output-panel",children:JSON.stringify(l.resultJson,null,2)})]}),l.contextSnapshot&&Object.keys(l.contextSnapshot).length>0&&e.jsxs("div",{className:"run-output-section",children:[e.jsx("div",{className:"run-output-label",children:"Context"}),e.jsx("div",{className:"run-context-grid",children:Object.entries(l.contextSnapshot).map(([D,b])=>e.jsxs("span",{className:"run-context-item",children:[e.jsxs("span",{className:"text-muted",children:[D,":"]})," ",e.jsx("span",{children:String(b)})]},D))})]}),!l.stdoutExcerpt&&!l.stderrExcerpt&&!l.resultJson&&e.jsx("div",{className:"text-muted run-output-empty",children:"No output captured"})]}),e.jsxs("div",{className:"run-agent-logs-section",children:[e.jsx("div",{className:"run-output-label",children:"Agent Logs"}),L?e.jsxs("div",{className:"run-details-loading-state",children:[e.jsx(_,{size:14,className:"animate-spin"}),e.jsx("span",{className:"text-muted",children:"Loading logs..."})]}):f.length===0?e.jsx("div",{className:"text-muted run-output-empty",children:"No logs available for this run"}):e.jsx(pt,{entries:f,loading:!1})]})]})]},u.id)};return e.jsxs("div",{className:"runs-tab",children:[H&&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":"",w&&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:[w&&e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void W(),"aria-label":`Stop active run for ${d??a}`,children:[e.jsx(ve,{size:14})," Stop Run"]}),e.jsxs("button",{className:"btn btn--sm btn-task-create",onClick:()=>void U(),"aria-label":`Run now for ${d??a}`,children:[e.jsx(Fe,{size:14})," Run Now"]})]})]}),G.map((u,x)=>I(u,x,!0)),h.map((u,x)=>I(u,G.length+x,!1))]})}function Jt(s,a){const i=Math.floor((a.getTime()-s.getTime())/1e3);return i<60?`${i}s`:i<3600?`${Math.floor(i/60)}m ${i%60}s`:`${Math.floor(i/3600)}h ${Math.floor(i%3600/60)}m`}const Gt={triage:"Triage",todo:"Todo","in-progress":"In Progress","in-review":"In Review",done:"Done",archived:"Archived"};function Wt(s){const a=s.title?.trim()||s.description?.trim()||s.id;return a.length>80?`${a.slice(0,77)}...`:a}function qt({agentId:s,projectId:a,addToast:i}){const[o,d]=t.useState([]),[r,j]=t.useState(!0);return t.useEffect(()=>{let m=!1;return j(!0),lt(s,a).then(N=>{m||d(N)}).catch(N=>{m||(d([]),i(`Failed to load assigned tasks: ${q(N)}`,"error"))}).finally(()=>{m||j(!1)}),()=>{m=!0}},[s,a,i]),r?e.jsxs("div",{className:"agent-tasks-empty",children:[e.jsx(_,{size:16,className:"animate-spin"}),e.jsx("p",{children:"Loading assigned tasks..."})]}):o.length===0?e.jsxs("div",{className:"agent-tasks-empty",children:[e.jsx(Ts,{size:18}),e.jsx("p",{children:"No tasks assigned to this agent"})]}):e.jsx("div",{className:"agent-tasks-list",children:o.map(m=>e.jsxs("a",{className:"agent-task-item",href:`/tasks/${m.id}`,children:[e.jsxs("div",{className:"agent-task-row",children:[e.jsx("span",{className:"agent-task-id",children:m.id}),e.jsx("span",{className:`agent-task-column column-${m.column}`,children:Gt[m.column]})]}),e.jsx("div",{className:"agent-task-title",title:m.title||m.description||m.id,children:Wt(m)}),e.jsxs("div",{className:"agent-task-status",children:[m.status??"idle"," · Updated ",je(m.updatedAt)]})]},m.id))})}const pe=[{key:"maxRetries",label:"Max Retries",type:"number",placeholder:"3",hint:"Maximum number of automatic retries on task failure (0–10, default 3)",min:0,max:10},{key:"timeoutMs",label:"Task Timeout (ms)",type:"number",placeholder:"600000",hint:"Maximum time in ms before a task is considered timed out (minimum 60000ms, default 600000ms)",min:6e4,max:864e5},{key:"logLevel",label:"Log Level",type:"select",hint:"Verbosity of agent log output",options:[{value:"debug",label:"Debug"},{value:"info",label:"Info"},{value:"warn",label:"Warning"},{value:"error",label:"Error"}]}];function Yt(s){const a={};for(const i of pe){const o=s[i.key]?.trim();if(o){if(i.type==="number"){const d=Number(o);if(Number.isNaN(d)||!Number.isFinite(d)){a[i.key]=`"${i.label}" must be a valid number`;continue}i.min!==void 0&&d<i.min&&(a[i.key]=`"${i.label}" must be at least ${i.min.toLocaleString()}`),i.max!==void 0&&d>i.max&&(a[i.key]=`"${i.label}" must be at most ${i.max.toLocaleString()}`)}if(i.type==="select"){const d=i.options?.map(r=>r.value)??[];d.length>0&&!d.includes(o)&&(a[i.key]=`"${i.label}" must be one of: ${d.join(", ")}`)}}}return a}function Kt({agent:s,projectId:a,addToast:i,onSaved:o}){const[d,r]=t.useState(s.soul??""),[j,m]=t.useState(!1),[N,p]=t.useState(!1),[k,F]=t.useState(!1);t.useEffect(()=>{r(s.soul??""),p(!1),F(!1)},[s.id,s.soul]);const f=d!==(s.soul??""),z=async()=>{if(d.length>1e4){i("Soul must be at most 10,000 characters","error");return}m(!0);try{await vt(s.id,d,a),i("Soul saved","success"),p(!0),setTimeout(()=>p(!1),3e3),await o()}catch(L){i(`Failed to save soul: ${q(L)}`,"error")}finally{m(!1)}};return e.jsx("div",{className:"config-tab",children:e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Soul"}),e.jsx("p",{className:"config-description",children:"Define this agent's personality and identity."}),e.jsx("div",{className:"config-fields",children:e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-soul",children:"Agent Soul"}),e.jsx("div",{className:"agent-content-toolbar",children:e.jsxs("div",{className:"agent-content-mode-toggle",children:[e.jsxs("button",{className:`btn btn-sm ${k?"":"btn-primary"}`,onClick:()=>F(!1),disabled:!k,"aria-label":"Edit mode",children:[e.jsx(Ee,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${k?"btn-primary":""}`,onClick:()=>F(!0),disabled:k,"aria-label":"Preview mode",children:[e.jsx(Le,{size:14}),"Preview"]})]})}),k?d.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(De,{remarkPlugins:[$e],children:d})}):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:d,onChange:L=>{r(L.target.value),p(!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-task-create",disabled:!f||j,onClick:()=>void z(),children:j?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{size:16}),"Save Soul"]})}),!f&&N&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(Q,{size:14}),"Soul saved"]})]})]})})}function Zt({agent:s,projectId:a,addToast:i,onSaved:o}){const[d,r]=t.useState(s.memory??""),[j,m]=t.useState(!1),[N,p]=t.useState(!1),[k,F]=t.useState(!1),[f,z]=t.useState([]),[L,A]=t.useState(!1),[l,v]=t.useState(""),[C,B]=t.useState(""),[T,w]=t.useState(!1),[y,U]=t.useState(!1),[W,H]=t.useState(!1),[R,G]=t.useState(!1),[h,J]=t.useState(""),I=s.state==="running",u=d!==(s.memory??""),x=t.useMemo(()=>f.find(b=>b.path===l),[f,l]),K=x?Bt[x.layer]:"Select a memory file to view or edit.",c=t.useCallback(async b=>{U(!0);try{const O=await ot(s.id,b,a);v(O.path),B(O.content),w(!1),G(!1)}catch(O){i(`Failed to load agent memory file: ${q(O)}`,"error")}finally{U(!1)}},[s.id,a,i]),E=t.useCallback(async(b="")=>{A(!0);try{const{files:O}=await dt(s.id,a);if(z(O),O.length===0){v(""),B(""),w(!1);return}const le=It(O,b);await c(le)}catch(O){i(`Failed to load memory files: ${q(O)}`,"error"),z([]),v(""),B(""),w(!1)}finally{A(!1)}},[s.id,a,i,c]);t.useEffect(()=>{r(s.memory??""),p(!1),F(!1),J(""),G(!1),E()},[s.id,s.memory,E]);const V=async()=>{if(d.length>5e4){i("Memory must be at most 50,000 characters","error");return}m(!0);try{await jt(s.id,d,a),i("Memory saved","success"),p(!0),setTimeout(()=>p(!1),3e3),await o()}catch(b){i(`Failed to save memory: ${q(b)}`,"error")}finally{m(!1)}},g=async b=>{if(!(!b||b===l)){if(T){J("Save the current file before switching to another file.");return}J(""),await c(b)}},D=async()=>{if(l){H(!0);try{await Nt(s.id,l,C,a),w(!1),G(!0),setTimeout(()=>G(!1),3e3),J(""),await E(l),i("Agent memory file saved","success")}catch(b){i(`Failed to save agent memory file: ${q(b)}`,"error")}finally{H(!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."}),I&&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:[!I&&e.jsxs("button",{className:`btn btn-sm ${k?"":"btn-primary"}`,onClick:()=>F(!1),disabled:!k,"aria-label":"Edit mode",children:[e.jsx(Ee,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${k?"btn-primary":""}`,onClick:()=>F(!0),disabled:k,"aria-label":"Preview mode",children:[e.jsx(Le,{size:14}),"Preview"]})]})}),k?d.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(De,{remarkPlugins:[$e],children:d})}):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:d,readOnly:I,onChange:b=>{r(b.target.value),p(!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:l,disabled:L||y||W||f.length===0,onChange:b=>{g(b.target.value)},children:f.length===0?e.jsx("option",{value:"",children:"No memory files found"}):f.map(b=>e.jsxs("option",{value:b.path,children:[js[b.layer]," • ",b.label]},b.path))}),L&&e.jsxs("span",{className:"config-hint",style:{display:"inline-flex",gap:6,marginTop:8},children:[e.jsx(_,{size:14,className:"animate-spin"}),"Loading memory files…"]}),x&&e.jsxs("div",{className:"config-hint",style:{marginTop:8},children:[e.jsx("strong",{children:js[x.layer]})," · ",K,e.jsx("br",{}),x.size.toLocaleString()," bytes · Updated ",je(x.updatedAt)]}),e.jsx("textarea",{className:"input",rows:14,placeholder:"Select a memory file to view and edit its content...",value:C,readOnly:I||!l||y,onChange:b=>{B(b.target.value),w(!0),G(!1),J("")},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical",marginTop:8}}),y&&e.jsxs("span",{className:"config-hint",style:{display:"inline-flex",gap:6,marginTop:8},children:[e.jsx(_,{size:14,className:"animate-spin"}),"Loading file content…"]}),h&&e.jsx("span",{className:"config-hint",style:{display:"block",marginTop:8},children:h})]})]}),e.jsxs("div",{className:"config-actions",children:[!k&&e.jsx("button",{className:"btn btn-task-create",disabled:!u||j||I,onClick:()=>void V(),children:j?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{size:16}),"Save Memory"]})}),e.jsx("button",{className:"btn",disabled:!T||W||!l||I,onClick:()=>void D(),children:W?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Saving file…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{size:16}),"Save Memory File"]})}),!u&&N&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(Q,{size:14}),"Memory saved"]}),!T&&R&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(Q,{size:14}),"Memory file saved"]})]})]})})}function Qt({agent:s,projectId:a,addToast:i,onSaved:o}){const[d,r]=t.useState(s.instructionsText??""),[j,m]=t.useState(s.instructionsPath??""),[N,p]=t.useState(!1),[k,F]=t.useState(""),[f,z]=t.useState(!1),[L,A]=t.useState(!1),[l,v]=t.useState(!1),[C,B]=t.useState(!1),[T,w]=t.useState(!1),[y,U]=t.useState(!1);t.useEffect(()=>{const h=j.trim();if(!h){F(""),A(!1);return}z(!0),Ms("project",h).then(J=>{F(J.content),A(!1)}).catch(J=>{const I=q(J);I.includes("ENOENT")||I.includes("Not found")||I.includes("not found")?(F(""),A(!1)):(i(`Failed to load instructions file: ${I}`,"error"),F(""))}).finally(()=>{z(!1)})},[j,i]),t.useEffect(()=>{r(s.instructionsText??""),m(s.instructionsPath??""),w(!1),U(!1),p(!1)},[s.id,s.instructionsText,s.instructionsPath]);const W=(()=>{const h=d??"",J=s.instructionsText??"",I=j?.trim()??"",u=s.instructionsPath?.trim()??"";return h!==J||I!==u})(),H=async()=>{v(!0);try{await bt(s.id,{instructionsText:d||void 0,instructionsPath:j.trim()||void 0},a),i("Instructions saved","success"),w(!0),setTimeout(()=>w(!1),3e3),await o()}catch(h){i(`Failed to save instructions: ${q(h)}`,"error")}finally{v(!1)}},R=async()=>{const h=j.trim();if(!h){i("No instructions file path set","error");return}B(!0);try{await Fs("project",h,k),i("Instructions file saved","success"),A(!1),U(!0),setTimeout(()=>U(!1),3e3)}catch(J){i(`Failed to save instructions file: ${q(J)}`,"error")}finally{B(!1)}},G=!!j.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 ${N?"":"btn-primary"}`,onClick:()=>p(!1),disabled:!N,"aria-label":"Edit mode","data-testid":"instructions-edit-toggle",children:[e.jsx(Ee,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${N?"btn-primary":""}`,onClick:()=>p(!0),disabled:N,"aria-label":"Preview mode","data-testid":"instructions-preview-toggle",children:[e.jsx(Le,{size:14}),"Preview"]})]})}),N?d.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(De,{remarkPlugins:[$e],children:d})}):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:d,onChange:h=>{r(h.target.value),w(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),!N&&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:j,onChange:h=>{m(h.target.value),w(!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."})]})]}),!N&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!W||l,onClick:()=>void H(),children:l?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{size:16}),"Save Instructions"]})}),!W&&T&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(Q,{size:14}),"Instructions saved"]})]})]}),G&&e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Instructions File Editor"}),e.jsx("p",{className:"config-description",children:"Edit the instructions file directly. Changes are saved separately from the path configuration."}),e.jsx("div",{className:"config-fields",children:e.jsxs("div",{className:"config-field",children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[e.jsx("label",{htmlFor:"instructions-file-content",children:"File Content"}),f&&e.jsxs("span",{className:"config-hint",style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx(_,{size:12,className:"animate-spin"}),"Loading..."]}),L&&!f&&e.jsx("span",{className:"config-hint",style:{color:"var(--color-warning, #e3b541)"},children:"Unsaved changes"})]}),e.jsx("textarea",{id:"instructions-file-content",className:"input",rows:20,placeholder:"File content will appear here when loaded...",value:k,readOnly:f,onChange:h=>{F(h.target.value),A(!0),U(!1)},style:{fontFamily:"monospace",fontSize:"0.875rem",resize:"vertical"}}),e.jsx("span",{className:"config-hint",children:"Edit the markdown file content directly. Save separately using the button below."})]})}),e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!L||C,onClick:()=>void R(),children:C?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{size:16}),"Save File"]})}),!L&&y&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(Q,{size:14}),"File saved"]})]})]})]})}function Ns(s){const a=s??{},i={};return a.heartbeatIntervalMs!==void 0&&a.heartbeatIntervalMs!==null&&(i.heartbeatIntervalMs=String(Number(a.heartbeatIntervalMs)/1e3)),a.heartbeatTimeoutMs!==void 0&&a.heartbeatTimeoutMs!==null&&(i.heartbeatTimeoutMs=String(Number(a.heartbeatTimeoutMs)/1e3)),a.maxConcurrentRuns!==void 0&&a.maxConcurrentRuns!==null&&(i.maxConcurrentRuns=String(a.maxConcurrentRuns)),(a.messageResponseMode==="immediate"||a.messageResponseMode==="on-heartbeat")&&(i.messageResponseMode=a.messageResponseMode),i}function Ve(s){return s?.enabled!==!1}function ys(s){const a=(s??{}).budgetConfig,i={};return a&&(a.tokenBudget!==void 0&&a.tokenBudget!==null&&(i.tokenBudget=String(a.tokenBudget)),a.usageThreshold!==void 0&&a.usageThreshold!==null&&(i.usageThreshold=String(Number(a.usageThreshold)*100)),a.budgetPeriod!==void 0&&a.budgetPeriod!==null&&(i.budgetPeriod=String(a.budgetPeriod)),a.resetDay!==void 0&&a.resetDay!==null&&(i.resetDay=String(a.resetDay))),i}function Xt({agent:s,projectId:a,addToast:i,onSaved:o}){const[d,r]=t.useState(!1),[j,m]=t.useState(!1),[N,p]=t.useState(!1),[k,F]=t.useState(!1),[f,z]=t.useState(!1),[L,A]=t.useState(""),[l,v]=t.useState(!1),[C,B]=t.useState(null),[T,w]=t.useState(!1),y=s.heartbeatProcedurePath?.trim(),U=`.fusion/agents/${s.name.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||s.id.toLowerCase().replace(/[^a-z0-9]+/g,"-")||"agent"}-${s.id.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"agent"}/HEARTBEAT.md`,W=`.fusion/agents/${s.id}/HEARTBEAT.md`,H=s.id.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"agent",R=!!(y&&(y===U||y===W||new RegExp(`^\\.fusion/agents/[^/]+-${H}/HEARTBEAT\\.md$`).test(y))),G=!!y,h=t.useCallback(async x=>{p(!0),B(null);try{const K=await Ms("project",x,a);A(K.content),v(!1)}catch(K){const c=q(K);B(c),i(`Failed to load heartbeat procedure file: ${c}`,"error")}finally{p(!1)}},[i,a]);t.useEffect(()=>{m(!1),z(!1),A(""),v(!1),B(null),p(!1),F(!1),w(!1)},[s.id,y]);const J=async()=>{y&&(m(!0),await h(y))},I=async()=>{if(y){F(!0);try{await Fs("project",y,L,a),v(!1),w(!0),i("Heartbeat procedure file saved","success"),setTimeout(()=>w(!1),3e3)}catch(x){i(`Failed to save heartbeat procedure file: ${q(x)}`,"error")}finally{F(!1)}}},u=async()=>{r(!0);try{const x=await Ct(s.id,a);i(x.procedureFileSeeded?`Heartbeat procedure file ready at ${x.heartbeatProcedurePath}`:`Heartbeat procedure path set to ${x.heartbeatProcedurePath}`,"success"),await o()}catch(x){i(`Failed to upgrade heartbeat procedure: ${q(x)}`,"error")}finally{r(!1)}};return e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Heartbeat Procedure"}),e.jsxs("p",{className:"config-description",children:["The per-tick procedure this agent runs every wake. Defaults to a per-agent markdown file (for example ",e.jsx("code",{children:".fusion/agents/ceo-agent2736/HEARTBEAT.md"}),") that you can edit. Legacy id-only default paths remain valid. Resets on every tick — no need to restart the agent after editing."]}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsxs("span",{className:"config-hint",children:["Current path: ",e.jsx("code",{children:y||"(none — using built-in default)"})]}),G&&e.jsx("div",{className:"heartbeat-procedure-actions",children:e.jsx("button",{className:"btn btn-sm",onClick:()=>void J(),disabled:N,children:N?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Loading file…"]}):e.jsxs(e.Fragment,{children:[e.jsx(be,{size:16}),"View Heartbeat Markdown"]})})})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("button",{className:"btn",disabled:d||R,onClick:()=>void u(),"aria-label":"Upgrade agent to default heartbeat procedure file",children:d?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Upgrading…"]}):R?e.jsxs(e.Fragment,{children:[e.jsx(Q,{size:16}),"Already on default"]}):"Upgrade to Default Heartbeat Procedure"}),e.jsxs("span",{className:"config-hint",children:["Sets ",e.jsx("code",{children:"heartbeatProcedurePath"})," to"," ",e.jsx("code",{children:U})," ","and seeds the file from the built-in template if it doesn't exist. Each agent gets its own per-agent file, so edits stay scoped to this agent. Operator edits to the file are preserved."]})]})]}),j&&G&&y&&e.jsxs("div",{className:"config-fields heartbeat-procedure-viewer",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"heartbeat-procedure-file-content",children:"Heartbeat Procedure File"}),e.jsxs("div",{className:"agent-content-toolbar",children:[e.jsxs("div",{className:"agent-content-mode-toggle",children:[e.jsxs("button",{className:`btn btn-sm ${f?"":"btn-primary"}`,onClick:()=>z(!1),disabled:!f,"aria-label":"Heartbeat file edit mode",children:[e.jsx(Ee,{size:14}),"Edit"]}),e.jsxs("button",{className:`btn btn-sm ${f?"btn-primary":""}`,onClick:()=>z(!0),disabled:f,"aria-label":"Heartbeat file preview mode",children:[e.jsx(Le,{size:14}),"Preview"]})]}),N&&e.jsxs("span",{className:"config-hint heartbeat-procedure-status",children:[e.jsx(_,{size:12,className:"animate-spin"}),"Loading..."]}),l&&!N&&e.jsx("span",{className:"config-hint heartbeat-procedure-status heartbeat-procedure-status--warning",children:"Unsaved changes"})]}),f?L.trim()?e.jsx("div",{className:"agent-content-preview markdown-body",children:e.jsx(De,{remarkPlugins:[$e],children:L})}):e.jsx("div",{className:"agent-content-preview agent-content-placeholder",children:"No heartbeat procedure markdown content yet."}):e.jsx("textarea",{id:"heartbeat-procedure-file-content",className:"input",rows:16,value:L,readOnly:N,placeholder:"Heartbeat procedure markdown file content will appear here...",onChange:x=>{A(x.target.value),v(!0),w(!1)}}),C&&e.jsxs("span",{className:"config-error",children:["Failed to load file: ",C]}),e.jsxs("span",{className:"config-hint",children:["This editor writes directly to ",e.jsx("code",{children:y}),"."]})]}),!f&&e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!l||k||N,onClick:()=>void I(),children:k?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{size:16}),"Save Heartbeat File"]})}),!l&&T&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(Q,{size:14}),"File saved"]})]})]})]})}function ea({agent:s,projectId:a,addToast:i,onSaved:o,onHasChangesChange:d,onDelete:r}){const[j,m]=t.useState(s.name),[N,p]=t.useState(s.role),[k,F]=t.useState(s.title??""),[f,z]=t.useState(s.icon??""),[L,A]=t.useState(s.reportsTo??""),[l,v]=t.useState([]),[C,B]=t.useState(!1),[T,w]=t.useState(()=>{const n={};for(const M of pe){const P=s.metadata[M.key];P!=null&&(n[M.key]=String(P))}return n}),[y,U]=t.useState(()=>Ns(s.runtimeConfig)),[W,H]=t.useState(()=>Ve(s.runtimeConfig)),[R,G]=t.useState(()=>ys(s.runtimeConfig)),[h,J]=t.useState(s.bundleConfig?.mode??""),[I,u]=t.useState(s.bundleConfig?.entryFile??"AGENTS.md"),[x,K]=t.useState(s.bundleConfig?.externalPath??""),[c,E]=t.useState(s.bundleConfig?.files??[]),[V,g]=t.useState(Array.isArray(s.metadata?.skills)?s.metadata.skills:[]),[D,b]=t.useState([]),[O,le]=t.useState(!1),[Ne,de]=t.useState([]),[Pe,Ke]=t.useState(!1),ye=(()=>{const n=s.runtimeConfig??{};return n.modelProvider&&n.modelId?`${n.modelProvider}/${n.modelId}`:typeof n.model=="string"&&n.model.includes("/")?n.model:""})(),ce=typeof s.runtimeConfig?.runtimeHint=="string"?s.runtimeConfig.runtimeHint:"",[ae,ze]=t.useState(ce?"runtime":"model"),[oe,Ze]=t.useState(ye),[Se,Be]=t.useState(ce),ke=L.trim(),Qe=t.useMemo(()=>l.filter(n=>n.id!==s.id),[l,s.id]),Es=!!ke&&!Qe.some(n=>n.id===ke);t.useEffect(()=>{let n=!1;return B(!0),ut(void 0,a).then(M=>{n||v(M)}).catch(()=>{n||v([])}).finally(()=>{n||B(!1)}),()=>{n=!0}},[a]),t.useEffect(()=>{le(!0),mt().then(n=>b(n.models)).catch(()=>{}).finally(()=>le(!1))},[]),t.useEffect(()=>{Ke(!0),Rs(a).then(de).catch(()=>de([])).finally(()=>Ke(!1))},[a]);const[ne,He]=t.useState(null),[Xe,es]=t.useState(!1);t.useEffect(()=>{Ue(s.id,a).then(He).catch(()=>He(null))},[s.id,a]);const Ls=async()=>{es(!0);try{await St(s.id,a),i("Budget usage reset successfully","success");const n=await Ue(s.id,a);He(n)}catch(n){i(`Failed to reset budget: ${q(n)}`,"error")}finally{es(!1)}},[ss,ts]=t.useState(!1),[$,Ce]=t.useState({}),[Ds,ue]=t.useState(!1),as=s.state==="idle"||s.state==="terminated",he=t.useRef(null),ns=t.useRef(null);t.useEffect(()=>()=>{he.current&&clearTimeout(he.current)},[]);const ie=(()=>{if(j!==s.name||N!==s.role||k!==(s.title??"")||f!==(s.icon??"")||L!==(s.reportsTo??"")||h!==(s.bundleConfig?.mode??"")||I!==(s.bundleConfig?.entryFile??"AGENTS.md")||x!==(s.bundleConfig?.externalPath??"")||JSON.stringify(c)!==JSON.stringify(s.bundleConfig?.files??[]))return!0;for(const Z of pe){const re=T[Z.key]?.trim()??"",X=s.metadata[Z.key]!==void 0&&s.metadata[Z.key]!==null?String(s.metadata[Z.key]):"";if(re!==X)return!0}const n=s.runtimeConfig??{};if(W!==Ve(s.runtimeConfig))return!0;for(const Z of["heartbeatIntervalMs","heartbeatTimeoutMs","maxConcurrentRuns","messageResponseMode"]){const re=y[Z]?.trim()??"";let X=n[Z]!==void 0&&n[Z]!==null?String(n[Z]):"";if((Z==="heartbeatIntervalMs"||Z==="heartbeatTimeoutMs")&&X&&(X=String(Number(X)/1e3)),re!==X)return!0}const M=n.budgetConfig;for(const Z of["tokenBudget","budgetPeriod","resetDay"]){const re=R[Z]?.trim()??"",X=M?.[Z]!==void 0&&M?.[Z]!==null?String(M[Z]):"";if(re!==X)return!0}const P=R.usageThreshold?.trim()??"",se=M?.usageThreshold!==void 0&&M?.usageThreshold!==null?String(Number(M.usageThreshold)*100):"";if(P!==se)return!0;const ge=Array.isArray(s.metadata?.skills)?s.metadata.skills:[];return JSON.stringify(V)!==JSON.stringify(ge)||ae!==(ce?"runtime":"model")||oe!==ye||Se!==ce})(),is=t.useRef(null);t.useEffect(()=>{d&&is.current!==ie&&(is.current=ie,d(ie))},[ie,d]),t.useEffect(()=>()=>{d?.(!1)},[d]),t.useEffect(()=>{const n={id:s.id,updatedAt:s.updatedAt},M=ns.current;(!M||M.id!==n.id||M.updatedAt!==n.updatedAt)&&(ie||(ns.current=n,U(Ns(s.runtimeConfig)),H(Ve(s.runtimeConfig)),G(ys(s.runtimeConfig)),Ze(ye),Be(ce),ze(ce?"runtime":"model")))},[s,ie,ye,ce]);const rs=(n,M)=>{w(P=>({...P,[n]:M})),ue(!1),$[n]&&Ce(P=>{const se={...P};return delete se[n],se})},we=(n,M)=>{U(P=>({...P,[n]:M})),ue(!1),$[n]&&Ce(P=>{const se={...P};return delete se[n],se})},$s=n=>{H(n),ue(!1)},Re=(n,M)=>{G(P=>({...P,[n]:M})),ue(!1),$[n]&&Ce(P=>{const se={...P};return delete se[n],se})},Ps=async()=>{const n=Yt(T);for(const[S,te]of Object.entries({heartbeatIntervalMs:{label:"Heartbeat Interval",min:1},heartbeatTimeoutMs:{label:"Heartbeat Timeout",min:5},maxConcurrentRuns:{label:"Max Concurrent Runs",min:1}})){const fe=y[S]?.trim();if(!fe)continue;const Oe=Number(fe);Number.isNaN(Oe)||!Number.isFinite(Oe)?n[S]=`"${te.label}" must be a valid number`:Oe<te.min&&(n[S]=`"${te.label}" must be at least ${te.min.toLocaleString()}`)}const M=y.messageResponseMode?.trim();M&&!["immediate","on-heartbeat"].includes(M)&&(n.messageResponseMode='"Message Response Mode" must be either immediate or on-heartbeat');const P=R.tokenBudget?.trim();if(P){const S=Number(P);Number.isNaN(S)||!Number.isFinite(S)?n.tokenBudget='"Token Budget" must be a valid number':S<=0&&(n.tokenBudget='"Token Budget" must be greater than 0')}const se=R.usageThreshold?.trim();if(se){const S=Number(se);Number.isNaN(S)||!Number.isFinite(S)?n.usageThreshold='"Usage Threshold" must be a valid number':(S<1||S>100)&&(n.usageThreshold='"Usage Threshold" must be between 1 and 100')}const ge=R.budgetPeriod?.trim();ge&&!["daily","weekly","monthly","lifetime"].includes(ge)&&(n.budgetPeriod='"Budget Period" must be one of: daily, weekly, monthly, lifetime');const Z=R.resetDay?.trim(),re=ge||"lifetime";if(Z){const S=Number(Z);Number.isNaN(S)||!Number.isFinite(S)?n.resetDay='"Reset Day" must be a valid number':re==="weekly"?(S<0||S>6||!Number.isInteger(S))&&(n.resetDay='"Reset Day" must be between 0 (Sunday) and 6 (Saturday) for weekly period'):re==="monthly"&&(S<1||S>31||!Number.isInteger(S))&&(n.resetDay='"Reset Day" must be between 1 and 31 for monthly period')}if(Object.keys(n).length>0){Ce(n),i("Please fix validation errors before saving","error");return}const X={...s.metadata};for(const S of pe){const te=T[S.key]?.trim();te?S.type==="number"?X[S.key]=Number(te):X[S.key]=te:delete X[S.key]}V.length>0?X.skills=V:delete X.skills;const Y={...s.runtimeConfig};Y.enabled=W;for(const S of["heartbeatIntervalMs","heartbeatTimeoutMs","maxConcurrentRuns"]){const te=y[S]?.trim();if(!te)delete Y[S];else{const fe=Number(te);Y[S]=S==="maxConcurrentRuns"?fe:fe*1e3}}const ls=y.messageResponseMode?.trim();if(ls?Y.messageResponseMode=ls:delete Y.messageResponseMode,ae==="runtime")Se.trim()?Y.runtimeHint=Se.trim():delete Y.runtimeHint,delete Y.modelProvider,delete Y.modelId,delete Y.model;else if(delete Y.runtimeHint,oe.trim()){const S=oe.indexOf("/");S!==-1&&(Y.modelProvider=oe.slice(0,S),Y.modelId=oe.slice(S+1),Y.model=oe.trim())}else delete Y.modelProvider,delete Y.modelId,delete Y.model;const me={},cs=R.tokenBudget?.trim(),os=R.usageThreshold?.trim(),ds=R.budgetPeriod?.trim(),us=R.resetDay?.trim();cs&&(me.tokenBudget=Number(cs)),os&&(me.usageThreshold=Number(os)/100),ds&&(me.budgetPeriod=ds),us&&(me.resetDay=Number(us)),Object.keys(me).length>0?Y.budgetConfig=me:delete Y.budgetConfig;let Ie;h&&(Ie={mode:h,entryFile:I||"AGENTS.md",files:c.length>0?c:["AGENTS.md"]},h==="external"&&x.trim()&&(Ie.externalPath=x.trim())),ts(!0);try{await kt(s.id,{name:j.trim()||void 0,role:N,title:k.trim()||void 0,icon:f.trim()||void 0,reportsTo:L.trim()||void 0,metadata:X,runtimeConfig:Y,bundleConfig:Ie},a),i("Settings saved","success"),ue(!0),he.current&&clearTimeout(he.current),he.current=setTimeout(()=>ue(!1),3e3),await o()}catch(S){i(`Failed to save settings: ${q(S)}`,"error")}finally{ts(!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:j,onChange:n=>m(n.target.value)})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-role",children:"Role"}),e.jsxs("select",{id:"agent-role",className:"select",value:N,onChange:n=>p(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=>F(n.target.value)})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-icon",children:"Icon"}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:f,onChange:n=>z(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:L,onChange:n=>A(n.target.value),disabled:C,children:[e.jsx("option",{value:"",children:"No manager"}),Es&&e.jsxs("option",{value:ke,children:["Unknown manager (",ke,")"]}),Qe.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(wt,{id:"agent-skills",label:"Skills",value:V,onChange:g,projectId:a})})})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Model"}),e.jsx("p",{className:"config-description",children:"Choose either a built-in model or a plugin runtime for this agent. These options are mutually exclusive."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{children:"Runtime Source"}),e.jsxs("div",{className:"config-runtime-tabs",role:"tablist","aria-label":"Runtime source",children:[e.jsx("button",{type:"button",className:`config-runtime-tab${ae==="model"?" active":""}`,role:"tab","aria-selected":ae==="model",tabIndex:ae==="model"?0:-1,onClick:()=>{ze("model"),Be("")},children:"Built-in Model"}),e.jsx("button",{type:"button",className:`config-runtime-tab${ae==="runtime"?" active":""}`,role:"tab","aria-selected":ae==="runtime",tabIndex:ae==="runtime"?0:-1,onClick:()=>ze("runtime"),children:"Plugin Runtime"})]})]}),ae==="model"?e.jsx("div",{className:"config-field",children:e.jsx(ht,{models:D,value:oe,onChange:Ze,placeholder:"Use global default",label:"Agent Model",disabled:O})}):e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),Pe?e.jsx("span",{className:"config-hint",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:Se,onChange:n=>Be(n.target.value),children:[e.jsx("option",{value:"",children:Ne.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),Ne.map(n=>e.jsx("option",{value:n.runtimeId,children:n.description?`${n.name} — ${n.description}`:n.name},`${n.pluginId}:${n.runtimeId}`))]})]})]})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Heartbeat Settings"}),e.jsx("p",{className:"config-description",children:"Configure how this agent's heartbeat is monitored. Leave a field empty to use system defaults."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsxs("label",{className:"checkbox-label",htmlFor:"hb-enabled",children:[e.jsx("input",{id:"hb-enabled",type:"checkbox",checked:W,onChange:n=>$s(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:ee("input",!!$.heartbeatIntervalMs&&"input--error"),placeholder:String(Je/1e3),value:y.heartbeatIntervalMs??"",onChange:n=>we("heartbeatIntervalMs",n.target.value)}),$.heartbeatIntervalMs?e.jsx("span",{className:"config-error",children:$.heartbeatIntervalMs}):e.jsxs("span",{className:"config-hint",children:["How often heartbeats are checked. Leave empty for system default (",Je/1e3,"s / ",Ht,")."]})]}),e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"hb-heartbeatTimeoutMs",children:"Heartbeat Timeout (s)"}),e.jsx("input",{id:"hb-heartbeatTimeoutMs",type:"text",inputMode:"numeric",className:ee("input",!!$.heartbeatTimeoutMs&&"input--error"),placeholder:"60",value:y.heartbeatTimeoutMs??"",onChange:n=>we("heartbeatTimeoutMs",n.target.value)}),$.heartbeatTimeoutMs?e.jsx("span",{className:"config-error",children:$.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:ee("input",!!$.maxConcurrentRuns&&"input--error"),placeholder:"1",value:y.maxConcurrentRuns??"",onChange:n=>we("maxConcurrentRuns",n.target.value)}),$.maxConcurrentRuns?e.jsx("span",{className:"config-error",children:$.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:ee("select",!!$.messageResponseMode&&"input--error"),value:y.messageResponseMode??"",onChange:n=>we("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"})]}),$.messageResponseMode?e.jsx("span",{className:"config-error",children:$.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:ee("input",!!$.tokenBudget&&"input--error"),placeholder:"No limit",value:R.tokenBudget??"",onChange:n=>Re("tokenBudget",n.target.value)}),$.tokenBudget?e.jsx("span",{className:"config-error",children:$.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:ee("input",!!$.usageThreshold&&"input--error"),placeholder:"80",value:R.usageThreshold??"",onChange:n=>Re("usageThreshold",n.target.value)}),$.usageThreshold?e.jsx("span",{className:"config-error",children:$.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:ee("select",!!$.budgetPeriod&&"input--error"),value:R.budgetPeriod??"",onChange:n=>Re("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"})]}),$.budgetPeriod?e.jsx("span",{className:"config-error",children:$.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:ee("input",!!$.resetDay&&"input--error"),placeholder:"Auto",value:R.resetDay??"",onChange:n=>Re("resetDay",n.target.value)}),$.resetDay?e.jsx("span",{className:"config-error",children:$.resetDay}):e.jsx("span",{className:"config-hint",children:R.budgetPeriod==="weekly"?"Day of week (0=Sunday to 6=Saturday) for reset.":R.budgetPeriod==="monthly"?"Day of month (1-31) for reset.":"Day for reset (weekly: 0-6, monthly: 1-31). Leave empty for automatic."})]}),ne?.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:ee("budget-progress-bar__fill",(ne.usagePercent??0)>=100?"budget-progress-bar__fill--red":(ne.usagePercent??0)>=80?"budget-progress-bar__fill--amber":"budget-progress-bar__fill--green"),style:{width:`${Math.min(ne.usagePercent??0,100)}%`}})}),e.jsxs("span",{className:"budget-progress-label",children:[(ne.currentUsage??0).toLocaleString()," / ",(ne.budgetLimit??0).toLocaleString()," tokens (",Math.round(ne.usagePercent??0),"% used)"]})]})]}),ne?.budgetLimit!=null&&e.jsx("div",{className:"config-field",children:e.jsx("button",{className:"btn btn-reset-budget",onClick:()=>void Ls(),disabled:Xe,children:Xe?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:14,className:"animate-spin"}),"Resetting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14}),"Reset Budget Usage"]})})})]})]}),e.jsxs("div",{className:"config-section",children:[e.jsx("h3",{children:"Instruction Bundle"}),e.jsx("p",{className:"config-description",children:"Configure the agent's instruction bundle. Leave empty to use inline instructions only."}),e.jsxs("div",{className:"config-fields",children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"bundle-mode",children:"Bundle Mode"}),e.jsxs("select",{id:"bundle-mode",className:"select",value:h,onChange:n=>J(n.target.value),children:[e.jsx("option",{value:"",children:"None (use inline instructions)"}),e.jsx("option",{value:"managed",children:"Managed (system-managed directory)"}),e.jsx("option",{value:"external",children:"External (user-specified path)"})]}),e.jsxs("span",{className:"config-hint",children:[h==="managed"&&"Files will be stored in a system-managed directory within .fusion/agents/",h==="external"&&"Specify an external directory path for the instruction files",!h&&"Select a mode to enable instruction bundling"]})]}),h&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"bundle-entry-file",children:"Entry File"}),e.jsx("input",{id:"bundle-entry-file",type:"text",className:"input",placeholder:"AGENTS.md",value:I,onChange:n=>u(n.target.value)}),e.jsx("span",{className:"config-hint",children:"Primary instructions file name (default: AGENTS.md)"})]}),h==="external"&&e.jsxs("div",{className:"config-field",children:[e.jsx("label",{htmlFor:"bundle-external-path",children:"External Path"}),e.jsx("input",{id:"bundle-external-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/my-agent",value:x,onChange:n=>K(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:c.join(", "),onChange:n=>E(n.target.value.split(",").map(M=>M.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:pe.map(n=>{const M=!!$[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:ee("select",M&&"input--error"),value:T[n.key]??"",onChange:P=>rs(n.key,P.target.value),children:[e.jsx("option",{value:"",children:"System Default"}),n.options?.map(P=>e.jsx("option",{value:P.value,children:P.label},P.value))]}):e.jsx("input",{id:`adv-${n.key}`,type:"text",inputMode:n.type==="number"?"numeric":void 0,className:ee("input",M&&"input--error"),placeholder:n.placeholder,value:T[n.key]??"",onChange:P=>rs(n.key,P.target.value)}),M&&e.jsx("span",{className:"config-error",children:$[n.key]}),!M&&n.hint&&e.jsx("span",{className:"config-hint",children:n.hint})]},n.key)})}),e.jsxs("div",{className:"config-actions",children:[e.jsx("button",{className:"btn btn-task-create",disabled:!ie||ss,onClick:()=>void Ps(),children:ss?e.jsxs(e.Fragment,{children:[e.jsx(_,{size:16,className:"animate-spin"}),"Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{size:16}),"Save Settings"]})}),!ie&&Ds&&e.jsxs("span",{className:"config-saved-indicator",children:[e.jsx(Q,{size:14}),"Settings saved"]})]})]}),e.jsx(Xt,{agent:s,projectId:a,addToast:i,onSaved:o}),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:!as||!r,onClick:()=>void r?.(),children:[e.jsx(Te,{size:16}),"Delete Agent"]}),e.jsx("span",{className:"config-danger-note",children:as?"Deletion is permanent and cannot be undone.":`Agent deletion is only available when state is idle or terminated (current state: ${s.state}).`})]})})]})]})}function sa({agentId:s,projectId:a,onChildClick:i}){const[o,d]=t.useState([]),[r,j]=t.useState(!0);return t.useEffect(()=>{j(!0),ct(s,a).then(d).finally(()=>j(!1))},[s,a]),r?e.jsxs("div",{className:"detail-section",children:[e.jsx("div",{className:"detail-section-header",children:e.jsx("h3",{children:"Employees"})}),e.jsxs("div",{className:"detail-section-body",style:{display:"flex",alignItems:"center",gap:8,padding:16},children:[e.jsx(_,{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:["(",o.length,")"]})]}),e.jsx("div",{className:"detail-section-body",children:o.length===0?e.jsxs("div",{className:"agent-empty",style:{padding:24},children:[e.jsx(qe,{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:o.map(m=>{const N=Ye[m.state];return e.jsxs("div",{className:"agent-tree__node agent-is-child",onClick:()=>i?.(m.id),role:"button",tabIndex:0,onKeyDown:p=>p.key==="Enter"&&i?.(m.id),style:{cursor:i?"pointer":"default"},children:[e.jsx("span",{className:"agent-tree__icon",children:m.icon??"🤖"}),e.jsx("span",{className:"agent-tree__name",children:m.name}),e.jsx("span",{className:"agent-tree__badge",style:{background:N?.bg??"var(--state-idle-bg)",color:N?.text??"var(--state-idle-text)",border:`1px solid ${N?.border??"var(--state-idle-border)"}`},children:m.state})]},m.id)})})})]})}export{ca as AgentDetailView};
|