meshy-node 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dashboard/assets/DashboardPage-DyNoe7cv.js +149 -0
- package/dashboard/assets/DashboardShared-Coi8X4Mf.js +89 -0
- package/dashboard/assets/{DiffTab-BEsNBvvh.js → DiffTab-797YuD9i.js} +1 -1
- package/dashboard/assets/{FilesTab-Cg5PBMv6.js → FilesTab-CxWQD31o.js} +1 -1
- package/dashboard/assets/{MarkdownPreviewFrame-B58EGPZX.js → MarkdownPreviewFrame-tY-M5bCG.js} +2 -2
- package/dashboard/assets/PreviewTab-Ci5d1xLj.js +16 -0
- package/dashboard/assets/SharedConversationPage-BMmvljLM.js +2 -0
- package/dashboard/assets/{file-BDYM9RQo.js → file-QtUVb5S2.js} +1 -1
- package/dashboard/assets/index-BT6taBuK.css +1 -0
- package/dashboard/assets/index-BxuLE_uo.js +316 -0
- package/dashboard/assets/{play-nM4_YhiZ.js → play-Cwrx3Fzy.js} +1 -1
- package/dashboard/index.html +2 -2
- package/main.cjs +1795 -99
- package/package.json +4 -1
- package/runtime-metadata.json +4 -4
- package/dashboard/assets/DashboardPage-CKkLv8I1.js +0 -149
- package/dashboard/assets/DashboardShared-BvjPqceV.js +0 -83
- package/dashboard/assets/PreviewTab-CoN0CJR0.js +0 -16
- package/dashboard/assets/SharedConversationPage-aj_wfoD8.js +0 -7
- package/dashboard/assets/index-AgRF0fhH.js +0 -316
- package/dashboard/assets/index-BYWN4SLt.css +0 -1
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-Cg5PBMv6.js","assets/index-AgRF0fhH.js","assets/index-BYWN4SLt.css","assets/MarkdownPreviewFrame-B58EGPZX.js","assets/DashboardShared-BvjPqceV.js","assets/file-BDYM9RQo.js","assets/PreviewTab-CoN0CJR0.js","assets/play-nM4_YhiZ.js","assets/DiffTab-BEsNBvvh.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as ge,r as a,j as e,X as Je,B as Z,S as ua,a as Ur,b as A,d as Hr,g as qr,e as Kr,I as nt,C as $t,f as Gr,h as ma,F as Wr,i as Ut,k as Ue,l as xe,D as Ot,m as Yr,n as Qr,t as le,o as Ne,p as ke,q as Me,s as Se,u as xa,v as Ze,T as Xr,w as Jr,x as vn,y as Zr,z as Ht,A as qt,E as us,G as ha,H as pa,J as Ct,K as Ds,L as eo,M as qs,N as fa,P as to,O as Ks,Q as bt,R as Be,U as so,V as st,W as es,Y as ts,Z as ss,_ as ns,$ as as,a0 as rs,a1 as os,a2 as is,a3 as Gs,a4 as no,a5 as Ws,a6 as ga,a7 as ao,a8 as jn,a9 as wn,aa as ys,ab as ro,ac as oo,ad as io,ae as lo,af as co,ag as ms,ah as uo,ai as ba,aj as mo,ak as xo,al as ho,am as va,an as ja,ao as wa,ap as po,aq as ls,ar as Ys,as as fo,at as go,au as bo,av as ya,aw as zt,ax as vo,ay as As,az as jo,aA as wo,aB as yo,aC as No,aD as yn,aE as ko,aF as So,aG as Ns,aH as Co,aI as Nn,aJ as _o,aK as To,aL as Eo,aM as kn,aN as Do,aO as Ao,aP as Ms,aQ as Mo,aR as Po,aS as Na,aT as Sn,aU as ka,aV as Lo,aW as Io,aX as Bo,aY as Ro,aZ as $o,a_ as Oo,a$ as zo,b0 as Fo,b1 as Vo,b2 as Uo,b3 as Ho,b4 as qo,b5 as Ko,b6 as Go,b7 as Wo,b8 as Yo,b9 as Qo,ba as Xo,bb as Jo,bc as Zo,bd as ei,be as ti,bf as si,bg as ni,bh as ai,bi as ri,bj as oi,bk as ii,bl as li,bm as di,bn as ci}from"./index-AgRF0fhH.js";import{r as Cn,e as ui,b as Sa,t as Ca,A as Qs,L as he,g as _a,a as mi,c as xi,d as _n,f as Tn,h as hi,i as pi,C as En,T as ks,D as St,I as Xe,M as Ps,j as fi,m as Ta,k as Ls,l as gi,n as Dn,o as bi,p as vi,q as Ss,s as ji,u as wi,v as yi}from"./DashboardShared-BvjPqceV.js";import{P as Xs}from"./play-nM4_YhiZ.js";import{M as Ni}from"./MarkdownPreviewFrame-B58EGPZX.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 ki=[["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"}]],Si=ge("archive",ki);/**
|
|
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 Ci=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],An=ge("arrow-right",Ci);/**
|
|
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 _i=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Ea=ge("arrow-up",_i);/**
|
|
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 Ti=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Ft=ge("chevron-left",Ti);/**
|
|
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 Ei=[["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"}]],Di=ge("earth",Ei);/**
|
|
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 Ai=[["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"}]],Mi=ge("ellipsis-vertical",Ai);/**
|
|
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 Pi=[["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"}]],Li=ge("ellipsis",Pi);/**
|
|
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 Ii=[["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"}]],Bi=ge("flag",Ii);/**
|
|
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 Ri=[["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"}]],Js=ge("folder-open",Ri);/**
|
|
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 $i=[["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"}]],Oi=ge("funnel",$i);/**
|
|
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 zi=[["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"}]],Is=ge("git-branch",zi);/**
|
|
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 Fi=[["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"}]],Vi=ge("globe",Fi);/**
|
|
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 Ui=[["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"}]],Bs=ge("history",Ui);/**
|
|
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 Hi=[["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"}]],Rs=ge("image-plus",Hi);/**
|
|
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 qi=[["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"}]],Ki=ge("laptop",qi);/**
|
|
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 Gi=[["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"}]],Zs=ge("link-2",Gi);/**
|
|
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 Wi=[["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"}]],Yi=ge("list-ordered",Wi);/**
|
|
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 Qi=[["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"}]],xs=ge("message-square-plus",Qi);/**
|
|
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 Xi=[["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"}]],At=ge("pencil",Xi);/**
|
|
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 Ji=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Zi=ge("plus",Ji);/**
|
|
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 el=[["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"}]],tl=ge("rotate-ccw",el);/**
|
|
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 sl=[["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"}]],Da=ge("rotate-cw",sl);/**
|
|
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 nl=[["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"}]],Aa=ge("send",nl);/**
|
|
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 al=[["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"}]],ds=ge("share-2",al);/**
|
|
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 rl=[["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"}]],ol=ge("sliders-horizontal",rl);/**
|
|
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 il=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Mn=ge("square",il);/**
|
|
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 ll=[["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"}]],Ma=ge("trash-2",ll);/**
|
|
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 dl=[["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"}]],cl=ge("user-plus",dl);/**
|
|
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 ul=[["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"}]],ml=ge("wifi",ul),xl=new Set(["assigned","running"]);function hl(t,s){return t.reduce((n,r)=>r.assignedTo===s&&xl.has(r.status)?n+1:n,0)}function Mt(t){return(t==null?void 0:t.toLowerCase())==="devtunnel"}function pl(t){return t?Mt(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function en(t,s){return Mt(s??t.transportType)||!!t.devtunnelEndpoint}function Pa(t,s){return!Mt(s??t.transportType)}function La(t,s){const n=s??t.transportType;return Mt(n)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":pl(n)}function Pn(t,s){return!t&&!s}function fl({routeTaskId:t,creatingTask:s,internalSelectedTaskId:n,sortedTaskIds:r}){return t||(s?null:r[0]??n??null)}function gl({activeTaskId:t,routeTaskId:s,creatingTask:n,tasksLoading:r,loadedTaskIds:o}){return!t||s||n||r?!1:!o.includes(t)}function bl(t,s){return[s,...t.filter(n=>n.id!==s.id)]}function Ia(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 vl=new Set(["completed","failed","cancelled","archived"]);function jl(t,s){const n=new Set(s);return new Set(Array.from(t).filter(r=>n.has(r)))}function wl(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=>vl.has(o.status))}function yl(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 Ba(){const[t,s]=a.useState([]),[n,r]=a.useState(null),o=a.useRef(null),i=a.useCallback(()=>{var y;(y=o.current)==null||y.click()},[]),c=a.useCallback(async y=>{const p=Array.from(y.target.files??[]);if(p.length!==0)try{const l=await Cn(p);s(k=>[...k,...l]),r(null)}catch(l){r(l instanceof Error?l.message:"Failed to attach image")}finally{y.target.value=""}},[]),m=a.useCallback(async y=>{const p=ui(y.clipboardData);if(p.length!==0){y.preventDefault();try{const l=await Cn(p);s(k=>[...k,...l]),r(null)}catch(l){r(l instanceof Error?l.message:"Failed to attach image")}}},[]),g=a.useCallback(y=>{s(p=>p.filter((l,k)=>k!==y))},[]),h=a.useCallback(()=>{s([]),r(null)},[]);return{images:t,error:n,fileInputRef:o,pickImages:i,handleFileChange:c,handlePaste:m,removeImage:g,clearImages:h}}function Nl(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"?_a(t.value):t.value}function Ln(t){switch(t.toLowerCase()){case"branch":return Is;case"node":return ua;case"working dir":default:return Js}}function Sl({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 Cl({contentLength:t,disabled:s=!1}){return t>0&&!s}function _l({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:c}){const[m,g]=a.useState(""),[h,y]=a.useState(0),p=a.useRef(null),{images:l,error:k,fileInputRef:E,pickImages:j,handleFileChange:_,handlePaste:b,removeImage:N,clearImages:f}=Ba(),w=a.useCallback(()=>{p.current&&(p.current.style.height="auto")},[]),C=a.useCallback(()=>{const O=Sa(m,l);Cl({contentLength:O.length,disabled:s})&&(y(B=>B+1),t(O),g(""),f(),w())},[m,l,s,t,f,w]),S=a.useCallback(O=>{O.key==="Enter"&&!O.shiftKey&&(O.preventDefault(),C())},[C]),M=a.useCallback(()=>{p.current&&(p.current.style.height="auto",p.current.style.height=`${Math.min(p.current.scrollHeight,220)}px`)},[]),P=m.trim().length>0||l.length>0,F=Sl({disabled:s,running:i,canStop:i&&!!c,hasContent:P}),D=Nl(o),X=D.primary?Ln(D.primary.label):Js,q=i?P?"Enter queues this message for the next turn":c?"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:E,type:"file",accept:"image/*",multiple:!0,onChange:_,className:"hidden"}),D.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(X,{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:D.primary.value,children:D.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((O,B)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Ca(O),alt:O.filename??`attachment ${B+1}`,className:"h-24 w-24 rounded-xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>N(B),className:"absolute -top-2 -right-2 flex h-7 w-7 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 ${O.filename??`image ${B+1}`}`,children:e.jsx(Je,{className:"h-3.5 w-3.5"})})]},`${O.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:p,"data-chat-input-textarea":"true",value:m,onChange:O=>g(O.target.value),onKeyDown:S,onPaste:b,onInput:M,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:[D.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:D.secondary.map(O=>{const B=Ln(O.label),re=O.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${O.label}: ${O.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[re?e.jsx(Qs,{agent:O.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 ${O.mono?"font-mono":""}`,children:O.displayValue})]},`${O.label}:${O.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(Z,{type:"button",variant:"ghost",onClick:j,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(Rs,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:q,children:e.jsx(Z,{onClick:F.primaryAction==="stop"?c:C,disabled:F.primaryDisabled,size:"icon","data-chat-send-button":"true","aria-label":F.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:F.primaryAction==="stop"?e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Aa,{className:`h-3.5 w-3.5 ${h>0?"animate-chat-send-flight":""}`},h)})})]})]}),k&&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:k})]})})})}var Tl=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],El=Tl.reduce((t,s)=>{const n=Ur(`Primitive.${s}`),r=a.forwardRef((o,i)=>{const{asChild:c,...m}=o,g=c?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(g,{...m,ref:i})});return r.displayName=`Primitive.${s}`,{...t,[s]:r}},{}),Dl="Label",Ra=a.forwardRef((t,s)=>e.jsx(El.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())}}));Ra.displayName=Dl;var $a=Ra;const Al=Hr("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ie=a.forwardRef(({className:t,...s},n)=>e.jsx($a,{ref:n,className:A(Al(),t),...s}));Ie.displayName=$a.displayName;function Ml(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function Pl(t){return t.trim()||"."}function Ll(t){return new Promise(s=>window.setTimeout(s,t))}function Il(t){return!!t&&typeof t=="object"&&typeof t.createdBranch=="string"&&typeof t.currentBranch<"u"}async function Bl(t){let s=t;for(let n=0;n<60;n++){if(s.status==="succeeded"){if(Il(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 Ll(1e3),s=await Gr(s.id)}throw new Error("Timed out waiting for branch creation")}function In({value:t,onChange:s,project:n,assignTo:r,nodes:o,assignableNodes:i,layout:c="default",chipClassName:m,chipActiveClassName:g,chipInactiveClassName:h,labelClassName:y,triggerClassName:p}){const[l,k]=a.useState(!1),[E,j]=a.useState(null),[_,b]=a.useState(""),[N,f]=a.useState(!1),[w,C]=a.useState(!1),[S,M]=a.useState(!1),[P,$]=a.useState(null),[F,D]=a.useState(""),[X,q]=a.useState(""),[O,B]=a.useState(""),[re,se]=a.useState(!1),oe=a.useRef(null),ne=a.useRef(0),L=a.useMemo(()=>Ml(r,o,i),[r,o,i]),H=L==null?void 0:L.id,u=a.useMemo(()=>Pl(n),[n]),U=a.useMemo(()=>H?`${H}
|
|
148
|
-
${u}`:"",[H,u]),x=a.useCallback(async(ee=0,z=!1)=>{const J=ne.current+1,de=U;if(ne.current=J,!H){j(null),b("");return}$(null),z||b(""),z?C(!0):f(!0);try{const R=await qr(H,{path:u,limit:20,offset:ee,allowAbsolute:!0});if(J!==ne.current)return;b(de),j(ie=>z&&ie?{...R,branches:[...ie.branches,...R.branches]}:R)}catch(R){if(J!==ne.current)return;$(R instanceof Error?R.message:"Failed to load branch info"),z||(j(null),b(""))}finally{J===ne.current&&(f(!1),C(!1))}},[H,U,u]);a.useEffect(()=>{if(!H){ne.current+=1,j(null),b(""),$(null);return}x()},[H,u,x]),a.useEffect(()=>{const ee=t.trim(),z=_===U?E:null,J=z!=null&&z.available&&z.currentBranch?z.currentBranch:"";ee!==J&&s(J)},[E,U,_,s,t]),a.useEffect(()=>{if(!l)return;const ee=J=>{oe.current&&(oe.current.contains(J.target)||k(!1))},z=J=>{J.key==="Escape"&&k(!1)};return document.addEventListener("mousedown",ee),document.addEventListener("keydown",z),()=>{document.removeEventListener("mousedown",ee),document.removeEventListener("keydown",z)}},[l]),a.useEffect(()=>{l&&(q(""),B(""),se(!1))},[l,H,u]);const W=a.useCallback(async()=>{if(!H)return;const ee=F.trim(),z=re?O.trim():X.trim();if(!(!ee||!z)){M(!0),$(null);try{const J=await Kr(H,{path:u,branchName:ee,startPoint:z,limit:20,offset:0,allowAbsolute:!0}),de=await Bl(J);b(U),j(de),s(de.currentBranch??de.createdBranch),D(""),q(""),B(""),se(!1),k(!1)}catch(J){$(J instanceof Error?J.message:"Failed to create branch")}finally{M(!1)}}},[H,U,u,re,O,F,s,X]),T=_===U?E:null,G=a.useCallback(()=>{T!=null&&T.hasMore&&x(T.branches.length,!0)},[T,x]),v=t.trim()||(T==null?void 0:T.currentBranch)||(T&&!T.available?"No git repo":"Branch"),Y=re?O.trim():X.trim(),Q=!!(T!=null&&T.available&&F.trim()&&Y&&!S),ue=c==="composer"?e.jsxs(Z,{type:"button",variant:"ghost",onClick:()=>k(ee=>!ee),title:v,"aria-label":`Branch: ${v}`,className:A(m,p,"min-w-0 max-w-full",t.trim()?g:h),children:[N&&!T?e.jsx(he,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(Is,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:A("min-w-0 truncate",y),children:v})]}):e.jsxs(Z,{type:"button",variant:"outline",onClick:()=>k(ee=>!ee),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:v,children:[e.jsx("span",{className:A("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:v}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:L?L.name:"Manual"})]});return e.jsxs("div",{className:A("relative inline-block",c==="composer"?"min-w-0 shrink-0":"w-full"),ref:oe,children:[c==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{className:"text-sm font-medium",children:"Branch"}),ue]}):ue,l&&e.jsxs("div",{className:A("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",c==="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(Is,{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:T!=null&&T.repoRoot?`${T.currentBranch??v} · ${T.repoRoot}`:(T==null?void 0:T.currentBranch)??v,children:(T==null?void 0:T.currentBranch)??v}),N?e.jsx(he,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),L?N&&!T?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(he,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):T&&!T.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(nt,{value:F,onChange:ee=>D(ee.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(Z,{type:"button",size:"sm",onClick:()=>void W(),disabled:!Q,title:Q?"Create branch":"Enter a name and pick a base","aria-label":"Create branch",className:"h-8 w-8 shrink-0 rounded-md p-0",children:S?e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Zi,{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"}),!re&&e.jsxs("button",{type:"button",onClick:()=>se(!0),className:"flex items-center gap-1 rounded px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx(At,{className:"h-2.5 w-2.5"}),"Manual"]})]}),re?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(nt,{value:O,onChange:ee=>B(ee.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{se(!1),B("")},className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel manual input","aria-label":"Cancel manual input",children:e.jsx(Je,{className:"h-3.5 w-3.5"})})]}):T!=null&&T.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-md border border-border/40 bg-background/40",children:[T.branches.map(ee=>{const z=X===ee.ref,J=ee.branch==="main"||ee.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>q(ee.ref),className:A("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",z&&"bg-background/70"),title:ee.ref,children:[e.jsx("span",{className:A("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:ee.ref}),z?e.jsx($t,{className:"h-3 w-3 shrink-0 text-primary"}):null]},ee.ref)}),T.hasMore&&e.jsxs("button",{type:"button",onClick:G,disabled:w,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:[w?e.jsx(he,{className:"h-3 w-3 animate-spin"}):e.jsx(Bs,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"rounded-md 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."}),P&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:P})]})]})}const Rl=20,$l=3,$s="meshy-working-dir-recents-by-node";function Ol(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function zl(t){const s=t.trim();return s||"."}function Os(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===$l))break}return s}function Fl(t,s){const n=s.trim();return Os(n?[n,...t]:t)}function Oa(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(c=>typeof c=="string"),i=Os(o);i.length>0&&(s[n]=i)}return s}function Vl(t,s,n){if(!s)return t;const r=t[s]??[],o=Fl(r,n);if(o.length===0){if(!(s in t))return t;const{[s]:i,...c}=t;return c}return{...t,[s]:o}}function Ul(t,s){var n;return s?((n=t[s])==null?void 0:n[0])??"":""}function za(t){if(!t||typeof window>"u")return"";try{const s=window.localStorage.getItem($s);return s?Ul(Oa(JSON.parse(s)),t):""}catch{return""}}function Hl(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function ql(t,s){const n=s.trim();return n?Ol(n)||!t?n:`${t.replace(/[/\\]+$/,"")}/${n}`:""}function Kl(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 cs({value:t,onChange:s,assignTo:n,nodes:r,assignableNodes:o,layout:i="default",chipClassName:c,chipActiveClassName:m,chipInactiveClassName:g,labelClassName:h,triggerClassName:y,popoverPlacement:p="bottom",popoverAlign:l="start"}){const[k,E]=a.useState(!1),[j,_]=a.useState(null),[b,N]=a.useState(!1),[f,w]=a.useState(!1),[C,S]=a.useState(null),[M,P]=a.useState(""),[$,F]=a.useState(!1),[D,X]=a.useState({}),q=a.useRef(null),O=a.useMemo(()=>Hl(n,r,o),[n,r,o]),B=O==null?void 0:O.id,re=a.useMemo(()=>B?D[B]??[]:[],[D,B]),se=a.useMemo(()=>t.trim()?ql(O==null?void 0:O.workDir,t):"Use node default",[t,O==null?void 0:O.workDir]);a.useEffect(()=>{if(!(typeof window>"u"))try{const v=window.localStorage.getItem($s);if(!v)return;const Y=JSON.parse(v);X(Oa(Y))}catch{}},[]);const oe=a.useCallback(v=>{B&&X(Y=>{const Q=Vl(Y,B,v);if(Q===Y)return Y;if(typeof window<"u")try{window.localStorage.setItem($s,JSON.stringify(Q))}catch{}return Q})},[B]),ne=a.useCallback((v,Y=!0)=>{const Q=v.trim();s(Q),Y&&Q&&oe(Q),E(!1)},[s,oe]),L=a.useCallback(async(v,Y=0,Q=!1)=>{if(B){S(null),Q?w(!0):N(!0);try{const ue=await ma(B,{path:v,limit:Rl,offset:Y,directoriesOnly:!0,allowAbsolute:!0});_(ee=>Q&&ee?{...ue,entries:[...ee.entries,...ue.entries]}:ue)}catch(ue){S(ue instanceof Error?ue.message:"Failed to browse directories"),Q||_(null)}finally{N(!1),w(!1)}}},[B]),H=a.useRef(t);H.current=t;const u=a.useRef(L);u.current=L,a.useEffect(()=>{if(!k)return;const v=H.current;P(v),F(!1),_(null),S(null),B&&u.current(zl(v))},[k,B]),a.useEffect(()=>{if(!k)return;const v=Q=>{q.current&&(q.current.contains(Q.target)||E(!1))},Y=Q=>{Q.key==="Escape"&&E(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",Y),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",Y)}},[k]);const U=a.useCallback(v=>{L(v)},[L]),x=a.useCallback(()=>{j&&L(j.currentPath,j.entries.length,!0)},[j,L]),W=i==="composer"?e.jsxs(Z,{type:"button",variant:"ghost",onClick:()=>E(v=>!v),title:se,"aria-label":`Working directory: ${se}`,className:A(c,y,"min-w-0 max-w-full",t.trim()?m:g),children:[e.jsx(Wr,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:A("min-w-0 truncate",h),children:se})]}):e.jsxs(Z,{type:"button",variant:"outline",onClick:()=>E(v=>!v),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:se,children:[e.jsx("span",{className:A("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:se}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:O?O.name:"Manual"})]}),T=Kl(j,O),G=!!(j!=null&&j.parentPath);return e.jsxs("div",{className:A("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":p,"data-workdir-popover-align":l,ref:q,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{className:"text-sm font-medium",children:"Working directory"}),W]}):W,k&&e.jsxs("div",{className:A("absolute z-50 flex max-h-[min(28rem,calc(100vh-5rem))] w-[240px] flex-col overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",p==="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:[re.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(Bs,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:re.map(v=>e.jsx("button",{type:"button",onClick:()=>ne(v),className:"truncate rounded px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:v,children:v},v))})]}),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:()=>(j==null?void 0:j.parentPath)&&U(j.parentPath),disabled:!G||b,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md 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(Ea,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:T,children:T}),j&&e.jsx("button",{type:"button",onClick:()=>ne(j.isAbsolute?j.currentPath:j.currentPath==="."?"":j.currentPath),className:"shrink-0 rounded 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:[O?b?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(he,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):j&&j.entries.length>0?e.jsxs(e.Fragment,{children:[j.entries.map(v=>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(v.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 ${v.path}`,children:[e.jsx(Ut,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:v.name})]}),e.jsx("button",{type:"button",onClick:()=>U(v.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 ${v.name}`,children:e.jsx(Ue,{className:"h-3.5 w-3.5"})})]},v.path)),j.hasMore&&e.jsxs("button",{type:"button",onClick:x,disabled:f,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:[f?e.jsx(he,{className:"h-3 w-3 animate-spin"}):e.jsx(Bs,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:C??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),C&&j&&j.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:C})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:$?e.jsxs(e.Fragment,{children:[e.jsx(nt,{value:M,onChange:v=>P(v.target.value),onKeyDown:v=>{v.key==="Enter"&&M.trim()?(v.preventDefault(),ne(M)):v.key==="Escape"&&(v.preventDefault(),F(!1),P(t))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>ne(M),disabled:!M.trim(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-foreground hover:bg-background/60 disabled:opacity-40",title:"Apply","aria-label":"Apply manual path",children:e.jsx($t,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{F(!1),P(t)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(Je,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{P(t),F(!0)},className:"flex h-7 flex-1 items-center justify-between rounded-md 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(At,{className:"h-3 w-3"})]})})]})]})}function Fa(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 tn({isCurrent:t}){return t?e.jsx(Ki,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Vi,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function zs(t,s){return t.map(n=>{const r=!!s&&n.id===s;return e.jsx(xe,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(tn,{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 Gl(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??Ot}}function Wl(){return Xr.map(t=>e.jsx(xe,{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 Yl(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 Bn(t){if(!t.updatedAt)return 0;const s=Date.parse(t.updatedAt);return Number.isNaN(s)?0:s}function Ql(t,s){return Bn(s)-Bn(t)||t.sessionId.localeCompare(s.sessionId)}function Xl(t){const s=t.trim().replace(/[\\/]+$/,"");return s?s.split(/[\\/]+/).filter(Boolean).at(-1)??s:"Unknown project"}function Jl(t){const s=new Map;for(const n of[...t].sort(Ql)){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:Xl(n),cwd:n,sessions:r}))}function Zl(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function ed({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:o,onCancel:i,className:c,footerClassName:m,submitLabel:g="Load session",cancelLabel:h="Cancel",autoFocus:y=!1}){const p=a.useMemo(()=>Fa(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),l=a.useMemo(()=>{var R;return n&&p.some(ie=>ie.id===n)?n:((R=p[0])==null?void 0:R.id)??""},[p,n]),[k,E]=a.useState(""),[j,_]=a.useState("codex"),[b,N]=a.useState(""),[f,w]=a.useState(""),[C,S]=a.useState(""),[M,P]=a.useState(l),[$,F]=a.useState("normal"),[D,X]=a.useState(Ot),[q,O]=a.useState(!1),[B,re]=a.useState([]),[se,oe]=a.useState(!1),[ne,L]=a.useState(null),H=a.useMemo(()=>B.find(R=>R.sessionId===b)??null,[B,b]);a.useEffect(()=>{M&&p.some(R=>R.id===M)||P(l)},[M,p,l]),a.useEffect(()=>{N(""),w(""),S("")},[j,M]),a.useEffect(()=>{let R=!1;return M?(oe(!0),L(null),Yr(M,{agent:j,limit:50}).then(ie=>{R||re(ie.sessions)}).catch(ie=>{R||(re([]),L(ie instanceof Error?ie.message:"Failed to load native sessions"))}).finally(()=>{R||oe(!1)}),()=>{R=!0}):(re([]),L(null),oe(!1),()=>{R=!0})},[j,M]),a.useEffect(()=>{H&&(w(H.sessionId),S(H.cwd))},[H]);const u=a.useCallback(async R=>{R.preventDefault();const ie=Gl({title:k,defaultTitle:H==null?void 0:H.summary,agent:j,sessionId:f,cwd:C,assignTo:M,priority:$,mode:D});if(ie){O(!0);try{const Ce=await Qr(ie);o(Ce)}catch(Ce){le.error(Ce instanceof Error?Ce.message:"Failed to load native session")}finally{O(!1)}}},[k,H,j,f,C,M,$,D,o]),U=!!(f.trim()&&C.trim()&&M),[x,W]=a.useState(!1),[T,G]=a.useState(""),[v,Y]=a.useState(()=>new Set),Q=p.find(R=>R.id===M)??null,ue=!!(n&&(Q==null?void 0:Q.id)===n),ee=a.useMemo(()=>{const R=T.trim().toLowerCase();return R?B.filter(ie=>ie.summary.toLowerCase().includes(R)||ie.sessionId.toLowerCase().includes(R)||ie.cwd.toLowerCase().includes(R)):B},[B,T]),z=a.useMemo(()=>Jl(ee),[ee]),J=a.useCallback(R=>{Y(ie=>Zl(ie,R))},[]),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:u,className:A("space-y-4",c),children:[e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/54 shadow-[0_24px_86px_-48px_rgba(15,23,42,0.55)] backdrop-blur-xl dark:shadow-[0_24px_86px_-48px_rgba(0,0,0,0.9)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/50 px-4 py-3",children:[e.jsxs(Ne,{value:M,onValueChange:P,children:[e.jsx(ke,{className:A(de),"aria-label":"Node",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(tn,{isCurrent:ue}),e.jsx("span",{className:"max-w-[10rem] truncate",children:Q.name})]}):e.jsx(Me,{placeholder:"Node"})}),e.jsx(Se,{children:zs(p,n)})]}),e.jsxs(Ne,{value:j,onValueChange:R=>_(R),children:[e.jsxs(ke,{className:A(de),"aria-label":"Agent",children:[e.jsx(Qs,{agent:j}),e.jsx("span",{children:j})]}),e.jsx(Se,{children:mi()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(xa,{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(nt,{value:T,onChange:R=>G(R.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(Ie,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:se?"Loading...":`${ee.length} session${ee.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-lg",children:[se&&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:[!M&&e.jsx("div",{className:"rounded-lg border border-dashed border-border/60 bg-background/35 px-4 py-6 text-center text-xs text-muted-foreground",children:"Pick a node to load its recent sessions."}),M&&!se&&ee.length===0&&e.jsx("div",{className:"rounded-lg border border-dashed border-border/60 bg-background/35 px-4 py-6 text-center text-xs 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."}),z.map(R=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>J(R.cwd),"aria-expanded":!v.has(R.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(Ze,{className:A("h-3.5 w-3.5 shrink-0 transition-transform",v.has(R.cwd)&&"-rotate-90")}),e.jsx(Js,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:R.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[R.sessions.length," session",R.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:R.cwd})]}),!v.has(R.cwd)&&R.sessions.map(ie=>{const Ce=ie.sessionId===b;return e.jsxs("button",{type:"button",onClick:()=>N(ie.sessionId),className:A("flex w-full flex-col gap-1 rounded-lg border px-3 py-2.5 text-left transition-all duration-200 hover:-translate-y-px",Ce?"border-primary/45 bg-primary/9 shadow-[0_18px_60px_-44px_hsl(var(--primary)/0.95)]":"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:A("h-2 w-2 shrink-0 rounded-full",Ce?"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:Yl(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)})]},R.cwd))]})]}),ne&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:ne})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:()=>W(R=>!R),className:"flex w-full items-center gap-2 text-[11px] font-medium uppercase tracking-[0.2em] text-muted-foreground transition-colors hover:text-foreground","aria-expanded":x,children:[e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0}),e.jsx("span",{className:"shrink-0",children:x?"Less options":"More options"}),e.jsx(Ze,{className:A("h-3.5 w-3.5 shrink-0 transition-transform",x&&"rotate-180")}),e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0})]}),x&&e.jsxs("div",{className:"space-y-4 rounded-xl border border-border/60 bg-background/35 p-4",children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ie,{htmlFor:"native-session-id",className:"text-xs font-medium text-muted-foreground",children:"Session ID"}),e.jsx(nt,{id:"native-session-id",type:"text",value:f,onChange:R=>{N(""),w(R.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:y,className:"h-10 rounded-sm border-border/70 bg-background/70 font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ie,{htmlFor:"native-session-title",className:"text-xs font-medium text-muted-foreground",children:"Task title"}),e.jsx(nt,{id:"native-session-title",type:"text",value:k,onChange:R=>E(R.target.value),placeholder:"Optional",className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm"})]})]}),e.jsx(cs,{value:C,onChange:R=>{N(""),S(R)},assignTo:M,nodes:t,assignableNodes:p}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ie,{className:"text-xs font-medium text-muted-foreground",children:"Mode"}),e.jsxs(Ne,{value:D,onValueChange:R=>X(R),children:[e.jsx(ke,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Me,{placeholder:"Select mode"})}),e.jsx(Se,{children:Wl()})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ie,{className:"text-xs font-medium text-muted-foreground",children:"Priority"}),e.jsxs(Ne,{value:$,onValueChange:F,children:[e.jsx(ke,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Me,{placeholder:"Select priority"})}),e.jsxs(Se,{children:[e.jsx(xe,{value:"low",children:"Low"}),e.jsx(xe,{value:"normal",children:"Normal"}),e.jsx(xe,{value:"high",children:"High"}),e.jsx(xe,{value:"critical",children:"Critical"})]})]})]})]})]})]}),e.jsxs("div",{className:A("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",m),children:[i&&e.jsx(Z,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:h}),e.jsx(Z,{type:"submit",disabled:!U||q,className:"rounded-sm px-5",children:q?e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"h-4 w-4 animate-spin"})," Loading..."]}):g})]})]})}function Va(t,s,n=!1){const r=t.trim();if(r)return r;const o=s.trim().split(`
|
|
149
|
-
`).map(i=>i.trim()).find(Boolean);return o?o.length>72?`${o.slice(0,69).trimEnd()}...`:o:n?"Image task":""}function td(t){var c;const s=t.title.trim(),n=Va(t.title,t.description,t.images.length>0),r=t.description.trim()||n,o=t.mode??Ot,i=Sa(t.description,t.images);return!n||!r||!t.agent?null:{title:n,description:r,agent:t.agent,project:t.project.trim()||null,branch:((c=t.branch)==null?void 0:c.trim())||null,payload:{initialMessage:i,mode:o,titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function sd({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:c,onCancel:m,className:g,footerClassName:h,submitLabel:y="Create chat",cancelLabel:p="Cancel",autoFocus:l=!1,layout:k="default"}){const[E,j]=a.useState(""),[_,b]=a.useState(""),[N,f]=a.useState(vn),[w,C]=a.useState(Ot),[S,M]=a.useState((i==null?void 0:i.trim())??""),P=a.useRef(i!==void 0),[$,F]=a.useState(""),[D,X]=a.useState("normal"),q=a.useMemo(()=>Fa(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),O=a.useMemo(()=>{var ae;return o&&q.some(ve=>ve.id===o)?o:n&&q.some(ve=>ve.id===n)?n:((ae=q[0])==null?void 0:ae.id)??""},[q,n,o]),[B,re]=a.useState(O),[se,oe]=a.useState(!1),[ne,L]=a.useState(!1),{images:H,error:u,fileInputRef:U,pickImages:x,handleFileChange:W,handlePaste:T,removeImage:G}=Ba(),v=a.useMemo(()=>q.find(ae=>ae.id===B)??null,[B,q]),Y=!!(n&&(v==null?void 0:v.id)===n),Q=_a(N),ue=xi(w);a.useEffect(()=>{B&&q.some(ae=>ae.id===B)||re(O)},[B,q,O]),a.useEffect(()=>{if(P.current){P.current=!1;return}M(za(B)),F("")},[B]),a.useEffect(()=>{F("")},[S]);const ee=a.useCallback(async ae=>{ae.preventDefault();const ve=td({title:E,description:_,agent:N,project:S,branch:$,priority:D,assignTo:B,mode:w,images:H});if(ve){oe(!0);try{const _e=await Zr(ve);c(_e)}catch(_e){le.error(_e instanceof Error?_e.message:"Failed to create task")}finally{oe(!1)}}},[E,_,N,S,$,D,B,w,H,c]),z=Va(E,_,H.length>0),J=!!(z&&N&&B&&(_.trim()||H.length>0)),de=a.useCallback(ae=>{var ve;ae.nativeEvent.isComposing||ae.key==="Enter"&&(ae.ctrlKey||ae.metaKey)&&J&&!se&&(ae.preventDefault(),(ve=ae.currentTarget.form)==null||ve.requestSubmit())},[J,se]),R=H.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:H.map((ae,ve)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Ca(ae),alt:ae.filename??`attachment ${ve+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>G(ve),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 ${ae.filename??`image ${ve+1}`}`,children:e.jsx(Je,{className:"h-3.5 w-3.5"})})]},`${ae.filename??"image"}-${ve}`))}),ie=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{className:"text-sm font-medium",children:"Assign to"}),e.jsxs(Ne,{value:B,onValueChange:re,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Me,{placeholder:"Select node"})}),e.jsx(Se,{children:zs(q,n)})]})]}),Ce=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{className:"text-sm font-medium",children:"Agent"}),e.jsxs(Ne,{value:N,onValueChange:f,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Me,{placeholder:"Select agent"})}),e.jsx(Se,{children:_n()})]})]}),Ee=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{className:"text-sm font-medium",children:"Mode"}),e.jsxs(Ne,{value:w,onValueChange:ae=>C(ae),children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Me,{placeholder:"Select mode"})}),e.jsx(Se,{children:Tn()})]})]}),Oe=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{className:"text-sm font-medium",children:"Priority"}),e.jsxs(Ne,{value:D,onValueChange:X,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Me,{placeholder:"Select priority"})}),e.jsxs(Se,{children:[e.jsx(xe,{value:"low",children:"Low"}),e.jsx(xe,{value:"normal",children:"Normal"}),e.jsx(xe,{value:"high",children:"High"}),e.jsx(xe,{value:"critical",children:"Critical"})]})]})]}),Le=e.jsx(cs,{value:S,onChange:M,assignTo:B,nodes:t,assignableNodes:q}),ze=e.jsx(In,{value:$,onChange:F,project:S,assignTo:B,nodes:t,assignableNodes:q});return k==="composer"?e.jsxs("form",{onSubmit:ee,className:A("space-y-4",g),children:[e.jsx("input",{ref:U,type:"file",accept:"image/*",multiple:!0,onChange:W,className:"hidden"}),(()=>{const ae="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",ve="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",_e="border-border/70 bg-background/55 text-foreground",Re=N===vn,Fe=w===Ot;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/54 shadow-[0_24px_86px_-48px_rgba(15,23,42,0.55)] backdrop-blur-xl dark:shadow-[0_24px_86px_-48px_rgba(0,0,0,0.9)]",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(Ne,{value:B,onValueChange:re,children:[e.jsx(ke,{className:A(ae,_e,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${(v==null?void 0:v.name)??"unassigned"}`,"aria-label":`Assigned node: ${(v==null?void 0:v.name)??"unassigned"}`,children:v?e.jsxs(e.Fragment,{children:[e.jsx(tn,{isCurrent:Y}),e.jsx("span",{className:"min-w-0 truncate",children:v.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(Me,{placeholder:"Select node"})}),e.jsx(Se,{children:zs(q,n)})]}),ne?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(nt,{id:"task-title-composer",type:"text",value:E,onChange:we=>j(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(Z,{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($t,{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:z||"Title","aria-label":z?`Edit title: ${z}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:z||"Title"}),e.jsx(At,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:_,onChange:we=>b(we.target.value),onKeyDown:de,onPaste:T,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-xl 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(Z,{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(Rs,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(Ne,{value:N,onValueChange:f,children:[e.jsxs(ke,{className:A(ae,"chat-composer__icon-trigger",Re?ve:_e),title:`Agent: ${Q}`,"aria-label":`Agent: ${Q}`,children:[e.jsx(Qs,{agent:N}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:Q})]}),e.jsx(Se,{children:_n()})]}),e.jsxs(Ne,{value:w,onValueChange:we=>C(we),children:[e.jsxs(ke,{className:A(ae,"chat-composer__icon-trigger",Fe?ve:_e),title:`Mode: ${ue}`,"aria-label":`Mode: ${ue}`,children:[e.jsx(ol,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:ue})]}),e.jsx(Se,{children:Tn()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(Ne,{value:D,onValueChange:X,children:[e.jsx(ke,{"aria-label":`Priority: ${D}`,title:`Priority: ${D}`,className:A("h-9 w-9 justify-center gap-0 rounded-sm p-0 text-xs shadow-none [&>svg:last-child]:hidden",D==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",D==="critical"&&"text-destructive",D==="high"&&"text-amber-600 dark:text-amber-400",D==="low"&&"text-muted-foreground"),children:e.jsx(Bi,{className:A("h-4 w-4",D==="critical"&&"fill-destructive/20")})}),e.jsxs(Se,{children:[e.jsx(xe,{value:"low",children:"Low"}),e.jsx(xe,{value:"normal",children:"Normal"}),e.jsx(xe,{value:"high",children:"High"}),e.jsx(xe,{value:"critical",children:"Critical"})]})]}),m&&e.jsxs(Z,{type:"button",variant:"ghost",size:"sm",onClick:m,"aria-label":p,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(Je,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:p})]}),e.jsxs(Z,{type:"submit",size:"icon",disabled:!J||se,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[se?e.jsx(he,{className:"h-4 w-4 animate-spin"}):e.jsx(Aa,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:se?"Creating chat":y})]})]})]})]}),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(cs,{value:S,onChange:M,assignTo:B,nodes:t,assignableNodes:q,layout:"composer",chipClassName:ae,chipActiveClassName:we,chipInactiveClassName:we,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(In,{value:$,onChange:F,project:S,assignTo:B,nodes:t,assignableNodes:q,layout:"composer",chipClassName:ae,chipActiveClassName:we,chipInactiveClassName:we,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(R||u)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 bg-background/45 p-4",children:[R,u&&e.jsx("div",{className:"text-xs text-destructive",children:u}),!u&&e.jsx("div",{className:"text-xs 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:ee,className:A("space-y-5",g),children:[e.jsx("input",{ref:U,type:"file",accept:"image/*",multiple:!0,onChange:W,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{htmlFor:"task-description",className:"text-sm font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:_,onChange:ae=>b(ae.target.value),onKeyDown:de,onPaste:T,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:l,className:"flex min-h-[144px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-xl border border-border/70 bg-background/70 px-4 py-3 text-sm leading-6 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-3",children:[e.jsxs(Z,{type:"button",variant:"outline",onClick:x,className:"rounded-sm",children:[e.jsx(Rs,{className:"h-4 w-4"}),"Add images"]}),e.jsx("p",{className:"text-xs 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."})]}),R,u&&e.jsx("p",{className:"text-xs text-destructive",children:u})]}),e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1fr)_220px_220px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(nt,{id:"task-title",type:"text",value:E,onChange:ae=>j(ae.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-11 rounded-lg border-border/70 bg-background/70"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:z?`Will appear as: ${z}`:"A title will be generated from the first line of the prompt."})]}),Ce,Ee]}),Le,ze,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[Oe,ie]}),e.jsxs("div",{className:A("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",h),children:[m&&e.jsx(Z,{type:"button",variant:"ghost",onClick:m,className:"rounded-sm",children:p}),e.jsx(Z,{type:"submit",disabled:!J||se,className:"rounded-sm px-5",children:se?"Creating...":y})]})]})}function nd({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:c,onCancel:m,defaultMode:g="chat",mode:h,onModeChange:y,layout:p="default",className:l,footerClassName:k,autoFocus:E=!1}){const[j,_]=a.useState(g),b=h!==void 0,N=b?h:j,f=w=>{b||_(w),y==null||y(w)};return e.jsxs("div",{className:A("space-y-4",l),children:[!b&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 bg-background/45 p-1",children:[e.jsxs(Z,{type:"button",variant:N==="chat"?"default":"ghost",onClick:()=>f("chat"),className:"flex-1 rounded-sm",children:[e.jsx(Jr,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(Z,{type:"button",variant:N==="native"?"default":"ghost",onClick:()=>f("native"),className:"flex-1 rounded-sm",children:[e.jsx(Zs,{className:"h-4 w-4"}),"Load session"]})]}),N==="chat"?e.jsx(sd,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:c,onCancel:m,footerClassName:k,submitLabel:p==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:E,layout:p},`${o??""}:${i??""}`):e.jsx(ed,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:c,onCancel:m,footerClassName:k,autoFocus:E})]})}function ad({onClick:t,running:s}){return e.jsxs(Z,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:A("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(At,{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 Rn({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 rd({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",Ua=`${_t} (MSIT)`;function od({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:o,stopping:i=!1,shareResult:c}){return e.jsx(Ht,{open:t,onOpenChange:s,children:e.jsxs(qt,{className:"max-w-md rounded-xl p-5",children:[e.jsx(us,{className:"sr-only",children:"Share conversation"}),e.jsx(id,{onOpenChange:s,onShare:n,onStopShare:r,sharing:o,stopping:i,shareResult:c})]})})}function id({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:o=!1,shareResult:i}){const[c,m]=a.useState((i==null?void 0:i.tenant)??_t),[g,h]=a.useState((i==null?void 0:i.scope)??"chat"),y=i!=null&&i.url?ha(i.url):null,p=r||o;return a.useEffect(()=>{m((i==null?void 0:i.tenant)??_t),h((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-base 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(ld,{value:c,onChange:m,disabled:p}),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($n,{active:g==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>h("chat")}),e.jsx($n,{active:g==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>h("filesPreview")})]})]}),y&&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:y,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void Ct(y,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(pa,{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(Z,{variant:"outline",onClick:()=>t(!1),disabled:p,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(Z,{variant:"outline",onClick:()=>void n(),disabled:p,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[o&&e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(Z,{onClick:()=>void s({tenant:c,scope:g}),disabled:p,className:"h-8 text-xs",children:[r&&e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function ld({value:t,onChange:s,disabled:n}){const[r,o]=a.useState(!1),[i,c]=a.useState(!1),[m,g]=a.useState(t),h=a.useRef(null);a.useEffect(()=>{g(t)},[t]),a.useEffect(()=>{if(!r)return;const p=k=>{var j;const E=k.target;E instanceof Node&&((j=h.current)!=null&&j.contains(E)||(o(!1),c(!1)))},l=k=>{k.key==="Escape"&&(o(!1),c(!1))};return document.addEventListener("mousedown",p),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",l)}},[r]);const y=p=>{const l=p.trim();l&&(s(l),g(l),c(!1),o(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:h,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(p=>!p),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:dd(t)}),e.jsx(Ze,{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-lg border border-border/60 bg-background/95 text-xs shadow-lg backdrop-blur",children:[e.jsxs("button",{type:"button",onClick:()=>y(_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:Ua}),t===_t&&e.jsx($t,{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:m,onChange:p=>g(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),y(m))},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:()=>y(m),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx($t,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{g(t),c(!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(Je,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>c(!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(At,{className:"h-3 w-3"})]})})]})]})]})}function dd(t){return t===_t?Ua:t}function $n({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 cd(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 ud({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(Yi,{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)=>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.jsx("span",{className:"min-w-0 flex-1 break-words [overflow-wrap:anywhere]",children:cd(n.content)}),s&&e.jsx(Z,{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(Je,{className:"h-3 w-3"})})]},n.id))})]})})}const md=30,xd=1600;function hd({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Cs(t){return t.scrollHeight-t.scrollTop-t.clientHeight<md}function On({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function pd({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 c=a.useRef(null),m=a.useRef(s),g=a.useRef(!1),h=a.useRef(0),y=a.useRef(new Map),p=a.useRef(0),l=a.useRef(!0),k=a.useCallback((f=m.current)=>{const w=c.current;!w||!f||(y.current.set(f,w.scrollTop),h.current=w.scrollTop,l.current=Cs(w))},[]),E=a.useCallback((f=m.current)=>{const w=c.current;!w||!f||(w.scrollTop=hd({savedScrollTop:y.current.get(f),scrollHeight:w.scrollHeight,clientHeight:w.clientHeight}),h.current=w.scrollTop,l.current=Cs(w))},[]),j=a.useCallback((f,w=m.current)=>{f.scrollTop=f.scrollHeight,h.current=f.scrollTop,l.current=!0,w&&y.current.set(w,f.scrollTop)},[]),_=a.useCallback((f=m.current)=>{const w=c.current;p.current=Date.now()+xd,w&&(j(w,f),requestAnimationFrame(()=>{j(w,f),requestAnimationFrame(()=>j(w,f))}))},[j]),b=a.useCallback(f=>{const w=f.currentTarget,C=h.current,S=w.scrollTop<C&&C-w.scrollTop>10,M=w.scrollTop<=0;if(k(),!g.current){if(Cs(w)){i(!1),g.current=!0,setTimeout(()=>{g.current=!1},300);return}(S||M)&&(p.current=0,pd({atTop:M,inputCollapseDisabled:r,scrollingUp:S})&&i(!0))}},[r,k,i]),N=a.useCallback(f=>{t==="transcript"&&k(),o(f),f==="transcript"&&requestAnimationFrame(()=>E())},[t,E,k,o]);return a.useLayoutEffect(()=>{r&&i(!1)},[r,i]),a.useLayoutEffect(()=>{const f=m.current;f&&f!==s&&k(f),m.current=s,t==="transcript"&&requestAnimationFrame(()=>E(s))},[s,t,E,k]),a.useLayoutEffect(()=>{const f=c.current;if(!f||t!=="transcript"||!s)return;On({explicitBottomStickUntil:p.current,now:Date.now(),wasAtBottom:l.current})&&j(f,s),k(s)},[s,t,n,k,j]),a.useLayoutEffect(()=>{const f=c.current,w=f==null?void 0:f.firstElementChild;if(!f||!w||t!=="transcript"||typeof ResizeObserver>"u")return;const C=new ResizeObserver(()=>{On({explicitBottomStickUntil:p.current,now:Date.now(),wasAtBottom:l.current})?j(f):k()});return C.observe(f),C.observe(w),()=>C.disconnect()},[t,s,k,j]),{handleTranscriptScroll:b,handleTranscriptTabChange:N,scrollTranscriptToBottom:_,transcriptScrollRef:c}}function Ha(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 sn="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",gd="rounded-none border-b border-transparent !bg-transparent px-0 pb-1 pt-0 text-[11px] font-medium !shadow-none data-[state=active]:border-primary data-[state=active]:!bg-transparent data-[state=active]:!shadow-none",bd=a.lazy(async()=>({default:(await Gs(()=>import("./FilesTab-Cg5PBMv6.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),vd=a.lazy(async()=>({default:(await Gs(()=>import("./PreviewTab-CoN0CJR0.js"),__vite__mapDeps([6,1,2,7]))).PreviewTab})),jd=a.lazy(async()=>({default:(await Gs(()=>import("./DiffTab-BEsNBvvh.js"),__vite__mapDeps([8,1,2,5,4,7,3]))).DiffTab}));function wd({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:c,activeTab:m,setActiveTab:g,creatingTask:h,createMode:y,createDefaults:p,activeTask:l,assignedNode:k,taskLoading:E,transcriptLoading:j,taskError:_,displayEvents:b,initialPromptAlreadyInLogs:N,initialPrompt:f,supportsFollowUp:w,taskUnavailable:C,chatDisabled:S,chatDisabledReason:M,questionBypassEnabled:P,isRunning:$,isStarting:F,hasPendingFollowUp:D,canCancel:X,canRetry:q,onRetry:O,onCancel:B,onReloadNativeTranscript:re,onShareTask:se,onStopShareTask:oe,onStartCreateTask:ne,onCancelCreateTask:L,onCreateTask:H,onSendMessage:u,onCancelQueuedMessage:U,onQuestionBypassChange:x,onSubmitQuestionResponse:W}){const[T,G]=a.useState(!1),[v,Y]=a.useState(!1),[Q,ue]=a.useState(!1),[ee,z]=a.useState(!1),[J,de]=a.useState(!1),[R,ie]=a.useState({}),[Ce,Ee]=a.useState(new Set),[Oe,Le]=a.useState(new Set),[ze,ae]=a.useState(null),ve=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",_e=l?(k==null?void 0:k.name)??Ds(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",Re=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:_e}),"..."]}):"Connecting session to an available node...",Fe=l?[{label:"Working dir",value:ve,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:_e}]:[],we=!!(f&&!N),rt=we||b.length>0,jt=$&&rt,ot=(F||D||$)&&!jt,Ke=jt?"The agent is still working on this conversation.":ot?Re:null,{collapsedButtonRunning:wt,showDockedProgress:$e,showInlineProgress:V}=rd({hasTranscriptProgress:!!Ke,hasVisibleTranscriptEvents:rt,inputCollapsed:T}),ce=(l==null?void 0:l.conversationKind)==="nativeSession",Te=j?"Loading transcript":ce?"No transcript imported":"Transcript is warming up",ht=j?"Loading transcript...":ce?"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.",pt=(l==null?void 0:l.queuedMessages)??[],ft=a.useMemo(()=>hi(b),[b]),De=a.useMemo(()=>pi("transcript",ft.map(pe=>pe.event)),[ft]),He=l&&!Ce.has(l.id)?R[l.id]??l.activeShare??null:null,it=(l==null?void 0:l.id)??null,yt=`${it??"none"}:${b.length}:${pt.length}:${we?1:0}:${j?1:0}:${V?1:0}`,{handleTranscriptScroll:et,handleTranscriptTabChange:gt,scrollTranscriptToBottom:lt,transcriptScrollRef:dt}=fd({activeTab:m,activeTaskId:it,contentVersion:yt,inputCollapseDisabled:!!Ke,setActiveTab:g,setInputCollapsed:G}),{markScrollbarActive:ye,scrollbarActive:at}=Ha(),Ae=a.useCallback(pe=>{ye(),et(pe)},[et,ye]),ct=a.useCallback(pe=>{ae(je=>({path:pe,requestId:((je==null?void 0:je.requestId)??0)+1})),gt("files")},[gt]),ut=a.useCallback(pe=>{lt(),u(pe)},[u,lt]);return a.useEffect(()=>{ae(null)},[it]),h?e.jsx(yd,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:c,defaultMode:y,createDefaults:p,onCancel:L,onCreated:H}):!l&&E?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(Fs,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:c})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(he,{className:"h-7 w-7 animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl 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(he,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(qs,{value:m,onValueChange:gt,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(qa,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:o,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:A(sn,"xl:hidden"),children:r?e.jsx(Ue,{className:Tt}):e.jsx(Ft,{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(fa,{status:l.status,isNative:ce}),l.priority!=="normal"&&e.jsx(to,{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(Ks,{className:"h-auto max-w-full justify-start gap-3 overflow-x-auto rounded-none !bg-transparent !p-0 !shadow-none",children:["transcript","files","diff","preview"].map(pe=>e.jsx(bt,{value:pe,className:gd,children:pe[0].toUpperCase()+pe.slice(1)},pe))}),C&&e.jsx(Be,{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:so(l.updatedAt)}),q&&e.jsxs(Z,{variant:"outline",size:"sm",onClick:O,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(tl,{className:"h-3.5 w-3.5"}),"Retry"]}),ce&&re&&e.jsx(Z,{variant:"ghost",size:"icon",onClick:re,disabled:j,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(Da,{className:A("h-3.5 w-3.5",j&&"animate-spin")})}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",disabled:C,title:C?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":C?"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:()=>ue(!0),children:e.jsx(ds,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(st,{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:dt,"data-transcript-scroll":"true",className:A("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",at&&"scrollbar-line-active"),onScroll:Ae,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[we&&f&&e.jsx(En,{event:f,agent:l.agent,taskRootPath:l.effectiveProjectPath,onOpenFilePath:ct,questionBypassEnabled:P,onQuestionBypassChange:x,onSubmitQuestionResponse:W,questionResponseDisabled:!w||S}),ft.map(({event:pe,subItems:je},tt)=>e.jsx(En,{event:pe,agent:l.agent,subItems:je,taskRootPath:l.effectiveProjectPath,onOpenFilePath:ct,questionBypassEnabled:P,onQuestionBypassChange:x,onSubmitQuestionResponse:W,questionResponseDisabled:!w||S},De[tt])),!rt&&!ot&&e.jsxs("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-5 py-8 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:Te}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:ht})]}),(!w&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!w&&l.result&&e.jsxs("div",{className:"rounded-xl 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&&!Oe.has(l.id)&&e.jsxs("div",{className:"rounded-xl 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:()=>Le(pe=>new Set(pe).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(Je,{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})]})]}),V&&Ke&&e.jsx(Rn,{children:Ke})]})})}),$e&&Ke&&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(Rn,{children:Ke})})}),w?e.jsxs(e.Fragment,{children:[T&&e.jsx(ad,{running:wt,onClick:()=>{G(!1),lt(),requestAnimationFrame(()=>{var pe;return(pe=document.querySelector('[data-chat-input-textarea="true"]'))==null?void 0:pe.focus()})}}),e.jsxs("div",{className:`shrink-0 ${T?"hidden":""}`,children:[e.jsx(ud,{messages:pt,onCancelMessage:U}),e.jsx(_l,{onSend:ut,disabled:S,disabledReason:M,contextItems:Fe,placeholder:S?M:$?"Queue a message for the next turn...":"Continue the conversation...",running:$||D,onStop:X?()=>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(st,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(ks,{label:"Loading files..."}),children:e.jsx(bd,{taskId:l.id,requestedFilePath:(ze==null?void 0:ze.path)??null,requestedFileRequestId:(ze==null?void 0:ze.requestId)??0})})}),e.jsx(st,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(ks,{label:"Loading preview..."}),children:e.jsx(vd,{taskId:l.id})})}),e.jsx(st,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(ks,{label:"Loading diff..."}),children:e.jsx(jd,{taskId:l.id})})}),e.jsx(es,{open:v,onOpenChange:Y,children:e.jsxs(ts,{children:[e.jsxs(ss,{children:[e.jsx(ns,{children:"Stop this task?"}),e.jsx(as,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(rs,{children:[e.jsx(os,{children:"Keep running"}),e.jsx(is,{onClick:B,children:"Stop task"})]})]})}),e.jsx(od,{open:Q,onOpenChange:ue,sharing:ee,stopping:J,shareResult:He,onShare:async pe=>{if(!l)return null;z(!0);try{const je=await se(pe);return je!=null&&je.url&&(ie(tt=>({...tt,[l.id]:je})),Ee(tt=>{const Nt=new Set(tt);return Nt.delete(l.id),Nt})),je}finally{z(!1)}},onStopShare:async()=>{if(!l)return!1;de(!0);try{const pe=await oe();return pe!==!1&&(ie(je=>{const tt={...je};return delete tt[l.id],tt}),Ee(je=>new Set(je).add(l.id))),pe}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(Fs,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:c})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(eo,{className:"h-7 w-7"})}),e.jsx("h2",{className:"mt-5 text-xl font-semibold tracking-tight text-foreground sm:text-3xl",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-3 max-w-xl text-[11px] leading-6 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(Z,{onClick:()=>ne(),className:"mt-6 rounded-lg px-5",children:[e.jsx(xs,{className:"h-4 w-4"}),"Start or load chat"]}),_&&e.jsx("div",{className:"mx-auto mt-4 max-w-lg rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:_})]})})]})}function yd({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:c,defaultMode:m,createDefaults:g,onCancel:h,onCreated:y}){var E,j,_;const[p,l]=a.useState(m??"chat");a.useEffect(()=>{m&&l(m)},[m]);const k=e.jsx("div",{className:"flex items-center gap-1 rounded-lg border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-sm",children:[{value:"chat",label:"New chat",icon:xs},{value:"native",label:"Load session",icon:Zs}].map(b=>{const N=b.icon,f=b.value===p;return e.jsxs("button",{type:"button",onClick:()=>l(b.value),"aria-pressed":f,className:A("flex items-center gap-1.5 rounded-sm px-2 py-1 transition-all duration-200",f?"bg-primary text-primary-foreground shadow-[0_8px_24px_-12px_hsl(var(--primary)/0.7)]":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(N,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:b.label})]},b.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(Fs,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:c,centerSlot:k})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(nd,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(E=i==null?void 0:i.self)==null?void 0:E.role,currentNodeId:((j=i==null?void 0:i.self)==null?void 0:j.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:p,onModeChange:l,onCreated:y,onCancel:h,autoFocus:!0,layout:"composer"})})})]})}function Fs({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(qa,{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(Z,{variant:"ghost",size:"icon",onClick:o,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:A(sn,"xl:hidden"),children:r?e.jsx(Ue,{className:Tt}):e.jsx(Ft,{className:Tt})})]})}function qa({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){var i,c;const o=(c=(i=globalThis.window)==null?void 0:i.matchMedia("(min-width: 1024px)"))!=null&&c.matches?s:n;return e.jsx(Z,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:A(sn,t),children:o?e.jsx(Ft,{className:Tt}):e.jsx(Ue,{className:Tt})})}function Nd({onAdded:t}){const[s,n]=a.useState(""),[r,o]=a.useState(!1),[i,c]=a.useState(null),m=a.useCallback(async g=>{if(g.preventDefault(),!!s.trim()){o(!0),c(null);try{await no({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(h){c(h instanceof Error?h.message:"Failed to join node")}finally{o(!1)}}},[s,t]);return e.jsx(qt,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-xl border border-border/60 bg-background/95 p-0 shadow-[0_40px_120px_-60px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-6 py-5",children:e.jsxs(Ws,{className:"space-y-2 text-left",children:[e.jsx(us,{className:"text-2xl tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-sm 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:m,className:"space-y-4 px-6 py-5",children:[i&&e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm 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(Ie,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Be,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(nt,{id:"leader-endpoint",type:"url",value:s,onChange:g=>n(g.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-11 rounded-lg border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-lg border border-border/60 bg-background/45 px-4 py-3 text-sm 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(ga,{className:"border-t border-border/60 pt-4",children:e.jsx(Z,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function kd({open:t,onOpenChange:s,onAdded:n}){return e.jsx(Ht,{open:t,onOpenChange:s,children:e.jsx(Nd,{onAdded:()=>{s(!1),n()}})})}const Sd="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",Cd="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",_d="h-2.5 w-2.5";function Ka({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:A("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 Td({className:t,label:s,onToggle:n,side:r,visible:o}){const i=r==="left"?o?Ft:Ue:o?Ue:Ft;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:A(Sd,t),children:e.jsx("span",{className:Cd,"aria-hidden":"true",children:e.jsx(i,{className:_d,strokeWidth:2.1})})})}function zn({className:t,label:s,onToggle:n,panel:r,panelResize:o,screen:i,side:c,visible:m}){const g=i==="lg"?"lg:block":"xl:block",h=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:A("group absolute top-0 z-30 hidden h-full w-4",g,t),children:[r&&e.jsx(Ka,{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(Td,{side:c,visible:m,label:s,onToggle:n,className:A(h,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function Ed({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:o,operationsOpen:i,operationsPanelRef:c,operationsSidecar:m,panelResize:g,taskSidebar:h,terminalPanel:y,onCloseOperations:p,onCloseTaskList:l,onToggleOperations:k,onToggleTasks:E}){const j={"--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:j,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(zn,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:E,panel:s?"tasks":void 0,panelResize:g,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:A("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&&h}),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}),y&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(Ka,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:g,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),y]})]}),e.jsx(zn,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:k,panel:i?"operations":void 0,panelResize:g,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:A("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&&m})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:p,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:c,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:m})]}),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 Dd=10,vt="__all__";function qe(t){return"session"in t}function Fn(t,s){var n;return s&&t.some(r=>r.id===s)?s:((n=t[0])==null?void 0:n.id)??""}function _s(t){return t&&(za(t.id)||t.workDir)||""}function Qt(t,s,n){let r=!1;const o=t.map(i=>qe(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return Vs(r?o:[...o,{id:`session-${n.id}`,nodeName:s,session:n}])}function Ga(t,s){return t.filter(qe).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function Ad(t){const s=t.filter(qe).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 Md(t,s){return!!(t&&s&&!t.contains(s))}function Pd(t,s,n){var o;if(n===vt)return n;const r=Ga(t,s);return r.some(i=>i.session.id===n)?n:((o=r[0])==null?void 0:o.session.id)??vt}function Ld(t,s,n){return n===vt?t.filter(r=>!qe(r)||r.session.nodeId===s):t.filter(r=>qe(r)&&r.session.nodeId===s&&r.session.id===n)}function Vs(t){const s=t.map((r,o)=>({entry:r,index:o})).filter(({entry:r})=>qe(r)&&r.session.status!=="running").sort((r,o)=>!qe(r.entry)||!qe(o.entry)?0:o.entry.session.startedAt-r.entry.session.startedAt||o.index-r.index),n=new Set(s.slice(0,Dd).map(({entry:r})=>qe(r)?r.session.id:""));return t.filter(r=>!qe(r)||r.session.status==="running"||n.has(r.session.id))}function Us(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 Id(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${Us(t.session)} - ${s}`}function Wa(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function Bd(t,s){return s===vt?"All sessions":t?Wa(t.session.command,34):"Command session"}function Vn(t){return t.status==="stopped"?"":t.stderr}function Rd({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[o,i]=a.useState(()=>Fn(t,s)),c=a.useMemo(()=>t.find(x=>x.id===o)??t[0]??null,[t,o]),[m,g]=a.useState(()=>_s(c)),[h,y]=a.useState(""),[p,l]=a.useState(()=>Vs(r)),[k,E]=a.useState(vt),[j,_]=a.useState(!1),[b,N]=a.useState(!1),[f,w]=a.useState(!1),[C,S]=a.useState(!1),[M,P]=a.useState(!1),$=a.useRef(null),F=a.useRef(null),D=a.useMemo(()=>t.find(x=>x.id===o)??t[0]??null,[t,o]),X=a.useMemo(()=>Ga(p,(D==null?void 0:D.id)??""),[p,D]),q=a.useMemo(()=>Ad(X),[X]),O=a.useMemo(()=>X.find(x=>x.session.id===k),[k,X]),B=a.useMemo(()=>Ld(p,(D==null?void 0:D.id)??"",k),[p,D,k]),re=a.useRef((D==null?void 0:D.id)??"");a.useEffect(()=>{o&&t.some(x=>x.id===o)||i(Fn(t,s))},[s,t,o]),a.useEffect(()=>{const x=(D==null?void 0:D.id)??"";re.current!==x&&(re.current=x,g(_s(D)))},[D]),a.useEffect(()=>{E(x=>Pd(p,(D==null?void 0:D.id)??"",j?x:""))},[p,D,j]),a.useEffect(()=>{var x;(x=$.current)==null||x.scrollTo({top:$.current.scrollHeight})},[p]),a.useEffect(()=>{let x=!1;async function W(){const T=await Promise.allSettled(t.map(async G=>({node:G,response:await ro(G.id)})));x||l(G=>T.reduce((v,Y)=>Y.status!=="fulfilled"?v:Y.value.response.sessions.reduce((Q,ue)=>Qt(Q,Y.value.node.name,ue),v),G))}return t.length>0&&W(),()=>{x=!0}},[t]),a.useEffect(()=>{const x=p.filter(qe).filter(T=>T.session.status==="running");if(x.length===0)return;const W=window.setInterval(()=>{for(const T of x)ao(T.session.nodeId,T.session.id).then(G=>l(v=>Qt(v,T.nodeName,G))).catch(()=>{})},1e3);return()=>window.clearInterval(W)},[p]);const se=a.useRef(null);async function oe(x){if(x.preventDefault(),!D||!h.trim()||M)return;const W=h.trim(),T=D.name;P(!0),y("");try{const G=await io(D.id,{command:W,...m.trim()?{cwd:m.trim()}:{}});l(v=>Qt(v,T,G)),E(G.id),_(!0)}catch(G){l(v=>[...v,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:T,command:W,error:G instanceof Error?G.message:"Command failed"}])}finally{P(!1)}}async function ne(x,W){x.stopPropagation();const T=await oo(W.session.nodeId,W.session.id);l(G=>Qt(G,W.nodeName,T))}function L(x){E(x),_(!0),N(!1)}function H(x){b&&Md(F.current,x.target)&&N(!1)}function u(x,W,T,G,v){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":!T,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(Ze,{className:A("h-3 w-3 transition-transform",T&&"-rotate-90")})]}),!T&&(W.length>0?W.map(U):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:v}))]})}function U(x){const W=k===x.session.id,T=x.session.status==="running";return e.jsxs("div",{className:A("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",W&&"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:A("flex h-4 w-4 shrink-0 items-center justify-center",T?"text-primary":x.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:T?e.jsx(he,{className:"h-3 w-3 animate-spin"}):x.session.status==="exited"?e.jsx(wn,{className:"h-3 w-3"}):e.jsx(ys,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:Wa(x.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[x.nodeName," · ",Us(x.session)]})]})]}),T&&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(Mn,{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(Je,{className:"h-3.5 w-3.5"})}):e.jsx(jn,{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:F,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":b,title:O?Id(O):"All sessions",onClick:()=>N(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:Bd(O,k)}),e.jsx(Ze,{className:A("h-3 w-3 shrink-0 text-muted-foreground transition-transform",b&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!b,className:A("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!b&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>L(vt),className:A("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",k===vt&&"bg-primary/10 text-primary"),children:[e.jsx(jn,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),u("Active",q.active,f,()=>w(x=>!x),"No active sessions"),u("Completed",q.completed,C,()=>S(x=>!x),"No completed sessions")]})})]}),e.jsx("select",{value:(D==null?void 0:D.id)??"",onChange:x=>{i(x.target.value),_(!1),g(_s(t.find(W=>W.id===x.target.value)??null))},disabled:M||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(cs,{value:m,onChange:g,assignTo:(D==null?void 0:D.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:$,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=se.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=>qe(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:A("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(he,{className:"h-3 w-3 animate-spin"}):x.session.status==="exited"?e.jsx(wn,{className:"h-3 w-3"}):e.jsx(ys,{className:"h-3 w-3"}),Us(x.session)]}),x.session.status==="running"&&e.jsx("button",{type:"button",onClick:W=>void ne(W,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(Mn,{className:"h-3 w-3"})})]}),x.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:x.session.stdout}),Vn(x.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Vn(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(ys,{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:D?`${D.name}$`:"$"}),e.jsx("input",{ref:se,value:h,onChange:x=>y(x.target.value),disabled:!D||M,placeholder:D?"":"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:!D||!h.trim()||M,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:M?e.jsx(he,{className:"h-3 w-3 animate-spin"}):e.jsx(Xs,{className:"h-3 w-3"})})]})]})]})})}function nn({nodeId:t,nodeName:s,onOpenSettings:n,onOpenCapabilities:r,onOpenDevBox:o,onStartDevBox:i,onToggleRemoteAccess:c,remoteAccessLabel:m,remoteAccessPending:g,remoteAccessDisabled:h,remoteAccessDisabledReason:y,showConfigureDevBox:p,showStartDevBox:l,startDevBoxPending:k,className:E}){const[j,_]=a.useState(!1),[b,N]=a.useState(null),f=a.useRef(null),w=a.useRef(null),C=k?"Starting":"Start DevBox",S=m!=null&&m.startsWith("Disable")?lo:ml;a.useLayoutEffect(()=>{if(!j){N(null);return}const P=()=>{const $=w.current,F=f.current;if(!$||!F)return;const D=$.getBoundingClientRect(),X=F.getBoundingClientRect();N(Od({left:D.left,right:D.right,bottom:D.bottom,top:D.top},{width:X.width,height:X.height},{width:window.innerWidth,height:window.innerHeight},zd()))};return P(),window.addEventListener("resize",P),window.addEventListener("scroll",P,!0),()=>{window.removeEventListener("resize",P),window.removeEventListener("scroll",P,!0)}},[j]),a.useEffect(()=>{if(!j)return;const P=F=>{var X,q;const D=F.target;D instanceof Node&&!((X=f.current)!=null&&X.contains(D))&&!((q=w.current)!=null&&q.contains(D))&&_(!1)},$=F=>{F.key==="Escape"&&_(!1)};return document.addEventListener("mousedown",P),document.addEventListener("keydown",$),()=>{document.removeEventListener("mousedown",P),document.removeEventListener("keydown",$)}},[j]);const M=j?e.jsxs("div",{ref:f,"data-node-action-menu-portal":"true",role:"menu",style:$d(b),onClick:P=>P.stopPropagation(),onPointerDown:P=>P.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:P=>{P.stopPropagation(),_(!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(co,{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":`Open ${s} capabilities`,title:`Open ${s} capabilities`,onClick:P=>{P.stopPropagation(),_(!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(ms,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Capabilities"})]}),m&&c&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${m} for ${s}`,title:y??`${m} for ${s}`,onClick:P=>{P.stopPropagation(),!(g||h)&&(_(!1),c())},disabled:g||h,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:[g?e.jsx(he,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(S,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:m})]}),l&&i&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${C} for ${s}`,title:`${C} for ${s}`,onClick:P=>{P.stopPropagation(),!k&&(_(!1),i(t))},disabled: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:[k?e.jsx(he,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(Xs,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:C})]}),p&&o&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${s}`,title:`Configure DevBox for ${s}`,onClick:P=>{P.stopPropagation(),_(!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(uo,{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:A("relative shrink-0",j&&"z-[120]",E),onClick:P=>P.stopPropagation(),onPointerDown:P=>P.stopPropagation(),children:[e.jsx(Z,{ref:w,type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${s}`,"aria-haspopup":"menu","aria-expanded":j,title:`More actions for ${s}`,onClick:P=>{P.stopPropagation(),_($=>($||N(null),!$))},className:A("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",j&&"bg-background/80 text-primary"),children:e.jsx(Mi,{className:"h-3.5 w-3.5"})}),M&&(typeof document>"u"?M:ba.createPortal(M,document.body))]})}function $d(t){return t?{left:t.left,top:t.top}:{left:0,top:0,visibility:"hidden"}}function Od(t,s,n,r=1){const c=s.width||160,m=s.height||0,g=Number.isFinite(r)&&r>0?r:1,h=Math.max(8,Math.min(t.right-c,n.width-c-8)),y=t.bottom+4,p=(t.top??t.bottom)-m-4,l=y+m>n.height-8&&p>=8?p:y;return{left:Math.round(h/g),top:Math.round(l/g)}}function zd(){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 Fd=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),Vd=new Set(["startinprogress","starting"]);function Et(t){return!!(t!=null&&t.enabled&&t.name)}function Ud(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&Fd.has(s))}function Dt(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&Vd.has(s))}function hs(t,s,n){return t==="offline"&&Ud(s)&&Et(n)}function Un(t,s){return t==="offline"&&Et(s)}function Hn(t){return!Et(t)}function Hd({nodeStatus:t,status:s,current:n,selected:r}){const o=r??n;return o&&hs(t,s,o)?o:null}function Pe(t){return t.scope||`name:${t.name??""}`}function qd({previousKey:t,baseDevBox:s,listed:n}){if(t&&n.some(i=>Pe(i)===t))return t;if(!Et(s))return n[0]?Pe(n[0]):"";const r=Pe(s),o=n.find(i=>Pe(i)===r)??n.find(i=>i.name===s.name);return o?Pe(o):r}function Kd({cluster:t,systemInfo:s,nodeNameById:n,nodeBlockingTaskCounts:r,eventTypeFilter:o,onEventTypeFilterChange:i,eventTypeOptions:c,filteredEvents:m,sseConnected:g,clusterLoading:h,clusterError:y,promotePending:p,onPromote:l,onAddNode:k,leavePending:E,onLeaveCluster:j,onToggleNodeDevTunnel:_,devTunnelNodeId:b,devBoxStartNodeId:N,devBoxStartingNodeIds:f=new Set,onOpenNodeSettings:w,onOpenNodeCapabilities:C,onOpenDevBox:S,onStartDevBox:M}){var se,oe,ne;const P=((se=t==null?void 0:t.self)==null?void 0:se.role)==="leader",$=((oe=t==null?void 0:t.self)==null?void 0:oe.role)==="follower"&&!(t!=null&&t.leader),F=(t==null?void 0:t.self)??null,X=mo((t==null?void 0:t.nodes)??[],F==null?void 0:F.id).filter(L=>L.id!==(F==null?void 0:F.id)),q=t!=null&&t.leader?t.nodes.find(L=>{var H;return L.id===((H=t.leader)==null?void 0:H.id)})??null:null,O=t!=null&&t.leader?t.leader.dashboardOrigin??(q==null?void 0:q.dashboardOrigin)??(s&&t.leader.id===(s.nodeId??s.id)?s.dashboardOrigin:void 0)??t.leader.endpoint:null,B=(F==null?void 0:F.role)==="leader"&&X.length===0,re=(F==null?void 0:F.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(qs,{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(Ks,{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(st,{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:[F&&e.jsx(qn,{node:F,systemInfo:s,blockingTaskCount:r.get(F.id)??0,devTunnelNodeId:b,onToggleNodeDevTunnel:_,showActions:!1,defaultExpanded:!1,onOpenDevBox:S,devBoxStartingNodeIds:f}),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(Be,{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"})]}),h&&!t?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(he,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):y&&!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:y}):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(Xe,{label:"Leader",value:((ne=t==null?void 0:t.leader)==null?void 0:ne.name)??"None"}),e.jsx(Xe,{label:"Leader URL",value:O??"Unavailable",mono:!0,action:O?e.jsx(Vt,{label:"Copy leader URL",onClick:()=>void Ct(O,"Leader URL copied")}):void 0}),e.jsx(Xe,{label:"Feed",value:g?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:$&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:l,disabled:p,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[p&&e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(st,{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(Z,{variant:"secondary",size:"sm",onClick:k,className:"h-6 border-0 bg-primary px-2 text-[10px] text-primary-foreground shadow-none hover:bg-primary/90",children:[e.jsx(cl,{className:"h-3 w-3"}),"Join node"]}):re?e.jsxs(Z,{variant:"secondary",size:"sm",onClick:j,disabled:E,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[E&&e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),F&&e.jsx(qn,{node:F,systemInfo:s,blockingTaskCount:r.get(F.id)??0,devTunnelNodeId:b,onToggleNodeDevTunnel:_,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:P?w:void 0,onOpenNodeCapabilities:P?C:void 0,onOpenDevBox:P?S:void 0,onStartDevBox:P?M:void 0,devBoxStartNodeId:N,devBoxStartingNodeIds:f})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",X.length,")"]}),X.length>0?e.jsx("div",{className:"space-y-1.5",children:X.map(L=>e.jsx(Gd,{node:L,isLeader:!!P,blockingTaskCount:r.get(L.id)??0,devTunnelNodeId:b,onToggleNodeDevTunnel:_,onOpenNodeSettings:P?w:void 0,onOpenNodeCapabilities:P?C:void 0,onOpenDevBox:P?S:void 0,onStartDevBox:P?M:void 0,devBoxStartNodeId:N,devBoxStartingNodeIds:f},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(st,{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(xo,{className:A("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(Ne,{value:o,onValueChange:i,children:[e.jsx(ke,{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(Me,{placeholder:"Event type"})}),e.jsx(Se,{className:"shadow-none",children:c.map(L=>e.jsx(xe,{value:L,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:L==="all"?"All event types":L},L))})]}),e.jsx(Be,{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(ho,{events:m,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 qn({node:t,systemInfo:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:o,showActions:i=!0,defaultExpanded:c=!1,onOpenNodeSettings:m,onOpenNodeCapabilities:g,onOpenDevBox:h,onStartDevBox:y,devBoxStartNodeId:p,devBoxStartingNodeIds:l}){var M,P,$,F;const[k,E]=a.useState(c),j=(s==null?void 0:s.dashboardOrigin)??t.dashboardOrigin,_=t.devtunnelEndpoint??t.endpoint,b=j??t.endpoint,N=(s==null?void 0:s.workDir)??t.workDir,f=La(t,s==null?void 0:s.transportType),w=en(t,s==null?void 0:s.transportType),C=w&&Mt((s==null?void 0:s.transportType)??t.transportType)?!0:Pa(t,s==null?void 0:s.transportType),S=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:()=>E(D=>!D),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[k?e.jsx(Ze,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Ue,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(va,{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:b,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(ja,{className:"h-3 w-3"})}),(m||g||i&&C)&&e.jsx(nn,{nodeId:t.id,nodeName:t.name,onOpenSettings:m,onOpenCapabilities:g,onOpenDevBox:h,onStartDevBox:y,onToggleRemoteAccess:i&&C?()=>o(t):void 0,remoteAccessLabel:i&&C?w?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:S,remoteAccessDisabledReason:S?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:(M=t.devbox)==null?void 0:M.enabled,showStartDevBox:hs(t.status,(P=t.devbox)==null?void 0:P.lastStatus,t.devbox)||Dt(($=t.devbox)==null?void 0:$.lastStatus)||l.has(t.id),startDevBoxPending:p===t.id||Dt((F=t.devbox)==null?void 0:F.lastStatus)||l.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>E(D=>!D),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(wa,{role:t.role,size:"compact"}),e.jsx(Be,{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})]})]}),k&&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(Xe,{label:"Node ID",value:t.id,mono:!0}),j&&e.jsx(Xe,{label:"Dashboard",value:j,mono:!0,action:e.jsx(Vt,{label:"Copy dashboard URL",onClick:()=>void Ct(j,"Dashboard URL copied")})}),e.jsx(Xe,{label:"Node URL",value:_,mono:!0,action:e.jsx(Vt,{label:"Copy node URL",onClick:()=>void Ct(_,"Node URL copied")})}),N&&e.jsx(Xe,{label:"Workspace",value:N,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Ps,{label:"Transport",value:f}),s&&e.jsx(Ps,{label:"Uptime",value:po(s.uptime),mono:!0})]}),i&&g&&e.jsxs(Z,{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(ms,{className:"h-3 w-3"}),"Capabilities"]}),i&&C&&S&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Gd({node:t,isLeader:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:o,onOpenNodeSettings:i,onOpenNodeCapabilities:c,onOpenDevBox:m,onStartDevBox:g,devBoxStartNodeId:h,devBoxStartingNodeIds:y}){var w,C,S,M;const[p,l]=a.useState(!1),k=t.dashboardOrigin,E=t.devtunnelEndpoint??t.endpoint,j=k??t.endpoint,_=La(t),b=en(t),N=Pa(t),f=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(P=>!P),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[p?e.jsx(Ze,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(Ue,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(va,{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:j,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(ja,{className:"h-3 w-3"})}),s&&(i||c||N)&&e.jsx(nn,{nodeId:t.id,nodeName:t.name,onOpenSettings:i,onOpenCapabilities:c,onOpenDevBox:m,onStartDevBox:g,onToggleRemoteAccess:N?()=>o(t):void 0,remoteAccessLabel:N?b?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:f,remoteAccessDisabledReason:f?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:(w=t.devbox)==null?void 0:w.enabled,showStartDevBox:hs(t.status,(C=t.devbox)==null?void 0:C.lastStatus,t.devbox)||Dt((S=t.devbox)==null?void 0:S.lastStatus)||y.has(t.id),startDevBoxPending:h===t.id||Dt((M=t.devbox)==null?void 0:M.lastStatus)||y.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>l(P=>!P),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(wa,{role:t.role,size:"compact"}),e.jsx(Be,{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})]})]}),p&&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(Xe,{label:"Node ID",value:t.id,mono:!0}),k&&e.jsx(Xe,{label:"Dashboard",value:k,mono:!0,action:e.jsx(Vt,{label:"Copy dashboard URL",onClick:()=>void Ct(k,"Dashboard URL copied")})}),e.jsx(Xe,{label:"Node URL",value:E,mono:!0,action:e.jsx(Vt,{label:"Copy node URL",onClick:()=>void Ct(E,"Node URL copied")})}),t.workDir&&e.jsx(Xe,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(Ps,{label:"Transport",value:_})]}),s&&c&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:()=>c(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(ms,{className:"h-3 w-3"}),"Capabilities"]}),s&&N&&f&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Vt({label:t,onClick:s}){return e.jsx(Z,{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(pa,{className:"h-3 w-3"})})}function Wd(t,s,n,r){var m,g;if(!t)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const o=((m=s==null?void 0:s.self)==null?void 0:m.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(h=>h.id===t.assignedTo):void 0;return t.assignedTo!==null&&(i?i.status==="offline":s?t.assignedNodeAvailable===!1||!s.nodes.some(h=>h.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..."}:ls.has(t.status)||t.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:ls.has(t.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}function Yd({dirPath:t,label:s,taskCount:n,collapsed:r,onToggle:o,onCreateTask:i,onOpenCapabilities:c}){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(Ue,{className:A("h-3 w-3 shrink-0 transition-transform duration-200",!r&&"rotate-90")}),e.jsx(Ut,{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})]}),c&&e.jsx("button",{type:"button",onClick:c,"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(ms,{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(xs,{className:"h-2.5 w-2.5"})})]})}const Ya="meshy-task-sidebar-tree-state";function Kn(t){return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Ts(){var t;try{return((t=globalThis.window)==null?void 0:t.localStorage)??globalThis.localStorage??null}catch{return null}}function Gn(t){if(!t)return{collapsedNodes:[],collapsedDirs:[]};try{const s=t.getItem(Ya);if(!s)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(s);return{collapsedNodes:Kn(n.collapsedNodes),collapsedDirs:Kn(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Qd(t,s){if(t)try{t.setItem(Ya,JSON.stringify(s))}catch{}}function Wn(t,s){if(!t.has(s))return t;const n=new Set(t);return n.delete(s),n}function Xd(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 Yn(t,s,n){return n?{collapsedNodes:Wn(t,n.nodeKey),collapsedDirs:Wn(s,n.dirKey)}:{collapsedNodes:t,collapsedDirs:s}}function Jd(t,s,n){const r=t.filter(m=>m.status==="completed"),o=new Set((s?r:[...r].sort((m,g)=>g.updatedAt-m.updatedAt).slice(0,Ys)).map(m=>m.id));n&&r.some(m=>m.id===n)&&o.add(n);const i=t.filter(m=>m.status!=="completed"||o.has(m.id)),c=r.length-o.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,c)}}const Xt="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",Jt="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function Qn({toolbarTasks:t,activeTaskId:s,tasksLoading:n,tasksError:r,isLeader:o,scope:i,agentFilter:c,nodeFilter:m,taskKindFilter:g,agentOptions:h,nodeOptions:y,nodeNameById:p,nodeWorkDirById:l,nodeStatusById:k,completedGroupByKey:E,devBoxNodeIds:j=new Set,devBoxStartNodeIds:_=new Set,devBoxStartingNodeIds:b=new Set,leaderNodeId:N,searchQuery:f,selectedTaskIds:w,allVisibleTasksSelected:C,someVisibleTasksSelected:S,canBatchArchive:M,onScopeChange:P,onAgentFilterChange:$,onNodeFilterChange:F,onTaskKindFilterChange:D,onToggleTaskSelected:X,onToggleAllVisibleTasks:q,onBatchArchive:O,onBatchDelete:B,onCreateTask:re,onOpenNodeSettings:se,onOpenNodeCapabilities:oe,onOpenProjectCapabilities:ne,onOpenDevBox:L,onStartDevBox:H,onLoadCompletedTasks:u,onSelectTask:U}){const[x,W]=a.useState(!1),[T,G]=a.useState(()=>w.size>0),{markScrollbarActive:v,scrollbarActive:Y}=Ha(),Q=w.size,ue=!!(o&&(T||Q>0)),ee=i!=="active"||m!=="all"||c!=="all"||g!=="all",z=f.trim().length>0,[J,de]=a.useState(()=>new Set(Gn(Ts()).collapsedNodes)),[R,ie]=a.useState(()=>new Set(Gn(Ts()).collapsedDirs)),[Ce,Ee]=a.useState(new Set),Oe=a.useMemo(()=>fo(t,p,N,l),[t,p,N,l]),Le=a.useMemo(()=>Xd(Oe,s),[Oe,s]),ze=a.useRef(null),ae=Oe.length===1,ve=Oe.length>0,_e=ae&&(ee||z),Re=!!(o&&(Oe.length>0||Q>0)),Fe=a.useCallback(V=>{de(ce=>{const Te=new Set(ce);return Te.has(V)?Te.delete(V):Te.add(V),Te})},[]),we=a.useCallback(V=>{ie(ce=>{const Te=new Set(ce);return Te.has(V)?Te.delete(V):Te.add(V),Te})},[]),rt=a.useCallback(V=>{Ee(ce=>{const Te=new Set(ce);return Te.add(V),Te})},[]);a.useEffect(()=>{Qd(Ts(),{collapsedNodes:Array.from(J),collapsedDirs:Array.from(R)})},[R,J]),a.useEffect(()=>{if(!Le||!s)return;const V=`${s}:${Le.nodeKey}:${Le.dirKey}`;ze.current!==V&&(ze.current=V,de(ce=>Yn(ce,new Set,Le).collapsedNodes),ie(ce=>Yn(new Set,ce,Le).collapsedDirs))},[s,Le]);const jt=a.useCallback(V=>{G(!0),q(V)},[q]),ot=a.useCallback(()=>{q(!1),G(!1)},[q]);a.useEffect(()=>{o||G(!1)},[o]);const Ke=ue?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(zt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:S&&!C?"indeterminate":C,onCheckedChange:V=>jt(V===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Multi select"})]}):e.jsxs(Z,{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(fi,{className:"h-3 w-3"}),"Multi select"]}),wt=Q>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:[Q," task",Q!==1?"s":""," selected"]}),!M&&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,$e=Q>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(es,{children:[e.jsx(As,{asChild:!0,children:e.jsxs(Z,{variant:"ghost",size:"sm",disabled:!M,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(Si,{}),"Archive"]})}),e.jsxs(ts,{children:[e.jsxs(ss,{children:[e.jsxs(ns,{children:["Archive ",Q," task",Q!==1?"s":"","?"]}),e.jsx(as,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(rs,{children:[e.jsx(os,{children:"Cancel"}),e.jsx(is,{onClick:O,disabled:!M,children:"Archive"})]})]})]}),e.jsxs(es,{children:[e.jsx(As,{asChild:!0,children:e.jsxs(Z,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(Ma,{}),"Delete"]})}),e.jsxs(ts,{children:[e.jsxs(ss,{children:[e.jsxs(ns,{children:["Delete ",Q," task",Q!==1?"s":"","?"]}),e.jsx(as,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(rs,{children:[e.jsx(os,{children:"Cancel"}),e.jsx(is,{onClick:B,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return 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(Z,{onClick:()=>re("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(xs,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsxs(Z,{variant:"outline",onClick:()=>re("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(Zs,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Load session"]})]}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>W(V=>!V),className:A("ml-auto h-8 w-8 shrink-0 rounded-sm text-muted-foreground shadow-none hover:bg-muted/55 hover:text-foreground",(x||ee)&&"bg-primary/8 text-primary hover:bg-primary/12 hover:text-primary"),title:"Filters",children:e.jsx(Oi,{className:"h-3.5 w-3.5"})})]}),(x||ee)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(Ne,{value:i,onValueChange:V=>P(V),children:[e.jsx(ke,{className:Xt,children:e.jsx(Me,{})}),e.jsx(Se,{children:go.map(V=>e.jsx(xe,{value:V.value,className:Jt,children:V.label},V.value))})]}),e.jsxs(Ne,{value:m,onValueChange:F,children:[e.jsx(ke,{className:Xt,children:e.jsx(Me,{placeholder:"Node"})}),e.jsx(Se,{children:y.map(V=>e.jsx(xe,{value:V.value,className:Jt,children:V.label},V.value))})]}),e.jsxs(Ne,{value:c,onValueChange:$,children:[e.jsx(ke,{className:Xt,children:e.jsx(Me,{placeholder:"Agent"})}),e.jsx(Se,{children:h.map(V=>e.jsx(xe,{value:V,className:Jt,children:V==="all"?"All agents":V},V))})]}),e.jsxs(Ne,{value:g,onValueChange:V=>D(V),children:[e.jsx(ke,{className:Xt,children:e.jsx(Me,{placeholder:"Type"})}),e.jsx(Se,{children:bo.map(V=>e.jsx(xe,{value:V.value,className:Jt,children:V.label},V.value))})]})]})]}),e.jsx("div",{className:A("scrollbar-line min-h-0 flex-1 overflow-y-auto pl-2.5 pr-1.5 py-2",Y&&"scrollbar-line-active"),onScroll:v,children:Oe.length>0?e.jsx("div",{className:"space-y-1",children:Oe.map(V=>{const ce=V.nodeId??"__unassigned__",Te=V.dirs.reduce((De,He)=>De+He.tasks.length,0),ht=ve&&!_e&&J.has(ce),pt=V.nodeId!==null&&k.get(V.nodeId)==="offline",ft=!!(o&&V.nodeId&&se);return e.jsxs("div",{className:"space-y-1",children:[ve&&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:()=>Fe(ce),"aria-expanded":!ht,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(Ue,{className:A("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!ht&&"rotate-90")}),e.jsx(ua,{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:V.nodeName}),e.jsxs(Be,{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:[Te," task",Te===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[pt&&e.jsx(Be,{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"}),V.nodeId===N&&e.jsx(Be,{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"})]})]}),ft&&V.nodeId&&se&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(nn,{nodeId:V.nodeId,nodeName:V.nodeName,onOpenSettings:se,onOpenCapabilities:oe,onOpenDevBox:L,onStartDevBox:H,showConfigureDevBox:j.has(V.nodeId),showStartDevBox:_.has(V.nodeId)||b.has(V.nodeId),startDevBoxPending:b.has(V.nodeId)})})]}),e.jsx("div",{className:A("grid transition-[grid-template-rows] duration-300 ease-in-out",ht?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:V.dirs.map(De=>{const He=`${ce}::${De.path}`,it=R.has(He),yt=ya(De.path),et=E==null?void 0:E.get(He),gt=et?{visibleTasks:De.tasks,hiddenCompletedCount:Math.max(0,et.total-et.returned)}:Jd(De.tasks,Ce.has(He),s),{visibleTasks:lt,hiddenCompletedCount:dt}=gt;return e.jsxs("div",{className:A("space-y-0.5 rounded-xl",ve&&"pl-2.5"),children:[e.jsx(Yd,{dirPath:De.path,label:yt,taskCount:De.tasks.length,collapsed:it,onToggle:()=>we(He),onCreateTask:()=>re("chat",{assignTo:V.nodeId,project:De.path==="default workspace"?"":De.path}),onOpenCapabilities:V.nodeId&&ne?()=>ne(V.nodeId,De.path==="default workspace"?(l==null?void 0:l.get(V.nodeId))??De.path:De.path):void 0}),e.jsx("div",{className:A("grid transition-[grid-template-rows] duration-300 ease-in-out",it?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:A("overflow-hidden",ve?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[lt.map(ye=>{const at=ye.id===s,Ae=ye.assignedTo?k.get(ye.assignedTo):void 0,ct=!!ye.assignedTo&&(Ae?Ae==="offline":ye.assignedNodeAvailable===!1);return e.jsxs("div",{className:A("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",at?'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:[ue&&e.jsx("div",{className:"flex shrink-0",onClick:ut=>ut.stopPropagation(),children:e.jsx(zt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:w.has(ye.id),onCheckedChange:ut=>X(ye.id,ut===!0),"aria-label":`Select ${ye.title}`})}),e.jsxs("button",{type:"button",onClick:()=>U(ye.id),"aria-current":at?"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:A("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",at?"text-foreground":"text-foreground/80"),children:ye.title})}),e.jsx("span",{className:A("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",at?"text-primary/75":"text-muted-foreground/55"),children:vo(ye.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:ye.agent}),ye.activeShare&&e.jsx(Be,{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"}),ct&&e.jsx(Be,{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(fa,{status:ye.status,isNative:ye.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},ye.id)}),dt>0&&e.jsxs("button",{type:"button",onClick:()=>{et&&u?u(et):rt(He)},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 ${dt} more completed tasks in ${yt}`,children:[e.jsx(Ze,{className:"h-3 w-3"}),"Load ",dt," more completed"]})]})})})]},He)})})})]},ce)})}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(V=>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+V*12}%`,animationDelay:`${V*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${V*120+60}ms`}})]})]})},V))}):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."})}),Re?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:ue&&Q>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[wt,e.jsx(Z,{variant:"ghost",size:"sm",onClick:ot,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:Ke}),$e]})]}):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:Ke}),ue&&e.jsx(Z,{variant:"ghost",size:"sm",onClick:ot,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]})}async function Zd(t,s){var n,r;try{const o=await jo(t,s),i={...o,url:ha(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 ec(t){try{return await wo(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 c=>{if(!t)return;const m=await Zd(t.id,c);return m&&r(),m},[t,r]),i=a.useCallback(async()=>{if(!t)return!1;const c=await ec(t.id);return c&&r(),c},[t,r]);return{handleShareTask:o,handleStopShareTask:i}}function Xn(t,s,n){const r=a.useRef(s);r.current=s,a.useEffect(()=>{let c=0,m=0;const g=p=>{const l=p.touches[0];l&&(c=l.clientX,m=l.clientY)},h=p=>{var j,_,b,N;const l=p.changedTouches[0];if(!l)return;const k=l.clientX-c;Math.abs(l.clientY-m)>100||Math.abs(k)<50||(k>0?(_=(j=r.current).onSwipeRight)==null||_.call(j):(N=(b=r.current).onSwipeLeft)==null||N.call(b))},y=(t==null?void 0:t.current)??document;return y.addEventListener("touchstart",g,{passive:!0}),y.addEventListener("touchend",h,{passive:!0}),()=>{y.removeEventListener("touchstart",g),y.removeEventListener("touchend",h)}},[t,n==null?void 0:n.threshold,n==null?void 0:n.maxVertical])}const sc="(min-width: 1024px)",nc="(min-width: 1800px)";function Jn(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 rc(){const[t,s]=a.useState(()=>yo(yn(),No({operationsOpen:Jn(nc)}))),[n,r]=a.useState(!1),o=a.useRef(null),i=a.useRef(null),c=a.useRef(null),m=t.layout.desktopTasksOpen,g=t.layout.operationsOpen,h=t.sizes;a.useEffect(()=>{ko(yn(),t)},[t]);const y=a.useCallback((_,b)=>{s(N=>{const f=N.layout[_],w=typeof b=="function"?b(f):b;return w===f?N:{...N,layout:{...N.layout,[_]:w}}})},[]),p=a.useCallback(_=>{y("desktopTasksOpen",_)},[y]),l=a.useCallback(_=>{y("operationsOpen",_)},[y]);Xn(i,{onSwipeLeft:()=>r(!1)}),Xn(c,{onSwipeRight:()=>l(!1)});const k=a.useCallback(()=>{if(Jn(sc)){p(_=>!_);return}r(_=>!_)},[p]);a.useEffect(()=>{var N,f,w;const _=C=>{const S=o.current;if(!S)return;C.preventDefault();const M=Co(S.panel,S.startSize,S.startClientX,S.startClientY,C.clientX,C.clientY,S.rootFontSize);s(P=>({...P,sizes:{...P.sizes,[S.panel]:M}}))},b=()=>{o.current=null};return(N=globalThis.window)==null||N.addEventListener("pointermove",_),(f=globalThis.window)==null||f.addEventListener("pointerup",b),(w=globalThis.window)==null||w.addEventListener("pointercancel",b),()=>{var C,S,M;(C=globalThis.window)==null||C.removeEventListener("pointermove",_),(S=globalThis.window)==null||S.removeEventListener("pointerup",b),(M=globalThis.window)==null||M.removeEventListener("pointercancel",b)}},[]);const E=a.useCallback((_,b)=>{var N,f;b.preventDefault(),(f=(N=b.currentTarget).setPointerCapture)==null||f.call(N,b.pointerId),o.current={panel:_,startSize:h[_],startClientX:b.clientX,startClientY:b.clientY,rootFontSize:ac()}},[h]),j=a.useCallback((_,b)=>{b.preventDefault(),s(N=>({...N,sizes:{...N.sizes,[_]:So(_,N.sizes[_],b.deltaY)}}))},[]);return{desktopTasksOpen:m,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:g,operationsPanelRef:c,panelResize:{sizes:{tasks:Ns(h.tasks),operations:Ns(h.operations),terminal:Ns(h.terminal)},onPointerDown:E,onWheel:j},setMobileTasksPanelOpen:r,setOperationsOpen:l,toggleTasksPanel:k}}function oc(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)}function ic({isLeader:t,selfId:s}){return{...!t&&s?{assignedTo:s}:{},completedLimitPerProject:Ys}}function Hs(t){return`${t.assignedTo??"__unassigned__"}::${t.projectPath}`}function lc(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 dc(t,s,n=new Set){return!s||n.has(s.id)||t.some(r=>r.id===s.id)?t:Ia(t,s)}function cc({isLeader:t,selfId:s,sseConnected:n,preservedTask:r,subscribe:o}){const[i,c]=a.useState([]),[m,g]=a.useState([]),[h,y]=a.useState(!0),[p,l]=a.useState(null),k=a.useRef(new Set),E=a.useRef(null),j=a.useCallback(async()=>{try{const f=await Nn(ic({isLeader:t,selfId:s}));c(dc(f.tasks,r,k.current)),g(f.completedGroups??[]),l(null)}catch(f){l(f instanceof Error?f.message:"Failed to load tasks")}finally{y(!1)}},[t,r,s]),_=a.useCallback(async f=>{if(!f.hasMore||!f.nextCursor)return;const w=await Nn({status:"completed",assignedTo:f.assignedTo??"__unassigned__",projectPath:f.projectPath,cursor:f.nextCursor,limit:Ys});c(C=>lc(C,w.tasks)),g(C=>C.map(S=>Hs(S)===Hs(f)?{...S,returned:Math.min(S.total,S.returned+w.tasks.length),hasMore:w.hasMore===!0,nextCursor:w.nextCursor??null}:S))},[]),b=a.useCallback(()=>{E.current===null&&(E.current=window.setTimeout(()=>{E.current=null,j()},_o))},[j]),N=a.useCallback(f=>{const w=new Set(f);if(w.size!==0){for(const C of w)k.current.add(C);c(C=>C.filter(S=>!w.has(S.id)))}},[]);return To(j,Ao(n)),a.useEffect(()=>()=>{E.current!==null&&(window.clearTimeout(E.current),E.current=null)},[]),a.useEffect(()=>{const f=[o("task.updated",w=>{c(C=>oc(C,w.data))}),o("task.status",w=>{c(C=>Eo(C,w.data))}),o("node",w=>{kn(w.type)&&b()}),o("task",w=>{if(w.type==="task.deleted"){const C=w.data.taskId;typeof C=="string"&&k.current.add(C),c(S=>Do(S,w.data))}kn(w.type)&&b()})];return()=>f.forEach(w=>w())},[o,b]),{completedGroups:m,fetchTasks:j,loadCompletedTasksPage:_,removeTasksFromList:N,setTasks:c,tasks:i,tasksError:p,tasksLoading:h}}function Qa(t){return t.map(s=>({...s}))}function uc(t,s){const n=s.get(t);return{logs:n?Qa(n.logs):[],transcriptLoading:(n==null?void 0:n.loaded)!==!0}}function mc(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function xc({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=mc(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 hc=[0,300,1e3,2e3];function pc({task:t,getActiveTaskId:s,setLogs:n,setPendingMessages:r,setTranscriptLoading:o}){t.conversationKind==="nativeSession"&&(async()=>{try{for(const i of hc){if(i>0&&await new Promise(c=>setTimeout(c,i)),s()!==t.id)return;try{const c=await Ms(t.id);if(s()!==t.id||(n(m=>Ta(m,c.logs)),r(m=>Ls(m,c.logs)),c.total>0))return}catch{}}}finally{s()===t.id&&(o==null||o(!1))}})()}function fc(t,s){return Pe(t??{})===Pe(s??{})}function gc(t){return t&&"status"in t&&typeof t.status=="string"?t.status:void 0}function Zn(t,s){return{...t,enabled:!0,alwaysOnline:s}}function Xa(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 bc({operationStarting:t,loading:s,refreshing:n,savedStatus:r,fallbackStatus:o}){return t?"Starting":s?"Listing DevBoxes":n?"Refreshing":r??o}function ea({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-full border border-border/70 bg-background/70 px-1.5 py-0.5 text-[10px] leading-none text-muted-foreground",children:Xa(t)})]})}function vc({node:t,open:s,startInProgress:n=!1,onOpenChange:r,onRefresh:o}){const i=(t==null?void 0:t.id)??null,c=s&&!n&&Un(t==null?void 0:t.status,(t==null?void 0:t.devbox)??null),[m,g]=a.useState([]),[h,y]=a.useState(()=>t!=null&&t.devbox?Pe(t.devbox):""),[p,l]=a.useState(()=>(t==null?void 0:t.devbox)??null),[k,E]=a.useState(()=>Hn((t==null?void 0:t.devbox)??null)),[j,_]=a.useState(!1),[b,N]=a.useState(c),[f,w]=a.useState(!1),[C,S]=a.useState(!1),[M,P]=a.useState(()=>{var v;return((v=t==null?void 0:t.devbox)==null?void 0:v.alwaysOnline)===!0}),$=a.useMemo(()=>{const v=m.find(Y=>Pe(Y)===h);return v||(Et(p)&&Pe(p)===h?p:void 0)},[p,m,h]),F=gc($??void 0),D=k?F??(p==null?void 0:p.lastStatus):(p==null?void 0:p.lastStatus)??F,X=(t==null?void 0:t.status)==="online"||(t==null?void 0:t.status)==="busy"?"Running":"Unknown",q=C||n,O=bc({operationStarting:q,loading:j,refreshing:b,savedStatus:D,fallbackStatus:X}),B=k&&!!$&&!fc(p,$),re=(p==null?void 0:p.alwaysOnline)===!0!==M,se=Hd({nodeStatus:t==null?void 0:t.status,status:O,current:p,selected:$}),oe=!!se,ne=!!$&&(B||re)&&!oe,L=$??p,H=a.useCallback(async()=>{if(i){N(!0);try{const v=await Mo(i);l(v.devbox),y(Pe(v.devbox))}catch(v){le.error(v instanceof Error?v.message:"Failed to refresh DevBox status")}finally{N(!1)}}},[i]),u=a.useCallback(async v=>{_(!0);try{const Y=await Po();g(Y),y(Q=>qd({previousKey:Q,baseDevBox:v,listed:Y}))}catch(Y){le.error(Y instanceof Error?Y.message:"Failed to load DevBoxes")}finally{_(!1)}},[]);a.useEffect(()=>{if(!s||!i)return;let v=!1;const Y=(t==null?void 0:t.devbox)??null,Q=Hn(Y),ue=!n&&Un(t==null?void 0:t.status,Y);_(!1),N(ue),E(Q),l(Y),P((Y==null?void 0:Y.alwaysOnline)===!0),y(Et(Y)?Pe(Y):""),g([]);async function ee(){ue&&await H(),!v&&Q&&await u(Y)}return ee(),()=>{v=!0}},[u,t==null?void 0:t.devbox,t==null?void 0:t.status,i,s,H,n]);async function U(){E(!0),m.length===0&&await u(p)}async function x(){if(!(!t||!$)){w(!0);try{const v=await Sn(t.id,Zn($,M));l(v.node.devbox??null),v.node.devbox&&y(Pe(v.node.devbox)),E(!1),le.success(`Configured DevBox for ${t.name}`),await(o==null?void 0:o())}catch(v){le.error(v instanceof Error?v.message:"Failed to configure DevBox")}finally{w(!1)}}}async function W(){if(!(!t||!se)){S(!0);try{if($&&(B||re)){const Y=await Sn(t.id,Zn($,M));l(Y.node.devbox??null),Y.node.devbox&&y(Pe(Y.node.devbox)),E(!1)}const{operation:v}=await ka(t.id);l(Y=>Y&&{...Y,lastStatus:"Starting",checkedAt:Date.now(),operationId:v.id}),le.success(`Start requested for ${t.name}`),await(o==null?void 0:o())}catch(v){le.error(v instanceof Error?v.message:"Failed to start DevBox")}finally{S(!1)}}}const T=j?"Loading DevBoxes...":m.length===0?"No DevBoxes available":"Select a DevBox",G=O==="Running"&&(t==null?void 0:t.status)==="offline";return e.jsx(Ht,{open:s,onOpenChange:r,children:e.jsxs(qt,{className:"max-w-md gap-4 rounded-lg p-5",children:[e.jsxs(Ws,{className:"space-y-1",children:[e.jsx(us,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(Na,{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:[(k||L)&&e.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 rounded-xl border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:k?e.jsxs(Ne,{value:h,onValueChange:y,disabled:j||f||C||m.length===0,children:[e.jsx(ke,{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:j&&!$?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}),T]}):$?e.jsx(ea,{devbox:$}):e.jsx(Me,{placeholder:T})}),e.jsx(Se,{children:m.map(v=>e.jsx(xe,{value:Pe(v),textValue:`${v.name} ${v.projectName??""} ${Xa(v)}`,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(ea,{devbox:v,showStatus:!0})},Pe(v)))})]}):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(Be,{variant:"outline",className:"rounded-full px-2 py-0.5 text-[10px]",children:[(j||b)&&e.jsx(he,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),O]}),(p==null?void 0:p.name)&&e.jsx(Z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{U()},disabled:j||f||q||k,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-full text-muted-foreground hover:text-foreground",children:j&&k?e.jsx(he,{className:"h-3 w-3 animate-spin"}):e.jsx(At,{className:"h-3 w-3"})})]})]}),G&&e.jsx("div",{className:"rounded-xl 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-xl border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(zt,{checked:M,onCheckedChange:v=>P(v===!0),disabled:f||C||q,"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(ga,{className:"gap-2 sm:space-x-0",children:[e.jsx(Z,{variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:f||C,className:"h-8 rounded-xl text-xs",children:"Close"}),oe&&e.jsxs(Z,{size:"sm",onClick:W,disabled:C,className:"h-8 rounded-xl text-xs",children:[C?e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Xs,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!oe&&e.jsxs(Z,{size:"sm",onClick:x,disabled:!ne||f,className:"h-8 rounded-xl text-xs",children:[f&&e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function jc(t,s=Lo){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 wc({cluster:t,refresh:s}){const[n,r]=a.useState(null),[o,i]=a.useState(null),[c,m]=a.useState(()=>new Set),[g,h]=a.useState(()=>new Set),y=a.useMemo(()=>(t==null?void 0:t.nodes.find(b=>b.id===n))??null,[t==null?void 0:t.nodes,n]),p=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(b=>{var N;return(N=b.devbox)==null?void 0:N.enabled}).map(b=>b.id)),[t==null?void 0:t.nodes]),l=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(b=>{var N;return hs(b.status,(N=b.devbox)==null?void 0:N.lastStatus,b.devbox)}).map(b=>b.id)),[t==null?void 0:t.nodes]),k=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(b=>{var N;return Dt((N=b.devbox)==null?void 0:N.lastStatus)}).map(b=>b.id)),[t==null?void 0:t.nodes]),E=a.useMemo(()=>{const b=new Set(c);o&&b.add(o);for(const N of g)b.add(N);for(const N of k)b.add(N);return b},[g,o,c,k]);a.useEffect(()=>{let b=!1;const N=[...p];async function f(){try{const w=await jc(N);b||h(w)}catch{b||h(new Set)}}return f(),()=>{b=!0}},[p]),a.useEffect(()=>{m(b=>{var w;let N=!1;const f=new Set(b);for(const C of b){const S=t==null?void 0:t.nodes.find(M=>M.id===C);(S==null?void 0:S.status)!=="online"&&(!((w=S==null?void 0:S.devbox)!=null&&w.lastStatus)||Dt(S.devbox.lastStatus))||(f.delete(C),N=!0)}return N?f:b})},[t==null?void 0:t.nodes]);const j=a.useCallback(async b=>{const N=t==null?void 0:t.nodes.find(f=>f.id===b);if(N){i(b),m(f=>new Set(f).add(b));try{await ka(b),le.success(`Start requested for ${N.name}`),s()}catch(f){m(w=>{const C=new Set(w);return C.delete(b),C}),le.error(f instanceof Error?f.message:"Failed to start DevBox")}finally{i(null)}}},[t==null?void 0:t.nodes,s]);return{devBoxDialog:e.jsx(vc,{node:y,open:n!==null,startInProgress:y?E.has(y.id):!1,onOpenChange:b=>{b||r(null)},onRefresh:s}),devBoxNodeIds:p,devBoxStartNodeId:o,devBoxStartNodeIds:l,devBoxStartingNodeIds:E,openDevBox:r,startDevBox:j}}function yc(t){const[s,n]=a.useState(null),r=a.useCallback(i=>{t&&n(i)},[t]);return{nodeSettingsDialog:e.jsx(Io,{open:s!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:s??void 0,showTrigger:!1}),openNodeSettings:r}}function Nc({activeTaskId:t,fetchActiveTask:s,setPendingMessages:n,setTask:r,setTasks:o}){const i=a.useCallback((g,h)=>{r(y=>y&&y.id===g?{...y,queuedMessages:h}:y),o(y=>y.map(p=>p.id===g?{...p,queuedMessages:h}:p))},[r,o]),c=a.useCallback(async g=>{if(!t)return!1;const h=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`;n(y=>[...y,{id:h,content:g,timestamp:new Date().toISOString()}]);try{const y=await Bo(t,g);return y.queued&&(n(p=>p.filter(l=>l.id!==h)),y.queuedMessages&&i(t,y.queuedMessages)),s(),!0}catch(y){return n(p=>p.filter(l=>l.id!==h)),le.error(y instanceof Error?y.message:"Failed to send message"),!1}},[t,s,n,i]);return{cancelQueuedMessage:a.useCallback(async g=>{if(t)try{const h=await Ro(t,g);i(t,h.queuedMessages),s()}catch(h){le.error(h instanceof Error?h.message:"Failed to cancel queued message")}},[t,s,i]),queueFollowUpMessage:c}}const ta="grid-cols-[1.5rem_5.25rem_4rem_minmax(8rem,1fr)_4rem_4rem_6rem]",kc={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Sc(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 Ja(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 Cc({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:A("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",ta),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:A("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",ta,n===i.id&&"bg-primary/10 text-primary shadow-[inset_2px_0_0_hsl(var(--primary))]"),children:[e.jsx("span",{onClick:c=>c.stopPropagation(),children:e.jsx(zt,{className:"h-3 w-3",checked:s.has(i.id),onCheckedChange:c=>r(i.id,c===!0),"aria-label":`Select ${i.name}`})}),e.jsx(_c,{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:Ja(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 _c({agent:t}){const s=kc[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 sa=320,na=560,Za=384,aa=360;function Tc(t,s=na+aa){const n=Math.max(sa,Math.min(na,s-aa));return Math.min(Math.max(Math.round(t),sa),n)}function Ec(t,s,n,r){return Tc(t+s-n,r)}function Dc({detail:t,deleting:s=!1,onDelete:n,desktopWidth:r=Za,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 c=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(Be,{variant:"secondary",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary",children:t.agent}),e.jsx(Be,{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(es,{children:[e.jsx(As,{asChild:!0,children:e.jsx(Z,{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(Ma,{className:"h-3.5 w-3.5"})})}),e.jsxs(ts,{className:"max-w-[22rem] gap-2 rounded-xl p-4",children:[e.jsxs(ss,{className:"space-y-1",children:[e.jsxs(ns,{className:"text-sm",children:["Delete ",t.name,"?"]}),e.jsxs(as,{className:"text-[11px] leading-4",children:["This removes the selected ",t.kind," from ",t.scope.kind==="global"?"the user profile":"this project","."]})]}),e.jsxs(rs,{className:"gap-1 pt-0 sm:space-x-1",children:[e.jsx(os,{className:"h-7 rounded-lg px-2 text-[11px]",children:"Cancel"}),e.jsx(is,{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(Zt,{label:"Version",value:t.version??"-"}),e.jsx(Zt,{label:"Size",value:Ja(t)}),e.jsx(Zt,{label:"Files",value:String(t.fileCount)}),e.jsx(Zt,{label:"Source",value:t.source??"local"})]}),e.jsxs(qs,{defaultValue:c,className:"mt-2 flex min-h-0 flex-1 flex-col",children:[e.jsxs(Ks,{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(st,{value:"mcp",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(Ac,{detail:t})}):e.jsx(st,{value:"files",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(Mc,{detail:t})}),e.jsx(st,{value:"readme",className:"mt-2 min-h-0 flex-1 overflow-auto",children:t.readmeMarkdown?e.jsx(Ni,{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(an,{children:"No README content."})})]},t.id)]})}function Ac({detail:t}){const s=t.mcpPreview??[];return s.length===0?e.jsx(an,{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 Mc({detail:t}){const s=t.fileTree??[];return s.length===0?e.jsx(an,{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 an({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 Zt({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 Pc=20,Lc=288,Ic=360,Bc=440;function Rc(){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 $c({triggerRect:t,targetRect:s,viewportRect:n,compact:r,browserOpen:o=!1,portalAlign:i,cssZoom:c=1}){const m=Number.isFinite(c)&&c>0?c:1,g=8,h=n.top+g,y=n.bottom-g,p=n.left+g,l=n.right-g,k=Math.max(0,y-t.bottom-4),E=Math.max(0,t.top-h-4),j=r?E<140&&k>E:k>=220||k>=E,_=j?k:E,b=Math.max(140,y-h),N=r&&o,C=Math.min(b,N?Bc:320,Math.max(N?Ic:140,_)),S=Lc*m,M=i==="end"?t.right-S:t.left,$=(Math.max(p,Math.min(M,l-S))-s.left)/m;if(!j&&!N)return{left:$,bottom:(s.bottom-(t.top-4))/m,maxHeight:C/m};const F=j?t.bottom+4:t.top-C-4,D=Math.max(h,Math.min(F,y-C));return{left:$,top:(D-s.top)/m,maxHeight:C/m}}function rn(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(tr(o)?o:sr(t.workDir,o));return s}function Oc(t,s){if(t.kind==="global")return{nodeId:s.id,scope:{kind:"global"}};const n=rn(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 zc(t,s){return{nodeId:t,scope:s}}function ra(t,s,n){const r=s.trim();return!r||r==="."?t.workDir??r:n||tr(r)?r:t.workDir?sr(t.workDir,r):r}function Fc({node:t,scope:s,clusterNodes:n,onSelectionChange:r}){const o=a.useMemo(()=>qc(n,t),[n,t]),i=a.useMemo(()=>rn(t),[t]),c=a.useMemo(()=>o.map(m=>({value:m.id,label:m.name,description:`${m.role} · ${m.status}`,status:m.status})),[o]);return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-2",children:[e.jsx(Hc,{ariaLabel:"Capability node",value:t.name,description:`${t.role} · ${t.status}`,options:c,selectedValue:t.id,onSelect:m=>{const g=o.find(h=>h.id===m);g&&(r==null||r(Oc(s,g)))}}),e.jsx(er,{node:t,projectPaths:i,selectedScope:s,onSelect:m=>r==null?void 0:r(zc(t.id,m))}),e.jsx(Vc,{node:t})]})}function Vc({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:A("h-1.5 w-1.5 shrink-0 rounded-full",Rt(t.status))})]})}function er({node:t,projectPaths:s,selectedScope:n,onSelect:r,compact:o=!1,portal:i=!1,portalAlign:c="start"}){const[m,g]=a.useState(!1),[h,y]=a.useState(null),[p,l]=a.useState(!1),[k,E]=a.useState(!1),[j,_]=a.useState(null),[b,N]=a.useState(!1),[f,w]=a.useState(null),C=a.useRef(null),S=a.useRef(null),M=a.useRef(null),P=a.useMemo(()=>s.map(L=>({value:L,label:ia(L),description:L})),[s]),$=n.kind==="project"?n.projectPath:void 0,F=n.kind==="global"?"Global":ia(n.projectPath),D=n.kind==="global"?"Global":n.projectPath,X=a.useCallback(()=>{var L;return!i||typeof document>"u"?null:((L=S.current)==null?void 0:L.closest('[data-capability-share-dialog="true"]'))??document.body},[i]),q=a.useCallback(()=>{if(!i||!S.current||typeof window>"u")return;const L=S.current.getBoundingClientRect(),H=X(),u=H&&H!==document.body?H.getBoundingClientRect():{left:0,top:0,bottom:window.innerHeight};w($c({triggerRect:L,targetRect:u,viewportRect:{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},compact:o,browserOpen:b,portalAlign:c,cssZoom:Rc()}))},[b,o,X,i,c]);a.useEffect(()=>{m||N(!1)},[m]),a.useEffect(()=>{if(!m)return;const L=H=>{if(!(H.target instanceof Node))return;const u=H.composedPath(),U=C.current?u.includes(C.current):!1,x=M.current?u.includes(M.current):H.target instanceof Element&&!!H.target.closest('[data-capability-scope-menu="true"]');!U&&!x&&g(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[m]),a.useEffect(()=>{if(!(!m||!i))return q(),window.addEventListener("resize",q),window.addEventListener("scroll",q,!0),()=>{window.removeEventListener("resize",q),window.removeEventListener("scroll",q,!0)}},[m,i,q]);const O=async(L,H=0,u=!1)=>{if(t.workDir){_(null),u?E(!0):l(!0);try{const U=await ma(t.id,{path:L||".",limit:Pc,offset:H,directoriesOnly:!0,allowAbsolute:!0});y(x=>u&&x?{...U,entries:[...x.entries,...U.entries]}:U)}catch(U){_(U instanceof Error?U.message:"Failed to browse folders"),u||y(null)}finally{l(!1),E(!1)}}};a.useEffect(()=>{!m||!b||!t.workDir||(y(null),_(null),O($||"."))},[b,m,t.id,t.workDir,$]);const B=(L,H=!1)=>{r({kind:"project",projectPath:ra(t,L,H)}),g(!1)},re=()=>{r({kind:"global"}),g(!1)},se=h?ra(t,h.currentPath,h.isAbsolute):$??t.workDir??"",oe=i?X():null,ne=e.jsxs("div",{ref:M,"data-capability-scope-menu":"true","aria-hidden":!m,onClick:L=>L.stopPropagation(),onMouseDown:L=>L.stopPropagation(),onPointerDown:L=>L.stopPropagation(),style:i&&f?{left:f.left,top:f.top,bottom:f.bottom,height:o&&b?f.maxHeight:void 0,maxHeight:f.maxHeight}:void 0,className:A(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"),!m&&"hidden"),children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 p-1",children:[e.jsx("div",{className:A("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:A("overflow-y-auto pr-0.5",o?"max-h-32":"max-h-40"),children:[e.jsx(oa,{icon:"global",label:"Global",selected:n.kind==="global",onSelect:re,compact:o}),P.length>0?P.map(L=>e.jsx(oa,{icon:"folder",label:L.label,description:L.description,selected:$===L.value,onSelect:()=>B(L.value,!0),compact:o},L.value)):e.jsx("div",{className:A("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:A("border-b border-border/55",b?"flex min-h-0 flex-1 flex-col":"shrink-0"),children:[e.jsxs("button",{type:"button","aria-expanded":b,onClick:()=>N(L=>!L),className:A("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(Ut,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Browse folders"}),e.jsx(Ze,{className:A("h-3 w-3 shrink-0 transition-transform duration-200",b&&"rotate-180")})]}),b&&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:()=>(h==null?void 0:h.parentPath)&&void O(h.parentPath),disabled:!(h!=null&&h.parentPath)||p,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(Ea,{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:se,children:se}),h&&e.jsx("button",{type:"button",onClick:()=>B(h.currentPath,h.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:A("min-h-0 flex-1 overflow-y-auto",o?"min-h-[8.25rem]":"max-h-56"),children:[t.workDir?p?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[9px] text-muted-foreground",children:[e.jsx(he,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading folders..."]}):h&&h.entries.length>0?e.jsxs(e.Fragment,{children:[h.entries.map(L=>e.jsx(Uc,{entry:L,onSelect:()=>B(L.path,h.isAbsolute),onOpen:()=>void O(L.path)},L.path)),h.hasMore&&e.jsxs("button",{type:"button",onClick:()=>void O(h.currentPath,h.entries.length,!0),disabled:k,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:[k?e.jsx(he,{className:"h-3 w-3 animate-spin"}):e.jsx(Li,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:j??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:"This node has no working directory."}),j&&h&&h.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[9px] text-destructive",children:j})]})]})]})]});return e.jsxs("div",{ref:C,className:"relative min-w-0",children:[e.jsxs("button",{ref:S,type:"button","aria-label":"Capability location","aria-expanded":m,title:D,onClick:()=>g(L=>(L||(N(!1),q()),!L)),className:A("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:A("block truncate font-medium text-foreground",o?"text-[9px] leading-3":"text-[10px] leading-4"),children:F})}),e.jsx(Ze,{className:A(o?"h-2.5 w-2.5":"h-3 w-3","shrink-0 text-muted-foreground transition-transform",m&&"rotate-180")})]}),i&&oe?ba.createPortal(ne,oe):ne]})}function oa({icon:t,label:s,description:n,selected:r,onSelect:o,compact:i=!1}){const c=t==="global"?Di:Ut;return e.jsxs("button",{type:"button",onClick:o,className:A(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(c,{className:A("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:A("block truncate text-muted-foreground",i?"text-[7px] leading-3":"text-[8px] leading-3"),children:n})]})]})}function Uc({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(Ut,{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(Ue,{className:"h-3 w-3"})})]})}function Hc({ariaLabel:t,value:s,description:n,options:r,selectedValue:o,onSelect:i}){const[c,m]=a.useState(!1),g=a.useRef(null);return a.useEffect(()=>{if(!c)return;const h=y=>{g.current&&y.target instanceof Node&&!g.current.contains(y.target)&&m(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[c]),e.jsxs("div",{ref:g,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":t,"aria-expanded":c,title:n??s,onClick:()=>m(h=>!h),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(Ze,{className:A("h-3 w-3 shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!c,className:A("absolute left-0 top-9 z-50 w-64 overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!c&&"hidden"),children:e.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:r.length>0?r.map(h=>e.jsxs("button",{type:"button",onClick:()=>{i(h.value),m(!1)},className:A("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",h.value===o&&"bg-primary/10 text-primary"),children:[h.status&&e.jsx("span",{className:A("h-1.5 w-1.5 shrink-0 rounded-full",Rt(h.status))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:h.label}),h.description&&e.jsx("span",{className:"block truncate text-[9px] text-muted-foreground",children:h.description})]})]},h.value)):e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No projects"})})})]})}function qc(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 Rt(t){return t==="online"?"bg-emerald-500":t==="offline"?"bg-muted-foreground/45":"bg-amber-500"}function ia(t){return t.split(/[\\/]+/).filter(Boolean).at(-1)??t}function tr(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)}function sr(t,s){return`${t.replace(/[\\/]+$/,"")}/${s.replace(/^[\\/]+/,"")}`}const Kc="h-6 w-24 rounded-sm px-2 text-[10px] shadow-none",Es="text-[10px]",nr=["claudecode","codex","copilot"],Bt={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Gc({open:t,sourceNode:s,targetNodes:n,selectedCapabilities:r,previewResults:o=[],embedded:i=!1,onClose:c,onPreviewTargetsChange:m,onShare:g}){const[h,y]=a.useState(()=>new Set(o.length>0?o.map(u=>Qe(u.nodeId,u.targetAgent)):Yc(s.id,n,r))),[p,l]=a.useState(()=>Object.fromEntries(Qc(s.id,n,r))),[k,E]=a.useState({}),[j,_]=a.useState(!1),[b,N]=a.useState(()=>new Set),[f,w]=a.useState(()=>new Set),C=r.some(u=>u.kind==="plugin"),S=a.useMemo(()=>on(r).map(u=>({key:Qe(s.id,u),nodeId:s.id,node:s,label:`Install into ${Bt[u]}`,agentLabel:Bt[u],defaultScope:rr(r),disabled:!1,targetAgent:u})),[r,s]),M=a.useMemo(()=>n.flatMap(u=>{const U={kind:"global"},x=u.status==="offline",W=ar(r);return W.length===0?[{key:Qe(u.id),nodeId:u.id,node:u,label:u.name,defaultScope:U,disabled:x}]:W.map(T=>({key:Qe(u.id,T),nodeId:u.id,node:u,label:`${u.name} / ${Bt[T]}`,agentLabel:Bt[T],defaultScope:U,disabled:x,targetAgent:T}))}),[r,n]),P=a.useMemo(()=>[...S,...M],[S,M]),$=a.useMemo(()=>n.map(u=>({node:u,options:M.filter(U=>U.nodeId===u.id)})).filter(u=>u.options.length>0),[n,M]),F=a.useMemo(()=>new Map(o.filter(u=>u.capabilityId).map(u=>[la(u.nodeId,u.capabilityId,u.targetAgent),u])),[o]),D=a.useMemo(()=>new Map(o.map(u=>[Qe(u.nodeId,u.targetAgent),u])),[o]),X=a.useMemo(()=>P.filter(u=>h.has(u.key)),[h,P]),q=a.useMemo(()=>X.map(u=>({nodeId:u.nodeId,scope:p[u.key]??u.defaultScope,...u.targetAgent?{targetAgent:u.targetAgent}:{}})),[X,p]),O=a.useMemo(()=>{const u=[],U=new Map;for(const x of X){if(!U.has(x.nodeId)){const W=x.nodeId===s.id?s:n.find(T=>T.id===x.nodeId);U.set(x.nodeId,{nodeId:x.nodeId,node:W,name:(W==null?void 0:W.name)??x.nodeId,options:[]}),u.push(x.nodeId)}U.get(x.nodeId).options.push(x)}return u.map(x=>U.get(x))},[X,s,n]),B=a.useMemo(()=>{const u=Array.from(new Set(r.map(x=>x.agent))),[U]=u;if(U)return u.length===1?Bt[U]:`${u.length} agents`},[r]),re=$.length+1;a.useEffect(()=>{let u=!1;const U={...p};for(const x of P)U[x.key]||(U[x.key]=x.defaultScope,u=!0);u&&l(U)},[P,p]),a.useEffect(()=>{t&&(m==null||m(q))},[t,m,q]),a.useEffect(()=>{t&&(N(new Set),w(new Set))},[t,s.id]),a.useEffect(()=>{if(!i||!t)return;const u=U=>{U.key==="Escape"&&c()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i,c,t]);const se=u=>{E(Object.fromEntries(X.map(U=>[U.key,u])))},oe=async()=>{_(!0);try{await g(X.map(u=>({nodeId:u.nodeId,scope:p[u.key]??u.defaultScope,...u.targetAgent?{targetAgent:u.targetAgent}:{},conflictStrategy:k[u.key]??"overwrite"})))}finally{_(!1)}},ne=u=>{const U=p[u.key]??u.defaultScope,x=`capability-share-target-${Wc(u.key)}`,W=h.has(u.key);return e.jsxs("div",{"data-target-agent":u.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":u.disabled?"true":void 0,children:[e.jsx(zt,{id:x,disabled:u.disabled,checked:W,onCheckedChange:T=>y(G=>{const v=new Set(G);return T===!0?v.add(u.key):v.delete(u.key),v}),"aria-label":`Select ${u.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":u.disabled?"true":void 0,children:u.agentLabel??u.label}),e.jsx("div",{className:"flex w-28 shrink-0 justify-end",children:W&&!u.disabled&&e.jsx(er,{node:u.node,projectPaths:rn(u.node),selectedScope:U,onSelect:T=>l(G=>({...G,[u.key]:T})),compact:!0,portal:!0,portalAlign:"end"})})]},u.key)},L=(u,U,x,W)=>{const T=b.has(u.id),G=X.filter(v=>v.nodeId===u.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":T,onClick:()=>N(v=>da(v,u.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(Ue,{className:A("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",T&&"rotate-90")}),e.jsx("span",{className:A("h-1.5 w-1.5 shrink-0 rounded-full",Rt(u.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold text-foreground",title:u.name,children:u.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:U?"this node":"remote"}),u.status==="offline"&&e.jsx(Be,{variant:"outline",className:"rounded-sm px-1 py-0 text-[8px]",children:"offline"}),W>0&&e.jsxs("span",{className:"sr-only",children:[W," agents"]})]}),e.jsx("div",{className:A("grid transition-[grid-template-rows] duration-200 ease-out",T?"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})})})]},u.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(ds,{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:A("h-1.5 w-1.5 shrink-0 rounded-full",Rt(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(An,{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:X.length})," selected · ",re," ",re===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,C?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"Cross-agent plugin installs are not supported."}):S.length===0?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No alternate agents available for this selection."}):S.map(ne),S.length),$.map(u=>L(u.node,!1,u.options.map(ne),u.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(u=>e.jsx("button",{type:"button",onClick:()=>se(u),className:"h-5 rounded-[3px] px-1.5 text-[9px] capitalize text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground",children:u},u))})]})]}),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:X.length===0?e.jsx("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"Select a target to preview conflicts."}):O.map(u=>{const U=!f.has(u.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":U,onClick:()=>w(x=>da(x,u.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(Ue,{className:A("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",U&&"rotate-90")}),u.node&&e.jsx("span",{className:A("h-1.5 w-1.5 shrink-0 rounded-full",Rt(u.node.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-semibold text-foreground",children:u.name}),e.jsxs("span",{className:"shrink-0 text-[8px] text-muted-foreground",children:[u.options.length," ",u.options.length===1?"agent":"agents"]})]}),e.jsx("div",{className:A("grid transition-[grid-template-rows] duration-200 ease-out",U?"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:u.options.map(x=>{const W=k[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(Ne,{value:W,onValueChange:T=>E(G=>({...G,[x.key]:T})),children:[e.jsx(ke,{className:Kc,children:e.jsx(Me,{})}),e.jsxs(Se,{className:"shadow-none",children:[e.jsx(xe,{value:"overwrite",className:Es,children:"Overwrite"}),e.jsx(xe,{value:"skip",className:Es,children:"Skip"}),e.jsx(xe,{value:"abort",className:Es,children:"Abort"})]})]})]}),e.jsx("div",{className:"space-y-px",children:r.map(T=>{const G=F.get(la(x.nodeId,T.id,x.targetAgent))??(r.length===1?D.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:T.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(An,{className:"inline h-2.5 w-2.5"})," v",G.sourceVersion]})]},T.id)})})]},x.key)})})})})]},u.nodeId)})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-border/55 px-4 py-3",children:[e.jsx(Z,{variant:"ghost",onClick:c,className:"h-7 rounded-sm px-3 text-[11px]",children:"Cancel"}),e.jsxs(Z,{onClick:oe,disabled:j||X.length===0,className:"h-7 rounded-sm px-3 text-[11px]",children:[j?e.jsx(he,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ds,{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:u=>{u.target===u.currentTarget&&c()},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:u=>u.stopPropagation(),children:[H,e.jsxs("button",{type:"button",onClick:c,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(Je,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})}):null:e.jsx(Ht,{open:t,onOpenChange:u=>{u||c()},children:e.jsx(qt,{"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 Qe(t,s){return s?`agent:${t}:${s}`:`node:${t}`}function Wc(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-")}function la(t,s,n){return`${Qe(t,n)}\0${s}`}function da(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function Yc(t,s,n){const r=s.find(i=>i.status!=="offline");if(r)return[Qe(r.id,Xc(n))];const o=on(n)[0];return o?[Qe(t,o)]:[]}function Qc(t,s,n){const r=ar(n);return[...s.flatMap(o=>r.length===0?[[Qe(o.id),{kind:"global"}]]:r.map(i=>[Qe(o.id,i),{kind:"global"}])),...on(n).map(o=>[Qe(t,o),rr(n)])]}function ar(t){return t.length===0||t.some(s=>s.kind==="plugin")?[]:nr}function Xc(t){var s;if(!(t.length===0||t.some(n=>n.kind==="plugin")))return(s=t[0])==null?void 0:s.agent}function on(t){if(t.length===0||t.some(n=>n.kind==="plugin"))return[];const s=new Set(t.map(n=>n.agent));return nr.filter(n=>!s.has(n))}function rr(t){var s;return((s=t[0])==null?void 0:s.scope)??{kind:"global"}}const ca="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",xt="py-0.5 pl-6 pr-1.5 text-[9px] leading-4 [&_svg]:h-3 [&_svg]:w-3",or="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",Jc="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 Zc(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 eu(t,s,n,r){return n.map(o=>({sourceNodeId:t,capabilityId:o.id,sourceScope:s,targets:r}))}function tu({loading:t,onRefresh:s}){return e.jsxs(Z,{variant:"ghost",onClick:s,disabled:t,"aria-busy":t,className:A(or,"min-w-[4.5rem]"),children:[e.jsx(Da,{className:A("h-2.5 w-2.5",t&&"animate-spin")}),t?"Refreshing":"Refresh"]})}function su({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(Z,{type:"button",variant:"ghost",onClick:n,disabled:t===0,className:or,children:[e.jsx(Je,{className:"h-2.5 w-2.5"}),"Selected: ",t," / Clear"]})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(tu,{loading:s,onRefresh:r}),e.jsxs(Z,{type:"button",variant:"ghost",onClick:o,disabled:t===0,className:Jc,children:[e.jsx(ds,{className:"h-2.5 w-2.5"}),"Share"]})]})]})}function nu({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 au({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(he,{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 ru({open:t,node:s,scope:n,clusterNodes:r,onOpenChange:o,onSelectionChange:i}){const[c,m]=a.useState([]),[g,h]=a.useState([]),[y,p]=a.useState(!1),[l,k]=a.useState(""),[E,j]=a.useState("all"),[_,b]=a.useState("all"),[N,f]=a.useState(new Set),[w,C]=a.useState(null),[S,M]=a.useState(null),[P,$]=a.useState(!1),[F,D]=a.useState(null),[X,q]=a.useState(!1),[O,B]=a.useState([]),[re,se]=a.useState(Za),[oe,ne]=a.useState(null),L=a.useMemo(()=>Sc(c,{search:l,agent:E,kind:_}),[E,c,_,l]),H=a.useMemo(()=>c.filter(z=>N.has(z.id)),[c,N]),u=a.useMemo(()=>r.filter(z=>z.id!==s.id),[r,s.id]),U=n.kind==="project"?n.projectPath:"global",x=async()=>{p(!0);try{const z=await Oo(s.id,{scope:n});m(z.items),h((z.errors??[]).map(J=>`${J.agent}: ${J.message}`))}catch(z){h([z instanceof Error?z.message:"Failed to load capabilities"])}finally{p(!1)}};a.useEffect(()=>{t&&(f(new Set),C(null),M(null),$(!1),B([]),m([]),h([]),x())},[t,s.id,n.kind,U]),a.useEffect(()=>{if(!oe)return;const z=de=>{se(Ec(oe.startWidth,oe.startClientX,de.clientX,window.innerWidth))},J=()=>ne(null);return window.addEventListener("pointermove",z),window.addEventListener("pointerup",J),()=>{window.removeEventListener("pointermove",z),window.removeEventListener("pointerup",J)}},[oe]);const W=z=>{z.preventDefault(),ne({startClientX:z.clientX,startWidth:re})},T=()=>{ne(null),$(!1),C(null),M(null)},G=()=>{f(new Set),B([])},v=async z=>{C(z.id),$(!0),M(null);const J=await zo(s.id,z.id,n);M(J.detail)},Y=a.useCallback(async z=>{if(H.length===0||z.length===0){B([]);return}B([]);try{const J=Zc(s.id,n,H,z),de=await Promise.all(J.map(R=>$o(R)));B(de.flatMap((R,ie)=>R.results.map(Ce=>{var Ee;return{...Ce,capabilityId:(Ee=J[ie])==null?void 0:Ee.capabilityId}})))}catch{B([])}},[s.id,n,H]),Q=()=>{B([]),q(!0)},ue=async z=>{const J=eu(s.id,n,H,z);J.length!==0&&(await Promise.all(J.map(de=>Vo(de))),le.success(`${J.length} capability share request${J.length===1?"":"s"} completed`),q(!1))},ee=async()=>{if(!(!S||F)){D(S.id);try{const z=await Fo(s.id,S.id,n);z.status==="deleted"?(le.success(`Deleted ${S.name}`),m(J=>J.filter(de=>de.id!==S.id)),f(J=>{const de=new Set(J);return de.delete(S.id),de}),C(null),M(null),$(!1),await x()):(le.info(z.message??"Capability was not found"),C(null),M(null),$(!1),await x())}catch(z){le.error(z instanceof Error?z.message:"Failed to delete capability")}finally{D(null)}}};return e.jsx(e.Fragment,{children:e.jsx(Ht,{open:t,onOpenChange:o,children:e.jsxs(qt,{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(Ws,{className:"border-b border-border/55 bg-card/28 px-4 py-2.5 text-left",children:[e.jsx(us,{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(Fc,{node:s,scope:n,clusterNodes:r,onSelectionChange:i}),e.jsxs(Na,{"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(xa,{className:"pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),e.jsx(nt,{value:l,onChange:z=>k(z.target.value),placeholder:"Search capabilities",className:"h-7 rounded-sm border-0 bg-muted/55 pl-6 text-[10px] shadow-none"})]}),e.jsxs(Ne,{value:E,onValueChange:z=>j(z),children:[e.jsx(ke,{className:A("w-28",ca),children:e.jsx(Me,{})}),e.jsxs(Se,{className:"shadow-none",children:[e.jsx(xe,{value:"all",className:xt,children:"Agent: All"}),e.jsx(xe,{value:"claudecode",className:xt,children:"Claude Code"}),e.jsx(xe,{value:"codex",className:xt,children:"Codex"}),e.jsx(xe,{value:"copilot",className:xt,children:"Copilot"})]})]}),e.jsxs(Ne,{value:_,onValueChange:z=>b(z),children:[e.jsx(ke,{className:A("w-24",ca),children:e.jsx(Me,{})}),e.jsxs(Se,{className:"shadow-none",children:[e.jsx(xe,{value:"all",className:xt,children:"Kind: All"}),e.jsx(xe,{value:"skill",className:xt,children:"Skill"}),e.jsx(xe,{value:"plugin",className:xt,children:"Plugin"}),e.jsx(xe,{value:"mcp",className:xt,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(Cc,{items:L,selectedIds:N,activeId:w,onToggleSelected:(z,J)=>f(de=>{const R=new Set(de);return J?R.add(z):R.delete(z),R}),onOpenDetail:v}),e.jsx(su,{selectedCount:N.size,loading:y,onClearSelection:G,onRefresh:x,onShare:Q}),e.jsx(au,{visible:y&&c.length===0})]}),P&&e.jsxs(e.Fragment,{children:[e.jsx(nu,{onBeginResize:W,onFold:T}),e.jsx(Dc,{detail:S,deleting:F===(S==null?void 0:S.id),desktopWidth:re,onDelete:S?ee:void 0,pending:!S})]})]}),X&&e.jsx(Gc,{open:X,sourceNode:s,targetNodes:u,selectedCapabilities:H,previewResults:O,embedded:!0,onClose:()=>q(!1),onPreviewTargetsChange:Y,onShare:ue})]})})})}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,h)=>{n({nodeId:g,scope:{kind:"project",projectPath:h}})},[]),c=a.useCallback(g=>{n(g)},[]);return{capabilitiesDialog:s&&r&&t?e.jsx(ru,{open:!0,node:r,scope:s.scope,clusterNodes:t.nodes,onOpenChange:g=>{g||n(null)},onSelectionChange:c}):null,openNodeCapabilities:o,openProjectCapabilities:i}}function iu(){var mn,xn,hn,pn,fn,gn;const{id:t}=Uo(),s=Ho(),n=qo(),r=Ko(),{cluster:o,systemInfo:i,events:c,sseConnected:m,subscribe:g,refresh:h,loading:y,error:p}=Go(),l=a.useMemo(()=>Wo(s.state),[s.state]),[k,E]=a.useState(null),[j,_]=a.useState("active"),[b,N]=a.useState("all"),[f,w]=a.useState("all"),[C,S]=a.useState("all"),M=(r==null?void 0:r.headerSearchQuery)??"",P=a.useDeferredValue(M),{desktopTasksOpen:$,mobileTasksPanelOpen:F,mobileTasksPanelRef:D,operationsOpen:X,operationsPanelRef:q,panelResize:O,setMobileTasksPanelOpen:B,setOperationsOpen:re,toggleTasksPanel:se}=rc(),[oe,ne]=a.useState(()=>!!(l!=null&&l.draftNewTask)),[L,H]=a.useState(()=>(l==null?void 0:l.createMode)??"chat"),[u,U]=a.useState(()=>(l==null?void 0:l.createDefaults)??null),[x,W]=a.useState(()=>l!=null&&l.draftNewTask?{route:l.returnRoute??"/",taskId:l.returnTaskId??null}:null),[T,G]=a.useState(!1),[v,Y]=a.useState("transcript"),[Q,ue]=a.useState("all"),[ee,z]=a.useState(!1),[J,de]=a.useState(null),[R,ie]=a.useState([]),[Ce,Ee]=a.useState([]),[Oe,Le]=a.useState(!1),[ze,ae]=a.useState(!1),[ve,_e]=a.useState(null),[Re,Fe]=a.useState(new Set),[we,rt]=a.useState(!1),[jt,ot]=a.useState(!1),[Ke,wt]=a.useState(null),$e=a.useRef(null),V=a.useRef(new Map),ce=((mn=o==null?void 0:o.self)==null?void 0:mn.role)==="leader",Te=(xn=o==null?void 0:o.self)==null?void 0:xn.id;xc({cluster:o,subscribe:g});const{nodeSettingsDialog:ht,openNodeSettings:pt}=yc(ce),{capabilitiesDialog:ft,openNodeCapabilities:De,openProjectCapabilities:He}=ou(o),{devBoxDialog:it,devBoxNodeIds:yt,devBoxStartNodeId:et,devBoxStartNodeIds:gt,devBoxStartingNodeIds:lt,openDevBox:dt,startDevBox:ye}=wc({cluster:o,refresh:h}),{completedGroups:at=[],fetchTasks:Ae,loadCompletedTasksPage:ct,removeTasksFromList:ut,setTasks:pe,tasks:je,tasksError:tt,tasksLoading:Nt}=cc({isLeader:ce,selfId:Te,sseConnected:m,preservedTask:J,subscribe:g}),Ge=a.useMemo(()=>[...je].sort((d,I)=>I.updatedAt-d.updatedAt),[je]),We=a.useMemo(()=>{var d;return((d=[...je].sort((I,K)=>K.createdAt-I.createdAt||K.updatedAt-I.updatedAt)[0])==null?void 0:d.id)??null},[je]),ir=a.useMemo(()=>{const d=new Map;for(const I of(o==null?void 0:o.nodes)??[]){const K=hl(Ge,I.id);K>0&&d.set(I.id,K)}return d},[o==null?void 0:o.nodes,Ge]),Ye=a.useMemo(()=>Ge.filter(d=>!Yo(d,o==null?void 0:o.nodes,o==null?void 0:o.self)||!Qo(d,j)||b!=="all"&&d.agent!==b||!Xo(d,C)||f==="unassigned"&&d.assignedTo||f!=="all"&&f!=="unassigned"&&Jo(d.assignedTo,o==null?void 0:o.nodes,d.assignedNodeName)!==f?!1:P.trim()?Zo(d,P):!0),[Ge,o==null?void 0:o.nodes,o==null?void 0:o.self,j,b,C,f,P]);a.useEffect(()=>{Fe(d=>{const I=jl(d,Ye.map(K=>K.id));return I.size===d.size?d:I})},[Ye]),a.useEffect(()=>{ce||Fe(new Set)},[ce]);const lr=a.useMemo(()=>["all",...Array.from(new Set(Ge.map(d=>d.agent))).sort()],[Ge]),dr=a.useMemo(()=>{const I=Array.from(new Set(Ge.map(K=>K.assignedTo).filter(K=>!!K))).map(K=>{const be=Ge.find(me=>me.assignedTo===K);return(o==null?void 0:o.nodes.find(me=>me.id===K))??{id:K,name:Ds(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}))]},[Ge,o==null?void 0:o.nodes]),ln=a.useMemo(()=>{const d=new Map;for(const I of(o==null?void 0:o.nodes)??[])d.set(I.id,I.name);for(const I of Ge)I.assignedTo&&I.assignedNodeName&&!d.has(I.assignedTo)&&d.set(I.assignedTo,I.assignedNodeName);return d},[o==null?void 0:o.nodes,Ge]),cr=a.useMemo(()=>{var I;const d=new Map;for(const K of(o==null?void 0:o.nodes)??[])K.workDir&&d.set(K.id,K.workDir);return(I=o==null?void 0:o.self)!=null&&I.workDir&&d.set(o.self.id,o.self.workDir),d},[o]),ur=a.useMemo(()=>{const d=new Map;for(const I of(o==null?void 0:o.nodes)??[])d.set(I.id,I.status);return o!=null&&o.self&&d.set(o.self.id,o.self.status),d},[o]),mr=a.useMemo(()=>new Map(at.map(d=>[Hs(d),d])),[at]),dn=a.useMemo(()=>{const d=new Map;for(const I of(o==null?void 0:o.nodes)??[])I.status!=="offline"&&d.set(I.id,I);return o!=null&&o.self&&o.self.status!=="offline"&&d.set(o.self.id,o.self),Array.from(d.values())},[o]),xr=((hn=o==null?void 0:o.self)==null?void 0:hn.id)??((pn=dn[0])==null?void 0:pn.id)??null,ps=a.useMemo(()=>["all",...Array.from(new Set(c.map(d=>d.type))).sort()],[c]),hr=a.useMemo(()=>Q==="all"?c:c.filter(d=>d.type===Q),[c,Q]),pr=Ye.length>0&&Ye.every(d=>Re.has(d.id)),fr=Ye.some(d=>Re.has(d.id)),gr=wl(Ye,Re);a.useEffect(()=>{l!=null&&l.draftNewTask&&(ne(!0),H(l.createMode??"chat"),U(l.createDefaults??null),W({route:l.returnRoute??"/",taskId:l.returnTaskId??null}))},[l]),a.useEffect(()=>{Q!=="all"&&!ps.includes(Q)&&ue("all")},[Q,ps]),a.useEffect(()=>{Pn(t,oe)&&!k&&We&&E(We)},[t,oe,k,We]),a.useEffect(()=>{Pn(t,oe)&&(k&&je.some(d=>d.id===k)||E(We))},[t,oe,k,We,je]);const fe=fl({routeTaskId:t,creatingTask:oe,internalSelectedTaskId:k,sortedTaskIds:We?[We]:[]}),kt=a.useMemo(()=>je.find(d=>d.id===fe)??null,[je,fe]);a.useEffect(()=>{$e.current=fe??null},[fe]);const mt=a.useCallback(()=>{de(null),ie([]),Ee([]),_e(null),ae(!1)},[]),Pt=a.useCallback((d,I,K=!0)=>{V.current.set(d,{logs:Qa(I),loaded:K})},[]),Ve=a.useCallback(async()=>{const d=fe;if(d)try{const I=await ei(d);if($e.current!==d)return;de(I),pe(K=>Ia(K,I)),_e(null)}catch(I){if($e.current!==d)return;mt(),_e(I instanceof Error?I.message:"Failed to load task")}finally{$e.current===d&&Le(!1)}},[fe,mt,pe]),Kt=a.useCallback(async()=>{const d=fe;if(d)try{const I=await Ms(d);if($e.current!==d)return;ie(K=>{const be=Ta(K,I.logs);return Pt(d,be),be}),Ee(K=>Ls(K,I.logs))}catch{}finally{$e.current===d&&ae(!1)}},[fe,Pt]);a.useEffect(()=>{if(!fe){mt(),Le(!1);return}Y("transcript"),de(kt);const d=uc(fe,V.current);ie(d.logs),Ee([]),_e(null),Le(!0),ae(d.transcriptLoading),Ve(),Kt()},[fe,mt,Kt,Ve]),a.useEffect(()=>{if(!gl({activeTaskId:fe,routeTaskId:t,creatingTask:oe,tasksLoading:Nt,loadedTaskIds:je.map(I=>I.id)}))return;const d=We;E(d),mt(),a.startTransition(()=>{n(d?`/tasks/${d}`:"/",{state:null})})},[fe,mt,oe,We,n,t,je,Nt]),a.useEffect(()=>{kt&&de(d=>!d||d.id!==kt.id?d:{...d,...kt})},[kt]),a.useEffect(()=>{if(fe)return g("task",d=>{const I=d.data.taskId;if(!(typeof I!="string"||I!==fe)){if(d.type==="task.output"){const K=d.data.event;if(K){ie(me=>{const It=gi(me,K);return Pt(fe,It),It}),ae(!1);const be=Dn(K);be&&Ee(me=>bi(me,be))}}d.type==="task.updated"&&Ve(),d.type==="task.status"&&(Ve(),Kt())}})},[g,fe,Ve,Kt]);const te=J??kt,br=te!=null&&te.assignedTo?(o==null?void 0:o.nodes.find(d=>d.id===te.assignedTo))??null:null,Lt=r==null?void 0:r.setHeaderTaskContext;a.useEffect(()=>{if(!Lt)return;if(!te){Lt(null);return}const d=te.effectiveProjectPath??te.project??"default workspace";return Lt({taskId:te.id,taskTitle:te.title,nodeName:Ds(te.assignedTo,o==null?void 0:o.nodes,te.assignedNodeName),projectLabel:ya(d),projectPath:d}),()=>Lt(null)},[te,o==null?void 0:o.nodes,Lt]);const fs=Ce.length>0,vr=te?ti.has(te.agent):!1,gs=(te==null?void 0:te.status)==="running",jr=te?ls.has(te.status):!1,wr=te?ls.has(te.status)||si.has(te.status):!1,yr=!!(te&&ce&&te.status==="failed"),bs=a.useMemo(()=>Wd(te,o,fs,!!gs),[te,o,fs,gs]),vs=a.useMemo(()=>vi([...R,...Ce.map(d=>Ss(d.content,d.timestamp))]),[R,Ce]),Gt=a.useMemo(()=>{if(!te||te.conversationKind==="nativeSession")return null;const d=ji(te);if(d.length>0)return Ss(d,new Date(te.createdAt).toISOString());if(vs.length>0)return null;const I=wi(te.description||te.title);return I.length>0?Ss(I,new Date(te.createdAt).toISOString()):null},[te,vs]),js=a.useMemo(()=>Gt?Dn(Gt):null,[Gt]),Nr=a.useMemo(()=>js?yi(R,js):!1,[R,js]),ws=a.useCallback((d="chat",I)=>{const K={route:t?`/tasks/${t}`:"/",taskId:fe};W(K),H(d),U(I??null),ne(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:K.route,returnTaskId:K.taskId,createMode:d,createDefaults:I}})})},[t,fe,n]),kr=a.useCallback(()=>{const d=(x==null?void 0:x.taskId)??We;ne(!1),W(null),U(null),E(d),a.startTransition(()=>{n((x==null?void 0:x.route)??"/",{state:null})})},[x,We,n]),cn=a.useCallback(d=>{ne(!1),W(null),U(null),E(d),a.startTransition(()=>{n(`/tasks/${d}`,{state:null})})},[n]),Sr=a.useCallback(d=>{$e.current=d.id,ne(!1),W(null),U(null),pe(I=>bl(I,d)),de(d),ie([]),Ee([]),_e(null),Le(!1),ae(d.conversationKind==="nativeSession"),Y("transcript"),E(d.id),pc({task:d,getActiveTaskId:()=>$e.current,setLogs:ie,setPendingMessages:Ee,setTranscriptLoading:ae}),Ae(),a.startTransition(()=>{n(`/tasks/${d.id}`,{state:null})})},[Ae,n]),{cancelQueuedMessage:Cr,queueFollowUpMessage:Wt}=Nc({activeTaskId:fe,fetchActiveTask:Ve,setPendingMessages:Ee,setTask:de,setTasks:pe}),_r=a.useCallback(d=>{Wt(d)},[Wt]),Tr=a.useCallback(async()=>{const d=fe;if(!(!d||(te==null?void 0:te.conversationKind)!=="nativeSession")){ae(!0);try{const I=await Ms(d);if($e.current!==d)return;ie(I.logs),Pt(d,I.logs),Ee(K=>Ls(K,I.logs))}catch(I){le.error(I instanceof Error?I.message:"Failed to reload transcript")}finally{$e.current===d&&ae(!1)}}},[te==null?void 0:te.conversationKind,fe,Pt]),Er=a.useCallback(d=>Wt(d),[Wt]),Dr=a.useCallback(async()=>{if(te)try{await ni(te.id),Ve(),Ae()}catch(d){le.error(d instanceof Error?d.message:"Failed to cancel task")}},[te,Ve,Ae]),{handleShareTask:Ar,handleStopShareTask:Mr}=tc(te,Ve,Ae),Pr=a.useCallback(async()=>{if(te)try{await ai(te.id),Ve(),Ae()}catch(d){le.error(d instanceof Error?d.message:"Failed to retry task")}},[te,Ve,Ae]),Yt=a.useCallback((d,I=!1)=>{const K=yl(Ye,d);return E(K),(I||!K)&&mt(),a.startTransition(()=>{n(K?`/tasks/${K}`:"/",{state:null})}),K},[mt,Ye,n]),Lr=a.useCallback((d,I)=>{Fe(K=>{const be=new Set(K);return I?be.add(d):be.delete(d),be})},[]),Ir=a.useCallback(d=>{if(!d){Fe(new Set);return}Fe(new Set(Ye.map(I=>I.id)))},[Ye]),Br=a.useCallback(async()=>{const d=Array.from(Re);if(d.length!==0)try{const{results:I}=await ri(d),K=I.filter(me=>!me.ok),be=I.filter(me=>me.ok).map(me=>me.id);fe&&be.includes(fe)&&Yt(be),K.length>0?le.error(`Failed to archive ${K.length} task(s): ${K.map(me=>me.error??me.id).join(", ")}`):le.success(`Archived ${be.length} task(s)`),Fe(new Set(K.map(me=>me.id))),Ae()}catch(I){le.error(I instanceof Error?I.message:"Failed to archive tasks")}},[fe,Ae,Yt,Re]),Rr=a.useCallback(async()=>{const d=Array.from(Re);if(d.length!==0)try{const{results:I}=await oi(d),K=I.filter(me=>!me.ok),be=I.filter(me=>me.ok).map(me=>me.id);be.length>0&&ut(be),fe&&be.includes(fe)&&Yt(be,!0),K.length>0?le.error(`Failed to delete ${K.length} task(s): ${K.map(me=>me.error??me.id).join(", ")}`):le.success(`Deleted ${be.length} task(s)`),Fe(new Set(K.map(me=>me.id))),Ae()}catch(I){le.error(I instanceof Error?I.message:"Failed to delete tasks")}},[fe,Ae,Yt,ut,Re]),$r=a.useCallback(async()=>{rt(!0);try{await ii(),h()}catch(d){le.error(d instanceof Error?d.message:"Failed to promote node")}finally{rt(!1)}},[h]),Or=a.useCallback(async()=>{ot(!0);try{await li(),le.success("This node left the remote cluster and is leading itself again."),Ae(),Ve(),h()}catch(d){le.error(d instanceof Error?d.message:"Failed to leave cluster")}finally{ot(!1)}},[Ve,Ae,h]),zr=a.useCallback(async d=>{var It;const I=!en(d),K=d.id===((It=o==null?void 0:o.self)==null?void 0:It.id),be=K?(i==null?void 0:i.transportType)??d.transportType:d.transportType,me=K&&!I&&Mt(be);wt(d.id);try{me?await di("direct"):await ci(d.id,I),le.success(I?`Enabled remote access on ${d.name}`:`Disabled remote access on ${d.name}`),h()}catch(bn){le.error(bn instanceof Error?bn.message:"Failed to update remote access")}finally{wt(null)}},[(fn=o==null?void 0:o.self)==null?void 0:fn.id,h,i==null?void 0:i.transportType]),Fr=a.useCallback(d=>{ct&&ct(d).catch(I=>{le.error(I instanceof Error?I.message:"Failed to load completed tasks")})},[ct]),un={toolbarTasks:Ye,activeTaskId:fe,tasksLoading:Nt,tasksError:tt,isLeader:ce,scope:j,agentFilter:b,nodeFilter:f,taskKindFilter:C,agentOptions:lr,nodeOptions:dr,nodeNameById:ln,nodeWorkDirById:cr,nodeStatusById:ur,leaderNodeId:((gn=o==null?void 0:o.leader)==null?void 0:gn.id)??null,searchQuery:M,completedGroupByKey:mr,devBoxNodeIds:yt,devBoxStartNodeIds:gt,devBoxStartingNodeIds:lt,selectedTaskIds:Re,allVisibleTasksSelected:pr,someVisibleTasksSelected:fr,canBatchArchive:gr,onScopeChange:_,onAgentFilterChange:N,onNodeFilterChange:w,onTaskKindFilterChange:S,onToggleTaskSelected:Lr,onToggleAllVisibleTasks:Ir,onBatchArchive:Br,onBatchDelete:Rr,onCreateTask:ws,onOpenNodeSettings:ce?pt:void 0,onOpenNodeCapabilities:ce?De:void 0,onOpenProjectCapabilities:ce?He:void 0,onOpenDevBox:ce?dt:void 0,onStartDevBox:ce?ye:void 0,onLoadCompletedTasks:Fr,onSelectTask:cn},Vr={cluster:o,systemInfo:i,nodeNameById:ln,nodeBlockingTaskCounts:ir,eventTypeFilter:Q,onEventTypeFilterChange:ue,eventTypeOptions:ps,filteredEvents:hr,sseConnected:m,clusterLoading:y,clusterError:p,promotePending:we,onPromote:$r,onAddNode:()=>G(!0),leavePending:jt,onLeaveCluster:Or,onToggleNodeDevTunnel:zr,devTunnelNodeId:Ke,devBoxStartNodeId:et,devBoxStartingNodeIds:lt,onOpenNodeSettings:ce?pt:void 0,onOpenNodeCapabilities:ce?De:void 0,onOpenDevBox:ce?dt:void 0,onStartDevBox:ce?ye:void 0};return e.jsxs(e.Fragment,{children:[e.jsx(Ed,{desktopTasksOpen:$,mobileTasksPanelOpen:F,mobileTasksPanelRef:D,operationsOpen:X,operationsPanelRef:q,panelResize:O,taskSidebar:e.jsx(Qn,{...un}),operationsSidecar:e.jsx(Kd,{...Vr}),terminalPanel:r!=null&&r.terminalOpen?e.jsx(Rd,{nodes:dn,defaultNodeId:xr,onClose:()=>r==null?void 0:r.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(wd,{onToggleTasks:se,desktopTasksOpen:$,mobileTasksPanelOpen:F,operationsOpen:X,onToggleOperations:()=>re(d=>!d),cluster:o,sseConnected:m,activeTab:v,setActiveTab:Y,creatingTask:oe,createMode:L,createDefaults:u,activeTask:te,assignedNode:br,taskLoading:Oe,transcriptLoading:ze,taskError:ve,displayEvents:vs,initialPromptAlreadyInLogs:Nr,initialPrompt:Gt,supportsFollowUp:vr,taskUnavailable:bs.taskUnavailable,chatDisabled:bs.chatDisabled,chatDisabledReason:bs.chatDisabledReason,questionBypassEnabled:ee,isRunning:!!gs,isStarting:jr,hasPendingFollowUp:fs,canCancel:!!wr,canRetry:!!yr,onRetry:Pr,onCancel:Dr,onReloadNativeTranscript:Tr,onShareTask:Ar,onStopShareTask:Mr,onStartCreateTask:ws,onCancelCreateTask:kr,onCreateTask:Sr,onSendMessage:_r,onCancelQueuedMessage:Cr,onQuestionBypassChange:z,onSubmitQuestionResponse:Er}),mobileTaskSidebar:e.jsx(Qn,{...un,onCreateTask:(d,I)=>{B(!1),ws(d,I)},onSelectTask:d=>{B(!1),cn(d)}}),onCloseOperations:()=>re(!1),onCloseTaskList:()=>B(!1),onToggleOperations:()=>re(d=>!d),onToggleTasks:se}),e.jsx(kd,{open:T,onOpenChange:G,onAdded:h}),ht,it,ft]})}const mu=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:iu},Symbol.toStringTag,{value:"Module"}));export{mu as D,Is as G};
|