meshy-node 0.4.0 → 0.4.2

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