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