@runfusion/fusion 0.14.0 → 0.14.1
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 +82 -6
- package/dist/client/assets/{AgentDetailView-CBFUveyO.js → AgentDetailView-B3KAsP2O.js} +1 -1
- package/dist/client/assets/{AgentsView-DPezXQ-U.js → AgentsView-DoXb_amw.js} +3 -3
- package/dist/client/assets/{ChatView-5N4-EuhD.js → ChatView-BJ2c7wvd.js} +1 -1
- package/dist/client/assets/{DevServerView-Daft4YFc.js → DevServerView-DbgM4tlT.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-rew1y6qO.js → DirectoryPicker-DfmtfMiu.js} +1 -1
- package/dist/client/assets/{DocumentsView-i72qJzwd.js → DocumentsView-_-Efkx_W.js} +1 -1
- package/dist/client/assets/{InsightsView-BL5eZJ0a.js → InsightsView-DUjcfW53.js} +1 -1
- package/dist/client/assets/{MemoryView-pl8Cdg_p.js → MemoryView-DxMPBb0q.js} +1 -1
- package/dist/client/assets/{NodesView-D6eJ15zc.js → NodesView-BEBTI15s.js} +1 -1
- package/dist/client/assets/{PiExtensionsManager-ExInwXWP.js → PiExtensionsManager-BpMYhHH_.js} +1 -1
- package/dist/client/assets/PluginManager-CPv7yQd3.js +1 -0
- package/dist/client/assets/PluginManager-DA_T0GHn.css +1 -0
- package/dist/client/assets/{ResearchView-B_QPUEjB.js → ResearchView-BrFvdyXT.js} +1 -1
- package/dist/client/assets/{RoadmapsView-DBNLaEsK.js → RoadmapsView-BDjLrtcj.js} +1 -1
- package/dist/client/assets/{SettingsModal-1ET586M3.js → SettingsModal-Cd-QGB0C.js} +3 -3
- package/dist/client/assets/{SettingsModal-CL_gWmOj.js → SettingsModal-CxDxiTRy.js} +1 -1
- package/dist/client/assets/{SetupWizardModal-CLkY9HFL.js → SetupWizardModal-DFUA4X3z.js} +1 -1
- package/dist/client/assets/{SkillMultiselect-B0qi32SQ.js → SkillMultiselect-BUWe5ujb.js} +1 -1
- package/dist/client/assets/{SkillsView-umVjRq6o.js → SkillsView-RAkqGX3y.js} +1 -1
- package/dist/client/assets/TodoView-Ceb0wrg1.js +6 -0
- package/dist/client/assets/{folder-open-nYPrL1W3.js → folder-open-DcM-Vd6r.js} +1 -1
- package/dist/client/assets/{index-Bc8nfKeH.js → index-DH3aprf6.js} +6 -6
- package/dist/client/assets/{list-checks-sK8xJeH_.js → list-checks-ByGHVQpZ.js} +1 -1
- package/dist/client/assets/{star-BRtXbYkB.js → star-DlEYI8GL.js} +1 -1
- package/dist/client/assets/{upload-BP60eBwN.js → upload-DKshabz-.js} +1 -1
- package/dist/client/assets/{users-qSGAX2Pf.js → users-X6tYPPBV.js} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/client/version.json +1 -1
- package/dist/extension.js +82 -6
- package/dist/pi-claude-cli/package.json +1 -1
- package/package.json +1 -1
- package/dist/client/assets/PluginManager-CYhtxHun.js +0 -1
- package/dist/client/assets/PluginManager-jyNkJZSz.css +0 -1
- package/dist/client/assets/TodoView-CFifSvrD.js +0 -6
package/dist/bin.js
CHANGED
|
@@ -10373,7 +10373,7 @@ function validatePluginManifest(manifest) {
|
|
|
10373
10373
|
const m = manifest;
|
|
10374
10374
|
if (!m.id || typeof m.id !== "string" || m.id.trim() === "") {
|
|
10375
10375
|
errors.push("id is required and must be a non-empty string");
|
|
10376
|
-
} else if (
|
|
10376
|
+
} else if (!SLUG_PATTERN.test(m.id)) {
|
|
10377
10377
|
errors.push("id must be a valid slug (lowercase, alphanumeric, hyphens only, cannot start or end with hyphen)");
|
|
10378
10378
|
}
|
|
10379
10379
|
if (!m.name || typeof m.name !== "string" || m.name.trim() === "") {
|
|
@@ -10426,7 +10426,7 @@ function validatePluginManifest(manifest) {
|
|
|
10426
10426
|
const runtime = m.runtime;
|
|
10427
10427
|
if (!runtime.runtimeId || typeof runtime.runtimeId !== "string" || runtime.runtimeId.trim() === "") {
|
|
10428
10428
|
errors.push("runtime.runtimeId is required and must be a non-empty string");
|
|
10429
|
-
} else if (
|
|
10429
|
+
} else if (!SLUG_PATTERN.test(runtime.runtimeId)) {
|
|
10430
10430
|
errors.push("runtime.runtimeId must be a valid slug (lowercase, alphanumeric, hyphens only, cannot start or end with hyphen)");
|
|
10431
10431
|
}
|
|
10432
10432
|
if (!runtime.name || typeof runtime.name !== "string" || runtime.name.trim() === "") {
|
|
@@ -10441,14 +10441,93 @@ function validatePluginManifest(manifest) {
|
|
|
10441
10441
|
}
|
|
10442
10442
|
}
|
|
10443
10443
|
}
|
|
10444
|
+
if (m.skills !== void 0) {
|
|
10445
|
+
if (!Array.isArray(m.skills)) {
|
|
10446
|
+
errors.push("skills must be an array");
|
|
10447
|
+
} else {
|
|
10448
|
+
for (const [index2, skill] of m.skills.entries()) {
|
|
10449
|
+
if (!skill || typeof skill !== "object") {
|
|
10450
|
+
errors.push(`skills[${index2}] must be an object`);
|
|
10451
|
+
continue;
|
|
10452
|
+
}
|
|
10453
|
+
const skillMeta = skill;
|
|
10454
|
+
if (!skillMeta.skillId || typeof skillMeta.skillId !== "string" || skillMeta.skillId.trim() === "") {
|
|
10455
|
+
errors.push(`skills[${index2}].skillId is required and must be a non-empty string`);
|
|
10456
|
+
} else if (!SLUG_PATTERN.test(skillMeta.skillId)) {
|
|
10457
|
+
errors.push(`skills[${index2}].skillId must be a valid slug (lowercase, alphanumeric, hyphens only, cannot start or end with hyphen)`);
|
|
10458
|
+
}
|
|
10459
|
+
if (!skillMeta.name || typeof skillMeta.name !== "string" || skillMeta.name.trim() === "") {
|
|
10460
|
+
errors.push(`skills[${index2}].name is required and must be a non-empty string`);
|
|
10461
|
+
}
|
|
10462
|
+
}
|
|
10463
|
+
}
|
|
10464
|
+
}
|
|
10465
|
+
if (m.workflowSteps !== void 0) {
|
|
10466
|
+
if (!Array.isArray(m.workflowSteps)) {
|
|
10467
|
+
errors.push("workflowSteps must be an array");
|
|
10468
|
+
} else {
|
|
10469
|
+
for (const [index2, step] of m.workflowSteps.entries()) {
|
|
10470
|
+
if (!step || typeof step !== "object") {
|
|
10471
|
+
errors.push(`workflowSteps[${index2}] must be an object`);
|
|
10472
|
+
continue;
|
|
10473
|
+
}
|
|
10474
|
+
const stepMeta = step;
|
|
10475
|
+
if (!stepMeta.stepId || typeof stepMeta.stepId !== "string" || stepMeta.stepId.trim() === "") {
|
|
10476
|
+
errors.push(`workflowSteps[${index2}].stepId is required and must be a non-empty string`);
|
|
10477
|
+
} else if (!SLUG_PATTERN.test(stepMeta.stepId)) {
|
|
10478
|
+
errors.push(`workflowSteps[${index2}].stepId must be a valid slug (lowercase, alphanumeric, hyphens only, cannot start or end with hyphen)`);
|
|
10479
|
+
}
|
|
10480
|
+
if (!stepMeta.name || typeof stepMeta.name !== "string" || stepMeta.name.trim() === "") {
|
|
10481
|
+
errors.push(`workflowSteps[${index2}].name is required and must be a non-empty string`);
|
|
10482
|
+
}
|
|
10483
|
+
if (stepMeta.mode !== void 0 && (typeof stepMeta.mode !== "string" || !["prompt", "script"].includes(stepMeta.mode))) {
|
|
10484
|
+
errors.push(`workflowSteps[${index2}].mode must be one of: prompt, script`);
|
|
10485
|
+
}
|
|
10486
|
+
}
|
|
10487
|
+
}
|
|
10488
|
+
}
|
|
10489
|
+
if (m.promptSurfaces !== void 0) {
|
|
10490
|
+
if (!Array.isArray(m.promptSurfaces)) {
|
|
10491
|
+
errors.push("promptSurfaces must be an array");
|
|
10492
|
+
} else {
|
|
10493
|
+
for (const [index2, surface] of m.promptSurfaces.entries()) {
|
|
10494
|
+
if (typeof surface !== "string" || !PROMPT_CONTRIBUTION_SURFACES.includes(surface)) {
|
|
10495
|
+
errors.push(`promptSurfaces[${index2}] must be one of: ${PROMPT_CONTRIBUTION_SURFACES.join(", ")}`);
|
|
10496
|
+
}
|
|
10497
|
+
}
|
|
10498
|
+
}
|
|
10499
|
+
}
|
|
10500
|
+
if (m.setup !== void 0) {
|
|
10501
|
+
if (typeof m.setup !== "object" || m.setup === null) {
|
|
10502
|
+
errors.push("setup must be an object");
|
|
10503
|
+
} else {
|
|
10504
|
+
const setup = m.setup;
|
|
10505
|
+
if (!setup.binaryName || typeof setup.binaryName !== "string" || setup.binaryName.trim() === "") {
|
|
10506
|
+
errors.push("setup.binaryName is required and must be a non-empty string");
|
|
10507
|
+
}
|
|
10508
|
+
if (!setup.description || typeof setup.description !== "string" || setup.description.trim() === "") {
|
|
10509
|
+
errors.push("setup.description is required and must be a non-empty string");
|
|
10510
|
+
}
|
|
10511
|
+
if (setup.channel !== void 0 && (typeof setup.channel !== "string" || !SETUP_CHANNELS.includes(setup.channel))) {
|
|
10512
|
+
errors.push(`setup.channel must be one of: ${SETUP_CHANNELS.join(", ")}`);
|
|
10513
|
+
}
|
|
10514
|
+
if (setup.defaultTimeoutMs !== void 0 && (typeof setup.defaultTimeoutMs !== "number" || !Number.isFinite(setup.defaultTimeoutMs) || setup.defaultTimeoutMs <= 0)) {
|
|
10515
|
+
errors.push("setup.defaultTimeoutMs must be a positive finite number");
|
|
10516
|
+
}
|
|
10517
|
+
}
|
|
10518
|
+
}
|
|
10444
10519
|
return {
|
|
10445
10520
|
valid: errors.length === 0,
|
|
10446
10521
|
errors
|
|
10447
10522
|
};
|
|
10448
10523
|
}
|
|
10524
|
+
var SLUG_PATTERN, PROMPT_CONTRIBUTION_SURFACES, SETUP_CHANNELS;
|
|
10449
10525
|
var init_plugin_types = __esm({
|
|
10450
10526
|
"../core/src/plugin-types.ts"() {
|
|
10451
10527
|
"use strict";
|
|
10528
|
+
SLUG_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
10529
|
+
PROMPT_CONTRIBUTION_SURFACES = ["executor-system", "executor-task", "triage", "reviewer", "heartbeat"];
|
|
10530
|
+
SETUP_CHANNELS = ["stable", "beta", "nightly"];
|
|
10452
10531
|
}
|
|
10453
10532
|
});
|
|
10454
10533
|
|
|
@@ -53980,11 +54059,8 @@ async function createFnAgent2(options) {
|
|
|
53980
54059
|
const createSessionWithModel = async (modelOverride) => {
|
|
53981
54060
|
const customToolList = [
|
|
53982
54061
|
...wrappedTools,
|
|
53983
|
-
...
|
|
54062
|
+
...options.customTools ?? []
|
|
53984
54063
|
];
|
|
53985
|
-
if (isReadonly && (options.customTools?.length ?? 0) > 0) {
|
|
53986
|
-
piLog.log(`readonly session \u2014 customTools (${options.customTools.length}) skipped`);
|
|
53987
|
-
}
|
|
53988
54064
|
if (options.beforeSpawnSession) {
|
|
53989
54065
|
await options.beforeSpawnSession();
|
|
53990
54066
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as t,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Ge,dj as zs,dk as Bs,dl as Hs,dm as Is,L as _,R as We,al as ms,Z as Os,am as _e,V as Te,W as Ss,N as ks,dn as _s,dp as Vs,dq as Us,w as Cs,cx as Js,dr as Gs,z as q,ds as Ws,s as hs,B as gs,Q as Me,U as fs,a$ as ve,X as qs,F as be,A as Fe,I as qe,dt as Ys,cr as Ks,aF as Zs,bn as Qs,an as ws,Y as Xs,a1 as et,a3 as st,du as Ue,j as Rs,dv as tt,r as at,dw as nt,dx as it,dy as rt,dz as lt,dA as ct,dB as Ee,a9 as Le,ab as De,ac as $e,C as Q,a7 as Ms,dC as ot,dD as dt,i as ut,h as mt,k as ht,dE as Je,a2 as gt,dF as ft,dG as xt,dH as pt,dI as vt,dJ as bt,dK as Fs,dL as jt,dM as Nt,a0 as yt,dN as St,_ as kt,dO as Ct}from"./index-
|
|
1
|
+
import{r as t,j as e}from"./vendor-react-K0fH_qHe.js";import{c as Ge,dj as zs,dk as Bs,dl as Hs,dm as Is,L as _,R as We,al as ms,Z as Os,am as _e,V as Te,W as Ss,N as ks,dn as _s,dp as Vs,dq as Us,w as Cs,cx as Js,dr as Gs,z as q,ds as Ws,s as hs,B as gs,Q as Me,U as fs,a$ as ve,X as qs,F as be,A as Fe,I as qe,dt as Ys,cr as Ks,aF as Zs,bn as Qs,an as ws,Y as Xs,a1 as et,a3 as st,du as Ue,j as Rs,dv as tt,r as at,dw as nt,dx as it,dy as rt,dz as lt,dA as ct,dB as Ee,a9 as Le,ab as De,ac as $e,C as Q,a7 as Ms,dC as ot,dD as dt,i as ut,h as mt,k as ht,dE as Je,a2 as gt,dF as ft,dG as xt,dH as pt,dI as vt,dJ as bt,dK as Fs,dL as jt,dM as Nt,a0 as yt,dN as St,_ as kt,dO as Ct}from"./index-DH3aprf6.js";import{S as As}from"./star-DlEYI8GL.js";import{S as wt}from"./SkillMultiselect-BUWe5ujb.js";import{L as Ts}from"./list-checks-ByGHVQpZ.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
2
2
|
* @license lucide-react v1.7.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-
|
|
2
|
-
import{c as Ye,s as yt,A as Te,r as Je,F as Xe,f as wt,C as De,Z as jt,B as et,g as Ze,a as gt,b as Ve,d as kt,e as Nt,h as Ct,i as It,u as nt,P as St,j as At,k as Et,l as Tt,m as Mt,n as Pt,o as Rt,p as _t,q as $t,t as at,G as Ft,S as Lt,L as We,T as Ue,R as Oe,X as st,v as zt,w as Dt,x as Ot,y as Ht,z as be,D as Ke,E as qt,H as Vt,I as Wt,J as Ut,K as Kt,M as Bt,N as ht,O as Gt,Q as $e,U as it,V as Qt,W as Jt,Y as Xt,_ as Fe,$ as Zt,a0 as rt,a1 as Yt,a2 as en,a3 as tn,a4 as nn}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-B3KAsP2O.js","assets/vendor-react-K0fH_qHe.js","assets/index-DH3aprf6.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-C1prPuSl.css","assets/star-DlEYI8GL.js","assets/SkillMultiselect-BUWe5ujb.js","assets/SkillMultiselect-DDHJnrkn.css","assets/list-checks-ByGHVQpZ.js","assets/AgentDetailView-B5tq9ius.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as Ye,s as yt,A as Te,r as Je,F as Xe,f as wt,C as De,Z as jt,B as et,g as Ze,a as gt,b as Ve,d as kt,e as Nt,h as Ct,i as It,u as nt,P as St,j as At,k as Et,l as Tt,m as Mt,n as Pt,o as Rt,p as _t,q as $t,t as at,G as Ft,S as Lt,L as We,T as Ue,R as Oe,X as st,v as zt,w as Dt,x as Ot,y as Ht,z as be,D as Ke,E as qt,H as Vt,I as Wt,J as Ut,K as Kt,M as Bt,N as ht,O as Gt,Q as $e,U as it,V as Qt,W as Jt,Y as Xt,_ as Fe,$ as Zt,a0 as rt,a1 as Yt,a2 as en,a3 as tn,a4 as nn}from"./index-DH3aprf6.js";import{r as a,j as e,a as an}from"./vendor-react-K0fH_qHe.js";import{S as sn}from"./SkillMultiselect-BUWe5ujb.js";import{U as pt}from"./upload-DKshabz-.js";import{F as rn}from"./folder-open-DcM-Vd6r.js";import"./vendor-xterm-DzcZoU0P.js";/**
|
|
3
3
|
* @license lucide-react v1.7.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -519,4 +519,4 @@ reportsTo: null
|
|
|
519
519
|
skills:
|
|
520
520
|
- review
|
|
521
521
|
---
|
|
522
|
-
Agent instructions go here...`,value:u,onChange:i=>{m("paste"),b([]),p(i.target.value),F(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),se&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),se]})]}),c==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:w})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Xe,{size:14}),e.jsxs("span",{children:[T.length," agent",T.length!==1?"s":""," found"]})]}),T.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(T.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((i,x)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:A.includes(i.name),onChange:()=>Me(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},x))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),S.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Xe,{size:14}),e.jsxs("span",{children:[S.length," skill",S.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_(S.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((i,x)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:E.includes(i.name),onChange:()=>Ie(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${x}`))})]}),J&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),J]})]}),c==="result"&&h&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(De,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:h.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.created.length," created"]})}),h.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skipped.length," skipped (already exist)"]})}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.errors.length," error",h.errors.length!==1?"s":""]})})]}),h.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.created.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))}),h.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.skills.imported.length," skill",h.skills.imported.length!==1?"s":""," imported"]})}),h.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skills.skipped.length," skill",h.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.skills.errors.length," skill",h.skills.errors.length!==1?"s":""," error",h.skills.errors.length!==1?"s":""]})}),h.skills.imported.length===0&&h.skills.skipped.length===0&&h.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.skills.imported.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.skills.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[c==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:Q,children:"Back"}),e.jsx("button",{className:"btn",onClick:H,disabled:Q,children:c==="result"?"Close":"Cancel"}),c==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void re(),disabled:P||(r==="directory"?f.length===0:r==="browse"?!L:!u.trim()),children:P?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),c==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ye(),disabled:Q||O===0&&z===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),le]}):`Import ${Ne}`})]})]})}):null}const Gn=a.lazy(()=>nn(()=>import("./AgentDetailView-CBFUveyO.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(s=>({default:s.AgentDetailView}))),ze=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Qe=[.1,.25,.5,1,2,3,5,10];function He(s){switch(s){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function qe(s,l){switch(l){case"running":return`${s}--running`;case"active":return`${s}--active`;case"paused":return`${s}--paused`;case"error":return`${s}--error`;case"terminated":return`${s}--terminated`;case"idle":default:return`${s}--idle`}}function vt({node:s,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m}){const{agent:u,children:p,depth:f}=s,b=c(u.id),w=g(u.id),C=o(u),T=He(u.state),M=qe("agent-tree__node",u.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${M}${u.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(f,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${b===0?" agent-tree__toggle--leaf":""}`,onClick:()=>b>0&&y(u.id),title:b>0?w?"Collapse":"Expand":"No employees","aria-label":b>0?w?"Collapse":"Expand":"No employees",children:b>0?w?e.jsx(Jt,{size:16}):e.jsx(ht,{size:16}):e.jsx(et,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:S=>S.key==="Enter"&&l(u.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(u.role)}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:`agent-tree__badge ${T}`,children:u.state}),e.jsx("span",{className:"agent-tree__health",style:{color:C.color},title:C.label,children:C.icon}),b>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",b,")"]}),(()=>{const S=m(u);return S.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:S.join(", "),children:[S[0],S.length>1&&` +${S.length-1}`]})})()]})]}),w&&p.length>0&&e.jsx("div",{className:"agent-tree__children",children:p.map(S=>e.jsx(vt,{node:S,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m},S.agent.id))})]})}function xt({node:s,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c}){const{agent:o,children:r}=s,m=y(o),u=He(o.state),p=qe("org-chart-node-card",o.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:p,onClick:()=>l(o.id),role:"button",tabIndex:0,onKeyDown:f=>f.key==="Enter"&&l(o.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:g(o.role)}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${u}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:m.color},title:m.label,children:[m.icon,!m.stateDerived&&e.jsx("span",{className:"text-secondary",children:m.label})]}),(()=>{const f=c(o);if(f.length===0)return null;const b=f.slice(0,2),w=f.length-2;return e.jsxs(e.Fragment,{children:[b.map(C=>e.jsx("span",{className:"org-chart-node__skill",children:C},C)),w>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",w]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:r.map(f=>e.jsx(xt,{node:f,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c},f.agent.id))})]})}function ta({addToast:s,projectId:l,onOpenTaskLogs:y,agentOnboardingEnabled:g=!1}){const[c,o]=a.useState(!1),[r,m]=a.useState("all"),{agents:u,stats:p,isLoading:f,loadAgents:b}=zt(l,{filterState:r,showSystemAgents:c}),[w,C]=a.useState(!1),[T,M]=a.useState(!1),[S,j]=a.useState(null),[A,v]=a.useState(!1),[E,_]=a.useState(null),[P,D]=a.useState(()=>{if(typeof window>"u")return"list";const n=Ze("fn-agent-view",l);return n==="list"||n==="board"||n==="tree"||n==="org"?n:"list"}),[Q,q]=a.useState([]),[se,F]=a.useState(!1),[h,I]=a.useState(!1),J=a.useRef(null),{confirm:V}=Dt(),X=a.useRef(null),ie=a.useId();a.useEffect(()=>{const n=Ze("fn-agent-view",l);if(n==="list"||n==="board"||n==="tree"||n==="org"){D(n);return}D("list")},[l]),a.useEffect(()=>{gt("fn-agent-view",P,l)},[P,l]);const[ve,W]=a.useState(null),ne=a.useRef(null),[ke,L]=a.useState(null),[oe,U]=a.useState(null),[ce,ae]=a.useState({}),[K,ue]=a.useState(1),[me,ge]=a.useState(!1),[H,xe]=a.useState(new Set),[Z,he]=a.useState(new Map),re=a.useRef(!0);a.useEffect(()=>(re.current=!0,()=>{re.current=!1}),[]),a.useEffect(()=>{Ot(l).then(n=>{re.current&&ue(n.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const ye=a.useCallback(async n=>{const t=Number.isFinite(n)&&n>0?n:1;ue(t),ge(!0);try{await Ht({heartbeatMultiplier:t},l),s(`Heartbeat speed set to ×${t.toFixed(1)}`,"success")}catch(d){s(`Failed to save heartbeat multiplier: ${be(d)}`,"error")}finally{re.current&&ge(!1)}},[l,s]),O=a.useMemo(()=>Z.size===0?u:u.map(n=>{const t=Z.get(n.id);return t?{...n,state:t}:n}),[u,Z]),z=jn(O,l),de=a.useMemo(()=>O.filter(n=>c||!Ke(n)),[O,c]),we=a.useMemo(()=>O.filter(n=>n.state!=="active"&&n.state!=="running"?!1:c||!Ke(n)),[O,c]),Ne=a.useMemo(()=>{if(c)return Q;const n=t=>Ke(t.agent)?null:{...t,children:t.children.map(n).filter(d=>d!==null)};return Q.map(n).filter(t=>t!==null)},[Q,c]);a.useEffect(()=>{if(P!=="org")return;let n=!1;return F(!0),qt(l,{includeEphemeral:c}).then(t=>{n||q(t)}).catch(t=>{n||(s(`Failed to load org chart: ${be(t)}`,"error"),q([]))}).finally(()=>{n||F(!1)}),()=>{n=!0}},[P,l,c,s]),a.useEffect(()=>{const n=setInterval(()=>{b()},3e4);return()=>{clearInterval(n)}},[b]),a.useEffect(()=>{if(!h)return;const n=d=>{const k=d.target;k&&(J.current?.contains(k)||X.current?.contains(k)||I(!1))},t=d=>{d.key==="Escape"&&(I(!1),X.current?.focus())};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),document.removeEventListener("keydown",t)}},[h]);const le=async(n,t)=>{if(!H.has(n)){xe(d=>new Set(d).add(n)),he(d=>{const k=new Map(d);return k.set(n,t),k});try{await Yt(n,t,l),s(`Agent state updated to ${t}`,"success"),await b(),he(d=>{const k=new Map(d);return k.delete(n),k})}catch(d){he(k=>{const $=new Map(k);return $.delete(n),$}),s(`Failed to update state: ${be(d)}`,"error")}finally{xe(d=>{const k=new Set(d);return k.delete(n),k})}}},Me=async(n,t)=>{if(await V({title:"Delete Agent",message:`Delete agent "${t}"? This cannot be undone.`,danger:!0}))try{await tn(n,l),s(`Agent "${t}" deleted`,"success"),b()}catch(k){s(`Failed to delete agent: ${be(k)}`,"error")}},Ie=async(n,t)=>{const d=u.find(k=>k.id===n);if(d){if(d.role===t){W(null);return}try{await Fe(n,{role:t},l),s(`Agent role updated to ${ze.find(k=>k.value===t)?.label??t}`,"success"),W(null),b()}catch(k){s(`Failed to update role: ${be(k)}`,"error")}}},i=(n,t)=>{n.key==="Escape"&&W(null)},x=async(n,t)=>{oe===n.id&&(U(null),ae(d=>{const k={...d};return delete k[n.id],k})),L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:t}},l),s(`Heartbeat interval updated to ${rt(t)} for ${n.name}`,"success"),b()}catch(d){s(`Failed to update heartbeat interval: ${be(d)}`,"error")}finally{L(null)}},R=async n=>{const t=ce[n.id]??"";if(t.trim()===""){s("Please enter a heartbeat interval in minutes","error");return}const d=Number(t);if(isNaN(d)){s("Heartbeat interval must be a valid number","error");return}if(d<=0){s("Heartbeat interval must be greater than 0","error");return}if(d>=1&&d<5){L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:Zt}},l),s(`Heartbeat interval set to 5 minutes (minimum). ${d} minute${d!==1?"s":""} was below the 5-minute minimum.`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}return}const k=Math.round(d*6e4);L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:k}},l),s(`Heartbeat interval updated to ${rt(k)} for ${n.name}`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}},Y=n=>{const t=Je(n.runtimeConfig?.heartbeatIntervalMs),d=Math.round(t/6e4);U(n.id),ae(k=>({...k,[n.id]:String(d)}))},B=a.useCallback(()=>{_(null)},[]),G=a.useCallback(n=>{_(n)},[]),Pe=async(n,t)=>{try{await en(n,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${t}`,"success"),b()}catch(d){s(`Failed to start heartbeat run: ${be(d)}`,"error")}},pe=n=>ze.find(t=>t.value===n)?.label??n,Se=n=>ze.find(t=>t.value===n)?.icon??"◆",Ae=n=>Array.isArray(n.metadata?.skills)?n.metadata.skills:[],fe=n=>Xt(n),Re=f&&u.length===0,je=a.useCallback(()=>{if(g){M(!0);return}C(!0)},[g]);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(et,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${P==="list"?" active":""}`,onClick:()=>D("list"),title:"List view","aria-label":"List view","aria-pressed":P==="list",children:e.jsx(Vt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="board"?" active":""}`,onClick:()=>D("board"),title:"Board view","aria-label":"Board view","aria-pressed":P==="board",children:e.jsx(Te,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="tree"?" active":""}`,onClick:()=>D("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":P==="tree",children:e.jsx(Wt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="org"?" active":""}`,onClick:()=>D("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":P==="org",children:e.jsx(dn,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:X,className:`btn-icon agent-controls-trigger${h?" agent-controls-trigger--active":""}`,onClick:()=>I(n=>!n),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":h,"aria-controls":ie,children:e.jsx(mn,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void b(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Oe,{size:16,className:f?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{je(),I(!1)},children:[e.jsx(Ut,{size:16}),"New Agent"]})]})]})]}),h&&e.jsxs("div",{ref:J,id:ie,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Kt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:r,onChange:n=>m(n.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"}),e.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:n=>o(n.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{v(!0),I(!1)},children:[e.jsx(pt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:K,onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",K.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Qe.reduce((n,t)=>Math.abs(t-K)<Math.abs(n-K)?t:n,Qe[0])),onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me,"aria-label":"Heartbeat speed preset",children:Qe.map(n=>e.jsxs("option",{value:String(n),children:["×",n]},n))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(xn,{agents:de})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(vn,{stats:p}),e.jsx(fn,{agents:we,projectId:l,onAgentSelect:_,onOpenTaskLogs:y}),e.jsx(Wn,{isOpen:w,onClose:()=>{C(!1),j(null)},onCreated:()=>{C(!1),j(null),b()},projectId:l,prefillDraft:S}),e.jsx(Un,{isOpen:T,onClose:()=>M(!1),onUseDraft:n=>{j(n),M(!1),C(!0)},projectId:l,existingAgents:u}),e.jsx(Bn,{isOpen:A,onClose:()=>v(!1),onImported:()=>void b(),projectId:l}),Re?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):P==="tree"?e.jsx("div",{className:"agent-tree__view",children:de.length===0?e.jsx(Le,{onCtaClick:je}):z.rootNodes.map(n=>e.jsx(vt,{node:n,onSelect:_,onToggle:z.toggleExpand,isExpanded:z.isExpanded,getChildCount:t=>z.getChildren(t).length,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:se?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):Ne.length===0?e.jsx(Le,{onCtaClick:je}):Ne.map(n=>e.jsx(xt,{node:n,onSelect:_,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="board"?e.jsx("div",{className:"agent-board",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-board-card",n.state);return e.jsx("div",{className:`agent-board-card ${k}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:$=>$.key==="Enter"&&_(n.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:Se(n.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:pe(n.role)}),e.jsx("span",{className:`agent-board-badge badge ${d}`,children:n.state})]}),e.jsx("div",{className:"agent-board-name",children:n.name}),e.jsx("div",{className:"agent-board-id",children:n.id}),e.jsxs("div",{className:"agent-board-health",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]})]})},n.id)})}):e.jsx("div",{className:"agent-list",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-card",n.state),$=Je(n.runtimeConfig?.heartbeatIntervalMs),ee=Bt($),_e=ke===n.id;return e.jsxs("div",{className:`agent-card ${k}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:N=>N.key==="Enter"&&_(n.id),children:[ve===n.id?e.jsx("select",{ref:ne,className:"select agent-role-select",value:n.role,onChange:N=>void Ie(n.id,N.target.value),onKeyDown:N=>i(N,n.id),onBlur:()=>W(null),autoFocus:!0,children:ze.map(N=>e.jsxs("option",{value:N.value,children:[N.icon," ",N.label]},N.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:N=>{N.stopPropagation(),W(n.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.stopPropagation(),W(n.id))},children:Se(n.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:n.name}),e.jsx("span",{className:"agent-id text-secondary",children:n.id})]}),e.jsx(ht,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${d}`,children:n.state}),e.jsxs("span",{className:"badge",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]}),e.jsx("span",{className:"badge text-secondary",children:pe(n.role)}),(()=>{const N=Ae(n);if(N.length===0)return null;const te=N.slice(0,2),Ce=N.length-2;return e.jsxs(e.Fragment,{children:[te.map(tt=>e.jsx("span",{className:"badge badge-skill",children:tt},tt)),Ce>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",Ce]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[n.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:n.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),oe===n.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:ce[n.id]??"",onChange:N=>ae(te=>({...te,[n.id]:N.target.value})),onKeyDown:N=>{N.key==="Enter"?R(n):N.key==="Escape"&&(U(null),ae(te=>{const Ce={...te};return delete Ce[n.id],Ce}))},disabled:_e,"aria-label":`Custom heartbeat interval in minutes for ${n.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void R(n),disabled:_e,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{U(null),ae(N=>{const te={...N};return delete te[n.id],te})},disabled:_e,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:$,onChange:N=>{const te=N.target.value;te==="__custom__"?Y(n):x(n,Number(te))},disabled:_e,"aria-label":`Set heartbeat interval for ${n.name}`,children:[ee.map(N=>e.jsx("option",{value:N.value,children:N.label},N.value)),Gt.some(N=>N.value===$)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),_e&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),n.lastHeartbeatAt&&(()=>{const N=new Date(n.lastHeartbeatAt),te=new Date(N.getTime()+$),Ce=n.state==="active"||n.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:N.toLocaleString(),children:["Last: ",N.toLocaleTimeString()]}),Ce&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:te.toLocaleString(),children:["Next: ",te.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[n.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Activate",children:[e.jsx($e,{size:14})," Start"]}),n.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void Pe(n.id,n.name),disabled:H.has(n.id),title:"Run Now","aria-label":`Run now for ${n.name}`,children:[e.jsx(Te,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Resume",children:[e.jsx($e,{size:14})," Resume"]}),n.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${n.name}`,children:[e.jsx(Te,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Retry",children:[e.jsx($e,{size:14})," Retry"]}),n.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Start",children:[e.jsx($e,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>_(n.id),title:`View details for ${n.name}`,"aria-label":`View details for ${n.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void Me(n.id,n.name),title:"Delete",children:[e.jsx(Qt,{size:14})," Delete"]})]})]},n.id)})})]}),E&&e.jsx(a.Suspense,{fallback:null,children:e.jsx(Gn,{agentId:E,projectId:l,onClose:B,addToast:s,onChildClick:G})})]})}export{ta as AgentsView};
|
|
522
|
+
Agent instructions go here...`,value:u,onChange:i=>{m("paste"),b([]),p(i.target.value),F(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),se&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),se]})]}),c==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:w})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Xe,{size:14}),e.jsxs("span",{children:[T.length," agent",T.length!==1?"s":""," found"]})]}),T.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v(T.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>v([]),children:"Clear agents"})]}),T.length>0?e.jsx("div",{className:"agent-import-agent-list",children:T.map((i,x)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:A.includes(i.name),onChange:()=>Me(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},x))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),S.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Xe,{size:14}),e.jsxs("span",{children:[S.length," skill",S.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_(S.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:S.map((i,x)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:E.includes(i.name),onChange:()=>Ie(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${x}`))})]}),J&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(Ue,{size:14}),J]})]}),c==="result"&&h&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(De,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:h.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.created.length," created"]})}),h.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skipped.length," skipped (already exist)"]})}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.errors.length," error",h.errors.length!==1?"s":""]})})]}),h.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.created.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))}),h.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[h.skills.imported.length," skill",h.skills.imported.length!==1?"s":""," imported"]})}),h.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[h.skills.skipped.length," skill",h.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[h.skills.errors.length," skill",h.skills.errors.length!==1?"s":""," error",h.skills.errors.length!==1?"s":""]})}),h.skills.imported.length===0&&h.skills.skipped.length===0&&h.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),h.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:h.skills.imported.map((i,x)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(De,{size:12}),e.jsx("span",{children:i.name})]},x))}),h.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:h.skills.errors.map((i,x)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(st,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},x))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[c==="preview"&&e.jsx("button",{className:"btn",onClick:()=>o("input"),disabled:Q,children:"Back"}),e.jsx("button",{className:"btn",onClick:H,disabled:Q,children:c==="result"?"Close":"Cancel"}),c==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void re(),disabled:P||(r==="directory"?f.length===0:r==="browse"?!L:!u.trim()),children:P?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),c==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ye(),disabled:Q||O===0&&z===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(We,{size:14,className:"spin"}),le]}):`Import ${Ne}`})]})]})}):null}const Gn=a.lazy(()=>nn(()=>import("./AgentDetailView-B3KAsP2O.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(s=>({default:s.AgentDetailView}))),ze=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Qe=[.1,.25,.5,1,2,3,5,10];function He(s){switch(s){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function qe(s,l){switch(l){case"running":return`${s}--running`;case"active":return`${s}--active`;case"paused":return`${s}--paused`;case"error":return`${s}--error`;case"terminated":return`${s}--terminated`;case"idle":default:return`${s}--idle`}}function vt({node:s,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m}){const{agent:u,children:p,depth:f}=s,b=c(u.id),w=g(u.id),C=o(u),T=He(u.state),M=qe("agent-tree__node",u.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${M}${u.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(f,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${b===0?" agent-tree__toggle--leaf":""}`,onClick:()=>b>0&&y(u.id),title:b>0?w?"Collapse":"Expand":"No employees","aria-label":b>0?w?"Collapse":"Expand":"No employees",children:b>0?w?e.jsx(Jt,{size:16}):e.jsx(ht,{size:16}):e.jsx(et,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:S=>S.key==="Enter"&&l(u.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(u.role)}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:`agent-tree__badge ${T}`,children:u.state}),e.jsx("span",{className:"agent-tree__health",style:{color:C.color},title:C.label,children:C.icon}),b>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",b,")"]}),(()=>{const S=m(u);return S.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:S.join(", "),children:[S[0],S.length>1&&` +${S.length-1}`]})})()]})]}),w&&p.length>0&&e.jsx("div",{className:"agent-tree__children",children:p.map(S=>e.jsx(vt,{node:S,onSelect:l,onToggle:y,isExpanded:g,getChildCount:c,getHealthStatus:o,getRoleIcon:r,getSkillBadges:m},S.agent.id))})]})}function xt({node:s,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c}){const{agent:o,children:r}=s,m=y(o),u=He(o.state),p=qe("org-chart-node-card",o.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:p,onClick:()=>l(o.id),role:"button",tabIndex:0,onKeyDown:f=>f.key==="Enter"&&l(o.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:g(o.role)}),e.jsx("span",{className:"org-chart-node__name",children:o.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${u}`,children:o.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:m.color},title:m.label,children:[m.icon,!m.stateDerived&&e.jsx("span",{className:"text-secondary",children:m.label})]}),(()=>{const f=c(o);if(f.length===0)return null;const b=f.slice(0,2),w=f.length-2;return e.jsxs(e.Fragment,{children:[b.map(C=>e.jsx("span",{className:"org-chart-node__skill",children:C},C)),w>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",w]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${o.name} employees`,children:r.map(f=>e.jsx(xt,{node:f,onSelect:l,getHealthStatus:y,getRoleIcon:g,getSkillBadges:c},f.agent.id))})]})}function ta({addToast:s,projectId:l,onOpenTaskLogs:y,agentOnboardingEnabled:g=!1}){const[c,o]=a.useState(!1),[r,m]=a.useState("all"),{agents:u,stats:p,isLoading:f,loadAgents:b}=zt(l,{filterState:r,showSystemAgents:c}),[w,C]=a.useState(!1),[T,M]=a.useState(!1),[S,j]=a.useState(null),[A,v]=a.useState(!1),[E,_]=a.useState(null),[P,D]=a.useState(()=>{if(typeof window>"u")return"list";const n=Ze("fn-agent-view",l);return n==="list"||n==="board"||n==="tree"||n==="org"?n:"list"}),[Q,q]=a.useState([]),[se,F]=a.useState(!1),[h,I]=a.useState(!1),J=a.useRef(null),{confirm:V}=Dt(),X=a.useRef(null),ie=a.useId();a.useEffect(()=>{const n=Ze("fn-agent-view",l);if(n==="list"||n==="board"||n==="tree"||n==="org"){D(n);return}D("list")},[l]),a.useEffect(()=>{gt("fn-agent-view",P,l)},[P,l]);const[ve,W]=a.useState(null),ne=a.useRef(null),[ke,L]=a.useState(null),[oe,U]=a.useState(null),[ce,ae]=a.useState({}),[K,ue]=a.useState(1),[me,ge]=a.useState(!1),[H,xe]=a.useState(new Set),[Z,he]=a.useState(new Map),re=a.useRef(!0);a.useEffect(()=>(re.current=!0,()=>{re.current=!1}),[]),a.useEffect(()=>{Ot(l).then(n=>{re.current&&ue(n.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const ye=a.useCallback(async n=>{const t=Number.isFinite(n)&&n>0?n:1;ue(t),ge(!0);try{await Ht({heartbeatMultiplier:t},l),s(`Heartbeat speed set to ×${t.toFixed(1)}`,"success")}catch(d){s(`Failed to save heartbeat multiplier: ${be(d)}`,"error")}finally{re.current&&ge(!1)}},[l,s]),O=a.useMemo(()=>Z.size===0?u:u.map(n=>{const t=Z.get(n.id);return t?{...n,state:t}:n}),[u,Z]),z=jn(O,l),de=a.useMemo(()=>O.filter(n=>c||!Ke(n)),[O,c]),we=a.useMemo(()=>O.filter(n=>n.state!=="active"&&n.state!=="running"?!1:c||!Ke(n)),[O,c]),Ne=a.useMemo(()=>{if(c)return Q;const n=t=>Ke(t.agent)?null:{...t,children:t.children.map(n).filter(d=>d!==null)};return Q.map(n).filter(t=>t!==null)},[Q,c]);a.useEffect(()=>{if(P!=="org")return;let n=!1;return F(!0),qt(l,{includeEphemeral:c}).then(t=>{n||q(t)}).catch(t=>{n||(s(`Failed to load org chart: ${be(t)}`,"error"),q([]))}).finally(()=>{n||F(!1)}),()=>{n=!0}},[P,l,c,s]),a.useEffect(()=>{const n=setInterval(()=>{b()},3e4);return()=>{clearInterval(n)}},[b]),a.useEffect(()=>{if(!h)return;const n=d=>{const k=d.target;k&&(J.current?.contains(k)||X.current?.contains(k)||I(!1))},t=d=>{d.key==="Escape"&&(I(!1),X.current?.focus())};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n),document.removeEventListener("keydown",t)}},[h]);const le=async(n,t)=>{if(!H.has(n)){xe(d=>new Set(d).add(n)),he(d=>{const k=new Map(d);return k.set(n,t),k});try{await Yt(n,t,l),s(`Agent state updated to ${t}`,"success"),await b(),he(d=>{const k=new Map(d);return k.delete(n),k})}catch(d){he(k=>{const $=new Map(k);return $.delete(n),$}),s(`Failed to update state: ${be(d)}`,"error")}finally{xe(d=>{const k=new Set(d);return k.delete(n),k})}}},Me=async(n,t)=>{if(await V({title:"Delete Agent",message:`Delete agent "${t}"? This cannot be undone.`,danger:!0}))try{await tn(n,l),s(`Agent "${t}" deleted`,"success"),b()}catch(k){s(`Failed to delete agent: ${be(k)}`,"error")}},Ie=async(n,t)=>{const d=u.find(k=>k.id===n);if(d){if(d.role===t){W(null);return}try{await Fe(n,{role:t},l),s(`Agent role updated to ${ze.find(k=>k.value===t)?.label??t}`,"success"),W(null),b()}catch(k){s(`Failed to update role: ${be(k)}`,"error")}}},i=(n,t)=>{n.key==="Escape"&&W(null)},x=async(n,t)=>{oe===n.id&&(U(null),ae(d=>{const k={...d};return delete k[n.id],k})),L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:t}},l),s(`Heartbeat interval updated to ${rt(t)} for ${n.name}`,"success"),b()}catch(d){s(`Failed to update heartbeat interval: ${be(d)}`,"error")}finally{L(null)}},R=async n=>{const t=ce[n.id]??"";if(t.trim()===""){s("Please enter a heartbeat interval in minutes","error");return}const d=Number(t);if(isNaN(d)){s("Heartbeat interval must be a valid number","error");return}if(d<=0){s("Heartbeat interval must be greater than 0","error");return}if(d>=1&&d<5){L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:Zt}},l),s(`Heartbeat interval set to 5 minutes (minimum). ${d} minute${d!==1?"s":""} was below the 5-minute minimum.`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}return}const k=Math.round(d*6e4);L(n.id);try{await Fe(n.id,{runtimeConfig:{...n.runtimeConfig??{},heartbeatIntervalMs:k}},l),s(`Heartbeat interval updated to ${rt(k)} for ${n.name}`,"success"),U(null),ae($=>{const ee={...$};return delete ee[n.id],ee}),b()}catch($){s(`Failed to update heartbeat interval: ${be($)}`,"error")}finally{L(null)}},Y=n=>{const t=Je(n.runtimeConfig?.heartbeatIntervalMs),d=Math.round(t/6e4);U(n.id),ae(k=>({...k,[n.id]:String(d)}))},B=a.useCallback(()=>{_(null)},[]),G=a.useCallback(n=>{_(n)},[]),Pe=async(n,t)=>{try{await en(n,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),s(`Heartbeat run started for ${t}`,"success"),b()}catch(d){s(`Failed to start heartbeat run: ${be(d)}`,"error")}},pe=n=>ze.find(t=>t.value===n)?.label??n,Se=n=>ze.find(t=>t.value===n)?.icon??"◆",Ae=n=>Array.isArray(n.metadata?.skills)?n.metadata.skills:[],fe=n=>Xt(n),Re=f&&u.length===0,je=a.useCallback(()=>{if(g){M(!0);return}C(!0)},[g]);return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(et,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${P==="list"?" active":""}`,onClick:()=>D("list"),title:"List view","aria-label":"List view","aria-pressed":P==="list",children:e.jsx(Vt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="board"?" active":""}`,onClick:()=>D("board"),title:"Board view","aria-label":"Board view","aria-pressed":P==="board",children:e.jsx(Te,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="tree"?" active":""}`,onClick:()=>D("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":P==="tree",children:e.jsx(Wt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${P==="org"?" active":""}`,onClick:()=>D("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":P==="org",children:e.jsx(dn,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:X,className:`btn-icon agent-controls-trigger${h?" agent-controls-trigger--active":""}`,onClick:()=>I(n=>!n),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":h,"aria-controls":ie,children:e.jsx(mn,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void b(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Oe,{size:16,className:f?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{je(),I(!1)},children:[e.jsx(Ut,{size:16}),"New Agent"]})]})]})]}),h&&e.jsxs("div",{ref:J,id:ie,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Kt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:r,onChange:n=>m(n.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"}),e.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:n=>o(n.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{v(!0),I(!1)},children:[e.jsx(pt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:K,onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",K.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Qe.reduce((n,t)=>Math.abs(t-K)<Math.abs(n-K)?t:n,Qe[0])),onChange:n=>{const t=Number(n.target.value);ye(Number.isFinite(t)&&t>0?t:1)},disabled:me,"aria-label":"Heartbeat speed preset",children:Qe.map(n=>e.jsxs("option",{value:String(n),children:["×",n]},n))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(xn,{agents:de})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(vn,{stats:p}),e.jsx(fn,{agents:we,projectId:l,onAgentSelect:_,onOpenTaskLogs:y}),e.jsx(Wn,{isOpen:w,onClose:()=>{C(!1),j(null)},onCreated:()=>{C(!1),j(null),b()},projectId:l,prefillDraft:S}),e.jsx(Un,{isOpen:T,onClose:()=>M(!1),onUseDraft:n=>{j(n),M(!1),C(!0)},projectId:l,existingAgents:u}),e.jsx(Bn,{isOpen:A,onClose:()=>v(!1),onImported:()=>void b(),projectId:l}),Re?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):P==="tree"?e.jsx("div",{className:"agent-tree__view",children:de.length===0?e.jsx(Le,{onCtaClick:je}):z.rootNodes.map(n=>e.jsx(vt,{node:n,onSelect:_,onToggle:z.toggleExpand,isExpanded:z.isExpanded,getChildCount:t=>z.getChildren(t).length,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:se?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Oe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):Ne.length===0?e.jsx(Le,{onCtaClick:je}):Ne.map(n=>e.jsx(xt,{node:n,onSelect:_,getHealthStatus:fe,getRoleIcon:Se,getSkillBadges:Ae},n.agent.id))}):P==="board"?e.jsx("div",{className:"agent-board",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-board-card",n.state);return e.jsx("div",{className:`agent-board-card ${k}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:$=>$.key==="Enter"&&_(n.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:Se(n.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:pe(n.role)}),e.jsx("span",{className:`agent-board-badge badge ${d}`,children:n.state})]}),e.jsx("div",{className:"agent-board-name",children:n.name}),e.jsx("div",{className:"agent-board-id",children:n.id}),e.jsxs("div",{className:"agent-board-health",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]})]})},n.id)})}):e.jsx("div",{className:"agent-list",children:de.length===0?e.jsx(Le,{onCtaClick:je}):de.map(n=>{const t=fe(n),d=He(n.state),k=qe("agent-card",n.state),$=Je(n.runtimeConfig?.heartbeatIntervalMs),ee=Bt($),_e=ke===n.id;return e.jsxs("div",{className:`agent-card ${k}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>_(n.id),role:"button",tabIndex:0,onKeyDown:N=>N.key==="Enter"&&_(n.id),children:[ve===n.id?e.jsx("select",{ref:ne,className:"select agent-role-select",value:n.role,onChange:N=>void Ie(n.id,N.target.value),onKeyDown:N=>i(N,n.id),onBlur:()=>W(null),autoFocus:!0,children:ze.map(N=>e.jsxs("option",{value:N.value,children:[N.icon," ",N.label]},N.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:N=>{N.stopPropagation(),W(n.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:N=>{(N.key==="Enter"||N.key===" ")&&(N.stopPropagation(),W(n.id))},children:Se(n.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:n.name}),e.jsx("span",{className:"agent-id text-secondary",children:n.id})]}),e.jsx(ht,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${d}`,children:n.state}),e.jsxs("span",{className:"badge",style:{color:t.color},title:t.label,children:[t.icon,!t.stateDerived&&` ${t.label}`]}),e.jsx("span",{className:"badge text-secondary",children:pe(n.role)}),(()=>{const N=Ae(n);if(N.length===0)return null;const te=N.slice(0,2),Ce=N.length-2;return e.jsxs(e.Fragment,{children:[te.map(tt=>e.jsx("span",{className:"badge badge-skill",children:tt},tt)),Ce>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",Ce]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[n.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:n.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),oe===n.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:ce[n.id]??"",onChange:N=>ae(te=>({...te,[n.id]:N.target.value})),onKeyDown:N=>{N.key==="Enter"?R(n):N.key==="Escape"&&(U(null),ae(te=>{const Ce={...te};return delete Ce[n.id],Ce}))},disabled:_e,"aria-label":`Custom heartbeat interval in minutes for ${n.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void R(n),disabled:_e,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{U(null),ae(N=>{const te={...N};return delete te[n.id],te})},disabled:_e,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:$,onChange:N=>{const te=N.target.value;te==="__custom__"?Y(n):x(n,Number(te))},disabled:_e,"aria-label":`Set heartbeat interval for ${n.name}`,children:[ee.map(N=>e.jsx("option",{value:N.value,children:N.label},N.value)),Gt.some(N=>N.value===$)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),_e&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),n.lastHeartbeatAt&&(()=>{const N=new Date(n.lastHeartbeatAt),te=new Date(N.getTime()+$),Ce=n.state==="active"||n.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:N.toLocaleString(),children:["Last: ",N.toLocaleTimeString()]}),Ce&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:te.toLocaleString(),children:["Next: ",te.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[n.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Activate",children:[e.jsx($e,{size:14})," Start"]}),n.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void Pe(n.id,n.name),disabled:H.has(n.id),title:"Run Now","aria-label":`Run now for ${n.name}`,children:[e.jsx(Te,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Resume",children:[e.jsx($e,{size:14})," Resume"]}),n.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${n.name}`,children:[e.jsx(Te,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"paused"),disabled:H.has(n.id),title:"Pause",children:[e.jsx(it,{size:14})," Pause"]})]}),n.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Retry",children:[e.jsx($e,{size:14})," Retry"]}),n.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void le(n.id,"active"),disabled:H.has(n.id),title:"Start",children:[e.jsx($e,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>_(n.id),title:`View details for ${n.name}`,"aria-label":`View details for ${n.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void Me(n.id,n.name),title:"Delete",children:[e.jsx(Qt,{size:14})," Delete"]})]})]},n.id)})})]}),E&&e.jsx(a.Suspense,{fallback:null,children:e.jsx(Gn,{agentId:E,projectId:l,onClose:B,addToast:s,onChildClick:G})})]})}export{ta as AgentsView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as t}from"./vendor-react-K0fH_qHe.js";import{i as He,aL as Pt,g as Et,aM as Ft,a as Lt,aN as _t,aO as It,aP as Ot,aQ as Ut,aR as zt,aS as Ht,s as Vt,aT as Bt,aU as qt,aV as Gt,aW as Wt,ab as rt,ac as lt,S as Kt,V as Ze,J as et,ao as Jt,aX as Yt,B as Pe,a8 as ot,a9 as ct,aY as Qt,aZ as Xt,a_ as Zt,a$ as es,b0 as ts,b1 as ss,b2 as ns,b3 as tt,h as as,u as st,k as is}from"./index-Bc8nfKeH.js";import"./vendor-xterm-DzcZoU0P.js";const ze="kb-chat-active-session";function rs(a){const i=a?.toolCalls;if(!Array.isArray(i))return;const r=i.map(l=>{if(!l||typeof l!="object")return null;const c=l,N=typeof c.toolName=="string"?c.toolName:"";if(!N)return null;const j=c.args;return{toolName:N,...j&&typeof j=="object"?{args:j}:{},isError:!!c.isError,result:c.result,status:"completed"}}).filter(l=>l!==null);return r.length>0?r:void 0}function nt(a){return{id:a.id,sessionId:a.sessionId,role:a.role,content:a.content,thinkingOutput:a.thinkingOutput,toolCalls:rs(a.metadata),attachments:a.attachments,createdAt:a.createdAt}}function ls(a){const[i,r]=s.useState([]),[l,c]=s.useState(null),[N,j]=s.useState(!0),[R,k]=s.useState([]),[P,I]=s.useState(!1),[x,F]=s.useState(!1),[T,$]=s.useState(""),[g,v]=s.useState(""),[C,y]=s.useState([]),[B,E]=s.useState(""),[X,W]=s.useState(""),[L,Y]=s.useState(!0),[h,M]=s.useState(new Map),w=s.useRef(null),_=s.useRef(!1),z=s.useRef(""),te=s.useRef(null),he=s.useRef(i),xe=s.useRef(l),ve=s.useRef(x);he.current=i,xe.current=l,ve.current=x,s.useEffect(()=>{z.current=B},[B]);const we=s.useRef(new Set),me=s.useRef(0),ke=s.useRef(a);ke.current!==a&&(ke.current=a,me.current++),s.useEffect(()=>{const d=me.current;He(void 0,a).then(f=>{if(me.current!==d)return;const p=new Map;for(const S of f)p.set(S.id,S);M(p)}).catch(()=>{})},[a]);const K=s.useCallback(async()=>{j(!0);try{const f=[...(await Pt(a)).sessions].sort((p,S)=>new Date(S.updatedAt).getTime()-new Date(p.updatedAt).getTime());r(f)}catch{}finally{j(!1)}},[a]);s.useEffect(()=>{K()},[K]);const se=s.useRef(()=>{});s.useEffect(()=>{if(N)return;const d=Et(ze,a);d&&i.find(p=>p.id===d)&&se.current(d)},[N,i,a]);const oe=s.useCallback(async(d,f)=>{I(!0);try{const p=await Ft(d,{limit:50,...f},a),S=p.messages.map(nt);f?.offset&&f.offset>0?k(q=>[...S,...q]):k(S),Y(p.messages.length>=50)}catch{}finally{I(!1)}},[a]),ne=s.useCallback(()=>{te.current?.(),te.current=null,z.current="",E(""),$(""),v(""),y([]),F(!1)},[]),ae=s.useCallback((d,f)=>{w.current&&(w.current.close(),w.current=null);const p=f??i.find(S=>S.id===d);c(p||null),ne(),Y(!0),d?oe(d):k([]),d?Lt(ze,d,a):_t(ze,a)},[i,oe,a,ne]);se.current=ae;const fe=s.useCallback(async d=>{const f=await It(d,a);w.current&&(w.current.close(),w.current=null);const p={id:f.session.id,title:f.session.title,agentId:f.session.agentId,status:f.session.status,modelProvider:f.session.modelProvider,modelId:f.session.modelId,createdAt:f.session.createdAt,updatedAt:f.session.updatedAt};return r(S=>S.some(q=>q.id===p.id)?S:[p,...S]),ne(),ae(p.id,p),k([]),p},[a,ne,ae]),Se=s.useCallback(async d=>{await Ot(d,{status:"archived"},a),r(f=>f.filter(p=>p.id!==d)),l?.id===d&&(c(null),k([]))},[l,a]),ce=s.useCallback(async d=>{l?.id===d&&w.current&&(w.current.close(),w.current=null),await Ut(d,a),r(f=>f.filter(p=>p.id!==d)),l?.id===d&&(c(null),k([]))},[l,a]),Z=s.useCallback(async()=>{!l||!L||await oe(l.id,{offset:R.length})},[l,L,oe,R.length]),de=s.useCallback(()=>{l&&(_.current=!0,te.current?.(),te.current=null,w.current?.close(),w.current=null,zt(l.id,a).catch(()=>{}),F(!1),$(""),v(""),y([]))},[l,a]),ye=s.useCallback(()=>{z.current="",E("")},[]),ue=s.useCallback((d,f)=>{if(!l)return;if(x){z.current=d,E(d);return}_.current=!1,w.current&&(w.current.close(),w.current=null);const p=`temp-${Date.now()}`,S={id:p,sessionId:l.id,role:"user",content:d,createdAt:new Date().toISOString()};k(m=>[...m,S]),$(""),v(""),y([]),F(!0);let q="",ge="",O=[],H=null,ie=null;const G=()=>{H=null,$(q)},u=()=>{ie=null,v(ge)},A=()=>{H!==null&&(cancelAnimationFrame(H),H=null),ie!==null&&(cancelAnimationFrame(ie),ie=null)};te.current=A;const V={onThinking:m=>{ge+=m,ie===null&&(ie=requestAnimationFrame(u))},onText:m=>{q+=m,H===null&&(H=requestAnimationFrame(G))},onToolStart:m=>{O=[...O,{toolName:m.toolName,args:m.args,isError:!1,status:"running"}],y(O)},onToolEnd:m=>{const D=[...O];for(let b=D.length-1;b>=0;b--){const ee=D[b];if(ee?.toolName===m.toolName&&ee.status==="running"){D[b]={...ee,status:"completed",isError:m.isError,result:m.result},O=D,y(D);return}}O=[...D,{toolName:m.toolName,isError:m.isError,result:m.result,status:"completed"}],y(O)},onDone:m=>{A();const D={id:m.messageId||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:q,thinkingOutput:ge,toolCalls:O.length>0?O:void 0,createdAt:new Date().toISOString()};we.current.add(D.id),k(ee=>[...ee,D]),$(""),v(""),y([]),F(!1),w.current=null,setTimeout(()=>{we.current.delete(D.id)},1e3),K();const b=z.current.trim();b&&(z.current="",E(""),ue(b))},onError:m=>{if(A(),k(D=>D.filter(b=>b.id!==p)),$(""),v(""),y([]),F(!1),w.current=null,console.error("[useChat] Stream error:",m),!_.current){const D=z.current.trim();D&&(z.current="",E(""),ue(D))}}};w.current=Ht(l.id,d,V,f,a)},[l,x,a,K]),Ne=X?i.filter(d=>d.title?.toLowerCase().includes(X.toLowerCase())||d.agentId.toLowerCase().includes(X.toLowerCase())):i;return s.useEffect(()=>{const d=me.current,f=a?`?projectId=${encodeURIComponent(a)}`:"",p=()=>me.current!==d,S=G=>{if(p())return;const u=JSON.parse(G.data);r(A=>A.some(V=>V.id===u.id)?A:[u,...A])},q=G=>{if(p())return;const u=JSON.parse(G.data);r(A=>[...A.map(m=>m.id===u.id?u:m)]),xe.current?.id===u.id&&c(u)},ge=G=>{if(p())return;const{id:u}=JSON.parse(G.data);r(A=>A.filter(V=>V.id!==u)),xe.current?.id===u&&(c(null),k([]))},O=G=>{if(p())return;const u=JSON.parse(G.data),A=nt(u);we.current.has(A.id)||xe.current?.id===A.sessionId&&!ve.current&&k(V=>V.some(m=>m.id===A.id)?V:[...V,A])},H=G=>{if(p())return;const{id:u}=JSON.parse(G.data);k(A=>A.filter(V=>V.id!==u))};return Vt(`/api/events${f}`,{events:{"chat:session:created":S,"chat:session:updated":q,"chat:session:deleted":ge,"chat:message:added":O,"chat:message:deleted":H}})},[a]),s.useEffect(()=>()=>{w.current&&(w.current.close(),w.current=null)},[]),{sessions:i,activeSession:l,sessionsLoading:N,messages:R,messagesLoading:P,isStreaming:x,streamingText:T,streamingThinking:g,streamingToolCalls:C,pendingMessage:B,selectSession:ae,createSession:fe,archiveSession:Se,deleteSession:ce,sendMessage:ue,stopStreaming:de,clearPendingMessage:ye,loadMoreMessages:Z,hasMoreMessages:L,searchQuery:X,setSearchQuery:W,filteredSessions:Ne,refreshSessions:K,agentsMap:h}}function dt(a){const i=new Date(a),l=new Date().getTime()-i.getTime(),c=Math.floor(l/1e3),N=Math.floor(c/60),j=Math.floor(N/60),R=Math.floor(j/24);return c<60?"just now":N<60?`${N}m ago`:j<24?`${j}h ago`:R<7?`${R}d ago`:i.toLocaleDateString()}function at(a,i){if(!a||!i)return null;const r=i.toLowerCase();if(r.includes("claude")){let c=i.replace(/^claude[- ]/i,"Claude ").replace(/sonnet[- ](\d+)[- ](\d+)/i,"Sonnet $1.$2").replace(/sonnet[- ](\d+)/i,"Sonnet $1").replace(/haiku[- ](\d+)/i,"Haiku $1").replace(/opus[- ](\d+)/i,"Opus $1").replace(/sonnet/i,"Sonnet").replace(/haiku/i,"Haiku").replace(/opus/i,"Opus").replace(/-/g," ").trim();return c=c.replace(/\s+/g," "),c.length>30?c.slice(0,30)+"…":c}if(r.includes("gpt")||r.includes("openai")){const c=i.replace(/^gpt-4-turbo$/i,"GPT-4 Turbo").replace(/^gpt-4o-mini$/i,"GPT-4o Mini").replace(/^gpt-4o$/i,"GPT-4o").replace(/^gpt-4$/i,"GPT-4").replace(/^gpt-o1-preview$/i,"GPT-o1 Preview").replace(/^gpt-o1-mini$/i,"GPT-o1 Mini").replace(/^gpt-o1$/i,"GPT-o1").replace(/^gpt/i,"GPT").trim();return c.length>30?c.slice(0,30)+"…":c}if(r.includes("gemini")){const c=i.replace(/^gemini[- ]/i,"Gemini ").replace(/pro[- ](\d+)[- ](\d+)/i,"Pro $1.$2").replace(/pro[- ](\d+)/i,"Pro $1").replace(/-/g," ").replace(/\s+/g," ").trim();return c.length>30?c.slice(0,30)+"…":c}const l=i.replace(/-/g," ").replace(/^\w/,c=>c.toUpperCase()).replace(/\s+/g," ").trim();return l.length>30?l.slice(0,30)+"…":l}function Re(a,i){return a.length<=i?a:`${a.slice(0,i)}…`}function os(a){if(!a)return null;const i=Object.entries(a);return i.length===0?null:i.map(([r,l])=>{const c=typeof l=="string"?l:(()=>{try{return JSON.stringify(l)}catch{return String(l)}})();return`${r}=${Re(c,50)}`}).join(", ")}function cs(a){if(a===void 0)return null;if(typeof a=="string")return Re(a,200);try{return Re(JSON.stringify(a),200)}catch{return Re(String(a),200)}}function ut(a){if(!a||a.length===0)return null;const i=(x,F)=>{const T=x.status==="running",$=x.status==="completed"&&x.isError,g=os(x.args),v=cs(x.result),C=T?g:v?`result: ${v}`:g?`args: ${g}`:null,y=T?"running":$?"error":"completed";return t.jsxs("details",{className:`chat-tool-call${T?" chat-tool-call--running":""}${$?" chat-tool-call--error":""}`,open:T,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"chat-tool-call-status-dot","aria-hidden":"true"}),t.jsx("span",{className:"chat-tool-call-name",children:x.toolName}),C&&t.jsx("span",{className:"chat-tool-call-preview",title:C,children:C}),t.jsx("span",{className:"chat-tool-call-status-text",children:y})]}),t.jsxs("div",{className:"chat-tool-call-content",children:[g&&t.jsxs("div",{className:"chat-tool-call-row",children:[t.jsx("span",{className:"chat-tool-call-label",children:"args"}),t.jsx("span",{className:"chat-tool-call-value",children:g})]}),v&&t.jsxs("div",{className:`chat-tool-call-row${$?" chat-tool-call-row--error":""}`,children:[t.jsx("span",{className:"chat-tool-call-label",children:"result"}),t.jsx("span",{className:"chat-tool-call-value",children:v})]})]})]},`${x.toolName}-${F}`)},r="chat-tool-calls";if(a.length===1)return t.jsxs("div",{className:r,"data-testid":"chat-tool-calls",children:[t.jsxs("div",{className:"chat-tool-calls-header",children:[t.jsx(tt,{size:12,"aria-hidden":"true"}),t.jsx("span",{children:"Tool calls"})]}),i(a[0],0)]});const l=a.filter(x=>x.status==="running").length,c=a.filter(x=>x.status==="completed"&&x.isError).length,N=l>0,j=Array.from(new Set(a.map(x=>x.toolName))),R=j.slice(0,5),k=Math.max(0,j.length-R.length),P=k>0?`${R.join(", ")}, +${k} more`:R.join(", "),I=N?`(${l} running)`:c>0?`(${c} ${c===1?"error":"errors"})`:null;return t.jsx("div",{className:r,"data-testid":"chat-tool-calls",children:t.jsxs("details",{className:"chat-tool-calls-group","data-testid":"chat-tool-calls-group",open:N,children:[t.jsxs("summary",{className:"chat-tool-calls-group-summary",children:[t.jsx(tt,{size:12,"aria-hidden":"true"}),t.jsxs("span",{children:[a.length," tool calls"]}),t.jsx("span",{className:"chat-tool-calls-names",title:P,children:P}),I&&t.jsx("span",{className:"chat-tool-calls-group-status",children:I})]}),a.map((x,F)=>i(x,F))]})})}const ht={pre:({children:a,...i})=>t.jsx("pre",{...i,className:"chat-markdown-pre",children:a}),table:({children:a,...i})=>t.jsx("table",{...i,className:"chat-markdown-table",children:a})},De="__fn_agent__",ds=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function it(a){const i=/(^|[\s])\/([^\s]*)$/.exec(a);if(!i)return null;const r=i[1]??"",l=i[2]??"",c=i.index+r.length;return{filter:l,start:c,end:a.length}}function us(a,i){const r=a.slice(0,i),l=/(^|[\s\n])@([\w-]*)$/.exec(r);if(!l)return null;const c=l[2]??"",N=r.length-c.length-1;return{filter:c,start:N,end:i}}function hs({projectId:a,onClose:i,onCreate:r}){const[l,c]=s.useState("agent"),[N,j]=s.useState([]),[R,k]=s.useState(!0),[P,I]=s.useState(""),[x,F]=s.useState([]),[T,$]=s.useState(!0),[g,v]=s.useState(""),[C,y]=s.useState([]),[B,E]=s.useState([]);s.useEffect(()=>{let h=!1;return k(!0),He(void 0,a).then(M=>{h||j(M)}).catch(()=>{h||j([])}).finally(()=>{h||k(!1)}),()=>{h=!0}},[a]),s.useEffect(()=>{$(!0),as().then(h=>{F(h.models),y(h.favoriteProviders),E(h.favoriteModels)}).catch(()=>{F([]),y([]),E([])}).finally(()=>{$(!1)})},[]);const X=s.useCallback(async h=>{const M=C,_=M.includes(h)?M.filter(z=>z!==h):[h,...M];y(_);try{await st({favoriteProviders:_,favoriteModels:B})}catch{y(M)}},[C,B]),W=s.useCallback(async h=>{const M=B,_=M.includes(h)?M.filter(z=>z!==h):[h,...M];E(_);try{await st({favoriteProviders:C,favoriteModels:_})}catch{E(M)}},[B,C]),L=h=>{if(h.preventDefault(),l==="agent"){if(!P)return;r({agentId:P});return}if(!g)return;const M=g.indexOf("/");if(M<=0)return;const w=g.slice(0,M),_=g.slice(M+1);r({agentId:De,modelProvider:w,modelId:_})},Y=l==="agent"?!P:!g;return t.jsx("div",{className:"chat-new-dialog-backdrop",onClick:i,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog",onClick:h=>h.stopPropagation(),children:[t.jsx("h3",{children:"New Chat"}),t.jsxs("div",{className:"chat-new-dialog-mode-toggle","data-testid":"chat-new-dialog-mode-toggle",children:[t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{c("agent"),v("")},children:"Agent"}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{c("model"),I("")},children:"Model"})]}),t.jsxs("form",{onSubmit:L,children:[l==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",R?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):N.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:N.map(h=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${P===h.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>I(h.id),"data-testid":`agent-option-${h.id}`,children:[t.jsx(Pe,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:h.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:h.role})]},h.id))})]}),l==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:T?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):t.jsx(is,{models:x,value:g,onChange:v,label:"Model",placeholder:"Select a model",favoriteProviders:C,onToggleFavorite:X,favoriteModels:B,onToggleModelFavorite:W})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:i,children:"Cancel"}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:Y,children:"Create"})]})]})]})})}const ms=s.memo(function({message:i,forcePlain:r,agentName:l,showAssistantModelTag:c,activeModelTag:N,activeSessionId:j,mentionAgentsByName:R,onToggleRender:k}){const P=i.role==="assistant",I=s.useMemo(()=>{if(P)return null;const T=i.content,$=/@([\w-]+)/g,g=[];let v=0,C=$.exec(T);for(;C;){const[y,B=""]=C,E=C.index;E>v&&g.push(T.slice(v,E));const X=B.replace(/_/g," ").toLowerCase(),W=R.get(X);W?g.push(t.jsxs("span",{className:"chat-mention-chip",children:["@",W.name.replace(/\s+/g,"_")]},`${W.id}-${E}`)):g.push(y),v=E+y.length,C=$.exec(T)}return v<T.length&&g.push(T.slice(v)),g.length===0?T:g},[P,i.content,R]),x=s.useMemo(()=>{const T=i.attachments;if(!T||T.length===0||!j)return null;const $=`/api/chat/sessions/${encodeURIComponent(j)}/attachments/`;return t.jsx("div",{className:"chat-message-attachments",children:T.map(g=>{const v=g.mimeType.startsWith("image/"),C=g.id||g.filename,y=`${$}${encodeURIComponent(g.filename)}`;return v?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:y,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:y,alt:g.originalName})},C):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:y,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(ns,{size:14}),t.jsx("span",{children:g.originalName})]},C)})})},[i.attachments,j]),F=s.useMemo(()=>P?r?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:i.content}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(rt,{remarkPlugins:[lt],components:ht,children:i.content})}):null,[P,r,i.content]);return t.jsxs("div",{className:`chat-message chat-message--${i.role}`,"data-testid":`chat-message-${i.id}`,children:[P&&t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(Pe,{size:14}),t.jsx("span",{children:l}),c&&N&&t.jsx("span",{className:"chat-model-tag",children:N}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${r?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":r?"Show rendered markdown":"Show plain text",onClick:()=>k(i.id),children:r?t.jsx(ot,{size:14}):t.jsx(ct,{size:14})})]}),P?F:t.jsx("div",{className:"chat-message-content",children:I}),ut(i.toolCalls),i.thinkingOutput&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:i.thinkingOutput})]}),x,t.jsx("div",{className:"chat-message-time",children:dt(i.createdAt)})]})});function ws({projectId:a,addToast:i}){const{activeSession:r,sessionsLoading:l,messages:c,messagesLoading:N,isStreaming:j,streamingText:R,streamingThinking:k,streamingToolCalls:P,selectSession:I,createSession:x,archiveSession:F,deleteSession:T,sendMessage:$,stopStreaming:g,pendingMessage:v,clearPendingMessage:C,searchQuery:y,setSearchQuery:B,filteredSessions:E}=ls(a),[X,W]=s.useState(!1),[L,Y]=s.useState(""),[h,M]=s.useState(null),[w,_]=s.useState(null),[z,te]=s.useState(!0),[he,xe]=s.useState(new Map),[ve,we]=s.useState([]),[me,ke]=s.useState(!0),[K,se]=s.useState(!1),[oe,ne]=s.useState(""),[ae,fe]=s.useState(0),[Se,ce]=s.useState(""),[Z,de]=s.useState(!1),[ye,ue]=s.useState(0),[Ne,d]=s.useState(-1),[f,p]=s.useState(()=>new Set),[S,q]=s.useState([]),[ge,O]=s.useState(!1),[,H]=s.useState(!1),[ie,G]=s.useState({top:0,left:0}),u=Bt({projectId:a}),A=s.useCallback(e=>{if(!e||!u.mentionActive)return;const n=e.getBoundingClientRect();G({top:n.top-260,left:n.left+8})},[u.mentionActive]),V=s.useRef(null),m=s.useRef(null),D=s.useRef(null),b=s.useRef(null),ee=s.useRef(!1),Me=s.useRef(!1),Ve=s.useRef(null),Be=s.useRef([]),je=s.useRef(0),re=qt()==="mobile",{keyboardOverlap:Ee,viewportHeight:qe,viewportOffsetTop:mt,keyboardOpen:Fe}=Gt({enabled:re&&!!r}),ft=Fe?{"--keyboard-overlap":`${Ee}px`,"--vv-offset-top":`${mt}px`,...qe!==null?{"--vv-height":`${qe}px`}:{}}:{},Q=s.useMemo(()=>{const e=oe.trim().toLowerCase();return(e?ve.filter(o=>o.name.toLowerCase().includes(e)):ve).slice(0,10)},[ve,oe]),be=s.useMemo(()=>Array.from(he.values()),[he]),pe=s.useMemo(()=>{const e=Se.trim().toLowerCase();return e?be.filter(n=>n.name.toLowerCase().includes(e)):be},[be,Se]),gt=s.useMemo(()=>{const e=new Map;for(const n of be)e.set(n.name.toLowerCase(),n);return e},[be]);s.useEffect(()=>{fe(0)},[Q]),s.useEffect(()=>{ue(0)},[Se,Z]),s.useEffect(()=>()=>{m.current!==null&&window.clearTimeout(m.current)},[]),s.useEffect(()=>{const e=D.current;e&&(e.scrollTop=e.scrollHeight)},[c,R]),s.useEffect(()=>{if(Ee<=0)return;const e=D.current;e&&(e.scrollTop=e.scrollHeight)},[Ee]),s.useEffect(()=>{if(!re||!Fe)return;const e=document.documentElement,n=document.body,o={htmlOverflow:e.style.overflow,bodyOverflow:n.style.overflow};return e.style.overflow="hidden",n.style.overflow="hidden",()=>{e.style.overflow=o.htmlOverflow,n.style.overflow=o.bodyOverflow}},[re,Fe]),s.useEffect(()=>{const e=()=>M(null);if(h)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[h]),s.useEffect(()=>{let e=!1;const n=a;return He(void 0,a).then(o=>{if(e||n!==a)return;const U=new Map;for(const J of o)U.set(J.id,J);xe(U)}).catch(()=>{}),()=>{e=!0}},[a]),s.useEffect(()=>{let e=!1;return ke(!0),Wt(a).then(n=>{e||we(n)}).catch(()=>{e||we([])}).finally(()=>{e||ke(!1)}),()=>{e=!0}},[a]),s.useEffect(()=>{Be.current=S},[S]),s.useEffect(()=>()=>{for(const e of Be.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl)},[]);const Te=s.useCallback(e=>{if(!e||e.length===0)return;const n=[];for(const o of Array.from(e)){if(!ds.includes(o.type))continue;const U=o.type.startsWith("image/");n.push({file:o,previewUrl:U?URL.createObjectURL(o):""})}n.length>0&&q(o=>[...o,...n])},[]),pt=s.useCallback(e=>{q(n=>{const o=n[e];return o?.previewUrl&&URL.revokeObjectURL(o.previewUrl),n.filter((U,J)=>J!==e)})},[]),xt=s.useCallback(e=>{const n=e.clipboardData?.files;if(!n||n.length===0)return;const o=Array.from(n).filter(U=>U.type.startsWith("image/"));o.length!==0&&Te(o)},[Te]),vt=s.useCallback(async e=>{try{await x(e),W(!1),re&&te(!1)}catch{i("Failed to create chat session","error")}},[x,i,re]),Le=s.useCallback(()=>{Y(""),se(!1),ne(""),de(!1),ce(""),d(-1),q(e=>{for(const n of e)n.previewUrl&&URL.revokeObjectURL(n.previewUrl);return[]})},[]),Ce=s.useCallback(()=>{const e=L.trim(),n=S.map(o=>o.file);if(!(!e&&n.length===0||!r)){if(e==="/clear"){Le(),g(),C(),x({agentId:r.agentId,modelProvider:r.modelProvider??void 0,modelId:r.modelId??void 0}).catch(()=>{i("Failed to clear conversation","error")});return}Le(),$(e,n)}},[L,S,r,Le,g,C,x,i,$]),Ae=s.useCallback(()=>{if(typeof window>"u"||window.innerWidth>768)return;const e=b.current;if(!e||e.disabled)return;const n=window.scrollX,o=window.scrollY;e.focus({preventScroll:!0}),window.requestAnimationFrame(()=>{(window.scrollX!==n||window.scrollY!==o)&&window.scrollTo(n,o)})},[]),Ge=s.useCallback(()=>{typeof window>"u"||window.innerWidth>768||(ee.current=!0)},[]),_e=s.useCallback(e=>{Y(n=>{const o=it(n);if(!o)return n;const U=`/skill:${e.name} `,J=n.slice(0,o.start)+U+n.slice(o.end);return window.requestAnimationFrame(()=>{b.current&&(b.current.style.height="auto",b.current.style.height=`${Math.min(b.current.scrollHeight,120)}px`,b.current.focus())}),J}),se(!1),ne(""),fe(0)},[]),Ie=s.useCallback(e=>{const n=b.current;if(!n||Ne<0)return;const o=n.selectionStart??je.current,U=n.selectionEnd??o,J=Math.max(o,U),Ye=Math.min(Ne,J),Qe=`${`@${e.name.replace(/\s+/g,"_")}`} `,Dt=L.slice(0,Ye)+Qe+L.slice(J),Xe=Ye+Qe.length;Y(Dt),de(!1),ce(""),ue(0),d(-1),window.requestAnimationFrame(()=>{b.current&&(b.current.style.height="auto",b.current.style.height=`${Math.min(b.current.scrollHeight,120)}px`,b.current.focus(),b.current.setSelectionRange(Xe,Xe))})},[Ne,L]),wt=s.useCallback(e=>{if(je.current=e.currentTarget.selectionStart??je.current,u.mentionActive&&u.files.length>0){if(u.handleKeyDown(e,L),e.key==="Enter"||e.key==="Tab"){const n=u.files[u.selectedIndex];if(n){const o=u.selectFile(n,L);Y(o),u.dismissMention(),H(!1)}}return}if(Z&&e.key==="ArrowDown"){e.preventDefault(),pe.length>0&&ue(n=>(n+1)%pe.length);return}if(Z&&e.key==="ArrowUp"){e.preventDefault(),pe.length>0&&ue(n=>n===0?pe.length-1:n-1);return}if(Z&&e.key==="Enter"){e.preventDefault();const n=pe[ye]??pe[0];n&&Ie(n);return}if(Z&&e.key==="Escape"){e.preventDefault(),de(!1),ce(""),d(-1);return}if(K&&e.key==="ArrowDown"){e.preventDefault(),Q.length>0&&fe(n=>(n+1)%Q.length);return}if(K&&e.key==="ArrowUp"){e.preventDefault(),Q.length>0&&fe(n=>n===0?Q.length-1:n-1);return}if(K&&(e.key==="Enter"||e.key==="Tab")&&Q.length>0){e.preventDefault();const n=Q[ae]??Q[0];n&&_e(n);return}if(K&&e.key==="Escape"){e.preventDefault(),se(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Ce())},[Z,pe,ye,Ie,K,Q,ae,_e,Ce,u,L]),$e=s.useCallback((e,n)=>{const o=us(e,n);if(o){de(!0),ce(o.filter),d(o.start);return}de(!1),ce(""),d(-1)},[]),St=s.useCallback(e=>{const n=e.target,o=n.value,U=n.selectionStart??o.length;je.current=U,Y(o);const J=it(o);J?(se(!0),ne(J.filter)):(se(!1),ne("")),$e(o,U),u.detectMention(o,U),H(u.mentionActive),u.mentionActive&&A(n),n.style.height="auto",n.style.height=`${Math.min(n.scrollHeight,120)}px`},[$e]),Oe=s.useCallback(e=>{const n=e.currentTarget,o=n.selectionStart??n.value.length;je.current=o,$e(n.value,o),u.detectMention(n.value,o),H(u.mentionActive),u.mentionActive&&A(n)},[$e,u,A]),bt=s.useCallback(e=>{e.key!=="Escape"&&Oe(e)},[Oe]),kt=s.useCallback(()=>{if(ee.current){window.requestAnimationFrame(()=>{Ae()});return}m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{se(!1),de(!1),ce(""),d(-1),H(!1),u.dismissMention(),m.current=null},120)},[u,Ae]),yt=s.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),Nt=s.useCallback(async e=>{M(null);try{await F(e),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[F,i]),jt=s.useCallback(async e=>{_(null),M(null);try{await T(e),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[T,i]),Ct=s.useCallback(e=>{I(e),re&&te(!1)},[I,re]),Mt=s.useCallback(()=>{I(""),te(!0)},[I]),Tt=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(ss,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>W(!0),children:[t.jsx(et,{size:16}),"New Chat"]})]}),le=at(r?.modelProvider,r?.modelId),We=r?.agentId===De?le??"Fusion":r?.title||he.get(r?.agentId??"")?.name||r?.agentId||"Chat",At=!!(le&&le!==We),Ue=he.get(r?.agentId??"")?.name||(r?.agentId===De?le??"Fusion":r?.agentId?.slice(0,30)??"Fusion"),Ke=!!(le&&le!==Ue),$t=v.length>50?`${v.slice(0,50)}…`:v,Je=s.useCallback(e=>{p(n=>{const o=new Set(n);return o.has(e)?o.delete(e):o.add(e),o})},[]),Rt=s.useCallback((e,n=!1)=>n?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:e}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(rt,{remarkPlugins:[lt],components:ht,children:e})}),[]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${z?"":" chat-sidebar--hidden"}`,children:[t.jsx("div",{className:"chat-sidebar-search",children:t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(Kt,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:y,onChange:e=>B(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:l?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):E.length===0?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):E.map(e=>t.jsxs("div",{className:`chat-session-item${r?.id===e.id?" chat-session-item--active":""}`,onClick:()=>Ct(e.id),onContextMenu:n=>{n.preventDefault(),M({sessionId:e.id,x:n.clientX,y:n.clientY})},"data-testid":`chat-session-${e.id}`,children:[t.jsx("button",{className:"chat-session-delete-btn",onClick:n=>{n.stopPropagation(),_(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(Ze,{size:14})}),t.jsx("div",{className:"chat-session-title",children:e.title||"Untitled"}),t.jsx("div",{className:"chat-session-preview",children:e.lastMessagePreview||"No messages"}),t.jsxs("div",{className:"chat-session-meta",children:[t.jsx("span",{children:he.get(e.agentId)?.name||(e.agentId===De?at(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))}),t.jsx("span",{children:e.updatedAt?dt(e.updatedAt):""})]})]},e.id))}),t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>W(!0),"data-testid":"chat-new-btn",children:[t.jsx(et,{size:14}),"New Chat"]})})]}),h&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:h.y,left:h.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>Nt(h.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Jt,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{M(null),_(h.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(Ze,{size:14}),"Delete"]})]}),w&&t.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>_(null),children:t.jsxs("div",{className:"chat-new-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Conversation?"}),t.jsx("p",{style:{fontSize:"14px",color:"var(--text-secondary)",marginBottom:"16px"},children:"This action cannot be undone. All messages in this conversation will be permanently deleted."}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>_(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void jt(w),children:"Delete"})]})]})}),t.jsxs("div",{className:"chat-thread",style:ft,children:[(r||!re)&&t.jsxs("div",{className:"chat-thread-header",children:[re&&r&&t.jsx("button",{className:"btn-icon",onClick:Mt,"data-testid":"chat-back-btn",children:t.jsx(Yt,{size:16})}),t.jsx(Pe,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:We}),At&&t.jsx("span",{className:"chat-model-tag",children:le})]}),t.jsxs("div",{className:"chat-messages",ref:D,children:[N?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):c.length===0&&!r?Tt():c.length===0&&r?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):t.jsxs(t.Fragment,{children:[c.map(e=>t.jsx(ms,{message:e,forcePlain:f.has(e.id),agentName:Ue,showAssistantModelTag:Ke,activeModelTag:le,activeSessionId:r?.id??null,mentionAgentsByName:gt,onToggleRender:Je},e.id)),j&&t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(Pe,{size:14}),t.jsx("span",{children:Ue}),Ke&&t.jsx("span",{className:"chat-model-tag",children:le}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${f.has("__streaming__")?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":f.has("__streaming__")?"Show rendered markdown":"Show plain text",onClick:()=>Je("__streaming__"),children:f.has("__streaming__")?t.jsx(ot,{size:14}):t.jsx(ct,{size:14})})]}),R?Rt(R,f.has("__streaming__")):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:k?"Thinking…":"Connecting…"}),ut(P),k&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:k})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}),t.jsx("div",{ref:V})]}),r&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Ve,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{Te(e.target.files),e.target.value=""}}),K&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:me?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):Q.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:oe?"No skills found":"No skills available"}):Q.map((e,n)=>t.jsxs("button",{type:"button",role:"option","aria-selected":n===ae,className:`chat-skill-menu-item${n===ae?" chat-skill-menu-item--highlighted":""}`,onMouseDown:o=>o.preventDefault(),onMouseEnter:()=>fe(n),onClick:()=>_e(e),children:[t.jsx("span",{className:"chat-skill-menu-item-name",children:e.name}),t.jsx("span",{className:"chat-skill-menu-item-description",title:e.relativePath,children:e.relativePath})]},e.id))}),S.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:S.map((e,n)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${n}`,children:[e.previewUrl?t.jsx("img",{src:e.previewUrl,alt:e.file.name}):t.jsx("span",{className:"chat-attachment-preview-name",children:e.file.name}),t.jsx("button",{type:"button",className:"chat-attachment-remove",onClick:()=>pt(n),"data-testid":`chat-attachment-remove-${n}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${n}`))}),t.jsxs("div",{className:"chat-input-row",children:[t.jsx("button",{type:"button",className:"btn-icon chat-attach-btn","data-testid":"chat-attach-btn","aria-label":"Attach files",onClick:()=>Ve.current?.click(),children:t.jsx(Qt,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${ge?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),O(!0)},onDragLeave:()=>O(!1),onDrop:e=>{e.preventDefault(),O(!1),Te(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:b,className:"chat-input-textarea",placeholder:"Type a message...",value:L,onChange:St,onKeyDown:wt,onKeyUp:bt,onClick:Oe,onBlur:kt,onFocus:yt,onPaste:xt,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||document.activeElement!==e.currentTarget&&(e.preventDefault(),e.currentTarget.focus({preventScroll:!0}))},rows:1,"data-testid":"chat-input"}),t.jsx(Xt,{agents:be,filter:Se,highlightedIndex:ye,visible:Z,onSelect:Ie,position:"below"}),t.jsx(Zt,{visible:u.mentionActive&&!Z,position:ie,files:u.files,selectedIndex:u.selectedIndex,onSelect:e=>{const n=u.selectFile(e,L);Y(n),u.dismissMention(),H(!1),b.current?.focus()},loading:u.loading}),v&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${$t}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:C,children:"×"})]})]}),j?t.jsx("button",{className:"chat-input-stop",onClick:g,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(es,{size:14})}):t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{typeof window>"u"||window.innerWidth>768||(e.preventDefault(),e.pointerType&&e.pointerType!=="mouse"&&(Me.current=!0,Ge(),Ae(),Ce(),window.setTimeout(()=>{ee.current=!1},1500)))},onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||(e.preventDefault(),Me.current=!0,Ge(),Ae(),Ce(),window.setTimeout(()=>{ee.current=!1},1500))},onMouseDown:e=>{typeof window>"u"||window.innerWidth>768||e.preventDefault()},onClick:()=>{if(Me.current){Me.current=!1;return}Ce()},disabled:!L.trim()&&S.length===0,"data-testid":"chat-send-btn",children:t.jsx(ts,{size:16})})]})]})]}),X&&t.jsx(hs,{projectId:a,onClose:()=>W(!1),onCreate:vt})]})}export{ws as ChatView};
|
|
1
|
+
import{r as s,j as t}from"./vendor-react-K0fH_qHe.js";import{i as He,aL as Pt,g as Et,aM as Ft,a as Lt,aN as _t,aO as It,aP as Ot,aQ as Ut,aR as zt,aS as Ht,s as Vt,aT as Bt,aU as qt,aV as Gt,aW as Wt,ab as rt,ac as lt,S as Kt,V as Ze,J as et,ao as Jt,aX as Yt,B as Pe,a8 as ot,a9 as ct,aY as Qt,aZ as Xt,a_ as Zt,a$ as es,b0 as ts,b1 as ss,b2 as ns,b3 as tt,h as as,u as st,k as is}from"./index-DH3aprf6.js";import"./vendor-xterm-DzcZoU0P.js";const ze="kb-chat-active-session";function rs(a){const i=a?.toolCalls;if(!Array.isArray(i))return;const r=i.map(l=>{if(!l||typeof l!="object")return null;const c=l,N=typeof c.toolName=="string"?c.toolName:"";if(!N)return null;const j=c.args;return{toolName:N,...j&&typeof j=="object"?{args:j}:{},isError:!!c.isError,result:c.result,status:"completed"}}).filter(l=>l!==null);return r.length>0?r:void 0}function nt(a){return{id:a.id,sessionId:a.sessionId,role:a.role,content:a.content,thinkingOutput:a.thinkingOutput,toolCalls:rs(a.metadata),attachments:a.attachments,createdAt:a.createdAt}}function ls(a){const[i,r]=s.useState([]),[l,c]=s.useState(null),[N,j]=s.useState(!0),[R,k]=s.useState([]),[P,I]=s.useState(!1),[x,F]=s.useState(!1),[T,$]=s.useState(""),[g,v]=s.useState(""),[C,y]=s.useState([]),[B,E]=s.useState(""),[X,W]=s.useState(""),[L,Y]=s.useState(!0),[h,M]=s.useState(new Map),w=s.useRef(null),_=s.useRef(!1),z=s.useRef(""),te=s.useRef(null),he=s.useRef(i),xe=s.useRef(l),ve=s.useRef(x);he.current=i,xe.current=l,ve.current=x,s.useEffect(()=>{z.current=B},[B]);const we=s.useRef(new Set),me=s.useRef(0),ke=s.useRef(a);ke.current!==a&&(ke.current=a,me.current++),s.useEffect(()=>{const d=me.current;He(void 0,a).then(f=>{if(me.current!==d)return;const p=new Map;for(const S of f)p.set(S.id,S);M(p)}).catch(()=>{})},[a]);const K=s.useCallback(async()=>{j(!0);try{const f=[...(await Pt(a)).sessions].sort((p,S)=>new Date(S.updatedAt).getTime()-new Date(p.updatedAt).getTime());r(f)}catch{}finally{j(!1)}},[a]);s.useEffect(()=>{K()},[K]);const se=s.useRef(()=>{});s.useEffect(()=>{if(N)return;const d=Et(ze,a);d&&i.find(p=>p.id===d)&&se.current(d)},[N,i,a]);const oe=s.useCallback(async(d,f)=>{I(!0);try{const p=await Ft(d,{limit:50,...f},a),S=p.messages.map(nt);f?.offset&&f.offset>0?k(q=>[...S,...q]):k(S),Y(p.messages.length>=50)}catch{}finally{I(!1)}},[a]),ne=s.useCallback(()=>{te.current?.(),te.current=null,z.current="",E(""),$(""),v(""),y([]),F(!1)},[]),ae=s.useCallback((d,f)=>{w.current&&(w.current.close(),w.current=null);const p=f??i.find(S=>S.id===d);c(p||null),ne(),Y(!0),d?oe(d):k([]),d?Lt(ze,d,a):_t(ze,a)},[i,oe,a,ne]);se.current=ae;const fe=s.useCallback(async d=>{const f=await It(d,a);w.current&&(w.current.close(),w.current=null);const p={id:f.session.id,title:f.session.title,agentId:f.session.agentId,status:f.session.status,modelProvider:f.session.modelProvider,modelId:f.session.modelId,createdAt:f.session.createdAt,updatedAt:f.session.updatedAt};return r(S=>S.some(q=>q.id===p.id)?S:[p,...S]),ne(),ae(p.id,p),k([]),p},[a,ne,ae]),Se=s.useCallback(async d=>{await Ot(d,{status:"archived"},a),r(f=>f.filter(p=>p.id!==d)),l?.id===d&&(c(null),k([]))},[l,a]),ce=s.useCallback(async d=>{l?.id===d&&w.current&&(w.current.close(),w.current=null),await Ut(d,a),r(f=>f.filter(p=>p.id!==d)),l?.id===d&&(c(null),k([]))},[l,a]),Z=s.useCallback(async()=>{!l||!L||await oe(l.id,{offset:R.length})},[l,L,oe,R.length]),de=s.useCallback(()=>{l&&(_.current=!0,te.current?.(),te.current=null,w.current?.close(),w.current=null,zt(l.id,a).catch(()=>{}),F(!1),$(""),v(""),y([]))},[l,a]),ye=s.useCallback(()=>{z.current="",E("")},[]),ue=s.useCallback((d,f)=>{if(!l)return;if(x){z.current=d,E(d);return}_.current=!1,w.current&&(w.current.close(),w.current=null);const p=`temp-${Date.now()}`,S={id:p,sessionId:l.id,role:"user",content:d,createdAt:new Date().toISOString()};k(m=>[...m,S]),$(""),v(""),y([]),F(!0);let q="",ge="",O=[],H=null,ie=null;const G=()=>{H=null,$(q)},u=()=>{ie=null,v(ge)},A=()=>{H!==null&&(cancelAnimationFrame(H),H=null),ie!==null&&(cancelAnimationFrame(ie),ie=null)};te.current=A;const V={onThinking:m=>{ge+=m,ie===null&&(ie=requestAnimationFrame(u))},onText:m=>{q+=m,H===null&&(H=requestAnimationFrame(G))},onToolStart:m=>{O=[...O,{toolName:m.toolName,args:m.args,isError:!1,status:"running"}],y(O)},onToolEnd:m=>{const D=[...O];for(let b=D.length-1;b>=0;b--){const ee=D[b];if(ee?.toolName===m.toolName&&ee.status==="running"){D[b]={...ee,status:"completed",isError:m.isError,result:m.result},O=D,y(D);return}}O=[...D,{toolName:m.toolName,isError:m.isError,result:m.result,status:"completed"}],y(O)},onDone:m=>{A();const D={id:m.messageId||`msg-${Date.now()}`,sessionId:l.id,role:"assistant",content:q,thinkingOutput:ge,toolCalls:O.length>0?O:void 0,createdAt:new Date().toISOString()};we.current.add(D.id),k(ee=>[...ee,D]),$(""),v(""),y([]),F(!1),w.current=null,setTimeout(()=>{we.current.delete(D.id)},1e3),K();const b=z.current.trim();b&&(z.current="",E(""),ue(b))},onError:m=>{if(A(),k(D=>D.filter(b=>b.id!==p)),$(""),v(""),y([]),F(!1),w.current=null,console.error("[useChat] Stream error:",m),!_.current){const D=z.current.trim();D&&(z.current="",E(""),ue(D))}}};w.current=Ht(l.id,d,V,f,a)},[l,x,a,K]),Ne=X?i.filter(d=>d.title?.toLowerCase().includes(X.toLowerCase())||d.agentId.toLowerCase().includes(X.toLowerCase())):i;return s.useEffect(()=>{const d=me.current,f=a?`?projectId=${encodeURIComponent(a)}`:"",p=()=>me.current!==d,S=G=>{if(p())return;const u=JSON.parse(G.data);r(A=>A.some(V=>V.id===u.id)?A:[u,...A])},q=G=>{if(p())return;const u=JSON.parse(G.data);r(A=>[...A.map(m=>m.id===u.id?u:m)]),xe.current?.id===u.id&&c(u)},ge=G=>{if(p())return;const{id:u}=JSON.parse(G.data);r(A=>A.filter(V=>V.id!==u)),xe.current?.id===u&&(c(null),k([]))},O=G=>{if(p())return;const u=JSON.parse(G.data),A=nt(u);we.current.has(A.id)||xe.current?.id===A.sessionId&&!ve.current&&k(V=>V.some(m=>m.id===A.id)?V:[...V,A])},H=G=>{if(p())return;const{id:u}=JSON.parse(G.data);k(A=>A.filter(V=>V.id!==u))};return Vt(`/api/events${f}`,{events:{"chat:session:created":S,"chat:session:updated":q,"chat:session:deleted":ge,"chat:message:added":O,"chat:message:deleted":H}})},[a]),s.useEffect(()=>()=>{w.current&&(w.current.close(),w.current=null)},[]),{sessions:i,activeSession:l,sessionsLoading:N,messages:R,messagesLoading:P,isStreaming:x,streamingText:T,streamingThinking:g,streamingToolCalls:C,pendingMessage:B,selectSession:ae,createSession:fe,archiveSession:Se,deleteSession:ce,sendMessage:ue,stopStreaming:de,clearPendingMessage:ye,loadMoreMessages:Z,hasMoreMessages:L,searchQuery:X,setSearchQuery:W,filteredSessions:Ne,refreshSessions:K,agentsMap:h}}function dt(a){const i=new Date(a),l=new Date().getTime()-i.getTime(),c=Math.floor(l/1e3),N=Math.floor(c/60),j=Math.floor(N/60),R=Math.floor(j/24);return c<60?"just now":N<60?`${N}m ago`:j<24?`${j}h ago`:R<7?`${R}d ago`:i.toLocaleDateString()}function at(a,i){if(!a||!i)return null;const r=i.toLowerCase();if(r.includes("claude")){let c=i.replace(/^claude[- ]/i,"Claude ").replace(/sonnet[- ](\d+)[- ](\d+)/i,"Sonnet $1.$2").replace(/sonnet[- ](\d+)/i,"Sonnet $1").replace(/haiku[- ](\d+)/i,"Haiku $1").replace(/opus[- ](\d+)/i,"Opus $1").replace(/sonnet/i,"Sonnet").replace(/haiku/i,"Haiku").replace(/opus/i,"Opus").replace(/-/g," ").trim();return c=c.replace(/\s+/g," "),c.length>30?c.slice(0,30)+"…":c}if(r.includes("gpt")||r.includes("openai")){const c=i.replace(/^gpt-4-turbo$/i,"GPT-4 Turbo").replace(/^gpt-4o-mini$/i,"GPT-4o Mini").replace(/^gpt-4o$/i,"GPT-4o").replace(/^gpt-4$/i,"GPT-4").replace(/^gpt-o1-preview$/i,"GPT-o1 Preview").replace(/^gpt-o1-mini$/i,"GPT-o1 Mini").replace(/^gpt-o1$/i,"GPT-o1").replace(/^gpt/i,"GPT").trim();return c.length>30?c.slice(0,30)+"…":c}if(r.includes("gemini")){const c=i.replace(/^gemini[- ]/i,"Gemini ").replace(/pro[- ](\d+)[- ](\d+)/i,"Pro $1.$2").replace(/pro[- ](\d+)/i,"Pro $1").replace(/-/g," ").replace(/\s+/g," ").trim();return c.length>30?c.slice(0,30)+"…":c}const l=i.replace(/-/g," ").replace(/^\w/,c=>c.toUpperCase()).replace(/\s+/g," ").trim();return l.length>30?l.slice(0,30)+"…":l}function Re(a,i){return a.length<=i?a:`${a.slice(0,i)}…`}function os(a){if(!a)return null;const i=Object.entries(a);return i.length===0?null:i.map(([r,l])=>{const c=typeof l=="string"?l:(()=>{try{return JSON.stringify(l)}catch{return String(l)}})();return`${r}=${Re(c,50)}`}).join(", ")}function cs(a){if(a===void 0)return null;if(typeof a=="string")return Re(a,200);try{return Re(JSON.stringify(a),200)}catch{return Re(String(a),200)}}function ut(a){if(!a||a.length===0)return null;const i=(x,F)=>{const T=x.status==="running",$=x.status==="completed"&&x.isError,g=os(x.args),v=cs(x.result),C=T?g:v?`result: ${v}`:g?`args: ${g}`:null,y=T?"running":$?"error":"completed";return t.jsxs("details",{className:`chat-tool-call${T?" chat-tool-call--running":""}${$?" chat-tool-call--error":""}`,open:T,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"chat-tool-call-status-dot","aria-hidden":"true"}),t.jsx("span",{className:"chat-tool-call-name",children:x.toolName}),C&&t.jsx("span",{className:"chat-tool-call-preview",title:C,children:C}),t.jsx("span",{className:"chat-tool-call-status-text",children:y})]}),t.jsxs("div",{className:"chat-tool-call-content",children:[g&&t.jsxs("div",{className:"chat-tool-call-row",children:[t.jsx("span",{className:"chat-tool-call-label",children:"args"}),t.jsx("span",{className:"chat-tool-call-value",children:g})]}),v&&t.jsxs("div",{className:`chat-tool-call-row${$?" chat-tool-call-row--error":""}`,children:[t.jsx("span",{className:"chat-tool-call-label",children:"result"}),t.jsx("span",{className:"chat-tool-call-value",children:v})]})]})]},`${x.toolName}-${F}`)},r="chat-tool-calls";if(a.length===1)return t.jsxs("div",{className:r,"data-testid":"chat-tool-calls",children:[t.jsxs("div",{className:"chat-tool-calls-header",children:[t.jsx(tt,{size:12,"aria-hidden":"true"}),t.jsx("span",{children:"Tool calls"})]}),i(a[0],0)]});const l=a.filter(x=>x.status==="running").length,c=a.filter(x=>x.status==="completed"&&x.isError).length,N=l>0,j=Array.from(new Set(a.map(x=>x.toolName))),R=j.slice(0,5),k=Math.max(0,j.length-R.length),P=k>0?`${R.join(", ")}, +${k} more`:R.join(", "),I=N?`(${l} running)`:c>0?`(${c} ${c===1?"error":"errors"})`:null;return t.jsx("div",{className:r,"data-testid":"chat-tool-calls",children:t.jsxs("details",{className:"chat-tool-calls-group","data-testid":"chat-tool-calls-group",open:N,children:[t.jsxs("summary",{className:"chat-tool-calls-group-summary",children:[t.jsx(tt,{size:12,"aria-hidden":"true"}),t.jsxs("span",{children:[a.length," tool calls"]}),t.jsx("span",{className:"chat-tool-calls-names",title:P,children:P}),I&&t.jsx("span",{className:"chat-tool-calls-group-status",children:I})]}),a.map((x,F)=>i(x,F))]})})}const ht={pre:({children:a,...i})=>t.jsx("pre",{...i,className:"chat-markdown-pre",children:a}),table:({children:a,...i})=>t.jsx("table",{...i,className:"chat-markdown-table",children:a})},De="__fn_agent__",ds=["image/png","image/jpeg","image/gif","image/webp","text/plain","application/json","text/yaml","text/markdown","text/csv","application/xml","text/x-log"];function it(a){const i=/(^|[\s])\/([^\s]*)$/.exec(a);if(!i)return null;const r=i[1]??"",l=i[2]??"",c=i.index+r.length;return{filter:l,start:c,end:a.length}}function us(a,i){const r=a.slice(0,i),l=/(^|[\s\n])@([\w-]*)$/.exec(r);if(!l)return null;const c=l[2]??"",N=r.length-c.length-1;return{filter:c,start:N,end:i}}function hs({projectId:a,onClose:i,onCreate:r}){const[l,c]=s.useState("agent"),[N,j]=s.useState([]),[R,k]=s.useState(!0),[P,I]=s.useState(""),[x,F]=s.useState([]),[T,$]=s.useState(!0),[g,v]=s.useState(""),[C,y]=s.useState([]),[B,E]=s.useState([]);s.useEffect(()=>{let h=!1;return k(!0),He(void 0,a).then(M=>{h||j(M)}).catch(()=>{h||j([])}).finally(()=>{h||k(!1)}),()=>{h=!0}},[a]),s.useEffect(()=>{$(!0),as().then(h=>{F(h.models),y(h.favoriteProviders),E(h.favoriteModels)}).catch(()=>{F([]),y([]),E([])}).finally(()=>{$(!1)})},[]);const X=s.useCallback(async h=>{const M=C,_=M.includes(h)?M.filter(z=>z!==h):[h,...M];y(_);try{await st({favoriteProviders:_,favoriteModels:B})}catch{y(M)}},[C,B]),W=s.useCallback(async h=>{const M=B,_=M.includes(h)?M.filter(z=>z!==h):[h,...M];E(_);try{await st({favoriteProviders:C,favoriteModels:_})}catch{E(M)}},[B,C]),L=h=>{if(h.preventDefault(),l==="agent"){if(!P)return;r({agentId:P});return}if(!g)return;const M=g.indexOf("/");if(M<=0)return;const w=g.slice(0,M),_=g.slice(M+1);r({agentId:De,modelProvider:w,modelId:_})},Y=l==="agent"?!P:!g;return t.jsx("div",{className:"chat-new-dialog-backdrop",onClick:i,role:"dialog","aria-modal":"true",children:t.jsxs("div",{className:"chat-new-dialog",onClick:h=>h.stopPropagation(),children:[t.jsx("h3",{children:"New Chat"}),t.jsxs("div",{className:"chat-new-dialog-mode-toggle","data-testid":"chat-new-dialog-mode-toggle",children:[t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="agent"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-agent",onClick:()=>{c("agent"),v("")},children:"Agent"}),t.jsx("button",{type:"button",className:`chat-new-dialog-mode-btn${l==="model"?" chat-new-dialog-mode-btn--active":""}`,"data-testid":"chat-new-dialog-mode-model",onClick:()=>{c("model"),I("")},children:"Model"})]}),t.jsxs("form",{onSubmit:L,children:[l==="agent"&&t.jsxs("label",{className:"chat-new-dialog-model-label",children:["Agent",R?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading agents..."}):N.length===0?t.jsx("div",{className:"chat-new-dialog-empty",children:"No agents available"}):t.jsx("div",{className:"chat-new-dialog-agent-list",children:N.map(h=>t.jsxs("button",{type:"button",className:`chat-new-dialog-agent-item${P===h.id?" chat-new-dialog-agent-item--selected":""}`,onClick:()=>I(h.id),"data-testid":`agent-option-${h.id}`,children:[t.jsx(Pe,{size:16}),t.jsx("span",{className:"chat-new-dialog-agent-name",children:h.name}),t.jsx("span",{className:"chat-new-dialog-agent-role",children:h.role})]},h.id))})]}),l==="model"&&t.jsx("div",{className:"chat-new-dialog-model-dropdown","data-testid":"chat-new-dialog-model-section",children:T?t.jsx("div",{className:"chat-new-dialog-loading",children:"Loading models..."}):t.jsx(is,{models:x,value:g,onChange:v,label:"Model",placeholder:"Select a model",favoriteProviders:C,onToggleFavorite:X,favoriteModels:B,onToggleModelFavorite:W})}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{type:"button",className:"btn btn-sm",onClick:i,children:"Cancel"}),t.jsx("button",{type:"submit",className:"btn btn-sm btn-primary",disabled:Y,children:"Create"})]})]})]})})}const ms=s.memo(function({message:i,forcePlain:r,agentName:l,showAssistantModelTag:c,activeModelTag:N,activeSessionId:j,mentionAgentsByName:R,onToggleRender:k}){const P=i.role==="assistant",I=s.useMemo(()=>{if(P)return null;const T=i.content,$=/@([\w-]+)/g,g=[];let v=0,C=$.exec(T);for(;C;){const[y,B=""]=C,E=C.index;E>v&&g.push(T.slice(v,E));const X=B.replace(/_/g," ").toLowerCase(),W=R.get(X);W?g.push(t.jsxs("span",{className:"chat-mention-chip",children:["@",W.name.replace(/\s+/g,"_")]},`${W.id}-${E}`)):g.push(y),v=E+y.length,C=$.exec(T)}return v<T.length&&g.push(T.slice(v)),g.length===0?T:g},[P,i.content,R]),x=s.useMemo(()=>{const T=i.attachments;if(!T||T.length===0||!j)return null;const $=`/api/chat/sessions/${encodeURIComponent(j)}/attachments/`;return t.jsx("div",{className:"chat-message-attachments",children:T.map(g=>{const v=g.mimeType.startsWith("image/"),C=g.id||g.filename,y=`${$}${encodeURIComponent(g.filename)}`;return v?t.jsx("a",{className:"chat-message-attachment-link","data-testid":"chat-message-attachment",href:y,target:"_blank",rel:"noopener noreferrer",children:t.jsx("img",{className:"chat-message-attachment",src:y,alt:g.originalName})},C):t.jsxs("a",{className:"chat-message-attachment-file","data-testid":"chat-message-attachment",href:y,target:"_blank",rel:"noopener noreferrer",children:[t.jsx(ns,{size:14}),t.jsx("span",{children:g.originalName})]},C)})})},[i.attachments,j]),F=s.useMemo(()=>P?r?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:i.content}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(rt,{remarkPlugins:[lt],components:ht,children:i.content})}):null,[P,r,i.content]);return t.jsxs("div",{className:`chat-message chat-message--${i.role}`,"data-testid":`chat-message-${i.id}`,children:[P&&t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(Pe,{size:14}),t.jsx("span",{children:l}),c&&N&&t.jsx("span",{className:"chat-model-tag",children:N}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${r?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":r?"Show rendered markdown":"Show plain text",onClick:()=>k(i.id),children:r?t.jsx(ot,{size:14}):t.jsx(ct,{size:14})})]}),P?F:t.jsx("div",{className:"chat-message-content",children:I}),ut(i.toolCalls),i.thinkingOutput&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:i.thinkingOutput})]}),x,t.jsx("div",{className:"chat-message-time",children:dt(i.createdAt)})]})});function ws({projectId:a,addToast:i}){const{activeSession:r,sessionsLoading:l,messages:c,messagesLoading:N,isStreaming:j,streamingText:R,streamingThinking:k,streamingToolCalls:P,selectSession:I,createSession:x,archiveSession:F,deleteSession:T,sendMessage:$,stopStreaming:g,pendingMessage:v,clearPendingMessage:C,searchQuery:y,setSearchQuery:B,filteredSessions:E}=ls(a),[X,W]=s.useState(!1),[L,Y]=s.useState(""),[h,M]=s.useState(null),[w,_]=s.useState(null),[z,te]=s.useState(!0),[he,xe]=s.useState(new Map),[ve,we]=s.useState([]),[me,ke]=s.useState(!0),[K,se]=s.useState(!1),[oe,ne]=s.useState(""),[ae,fe]=s.useState(0),[Se,ce]=s.useState(""),[Z,de]=s.useState(!1),[ye,ue]=s.useState(0),[Ne,d]=s.useState(-1),[f,p]=s.useState(()=>new Set),[S,q]=s.useState([]),[ge,O]=s.useState(!1),[,H]=s.useState(!1),[ie,G]=s.useState({top:0,left:0}),u=Bt({projectId:a}),A=s.useCallback(e=>{if(!e||!u.mentionActive)return;const n=e.getBoundingClientRect();G({top:n.top-260,left:n.left+8})},[u.mentionActive]),V=s.useRef(null),m=s.useRef(null),D=s.useRef(null),b=s.useRef(null),ee=s.useRef(!1),Me=s.useRef(!1),Ve=s.useRef(null),Be=s.useRef([]),je=s.useRef(0),re=qt()==="mobile",{keyboardOverlap:Ee,viewportHeight:qe,viewportOffsetTop:mt,keyboardOpen:Fe}=Gt({enabled:re&&!!r}),ft=Fe?{"--keyboard-overlap":`${Ee}px`,"--vv-offset-top":`${mt}px`,...qe!==null?{"--vv-height":`${qe}px`}:{}}:{},Q=s.useMemo(()=>{const e=oe.trim().toLowerCase();return(e?ve.filter(o=>o.name.toLowerCase().includes(e)):ve).slice(0,10)},[ve,oe]),be=s.useMemo(()=>Array.from(he.values()),[he]),pe=s.useMemo(()=>{const e=Se.trim().toLowerCase();return e?be.filter(n=>n.name.toLowerCase().includes(e)):be},[be,Se]),gt=s.useMemo(()=>{const e=new Map;for(const n of be)e.set(n.name.toLowerCase(),n);return e},[be]);s.useEffect(()=>{fe(0)},[Q]),s.useEffect(()=>{ue(0)},[Se,Z]),s.useEffect(()=>()=>{m.current!==null&&window.clearTimeout(m.current)},[]),s.useEffect(()=>{const e=D.current;e&&(e.scrollTop=e.scrollHeight)},[c,R]),s.useEffect(()=>{if(Ee<=0)return;const e=D.current;e&&(e.scrollTop=e.scrollHeight)},[Ee]),s.useEffect(()=>{if(!re||!Fe)return;const e=document.documentElement,n=document.body,o={htmlOverflow:e.style.overflow,bodyOverflow:n.style.overflow};return e.style.overflow="hidden",n.style.overflow="hidden",()=>{e.style.overflow=o.htmlOverflow,n.style.overflow=o.bodyOverflow}},[re,Fe]),s.useEffect(()=>{const e=()=>M(null);if(h)return document.addEventListener("click",e),()=>document.removeEventListener("click",e)},[h]),s.useEffect(()=>{let e=!1;const n=a;return He(void 0,a).then(o=>{if(e||n!==a)return;const U=new Map;for(const J of o)U.set(J.id,J);xe(U)}).catch(()=>{}),()=>{e=!0}},[a]),s.useEffect(()=>{let e=!1;return ke(!0),Wt(a).then(n=>{e||we(n)}).catch(()=>{e||we([])}).finally(()=>{e||ke(!1)}),()=>{e=!0}},[a]),s.useEffect(()=>{Be.current=S},[S]),s.useEffect(()=>()=>{for(const e of Be.current)e.previewUrl&&URL.revokeObjectURL(e.previewUrl)},[]);const Te=s.useCallback(e=>{if(!e||e.length===0)return;const n=[];for(const o of Array.from(e)){if(!ds.includes(o.type))continue;const U=o.type.startsWith("image/");n.push({file:o,previewUrl:U?URL.createObjectURL(o):""})}n.length>0&&q(o=>[...o,...n])},[]),pt=s.useCallback(e=>{q(n=>{const o=n[e];return o?.previewUrl&&URL.revokeObjectURL(o.previewUrl),n.filter((U,J)=>J!==e)})},[]),xt=s.useCallback(e=>{const n=e.clipboardData?.files;if(!n||n.length===0)return;const o=Array.from(n).filter(U=>U.type.startsWith("image/"));o.length!==0&&Te(o)},[Te]),vt=s.useCallback(async e=>{try{await x(e),W(!1),re&&te(!1)}catch{i("Failed to create chat session","error")}},[x,i,re]),Le=s.useCallback(()=>{Y(""),se(!1),ne(""),de(!1),ce(""),d(-1),q(e=>{for(const n of e)n.previewUrl&&URL.revokeObjectURL(n.previewUrl);return[]})},[]),Ce=s.useCallback(()=>{const e=L.trim(),n=S.map(o=>o.file);if(!(!e&&n.length===0||!r)){if(e==="/clear"){Le(),g(),C(),x({agentId:r.agentId,modelProvider:r.modelProvider??void 0,modelId:r.modelId??void 0}).catch(()=>{i("Failed to clear conversation","error")});return}Le(),$(e,n)}},[L,S,r,Le,g,C,x,i,$]),Ae=s.useCallback(()=>{if(typeof window>"u"||window.innerWidth>768)return;const e=b.current;if(!e||e.disabled)return;const n=window.scrollX,o=window.scrollY;e.focus({preventScroll:!0}),window.requestAnimationFrame(()=>{(window.scrollX!==n||window.scrollY!==o)&&window.scrollTo(n,o)})},[]),Ge=s.useCallback(()=>{typeof window>"u"||window.innerWidth>768||(ee.current=!0)},[]),_e=s.useCallback(e=>{Y(n=>{const o=it(n);if(!o)return n;const U=`/skill:${e.name} `,J=n.slice(0,o.start)+U+n.slice(o.end);return window.requestAnimationFrame(()=>{b.current&&(b.current.style.height="auto",b.current.style.height=`${Math.min(b.current.scrollHeight,120)}px`,b.current.focus())}),J}),se(!1),ne(""),fe(0)},[]),Ie=s.useCallback(e=>{const n=b.current;if(!n||Ne<0)return;const o=n.selectionStart??je.current,U=n.selectionEnd??o,J=Math.max(o,U),Ye=Math.min(Ne,J),Qe=`${`@${e.name.replace(/\s+/g,"_")}`} `,Dt=L.slice(0,Ye)+Qe+L.slice(J),Xe=Ye+Qe.length;Y(Dt),de(!1),ce(""),ue(0),d(-1),window.requestAnimationFrame(()=>{b.current&&(b.current.style.height="auto",b.current.style.height=`${Math.min(b.current.scrollHeight,120)}px`,b.current.focus(),b.current.setSelectionRange(Xe,Xe))})},[Ne,L]),wt=s.useCallback(e=>{if(je.current=e.currentTarget.selectionStart??je.current,u.mentionActive&&u.files.length>0){if(u.handleKeyDown(e,L),e.key==="Enter"||e.key==="Tab"){const n=u.files[u.selectedIndex];if(n){const o=u.selectFile(n,L);Y(o),u.dismissMention(),H(!1)}}return}if(Z&&e.key==="ArrowDown"){e.preventDefault(),pe.length>0&&ue(n=>(n+1)%pe.length);return}if(Z&&e.key==="ArrowUp"){e.preventDefault(),pe.length>0&&ue(n=>n===0?pe.length-1:n-1);return}if(Z&&e.key==="Enter"){e.preventDefault();const n=pe[ye]??pe[0];n&&Ie(n);return}if(Z&&e.key==="Escape"){e.preventDefault(),de(!1),ce(""),d(-1);return}if(K&&e.key==="ArrowDown"){e.preventDefault(),Q.length>0&&fe(n=>(n+1)%Q.length);return}if(K&&e.key==="ArrowUp"){e.preventDefault(),Q.length>0&&fe(n=>n===0?Q.length-1:n-1);return}if(K&&(e.key==="Enter"||e.key==="Tab")&&Q.length>0){e.preventDefault();const n=Q[ae]??Q[0];n&&_e(n);return}if(K&&e.key==="Escape"){e.preventDefault(),se(!1);return}e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Ce())},[Z,pe,ye,Ie,K,Q,ae,_e,Ce,u,L]),$e=s.useCallback((e,n)=>{const o=us(e,n);if(o){de(!0),ce(o.filter),d(o.start);return}de(!1),ce(""),d(-1)},[]),St=s.useCallback(e=>{const n=e.target,o=n.value,U=n.selectionStart??o.length;je.current=U,Y(o);const J=it(o);J?(se(!0),ne(J.filter)):(se(!1),ne("")),$e(o,U),u.detectMention(o,U),H(u.mentionActive),u.mentionActive&&A(n),n.style.height="auto",n.style.height=`${Math.min(n.scrollHeight,120)}px`},[$e]),Oe=s.useCallback(e=>{const n=e.currentTarget,o=n.selectionStart??n.value.length;je.current=o,$e(n.value,o),u.detectMention(n.value,o),H(u.mentionActive),u.mentionActive&&A(n)},[$e,u,A]),bt=s.useCallback(e=>{e.key!=="Escape"&&Oe(e)},[Oe]),kt=s.useCallback(()=>{if(ee.current){window.requestAnimationFrame(()=>{Ae()});return}m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{se(!1),de(!1),ce(""),d(-1),H(!1),u.dismissMention(),m.current=null},120)},[u,Ae]),yt=s.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),Nt=s.useCallback(async e=>{M(null);try{await F(e),i("Conversation archived","success")}catch{i("Failed to archive conversation","error")}},[F,i]),jt=s.useCallback(async e=>{_(null),M(null);try{await T(e),i("Conversation deleted","success")}catch{i("Failed to delete conversation","error")}},[T,i]),Ct=s.useCallback(e=>{I(e),re&&te(!1)},[I,re]),Mt=s.useCallback(()=>{I(""),te(!0)},[I]),Tt=()=>t.jsxs("div",{className:"chat-empty-state",children:[t.jsx(ss,{size:48,strokeWidth:1.5}),t.jsx("h2",{children:"Start a new conversation"}),t.jsxs("button",{className:"btn btn-primary",onClick:()=>W(!0),children:[t.jsx(et,{size:16}),"New Chat"]})]}),le=at(r?.modelProvider,r?.modelId),We=r?.agentId===De?le??"Fusion":r?.title||he.get(r?.agentId??"")?.name||r?.agentId||"Chat",At=!!(le&&le!==We),Ue=he.get(r?.agentId??"")?.name||(r?.agentId===De?le??"Fusion":r?.agentId?.slice(0,30)??"Fusion"),Ke=!!(le&&le!==Ue),$t=v.length>50?`${v.slice(0,50)}…`:v,Je=s.useCallback(e=>{p(n=>{const o=new Set(n);return o.has(e)?o.delete(e):o.add(e),o})},[]),Rt=s.useCallback((e,n=!1)=>n?t.jsx("div",{className:"chat-message-content chat-message-content--plain",children:e}):t.jsx("div",{className:"chat-message-content chat-message-content--markdown",children:t.jsx(rt,{remarkPlugins:[lt],components:ht,children:e})}),[]);return t.jsxs("div",{className:"chat-view",children:[t.jsxs("div",{className:`chat-sidebar${z?"":" chat-sidebar--hidden"}`,children:[t.jsx("div",{className:"chat-sidebar-search",children:t.jsxs("div",{className:"chat-sidebar-search-wrapper",children:[t.jsx(Kt,{size:14,className:"chat-sidebar-search-icon"}),t.jsx("input",{type:"text",className:"chat-sidebar-search",placeholder:"Search conversations...",value:y,onChange:e=>B(e.target.value),"data-testid":"chat-search-input"})]})}),t.jsx("div",{className:"chat-session-list chat-sidebar-list",children:l?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"Loading..."}):E.length===0?t.jsx("div",{style:{padding:"12px",color:"var(--text-secondary)",fontSize:"13px"},children:"No conversations yet"}):E.map(e=>t.jsxs("div",{className:`chat-session-item${r?.id===e.id?" chat-session-item--active":""}`,onClick:()=>Ct(e.id),onContextMenu:n=>{n.preventDefault(),M({sessionId:e.id,x:n.clientX,y:n.clientY})},"data-testid":`chat-session-${e.id}`,children:[t.jsx("button",{className:"chat-session-delete-btn",onClick:n=>{n.stopPropagation(),_(e.id)},"data-testid":"chat-session-delete-btn","aria-label":"Delete conversation",children:t.jsx(Ze,{size:14})}),t.jsx("div",{className:"chat-session-title",children:e.title||"Untitled"}),t.jsx("div",{className:"chat-session-preview",children:e.lastMessagePreview||"No messages"}),t.jsxs("div",{className:"chat-session-meta",children:[t.jsx("span",{children:he.get(e.agentId)?.name||(e.agentId===De?at(e.modelProvider,e.modelId)??"Fusion":e.agentId.slice(0,30))}),t.jsx("span",{children:e.updatedAt?dt(e.updatedAt):""})]})]},e.id))}),t.jsx("div",{className:"chat-sidebar-footer",children:t.jsxs("button",{className:"btn btn-sm btn-primary chat-sidebar-footer-btn",onClick:()=>W(!0),"data-testid":"chat-new-btn",children:[t.jsx(et,{size:14}),"New Chat"]})})]}),h&&t.jsxs("div",{className:"chat-session-context-menu",style:{top:h.y,left:h.x},onClick:e=>e.stopPropagation(),children:[t.jsxs("button",{onClick:()=>Nt(h.sessionId),"data-testid":"chat-context-archive",children:[t.jsx(Jt,{size:14}),"Archive"]}),t.jsxs("button",{onClick:()=>{M(null),_(h.sessionId)},"data-testid":"chat-context-delete",children:[t.jsx(Ze,{size:14}),"Delete"]})]}),w&&t.jsx("div",{className:"chat-new-dialog-backdrop",onClick:()=>_(null),children:t.jsxs("div",{className:"chat-new-dialog",onClick:e=>e.stopPropagation(),children:[t.jsx("h3",{children:"Delete Conversation?"}),t.jsx("p",{style:{fontSize:"14px",color:"var(--text-secondary)",marginBottom:"16px"},children:"This action cannot be undone. All messages in this conversation will be permanently deleted."}),t.jsxs("div",{className:"chat-new-dialog-actions",children:[t.jsx("button",{className:"btn btn-sm",onClick:()=>_(null),children:"Cancel"}),t.jsx("button",{className:"btn btn-sm btn-danger",onClick:()=>void jt(w),children:"Delete"})]})]})}),t.jsxs("div",{className:"chat-thread",style:ft,children:[(r||!re)&&t.jsxs("div",{className:"chat-thread-header",children:[re&&r&&t.jsx("button",{className:"btn-icon",onClick:Mt,"data-testid":"chat-back-btn",children:t.jsx(Yt,{size:16})}),t.jsx(Pe,{size:16}),t.jsx("span",{className:"chat-thread-header-title",children:We}),At&&t.jsx("span",{className:"chat-model-tag",children:le})]}),t.jsxs("div",{className:"chat-messages",ref:D,children:[N?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"Loading messages..."}):c.length===0&&!r?Tt():c.length===0&&r?t.jsx("div",{style:{color:"var(--text-secondary)",fontSize:"13px"},children:"No messages yet. Start the conversation!"}):t.jsxs(t.Fragment,{children:[c.map(e=>t.jsx(ms,{message:e,forcePlain:f.has(e.id),agentName:Ue,showAssistantModelTag:Ke,activeModelTag:le,activeSessionId:r?.id??null,mentionAgentsByName:gt,onToggleRender:Je},e.id)),j&&t.jsxs("div",{className:"chat-message chat-message--assistant chat-message--streaming",children:[t.jsxs("div",{className:"chat-message-avatar",children:[t.jsx(Pe,{size:14}),t.jsx("span",{children:Ue}),Ke&&t.jsx("span",{className:"chat-model-tag",children:le}),t.jsx("button",{type:"button",className:`chat-message-render-toggle${f.has("__streaming__")?" chat-message-render-toggle--plain":""}`,"data-testid":"chat-message-render-toggle","aria-label":f.has("__streaming__")?"Show rendered markdown":"Show plain text",onClick:()=>Je("__streaming__"),children:f.has("__streaming__")?t.jsx(ot,{size:14}):t.jsx(ct,{size:14})})]}),R?Rt(R,f.has("__streaming__")):t.jsx("div",{className:"chat-message-content chat-message-content--waiting",children:k?"Thinking…":"Connecting…"}),ut(P),k&&t.jsxs("details",{className:"chat-message-thinking",children:[t.jsx("summary",{children:"Thinking"}),t.jsx("pre",{className:"chat-message-thinking-content",children:k})]}),t.jsxs("div",{className:"chat-typing-indicator",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})]})]}),t.jsx("div",{ref:V})]}),r&&t.jsxs("div",{className:"chat-input-area",children:[t.jsx("input",{ref:Ve,type:"file",accept:"image/*,.txt,.json,.yaml,.yml,.log,.csv,.xml,.md",multiple:!0,style:{display:"none"},onChange:e=>{Te(e.target.files),e.target.value=""}}),K&&t.jsx("div",{className:"chat-skill-menu","data-testid":"chat-skill-menu",role:"listbox","aria-label":"Skill suggestions",children:me?t.jsx("div",{className:"chat-skill-menu-empty",children:"Loading skills…"}):Q.length===0?t.jsx("div",{className:"chat-skill-menu-empty",children:oe?"No skills found":"No skills available"}):Q.map((e,n)=>t.jsxs("button",{type:"button",role:"option","aria-selected":n===ae,className:`chat-skill-menu-item${n===ae?" chat-skill-menu-item--highlighted":""}`,onMouseDown:o=>o.preventDefault(),onMouseEnter:()=>fe(n),onClick:()=>_e(e),children:[t.jsx("span",{className:"chat-skill-menu-item-name",children:e.name}),t.jsx("span",{className:"chat-skill-menu-item-description",title:e.relativePath,children:e.relativePath})]},e.id))}),S.length>0&&t.jsx("div",{className:"chat-attachment-previews","data-testid":"chat-attachment-previews",children:S.map((e,n)=>t.jsxs("div",{className:"chat-attachment-preview","data-testid":`chat-attachment-preview-${n}`,children:[e.previewUrl?t.jsx("img",{src:e.previewUrl,alt:e.file.name}):t.jsx("span",{className:"chat-attachment-preview-name",children:e.file.name}),t.jsx("button",{type:"button",className:"chat-attachment-remove",onClick:()=>pt(n),"data-testid":`chat-attachment-remove-${n}`,"aria-label":`Remove ${e.file.name}`,children:"×"})]},e.previewUrl||`${e.file.name}-${n}`))}),t.jsxs("div",{className:"chat-input-row",children:[t.jsx("button",{type:"button",className:"btn-icon chat-attach-btn","data-testid":"chat-attach-btn","aria-label":"Attach files",onClick:()=>Ve.current?.click(),children:t.jsx(Qt,{size:16})}),t.jsxs("div",{className:`chat-input-wrapper${ge?" chat-input-wrapper--dragover":""}`,onDragOver:e=>{e.preventDefault(),O(!0)},onDragLeave:()=>O(!1),onDrop:e=>{e.preventDefault(),O(!1),Te(e.dataTransfer.files)},children:[t.jsx("textarea",{ref:b,className:"chat-input-textarea",placeholder:"Type a message...",value:L,onChange:St,onKeyDown:wt,onKeyUp:bt,onClick:Oe,onBlur:kt,onFocus:yt,onPaste:xt,onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||document.activeElement!==e.currentTarget&&(e.preventDefault(),e.currentTarget.focus({preventScroll:!0}))},rows:1,"data-testid":"chat-input"}),t.jsx(Xt,{agents:be,filter:Se,highlightedIndex:ye,visible:Z,onSelect:Ie,position:"below"}),t.jsx(Zt,{visible:u.mentionActive&&!Z,position:ie,files:u.files,selectedIndex:u.selectedIndex,onSelect:e=>{const n=u.selectFile(e,L);Y(n),u.dismissMention(),H(!1),b.current?.focus()},loading:u.loading}),v&&t.jsxs("div",{className:"chat-pending-message","data-testid":"chat-pending-indicator",children:[t.jsx("span",{children:`Queued: ${$t}`}),t.jsx("button",{type:"button",className:"chat-pending-message-dismiss","aria-label":"Dismiss queued message","data-testid":"chat-pending-dismiss",onClick:C,children:"×"})]})]}),j?t.jsx("button",{className:"chat-input-stop",onClick:g,"aria-label":"Stop generation","data-testid":"chat-stop-btn",children:t.jsx(es,{size:14})}):t.jsx("button",{type:"button",className:"chat-input-send",onPointerDown:e=>{typeof window>"u"||window.innerWidth>768||(e.preventDefault(),e.pointerType&&e.pointerType!=="mouse"&&(Me.current=!0,Ge(),Ae(),Ce(),window.setTimeout(()=>{ee.current=!1},1500)))},onTouchStart:e=>{typeof window>"u"||window.innerWidth>768||(e.preventDefault(),Me.current=!0,Ge(),Ae(),Ce(),window.setTimeout(()=>{ee.current=!1},1500))},onMouseDown:e=>{typeof window>"u"||window.innerWidth>768||e.preventDefault()},onClick:()=>{if(Me.current){Me.current=!1;return}Ce()},disabled:!L.trim()&&S.length===0,"data-testid":"chat-send-btn",children:t.jsx(ts,{size:16})})]})]})]}),X&&t.jsx(hs,{projectId:a,onClose:()=>W(!1),onCreate:vt})]})}export{ws as ChatView};
|