@runfusion/fusion 0.32.0 → 0.34.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 +24129 -11045
- package/dist/client/.vite/manifest.json +62 -61
- package/dist/client/assets/{AgentDetailView-CnFf_eBZ.js → AgentDetailView-CzqwIIpv.js} +3 -3
- package/dist/client/assets/{AgentPermissionPolicyEditor-Cmkt9Z01.js → AgentPermissionPolicyEditor-2eoM2XQH.js} +2 -2
- package/dist/client/assets/AgentsView-BrtAvhJl.js +29 -0
- package/dist/client/assets/ChatView-BuIe4MhL.js +6 -0
- package/dist/client/assets/DevServerView-CF6FPLRb.js +1 -0
- package/dist/client/assets/{DirectoryPicker-DctpCNrd.js → DirectoryPicker-BpvHQxhu.js} +1 -1
- package/dist/client/assets/{DocumentsView-DORp5JjC.js → DocumentsView-RMWZBJ-y.js} +1 -1
- package/dist/client/assets/{EvalsView-CYVJ1pbc.js → EvalsView-DtVxpc4T.js} +1 -1
- package/dist/client/assets/{ExperimentalAgentOnboardingModal-BULVNAiq.js → ExperimentalAgentOnboardingModal-fzJmb-yG.js} +2 -2
- package/dist/client/assets/{GoalsView-bmpZKOI_.js → GoalsView-BAchggxo.js} +1 -1
- package/dist/client/assets/{InsightsView-mmtem0RU.js → InsightsView-B8892IbG.js} +1 -1
- package/dist/client/assets/{MemoryView-HVpO1fCH.js → MemoryView-Cfp1WmAm.js} +2 -2
- package/dist/client/assets/NodesView-Dt26DSEQ.js +14 -0
- package/dist/client/assets/{PiExtensionsManager-Cyfas2VT.js → PiExtensionsManager-xHU56SMh.js} +2 -2
- package/dist/client/assets/{PluginManager-C7QDE3Lk.js → PluginManager-37WUEOmp.js} +1 -1
- package/dist/client/assets/ResearchView-pu88M5xL.js +1 -0
- package/dist/client/assets/SecretsView-BT7ofJLN.js +1 -0
- package/dist/client/assets/{SecretsView-BFhVwJu6.css → SecretsView-D5bHZ-wM.css} +1 -1
- package/dist/client/assets/SettingsModal-0gevFhXV.css +1 -0
- package/dist/client/assets/SettingsModal-Cz9MHNGg.js +31 -0
- package/dist/client/assets/{SettingsModal-YCJM5is3.js → SettingsModal-DxYXsn08.js} +1 -1
- package/dist/client/assets/{SetupWizardModal-BT-mj3VD.js → SetupWizardModal-yWTk3Cac.js} +1 -1
- package/dist/client/assets/{SkillsView-Db7dYpqd.js → SkillsView-CWNfKNTs.js} +1 -1
- package/dist/client/assets/{StashRecoveryView-CSYYcWux.js → StashRecoveryView-D0t4IIX-.js} +1 -1
- package/dist/client/assets/{TodoView-zqCqfy26.js → TodoView-B4W1Lhy6.js} +2 -2
- package/dist/client/assets/{dashboard-view-PpcsMDvN.js → dashboard-view-4OCJIthP.js} +1 -1
- package/dist/client/assets/{folder-open-mxsFQlAX.js → folder-open-BTdhwFQ5.js} +1 -1
- package/dist/client/assets/index-D4nQgFjo.js +742 -0
- package/dist/client/assets/index-k4s0JWir.css +1 -0
- package/dist/client/assets/{upload-j7JjaJzG.js → upload-kESyjow_.js} +1 -1
- package/dist/client/assets/{users-DZ_0WcB6.js → users-DNXMrdcp.js} +1 -1
- package/dist/client/index.html +102 -3
- package/dist/client/version.json +1 -1
- package/dist/droid-cli/package.json +1 -1
- package/dist/extension.js +18838 -6745
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/plugins/fusion-plugin-cli-printing-press/package.json +1 -1
- package/dist/plugins/fusion-plugin-cursor-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-dependency-graph/package.json +1 -1
- package/dist/plugins/fusion-plugin-droid-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/src/dashboard/__tests__/ReportsView.test.tsx +15 -0
- package/dist/plugins/fusion-plugin-reports/src/dashboard/test-setup.ts +9 -1
- package/dist/plugins/fusion-plugin-roadmap/package.json +1 -1
- package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +1 -1
- package/package.json +1 -1
- package/skill/fusion/references/extension-tools.md +4 -1
- package/skill/fusion/references/fusion-capabilities.md +1 -1
- package/dist/client/assets/AgentsView-LkVv9hph.js +0 -34
- package/dist/client/assets/ChatView-DYjECCRG.js +0 -1
- package/dist/client/assets/DevServerView-D7legPr1.js +0 -1
- package/dist/client/assets/NodesView-CM0eoCP8.js +0 -14
- package/dist/client/assets/ResearchView-Bn2WxwnQ.js +0 -1
- package/dist/client/assets/SecretsView-DgrrgzFc.js +0 -1
- package/dist/client/assets/SettingsModal-BCZrCLl3.js +0 -31
- package/dist/client/assets/SettingsModal-BZBV2kLr.css +0 -1
- package/dist/client/assets/index-Ba-F8c1g.js +0 -732
- package/dist/client/assets/index-D4HhaIOp.css +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusion/pi-claude-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
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,
|
|
@@ -3,6 +3,21 @@ import { describe, expect, it, vi } from "vitest";
|
|
|
3
3
|
import * as reportsHook from "../useReports.js";
|
|
4
4
|
import { ReportsView } from "../ReportsView.js";
|
|
5
5
|
|
|
6
|
+
// ReportDetailPanel transitively calls useReportPreview → fetch(), and jsdom
|
|
7
|
+
// has no fetch. The rejection lands after teardown and React's state update
|
|
8
|
+
// then references `window`, surfacing as an unhandled error that fails the
|
|
9
|
+
// suite. Stub the preview API to resolve synchronously.
|
|
10
|
+
vi.mock("../api.js", () => ({
|
|
11
|
+
listReports: vi.fn().mockResolvedValue([]),
|
|
12
|
+
getReport: vi.fn().mockResolvedValue(null),
|
|
13
|
+
getReportPreviewHtml: vi.fn().mockResolvedValue(""),
|
|
14
|
+
getReportExportUrl: vi.fn().mockReturnValue(""),
|
|
15
|
+
approveReport: vi.fn().mockResolvedValue(null),
|
|
16
|
+
rejectReport: vi.fn().mockResolvedValue(null),
|
|
17
|
+
publishReport: vi.fn().mockResolvedValue(null),
|
|
18
|
+
getShareBlocks: vi.fn().mockResolvedValue({}),
|
|
19
|
+
}));
|
|
20
|
+
|
|
6
21
|
describe("ReportsView", () => {
|
|
7
22
|
it("renders list and compare toggle", () => {
|
|
8
23
|
vi.spyOn(reportsHook, "useReports").mockReturnValue({
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import "@testing-library/jest-dom/vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { cleanup } from "@testing-library/react";
|
|
3
|
+
import { afterEach, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
// @testing-library/react only auto-registers cleanup when vitest globals are
|
|
6
|
+
// enabled. We don't enable globals here, so we wire it manually — otherwise
|
|
7
|
+
// React leaves the test tree mounted, its scheduler fires a deferred update
|
|
8
|
+
// via setImmediate after the jsdom environment is torn down, and the suite
|
|
9
|
+
// fails with "ReferenceError: window is not defined".
|
|
10
|
+
afterEach(() => cleanup());
|
|
3
11
|
|
|
4
12
|
if (typeof window !== "undefined") {
|
|
5
13
|
Object.defineProperty(window, "matchMedia", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runfusion/fusion",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
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",
|
|
@@ -118,11 +118,12 @@ Unarchive an archived task (move from archived → done). Restores the task to t
|
|
|
118
118
|
|
|
119
119
|
### fn_task_delete
|
|
120
120
|
|
|
121
|
-
Soft-delete a task from active Fusion board views. The task row and artifacts are preserved
|
|
121
|
+
Soft-delete a task from active Fusion board views. The task row and artifacts are preserved; optional allowResurrection marks the ID for intentional recreation.
|
|
122
122
|
|
|
123
123
|
| Parameter | Type | Required | Description |
|
|
124
124
|
|-----------|------|----------|-------------|
|
|
125
125
|
| `id` | string | ✓ | Task ID to delete (e.g. FN-001) |
|
|
126
|
+
| `allowResurrection` | boolean | — | When true, mark this tombstone as explicitly reusable for future recreation. |
|
|
126
127
|
|
|
127
128
|
### fn_task_plan
|
|
128
129
|
|
|
@@ -131,6 +132,7 @@ Create a task via AI-guided planning mode — interactive conversation to refine
|
|
|
131
132
|
| Parameter | Type | Required | Description |
|
|
132
133
|
|-----------|------|----------|-------------|
|
|
133
134
|
| `description` | string | — | Initial plan description (optional) — the AI will ask clarifying questions if not provided |
|
|
135
|
+
| `baseBranch` | string | — | Optional base branch for the task created from this planning session |
|
|
134
136
|
|
|
135
137
|
## GitHub Tools
|
|
136
138
|
|
|
@@ -176,6 +178,7 @@ Create a new mission — a high-level objective that can span multiple milestone
|
|
|
176
178
|
| `title` | string | ✓ | Mission title — brief but descriptive |
|
|
177
179
|
| `description` | string | — | Detailed mission objectives and context |
|
|
178
180
|
| `autoAdvance` | boolean | — | Automatically activate the next pending slice when the current slice completes |
|
|
181
|
+
| `baseBranch` | string | — | Optional integration base branch for tasks triaged from this mission |
|
|
179
182
|
|
|
180
183
|
### fn_mission_list
|
|
181
184
|
|
|
@@ -24,7 +24,7 @@ All skill/extension tool invocations in this catalog use the public `fn_*` names
|
|
|
24
24
|
| `fn_task_refine` | Request a refinement of a completed or in-review task. Creates a new follow-up task in planning that references the original task as a dependency. Use this when a done or in-review task needs additional work, improvements, or follow-up changes. |
|
|
25
25
|
| `fn_task_archive` | Archive a done task (move from done → archived). Archived tasks are preserved for historical reference but moved out of the main board view. |
|
|
26
26
|
| `fn_task_unarchive` | Unarchive an archived task (move from archived → done). Restores the task to the done column. |
|
|
27
|
-
| `fn_task_delete` | Soft-delete a task from active Fusion board views. The task row and artifacts are preserved
|
|
27
|
+
| `fn_task_delete` | Soft-delete a task from active Fusion board views. The task row and artifacts are preserved; optional allowResurrection marks the ID for intentional recreation. |
|
|
28
28
|
| `fn_task_import_github` | Import GitHub issues as Fusion tasks. Fetches open issues from a repository and creates tasks in the planning column. Each task includes the issue title and body with a link to the source issue. |
|
|
29
29
|
| `fn_task_import_github_issue` | Import a specific GitHub issue as a Fusion task. Fetches the issue by number and creates a single task in the planning column with the issue title and body. |
|
|
30
30
|
| `fn_task_browse_github_issues` | List open GitHub issues from a repository to browse before importing. Returns issue numbers, titles, and URLs for selection. Use with fn_task_import_github_issue to import specific issues by number. |
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-CnFf_eBZ.js","assets/vendor-react-K0fH_qHe.js","assets/index-Ba-F8c1g.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/vendor-codemirror-jBKmHyH0.js","assets/index-D4HhaIOp.css","assets/AgentPermissionPolicyEditor-Cmkt9Z01.js","assets/AgentPermissionPolicyEditor-CGxjOr6G.css","assets/ExperimentalAgentOnboardingModal-BULVNAiq.js","assets/ExperimentalAgentOnboardingModal-BNpveCEk.css","assets/AgentDetailView-CY-O6VkV.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as at,A as Ze,C as ct,Z as Na,s as ya,r as wt,F as Ct,f as ka,a as wa,b as ta,B as St,u as aa,d as gt,e as Ca,g as Sa,h as Aa,i as Ra,j as Ot,k as dt,P as Ta,l as Ma,m as _a,n as Ea,o as Dt,G as $a,S as La,L as ht,T as pt,R as qe,X as Ht,p as Ia,q as Pa,t as it,v as za,w as Bt,x as Fa,y as Oa,z as Ee,D as xt,E as Da,M as Ha,H as Ba,I as Wt,N as Gt,J as Vt,K as Wa,O as Ga,Q as Va,U as Ka,V as bt,W as Kt,Y as Ua,_ as Ya,$ as Xa,a0 as rt,a1 as qa,a2 as Ut,a3 as Za,a4 as Ja,a5 as Qa}from"./index-Ba-F8c1g.js";import{r as a,j as e,a as es}from"./vendor-react-K0fH_qHe.js";import{A as ts,S as as,E as ss,f as ns}from"./ExperimentalAgentOnboardingModal-BULVNAiq.js";import{U as At}from"./upload-j7JjaJzG.js";import{F as ls}from"./folder-open-mxsFQlAX.js";import"./vendor-xterm-DzcZoU0P.js";import"./vendor-codemirror-jBKmHyH0.js";/**
|
|
3
|
-
* @license lucide-react v1.7.0 - ISC
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the ISC license.
|
|
6
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/const is=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],rs=at("info",is);/**
|
|
8
|
-
* @license lucide-react v1.7.0 - ISC
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the ISC license.
|
|
11
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
-
*/const os=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1",key:"cif1o7"}]],cs=at("list-todo",os);/**
|
|
13
|
-
* @license lucide-react v1.7.0 - ISC
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the ISC license.
|
|
16
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/const ds=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],us=at("sliders-horizontal",ds);/**
|
|
18
|
-
* @license lucide-react v1.7.0 - ISC
|
|
19
|
-
*
|
|
20
|
-
* This source code is licensed under the ISC license.
|
|
21
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
-
*/const ms=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],gs=at("zoom-in",ms);/**
|
|
23
|
-
* @license lucide-react v1.7.0 - ISC
|
|
24
|
-
*
|
|
25
|
-
* This source code is licensed under the ISC license.
|
|
26
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
27
|
-
*/const hs=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],ps=at("zoom-out",hs);function Yt(n){return typeof n=="number"&&Number.isFinite(n)?n:0}function Ye(n){return n.toLocaleString()}function xs({agents:n}){const{rows:r,totalInputTokens:p,totalOutputTokens:u,totalTokens:m}=a.useMemo(()=>{const o=n.map(d=>{const f=Yt(d.totalInputTokens),j=Yt(d.totalOutputTokens);return{id:d.id,name:d.name,inputTokens:f,outputTokens:j,totalTokens:f+j}}).sort((d,f)=>f.totalTokens-d.totalTokens||d.name.localeCompare(f.name)||d.id.localeCompare(f.id));return{rows:o,totalInputTokens:o.reduce((d,f)=>d+f.inputTokens,0),totalOutputTokens:o.reduce((d,f)=>d+f.outputTokens,0),totalTokens:o.reduce((d,f)=>d+f.totalTokens,0)}},[n]),x=m>0;return e.jsxs("section",{className:"agent-token-stats-panel","aria-label":"Agent token usage statistics",children:[e.jsx("header",{className:"agent-token-stats-panel__header",children:e.jsx("h3",{className:"agent-token-stats-panel__title",children:"Token Usage by Agent"})}),e.jsxs("div",{className:"agent-token-stats-panel__totals",role:"list","aria-label":"Token usage totals",children:[e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Input Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ye(p)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Output Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ye(u)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Combined Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ye(m)})]})]}),x?e.jsx("div",{className:"agent-token-stats-panel__table-wrapper",children:e.jsxs("table",{className:"agent-token-stats-panel__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"Agent"}),e.jsx("th",{scope:"col",children:"Input"}),e.jsx("th",{scope:"col",children:"Output"}),e.jsx("th",{scope:"col",children:"Total"})]})}),e.jsx("tbody",{children:r.map(o=>e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",className:"agent-token-stats-panel__agent-cell",children:[e.jsx("span",{className:"agent-token-stats-panel__agent-name",children:o.name}),e.jsx("span",{className:"agent-token-stats-panel__agent-id",children:o.id})]}),e.jsx("td",{children:Ye(o.inputTokens)}),e.jsx("td",{children:Ye(o.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:Ye(o.totalTokens)})]},o.id))})]})}):e.jsx("div",{className:"agent-token-stats-panel__empty",role:"status",children:"No token usage recorded yet. Token totals appear here once agents run."})]})}const bs=[{icon:Ze,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:cs,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:ct,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:Na,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function vs({stats:n,className:r=""}){return n?e.jsx("div",{className:`agent-metrics-bar ${r}`.trim(),children:bs.map(p=>{const u=p.valueKey==="successRate"?`${Math.round(n.successRate*100)}%`:n[p.valueKey];return e.jsxs("div",{className:`agent-metric-card ${p.className}`,children:[e.jsx(p.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:u}),e.jsx("span",{className:"agent-metric-label",children:p.label})]})]},p.label)})}):null}const Xt=200;function fs(n,r){const[p,u]=a.useState([]),[m,x]=a.useState(!1),o=a.useRef(null),d=a.useRef(0),f=a.useRef(n),j=a.useRef(r);return(f.current!==n||j.current!==r)&&(f.current=n,j.current=r,d.current++,o.current&&(o.current(),o.current=null),u([]),x(!1)),a.useEffect(()=>{if(!n){u([]),x(!1);return}const A=d.current;let y=`/api/tasks/${encodeURIComponent(n)}/logs/stream`;r&&(y+=`?projectId=${encodeURIComponent(r)}`);const C=ya(y,{events:{"agent:log":T=>{if(d.current===A)try{const E=JSON.parse(T.data),H={type:E.type??"text",text:E.text??E.content??"",timestamp:E.timestamp,content:E.content};u(R=>{const _=[H,...R];return _.length>Xt?_.slice(0,Xt):_})}catch{}}},onOpen:()=>{d.current===A&&x(!0)},onError:()=>{d.current===A&&x(!1)}});return o.current=C,()=>{C(),o.current=null,d.current===A&&x(!1)}},[n,r]),{entries:p,isConnected:m}}const js=5e3;function Ns({agent:n,projectId:r,onSelect:p,onOpenTaskLogs:u}){const{entries:m,isConnected:x}=fs(n.taskId,r),[o,d]=a.useState(null);a.useEffect(()=>{if(!n.taskId){d(null);return}let R=!1,_;const b=async()=>{try{const I=await ka(n.taskId,r);R||d(I)}catch{}finally{R||(_=setTimeout(b,js))}};return b(),()=>{R=!0,_&&clearTimeout(_)}},[n.taskId,r]);const f=n.lastHeartbeatAt?Math.floor((Date.now()-new Date(n.lastHeartbeatAt).getTime())/1e3):0,j=(()=>{if(!n.lastHeartbeatAt)return null;const R=wt(n.runtimeConfig?.heartbeatIntervalMs),_=new Date(n.lastHeartbeatAt).getTime()+R,b=Math.round((_-Date.now())/1e3);return Number.isFinite(b)?b<=0?`Heartbeat overdue ${vt(-b)}`:`Next heartbeat in ${vt(b)}`:null})(),k=o?.steps?.[o.currentStep??0],A=o?.steps?.length??0,y=(o?.currentStep??0)+1,C=o?.modelId,T=()=>{p&&p(n.id)},E=R=>{R.stopPropagation(),n.taskId&&u&&u(n.taskId)},H=R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),T())};return e.jsxs("div",{className:"live-agent-card",onClick:T,onKeyDown:H,role:"button",tabIndex:0,"aria-label":`Select agent ${n.name}`,children:[e.jsxs("div",{className:"live-agent-card-header",children:[e.jsxs("div",{className:"live-agent-card-name",children:[e.jsx("span",{className:`status-dot ${n.state==="running"?"status-dot--pending":"status-dot--online"}`,"aria-hidden":"true"}),e.jsx("span",{children:n.name})]}),n.taskId&&e.jsx("span",{className:"live-agent-task badge",children:n.taskId})]}),e.jsx("div",{className:"live-agent-card-transcript",children:m.length===0?e.jsx("div",{className:"live-agent-card-empty",children:n.taskId?k?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"live-agent-card-status",children:["Step ",y,A?`/${A}`:"",": ",k.name]}),C&&e.jsx("div",{className:"live-agent-card-status-sub",children:C}),e.jsx("div",{className:"live-agent-card-status-sub",children:x?"Waiting for output...":"Connecting to log stream..."})]}):e.jsx("span",{children:x?"Waiting for output...":"Connecting..."}):e.jsx("span",{children:n.state==="running"?"Starting...":"Idle — no task assigned"})}):m.slice(0,20).map((R,_)=>e.jsx("div",{className:"live-agent-card-line",children:R.text},_))}),e.jsxs("div",{className:"live-agent-card-footer",children:[e.jsxs("div",{className:"live-agent-card-footer-meta",children:[e.jsx("span",{className:"text-secondary",title:"Time since last heartbeat",children:vt(f)}),j&&e.jsx("span",{className:"live-agent-card-next-heartbeat",title:j,children:j})]}),e.jsxs("div",{className:"live-agent-card-footer-actions",children:[n.taskId&&u&&e.jsxs("button",{type:"button",className:"live-agent-card-logs-btn",onClick:E,title:"View live run logs","aria-label":`View live logs for ${n.taskId}`,children:[e.jsx(Ct,{size:12}),e.jsx("span",{children:"Live logs"})]}),x&&e.jsx(Ze,{size:12,className:"live-agent-streaming-dot"})]})]})]})}function vt(n){return n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m ${n%60}s`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`}function ys({agents:n,projectId:r,onAgentSelect:p,onOpenTaskLogs:u,className:m=""}){const x=Array.from(new Map(n.map(o=>[o.id,o])).values());return x.length===0?null:e.jsxs("div",{className:`active-agents-panel ${m}`.trim(),children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(Ze,{size:16}),e.jsxs("span",{children:["Active Agents (",x.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:x.map(o=>e.jsx(Ns,{agent:o,projectId:r,onSelect:p,onOpenTaskLogs:u},o.id))})]})}function ks({stats:n,activeAgents:r,projectId:p,isOpen:u,onToggle:m,onSelectAgent:x,onOpenTaskLogs:o}){return e.jsxs("section",{className:"agents-overview-bar","aria-label":"Agents overview",children:[e.jsxs("button",{type:"button",className:"agents-overview-bar__toggle","aria-expanded":u,onClick:m,children:[e.jsxs("span",{className:"agents-overview-bar__title-wrap",children:[u?e.jsx(wa,{size:16,"aria-hidden":"true"}):e.jsx(ta,{size:16,"aria-hidden":"true"}),e.jsx("span",{className:"agents-overview-bar__title",children:"Overview"})]}),e.jsxs("span",{className:"agents-overview-bar__meta text-secondary",children:[r.filter(d=>d.state==="active").length," active · ",r.filter(d=>d.state==="running").length," running"]})]}),u?e.jsxs("div",{className:"agents-overview-bar__content",children:[e.jsx(vs,{stats:n,className:"agents-overview-bar__metrics"}),e.jsx(ys,{agents:r,projectId:p,onAgentSelect:x,onOpenTaskLogs:o,className:"agents-overview-bar__active-panel"})]}):null]})}function ft({title:n="No agents found",description:r="Create an agent to get started",ctaLabel:p="Create Agent",onCtaClick:u}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(St,{size:48,opacity:.3,className:"agent-empty-state__icon"}),e.jsx("p",{className:"agent-empty-state__title",children:n}),e.jsx("p",{className:"agent-empty-state__description text-secondary",children:r}),u?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:u,children:p}):null]})}const qt=3,jt=1e3;function ws({isOpen:n,onClose:r,onGenerated:p,projectId:u}){aa(n);const[m,x]=a.useState(""),[o,d]=a.useState({type:"input"}),[f,j]=a.useState(null),[k,A]=a.useState(!1),y=a.useRef(null),C=a.useRef(null);a.useEffect(()=>{n&&o.type==="input"&&C.current?.focus()},[n,o.type]),a.useEffect(()=>{if(!n&&y.current){const b=y.current;y.current=null,gt(b,u).catch(()=>{})}},[n,u]),a.useEffect(()=>{if(!n)return;const b=I=>{I.key==="Escape"&&T()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[n]);const T=a.useCallback(()=>{if(y.current){const b=y.current;y.current=null,gt(b,u).catch(()=>{})}x(""),d({type:"input"}),j(null),A(!1),r()},[r,u]),E=a.useCallback(async()=>{if(!(!m.trim()||m.trim().length<qt)){j(null),d({type:"loading"});try{const{sessionId:b}=await Ca(m.trim(),u);y.current=b;const{spec:I}=await Sa(b,u);d({type:"preview",spec:I,sessionId:b})}catch(b){const I=b instanceof Error?b.message:"Failed to generate agent specification";I.includes("429")||I.toLowerCase().includes("rate limit")?j("Too many requests. Please wait a moment and try again."):j(I),d({type:"input"}),y.current=null}}},[m,u]),H=a.useCallback(async()=>{if(y.current){const b=y.current;y.current=null;try{await gt(b,u)}catch{}}await E()},[E,u]),R=a.useCallback(()=>{o.type==="preview"&&(y.current=null,p(o.spec),x(""),d({type:"input"}),j(null),A(!1),r())},[o,p,r]);if(!n)return null;const _=m.trim().length>=qt&&m.trim().length<=jt;return e.jsx("div",{className:"agent-dialog-overlay",onClick:b=>{b.target===b.currentTarget&&T()},children:e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Generate agent with AI",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsxs("span",{className:"agent-dialog-header-title",children:[e.jsx("span",{className:"agent-dialog-header-sparkle",children:"✨"}),"Generate Agent"]}),e.jsx("button",{className:"modal-close",onClick:T,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[f&&e.jsx("div",{className:"agent-dialog-error-banner",children:f}),o.type==="input"&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Describe your agent's role and the AI will generate a complete specification including system prompt, suggested configuration, and more."}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-role-description",children:"Role Description"}),e.jsx("textarea",{ref:C,id:"agent-role-description",className:"input agent-dialog-textarea",rows:4,placeholder:'e.g. "Senior frontend code reviewer who specializes in React accessibility"',value:m,onChange:b=>x(b.target.value),onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&_&&(b.preventDefault(),E())},maxLength:jt,"aria-describedby":"role-description-hint"}),e.jsxs("div",{id:"role-description-hint",className:"agent-dialog-hint",children:[e.jsx("span",{children:"Describe what your agent should do"}),e.jsxs("span",{children:[m.length,"/",jt]})]})]})]}),o.type==="loading"&&e.jsxs("div",{className:"agent-dialog-loading-center",children:[e.jsx("div",{className:"agent-dialog-spinner spin"}),e.jsx("p",{className:"agent-dialog-loading-text",children:"Generating agent specification..."})]}),o.type==="preview"&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-summary agent-dialog-summary--spaced",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Title"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[o.spec.icon," ",o.spec.title]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Role"}),e.jsx("span",{children:o.spec.role})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Description"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--body",children:o.spec.description})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--capitalize",children:o.spec.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Max Turns"}),e.jsx("span",{children:o.spec.maxTurns})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{children:["System Prompt",e.jsx("button",{type:"button",className:"agent-dialog-expand-btn",onClick:()=>A(!k),children:k?"Collapse":"Expand"})]}),e.jsxs("div",{className:`agent-generation-prompt-box${k?"":" agent-generation-prompt-box--collapsed"}`,children:[o.spec.systemPrompt,!k&&o.spec.systemPrompt.length>500&&e.jsx("div",{className:"agent-generation-prompt-fade"})]})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[e.jsx("button",{className:"btn",onClick:T,children:"Cancel"}),o.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void E(),disabled:!_,children:"Generate"}),o.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void H(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:R,children:"Use This"})]})]})]})})}const Zt=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Jt=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Cs({isOpen:n,onClose:r,onCreated:p,projectId:u,prefillDraft:m=null,agentOnboardingEnabled:x=!1,existingAgents:o=[],onPrefillDraft:d}){const[f,j]=a.useState(0),[k,A]=a.useState("presets"),[y,C]=a.useState(""),[T,E]=a.useState(""),[H,R]=a.useState(""),[_,b]=a.useState("custom"),[I,$]=a.useState(""),[q,Ne]=a.useState(""),[le,K]=a.useState(""),[ae,ie]=a.useState(""),[F,N]=a.useState(""),[me,ge]=a.useState(""),[S,Z]=a.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[re,$e]=a.useState(null),[ee,te]=a.useState([]),[ye,U]=a.useState(!1),[he,ke]=a.useState(null),[oe,J]=a.useState(!1),[ce,pe]=a.useState(!1),[G,B]=a.useState([]),[Le,Fe]=a.useState(!1),[we,de]=a.useState([]),[xe,Ae]=a.useState([]),[D,L]=a.useState("model"),[Q,be]=a.useState(""),[Re,Ie]=a.useState([]),[Oe,Pe]=a.useState(!1),[i,v]=a.useState([]),[O,se]=a.useState(!1);a.useEffect(()=>{n&&(Fe(!0),Aa().then(s=>{B(s.models),de(s.favoriteProviders),Ae(s.favoriteModels)}).catch(()=>{}).finally(()=>Fe(!1)))},[n]),a.useEffect(()=>{n&&(se(!0),v([]),Ra(void 0,u).then(s=>{v(s)}).catch(()=>{v([])}).finally(()=>se(!1)))},[n,u]),a.useEffect(()=>{if(!n)return;const s=Ma;if(typeof s!="function"){Ie([]),Pe(!1);return}Pe(!0),Ie([]),s(u).then(w=>{Ie(w)}).catch(()=>{Ie([])}).finally(()=>Pe(!1))},[n,u]);const P=S.model.includes("/")?S.model:"",Y=a.useCallback(s=>{const w=Jt.has(s.role)?s.role:"custom";C(s.title),E(s.description),R(s.icon),b(w),K(s.systemPrompt),Z(_e=>({..._e,thinkingLevel:s.thinkingLevel,maxTurns:s.maxTurns})),J(!1),j(1)},[]),Ce=a.useCallback(s=>{Z(w=>({...w,model:s}))},[]),De=a.useCallback(s=>{L(s),s==="model"&&be("")},[]),Te=a.useCallback(async s=>{const w=we,V=w.includes(s)?w.filter(ve=>ve!==s):[s,...w];de(V);try{await Ot({favoriteProviders:V,favoriteModels:xe})}catch{de(w)}},[we,xe]),Ve=a.useCallback(async s=>{const w=xe,V=w.includes(s)?w.filter(ve=>ve!==s):[s,...w];Ae(V);try{await Ot({favoriteProviders:we,favoriteModels:V})}catch{Ae(w)}},[we,xe]),st=a.useCallback(s=>{$e(s.id),C(s.name),R(s.icon),E(s.description??s.title),b(s.role),N(s.soul??""),K(s.instructionsText??""),j(1)},[]),Ke=a.useCallback(s=>{const w=s.runtimeHint?.trim()??"",_e=s.model?.trim()||s.modelHint?.trim()||"";j(1),A("custom"),C(s.name??""),E(s.title??""),R(s.icon??""),b(Jt.has(s.role)?s.role:"custom"),$(s.reportsTo??""),K(s.instructionsText??""),ie(s.heartbeatProcedurePath??""),N(s.soul??""),ge(s.memory??""),te(Array.isArray(s.skills)?s.skills:[]),Z(V=>({...V,model:w?"":_e,thinkingLevel:s.thinkingLevel??V.thinkingLevel,maxTurns:s.maxTurns??V.maxTurns})),w?(L("runtime"),be(w)):(L("model"),be(""))},[]);if(a.useEffect(()=>{!n||!m||Ke(m)},[n,m,Ke]),!n)return null;const He=()=>{j(0),A("presets"),C(""),E(""),R(""),b("custom"),$(""),Ne(""),K(""),ie(""),N(""),ge(""),Z({model:"",thinkingLevel:"off",maxTurns:1e3}),L("model"),be(""),$e(null),te([]),ke(null),J(!1),pe(!1),r()},Me=async()=>{if(y.trim()){U(!0),ke(null);try{const s={};D==="runtime"?Q.trim()&&(s.runtimeHint=Q.trim()):S.model.trim()&&(s.model=S.model.trim()),S.thinkingLevel!=="off"&&(s.thinkingLevel=S.thinkingLevel),S.maxTurns!==1e3&&(s.maxTurns=S.maxTurns),await Ea({name:y.trim(),role:_,...T.trim()?{title:T.trim()}:{},...H.trim()?{icon:H.trim()}:{},...I.trim()?{reportsTo:I.trim()}:{},...q.trim()?{instructionsPath:q.trim()}:{},...le.trim()?{instructionsText:le.trim()}:{},...ae.trim()?{heartbeatProcedurePath:ae.trim()}:{},...F.trim()?{soul:F.trim()}:{},...me.trim()?{memory:me.trim()}:{},...Object.keys(s).length>0?{runtimeConfig:s}:{},...ee.length>0?{metadata:{skills:ee}}:{}},u),He(),p()}catch(s){ke(s instanceof Error?s.message:"Failed to create agent")}finally{U(!1)}}},Je=Zt.find(s=>s.value===_),ze=I.trim(),Se=ze?i.find(s=>s.id===ze):void 0,Be=Q?Re.find(s=>s.runtimeId===Q):void 0,Qe=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:s,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":s,children:[e.jsxs("label",{className:`agent-runtime-mode-option${D==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"model",checked:D==="model",onChange:()=>De("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${D==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"runtime",checked:D==="runtime",onChange:()=>De("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),D==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),Le?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(_a,{id:"agent-model",label:"Model",value:P,onChange:Ce,models:G,placeholder:"Select a model…",favoriteProviders:we,onToggleFavorite:Te,favoriteModels:xe,onToggleModelFavorite:Ve})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),Oe?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:Q,onChange:w=>be(w.target.value),children:[e.jsx("option",{value:"",children:Re.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),Re.map(w=>e.jsx("option",{value:w.runtimeId,children:w.description?`${w.name} — ${w.description}`:w.name},`${w.pluginId}:${w.runtimeId}`))]})]})]});return es.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:s=>{s.target===s.currentTarget&&He()},children:[e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Create new agent",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"New Agent"}),e.jsx("button",{className:"btn-icon",onClick:He,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(s=>e.jsx("div",{className:`agent-dialog-step${s===f?" active":s<f?" completed":""}`,"aria-label":`Step ${s+1}`},s))}),e.jsxs("div",{className:"agent-dialog-body",children:[f===0&&e.jsxs("div",{children:[x&&e.jsx("div",{className:"agent-dialog-step-zero-actions",children:e.jsx("button",{type:"button",className:"btn agent-dialog-interview-btn",onClick:()=>pe(!0),children:"AI Interview"})}),e.jsxs("div",{className:"agent-dialog-tabs",role:"tablist","aria-label":"Agent setup mode",children:[e.jsx("button",{id:"agent-dialog-tab-presets",type:"button",role:"tab","aria-controls":"agent-dialog-panel-presets","aria-selected":k==="presets",tabIndex:k==="presets"?0:-1,className:`agent-dialog-tab${k==="presets"?" active":""}`,onClick:()=>A("presets"),"data-testid":"agent-dialog-tab-presets",children:"Preset personas"}),e.jsx("button",{id:"agent-dialog-tab-custom",type:"button",role:"tab","aria-controls":"agent-dialog-panel-custom","aria-selected":k==="custom",tabIndex:k==="custom"?0:-1,className:`agent-dialog-tab${k==="custom"?" active":""}`,onClick:()=>A("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),k==="presets"&&e.jsx("div",{id:"agent-dialog-panel-presets",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-presets",children:e.jsxs("div",{className:"agent-presets",children:[e.jsx("div",{className:"agent-presets-header",children:"Choose a preset persona to prefill role, identity, soul, and instructions"}),e.jsx("div",{className:"agent-presets-grid",children:ts.map(s=>e.jsxs("button",{type:"button",className:`agent-preset-card${re===s.id?" selected":""}`,"data-testid":`preset-${s.id}`,onClick:()=>st(s),title:s.title,children:[e.jsx("span",{className:"agent-preset-icon",children:e.jsx(dt,{agent:{id:s.id,icon:s.icon,name:s.name},size:28})}),e.jsx("span",{className:"agent-preset-name",children:s.name}),e.jsx("span",{className:"agent-preset-role",children:s.role}),s.description&&e.jsx("span",{className:"agent-preset-description",children:s.description})]},s.id))})]})}),k==="custom"&&e.jsxs("div",{id:"agent-dialog-panel-custom",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-custom",children:[e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Identity"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-name",children:["Name ",!re&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:y,onChange:s=>C(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field agent-dialog-field--title",children:[e.jsxs("label",{htmlFor:"agent-title",children:["Title ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:T,onChange:s=>E(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-icon",children:["Icon ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:H,onChange:s=>R(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:Zt.map(s=>e.jsxs("button",{type:"button",className:`agent-role-option${_===s.value?" selected":""}`,onClick:()=>b(s.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:s.icon}),e.jsx("span",{className:"agent-role-option-label",children:s.label})]},s.value))})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Configuration"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-reports-to",children:["Reports To ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:I,onChange:s=>$(s.target.value),disabled:O,children:[e.jsx("option",{value:"",children:"No manager"}),i.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.id,")"]},s.id))]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-soul",children:["Soul ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:F,onChange:s=>N(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-memory",children:["Agent Memory ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-memory",className:"input",rows:2,placeholder:"Private to this agent — durable preferences, operating habits, and context it should carry across tasks...",value:me,onChange:s=>ge(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-path",children:["Instructions Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:q,onChange:s=>Ne(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-heartbeat-procedure-path",children:["Heartbeat Procedure Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-heartbeat-procedure-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/ceo-agent2736/HEARTBEAT.md",value:ae,onChange:s=>ie(s.target.value)}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-field-hint",children:"Path to the agent's heartbeat procedure path, typically .fusion/agents/ceo-agent2736/HEARTBEAT.md. Legacy id-only default paths still work."})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-text",children:["Inline Instructions ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:le,onChange:s=>K(s.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),Qe("agent-runtime-source-step-0")]}),e.jsxs("div",{className:"agent-dialog-ai-generate",children:[e.jsxs("button",{type:"button",className:"btn btn--ai-generate",onClick:()=>J(!0),children:[e.jsx("span",{children:"✨"}),"Generate with AI"]}),e.jsx("p",{className:"agent-dialog-ai-hint",children:"Describe your agent's role and let AI generate a specification"})]})]})]}),f===1&&e.jsxs("div",{children:[Qe("agent-runtime-source-step-1"),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-thinking",children:"Thinking Level"}),e.jsxs("select",{id:"agent-thinking",className:"select",value:S.thinkingLevel,onChange:s=>Z(w=>({...w,thinkingLevel:s.target.value})),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"minimal",children:"Minimal"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-max-turns",children:"Max Turns"}),e.jsx("input",{id:"agent-max-turns",type:"number",className:"input",min:1,max:2e3,value:S.maxTurns,onChange:s=>Z(w=>({...w,maxTurns:Math.max(1,parseInt(s.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(as,{id:"agent-skills",label:"Skills",value:ee,onChange:te,projectId:u}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),f===2&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Review your agent configuration before creating."}),e.jsxs("div",{className:"agent-dialog-summary",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Name"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[H&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:H}),y]})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable agent-dialog-summary-row--title",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-title",children:"Title"}),e.jsx("input",{id:"agent-review-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:T,onChange:s=>E(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Role"}),e.jsxs("span",{children:[Je?.icon," ",Je?.label]})]}),ze&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Reports To"}),e.jsx("span",{children:Se?`${Se.name} (${Se.id})`:ze})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-soul",children:"Soul"}),e.jsx("textarea",{id:"agent-review-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:F,onChange:s=>N(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-heartbeat-procedure-path",children:"Heartbeat Procedure Path"}),e.jsx("input",{id:"agent-review-heartbeat-procedure-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/ceo-agent2736/HEARTBEAT.md",value:ae,onChange:s=>ie(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-instructions-path",children:"Instructions Path"}),e.jsx("input",{id:"agent-review-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:q,onChange:s=>Ne(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row agent-dialog-summary-row--editable",children:[e.jsx("label",{className:"agent-dialog-summary-row-label",htmlFor:"agent-review-instructions-text",children:"Inline Instructions"}),e.jsx("textarea",{id:"agent-review-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:le,onChange:s=>K(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:D==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:D==="runtime"?Be?Be.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):P?e.jsxs(e.Fragment,{children:[e.jsx(Ta,{provider:P.split("/")[0],size:"sm"})," ",(()=>{const s=P.indexOf("/"),w=P.slice(0,s),_e=P.slice(s+1);return G.find(ve=>ve.provider===w&&ve.id===_e)?.name||P})()]}):e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"default"})})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value--capitalize",children:S.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Max Turns"}),e.jsx("span",{children:S.maxTurns})]}),ee.length>0&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Skills"}),e.jsxs("span",{children:[ee.length," skill",ee.length!==1?"s":""," selected"]})]})]}),he&&e.jsx("p",{className:"agent-dialog-error",children:he})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[f>0&&e.jsx("button",{className:"btn",onClick:()=>j(s=>s-1),disabled:ye,children:"Back"}),e.jsx("button",{className:"btn",onClick:He,disabled:ye,children:"Cancel"}),f<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>j(s=>s+1),disabled:f===0&&!y.trim()&&!re,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void Me(),disabled:ye||!y.trim(),children:ye?"Creating...":"Create"})]})]}),e.jsx(ws,{isOpen:oe,onClose:()=>J(!1),onGenerated:Y,projectId:u}),e.jsx(ss,{isOpen:ce,onClose:()=>pe(!1),onUseDraft:s=>{d?.(s),d||Ke(s),pe(!1)},projectId:u,existingAgents:o,mode:"create"})]}),document.body)}function Ss(n){const r=n.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!r)throw new Error("Missing YAML frontmatter delimiters (---)");const p=r[1].split(/\r?\n/),u=r[2]??"",m={name:""},x=[];let o=!1;for(const d of p){const j=d.trimEnd().trim();if(!j)continue;if(j.startsWith("skills:")){o=!0;continue}if(o&&j.startsWith("- ")){x.push(j.slice(2).trim());continue}o=!1;const[k,...A]=j.split(":"),C=A.join(":").trim().replace(/^['"]|['"]$/g,"");k==="name"&&(m.name=C),k==="title"&&(m.title=C),k==="icon"&&(m.icon=C),k==="role"&&(m.role=C),k==="reportsTo"&&(m.reportsTo=C)}if(!m.name)throw new Error("Missing required field: name");return x.length>0&&(m.skills=x),u.trim().length>0&&(m.instructionBody=u),m}function As({isOpen:n,onClose:r,onImported:p,projectId:u,initialInputMethod:m="paste"}){aa(n);const[x,o]=a.useState("input"),[d,f]=a.useState(m),[j,k]=a.useState(""),[A,y]=a.useState([]),[C,T]=a.useState("Unknown"),[E,H]=a.useState([]),[R,_]=a.useState([]),[b,I]=a.useState([]),[$,q]=a.useState([]),[Ne,le]=a.useState(!1),[K,ae]=a.useState(!1),[ie,F]=a.useState(null),[N,me]=a.useState(null),[ge,S]=a.useState(null),Z=a.useRef(null),re=a.useRef(null),[$e,ee]=a.useState([]),[te,ye]=a.useState(""),[U,he]=a.useState(null),[ke,oe]=a.useState(!1),[J,ce]=a.useState(null),pe=a.useRef(!1);a.useEffect(()=>{d==="browse"&&!pe.current&&!ke&&(pe.current=!0,oe(!0),ce(null),Dt().then(i=>{i.error?ce(i.error):i.companies.length>0?ee(i.companies):ce("No companies available")}).catch(i=>{ce(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{oe(!1)}))},[d,ke]);const G=a.useCallback(()=>{pe.current=!0,ce(null),ee([]),he(null),oe(!0),Dt().then(i=>{i.error?ce(i.error):i.companies.length>0?ee(i.companies):ce("No companies available")}).catch(i=>{ce(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{oe(!1)})},[]),B=a.useCallback(()=>{o("input"),f(m),k(""),y([]),T("Unknown"),H([]),_([]),I([]),q([]),le(!1),ae(!1),F(null),me(null),S(null),ee([]),ye(""),he(null),oe(!1),ce(null),pe.current=!1},[m]),Le=a.useCallback(()=>{B(),r()},[B,r]),Fe=a.useCallback(i=>{const v=i.target.files?.[0];if(!v)return;const O=new FileReader;O.onload=se=>{const P=se.target?.result;f("file"),y([]),k(P),F(null)},O.onerror=()=>{F("Failed to read file")},O.readAsText(v),i.target.value=""},[]),we=a.useCallback(async i=>{const v=Array.from(i.target.files??[]);if(v.length!==0)try{const O=v.filter(P=>(P.webkitRelativePath||P.name).toLowerCase().endsWith("agents.md")).sort((P,Y)=>{const Ce=P.webkitRelativePath||P.name,De=Y.webkitRelativePath||Y.name;return Ce.localeCompare(De)});if(O.length===0){F("Selected directory has no AGENTS.md files");return}const se=[];for(const P of O){const Y=await P.text();se.push(Ss(Y))}f("directory"),y(se),k(""),F(null)}catch{F("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function de(i){if(!u)return`/api${i}`;const v=i.includes("?")?"&":"?";return`/api${i}${v}projectId=${encodeURIComponent(u)}`}const xe=a.useCallback(async()=>{if(d==="directory"&&A.length===0){F("Please select a directory containing AGENTS.md files");return}if(d==="browse"&&!U){F("Please select a company from the catalog");return}if(d!=="directory"&&d!=="browse"&&!j.trim()){F("Please provide manifest content");return}le(!0),F(null);try{let i;d==="directory"?i={agents:A,dryRun:!0}:d==="browse"&&U?i={importSource:"companies.sh",companySlug:U.slug,dryRun:!0}:i={manifest:j,dryRun:!0};const v=await fetch(de("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!v.ok){const Y=await v.json();throw new Error(Y.error??`Parse failed (${v.status})`)}const O=await v.json(),se=O.agents&&O.agents.length>0?O.agents:O.created.map(Y=>({name:Y,role:"custom"})),P=Array.isArray(O.skills)?O.skills:[];T(O.companyName??"Unknown"),H(se),_(P),I(se.map(Y=>Y.name)),q(P.map(Y=>Y.name)),o("preview")}catch(i){F(i instanceof Error?i.message:"Failed to parse manifest")}finally{le(!1)}},[d,A,j,U,u]),Ae=a.useCallback(async()=>{ae(!0),S(null);try{let i;d==="directory"?i={agents:A,skipExisting:!0,selectedAgents:b,selectedSkills:$}:d==="browse"&&U?i={importSource:"companies.sh",companySlug:U.slug,skipExisting:!0,selectedAgents:b,selectedSkills:$}:i={manifest:j,skipExisting:!0,selectedAgents:b,selectedSkills:$};const v=await fetch(de("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!v.ok){const se=await v.json();throw new Error(se.error??`Import failed (${v.status})`)}const O=await v.json();me(O),o("result"),p()}catch(i){S(i instanceof Error?i.message:"Failed to import agents")}finally{ae(!1)}},[d,A,j,U,b,$,u,p]),D=b.length,L=$.length,Q=`${D} Agent${D!==1?"s":""}`,be=`${L} Skill${L!==1?"s":""}`,Re=D>0&&L>0?`${Q} + ${be}`:L>0?be:Q,Ie=D>0&&L>0?`Importing ${D} agent${D!==1?"s":""} and ${L} skill${L!==1?"s":""}...`:L>0?`Importing ${L} skill${L!==1?"s":""}...`:`Importing ${D} agent${D!==1?"s":""}...`,Oe=i=>{I(v=>v.includes(i)?v.filter(O=>O!==i):[...v,i])},Pe=i=>{q(v=>v.includes(i)?v.filter(O=>O!==i):[...v,i])};return n?e.jsx("div",{className:"agent-dialog-overlay",onClick:i=>{i.target===i.currentTarget&&Le()},children:e.jsxs("div",{className:"agent-dialog agent-import-dialog",role:"dialog","aria-modal":"true","aria-label":"Import agents",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"Import Agents"}),e.jsx("button",{className:"modal-close",onClick:Le,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[x==="input"&&e.jsxs("div",{className:"agent-import-input",children:[e.jsx("p",{className:"agent-import-description",children:"Import agents from an Agent Companies package. Browse the companies.sh catalog to discover published agents, upload an AGENTS.md file, select a directory, or paste manifest content."}),e.jsxs("div",{className:"agent-import-file-upload",children:[e.jsx("input",{ref:Z,type:"file",accept:".md,.txt",onChange:Fe,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:re,type:"file",webkitdirectory:"",multiple:!0,onChange:we,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>Z.current?.click(),children:[e.jsx(At,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>re.current?.click(),children:[e.jsx(ls,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{f("browse"),y([]),k(""),he(null),F(null)},children:[e.jsx($a,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),d==="browse"&&e.jsxs("div",{className:"agent-import-browse",children:[e.jsxs("div",{className:"agent-import-browse-header",children:[e.jsxs("div",{className:"agent-import-browse-search",children:[e.jsx(La,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:te,onChange:i=>ye(i.target.value),"aria-label":"Search companies"})]}),U&&e.jsxs("div",{className:"agent-import-browse-selected",children:[e.jsx("span",{className:"agent-import-browse-selected-label",children:"Selected:"}),e.jsx("span",{className:"agent-import-browse-selected-name",children:U.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>he(null),children:"Change"})]})]}),ke&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(ht,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),J&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(pt,{size:16}),e.jsx("span",{children:J}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:G,children:[e.jsx(qe,{size:14}),"Retry"]})]}),!ke&&!J&&e.jsxs("div",{className:"agent-import-browse-list",children:[$e.filter(i=>te===""||i.name.toLowerCase().includes(te.toLowerCase())||(i.tagline?.toLowerCase().includes(te.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${U?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>he(i),role:"button",tabIndex:0,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&he(i)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:i.name}),i.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[i.installs.toLocaleString()," installs"]})]}),i.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:i.tagline}),i.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:i.repo})]},i.slug)),$e.filter(i=>te===""||i.name.toLowerCase().includes(te.toLowerCase())||(i.tagline?.toLowerCase().includes(te.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:te?"No companies match your search":"No companies available"})]})]}),d!=="browse"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-divider",children:e.jsx("span",{children:"or paste manifest content"})}),e.jsx("textarea",{className:"agent-import-textarea",placeholder:`---
|
|
28
|
-
name: CEO
|
|
29
|
-
title: Chief Executive Officer
|
|
30
|
-
reportsTo: null
|
|
31
|
-
skills:
|
|
32
|
-
- review
|
|
33
|
-
---
|
|
34
|
-
Agent instructions go here...`,value:j,onChange:i=>{f("paste"),y([]),k(i.target.value),F(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",d]}),ie&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(pt,{size:14}),ie]})]}),x==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:C})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Ct,{size:14}),e.jsxs("span",{children:[E.length," agent",E.length!==1?"s":""," found"]})]}),E.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>I(E.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>I([]),children:"Clear agents"})]}),E.length>0?e.jsx("div",{className:"agent-import-agent-list",children:E.map((i,v)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:b.includes(i.name),onChange:()=>Oe(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},v))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),R.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Ct,{size:14}),e.jsxs("span",{children:[R.length," skill",R.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>q(R.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>q([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:R.map((i,v)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:$.includes(i.name),onChange:()=>Pe(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${v}`))})]}),ge&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(pt,{size:14}),ge]})]}),x==="result"&&N&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(ct,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:N.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[N.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[N.created.length," created"]})}),N.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[N.skipped.length," skipped (already exist)"]})}),N.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[N.errors.length," error",N.errors.length!==1?"s":""]})})]}),N.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:N.created.map((i,v)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(ct,{size:12}),e.jsx("span",{children:i.name})]},v))}),N.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.errors.map((i,v)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Ht,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},v))}),N.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[N.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[N.skills.imported.length," skill",N.skills.imported.length!==1?"s":""," imported"]})}),N.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[N.skills.skipped.length," skill",N.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),N.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[N.skills.errors.length," skill",N.skills.errors.length!==1?"s":""," error",N.skills.errors.length!==1?"s":""]})}),N.skills.imported.length===0&&N.skills.skipped.length===0&&N.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),N.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:N.skills.imported.map((i,v)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(ct,{size:12}),e.jsx("span",{children:i.name})]},v))}),N.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:N.skills.errors.map((i,v)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Ht,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},v))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[x==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:K,children:"Back"}),e.jsx("button",{className:"btn",onClick:Le,disabled:K,children:x==="result"?"Close":"Cancel"}),x==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void xe(),disabled:Ne||(d==="directory"?A.length===0:d==="browse"?!U:!j.trim()),children:Ne?e.jsxs(e.Fragment,{children:[e.jsx(ht,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),x==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void Ae(),disabled:K||D===0&&L===0,children:K?e.jsxs(e.Fragment,{children:[e.jsx(ht,{size:14,className:"spin"}),Ie]}):`Import ${Re}`})]})]})}):null}const Nt="fn-agent-org-chart-layout";function Qt(n){return n==="auto"||n==="horizontal"||n==="vertical"}const Rs=768,Ts={nodeWidth:220,siblingGap:24,rootGap:24,chartPadding:24},Ms={nodeWidth:160,siblingGap:8,rootGap:8,chartPadding:8};function sa(n){return n.children.length===0?1:n.children.reduce((r,p)=>r+sa(p),0)}function _s(n){return n<=Rs?Ms:Ts}function Es(n,r){const p=sa(n);return p*r.nodeWidth+Math.max(0,p-1)*r.siblingGap}function $s(n,r=Number.POSITIVE_INFINITY){const p=_s(r);if(n.length===0)return p.nodeWidth;const m=n.map(o=>Es(o,p)).reduce((o,d)=>o+d,0),x=Math.max(0,n.length-1)*p.rootGap;return m+x+p.chartPadding*2}function Ls(n){const r=n.preference??"auto";if(r!=="auto")return r;const p=Number.isFinite(n.availableWidth)&&n.availableWidth>0?n.availableWidth:0;return p===0||n.tree.length<=1?"horizontal":$s(n.tree,p)>p?"vertical":"horizontal"}const ea=a.lazy(()=>Ya(()=>import("./AgentDetailView-CnFf_eBZ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(n=>({default:n.AgentDetailView}))),yt=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],kt=[.1,.25,.5,1,2,3,5,10],Is=.25,Ps=3,ot=16,Xe=32;function Rt(n){switch(n){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"idle":default:return"agent-badge--idle"}}function Tt(n,r){switch(r){case"running":return`${n}--running`;case"active":return`${n}--active`;case"paused":return`${n}--paused`;case"error":return`${n}--error`;case"idle":default:return`${n}--idle`}}function na(n){return n.children.length===0?1:n.children.reduce((r,p)=>r+na(p),0)}function Mt(n,r){return n.state==="error"?{title:void 0,label:"Error"}:{title:r.reason??r.label,label:r.stateDerived?null:r.label}}function la({node:n,onSelect:r,getHealthStatus:p,selectedAgentId:u,registerNodeElement:m,linksRef:x}){const{agent:o,children:d}=n,f=p(o),j=Mt(o,f),k=Rt(o.state),A=Tt("org-chart-node-card",o.state),y=na(n),C={"--org-chart-subtree-leaves":String(y)};return e.jsxs("div",{className:`org-chart-node${d.length>0?" org-chart-node--has-children":""}`,style:C,children:[e.jsxs("div",{ref:T=>m(o.id,T),"data-agent-id":o.id,className:`org-chart-node-card ${A}${u===o.id?" agent-card--selected":""}`,onClick:()=>r(o.id),role:"button",tabIndex:0,onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&(T.key===" "&&T.preventDefault(),r(o.id))},children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:e.jsx(dt,{agent:o,size:20})}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${k}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:f.color},title:j.title,children:[f.icon,j.label&&e.jsx("span",{className:"text-secondary",children:j.label})]})]})]}),d.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:d.map(T=>(x.current.push({parentId:o.id,childId:T.agent.id}),e.jsx(la,{node:T,onSelect:r,getHealthStatus:p,selectedAgentId:u,registerNodeElement:m,linksRef:x},T.agent.id)))})]})}function zs({links:n,nodeElements:r,canvasRef:p,viewportRef:u,layoutMode:m,transform:x}){const[o,d]=a.useState([]);return a.useLayoutEffect(()=>{const f=p.current,j=u.current;if(!f||!j||n.length===0){d([]);return}const k=()=>{const y=f.getBoundingClientRect(),C=n.flatMap(({parentId:T,childId:E})=>{const H=r.get(T),R=r.get(E);if(!H||!R)return[];const _=H.getBoundingClientRect(),b=R.getBoundingClientRect(),I=(_.left-y.left)/x.scale,$=(_.top-y.top)/x.scale,q=(b.left-y.left)/x.scale,Ne=(b.top-y.top)/x.scale;if(m==="vertical"){const N=I,me=$+_.height/x.scale/2,ge=q,S=Ne+b.height/x.scale/2,Z=N-(N-ge)/2;return[`M ${N} ${me} L ${Z} ${me} L ${Z} ${S} L ${ge} ${S}`]}const le=I+_.width/x.scale/2,K=$+_.height/x.scale,ae=q+b.width/x.scale/2,ie=Ne,F=K+(ie-K)/2;return[`M ${le} ${K} L ${le} ${F} L ${ae} ${F} L ${ae} ${ie}`]});d(C)};k();const A=new ResizeObserver(k);return A.observe(f),A.observe(j),r.forEach(y=>A.observe(y)),()=>A.disconnect()},[p,m,n,r,x.scale,u]),e.jsx("svg",{className:"agent-org-chart-connectors","aria-hidden":"true",children:o.map((f,j)=>e.jsx("path",{d:f},`${j}-${f}`))})}function Vs({addToast:n,projectId:r,onOpenTaskLogs:p,agentOnboardingEnabled:u=!1}){const[m,x]=a.useState(!1),d=Ia()==="mobile",[f,j]=a.useState("all"),{agents:k,stats:A,isLoading:y,loadAgents:C,refreshAgents:T}=Pa(r,{filterState:f,showSystemAgents:m}),[E,H]=a.useState(!1),[R,_]=a.useState(null),[b,I]=a.useState(!1),[$,q]=a.useState(null),[Ne,le]=a.useState(null),K=d&&!!$,[ae,ie]=a.useState("dashboard"),[F,N]=a.useState(null),[me,ge]=a.useState(!1),[S,Z]=a.useState(()=>{if(typeof window>"u")return"list";const t=it("fn-agent-view",r);return t==="list"||t==="board"||t==="org"?t:"list"}),[re,$e]=a.useState(()=>{if(typeof window>"u")return"auto";const t=it(Nt,r);return Qt(t)?t:"auto"}),[ee,te]=a.useState([]),[ye,U]=a.useState(!1),[he,ke]=a.useState(0),[oe,J]=a.useState(!1),[ce,pe]=a.useState(!1),[G,B]=a.useState({scale:1,x:0,y:0}),[Le,Fe]=a.useState(!1),we=a.useRef(null),de=a.useRef(null),xe=a.useRef(null),Ae=a.useRef(new Map),D=a.useRef([]),L=a.useRef(new Map),Q=a.useRef(null),be=a.useRef(null),Re=a.useRef(!1),{confirm:Ie}=za(),Oe=a.useRef(null),Pe=a.useId();a.useEffect(()=>{const t=it("fn-agent-view",r);if(t==="list"||t==="board"||t==="org"){Z(t);return}Z("list")},[r]),a.useEffect(()=>{Bt("fn-agent-view",S,r)},[S,r]),a.useEffect(()=>{const t=it(Nt,r);$e(Qt(t)?t:"auto")},[r]),a.useEffect(()=>{Bt(Nt,re,r)},[re,r]);const[i,v]=a.useState(null),O=a.useRef(null),[se,P]=a.useState(null),[Y,Ce]=a.useState(null),[De,Te]=a.useState({}),[Ve,st]=a.useState(1),[Ke,He]=a.useState(!1),[Me,Je]=a.useState(new Set),[ze,Se]=a.useState(new Map),Be=a.useRef(!0);a.useEffect(()=>(Be.current=!0,()=>{Be.current=!1}),[]),a.useEffect(()=>{Fa(r).then(t=>{Be.current&&st(t.heartbeatMultiplier??1)}).catch(()=>{})},[r]);const Qe=a.useCallback(async t=>{const l=Number.isFinite(t)&&t>0?t:1;st(l),He(!0);try{await Oa({heartbeatMultiplier:l},r),n(`Heartbeat speed set to ×${l.toFixed(1)}`,"success")}catch(c){n(`Failed to save heartbeat multiplier: ${Ee(c)}`,"error")}finally{Be.current&&He(!1)}},[r,n]),s=a.useMemo(()=>ze.size===0?k:k.map(t=>{const l=ze.get(t.id);return l?{...t,state:l}:t}),[k,ze]),w=a.useMemo(()=>s.filter(t=>m||!xt(t)),[s,m]),_e=a.useMemo(()=>s.filter(t=>t.state!=="active"&&t.state!=="running"?!1:m||!xt(t)),[s,m]),V=a.useMemo(()=>{if(m)return ee;const t=l=>xt(l.agent)?null:{...l,children:l.children.map(t).filter(c=>c!==null)};return ee.map(t).filter(l=>l!==null)},[ee,m]);a.useEffect(()=>{if(S!=="org")return;const t=de.current;if(!t)return;const l=()=>{ke(t.clientWidth)};l();const c=typeof ResizeObserver<"u"?new ResizeObserver(l):null;return c?.observe(t),window.addEventListener("resize",l),()=>{c?.disconnect(),window.removeEventListener("resize",l)}},[S,V.length]),a.useEffect(()=>{if(S!=="org")return;let t=!1;return U(!0),Da(r,{includeEphemeral:m}).then(l=>{t||te(l)}).catch(l=>{t||(n(`Failed to load org chart: ${Ee(l)}`,"error"),te([]))}).finally(()=>{t||U(!1)}),()=>{t=!0}},[S,r,m,n]),a.useEffect(()=>{const t=setInterval(()=>{C()},3e4);return()=>{clearInterval(t)}},[C]),a.useEffect(()=>{if(!oe)return;const t=c=>{const g=c.target;g&&(we.current?.contains(g)||Oe.current?.contains(g)||J(!1))},l=c=>{c.key==="Escape"&&(J(!1),Oe.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",l)}},[oe]);const ve=async(t,l)=>{if(!Me.has(t)){Je(c=>new Set(c).add(t)),Se(c=>{const g=new Map(c);return g.set(t,l),g});try{await Za(t,l,r),n(`Agent state updated to ${l}`,"success"),await C(),Se(c=>{const g=new Map(c);return g.delete(t),g})}catch(c){Se(g=>{const M=new Map(g);return M.delete(t),M}),n(`Failed to update state: ${Ee(c)}`,"error")}finally{Je(c=>{const g=new Set(c);return g.delete(t),g})}}},ia=async(t,l)=>{if(await Ie({title:"Delete Agent",message:`Delete agent "${l}"? This cannot be undone.`,danger:!0}))try{await Qa(t,r),n(`Agent "${l}" deleted`,"success"),await C()}catch(g){n(`Failed to delete agent: ${Ee(g)}`,"error")}},ra=async(t,l)=>{const c=k.find(g=>g.id===t);if(c){if(c.role===l){v(null);return}try{await rt(t,{role:l},r),n(`Agent role updated to ${yt.find(g=>g.value===l)?.label??l}`,"success"),v(null),C()}catch(g){n(`Failed to update role: ${Ee(g)}`,"error")}}},oa=(t,l)=>{t.key==="Escape"&&v(null)},ca=async(t,l)=>{Y===t.id&&(Ce(null),Te(c=>{const g={...c};return delete g[t.id],g})),P(t.id);try{await rt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:l}},r),n(`Heartbeat interval updated to ${Ut(l)} for ${t.name}`,"success"),C()}catch(c){n(`Failed to update heartbeat interval: ${Ee(c)}`,"error")}finally{P(null)}},_t=async t=>{const l=De[t.id]??"";if(l.trim()===""){n("Please enter a heartbeat interval in minutes","error");return}const c=Number(l);if(isNaN(c)){n("Heartbeat interval must be a valid number","error");return}if(c<=0){n("Heartbeat interval must be greater than 0","error");return}if(c>=1&&c<5){P(t.id);try{await rt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:qa}},r),n(`Heartbeat interval set to 5 minutes (minimum). ${c} minute${c!==1?"s":""} was below the 5-minute minimum.`,"success"),Ce(null),Te(M=>{const z={...M};return delete z[t.id],z}),C()}catch(M){n(`Failed to update heartbeat interval: ${Ee(M)}`,"error")}finally{P(null)}return}const g=Math.round(c*6e4);P(t.id);try{await rt(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:g}},r),n(`Heartbeat interval updated to ${Ut(g)} for ${t.name}`,"success"),Ce(null),Te(M=>{const z={...M};return delete z[t.id],z}),C()}catch(M){n(`Failed to update heartbeat interval: ${Ee(M)}`,"error")}finally{P(null)}},da=t=>{const l=wt(t.runtimeConfig?.heartbeatIntervalMs),c=Math.round(l/6e4);Ce(t.id),Te(g=>({...g,[t.id]:String(c)}))},ue=a.useCallback((t,l)=>{q(t),ie(l?.initialTab??"dashboard"),N(l?.initialRunId??null),ge(l?.preferActiveRun??!1)},[]),We=a.useCallback(()=>{q(null),ie("dashboard"),N(null),ge(!1)},[]),Et=a.useCallback(t=>{ue(t)},[ue]),ua=a.useCallback(t=>{le(t),ue(t)},[ue]),ma=a.useCallback(async({agentId:t,deleted:l})=>{await T(),l&&$===t&&We()},[T,$,We]),ga=a.useCallback(t=>{ue(t),d&&pe(!1)},[d,ue]),ha=async(t,l)=>{Se(c=>{const g=new Map(c);return g.set(t,"running"),g});try{await Ja(t,r,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),n(`Heartbeat run started for ${l}`,"success"),await C(),Se(c=>{const g=new Map(c);return g.delete(t),g})}catch(c){Se(g=>{const M=new Map(g);return M.delete(t),M}),n(`Failed to start heartbeat run: ${Ee(c)}`,"error")}},Ge=a.useCallback(t=>Math.min(Ps,Math.max(Is,t)),[]),X=a.useCallback(t=>{const l=de.current,c=xe.current?.querySelector(".agent-org-chart");if(!l||!c)return{...t,scale:Ge(t.scale)};const g=Ge(t.scale),M=c.scrollWidth*g,z=c.scrollHeight*g,fe=l.clientWidth,je=l.clientHeight,h=Math.min(Xe,fe-M-Xe),W=Xe,ne=Math.min(Xe,je-z-Xe),tt=Xe;return{scale:g,x:Math.max(h,Math.min(W,t.x)),y:Math.max(ne,Math.min(tt,t.y))}},[Ge]),nt=a.useCallback((t,l,c)=>{const g=de.current;g&&B(M=>{const z=Ge(t),fe=g.getBoundingClientRect(),je=l-fe.left,h=c-fe.top,W=(je-M.x)/M.scale,ne=(h-M.y)/M.scale;return X({scale:z,x:je-W*z,y:h-ne*z})})},[Ge,X]),Ue=a.useCallback(()=>{const t=de.current,l=xe.current?.querySelector(".agent-org-chart");if(!t||!l)return;const c=t.clientWidth,g=t.clientHeight,M=l.scrollWidth,z=l.scrollHeight;if(M<=0||z<=0)return;const fe=Ge(Math.min(c/M,g/z,1)),je=(c-M*fe)/2,h=(g-z*fe)/2;B(X({scale:fe,x:je,y:h}))},[Ge,X]),ut=a.useCallback(t=>{Z(t),t!=="org"&&B({scale:1,x:0,y:0}),d&&$&&We()},[We,d,$]),$t=t=>yt.find(l=>l.value===t)?.label??t,lt=a.useMemo(()=>Ls({tree:V,availableWidth:he,preference:re}),[V,re,he]),Lt=a.useCallback(t=>{$e(t),B({scale:1,x:0,y:0})},[]);a.useEffect(()=>{B({scale:1,x:0,y:0}),Re.current=!1},[r,lt]),a.useLayoutEffect(()=>{S!=="org"||ye||V.length===0||Re.current||(Ue(),Re.current=!0)},[S,V.length,Ue,ye]);const pa=a.useCallback((t,l)=>{l?Ae.current.set(t,l):Ae.current.delete(t)},[]),It=a.useCallback(()=>e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>B(t=>X({...t,scale:t.scale*.9})),"aria-label":"Zoom out org chart",title:"Zoom out",children:e.jsx(ps,{size:16})}),e.jsxs("span",{className:"agent-org-chart-controls__zoom-label","aria-live":"polite",children:[Math.round(G.scale*100),"%"]}),e.jsx("button",{type:"button",className:"btn-icon touch-target",onClick:()=>B(t=>X({...t,scale:t.scale*1.1})),"aria-label":"Zoom in org chart",title:"Zoom in",children:e.jsx(gs,{size:16})}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm agent-org-chart-controls__fit-btn",onClick:Ue,"aria-label":"Fit org chart",title:"Fit org chart",children:[e.jsx(Ha,{size:16}),"Fit"]}),e.jsxs("button",{type:"button",className:"btn touch-target btn-sm",onClick:()=>B(t=>X({...t,x:0,y:0})),"aria-label":"Center org chart",title:"Center org chart",children:[e.jsx(Ba,{size:16}),"Center"]})]}),[X,Ue,G.scale]),xa=a.useCallback(t=>{if(!(t.ctrlKey||t.metaKey))return;t.preventDefault();const l=t.deltaY>0?.9:1.1;nt(G.scale*l,t.clientX,t.clientY)},[G.scale,nt]),ba=a.useCallback(t=>{if(t.target.closest(".org-chart-node-card"))return;if(t.currentTarget.setPointerCapture?.(t.pointerId),L.current.set(t.pointerId,{x:t.clientX,y:t.clientY}),L.current.size===1){Q.current={x:t.clientX-G.x,y:t.clientY-G.y,pointerId:t.pointerId},Fe(!0);return}if(L.current.size===2){const c=Array.from(L.current.values()),g=c[0].x-c[1].x,M=c[0].y-c[1].y;be.current={distance:Math.hypot(g,M),scale:G.scale,centerX:(c[0].x+c[1].x)/2,centerY:(c[0].y+c[1].y)/2},Q.current=null}},[G.scale,G.x,G.y]),va=a.useCallback(t=>{if(L.current.has(t.pointerId)){if(L.current.set(t.pointerId,{x:t.clientX,y:t.clientY}),L.current.size>=2){const l=Array.from(L.current.values()),c=be.current;if(!c)return;const g=l[0].x-l[1].x,M=l[0].y-l[1].y,z=Math.hypot(g,M),fe=c.scale*(z/c.distance);nt(fe,c.centerX,c.centerY);return}!Q.current||Q.current.pointerId!==t.pointerId||B(l=>X({...l,x:t.clientX-Q.current.x,y:t.clientY-Q.current.y}))}},[X,nt]),Pt=a.useCallback(t=>{L.current.delete(t.pointerId),L.current.size<2&&(be.current=null),L.current.size===0&&(Q.current=null,Fe(!1))},[]),fa=a.useCallback(t=>{if(t.key==="ArrowLeft")B(l=>X({...l,x:l.x+ot}));else if(t.key==="ArrowRight")B(l=>X({...l,x:l.x-ot}));else if(t.key==="ArrowUp")B(l=>X({...l,y:l.y+ot}));else if(t.key==="ArrowDown")B(l=>X({...l,y:l.y-ot}));else if(t.key==="+"||t.key==="=")B(l=>X({...l,scale:l.scale*1.1}));else if(t.key==="-")B(l=>X({...l,scale:l.scale*.9}));else if(t.key==="0")Ue();else if(t.key==="Home")B({scale:1,x:0,y:0});else return;t.preventDefault()},[X,Ue]),zt=a.useCallback(()=>{const t=[{value:"horizontal",label:"Horizontal",icon:e.jsx(Gt,{size:16}),ariaLabel:"Horizontal layout"},{value:"vertical",label:"Vertical",icon:e.jsx(Wt,{size:16}),ariaLabel:"Vertical layout"},{value:"auto",label:"Auto",icon:e.jsx(qe,{size:16}),ariaLabel:"Automatic layout"}];return e.jsx("div",{className:"agent-org-chart-layout-toggle","data-testid":"agent-org-chart-layout-toggle",children:t.map(l=>{const c=re===l.value;return e.jsxs("button",{type:"button",className:`btn-icon touch-target agent-org-chart-layout-toggle__button${c?" btn-icon--active":""}`,onClick:()=>Lt(l.value),"aria-pressed":c,"aria-label":l.ariaLabel,title:l.ariaLabel,"data-layout-value":l.value,children:[l.icon,e.jsx("span",{className:"agent-org-chart-layout-toggle__text",children:l.label})]},l.value)})})},[Lt,re]),ja=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],mt=t=>Xa(t),Ft=y&&k.length===0,et=a.useCallback(()=>{H(!0)},[]);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(St,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${S==="list"?" active":""}`,onClick:()=>ut("list"),title:"List view","aria-label":"List view","aria-pressed":S==="list",children:e.jsx(Wt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${S==="board"?" active":""}`,onClick:()=>ut("board"),title:"Board view","aria-label":"Board view","aria-pressed":S==="board",children:e.jsx(Ze,{size:16})}),e.jsx("button",{className:`view-toggle-btn${S==="org"?" active":""}`,onClick:()=>ut("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":S==="org",children:e.jsx(Gt,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:Oe,className:`btn-icon agent-controls-trigger${oe?" agent-controls-trigger--active":""}`,onClick:()=>J(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":oe,"aria-controls":Pe,children:e.jsx(us,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void C(),title:"Refresh","aria-label":"Refresh",children:e.jsx(qe,{size:16,className:y?"spin":void 0})}),!d&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{I(!0),J(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(At,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{et(),J(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(Vt,{size:16}),"New Agent"]})]}),oe&&e.jsxs("div",{ref:we,id:Pe,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsx("div",{className:"agent-controls",children:e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Wa,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:f,onChange:t=>j(t.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:t=>x(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]})}),d&&e.jsxs("div",{className:"agent-controls-mobile-actions",children:[e.jsxs("button",{className:"btn btn-sm agent-import-trigger",onClick:()=>{I(!0),J(!1)},"aria-label":"Import",title:"Import",children:[e.jsx(At,{size:16}),"Import"]}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{et(),J(!1)},"aria-label":"New Agent",title:"New Agent",children:[e.jsx(Vt,{size:16}),"New Agent"]})]}),e.jsx("div",{className:"agent-global-controls agent-controls-actions",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:Ve,onChange:t=>{const l=Number(t.target.value);Qe(Number.isFinite(l)&&l>0?l:1)},disabled:Ke}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",Ve.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(kt.reduce((t,l)=>Math.abs(l-Ve)<Math.abs(t-Ve)?l:t,kt[0])),onChange:t=>{const l=Number(t.target.value);Qe(Number.isFinite(l)&&l>0?l:1)},disabled:Ke,"aria-label":"Heartbeat speed preset",children:kt.map(t=>e.jsxs("option",{value:String(t),children:["×",t]},t))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(xs,{agents:w})]})]})]})]}),e.jsx(Cs,{isOpen:E,onClose:()=>{H(!1),_(null)},onCreated:()=>{H(!1),_(null),C()},projectId:r,prefillDraft:R,agentOnboardingEnabled:u,existingAgents:k,onPrefillDraft:_}),e.jsx(As,{isOpen:b,onClose:()=>I(!1),onImported:()=>void C(),projectId:r}),e.jsx(ks,{stats:A,activeAgents:_e,projectId:r,isOpen:ce,onToggle:()=>pe(t=>!t),onSelectAgent:ga,onOpenTaskLogs:p}),S==="org"?e.jsx("div",{className:"agents-org-full-view",children:e.jsx("div",{className:"agents-view-content agents-view-content--org-full",children:$?e.jsxs("div",{className:"agents-org-detail-view","data-testid":"agents-org-detail-view",children:[e.jsx("button",{type:"button",className:"btn btn-sm agents-org-detail-back",onClick:We,"aria-label":"Back to org chart",children:"Back to org chart"}),e.jsx(a.Suspense,{fallback:null,children:e.jsx(ea,{inline:!0,showInlineBackButton:!1,agentId:$,projectId:r,onClose:We,addToast:n,onChildClick:Et,initialTab:ae,initialRunId:F,preferActiveRun:me},$)})]}):Ft?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(qe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):e.jsxs("div",{className:"agent-org-chart-shell","data-testid":"agent-org-chart-shell",children:[d?e.jsxs("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:[zt(),It()]}):e.jsxs("div",{className:"agent-org-chart-toolbar",children:[zt(),e.jsx("div",{className:"agent-org-chart-controls","data-testid":"agent-org-chart-controls",children:It()})]}),e.jsx("div",{ref:de,className:"agent-org-chart-viewport","data-testid":"agent-org-chart-viewport",tabIndex:0,role:"region","aria-label":"Org chart canvas",onWheel:xa,onPointerDown:ba,onPointerMove:va,onPointerUp:Pt,onPointerCancel:Pt,onKeyDown:fa,"data-panning":Le?"true":"false",children:e.jsxs("div",{ref:xe,className:`agent-org-chart-canvas agent-org-chart-canvas--zoom-${Math.round((G.scale??1)*100)}`,"data-panning":Le?"true":"false",style:{transform:`translate(${G.x}px, ${G.y}px) scale(${G.scale})`},children:[e.jsx("div",{className:`agent-org-chart${lt==="vertical"?" agent-org-chart--vertical":""}`,"data-testid":"agent-org-chart","data-layout-mode":lt,children:ye?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(qe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):V.length===0?e.jsx(ft,{onCtaClick:et}):(D.current=[],V.map(t=>e.jsx(la,{node:t,onSelect:ua,getHealthStatus:mt,selectedAgentId:Ne,registerNodeElement:pa,linksRef:D},t.agent.id)))}),e.jsx(zs,{links:D.current,nodeElements:Ae.current,canvasRef:xe,viewportRef:de,layoutMode:lt,transform:G})]})})]})})}):e.jsxs("div",{className:"agents-split-layout",children:[e.jsx("div",{className:`agents-split-sidebar${K?" agents-split-sidebar--hidden-mobile":""}`,children:e.jsx("div",{className:"agents-view-content",children:Ft?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(qe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):S==="board"?e.jsx("div",{className:"agent-board",children:w.length===0?e.jsx(ft,{onCtaClick:et}):w.map(t=>{const l=mt(t),c=Mt(t,l),g=Rt(t.state),M=Tt("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${M}${$===t.id?" agent-card--selected":""}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>ue(t.id),role:"button",tabIndex:0,onKeyDown:z=>{(z.key==="Enter"||z.key===" ")&&(z.key===" "&&z.preventDefault(),ue(t.id))},children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:e.jsx(dt,{agent:t,size:20})}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:$t(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${g}`,children:t.state}),(t.pendingApprovalCount??0)>0?e.jsxs("span",{className:"agent-board-badge badge agent-approval-badge",title:"Pending approvals",children:[e.jsx("span",{className:"status-dot status-dot--pending"}),t.pendingApprovalCount]}):null]}),e.jsx("div",{className:"agent-board-name",children:t.name}),e.jsx("div",{className:"agent-board-id",children:t.id}),e.jsxs("div",{className:"agent-board-health",style:{color:l.color},title:c.title,children:[l.icon,c.label?` ${c.label}`:""]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:w.length===0?e.jsx(ft,{onCtaClick:et}):w.map(t=>{const l=mt(t),c=Mt(t,l),g=Rt(t.state),M=Tt("agent-card",t.state),z=wt(t.runtimeConfig?.heartbeatIntervalMs),fe=Ga(z),je=se===t.id;return e.jsxs("div",{className:`agent-card agent-card--clickable ${M}${$===t.id?" agent-card--selected":""}`,onClick:h=>{const W=h.target;if(W===h.currentTarget){ue(t.id);return}const ne=W.closest('button, select, input, [role="button"]');ne&&ne!==h.currentTarget||ue(t.id)},role:"button",tabIndex:0,onKeyDown:h=>{h.target===h.currentTarget&&(h.key==="Enter"||h.key===" ")&&(h.key===" "&&h.preventDefault(),ue(t.id))},"aria-label":`Open details for ${t.name}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info",children:[i===t.id?e.jsx("select",{ref:O,className:"select agent-role-select",value:t.role,onChange:h=>void ra(t.id,h.target.value),onKeyDown:h=>oa(h,t.id),onBlur:()=>v(null),autoFocus:!0,children:yt.map(h=>e.jsxs("option",{value:h.value,children:[h.icon," ",h.label]},h.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:h=>{h.stopPropagation(),v(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.stopPropagation(),v(t.id))},children:e.jsx(dt,{agent:t,size:20})}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:t.name}),e.jsx("span",{className:"agent-id text-secondary",children:t.id})]}),e.jsx(ta,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${g}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:l.color},title:c.title,children:[l.icon,c.label?` ${c.label}`:""]}),e.jsx("span",{className:"badge text-secondary",children:$t(t.role)}),(t.pendingApprovalCount??0)>0?e.jsxs("span",{className:"badge agent-approval-badge",title:"Pending approvals",children:[e.jsx("span",{className:"status-dot status-dot--pending"}),t.pendingApprovalCount]}):null,(()=>{const h=ja(t);if(h.length===0)return null;const W=h.slice(0,2),ne=h.length-2;return e.jsxs(e.Fragment,{children:[W.map(tt=>e.jsx("span",{className:"badge badge-skill",title:tt,children:ns(tt)},tt)),ne>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",ne]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.state==="error"&&t.lastError?e.jsx(Va,{errorText:t.lastError,issueContext:{surface:"AgentsView list",agentId:t.id,agentName:t.name,agentState:t.state,taskId:t.taskId}}):null,t.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:t.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),Y===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:De[t.id]??"",onChange:h=>Te(W=>({...W,[t.id]:h.target.value})),onKeyDown:h=>{h.key==="Enter"?_t(t):h.key==="Escape"&&(Ce(null),Te(W=>{const ne={...W};return delete ne[t.id],ne}))},disabled:je,"aria-label":`Custom heartbeat interval in minutes for ${t.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>void _t(t),disabled:je,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>{Ce(null),Te(h=>{const W={...h};return delete W[t.id],W})},disabled:je,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:z,onChange:h=>{const W=h.target.value;W==="__custom__"?da(t):ca(t,Number(W))},disabled:je,"aria-label":`Set heartbeat interval for ${t.name}`,children:[fe.map(h=>e.jsx("option",{value:h.value,children:h.label},h.value)),Ka.some(h=>h.value===z)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),je&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const h=new Date(t.lastHeartbeatAt),W=new Date(h.getTime()+z),ne=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:h.toLocaleString(),children:["Last: ",h.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),ne&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:W.toLocaleString(),children:["Next: ",W.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--primary",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ve(t.id,"active"),disabled:Me.has(t.id),title:"Activate",children:[e.jsx(bt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Start"})]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ha(t.id,t.name),disabled:Me.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(Ze,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Run Now"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ve(t.id,"paused"),disabled:Me.has(t.id),title:"Pause",children:[e.jsx(Kt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ve(t.id,"active"),disabled:Me.has(t.id),title:"Resume",children:[e.jsx(bt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Resume"})]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn-sm",onClick:()=>ue(t.id,{initialTab:"runs",initialRunId:null,preferActiveRun:!0}),title:"View live run details","aria-label":`View live run details for ${t.name}`,children:[e.jsx(Ze,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Running"})]}),e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ve(t.id,"paused"),disabled:Me.has(t.id),title:"Pause",children:[e.jsx(Kt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Pause"})]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn-sm",onClick:()=>void ve(t.id,"active"),disabled:Me.has(t.id),title:"Retry",children:[e.jsx(bt,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Retry"})]})]}),e.jsxs("div",{className:"agent-card-actions-group agent-card-actions-group--secondary",children:[e.jsxs("button",{className:"btn btn-sm agent-card-details-btn",onClick:()=>ue(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:[e.jsx(rs,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Details"})]}),(t.state==="idle"||t.state==="paused")&&e.jsxs("button",{className:"btn btn-sm btn-danger",onClick:()=>void ia(t.id,t.name),title:"Delete",children:[e.jsx(Ua,{size:14})," ",e.jsx("span",{className:"agent-card-action-label",children:"Delete"})]})]})]})]},t.id)})})})}),e.jsx("div",{className:`agents-split-detail${d&&!$?" agents-split-detail--hidden-mobile":""}`,children:$?e.jsx(a.Suspense,{fallback:null,children:e.jsx(ea,{inline:!0,showInlineBackButton:d,agentId:$,projectId:r,onClose:We,addToast:n,onChildClick:Et,initialTab:ae,initialRunId:F,preferActiveRun:me,onMutationSuccess:ma},$)}):e.jsxs("div",{className:"agents-detail-empty-state",children:[e.jsx(St,{size:48}),e.jsx("h3",{children:"Select an agent"}),e.jsx("p",{children:"Choose an agent from the sidebar to view details"})]})})]})]})}export{Vs as AgentsView};
|