meshy-node 0.10.4 → 0.10.6

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,166 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-uM8qGxbi.js","assets/index-BfhJ5QGx.js","assets/index-Bol9w8Lt.css","assets/MarkdownPreviewFrame-BueJ6Pjk.js","assets/DashboardShared-CnAnYJXR.js","assets/file-Du0lhUCi.js","assets/PreviewTab-K7c436fs.js","assets/DiffTab-JNuSFUCI.js"])))=>i.map(i=>d[i]);
2
+ import{c as me,r as o,a as ws,f as Da,m as _a,j as e,X as it,Q as Nn,B as J,L as de,S as Ma,b as Di,d as B,e as _i,g as Mi,h as Pi,I as ot,P as Ii,C as as,i as Ri,k as Pa,F as Li,l as Lt,n as st,o as De,D as os,p as Bi,q as Oi,t as ce,s as _e,u as Me,v as $e,w as Pe,x as Ia,y as Je,T as Fi,z as zi,A as rr,E as Ui,G as St,H as Ct,J as Bt,K as Ra,M as La,N as Es,O as On,R as $i,U as Nt,V as qi,W as kn,Y as Vi,Z as Fn,_ as Ba,$ as Hi,a0 as Ve,a1 as Ki,a2 as ft,a3 as Yt,a4 as Jt,a5 as Zt,a6 as Xt,a7 as es,a8 as ts,a9 as ss,aa as ns,ab as zn,ac as Gi,ad as As,ae as Oa,af as Wi,ag as ar,ah as or,ai as $s,aj as Qi,ak as Yi,al as Ji,am as Zi,an as Xi,ao as Ds,ap as el,aq as tl,ar as _s,as as sl,at as Fa,au as nl,av as rl,aw as al,ax as za,ay as Un,az as Ua,aA as ol,aB as ys,aC as il,aD as ir,aE as ll,aF as $n,aG as cl,aH as dl,aI as ul,aJ as ml,aK as $a,aL as is,aM as hl,aN as Sn,aO as qa,aP as fl,aQ as xl,aR as pl,aS as gl,aT as lr,aU as bl,aV as vl,aW as qs,aX as wl,aY as cr,aZ as yl,a_ as jl,a$ as Nl,b0 as dr,b1 as kl,b2 as Sl,b3 as Cn,b4 as Cl,b5 as Tl,b6 as Va,b7 as ur,b8 as Ha,b9 as El,ba as Al,bb as Dl,bc as _l,bd as Ml,be as Pl,bf as Il,bg as Rl,bh as Ll,bi as Bl,bj as Ol,bk as Fl,bl as zl,bm as Ul,bn as $l,bo as ql,bp as Vl,bq as Hl,br as Kl,bs as Gl,bt as Wl,bu as Ql,bv as Yl,bw as Jl,bx as Zl,by as Xl,bz as ec,bA as tc,bB as sc,bC as nc,bD as rc,bE as ac,bF as oc}from"./index-BfhJ5QGx.js";import{r as mr,e as ic,b as Ka,g as Ga,I as Wa,A as qn,a as Qa,c as Ya,T as Ja,d as lc,i as Za,f as cc,p as Xa,h as dc,t as uc,j as hr,k as fr,l as mc,m as hc,n as fc,C as xr,o as Vs,q as Tn,D as _t,s as tt,M as En,L as xc,u as eo,v as An,w as pc,x as gc,y as bc,z as Hs,B as vc,E as wc,F as yc}from"./DashboardShared-CnAnYJXR.js";import{E as jc,M as Nc}from"./MarkdownPreviewFrame-BueJ6Pjk.js";import{P as Ms,D as fs,g as kc,a as Sc,b as Cc}from"./PreviewTab-K7c436fs.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 Tc=[["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"}]],Ec=me("archive",Tc);/**
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 Ac=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],pr=me("arrow-right",Ac);/**
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 Dc=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],to=me("arrow-up",Dc);/**
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 _c=[["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"}]],so=me("brain-circuit",_c);/**
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 Mc=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],js=me("chevron-left",Mc);/**
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 Pc=[["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"}]],Ic=me("earth",Pc);/**
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 Rc=[["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"}]],Lc=me("ellipsis-vertical",Rc);/**
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 Bc=[["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"}]],Oc=me("ellipsis",Bc);/**
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 Fc=[["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"}]],Ps=me("folder-open",Fc);/**
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 zc=[["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"}]],Uc=me("funnel",zc);/**
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 $c=[["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"}]],Ns=me("git-branch",$c);/**
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 qc=[["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"}]],Vc=me("globe",qc);/**
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 Hc=[["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"}]],ks=me("history",Hc);/**
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 Kc=[["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"}]],Dn=me("image-plus",Kc);/**
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 Gc=[["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"}]],Wc=me("laptop",Gc);/**
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 Qc=[["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"}]],Vn=me("link-2",Qc);/**
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 Yc=[["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"}]],Jc=me("list-ordered",Yc);/**
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 Zc=[["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"}]],Is=me("message-square-plus",Zc);/**
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 Xc=[["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"}]],no=me("monitor-play",Xc);/**
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 ed=[["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"}]],Ot=me("pencil",ed);/**
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 td=[["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"}]],sd=me("qr-code",td);/**
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 nd=[["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"}]],rd=me("rotate-ccw",nd);/**
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 ad=[["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"}]],ro=me("rotate-cw",ad);/**
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 od=[["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"}]],ao=me("send",od);/**
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 id=[["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"}]],Ss=me("share-2",id);/**
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 ld=[["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"}]],cd=me("sliders-horizontal",ld);/**
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 dd=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],gr=me("square",dd);/**
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 ud=[["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"}]],md=me("user-plus",ud);/**
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 hd=[["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"}]],fd=me("wifi",hd);/**
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 xd=[["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"}]],pd=me("zoom-in",xd);/**
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 gd=[["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"}]],bd=me("zoom-out",gd),vd=new Set(["assigned","running"]);function wd(t,s){return t.reduce((n,r)=>r.assignedTo===s&&vd.has(r.status)?n+1:n,0)}function Ft(t){return t?.toLowerCase()==="devtunnel"}function yd(t){return t?Ft(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function Hn(t,s){return Ft(s??t.transportType)||!!t.devtunnelEndpoint}function oo(t,s){return!Ft(s??t.transportType)}function io(t,s){const n=s??t.transportType;return Ft(n)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":yd(n)}function br(t,s){return!t&&!s}function jd({routeTaskId:t,creatingTask:s,internalSelectedTaskId:n,sortedTaskIds:r}){return t||(s?null:r[0]??n??null)}function Nd({activeTaskId:t,routeTaskId:s,creatingTask:n,tasksLoading:r,loadedTaskIds:a}){return!t||s||n||r?!1:!a.includes(t)}function kd(t,s){return[s,...t.filter(n=>n.id!==s.id)]}function lo(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 Sd=new Set(["completed","failed","cancelled","archived"]);function Cd(t,s){const n=new Set(s);return new Set(Array.from(t).filter(r=>n.has(r)))}function Td(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=>Sd.has(a.status))}function Ed(t,s){const n=new Set(s);return t.find(r=>!n.has(r.id))?.id??null}function co(){const[t,s]=o.useState([]),[n,r]=o.useState(null),a=o.useRef(null),i=o.useCallback(()=>{a.current?.click()},[]),l=o.useCallback(async p=>{const u=Array.from(p.target.files??[]);if(u.length!==0)try{const h=await mr(u);s(x=>[...x,...h]),r(null)}catch(h){r(h instanceof Error?h.message:"Failed to attach image")}finally{p.target.value=""}},[]),c=o.useCallback(async p=>{const u=ic(p.clipboardData);if(u.length!==0){p.preventDefault();try{const h=await mr(u);s(x=>[...x,...h]),r(null)}catch(h){r(h instanceof Error?h.message:"Failed to attach image")}}},[]),d=o.useCallback(p=>{s(u=>u.filter((h,x)=>x!==p))},[]),m=o.useCallback(()=>{s([]),r(null)},[]);return{images:t,error:n,fileInputRef:a,pickImages:i,handleFileChange:l,handlePaste:c,removeImage:d,clearImages:m}}function Ad(t){const s=t.map(a=>({...a,displayValue:Dd(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 Dd(t){return t.label.toLowerCase()==="agent"?Qa(t.value):t.value}function vr(t){switch(t.toLowerCase()){case"branch":return Ns;case"node":return Ma;default:return Ps}}function _d({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 Md({contentLength:t,disabled:s=!1}){return t>0&&!s}function Pd({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:c=!1,onStop:d,quickChats:m=[]}){const[p,u]=o.useState(""),[h,x]=o.useState(0),[k,j]=o.useState(0),A=o.useRef(null),{images:f,error:E,fileInputRef:y,pickImages:v,handleFileChange:b,handlePaste:C,removeImage:T,clearImages:P}=co(),S=o.useCallback(()=>{A.current&&(A.current.style.height="auto")},[]),I=o.useCallback(()=>{A.current&&(A.current.style.height="auto",A.current.style.height=`${Math.min(A.current.scrollHeight,220)}px`)},[]);o.useEffect(()=>{x(0)},[p,m]);const _=o.useCallback(O=>{u(O.prompt);const g=()=>{A.current?.focus(),I()};typeof requestAnimationFrame=="function"?requestAnimationFrame(g):g()},[I]),D=o.useCallback(()=>{const O=ws(p,m,h);if(O){_(O);return}const g=Ka(p,f);Md({contentLength:g.length,disabled:s})&&(j($=>$+1),t(g),u(""),P(),S())},[p,f,s,t,P,S,m,h,_]),R=o.useCallback(O=>{const g=Da(p,m);if(g.length>0&&(O.key==="ArrowDown"||O.key==="ArrowUp")){O.preventDefault(),x($=>_a($,g.length,O.key==="ArrowDown"?1:-1));return}if(O.key==="Enter"&&!O.shiftKey){O.preventDefault();const $=ws(p,m,h);$?_($):D()}},[_,D,m,h,p]),F=p.trim().length>0||f.length>0,Y=_d({disabled:s,running:c,canStop:c&&!!d,hasContent:F}),X=Ad(a),Z=X.primary?vr(X.primary.label):Ps,te=i?Ga(i,l):null,V=c?F?"Enter queues this message for the next turn":d?"Task is running - type to queue, empty button stops task":"Task is running - type to queue a message":s?n:"Enter sends, Shift+Enter adds a line";return e.jsx("div",{"data-chat-input-shell":"true",className:"chat-input-shell animate-composer-settle w-full bg-background/35 px-2 pb-2 pt-0 sm:px-4 sm:pb-3",children:e.jsx("div",{"data-chat-input-column":"true",className:"mx-auto w-full max-w-[72rem]",children:e.jsxs("div",{"data-chat-input-card":"true",className:"chat-input-card overflow-hidden rounded-xl border border-border/65 bg-card/88 transition-[border-color,box-shadow] duration-200 focus-within:border-primary/50 focus-within:ring-2 focus-within:ring-primary/15 sm:rounded-xl",children:[e.jsx("input",{ref:y,type:"file",accept:"image/*",multiple:!0,onChange:b,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(Z,{className:"h-2.5 w-2.5 shrink-0 text-primary/45","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[9px] leading-3 text-muted-foreground/72",title:X.primary.value,children:X.primary.displayValue})]})}),f.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:f.map((O,g)=>e.jsxs("div",{className:"relative",children:[e.jsx(Wa,{image:O,alt:O.filename??`attachment ${g+1}`,thumbnailClassName:"h-24 w-24 border border-border/70",imageClassName:"h-full w-full"}),e.jsx("button",{type:"button",onClick:()=>T(g),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 ${g+1}`}`,children:e.jsx(it,{className:"h-3 w-3"})})]},`${O.filename??"image"}-${g}`))})}),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:p,onChange:O=>u(O.target.value),onKeyDown:R,onPaste:C,onInput:I,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(Nn,{query:p,quickChats:m,selectedIndex:h,onActiveIndexChange:x,onSelect:_}),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 g=vr(O.label),$=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:[$?e.jsx(qn,{agent:O.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(g,{"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:[te&&e.jsxs("span",{"data-chat-input-model-display":"true","aria-label":`Model: ${te}`,title:`Model: ${te}`,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(so,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),te]}),e.jsxs(J,{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(Dn,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:V,children:e.jsx(J,{onClick:Y.primaryAction==="stop"?d:D,disabled:Y.primaryDisabled,size:"icon","data-chat-send-button":"true","aria-label":Y.primaryAction==="stop"?"Stop running task":c?"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(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ao,{className:`h-3.5 w-3.5 ${k>0?"animate-chat-send-flight":""}`},k)})})]})]}),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 Id=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Rd=Id.reduce((t,s)=>{const n=Di(`Primitive.${s}`),r=o.forwardRef((a,i)=>{const{asChild:l,...c}=a,d=l?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(d,{...c,ref:i})});return r.displayName=`Primitive.${s}`,{...t,[s]:r}},{}),Ld="Label",uo=o.forwardRef((t,s)=>e.jsx(Rd.label,{...t,ref:s,onMouseDown:n=>{n.target.closest("button, input, select, textarea")||(t.onMouseDown?.(n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));uo.displayName=Ld;var mo=uo;const Bd=_i("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ge=o.forwardRef(({className:t,...s},n)=>e.jsx(mo,{ref:n,className:B(Bd(),t),...s}));Ge.displayName=mo.displayName;function wr({agent:t,query:s,onSelect:n}){const r=Ya(t,s);return r?e.jsx("div",{"data-codex-goal-command":"true",className:"mx-2 mb-0.5 rounded-sm bg-background/70 p-0.5 shadow-none sm:mx-5",children:e.jsx("div",{role:"listbox","aria-label":"Codex commands",children:e.jsxs("button",{type:"button",role:"option","aria-selected":"true",onClick:n,className:"flex h-8 w-full min-w-0 items-center gap-2 rounded-sm px-2 text-left transition-colors hover:bg-muted/50 hover:text-foreground",children:[e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-primary",children:e.jsx(Ja,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx("span",{className:"shrink-0 text-[11px] font-medium text-foreground",children:r.label}),e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:r.description})]})})}):null}function Od(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function Fd(t){return t.trim()||"."}function zd(t){return new Promise(s=>window.setTimeout(s,t))}function Ud(t){return!!t&&typeof t=="object"&&typeof t.createdBranch=="string"&&typeof t.currentBranch<"u"}async function $d(t){let s=t;for(let n=0;n<60;n++){if(s.status==="succeeded"){if(Ud(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 zd(1e3),s=await Ri(s.id)}throw new Error("Timed out waiting for branch creation")}function yr({value:t,onChange:s,project:n,assignTo:r,nodes:a,assignableNodes:i,layout:l="default",chipClassName:c,chipActiveClassName:d,chipInactiveClassName:m,labelClassName:p,triggerClassName:u}){const[h,x]=o.useState(!1),[k,j]=o.useState(null),[A,f]=o.useState(""),[E,y]=o.useState(!1),[v,b]=o.useState(!1),[C,T]=o.useState(!1),[P,S]=o.useState(null),[I,_]=o.useState(""),[D,R]=o.useState(""),[F,Q]=o.useState(""),[Y,X]=o.useState(!1),Z=o.useRef(null),te=o.useRef(0),V=o.useMemo(()=>Od(r,a,i),[r,a,i]),O=V?.id,g=o.useMemo(()=>Fd(n),[n]),$=o.useMemo(()=>O?`${O}
158
+ ${g}`:"",[O,g]),N=o.useCallback(async(ae=0,G=!1)=>{const M=te.current+1,ne=$;if(te.current=M,!O){j(null),f("");return}S(null),G||f(""),G?b(!0):y(!0);try{const H=await Mi(O,{path:g,limit:20,offset:ae,allowAbsolute:!0});if(M!==te.current)return;f(ne),j(re=>G&&re?{...H,branches:[...re.branches,...H.branches]}:H)}catch(H){if(M!==te.current)return;S(H instanceof Error?H.message:"Failed to load branch info"),G||(j(null),f(""))}finally{M===te.current&&(y(!1),b(!1))}},[O,$,g]);o.useEffect(()=>{if(!O){te.current+=1,j(null),f(""),S(null);return}N()},[O,g,N]),o.useEffect(()=>{const ae=t.trim(),G=A===$?k:null,M=G?.available&&G.currentBranch?G.currentBranch:"";ae!==M&&s(M)},[k,$,A,s,t]),o.useEffect(()=>{if(!h)return;const ae=M=>{Z.current&&(Z.current.contains(M.target)||x(!1))},G=M=>{M.key==="Escape"&&x(!1)};return document.addEventListener("mousedown",ae),document.addEventListener("keydown",G),()=>{document.removeEventListener("mousedown",ae),document.removeEventListener("keydown",G)}},[h]),o.useEffect(()=>{h&&(R(""),Q(""),X(!1))},[h,O,g]);const q=o.useCallback(async()=>{if(!O)return;const ae=I.trim(),G=Y?F.trim():D.trim();if(!(!ae||!G)){T(!0),S(null);try{const M=await Pi(O,{path:g,branchName:ae,startPoint:G,limit:20,offset:0,allowAbsolute:!0}),ne=await $d(M);f($),j(ne),s(ne.currentBranch??ne.createdBranch),_(""),R(""),Q(""),X(!1),x(!1)}catch(M){S(M instanceof Error?M.message:"Failed to create branch")}finally{T(!1)}}},[O,$,g,Y,F,I,s,D]),z=A===$?k:null,W=o.useCallback(()=>{z?.hasMore&&N(z.branches.length,!0)},[z,N]),L=t.trim()||z?.currentBranch||(z&&!z.available?"No git repo":"Branch"),oe=Y?F.trim():D.trim(),ie=!!(z?.available&&I.trim()&&oe&&!C),he=l==="composer"?e.jsxs(J,{type:"button",variant:"ghost",onClick:()=>x(ae=>!ae),title:L,"aria-label":`Branch: ${L}`,className:B(c,u,"min-w-0 max-w-full",t.trim()?d:m),children:[E&&!z?e.jsx(de,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(Ns,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:B("min-w-0 truncate",p),children:L})]}):e.jsxs(J,{type:"button",variant:"outline",onClick:()=>x(ae=>!ae),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:B("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:V?V.name:"Manual"})]});return e.jsxs("div",{className:B("relative inline-block",l==="composer"?"min-w-0 shrink-0":"w-full"),ref:Z,children:[l==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[10px] font-medium",children:"Branch"}),he]}):he,h&&e.jsxs("div",{className:B("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(Ns,{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:z?.repoRoot?`${z.currentBranch??L} · ${z.repoRoot}`:z?.currentBranch??L,children:z?.currentBranch??L}),E?e.jsx(de,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),V?E&&!z?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(de,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):z&&!z.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(ot,{value:I,onChange:ae=>_(ae.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(J,{type:"button",size:"sm",onClick:()=>{q()},disabled:!ie,title:ie?"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(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ii,{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(Ot,{className:"h-2.5 w-2.5"}),"Manual"]})]}),Y?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ot,{value:F,onChange:ae=>Q(ae.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(it,{className:"h-3.5 w-3.5"})})]}):z?.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-sm border border-border/40 bg-background/40",children:[z.branches.map(ae=>{const G=D===ae.ref,M=ae.branch==="main"||ae.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>R(ae.ref),className:B("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:ae.ref,children:[e.jsx("span",{className:B("shrink-0 text-[10px]",M?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:M?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:ae.ref}),G?e.jsx(as,{className:"h-3 w-3 shrink-0 text-primary"}):null]},ae.ref)}),z.hasMore&&e.jsxs("button",{type:"button",onClick:W,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(de,{className:"h-3 w-3 animate-spin"}):e.jsx(ks,{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."}),P&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:P})]})]})}const qd=20,Vd=3,_n="meshy-working-dir-recents-by-node";function Hd(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function Kd(t){const s=t.trim();return s||"."}function Mn(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===Vd))break}return s}function Gd(t,s){const n=s.trim();return Mn(n?[n,...t]:t)}function ho(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=Mn(a);i.length>0&&(s[n]=i)}return s}function Wd(t,s,n){if(!s)return t;const r=t[s]??[],a=Gd(r,n);if(a.length===0){if(!(s in t))return t;const{[s]:i,...l}=t;return l}return{...t,[s]:a}}function Qd(t,s){return s?t[s]?.[0]??"":""}function fo(t){if(!t||typeof window>"u")return"";try{const s=window.localStorage.getItem(_n);return s?Qd(ho(JSON.parse(s)),t):""}catch{return""}}function Yd(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function Jd(t,s){const n=s.trim();return n?Hd(n)||!t?n:`${t.replace(/[/\\]+$/,"")}/${n}`:""}function Zd(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 Cs({value:t,onChange:s,assignTo:n,nodes:r,assignableNodes:a,layout:i="default",chipClassName:l,chipActiveClassName:c,chipInactiveClassName:d,labelClassName:m,triggerClassName:p,popoverPlacement:u="bottom",popoverAlign:h="start"}){const[x,k]=o.useState(!1),[j,A]=o.useState(null),[f,E]=o.useState(!1),[y,v]=o.useState(!1),[b,C]=o.useState(null),[T,P]=o.useState(""),[S,I]=o.useState(!1),[_,D]=o.useState({}),R=o.useRef(null),F=o.useMemo(()=>Yd(n,r,a),[n,r,a]),Q=F?.id,Y=o.useMemo(()=>Q?_[Q]??[]:[],[_,Q]),X=o.useMemo(()=>t.trim()?Jd(F?.workDir,t):"Use node default",[t,F?.workDir]);o.useEffect(()=>{if(!(typeof window>"u"))try{const L=window.localStorage.getItem(_n);if(!L)return;const oe=JSON.parse(L);D(ho(oe))}catch{}},[]);const Z=o.useCallback(L=>{Q&&D(oe=>{const ie=Wd(oe,Q,L);if(ie===oe)return oe;if(typeof window<"u")try{window.localStorage.setItem(_n,JSON.stringify(ie))}catch{}return ie})},[Q]),te=o.useCallback((L,oe=!0)=>{const ie=L.trim();s(ie),oe&&ie&&Z(ie),k(!1)},[s,Z]),V=o.useCallback(async(L,oe=0,ie=!1)=>{if(Q){C(null),ie?v(!0):E(!0);try{const he=await Pa(Q,{path:L,limit:qd,offset:oe,directoriesOnly:!0,allowAbsolute:!0});A(ae=>ie&&ae?{...he,entries:[...ae.entries,...he.entries]}:he)}catch(he){C(he instanceof Error?he.message:"Failed to browse directories"),ie||A(null)}finally{E(!1),v(!1)}}},[Q]),O=o.useRef(t);O.current=t;const g=o.useRef(V);g.current=V,o.useEffect(()=>{if(!x)return;const L=O.current;P(L),I(!1),A(null),C(null),Q&&g.current(Kd(L))},[x,Q]),o.useEffect(()=>{if(!x)return;const L=ie=>{R.current&&(R.current.contains(ie.target)||k(!1))},oe=ie=>{ie.key==="Escape"&&k(!1)};return document.addEventListener("mousedown",L),document.addEventListener("keydown",oe),()=>{document.removeEventListener("mousedown",L),document.removeEventListener("keydown",oe)}},[x]);const $=o.useCallback(L=>{V(L)},[V]),N=o.useCallback(()=>{j&&V(j.currentPath,j.entries.length,!0)},[j,V]),q=i==="composer"?e.jsxs(J,{type:"button",variant:"ghost",onClick:()=>k(L=>!L),title:X,"aria-label":`Working directory: ${X}`,className:B(l,p,"min-w-0 max-w-full",t.trim()?c:d),children:[e.jsx(Li,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:B("min-w-0 truncate",m),children:X})]}):e.jsxs(J,{type:"button",variant:"outline",onClick:()=>k(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:B("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:F?F.name:"Manual"})]}),z=Zd(j,F),W=!!j?.parentPath;return e.jsxs("div",{className:B("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":u,"data-workdir-popover-align":h,ref:R,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[10px] font-medium",children:"Working directory"}),q]}):q,x&&e.jsxs("div",{className:B("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",u==="top"?"bottom-full mb-2":"top-full mt-2",i==="composer"?h==="end"?"right-0":"left-0":h==="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(ks,{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:()=>te(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:()=>j?.parentPath&&$(j.parentPath),disabled:!W||f,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-sm border border-border/60 text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(to,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:z,children:z}),j&&e.jsx("button",{type:"button",onClick:()=>te(j.isAbsolute?j.currentPath:j.currentPath==="."?"":j.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:[F?f?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(de,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):j&&j.entries.length>0?e.jsxs(e.Fragment,{children:[j.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:()=>te(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(Lt,{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:()=>$(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(st,{className:"h-3.5 w-3.5"})})]},L.path)),j.hasMore&&e.jsxs("button",{type:"button",onClick:N,disabled:y,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:[y?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(ks,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:b??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),b&&j&&j.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:b})]}),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(ot,{value:T,onChange:L=>P(L.target.value),onKeyDown:L=>{L.key==="Enter"&&T.trim()?(L.preventDefault(),te(T)):L.key==="Escape"&&(L.preventDefault(),I(!1),P(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:()=>te(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:()=>{I(!1),P(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(it,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{P(t),I(!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(Ot,{className:"h-3 w-3"})]})})]})]})}function xo(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 Kn({isCurrent:t}){return t?e.jsx(Wc,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Vc,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function Pn(t,s){return t.map(n=>{const r=!!s&&n.id===s;return e.jsx(De,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Kn,{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 Xd(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 eu(){return Fi.map(t=>e.jsx(De,{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 tu(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 jr(t){if(!t.updatedAt)return 0;const s=Date.parse(t.updatedAt);return Number.isNaN(s)?0:s}function su(t,s){return jr(s)-jr(t)||t.sessionId.localeCompare(s.sessionId)}function nu(t){const s=t.trim().replace(/[\\/]+$/,"");return s?s.split(/[\\/]+/).filter(Boolean).at(-1)??s:"Unknown project"}function ru(t){const s=new Map;for(const n of[...t].sort(su)){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:nu(n),cwd:n,sessions:r}))}function au(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function ou({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:a,onCancel:i,className:l,footerClassName:c,submitLabel:d="Load session",cancelLabel:m="Cancel",autoFocus:p=!1}){const u=o.useMemo(()=>xo(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),h=o.useMemo(()=>n&&u.some(M=>M.id===n)?n:u[0]?.id??"",[u,n]),[x,k]=o.useState(""),[j,A]=o.useState("codex"),[f,E]=o.useState(""),[y,v]=o.useState(""),[b,C]=o.useState(""),[T,P]=o.useState(h),[S,I]=o.useState(os),[_,D]=o.useState(!1),[R,F]=o.useState([]),[Q,Y]=o.useState(!1),[X,Z]=o.useState(null),te=o.useMemo(()=>R.find(M=>M.sessionId===f)??null,[R,f]);o.useEffect(()=>{T&&u.some(M=>M.id===T)||P(h)},[T,u,h]),o.useEffect(()=>{E(""),v(""),C("")},[j,T]),o.useEffect(()=>{let M=!1;return T?(Y(!0),Z(null),Bi(T,{agent:j,limit:50}).then(ne=>{M||F(ne.sessions)}).catch(ne=>{M||(F([]),Z(ne instanceof Error?ne.message:"Failed to load native sessions"))}).finally(()=>{M||Y(!1)}),()=>{M=!0}):(F([]),Z(null),Y(!1),()=>{M=!0})},[j,T]),o.useEffect(()=>{te&&(v(te.sessionId),C(te.cwd))},[te]);const V=o.useCallback(async M=>{M.preventDefault();const ne=Xd({title:x,defaultTitle:te?.summary,agent:j,sessionId:y,cwd:b,assignTo:T,priority:"normal",mode:S});if(ne){D(!0);try{const H=await Oi(ne);a(H)}catch(H){ce.error(H instanceof Error?H.message:"Failed to load native session")}finally{D(!1)}}},[x,te,j,y,b,T,S,a]),O=!!(y.trim()&&b.trim()&&T),[g,$]=o.useState(!1),[N,q]=o.useState(""),[z,W]=o.useState(()=>new Set),L=u.find(M=>M.id===T)??null,oe=!!(n&&L?.id===n),ie=o.useMemo(()=>{const M=N.trim().toLowerCase();return M?R.filter(ne=>ne.summary.toLowerCase().includes(M)||ne.sessionId.toLowerCase().includes(M)||ne.cwd.toLowerCase().includes(M)):R},[R,N]),he=o.useMemo(()=>ru(ie),[ie]),ae=o.useCallback(M=>{W(ne=>au(ne,M))},[]),G="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:V,className:B("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(_e,{value:T,onValueChange:P,children:[e.jsx(Me,{className:B(G),"aria-label":"Node",children:L?e.jsxs(e.Fragment,{children:[e.jsx(Kn,{isCurrent:oe}),e.jsx("span",{className:"max-w-[10rem] truncate",children:L.name})]}):e.jsx($e,{placeholder:"Node"})}),e.jsx(Pe,{children:Pn(u,n)})]}),e.jsxs(_e,{value:j,onValueChange:M=>A(M),children:[e.jsxs(Me,{className:B(G),"aria-label":"Agent",children:[e.jsx(qn,{agent:j}),e.jsx("span",{children:j})]}),e.jsx(Pe,{children:lc()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(Ia,{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(ot,{value:N,onChange:M=>q(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(Ge,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:Q?"Loading...":`${ie.length} session${ie.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-sm",children:[Q&&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&&!Q&&ie.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:R.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),he.map(M=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>ae(M.cwd),"aria-expanded":!z.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:B("h-3.5 w-3.5 shrink-0 transition-transform",z.has(M.cwd)&&"-rotate-90")}),e.jsx(Ps,{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})]}),!z.has(M.cwd)&&M.sessions.map(ne=>{const H=ne.sessionId===f;return e.jsxs("button",{type:"button",onClick:()=>E(ne.sessionId),className:B("flex w-full flex-col gap-1 rounded-sm border px-2.5 py-2 text-left transition-colors duration-200",H?"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:B("h-2 w-2 shrink-0 rounded-full",H?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:ne.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:tu(ne.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:ne.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:ne.cwd})]})]},ne.sessionId)})]},M.cwd))]})]}),X&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:X})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>$(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":g,children:[e.jsx("span",{className:"shrink-0",children:g?"Less options":"More options"}),e.jsx(Je,{className:B("h-3.5 w-3.5 shrink-0 transition-transform",g&&"rotate-180")})]}),g&&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(Ge,{htmlFor:"native-session-id",className:"text-[10px] font-medium text-muted-foreground",children:"Session ID"}),e.jsx(ot,{id:"native-session-id",type:"text",value:y,onChange:M=>{E(""),v(M.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:p,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(Ge,{htmlFor:"native-session-title",className:"text-[10px] font-medium text-muted-foreground",children:"Task title"}),e.jsx(ot,{id:"native-session-title",type:"text",value:x,onChange:M=>k(M.target.value),placeholder:"Optional",className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none"})]})]}),e.jsx(Cs,{value:b,onChange:M=>{E(""),C(M)},assignTo:T,nodes:t,assignableNodes:u}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Ge,{className:"text-[10px] font-medium text-muted-foreground",children:"Mode"}),e.jsxs(_e,{value:S,onValueChange:M=>I(M),children:[e.jsx(Me,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx($e,{placeholder:"Select mode"})}),e.jsx(Pe,{children:eu()})]})]})]})]}),e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",c),children:[i&&e.jsx(J,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:m}),e.jsx(J,{type:"submit",disabled:!O||_,className:"rounded-sm px-5",children:_?e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-4 w-4 animate-spin"})," Loading..."]}):d})]})]})}const Ks="__agent-default__";function po({agent:t,value:s,onChange:n,triggerClassName:r,contentClassName:a="max-h-80",chip:i=!1}){const l=Ga(t,s);return o.useEffect(()=>{s&&!Za(t,s)&&n("")},[t,s,n]),e.jsxs(_e,{value:s||Ks,onValueChange:c=>n(c===Ks?"":c),children:[e.jsx(Me,{"aria-label":`Model: ${l}`,title:`Model: ${l}`,className:r,children:i?e.jsxs(e.Fragment,{children:[e.jsx(so,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:l})]}):e.jsx($e,{placeholder:"Agent default"})}),e.jsxs(Pe,{className:a,children:[e.jsx(De,{value:Ks,className:"py-1 text-[11px]",children:"Agent default"}),cc(t)]})]})}function iu(t){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[11px] font-medium",children:"Model"}),e.jsx(po,{...t,triggerClassName:"h-8 rounded-sm border-border/70 bg-background/70"})]})}function go(t,s,n=!1){const r=t.trim();if(r)return r;const a=s.trim().split(`
159
+ `).map(i=>i.trim()).find(Boolean);return a?a.length>72?`${a.slice(0,69).trimEnd()}...`:a:n?"Image task":""}function lu(t){const s=t.title.trim(),n=Xa(t.agent,t.description),r=n.prompt,a=go(t.title,r,t.images.length>0),i=r.trim()||a,l=t.mode??os,c=t.model?.trim(),d=c&&Za(t.agent,c)?c:"",m=n.isGoal?n.commandPrompt:r,p=Ka(m,t.images);return!a||!i||!t.agent?null:{title:a,description:i,agent:t.agent,project:t.project.trim()||null,branch:t.branch?.trim()||null,payload:{initialMessage:p,mode:l,...d?{model:d}:{},...n.isGoal?{goal:!0}:{},titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function cu({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,className:d,footerClassName:m,submitLabel:p="Create chat",cancelLabel:u="Cancel",autoFocus:h=!1,layout:x="default",quickChats:k=[]}){const[j,A]=o.useState(""),[f,E]=o.useState(""),[y,v]=o.useState(0),[b,C]=o.useState(rr),[T,P]=o.useState(""),[S,I]=o.useState(os),[_,D]=o.useState(i?.trim()??""),R=o.useRef(i!==void 0),[F,Q]=o.useState(""),Y=o.useMemo(()=>xo(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),X=o.useMemo(()=>a&&Y.some(ee=>ee.id===a)?a:n&&Y.some(ee=>ee.id===n)?n:Y[0]?.id??"",[Y,n,a]),[Z,te]=o.useState(X),[V,O]=o.useState(!1),[g,$]=o.useState(!1),{images:N,error:q,fileInputRef:z,pickImages:W,handleFileChange:L,handlePaste:oe,removeImage:ie}=co(),he=o.useRef(null),ae=o.useMemo(()=>Y.find(ee=>ee.id===Z)??null,[Z,Y]),G=!!(n&&ae?.id===n),M=Qa(b),ne=dc(S),H=o.useMemo(()=>Xa(b,f),[b,f]),re=o.useMemo(()=>Ya(b,f),[b,f]),we=H.prompt,fe=o.useMemo(()=>H.isGoal||re?[]:k,[H.isGoal,re,k]);o.useEffect(()=>{Z&&Y.some(ee=>ee.id===Z)||te(X)},[Z,Y,X]),o.useEffect(()=>{if(R.current){R.current=!1;return}D(fo(Z)),Q("")},[Z]),o.useEffect(()=>{Q("")},[_]),o.useEffect(()=>{v(0)},[f,k,b]);const Ie=o.useCallback(ee=>{E(ee.prompt)},[]),Ee=o.useCallback(()=>{E(re?.value??"/goal "),v(0),!(typeof window>"u")&&window.setTimeout(()=>{const ee=he.current;ee?.focus();const ge=ee?.value.length??0;ee?.setSelectionRange(ge,ge)},0)},[re]),xt=o.useCallback(async ee=>{if(ee.preventDefault(),re){Ee();return}const ge=ws(f,fe,y);if(ge){Ie(ge);return}const ye=lu({title:j,description:f,agent:b,model:T,project:_,branch:F,priority:"normal",assignTo:Z,mode:S,images:N});if(ye){O(!0);try{const Fe=await Ui(ye);l(Fe)}catch(Fe){ce.error(Fe instanceof Error?Fe.message:"Failed to create task")}finally{O(!1)}}},[j,f,b,T,_,F,Z,S,N,l,fe,y,Ie,re,Ee]),Le=go(j,we,N.length>0),Ze=!re&&!!(Le&&b&&Z&&(we.trim()||N.length>0)),Se=o.useCallback(ee=>{if(ee.nativeEvent.isComposing)return;if(re&&(ee.key==="ArrowDown"||ee.key==="ArrowUp")){ee.preventDefault();return}const ge=Da(f,fe);if(ge.length>0&&(ee.key==="ArrowDown"||ee.key==="ArrowUp")){ee.preventDefault(),v(ye=>_a(ye,ge.length,ee.key==="ArrowDown"?1:-1));return}if(ee.key==="Enter"){if(re&&!ee.shiftKey){ee.preventDefault(),Ee();return}const ye=ws(f,fe,y);if(ye&&!ee.shiftKey){ee.preventDefault(),Ie(ye);return}}ee.key==="Enter"&&(ee.ctrlKey||ee.metaKey)&&Ze&&!V&&(ee.preventDefault(),ee.currentTarget.form?.requestSubmit())},[Ee,Ie,fe,Ze,f,re,y,V]),He=N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:N.map((ee,ge)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:uc(ee),alt:ee.filename??`attachment ${ge+1}`,className:"h-20 w-20 rounded-sm border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>ie(ge),className:"absolute -top-2 -right-2 flex h-6 w-6 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${ee.filename??`image ${ge+1}`}`,children:e.jsx(it,{className:"h-3.5 w-3.5"})})]},`${ee.filename??"image"}-${ge}`))}),We=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[11px] font-medium",children:"Assign to"}),e.jsxs(_e,{value:Z,onValueChange:te,children:[e.jsx(Me,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select node"})}),e.jsx(Pe,{children:Pn(Y,n)})]})]}),Ke=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[11px] font-medium",children:"Agent"}),e.jsxs(_e,{value:b,onValueChange:C,children:[e.jsx(Me,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select agent"})}),e.jsx(Pe,{children:hr()})]})]}),Oe=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[11px] font-medium",children:"Mode"}),e.jsxs(_e,{value:S,onValueChange:ee=>I(ee),children:[e.jsx(Me,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select mode"})}),e.jsx(Pe,{children:fr()})]})]}),lt=e.jsx(Cs,{value:_,onChange:D,assignTo:Z,nodes:t,assignableNodes:Y}),ct=e.jsx(yr,{value:F,onChange:Q,project:_,assignTo:Z,nodes:t,assignableNodes:Y});return x==="composer"?e.jsxs("form",{onSubmit:xt,className:B("space-y-4",d),children:[e.jsx("input",{ref:z,type:"file",accept:"image/*",multiple:!0,onChange:L,className:"hidden"}),(()=>{const ee="chat-composer__chip h-9 min-w-0 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors [&>span]:min-w-0",ge="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",ye="border-border/70 bg-background/55 text-foreground",Fe=b===rr,ze=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(_e,{value:Z,onValueChange:te,children:[e.jsx(Me,{className:B(ee,ye,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${ae?.name??"unassigned"}`,"aria-label":`Assigned node: ${ae?.name??"unassigned"}`,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(Kn,{isCurrent:G}),e.jsx("span",{className:"min-w-0 truncate",children:ae.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:G?"current":"remote"})]}):e.jsx($e,{placeholder:"Select node"})}),e.jsx(Pe,{children:Pn(Y,n)})]}),g?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{id:"task-title-composer",type:"text",value:j,onChange:Ne=>A(Ne.target.value),onKeyDown:Ne=>{(Ne.key==="Enter"||Ne.key==="Escape")&&(Ne.preventDefault(),$(!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(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>$(!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:()=>$(!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:Le||"Title","aria-label":Le?`Edit title: ${Le}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:Le||"Title"}),e.jsx(Ot,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",ref:he,value:f,onChange:Ne=>E(Ne.target.value),onKeyDown:Se,onPaste:oe,placeholder:"Ask anything...",rows:4,autoFocus:h,"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(wr,{agent:b,query:f,onSelect:Ee}),e.jsx(Nn,{query:f,quickChats:fe,selectedIndex:y,onActiveIndexChange:v,onSelect:Ie}),e.jsxs("div",{className:"chat-composer__rail flex min-w-0 flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:W,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Dn,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(_e,{value:b,onValueChange:C,children:[e.jsxs(Me,{className:B(ee,"chat-composer__icon-trigger",Fe?ge:ye),title:`Agent: ${M}`,"aria-label":`Agent: ${M}`,children:[e.jsx(qn,{agent:b}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:M})]}),e.jsx(Pe,{children:hr()})]}),e.jsx(po,{agent:b,value:T,onChange:P,chip:!0,triggerClassName:B(ee,"chat-composer__icon-trigger",T?ye:ge),contentClassName:"max-h-80 shadow-none"}),e.jsxs(_e,{value:S,onValueChange:Ne=>I(Ne),children:[e.jsxs(Me,{className:B(ee,"chat-composer__icon-trigger",ze?ge:ye),title:`Mode: ${ne}`,"aria-label":`Mode: ${ne}`,children:[e.jsx(cd,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:ne})]}),e.jsx(Pe,{children:fr()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[c&&e.jsxs(J,{type:"button",variant:"ghost",size:"sm",onClick:c,"aria-label":u,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(it,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:u})]}),e.jsxs(J,{type:"submit",size:"icon",disabled:!Ze||V,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[V?e.jsx(de,{className:"h-4 w-4 animate-spin"}):e.jsx(ao,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:V?"Creating chat":p})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const Ne="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Cs,{value:_,onChange:D,assignTo:Z,nodes:t,assignableNodes:Y,layout:"composer",chipClassName:ee,chipActiveClassName:Ne,chipInactiveClassName:Ne,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(yr,{value:F,onChange:Q,project:_,assignTo:Z,nodes:t,assignableNodes:Y,layout:"composer",chipClassName:ee,chipActiveClassName:Ne,chipInactiveClassName:Ne,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(He||q)&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/45 p-2.5",children:[He,q&&e.jsx("div",{className:"text-[11px] text-destructive",children:q}),!q&&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:xt,className:B("space-y-4",d),children:[e.jsx("input",{ref:z,type:"file",accept:"image/*",multiple:!0,onChange:L,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{htmlFor:"task-description",className:"text-[11px] font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",ref:he,value:f,onChange:ee=>E(ee.target.value),onKeyDown:Se,onPaste:oe,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:h,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(wr,{agent:b,query:f,onSelect:Ee}),e.jsx(Nn,{query:f,quickChats:fe,selectedIndex:y,onActiveIndexChange:v,onSelect:Ie}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(J,{type:"button",variant:"outline",onClick:W,className:"rounded-sm",children:[e.jsx(Dn,{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."})]}),He,q&&e.jsx("p",{className:"text-[11px] text-destructive",children:q})]}),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(Ge,{htmlFor:"task-title",className:"text-[11px] font-medium",children:"Chat title"}),e.jsx(ot,{id:"task-title",type:"text",value:j,onChange:ee=>A(ee.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-8 rounded-sm border-border/70 bg-background/70"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:Le?`Will appear as: ${Le}`:"A title will be generated from the first line of the prompt."})]}),Ke,e.jsx(iu,{agent:b,value:T,onChange:P}),Oe]}),lt,ct,We,e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",m),children:[c&&e.jsx(J,{type:"button",variant:"ghost",onClick:c,className:"rounded-sm",children:u}),e.jsx(J,{type:"submit",disabled:!Ze||V,className:"rounded-sm px-5",children:V?"Creating...":p})]})]})}function du({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,defaultMode:d="chat",mode:m,onModeChange:p,layout:u="default",className:h,footerClassName:x,autoFocus:k=!1,quickChats:j=[]}){const[A,f]=o.useState(d),E=m!==void 0,y=E?m:A,v=b=>{E||f(b),p?.(b)};return e.jsxs("div",{className:B("space-y-4",h),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(J,{type:"button",variant:y==="chat"?"default":"ghost",onClick:()=>v("chat"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(zi,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(J,{type:"button",variant:y==="native"?"default":"ghost",onClick:()=>v("native"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(Vn,{className:"h-4 w-4"}),"Load session"]})]}),y==="chat"?e.jsx(cu,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,footerClassName:x,submitLabel:u==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:k,layout:u,quickChats:j},`${a??""}:${i??""}`):e.jsx(ou,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:l,onCancel:c,footerClassName:x,autoFocus:k})]})}function uu({onClick:t,running:s}){return e.jsxs(J,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:B("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(Ot,{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 Nr({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 mu({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",bo=`${Pt} (MSIT)`;function hu({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i=!1,shareResult:l}){return e.jsx(St,{open:t,onOpenChange:s,children:e.jsxs(Ct,{className:"max-w-md rounded-sm p-4",children:[e.jsx(Bt,{className:"sr-only",children:"Share conversation"}),e.jsx(fu,{onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i,shareResult:l})]})})}function fu({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:a=!1,shareResult:i}){const[l,c]=o.useState(i?.tenant??Pt),[d,m]=o.useState(i?.scope??"chat"),p=i?.url?Ra(i.url):null,u=r||a;return o.useEffect(()=>{c(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(xu,{value:l,onChange:c,disabled:u}),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(kr,{active:d==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>m("chat")}),e.jsx(kr,{active:d==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>m("filesPreview")})]})]}),p&&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:p,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>{Es(p,"Shared link copied")},"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(La,{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(J,{variant:"outline",onClick:()=>t(!1),disabled:u,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(J,{variant:"outline",onClick:()=>{n()},disabled:u,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[a&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(J,{onClick:()=>{s({tenant:l,scope:d})},disabled:u,className:"h-8 text-xs",children:[r&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function xu({value:t,onChange:s,disabled:n}){const[r,a]=o.useState(!1),[i,l]=o.useState(!1),[c,d]=o.useState(t),m=o.useRef(null);o.useEffect(()=>{d(t)},[t]),o.useEffect(()=>{if(!r)return;const u=x=>{const k=x.target;k instanceof Node&&(m.current?.contains(k)||(a(!1),l(!1)))},h=x=>{x.key==="Escape"&&(a(!1),l(!1))};return document.addEventListener("mousedown",u),document.addEventListener("keydown",h),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",h)}},[r]);const p=u=>{const h=u.trim();h&&(s(h),d(h),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(u=>!u),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:pu(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:()=>p(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:bo}),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:c,onChange:u=>d(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),p(c))},autoFocus:!0,placeholder:"Tenant ID",className:"h-7 min-w-0 flex-1 rounded-sm border border-border/60 bg-background/70 px-2 font-mono text-[11px] outline-none focus:ring-2 focus:ring-ring"}),e.jsx("button",{type:"button",onClick:()=>p(c),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:()=>{d(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(it,{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(Ot,{className:"h-3 w-3"})]})})]})]})]})}function pu(t){return t===Pt?bo:t}function kr({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 gu(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 bu({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(Jc,{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:gu(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(Wa,{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(J,{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(it,{className:"h-3 w-3"})})]},n.id)})})]})})}const vu="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",wu=[{value:"transcript",label:"Transcript",icon:$i},{value:"files",label:"Files",icon:Lt,activeIcon:Ps},{value:"diff",label:"Diff",icon:Ns},{value:"preview",label:"Preview",icon:jc}];function yu({activeTab:t}){return e.jsx(On,{className:"h-auto max-w-full justify-start gap-2 overflow-x-auto rounded-sm !bg-muted/40 !p-0.5 !shadow-none",children:wu.map(s=>{const n=s.value===t&&s.activeIcon?s.activeIcon:s.icon;return e.jsx(Nt,{value:s.value,title:s.label,"aria-label":s.label,className:vu,children:e.jsx(n,{className:"h-3.5 w-3.5","aria-hidden":"true"})},s.value)})})}const vo="pointer-events-auto h-5 w-5 shrink-0 rounded-sm bg-muted/65 text-muted-foreground hover:bg-muted hover:text-foreground",Ts="h-3.5 w-3.5";function In({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(wo,{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(yo,{operationsOpen:r,onToggleOperations:a,className:"xl:hidden"})]})}function wo({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){const a=globalThis.window?.matchMedia("(min-width: 1024px)")?.matches?s:n;return e.jsx(J,{variant:"ghost",size:"icon",onClick:r,title:a?"Hide tasks":"Show tasks","aria-label":a?"Hide tasks":"Show tasks",className:B(vo,t),children:a?e.jsx(js,{className:Ts}):e.jsx(st,{className:Ts})})}function yo({className:t,operationsOpen:s,onToggleOperations:n}){return e.jsx(J,{variant:"ghost",size:"icon",onClick:n,title:s?"Hide cluster":"Show cluster","aria-label":s?"Hide cluster":"Show cluster",className:B(vo,t),children:s?e.jsx(st,{className:Ts}):e.jsx(js,{className:Ts})})}const Sr="h-7 w-7 rounded-sm border-0 bg-primary/10 text-primary backdrop-blur hover:bg-primary/20 hover:text-primary";function ju({active:t,onScrollToBottom:s,onScrollToTop:n}){return e.jsxs("div",{className:B("pointer-events-none absolute right-3 top-1/2 z-10 flex -translate-y-1/2 flex-col gap-2 opacity-0 transition-opacity duration-200 group-hover:pointer-events-auto group-hover:opacity-100",t&&"pointer-events-auto opacity-100"),children:[e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:Sr,onClick:n,"aria-label":"Scroll to top",title:"Scroll to top",children:e.jsx(qi,{className:"h-4 w-4"})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:Sr,onClick:s,"aria-label":"Scroll to bottom",title:"Scroll to bottom",children:e.jsx(Je,{className:"h-4 w-4"})})]})}const Cr="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",jt={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:`${Cr} mt-0`,action:Cr},Nu=30,ku=1600;function Su({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Gs(t){return t.scrollHeight-t.scrollTop-t.clientHeight<Nu}function Tr({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function Ws(t,s){return!!(s&&(t===s||t.contains(s)))}function Qs(t){const s=t.ownerDocument.getSelection();if(!s||s.isCollapsed||s.rangeCount===0)return!1;if(Ws(t,s.anchorNode)||Ws(t,s.focusNode))return!0;for(let n=0;n<s.rangeCount;n+=1)if(Ws(t,s.getRangeAt(n).commonAncestorContainer))return!0;return!1}function Cu({atTop:t,inputCollapseDisabled:s,scrollingUp:n}){return!s&&(n||t)}function Tu({activeTab:t,activeTaskId:s,contentVersion:n,inputCollapseDisabled:r=!1,setActiveTab:a,setInputCollapsed:i}){const l=o.useRef(null),c=o.useRef(s),d=o.useRef(!1),m=o.useRef(0),p=o.useRef(new Map),u=o.useRef(0),h=o.useRef(!0),x=o.useCallback((v=c.current)=>{const b=l.current;!b||!v||(p.current.set(v,b.scrollTop),m.current=b.scrollTop,h.current=Gs(b))},[]),k=o.useCallback((v=c.current)=>{const b=l.current;!b||!v||(b.scrollTop=Su({savedScrollTop:p.current.get(v),scrollHeight:b.scrollHeight,clientHeight:b.clientHeight}),m.current=b.scrollTop,h.current=Gs(b))},[]),j=o.useCallback((v,b=c.current)=>{v.scrollTop=v.scrollHeight,m.current=v.scrollTop,h.current=!0,b&&p.current.set(b,v.scrollTop)},[]),A=o.useCallback((v=c.current)=>{const b=l.current;u.current=Date.now()+ku,b&&(j(b,v),requestAnimationFrame(()=>{j(b,v),requestAnimationFrame(()=>j(b,v))}))},[j]),f=o.useCallback((v=c.current)=>{const b=l.current;u.current=0,b&&(b.scrollTop=0,m.current=0,h.current=!1,v&&p.current.set(v,0))},[]),E=o.useCallback(v=>{const b=v.currentTarget,C=m.current,T=b.scrollTop<C&&C-b.scrollTop>10,P=b.scrollTop<=0,S=Qs(b);if(x(),S){u.current=0;return}if(!d.current){if(Gs(b)){i(!1),d.current=!0,setTimeout(()=>{d.current=!1},300);return}(T||P)&&(u.current=0,Cu({atTop:P,inputCollapseDisabled:r,scrollingUp:T})&&i(!0))}},[r,x,i]),y=o.useCallback(v=>{t==="transcript"&&x(),a(v),v==="transcript"&&requestAnimationFrame(()=>k())},[t,k,x,a]);return o.useLayoutEffect(()=>{r&&i(!1)},[r,i]),o.useLayoutEffect(()=>{const v=c.current;v&&v!==s&&x(v),c.current=s,t==="transcript"&&requestAnimationFrame(()=>k(s))},[s,t,k,x]),o.useLayoutEffect(()=>{const v=l.current;if(!v||t!=="transcript"||!s)return;const b=Tr({explicitBottomStickUntil:u.current,now:Date.now(),wasAtBottom:h.current});if(Qs(v)){u.current=0,x(s);return}b&&j(v,s),x(s)},[s,t,n,x,j]),o.useLayoutEffect(()=>{const v=l.current,b=v?.firstElementChild;if(!v||!b||t!=="transcript"||typeof ResizeObserver>"u")return;const C=new ResizeObserver(()=>{if(Qs(v)){u.current=0,x();return}Tr({explicitBottomStickUntil:u.current,now:Date.now(),wasAtBottom:h.current})?j(v):x()});return C.observe(v),C.observe(b),()=>C.disconnect()},[t,s,x,j]),{handleTranscriptScroll:E,handleTranscriptTabChange:y,scrollTranscriptToBottom:A,scrollTranscriptToTop:f,transcriptScrollRef:l}}function jo(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 Eu=o.lazy(async()=>({default:(await zn(()=>import("./FilesTab-uM8qGxbi.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Au=o.lazy(async()=>({default:(await zn(()=>import("./PreviewTab-K7c436fs.js").then(s=>s.c),__vite__mapDeps([6,1,2]))).PreviewTab})),Du=o.lazy(async()=>({default:(await zn(()=>import("./DiffTab-JNuSFUCI.js"),__vite__mapDeps([7,1,2,5,4,3,6]))).DiffTab}));function _u({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,activeTab:l,setActiveTab:c,creatingTask:d,createMode:m,createDefaults:p,activeTask:u,assignedNode:h,taskLoading:x,transcriptLoading:k,taskError:j,displayEvents:A,initialPromptAlreadyInLogs:f,initialPrompt:E,supportsFollowUp:y,taskUnavailable:v,chatDisabled:b,chatDisabledReason:C,questionBypassEnabled:T,isRunning:P,isStarting:S,hasPendingFollowUp:I,canCancel:_,canRetry:D,onRetry:R,onCancel:F,onReloadNativeTranscript:Q,onShareTask:Y,onStopShareTask:X,onStartCreateTask:Z,onCancelCreateTask:te,onCreateTask:V,onSendMessage:O,onCancelQueuedMessage:g,onQuestionBypassChange:$,onSubmitQuestionResponse:N,quickChats:q=[]}){const[z,W]=o.useState(!1),[L,oe]=o.useState(!1),[ie,he]=o.useState(!1),[ae,G]=o.useState(!1),[M,ne]=o.useState(!1),[H,re]=o.useState({}),[we,fe]=o.useState(new Set),[Ie,Ee]=o.useState(new Set),[xt,Le]=o.useState(null),[Ze,Se]=o.useState(null),He=u?.effectiveProjectPath??u?.project??"default workspace",We=u?h?.name??kn(u.assignedTo,i?.nodes,u.assignedNodeName):"unassigned",Ke=u?.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:We}),"..."]}):"Connecting session to an available node...",Oe=u?[{label:"Working dir",value:He,mono:!0},...u.branch?[{label:"Branch",value:u.branch,mono:!0}]:[],{label:"Agent",value:u.agent,mono:!0},{label:"Node",value:We}]:[],lt=!!(E&&!f),ct=lt||A.length>0,ee=P&&ct,ge=(S||I||P)&&!ee,ye=ee?"The agent is still working on this conversation.":ge?Ke:null,{collapsedButtonRunning:Fe,showDockedProgress:ze,showInlineProgress:Ne}=mu({hasTranscriptProgress:!!ye,hasVisibleTranscriptEvents:ct,inputCollapsed:z}),je=u?.conversationKind==="nativeSession",pt=mc(u),zt=k?"Loading transcript":je?"No transcript imported":"Transcript is warming up",Ut=k?"Loading transcript...":je?"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.",K=u?.queuedMessages??[],ke=o.useMemo(()=>hc(A),[A]),Ae=o.useMemo(()=>ke.findIndex(({event:pe})=>Mu(pe)),[ke]),wt=o.useMemo(()=>fc("transcript",ke.map(pe=>pe.event)),[ke]),$t=u&&!we.has(u.id)?H[u.id]??u.activeShare??null:null,yt=u?.id??null,Be=`${yt??"none"}:${A.length}:${K.length}:${lt?1:0}:${k?1:0}:${Ne?1:0}`,{handleTranscriptScroll:Qe,handleTranscriptTabChange:nt,scrollTranscriptToBottom:dt,scrollTranscriptToTop:ut,transcriptScrollRef:At}=Tu({activeTab:l,activeTaskId:yt,contentVersion:Be,inputCollapseDisabled:!!ye,setActiveTab:c,setInputCollapsed:W}),{markScrollbarActive:Re,scrollbarActive:mt}=jo(),Ce=o.useCallback(pe=>{Re(),Qe(pe)},[Qe,Re]),Xe=o.useCallback(pe=>{Le(be=>({path:pe,requestId:(be?.requestId??0)+1})),nt("files")},[nt]),qe=o.useCallback(pe=>{Se(be=>({path:pe,requestId:(be?.requestId??0)+1})),nt("preview")},[nt]),qt=o.useCallback(pe=>{dt(),O(pe)},[O,dt]);return o.useEffect(()=>{Le(null),Se(null)},[yt]),d?e.jsx(Pu,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,defaultMode:m,createDefaults:p,onCancel:te,onCreated:V,quickChats:q}):!u&&x?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(In,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a})}),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(de,{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(de,{className:"h-3.5 w-3.5 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):u?e.jsxs(Fn,{value:l,onValueChange:nt,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(wo,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(yo,{operationsOpen:r,onToggleOperations:a,className:"xl:hidden"})]}),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(Ba,{status:u.status,isNative:je}),pt&&e.jsxs("span",{"data-task-goal-label":"true",title:"Codex goal",className:"inline-flex h-5 shrink-0 items-center gap-1 rounded-sm bg-primary/10 px-1.5 text-[9px] font-semibold uppercase tracking-[0.12em] text-primary",children:[e.jsx(Ja,{className:"h-3 w-3","aria-hidden":"true"}),"Goal"]}),u.priority!=="normal"&&e.jsx(Hi,{priority:u.priority})]}),j&&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:j}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx(yu,{activeTab:l}),v&&e.jsx(Ve,{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:Ki(u.updatedAt)}),D&&e.jsxs(J,{variant:"ghost",size:"sm",onClick:R,"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(rd,{className:"h-3.5 w-3.5"}),"Retry"]}),je&&Q&&e.jsx(J,{variant:"ghost",size:"icon",onClick:Q,disabled:k,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(ro,{className:B("h-3.5 w-3.5",k&&"animate-spin")})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",disabled:v,title:v?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":v?"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:()=>he(!0),children:e.jsx(Ss,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(ft,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"group 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:At,"data-transcript-scroll":"true",className:B("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",mt&&"scrollbar-line-active"),onScroll:Ce,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[lt&&E&&e.jsx(xr,{event:E,agent:u.agent,sentAsGoal:pt,taskRootPath:u.effectiveProjectPath,onOpenFilePath:Xe,questionBypassEnabled:T,onQuestionBypassChange:$,onSubmitQuestionResponse:N,questionResponseDisabled:!y||b}),ke.map(({event:pe,subItems:be},Te)=>e.jsx(xr,{event:pe,agent:u.agent,subItems:be,sentAsGoal:pt&&!lt&&Te===Ae,taskRootPath:u.effectiveProjectPath,onOpenFilePath:Xe,questionBypassEnabled:T,onQuestionBypassChange:$,onSubmitQuestionResponse:N,questionResponseDisabled:!y||b},wt[Te])),!ct&&!ge&&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:zt}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Ut})]}),(!y&&u.result||u.error)&&e.jsxs("div",{className:"space-y-3",children:[!y&&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&&!Ie.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:()=>Ee(pe=>new Set(pe).add(u.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(it,{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})]})]}),Ne&&ye&&e.jsx(Nr,{children:ye})]})})}),e.jsx(ju,{active:mt,onScrollToBottom:()=>dt(),onScrollToTop:()=>ut()}),ze&&ye&&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(Nr,{children:ye})})}),y?e.jsxs(e.Fragment,{children:[z&&e.jsx(uu,{running:Fe,onClick:()=>{W(!1),dt(),requestAnimationFrame(()=>document.querySelector('[data-chat-input-textarea="true"]')?.focus())}}),e.jsxs("div",{className:`shrink-0 ${z?"hidden":""}`,children:[e.jsx(bu,{messages:K,onCancelMessage:g}),e.jsx(Pd,{onSend:qt,disabled:b,disabledReason:C,contextItems:Oe,agent:u.agent,model:typeof u.payload.model=="string"?u.payload.model:null,placeholder:b?C:P?"Queue a message for the next turn...":"Continue the conversation...",running:P||I,onStop:_?()=>oe(!0):void 0,quickChats:q})]})]}):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(ft,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Vs,{label:"Loading files..."}),children:e.jsx(Eu,{taskId:u.id,requestedFilePath:xt?.path??null,requestedFileRequestId:xt?.requestId??0,onPreviewFile:qe})})}),e.jsx(ft,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Vs,{label:"Loading preview..."}),children:e.jsx(Au,{taskId:u.id,requestedEntryPath:Ze?.path??null,requestedEntryRequestId:Ze?.requestId??0})})}),e.jsx(ft,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Vs,{label:"Loading diff..."}),children:e.jsx(Du,{taskId:u.id})})}),e.jsx(Yt,{open:L,onOpenChange:oe,children:e.jsxs(Jt,{className:jt.content,children:[e.jsxs(Zt,{className:jt.header,children:[e.jsx(Xt,{className:jt.title,children:"Stop this task?"}),e.jsx(es,{className:jt.description,children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ts,{className:jt.footer,children:[e.jsx(ss,{className:jt.cancel,children:"Keep running"}),e.jsx(ns,{className:jt.action,onClick:F,children:"Stop task"})]})]})}),e.jsx(hu,{open:ie,onOpenChange:he,sharing:ae,stopping:M,shareResult:$t,onShare:async pe=>{if(!u)return null;G(!0);try{const be=await Y(pe);return be?.url&&(re(Te=>({...Te,[u.id]:be})),fe(Te=>{const ls=new Set(Te);return ls.delete(u.id),ls})),be}finally{G(!1)}},onStopShare:async()=>{if(!u)return!1;ne(!0);try{const pe=await X();return pe!==!1&&(re(be=>{const Te={...be};return delete Te[u.id],Te}),fe(be=>new Set(be).add(u.id))),pe}finally{ne(!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(In,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a})}),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(Vi,{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(J,{onClick:()=>Z(),className:"mt-4 h-8 rounded-sm px-3",children:[e.jsx(Is,{className:"h-3.5 w-3.5"}),"Start or load chat"]}),j&&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:j})]})})]})}function Mu(t){return t.type!=="user"||t.isMeta===!0||t.isSidechain===!0?!1:!!Tn(t)?.some(n=>n.type==="text"||n.type==="image")}function Pu({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,defaultMode:l,createDefaults:c,onCancel:d,onCreated:m,quickChats:p}){const[u,h]=o.useState(l??"chat");o.useEffect(()=>{l&&h(l)},[l]);const x=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:Is},{value:"native",label:"Load session",icon:Vn}].map(k=>{const j=k.icon,A=k.value===u;return e.jsxs("button",{type:"button",onClick:()=>h(k.value),"aria-pressed":A,className:B("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",A?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(j,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:k.label})]},k.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(In,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,centerSlot:x})}),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(du,{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:h,onCreated:m,onCancel:d,autoFocus:!0,layout:"composer",quickChats:p})})})]})}function Iu({onAdded:t}){const[s,n]=o.useState(""),[r,a]=o.useState(!1),[i,l]=o.useState(null),c=o.useCallback(async d=>{if(d.preventDefault(),!!s.trim()){a(!0),l(null);try{await Gi({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(Ct,{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(As,{className:"space-y-1 text-left",children:[e.jsx(Bt,{className:"text-sm tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Verify the remote leader's DevTunnel Node URL, sync this node's tasks to that leader, and join the cluster as a follower."})]})}),e.jsxs("form",{onSubmit:c,className:"space-y-3 px-3.5 py-3",children:[i&&e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Ge,{htmlFor:"leader-endpoint",children:"Leader Node URL"}),e.jsx(Ve,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(ot,{id:"leader-endpoint",type:"url",value:s,onChange:d=>n(d.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(Oa,{className:"border-t border-border/60 pt-3",children:e.jsx(J,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function Ru({open:t,onOpenChange:s,onAdded:n}){return e.jsx(St,{open:t,onOpenChange:s,children:e.jsx(Iu,{onAdded:()=>{s(!1),n()}})})}const Lu="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",Bu="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",Ou="h-2.5 w-2.5";function No({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:B("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 Fu({className:t,label:s,onToggle:n,side:r,visible:a}){const i=r==="left"?a?js:st:a?st:js;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:B(Lu,t),children:e.jsx("span",{className:Bu,"aria-hidden":"true",children:e.jsx(i,{className:Ou,strokeWidth:2.1})})})}function Er({className:t,label:s,onToggle:n,panel:r,panelResize:a,screen:i,side:l,visible:c}){const d=i==="lg"?"lg:block":"xl:block",m=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:B("group absolute top-0 z-30 hidden h-full w-4",d,t),children:[r&&e.jsx(No,{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(Fu,{side:l,visible:c,label:s,onToggle:n,className:B(m,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function zu({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:a,operationsOpen:i,operationsPanelRef:l,operationsSidecar:c,panelResize:d,taskSidebar:m,terminalPanel:p,onCloseOperations:u,onCloseTaskList:h,onToggleOperations:x,onToggleTasks:k}){const j={"--dashboard-tasks-width":d.sizes.tasks,"--dashboard-operations-width":d.sizes.operations,"--dashboard-terminal-height":d.sizes.terminal};return e.jsxs("div",{className:"dashboard-workspace flex h-full min-h-0 flex-col overflow-hidden",style:j,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(Er,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:k,panel:s?"tasks":void 0,panelResize:d,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:B("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}),p&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(No,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:d,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),p]})]}),e.jsx(Er,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:x,panel:i?"operations":void 0,panelResize:d,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:B("dashboard-workspace__operations-panel relative hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",i?"xl:ml-2 xl:w-[var(--dashboard-operations-width)]":"xl:w-0 xl:overflow-hidden"),children:i&&c})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:u,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:c})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:h,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 Uu=10,kt="__all__";function et(t){return"session"in t}function Ar(t,s){return s&&t.some(n=>n.id===s)?s:t[0]?.id??""}function Ys(t){return t&&(fo(t.id)||t.workDir)||""}function xs(t,s,n){let r=!1;const a=t.map(i=>et(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return Rn(r?a:[...a,{id:`session-${n.id}`,nodeName:s,session:n}])}function ko(t,s){return t.filter(et).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function $u(t){const s=t.filter(et).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 qu(t,s){return!!(t&&s&&!t.contains(s))}function Vu(t,s,n){if(n===kt)return n;const r=ko(t,s);return r.some(a=>a.session.id===n)?n:r[0]?.session.id??kt}function Hu(t,s,n){return n===kt?t.filter(r=>!et(r)||r.session.nodeId===s):t.filter(r=>et(r)&&r.session.nodeId===s&&r.session.id===n)}function Rn(t){const s=t.map((r,a)=>({entry:r,index:a})).filter(({entry:r})=>et(r)&&r.session.status!=="running").sort((r,a)=>!et(r.entry)||!et(a.entry)?0:a.entry.session.startedAt-r.entry.session.startedAt||a.index-r.index),n=new Set(s.slice(0,Uu).map(({entry:r})=>et(r)?r.session.id:""));return t.filter(r=>!et(r)||r.session.status==="running"||n.has(r.session.id))}function Ln(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 Ku(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${Ln(t.session)} - ${s}`}function So(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function Gu(t,s){return s===kt?"All sessions":t?So(t.session.command,34):"Command session"}function Dr(t){return t.status==="stopped"?"":t.stderr}function Wu({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[a,i]=o.useState(()=>Ar(t,s)),l=o.useMemo(()=>t.find(N=>N.id===a)??t[0]??null,[t,a]),[c,d]=o.useState(()=>Ys(l)),[m,p]=o.useState(""),[u,h]=o.useState(()=>Rn(r)),[x,k]=o.useState(kt),[j,A]=o.useState(!1),[f,E]=o.useState(!1),[y,v]=o.useState(!1),[b,C]=o.useState(!1),[T,P]=o.useState(!1),S=o.useRef(null),I=o.useRef(null),_=o.useMemo(()=>t.find(N=>N.id===a)??t[0]??null,[t,a]),D=o.useMemo(()=>ko(u,_?.id??""),[u,_]),R=o.useMemo(()=>$u(D),[D]),F=o.useMemo(()=>D.find(N=>N.session.id===x),[x,D]),Q=o.useMemo(()=>Hu(u,_?.id??"",x),[u,_,x]),Y=o.useRef(_?.id??"");o.useEffect(()=>{a&&t.some(N=>N.id===a)||i(Ar(t,s))},[s,t,a]),o.useEffect(()=>{const N=_?.id??"";Y.current!==N&&(Y.current=N,d(Ys(_)))},[_]),o.useEffect(()=>{k(N=>Vu(u,_?.id??"",j?N:""))},[u,_,j]),o.useEffect(()=>{S.current?.scrollTo({top:S.current.scrollHeight})},[u]),o.useEffect(()=>{let N=!1;async function q(){const z=await Promise.allSettled(t.map(async W=>({node:W,response:await Qi(W.id)})));N||h(W=>z.reduce((L,oe)=>oe.status!=="fulfilled"?L:oe.value.response.sessions.reduce((ie,he)=>xs(ie,oe.value.node.name,he),L),W))}return t.length>0&&q(),()=>{N=!0}},[t]),o.useEffect(()=>{const N=u.filter(et).filter(z=>z.session.status==="running");if(N.length===0)return;const q=window.setInterval(()=>{for(const z of N)Wi(z.session.nodeId,z.session.id).then(W=>h(L=>xs(L,z.nodeName,W))).catch(()=>{})},1e3);return()=>window.clearInterval(q)},[u]);const X=o.useRef(null);async function Z(N){if(N.preventDefault(),!_||!m.trim()||T)return;const q=m.trim(),z=_.name;P(!0),p("");try{const W=await Ji(_.id,{command:q,...c.trim()?{cwd:c.trim()}:{}});h(L=>xs(L,z,W)),k(W.id),A(!0)}catch(W){h(L=>[...L,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:z,command:q,error:W instanceof Error?W.message:"Command failed"}])}finally{P(!1)}}async function te(N,q){N.stopPropagation();const z=await Yi(q.session.nodeId,q.session.id);h(W=>xs(W,q.nodeName,z))}function V(N){k(N),A(!0),E(!1)}function O(N){f&&qu(I.current,N.target)&&E(!1)}function g(N,q,z,W,L){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:W,"aria-label":`Toggle ${N} sessions`,"aria-expanded":!z,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:N}),e.jsx(Je,{className:B("h-3 w-3 transition-transform",z&&"-rotate-90")})]}),!z&&(q.length>0?q.map($):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:L}))]})}function $(N){const q=x===N.session.id,z=N.session.status==="running";return e.jsxs("div",{className:B("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",q&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>V(N.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:B("flex h-4 w-4 shrink-0 items-center justify-center",z?"text-primary":N.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:z?e.jsx(de,{className:"h-3 w-3 animate-spin"}):N.session.status==="exited"?e.jsx(or,{className:"h-3 w-3"}):e.jsx($s,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:So(N.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[N.nodeName," · ",Ln(N.session)]})]})]}),z&&e.jsx("button",{type:"button",onClick:W=>{te(W,N)},"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"})})]},N.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(it,{className:"h-3.5 w-3.5"})}):e.jsx(ar,{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:I,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":f,title:F?Ku(F):"All sessions",onClick:()=>E(N=>!N),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:Gu(F,x)}),e.jsx(Je,{className:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform",f&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!f,className:B("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!f&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>V(kt),className:B("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",x===kt&&"bg-primary/10 text-primary"),children:[e.jsx(ar,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),g("Active",R.active,y,()=>v(N=>!N),"No active sessions"),g("Completed",R.completed,b,()=>C(N=>!N),"No completed sessions")]})})]}),e.jsx("select",{value:_?.id??"",onChange:N=>{i(N.target.value),A(!1),d(Ys(t.find(q=>q.id===N.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(N=>e.jsx("option",{value:N.id,className:"bg-background text-foreground",children:N.name},N.id))}),e.jsx(Cs,{value:c,onChange:d,assignTo:_?.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(N=>et(N)?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:[N.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:N.session.command}),e.jsxs("span",{className:B("inline-flex items-center gap-1",N.session.status==="running"||N.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[N.session.status==="running"?e.jsx(de,{className:"h-3 w-3 animate-spin"}):N.session.status==="exited"?e.jsx(or,{className:"h-3 w-3"}):e.jsx($s,{className:"h-3 w-3"}),Ln(N.session)]}),N.session.status==="running"&&e.jsx("button",{type:"button",onClick:q=>{te(q,N)},"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"})})]}),N.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:N.session.stdout}),Dr(N.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Dr(N.session)}),(N.session.stdoutTruncated||N.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},N.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:[N.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:N.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx($s,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:N.error})]},N.id))}),e.jsxs("form",{onSubmit:Z,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:_?`${_.name}$`:"$"}),e.jsx("input",{ref:X,value:m,onChange:N=>p(N.target.value),disabled:!_||T,placeholder:_?"":"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:!_||!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(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Ms,{className:"h-3 w-3"})})]})]})]})})}var Mt={},Js,_r;function Qu(){return _r||(_r=1,Js=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Js}var Zs={},bt={},Mr;function Tt(){if(Mr)return bt;Mr=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 bt.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},bt.getSymbolTotalCodewords=function(r){return s[r]},bt.getBCHDigit=function(n){let r=0;for(;n!==0;)r++,n>>>=1;return r},bt.setToSJISFunction=function(r){if(typeof r!="function")throw new Error('"toSJISFunc" is not a valid function.');t=r},bt.isKanjiModeEnabled=function(){return typeof t<"u"},bt.toSJIS=function(r){return t(r)},bt}var Xs={},Pr;function Gn(){return Pr||(Pr=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}}})(Xs)),Xs}var en,Ir;function Yu(){if(Ir)return en;Ir=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++}},en=t,en}var tn,Rr;function Ju(){if(Rr)return tn;Rr=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]},tn=t,tn}var sn={},Lr;function Zu(){return Lr||(Lr=1,(function(t){const s=Tt().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,c=[i-7];for(let d=1;d<a-1;d++)c[d]=c[d-1]-l;return c.push(6),c.reverse()},t.getPositions=function(r){const a=[],i=t.getRowColCoords(r),l=i.length;for(let c=0;c<l;c++)for(let d=0;d<l;d++)c===0&&d===0||c===0&&d===l-1||c===l-1&&d===0||a.push([i[c],i[d]]);return a}})(sn)),sn}var nn={},Br;function Xu(){if(Br)return nn;Br=1;const t=Tt().getSymbolSize,s=7;return nn.getPositions=function(r){const a=t(r);return[[0,0],[a-s,0],[0,a-s]]},nn}var rn={},Or;function em(){return Or||(Or=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,c=0,d=0,m=null,p=null;for(let u=0;u<i;u++){c=d=0,m=p=null;for(let h=0;h<i;h++){let x=a.get(u,h);x===m?c++:(c>=5&&(l+=s.N1+(c-5)),m=x,c=1),x=a.get(h,u),x===p?d++:(d>=5&&(l+=s.N1+(d-5)),p=x,d=1)}c>=5&&(l+=s.N1+(c-5)),d>=5&&(l+=s.N1+(d-5))}return l},t.getPenaltyN2=function(a){const i=a.size;let l=0;for(let c=0;c<i-1;c++)for(let d=0;d<i-1;d++){const m=a.get(c,d)+a.get(c,d+1)+a.get(c+1,d)+a.get(c+1,d+1);(m===4||m===0)&&l++}return l*s.N2},t.getPenaltyN3=function(a){const i=a.size;let l=0,c=0,d=0;for(let m=0;m<i;m++){c=d=0;for(let p=0;p<i;p++)c=c<<1&2047|a.get(m,p),p>=10&&(c===1488||c===93)&&l++,d=d<<1&2047|a.get(p,m),p>=10&&(d===1488||d===93)&&l++}return l*s.N3},t.getPenaltyN4=function(a){let i=0;const l=a.data.length;for(let d=0;d<l;d++)i+=a.data[d];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 c=0;c<l;c++)for(let d=0;d<l;d++)i.isReserved(d,c)||i.xor(d,c,n(a,d,c))},t.getBestMask=function(a,i){const l=Object.keys(t.Patterns).length;let c=0,d=1/0;for(let m=0;m<l;m++){i(m),t.applyMask(m,a);const p=t.getPenaltyN1(a)+t.getPenaltyN2(a)+t.getPenaltyN3(a)+t.getPenaltyN4(a);t.applyMask(m,a),p<d&&(d=p,c=m)}return c}})(rn)),rn}var ps={},Fr;function Co(){if(Fr)return ps;Fr=1;const t=Gn(),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 an={},Wt={},zr;function tm(){if(zr)return Wt;zr=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 Ur;function sm(){return Ur||(Ur=1,(function(t){const s=tm();t.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let l=0;l<r.length;l++)for(let c=0;c<a.length;c++)i[l+c]^=s.mul(r[l],a[c]);return i},t.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const l=i[0];for(let d=0;d<a.length;d++)i[d]^=s.mul(a[d],l);let c=0;for(;c<i.length&&i[c]===0;)c++;i=i.slice(c)}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}})(an)),an}var on,$r;function nm(){if($r)return on;$r=1;const t=sm();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 c=new Uint8Array(this.degree);return c.set(i,l),c}return i},on=s,on}var ln={},cn={},dn={},qr;function To(){return qr||(qr=1,dn.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),dn}var ht={},Vr;function Eo(){if(Vr)return ht;Vr=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
160
+ ]))+`;ht.KANJI=new RegExp(n,"g"),ht.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),ht.BYTE=new RegExp(r,"g"),ht.NUMERIC=new RegExp(t,"g"),ht.ALPHANUMERIC=new RegExp(s,"g");const a=new RegExp("^"+n+"$"),i=new RegExp("^"+t+"$"),l=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return ht.testKanji=function(d){return a.test(d)},ht.testNumeric=function(d){return i.test(d)},ht.testAlphanumeric=function(d){return l.test(d)},ht}var Hr;function Et(){return Hr||(Hr=1,(function(t){const s=To(),n=Eo();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}}})(cn)),cn}var Kr;function rm(){return Kr||(Kr=1,(function(t){const s=Tt(),n=Co(),r=Gn(),a=Et(),i=To(),l=7973,c=s.getBCHDigit(l);function d(h,x,k){for(let j=1;j<=40;j++)if(x<=t.getCapacity(j,k,h))return j}function m(h,x){return a.getCharCountIndicator(h,x)+4}function p(h,x){let k=0;return h.forEach(function(j){const A=m(j.mode,x);k+=A+j.getBitsLength()}),k}function u(h,x){for(let k=1;k<=40;k++)if(p(h,k)<=t.getCapacity(k,x,a.MIXED))return k}t.from=function(x,k){return i.isValid(x)?parseInt(x,10):k},t.getCapacity=function(x,k,j){if(!i.isValid(x))throw new Error("Invalid QR Code version");typeof j>"u"&&(j=a.BYTE);const A=s.getSymbolTotalCodewords(x),f=n.getTotalCodewordsCount(x,k),E=(A-f)*8;if(j===a.MIXED)return E;const y=E-m(j,x);switch(j){case a.NUMERIC:return Math.floor(y/10*3);case a.ALPHANUMERIC:return Math.floor(y/11*2);case a.KANJI:return Math.floor(y/13);case a.BYTE:default:return Math.floor(y/8)}},t.getBestVersionForData=function(x,k){let j;const A=r.from(k,r.M);if(Array.isArray(x)){if(x.length>1)return u(x,A);if(x.length===0)return 1;j=x[0]}else j=x;return d(j.mode,j.getLength(),A)},t.getEncodedBits=function(x){if(!i.isValid(x)||x<7)throw new Error("Invalid QR Code version");let k=x<<12;for(;s.getBCHDigit(k)-c>=0;)k^=l<<s.getBCHDigit(k)-c;return x<<12|k}})(ln)),ln}var un={},Gr;function am(){if(Gr)return un;Gr=1;const t=Tt(),s=1335,n=21522,r=t.getBCHDigit(s);return un.getEncodedBits=function(i,l){const c=i.bit<<3|l;let d=c<<10;for(;t.getBCHDigit(d)-r>=0;)d^=s<<t.getBCHDigit(d)-r;return(c<<10|d)^n},un}var mn={},hn,Wr;function om(){if(Wr)return hn;Wr=1;const t=Et();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 c=this.data.length-a;c>0&&(i=this.data.substr(a),l=parseInt(i,10),r.put(l,c*3+1))},hn=s,hn}var fn,Qr;function im(){if(Qr)return fn;Qr=1;const t=Et(),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)},fn=n,fn}var xn,Yr;function lm(){if(Yr)return xn;Yr=1;const t=Et();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)},xn=s,xn}var pn,Jr;function cm(){if(Jr)return pn;Jr=1;const t=Et(),s=Tt();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]+`
161
+ Make sure your charset is UTF-8`);i=(i>>>8&255)*192+(i&255),r.put(i,13)}},pn=n,pn}var gn={exports:{}},Zr;function dm(){return Zr||(Zr=1,(function(t){var s={single_source_shortest_paths:function(n,r,a){var i={},l={};l[r]=0;var c=s.PriorityQueue.make();c.push(r,0);for(var d,m,p,u,h,x,k,j,A;!c.empty();){d=c.pop(),m=d.value,u=d.cost,h=n[m]||{};for(p in h)h.hasOwnProperty(p)&&(x=h[p],k=u+x,j=l[p],A=typeof l[p]>"u",(A||j>k)&&(l[p]=k,c.push(p,k),i[p]=m))}if(typeof a<"u"&&typeof l[a]>"u"){var f=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(f)}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})(gn)),gn.exports}var Xr;function um(){return Xr||(Xr=1,(function(t){const s=Et(),n=om(),r=im(),a=lm(),i=cm(),l=Eo(),c=Tt(),d=dm();function m(f){return unescape(encodeURIComponent(f)).length}function p(f,E,y){const v=[];let b;for(;(b=f.exec(y))!==null;)v.push({data:b[0],index:b.index,mode:E,length:b[0].length});return v}function u(f){const E=p(l.NUMERIC,s.NUMERIC,f),y=p(l.ALPHANUMERIC,s.ALPHANUMERIC,f);let v,b;return c.isKanjiModeEnabled()?(v=p(l.BYTE,s.BYTE,f),b=p(l.KANJI,s.KANJI,f)):(v=p(l.BYTE_KANJI,s.BYTE,f),b=[]),E.concat(y,v,b).sort(function(T,P){return T.index-P.index}).map(function(T){return{data:T.data,mode:T.mode,length:T.length}})}function h(f,E){switch(E){case s.NUMERIC:return n.getBitsLength(f);case s.ALPHANUMERIC:return r.getBitsLength(f);case s.KANJI:return i.getBitsLength(f);case s.BYTE:return a.getBitsLength(f)}}function x(f){return f.reduce(function(E,y){const v=E.length-1>=0?E[E.length-1]:null;return v&&v.mode===y.mode?(E[E.length-1].data+=y.data,E):(E.push(y),E)},[])}function k(f){const E=[];for(let y=0;y<f.length;y++){const v=f[y];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 j(f,E){const y={},v={start:{}};let b=["start"];for(let C=0;C<f.length;C++){const T=f[C],P=[];for(let S=0;S<T.length;S++){const I=T[S],_=""+C+S;P.push(_),y[_]={node:I,lastCount:0},v[_]={};for(let D=0;D<b.length;D++){const R=b[D];y[R]&&y[R].node.mode===I.mode?(v[R][_]=h(y[R].lastCount+I.length,I.mode)-h(y[R].lastCount,I.mode),y[R].lastCount+=I.length):(y[R]&&(y[R].lastCount=I.length),v[R][_]=h(I.length,I.mode)+4+s.getCharCountIndicator(I.mode,E))}}b=P}for(let C=0;C<b.length;C++)v[b[C]].end=0;return{map:v,table:y}}function A(f,E){let y;const v=s.getBestModeForData(f);if(y=s.from(E,v),y!==s.BYTE&&y.bit<v.bit)throw new Error('"'+f+'" cannot be encoded with mode '+s.toString(y)+`.
162
+ Suggested mode is: `+s.toString(v));switch(y===s.KANJI&&!c.isKanjiModeEnabled()&&(y=s.BYTE),y){case s.NUMERIC:return new n(f);case s.ALPHANUMERIC:return new r(f);case s.KANJI:return new i(f);case s.BYTE:return new a(f)}}t.fromArray=function(E){return E.reduce(function(y,v){return typeof v=="string"?y.push(A(v,null)):v.data&&y.push(A(v.data,v.mode)),y},[])},t.fromString=function(E,y){const v=u(E,c.isKanjiModeEnabled()),b=k(v),C=j(b,y),T=d.find_path(C.map,"start","end"),P=[];for(let S=1;S<T.length-1;S++)P.push(C.table[T[S]].node);return t.fromArray(x(P))},t.rawSplit=function(E){return t.fromArray(u(E,c.isKanjiModeEnabled()))}})(mn)),mn}var ea;function mm(){if(ea)return Zs;ea=1;const t=Tt(),s=Gn(),n=Yu(),r=Ju(),a=Zu(),i=Xu(),l=em(),c=Co(),d=nm(),m=rm(),p=am(),u=Et(),h=um();function x(C,T){const P=C.size,S=i.getPositions(T);for(let I=0;I<S.length;I++){const _=S[I][0],D=S[I][1];for(let R=-1;R<=7;R++)if(!(_+R<=-1||P<=_+R))for(let F=-1;F<=7;F++)D+F<=-1||P<=D+F||(R>=0&&R<=6&&(F===0||F===6)||F>=0&&F<=6&&(R===0||R===6)||R>=2&&R<=4&&F>=2&&F<=4?C.set(_+R,D+F,!0,!0):C.set(_+R,D+F,!1,!0))}}function k(C){const T=C.size;for(let P=8;P<T-8;P++){const S=P%2===0;C.set(P,6,S,!0),C.set(6,P,S,!0)}}function j(C,T){const P=a.getPositions(T);for(let S=0;S<P.length;S++){const I=P[S][0],_=P[S][1];for(let D=-2;D<=2;D++)for(let R=-2;R<=2;R++)D===-2||D===2||R===-2||R===2||D===0&&R===0?C.set(I+D,_+R,!0,!0):C.set(I+D,_+R,!1,!0)}}function A(C,T){const P=C.size,S=m.getEncodedBits(T);let I,_,D;for(let R=0;R<18;R++)I=Math.floor(R/3),_=R%3+P-8-3,D=(S>>R&1)===1,C.set(I,_,D,!0),C.set(_,I,D,!0)}function f(C,T,P){const S=C.size,I=p.getEncodedBits(T,P);let _,D;for(_=0;_<15;_++)D=(I>>_&1)===1,_<6?C.set(_,8,D,!0):_<8?C.set(_+1,8,D,!0):C.set(S-15+_,8,D,!0),_<8?C.set(8,S-_-1,D,!0):_<9?C.set(8,15-_-1+1,D,!0):C.set(8,15-_-1,D,!0);C.set(S-8,8,1,!0)}function E(C,T){const P=C.size;let S=-1,I=P-1,_=7,D=0;for(let R=P-1;R>0;R-=2)for(R===6&&R--;;){for(let F=0;F<2;F++)if(!C.isReserved(I,R-F)){let Q=!1;D<T.length&&(Q=(T[D]>>>_&1)===1),C.set(I,R-F,Q),_--,_===-1&&(D++,_=7)}if(I+=S,I<0||P<=I){I-=S,S=-S;break}}}function y(C,T,P){const S=new n;P.forEach(function(F){S.put(F.mode.bit,4),S.put(F.getLength(),u.getCharCountIndicator(F.mode,C)),F.write(S)});const I=t.getSymbolTotalCodewords(C),_=c.getTotalCodewordsCount(C,T),D=(I-_)*8;for(S.getLengthInBits()+4<=D&&S.put(0,4);S.getLengthInBits()%8!==0;)S.putBit(0);const R=(D-S.getLengthInBits())/8;for(let F=0;F<R;F++)S.put(F%2?17:236,8);return v(S,C,T)}function v(C,T,P){const S=t.getSymbolTotalCodewords(T),I=c.getTotalCodewordsCount(T,P),_=S-I,D=c.getBlocksCount(T,P),R=S%D,F=D-R,Q=Math.floor(S/D),Y=Math.floor(_/D),X=Y+1,Z=Q-Y,te=new d(Z);let V=0;const O=new Array(D),g=new Array(D);let $=0;const N=new Uint8Array(C.buffer);for(let oe=0;oe<D;oe++){const ie=oe<F?Y:X;O[oe]=N.slice(V,V+ie),g[oe]=te.encode(O[oe]),V+=ie,$=Math.max($,ie)}const q=new Uint8Array(S);let z=0,W,L;for(W=0;W<$;W++)for(L=0;L<D;L++)W<O[L].length&&(q[z++]=O[L][W]);for(W=0;W<Z;W++)for(L=0;L<D;L++)q[z++]=g[L][W];return q}function b(C,T,P,S){let I;if(Array.isArray(C))I=h.fromArray(C);else if(typeof C=="string"){let Q=T;if(!Q){const Y=h.rawSplit(C);Q=m.getBestVersionForData(Y,P)}I=h.fromString(C,Q||40)}else throw new Error("Invalid data");const _=m.getBestVersionForData(I,P);if(!_)throw new Error("The amount of data is too big to be stored in a QR Code");if(!T)T=_;else if(T<_)throw new Error(`
163
+ The chosen QR Code version cannot contain this amount of data.
164
+ Minimum version required to store current data is: `+_+`.
165
+ `);const D=y(T,P,I),R=t.getSymbolSize(T),F=new r(R);return x(F,T),k(F),j(F,T),f(F,P,0),T>=7&&A(F,T),E(F,D),isNaN(S)&&(S=l.getBestMask(F,f.bind(null,F,P))),l.applyMask(S,F),f(F,P,S),{modules:F,version:T,errorCorrectionLevel:P,maskPattern:S,segments:I}}return Zs.create=function(T,P){if(typeof T>"u"||T==="")throw new Error("No input text");let S=s.M,I,_;return typeof P<"u"&&(S=s.from(P.errorCorrectionLevel,s.M),I=m.from(P.version),_=l.from(P.maskPattern),P.toSJISFunc&&t.setToSJISFunction(P.toSJISFunc)),b(T,I,S,_)},Zs}var bn={},vn={},ta;function Ao(){return ta||(ta=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,c=a.modules.data,d=t.getScale(l,i),m=Math.floor((l+i.margin*2)*d),p=i.margin*d,u=[i.color.light,i.color.dark];for(let h=0;h<m;h++)for(let x=0;x<m;x++){let k=(h*m+x)*4,j=i.color.light;if(h>=p&&x>=p&&h<m-p&&x<m-p){const A=Math.floor((h-p)/d),f=Math.floor((x-p)/d);j=u[c[A*l+f]?1:0]}r[k++]=j.r,r[k++]=j.g,r[k++]=j.b,r[k]=j.a}}})(vn)),vn}var sa;function hm(){return sa||(sa=1,(function(t){const s=Ao();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,c){let d=c,m=l;typeof d>"u"&&(!l||!l.getContext)&&(d=l,l=void 0),l||(m=r()),d=s.getOptions(d);const p=s.getImageWidth(i.modules.size,d),u=m.getContext("2d"),h=u.createImageData(p,p);return s.qrToImageData(h.data,i,d),n(u,m,p),u.putImageData(h,0,0),m},t.renderToDataURL=function(i,l,c){let d=c;typeof d>"u"&&(!l||!l.getContext)&&(d=l,l=void 0),d||(d={});const m=t.render(i,l,d),p=d.type||"image/png",u=d.rendererOpts||{};return m.toDataURL(p,u.quality)}})(bn)),bn}var wn={},na;function fm(){if(na)return wn;na=1;const t=Ao();function s(a,i){const l=a.a/255,c=i+'="'+a.hex+'"';return l<1?c+" "+i+'-opacity="'+l.toFixed(2).slice(1)+'"':c}function n(a,i,l){let c=a+i;return typeof l<"u"&&(c+=" "+l),c}function r(a,i,l){let c="",d=0,m=!1,p=0;for(let u=0;u<a.length;u++){const h=Math.floor(u%i),x=Math.floor(u/i);!h&&!m&&(m=!0),a[u]?(p++,u>0&&h>0&&a[u-1]||(c+=m?n("M",h+l,.5+x+l):n("m",d,0),d=0,m=!1),h+1<i&&a[u+1]||(c+=n("h",p),p=0)):d++}return c}return wn.render=function(i,l,c){const d=t.getOptions(l),m=i.modules.size,p=i.modules.data,u=m+d.margin*2,h=d.color.light.a?"<path "+s(d.color.light,"fill")+' d="M0 0h'+u+"v"+u+'H0z"/>':"",x="<path "+s(d.color.dark,"stroke")+' d="'+r(p,m,d.margin)+'"/>',k='viewBox="0 0 '+u+" "+u+'"',A='<svg xmlns="http://www.w3.org/2000/svg" '+(d.width?'width="'+d.width+'" height="'+d.width+'" ':"")+k+' shape-rendering="crispEdges">'+h+x+`</svg>
166
+ `;return typeof c=="function"&&c(null,A),A},wn}var ra;function xm(){if(ra)return Mt;ra=1;const t=Qu(),s=mm(),n=hm(),r=fm();function a(i,l,c,d,m){const p=[].slice.call(arguments,1),u=p.length,h=typeof p[u-1]=="function";if(!h&&!t())throw new Error("Callback required as last argument");if(h){if(u<2)throw new Error("Too few arguments provided");u===2?(m=c,c=l,l=d=void 0):u===3&&(l.getContext&&typeof m>"u"?(m=d,d=void 0):(m=d,d=c,c=l,l=void 0))}else{if(u<1)throw new Error("Too few arguments provided");return u===1?(c=l,l=d=void 0):u===2&&!l.getContext&&(d=c,c=l,l=void 0),new Promise(function(x,k){try{const j=s.create(c,d);x(i(j,l,d))}catch(j){k(j)}})}try{const x=s.create(c,d);m(null,i(x,l,d))}catch(x){m(x)}}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,c){return r.render(i,c)}),Mt}var pm=xm();function gm(t){return Zi(t)}function bm(t){return pm.toDataURL(t,{errorCorrectionLevel:"M",margin:2,scale:8,color:{dark:"#111827ff",light:"#ffffffff"}})}function Do({title:t,description:s,triggerLabel:n,qrValue:r,displayValue:a,hint:i,imageAlt:l,copyLabel:c,copiedMessage:d}){const[m,p]=o.useState(!1),[u,h]=o.useState(null),[x,k]=o.useState(null);return o.useEffect(()=>{if(!m)return;let j=!1;return h(null),k(null),bm(r).then(A=>{j||h(A)}).catch(()=>{j||k("QR code unavailable")}),()=>{j=!0}},[m,r]),e.jsxs(St,{open:m,onOpenChange:p,children:[e.jsx(Xi,{asChild:!0,children:e.jsx(J,{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(sd,{className:"h-3 w-3"})})}),e.jsxs(Ct,{className:"max-w-[20rem] gap-2 p-3",children:[e.jsxs(As,{className:"space-y-1 text-left",children:[e.jsx(Bt,{className:"text-[12px]",children:t}),e.jsx(Ds,{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:u?e.jsx("img",{src:u,alt:l,className:"h-full w-full"}):x?e.jsx("span",{children:x}):e.jsx(de,{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(J,{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:()=>{Es(a,d)},children:c})]})]})]})}function vm({nodeName:t,nodeEndpoint:s}){const n=o.useMemo(()=>gm({nodeName:t,nodeEndpoint:s}),[s,t]),r=`Show ${t} Node QR code`;return e.jsx(Do,{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 wm({nodeName:t,dashboardUrl:s}){const n=`Show ${t} dashboard QR code`;return e.jsx(Do,{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 Wn({nodeId:t,nodeName:s,onOpenSettings:n,onOpenServicePreview:r,onOpenCapabilities:a,onOpenDevBox:i,onStartDevBox:l,onToggleRemoteAccess:c,remoteAccessLabel:d,remoteAccessPending:m,remoteAccessDisabled:p,remoteAccessDisabledReason:u,showConfigureDevBox:h,showStartDevBox:x,startDevBoxPending:k,className:j}){const[A,f]=o.useState(!1),[E,y]=o.useState(null),v=o.useRef(null),b=o.useRef(null),C=k?"Starting":"Start DevBox",T=d?.startsWith("Disable")?el:fd;o.useLayoutEffect(()=>{if(!A){y(null);return}const S=()=>{const I=b.current,_=v.current;if(!I||!_)return;const D=I.getBoundingClientRect(),R=_.getBoundingClientRect();y(jm({left:D.left,right:D.right,bottom:D.bottom,top:D.top},{width:R.width,height:R.height},{width:window.innerWidth,height:window.innerHeight},Nm()))};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=_=>{const D=_.target;D instanceof Node&&!v.current?.contains(D)&&!b.current?.contains(D)&&f(!1)},I=_=>{_.key==="Escape"&&f(!1)};return document.addEventListener("mousedown",S),document.addEventListener("keydown",I),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("keydown",I)}},[A]);const P=A?e.jsxs("div",{ref:v,"data-node-action-menu-portal":"true",role:"menu",style:ym(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(),f(!1),n(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(tl,{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(),f(!1),r(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(no,{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(),f(!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(_s,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Capabilities"})]}),d&&c&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${d} for ${s}`,title:u??`${d} for ${s}`,onClick:S=>{S.stopPropagation(),!(m||p)&&(f(!1),c())},disabled:m||p,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(de,{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:d})]}),x&&l&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${C} for ${s}`,title:`${C} for ${s}`,onClick:S=>{S.stopPropagation(),!k&&(f(!1),l(t))},disabled:k,className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80 disabled:cursor-not-allowed disabled:opacity-60",children:[k?e.jsx(de,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(Ms,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:C})]}),h&&i&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${s}`,title:`Configure DevBox for ${s}`,onClick:S=>{S.stopPropagation(),f(!1),i(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(sl,{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:B("relative shrink-0",A&&"z-[120]",j),onClick:S=>S.stopPropagation(),onPointerDown:S=>S.stopPropagation(),children:[e.jsx(J,{ref:b,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(),f(I=>(I||y(null),!I))},className:B("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(Lc,{className:"h-3.5 w-3.5"})}),P&&(typeof document>"u"?P:Fa.createPortal(P,document.body))]})}function ym(t){return t?{left:t.left,top:t.top}:{left:0,top:0,visibility:"hidden"}}function jm(t,s,n,r=1){const l=s.width||160,c=s.height||0,d=Number.isFinite(r)&&r>0?r:1,m=Math.max(8,Math.min(t.right-l,n.width-l-8)),p=t.bottom+4,u=(t.top??t.bottom)-c-4,h=p+c>n.height-8&&u>=8?u:p;return{left:Math.round(m/d),top:Math.round(h/d)}}function Nm(){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 km=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),Sm=new Set(["startinprogress","starting"]);function It(t){return!!(t?.enabled&&t.name)}function Cm(t){const s=t?.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&km.has(s))}function Rt(t){const s=t?.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&Sm.has(s))}function Rs(t,s,n){return t==="offline"&&Cm(s)&&It(n)}function aa(t,s){return t==="offline"&&It(s)}function oa(t){return!It(t)}function Tm({nodeStatus:t,status:s,current:n,selected:r}){const a=r??n;return a&&Rs(t,s,a)?a:null}function Ue(t){return t.scope||`name:${t.name??""}`}function Em({previousKey:t,baseDevBox:s,listed:n}){if(t&&n.some(i=>Ue(i)===t))return t;if(!It(s))return n[0]?Ue(n[0]):"";const r=Ue(s),a=n.find(i=>Ue(i)===r)??n.find(i=>i.name===s.name);return a?Ue(a):r}function Am(t){return t==="nodes"||t==="events"?t:"overview"}function Dm({cluster:t,systemInfo:s,nodeNameById:n,nodeBlockingTaskCounts:r,eventTypeFilter:a,onEventTypeFilterChange:i,eventTypeOptions:l,filteredEvents:c,sseConnected:d,clusterLoading:m,clusterError:p,promotePending:u,onPromote:h,onAddNode:x,leavePending:k,onLeaveCluster:j,onToggleNodeDevTunnel:A,devTunnelNodeId:f,devBoxStartNodeId:E,devBoxStartingNodeIds:y=new Set,activeTab:v,onTabChange:b,onOpenNodeSettings:C,onOpenNodeCapabilities:T,onOpenDevBox:P,onStartDevBox:S}){const I=t?.self?.role==="leader",_=t?.self?.role==="follower"&&!t?.leader,D=t?.self??null,F=nl(t?.nodes??[],D?.id).filter(q=>q.id!==D?.id),Q=t?.leader?t.nodes.find(q=>q.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,Z=t?.leader?.name??Q?.name??"Leader",te=D?.role==="leader"&&F.length===0,V=D?.role==="follower",[O,g]=o.useState("overview"),$=v??O;function N(q){const z=Am(q);g(z),b?.(z)}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(Fn,{value:$,onValueChange:N,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(On,{className:"grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(Nt,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(Nt,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(Nt,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})}),e.jsx(ft,{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:[D&&e.jsx(ia,{node:D,systemInfo:s,blockingTaskCount:r.get(D.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:A,showActions:!1,defaultExpanded:!1,onOpenDevBox:P,devBoxStartingNodeIds:y}),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(Ve,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:d?"Connected":"Reconnecting"})]}),m&&!t?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(de,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):p&&!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:p}):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(tt,{label:"Leader",value:t?.leader?.name??"None"}),e.jsx(tt,{label:"Leader Dashboard URL",value:Y??"Unavailable",mono:!0,action:Y?e.jsx(Yn,{nodeName:Z,dashboardUrl:Y,copyLabel:"Copy leader dashboard URL",copiedMessage:"Leader Dashboard URL copied"}):void 0}),X&&e.jsx(tt,{label:"Leader Node URL",value:X,mono:!0,action:e.jsx(Qn,{nodeName:Z,nodeEndpoint:X,copyLabel:"Copy leader node URL",copiedMessage:"Leader Node URL copied"})}),e.jsx(tt,{label:"Feed",value:d?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:_&&e.jsxs(J,{variant:"secondary",size:"sm",onClick:h,disabled:u,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[u&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(ft,{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"}),te?e.jsxs(J,{variant:"secondary",size:"sm",onClick:x,className:"h-6 border-0 bg-primary px-2 text-[10px] text-primary-foreground shadow-none hover:bg-primary/90",children:[e.jsx(md,{className:"h-3 w-3"}),"Join node"]}):V?e.jsxs(J,{variant:"secondary",size:"sm",onClick:j,disabled:k,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[k&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),D&&e.jsx(ia,{node:D,systemInfo:s,blockingTaskCount:r.get(D.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:A,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:I?C:void 0,onOpenNodeCapabilities:I?T:void 0,onOpenDevBox:I?P:void 0,onStartDevBox:I?S:void 0,devBoxStartNodeId:E,devBoxStartingNodeIds:y})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",F.length,")"]}),F.length>0?e.jsx("div",{className:"space-y-1.5",children:F.map(q=>e.jsx(_m,{node:q,isLeader:!!I,blockingTaskCount:r.get(q.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:A,onOpenNodeSettings:I?C:void 0,onOpenNodeCapabilities:I?T:void 0,onOpenDevBox:I?P:void 0,onStartDevBox:I?S:void 0,devBoxStartNodeId:E,devBoxStartingNodeIds:y},q.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(ft,{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(rl,{className:B("h-3.5 w-3.5",d?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(_e,{value:a,onValueChange:i,children:[e.jsx(Me,{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($e,{placeholder:"Event type"})}),e.jsx(Pe,{className:"shadow-none",children:l.map(q=>e.jsx(De,{value:q,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:q==="all"?"All event types":q},q))})]}),e.jsx(Ve,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:d?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(al,{events:c,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 ia({node:t,systemInfo:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:a,showActions:i=!0,defaultExpanded:l=!1,onOpenNodeSettings:c,onOpenNodeCapabilities:d,onOpenDevBox:m,onStartDevBox:p,devBoxStartNodeId:u,devBoxStartingNodeIds:h}){const[x,k]=o.useState(l),j=s?.dashboardOrigin??t.dashboardOrigin,A=t.devtunnelEndpoint??t.endpoint,f=j??t.endpoint,E=s?.workDir??t.workDir,y=io(t,s?.transportType),v=Hn(t,s?.transportType),b=v&&Ft(s?.transportType??t.transportType)?!0:oo(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:()=>k(T=>!T),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[x?e.jsx(Je,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(st,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(za,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Current node"})]}),e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Un,{className:"h-3 w-3"})}),(c||d||i&&b)&&e.jsx(Wn,{nodeId:t.id,nodeName:t.name,onOpenSettings:c,onOpenCapabilities:d,onOpenDevBox:m,onStartDevBox:p,onToggleRemoteAccess:i&&b?()=>a(t):void 0,remoteAccessLabel:i&&b?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:Rs(t.status,t.devbox?.lastStatus,t.devbox)||Rt(t.devbox?.lastStatus)||h.has(t.id),startDevBoxPending:u===t.id||Rt(t.devbox?.lastStatus)||h.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>k(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(Ua,{role:t.role,size:"compact"}),e.jsx(Ve,{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})]})]}),x&&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(tt,{label:"Node ID",value:t.id,mono:!0}),j&&e.jsx(tt,{label:"Dashboard",value:j,mono:!0,action:e.jsx(Yn,{nodeName:t.name,dashboardUrl:j})}),e.jsx(tt,{label:"Node URL",value:A,mono:!0,action:e.jsx(Qn,{nodeName:t.name,nodeEndpoint:A})}),E&&e.jsx(tt,{label:"Workspace",value:E,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(En,{label:"Transport",value:y}),s&&e.jsx(En,{label:"Uptime",value:ol(s.uptime),mono:!0})]}),i&&d&&e.jsxs(J,{variant:"secondary",size:"sm",onClick:()=>d(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(_s,{className:"h-3 w-3"}),"Capabilities"]}),i&&b&&C&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function _m({node:t,isLeader:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:a,onOpenNodeSettings:i,onOpenNodeCapabilities:l,onOpenDevBox:c,onStartDevBox:d,devBoxStartNodeId:m,devBoxStartingNodeIds:p}){const[u,h]=o.useState(!1),x=t.dashboardOrigin,k=t.devtunnelEndpoint??t.endpoint,j=x??t.endpoint,A=io(t),f=Hn(t),E=oo(t),y=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:()=>h(v=>!v),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[u?e.jsx(Je,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(st,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(za,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Peer node"})]}),e.jsx("a",{href:j,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Un,{className:"h-3 w-3"})}),s&&(i||l||E)&&e.jsx(Wn,{nodeId:t.id,nodeName:t.name,onOpenSettings:i,onOpenCapabilities:l,onOpenDevBox:c,onStartDevBox:d,onToggleRemoteAccess:E?()=>a(t):void 0,remoteAccessLabel:E?f?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:y,remoteAccessDisabledReason:y?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:t.devbox?.enabled,showStartDevBox:Rs(t.status,t.devbox?.lastStatus,t.devbox)||Rt(t.devbox?.lastStatus)||p.has(t.id),startDevBoxPending:m===t.id||Rt(t.devbox?.lastStatus)||p.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>h(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(Ua,{role:t.role,size:"compact"}),e.jsx(Ve,{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})]})]}),u&&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(tt,{label:"Node ID",value:t.id,mono:!0}),x&&e.jsx(tt,{label:"Dashboard",value:x,mono:!0,action:e.jsx(Yn,{nodeName:t.name,dashboardUrl:x})}),e.jsx(tt,{label:"Node URL",value:k,mono:!0,action:e.jsx(Qn,{nodeName:t.name,nodeEndpoint:k})}),t.workDir&&e.jsx(tt,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(En,{label:"Transport",value:A})]}),s&&l&&e.jsxs(J,{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(_s,{className:"h-3 w-3"}),"Capabilities"]}),s&&E&&y&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Qn({nodeName:t,nodeEndpoint:s,copyLabel:n="Copy node URL",copiedMessage:r="Node URL copied"}){return e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(vm,{nodeName:t,nodeEndpoint:s}),e.jsx(_o,{label:n,onClick:()=>{Es(s,r)}})]})}function Yn({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(wm,{nodeName:t,dashboardUrl:s}),e.jsx(_o,{label:n,onClick:()=>{Es(s,r)}})]})}function _o({label:t,onClick:s}){return e.jsx(J,{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(La,{className:"h-3 w-3"})})}function Mm(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(c=>c.id===t.assignedTo):void 0;return t.assignedTo!==null&&(i?i.status==="offline":s?t.assignedNodeAvailable===!1||!s.nodes.some(c=>c.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 Mo=.5,Po=1.75,la=.1;function Pm({node:t,open:s,onOpenChange:n}){const[r,a]=o.useState(fs),[i,l]=o.useState(null),[c,d]=o.useState(1),[m,p]=o.useState(!1),[u,h]=o.useState(null);o.useEffect(()=>{a(fs),l(null),d(1),p(!1),h(null)},[t?.id,s]);const x=o.useCallback(async y=>{if(!t)return;const v=y??Number.parseInt(r.trim()||fs,10);if(!Number.isInteger(v)||v<1||v>65535){h("Enter a port between 1 and 65535");return}p(!0),h(null);try{const b=await il(t.id,{port:v});l(b),a(String(v)),ir("preview.created",{result:"success",previewType:"service-port"})}catch(b){h(b instanceof Error?b.message:"Failed to create service preview"),ir("preview.failed",{result:"failed",previewType:"service-port"})}finally{p(!1)}},[t,r]),k=o.useCallback(()=>{typeof i?.port=="number"&&x(i.port)},[i?.port,x]);o.useEffect(()=>{if(!i)return;const y=i.expiresAt-Date.now()-5e3;if(y<=0){k();return}const v=window.setTimeout(k,y);return()=>window.clearTimeout(v)},[k,i]);const j=i?kc(i):null,A=t?.name??"Node",f=Im(c),E={width:`${100/c}%`,height:`${100/c}%`,transform:`scale(${c})`,transformOrigin:"top left"};return e.jsx(St,{open:s,onOpenChange:n,children:e.jsxs(Ct,{onOpenAutoFocus:y=>y.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(Bt,{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold text-foreground",children:[e.jsx(no,{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(Ds,{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:y=>{y.preventDefault(),x()},children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:["Port",e.jsx(ot,{type:"text",min:1,max:65535,inputMode:"numeric",value:r,onChange:y=>a(y.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(J,{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(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ms,{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:Rm(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(J,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>d(y=>ca(y,-la)),disabled:c<=Mo,title:"Zoom out","aria-label":"Zoom out preview",children:e.jsx(bd,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>d(1),className:"h-6 min-w-11 border-x border-border/45 px-1.5 text-center font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted/55 hover:text-foreground",title:"Reset zoom","aria-label":"Reset preview zoom",children:f}),e.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>d(y=>ca(y,la)),disabled:c>=Po,title:"Zoom in","aria-label":"Zoom in preview",children:e.jsx(pd,{className:"h-3.5 w-3.5"})})]}),e.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:k,title:"Refresh",children:e.jsx(ll,{className:"h-3.5 w-3.5"})}),e.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",asChild:!0,title:"Open in new tab",children:e.jsx("a",{href:j??i.previewUrl,target:"_blank",rel:"noopener noreferrer",children:e.jsx(Un,{className:"h-3.5 w-3.5"})})})]})]})]}),u&&e.jsx("div",{className:"shrink-0 border-b border-destructive/20 bg-destructive/5 px-3 py-1.5 text-[11px] text-destructive",children:u}),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:Cc(i),style:E,className:"h-full w-full border-0",sandbox:Sc(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 ca(t,s){return Io(Math.round((t+s)*100)/100)}function Io(t){return Number.isFinite(t)?Math.min(Po,Math.max(Mo,t)):1}function Im(t){return`${Math.round(Io(t)*100)}%`}function Rm(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 Lm({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(st,{className:B("h-3 w-3 shrink-0 transition-transform duration-200",!r&&"rotate-90")}),e.jsx(Lt,{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(_s,{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(Is,{className:"h-2.5 w-2.5"})})]})}const Ro="meshy-task-sidebar-tree-state";function da(t){return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function yn(){try{return globalThis.window?.localStorage??globalThis.localStorage??null}catch{return null}}function ua(t){if(!t)return{collapsedNodes:[],collapsedDirs:[]};try{const s=t.getItem(Ro);if(!s)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(s);return{collapsedNodes:da(n.collapsedNodes),collapsedDirs:da(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Bm(t,s){if(t)try{t.setItem(Ro,JSON.stringify(s))}catch{}}function ma(t,s){if(!t.has(s))return t;const n=new Set(t);return n.delete(s),n}function Om(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 ha(t,s,n){return n?{collapsedNodes:ma(t,n.nodeKey),collapsedDirs:ma(s,n.dirKey)}:{collapsedNodes:t,collapsedDirs:s}}function Fm(t,s,n){const r=t.filter(c=>c.status==="completed"),a=new Set((s?r:[...r].sort((c,d)=>d.updatedAt-c.updatedAt).slice(0,$n)).map(c=>c.id));n&&r.some(c=>c.id===n)&&a.add(n);const i=t.filter(c=>c.status!=="completed"||a.has(c.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 fa({toolbarTasks:t,activeTaskId:s,tasksLoading:n,tasksError:r,isLeader:a,scope:i,agentFilter:l,nodeFilter:c,taskKindFilter:d,agentOptions:m,nodeOptions:p,nodeNameById:u,nodeWorkDirById:h,nodeStatusById:x,completedGroupByKey:k,devBoxNodeIds:j=new Set,devBoxStartNodeIds:A=new Set,devBoxStartingNodeIds:f=new Set,leaderNodeId:E,searchQuery:y,selectedTaskIds:v,allVisibleTasksSelected:b,someVisibleTasksSelected:C,canBatchArchive:T,onScopeChange:P,onAgentFilterChange:S,onNodeFilterChange:I,onTaskKindFilterChange:_,onToggleTaskSelected:D,onToggleAllVisibleTasks:R,onBatchArchive:F,onBatchDelete:Q,onCreateTask:Y,onOpenNodeSettings:X,onOpenNodeCapabilities:Z,onOpenProjectCapabilities:te,onOpenDevBox:V,onStartDevBox:O,onLoadCompletedTasks:g,onSelectTask:$}){const[N,q]=o.useState(!1),[z,W]=o.useState(()=>v.size>0),[L,oe]=o.useState(!1),[ie,he]=o.useState(null),{markScrollbarActive:ae,scrollbarActive:G}=jo(),M=v.size,ne=!!(a&&(z||M>0)),H=i!=="active"||c!=="all"||l!=="all"||d!=="all",re=y.trim().length>0,[we,fe]=o.useState(()=>new Set(ua(yn()).collapsedNodes)),[Ie,Ee]=o.useState(()=>new Set(ua(yn()).collapsedDirs)),[xt,Le]=o.useState(new Set),Ze=o.useMemo(()=>cl({nodeStatusById:x,nodeNameById:u,nodeWorkDirById:h,nodeFilter:c,searchQuery:y}),[x,u,h,c,y]),Se=o.useMemo(()=>dl(t,u,E,h,Ze),[t,u,E,h,Ze]),He=o.useMemo(()=>Om(Se,s),[Se,s]),We=o.useRef(null),Ke=Se.length===1,Oe=Se.length>0,lt=Ke&&(H||re),ct=!!(a&&(t.length>0||M>0)),ee=o.useCallback(K=>{fe(ke=>{const Ae=new Set(ke);return Ae.has(K)?Ae.delete(K):Ae.add(K),Ae})},[]),ge=o.useCallback(K=>{Ee(ke=>{const Ae=new Set(ke);return Ae.has(K)?Ae.delete(K):Ae.add(K),Ae})},[]),ye=o.useCallback(K=>{Le(ke=>{const Ae=new Set(ke);return Ae.add(K),Ae})},[]);o.useEffect(()=>{Bm(yn(),{collapsedNodes:Array.from(we),collapsedDirs:Array.from(Ie)})},[Ie,we]),o.useEffect(()=>{if(!He||!s)return;const K=`${s}:${He.nodeKey}:${He.dirKey}`;We.current!==K&&(We.current=K,fe(ke=>ha(ke,new Set,He).collapsedNodes),Ee(ke=>ha(new Set,ke,He).collapsedDirs))},[s,He]);const Fe=o.useCallback(K=>{W(!0),R(K)},[R]),ze=o.useCallback(K=>{if(K===!0&&!b){W(!0),oe(!0);return}Fe(K===!0)},[b,Fe]),Ne=o.useCallback(()=>{Fe(!0),oe(!1)},[Fe]),je=o.useCallback(()=>{R(!1),W(!1),oe(!1)},[R]);o.useEffect(()=>{a||(W(!1),oe(!1))},[a]);const pt=ne?e.jsxs(Yt,{open:L,onOpenChange:oe,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&&!b?"indeterminate":b,onCheckedChange:ze,"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:Ne,children:"Select all"})]})]})]}):e.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>W(!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(xc,{className:"h-3 w-3"}),"Multi select"]}),zt=M>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:[M," task",M!==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,Ut=M>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(Yt,{children:[e.jsx(Sn,{asChild:!0,children:e.jsxs(J,{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(Ec,{}),"Archive"]})}),e.jsxs(Jt,{children:[e.jsxs(Zt,{children:[e.jsxs(Xt,{children:["Archive ",M," selected task",M!==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:F,disabled:!T,children:"Archive"})]})]})]}),e.jsxs(Yt,{children:[e.jsx(Sn,{asChild:!0,children:e.jsxs(J,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(qa,{}),"Delete"]})}),e.jsxs(Jt,{children:[e.jsxs(Zt,{children:[e.jsxs(Xt,{children:["Delete ",M," selected task",M!==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(J,{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(Is,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsxs(J,{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(Vn,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Load session"]})]}),e.jsx(J,{variant:"ghost",size:"icon",onClick:()=>q(K=>!K),className:B("ml-auto h-8 w-8 shrink-0 rounded-sm text-muted-foreground shadow-none hover:bg-muted/55 hover:text-foreground",(N||H)&&"bg-primary/8 text-primary hover:bg-primary/12 hover:text-primary"),title:"Filters",children:e.jsx(Uc,{className:"h-3.5 w-3.5"})})]}),(N||H)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(_e,{value:i,onValueChange:K=>P(K),children:[e.jsx(Me,{className:gs,children:e.jsx($e,{})}),e.jsx(Pe,{children:ul.map(K=>e.jsx(De,{value:K.value,className:bs,children:K.label},K.value))})]}),e.jsxs(_e,{value:c,onValueChange:I,children:[e.jsx(Me,{className:gs,children:e.jsx($e,{placeholder:"Node"})}),e.jsx(Pe,{children:p.map(K=>e.jsx(De,{value:K.value,className:bs,children:K.label},K.value))})]}),e.jsxs(_e,{value:l,onValueChange:S,children:[e.jsx(Me,{className:gs,children:e.jsx($e,{placeholder:"Agent"})}),e.jsx(Pe,{children:m.map(K=>e.jsx(De,{value:K,className:bs,children:K==="all"?"All agents":K},K))})]}),e.jsxs(_e,{value:d,onValueChange:K=>_(K),children:[e.jsx(Me,{className:gs,children:e.jsx($e,{placeholder:"Type"})}),e.jsx(Pe,{children:ml.map(K=>e.jsx(De,{value:K.value,className:bs,children:K.label},K.value))})]})]})]}),e.jsx("div",{className:B("scrollbar-line min-h-0 flex-1 overflow-y-auto pl-2.5 pr-1.5 py-2",G&&"scrollbar-line-active"),onScroll:ae,children:Se.length>0?e.jsx("div",{className:"space-y-1",children:Se.map(K=>{const ke=K.nodeId??"__unassigned__",Ae=K.dirs.reduce((Be,Qe)=>Be+Qe.tasks.length,0),wt=Oe&&!lt&&we.has(ke),$t=K.nodeId!==null&&x.get(K.nodeId)==="offline",yt=!!(a&&K.nodeId);return e.jsxs("div",{className:"space-y-1",children:[Oe&&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:()=>ee(ke),"aria-expanded":!wt,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(st,{className:B("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!wt&&"rotate-90")}),e.jsx(Ma,{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(Ve,{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(Ve,{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(Ve,{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"})]})]}),yt&&K.nodeId&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(Wn,{nodeId:K.nodeId,nodeName:K.nodeName,onOpenSettings:X,onOpenServicePreview:()=>he({id:K.nodeId,name:K.nodeName}),onOpenCapabilities:Z,onOpenDevBox:V,onStartDevBox:O,showConfigureDevBox:j.has(K.nodeId),showStartDevBox:A.has(K.nodeId)||f.has(K.nodeId),startDevBoxPending:f.has(K.nodeId)})})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-300 ease-in-out",wt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:K.dirs.map(Be=>{const Qe=`${ke}::${Be.path}`,nt=Ie.has(Qe),dt=$a(Be.path),ut=k?.get(Qe),At=ut?{visibleTasks:Be.tasks,hiddenCompletedCount:Math.max(0,ut.total-ut.returned)}:Fm(Be.tasks,xt.has(Qe),s),{visibleTasks:Re,hiddenCompletedCount:mt}=At;return e.jsxs("div",{className:B("space-y-0.5 rounded-xl",Oe&&"pl-2.5"),children:[e.jsx(Lm,{dirPath:Be.path,label:dt,taskCount:Be.tasks.length,collapsed:nt,onToggle:()=>ge(Qe),onCreateTask:()=>Y("chat",{assignTo:K.nodeId,project:Be.path==="default workspace"?"":Be.path}),onOpenCapabilities:K.nodeId&&te?()=>te(K.nodeId,Be.path==="default workspace"?h?.get(K.nodeId)??Be.path:Be.path):void 0}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-300 ease-in-out",nt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:B("overflow-hidden",Oe?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[Re.map(Ce=>{const Xe=Ce.id===s,qe=Ce.assignedTo?x.get(Ce.assignedTo):void 0,qt=!!Ce.assignedTo&&(qe?qe==="offline":Ce.assignedNodeAvailable===!1);return e.jsxs("div",{className:B("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",Xe?'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:[ne&&e.jsx("div",{className:"flex shrink-0",onClick:pe=>pe.stopPropagation(),children:e.jsx(is,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:v.has(Ce.id),onCheckedChange:pe=>D(Ce.id,pe===!0),"aria-label":`Select ${Ce.title}`})}),e.jsxs("button",{type:"button",onClick:()=>$(Ce.id),"aria-current":Xe?"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:B("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",Xe?"text-foreground":"text-foreground/80"),children:Ce.title})}),e.jsx("span",{className:B("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",Xe?"text-primary/75":"text-muted-foreground/55"),children:hl(Ce.updatedAt)}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5",children:[e.jsx("span",{className:"rounded-sm bg-muted/35 px-1 py-0 font-mono text-[8px] leading-3 text-muted-foreground/65",children:Ce.agent}),Ce.activeShare&&e.jsx(Ve,{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"}),qt&&e.jsx(Ve,{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(Ba,{status:Ce.status,isNative:Ce.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},Ce.id)}),mt>0&&e.jsxs("button",{type:"button",onClick:()=>{ut&&g?g(ut):ye(Qe)},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 ${mt} more completed tasks in ${dt}`,children:[e.jsx(Je,{className:"h-3 w-3"}),"Load ",mt," more completed"]})]})})})]},Qe)})})})]},ke)})}):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."})}),ct?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:ne&&M>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[zt,e.jsx(J,{variant:"ghost",size:"sm",onClick:je,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:pt}),Ut]})]}):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:pt}),ne&&e.jsx(J,{variant:"ghost",size:"sm",onClick:je,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]}),e.jsx(Pm,{node:ie,open:ie!==null,onOpenChange:K=>{K||he(null)}})]})}async function zm(t,s){try{const n=await fl(t,s),r={...n,url:Ra(n.url)};if(globalThis.navigator?.clipboard?.writeText)try{await globalThis.navigator.clipboard.writeText(r.url),ce.success("Shared link copied")}catch{ce.success("Shared link created")}else ce.success("Shared link created");return r}catch(n){ce.error(n instanceof Error?n.message:"Failed to create shared link");return}}async function Um(t){try{return await xl(t),ce.success("Shared link stopped"),!0}catch(s){return ce.error(s instanceof Error?s.message:"Failed to stop shared link"),!1}}function $m(t,s,n){const r=o.useCallback(()=>{s(),n()},[s,n]),a=o.useCallback(async l=>{if(!t)return;const c=await zm(t.id,l);return c&&r(),c},[t,r]),i=o.useCallback(async()=>{if(!t)return!1;const l=await Um(t.id);return l&&r(),l},[t,r]);return{handleShareTask:a,handleStopShareTask:i}}function xa(t,s,n){const r=o.useRef(s);r.current=s,o.useEffect(()=>{let l=0,c=0;const d=u=>{const h=u.touches[0];h&&(l=h.clientX,c=h.clientY)},m=u=>{const h=u.changedTouches[0];if(!h)return;const x=h.clientX-l;Math.abs(h.clientY-c)>100||Math.abs(x)<50||(x>0?r.current.onSwipeRight?.():r.current.onSwipeLeft?.())},p=t?.current??document;return p.addEventListener("touchstart",d,{passive:!0}),p.addEventListener("touchend",m,{passive:!0}),()=>{p.removeEventListener("touchstart",d),p.removeEventListener("touchend",m)}},[t,n?.threshold,n?.maxVertical])}const qm="(min-width: 1024px)",Vm="(min-width: 1800px)";function pa(t){return globalThis.window?.matchMedia?.(t)?.matches??!1}function Hm(){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 Km(){const[t,s]=o.useState(()=>pl(lr(),gl({operationsOpen:pa(Vm)}))),[n,r]=o.useState(!1),a=o.useRef(null),i=o.useRef(null),l=o.useRef(null),c=t.layout.desktopTasksOpen,d=t.layout.operationsOpen,m=t.sizes;o.useEffect(()=>{bl(lr(),t)},[t]);const p=o.useCallback((A,f)=>{s(E=>{const y=E.layout[A],v=typeof f=="function"?f(y):f;return v===y?E:{...E,layout:{...E.layout,[A]:v}}})},[]),u=o.useCallback(A=>{p("desktopTasksOpen",A)},[p]),h=o.useCallback(A=>{p("operationsOpen",A)},[p]);xa(i,{onSwipeLeft:()=>r(!1)}),xa(l,{onSwipeRight:()=>h(!1)});const x=o.useCallback(()=>{if(pa(qm)){u(A=>!A);return}r(A=>!A)},[u]);o.useEffect(()=>{const A=E=>{const y=a.current;if(!y)return;E.preventDefault();const v=wl(y.panel,y.startSize,y.startClientX,y.startClientY,E.clientX,E.clientY,y.rootFontSize);s(b=>({...b,sizes:{...b.sizes,[y.panel]:v}}))},f=()=>{a.current=null};return globalThis.window?.addEventListener("pointermove",A),globalThis.window?.addEventListener("pointerup",f),globalThis.window?.addEventListener("pointercancel",f),()=>{globalThis.window?.removeEventListener("pointermove",A),globalThis.window?.removeEventListener("pointerup",f),globalThis.window?.removeEventListener("pointercancel",f)}},[]);const k=o.useCallback((A,f)=>{f.preventDefault(),f.currentTarget.setPointerCapture?.(f.pointerId),a.current={panel:A,startSize:m[A],startClientX:f.clientX,startClientY:f.clientY,rootFontSize:Hm()}},[m]),j=o.useCallback((A,f)=>{f.preventDefault(),s(E=>({...E,sizes:{...E.sizes,[A]:vl(A,E.sizes[A],f.deltaY)}}))},[]);return{desktopTasksOpen:c,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:d,operationsPanelRef:l,panelResize:{sizes:{tasks:qs(m.tasks),operations:qs(m.operations),terminal:qs(m.terminal)},onPointerDown:k,onWheel:j},setMobileTasksPanelOpen:r,setOperationsOpen:h,toggleTasksPanel:x}}function Gm(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 Wm="notify_desktop_task";function Qm(t=Lo()){const s=t?.__TAURI__?.core?.invoke;return typeof s=="function"?s:null}async function Ym(t,s=Lo()){const n=Qm(s);return n?(await n(Wm,t),!0):!1}function Jm(t,s){const n=[];for(const r of s){const a=Zm(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 Zm(t){return t==="completed"||t==="failed"?t:null}function Lo(){return typeof window>"u"?null:window}function Xm({isLeader:t,selfId:s}){return{...!t&&s?{assignedTo:s}:{},completedLimitPerProject:$n}}function Bn(t){return`${t.assignedTo??"__unassigned__"}::${t.projectPath}`}function eh(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 th(t,s,n=new Set){return!s||n.has(s.id)||t.some(r=>r.id===s.id)?t:lo(t,s)}function sh({isLeader:t,selfId:s,sseConnected:n,preservedTask:r,subscribe:a}){const[i,l]=o.useState([]),[c,d]=o.useState([]),[m,p]=o.useState(!0),[u,h]=o.useState(null),x=o.useRef(new Set),k=o.useRef(null),j=o.useRef(null),A=o.useCallback(async()=>{try{const v=await cr(Xm({isLeader:t,selfId:s}));l(th(v.tasks,r,x.current)),d(v.completedGroups??[]),h(null)}catch(v){h(v instanceof Error?v.message:"Failed to load tasks")}finally{p(!1)}},[t,r,s]),f=o.useCallback(async v=>{if(!v.hasMore||!v.nextCursor)return;const b=await cr({status:"completed",assignedTo:v.assignedTo??"__unassigned__",projectPath:v.projectPath,cursor:v.nextCursor,limit:$n});l(C=>eh(C,b.tasks)),d(C=>C.map(T=>Bn(T)===Bn(v)?{...T,returned:Math.min(T.total,T.returned+b.tasks.length),hasMore:b.hasMore===!0,nextCursor:b.nextCursor??null}:T))},[]),E=o.useCallback(()=>{j.current===null&&(j.current=window.setTimeout(()=>{j.current=null,A()},yl))},[A]),y=o.useCallback(v=>{const b=new Set(v);if(b.size!==0){for(const C of b)x.current.add(C);l(C=>C.filter(T=>!b.has(T.id)))}},[]);return jl(A,Sl(n)),o.useEffect(()=>()=>{j.current!==null&&(window.clearTimeout(j.current),j.current=null)},[]),o.useEffect(()=>{const v=k.current;if(v)for(const b of Jm(v,i))Ym(b).catch(()=>{});k.current=new Map(i.map(b=>[b.id,b]))},[i]),o.useEffect(()=>{const v=[a("task.updated",b=>{l(C=>Gm(C,b.data))}),a("task.status",b=>{l(C=>Nl(C,b.data))}),a("node",b=>{dr(b.type)&&E()}),a("task",b=>{if(b.type==="task.deleted"){const C=b.data.taskId;typeof C=="string"&&x.current.add(C),l(T=>kl(T,b.data))}dr(b.type)&&E()})];return()=>v.forEach(b=>b())},[a,E]),{completedGroups:c,fetchTasks:A,loadCompletedTasksPage:f,removeTasksFromList:y,setTasks:l,tasks:i,tasksError:u,tasksLoading:m}}function Bo(t){return t.map(s=>({...s}))}function nh(t,s){const n=s.get(t);return{logs:n?Bo(n.logs):[],transcriptLoading:n?.loaded!==!0}}function rh(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function ah(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 oh({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=ah(r,n),i=rh(t,r);r.type==="node.joined"&&!i&&ce.success(`${a} joined the cluster`),r.type==="node.left"&&!i&&ce.message(`${a} left the cluster`)})},[t,s])}const ih=[0,300,1e3,2e3];function lh({task:t,getActiveTaskId:s,setLogs:n,setPendingMessages:r,setTranscriptLoading:a}){t.conversationKind==="nativeSession"&&(async()=>{try{for(const i of ih){if(i>0&&await new Promise(l=>setTimeout(l,i)),s()!==t.id)return;try{const l=await Cn(t.id);if(s()!==t.id||(n(c=>eo(c,l.logs)),r(c=>An(c,l.logs)),l.total>0))return}catch{}}}finally{s()===t.id&&a?.(!1)}})()}const Oo=8;function ch(t,s){return Ue(t??{})===Ue(s??{})}function dh(t){return t&&"status"in t&&typeof t.status=="string"?t.status:void 0}function ga(t,s){return{...t,enabled:!0,alwaysOnline:s}}function Fo(t){return t?.status?.trim()||t?.lastStatus?.trim()||"Unknown"}function uh({operationStarting:t,loading:s,refreshing:n,savedStatus:r,fallbackStatus:a}){return t?"Starting":s?"Listing DevBoxes":n?"Refreshing":r??a}async function mh(t,s=Va){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,Oo)}function hh(t){return t.charAt(0).toUpperCase()+t.slice(1)}function fh(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 xh(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function ba(t,s){const r=xh(t)?.[s];return typeof r=="string"&&r.trim()?r.trim():null}function ph(t){if(t.status==="failed")return t.error||"Operation failed";const s=ba(t.result,"operationId");if(s)return`MCP operation ${s}`;const n=ba(t.payload,"previousStatus");return n?`Previous DevBox status: ${n}`:t.status==="succeeded"?"Completed":"Waiting for completion"}function gh(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 va({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:Fo(t)})]})}function bh({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:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform",!r&&"-rotate-90")}),e.jsx(ks,{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(de,{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(de,{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=ph(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:fh(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:B("shrink-0 rounded-sm border px-1.5 py-0 text-[10px] leading-4",gh(i.status)),children:hh(i.status)})]},i.id)})]})]})}function vh({node:t,open:s,startInProgress:n=!1,onOpenChange:r,onRefresh:a}){const i=t?.id??null,l=s&&!n&&aa(t?.status,t?.devbox??null),[c,d]=o.useState([]),[m,p]=o.useState(()=>t?.devbox?Ue(t.devbox):""),[u,h]=o.useState(()=>t?.devbox??null),[x,k]=o.useState(()=>oa(t?.devbox??null)),[j,A]=o.useState(!1),[f,E]=o.useState(l),[y,v]=o.useState(!1),[b,C]=o.useState(!1),[T,P]=o.useState(()=>t?.devbox?.alwaysOnline===!0),[S,I]=o.useState(!1),[_,D]=o.useState([]),[R,F]=o.useState(!1),[Q,Y]=o.useState(null),X=o.useMemo(()=>{const H=c.find(re=>Ue(re)===m);return H||(It(u)&&Ue(u)===m?u:void 0)},[u,c,m]),Z=dh(X??void 0),te=x?Z??u?.lastStatus:u?.lastStatus??Z,V=t?.status==="online"||t?.status==="busy"?"Running":"Unknown",O=b||n,g=uh({operationStarting:O,loading:j,refreshing:f,savedStatus:te,fallbackStatus:V}),$=x&&!!X&&!ch(u,X),N=u?.alwaysOnline===!0!==T,q=Tm({nodeStatus:t?.status,status:g,current:u,selected:X}),z=!!q,W=!!X&&($||N)&&!z,L=X??u,oe=o.useCallback(async()=>{if(i){E(!0);try{const H=await Cl(i);h(H.devbox),p(Ue(H.devbox))}catch(H){ce.error(H instanceof Error?H.message:"Failed to refresh DevBox status")}finally{E(!1)}}},[i]),ie=o.useCallback(async H=>{A(!0);try{const re=await Tl();d(re),p(we=>Em({previousKey:we,baseDevBox:H,listed:re}))}catch(re){ce.error(re instanceof Error?re.message:"Failed to load DevBoxes")}finally{A(!1)}},[]);o.useEffect(()=>{if(!s||!i)return;let H=!1;const re=t?.devbox??null,we=oa(re),fe=!n&&aa(t?.status,re);A(!1),E(fe),k(we),h(re),P(re?.alwaysOnline===!0),I(!1),p(It(re)?Ue(re):""),d([]);async function Ie(){fe&&await oe(),!H&&we&&await ie(re)}return Ie(),()=>{H=!0}},[ie,t?.devbox,t?.status,i,s,oe,n]),o.useEffect(()=>{if(!s||!i)return;let H=!1;const re=i;async function we(){F(!0),Y(null),D([]);try{const fe=await mh(re);if(H)return;D(fe)}catch(fe){if(H)return;D([]),Y(fe instanceof Error?fe.message:"Failed to load operation history")}finally{H||F(!1)}}return we(),()=>{H=!0}},[i,s]);async function he(){k(!0),c.length===0&&await ie(u)}async function ae(){if(!(!t||!X)){v(!0);try{const H=await ur(t.id,ga(X,T));h(H.node.devbox??null),H.node.devbox&&p(Ue(H.node.devbox)),k(!1),ce.success(`Configured DevBox for ${t.name}`),await a?.()}catch(H){ce.error(H instanceof Error?H.message:"Failed to configure DevBox")}finally{v(!1)}}}async function G(){if(!(!t||!q)){C(!0);try{if(X&&($||N)){const re=await ur(t.id,ga(X,T));h(re.node.devbox??null),re.node.devbox&&p(Ue(re.node.devbox)),k(!1)}const{operation:H}=await Ha(t.id);h(re=>re&&{...re,lastStatus:"Starting",checkedAt:Date.now(),operationId:H.id}),D(re=>[H,...re.filter(we=>we.id!==H.id)].slice(0,Oo)),ce.success(`Start requested for ${t.name}`),await a?.()}catch(H){ce.error(H instanceof Error?H.message:"Failed to start DevBox")}finally{C(!1)}}}const M=j?"Loading DevBoxes...":c.length===0?"No DevBoxes available":"Select a DevBox",ne=g==="Running"&&t?.status==="offline";return e.jsx(St,{open:s,onOpenChange:r,children:e.jsxs(Ct,{className:"w-[calc(100vw-2rem)] max-w-md grid-cols-[minmax(0,1fr)] gap-3 overflow-hidden rounded-sm p-4",children:[e.jsxs(As,{className:"min-w-0 max-w-full space-y-1 overflow-hidden",children:[e.jsx(Bt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(Ds,{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:[(x||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:x?e.jsxs(_e,{value:m,onValueChange:p,disabled:j||y||b||c.length===0,children:[e.jsx(Me,{className:"h-7 justify-start gap-2 rounded-none border-0 bg-transparent px-0 text-xs shadow-none focus:ring-0 focus:ring-offset-0 [&>span]:!flex [&>span]:!min-w-0 [&>span]:!flex-1 [&>span]:!items-center",children:j&&!X?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),M]}):X?e.jsx(va,{devbox:X}):e.jsx($e,{placeholder:M})}),e.jsx(Pe,{children:c.map(H=>e.jsx(De,{value:Ue(H),textValue:`${H.name} ${H.projectName??""} ${Fo(H)}`,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(va,{devbox:H,showStatus:!0})},Ue(H)))})]}):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(Ve,{variant:"outline",className:"rounded-sm px-1.5 py-0 text-[10px]",children:[(j||f)&&e.jsx(de,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),g]}),u?.name&&e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{he()},disabled:j||y||O||x,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-sm text-muted-foreground hover:text-foreground",children:j&&x?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Ot,{className:"h-3 w-3"})})]})]}),ne&&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:H=>P(H===!0),disabled:y||b||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(bh,{error:Q,loading:R,onToggle:()=>I(H=>!H),open:S,operations:_})]}),e.jsxs(Oa,{className:"gap-2 sm:space-x-0",children:[e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y||b,className:"h-8 rounded-sm text-xs",children:"Close"}),z&&e.jsxs(J,{size:"sm",onClick:G,disabled:b,className:"h-8 rounded-sm text-xs",children:[b?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ms,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!z&&e.jsxs(J,{size:"sm",onClick:ae,disabled:!W||y,className:"h-8 rounded-sm text-xs",children:[y&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function wh(t,s=Va){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 yh({cluster:t,refresh:s}){const[n,r]=o.useState(null),[a,i]=o.useState(null),[l,c]=o.useState(()=>new Set),[d,m]=o.useState(()=>new Set),p=o.useMemo(()=>t?.nodes.find(f=>f.id===n)??null,[t?.nodes,n]),u=o.useMemo(()=>new Set((t?.nodes??[]).filter(f=>f.devbox?.enabled).map(f=>f.id)),[t?.nodes]),h=o.useMemo(()=>new Set((t?.nodes??[]).filter(f=>Rs(f.status,f.devbox?.lastStatus,f.devbox)).map(f=>f.id)),[t?.nodes]),x=o.useMemo(()=>new Set((t?.nodes??[]).filter(f=>Rt(f.devbox?.lastStatus)).map(f=>f.id)),[t?.nodes]),k=o.useMemo(()=>{const f=new Set(l);a&&f.add(a);for(const E of d)f.add(E);for(const E of x)f.add(E);return f},[d,a,l,x]);o.useEffect(()=>{let f=!1;const E=[...u];async function y(){try{const v=await wh(E);f||m(v)}catch{f||m(new Set)}}return y(),()=>{f=!0}},[u]),o.useEffect(()=>{c(f=>{let E=!1;const y=new Set(f);for(const v of f){const b=t?.nodes.find(C=>C.id===v);b?.status!=="online"&&(!b?.devbox?.lastStatus||Rt(b.devbox.lastStatus))||(y.delete(v),E=!0)}return E?y:f})},[t?.nodes]);const j=o.useCallback(async f=>{const E=t?.nodes.find(y=>y.id===f);if(E){i(f),c(y=>new Set(y).add(f));try{await Ha(f),ce.success(`Start requested for ${E.name}`),s()}catch(y){c(v=>{const b=new Set(v);return b.delete(f),b}),ce.error(y instanceof Error?y.message:"Failed to start DevBox")}finally{i(null)}}},[t?.nodes,s]);return{devBoxDialog:e.jsx(vh,{node:p,open:n!==null,startInProgress:p?k.has(p.id):!1,onOpenChange:f=>{f||r(null)},onRefresh:s}),devBoxNodeIds:u,devBoxStartNodeId:a,devBoxStartNodeIds:h,devBoxStartingNodeIds:k,openDevBox:r,startDevBox:j}}function jh(t){const[s,n]=o.useState(null),r=o.useCallback(i=>{t&&n(i)},[t]);return{nodeSettingsDialog:e.jsx(El,{open:s!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:s??void 0,showTrigger:!1}),openNodeSettings:r}}function Nh(t=!1){return!t}function kh({activeTaskId:t,fetchActiveTask:s,isRunning:n=!1,setPendingMessages:r,setTask:a,setTasks:i}){const l=o.useCallback((m,p)=>{a(u=>u&&u.id===m?{...u,queuedMessages:p}:u),i(u=>u.map(h=>h.id===m?{...h,queuedMessages:p}:h))},[a,i]),c=o.useCallback(async m=>{if(!t)return!1;const p=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`,u=Nh(n);u&&r(h=>[...h,{id:p,content:m,timestamp:new Date().toISOString()}]);try{const h=await Al(t,m);return h.queued&&(u&&r(x=>x.filter(k=>k.id!==p)),h.queuedMessages&&l(t,h.queuedMessages)),s(),!0}catch(h){return u&&r(x=>x.filter(k=>k.id!==p)),ce.error(h instanceof Error?h.message:"Failed to send message"),!1}},[t,s,n,r,l]);return{cancelQueuedMessage:o.useCallback(async m=>{if(t)try{const p=await Dl(t,m);l(t,p.queuedMessages),s()}catch(p){ce.error(p instanceof Error?p.message:"Failed to cancel queued message")}},[t,s,l]),queueFollowUpMessage:c}}const wa="grid-cols-[1.5rem_5.25rem_4rem_minmax(8rem,1fr)_4rem_4rem_6rem]",Sh={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Ch(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 zo(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 Th({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:B("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",wa),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:B("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",wa,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(Eh,{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:zo(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 Eh({agent:t}){const s=Sh[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 ya=320,ja=560,Uo=384,Na=360;function Ah(t,s=ja+Na){const n=Math.max(ya,Math.min(ja,s-Na));return Math.min(Math.max(Math.round(t),ya),n)}function Dh(t,s,n,r){return Ah(t+s-n,r)}function _h({detail:t,deleting:s=!1,onDelete:n,desktopWidth:r=Uo,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(Ve,{variant:"secondary",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary",children:t.agent}),e.jsx(Ve,{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(Sn,{asChild:!0,children:e.jsx(J,{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(qa,{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:zo(t)}),e.jsx(vs,{label:"Files",value:String(t.fileCount)}),e.jsx(vs,{label:"Source",value:t.source??"local"})]}),e.jsxs(Fn,{defaultValue:l,className:"mt-2 flex min-h-0 flex-1 flex-col",children:[e.jsxs(On,{className:"grid h-auto grid-cols-2 rounded-sm bg-primary/8 p-0.5",children:[t.kind==="mcp"?e.jsx(Nt,{value:"mcp",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"MCP"}):e.jsx(Nt,{value:"files",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"Files"}),e.jsx(Nt,{value:"readme",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"README"})]}),t.kind==="mcp"?e.jsx(ft,{value:"mcp",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(Mh,{detail:t})}):e.jsx(ft,{value:"files",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(Ph,{detail:t})}),e.jsx(ft,{value:"readme",className:"mt-2 min-h-0 flex-1 overflow-auto",children:t.readmeMarkdown?e.jsx(Nc,{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(Jn,{children:"No README content."})})]},t.id)]})}function Mh({detail:t}){const s=t.mcpPreview??[];return s.length===0?e.jsx(Jn,{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 Ph({detail:t}){const s=t.fileTree??[];return s.length===0?e.jsx(Jn,{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 Jn({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 Ih=20,Rh=288,Lh=360,Bh=440;function Oh(){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 Fh({triggerRect:t,targetRect:s,viewportRect:n,compact:r,browserOpen:a=!1,portalAlign:i,cssZoom:l=1}){const c=Number.isFinite(l)&&l>0?l:1,d=8,m=n.top+d,p=n.bottom-d,u=n.left+d,h=n.right-d,x=Math.max(0,p-t.bottom-4),k=Math.max(0,t.top-m-4),j=r?k<140&&x>k:x>=220||x>=k,A=j?x:k,f=Math.max(140,p-m),E=r&&a,b=Math.min(f,E?Bh:320,Math.max(E?Lh:140,A)),C=Rh*c,T=i==="end"?t.right-C:t.left,S=(Math.max(u,Math.min(T,h-C))-s.left)/c;if(!j&&!E)return{left:S,bottom:(s.bottom-(t.top-4))/c,maxHeight:b/c};const I=j?t.bottom+4:t.top-b-4,_=Math.max(m,Math.min(I,p-b));return{left:S,top:(_-s.top)/c,maxHeight:b/c}}function Zn(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(qo(a)?a:Vo(t.workDir,a));return s}function zh(t,s){if(t.kind==="global")return{nodeId:s.id,scope:{kind:"global"}};const n=Zn(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 Uh(t,s){return{nodeId:t,scope:s}}function ka(t,s,n){const r=s.trim();return!r||r==="."?t.workDir??r:n||qo(r)?r:t.workDir?Vo(t.workDir,r):r}function $h({node:t,scope:s,clusterNodes:n,onSelectionChange:r}){const a=o.useMemo(()=>Kh(n,t),[n,t]),i=o.useMemo(()=>Zn(t),[t]),l=o.useMemo(()=>a.map(c=>({value:c.id,label:c.name,description:`${c.role} · ${c.status}`,status:c.status})),[a]);return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-2",children:[e.jsx(Hh,{ariaLabel:"Capability node",value:t.name,description:`${t.role} · ${t.status}`,options:l,selectedValue:t.id,onSelect:c=>{const d=a.find(m=>m.id===c);d&&r?.(zh(s,d))}}),e.jsx($o,{node:t,projectPaths:i,selectedScope:s,onSelect:c=>r?.(Uh(t.id,c))}),e.jsx(qh,{node:t})]})}function qh({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:B("h-1.5 w-1.5 shrink-0 rounded-full",rs(t.status))})]})}function $o({node:t,projectPaths:s,selectedScope:n,onSelect:r,compact:a=!1,portal:i=!1,portalAlign:l="start"}){const[c,d]=o.useState(!1),[m,p]=o.useState(null),[u,h]=o.useState(!1),[x,k]=o.useState(!1),[j,A]=o.useState(null),[f,E]=o.useState(!1),[y,v]=o.useState(null),b=o.useRef(null),C=o.useRef(null),T=o.useRef(null),P=o.useMemo(()=>s.map(V=>({value:V,label:Ca(V),description:V})),[s]),S=n.kind==="project"?n.projectPath:void 0,I=n.kind==="global"?"Global":Ca(n.projectPath),_=n.kind==="global"?"Global":n.projectPath,D=o.useCallback(()=>!i||typeof document>"u"?null:C.current?.closest('[data-capability-share-dialog="true"]')??document.body,[i]),R=o.useCallback(()=>{if(!i||!C.current||typeof window>"u")return;const V=C.current.getBoundingClientRect(),O=D(),g=O&&O!==document.body?O.getBoundingClientRect():{left:0,top:0,bottom:window.innerHeight};v(Fh({triggerRect:V,targetRect:g,viewportRect:{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},compact:a,browserOpen:f,portalAlign:l,cssZoom:Oh()}))},[f,a,D,i,l]);o.useEffect(()=>{c||E(!1)},[c]),o.useEffect(()=>{if(!c)return;const V=O=>{if(!(O.target instanceof Node))return;const g=O.composedPath(),$=b.current?g.includes(b.current):!1,N=T.current?g.includes(T.current):O.target instanceof Element&&!!O.target.closest('[data-capability-scope-menu="true"]');!$&&!N&&d(!1)};return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[c]),o.useEffect(()=>{if(!(!c||!i))return R(),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0),()=>{window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0)}},[c,i,R]);const F=async(V,O=0,g=!1)=>{if(t.workDir){A(null),g?k(!0):h(!0);try{const $=await Pa(t.id,{path:V||".",limit:Ih,offset:O,directoriesOnly:!0,allowAbsolute:!0});p(N=>g&&N?{...$,entries:[...N.entries,...$.entries]}:$)}catch($){A($ instanceof Error?$.message:"Failed to browse folders"),g||p(null)}finally{h(!1),k(!1)}}};o.useEffect(()=>{!c||!f||!t.workDir||(p(null),A(null),F(S||"."))},[f,c,t.id,t.workDir,S]);const Q=(V,O=!1)=>{r({kind:"project",projectPath:ka(t,V,O)}),d(!1)},Y=()=>{r({kind:"global"}),d(!1)},X=m?ka(t,m.currentPath,m.isAbsolute):S??t.workDir??"",Z=i?D():null,te=e.jsxs("div",{ref:T,"data-capability-scope-menu":"true","aria-hidden":!c,onClick:V=>V.stopPropagation(),onMouseDown:V=>V.stopPropagation(),onPointerDown:V=>V.stopPropagation(),style:i&&y?{left:y.left,top:y.top,bottom:y.bottom,height:a&&f?y.maxHeight:void 0,maxHeight:y.maxHeight}:void 0,className:B(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"),!c&&"hidden"),children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 p-1",children:[e.jsx("div",{className:B("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:B("overflow-y-auto pr-0.5",a?"max-h-32":"max-h-40"),children:[e.jsx(Sa,{icon:"global",label:"Global",selected:n.kind==="global",onSelect:Y,compact:a}),P.length>0?P.map(V=>e.jsx(Sa,{icon:"folder",label:V.label,description:V.description,selected:S===V.value,onSelect:()=>Q(V.value,!0),compact:a},V.value)):e.jsx("div",{className:B("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:B("border-b border-border/55",f?"flex min-h-0 flex-1 flex-col":"shrink-0"),children:[e.jsxs("button",{type:"button","aria-expanded":f,onClick:()=>E(V=>!V),className:B("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(Lt,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Browse folders"}),e.jsx(Je,{className:B("h-3 w-3 shrink-0 transition-transform duration-200",f&&"rotate-180")})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"shrink-0 px-2 pb-1.5",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>m?.parentPath&&void F(m.parentPath),disabled:!m?.parentPath||u,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(to,{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:B("min-h-0 flex-1 overflow-y-auto",a?"min-h-[8.25rem]":"max-h-56"),children:[t.workDir?u?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[9px] text-muted-foreground",children:[e.jsx(de,{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(V=>e.jsx(Vh,{entry:V,onSelect:()=>Q(V.path,m.isAbsolute),onOpen:()=>{F(V.path)}},V.path)),m.hasMore&&e.jsxs("button",{type:"button",onClick:()=>{F(m.currentPath,m.entries.length,!0)},disabled:x,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:[x?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Oc,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:j??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:"This node has no working directory."}),j&&m&&m.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[9px] text-destructive",children:j})]})]})]})]});return e.jsxs("div",{ref:b,className:"relative min-w-0",children:[e.jsxs("button",{ref:C,type:"button","aria-label":"Capability location","aria-expanded":c,title:_,onClick:()=>d(V=>(V||(E(!1),R()),!V)),className:B("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:B("block truncate font-medium text-foreground",a?"text-[9px] leading-3":"text-[10px] leading-4"),children:I})}),e.jsx(Je,{className:B(a?"h-2.5 w-2.5":"h-3 w-3","shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),i&&Z?Fa.createPortal(te,Z):te]})}function Sa({icon:t,label:s,description:n,selected:r,onSelect:a,compact:i=!1}){const l=t==="global"?Ic:Lt;return e.jsxs("button",{type:"button",onClick:a,className:B(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:B("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:B("block truncate text-muted-foreground",i?"text-[7px] leading-3":"text-[8px] leading-3"),children:n})]})]})}function Vh({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(Lt,{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(st,{className:"h-3 w-3"})})]})}function Hh({ariaLabel:t,value:s,description:n,options:r,selectedValue:a,onSelect:i}){const[l,c]=o.useState(!1),d=o.useRef(null);return o.useEffect(()=>{if(!l)return;const m=p=>{d.current&&p.target instanceof Node&&!d.current.contains(p.target)&&c(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[l]),e.jsxs("div",{ref:d,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":t,"aria-expanded":l,title:n??s,onClick:()=>c(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:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform",l&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!l,className:B("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),c(!1)},className:B("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:B("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 Kh(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 Ca(t){return t.split(/[\\/]+/).filter(Boolean).at(-1)??t}function qo(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)}function Vo(t,s){return`${t.replace(/[\\/]+$/,"")}/${s.replace(/^[\\/]+/,"")}`}const Gh="h-6 w-24 rounded-sm px-2 text-[10px] shadow-none",jn="text-[10px]",Ho=["claudecode","codex","copilot"],Qt={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Wh({open:t,sourceNode:s,targetNodes:n,selectedCapabilities:r,previewResults:a=[],embedded:i=!1,onClose:l,onPreviewTargetsChange:c,onShare:d}){const[m,p]=o.useState(()=>new Set(a.length>0?a.map(g=>at(g.nodeId,g.targetAgent)):Yh(s.id,n,r))),[u,h]=o.useState(()=>Object.fromEntries(Jh(s.id,n,r))),[x,k]=o.useState({}),[j,A]=o.useState(!1),[f,E]=o.useState(()=>new Set),[y,v]=o.useState(()=>new Set),b=r.some(g=>g.kind==="plugin"),C=o.useMemo(()=>Xn(r).map(g=>({key:at(s.id,g),nodeId:s.id,node:s,label:`Install into ${Qt[g]}`,agentLabel:Qt[g],defaultScope:Go(r),disabled:!1,targetAgent:g})),[r,s]),T=o.useMemo(()=>n.flatMap(g=>{const $={kind:"global"},N=g.status==="offline",q=Ko(r);return q.length===0?[{key:at(g.id),nodeId:g.id,node:g,label:g.name,defaultScope:$,disabled:N}]:q.map(z=>({key:at(g.id,z),nodeId:g.id,node:g,label:`${g.name} / ${Qt[z]}`,agentLabel:Qt[z],defaultScope:$,disabled:N,targetAgent:z}))}),[r,n]),P=o.useMemo(()=>[...C,...T],[C,T]),S=o.useMemo(()=>n.map(g=>({node:g,options:T.filter($=>$.nodeId===g.id)})).filter(g=>g.options.length>0),[n,T]),I=o.useMemo(()=>new Map(a.filter(g=>g.capabilityId).map(g=>[Ta(g.nodeId,g.capabilityId,g.targetAgent),g])),[a]),_=o.useMemo(()=>new Map(a.map(g=>[at(g.nodeId,g.targetAgent),g])),[a]),D=o.useMemo(()=>P.filter(g=>m.has(g.key)),[m,P]),R=o.useMemo(()=>D.map(g=>({nodeId:g.nodeId,scope:u[g.key]??g.defaultScope,...g.targetAgent?{targetAgent:g.targetAgent}:{}})),[D,u]),F=o.useMemo(()=>{const g=[],$=new Map;for(const N of D){if(!$.has(N.nodeId)){const q=N.nodeId===s.id?s:n.find(z=>z.id===N.nodeId);$.set(N.nodeId,{nodeId:N.nodeId,node:q,name:q?.name??N.nodeId,options:[]}),g.push(N.nodeId)}$.get(N.nodeId).options.push(N)}return g.map(N=>$.get(N))},[D,s,n]),Q=o.useMemo(()=>{const g=Array.from(new Set(r.map(N=>N.agent))),[$]=g;if($)return g.length===1?Qt[$]:`${g.length} agents`},[r]),Y=S.length+1;o.useEffect(()=>{let g=!1;const $={...u};for(const N of P)$[N.key]||($[N.key]=N.defaultScope,g=!0);g&&h($)},[P,u]),o.useEffect(()=>{t&&c?.(R)},[t,c,R]),o.useEffect(()=>{t&&(E(new Set),v(new Set))},[t,s.id]),o.useEffect(()=>{if(!i||!t)return;const g=$=>{$.key==="Escape"&&l()};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[i,l,t]);const X=g=>{k(Object.fromEntries(D.map($=>[$.key,g])))},Z=async()=>{A(!0);try{await d(D.map(g=>({nodeId:g.nodeId,scope:u[g.key]??g.defaultScope,...g.targetAgent?{targetAgent:g.targetAgent}:{},conflictStrategy:x[g.key]??"overwrite"})))}finally{A(!1)}},te=g=>{const $=u[g.key]??g.defaultScope,N=`capability-share-target-${Qh(g.key)}`,q=m.has(g.key);return e.jsxs("div",{"data-target-agent":g.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":g.disabled?"true":void 0,children:[e.jsx(is,{id:N,disabled:g.disabled,checked:q,onCheckedChange:z=>p(W=>{const L=new Set(W);return z===!0?L.add(g.key):L.delete(g.key),L}),"aria-label":`Select ${g.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:N,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":g.disabled?"true":void 0,children:g.agentLabel??g.label}),e.jsx("div",{className:"flex w-28 shrink-0 justify-end",children:q&&!g.disabled&&e.jsx($o,{node:g.node,projectPaths:Zn(g.node),selectedScope:$,onSelect:z=>h(W=>({...W,[g.key]:z})),compact:!0,portal:!0,portalAlign:"end"})})]},g.key)},V=(g,$,N,q)=>{const z=f.has(g.id),W=D.filter(L=>L.nodeId===g.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":z,onClick:()=>E(L=>Ea(L,g.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(st,{className:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",z&&"rotate-90")}),e.jsx("span",{className:B("h-1.5 w-1.5 shrink-0 rounded-full",rs(g.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold text-foreground",title:g.name,children:g.name}),W>0&&e.jsxs("span",{className:"shrink-0 text-[8px] font-medium text-primary",children:[W," selected"]}),e.jsx("span",{className:"shrink-0 text-[8px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:$?"this node":"remote"}),g.status==="offline"&&e.jsx(Ve,{variant:"outline",className:"rounded-sm px-1 py-0 text-[8px]",children:"offline"}),q>0&&e.jsxs("span",{className:"sr-only",children:[q," agents"]})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-200 ease-out",z?"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:N})})})]},g.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(Ss,{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:B("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:D.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:[V(s,!0,b?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(te),C.length),S.map(g=>V(g.node,!1,g.options.map(te),g.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(g=>e.jsx("button",{type:"button",onClick:()=>X(g),className:"h-5 rounded-[3px] px-1.5 text-[9px] capitalize text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground",children:g},g))})]})]}),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:D.length===0?e.jsx("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"Select a target to preview conflicts."}):F.map(g=>{const $=!y.has(g.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":$,onClick:()=>v(N=>Ea(N,g.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(st,{className:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",$&&"rotate-90")}),g.node&&e.jsx("span",{className:B("h-1.5 w-1.5 shrink-0 rounded-full",rs(g.node.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-semibold text-foreground",children:g.name}),e.jsxs("span",{className:"shrink-0 text-[8px] text-muted-foreground",children:[g.options.length," ",g.options.length===1?"agent":"agents"]})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-200 ease-out",$?"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:g.options.map(N=>{const q=x[N.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:N.agentLabel??"Matching agent"}),e.jsxs(_e,{value:q,onValueChange:z=>k(W=>({...W,[N.key]:z})),children:[e.jsx(Me,{className:Gh,children:e.jsx($e,{})}),e.jsxs(Pe,{className:"shadow-none",children:[e.jsx(De,{value:"overwrite",className:jn,children:"Overwrite"}),e.jsx(De,{value:"skip",className:jn,children:"Skip"}),e.jsx(De,{value:"abort",className:jn,children:"Abort"})]})]})]}),e.jsx("div",{className:"space-y-px",children:r.map(z=>{const W=I.get(Ta(N.nodeId,z.id,N.targetAgent))??(r.length===1?_.get(N.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:z.name}),e.jsx("span",{className:W?.conflict?"text-amber-500":W?"text-emerald-500":"text-muted-foreground",children:W?W.conflict?`exists${W.currentVersion?` v${W.currentVersion}`:""}`:"new install":"checking"}),W?.sourceVersion&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[e.jsx(pr,{className:"inline h-2.5 w-2.5"})," v",W.sourceVersion]})]},z.id)})})]},N.key)})})})})]},g.nodeId)})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-border/55 px-4 py-3",children:[e.jsx(J,{variant:"ghost",onClick:l,className:"h-7 rounded-sm px-3 text-[11px]",children:"Cancel"}),e.jsxs(J,{onClick:Z,disabled:j||D.length===0,className:"h-7 rounded-sm px-3 text-[11px]",children:[j?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ss,{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:g=>{g.target===g.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:g=>g.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(it,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})}):null:e.jsx(St,{open:t,onOpenChange:g=>{g||l()},children:e.jsx(Ct,{"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 at(t,s){return s?`agent:${t}:${s}`:`node:${t}`}function Qh(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-")}function Ta(t,s,n){return`${at(t,n)}\0${s}`}function Ea(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function Yh(t,s,n){const r=s.find(i=>i.status!=="offline");if(r)return[at(r.id,Zh(n))];const a=Xn(n)[0];return a?[at(t,a)]:[]}function Jh(t,s,n){const r=Ko(n);return[...s.flatMap(a=>r.length===0?[[at(a.id),{kind:"global"}]]:r.map(i=>[at(a.id,i),{kind:"global"}])),...Xn(n).map(a=>[at(t,a),Go(n)])]}function Ko(t){return t.length===0||t.some(s=>s.kind==="plugin")?[]:Ho}function Zh(t){if(!(t.length===0||t.some(s=>s.kind==="plugin")))return t[0]?.agent}function Xn(t){if(t.length===0||t.some(n=>n.kind==="plugin"))return[];const s=new Set(t.map(n=>n.agent));return Ho.filter(n=>!s.has(n))}function Go(t){return t[0]?.scope??{kind:"global"}}const Aa="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",vt="py-0.5 pl-6 pr-1.5 text-[9px] leading-4 [&_svg]:h-3 [&_svg]:w-3",Wo="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",Xh="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 ef(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 tf(t,s,n,r){return n.map(a=>({sourceNodeId:t,capabilityId:a.id,sourceScope:s,targets:r}))}function sf({loading:t,onRefresh:s}){return e.jsxs(J,{variant:"ghost",onClick:s,disabled:t,"aria-busy":t,className:B(Wo,"min-w-[4.5rem]"),children:[e.jsx(ro,{className:B("h-2.5 w-2.5",t&&"animate-spin")}),t?"Refreshing":"Refresh"]})}function nf({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(J,{type:"button",variant:"ghost",onClick:n,disabled:t===0,className:Wo,children:[e.jsx(it,{className:"h-2.5 w-2.5"}),"Selected: ",t," / Clear"]})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(sf,{loading:s,onRefresh:r}),e.jsxs(J,{type:"button",variant:"ghost",onClick:a,disabled:t===0,className:Xh,children:[e.jsx(Ss,{className:"h-2.5 w-2.5"}),"Share"]})]})]})}function rf({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 af({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(de,{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 of({open:t,node:s,scope:n,clusterNodes:r,onOpenChange:a,onSelectionChange:i}){const[l,c]=o.useState([]),[d,m]=o.useState([]),[p,u]=o.useState(!1),[h,x]=o.useState(""),[k,j]=o.useState("all"),[A,f]=o.useState("all"),[E,y]=o.useState(new Set),[v,b]=o.useState(null),[C,T]=o.useState(null),[P,S]=o.useState(!1),[I,_]=o.useState(null),[D,R]=o.useState(!1),[F,Q]=o.useState([]),[Y,X]=o.useState(Uo),[Z,te]=o.useState(null),V=o.useMemo(()=>Ch(l,{search:h,agent:k,kind:A}),[k,l,A,h]),O=o.useMemo(()=>l.filter(G=>E.has(G.id)),[l,E]),g=o.useMemo(()=>r.filter(G=>G.id!==s.id),[r,s.id]),$=n.kind==="project"?n.projectPath:"global",N=async()=>{u(!0);try{const G=await Ml(s.id,{scope:n});c(G.items),m((G.errors??[]).map(M=>`${M.agent}: ${M.message}`))}catch(G){m([G instanceof Error?G.message:"Failed to load capabilities"])}finally{u(!1)}};o.useEffect(()=>{t&&(y(new Set),b(null),T(null),S(!1),Q([]),c([]),m([]),N())},[t,s.id,n.kind,$]),o.useEffect(()=>{if(!Z)return;const G=ne=>{X(Dh(Z.startWidth,Z.startClientX,ne.clientX,window.innerWidth))},M=()=>te(null);return window.addEventListener("pointermove",G),window.addEventListener("pointerup",M),()=>{window.removeEventListener("pointermove",G),window.removeEventListener("pointerup",M)}},[Z]);const q=G=>{G.preventDefault(),te({startClientX:G.clientX,startWidth:Y})},z=()=>{te(null),S(!1),b(null),T(null)},W=()=>{y(new Set),Q([])},L=async G=>{b(G.id),S(!0),T(null);const M=await Pl(s.id,G.id,n);T(M.detail)},oe=o.useCallback(async G=>{if(O.length===0||G.length===0){Q([]);return}Q([]);try{const M=ef(s.id,n,O,G),ne=await Promise.all(M.map(H=>_l(H)));Q(ne.flatMap((H,re)=>H.results.map(we=>({...we,capabilityId:M[re]?.capabilityId}))))}catch{Q([])}},[s.id,n,O]),ie=()=>{Q([]),R(!0)},he=async G=>{const M=tf(s.id,n,O,G);M.length!==0&&(await Promise.all(M.map(ne=>Rl(ne))),ce.success(`${M.length} capability share request${M.length===1?"":"s"} completed`),R(!1))},ae=async()=>{if(!(!C||I)){_(C.id);try{const G=await Il(s.id,C.id,n);G.status==="deleted"?(ce.success(`Deleted ${C.name}`),c(M=>M.filter(ne=>ne.id!==C.id)),y(M=>{const ne=new Set(M);return ne.delete(C.id),ne}),b(null),T(null),S(!1),await N()):(ce.info(G.message??"Capability was not found"),b(null),T(null),S(!1),await N())}catch(G){ce.error(G instanceof Error?G.message:"Failed to delete capability")}finally{_(null)}}};return e.jsx(e.Fragment,{children:e.jsx(St,{open:t,onOpenChange:a,children:e.jsxs(Ct,{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(As,{className:"border-b border-border/55 bg-card/28 px-4 py-2.5 text-left",children:[e.jsx(Bt,{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($h,{node:s,scope:n,clusterNodes:r,onSelectionChange:i}),e.jsxs(Ds,{"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(Ia,{className:"pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),e.jsx(ot,{value:h,onChange:G=>x(G.target.value),placeholder:"Search capabilities",className:"h-7 rounded-sm border-0 bg-muted/55 pl-6 text-[10px] shadow-none"})]}),e.jsxs(_e,{value:k,onValueChange:G=>j(G),children:[e.jsx(Me,{className:B("w-28",Aa),children:e.jsx($e,{})}),e.jsxs(Pe,{className:"shadow-none",children:[e.jsx(De,{value:"all",className:vt,children:"Agent: All"}),e.jsx(De,{value:"claudecode",className:vt,children:"Claude Code"}),e.jsx(De,{value:"codex",className:vt,children:"Codex"}),e.jsx(De,{value:"copilot",className:vt,children:"Copilot"})]})]}),e.jsxs(_e,{value:A,onValueChange:G=>f(G),children:[e.jsx(Me,{className:B("w-24",Aa),children:e.jsx($e,{})}),e.jsxs(Pe,{className:"shadow-none",children:[e.jsx(De,{value:"all",className:vt,children:"Kind: All"}),e.jsx(De,{value:"skill",className:vt,children:"Skill"}),e.jsx(De,{value:"plugin",className:vt,children:"Plugin"}),e.jsx(De,{value:"mcp",className:vt,children:"MCP"})]})]})]}),d.length>0&&e.jsx("div",{className:"rounded-sm bg-amber-500/10 px-2 py-1 text-[10px] text-amber-600",children:d.join(" · ")}),e.jsx(Th,{items:V,selectedIds:E,activeId:v,onToggleSelected:(G,M)=>y(ne=>{const H=new Set(ne);return M?H.add(G):H.delete(G),H}),onOpenDetail:L}),e.jsx(nf,{selectedCount:E.size,loading:p,onClearSelection:W,onRefresh:N,onShare:ie}),e.jsx(af,{visible:p&&l.length===0})]}),P&&e.jsxs(e.Fragment,{children:[e.jsx(rf,{onBeginResize:q,onFold:z}),e.jsx(_h,{detail:C,deleting:I===C?.id,desktopWidth:Y,onDelete:C?ae:void 0,pending:!C})]})]}),D&&e.jsx(Wh,{open:D,sourceNode:s,targetNodes:g,selectedCapabilities:O,previewResults:F,embedded:!0,onClose:()=>R(!1),onPreviewTargetsChange:oe,onShare:he})]})})})}function lf(t){const[s,n]=o.useState(null),r=o.useMemo(()=>s?t?.nodes.find(d=>d.id===s.nodeId)??(t?.self.id===s.nodeId?t.self:null)??null:null,[t,s]),a=o.useCallback(d=>{n({nodeId:d,scope:{kind:"global"}})},[]),i=o.useCallback((d,m)=>{n({nodeId:d,scope:{kind:"project",projectPath:m}})},[]),l=o.useCallback(d=>{n(d)},[]);return{capabilitiesDialog:s&&r&&t?e.jsx(of,{open:!0,node:r,scope:s.scope,clusterNodes:t.nodes,onOpenChange:d=>{d||n(null)},onSelectionChange:l}):null,openNodeCapabilities:a,openProjectCapabilities:i}}function cf(){const{id:t}=Ll(),s=Bl(),n=Ol(),r=Fl(),{cluster:a,systemInfo:i,events:l,sseConnected:c,subscribe:d,refresh:m,loading:p,error:u}=zl(),h=o.useMemo(()=>Ul(s.state),[s.state]),[x,k]=o.useState(null),[j,A]=o.useState("active"),[f,E]=o.useState("all"),[y,v]=o.useState("all"),[b,C]=o.useState("all"),T=r?.headerSearchQuery??"",P=o.useDeferredValue(T),{desktopTasksOpen:S,mobileTasksPanelOpen:I,mobileTasksPanelRef:_,operationsOpen:D,operationsPanelRef:R,panelResize:F,setMobileTasksPanelOpen:Q,setOperationsOpen:Y,toggleTasksPanel:X}=Km(),[Z,te]=o.useState(()=>!!h?.draftNewTask),[V,O]=o.useState(()=>h?.createMode??"chat"),[g,$]=o.useState(()=>h?.createDefaults??null),[N,q]=o.useState(()=>h?.draftNewTask?{route:h.returnRoute??"/",taskId:h.returnTaskId??null}:null),[z,W]=o.useState(!1),[L,oe]=o.useState("transcript"),[ie,he]=o.useState("overview"),[ae,G]=o.useState("all"),[M,ne]=o.useState(!1),[H,re]=o.useState(null),[we,fe]=o.useState([]),[Ie,Ee]=o.useState([]),[xt,Le]=o.useState(!1),[Ze,Se]=o.useState(!1),[He,We]=o.useState(null),[Ke,Oe]=o.useState(new Set),[lt,ct]=o.useState(!1),[ee,ge]=o.useState(!1),[ye,Fe]=o.useState(null),ze=o.useRef(null),Ne=o.useRef(new Map),je=a?.self?.role==="leader",pt=a?.self?.id,{quickChats:zt}=$l();oh({cluster:a,subscribe:d});const{nodeSettingsDialog:Ut,openNodeSettings:K}=jh(je),{capabilitiesDialog:ke,openNodeCapabilities:Ae,openProjectCapabilities:wt}=lf(a),{devBoxDialog:$t,devBoxNodeIds:yt,devBoxStartNodeId:Be,devBoxStartNodeIds:Qe,devBoxStartingNodeIds:nt,openDevBox:dt,startDevBox:ut}=yh({cluster:a,refresh:m}),{completedGroups:At=[],fetchTasks:Re,loadCompletedTasksPage:mt,removeTasksFromList:Ce,setTasks:Xe,tasks:qe,tasksError:qt,tasksLoading:pe}=sh({isLeader:je,selfId:pt,sseConnected:c,preservedTask:H,subscribe:d});o.useEffect(()=>ql(()=>{he("events"),Y(!0)}),[Y]);const be=o.useMemo(()=>[...qe].sort((w,U)=>U.updatedAt-w.updatedAt),[qe]),Te=o.useMemo(()=>[...qe].sort((w,U)=>U.createdAt-w.createdAt||U.updatedAt-w.updatedAt)[0]?.id??null,[qe]),ls=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[]){const se=wd(be,U.id);se>0&&w.set(U.id,se)}return w},[a?.nodes,be]),rt=o.useMemo(()=>be.filter(w=>!Vl(w,a?.nodes,a?.self)||!Hl(w,j)||f!=="all"&&w.agent!==f||!Kl(w,b)||y==="unassigned"&&w.assignedTo||y!=="all"&&y!=="unassigned"&&Gl(w.assignedTo,a?.nodes,w.assignedNodeName)!==y?!1:P.trim()?Wl(w,P):!0),[be,a?.nodes,a?.self,j,f,b,y,P]);o.useEffect(()=>{Oe(w=>{const U=Cd(w,rt.map(se=>se.id));return U.size===w.size?w:U})},[rt]),o.useEffect(()=>{je||Oe(new Set)},[je]);const Qo=o.useMemo(()=>["all",...Array.from(new Set(be.map(w=>w.agent))).sort()],[be]),Yo=o.useMemo(()=>{const U=Array.from(new Set(be.map(se=>se.assignedTo).filter(se=>!!se))).map(se=>{const ve=be.find(ue=>ue.assignedTo===se);return a?.nodes.find(ue=>ue.id===se)??{id:se,name:kn(se,a?.nodes,ve?.assignedNodeName)}}).sort((se,ve)=>se.name.localeCompare(ve.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...U.map(se=>({value:se.name.toLowerCase(),label:se.name}))]},[be,a?.nodes]),er=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[])w.set(U.id,U.name);for(const U of be)U.assignedTo&&U.assignedNodeName&&!w.has(U.assignedTo)&&w.set(U.assignedTo,U.assignedNodeName);return w},[a?.nodes,be]),Jo=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[])U.workDir&&w.set(U.id,U.workDir);return a?.self?.workDir&&w.set(a.self.id,a.self.workDir),w},[a]),Zo=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[])w.set(U.id,U.status);return a?.self&&w.set(a.self.id,a.self.status),w},[a]),Xo=o.useMemo(()=>new Map(At.map(w=>[Bn(w),w])),[At]),tr=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[])U.status!=="offline"&&w.set(U.id,U);return a?.self&&a.self.status!=="offline"&&w.set(a.self.id,a.self),Array.from(w.values())},[a]),ei=a?.self?.id??tr[0]?.id??null,Vt=o.useMemo(()=>l.filter(Ql),[l]),Ls=o.useMemo(()=>["all",...Array.from(new Set(Vt.map(w=>w.type))).sort()],[Vt]),ti=o.useMemo(()=>ae==="all"?Vt:Vt.filter(w=>w.type===ae),[Vt,ae]),si=rt.length>0&&rt.every(w=>Ke.has(w.id)),ni=rt.some(w=>Ke.has(w.id)),ri=Td(rt,Ke);o.useEffect(()=>{h?.draftNewTask&&(te(!0),O(h.createMode??"chat"),$(h.createDefaults??null),q({route:h.returnRoute??"/",taskId:h.returnTaskId??null}))},[h]),o.useEffect(()=>{ae!=="all"&&!Ls.includes(ae)&&G("all")},[ae,Ls]),o.useEffect(()=>{br(t,Z)&&!x&&Te&&k(Te)},[t,Z,x,Te]),o.useEffect(()=>{br(t,Z)&&(x&&qe.some(w=>w.id===x)||k(Te))},[t,Z,x,Te,qe]);const xe=jd({routeTaskId:t,creatingTask:Z,internalSelectedTaskId:x,sortedTaskIds:Te?[Te]:[]}),Dt=o.useMemo(()=>qe.find(w=>w.id===xe)??null,[qe,xe]);o.useEffect(()=>{ze.current=xe??null},[xe]);const gt=o.useCallback(()=>{re(null),fe([]),Ee([]),We(null),Se(!1)},[]),Ht=o.useCallback((w,U,se=!0)=>{Ne.current.set(w,{logs:Bo(U),loaded:se})},[]),Ye=o.useCallback(async()=>{const w=xe;if(w)try{const U=await Yl(w);if(ze.current!==w)return;re(U),Xe(se=>lo(se,U)),We(null)}catch(U){if(ze.current!==w)return;gt(),We(U instanceof Error?U.message:"Failed to load task")}finally{ze.current===w&&Le(!1)}},[xe,gt,Xe]),cs=o.useCallback(async()=>{const w=xe;if(w)try{const U=await Cn(w);if(ze.current!==w)return;fe(se=>{const ve=eo(se,U.logs);return Ht(w,ve),ve}),Ee(se=>An(se,U.logs))}catch{}finally{ze.current===w&&Se(!1)}},[xe,Ht]);o.useEffect(()=>{if(!xe){gt(),Le(!1);return}oe("transcript"),re(Dt);const w=nh(xe,Ne.current);fe(w.logs),Ee([]),We(null),Le(!0),Se(w.transcriptLoading),Ye(),cs()},[xe,gt,cs,Ye]),o.useEffect(()=>{if(!Nd({activeTaskId:xe,routeTaskId:t,creatingTask:Z,tasksLoading:pe,loadedTaskIds:qe.map(U=>U.id)}))return;const w=Te;k(w),gt(),o.startTransition(()=>{n(w?`/tasks/${w}`:"/",{state:null})})},[xe,gt,Z,Te,n,t,qe,pe]),o.useEffect(()=>{Dt&&re(w=>!w||w.id!==Dt.id?w:{...w,...Dt})},[Dt]),o.useEffect(()=>{if(xe)return d("task",w=>{const U=w.data.taskId;if(!(typeof U!="string"||U!==xe)){if(w.type==="task.output"){const se=w.data.event;if(se){fe(ue=>{const Gt=pc(ue,se);return Ht(xe,Gt),Gt}),Se(!1);const ve=Tn(se);ve&&Ee(ue=>gc(ue,ve))}}w.type==="task.updated"&&Ye(),w.type==="task.status"&&(Ye(),cs())}})},[d,xe,Ye,cs]);const le=H??Dt,ai=le?.assignedTo?a?.nodes.find(w=>w.id===le.assignedTo)??null:null,Kt=r?.setHeaderTaskContext;o.useEffect(()=>{if(!Kt)return;if(!le){Kt(null);return}const w=le.effectiveProjectPath??le.project??"default workspace";return Kt({taskId:le.id,taskTitle:le.title,nodeName:kn(le.assignedTo,a?.nodes,le.assignedNodeName),projectLabel:$a(w),projectPath:w}),()=>Kt(null)},[le,a?.nodes,Kt]);const Bs=Ie.length>0,oi=le?Jl.has(le.agent):!1,ds=le?.status==="running",ii=le?ys.has(le.status):!1,li=le?ys.has(le.status)||Zl.has(le.status):!1,ci=!!(le&&je&&le.status==="failed"),Os=o.useMemo(()=>Mm(le,a,Bs,!!ds),[le,a,Bs,ds]),Fs=o.useMemo(()=>bc([...we,...Ie.map(w=>Hs(w.content,w.timestamp))]),[we,Ie]),us=o.useMemo(()=>{if(!le||le.conversationKind==="nativeSession")return null;const w=vc(le);if(w.length>0)return Hs(w,new Date(le.createdAt).toISOString());if(Fs.length>0)return null;const U=wc(le.description||le.title);return U.length>0?Hs(U,new Date(le.createdAt).toISOString()):null},[le,Fs]),zs=o.useMemo(()=>us?Tn(us):null,[us]),di=o.useMemo(()=>zs?yc(we,zs):!1,[we,zs]),Us=o.useCallback((w="chat",U)=>{const se={route:t?`/tasks/${t}`:"/",taskId:xe};q(se),O(w),$(U??null),te(!0),o.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:se.route,returnTaskId:se.taskId,createMode:w,createDefaults:U}})})},[t,xe,n]),ui=o.useCallback(()=>{const w=N?.taskId??Te;te(!1),q(null),$(null),k(w),o.startTransition(()=>{n(N?.route??"/",{state:null})})},[N,Te,n]),sr=o.useCallback(w=>{te(!1),q(null),$(null),k(w),o.startTransition(()=>{n(`/tasks/${w}`,{state:null})})},[n]),mi=o.useCallback(w=>{ze.current=w.id,te(!1),q(null),$(null),Xe(U=>kd(U,w)),re(w),fe([]),Ee([]),We(null),Le(!1),Se(w.conversationKind==="nativeSession"),oe("transcript"),k(w.id),lh({task:w,getActiveTaskId:()=>ze.current,setLogs:fe,setPendingMessages:Ee,setTranscriptLoading:Se}),Re(),o.startTransition(()=>{n(`/tasks/${w.id}`,{state:null})})},[Re,n]),{cancelQueuedMessage:hi,queueFollowUpMessage:ms}=kh({activeTaskId:xe,fetchActiveTask:Ye,isRunning:ds,setPendingMessages:Ee,setTask:re,setTasks:Xe}),fi=o.useCallback(w=>{ms(w)},[ms]),xi=o.useCallback(async()=>{const w=xe;if(!(!w||le?.conversationKind!=="nativeSession")){Se(!0);try{const U=await Cn(w);if(ze.current!==w)return;fe(U.logs),Ht(w,U.logs),Ee(se=>An(se,U.logs))}catch(U){ce.error(U instanceof Error?U.message:"Failed to reload transcript")}finally{ze.current===w&&Se(!1)}}},[le?.conversationKind,xe,Ht]),pi=o.useCallback(w=>ms(w),[ms]),gi=o.useCallback(async()=>{if(le)try{await Xl(le.id),Ye(),Re()}catch(w){ce.error(w instanceof Error?w.message:"Failed to cancel task")}},[le,Ye,Re]),{handleShareTask:bi,handleStopShareTask:vi}=$m(le,Ye,Re),wi=o.useCallback(async()=>{if(le)try{await ec(le.id),Ye(),Re()}catch(w){ce.error(w instanceof Error?w.message:"Failed to retry task")}},[le,Ye,Re]),hs=o.useCallback((w,U=!1)=>{const se=Ed(rt,w);return k(se),(U||!se)&&gt(),o.startTransition(()=>{n(se?`/tasks/${se}`:"/",{state:null})}),se},[gt,rt,n]),yi=o.useCallback((w,U)=>{Oe(se=>{const ve=new Set(se);return U?ve.add(w):ve.delete(w),ve})},[]),ji=o.useCallback(w=>{if(!w){Oe(new Set);return}Oe(new Set(rt.map(U=>U.id)))},[rt]),Ni=o.useCallback(async()=>{const w=Array.from(Ke);if(w.length!==0)try{const{results:U}=await tc(w),se=U.filter(ue=>!ue.ok),ve=U.filter(ue=>ue.ok).map(ue=>ue.id);xe&&ve.includes(xe)&&hs(ve),se.length>0?ce.error(`Failed to archive ${se.length} task(s): ${se.map(ue=>ue.error??ue.id).join(", ")}`):ce.success(`Archived ${ve.length} task(s)`),Oe(new Set(se.map(ue=>ue.id))),Re()}catch(U){ce.error(U instanceof Error?U.message:"Failed to archive tasks")}},[xe,Re,hs,Ke]),ki=o.useCallback(async()=>{const w=Array.from(Ke);if(w.length!==0)try{const{results:U}=await sc(w),se=U.filter(ue=>!ue.ok),ve=U.filter(ue=>ue.ok).map(ue=>ue.id);ve.length>0&&Ce(ve),xe&&ve.includes(xe)&&hs(ve,!0),se.length>0?ce.error(`Failed to delete ${se.length} task(s): ${se.map(ue=>ue.error??ue.id).join(", ")}`):ce.success(`Deleted ${ve.length} task(s)`),Oe(new Set(se.map(ue=>ue.id))),Re()}catch(U){ce.error(U instanceof Error?U.message:"Failed to delete tasks")}},[xe,Re,hs,Ce,Ke]),Si=o.useCallback(async()=>{ct(!0);try{await nc(),m()}catch(w){ce.error(w instanceof Error?w.message:"Failed to promote node")}finally{ct(!1)}},[m]),Ci=o.useCallback(async()=>{ge(!0);try{await rc(),ce.success("This node left the remote cluster and is leading itself again."),Re(),Ye(),m()}catch(w){ce.error(w instanceof Error?w.message:"Failed to leave cluster")}finally{ge(!1)}},[Ye,Re,m]),Ti=o.useCallback(async w=>{const U=!Hn(w),se=w.id===a?.self?.id,ve=se?i?.transportType??w.transportType:w.transportType,ue=se&&!U&&Ft(ve);Fe(w.id);try{ue?await ac("direct"):await oc(w.id,U),ce.success(U?`Enabled remote access on ${w.name}`:`Disabled remote access on ${w.name}`),m()}catch(Gt){ce.error(Gt instanceof Error?Gt.message:"Failed to update remote access")}finally{Fe(null)}},[a?.self?.id,m,i?.transportType]),Ei=o.useCallback(w=>{mt&&mt(w).catch(U=>{ce.error(U instanceof Error?U.message:"Failed to load completed tasks")})},[mt]),nr={toolbarTasks:rt,activeTaskId:xe,tasksLoading:pe,tasksError:qt,isLeader:je,scope:j,agentFilter:f,nodeFilter:y,taskKindFilter:b,agentOptions:Qo,nodeOptions:Yo,nodeNameById:er,nodeWorkDirById:Jo,nodeStatusById:Zo,leaderNodeId:a?.leader?.id??null,searchQuery:T,completedGroupByKey:Xo,devBoxNodeIds:yt,devBoxStartNodeIds:Qe,devBoxStartingNodeIds:nt,selectedTaskIds:Ke,allVisibleTasksSelected:si,someVisibleTasksSelected:ni,canBatchArchive:ri,onScopeChange:A,onAgentFilterChange:E,onNodeFilterChange:v,onTaskKindFilterChange:C,onToggleTaskSelected:yi,onToggleAllVisibleTasks:ji,onBatchArchive:Ni,onBatchDelete:ki,onCreateTask:Us,onOpenNodeSettings:je?K:void 0,onOpenNodeCapabilities:je?Ae:void 0,onOpenProjectCapabilities:je?wt:void 0,onOpenDevBox:je?dt:void 0,onStartDevBox:je?ut:void 0,onLoadCompletedTasks:Ei,onSelectTask:sr},Ai={cluster:a,systemInfo:i,nodeNameById:er,nodeBlockingTaskCounts:ls,eventTypeFilter:ae,onEventTypeFilterChange:G,activeTab:ie,onTabChange:he,eventTypeOptions:Ls,filteredEvents:ti,sseConnected:c,clusterLoading:p,clusterError:u,promotePending:lt,onPromote:Si,onAddNode:()=>W(!0),leavePending:ee,onLeaveCluster:Ci,onToggleNodeDevTunnel:Ti,devTunnelNodeId:ye,devBoxStartNodeId:Be,devBoxStartingNodeIds:nt,onOpenNodeSettings:je?K:void 0,onOpenNodeCapabilities:je?Ae:void 0,onOpenDevBox:je?dt:void 0,onStartDevBox:je?ut:void 0};return e.jsxs(e.Fragment,{children:[e.jsx(zu,{desktopTasksOpen:S,mobileTasksPanelOpen:I,mobileTasksPanelRef:_,operationsOpen:D,operationsPanelRef:R,panelResize:F,taskSidebar:e.jsx(fa,{...nr}),operationsSidecar:e.jsx(Dm,{...Ai}),terminalPanel:r?.terminalOpen?e.jsx(Wu,{nodes:tr,defaultNodeId:ei,onClose:()=>r?.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(_u,{onToggleTasks:X,desktopTasksOpen:S,mobileTasksPanelOpen:I,operationsOpen:D,onToggleOperations:()=>Y(w=>!w),cluster:a,sseConnected:c,activeTab:L,setActiveTab:oe,creatingTask:Z,createMode:V,createDefaults:g,activeTask:le,assignedNode:ai,taskLoading:xt,transcriptLoading:Ze,taskError:He,displayEvents:Fs,initialPromptAlreadyInLogs:di,initialPrompt:us,supportsFollowUp:oi,taskUnavailable:Os.taskUnavailable,chatDisabled:Os.chatDisabled,chatDisabledReason:Os.chatDisabledReason,questionBypassEnabled:M,isRunning:!!ds,isStarting:ii,hasPendingFollowUp:Bs,canCancel:!!li,canRetry:!!ci,onRetry:wi,onCancel:gi,onReloadNativeTranscript:xi,onShareTask:bi,onStopShareTask:vi,onStartCreateTask:Us,onCancelCreateTask:ui,onCreateTask:mi,onSendMessage:fi,onCancelQueuedMessage:hi,onQuestionBypassChange:ne,onSubmitQuestionResponse:pi,quickChats:zt}),mobileTaskSidebar:e.jsx(fa,{...nr,onCreateTask:(w,U)=>{Q(!1),Us(w,U)},onSelectTask:w=>{Q(!1),sr(w)}}),onCloseOperations:()=>Y(!1),onCloseTaskList:()=>Q(!1),onToggleOperations:()=>Y(w=>!w),onToggleTasks:X}),e.jsx(Ru,{open:z,onOpenChange:W,onAdded:m}),Ut,$t,ke]})}const ff=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:cf},Symbol.toStringTag,{value:"Module"}));export{to as A,ff as D,Ns as G};