meshy-node 0.8.8 → 0.8.9
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.
- package/README.md +1 -1
- package/dashboard/assets/DashboardPage-1YfzxMX4.js +144 -0
- package/dashboard/assets/{DashboardShared-NVn_Tw2W.js → DashboardShared-BhuvZY0B.js} +18 -18
- package/dashboard/assets/{DiffTab-CAro0pTI.js → DiffTab-DrsxsCTo.js} +3 -3
- package/dashboard/assets/{FilesTab-Bz7sh_3g.js → FilesTab-2p61JxFR.js} +1 -1
- package/dashboard/assets/{PreviewTab-DoI4vsUp.js → PreviewTab-hE7s4Tq6.js} +2 -2
- package/dashboard/assets/{SharedConversationPage-BOY747wP.js → SharedConversationPage-FDJRMTJV.js} +3 -3
- package/dashboard/assets/{file-Dntylbon.js → file-BBv9tDe9.js} +1 -1
- package/dashboard/assets/{index-uVUa1V95.js → index-CR3C-F8v.js} +68 -68
- package/dashboard/assets/index-Df0Lew9J.css +1 -0
- package/dashboard/assets/{play-142JBIu2.js → play-D8zhWxnK.js} +1 -1
- package/dashboard/index.html +2 -2
- package/main.cjs +2161 -583
- package/package.json +1 -1
- package/runtime-metadata.json +4 -4
- package/dashboard/assets/DashboardPage-bSrGTUpL.js +0 -134
- package/dashboard/assets/index-j4uVsDWB.css +0 -1
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-Bz7sh_3g.js","assets/index-uVUa1V95.js","assets/index-j4uVsDWB.css","assets/DashboardShared-NVn_Tw2W.js","assets/file-Dntylbon.js","assets/PreviewTab-DoI4vsUp.js","assets/play-142JBIu2.js","assets/DiffTab-CAro0pTI.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as je,r as n,j as e,X as ot,B as I,S as Un,a as dr,b as $,d as cr,g as ur,e as mr,I as nt,C as Pt,f as xr,h as hr,F as fr,i as Vn,k as Bt,l as ke,D as Rt,m as pr,n as gr,t as ne,o as Te,p as Ee,q as Ue,s as De,u as cs,v as it,T as br,w as vr,x as rn,y as jr,z as Ps,A as Bs,E as Rs,G as qn,H as Kn,J as wt,K as us,L as wr,M as Hn,N as Wn,P as Nr,O as Gn,Q as xt,R as Ye,U as yr,V as ht,W as ms,Y as xs,Z as hs,_ as fs,$ as ps,a0 as gs,a1 as bs,a2 as vs,a3 as $s,a4 as kr,a5 as Qn,a6 as Yn,a7 as Sr,a8 as on,a9 as ln,aa as Kt,ab as Cr,ac as _r,ad as Tr,ae as Er,af as Dr,ag as Ar,ah as Mr,ai as Lr,aj as Xn,ak as Jn,al as Zn,am as Pr,an as Ht,ao as Os,ap as Br,aq as Rr,ar as $r,as as ea,at as js,au as Or,av as dn,aw as Fr,ax as Ir,ay as zr,az as Ur,aA as cn,aB as Vr,aC as qr,aD as ns,aE as Kr,aF as un,aG as Hr,aH as Wr,aI as Gr,aJ as mn,aK as Qr,aL as Yr,aM as ws,aN as Xr,aO as Jr,aP as Zr,aQ as xn,aR as ta,aS as eo,aT as to,aU as so,aV as no,aW as ao,aX as ro,aY as oo,aZ as io,a_ as lo,a$ as co,b0 as uo,b1 as mo,b2 as xo,b3 as ho,b4 as fo,b5 as po,b6 as go,b7 as bo,b8 as vo,b9 as jo,ba as wo,bb as No,bc as yo,bd as ko,be as So,bf as Co}from"./index-uVUa1V95.js";import{r as hn,e as _o,b as sa,t as na,A as Fs,L as xe,g as aa,a as To,c as Eo,d as fn,f as pn,h as Do,i as Ao,C as gn,T as as,D as jt,I as st,M as Ns,j as ra,k as Mo,m as oa,l as ys,n as Lo,o as bn,p as Po,q as Bo,s as rs,u as Ro,v as $o,w as Oo}from"./DashboardShared-NVn_Tw2W.js";import{P as Is}from"./play-142JBIu2.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 Fo=[["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"}]],Io=je("archive",Fo);/**
|
|
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 zo=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Uo=je("arrow-up",zo);/**
|
|
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 Vo=[["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"}]],qo=je("ellipsis-vertical",Vo);/**
|
|
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 Ko=[["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"}]],Ho=je("flag",Ko);/**
|
|
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 Wo=[["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"}]],zs=je("folder-open",Wo);/**
|
|
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 Go=[["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"}]],Qo=je("funnel",Go);/**
|
|
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 Yo=[["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"}]],ks=je("git-branch",Yo);/**
|
|
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 Xo=[["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"}]],Jo=je("globe",Xo);/**
|
|
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 Zo=[["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"}]],Ss=je("history",Zo);/**
|
|
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 ei=[["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"}]],Cs=je("image-plus",ei);/**
|
|
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 ti=[["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"}]],si=je("laptop",ti);/**
|
|
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 ni=[["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"}]],Us=je("link-2",ni);/**
|
|
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 ai=[["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"}]],ri=je("list-ordered",ai);/**
|
|
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 oi=[["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"}]],Wt=je("message-square-plus",oi);/**
|
|
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 ii=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]],ia=je("panel-left-close",ii);/**
|
|
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 li=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m14 9 3 3-3 3",key:"8010ee"}]],di=je("panel-left-open",li);/**
|
|
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 ci=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]],Vs=je("panel-right-close",ci);/**
|
|
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 ui=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m10 15-3-3 3-3",key:"1pgupc"}]],la=je("panel-right-open",ui);/**
|
|
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 mi=[["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"}]],Ct=je("pencil",mi);/**
|
|
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 xi=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],hi=je("plus",xi);/**
|
|
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 fi=[["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"}]],vn=je("rotate-ccw",fi);/**
|
|
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 pi=[["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"}]],da=je("send",pi);/**
|
|
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 gi=[["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"}]],bi=je("share-2",gi);/**
|
|
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 vi=[["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"}]],ji=je("sliders-horizontal",vi);/**
|
|
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 wi=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],jn=je("square",wi);/**
|
|
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 Ni=[["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"}]],yi=je("trash-2",Ni),ki=new Set(["assigned","running"]);function Si(t,s){return t.reduce((a,o)=>o.assignedTo===s&&ki.has(o.status)?a+1:a,0)}function _t(t){return(t==null?void 0:t.toLowerCase())==="devtunnel"}function Ci(t){return t?_t(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function qs(t,s){return _t(s??t.transportType)||!!t.devtunnelEndpoint}function ca(t,s){return!_t(s??t.transportType)}function ua(t,s){const a=s??t.transportType;return _t(a)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":Ci(a)}function wn(t,s){return!t&&!s}function _i({routeTaskId:t,creatingTask:s,internalSelectedTaskId:a,sortedTaskIds:o}){return t||(s?null:o[0]??a??null)}function Ti({activeTaskId:t,routeTaskId:s,creatingTask:a,tasksLoading:o,loadedTaskIds:r}){return!t||s||a||o?!1:!r.includes(t)}function Ei(t,s){return[s,...t.filter(a=>a.id!==s.id)]}function ma(t,s){const a=t.findIndex(o=>o.id===s.id);return a===-1?[...t,s]:t.map((o,r)=>r===a?s:o)}const Di=new Set(["completed","failed","cancelled","archived"]);function Ai(t,s){const a=new Set(s);return new Set(Array.from(t).filter(o=>a.has(o)))}function Mi(t,s){const a=new Set(s);if(a.size===0)return!1;const o=t.filter(r=>a.has(r.id));return o.length===a.size&&o.every(r=>Di.has(r.status))}function Li(t,s){var o;const a=new Set(s);return((o=t.find(r=>!a.has(r.id)))==null?void 0:o.id)??null}function xa(){const[t,s]=n.useState([]),[a,o]=n.useState(null),r=n.useRef(null),i=n.useCallback(()=>{var v;(v=r.current)==null||v.click()},[]),f=n.useCallback(async v=>{const c=Array.from(v.target.files??[]);if(c.length!==0)try{const l=await hn(c);s(j=>[...j,...l]),o(null)}catch(l){o(l instanceof Error?l.message:"Failed to attach image")}finally{v.target.value=""}},[]),p=n.useCallback(async v=>{const c=_o(v.clipboardData);if(c.length!==0){v.preventDefault();try{const l=await hn(c);s(j=>[...j,...l]),o(null)}catch(l){o(l instanceof Error?l.message:"Failed to attach image")}}},[]),w=n.useCallback(v=>{s(c=>c.filter((l,j)=>j!==v))},[]),N=n.useCallback(()=>{s([]),o(null)},[]);return{images:t,error:a,fileInputRef:r,pickImages:i,handleFileChange:f,handlePaste:p,removeImage:w,clearImages:N}}function Pi(t){const s=t.map(r=>({...r,displayValue:Bi(r)})),a=s.findIndex(r=>r.label.toLowerCase()==="working dir"),o=a>=0?a:0;return{primary:s[o],secondary:s.filter((r,i)=>i!==o)}}function Bi(t){return t.label.toLowerCase()==="agent"?aa(t.value):t.value}function Nn(t){switch(t.toLowerCase()){case"branch":return ks;case"node":return Un;case"working dir":default:return zs}}function Ri({disabled:t=!1,running:s=!1,canStop:a=!1,hasContent:o=!1}){return s&&!o?{primaryAction:"stop",primaryDisabled:t||!a}:{primaryAction:"send",primaryDisabled:t||!o}}function $i({contentLength:t,disabled:s=!1}){return t>0&&!s}function Oi({onSend:t,disabled:s,disabledReason:a="Chat is waiting on the agent.",placeholder:o="Send a follow-up message...",contextItems:r=[],running:i=!1,onStop:f}){const[p,w]=n.useState(""),[N,v]=n.useState(0),c=n.useRef(null),{images:l,error:j,fileInputRef:C,pickImages:b,handleFileChange:_,handlePaste:m,removeImage:y,clearImages:u}=xa(),g=n.useCallback(()=>{c.current&&(c.current.style.height="auto")},[]),S=n.useCallback(()=>{const M=sa(p,l);$i({contentLength:M.length,disabled:s})&&(v(B=>B+1),t(M),w(""),u(),g())},[p,l,s,t,u,g]),D=n.useCallback(M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),S())},[S]),L=n.useCallback(()=>{c.current&&(c.current.style.height="auto",c.current.style.height=`${Math.min(c.current.scrollHeight,220)}px`)},[]),G=p.trim().length>0||l.length>0,F=Ri({disabled:s,running:i,canStop:i&&!!f,hasContent:G}),A=Pi(r),ae=A.primary?Nn(A.primary.label):zs,W=i?G?"Enter queues this message for the next turn":f?"Task is running - type to queue, empty button stops task":"Task is running - type to queue a message":s?a:"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:C,type:"file",accept:"image/*",multiple:!0,onChange:_,className:"hidden"}),A.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(ae,{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:A.primary.value,children:A.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((M,B)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:na(M),alt:M.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 ${M.filename??`image ${B+1}`}`,children:e.jsx(ot,{className:"h-3.5 w-3.5"})})]},`${M.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:c,"data-chat-input-textarea":"true",value:p,onChange:M=>w(M.target.value),onKeyDown:D,onPaste:m,onInput:L,placeholder:o,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:[A.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:A.secondary.map(M=>{const B=Nn(M.label),re=M.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${M.label}: ${M.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[re?e.jsx(Fs,{agent:M.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 ${M.mono?"font-mono":""}`,children:M.displayValue})]},`${M.label}:${M.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(I,{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(Cs,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:W,children:e.jsx(I,{onClick:F.primaryAction==="stop"?f:S,disabled:F.primaryDisabled,size:"icon","data-chat-send-button":"true","aria-label":F.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:F.primaryAction==="stop"?e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(da,{className:`h-3.5 w-3.5 ${N>0?"animate-chat-send-flight":""}`},N)})})]})]}),j&&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:j})]})})})}var Fi=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ii=Fi.reduce((t,s)=>{const a=dr(`Primitive.${s}`),o=n.forwardRef((r,i)=>{const{asChild:f,...p}=r,w=f?a:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(w,{...p,ref:i})});return o.displayName=`Primitive.${s}`,{...t,[s]:o}},{}),zi="Label",ha=n.forwardRef((t,s)=>e.jsx(Ii.label,{...t,ref:s,onMouseDown:a=>{var r;a.target.closest("button, input, select, textarea")||((r=t.onMouseDown)==null||r.call(t,a),!a.defaultPrevented&&a.detail>1&&a.preventDefault())}}));ha.displayName=zi;var fa=ha;const Ui=cr("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Be=n.forwardRef(({className:t,...s},a)=>e.jsx(fa,{ref:a,className:$(Ui(),t),...s}));Be.displayName=fa.displayName;function Vi(t,s,a){return t!=="auto"?s.find(o=>o.id===t)??null:a.length===1?a[0]??null:null}function qi(t){return t.trim()||"."}function Ki(t){return new Promise(s=>window.setTimeout(s,t))}function Hi(t){return!!t&&typeof t=="object"&&typeof t.createdBranch=="string"&&typeof t.currentBranch<"u"}async function Wi(t){let s=t;for(let a=0;a<60;a++){if(s.status==="succeeded"){if(Hi(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 Ki(1e3),s=await xr(s.id)}throw new Error("Timed out waiting for branch creation")}function yn({value:t,onChange:s,project:a,assignTo:o,nodes:r,assignableNodes:i,layout:f="default",chipClassName:p,chipActiveClassName:w,chipInactiveClassName:N,labelClassName:v,triggerClassName:c}){const[l,j]=n.useState(!1),[C,b]=n.useState(null),[_,m]=n.useState(""),[y,u]=n.useState(!1),[g,S]=n.useState(!1),[D,L]=n.useState(!1),[G,U]=n.useState(null),[F,A]=n.useState(""),[ae,W]=n.useState(""),[M,B]=n.useState(""),[re,ee]=n.useState(!1),oe=n.useRef(null),ie=n.useRef(0),V=n.useMemo(()=>Vi(o,r,i),[o,r,i]),z=V==null?void 0:V.id,te=n.useMemo(()=>qi(a),[a]),we=n.useMemo(()=>z?`${z}
|
|
133
|
-
${te}`:"",[z,te]),h=n.useCallback(async(q=0,X=!1)=>{const se=ie.current+1,Se=we;if(ie.current=se,!z){b(null),m("");return}U(null),X||m(""),X?S(!0):u(!0);try{const P=await ur(z,{path:te,limit:20,offset:q,allowAbsolute:!0});if(se!==ie.current)return;m(Se),b(H=>X&&H?{...P,branches:[...H.branches,...P.branches]}:P)}catch(P){if(se!==ie.current)return;U(P instanceof Error?P.message:"Failed to load branch info"),X||(b(null),m(""))}finally{se===ie.current&&(u(!1),S(!1))}},[z,we,te]);n.useEffect(()=>{if(!z){ie.current+=1,b(null),m(""),U(null);return}h()},[z,te,h]),n.useEffect(()=>{const q=t.trim(),X=_===we?C:null,se=X!=null&&X.available&&X.currentBranch?X.currentBranch:"";q!==se&&s(se)},[C,we,_,s,t]),n.useEffect(()=>{if(!l)return;const q=se=>{oe.current&&(oe.current.contains(se.target)||j(!1))},X=se=>{se.key==="Escape"&&j(!1)};return document.addEventListener("mousedown",q),document.addEventListener("keydown",X),()=>{document.removeEventListener("mousedown",q),document.removeEventListener("keydown",X)}},[l]),n.useEffect(()=>{l&&(W(""),B(""),ee(!1))},[l,z,te]);const Y=n.useCallback(async()=>{if(!z)return;const q=F.trim(),X=re?M.trim():ae.trim();if(!(!q||!X)){L(!0),U(null);try{const se=await mr(z,{path:te,branchName:q,startPoint:X,limit:20,offset:0,allowAbsolute:!0}),Se=await Wi(se);m(we),b(Se),s(Se.currentBranch??Se.createdBranch),A(""),W(""),B(""),ee(!1),j(!1)}catch(se){U(se instanceof Error?se.message:"Failed to create branch")}finally{L(!1)}}},[z,we,te,re,M,F,s,ae]),T=_===we?C:null,J=n.useCallback(()=>{T!=null&&T.hasMore&&h(T.branches.length,!0)},[T,h]),x=t.trim()||(T==null?void 0:T.currentBranch)||(T&&!T.available?"No git repo":"Branch"),O=re?M.trim():ae.trim(),Q=!!(T!=null&&T.available&&F.trim()&&O&&!D),me=f==="composer"?e.jsxs(I,{type:"button",variant:"ghost",onClick:()=>j(q=>!q),title:x,"aria-label":`Branch: ${x}`,className:$(p,c,"min-w-0 max-w-full",t.trim()?w:N),children:[y&&!T?e.jsx(xe,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(ks,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:$("min-w-0 truncate",v),children:x})]}):e.jsxs(I,{type:"button",variant:"outline",onClick:()=>j(q=>!q),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:x,children:[e.jsx("span",{className:$("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:x}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:V?V.name:"Manual"})]});return e.jsxs("div",{className:$("relative inline-block",f==="composer"?"min-w-0 shrink-0":"w-full"),ref:oe,children:[f==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Be,{className:"text-sm font-medium",children:"Branch"}),me]}):me,l&&e.jsxs("div",{className:$("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",f==="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(ks,{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:T!=null&&T.repoRoot?`${T.currentBranch??x} · ${T.repoRoot}`:(T==null?void 0:T.currentBranch)??x,children:(T==null?void 0:T.currentBranch)??x}),y?e.jsx(xe,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),V?y&&!T?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(xe,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):T&&!T.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:F,onChange:q=>A(q.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(I,{type:"button",size:"sm",onClick:()=>void Y(),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-md p-0",children:D?e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(hi,{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:()=>ee(!0),className:"flex items-center gap-1 rounded px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx(Ct,{className:"h-2.5 w-2.5"}),"Manual"]})]}),re?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(nt,{value:M,onChange:q=>B(q.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{ee(!1),B("")},className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel manual input","aria-label":"Cancel manual input",children:e.jsx(ot,{className:"h-3.5 w-3.5"})})]}):T!=null&&T.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-md border border-border/40 bg-background/40",children:[T.branches.map(q=>{const X=ae===q.ref,se=q.branch==="main"||q.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>W(q.ref),className:$("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",X&&"bg-background/70"),title:q.ref,children:[e.jsx("span",{className:$("shrink-0 text-[10px]",se?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:se?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:q.ref}),X?e.jsx(Pt,{className:"h-3 w-3 shrink-0 text-primary"}):null]},q.ref)}),T.hasMore&&e.jsxs("button",{type:"button",onClick:J,disabled:g,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:[g?e.jsx(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(Ss,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"rounded-md 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."}),G&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:G})]})]})}const Gi=20,Qi=3,_s="meshy-working-dir-recents-by-node";function Yi(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function Xi(t){const s=t.trim();return s||"."}function Ts(t){const s=[],a=new Set;for(const o of t){const r=o.trim();if(!(!r||a.has(r))&&(a.add(r),s.push(r),s.length===Qi))break}return s}function Ji(t,s){const a=s.trim();return Ts(a?[a,...t]:t)}function pa(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const s={};for(const[a,o]of Object.entries(t)){if(!a||!Array.isArray(o))continue;const r=o.filter(f=>typeof f=="string"),i=Ts(r);i.length>0&&(s[a]=i)}return s}function Zi(t,s,a){if(!s)return t;const o=t[s]??[],r=Ji(o,a);if(r.length===0){if(!(s in t))return t;const{[s]:i,...f}=t;return f}return{...t,[s]:r}}function el(t,s){var a;return s?((a=t[s])==null?void 0:a[0])??"":""}function ga(t){if(!t||typeof window>"u")return"";try{const s=window.localStorage.getItem(_s);return s?el(pa(JSON.parse(s)),t):""}catch{return""}}function tl(t,s,a){return t!=="auto"?s.find(o=>o.id===t)??null:a.length===1?a[0]??null:null}function sl(t,s){const a=s.trim();return a?Yi(a)||!t?a:`${t.replace(/[/\\]+$/,"")}/${a}`:""}function nl(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 Gt({value:t,onChange:s,assignTo:a,nodes:o,assignableNodes:r,layout:i="default",chipClassName:f,chipActiveClassName:p,chipInactiveClassName:w,labelClassName:N,triggerClassName:v,popoverPlacement:c="bottom",popoverAlign:l="start"}){const[j,C]=n.useState(!1),[b,_]=n.useState(null),[m,y]=n.useState(!1),[u,g]=n.useState(!1),[S,D]=n.useState(null),[L,G]=n.useState(""),[U,F]=n.useState(!1),[A,ae]=n.useState({}),W=n.useRef(null),M=n.useMemo(()=>tl(a,o,r),[a,o,r]),B=M==null?void 0:M.id,re=n.useMemo(()=>B?A[B]??[]:[],[A,B]),ee=n.useMemo(()=>t.trim()?sl(M==null?void 0:M.workDir,t):"Use node default",[t,M==null?void 0:M.workDir]);n.useEffect(()=>{if(!(typeof window>"u"))try{const x=window.localStorage.getItem(_s);if(!x)return;const O=JSON.parse(x);ae(pa(O))}catch{}},[]);const oe=n.useCallback(x=>{B&&ae(O=>{const Q=Zi(O,B,x);if(Q===O)return O;if(typeof window<"u")try{window.localStorage.setItem(_s,JSON.stringify(Q))}catch{}return Q})},[B]),ie=n.useCallback((x,O=!0)=>{const Q=x.trim();s(Q),O&&Q&&oe(Q),C(!1)},[s,oe]),V=n.useCallback(async(x,O=0,Q=!1)=>{if(B){D(null),Q?g(!0):y(!0);try{const me=await hr(B,{path:x,limit:Gi,offset:O,directoriesOnly:!0,allowAbsolute:!0});_(q=>Q&&q?{...me,entries:[...q.entries,...me.entries]}:me)}catch(me){D(me instanceof Error?me.message:"Failed to browse directories"),Q||_(null)}finally{y(!1),g(!1)}}},[B]),z=n.useRef(t);z.current=t;const te=n.useRef(V);te.current=V,n.useEffect(()=>{if(!j)return;const x=z.current;G(x),F(!1),_(null),D(null),B&&te.current(Xi(x))},[j,B]),n.useEffect(()=>{if(!j)return;const x=Q=>{W.current&&(W.current.contains(Q.target)||C(!1))},O=Q=>{Q.key==="Escape"&&C(!1)};return document.addEventListener("mousedown",x),document.addEventListener("keydown",O),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",O)}},[j]);const we=n.useCallback(x=>{V(x)},[V]),h=n.useCallback(()=>{b&&V(b.currentPath,b.entries.length,!0)},[b,V]),Y=i==="composer"?e.jsxs(I,{type:"button",variant:"ghost",onClick:()=>C(x=>!x),title:ee,"aria-label":`Working directory: ${ee}`,className:$(f,v,"min-w-0 max-w-full",t.trim()?p:w),children:[e.jsx(fr,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:$("min-w-0 truncate",N),children:ee})]}):e.jsxs(I,{type:"button",variant:"outline",onClick:()=>C(x=>!x),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:ee,children:[e.jsx("span",{className:$("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:ee}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:M?M.name:"Manual"})]}),T=nl(b,M),J=!!(b!=null&&b.parentPath);return e.jsxs("div",{className:$("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":c,"data-workdir-popover-align":l,ref:W,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Be,{className:"text-sm font-medium",children:"Working directory"}),Y]}):Y,j&&e.jsxs("div",{className:$("absolute z-50 flex max-h-[min(28rem,calc(100vh-5rem))] w-[240px] flex-col overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",c==="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(Ss,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:re.map(x=>e.jsx("button",{type:"button",onClick:()=>ie(x),className:"truncate rounded px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:x,children:x},x))})]}),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)&&we(b.parentPath),disabled:!J||m,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md 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(Uo,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:T,children:T}),b&&e.jsx("button",{type:"button",onClick:()=>ie(b.isAbsolute?b.currentPath:b.currentPath==="."?"":b.currentPath),className:"shrink-0 rounded 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:[M?m?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(xe,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):b&&b.entries.length>0?e.jsxs(e.Fragment,{children:[b.entries.map(x=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>ie(x.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 ${x.path}`,children:[e.jsx(Vn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:x.name})]}),e.jsx("button",{type:"button",onClick:()=>we(x.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 ${x.name}`,children:e.jsx(Bt,{className:"h-3.5 w-3.5"})})]},x.path)),b.hasMore&&e.jsxs("button",{type:"button",onClick:h,disabled:u,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:[u?e.jsx(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(Ss,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:S??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),S&&b&&b.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:S})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:U?e.jsxs(e.Fragment,{children:[e.jsx(nt,{value:L,onChange:x=>G(x.target.value),onKeyDown:x=>{x.key==="Enter"&&L.trim()?(x.preventDefault(),ie(L)):x.key==="Escape"&&(x.preventDefault(),F(!1),G(t))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>ie(L),disabled:!L.trim(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-foreground hover:bg-background/60 disabled:opacity-40",title:"Apply","aria-label":"Apply manual path",children:e.jsx(Pt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{F(!1),G(t)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(ot,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{G(t),F(!0)},className:"flex h-7 flex-1 items-center justify-between rounded-md 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(Ct,{className:"h-3 w-3"})]})})]})]})}function ba(t,s={}){const a=t.filter(o=>o.status==="online");return s.currentNodeRole!=="follower"||!s.leaderNodeId?a:a.filter(o=>o.id!==s.leaderNodeId)}function Ks({isCurrent:t}){return t?e.jsx(si,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Jo,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function Es(t,s){return t.map(a=>{const o=!!s&&a.id===s;return e.jsx(ke,{value:a.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Ks,{isCurrent:o}),e.jsx("span",{className:"truncate",children:a.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:o?"current":"remote"})]})},a.id)})}function al(t){var o;const s=t.sessionId.trim(),a=t.cwd.trim();return!s||!a||!t.assignTo?null:{title:t.title.trim()||((o=t.defaultTitle)==null?void 0:o.trim())||void 0,agent:t.agent,sessionId:s,cwd:a,assignTo:t.assignTo,priority:t.priority,mode:t.mode??Rt}}function rl(){return br.map(t=>e.jsx(ke,{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 ol(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 kn(t){if(!t.updatedAt)return 0;const s=Date.parse(t.updatedAt);return Number.isNaN(s)?0:s}function il(t,s){return kn(s)-kn(t)||t.sessionId.localeCompare(s.sessionId)}function ll(t){const s=t.trim().replace(/[\\/]+$/,"");return s?s.split(/[\\/]+/).filter(Boolean).at(-1)??s:"Unknown project"}function dl(t){const s=new Map;for(const a of[...t].sort(il)){const o=s.get(a.cwd);if(o){o.push(a);continue}s.set(a.cwd,[a])}return Array.from(s.entries()).map(([a,o])=>({folderName:ll(a),cwd:a,sessions:o}))}function cl(t,s){const a=new Set(t);return a.has(s)?a.delete(s):a.add(s),a}function ul({nodes:t,currentNodeRole:s,currentNodeId:a,leaderNodeId:o,onCreated:r,onCancel:i,className:f,footerClassName:p,submitLabel:w="Load session",cancelLabel:N="Cancel",autoFocus:v=!1}){const c=n.useMemo(()=>ba(t,{currentNodeRole:s,leaderNodeId:o}),[t,s,o]),l=n.useMemo(()=>{var P;return a&&c.some(H=>H.id===a)?a:((P=c[0])==null?void 0:P.id)??""},[c,a]),[j,C]=n.useState(""),[b,_]=n.useState("codex"),[m,y]=n.useState(""),[u,g]=n.useState(""),[S,D]=n.useState(""),[L,G]=n.useState(l),[U,F]=n.useState("normal"),[A,ae]=n.useState(Rt),[W,M]=n.useState(!1),[B,re]=n.useState([]),[ee,oe]=n.useState(!1),[ie,V]=n.useState(null),z=n.useMemo(()=>B.find(P=>P.sessionId===m)??null,[B,m]);n.useEffect(()=>{L&&c.some(P=>P.id===L)||G(l)},[L,c,l]),n.useEffect(()=>{y(""),g(""),D("")},[b,L]),n.useEffect(()=>{let P=!1;return L?(oe(!0),V(null),pr(L,{agent:b,limit:50}).then(H=>{P||re(H.sessions)}).catch(H=>{P||(re([]),V(H instanceof Error?H.message:"Failed to load native sessions"))}).finally(()=>{P||oe(!1)}),()=>{P=!0}):(re([]),V(null),oe(!1),()=>{P=!0})},[b,L]),n.useEffect(()=>{z&&(g(z.sessionId),D(z.cwd))},[z]);const te=n.useCallback(async P=>{P.preventDefault();const H=al({title:j,defaultTitle:z==null?void 0:z.summary,agent:b,sessionId:u,cwd:S,assignTo:L,priority:U,mode:A});if(H){M(!0);try{const Ne=await gr(H);r(Ne)}catch(Ne){ne.error(Ne instanceof Error?Ne.message:"Failed to load native session")}finally{M(!1)}}},[j,z,b,u,S,L,U,A,r]),we=!!(u.trim()&&S.trim()&&L),[h,Y]=n.useState(!1),[T,J]=n.useState(""),[x,O]=n.useState(()=>new Set),Q=c.find(P=>P.id===L)??null,me=!!(a&&(Q==null?void 0:Q.id)===a),q=n.useMemo(()=>{const P=T.trim().toLowerCase();return P?B.filter(H=>H.summary.toLowerCase().includes(P)||H.sessionId.toLowerCase().includes(P)||H.cwd.toLowerCase().includes(P)):B},[B,T]),X=n.useMemo(()=>dl(q),[q]),se=n.useCallback(P=>{O(H=>cl(H,P))},[]),Se="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:te,className:$("space-y-4",f),children:[e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/54 shadow-[0_24px_86px_-48px_rgba(15,23,42,0.55)] backdrop-blur-xl dark:shadow-[0_24px_86px_-48px_rgba(0,0,0,0.9)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/50 px-4 py-3",children:[e.jsxs(Te,{value:L,onValueChange:G,children:[e.jsx(Ee,{className:$(Se),"aria-label":"Node",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{isCurrent:me}),e.jsx("span",{className:"max-w-[10rem] truncate",children:Q.name})]}):e.jsx(Ue,{placeholder:"Node"})}),e.jsx(De,{children:Es(c,a)})]}),e.jsxs(Te,{value:b,onValueChange:P=>_(P),children:[e.jsxs(Ee,{className:$(Se),"aria-label":"Agent",children:[e.jsx(Fs,{agent:b}),e.jsx("span",{children:b})]}),e.jsx(De,{children:To()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(cs,{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:T,onChange:P=>J(P.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(Be,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:ee?"Loading...":`${q.length} session${q.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-lg",children:[ee&&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:[!L&&e.jsx("div",{className:"rounded-lg border border-dashed border-border/60 bg-background/35 px-4 py-6 text-center text-xs text-muted-foreground",children:"Pick a node to load its recent sessions."}),L&&!ee&&q.length===0&&e.jsx("div",{className:"rounded-lg border border-dashed border-border/60 bg-background/35 px-4 py-6 text-center text-xs 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."}),X.map(P=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>se(P.cwd),"aria-expanded":!x.has(P.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(it,{className:$("h-3.5 w-3.5 shrink-0 transition-transform",x.has(P.cwd)&&"-rotate-90")}),e.jsx(zs,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:P.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[P.sessions.length," session",P.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:P.cwd})]}),!x.has(P.cwd)&&P.sessions.map(H=>{const Ne=H.sessionId===m;return e.jsxs("button",{type:"button",onClick:()=>y(H.sessionId),className:$("flex w-full flex-col gap-1 rounded-lg border px-3 py-2.5 text-left transition-all duration-200 hover:-translate-y-px",Ne?"border-primary/45 bg-primary/9 shadow-[0_18px_60px_-44px_hsl(var(--primary)/0.95)]":"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:$("h-2 w-2 shrink-0 rounded-full",Ne?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:H.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:ol(H.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:H.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:H.cwd})]})]},H.sessionId)})]},P.cwd))]})]}),ie&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:ie})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:()=>Y(P=>!P),className:"flex w-full items-center gap-2 text-[11px] font-medium uppercase tracking-[0.2em] text-muted-foreground transition-colors hover:text-foreground","aria-expanded":h,children:[e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0}),e.jsx("span",{className:"shrink-0",children:h?"Less options":"More options"}),e.jsx(it,{className:$("h-3.5 w-3.5 shrink-0 transition-transform",h&&"rotate-180")}),e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0})]}),h&&e.jsxs("div",{className:"space-y-4 rounded-xl border border-border/60 bg-background/35 p-4",children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Be,{htmlFor:"native-session-id",className:"text-xs font-medium text-muted-foreground",children:"Session ID"}),e.jsx(nt,{id:"native-session-id",type:"text",value:u,onChange:P=>{y(""),g(P.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:v,className:"h-10 rounded-sm border-border/70 bg-background/70 font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Be,{htmlFor:"native-session-title",className:"text-xs font-medium text-muted-foreground",children:"Task title"}),e.jsx(nt,{id:"native-session-title",type:"text",value:j,onChange:P=>C(P.target.value),placeholder:"Optional",className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm"})]})]}),e.jsx(Gt,{value:S,onChange:P=>{y(""),D(P)},assignTo:L,nodes:t,assignableNodes:c}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Be,{className:"text-xs font-medium text-muted-foreground",children:"Mode"}),e.jsxs(Te,{value:A,onValueChange:P=>ae(P),children:[e.jsx(Ee,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Ue,{placeholder:"Select mode"})}),e.jsx(De,{children:rl()})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Be,{className:"text-xs font-medium text-muted-foreground",children:"Priority"}),e.jsxs(Te,{value:U,onValueChange:F,children:[e.jsx(Ee,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Ue,{placeholder:"Select priority"})}),e.jsxs(De,{children:[e.jsx(ke,{value:"low",children:"Low"}),e.jsx(ke,{value:"normal",children:"Normal"}),e.jsx(ke,{value:"high",children:"High"}),e.jsx(ke,{value:"critical",children:"Critical"})]})]})]})]})]})]}),e.jsxs("div",{className:$("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",p),children:[i&&e.jsx(I,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:N}),e.jsx(I,{type:"submit",disabled:!we||W,className:"rounded-sm px-5",children:W?e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-4 w-4 animate-spin"})," Loading..."]}):w})]})]})}function va(t,s,a=!1){const o=t.trim();if(o)return o;const r=s.trim().split(`
|
|
134
|
-
`).map(i=>i.trim()).find(Boolean);return r?r.length>72?`${r.slice(0,69).trimEnd()}...`:r:a?"Image task":""}function ml(t){var f;const s=t.title.trim(),a=va(t.title,t.description,t.images.length>0),o=t.description.trim()||a,r=t.mode??Rt,i=sa(t.description,t.images);return!a||!o||!t.agent?null:{title:a,description:o,agent:t.agent,project:t.project.trim()||null,branch:((f=t.branch)==null?void 0:f.trim())||null,payload:{initialMessage:i,mode:r,titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function xl({nodes:t,currentNodeRole:s,currentNodeId:a,leaderNodeId:o,initialAssignTo:r,initialProject:i,onCreated:f,onCancel:p,className:w,footerClassName:N,submitLabel:v="Create chat",cancelLabel:c="Cancel",autoFocus:l=!1,layout:j="default"}){const[C,b]=n.useState(""),[_,m]=n.useState(""),[y,u]=n.useState(rn),[g,S]=n.useState(Rt),[D,L]=n.useState((i==null?void 0:i.trim())??""),G=n.useRef(i!==void 0),[U,F]=n.useState(""),[A,ae]=n.useState("normal"),W=n.useMemo(()=>ba(t,{currentNodeRole:s,leaderNodeId:o}),[t,s,o]),M=n.useMemo(()=>{var Z;return r&&W.some(he=>he.id===r)?r:a&&W.some(he=>he.id===a)?a:((Z=W[0])==null?void 0:Z.id)??""},[W,a,r]),[B,re]=n.useState(M),[ee,oe]=n.useState(!1),[ie,V]=n.useState(!1),{images:z,error:te,fileInputRef:we,pickImages:h,handleFileChange:Y,handlePaste:T,removeImage:J}=xa(),x=n.useMemo(()=>W.find(Z=>Z.id===B)??null,[B,W]),O=!!(a&&(x==null?void 0:x.id)===a),Q=aa(y),me=Eo(g);n.useEffect(()=>{B&&W.some(Z=>Z.id===B)||re(M)},[B,W,M]),n.useEffect(()=>{if(G.current){G.current=!1;return}L(ga(B)),F("")},[B]),n.useEffect(()=>{F("")},[D]);const q=n.useCallback(async Z=>{Z.preventDefault();const he=ml({title:C,description:_,agent:y,project:D,branch:U,priority:A,assignTo:B,mode:g,images:z});if(he){oe(!0);try{const Le=await jr(he);f(Le)}catch(Le){ne.error(Le instanceof Error?Le.message:"Failed to create task")}finally{oe(!1)}}},[C,_,y,D,U,A,B,g,z,f]),X=va(C,_,z.length>0),se=!!(X&&y&&B&&(_.trim()||z.length>0)),Se=n.useCallback(Z=>{var he;Z.nativeEvent.isComposing||Z.key==="Enter"&&(Z.ctrlKey||Z.metaKey)&&se&&!ee&&(Z.preventDefault(),(he=Z.currentTarget.form)==null||he.requestSubmit())},[se,ee]),P=z.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:z.map((Z,he)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:na(Z),alt:Z.filename??`attachment ${he+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>J(he),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 ${Z.filename??`image ${he+1}`}`,children:e.jsx(ot,{className:"h-3.5 w-3.5"})})]},`${Z.filename??"image"}-${he}`))}),H=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Be,{className:"text-sm font-medium",children:"Assign to"}),e.jsxs(Te,{value:B,onValueChange:re,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ue,{placeholder:"Select node"})}),e.jsx(De,{children:Es(W,a)})]})]}),Ne=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Be,{className:"text-sm font-medium",children:"Agent"}),e.jsxs(Te,{value:y,onValueChange:u,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ue,{placeholder:"Select agent"})}),e.jsx(De,{children:fn()})]})]}),Re=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Be,{className:"text-sm font-medium",children:"Mode"}),e.jsxs(Te,{value:g,onValueChange:Z=>S(Z),children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ue,{placeholder:"Select mode"})}),e.jsx(De,{children:pn()})]})]}),Ve=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Be,{className:"text-sm font-medium",children:"Priority"}),e.jsxs(Te,{value:A,onValueChange:ae,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ue,{placeholder:"Select priority"})}),e.jsxs(De,{children:[e.jsx(ke,{value:"low",children:"Low"}),e.jsx(ke,{value:"normal",children:"Normal"}),e.jsx(ke,{value:"high",children:"High"}),e.jsx(ke,{value:"critical",children:"Critical"})]})]})]}),Je=e.jsx(Gt,{value:D,onChange:L,assignTo:B,nodes:t,assignableNodes:W}),ye=e.jsx(yn,{value:U,onChange:F,project:D,assignTo:B,nodes:t,assignableNodes:W});return j==="composer"?e.jsxs("form",{onSubmit:q,className:$("space-y-4",w),children:[e.jsx("input",{ref:we,type:"file",accept:"image/*",multiple:!0,onChange:Y,className:"hidden"}),(()=>{const Z="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",he="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",Le="border-border/70 bg-background/55 text-foreground",$e=y===rn,qe=g===Rt;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/54 shadow-[0_24px_86px_-48px_rgba(15,23,42,0.55)] backdrop-blur-xl dark:shadow-[0_24px_86px_-48px_rgba(0,0,0,0.9)]",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(Te,{value:B,onValueChange:re,children:[e.jsx(Ee,{className:$(Z,Le,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${(x==null?void 0:x.name)??"unassigned"}`,"aria-label":`Assigned node: ${(x==null?void 0:x.name)??"unassigned"}`,children:x?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{isCurrent:O}),e.jsx("span",{className:"min-w-0 truncate",children:x.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:O?"current":"remote"})]}):e.jsx(Ue,{placeholder:"Select node"})}),e.jsx(De,{children:Es(W,a)})]}),ie?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(nt,{id:"task-title-composer",type:"text",value:C,onChange:le=>b(le.target.value),onKeyDown:le=>{(le.key==="Enter"||le.key==="Escape")&&(le.preventDefault(),V(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(I,{type:"button",variant:"ghost",size:"icon",onClick:()=>V(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Pt,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>V(!0),className:"chat-composer__title-button flex min-w-0 items-center gap-1.5 rounded-sm px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-background/55 hover:text-foreground",title:X||"Title","aria-label":X?`Edit title: ${X}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:X||"Title"}),e.jsx(Ct,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:_,onChange:le=>m(le.target.value),onKeyDown:Se,onPaste:T,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-xl 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(I,{type:"button",variant:"ghost",size:"icon",onClick:h,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Cs,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(Te,{value:y,onValueChange:u,children:[e.jsxs(Ee,{className:$(Z,"chat-composer__icon-trigger",$e?he:Le),title:`Agent: ${Q}`,"aria-label":`Agent: ${Q}`,children:[e.jsx(Fs,{agent:y}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:Q})]}),e.jsx(De,{children:fn()})]}),e.jsxs(Te,{value:g,onValueChange:le=>S(le),children:[e.jsxs(Ee,{className:$(Z,"chat-composer__icon-trigger",qe?he:Le),title:`Mode: ${me}`,"aria-label":`Mode: ${me}`,children:[e.jsx(ji,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:me})]}),e.jsx(De,{children:pn()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(Te,{value:A,onValueChange:ae,children:[e.jsx(Ee,{"aria-label":`Priority: ${A}`,title:`Priority: ${A}`,className:$("h-9 w-9 justify-center gap-0 rounded-sm p-0 text-xs shadow-none [&>svg:last-child]:hidden",A==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",A==="critical"&&"text-destructive",A==="high"&&"text-amber-600 dark:text-amber-400",A==="low"&&"text-muted-foreground"),children:e.jsx(Ho,{className:$("h-4 w-4",A==="critical"&&"fill-destructive/20")})}),e.jsxs(De,{children:[e.jsx(ke,{value:"low",children:"Low"}),e.jsx(ke,{value:"normal",children:"Normal"}),e.jsx(ke,{value:"high",children:"High"}),e.jsx(ke,{value:"critical",children:"Critical"})]})]}),p&&e.jsxs(I,{type:"button",variant:"ghost",size:"sm",onClick:p,"aria-label":c,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(ot,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:c})]}),e.jsxs(I,{type:"submit",size:"icon",disabled:!se||ee,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[ee?e.jsx(xe,{className:"h-4 w-4 animate-spin"}):e.jsx(da,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:ee?"Creating chat":v})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const le="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Gt,{value:D,onChange:L,assignTo:B,nodes:t,assignableNodes:W,layout:"composer",chipClassName:Z,chipActiveClassName:le,chipInactiveClassName:le,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(yn,{value:U,onChange:F,project:D,assignTo:B,nodes:t,assignableNodes:W,layout:"composer",chipClassName:Z,chipActiveClassName:le,chipInactiveClassName:le,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(P||te)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 bg-background/45 p-4",children:[P,te&&e.jsx("div",{className:"text-xs text-destructive",children:te}),!te&&e.jsx("div",{className:"text-xs 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:q,className:$("space-y-5",w),children:[e.jsx("input",{ref:we,type:"file",accept:"image/*",multiple:!0,onChange:Y,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Be,{htmlFor:"task-description",className:"text-sm font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:_,onChange:Z=>m(Z.target.value),onKeyDown:Se,onPaste:T,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:l,className:"flex min-h-[144px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-xl border border-border/70 bg-background/70 px-4 py-3 text-sm leading-6 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-3",children:[e.jsxs(I,{type:"button",variant:"outline",onClick:h,className:"rounded-sm",children:[e.jsx(Cs,{className:"h-4 w-4"}),"Add images"]}),e.jsx("p",{className:"text-xs 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."})]}),P,te&&e.jsx("p",{className:"text-xs text-destructive",children:te})]}),e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1fr)_220px_220px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Be,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(nt,{id:"task-title",type:"text",value:C,onChange:Z=>b(Z.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-11 rounded-lg border-border/70 bg-background/70"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:X?`Will appear as: ${X}`:"A title will be generated from the first line of the prompt."})]}),Ne,Re]}),Je,ye,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[Ve,H]}),e.jsxs("div",{className:$("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",N),children:[p&&e.jsx(I,{type:"button",variant:"ghost",onClick:p,className:"rounded-sm",children:c}),e.jsx(I,{type:"submit",disabled:!se||ee,className:"rounded-sm px-5",children:ee?"Creating...":v})]})]})}function hl({nodes:t,currentNodeRole:s,currentNodeId:a,leaderNodeId:o,initialAssignTo:r,initialProject:i,onCreated:f,onCancel:p,defaultMode:w="chat",mode:N,onModeChange:v,layout:c="default",className:l,footerClassName:j,autoFocus:C=!1}){const[b,_]=n.useState(w),m=N!==void 0,y=m?N:b,u=g=>{m||_(g),v==null||v(g)};return e.jsxs("div",{className:$("space-y-4",l),children:[!m&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 bg-background/45 p-1",children:[e.jsxs(I,{type:"button",variant:y==="chat"?"default":"ghost",onClick:()=>u("chat"),className:"flex-1 rounded-sm",children:[e.jsx(vr,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(I,{type:"button",variant:y==="native"?"default":"ghost",onClick:()=>u("native"),className:"flex-1 rounded-sm",children:[e.jsx(Us,{className:"h-4 w-4"}),"Load session"]})]}),y==="chat"?e.jsx(xl,{nodes:t,currentNodeRole:s,currentNodeId:a,leaderNodeId:o,initialAssignTo:r,initialProject:i,onCreated:f,onCancel:p,footerClassName:j,submitLabel:c==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:C,layout:c},`${r??""}:${i??""}`):e.jsx(ul,{nodes:t,currentNodeRole:s,currentNodeId:a,leaderNodeId:o,onCreated:f,onCancel:p,footerClassName:j,autoFocus:C})]})}function fl({onClick:t,running:s}){return e.jsxs(I,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:$("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(Ct,{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 Sn({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 pl({hasVisibleTranscriptEvents:t,hasTranscriptProgress:s,inputCollapsed:a}){return{collapsedButtonRunning:s&&t&&a,showDockedProgress:s&&t&&!a,showInlineProgress:s&&!t}}const Nt="72f988bf-86f1-41af-91ab-2d7cd011db47",ja=`${Nt} (MSIT)`;function gl({open:t,onOpenChange:s,onShare:a,onStopShare:o,sharing:r,stopping:i=!1,shareResult:f}){return e.jsx(Ps,{open:t,onOpenChange:s,children:e.jsxs(Bs,{className:"max-w-md rounded-xl p-5",children:[e.jsx(Rs,{className:"sr-only",children:"Share conversation"}),e.jsx(bl,{onOpenChange:s,onShare:a,onStopShare:o,sharing:r,stopping:i,shareResult:f})]})})}function bl({onOpenChange:t,onShare:s,onStopShare:a,sharing:o,stopping:r=!1,shareResult:i}){const[f,p]=n.useState((i==null?void 0:i.tenant)??Nt),[w,N]=n.useState((i==null?void 0:i.scope)??"chat"),v=i!=null&&i.url?qn(i.url):null,c=o||r;return n.useEffect(()=>{p((i==null?void 0:i.tenant)??Nt),N((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-base 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(vl,{value:f,onChange:p,disabled:c}),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(Cn,{active:w==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>N("chat")}),e.jsx(Cn,{active:w==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>N("filesPreview")})]})]}),v&&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:v,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(I,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void wt(v,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Kn,{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(I,{variant:"outline",onClick:()=>t(!1),disabled:c,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&a&&e.jsxs(I,{variant:"outline",onClick:()=>void a(),disabled:c,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[r&&e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(I,{onClick:()=>void s({tenant:f,scope:w}),disabled:c,className:"h-8 text-xs",children:[o&&e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function vl({value:t,onChange:s,disabled:a}){const[o,r]=n.useState(!1),[i,f]=n.useState(!1),[p,w]=n.useState(t),N=n.useRef(null);n.useEffect(()=>{w(t)},[t]),n.useEffect(()=>{if(!o)return;const c=j=>{var b;const C=j.target;C instanceof Node&&((b=N.current)!=null&&b.contains(C)||(r(!1),f(!1)))},l=j=>{j.key==="Escape"&&(r(!1),f(!1))};return document.addEventListener("mousedown",c),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",l)}},[o]);const v=c=>{const l=c.trim();l&&(s(l),w(l),f(!1),r(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:N,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!a&&r(c=>!c),disabled:a,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:jl(t)}),e.jsx(it,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),o&&e.jsxs("div",{className:"absolute left-0 right-0 z-50 mt-2 overflow-hidden rounded-lg border border-border/60 bg-background/95 text-xs shadow-lg backdrop-blur",children:[e.jsxs("button",{type:"button",onClick:()=>v(Nt),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:ja}),t===Nt&&e.jsx(Pt,{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:p,onChange:c=>w(c.target.value),onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),v(p))},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:()=>v(p),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(Pt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{w(t),f(!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(ot,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>f(!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(Ct,{className:"h-3 w-3"})]})})]})]})]})}function jl(t){return t===Nt?ja:t}function Cn({active:t,title:s,description:a,onClick:o}){return e.jsxs("button",{type:"button",onClick:o,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:a})]})}function wl(t){const s=t.map(a=>a.type==="text"?a.text:a.type==="image"?a.filename?`Image: ${a.filename}`:"Image attachment":a.isError?`Tool result error: ${a.content}`:`Tool result: ${a.content}`).join(" ").replace(/\s+/g," ").trim();return s?s.length>160?`${s.slice(0,157)}...`:s:"Queued follow-up"}function Nl({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(ri,{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((a,o)=>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:o+1}),e.jsx("span",{className:"min-w-0 flex-1 break-words [overflow-wrap:anywhere]",children:wl(a.content)}),s&&e.jsx(I,{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(a.id),children:e.jsx(ot,{className:"h-3 w-3"})})]},a.id))})]})})}const yl=30,kl=1600;function Sl({savedScrollTop:t,scrollHeight:s,clientHeight:a}){const o=Math.max(0,s-a);return Math.min(Math.max(0,t??o),o)}function os(t){return t.scrollHeight-t.scrollTop-t.clientHeight<yl}function _n({explicitBottomStickUntil:t,now:s,wasAtBottom:a}){return a||t>s}function Cl({atTop:t,inputCollapseDisabled:s,scrollingUp:a}){return!s&&(a||t)}function _l({activeTab:t,activeTaskId:s,contentVersion:a,inputCollapseDisabled:o=!1,setActiveTab:r,setInputCollapsed:i}){const f=n.useRef(null),p=n.useRef(s),w=n.useRef(!1),N=n.useRef(0),v=n.useRef(new Map),c=n.useRef(0),l=n.useRef(!0),j=n.useCallback((u=p.current)=>{const g=f.current;!g||!u||(v.current.set(u,g.scrollTop),N.current=g.scrollTop,l.current=os(g))},[]),C=n.useCallback((u=p.current)=>{const g=f.current;!g||!u||(g.scrollTop=Sl({savedScrollTop:v.current.get(u),scrollHeight:g.scrollHeight,clientHeight:g.clientHeight}),N.current=g.scrollTop,l.current=os(g))},[]),b=n.useCallback((u,g=p.current)=>{u.scrollTop=u.scrollHeight,N.current=u.scrollTop,l.current=!0,g&&v.current.set(g,u.scrollTop)},[]),_=n.useCallback((u=p.current)=>{const g=f.current;c.current=Date.now()+kl,g&&(b(g,u),requestAnimationFrame(()=>{b(g,u),requestAnimationFrame(()=>b(g,u))}))},[b]),m=n.useCallback(u=>{const g=u.currentTarget,S=N.current,D=g.scrollTop<S&&S-g.scrollTop>10,L=g.scrollTop<=0;if(j(),!w.current){if(os(g)){i(!1),w.current=!0,setTimeout(()=>{w.current=!1},300);return}(D||L)&&(c.current=0,Cl({atTop:L,inputCollapseDisabled:o,scrollingUp:D})&&i(!0))}},[o,j,i]),y=n.useCallback(u=>{t==="transcript"&&j(),r(u),u==="transcript"&&requestAnimationFrame(()=>C())},[t,C,j,r]);return n.useLayoutEffect(()=>{o&&i(!1)},[o,i]),n.useLayoutEffect(()=>{const u=p.current;u&&u!==s&&j(u),p.current=s,t==="transcript"&&requestAnimationFrame(()=>C(s))},[s,t,C,j]),n.useLayoutEffect(()=>{const u=f.current;if(!u||t!=="transcript"||!s)return;_n({explicitBottomStickUntil:c.current,now:Date.now(),wasAtBottom:l.current})&&b(u,s),j(s)},[s,t,a,j,b]),n.useLayoutEffect(()=>{const u=f.current,g=u==null?void 0:u.firstElementChild;if(!u||!g||t!=="transcript"||typeof ResizeObserver>"u")return;const S=new ResizeObserver(()=>{_n({explicitBottomStickUntil:c.current,now:Date.now(),wasAtBottom:l.current})?b(u):j()});return S.observe(u),S.observe(g),()=>S.disconnect()},[t,s,j,b]),{handleTranscriptScroll:m,handleTranscriptTabChange:y,scrollTranscriptToBottom:_,transcriptScrollRef:f}}function wa(t=700){const[s,a]=n.useState(!1),o=n.useRef(null),r=n.useCallback(()=>{a(!0),o.current!==null&&clearTimeout(o.current),o.current=setTimeout(()=>{a(!1),o.current=null},t)},[t]);return n.useEffect(()=>()=>{o.current!==null&&clearTimeout(o.current)},[]),{markScrollbarActive:r,scrollbarActive:s}}const Hs="h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",yt="h-3.5 w-3.5",Tl=n.lazy(async()=>({default:(await $s(()=>import("./FilesTab-Bz7sh_3g.js"),__vite__mapDeps([0,1,2,3,4]))).FilesTab})),El=n.lazy(async()=>({default:(await $s(()=>import("./PreviewTab-DoI4vsUp.js"),__vite__mapDeps([5,1,2,6]))).PreviewTab})),Dl=n.lazy(async()=>({default:(await $s(()=>import("./DiffTab-CAro0pTI.js"),__vite__mapDeps([7,1,2,4,3,6]))).DiffTab}));function Al({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:a,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:f,activeTab:p,setActiveTab:w,creatingTask:N,createMode:v,createDefaults:c,activeTask:l,assignedNode:j,taskLoading:C,transcriptLoading:b,taskError:_,displayEvents:m,initialPromptAlreadyInLogs:y,initialPrompt:u,supportsFollowUp:g,taskUnavailable:S,chatDisabled:D,chatDisabledReason:L,questionBypassEnabled:G,isRunning:U,isStarting:F,hasPendingFollowUp:A,canCancel:ae,canRetry:W,onRetry:M,onCancel:B,onReloadNativeTranscript:re,onShareTask:ee,onStopShareTask:oe,onStartCreateTask:ie,onCancelCreateTask:V,onCreateTask:z,onSendMessage:te,onCancelQueuedMessage:we,onQuestionBypassChange:h,onSubmitQuestionResponse:Y}){const[T,J]=n.useState(!1),[x,O]=n.useState(!1),[Q,me]=n.useState(!1),[q,X]=n.useState(!1),[se,Se]=n.useState(!1),[P,H]=n.useState({}),[Ne,Re]=n.useState(new Set),[Ve,Je]=n.useState(new Set),[ye,Z]=n.useState(null),he=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",Le=l?(j==null?void 0:j.name)??us(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",$e=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:Le}),"..."]}):"Connecting session to an available node...",qe=l?[{label:"Working dir",value:he,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:Le}]:[],le=!!(u&&!y),Pe=le||m.length>0,Ge=U&&Pe,at=(F||A||U)&&!Ge,Ze=Ge?"The agent is still working on this conversation.":at?$e:null,{collapsedButtonRunning:Tt,showDockedProgress:pt,showInlineProgress:gt}=pl({hasTranscriptProgress:!!Ze,hasVisibleTranscriptEvents:Pe,inputCollapsed:T}),rt=(l==null?void 0:l.conversationKind)==="nativeSession",Oe=b?"Loading transcript":rt?"No transcript imported":"Transcript is warming up",ut=b?"Loading transcript...":rt?"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.",Ce=(l==null?void 0:l.queuedMessages)??[],mt=n.useMemo(()=>Do(m),[m]),Et=n.useMemo(()=>Ao("transcript",mt.map(ve=>ve.event)),[mt]),E=l&&!Ne.has(l.id)?P[l.id]??l.activeShare??null:null,be=(l==null?void 0:l.id)??null,fe=`${be??"none"}:${m.length}:${Ce.length}:${le?1:0}:${b?1:0}:${gt?1:0}`,{handleTranscriptScroll:Fe,handleTranscriptTabChange:Ke,scrollTranscriptToBottom:lt,transcriptScrollRef:Ae}=_l({activeTab:p,activeTaskId:be,contentVersion:fe,inputCollapseDisabled:!!Ze,setActiveTab:w,setInputCollapsed:J}),{markScrollbarActive:Ie,scrollbarActive:dt}=wa(),_e=n.useCallback(ve=>{Ie(),Fe(ve)},[Fe,Ie]),Qe=n.useCallback(ve=>{Z(ce=>({path:ve,requestId:((ce==null?void 0:ce.requestId)??0)+1})),Ke("files")},[Ke]),bt=n.useCallback(ve=>{lt(),te(ve)},[te,lt]);return n.useEffect(()=>{Z(null)},[be]),N?e.jsx(Ml,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:a,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:f,defaultMode:v,createDefaults:c,onCancel:V,onCreated:z}):!l&&C?e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ds,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:a,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:f})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(xe,{className:"h-7 w-7 animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-2xl 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(xe,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(Hn,{value:p,onValueChange:Ke,className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Na,{desktopTasksOpen:s,mobileTasksPanelOpen:a,onToggleTasks:t}),e.jsx("h2",{className:"min-w-0 truncate text-sm font-semibold tracking-tight text-foreground sm:text-lg",title:l.title,children:l.title}),e.jsx(Wn,{status:l.status,isNative:rt}),l.priority!=="normal"&&e.jsx(Nr,{priority:l.priority}),e.jsx(I,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:$("ml-auto",Hs),children:o?e.jsx(Vs,{className:yt}):e.jsx(la,{className:yt})})]}),_&&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:_}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsxs(Gn,{className:"h-auto max-w-full overflow-x-auto rounded-sm bg-muted/70 p-0.5",children:[e.jsx(xt,{value:"transcript",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Transcript"}),e.jsx(xt,{value:"files",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Files"}),e.jsx(xt,{value:"preview",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Preview"}),e.jsx(xt,{value:"diff",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Diff"})]}),S&&e.jsx(Ye,{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.jsxs("span",{className:"hidden sm:inline",children:["updated ",yr(l.updatedAt)]}),e.jsx("span",{className:"font-mono",children:l.id.slice(0,8)}),W&&e.jsxs(I,{variant:"outline",size:"sm",onClick:M,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(vn,{className:"h-3.5 w-3.5"}),"Retry"]}),rt&&re&&e.jsx(I,{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(vn,{className:$("h-3.5 w-3.5",b&&"animate-spin")})}),e.jsx(I,{type:"button",variant:"ghost",size:"icon",disabled:S,title:S?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":S?"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:()=>me(!0),children:e.jsx(bi,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(ht,{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:Ae,"data-transcript-scroll":"true",className:$("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-5 pt-5 sm:px-5",dt&&"scrollbar-line-active"),onScroll:_e,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-5",children:[le&&u&&e.jsx(gn,{event:u,agent:l.agent,taskRootPath:l.effectiveProjectPath,onOpenFilePath:Qe,questionBypassEnabled:G,onQuestionBypassChange:h,onSubmitQuestionResponse:Y,questionResponseDisabled:!g||D}),mt.map(({event:ve,subItems:ce},pe)=>e.jsx(gn,{event:ve,agent:l.agent,subItems:ce,taskRootPath:l.effectiveProjectPath,onOpenFilePath:Qe,questionBypassEnabled:G,onQuestionBypassChange:h,onSubmitQuestionResponse:Y,questionResponseDisabled:!g||D},Et[pe])),!Pe&&!at&&e.jsxs("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-5 py-8 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:Oe}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:ut})]}),(!g&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!g&&l.result&&e.jsxs("div",{className:"rounded-xl 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&&!Ve.has(l.id)&&e.jsxs("div",{className:"rounded-xl 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:()=>Je(ve=>new Set(ve).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(ot,{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})]})]}),gt&&Ze&&e.jsx(Sn,{children:Ze})]})})}),pt&&Ze&&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(Sn,{children:Ze})})}),g?e.jsxs(e.Fragment,{children:[T&&e.jsx(fl,{running:Tt,onClick:()=>{J(!1),lt(),requestAnimationFrame(()=>{var ve;return(ve=document.querySelector('[data-chat-input-textarea="true"]'))==null?void 0:ve.focus()})}}),e.jsxs("div",{className:`shrink-0 ${T?"hidden":""}`,children:[e.jsx(Nl,{messages:Ce,onCancelMessage:we}),e.jsx(Oi,{onSend:bt,disabled:D,disabledReason:L,contextItems:qe,placeholder:D?L:U?"Queue a message for the next turn...":"Continue the conversation...",running:U||A,onStop:ae?()=>O(!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(ht,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(n.Suspense,{fallback:e.jsx(as,{label:"Loading files..."}),children:e.jsx(Tl,{taskId:l.id,requestedFilePath:(ye==null?void 0:ye.path)??null,requestedFileRequestId:(ye==null?void 0:ye.requestId)??0})})}),e.jsx(ht,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(n.Suspense,{fallback:e.jsx(as,{label:"Loading preview..."}),children:e.jsx(El,{taskId:l.id})})}),e.jsx(ht,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(n.Suspense,{fallback:e.jsx(as,{label:"Loading diff..."}),children:e.jsx(Dl,{taskId:l.id})})}),e.jsx(ms,{open:x,onOpenChange:O,children:e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsx(fs,{children:"Stop this task?"}),e.jsx(ps,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(gs,{children:[e.jsx(bs,{children:"Keep running"}),e.jsx(vs,{onClick:B,children:"Stop task"})]})]})}),e.jsx(gl,{open:Q,onOpenChange:me,sharing:q,stopping:se,shareResult:E,onShare:async ve=>{if(!l)return null;X(!0);try{const ce=await ee(ve);return ce!=null&&ce.url&&(H(pe=>({...pe,[l.id]:ce})),Re(pe=>{const et=new Set(pe);return et.delete(l.id),et})),ce}finally{X(!1)}},onStopShare:async()=>{if(!l)return!1;Se(!0);try{const ve=await oe();return ve!==!1&&(H(ce=>{const pe={...ce};return delete pe[l.id],pe}),Re(ce=>new Set(ce).add(l.id))),ve}finally{Se(!1)}}})]}):e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ds,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:a,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:f})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(wr,{className:"h-7 w-7"})}),e.jsx("h2",{className:"mt-5 text-xl font-semibold tracking-tight text-foreground sm:text-3xl",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-3 max-w-xl text-[11px] leading-6 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(I,{onClick:()=>ie(),className:"mt-6 rounded-lg px-5",children:[e.jsx(Wt,{className:"h-4 w-4"}),"Start or load chat"]}),_&&e.jsx("div",{className:"mx-auto mt-4 max-w-lg rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:_})]})})]})}function Ml({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:a,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:f,defaultMode:p,createDefaults:w,onCancel:N,onCreated:v}){var C,b,_;const[c,l]=n.useState(p??"chat");n.useEffect(()=>{p&&l(p)},[p]);const j=e.jsx("div",{className:"flex items-center gap-1 rounded-lg border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-sm",children:[{value:"chat",label:"New chat",icon:Wt},{value:"native",label:"Load session",icon:Us}].map(m=>{const y=m.icon,u=m.value===c;return e.jsxs("button",{type:"button",onClick:()=>l(m.value),"aria-pressed":u,className:$("flex items-center gap-1.5 rounded-sm px-2 py-1 transition-all duration-200",u?"bg-primary text-primary-foreground shadow-[0_8px_24px_-12px_hsl(var(--primary)/0.7)]":"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:m.label})]},m.value)})});return e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ds,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:a,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:f,centerSlot:j})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(hl,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(C=i==null?void 0:i.self)==null?void 0:C.role,currentNodeId:((b=i==null?void 0:i.self)==null?void 0:b.id)??null,leaderNodeId:((_=i==null?void 0:i.leader)==null?void 0:_.id)??null,initialAssignTo:w==null?void 0:w.assignTo,initialProject:w==null?void 0:w.project,mode:c,onModeChange:l,onCreated:v,onCancel:N,autoFocus:!0,layout:"composer"})})})]})}function Ds({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:a,operationsOpen:o,onToggleOperations:r,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(Na,{desktopTasksOpen:s,mobileTasksPanelOpen:a,onToggleTasks:t})}),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(I,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:Hs,children:o?e.jsx(Vs,{className:yt}):e.jsx(la,{className:yt})})]})}function Na({desktopTasksOpen:t,mobileTasksPanelOpen:s,onToggleTasks:a}){var r,i;const o=(i=(r=globalThis.window)==null?void 0:r.matchMedia("(min-width: 1024px)"))!=null&&i.matches?t:s;return e.jsx(I,{variant:"ghost",size:"icon",onClick:a,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:Hs,children:o?e.jsx(ia,{className:yt}):e.jsx(di,{className:yt})})}function Ll({onAdded:t}){const[s,a]=n.useState(""),[o,r]=n.useState(!1),[i,f]=n.useState(null),p=n.useCallback(async w=>{if(w.preventDefault(),!!s.trim()){r(!0),f(null);try{await kr({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(N){f(N instanceof Error?N.message:"Failed to join node")}finally{r(!1)}}},[s,t]);return e.jsx(Bs,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-xl border border-border/60 bg-background/95 p-0 shadow-[0_40px_120px_-60px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-6 py-5",children:e.jsxs(Qn,{className:"space-y-2 text-left",children:[e.jsx(Rs,{className:"text-2xl tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-sm 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:p,className:"space-y-4 px-6 py-5",children:[i&&e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm 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(Be,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Ye,{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:w=>a(w.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-11 rounded-lg border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-lg border border-border/60 bg-background/45 px-4 py-3 text-sm 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(Yn,{className:"border-t border-border/60 pt-4",children:e.jsx(I,{type:"submit",disabled:!s.trim()||o,className:"rounded-sm",children:o?"Joining...":"Join node"})})]})]})})}function Pl({open:t,onOpenChange:s,onAdded:a}){return e.jsx(Ps,{open:t,onOpenChange:s,children:e.jsx(Ll,{onAdded:()=>{s(!1),a()}})})}function is({className:t,label:s,orientation:a,panel:o,panelResize:r}){return e.jsx("button",{type:"button","aria-label":s,"aria-orientation":a,"data-dashboard-resize-handle":o,onPointerDown:i=>r.onPointerDown(o,i),onWheel:i=>r.onWheel(o,i),className:$("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 Bl({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:a,mobileTasksPanelOpen:o,mobileTasksPanelRef:r,operationsOpen:i,operationsPanelRef:f,operationsSidecar:p,panelResize:w,taskSidebar:N,terminalPanel:v,onCloseOperations:c,onCloseTaskList:l}){const j={"--dashboard-tasks-width":w.sizes.tasks,"--dashboard-operations-width":w.sizes.operations,"--dashboard-terminal-height":w.sizes.terminal};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",style:j,children:[e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsx("div",{className:$("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&&e.jsxs(e.Fragment,{children:[N,e.jsx(is,{panel:"tasks",orientation:"vertical",label:"Resize tasks panel",panelResize:w,className:"-right-1 top-0 h-full w-2 cursor-col-resize"})]})}),e.jsxs("section",{className:"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}),v&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(is,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:w,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),v]})]}),e.jsx("div",{className:$("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&&e.jsxs(e.Fragment,{children:[e.jsx(is,{panel:"operations",orientation:"vertical",label:"Resize operations panel",panelResize:w,className:"-left-1 top-0 h-full w-2 cursor-col-resize"}),p]})})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:c,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:f,className:"fixed inset-y-0 right-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:p})]}),o&&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:r,className:"fixed inset-y-0 left-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:a})]})]})}const Rl=10,ft="__all__";function Xe(t){return"session"in t}function Tn(t,s){var a;return s&&t.some(o=>o.id===s)?s:((a=t[0])==null?void 0:a.id)??""}function ls(t){return t&&(ga(t.id)||t.workDir)||""}function Ut(t,s,a){let o=!1;const r=t.map(i=>Xe(i)&&i.session.id===a.id?(o=!0,{...i,nodeName:s,session:a}):i);return As(o?r:[...r,{id:`session-${a.id}`,nodeName:s,session:a}])}function ya(t,s){return t.filter(Xe).filter(a=>a.session.nodeId===s).sort((a,o)=>o.session.startedAt-a.session.startedAt)}function $l(t){const s=t.filter(Xe).sort((a,o)=>o.session.startedAt-a.session.startedAt);return{active:s.filter(a=>a.session.status==="running"),completed:s.filter(a=>a.session.status!=="running")}}function Ol(t,s){return!!(t&&s&&!t.contains(s))}function Fl(t,s,a){var r;if(a===ft)return a;const o=ya(t,s);return o.some(i=>i.session.id===a)?a:((r=o[0])==null?void 0:r.session.id)??ft}function Il(t,s,a){return a===ft?t.filter(o=>!Xe(o)||o.session.nodeId===s):t.filter(o=>Xe(o)&&o.session.nodeId===s&&o.session.id===a)}function As(t){const s=t.map((o,r)=>({entry:o,index:r})).filter(({entry:o})=>Xe(o)&&o.session.status!=="running").sort((o,r)=>!Xe(o.entry)||!Xe(r.entry)?0:r.entry.session.startedAt-o.entry.session.startedAt||r.index-o.index),a=new Set(s.slice(0,Rl).map(({entry:o})=>Xe(o)?o.session.id:""));return t.filter(o=>!Xe(o)||o.session.status==="running"||a.has(o.session.id))}function Ms(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 zl(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${Ms(t.session)} - ${s}`}function ka(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function Ul(t,s){return s===ft?"All sessions":t?ka(t.session.command,34):"Command session"}function En(t){return t.status==="stopped"?"":t.stderr}function Vl({nodes:t,defaultNodeId:s,onClose:a,initialHistory:o=[]}){const[r,i]=n.useState(()=>Tn(t,s)),f=n.useMemo(()=>t.find(h=>h.id===r)??t[0]??null,[t,r]),[p,w]=n.useState(()=>ls(f)),[N,v]=n.useState(""),[c,l]=n.useState(()=>As(o)),[j,C]=n.useState(ft),[b,_]=n.useState(!1),[m,y]=n.useState(!1),[u,g]=n.useState(!1),[S,D]=n.useState(!1),[L,G]=n.useState(!1),U=n.useRef(null),F=n.useRef(null),A=n.useMemo(()=>t.find(h=>h.id===r)??t[0]??null,[t,r]),ae=n.useMemo(()=>ya(c,(A==null?void 0:A.id)??""),[c,A]),W=n.useMemo(()=>$l(ae),[ae]),M=n.useMemo(()=>ae.find(h=>h.session.id===j),[j,ae]),B=n.useMemo(()=>Il(c,(A==null?void 0:A.id)??"",j),[c,A,j]),re=n.useRef((A==null?void 0:A.id)??"");n.useEffect(()=>{r&&t.some(h=>h.id===r)||i(Tn(t,s))},[s,t,r]),n.useEffect(()=>{const h=(A==null?void 0:A.id)??"";re.current!==h&&(re.current=h,w(ls(A)))},[A]),n.useEffect(()=>{C(h=>Fl(c,(A==null?void 0:A.id)??"",b?h:""))},[c,A,b]),n.useEffect(()=>{var h;(h=U.current)==null||h.scrollTo({top:U.current.scrollHeight})},[c]),n.useEffect(()=>{let h=!1;async function Y(){const T=await Promise.allSettled(t.map(async J=>({node:J,response:await Cr(J.id)})));h||l(J=>T.reduce((x,O)=>O.status!=="fulfilled"?x:O.value.response.sessions.reduce((Q,me)=>Ut(Q,O.value.node.name,me),x),J))}return t.length>0&&Y(),()=>{h=!0}},[t]),n.useEffect(()=>{const h=c.filter(Xe).filter(T=>T.session.status==="running");if(h.length===0)return;const Y=window.setInterval(()=>{for(const T of h)Sr(T.session.nodeId,T.session.id).then(J=>l(x=>Ut(x,T.nodeName,J))).catch(()=>{})},1e3);return()=>window.clearInterval(Y)},[c]);const ee=n.useRef(null);async function oe(h){if(h.preventDefault(),!A||!N.trim()||L)return;const Y=N.trim(),T=A.name;G(!0),v("");try{const J=await Tr(A.id,{command:Y,...p.trim()?{cwd:p.trim()}:{}});l(x=>Ut(x,T,J)),C(J.id),_(!0)}catch(J){l(x=>[...x,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:T,command:Y,error:J instanceof Error?J.message:"Command failed"}])}finally{G(!1)}}async function ie(h,Y){h.stopPropagation();const T=await _r(Y.session.nodeId,Y.session.id);l(J=>Ut(J,Y.nodeName,T))}function V(h){C(h),_(!0),y(!1)}function z(h){m&&Ol(F.current,h.target)&&y(!1)}function te(h,Y,T,J,x){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:J,"aria-label":`Toggle ${h} sessions`,"aria-expanded":!T,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:h}),e.jsx(it,{className:$("h-3 w-3 transition-transform",T&&"-rotate-90")})]}),!T&&(Y.length>0?Y.map(we):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:x}))]})}function we(h){const Y=j===h.session.id,T=h.session.status==="running";return e.jsxs("div",{className:$("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",Y&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>V(h.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:$("flex h-4 w-4 shrink-0 items-center justify-center",T?"text-primary":h.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:T?e.jsx(xe,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(ln,{className:"h-3 w-3"}):e.jsx(Kt,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:ka(h.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[h.nodeName," · ",Ms(h.session)]})]})]}),T&&e.jsx("button",{type:"button",onClick:J=>void ie(J,h),"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(jn,{className:"h-3 w-3"})})]},h.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:z,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:[a?e.jsx("button",{type:"button",onClick:a,"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(ot,{className:"h-3.5 w-3.5"})}):e.jsx(on,{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:F,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":m,title:M?zl(M):"All sessions",onClick:()=>y(h=>!h),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:Ul(M,j)}),e.jsx(it,{className:$("h-3 w-3 shrink-0 text-muted-foreground transition-transform",m&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!m,className:$("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!m&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>V(ft),className:$("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",j===ft&&"bg-primary/10 text-primary"),children:[e.jsx(on,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),te("Active",W.active,u,()=>g(h=>!h),"No active sessions"),te("Completed",W.completed,S,()=>D(h=>!h),"No completed sessions")]})})]}),e.jsx("select",{value:(A==null?void 0:A.id)??"",onChange:h=>{i(h.target.value),_(!1),w(ls(t.find(Y=>Y.id===h.target.value)??null))},disabled:L||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(h=>e.jsx("option",{value:h.id,className:"bg-background text-foreground",children:h.name},h.id))}),e.jsx(Gt,{value:p,onChange:w,assignTo:(A==null?void 0:A.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:U,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 h;return(h=ee.current)==null?void 0:h.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(h=>Xe(h)?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:[h.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:h.session.command}),e.jsxs("span",{className:$("inline-flex items-center gap-1",h.session.status==="running"||h.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[h.session.status==="running"?e.jsx(xe,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(ln,{className:"h-3 w-3"}):e.jsx(Kt,{className:"h-3 w-3"}),Ms(h.session)]}),h.session.status==="running"&&e.jsx("button",{type:"button",onClick:Y=>void ie(Y,h),"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(jn,{className:"h-3 w-3"})})]}),h.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:h.session.stdout}),En(h.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:En(h.session)}),(h.session.stdoutTruncated||h.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},h.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:[h.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:h.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(Kt,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:h.error})]},h.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:A?`${A.name}$`:"$"}),e.jsx("input",{ref:ee,value:N,onChange:h=>v(h.target.value),disabled:!A||L,placeholder:A?"":"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:!A||!N.trim()||L,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:L?e.jsx(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(Is,{className:"h-3 w-3"})})]})]})]})})}function Ws({nodeId:t,nodeName:s,onOpenSettings:a,onOpenDevBox:o,onStartDevBox:r,showConfigureDevBox:i,showStartDevBox:f,startDevBoxPending:p,className:w}){const[N,v]=n.useState(!1),c=n.useRef(null),l=p?"Starting":"Start DevBox";return n.useEffect(()=>{if(!N)return;const j=b=>{var m;const _=b.target;_ instanceof Node&&((m=c.current)!=null&&m.contains(_)||v(!1))},C=b=>{b.key==="Escape"&&v(!1)};return document.addEventListener("mousedown",j),document.addEventListener("keydown",C),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",C)}},[N]),e.jsxs("div",{ref:c,className:$("relative shrink-0",w),onClick:j=>j.stopPropagation(),children:[e.jsx(I,{type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${s}`,"aria-haspopup":"menu","aria-expanded":N,title:`More actions for ${s}`,onClick:()=>v(j=>!j),className:$("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",N&&"bg-background/80 text-primary"),children:e.jsx(qo,{className:"h-3.5 w-3.5"})}),N&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-full z-30 mt-1 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:[e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} settings`,title:`Open ${s} settings`,onClick:()=>{v(!1),a(t)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Er,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Settings"})]}),f&&r&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${l} for ${s}`,title:`${l} for ${s}`,onClick:()=>{p||(v(!1),r(t))},disabled:p,className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80 disabled:cursor-not-allowed disabled:opacity-60",children:[p?e.jsx(xe,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(Is,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:l})]}),i&&o&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${s}`,title:`Configure DevBox for ${s}`,onClick:()=>{v(!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(Dr,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Configure DevBox"})]})]})]})}const ql=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),Kl=new Set(["startinprogress","starting"]);function kt(t){return!!(t!=null&&t.enabled&&t.name)}function Hl(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&ql.has(s))}function St(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&Kl.has(s))}function Qt(t,s,a){return t==="offline"&&Hl(s)&&kt(a)}function Dn(t,s){return t==="offline"&&kt(s)}function An(t){return!kt(t)}function Wl({nodeStatus:t,status:s,current:a,selected:o}){const r=o??a;return r&&Qt(t,s,r)?r:null}function Me(t){return t.scope||`name:${t.name??""}`}function Gl({previousKey:t,baseDevBox:s,listed:a}){if(t&&a.some(i=>Me(i)===t))return t;if(!kt(s))return a[0]?Me(a[0]):"";const o=Me(s),r=a.find(i=>Me(i)===o)??a.find(i=>i.name===s.name);return r?Me(r):o}function Ql({cluster:t,systemInfo:s,nodeNameById:a,nodeBlockingTaskCounts:o,eventTypeFilter:r,onEventTypeFilterChange:i,eventTypeOptions:f,filteredEvents:p,sseConnected:w,clusterLoading:N,clusterError:v,promotePending:c,onPromote:l,onAddNode:j,leavePending:C,onLeaveCluster:b,onToggleNodeDevTunnel:_,devTunnelNodeId:m,devBoxStartNodeId:y,devBoxStartingNodeIds:u=new Set,onOpenNodeSettings:g,onOpenDevBox:S,onStartDevBox:D,onClose:L}){var ee,oe,ie;const G=((ee=t==null?void 0:t.self)==null?void 0:ee.role)==="leader",U=((oe=t==null?void 0:t.self)==null?void 0:oe.role)==="follower"&&!(t!=null&&t.leader),F=(t==null?void 0:t.self)??null,ae=Ar((t==null?void 0:t.nodes)??[],F==null?void 0:F.id).filter(V=>V.id!==(F==null?void 0:F.id)),W=t!=null&&t.leader?t.nodes.find(V=>{var z;return V.id===((z=t.leader)==null?void 0:z.id)})??null:null,M=t!=null&&t.leader?t.leader.dashboardOrigin??(W==null?void 0:W.dashboardOrigin)??(s&&t.leader.id===(s.nodeId??s.id)?s.dashboardOrigin:void 0)??t.leader.endpoint:null,B=(F==null?void 0:F.role)==="leader"&&ae.length===0,re=(F==null?void 0:F.role)==="follower";return e.jsx("aside",{className:"dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl !border-0",children:e.jsxs(Hn,{defaultValue:"overview",className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"shrink-0 bg-card/24 px-2.5 py-2.5 shadow-[0_1px_0_hsl(var(--border)/0.22)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold tracking-tight",children:"Operations"}),e.jsx("p",{className:"mt-px text-[9px] text-muted-foreground",children:"Node, cluster, and live events."})]}),e.jsx(I,{variant:"ghost",size:"icon",onClick:L,className:"h-6 w-6 rounded-sm",children:e.jsx(Vs,{className:"h-3.5 w-3.5"})})]}),e.jsxs(Gn,{className:"mt-1.5 grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(xt,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(xt,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(xt,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})]}),e.jsx(ht,{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:[F&&e.jsx(Mn,{node:F,systemInfo:s,blockingTaskCount:o.get(F.id)??0,devTunnelNodeId:m,onToggleNodeDevTunnel:_,showActions:!1,defaultExpanded:!1,onOpenDevBox:S,devBoxStartingNodeIds:u}),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(Ye,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 shadow-sm",children:w?"Connected":"Reconnecting"})]}),N&&!t?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(xe,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):v&&!t?e.jsx("div",{className:"rounded-sm bg-destructive/10 px-2 py-1.5 text-[10px] text-destructive shadow-sm",children:v}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(jt,{label:"Term",value:String((t==null?void 0:t.term)??0)}),e.jsx(jt,{label:"Nodes",value:String((t==null?void 0:t.nodes.length)??0)}),e.jsx(jt,{label:"Pending",value:String((t==null?void 0:t.taskSummary.pending)??0)}),e.jsx(jt,{label:"Running",value:String((t==null?void 0:t.taskSummary.running)??0)}),e.jsx(jt,{label:"Completed",value:String((t==null?void 0:t.taskSummary.completed)??0)}),e.jsx(jt,{label:"Failed",value:String((t==null?void 0:t.taskSummary.failed)??0)})]}),e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/56 px-2 py-2 shadow-sm",children:[e.jsx(st,{label:"Leader",value:((ie=t==null?void 0:t.leader)==null?void 0:ie.name)??"None"}),e.jsx(st,{label:"Leader URL",value:M??"Unavailable",mono:!0,action:M?e.jsx($t,{label:"Copy leader URL",onClick:()=>void wt(M,"Leader URL copied")}):void 0}),e.jsx(st,{label:"Feed",value:w?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:U&&e.jsxs(I,{variant:"outline",size:"sm",onClick:l,disabled:c,className:"h-6 rounded-sm px-2 text-[10px]",children:[c&&e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(ht,{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.jsx(I,{variant:"outline",size:"sm",onClick:j,className:"h-6 rounded-sm px-2 text-[10px]",children:"Join node"}):re?e.jsxs(I,{variant:"outline",size:"sm",onClick:b,disabled:C,className:"h-6 rounded-sm px-2 text-[10px]",children:[C&&e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),F&&e.jsx(Mn,{node:F,systemInfo:s,blockingTaskCount:o.get(F.id)??0,devTunnelNodeId:m,onToggleNodeDevTunnel:_,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:G?g:void 0,onOpenDevBox:G?S:void 0,onStartDevBox:G?D:void 0,devBoxStartNodeId:y,devBoxStartingNodeIds:u})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",ae.length,")"]}),ae.length>0?e.jsx("div",{className:"space-y-1.5",children:ae.map(V=>e.jsx(Yl,{node:V,isLeader:!!G,blockingTaskCount:o.get(V.id)??0,devTunnelNodeId:m,onToggleNodeDevTunnel:_,onOpenNodeSettings:G?g:void 0,onOpenDevBox:G?S:void 0,onStartDevBox:G?D:void 0,devBoxStartNodeId:y,devBoxStartingNodeIds:u},V.id))}):e.jsx("div",{className:"rounded-sm bg-background/45 px-2 py-2 text-[10px] text-muted-foreground shadow-sm",children:"No peer nodes are connected yet."})]})]})})}),e.jsx(ht,{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(Mr,{className:$("h-3.5 w-3.5",w?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(Te,{value:r,onValueChange:i,children:[e.jsx(Ee,{className:"h-6 min-w-[10rem] flex-1 rounded-sm border-border/70 bg-background/60 text-[10px] sm:max-w-[14rem] [&>svg]:h-3 [&>svg]:w-3",children:e.jsx(Ue,{placeholder:"Event type"})}),e.jsx(De,{children:f.map(V=>e.jsx(ke,{value:V,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:V==="all"?"All event types":V},V))})]}),e.jsx(Ye,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 shadow-sm",children:w?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Lr,{events:p,maxHeight:"100%",emptyTitle:r==="all"?"No live events yet":"No matching events",emptyDescription:r==="all"?"Cluster activity appears here as it happens.":`No "${r}" events are in the current stream.`,nodeNameById:a,density:"compact"})})]})})]})})}function Mn({node:t,systemInfo:s,blockingTaskCount:a,devTunnelNodeId:o,onToggleNodeDevTunnel:r,showActions:i=!0,defaultExpanded:f=!1,onOpenNodeSettings:p,onOpenDevBox:w,onStartDevBox:N,devBoxStartNodeId:v,devBoxStartingNodeIds:c}){var D,L,G,U;const[l,j]=n.useState(f),C=(s==null?void 0:s.dashboardOrigin)??t.dashboardOrigin,b=t.devtunnelEndpoint??t.endpoint,_=C??t.endpoint,m=(s==null?void 0:s.workDir)??t.workDir,y=ua(t,s==null?void 0:s.transportType),u=qs(t,s==null?void 0:s.transportType),g=u&&_t((s==null?void 0:s.transportType)??t.transportType)?!0:ca(t,s==null?void 0:s.transportType),S=a>0;return e.jsxs("section",{className:"rounded-lg bg-primary/7 shadow-[0_18px_56px_-42px_hsl(var(--primary)/0.85)]",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:()=>j(F=>!F),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[l?e.jsx(it,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Bt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(Xn,{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:_,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Jn,{className:"h-3 w-3"})}),p&&e.jsx(Ws,{nodeId:t.id,nodeName:t.name,onOpenSettings:p,onOpenDevBox:w,onStartDevBox:N,showConfigureDevBox:(D=t.devbox)==null?void 0:D.enabled,showStartDevBox:Qt(t.status,(L=t.devbox)==null?void 0:L.lastStatus,t.devbox)||St((G=t.devbox)==null?void 0:G.lastStatus)||c.has(t.id),startDevBoxPending:v===t.id||St((U=t.devbox)==null?void 0:U.lastStatus)||c.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>j(F=>!F),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(Zn,{role:t.role,size:"compact"}),e.jsx(Ye,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-sm",children:t.status})]})]}),l&&e.jsxs("div",{className:"space-y-2 px-2.5 pb-2.5 pt-1.5 shadow-[inset_0_1px_0_hsl(var(--primary)/0.12)]",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/70 px-2 py-1.5 shadow-sm",children:[e.jsx(st,{label:"Node ID",value:t.id,mono:!0}),C&&e.jsx(st,{label:"Dashboard",value:C,mono:!0,action:e.jsx($t,{label:"Copy dashboard URL",onClick:()=>void wt(C,"Dashboard URL copied")})}),e.jsx(st,{label:"Node URL",value:b,mono:!0,action:e.jsx($t,{label:"Copy node URL",onClick:()=>void wt(b,"Node URL copied")})}),m&&e.jsx(st,{label:"Workspace",value:m,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Ns,{label:"Transport",value:y}),s&&e.jsx(Ns,{label:"Uptime",value:Pr(s.uptime),mono:!0})]}),e.jsx(ra,{capabilities:t.capabilities,action:i&&g?e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>r(t),disabled:o===t.id||S,className:"h-6 rounded-sm px-2 text-[10px]",title:S?"Finish assigned or running tasks before changing remote access":void 0,children:[o===t.id&&e.jsx(xe,{className:"h-3 w-3 animate-spin"}),u?"Disable Remote Access":"Enable Remote Access"]}):void 0}),i&&g&&S&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[a," active task",a===1?"":"s"," on this node."]})]})]})}function Yl({node:t,isLeader:s,blockingTaskCount:a,devTunnelNodeId:o,onToggleNodeDevTunnel:r,onOpenNodeSettings:i,onOpenDevBox:f,onStartDevBox:p,devBoxStartNodeId:w,devBoxStartingNodeIds:N}){var u,g,S,D;const[v,c]=n.useState(!1),l=t.dashboardOrigin,j=t.devtunnelEndpoint??t.endpoint,C=l??t.endpoint,b=ua(t),_=qs(t),m=ca(t),y=a>0;return e.jsxs("div",{className:"rounded-sm bg-background/54 shadow-sm",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:()=>c(L=>!L),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[v?e.jsx(it,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(Bt,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Xn,{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:C,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Jn,{className:"h-3 w-3"})}),s&&i&&e.jsx(Ws,{nodeId:t.id,nodeName:t.name,onOpenSettings:i,onOpenDevBox:f,onStartDevBox:p,showConfigureDevBox:(u=t.devbox)==null?void 0:u.enabled,showStartDevBox:Qt(t.status,(g=t.devbox)==null?void 0:g.lastStatus,t.devbox)||St((S=t.devbox)==null?void 0:S.lastStatus)||N.has(t.id),startDevBoxPending:w===t.id||St((D=t.devbox)==null?void 0:D.lastStatus)||N.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>c(L=>!L),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(Zn,{role:t.role,size:"compact"}),e.jsx(Ye,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-sm",children:t.status})]})]}),v&&e.jsxs("div",{className:"space-y-2 px-2.5 pb-2.5 pt-1.5 shadow-[inset_0_1px_0_hsl(var(--border)/0.22)]",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(st,{label:"Node ID",value:t.id,mono:!0}),l&&e.jsx(st,{label:"Dashboard",value:l,mono:!0,action:e.jsx($t,{label:"Copy dashboard URL",onClick:()=>void wt(l,"Dashboard URL copied")})}),e.jsx(st,{label:"Node URL",value:j,mono:!0,action:e.jsx($t,{label:"Copy node URL",onClick:()=>void wt(j,"Node URL copied")})}),t.workDir&&e.jsx(st,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(Ns,{label:"Transport",value:b})]}),e.jsx(ra,{capabilities:t.capabilities,action:s&&m?e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>r(t),disabled:o===t.id||y,className:"h-6 rounded-sm px-2 text-[10px]",title:y?"Finish assigned or running tasks before changing remote access":void 0,children:[o===t.id&&e.jsx(xe,{className:"h-3 w-3 animate-spin"}),_?"Disable Remote Access":"Enable Remote Access"]}):void 0}),s&&m&&y&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[a," active task",a===1?"":"s"," on this node."]})]})]})}function $t({label:t,onClick:s}){return e.jsx(I,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground",onClick:s,"aria-label":t,title:t,children:e.jsx(Kn,{className:"h-3 w-3"})})}function Xl(t,s,a,o){var p,w;if(!t)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const r=((p=s==null?void 0:s.self)==null?void 0:p.role)==="follower",i=t.assignedTo?((w=s==null?void 0:s.self)==null?void 0:w.id)===t.assignedTo?s.self:s==null?void 0:s.nodes.find(N=>N.id===t.assignedTo):void 0;return t.assignedTo!==null&&(i?i.status==="offline":s?t.assignedNodeAvailable===!1||!s.nodes.some(N=>N.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.`}:r?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Follower nodes are read-only. Use the leader dashboard to manage chat, or leave the cluster first."}:a?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Sending message..."}:o?{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Queue a message for the next turn..."}:Ht.has(t.status)||t.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:Ht.has(t.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const Sa="meshy-task-sidebar-tree-state";function Ln(t){return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function ds(){var t;try{return((t=globalThis.window)==null?void 0:t.localStorage)??globalThis.localStorage??null}catch{return null}}function Pn(t){if(!t)return{collapsedNodes:[],collapsedDirs:[]};try{const s=t.getItem(Sa);if(!s)return{collapsedNodes:[],collapsedDirs:[]};const a=JSON.parse(s);return{collapsedNodes:Ln(a.collapsedNodes),collapsedDirs:Ln(a.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Jl(t,s){if(t)try{t.setItem(Sa,JSON.stringify(s))}catch{}}function Bn(t,s){if(!t.has(s))return t;const a=new Set(t);return a.delete(s),a}function Zl(t,s){if(!s)return null;for(const a of t){const o=a.nodeId??"__unassigned__";for(const r of a.dirs)if(r.tasks.some(i=>i.id===s))return{nodeKey:o,dirKey:`${o}::${r.path}`}}return null}function Rn(t,s,a){return a?{collapsedNodes:Bn(t,a.nodeKey),collapsedDirs:Bn(s,a.dirKey)}:{collapsedNodes:t,collapsedDirs:s}}function ed(t,s,a){const o=t.filter(p=>p.status==="completed"),r=new Set((s?o:[...o].sort((p,w)=>w.updatedAt-p.updatedAt).slice(0,Os)).map(p=>p.id));a&&o.some(p=>p.id===a)&&r.add(a);const i=t.filter(p=>p.status!=="completed"||r.has(p.id)),f=o.length-r.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,f)}}const Vt="h-6 rounded-sm border-border/70 bg-background/60 px-2 py-0 text-[10px] leading-none shadow-sm [&>svg]:h-3 [&>svg]:w-3",qt="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function $n({toolbarTasks:t,activeTaskId:s,tasksLoading:a,tasksError:o,isLeader:r,scope:i,agentFilter:f,nodeFilter:p,taskKindFilter:w,agentOptions:N,nodeOptions:v,nodeNameById:c,nodeWorkDirById:l,nodeStatusById:j,completedGroupByKey:C,devBoxNodeIds:b=new Set,devBoxStartNodeIds:_=new Set,devBoxStartingNodeIds:m=new Set,leaderNodeId:y,searchQuery:u,selectedTaskIds:g,allVisibleTasksSelected:S,someVisibleTasksSelected:D,canBatchArchive:L,onSearchChange:G,onScopeChange:U,onAgentFilterChange:F,onNodeFilterChange:A,onTaskKindFilterChange:ae,onToggleTaskSelected:W,onToggleAllVisibleTasks:M,onBatchArchive:B,onBatchDelete:re,onCreateTask:ee,onOpenNodeSettings:oe,onOpenDevBox:ie,onStartDevBox:V,onLoadCompletedTasks:z,onSelectTask:te,onClose:we}){const[h,Y]=n.useState(!!u),[T,J]=n.useState(!1),[x,O]=n.useState(!1),Q=n.useRef(null),me=n.useRef(null),q=n.useRef(null),[X,se]=n.useState(()=>g.size>0),{markScrollbarActive:Se,scrollbarActive:P}=wa(),H=g.size,Ne=!!(r&&(X||H>0)),Re=i!=="active"||p!=="all"||f!=="all"||w!=="all",Ve=u.trim().length>0,[Je,ye]=n.useState(()=>new Set(Pn(ds()).collapsedNodes)),[Z,he]=n.useState(()=>new Set(Pn(ds()).collapsedDirs)),[Le,$e]=n.useState(new Set),qe=n.useMemo(()=>Br(t,c,y,l),[t,c,y,l]),le=n.useMemo(()=>Zl(qe,s),[qe,s]),Pe=n.useRef(null),Ge=qe.length===1,at=qe.length>0,Ze=Ge&&(Re||Ve),Tt=!!(r&&(qe.length>0||H>0)),pt=n.useCallback(E=>{ye(be=>{const fe=new Set(be);return fe.has(E)?fe.delete(E):fe.add(E),fe})},[]),gt=n.useCallback(E=>{he(be=>{const fe=new Set(be);return fe.has(E)?fe.delete(E):fe.add(E),fe})},[]),rt=n.useCallback(E=>{$e(be=>{const fe=new Set(be);return fe.add(E),fe})},[]);n.useEffect(()=>{Jl(ds(),{collapsedNodes:Array.from(Je),collapsedDirs:Array.from(Z)})},[Z,Je]),n.useEffect(()=>{if(!le||!s)return;const E=`${s}:${le.nodeKey}:${le.dirKey}`;Pe.current!==E&&(Pe.current=E,ye(be=>Rn(be,new Set,le).collapsedNodes),he(be=>Rn(new Set,be,le).collapsedDirs))},[s,le]);const Oe=n.useCallback(E=>{se(!0),M(E)},[M]),ut=n.useCallback(()=>{M(!1),se(!1)},[M]);n.useEffect(()=>{r||se(!1)},[r]),n.useEffect(()=>{u&&Y(!0)},[u]),n.useEffect(()=>{var E;h&&((E=Q.current)==null||E.focus())},[h]),n.useEffect(()=>{if(!h)return;const E=fe=>{var Ke;const Fe=fe.target;Fe instanceof Node&&((Ke=me.current)!=null&&Ke.contains(Fe)||Y(!1))},be=fe=>{fe.key==="Escape"&&Y(!1)};return document.addEventListener("mousedown",E),document.addEventListener("keydown",be),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",be)}},[h]),n.useEffect(()=>{if(!x)return;const E=fe=>{var Ke;const Fe=fe.target;Fe instanceof Node&&((Ke=q.current)!=null&&Ke.contains(Fe)||O(!1))},be=fe=>{fe.key==="Escape"&&O(!1)};return document.addEventListener("mousedown",E),document.addEventListener("keydown",be),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",be)}},[x]);const Ce=Ne?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(js,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:D&&!S?"indeterminate":S,onCheckedChange:E=>Oe(E===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Multi select"})]}):e.jsxs(I,{variant:"ghost",size:"sm",onClick:()=>se(!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(Mo,{className:"h-3 w-3"}),"Multi select"]}),mt=H>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:[H," task",H!==1?"s":""," selected"]}),!L&&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,Et=H>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(ms,{children:[e.jsx(dn,{asChild:!0,children:e.jsxs(I,{variant:"ghost",size:"sm",disabled:!L,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(Io,{}),"Archive"]})}),e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsxs(fs,{children:["Archive ",H," task",H!==1?"s":"","?"]}),e.jsx(ps,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(gs,{children:[e.jsx(bs,{children:"Cancel"}),e.jsx(vs,{onClick:B,disabled:!L,children:"Archive"})]})]})]}),e.jsxs(ms,{children:[e.jsx(dn,{asChild:!0,children:e.jsxs(I,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(yi,{}),"Delete"]})}),e.jsxs(xs,{children:[e.jsxs(hs,{children:[e.jsxs(fs,{children:["Delete ",H," task",H!==1?"s":"","?"]}),e.jsx(ps,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(gs,{children:[e.jsx(bs,{children:"Cancel"}),e.jsx(vs,{onClick:re,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return e.jsxs("aside",{className:"dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl !border-t-0",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 bg-card/24 px-2.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-sm font-semibold tracking-tight text-foreground",children:"Tasks"}),e.jsx(I,{variant:"ghost",size:"icon",onClick:we,className:"h-6 w-6 rounded-sm",children:e.jsx(ia,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{ref:me,className:"mt-2 flex items-center gap-1.5",children:[e.jsxs("div",{ref:q,className:$("relative flex items-stretch transition-[flex] duration-200",h?"flex-[2]":"flex-1"),children:[e.jsxs(I,{onClick:()=>{O(!1),ee("chat")},className:"h-8 flex-1 justify-start rounded-l-sm rounded-r-none px-2.5 text-left text-[11px] shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(Wt,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsx(I,{onClick:()=>O(E=>!E),"aria-label":"More chat options","aria-haspopup":"menu","aria-expanded":x,className:"h-8 w-7 rounded-l-none rounded-r-sm border-l border-primary-foreground/20 px-0 shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:e.jsx(it,{className:$("h-3 w-3 transition-transform",x&&"rotate-180")})}),x&&e.jsx("div",{role:"menu",className:"absolute left-0 right-0 top-full z-20 mt-2 overflow-hidden rounded-lg border border-border/60 bg-popover/96 p-1 shadow-[0_20px_60px_-30px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{O(!1),ee("native")},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-2 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Us,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{className:"flex-1 truncate whitespace-nowrap",children:"Load session"}),e.jsx("span",{className:"shrink-0 text-[9px] uppercase tracking-[0.18em] text-muted-foreground",children:"native"})]})})]}),h?e.jsxs("div",{className:"flex min-w-0 flex-[3] items-center gap-1.5",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(cs,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(nt,{ref:Q,value:u,onChange:E=>G(E.target.value),placeholder:"Search tasks",className:"h-8 rounded-sm border-border/70 bg-background/68 pl-8 text-[11px] shadow-none"})]}),e.jsx(I,{variant:"outline",size:"icon",onClick:()=>Y(!1),className:"h-8 w-8 rounded-sm border-border/70 bg-background/68 shadow-none",children:e.jsx(Kt,{className:"h-3.5 w-3.5"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(I,{variant:"outline",onClick:()=>Y(!0),className:$("h-8 rounded-sm border-border/70 bg-background/68 px-2.5 text-[11px] shadow-none",u&&"border-primary/40 bg-primary/8 text-primary"),children:[e.jsx(cs,{className:"h-3.5 w-3.5"}),"Search"]}),e.jsx(I,{variant:T||Re?"secondary":"outline",size:"icon",onClick:()=>J(E=>!E),className:$("h-8 w-8 shrink-0 rounded-sm border-border/70 bg-background/68 shadow-none",Re&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(Qo,{className:"h-3.5 w-3.5"})})]})]}),(T||Re)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(Te,{value:i,onValueChange:E=>U(E),children:[e.jsx(Ee,{className:Vt,children:e.jsx(Ue,{})}),e.jsx(De,{children:Rr.map(E=>e.jsx(ke,{value:E.value,className:qt,children:E.label},E.value))})]}),e.jsxs(Te,{value:p,onValueChange:A,children:[e.jsx(Ee,{className:Vt,children:e.jsx(Ue,{placeholder:"Node"})}),e.jsx(De,{children:v.map(E=>e.jsx(ke,{value:E.value,className:qt,children:E.label},E.value))})]}),e.jsxs(Te,{value:f,onValueChange:F,children:[e.jsx(Ee,{className:Vt,children:e.jsx(Ue,{placeholder:"Agent"})}),e.jsx(De,{children:N.map(E=>e.jsx(ke,{value:E,className:qt,children:E==="all"?"All agents":E},E))})]}),e.jsxs(Te,{value:w,onValueChange:E=>ae(E),children:[e.jsx(Ee,{className:Vt,children:e.jsx(Ue,{placeholder:"Type"})}),e.jsx(De,{children:$r.map(E=>e.jsx(ke,{value:E.value,className:qt,children:E.label},E.value))})]})]})]}),e.jsx("div",{className:$("scrollbar-line min-h-0 flex-1 overflow-y-auto px-1.5 py-2",P&&"scrollbar-line-active"),onScroll:Se,children:qe.length>0?e.jsx("div",{className:"space-y-1",children:qe.map(E=>{const be=E.nodeId??"__unassigned__",fe=E.dirs.reduce((Ae,Ie)=>Ae+Ie.tasks.length,0),Fe=at&&!Ze&&Je.has(be),Ke=E.nodeId!==null&&j.get(E.nodeId)==="offline",lt=!!(r&&E.nodeId&&oe);return e.jsxs("div",{className:"space-y-1",children:[at&&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:()=>pt(be),"aria-expanded":!Fe,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(Bt,{className:$("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!Fe&&"rotate-90")}),e.jsx(Un,{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:E.nodeName}),e.jsxs(Ye,{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:[fe," task",fe===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[Ke&&e.jsx(Ye,{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"}),E.nodeId===y&&e.jsx(Ye,{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"})]})]}),lt&&E.nodeId&&oe&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(Ws,{nodeId:E.nodeId,nodeName:E.nodeName,onOpenSettings:oe,onOpenDevBox:ie,onStartDevBox:V,showConfigureDevBox:b.has(E.nodeId),showStartDevBox:_.has(E.nodeId)||m.has(E.nodeId),startDevBoxPending:m.has(E.nodeId)})})]}),e.jsx("div",{className:$("grid transition-[grid-template-rows] duration-300 ease-in-out",Fe?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:E.dirs.map(Ae=>{const Ie=`${be}::${Ae.path}`,dt=Z.has(Ie),_e=ea(Ae.path),Qe=C==null?void 0:C.get(Ie),bt=Qe?{visibleTasks:Ae.tasks,hiddenCompletedCount:Math.max(0,Qe.total-Qe.returned)}:ed(Ae.tasks,Le.has(Ie),s),{visibleTasks:ve,hiddenCompletedCount:ce}=bt;return e.jsxs("div",{className:$("space-y-0.5 rounded-xl",at&&"pl-2.5"),children:[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:()=>gt(Ie),"aria-expanded":!dt,title:Ae.path,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-l-sm px-2 py-1 text-left",children:[e.jsx(Bt,{className:$("h-3 w-3 shrink-0 transition-transform duration-200",!dt&&"rotate-90")}),e.jsx(Vn,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:_e}),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:Ae.tasks.length})]}),e.jsx("button",{type:"button",onClick:()=>ee("chat",{assignTo:E.nodeId,project:Ae.path==="default workspace"?"":Ae.path}),"aria-label":`New chat in ${Ae.path}`,title:`New chat in ${Ae.path}`,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(Wt,{className:"h-2.5 w-2.5"})})]}),e.jsx("div",{className:$("grid transition-[grid-template-rows] duration-300 ease-in-out",dt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:$("overflow-hidden",at?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[ve.map(pe=>{const et=pe.id===s,ze=pe.assignedTo?j.get(pe.assignedTo):void 0,He=!!pe.assignedTo&&(ze?ze==="offline":pe.assignedNodeAvailable===!1);return e.jsxs("div",{className:$("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",et?'bg-primary/10 before:absolute before:left-0 before:top-1/2 before:h-1/2 before:w-[2px] before:-translate-y-1/2 before:rounded-full before:bg-primary before:content-[""]':"hover:bg-muted/40"),children:[Ne&&e.jsx("div",{className:"flex shrink-0",onClick:Dt=>Dt.stopPropagation(),children:e.jsx(js,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:g.has(pe.id),onCheckedChange:Dt=>W(pe.id,Dt===!0),"aria-label":`Select ${pe.title}`})}),e.jsxs("button",{type:"button",onClick:()=>te(pe.id),"aria-current":et?"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:$("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",et?"text-foreground":"text-foreground/80"),children:pe.title})}),e.jsx("span",{className:$("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",et?"text-primary/75":"text-muted-foreground/55"),children:Or(pe.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:pe.agent}),pe.activeShare&&e.jsx(Ye,{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"}),He&&e.jsx(Ye,{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(Wn,{status:pe.status,isNative:pe.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},pe.id)}),ce>0&&e.jsxs("button",{type:"button",onClick:()=>{Qe&&z?z(Qe):rt(Ie)},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 ${ce} more completed tasks in ${_e}`,children:[e.jsx(it,{className:"h-3 w-3"}),"Load ",ce," more completed"]})]})})})]},Ie)})})})]},be)})}):a?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(E=>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+E*12}%`,animationDelay:`${E*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${E*120+60}ms`}})]})]})},E))}):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:o||"No tasks match this view."})}),Tt?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:Ne&&H>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[mt,e.jsx(I,{variant:"ghost",size:"sm",onClick:ut,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Clear"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:Ce}),Et]})]}):e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:Ce}),Ne&&e.jsx(I,{variant:"ghost",size:"sm",onClick:ut,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]})}async function td(t,s){var a,o;try{const r=await Fr(t,s),i={...r,url:qn(r.url)};if((o=(a=globalThis.navigator)==null?void 0:a.clipboard)!=null&&o.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),ne.success("Shared link copied")}catch{ne.success("Shared link created")}else ne.success("Shared link created");return i}catch(r){ne.error(r instanceof Error?r.message:"Failed to create shared link");return}}async function sd(t){try{return await Ir(t),ne.success("Shared link stopped"),!0}catch(s){return ne.error(s instanceof Error?s.message:"Failed to stop shared link"),!1}}function nd(t,s,a){const o=n.useCallback(()=>{s(),a()},[s,a]),r=n.useCallback(async f=>{if(!t)return;const p=await td(t.id,f);return p&&o(),p},[t,o]),i=n.useCallback(async()=>{if(!t)return!1;const f=await sd(t.id);return f&&o(),f},[t,o]);return{handleShareTask:r,handleStopShareTask:i}}function On(t,s,a){const o=n.useRef(s);o.current=s,n.useEffect(()=>{let f=0,p=0;const w=c=>{const l=c.touches[0];l&&(f=l.clientX,p=l.clientY)},N=c=>{var b,_,m,y;const l=c.changedTouches[0];if(!l)return;const j=l.clientX-f;Math.abs(l.clientY-p)>100||Math.abs(j)<50||(j>0?(_=(b=o.current).onSwipeRight)==null||_.call(b):(y=(m=o.current).onSwipeLeft)==null||y.call(m))},v=(t==null?void 0:t.current)??document;return v.addEventListener("touchstart",w,{passive:!0}),v.addEventListener("touchend",N,{passive:!0}),()=>{v.removeEventListener("touchstart",w),v.removeEventListener("touchend",N)}},[t,a==null?void 0:a.threshold,a==null?void 0:a.maxVertical])}const ad="(min-width: 1024px)",rd="(min-width: 1800px)";function Fn(t){var s,a,o;return((o=(a=(s=globalThis.window)==null?void 0:s.matchMedia)==null?void 0:a.call(s,t))==null?void 0:o.matches)??!1}function od(){var a,o;const t=(a=globalThis.document)==null?void 0:a.documentElement;if(!t||!((o=globalThis.window)!=null&&o.getComputedStyle))return 16;const s=Number.parseFloat(globalThis.window.getComputedStyle(t).fontSize);return Number.isFinite(s)&&s>0?s:16}function id(){const[t,s]=n.useState(()=>zr(cn(),Ur({operationsOpen:Fn(rd)}))),[a,o]=n.useState(!1),r=n.useRef(null),i=n.useRef(null),f=n.useRef(null),p=t.layout.desktopTasksOpen,w=t.layout.operationsOpen,N=t.sizes;n.useEffect(()=>{Vr(cn(),t)},[t]);const v=n.useCallback((_,m)=>{s(y=>{const u=y.layout[_],g=typeof m=="function"?m(u):m;return g===u?y:{...y,layout:{...y.layout,[_]:g}}})},[]),c=n.useCallback(_=>{v("desktopTasksOpen",_)},[v]),l=n.useCallback(_=>{v("operationsOpen",_)},[v]);On(i,{onSwipeLeft:()=>o(!1)}),On(f,{onSwipeRight:()=>l(!1)});const j=n.useCallback(()=>{if(Fn(ad)){c(_=>!_);return}o(_=>!_)},[c]);n.useEffect(()=>{var y,u,g;const _=S=>{const D=r.current;if(!D)return;S.preventDefault();const L=Kr(D.panel,D.startSize,D.startClientX,D.startClientY,S.clientX,S.clientY,D.rootFontSize);s(G=>({...G,sizes:{...G.sizes,[D.panel]:L}}))},m=()=>{r.current=null};return(y=globalThis.window)==null||y.addEventListener("pointermove",_),(u=globalThis.window)==null||u.addEventListener("pointerup",m),(g=globalThis.window)==null||g.addEventListener("pointercancel",m),()=>{var S,D,L;(S=globalThis.window)==null||S.removeEventListener("pointermove",_),(D=globalThis.window)==null||D.removeEventListener("pointerup",m),(L=globalThis.window)==null||L.removeEventListener("pointercancel",m)}},[]);const C=n.useCallback((_,m)=>{var y,u;m.preventDefault(),(u=(y=m.currentTarget).setPointerCapture)==null||u.call(y,m.pointerId),r.current={panel:_,startSize:N[_],startClientX:m.clientX,startClientY:m.clientY,rootFontSize:od()}},[N]),b=n.useCallback((_,m)=>{m.preventDefault(),s(y=>({...y,sizes:{...y.sizes,[_]:qr(_,y.sizes[_],m.deltaY)}}))},[]);return{desktopTasksOpen:p,mobileTasksPanelOpen:a,mobileTasksPanelRef:i,operationsOpen:w,operationsPanelRef:f,panelResize:{sizes:{tasks:ns(N.tasks),operations:ns(N.operations),terminal:ns(N.terminal)},onPointerDown:C,onWheel:b},setMobileTasksPanelOpen:o,setOperationsOpen:l,toggleTasksPanel:j}}function ld(t,s){const a=s.taskId,o=s.updates;return typeof a!="string"||!o||typeof o!="object"?t:t.map(r=>r.id===a?{...r,...o}:r)}function dd({isLeader:t,selfId:s}){return{...!t&&s?{assignedTo:s}:{},completedLimitPerProject:Os}}function Ls(t){return`${t.assignedTo??"__unassigned__"}::${t.projectPath}`}function cd(t,s){const a=new Map(t.map(o=>[o.id,o]));for(const o of s)a.set(o.id,o);return Array.from(a.values())}function ud(t,s,a=new Set){return!s||a.has(s.id)||t.some(o=>o.id===s.id)?t:ma(t,s)}function md({isLeader:t,selfId:s,sseConnected:a,preservedTask:o,subscribe:r}){const[i,f]=n.useState([]),[p,w]=n.useState([]),[N,v]=n.useState(!0),[c,l]=n.useState(null),j=n.useRef(new Set),C=n.useRef(null),b=n.useCallback(async()=>{try{const u=await un(dd({isLeader:t,selfId:s}));f(ud(u.tasks,o,j.current)),w(u.completedGroups??[]),l(null)}catch(u){l(u instanceof Error?u.message:"Failed to load tasks")}finally{v(!1)}},[t,o,s]),_=n.useCallback(async u=>{if(!u.hasMore||!u.nextCursor)return;const g=await un({status:"completed",assignedTo:u.assignedTo??"__unassigned__",projectPath:u.projectPath,cursor:u.nextCursor,limit:Os});f(S=>cd(S,g.tasks)),w(S=>S.map(D=>Ls(D)===Ls(u)?{...D,returned:Math.min(D.total,D.returned+g.tasks.length),hasMore:g.hasMore===!0,nextCursor:g.nextCursor??null}:D))},[]),m=n.useCallback(()=>{C.current===null&&(C.current=window.setTimeout(()=>{C.current=null,b()},Hr))},[b]),y=n.useCallback(u=>{const g=new Set(u);if(g.size!==0){for(const S of g)j.current.add(S);f(S=>S.filter(D=>!g.has(D.id)))}},[]);return Wr(b,Yr(a)),n.useEffect(()=>()=>{C.current!==null&&(window.clearTimeout(C.current),C.current=null)},[]),n.useEffect(()=>{const u=[r("task.updated",g=>{f(S=>ld(S,g.data))}),r("task.status",g=>{f(S=>Gr(S,g.data))}),r("node",g=>{mn(g.type)&&m()}),r("task",g=>{if(g.type==="task.deleted"){const S=g.data.taskId;typeof S=="string"&&j.current.add(S),f(D=>Qr(D,g.data))}mn(g.type)&&m()})];return()=>u.forEach(g=>g())},[r,m]),{completedGroups:p,fetchTasks:b,loadCompletedTasksPage:_,removeTasksFromList:y,setTasks:f,tasks:i,tasksError:c,tasksLoading:N}}function Ca(t){return t.map(s=>({...s}))}function xd(t,s){const a=s.get(t);return{logs:a?Ca(a.logs):[],transcriptLoading:(a==null?void 0:a.loaded)!==!0}}function hd(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function fd({cluster:t,subscribe:s}){n.useEffect(()=>{var a;if(((a=t==null?void 0:t.self)==null?void 0:a.role)==="leader")return s("node",o=>{const r=String(o.data.name??o.data.nodeId??"node"),i=hd(t,o);o.type==="node.joined"&&!i&&ne.success(`${r} joined the cluster`),o.type==="node.left"&&!i&&ne.message(`${r} left the cluster`)})},[t,s])}const pd=[0,300,1e3,2e3];function gd({task:t,getActiveTaskId:s,setLogs:a,setPendingMessages:o,setTranscriptLoading:r}){t.conversationKind==="nativeSession"&&(async()=>{try{for(const i of pd){if(i>0&&await new Promise(f=>setTimeout(f,i)),s()!==t.id)return;try{const f=await ws(t.id);if(s()!==t.id||(a(p=>oa(p,f.logs)),o(p=>ys(p,f.logs)),f.total>0))return}catch{}}}finally{s()===t.id&&(r==null||r(!1))}})()}function bd(t,s){return Me(t??{})===Me(s??{})}function vd(t){return t&&"status"in t&&typeof t.status=="string"?t.status:void 0}function In(t,s){return{...t,enabled:!0,alwaysOnline:s}}function _a(t){var s,a;return((s=t==null?void 0:t.status)==null?void 0:s.trim())||((a=t==null?void 0:t.lastStatus)==null?void 0:a.trim())||"Unknown"}function jd({operationStarting:t,loading:s,refreshing:a,savedStatus:o,fallbackStatus:r}){return t?"Starting":s?"Listing DevBoxes":a?"Refreshing":o??r}function zn({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-full border border-border/70 bg-background/70 px-1.5 py-0.5 text-[10px] leading-none text-muted-foreground",children:_a(t)})]})}function wd({node:t,open:s,startInProgress:a=!1,onOpenChange:o,onRefresh:r}){const i=(t==null?void 0:t.id)??null,f=s&&!a&&Dn(t==null?void 0:t.status,(t==null?void 0:t.devbox)??null),[p,w]=n.useState([]),[N,v]=n.useState(()=>t!=null&&t.devbox?Me(t.devbox):""),[c,l]=n.useState(()=>(t==null?void 0:t.devbox)??null),[j,C]=n.useState(()=>An((t==null?void 0:t.devbox)??null)),[b,_]=n.useState(!1),[m,y]=n.useState(f),[u,g]=n.useState(!1),[S,D]=n.useState(!1),[L,G]=n.useState(()=>{var x;return((x=t==null?void 0:t.devbox)==null?void 0:x.alwaysOnline)===!0}),U=n.useMemo(()=>{const x=p.find(O=>Me(O)===N);return x||(kt(c)&&Me(c)===N?c:void 0)},[c,p,N]),F=vd(U??void 0),A=j?F??(c==null?void 0:c.lastStatus):(c==null?void 0:c.lastStatus)??F,ae=(t==null?void 0:t.status)==="online"||(t==null?void 0:t.status)==="busy"?"Running":"Unknown",W=S||a,M=jd({operationStarting:W,loading:b,refreshing:m,savedStatus:A,fallbackStatus:ae}),B=j&&!!U&&!bd(c,U),re=(c==null?void 0:c.alwaysOnline)===!0!==L,ee=Wl({nodeStatus:t==null?void 0:t.status,status:M,current:c,selected:U}),oe=!!ee,ie=!!U&&(B||re)&&!oe,V=U??c,z=n.useCallback(async()=>{if(i){y(!0);try{const x=await Xr(i);l(x.devbox),v(Me(x.devbox))}catch(x){ne.error(x instanceof Error?x.message:"Failed to refresh DevBox status")}finally{y(!1)}}},[i]),te=n.useCallback(async x=>{_(!0);try{const O=await Jr();w(O),v(Q=>Gl({previousKey:Q,baseDevBox:x,listed:O}))}catch(O){ne.error(O instanceof Error?O.message:"Failed to load DevBoxes")}finally{_(!1)}},[]);n.useEffect(()=>{if(!s||!i)return;let x=!1;const O=(t==null?void 0:t.devbox)??null,Q=An(O),me=!a&&Dn(t==null?void 0:t.status,O);_(!1),y(me),C(Q),l(O),G((O==null?void 0:O.alwaysOnline)===!0),v(kt(O)?Me(O):""),w([]);async function q(){me&&await z(),!x&&Q&&await te(O)}return q(),()=>{x=!0}},[te,t==null?void 0:t.devbox,t==null?void 0:t.status,i,s,z,a]);async function we(){C(!0),p.length===0&&await te(c)}async function h(){if(!(!t||!U)){g(!0);try{const x=await xn(t.id,In(U,L));l(x.node.devbox??null),x.node.devbox&&v(Me(x.node.devbox)),C(!1),ne.success(`Configured DevBox for ${t.name}`),await(r==null?void 0:r())}catch(x){ne.error(x instanceof Error?x.message:"Failed to configure DevBox")}finally{g(!1)}}}async function Y(){if(!(!t||!ee)){D(!0);try{if(U&&(B||re)){const O=await xn(t.id,In(U,L));l(O.node.devbox??null),O.node.devbox&&v(Me(O.node.devbox)),C(!1)}const{operation:x}=await ta(t.id);l(O=>O&&{...O,lastStatus:"Starting",checkedAt:Date.now(),operationId:x.id}),ne.success(`Start requested for ${t.name}`),await(r==null?void 0:r())}catch(x){ne.error(x instanceof Error?x.message:"Failed to start DevBox")}finally{D(!1)}}}const T=b?"Loading DevBoxes...":p.length===0?"No DevBoxes available":"Select a DevBox",J=M==="Running"&&(t==null?void 0:t.status)==="offline";return e.jsx(Ps,{open:s,onOpenChange:o,children:e.jsxs(Bs,{className:"max-w-md gap-4 rounded-lg p-5",children:[e.jsxs(Qn,{className:"space-y-1",children:[e.jsx(Rs,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(Zr,{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:[(j||V)&&e.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 rounded-xl border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:j?e.jsxs(Te,{value:N,onValueChange:v,disabled:b||u||S||p.length===0,children:[e.jsx(Ee,{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&&!U?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}),T]}):U?e.jsx(zn,{devbox:U}):e.jsx(Ue,{placeholder:T})}),e.jsx(De,{children:p.map(x=>e.jsx(ke,{value:Me(x),textValue:`${x.name} ${x.projectName??""} ${_a(x)}`,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(zn,{devbox:x,showStatus:!0})},Me(x)))})]}):V&&e.jsxs("div",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:V.name}),V.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",V.projectName]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Ye,{variant:"outline",className:"rounded-full px-2 py-0.5 text-[10px]",children:[(b||m)&&e.jsx(xe,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),M]}),(c==null?void 0:c.name)&&e.jsx(I,{type:"button",variant:"ghost",size:"icon",onClick:()=>{we()},disabled:b||u||W||j,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-full text-muted-foreground hover:text-foreground",children:b&&j?e.jsx(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(Ct,{className:"h-3 w-3"})})]})]}),J&&e.jsx("div",{className:"rounded-xl 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-xl border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(js,{checked:L,onCheckedChange:x=>G(x===!0),disabled:u||S||W,"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(Yn,{className:"gap-2 sm:space-x-0",children:[e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>o(!1),disabled:u||S,className:"h-8 rounded-xl text-xs",children:"Close"}),oe&&e.jsxs(I,{size:"sm",onClick:Y,disabled:S,className:"h-8 rounded-xl text-xs",children:[S?e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Is,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!oe&&e.jsxs(I,{size:"sm",onClick:h,disabled:!ie||u,className:"h-8 rounded-xl text-xs",children:[u&&e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function Nd(t,s=eo){if(t.length===0)return new Set;const a=new Set(t),[o,r]=await Promise.all([s({kind:"devbox.start",status:"queued"}),s({kind:"devbox.start",status:"running"})]);return new Set([...o,...r].filter(i=>a.has(i.nodeId)).map(i=>i.nodeId))}function yd({cluster:t,refresh:s}){const[a,o]=n.useState(null),[r,i]=n.useState(null),[f,p]=n.useState(()=>new Set),[w,N]=n.useState(()=>new Set),v=n.useMemo(()=>(t==null?void 0:t.nodes.find(m=>m.id===a))??null,[t==null?void 0:t.nodes,a]),c=n.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(m=>{var y;return(y=m.devbox)==null?void 0:y.enabled}).map(m=>m.id)),[t==null?void 0:t.nodes]),l=n.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(m=>{var y;return Qt(m.status,(y=m.devbox)==null?void 0:y.lastStatus,m.devbox)}).map(m=>m.id)),[t==null?void 0:t.nodes]),j=n.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(m=>{var y;return St((y=m.devbox)==null?void 0:y.lastStatus)}).map(m=>m.id)),[t==null?void 0:t.nodes]),C=n.useMemo(()=>{const m=new Set(f);r&&m.add(r);for(const y of w)m.add(y);for(const y of j)m.add(y);return m},[w,r,f,j]);n.useEffect(()=>{let m=!1;const y=[...c];async function u(){try{const g=await Nd(y);m||N(g)}catch{m||N(new Set)}}return u(),()=>{m=!0}},[c]),n.useEffect(()=>{p(m=>{var g;let y=!1;const u=new Set(m);for(const S of m){const D=t==null?void 0:t.nodes.find(L=>L.id===S);(D==null?void 0:D.status)!=="online"&&(!((g=D==null?void 0:D.devbox)!=null&&g.lastStatus)||St(D.devbox.lastStatus))||(u.delete(S),y=!0)}return y?u:m})},[t==null?void 0:t.nodes]);const b=n.useCallback(async m=>{const y=t==null?void 0:t.nodes.find(u=>u.id===m);if(y){i(m),p(u=>new Set(u).add(m));try{await ta(m),ne.success(`Start requested for ${y.name}`),s()}catch(u){p(g=>{const S=new Set(g);return S.delete(m),S}),ne.error(u instanceof Error?u.message:"Failed to start DevBox")}finally{i(null)}}},[t==null?void 0:t.nodes,s]);return{devBoxDialog:e.jsx(wd,{node:v,open:a!==null,startInProgress:v?C.has(v.id):!1,onOpenChange:m=>{m||o(null)},onRefresh:s}),devBoxNodeIds:c,devBoxStartNodeId:r,devBoxStartNodeIds:l,devBoxStartingNodeIds:C,openDevBox:o,startDevBox:b}}function kd(t){const[s,a]=n.useState(null),o=n.useCallback(i=>{t&&a(i)},[t]);return{nodeSettingsDialog:e.jsx(to,{open:s!==null,onOpenChange:i=>{i||a(null)},initialSelectedNodeId:s??void 0,showTrigger:!1}),openNodeSettings:o}}function Sd({activeTaskId:t,fetchActiveTask:s,setPendingMessages:a,setTask:o,setTasks:r}){const i=n.useCallback((w,N)=>{o(v=>v&&v.id===w?{...v,queuedMessages:N}:v),r(v=>v.map(c=>c.id===w?{...c,queuedMessages:N}:c))},[o,r]),f=n.useCallback(async w=>{if(!t)return!1;const N=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`;a(v=>[...v,{id:N,content:w,timestamp:new Date().toISOString()}]);try{const v=await so(t,w);return v.queued&&(a(c=>c.filter(l=>l.id!==N)),v.queuedMessages&&i(t,v.queuedMessages)),s(),!0}catch(v){return a(c=>c.filter(l=>l.id!==N)),ne.error(v instanceof Error?v.message:"Failed to send message"),!1}},[t,s,a,i]);return{cancelQueuedMessage:n.useCallback(async w=>{if(t)try{const N=await no(t,w);i(t,N.queuedMessages),s()}catch(N){ne.error(N instanceof Error?N.message:"Failed to cancel queued message")}},[t,s,i]),queueFollowUpMessage:f}}function Cd(){var Js,Zs,en,tn,sn,nn;const{id:t}=ao(),s=ro(),a=oo(),o=io(),{cluster:r,systemInfo:i,events:f,sseConnected:p,subscribe:w,refresh:N,loading:v,error:c}=lo(),l=n.useMemo(()=>co(s.state),[s.state]),[j,C]=n.useState(null),[b,_]=n.useState("active"),[m,y]=n.useState("all"),[u,g]=n.useState("all"),[S,D]=n.useState("all"),[L,G]=n.useState(""),U=(o==null?void 0:o.headerSearchQuery)??L,F=(o==null?void 0:o.setHeaderSearchQuery)??G,A=n.useDeferredValue(U),{desktopTasksOpen:ae,mobileTasksPanelOpen:W,mobileTasksPanelRef:M,operationsOpen:B,operationsPanelRef:re,panelResize:ee,setMobileTasksPanelOpen:oe,setOperationsOpen:ie,toggleTasksPanel:V}=id(),[z,te]=n.useState(()=>!!(l!=null&&l.draftNewTask)),[we,h]=n.useState(()=>(l==null?void 0:l.createMode)??"chat"),[Y,T]=n.useState(()=>(l==null?void 0:l.createDefaults)??null),[J,x]=n.useState(()=>l!=null&&l.draftNewTask?{route:l.returnRoute??"/",taskId:l.returnTaskId??null}:null),[O,Q]=n.useState(!1),[me,q]=n.useState("transcript"),[X,se]=n.useState("all"),[Se,P]=n.useState(!1),[H,Ne]=n.useState(null),[Re,Ve]=n.useState([]),[Je,ye]=n.useState([]),[Z,he]=n.useState(!1),[Le,$e]=n.useState(!1),[qe,le]=n.useState(null),[Pe,Ge]=n.useState(new Set),[at,Ze]=n.useState(!1),[Tt,pt]=n.useState(!1),[gt,rt]=n.useState(null),Oe=n.useRef(null),ut=n.useRef(new Map),Ce=((Js=r==null?void 0:r.self)==null?void 0:Js.role)==="leader",mt=(Zs=r==null?void 0:r.self)==null?void 0:Zs.id;fd({cluster:r,subscribe:w});const{nodeSettingsDialog:Et,openNodeSettings:E}=kd(Ce),{devBoxDialog:be,devBoxNodeIds:fe,devBoxStartNodeId:Fe,devBoxStartNodeIds:Ke,devBoxStartingNodeIds:lt,openDevBox:Ae,startDevBox:Ie}=yd({cluster:r,refresh:N}),{completedGroups:dt=[],fetchTasks:_e,loadCompletedTasksPage:Qe,removeTasksFromList:bt,setTasks:ve,tasks:ce,tasksError:pe,tasksLoading:et}=md({isLeader:Ce,selfId:mt,sseConnected:p,preservedTask:H,subscribe:w}),ze=n.useMemo(()=>[...ce].sort((d,k)=>k.updatedAt-d.updatedAt),[ce]),He=n.useMemo(()=>{var d;return((d=[...ce].sort((k,R)=>R.createdAt-k.createdAt||R.updatedAt-k.updatedAt)[0])==null?void 0:d.id)??null},[ce]),Dt=n.useMemo(()=>{const d=new Map;for(const k of(r==null?void 0:r.nodes)??[]){const R=Si(ze,k.id);R>0&&d.set(k.id,R)}return d},[r==null?void 0:r.nodes,ze]),tt=n.useMemo(()=>ze.filter(d=>!uo(d,r==null?void 0:r.nodes,r==null?void 0:r.self)||!mo(d,b)||m!=="all"&&d.agent!==m||!xo(d,S)||u==="unassigned"&&d.assignedTo||u!=="all"&&u!=="unassigned"&&ho(d.assignedTo,r==null?void 0:r.nodes,d.assignedNodeName)!==u?!1:A.trim()?fo(d,A):!0),[ze,r==null?void 0:r.nodes,r==null?void 0:r.self,b,m,S,u,A]);n.useEffect(()=>{Ge(d=>{const k=Ai(d,tt.map(R=>R.id));return k.size===d.size?d:k})},[tt]),n.useEffect(()=>{Ce||Ge(new Set)},[Ce]);const Ta=n.useMemo(()=>["all",...Array.from(new Set(ze.map(d=>d.agent))).sort()],[ze]),Ea=n.useMemo(()=>{const k=Array.from(new Set(ze.map(R=>R.assignedTo).filter(R=>!!R))).map(R=>{const ge=ze.find(de=>de.assignedTo===R);return(r==null?void 0:r.nodes.find(de=>de.id===R))??{id:R,name:us(R,r==null?void 0:r.nodes,ge==null?void 0:ge.assignedNodeName)}}).sort((R,ge)=>R.name.localeCompare(ge.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...k.map(R=>({value:R.name.toLowerCase(),label:R.name}))]},[ze,r==null?void 0:r.nodes]),Gs=n.useMemo(()=>{const d=new Map;for(const k of(r==null?void 0:r.nodes)??[])d.set(k.id,k.name);for(const k of ze)k.assignedTo&&k.assignedNodeName&&!d.has(k.assignedTo)&&d.set(k.assignedTo,k.assignedNodeName);return d},[r==null?void 0:r.nodes,ze]),Da=n.useMemo(()=>{var k;const d=new Map;for(const R of(r==null?void 0:r.nodes)??[])R.workDir&&d.set(R.id,R.workDir);return(k=r==null?void 0:r.self)!=null&&k.workDir&&d.set(r.self.id,r.self.workDir),d},[r]),Aa=n.useMemo(()=>{const d=new Map;for(const k of(r==null?void 0:r.nodes)??[])d.set(k.id,k.status);return r!=null&&r.self&&d.set(r.self.id,r.self.status),d},[r]),Ma=n.useMemo(()=>new Map(dt.map(d=>[Ls(d),d])),[dt]),Qs=n.useMemo(()=>{const d=new Map;for(const k of(r==null?void 0:r.nodes)??[])k.status!=="offline"&&d.set(k.id,k);return r!=null&&r.self&&r.self.status!=="offline"&&d.set(r.self.id,r.self),Array.from(d.values())},[r]),La=((en=r==null?void 0:r.self)==null?void 0:en.id)??((tn=Qs[0])==null?void 0:tn.id)??null,Yt=n.useMemo(()=>["all",...Array.from(new Set(f.map(d=>d.type))).sort()],[f]),Pa=n.useMemo(()=>X==="all"?f:f.filter(d=>d.type===X),[f,X]),Ba=tt.length>0&&tt.every(d=>Pe.has(d.id)),Ra=tt.some(d=>Pe.has(d.id)),$a=Mi(tt,Pe);n.useEffect(()=>{l!=null&&l.draftNewTask&&(te(!0),h(l.createMode??"chat"),T(l.createDefaults??null),x({route:l.returnRoute??"/",taskId:l.returnTaskId??null}))},[l]),n.useEffect(()=>{X!=="all"&&!Yt.includes(X)&&se("all")},[X,Yt]),n.useEffect(()=>{wn(t,z)&&!j&&He&&C(He)},[t,z,j,He]),n.useEffect(()=>{wn(t,z)&&(j&&ce.some(d=>d.id===j)||C(He))},[t,z,j,He,ce]);const ue=_i({routeTaskId:t,creatingTask:z,internalSelectedTaskId:j,sortedTaskIds:He?[He]:[]}),vt=n.useMemo(()=>ce.find(d=>d.id===ue)??null,[ce,ue]);n.useEffect(()=>{Oe.current=ue??null},[ue]);const ct=n.useCallback(()=>{Ne(null),Ve([]),ye([]),le(null),$e(!1)},[]),At=n.useCallback((d,k,R=!0)=>{ut.current.set(d,{logs:Ca(k),loaded:R})},[]),We=n.useCallback(async()=>{const d=ue;if(d)try{const k=await po(d);if(Oe.current!==d)return;Ne(k),ve(R=>ma(R,k)),le(null)}catch(k){if(Oe.current!==d)return;ct(),le(k instanceof Error?k.message:"Failed to load task")}finally{Oe.current===d&&he(!1)}},[ue,ct,ve]),Ot=n.useCallback(async()=>{const d=ue;if(d)try{const k=await ws(d);if(Oe.current!==d)return;Ve(R=>{const ge=oa(R,k.logs);return At(d,ge),ge}),ye(R=>ys(R,k.logs))}catch{}finally{Oe.current===d&&$e(!1)}},[ue,At]);n.useEffect(()=>{if(!ue){ct(),he(!1);return}q("transcript"),Ne(vt);const d=xd(ue,ut.current);Ve(d.logs),ye([]),le(null),he(!0),$e(d.transcriptLoading),We(),Ot()},[ue,ct,Ot,We]),n.useEffect(()=>{if(!Ti({activeTaskId:ue,routeTaskId:t,creatingTask:z,tasksLoading:et,loadedTaskIds:ce.map(k=>k.id)}))return;const d=He;C(d),ct(),n.startTransition(()=>{a(d?`/tasks/${d}`:"/",{state:null})})},[ue,ct,z,He,a,t,ce,et]),n.useEffect(()=>{vt&&Ne(d=>!d||d.id!==vt.id?d:{...d,...vt})},[vt]),n.useEffect(()=>{if(ue)return w("task",d=>{const k=d.data.taskId;if(!(typeof k!="string"||k!==ue)){if(d.type==="task.output"){const R=d.data.event;if(R){Ve(de=>{const Lt=Lo(de,R);return At(ue,Lt),Lt}),$e(!1);const ge=bn(R);ge&&ye(de=>Po(de,ge))}}d.type==="task.updated"&&We(),d.type==="task.status"&&(We(),Ot())}})},[w,ue,We,Ot]);const K=H??vt,Oa=K!=null&&K.assignedTo?(r==null?void 0:r.nodes.find(d=>d.id===K.assignedTo))??null:null,Mt=o==null?void 0:o.setHeaderTaskContext;n.useEffect(()=>{if(!Mt)return;if(!K){Mt(null);return}const d=K.effectiveProjectPath??K.project??"default workspace";return Mt({taskId:K.id,taskTitle:K.title,nodeName:us(K.assignedTo,r==null?void 0:r.nodes,K.assignedNodeName),projectLabel:ea(d),projectPath:d}),()=>Mt(null)},[K,r==null?void 0:r.nodes,Mt]);const Xt=Je.length>0,Fa=K?go.has(K.agent):!1,Jt=(K==null?void 0:K.status)==="running",Ia=K?Ht.has(K.status):!1,za=K?Ht.has(K.status)||bo.has(K.status):!1,Ua=!!(K&&Ce&&K.status==="failed"),Zt=n.useMemo(()=>Xl(K,r,Xt,!!Jt),[K,r,Xt,Jt]),es=n.useMemo(()=>Bo([...Re,...Je.map(d=>rs(d.content,d.timestamp))]),[Re,Je]),Ft=n.useMemo(()=>{if(!K||K.conversationKind==="nativeSession")return null;const d=Ro(K);if(d.length>0)return rs(d,new Date(K.createdAt).toISOString());if(es.length>0)return null;const k=$o(K.description||K.title);return k.length>0?rs(k,new Date(K.createdAt).toISOString()):null},[K,es]),ts=n.useMemo(()=>Ft?bn(Ft):null,[Ft]),Va=n.useMemo(()=>ts?Oo(Re,ts):!1,[Re,ts]),ss=n.useCallback((d="chat",k)=>{const R={route:t?`/tasks/${t}`:"/",taskId:ue};x(R),h(d),T(k??null),te(!0),n.startTransition(()=>{a("/",{state:{draftNewTask:!0,returnRoute:R.route,returnTaskId:R.taskId,createMode:d,createDefaults:k}})})},[t,ue,a]),qa=n.useCallback(()=>{const d=(J==null?void 0:J.taskId)??He;te(!1),x(null),T(null),C(d),n.startTransition(()=>{a((J==null?void 0:J.route)??"/",{state:null})})},[J,He,a]),Ys=n.useCallback(d=>{te(!1),x(null),T(null),C(d),n.startTransition(()=>{a(`/tasks/${d}`,{state:null})})},[a]),Ka=n.useCallback(d=>{Oe.current=d.id,te(!1),x(null),T(null),ve(k=>Ei(k,d)),Ne(d),Ve([]),ye([]),le(null),he(!1),$e(d.conversationKind==="nativeSession"),q("transcript"),C(d.id),gd({task:d,getActiveTaskId:()=>Oe.current,setLogs:Ve,setPendingMessages:ye,setTranscriptLoading:$e}),_e(),n.startTransition(()=>{a(`/tasks/${d.id}`,{state:null})})},[_e,a]),{cancelQueuedMessage:Ha,queueFollowUpMessage:It}=Sd({activeTaskId:ue,fetchActiveTask:We,setPendingMessages:ye,setTask:Ne,setTasks:ve}),Wa=n.useCallback(d=>{It(d)},[It]),Ga=n.useCallback(async()=>{const d=ue;if(!(!d||(K==null?void 0:K.conversationKind)!=="nativeSession")){$e(!0);try{const k=await ws(d);if(Oe.current!==d)return;Ve(k.logs),At(d,k.logs),ye(R=>ys(R,k.logs))}catch(k){ne.error(k instanceof Error?k.message:"Failed to reload transcript")}finally{Oe.current===d&&$e(!1)}}},[K==null?void 0:K.conversationKind,ue,At]),Qa=n.useCallback(d=>It(d),[It]),Ya=n.useCallback(async()=>{if(K)try{await vo(K.id),We(),_e()}catch(d){ne.error(d instanceof Error?d.message:"Failed to cancel task")}},[K,We,_e]),{handleShareTask:Xa,handleStopShareTask:Ja}=nd(K,We,_e),Za=n.useCallback(async()=>{if(K)try{await jo(K.id),We(),_e()}catch(d){ne.error(d instanceof Error?d.message:"Failed to retry task")}},[K,We,_e]),zt=n.useCallback((d,k=!1)=>{const R=Li(tt,d);return C(R),(k||!R)&&ct(),n.startTransition(()=>{a(R?`/tasks/${R}`:"/",{state:null})}),R},[ct,tt,a]),er=n.useCallback((d,k)=>{Ge(R=>{const ge=new Set(R);return k?ge.add(d):ge.delete(d),ge})},[]),tr=n.useCallback(d=>{if(!d){Ge(new Set);return}Ge(new Set(tt.map(k=>k.id)))},[tt]),sr=n.useCallback(async()=>{const d=Array.from(Pe);if(d.length!==0)try{const{results:k}=await wo(d),R=k.filter(de=>!de.ok),ge=k.filter(de=>de.ok).map(de=>de.id);ue&&ge.includes(ue)&&zt(ge),R.length>0?ne.error(`Failed to archive ${R.length} task(s): ${R.map(de=>de.error??de.id).join(", ")}`):ne.success(`Archived ${ge.length} task(s)`),Ge(new Set(R.map(de=>de.id))),_e()}catch(k){ne.error(k instanceof Error?k.message:"Failed to archive tasks")}},[ue,_e,zt,Pe]),nr=n.useCallback(async()=>{const d=Array.from(Pe);if(d.length!==0)try{const{results:k}=await No(d),R=k.filter(de=>!de.ok),ge=k.filter(de=>de.ok).map(de=>de.id);ge.length>0&&bt(ge),ue&&ge.includes(ue)&&zt(ge,!0),R.length>0?ne.error(`Failed to delete ${R.length} task(s): ${R.map(de=>de.error??de.id).join(", ")}`):ne.success(`Deleted ${ge.length} task(s)`),Ge(new Set(R.map(de=>de.id))),_e()}catch(k){ne.error(k instanceof Error?k.message:"Failed to delete tasks")}},[ue,_e,zt,bt,Pe]),ar=n.useCallback(async()=>{Ze(!0);try{await yo(),N()}catch(d){ne.error(d instanceof Error?d.message:"Failed to promote node")}finally{Ze(!1)}},[N]),rr=n.useCallback(async()=>{pt(!0);try{await ko(),ne.success("This node left the remote cluster and is leading itself again."),_e(),We(),N()}catch(d){ne.error(d instanceof Error?d.message:"Failed to leave cluster")}finally{pt(!1)}},[We,_e,N]),or=n.useCallback(async d=>{var Lt;const k=!qs(d),R=d.id===((Lt=r==null?void 0:r.self)==null?void 0:Lt.id),ge=R?(i==null?void 0:i.transportType)??d.transportType:d.transportType,de=R&&!k&&_t(ge);rt(d.id);try{de?await So("direct"):await Co(d.id,k),ne.success(k?`Enabled remote access on ${d.name}`:`Disabled remote access on ${d.name}`),N()}catch(an){ne.error(an instanceof Error?an.message:"Failed to update remote access")}finally{rt(null)}},[(sn=r==null?void 0:r.self)==null?void 0:sn.id,N,i==null?void 0:i.transportType]),ir=n.useCallback(d=>{Qe&&Qe(d).catch(k=>{ne.error(k instanceof Error?k.message:"Failed to load completed tasks")})},[Qe]),Xs={toolbarTasks:tt,activeTaskId:ue,tasksLoading:et,tasksError:pe,isLeader:Ce,scope:b,agentFilter:m,nodeFilter:u,taskKindFilter:S,agentOptions:Ta,nodeOptions:Ea,nodeNameById:Gs,nodeWorkDirById:Da,nodeStatusById:Aa,leaderNodeId:((nn=r==null?void 0:r.leader)==null?void 0:nn.id)??null,searchQuery:U,completedGroupByKey:Ma,devBoxNodeIds:fe,devBoxStartNodeIds:Ke,devBoxStartingNodeIds:lt,selectedTaskIds:Pe,allVisibleTasksSelected:Ba,someVisibleTasksSelected:Ra,canBatchArchive:$a,onSearchChange:F,onScopeChange:_,onAgentFilterChange:y,onNodeFilterChange:g,onTaskKindFilterChange:D,onToggleTaskSelected:er,onToggleAllVisibleTasks:tr,onBatchArchive:sr,onBatchDelete:nr,onCreateTask:ss,onOpenNodeSettings:Ce?E:void 0,onOpenDevBox:Ce?Ae:void 0,onStartDevBox:Ce?Ie:void 0,onLoadCompletedTasks:ir,onSelectTask:Ys,onClose:V},lr={cluster:r,systemInfo:i,nodeNameById:Gs,nodeBlockingTaskCounts:Dt,eventTypeFilter:X,onEventTypeFilterChange:se,eventTypeOptions:Yt,filteredEvents:Pa,sseConnected:p,clusterLoading:v,clusterError:c,promotePending:at,onPromote:ar,onAddNode:()=>Q(!0),leavePending:Tt,onLeaveCluster:rr,onToggleNodeDevTunnel:or,devTunnelNodeId:gt,devBoxStartNodeId:Fe,devBoxStartingNodeIds:lt,onOpenNodeSettings:Ce?E:void 0,onOpenDevBox:Ce?Ae:void 0,onStartDevBox:Ce?Ie:void 0,onClose:()=>ie(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Bl,{desktopTasksOpen:ae,mobileTasksPanelOpen:W,mobileTasksPanelRef:M,operationsOpen:B,operationsPanelRef:re,panelResize:ee,taskSidebar:e.jsx($n,{...Xs}),operationsSidecar:e.jsx(Ql,{...lr}),terminalPanel:o!=null&&o.terminalOpen?e.jsx(Vl,{nodes:Qs,defaultNodeId:La,onClose:()=>o==null?void 0:o.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(Al,{onToggleTasks:V,desktopTasksOpen:ae,mobileTasksPanelOpen:W,operationsOpen:B,onToggleOperations:()=>ie(d=>!d),cluster:r,sseConnected:p,activeTab:me,setActiveTab:q,creatingTask:z,createMode:we,createDefaults:Y,activeTask:K,assignedNode:Oa,taskLoading:Z,transcriptLoading:Le,taskError:qe,displayEvents:es,initialPromptAlreadyInLogs:Va,initialPrompt:Ft,supportsFollowUp:Fa,taskUnavailable:Zt.taskUnavailable,chatDisabled:Zt.chatDisabled,chatDisabledReason:Zt.chatDisabledReason,questionBypassEnabled:Se,isRunning:!!Jt,isStarting:Ia,hasPendingFollowUp:Xt,canCancel:!!za,canRetry:!!Ua,onRetry:Za,onCancel:Ya,onReloadNativeTranscript:Ga,onShareTask:Xa,onStopShareTask:Ja,onStartCreateTask:ss,onCancelCreateTask:qa,onCreateTask:Ka,onSendMessage:Wa,onCancelQueuedMessage:Ha,onQuestionBypassChange:P,onSubmitQuestionResponse:Qa}),mobileTaskSidebar:e.jsx($n,{...Xs,onCreateTask:(d,k)=>{oe(!1),ss(d,k)},onSelectTask:d=>{oe(!1),Ys(d)},onClose:()=>oe(!1)}),onCloseOperations:()=>ie(!1),onCloseTaskList:()=>oe(!1)}),e.jsx(Pl,{open:O,onOpenChange:Q,onAdded:N}),Et,be]})}const Dd=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:Cd},Symbol.toStringTag,{value:"Module"}));export{Dd as D,ks as G};
|