meshy-node 0.3.3 → 0.3.5

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