meshy-node 0.3.9 → 0.4.0

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