meshy-node 0.8.10 → 0.9.0

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