meshy-node 0.6.4 → 0.6.6

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