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