meshy-node 0.9.1 → 0.9.3

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