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