meshy-node 0.10.1 → 0.10.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.
@@ -0,0 +1,171 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-RR7aUMed.js","assets/index-wWBvCQa_.js","assets/index-C5P8wBe6.css","assets/MarkdownPreviewFrame-AYrcV-z2.js","assets/DashboardShared-jid8cltG.js","assets/file-KRY6pQrh.js","assets/PreviewTab-DO689Vk0.js","assets/DiffTab-WaSKUZxb.js"])))=>i.map(i=>d[i]);
2
+ import{c as fe,r as o,a as ws,f as Ea,m as Aa,j as e,X as at,Q as jn,B as Z,L as ue,S as Da,b as ki,d as R,e as Si,g as Ci,h as Ti,I as rt,P as Ei,C as as,i as Ai,k as _a,F as Di,l as Bt,n as We,o as he,D as os,p as _i,q as Mi,t as le,s as je,u as Ne,v as Pe,w as ke,x as Ma,y as Je,T as Pi,z as Ii,A as nr,E as Li,G as yt,H as jt,J as Ot,K as Pa,M as Ia,N as Cs,O as Rn,R as Ri,U as vt,V as Nn,W as Bi,Y as Bn,Z as La,_ as Oi,$ as $e,a0 as Fi,a1 as ct,a2 as Yt,a3 as Jt,a4 as Zt,a5 as Xt,a6 as es,a7 as ts,a8 as ss,a9 as ns,aa as On,ab as zi,ac as Ts,ad as Ra,ae as Ui,af as rr,ag as ar,ah as Us,ai as $i,aj as qi,ak as Vi,al as Hi,am as Ki,an as Es,ao as Gi,ap as Wi,aq as As,ar as Qi,as as Ba,at as Yi,au as Ji,av as Zi,aw as Oa,ax as Fn,ay as Fa,az as Xi,aA as ys,aB as el,aC as or,aD as tl,aE as zn,aF as sl,aG as nl,aH as rl,aI as za,aJ as is,aK as al,aL as kn,aM as Ua,aN as ol,aO as il,aP as ll,aQ as dl,aR as ir,aS as cl,aT as ul,aU as $s,aV as ml,aW as lr,aX as hl,aY as fl,aZ as xl,a_ as dr,a$ as pl,b0 as gl,b1 as Sn,b2 as bl,b3 as vl,b4 as $a,b5 as cr,b6 as qa,b7 as wl,b8 as yl,b9 as jl,ba as Nl,bb as kl,bc as Sl,bd as Cl,be as Tl,bf as El,bg as Al,bh as Dl,bi as _l,bj as Ml,bk as Pl,bl as Il,bm as Ll,bn as Rl,bo as Bl,bp as Ol,bq as Fl,br as zl,bs as Ul,bt as $l,bu as ql,bv as Vl,bw as Hl,bx as Kl,by as Gl,bz as Wl,bA as Ql,bB as Yl,bC as Jl,bD as Zl}from"./index-wWBvCQa_.js";import{r as ur,e as Xl,b as Va,g as Ha,I as Ka,A as Un,a as Ga,c as ed,i as Wa,d as td,f as sd,t as nd,h as mr,j as hr,k as rd,l as ad,C as fr,T as qs,D as _t,m as Ye,M as Cn,L as od,n as Qa,o as Tn,p as id,q as xr,s as ld,u as dd,v as Vs,w as cd,x as ud,y as md}from"./DashboardShared-jid8cltG.js";import{E as hd,M as fd}from"./MarkdownPreviewFrame-AYrcV-z2.js";import{P as Ds,D as fs,g as xd,a as pd,b as gd}from"./PreviewTab-DO689Vk0.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 bd=[["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"}]],vd=fe("archive",bd);/**
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 wd=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],pr=fe("arrow-right",wd);/**
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 yd=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Ya=fe("arrow-up",yd);/**
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 jd=[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M9 13a4.5 4.5 0 0 0 3-4",key:"10igwf"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M12 13h4",key:"1ku699"}],["path",{d:"M12 18h6a2 2 0 0 1 2 2v1",key:"105ag5"}],["path",{d:"M12 8h8",key:"1lhi5i"}],["path",{d:"M16 8V5a2 2 0 0 1 2-2",key:"u6izg6"}],["circle",{cx:"16",cy:"13",r:".5",key:"ry7gng"}],["circle",{cx:"18",cy:"3",r:".5",key:"1aiba7"}],["circle",{cx:"20",cy:"21",r:".5",key:"yhc1fs"}],["circle",{cx:"20",cy:"8",r:".5",key:"1e43v0"}]],Ja=fe("brain-circuit",jd);/**
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 Nd=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],ls=fe("chevron-left",Nd);/**
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 kd=[["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"}]],Sd=fe("earth",kd);/**
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 Cd=[["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"}]],Td=fe("ellipsis-vertical",Cd);/**
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 Ed=[["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"}]],Ad=fe("ellipsis",Ed);/**
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 Dd=[["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"}]],_d=fe("flag",Dd);/**
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 Md=[["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"}]],_s=fe("folder-open",Md);/**
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 Pd=[["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"}]],Id=fe("funnel",Pd);/**
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 Ld=[["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"}]],js=fe("git-branch",Ld);/**
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 Rd=[["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"}]],Bd=fe("globe",Rd);/**
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 Od=[["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"}]],Ns=fe("history",Od);/**
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 Fd=[["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"}]],En=fe("image-plus",Fd);/**
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 zd=[["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"}]],Ud=fe("laptop",zd);/**
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 $d=[["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"}]],$n=fe("link-2",$d);/**
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 qd=[["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"}]],Vd=fe("list-ordered",qd);/**
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 Hd=[["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"}]],Ms=fe("message-square-plus",Hd);/**
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 Kd=[["path",{d:"M15.033 9.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56V7.648a.645.645 0 0 1 .967-.56z",key:"vbtd3f"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",key:"x3v2xh"}]],Za=fe("monitor-play",Kd);/**
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 Gd=[["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"}]],Ft=fe("pencil",Gd);/**
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 Wd=[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]],Qd=fe("qr-code",Wd);/**
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 Yd=[["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"}]],Jd=fe("rotate-ccw",Yd);/**
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 Zd=[["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"}]],Xa=fe("rotate-cw",Zd);/**
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 Xd=[["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"}]],eo=fe("send",Xd);/**
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 ec=[["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"}]],ks=fe("share-2",ec);/**
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 tc=[["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"}]],sc=fe("sliders-horizontal",tc);/**
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 nc=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],gr=fe("square",nc);/**
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 rc=[["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"}]],ac=fe("user-plus",rc);/**
148
+ * @license lucide-react v1.7.0 - ISC
149
+ *
150
+ * This source code is licensed under the ISC license.
151
+ * See the LICENSE file in the root directory of this source tree.
152
+ */const oc=[["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"}]],ic=fe("wifi",oc);/**
153
+ * @license lucide-react v1.7.0 - ISC
154
+ *
155
+ * This source code is licensed under the ISC license.
156
+ * See the LICENSE file in the root directory of this source tree.
157
+ */const lc=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"11",x2:"11",y1:"8",y2:"14",key:"1vmskp"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],dc=fe("zoom-in",lc);/**
158
+ * @license lucide-react v1.7.0 - ISC
159
+ *
160
+ * This source code is licensed under the ISC license.
161
+ * See the LICENSE file in the root directory of this source tree.
162
+ */const cc=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],uc=fe("zoom-out",cc),mc=new Set(["assigned","running"]);function hc(t,s){return t.reduce((n,r)=>r.assignedTo===s&&mc.has(r.status)?n+1:n,0)}function zt(t){return t?.toLowerCase()==="devtunnel"}function fc(t){return t?zt(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function qn(t,s){return zt(s??t.transportType)||!!t.devtunnelEndpoint}function to(t,s){return!zt(s??t.transportType)}function so(t,s){const n=s??t.transportType;return zt(n)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":fc(n)}function br(t,s){return!t&&!s}function xc({routeTaskId:t,creatingTask:s,internalSelectedTaskId:n,sortedTaskIds:r}){return t||(s?null:r[0]??n??null)}function pc({activeTaskId:t,routeTaskId:s,creatingTask:n,tasksLoading:r,loadedTaskIds:a}){return!t||s||n||r?!1:!a.includes(t)}function gc(t,s){return[s,...t.filter(n=>n.id!==s.id)]}function no(t,s){const n=t.findIndex(r=>r.id===s.id);return n===-1?[...t,s]:t.map((r,a)=>a===n?s:r)}const bc=new Set(["completed","failed","cancelled","archived"]);function vc(t,s){const n=new Set(s);return new Set(Array.from(t).filter(r=>n.has(r)))}function wc(t,s){const n=new Set(s);if(n.size===0)return!1;const r=t.filter(a=>n.has(a.id));return r.length===n.size&&r.every(a=>bc.has(a.status))}function yc(t,s){const n=new Set(s);return t.find(r=>!n.has(r.id))?.id??null}function ro(){const[t,s]=o.useState([]),[n,r]=o.useState(null),a=o.useRef(null),i=o.useCallback(()=>{a.current?.click()},[]),l=o.useCallback(async b=>{const f=Array.from(b.target.files??[]);if(f.length!==0)try{const u=await ur(f);s(g=>[...g,...u]),r(null)}catch(u){r(u instanceof Error?u.message:"Failed to attach image")}finally{b.target.value=""}},[]),d=o.useCallback(async b=>{const f=Xl(b.clipboardData);if(f.length!==0){b.preventDefault();try{const u=await ur(f);s(g=>[...g,...u]),r(null)}catch(u){r(u instanceof Error?u.message:"Failed to attach image")}}},[]),c=o.useCallback(b=>{s(f=>f.filter((u,g)=>g!==b))},[]),m=o.useCallback(()=>{s([]),r(null)},[]);return{images:t,error:n,fileInputRef:a,pickImages:i,handleFileChange:l,handlePaste:d,removeImage:c,clearImages:m}}function jc(t){const s=t.map(a=>({...a,displayValue:Nc(a)})),n=s.findIndex(a=>a.label.toLowerCase()==="working dir"),r=n>=0?n:0;return{primary:s[r],secondary:s.filter((a,i)=>i!==r)}}function Nc(t){return t.label.toLowerCase()==="agent"?Ga(t.value):t.value}function vr(t){switch(t.toLowerCase()){case"branch":return js;case"node":return Da;default:return _s}}function kc({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 Sc({contentLength:t,disabled:s=!1}){return t>0&&!s}function Cc({onSend:t,disabled:s,disabledReason:n="Chat is waiting on the agent.",placeholder:r="Send a follow-up message...",contextItems:a=[],agent:i,model:l,running:d=!1,onStop:c,quickChats:m=[]}){const[b,f]=o.useState(""),[u,g]=o.useState(0),[N,y]=o.useState(0),A=o.useRef(null),{images:h,error:E,fileInputRef:x,pickImages:v,handleFileChange:k,handlePaste:C,removeImage:T,clearImages:I}=ro(),S=o.useCallback(()=>{A.current&&(A.current.style.height="auto")},[]),P=o.useCallback(()=>{A.current&&(A.current.style.height="auto",A.current.style.height=`${Math.min(A.current.scrollHeight,220)}px`)},[]);o.useEffect(()=>{g(0)},[b,m]);const D=o.useCallback(O=>{f(O.prompt);const p=()=>{A.current?.focus(),P()};typeof requestAnimationFrame=="function"?requestAnimationFrame(p):p()},[P]),_=o.useCallback(()=>{const O=ws(b,m,u);if(O){D(O);return}const p=Va(b,h);Sc({contentLength:p.length,disabled:s})&&(y(q=>q+1),t(p),f(""),I(),S())},[b,h,s,t,I,S,m,u,D]),B=o.useCallback(O=>{const p=Ea(b,m);if(p.length>0&&(O.key==="ArrowDown"||O.key==="ArrowUp")){O.preventDefault(),g(q=>Aa(q,p.length,O.key==="ArrowDown"?1:-1));return}if(O.key==="Enter"&&!O.shiftKey){O.preventDefault();const q=ws(b,m,u);q?D(q):_()}},[D,_,m,u,b]),z=b.trim().length>0||h.length>0,Y=kc({disabled:s,running:d,canStop:d&&!!c,hasContent:z}),X=jc(a),ee=X.primary?vr(X.primary.label):_s,ne=i?Ha(i,l):null,U=d?z?"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:x,type:"file",accept:"image/*",multiple:!0,onChange:k,className:"hidden"}),X.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(ee,{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:X.primary.value,children:X.primary.displayValue})]})}),h.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:h.map((O,p)=>e.jsxs("div",{className:"relative",children:[e.jsx(Ka,{image:O,alt:O.filename??`attachment ${p+1}`,thumbnailClassName:"h-24 w-24 border border-border/70",imageClassName:"h-full w-full"}),e.jsx("button",{type:"button",onClick:()=>T(p),className:"absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${O.filename??`image ${p+1}`}`,children:e.jsx(at,{className:"h-3 w-3"})})]},`${O.filename??"image"}-${p}`))})}),e.jsx("div",{className:"px-2 pb-0 pt-1 sm:px-5 sm:pt-1.5",children:e.jsx("textarea",{ref:A,"data-chat-input-textarea":"true",value:b,onChange:O=>f(O.target.value),onKeyDown:B,onPaste:C,onInput:P,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.jsx(jn,{query:b,quickChats:m,selectedIndex:u,onActiveIndexChange:g,onSelect:D}),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:[X.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:X.secondary.map(O=>{const p=vr(O.label),q=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:[q?e.jsx(Un,{agent:O.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(p,{"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:[ne&&e.jsxs("span",{"data-chat-input-model-display":"true","aria-label":`Model: ${ne}`,title:`Model: ${ne}`,className:"inline-flex h-7 max-w-[9rem] shrink-0 items-center gap-1.5 truncate rounded-sm px-2 text-[10px] text-muted-foreground",children:[e.jsx(Ja,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),ne]}),e.jsxs(Z,{type:"button",variant:"ghost",onClick:v,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(En,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:U,children:e.jsx(Z,{onClick:Y.primaryAction==="stop"?c:_,disabled:Y.primaryDisabled,size:"icon","data-chat-send-button":"true","aria-label":Y.primaryAction==="stop"?"Stop running task":d?"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:Y.primaryAction==="stop"?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(eo,{className:`h-3.5 w-3.5 ${N>0?"animate-chat-send-flight":""}`},N)})})]})]}),E&&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:E})]})})})}var Tc=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ec=Tc.reduce((t,s)=>{const n=ki(`Primitive.${s}`),r=o.forwardRef((a,i)=>{const{asChild:l,...d}=a,c=l?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(c,{...d,ref:i})});return r.displayName=`Primitive.${s}`,{...t,[s]:r}},{}),Ac="Label",ao=o.forwardRef((t,s)=>e.jsx(Ec.label,{...t,ref:s,onMouseDown:n=>{n.target.closest("button, input, select, textarea")||(t.onMouseDown?.(n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));ao.displayName=Ac;var oo=ao;const Dc=Si("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Fe=o.forwardRef(({className:t,...s},n)=>e.jsx(oo,{ref:n,className:R(Dc(),t),...s}));Fe.displayName=oo.displayName;function _c(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function Mc(t){return t.trim()||"."}function Pc(t){return new Promise(s=>window.setTimeout(s,t))}function Ic(t){return!!t&&typeof t=="object"&&typeof t.createdBranch=="string"&&typeof t.currentBranch<"u"}async function Lc(t){let s=t;for(let n=0;n<60;n++){if(s.status==="succeeded"){if(Ic(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 Pc(1e3),s=await Ai(s.id)}throw new Error("Timed out waiting for branch creation")}function wr({value:t,onChange:s,project:n,assignTo:r,nodes:a,assignableNodes:i,layout:l="default",chipClassName:d,chipActiveClassName:c,chipInactiveClassName:m,labelClassName:b,triggerClassName:f}){const[u,g]=o.useState(!1),[N,y]=o.useState(null),[A,h]=o.useState(""),[E,x]=o.useState(!1),[v,k]=o.useState(!1),[C,T]=o.useState(!1),[I,S]=o.useState(null),[P,D]=o.useState(""),[_,B]=o.useState(""),[z,Q]=o.useState(""),[Y,X]=o.useState(!1),ee=o.useRef(null),ne=o.useRef(0),U=o.useMemo(()=>_c(r,a,i),[r,a,i]),O=U?.id,p=o.useMemo(()=>Mc(n),[n]),q=o.useMemo(()=>O?`${O}
163
+ ${p}`:"",[O,p]),j=o.useCallback(async(re=0,G=!1)=>{const J=ne.current+1,ce=q;if(ne.current=J,!O){y(null),h("");return}S(null),G||h(""),G?k(!0):x(!0);try{const M=await Ci(O,{path:p,limit:20,offset:re,allowAbsolute:!0});if(J!==ne.current)return;h(ce),y(W=>G&&W?{...M,branches:[...W.branches,...M.branches]}:M)}catch(M){if(J!==ne.current)return;S(M instanceof Error?M.message:"Failed to load branch info"),G||(y(null),h(""))}finally{J===ne.current&&(x(!1),k(!1))}},[O,q,p]);o.useEffect(()=>{if(!O){ne.current+=1,y(null),h(""),S(null);return}j()},[O,p,j]),o.useEffect(()=>{const re=t.trim(),G=A===q?N:null,J=G?.available&&G.currentBranch?G.currentBranch:"";re!==J&&s(J)},[N,q,A,s,t]),o.useEffect(()=>{if(!u)return;const re=J=>{ee.current&&(ee.current.contains(J.target)||g(!1))},G=J=>{J.key==="Escape"&&g(!1)};return document.addEventListener("mousedown",re),document.addEventListener("keydown",G),()=>{document.removeEventListener("mousedown",re),document.removeEventListener("keydown",G)}},[u]),o.useEffect(()=>{u&&(B(""),Q(""),X(!1))},[u,O,p]);const V=o.useCallback(async()=>{if(!O)return;const re=P.trim(),G=Y?z.trim():_.trim();if(!(!re||!G)){T(!0),S(null);try{const J=await Ti(O,{path:p,branchName:re,startPoint:G,limit:20,offset:0,allowAbsolute:!0}),ce=await Lc(J);h(q),y(ce),s(ce.currentBranch??ce.createdBranch),D(""),B(""),Q(""),X(!1),g(!1)}catch(J){S(J instanceof Error?J.message:"Failed to create branch")}finally{T(!1)}}},[O,q,p,Y,z,P,s,_]),F=A===q?N:null,H=o.useCallback(()=>{F?.hasMore&&j(F.branches.length,!0)},[F,j]),L=t.trim()||F?.currentBranch||(F&&!F.available?"No git repo":"Branch"),ae=Y?z.trim():_.trim(),oe=!!(F?.available&&P.trim()&&ae&&!C),ge=l==="composer"?e.jsxs(Z,{type:"button",variant:"ghost",onClick:()=>g(re=>!re),title:L,"aria-label":`Branch: ${L}`,className:R(d,f,"min-w-0 max-w-full",t.trim()?c:m),children:[E&&!F?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(js,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:R("min-w-0 truncate",b),children:L})]}):e.jsxs(Z,{type:"button",variant:"outline",onClick:()=>g(re=>!re),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:L,children:[e.jsx("span",{className:R("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:L}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:U?U.name:"Manual"})]});return e.jsxs("div",{className:R("relative inline-block",l==="composer"?"min-w-0 shrink-0":"w-full"),ref:ee,children:[l==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-[10px] font-medium",children:"Branch"}),ge]}):ge,u&&e.jsxs("div",{className:R("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-sm border border-border/60 bg-background/95 shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",l==="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(js,{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:F?.repoRoot?`${F.currentBranch??L} · ${F.repoRoot}`:F?.currentBranch??L,children:F?.currentBranch??L}),E?e.jsx(ue,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),U?E&&!F?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):F&&!F.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(rt,{value:P,onChange:re=>D(re.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(Z,{type:"button",size:"sm",onClick:()=>{V()},disabled:!oe,title:oe?"Create branch":"Enter a name and pick a base","aria-label":"Create branch",className:"h-8 w-8 shrink-0 rounded-sm p-0",children:C?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ei,{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"}),!Y&&e.jsxs("button",{type:"button",onClick:()=>X(!0),className:"flex items-center gap-1 rounded-sm px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx(Ft,{className:"h-2.5 w-2.5"}),"Manual"]})]}),Y?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(rt,{value:z,onChange:re=>Q(re.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{X(!1),Q("")},className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel manual input","aria-label":"Cancel manual input",children:e.jsx(at,{className:"h-3.5 w-3.5"})})]}):F?.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-sm border border-border/40 bg-background/40",children:[F.branches.map(re=>{const G=_===re.ref,J=re.branch==="main"||re.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>B(re.ref),className:R("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",G&&"bg-background/70"),title:re.ref,children:[e.jsx("span",{className:R("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:re.ref}),G?e.jsx(as,{className:"h-3 w-3 shrink-0 text-primary"}):null]},re.ref)}),F.hasMore&&e.jsxs("button",{type:"button",onClick:H,disabled:v,className:"flex w-full items-center justify-center gap-1 border-t border-border/20 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[v?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Ns,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"rounded-sm border border-dashed border-border/40 px-2.5 py-2 text-[11px] text-muted-foreground",children:"No remote branches found."})]})]})}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a specific node first."}),I&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:I})]})]})}const Rc=20,Bc=3,An="meshy-working-dir-recents-by-node";function Oc(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function Fc(t){const s=t.trim();return s||"."}function Dn(t){const s=[],n=new Set;for(const r of t){const a=r.trim();if(!(!a||n.has(a))&&(n.add(a),s.push(a),s.length===Bc))break}return s}function zc(t,s){const n=s.trim();return Dn(n?[n,...t]:t)}function io(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 a=r.filter(l=>typeof l=="string"),i=Dn(a);i.length>0&&(s[n]=i)}return s}function Uc(t,s,n){if(!s)return t;const r=t[s]??[],a=zc(r,n);if(a.length===0){if(!(s in t))return t;const{[s]:i,...l}=t;return l}return{...t,[s]:a}}function $c(t,s){return s?t[s]?.[0]??"":""}function lo(t){if(!t||typeof window>"u")return"";try{const s=window.localStorage.getItem(An);return s?$c(io(JSON.parse(s)),t):""}catch{return""}}function qc(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function Vc(t,s){const n=s.trim();return n?Oc(n)||!t?n:`${t.replace(/[/\\]+$/,"")}/${n}`:""}function Hc(t,s){return t?t.isAbsolute?t.currentPath:t.currentPath==="."||t.currentPath===""?t.rootPath||s?.workDir||"Node root":t.currentPath:s?.workDir??"Node root"}function Ss({value:t,onChange:s,assignTo:n,nodes:r,assignableNodes:a,layout:i="default",chipClassName:l,chipActiveClassName:d,chipInactiveClassName:c,labelClassName:m,triggerClassName:b,popoverPlacement:f="bottom",popoverAlign:u="start"}){const[g,N]=o.useState(!1),[y,A]=o.useState(null),[h,E]=o.useState(!1),[x,v]=o.useState(!1),[k,C]=o.useState(null),[T,I]=o.useState(""),[S,P]=o.useState(!1),[D,_]=o.useState({}),B=o.useRef(null),z=o.useMemo(()=>qc(n,r,a),[n,r,a]),Q=z?.id,Y=o.useMemo(()=>Q?D[Q]??[]:[],[D,Q]),X=o.useMemo(()=>t.trim()?Vc(z?.workDir,t):"Use node default",[t,z?.workDir]);o.useEffect(()=>{if(!(typeof window>"u"))try{const L=window.localStorage.getItem(An);if(!L)return;const ae=JSON.parse(L);_(io(ae))}catch{}},[]);const ee=o.useCallback(L=>{Q&&_(ae=>{const oe=Uc(ae,Q,L);if(oe===ae)return ae;if(typeof window<"u")try{window.localStorage.setItem(An,JSON.stringify(oe))}catch{}return oe})},[Q]),ne=o.useCallback((L,ae=!0)=>{const oe=L.trim();s(oe),ae&&oe&&ee(oe),N(!1)},[s,ee]),U=o.useCallback(async(L,ae=0,oe=!1)=>{if(Q){C(null),oe?v(!0):E(!0);try{const ge=await _a(Q,{path:L,limit:Rc,offset:ae,directoriesOnly:!0,allowAbsolute:!0});A(re=>oe&&re?{...ge,entries:[...re.entries,...ge.entries]}:ge)}catch(ge){C(ge instanceof Error?ge.message:"Failed to browse directories"),oe||A(null)}finally{E(!1),v(!1)}}},[Q]),O=o.useRef(t);O.current=t;const p=o.useRef(U);p.current=U,o.useEffect(()=>{if(!g)return;const L=O.current;I(L),P(!1),A(null),C(null),Q&&p.current(Fc(L))},[g,Q]),o.useEffect(()=>{if(!g)return;const L=oe=>{B.current&&(B.current.contains(oe.target)||N(!1))},ae=oe=>{oe.key==="Escape"&&N(!1)};return document.addEventListener("mousedown",L),document.addEventListener("keydown",ae),()=>{document.removeEventListener("mousedown",L),document.removeEventListener("keydown",ae)}},[g]);const q=o.useCallback(L=>{U(L)},[U]),j=o.useCallback(()=>{y&&U(y.currentPath,y.entries.length,!0)},[y,U]),V=i==="composer"?e.jsxs(Z,{type:"button",variant:"ghost",onClick:()=>N(L=>!L),title:X,"aria-label":`Working directory: ${X}`,className:R(l,b,"min-w-0 max-w-full",t.trim()?d:c),children:[e.jsx(Di,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:R("min-w-0 truncate",m),children:X})]}):e.jsxs(Z,{type:"button",variant:"outline",onClick:()=>N(L=>!L),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:X,children:[e.jsx("span",{className:R("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:X}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:z?z.name:"Manual"})]}),F=Hc(y,z),H=!!y?.parentPath;return e.jsxs("div",{className:R("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":f,"data-workdir-popover-align":u,ref:B,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-[10px] font-medium",children:"Working directory"}),V]}):V,g&&e.jsxs("div",{className:R("absolute z-50 flex max-h-[min(28rem,calc(100vh-5rem))] w-[240px] flex-col overflow-hidden rounded-sm border border-border/60 bg-background/95 shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",f==="top"?"bottom-full mb-2":"top-full mt-2",i==="composer"?u==="end"?"right-0":"left-0":u==="end"?"right-0 w-auto min-w-[240px]":"left-0 right-0 w-auto min-w-[240px]"),children:[Y.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(Ns,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:Y.map(L=>e.jsx("button",{type:"button",onClick:()=>ne(L),className:"truncate rounded-sm px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:L,children:L},L))})]}),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:()=>y?.parentPath&&q(y.parentPath),disabled:!H||h,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-sm border border-border/60 text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(Ya,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:F,children:F}),y&&e.jsx("button",{type:"button",onClick:()=>ne(y.isAbsolute?y.currentPath:y.currentPath==="."?"":y.currentPath),className:"shrink-0 rounded-sm px-1.5 py-0.5 text-[10px] font-medium text-foreground hover:bg-background/60",title:"Use this folder",children:"Use"})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[z?h?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):y&&y.entries.length>0?e.jsxs(e.Fragment,{children:[y.entries.map(L=>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(L.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 ${L.path}`,children:[e.jsx(Bt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:L.name})]}),e.jsx("button",{type:"button",onClick:()=>q(L.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 ${L.name}`,children:e.jsx(We,{className:"h-3.5 w-3.5"})})]},L.path)),y.hasMore&&e.jsxs("button",{type:"button",onClick:j,disabled:x,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:[x?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Ns,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:k??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),k&&y&&y.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:k})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:S?e.jsxs(e.Fragment,{children:[e.jsx(rt,{value:T,onChange:L=>I(L.target.value),onKeyDown:L=>{L.key==="Enter"&&T.trim()?(L.preventDefault(),ne(T)):L.key==="Escape"&&(L.preventDefault(),P(!1),I(t))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>ne(T),disabled:!T.trim(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-foreground hover:bg-background/60 disabled:opacity-40",title:"Apply","aria-label":"Apply manual path",children:e.jsx(as,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{P(!1),I(t)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(at,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{I(t),P(!0)},className:"flex h-7 flex-1 items-center justify-between rounded-sm px-1.5 text-[11px] text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Enter a manual path",children:[e.jsx("span",{children:"Manual input"}),e.jsx(Ft,{className:"h-3 w-3"})]})})]})]})}function co(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 Vn({isCurrent:t}){return t?e.jsx(Ud,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Bd,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function _n(t,s){return t.map(n=>{const r=!!s&&n.id===s;return e.jsx(he,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Vn,{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 Kc(t){const s=t.sessionId.trim(),n=t.cwd.trim();return!s||!n||!t.assignTo?null:{title:t.title.trim()||t.defaultTitle?.trim()||void 0,agent:t.agent,sessionId:s,cwd:n,assignTo:t.assignTo,priority:t.priority,mode:t.mode??os}}function Gc(){return Pi.map(t=>e.jsx(he,{value:t.value,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:t.label}),t.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:t.description})]})},t.value))}function Wc(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 yr(t){if(!t.updatedAt)return 0;const s=Date.parse(t.updatedAt);return Number.isNaN(s)?0:s}function Qc(t,s){return yr(s)-yr(t)||t.sessionId.localeCompare(s.sessionId)}function Yc(t){const s=t.trim().replace(/[\\/]+$/,"");return s?s.split(/[\\/]+/).filter(Boolean).at(-1)??s:"Unknown project"}function Jc(t){const s=new Map;for(const n of[...t].sort(Qc)){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:Yc(n),cwd:n,sessions:r}))}function Zc(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function Xc({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:a,onCancel:i,className:l,footerClassName:d,submitLabel:c="Load session",cancelLabel:m="Cancel",autoFocus:b=!1}){const f=o.useMemo(()=>co(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),u=o.useMemo(()=>n&&f.some(M=>M.id===n)?n:f[0]?.id??"",[f,n]),[g,N]=o.useState(""),[y,A]=o.useState("codex"),[h,E]=o.useState(""),[x,v]=o.useState(""),[k,C]=o.useState(""),[T,I]=o.useState(u),[S,P]=o.useState("normal"),[D,_]=o.useState(os),[B,z]=o.useState(!1),[Q,Y]=o.useState([]),[X,ee]=o.useState(!1),[ne,U]=o.useState(null),O=o.useMemo(()=>Q.find(M=>M.sessionId===h)??null,[Q,h]);o.useEffect(()=>{T&&f.some(M=>M.id===T)||I(u)},[T,f,u]),o.useEffect(()=>{E(""),v(""),C("")},[y,T]),o.useEffect(()=>{let M=!1;return T?(ee(!0),U(null),_i(T,{agent:y,limit:50}).then(W=>{M||Y(W.sessions)}).catch(W=>{M||(Y([]),U(W instanceof Error?W.message:"Failed to load native sessions"))}).finally(()=>{M||ee(!1)}),()=>{M=!0}):(Y([]),U(null),ee(!1),()=>{M=!0})},[y,T]),o.useEffect(()=>{O&&(v(O.sessionId),C(O.cwd))},[O]);const p=o.useCallback(async M=>{M.preventDefault();const W=Kc({title:g,defaultTitle:O?.summary,agent:y,sessionId:x,cwd:k,assignTo:T,priority:S,mode:D});if(W){z(!0);try{const me=await Mi(W);a(me)}catch(me){le.error(me instanceof Error?me.message:"Failed to load native session")}finally{z(!1)}}},[g,O,y,x,k,T,S,D,a]),q=!!(x.trim()&&k.trim()&&T),[j,V]=o.useState(!1),[F,H]=o.useState(""),[L,ae]=o.useState(()=>new Set),oe=f.find(M=>M.id===T)??null,ge=!!(n&&oe?.id===n),re=o.useMemo(()=>{const M=F.trim().toLowerCase();return M?Q.filter(W=>W.summary.toLowerCase().includes(M)||W.sessionId.toLowerCase().includes(M)||W.cwd.toLowerCase().includes(M)):Q},[Q,F]),G=o.useMemo(()=>Jc(re),[re]),J=o.useCallback(M=>{ae(W=>Zc(W,M))},[]),ce="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:p,className:R("space-y-4",l),children:[e.jsxs("div",{className:"rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/50 px-3 py-2.5",children:[e.jsxs(je,{value:T,onValueChange:I,children:[e.jsx(Ne,{className:R(ce),"aria-label":"Node",children:oe?e.jsxs(e.Fragment,{children:[e.jsx(Vn,{isCurrent:ge}),e.jsx("span",{className:"max-w-[10rem] truncate",children:oe.name})]}):e.jsx(Pe,{placeholder:"Node"})}),e.jsx(ke,{children:_n(f,n)})]}),e.jsxs(je,{value:y,onValueChange:M=>A(M),children:[e.jsxs(Ne,{className:R(ce),"aria-label":"Agent",children:[e.jsx(Un,{agent:y}),e.jsx("span",{children:y})]}),e.jsx(ke,{children:ed()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(Ma,{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(rt,{value:F,onChange:M=>H(M.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(Fe,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:X?"Loading...":`${re.length} session${re.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-sm",children:[X&&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:[!T&&e.jsx("div",{className:"rounded-sm border border-dashed border-border/60 bg-background/35 px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Pick a node to load its recent sessions."}),T&&!X&&re.length===0&&e.jsx("div",{className:"rounded-sm border border-dashed border-border/60 bg-background/35 px-3 py-4 text-center text-[11px] text-muted-foreground",children:Q.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),G.map(M=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>J(M.cwd),"aria-expanded":!L.has(M.cwd),className:"sticky top-0 z-[1] flex w-full items-center gap-2 border-b border-border/50 bg-background/95 px-1 py-1.5 text-left text-[10px] text-muted-foreground backdrop-blur transition-colors hover:bg-background",children:[e.jsx(Je,{className:R("h-3.5 w-3.5 shrink-0 transition-transform",L.has(M.cwd)&&"-rotate-90")}),e.jsx(_s,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:M.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[M.sessions.length," session",M.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:M.cwd})]}),!L.has(M.cwd)&&M.sessions.map(W=>{const me=W.sessionId===h;return e.jsxs("button",{type:"button",onClick:()=>E(W.sessionId),className:R("flex w-full flex-col gap-1 rounded-sm border px-2.5 py-2 text-left transition-colors duration-200",me?"border-primary/45 bg-primary/9 shadow-none":"border-border/55 bg-background/40 hover:border-border hover:bg-background/65"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:R("h-2 w-2 shrink-0 rounded-full",me?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:W.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:Wc(W.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:W.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:W.cwd})]})]},W.sessionId)})]},M.cwd))]})]}),ne&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:ne})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>V(M=>!M),className:"inline-flex h-6 items-center gap-1.5 rounded-sm px-1.5 text-[10px] font-medium uppercase tracking-[0.16em] text-muted-foreground transition-colors hover:bg-muted/45 hover:text-foreground","aria-expanded":j,children:[e.jsx("span",{className:"shrink-0",children:j?"Less options":"More options"}),e.jsx(Je,{className:R("h-3.5 w-3.5 shrink-0 transition-transform",j&&"rotate-180")})]}),j&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/30 p-2.5",children:[e.jsxs("div",{className:"grid gap-2.5 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{htmlFor:"native-session-id",className:"text-[10px] font-medium text-muted-foreground",children:"Session ID"}),e.jsx(rt,{id:"native-session-id",type:"text",value:x,onChange:M=>{E(""),v(M.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:b,className:"h-7 rounded-sm border-border/70 bg-background/70 font-mono text-[11px] shadow-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{htmlFor:"native-session-title",className:"text-[10px] font-medium text-muted-foreground",children:"Task title"}),e.jsx(rt,{id:"native-session-title",type:"text",value:g,onChange:M=>N(M.target.value),placeholder:"Optional",className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none"})]})]}),e.jsx(Ss,{value:k,onChange:M=>{E(""),C(M)},assignTo:T,nodes:t,assignableNodes:f}),e.jsxs("div",{className:"grid gap-2.5 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-[10px] font-medium text-muted-foreground",children:"Mode"}),e.jsxs(je,{value:D,onValueChange:M=>_(M),children:[e.jsx(Ne,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx(Pe,{placeholder:"Select mode"})}),e.jsx(ke,{children:Gc()})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-[10px] font-medium text-muted-foreground",children:"Priority"}),e.jsxs(je,{value:S,onValueChange:P,children:[e.jsx(Ne,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx(Pe,{placeholder:"Select priority"})}),e.jsxs(ke,{children:[e.jsx(he,{value:"low",children:"Low"}),e.jsx(he,{value:"normal",children:"Normal"}),e.jsx(he,{value:"high",children:"High"}),e.jsx(he,{value:"critical",children:"Critical"})]})]})]})]})]})]}),e.jsxs("div",{className:R("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",d),children:[i&&e.jsx(Z,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:m}),e.jsx(Z,{type:"submit",disabled:!q||B,className:"rounded-sm px-5",children:B?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"})," Loading..."]}):c})]})]})}const Hs="__agent-default__";function uo({agent:t,value:s,onChange:n,triggerClassName:r,contentClassName:a="max-h-80",chip:i=!1}){const l=Ha(t,s);return o.useEffect(()=>{s&&!Wa(t,s)&&n("")},[t,s,n]),e.jsxs(je,{value:s||Hs,onValueChange:d=>n(d===Hs?"":d),children:[e.jsx(Ne,{"aria-label":`Model: ${l}`,title:`Model: ${l}`,className:r,children:i?e.jsxs(e.Fragment,{children:[e.jsx(Ja,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:l})]}):e.jsx(Pe,{placeholder:"Agent default"})}),e.jsxs(ke,{className:a,children:[e.jsx(he,{value:Hs,className:"py-1 text-[11px]",children:"Agent default"}),td(t)]})]})}function eu(t){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-[11px] font-medium",children:"Model"}),e.jsx(uo,{...t,triggerClassName:"h-8 rounded-sm border-border/70 bg-background/70"})]})}function mo(t,s,n=!1){const r=t.trim();if(r)return r;const a=s.trim().split(`
164
+ `).map(i=>i.trim()).find(Boolean);return a?a.length>72?`${a.slice(0,69).trimEnd()}...`:a:n?"Image task":""}function tu(t){const s=t.title.trim(),n=mo(t.title,t.description,t.images.length>0),r=t.description.trim()||n,a=t.mode??os,i=t.model?.trim(),l=i&&Wa(t.agent,i)?i:"",d=Va(t.description,t.images);return!n||!r||!t.agent?null:{title:n,description:r,agent:t.agent,project:t.project.trim()||null,branch:t.branch?.trim()||null,payload:{initialMessage:d,mode:a,...l?{model:l}:{},titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function su({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:d,className:c,footerClassName:m,submitLabel:b="Create chat",cancelLabel:f="Cancel",autoFocus:u=!1,layout:g="default",quickChats:N=[]}){const[y,A]=o.useState(""),[h,E]=o.useState(""),[x,v]=o.useState(0),[k,C]=o.useState(nr),[T,I]=o.useState(""),[S,P]=o.useState(os),[D,_]=o.useState(i?.trim()??""),B=o.useRef(i!==void 0),[z,Q]=o.useState(""),[Y,X]=o.useState("normal"),ee=o.useMemo(()=>co(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),ne=o.useMemo(()=>a&&ee.some(te=>te.id===a)?a:n&&ee.some(te=>te.id===n)?n:ee[0]?.id??"",[ee,n,a]),[U,O]=o.useState(ne),[p,q]=o.useState(!1),[j,V]=o.useState(!1),{images:F,error:H,fileInputRef:L,pickImages:ae,handleFileChange:oe,handlePaste:ge,removeImage:re}=ro(),G=o.useMemo(()=>ee.find(te=>te.id===U)??null,[U,ee]),J=!!(n&&G?.id===n),ce=Ga(k),M=sd(S);o.useEffect(()=>{U&&ee.some(te=>te.id===U)||O(ne)},[U,ee,ne]),o.useEffect(()=>{if(B.current){B.current=!1;return}_(lo(U)),Q("")},[U]),o.useEffect(()=>{Q("")},[D]),o.useEffect(()=>{v(0)},[h,N]);const W=o.useCallback(te=>{E(te.prompt)},[]),me=o.useCallback(async te=>{te.preventDefault();const ye=ws(h,N,x);if(ye){W(ye);return}const Se=tu({title:y,description:h,agent:k,model:T,project:D,branch:z,priority:Y,assignTo:U,mode:S,images:F});if(Se){q(!0);try{const He=await Li(Se);l(He)}catch(He){le.error(He instanceof Error?He.message:"Failed to create task")}finally{q(!1)}}},[y,h,k,T,D,z,Y,U,S,F,l,N,x,W]),be=mo(y,h,F.length>0),Ie=!!(be&&k&&U&&(h.trim()||F.length>0)),Re=o.useCallback(te=>{if(te.nativeEvent.isComposing)return;const ye=Ea(h,N);if(ye.length>0&&(te.key==="ArrowDown"||te.key==="ArrowUp")){te.preventDefault(),v(Se=>Aa(Se,ye.length,te.key==="ArrowDown"?1:-1));return}if(te.key==="Enter"){const Se=ws(h,N,x);if(Se&&!te.shiftKey){te.preventDefault(),W(Se);return}}te.key==="Enter"&&(te.ctrlKey||te.metaKey)&&Ie&&!p&&(te.preventDefault(),te.currentTarget.form?.requestSubmit())},[W,Ie,h,N,x,p]),ut=F.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:F.map((te,ye)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:nd(te),alt:te.filename??`attachment ${ye+1}`,className:"h-20 w-20 rounded-sm border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>re(ye),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 ${te.filename??`image ${ye+1}`}`,children:e.jsx(at,{className:"h-3.5 w-3.5"})})]},`${te.filename??"image"}-${ye}`))}),Ze=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-[11px] font-medium",children:"Assign to"}),e.jsxs(je,{value:U,onValueChange:O,children:[e.jsx(Ne,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select node"})}),e.jsx(ke,{children:_n(ee,n)})]})]}),qe=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-[11px] font-medium",children:"Agent"}),e.jsxs(je,{value:k,onValueChange:C,children:[e.jsx(Ne,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select agent"})}),e.jsx(ke,{children:mr()})]})]}),Te=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-[11px] font-medium",children:"Mode"}),e.jsxs(je,{value:S,onValueChange:te=>P(te),children:[e.jsx(Ne,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select mode"})}),e.jsx(ke,{children:hr()})]})]}),mt=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-[11px] font-medium",children:"Priority"}),e.jsxs(je,{value:Y,onValueChange:X,children:[e.jsx(Ne,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select priority"})}),e.jsxs(ke,{children:[e.jsx(he,{value:"low",children:"Low"}),e.jsx(he,{value:"normal",children:"Normal"}),e.jsx(he,{value:"high",children:"High"}),e.jsx(he,{value:"critical",children:"Critical"})]})]})]}),Xe=e.jsx(Ss,{value:D,onChange:_,assignTo:U,nodes:t,assignableNodes:ee}),Le=e.jsx(wr,{value:z,onChange:Q,project:D,assignTo:U,nodes:t,assignableNodes:ee});return g==="composer"?e.jsxs("form",{onSubmit:me,className:R("space-y-4",c),children:[e.jsx("input",{ref:L,type:"file",accept:"image/*",multiple:!0,onChange:oe,className:"hidden"}),(()=>{const te="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",ye="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",Se="border-border/70 bg-background/55 text-foreground",He=k===nr,Ke=S===os;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"chat-composer__card rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",children:[e.jsxs("div",{className:"chat-composer__header flex min-w-0 items-center justify-between gap-3 px-4 pt-3",children:[e.jsxs(je,{value:U,onValueChange:O,children:[e.jsx(Ne,{className:R(te,Se,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${G?.name??"unassigned"}`,"aria-label":`Assigned node: ${G?.name??"unassigned"}`,children:G?e.jsxs(e.Fragment,{children:[e.jsx(Vn,{isCurrent:J}),e.jsx("span",{className:"min-w-0 truncate",children:G.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:J?"current":"remote"})]}):e.jsx(Pe,{placeholder:"Select node"})}),e.jsx(ke,{children:_n(ee,n)})]}),j?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(rt,{id:"task-title-composer",type:"text",value:y,onChange:we=>A(we.target.value),onKeyDown:we=>{(we.key==="Enter"||we.key==="Escape")&&(we.preventDefault(),V(!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:()=>V(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(as,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>V(!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:be||"Title","aria-label":be?`Edit title: ${be}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:be||"Title"}),e.jsx(Ft,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:h,onChange:we=>E(we.target.value),onKeyDown:Re,onPaste:ge,placeholder:"Ask anything...",rows:4,autoFocus:u,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm bg-transparent px-5 pt-2 pb-2 text-xs leading-5 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsx(jn,{query:h,quickChats:N,selectedIndex:x,onActiveIndexChange:v,onSelect:W}),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:ae,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(En,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(je,{value:k,onValueChange:C,children:[e.jsxs(Ne,{className:R(te,"chat-composer__icon-trigger",He?ye:Se),title:`Agent: ${ce}`,"aria-label":`Agent: ${ce}`,children:[e.jsx(Un,{agent:k}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:ce})]}),e.jsx(ke,{children:mr()})]}),e.jsx(uo,{agent:k,value:T,onChange:I,chip:!0,triggerClassName:R(te,"chat-composer__icon-trigger",T?Se:ye),contentClassName:"max-h-80 shadow-none"}),e.jsxs(je,{value:S,onValueChange:we=>P(we),children:[e.jsxs(Ne,{className:R(te,"chat-composer__icon-trigger",Ke?ye:Se),title:`Mode: ${M}`,"aria-label":`Mode: ${M}`,children:[e.jsx(sc,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:M})]}),e.jsx(ke,{children:hr()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(je,{value:Y,onValueChange:X,children:[e.jsx(Ne,{"aria-label":`Priority: ${Y}`,title:`Priority: ${Y}`,className:R("h-9 w-9 justify-center gap-0 rounded-sm p-0 text-xs shadow-none [&>svg:last-child]:hidden",Y==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",Y==="critical"&&"text-destructive",Y==="high"&&"text-amber-600 dark:text-amber-400",Y==="low"&&"text-muted-foreground"),children:e.jsx(_d,{className:R("h-4 w-4",Y==="critical"&&"fill-destructive/20")})}),e.jsxs(ke,{children:[e.jsx(he,{value:"low",children:"Low"}),e.jsx(he,{value:"normal",children:"Normal"}),e.jsx(he,{value:"high",children:"High"}),e.jsx(he,{value:"critical",children:"Critical"})]})]}),d&&e.jsxs(Z,{type:"button",variant:"ghost",size:"sm",onClick:d,"aria-label":f,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(at,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:f})]}),e.jsxs(Z,{type:"submit",size:"icon",disabled:!Ie||p,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[p?e.jsx(ue,{className:"h-4 w-4 animate-spin"}):e.jsx(eo,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:p?"Creating chat":b})]})]})]})]}),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(Ss,{value:D,onChange:_,assignTo:U,nodes:t,assignableNodes:ee,layout:"composer",chipClassName:te,chipActiveClassName:we,chipInactiveClassName:we,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(wr,{value:z,onChange:Q,project:D,assignTo:U,nodes:t,assignableNodes:ee,layout:"composer",chipClassName:te,chipActiveClassName:we,chipInactiveClassName:we,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(ut||H)&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/45 p-2.5",children:[ut,H&&e.jsx("div",{className:"text-[11px] text-destructive",children:H}),!H&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Ctrl/Cmd+Enter starts the chat. Enter adds a new line. Paste screenshots directly into the prompt box or use the Images button."})]})]}):e.jsxs("form",{onSubmit:me,className:R("space-y-4",c),children:[e.jsx("input",{ref:L,type:"file",accept:"image/*",multiple:!0,onChange:oe,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{htmlFor:"task-description",className:"text-[11px] font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:h,onChange:te=>E(te.target.value),onKeyDown:Re,onPaste:ge,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:u,className:"flex min-h-[128px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm border border-border/70 bg-background/70 px-3 py-2 text-xs leading-5 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"}),e.jsx(jn,{query:h,quickChats:N,selectedIndex:x,onActiveIndexChange:v,onSelect:W}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Z,{type:"button",variant:"outline",onClick:ae,className:"rounded-sm",children:[e.jsx(En,{className:"h-4 w-4"}),"Add images"]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Ctrl/Cmd+Enter starts the chat. Enter adds a new line. Upload or paste screenshots and reference images with the opening prompt."})]}),ut,H&&e.jsx("p",{className:"text-[11px] text-destructive",children:H})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_170px_190px_150px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{htmlFor:"task-title",className:"text-[11px] font-medium",children:"Chat title"}),e.jsx(rt,{id:"task-title",type:"text",value:y,onChange:te=>A(te.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-8 rounded-sm border-border/70 bg-background/70"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:be?`Will appear as: ${be}`:"A title will be generated from the first line of the prompt."})]}),qe,e.jsx(eu,{agent:k,value:T,onChange:I}),Te]}),Xe,Le,e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[mt,Ze]}),e.jsxs("div",{className:R("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",m),children:[d&&e.jsx(Z,{type:"button",variant:"ghost",onClick:d,className:"rounded-sm",children:f}),e.jsx(Z,{type:"submit",disabled:!Ie||p,className:"rounded-sm px-5",children:p?"Creating...":b})]})]})}function nu({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:d,defaultMode:c="chat",mode:m,onModeChange:b,layout:f="default",className:u,footerClassName:g,autoFocus:N=!1,quickChats:y=[]}){const[A,h]=o.useState(c),E=m!==void 0,x=E?m:A,v=k=>{E||h(k),b?.(k)};return e.jsxs("div",{className:R("space-y-4",u),children:[!E&&e.jsxs("div",{className:"flex h-8 items-center gap-0.5 rounded-sm border border-border/60 bg-background/45 p-0.5",children:[e.jsxs(Z,{type:"button",variant:x==="chat"?"default":"ghost",onClick:()=>v("chat"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(Ii,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(Z,{type:"button",variant:x==="native"?"default":"ghost",onClick:()=>v("native"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx($n,{className:"h-4 w-4"}),"Load session"]})]}),x==="chat"?e.jsx(su,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:d,footerClassName:g,submitLabel:f==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:N,layout:f,quickChats:y},`${a??""}:${i??""}`):e.jsx(Xc,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:l,onCancel:d,footerClassName:g,autoFocus:N})]})}function ru({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:R("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(Ft,{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 jr({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 au({hasVisibleTranscriptEvents:t,hasTranscriptProgress:s,inputCollapsed:n}){return{collapsedButtonRunning:s&&t&&n,showDockedProgress:s&&t&&!n,showInlineProgress:s&&!t}}const Pt="72f988bf-86f1-41af-91ab-2d7cd011db47",ho=`${Pt} (MSIT)`;function ou({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i=!1,shareResult:l}){return e.jsx(yt,{open:t,onOpenChange:s,children:e.jsxs(jt,{className:"max-w-md rounded-sm p-4",children:[e.jsx(Ot,{className:"sr-only",children:"Share conversation"}),e.jsx(iu,{onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i,shareResult:l})]})})}function iu({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:a=!1,shareResult:i}){const[l,d]=o.useState(i?.tenant??Pt),[c,m]=o.useState(i?.scope??"chat"),b=i?.url?Pa(i.url):null,f=r||a;return o.useEffect(()=>{d(i?.tenant??Pt),m(i?.scope??"chat")},[i?.shareId,i?.tenant,i?.scope]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-sm font-semibold leading-none tracking-tight",children:"Share conversation"}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:"Create a tenant-gated link for this task."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(lu,{value:l,onChange:d,disabled:f}),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(Nr,{active:c==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>m("chat")}),e.jsx(Nr,{active:c==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>m("filesPreview")})]})]}),b&&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:b,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:()=>{Cs(b,"Shared link copied")},"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ia,{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:f,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(Z,{variant:"outline",onClick:()=>{n()},disabled:f,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[a&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(Z,{onClick:()=>{s({tenant:l,scope:c})},disabled:f,className:"h-8 text-xs",children:[r&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function lu({value:t,onChange:s,disabled:n}){const[r,a]=o.useState(!1),[i,l]=o.useState(!1),[d,c]=o.useState(t),m=o.useRef(null);o.useEffect(()=>{c(t)},[t]),o.useEffect(()=>{if(!r)return;const f=g=>{const N=g.target;N instanceof Node&&(m.current?.contains(N)||(a(!1),l(!1)))},u=g=>{g.key==="Escape"&&(a(!1),l(!1))};return document.addEventListener("mousedown",f),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",u)}},[r]);const b=f=>{const u=f.trim();u&&(s(u),c(u),l(!1),a(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:m,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&a(f=>!f),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:du(t)}),e.jsx(Je,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),r&&e.jsxs("div",{className:"absolute left-0 right-0 z-50 mt-2 overflow-hidden rounded-sm border border-border/60 bg-background/95 text-xs shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",children:[e.jsxs("button",{type:"button",onClick:()=>b(Pt),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:ho}),t===Pt&&e.jsx(as,{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:d,onChange:f=>c(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),b(d))},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:()=>b(d),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(as,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{c(t),l(!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(at,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>l(!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(Ft,{className:"h-3 w-3"})]})})]})]})]})}function du(t){return t===Pt?ho:t}function Nr({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 cu(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 uu({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(Vd,{className:"h-3.5 w-3.5 text-primary"}),"Queued messages",e.jsx("span",{className:"ml-auto rounded-sm border border-border/60 bg-muted/60 px-1.5 py-0 text-[10px] text-muted-foreground",children:t.length})]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:t.map((n,r)=>{const a=n.content.filter(i=>i.type==="image");return e.jsxs("div",{className:"flex min-w-0 items-start gap-2 text-[11px] leading-5 text-muted-foreground",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-[10px] font-medium text-primary",children:r+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"break-words [overflow-wrap:anywhere]",children:cu(n.content)}),a.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:a.map((i,l)=>e.jsx(Ka,{image:i,alt:i.filename??`queued attachment ${l+1}`,thumbnailClassName:"h-14 w-14 border border-border/65",imageClassName:"h-full w-full"},`${i.filename??"image"}-${l}`))})]}),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(at,{className:"h-3 w-3"})})]},n.id)})})]})})}const mu="h-6 w-6 rounded-none border-b border-transparent !bg-transparent p-0 text-muted-foreground !shadow-none hover:text-foreground data-[state=active]:border-primary data-[state=active]:!bg-transparent data-[state=active]:text-primary data-[state=active]:!shadow-none",hu=[{value:"transcript",label:"Transcript",icon:Ri},{value:"files",label:"Files",icon:Bt,activeIcon:_s},{value:"diff",label:"Diff",icon:js},{value:"preview",label:"Preview",icon:hd}];function fu({activeTab:t}){return e.jsx(Rn,{className:"h-auto max-w-full justify-start gap-2 overflow-x-auto rounded-sm !bg-muted/40 !p-0.5 !shadow-none",children:hu.map(s=>{const n=s.value===t&&s.activeIcon?s.activeIcon:s.icon;return e.jsx(vt,{value:s.value,title:s.label,"aria-label":s.label,className:mu,children:e.jsx(n,{className:"h-3.5 w-3.5","aria-hidden":"true"})},s.value)})})}const kr="h-[1.625rem] rounded-sm !border-0 !bg-transparent px-2 text-[10.5px] font-medium text-primary !shadow-none hover:!bg-transparent hover:text-primary/80 focus-visible:ring-1 focus-visible:ring-ring/50 focus-visible:ring-offset-0",bt={content:"max-w-[20rem] gap-2.5 rounded-lg border-0 p-3.5 shadow-[0_18px_70px_-44px_rgba(0,0,0,0.72)] sm:max-w-[20rem]",header:"space-y-1 text-left",title:"text-[13px] leading-4",description:"text-[11px] leading-4",footer:"gap-1 pt-0 sm:space-x-1",cancel:`${kr} mt-0`,action:kr},xu=30,pu=1600;function gu({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Ks(t){return t.scrollHeight-t.scrollTop-t.clientHeight<xu}function Sr({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function Gs(t,s){return!!(s&&(t===s||t.contains(s)))}function Ws(t){const s=t.ownerDocument.getSelection();if(!s||s.isCollapsed||s.rangeCount===0)return!1;if(Gs(t,s.anchorNode)||Gs(t,s.focusNode))return!0;for(let n=0;n<s.rangeCount;n+=1)if(Gs(t,s.getRangeAt(n).commonAncestorContainer))return!0;return!1}function bu({atTop:t,inputCollapseDisabled:s,scrollingUp:n}){return!s&&(n||t)}function vu({activeTab:t,activeTaskId:s,contentVersion:n,inputCollapseDisabled:r=!1,setActiveTab:a,setInputCollapsed:i}){const l=o.useRef(null),d=o.useRef(s),c=o.useRef(!1),m=o.useRef(0),b=o.useRef(new Map),f=o.useRef(0),u=o.useRef(!0),g=o.useCallback((x=d.current)=>{const v=l.current;!v||!x||(b.current.set(x,v.scrollTop),m.current=v.scrollTop,u.current=Ks(v))},[]),N=o.useCallback((x=d.current)=>{const v=l.current;!v||!x||(v.scrollTop=gu({savedScrollTop:b.current.get(x),scrollHeight:v.scrollHeight,clientHeight:v.clientHeight}),m.current=v.scrollTop,u.current=Ks(v))},[]),y=o.useCallback((x,v=d.current)=>{x.scrollTop=x.scrollHeight,m.current=x.scrollTop,u.current=!0,v&&b.current.set(v,x.scrollTop)},[]),A=o.useCallback((x=d.current)=>{const v=l.current;f.current=Date.now()+pu,v&&(y(v,x),requestAnimationFrame(()=>{y(v,x),requestAnimationFrame(()=>y(v,x))}))},[y]),h=o.useCallback(x=>{const v=x.currentTarget,k=m.current,C=v.scrollTop<k&&k-v.scrollTop>10,T=v.scrollTop<=0,I=Ws(v);if(g(),I){f.current=0;return}if(!c.current){if(Ks(v)){i(!1),c.current=!0,setTimeout(()=>{c.current=!1},300);return}(C||T)&&(f.current=0,bu({atTop:T,inputCollapseDisabled:r,scrollingUp:C})&&i(!0))}},[r,g,i]),E=o.useCallback(x=>{t==="transcript"&&g(),a(x),x==="transcript"&&requestAnimationFrame(()=>N())},[t,N,g,a]);return o.useLayoutEffect(()=>{r&&i(!1)},[r,i]),o.useLayoutEffect(()=>{const x=d.current;x&&x!==s&&g(x),d.current=s,t==="transcript"&&requestAnimationFrame(()=>N(s))},[s,t,N,g]),o.useLayoutEffect(()=>{const x=l.current;if(!x||t!=="transcript"||!s)return;const v=Sr({explicitBottomStickUntil:f.current,now:Date.now(),wasAtBottom:u.current});if(Ws(x)){f.current=0,g(s);return}v&&y(x,s),g(s)},[s,t,n,g,y]),o.useLayoutEffect(()=>{const x=l.current,v=x?.firstElementChild;if(!x||!v||t!=="transcript"||typeof ResizeObserver>"u")return;const k=new ResizeObserver(()=>{if(Ws(x)){f.current=0,g();return}Sr({explicitBottomStickUntil:f.current,now:Date.now(),wasAtBottom:u.current})?y(x):g()});return k.observe(x),k.observe(v),()=>k.disconnect()},[t,s,g,y]),{handleTranscriptScroll:h,handleTranscriptTabChange:E,scrollTranscriptToBottom:A,transcriptScrollRef:l}}function fo(t=700){const[s,n]=o.useState(!1),r=o.useRef(null),a=o.useCallback(()=>{n(!0),r.current!==null&&clearTimeout(r.current),r.current=setTimeout(()=>{n(!1),r.current=null},t)},[t]);return o.useEffect(()=>()=>{r.current!==null&&clearTimeout(r.current)},[]),{markScrollbarActive:a,scrollbarActive:s}}const Hn="pointer-events-auto h-5 w-5 shrink-0 rounded-full bg-muted/65 text-muted-foreground hover:bg-muted hover:text-foreground",It="h-3.5 w-3.5",wu=o.lazy(async()=>({default:(await On(()=>import("./FilesTab-RR7aUMed.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),yu=o.lazy(async()=>({default:(await On(()=>import("./PreviewTab-DO689Vk0.js").then(s=>s.c),__vite__mapDeps([6,1,2]))).PreviewTab})),ju=o.lazy(async()=>({default:(await On(()=>import("./DiffTab-WaSKUZxb.js"),__vite__mapDeps([7,1,2,5,4,3,6]))).DiffTab}));function Nu({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,sseConnected:l,activeTab:d,setActiveTab:c,creatingTask:m,createMode:b,createDefaults:f,activeTask:u,assignedNode:g,taskLoading:N,transcriptLoading:y,taskError:A,displayEvents:h,initialPromptAlreadyInLogs:E,initialPrompt:x,supportsFollowUp:v,taskUnavailable:k,chatDisabled:C,chatDisabledReason:T,questionBypassEnabled:I,isRunning:S,isStarting:P,hasPendingFollowUp:D,canCancel:_,canRetry:B,onRetry:z,onCancel:Q,onReloadNativeTranscript:Y,onShareTask:X,onStopShareTask:ee,onStartCreateTask:ne,onCancelCreateTask:U,onCreateTask:O,onSendMessage:p,onCancelQueuedMessage:q,onQuestionBypassChange:j,onSubmitQuestionResponse:V,quickChats:F=[]}){const[H,L]=o.useState(!1),[ae,oe]=o.useState(!1),[ge,re]=o.useState(!1),[G,J]=o.useState(!1),[ce,M]=o.useState(!1),[W,me]=o.useState({}),[be,Ie]=o.useState(new Set),[Re,ut]=o.useState(new Set),[Ze,qe]=o.useState(null),Te=u?.effectiveProjectPath??u?.project??"default workspace",mt=u?g?.name??Nn(u.assignedTo,i?.nodes,u.assignedNodeName):"unassigned",Xe=u?.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:mt}),"..."]}):"Connecting session to an available node...",Le=u?[{label:"Working dir",value:Te,mono:!0},...u.branch?[{label:"Branch",value:u.branch,mono:!0}]:[],{label:"Agent",value:u.agent,mono:!0},{label:"Node",value:mt}]:[],te=!!(x&&!E),ye=te||h.length>0,Se=S&&ye,He=(P||D||S)&&!Se,Ke=Se?"The agent is still working on this conversation.":He?Xe:null,{collapsedButtonRunning:we,showDockedProgress:St,showInlineProgress:ze}=au({hasTranscriptProgress:!!Ke,hasVisibleTranscriptEvents:ye,inputCollapsed:H}),ot=u?.conversationKind==="nativeSession",Ce=y?"Loading transcript":ot?"No transcript imported":"Transcript is warming up",Ut=y?"Loading transcript...":ot?"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.",Ct=u?.queuedMessages??[],K=o.useMemo(()=>rd(h),[h]),Ee=o.useMemo(()=>ad("transcript",K.map(de=>de.event)),[K]),Ae=u&&!be.has(u.id)?W[u.id]??u.activeShare??null:null,it=u?.id??null,$t=`${it??"none"}:${h.length}:${Ct.length}:${te?1:0}:${y?1:0}:${ze?1:0}`,{handleTranscriptScroll:Tt,handleTranscriptTabChange:De,scrollTranscriptToBottom:Ve,transcriptScrollRef:Et}=vu({activeTab:d,activeTaskId:it,contentVersion:$t,inputCollapseDisabled:!!Ke,setActiveTab:c,setInputCollapsed:L}),{markScrollbarActive:ht,scrollbarActive:lt}=fo(),At=o.useCallback(de=>{ht(),Tt(de)},[Tt,ht]),gt=o.useCallback(de=>{qe(Me=>({path:de,requestId:(Me?.requestId??0)+1})),De("files")},[De]),_e=o.useCallback(de=>{Ve(),p(de)},[p,Ve]);return o.useEffect(()=>{qe(null)},[it]),m?e.jsx(ku,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,sseConnected:l,defaultMode:b,createDefaults:f,onCancel:U,onCreated:O,quickChats:F}):!u&&N?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(Mn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,sseConnected:l})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"space-y-3 text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(ue,{className:"h-5 w-5 animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm font-semibold tracking-tight text-foreground",children:"Loading conversation"}),e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):u?e.jsxs(Bn,{value:d,onValueChange:De,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(xo,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:a,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:R(Hn,"xl:hidden"),children:r?e.jsx(We,{className:It}):e.jsx(ls,{className:It})})]}),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:u.title,children:u.title}),e.jsx(La,{status:u.status,isNative:ot}),u.priority!=="normal"&&e.jsx(Oi,{priority:u.priority})]}),A&&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:A}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx(fu,{activeTab:d}),k&&e.jsx($e,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"hidden rounded-sm bg-muted/65 px-1.5 py-0.5 tabular-nums sm:inline-flex",children:Fi(u.updatedAt)}),B&&e.jsxs(Z,{variant:"ghost",size:"sm",onClick:z,"aria-label":"Retry task",title:"Retry task",className:"h-7 shrink-0 rounded-sm border-0 bg-primary/10 px-2 text-[10px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[e.jsx(Jd,{className:"h-3.5 w-3.5"}),"Retry"]}),ot&&Y&&e.jsx(Z,{variant:"ghost",size:"icon",onClick:Y,disabled:y,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(Xa,{className:R("h-3.5 w-3.5",y&&"animate-spin")})}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",disabled:k,title:k?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":k?"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:()=>re(!0),children:e.jsx(ks,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(ct,{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:Et,"data-transcript-scroll":"true",className:R("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",lt&&"scrollbar-line-active"),onScroll:At,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[te&&x&&e.jsx(fr,{event:x,agent:u.agent,taskRootPath:u.effectiveProjectPath,onOpenFilePath:gt,questionBypassEnabled:I,onQuestionBypassChange:j,onSubmitQuestionResponse:V,questionResponseDisabled:!v||C}),K.map(({event:de,subItems:Me},Be)=>e.jsx(fr,{event:de,agent:u.agent,subItems:Me,taskRootPath:u.effectiveProjectPath,onOpenFilePath:gt,questionBypassEnabled:I,onQuestionBypassChange:j,onSubmitQuestionResponse:V,questionResponseDisabled:!v||C},Ee[Be])),!ye&&!He&&e.jsxs("div",{className:"rounded-sm border border-dashed border-border/70 bg-background/35 px-3 py-4 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:Ce}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Ut})]}),(!v&&u.result||u.error)&&e.jsxs("div",{className:"space-y-3",children:[!v&&u.result&&e.jsxs("div",{className:"rounded-sm border border-border/70 bg-card/80 px-3 py-3",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:"Stored result"}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5 text-muted-foreground",children:JSON.stringify(u.result,null,2)})]}),u.error&&!Re.has(u.id)&&e.jsxs("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-3 text-destructive",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em]",children:"Stored error"}),e.jsx("button",{onClick:()=>ut(de=>new Set(de).add(u.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(at,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5",children:u.error})]})]}),ze&&Ke&&e.jsx(jr,{children:Ke})]})})}),St&&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(jr,{children:Ke})})}),v?e.jsxs(e.Fragment,{children:[H&&e.jsx(ru,{running:we,onClick:()=>{L(!1),Ve(),requestAnimationFrame(()=>document.querySelector('[data-chat-input-textarea="true"]')?.focus())}}),e.jsxs("div",{className:`shrink-0 ${H?"hidden":""}`,children:[e.jsx(uu,{messages:Ct,onCancelMessage:q}),e.jsx(Cc,{onSend:_e,disabled:C,disabledReason:T,contextItems:Le,agent:u.agent,model:typeof u.payload.model=="string"?u.payload.model:null,placeholder:C?T:S?"Queue a message for the next turn...":"Continue the conversation...",running:S||D,onStop:_?()=>oe(!0):void 0,quickChats:F})]})]}):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(ct,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading files..."}),children:e.jsx(wu,{taskId:u.id,requestedFilePath:Ze?.path??null,requestedFileRequestId:Ze?.requestId??0})})}),e.jsx(ct,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading preview..."}),children:e.jsx(yu,{taskId:u.id})})}),e.jsx(ct,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading diff..."}),children:e.jsx(ju,{taskId:u.id})})}),e.jsx(Yt,{open:ae,onOpenChange:oe,children:e.jsxs(Jt,{className:bt.content,children:[e.jsxs(Zt,{className:bt.header,children:[e.jsx(Xt,{className:bt.title,children:"Stop this task?"}),e.jsx(es,{className:bt.description,children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ts,{className:bt.footer,children:[e.jsx(ss,{className:bt.cancel,children:"Keep running"}),e.jsx(ns,{className:bt.action,onClick:Q,children:"Stop task"})]})]})}),e.jsx(ou,{open:ge,onOpenChange:re,sharing:G,stopping:ce,shareResult:Ae,onShare:async de=>{if(!u)return null;J(!0);try{const Me=await X(de);return Me?.url&&(me(Be=>({...Be,[u.id]:Me})),Ie(Be=>{const Ue=new Set(Be);return Ue.delete(u.id),Ue})),Me}finally{J(!1)}},onStopShare:async()=>{if(!u)return!1;M(!0);try{const de=await ee();return de!==!1&&(me(Me=>{const Be={...Me};return delete Be[u.id],Be}),Ie(Me=>new Set(Me).add(u.id))),de}finally{M(!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(Mn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,sseConnected:l})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"w-full max-w-lg text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(Bi,{className:"h-5 w-5"})}),e.jsx("h2",{className:"mt-3 text-sm font-semibold tracking-tight text-foreground sm:text-[15px]",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-2 max-w-md text-[11px] leading-5 text-muted-foreground",children:"Open a task from the left sidebar to continue the conversation, or start a new task or load a native session."}),e.jsxs(Z,{onClick:()=>ne(),className:"mt-4 h-8 rounded-sm px-3",children:[e.jsx(Ms,{className:"h-3.5 w-3.5"}),"Start or load chat"]}),A&&e.jsx("div",{className:"mx-auto mt-3 max-w-md rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:A})]})})]})}function ku({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,sseConnected:l,defaultMode:d,createDefaults:c,onCancel:m,onCreated:b,quickChats:f}){const[u,g]=o.useState(d??"chat");o.useEffect(()=>{d&&g(d)},[d]);const N=e.jsx("div",{className:"flex h-8 items-center gap-0.5 overflow-hidden rounded-sm border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-none",children:[{value:"chat",label:"New chat",icon:Ms},{value:"native",label:"Load session",icon:$n}].map(y=>{const A=y.icon,h=y.value===u;return e.jsxs("button",{type:"button",onClick:()=>g(y.value),"aria-pressed":h,className:R("flex h-7 min-w-28 items-center justify-center gap-1.5 rounded-sm border border-transparent px-2.5 transition-colors duration-150",h?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(A,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:y.label})]},y.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(Mn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,sseConnected:l,centerSlot:N})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(nu,{nodes:i?.nodes??[],currentNodeRole:i?.self?.role,currentNodeId:i?.self?.id??null,leaderNodeId:i?.leader?.id??null,initialAssignTo:c?.assignTo,initialProject:c?.project,mode:u,onModeChange:g,onCreated:b,onCancel:m,autoFocus:!0,layout:"composer",quickChats:f})})})]})}function Mn({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,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(xo,{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:a,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:R(Hn,"xl:hidden"),children:r?e.jsx(We,{className:It}):e.jsx(ls,{className:It})})]})}function xo({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){const a=globalThis.window?.matchMedia("(min-width: 1024px)")?.matches?s:n;return e.jsx(Z,{variant:"ghost",size:"icon",onClick:r,title:a?"Hide tasks":"Show tasks","aria-label":a?"Hide tasks":"Show tasks",className:R(Hn,t),children:a?e.jsx(ls,{className:It}):e.jsx(We,{className:It})})}function Su({onAdded:t}){const[s,n]=o.useState(""),[r,a]=o.useState(!1),[i,l]=o.useState(null),d=o.useCallback(async c=>{if(c.preventDefault(),!!s.trim()){a(!0),l(null);try{await zi({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(m){l(m instanceof Error?m.message:"Failed to join node")}finally{a(!1)}}},[s,t]);return e.jsx(jt,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-sm border border-border/60 bg-background/95 p-0 shadow-[0_28px_90px_-58px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-3.5 py-2.5",children:e.jsxs(Ts,{className:"space-y-1 text-left",children:[e.jsx(Ot,{className:"text-sm tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Verify the remote leader's DevTunnel endpoint, sync this node's tasks to that leader, and join the cluster as a follower."})]})}),e.jsxs("form",{onSubmit:d,className:"space-y-3 px-3.5 py-3",children:[i&&e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Fe,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx($e,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(rt,{id:"leader-endpoint",type:"url",value:s,onChange:c=>n(c.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-8 rounded-sm border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-sm border border-border/60 bg-background/45 px-3 py-2 text-[11px] text-muted-foreground",children:"This does not switch the local node transport or auto-enable a local DevTunnel. Leaving later will detach this node from the remote leader and make it leader of its own cluster again."}),e.jsx(Ra,{className:"border-t border-border/60 pt-3",children:e.jsx(Z,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function Cu({open:t,onOpenChange:s,onAdded:n}){return e.jsx(yt,{open:t,onOpenChange:s,children:e.jsx(Su,{onAdded:()=>{s(!1),n()}})})}const Tu="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",Eu="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",Au="h-2.5 w-2.5";function po({className:t,label:s,orientation:n,panel:r,panelResize:a}){return e.jsx("button",{type:"button","aria-label":s,"aria-orientation":n,"data-dashboard-resize-handle":r,onPointerDown:i=>a.onPointerDown(r,i),onWheel:i=>a.onWheel(r,i),className:R("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 Du({className:t,label:s,onToggle:n,side:r,visible:a}){const i=r==="left"?a?ls:We:a?We:ls;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:R(Tu,t),children:e.jsx("span",{className:Eu,"aria-hidden":"true",children:e.jsx(i,{className:Au,strokeWidth:2.1})})})}function Cr({className:t,label:s,onToggle:n,panel:r,panelResize:a,screen:i,side:l,visible:d}){const c=i==="lg"?"lg:block":"xl:block",m=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:R("group absolute top-0 z-30 hidden h-full w-4",c,t),children:[r&&e.jsx(po,{panel:r,orientation:"vertical",label:`Resize ${r} panel`,panelResize:a,className:"left-1/2 top-0 h-full w-2 -translate-x-1/2 cursor-col-resize"}),e.jsx(Du,{side:l,visible:d,label:s,onToggle:n,className:R(m,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function _u({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:a,operationsOpen:i,operationsPanelRef:l,operationsSidecar:d,panelResize:c,taskSidebar:m,terminalPanel:b,onCloseOperations:f,onCloseTaskList:u,onToggleOperations:g,onToggleTasks:N}){const y={"--dashboard-tasks-width":c.sizes.tasks,"--dashboard-operations-width":c.sizes.operations,"--dashboard-terminal-height":c.sizes.terminal};return e.jsxs("div",{className:"dashboard-workspace flex h-full min-h-0 flex-col overflow-hidden",style:y,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(Cr,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:N,panel:s?"tasks":void 0,panelResize:c,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:R("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&&m}),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}),b&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(po,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:c,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),b]})]}),e.jsx(Cr,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:g,panel:i?"operations":void 0,panelResize:c,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:R("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&&d})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:f,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:l,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:d})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:u,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:a,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 Mu=10,wt="__all__";function Qe(t){return"session"in t}function Tr(t,s){return s&&t.some(n=>n.id===s)?s:t[0]?.id??""}function Qs(t){return t&&(lo(t.id)||t.workDir)||""}function xs(t,s,n){let r=!1;const a=t.map(i=>Qe(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return Pn(r?a:[...a,{id:`session-${n.id}`,nodeName:s,session:n}])}function go(t,s){return t.filter(Qe).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function Pu(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 Iu(t,s){return!!(t&&s&&!t.contains(s))}function Lu(t,s,n){if(n===wt)return n;const r=go(t,s);return r.some(a=>a.session.id===n)?n:r[0]?.session.id??wt}function Ru(t,s,n){return n===wt?t.filter(r=>!Qe(r)||r.session.nodeId===s):t.filter(r=>Qe(r)&&r.session.nodeId===s&&r.session.id===n)}function Pn(t){const s=t.map((r,a)=>({entry:r,index:a})).filter(({entry:r})=>Qe(r)&&r.session.status!=="running").sort((r,a)=>!Qe(r.entry)||!Qe(a.entry)?0:a.entry.session.startedAt-r.entry.session.startedAt||a.index-r.index),n=new Set(s.slice(0,Mu).map(({entry:r})=>Qe(r)?r.session.id:""));return t.filter(r=>!Qe(r)||r.session.status==="running"||n.has(r.session.id))}function In(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 Bu(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${In(t.session)} - ${s}`}function bo(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function Ou(t,s){return s===wt?"All sessions":t?bo(t.session.command,34):"Command session"}function Er(t){return t.status==="stopped"?"":t.stderr}function Fu({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[a,i]=o.useState(()=>Tr(t,s)),l=o.useMemo(()=>t.find(j=>j.id===a)??t[0]??null,[t,a]),[d,c]=o.useState(()=>Qs(l)),[m,b]=o.useState(""),[f,u]=o.useState(()=>Pn(r)),[g,N]=o.useState(wt),[y,A]=o.useState(!1),[h,E]=o.useState(!1),[x,v]=o.useState(!1),[k,C]=o.useState(!1),[T,I]=o.useState(!1),S=o.useRef(null),P=o.useRef(null),D=o.useMemo(()=>t.find(j=>j.id===a)??t[0]??null,[t,a]),_=o.useMemo(()=>go(f,D?.id??""),[f,D]),B=o.useMemo(()=>Pu(_),[_]),z=o.useMemo(()=>_.find(j=>j.session.id===g),[g,_]),Q=o.useMemo(()=>Ru(f,D?.id??"",g),[f,D,g]),Y=o.useRef(D?.id??"");o.useEffect(()=>{a&&t.some(j=>j.id===a)||i(Tr(t,s))},[s,t,a]),o.useEffect(()=>{const j=D?.id??"";Y.current!==j&&(Y.current=j,c(Qs(D)))},[D]),o.useEffect(()=>{N(j=>Lu(f,D?.id??"",y?j:""))},[f,D,y]),o.useEffect(()=>{S.current?.scrollTo({top:S.current.scrollHeight})},[f]),o.useEffect(()=>{let j=!1;async function V(){const F=await Promise.allSettled(t.map(async H=>({node:H,response:await $i(H.id)})));j||u(H=>F.reduce((L,ae)=>ae.status!=="fulfilled"?L:ae.value.response.sessions.reduce((oe,ge)=>xs(oe,ae.value.node.name,ge),L),H))}return t.length>0&&V(),()=>{j=!0}},[t]),o.useEffect(()=>{const j=f.filter(Qe).filter(F=>F.session.status==="running");if(j.length===0)return;const V=window.setInterval(()=>{for(const F of j)Ui(F.session.nodeId,F.session.id).then(H=>u(L=>xs(L,F.nodeName,H))).catch(()=>{})},1e3);return()=>window.clearInterval(V)},[f]);const X=o.useRef(null);async function ee(j){if(j.preventDefault(),!D||!m.trim()||T)return;const V=m.trim(),F=D.name;I(!0),b("");try{const H=await Vi(D.id,{command:V,...d.trim()?{cwd:d.trim()}:{}});u(L=>xs(L,F,H)),N(H.id),A(!0)}catch(H){u(L=>[...L,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:F,command:V,error:H instanceof Error?H.message:"Command failed"}])}finally{I(!1)}}async function ne(j,V){j.stopPropagation();const F=await qi(V.session.nodeId,V.session.id);u(H=>xs(H,V.nodeName,F))}function U(j){N(j),A(!0),E(!1)}function O(j){h&&Iu(P.current,j.target)&&E(!1)}function p(j,V,F,H,L){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:H,"aria-label":`Toggle ${j} sessions`,"aria-expanded":!F,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:j}),e.jsx(Je,{className:R("h-3 w-3 transition-transform",F&&"-rotate-90")})]}),!F&&(V.length>0?V.map(q):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:L}))]})}function q(j){const V=g===j.session.id,F=j.session.status==="running";return e.jsxs("div",{className:R("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",V&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>U(j.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:R("flex h-4 w-4 shrink-0 items-center justify-center",F?"text-primary":j.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:F?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):j.session.status==="exited"?e.jsx(ar,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:bo(j.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[j.nodeName," · ",In(j.session)]})]})]}),F&&e.jsx("button",{type:"button",onClick:H=>{ne(H,j)},"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(gr,{className:"h-3 w-3"})})]},j.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:O,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(at,{className:"h-3.5 w-3.5"})}):e.jsx(rr,{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:P,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":h,title:z?Bu(z):"All sessions",onClick:()=>E(j=>!j),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:Ou(z,g)}),e.jsx(Je,{className:R("h-3 w-3 shrink-0 text-muted-foreground transition-transform",h&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!h,className:R("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!h&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>U(wt),className:R("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",g===wt&&"bg-primary/10 text-primary"),children:[e.jsx(rr,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),p("Active",B.active,x,()=>v(j=>!j),"No active sessions"),p("Completed",B.completed,k,()=>C(j=>!j),"No completed sessions")]})})]}),e.jsx("select",{value:D?.id??"",onChange:j=>{i(j.target.value),A(!1),c(Qs(t.find(V=>V.id===j.target.value)??null))},disabled:T||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(j=>e.jsx("option",{value:j.id,className:"bg-background text-foreground",children:j.name},j.id))}),e.jsx(Ss,{value:d,onChange:c,assignTo: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:S,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>X.current?.focus(),children:[Q.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:Q.map(j=>Qe(j)?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:[j.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:j.session.command}),e.jsxs("span",{className:R("inline-flex items-center gap-1",j.session.status==="running"||j.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[j.session.status==="running"?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):j.session.status==="exited"?e.jsx(ar,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"}),In(j.session)]}),j.session.status==="running"&&e.jsx("button",{type:"button",onClick:V=>{ne(V,j)},"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(gr,{className:"h-3 w-3"})})]}),j.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:j.session.stdout}),Er(j.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Er(j.session)}),(j.session.stdoutTruncated||j.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},j.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:[j.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:j.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(Us,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:j.error})]},j.id))}),e.jsxs("form",{onSubmit:ee,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:X,value:m,onChange:j=>b(j.target.value),disabled:!D||T,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||!m.trim()||T,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:T?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Ds,{className:"h-3 w-3"})})]})]})]})})}var Mt={},Ys,Ar;function zu(){return Ar||(Ar=1,Ys=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Ys}var Js={},xt={},Dr;function Nt(){if(Dr)return xt;Dr=1;let t;const s=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return xt.getSymbolSize=function(r){if(!r)throw new Error('"version" cannot be null or undefined');if(r<1||r>40)throw new Error('"version" should be in range from 1 to 40');return r*4+17},xt.getSymbolTotalCodewords=function(r){return s[r]},xt.getBCHDigit=function(n){let r=0;for(;n!==0;)r++,n>>>=1;return r},xt.setToSJISFunction=function(r){if(typeof r!="function")throw new Error('"toSJISFunc" is not a valid function.');t=r},xt.isKanjiModeEnabled=function(){return typeof t<"u"},xt.toSJIS=function(r){return t(r)},xt}var Zs={},_r;function Kn(){return _r||(_r=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function s(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+n)}}t.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},t.from=function(r,a){if(t.isValid(r))return r;try{return s(r)}catch{return a}}})(Zs)),Zs}var Xs,Mr;function Uu(){if(Mr)return Xs;Mr=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(s){const n=Math.floor(s/8);return(this.buffer[n]>>>7-s%8&1)===1},put:function(s,n){for(let r=0;r<n;r++)this.putBit((s>>>n-r-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(s){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),s&&(this.buffer[n]|=128>>>this.length%8),this.length++}},Xs=t,Xs}var en,Pr;function $u(){if(Pr)return en;Pr=1;function t(s){if(!s||s<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=s,this.data=new Uint8Array(s*s),this.reservedBit=new Uint8Array(s*s)}return t.prototype.set=function(s,n,r,a){const i=s*this.size+n;this.data[i]=r,a&&(this.reservedBit[i]=!0)},t.prototype.get=function(s,n){return this.data[s*this.size+n]},t.prototype.xor=function(s,n,r){this.data[s*this.size+n]^=r},t.prototype.isReserved=function(s,n){return this.reservedBit[s*this.size+n]},en=t,en}var tn={},Ir;function qu(){return Ir||(Ir=1,(function(t){const s=Nt().getSymbolSize;t.getRowColCoords=function(r){if(r===1)return[];const a=Math.floor(r/7)+2,i=s(r),l=i===145?26:Math.ceil((i-13)/(2*a-2))*2,d=[i-7];for(let c=1;c<a-1;c++)d[c]=d[c-1]-l;return d.push(6),d.reverse()},t.getPositions=function(r){const a=[],i=t.getRowColCoords(r),l=i.length;for(let d=0;d<l;d++)for(let c=0;c<l;c++)d===0&&c===0||d===0&&c===l-1||d===l-1&&c===0||a.push([i[d],i[c]]);return a}})(tn)),tn}var sn={},Lr;function Vu(){if(Lr)return sn;Lr=1;const t=Nt().getSymbolSize,s=7;return sn.getPositions=function(r){const a=t(r);return[[0,0],[a-s,0],[0,a-s]]},sn}var nn={},Rr;function Hu(){return Rr||(Rr=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const s={N1:3,N2:3,N3:40,N4:10};t.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},t.from=function(a){return t.isValid(a)?parseInt(a,10):void 0},t.getPenaltyN1=function(a){const i=a.size;let l=0,d=0,c=0,m=null,b=null;for(let f=0;f<i;f++){d=c=0,m=b=null;for(let u=0;u<i;u++){let g=a.get(f,u);g===m?d++:(d>=5&&(l+=s.N1+(d-5)),m=g,d=1),g=a.get(u,f),g===b?c++:(c>=5&&(l+=s.N1+(c-5)),b=g,c=1)}d>=5&&(l+=s.N1+(d-5)),c>=5&&(l+=s.N1+(c-5))}return l},t.getPenaltyN2=function(a){const i=a.size;let l=0;for(let d=0;d<i-1;d++)for(let c=0;c<i-1;c++){const m=a.get(d,c)+a.get(d,c+1)+a.get(d+1,c)+a.get(d+1,c+1);(m===4||m===0)&&l++}return l*s.N2},t.getPenaltyN3=function(a){const i=a.size;let l=0,d=0,c=0;for(let m=0;m<i;m++){d=c=0;for(let b=0;b<i;b++)d=d<<1&2047|a.get(m,b),b>=10&&(d===1488||d===93)&&l++,c=c<<1&2047|a.get(b,m),b>=10&&(c===1488||c===93)&&l++}return l*s.N3},t.getPenaltyN4=function(a){let i=0;const l=a.data.length;for(let c=0;c<l;c++)i+=a.data[c];return Math.abs(Math.ceil(i*100/l/5)-10)*s.N4};function n(r,a,i){switch(r){case t.Patterns.PATTERN000:return(a+i)%2===0;case t.Patterns.PATTERN001:return a%2===0;case t.Patterns.PATTERN010:return i%3===0;case t.Patterns.PATTERN011:return(a+i)%3===0;case t.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(i/3))%2===0;case t.Patterns.PATTERN101:return a*i%2+a*i%3===0;case t.Patterns.PATTERN110:return(a*i%2+a*i%3)%2===0;case t.Patterns.PATTERN111:return(a*i%3+(a+i)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}t.applyMask=function(a,i){const l=i.size;for(let d=0;d<l;d++)for(let c=0;c<l;c++)i.isReserved(c,d)||i.xor(c,d,n(a,c,d))},t.getBestMask=function(a,i){const l=Object.keys(t.Patterns).length;let d=0,c=1/0;for(let m=0;m<l;m++){i(m),t.applyMask(m,a);const b=t.getPenaltyN1(a)+t.getPenaltyN2(a)+t.getPenaltyN3(a)+t.getPenaltyN4(a);t.applyMask(m,a),b<c&&(c=b,d=m)}return d}})(nn)),nn}var ps={},Br;function vo(){if(Br)return ps;Br=1;const t=Kn(),s=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],n=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return ps.getBlocksCount=function(a,i){switch(i){case t.L:return s[(a-1)*4+0];case t.M:return s[(a-1)*4+1];case t.Q:return s[(a-1)*4+2];case t.H:return s[(a-1)*4+3];default:return}},ps.getTotalCodewordsCount=function(a,i){switch(i){case t.L:return n[(a-1)*4+0];case t.M:return n[(a-1)*4+1];case t.Q:return n[(a-1)*4+2];case t.H:return n[(a-1)*4+3];default:return}},ps}var rn={},Wt={},Or;function Ku(){if(Or)return Wt;Or=1;const t=new Uint8Array(512),s=new Uint8Array(256);return(function(){let r=1;for(let a=0;a<255;a++)t[a]=r,s[r]=a,r<<=1,r&256&&(r^=285);for(let a=255;a<512;a++)t[a]=t[a-255]})(),Wt.log=function(r){if(r<1)throw new Error("log("+r+")");return s[r]},Wt.exp=function(r){return t[r]},Wt.mul=function(r,a){return r===0||a===0?0:t[s[r]+s[a]]},Wt}var Fr;function Gu(){return Fr||(Fr=1,(function(t){const s=Ku();t.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let l=0;l<r.length;l++)for(let d=0;d<a.length;d++)i[l+d]^=s.mul(r[l],a[d]);return i},t.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const l=i[0];for(let c=0;c<a.length;c++)i[c]^=s.mul(a[c],l);let d=0;for(;d<i.length&&i[d]===0;)d++;i=i.slice(d)}return i},t.generateECPolynomial=function(r){let a=new Uint8Array([1]);for(let i=0;i<r;i++)a=t.mul(a,new Uint8Array([1,s.exp(i)]));return a}})(rn)),rn}var an,zr;function Wu(){if(zr)return an;zr=1;const t=Gu();function s(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return s.prototype.initialize=function(r){this.degree=r,this.genPoly=t.generateECPolynomial(this.degree)},s.prototype.encode=function(r){if(!this.genPoly)throw new Error("Encoder not initialized");const a=new Uint8Array(r.length+this.degree);a.set(r);const i=t.mod(a,this.genPoly),l=this.degree-i.length;if(l>0){const d=new Uint8Array(this.degree);return d.set(i,l),d}return i},an=s,an}var on={},ln={},dn={},Ur;function wo(){return Ur||(Ur=1,dn.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),dn}var dt={},$r;function yo(){if($r)return dt;$r=1;const t="[0-9]+",s="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const r="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
165
+ ]))+`;dt.KANJI=new RegExp(n,"g"),dt.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),dt.BYTE=new RegExp(r,"g"),dt.NUMERIC=new RegExp(t,"g"),dt.ALPHANUMERIC=new RegExp(s,"g");const a=new RegExp("^"+n+"$"),i=new RegExp("^"+t+"$"),l=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return dt.testKanji=function(c){return a.test(c)},dt.testNumeric=function(c){return i.test(c)},dt.testAlphanumeric=function(c){return l.test(c)},dt}var qr;function kt(){return qr||(qr=1,(function(t){const s=wo(),n=yo();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(i,l){if(!i.ccBits)throw new Error("Invalid mode: "+i);if(!s.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?i.ccBits[0]:l<27?i.ccBits[1]:i.ccBits[2]},t.getBestModeForData=function(i){return n.testNumeric(i)?t.NUMERIC:n.testAlphanumeric(i)?t.ALPHANUMERIC:n.testKanji(i)?t.KANJI:t.BYTE},t.toString=function(i){if(i&&i.id)return i.id;throw new Error("Invalid mode")},t.isValid=function(i){return i&&i.bit&&i.ccBits};function r(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+a)}}t.from=function(i,l){if(t.isValid(i))return i;try{return r(i)}catch{return l}}})(ln)),ln}var Vr;function Qu(){return Vr||(Vr=1,(function(t){const s=Nt(),n=vo(),r=Kn(),a=kt(),i=wo(),l=7973,d=s.getBCHDigit(l);function c(u,g,N){for(let y=1;y<=40;y++)if(g<=t.getCapacity(y,N,u))return y}function m(u,g){return a.getCharCountIndicator(u,g)+4}function b(u,g){let N=0;return u.forEach(function(y){const A=m(y.mode,g);N+=A+y.getBitsLength()}),N}function f(u,g){for(let N=1;N<=40;N++)if(b(u,N)<=t.getCapacity(N,g,a.MIXED))return N}t.from=function(g,N){return i.isValid(g)?parseInt(g,10):N},t.getCapacity=function(g,N,y){if(!i.isValid(g))throw new Error("Invalid QR Code version");typeof y>"u"&&(y=a.BYTE);const A=s.getSymbolTotalCodewords(g),h=n.getTotalCodewordsCount(g,N),E=(A-h)*8;if(y===a.MIXED)return E;const x=E-m(y,g);switch(y){case a.NUMERIC:return Math.floor(x/10*3);case a.ALPHANUMERIC:return Math.floor(x/11*2);case a.KANJI:return Math.floor(x/13);case a.BYTE:default:return Math.floor(x/8)}},t.getBestVersionForData=function(g,N){let y;const A=r.from(N,r.M);if(Array.isArray(g)){if(g.length>1)return f(g,A);if(g.length===0)return 1;y=g[0]}else y=g;return c(y.mode,y.getLength(),A)},t.getEncodedBits=function(g){if(!i.isValid(g)||g<7)throw new Error("Invalid QR Code version");let N=g<<12;for(;s.getBCHDigit(N)-d>=0;)N^=l<<s.getBCHDigit(N)-d;return g<<12|N}})(on)),on}var cn={},Hr;function Yu(){if(Hr)return cn;Hr=1;const t=Nt(),s=1335,n=21522,r=t.getBCHDigit(s);return cn.getEncodedBits=function(i,l){const d=i.bit<<3|l;let c=d<<10;for(;t.getBCHDigit(c)-r>=0;)c^=s<<t.getBCHDigit(c)-r;return(d<<10|c)^n},cn}var un={},mn,Kr;function Ju(){if(Kr)return mn;Kr=1;const t=kt();function s(n){this.mode=t.NUMERIC,this.data=n.toString()}return s.getBitsLength=function(r){return 10*Math.floor(r/3)+(r%3?r%3*3+1:0)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(r){let a,i,l;for(a=0;a+3<=this.data.length;a+=3)i=this.data.substr(a,3),l=parseInt(i,10),r.put(l,10);const d=this.data.length-a;d>0&&(i=this.data.substr(a),l=parseInt(i,10),r.put(l,d*3+1))},mn=s,mn}var hn,Gr;function Zu(){if(Gr)return hn;Gr=1;const t=kt(),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function n(r){this.mode=t.ALPHANUMERIC,this.data=r}return n.getBitsLength=function(a){return 11*Math.floor(a/2)+6*(a%2)},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(a){let i;for(i=0;i+2<=this.data.length;i+=2){let l=s.indexOf(this.data[i])*45;l+=s.indexOf(this.data[i+1]),a.put(l,11)}this.data.length%2&&a.put(s.indexOf(this.data[i]),6)},hn=n,hn}var fn,Wr;function Xu(){if(Wr)return fn;Wr=1;const t=kt();function s(n){this.mode=t.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}return s.getBitsLength=function(r){return r*8},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(n){for(let r=0,a=this.data.length;r<a;r++)n.put(this.data[r],8)},fn=s,fn}var xn,Qr;function em(){if(Qr)return xn;Qr=1;const t=kt(),s=Nt();function n(r){this.mode=t.KANJI,this.data=r}return n.getBitsLength=function(a){return a*13},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(r){let a;for(a=0;a<this.data.length;a++){let i=s.toSJIS(this.data[a]);if(i>=33088&&i<=40956)i-=33088;else if(i>=57408&&i<=60351)i-=49472;else throw new Error("Invalid SJIS character: "+this.data[a]+`
166
+ Make sure your charset is UTF-8`);i=(i>>>8&255)*192+(i&255),r.put(i,13)}},xn=n,xn}var pn={exports:{}},Yr;function tm(){return Yr||(Yr=1,(function(t){var s={single_source_shortest_paths:function(n,r,a){var i={},l={};l[r]=0;var d=s.PriorityQueue.make();d.push(r,0);for(var c,m,b,f,u,g,N,y,A;!d.empty();){c=d.pop(),m=c.value,f=c.cost,u=n[m]||{};for(b in u)u.hasOwnProperty(b)&&(g=u[b],N=f+g,y=l[b],A=typeof l[b]>"u",(A||y>N)&&(l[b]=N,d.push(b,N),i[b]=m))}if(typeof a<"u"&&typeof l[a]>"u"){var h=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(h)}return i},extract_shortest_path_from_predecessor_list:function(n,r){for(var a=[],i=r;i;)a.push(i),n[i],i=n[i];return a.reverse(),a},find_path:function(n,r,a){var i=s.single_source_shortest_paths(n,r,a);return s.extract_shortest_path_from_predecessor_list(i,a)},PriorityQueue:{make:function(n){var r=s.PriorityQueue,a={},i;n=n||{};for(i in r)r.hasOwnProperty(i)&&(a[i]=r[i]);return a.queue=[],a.sorter=n.sorter||r.default_sorter,a},default_sorter:function(n,r){return n.cost-r.cost},push:function(n,r){var a={value:n,cost:r};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=s})(pn)),pn.exports}var Jr;function sm(){return Jr||(Jr=1,(function(t){const s=kt(),n=Ju(),r=Zu(),a=Xu(),i=em(),l=yo(),d=Nt(),c=tm();function m(h){return unescape(encodeURIComponent(h)).length}function b(h,E,x){const v=[];let k;for(;(k=h.exec(x))!==null;)v.push({data:k[0],index:k.index,mode:E,length:k[0].length});return v}function f(h){const E=b(l.NUMERIC,s.NUMERIC,h),x=b(l.ALPHANUMERIC,s.ALPHANUMERIC,h);let v,k;return d.isKanjiModeEnabled()?(v=b(l.BYTE,s.BYTE,h),k=b(l.KANJI,s.KANJI,h)):(v=b(l.BYTE_KANJI,s.BYTE,h),k=[]),E.concat(x,v,k).sort(function(T,I){return T.index-I.index}).map(function(T){return{data:T.data,mode:T.mode,length:T.length}})}function u(h,E){switch(E){case s.NUMERIC:return n.getBitsLength(h);case s.ALPHANUMERIC:return r.getBitsLength(h);case s.KANJI:return i.getBitsLength(h);case s.BYTE:return a.getBitsLength(h)}}function g(h){return h.reduce(function(E,x){const v=E.length-1>=0?E[E.length-1]:null;return v&&v.mode===x.mode?(E[E.length-1].data+=x.data,E):(E.push(x),E)},[])}function N(h){const E=[];for(let x=0;x<h.length;x++){const v=h[x];switch(v.mode){case s.NUMERIC:E.push([v,{data:v.data,mode:s.ALPHANUMERIC,length:v.length},{data:v.data,mode:s.BYTE,length:v.length}]);break;case s.ALPHANUMERIC:E.push([v,{data:v.data,mode:s.BYTE,length:v.length}]);break;case s.KANJI:E.push([v,{data:v.data,mode:s.BYTE,length:m(v.data)}]);break;case s.BYTE:E.push([{data:v.data,mode:s.BYTE,length:m(v.data)}])}}return E}function y(h,E){const x={},v={start:{}};let k=["start"];for(let C=0;C<h.length;C++){const T=h[C],I=[];for(let S=0;S<T.length;S++){const P=T[S],D=""+C+S;I.push(D),x[D]={node:P,lastCount:0},v[D]={};for(let _=0;_<k.length;_++){const B=k[_];x[B]&&x[B].node.mode===P.mode?(v[B][D]=u(x[B].lastCount+P.length,P.mode)-u(x[B].lastCount,P.mode),x[B].lastCount+=P.length):(x[B]&&(x[B].lastCount=P.length),v[B][D]=u(P.length,P.mode)+4+s.getCharCountIndicator(P.mode,E))}}k=I}for(let C=0;C<k.length;C++)v[k[C]].end=0;return{map:v,table:x}}function A(h,E){let x;const v=s.getBestModeForData(h);if(x=s.from(E,v),x!==s.BYTE&&x.bit<v.bit)throw new Error('"'+h+'" cannot be encoded with mode '+s.toString(x)+`.
167
+ Suggested mode is: `+s.toString(v));switch(x===s.KANJI&&!d.isKanjiModeEnabled()&&(x=s.BYTE),x){case s.NUMERIC:return new n(h);case s.ALPHANUMERIC:return new r(h);case s.KANJI:return new i(h);case s.BYTE:return new a(h)}}t.fromArray=function(E){return E.reduce(function(x,v){return typeof v=="string"?x.push(A(v,null)):v.data&&x.push(A(v.data,v.mode)),x},[])},t.fromString=function(E,x){const v=f(E,d.isKanjiModeEnabled()),k=N(v),C=y(k,x),T=c.find_path(C.map,"start","end"),I=[];for(let S=1;S<T.length-1;S++)I.push(C.table[T[S]].node);return t.fromArray(g(I))},t.rawSplit=function(E){return t.fromArray(f(E,d.isKanjiModeEnabled()))}})(un)),un}var Zr;function nm(){if(Zr)return Js;Zr=1;const t=Nt(),s=Kn(),n=Uu(),r=$u(),a=qu(),i=Vu(),l=Hu(),d=vo(),c=Wu(),m=Qu(),b=Yu(),f=kt(),u=sm();function g(C,T){const I=C.size,S=i.getPositions(T);for(let P=0;P<S.length;P++){const D=S[P][0],_=S[P][1];for(let B=-1;B<=7;B++)if(!(D+B<=-1||I<=D+B))for(let z=-1;z<=7;z++)_+z<=-1||I<=_+z||(B>=0&&B<=6&&(z===0||z===6)||z>=0&&z<=6&&(B===0||B===6)||B>=2&&B<=4&&z>=2&&z<=4?C.set(D+B,_+z,!0,!0):C.set(D+B,_+z,!1,!0))}}function N(C){const T=C.size;for(let I=8;I<T-8;I++){const S=I%2===0;C.set(I,6,S,!0),C.set(6,I,S,!0)}}function y(C,T){const I=a.getPositions(T);for(let S=0;S<I.length;S++){const P=I[S][0],D=I[S][1];for(let _=-2;_<=2;_++)for(let B=-2;B<=2;B++)_===-2||_===2||B===-2||B===2||_===0&&B===0?C.set(P+_,D+B,!0,!0):C.set(P+_,D+B,!1,!0)}}function A(C,T){const I=C.size,S=m.getEncodedBits(T);let P,D,_;for(let B=0;B<18;B++)P=Math.floor(B/3),D=B%3+I-8-3,_=(S>>B&1)===1,C.set(P,D,_,!0),C.set(D,P,_,!0)}function h(C,T,I){const S=C.size,P=b.getEncodedBits(T,I);let D,_;for(D=0;D<15;D++)_=(P>>D&1)===1,D<6?C.set(D,8,_,!0):D<8?C.set(D+1,8,_,!0):C.set(S-15+D,8,_,!0),D<8?C.set(8,S-D-1,_,!0):D<9?C.set(8,15-D-1+1,_,!0):C.set(8,15-D-1,_,!0);C.set(S-8,8,1,!0)}function E(C,T){const I=C.size;let S=-1,P=I-1,D=7,_=0;for(let B=I-1;B>0;B-=2)for(B===6&&B--;;){for(let z=0;z<2;z++)if(!C.isReserved(P,B-z)){let Q=!1;_<T.length&&(Q=(T[_]>>>D&1)===1),C.set(P,B-z,Q),D--,D===-1&&(_++,D=7)}if(P+=S,P<0||I<=P){P-=S,S=-S;break}}}function x(C,T,I){const S=new n;I.forEach(function(z){S.put(z.mode.bit,4),S.put(z.getLength(),f.getCharCountIndicator(z.mode,C)),z.write(S)});const P=t.getSymbolTotalCodewords(C),D=d.getTotalCodewordsCount(C,T),_=(P-D)*8;for(S.getLengthInBits()+4<=_&&S.put(0,4);S.getLengthInBits()%8!==0;)S.putBit(0);const B=(_-S.getLengthInBits())/8;for(let z=0;z<B;z++)S.put(z%2?17:236,8);return v(S,C,T)}function v(C,T,I){const S=t.getSymbolTotalCodewords(T),P=d.getTotalCodewordsCount(T,I),D=S-P,_=d.getBlocksCount(T,I),B=S%_,z=_-B,Q=Math.floor(S/_),Y=Math.floor(D/_),X=Y+1,ee=Q-Y,ne=new c(ee);let U=0;const O=new Array(_),p=new Array(_);let q=0;const j=new Uint8Array(C.buffer);for(let ae=0;ae<_;ae++){const oe=ae<z?Y:X;O[ae]=j.slice(U,U+oe),p[ae]=ne.encode(O[ae]),U+=oe,q=Math.max(q,oe)}const V=new Uint8Array(S);let F=0,H,L;for(H=0;H<q;H++)for(L=0;L<_;L++)H<O[L].length&&(V[F++]=O[L][H]);for(H=0;H<ee;H++)for(L=0;L<_;L++)V[F++]=p[L][H];return V}function k(C,T,I,S){let P;if(Array.isArray(C))P=u.fromArray(C);else if(typeof C=="string"){let Q=T;if(!Q){const Y=u.rawSplit(C);Q=m.getBestVersionForData(Y,I)}P=u.fromString(C,Q||40)}else throw new Error("Invalid data");const D=m.getBestVersionForData(P,I);if(!D)throw new Error("The amount of data is too big to be stored in a QR Code");if(!T)T=D;else if(T<D)throw new Error(`
168
+ The chosen QR Code version cannot contain this amount of data.
169
+ Minimum version required to store current data is: `+D+`.
170
+ `);const _=x(T,I,P),B=t.getSymbolSize(T),z=new r(B);return g(z,T),N(z),y(z,T),h(z,I,0),T>=7&&A(z,T),E(z,_),isNaN(S)&&(S=l.getBestMask(z,h.bind(null,z,I))),l.applyMask(S,z),h(z,I,S),{modules:z,version:T,errorCorrectionLevel:I,maskPattern:S,segments:P}}return Js.create=function(T,I){if(typeof T>"u"||T==="")throw new Error("No input text");let S=s.M,P,D;return typeof I<"u"&&(S=s.from(I.errorCorrectionLevel,s.M),P=m.from(I.version),D=l.from(I.maskPattern),I.toSJISFunc&&t.setToSJISFunction(I.toSJISFunc)),k(T,P,S,D)},Js}var gn={},bn={},Xr;function jo(){return Xr||(Xr=1,(function(t){function s(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let r=n.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+n);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(i){return[i,i]}))),r.length===6&&r.push("F","F");const a=parseInt(r.join(""),16);return{r:a>>24&255,g:a>>16&255,b:a>>8&255,a:a&255,hex:"#"+r.slice(0,6).join("")}}t.getOptions=function(r){r||(r={}),r.color||(r.color={});const a=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,i=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:i,scale:i?4:l,margin:a,color:{dark:s(r.color.dark||"#000000ff"),light:s(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},t.getScale=function(r,a){return a.width&&a.width>=r+a.margin*2?a.width/(r+a.margin*2):a.scale},t.getImageWidth=function(r,a){const i=t.getScale(r,a);return Math.floor((r+a.margin*2)*i)},t.qrToImageData=function(r,a,i){const l=a.modules.size,d=a.modules.data,c=t.getScale(l,i),m=Math.floor((l+i.margin*2)*c),b=i.margin*c,f=[i.color.light,i.color.dark];for(let u=0;u<m;u++)for(let g=0;g<m;g++){let N=(u*m+g)*4,y=i.color.light;if(u>=b&&g>=b&&u<m-b&&g<m-b){const A=Math.floor((u-b)/c),h=Math.floor((g-b)/c);y=f[d[A*l+h]?1:0]}r[N++]=y.r,r[N++]=y.g,r[N++]=y.b,r[N]=y.a}}})(bn)),bn}var ea;function rm(){return ea||(ea=1,(function(t){const s=jo();function n(a,i,l){a.clearRect(0,0,i.width,i.height),i.style||(i.style={}),i.height=l,i.width=l,i.style.height=l+"px",i.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(i,l,d){let c=d,m=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(m=r()),c=s.getOptions(c);const b=s.getImageWidth(i.modules.size,c),f=m.getContext("2d"),u=f.createImageData(b,b);return s.qrToImageData(u.data,i,c),n(f,m,b),f.putImageData(u,0,0),m},t.renderToDataURL=function(i,l,d){let c=d;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const m=t.render(i,l,c),b=c.type||"image/png",f=c.rendererOpts||{};return m.toDataURL(b,f.quality)}})(gn)),gn}var vn={},ta;function am(){if(ta)return vn;ta=1;const t=jo();function s(a,i){const l=a.a/255,d=i+'="'+a.hex+'"';return l<1?d+" "+i+'-opacity="'+l.toFixed(2).slice(1)+'"':d}function n(a,i,l){let d=a+i;return typeof l<"u"&&(d+=" "+l),d}function r(a,i,l){let d="",c=0,m=!1,b=0;for(let f=0;f<a.length;f++){const u=Math.floor(f%i),g=Math.floor(f/i);!u&&!m&&(m=!0),a[f]?(b++,f>0&&u>0&&a[f-1]||(d+=m?n("M",u+l,.5+g+l):n("m",c,0),c=0,m=!1),u+1<i&&a[f+1]||(d+=n("h",b),b=0)):c++}return d}return vn.render=function(i,l,d){const c=t.getOptions(l),m=i.modules.size,b=i.modules.data,f=m+c.margin*2,u=c.color.light.a?"<path "+s(c.color.light,"fill")+' d="M0 0h'+f+"v"+f+'H0z"/>':"",g="<path "+s(c.color.dark,"stroke")+' d="'+r(b,m,c.margin)+'"/>',N='viewBox="0 0 '+f+" "+f+'"',A='<svg xmlns="http://www.w3.org/2000/svg" '+(c.width?'width="'+c.width+'" height="'+c.width+'" ':"")+N+' shape-rendering="crispEdges">'+u+g+`</svg>
171
+ `;return typeof d=="function"&&d(null,A),A},vn}var sa;function om(){if(sa)return Mt;sa=1;const t=zu(),s=nm(),n=rm(),r=am();function a(i,l,d,c,m){const b=[].slice.call(arguments,1),f=b.length,u=typeof b[f-1]=="function";if(!u&&!t())throw new Error("Callback required as last argument");if(u){if(f<2)throw new Error("Too few arguments provided");f===2?(m=d,d=l,l=c=void 0):f===3&&(l.getContext&&typeof m>"u"?(m=c,c=void 0):(m=c,c=d,d=l,l=void 0))}else{if(f<1)throw new Error("Too few arguments provided");return f===1?(d=l,l=c=void 0):f===2&&!l.getContext&&(c=d,d=l,l=void 0),new Promise(function(g,N){try{const y=s.create(d,c);g(i(y,l,c))}catch(y){N(y)}})}try{const g=s.create(d,c);m(null,i(g,l,c))}catch(g){m(g)}}return Mt.create=s.create,Mt.toCanvas=a.bind(null,n.render),Mt.toDataURL=a.bind(null,n.renderToDataURL),Mt.toString=a.bind(null,function(i,l,d){return r.render(i,d)}),Mt}var im=om();function lm(t){return Hi(t)}function dm(t){return im.toDataURL(t,{errorCorrectionLevel:"M",margin:2,scale:8,color:{dark:"#111827ff",light:"#ffffffff"}})}function No({title:t,description:s,triggerLabel:n,qrValue:r,displayValue:a,hint:i,imageAlt:l,copyLabel:d,copiedMessage:c}){const[m,b]=o.useState(!1),[f,u]=o.useState(null),[g,N]=o.useState(null);return o.useEffect(()=>{if(!m)return;let y=!1;return u(null),N(null),dm(r).then(A=>{y||u(A)}).catch(()=>{y||N("QR code unavailable")}),()=>{y=!0}},[m,r]),e.jsxs(yt,{open:m,onOpenChange:b,children:[e.jsx(Ki,{asChild:!0,children: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","aria-label":n,title:n,children:e.jsx(Qd,{className:"h-3 w-3"})})}),e.jsxs(jt,{className:"max-w-[20rem] gap-2 p-3",children:[e.jsxs(Ts,{className:"space-y-1 text-left",children:[e.jsx(Ot,{className:"text-[12px]",children:t}),e.jsx(Es,{children:s})]}),e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("div",{className:"flex h-52 w-52 items-center justify-center rounded-sm bg-white p-2 text-[10px] text-muted-foreground",children:f?e.jsx("img",{src:f,alt:l,className:"h-full w-full"}):g?e.jsx("span",{children:g}):e.jsx(ue,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),e.jsx("div",{className:"w-full rounded-sm bg-primary/10 px-2 py-1 text-center text-[10px] font-medium text-foreground",children:i}),e.jsx("div",{className:"w-full rounded-sm bg-muted/45 px-2 py-1.5 font-mono text-[9px] leading-[0.95rem] text-foreground break-all",children:a}),e.jsx(Z,{type:"button",variant:"secondary",size:"sm",className:"h-6 w-full border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",onClick:()=>{Cs(a,c)},children:d})]})]})]})}function cm({nodeName:t,nodeEndpoint:s}){const n=o.useMemo(()=>lm({nodeName:t,nodeEndpoint:s}),[s,t]),r=`Show ${t} Node QR code`;return e.jsx(No,{title:"Node URL QR",description:t,triggerLabel:r,qrValue:n,displayValue:s,hint:"Scan with Meshy Mobile",imageAlt:`${t} Node URL QR code`,copyLabel:"Copy node URL",copiedMessage:"Node URL copied"})}function um({nodeName:t,dashboardUrl:s}){const n=`Show ${t} dashboard QR code`;return e.jsx(No,{title:"Dashboard URL QR",description:t,triggerLabel:n,qrValue:s,displayValue:s,hint:"Scan with Edge to view the dashboard",imageAlt:`${t} dashboard URL QR code`,copyLabel:"Copy dashboard URL",copiedMessage:"Dashboard URL copied"})}function Gn({nodeId:t,nodeName:s,onOpenSettings:n,onOpenServicePreview:r,onOpenCapabilities:a,onOpenDevBox:i,onStartDevBox:l,onToggleRemoteAccess:d,remoteAccessLabel:c,remoteAccessPending:m,remoteAccessDisabled:b,remoteAccessDisabledReason:f,showConfigureDevBox:u,showStartDevBox:g,startDevBoxPending:N,className:y}){const[A,h]=o.useState(!1),[E,x]=o.useState(null),v=o.useRef(null),k=o.useRef(null),C=N?"Starting":"Start DevBox",T=c?.startsWith("Disable")?Gi:ic;o.useLayoutEffect(()=>{if(!A){x(null);return}const S=()=>{const P=k.current,D=v.current;if(!P||!D)return;const _=P.getBoundingClientRect(),B=D.getBoundingClientRect();x(hm({left:_.left,right:_.right,bottom:_.bottom,top:_.top},{width:B.width,height:B.height},{width:window.innerWidth,height:window.innerHeight},fm()))};return S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}},[A]),o.useEffect(()=>{if(!A)return;const S=D=>{const _=D.target;_ instanceof Node&&!v.current?.contains(_)&&!k.current?.contains(_)&&h(!1)},P=D=>{D.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",S),document.addEventListener("keydown",P),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("keydown",P)}},[A]);const I=A?e.jsxs("div",{ref:v,"data-node-action-menu-portal":"true",role:"menu",style:mm(E),onClick:S=>S.stopPropagation(),onPointerDown:S=>S.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:S=>{S.stopPropagation(),h(!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(Wi,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Settings"})]}),r&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Preview service on ${s}`,title:`Preview service on ${s}`,onClick:S=>{S.stopPropagation(),h(!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(Za,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Preview service"})]}),a&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} capabilities`,title:`Open ${s} capabilities`,onClick:S=>{S.stopPropagation(),h(!1),a(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(As,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Capabilities"})]}),c&&d&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${c} for ${s}`,title:f??`${c} for ${s}`,onClick:S=>{S.stopPropagation(),!(m||b)&&(h(!1),d())},disabled:m||b,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:[m?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(T,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:c})]}),g&&l&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${C} for ${s}`,title:`${C} for ${s}`,onClick:S=>{S.stopPropagation(),!N&&(h(!1),l(t))},disabled:N,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:[N?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(Ds,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:C})]}),u&&i&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${s}`,title:`Configure DevBox for ${s}`,onClick:S=>{S.stopPropagation(),h(!1),i(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Qi,{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:R("relative shrink-0",A&&"z-[120]",y),onClick:S=>S.stopPropagation(),onPointerDown:S=>S.stopPropagation(),children:[e.jsx(Z,{ref:k,type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${s}`,"aria-haspopup":"menu","aria-expanded":A,title:`More actions for ${s}`,onClick:S=>{S.stopPropagation(),h(P=>(P||x(null),!P))},className:R("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",A&&"bg-background/80 text-primary"),children:e.jsx(Td,{className:"h-3.5 w-3.5"})}),I&&(typeof document>"u"?I:Ba.createPortal(I,document.body))]})}function mm(t){return t?{left:t.left,top:t.top}:{left:0,top:0,visibility:"hidden"}}function hm(t,s,n,r=1){const l=s.width||160,d=s.height||0,c=Number.isFinite(r)&&r>0?r:1,m=Math.max(8,Math.min(t.right-l,n.width-l-8)),b=t.bottom+4,f=(t.top??t.bottom)-d-4,u=b+d>n.height-8&&f>=8?f:b;return{left:Math.round(m/c),top:Math.round(u/c)}}function fm(){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 xm=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),pm=new Set(["startinprogress","starting"]);function Lt(t){return!!(t?.enabled&&t.name)}function gm(t){const s=t?.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&xm.has(s))}function Rt(t){const s=t?.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&pm.has(s))}function Ps(t,s,n){return t==="offline"&&gm(s)&&Lt(n)}function na(t,s){return t==="offline"&&Lt(s)}function ra(t){return!Lt(t)}function bm({nodeStatus:t,status:s,current:n,selected:r}){const a=r??n;return a&&Ps(t,s,a)?a:null}function Oe(t){return t.scope||`name:${t.name??""}`}function vm({previousKey:t,baseDevBox:s,listed:n}){if(t&&n.some(i=>Oe(i)===t))return t;if(!Lt(s))return n[0]?Oe(n[0]):"";const r=Oe(s),a=n.find(i=>Oe(i)===r)??n.find(i=>i.name===s.name);return a?Oe(a):r}function wm(t){return t==="nodes"||t==="events"?t:"overview"}function ym({cluster:t,systemInfo:s,nodeNameById:n,nodeBlockingTaskCounts:r,eventTypeFilter:a,onEventTypeFilterChange:i,eventTypeOptions:l,filteredEvents:d,sseConnected:c,clusterLoading:m,clusterError:b,promotePending:f,onPromote:u,onAddNode:g,leavePending:N,onLeaveCluster:y,onToggleNodeDevTunnel:A,devTunnelNodeId:h,devBoxStartNodeId:E,devBoxStartingNodeIds:x=new Set,activeTab:v,onTabChange:k,onOpenNodeSettings:C,onOpenNodeCapabilities:T,onOpenDevBox:I,onStartDevBox:S}){const P=t?.self?.role==="leader",D=t?.self?.role==="follower"&&!t?.leader,_=t?.self??null,z=Yi(t?.nodes??[],_?.id).filter(V=>V.id!==_?.id),Q=t?.leader?t.nodes.find(V=>V.id===t.leader?.id)??null:null,Y=t?.leader?t.leader.dashboardOrigin??Q?.dashboardOrigin??(s&&t.leader.id===(s.nodeId??s.id)?s.dashboardOrigin:void 0)??t.leader.endpoint:null,X=t?.leader?Q?.devtunnelEndpoint??t.leader.endpoint:null,ee=t?.leader?.name??Q?.name??"Leader",ne=_?.role==="leader"&&z.length===0,U=_?.role==="follower",[O,p]=o.useState("overview"),q=v??O;function j(V){const F=wm(V);p(F),k?.(F)}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(Bn,{value:q,onValueChange:j,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(Rn,{className:"grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(vt,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(vt,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(vt,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})}),e.jsx(ct,{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:[_&&e.jsx(aa,{node:_,systemInfo:s,blockingTaskCount:r.get(_.id)??0,devTunnelNodeId:h,onToggleNodeDevTunnel:A,showActions:!1,defaultExpanded:!1,onOpenDevBox:I,devBoxStartingNodeIds:x}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"Cluster snapshot"}),e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:c?"Connected":"Reconnecting"})]}),m&&!t?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):b&&!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:b}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(_t,{label:"Term",value:String(t?.term??0)}),e.jsx(_t,{label:"Nodes",value:String(t?.nodes.length??0)}),e.jsx(_t,{label:"Pending",value:String(t?.taskSummary.pending??0)}),e.jsx(_t,{label:"Running",value:String(t?.taskSummary.running??0)}),e.jsx(_t,{label:"Completed",value:String(t?.taskSummary.completed??0)}),e.jsx(_t,{label:"Failed",value:String(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(Ye,{label:"Leader",value:t?.leader?.name??"None"}),e.jsx(Ye,{label:"Leader URL",value:Y??"Unavailable",mono:!0,action:Y?e.jsx(Qn,{nodeName:ee,dashboardUrl:Y,copyLabel:"Copy leader URL",copiedMessage:"Leader URL copied"}):void 0}),X&&e.jsx(Ye,{label:"Node URL",value:X,mono:!0,action:e.jsx(Wn,{nodeName:ee,nodeEndpoint:X})}),e.jsx(Ye,{label:"Feed",value:c?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:D&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:u,disabled:f,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[f&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(ct,{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"}),ne?e.jsxs(Z,{variant:"secondary",size:"sm",onClick:g,className:"h-6 border-0 bg-primary px-2 text-[10px] text-primary-foreground shadow-none hover:bg-primary/90",children:[e.jsx(ac,{className:"h-3 w-3"}),"Join node"]}):U?e.jsxs(Z,{variant:"secondary",size:"sm",onClick:y,disabled:N,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[N&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),_&&e.jsx(aa,{node:_,systemInfo:s,blockingTaskCount:r.get(_.id)??0,devTunnelNodeId:h,onToggleNodeDevTunnel:A,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:P?C:void 0,onOpenNodeCapabilities:P?T:void 0,onOpenDevBox:P?I:void 0,onStartDevBox:P?S:void 0,devBoxStartNodeId:E,devBoxStartingNodeIds:x})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",z.length,")"]}),z.length>0?e.jsx("div",{className:"space-y-1.5",children:z.map(V=>e.jsx(jm,{node:V,isLeader:!!P,blockingTaskCount:r.get(V.id)??0,devTunnelNodeId:h,onToggleNodeDevTunnel:A,onOpenNodeSettings:P?C:void 0,onOpenNodeCapabilities:P?T:void 0,onOpenDevBox:P?I:void 0,onStartDevBox:P?S:void 0,devBoxStartNodeId:E,devBoxStartingNodeIds:x},V.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(ct,{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(Ji,{className:R("h-3.5 w-3.5",c?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(je,{value:a,onValueChange:i,children:[e.jsx(Ne,{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(Pe,{placeholder:"Event type"})}),e.jsx(ke,{className:"shadow-none",children:l.map(V=>e.jsx(he,{value:V,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:V==="all"?"All event types":V},V))})]}),e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:c?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Zi,{events:d,maxHeight:"100%",emptyTitle:a==="all"?"No live events yet":"No matching events",emptyDescription:a==="all"?"Cluster activity appears here as it happens.":`No "${a}" events are in the current stream.`,nodeNameById:n,density:"compact"})})]})})]})})}function aa({node:t,systemInfo:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:a,showActions:i=!0,defaultExpanded:l=!1,onOpenNodeSettings:d,onOpenNodeCapabilities:c,onOpenDevBox:m,onStartDevBox:b,devBoxStartNodeId:f,devBoxStartingNodeIds:u}){const[g,N]=o.useState(l),y=s?.dashboardOrigin??t.dashboardOrigin,A=t.devtunnelEndpoint??t.endpoint,h=y??t.endpoint,E=s?.workDir??t.workDir,x=so(t,s?.transportType),v=qn(t,s?.transportType),k=v&&zt(s?.transportType??t.transportType)?!0:to(t,s?.transportType),C=n>0;return e.jsxs("section",{className:"dashboard-operations-node-card bg-primary/8 shadow-none",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>N(T=>!T),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[g?e.jsx(Je,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(We,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(Oa,{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:h,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Fn,{className:"h-3 w-3"})}),(d||c||i&&k)&&e.jsx(Gn,{nodeId:t.id,nodeName:t.name,onOpenSettings:d,onOpenCapabilities:c,onOpenDevBox:m,onStartDevBox:b,onToggleRemoteAccess:i&&k?()=>a(t):void 0,remoteAccessLabel:i&&k?v?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:C,remoteAccessDisabledReason:C?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:t.devbox?.enabled,showStartDevBox:Ps(t.status,t.devbox?.lastStatus,t.devbox)||Rt(t.devbox?.lastStatus)||u.has(t.id),startDevBoxPending:f===t.id||Rt(t.devbox?.lastStatus)||u.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>N(T=>!T),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(Fa,{role:t.role,size:"compact"}),e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),g&&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(Ye,{label:"Node ID",value:t.id,mono:!0}),y&&e.jsx(Ye,{label:"Dashboard",value:y,mono:!0,action:e.jsx(Qn,{nodeName:t.name,dashboardUrl:y})}),e.jsx(Ye,{label:"Node URL",value:A,mono:!0,action:e.jsx(Wn,{nodeName:t.name,nodeEndpoint:A})}),E&&e.jsx(Ye,{label:"Workspace",value:E,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Cn,{label:"Transport",value:x}),s&&e.jsx(Cn,{label:"Uptime",value:Xi(s.uptime),mono:!0})]}),i&&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(As,{className:"h-3 w-3"}),"Capabilities"]}),i&&k&&C&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function jm({node:t,isLeader:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:a,onOpenNodeSettings:i,onOpenNodeCapabilities:l,onOpenDevBox:d,onStartDevBox:c,devBoxStartNodeId:m,devBoxStartingNodeIds:b}){const[f,u]=o.useState(!1),g=t.dashboardOrigin,N=t.devtunnelEndpoint??t.endpoint,y=g??t.endpoint,A=so(t),h=qn(t),E=to(t),x=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:()=>u(v=>!v),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[f?e.jsx(Je,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(We,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Oa,{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:y,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Fn,{className:"h-3 w-3"})}),s&&(i||l||E)&&e.jsx(Gn,{nodeId:t.id,nodeName:t.name,onOpenSettings:i,onOpenCapabilities:l,onOpenDevBox:d,onStartDevBox:c,onToggleRemoteAccess:E?()=>a(t):void 0,remoteAccessLabel:E?h?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:x,remoteAccessDisabledReason:x?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:t.devbox?.enabled,showStartDevBox:Ps(t.status,t.devbox?.lastStatus,t.devbox)||Rt(t.devbox?.lastStatus)||b.has(t.id),startDevBoxPending:m===t.id||Rt(t.devbox?.lastStatus)||b.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>u(v=>!v),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(Fa,{role:t.role,size:"compact"}),e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),f&&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(Ye,{label:"Node ID",value:t.id,mono:!0}),g&&e.jsx(Ye,{label:"Dashboard",value:g,mono:!0,action:e.jsx(Qn,{nodeName:t.name,dashboardUrl:g})}),e.jsx(Ye,{label:"Node URL",value:N,mono:!0,action:e.jsx(Wn,{nodeName:t.name,nodeEndpoint:N})}),t.workDir&&e.jsx(Ye,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(Cn,{label:"Transport",value:A})]}),s&&l&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:()=>l(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(As,{className:"h-3 w-3"}),"Capabilities"]}),s&&E&&x&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Wn({nodeName:t,nodeEndpoint:s}){return e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(cm,{nodeName:t,nodeEndpoint:s}),e.jsx(ko,{label:"Copy node URL",onClick:()=>{Cs(s,"Node URL copied")}})]})}function Qn({nodeName:t,dashboardUrl:s,copyLabel:n="Copy dashboard URL",copiedMessage:r="Dashboard URL copied"}){return e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(um,{nodeName:t,dashboardUrl:s}),e.jsx(ko,{label:n,onClick:()=>{Cs(s,r)}})]})}function ko({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(Ia,{className:"h-3 w-3"})})}function Nm(t,s,n,r){if(!t)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const a=s?.self?.role==="follower",i=t.assignedTo?s?.self?.id===t.assignedTo?s.self:s?.nodes.find(d=>d.id===t.assignedTo):void 0;return t.assignedTo!==null&&(i?i.status==="offline":s?t.assignedNodeAvailable===!1||!s.nodes.some(d=>d.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.`}:a?{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..."}:ys.has(t.status)||t.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:ys.has(t.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const So=.5,Co=1.75,oa=.1;function km({node:t,open:s,onOpenChange:n}){const[r,a]=o.useState(fs),[i,l]=o.useState(null),[d,c]=o.useState(1),[m,b]=o.useState(!1),[f,u]=o.useState(null);o.useEffect(()=>{a(fs),l(null),c(1),b(!1),u(null)},[t?.id,s]);const g=o.useCallback(async x=>{if(!t)return;const v=x??Number.parseInt(r.trim()||fs,10);if(!Number.isInteger(v)||v<1||v>65535){u("Enter a port between 1 and 65535");return}b(!0),u(null);try{const k=await el(t.id,{port:v});l(k),a(String(v)),or("preview.created",{result:"success",previewType:"service-port"})}catch(k){u(k instanceof Error?k.message:"Failed to create service preview"),or("preview.failed",{result:"failed",previewType:"service-port"})}finally{b(!1)}},[t,r]),N=o.useCallback(()=>{typeof i?.port=="number"&&g(i.port)},[i?.port,g]);o.useEffect(()=>{if(!i)return;const x=i.expiresAt-Date.now()-5e3;if(x<=0){N();return}const v=window.setTimeout(N,x);return()=>window.clearTimeout(v)},[N,i]);const y=i?xd(i):null,A=t?.name??"Node",h=Sm(d),E={width:`${100/d}%`,height:`${100/d}%`,transform:`scale(${d})`,transformOrigin:"top left"};return e.jsx(yt,{open:s,onOpenChange:n,children:e.jsxs(jt,{onOpenAutoFocus:x=>x.preventDefault(),className:"flex h-[min(82vh,44rem)] max-w-[min(92vw,72rem)] flex-col gap-0 overflow-hidden p-0",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border/60 px-3 py-2 pr-9",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(Ot,{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold text-foreground",children:[e.jsx(Za,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0",children:"Preview service"}),e.jsx("span",{className:"min-w-0 truncate font-mono text-[10px] font-medium text-muted-foreground",children:A})]}),e.jsx(Es,{className:"sr-only",children:"Preview a service port running on the selected node."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("form",{className:"flex items-center gap-1.5",onSubmit:x=>{x.preventDefault(),g()},children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:["Port",e.jsx(rt,{type:"text",min:1,max:65535,inputMode:"numeric",value:r,onChange:x=>a(x.target.value),placeholder:fs,"aria-label":"Node service preview port",className:"h-6 w-20 rounded-sm border-0 bg-muted/55 px-2 text-[11px] shadow-none focus:bg-muted/55 focus:outline-none focus-visible:border-0 focus-visible:bg-muted/55 focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsxs(Z,{type:"submit",variant:"ghost",size:"sm",disabled:m,className:"h-6 rounded-sm border-0 bg-primary/10 px-2 text-[11px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[m?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ds,{className:"h-3.5 w-3.5"}),"Preview"]})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden shrink-0 text-[10px] text-muted-foreground sm:inline",children:Cm(i.expiresAt)}),e.jsxs("div",{className:"flex h-6 shrink-0 items-center overflow-hidden rounded-sm border border-border/55 bg-muted/35",children:[e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>c(x=>ia(x,-oa)),disabled:d<=So,title:"Zoom out","aria-label":"Zoom out preview",children:e.jsx(uc,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>c(1),className:"h-6 min-w-11 border-x border-border/45 px-1.5 text-center font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted/55 hover:text-foreground",title:"Reset zoom","aria-label":"Reset preview zoom",children:h}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>c(x=>ia(x,oa)),disabled:d>=Co,title:"Zoom in","aria-label":"Zoom in preview",children:e.jsx(dc,{className:"h-3.5 w-3.5"})})]}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:N,title:"Refresh",children:e.jsx(tl,{className:"h-3.5 w-3.5"})}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",asChild:!0,title:"Open in new tab",children:e.jsx("a",{href:y??i.previewUrl,target:"_blank",rel:"noopener noreferrer",children:e.jsx(Fn,{className:"h-3.5 w-3.5"})})})]})]})]}),f&&e.jsx("div",{className:"shrink-0 border-b border-destructive/20 bg-destructive/5 px-3 py-1.5 text-[11px] text-destructive",children:f}),e.jsx("div",{className:"min-h-0 flex-1 p-2",children:i?e.jsx("div",{className:"h-full overflow-hidden rounded-sm border border-border/60 bg-white shadow-none",children:e.jsx("iframe",{src:gd(i),style:E,className:"h-full w-full border-0",sandbox:pd(i),title:`${A} Service Preview`})}):e.jsx("div",{className:"flex h-full min-h-56 items-center justify-center rounded-sm border border-dashed border-border/65 bg-background/35 px-3 text-center text-[11px] text-muted-foreground",children:"No service preview running."})})]})})}function ia(t,s){return To(Math.round((t+s)*100)/100)}function To(t){return Number.isFinite(t)?Math.min(Co,Math.max(So,t)):1}function Sm(t){return`${Math.round(To(t)*100)}%`}function Cm(t){const s=Math.max(0,Math.round((t-Date.now())/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60),r=s%60;return`${n}m ${r}s`}function Tm({dirPath:t,label:s,taskCount:n,collapsed:r,onToggle:a,onCreateTask:i,onOpenCapabilities:l}){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:a,"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(We,{className:R("h-3 w-3 shrink-0 transition-transform duration-200",!r&&"rotate-90")}),e.jsx(Bt,{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})]}),l&&e.jsx("button",{type:"button",onClick:l,"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(As,{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(Ms,{className:"h-2.5 w-2.5"})})]})}const Eo="meshy-task-sidebar-tree-state";function la(t){return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function wn(){try{return globalThis.window?.localStorage??globalThis.localStorage??null}catch{return null}}function da(t){if(!t)return{collapsedNodes:[],collapsedDirs:[]};try{const s=t.getItem(Eo);if(!s)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(s);return{collapsedNodes:la(n.collapsedNodes),collapsedDirs:la(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Em(t,s){if(t)try{t.setItem(Eo,JSON.stringify(s))}catch{}}function ca(t,s){if(!t.has(s))return t;const n=new Set(t);return n.delete(s),n}function Am(t,s){if(!s)return null;for(const n of t){const r=n.nodeId??"__unassigned__";for(const a of n.dirs)if(a.tasks.some(i=>i.id===s))return{nodeKey:r,dirKey:`${r}::${a.path}`}}return null}function ua(t,s,n){return n?{collapsedNodes:ca(t,n.nodeKey),collapsedDirs:ca(s,n.dirKey)}:{collapsedNodes:t,collapsedDirs:s}}function Dm(t,s,n){const r=t.filter(d=>d.status==="completed"),a=new Set((s?r:[...r].sort((d,c)=>c.updatedAt-d.updatedAt).slice(0,zn)).map(d=>d.id));n&&r.some(d=>d.id===n)&&a.add(n);const i=t.filter(d=>d.status!=="completed"||a.has(d.id)),l=r.length-a.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,l)}}const gs="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",bs="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function ma({toolbarTasks:t,activeTaskId:s,tasksLoading:n,tasksError:r,isLeader:a,scope:i,agentFilter:l,nodeFilter:d,taskKindFilter:c,agentOptions:m,nodeOptions:b,nodeNameById:f,nodeWorkDirById:u,nodeStatusById:g,completedGroupByKey:N,devBoxNodeIds:y=new Set,devBoxStartNodeIds:A=new Set,devBoxStartingNodeIds:h=new Set,leaderNodeId:E,searchQuery:x,selectedTaskIds:v,allVisibleTasksSelected:k,someVisibleTasksSelected:C,canBatchArchive:T,onScopeChange:I,onAgentFilterChange:S,onNodeFilterChange:P,onTaskKindFilterChange:D,onToggleTaskSelected:_,onToggleAllVisibleTasks:B,onBatchArchive:z,onBatchDelete:Q,onCreateTask:Y,onOpenNodeSettings:X,onOpenNodeCapabilities:ee,onOpenProjectCapabilities:ne,onOpenDevBox:U,onStartDevBox:O,onLoadCompletedTasks:p,onSelectTask:q}){const[j,V]=o.useState(!1),[F,H]=o.useState(()=>v.size>0),[L,ae]=o.useState(!1),[oe,ge]=o.useState(null),{markScrollbarActive:re,scrollbarActive:G}=fo(),J=v.size,ce=!!(a&&(F||J>0)),M=i!=="active"||d!=="all"||l!=="all"||c!=="all",W=x.trim().length>0,[me,be]=o.useState(()=>new Set(da(wn()).collapsedNodes)),[Ie,Re]=o.useState(()=>new Set(da(wn()).collapsedDirs)),[ut,Ze]=o.useState(new Set),qe=o.useMemo(()=>sl(t,f,E,u),[t,f,E,u]),Te=o.useMemo(()=>Am(qe,s),[qe,s]),mt=o.useRef(null),Xe=qe.length===1,Le=qe.length>0,te=Xe&&(M||W),ye=!!(a&&(qe.length>0||J>0)),Se=o.useCallback(K=>{be(Ee=>{const Ae=new Set(Ee);return Ae.has(K)?Ae.delete(K):Ae.add(K),Ae})},[]),He=o.useCallback(K=>{Re(Ee=>{const Ae=new Set(Ee);return Ae.has(K)?Ae.delete(K):Ae.add(K),Ae})},[]),Ke=o.useCallback(K=>{Ze(Ee=>{const Ae=new Set(Ee);return Ae.add(K),Ae})},[]);o.useEffect(()=>{Em(wn(),{collapsedNodes:Array.from(me),collapsedDirs:Array.from(Ie)})},[Ie,me]),o.useEffect(()=>{if(!Te||!s)return;const K=`${s}:${Te.nodeKey}:${Te.dirKey}`;mt.current!==K&&(mt.current=K,be(Ee=>ua(Ee,new Set,Te).collapsedNodes),Re(Ee=>ua(new Set,Ee,Te).collapsedDirs))},[s,Te]);const we=o.useCallback(K=>{H(!0),B(K)},[B]),St=o.useCallback(K=>{if(K===!0&&!k){H(!0),ae(!0);return}we(K===!0)},[k,we]),ze=o.useCallback(()=>{we(!0),ae(!1)},[we]),ot=o.useCallback(()=>{B(!1),H(!1),ae(!1)},[B]);o.useEffect(()=>{a||(H(!1),ae(!1))},[a]);const Ce=ce?e.jsxs(Yt,{open:L,onOpenChange:ae,children:[e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(is,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:C&&!k?"indeterminate":k,onCheckedChange:St,"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Select all"})]}),L&&e.jsxs(Jt,{children:[e.jsxs(Zt,{children:[e.jsx(Xt,{children:"Select every visible task?"}),e.jsx(es,{children:"This will select every task currently shown in the rail and expose bulk archive/delete actions. Cancel now unless you intend to act on all visible tasks together."})]}),e.jsxs(ts,{children:[e.jsx(ss,{autoFocus:!0,children:"Cancel"}),e.jsx(ns,{onClick:ze,children:"Select all"})]})]})]}):e.jsxs(Z,{variant:"ghost",size:"sm",onClick:()=>H(!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(od,{className:"h-3 w-3"}),"Multi select"]}),Ut=J>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:[J," task",J!==1?"s":""," selected"]}),!T&&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,Ct=J>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(Yt,{children:[e.jsx(kn,{asChild:!0,children:e.jsxs(Z,{variant:"ghost",size:"sm",disabled:!T,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(vd,{}),"Archive"]})}),e.jsxs(Jt,{children:[e.jsxs(Zt,{children:[e.jsxs(Xt,{children:["Archive ",J," selected task",J!==1?"s":"","?"]}),e.jsx(es,{children:"These tasks leave the default view immediately. Cancel if any selected task still needs to stay visible in active work."})]}),e.jsxs(ts,{children:[e.jsx(ss,{autoFocus:!0,children:"Cancel"}),e.jsx(ns,{onClick:z,disabled:!T,children:"Archive"})]})]})]}),e.jsxs(Yt,{children:[e.jsx(kn,{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(Ua,{}),"Delete"]})}),e.jsxs(Jt,{children:[e.jsxs(Zt,{children:[e.jsxs(Xt,{children:["Delete ",J," selected task",J!==1?"s":""," and saved logs?"]}),e.jsx(es,{children:"This cannot be undone. Cancel unless you are certain every selected task and log should be removed now."})]}),e.jsxs(ts,{children:[e.jsx(ss,{autoFocus:!0,children:"Cancel"}),e.jsx(ns,{onClick:Q,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"dashboard-task-sidebar dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"dashboard-task-sidebar__header shrink-0 bg-card/24 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex min-w-0 items-stretch gap-1.5",children:[e.jsxs(Z,{onClick:()=>Y("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(Ms,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsxs(Z,{variant:"outline",onClick:()=>Y("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($n,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Load session"]})]}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>V(K=>!K),className:R("ml-auto h-8 w-8 shrink-0 rounded-sm text-muted-foreground shadow-none hover:bg-muted/55 hover:text-foreground",(j||M)&&"bg-primary/8 text-primary hover:bg-primary/12 hover:text-primary"),title:"Filters",children:e.jsx(Id,{className:"h-3.5 w-3.5"})})]}),(j||M)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(je,{value:i,onValueChange:K=>I(K),children:[e.jsx(Ne,{className:gs,children:e.jsx(Pe,{})}),e.jsx(ke,{children:nl.map(K=>e.jsx(he,{value:K.value,className:bs,children:K.label},K.value))})]}),e.jsxs(je,{value:d,onValueChange:P,children:[e.jsx(Ne,{className:gs,children:e.jsx(Pe,{placeholder:"Node"})}),e.jsx(ke,{children:b.map(K=>e.jsx(he,{value:K.value,className:bs,children:K.label},K.value))})]}),e.jsxs(je,{value:l,onValueChange:S,children:[e.jsx(Ne,{className:gs,children:e.jsx(Pe,{placeholder:"Agent"})}),e.jsx(ke,{children:m.map(K=>e.jsx(he,{value:K,className:bs,children:K==="all"?"All agents":K},K))})]}),e.jsxs(je,{value:c,onValueChange:K=>D(K),children:[e.jsx(Ne,{className:gs,children:e.jsx(Pe,{placeholder:"Type"})}),e.jsx(ke,{children:rl.map(K=>e.jsx(he,{value:K.value,className:bs,children:K.label},K.value))})]})]})]}),e.jsx("div",{className:R("scrollbar-line min-h-0 flex-1 overflow-y-auto pl-2.5 pr-1.5 py-2",G&&"scrollbar-line-active"),onScroll:re,children:qe.length>0?e.jsx("div",{className:"space-y-1",children:qe.map(K=>{const Ee=K.nodeId??"__unassigned__",Ae=K.dirs.reduce((De,Ve)=>De+Ve.tasks.length,0),it=Le&&!te&&me.has(Ee),$t=K.nodeId!==null&&g.get(K.nodeId)==="offline",Tt=!!(a&&K.nodeId);return e.jsxs("div",{className:"space-y-1",children:[Le&&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:()=>Se(Ee),"aria-expanded":!it,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(We,{className:R("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!it&&"rotate-90")}),e.jsx(Da,{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:K.nodeName}),e.jsxs($e,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-transparent bg-background/55 px-1.5 py-0 text-[7px] font-semibold leading-3.5 text-muted-foreground shadow-none normal-case tracking-normal",children:[Ae," task",Ae===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[$t&&e.jsx($e,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/10 px-1 py-0 text-[8px] font-semibold leading-3 text-destructive shadow-none",children:"offline"}),K.nodeId===E&&e.jsx($e,{variant:"outline",className:"rounded-sm border-transparent bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"})]})]}),Tt&&K.nodeId&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(Gn,{nodeId:K.nodeId,nodeName:K.nodeName,onOpenSettings:X,onOpenServicePreview:()=>ge({id:K.nodeId,name:K.nodeName}),onOpenCapabilities:ee,onOpenDevBox:U,onStartDevBox:O,showConfigureDevBox:y.has(K.nodeId),showStartDevBox:A.has(K.nodeId)||h.has(K.nodeId),startDevBoxPending:h.has(K.nodeId)})})]}),e.jsx("div",{className:R("grid transition-[grid-template-rows] duration-300 ease-in-out",it?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:K.dirs.map(De=>{const Ve=`${Ee}::${De.path}`,Et=Ie.has(Ve),ht=za(De.path),lt=N?.get(Ve),At=lt?{visibleTasks:De.tasks,hiddenCompletedCount:Math.max(0,lt.total-lt.returned)}:Dm(De.tasks,ut.has(Ve),s),{visibleTasks:gt,hiddenCompletedCount:_e}=At;return e.jsxs("div",{className:R("space-y-0.5 rounded-xl",Le&&"pl-2.5"),children:[e.jsx(Tm,{dirPath:De.path,label:ht,taskCount:De.tasks.length,collapsed:Et,onToggle:()=>He(Ve),onCreateTask:()=>Y("chat",{assignTo:K.nodeId,project:De.path==="default workspace"?"":De.path}),onOpenCapabilities:K.nodeId&&ne?()=>ne(K.nodeId,De.path==="default workspace"?u?.get(K.nodeId)??De.path:De.path):void 0}),e.jsx("div",{className:R("grid transition-[grid-template-rows] duration-300 ease-in-out",Et?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:R("overflow-hidden",Le?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[gt.map(de=>{const Me=de.id===s,Be=de.assignedTo?g.get(de.assignedTo):void 0,Ue=!!de.assignedTo&&(Be?Be==="offline":de.assignedNodeAvailable===!1);return e.jsxs("div",{className:R("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",Me?'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:[ce&&e.jsx("div",{className:"flex shrink-0",onClick:qt=>qt.stopPropagation(),children:e.jsx(is,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:v.has(de.id),onCheckedChange:qt=>_(de.id,qt===!0),"aria-label":`Select ${de.title}`})}),e.jsxs("button",{type:"button",onClick:()=>q(de.id),"aria-current":Me?"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:R("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",Me?"text-foreground":"text-foreground/80"),children:de.title})}),e.jsx("span",{className:R("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",Me?"text-primary/75":"text-muted-foreground/55"),children:al(de.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:de.agent}),de.activeShare&&e.jsx($e,{variant:"outline",className:"rounded-sm border-primary/25 bg-primary/8 px-1 py-0 text-[8px] leading-3 text-primary shadow-none",children:"shared"}),Ue&&e.jsx($e,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/8 px-1 py-0 text-[8px] leading-3 text-destructive shadow-none",children:"unavailable"})]}),e.jsx(La,{status:de.status,isNative:de.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},de.id)}),_e>0&&e.jsxs("button",{type:"button",onClick:()=>{lt&&p?p(lt):Ke(Ve)},className:"mt-1 flex w-full items-center justify-center gap-1 rounded-sm border border-dashed border-border/55 bg-background/35 px-2 py-1 text-[9px] font-medium text-muted-foreground transition-colors hover:border-primary/35 hover:bg-primary/8 hover:text-primary","aria-label":`Load ${_e} more completed tasks in ${ht}`,children:[e.jsx(Je,{className:"h-3 w-3"}),"Load ",_e," more completed"]})]})})})]},Ve)})})})]},Ee)})}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(K=>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+K*12}%`,animationDelay:`${K*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${K*120+60}ms`}})]})]})},K))}):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."})}),ye?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:ce&&J>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[Ut,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:Ce}),Ct]})]}):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:Ce}),ce&&e.jsx(Z,{variant:"ghost",size:"sm",onClick:ot,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]}),e.jsx(km,{node:oe,open:oe!==null,onOpenChange:K=>{K||ge(null)}})]})}async function _m(t,s){try{const n=await ol(t,s),r={...n,url:Pa(n.url)};if(globalThis.navigator?.clipboard?.writeText)try{await globalThis.navigator.clipboard.writeText(r.url),le.success("Shared link copied")}catch{le.success("Shared link created")}else le.success("Shared link created");return r}catch(n){le.error(n instanceof Error?n.message:"Failed to create shared link");return}}async function Mm(t){try{return await il(t),le.success("Shared link stopped"),!0}catch(s){return le.error(s instanceof Error?s.message:"Failed to stop shared link"),!1}}function Pm(t,s,n){const r=o.useCallback(()=>{s(),n()},[s,n]),a=o.useCallback(async l=>{if(!t)return;const d=await _m(t.id,l);return d&&r(),d},[t,r]),i=o.useCallback(async()=>{if(!t)return!1;const l=await Mm(t.id);return l&&r(),l},[t,r]);return{handleShareTask:a,handleStopShareTask:i}}function ha(t,s,n){const r=o.useRef(s);r.current=s,o.useEffect(()=>{let l=0,d=0;const c=f=>{const u=f.touches[0];u&&(l=u.clientX,d=u.clientY)},m=f=>{const u=f.changedTouches[0];if(!u)return;const g=u.clientX-l;Math.abs(u.clientY-d)>100||Math.abs(g)<50||(g>0?r.current.onSwipeRight?.():r.current.onSwipeLeft?.())},b=t?.current??document;return b.addEventListener("touchstart",c,{passive:!0}),b.addEventListener("touchend",m,{passive:!0}),()=>{b.removeEventListener("touchstart",c),b.removeEventListener("touchend",m)}},[t,n?.threshold,n?.maxVertical])}const Im="(min-width: 1024px)",Lm="(min-width: 1800px)";function fa(t){return globalThis.window?.matchMedia?.(t)?.matches??!1}function Rm(){const t=globalThis.document?.documentElement;if(!t||!globalThis.window?.getComputedStyle)return 16;const s=Number.parseFloat(globalThis.window.getComputedStyle(t).fontSize);return Number.isFinite(s)&&s>0?s:16}function Bm(){const[t,s]=o.useState(()=>ll(ir(),dl({operationsOpen:fa(Lm)}))),[n,r]=o.useState(!1),a=o.useRef(null),i=o.useRef(null),l=o.useRef(null),d=t.layout.desktopTasksOpen,c=t.layout.operationsOpen,m=t.sizes;o.useEffect(()=>{cl(ir(),t)},[t]);const b=o.useCallback((A,h)=>{s(E=>{const x=E.layout[A],v=typeof h=="function"?h(x):h;return v===x?E:{...E,layout:{...E.layout,[A]:v}}})},[]),f=o.useCallback(A=>{b("desktopTasksOpen",A)},[b]),u=o.useCallback(A=>{b("operationsOpen",A)},[b]);ha(i,{onSwipeLeft:()=>r(!1)}),ha(l,{onSwipeRight:()=>u(!1)});const g=o.useCallback(()=>{if(fa(Im)){f(A=>!A);return}r(A=>!A)},[f]);o.useEffect(()=>{const A=E=>{const x=a.current;if(!x)return;E.preventDefault();const v=ml(x.panel,x.startSize,x.startClientX,x.startClientY,E.clientX,E.clientY,x.rootFontSize);s(k=>({...k,sizes:{...k.sizes,[x.panel]:v}}))},h=()=>{a.current=null};return globalThis.window?.addEventListener("pointermove",A),globalThis.window?.addEventListener("pointerup",h),globalThis.window?.addEventListener("pointercancel",h),()=>{globalThis.window?.removeEventListener("pointermove",A),globalThis.window?.removeEventListener("pointerup",h),globalThis.window?.removeEventListener("pointercancel",h)}},[]);const N=o.useCallback((A,h)=>{h.preventDefault(),h.currentTarget.setPointerCapture?.(h.pointerId),a.current={panel:A,startSize:m[A],startClientX:h.clientX,startClientY:h.clientY,rootFontSize:Rm()}},[m]),y=o.useCallback((A,h)=>{h.preventDefault(),s(E=>({...E,sizes:{...E.sizes,[A]:ul(A,E.sizes[A],h.deltaY)}}))},[]);return{desktopTasksOpen:d,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:c,operationsPanelRef:l,panelResize:{sizes:{tasks:$s(m.tasks),operations:$s(m.operations),terminal:$s(m.terminal)},onPointerDown:N,onWheel:y},setMobileTasksPanelOpen:r,setOperationsOpen:u,toggleTasksPanel:g}}function Om(t,s){const n=s.taskId,r=s.updates;return typeof n!="string"||!r||typeof r!="object"?t:t.map(a=>a.id===n?{...a,...r}:a)}const Fm="notify_desktop_task";function zm(t=Ao()){const s=t?.__TAURI__?.core?.invoke;return typeof s=="function"?s:null}async function Um(t,s=Ao()){const n=zm(s);return n?(await n(Fm,t),!0):!1}function $m(t,s){const n=[];for(const r of s){const a=qm(r.status);if(!a)continue;const i=t.get(r.id);!i||i.status===r.status||n.push({taskId:r.id,title:r.title.trim()||"Meshy task",status:a,assignedNodeName:r.assignedNodeName??null,projectPath:r.effectiveProjectPath??r.project??null})}return n}function qm(t){return t==="completed"||t==="failed"?t:null}function Ao(){return typeof window>"u"?null:window}function Vm({isLeader:t,selfId:s}){return{...!t&&s?{assignedTo:s}:{},completedLimitPerProject:zn}}function Ln(t){return`${t.assignedTo??"__unassigned__"}::${t.projectPath}`}function Hm(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 Km(t,s,n=new Set){return!s||n.has(s.id)||t.some(r=>r.id===s.id)?t:no(t,s)}function Gm({isLeader:t,selfId:s,sseConnected:n,preservedTask:r,subscribe:a}){const[i,l]=o.useState([]),[d,c]=o.useState([]),[m,b]=o.useState(!0),[f,u]=o.useState(null),g=o.useRef(new Set),N=o.useRef(null),y=o.useRef(null),A=o.useCallback(async()=>{try{const v=await lr(Vm({isLeader:t,selfId:s}));l(Km(v.tasks,r,g.current)),c(v.completedGroups??[]),u(null)}catch(v){u(v instanceof Error?v.message:"Failed to load tasks")}finally{b(!1)}},[t,r,s]),h=o.useCallback(async v=>{if(!v.hasMore||!v.nextCursor)return;const k=await lr({status:"completed",assignedTo:v.assignedTo??"__unassigned__",projectPath:v.projectPath,cursor:v.nextCursor,limit:zn});l(C=>Hm(C,k.tasks)),c(C=>C.map(T=>Ln(T)===Ln(v)?{...T,returned:Math.min(T.total,T.returned+k.tasks.length),hasMore:k.hasMore===!0,nextCursor:k.nextCursor??null}:T))},[]),E=o.useCallback(()=>{y.current===null&&(y.current=window.setTimeout(()=>{y.current=null,A()},hl))},[A]),x=o.useCallback(v=>{const k=new Set(v);if(k.size!==0){for(const C of k)g.current.add(C);l(C=>C.filter(T=>!k.has(T.id)))}},[]);return fl(A,gl(n)),o.useEffect(()=>()=>{y.current!==null&&(window.clearTimeout(y.current),y.current=null)},[]),o.useEffect(()=>{const v=N.current;if(v)for(const k of $m(v,i))Um(k).catch(()=>{});N.current=new Map(i.map(k=>[k.id,k]))},[i]),o.useEffect(()=>{const v=[a("task.updated",k=>{l(C=>Om(C,k.data))}),a("task.status",k=>{l(C=>xl(C,k.data))}),a("node",k=>{dr(k.type)&&E()}),a("task",k=>{if(k.type==="task.deleted"){const C=k.data.taskId;typeof C=="string"&&g.current.add(C),l(T=>pl(T,k.data))}dr(k.type)&&E()})];return()=>v.forEach(k=>k())},[a,E]),{completedGroups:d,fetchTasks:A,loadCompletedTasksPage:h,removeTasksFromList:x,setTasks:l,tasks:i,tasksError:f,tasksLoading:m}}function Do(t){return t.map(s=>({...s}))}function Wm(t,s){const n=s.get(t);return{logs:n?Do(n.logs):[],transcriptLoading:n?.loaded!==!0}}function Qm(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function Ym(t,s){const n=t.data.name;if(typeof n=="string"&&n.length>0)return n;const r=t.data.nodeId;return typeof r=="string"?s?.get(r)??r:"node"}function Jm({cluster:t,subscribe:s}){o.useEffect(()=>{if(t?.self?.role!=="leader")return;const n=new Map(t.nodes.map(r=>[r.id,r.name]));return n.set(t.self.id,t.self.name),s("node",r=>{const a=Ym(r,n),i=Qm(t,r);r.type==="node.joined"&&!i&&le.success(`${a} joined the cluster`),r.type==="node.left"&&!i&&le.message(`${a} left the cluster`)})},[t,s])}const Zm=[0,300,1e3,2e3];function Xm({task:t,getActiveTaskId:s,setLogs:n,setPendingMessages:r,setTranscriptLoading:a}){t.conversationKind==="nativeSession"&&(async()=>{try{for(const i of Zm){if(i>0&&await new Promise(l=>setTimeout(l,i)),s()!==t.id)return;try{const l=await Sn(t.id);if(s()!==t.id||(n(d=>Qa(d,l.logs)),r(d=>Tn(d,l.logs)),l.total>0))return}catch{}}}finally{s()===t.id&&a?.(!1)}})()}const _o=8;function eh(t,s){return Oe(t??{})===Oe(s??{})}function th(t){return t&&"status"in t&&typeof t.status=="string"?t.status:void 0}function xa(t,s){return{...t,enabled:!0,alwaysOnline:s}}function Mo(t){return t?.status?.trim()||t?.lastStatus?.trim()||"Unknown"}function sh({operationStarting:t,loading:s,refreshing:n,savedStatus:r,fallbackStatus:a}){return t?"Starting":s?"Listing DevBoxes":n?"Refreshing":r??a}async function nh(t,s=$a){return(await s({nodeId:t,kind:"devbox.start"})).filter(r=>r.kind==="devbox.start").sort((r,a)=>(a.updatedAt??a.createdAt)-(r.updatedAt??r.createdAt)).slice(0,_o)}function rh(t){return t.charAt(0).toUpperCase()+t.slice(1)}function ah(t){const s=t.completedAt??t.startedAt??t.updatedAt??t.createdAt;return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(s))}function oh(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function pa(t,s){const r=oh(t)?.[s];return typeof r=="string"&&r.trim()?r.trim():null}function ih(t){if(t.status==="failed")return t.error||"Operation failed";const s=pa(t.result,"operationId");if(s)return`MCP operation ${s}`;const n=pa(t.payload,"previousStatus");return n?`Previous DevBox status: ${n}`:t.status==="succeeded"?"Completed":"Waiting for completion"}function lh(t){return t==="succeeded"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":t==="failed"?"border-destructive/30 bg-destructive/10 text-destructive":t==="running"?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":"border-border/70 bg-muted/40 text-muted-foreground"}function ga({devbox:t,showStatus:s=!1}){return e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"font-medium",children:t.name}),t.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",t.projectName]})]}),s&&e.jsx("span",{className:"ml-auto shrink-0 rounded-sm border border-border/70 bg-background/70 px-1.5 py-0 text-[10px] leading-none text-muted-foreground",children:Mo(t)})]})}function dh({error:t,loading:s,onToggle:n,open:r,operations:a}){return e.jsxs("div",{className:"min-w-0 max-w-full overflow-hidden rounded-sm border border-border/60 bg-muted/20 text-xs",children:[e.jsxs("button",{type:"button",onClick:n,"aria-expanded":r,className:"flex h-8 w-full items-center gap-2 px-3 text-left text-[11px] text-foreground hover:bg-muted/30",children:[e.jsx(Je,{className:R("h-3 w-3 shrink-0 text-muted-foreground transition-transform",!r&&"-rotate-90")}),e.jsx(Ns,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Operations history"}),s&&e.jsx(ue,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}),!s&&a.length>0&&e.jsx("span",{className:"shrink-0 rounded-sm border border-border/70 bg-background/60 px-1.5 py-0 text-[10px] leading-none text-muted-foreground",children:a.length})]}),r&&e.jsxs("div",{className:"max-h-44 min-w-0 max-w-full overflow-y-auto border-t border-border/50 px-2 py-1.5",children:[s&&a.length===0&&e.jsxs("div",{className:"flex h-7 items-center gap-2 px-1 text-[10px] text-muted-foreground",children:[e.jsx(ue,{className:"h-3 w-3 animate-spin"}),"Loading operations"]}),t&&e.jsx("div",{className:"px-1 py-1 text-[10px] text-destructive",children:t}),!s&&!t&&a.length===0&&e.jsx("div",{className:"px-1 py-1 text-[10px] text-muted-foreground",children:"No DevBox operations yet."}),a.map(i=>{const l=ih(i);return e.jsxs("div",{className:"flex w-full min-w-0 max-w-full items-start gap-2 overflow-hidden rounded-sm px-1 py-1.5 text-[11px] hover:bg-background/40",children:[e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium text-foreground",children:"Start DevBox"}),e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:ah(i)})]}),e.jsx("div",{className:"mt-0.5 w-full min-w-0 max-w-full overflow-x-auto whitespace-nowrap text-[10px] leading-3.5 text-muted-foreground",title:l,children:e.jsx("span",{className:"inline-block min-w-max",children:l})})]}),e.jsx("span",{className:R("shrink-0 rounded-sm border px-1.5 py-0 text-[10px] leading-4",lh(i.status)),children:rh(i.status)})]},i.id)})]})]})}function ch({node:t,open:s,startInProgress:n=!1,onOpenChange:r,onRefresh:a}){const i=t?.id??null,l=s&&!n&&na(t?.status,t?.devbox??null),[d,c]=o.useState([]),[m,b]=o.useState(()=>t?.devbox?Oe(t.devbox):""),[f,u]=o.useState(()=>t?.devbox??null),[g,N]=o.useState(()=>ra(t?.devbox??null)),[y,A]=o.useState(!1),[h,E]=o.useState(l),[x,v]=o.useState(!1),[k,C]=o.useState(!1),[T,I]=o.useState(()=>t?.devbox?.alwaysOnline===!0),[S,P]=o.useState(!1),[D,_]=o.useState([]),[B,z]=o.useState(!1),[Q,Y]=o.useState(null),X=o.useMemo(()=>{const M=d.find(W=>Oe(W)===m);return M||(Lt(f)&&Oe(f)===m?f:void 0)},[f,d,m]),ee=th(X??void 0),ne=g?ee??f?.lastStatus:f?.lastStatus??ee,U=t?.status==="online"||t?.status==="busy"?"Running":"Unknown",O=k||n,p=sh({operationStarting:O,loading:y,refreshing:h,savedStatus:ne,fallbackStatus:U}),q=g&&!!X&&!eh(f,X),j=f?.alwaysOnline===!0!==T,V=bm({nodeStatus:t?.status,status:p,current:f,selected:X}),F=!!V,H=!!X&&(q||j)&&!F,L=X??f,ae=o.useCallback(async()=>{if(i){E(!0);try{const M=await bl(i);u(M.devbox),b(Oe(M.devbox))}catch(M){le.error(M instanceof Error?M.message:"Failed to refresh DevBox status")}finally{E(!1)}}},[i]),oe=o.useCallback(async M=>{A(!0);try{const W=await vl();c(W),b(me=>vm({previousKey:me,baseDevBox:M,listed:W}))}catch(W){le.error(W instanceof Error?W.message:"Failed to load DevBoxes")}finally{A(!1)}},[]);o.useEffect(()=>{if(!s||!i)return;let M=!1;const W=t?.devbox??null,me=ra(W),be=!n&&na(t?.status,W);A(!1),E(be),N(me),u(W),I(W?.alwaysOnline===!0),P(!1),b(Lt(W)?Oe(W):""),c([]);async function Ie(){be&&await ae(),!M&&me&&await oe(W)}return Ie(),()=>{M=!0}},[oe,t?.devbox,t?.status,i,s,ae,n]),o.useEffect(()=>{if(!s||!i)return;let M=!1;const W=i;async function me(){z(!0),Y(null),_([]);try{const be=await nh(W);if(M)return;_(be)}catch(be){if(M)return;_([]),Y(be instanceof Error?be.message:"Failed to load operation history")}finally{M||z(!1)}}return me(),()=>{M=!0}},[i,s]);async function ge(){N(!0),d.length===0&&await oe(f)}async function re(){if(!(!t||!X)){v(!0);try{const M=await cr(t.id,xa(X,T));u(M.node.devbox??null),M.node.devbox&&b(Oe(M.node.devbox)),N(!1),le.success(`Configured DevBox for ${t.name}`),await a?.()}catch(M){le.error(M instanceof Error?M.message:"Failed to configure DevBox")}finally{v(!1)}}}async function G(){if(!(!t||!V)){C(!0);try{if(X&&(q||j)){const W=await cr(t.id,xa(X,T));u(W.node.devbox??null),W.node.devbox&&b(Oe(W.node.devbox)),N(!1)}const{operation:M}=await qa(t.id);u(W=>W&&{...W,lastStatus:"Starting",checkedAt:Date.now(),operationId:M.id}),_(W=>[M,...W.filter(me=>me.id!==M.id)].slice(0,_o)),le.success(`Start requested for ${t.name}`),await a?.()}catch(M){le.error(M instanceof Error?M.message:"Failed to start DevBox")}finally{C(!1)}}}const J=y?"Loading DevBoxes...":d.length===0?"No DevBoxes available":"Select a DevBox",ce=p==="Running"&&t?.status==="offline";return e.jsx(yt,{open:s,onOpenChange:r,children:e.jsxs(jt,{className:"w-[calc(100vw-2rem)] max-w-md grid-cols-[minmax(0,1fr)] gap-3 overflow-hidden rounded-sm p-4",children:[e.jsxs(Ts,{className:"min-w-0 max-w-full space-y-1 overflow-hidden",children:[e.jsx(Ot,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(Es,{className:"max-w-full text-xs",children:["Bind ",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:"min-w-0 max-w-full space-y-3 overflow-hidden",children:[(g||L)&&e.jsxs("div",{className:"flex min-h-9 w-full min-w-0 max-w-full items-center justify-between gap-3 overflow-hidden rounded-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:g?e.jsxs(je,{value:m,onValueChange:b,disabled:y||x||k||d.length===0,children:[e.jsx(Ne,{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:y&&!X?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),J]}):X?e.jsx(ga,{devbox:X}):e.jsx(Pe,{placeholder:J})}),e.jsx(ke,{children:d.map(M=>e.jsx(he,{value:Oe(M),textValue:`${M.name} ${M.projectName??""} ${Mo(M)}`,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(ga,{devbox:M,showStatus:!0})},Oe(M)))})]}):L&&e.jsxs("div",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:L.name}),L.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",L.projectName]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs($e,{variant:"outline",className:"rounded-sm px-1.5 py-0 text-[10px]",children:[(y||h)&&e.jsx(ue,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),p]}),f?.name&&e.jsx(Z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{ge()},disabled:y||x||O||g,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-sm text-muted-foreground hover:text-foreground",children:y&&g?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Ft,{className:"h-3 w-3"})})]})]}),ce&&e.jsx("div",{className:"rounded-sm border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:"DevBox is running, but the Meshy node is not connected yet."}),e.jsxs("label",{className:"flex min-h-9 w-full min-w-0 max-w-full items-start gap-2 overflow-hidden rounded-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(is,{checked:T,onCheckedChange:M=>I(M===!0),disabled:x||k||O,"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.jsx(dh,{error:Q,loading:B,onToggle:()=>P(M=>!M),open:S,operations:D})]}),e.jsxs(Ra,{className:"gap-2 sm:space-x-0",children:[e.jsx(Z,{variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:x||k,className:"h-8 rounded-sm text-xs",children:"Close"}),F&&e.jsxs(Z,{size:"sm",onClick:G,disabled:k,className:"h-8 rounded-sm text-xs",children:[k?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ds,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!F&&e.jsxs(Z,{size:"sm",onClick:re,disabled:!H||x,className:"h-8 rounded-sm text-xs",children:[x&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function uh(t,s=$a){if(t.length===0)return new Set;const n=new Set(t),[r,a]=await Promise.all([s({kind:"devbox.start",status:"queued"}),s({kind:"devbox.start",status:"running"})]);return new Set([...r,...a].filter(i=>n.has(i.nodeId)).map(i=>i.nodeId))}function mh({cluster:t,refresh:s}){const[n,r]=o.useState(null),[a,i]=o.useState(null),[l,d]=o.useState(()=>new Set),[c,m]=o.useState(()=>new Set),b=o.useMemo(()=>t?.nodes.find(h=>h.id===n)??null,[t?.nodes,n]),f=o.useMemo(()=>new Set((t?.nodes??[]).filter(h=>h.devbox?.enabled).map(h=>h.id)),[t?.nodes]),u=o.useMemo(()=>new Set((t?.nodes??[]).filter(h=>Ps(h.status,h.devbox?.lastStatus,h.devbox)).map(h=>h.id)),[t?.nodes]),g=o.useMemo(()=>new Set((t?.nodes??[]).filter(h=>Rt(h.devbox?.lastStatus)).map(h=>h.id)),[t?.nodes]),N=o.useMemo(()=>{const h=new Set(l);a&&h.add(a);for(const E of c)h.add(E);for(const E of g)h.add(E);return h},[c,a,l,g]);o.useEffect(()=>{let h=!1;const E=[...f];async function x(){try{const v=await uh(E);h||m(v)}catch{h||m(new Set)}}return x(),()=>{h=!0}},[f]),o.useEffect(()=>{d(h=>{let E=!1;const x=new Set(h);for(const v of h){const k=t?.nodes.find(C=>C.id===v);k?.status!=="online"&&(!k?.devbox?.lastStatus||Rt(k.devbox.lastStatus))||(x.delete(v),E=!0)}return E?x:h})},[t?.nodes]);const y=o.useCallback(async h=>{const E=t?.nodes.find(x=>x.id===h);if(E){i(h),d(x=>new Set(x).add(h));try{await qa(h),le.success(`Start requested for ${E.name}`),s()}catch(x){d(v=>{const k=new Set(v);return k.delete(h),k}),le.error(x instanceof Error?x.message:"Failed to start DevBox")}finally{i(null)}}},[t?.nodes,s]);return{devBoxDialog:e.jsx(ch,{node:b,open:n!==null,startInProgress:b?N.has(b.id):!1,onOpenChange:h=>{h||r(null)},onRefresh:s}),devBoxNodeIds:f,devBoxStartNodeId:a,devBoxStartNodeIds:u,devBoxStartingNodeIds:N,openDevBox:r,startDevBox:y}}function hh(t){const[s,n]=o.useState(null),r=o.useCallback(i=>{t&&n(i)},[t]);return{nodeSettingsDialog:e.jsx(wl,{open:s!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:s??void 0,showTrigger:!1}),openNodeSettings:r}}function fh(t=!1){return!t}function xh({activeTaskId:t,fetchActiveTask:s,isRunning:n=!1,setPendingMessages:r,setTask:a,setTasks:i}){const l=o.useCallback((m,b)=>{a(f=>f&&f.id===m?{...f,queuedMessages:b}:f),i(f=>f.map(u=>u.id===m?{...u,queuedMessages:b}:u))},[a,i]),d=o.useCallback(async m=>{if(!t)return!1;const b=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`,f=fh(n);f&&r(u=>[...u,{id:b,content:m,timestamp:new Date().toISOString()}]);try{const u=await yl(t,m);return u.queued&&(f&&r(g=>g.filter(N=>N.id!==b)),u.queuedMessages&&l(t,u.queuedMessages)),s(),!0}catch(u){return f&&r(g=>g.filter(N=>N.id!==b)),le.error(u instanceof Error?u.message:"Failed to send message"),!1}},[t,s,n,r,l]);return{cancelQueuedMessage:o.useCallback(async m=>{if(t)try{const b=await jl(t,m);l(t,b.queuedMessages),s()}catch(b){le.error(b instanceof Error?b.message:"Failed to cancel queued message")}},[t,s,l]),queueFollowUpMessage:d}}const ba="grid-cols-[1.5rem_5.25rem_4rem_minmax(8rem,1fr)_4rem_4rem_6rem]",ph={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function gh(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(a=>a?.toLowerCase().includes(n)):!0)}function Po(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 bh({items:t,selectedIds:s,activeId:n,onToggleSelected:r,onOpenDetail:a}){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:R("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",ba),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:()=>a(i),className:R("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",ba,n===i.id&&"bg-primary/10 text-primary shadow-[inset_2px_0_0_hsl(var(--primary))]"),children:[e.jsx("span",{onClick:l=>l.stopPropagation(),children:e.jsx(is,{className:"h-3 w-3",checked:s.has(i.id),onCheckedChange:l=>r(i.id,l===!0),"aria-label":`Select ${i.name}`})}),e.jsx(vh,{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:Po(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 vh({agent:t}){const s=ph[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 va=320,wa=560,Io=384,ya=360;function wh(t,s=wa+ya){const n=Math.max(va,Math.min(wa,s-ya));return Math.min(Math.max(Math.round(t),va),n)}function yh(t,s,n,r){return wh(t+s-n,r)}function jh({detail:t,deleting:s=!1,onDelete:n,desktopWidth:r=Io,pending:a=!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:a?"Loading capability metadata...":"No capability selected."});const l=t.kind==="mcp"?"mcp":"files";return e.jsxs("aside",{"data-capability-detail-panel":"true",style:i,className:"flex min-h-0 w-full shrink-0 animate-panel-settle flex-col bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-2.5 lg:w-[var(--capability-detail-width)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold leading-5 text-foreground",children:t.name}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-1",children:[e.jsx($e,{variant:"secondary",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary",children:t.agent}),e.jsx($e,{variant:"outline",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary/90",children:t.kind})]})]}),n&&e.jsxs(Yt,{children:[e.jsx(kn,{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(Ua,{className:"h-3.5 w-3.5"})})}),e.jsxs(Jt,{className:"max-w-[22rem] gap-2 rounded-xl p-4",children:[e.jsxs(Zt,{className:"space-y-1",children:[e.jsxs(Xt,{className:"text-sm",children:["Delete ",t.name,"?"]}),e.jsxs(es,{className:"text-[11px] leading-4",children:["This removes the selected ",t.kind," from ",t.scope.kind==="global"?"the user profile":"this project","."]})]}),e.jsxs(ts,{className:"gap-1 pt-0 sm:space-x-1",children:[e.jsx(ss,{className:"h-7 rounded-lg px-2 text-[11px]",children:"Cancel"}),e.jsx(ns,{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(vs,{label:"Version",value:t.version??"-"}),e.jsx(vs,{label:"Size",value:Po(t)}),e.jsx(vs,{label:"Files",value:String(t.fileCount)}),e.jsx(vs,{label:"Source",value:t.source??"local"})]}),e.jsxs(Bn,{defaultValue:l,className:"mt-2 flex min-h-0 flex-1 flex-col",children:[e.jsxs(Rn,{className:"grid h-auto grid-cols-2 rounded-sm bg-primary/8 p-0.5",children:[t.kind==="mcp"?e.jsx(vt,{value:"mcp",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"MCP"}):e.jsx(vt,{value:"files",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"Files"}),e.jsx(vt,{value:"readme",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"README"})]}),t.kind==="mcp"?e.jsx(ct,{value:"mcp",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(Nh,{detail:t})}):e.jsx(ct,{value:"files",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(kh,{detail:t})}),e.jsx(ct,{value:"readme",className:"mt-2 min-h-0 flex-1 overflow-auto",children:t.readmeMarkdown?e.jsx(fd,{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(Yn,{children:"No README content."})})]},t.id)]})}function Nh({detail:t}){const s=t.mcpPreview??[];return s.length===0?e.jsx(Yn,{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 kh({detail:t}){const s=t.fileTree??[];return s.length===0?e.jsx(Yn,{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 Yn({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 vs({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 Sh=20,Ch=288,Th=360,Eh=440;function Ah(){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 Dh({triggerRect:t,targetRect:s,viewportRect:n,compact:r,browserOpen:a=!1,portalAlign:i,cssZoom:l=1}){const d=Number.isFinite(l)&&l>0?l:1,c=8,m=n.top+c,b=n.bottom-c,f=n.left+c,u=n.right-c,g=Math.max(0,b-t.bottom-4),N=Math.max(0,t.top-m-4),y=r?N<140&&g>N:g>=220||g>=N,A=y?g:N,h=Math.max(140,b-m),E=r&&a,k=Math.min(h,E?Eh:320,Math.max(E?Th:140,A)),C=Ch*d,T=i==="end"?t.right-C:t.left,S=(Math.max(f,Math.min(T,u-C))-s.left)/d;if(!y&&!E)return{left:S,bottom:(s.bottom-(t.top-4))/d,maxHeight:k/d};const P=y?t.bottom+4:t.top-k-4,D=Math.max(m,Math.min(P,b-k));return{left:S,top:(D-s.top)/d,maxHeight:k/d}}function Jn(t){if(!t.workDir)return[];const s=[],n=new Set,r=a=>{!a||n.has(a)||(n.add(a),s.push(a))};r(t.workDir);for(const a of t.workDirFolders??[])r(Ro(a)?a:Bo(t.workDir,a));return s}function _h(t,s){if(t.kind==="global")return{nodeId:s.id,scope:{kind:"global"}};const n=Jn(s),r=n.find(a=>a===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 Mh(t,s){return{nodeId:t,scope:s}}function ja(t,s,n){const r=s.trim();return!r||r==="."?t.workDir??r:n||Ro(r)?r:t.workDir?Bo(t.workDir,r):r}function Ph({node:t,scope:s,clusterNodes:n,onSelectionChange:r}){const a=o.useMemo(()=>Bh(n,t),[n,t]),i=o.useMemo(()=>Jn(t),[t]),l=o.useMemo(()=>a.map(d=>({value:d.id,label:d.name,description:`${d.role} · ${d.status}`,status:d.status})),[a]);return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-2",children:[e.jsx(Rh,{ariaLabel:"Capability node",value:t.name,description:`${t.role} · ${t.status}`,options:l,selectedValue:t.id,onSelect:d=>{const c=a.find(m=>m.id===d);c&&r?.(_h(s,c))}}),e.jsx(Lo,{node:t,projectPaths:i,selectedScope:s,onSelect:d=>r?.(Mh(t.id,d))}),e.jsx(Ih,{node:t})]})}function Ih({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:R("h-1.5 w-1.5 shrink-0 rounded-full",rs(t.status))})]})}function Lo({node:t,projectPaths:s,selectedScope:n,onSelect:r,compact:a=!1,portal:i=!1,portalAlign:l="start"}){const[d,c]=o.useState(!1),[m,b]=o.useState(null),[f,u]=o.useState(!1),[g,N]=o.useState(!1),[y,A]=o.useState(null),[h,E]=o.useState(!1),[x,v]=o.useState(null),k=o.useRef(null),C=o.useRef(null),T=o.useRef(null),I=o.useMemo(()=>s.map(U=>({value:U,label:ka(U),description:U})),[s]),S=n.kind==="project"?n.projectPath:void 0,P=n.kind==="global"?"Global":ka(n.projectPath),D=n.kind==="global"?"Global":n.projectPath,_=o.useCallback(()=>!i||typeof document>"u"?null:C.current?.closest('[data-capability-share-dialog="true"]')??document.body,[i]),B=o.useCallback(()=>{if(!i||!C.current||typeof window>"u")return;const U=C.current.getBoundingClientRect(),O=_(),p=O&&O!==document.body?O.getBoundingClientRect():{left:0,top:0,bottom:window.innerHeight};v(Dh({triggerRect:U,targetRect:p,viewportRect:{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},compact:a,browserOpen:h,portalAlign:l,cssZoom:Ah()}))},[h,a,_,i,l]);o.useEffect(()=>{d||E(!1)},[d]),o.useEffect(()=>{if(!d)return;const U=O=>{if(!(O.target instanceof Node))return;const p=O.composedPath(),q=k.current?p.includes(k.current):!1,j=T.current?p.includes(T.current):O.target instanceof Element&&!!O.target.closest('[data-capability-scope-menu="true"]');!q&&!j&&c(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[d]),o.useEffect(()=>{if(!(!d||!i))return B(),window.addEventListener("resize",B),window.addEventListener("scroll",B,!0),()=>{window.removeEventListener("resize",B),window.removeEventListener("scroll",B,!0)}},[d,i,B]);const z=async(U,O=0,p=!1)=>{if(t.workDir){A(null),p?N(!0):u(!0);try{const q=await _a(t.id,{path:U||".",limit:Sh,offset:O,directoriesOnly:!0,allowAbsolute:!0});b(j=>p&&j?{...q,entries:[...j.entries,...q.entries]}:q)}catch(q){A(q instanceof Error?q.message:"Failed to browse folders"),p||b(null)}finally{u(!1),N(!1)}}};o.useEffect(()=>{!d||!h||!t.workDir||(b(null),A(null),z(S||"."))},[h,d,t.id,t.workDir,S]);const Q=(U,O=!1)=>{r({kind:"project",projectPath:ja(t,U,O)}),c(!1)},Y=()=>{r({kind:"global"}),c(!1)},X=m?ja(t,m.currentPath,m.isAbsolute):S??t.workDir??"",ee=i?_():null,ne=e.jsxs("div",{ref:T,"data-capability-scope-menu":"true","aria-hidden":!d,onClick:U=>U.stopPropagation(),onMouseDown:U=>U.stopPropagation(),onPointerDown:U=>U.stopPropagation(),style:i&&x?{left:x.left,top:x.top,bottom:x.bottom,height:a&&h?x.maxHeight:void 0,maxHeight:x.maxHeight}:void 0,className:R(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&&(a?"top-7":"top-9"),!d&&"hidden"),children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 p-1",children:[e.jsx("div",{className:R("px-2 text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",a?"pb-0.5 pt-0.5 leading-3":"pb-1 pt-1"),children:"Scope"}),e.jsxs("div",{className:R("overflow-y-auto pr-0.5",a?"max-h-32":"max-h-40"),children:[e.jsx(Na,{icon:"global",label:"Global",selected:n.kind==="global",onSelect:Y,compact:a}),I.length>0?I.map(U=>e.jsx(Na,{icon:"folder",label:U.label,description:U.description,selected:S===U.value,onSelect:()=>Q(U.value,!0),compact:a},U.value)):e.jsx("div",{className:R("flex items-center px-2 text-muted-foreground",a?"h-7 text-[9px]":"h-8 text-[10px]"),children:"No known projects"})]})]}),e.jsxs("div",{className:R("border-b border-border/55",h?"flex min-h-0 flex-1 flex-col":"shrink-0"),children:[e.jsxs("button",{type:"button","aria-expanded":h,onClick:()=>E(U=>!U),className:R("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",a?"py-1 leading-3":"py-1.5"),children:[e.jsx(Bt,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Browse folders"}),e.jsx(Je,{className:R("h-3 w-3 shrink-0 transition-transform duration-200",h&&"rotate-180")})]}),h&&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:()=>m?.parentPath&&void z(m.parentPath),disabled:!m?.parentPath||f,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(Ya,{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:X,children:X}),m&&e.jsx("button",{type:"button",onClick:()=>Q(m.currentPath,m.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:R("min-h-0 flex-1 overflow-y-auto",a?"min-h-[8.25rem]":"max-h-56"),children:[t.workDir?f?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[9px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading folders..."]}):m&&m.entries.length>0?e.jsxs(e.Fragment,{children:[m.entries.map(U=>e.jsx(Lh,{entry:U,onSelect:()=>Q(U.path,m.isAbsolute),onOpen:()=>{z(U.path)}},U.path)),m.hasMore&&e.jsxs("button",{type:"button",onClick:()=>{z(m.currentPath,m.entries.length,!0)},disabled:g,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:[g?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Ad,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:y??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:"This node has no working directory."}),y&&m&&m.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[9px] text-destructive",children:y})]})]})]})]});return e.jsxs("div",{ref:k,className:"relative min-w-0",children:[e.jsxs("button",{ref:C,type:"button","aria-label":"Capability location","aria-expanded":d,title:D,onClick:()=>c(U=>(U||(E(!1),B()),!U)),className:R("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",a?"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:R("block truncate font-medium text-foreground",a?"text-[9px] leading-3":"text-[10px] leading-4"),children:P})}),e.jsx(Je,{className:R(a?"h-2.5 w-2.5":"h-3 w-3","shrink-0 text-muted-foreground transition-transform",d&&"rotate-180")})]}),i&&ee?Ba.createPortal(ne,ee):ne]})}function Na({icon:t,label:s,description:n,selected:r,onSelect:a,compact:i=!1}){const l=t==="global"?Sd:Bt;return e.jsxs("button",{type:"button",onClick:a,className:R(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(l,{className:R("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:R("block truncate text-muted-foreground",i?"text-[7px] leading-3":"text-[8px] leading-3"),children:n})]})]})}function Lh({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(Bt,{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(We,{className:"h-3 w-3"})})]})}function Rh({ariaLabel:t,value:s,description:n,options:r,selectedValue:a,onSelect:i}){const[l,d]=o.useState(!1),c=o.useRef(null);return o.useEffect(()=>{if(!l)return;const m=b=>{c.current&&b.target instanceof Node&&!c.current.contains(b.target)&&d(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[l]),e.jsxs("div",{ref:c,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":t,"aria-expanded":l,title:n??s,onClick:()=>d(m=>!m),className:"flex h-7 min-w-32 max-w-56 items-center gap-1.5 rounded-sm border-0 bg-muted/55 px-2 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:"block truncate text-[10px] font-medium leading-4 text-foreground",children:s})}),e.jsx(Je,{className:R("h-3 w-3 shrink-0 text-muted-foreground transition-transform",l&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!l,className:R("absolute left-0 top-9 z-50 w-64 overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!l&&"hidden"),children:e.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:r.length>0?r.map(m=>e.jsxs("button",{type:"button",onClick:()=>{i(m.value),d(!1)},className:R("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",m.value===a&&"bg-primary/10 text-primary"),children:[m.status&&e.jsx("span",{className:R("h-1.5 w-1.5 shrink-0 rounded-full",rs(m.status))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:m.label}),m.description&&e.jsx("span",{className:"block truncate text-[9px] text-muted-foreground",children:m.description})]})]},m.value)):e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No projects"})})})]})}function Bh(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 rs(t){return t==="online"?"bg-emerald-500":t==="offline"?"bg-muted-foreground/45":"bg-amber-500"}function ka(t){return t.split(/[\\/]+/).filter(Boolean).at(-1)??t}function Ro(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)}function Bo(t,s){return`${t.replace(/[\\/]+$/,"")}/${s.replace(/^[\\/]+/,"")}`}const Oh="h-6 w-24 rounded-sm px-2 text-[10px] shadow-none",yn="text-[10px]",Oo=["claudecode","codex","copilot"],Qt={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Fh({open:t,sourceNode:s,targetNodes:n,selectedCapabilities:r,previewResults:a=[],embedded:i=!1,onClose:l,onPreviewTargetsChange:d,onShare:c}){const[m,b]=o.useState(()=>new Set(a.length>0?a.map(p=>nt(p.nodeId,p.targetAgent)):Uh(s.id,n,r))),[f,u]=o.useState(()=>Object.fromEntries($h(s.id,n,r))),[g,N]=o.useState({}),[y,A]=o.useState(!1),[h,E]=o.useState(()=>new Set),[x,v]=o.useState(()=>new Set),k=r.some(p=>p.kind==="plugin"),C=o.useMemo(()=>Zn(r).map(p=>({key:nt(s.id,p),nodeId:s.id,node:s,label:`Install into ${Qt[p]}`,agentLabel:Qt[p],defaultScope:zo(r),disabled:!1,targetAgent:p})),[r,s]),T=o.useMemo(()=>n.flatMap(p=>{const q={kind:"global"},j=p.status==="offline",V=Fo(r);return V.length===0?[{key:nt(p.id),nodeId:p.id,node:p,label:p.name,defaultScope:q,disabled:j}]:V.map(F=>({key:nt(p.id,F),nodeId:p.id,node:p,label:`${p.name} / ${Qt[F]}`,agentLabel:Qt[F],defaultScope:q,disabled:j,targetAgent:F}))}),[r,n]),I=o.useMemo(()=>[...C,...T],[C,T]),S=o.useMemo(()=>n.map(p=>({node:p,options:T.filter(q=>q.nodeId===p.id)})).filter(p=>p.options.length>0),[n,T]),P=o.useMemo(()=>new Map(a.filter(p=>p.capabilityId).map(p=>[Sa(p.nodeId,p.capabilityId,p.targetAgent),p])),[a]),D=o.useMemo(()=>new Map(a.map(p=>[nt(p.nodeId,p.targetAgent),p])),[a]),_=o.useMemo(()=>I.filter(p=>m.has(p.key)),[m,I]),B=o.useMemo(()=>_.map(p=>({nodeId:p.nodeId,scope:f[p.key]??p.defaultScope,...p.targetAgent?{targetAgent:p.targetAgent}:{}})),[_,f]),z=o.useMemo(()=>{const p=[],q=new Map;for(const j of _){if(!q.has(j.nodeId)){const V=j.nodeId===s.id?s:n.find(F=>F.id===j.nodeId);q.set(j.nodeId,{nodeId:j.nodeId,node:V,name:V?.name??j.nodeId,options:[]}),p.push(j.nodeId)}q.get(j.nodeId).options.push(j)}return p.map(j=>q.get(j))},[_,s,n]),Q=o.useMemo(()=>{const p=Array.from(new Set(r.map(j=>j.agent))),[q]=p;if(q)return p.length===1?Qt[q]:`${p.length} agents`},[r]),Y=S.length+1;o.useEffect(()=>{let p=!1;const q={...f};for(const j of I)q[j.key]||(q[j.key]=j.defaultScope,p=!0);p&&u(q)},[I,f]),o.useEffect(()=>{t&&d?.(B)},[t,d,B]),o.useEffect(()=>{t&&(E(new Set),v(new Set))},[t,s.id]),o.useEffect(()=>{if(!i||!t)return;const p=q=>{q.key==="Escape"&&l()};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[i,l,t]);const X=p=>{N(Object.fromEntries(_.map(q=>[q.key,p])))},ee=async()=>{A(!0);try{await c(_.map(p=>({nodeId:p.nodeId,scope:f[p.key]??p.defaultScope,...p.targetAgent?{targetAgent:p.targetAgent}:{},conflictStrategy:g[p.key]??"overwrite"})))}finally{A(!1)}},ne=p=>{const q=f[p.key]??p.defaultScope,j=`capability-share-target-${zh(p.key)}`,V=m.has(p.key);return e.jsxs("div",{"data-target-agent":p.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":p.disabled?"true":void 0,children:[e.jsx(is,{id:j,disabled:p.disabled,checked:V,onCheckedChange:F=>b(H=>{const L=new Set(H);return F===!0?L.add(p.key):L.delete(p.key),L}),"aria-label":`Select ${p.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:j,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":p.disabled?"true":void 0,children:p.agentLabel??p.label}),e.jsx("div",{className:"flex w-28 shrink-0 justify-end",children:V&&!p.disabled&&e.jsx(Lo,{node:p.node,projectPaths:Jn(p.node),selectedScope:q,onSelect:F=>u(H=>({...H,[p.key]:F})),compact:!0,portal:!0,portalAlign:"end"})})]},p.key)},U=(p,q,j,V)=>{const F=h.has(p.id),H=_.filter(L=>L.nodeId===p.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":F,onClick:()=>E(L=>Ca(L,p.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(We,{className:R("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",F&&"rotate-90")}),e.jsx("span",{className:R("h-1.5 w-1.5 shrink-0 rounded-full",rs(p.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold text-foreground",title:p.name,children:p.name}),H>0&&e.jsxs("span",{className:"shrink-0 text-[8px] font-medium text-primary",children:[H," selected"]}),e.jsx("span",{className:"shrink-0 text-[8px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:q?"this node":"remote"}),p.status==="offline"&&e.jsx($e,{variant:"outline",className:"rounded-sm px-1 py-0 text-[8px]",children:"offline"}),V>0&&e.jsxs("span",{className:"sr-only",children:[V," agents"]})]}),e.jsx("div",{className:R("grid transition-[grid-template-rows] duration-200 ease-out",F?"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:j})})})]},p.id)},O=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(ks,{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:R("h-1.5 w-1.5 shrink-0 rounded-full",rs(s.status))}),e.jsx("span",{className:"truncate font-semibold text-foreground",title:s.name,children:s.name}),Q&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:["· ",Q]})]}),e.jsx(pr,{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:_.length})," selected · ",Y," ",Y===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:[U(s,!0,k?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"Cross-agent plugin installs are not supported."}):C.length===0?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No alternate agents available for this selection."}):C.map(ne),C.length),S.map(p=>U(p.node,!1,p.options.map(ne),p.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(p=>e.jsx("button",{type:"button",onClick:()=>X(p),className:"h-5 rounded-[3px] px-1.5 text-[9px] capitalize text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground",children:p},p))})]})]}),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:_.length===0?e.jsx("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"Select a target to preview conflicts."}):z.map(p=>{const q=!x.has(p.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":q,onClick:()=>v(j=>Ca(j,p.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(We,{className:R("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",q&&"rotate-90")}),p.node&&e.jsx("span",{className:R("h-1.5 w-1.5 shrink-0 rounded-full",rs(p.node.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-semibold text-foreground",children:p.name}),e.jsxs("span",{className:"shrink-0 text-[8px] text-muted-foreground",children:[p.options.length," ",p.options.length===1?"agent":"agents"]})]}),e.jsx("div",{className:R("grid transition-[grid-template-rows] duration-200 ease-out",q?"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:p.options.map(j=>{const V=g[j.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:j.agentLabel??"Matching agent"}),e.jsxs(je,{value:V,onValueChange:F=>N(H=>({...H,[j.key]:F})),children:[e.jsx(Ne,{className:Oh,children:e.jsx(Pe,{})}),e.jsxs(ke,{className:"shadow-none",children:[e.jsx(he,{value:"overwrite",className:yn,children:"Overwrite"}),e.jsx(he,{value:"skip",className:yn,children:"Skip"}),e.jsx(he,{value:"abort",className:yn,children:"Abort"})]})]})]}),e.jsx("div",{className:"space-y-px",children:r.map(F=>{const H=P.get(Sa(j.nodeId,F.id,j.targetAgent))??(r.length===1?D.get(j.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:F.name}),e.jsx("span",{className:H?.conflict?"text-amber-500":H?"text-emerald-500":"text-muted-foreground",children:H?H.conflict?`exists${H.currentVersion?` v${H.currentVersion}`:""}`:"new install":"checking"}),H?.sourceVersion&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[e.jsx(pr,{className:"inline h-2.5 w-2.5"})," v",H.sourceVersion]})]},F.id)})})]},j.key)})})})})]},p.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:l,className:"h-7 rounded-sm px-3 text-[11px]",children:"Cancel"}),e.jsxs(Z,{onClick:ee,disabled:y||_.length===0,className:"h-7 rounded-sm px-3 text-[11px]",children:[y?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ks,{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:p=>{p.target===p.currentTarget&&l()},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:p=>p.stopPropagation(),children:[O,e.jsxs("button",{type:"button",onClick:l,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(at,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})}):null:e.jsx(yt,{open:t,onOpenChange:p=>{p||l()},children:e.jsx(jt,{"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:O})})}function nt(t,s){return s?`agent:${t}:${s}`:`node:${t}`}function zh(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-")}function Sa(t,s,n){return`${nt(t,n)}\0${s}`}function Ca(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function Uh(t,s,n){const r=s.find(i=>i.status!=="offline");if(r)return[nt(r.id,qh(n))];const a=Zn(n)[0];return a?[nt(t,a)]:[]}function $h(t,s,n){const r=Fo(n);return[...s.flatMap(a=>r.length===0?[[nt(a.id),{kind:"global"}]]:r.map(i=>[nt(a.id,i),{kind:"global"}])),...Zn(n).map(a=>[nt(t,a),zo(n)])]}function Fo(t){return t.length===0||t.some(s=>s.kind==="plugin")?[]:Oo}function qh(t){if(!(t.length===0||t.some(s=>s.kind==="plugin")))return t[0]?.agent}function Zn(t){if(t.length===0||t.some(n=>n.kind==="plugin"))return[];const s=new Set(t.map(n=>n.agent));return Oo.filter(n=>!s.has(n))}function zo(t){return t[0]?.scope??{kind:"global"}}const Ta="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",pt="py-0.5 pl-6 pr-1.5 text-[9px] leading-4 [&_svg]:h-3 [&_svg]:w-3",Uo="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",Vh="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 Hh(t,s,n,r){return n.map(a=>({sourceNodeId:t,capabilityId:a.id,sourceScope:s,targets:r.map(i=>({nodeId:i.nodeId,scope:i.scope,...i.targetAgent?{targetAgent:i.targetAgent}:{}}))}))}function Kh(t,s,n,r){return n.map(a=>({sourceNodeId:t,capabilityId:a.id,sourceScope:s,targets:r}))}function Gh({loading:t,onRefresh:s}){return e.jsxs(Z,{variant:"ghost",onClick:s,disabled:t,"aria-busy":t,className:R(Uo,"min-w-[4.5rem]"),children:[e.jsx(Xa,{className:R("h-2.5 w-2.5",t&&"animate-spin")}),t?"Refreshing":"Refresh"]})}function Wh({selectedCount:t,loading:s,onClearSelection:n,onRefresh:r,onShare:a}){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:Uo,children:[e.jsx(at,{className:"h-2.5 w-2.5"}),"Selected: ",t," / Clear"]})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Gh,{loading:s,onRefresh:r}),e.jsxs(Z,{type:"button",variant:"ghost",onClick:a,disabled:t===0,className:Vh,children:[e.jsx(ks,{className:"h-2.5 w-2.5"}),"Share"]})]})]})}function Qh({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 Yh({visible:t}){return t?e.jsx("div",{className:"absolute inset-2.5 z-10 flex items-center justify-center rounded-sm border border-border/60 bg-background/85 shadow-sm backdrop-blur-sm",children:e.jsxs("div",{className:"flex w-full max-w-80 flex-col items-center gap-3 px-5 text-center",children:[e.jsxs("div",{className:"relative flex h-10 w-10 items-center justify-center rounded-full border border-primary/25 bg-primary/8",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border border-primary/20 animate-ping"}),e.jsx(ue,{className:"relative h-4 w-4 animate-spin text-primary"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:"Loading capabilities"}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Reading agent skills, plugins, and MCP servers for this selection."})]}),e.jsxs("div",{className:"grid w-full gap-1.5","aria-hidden":"true",children:[e.jsx("span",{className:"h-1.5 rounded-full bg-muted animate-pulse"}),e.jsx("span",{className:"mx-auto h-1.5 w-3/4 rounded-full bg-muted/70 animate-pulse"})]})]})}):null}function Jh({open:t,node:s,scope:n,clusterNodes:r,onOpenChange:a,onSelectionChange:i}){const[l,d]=o.useState([]),[c,m]=o.useState([]),[b,f]=o.useState(!1),[u,g]=o.useState(""),[N,y]=o.useState("all"),[A,h]=o.useState("all"),[E,x]=o.useState(new Set),[v,k]=o.useState(null),[C,T]=o.useState(null),[I,S]=o.useState(!1),[P,D]=o.useState(null),[_,B]=o.useState(!1),[z,Q]=o.useState([]),[Y,X]=o.useState(Io),[ee,ne]=o.useState(null),U=o.useMemo(()=>gh(l,{search:u,agent:N,kind:A}),[N,l,A,u]),O=o.useMemo(()=>l.filter(G=>E.has(G.id)),[l,E]),p=o.useMemo(()=>r.filter(G=>G.id!==s.id),[r,s.id]),q=n.kind==="project"?n.projectPath:"global",j=async()=>{f(!0);try{const G=await kl(s.id,{scope:n});d(G.items),m((G.errors??[]).map(J=>`${J.agent}: ${J.message}`))}catch(G){m([G instanceof Error?G.message:"Failed to load capabilities"])}finally{f(!1)}};o.useEffect(()=>{t&&(x(new Set),k(null),T(null),S(!1),Q([]),d([]),m([]),j())},[t,s.id,n.kind,q]),o.useEffect(()=>{if(!ee)return;const G=ce=>{X(yh(ee.startWidth,ee.startClientX,ce.clientX,window.innerWidth))},J=()=>ne(null);return window.addEventListener("pointermove",G),window.addEventListener("pointerup",J),()=>{window.removeEventListener("pointermove",G),window.removeEventListener("pointerup",J)}},[ee]);const V=G=>{G.preventDefault(),ne({startClientX:G.clientX,startWidth:Y})},F=()=>{ne(null),S(!1),k(null),T(null)},H=()=>{x(new Set),Q([])},L=async G=>{k(G.id),S(!0),T(null);const J=await Sl(s.id,G.id,n);T(J.detail)},ae=o.useCallback(async G=>{if(O.length===0||G.length===0){Q([]);return}Q([]);try{const J=Hh(s.id,n,O,G),ce=await Promise.all(J.map(M=>Nl(M)));Q(ce.flatMap((M,W)=>M.results.map(me=>({...me,capabilityId:J[W]?.capabilityId}))))}catch{Q([])}},[s.id,n,O]),oe=()=>{Q([]),B(!0)},ge=async G=>{const J=Kh(s.id,n,O,G);J.length!==0&&(await Promise.all(J.map(ce=>Tl(ce))),le.success(`${J.length} capability share request${J.length===1?"":"s"} completed`),B(!1))},re=async()=>{if(!(!C||P)){D(C.id);try{const G=await Cl(s.id,C.id,n);G.status==="deleted"?(le.success(`Deleted ${C.name}`),d(J=>J.filter(ce=>ce.id!==C.id)),x(J=>{const ce=new Set(J);return ce.delete(C.id),ce}),k(null),T(null),S(!1),await j()):(le.info(G.message??"Capability was not found"),k(null),T(null),S(!1),await j())}catch(G){le.error(G instanceof Error?G.message:"Failed to delete capability")}finally{D(null)}}};return e.jsx(e.Fragment,{children:e.jsx(yt,{open:t,onOpenChange:a,children:e.jsxs(jt,{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(Ts,{className:"border-b border-border/55 bg-card/28 px-4 py-2.5 text-left",children:[e.jsx(Ot,{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(Ph,{node:s,scope:n,clusterNodes:r,onSelectionChange:i}),e.jsxs(Es,{"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(Ma,{className:"pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),e.jsx(rt,{value:u,onChange:G=>g(G.target.value),placeholder:"Search capabilities",className:"h-7 rounded-sm border-0 bg-muted/55 pl-6 text-[10px] shadow-none"})]}),e.jsxs(je,{value:N,onValueChange:G=>y(G),children:[e.jsx(Ne,{className:R("w-28",Ta),children:e.jsx(Pe,{})}),e.jsxs(ke,{className:"shadow-none",children:[e.jsx(he,{value:"all",className:pt,children:"Agent: All"}),e.jsx(he,{value:"claudecode",className:pt,children:"Claude Code"}),e.jsx(he,{value:"codex",className:pt,children:"Codex"}),e.jsx(he,{value:"copilot",className:pt,children:"Copilot"})]})]}),e.jsxs(je,{value:A,onValueChange:G=>h(G),children:[e.jsx(Ne,{className:R("w-24",Ta),children:e.jsx(Pe,{})}),e.jsxs(ke,{className:"shadow-none",children:[e.jsx(he,{value:"all",className:pt,children:"Kind: All"}),e.jsx(he,{value:"skill",className:pt,children:"Skill"}),e.jsx(he,{value:"plugin",className:pt,children:"Plugin"}),e.jsx(he,{value:"mcp",className:pt,children:"MCP"})]})]})]}),c.length>0&&e.jsx("div",{className:"rounded-sm bg-amber-500/10 px-2 py-1 text-[10px] text-amber-600",children:c.join(" · ")}),e.jsx(bh,{items:U,selectedIds:E,activeId:v,onToggleSelected:(G,J)=>x(ce=>{const M=new Set(ce);return J?M.add(G):M.delete(G),M}),onOpenDetail:L}),e.jsx(Wh,{selectedCount:E.size,loading:b,onClearSelection:H,onRefresh:j,onShare:oe}),e.jsx(Yh,{visible:b&&l.length===0})]}),I&&e.jsxs(e.Fragment,{children:[e.jsx(Qh,{onBeginResize:V,onFold:F}),e.jsx(jh,{detail:C,deleting:P===C?.id,desktopWidth:Y,onDelete:C?re:void 0,pending:!C})]})]}),_&&e.jsx(Fh,{open:_,sourceNode:s,targetNodes:p,selectedCapabilities:O,previewResults:z,embedded:!0,onClose:()=>B(!1),onPreviewTargetsChange:ae,onShare:ge})]})})})}function Zh(t){const[s,n]=o.useState(null),r=o.useMemo(()=>s?t?.nodes.find(c=>c.id===s.nodeId)??(t?.self.id===s.nodeId?t.self:null)??null:null,[t,s]),a=o.useCallback(c=>{n({nodeId:c,scope:{kind:"global"}})},[]),i=o.useCallback((c,m)=>{n({nodeId:c,scope:{kind:"project",projectPath:m}})},[]),l=o.useCallback(c=>{n(c)},[]);return{capabilitiesDialog:s&&r&&t?e.jsx(Jh,{open:!0,node:r,scope:s.scope,clusterNodes:t.nodes,onOpenChange:c=>{c||n(null)},onSelectionChange:l}):null,openNodeCapabilities:a,openProjectCapabilities:i}}function Xh(){const{id:t}=El(),s=Al(),n=Dl(),r=_l(),{cluster:a,systemInfo:i,events:l,sseConnected:d,subscribe:c,refresh:m,loading:b,error:f}=Ml(),u=o.useMemo(()=>Pl(s.state),[s.state]),[g,N]=o.useState(null),[y,A]=o.useState("active"),[h,E]=o.useState("all"),[x,v]=o.useState("all"),[k,C]=o.useState("all"),T=r?.headerSearchQuery??"",I=o.useDeferredValue(T),{desktopTasksOpen:S,mobileTasksPanelOpen:P,mobileTasksPanelRef:D,operationsOpen:_,operationsPanelRef:B,panelResize:z,setMobileTasksPanelOpen:Q,setOperationsOpen:Y,toggleTasksPanel:X}=Bm(),[ee,ne]=o.useState(()=>!!u?.draftNewTask),[U,O]=o.useState(()=>u?.createMode??"chat"),[p,q]=o.useState(()=>u?.createDefaults??null),[j,V]=o.useState(()=>u?.draftNewTask?{route:u.returnRoute??"/",taskId:u.returnTaskId??null}:null),[F,H]=o.useState(!1),[L,ae]=o.useState("transcript"),[oe,ge]=o.useState("overview"),[re,G]=o.useState("all"),[J,ce]=o.useState(!1),[M,W]=o.useState(null),[me,be]=o.useState([]),[Ie,Re]=o.useState([]),[ut,Ze]=o.useState(!1),[qe,Te]=o.useState(!1),[mt,Xe]=o.useState(null),[Le,te]=o.useState(new Set),[ye,Se]=o.useState(!1),[He,Ke]=o.useState(!1),[we,St]=o.useState(null),ze=o.useRef(null),ot=o.useRef(new Map),Ce=a?.self?.role==="leader",Ut=a?.self?.id,{quickChats:Ct}=Il();Jm({cluster:a,subscribe:c});const{nodeSettingsDialog:K,openNodeSettings:Ee}=hh(Ce),{capabilitiesDialog:Ae,openNodeCapabilities:it,openProjectCapabilities:$t}=Zh(a),{devBoxDialog:Tt,devBoxNodeIds:De,devBoxStartNodeId:Ve,devBoxStartNodeIds:Et,devBoxStartingNodeIds:ht,openDevBox:lt,startDevBox:At}=mh({cluster:a,refresh:m}),{completedGroups:gt=[],fetchTasks:_e,loadCompletedTasksPage:de,removeTasksFromList:Me,setTasks:Be,tasks:Ue,tasksError:qt,tasksLoading:Is}=Gm({isLeader:Ce,selfId:Ut,sseConnected:d,preservedTask:M,subscribe:c});o.useEffect(()=>Ll(()=>{ge("events"),Y(!0)}),[Y]);const et=o.useMemo(()=>[...Ue].sort((w,$)=>$.updatedAt-w.updatedAt),[Ue]),tt=o.useMemo(()=>[...Ue].sort((w,$)=>$.createdAt-w.createdAt||$.updatedAt-w.updatedAt)[0]?.id??null,[Ue]),$o=o.useMemo(()=>{const w=new Map;for(const $ of a?.nodes??[]){const se=hc(et,$.id);se>0&&w.set($.id,se)}return w},[a?.nodes,et]),st=o.useMemo(()=>et.filter(w=>!Rl(w,a?.nodes,a?.self)||!Bl(w,y)||h!=="all"&&w.agent!==h||!Ol(w,k)||x==="unassigned"&&w.assignedTo||x!=="all"&&x!=="unassigned"&&Fl(w.assignedTo,a?.nodes,w.assignedNodeName)!==x?!1:I.trim()?zl(w,I):!0),[et,a?.nodes,a?.self,y,h,k,x,I]);o.useEffect(()=>{te(w=>{const $=vc(w,st.map(se=>se.id));return $.size===w.size?w:$})},[st]),o.useEffect(()=>{Ce||te(new Set)},[Ce]);const qo=o.useMemo(()=>["all",...Array.from(new Set(et.map(w=>w.agent))).sort()],[et]),Vo=o.useMemo(()=>{const $=Array.from(new Set(et.map(se=>se.assignedTo).filter(se=>!!se))).map(se=>{const ve=et.find(xe=>xe.assignedTo===se);return a?.nodes.find(xe=>xe.id===se)??{id:se,name:Nn(se,a?.nodes,ve?.assignedNodeName)}}).sort((se,ve)=>se.name.localeCompare(ve.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...$.map(se=>({value:se.name.toLowerCase(),label:se.name}))]},[et,a?.nodes]),Xn=o.useMemo(()=>{const w=new Map;for(const $ of a?.nodes??[])w.set($.id,$.name);for(const $ of et)$.assignedTo&&$.assignedNodeName&&!w.has($.assignedTo)&&w.set($.assignedTo,$.assignedNodeName);return w},[a?.nodes,et]),Ho=o.useMemo(()=>{const w=new Map;for(const $ of a?.nodes??[])$.workDir&&w.set($.id,$.workDir);return a?.self?.workDir&&w.set(a.self.id,a.self.workDir),w},[a]),Ko=o.useMemo(()=>{const w=new Map;for(const $ of a?.nodes??[])w.set($.id,$.status);return a?.self&&w.set(a.self.id,a.self.status),w},[a]),Go=o.useMemo(()=>new Map(gt.map(w=>[Ln(w),w])),[gt]),er=o.useMemo(()=>{const w=new Map;for(const $ of a?.nodes??[])$.status!=="offline"&&w.set($.id,$);return a?.self&&a.self.status!=="offline"&&w.set(a.self.id,a.self),Array.from(w.values())},[a]),Wo=a?.self?.id??er[0]?.id??null,Vt=o.useMemo(()=>l.filter(Ul),[l]),Ls=o.useMemo(()=>["all",...Array.from(new Set(Vt.map(w=>w.type))).sort()],[Vt]),Qo=o.useMemo(()=>re==="all"?Vt:Vt.filter(w=>w.type===re),[Vt,re]),Yo=st.length>0&&st.every(w=>Le.has(w.id)),Jo=st.some(w=>Le.has(w.id)),Zo=wc(st,Le);o.useEffect(()=>{u?.draftNewTask&&(ne(!0),O(u.createMode??"chat"),q(u.createDefaults??null),V({route:u.returnRoute??"/",taskId:u.returnTaskId??null}))},[u]),o.useEffect(()=>{re!=="all"&&!Ls.includes(re)&&G("all")},[re,Ls]),o.useEffect(()=>{br(t,ee)&&!g&&tt&&N(tt)},[t,ee,g,tt]),o.useEffect(()=>{br(t,ee)&&(g&&Ue.some(w=>w.id===g)||N(tt))},[t,ee,g,tt,Ue]);const pe=xc({routeTaskId:t,creatingTask:ee,internalSelectedTaskId:g,sortedTaskIds:tt?[tt]:[]}),Dt=o.useMemo(()=>Ue.find(w=>w.id===pe)??null,[Ue,pe]);o.useEffect(()=>{ze.current=pe??null},[pe]);const ft=o.useCallback(()=>{W(null),be([]),Re([]),Xe(null),Te(!1)},[]),Ht=o.useCallback((w,$,se=!0)=>{ot.current.set(w,{logs:Do($),loaded:se})},[]),Ge=o.useCallback(async()=>{const w=pe;if(w)try{const $=await $l(w);if(ze.current!==w)return;W($),Be(se=>no(se,$)),Xe(null)}catch($){if(ze.current!==w)return;ft(),Xe($ instanceof Error?$.message:"Failed to load task")}finally{ze.current===w&&Ze(!1)}},[pe,ft,Be]),ds=o.useCallback(async()=>{const w=pe;if(w)try{const $=await Sn(w);if(ze.current!==w)return;be(se=>{const ve=Qa(se,$.logs);return Ht(w,ve),ve}),Re(se=>Tn(se,$.logs))}catch{}finally{ze.current===w&&Te(!1)}},[pe,Ht]);o.useEffect(()=>{if(!pe){ft(),Ze(!1);return}ae("transcript"),W(Dt);const w=Wm(pe,ot.current);be(w.logs),Re([]),Xe(null),Ze(!0),Te(w.transcriptLoading),Ge(),ds()},[pe,ft,ds,Ge]),o.useEffect(()=>{if(!pc({activeTaskId:pe,routeTaskId:t,creatingTask:ee,tasksLoading:Is,loadedTaskIds:Ue.map($=>$.id)}))return;const w=tt;N(w),ft(),o.startTransition(()=>{n(w?`/tasks/${w}`:"/",{state:null})})},[pe,ft,ee,tt,n,t,Ue,Is]),o.useEffect(()=>{Dt&&W(w=>!w||w.id!==Dt.id?w:{...w,...Dt})},[Dt]),o.useEffect(()=>{if(pe)return c("task",w=>{const $=w.data.taskId;if(!(typeof $!="string"||$!==pe)){if(w.type==="task.output"){const se=w.data.event;if(se){be(xe=>{const Gt=id(xe,se);return Ht(pe,Gt),Gt}),Te(!1);const ve=xr(se);ve&&Re(xe=>ld(xe,ve))}}w.type==="task.updated"&&Ge(),w.type==="task.status"&&(Ge(),ds())}})},[c,pe,Ge,ds]);const ie=M??Dt,Xo=ie?.assignedTo?a?.nodes.find(w=>w.id===ie.assignedTo)??null:null,Kt=r?.setHeaderTaskContext;o.useEffect(()=>{if(!Kt)return;if(!ie){Kt(null);return}const w=ie.effectiveProjectPath??ie.project??"default workspace";return Kt({taskId:ie.id,taskTitle:ie.title,nodeName:Nn(ie.assignedTo,a?.nodes,ie.assignedNodeName),projectLabel:za(w),projectPath:w}),()=>Kt(null)},[ie,a?.nodes,Kt]);const Rs=Ie.length>0,ei=ie?ql.has(ie.agent):!1,cs=ie?.status==="running",ti=ie?ys.has(ie.status):!1,si=ie?ys.has(ie.status)||Vl.has(ie.status):!1,ni=!!(ie&&Ce&&ie.status==="failed"),Bs=o.useMemo(()=>Nm(ie,a,Rs,!!cs),[ie,a,Rs,cs]),Os=o.useMemo(()=>dd([...me,...Ie.map(w=>Vs(w.content,w.timestamp))]),[me,Ie]),us=o.useMemo(()=>{if(!ie||ie.conversationKind==="nativeSession")return null;const w=cd(ie);if(w.length>0)return Vs(w,new Date(ie.createdAt).toISOString());if(Os.length>0)return null;const $=ud(ie.description||ie.title);return $.length>0?Vs($,new Date(ie.createdAt).toISOString()):null},[ie,Os]),Fs=o.useMemo(()=>us?xr(us):null,[us]),ri=o.useMemo(()=>Fs?md(me,Fs):!1,[me,Fs]),zs=o.useCallback((w="chat",$)=>{const se={route:t?`/tasks/${t}`:"/",taskId:pe};V(se),O(w),q($??null),ne(!0),o.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:se.route,returnTaskId:se.taskId,createMode:w,createDefaults:$}})})},[t,pe,n]),ai=o.useCallback(()=>{const w=j?.taskId??tt;ne(!1),V(null),q(null),N(w),o.startTransition(()=>{n(j?.route??"/",{state:null})})},[j,tt,n]),tr=o.useCallback(w=>{ne(!1),V(null),q(null),N(w),o.startTransition(()=>{n(`/tasks/${w}`,{state:null})})},[n]),oi=o.useCallback(w=>{ze.current=w.id,ne(!1),V(null),q(null),Be($=>gc($,w)),W(w),be([]),Re([]),Xe(null),Ze(!1),Te(w.conversationKind==="nativeSession"),ae("transcript"),N(w.id),Xm({task:w,getActiveTaskId:()=>ze.current,setLogs:be,setPendingMessages:Re,setTranscriptLoading:Te}),_e(),o.startTransition(()=>{n(`/tasks/${w.id}`,{state:null})})},[_e,n]),{cancelQueuedMessage:ii,queueFollowUpMessage:ms}=xh({activeTaskId:pe,fetchActiveTask:Ge,isRunning:cs,setPendingMessages:Re,setTask:W,setTasks:Be}),li=o.useCallback(w=>{ms(w)},[ms]),di=o.useCallback(async()=>{const w=pe;if(!(!w||ie?.conversationKind!=="nativeSession")){Te(!0);try{const $=await Sn(w);if(ze.current!==w)return;be($.logs),Ht(w,$.logs),Re(se=>Tn(se,$.logs))}catch($){le.error($ instanceof Error?$.message:"Failed to reload transcript")}finally{ze.current===w&&Te(!1)}}},[ie?.conversationKind,pe,Ht]),ci=o.useCallback(w=>ms(w),[ms]),ui=o.useCallback(async()=>{if(ie)try{await Hl(ie.id),Ge(),_e()}catch(w){le.error(w instanceof Error?w.message:"Failed to cancel task")}},[ie,Ge,_e]),{handleShareTask:mi,handleStopShareTask:hi}=Pm(ie,Ge,_e),fi=o.useCallback(async()=>{if(ie)try{await Kl(ie.id),Ge(),_e()}catch(w){le.error(w instanceof Error?w.message:"Failed to retry task")}},[ie,Ge,_e]),hs=o.useCallback((w,$=!1)=>{const se=yc(st,w);return N(se),($||!se)&&ft(),o.startTransition(()=>{n(se?`/tasks/${se}`:"/",{state:null})}),se},[ft,st,n]),xi=o.useCallback((w,$)=>{te(se=>{const ve=new Set(se);return $?ve.add(w):ve.delete(w),ve})},[]),pi=o.useCallback(w=>{if(!w){te(new Set);return}te(new Set(st.map($=>$.id)))},[st]),gi=o.useCallback(async()=>{const w=Array.from(Le);if(w.length!==0)try{const{results:$}=await Gl(w),se=$.filter(xe=>!xe.ok),ve=$.filter(xe=>xe.ok).map(xe=>xe.id);pe&&ve.includes(pe)&&hs(ve),se.length>0?le.error(`Failed to archive ${se.length} task(s): ${se.map(xe=>xe.error??xe.id).join(", ")}`):le.success(`Archived ${ve.length} task(s)`),te(new Set(se.map(xe=>xe.id))),_e()}catch($){le.error($ instanceof Error?$.message:"Failed to archive tasks")}},[pe,_e,hs,Le]),bi=o.useCallback(async()=>{const w=Array.from(Le);if(w.length!==0)try{const{results:$}=await Wl(w),se=$.filter(xe=>!xe.ok),ve=$.filter(xe=>xe.ok).map(xe=>xe.id);ve.length>0&&Me(ve),pe&&ve.includes(pe)&&hs(ve,!0),se.length>0?le.error(`Failed to delete ${se.length} task(s): ${se.map(xe=>xe.error??xe.id).join(", ")}`):le.success(`Deleted ${ve.length} task(s)`),te(new Set(se.map(xe=>xe.id))),_e()}catch($){le.error($ instanceof Error?$.message:"Failed to delete tasks")}},[pe,_e,hs,Me,Le]),vi=o.useCallback(async()=>{Se(!0);try{await Ql(),m()}catch(w){le.error(w instanceof Error?w.message:"Failed to promote node")}finally{Se(!1)}},[m]),wi=o.useCallback(async()=>{Ke(!0);try{await Yl(),le.success("This node left the remote cluster and is leading itself again."),_e(),Ge(),m()}catch(w){le.error(w instanceof Error?w.message:"Failed to leave cluster")}finally{Ke(!1)}},[Ge,_e,m]),yi=o.useCallback(async w=>{const $=!qn(w),se=w.id===a?.self?.id,ve=se?i?.transportType??w.transportType:w.transportType,xe=se&&!$&&zt(ve);St(w.id);try{xe?await Jl("direct"):await Zl(w.id,$),le.success($?`Enabled remote access on ${w.name}`:`Disabled remote access on ${w.name}`),m()}catch(Gt){le.error(Gt instanceof Error?Gt.message:"Failed to update remote access")}finally{St(null)}},[a?.self?.id,m,i?.transportType]),ji=o.useCallback(w=>{de&&de(w).catch($=>{le.error($ instanceof Error?$.message:"Failed to load completed tasks")})},[de]),sr={toolbarTasks:st,activeTaskId:pe,tasksLoading:Is,tasksError:qt,isLeader:Ce,scope:y,agentFilter:h,nodeFilter:x,taskKindFilter:k,agentOptions:qo,nodeOptions:Vo,nodeNameById:Xn,nodeWorkDirById:Ho,nodeStatusById:Ko,leaderNodeId:a?.leader?.id??null,searchQuery:T,completedGroupByKey:Go,devBoxNodeIds:De,devBoxStartNodeIds:Et,devBoxStartingNodeIds:ht,selectedTaskIds:Le,allVisibleTasksSelected:Yo,someVisibleTasksSelected:Jo,canBatchArchive:Zo,onScopeChange:A,onAgentFilterChange:E,onNodeFilterChange:v,onTaskKindFilterChange:C,onToggleTaskSelected:xi,onToggleAllVisibleTasks:pi,onBatchArchive:gi,onBatchDelete:bi,onCreateTask:zs,onOpenNodeSettings:Ce?Ee:void 0,onOpenNodeCapabilities:Ce?it:void 0,onOpenProjectCapabilities:Ce?$t:void 0,onOpenDevBox:Ce?lt:void 0,onStartDevBox:Ce?At:void 0,onLoadCompletedTasks:ji,onSelectTask:tr},Ni={cluster:a,systemInfo:i,nodeNameById:Xn,nodeBlockingTaskCounts:$o,eventTypeFilter:re,onEventTypeFilterChange:G,activeTab:oe,onTabChange:ge,eventTypeOptions:Ls,filteredEvents:Qo,sseConnected:d,clusterLoading:b,clusterError:f,promotePending:ye,onPromote:vi,onAddNode:()=>H(!0),leavePending:He,onLeaveCluster:wi,onToggleNodeDevTunnel:yi,devTunnelNodeId:we,devBoxStartNodeId:Ve,devBoxStartingNodeIds:ht,onOpenNodeSettings:Ce?Ee:void 0,onOpenNodeCapabilities:Ce?it:void 0,onOpenDevBox:Ce?lt:void 0,onStartDevBox:Ce?At:void 0};return e.jsxs(e.Fragment,{children:[e.jsx(_u,{desktopTasksOpen:S,mobileTasksPanelOpen:P,mobileTasksPanelRef:D,operationsOpen:_,operationsPanelRef:B,panelResize:z,taskSidebar:e.jsx(ma,{...sr}),operationsSidecar:e.jsx(ym,{...Ni}),terminalPanel:r?.terminalOpen?e.jsx(Fu,{nodes:er,defaultNodeId:Wo,onClose:()=>r?.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(Nu,{onToggleTasks:X,desktopTasksOpen:S,mobileTasksPanelOpen:P,operationsOpen:_,onToggleOperations:()=>Y(w=>!w),cluster:a,sseConnected:d,activeTab:L,setActiveTab:ae,creatingTask:ee,createMode:U,createDefaults:p,activeTask:ie,assignedNode:Xo,taskLoading:ut,transcriptLoading:qe,taskError:mt,displayEvents:Os,initialPromptAlreadyInLogs:ri,initialPrompt:us,supportsFollowUp:ei,taskUnavailable:Bs.taskUnavailable,chatDisabled:Bs.chatDisabled,chatDisabledReason:Bs.chatDisabledReason,questionBypassEnabled:J,isRunning:!!cs,isStarting:ti,hasPendingFollowUp:Rs,canCancel:!!si,canRetry:!!ni,onRetry:fi,onCancel:ui,onReloadNativeTranscript:di,onShareTask:mi,onStopShareTask:hi,onStartCreateTask:zs,onCancelCreateTask:ai,onCreateTask:oi,onSendMessage:li,onCancelQueuedMessage:ii,onQuestionBypassChange:ce,onSubmitQuestionResponse:ci,quickChats:Ct}),mobileTaskSidebar:e.jsx(ma,{...sr,onCreateTask:(w,$)=>{Q(!1),zs(w,$)},onSelectTask:w=>{Q(!1),tr(w)}}),onCloseOperations:()=>Y(!1),onCloseTaskList:()=>Q(!1),onToggleOperations:()=>Y(w=>!w),onToggleTasks:X}),e.jsx(Cu,{open:F,onOpenChange:H,onAdded:m}),K,Tt,Ae]})}const rf=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:Xh},Symbol.toStringTag,{value:"Module"}));export{Ya as A,rf as D,js as G};