meshy-node 0.10.7 → 0.10.8

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.
@@ -1,176 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-CXyf-FqN.js","assets/index-0SJFGvhq.js","assets/index-Br15-PXW.css","assets/MarkdownPreviewFrame-CFCsFLMN.js","assets/DashboardShared-BUUqTMMG.js","assets/file-Ct6iLy28.js","assets/PreviewTab-hYU-Sg4s.js","assets/DiffTab-BJ-QDAVa.js"])))=>i.map(i=>d[i]);
2
- import{c as ue,r as o,a as Ns,f as Ma,m as Pa,j as e,X as it,Q as kn,B as J,L as de,S as Ia,b as Ri,d as O,e as Li,g as Bi,h as Oi,I as ot,P as Fi,C as as,i as zi,k as Ra,F as Ui,l as Bt,n as st,o as De,D as os,p as $i,q as qi,t as ce,s as _e,u as Me,v as $e,w as Pe,x as La,y as Je,T as Vi,z as Hi,A as or,E as Ki,G as wt,H as yt,J as Tt,K as Ba,M as Oa,N as ls,O as zn,R as Gi,U as St,V as Wi,W as Sn,Y as Qi,Z as Un,_ as Fa,$ as Yi,a0 as Ve,a1 as Ji,a2 as ft,a3 as Yt,a4 as Jt,a5 as Zt,a6 as Xt,a7 as es,a8 as ts,a9 as ss,aa as ns,ab as $n,ac as Zi,ad as cs,ae as za,af as Xi,ag as ir,ah as Cn,ai as $s,aj as el,ak as tl,al as sl,am as nl,an as rl,ao as al,ap as Ua,aq as ds,ar as $a,as as ol,at as il,au as _s,av as ll,aw as qa,ax as cl,ay as dl,az as ul,aA as Va,aB as qn,aC as Ha,aD as ml,aE as ks,aF as hl,aG as lr,aH as Vn,aI as fl,aJ as xl,aK as pl,aL as gl,aM as Ka,aN as is,aO as bl,aP as Tn,aQ as Ga,aR as vl,aS as wl,aT as yl,aU as jl,aV as cr,aW as Nl,aX as kl,aY as qs,aZ as Sl,a_ as dr,a$ as Cl,b0 as Tl,b1 as El,b2 as ur,b3 as Al,b4 as Dl,b5 as En,b6 as _l,b7 as Ml,b8 as Wa,b9 as mr,ba as Qa,bb as Pl,bc as Il,bd as Rl,be as Ll,bf as Bl,bg as Ol,bh as Fl,bi as zl,bj as Ul,bk as $l,bl as ql,bm as Vl,bn as Hl,bo as Kl,bp as Gl,bq as Wl,br as Ql,bs as Yl,bt as Jl,bu as Zl,bv as Xl,bw as ec,bx as tc,by as sc,bz as nc,bA as rc,bB as ac,bC as oc,bD as ic,bE as lc,bF as cc,bG as dc,bH as uc}from"./index-0SJFGvhq.js";import{r as hr,e as mc,b as Ya,g as Ja,I as Za,A as Hn,a as Xa,c as eo,T as to,d as hc,i as so,f as fc,p as no,h as xc,t as pc,j as fr,k as xr,l as gc,m as bc,n as vc,C as pr,o as Vs,q as An,D as Mt,s as tt,M as Dn,L as wc,u as ro,v as _n,w as yc,x as jc,y as Nc,z as Hs,B as kc,E as Sc,F as Cc}from"./DashboardShared-BUUqTMMG.js";import{E as Tc,M as Ec}from"./MarkdownPreviewFrame-CFCsFLMN.js";import{P as Ms,D as gs,g as Ac,a as Dc,b as _c}from"./PreviewTab-hYU-Sg4s.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 Mc=[["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"}]],Pc=ue("archive",Mc);/**
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 Ic=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],gr=ue("arrow-right",Ic);/**
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 Rc=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],ao=ue("arrow-up",Rc);/**
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 Lc=[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M9 13a4.5 4.5 0 0 0 3-4",key:"10igwf"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M12 13h4",key:"1ku699"}],["path",{d:"M12 18h6a2 2 0 0 1 2 2v1",key:"105ag5"}],["path",{d:"M12 8h8",key:"1lhi5i"}],["path",{d:"M16 8V5a2 2 0 0 1 2-2",key:"u6izg6"}],["circle",{cx:"16",cy:"13",r:".5",key:"ry7gng"}],["circle",{cx:"18",cy:"3",r:".5",key:"1aiba7"}],["circle",{cx:"20",cy:"21",r:".5",key:"yhc1fs"}],["circle",{cx:"20",cy:"8",r:".5",key:"1e43v0"}]],oo=ue("brain-circuit",Lc);/**
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 Bc=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Ss=ue("chevron-left",Bc);/**
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 Oc=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]],br=ue("clock",Oc);/**
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 Fc=[["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"}]],zc=ue("earth",Fc);/**
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 Uc=[["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"}]],$c=ue("ellipsis-vertical",Uc);/**
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 qc=[["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"}]],Vc=ue("ellipsis",qc);/**
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 Hc=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],Ps=ue("folder-open",Hc);/**
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 Kc=[["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"}]],Gc=ue("funnel",Kc);/**
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 Wc=[["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"}]],Cs=ue("git-branch",Wc);/**
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 Qc=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],Yc=ue("globe",Qc);/**
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 Jc=[["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"}]],Ts=ue("history",Jc);/**
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 Zc=[["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"}]],Mn=ue("image-plus",Zc);/**
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 Xc=[["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"}]],ed=ue("laptop",Xc);/**
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 td=[["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"}]],Kn=ue("link-2",td);/**
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 sd=[["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"}]],nd=ue("list-ordered",sd);/**
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 rd=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M12 8v6",key:"1ib9pf"}],["path",{d:"M9 11h6",key:"1fldmi"}]],Is=ue("message-square-plus",rd);/**
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 ad=[["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"}]],io=ue("monitor-play",ad);/**
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 od=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],Ot=ue("pencil",od);/**
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 id=[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]],lo=ue("qr-code",id);/**
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 ld=[["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"}]],cd=ue("rotate-ccw",ld);/**
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 dd=[["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"}]],co=ue("rotate-cw",dd);/**
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 ud=[["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"}]],uo=ue("send",ud);/**
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 md=[["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"}]],Es=ue("share-2",md);/**
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 hd=[["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"}]],fd=ue("sliders-horizontal",hd);/**
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 xd=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],vr=ue("square",xd);/**
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 pd=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Ks=ue("triangle-alert",pd);/**
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 gd=[["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"}]],bd=ue("user-plus",gd);/**
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 vd=[["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"}]],wd=ue("wifi",vd);/**
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 yd=[["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"}]],jd=ue("zoom-in",yd);/**
163
- * @license lucide-react v1.7.0 - ISC
164
- *
165
- * This source code is licensed under the ISC license.
166
- * See the LICENSE file in the root directory of this source tree.
167
- */const Nd=[["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"}]],kd=ue("zoom-out",Nd),Sd=new Set(["assigned","running"]);function Cd(t,s){return t.reduce((n,r)=>r.assignedTo===s&&Sd.has(r.status)?n+1:n,0)}function Ft(t){return t?.toLowerCase()==="devtunnel"}function Td(t){return t?Ft(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function Gn(t,s){return Ft(s??t.transportType)||!!t.devtunnelEndpoint}function mo(t,s){return!Ft(s??t.transportType)}function ho(t,s){const n=s??t.transportType;return Ft(n)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":Td(n)}function wr(t,s){return!t&&!s}function Ed({routeTaskId:t,creatingTask:s,internalSelectedTaskId:n,sortedTaskIds:r}){return t||(s?null:r[0]??n??null)}function Ad({activeTaskId:t,routeTaskId:s,creatingTask:n,tasksLoading:r,loadedTaskIds:a}){return!t||s||n||r?!1:!a.includes(t)}function Dd(t,s){return[s,...t.filter(n=>n.id!==s.id)]}function fo(t,s){const n=t.findIndex(r=>r.id===s.id);return n===-1?[...t,s]:t.map((r,a)=>a===n?s:r)}const _d=new Set(["completed","failed","cancelled","archived"]);function Md(t,s){const n=new Set(s);return new Set(Array.from(t).filter(r=>n.has(r)))}function Pd(t,s){const n=new Set(s);if(n.size===0)return!1;const r=t.filter(a=>n.has(a.id));return r.length===n.size&&r.every(a=>_d.has(a.status))}function Id(t,s){const n=new Set(s);return t.find(r=>!n.has(r.id))?.id??null}function xo(){const[t,s]=o.useState([]),[n,r]=o.useState(null),a=o.useRef(null),i=o.useCallback(()=>{a.current?.click()},[]),l=o.useCallback(async g=>{const u=Array.from(g.target.files??[]);if(u.length!==0)try{const h=await hr(u);s(p=>[...p,...h]),r(null)}catch(h){r(h instanceof Error?h.message:"Failed to attach image")}finally{g.target.value=""}},[]),c=o.useCallback(async g=>{const u=mc(g.clipboardData);if(u.length!==0){g.preventDefault();try{const h=await hr(u);s(p=>[...p,...h]),r(null)}catch(h){r(h instanceof Error?h.message:"Failed to attach image")}}},[]),d=o.useCallback(g=>{s(u=>u.filter((h,p)=>p!==g))},[]),m=o.useCallback(()=>{s([]),r(null)},[]);return{images:t,error:n,fileInputRef:a,pickImages:i,handleFileChange:l,handlePaste:c,removeImage:d,clearImages:m}}function Rd(t){const s=t.map(a=>({...a,displayValue:Ld(a)})),n=s.findIndex(a=>a.label.toLowerCase()==="working dir"),r=n>=0?n:0;return{primary:s[r],secondary:s.filter((a,i)=>i!==r)}}function Ld(t){return t.label.toLowerCase()==="agent"?Xa(t.value):t.value}function yr(t){switch(t.toLowerCase()){case"branch":return Cs;case"node":return Ia;default:return Ps}}function Bd({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 Od({contentLength:t,disabled:s=!1}){return t>0&&!s}function Fd({onSend:t,disabled:s,disabledReason:n="Chat is waiting on the agent.",placeholder:r="Send a follow-up message...",contextItems:a=[],agent:i,model:l,running:c=!1,onStop:d,quickChats:m=[]}){const[g,u]=o.useState(""),[h,p]=o.useState(0),[k,j]=o.useState(0),A=o.useRef(null),{images:f,error:E,fileInputRef:y,pickImages:x,handleFileChange:b,handlePaste:C,removeImage:S,clearImages:P}=xo(),T=o.useCallback(()=>{A.current&&(A.current.style.height="auto")},[]),I=o.useCallback(()=>{A.current&&(A.current.style.height="auto",A.current.style.height=`${Math.min(A.current.scrollHeight,220)}px`)},[]);o.useEffect(()=>{p(0)},[g,m]);const _=o.useCallback(F=>{u(F.prompt);const v=()=>{A.current?.focus(),I()};typeof requestAnimationFrame=="function"?requestAnimationFrame(v):v()},[I]),D=o.useCallback(()=>{const F=Ns(g,m,h);if(F){_(F);return}const v=Ya(g,f);Od({contentLength:v.length,disabled:s})&&(j($=>$+1),t(v),u(""),P(),T())},[g,f,s,t,P,T,m,h,_]),L=o.useCallback(F=>{const v=Ma(g,m);if(v.length>0&&(F.key==="ArrowDown"||F.key==="ArrowUp")){F.preventDefault(),p($=>Pa($,v.length,F.key==="ArrowDown"?1:-1));return}if(F.key==="Enter"&&!F.shiftKey){F.preventDefault();const $=Ns(g,m,h);$?_($):D()}},[_,D,m,h,g]),z=g.trim().length>0||f.length>0,Y=Bd({disabled:s,running:c,canStop:c&&!!d,hasContent:z}),X=Rd(a),Z=X.primary?yr(X.primary.label):Ps,te=i?Ja(i,l):null,q=c?z?"Enter queues this message for the next turn":d?"Task is running - type to queue, empty button stops task":"Task is running - type to queue a message":s?n:"Enter sends, Shift+Enter adds a line";return e.jsx("div",{"data-chat-input-shell":"true",className:"chat-input-shell animate-composer-settle w-full bg-background/35 px-2 pb-2 pt-0 sm:px-4 sm:pb-3",children:e.jsx("div",{"data-chat-input-column":"true",className:"mx-auto w-full max-w-[72rem]",children:e.jsxs("div",{"data-chat-input-card":"true",className:"chat-input-card overflow-hidden rounded-xl border border-border/65 bg-card/88 transition-[border-color,box-shadow] duration-200 focus-within:border-primary/50 focus-within:ring-2 focus-within:ring-primary/15 sm:rounded-xl",children:[e.jsx("input",{ref:y,type:"file",accept:"image/*",multiple:!0,onChange:b,className:"hidden"}),X.primary&&e.jsx("div",{"data-chat-input-primary-context":"true",className:"px-2.5 pt-1.5 sm:px-5 sm:pt-2",children:e.jsxs("div",{className:"-ml-1.5 inline-flex max-w-full items-center gap-1.5 rounded-sm bg-muted/45 px-1.5 py-0.5 shadow-[0_10px_28px_-18px_rgba(15,23,42,0.72)] sm:-ml-2 dark:shadow-[0_10px_28px_-18px_rgba(0,0,0,0.95)]",children:[e.jsx(Z,{className:"h-2.5 w-2.5 shrink-0 text-primary/45","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[9px] leading-3 text-muted-foreground/72",title:X.primary.value,children:X.primary.displayValue})]})}),f.length>0&&e.jsx("div",{className:"px-2 pt-2.5 sm:px-5 sm:pt-4",children:e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map((F,v)=>e.jsxs("div",{className:"relative",children:[e.jsx(Za,{image:F,alt:F.filename??`attachment ${v+1}`,thumbnailClassName:"h-24 w-24 border border-border/70",imageClassName:"h-full w-full"}),e.jsx("button",{type:"button",onClick:()=>S(v),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 ${F.filename??`image ${v+1}`}`,children:e.jsx(it,{className:"h-3 w-3"})})]},`${F.filename??"image"}-${v}`))})}),e.jsx("div",{className:"px-2 pb-0 pt-1 sm:px-5 sm:pt-1.5",children:e.jsx("textarea",{ref:A,"data-chat-input-textarea":"true",value:g,onChange:F=>u(F.target.value),onKeyDown:L,onPaste:C,onInput:I,placeholder:r,disabled:s,rows:1,className:"min-h-[1.35rem] w-full resize-none overflow-x-hidden overflow-y-auto bg-transparent px-0 py-0 text-[11px] leading-[1.35rem] text-foreground placeholder:text-[10px] placeholder:text-muted-foreground/65 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50"})}),e.jsx(kn,{query:g,quickChats:m,selectedIndex:h,onActiveIndexChange:p,onSelect:_}),e.jsxs("div",{className:"flex items-end justify-between gap-2 px-2 pb-1.5 pt-0.5 sm:px-5 sm:pb-2.5",children:[X.secondary.length>0?e.jsx("div",{"data-chat-input-secondary-context":"true",className:"flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 pb-0.5 text-[9px] leading-3 text-muted-foreground/72 sm:text-[9px]",children:X.secondary.map(F=>{const v=yr(F.label),$=F.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${F.label}: ${F.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[$?e.jsx(Hn,{agent:F.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(v,{"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 ${F.mono?"font-mono":""}`,children:F.displayValue})]},`${F.label}:${F.value}`)})}):e.jsx("div",{className:"min-w-0 flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[te&&e.jsxs("span",{"data-chat-input-model-display":"true","aria-label":`Model: ${te}`,title:`Model: ${te}`,className:"inline-flex h-7 max-w-[9rem] shrink-0 items-center gap-1.5 truncate rounded-sm px-2 text-[10px] text-muted-foreground",children:[e.jsx(oo,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),te]}),e.jsxs(J,{type:"button",variant:"ghost",onClick:x,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(Mn,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:q,children:e.jsx(J,{onClick:Y.primaryAction==="stop"?d:D,disabled:Y.primaryDisabled,size:"icon","data-chat-send-button":"true","aria-label":Y.primaryAction==="stop"?"Stop running task":c?"Queue message":"Send message",className:"chat-send-button h-7 w-9 shrink-0 rounded-sm bg-primary/90 text-primary-foreground shadow-[0_12px_30px_-18px_hsl(var(--primary)/0.95)] transition-transform duration-150 hover:bg-primary active:scale-95",children:Y.primaryAction==="stop"?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(uo,{className:`h-3.5 w-3.5 ${k>0?"animate-chat-send-flight":""}`},k)})})]})]}),E&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-2 py-2 text-[11px] text-destructive sm:px-6 sm:py-3",children:E})]})})})}var zd=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ud=zd.reduce((t,s)=>{const n=Ri(`Primitive.${s}`),r=o.forwardRef((a,i)=>{const{asChild:l,...c}=a,d=l?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(d,{...c,ref:i})});return r.displayName=`Primitive.${s}`,{...t,[s]:r}},{}),$d="Label",po=o.forwardRef((t,s)=>e.jsx(Ud.label,{...t,ref:s,onMouseDown:n=>{n.target.closest("button, input, select, textarea")||(t.onMouseDown?.(n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));po.displayName=$d;var go=po;const qd=Li("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ge=o.forwardRef(({className:t,...s},n)=>e.jsx(go,{ref:n,className:O(qd(),t),...s}));Ge.displayName=go.displayName;function jr({agent:t,query:s,onSelect:n}){const r=eo(t,s);return r?e.jsx("div",{"data-codex-goal-command":"true",className:"mx-2 mb-0.5 rounded-sm bg-background/70 p-0.5 shadow-none sm:mx-5",children:e.jsx("div",{role:"listbox","aria-label":"Codex commands",children:e.jsxs("button",{type:"button",role:"option","aria-selected":"true",onClick:n,className:"flex h-8 w-full min-w-0 items-center gap-2 rounded-sm px-2 text-left transition-colors hover:bg-muted/50 hover:text-foreground",children:[e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-primary",children:e.jsx(to,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx("span",{className:"shrink-0 text-[11px] font-medium text-foreground",children:r.label}),e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:r.description})]})})}):null}function Vd(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function Hd(t){return t.trim()||"."}function Kd(t){return new Promise(s=>window.setTimeout(s,t))}function Gd(t){return!!t&&typeof t=="object"&&typeof t.createdBranch=="string"&&typeof t.currentBranch<"u"}async function Wd(t){let s=t;for(let n=0;n<60;n++){if(s.status==="succeeded"){if(Gd(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 Kd(1e3),s=await zi(s.id)}throw new Error("Timed out waiting for branch creation")}function Nr({value:t,onChange:s,project:n,assignTo:r,nodes:a,assignableNodes:i,layout:l="default",chipClassName:c,chipActiveClassName:d,chipInactiveClassName:m,labelClassName:g,triggerClassName:u}){const[h,p]=o.useState(!1),[k,j]=o.useState(null),[A,f]=o.useState(""),[E,y]=o.useState(!1),[x,b]=o.useState(!1),[C,S]=o.useState(!1),[P,T]=o.useState(null),[I,_]=o.useState(""),[D,L]=o.useState(""),[z,Q]=o.useState(""),[Y,X]=o.useState(!1),Z=o.useRef(null),te=o.useRef(0),q=o.useMemo(()=>Vd(r,a,i),[r,a,i]),F=q?.id,v=o.useMemo(()=>Hd(n),[n]),$=o.useMemo(()=>F?`${F}
168
- ${v}`:"",[F,v]),N=o.useCallback(async(ae=0,G=!1)=>{const M=te.current+1,ne=$;if(te.current=M,!F){j(null),f("");return}T(null),G||f(""),G?b(!0):y(!0);try{const V=await Bi(F,{path:v,limit:20,offset:ae,allowAbsolute:!0});if(M!==te.current)return;f(ne),j(re=>G&&re?{...V,branches:[...re.branches,...V.branches]}:V)}catch(V){if(M!==te.current)return;T(V instanceof Error?V.message:"Failed to load branch info"),G||(j(null),f(""))}finally{M===te.current&&(y(!1),b(!1))}},[F,$,v]);o.useEffect(()=>{if(!F){te.current+=1,j(null),f(""),T(null);return}N()},[F,v,N]),o.useEffect(()=>{const ae=t.trim(),G=A===$?k:null,M=G?.available&&G.currentBranch?G.currentBranch:"";ae!==M&&s(M)},[k,$,A,s,t]),o.useEffect(()=>{if(!h)return;const ae=M=>{Z.current&&(Z.current.contains(M.target)||p(!1))},G=M=>{M.key==="Escape"&&p(!1)};return document.addEventListener("mousedown",ae),document.addEventListener("keydown",G),()=>{document.removeEventListener("mousedown",ae),document.removeEventListener("keydown",G)}},[h]),o.useEffect(()=>{h&&(L(""),Q(""),X(!1))},[h,F,v]);const W=o.useCallback(async()=>{if(!F)return;const ae=I.trim(),G=Y?z.trim():D.trim();if(!(!ae||!G)){S(!0),T(null);try{const M=await Oi(F,{path:v,branchName:ae,startPoint:G,limit:20,offset:0,allowAbsolute:!0}),ne=await Wd(M);f($),j(ne),s(ne.currentBranch??ne.createdBranch),_(""),L(""),Q(""),X(!1),p(!1)}catch(M){T(M instanceof Error?M.message:"Failed to create branch")}finally{S(!1)}}},[F,$,v,Y,z,I,s,D]),R=A===$?k:null,K=o.useCallback(()=>{R?.hasMore&&N(R.branches.length,!0)},[R,N]),B=t.trim()||R?.currentBranch||(R&&!R.available?"No git repo":"Branch"),oe=Y?z.trim():D.trim(),ie=!!(R?.available&&I.trim()&&oe&&!C),he=l==="composer"?e.jsxs(J,{type:"button",variant:"ghost",onClick:()=>p(ae=>!ae),title:B,"aria-label":`Branch: ${B}`,className:O(c,u,"min-w-0 max-w-full",t.trim()?d:m),children:[E&&!R?e.jsx(de,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(Cs,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:O("min-w-0 truncate",g),children:B})]}):e.jsxs(J,{type:"button",variant:"outline",onClick:()=>p(ae=>!ae),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:B,children:[e.jsx("span",{className:O("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:B}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:q?q.name:"Manual"})]});return e.jsxs("div",{className:O("relative inline-block",l==="composer"?"min-w-0 shrink-0":"w-full"),ref:Z,children:[l==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[10px] font-medium",children:"Branch"}),he]}):he,h&&e.jsxs("div",{className:O("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-sm border border-border/60 bg-background/95 shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",l==="composer"?"left-0":"left-0 right-0 w-auto min-w-[240px]"),children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsx(Cs,{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:R?.repoRoot?`${R.currentBranch??B} · ${R.repoRoot}`:R?.currentBranch??B,children:R?.currentBranch??B}),E?e.jsx(de,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),q?E&&!R?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(de,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):R&&!R.available?e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Not a git repository."}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2 px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{value:I,onChange:ae=>_(ae.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(J,{type:"button",size:"sm",onClick:()=>{W()},disabled:!ie,title:ie?"Create branch":"Enter a name and pick a base","aria-label":"Create branch",className:"h-8 w-8 shrink-0 rounded-sm p-0",children:C?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Fi,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Base from"}),!Y&&e.jsxs("button",{type:"button",onClick:()=>X(!0),className:"flex items-center gap-1 rounded-sm px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx(Ot,{className:"h-2.5 w-2.5"}),"Manual"]})]}),Y?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ot,{value:z,onChange:ae=>Q(ae.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{X(!1),Q("")},className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel manual input","aria-label":"Cancel manual input",children:e.jsx(it,{className:"h-3.5 w-3.5"})})]}):R?.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-sm border border-border/40 bg-background/40",children:[R.branches.map(ae=>{const G=D===ae.ref,M=ae.branch==="main"||ae.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>L(ae.ref),className:O("flex w-full items-center gap-2 border-b border-border/20 px-2.5 py-1.5 text-left text-[11px] last:border-b-0 hover:bg-background/60",G&&"bg-background/70"),title:ae.ref,children:[e.jsx("span",{className:O("shrink-0 text-[10px]",M?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:M?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:ae.ref}),G?e.jsx(as,{className:"h-3 w-3 shrink-0 text-primary"}):null]},ae.ref)}),R.hasMore&&e.jsxs("button",{type:"button",onClick:K,disabled:x,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:[x?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Ts,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"rounded-sm border border-dashed border-border/40 px-2.5 py-2 text-[11px] text-muted-foreground",children:"No remote branches found."})]})]})}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a specific node first."}),P&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:P})]})]})}const Qd=20,Yd=3,Pn="meshy-working-dir-recents-by-node";function Jd(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function Zd(t){const s=t.trim();return s||"."}function In(t){const s=[],n=new Set;for(const r of t){const a=r.trim();if(!(!a||n.has(a))&&(n.add(a),s.push(a),s.length===Yd))break}return s}function Xd(t,s){const n=s.trim();return In(n?[n,...t]:t)}function bo(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const s={};for(const[n,r]of Object.entries(t)){if(!n||!Array.isArray(r))continue;const a=r.filter(l=>typeof l=="string"),i=In(a);i.length>0&&(s[n]=i)}return s}function eu(t,s,n){if(!s)return t;const r=t[s]??[],a=Xd(r,n);if(a.length===0){if(!(s in t))return t;const{[s]:i,...l}=t;return l}return{...t,[s]:a}}function tu(t,s){return s?t[s]?.[0]??"":""}function vo(t){if(!t||typeof window>"u")return"";try{const s=window.localStorage.getItem(Pn);return s?tu(bo(JSON.parse(s)),t):""}catch{return""}}function su(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function nu(t,s){const n=s.trim();return n?Jd(n)||!t?n:`${t.replace(/[/\\]+$/,"")}/${n}`:""}function ru(t,s){return t?t.isAbsolute?t.currentPath:t.currentPath==="."||t.currentPath===""?t.rootPath||s?.workDir||"Node root":t.currentPath:s?.workDir??"Node root"}function As({value:t,onChange:s,assignTo:n,nodes:r,assignableNodes:a,layout:i="default",chipClassName:l,chipActiveClassName:c,chipInactiveClassName:d,labelClassName:m,triggerClassName:g,popoverPlacement:u="bottom",popoverAlign:h="start"}){const[p,k]=o.useState(!1),[j,A]=o.useState(null),[f,E]=o.useState(!1),[y,x]=o.useState(!1),[b,C]=o.useState(null),[S,P]=o.useState(""),[T,I]=o.useState(!1),[_,D]=o.useState({}),L=o.useRef(null),z=o.useMemo(()=>su(n,r,a),[n,r,a]),Q=z?.id,Y=o.useMemo(()=>Q?_[Q]??[]:[],[_,Q]),X=o.useMemo(()=>t.trim()?nu(z?.workDir,t):"Use node default",[t,z?.workDir]);o.useEffect(()=>{if(!(typeof window>"u"))try{const B=window.localStorage.getItem(Pn);if(!B)return;const oe=JSON.parse(B);D(bo(oe))}catch{}},[]);const Z=o.useCallback(B=>{Q&&D(oe=>{const ie=eu(oe,Q,B);if(ie===oe)return oe;if(typeof window<"u")try{window.localStorage.setItem(Pn,JSON.stringify(ie))}catch{}return ie})},[Q]),te=o.useCallback((B,oe=!0)=>{const ie=B.trim();s(ie),oe&&ie&&Z(ie),k(!1)},[s,Z]),q=o.useCallback(async(B,oe=0,ie=!1)=>{if(Q){C(null),ie?x(!0):E(!0);try{const he=await Ra(Q,{path:B,limit:Qd,offset:oe,directoriesOnly:!0,allowAbsolute:!0});A(ae=>ie&&ae?{...he,entries:[...ae.entries,...he.entries]}:he)}catch(he){C(he instanceof Error?he.message:"Failed to browse directories"),ie||A(null)}finally{E(!1),x(!1)}}},[Q]),F=o.useRef(t);F.current=t;const v=o.useRef(q);v.current=q,o.useEffect(()=>{if(!p)return;const B=F.current;P(B),I(!1),A(null),C(null),Q&&v.current(Zd(B))},[p,Q]),o.useEffect(()=>{if(!p)return;const B=ie=>{L.current&&(L.current.contains(ie.target)||k(!1))},oe=ie=>{ie.key==="Escape"&&k(!1)};return document.addEventListener("mousedown",B),document.addEventListener("keydown",oe),()=>{document.removeEventListener("mousedown",B),document.removeEventListener("keydown",oe)}},[p]);const $=o.useCallback(B=>{q(B)},[q]),N=o.useCallback(()=>{j&&q(j.currentPath,j.entries.length,!0)},[j,q]),W=i==="composer"?e.jsxs(J,{type:"button",variant:"ghost",onClick:()=>k(B=>!B),title:X,"aria-label":`Working directory: ${X}`,className:O(l,g,"min-w-0 max-w-full",t.trim()?c:d),children:[e.jsx(Ui,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:O("min-w-0 truncate",m),children:X})]}):e.jsxs(J,{type:"button",variant:"outline",onClick:()=>k(B=>!B),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:X,children:[e.jsx("span",{className:O("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:X}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:z?z.name:"Manual"})]}),R=ru(j,z),K=!!j?.parentPath;return e.jsxs("div",{className:O("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":u,"data-workdir-popover-align":h,ref:L,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[10px] font-medium",children:"Working directory"}),W]}):W,p&&e.jsxs("div",{className:O("absolute z-50 flex max-h-[min(28rem,calc(100vh-5rem))] w-[240px] flex-col overflow-hidden rounded-sm border border-border/60 bg-background/95 shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",u==="top"?"bottom-full mb-2":"top-full mt-2",i==="composer"?h==="end"?"right-0":"left-0":h==="end"?"right-0 w-auto min-w-[240px]":"left-0 right-0 w-auto min-w-[240px]"),children:[Y.length>0&&e.jsxs("div",{className:"border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx(Ts,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:Y.map(B=>e.jsx("button",{type:"button",onClick:()=>te(B),className:"truncate rounded-sm px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:B,children:B},B))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border/60 px-2.5 py-1.5",children:[e.jsx("button",{type:"button",onClick:()=>j?.parentPath&&$(j.parentPath),disabled:!K||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(ao,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:R,children:R}),j&&e.jsx("button",{type:"button",onClick:()=>te(j.isAbsolute?j.currentPath:j.currentPath==="."?"":j.currentPath),className:"shrink-0 rounded-sm px-1.5 py-0.5 text-[10px] font-medium text-foreground hover:bg-background/60",title:"Use this folder",children:"Use"})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[z?f?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(de,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):j&&j.entries.length>0?e.jsxs(e.Fragment,{children:[j.entries.map(B=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>te(B.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 ${B.path}`,children:[e.jsx(Bt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:B.name})]}),e.jsx("button",{type:"button",onClick:()=>$(B.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 ${B.name}`,children:e.jsx(st,{className:"h-3.5 w-3.5"})})]},B.path)),j.hasMore&&e.jsxs("button",{type:"button",onClick:N,disabled:y,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[y?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Ts,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:b??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),b&&j&&j.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:b})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:T?e.jsxs(e.Fragment,{children:[e.jsx(ot,{value:S,onChange:B=>P(B.target.value),onKeyDown:B=>{B.key==="Enter"&&S.trim()?(B.preventDefault(),te(S)):B.key==="Escape"&&(B.preventDefault(),I(!1),P(t))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>te(S),disabled:!S.trim(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-foreground hover:bg-background/60 disabled:opacity-40",title:"Apply","aria-label":"Apply manual path",children:e.jsx(as,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{I(!1),P(t)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(it,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{P(t),I(!0)},className:"flex h-7 flex-1 items-center justify-between rounded-sm px-1.5 text-[11px] text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Enter a manual path",children:[e.jsx("span",{children:"Manual input"}),e.jsx(Ot,{className:"h-3 w-3"})]})})]})]})}function wo(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 Wn({isCurrent:t}){return t?e.jsx(ed,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Yc,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function Rn(t,s){return t.map(n=>{const r=!!s&&n.id===s;return e.jsx(De,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Wn,{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 au(t){const s=t.sessionId.trim(),n=t.cwd.trim();return!s||!n||!t.assignTo?null:{title:t.title.trim()||t.defaultTitle?.trim()||void 0,agent:t.agent,sessionId:s,cwd:n,assignTo:t.assignTo,priority:t.priority,mode:t.mode??os}}function ou(){return Vi.map(t=>e.jsx(De,{value:t.value,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:t.label}),t.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:t.description})]})},t.value))}function iu(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 kr(t){if(!t.updatedAt)return 0;const s=Date.parse(t.updatedAt);return Number.isNaN(s)?0:s}function lu(t,s){return kr(s)-kr(t)||t.sessionId.localeCompare(s.sessionId)}function cu(t){const s=t.trim().replace(/[\\/]+$/,"");return s?s.split(/[\\/]+/).filter(Boolean).at(-1)??s:"Unknown project"}function du(t){const s=new Map;for(const n of[...t].sort(lu)){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:cu(n),cwd:n,sessions:r}))}function uu(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function mu({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:a,onCancel:i,className:l,footerClassName:c,submitLabel:d="Load session",cancelLabel:m="Cancel",autoFocus:g=!1}){const u=o.useMemo(()=>wo(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),h=o.useMemo(()=>n&&u.some(M=>M.id===n)?n:u[0]?.id??"",[u,n]),[p,k]=o.useState(""),[j,A]=o.useState("codex"),[f,E]=o.useState(""),[y,x]=o.useState(""),[b,C]=o.useState(""),[S,P]=o.useState(h),[T,I]=o.useState(os),[_,D]=o.useState(!1),[L,z]=o.useState([]),[Q,Y]=o.useState(!1),[X,Z]=o.useState(null),te=o.useMemo(()=>L.find(M=>M.sessionId===f)??null,[L,f]);o.useEffect(()=>{S&&u.some(M=>M.id===S)||P(h)},[S,u,h]),o.useEffect(()=>{E(""),x(""),C("")},[j,S]),o.useEffect(()=>{let M=!1;return S?(Y(!0),Z(null),$i(S,{agent:j,limit:50}).then(ne=>{M||z(ne.sessions)}).catch(ne=>{M||(z([]),Z(ne instanceof Error?ne.message:"Failed to load native sessions"))}).finally(()=>{M||Y(!1)}),()=>{M=!0}):(z([]),Z(null),Y(!1),()=>{M=!0})},[j,S]),o.useEffect(()=>{te&&(x(te.sessionId),C(te.cwd))},[te]);const q=o.useCallback(async M=>{M.preventDefault();const ne=au({title:p,defaultTitle:te?.summary,agent:j,sessionId:y,cwd:b,assignTo:S,priority:"normal",mode:T});if(ne){D(!0);try{const V=await qi(ne);a(V)}catch(V){ce.error(V instanceof Error?V.message:"Failed to load native session")}finally{D(!1)}}},[p,te,j,y,b,S,T,a]),F=!!(y.trim()&&b.trim()&&S),[v,$]=o.useState(!1),[N,W]=o.useState(""),[R,K]=o.useState(()=>new Set),B=u.find(M=>M.id===S)??null,oe=!!(n&&B?.id===n),ie=o.useMemo(()=>{const M=N.trim().toLowerCase();return M?L.filter(ne=>ne.summary.toLowerCase().includes(M)||ne.sessionId.toLowerCase().includes(M)||ne.cwd.toLowerCase().includes(M)):L},[L,N]),he=o.useMemo(()=>du(ie),[ie]),ae=o.useCallback(M=>{K(ne=>uu(ne,M))},[]),G="h-9 w-auto gap-1.5 rounded-sm border-border/60 bg-background/60 px-3 text-xs shadow-none transition-colors hover:bg-background/80";return e.jsxs("form",{onSubmit:q,className:O("space-y-4",l),children:[e.jsxs("div",{className:"rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/50 px-3 py-2.5",children:[e.jsxs(_e,{value:S,onValueChange:P,children:[e.jsx(Me,{className:O(G),"aria-label":"Node",children:B?e.jsxs(e.Fragment,{children:[e.jsx(Wn,{isCurrent:oe}),e.jsx("span",{className:"max-w-[10rem] truncate",children:B.name})]}):e.jsx($e,{placeholder:"Node"})}),e.jsx(Pe,{children:Rn(u,n)})]}),e.jsxs(_e,{value:j,onValueChange:M=>A(M),children:[e.jsxs(Me,{className:O(G),"aria-label":"Agent",children:[e.jsx(Hn,{agent:j}),e.jsx("span",{children:j})]}),e.jsx(Pe,{children:hc()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(La,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ot,{value:N,onChange:M=>W(M.target.value),placeholder:"Filter sessions",className:"h-9 rounded-sm border-border/60 bg-background/60 pl-9 text-xs shadow-none"})]})]}),e.jsxs("div",{className:"px-3 py-3",children:[e.jsx("div",{className:"flex items-center justify-between px-1 pb-2",children:e.jsx(Ge,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:Q?"Loading...":`${ie.length} session${ie.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-sm",children:[Q&&e.jsx("div",{className:"absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden bg-primary/10",children:e.jsx("div",{className:"h-full w-1/3 animate-indeterminate-bar bg-primary/70"})}),e.jsxs("div",{className:"h-full space-y-1.5 overflow-y-auto pr-1",children:[!S&&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."}),S&&!Q&&ie.length===0&&e.jsx("div",{className:"rounded-sm border border-dashed border-border/60 bg-background/35 px-3 py-4 text-center text-[11px] text-muted-foreground",children:L.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),he.map(M=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>ae(M.cwd),"aria-expanded":!R.has(M.cwd),className:"sticky top-0 z-[1] flex w-full items-center gap-2 border-b border-border/50 bg-background/95 px-1 py-1.5 text-left text-[10px] text-muted-foreground backdrop-blur transition-colors hover:bg-background",children:[e.jsx(Je,{className:O("h-3.5 w-3.5 shrink-0 transition-transform",R.has(M.cwd)&&"-rotate-90")}),e.jsx(Ps,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:M.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[M.sessions.length," session",M.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:M.cwd})]}),!R.has(M.cwd)&&M.sessions.map(ne=>{const V=ne.sessionId===f;return e.jsxs("button",{type:"button",onClick:()=>E(ne.sessionId),className:O("flex w-full flex-col gap-1 rounded-sm border px-2.5 py-2 text-left transition-colors duration-200",V?"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:O("h-2 w-2 shrink-0 rounded-full",V?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:ne.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:iu(ne.updatedAt)})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-4 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"font-mono",children:ne.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:ne.cwd})]})]},ne.sessionId)})]},M.cwd))]})]}),X&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:X})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>$(M=>!M),className:"inline-flex h-6 items-center gap-1.5 rounded-sm px-1.5 text-[10px] font-medium uppercase tracking-[0.16em] text-muted-foreground transition-colors hover:bg-muted/45 hover:text-foreground","aria-expanded":v,children:[e.jsx("span",{className:"shrink-0",children:v?"Less options":"More options"}),e.jsx(Je,{className:O("h-3.5 w-3.5 shrink-0 transition-transform",v&&"rotate-180")})]}),v&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/30 p-2.5",children:[e.jsxs("div",{className:"grid gap-2.5 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Ge,{htmlFor:"native-session-id",className:"text-[10px] font-medium text-muted-foreground",children:"Session ID"}),e.jsx(ot,{id:"native-session-id",type:"text",value:y,onChange:M=>{E(""),x(M.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:g,className:"h-7 rounded-sm border-border/70 bg-background/70 font-mono text-[11px] shadow-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Ge,{htmlFor:"native-session-title",className:"text-[10px] font-medium text-muted-foreground",children:"Task title"}),e.jsx(ot,{id:"native-session-title",type:"text",value:p,onChange:M=>k(M.target.value),placeholder:"Optional",className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none"})]})]}),e.jsx(As,{value:b,onChange:M=>{E(""),C(M)},assignTo:S,nodes:t,assignableNodes:u}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Ge,{className:"text-[10px] font-medium text-muted-foreground",children:"Mode"}),e.jsxs(_e,{value:T,onValueChange:M=>I(M),children:[e.jsx(Me,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx($e,{placeholder:"Select mode"})}),e.jsx(Pe,{children:ou()})]})]})]})]}),e.jsxs("div",{className:O("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",c),children:[i&&e.jsx(J,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:m}),e.jsx(J,{type:"submit",disabled:!F||_,className:"rounded-sm px-5",children:_?e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-4 w-4 animate-spin"})," Loading..."]}):d})]})]})}const Gs="__agent-default__";function yo({agent:t,value:s,onChange:n,triggerClassName:r,contentClassName:a="max-h-80",chip:i=!1}){const l=Ja(t,s);return o.useEffect(()=>{s&&!so(t,s)&&n("")},[t,s,n]),e.jsxs(_e,{value:s||Gs,onValueChange:c=>n(c===Gs?"":c),children:[e.jsx(Me,{"aria-label":`Model: ${l}`,title:`Model: ${l}`,className:r,children:i?e.jsxs(e.Fragment,{children:[e.jsx(oo,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:l})]}):e.jsx($e,{placeholder:"Agent default"})}),e.jsxs(Pe,{className:a,children:[e.jsx(De,{value:Gs,className:"py-1 text-[11px]",children:"Agent default"}),fc(t)]})]})}function hu(t){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[11px] font-medium",children:"Model"}),e.jsx(yo,{...t,triggerClassName:"h-8 rounded-sm border-border/70 bg-background/70"})]})}function jo(t,s,n=!1){const r=t.trim();if(r)return r;const a=s.trim().split(`
169
- `).map(i=>i.trim()).find(Boolean);return a?a.length>72?`${a.slice(0,69).trimEnd()}...`:a:n?"Image task":""}function fu(t){const s=t.title.trim(),n=no(t.agent,t.description),r=n.prompt,a=jo(t.title,r,t.images.length>0),i=r.trim()||a,l=t.mode??os,c=t.model?.trim(),d=c&&so(t.agent,c)?c:"",m=n.isGoal?n.commandPrompt:r,g=Ya(m,t.images);return!a||!i||!t.agent?null:{title:a,description:i,agent:t.agent,project:t.project.trim()||null,branch:t.branch?.trim()||null,payload:{initialMessage:g,mode:l,...d?{model:d}:{},...n.isGoal?{goal:!0}:{},titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function xu({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,className:d,footerClassName:m,submitLabel:g="Create chat",cancelLabel:u="Cancel",autoFocus:h=!1,layout:p="default",quickChats:k=[]}){const[j,A]=o.useState(""),[f,E]=o.useState(""),[y,x]=o.useState(0),[b,C]=o.useState(or),[S,P]=o.useState(""),[T,I]=o.useState(os),[_,D]=o.useState(i?.trim()??""),L=o.useRef(i!==void 0),[z,Q]=o.useState(""),Y=o.useMemo(()=>wo(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),X=o.useMemo(()=>a&&Y.some(ee=>ee.id===a)?a:n&&Y.some(ee=>ee.id===n)?n:Y[0]?.id??"",[Y,n,a]),[Z,te]=o.useState(X),[q,F]=o.useState(!1),[v,$]=o.useState(!1),{images:N,error:W,fileInputRef:R,pickImages:K,handleFileChange:B,handlePaste:oe,removeImage:ie}=xo(),he=o.useRef(null),ae=o.useMemo(()=>Y.find(ee=>ee.id===Z)??null,[Z,Y]),G=!!(n&&ae?.id===n),M=Xa(b),ne=xc(T),V=o.useMemo(()=>no(b,f),[b,f]),re=o.useMemo(()=>eo(b,f),[b,f]),we=V.prompt,fe=o.useMemo(()=>V.isGoal||re?[]:k,[V.isGoal,re,k]);o.useEffect(()=>{Z&&Y.some(ee=>ee.id===Z)||te(X)},[Z,Y,X]),o.useEffect(()=>{if(L.current){L.current=!1;return}D(vo(Z)),Q("")},[Z]),o.useEffect(()=>{Q("")},[_]),o.useEffect(()=>{x(0)},[f,k,b]);const Ie=o.useCallback(ee=>{E(ee.prompt)},[]),Ee=o.useCallback(()=>{E(re?.value??"/goal "),x(0),!(typeof window>"u")&&window.setTimeout(()=>{const ee=he.current;ee?.focus();const ge=ee?.value.length??0;ee?.setSelectionRange(ge,ge)},0)},[re]),xt=o.useCallback(async ee=>{if(ee.preventDefault(),re){Ee();return}const ge=Ns(f,fe,y);if(ge){Ie(ge);return}const ye=fu({title:j,description:f,agent:b,model:S,project:_,branch:z,priority:"normal",assignTo:Z,mode:T,images:N});if(ye){F(!0);try{const Fe=await Ki(ye);l(Fe)}catch(Fe){ce.error(Fe instanceof Error?Fe.message:"Failed to create task")}finally{F(!1)}}},[j,f,b,S,_,z,Z,T,N,l,fe,y,Ie,re,Ee]),Le=jo(j,we,N.length>0),Ze=!re&&!!(Le&&b&&Z&&(we.trim()||N.length>0)),Se=o.useCallback(ee=>{if(ee.nativeEvent.isComposing)return;if(re&&(ee.key==="ArrowDown"||ee.key==="ArrowUp")){ee.preventDefault();return}const ge=Ma(f,fe);if(ge.length>0&&(ee.key==="ArrowDown"||ee.key==="ArrowUp")){ee.preventDefault(),x(ye=>Pa(ye,ge.length,ee.key==="ArrowDown"?1:-1));return}if(ee.key==="Enter"){if(re&&!ee.shiftKey){ee.preventDefault(),Ee();return}const ye=Ns(f,fe,y);if(ye&&!ee.shiftKey){ee.preventDefault(),Ie(ye);return}}ee.key==="Enter"&&(ee.ctrlKey||ee.metaKey)&&Ze&&!q&&(ee.preventDefault(),ee.currentTarget.form?.requestSubmit())},[Ee,Ie,fe,Ze,f,re,y,q]),He=N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:N.map((ee,ge)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:pc(ee),alt:ee.filename??`attachment ${ge+1}`,className:"h-20 w-20 rounded-sm border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>ie(ge),className:"absolute -top-2 -right-2 flex h-6 w-6 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${ee.filename??`image ${ge+1}`}`,children:e.jsx(it,{className:"h-3.5 w-3.5"})})]},`${ee.filename??"image"}-${ge}`))}),We=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[11px] font-medium",children:"Assign to"}),e.jsxs(_e,{value:Z,onValueChange:te,children:[e.jsx(Me,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select node"})}),e.jsx(Pe,{children:Rn(Y,n)})]})]}),Ke=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[11px] font-medium",children:"Agent"}),e.jsxs(_e,{value:b,onValueChange:C,children:[e.jsx(Me,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select agent"})}),e.jsx(Pe,{children:fr()})]})]}),Oe=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{className:"text-[11px] font-medium",children:"Mode"}),e.jsxs(_e,{value:T,onValueChange:ee=>I(ee),children:[e.jsx(Me,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select mode"})}),e.jsx(Pe,{children:xr()})]})]}),lt=e.jsx(As,{value:_,onChange:D,assignTo:Z,nodes:t,assignableNodes:Y}),ct=e.jsx(Nr,{value:z,onChange:Q,project:_,assignTo:Z,nodes:t,assignableNodes:Y});return p==="composer"?e.jsxs("form",{onSubmit:xt,className:O("space-y-4",d),children:[e.jsx("input",{ref:R,type:"file",accept:"image/*",multiple:!0,onChange:B,className:"hidden"}),(()=>{const ee="chat-composer__chip h-9 min-w-0 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors [&>span]:min-w-0",ge="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",ye="border-border/70 bg-background/55 text-foreground",Fe=b===or,ze=T===os;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"chat-composer__card rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",children:[e.jsxs("div",{className:"chat-composer__header flex min-w-0 items-center justify-between gap-3 px-4 pt-3",children:[e.jsxs(_e,{value:Z,onValueChange:te,children:[e.jsx(Me,{className:O(ee,ye,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${ae?.name??"unassigned"}`,"aria-label":`Assigned node: ${ae?.name??"unassigned"}`,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(Wn,{isCurrent:G}),e.jsx("span",{className:"min-w-0 truncate",children:ae.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:G?"current":"remote"})]}):e.jsx($e,{placeholder:"Select node"})}),e.jsx(Pe,{children:Rn(Y,n)})]}),v?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{id:"task-title-composer",type:"text",value:j,onChange:Ne=>A(Ne.target.value),onKeyDown:Ne=>{(Ne.key==="Enter"||Ne.key==="Escape")&&(Ne.preventDefault(),$(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>$(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(as,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>$(!0),className:"chat-composer__title-button flex min-w-0 items-center gap-1.5 rounded-sm px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-background/55 hover:text-foreground",title:Le||"Title","aria-label":Le?`Edit title: ${Le}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:Le||"Title"}),e.jsx(Ot,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",ref:he,value:f,onChange:Ne=>E(Ne.target.value),onKeyDown:Se,onPaste:oe,placeholder:"Ask anything...",rows:4,autoFocus:h,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm bg-transparent px-5 pt-2 pb-2 text-xs leading-5 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsx(jr,{agent:b,query:f,onSelect:Ee}),e.jsx(kn,{query:f,quickChats:fe,selectedIndex:y,onActiveIndexChange:x,onSelect:Ie}),e.jsxs("div",{className:"chat-composer__rail flex min-w-0 flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:K,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Mn,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(_e,{value:b,onValueChange:C,children:[e.jsxs(Me,{className:O(ee,"chat-composer__icon-trigger",Fe?ge:ye),title:`Agent: ${M}`,"aria-label":`Agent: ${M}`,children:[e.jsx(Hn,{agent:b}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:M})]}),e.jsx(Pe,{children:fr()})]}),e.jsx(yo,{agent:b,value:S,onChange:P,chip:!0,triggerClassName:O(ee,"chat-composer__icon-trigger",S?ye:ge),contentClassName:"max-h-80 shadow-none"}),e.jsxs(_e,{value:T,onValueChange:Ne=>I(Ne),children:[e.jsxs(Me,{className:O(ee,"chat-composer__icon-trigger",ze?ge:ye),title:`Mode: ${ne}`,"aria-label":`Mode: ${ne}`,children:[e.jsx(fd,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:ne})]}),e.jsx(Pe,{children:xr()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[c&&e.jsxs(J,{type:"button",variant:"ghost",size:"sm",onClick:c,"aria-label":u,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(it,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:u})]}),e.jsxs(J,{type:"submit",size:"icon",disabled:!Ze||q,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[q?e.jsx(de,{className:"h-4 w-4 animate-spin"}):e.jsx(uo,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:q?"Creating chat":g})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const Ne="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(As,{value:_,onChange:D,assignTo:Z,nodes:t,assignableNodes:Y,layout:"composer",chipClassName:ee,chipActiveClassName:Ne,chipInactiveClassName:Ne,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(Nr,{value:z,onChange:Q,project:_,assignTo:Z,nodes:t,assignableNodes:Y,layout:"composer",chipClassName:ee,chipActiveClassName:Ne,chipInactiveClassName:Ne,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(He||W)&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/45 p-2.5",children:[He,W&&e.jsx("div",{className:"text-[11px] text-destructive",children:W}),!W&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Ctrl/Cmd+Enter starts the chat. Enter adds a new line. Paste screenshots directly into the prompt box or use the Images button."})]})]}):e.jsxs("form",{onSubmit:xt,className:O("space-y-4",d),children:[e.jsx("input",{ref:R,type:"file",accept:"image/*",multiple:!0,onChange:B,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{htmlFor:"task-description",className:"text-[11px] font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",ref:he,value:f,onChange:ee=>E(ee.target.value),onKeyDown:Se,onPaste:oe,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:h,className:"flex min-h-[128px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm border border-border/70 bg-background/70 px-3 py-2 text-xs leading-5 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"}),e.jsx(jr,{agent:b,query:f,onSelect:Ee}),e.jsx(kn,{query:f,quickChats:fe,selectedIndex:y,onActiveIndexChange:x,onSelect:Ie}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(J,{type:"button",variant:"outline",onClick:K,className:"rounded-sm",children:[e.jsx(Mn,{className:"h-4 w-4"}),"Add images"]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Ctrl/Cmd+Enter starts the chat. Enter adds a new line. Upload or paste screenshots and reference images with the opening prompt."})]}),He,W&&e.jsx("p",{className:"text-[11px] text-destructive",children:W})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_170px_190px_150px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ge,{htmlFor:"task-title",className:"text-[11px] font-medium",children:"Chat title"}),e.jsx(ot,{id:"task-title",type:"text",value:j,onChange:ee=>A(ee.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-8 rounded-sm border-border/70 bg-background/70"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:Le?`Will appear as: ${Le}`:"A title will be generated from the first line of the prompt."})]}),Ke,e.jsx(hu,{agent:b,value:S,onChange:P}),Oe]}),lt,ct,We,e.jsxs("div",{className:O("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",m),children:[c&&e.jsx(J,{type:"button",variant:"ghost",onClick:c,className:"rounded-sm",children:u}),e.jsx(J,{type:"submit",disabled:!Ze||q,className:"rounded-sm px-5",children:q?"Creating...":g})]})]})}function pu({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,defaultMode:d="chat",mode:m,onModeChange:g,layout:u="default",className:h,footerClassName:p,autoFocus:k=!1,quickChats:j=[]}){const[A,f]=o.useState(d),E=m!==void 0,y=E?m:A,x=b=>{E||f(b),g?.(b)};return e.jsxs("div",{className:O("space-y-4",h),children:[!E&&e.jsxs("div",{className:"flex h-8 items-center gap-0.5 rounded-sm border border-border/60 bg-background/45 p-0.5",children:[e.jsxs(J,{type:"button",variant:y==="chat"?"default":"ghost",onClick:()=>x("chat"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(Hi,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(J,{type:"button",variant:y==="native"?"default":"ghost",onClick:()=>x("native"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(Kn,{className:"h-4 w-4"}),"Load session"]})]}),y==="chat"?e.jsx(xu,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,footerClassName:p,submitLabel:u==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:k,layout:u,quickChats:j},`${a??""}:${i??""}`):e.jsx(mu,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:l,onCancel:c,footerClassName:p,autoFocus:k})]})}function gu({onClick:t,running:s}){return e.jsxs(J,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:O("absolute bottom-4 right-4 z-10 h-12 w-12 overflow-visible rounded-lg shadow-lg",s&&"animate-soft-status-pulse bg-primary/90 text-primary-foreground hover:bg-primary"),children:[e.jsx(Ot,{className:"h-4 w-4"}),s&&e.jsx("span",{"aria-hidden":"true","data-running-indicator":"true",className:"pointer-events-none absolute right-1.5 top-1.5 h-2 w-2 rounded-full bg-primary-foreground shadow-[0_0_0_2px_hsl(var(--primary))]"})]})}function Sr({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 bu({hasVisibleTranscriptEvents:t,hasTranscriptProgress:s,inputCollapsed:n}){return{collapsedButtonRunning:s&&t&&n,showDockedProgress:s&&t&&!n,showInlineProgress:s&&!t}}const It="72f988bf-86f1-41af-91ab-2d7cd011db47",No=`${It} (MSIT)`;function vu({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i=!1,shareResult:l}){return e.jsx(wt,{open:t,onOpenChange:s,children:e.jsxs(yt,{className:"max-w-md rounded-sm p-4",children:[e.jsx(Tt,{className:"sr-only",children:"Share conversation"}),e.jsx(wu,{onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i,shareResult:l})]})})}function wu({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:a=!1,shareResult:i}){const[l,c]=o.useState(i?.tenant??It),[d,m]=o.useState(i?.scope??"chat"),g=i?.url?Ba(i.url):null,u=r||a;return o.useEffect(()=>{c(i?.tenant??It),m(i?.scope??"chat")},[i?.shareId,i?.tenant,i?.scope]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-sm font-semibold leading-none tracking-tight",children:"Share conversation"}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:"Create a tenant-gated link for this task."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(yu,{value:l,onChange:c,disabled:u}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Access"}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(Cr,{active:d==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>m("chat")}),e.jsx(Cr,{active:d==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>m("filesPreview")})]})]}),g&&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:g,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>{ls(g,"Shared link copied")},"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Oa,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e.jsx(J,{variant:"outline",onClick:()=>t(!1),disabled:u,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(J,{variant:"outline",onClick:()=>{n()},disabled:u,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[a&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(J,{onClick:()=>{s({tenant:l,scope:d})},disabled:u,className:"h-8 text-xs",children:[r&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function yu({value:t,onChange:s,disabled:n}){const[r,a]=o.useState(!1),[i,l]=o.useState(!1),[c,d]=o.useState(t),m=o.useRef(null);o.useEffect(()=>{d(t)},[t]),o.useEffect(()=>{if(!r)return;const u=p=>{const k=p.target;k instanceof Node&&(m.current?.contains(k)||(a(!1),l(!1)))},h=p=>{p.key==="Escape"&&(a(!1),l(!1))};return document.addEventListener("mousedown",u),document.addEventListener("keydown",h),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",h)}},[r]);const g=u=>{const h=u.trim();h&&(s(h),d(h),l(!1),a(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:m,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&a(u=>!u),disabled:n,className:"flex h-9 w-full items-center justify-between gap-2 rounded-sm border border-border/70 bg-background/70 px-3 text-left text-xs text-foreground shadow-sm outline-none transition-colors hover:bg-background disabled:opacity-50",children:[e.jsx("span",{className:"min-w-0 truncate font-mono",children:ju(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:()=>g(It),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:No}),t===It&&e.jsx(as,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]}),e.jsx("div",{className:"border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:i?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:c,onChange:u=>d(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),g(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:()=>g(c),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(as,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{d(t),l(!1)},className:"flex h-7 w-7 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",children:e.jsx(it,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>l(!0),className:"flex h-7 w-full items-center justify-between rounded-sm px-1.5 text-[11px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx("span",{children:"Manual tenant ID"}),e.jsx(Ot,{className:"h-3 w-3"})]})})]})]})]})}function ju(t){return t===It?No:t}function Cr({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 Nu(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 ku({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(nd,{className:"h-3.5 w-3.5 text-primary"}),"Queued messages",e.jsx("span",{className:"ml-auto rounded-sm border border-border/60 bg-muted/60 px-1.5 py-0 text-[10px] text-muted-foreground",children:t.length})]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:t.map((n,r)=>{const a=n.content.filter(i=>i.type==="image");return e.jsxs("div",{className:"flex min-w-0 items-start gap-2 text-[11px] leading-5 text-muted-foreground",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-[10px] font-medium text-primary",children:r+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"break-words [overflow-wrap:anywhere]",children:Nu(n.content)}),a.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:a.map((i,l)=>e.jsx(Za,{image:i,alt:i.filename??`queued attachment ${l+1}`,thumbnailClassName:"h-14 w-14 border border-border/65",imageClassName:"h-full w-full"},`${i.filename??"image"}-${l}`))})]}),s&&e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground hover:text-destructive",title:"Cancel queued message","aria-label":"Cancel queued message",onClick:()=>s(n.id),children:e.jsx(it,{className:"h-3 w-3"})})]},n.id)})})]})})}const Su="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",Cu=[{value:"transcript",label:"Transcript",icon:Gi},{value:"files",label:"Files",icon:Bt,activeIcon:Ps},{value:"diff",label:"Diff",icon:Cs},{value:"preview",label:"Preview",icon:Tc}];function Tu({activeTab:t}){return e.jsx(zn,{className:"h-auto max-w-full justify-start gap-2 overflow-x-auto rounded-sm !bg-muted/40 !p-0.5 !shadow-none",children:Cu.map(s=>{const n=s.value===t&&s.activeIcon?s.activeIcon:s.icon;return e.jsx(St,{value:s.value,title:s.label,"aria-label":s.label,className:Su,children:e.jsx(n,{className:"h-3.5 w-3.5","aria-hidden":"true"})},s.value)})})}const ko="pointer-events-auto h-5 w-5 shrink-0 rounded-sm bg-muted/65 text-muted-foreground hover:bg-muted hover:text-foreground",Ds="h-3.5 w-3.5";function Ln({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,centerSlot:i}){return e.jsxs("div",{className:"relative flex w-full items-center justify-between gap-1.5",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:e.jsx(So,{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(Co,{operationsOpen:r,onToggleOperations:a,className:"xl:hidden"})]})}function So({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){const a=globalThis.window?.matchMedia("(min-width: 1024px)")?.matches?s:n;return e.jsx(J,{variant:"ghost",size:"icon",onClick:r,title:a?"Hide tasks":"Show tasks","aria-label":a?"Hide tasks":"Show tasks",className:O(ko,t),children:a?e.jsx(Ss,{className:Ds}):e.jsx(st,{className:Ds})})}function Co({className:t,operationsOpen:s,onToggleOperations:n}){return e.jsx(J,{variant:"ghost",size:"icon",onClick:n,title:s?"Hide cluster":"Show cluster","aria-label":s?"Hide cluster":"Show cluster",className:O(ko,t),children:s?e.jsx(st,{className:Ds}):e.jsx(Ss,{className:Ds})})}const Tr="h-7 w-7 rounded-sm border-0 bg-primary/10 text-primary backdrop-blur hover:bg-primary/20 hover:text-primary";function Eu({active:t,onScrollToBottom:s,onScrollToTop:n}){return e.jsxs("div",{className:O("pointer-events-none absolute right-3 top-1/2 z-10 flex -translate-y-1/2 flex-col gap-2 opacity-0 transition-opacity duration-200 group-hover:pointer-events-auto group-hover:opacity-100",t&&"pointer-events-auto opacity-100"),children:[e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:Tr,onClick:n,"aria-label":"Scroll to top",title:"Scroll to top",children:e.jsx(Wi,{className:"h-4 w-4"})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:Tr,onClick:s,"aria-label":"Scroll to bottom",title:"Scroll to bottom",children:e.jsx(Je,{className:"h-4 w-4"})})]})}const Er="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",kt={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:`${Er} mt-0`,action:Er},Au=30,Du=1600;function _u({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Ws(t){return t.scrollHeight-t.scrollTop-t.clientHeight<Au}function Ar({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function Qs(t,s){return!!(s&&(t===s||t.contains(s)))}function Ys(t){const s=t.ownerDocument.getSelection();if(!s||s.isCollapsed||s.rangeCount===0)return!1;if(Qs(t,s.anchorNode)||Qs(t,s.focusNode))return!0;for(let n=0;n<s.rangeCount;n+=1)if(Qs(t,s.getRangeAt(n).commonAncestorContainer))return!0;return!1}function Mu({atTop:t,inputCollapseDisabled:s,scrollingUp:n}){return!s&&(n||t)}function Pu({activeTab:t,activeTaskId:s,contentVersion:n,inputCollapseDisabled:r=!1,setActiveTab:a,setInputCollapsed:i}){const l=o.useRef(null),c=o.useRef(s),d=o.useRef(!1),m=o.useRef(0),g=o.useRef(new Map),u=o.useRef(0),h=o.useRef(!0),p=o.useCallback((x=c.current)=>{const b=l.current;!b||!x||(g.current.set(x,b.scrollTop),m.current=b.scrollTop,h.current=Ws(b))},[]),k=o.useCallback((x=c.current)=>{const b=l.current;!b||!x||(b.scrollTop=_u({savedScrollTop:g.current.get(x),scrollHeight:b.scrollHeight,clientHeight:b.clientHeight}),m.current=b.scrollTop,h.current=Ws(b))},[]),j=o.useCallback((x,b=c.current)=>{x.scrollTop=x.scrollHeight,m.current=x.scrollTop,h.current=!0,b&&g.current.set(b,x.scrollTop)},[]),A=o.useCallback((x=c.current)=>{const b=l.current;u.current=Date.now()+Du,b&&(j(b,x),requestAnimationFrame(()=>{j(b,x),requestAnimationFrame(()=>j(b,x))}))},[j]),f=o.useCallback((x=c.current)=>{const b=l.current;u.current=0,b&&(b.scrollTop=0,m.current=0,h.current=!1,x&&g.current.set(x,0))},[]),E=o.useCallback(x=>{const b=x.currentTarget,C=m.current,S=b.scrollTop<C&&C-b.scrollTop>10,P=b.scrollTop<=0,T=Ys(b);if(p(),T){u.current=0;return}if(!d.current){if(Ws(b)){i(!1),d.current=!0,setTimeout(()=>{d.current=!1},300);return}(S||P)&&(u.current=0,Mu({atTop:P,inputCollapseDisabled:r,scrollingUp:S})&&i(!0))}},[r,p,i]),y=o.useCallback(x=>{t==="transcript"&&p(),a(x),x==="transcript"&&requestAnimationFrame(()=>k())},[t,k,p,a]);return o.useLayoutEffect(()=>{r&&i(!1)},[r,i]),o.useLayoutEffect(()=>{const x=c.current;x&&x!==s&&p(x),c.current=s,t==="transcript"&&requestAnimationFrame(()=>k(s))},[s,t,k,p]),o.useLayoutEffect(()=>{const x=l.current;if(!x||t!=="transcript"||!s)return;const b=Ar({explicitBottomStickUntil:u.current,now:Date.now(),wasAtBottom:h.current});if(Ys(x)){u.current=0,p(s);return}b&&j(x,s),p(s)},[s,t,n,p,j]),o.useLayoutEffect(()=>{const x=l.current,b=x?.firstElementChild;if(!x||!b||t!=="transcript"||typeof ResizeObserver>"u")return;const C=new ResizeObserver(()=>{if(Ys(x)){u.current=0,p();return}Ar({explicitBottomStickUntil:u.current,now:Date.now(),wasAtBottom:h.current})?j(x):p()});return C.observe(x),C.observe(b),()=>C.disconnect()},[t,s,p,j]),{handleTranscriptScroll:E,handleTranscriptTabChange:y,scrollTranscriptToBottom:A,scrollTranscriptToTop:f,transcriptScrollRef:l}}function To(t=700){const[s,n]=o.useState(!1),r=o.useRef(null),a=o.useCallback(()=>{n(!0),r.current!==null&&clearTimeout(r.current),r.current=setTimeout(()=>{n(!1),r.current=null},t)},[t]);return o.useEffect(()=>()=>{r.current!==null&&clearTimeout(r.current)},[]),{markScrollbarActive:a,scrollbarActive:s}}const Iu=o.lazy(async()=>({default:(await $n(()=>import("./FilesTab-CXyf-FqN.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Ru=o.lazy(async()=>({default:(await $n(()=>import("./PreviewTab-hYU-Sg4s.js").then(s=>s.c),__vite__mapDeps([6,1,2]))).PreviewTab})),Lu=o.lazy(async()=>({default:(await $n(()=>import("./DiffTab-BJ-QDAVa.js"),__vite__mapDeps([7,1,2,5,4,3,6]))).DiffTab}));function Bu({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,activeTab:l,setActiveTab:c,creatingTask:d,createMode:m,createDefaults:g,activeTask:u,assignedNode:h,taskLoading:p,transcriptLoading:k,taskError:j,displayEvents:A,initialPromptAlreadyInLogs:f,initialPrompt:E,supportsFollowUp:y,taskUnavailable:x,chatDisabled:b,chatDisabledReason:C,questionBypassEnabled:S,isRunning:P,isStarting:T,hasPendingFollowUp:I,canCancel:_,canRetry:D,onRetry:L,onCancel:z,onReloadNativeTranscript:Q,onShareTask:Y,onStopShareTask:X,onStartCreateTask:Z,onCancelCreateTask:te,onCreateTask:q,onSendMessage:F,onCancelQueuedMessage:v,onQuestionBypassChange:$,onSubmitQuestionResponse:N,quickChats:W=[]}){const[R,K]=o.useState(!1),[B,oe]=o.useState(!1),[ie,he]=o.useState(!1),[ae,G]=o.useState(!1),[M,ne]=o.useState(!1),[V,re]=o.useState({}),[we,fe]=o.useState(new Set),[Ie,Ee]=o.useState(new Set),[xt,Le]=o.useState(null),[Ze,Se]=o.useState(null),He=u?.effectiveProjectPath??u?.project??"default workspace",We=u?h?.name??Sn(u.assignedTo,i?.nodes,u.assignedNodeName):"unassigned",Ke=u?.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:We}),"..."]}):"Connecting session to an available node...",Oe=u?[{label:"Working dir",value:He,mono:!0},...u.branch?[{label:"Branch",value:u.branch,mono:!0}]:[],{label:"Agent",value:u.agent,mono:!0},{label:"Node",value:We}]:[],lt=!!(E&&!f),ct=lt||A.length>0,ee=P&&ct,ge=(T||I||P)&&!ee,ye=ee?"The agent is still working on this conversation.":ge?Ke:null,{collapsedButtonRunning:Fe,showDockedProgress:ze,showInlineProgress:Ne}=bu({hasTranscriptProgress:!!ye,hasVisibleTranscriptEvents:ct,inputCollapsed:R}),je=u?.conversationKind==="nativeSession",pt=gc(u),zt=k?"Loading transcript":je?"No transcript imported":"Transcript is warming up",Ut=k?"Loading transcript...":je?"Meshy could not find imported history for this native session yet.":"The opening prompt has been stored, but the agent has not emitted conversation output yet.",H=u?.queuedMessages??[],ke=o.useMemo(()=>bc(A),[A]),Ae=o.useMemo(()=>ke.findIndex(({event:pe})=>Ou(pe)),[ke]),jt=o.useMemo(()=>vc("transcript",ke.map(pe=>pe.event)),[ke]),$t=u&&!we.has(u.id)?V[u.id]??u.activeShare??null:null,Nt=u?.id??null,Be=`${Nt??"none"}:${A.length}:${H.length}:${lt?1:0}:${k?1:0}:${Ne?1:0}`,{handleTranscriptScroll:Qe,handleTranscriptTabChange:nt,scrollTranscriptToBottom:dt,scrollTranscriptToTop:ut,transcriptScrollRef:Dt}=Pu({activeTab:l,activeTaskId:Nt,contentVersion:Be,inputCollapseDisabled:!!ye,setActiveTab:c,setInputCollapsed:K}),{markScrollbarActive:Re,scrollbarActive:mt}=To(),Ce=o.useCallback(pe=>{Re(),Qe(pe)},[Qe,Re]),Xe=o.useCallback(pe=>{Le(be=>({path:pe,requestId:(be?.requestId??0)+1})),nt("files")},[nt]),qe=o.useCallback(pe=>{Se(be=>({path:pe,requestId:(be?.requestId??0)+1})),nt("preview")},[nt]),qt=o.useCallback(pe=>{dt(),F(pe)},[F,dt]);return o.useEffect(()=>{Le(null),Se(null)},[Nt]),d?e.jsx(Fu,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,defaultMode:m,createDefaults:g,onCancel:te,onCreated:q,quickChats:W}):!u&&p?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(Ln,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"space-y-3 text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(de,{className:"h-5 w-5 animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm font-semibold tracking-tight text-foreground",children:"Loading conversation"}),e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):u?e.jsxs(Un,{value:l,onValueChange:nt,className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"dashboard-conversation-panel__header relative shrink-0 bg-card/28 px-3 pb-0.5 pt-1 sm:px-5 sm:pt-1.5",children:[e.jsxs("div",{className:"pointer-events-none absolute left-1 right-1 top-2 flex items-center justify-between sm:left-1.5 sm:right-1.5 sm:top-2.5",children:[e.jsx(So,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(Co,{operationsOpen:r,onToggleOperations:a,className:"xl:hidden"})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx("h2",{className:"min-w-0 truncate text-[13px] font-semibold leading-5 text-foreground sm:text-[15px]",title:u.title,children:u.title}),e.jsx(Fa,{status:u.status,isNative:je}),pt&&e.jsxs("span",{"data-task-goal-label":"true",title:"Codex goal",className:"inline-flex h-5 shrink-0 items-center gap-1 rounded-sm bg-primary/10 px-1.5 text-[9px] font-semibold uppercase tracking-[0.12em] text-primary",children:[e.jsx(to,{className:"h-3 w-3","aria-hidden":"true"}),"Goal"]}),u.priority!=="normal"&&e.jsx(Yi,{priority:u.priority})]}),j&&e.jsx("div",{className:"mt-2 w-fit rounded-sm border border-destructive/25 bg-destructive/10 px-2 py-1 text-[11px] text-destructive",children:j}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx(Tu,{activeTab:l}),x&&e.jsx(Ve,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"hidden rounded-sm bg-muted/65 px-1.5 py-0.5 tabular-nums sm:inline-flex",children:Ji(u.updatedAt)}),D&&e.jsxs(J,{variant:"ghost",size:"sm",onClick:L,"aria-label":"Retry task",title:"Retry task",className:"h-7 shrink-0 rounded-sm border-0 bg-primary/10 px-2 text-[10px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[e.jsx(cd,{className:"h-3.5 w-3.5"}),"Retry"]}),je&&Q&&e.jsx(J,{variant:"ghost",size:"icon",onClick:Q,disabled:k,title:"Reload native session transcript","aria-label":"Reload native session transcript",className:"h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",children:e.jsx(co,{className:O("h-3.5 w-3.5",k&&"animate-spin")})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",disabled:x,title:x?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":x?"Unavailable tasks cannot be shared.":"Share conversation",className:"h-6 w-6 shrink-0 rounded-sm text-primary hover:bg-primary/10 hover:text-primary disabled:bg-transparent disabled:text-muted-foreground",onClick:()=>he(!0),children:e.jsx(Es,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(ft,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"group relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"relative min-h-0 flex-1",children:e.jsx("div",{ref:Dt,"data-transcript-scroll":"true",className:O("scrollbar-line h-full min-h-0 touch-pan-y overflow-x-hidden overflow-y-auto overscroll-x-none bg-gradient-to-b from-background/15 via-transparent to-background/35 px-3 pb-4 pt-4 sm:px-5",mt&&"scrollbar-line-active"),onScroll:Ce,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[lt&&E&&e.jsx(pr,{event:E,agent:u.agent,sentAsGoal:pt,taskRootPath:u.effectiveProjectPath,onOpenFilePath:Xe,questionBypassEnabled:S,onQuestionBypassChange:$,onSubmitQuestionResponse:N,questionResponseDisabled:!y||b}),ke.map(({event:pe,subItems:be},Te)=>e.jsx(pr,{event:pe,agent:u.agent,subItems:be,sentAsGoal:pt&&!lt&&Te===Ae,taskRootPath:u.effectiveProjectPath,onOpenFilePath:Xe,questionBypassEnabled:S,onQuestionBypassChange:$,onSubmitQuestionResponse:N,questionResponseDisabled:!y||b},jt[Te])),!ct&&!ge&&e.jsxs("div",{className:"rounded-sm border border-dashed border-border/70 bg-background/35 px-3 py-4 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:zt}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Ut})]}),(!y&&u.result||u.error)&&e.jsxs("div",{className:"space-y-3",children:[!y&&u.result&&e.jsxs("div",{className:"rounded-sm border border-border/70 bg-card/80 px-3 py-3",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:"Stored result"}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5 text-muted-foreground",children:JSON.stringify(u.result,null,2)})]}),u.error&&!Ie.has(u.id)&&e.jsxs("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-3 text-destructive",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em]",children:"Stored error"}),e.jsx("button",{onClick:()=>Ee(pe=>new Set(pe).add(u.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(it,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5",children:u.error})]})]}),Ne&&ye&&e.jsx(Sr,{children:ye})]})})}),e.jsx(Eu,{active:mt,onScrollToBottom:()=>dt(),onScrollToTop:()=>ut()}),ze&&ye&&e.jsx("div",{"data-docked-progress":"true",className:"shrink-0 bg-background/35 px-3 py-1 sm:px-5",children:e.jsx("div",{className:"mx-auto max-w-[72rem]",children:e.jsx(Sr,{children:ye})})}),y?e.jsxs(e.Fragment,{children:[R&&e.jsx(gu,{running:Fe,onClick:()=>{K(!1),dt(),requestAnimationFrame(()=>document.querySelector('[data-chat-input-textarea="true"]')?.focus())}}),e.jsxs("div",{className:`shrink-0 ${R?"hidden":""}`,children:[e.jsx(ku,{messages:H,onCancelMessage:v}),e.jsx(Fd,{onSend:qt,disabled:b,disabledReason:C,contextItems:Oe,agent:u.agent,model:typeof u.payload.model=="string"?u.payload.model:null,placeholder:b?C:P?"Queue a message for the next turn...":"Continue the conversation...",running:P||I,onStop:_?()=>oe(!0):void 0,quickChats:W})]})]}):e.jsx("div",{className:"shrink-0 border-t border-border/60 px-3 py-3 text-[11px] text-muted-foreground sm:px-5",children:"This task does not expose follow-up chat messages. Use Files, Preview, or Diff to inspect the result."})]})}),e.jsx(ft,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Vs,{label:"Loading files..."}),children:e.jsx(Iu,{taskId:u.id,requestedFilePath:xt?.path??null,requestedFileRequestId:xt?.requestId??0,onPreviewFile:qe})})}),e.jsx(ft,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Vs,{label:"Loading preview..."}),children:e.jsx(Ru,{taskId:u.id,requestedEntryPath:Ze?.path??null,requestedEntryRequestId:Ze?.requestId??0})})}),e.jsx(ft,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(Vs,{label:"Loading diff..."}),children:e.jsx(Lu,{taskId:u.id})})}),e.jsx(Yt,{open:B,onOpenChange:oe,children:e.jsxs(Jt,{className:kt.content,children:[e.jsxs(Zt,{className:kt.header,children:[e.jsx(Xt,{className:kt.title,children:"Stop this task?"}),e.jsx(es,{className:kt.description,children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ts,{className:kt.footer,children:[e.jsx(ss,{className:kt.cancel,children:"Keep running"}),e.jsx(ns,{className:kt.action,onClick:z,children:"Stop task"})]})]})}),e.jsx(vu,{open:ie,onOpenChange:he,sharing:ae,stopping:M,shareResult:$t,onShare:async pe=>{if(!u)return null;G(!0);try{const be=await Y(pe);return be?.url&&(re(Te=>({...Te,[u.id]:be})),fe(Te=>{const us=new Set(Te);return us.delete(u.id),us})),be}finally{G(!1)}},onStopShare:async()=>{if(!u)return!1;ne(!0);try{const pe=await X();return pe!==!1&&(re(be=>{const Te={...be};return delete Te[u.id],Te}),fe(be=>new Set(be).add(u.id))),pe}finally{ne(!1)}}})]}):e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ln,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"w-full max-w-lg text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(Qi,{className:"h-5 w-5"})}),e.jsx("h2",{className:"mt-3 text-sm font-semibold tracking-tight text-foreground sm:text-[15px]",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-2 max-w-md text-[11px] leading-5 text-muted-foreground",children:"Open a task from the left sidebar to continue the conversation, or start a new task or load a native session."}),e.jsxs(J,{onClick:()=>Z(),className:"mt-4 h-8 rounded-sm px-3",children:[e.jsx(Is,{className:"h-3.5 w-3.5"}),"Start or load chat"]}),j&&e.jsx("div",{className:"mx-auto mt-3 max-w-md rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:j})]})})]})}function Ou(t){return t.type!=="user"||t.isMeta===!0||t.isSidechain===!0?!1:!!An(t)?.some(n=>n.type==="text"||n.type==="image")}function Fu({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,defaultMode:l,createDefaults:c,onCancel:d,onCreated:m,quickChats:g}){const[u,h]=o.useState(l??"chat");o.useEffect(()=>{l&&h(l)},[l]);const p=e.jsx("div",{className:"flex h-8 items-center gap-0.5 overflow-hidden rounded-sm border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-none",children:[{value:"chat",label:"New chat",icon:Is},{value:"native",label:"Load session",icon:Kn}].map(k=>{const j=k.icon,A=k.value===u;return e.jsxs("button",{type:"button",onClick:()=>h(k.value),"aria-pressed":A,className:O("flex h-7 min-w-28 items-center justify-center gap-1.5 rounded-sm border border-transparent px-2.5 transition-colors duration-150",A?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(j,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:k.label})]},k.value)})});return e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ln,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,centerSlot:p})}),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(pu,{nodes:i?.nodes??[],currentNodeRole:i?.self?.role,currentNodeId:i?.self?.id??null,leaderNodeId:i?.leader?.id??null,initialAssignTo:c?.assignTo,initialProject:c?.project,mode:u,onModeChange:h,onCreated:m,onCancel:d,autoFocus:!0,layout:"composer",quickChats:g})})})]})}function zu({onAdded:t}){const[s,n]=o.useState(""),[r,a]=o.useState(!1),[i,l]=o.useState(null),c=o.useCallback(async d=>{if(d.preventDefault(),!!s.trim()){a(!0),l(null);try{await Zi({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(m){l(m instanceof Error?m.message:"Failed to join node")}finally{a(!1)}}},[s,t]);return e.jsx(yt,{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(cs,{className:"space-y-1 text-left",children:[e.jsx(Tt,{className:"text-sm tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Verify the remote leader's DevTunnel Node URL, sync this node's tasks to that leader, and join the cluster as a follower."})]})}),e.jsxs("form",{onSubmit:c,className:"space-y-3 px-3.5 py-3",children:[i&&e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Ge,{htmlFor:"leader-endpoint",children:"Leader Node URL"}),e.jsx(Ve,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(ot,{id:"leader-endpoint",type:"url",value:s,onChange:d=>n(d.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-8 rounded-sm border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-sm border border-border/60 bg-background/45 px-3 py-2 text-[11px] text-muted-foreground",children:"This does not switch the local node transport or auto-enable a local DevTunnel. Leaving later will detach this node from the remote leader and make it leader of its own cluster again."}),e.jsx(za,{className:"border-t border-border/60 pt-3",children:e.jsx(J,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function Uu({open:t,onOpenChange:s,onAdded:n}){return e.jsx(wt,{open:t,onOpenChange:s,children:e.jsx(zu,{onAdded:()=>{s(!1),n()}})})}const $u="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",qu="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",Vu="h-2.5 w-2.5";function Eo({className:t,label:s,orientation:n,panel:r,panelResize:a}){return e.jsx("button",{type:"button","aria-label":s,"aria-orientation":n,"data-dashboard-resize-handle":r,onPointerDown:i=>a.onPointerDown(r,i),onWheel:i=>a.onWheel(r,i),className:O("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 Hu({className:t,label:s,onToggle:n,side:r,visible:a}){const i=r==="left"?a?Ss:st:a?st:Ss;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:O($u,t),children:e.jsx("span",{className:qu,"aria-hidden":"true",children:e.jsx(i,{className:Vu,strokeWidth:2.1})})})}function Dr({className:t,label:s,onToggle:n,panel:r,panelResize:a,screen:i,side:l,visible:c}){const d=i==="lg"?"lg:block":"xl:block",m=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:O("group absolute top-0 z-30 hidden h-full w-4",d,t),children:[r&&e.jsx(Eo,{panel:r,orientation:"vertical",label:`Resize ${r} panel`,panelResize:a,className:"left-1/2 top-0 h-full w-2 -translate-x-1/2 cursor-col-resize"}),e.jsx(Hu,{side:l,visible:c,label:s,onToggle:n,className:O(m,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function Ku({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:a,operationsOpen:i,operationsPanelRef:l,operationsSidecar:c,panelResize:d,taskSidebar:m,terminalPanel:g,onCloseOperations:u,onCloseTaskList:h,onToggleOperations:p,onToggleTasks:k}){const j={"--dashboard-tasks-width":d.sizes.tasks,"--dashboard-operations-width":d.sizes.operations,"--dashboard-terminal-height":d.sizes.terminal};return e.jsxs("div",{className:"dashboard-workspace flex h-full min-h-0 flex-col overflow-hidden",style:j,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(Dr,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:k,panel:s?"tasks":void 0,panelResize:d,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:O("dashboard-workspace__tasks-panel relative hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",s?"lg:mr-2 lg:w-[var(--dashboard-tasks-width)]":"lg:w-0 lg:overflow-hidden"),children:s&&m}),e.jsxs("section",{className:"dashboard-workspace__primary flex min-h-0 min-w-0 flex-1 flex-col gap-2",children:[e.jsx("div",{className:"min-h-0 flex-1",children:t}),g&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(Eo,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:d,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),g]})]}),e.jsx(Dr,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:p,panel:i?"operations":void 0,panelResize:d,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:O("dashboard-workspace__operations-panel relative hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",i?"xl:ml-2 xl:w-[var(--dashboard-operations-width)]":"xl:w-0 xl:overflow-hidden"),children:i&&c})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:u,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:l,className:"fixed bottom-0 right-0 top-[var(--dashboard-mobile-overlay-top)] z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:c})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:h,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:a,className:"fixed bottom-0 left-0 top-[var(--dashboard-mobile-overlay-top)] z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:n})]})]})}const Gu=10,Ct="__all__";function et(t){return"session"in t}function _r(t,s){return s&&t.some(n=>n.id===s)?s:t[0]?.id??""}function Js(t){return t&&(vo(t.id)||t.workDir)||""}function bs(t,s,n){let r=!1;const a=t.map(i=>et(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return Bn(r?a:[...a,{id:`session-${n.id}`,nodeName:s,session:n}])}function Ao(t,s){return t.filter(et).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function Wu(t){const s=t.filter(et).sort((n,r)=>r.session.startedAt-n.session.startedAt);return{active:s.filter(n=>n.session.status==="running"),completed:s.filter(n=>n.session.status!=="running")}}function Qu(t,s){return!!(t&&s&&!t.contains(s))}function Yu(t,s,n){if(n===Ct)return n;const r=Ao(t,s);return r.some(a=>a.session.id===n)?n:r[0]?.session.id??Ct}function Ju(t,s,n){return n===Ct?t.filter(r=>!et(r)||r.session.nodeId===s):t.filter(r=>et(r)&&r.session.nodeId===s&&r.session.id===n)}function Bn(t){const s=t.map((r,a)=>({entry:r,index:a})).filter(({entry:r})=>et(r)&&r.session.status!=="running").sort((r,a)=>!et(r.entry)||!et(a.entry)?0:a.entry.session.startedAt-r.entry.session.startedAt||a.index-r.index),n=new Set(s.slice(0,Gu).map(({entry:r})=>et(r)?r.session.id:""));return t.filter(r=>!et(r)||r.session.status==="running"||n.has(r.session.id))}function On(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 Zu(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${On(t.session)} - ${s}`}function Do(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function Xu(t,s){return s===Ct?"All sessions":t?Do(t.session.command,34):"Command session"}function Mr(t){return t.status==="stopped"?"":t.stderr}function em({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[a,i]=o.useState(()=>_r(t,s)),l=o.useMemo(()=>t.find(N=>N.id===a)??t[0]??null,[t,a]),[c,d]=o.useState(()=>Js(l)),[m,g]=o.useState(""),[u,h]=o.useState(()=>Bn(r)),[p,k]=o.useState(Ct),[j,A]=o.useState(!1),[f,E]=o.useState(!1),[y,x]=o.useState(!1),[b,C]=o.useState(!1),[S,P]=o.useState(!1),T=o.useRef(null),I=o.useRef(null),_=o.useMemo(()=>t.find(N=>N.id===a)??t[0]??null,[t,a]),D=o.useMemo(()=>Ao(u,_?.id??""),[u,_]),L=o.useMemo(()=>Wu(D),[D]),z=o.useMemo(()=>D.find(N=>N.session.id===p),[p,D]),Q=o.useMemo(()=>Ju(u,_?.id??"",p),[u,_,p]),Y=o.useRef(_?.id??"");o.useEffect(()=>{a&&t.some(N=>N.id===a)||i(_r(t,s))},[s,t,a]),o.useEffect(()=>{const N=_?.id??"";Y.current!==N&&(Y.current=N,d(Js(_)))},[_]),o.useEffect(()=>{k(N=>Yu(u,_?.id??"",j?N:""))},[u,_,j]),o.useEffect(()=>{T.current?.scrollTo({top:T.current.scrollHeight})},[u]),o.useEffect(()=>{let N=!1;async function W(){const R=await Promise.allSettled(t.map(async K=>({node:K,response:await el(K.id)})));N||h(K=>R.reduce((B,oe)=>oe.status!=="fulfilled"?B:oe.value.response.sessions.reduce((ie,he)=>bs(ie,oe.value.node.name,he),B),K))}return t.length>0&&W(),()=>{N=!0}},[t]),o.useEffect(()=>{const N=u.filter(et).filter(R=>R.session.status==="running");if(N.length===0)return;const W=window.setInterval(()=>{for(const R of N)Xi(R.session.nodeId,R.session.id).then(K=>h(B=>bs(B,R.nodeName,K))).catch(()=>{})},1e3);return()=>window.clearInterval(W)},[u]);const X=o.useRef(null);async function Z(N){if(N.preventDefault(),!_||!m.trim()||S)return;const W=m.trim(),R=_.name;P(!0),g("");try{const K=await sl(_.id,{command:W,...c.trim()?{cwd:c.trim()}:{}});h(B=>bs(B,R,K)),k(K.id),A(!0)}catch(K){h(B=>[...B,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:R,command:W,error:K instanceof Error?K.message:"Command failed"}])}finally{P(!1)}}async function te(N,W){N.stopPropagation();const R=await tl(W.session.nodeId,W.session.id);h(K=>bs(K,W.nodeName,R))}function q(N){k(N),A(!0),E(!1)}function F(N){f&&Qu(I.current,N.target)&&E(!1)}function v(N,W,R,K,B){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:K,"aria-label":`Toggle ${N} sessions`,"aria-expanded":!R,className:"node-terminal__small flex w-full items-center justify-between gap-2 px-2 pb-1 pt-0.5 text-left font-medium uppercase tracking-normal text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{children:N}),e.jsx(Je,{className:O("h-3 w-3 transition-transform",R&&"-rotate-90")})]}),!R&&(W.length>0?W.map($):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:B}))]})}function $(N){const W=p===N.session.id,R=N.session.status==="running";return e.jsxs("div",{className:O("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",W&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>q(N.session.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:O("flex h-4 w-4 shrink-0 items-center justify-center",R?"text-primary":N.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:R?e.jsx(de,{className:"h-3 w-3 animate-spin"}):N.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:Do(N.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[N.nodeName," · ",On(N.session)]})]})]}),R&&e.jsx("button",{type:"button",onClick:K=>{te(K,N)},"aria-label":"Stop terminal session from selector",title:"Stop terminal session",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(vr,{className:"h-3 w-3"})})]},N.session.id)}return e.jsx("section",{className:"dashboard-panel node-terminal animate-composer-settle flex h-full min-h-0 shrink-0 overflow-visible rounded-xl","aria-label":"Node terminal",onClick:F,children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-visible rounded-[inherit] bg-card/72 text-card-foreground",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"node-terminal__header flex min-w-0 items-center gap-2 font-medium",children:[n?e.jsx("button",{type:"button",onClick:n,"aria-label":"Close terminal",title:"Close terminal",className:"flex h-6 w-6 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(it,{className:"h-3.5 w-3.5"})}):e.jsx(ir,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{children:"Terminal"})]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-2",children:[e.jsxs("div",{ref:I,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":f,title:z?Zu(z):"All sessions",onClick:()=>E(N=>!N),className:"node-terminal__control flex h-7 max-w-[14rem] list-none items-center gap-1.5 rounded-sm border border-border/70 bg-background/70 px-2 text-foreground outline-none transition-colors hover:bg-muted/65 focus-visible:ring-2 focus-visible:ring-ring/70 [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{className:"min-w-0 truncate",children:Xu(z,p)}),e.jsx(Je,{className:O("h-3 w-3 shrink-0 text-muted-foreground transition-transform",f&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!f,className:O("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:()=>q(Ct),className:O("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",p===Ct&&"bg-primary/10 text-primary"),children:[e.jsx(ir,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),v("Active",L.active,y,()=>x(N=>!N),"No active sessions"),v("Completed",L.completed,b,()=>C(N=>!N),"No completed sessions")]})})]}),e.jsx("select",{value:_?.id??"",onChange:N=>{i(N.target.value),A(!1),d(Js(t.find(W=>W.id===N.target.value)??null))},disabled:S||t.length===0,"aria-label":"Terminal node",className:"node-terminal__control h-7 max-w-[11rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground outline-none transition-colors hover:bg-muted/65 disabled:opacity-50",children:t.map(N=>e.jsx("option",{value:N.id,className:"bg-background text-foreground",children:N.name},N.id))}),e.jsx(As,{value:c,onChange:d,assignTo:_?.id??"",nodes:t,assignableNodes:t,layout:"composer",chipClassName:"node-terminal__control h-7 max-w-[18rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground hover:bg-muted/65",chipActiveClassName:"font-mono",chipInactiveClassName:"text-muted-foreground",labelClassName:"node-terminal__workdir",triggerClassName:"terminal-workdir-trigger",popoverPlacement:"top",popoverAlign:"end"})]})]}),e.jsxs("div",{ref:T,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>X.current?.focus(),children:[Q.length===0?e.jsx("div",{className:"text-muted-foreground mb-2",children:"Commands run on the selected node and stay visible while running or after exit."}):e.jsx("div",{className:"space-y-3 mb-2",children:Q.map(N=>et(N)?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"text-primary",children:[N.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:N.session.command}),e.jsxs("span",{className:O("inline-flex items-center gap-1",N.session.status==="running"||N.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[N.session.status==="running"?e.jsx(de,{className:"h-3 w-3 animate-spin"}):N.session.status==="exited"?e.jsx(Cn,{className:"h-3 w-3"}):e.jsx($s,{className:"h-3 w-3"}),On(N.session)]}),N.session.status==="running"&&e.jsx("button",{type:"button",onClick:W=>{te(W,N)},"aria-label":"Stop terminal session",title:"Stop terminal session",className:"inline-flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/65 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(vr,{className:"h-3 w-3"})})]}),N.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:N.session.stdout}),Mr(N.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Mr(N.session)}),(N.session.stdoutTruncated||N.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},N.id):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"text-primary",children:[N.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:N.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx($s,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:N.error})]},N.id))}),e.jsxs("form",{onSubmit:Z,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:_?`${_.name}$`:"$"}),e.jsx("input",{ref:X,value:m,onChange:N=>g(N.target.value),disabled:!_||S,placeholder:_?"":"No online nodes available",className:"node-terminal__input flex-1 min-w-0 bg-transparent border-none outline-none text-foreground placeholder:text-muted-foreground font-mono caret-primary disabled:opacity-50",autoComplete:"off",spellCheck:!1}),e.jsx("button",{type:"submit","aria-label":"Run",title:"Run",disabled:!_||!m.trim()||S,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:S?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Ms,{className:"h-3 w-3"})})]})]})]})})}var Pt={},Zs,Pr;function tm(){return Pr||(Pr=1,Zs=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Zs}var Xs={},bt={},Ir;function Et(){if(Ir)return bt;Ir=1;let t;const s=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return bt.getSymbolSize=function(r){if(!r)throw new Error('"version" cannot be null or undefined');if(r<1||r>40)throw new Error('"version" should be in range from 1 to 40');return r*4+17},bt.getSymbolTotalCodewords=function(r){return s[r]},bt.getBCHDigit=function(n){let r=0;for(;n!==0;)r++,n>>>=1;return r},bt.setToSJISFunction=function(r){if(typeof r!="function")throw new Error('"toSJISFunc" is not a valid function.');t=r},bt.isKanjiModeEnabled=function(){return typeof t<"u"},bt.toSJIS=function(r){return t(r)},bt}var en={},Rr;function Qn(){return Rr||(Rr=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function s(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+n)}}t.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},t.from=function(r,a){if(t.isValid(r))return r;try{return s(r)}catch{return a}}})(en)),en}var tn,Lr;function sm(){if(Lr)return tn;Lr=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(s){const n=Math.floor(s/8);return(this.buffer[n]>>>7-s%8&1)===1},put:function(s,n){for(let r=0;r<n;r++)this.putBit((s>>>n-r-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(s){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),s&&(this.buffer[n]|=128>>>this.length%8),this.length++}},tn=t,tn}var sn,Br;function nm(){if(Br)return sn;Br=1;function t(s){if(!s||s<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=s,this.data=new Uint8Array(s*s),this.reservedBit=new Uint8Array(s*s)}return t.prototype.set=function(s,n,r,a){const i=s*this.size+n;this.data[i]=r,a&&(this.reservedBit[i]=!0)},t.prototype.get=function(s,n){return this.data[s*this.size+n]},t.prototype.xor=function(s,n,r){this.data[s*this.size+n]^=r},t.prototype.isReserved=function(s,n){return this.reservedBit[s*this.size+n]},sn=t,sn}var nn={},Or;function rm(){return Or||(Or=1,(function(t){const s=Et().getSymbolSize;t.getRowColCoords=function(r){if(r===1)return[];const a=Math.floor(r/7)+2,i=s(r),l=i===145?26:Math.ceil((i-13)/(2*a-2))*2,c=[i-7];for(let d=1;d<a-1;d++)c[d]=c[d-1]-l;return c.push(6),c.reverse()},t.getPositions=function(r){const a=[],i=t.getRowColCoords(r),l=i.length;for(let c=0;c<l;c++)for(let d=0;d<l;d++)c===0&&d===0||c===0&&d===l-1||c===l-1&&d===0||a.push([i[c],i[d]]);return a}})(nn)),nn}var rn={},Fr;function am(){if(Fr)return rn;Fr=1;const t=Et().getSymbolSize,s=7;return rn.getPositions=function(r){const a=t(r);return[[0,0],[a-s,0],[0,a-s]]},rn}var an={},zr;function om(){return zr||(zr=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const s={N1:3,N2:3,N3:40,N4:10};t.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},t.from=function(a){return t.isValid(a)?parseInt(a,10):void 0},t.getPenaltyN1=function(a){const i=a.size;let l=0,c=0,d=0,m=null,g=null;for(let u=0;u<i;u++){c=d=0,m=g=null;for(let h=0;h<i;h++){let p=a.get(u,h);p===m?c++:(c>=5&&(l+=s.N1+(c-5)),m=p,c=1),p=a.get(h,u),p===g?d++:(d>=5&&(l+=s.N1+(d-5)),g=p,d=1)}c>=5&&(l+=s.N1+(c-5)),d>=5&&(l+=s.N1+(d-5))}return l},t.getPenaltyN2=function(a){const i=a.size;let l=0;for(let c=0;c<i-1;c++)for(let d=0;d<i-1;d++){const m=a.get(c,d)+a.get(c,d+1)+a.get(c+1,d)+a.get(c+1,d+1);(m===4||m===0)&&l++}return l*s.N2},t.getPenaltyN3=function(a){const i=a.size;let l=0,c=0,d=0;for(let m=0;m<i;m++){c=d=0;for(let g=0;g<i;g++)c=c<<1&2047|a.get(m,g),g>=10&&(c===1488||c===93)&&l++,d=d<<1&2047|a.get(g,m),g>=10&&(d===1488||d===93)&&l++}return l*s.N3},t.getPenaltyN4=function(a){let i=0;const l=a.data.length;for(let d=0;d<l;d++)i+=a.data[d];return Math.abs(Math.ceil(i*100/l/5)-10)*s.N4};function n(r,a,i){switch(r){case t.Patterns.PATTERN000:return(a+i)%2===0;case t.Patterns.PATTERN001:return a%2===0;case t.Patterns.PATTERN010:return i%3===0;case t.Patterns.PATTERN011:return(a+i)%3===0;case t.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(i/3))%2===0;case t.Patterns.PATTERN101:return a*i%2+a*i%3===0;case t.Patterns.PATTERN110:return(a*i%2+a*i%3)%2===0;case t.Patterns.PATTERN111:return(a*i%3+(a+i)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}t.applyMask=function(a,i){const l=i.size;for(let c=0;c<l;c++)for(let d=0;d<l;d++)i.isReserved(d,c)||i.xor(d,c,n(a,d,c))},t.getBestMask=function(a,i){const l=Object.keys(t.Patterns).length;let c=0,d=1/0;for(let m=0;m<l;m++){i(m),t.applyMask(m,a);const g=t.getPenaltyN1(a)+t.getPenaltyN2(a)+t.getPenaltyN3(a)+t.getPenaltyN4(a);t.applyMask(m,a),g<d&&(d=g,c=m)}return c}})(an)),an}var vs={},Ur;function _o(){if(Ur)return vs;Ur=1;const t=Qn(),s=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],n=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return vs.getBlocksCount=function(a,i){switch(i){case t.L:return s[(a-1)*4+0];case t.M:return s[(a-1)*4+1];case t.Q:return s[(a-1)*4+2];case t.H:return s[(a-1)*4+3];default:return}},vs.getTotalCodewordsCount=function(a,i){switch(i){case t.L:return n[(a-1)*4+0];case t.M:return n[(a-1)*4+1];case t.Q:return n[(a-1)*4+2];case t.H:return n[(a-1)*4+3];default:return}},vs}var on={},Wt={},$r;function im(){if($r)return Wt;$r=1;const t=new Uint8Array(512),s=new Uint8Array(256);return(function(){let r=1;for(let a=0;a<255;a++)t[a]=r,s[r]=a,r<<=1,r&256&&(r^=285);for(let a=255;a<512;a++)t[a]=t[a-255]})(),Wt.log=function(r){if(r<1)throw new Error("log("+r+")");return s[r]},Wt.exp=function(r){return t[r]},Wt.mul=function(r,a){return r===0||a===0?0:t[s[r]+s[a]]},Wt}var qr;function lm(){return qr||(qr=1,(function(t){const s=im();t.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let l=0;l<r.length;l++)for(let c=0;c<a.length;c++)i[l+c]^=s.mul(r[l],a[c]);return i},t.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const l=i[0];for(let d=0;d<a.length;d++)i[d]^=s.mul(a[d],l);let c=0;for(;c<i.length&&i[c]===0;)c++;i=i.slice(c)}return i},t.generateECPolynomial=function(r){let a=new Uint8Array([1]);for(let i=0;i<r;i++)a=t.mul(a,new Uint8Array([1,s.exp(i)]));return a}})(on)),on}var ln,Vr;function cm(){if(Vr)return ln;Vr=1;const t=lm();function s(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return s.prototype.initialize=function(r){this.degree=r,this.genPoly=t.generateECPolynomial(this.degree)},s.prototype.encode=function(r){if(!this.genPoly)throw new Error("Encoder not initialized");const a=new Uint8Array(r.length+this.degree);a.set(r);const i=t.mod(a,this.genPoly),l=this.degree-i.length;if(l>0){const c=new Uint8Array(this.degree);return c.set(i,l),c}return i},ln=s,ln}var cn={},dn={},un={},Hr;function Mo(){return Hr||(Hr=1,un.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),un}var ht={},Kr;function Po(){if(Kr)return ht;Kr=1;const t="[0-9]+",s="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const r="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
170
- ]))+`;ht.KANJI=new RegExp(n,"g"),ht.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),ht.BYTE=new RegExp(r,"g"),ht.NUMERIC=new RegExp(t,"g"),ht.ALPHANUMERIC=new RegExp(s,"g");const a=new RegExp("^"+n+"$"),i=new RegExp("^"+t+"$"),l=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return ht.testKanji=function(d){return a.test(d)},ht.testNumeric=function(d){return i.test(d)},ht.testAlphanumeric=function(d){return l.test(d)},ht}var Gr;function At(){return Gr||(Gr=1,(function(t){const s=Mo(),n=Po();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(i,l){if(!i.ccBits)throw new Error("Invalid mode: "+i);if(!s.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?i.ccBits[0]:l<27?i.ccBits[1]:i.ccBits[2]},t.getBestModeForData=function(i){return n.testNumeric(i)?t.NUMERIC:n.testAlphanumeric(i)?t.ALPHANUMERIC:n.testKanji(i)?t.KANJI:t.BYTE},t.toString=function(i){if(i&&i.id)return i.id;throw new Error("Invalid mode")},t.isValid=function(i){return i&&i.bit&&i.ccBits};function r(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+a)}}t.from=function(i,l){if(t.isValid(i))return i;try{return r(i)}catch{return l}}})(dn)),dn}var Wr;function dm(){return Wr||(Wr=1,(function(t){const s=Et(),n=_o(),r=Qn(),a=At(),i=Mo(),l=7973,c=s.getBCHDigit(l);function d(h,p,k){for(let j=1;j<=40;j++)if(p<=t.getCapacity(j,k,h))return j}function m(h,p){return a.getCharCountIndicator(h,p)+4}function g(h,p){let k=0;return h.forEach(function(j){const A=m(j.mode,p);k+=A+j.getBitsLength()}),k}function u(h,p){for(let k=1;k<=40;k++)if(g(h,k)<=t.getCapacity(k,p,a.MIXED))return k}t.from=function(p,k){return i.isValid(p)?parseInt(p,10):k},t.getCapacity=function(p,k,j){if(!i.isValid(p))throw new Error("Invalid QR Code version");typeof j>"u"&&(j=a.BYTE);const A=s.getSymbolTotalCodewords(p),f=n.getTotalCodewordsCount(p,k),E=(A-f)*8;if(j===a.MIXED)return E;const y=E-m(j,p);switch(j){case a.NUMERIC:return Math.floor(y/10*3);case a.ALPHANUMERIC:return Math.floor(y/11*2);case a.KANJI:return Math.floor(y/13);case a.BYTE:default:return Math.floor(y/8)}},t.getBestVersionForData=function(p,k){let j;const A=r.from(k,r.M);if(Array.isArray(p)){if(p.length>1)return u(p,A);if(p.length===0)return 1;j=p[0]}else j=p;return d(j.mode,j.getLength(),A)},t.getEncodedBits=function(p){if(!i.isValid(p)||p<7)throw new Error("Invalid QR Code version");let k=p<<12;for(;s.getBCHDigit(k)-c>=0;)k^=l<<s.getBCHDigit(k)-c;return p<<12|k}})(cn)),cn}var mn={},Qr;function um(){if(Qr)return mn;Qr=1;const t=Et(),s=1335,n=21522,r=t.getBCHDigit(s);return mn.getEncodedBits=function(i,l){const c=i.bit<<3|l;let d=c<<10;for(;t.getBCHDigit(d)-r>=0;)d^=s<<t.getBCHDigit(d)-r;return(c<<10|d)^n},mn}var hn={},fn,Yr;function mm(){if(Yr)return fn;Yr=1;const t=At();function s(n){this.mode=t.NUMERIC,this.data=n.toString()}return s.getBitsLength=function(r){return 10*Math.floor(r/3)+(r%3?r%3*3+1:0)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(r){let a,i,l;for(a=0;a+3<=this.data.length;a+=3)i=this.data.substr(a,3),l=parseInt(i,10),r.put(l,10);const c=this.data.length-a;c>0&&(i=this.data.substr(a),l=parseInt(i,10),r.put(l,c*3+1))},fn=s,fn}var xn,Jr;function hm(){if(Jr)return xn;Jr=1;const t=At(),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function n(r){this.mode=t.ALPHANUMERIC,this.data=r}return n.getBitsLength=function(a){return 11*Math.floor(a/2)+6*(a%2)},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(a){let i;for(i=0;i+2<=this.data.length;i+=2){let l=s.indexOf(this.data[i])*45;l+=s.indexOf(this.data[i+1]),a.put(l,11)}this.data.length%2&&a.put(s.indexOf(this.data[i]),6)},xn=n,xn}var pn,Zr;function fm(){if(Zr)return pn;Zr=1;const t=At();function s(n){this.mode=t.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}return s.getBitsLength=function(r){return r*8},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(n){for(let r=0,a=this.data.length;r<a;r++)n.put(this.data[r],8)},pn=s,pn}var gn,Xr;function xm(){if(Xr)return gn;Xr=1;const t=At(),s=Et();function n(r){this.mode=t.KANJI,this.data=r}return n.getBitsLength=function(a){return a*13},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(r){let a;for(a=0;a<this.data.length;a++){let i=s.toSJIS(this.data[a]);if(i>=33088&&i<=40956)i-=33088;else if(i>=57408&&i<=60351)i-=49472;else throw new Error("Invalid SJIS character: "+this.data[a]+`
171
- Make sure your charset is UTF-8`);i=(i>>>8&255)*192+(i&255),r.put(i,13)}},gn=n,gn}var bn={exports:{}},ea;function pm(){return ea||(ea=1,(function(t){var s={single_source_shortest_paths:function(n,r,a){var i={},l={};l[r]=0;var c=s.PriorityQueue.make();c.push(r,0);for(var d,m,g,u,h,p,k,j,A;!c.empty();){d=c.pop(),m=d.value,u=d.cost,h=n[m]||{};for(g in h)h.hasOwnProperty(g)&&(p=h[g],k=u+p,j=l[g],A=typeof l[g]>"u",(A||j>k)&&(l[g]=k,c.push(g,k),i[g]=m))}if(typeof a<"u"&&typeof l[a]>"u"){var f=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(f)}return i},extract_shortest_path_from_predecessor_list:function(n,r){for(var a=[],i=r;i;)a.push(i),n[i],i=n[i];return a.reverse(),a},find_path:function(n,r,a){var i=s.single_source_shortest_paths(n,r,a);return s.extract_shortest_path_from_predecessor_list(i,a)},PriorityQueue:{make:function(n){var r=s.PriorityQueue,a={},i;n=n||{};for(i in r)r.hasOwnProperty(i)&&(a[i]=r[i]);return a.queue=[],a.sorter=n.sorter||r.default_sorter,a},default_sorter:function(n,r){return n.cost-r.cost},push:function(n,r){var a={value:n,cost:r};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=s})(bn)),bn.exports}var ta;function gm(){return ta||(ta=1,(function(t){const s=At(),n=mm(),r=hm(),a=fm(),i=xm(),l=Po(),c=Et(),d=pm();function m(f){return unescape(encodeURIComponent(f)).length}function g(f,E,y){const x=[];let b;for(;(b=f.exec(y))!==null;)x.push({data:b[0],index:b.index,mode:E,length:b[0].length});return x}function u(f){const E=g(l.NUMERIC,s.NUMERIC,f),y=g(l.ALPHANUMERIC,s.ALPHANUMERIC,f);let x,b;return c.isKanjiModeEnabled()?(x=g(l.BYTE,s.BYTE,f),b=g(l.KANJI,s.KANJI,f)):(x=g(l.BYTE_KANJI,s.BYTE,f),b=[]),E.concat(y,x,b).sort(function(S,P){return S.index-P.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function h(f,E){switch(E){case s.NUMERIC:return n.getBitsLength(f);case s.ALPHANUMERIC:return r.getBitsLength(f);case s.KANJI:return i.getBitsLength(f);case s.BYTE:return a.getBitsLength(f)}}function p(f){return f.reduce(function(E,y){const x=E.length-1>=0?E[E.length-1]:null;return x&&x.mode===y.mode?(E[E.length-1].data+=y.data,E):(E.push(y),E)},[])}function k(f){const E=[];for(let y=0;y<f.length;y++){const x=f[y];switch(x.mode){case s.NUMERIC:E.push([x,{data:x.data,mode:s.ALPHANUMERIC,length:x.length},{data:x.data,mode:s.BYTE,length:x.length}]);break;case s.ALPHANUMERIC:E.push([x,{data:x.data,mode:s.BYTE,length:x.length}]);break;case s.KANJI:E.push([x,{data:x.data,mode:s.BYTE,length:m(x.data)}]);break;case s.BYTE:E.push([{data:x.data,mode:s.BYTE,length:m(x.data)}])}}return E}function j(f,E){const y={},x={start:{}};let b=["start"];for(let C=0;C<f.length;C++){const S=f[C],P=[];for(let T=0;T<S.length;T++){const I=S[T],_=""+C+T;P.push(_),y[_]={node:I,lastCount:0},x[_]={};for(let D=0;D<b.length;D++){const L=b[D];y[L]&&y[L].node.mode===I.mode?(x[L][_]=h(y[L].lastCount+I.length,I.mode)-h(y[L].lastCount,I.mode),y[L].lastCount+=I.length):(y[L]&&(y[L].lastCount=I.length),x[L][_]=h(I.length,I.mode)+4+s.getCharCountIndicator(I.mode,E))}}b=P}for(let C=0;C<b.length;C++)x[b[C]].end=0;return{map:x,table:y}}function A(f,E){let y;const x=s.getBestModeForData(f);if(y=s.from(E,x),y!==s.BYTE&&y.bit<x.bit)throw new Error('"'+f+'" cannot be encoded with mode '+s.toString(y)+`.
172
- Suggested mode is: `+s.toString(x));switch(y===s.KANJI&&!c.isKanjiModeEnabled()&&(y=s.BYTE),y){case s.NUMERIC:return new n(f);case s.ALPHANUMERIC:return new r(f);case s.KANJI:return new i(f);case s.BYTE:return new a(f)}}t.fromArray=function(E){return E.reduce(function(y,x){return typeof x=="string"?y.push(A(x,null)):x.data&&y.push(A(x.data,x.mode)),y},[])},t.fromString=function(E,y){const x=u(E,c.isKanjiModeEnabled()),b=k(x),C=j(b,y),S=d.find_path(C.map,"start","end"),P=[];for(let T=1;T<S.length-1;T++)P.push(C.table[S[T]].node);return t.fromArray(p(P))},t.rawSplit=function(E){return t.fromArray(u(E,c.isKanjiModeEnabled()))}})(hn)),hn}var sa;function bm(){if(sa)return Xs;sa=1;const t=Et(),s=Qn(),n=sm(),r=nm(),a=rm(),i=am(),l=om(),c=_o(),d=cm(),m=dm(),g=um(),u=At(),h=gm();function p(C,S){const P=C.size,T=i.getPositions(S);for(let I=0;I<T.length;I++){const _=T[I][0],D=T[I][1];for(let L=-1;L<=7;L++)if(!(_+L<=-1||P<=_+L))for(let z=-1;z<=7;z++)D+z<=-1||P<=D+z||(L>=0&&L<=6&&(z===0||z===6)||z>=0&&z<=6&&(L===0||L===6)||L>=2&&L<=4&&z>=2&&z<=4?C.set(_+L,D+z,!0,!0):C.set(_+L,D+z,!1,!0))}}function k(C){const S=C.size;for(let P=8;P<S-8;P++){const T=P%2===0;C.set(P,6,T,!0),C.set(6,P,T,!0)}}function j(C,S){const P=a.getPositions(S);for(let T=0;T<P.length;T++){const I=P[T][0],_=P[T][1];for(let D=-2;D<=2;D++)for(let L=-2;L<=2;L++)D===-2||D===2||L===-2||L===2||D===0&&L===0?C.set(I+D,_+L,!0,!0):C.set(I+D,_+L,!1,!0)}}function A(C,S){const P=C.size,T=m.getEncodedBits(S);let I,_,D;for(let L=0;L<18;L++)I=Math.floor(L/3),_=L%3+P-8-3,D=(T>>L&1)===1,C.set(I,_,D,!0),C.set(_,I,D,!0)}function f(C,S,P){const T=C.size,I=g.getEncodedBits(S,P);let _,D;for(_=0;_<15;_++)D=(I>>_&1)===1,_<6?C.set(_,8,D,!0):_<8?C.set(_+1,8,D,!0):C.set(T-15+_,8,D,!0),_<8?C.set(8,T-_-1,D,!0):_<9?C.set(8,15-_-1+1,D,!0):C.set(8,15-_-1,D,!0);C.set(T-8,8,1,!0)}function E(C,S){const P=C.size;let T=-1,I=P-1,_=7,D=0;for(let L=P-1;L>0;L-=2)for(L===6&&L--;;){for(let z=0;z<2;z++)if(!C.isReserved(I,L-z)){let Q=!1;D<S.length&&(Q=(S[D]>>>_&1)===1),C.set(I,L-z,Q),_--,_===-1&&(D++,_=7)}if(I+=T,I<0||P<=I){I-=T,T=-T;break}}}function y(C,S,P){const T=new n;P.forEach(function(z){T.put(z.mode.bit,4),T.put(z.getLength(),u.getCharCountIndicator(z.mode,C)),z.write(T)});const I=t.getSymbolTotalCodewords(C),_=c.getTotalCodewordsCount(C,S),D=(I-_)*8;for(T.getLengthInBits()+4<=D&&T.put(0,4);T.getLengthInBits()%8!==0;)T.putBit(0);const L=(D-T.getLengthInBits())/8;for(let z=0;z<L;z++)T.put(z%2?17:236,8);return x(T,C,S)}function x(C,S,P){const T=t.getSymbolTotalCodewords(S),I=c.getTotalCodewordsCount(S,P),_=T-I,D=c.getBlocksCount(S,P),L=T%D,z=D-L,Q=Math.floor(T/D),Y=Math.floor(_/D),X=Y+1,Z=Q-Y,te=new d(Z);let q=0;const F=new Array(D),v=new Array(D);let $=0;const N=new Uint8Array(C.buffer);for(let oe=0;oe<D;oe++){const ie=oe<z?Y:X;F[oe]=N.slice(q,q+ie),v[oe]=te.encode(F[oe]),q+=ie,$=Math.max($,ie)}const W=new Uint8Array(T);let R=0,K,B;for(K=0;K<$;K++)for(B=0;B<D;B++)K<F[B].length&&(W[R++]=F[B][K]);for(K=0;K<Z;K++)for(B=0;B<D;B++)W[R++]=v[B][K];return W}function b(C,S,P,T){let I;if(Array.isArray(C))I=h.fromArray(C);else if(typeof C=="string"){let Q=S;if(!Q){const Y=h.rawSplit(C);Q=m.getBestVersionForData(Y,P)}I=h.fromString(C,Q||40)}else throw new Error("Invalid data");const _=m.getBestVersionForData(I,P);if(!_)throw new Error("The amount of data is too big to be stored in a QR Code");if(!S)S=_;else if(S<_)throw new Error(`
173
- The chosen QR Code version cannot contain this amount of data.
174
- Minimum version required to store current data is: `+_+`.
175
- `);const D=y(S,P,I),L=t.getSymbolSize(S),z=new r(L);return p(z,S),k(z),j(z,S),f(z,P,0),S>=7&&A(z,S),E(z,D),isNaN(T)&&(T=l.getBestMask(z,f.bind(null,z,P))),l.applyMask(T,z),f(z,P,T),{modules:z,version:S,errorCorrectionLevel:P,maskPattern:T,segments:I}}return Xs.create=function(S,P){if(typeof S>"u"||S==="")throw new Error("No input text");let T=s.M,I,_;return typeof P<"u"&&(T=s.from(P.errorCorrectionLevel,s.M),I=m.from(P.version),_=l.from(P.maskPattern),P.toSJISFunc&&t.setToSJISFunction(P.toSJISFunc)),b(S,I,T,_)},Xs}var vn={},wn={},na;function Io(){return na||(na=1,(function(t){function s(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let r=n.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+n);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(i){return[i,i]}))),r.length===6&&r.push("F","F");const a=parseInt(r.join(""),16);return{r:a>>24&255,g:a>>16&255,b:a>>8&255,a:a&255,hex:"#"+r.slice(0,6).join("")}}t.getOptions=function(r){r||(r={}),r.color||(r.color={});const a=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,i=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:i,scale:i?4:l,margin:a,color:{dark:s(r.color.dark||"#000000ff"),light:s(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},t.getScale=function(r,a){return a.width&&a.width>=r+a.margin*2?a.width/(r+a.margin*2):a.scale},t.getImageWidth=function(r,a){const i=t.getScale(r,a);return Math.floor((r+a.margin*2)*i)},t.qrToImageData=function(r,a,i){const l=a.modules.size,c=a.modules.data,d=t.getScale(l,i),m=Math.floor((l+i.margin*2)*d),g=i.margin*d,u=[i.color.light,i.color.dark];for(let h=0;h<m;h++)for(let p=0;p<m;p++){let k=(h*m+p)*4,j=i.color.light;if(h>=g&&p>=g&&h<m-g&&p<m-g){const A=Math.floor((h-g)/d),f=Math.floor((p-g)/d);j=u[c[A*l+f]?1:0]}r[k++]=j.r,r[k++]=j.g,r[k++]=j.b,r[k]=j.a}}})(wn)),wn}var ra;function vm(){return ra||(ra=1,(function(t){const s=Io();function n(a,i,l){a.clearRect(0,0,i.width,i.height),i.style||(i.style={}),i.height=l,i.width=l,i.style.height=l+"px",i.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(i,l,c){let d=c,m=l;typeof d>"u"&&(!l||!l.getContext)&&(d=l,l=void 0),l||(m=r()),d=s.getOptions(d);const g=s.getImageWidth(i.modules.size,d),u=m.getContext("2d"),h=u.createImageData(g,g);return s.qrToImageData(h.data,i,d),n(u,m,g),u.putImageData(h,0,0),m},t.renderToDataURL=function(i,l,c){let d=c;typeof d>"u"&&(!l||!l.getContext)&&(d=l,l=void 0),d||(d={});const m=t.render(i,l,d),g=d.type||"image/png",u=d.rendererOpts||{};return m.toDataURL(g,u.quality)}})(vn)),vn}var yn={},aa;function wm(){if(aa)return yn;aa=1;const t=Io();function s(a,i){const l=a.a/255,c=i+'="'+a.hex+'"';return l<1?c+" "+i+'-opacity="'+l.toFixed(2).slice(1)+'"':c}function n(a,i,l){let c=a+i;return typeof l<"u"&&(c+=" "+l),c}function r(a,i,l){let c="",d=0,m=!1,g=0;for(let u=0;u<a.length;u++){const h=Math.floor(u%i),p=Math.floor(u/i);!h&&!m&&(m=!0),a[u]?(g++,u>0&&h>0&&a[u-1]||(c+=m?n("M",h+l,.5+p+l):n("m",d,0),d=0,m=!1),h+1<i&&a[u+1]||(c+=n("h",g),g=0)):d++}return c}return yn.render=function(i,l,c){const d=t.getOptions(l),m=i.modules.size,g=i.modules.data,u=m+d.margin*2,h=d.color.light.a?"<path "+s(d.color.light,"fill")+' d="M0 0h'+u+"v"+u+'H0z"/>':"",p="<path "+s(d.color.dark,"stroke")+' d="'+r(g,m,d.margin)+'"/>',k='viewBox="0 0 '+u+" "+u+'"',A='<svg xmlns="http://www.w3.org/2000/svg" '+(d.width?'width="'+d.width+'" height="'+d.width+'" ':"")+k+' shape-rendering="crispEdges">'+h+p+`</svg>
176
- `;return typeof c=="function"&&c(null,A),A},yn}var oa;function ym(){if(oa)return Pt;oa=1;const t=tm(),s=bm(),n=vm(),r=wm();function a(i,l,c,d,m){const g=[].slice.call(arguments,1),u=g.length,h=typeof g[u-1]=="function";if(!h&&!t())throw new Error("Callback required as last argument");if(h){if(u<2)throw new Error("Too few arguments provided");u===2?(m=c,c=l,l=d=void 0):u===3&&(l.getContext&&typeof m>"u"?(m=d,d=void 0):(m=d,d=c,c=l,l=void 0))}else{if(u<1)throw new Error("Too few arguments provided");return u===1?(c=l,l=d=void 0):u===2&&!l.getContext&&(d=c,c=l,l=void 0),new Promise(function(p,k){try{const j=s.create(c,d);p(i(j,l,d))}catch(j){k(j)}})}try{const p=s.create(c,d);m(null,i(p,l,d))}catch(p){m(p)}}return Pt.create=s.create,Pt.toCanvas=a.bind(null,n.render),Pt.toDataURL=a.bind(null,n.renderToDataURL),Pt.toString=a.bind(null,function(i,l,c){return r.render(i,c)}),Pt}var jm=ym();function Ro(t){return jm.toDataURL(t,{errorCorrectionLevel:"M",margin:2,scale:8,color:{dark:"#111827ff",light:"#ffffffff"}})}function Nm({title:t,description:s,triggerLabel:n,qrValue:r,displayValue:a,hint:i,imageAlt:l,copyLabel:c,copiedMessage:d}){const[m,g]=o.useState(!1),[u,h]=o.useState(null),[p,k]=o.useState(null);return o.useEffect(()=>{if(!m)return;let j=!1;return h(null),k(null),Ro(r).then(A=>{j||h(A)}).catch(()=>{j||k("QR code unavailable")}),()=>{j=!0}},[m,r]),e.jsxs(wt,{open:m,onOpenChange:g,children:[e.jsx(Ua,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-4 w-4 shrink-0 rounded-sm p-0 text-muted-foreground opacity-70 hover:bg-muted/45 hover:opacity-100 [&_svg]:size-2.5","aria-label":n,title:n,children:e.jsx(lo,{className:"h-3 w-3"})})}),e.jsxs(yt,{className:"max-w-[20rem] gap-2 p-3",children:[e.jsxs(cs,{className:"space-y-1 text-left",children:[e.jsx(Tt,{className:"text-[12px]",children:t}),e.jsx(ds,{children:s})]}),e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("div",{className:"flex h-52 w-52 items-center justify-center rounded-sm bg-white p-2 text-[10px] text-muted-foreground",children:u?e.jsx("img",{src:u,alt:l,className:"h-full w-full"}):p?e.jsx("span",{children:p}):e.jsx(de,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),e.jsx("div",{className:"w-full rounded-sm bg-primary/10 px-2 py-1 text-center text-[10px] font-medium text-foreground",children:i}),e.jsx("div",{className:"w-full rounded-sm bg-muted/45 px-2 py-1.5 font-mono text-[9px] leading-[0.95rem] text-foreground break-all",children:a}),e.jsx(J,{type:"button",variant:"secondary",size:"sm",className:"h-6 w-full border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",onClick:()=>{ls(a,d)},children:c})]})]})]})}function km(t,s){const n=Date.parse(t)-s;if(!Number.isFinite(n)||n<=0)return"expired";const r=Math.ceil(n/1e3),a=Math.floor(r/60),i=r%60;return a>0?`${a}m ${i.toString().padStart(2,"0")}s`:`${r}s`}function Sm(t,s){return t?t.invitation.status==="active"&&Date.parse(t.invitation.expiresAt)<=s?"expired":t.invitation.status:"loading"}function Cm(t){switch(t){case"active":return{label:"Active",tone:"bg-emerald-500/10 text-emerald-500",icon:br};case"consumed":return{label:"Paired",tone:"bg-emerald-500/10 text-emerald-500",icon:Cn};case"expired":return{label:"Expired",tone:"bg-amber-500/10 text-amber-500",icon:Ks};case"cancelled":return{label:"Cancelled",tone:"bg-destructive/10 text-destructive",icon:Ks};case"error":return{label:"Unavailable",tone:"bg-destructive/10 text-destructive",icon:Ks};default:return{label:"Loading",tone:"bg-muted text-muted-foreground",icon:br}}}function Tm({nodeName:t,nodeEndpoint:s}){const[n,r]=o.useState(!1),[a,i]=o.useState(null),[l,c]=o.useState(null),[d,m]=o.useState(null),[g,u]=o.useState(!1),[h,p]=o.useState(()=>Date.now()),k=`Show ${t} mobile pairing QR code`,j=o.useMemo(()=>a?nl(a.qr):null,[a]),A=d?"error":Sm(a,h),f=Cm(A),E=f.icon,y=o.useCallback(async()=>{u(!0),m(null),c(null);try{const x=await rl();i(x),p(Date.now())}catch(x){i(null),m(x instanceof Error?x.message:"Mobile pairing QR unavailable")}finally{u(!1)}},[]);return o.useEffect(()=>{n&&y()},[n,y]),o.useEffect(()=>{if(!n)return;const x=window.setInterval(()=>p(Date.now()),1e3);return()=>window.clearInterval(x)},[n]),o.useEffect(()=>{if(!n||!a||A!=="active")return;let x=!1;const b=window.setInterval(()=>{al(a.invitation.pairingId).then(C=>{x||i(S=>S&&{...S,invitation:C.invitation})}).catch(()=>{x||m("Pairing status unavailable")})},2e3);return()=>{x=!0,window.clearInterval(b)}},[n,a?.invitation.pairingId,A]),o.useEffect(()=>{if(!n||!j)return;let x=!1;return c(null),Ro(j).then(b=>{x||c(b)}).catch(()=>{x||m("QR code unavailable")}),()=>{x=!0}},[n,j]),e.jsxs(wt,{open:n,onOpenChange:r,children:[e.jsx(Ua,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-4 w-4 shrink-0 rounded-sm p-0 text-muted-foreground opacity-70 hover:bg-muted/45 hover:opacity-100 [&_svg]:size-2.5","aria-label":k,title:k,children:e.jsx(lo,{className:"h-3 w-3"})})}),e.jsxs(yt,{className:"max-w-[20rem] gap-2 p-3",children:[e.jsxs(cs,{className:"space-y-1 text-left",children:[e.jsx(Tt,{className:"text-[12px]",children:"Mobile pairing QR"}),e.jsx(ds,{children:t})]}),e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsxs("div",{className:"relative flex h-52 w-52 items-center justify-center rounded-sm bg-white p-2 text-[10px] text-muted-foreground",children:[l?e.jsx("img",{src:l,alt:`${t} mobile pairing QR code`,className:"h-full w-full"}):d?e.jsx("span",{className:"px-3 text-center",children:d}):e.jsx(de,{className:"h-5 w-5 animate-spin text-muted-foreground"}),l&&A!=="active"?e.jsxs("div",{className:"absolute inset-2 flex items-center justify-center rounded-sm bg-background/85 px-3 text-center text-[10px] font-medium text-foreground",children:[f.label,". Refresh to create a new QR."]}):null]}),e.jsxs("div",{className:"grid w-full grid-cols-[1fr_auto] items-center gap-2 rounded-sm bg-muted/45 px-2 py-1.5",children:[e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"truncate font-mono text-[9px] leading-3 text-foreground",children:a?.invitation.apiBaseUrl??s}),e.jsx("div",{className:"text-[9px] leading-3 text-muted-foreground",children:a?`${a.invitation.usedCount}/${a.invitation.maxUses} used - ${km(a.invitation.expiresAt,h)}`:"Creating invitation"})]}),e.jsxs("div",{className:`flex h-5 items-center gap-1 rounded-sm px-1.5 text-[9px] font-medium ${f.tone}`,children:[e.jsx(E,{className:"h-3 w-3"}),f.label]})]}),e.jsx("div",{className:"w-full rounded-sm bg-primary/10 px-2 py-1 text-center text-[10px] font-medium text-foreground",children:"Scan with Meshy Mobile"}),e.jsxs("div",{className:"grid w-full grid-cols-2 gap-2",children:[e.jsx(J,{type:"button",variant:"secondary",size:"sm",className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",onClick:()=>{ls(a?.invitation.apiBaseUrl??s,"Node URL copied")},children:"Copy URL"}),e.jsxs(J,{type:"button",variant:"secondary",size:"sm",className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",disabled:g,onClick:()=>{y()},children:[g?e.jsx(de,{className:"mr-1 h-3 w-3 animate-spin"}):e.jsx($a,{className:"mr-1 h-3 w-3"}),"Refresh"]})]})]})]})]})}function Em({nodeName:t,dashboardUrl:s}){const n=`Show ${t} dashboard QR code`;return e.jsx(Nm,{title:"Dashboard URL QR",description:t,triggerLabel:n,qrValue:s,displayValue:s,hint:"Scan with Edge to view the dashboard",imageAlt:`${t} dashboard URL QR code`,copyLabel:"Copy dashboard URL",copiedMessage:"Dashboard URL copied"})}function Yn({nodeId:t,nodeName:s,onOpenSettings:n,onOpenServicePreview:r,onOpenCapabilities:a,onOpenDevBox:i,onStartDevBox:l,onToggleRemoteAccess:c,remoteAccessLabel:d,remoteAccessPending:m,remoteAccessDisabled:g,remoteAccessDisabledReason:u,showConfigureDevBox:h,showStartDevBox:p,startDevBoxPending:k,className:j}){const[A,f]=o.useState(!1),[E,y]=o.useState(null),x=o.useRef(null),b=o.useRef(null),C=k?"Starting":"Start DevBox",S=d?.startsWith("Disable")?ol:wd;o.useLayoutEffect(()=>{if(!A){y(null);return}const T=()=>{const I=b.current,_=x.current;if(!I||!_)return;const D=I.getBoundingClientRect(),L=_.getBoundingClientRect();y(Dm({left:D.left,right:D.right,bottom:D.bottom,top:D.top},{width:L.width,height:L.height},{width:window.innerWidth,height:window.innerHeight},_m()))};return T(),window.addEventListener("resize",T),window.addEventListener("scroll",T,!0),()=>{window.removeEventListener("resize",T),window.removeEventListener("scroll",T,!0)}},[A]),o.useEffect(()=>{if(!A)return;const T=_=>{const D=_.target;D instanceof Node&&!x.current?.contains(D)&&!b.current?.contains(D)&&f(!1)},I=_=>{_.key==="Escape"&&f(!1)};return document.addEventListener("mousedown",T),document.addEventListener("keydown",I),()=>{document.removeEventListener("mousedown",T),document.removeEventListener("keydown",I)}},[A]);const P=A?e.jsxs("div",{ref:x,"data-node-action-menu-portal":"true",role:"menu",style:Am(E),onClick:T=>T.stopPropagation(),onPointerDown:T=>T.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:T=>{T.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(il,{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:T=>{T.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(io,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Preview service"})]}),a&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} capabilities`,title:`Open ${s} capabilities`,onClick:T=>{T.stopPropagation(),f(!1),a(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(_s,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Capabilities"})]}),d&&c&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${d} for ${s}`,title:u??`${d} for ${s}`,onClick:T=>{T.stopPropagation(),!(m||g)&&(f(!1),c())},disabled:m||g,className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80 disabled:cursor-not-allowed disabled:opacity-60",children:[m?e.jsx(de,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(S,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:d})]}),p&&l&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${C} for ${s}`,title:`${C} for ${s}`,onClick:T=>{T.stopPropagation(),!k&&(f(!1),l(t))},disabled:k,className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80 disabled:cursor-not-allowed disabled:opacity-60",children:[k?e.jsx(de,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(Ms,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:C})]}),h&&i&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${s}`,title:`Configure DevBox for ${s}`,onClick:T=>{T.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(ll,{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:O("relative shrink-0",A&&"z-[120]",j),onClick:T=>T.stopPropagation(),onPointerDown:T=>T.stopPropagation(),children:[e.jsx(J,{ref:b,type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${s}`,"aria-haspopup":"menu","aria-expanded":A,title:`More actions for ${s}`,onClick:T=>{T.stopPropagation(),f(I=>(I||y(null),!I))},className:O("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",A&&"bg-background/80 text-primary"),children:e.jsx($c,{className:"h-3.5 w-3.5"})}),P&&(typeof document>"u"?P:qa.createPortal(P,document.body))]})}function Am(t){return t?{left:t.left,top:t.top}:{left:0,top:0,visibility:"hidden"}}function Dm(t,s,n,r=1){const l=s.width||160,c=s.height||0,d=Number.isFinite(r)&&r>0?r:1,m=Math.max(8,Math.min(t.right-l,n.width-l-8)),g=t.bottom+4,u=(t.top??t.bottom)-c-4,h=g+c>n.height-8&&u>=8?u:g;return{left:Math.round(m/d),top:Math.round(h/d)}}function _m(){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 Mm=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),Pm=new Set(["startinprogress","starting"]);function Rt(t){return!!(t?.enabled&&t.name)}function Im(t){const s=t?.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&Mm.has(s))}function Lt(t){const s=t?.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&Pm.has(s))}function Rs(t,s,n){return t==="offline"&&Im(s)&&Rt(n)}function ia(t,s){return t==="offline"&&Rt(s)}function la(t){return!Rt(t)}function Rm({nodeStatus:t,status:s,current:n,selected:r}){const a=r??n;return a&&Rs(t,s,a)?a:null}function Ue(t){return t.scope||`name:${t.name??""}`}function Lm({previousKey:t,baseDevBox:s,listed:n}){if(t&&n.some(i=>Ue(i)===t))return t;if(!Rt(s))return n[0]?Ue(n[0]):"";const r=Ue(s),a=n.find(i=>Ue(i)===r)??n.find(i=>i.name===s.name);return a?Ue(a):r}function Bm(t){return t==="nodes"||t==="events"?t:"overview"}function Om({cluster:t,systemInfo:s,nodeNameById:n,nodeBlockingTaskCounts:r,eventTypeFilter:a,onEventTypeFilterChange:i,eventTypeOptions:l,filteredEvents:c,sseConnected:d,clusterLoading:m,clusterError:g,promotePending:u,onPromote:h,onAddNode:p,leavePending:k,onLeaveCluster:j,onToggleNodeDevTunnel:A,devTunnelNodeId:f,devBoxStartNodeId:E,devBoxStartingNodeIds:y=new Set,activeTab:x,onTabChange:b,onOpenNodeSettings:C,onOpenNodeCapabilities:S,onOpenDevBox:P,onStartDevBox:T}){const I=t?.self?.role==="leader",_=t?.self?.role==="follower"&&!t?.leader,D=t?.self??null,z=cl(t?.nodes??[],D?.id).filter(R=>R.id!==D?.id),Q=t?.leader?t.nodes.find(R=>R.id===t.leader?.id)??null:null,Y=t?.leader?t.leader.dashboardOrigin??Q?.dashboardOrigin??(s&&t.leader.id===(s.nodeId??s.id)?s.dashboardOrigin:void 0)??t.leader.endpoint:null,X=t?.leader?Q?.devtunnelEndpoint??t.leader.endpoint:null,Z=t?.leader?.name??Q?.name??"Leader",te=!!(t?.leader?.id&&t.leader.id===D?.id),q=D?.role==="leader"&&z.length===0,F=D?.role==="follower",[v,$]=o.useState("overview"),N=x??v;function W(R){const K=Bm(R);$(K),b?.(K)}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(Un,{value:N,onValueChange:W,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(zn,{className:"grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(St,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(St,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(St,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})}),e.jsx(ft,{value:"overview",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-2 py-2",children:e.jsxs("div",{className:"space-y-2.5",children:[D&&e.jsx(ca,{node:D,systemInfo:s,blockingTaskCount:r.get(D.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:A,showActions:!1,defaultExpanded:!1,onOpenDevBox:P,devBoxStartingNodeIds:y}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"Cluster snapshot"}),e.jsx(Ve,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:d?"Connected":"Reconnecting"})]}),m&&!t?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(de,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):g&&!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:g}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(Mt,{label:"Term",value:String(t?.term??0)}),e.jsx(Mt,{label:"Nodes",value:String(t?.nodes.length??0)}),e.jsx(Mt,{label:"Pending",value:String(t?.taskSummary.pending??0)}),e.jsx(Mt,{label:"Running",value:String(t?.taskSummary.running??0)}),e.jsx(Mt,{label:"Completed",value:String(t?.taskSummary.completed??0)}),e.jsx(Mt,{label:"Failed",value:String(t?.taskSummary.failed??0)})]}),e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-muted/45 px-2 py-2 shadow-none",children:[e.jsx(tt,{label:"Leader",value:t?.leader?.name??"None"}),e.jsx(tt,{label:"Leader Dashboard URL",value:Y??"Unavailable",mono:!0,action:Y?e.jsx(Zn,{nodeName:Z,dashboardUrl:Y,copyLabel:"Copy leader dashboard URL",copiedMessage:"Leader Dashboard URL copied"}):void 0}),X&&e.jsx(tt,{label:"Leader Node URL",value:X,mono:!0,action:e.jsx(Jn,{nodeName:Z,nodeEndpoint:X,copyLabel:"Copy leader node URL",copiedMessage:"Leader Node URL copied",showPairingQr:te})}),e.jsx(tt,{label:"Feed",value:d?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:_&&e.jsxs(J,{variant:"secondary",size:"sm",onClick:h,disabled:u,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[u&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(ft,{value:"nodes",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-2 py-2",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"This node"}),q?e.jsxs(J,{variant:"secondary",size:"sm",onClick:p,className:"h-6 border-0 bg-primary px-2 text-[10px] text-primary-foreground shadow-none hover:bg-primary/90",children:[e.jsx(bd,{className:"h-3 w-3"}),"Join node"]}):F?e.jsxs(J,{variant:"secondary",size:"sm",onClick:j,disabled:k,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[k&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),D&&e.jsx(ca,{node:D,systemInfo:s,blockingTaskCount:r.get(D.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:A,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:I?C:void 0,onOpenNodeCapabilities:I?S:void 0,onOpenDevBox:I?P:void 0,onStartDevBox:I?T:void 0,devBoxStartNodeId:E,devBoxStartingNodeIds:y})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",z.length,")"]}),z.length>0?e.jsx("div",{className:"space-y-1.5",children:z.map(R=>e.jsx(Fm,{node:R,isLeader:!!I,blockingTaskCount:r.get(R.id)??0,devTunnelNodeId:f,onToggleNodeDevTunnel:A,onOpenNodeSettings:I?C:void 0,onOpenNodeCapabilities:I?S:void 0,onOpenDevBox:I?P:void 0,onStartDevBox:I?T:void 0,devBoxStartNodeId:E,devBoxStartingNodeIds:y},R.id))}):e.jsx("div",{className:"rounded-sm bg-muted/45 px-2 py-2 text-[10px] text-muted-foreground shadow-none",children:"No peer nodes are connected yet."})]})]})})}),e.jsx(ft,{value:"events",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col px-2 py-2",children:[e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-foreground",children:[e.jsx(dl,{className:O("h-3.5 w-3.5",d?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(_e,{value:a,onValueChange:i,children:[e.jsx(Me,{className:"h-6 min-w-[10rem] flex-1 rounded-sm border-0 bg-muted/60 text-[10px] shadow-none sm:max-w-[14rem] [&>svg]:h-3 [&>svg]:w-3",children:e.jsx($e,{placeholder:"Event type"})}),e.jsx(Pe,{className:"shadow-none",children:l.map(R=>e.jsx(De,{value:R,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:R==="all"?"All event types":R},R))})]}),e.jsx(Ve,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:d?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(ul,{events:c,maxHeight:"100%",emptyTitle:a==="all"?"No live events yet":"No matching events",emptyDescription:a==="all"?"Cluster activity appears here as it happens.":`No "${a}" events are in the current stream.`,nodeNameById:n,density:"compact"})})]})})]})})}function ca({node:t,systemInfo:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:a,showActions:i=!0,defaultExpanded:l=!1,onOpenNodeSettings:c,onOpenNodeCapabilities:d,onOpenDevBox:m,onStartDevBox:g,devBoxStartNodeId:u,devBoxStartingNodeIds:h}){const[p,k]=o.useState(l),j=s?.dashboardOrigin??t.dashboardOrigin,A=t.devtunnelEndpoint??t.endpoint,f=j??t.endpoint,E=s?.workDir??t.workDir,y=ho(t,s?.transportType),x=Gn(t,s?.transportType),b=x&&Ft(s?.transportType??t.transportType)?!0:mo(t,s?.transportType),C=n>0;return e.jsxs("section",{className:"dashboard-operations-node-card bg-primary/8 shadow-none",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>k(S=>!S),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[p?e.jsx(Je,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(st,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(Va,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Current node"})]}),e.jsx("a",{href:f,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(qn,{className:"h-3 w-3"})}),(c||d||i&&b)&&e.jsx(Yn,{nodeId:t.id,nodeName:t.name,onOpenSettings:c,onOpenCapabilities:d,onOpenDevBox:m,onStartDevBox:g,onToggleRemoteAccess:i&&b?()=>a(t):void 0,remoteAccessLabel:i&&b?x?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:C,remoteAccessDisabledReason:C?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:t.devbox?.enabled,showStartDevBox:Rs(t.status,t.devbox?.lastStatus,t.devbox)||Lt(t.devbox?.lastStatus)||h.has(t.id),startDevBoxPending:u===t.id||Lt(t.devbox?.lastStatus)||h.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>k(S=>!S),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(Ha,{role:t.role,size:"compact"}),e.jsx(Ve,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),p&&e.jsxs("div",{className:"space-y-2 bg-primary/5 px-2.5 pb-2.5 pt-1.5",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-muted/45 px-2 py-1.5 shadow-none",children:[e.jsx(tt,{label:"Node ID",value:t.id,mono:!0}),j&&e.jsx(tt,{label:"Dashboard",value:j,mono:!0,action:e.jsx(Zn,{nodeName:t.name,dashboardUrl:j})}),e.jsx(tt,{label:"Node URL",value:A,mono:!0,action:e.jsx(Jn,{nodeName:t.name,nodeEndpoint:A})}),E&&e.jsx(tt,{label:"Workspace",value:E,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Dn,{label:"Transport",value:y}),s&&e.jsx(Dn,{label:"Uptime",value:ml(s.uptime),mono:!0})]}),i&&d&&e.jsxs(J,{variant:"secondary",size:"sm",onClick:()=>d(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(_s,{className:"h-3 w-3"}),"Capabilities"]}),i&&b&&C&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Fm({node:t,isLeader:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:a,onOpenNodeSettings:i,onOpenNodeCapabilities:l,onOpenDevBox:c,onStartDevBox:d,devBoxStartNodeId:m,devBoxStartingNodeIds:g}){const[u,h]=o.useState(!1),p=t.dashboardOrigin,k=t.devtunnelEndpoint??t.endpoint,j=p??t.endpoint,A=ho(t),f=Gn(t),E=mo(t),y=n>0;return e.jsxs("div",{className:"dashboard-operations-node-card bg-muted/45 shadow-none",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>h(x=>!x),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[u?e.jsx(Je,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(st,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Va,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Peer node"})]}),e.jsx("a",{href:j,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(qn,{className:"h-3 w-3"})}),s&&(i||l||E)&&e.jsx(Yn,{nodeId:t.id,nodeName:t.name,onOpenSettings:i,onOpenCapabilities:l,onOpenDevBox:c,onStartDevBox:d,onToggleRemoteAccess:E?()=>a(t):void 0,remoteAccessLabel:E?f?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:y,remoteAccessDisabledReason:y?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:t.devbox?.enabled,showStartDevBox:Rs(t.status,t.devbox?.lastStatus,t.devbox)||Lt(t.devbox?.lastStatus)||g.has(t.id),startDevBoxPending:m===t.id||Lt(t.devbox?.lastStatus)||g.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>h(x=>!x),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(Ha,{role:t.role,size:"compact"}),e.jsx(Ve,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),u&&e.jsxs("div",{className:"space-y-2 bg-muted/35 px-2.5 pb-2.5 pt-1.5",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/55 px-2 py-1.5 shadow-none",children:[e.jsx(tt,{label:"Node ID",value:t.id,mono:!0}),p&&e.jsx(tt,{label:"Dashboard",value:p,mono:!0,action:e.jsx(Zn,{nodeName:t.name,dashboardUrl:p})}),e.jsx(tt,{label:"Node URL",value:k,mono:!0,action:e.jsx(Jn,{nodeName:t.name,nodeEndpoint:k,showPairingQr:!1})}),t.workDir&&e.jsx(tt,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(Dn,{label:"Transport",value:A})]}),s&&l&&e.jsxs(J,{variant:"secondary",size:"sm",onClick:()=>l(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(_s,{className:"h-3 w-3"}),"Capabilities"]}),s&&E&&y&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Jn({nodeName:t,nodeEndpoint:s,copyLabel:n="Copy node URL",copiedMessage:r="Node URL copied",showPairingQr:a=!0}){return e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[a?e.jsx(Tm,{nodeName:t,nodeEndpoint:s}):null,e.jsx(Lo,{label:n,onClick:()=>{ls(s,r)}})]})}function Zn({nodeName:t,dashboardUrl:s,copyLabel:n="Copy dashboard URL",copiedMessage:r="Dashboard URL copied"}){return e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(Em,{nodeName:t,dashboardUrl:s}),e.jsx(Lo,{label:n,onClick:()=>{ls(s,r)}})]})}function Lo({label:t,onClick:s}){return e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-4 w-4 shrink-0 rounded-sm p-0 text-muted-foreground opacity-70 hover:bg-muted/45 hover:opacity-100 [&_svg]:size-2.5",onClick:s,"aria-label":t,title:t,children:e.jsx(Oa,{className:"h-3 w-3"})})}function zm(t,s,n,r){if(!t)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const a=s?.self?.role==="follower",i=t.assignedTo?s?.self?.id===t.assignedTo?s.self:s?.nodes.find(c=>c.id===t.assignedTo):void 0;return t.assignedTo!==null&&(i?i.status==="offline":s?t.assignedNodeAvailable===!1||!s.nodes.some(c=>c.id===t.assignedTo):t.assignedNodeAvailable===!1)?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${t.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}:a?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Follower nodes are read-only. Use the leader dashboard to manage chat, or leave the cluster first."}:n?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Sending message..."}:r?{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Queue a message for the next turn..."}:ks.has(t.status)||t.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:ks.has(t.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const Bo=.5,Oo=1.75,da=.1;function Um({node:t,open:s,onOpenChange:n}){const[r,a]=o.useState(gs),[i,l]=o.useState(null),[c,d]=o.useState(1),[m,g]=o.useState(!1),[u,h]=o.useState(null);o.useEffect(()=>{a(gs),l(null),d(1),g(!1),h(null)},[t?.id,s]);const p=o.useCallback(async y=>{if(!t)return;const x=y??Number.parseInt(r.trim()||gs,10);if(!Number.isInteger(x)||x<1||x>65535){h("Enter a port between 1 and 65535");return}g(!0),h(null);try{const b=await hl(t.id,{port:x});l(b),a(String(x)),lr("preview.created",{result:"success",previewType:"service-port"})}catch(b){h(b instanceof Error?b.message:"Failed to create service preview"),lr("preview.failed",{result:"failed",previewType:"service-port"})}finally{g(!1)}},[t,r]),k=o.useCallback(()=>{typeof i?.port=="number"&&p(i.port)},[i?.port,p]);o.useEffect(()=>{if(!i)return;const y=i.expiresAt-Date.now()-5e3;if(y<=0){k();return}const x=window.setTimeout(k,y);return()=>window.clearTimeout(x)},[k,i]);const j=i?Ac(i):null,A=t?.name??"Node",f=$m(c),E={width:`${100/c}%`,height:`${100/c}%`,transform:`scale(${c})`,transformOrigin:"top left"};return e.jsx(wt,{open:s,onOpenChange:n,children:e.jsxs(yt,{onOpenAutoFocus:y=>y.preventDefault(),className:"flex h-[min(82vh,44rem)] max-w-[min(92vw,72rem)] flex-col gap-0 overflow-hidden p-0",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border/60 px-3 py-2 pr-9",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(Tt,{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold text-foreground",children:[e.jsx(io,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0",children:"Preview service"}),e.jsx("span",{className:"min-w-0 truncate font-mono text-[10px] font-medium text-muted-foreground",children:A})]}),e.jsx(ds,{className:"sr-only",children:"Preview a service port running on the selected node."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("form",{className:"flex items-center gap-1.5",onSubmit:y=>{y.preventDefault(),p()},children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:["Port",e.jsx(ot,{type:"text",min:1,max:65535,inputMode:"numeric",value:r,onChange:y=>a(y.target.value),placeholder:gs,"aria-label":"Node service preview port",className:"h-6 w-20 rounded-sm border-0 bg-muted/55 px-2 text-[11px] shadow-none focus:bg-muted/55 focus:outline-none focus-visible:border-0 focus-visible:bg-muted/55 focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsxs(J,{type:"submit",variant:"ghost",size:"sm",disabled:m,className:"h-6 rounded-sm border-0 bg-primary/10 px-2 text-[11px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[m?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ms,{className:"h-3.5 w-3.5"}),"Preview"]})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden shrink-0 text-[10px] text-muted-foreground sm:inline",children:qm(i.expiresAt)}),e.jsxs("div",{className:"flex h-6 shrink-0 items-center overflow-hidden rounded-sm border border-border/55 bg-muted/35",children:[e.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>d(y=>ua(y,-da)),disabled:c<=Bo,title:"Zoom out","aria-label":"Zoom out preview",children:e.jsx(kd,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>d(1),className:"h-6 min-w-11 border-x border-border/45 px-1.5 text-center font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted/55 hover:text-foreground",title:"Reset zoom","aria-label":"Reset preview zoom",children:f}),e.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>d(y=>ua(y,da)),disabled:c>=Oo,title:"Zoom in","aria-label":"Zoom in preview",children:e.jsx(jd,{className:"h-3.5 w-3.5"})})]}),e.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:k,title:"Refresh",children:e.jsx($a,{className:"h-3.5 w-3.5"})}),e.jsx(J,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",asChild:!0,title:"Open in new tab",children:e.jsx("a",{href:j??i.previewUrl,target:"_blank",rel:"noopener noreferrer",children:e.jsx(qn,{className:"h-3.5 w-3.5"})})})]})]})]}),u&&e.jsx("div",{className:"shrink-0 border-b border-destructive/20 bg-destructive/5 px-3 py-1.5 text-[11px] text-destructive",children:u}),e.jsx("div",{className:"min-h-0 flex-1 p-2",children:i?e.jsx("div",{className:"h-full overflow-hidden rounded-sm border border-border/60 bg-white shadow-none",children:e.jsx("iframe",{src:_c(i),style:E,className:"h-full w-full border-0",sandbox:Dc(i),title:`${A} Service Preview`})}):e.jsx("div",{className:"flex h-full min-h-56 items-center justify-center rounded-sm border border-dashed border-border/65 bg-background/35 px-3 text-center text-[11px] text-muted-foreground",children:"No service preview running."})})]})})}function ua(t,s){return Fo(Math.round((t+s)*100)/100)}function Fo(t){return Number.isFinite(t)?Math.min(Oo,Math.max(Bo,t)):1}function $m(t){return`${Math.round(Fo(t)*100)}%`}function qm(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 Vm({dirPath:t,label:s,taskCount:n,collapsed:r,onToggle:a,onCreateTask:i,onOpenCapabilities:l}){return e.jsxs("div",{className:"group/project-row flex w-full items-stretch rounded-sm bg-muted/15 text-[9px] font-medium text-muted-foreground/70 transition-all duration-150 hover:bg-muted/30 hover:text-foreground active:scale-[0.98] active:bg-muted/40",children:[e.jsxs("button",{type:"button",onClick:a,"aria-expanded":!r,title:t,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-l-sm px-2 py-1 text-left",children:[e.jsx(st,{className:O("h-3 w-3 shrink-0 transition-transform duration-200",!r&&"rotate-90")}),e.jsx(Bt,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:s}),e.jsx("span",{className:"ml-2 shrink-0 rounded-sm bg-background/55 px-1 py-0 tabular-nums text-[8px] font-medium leading-3 text-muted-foreground/45",children:n})]}),l&&e.jsx("button",{type:"button",onClick:l,"aria-label":`Capabilities for ${t}`,title:`Capabilities for ${t}`,className:"pointer-events-none mr-0.5 flex h-4 w-4 shrink-0 translate-y-px self-center items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-all hover:bg-primary/10 hover:text-primary focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/project-row:pointer-events-auto group-hover/project-row:opacity-100",children:e.jsx(_s,{className:"h-2.5 w-2.5"})}),e.jsx("button",{type:"button",onClick:i,"aria-label":`New chat in ${t}`,title:`New chat in ${t}`,className:"pointer-events-none ml-auto flex h-4 w-4 shrink-0 translate-y-px self-center items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-all hover:bg-primary/10 hover:text-primary focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/project-row:pointer-events-auto group-hover/project-row:opacity-100",children:e.jsx(Is,{className:"h-2.5 w-2.5"})})]})}const zo="meshy-task-sidebar-tree-state";function ma(t){return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function jn(){try{return globalThis.window?.localStorage??globalThis.localStorage??null}catch{return null}}function ha(t){if(!t)return{collapsedNodes:[],collapsedDirs:[]};try{const s=t.getItem(zo);if(!s)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(s);return{collapsedNodes:ma(n.collapsedNodes),collapsedDirs:ma(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Hm(t,s){if(t)try{t.setItem(zo,JSON.stringify(s))}catch{}}function fa(t,s){if(!t.has(s))return t;const n=new Set(t);return n.delete(s),n}function Km(t,s){if(!s)return null;for(const n of t){const r=n.nodeId??"__unassigned__";for(const a of n.dirs)if(a.tasks.some(i=>i.id===s))return{nodeKey:r,dirKey:`${r}::${a.path}`}}return null}function xa(t,s,n){return n?{collapsedNodes:fa(t,n.nodeKey),collapsedDirs:fa(s,n.dirKey)}:{collapsedNodes:t,collapsedDirs:s}}function Gm(t,s,n){const r=t.filter(c=>c.status==="completed"),a=new Set((s?r:[...r].sort((c,d)=>d.updatedAt-c.updatedAt).slice(0,Vn)).map(c=>c.id));n&&r.some(c=>c.id===n)&&a.add(n);const i=t.filter(c=>c.status!=="completed"||a.has(c.id)),l=r.length-a.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,l)}}const ws="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",ys="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function pa({toolbarTasks:t,activeTaskId:s,tasksLoading:n,tasksError:r,isLeader:a,scope:i,agentFilter:l,nodeFilter:c,taskKindFilter:d,agentOptions:m,nodeOptions:g,nodeNameById:u,nodeWorkDirById:h,nodeStatusById:p,completedGroupByKey:k,devBoxNodeIds:j=new Set,devBoxStartNodeIds:A=new Set,devBoxStartingNodeIds:f=new Set,leaderNodeId:E,searchQuery:y,selectedTaskIds:x,allVisibleTasksSelected:b,someVisibleTasksSelected:C,canBatchArchive:S,onScopeChange:P,onAgentFilterChange:T,onNodeFilterChange:I,onTaskKindFilterChange:_,onToggleTaskSelected:D,onToggleAllVisibleTasks:L,onBatchArchive:z,onBatchDelete:Q,onCreateTask:Y,onOpenNodeSettings:X,onOpenNodeCapabilities:Z,onOpenProjectCapabilities:te,onOpenDevBox:q,onStartDevBox:F,onLoadCompletedTasks:v,onSelectTask:$}){const[N,W]=o.useState(!1),[R,K]=o.useState(()=>x.size>0),[B,oe]=o.useState(!1),[ie,he]=o.useState(null),{markScrollbarActive:ae,scrollbarActive:G}=To(),M=x.size,ne=!!(a&&(R||M>0)),V=i!=="active"||c!=="all"||l!=="all"||d!=="all",re=y.trim().length>0,[we,fe]=o.useState(()=>new Set(ha(jn()).collapsedNodes)),[Ie,Ee]=o.useState(()=>new Set(ha(jn()).collapsedDirs)),[xt,Le]=o.useState(new Set),Ze=o.useMemo(()=>fl({nodeStatusById:p,nodeNameById:u,nodeWorkDirById:h,nodeFilter:c,searchQuery:y}),[p,u,h,c,y]),Se=o.useMemo(()=>xl(t,u,E,h,Ze),[t,u,E,h,Ze]),He=o.useMemo(()=>Km(Se,s),[Se,s]),We=o.useRef(null),Ke=Se.length===1,Oe=Se.length>0,lt=Ke&&(V||re),ct=!!(a&&(t.length>0||M>0)),ee=o.useCallback(H=>{fe(ke=>{const Ae=new Set(ke);return Ae.has(H)?Ae.delete(H):Ae.add(H),Ae})},[]),ge=o.useCallback(H=>{Ee(ke=>{const Ae=new Set(ke);return Ae.has(H)?Ae.delete(H):Ae.add(H),Ae})},[]),ye=o.useCallback(H=>{Le(ke=>{const Ae=new Set(ke);return Ae.add(H),Ae})},[]);o.useEffect(()=>{Hm(jn(),{collapsedNodes:Array.from(we),collapsedDirs:Array.from(Ie)})},[Ie,we]),o.useEffect(()=>{if(!He||!s)return;const H=`${s}:${He.nodeKey}:${He.dirKey}`;We.current!==H&&(We.current=H,fe(ke=>xa(ke,new Set,He).collapsedNodes),Ee(ke=>xa(new Set,ke,He).collapsedDirs))},[s,He]);const Fe=o.useCallback(H=>{K(!0),L(H)},[L]),ze=o.useCallback(H=>{if(H===!0&&!b){K(!0),oe(!0);return}Fe(H===!0)},[b,Fe]),Ne=o.useCallback(()=>{Fe(!0),oe(!1)},[Fe]),je=o.useCallback(()=>{L(!1),K(!1),oe(!1)},[L]);o.useEffect(()=>{a||(K(!1),oe(!1))},[a]);const pt=ne?e.jsxs(Yt,{open:B,onOpenChange:oe,children:[e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(is,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:C&&!b?"indeterminate":b,onCheckedChange:ze,"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Select all"})]}),B&&e.jsxs(Jt,{children:[e.jsxs(Zt,{children:[e.jsx(Xt,{children:"Select every visible task?"}),e.jsx(es,{children:"This will select every task currently shown in the rail and expose bulk archive/delete actions. Cancel now unless you intend to act on all visible tasks together."})]}),e.jsxs(ts,{children:[e.jsx(ss,{autoFocus:!0,children:"Cancel"}),e.jsx(ns,{onClick:Ne,children:"Select all"})]})]})]}):e.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>K(!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(wc,{className:"h-3 w-3"}),"Multi select"]}),zt=M>0?e.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"text-[9px] font-semibold leading-3 text-foreground",children:[M," task",M!==1?"s":""," selected"]}),!S&&e.jsx("div",{className:"max-w-48 text-[9px] leading-3.5 text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."})]}):null,Ut=M>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(Yt,{children:[e.jsx(Tn,{asChild:!0,children:e.jsxs(J,{variant:"ghost",size:"sm",disabled:!S,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(Pc,{}),"Archive"]})}),e.jsxs(Jt,{children:[e.jsxs(Zt,{children:[e.jsxs(Xt,{children:["Archive ",M," selected task",M!==1?"s":"","?"]}),e.jsx(es,{children:"These tasks leave the default view immediately. Cancel if any selected task still needs to stay visible in active work."})]}),e.jsxs(ts,{children:[e.jsx(ss,{autoFocus:!0,children:"Cancel"}),e.jsx(ns,{onClick:z,disabled:!S,children:"Archive"})]})]})]}),e.jsxs(Yt,{children:[e.jsx(Tn,{asChild:!0,children:e.jsxs(J,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(Ga,{}),"Delete"]})}),e.jsxs(Jt,{children:[e.jsxs(Zt,{children:[e.jsxs(Xt,{children:["Delete ",M," selected task",M!==1?"s":""," and saved logs?"]}),e.jsx(es,{children:"This cannot be undone. Cancel unless you are certain every selected task and log should be removed now."})]}),e.jsxs(ts,{children:[e.jsx(ss,{autoFocus:!0,children:"Cancel"}),e.jsx(ns,{onClick:Q,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"dashboard-task-sidebar dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"dashboard-task-sidebar__header shrink-0 bg-card/24 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex min-w-0 items-stretch gap-1.5",children:[e.jsxs(J,{onClick:()=>Y("chat"),className:"h-8 w-[6.75rem] justify-start rounded-sm px-2.5 text-left text-[11px] shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(Is,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsxs(J,{variant:"outline",onClick:()=>Y("native"),className:"h-8 w-[7.75rem] justify-start rounded-sm border-0 bg-muted/45 px-2.5 text-left text-[11px] text-foreground shadow-none hover:bg-muted/65 hover:text-foreground",children:[e.jsx(Kn,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Load session"]})]}),e.jsx(J,{variant:"ghost",size:"icon",onClick:()=>W(H=>!H),className:O("ml-auto h-8 w-8 shrink-0 rounded-sm text-muted-foreground shadow-none hover:bg-muted/55 hover:text-foreground",(N||V)&&"bg-primary/8 text-primary hover:bg-primary/12 hover:text-primary"),title:"Filters",children:e.jsx(Gc,{className:"h-3.5 w-3.5"})})]}),(N||V)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(_e,{value:i,onValueChange:H=>P(H),children:[e.jsx(Me,{className:ws,children:e.jsx($e,{})}),e.jsx(Pe,{children:pl.map(H=>e.jsx(De,{value:H.value,className:ys,children:H.label},H.value))})]}),e.jsxs(_e,{value:c,onValueChange:I,children:[e.jsx(Me,{className:ws,children:e.jsx($e,{placeholder:"Node"})}),e.jsx(Pe,{children:g.map(H=>e.jsx(De,{value:H.value,className:ys,children:H.label},H.value))})]}),e.jsxs(_e,{value:l,onValueChange:T,children:[e.jsx(Me,{className:ws,children:e.jsx($e,{placeholder:"Agent"})}),e.jsx(Pe,{children:m.map(H=>e.jsx(De,{value:H,className:ys,children:H==="all"?"All agents":H},H))})]}),e.jsxs(_e,{value:d,onValueChange:H=>_(H),children:[e.jsx(Me,{className:ws,children:e.jsx($e,{placeholder:"Type"})}),e.jsx(Pe,{children:gl.map(H=>e.jsx(De,{value:H.value,className:ys,children:H.label},H.value))})]})]})]}),e.jsx("div",{className:O("scrollbar-line min-h-0 flex-1 overflow-y-auto pl-2.5 pr-1.5 py-2",G&&"scrollbar-line-active"),onScroll:ae,children:Se.length>0?e.jsx("div",{className:"space-y-1",children:Se.map(H=>{const ke=H.nodeId??"__unassigned__",Ae=H.dirs.reduce((Be,Qe)=>Be+Qe.tasks.length,0),jt=Oe&&!lt&&we.has(ke),$t=H.nodeId!==null&&p.get(H.nodeId)==="offline",Nt=!!(a&&H.nodeId);return e.jsxs("div",{className:"space-y-1",children:[Oe&&e.jsxs("div",{className:"flex w-full items-stretch rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 text-left text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsxs("button",{type:"button",onClick:()=>ee(ke),"aria-expanded":!jt,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(st,{className:O("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!jt&&"rotate-90")}),e.jsx(Ia,{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:H.nodeName}),e.jsxs(Ve,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-transparent bg-background/55 px-1.5 py-0 text-[7px] font-semibold leading-3.5 text-muted-foreground shadow-none normal-case tracking-normal",children:[Ae," task",Ae===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[$t&&e.jsx(Ve,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/10 px-1 py-0 text-[8px] font-semibold leading-3 text-destructive shadow-none",children:"offline"}),H.nodeId===E&&e.jsx(Ve,{variant:"outline",className:"rounded-sm border-transparent bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"})]})]}),Nt&&H.nodeId&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(Yn,{nodeId:H.nodeId,nodeName:H.nodeName,onOpenSettings:X,onOpenServicePreview:()=>he({id:H.nodeId,name:H.nodeName}),onOpenCapabilities:Z,onOpenDevBox:q,onStartDevBox:F,showConfigureDevBox:j.has(H.nodeId),showStartDevBox:A.has(H.nodeId)||f.has(H.nodeId),startDevBoxPending:f.has(H.nodeId)})})]}),e.jsx("div",{className:O("grid transition-[grid-template-rows] duration-300 ease-in-out",jt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:H.dirs.map(Be=>{const Qe=`${ke}::${Be.path}`,nt=Ie.has(Qe),dt=Ka(Be.path),ut=k?.get(Qe),Dt=ut?{visibleTasks:Be.tasks,hiddenCompletedCount:Math.max(0,ut.total-ut.returned)}:Gm(Be.tasks,xt.has(Qe),s),{visibleTasks:Re,hiddenCompletedCount:mt}=Dt;return e.jsxs("div",{className:O("space-y-0.5 rounded-xl",Oe&&"pl-2.5"),children:[e.jsx(Vm,{dirPath:Be.path,label:dt,taskCount:Be.tasks.length,collapsed:nt,onToggle:()=>ge(Qe),onCreateTask:()=>Y("chat",{assignTo:H.nodeId,project:Be.path==="default workspace"?"":Be.path}),onOpenCapabilities:H.nodeId&&te?()=>te(H.nodeId,Be.path==="default workspace"?h?.get(H.nodeId)??Be.path:Be.path):void 0}),e.jsx("div",{className:O("grid transition-[grid-template-rows] duration-300 ease-in-out",nt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:O("overflow-hidden",Oe?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[Re.map(Ce=>{const Xe=Ce.id===s,qe=Ce.assignedTo?p.get(Ce.assignedTo):void 0,qt=!!Ce.assignedTo&&(qe?qe==="offline":Ce.assignedNodeAvailable===!1);return e.jsxs("div",{className:O("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",Xe?'bg-primary/10 before:absolute before:left-0 before:top-1/2 before:h-1/2 before:w-[2px] before:-translate-y-1/2 before:rounded-full before:bg-primary before:content-[""]':"hover:bg-muted/40"),children:[ne&&e.jsx("div",{className:"flex shrink-0",onClick:pe=>pe.stopPropagation(),children:e.jsx(is,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:x.has(Ce.id),onCheckedChange:pe=>D(Ce.id,pe===!0),"aria-label":`Select ${Ce.title}`})}),e.jsxs("button",{type:"button",onClick:()=>$(Ce.id),"aria-current":Xe?"page":void 0,className:"relative min-w-0 flex-1 pr-8 text-left",children:[e.jsx("div",{className:"flex items-center gap-1.5 pr-1",children:e.jsx("span",{className:O("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",Xe?"text-foreground":"text-foreground/80"),children:Ce.title})}),e.jsx("span",{className:O("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",Xe?"text-primary/75":"text-muted-foreground/55"),children:bl(Ce.updatedAt)}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5",children:[e.jsx("span",{className:"rounded-sm bg-muted/35 px-1 py-0 font-mono text-[8px] leading-3 text-muted-foreground/65",children:Ce.agent}),Ce.activeShare&&e.jsx(Ve,{variant:"outline",className:"rounded-sm border-primary/25 bg-primary/8 px-1 py-0 text-[8px] leading-3 text-primary shadow-none",children:"shared"}),qt&&e.jsx(Ve,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/8 px-1 py-0 text-[8px] leading-3 text-destructive shadow-none",children:"unavailable"})]}),e.jsx(Fa,{status:Ce.status,isNative:Ce.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},Ce.id)}),mt>0&&e.jsxs("button",{type:"button",onClick:()=>{ut&&v?v(ut):ye(Qe)},className:"mt-1 flex w-full items-center justify-center gap-1 rounded-sm border border-dashed border-border/55 bg-background/35 px-2 py-1 text-[9px] font-medium text-muted-foreground transition-colors hover:border-primary/35 hover:bg-primary/8 hover:text-primary","aria-label":`Load ${mt} more completed tasks in ${dt}`,children:[e.jsx(Je,{className:"h-3 w-3"}),"Load ",mt," more completed"]})]})})})]},Qe)})})})]},ke)})}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(H=>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+H*12}%`,animationDelay:`${H*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${H*120+60}ms`}})]})]})},H))}):e.jsx("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-3 py-5 text-[11px] text-muted-foreground",children:r||"No tasks match this view."})}),ct?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:ne&&M>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[zt,e.jsx(J,{variant:"ghost",size:"sm",onClick:je,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Clear"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:pt}),Ut]})]}):e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:pt}),ne&&e.jsx(J,{variant:"ghost",size:"sm",onClick:je,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]}),e.jsx(Um,{node:ie,open:ie!==null,onOpenChange:H=>{H||he(null)}})]})}async function Wm(t,s){try{const n=await vl(t,s),r={...n,url:Ba(n.url)};if(globalThis.navigator?.clipboard?.writeText)try{await globalThis.navigator.clipboard.writeText(r.url),ce.success("Shared link copied")}catch{ce.success("Shared link created")}else ce.success("Shared link created");return r}catch(n){ce.error(n instanceof Error?n.message:"Failed to create shared link");return}}async function Qm(t){try{return await wl(t),ce.success("Shared link stopped"),!0}catch(s){return ce.error(s instanceof Error?s.message:"Failed to stop shared link"),!1}}function Ym(t,s,n){const r=o.useCallback(()=>{s(),n()},[s,n]),a=o.useCallback(async l=>{if(!t)return;const c=await Wm(t.id,l);return c&&r(),c},[t,r]),i=o.useCallback(async()=>{if(!t)return!1;const l=await Qm(t.id);return l&&r(),l},[t,r]);return{handleShareTask:a,handleStopShareTask:i}}function ga(t,s,n){const r=o.useRef(s);r.current=s,o.useEffect(()=>{let l=0,c=0;const d=u=>{const h=u.touches[0];h&&(l=h.clientX,c=h.clientY)},m=u=>{const h=u.changedTouches[0];if(!h)return;const p=h.clientX-l;Math.abs(h.clientY-c)>100||Math.abs(p)<50||(p>0?r.current.onSwipeRight?.():r.current.onSwipeLeft?.())},g=t?.current??document;return g.addEventListener("touchstart",d,{passive:!0}),g.addEventListener("touchend",m,{passive:!0}),()=>{g.removeEventListener("touchstart",d),g.removeEventListener("touchend",m)}},[t,n?.threshold,n?.maxVertical])}const Jm="(min-width: 1024px)",Zm="(min-width: 1800px)";function ba(t){return globalThis.window?.matchMedia?.(t)?.matches??!1}function Xm(){const t=globalThis.document?.documentElement;if(!t||!globalThis.window?.getComputedStyle)return 16;const s=Number.parseFloat(globalThis.window.getComputedStyle(t).fontSize);return Number.isFinite(s)&&s>0?s:16}function eh(){const[t,s]=o.useState(()=>yl(cr(),jl({operationsOpen:ba(Zm)}))),[n,r]=o.useState(!1),a=o.useRef(null),i=o.useRef(null),l=o.useRef(null),c=t.layout.desktopTasksOpen,d=t.layout.operationsOpen,m=t.sizes;o.useEffect(()=>{Nl(cr(),t)},[t]);const g=o.useCallback((A,f)=>{s(E=>{const y=E.layout[A],x=typeof f=="function"?f(y):f;return x===y?E:{...E,layout:{...E.layout,[A]:x}}})},[]),u=o.useCallback(A=>{g("desktopTasksOpen",A)},[g]),h=o.useCallback(A=>{g("operationsOpen",A)},[g]);ga(i,{onSwipeLeft:()=>r(!1)}),ga(l,{onSwipeRight:()=>h(!1)});const p=o.useCallback(()=>{if(ba(Jm)){u(A=>!A);return}r(A=>!A)},[u]);o.useEffect(()=>{const A=E=>{const y=a.current;if(!y)return;E.preventDefault();const x=Sl(y.panel,y.startSize,y.startClientX,y.startClientY,E.clientX,E.clientY,y.rootFontSize);s(b=>({...b,sizes:{...b.sizes,[y.panel]:x}}))},f=()=>{a.current=null};return globalThis.window?.addEventListener("pointermove",A),globalThis.window?.addEventListener("pointerup",f),globalThis.window?.addEventListener("pointercancel",f),()=>{globalThis.window?.removeEventListener("pointermove",A),globalThis.window?.removeEventListener("pointerup",f),globalThis.window?.removeEventListener("pointercancel",f)}},[]);const k=o.useCallback((A,f)=>{f.preventDefault(),f.currentTarget.setPointerCapture?.(f.pointerId),a.current={panel:A,startSize:m[A],startClientX:f.clientX,startClientY:f.clientY,rootFontSize:Xm()}},[m]),j=o.useCallback((A,f)=>{f.preventDefault(),s(E=>({...E,sizes:{...E.sizes,[A]:kl(A,E.sizes[A],f.deltaY)}}))},[]);return{desktopTasksOpen:c,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:d,operationsPanelRef:l,panelResize:{sizes:{tasks:qs(m.tasks),operations:qs(m.operations),terminal:qs(m.terminal)},onPointerDown:k,onWheel:j},setMobileTasksPanelOpen:r,setOperationsOpen:h,toggleTasksPanel:p}}function th(t,s){const n=s.taskId,r=s.updates;return typeof n!="string"||!r||typeof r!="object"?t:t.map(a=>a.id===n?{...a,...r}:a)}const sh="notify_desktop_task";function nh(t=Uo()){const s=t?.__TAURI__?.core?.invoke;return typeof s=="function"?s:null}async function rh(t,s=Uo()){const n=nh(s);return n?(await n(sh,t),!0):!1}function ah(t,s){const n=[];for(const r of s){const a=oh(r.status);if(!a)continue;const i=t.get(r.id);!i||i.status===r.status||n.push({taskId:r.id,title:r.title.trim()||"Meshy task",status:a,assignedNodeName:r.assignedNodeName??null,projectPath:r.effectiveProjectPath??r.project??null})}return n}function oh(t){return t==="completed"||t==="failed"?t:null}function Uo(){return typeof window>"u"?null:window}function ih({isLeader:t,selfId:s}){return{...!t&&s?{assignedTo:s}:{},completedLimitPerProject:Vn}}function Fn(t){return`${t.assignedTo??"__unassigned__"}::${t.projectPath}`}function lh(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 ch(t,s,n=new Set){return!s||n.has(s.id)||t.some(r=>r.id===s.id)?t:fo(t,s)}function dh({isLeader:t,selfId:s,sseConnected:n,preservedTask:r,subscribe:a}){const[i,l]=o.useState([]),[c,d]=o.useState([]),[m,g]=o.useState(!0),[u,h]=o.useState(null),p=o.useRef(new Set),k=o.useRef(null),j=o.useRef(null),A=o.useCallback(async()=>{try{const x=await dr(ih({isLeader:t,selfId:s}));l(ch(x.tasks,r,p.current)),d(x.completedGroups??[]),h(null)}catch(x){h(x instanceof Error?x.message:"Failed to load tasks")}finally{g(!1)}},[t,r,s]),f=o.useCallback(async x=>{if(!x.hasMore||!x.nextCursor)return;const b=await dr({status:"completed",assignedTo:x.assignedTo??"__unassigned__",projectPath:x.projectPath,cursor:x.nextCursor,limit:Vn});l(C=>lh(C,b.tasks)),d(C=>C.map(S=>Fn(S)===Fn(x)?{...S,returned:Math.min(S.total,S.returned+b.tasks.length),hasMore:b.hasMore===!0,nextCursor:b.nextCursor??null}:S))},[]),E=o.useCallback(()=>{j.current===null&&(j.current=window.setTimeout(()=>{j.current=null,A()},Cl))},[A]),y=o.useCallback(x=>{const b=new Set(x);if(b.size!==0){for(const C of b)p.current.add(C);l(C=>C.filter(S=>!b.has(S.id)))}},[]);return Tl(A,Dl(n)),o.useEffect(()=>()=>{j.current!==null&&(window.clearTimeout(j.current),j.current=null)},[]),o.useEffect(()=>{const x=k.current;if(x)for(const b of ah(x,i))rh(b).catch(()=>{});k.current=new Map(i.map(b=>[b.id,b]))},[i]),o.useEffect(()=>{const x=[a("task.updated",b=>{l(C=>th(C,b.data))}),a("task.status",b=>{l(C=>El(C,b.data))}),a("node",b=>{ur(b.type)&&E()}),a("task",b=>{if(b.type==="task.deleted"){const C=b.data.taskId;typeof C=="string"&&p.current.add(C),l(S=>Al(S,b.data))}ur(b.type)&&E()})];return()=>x.forEach(b=>b())},[a,E]),{completedGroups:c,fetchTasks:A,loadCompletedTasksPage:f,removeTasksFromList:y,setTasks:l,tasks:i,tasksError:u,tasksLoading:m}}function $o(t){return t.map(s=>({...s}))}function uh(t,s){const n=s.get(t);return{logs:n?$o(n.logs):[],transcriptLoading:n?.loaded!==!0}}function mh(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function hh(t,s){const n=t.data.name;if(typeof n=="string"&&n.length>0)return n;const r=t.data.nodeId;return typeof r=="string"?s?.get(r)??r:"node"}function fh({cluster:t,subscribe:s}){o.useEffect(()=>{if(t?.self?.role!=="leader")return;const n=new Map(t.nodes.map(r=>[r.id,r.name]));return n.set(t.self.id,t.self.name),s("node",r=>{const a=hh(r,n),i=mh(t,r);r.type==="node.joined"&&!i&&ce.success(`${a} joined the cluster`),r.type==="node.left"&&!i&&ce.message(`${a} left the cluster`)})},[t,s])}const xh=[0,300,1e3,2e3];function ph({task:t,getActiveTaskId:s,setLogs:n,setPendingMessages:r,setTranscriptLoading:a}){t.conversationKind==="nativeSession"&&(async()=>{try{for(const i of xh){if(i>0&&await new Promise(l=>setTimeout(l,i)),s()!==t.id)return;try{const l=await En(t.id);if(s()!==t.id||(n(c=>ro(c,l.logs)),r(c=>_n(c,l.logs)),l.total>0))return}catch{}}}finally{s()===t.id&&a?.(!1)}})()}const qo=8;function gh(t,s){return Ue(t??{})===Ue(s??{})}function bh(t){return t&&"status"in t&&typeof t.status=="string"?t.status:void 0}function va(t,s){return{...t,enabled:!0,alwaysOnline:s}}function Vo(t){return t?.status?.trim()||t?.lastStatus?.trim()||"Unknown"}function vh({operationStarting:t,loading:s,refreshing:n,savedStatus:r,fallbackStatus:a}){return t?"Starting":s?"Listing DevBoxes":n?"Refreshing":r??a}async function wh(t,s=Wa){return(await s({nodeId:t,kind:"devbox.start"})).filter(r=>r.kind==="devbox.start").sort((r,a)=>(a.updatedAt??a.createdAt)-(r.updatedAt??r.createdAt)).slice(0,qo)}function yh(t){return t.charAt(0).toUpperCase()+t.slice(1)}function jh(t){const s=t.completedAt??t.startedAt??t.updatedAt??t.createdAt;return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(s))}function Nh(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function wa(t,s){const r=Nh(t)?.[s];return typeof r=="string"&&r.trim()?r.trim():null}function kh(t){if(t.status==="failed")return t.error||"Operation failed";const s=wa(t.result,"operationId");if(s)return`MCP operation ${s}`;const n=wa(t.payload,"previousStatus");return n?`Previous DevBox status: ${n}`:t.status==="succeeded"?"Completed":"Waiting for completion"}function Sh(t){return t==="succeeded"?"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":t==="failed"?"border-destructive/30 bg-destructive/10 text-destructive":t==="running"?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300":"border-border/70 bg-muted/40 text-muted-foreground"}function ya({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:Vo(t)})]})}function Ch({error:t,loading:s,onToggle:n,open:r,operations:a}){return e.jsxs("div",{className:"min-w-0 max-w-full overflow-hidden rounded-sm border border-border/60 bg-muted/20 text-xs",children:[e.jsxs("button",{type:"button",onClick:n,"aria-expanded":r,className:"flex h-8 w-full items-center gap-2 px-3 text-left text-[11px] text-foreground hover:bg-muted/30",children:[e.jsx(Je,{className:O("h-3 w-3 shrink-0 text-muted-foreground transition-transform",!r&&"-rotate-90")}),e.jsx(Ts,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Operations history"}),s&&e.jsx(de,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}),!s&&a.length>0&&e.jsx("span",{className:"shrink-0 rounded-sm border border-border/70 bg-background/60 px-1.5 py-0 text-[10px] leading-none text-muted-foreground",children:a.length})]}),r&&e.jsxs("div",{className:"max-h-44 min-w-0 max-w-full overflow-y-auto border-t border-border/50 px-2 py-1.5",children:[s&&a.length===0&&e.jsxs("div",{className:"flex h-7 items-center gap-2 px-1 text-[10px] text-muted-foreground",children:[e.jsx(de,{className:"h-3 w-3 animate-spin"}),"Loading operations"]}),t&&e.jsx("div",{className:"px-1 py-1 text-[10px] text-destructive",children:t}),!s&&!t&&a.length===0&&e.jsx("div",{className:"px-1 py-1 text-[10px] text-muted-foreground",children:"No DevBox operations yet."}),a.map(i=>{const l=kh(i);return e.jsxs("div",{className:"flex w-full min-w-0 max-w-full items-start gap-2 overflow-hidden rounded-sm px-1 py-1.5 text-[11px] hover:bg-background/40",children:[e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium text-foreground",children:"Start DevBox"}),e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:jh(i)})]}),e.jsx("div",{className:"mt-0.5 w-full min-w-0 max-w-full overflow-x-auto whitespace-nowrap text-[10px] leading-3.5 text-muted-foreground",title:l,children:e.jsx("span",{className:"inline-block min-w-max",children:l})})]}),e.jsx("span",{className:O("shrink-0 rounded-sm border px-1.5 py-0 text-[10px] leading-4",Sh(i.status)),children:yh(i.status)})]},i.id)})]})]})}function Th({node:t,open:s,startInProgress:n=!1,onOpenChange:r,onRefresh:a}){const i=t?.id??null,l=s&&!n&&ia(t?.status,t?.devbox??null),[c,d]=o.useState([]),[m,g]=o.useState(()=>t?.devbox?Ue(t.devbox):""),[u,h]=o.useState(()=>t?.devbox??null),[p,k]=o.useState(()=>la(t?.devbox??null)),[j,A]=o.useState(!1),[f,E]=o.useState(l),[y,x]=o.useState(!1),[b,C]=o.useState(!1),[S,P]=o.useState(()=>t?.devbox?.alwaysOnline===!0),[T,I]=o.useState(!1),[_,D]=o.useState([]),[L,z]=o.useState(!1),[Q,Y]=o.useState(null),X=o.useMemo(()=>{const V=c.find(re=>Ue(re)===m);return V||(Rt(u)&&Ue(u)===m?u:void 0)},[u,c,m]),Z=bh(X??void 0),te=p?Z??u?.lastStatus:u?.lastStatus??Z,q=t?.status==="online"||t?.status==="busy"?"Running":"Unknown",F=b||n,v=vh({operationStarting:F,loading:j,refreshing:f,savedStatus:te,fallbackStatus:q}),$=p&&!!X&&!gh(u,X),N=u?.alwaysOnline===!0!==S,W=Rm({nodeStatus:t?.status,status:v,current:u,selected:X}),R=!!W,K=!!X&&($||N)&&!R,B=X??u,oe=o.useCallback(async()=>{if(i){E(!0);try{const V=await _l(i);h(V.devbox),g(Ue(V.devbox))}catch(V){ce.error(V instanceof Error?V.message:"Failed to refresh DevBox status")}finally{E(!1)}}},[i]),ie=o.useCallback(async V=>{A(!0);try{const re=await Ml();d(re),g(we=>Lm({previousKey:we,baseDevBox:V,listed:re}))}catch(re){ce.error(re instanceof Error?re.message:"Failed to load DevBoxes")}finally{A(!1)}},[]);o.useEffect(()=>{if(!s||!i)return;let V=!1;const re=t?.devbox??null,we=la(re),fe=!n&&ia(t?.status,re);A(!1),E(fe),k(we),h(re),P(re?.alwaysOnline===!0),I(!1),g(Rt(re)?Ue(re):""),d([]);async function Ie(){fe&&await oe(),!V&&we&&await ie(re)}return Ie(),()=>{V=!0}},[ie,t?.devbox,t?.status,i,s,oe,n]),o.useEffect(()=>{if(!s||!i)return;let V=!1;const re=i;async function we(){z(!0),Y(null),D([]);try{const fe=await wh(re);if(V)return;D(fe)}catch(fe){if(V)return;D([]),Y(fe instanceof Error?fe.message:"Failed to load operation history")}finally{V||z(!1)}}return we(),()=>{V=!0}},[i,s]);async function he(){k(!0),c.length===0&&await ie(u)}async function ae(){if(!(!t||!X)){x(!0);try{const V=await mr(t.id,va(X,S));h(V.node.devbox??null),V.node.devbox&&g(Ue(V.node.devbox)),k(!1),ce.success(`Configured DevBox for ${t.name}`),await a?.()}catch(V){ce.error(V instanceof Error?V.message:"Failed to configure DevBox")}finally{x(!1)}}}async function G(){if(!(!t||!W)){C(!0);try{if(X&&($||N)){const re=await mr(t.id,va(X,S));h(re.node.devbox??null),re.node.devbox&&g(Ue(re.node.devbox)),k(!1)}const{operation:V}=await Qa(t.id);h(re=>re&&{...re,lastStatus:"Starting",checkedAt:Date.now(),operationId:V.id}),D(re=>[V,...re.filter(we=>we.id!==V.id)].slice(0,qo)),ce.success(`Start requested for ${t.name}`),await a?.()}catch(V){ce.error(V instanceof Error?V.message:"Failed to start DevBox")}finally{C(!1)}}}const M=j?"Loading DevBoxes...":c.length===0?"No DevBoxes available":"Select a DevBox",ne=v==="Running"&&t?.status==="offline";return e.jsx(wt,{open:s,onOpenChange:r,children:e.jsxs(yt,{className:"w-[calc(100vw-2rem)] max-w-md grid-cols-[minmax(0,1fr)] gap-3 overflow-hidden rounded-sm p-4",children:[e.jsxs(cs,{className:"min-w-0 max-w-full space-y-1 overflow-hidden",children:[e.jsx(Tt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(ds,{className:"max-w-full text-xs",children:["Bind ",t?.name?e.jsx("span",{className:"font-medium text-foreground",children:t.name}):"this node"," to an Azure Dev Box. Meshy will start it when the node is offline."]})]}),e.jsxs("div",{className:"min-w-0 max-w-full space-y-3 overflow-hidden",children:[(p||B)&&e.jsxs("div",{className:"flex min-h-9 w-full min-w-0 max-w-full items-center justify-between gap-3 overflow-hidden rounded-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:p?e.jsxs(_e,{value:m,onValueChange:g,disabled:j||y||b||c.length===0,children:[e.jsx(Me,{className:"h-7 justify-start gap-2 rounded-none border-0 bg-transparent px-0 text-xs shadow-none focus:ring-0 focus:ring-offset-0 [&>span]:!flex [&>span]:!min-w-0 [&>span]:!flex-1 [&>span]:!items-center",children:j&&!X?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),M]}):X?e.jsx(ya,{devbox:X}):e.jsx($e,{placeholder:M})}),e.jsx(Pe,{children:c.map(V=>e.jsx(De,{value:Ue(V),textValue:`${V.name} ${V.projectName??""} ${Vo(V)}`,className:"pl-2 pr-7 text-xs [&>span:first-child]:left-auto [&>span:first-child]:right-2 [&>span:last-child]:w-full",children:e.jsx(ya,{devbox:V,showStatus:!0})},Ue(V)))})]}):B&&e.jsxs("div",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:B.name}),B.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",B.projectName]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Ve,{variant:"outline",className:"rounded-sm px-1.5 py-0 text-[10px]",children:[(j||f)&&e.jsx(de,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),v]}),u?.name&&e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>{he()},disabled:j||y||F||p,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-sm text-muted-foreground hover:text-foreground",children:j&&p?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Ot,{className:"h-3 w-3"})})]})]}),ne&&e.jsx("div",{className:"rounded-sm border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:"DevBox is running, but the Meshy node is not connected yet."}),e.jsxs("label",{className:"flex min-h-9 w-full min-w-0 max-w-full items-start gap-2 overflow-hidden rounded-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(is,{checked:S,onCheckedChange:V=>P(V===!0),disabled:y||b||F,"aria-label":"Always online",className:"mt-0.5 h-3.5 w-3.5"}),e.jsxs("span",{className:"min-w-0 leading-4",children:[e.jsx("span",{className:"block",children:"Always online"}),e.jsx("span",{className:"block text-[10px] leading-3.5 text-muted-foreground",children:"Meshy will start the DevBox automatically when it is Hibernated or Stopped."})]})]}),e.jsx(Ch,{error:Q,loading:L,onToggle:()=>I(V=>!V),open:T,operations:_})]}),e.jsxs(za,{className:"gap-2 sm:space-x-0",children:[e.jsx(J,{variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y||b,className:"h-8 rounded-sm text-xs",children:"Close"}),R&&e.jsxs(J,{size:"sm",onClick:G,disabled:b,className:"h-8 rounded-sm text-xs",children:[b?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ms,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!R&&e.jsxs(J,{size:"sm",onClick:ae,disabled:!K||y,className:"h-8 rounded-sm text-xs",children:[y&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function Eh(t,s=Wa){if(t.length===0)return new Set;const n=new Set(t),[r,a]=await Promise.all([s({kind:"devbox.start",status:"queued"}),s({kind:"devbox.start",status:"running"})]);return new Set([...r,...a].filter(i=>n.has(i.nodeId)).map(i=>i.nodeId))}function Ah({cluster:t,refresh:s}){const[n,r]=o.useState(null),[a,i]=o.useState(null),[l,c]=o.useState(()=>new Set),[d,m]=o.useState(()=>new Set),g=o.useMemo(()=>t?.nodes.find(f=>f.id===n)??null,[t?.nodes,n]),u=o.useMemo(()=>new Set((t?.nodes??[]).filter(f=>f.devbox?.enabled).map(f=>f.id)),[t?.nodes]),h=o.useMemo(()=>new Set((t?.nodes??[]).filter(f=>Rs(f.status,f.devbox?.lastStatus,f.devbox)).map(f=>f.id)),[t?.nodes]),p=o.useMemo(()=>new Set((t?.nodes??[]).filter(f=>Lt(f.devbox?.lastStatus)).map(f=>f.id)),[t?.nodes]),k=o.useMemo(()=>{const f=new Set(l);a&&f.add(a);for(const E of d)f.add(E);for(const E of p)f.add(E);return f},[d,a,l,p]);o.useEffect(()=>{let f=!1;const E=[...u];async function y(){try{const x=await Eh(E);f||m(x)}catch{f||m(new Set)}}return y(),()=>{f=!0}},[u]),o.useEffect(()=>{c(f=>{let E=!1;const y=new Set(f);for(const x of f){const b=t?.nodes.find(C=>C.id===x);b?.status!=="online"&&(!b?.devbox?.lastStatus||Lt(b.devbox.lastStatus))||(y.delete(x),E=!0)}return E?y:f})},[t?.nodes]);const j=o.useCallback(async f=>{const E=t?.nodes.find(y=>y.id===f);if(E){i(f),c(y=>new Set(y).add(f));try{await Qa(f),ce.success(`Start requested for ${E.name}`),s()}catch(y){c(x=>{const b=new Set(x);return b.delete(f),b}),ce.error(y instanceof Error?y.message:"Failed to start DevBox")}finally{i(null)}}},[t?.nodes,s]);return{devBoxDialog:e.jsx(Th,{node:g,open:n!==null,startInProgress:g?k.has(g.id):!1,onOpenChange:f=>{f||r(null)},onRefresh:s}),devBoxNodeIds:u,devBoxStartNodeId:a,devBoxStartNodeIds:h,devBoxStartingNodeIds:k,openDevBox:r,startDevBox:j}}function Dh(t){const[s,n]=o.useState(null),r=o.useCallback(i=>{t&&n(i)},[t]);return{nodeSettingsDialog:e.jsx(Pl,{open:s!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:s??void 0,showTrigger:!1}),openNodeSettings:r}}function _h(t=!1){return!t}function Mh({activeTaskId:t,fetchActiveTask:s,isRunning:n=!1,setPendingMessages:r,setTask:a,setTasks:i}){const l=o.useCallback((m,g)=>{a(u=>u&&u.id===m?{...u,queuedMessages:g}:u),i(u=>u.map(h=>h.id===m?{...h,queuedMessages:g}:h))},[a,i]),c=o.useCallback(async m=>{if(!t)return!1;const g=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`,u=_h(n);u&&r(h=>[...h,{id:g,content:m,timestamp:new Date().toISOString()}]);try{const h=await Il(t,m);return h.queued&&(u&&r(p=>p.filter(k=>k.id!==g)),h.queuedMessages&&l(t,h.queuedMessages)),s(),!0}catch(h){return u&&r(p=>p.filter(k=>k.id!==g)),ce.error(h instanceof Error?h.message:"Failed to send message"),!1}},[t,s,n,r,l]);return{cancelQueuedMessage:o.useCallback(async m=>{if(t)try{const g=await Rl(t,m);l(t,g.queuedMessages),s()}catch(g){ce.error(g instanceof Error?g.message:"Failed to cancel queued message")}},[t,s,l]),queueFollowUpMessage:c}}const ja="grid-cols-[1.5rem_5.25rem_4rem_minmax(8rem,1fr)_4rem_4rem_6rem]",Ph={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Ih(t,s){const n=s.search.trim().toLowerCase();return t.filter(r=>s.agent!=="all"&&r.agent!==s.agent||s.kind!=="all"&&r.kind!==s.kind?!1:n?[r.name,r.description,r.source,r.version,r.agent,r.kind].some(a=>a?.toLowerCase().includes(n)):!0)}function Ho(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 Rh({items:t,selectedIds:s,activeId:n,onToggleSelected:r,onOpenDetail:a}){return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden rounded-sm border border-border/60 bg-card/35",children:[e.jsxs("div",{className:O("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",ja),children:[e.jsx("span",{}),e.jsx("span",{children:"Agent"}),e.jsx("span",{children:"Kind"}),e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Ver"}),e.jsx("span",{children:"Size"}),e.jsx("span",{children:"Source"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:t.length>0?t.map(i=>e.jsxs("button",{type:"button",onClick:()=>a(i),className:O("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",ja,n===i.id&&"bg-primary/10 text-primary shadow-[inset_2px_0_0_hsl(var(--primary))]"),children:[e.jsx("span",{onClick:l=>l.stopPropagation(),children:e.jsx(is,{className:"h-3 w-3",checked:s.has(i.id),onCheckedChange:l=>r(i.id,l===!0),"aria-label":`Select ${i.name}`})}),e.jsx(Lh,{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:Ho(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 Lh({agent:t}){const s=Ph[t];return e.jsx("span",{className:"block min-w-0 truncate text-[10px] font-medium leading-3 text-muted-foreground",title:s,children:s})}const Na=320,ka=560,Ko=384,Sa=360;function Bh(t,s=ka+Sa){const n=Math.max(Na,Math.min(ka,s-Sa));return Math.min(Math.max(Math.round(t),Na),n)}function Oh(t,s,n,r){return Bh(t+s-n,r)}function Fh({detail:t,deleting:s=!1,onDelete:n,desktopWidth:r=Ko,pending:a=!1}){const i={"--capability-detail-width":`${r}px`};if(!t)return e.jsx("aside",{"data-capability-detail-panel":"true",style:i,className:"hidden min-h-0 shrink-0 animate-panel-settle bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-3 text-[11px] text-muted-foreground lg:block lg:w-[var(--capability-detail-width)]",children:a?"Loading capability metadata...":"No capability selected."});const l=t.kind==="mcp"?"mcp":"files";return e.jsxs("aside",{"data-capability-detail-panel":"true",style:i,className:"flex min-h-0 w-full shrink-0 animate-panel-settle flex-col bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-2.5 lg:w-[var(--capability-detail-width)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold leading-5 text-foreground",children:t.name}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-1",children:[e.jsx(Ve,{variant:"secondary",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary",children:t.agent}),e.jsx(Ve,{variant:"outline",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary/90",children:t.kind})]})]}),n&&e.jsxs(Yt,{children:[e.jsx(Tn,{asChild:!0,children:e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground hover:text-destructive","aria-label":"Delete capability",title:"Delete capability",disabled:s,children:e.jsx(Ga,{className:"h-3.5 w-3.5"})})}),e.jsxs(Jt,{className:"max-w-[22rem] gap-2 rounded-xl p-4",children:[e.jsxs(Zt,{className:"space-y-1",children:[e.jsxs(Xt,{className:"text-sm",children:["Delete ",t.name,"?"]}),e.jsxs(es,{className:"text-[11px] leading-4",children:["This removes the selected ",t.kind," from ",t.scope.kind==="global"?"the user profile":"this project","."]})]}),e.jsxs(ts,{className:"gap-1 pt-0 sm:space-x-1",children:[e.jsx(ss,{className:"h-7 rounded-lg px-2 text-[11px]",children:"Cancel"}),e.jsx(ns,{className:"h-7 rounded-lg px-2 text-[11px]",onClick:n,disabled:s,children:"Delete"})]})]})]})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-1 text-[9px]",children:[e.jsx(js,{label:"Version",value:t.version??"-"}),e.jsx(js,{label:"Size",value:Ho(t)}),e.jsx(js,{label:"Files",value:String(t.fileCount)}),e.jsx(js,{label:"Source",value:t.source??"local"})]}),e.jsxs(Un,{defaultValue:l,className:"mt-2 flex min-h-0 flex-1 flex-col",children:[e.jsxs(zn,{className:"grid h-auto grid-cols-2 rounded-sm bg-primary/8 p-0.5",children:[t.kind==="mcp"?e.jsx(St,{value:"mcp",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"MCP"}):e.jsx(St,{value:"files",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"Files"}),e.jsx(St,{value:"readme",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"README"})]}),t.kind==="mcp"?e.jsx(ft,{value:"mcp",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(zh,{detail:t})}):e.jsx(ft,{value:"files",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(Uh,{detail:t})}),e.jsx(ft,{value:"readme",className:"mt-2 min-h-0 flex-1 overflow-auto",children:t.readmeMarkdown?e.jsx(Ec,{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(Xn,{children:"No README content."})})]},t.id)]})}function zh({detail:t}){const s=t.mcpPreview??[];return s.length===0?e.jsx(Xn,{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 Uh({detail:t}){const s=t.fileTree??[];return s.length===0?e.jsx(Xn,{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 Xn({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 js({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 $h=20,qh=288,Vh=360,Hh=440;function Kh(){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 Gh({triggerRect:t,targetRect:s,viewportRect:n,compact:r,browserOpen:a=!1,portalAlign:i,cssZoom:l=1}){const c=Number.isFinite(l)&&l>0?l:1,d=8,m=n.top+d,g=n.bottom-d,u=n.left+d,h=n.right-d,p=Math.max(0,g-t.bottom-4),k=Math.max(0,t.top-m-4),j=r?k<140&&p>k:p>=220||p>=k,A=j?p:k,f=Math.max(140,g-m),E=r&&a,b=Math.min(f,E?Hh:320,Math.max(E?Vh:140,A)),C=qh*c,S=i==="end"?t.right-C:t.left,T=(Math.max(u,Math.min(S,h-C))-s.left)/c;if(!j&&!E)return{left:T,bottom:(s.bottom-(t.top-4))/c,maxHeight:b/c};const I=j?t.bottom+4:t.top-b-4,_=Math.max(m,Math.min(I,g-b));return{left:T,top:(_-s.top)/c,maxHeight:b/c}}function er(t){if(!t.workDir)return[];const s=[],n=new Set,r=a=>{!a||n.has(a)||(n.add(a),s.push(a))};r(t.workDir);for(const a of t.workDirFolders??[])r(Wo(a)?a:Qo(t.workDir,a));return s}function Wh(t,s){if(t.kind==="global")return{nodeId:s.id,scope:{kind:"global"}};const n=er(s),r=n.find(a=>a===t.projectPath);return r?{nodeId:s.id,scope:{kind:"project",projectPath:r}}:n[0]?{nodeId:s.id,scope:{kind:"project",projectPath:n[0]}}:{nodeId:s.id,scope:{kind:"global"}}}function Qh(t,s){return{nodeId:t,scope:s}}function Ca(t,s,n){const r=s.trim();return!r||r==="."?t.workDir??r:n||Wo(r)?r:t.workDir?Qo(t.workDir,r):r}function Yh({node:t,scope:s,clusterNodes:n,onSelectionChange:r}){const a=o.useMemo(()=>ef(n,t),[n,t]),i=o.useMemo(()=>er(t),[t]),l=o.useMemo(()=>a.map(c=>({value:c.id,label:c.name,description:`${c.role} · ${c.status}`,status:c.status})),[a]);return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-2",children:[e.jsx(Xh,{ariaLabel:"Capability node",value:t.name,description:`${t.role} · ${t.status}`,options:l,selectedValue:t.id,onSelect:c=>{const d=a.find(m=>m.id===c);d&&r?.(Wh(s,d))}}),e.jsx(Go,{node:t,projectPaths:i,selectedScope:s,onSelect:c=>r?.(Qh(t.id,c))}),e.jsx(Jh,{node:t})]})}function Jh({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:O("h-1.5 w-1.5 shrink-0 rounded-full",rs(t.status))})]})}function Go({node:t,projectPaths:s,selectedScope:n,onSelect:r,compact:a=!1,portal:i=!1,portalAlign:l="start"}){const[c,d]=o.useState(!1),[m,g]=o.useState(null),[u,h]=o.useState(!1),[p,k]=o.useState(!1),[j,A]=o.useState(null),[f,E]=o.useState(!1),[y,x]=o.useState(null),b=o.useRef(null),C=o.useRef(null),S=o.useRef(null),P=o.useMemo(()=>s.map(q=>({value:q,label:Ea(q),description:q})),[s]),T=n.kind==="project"?n.projectPath:void 0,I=n.kind==="global"?"Global":Ea(n.projectPath),_=n.kind==="global"?"Global":n.projectPath,D=o.useCallback(()=>!i||typeof document>"u"?null:C.current?.closest('[data-capability-share-dialog="true"]')??document.body,[i]),L=o.useCallback(()=>{if(!i||!C.current||typeof window>"u")return;const q=C.current.getBoundingClientRect(),F=D(),v=F&&F!==document.body?F.getBoundingClientRect():{left:0,top:0,bottom:window.innerHeight};x(Gh({triggerRect:q,targetRect:v,viewportRect:{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},compact:a,browserOpen:f,portalAlign:l,cssZoom:Kh()}))},[f,a,D,i,l]);o.useEffect(()=>{c||E(!1)},[c]),o.useEffect(()=>{if(!c)return;const q=F=>{if(!(F.target instanceof Node))return;const v=F.composedPath(),$=b.current?v.includes(b.current):!1,N=S.current?v.includes(S.current):F.target instanceof Element&&!!F.target.closest('[data-capability-scope-menu="true"]');!$&&!N&&d(!1)};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[c]),o.useEffect(()=>{if(!(!c||!i))return L(),window.addEventListener("resize",L),window.addEventListener("scroll",L,!0),()=>{window.removeEventListener("resize",L),window.removeEventListener("scroll",L,!0)}},[c,i,L]);const z=async(q,F=0,v=!1)=>{if(t.workDir){A(null),v?k(!0):h(!0);try{const $=await Ra(t.id,{path:q||".",limit:$h,offset:F,directoriesOnly:!0,allowAbsolute:!0});g(N=>v&&N?{...$,entries:[...N.entries,...$.entries]}:$)}catch($){A($ instanceof Error?$.message:"Failed to browse folders"),v||g(null)}finally{h(!1),k(!1)}}};o.useEffect(()=>{!c||!f||!t.workDir||(g(null),A(null),z(T||"."))},[f,c,t.id,t.workDir,T]);const Q=(q,F=!1)=>{r({kind:"project",projectPath:Ca(t,q,F)}),d(!1)},Y=()=>{r({kind:"global"}),d(!1)},X=m?Ca(t,m.currentPath,m.isAbsolute):T??t.workDir??"",Z=i?D():null,te=e.jsxs("div",{ref:S,"data-capability-scope-menu":"true","aria-hidden":!c,onClick:q=>q.stopPropagation(),onMouseDown:q=>q.stopPropagation(),onPointerDown:q=>q.stopPropagation(),style:i&&y?{left:y.left,top:y.top,bottom:y.bottom,height:a&&f?y.maxHeight:void 0,maxHeight:y.maxHeight}:void 0,className:O(i?"absolute z-[80] flex w-72 flex-col overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none pointer-events-auto":"absolute left-0 z-50 flex max-h-[28rem] w-72 flex-col overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!i&&(a?"top-7":"top-9"),!c&&"hidden"),children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 p-1",children:[e.jsx("div",{className:O("px-2 text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",a?"pb-0.5 pt-0.5 leading-3":"pb-1 pt-1"),children:"Scope"}),e.jsxs("div",{className:O("overflow-y-auto pr-0.5",a?"max-h-32":"max-h-40"),children:[e.jsx(Ta,{icon:"global",label:"Global",selected:n.kind==="global",onSelect:Y,compact:a}),P.length>0?P.map(q=>e.jsx(Ta,{icon:"folder",label:q.label,description:q.description,selected:T===q.value,onSelect:()=>Q(q.value,!0),compact:a},q.value)):e.jsx("div",{className:O("flex items-center px-2 text-muted-foreground",a?"h-7 text-[9px]":"h-8 text-[10px]"),children:"No known projects"})]})]}),e.jsxs("div",{className:O("border-b border-border/55",f?"flex min-h-0 flex-1 flex-col":"shrink-0"),children:[e.jsxs("button",{type:"button","aria-expanded":f,onClick:()=>E(q=>!q),className:O("flex w-full items-center gap-1 px-2 text-left text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground transition-colors hover:bg-muted/45 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",a?"py-1 leading-3":"py-1.5"),children:[e.jsx(Bt,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Browse folders"}),e.jsx(Je,{className:O("h-3 w-3 shrink-0 transition-transform duration-200",f&&"rotate-180")})]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"shrink-0 px-2 pb-1.5",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>m?.parentPath&&void z(m.parentPath),disabled:!m?.parentPath||u,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(ao,{className:"h-2.5 w-2.5"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[9px] text-muted-foreground",title:X,children:X}),m&&e.jsx("button",{type:"button",onClick:()=>Q(m.currentPath,m.isAbsolute),className:"shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium text-foreground hover:bg-muted/60",title:"Use this folder",children:"Use"})]})}),e.jsxs("div",{className:O("min-h-0 flex-1 overflow-y-auto",a?"min-h-[8.25rem]":"max-h-56"),children:[t.workDir?u?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[9px] text-muted-foreground",children:[e.jsx(de,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading folders..."]}):m&&m.entries.length>0?e.jsxs(e.Fragment,{children:[m.entries.map(q=>e.jsx(Zh,{entry:q,onSelect:()=>Q(q.path,m.isAbsolute),onOpen:()=>{z(q.path)}},q.path)),m.hasMore&&e.jsxs("button",{type:"button",onClick:()=>{z(m.currentPath,m.entries.length,!0)},disabled:p,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:[p?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Vc,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:j??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:"This node has no working directory."}),j&&m&&m.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[9px] text-destructive",children:j})]})]})]})]});return e.jsxs("div",{ref:b,className:"relative min-w-0",children:[e.jsxs("button",{ref:C,type:"button","aria-label":"Capability location","aria-expanded":c,title:_,onClick:()=>d(q=>(q||(E(!1),L()),!q)),className:O("flex min-w-0 items-center gap-1.5 rounded-sm border-0 bg-muted/55 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",a?"h-5 w-24 max-w-28 px-1.5":"h-7 min-w-32 max-w-56 px-2"),children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:O("block truncate font-medium text-foreground",a?"text-[9px] leading-3":"text-[10px] leading-4"),children:I})}),e.jsx(Je,{className:O(a?"h-2.5 w-2.5":"h-3 w-3","shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),i&&Z?qa.createPortal(te,Z):te]})}function Ta({icon:t,label:s,description:n,selected:r,onSelect:a,compact:i=!1}){const l=t==="global"?zc:Bt;return e.jsxs("button",{type:"button",onClick:a,className:O(i?"flex h-7 w-full items-center gap-1.5 rounded-md px-2 text-left text-[9px]":"flex h-8 w-full items-center gap-1.5 rounded-md px-2 text-left text-[10px]","transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",r&&"bg-primary/10 text-primary"),children:[e.jsx(l,{className:O("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:O("block truncate text-muted-foreground",i?"text-[7px] leading-3":"text-[8px] leading-3"),children:n})]})]})}function Zh({entry:t,onOpen:s,onSelect:n}){return e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:n,className:"flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1 text-left text-[9px] hover:bg-muted/55",title:`Use ${t.path}`,children:[e.jsx(Bt,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-foreground",children:t.name})]}),e.jsx("button",{type:"button",onClick:s,className:"flex w-7 shrink-0 items-center justify-center border-l border-border/30 text-muted-foreground hover:bg-muted/65 hover:text-foreground",title:"Open subfolder","aria-label":`Open ${t.name}`,children:e.jsx(st,{className:"h-3 w-3"})})]})}function Xh({ariaLabel:t,value:s,description:n,options:r,selectedValue:a,onSelect:i}){const[l,c]=o.useState(!1),d=o.useRef(null);return o.useEffect(()=>{if(!l)return;const m=g=>{d.current&&g.target instanceof Node&&!d.current.contains(g.target)&&c(!1)};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[l]),e.jsxs("div",{ref:d,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":t,"aria-expanded":l,title:n??s,onClick:()=>c(m=>!m),className:"flex h-7 min-w-32 max-w-56 items-center gap-1.5 rounded-sm border-0 bg-muted/55 px-2 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:"block truncate text-[10px] font-medium leading-4 text-foreground",children:s})}),e.jsx(Je,{className:O("h-3 w-3 shrink-0 text-muted-foreground transition-transform",l&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!l,className:O("absolute left-0 top-9 z-50 w-64 overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!l&&"hidden"),children:e.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:r.length>0?r.map(m=>e.jsxs("button",{type:"button",onClick:()=>{i(m.value),c(!1)},className:O("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[11px] transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",m.value===a&&"bg-primary/10 text-primary"),children:[m.status&&e.jsx("span",{className:O("h-1.5 w-1.5 shrink-0 rounded-full",rs(m.status))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:m.label}),m.description&&e.jsx("span",{className:"block truncate text-[9px] text-muted-foreground",children:m.description})]})]},m.value)):e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No projects"})})})]})}function ef(t,s){const n=new Map;for(const r of t)n.set(r.id,r);return n.set(s.id,s),Array.from(n.values())}function rs(t){return t==="online"?"bg-emerald-500":t==="offline"?"bg-muted-foreground/45":"bg-amber-500"}function Ea(t){return t.split(/[\\/]+/).filter(Boolean).at(-1)??t}function Wo(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)}function Qo(t,s){return`${t.replace(/[\\/]+$/,"")}/${s.replace(/^[\\/]+/,"")}`}const tf="h-6 w-24 rounded-sm px-2 text-[10px] shadow-none",Nn="text-[10px]",Yo=["claudecode","codex","copilot"],Qt={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function sf({open:t,sourceNode:s,targetNodes:n,selectedCapabilities:r,previewResults:a=[],embedded:i=!1,onClose:l,onPreviewTargetsChange:c,onShare:d}){const[m,g]=o.useState(()=>new Set(a.length>0?a.map(v=>at(v.nodeId,v.targetAgent)):rf(s.id,n,r))),[u,h]=o.useState(()=>Object.fromEntries(af(s.id,n,r))),[p,k]=o.useState({}),[j,A]=o.useState(!1),[f,E]=o.useState(()=>new Set),[y,x]=o.useState(()=>new Set),b=r.some(v=>v.kind==="plugin"),C=o.useMemo(()=>tr(r).map(v=>({key:at(s.id,v),nodeId:s.id,node:s,label:`Install into ${Qt[v]}`,agentLabel:Qt[v],defaultScope:Zo(r),disabled:!1,targetAgent:v})),[r,s]),S=o.useMemo(()=>n.flatMap(v=>{const $={kind:"global"},N=v.status==="offline",W=Jo(r);return W.length===0?[{key:at(v.id),nodeId:v.id,node:v,label:v.name,defaultScope:$,disabled:N}]:W.map(R=>({key:at(v.id,R),nodeId:v.id,node:v,label:`${v.name} / ${Qt[R]}`,agentLabel:Qt[R],defaultScope:$,disabled:N,targetAgent:R}))}),[r,n]),P=o.useMemo(()=>[...C,...S],[C,S]),T=o.useMemo(()=>n.map(v=>({node:v,options:S.filter($=>$.nodeId===v.id)})).filter(v=>v.options.length>0),[n,S]),I=o.useMemo(()=>new Map(a.filter(v=>v.capabilityId).map(v=>[Aa(v.nodeId,v.capabilityId,v.targetAgent),v])),[a]),_=o.useMemo(()=>new Map(a.map(v=>[at(v.nodeId,v.targetAgent),v])),[a]),D=o.useMemo(()=>P.filter(v=>m.has(v.key)),[m,P]),L=o.useMemo(()=>D.map(v=>({nodeId:v.nodeId,scope:u[v.key]??v.defaultScope,...v.targetAgent?{targetAgent:v.targetAgent}:{}})),[D,u]),z=o.useMemo(()=>{const v=[],$=new Map;for(const N of D){if(!$.has(N.nodeId)){const W=N.nodeId===s.id?s:n.find(R=>R.id===N.nodeId);$.set(N.nodeId,{nodeId:N.nodeId,node:W,name:W?.name??N.nodeId,options:[]}),v.push(N.nodeId)}$.get(N.nodeId).options.push(N)}return v.map(N=>$.get(N))},[D,s,n]),Q=o.useMemo(()=>{const v=Array.from(new Set(r.map(N=>N.agent))),[$]=v;if($)return v.length===1?Qt[$]:`${v.length} agents`},[r]),Y=T.length+1;o.useEffect(()=>{let v=!1;const $={...u};for(const N of P)$[N.key]||($[N.key]=N.defaultScope,v=!0);v&&h($)},[P,u]),o.useEffect(()=>{t&&c?.(L)},[t,c,L]),o.useEffect(()=>{t&&(E(new Set),x(new Set))},[t,s.id]),o.useEffect(()=>{if(!i||!t)return;const v=$=>{$.key==="Escape"&&l()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[i,l,t]);const X=v=>{k(Object.fromEntries(D.map($=>[$.key,v])))},Z=async()=>{A(!0);try{await d(D.map(v=>({nodeId:v.nodeId,scope:u[v.key]??v.defaultScope,...v.targetAgent?{targetAgent:v.targetAgent}:{},conflictStrategy:p[v.key]??"overwrite"})))}finally{A(!1)}},te=v=>{const $=u[v.key]??v.defaultScope,N=`capability-share-target-${nf(v.key)}`,W=m.has(v.key);return e.jsxs("div",{"data-target-agent":v.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":v.disabled?"true":void 0,children:[e.jsx(is,{id:N,disabled:v.disabled,checked:W,onCheckedChange:R=>g(K=>{const B=new Set(K);return R===!0?B.add(v.key):B.delete(v.key),B}),"aria-label":`Select ${v.label} as a share target`,"data-share-target-checkbox":!0,className:"h-3.5 w-3.5 border-border/70 bg-background/80 shadow-none data-[state=checked]:border-primary data-[state=checked]:bg-primary [&_svg]:h-3 [&_svg]:w-3"}),e.jsx("label",{htmlFor:N,className:"min-w-0 flex-1 cursor-pointer truncate text-[10px] font-medium leading-4 text-foreground data-[disabled=true]:cursor-not-allowed","data-disabled":v.disabled?"true":void 0,children:v.agentLabel??v.label}),e.jsx("div",{className:"flex w-28 shrink-0 justify-end",children:W&&!v.disabled&&e.jsx(Go,{node:v.node,projectPaths:er(v.node),selectedScope:$,onSelect:R=>h(K=>({...K,[v.key]:R})),compact:!0,portal:!0,portalAlign:"end"})})]},v.key)},q=(v,$,N,W)=>{const R=f.has(v.id),K=D.filter(B=>B.nodeId===v.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":R,onClick:()=>E(B=>Da(B,v.id)),className:"flex w-full items-center gap-2 border-b border-border/35 bg-primary/5 px-2 py-1.5 text-left transition-colors hover:bg-primary/10",children:[e.jsx(st,{className:O("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",R&&"rotate-90")}),e.jsx("span",{className:O("h-1.5 w-1.5 shrink-0 rounded-full",rs(v.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold text-foreground",title:v.name,children:v.name}),K>0&&e.jsxs("span",{className:"shrink-0 text-[8px] font-medium text-primary",children:[K," selected"]}),e.jsx("span",{className:"shrink-0 text-[8px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:$?"this node":"remote"}),v.status==="offline"&&e.jsx(Ve,{variant:"outline",className:"rounded-sm px-1 py-0 text-[8px]",children:"offline"}),W>0&&e.jsxs("span",{className:"sr-only",children:[W," agents"]})]}),e.jsx("div",{className:O("grid transition-[grid-template-rows] duration-200 ease-out",R?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsx("div",{className:"divide-y divide-border/25",children:N})})})]},v.id)},F=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(Es,{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:O("h-1.5 w-1.5 shrink-0 rounded-full",rs(s.status))}),e.jsx("span",{className:"truncate font-semibold text-foreground",title:s.name,children:s.name}),Q&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:["· ",Q]})]}),e.jsx(gr,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Targets"}),e.jsxs("span",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:D.length})," selected · ",Y," ",Y===1?"node":"nodes"]})]}),e.jsxs("div",{className:"grid gap-4 p-4 lg:grid-cols-[17rem_minmax(0,1fr)]",children:[e.jsx("section",{className:"min-w-0",children:e.jsxs("div",{className:"max-h-[56vh] space-y-2 overflow-y-auto pr-0.5",children:[q(s,!0,b?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"Cross-agent plugin installs are not supported."}):C.length===0?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No alternate agents available for this selection."}):C.map(te),C.length),T.map(v=>q(v.node,!1,v.options.map(te),v.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(v=>e.jsx("button",{type:"button",onClick:()=>X(v),className:"h-5 rounded-[3px] px-1.5 text-[9px] capitalize text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground",children:v},v))})]})]}),e.jsx("div",{className:"max-h-[56vh] min-h-32 overflow-y-auto rounded-sm border border-border/55 bg-background/45 p-2",children:D.length===0?e.jsx("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"Select a target to preview conflicts."}):z.map(v=>{const $=!y.has(v.nodeId);return e.jsxs("div",{className:"mb-1.5 overflow-hidden rounded-sm border border-border/35 bg-muted/10 last:mb-0",children:[e.jsxs("button",{type:"button","aria-expanded":$,onClick:()=>x(N=>Da(N,v.nodeId)),className:"flex w-full items-center gap-1.5 border-b border-border/30 bg-primary/5 px-2 py-1 text-left transition-colors hover:bg-primary/10",children:[e.jsx(st,{className:O("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",$&&"rotate-90")}),v.node&&e.jsx("span",{className:O("h-1.5 w-1.5 shrink-0 rounded-full",rs(v.node.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-semibold text-foreground",children:v.name}),e.jsxs("span",{className:"shrink-0 text-[8px] text-muted-foreground",children:[v.options.length," ",v.options.length===1?"agent":"agents"]})]}),e.jsx("div",{className:O("grid transition-[grid-template-rows] duration-200 ease-out",$?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsx("div",{className:"space-y-1 p-1.5",children:v.options.map(N=>{const W=p[N.key]??"overwrite";return e.jsxs("div",{className:"rounded-sm bg-background/45 px-2 py-1",children:[e.jsxs("div",{className:"mb-0.5 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[9px] font-medium leading-4 text-foreground",children:N.agentLabel??"Matching agent"}),e.jsxs(_e,{value:W,onValueChange:R=>k(K=>({...K,[N.key]:R})),children:[e.jsx(Me,{className:tf,children:e.jsx($e,{})}),e.jsxs(Pe,{className:"shadow-none",children:[e.jsx(De,{value:"overwrite",className:Nn,children:"Overwrite"}),e.jsx(De,{value:"skip",className:Nn,children:"Skip"}),e.jsx(De,{value:"abort",className:Nn,children:"Abort"})]})]})]}),e.jsx("div",{className:"space-y-px",children:r.map(R=>{const K=I.get(Aa(N.nodeId,R.id,N.targetAgent))??(r.length===1?_.get(N.key):void 0);return e.jsxs("div",{className:"flex items-center gap-1.5 text-[9px] leading-4",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:R.name}),e.jsx("span",{className:K?.conflict?"text-amber-500":K?"text-emerald-500":"text-muted-foreground",children:K?K.conflict?`exists${K.currentVersion?` v${K.currentVersion}`:""}`:"new install":"checking"}),K?.sourceVersion&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[e.jsx(gr,{className:"inline h-2.5 w-2.5"})," v",K.sourceVersion]})]},R.id)})})]},N.key)})})})})]},v.nodeId)})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-border/55 px-4 py-3",children:[e.jsx(J,{variant:"ghost",onClick:l,className:"h-7 rounded-sm px-3 text-[11px]",children:"Cancel"}),e.jsxs(J,{onClick:Z,disabled:j||D.length===0,className:"h-7 rounded-sm px-3 text-[11px]",children:[j?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Es,{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:v=>{v.target===v.currentTarget&&l()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"capability-share-title","aria-describedby":"capability-share-description","data-capability-share-dialog":"true",className:"relative grid w-full max-w-3xl gap-0 overflow-visible rounded-xl border-0 bg-background text-foreground shadow-[0_34px_110px_-54px_rgba(0,0,0,0.55)]",onMouseDown:v=>v.stopPropagation(),children:[F,e.jsxs("button",{type:"button",onClick:l,className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:[e.jsx(it,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})}):null:e.jsx(wt,{open:t,onOpenChange:v=>{v||l()},children:e.jsx(yt,{"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:F})})}function at(t,s){return s?`agent:${t}:${s}`:`node:${t}`}function nf(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-")}function Aa(t,s,n){return`${at(t,n)}\0${s}`}function Da(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function rf(t,s,n){const r=s.find(i=>i.status!=="offline");if(r)return[at(r.id,of(n))];const a=tr(n)[0];return a?[at(t,a)]:[]}function af(t,s,n){const r=Jo(n);return[...s.flatMap(a=>r.length===0?[[at(a.id),{kind:"global"}]]:r.map(i=>[at(a.id,i),{kind:"global"}])),...tr(n).map(a=>[at(t,a),Zo(n)])]}function Jo(t){return t.length===0||t.some(s=>s.kind==="plugin")?[]:Yo}function of(t){if(!(t.length===0||t.some(s=>s.kind==="plugin")))return t[0]?.agent}function tr(t){if(t.length===0||t.some(n=>n.kind==="plugin"))return[];const s=new Set(t.map(n=>n.agent));return Yo.filter(n=>!s.has(n))}function Zo(t){return t[0]?.scope??{kind:"global"}}const _a="h-7 rounded-sm border-0 bg-muted/55 px-2 text-[9px] leading-none shadow-none hover:bg-muted/70 [&>svg]:h-3 [&>svg]:w-3",vt="py-0.5 pl-6 pr-1.5 text-[9px] leading-4 [&_svg]:h-3 [&_svg]:w-3",Xo="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",lf="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 cf(t,s,n,r){return n.map(a=>({sourceNodeId:t,capabilityId:a.id,sourceScope:s,targets:r.map(i=>({nodeId:i.nodeId,scope:i.scope,...i.targetAgent?{targetAgent:i.targetAgent}:{}}))}))}function df(t,s,n,r){return n.map(a=>({sourceNodeId:t,capabilityId:a.id,sourceScope:s,targets:r}))}function uf({loading:t,onRefresh:s}){return e.jsxs(J,{variant:"ghost",onClick:s,disabled:t,"aria-busy":t,className:O(Xo,"min-w-[4.5rem]"),children:[e.jsx(co,{className:O("h-2.5 w-2.5",t&&"animate-spin")}),t?"Refreshing":"Refresh"]})}function mf({selectedCount:t,loading:s,onClearSelection:n,onRefresh:r,onShare:a}){return e.jsxs("div",{className:"flex items-center justify-between gap-2 bg-card/15 px-0.5 pt-1.5 text-[9px] text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(J,{type:"button",variant:"ghost",onClick:n,disabled:t===0,className:Xo,children:[e.jsx(it,{className:"h-2.5 w-2.5"}),"Selected: ",t," / Clear"]})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(uf,{loading:s,onRefresh:r}),e.jsxs(J,{type:"button",variant:"ghost",onClick:a,disabled:t===0,className:lf,children:[e.jsx(Es,{className:"h-2.5 w-2.5"}),"Share"]})]})]})}function hf({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 ff({visible:t}){return t?e.jsx("div",{className:"absolute inset-2.5 z-10 flex items-center justify-center rounded-sm border border-border/60 bg-background/85 shadow-sm backdrop-blur-sm",children:e.jsxs("div",{className:"flex w-full max-w-80 flex-col items-center gap-3 px-5 text-center",children:[e.jsxs("div",{className:"relative flex h-10 w-10 items-center justify-center rounded-full border border-primary/25 bg-primary/8",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border border-primary/20 animate-ping"}),e.jsx(de,{className:"relative h-4 w-4 animate-spin text-primary"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:"Loading capabilities"}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Reading agent skills, plugins, and MCP servers for this selection."})]}),e.jsxs("div",{className:"grid w-full gap-1.5","aria-hidden":"true",children:[e.jsx("span",{className:"h-1.5 rounded-full bg-muted animate-pulse"}),e.jsx("span",{className:"mx-auto h-1.5 w-3/4 rounded-full bg-muted/70 animate-pulse"})]})]})}):null}function xf({open:t,node:s,scope:n,clusterNodes:r,onOpenChange:a,onSelectionChange:i}){const[l,c]=o.useState([]),[d,m]=o.useState([]),[g,u]=o.useState(!1),[h,p]=o.useState(""),[k,j]=o.useState("all"),[A,f]=o.useState("all"),[E,y]=o.useState(new Set),[x,b]=o.useState(null),[C,S]=o.useState(null),[P,T]=o.useState(!1),[I,_]=o.useState(null),[D,L]=o.useState(!1),[z,Q]=o.useState([]),[Y,X]=o.useState(Ko),[Z,te]=o.useState(null),q=o.useMemo(()=>Ih(l,{search:h,agent:k,kind:A}),[k,l,A,h]),F=o.useMemo(()=>l.filter(G=>E.has(G.id)),[l,E]),v=o.useMemo(()=>r.filter(G=>G.id!==s.id),[r,s.id]),$=n.kind==="project"?n.projectPath:"global",N=async()=>{u(!0);try{const G=await Bl(s.id,{scope:n});c(G.items),m((G.errors??[]).map(M=>`${M.agent}: ${M.message}`))}catch(G){m([G instanceof Error?G.message:"Failed to load capabilities"])}finally{u(!1)}};o.useEffect(()=>{t&&(y(new Set),b(null),S(null),T(!1),Q([]),c([]),m([]),N())},[t,s.id,n.kind,$]),o.useEffect(()=>{if(!Z)return;const G=ne=>{X(Oh(Z.startWidth,Z.startClientX,ne.clientX,window.innerWidth))},M=()=>te(null);return window.addEventListener("pointermove",G),window.addEventListener("pointerup",M),()=>{window.removeEventListener("pointermove",G),window.removeEventListener("pointerup",M)}},[Z]);const W=G=>{G.preventDefault(),te({startClientX:G.clientX,startWidth:Y})},R=()=>{te(null),T(!1),b(null),S(null)},K=()=>{y(new Set),Q([])},B=async G=>{b(G.id),T(!0),S(null);const M=await Ol(s.id,G.id,n);S(M.detail)},oe=o.useCallback(async G=>{if(F.length===0||G.length===0){Q([]);return}Q([]);try{const M=cf(s.id,n,F,G),ne=await Promise.all(M.map(V=>Ll(V)));Q(ne.flatMap((V,re)=>V.results.map(we=>({...we,capabilityId:M[re]?.capabilityId}))))}catch{Q([])}},[s.id,n,F]),ie=()=>{Q([]),L(!0)},he=async G=>{const M=df(s.id,n,F,G);M.length!==0&&(await Promise.all(M.map(ne=>zl(ne))),ce.success(`${M.length} capability share request${M.length===1?"":"s"} completed`),L(!1))},ae=async()=>{if(!(!C||I)){_(C.id);try{const G=await Fl(s.id,C.id,n);G.status==="deleted"?(ce.success(`Deleted ${C.name}`),c(M=>M.filter(ne=>ne.id!==C.id)),y(M=>{const ne=new Set(M);return ne.delete(C.id),ne}),b(null),S(null),T(!1),await N()):(ce.info(G.message??"Capability was not found"),b(null),S(null),T(!1),await N())}catch(G){ce.error(G instanceof Error?G.message:"Failed to delete capability")}finally{_(null)}}};return e.jsx(e.Fragment,{children:e.jsx(wt,{open:t,onOpenChange:a,children:e.jsxs(yt,{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(cs,{className:"border-b border-border/55 bg-card/28 px-4 py-2.5 text-left",children:[e.jsx(Tt,{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(Yh,{node:s,scope:n,clusterNodes:r,onSelectionChange:i}),e.jsxs(ds,{"data-capability-selection-help":"true",className:"ml-auto max-w-[min(32rem,38vw)] space-y-0.5 pt-0.5 text-right text-[9px] leading-[11px] text-muted-foreground",children:[e.jsx("span",{className:"block truncate whitespace-nowrap",children:"Sharing copies into selected agents on target nodes."}),n.kind==="project"&&e.jsx("span",{"data-capability-selection-path":"true",className:"block truncate font-mono text-[7px] leading-[10px] text-muted-foreground/80",title:n.projectPath,children:n.projectPath})]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:flex-row",children:[e.jsxs("main",{className:"relative flex min-w-0 flex-1 flex-col gap-2 bg-gradient-to-b from-primary/4 via-background/20 to-background/40 p-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-44 flex-1",children:[e.jsx(La,{className:"pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),e.jsx(ot,{value:h,onChange:G=>p(G.target.value),placeholder:"Search capabilities",className:"h-7 rounded-sm border-0 bg-muted/55 pl-6 text-[10px] shadow-none"})]}),e.jsxs(_e,{value:k,onValueChange:G=>j(G),children:[e.jsx(Me,{className:O("w-28",_a),children:e.jsx($e,{})}),e.jsxs(Pe,{className:"shadow-none",children:[e.jsx(De,{value:"all",className:vt,children:"Agent: All"}),e.jsx(De,{value:"claudecode",className:vt,children:"Claude Code"}),e.jsx(De,{value:"codex",className:vt,children:"Codex"}),e.jsx(De,{value:"copilot",className:vt,children:"Copilot"})]})]}),e.jsxs(_e,{value:A,onValueChange:G=>f(G),children:[e.jsx(Me,{className:O("w-24",_a),children:e.jsx($e,{})}),e.jsxs(Pe,{className:"shadow-none",children:[e.jsx(De,{value:"all",className:vt,children:"Kind: All"}),e.jsx(De,{value:"skill",className:vt,children:"Skill"}),e.jsx(De,{value:"plugin",className:vt,children:"Plugin"}),e.jsx(De,{value:"mcp",className:vt,children:"MCP"})]})]})]}),d.length>0&&e.jsx("div",{className:"rounded-sm bg-amber-500/10 px-2 py-1 text-[10px] text-amber-600",children:d.join(" · ")}),e.jsx(Rh,{items:q,selectedIds:E,activeId:x,onToggleSelected:(G,M)=>y(ne=>{const V=new Set(ne);return M?V.add(G):V.delete(G),V}),onOpenDetail:B}),e.jsx(mf,{selectedCount:E.size,loading:g,onClearSelection:K,onRefresh:N,onShare:ie}),e.jsx(ff,{visible:g&&l.length===0})]}),P&&e.jsxs(e.Fragment,{children:[e.jsx(hf,{onBeginResize:W,onFold:R}),e.jsx(Fh,{detail:C,deleting:I===C?.id,desktopWidth:Y,onDelete:C?ae:void 0,pending:!C})]})]}),D&&e.jsx(sf,{open:D,sourceNode:s,targetNodes:v,selectedCapabilities:F,previewResults:z,embedded:!0,onClose:()=>L(!1),onPreviewTargetsChange:oe,onShare:he})]})})})}function pf(t){const[s,n]=o.useState(null),r=o.useMemo(()=>s?t?.nodes.find(d=>d.id===s.nodeId)??(t?.self.id===s.nodeId?t.self:null)??null:null,[t,s]),a=o.useCallback(d=>{n({nodeId:d,scope:{kind:"global"}})},[]),i=o.useCallback((d,m)=>{n({nodeId:d,scope:{kind:"project",projectPath:m}})},[]),l=o.useCallback(d=>{n(d)},[]);return{capabilitiesDialog:s&&r&&t?e.jsx(xf,{open:!0,node:r,scope:s.scope,clusterNodes:t.nodes,onOpenChange:d=>{d||n(null)},onSelectionChange:l}):null,openNodeCapabilities:a,openProjectCapabilities:i}}function gf(){const{id:t}=Ul(),s=$l(),n=ql(),r=Vl(),{cluster:a,systemInfo:i,events:l,sseConnected:c,subscribe:d,refresh:m,loading:g,error:u}=Hl(),h=o.useMemo(()=>Kl(s.state),[s.state]),[p,k]=o.useState(null),[j,A]=o.useState("active"),[f,E]=o.useState("all"),[y,x]=o.useState("all"),[b,C]=o.useState("all"),S=r?.headerSearchQuery??"",P=o.useDeferredValue(S),{desktopTasksOpen:T,mobileTasksPanelOpen:I,mobileTasksPanelRef:_,operationsOpen:D,operationsPanelRef:L,panelResize:z,setMobileTasksPanelOpen:Q,setOperationsOpen:Y,toggleTasksPanel:X}=eh(),[Z,te]=o.useState(()=>!!h?.draftNewTask),[q,F]=o.useState(()=>h?.createMode??"chat"),[v,$]=o.useState(()=>h?.createDefaults??null),[N,W]=o.useState(()=>h?.draftNewTask?{route:h.returnRoute??"/",taskId:h.returnTaskId??null}:null),[R,K]=o.useState(!1),[B,oe]=o.useState("transcript"),[ie,he]=o.useState("overview"),[ae,G]=o.useState("all"),[M,ne]=o.useState(!1),[V,re]=o.useState(null),[we,fe]=o.useState([]),[Ie,Ee]=o.useState([]),[xt,Le]=o.useState(!1),[Ze,Se]=o.useState(!1),[He,We]=o.useState(null),[Ke,Oe]=o.useState(new Set),[lt,ct]=o.useState(!1),[ee,ge]=o.useState(!1),[ye,Fe]=o.useState(null),ze=o.useRef(null),Ne=o.useRef(new Map),je=a?.self?.role==="leader",pt=a?.self?.id,{quickChats:zt}=Gl();fh({cluster:a,subscribe:d});const{nodeSettingsDialog:Ut,openNodeSettings:H}=Dh(je),{capabilitiesDialog:ke,openNodeCapabilities:Ae,openProjectCapabilities:jt}=pf(a),{devBoxDialog:$t,devBoxNodeIds:Nt,devBoxStartNodeId:Be,devBoxStartNodeIds:Qe,devBoxStartingNodeIds:nt,openDevBox:dt,startDevBox:ut}=Ah({cluster:a,refresh:m}),{completedGroups:Dt=[],fetchTasks:Re,loadCompletedTasksPage:mt,removeTasksFromList:Ce,setTasks:Xe,tasks:qe,tasksError:qt,tasksLoading:pe}=dh({isLeader:je,selfId:pt,sseConnected:c,preservedTask:V,subscribe:d});o.useEffect(()=>Wl(()=>{he("events"),Y(!0)}),[Y]);const be=o.useMemo(()=>[...qe].sort((w,U)=>U.updatedAt-w.updatedAt),[qe]),Te=o.useMemo(()=>[...qe].sort((w,U)=>U.createdAt-w.createdAt||U.updatedAt-w.updatedAt)[0]?.id??null,[qe]),us=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[]){const se=Cd(be,U.id);se>0&&w.set(U.id,se)}return w},[a?.nodes,be]),rt=o.useMemo(()=>be.filter(w=>!Ql(w,a?.nodes,a?.self)||!Yl(w,j)||f!=="all"&&w.agent!==f||!Jl(w,b)||y==="unassigned"&&w.assignedTo||y!=="all"&&y!=="unassigned"&&Zl(w.assignedTo,a?.nodes,w.assignedNodeName)!==y?!1:P.trim()?Xl(w,P):!0),[be,a?.nodes,a?.self,j,f,b,y,P]);o.useEffect(()=>{Oe(w=>{const U=Md(w,rt.map(se=>se.id));return U.size===w.size?w:U})},[rt]),o.useEffect(()=>{je||Oe(new Set)},[je]);const ei=o.useMemo(()=>["all",...Array.from(new Set(be.map(w=>w.agent))).sort()],[be]),ti=o.useMemo(()=>{const U=Array.from(new Set(be.map(se=>se.assignedTo).filter(se=>!!se))).map(se=>{const ve=be.find(me=>me.assignedTo===se);return a?.nodes.find(me=>me.id===se)??{id:se,name:Sn(se,a?.nodes,ve?.assignedNodeName)}}).sort((se,ve)=>se.name.localeCompare(ve.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...U.map(se=>({value:se.name.toLowerCase(),label:se.name}))]},[be,a?.nodes]),sr=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[])w.set(U.id,U.name);for(const U of be)U.assignedTo&&U.assignedNodeName&&!w.has(U.assignedTo)&&w.set(U.assignedTo,U.assignedNodeName);return w},[a?.nodes,be]),si=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[])U.workDir&&w.set(U.id,U.workDir);return a?.self?.workDir&&w.set(a.self.id,a.self.workDir),w},[a]),ni=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[])w.set(U.id,U.status);return a?.self&&w.set(a.self.id,a.self.status),w},[a]),ri=o.useMemo(()=>new Map(Dt.map(w=>[Fn(w),w])),[Dt]),nr=o.useMemo(()=>{const w=new Map;for(const U of a?.nodes??[])U.status!=="offline"&&w.set(U.id,U);return a?.self&&a.self.status!=="offline"&&w.set(a.self.id,a.self),Array.from(w.values())},[a]),ai=a?.self?.id??nr[0]?.id??null,Vt=o.useMemo(()=>l.filter(ec),[l]),Ls=o.useMemo(()=>["all",...Array.from(new Set(Vt.map(w=>w.type))).sort()],[Vt]),oi=o.useMemo(()=>ae==="all"?Vt:Vt.filter(w=>w.type===ae),[Vt,ae]),ii=rt.length>0&&rt.every(w=>Ke.has(w.id)),li=rt.some(w=>Ke.has(w.id)),ci=Pd(rt,Ke);o.useEffect(()=>{h?.draftNewTask&&(te(!0),F(h.createMode??"chat"),$(h.createDefaults??null),W({route:h.returnRoute??"/",taskId:h.returnTaskId??null}))},[h]),o.useEffect(()=>{ae!=="all"&&!Ls.includes(ae)&&G("all")},[ae,Ls]),o.useEffect(()=>{wr(t,Z)&&!p&&Te&&k(Te)},[t,Z,p,Te]),o.useEffect(()=>{wr(t,Z)&&(p&&qe.some(w=>w.id===p)||k(Te))},[t,Z,p,Te,qe]);const xe=Ed({routeTaskId:t,creatingTask:Z,internalSelectedTaskId:p,sortedTaskIds:Te?[Te]:[]}),_t=o.useMemo(()=>qe.find(w=>w.id===xe)??null,[qe,xe]);o.useEffect(()=>{ze.current=xe??null},[xe]);const gt=o.useCallback(()=>{re(null),fe([]),Ee([]),We(null),Se(!1)},[]),Ht=o.useCallback((w,U,se=!0)=>{Ne.current.set(w,{logs:$o(U),loaded:se})},[]),Ye=o.useCallback(async()=>{const w=xe;if(w)try{const U=await tc(w);if(ze.current!==w)return;re(U),Xe(se=>fo(se,U)),We(null)}catch(U){if(ze.current!==w)return;gt(),We(U instanceof Error?U.message:"Failed to load task")}finally{ze.current===w&&Le(!1)}},[xe,gt,Xe]),ms=o.useCallback(async()=>{const w=xe;if(w)try{const U=await En(w);if(ze.current!==w)return;fe(se=>{const ve=ro(se,U.logs);return Ht(w,ve),ve}),Ee(se=>_n(se,U.logs))}catch{}finally{ze.current===w&&Se(!1)}},[xe,Ht]);o.useEffect(()=>{if(!xe){gt(),Le(!1);return}oe("transcript"),re(_t);const w=uh(xe,Ne.current);fe(w.logs),Ee([]),We(null),Le(!0),Se(w.transcriptLoading),Ye(),ms()},[xe,gt,ms,Ye]),o.useEffect(()=>{if(!Ad({activeTaskId:xe,routeTaskId:t,creatingTask:Z,tasksLoading:pe,loadedTaskIds:qe.map(U=>U.id)}))return;const w=Te;k(w),gt(),o.startTransition(()=>{n(w?`/tasks/${w}`:"/",{state:null})})},[xe,gt,Z,Te,n,t,qe,pe]),o.useEffect(()=>{_t&&re(w=>!w||w.id!==_t.id?w:{...w,..._t})},[_t]),o.useEffect(()=>{if(xe)return d("task",w=>{const U=w.data.taskId;if(!(typeof U!="string"||U!==xe)){if(w.type==="task.output"){const se=w.data.event;if(se){fe(me=>{const Gt=yc(me,se);return Ht(xe,Gt),Gt}),Se(!1);const ve=An(se);ve&&Ee(me=>jc(me,ve))}}w.type==="task.updated"&&Ye(),w.type==="task.status"&&(Ye(),ms())}})},[d,xe,Ye,ms]);const le=V??_t,di=le?.assignedTo?a?.nodes.find(w=>w.id===le.assignedTo)??null:null,Kt=r?.setHeaderTaskContext;o.useEffect(()=>{if(!Kt)return;if(!le){Kt(null);return}const w=le.effectiveProjectPath??le.project??"default workspace";return Kt({taskId:le.id,taskTitle:le.title,nodeName:Sn(le.assignedTo,a?.nodes,le.assignedNodeName),projectLabel:Ka(w),projectPath:w}),()=>Kt(null)},[le,a?.nodes,Kt]);const Bs=Ie.length>0,ui=le?sc.has(le.agent):!1,hs=le?.status==="running",mi=le?ks.has(le.status):!1,hi=le?ks.has(le.status)||nc.has(le.status):!1,fi=!!(le&&je&&le.status==="failed"),Os=o.useMemo(()=>zm(le,a,Bs,!!hs),[le,a,Bs,hs]),Fs=o.useMemo(()=>Nc([...we,...Ie.map(w=>Hs(w.content,w.timestamp))]),[we,Ie]),fs=o.useMemo(()=>{if(!le||le.conversationKind==="nativeSession")return null;const w=kc(le);if(w.length>0)return Hs(w,new Date(le.createdAt).toISOString());if(Fs.length>0)return null;const U=Sc(le.description||le.title);return U.length>0?Hs(U,new Date(le.createdAt).toISOString()):null},[le,Fs]),zs=o.useMemo(()=>fs?An(fs):null,[fs]),xi=o.useMemo(()=>zs?Cc(we,zs):!1,[we,zs]),Us=o.useCallback((w="chat",U)=>{const se={route:t?`/tasks/${t}`:"/",taskId:xe};W(se),F(w),$(U??null),te(!0),o.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:se.route,returnTaskId:se.taskId,createMode:w,createDefaults:U}})})},[t,xe,n]),pi=o.useCallback(()=>{const w=N?.taskId??Te;te(!1),W(null),$(null),k(w),o.startTransition(()=>{n(N?.route??"/",{state:null})})},[N,Te,n]),rr=o.useCallback(w=>{te(!1),W(null),$(null),k(w),o.startTransition(()=>{n(`/tasks/${w}`,{state:null})})},[n]),gi=o.useCallback(w=>{ze.current=w.id,te(!1),W(null),$(null),Xe(U=>Dd(U,w)),re(w),fe([]),Ee([]),We(null),Le(!1),Se(w.conversationKind==="nativeSession"),oe("transcript"),k(w.id),ph({task:w,getActiveTaskId:()=>ze.current,setLogs:fe,setPendingMessages:Ee,setTranscriptLoading:Se}),Re(),o.startTransition(()=>{n(`/tasks/${w.id}`,{state:null})})},[Re,n]),{cancelQueuedMessage:bi,queueFollowUpMessage:xs}=Mh({activeTaskId:xe,fetchActiveTask:Ye,isRunning:hs,setPendingMessages:Ee,setTask:re,setTasks:Xe}),vi=o.useCallback(w=>{xs(w)},[xs]),wi=o.useCallback(async()=>{const w=xe;if(!(!w||le?.conversationKind!=="nativeSession")){Se(!0);try{const U=await En(w);if(ze.current!==w)return;fe(U.logs),Ht(w,U.logs),Ee(se=>_n(se,U.logs))}catch(U){ce.error(U instanceof Error?U.message:"Failed to reload transcript")}finally{ze.current===w&&Se(!1)}}},[le?.conversationKind,xe,Ht]),yi=o.useCallback(w=>xs(w),[xs]),ji=o.useCallback(async()=>{if(le)try{await rc(le.id),Ye(),Re()}catch(w){ce.error(w instanceof Error?w.message:"Failed to cancel task")}},[le,Ye,Re]),{handleShareTask:Ni,handleStopShareTask:ki}=Ym(le,Ye,Re),Si=o.useCallback(async()=>{if(le)try{await ac(le.id),Ye(),Re()}catch(w){ce.error(w instanceof Error?w.message:"Failed to retry task")}},[le,Ye,Re]),ps=o.useCallback((w,U=!1)=>{const se=Id(rt,w);return k(se),(U||!se)&&gt(),o.startTransition(()=>{n(se?`/tasks/${se}`:"/",{state:null})}),se},[gt,rt,n]),Ci=o.useCallback((w,U)=>{Oe(se=>{const ve=new Set(se);return U?ve.add(w):ve.delete(w),ve})},[]),Ti=o.useCallback(w=>{if(!w){Oe(new Set);return}Oe(new Set(rt.map(U=>U.id)))},[rt]),Ei=o.useCallback(async()=>{const w=Array.from(Ke);if(w.length!==0)try{const{results:U}=await oc(w),se=U.filter(me=>!me.ok),ve=U.filter(me=>me.ok).map(me=>me.id);xe&&ve.includes(xe)&&ps(ve),se.length>0?ce.error(`Failed to archive ${se.length} task(s): ${se.map(me=>me.error??me.id).join(", ")}`):ce.success(`Archived ${ve.length} task(s)`),Oe(new Set(se.map(me=>me.id))),Re()}catch(U){ce.error(U instanceof Error?U.message:"Failed to archive tasks")}},[xe,Re,ps,Ke]),Ai=o.useCallback(async()=>{const w=Array.from(Ke);if(w.length!==0)try{const{results:U}=await ic(w),se=U.filter(me=>!me.ok),ve=U.filter(me=>me.ok).map(me=>me.id);ve.length>0&&Ce(ve),xe&&ve.includes(xe)&&ps(ve,!0),se.length>0?ce.error(`Failed to delete ${se.length} task(s): ${se.map(me=>me.error??me.id).join(", ")}`):ce.success(`Deleted ${ve.length} task(s)`),Oe(new Set(se.map(me=>me.id))),Re()}catch(U){ce.error(U instanceof Error?U.message:"Failed to delete tasks")}},[xe,Re,ps,Ce,Ke]),Di=o.useCallback(async()=>{ct(!0);try{await lc(),m()}catch(w){ce.error(w instanceof Error?w.message:"Failed to promote node")}finally{ct(!1)}},[m]),_i=o.useCallback(async()=>{ge(!0);try{await cc(),ce.success("This node left the remote cluster and is leading itself again."),Re(),Ye(),m()}catch(w){ce.error(w instanceof Error?w.message:"Failed to leave cluster")}finally{ge(!1)}},[Ye,Re,m]),Mi=o.useCallback(async w=>{const U=!Gn(w),se=w.id===a?.self?.id,ve=se?i?.transportType??w.transportType:w.transportType,me=se&&!U&&Ft(ve);Fe(w.id);try{me?await dc("direct"):await uc(w.id,U),ce.success(U?`Enabled remote access on ${w.name}`:`Disabled remote access on ${w.name}`),m()}catch(Gt){ce.error(Gt instanceof Error?Gt.message:"Failed to update remote access")}finally{Fe(null)}},[a?.self?.id,m,i?.transportType]),Pi=o.useCallback(w=>{mt&&mt(w).catch(U=>{ce.error(U instanceof Error?U.message:"Failed to load completed tasks")})},[mt]),ar={toolbarTasks:rt,activeTaskId:xe,tasksLoading:pe,tasksError:qt,isLeader:je,scope:j,agentFilter:f,nodeFilter:y,taskKindFilter:b,agentOptions:ei,nodeOptions:ti,nodeNameById:sr,nodeWorkDirById:si,nodeStatusById:ni,leaderNodeId:a?.leader?.id??null,searchQuery:S,completedGroupByKey:ri,devBoxNodeIds:Nt,devBoxStartNodeIds:Qe,devBoxStartingNodeIds:nt,selectedTaskIds:Ke,allVisibleTasksSelected:ii,someVisibleTasksSelected:li,canBatchArchive:ci,onScopeChange:A,onAgentFilterChange:E,onNodeFilterChange:x,onTaskKindFilterChange:C,onToggleTaskSelected:Ci,onToggleAllVisibleTasks:Ti,onBatchArchive:Ei,onBatchDelete:Ai,onCreateTask:Us,onOpenNodeSettings:je?H:void 0,onOpenNodeCapabilities:je?Ae:void 0,onOpenProjectCapabilities:je?jt:void 0,onOpenDevBox:je?dt:void 0,onStartDevBox:je?ut:void 0,onLoadCompletedTasks:Pi,onSelectTask:rr},Ii={cluster:a,systemInfo:i,nodeNameById:sr,nodeBlockingTaskCounts:us,eventTypeFilter:ae,onEventTypeFilterChange:G,activeTab:ie,onTabChange:he,eventTypeOptions:Ls,filteredEvents:oi,sseConnected:c,clusterLoading:g,clusterError:u,promotePending:lt,onPromote:Di,onAddNode:()=>K(!0),leavePending:ee,onLeaveCluster:_i,onToggleNodeDevTunnel:Mi,devTunnelNodeId:ye,devBoxStartNodeId:Be,devBoxStartingNodeIds:nt,onOpenNodeSettings:je?H:void 0,onOpenNodeCapabilities:je?Ae:void 0,onOpenDevBox:je?dt:void 0,onStartDevBox:je?ut:void 0};return e.jsxs(e.Fragment,{children:[e.jsx(Ku,{desktopTasksOpen:T,mobileTasksPanelOpen:I,mobileTasksPanelRef:_,operationsOpen:D,operationsPanelRef:L,panelResize:z,taskSidebar:e.jsx(pa,{...ar}),operationsSidecar:e.jsx(Om,{...Ii}),terminalPanel:r?.terminalOpen?e.jsx(em,{nodes:nr,defaultNodeId:ai,onClose:()=>r?.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(Bu,{onToggleTasks:X,desktopTasksOpen:T,mobileTasksPanelOpen:I,operationsOpen:D,onToggleOperations:()=>Y(w=>!w),cluster:a,sseConnected:c,activeTab:B,setActiveTab:oe,creatingTask:Z,createMode:q,createDefaults:v,activeTask:le,assignedNode:di,taskLoading:xt,transcriptLoading:Ze,taskError:He,displayEvents:Fs,initialPromptAlreadyInLogs:xi,initialPrompt:fs,supportsFollowUp:ui,taskUnavailable:Os.taskUnavailable,chatDisabled:Os.chatDisabled,chatDisabledReason:Os.chatDisabledReason,questionBypassEnabled:M,isRunning:!!hs,isStarting:mi,hasPendingFollowUp:Bs,canCancel:!!hi,canRetry:!!fi,onRetry:Si,onCancel:ji,onReloadNativeTranscript:wi,onShareTask:Ni,onStopShareTask:ki,onStartCreateTask:Us,onCancelCreateTask:pi,onCreateTask:gi,onSendMessage:vi,onCancelQueuedMessage:bi,onQuestionBypassChange:ne,onSubmitQuestionResponse:yi,quickChats:zt}),mobileTaskSidebar:e.jsx(pa,{...ar,onCreateTask:(w,U)=>{Q(!1),Us(w,U)},onSelectTask:w=>{Q(!1),rr(w)}}),onCloseOperations:()=>Y(!1),onCloseTaskList:()=>Q(!1),onToggleOperations:()=>Y(w=>!w),onToggleTasks:X}),e.jsx(Uu,{open:R,onOpenChange:K,onAdded:m}),Ut,$t,ke]})}const jf=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:gf},Symbol.toStringTag,{value:"Module"}));export{ao as A,jf as D,Cs as G};