meshy-node 0.9.4 → 0.9.5
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/README.md +1 -1
- package/dashboard/assets/DashboardPage-D21dWlmw.js +164 -0
- package/dashboard/assets/{DashboardShared-clSb73vU.js → DashboardShared-CtD601bB.js} +1 -1
- package/dashboard/assets/{DiffTab-QOs1BAhv.js → DiffTab-D1I57xJM.js} +2 -2
- package/dashboard/assets/{FilesTab-amewzDu1.js → FilesTab-B_30Lp2l.js} +2 -2
- package/dashboard/assets/{MarkdownPreviewFrame-DTqC8qsr.js → MarkdownPreviewFrame-hB6tBCB8.js} +1 -1
- package/dashboard/assets/PreviewTab-BBaAgEyn.js +21 -0
- package/dashboard/assets/{SharedConversationPage-BlehYOnU.js → SharedConversationPage-DpJKqW_3.js} +2 -2
- package/dashboard/assets/{file-61zsRyWG.js → file-B8vnmnf2.js} +1 -1
- package/dashboard/assets/index-9hU42hur.js +316 -0
- package/dashboard/assets/{index-DGEkwKT1.css → index-DQIXvvgG.css} +1 -1
- package/dashboard/index.html +2 -2
- package/main.cjs +143611 -50645
- package/package.json +1 -1
- package/runtime-metadata.json +4 -4
- package/dashboard/assets/DashboardPage-D2jQAhdO.js +0 -164
- package/dashboard/assets/PreviewTab-CDVQQTEo.js +0 -21
- package/dashboard/assets/index-BubHGNBS.js +0 -316
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-amewzDu1.js","assets/index-BubHGNBS.js","assets/index-DGEkwKT1.css","assets/MarkdownPreviewFrame-DTqC8qsr.js","assets/DashboardShared-clSb73vU.js","assets/file-61zsRyWG.js","assets/PreviewTab-CDVQQTEo.js","assets/DiffTab-QOs1BAhv.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as me,r as a,j as e,X as Xe,B as W,S as ga,a as Xr,b as M,d as Jr,g as eo,e as to,I as Qe,C as Vt,f as so,h as ba,F as no,i as At,k as Fe,l as he,D as Ut,m as ao,n as ro,t as le,o as Se,p as Ce,q as Le,s as _e,u as va,v as Je,T as oo,w as io,x as yn,y as lo,z as Mt,A as Pt,E as Gt,G as ja,H as wa,J as Ct,K as Ws,L as bt,M as Ls,N as co,O as Ys,P as ya,Q as uo,R as $e,U as mo,V as nt,W as ns,Y as as,Z as rs,_ as os,$ as is,a0 as ls,a1 as ds,a2 as cs,a3 as Zs,a4 as xo,a5 as Qs,a6 as Na,a7 as ho,a8 as Nn,a9 as kn,aa as Cs,ab as po,ac as fo,ad as go,ae as bo,af as vo,ag as ps,ah as jo,ai as ka,aj as wo,ak as yo,al as No,am as Sa,an as Xs,ao as Ca,ap as ko,aq as us,ar as So,as as Js,at as Co,au as en,av as _o,aw as To,ax as Eo,ay as _a,az as Ht,aA as Do,aB as Is,aC as Ao,aD as Mo,aE as Po,aF as Lo,aG as Sn,aH as Io,aI as Bo,aJ as _s,aK as Ro,aL as Cn,aM as $o,aN as Oo,aO as zo,aP as _n,aQ as Fo,aR as Vo,aS as Bs,aT as Uo,aU as Ho,aV as Tn,aW as Ta,aX as qo,aY as Ko,aZ as Go,a_ as Wo,a$ as Yo,b0 as Zo,b1 as Qo,b2 as Xo,b3 as Jo,b4 as ei,b5 as ti,b6 as si,b7 as ni,b8 as ai,b9 as ri,ba as oi,bb as ii,bc as li,bd as di,be as ci,bf as ui,bg as mi,bh as xi,bi as hi,bj as pi,bk as fi,bl as gi,bm as bi,bn as vi,bo as ji,bp as wi}from"./index-BubHGNBS.js";import{r as En,e as yi,b as Ea,I as Da,A as tn,L as ue,g as Aa,a as Ni,c as ki,t as Si,d as Dn,f as An,M as Ci,h as _i,i as Ti,C as Mn,T as Ts,D as St,j as Ze,k as Rs,l as Ei,m as Ma,n as $s,o as Di,p as Pn,q as Ai,s as Mi,u as Es,v as Pi,w as Li,x as Ii}from"./DashboardShared-clSb73vU.js";import{E as Bi,M as Ri}from"./MarkdownPreviewFrame-DTqC8qsr.js";import{P as fs,g as $i,a as Oi,b as zi}from"./PreviewTab-CDVQQTEo.js";/**
|
|
3
|
-
* @license lucide-react v1.7.0 - ISC
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the ISC license.
|
|
6
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/const Fi=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],Vi=me("archive",Fi);/**
|
|
8
|
-
* @license lucide-react v1.7.0 - ISC
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the ISC license.
|
|
11
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
12
|
-
*/const Ui=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],Ln=me("arrow-right",Ui);/**
|
|
13
|
-
* @license lucide-react v1.7.0 - ISC
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the ISC license.
|
|
16
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/const Hi=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Pa=me("arrow-up",Hi);/**
|
|
18
|
-
* @license lucide-react v1.7.0 - ISC
|
|
19
|
-
*
|
|
20
|
-
* This source code is licensed under the ISC license.
|
|
21
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
22
|
-
*/const qi=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],qt=me("chevron-left",qi);/**
|
|
23
|
-
* @license lucide-react v1.7.0 - ISC
|
|
24
|
-
*
|
|
25
|
-
* This source code is licensed under the ISC license.
|
|
26
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
27
|
-
*/const Ki=[["path",{d:"M21.54 15H17a2 2 0 0 0-2 2v4.54",key:"1djwo0"}],["path",{d:"M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",key:"1tzkfa"}],["path",{d:"M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05",key:"14pb5j"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Gi=me("earth",Ki);/**
|
|
28
|
-
* @license lucide-react v1.7.0 - ISC
|
|
29
|
-
*
|
|
30
|
-
* This source code is licensed under the ISC license.
|
|
31
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
32
|
-
*/const Wi=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],Yi=me("ellipsis-vertical",Wi);/**
|
|
33
|
-
* @license lucide-react v1.7.0 - ISC
|
|
34
|
-
*
|
|
35
|
-
* This source code is licensed under the ISC license.
|
|
36
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
37
|
-
*/const Zi=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],Qi=me("ellipsis",Zi);/**
|
|
38
|
-
* @license lucide-react v1.7.0 - ISC
|
|
39
|
-
*
|
|
40
|
-
* This source code is licensed under the ISC license.
|
|
41
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
42
|
-
*/const Xi=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],Ji=me("flag",Xi);/**
|
|
43
|
-
* @license lucide-react v1.7.0 - ISC
|
|
44
|
-
*
|
|
45
|
-
* This source code is licensed under the ISC license.
|
|
46
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
47
|
-
*/const el=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],gs=me("folder-open",el);/**
|
|
48
|
-
* @license lucide-react v1.7.0 - ISC
|
|
49
|
-
*
|
|
50
|
-
* This source code is licensed under the ISC license.
|
|
51
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
52
|
-
*/const tl=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],sl=me("funnel",tl);/**
|
|
53
|
-
* @license lucide-react v1.7.0 - ISC
|
|
54
|
-
*
|
|
55
|
-
* This source code is licensed under the ISC license.
|
|
56
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
57
|
-
*/const nl=[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]],ms=me("git-branch",nl);/**
|
|
58
|
-
* @license lucide-react v1.7.0 - ISC
|
|
59
|
-
*
|
|
60
|
-
* This source code is licensed under the ISC license.
|
|
61
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
62
|
-
*/const al=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],rl=me("globe",al);/**
|
|
63
|
-
* @license lucide-react v1.7.0 - ISC
|
|
64
|
-
*
|
|
65
|
-
* This source code is licensed under the ISC license.
|
|
66
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
67
|
-
*/const ol=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],Os=me("history",ol);/**
|
|
68
|
-
* @license lucide-react v1.7.0 - ISC
|
|
69
|
-
*
|
|
70
|
-
* This source code is licensed under the ISC license.
|
|
71
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
72
|
-
*/const il=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],zs=me("image-plus",il);/**
|
|
73
|
-
* @license lucide-react v1.7.0 - ISC
|
|
74
|
-
*
|
|
75
|
-
* This source code is licensed under the ISC license.
|
|
76
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
77
|
-
*/const ll=[["path",{d:"M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z",key:"1pdavp"}],["path",{d:"M20.054 15.987H3.946",key:"14rxg9"}]],dl=me("laptop",ll);/**
|
|
78
|
-
* @license lucide-react v1.7.0 - ISC
|
|
79
|
-
*
|
|
80
|
-
* This source code is licensed under the ISC license.
|
|
81
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
82
|
-
*/const cl=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],sn=me("link-2",cl);/**
|
|
83
|
-
* @license lucide-react v1.7.0 - ISC
|
|
84
|
-
*
|
|
85
|
-
* This source code is licensed under the ISC license.
|
|
86
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
87
|
-
*/const ul=[["path",{d:"M11 5h10",key:"1cz7ny"}],["path",{d:"M11 12h10",key:"1438ji"}],["path",{d:"M11 19h10",key:"11t30w"}],["path",{d:"M4 4h1v5",key:"10yrso"}],["path",{d:"M4 9h2",key:"r1h2o0"}],["path",{d:"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02",key:"xtkcd5"}]],ml=me("list-ordered",ul);/**
|
|
88
|
-
* @license lucide-react v1.7.0 - ISC
|
|
89
|
-
*
|
|
90
|
-
* This source code is licensed under the ISC license.
|
|
91
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
92
|
-
*/const xl=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M12 8v6",key:"1ib9pf"}],["path",{d:"M9 11h6",key:"1fldmi"}]],bs=me("message-square-plus",xl);/**
|
|
93
|
-
* @license lucide-react v1.7.0 - ISC
|
|
94
|
-
*
|
|
95
|
-
* This source code is licensed under the ISC license.
|
|
96
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
97
|
-
*/const hl=[["path",{d:"M15.033 9.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56V7.648a.645.645 0 0 1 .967-.56z",key:"vbtd3f"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",key:"x3v2xh"}]],La=me("monitor-play",hl);/**
|
|
98
|
-
* @license lucide-react v1.7.0 - ISC
|
|
99
|
-
*
|
|
100
|
-
* This source code is licensed under the ISC license.
|
|
101
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
102
|
-
*/const pl=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],Lt=me("pencil",pl);/**
|
|
103
|
-
* @license lucide-react v1.7.0 - ISC
|
|
104
|
-
*
|
|
105
|
-
* This source code is licensed under the ISC license.
|
|
106
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
107
|
-
*/const fl=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],gl=me("plus",fl);/**
|
|
108
|
-
* @license lucide-react v1.7.0 - ISC
|
|
109
|
-
*
|
|
110
|
-
* This source code is licensed under the ISC license.
|
|
111
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
112
|
-
*/const bl=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],vl=me("rotate-ccw",bl);/**
|
|
113
|
-
* @license lucide-react v1.7.0 - ISC
|
|
114
|
-
*
|
|
115
|
-
* This source code is licensed under the ISC license.
|
|
116
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
117
|
-
*/const jl=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],Ia=me("rotate-cw",jl);/**
|
|
118
|
-
* @license lucide-react v1.7.0 - ISC
|
|
119
|
-
*
|
|
120
|
-
* This source code is licensed under the ISC license.
|
|
121
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
122
|
-
*/const wl=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],Ba=me("send",wl);/**
|
|
123
|
-
* @license lucide-react v1.7.0 - ISC
|
|
124
|
-
*
|
|
125
|
-
* This source code is licensed under the ISC license.
|
|
126
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
127
|
-
*/const yl=[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]],xs=me("share-2",yl);/**
|
|
128
|
-
* @license lucide-react v1.7.0 - ISC
|
|
129
|
-
*
|
|
130
|
-
* This source code is licensed under the ISC license.
|
|
131
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
132
|
-
*/const Nl=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],kl=me("sliders-horizontal",Nl);/**
|
|
133
|
-
* @license lucide-react v1.7.0 - ISC
|
|
134
|
-
*
|
|
135
|
-
* This source code is licensed under the ISC license.
|
|
136
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
137
|
-
*/const Sl=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],In=me("square",Sl);/**
|
|
138
|
-
* @license lucide-react v1.7.0 - ISC
|
|
139
|
-
*
|
|
140
|
-
* This source code is licensed under the ISC license.
|
|
141
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
142
|
-
*/const Cl=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],Ra=me("trash-2",Cl);/**
|
|
143
|
-
* @license lucide-react v1.7.0 - ISC
|
|
144
|
-
*
|
|
145
|
-
* This source code is licensed under the ISC license.
|
|
146
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
147
|
-
*/const _l=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],Tl=me("user-plus",_l);/**
|
|
148
|
-
* @license lucide-react v1.7.0 - ISC
|
|
149
|
-
*
|
|
150
|
-
* This source code is licensed under the ISC license.
|
|
151
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
152
|
-
*/const El=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],Dl=me("wifi",El);/**
|
|
153
|
-
* @license lucide-react v1.7.0 - ISC
|
|
154
|
-
*
|
|
155
|
-
* This source code is licensed under the ISC license.
|
|
156
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
157
|
-
*/const Al=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Ml=me("zoom-in",Al);/**
|
|
158
|
-
* @license lucide-react v1.7.0 - ISC
|
|
159
|
-
*
|
|
160
|
-
* This source code is licensed under the ISC license.
|
|
161
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
162
|
-
*/const Pl=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Ll=me("zoom-out",Pl),Il=new Set(["assigned","running"]);function Bl(t,s){return t.reduce((n,r)=>r.assignedTo===s&&Il.has(r.status)?n+1:n,0)}function It(t){return(t==null?void 0:t.toLowerCase())==="devtunnel"}function Rl(t){return t?It(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function nn(t,s){return It(s??t.transportType)||!!t.devtunnelEndpoint}function $a(t,s){return!It(s??t.transportType)}function Oa(t,s){const n=s??t.transportType;return It(n)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":Rl(n)}function Bn(t,s){return!t&&!s}function $l({routeTaskId:t,creatingTask:s,internalSelectedTaskId:n,sortedTaskIds:r}){return t||(s?null:r[0]??n??null)}function Ol({activeTaskId:t,routeTaskId:s,creatingTask:n,tasksLoading:r,loadedTaskIds:o}){return!t||s||n||r?!1:!o.includes(t)}function zl(t,s){return[s,...t.filter(n=>n.id!==s.id)]}function za(t,s){const n=t.findIndex(r=>r.id===s.id);return n===-1?[...t,s]:t.map((r,o)=>o===n?s:r)}const Fl=new Set(["completed","failed","cancelled","archived"]);function Vl(t,s){const n=new Set(s);return new Set(Array.from(t).filter(r=>n.has(r)))}function Ul(t,s){const n=new Set(s);if(n.size===0)return!1;const r=t.filter(o=>n.has(o.id));return r.length===n.size&&r.every(o=>Fl.has(o.status))}function Hl(t,s){var r;const n=new Set(s);return((r=t.find(o=>!n.has(o.id)))==null?void 0:r.id)??null}function Fa(){const[t,s]=a.useState([]),[n,r]=a.useState(null),o=a.useRef(null),i=a.useCallback(()=>{var k;(k=o.current)==null||k.click()},[]),d=a.useCallback(async k=>{const h=Array.from(k.target.files??[]);if(h.length!==0)try{const l=await En(h);s(N=>[...N,...l]),r(null)}catch(l){r(l instanceof Error?l.message:"Failed to attach image")}finally{k.target.value=""}},[]),c=a.useCallback(async k=>{const h=yi(k.clipboardData);if(h.length!==0){k.preventDefault();try{const l=await En(h);s(N=>[...N,...l]),r(null)}catch(l){r(l instanceof Error?l.message:"Failed to attach image")}}},[]),g=a.useCallback(k=>{s(h=>h.filter((l,N)=>N!==k))},[]),p=a.useCallback(()=>{s([]),r(null)},[]);return{images:t,error:n,fileInputRef:o,pickImages:i,handleFileChange:d,handlePaste:c,removeImage:g,clearImages:p}}function ql(t){const s=t.map(o=>({...o,displayValue:Kl(o)})),n=s.findIndex(o=>o.label.toLowerCase()==="working dir"),r=n>=0?n:0;return{primary:s[r],secondary:s.filter((o,i)=>i!==r)}}function Kl(t){return t.label.toLowerCase()==="agent"?Aa(t.value):t.value}function Rn(t){switch(t.toLowerCase()){case"branch":return ms;case"node":return ga;case"working dir":default:return gs}}function Gl({disabled:t=!1,running:s=!1,canStop:n=!1,hasContent:r=!1}){return s&&!r?{primaryAction:"stop",primaryDisabled:t||!n}:{primaryAction:"send",primaryDisabled:t||!r}}function Wl({contentLength:t,disabled:s=!1}){return t>0&&!s}function Yl({onSend:t,disabled:s,disabledReason:n="Chat is waiting on the agent.",placeholder:r="Send a follow-up message...",contextItems:o=[],running:i=!1,onStop:d}){const[c,g]=a.useState(""),[p,k]=a.useState(0),h=a.useRef(null),{images:l,error:N,fileInputRef:T,pickImages:w,handleFileChange:_,handlePaste:f,removeImage:S,clearImages:b}=Fa(),v=a.useCallback(()=>{h.current&&(h.current.style.height="auto")},[]),y=a.useCallback(()=>{const R=Ea(c,l);Wl({contentLength:R.length,disabled:s})&&(k(B=>B+1),t(R),g(""),b(),v())},[c,l,s,t,b,v]),C=a.useCallback(R=>{R.key==="Enter"&&!R.shiftKey&&(R.preventDefault(),y())},[y]),E=a.useCallback(()=>{h.current&&(h.current.style.height="auto",h.current.style.height=`${Math.min(h.current.scrollHeight,220)}px`)},[]),q=c.trim().length>0||l.length>0,z=Gl({disabled:s,running:i,canStop:i&&!!d,hasContent:q}),P=ql(o),Z=P.primary?Rn(P.primary.label):gs,U=i?q?"Enter queues this message for the next turn":d?"Task is running - type to queue, empty button stops task":"Task is running - type to queue a message":s?n:"Enter sends, Shift+Enter adds a line";return e.jsx("div",{"data-chat-input-shell":"true",className:"chat-input-shell animate-composer-settle w-full bg-background/35 px-2 pb-2 pt-0 sm:px-4 sm:pb-3",children:e.jsx("div",{"data-chat-input-column":"true",className:"mx-auto w-full max-w-[72rem]",children:e.jsxs("div",{"data-chat-input-card":"true",className:"chat-input-card overflow-hidden rounded-xl border border-border/65 bg-card/88 transition-[border-color,box-shadow] duration-200 focus-within:border-primary/50 focus-within:ring-2 focus-within:ring-primary/15 sm:rounded-xl",children:[e.jsx("input",{ref:T,type:"file",accept:"image/*",multiple:!0,onChange:_,className:"hidden"}),P.primary&&e.jsx("div",{"data-chat-input-primary-context":"true",className:"px-2.5 pt-1.5 sm:px-5 sm:pt-2",children:e.jsxs("div",{className:"-ml-1.5 inline-flex max-w-full items-center gap-1.5 rounded-sm bg-muted/45 px-1.5 py-0.5 shadow-[0_10px_28px_-18px_rgba(15,23,42,0.72)] sm:-ml-2 dark:shadow-[0_10px_28px_-18px_rgba(0,0,0,0.95)]",children:[e.jsx(Z,{className:"h-2.5 w-2.5 shrink-0 text-primary/45","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[9px] leading-3 text-muted-foreground/72",title:P.primary.value,children:P.primary.displayValue})]})}),l.length>0&&e.jsx("div",{className:"px-2 pt-2.5 sm:px-5 sm:pt-4",children:e.jsx("div",{className:"flex flex-wrap gap-3",children:l.map((R,B)=>e.jsxs("div",{className:"relative",children:[e.jsx(Da,{image:R,alt:R.filename??`attachment ${B+1}`,thumbnailClassName:"h-24 w-24 border border-border/70",imageClassName:"h-full w-full"}),e.jsx("button",{type:"button",onClick:()=>S(B),className:"absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${R.filename??`image ${B+1}`}`,children:e.jsx(Xe,{className:"h-3 w-3"})})]},`${R.filename??"image"}-${B}`))})}),e.jsx("div",{className:"px-2 pb-0 pt-1 sm:px-5 sm:pt-1.5",children:e.jsx("textarea",{ref:h,"data-chat-input-textarea":"true",value:c,onChange:R=>g(R.target.value),onKeyDown:C,onPaste:f,onInput:E,placeholder:r,disabled:s,rows:1,className:"min-h-[1.35rem] w-full resize-none overflow-x-hidden overflow-y-auto bg-transparent px-0 py-0 text-[11px] leading-[1.35rem] text-foreground placeholder:text-[10px] placeholder:text-muted-foreground/65 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50"})}),e.jsxs("div",{className:"flex items-end justify-between gap-2 px-2 pb-1.5 pt-0.5 sm:px-5 sm:pb-2.5",children:[P.secondary.length>0?e.jsx("div",{"data-chat-input-secondary-context":"true",className:"flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 pb-0.5 text-[9px] leading-3 text-muted-foreground/72 sm:text-[9px]",children:P.secondary.map(R=>{const B=Rn(R.label),ae=R.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${R.label}: ${R.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[ae?e.jsx(tn,{agent:R.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(B,{"data-chat-input-secondary-icon":"true",className:"h-2.5 w-2.5 shrink-0 text-primary/50","aria-hidden":"true"}),e.jsx("span",{className:`truncate ${R.mono?"font-mono":""}`,children:R.displayValue})]},`${R.label}:${R.value}`)})}):e.jsx("div",{className:"min-w-0 flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(W,{type:"button",variant:"ghost",onClick:w,disabled:s,className:"h-7 shrink-0 gap-1.5 rounded-sm px-2 text-[10px] text-muted-foreground hover:text-foreground sm:px-2",title:"Attach images",children:[e.jsx(zs,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:U,children:e.jsx(W,{onClick:z.primaryAction==="stop"?d:y,disabled:z.primaryDisabled,size:"icon","data-chat-send-button":"true","aria-label":z.primaryAction==="stop"?"Stop running task":i?"Queue message":"Send message",className:"chat-send-button h-7 w-9 shrink-0 rounded-sm bg-primary/90 text-primary-foreground shadow-[0_12px_30px_-18px_hsl(var(--primary)/0.95)] transition-transform duration-150 hover:bg-primary active:scale-95",children:z.primaryAction==="stop"?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ba,{className:`h-3.5 w-3.5 ${p>0?"animate-chat-send-flight":""}`},p)})})]})]}),N&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-2 py-2 text-[11px] text-destructive sm:px-6 sm:py-3",children:N})]})})})}var Zl=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ql=Zl.reduce((t,s)=>{const n=Xr(`Primitive.${s}`),r=a.forwardRef((o,i)=>{const{asChild:d,...c}=o,g=d?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(g,{...c,ref:i})});return r.displayName=`Primitive.${s}`,{...t,[s]:r}},{}),Xl="Label",Va=a.forwardRef((t,s)=>e.jsx(Ql.label,{...t,ref:s,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=t.onMouseDown)==null||o.call(t,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Va.displayName=Xl;var Ua=Va;const Jl=Jr("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Re=a.forwardRef(({className:t,...s},n)=>e.jsx(Ua,{ref:n,className:M(Jl(),t),...s}));Re.displayName=Ua.displayName;function ed(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function td(t){return t.trim()||"."}function sd(t){return new Promise(s=>window.setTimeout(s,t))}function nd(t){return!!t&&typeof t=="object"&&typeof t.createdBranch=="string"&&typeof t.currentBranch<"u"}async function ad(t){let s=t;for(let n=0;n<60;n++){if(s.status==="succeeded"){if(nd(s.result))return s.result;throw new Error("Branch creation completed without branch details")}if(s.status==="failed")throw new Error(s.error||"Branch creation failed");await sd(1e3),s=await so(s.id)}throw new Error("Timed out waiting for branch creation")}function $n({value:t,onChange:s,project:n,assignTo:r,nodes:o,assignableNodes:i,layout:d="default",chipClassName:c,chipActiveClassName:g,chipInactiveClassName:p,labelClassName:k,triggerClassName:h}){const[l,N]=a.useState(!1),[T,w]=a.useState(null),[_,f]=a.useState(""),[S,b]=a.useState(!1),[v,y]=a.useState(!1),[C,E]=a.useState(!1),[q,D]=a.useState(null),[z,P]=a.useState(""),[Z,U]=a.useState(""),[R,B]=a.useState(""),[ae,re]=a.useState(!1),oe=a.useRef(null),ne=a.useRef(0),L=a.useMemo(()=>ed(r,o,i),[r,o,i]),H=L==null?void 0:L.id,m=a.useMemo(()=>td(n),[n]),V=a.useMemo(()=>H?`${H}
|
|
163
|
-
${m}`:"",[H,m]),x=a.useCallback(async(X=0,$=!1)=>{const J=ne.current+1,de=V;if(ne.current=J,!H){w(null),f("");return}D(null),$||f(""),$?y(!0):b(!0);try{const O=await eo(H,{path:m,limit:20,offset:X,allowAbsolute:!0});if(J!==ne.current)return;f(de),w(ie=>$&&ie?{...O,branches:[...ie.branches,...O.branches]}:O)}catch(O){if(J!==ne.current)return;D(O instanceof Error?O.message:"Failed to load branch info"),$||(w(null),f(""))}finally{J===ne.current&&(b(!1),y(!1))}},[H,V,m]);a.useEffect(()=>{if(!H){ne.current+=1,w(null),f(""),D(null);return}x()},[H,m,x]),a.useEffect(()=>{const X=t.trim(),$=_===V?T:null,J=$!=null&&$.available&&$.currentBranch?$.currentBranch:"";X!==J&&s(J)},[T,V,_,s,t]),a.useEffect(()=>{if(!l)return;const X=J=>{oe.current&&(oe.current.contains(J.target)||N(!1))},$=J=>{J.key==="Escape"&&N(!1)};return document.addEventListener("mousedown",X),document.addEventListener("keydown",$),()=>{document.removeEventListener("mousedown",X),document.removeEventListener("keydown",$)}},[l]),a.useEffect(()=>{l&&(U(""),B(""),re(!1))},[l,H,m]);const Q=a.useCallback(async()=>{if(!H)return;const X=z.trim(),$=ae?R.trim():Z.trim();if(!(!X||!$)){E(!0),D(null);try{const J=await to(H,{path:m,branchName:X,startPoint:$,limit:20,offset:0,allowAbsolute:!0}),de=await ad(J);f(V),w(de),s(de.currentBranch??de.createdBranch),P(""),U(""),B(""),re(!1),N(!1)}catch(J){D(J instanceof Error?J.message:"Failed to create branch")}finally{E(!1)}}},[H,V,m,ae,R,z,s,Z]),A=_===V?T:null,G=a.useCallback(()=>{A!=null&&A.hasMore&&x(A.branches.length,!0)},[A,x]),j=t.trim()||(A==null?void 0:A.currentBranch)||(A&&!A.available?"No git repo":"Branch"),Y=ae?R.trim():Z.trim(),te=!!(A!=null&&A.available&&z.trim()&&Y&&!C),pe=d==="composer"?e.jsxs(W,{type:"button",variant:"ghost",onClick:()=>N(X=>!X),title:j,"aria-label":`Branch: ${j}`,className:M(c,h,"min-w-0 max-w-full",t.trim()?g:p),children:[S&&!A?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(ms,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:M("min-w-0 truncate",k),children:j})]}):e.jsxs(W,{type:"button",variant:"outline",onClick:()=>N(X=>!X),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:j,children:[e.jsx("span",{className:M("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:j}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:L?L.name:"Manual"})]});return e.jsxs("div",{className:M("relative inline-block",d==="composer"?"min-w-0 shrink-0":"w-full"),ref:oe,children:[d==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-[10px] font-medium",children:"Branch"}),pe]}):pe,l&&e.jsxs("div",{className:M("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-sm border border-border/60 bg-background/95 shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",d==="composer"?"left-0":"left-0 right-0 w-auto min-w-[240px]"),children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsx(ms,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-foreground",title:A!=null&&A.repoRoot?`${A.currentBranch??j} · ${A.repoRoot}`:(A==null?void 0:A.currentBranch)??j,children:(A==null?void 0:A.currentBranch)??j}),S?e.jsx(ue,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),L?S&&!A?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):A&&!A.available?e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Not a git repository."}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2 px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Qe,{value:z,onChange:X=>P(X.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(W,{type:"button",size:"sm",onClick:()=>void Q(),disabled:!te,title:te?"Create branch":"Enter a name and pick a base","aria-label":"Create branch",className:"h-8 w-8 shrink-0 rounded-sm p-0",children:C?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(gl,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Base from"}),!ae&&e.jsxs("button",{type:"button",onClick:()=>re(!0),className:"flex items-center gap-1 rounded-sm px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx(Lt,{className:"h-2.5 w-2.5"}),"Manual"]})]}),ae?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Qe,{value:R,onChange:X=>B(X.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{re(!1),B("")},className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel manual input","aria-label":"Cancel manual input",children:e.jsx(Xe,{className:"h-3.5 w-3.5"})})]}):A!=null&&A.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-sm border border-border/40 bg-background/40",children:[A.branches.map(X=>{const $=Z===X.ref,J=X.branch==="main"||X.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>U(X.ref),className:M("flex w-full items-center gap-2 border-b border-border/20 px-2.5 py-1.5 text-left text-[11px] last:border-b-0 hover:bg-background/60",$&&"bg-background/70"),title:X.ref,children:[e.jsx("span",{className:M("shrink-0 text-[10px]",J?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:J?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:X.ref}),$?e.jsx(Vt,{className:"h-3 w-3 shrink-0 text-primary"}):null]},X.ref)}),A.hasMore&&e.jsxs("button",{type:"button",onClick:G,disabled:v,className:"flex w-full items-center justify-center gap-1 border-t border-border/20 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[v?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Os,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"rounded-sm border border-dashed border-border/40 px-2.5 py-2 text-[11px] text-muted-foreground",children:"No remote branches found."})]})]})}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a specific node first."}),q&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:q})]})]})}const rd=20,od=3,Fs="meshy-working-dir-recents-by-node";function id(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function ld(t){const s=t.trim();return s||"."}function Vs(t){const s=[],n=new Set;for(const r of t){const o=r.trim();if(!(!o||n.has(o))&&(n.add(o),s.push(o),s.length===od))break}return s}function dd(t,s){const n=s.trim();return Vs(n?[n,...t]:t)}function Ha(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const s={};for(const[n,r]of Object.entries(t)){if(!n||!Array.isArray(r))continue;const o=r.filter(d=>typeof d=="string"),i=Vs(o);i.length>0&&(s[n]=i)}return s}function cd(t,s,n){if(!s)return t;const r=t[s]??[],o=dd(r,n);if(o.length===0){if(!(s in t))return t;const{[s]:i,...d}=t;return d}return{...t,[s]:o}}function ud(t,s){var n;return s?((n=t[s])==null?void 0:n[0])??"":""}function qa(t){if(!t||typeof window>"u")return"";try{const s=window.localStorage.getItem(Fs);return s?ud(Ha(JSON.parse(s)),t):""}catch{return""}}function md(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function xd(t,s){const n=s.trim();return n?id(n)||!t?n:`${t.replace(/[/\\]+$/,"")}/${n}`:""}function hd(t,s){return t?t.isAbsolute?t.currentPath:t.currentPath==="."||t.currentPath===""?t.rootPath||(s==null?void 0:s.workDir)||"Node root":t.currentPath:(s==null?void 0:s.workDir)??"Node root"}function hs({value:t,onChange:s,assignTo:n,nodes:r,assignableNodes:o,layout:i="default",chipClassName:d,chipActiveClassName:c,chipInactiveClassName:g,labelClassName:p,triggerClassName:k,popoverPlacement:h="bottom",popoverAlign:l="start"}){const[N,T]=a.useState(!1),[w,_]=a.useState(null),[f,S]=a.useState(!1),[b,v]=a.useState(!1),[y,C]=a.useState(null),[E,q]=a.useState(""),[D,z]=a.useState(!1),[P,Z]=a.useState({}),U=a.useRef(null),R=a.useMemo(()=>md(n,r,o),[n,r,o]),B=R==null?void 0:R.id,ae=a.useMemo(()=>B?P[B]??[]:[],[P,B]),re=a.useMemo(()=>t.trim()?xd(R==null?void 0:R.workDir,t):"Use node default",[t,R==null?void 0:R.workDir]);a.useEffect(()=>{if(!(typeof window>"u"))try{const j=window.localStorage.getItem(Fs);if(!j)return;const Y=JSON.parse(j);Z(Ha(Y))}catch{}},[]);const oe=a.useCallback(j=>{B&&Z(Y=>{const te=cd(Y,B,j);if(te===Y)return Y;if(typeof window<"u")try{window.localStorage.setItem(Fs,JSON.stringify(te))}catch{}return te})},[B]),ne=a.useCallback((j,Y=!0)=>{const te=j.trim();s(te),Y&&te&&oe(te),T(!1)},[s,oe]),L=a.useCallback(async(j,Y=0,te=!1)=>{if(B){C(null),te?v(!0):S(!0);try{const pe=await ba(B,{path:j,limit:rd,offset:Y,directoriesOnly:!0,allowAbsolute:!0});_(X=>te&&X?{...pe,entries:[...X.entries,...pe.entries]}:pe)}catch(pe){C(pe instanceof Error?pe.message:"Failed to browse directories"),te||_(null)}finally{S(!1),v(!1)}}},[B]),H=a.useRef(t);H.current=t;const m=a.useRef(L);m.current=L,a.useEffect(()=>{if(!N)return;const j=H.current;q(j),z(!1),_(null),C(null),B&&m.current(ld(j))},[N,B]),a.useEffect(()=>{if(!N)return;const j=te=>{U.current&&(U.current.contains(te.target)||T(!1))},Y=te=>{te.key==="Escape"&&T(!1)};return document.addEventListener("mousedown",j),document.addEventListener("keydown",Y),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",Y)}},[N]);const V=a.useCallback(j=>{L(j)},[L]),x=a.useCallback(()=>{w&&L(w.currentPath,w.entries.length,!0)},[w,L]),Q=i==="composer"?e.jsxs(W,{type:"button",variant:"ghost",onClick:()=>T(j=>!j),title:re,"aria-label":`Working directory: ${re}`,className:M(d,k,"min-w-0 max-w-full",t.trim()?c:g),children:[e.jsx(no,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:M("min-w-0 truncate",p),children:re})]}):e.jsxs(W,{type:"button",variant:"outline",onClick:()=>T(j=>!j),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:re,children:[e.jsx("span",{className:M("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:re}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:R?R.name:"Manual"})]}),A=hd(w,R),G=!!(w!=null&&w.parentPath);return e.jsxs("div",{className:M("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":h,"data-workdir-popover-align":l,ref:U,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-[10px] font-medium",children:"Working directory"}),Q]}):Q,N&&e.jsxs("div",{className:M("absolute z-50 flex max-h-[min(28rem,calc(100vh-5rem))] w-[240px] flex-col overflow-hidden rounded-sm border border-border/60 bg-background/95 shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",h==="top"?"bottom-full mb-2":"top-full mt-2",i==="composer"?l==="end"?"right-0":"left-0":l==="end"?"right-0 w-auto min-w-[240px]":"left-0 right-0 w-auto min-w-[240px]"),children:[ae.length>0&&e.jsxs("div",{className:"border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx(Os,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:ae.map(j=>e.jsx("button",{type:"button",onClick:()=>ne(j),className:"truncate rounded-sm px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:j,children:j},j))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border/60 px-2.5 py-1.5",children:[e.jsx("button",{type:"button",onClick:()=>(w==null?void 0:w.parentPath)&&V(w.parentPath),disabled:!G||f,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-sm border border-border/60 text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(Pa,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:A,children:A}),w&&e.jsx("button",{type:"button",onClick:()=>ne(w.isAbsolute?w.currentPath:w.currentPath==="."?"":w.currentPath),className:"shrink-0 rounded-sm px-1.5 py-0.5 text-[10px] font-medium text-foreground hover:bg-background/60",title:"Use this folder",children:"Use"})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[R?f?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):w&&w.entries.length>0?e.jsxs(e.Fragment,{children:[w.entries.map(j=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ne(j.path),className:"flex min-w-0 flex-1 items-center gap-2 px-2.5 py-1.5 text-left hover:bg-background/55",title:`Use ${j.path}`,children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:j.name})]}),e.jsx("button",{type:"button",onClick:()=>V(j.path),className:"flex w-9 shrink-0 items-center justify-center border-l border-border/30 text-muted-foreground hover:bg-background/70 hover:text-foreground",title:"Open subfolder","aria-label":`Open ${j.name}`,children:e.jsx(Fe,{className:"h-3.5 w-3.5"})})]},j.path)),w.hasMore&&e.jsxs("button",{type:"button",onClick:x,disabled:b,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[b?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Os,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:y??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),y&&w&&w.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:y})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:D?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{value:E,onChange:j=>q(j.target.value),onKeyDown:j=>{j.key==="Enter"&&E.trim()?(j.preventDefault(),ne(E)):j.key==="Escape"&&(j.preventDefault(),z(!1),q(t))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>ne(E),disabled:!E.trim(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-foreground hover:bg-background/60 disabled:opacity-40",title:"Apply","aria-label":"Apply manual path",children:e.jsx(Vt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{z(!1),q(t)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(Xe,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{q(t),z(!0)},className:"flex h-7 flex-1 items-center justify-between rounded-sm px-1.5 text-[11px] text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Enter a manual path",children:[e.jsx("span",{children:"Manual input"}),e.jsx(Lt,{className:"h-3 w-3"})]})})]})]})}function Ka(t,s={}){const n=t.filter(r=>r.status==="online");return s.currentNodeRole!=="follower"||!s.leaderNodeId?n:n.filter(r=>r.id!==s.leaderNodeId)}function an({isCurrent:t}){return t?e.jsx(dl,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(rl,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function Us(t,s){return t.map(n=>{const r=!!s&&n.id===s;return e.jsx(he,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(an,{isCurrent:r}),e.jsx("span",{className:"truncate",children:n.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:r?"current":"remote"})]})},n.id)})}function pd(t){var r;const s=t.sessionId.trim(),n=t.cwd.trim();return!s||!n||!t.assignTo?null:{title:t.title.trim()||((r=t.defaultTitle)==null?void 0:r.trim())||void 0,agent:t.agent,sessionId:s,cwd:n,assignTo:t.assignTo,priority:t.priority,mode:t.mode??Ut}}function fd(){return oo.map(t=>e.jsx(he,{value:t.value,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:t.label}),t.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:t.description})]})},t.value))}function gd(t){if(!t)return"unknown time";const s=Date.parse(t);return Number.isNaN(s)?t:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(s)}function On(t){if(!t.updatedAt)return 0;const s=Date.parse(t.updatedAt);return Number.isNaN(s)?0:s}function bd(t,s){return On(s)-On(t)||t.sessionId.localeCompare(s.sessionId)}function vd(t){const s=t.trim().replace(/[\\/]+$/,"");return s?s.split(/[\\/]+/).filter(Boolean).at(-1)??s:"Unknown project"}function jd(t){const s=new Map;for(const n of[...t].sort(bd)){const r=s.get(n.cwd);if(r){r.push(n);continue}s.set(n.cwd,[n])}return Array.from(s.entries()).map(([n,r])=>({folderName:vd(n),cwd:n,sessions:r}))}function wd(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function yd({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:o,onCancel:i,className:d,footerClassName:c,submitLabel:g="Load session",cancelLabel:p="Cancel",autoFocus:k=!1}){const h=a.useMemo(()=>Ka(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),l=a.useMemo(()=>{var O;return n&&h.some(ie=>ie.id===n)?n:((O=h[0])==null?void 0:O.id)??""},[h,n]),[N,T]=a.useState(""),[w,_]=a.useState("codex"),[f,S]=a.useState(""),[b,v]=a.useState(""),[y,C]=a.useState(""),[E,q]=a.useState(l),[D,z]=a.useState("normal"),[P,Z]=a.useState(Ut),[U,R]=a.useState(!1),[B,ae]=a.useState([]),[re,oe]=a.useState(!1),[ne,L]=a.useState(null),H=a.useMemo(()=>B.find(O=>O.sessionId===f)??null,[B,f]);a.useEffect(()=>{E&&h.some(O=>O.id===E)||q(l)},[E,h,l]),a.useEffect(()=>{S(""),v(""),C("")},[w,E]),a.useEffect(()=>{let O=!1;return E?(oe(!0),L(null),ao(E,{agent:w,limit:50}).then(ie=>{O||ae(ie.sessions)}).catch(ie=>{O||(ae([]),L(ie instanceof Error?ie.message:"Failed to load native sessions"))}).finally(()=>{O||oe(!1)}),()=>{O=!0}):(ae([]),L(null),oe(!1),()=>{O=!0})},[w,E]),a.useEffect(()=>{H&&(v(H.sessionId),C(H.cwd))},[H]);const m=a.useCallback(async O=>{O.preventDefault();const ie=pd({title:N,defaultTitle:H==null?void 0:H.summary,agent:w,sessionId:b,cwd:y,assignTo:E,priority:D,mode:P});if(ie){R(!0);try{const Ne=await ro(ie);o(Ne)}catch(Ne){le.error(Ne instanceof Error?Ne.message:"Failed to load native session")}finally{R(!1)}}},[N,H,w,b,y,E,D,P,o]),V=!!(b.trim()&&y.trim()&&E),[x,Q]=a.useState(!1),[A,G]=a.useState(""),[j,Y]=a.useState(()=>new Set),te=h.find(O=>O.id===E)??null,pe=!!(n&&(te==null?void 0:te.id)===n),X=a.useMemo(()=>{const O=A.trim().toLowerCase();return O?B.filter(ie=>ie.summary.toLowerCase().includes(O)||ie.sessionId.toLowerCase().includes(O)||ie.cwd.toLowerCase().includes(O)):B},[B,A]),$=a.useMemo(()=>jd(X),[X]),J=a.useCallback(O=>{Y(ie=>wd(ie,O))},[]),de="h-9 w-auto gap-1.5 rounded-sm border-border/60 bg-background/60 px-3 text-xs shadow-none transition-colors hover:bg-background/80";return e.jsxs("form",{onSubmit:m,className:M("space-y-4",d),children:[e.jsxs("div",{className:"rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/50 px-3 py-2.5",children:[e.jsxs(Se,{value:E,onValueChange:q,children:[e.jsx(Ce,{className:M(de),"aria-label":"Node",children:te?e.jsxs(e.Fragment,{children:[e.jsx(an,{isCurrent:pe}),e.jsx("span",{className:"max-w-[10rem] truncate",children:te.name})]}):e.jsx(Le,{placeholder:"Node"})}),e.jsx(_e,{children:Us(h,n)})]}),e.jsxs(Se,{value:w,onValueChange:O=>_(O),children:[e.jsxs(Ce,{className:M(de),"aria-label":"Agent",children:[e.jsx(tn,{agent:w}),e.jsx("span",{children:w})]}),e.jsx(_e,{children:Ni()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(va,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(Qe,{value:A,onChange:O=>G(O.target.value),placeholder:"Filter sessions",className:"h-9 rounded-sm border-border/60 bg-background/60 pl-9 text-xs shadow-none"})]})]}),e.jsxs("div",{className:"px-3 py-3",children:[e.jsx("div",{className:"flex items-center justify-between px-1 pb-2",children:e.jsx(Re,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:re?"Loading...":`${X.length} session${X.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-sm",children:[re&&e.jsx("div",{className:"absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden bg-primary/10",children:e.jsx("div",{className:"h-full w-1/3 animate-indeterminate-bar bg-primary/70"})}),e.jsxs("div",{className:"h-full space-y-1.5 overflow-y-auto pr-1",children:[!E&&e.jsx("div",{className:"rounded-sm border border-dashed border-border/60 bg-background/35 px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Pick a node to load its recent sessions."}),E&&!re&&X.length===0&&e.jsx("div",{className:"rounded-sm border border-dashed border-border/60 bg-background/35 px-3 py-4 text-center text-[11px] text-muted-foreground",children:B.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),$.map(O=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>J(O.cwd),"aria-expanded":!j.has(O.cwd),className:"sticky top-0 z-[1] flex w-full items-center gap-2 border-b border-border/50 bg-background/95 px-1 py-1.5 text-left text-[10px] text-muted-foreground backdrop-blur transition-colors hover:bg-background",children:[e.jsx(Je,{className:M("h-3.5 w-3.5 shrink-0 transition-transform",j.has(O.cwd)&&"-rotate-90")}),e.jsx(gs,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:O.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[O.sessions.length," session",O.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:O.cwd})]}),!j.has(O.cwd)&&O.sessions.map(ie=>{const Ne=ie.sessionId===f;return e.jsxs("button",{type:"button",onClick:()=>S(ie.sessionId),className:M("flex w-full flex-col gap-1 rounded-sm border px-2.5 py-2 text-left transition-colors duration-200",Ne?"border-primary/45 bg-primary/9 shadow-none":"border-border/55 bg-background/40 hover:border-border hover:bg-background/65"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:M("h-2 w-2 shrink-0 rounded-full",Ne?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:ie.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:gd(ie.updatedAt)})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-4 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"font-mono",children:ie.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:ie.cwd})]})]},ie.sessionId)})]},O.cwd))]})]}),ne&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:ne})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>Q(O=>!O),className:"inline-flex h-6 items-center gap-1.5 rounded-sm px-1.5 text-[10px] font-medium uppercase tracking-[0.16em] text-muted-foreground transition-colors hover:bg-muted/45 hover:text-foreground","aria-expanded":x,children:[e.jsx("span",{className:"shrink-0",children:x?"Less options":"More options"}),e.jsx(Je,{className:M("h-3.5 w-3.5 shrink-0 transition-transform",x&&"rotate-180")})]}),x&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/30 p-2.5",children:[e.jsxs("div",{className:"grid gap-2.5 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Re,{htmlFor:"native-session-id",className:"text-[10px] font-medium text-muted-foreground",children:"Session ID"}),e.jsx(Qe,{id:"native-session-id",type:"text",value:b,onChange:O=>{S(""),v(O.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:k,className:"h-7 rounded-sm border-border/70 bg-background/70 font-mono text-[11px] shadow-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Re,{htmlFor:"native-session-title",className:"text-[10px] font-medium text-muted-foreground",children:"Task title"}),e.jsx(Qe,{id:"native-session-title",type:"text",value:N,onChange:O=>T(O.target.value),placeholder:"Optional",className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none"})]})]}),e.jsx(hs,{value:y,onChange:O=>{S(""),C(O)},assignTo:E,nodes:t,assignableNodes:h}),e.jsxs("div",{className:"grid gap-2.5 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Re,{className:"text-[10px] font-medium text-muted-foreground",children:"Mode"}),e.jsxs(Se,{value:P,onValueChange:O=>Z(O),children:[e.jsx(Ce,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx(Le,{placeholder:"Select mode"})}),e.jsx(_e,{children:fd()})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Re,{className:"text-[10px] font-medium text-muted-foreground",children:"Priority"}),e.jsxs(Se,{value:D,onValueChange:z,children:[e.jsx(Ce,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx(Le,{placeholder:"Select priority"})}),e.jsxs(_e,{children:[e.jsx(he,{value:"low",children:"Low"}),e.jsx(he,{value:"normal",children:"Normal"}),e.jsx(he,{value:"high",children:"High"}),e.jsx(he,{value:"critical",children:"Critical"})]})]})]})]})]})]}),e.jsxs("div",{className:M("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",c),children:[i&&e.jsx(W,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:p}),e.jsx(W,{type:"submit",disabled:!V||U,className:"rounded-sm px-5",children:U?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"})," Loading..."]}):g})]})]})}function Ga(t,s,n=!1){const r=t.trim();if(r)return r;const o=s.trim().split(`
|
|
164
|
-
`).map(i=>i.trim()).find(Boolean);return o?o.length>72?`${o.slice(0,69).trimEnd()}...`:o:n?"Image task":""}function Nd(t){var d;const s=t.title.trim(),n=Ga(t.title,t.description,t.images.length>0),r=t.description.trim()||n,o=t.mode??Ut,i=Ea(t.description,t.images);return!n||!r||!t.agent?null:{title:n,description:r,agent:t.agent,project:t.project.trim()||null,branch:((d=t.branch)==null?void 0:d.trim())||null,payload:{initialMessage:i,mode:o,titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function kd({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,className:g,footerClassName:p,submitLabel:k="Create chat",cancelLabel:h="Cancel",autoFocus:l=!1,layout:N="default"}){const[T,w]=a.useState(""),[_,f]=a.useState(""),[S,b]=a.useState(yn),[v,y]=a.useState(Ut),[C,E]=a.useState((i==null?void 0:i.trim())??""),q=a.useRef(i!==void 0),[D,z]=a.useState(""),[P,Z]=a.useState("normal"),U=a.useMemo(()=>Ka(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),R=a.useMemo(()=>{var ee;return o&&U.some(je=>je.id===o)?o:n&&U.some(je=>je.id===n)?n:((ee=U[0])==null?void 0:ee.id)??""},[U,n,o]),[B,ae]=a.useState(R),[re,oe]=a.useState(!1),[ne,L]=a.useState(!1),{images:H,error:m,fileInputRef:V,pickImages:x,handleFileChange:Q,handlePaste:A,removeImage:G}=Fa(),j=a.useMemo(()=>U.find(ee=>ee.id===B)??null,[B,U]),Y=!!(n&&(j==null?void 0:j.id)===n),te=Aa(S),pe=ki(v);a.useEffect(()=>{B&&U.some(ee=>ee.id===B)||ae(R)},[B,U,R]),a.useEffect(()=>{if(q.current){q.current=!1;return}E(qa(B)),z("")},[B]),a.useEffect(()=>{z("")},[C]);const X=a.useCallback(async ee=>{ee.preventDefault();const je=Nd({title:T,description:_,agent:S,project:C,branch:D,priority:P,assignTo:B,mode:v,images:H});if(je){oe(!0);try{const Ee=await lo(je);d(Ee)}catch(Ee){le.error(Ee instanceof Error?Ee.message:"Failed to create task")}finally{oe(!1)}}},[T,_,S,C,D,P,B,v,H,d]),$=Ga(T,_,H.length>0),J=!!($&&S&&B&&(_.trim()||H.length>0)),de=a.useCallback(ee=>{var je;ee.nativeEvent.isComposing||ee.key==="Enter"&&(ee.ctrlKey||ee.metaKey)&&J&&!re&&(ee.preventDefault(),(je=ee.currentTarget.form)==null||je.requestSubmit())},[J,re]),O=H.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:H.map((ee,je)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Si(ee),alt:ee.filename??`attachment ${je+1}`,className:"h-20 w-20 rounded-sm border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>G(je),className:"absolute -top-2 -right-2 flex h-6 w-6 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${ee.filename??`image ${je+1}`}`,children:e.jsx(Xe,{className:"h-3.5 w-3.5"})})]},`${ee.filename??"image"}-${je}`))}),ie=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-[11px] font-medium",children:"Assign to"}),e.jsxs(Se,{value:B,onValueChange:ae,children:[e.jsx(Ce,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Le,{placeholder:"Select node"})}),e.jsx(_e,{children:Us(U,n)})]})]}),Ne=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-[11px] font-medium",children:"Agent"}),e.jsxs(Se,{value:S,onValueChange:b,children:[e.jsx(Ce,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Le,{placeholder:"Select agent"})}),e.jsx(_e,{children:Dn()})]})]}),Te=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-[11px] font-medium",children:"Mode"}),e.jsxs(Se,{value:v,onValueChange:ee=>y(ee),children:[e.jsx(Ce,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Le,{placeholder:"Select mode"})}),e.jsx(_e,{children:An()})]})]}),ct=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-[11px] font-medium",children:"Priority"}),e.jsxs(Se,{value:P,onValueChange:Z,children:[e.jsx(Ce,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Le,{placeholder:"Select priority"})}),e.jsxs(_e,{children:[e.jsx(he,{value:"low",children:"Low"}),e.jsx(he,{value:"normal",children:"Normal"}),e.jsx(he,{value:"high",children:"High"}),e.jsx(he,{value:"critical",children:"Critical"})]})]})]}),et=e.jsx(hs,{value:C,onChange:E,assignTo:B,nodes:t,assignableNodes:U}),Ae=e.jsx($n,{value:D,onChange:z,project:C,assignTo:B,nodes:t,assignableNodes:U});return N==="composer"?e.jsxs("form",{onSubmit:X,className:M("space-y-4",g),children:[e.jsx("input",{ref:V,type:"file",accept:"image/*",multiple:!0,onChange:Q,className:"hidden"}),(()=>{const ee="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",je="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",Ee="border-border/70 bg-background/55 text-foreground",Pe=S===yn,Oe=v===Ut;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"chat-composer__card rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",children:[e.jsxs("div",{className:"chat-composer__header flex min-w-0 items-center justify-between gap-3 px-4 pt-3",children:[e.jsxs(Se,{value:B,onValueChange:ae,children:[e.jsx(Ce,{className:M(ee,Ee,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${(j==null?void 0:j.name)??"unassigned"}`,"aria-label":`Assigned node: ${(j==null?void 0:j.name)??"unassigned"}`,children:j?e.jsxs(e.Fragment,{children:[e.jsx(an,{isCurrent:Y}),e.jsx("span",{className:"min-w-0 truncate",children:j.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:Y?"current":"remote"})]}):e.jsx(Le,{placeholder:"Select node"})}),e.jsx(_e,{children:Us(U,n)})]}),ne?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Qe,{id:"task-title-composer",type:"text",value:T,onChange:we=>w(we.target.value),onKeyDown:we=>{(we.key==="Enter"||we.key==="Escape")&&(we.preventDefault(),L(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(W,{type:"button",variant:"ghost",size:"icon",onClick:()=>L(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Vt,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>L(!0),className:"chat-composer__title-button flex min-w-0 items-center gap-1.5 rounded-sm px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-background/55 hover:text-foreground",title:$||"Title","aria-label":$?`Edit title: ${$}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:$||"Title"}),e.jsx(Lt,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:_,onChange:we=>f(we.target.value),onKeyDown:de,onPaste:A,placeholder:"Ask anything...",rows:4,autoFocus:l,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm bg-transparent px-5 pt-2 pb-2 text-xs leading-5 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsxs("div",{className:"chat-composer__rail flex flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(W,{type:"button",variant:"ghost",size:"icon",onClick:x,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(zs,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(Se,{value:S,onValueChange:b,children:[e.jsxs(Ce,{className:M(ee,"chat-composer__icon-trigger",Pe?je:Ee),title:`Agent: ${te}`,"aria-label":`Agent: ${te}`,children:[e.jsx(tn,{agent:S}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:te})]}),e.jsx(_e,{children:Dn()})]}),e.jsxs(Se,{value:v,onValueChange:we=>y(we),children:[e.jsxs(Ce,{className:M(ee,"chat-composer__icon-trigger",Oe?je:Ee),title:`Mode: ${pe}`,"aria-label":`Mode: ${pe}`,children:[e.jsx(kl,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:pe})]}),e.jsx(_e,{children:An()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(Se,{value:P,onValueChange:Z,children:[e.jsx(Ce,{"aria-label":`Priority: ${P}`,title:`Priority: ${P}`,className:M("h-9 w-9 justify-center gap-0 rounded-sm p-0 text-xs shadow-none [&>svg:last-child]:hidden",P==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",P==="critical"&&"text-destructive",P==="high"&&"text-amber-600 dark:text-amber-400",P==="low"&&"text-muted-foreground"),children:e.jsx(Ji,{className:M("h-4 w-4",P==="critical"&&"fill-destructive/20")})}),e.jsxs(_e,{children:[e.jsx(he,{value:"low",children:"Low"}),e.jsx(he,{value:"normal",children:"Normal"}),e.jsx(he,{value:"high",children:"High"}),e.jsx(he,{value:"critical",children:"Critical"})]})]}),c&&e.jsxs(W,{type:"button",variant:"ghost",size:"sm",onClick:c,"aria-label":h,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(Xe,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:h})]}),e.jsxs(W,{type:"submit",size:"icon",disabled:!J||re,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[re?e.jsx(ue,{className:"h-4 w-4 animate-spin"}):e.jsx(Ba,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:re?"Creating chat":k})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const we="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(hs,{value:C,onChange:E,assignTo:B,nodes:t,assignableNodes:U,layout:"composer",chipClassName:ee,chipActiveClassName:we,chipInactiveClassName:we,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx($n,{value:D,onChange:z,project:C,assignTo:B,nodes:t,assignableNodes:U,layout:"composer",chipClassName:ee,chipActiveClassName:we,chipInactiveClassName:we,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(O||m)&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/45 p-2.5",children:[O,m&&e.jsx("div",{className:"text-[11px] text-destructive",children:m}),!m&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Ctrl/Cmd+Enter starts the chat. Enter adds a new line. Paste screenshots directly into the prompt box or use the Images button."})]})]}):e.jsxs("form",{onSubmit:X,className:M("space-y-4",g),children:[e.jsx("input",{ref:V,type:"file",accept:"image/*",multiple:!0,onChange:Q,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{htmlFor:"task-description",className:"text-[11px] font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:_,onChange:ee=>f(ee.target.value),onKeyDown:de,onPaste:A,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:l,className:"flex min-h-[128px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm border border-border/70 bg-background/70 px-3 py-2 text-xs leading-5 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(W,{type:"button",variant:"outline",onClick:x,className:"rounded-sm",children:[e.jsx(zs,{className:"h-4 w-4"}),"Add images"]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Ctrl/Cmd+Enter starts the chat. Enter adds a new line. Upload or paste screenshots and reference images with the opening prompt."})]}),O,m&&e.jsx("p",{className:"text-[11px] text-destructive",children:m})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_190px_190px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{htmlFor:"task-title",className:"text-[11px] font-medium",children:"Chat title"}),e.jsx(Qe,{id:"task-title",type:"text",value:T,onChange:ee=>w(ee.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-8 rounded-sm border-border/70 bg-background/70"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:$?`Will appear as: ${$}`:"A title will be generated from the first line of the prompt."})]}),Ne,Te]}),et,Ae,e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[ct,ie]}),e.jsxs("div",{className:M("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",p),children:[c&&e.jsx(W,{type:"button",variant:"ghost",onClick:c,className:"rounded-sm",children:h}),e.jsx(W,{type:"submit",disabled:!J||re,className:"rounded-sm px-5",children:re?"Creating...":k})]})]})}function Sd({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,defaultMode:g="chat",mode:p,onModeChange:k,layout:h="default",className:l,footerClassName:N,autoFocus:T=!1}){const[w,_]=a.useState(g),f=p!==void 0,S=f?p:w,b=v=>{f||_(v),k==null||k(v)};return e.jsxs("div",{className:M("space-y-4",l),children:[!f&&e.jsxs("div",{className:"flex h-8 items-center gap-0.5 rounded-sm border border-border/60 bg-background/45 p-0.5",children:[e.jsxs(W,{type:"button",variant:S==="chat"?"default":"ghost",onClick:()=>b("chat"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(io,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(W,{type:"button",variant:S==="native"?"default":"ghost",onClick:()=>b("native"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(sn,{className:"h-4 w-4"}),"Load session"]})]}),S==="chat"?e.jsx(kd,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,footerClassName:N,submitLabel:h==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:T,layout:h},`${o??""}:${i??""}`):e.jsx(yd,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:d,onCancel:c,footerClassName:N,autoFocus:T})]})}function Cd({onClick:t,running:s}){return e.jsxs(W,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:M("absolute bottom-4 right-4 z-10 h-12 w-12 overflow-visible rounded-lg shadow-lg",s&&"animate-soft-status-pulse bg-primary/90 text-primary-foreground hover:bg-primary"),children:[e.jsx(Lt,{className:"h-4 w-4"}),s&&e.jsx("span",{"aria-hidden":"true","data-running-indicator":"true",className:"pointer-events-none absolute right-1.5 top-1.5 h-2 w-2 rounded-full bg-primary-foreground shadow-[0_0_0_2px_hsl(var(--primary))]"})]})}function zn({children:t}){return e.jsxs("div",{className:"agent-progress-banner animate-message-receive flex items-center gap-1.5 rounded-lg bg-transparent px-1 py-1 text-[11px]",children:[e.jsx("span",{className:"agent-progress-terminal-spinner h-4 w-4 shrink-0","aria-hidden":"true"}),e.jsx("div",{className:"agent-progress-sweep-text min-w-0 leading-5",children:t})]})}function _d({hasVisibleTranscriptEvents:t,hasTranscriptProgress:s,inputCollapsed:n}){return{collapsedButtonRunning:s&&t&&n,showDockedProgress:s&&t&&!n,showInlineProgress:s&&!t}}const _t="72f988bf-86f1-41af-91ab-2d7cd011db47",Wa=`${_t} (MSIT)`;function Td({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:o,stopping:i=!1,shareResult:d}){return e.jsx(Mt,{open:t,onOpenChange:s,children:e.jsxs(Pt,{className:"max-w-md rounded-sm p-4",children:[e.jsx(Gt,{className:"sr-only",children:"Share conversation"}),e.jsx(Ed,{onOpenChange:s,onShare:n,onStopShare:r,sharing:o,stopping:i,shareResult:d})]})})}function Ed({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:o=!1,shareResult:i}){const[d,c]=a.useState((i==null?void 0:i.tenant)??_t),[g,p]=a.useState((i==null?void 0:i.scope)??"chat"),k=i!=null&&i.url?ja(i.url):null,h=r||o;return a.useEffect(()=>{c((i==null?void 0:i.tenant)??_t),p((i==null?void 0:i.scope)??"chat")},[i==null?void 0:i.shareId,i==null?void 0:i.tenant,i==null?void 0:i.scope]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-sm font-semibold leading-none tracking-tight",children:"Share conversation"}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:"Create a tenant-gated link for this task."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Dd,{value:d,onChange:c,disabled:h}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Access"}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(Fn,{active:g==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>p("chat")}),e.jsx(Fn,{active:g==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>p("filesPreview")})]})]}),k&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Shared link"}),e.jsxs("div",{className:"flex items-center gap-2 rounded-sm border border-border/70 bg-muted/30 px-3 py-2",children:[e.jsx("input",{readOnly:!0,value:k,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(W,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void Ct(k,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(wa,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e.jsx(W,{variant:"outline",onClick:()=>t(!1),disabled:h,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(W,{variant:"outline",onClick:()=>void n(),disabled:h,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[o&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(W,{onClick:()=>void s({tenant:d,scope:g}),disabled:h,className:"h-8 text-xs",children:[r&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function Dd({value:t,onChange:s,disabled:n}){const[r,o]=a.useState(!1),[i,d]=a.useState(!1),[c,g]=a.useState(t),p=a.useRef(null);a.useEffect(()=>{g(t)},[t]),a.useEffect(()=>{if(!r)return;const h=N=>{var w;const T=N.target;T instanceof Node&&((w=p.current)!=null&&w.contains(T)||(o(!1),d(!1)))},l=N=>{N.key==="Escape"&&(o(!1),d(!1))};return document.addEventListener("mousedown",h),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",l)}},[r]);const k=h=>{const l=h.trim();l&&(s(l),g(l),d(!1),o(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:p,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&o(h=>!h),disabled:n,className:"flex h-9 w-full items-center justify-between gap-2 rounded-sm border border-border/70 bg-background/70 px-3 text-left text-xs text-foreground shadow-sm outline-none transition-colors hover:bg-background disabled:opacity-50",children:[e.jsx("span",{className:"min-w-0 truncate font-mono",children:Ad(t)}),e.jsx(Je,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),r&&e.jsxs("div",{className:"absolute left-0 right-0 z-50 mt-2 overflow-hidden rounded-sm border border-border/60 bg-background/95 text-xs shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",children:[e.jsxs("button",{type:"button",onClick:()=>k(_t),className:"flex w-full items-center justify-between gap-2 px-3 py-2 text-left hover:bg-background/60",children:[e.jsx("span",{className:"min-w-0 truncate font-mono text-[11px]",children:Wa}),t===_t&&e.jsx(Vt,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]}),e.jsx("div",{className:"border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:i?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:c,onChange:h=>g(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),k(c))},autoFocus:!0,placeholder:"Tenant ID",className:"h-7 min-w-0 flex-1 rounded-sm border border-border/60 bg-background/70 px-2 font-mono text-[11px] outline-none focus:ring-2 focus:ring-ring"}),e.jsx("button",{type:"button",onClick:()=>k(c),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(Vt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{g(t),d(!1)},className:"flex h-7 w-7 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",children:e.jsx(Xe,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>d(!0),className:"flex h-7 w-full items-center justify-between rounded-sm px-1.5 text-[11px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx("span",{children:"Manual tenant ID"}),e.jsx(Lt,{className:"h-3 w-3"})]})})]})]})]})}function Ad(t){return t===_t?Wa:t}function Fn({active:t,title:s,description:n,onClick:r}){return e.jsxs("button",{type:"button",onClick:r,className:t?"rounded-sm border border-primary/45 bg-primary/10 px-3 py-2 text-left shadow-sm":"rounded-sm border border-border/70 bg-background px-3 py-2 text-left shadow-sm hover:bg-muted/50",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:s}),e.jsx("div",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:n})]})}function Md(t){const s=t.map(n=>n.type==="text"?n.text:n.type==="image"?n.filename?`Image: ${n.filename}`:"Image attachment":n.isError?`Tool result error: ${n.content}`:`Tool result: ${n.content}`).join(" ").replace(/\s+/g," ").trim();return s?s.length>160?`${s.slice(0,157)}...`:s:"Queued follow-up"}function Pd({messages:t,onCancelMessage:s}){return t.length===0?null:e.jsx("div",{className:"border-t border-border/55 bg-card/30 px-3 py-2 sm:px-5",children:e.jsxs("div",{className:"mx-auto max-w-[72rem] rounded-sm border border-border/65 bg-background/58 px-3 py-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-medium text-foreground",children:[e.jsx(ml,{className:"h-3.5 w-3.5 text-primary"}),"Queued messages",e.jsx("span",{className:"ml-auto rounded-sm border border-border/60 bg-muted/60 px-1.5 py-0 text-[10px] text-muted-foreground",children:t.length})]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:t.map((n,r)=>{const o=n.content.filter(i=>i.type==="image");return e.jsxs("div",{className:"flex min-w-0 items-start gap-2 text-[11px] leading-5 text-muted-foreground",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-[10px] font-medium text-primary",children:r+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"break-words [overflow-wrap:anywhere]",children:Md(n.content)}),o.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:o.map((i,d)=>e.jsx(Da,{image:i,alt:i.filename??`queued attachment ${d+1}`,thumbnailClassName:"h-14 w-14 border border-border/65",imageClassName:"h-full w-full"},`${i.filename??"image"}-${d}`))})]}),s&&e.jsx(W,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground hover:text-destructive",title:"Cancel queued message","aria-label":"Cancel queued message",onClick:()=>s(n.id),children:e.jsx(Xe,{className:"h-3 w-3"})})]},n.id)})})]})})}const Ld="h-6 w-6 rounded-none border-b border-transparent !bg-transparent p-0 text-muted-foreground !shadow-none hover:text-foreground data-[state=active]:border-primary data-[state=active]:!bg-transparent data-[state=active]:text-primary data-[state=active]:!shadow-none",Id=[{value:"transcript",label:"Transcript",icon:Ci},{value:"files",label:"Files",icon:At,activeIcon:gs},{value:"diff",label:"Diff",icon:ms},{value:"preview",label:"Preview",icon:Bi}];function Bd({activeTab:t}){return e.jsx(Ws,{className:"h-auto max-w-full justify-start gap-2 overflow-x-auto rounded-sm !bg-muted/40 !p-0.5 !shadow-none",children:Id.map(s=>{const n=s.value===t&&s.activeIcon?s.activeIcon:s.icon;return e.jsx(bt,{value:s.value,title:s.label,"aria-label":s.label,className:Ld,children:e.jsx(n,{className:"h-3.5 w-3.5","aria-hidden":"true"})},s.value)})})}const Vn="h-[1.625rem] rounded-sm !border-0 !bg-transparent px-2 text-[10.5px] font-medium text-primary !shadow-none hover:!bg-transparent hover:text-primary/80 focus-visible:ring-1 focus-visible:ring-ring/50 focus-visible:ring-offset-0",gt={content:"max-w-[20rem] gap-2.5 rounded-lg border-0 p-3.5 shadow-[0_18px_70px_-44px_rgba(0,0,0,0.72)] sm:max-w-[20rem]",header:"space-y-1 text-left",title:"text-[13px] leading-4",description:"text-[11px] leading-4",footer:"gap-1 pt-0 sm:space-x-1",cancel:`${Vn} mt-0`,action:Vn},Rd=30,$d=1600;function Od({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Ds(t){return t.scrollHeight-t.scrollTop-t.clientHeight<Rd}function Un({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function zd({atTop:t,inputCollapseDisabled:s,scrollingUp:n}){return!s&&(n||t)}function Fd({activeTab:t,activeTaskId:s,contentVersion:n,inputCollapseDisabled:r=!1,setActiveTab:o,setInputCollapsed:i}){const d=a.useRef(null),c=a.useRef(s),g=a.useRef(!1),p=a.useRef(0),k=a.useRef(new Map),h=a.useRef(0),l=a.useRef(!0),N=a.useCallback((b=c.current)=>{const v=d.current;!v||!b||(k.current.set(b,v.scrollTop),p.current=v.scrollTop,l.current=Ds(v))},[]),T=a.useCallback((b=c.current)=>{const v=d.current;!v||!b||(v.scrollTop=Od({savedScrollTop:k.current.get(b),scrollHeight:v.scrollHeight,clientHeight:v.clientHeight}),p.current=v.scrollTop,l.current=Ds(v))},[]),w=a.useCallback((b,v=c.current)=>{b.scrollTop=b.scrollHeight,p.current=b.scrollTop,l.current=!0,v&&k.current.set(v,b.scrollTop)},[]),_=a.useCallback((b=c.current)=>{const v=d.current;h.current=Date.now()+$d,v&&(w(v,b),requestAnimationFrame(()=>{w(v,b),requestAnimationFrame(()=>w(v,b))}))},[w]),f=a.useCallback(b=>{const v=b.currentTarget,y=p.current,C=v.scrollTop<y&&y-v.scrollTop>10,E=v.scrollTop<=0;if(N(),!g.current){if(Ds(v)){i(!1),g.current=!0,setTimeout(()=>{g.current=!1},300);return}(C||E)&&(h.current=0,zd({atTop:E,inputCollapseDisabled:r,scrollingUp:C})&&i(!0))}},[r,N,i]),S=a.useCallback(b=>{t==="transcript"&&N(),o(b),b==="transcript"&&requestAnimationFrame(()=>T())},[t,T,N,o]);return a.useLayoutEffect(()=>{r&&i(!1)},[r,i]),a.useLayoutEffect(()=>{const b=c.current;b&&b!==s&&N(b),c.current=s,t==="transcript"&&requestAnimationFrame(()=>T(s))},[s,t,T,N]),a.useLayoutEffect(()=>{const b=d.current;if(!b||t!=="transcript"||!s)return;Un({explicitBottomStickUntil:h.current,now:Date.now(),wasAtBottom:l.current})&&w(b,s),N(s)},[s,t,n,N,w]),a.useLayoutEffect(()=>{const b=d.current,v=b==null?void 0:b.firstElementChild;if(!b||!v||t!=="transcript"||typeof ResizeObserver>"u")return;const y=new ResizeObserver(()=>{Un({explicitBottomStickUntil:h.current,now:Date.now(),wasAtBottom:l.current})?w(b):N()});return y.observe(b),y.observe(v),()=>y.disconnect()},[t,s,N,w]),{handleTranscriptScroll:f,handleTranscriptTabChange:S,scrollTranscriptToBottom:_,transcriptScrollRef:d}}function Ya(t=700){const[s,n]=a.useState(!1),r=a.useRef(null),o=a.useCallback(()=>{n(!0),r.current!==null&&clearTimeout(r.current),r.current=setTimeout(()=>{n(!1),r.current=null},t)},[t]);return a.useEffect(()=>()=>{r.current!==null&&clearTimeout(r.current)},[]),{markScrollbarActive:o,scrollbarActive:s}}const rn="pointer-events-auto h-5 w-5 shrink-0 rounded-full bg-muted/65 text-muted-foreground hover:bg-muted hover:text-foreground",Tt="h-3.5 w-3.5",Vd=a.lazy(async()=>({default:(await Zs(()=>import("./FilesTab-amewzDu1.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Ud=a.lazy(async()=>({default:(await Zs(()=>import("./PreviewTab-CDVQQTEo.js").then(s=>s.c),__vite__mapDeps([6,1,2]))).PreviewTab})),Hd=a.lazy(async()=>({default:(await Zs(()=>import("./DiffTab-QOs1BAhv.js"),__vite__mapDeps([7,1,2,5,4,3,6]))).DiffTab}));function qd({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,activeTab:c,setActiveTab:g,creatingTask:p,createMode:k,createDefaults:h,activeTask:l,assignedNode:N,taskLoading:T,transcriptLoading:w,taskError:_,displayEvents:f,initialPromptAlreadyInLogs:S,initialPrompt:b,supportsFollowUp:v,taskUnavailable:y,chatDisabled:C,chatDisabledReason:E,questionBypassEnabled:q,isRunning:D,isStarting:z,hasPendingFollowUp:P,canCancel:Z,canRetry:U,onRetry:R,onCancel:B,onReloadNativeTranscript:ae,onShareTask:re,onStopShareTask:oe,onStartCreateTask:ne,onCancelCreateTask:L,onCreateTask:H,onSendMessage:m,onCancelQueuedMessage:V,onQuestionBypassChange:x,onSubmitQuestionResponse:Q}){const[A,G]=a.useState(!1),[j,Y]=a.useState(!1),[te,pe]=a.useState(!1),[X,$]=a.useState(!1),[J,de]=a.useState(!1),[O,ie]=a.useState({}),[Ne,Te]=a.useState(new Set),[ct,et]=a.useState(new Set),[Ae,ee]=a.useState(null),je=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",Ee=l?(N==null?void 0:N.name)??Ls(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",Pe=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:Ee}),"..."]}):"Connecting session to an available node...",Oe=l?[{label:"Working dir",value:je,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:Ee}]:[],we=!!(b&&!S),rt=we||f.length>0,jt=D&&rt,ut=(z||P||D)&&!jt,tt=jt?"The agent is still working on this conversation.":ut?Pe:null,{collapsedButtonRunning:mt,showDockedProgress:Be,showInlineProgress:xt}=_d({hasTranscriptProgress:!!tt,hasVisibleTranscriptEvents:rt,inputCollapsed:A}),ye=(l==null?void 0:l.conversationKind)==="nativeSession",F=w?"Loading transcript":ye?"No transcript imported":"Transcript is warming up",Me=w?"Loading transcript...":ye?"Meshy could not find imported history for this native session yet.":"The opening prompt has been stored, but the agent has not emitted conversation output yet.",ke=(l==null?void 0:l.queuedMessages)??[],at=a.useMemo(()=>_i(f),[f]),wt=a.useMemo(()=>Ti("transcript",at.map(ve=>ve.event)),[at]),Bt=l&&!Ne.has(l.id)?O[l.id]??l.activeShare??null:null,De=(l==null?void 0:l.id)??null,Ve=`${De??"none"}:${f.length}:${ke.length}:${we?1:0}:${w?1:0}:${xt?1:0}`,{handleTranscriptScroll:ht,handleTranscriptTabChange:ot,scrollTranscriptToBottom:Ue,transcriptScrollRef:yt}=Fd({activeTab:c,activeTaskId:De,contentVersion:Ve,inputCollapseDisabled:!!tt,setActiveTab:g,setInputCollapsed:G}),{markScrollbarActive:pt,scrollbarActive:it}=Ya(),ce=a.useCallback(ve=>{pt(),ht(ve)},[ht,pt]),qe=a.useCallback(ve=>{ee(fe=>({path:ve,requestId:((fe==null?void 0:fe.requestId)??0)+1})),ot("files")},[ot]),ft=a.useCallback(ve=>{Ue(),m(ve)},[m,Ue]);return a.useEffect(()=>{ee(null)},[De]),p?e.jsx(Kd,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,defaultMode:k,createDefaults:h,onCancel:L,onCreated:H}):!l&&T?e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Hs,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"space-y-3 text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(ue,{className:"h-5 w-5 animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm font-semibold tracking-tight text-foreground",children:"Loading conversation"}),e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(Ys,{value:c,onValueChange:ot,className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"dashboard-conversation-panel__header relative shrink-0 bg-card/28 px-3 pb-0.5 pt-1 sm:px-5 sm:pt-1.5",children:[e.jsxs("div",{className:"pointer-events-none absolute left-1 right-1 top-2 flex items-center justify-between sm:left-1.5 sm:right-1.5 sm:top-2.5",children:[e.jsx(Za,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(W,{variant:"ghost",size:"icon",onClick:o,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:M(rn,"xl:hidden"),children:r?e.jsx(Fe,{className:Tt}):e.jsx(qt,{className:Tt})})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx("h2",{className:"min-w-0 truncate text-[13px] font-semibold leading-5 text-foreground sm:text-[15px]",title:l.title,children:l.title}),e.jsx(ya,{status:l.status,isNative:ye}),l.priority!=="normal"&&e.jsx(uo,{priority:l.priority})]}),_&&e.jsx("div",{className:"mt-2 w-fit rounded-sm border border-destructive/25 bg-destructive/10 px-2 py-1 text-[11px] text-destructive",children:_}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx(Bd,{activeTab:c}),y&&e.jsx($e,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"hidden rounded-sm bg-muted/65 px-1.5 py-0.5 tabular-nums sm:inline-flex",children:mo(l.updatedAt)}),U&&e.jsxs(W,{variant:"outline",size:"sm",onClick:R,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(vl,{className:"h-3.5 w-3.5"}),"Retry"]}),ye&&ae&&e.jsx(W,{variant:"ghost",size:"icon",onClick:ae,disabled:w,title:"Reload native session transcript","aria-label":"Reload native session transcript",className:"h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",children:e.jsx(Ia,{className:M("h-3.5 w-3.5",w&&"animate-spin")})}),e.jsx(W,{type:"button",variant:"ghost",size:"icon",disabled:y,title:y?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":y?"Unavailable tasks cannot be shared.":"Share conversation",className:"h-6 w-6 shrink-0 rounded-sm text-primary hover:bg-primary/10 hover:text-primary disabled:bg-transparent disabled:text-muted-foreground",onClick:()=>pe(!0),children:e.jsx(xs,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(nt,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"relative min-h-0 flex-1",children:e.jsx("div",{ref:yt,"data-transcript-scroll":"true",className:M("scrollbar-line h-full min-h-0 touch-pan-y overflow-x-hidden overflow-y-auto overscroll-x-none bg-gradient-to-b from-background/15 via-transparent to-background/35 px-3 pb-4 pt-4 sm:px-5",it&&"scrollbar-line-active"),onScroll:ce,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[we&&b&&e.jsx(Mn,{event:b,agent:l.agent,taskRootPath:l.effectiveProjectPath,onOpenFilePath:qe,questionBypassEnabled:q,onQuestionBypassChange:x,onSubmitQuestionResponse:Q,questionResponseDisabled:!v||C}),at.map(({event:ve,subItems:fe},st)=>e.jsx(Mn,{event:ve,agent:l.agent,subItems:fe,taskRootPath:l.effectiveProjectPath,onOpenFilePath:qe,questionBypassEnabled:q,onQuestionBypassChange:x,onSubmitQuestionResponse:Q,questionResponseDisabled:!v||C},wt[st])),!rt&&!ut&&e.jsxs("div",{className:"rounded-sm border border-dashed border-border/70 bg-background/35 px-3 py-4 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:F}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Me})]}),(!v&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!v&&l.result&&e.jsxs("div",{className:"rounded-sm border border-border/70 bg-card/80 px-3 py-3",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:"Stored result"}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5 text-muted-foreground",children:JSON.stringify(l.result,null,2)})]}),l.error&&!ct.has(l.id)&&e.jsxs("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-3 text-destructive",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em]",children:"Stored error"}),e.jsx("button",{onClick:()=>et(ve=>new Set(ve).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(Xe,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5",children:l.error})]})]}),xt&&tt&&e.jsx(zn,{children:tt})]})})}),Be&&tt&&e.jsx("div",{"data-docked-progress":"true",className:"shrink-0 bg-background/35 px-3 py-1 sm:px-5",children:e.jsx("div",{className:"mx-auto max-w-[72rem]",children:e.jsx(zn,{children:tt})})}),v?e.jsxs(e.Fragment,{children:[A&&e.jsx(Cd,{running:mt,onClick:()=>{G(!1),Ue(),requestAnimationFrame(()=>{var ve;return(ve=document.querySelector('[data-chat-input-textarea="true"]'))==null?void 0:ve.focus()})}}),e.jsxs("div",{className:`shrink-0 ${A?"hidden":""}`,children:[e.jsx(Pd,{messages:ke,onCancelMessage:V}),e.jsx(Yl,{onSend:ft,disabled:C,disabledReason:E,contextItems:Oe,placeholder:C?E:D?"Queue a message for the next turn...":"Continue the conversation...",running:D||P,onStop:Z?()=>Y(!0):void 0})]})]}):e.jsx("div",{className:"shrink-0 border-t border-border/60 px-3 py-3 text-[11px] text-muted-foreground sm:px-5",children:"This task does not expose follow-up chat messages. Use Files, Preview, or Diff to inspect the result."})]})}),e.jsx(nt,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ts,{label:"Loading files..."}),children:e.jsx(Vd,{taskId:l.id,requestedFilePath:(Ae==null?void 0:Ae.path)??null,requestedFileRequestId:(Ae==null?void 0:Ae.requestId)??0})})}),e.jsx(nt,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ts,{label:"Loading preview..."}),children:e.jsx(Ud,{taskId:l.id})})}),e.jsx(nt,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ts,{label:"Loading diff..."}),children:e.jsx(Hd,{taskId:l.id})})}),e.jsx(ns,{open:j,onOpenChange:Y,children:e.jsxs(as,{className:gt.content,children:[e.jsxs(rs,{className:gt.header,children:[e.jsx(os,{className:gt.title,children:"Stop this task?"}),e.jsx(is,{className:gt.description,children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ls,{className:gt.footer,children:[e.jsx(ds,{className:gt.cancel,children:"Keep running"}),e.jsx(cs,{className:gt.action,onClick:B,children:"Stop task"})]})]})}),e.jsx(Td,{open:te,onOpenChange:pe,sharing:X,stopping:J,shareResult:Bt,onShare:async ve=>{if(!l)return null;$(!0);try{const fe=await re(ve);return fe!=null&&fe.url&&(ie(st=>({...st,[l.id]:fe})),Te(st=>{const Nt=new Set(st);return Nt.delete(l.id),Nt})),fe}finally{$(!1)}},onStopShare:async()=>{if(!l)return!1;de(!0);try{const ve=await oe();return ve!==!1&&(ie(fe=>{const st={...fe};return delete st[l.id],st}),Te(fe=>new Set(fe).add(l.id))),ve}finally{de(!1)}}})]}):e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Hs,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"w-full max-w-lg text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(co,{className:"h-5 w-5"})}),e.jsx("h2",{className:"mt-3 text-sm font-semibold tracking-tight text-foreground sm:text-[15px]",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-2 max-w-md text-[11px] leading-5 text-muted-foreground",children:"Open a task from the left sidebar to continue the conversation, or start a new task or load a native session."}),e.jsxs(W,{onClick:()=>ne(),className:"mt-4 h-8 rounded-sm px-3",children:[e.jsx(bs,{className:"h-3.5 w-3.5"}),"Start or load chat"]}),_&&e.jsx("div",{className:"mx-auto mt-3 max-w-md rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:_})]})})]})}function Kd({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,defaultMode:c,createDefaults:g,onCancel:p,onCreated:k}){var T,w,_;const[h,l]=a.useState(c??"chat");a.useEffect(()=>{c&&l(c)},[c]);const N=e.jsx("div",{className:"flex h-8 items-center gap-0.5 overflow-hidden rounded-sm border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-none",children:[{value:"chat",label:"New chat",icon:bs},{value:"native",label:"Load session",icon:sn}].map(f=>{const S=f.icon,b=f.value===h;return e.jsxs("button",{type:"button",onClick:()=>l(f.value),"aria-pressed":b,className:M("flex h-7 min-w-28 items-center justify-center gap-1.5 rounded-sm border border-transparent px-2.5 transition-colors duration-150",b?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(S,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:f.label})]},f.value)})});return e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Hs,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,centerSlot:N})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(Sd,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(T=i==null?void 0:i.self)==null?void 0:T.role,currentNodeId:((w=i==null?void 0:i.self)==null?void 0:w.id)??null,leaderNodeId:((_=i==null?void 0:i.leader)==null?void 0:_.id)??null,initialAssignTo:g==null?void 0:g.assignTo,initialProject:g==null?void 0:g.project,mode:h,onModeChange:l,onCreated:k,onCancel:p,autoFocus:!0,layout:"composer"})})})]})}function Hs({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,centerSlot:i}){return e.jsxs("div",{className:"relative flex w-full items-center justify-between gap-1.5",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:e.jsx(Za,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"})}),i&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",children:e.jsx("div",{className:"pointer-events-auto",children:i})}),e.jsx(W,{variant:"ghost",size:"icon",onClick:o,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:M(rn,"xl:hidden"),children:r?e.jsx(Fe,{className:Tt}):e.jsx(qt,{className:Tt})})]})}function Za({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){var i,d;const o=(d=(i=globalThis.window)==null?void 0:i.matchMedia("(min-width: 1024px)"))!=null&&d.matches?s:n;return e.jsx(W,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:M(rn,t),children:o?e.jsx(qt,{className:Tt}):e.jsx(Fe,{className:Tt})})}function Gd({onAdded:t}){const[s,n]=a.useState(""),[r,o]=a.useState(!1),[i,d]=a.useState(null),c=a.useCallback(async g=>{if(g.preventDefault(),!!s.trim()){o(!0),d(null);try{await xo({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(p){d(p instanceof Error?p.message:"Failed to join node")}finally{o(!1)}}},[s,t]);return e.jsx(Pt,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-sm border border-border/60 bg-background/95 p-0 shadow-[0_28px_90px_-58px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-3.5 py-2.5",children:e.jsxs(Qs,{className:"space-y-1 text-left",children:[e.jsx(Gt,{className:"text-sm tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Verify the remote leader's DevTunnel endpoint, sync this node's tasks to that leader, and join the cluster as a follower."})]})}),e.jsxs("form",{onSubmit:c,className:"space-y-3 px-3.5 py-3",children:[i&&e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Re,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx($e,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(Qe,{id:"leader-endpoint",type:"url",value:s,onChange:g=>n(g.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-8 rounded-sm border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-sm border border-border/60 bg-background/45 px-3 py-2 text-[11px] text-muted-foreground",children:"This does not switch the local node transport or auto-enable a local DevTunnel. Leaving later will detach this node from the remote leader and make it leader of its own cluster again."}),e.jsx(Na,{className:"border-t border-border/60 pt-3",children:e.jsx(W,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function Wd({open:t,onOpenChange:s,onAdded:n}){return e.jsx(Mt,{open:t,onOpenChange:s,children:e.jsx(Gd,{onAdded:()=>{s(!1),n()}})})}const Yd="absolute top-1/2 z-30 hidden h-10 w-4 -translate-y-1/2 items-center justify-center rounded-full text-muted-foreground opacity-0 outline-none transition-opacity duration-150 hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/55",Zd="flex h-7 w-3.5 items-center justify-center rounded-full bg-muted/85 shadow-[0_12px_24px_-20px_rgba(0,0,0,0.9)] backdrop-blur-sm transition-colors hover:bg-card hover:text-foreground",Qd="h-2.5 w-2.5";function Qa({className:t,label:s,orientation:n,panel:r,panelResize:o}){return e.jsx("button",{type:"button","aria-label":s,"aria-orientation":n,"data-dashboard-resize-handle":r,onPointerDown:i=>o.onPointerDown(r,i),onWheel:i=>o.onWheel(r,i),className:M("group absolute z-20 hidden touch-none rounded-sm bg-transparent outline-none transition-colors hover:bg-primary/12 focus-visible:bg-primary/12 focus-visible:ring-2 focus-visible:ring-ring/70 lg:block",t),children:e.jsx("span",{className:"pointer-events-none absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"})})}function Xd({className:t,label:s,onToggle:n,side:r,visible:o}){const i=r==="left"?o?qt:Fe:o?Fe:qt;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:M(Yd,t),children:e.jsx("span",{className:Zd,"aria-hidden":"true",children:e.jsx(i,{className:Qd,strokeWidth:2.1})})})}function Hn({className:t,label:s,onToggle:n,panel:r,panelResize:o,screen:i,side:d,visible:c}){const g=i==="lg"?"lg:block":"xl:block",p=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:M("group absolute top-0 z-30 hidden h-full w-4",g,t),children:[r&&e.jsx(Qa,{panel:r,orientation:"vertical",label:`Resize ${r} panel`,panelResize:o,className:"left-1/2 top-0 h-full w-2 -translate-x-1/2 cursor-col-resize"}),e.jsx(Xd,{side:d,visible:c,label:s,onToggle:n,className:M(p,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function Jd({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:o,operationsOpen:i,operationsPanelRef:d,operationsSidecar:c,panelResize:g,taskSidebar:p,terminalPanel:k,onCloseOperations:h,onCloseTaskList:l,onToggleOperations:N,onToggleTasks:T}){const w={"--dashboard-tasks-width":g.sizes.tasks,"--dashboard-operations-width":g.sizes.operations,"--dashboard-terminal-height":g.sizes.terminal};return e.jsxs("div",{className:"dashboard-workspace flex h-full min-h-0 flex-col overflow-hidden",style:w,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(Hn,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:T,panel:s?"tasks":void 0,panelResize:g,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:M("dashboard-workspace__tasks-panel relative hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",s?"lg:mr-2 lg:w-[var(--dashboard-tasks-width)]":"lg:w-0 lg:overflow-hidden"),children:s&&p}),e.jsxs("section",{className:"dashboard-workspace__primary flex min-h-0 min-w-0 flex-1 flex-col gap-2",children:[e.jsx("div",{className:"min-h-0 flex-1",children:t}),k&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(Qa,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:g,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),k]})]}),e.jsx(Hn,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:N,panel:i?"operations":void 0,panelResize:g,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:M("dashboard-workspace__operations-panel relative hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",i?"xl:ml-2 xl:w-[var(--dashboard-operations-width)]":"xl:w-0 xl:overflow-hidden"),children:i&&c})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:h,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:d,className:"fixed bottom-0 right-0 top-[var(--dashboard-mobile-overlay-top)] z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:c})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:l,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:o,className:"fixed bottom-0 left-0 top-[var(--dashboard-mobile-overlay-top)] z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:n})]})]})}const ec=10,vt="__all__";function He(t){return"session"in t}function qn(t,s){var n;return s&&t.some(r=>r.id===s)?s:((n=t[0])==null?void 0:n.id)??""}function As(t){return t&&(qa(t.id)||t.workDir)||""}function Jt(t,s,n){let r=!1;const o=t.map(i=>He(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return qs(r?o:[...o,{id:`session-${n.id}`,nodeName:s,session:n}])}function Xa(t,s){return t.filter(He).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function tc(t){const s=t.filter(He).sort((n,r)=>r.session.startedAt-n.session.startedAt);return{active:s.filter(n=>n.session.status==="running"),completed:s.filter(n=>n.session.status!=="running")}}function sc(t,s){return!!(t&&s&&!t.contains(s))}function nc(t,s,n){var o;if(n===vt)return n;const r=Xa(t,s);return r.some(i=>i.session.id===n)?n:((o=r[0])==null?void 0:o.session.id)??vt}function ac(t,s,n){return n===vt?t.filter(r=>!He(r)||r.session.nodeId===s):t.filter(r=>He(r)&&r.session.nodeId===s&&r.session.id===n)}function qs(t){const s=t.map((r,o)=>({entry:r,index:o})).filter(({entry:r})=>He(r)&&r.session.status!=="running").sort((r,o)=>!He(r.entry)||!He(o.entry)?0:o.entry.session.startedAt-r.entry.session.startedAt||o.index-r.index),n=new Set(s.slice(0,ec).map(({entry:r})=>He(r)?r.session.id:""));return t.filter(r=>!He(r)||r.session.status==="running"||n.has(r.session.id))}function Ks(t){return t.status==="running"?t.pid?`running pid ${t.pid}`:"running":t.status==="exited"?`exit ${t.exitCode??0}`:t.status==="stopped"?"stopped":t.signal?`failed ${t.signal}`:`exit ${t.exitCode??"failed"}`}function rc(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${Ks(t.session)} - ${s}`}function Ja(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function oc(t,s){return s===vt?"All sessions":t?Ja(t.session.command,34):"Command session"}function Kn(t){return t.status==="stopped"?"":t.stderr}function ic({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[o,i]=a.useState(()=>qn(t,s)),d=a.useMemo(()=>t.find(x=>x.id===o)??t[0]??null,[t,o]),[c,g]=a.useState(()=>As(d)),[p,k]=a.useState(""),[h,l]=a.useState(()=>qs(r)),[N,T]=a.useState(vt),[w,_]=a.useState(!1),[f,S]=a.useState(!1),[b,v]=a.useState(!1),[y,C]=a.useState(!1),[E,q]=a.useState(!1),D=a.useRef(null),z=a.useRef(null),P=a.useMemo(()=>t.find(x=>x.id===o)??t[0]??null,[t,o]),Z=a.useMemo(()=>Xa(h,(P==null?void 0:P.id)??""),[h,P]),U=a.useMemo(()=>tc(Z),[Z]),R=a.useMemo(()=>Z.find(x=>x.session.id===N),[N,Z]),B=a.useMemo(()=>ac(h,(P==null?void 0:P.id)??"",N),[h,P,N]),ae=a.useRef((P==null?void 0:P.id)??"");a.useEffect(()=>{o&&t.some(x=>x.id===o)||i(qn(t,s))},[s,t,o]),a.useEffect(()=>{const x=(P==null?void 0:P.id)??"";ae.current!==x&&(ae.current=x,g(As(P)))},[P]),a.useEffect(()=>{T(x=>nc(h,(P==null?void 0:P.id)??"",w?x:""))},[h,P,w]),a.useEffect(()=>{var x;(x=D.current)==null||x.scrollTo({top:D.current.scrollHeight})},[h]),a.useEffect(()=>{let x=!1;async function Q(){const A=await Promise.allSettled(t.map(async G=>({node:G,response:await po(G.id)})));x||l(G=>A.reduce((j,Y)=>Y.status!=="fulfilled"?j:Y.value.response.sessions.reduce((te,pe)=>Jt(te,Y.value.node.name,pe),j),G))}return t.length>0&&Q(),()=>{x=!0}},[t]),a.useEffect(()=>{const x=h.filter(He).filter(A=>A.session.status==="running");if(x.length===0)return;const Q=window.setInterval(()=>{for(const A of x)ho(A.session.nodeId,A.session.id).then(G=>l(j=>Jt(j,A.nodeName,G))).catch(()=>{})},1e3);return()=>window.clearInterval(Q)},[h]);const re=a.useRef(null);async function oe(x){if(x.preventDefault(),!P||!p.trim()||E)return;const Q=p.trim(),A=P.name;q(!0),k("");try{const G=await go(P.id,{command:Q,...c.trim()?{cwd:c.trim()}:{}});l(j=>Jt(j,A,G)),T(G.id),_(!0)}catch(G){l(j=>[...j,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:A,command:Q,error:G instanceof Error?G.message:"Command failed"}])}finally{q(!1)}}async function ne(x,Q){x.stopPropagation();const A=await fo(Q.session.nodeId,Q.session.id);l(G=>Jt(G,Q.nodeName,A))}function L(x){T(x),_(!0),S(!1)}function H(x){f&&sc(z.current,x.target)&&S(!1)}function m(x,Q,A,G,j){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:G,"aria-label":`Toggle ${x} sessions`,"aria-expanded":!A,className:"node-terminal__small flex w-full items-center justify-between gap-2 px-2 pb-1 pt-0.5 text-left font-medium uppercase tracking-normal text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{children:x}),e.jsx(Je,{className:M("h-3 w-3 transition-transform",A&&"-rotate-90")})]}),!A&&(Q.length>0?Q.map(V):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:j}))]})}function V(x){const Q=N===x.session.id,A=x.session.status==="running";return e.jsxs("div",{className:M("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",Q&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>L(x.session.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:M("flex h-4 w-4 shrink-0 items-center justify-center",A?"text-primary":x.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:A?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):x.session.status==="exited"?e.jsx(kn,{className:"h-3 w-3"}):e.jsx(Cs,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:Ja(x.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[x.nodeName," · ",Ks(x.session)]})]})]}),A&&e.jsx("button",{type:"button",onClick:G=>void ne(G,x),"aria-label":"Stop terminal session from selector",title:"Stop terminal session",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(In,{className:"h-3 w-3"})})]},x.session.id)}return e.jsx("section",{className:"dashboard-panel node-terminal animate-composer-settle flex h-full min-h-0 shrink-0 overflow-visible rounded-xl","aria-label":"Node terminal",onClick:H,children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-visible rounded-[inherit] bg-card/72 text-card-foreground",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"node-terminal__header flex min-w-0 items-center gap-2 font-medium",children:[n?e.jsx("button",{type:"button",onClick:n,"aria-label":"Close terminal",title:"Close terminal",className:"flex h-6 w-6 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(Xe,{className:"h-3.5 w-3.5"})}):e.jsx(Nn,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{children:"Terminal"})]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-2",children:[e.jsxs("div",{ref:z,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":f,title:R?rc(R):"All sessions",onClick:()=>S(x=>!x),className:"node-terminal__control flex h-7 max-w-[14rem] list-none items-center gap-1.5 rounded-sm border border-border/70 bg-background/70 px-2 text-foreground outline-none transition-colors hover:bg-muted/65 focus-visible:ring-2 focus-visible:ring-ring/70 [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{className:"min-w-0 truncate",children:oc(R,N)}),e.jsx(Je,{className:M("h-3 w-3 shrink-0 text-muted-foreground transition-transform",f&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!f,className:M("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!f&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>L(vt),className:M("node-terminal__control flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",N===vt&&"bg-primary/10 text-primary"),children:[e.jsx(Nn,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),m("Active",U.active,b,()=>v(x=>!x),"No active sessions"),m("Completed",U.completed,y,()=>C(x=>!x),"No completed sessions")]})})]}),e.jsx("select",{value:(P==null?void 0:P.id)??"",onChange:x=>{i(x.target.value),_(!1),g(As(t.find(Q=>Q.id===x.target.value)??null))},disabled:E||t.length===0,"aria-label":"Terminal node",className:"node-terminal__control h-7 max-w-[11rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground outline-none transition-colors hover:bg-muted/65 disabled:opacity-50",children:t.map(x=>e.jsx("option",{value:x.id,className:"bg-background text-foreground",children:x.name},x.id))}),e.jsx(hs,{value:c,onChange:g,assignTo:(P==null?void 0:P.id)??"",nodes:t,assignableNodes:t,layout:"composer",chipClassName:"node-terminal__control h-7 max-w-[18rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground hover:bg-muted/65",chipActiveClassName:"font-mono",chipInactiveClassName:"text-muted-foreground",labelClassName:"node-terminal__workdir",triggerClassName:"terminal-workdir-trigger",popoverPlacement:"top",popoverAlign:"end"})]})]}),e.jsxs("div",{ref:D,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>{var x;return(x=re.current)==null?void 0:x.focus()},children:[B.length===0?e.jsx("div",{className:"text-muted-foreground mb-2",children:"Commands run on the selected node and stay visible while running or after exit."}):e.jsx("div",{className:"space-y-3 mb-2",children:B.map(x=>He(x)?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"text-primary",children:[x.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:x.session.command}),e.jsxs("span",{className:M("inline-flex items-center gap-1",x.session.status==="running"||x.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[x.session.status==="running"?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):x.session.status==="exited"?e.jsx(kn,{className:"h-3 w-3"}):e.jsx(Cs,{className:"h-3 w-3"}),Ks(x.session)]}),x.session.status==="running"&&e.jsx("button",{type:"button",onClick:Q=>void ne(Q,x),"aria-label":"Stop terminal session",title:"Stop terminal session",className:"inline-flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/65 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(In,{className:"h-3 w-3"})})]}),x.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:x.session.stdout}),Kn(x.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Kn(x.session)}),(x.session.stdoutTruncated||x.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},x.id):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"text-primary",children:[x.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:x.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(Cs,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:x.error})]},x.id))}),e.jsxs("form",{onSubmit:oe,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:P?`${P.name}$`:"$"}),e.jsx("input",{ref:re,value:p,onChange:x=>k(x.target.value),disabled:!P||E,placeholder:P?"":"No online nodes available",className:"node-terminal__input flex-1 min-w-0 bg-transparent border-none outline-none text-foreground placeholder:text-muted-foreground font-mono caret-primary disabled:opacity-50",autoComplete:"off",spellCheck:!1}),e.jsx("button",{type:"submit","aria-label":"Run",title:"Run",disabled:!P||!p.trim()||E,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:text-muted-foreground disabled:opacity-50",children:E?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(fs,{className:"h-3 w-3"})})]})]})]})})}function on({nodeId:t,nodeName:s,onOpenSettings:n,onOpenServicePreview:r,onOpenCapabilities:o,onOpenDevBox:i,onStartDevBox:d,onToggleRemoteAccess:c,remoteAccessLabel:g,remoteAccessPending:p,remoteAccessDisabled:k,remoteAccessDisabledReason:h,showConfigureDevBox:l,showStartDevBox:N,startDevBoxPending:T,className:w}){const[_,f]=a.useState(!1),[S,b]=a.useState(null),v=a.useRef(null),y=a.useRef(null),C=T?"Starting":"Start DevBox",E=g!=null&&g.startsWith("Disable")?bo:Dl;a.useLayoutEffect(()=>{if(!_){b(null);return}const D=()=>{const z=y.current,P=v.current;if(!z||!P)return;const Z=z.getBoundingClientRect(),U=P.getBoundingClientRect();b(dc({left:Z.left,right:Z.right,bottom:Z.bottom,top:Z.top},{width:U.width,height:U.height},{width:window.innerWidth,height:window.innerHeight},cc()))};return D(),window.addEventListener("resize",D),window.addEventListener("scroll",D,!0),()=>{window.removeEventListener("resize",D),window.removeEventListener("scroll",D,!0)}},[_]),a.useEffect(()=>{if(!_)return;const D=P=>{var U,R;const Z=P.target;Z instanceof Node&&!((U=v.current)!=null&&U.contains(Z))&&!((R=y.current)!=null&&R.contains(Z))&&f(!1)},z=P=>{P.key==="Escape"&&f(!1)};return document.addEventListener("mousedown",D),document.addEventListener("keydown",z),()=>{document.removeEventListener("mousedown",D),document.removeEventListener("keydown",z)}},[_]);const q=_?e.jsxs("div",{ref:v,"data-node-action-menu-portal":"true",role:"menu",style:lc(S),onClick:D=>D.stopPropagation(),onPointerDown:D=>D.stopPropagation(),className:"fixed z-[130] min-w-40 overflow-hidden whitespace-nowrap rounded-sm border border-border/65 bg-popover/96 p-1 normal-case tracking-normal shadow-[0_18px_48px_-28px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:[n&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} settings`,title:`Open ${s} settings`,onClick:D=>{D.stopPropagation(),f(!1),n(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(vo,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Settings"})]}),r&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Preview service on ${s}`,title:`Preview service on ${s}`,onClick:D=>{D.stopPropagation(),f(!1),r(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(La,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Preview service"})]}),o&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} capabilities`,title:`Open ${s} capabilities`,onClick:D=>{D.stopPropagation(),f(!1),o(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(ps,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Capabilities"})]}),g&&c&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${g} for ${s}`,title:h??`${g} for ${s}`,onClick:D=>{D.stopPropagation(),!(p||k)&&(f(!1),c())},disabled:p||k,className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80 disabled:cursor-not-allowed disabled:opacity-60",children:[p?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(E,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:g})]}),N&&d&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${C} for ${s}`,title:`${C} for ${s}`,onClick:D=>{D.stopPropagation(),!T&&(f(!1),d(t))},disabled:T,className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80 disabled:cursor-not-allowed disabled:opacity-60",children:[T?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(fs,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:C})]}),l&&i&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${s}`,title:`Configure DevBox for ${s}`,onClick:D=>{D.stopPropagation(),f(!1),i(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(jo,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Configure DevBox"})]})]}):null;return e.jsxs("div",{"data-node-action-menu":"true",className:M("relative shrink-0",_&&"z-[120]",w),onClick:D=>D.stopPropagation(),onPointerDown:D=>D.stopPropagation(),children:[e.jsx(W,{ref:y,type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${s}`,"aria-haspopup":"menu","aria-expanded":_,title:`More actions for ${s}`,onClick:D=>{D.stopPropagation(),f(z=>(z||b(null),!z))},className:M("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",_&&"bg-background/80 text-primary"),children:e.jsx(Yi,{className:"h-3.5 w-3.5"})}),q&&(typeof document>"u"?q:ka.createPortal(q,document.body))]})}function lc(t){return t?{left:t.left,top:t.top}:{left:0,top:0,visibility:"hidden"}}function dc(t,s,n,r=1){const d=s.width||160,c=s.height||0,g=Number.isFinite(r)&&r>0?r:1,p=Math.max(8,Math.min(t.right-d,n.width-d-8)),k=t.bottom+4,h=(t.top??t.bottom)-c-4,l=k+c>n.height-8&&h>=8?h:k;return{left:Math.round(p/g),top:Math.round(l/g)}}function cc(){if(typeof window>"u"||typeof document>"u")return 1;const t=window.getComputedStyle(document.documentElement),s=t.zoom||t.getPropertyValue("--ui-zoom"),n=Number.parseFloat(s);return Number.isFinite(n)&&n>0?n:1}const uc=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),mc=new Set(["startinprogress","starting"]);function Et(t){return!!(t!=null&&t.enabled&&t.name)}function xc(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&uc.has(s))}function Dt(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&mc.has(s))}function vs(t,s,n){return t==="offline"&&xc(s)&&Et(n)}function Gn(t,s){return t==="offline"&&Et(s)}function Wn(t){return!Et(t)}function hc({nodeStatus:t,status:s,current:n,selected:r}){const o=r??n;return o&&vs(t,s,o)?o:null}function Ie(t){return t.scope||`name:${t.name??""}`}function pc({previousKey:t,baseDevBox:s,listed:n}){if(t&&n.some(i=>Ie(i)===t))return t;if(!Et(s))return n[0]?Ie(n[0]):"";const r=Ie(s),o=n.find(i=>Ie(i)===r)??n.find(i=>i.name===s.name);return o?Ie(o):r}function fc({cluster:t,systemInfo:s,nodeNameById:n,nodeBlockingTaskCounts:r,eventTypeFilter:o,onEventTypeFilterChange:i,eventTypeOptions:d,filteredEvents:c,sseConnected:g,clusterLoading:p,clusterError:k,promotePending:h,onPromote:l,onAddNode:N,leavePending:T,onLeaveCluster:w,onToggleNodeDevTunnel:_,devTunnelNodeId:f,devBoxStartNodeId:S,devBoxStartingNodeIds:b=new Set,onOpenNodeSettings:v,onOpenNodeCapabilities:y,onOpenDevBox:C,onStartDevBox:E}){var re,oe,ne;const q=((re=t==null?void 0:t.self)==null?void 0:re.role)==="leader",D=((oe=t==null?void 0:t.self)==null?void 0:oe.role)==="follower"&&!(t!=null&&t.leader),z=(t==null?void 0:t.self)??null,Z=wo((t==null?void 0:t.nodes)??[],z==null?void 0:z.id).filter(L=>L.id!==(z==null?void 0:z.id)),U=t!=null&&t.leader?t.nodes.find(L=>{var H;return L.id===((H=t.leader)==null?void 0:H.id)})??null:null,R=t!=null&&t.leader?t.leader.dashboardOrigin??(U==null?void 0:U.dashboardOrigin)??(s&&t.leader.id===(s.nodeId??s.id)?s.dashboardOrigin:void 0)??t.leader.endpoint:null,B=(z==null?void 0:z.role)==="leader"&&Z.length===0,ae=(z==null?void 0:z.role)==="follower";return e.jsx("aside",{className:"dashboard-operations-sidecar dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:e.jsxs(Ys,{defaultValue:"overview",className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"dashboard-operations-sidecar__header shrink-0 bg-card/24 px-2.5 py-2",children:e.jsxs(Ws,{className:"grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(bt,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(bt,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(bt,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})}),e.jsx(nt,{value:"overview",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-2 py-2",children:e.jsxs("div",{className:"space-y-2.5",children:[z&&e.jsx(Yn,{node:z,systemInfo:s,blockingTaskCount:r.get(z.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:_,showActions:!1,defaultExpanded:!1,onOpenDevBox:C,devBoxStartingNodeIds:b}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"Cluster snapshot"}),e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:g?"Connected":"Reconnecting"})]}),p&&!t?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):k&&!t?e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-2 py-1.5 text-[10px] text-destructive shadow-none",children:k}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(St,{label:"Term",value:String((t==null?void 0:t.term)??0)}),e.jsx(St,{label:"Nodes",value:String((t==null?void 0:t.nodes.length)??0)}),e.jsx(St,{label:"Pending",value:String((t==null?void 0:t.taskSummary.pending)??0)}),e.jsx(St,{label:"Running",value:String((t==null?void 0:t.taskSummary.running)??0)}),e.jsx(St,{label:"Completed",value:String((t==null?void 0:t.taskSummary.completed)??0)}),e.jsx(St,{label:"Failed",value:String((t==null?void 0:t.taskSummary.failed)??0)})]}),e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-muted/45 px-2 py-2 shadow-none",children:[e.jsx(Ze,{label:"Leader",value:((ne=t==null?void 0:t.leader)==null?void 0:ne.name)??"None"}),e.jsx(Ze,{label:"Leader URL",value:R??"Unavailable",mono:!0,action:R?e.jsx(Kt,{label:"Copy leader URL",onClick:()=>void Ct(R,"Leader URL copied")}):void 0}),e.jsx(Ze,{label:"Feed",value:g?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:D&&e.jsxs(W,{variant:"secondary",size:"sm",onClick:l,disabled:h,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[h&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(nt,{value:"nodes",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-2 py-2",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"This node"}),B?e.jsxs(W,{variant:"secondary",size:"sm",onClick:N,className:"h-6 border-0 bg-primary px-2 text-[10px] text-primary-foreground shadow-none hover:bg-primary/90",children:[e.jsx(Tl,{className:"h-3 w-3"}),"Join node"]}):ae?e.jsxs(W,{variant:"secondary",size:"sm",onClick:w,disabled:T,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[T&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),z&&e.jsx(Yn,{node:z,systemInfo:s,blockingTaskCount:r.get(z.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:_,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:q?v:void 0,onOpenNodeCapabilities:q?y:void 0,onOpenDevBox:q?C:void 0,onStartDevBox:q?E:void 0,devBoxStartNodeId:S,devBoxStartingNodeIds:b})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",Z.length,")"]}),Z.length>0?e.jsx("div",{className:"space-y-1.5",children:Z.map(L=>e.jsx(gc,{node:L,isLeader:!!q,blockingTaskCount:r.get(L.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:_,onOpenNodeSettings:q?v:void 0,onOpenNodeCapabilities:q?y:void 0,onOpenDevBox:q?C:void 0,onStartDevBox:q?E:void 0,devBoxStartNodeId:S,devBoxStartingNodeIds:b},L.id))}):e.jsx("div",{className:"rounded-sm bg-muted/45 px-2 py-2 text-[10px] text-muted-foreground shadow-none",children:"No peer nodes are connected yet."})]})]})})}),e.jsx(nt,{value:"events",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col px-2 py-2",children:[e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-foreground",children:[e.jsx(yo,{className:M("h-3.5 w-3.5",g?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(Se,{value:o,onValueChange:i,children:[e.jsx(Ce,{className:"h-6 min-w-[10rem] flex-1 rounded-sm border-0 bg-muted/60 text-[10px] shadow-none sm:max-w-[14rem] [&>svg]:h-3 [&>svg]:w-3",children:e.jsx(Le,{placeholder:"Event type"})}),e.jsx(_e,{className:"shadow-none",children:d.map(L=>e.jsx(he,{value:L,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:L==="all"?"All event types":L},L))})]}),e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:g?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(No,{events:c,maxHeight:"100%",emptyTitle:o==="all"?"No live events yet":"No matching events",emptyDescription:o==="all"?"Cluster activity appears here as it happens.":`No "${o}" events are in the current stream.`,nodeNameById:n,density:"compact"})})]})})]})})}function Yn({node:t,systemInfo:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:o,showActions:i=!0,defaultExpanded:d=!1,onOpenNodeSettings:c,onOpenNodeCapabilities:g,onOpenDevBox:p,onStartDevBox:k,devBoxStartNodeId:h,devBoxStartingNodeIds:l}){var E,q,D,z;const[N,T]=a.useState(d),w=(s==null?void 0:s.dashboardOrigin)??t.dashboardOrigin,_=t.devtunnelEndpoint??t.endpoint,f=w??t.endpoint,S=(s==null?void 0:s.workDir)??t.workDir,b=Oa(t,s==null?void 0:s.transportType),v=nn(t,s==null?void 0:s.transportType),y=v&&It((s==null?void 0:s.transportType)??t.transportType)?!0:$a(t,s==null?void 0:s.transportType),C=n>0;return e.jsxs("section",{className:"dashboard-operations-node-card bg-primary/8 shadow-none",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>T(P=>!P),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[N?e.jsx(Je,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Fe,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(Sa,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Current node"})]}),e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Xs,{className:"h-3 w-3"})}),(c||g||i&&y)&&e.jsx(on,{nodeId:t.id,nodeName:t.name,onOpenSettings:c,onOpenCapabilities:g,onOpenDevBox:p,onStartDevBox:k,onToggleRemoteAccess:i&&y?()=>o(t):void 0,remoteAccessLabel:i&&y?v?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:C,remoteAccessDisabledReason:C?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:(E=t.devbox)==null?void 0:E.enabled,showStartDevBox:vs(t.status,(q=t.devbox)==null?void 0:q.lastStatus,t.devbox)||Dt((D=t.devbox)==null?void 0:D.lastStatus)||l.has(t.id),startDevBoxPending:h===t.id||Dt((z=t.devbox)==null?void 0:z.lastStatus)||l.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>T(P=>!P),className:"mt-1 flex min-w-0 items-center gap-1 pl-5 text-left",children:[e.jsx("span",{className:"text-[10px] font-semibold tracking-tight text-foreground",children:t.name}),e.jsx(Ca,{role:t.role,size:"compact"}),e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),N&&e.jsxs("div",{className:"space-y-2 bg-primary/5 px-2.5 pb-2.5 pt-1.5",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-muted/45 px-2 py-1.5 shadow-none",children:[e.jsx(Ze,{label:"Node ID",value:t.id,mono:!0}),w&&e.jsx(Ze,{label:"Dashboard",value:w,mono:!0,action:e.jsx(Kt,{label:"Copy dashboard URL",onClick:()=>void Ct(w,"Dashboard URL copied")})}),e.jsx(Ze,{label:"Node URL",value:_,mono:!0,action:e.jsx(Kt,{label:"Copy node URL",onClick:()=>void Ct(_,"Node URL copied")})}),S&&e.jsx(Ze,{label:"Workspace",value:S,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Rs,{label:"Transport",value:b}),s&&e.jsx(Rs,{label:"Uptime",value:ko(s.uptime),mono:!0})]}),i&&g&&e.jsxs(W,{variant:"secondary",size:"sm",onClick:()=>g(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(ps,{className:"h-3 w-3"}),"Capabilities"]}),i&&y&&C&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function gc({node:t,isLeader:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:o,onOpenNodeSettings:i,onOpenNodeCapabilities:d,onOpenDevBox:c,onStartDevBox:g,devBoxStartNodeId:p,devBoxStartingNodeIds:k}){var v,y,C,E;const[h,l]=a.useState(!1),N=t.dashboardOrigin,T=t.devtunnelEndpoint??t.endpoint,w=N??t.endpoint,_=Oa(t),f=nn(t),S=$a(t),b=n>0;return e.jsxs("div",{className:"dashboard-operations-node-card bg-muted/45 shadow-none",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>l(q=>!q),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[h?e.jsx(Je,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(Fe,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Sa,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Peer node"})]}),e.jsx("a",{href:w,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Xs,{className:"h-3 w-3"})}),s&&(i||d||S)&&e.jsx(on,{nodeId:t.id,nodeName:t.name,onOpenSettings:i,onOpenCapabilities:d,onOpenDevBox:c,onStartDevBox:g,onToggleRemoteAccess:S?()=>o(t):void 0,remoteAccessLabel:S?f?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:b,remoteAccessDisabledReason:b?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:(v=t.devbox)==null?void 0:v.enabled,showStartDevBox:vs(t.status,(y=t.devbox)==null?void 0:y.lastStatus,t.devbox)||Dt((C=t.devbox)==null?void 0:C.lastStatus)||k.has(t.id),startDevBoxPending:p===t.id||Dt((E=t.devbox)==null?void 0:E.lastStatus)||k.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>l(q=>!q),className:"mt-1 flex min-w-0 items-center gap-1 pl-4 text-left",children:[e.jsx("span",{className:"text-[10px] font-semibold text-foreground",children:t.name}),e.jsx(Ca,{role:t.role,size:"compact"}),e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),h&&e.jsxs("div",{className:"space-y-2 bg-muted/35 px-2.5 pb-2.5 pt-1.5",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/55 px-2 py-1.5 shadow-none",children:[e.jsx(Ze,{label:"Node ID",value:t.id,mono:!0}),N&&e.jsx(Ze,{label:"Dashboard",value:N,mono:!0,action:e.jsx(Kt,{label:"Copy dashboard URL",onClick:()=>void Ct(N,"Dashboard URL copied")})}),e.jsx(Ze,{label:"Node URL",value:T,mono:!0,action:e.jsx(Kt,{label:"Copy node URL",onClick:()=>void Ct(T,"Node URL copied")})}),t.workDir&&e.jsx(Ze,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(Rs,{label:"Transport",value:_})]}),s&&d&&e.jsxs(W,{variant:"secondary",size:"sm",onClick:()=>d(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(ps,{className:"h-3 w-3"}),"Capabilities"]}),s&&S&&b&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Kt({label:t,onClick:s}){return e.jsx(W,{type:"button",variant:"ghost",size:"icon",className:"h-4 w-4 shrink-0 rounded-sm p-0 text-muted-foreground opacity-70 hover:bg-muted/45 hover:opacity-100 [&_svg]:size-2.5",onClick:s,"aria-label":t,title:t,children:e.jsx(wa,{className:"h-3 w-3"})})}function bc(t,s,n,r){var c,g;if(!t)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const o=((c=s==null?void 0:s.self)==null?void 0:c.role)==="follower",i=t.assignedTo?((g=s==null?void 0:s.self)==null?void 0:g.id)===t.assignedTo?s.self:s==null?void 0:s.nodes.find(p=>p.id===t.assignedTo):void 0;return t.assignedTo!==null&&(i?i.status==="offline":s?t.assignedNodeAvailable===!1||!s.nodes.some(p=>p.id===t.assignedTo):t.assignedNodeAvailable===!1)?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${t.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}:o?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Follower nodes are read-only. Use the leader dashboard to manage chat, or leave the cluster first."}:n?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Sending message..."}:r?{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Queue a message for the next turn..."}:us.has(t.status)||t.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:us.has(t.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const er=.5,tr=1.75,Zn=.1;function vc({node:t,open:s,onOpenChange:n}){const[r,o]=a.useState(""),[i,d]=a.useState(null),[c,g]=a.useState(1),[p,k]=a.useState(!1),[h,l]=a.useState(null);a.useEffect(()=>{o(""),d(null),g(1),k(!1),l(null)},[t==null?void 0:t.id,s]);const N=a.useCallback(async b=>{if(!t)return;const v=b??Number.parseInt(r,10);if(!Number.isInteger(v)||v<1||v>65535){l("Enter a port between 1 and 65535");return}k(!0),l(null);try{const y=await So(t.id,{port:v});d(y),o(String(v))}catch(y){l(y instanceof Error?y.message:"Failed to create service preview")}finally{k(!1)}},[t,r]),T=a.useCallback(()=>{typeof(i==null?void 0:i.port)=="number"&&N(i.port)},[i==null?void 0:i.port,N]);a.useEffect(()=>{if(!i)return;const b=i.expiresAt-Date.now()-5e3;if(b<=0){T();return}const v=window.setTimeout(T,b);return()=>window.clearTimeout(v)},[T,i]);const w=i?$i(i):null,_=(t==null?void 0:t.name)??"Node",f=jc(c),S={width:`${100/c}%`,height:`${100/c}%`,transform:`scale(${c})`,transformOrigin:"top left"};return e.jsx(Mt,{open:s,onOpenChange:n,children:e.jsxs(Pt,{className:"flex h-[min(82vh,44rem)] max-w-[min(92vw,72rem)] flex-col gap-0 overflow-hidden p-0",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border/60 px-3 py-2 pr-9",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(Gt,{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold text-foreground",children:[e.jsx(La,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0",children:"Preview service"}),e.jsx("span",{className:"min-w-0 truncate font-mono text-[10px] font-medium text-muted-foreground",children:_})]}),e.jsx(Js,{className:"sr-only",children:"Preview a service port running on the selected node."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("form",{className:"flex items-center gap-1.5",onSubmit:b=>{b.preventDefault(),N()},children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:["Port",e.jsx(Qe,{type:"number",min:1,max:65535,inputMode:"numeric",value:r,onChange:b=>o(b.target.value),placeholder:"5173","aria-label":"Node service preview port",className:"h-6 w-20 rounded-sm px-2 text-[11px]"})]}),e.jsxs(W,{type:"submit",variant:"ghost",size:"sm",disabled:p,className:"h-6 rounded-sm border-0 bg-primary/10 px-2 text-[11px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[p?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(fs,{className:"h-3.5 w-3.5"}),"Run"]})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden shrink-0 text-[10px] text-muted-foreground sm:inline",children:wc(i.expiresAt)}),e.jsxs("div",{className:"flex h-6 shrink-0 items-center overflow-hidden rounded-sm border border-border/55 bg-muted/35",children:[e.jsx(W,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>g(b=>Qn(b,-Zn)),disabled:c<=er,title:"Zoom out","aria-label":"Zoom out preview",children:e.jsx(Ll,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>g(1),className:"h-6 min-w-11 border-x border-border/45 px-1.5 text-center font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted/55 hover:text-foreground",title:"Reset zoom","aria-label":"Reset preview zoom",children:f}),e.jsx(W,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>g(b=>Qn(b,Zn)),disabled:c>=tr,title:"Zoom in","aria-label":"Zoom in preview",children:e.jsx(Ml,{className:"h-3.5 w-3.5"})})]}),e.jsx(W,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:T,title:"Refresh",children:e.jsx(Co,{className:"h-3.5 w-3.5"})}),e.jsx(W,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",asChild:!0,title:"Open in new tab",children:e.jsx("a",{href:w??i.previewUrl,target:"_blank",rel:"noopener noreferrer",children:e.jsx(Xs,{className:"h-3.5 w-3.5"})})})]})]})]}),h&&e.jsx("div",{className:"shrink-0 border-b border-destructive/20 bg-destructive/5 px-3 py-1.5 text-[11px] text-destructive",children:h}),e.jsx("div",{className:"min-h-0 flex-1 p-2",children:i?e.jsx("div",{className:"h-full overflow-hidden rounded-sm border border-border/60 bg-white shadow-none",children:e.jsx("iframe",{src:zi(i),style:S,className:"h-full w-full border-0",sandbox:Oi(i),title:`${_} Service Preview`})}):e.jsx("div",{className:"flex h-full min-h-56 items-center justify-center rounded-sm border border-dashed border-border/65 bg-background/35 px-3 text-center text-[11px] text-muted-foreground",children:"No service preview running."})})]})})}function Qn(t,s){return sr(Math.round((t+s)*100)/100)}function sr(t){return Number.isFinite(t)?Math.min(tr,Math.max(er,t)):1}function jc(t){return`${Math.round(sr(t)*100)}%`}function wc(t){const s=Math.max(0,Math.round((t-Date.now())/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60),r=s%60;return`${n}m ${r}s`}function yc({dirPath:t,label:s,taskCount:n,collapsed:r,onToggle:o,onCreateTask:i,onOpenCapabilities:d}){return e.jsxs("div",{className:"group/project-row flex w-full items-stretch rounded-sm bg-muted/15 text-[9px] font-medium text-muted-foreground/70 transition-all duration-150 hover:bg-muted/30 hover:text-foreground active:scale-[0.98] active:bg-muted/40",children:[e.jsxs("button",{type:"button",onClick:o,"aria-expanded":!r,title:t,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-l-sm px-2 py-1 text-left",children:[e.jsx(Fe,{className:M("h-3 w-3 shrink-0 transition-transform duration-200",!r&&"rotate-90")}),e.jsx(At,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:s}),e.jsx("span",{className:"ml-2 shrink-0 rounded-sm bg-background/55 px-1 py-0 tabular-nums text-[8px] font-medium leading-3 text-muted-foreground/45",children:n})]}),d&&e.jsx("button",{type:"button",onClick:d,"aria-label":`Capabilities for ${t}`,title:`Capabilities for ${t}`,className:"pointer-events-none mr-0.5 flex h-4 w-4 shrink-0 translate-y-px self-center items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-all hover:bg-primary/10 hover:text-primary focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/project-row:pointer-events-auto group-hover/project-row:opacity-100",children:e.jsx(ps,{className:"h-2.5 w-2.5"})}),e.jsx("button",{type:"button",onClick:i,"aria-label":`New chat in ${t}`,title:`New chat in ${t}`,className:"pointer-events-none ml-auto flex h-4 w-4 shrink-0 translate-y-px self-center items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-all hover:bg-primary/10 hover:text-primary focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/project-row:pointer-events-auto group-hover/project-row:opacity-100",children:e.jsx(bs,{className:"h-2.5 w-2.5"})})]})}const nr="meshy-task-sidebar-tree-state";function Xn(t){return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Ms(){var t;try{return((t=globalThis.window)==null?void 0:t.localStorage)??globalThis.localStorage??null}catch{return null}}function Jn(t){if(!t)return{collapsedNodes:[],collapsedDirs:[]};try{const s=t.getItem(nr);if(!s)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(s);return{collapsedNodes:Xn(n.collapsedNodes),collapsedDirs:Xn(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Nc(t,s){if(t)try{t.setItem(nr,JSON.stringify(s))}catch{}}function ea(t,s){if(!t.has(s))return t;const n=new Set(t);return n.delete(s),n}function kc(t,s){if(!s)return null;for(const n of t){const r=n.nodeId??"__unassigned__";for(const o of n.dirs)if(o.tasks.some(i=>i.id===s))return{nodeKey:r,dirKey:`${r}::${o.path}`}}return null}function ta(t,s,n){return n?{collapsedNodes:ea(t,n.nodeKey),collapsedDirs:ea(s,n.dirKey)}:{collapsedNodes:t,collapsedDirs:s}}function Sc(t,s,n){const r=t.filter(c=>c.status==="completed"),o=new Set((s?r:[...r].sort((c,g)=>g.updatedAt-c.updatedAt).slice(0,en)).map(c=>c.id));n&&r.some(c=>c.id===n)&&o.add(n);const i=t.filter(c=>c.status!=="completed"||o.has(c.id)),d=r.length-o.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,d)}}const es="h-6 rounded-sm border-0 bg-muted/45 px-2 py-0 text-[10px] leading-none text-foreground shadow-none hover:bg-muted/65 focus:bg-muted/65 focus:ring-0 focus:ring-offset-0 [&>svg]:h-3 [&>svg]:w-3",ts="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function sa({toolbarTasks:t,activeTaskId:s,tasksLoading:n,tasksError:r,isLeader:o,scope:i,agentFilter:d,nodeFilter:c,taskKindFilter:g,agentOptions:p,nodeOptions:k,nodeNameById:h,nodeWorkDirById:l,nodeStatusById:N,completedGroupByKey:T,devBoxNodeIds:w=new Set,devBoxStartNodeIds:_=new Set,devBoxStartingNodeIds:f=new Set,leaderNodeId:S,searchQuery:b,selectedTaskIds:v,allVisibleTasksSelected:y,someVisibleTasksSelected:C,canBatchArchive:E,onScopeChange:q,onAgentFilterChange:D,onNodeFilterChange:z,onTaskKindFilterChange:P,onToggleTaskSelected:Z,onToggleAllVisibleTasks:U,onBatchArchive:R,onBatchDelete:B,onCreateTask:ae,onOpenNodeSettings:re,onOpenNodeCapabilities:oe,onOpenProjectCapabilities:ne,onOpenDevBox:L,onStartDevBox:H,onLoadCompletedTasks:m,onSelectTask:V}){const[x,Q]=a.useState(!1),[A,G]=a.useState(()=>v.size>0),[j,Y]=a.useState(null),{markScrollbarActive:te,scrollbarActive:pe}=Ya(),X=v.size,$=!!(o&&(A||X>0)),J=i!=="active"||c!=="all"||d!=="all"||g!=="all",de=b.trim().length>0,[O,ie]=a.useState(()=>new Set(Jn(Ms()).collapsedNodes)),[Ne,Te]=a.useState(()=>new Set(Jn(Ms()).collapsedDirs)),[ct,et]=a.useState(new Set),Ae=a.useMemo(()=>_o(t,h,S,l),[t,h,S,l]),ee=a.useMemo(()=>kc(Ae,s),[Ae,s]),je=a.useRef(null),Ee=Ae.length===1,Pe=Ae.length>0,Oe=Ee&&(J||de),we=!!(o&&(Ae.length>0||X>0)),rt=a.useCallback(F=>{ie(Me=>{const ke=new Set(Me);return ke.has(F)?ke.delete(F):ke.add(F),ke})},[]),jt=a.useCallback(F=>{Te(Me=>{const ke=new Set(Me);return ke.has(F)?ke.delete(F):ke.add(F),ke})},[]),ut=a.useCallback(F=>{et(Me=>{const ke=new Set(Me);return ke.add(F),ke})},[]);a.useEffect(()=>{Nc(Ms(),{collapsedNodes:Array.from(O),collapsedDirs:Array.from(Ne)})},[Ne,O]),a.useEffect(()=>{if(!ee||!s)return;const F=`${s}:${ee.nodeKey}:${ee.dirKey}`;je.current!==F&&(je.current=F,ie(Me=>ta(Me,new Set,ee).collapsedNodes),Te(Me=>ta(new Set,Me,ee).collapsedDirs))},[s,ee]);const tt=a.useCallback(F=>{G(!0),U(F)},[U]),mt=a.useCallback(()=>{U(!1),G(!1)},[U]);a.useEffect(()=>{o||G(!1)},[o]);const Be=$?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(Ht,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:C&&!y?"indeterminate":y,onCheckedChange:F=>tt(F===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Multi select"})]}):e.jsxs(W,{variant:"ghost",size:"sm",onClick:()=>G(!0),className:"h-5 rounded-sm px-1.5 text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75 hover:text-foreground",children:[e.jsx(Ei,{className:"h-3 w-3"}),"Multi select"]}),xt=X>0?e.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"text-[9px] font-semibold leading-3 text-foreground",children:[X," task",X!==1?"s":""," selected"]}),!E&&e.jsx("div",{className:"max-w-48 text-[9px] leading-3.5 text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."})]}):null,ye=X>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(ns,{children:[e.jsx(Is,{asChild:!0,children:e.jsxs(W,{variant:"ghost",size:"sm",disabled:!E,className:"h-5 gap-1 rounded-sm bg-muted/45 px-1.5 text-[8px] text-foreground/80 shadow-none hover:bg-muted/65 [&_svg]:size-3",children:[e.jsx(Vi,{}),"Archive"]})}),e.jsxs(as,{children:[e.jsxs(rs,{children:[e.jsxs(os,{children:["Archive ",X," task",X!==1?"s":"","?"]}),e.jsx(is,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(ls,{children:[e.jsx(ds,{children:"Cancel"}),e.jsx(cs,{onClick:R,disabled:!E,children:"Archive"})]})]})]}),e.jsxs(ns,{children:[e.jsx(Is,{asChild:!0,children:e.jsxs(W,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(Ra,{}),"Delete"]})}),e.jsxs(as,{children:[e.jsxs(rs,{children:[e.jsxs(os,{children:["Delete ",X," task",X!==1?"s":"","?"]}),e.jsx(is,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(ls,{children:[e.jsx(ds,{children:"Cancel"}),e.jsx(cs,{onClick:B,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"dashboard-task-sidebar dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"dashboard-task-sidebar__header shrink-0 bg-card/24 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex min-w-0 items-stretch gap-1.5",children:[e.jsxs(W,{onClick:()=>ae("chat"),className:"h-8 w-[6.75rem] justify-start rounded-sm px-2.5 text-left text-[11px] shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(bs,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsxs(W,{variant:"outline",onClick:()=>ae("native"),className:"h-8 w-[7.75rem] justify-start rounded-sm border-0 bg-muted/45 px-2.5 text-left text-[11px] text-foreground shadow-none hover:bg-muted/65 hover:text-foreground",children:[e.jsx(sn,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Load session"]})]}),e.jsx(W,{variant:"ghost",size:"icon",onClick:()=>Q(F=>!F),className:M("ml-auto h-8 w-8 shrink-0 rounded-sm text-muted-foreground shadow-none hover:bg-muted/55 hover:text-foreground",(x||J)&&"bg-primary/8 text-primary hover:bg-primary/12 hover:text-primary"),title:"Filters",children:e.jsx(sl,{className:"h-3.5 w-3.5"})})]}),(x||J)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(Se,{value:i,onValueChange:F=>q(F),children:[e.jsx(Ce,{className:es,children:e.jsx(Le,{})}),e.jsx(_e,{children:To.map(F=>e.jsx(he,{value:F.value,className:ts,children:F.label},F.value))})]}),e.jsxs(Se,{value:c,onValueChange:z,children:[e.jsx(Ce,{className:es,children:e.jsx(Le,{placeholder:"Node"})}),e.jsx(_e,{children:k.map(F=>e.jsx(he,{value:F.value,className:ts,children:F.label},F.value))})]}),e.jsxs(Se,{value:d,onValueChange:D,children:[e.jsx(Ce,{className:es,children:e.jsx(Le,{placeholder:"Agent"})}),e.jsx(_e,{children:p.map(F=>e.jsx(he,{value:F,className:ts,children:F==="all"?"All agents":F},F))})]}),e.jsxs(Se,{value:g,onValueChange:F=>P(F),children:[e.jsx(Ce,{className:es,children:e.jsx(Le,{placeholder:"Type"})}),e.jsx(_e,{children:Eo.map(F=>e.jsx(he,{value:F.value,className:ts,children:F.label},F.value))})]})]})]}),e.jsx("div",{className:M("scrollbar-line min-h-0 flex-1 overflow-y-auto pl-2.5 pr-1.5 py-2",pe&&"scrollbar-line-active"),onScroll:te,children:Ae.length>0?e.jsx("div",{className:"space-y-1",children:Ae.map(F=>{const Me=F.nodeId??"__unassigned__",ke=F.dirs.reduce((De,Ve)=>De+Ve.tasks.length,0),at=Pe&&!Oe&&O.has(Me),wt=F.nodeId!==null&&N.get(F.nodeId)==="offline",Bt=!!(o&&F.nodeId);return e.jsxs("div",{className:"space-y-1",children:[Pe&&e.jsxs("div",{className:"flex w-full items-stretch rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 text-left text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsxs("button",{type:"button",onClick:()=>rt(Me),"aria-expanded":!at,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(Fe,{className:M("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!at&&"rotate-90")}),e.jsx(ga,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:F.nodeName}),e.jsxs($e,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-transparent bg-background/55 px-1.5 py-0 text-[7px] font-semibold leading-3.5 text-muted-foreground shadow-none normal-case tracking-normal",children:[ke," task",ke===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[wt&&e.jsx($e,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/10 px-1 py-0 text-[8px] font-semibold leading-3 text-destructive shadow-none",children:"offline"}),F.nodeId===S&&e.jsx($e,{variant:"outline",className:"rounded-sm border-transparent bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"})]})]}),Bt&&F.nodeId&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(on,{nodeId:F.nodeId,nodeName:F.nodeName,onOpenSettings:re,onOpenServicePreview:()=>Y({id:F.nodeId,name:F.nodeName}),onOpenCapabilities:oe,onOpenDevBox:L,onStartDevBox:H,showConfigureDevBox:w.has(F.nodeId),showStartDevBox:_.has(F.nodeId)||f.has(F.nodeId),startDevBoxPending:f.has(F.nodeId)})})]}),e.jsx("div",{className:M("grid transition-[grid-template-rows] duration-300 ease-in-out",at?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:F.dirs.map(De=>{const Ve=`${Me}::${De.path}`,ht=Ne.has(Ve),ot=_a(De.path),Ue=T==null?void 0:T.get(Ve),yt=Ue?{visibleTasks:De.tasks,hiddenCompletedCount:Math.max(0,Ue.total-Ue.returned)}:Sc(De.tasks,ct.has(Ve),s),{visibleTasks:pt,hiddenCompletedCount:it}=yt;return e.jsxs("div",{className:M("space-y-0.5 rounded-xl",Pe&&"pl-2.5"),children:[e.jsx(yc,{dirPath:De.path,label:ot,taskCount:De.tasks.length,collapsed:ht,onToggle:()=>jt(Ve),onCreateTask:()=>ae("chat",{assignTo:F.nodeId,project:De.path==="default workspace"?"":De.path}),onOpenCapabilities:F.nodeId&&ne?()=>ne(F.nodeId,De.path==="default workspace"?(l==null?void 0:l.get(F.nodeId))??De.path:De.path):void 0}),e.jsx("div",{className:M("grid transition-[grid-template-rows] duration-300 ease-in-out",ht?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:M("overflow-hidden",Pe?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[pt.map(ce=>{const qe=ce.id===s,ft=ce.assignedTo?N.get(ce.assignedTo):void 0,ve=!!ce.assignedTo&&(ft?ft==="offline":ce.assignedNodeAvailable===!1);return e.jsxs("div",{className:M("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",qe?'bg-primary/10 before:absolute before:left-0 before:top-1/2 before:h-1/2 before:w-[2px] before:-translate-y-1/2 before:rounded-full before:bg-primary before:content-[""]':"hover:bg-muted/40"),children:[$&&e.jsx("div",{className:"flex shrink-0",onClick:fe=>fe.stopPropagation(),children:e.jsx(Ht,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:v.has(ce.id),onCheckedChange:fe=>Z(ce.id,fe===!0),"aria-label":`Select ${ce.title}`})}),e.jsxs("button",{type:"button",onClick:()=>V(ce.id),"aria-current":qe?"page":void 0,className:"relative min-w-0 flex-1 pr-8 text-left",children:[e.jsx("div",{className:"flex items-center gap-1.5 pr-1",children:e.jsx("span",{className:M("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",qe?"text-foreground":"text-foreground/80"),children:ce.title})}),e.jsx("span",{className:M("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",qe?"text-primary/75":"text-muted-foreground/55"),children:Do(ce.updatedAt)}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5",children:[e.jsx("span",{className:"rounded-sm bg-muted/35 px-1 py-0 font-mono text-[8px] leading-3 text-muted-foreground/65",children:ce.agent}),ce.activeShare&&e.jsx($e,{variant:"outline",className:"rounded-sm border-primary/25 bg-primary/8 px-1 py-0 text-[8px] leading-3 text-primary shadow-none",children:"shared"}),ve&&e.jsx($e,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/8 px-1 py-0 text-[8px] leading-3 text-destructive shadow-none",children:"unavailable"})]}),e.jsx(ya,{status:ce.status,isNative:ce.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},ce.id)}),it>0&&e.jsxs("button",{type:"button",onClick:()=>{Ue&&m?m(Ue):ut(Ve)},className:"mt-1 flex w-full items-center justify-center gap-1 rounded-sm border border-dashed border-border/55 bg-background/35 px-2 py-1 text-[9px] font-medium text-muted-foreground transition-colors hover:border-primary/35 hover:bg-primary/8 hover:text-primary","aria-label":`Load ${it} more completed tasks in ${ot}`,children:[e.jsx(Je,{className:"h-3 w-3"}),"Load ",it," more completed"]})]})})})]},Ve)})})})]},Me)})}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(F=>e.jsx("div",{className:"rounded-xl border border-border/40 bg-background/30 px-3 py-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"mt-1 h-2.5 w-2.5 shrink-0 animate-pulse rounded-full bg-muted-foreground/20"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-2.5 animate-pulse rounded-full bg-muted-foreground/15",style:{width:`${60+F*12}%`,animationDelay:`${F*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${F*120+60}ms`}})]})]})},F))}):e.jsx("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-3 py-5 text-[11px] text-muted-foreground",children:r||"No tasks match this view."})}),we?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:$&&X>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[xt,e.jsx(W,{variant:"ghost",size:"sm",onClick:mt,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Clear"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:Be}),ye]})]}):e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:Be}),$&&e.jsx(W,{variant:"ghost",size:"sm",onClick:mt,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]}),e.jsx(vc,{node:j,open:j!==null,onOpenChange:F=>{F||Y(null)}})]})}async function Cc(t,s){var n,r;try{const o=await Ao(t,s),i={...o,url:ja(o.url)};if((r=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&r.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),le.success("Shared link copied")}catch{le.success("Shared link created")}else le.success("Shared link created");return i}catch(o){le.error(o instanceof Error?o.message:"Failed to create shared link");return}}async function _c(t){try{return await Mo(t),le.success("Shared link stopped"),!0}catch(s){return le.error(s instanceof Error?s.message:"Failed to stop shared link"),!1}}function Tc(t,s,n){const r=a.useCallback(()=>{s(),n()},[s,n]),o=a.useCallback(async d=>{if(!t)return;const c=await Cc(t.id,d);return c&&r(),c},[t,r]),i=a.useCallback(async()=>{if(!t)return!1;const d=await _c(t.id);return d&&r(),d},[t,r]);return{handleShareTask:o,handleStopShareTask:i}}function na(t,s,n){const r=a.useRef(s);r.current=s,a.useEffect(()=>{let d=0,c=0;const g=h=>{const l=h.touches[0];l&&(d=l.clientX,c=l.clientY)},p=h=>{var w,_,f,S;const l=h.changedTouches[0];if(!l)return;const N=l.clientX-d;Math.abs(l.clientY-c)>100||Math.abs(N)<50||(N>0?(_=(w=r.current).onSwipeRight)==null||_.call(w):(S=(f=r.current).onSwipeLeft)==null||S.call(f))},k=(t==null?void 0:t.current)??document;return k.addEventListener("touchstart",g,{passive:!0}),k.addEventListener("touchend",p,{passive:!0}),()=>{k.removeEventListener("touchstart",g),k.removeEventListener("touchend",p)}},[t,n==null?void 0:n.threshold,n==null?void 0:n.maxVertical])}const Ec="(min-width: 1024px)",Dc="(min-width: 1800px)";function aa(t){var s,n,r;return((r=(n=(s=globalThis.window)==null?void 0:s.matchMedia)==null?void 0:n.call(s,t))==null?void 0:r.matches)??!1}function Ac(){var n,r;const t=(n=globalThis.document)==null?void 0:n.documentElement;if(!t||!((r=globalThis.window)!=null&&r.getComputedStyle))return 16;const s=Number.parseFloat(globalThis.window.getComputedStyle(t).fontSize);return Number.isFinite(s)&&s>0?s:16}function Mc(){const[t,s]=a.useState(()=>Po(Sn(),Lo({operationsOpen:aa(Dc)}))),[n,r]=a.useState(!1),o=a.useRef(null),i=a.useRef(null),d=a.useRef(null),c=t.layout.desktopTasksOpen,g=t.layout.operationsOpen,p=t.sizes;a.useEffect(()=>{Io(Sn(),t)},[t]);const k=a.useCallback((_,f)=>{s(S=>{const b=S.layout[_],v=typeof f=="function"?f(b):f;return v===b?S:{...S,layout:{...S.layout,[_]:v}}})},[]),h=a.useCallback(_=>{k("desktopTasksOpen",_)},[k]),l=a.useCallback(_=>{k("operationsOpen",_)},[k]);na(i,{onSwipeLeft:()=>r(!1)}),na(d,{onSwipeRight:()=>l(!1)});const N=a.useCallback(()=>{if(aa(Ec)){h(_=>!_);return}r(_=>!_)},[h]);a.useEffect(()=>{var S,b,v;const _=y=>{const C=o.current;if(!C)return;y.preventDefault();const E=Ro(C.panel,C.startSize,C.startClientX,C.startClientY,y.clientX,y.clientY,C.rootFontSize);s(q=>({...q,sizes:{...q.sizes,[C.panel]:E}}))},f=()=>{o.current=null};return(S=globalThis.window)==null||S.addEventListener("pointermove",_),(b=globalThis.window)==null||b.addEventListener("pointerup",f),(v=globalThis.window)==null||v.addEventListener("pointercancel",f),()=>{var y,C,E;(y=globalThis.window)==null||y.removeEventListener("pointermove",_),(C=globalThis.window)==null||C.removeEventListener("pointerup",f),(E=globalThis.window)==null||E.removeEventListener("pointercancel",f)}},[]);const T=a.useCallback((_,f)=>{var S,b;f.preventDefault(),(b=(S=f.currentTarget).setPointerCapture)==null||b.call(S,f.pointerId),o.current={panel:_,startSize:p[_],startClientX:f.clientX,startClientY:f.clientY,rootFontSize:Ac()}},[p]),w=a.useCallback((_,f)=>{f.preventDefault(),s(S=>({...S,sizes:{...S.sizes,[_]:Bo(_,S.sizes[_],f.deltaY)}}))},[]);return{desktopTasksOpen:c,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:g,operationsPanelRef:d,panelResize:{sizes:{tasks:_s(p.tasks),operations:_s(p.operations),terminal:_s(p.terminal)},onPointerDown:T,onWheel:w},setMobileTasksPanelOpen:r,setOperationsOpen:l,toggleTasksPanel:N}}function Pc(t,s){const n=s.taskId,r=s.updates;return typeof n!="string"||!r||typeof r!="object"?t:t.map(o=>o.id===n?{...o,...r}:o)}const Lc="notify_desktop_task";function Ic(t=ar()){var n,r;const s=(r=(n=t==null?void 0:t.__TAURI__)==null?void 0:n.core)==null?void 0:r.invoke;return typeof s=="function"?s:null}async function Bc(t,s=ar()){const n=Ic(s);return n?(await n(Lc,t),!0):!1}function Rc(t,s){const n=[];for(const r of s){const o=$c(r.status);if(!o)continue;const i=t.get(r.id);!i||i.status===r.status||n.push({taskId:r.id,title:r.title.trim()||"Meshy task",status:o,assignedNodeName:r.assignedNodeName??null,projectPath:r.effectiveProjectPath??r.project??null})}return n}function $c(t){return t==="completed"||t==="failed"?t:null}function ar(){return typeof window>"u"?null:window}function Oc({isLeader:t,selfId:s}){return{...!t&&s?{assignedTo:s}:{},completedLimitPerProject:en}}function Gs(t){return`${t.assignedTo??"__unassigned__"}::${t.projectPath}`}function zc(t,s){const n=new Map(t.map(r=>[r.id,r]));for(const r of s)n.set(r.id,r);return Array.from(n.values())}function Fc(t,s,n=new Set){return!s||n.has(s.id)||t.some(r=>r.id===s.id)?t:za(t,s)}function Vc({isLeader:t,selfId:s,sseConnected:n,preservedTask:r,subscribe:o}){const[i,d]=a.useState([]),[c,g]=a.useState([]),[p,k]=a.useState(!0),[h,l]=a.useState(null),N=a.useRef(new Set),T=a.useRef(null),w=a.useRef(null),_=a.useCallback(async()=>{try{const v=await Cn(Oc({isLeader:t,selfId:s}));d(Fc(v.tasks,r,N.current)),g(v.completedGroups??[]),l(null)}catch(v){l(v instanceof Error?v.message:"Failed to load tasks")}finally{k(!1)}},[t,r,s]),f=a.useCallback(async v=>{if(!v.hasMore||!v.nextCursor)return;const y=await Cn({status:"completed",assignedTo:v.assignedTo??"__unassigned__",projectPath:v.projectPath,cursor:v.nextCursor,limit:en});d(C=>zc(C,y.tasks)),g(C=>C.map(E=>Gs(E)===Gs(v)?{...E,returned:Math.min(E.total,E.returned+y.tasks.length),hasMore:y.hasMore===!0,nextCursor:y.nextCursor??null}:E))},[]),S=a.useCallback(()=>{w.current===null&&(w.current=window.setTimeout(()=>{w.current=null,_()},$o))},[_]),b=a.useCallback(v=>{const y=new Set(v);if(y.size!==0){for(const C of y)N.current.add(C);d(C=>C.filter(E=>!y.has(E.id)))}},[]);return Oo(_,Vo(n)),a.useEffect(()=>()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),a.useEffect(()=>{const v=T.current;if(v)for(const y of Rc(v,i))Bc(y).catch(()=>{});T.current=new Map(i.map(y=>[y.id,y]))},[i]),a.useEffect(()=>{const v=[o("task.updated",y=>{d(C=>Pc(C,y.data))}),o("task.status",y=>{d(C=>zo(C,y.data))}),o("node",y=>{_n(y.type)&&S()}),o("task",y=>{if(y.type==="task.deleted"){const C=y.data.taskId;typeof C=="string"&&N.current.add(C),d(E=>Fo(E,y.data))}_n(y.type)&&S()})];return()=>v.forEach(y=>y())},[o,S]),{completedGroups:c,fetchTasks:_,loadCompletedTasksPage:f,removeTasksFromList:b,setTasks:d,tasks:i,tasksError:h,tasksLoading:p}}function rr(t){return t.map(s=>({...s}))}function Uc(t,s){const n=s.get(t);return{logs:n?rr(n.logs):[],transcriptLoading:(n==null?void 0:n.loaded)!==!0}}function Hc(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function qc({cluster:t,subscribe:s}){a.useEffect(()=>{var n;if(((n=t==null?void 0:t.self)==null?void 0:n.role)==="leader")return s("node",r=>{const o=String(r.data.name??r.data.nodeId??"node"),i=Hc(t,r);r.type==="node.joined"&&!i&&le.success(`${o} joined the cluster`),r.type==="node.left"&&!i&&le.message(`${o} left the cluster`)})},[t,s])}const Kc=[0,300,1e3,2e3];function Gc({task:t,getActiveTaskId:s,setLogs:n,setPendingMessages:r,setTranscriptLoading:o}){t.conversationKind==="nativeSession"&&(async()=>{try{for(const i of Kc){if(i>0&&await new Promise(d=>setTimeout(d,i)),s()!==t.id)return;try{const d=await Bs(t.id);if(s()!==t.id||(n(c=>Ma(c,d.logs)),r(c=>$s(c,d.logs)),d.total>0))return}catch{}}}finally{s()===t.id&&(o==null||o(!1))}})()}function Wc(t,s){return Ie(t??{})===Ie(s??{})}function Yc(t){return t&&"status"in t&&typeof t.status=="string"?t.status:void 0}function ra(t,s){return{...t,enabled:!0,alwaysOnline:s}}function or(t){var s,n;return((s=t==null?void 0:t.status)==null?void 0:s.trim())||((n=t==null?void 0:t.lastStatus)==null?void 0:n.trim())||"Unknown"}function Zc({operationStarting:t,loading:s,refreshing:n,savedStatus:r,fallbackStatus:o}){return t?"Starting":s?"Listing DevBoxes":n?"Refreshing":r??o}function oa({devbox:t,showStatus:s=!1}){return e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"font-medium",children:t.name}),t.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",t.projectName]})]}),s&&e.jsx("span",{className:"ml-auto shrink-0 rounded-sm border border-border/70 bg-background/70 px-1.5 py-0 text-[10px] leading-none text-muted-foreground",children:or(t)})]})}function Qc({node:t,open:s,startInProgress:n=!1,onOpenChange:r,onRefresh:o}){const i=(t==null?void 0:t.id)??null,d=s&&!n&&Gn(t==null?void 0:t.status,(t==null?void 0:t.devbox)??null),[c,g]=a.useState([]),[p,k]=a.useState(()=>t!=null&&t.devbox?Ie(t.devbox):""),[h,l]=a.useState(()=>(t==null?void 0:t.devbox)??null),[N,T]=a.useState(()=>Wn((t==null?void 0:t.devbox)??null)),[w,_]=a.useState(!1),[f,S]=a.useState(d),[b,v]=a.useState(!1),[y,C]=a.useState(!1),[E,q]=a.useState(()=>{var j;return((j=t==null?void 0:t.devbox)==null?void 0:j.alwaysOnline)===!0}),D=a.useMemo(()=>{const j=c.find(Y=>Ie(Y)===p);return j||(Et(h)&&Ie(h)===p?h:void 0)},[h,c,p]),z=Yc(D??void 0),P=N?z??(h==null?void 0:h.lastStatus):(h==null?void 0:h.lastStatus)??z,Z=(t==null?void 0:t.status)==="online"||(t==null?void 0:t.status)==="busy"?"Running":"Unknown",U=y||n,R=Zc({operationStarting:U,loading:w,refreshing:f,savedStatus:P,fallbackStatus:Z}),B=N&&!!D&&!Wc(h,D),ae=(h==null?void 0:h.alwaysOnline)===!0!==E,re=hc({nodeStatus:t==null?void 0:t.status,status:R,current:h,selected:D}),oe=!!re,ne=!!D&&(B||ae)&&!oe,L=D??h,H=a.useCallback(async()=>{if(i){S(!0);try{const j=await Uo(i);l(j.devbox),k(Ie(j.devbox))}catch(j){le.error(j instanceof Error?j.message:"Failed to refresh DevBox status")}finally{S(!1)}}},[i]),m=a.useCallback(async j=>{_(!0);try{const Y=await Ho();g(Y),k(te=>pc({previousKey:te,baseDevBox:j,listed:Y}))}catch(Y){le.error(Y instanceof Error?Y.message:"Failed to load DevBoxes")}finally{_(!1)}},[]);a.useEffect(()=>{if(!s||!i)return;let j=!1;const Y=(t==null?void 0:t.devbox)??null,te=Wn(Y),pe=!n&&Gn(t==null?void 0:t.status,Y);_(!1),S(pe),T(te),l(Y),q((Y==null?void 0:Y.alwaysOnline)===!0),k(Et(Y)?Ie(Y):""),g([]);async function X(){pe&&await H(),!j&&te&&await m(Y)}return X(),()=>{j=!0}},[m,t==null?void 0:t.devbox,t==null?void 0:t.status,i,s,H,n]);async function V(){T(!0),c.length===0&&await m(h)}async function x(){if(!(!t||!D)){v(!0);try{const j=await Tn(t.id,ra(D,E));l(j.node.devbox??null),j.node.devbox&&k(Ie(j.node.devbox)),T(!1),le.success(`Configured DevBox for ${t.name}`),await(o==null?void 0:o())}catch(j){le.error(j instanceof Error?j.message:"Failed to configure DevBox")}finally{v(!1)}}}async function Q(){if(!(!t||!re)){C(!0);try{if(D&&(B||ae)){const Y=await Tn(t.id,ra(D,E));l(Y.node.devbox??null),Y.node.devbox&&k(Ie(Y.node.devbox)),T(!1)}const{operation:j}=await Ta(t.id);l(Y=>Y&&{...Y,lastStatus:"Starting",checkedAt:Date.now(),operationId:j.id}),le.success(`Start requested for ${t.name}`),await(o==null?void 0:o())}catch(j){le.error(j instanceof Error?j.message:"Failed to start DevBox")}finally{C(!1)}}}const A=w?"Loading DevBoxes...":c.length===0?"No DevBoxes available":"Select a DevBox",G=R==="Running"&&(t==null?void 0:t.status)==="offline";return e.jsx(Mt,{open:s,onOpenChange:r,children:e.jsxs(Pt,{className:"max-w-md gap-3 rounded-sm p-4",children:[e.jsxs(Qs,{className:"space-y-1",children:[e.jsx(Gt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(Js,{className:"text-xs",children:["Bind ",t!=null&&t.name?e.jsx("span",{className:"font-medium text-foreground",children:t.name}):"this node"," to an Azure Dev Box. Meshy will start it when the node is offline."]})]}),e.jsxs("div",{className:"space-y-3",children:[(N||L)&&e.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 rounded-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:N?e.jsxs(Se,{value:p,onValueChange:k,disabled:w||b||y||c.length===0,children:[e.jsx(Ce,{className:"h-7 justify-start gap-2 rounded-none border-0 bg-transparent px-0 text-xs shadow-none focus:ring-0 focus:ring-offset-0 [&>span]:!flex [&>span]:!min-w-0 [&>span]:!flex-1 [&>span]:!items-center",children:w&&!D?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),A]}):D?e.jsx(oa,{devbox:D}):e.jsx(Le,{placeholder:A})}),e.jsx(_e,{children:c.map(j=>e.jsx(he,{value:Ie(j),textValue:`${j.name} ${j.projectName??""} ${or(j)}`,className:"pl-2 pr-7 text-xs [&>span:first-child]:left-auto [&>span:first-child]:right-2 [&>span:last-child]:w-full",children:e.jsx(oa,{devbox:j,showStatus:!0})},Ie(j)))})]}):L&&e.jsxs("div",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:L.name}),L.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",L.projectName]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs($e,{variant:"outline",className:"rounded-sm px-1.5 py-0 text-[10px]",children:[(w||f)&&e.jsx(ue,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),R]}),(h==null?void 0:h.name)&&e.jsx(W,{type:"button",variant:"ghost",size:"icon",onClick:()=>{V()},disabled:w||b||U||N,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-sm text-muted-foreground hover:text-foreground",children:w&&N?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Lt,{className:"h-3 w-3"})})]})]}),G&&e.jsx("div",{className:"rounded-sm border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:"DevBox is running, but the Meshy node is not connected yet."}),e.jsxs("label",{className:"flex min-h-9 items-start gap-2 rounded-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(Ht,{checked:E,onCheckedChange:j=>q(j===!0),disabled:b||y||U,"aria-label":"Always online",className:"mt-0.5 h-3.5 w-3.5"}),e.jsxs("span",{className:"min-w-0 leading-4",children:[e.jsx("span",{className:"block",children:"Always online"}),e.jsx("span",{className:"block text-[10px] leading-3.5 text-muted-foreground",children:"Meshy will start the DevBox automatically when it is Hibernated or Stopped."})]})]})]}),e.jsxs(Na,{className:"gap-2 sm:space-x-0",children:[e.jsx(W,{variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:b||y,className:"h-8 rounded-sm text-xs",children:"Close"}),oe&&e.jsxs(W,{size:"sm",onClick:Q,disabled:y,className:"h-8 rounded-sm text-xs",children:[y?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(fs,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!oe&&e.jsxs(W,{size:"sm",onClick:x,disabled:!ne||b,className:"h-8 rounded-sm text-xs",children:[b&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function Xc(t,s=qo){if(t.length===0)return new Set;const n=new Set(t),[r,o]=await Promise.all([s({kind:"devbox.start",status:"queued"}),s({kind:"devbox.start",status:"running"})]);return new Set([...r,...o].filter(i=>n.has(i.nodeId)).map(i=>i.nodeId))}function Jc({cluster:t,refresh:s}){const[n,r]=a.useState(null),[o,i]=a.useState(null),[d,c]=a.useState(()=>new Set),[g,p]=a.useState(()=>new Set),k=a.useMemo(()=>(t==null?void 0:t.nodes.find(f=>f.id===n))??null,[t==null?void 0:t.nodes,n]),h=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(f=>{var S;return(S=f.devbox)==null?void 0:S.enabled}).map(f=>f.id)),[t==null?void 0:t.nodes]),l=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(f=>{var S;return vs(f.status,(S=f.devbox)==null?void 0:S.lastStatus,f.devbox)}).map(f=>f.id)),[t==null?void 0:t.nodes]),N=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(f=>{var S;return Dt((S=f.devbox)==null?void 0:S.lastStatus)}).map(f=>f.id)),[t==null?void 0:t.nodes]),T=a.useMemo(()=>{const f=new Set(d);o&&f.add(o);for(const S of g)f.add(S);for(const S of N)f.add(S);return f},[g,o,d,N]);a.useEffect(()=>{let f=!1;const S=[...h];async function b(){try{const v=await Xc(S);f||p(v)}catch{f||p(new Set)}}return b(),()=>{f=!0}},[h]),a.useEffect(()=>{c(f=>{var v;let S=!1;const b=new Set(f);for(const y of f){const C=t==null?void 0:t.nodes.find(E=>E.id===y);(C==null?void 0:C.status)!=="online"&&(!((v=C==null?void 0:C.devbox)!=null&&v.lastStatus)||Dt(C.devbox.lastStatus))||(b.delete(y),S=!0)}return S?b:f})},[t==null?void 0:t.nodes]);const w=a.useCallback(async f=>{const S=t==null?void 0:t.nodes.find(b=>b.id===f);if(S){i(f),c(b=>new Set(b).add(f));try{await Ta(f),le.success(`Start requested for ${S.name}`),s()}catch(b){c(v=>{const y=new Set(v);return y.delete(f),y}),le.error(b instanceof Error?b.message:"Failed to start DevBox")}finally{i(null)}}},[t==null?void 0:t.nodes,s]);return{devBoxDialog:e.jsx(Qc,{node:k,open:n!==null,startInProgress:k?T.has(k.id):!1,onOpenChange:f=>{f||r(null)},onRefresh:s}),devBoxNodeIds:h,devBoxStartNodeId:o,devBoxStartNodeIds:l,devBoxStartingNodeIds:T,openDevBox:r,startDevBox:w}}function eu(t){const[s,n]=a.useState(null),r=a.useCallback(i=>{t&&n(i)},[t]);return{nodeSettingsDialog:e.jsx(Ko,{open:s!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:s??void 0,showTrigger:!1}),openNodeSettings:r}}function tu(t=!1){return!t}function su({activeTaskId:t,fetchActiveTask:s,isRunning:n=!1,setPendingMessages:r,setTask:o,setTasks:i}){const d=a.useCallback((p,k)=>{o(h=>h&&h.id===p?{...h,queuedMessages:k}:h),i(h=>h.map(l=>l.id===p?{...l,queuedMessages:k}:l))},[o,i]),c=a.useCallback(async p=>{if(!t)return!1;const k=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`,h=tu(n);h&&r(l=>[...l,{id:k,content:p,timestamp:new Date().toISOString()}]);try{const l=await Go(t,p);return l.queued&&(h&&r(N=>N.filter(T=>T.id!==k)),l.queuedMessages&&d(t,l.queuedMessages)),s(),!0}catch(l){return h&&r(N=>N.filter(T=>T.id!==k)),le.error(l instanceof Error?l.message:"Failed to send message"),!1}},[t,s,n,r,d]);return{cancelQueuedMessage:a.useCallback(async p=>{if(t)try{const k=await Wo(t,p);d(t,k.queuedMessages),s()}catch(k){le.error(k instanceof Error?k.message:"Failed to cancel queued message")}},[t,s,d]),queueFollowUpMessage:c}}const ia="grid-cols-[1.5rem_5.25rem_4rem_minmax(8rem,1fr)_4rem_4rem_6rem]",nu={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function au(t,s){const n=s.search.trim().toLowerCase();return t.filter(r=>s.agent!=="all"&&r.agent!==s.agent||s.kind!=="all"&&r.kind!==s.kind?!1:n?[r.name,r.description,r.source,r.version,r.agent,r.kind].some(o=>o==null?void 0:o.toLowerCase().includes(n)):!0)}function ir(t){return t.kind==="mcp"?"-":t.sizeBytes<1024?`${t.sizeBytes} B`:t.sizeBytes<1024*1024?`${Math.round(t.sizeBytes/1024)} KB`:`${(t.sizeBytes/1024/1024).toFixed(1)} MB`}function ru({items:t,selectedIds:s,activeId:n,onToggleSelected:r,onOpenDetail:o}){return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden rounded-sm border border-border/60 bg-card/35",children:[e.jsxs("div",{className:M("grid shrink-0 gap-2 border-b border-border/55 bg-primary/6 px-2 py-1.5 text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",ia),children:[e.jsx("span",{}),e.jsx("span",{children:"Agent"}),e.jsx("span",{children:"Kind"}),e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Ver"}),e.jsx("span",{children:"Size"}),e.jsx("span",{children:"Source"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:t.length>0?t.map(i=>e.jsxs("button",{type:"button",onClick:()=>o(i),className:M("grid h-7 w-full items-center gap-2 border-b border-border/30 px-2 text-left text-[10px] transition-colors hover:bg-primary/6",ia,n===i.id&&"bg-primary/10 text-primary shadow-[inset_2px_0_0_hsl(var(--primary))]"),children:[e.jsx("span",{onClick:d=>d.stopPropagation(),children:e.jsx(Ht,{className:"h-3 w-3",checked:s.has(i.id),onCheckedChange:d=>r(i.id,d===!0),"aria-label":`Select ${i.name}`})}),e.jsx(ou,{agent:i.agent}),e.jsx("span",{children:i.kind}),e.jsx("span",{className:"truncate font-medium text-foreground",children:i.name}),e.jsx("span",{className:"truncate text-muted-foreground",children:i.version??"-"}),e.jsx("span",{className:"truncate text-muted-foreground",children:ir(i)}),e.jsx("span",{className:"truncate text-muted-foreground",children:i.source??"local"})]},i.id)):e.jsx("div",{className:"px-3 py-8 text-center text-[11px] text-muted-foreground",children:"No capabilities match this view."})})]})}function ou({agent:t}){const s=nu[t];return e.jsx("span",{className:"block min-w-0 truncate text-[10px] font-medium leading-3 text-muted-foreground",title:s,children:s})}const la=320,da=560,lr=384,ca=360;function iu(t,s=da+ca){const n=Math.max(la,Math.min(da,s-ca));return Math.min(Math.max(Math.round(t),la),n)}function lu(t,s,n,r){return iu(t+s-n,r)}function du({detail:t,deleting:s=!1,onDelete:n,desktopWidth:r=lr,pending:o=!1}){const i={"--capability-detail-width":`${r}px`};if(!t)return e.jsx("aside",{"data-capability-detail-panel":"true",style:i,className:"hidden min-h-0 shrink-0 animate-panel-settle bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-3 text-[11px] text-muted-foreground lg:block lg:w-[var(--capability-detail-width)]",children:o?"Loading capability metadata...":"No capability selected."});const d=t.kind==="mcp"?"mcp":"files";return e.jsxs("aside",{"data-capability-detail-panel":"true",style:i,className:"flex min-h-0 w-full shrink-0 animate-panel-settle flex-col bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-2.5 lg:w-[var(--capability-detail-width)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold leading-5 text-foreground",children:t.name}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-1",children:[e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary",children:t.agent}),e.jsx($e,{variant:"outline",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary/90",children:t.kind})]})]}),n&&e.jsxs(ns,{children:[e.jsx(Is,{asChild:!0,children:e.jsx(W,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground hover:text-destructive","aria-label":"Delete capability",title:"Delete capability",disabled:s,children:e.jsx(Ra,{className:"h-3.5 w-3.5"})})}),e.jsxs(as,{className:"max-w-[22rem] gap-2 rounded-xl p-4",children:[e.jsxs(rs,{className:"space-y-1",children:[e.jsxs(os,{className:"text-sm",children:["Delete ",t.name,"?"]}),e.jsxs(is,{className:"text-[11px] leading-4",children:["This removes the selected ",t.kind," from ",t.scope.kind==="global"?"the user profile":"this project","."]})]}),e.jsxs(ls,{className:"gap-1 pt-0 sm:space-x-1",children:[e.jsx(ds,{className:"h-7 rounded-lg px-2 text-[11px]",children:"Cancel"}),e.jsx(cs,{className:"h-7 rounded-lg px-2 text-[11px]",onClick:n,disabled:s,children:"Delete"})]})]})]})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-1 text-[9px]",children:[e.jsx(ss,{label:"Version",value:t.version??"-"}),e.jsx(ss,{label:"Size",value:ir(t)}),e.jsx(ss,{label:"Files",value:String(t.fileCount)}),e.jsx(ss,{label:"Source",value:t.source??"local"})]}),e.jsxs(Ys,{defaultValue:d,className:"mt-2 flex min-h-0 flex-1 flex-col",children:[e.jsxs(Ws,{className:"grid h-auto grid-cols-2 rounded-sm bg-primary/8 p-0.5",children:[t.kind==="mcp"?e.jsx(bt,{value:"mcp",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"MCP"}):e.jsx(bt,{value:"files",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"Files"}),e.jsx(bt,{value:"readme",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"README"})]}),t.kind==="mcp"?e.jsx(nt,{value:"mcp",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(cu,{detail:t})}):e.jsx(nt,{value:"files",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(uu,{detail:t})}),e.jsx(nt,{value:"readme",className:"mt-2 min-h-0 flex-1 overflow-auto",children:t.readmeMarkdown?e.jsx(Ri,{content:t.readmeMarkdown,className:"overflow-hidden rounded-sm border-0 bg-background/70 shadow-none [&>div:first-child>div]:border-0 [&>div:first-child]:border-b-0",previewClassName:"px-3 py-2 text-[11px] leading-5",rawClassName:"text-[10px] leading-4"}):e.jsx(ln,{children:"No README content."})})]},t.id)]})}function cu({detail:t}){const s=t.mcpPreview??[];return s.length===0?e.jsx(ln,{children:"No MCP entries."}):e.jsx("div",{className:"space-y-1.5",children:s.map(n=>e.jsxs("div",{className:"rounded-sm bg-card/72 p-2 text-[10px] shadow-none",children:[e.jsx("div",{className:"font-semibold text-foreground",children:n.serverName}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto rounded-sm bg-background/55 px-2 py-1 whitespace-pre-wrap break-all font-mono text-[9px] leading-4 text-muted-foreground",children:JSON.stringify(n.config,null,2)})]},n.serverName))})}function uu({detail:t}){const s=t.fileTree??[];return s.length===0?e.jsx(ln,{children:"No files."}):e.jsx("div",{className:"space-y-1 overflow-auto rounded-sm bg-card/72 p-2 font-mono text-[9px] leading-4 text-muted-foreground shadow-none",children:s.map(n=>e.jsx("div",{children:n.relPath},n.relPath))})}function ln({children:t}){return e.jsx("div",{className:"rounded-sm bg-primary/5 px-2 py-6 text-center text-[10px] text-muted-foreground",children:t})}function ss({label:t,value:s}){return e.jsxs("div",{className:"rounded-sm bg-card/72 px-2 py-0.5 shadow-none",children:[e.jsx("div",{className:"text-[7px] uppercase tracking-[0.14em] text-muted-foreground",children:t}),e.jsx("div",{className:"truncate text-[9px] font-medium text-foreground",children:s})]})}const mu=20,xu=288,hu=360,pu=440;function fu(){if(typeof window>"u"||typeof document>"u")return 1;const t=window.getComputedStyle(document.documentElement),s=t.zoom||t.getPropertyValue("--ui-zoom"),n=Number.parseFloat(s);return Number.isFinite(n)&&n>0?n:1}function gu({triggerRect:t,targetRect:s,viewportRect:n,compact:r,browserOpen:o=!1,portalAlign:i,cssZoom:d=1}){const c=Number.isFinite(d)&&d>0?d:1,g=8,p=n.top+g,k=n.bottom-g,h=n.left+g,l=n.right-g,N=Math.max(0,k-t.bottom-4),T=Math.max(0,t.top-p-4),w=r?T<140&&N>T:N>=220||N>=T,_=w?N:T,f=Math.max(140,k-p),S=r&&o,y=Math.min(f,S?pu:320,Math.max(S?hu:140,_)),C=xu*c,E=i==="end"?t.right-C:t.left,D=(Math.max(h,Math.min(E,l-C))-s.left)/c;if(!w&&!S)return{left:D,bottom:(s.bottom-(t.top-4))/c,maxHeight:y/c};const z=w?t.bottom+4:t.top-y-4,P=Math.max(p,Math.min(z,k-y));return{left:D,top:(P-s.top)/c,maxHeight:y/c}}function dn(t){if(!t.workDir)return[];const s=[],n=new Set,r=o=>{!o||n.has(o)||(n.add(o),s.push(o))};r(t.workDir);for(const o of t.workDirFolders??[])r(cr(o)?o:ur(t.workDir,o));return s}function bu(t,s){if(t.kind==="global")return{nodeId:s.id,scope:{kind:"global"}};const n=dn(s),r=n.find(o=>o===t.projectPath);return r?{nodeId:s.id,scope:{kind:"project",projectPath:r}}:n[0]?{nodeId:s.id,scope:{kind:"project",projectPath:n[0]}}:{nodeId:s.id,scope:{kind:"global"}}}function vu(t,s){return{nodeId:t,scope:s}}function ua(t,s,n){const r=s.trim();return!r||r==="."?t.workDir??r:n||cr(r)?r:t.workDir?ur(t.workDir,r):r}function ju({node:t,scope:s,clusterNodes:n,onSelectionChange:r}){const o=a.useMemo(()=>ku(n,t),[n,t]),i=a.useMemo(()=>dn(t),[t]),d=a.useMemo(()=>o.map(c=>({value:c.id,label:c.name,description:`${c.role} · ${c.status}`,status:c.status})),[o]);return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-2",children:[e.jsx(Nu,{ariaLabel:"Capability node",value:t.name,description:`${t.role} · ${t.status}`,options:d,selectedValue:t.id,onSelect:c=>{const g=o.find(p=>p.id===c);g&&(r==null||r(bu(s,g)))}}),e.jsx(dr,{node:t,projectPaths:i,selectedScope:s,onSelect:c=>r==null?void 0:r(vu(t.id,c))}),e.jsx(wu,{node:t})]})}function wu({node:t}){return e.jsxs("div",{"data-capability-node-meta":"true",className:"flex min-w-0 items-center gap-1 border-0 bg-transparent px-0.5 text-[8px] leading-3 text-muted-foreground",title:`${t.role} · ${t.status}`,children:[e.jsx("span",{className:"truncate capitalize",children:t.role}),e.jsx("span",{className:M("h-1.5 w-1.5 shrink-0 rounded-full",Ft(t.status))})]})}function dr({node:t,projectPaths:s,selectedScope:n,onSelect:r,compact:o=!1,portal:i=!1,portalAlign:d="start"}){const[c,g]=a.useState(!1),[p,k]=a.useState(null),[h,l]=a.useState(!1),[N,T]=a.useState(!1),[w,_]=a.useState(null),[f,S]=a.useState(!1),[b,v]=a.useState(null),y=a.useRef(null),C=a.useRef(null),E=a.useRef(null),q=a.useMemo(()=>s.map(L=>({value:L,label:xa(L),description:L})),[s]),D=n.kind==="project"?n.projectPath:void 0,z=n.kind==="global"?"Global":xa(n.projectPath),P=n.kind==="global"?"Global":n.projectPath,Z=a.useCallback(()=>{var L;return!i||typeof document>"u"?null:((L=C.current)==null?void 0:L.closest('[data-capability-share-dialog="true"]'))??document.body},[i]),U=a.useCallback(()=>{if(!i||!C.current||typeof window>"u")return;const L=C.current.getBoundingClientRect(),H=Z(),m=H&&H!==document.body?H.getBoundingClientRect():{left:0,top:0,bottom:window.innerHeight};v(gu({triggerRect:L,targetRect:m,viewportRect:{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},compact:o,browserOpen:f,portalAlign:d,cssZoom:fu()}))},[f,o,Z,i,d]);a.useEffect(()=>{c||S(!1)},[c]),a.useEffect(()=>{if(!c)return;const L=H=>{if(!(H.target instanceof Node))return;const m=H.composedPath(),V=y.current?m.includes(y.current):!1,x=E.current?m.includes(E.current):H.target instanceof Element&&!!H.target.closest('[data-capability-scope-menu="true"]');!V&&!x&&g(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[c]),a.useEffect(()=>{if(!(!c||!i))return U(),window.addEventListener("resize",U),window.addEventListener("scroll",U,!0),()=>{window.removeEventListener("resize",U),window.removeEventListener("scroll",U,!0)}},[c,i,U]);const R=async(L,H=0,m=!1)=>{if(t.workDir){_(null),m?T(!0):l(!0);try{const V=await ba(t.id,{path:L||".",limit:mu,offset:H,directoriesOnly:!0,allowAbsolute:!0});k(x=>m&&x?{...V,entries:[...x.entries,...V.entries]}:V)}catch(V){_(V instanceof Error?V.message:"Failed to browse folders"),m||k(null)}finally{l(!1),T(!1)}}};a.useEffect(()=>{!c||!f||!t.workDir||(k(null),_(null),R(D||"."))},[f,c,t.id,t.workDir,D]);const B=(L,H=!1)=>{r({kind:"project",projectPath:ua(t,L,H)}),g(!1)},ae=()=>{r({kind:"global"}),g(!1)},re=p?ua(t,p.currentPath,p.isAbsolute):D??t.workDir??"",oe=i?Z():null,ne=e.jsxs("div",{ref:E,"data-capability-scope-menu":"true","aria-hidden":!c,onClick:L=>L.stopPropagation(),onMouseDown:L=>L.stopPropagation(),onPointerDown:L=>L.stopPropagation(),style:i&&b?{left:b.left,top:b.top,bottom:b.bottom,height:o&&f?b.maxHeight:void 0,maxHeight:b.maxHeight}:void 0,className:M(i?"absolute z-[80] flex w-72 flex-col overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none pointer-events-auto":"absolute left-0 z-50 flex max-h-[28rem] w-72 flex-col overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!i&&(o?"top-7":"top-9"),!c&&"hidden"),children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 p-1",children:[e.jsx("div",{className:M("px-2 text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",o?"pb-0.5 pt-0.5 leading-3":"pb-1 pt-1"),children:"Scope"}),e.jsxs("div",{className:M("overflow-y-auto pr-0.5",o?"max-h-32":"max-h-40"),children:[e.jsx(ma,{icon:"global",label:"Global",selected:n.kind==="global",onSelect:ae,compact:o}),q.length>0?q.map(L=>e.jsx(ma,{icon:"folder",label:L.label,description:L.description,selected:D===L.value,onSelect:()=>B(L.value,!0),compact:o},L.value)):e.jsx("div",{className:M("flex items-center px-2 text-muted-foreground",o?"h-7 text-[9px]":"h-8 text-[10px]"),children:"No known projects"})]})]}),e.jsxs("div",{className:M("border-b border-border/55",f?"flex min-h-0 flex-1 flex-col":"shrink-0"),children:[e.jsxs("button",{type:"button","aria-expanded":f,onClick:()=>S(L=>!L),className:M("flex w-full items-center gap-1 px-2 text-left text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground transition-colors hover:bg-muted/45 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",o?"py-1 leading-3":"py-1.5"),children:[e.jsx(At,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Browse folders"}),e.jsx(Je,{className:M("h-3 w-3 shrink-0 transition-transform duration-200",f&&"rotate-180")})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"shrink-0 px-2 pb-1.5",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>(p==null?void 0:p.parentPath)&&void R(p.parentPath),disabled:!(p!=null&&p.parentPath)||h,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(Pa,{className:"h-2.5 w-2.5"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[9px] text-muted-foreground",title:re,children:re}),p&&e.jsx("button",{type:"button",onClick:()=>B(p.currentPath,p.isAbsolute),className:"shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium text-foreground hover:bg-muted/60",title:"Use this folder",children:"Use"})]})}),e.jsxs("div",{className:M("min-h-0 flex-1 overflow-y-auto",o?"min-h-[8.25rem]":"max-h-56"),children:[t.workDir?h?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[9px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading folders..."]}):p&&p.entries.length>0?e.jsxs(e.Fragment,{children:[p.entries.map(L=>e.jsx(yu,{entry:L,onSelect:()=>B(L.path,p.isAbsolute),onOpen:()=>void R(L.path)},L.path)),p.hasMore&&e.jsxs("button",{type:"button",onClick:()=>void R(p.currentPath,p.entries.length,!0),disabled:N,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[9px] text-muted-foreground hover:bg-muted/60 hover:text-foreground disabled:opacity-50",children:[N?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Qi,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:w??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:"This node has no working directory."}),w&&p&&p.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[9px] text-destructive",children:w})]})]})]})]});return e.jsxs("div",{ref:y,className:"relative min-w-0",children:[e.jsxs("button",{ref:C,type:"button","aria-label":"Capability location","aria-expanded":c,title:P,onClick:()=>g(L=>(L||(S(!1),U()),!L)),className:M("flex min-w-0 items-center gap-1.5 rounded-sm border-0 bg-muted/55 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",o?"h-5 w-24 max-w-28 px-1.5":"h-7 min-w-32 max-w-56 px-2"),children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:M("block truncate font-medium text-foreground",o?"text-[9px] leading-3":"text-[10px] leading-4"),children:z})}),e.jsx(Je,{className:M(o?"h-2.5 w-2.5":"h-3 w-3","shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),i&&oe?ka.createPortal(ne,oe):ne]})}function ma({icon:t,label:s,description:n,selected:r,onSelect:o,compact:i=!1}){const d=t==="global"?Gi:At;return e.jsxs("button",{type:"button",onClick:o,className:M(i?"flex h-7 w-full items-center gap-1.5 rounded-md px-2 text-left text-[9px]":"flex h-8 w-full items-center gap-1.5 rounded-md px-2 text-left text-[10px]","transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",r&&"bg-primary/10 text-primary"),children:[e.jsx(d,{className:M("shrink-0 text-muted-foreground",i?"h-2.5 w-2.5":"h-3 w-3",r&&"text-primary")}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col justify-center",children:[e.jsx("span",{className:"block truncate font-medium leading-3",children:s}),n&&e.jsx("span",{className:M("block truncate text-muted-foreground",i?"text-[7px] leading-3":"text-[8px] leading-3"),children:n})]})]})}function yu({entry:t,onOpen:s,onSelect:n}){return e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:n,className:"flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1 text-left text-[9px] hover:bg-muted/55",title:`Use ${t.path}`,children:[e.jsx(At,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-foreground",children:t.name})]}),e.jsx("button",{type:"button",onClick:s,className:"flex w-7 shrink-0 items-center justify-center border-l border-border/30 text-muted-foreground hover:bg-muted/65 hover:text-foreground",title:"Open subfolder","aria-label":`Open ${t.name}`,children:e.jsx(Fe,{className:"h-3 w-3"})})]})}function Nu({ariaLabel:t,value:s,description:n,options:r,selectedValue:o,onSelect:i}){const[d,c]=a.useState(!1),g=a.useRef(null);return a.useEffect(()=>{if(!d)return;const p=k=>{g.current&&k.target instanceof Node&&!g.current.contains(k.target)&&c(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[d]),e.jsxs("div",{ref:g,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":t,"aria-expanded":d,title:n??s,onClick:()=>c(p=>!p),className:"flex h-7 min-w-32 max-w-56 items-center gap-1.5 rounded-sm border-0 bg-muted/55 px-2 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:"block truncate text-[10px] font-medium leading-4 text-foreground",children:s})}),e.jsx(Je,{className:M("h-3 w-3 shrink-0 text-muted-foreground transition-transform",d&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!d,className:M("absolute left-0 top-9 z-50 w-64 overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!d&&"hidden"),children:e.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:r.length>0?r.map(p=>e.jsxs("button",{type:"button",onClick:()=>{i(p.value),c(!1)},className:M("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[11px] transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",p.value===o&&"bg-primary/10 text-primary"),children:[p.status&&e.jsx("span",{className:M("h-1.5 w-1.5 shrink-0 rounded-full",Ft(p.status))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:p.label}),p.description&&e.jsx("span",{className:"block truncate text-[9px] text-muted-foreground",children:p.description})]})]},p.value)):e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No projects"})})})]})}function ku(t,s){const n=new Map;for(const r of t)n.set(r.id,r);return n.set(s.id,s),Array.from(n.values())}function Ft(t){return t==="online"?"bg-emerald-500":t==="offline"?"bg-muted-foreground/45":"bg-amber-500"}function xa(t){return t.split(/[\\/]+/).filter(Boolean).at(-1)??t}function cr(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)}function ur(t,s){return`${t.replace(/[\\/]+$/,"")}/${s.replace(/^[\\/]+/,"")}`}const Su="h-6 w-24 rounded-sm px-2 text-[10px] shadow-none",Ps="text-[10px]",mr=["claudecode","codex","copilot"],zt={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Cu({open:t,sourceNode:s,targetNodes:n,selectedCapabilities:r,previewResults:o=[],embedded:i=!1,onClose:d,onPreviewTargetsChange:c,onShare:g}){const[p,k]=a.useState(()=>new Set(o.length>0?o.map(m=>Ye(m.nodeId,m.targetAgent)):Tu(s.id,n,r))),[h,l]=a.useState(()=>Object.fromEntries(Eu(s.id,n,r))),[N,T]=a.useState({}),[w,_]=a.useState(!1),[f,S]=a.useState(()=>new Set),[b,v]=a.useState(()=>new Set),y=r.some(m=>m.kind==="plugin"),C=a.useMemo(()=>cn(r).map(m=>({key:Ye(s.id,m),nodeId:s.id,node:s,label:`Install into ${zt[m]}`,agentLabel:zt[m],defaultScope:hr(r),disabled:!1,targetAgent:m})),[r,s]),E=a.useMemo(()=>n.flatMap(m=>{const V={kind:"global"},x=m.status==="offline",Q=xr(r);return Q.length===0?[{key:Ye(m.id),nodeId:m.id,node:m,label:m.name,defaultScope:V,disabled:x}]:Q.map(A=>({key:Ye(m.id,A),nodeId:m.id,node:m,label:`${m.name} / ${zt[A]}`,agentLabel:zt[A],defaultScope:V,disabled:x,targetAgent:A}))}),[r,n]),q=a.useMemo(()=>[...C,...E],[C,E]),D=a.useMemo(()=>n.map(m=>({node:m,options:E.filter(V=>V.nodeId===m.id)})).filter(m=>m.options.length>0),[n,E]),z=a.useMemo(()=>new Map(o.filter(m=>m.capabilityId).map(m=>[ha(m.nodeId,m.capabilityId,m.targetAgent),m])),[o]),P=a.useMemo(()=>new Map(o.map(m=>[Ye(m.nodeId,m.targetAgent),m])),[o]),Z=a.useMemo(()=>q.filter(m=>p.has(m.key)),[p,q]),U=a.useMemo(()=>Z.map(m=>({nodeId:m.nodeId,scope:h[m.key]??m.defaultScope,...m.targetAgent?{targetAgent:m.targetAgent}:{}})),[Z,h]),R=a.useMemo(()=>{const m=[],V=new Map;for(const x of Z){if(!V.has(x.nodeId)){const Q=x.nodeId===s.id?s:n.find(A=>A.id===x.nodeId);V.set(x.nodeId,{nodeId:x.nodeId,node:Q,name:(Q==null?void 0:Q.name)??x.nodeId,options:[]}),m.push(x.nodeId)}V.get(x.nodeId).options.push(x)}return m.map(x=>V.get(x))},[Z,s,n]),B=a.useMemo(()=>{const m=Array.from(new Set(r.map(x=>x.agent))),[V]=m;if(V)return m.length===1?zt[V]:`${m.length} agents`},[r]),ae=D.length+1;a.useEffect(()=>{let m=!1;const V={...h};for(const x of q)V[x.key]||(V[x.key]=x.defaultScope,m=!0);m&&l(V)},[q,h]),a.useEffect(()=>{t&&(c==null||c(U))},[t,c,U]),a.useEffect(()=>{t&&(S(new Set),v(new Set))},[t,s.id]),a.useEffect(()=>{if(!i||!t)return;const m=V=>{V.key==="Escape"&&d()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[i,d,t]);const re=m=>{T(Object.fromEntries(Z.map(V=>[V.key,m])))},oe=async()=>{_(!0);try{await g(Z.map(m=>({nodeId:m.nodeId,scope:h[m.key]??m.defaultScope,...m.targetAgent?{targetAgent:m.targetAgent}:{},conflictStrategy:N[m.key]??"overwrite"})))}finally{_(!1)}},ne=m=>{const V=h[m.key]??m.defaultScope,x=`capability-share-target-${_u(m.key)}`,Q=p.has(m.key);return e.jsxs("div",{"data-target-agent":m.targetAgent,className:"flex min-h-6 items-center gap-2 px-2 py-0.5 transition-colors hover:bg-muted/35 data-[disabled=true]:opacity-55","data-disabled":m.disabled?"true":void 0,children:[e.jsx(Ht,{id:x,disabled:m.disabled,checked:Q,onCheckedChange:A=>k(G=>{const j=new Set(G);return A===!0?j.add(m.key):j.delete(m.key),j}),"aria-label":`Select ${m.label} as a share target`,"data-share-target-checkbox":!0,className:"h-3.5 w-3.5 border-border/70 bg-background/80 shadow-none data-[state=checked]:border-primary data-[state=checked]:bg-primary [&_svg]:h-3 [&_svg]:w-3"}),e.jsx("label",{htmlFor:x,className:"min-w-0 flex-1 cursor-pointer truncate text-[10px] font-medium leading-4 text-foreground data-[disabled=true]:cursor-not-allowed","data-disabled":m.disabled?"true":void 0,children:m.agentLabel??m.label}),e.jsx("div",{className:"flex w-28 shrink-0 justify-end",children:Q&&!m.disabled&&e.jsx(dr,{node:m.node,projectPaths:dn(m.node),selectedScope:V,onSelect:A=>l(G=>({...G,[m.key]:A})),compact:!0,portal:!0,portalAlign:"end"})})]},m.key)},L=(m,V,x,Q)=>{const A=f.has(m.id),G=Z.filter(j=>j.nodeId===m.id).length;return e.jsxs("div",{className:"overflow-hidden rounded-sm border border-border/45 bg-muted/15",children:[e.jsxs("button",{type:"button","aria-expanded":A,onClick:()=>S(j=>pa(j,m.id)),className:"flex w-full items-center gap-2 border-b border-border/35 bg-primary/5 px-2 py-1.5 text-left transition-colors hover:bg-primary/10",children:[e.jsx(Fe,{className:M("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",A&&"rotate-90")}),e.jsx("span",{className:M("h-1.5 w-1.5 shrink-0 rounded-full",Ft(m.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold text-foreground",title:m.name,children:m.name}),G>0&&e.jsxs("span",{className:"shrink-0 text-[8px] font-medium text-primary",children:[G," selected"]}),e.jsx("span",{className:"shrink-0 text-[8px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:V?"this node":"remote"}),m.status==="offline"&&e.jsx($e,{variant:"outline",className:"rounded-sm px-1 py-0 text-[8px]",children:"offline"}),Q>0&&e.jsxs("span",{className:"sr-only",children:[Q," agents"]})]}),e.jsx("div",{className:M("grid transition-[grid-template-rows] duration-200 ease-out",A?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsx("div",{className:"divide-y divide-border/25",children:x})})})]},m.id)},H=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-b border-border/55 px-4 py-3 text-left",children:[e.jsxs("h2",{id:"capability-share-title",className:"flex items-center gap-2 text-sm font-semibold leading-none tracking-tight",children:[e.jsx(xs,{className:"h-4 w-4 text-primary"}),"Share ",r.length," ",r.length===1?"capability":"capabilities"]}),e.jsx("p",{id:"capability-share-description",className:"mt-1.5 text-[11px] text-muted-foreground",children:"Copies each capability into the matching agent on the selected targets. Plugins install into their matching agent."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2.5 gap-y-1 border-b border-border/55 bg-muted/15 px-4 py-2 text-[11px]",children:[e.jsx("span",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Source"}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:M("h-1.5 w-1.5 shrink-0 rounded-full",Ft(s.status))}),e.jsx("span",{className:"truncate font-semibold text-foreground",title:s.name,children:s.name}),B&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:["· ",B]})]}),e.jsx(Ln,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Targets"}),e.jsxs("span",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:Z.length})," selected · ",ae," ",ae===1?"node":"nodes"]})]}),e.jsxs("div",{className:"grid gap-4 p-4 lg:grid-cols-[17rem_minmax(0,1fr)]",children:[e.jsx("section",{className:"min-w-0",children:e.jsxs("div",{className:"max-h-[56vh] space-y-2 overflow-y-auto pr-0.5",children:[L(s,!0,y?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"Cross-agent plugin installs are not supported."}):C.length===0?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No alternate agents available for this selection."}):C.map(ne),C.length),D.map(m=>L(m.node,!1,m.options.map(ne),m.options.length))]})}),e.jsxs("section",{className:"min-w-0",children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Conflict preview"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[8px] uppercase tracking-[0.12em] text-muted-foreground/70",children:"Set all"}),e.jsx("div",{className:"inline-flex items-center rounded-sm border border-border/55 bg-muted/20 p-px",children:["overwrite","skip","abort"].map(m=>e.jsx("button",{type:"button",onClick:()=>re(m),className:"h-5 rounded-[3px] px-1.5 text-[9px] capitalize text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground",children:m},m))})]})]}),e.jsx("div",{className:"max-h-[56vh] min-h-32 overflow-y-auto rounded-sm border border-border/55 bg-background/45 p-2",children:Z.length===0?e.jsx("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"Select a target to preview conflicts."}):R.map(m=>{const V=!b.has(m.nodeId);return e.jsxs("div",{className:"mb-1.5 overflow-hidden rounded-sm border border-border/35 bg-muted/10 last:mb-0",children:[e.jsxs("button",{type:"button","aria-expanded":V,onClick:()=>v(x=>pa(x,m.nodeId)),className:"flex w-full items-center gap-1.5 border-b border-border/30 bg-primary/5 px-2 py-1 text-left transition-colors hover:bg-primary/10",children:[e.jsx(Fe,{className:M("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",V&&"rotate-90")}),m.node&&e.jsx("span",{className:M("h-1.5 w-1.5 shrink-0 rounded-full",Ft(m.node.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-semibold text-foreground",children:m.name}),e.jsxs("span",{className:"shrink-0 text-[8px] text-muted-foreground",children:[m.options.length," ",m.options.length===1?"agent":"agents"]})]}),e.jsx("div",{className:M("grid transition-[grid-template-rows] duration-200 ease-out",V?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsx("div",{className:"space-y-1 p-1.5",children:m.options.map(x=>{const Q=N[x.key]??"overwrite";return e.jsxs("div",{className:"rounded-sm bg-background/45 px-2 py-1",children:[e.jsxs("div",{className:"mb-0.5 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[9px] font-medium leading-4 text-foreground",children:x.agentLabel??"Matching agent"}),e.jsxs(Se,{value:Q,onValueChange:A=>T(G=>({...G,[x.key]:A})),children:[e.jsx(Ce,{className:Su,children:e.jsx(Le,{})}),e.jsxs(_e,{className:"shadow-none",children:[e.jsx(he,{value:"overwrite",className:Ps,children:"Overwrite"}),e.jsx(he,{value:"skip",className:Ps,children:"Skip"}),e.jsx(he,{value:"abort",className:Ps,children:"Abort"})]})]})]}),e.jsx("div",{className:"space-y-px",children:r.map(A=>{const G=z.get(ha(x.nodeId,A.id,x.targetAgent))??(r.length===1?P.get(x.key):void 0);return e.jsxs("div",{className:"flex items-center gap-1.5 text-[9px] leading-4",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:A.name}),e.jsx("span",{className:G!=null&&G.conflict?"text-amber-500":G?"text-emerald-500":"text-muted-foreground",children:G?G.conflict?`exists${G.currentVersion?` v${G.currentVersion}`:""}`:"new install":"checking"}),(G==null?void 0:G.sourceVersion)&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[e.jsx(Ln,{className:"inline h-2.5 w-2.5"})," v",G.sourceVersion]})]},A.id)})})]},x.key)})})})})]},m.nodeId)})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-border/55 px-4 py-3",children:[e.jsx(W,{variant:"ghost",onClick:d,className:"h-7 rounded-sm px-3 text-[11px]",children:"Cancel"}),e.jsxs(W,{onClick:oe,disabled:w||Z.length===0,className:"h-7 rounded-sm px-3 text-[11px]",children:[w?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(xs,{className:"h-3.5 w-3.5"}),"Share"]})]})]});return i?t?e.jsx("div",{className:"absolute inset-0 z-[80] flex items-center justify-center bg-background/70 p-4 backdrop-blur-[2px]",onMouseDown:m=>{m.target===m.currentTarget&&d()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"capability-share-title","aria-describedby":"capability-share-description","data-capability-share-dialog":"true",className:"relative grid w-full max-w-3xl gap-0 overflow-visible rounded-xl border-0 bg-background text-foreground shadow-[0_34px_110px_-54px_rgba(0,0,0,0.55)]",onMouseDown:m=>m.stopPropagation(),children:[H,e.jsxs("button",{type:"button",onClick:d,className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:[e.jsx(Xe,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})}):null:e.jsx(Mt,{open:t,onOpenChange:m=>{m||d()},children:e.jsx(Pt,{"aria-labelledby":"capability-share-title","aria-describedby":"capability-share-description","data-capability-share-dialog":"true",className:"max-w-3xl gap-0 overflow-visible rounded-xl border-0 p-0",children:H})})}function Ye(t,s){return s?`agent:${t}:${s}`:`node:${t}`}function _u(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-")}function ha(t,s,n){return`${Ye(t,n)}\0${s}`}function pa(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function Tu(t,s,n){const r=s.find(i=>i.status!=="offline");if(r)return[Ye(r.id,Du(n))];const o=cn(n)[0];return o?[Ye(t,o)]:[]}function Eu(t,s,n){const r=xr(n);return[...s.flatMap(o=>r.length===0?[[Ye(o.id),{kind:"global"}]]:r.map(i=>[Ye(o.id,i),{kind:"global"}])),...cn(n).map(o=>[Ye(t,o),hr(n)])]}function xr(t){return t.length===0||t.some(s=>s.kind==="plugin")?[]:mr}function Du(t){var s;if(!(t.length===0||t.some(n=>n.kind==="plugin")))return(s=t[0])==null?void 0:s.agent}function cn(t){if(t.length===0||t.some(n=>n.kind==="plugin"))return[];const s=new Set(t.map(n=>n.agent));return mr.filter(n=>!s.has(n))}function hr(t){var s;return((s=t[0])==null?void 0:s.scope)??{kind:"global"}}const fa="h-7 rounded-sm border-0 bg-muted/55 px-2 text-[9px] leading-none shadow-none hover:bg-muted/70 [&>svg]:h-3 [&>svg]:w-3",dt="py-0.5 pl-6 pr-1.5 text-[9px] leading-4 [&_svg]:h-3 [&_svg]:w-3",pr="h-5 rounded-sm bg-muted/55 px-1.5 text-[9px] font-medium text-foreground shadow-none border-0 hover:bg-muted/75 hover:text-foreground disabled:text-muted-foreground [&_svg]:size-2.5",Au="h-5 rounded-sm bg-primary px-2 text-[9px] font-medium text-primary-foreground shadow-none border-0 hover:bg-primary/90 hover:text-primary-foreground disabled:bg-primary/45 disabled:text-primary-foreground/80 [&_svg]:size-2.5";function Mu(t,s,n,r){return n.map(o=>({sourceNodeId:t,capabilityId:o.id,sourceScope:s,targets:r.map(i=>({nodeId:i.nodeId,scope:i.scope,...i.targetAgent?{targetAgent:i.targetAgent}:{}}))}))}function Pu(t,s,n,r){return n.map(o=>({sourceNodeId:t,capabilityId:o.id,sourceScope:s,targets:r}))}function Lu({loading:t,onRefresh:s}){return e.jsxs(W,{variant:"ghost",onClick:s,disabled:t,"aria-busy":t,className:M(pr,"min-w-[4.5rem]"),children:[e.jsx(Ia,{className:M("h-2.5 w-2.5",t&&"animate-spin")}),t?"Refreshing":"Refresh"]})}function Iu({selectedCount:t,loading:s,onClearSelection:n,onRefresh:r,onShare:o}){return e.jsxs("div",{className:"flex items-center justify-between gap-2 bg-card/15 px-0.5 pt-1.5 text-[9px] text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(W,{type:"button",variant:"ghost",onClick:n,disabled:t===0,className:pr,children:[e.jsx(Xe,{className:"h-2.5 w-2.5"}),"Selected: ",t," / Clear"]})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Lu,{loading:s,onRefresh:r}),e.jsxs(W,{type:"button",variant:"ghost",onClick:o,disabled:t===0,className:Au,children:[e.jsx(xs,{className:"h-2.5 w-2.5"}),"Share"]})]})]})}function Bu({onBeginResize:t,onFold:s}){const n=r=>{r.key!=="Enter"&&r.key!==" "||(r.preventDefault(),s())};return e.jsx("div",{role:"separator","aria-label":"Fold capability detail panel","aria-orientation":"vertical",title:"Fold details",tabIndex:0,onClick:s,onKeyDown:n,onPointerDown:t,className:"hidden w-1 shrink-0 cursor-col-resize items-center justify-center bg-primary/10 transition-colors hover:bg-primary/22 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 lg:flex",children:e.jsx("span",{className:"h-8 w-px rounded-full bg-primary/45"})})}function Ru({visible:t}){return t?e.jsx("div",{className:"absolute inset-2.5 z-10 flex items-center justify-center rounded-sm border border-border/60 bg-background/85 shadow-sm backdrop-blur-sm",children:e.jsxs("div",{className:"flex w-full max-w-80 flex-col items-center gap-3 px-5 text-center",children:[e.jsxs("div",{className:"relative flex h-10 w-10 items-center justify-center rounded-full border border-primary/25 bg-primary/8",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border border-primary/20 animate-ping"}),e.jsx(ue,{className:"relative h-4 w-4 animate-spin text-primary"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:"Loading capabilities"}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Reading agent skills, plugins, and MCP servers for this selection."})]}),e.jsxs("div",{className:"grid w-full gap-1.5","aria-hidden":"true",children:[e.jsx("span",{className:"h-1.5 rounded-full bg-muted animate-pulse"}),e.jsx("span",{className:"mx-auto h-1.5 w-3/4 rounded-full bg-muted/70 animate-pulse"})]})]})}):null}function $u({open:t,node:s,scope:n,clusterNodes:r,onOpenChange:o,onSelectionChange:i}){const[d,c]=a.useState([]),[g,p]=a.useState([]),[k,h]=a.useState(!1),[l,N]=a.useState(""),[T,w]=a.useState("all"),[_,f]=a.useState("all"),[S,b]=a.useState(new Set),[v,y]=a.useState(null),[C,E]=a.useState(null),[q,D]=a.useState(!1),[z,P]=a.useState(null),[Z,U]=a.useState(!1),[R,B]=a.useState([]),[ae,re]=a.useState(lr),[oe,ne]=a.useState(null),L=a.useMemo(()=>au(d,{search:l,agent:T,kind:_}),[T,d,_,l]),H=a.useMemo(()=>d.filter($=>S.has($.id)),[d,S]),m=a.useMemo(()=>r.filter($=>$.id!==s.id),[r,s.id]),V=n.kind==="project"?n.projectPath:"global",x=async()=>{h(!0);try{const $=await Zo(s.id,{scope:n});c($.items),p(($.errors??[]).map(J=>`${J.agent}: ${J.message}`))}catch($){p([$ instanceof Error?$.message:"Failed to load capabilities"])}finally{h(!1)}};a.useEffect(()=>{t&&(b(new Set),y(null),E(null),D(!1),B([]),c([]),p([]),x())},[t,s.id,n.kind,V]),a.useEffect(()=>{if(!oe)return;const $=de=>{re(lu(oe.startWidth,oe.startClientX,de.clientX,window.innerWidth))},J=()=>ne(null);return window.addEventListener("pointermove",$),window.addEventListener("pointerup",J),()=>{window.removeEventListener("pointermove",$),window.removeEventListener("pointerup",J)}},[oe]);const Q=$=>{$.preventDefault(),ne({startClientX:$.clientX,startWidth:ae})},A=()=>{ne(null),D(!1),y(null),E(null)},G=()=>{b(new Set),B([])},j=async $=>{y($.id),D(!0),E(null);const J=await Qo(s.id,$.id,n);E(J.detail)},Y=a.useCallback(async $=>{if(H.length===0||$.length===0){B([]);return}B([]);try{const J=Mu(s.id,n,H,$),de=await Promise.all(J.map(O=>Yo(O)));B(de.flatMap((O,ie)=>O.results.map(Ne=>{var Te;return{...Ne,capabilityId:(Te=J[ie])==null?void 0:Te.capabilityId}})))}catch{B([])}},[s.id,n,H]),te=()=>{B([]),U(!0)},pe=async $=>{const J=Pu(s.id,n,H,$);J.length!==0&&(await Promise.all(J.map(de=>Jo(de))),le.success(`${J.length} capability share request${J.length===1?"":"s"} completed`),U(!1))},X=async()=>{if(!(!C||z)){P(C.id);try{const $=await Xo(s.id,C.id,n);$.status==="deleted"?(le.success(`Deleted ${C.name}`),c(J=>J.filter(de=>de.id!==C.id)),b(J=>{const de=new Set(J);return de.delete(C.id),de}),y(null),E(null),D(!1),await x()):(le.info($.message??"Capability was not found"),y(null),E(null),D(!1),await x())}catch($){le.error($ instanceof Error?$.message:"Failed to delete capability")}finally{P(null)}}};return e.jsx(e.Fragment,{children:e.jsx(Mt,{open:t,onOpenChange:o,children:e.jsxs(Pt,{className:"dashboard-panel animate-panel-settle flex h-[min(62vh,33rem)] w-[min(94vw,72rem)] max-w-[min(94vw,72rem)] flex-col gap-0 overflow-hidden rounded-xl p-0",children:[e.jsxs(Qs,{className:"border-b border-border/55 bg-card/28 px-4 py-2.5 text-left",children:[e.jsx(Gt,{className:"sr-only",children:"Capabilities"}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-x-4 gap-y-1 pr-10",children:[e.jsx(ju,{node:s,scope:n,clusterNodes:r,onSelectionChange:i}),e.jsxs(Js,{"data-capability-selection-help":"true",className:"ml-auto max-w-[min(32rem,38vw)] space-y-0.5 pt-0.5 text-right text-[9px] leading-[11px] text-muted-foreground",children:[e.jsx("span",{className:"block truncate whitespace-nowrap",children:"Sharing copies into selected agents on target nodes."}),n.kind==="project"&&e.jsx("span",{"data-capability-selection-path":"true",className:"block truncate font-mono text-[7px] leading-[10px] text-muted-foreground/80",title:n.projectPath,children:n.projectPath})]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:flex-row",children:[e.jsxs("main",{className:"relative flex min-w-0 flex-1 flex-col gap-2 bg-gradient-to-b from-primary/4 via-background/20 to-background/40 p-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-44 flex-1",children:[e.jsx(va,{className:"pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),e.jsx(Qe,{value:l,onChange:$=>N($.target.value),placeholder:"Search capabilities",className:"h-7 rounded-sm border-0 bg-muted/55 pl-6 text-[10px] shadow-none"})]}),e.jsxs(Se,{value:T,onValueChange:$=>w($),children:[e.jsx(Ce,{className:M("w-28",fa),children:e.jsx(Le,{})}),e.jsxs(_e,{className:"shadow-none",children:[e.jsx(he,{value:"all",className:dt,children:"Agent: All"}),e.jsx(he,{value:"claudecode",className:dt,children:"Claude Code"}),e.jsx(he,{value:"codex",className:dt,children:"Codex"}),e.jsx(he,{value:"copilot",className:dt,children:"Copilot"})]})]}),e.jsxs(Se,{value:_,onValueChange:$=>f($),children:[e.jsx(Ce,{className:M("w-24",fa),children:e.jsx(Le,{})}),e.jsxs(_e,{className:"shadow-none",children:[e.jsx(he,{value:"all",className:dt,children:"Kind: All"}),e.jsx(he,{value:"skill",className:dt,children:"Skill"}),e.jsx(he,{value:"plugin",className:dt,children:"Plugin"}),e.jsx(he,{value:"mcp",className:dt,children:"MCP"})]})]})]}),g.length>0&&e.jsx("div",{className:"rounded-sm bg-amber-500/10 px-2 py-1 text-[10px] text-amber-600",children:g.join(" · ")}),e.jsx(ru,{items:L,selectedIds:S,activeId:v,onToggleSelected:($,J)=>b(de=>{const O=new Set(de);return J?O.add($):O.delete($),O}),onOpenDetail:j}),e.jsx(Iu,{selectedCount:S.size,loading:k,onClearSelection:G,onRefresh:x,onShare:te}),e.jsx(Ru,{visible:k&&d.length===0})]}),q&&e.jsxs(e.Fragment,{children:[e.jsx(Bu,{onBeginResize:Q,onFold:A}),e.jsx(du,{detail:C,deleting:z===(C==null?void 0:C.id),desktopWidth:ae,onDelete:C?X:void 0,pending:!C})]})]}),Z&&e.jsx(Cu,{open:Z,sourceNode:s,targetNodes:m,selectedCapabilities:H,previewResults:R,embedded:!0,onClose:()=>U(!1),onPreviewTargetsChange:Y,onShare:pe})]})})})}function Ou(t){const[s,n]=a.useState(null),r=a.useMemo(()=>s?(t==null?void 0:t.nodes.find(g=>g.id===s.nodeId))??((t==null?void 0:t.self.id)===s.nodeId?t.self:null)??null:null,[t,s]),o=a.useCallback(g=>{n({nodeId:g,scope:{kind:"global"}})},[]),i=a.useCallback((g,p)=>{n({nodeId:g,scope:{kind:"project",projectPath:p}})},[]),d=a.useCallback(g=>{n(g)},[]);return{capabilitiesDialog:s&&r&&t?e.jsx($u,{open:!0,node:r,scope:s.scope,clusterNodes:t.nodes,onOpenChange:g=>{g||n(null)},onSelectionChange:d}):null,openNodeCapabilities:o,openProjectCapabilities:i}}function zu(){var pn,fn,gn,bn,vn,jn;const{id:t}=ei(),s=ti(),n=si(),r=ni(),{cluster:o,systemInfo:i,events:d,sseConnected:c,subscribe:g,refresh:p,loading:k,error:h}=ai(),l=a.useMemo(()=>ri(s.state),[s.state]),[N,T]=a.useState(null),[w,_]=a.useState("active"),[f,S]=a.useState("all"),[b,v]=a.useState("all"),[y,C]=a.useState("all"),E=(r==null?void 0:r.headerSearchQuery)??"",q=a.useDeferredValue(E),{desktopTasksOpen:D,mobileTasksPanelOpen:z,mobileTasksPanelRef:P,operationsOpen:Z,operationsPanelRef:U,panelResize:R,setMobileTasksPanelOpen:B,setOperationsOpen:ae,toggleTasksPanel:re}=Mc(),[oe,ne]=a.useState(()=>!!(l!=null&&l.draftNewTask)),[L,H]=a.useState(()=>(l==null?void 0:l.createMode)??"chat"),[m,V]=a.useState(()=>(l==null?void 0:l.createDefaults)??null),[x,Q]=a.useState(()=>l!=null&&l.draftNewTask?{route:l.returnRoute??"/",taskId:l.returnTaskId??null}:null),[A,G]=a.useState(!1),[j,Y]=a.useState("transcript"),[te,pe]=a.useState("all"),[X,$]=a.useState(!1),[J,de]=a.useState(null),[O,ie]=a.useState([]),[Ne,Te]=a.useState([]),[ct,et]=a.useState(!1),[Ae,ee]=a.useState(!1),[je,Ee]=a.useState(null),[Pe,Oe]=a.useState(new Set),[we,rt]=a.useState(!1),[jt,ut]=a.useState(!1),[tt,mt]=a.useState(null),Be=a.useRef(null),xt=a.useRef(new Map),ye=((pn=o==null?void 0:o.self)==null?void 0:pn.role)==="leader",F=(fn=o==null?void 0:o.self)==null?void 0:fn.id;qc({cluster:o,subscribe:g});const{nodeSettingsDialog:Me,openNodeSettings:ke}=eu(ye),{capabilitiesDialog:at,openNodeCapabilities:wt,openProjectCapabilities:Bt}=Ou(o),{devBoxDialog:De,devBoxNodeIds:Ve,devBoxStartNodeId:ht,devBoxStartNodeIds:ot,devBoxStartingNodeIds:Ue,openDevBox:yt,startDevBox:pt}=Jc({cluster:o,refresh:p}),{completedGroups:it=[],fetchTasks:ce,loadCompletedTasksPage:qe,removeTasksFromList:ft,setTasks:ve,tasks:fe,tasksError:st,tasksLoading:Nt}=Vc({isLeader:ye,selfId:F,sseConnected:c,preservedTask:J,subscribe:g}),Ke=a.useMemo(()=>[...fe].sort((u,I)=>I.updatedAt-u.updatedAt),[fe]),Ge=a.useMemo(()=>{var u;return((u=[...fe].sort((I,K)=>K.createdAt-I.createdAt||K.updatedAt-I.updatedAt)[0])==null?void 0:u.id)??null},[fe]),fr=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[]){const K=Bl(Ke,I.id);K>0&&u.set(I.id,K)}return u},[o==null?void 0:o.nodes,Ke]),We=a.useMemo(()=>Ke.filter(u=>!oi(u,o==null?void 0:o.nodes,o==null?void 0:o.self)||!ii(u,w)||f!=="all"&&u.agent!==f||!li(u,y)||b==="unassigned"&&u.assignedTo||b!=="all"&&b!=="unassigned"&&di(u.assignedTo,o==null?void 0:o.nodes,u.assignedNodeName)!==b?!1:q.trim()?ci(u,q):!0),[Ke,o==null?void 0:o.nodes,o==null?void 0:o.self,w,f,y,b,q]);a.useEffect(()=>{Oe(u=>{const I=Vl(u,We.map(K=>K.id));return I.size===u.size?u:I})},[We]),a.useEffect(()=>{ye||Oe(new Set)},[ye]);const gr=a.useMemo(()=>["all",...Array.from(new Set(Ke.map(u=>u.agent))).sort()],[Ke]),br=a.useMemo(()=>{const I=Array.from(new Set(Ke.map(K=>K.assignedTo).filter(K=>!!K))).map(K=>{const be=Ke.find(xe=>xe.assignedTo===K);return(o==null?void 0:o.nodes.find(xe=>xe.id===K))??{id:K,name:Ls(K,o==null?void 0:o.nodes,be==null?void 0:be.assignedNodeName)}}).sort((K,be)=>K.name.localeCompare(be.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...I.map(K=>({value:K.name.toLowerCase(),label:K.name}))]},[Ke,o==null?void 0:o.nodes]),un=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])u.set(I.id,I.name);for(const I of Ke)I.assignedTo&&I.assignedNodeName&&!u.has(I.assignedTo)&&u.set(I.assignedTo,I.assignedNodeName);return u},[o==null?void 0:o.nodes,Ke]),vr=a.useMemo(()=>{var I;const u=new Map;for(const K of(o==null?void 0:o.nodes)??[])K.workDir&&u.set(K.id,K.workDir);return(I=o==null?void 0:o.self)!=null&&I.workDir&&u.set(o.self.id,o.self.workDir),u},[o]),jr=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])u.set(I.id,I.status);return o!=null&&o.self&&u.set(o.self.id,o.self.status),u},[o]),wr=a.useMemo(()=>new Map(it.map(u=>[Gs(u),u])),[it]),mn=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])I.status!=="offline"&&u.set(I.id,I);return o!=null&&o.self&&o.self.status!=="offline"&&u.set(o.self.id,o.self),Array.from(u.values())},[o]),yr=((gn=o==null?void 0:o.self)==null?void 0:gn.id)??((bn=mn[0])==null?void 0:bn.id)??null,js=a.useMemo(()=>["all",...Array.from(new Set(d.map(u=>u.type))).sort()],[d]),Nr=a.useMemo(()=>te==="all"?d:d.filter(u=>u.type===te),[d,te]),kr=We.length>0&&We.every(u=>Pe.has(u.id)),Sr=We.some(u=>Pe.has(u.id)),Cr=Ul(We,Pe);a.useEffect(()=>{l!=null&&l.draftNewTask&&(ne(!0),H(l.createMode??"chat"),V(l.createDefaults??null),Q({route:l.returnRoute??"/",taskId:l.returnTaskId??null}))},[l]),a.useEffect(()=>{te!=="all"&&!js.includes(te)&&pe("all")},[te,js]),a.useEffect(()=>{Bn(t,oe)&&!N&&Ge&&T(Ge)},[t,oe,N,Ge]),a.useEffect(()=>{Bn(t,oe)&&(N&&fe.some(u=>u.id===N)||T(Ge))},[t,oe,N,Ge,fe]);const ge=$l({routeTaskId:t,creatingTask:oe,internalSelectedTaskId:N,sortedTaskIds:Ge?[Ge]:[]}),kt=a.useMemo(()=>fe.find(u=>u.id===ge)??null,[fe,ge]);a.useEffect(()=>{Be.current=ge??null},[ge]);const lt=a.useCallback(()=>{de(null),ie([]),Te([]),Ee(null),ee(!1)},[]),Rt=a.useCallback((u,I,K=!0)=>{xt.current.set(u,{logs:rr(I),loaded:K})},[]),ze=a.useCallback(async()=>{const u=ge;if(u)try{const I=await ui(u);if(Be.current!==u)return;de(I),ve(K=>za(K,I)),Ee(null)}catch(I){if(Be.current!==u)return;lt(),Ee(I instanceof Error?I.message:"Failed to load task")}finally{Be.current===u&&et(!1)}},[ge,lt,ve]),Wt=a.useCallback(async()=>{const u=ge;if(u)try{const I=await Bs(u);if(Be.current!==u)return;ie(K=>{const be=Ma(K,I.logs);return Rt(u,be),be}),Te(K=>$s(K,I.logs))}catch{}finally{Be.current===u&&ee(!1)}},[ge,Rt]);a.useEffect(()=>{if(!ge){lt(),et(!1);return}Y("transcript"),de(kt);const u=Uc(ge,xt.current);ie(u.logs),Te([]),Ee(null),et(!0),ee(u.transcriptLoading),ze(),Wt()},[ge,lt,Wt,ze]),a.useEffect(()=>{if(!Ol({activeTaskId:ge,routeTaskId:t,creatingTask:oe,tasksLoading:Nt,loadedTaskIds:fe.map(I=>I.id)}))return;const u=Ge;T(u),lt(),a.startTransition(()=>{n(u?`/tasks/${u}`:"/",{state:null})})},[ge,lt,oe,Ge,n,t,fe,Nt]),a.useEffect(()=>{kt&&de(u=>!u||u.id!==kt.id?u:{...u,...kt})},[kt]),a.useEffect(()=>{if(ge)return g("task",u=>{const I=u.data.taskId;if(!(typeof I!="string"||I!==ge)){if(u.type==="task.output"){const K=u.data.event;if(K){ie(xe=>{const Ot=Di(xe,K);return Rt(ge,Ot),Ot}),ee(!1);const be=Pn(K);be&&Te(xe=>Ai(xe,be))}}u.type==="task.updated"&&ze(),u.type==="task.status"&&(ze(),Wt())}})},[g,ge,ze,Wt]);const se=J??kt,_r=se!=null&&se.assignedTo?(o==null?void 0:o.nodes.find(u=>u.id===se.assignedTo))??null:null,$t=r==null?void 0:r.setHeaderTaskContext;a.useEffect(()=>{if(!$t)return;if(!se){$t(null);return}const u=se.effectiveProjectPath??se.project??"default workspace";return $t({taskId:se.id,taskTitle:se.title,nodeName:Ls(se.assignedTo,o==null?void 0:o.nodes,se.assignedNodeName),projectLabel:_a(u),projectPath:u}),()=>$t(null)},[se,o==null?void 0:o.nodes,$t]);const ws=Ne.length>0,Tr=se?mi.has(se.agent):!1,Yt=(se==null?void 0:se.status)==="running",Er=se?us.has(se.status):!1,Dr=se?us.has(se.status)||xi.has(se.status):!1,Ar=!!(se&&ye&&se.status==="failed"),ys=a.useMemo(()=>bc(se,o,ws,!!Yt),[se,o,ws,Yt]),Ns=a.useMemo(()=>Mi([...O,...Ne.map(u=>Es(u.content,u.timestamp))]),[O,Ne]),Zt=a.useMemo(()=>{if(!se||se.conversationKind==="nativeSession")return null;const u=Pi(se);if(u.length>0)return Es(u,new Date(se.createdAt).toISOString());if(Ns.length>0)return null;const I=Li(se.description||se.title);return I.length>0?Es(I,new Date(se.createdAt).toISOString()):null},[se,Ns]),ks=a.useMemo(()=>Zt?Pn(Zt):null,[Zt]),Mr=a.useMemo(()=>ks?Ii(O,ks):!1,[O,ks]),Ss=a.useCallback((u="chat",I)=>{const K={route:t?`/tasks/${t}`:"/",taskId:ge};Q(K),H(u),V(I??null),ne(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:K.route,returnTaskId:K.taskId,createMode:u,createDefaults:I}})})},[t,ge,n]),Pr=a.useCallback(()=>{const u=(x==null?void 0:x.taskId)??Ge;ne(!1),Q(null),V(null),T(u),a.startTransition(()=>{n((x==null?void 0:x.route)??"/",{state:null})})},[x,Ge,n]),xn=a.useCallback(u=>{ne(!1),Q(null),V(null),T(u),a.startTransition(()=>{n(`/tasks/${u}`,{state:null})})},[n]),Lr=a.useCallback(u=>{Be.current=u.id,ne(!1),Q(null),V(null),ve(I=>zl(I,u)),de(u),ie([]),Te([]),Ee(null),et(!1),ee(u.conversationKind==="nativeSession"),Y("transcript"),T(u.id),Gc({task:u,getActiveTaskId:()=>Be.current,setLogs:ie,setPendingMessages:Te,setTranscriptLoading:ee}),ce(),a.startTransition(()=>{n(`/tasks/${u.id}`,{state:null})})},[ce,n]),{cancelQueuedMessage:Ir,queueFollowUpMessage:Qt}=su({activeTaskId:ge,fetchActiveTask:ze,isRunning:Yt,setPendingMessages:Te,setTask:de,setTasks:ve}),Br=a.useCallback(u=>{Qt(u)},[Qt]),Rr=a.useCallback(async()=>{const u=ge;if(!(!u||(se==null?void 0:se.conversationKind)!=="nativeSession")){ee(!0);try{const I=await Bs(u);if(Be.current!==u)return;ie(I.logs),Rt(u,I.logs),Te(K=>$s(K,I.logs))}catch(I){le.error(I instanceof Error?I.message:"Failed to reload transcript")}finally{Be.current===u&&ee(!1)}}},[se==null?void 0:se.conversationKind,ge,Rt]),$r=a.useCallback(u=>Qt(u),[Qt]),Or=a.useCallback(async()=>{if(se)try{await hi(se.id),ze(),ce()}catch(u){le.error(u instanceof Error?u.message:"Failed to cancel task")}},[se,ze,ce]),{handleShareTask:zr,handleStopShareTask:Fr}=Tc(se,ze,ce),Vr=a.useCallback(async()=>{if(se)try{await pi(se.id),ze(),ce()}catch(u){le.error(u instanceof Error?u.message:"Failed to retry task")}},[se,ze,ce]),Xt=a.useCallback((u,I=!1)=>{const K=Hl(We,u);return T(K),(I||!K)&<(),a.startTransition(()=>{n(K?`/tasks/${K}`:"/",{state:null})}),K},[lt,We,n]),Ur=a.useCallback((u,I)=>{Oe(K=>{const be=new Set(K);return I?be.add(u):be.delete(u),be})},[]),Hr=a.useCallback(u=>{if(!u){Oe(new Set);return}Oe(new Set(We.map(I=>I.id)))},[We]),qr=a.useCallback(async()=>{const u=Array.from(Pe);if(u.length!==0)try{const{results:I}=await fi(u),K=I.filter(xe=>!xe.ok),be=I.filter(xe=>xe.ok).map(xe=>xe.id);ge&&be.includes(ge)&&Xt(be),K.length>0?le.error(`Failed to archive ${K.length} task(s): ${K.map(xe=>xe.error??xe.id).join(", ")}`):le.success(`Archived ${be.length} task(s)`),Oe(new Set(K.map(xe=>xe.id))),ce()}catch(I){le.error(I instanceof Error?I.message:"Failed to archive tasks")}},[ge,ce,Xt,Pe]),Kr=a.useCallback(async()=>{const u=Array.from(Pe);if(u.length!==0)try{const{results:I}=await gi(u),K=I.filter(xe=>!xe.ok),be=I.filter(xe=>xe.ok).map(xe=>xe.id);be.length>0&&ft(be),ge&&be.includes(ge)&&Xt(be,!0),K.length>0?le.error(`Failed to delete ${K.length} task(s): ${K.map(xe=>xe.error??xe.id).join(", ")}`):le.success(`Deleted ${be.length} task(s)`),Oe(new Set(K.map(xe=>xe.id))),ce()}catch(I){le.error(I instanceof Error?I.message:"Failed to delete tasks")}},[ge,ce,Xt,ft,Pe]),Gr=a.useCallback(async()=>{rt(!0);try{await bi(),p()}catch(u){le.error(u instanceof Error?u.message:"Failed to promote node")}finally{rt(!1)}},[p]),Wr=a.useCallback(async()=>{ut(!0);try{await vi(),le.success("This node left the remote cluster and is leading itself again."),ce(),ze(),p()}catch(u){le.error(u instanceof Error?u.message:"Failed to leave cluster")}finally{ut(!1)}},[ze,ce,p]),Yr=a.useCallback(async u=>{var Ot;const I=!nn(u),K=u.id===((Ot=o==null?void 0:o.self)==null?void 0:Ot.id),be=K?(i==null?void 0:i.transportType)??u.transportType:u.transportType,xe=K&&!I&&It(be);mt(u.id);try{xe?await ji("direct"):await wi(u.id,I),le.success(I?`Enabled remote access on ${u.name}`:`Disabled remote access on ${u.name}`),p()}catch(wn){le.error(wn instanceof Error?wn.message:"Failed to update remote access")}finally{mt(null)}},[(vn=o==null?void 0:o.self)==null?void 0:vn.id,p,i==null?void 0:i.transportType]),Zr=a.useCallback(u=>{qe&&qe(u).catch(I=>{le.error(I instanceof Error?I.message:"Failed to load completed tasks")})},[qe]),hn={toolbarTasks:We,activeTaskId:ge,tasksLoading:Nt,tasksError:st,isLeader:ye,scope:w,agentFilter:f,nodeFilter:b,taskKindFilter:y,agentOptions:gr,nodeOptions:br,nodeNameById:un,nodeWorkDirById:vr,nodeStatusById:jr,leaderNodeId:((jn=o==null?void 0:o.leader)==null?void 0:jn.id)??null,searchQuery:E,completedGroupByKey:wr,devBoxNodeIds:Ve,devBoxStartNodeIds:ot,devBoxStartingNodeIds:Ue,selectedTaskIds:Pe,allVisibleTasksSelected:kr,someVisibleTasksSelected:Sr,canBatchArchive:Cr,onScopeChange:_,onAgentFilterChange:S,onNodeFilterChange:v,onTaskKindFilterChange:C,onToggleTaskSelected:Ur,onToggleAllVisibleTasks:Hr,onBatchArchive:qr,onBatchDelete:Kr,onCreateTask:Ss,onOpenNodeSettings:ye?ke:void 0,onOpenNodeCapabilities:ye?wt:void 0,onOpenProjectCapabilities:ye?Bt:void 0,onOpenDevBox:ye?yt:void 0,onStartDevBox:ye?pt:void 0,onLoadCompletedTasks:Zr,onSelectTask:xn},Qr={cluster:o,systemInfo:i,nodeNameById:un,nodeBlockingTaskCounts:fr,eventTypeFilter:te,onEventTypeFilterChange:pe,eventTypeOptions:js,filteredEvents:Nr,sseConnected:c,clusterLoading:k,clusterError:h,promotePending:we,onPromote:Gr,onAddNode:()=>G(!0),leavePending:jt,onLeaveCluster:Wr,onToggleNodeDevTunnel:Yr,devTunnelNodeId:tt,devBoxStartNodeId:ht,devBoxStartingNodeIds:Ue,onOpenNodeSettings:ye?ke:void 0,onOpenNodeCapabilities:ye?wt:void 0,onOpenDevBox:ye?yt:void 0,onStartDevBox:ye?pt:void 0};return e.jsxs(e.Fragment,{children:[e.jsx(Jd,{desktopTasksOpen:D,mobileTasksPanelOpen:z,mobileTasksPanelRef:P,operationsOpen:Z,operationsPanelRef:U,panelResize:R,taskSidebar:e.jsx(sa,{...hn}),operationsSidecar:e.jsx(fc,{...Qr}),terminalPanel:r!=null&&r.terminalOpen?e.jsx(ic,{nodes:mn,defaultNodeId:yr,onClose:()=>r==null?void 0:r.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(qd,{onToggleTasks:re,desktopTasksOpen:D,mobileTasksPanelOpen:z,operationsOpen:Z,onToggleOperations:()=>ae(u=>!u),cluster:o,sseConnected:c,activeTab:j,setActiveTab:Y,creatingTask:oe,createMode:L,createDefaults:m,activeTask:se,assignedNode:_r,taskLoading:ct,transcriptLoading:Ae,taskError:je,displayEvents:Ns,initialPromptAlreadyInLogs:Mr,initialPrompt:Zt,supportsFollowUp:Tr,taskUnavailable:ys.taskUnavailable,chatDisabled:ys.chatDisabled,chatDisabledReason:ys.chatDisabledReason,questionBypassEnabled:X,isRunning:!!Yt,isStarting:Er,hasPendingFollowUp:ws,canCancel:!!Dr,canRetry:!!Ar,onRetry:Vr,onCancel:Or,onReloadNativeTranscript:Rr,onShareTask:zr,onStopShareTask:Fr,onStartCreateTask:Ss,onCancelCreateTask:Pr,onCreateTask:Lr,onSendMessage:Br,onCancelQueuedMessage:Ir,onQuestionBypassChange:$,onSubmitQuestionResponse:$r}),mobileTaskSidebar:e.jsx(sa,{...hn,onCreateTask:(u,I)=>{B(!1),Ss(u,I)},onSelectTask:u=>{B(!1),xn(u)}}),onCloseOperations:()=>ae(!1),onCloseTaskList:()=>B(!1),onToggleOperations:()=>ae(u=>!u),onToggleTasks:re}),e.jsx(Wd,{open:A,onOpenChange:G,onAdded:p}),Me,De,at]})}const qu=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:zu},Symbol.toStringTag,{value:"Module"}));export{qu as D,ms as G};
|