meshy-node 0.3.6 → 0.3.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meshy-node",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "private": false,
5
5
  "description": "Standalone Meshy node package with bundled runtime and dashboard assets.",
6
6
  "type": "commonjs",
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "packageName": "meshy-node",
3
- "packageVersion": "0.3.6",
3
+ "packageVersion": "0.3.8",
4
4
  "packages": {
5
5
  "workspace": {
6
6
  "name": "meshy",
7
- "version": "0.3.6"
7
+ "version": "0.3.8"
8
8
  },
9
9
  "node": {
10
10
  "name": "meshy-node",
11
- "version": "0.3.6"
11
+ "version": "0.3.8"
12
12
  },
13
13
  "core": {
14
14
  "name": "@meshy/core",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "repository": {
27
27
  "url": "https://github.com/ai-microsoft/meshy",
28
- "branch": "Beautify",
29
- "commit": "5afb7ee"
28
+ "branch": "supportTerminal",
29
+ "commit": "373ec48"
30
30
  }
31
31
  }
@@ -1,119 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-JtS0K69s.js","assets/index-CTmXIGF9.js","assets/index-BZEpNAD0.css","assets/folder-BgNe6kvb.js","assets/file-DEAybfOx.js","assets/PreviewTab-DjvNLJqk.js","assets/input-zoVCGkkt.js","assets/DiffTab-D32e4GZ0.js","assets/DashboardShared-CsdH5gbQ.js"])))=>i.map(i=>d[i]);
2
- import{c as he,r as s,j as e,a as Ia,b as A,d as $a,e as Ba,D as ys,f as Oa,g as ws,B as Pe,h as za,i as L,X as Ue,k as Ua,l as Va,C as He,m as Ka,n as qa,F as Ha,S as me,o as Ze,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 st,T as zt,z as Cs,A as Ja,E as Ya,G as Ss,H as _s,I as We,J as Es,K as Ts,L as Ds,P as Xa,M as Ms,N as Oe,O as Qa,Q as ze,R as kt,U as yt,V as wt,W as Ct,Y as St,Z as _t,_ as Et,$ as Tt,a0 as Ut,a1 as Za,a2 as er,a3 as tr,a4 as As,a5 as Ls,a6 as Ps,a7 as sr,a8 as ct,a9 as ar,aa as Vt,ab as rr,ac as Rs,ad as os,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 mr,an as hr,ao as ls,ap as pr,aq as fr,ar as br,as as gr,at as Fs,au as vr,av as jr,aw as Nr,ax as kr,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,aO as Br}from"./index-CTmXIGF9.js";import{r as is,e as Or,b as Is,t as $s,L as ve,C as ds,a as zr,T as jt,D as qe,I as Le,M as Dt,c as Bs,m as Os,d as zs,f as Ur,g as cs,h as Vr,i as Kr,j as Nt,k as qr,n as Hr,l as Wr}from"./DashboardShared-CsdH5gbQ.js";import{I as Ie}from"./input-zoVCGkkt.js";import{F as Gr,C as et}from"./folder-BgNe6kvb.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 Jr=[["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"}]],Yr=he("archive",Jr);/**
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 Xr=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Qr=he("arrow-up",Xr);/**
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 Zr=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],en=he("flag",Zr);/**
18
- * @license lucide-react v1.7.0 - ISC
19
- *
20
- * This source code is licensed under the ISC license.
21
- * See the LICENSE file in the root directory of this source tree.
22
- */const tn=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],sn=he("funnel",tn);/**
23
- * @license lucide-react v1.7.0 - ISC
24
- *
25
- * This source code is licensed under the ISC license.
26
- * See the LICENSE file in the root directory of this source tree.
27
- */const an=[["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",an);/**
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 rn=[["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"}]],nn=he("globe",rn);/**
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 on=[["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",on);/**
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 ln=[["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",ln);/**
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 dn=[["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"}]],cn=he("laptop",dn);/**
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 un=[["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",un);/**
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 xn=[["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",xn);/**
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 mn=[["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",mn);/**
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"}]],pn=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 fn=[["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",fn);/**
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 bn=[["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",bn);/**
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 gn=[["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",gn);/**
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 vn=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],jn=he("plus",vn);/**
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 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"}]],kn=he("rotate-ccw",Nn);/**
93
- * @license lucide-react v1.7.0 - ISC
94
- *
95
- * This source code is licensed under the ISC license.
96
- * See the LICENSE file in the root directory of this source tree.
97
- */const yn=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Lt=he("search",yn);/**
98
- * @license lucide-react v1.7.0 - ISC
99
- *
100
- * This source code is licensed under the ISC license.
101
- * See the LICENSE file in the root directory of this source tree.
102
- */const wn=[["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",wn);/**
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 Cn=[["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"}]],Sn=he("share-2",Cn);/**
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 _n=[["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"}]],En=he("sliders-horizontal",_n);/**
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 Tn=[["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"}]],Dn=he("trash-2",Tn),Mn=new Set(["assigned","running"]);function An(t,a){return t.reduce((r,n)=>n.assignedTo===a&&Mn.has(n.status)?r+1:r,0)}function Je(t){return(t==null?void 0:t.toLowerCase())==="devtunnel"}function Ln(t){return t?Je(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function Wt(t,a){return Je(a??t.transportType)||!!t.devtunnelEndpoint}function qs(t,a){return!Je(a??t.transportType)}function Hs(t,a){const r=a??t.transportType;return Je(r)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":Ln(r)}function xs(t,a){return!t&&!a}function Pn({routeTaskId:t,creatingTask:a,internalSelectedTaskId:r,sortedTaskIds:n}){return t||(a?null:r??n[0]??null)}function Rn(t,a){return[a,...t.filter(r=>r.id!==a.id)]}function Fn(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 In=new Set(["completed","failed","cancelled","archived"]);function $n(t,a){const r=new Set(a);return new Set(Array.from(t).filter(n=>r.has(n)))}function Bn(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=>In.has(d.status))}function On(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 zn=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Un=zn.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}},{}),Vn="Label",Ws=s.forwardRef((t,a)=>e.jsx(Un.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=Vn;var Gs=Ws;const Kn=$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:A(Kn(),t),...a}));Se.displayName=Gs.displayName;function qn({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(L,{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(h=>[...h,...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=Or(v.clipboardData);if(l.length!==0){v.preventDefault();try{const c=await is(l);a(h=>[...h,...c]),n(null)}catch(c){n(c instanceof Error?c.message:"Failed to attach image")}}},[]),p=s.useCallback(v=>{a(l=>l.filter((c,h)=>h!==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 Hn({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:h,handleFileChange:k,handlePaste:S,removeImage:w,clearImages:y}=Js(),N=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(),N())},[f,v,a,t,y,N]),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),P=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:k,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(Ue,{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(L,{type:"button",variant:"ghost",onClick:h,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(L,{onClick:o?u:X,disabled:o?!P:!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 Wn(t,a,r){return t!=="auto"?a.find(n=>n.id===t)??null:r.length===1?r[0]??null:null}function Gn(t){return t.trim()||"."}function Jn(t){return new Promise(a=>window.setTimeout(a,t))}function Yn(t){return!!t&&typeof t=="object"&&typeof t.createdBranch=="string"&&typeof t.currentBranch<"u"}async function Xn(t){let a=t;for(let r=0;r<60;r++){if(a.status==="succeeded"){if(Yn(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 Jn(1e3),a=await Ka(a.id)}throw new Error("Timed out waiting for branch creation")}function ms({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,h]=s.useState(!1),[k,S]=s.useState(null),[w,y]=s.useState(""),[N,X]=s.useState(!1),[O,T]=s.useState(!1),[ee,P]=s.useState(!1),[U,D]=s.useState(null),[B,pe]=s.useState(""),[E,V]=s.useState(""),[W,R]=s.useState(""),[de,K]=s.useState(!1),q=s.useRef(null),re=s.useRef(0),ce=s.useMemo(()=>Wn(n,d,o),[n,d,o]),I=ce==null?void 0:ce.id,Q=s.useMemo(()=>Gn(r),[r]),le=s.useMemo(()=>I?`${I}
118
- ${Q}`:"",[I,Q]),ne=s.useCallback(async(m=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:m,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 m=t.trim(),_=w===le?k:null,$=_!=null&&_.available&&_.currentBranch?_.currentBranch:"";m!==$&&a($)},[k,le,w,a,t]),s.useEffect(()=>{if(!c)return;const m=$=>{q.current&&(q.current.contains($.target)||h(!1))},_=$=>{$.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",_),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",_)}},[c]),s.useEffect(()=>{c&&(V(""),R(""),K(!1))},[c,I,Q]);const ie=s.useCallback(async()=>{if(!I)return;const m=B.trim(),_=de?W.trim():E.trim();if(!(!m||!_)){P(!0),D(null);try{const $=await Va(I,{path:Q,branchName:m,startPoint:_,limit:20,offset:0,allowAbsolute:!0}),j=await Xn($);y(le),S(j),a(j.currentBranch??j.createdBranch),pe(""),V(""),R(""),K(!1),h(!1)}catch($){D($ instanceof Error?$.message:"Failed to create branch")}finally{P(!1)}}},[I,le,Q,de,W,B,a,E]),x=w===le?k: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?W.trim():E.trim(),oe=!!(x!=null&&x.available&&B.trim()&&be&&!ee),je=u==="composer"?e.jsxs(L,{type:"button",variant:"ghost",onClick:()=>h(m=>!m),title:F,"aria-label":`Branch: ${F}`,className:A(f,l,"min-w-0 max-w-full",t.trim()?p:g),children:[N&&!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:A("min-w-0 truncate",v),children:F})]}):e.jsxs(L,{type:"button",variant:"outline",onClick:()=>h(m=>!m),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:F,children:[e.jsx("span",{className:A("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:A("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:A("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}),N?e.jsx(ve,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),ce?N&&!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:m=>pe(m.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(L,{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(jn,{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:W,onChange:m=>R(m.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{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(Ue,{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(m=>{const _=E===m.ref,$=m.branch==="main"||m.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>V(m.ref),className:A("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:m.ref,children:[e.jsx("span",{className:A("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:m.ref}),_?e.jsx(He,{className:"h-3 w-3 shrink-0 text-primary"}):null]},m.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 Qn=20,Zn=3,Pt="meshy-working-dir-recents-by-node";function eo(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function to(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===Zn))break}return a}function so(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 ao(t,a,r){if(!a)return t;const n=t[a]??[],d=so(n,r);if(d.length===0){if(!(a in t))return t;const{[a]:o,...u}=t;return u}return{...t,[a]:d}}function ro(t,a){var r;return a?((r=t[a])==null?void 0:r[0])??"":""}function no(t){if(!t||typeof window>"u")return"";try{const a=window.localStorage.getItem(Pt);return a?ro(Ys(JSON.parse(a)),t):""}catch{return""}}function oo(t,a,r){return t!=="auto"?a.find(n=>n.id===t)??null:r.length===1?r[0]??null:null}function lo(t,a){const r=a.trim();return r?eo(r)||!t?r:`${t.replace(/[/\\]+$/,"")}/${r}`:""}function io(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),[h,k]=s.useState(null),[S,w]=s.useState(!1),[y,N]=s.useState(!1),[X,O]=s.useState(null),[T,ee]=s.useState(""),[P,U]=s.useState(!1),[D,B]=s.useState({}),pe=s.useRef(null),E=s.useMemo(()=>oo(r,n,d),[r,n,d]),V=E==null?void 0:E.id,W=s.useMemo(()=>V?D[V]??[]:[],[D,V]),R=s.useMemo(()=>t.trim()?lo(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=ao(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?N(!0):w(!0);try{const be=await qa(V,{path:x,limit:Qn,offset:Z,directoriesOnly:!0,allowAbsolute:!0});k(oe=>F&&oe?{...be,entries:[...oe.entries,...be.entries]}:be)}catch(be){O(be instanceof Error?be.message:"Failed to browse directories"),F||k(null)}finally{w(!1),N(!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),k(null),O(null),V&&ce.current(to(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(()=>{h&&q(h.currentPath,h.entries.length,!0)},[h,q]),le=o==="composer"?e.jsxs(L,{type:"button",variant:"ghost",onClick:()=>c(x=>!x),title:R,"aria-label":`Working directory: ${R}`,className:A(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:A("min-w-0 truncate",g),children:R})]}):e.jsxs(L,{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:A("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=io(h,E),ie=!!(h!=null&&h.parentPath);return e.jsxs("div",{className:A("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:A("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:[W.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:W.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:()=>(h==null?void 0:h.parentPath)&&I(h.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(Qr,{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}),h&&e.jsx("button",{type:"button",onClick:()=>K(h.isAbsolute?h.currentPath:h.currentPath==="."?"":h.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..."]}):h&&h.entries.length>0?e.jsxs(e.Fragment,{children:[h.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(Gr,{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(et,{className:"h-3.5 w-3.5"})})]},x.path)),h.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&&h&&h.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:P?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(He,{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(Ue,{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(cn,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(nn,{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 co(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??Ze}}function uo(){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 xo(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 m;return r&&l.some(_=>_.id===r)?r:((m=l[0])==null?void 0:m.id)??""},[l,r]),[h,k]=s.useState(""),[S,w]=s.useState("codex"),[y,N]=s.useState(""),[X,O]=s.useState(""),[T,ee]=s.useState(""),[P,U]=s.useState(c),[D,B]=s.useState("normal"),[pe,E]=s.useState(Ze),[V,W]=s.useState(!1),[R,de]=s.useState([]),[K,q]=s.useState(!1),[re,ce]=s.useState(null),I=s.useMemo(()=>R.find(m=>m.sessionId===y)??null,[R,y]);s.useEffect(()=>{P&&l.some(m=>m.id===P)||U(c)},[P,l,c]),s.useEffect(()=>{N(""),O(""),ee("")},[S,P]),s.useEffect(()=>{let m=!1;return P?(q(!0),ce(null),Wa(P,{agent:S,limit:50}).then(_=>{m||de(_.sessions)}).catch(_=>{m||(de([]),ce(_ instanceof Error?_.message:"Failed to load native sessions"))}).finally(()=>{m||q(!1)}),()=>{m=!0}):(de([]),ce(null),q(!1),()=>{m=!0})},[S,P]),s.useEffect(()=>{I&&(O(I.sessionId),ee(I.cwd))},[I]);const Q=s.useCallback(async m=>{m.preventDefault();const _=co({title:h,defaultTitle:I==null?void 0:I.summary,agent:S,sessionId:X,cwd:T,assignTo:P,priority:D,mode:pe});if(_){W(!0);try{const $=await Ga(_);d($)}catch($){xe.error($ instanceof Error?$.message:"Failed to load native session")}finally{W(!1)}}},[h,I,S,X,T,P,D,pe,d]),le=!!(X.trim()&&T.trim()&&P),[ne,ie]=s.useState(!1),[x,Z]=s.useState(""),F=l.find(m=>m.id===P)??null,be=!!(r&&(F==null?void 0:F.id)===r),oe=s.useMemo(()=>{const m=x.trim().toLowerCase();return m?R.filter(_=>_.summary.toLowerCase().includes(m)||_.sessionId.toLowerCase().includes(m)||_.cwd.toLowerCase().includes(m)):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:A("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:P,onValueChange:U,children:[e.jsx(we,{className:A(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:m=>w(m),children:[e.jsxs(we,{className:A(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:m=>Z(m.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:[!P&&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."}),P&&!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(m=>{const _=m.sessionId===y;return e.jsxs("button",{type:"button",onClick:()=>N(m.sessionId),className:A("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:A("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:m.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:xo(m.updatedAt)})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-4 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"font-mono",children:m.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:m.cwd})]})]},m.sessionId)})]})]}),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(m=>!m),className:"flex w-full items-center gap-2 text-[11px] font-medium uppercase tracking-[0.2em] text-muted-foreground transition-colors hover:text-foreground","aria-expanded":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(st,{className:A("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:m=>{N(""),O(m.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:h,onChange:m=>k(m.target.value),placeholder:"Optional",className:"h-10 rounded-full border-border/70 bg-background/70 text-sm"})]})]}),e.jsx(Ft,{value:T,onChange:m=>{N(""),ee(m)},assignTo:P,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:m=>E(m),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:uo()})]})]}),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:A("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",f),children:[o&&e.jsx(L,{type:"button",variant:"ghost",onClick:o,className:"rounded-full",children:g}),e.jsx(L,{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 hs(){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 ho(t){var a;return((a=Cs.find(r=>r.value===t))==null?void 0:a.label)??t}function po(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(`
119
- `).map(o=>o.trim()).find(Boolean);return d?d.length>72?`${d.slice(0,69).trimEnd()}...`:d:r?"Image task":""}function fo(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??Ze,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 bo({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,h]=s.useState(""),[k,S]=s.useState(""),[w,y]=s.useState("claudecode"),[N,X]=s.useState(Ze),[O,T]=s.useState(""),[ee,P]=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),[W,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=ho(w),F=po(N);s.useEffect(()=>{E&&B.some(M=>M.id===E)||V(pe)},[E,B,pe]),s.useEffect(()=>{T(no(E)),P("")},[E]),s.useEffect(()=>{P("")},[O]);const be=s.useCallback(async M=>{M.preventDefault();const se=fo({title:c,description:k,agent:w,project:O,branch:ee,priority:U,assignTo:E,mode:N,images:q});if(se){R(!0);try{const H=await Ya(se);d(H)}catch(H){xe.error(H instanceof Error?H.message:"Failed to create task")}finally{R(!1)}}},[c,k,w,O,ee,U,E,N,q,d]),oe=Qs(c,k,q.length>0),je=!!(oe&&w&&E&&(k.trim()||q.length>0)),m=s.useCallback(M=>{var se;M.nativeEvent.isComposing||M.key==="Enter"&&(M.ctrlKey||M.metaKey)&&je&&!W&&(M.preventDefault(),(se=M.currentTarget.form)==null||se.requestSubmit())},[je,W]),_=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(Ue,{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:hs()})]})]}),z=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Se,{className:"text-sm font-medium",children:"Mode"}),e.jsxs(ye,{value:N,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}),Ne=e.jsx(ms,{value:ee,onChange:P,project:O,assignTo:E,nodes:t,assignableNodes:B});return l==="composer"?e.jsxs("form",{onSubmit:be,className:A("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",H="border-border/70 bg-background/55 text-foreground",Re=w==="claudecode",Ve=N===Ze;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:A(M,H,"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:ke=>h(ke.target.value),onKeyDown:ke=>{(ke.key==="Enter"||ke.key==="Escape")&&(ke.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(L,{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(He,{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:k,onChange:ke=>S(ke.target.value),onKeyDown:m,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(L,{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:A(M,"chat-composer__icon-trigger",Re?se:H),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:hs()})]}),e.jsxs(ye,{value:N,onValueChange:ke=>X(ke),children:[e.jsxs(we,{className:A(M,"chat-composer__icon-trigger",Ve?se:H),title:`Mode: ${F}`,"aria-label":`Mode: ${F}`,children:[e.jsx(En,{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:A("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(en,{className:A("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(L,{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(Ue,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:g})]}),e.jsxs(L,{type:"submit",size:"icon",disabled:!je||W,className:"h-10 w-10 rounded-full shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[W?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:W?"Creating chat":p})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const ke="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:ke,chipInactiveClassName:ke,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(ms,{value:ee,onChange:P,project:O,assignTo:E,nodes:t,assignableNodes:B,layout:"composer",chipClassName:M,chipActiveClassName:ke,chipInactiveClassName:ke,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:A("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:k,onChange:M=>S(M.target.value),onKeyDown:m,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(L,{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=>h(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,Ne,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[te,$]}),e.jsxs("div",{className:A("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",f),children:[o&&e.jsx(L,{type:"button",variant:"ghost",onClick:o,className:"rounded-2xl",children:g}),e.jsx(L,{type:"submit",disabled:!je||W,className:"rounded-2xl px-5",children:W?"Creating...":p})]})]})}function go({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[h,k]=s.useState(u),S=f!==void 0,w=S?f:h,y=N=>{S||k(N),p==null||p(N)};return e.jsxs("div",{className:A("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(L,{type:"button",variant:w==="chat"?"default":"ghost",onClick:()=>y("chat"),className:"flex-1 rounded-full",children:[e.jsx(Ja,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(L,{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(bo,{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 Ge="72f988bf-86f1-41af-91ab-2d7cd011db47",Zs=`${Ge} (MSIT)`;function vo({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(jo,{onOpenChange:a,onShare:r,onStopShare:n,sharing:d,stopping:o,shareResult:u})]})})}function jo({onOpenChange:t,onShare:a,onStopShare:r,sharing:n,stopping:d=!1,shareResult:o}){const[u,f]=s.useState((o==null?void 0:o.tenant)??Ge),[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)??Ge),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(L,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-full text-muted-foreground",onClick:()=>void We(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(L,{variant:"outline",onClick:()=>t(!1),disabled:l,className:"h-8 text-xs",children:o?"Done":"Cancel"}),o&&r&&e.jsxs(L,{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(L,{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=h=>{var S;const k=h.target;k instanceof Node&&((S=g.current)!=null&&S.contains(k)||(d(!1),u(!1)))},c=h=>{h.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:ko(t)}),e.jsx(st,{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(Ge),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===Ge&&e.jsx(He,{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(He,{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(Ue,{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 ko(t){return t===Ge?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 yo=s.lazy(async()=>({default:(await Ut(()=>import("./FilesTab-JtS0K69s.js"),__vite__mapDeps([0,1,2,3,4]))).FilesTab})),wo=s.lazy(async()=>({default:(await Ut(()=>import("./PreviewTab-DjvNLJqk.js"),__vite__mapDeps([5,1,2,6]))).PreviewTab})),Co=s.lazy(async()=>({default:(await Ut(()=>import("./DiffTab-D32e4GZ0.js"),__vite__mapDeps([7,1,2,3,4,8,6]))).DiffTab}));function So({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:h,taskError:k,displayEvents:S,initialPromptAlreadyInLogs:w,initialPrompt:y,supportsFollowUp:N,taskUnavailable:X,chatDisabled:O,chatDisabledReason:T,questionBypassEnabled:ee,isRunning:P,isStarting:U,hasPendingFollowUp:D,canCancel:B,canRetry:pe,onRetry:E,onCancel:V,onShareTask:W,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,m]=s.useState(!1),[_,$]=s.useState({}),[j,z]=s.useState(new Set),[te,fe]=s.useState(new Set),Ne=s.useRef(0),M=s.useRef(!1),se=s.useCallback(Ee=>{const J=Ee.currentTarget,De=Ne.current;if(Ne.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)},[]),H=(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",Ve=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...",ke=l?[{label:"Working dir",value:H,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:Re}]:[],Ye=!!(y&&!w),rt=Ye||S.length>0,Xe=P&&rt,Qe=(U||D||P)&&!Xe,Fe=(l==null?void 0:l.conversationKind)==="nativeSession",Be=l&&!j.has(l.id)?_[l.id]??l.activeShare??null:null;return g?e.jsx(_o,{onToggleTasks:t,desktopTasksOpen:a,mobileTasksPanelOpen:r,operationsOpen:n,onToggleOperations:d,cluster:o,sseConnected:u,defaultMode:v,onCancel:K,onCreated:q}):!l&&h?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(Xa,{priority:l.priority}),e.jsx(L,{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"})})]}),k&&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:k}),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"})]}),P&&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 ",Qa(l.updatedAt)]}),e.jsx("span",{className:"font-mono",children:l.id.slice(0,8)}),pe&&e.jsxs(L,{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(L,{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(Sn,{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:[Ye&&y&&e.jsx(ds,{event:y,questionBypassEnabled:ee,onQuestionBypassChange:ce,onSubmitQuestionResponse:I,questionResponseDisabled:!N||O}),S.map((Ee,J)=>e.jsx(ds,{event:Ee,questionBypassEnabled:ee,onQuestionBypassChange:ce,onSubmitQuestionResponse:I,questionResponseDisabled:!N||O},zr("transcript",Ee,J))),!rt&&!Qe&&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:h?"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."})]}),(!N&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!N&&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(Ue,{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})]})]}),Qe&&e.jsx(bs,{children:Ve}),Xe&&e.jsx(bs,{children:"The agent is still working on this conversation."}),e.jsx("div",{ref:Q})]})}),N?le?e.jsx(L,{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(Hn,{onSend:re,disabled:O,disabledReason:T,contextItems:ke,placeholder:O?T:"Continue the conversation...",running:P||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(yo,{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(wo,{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(Co,{taskId:l.id})})}),e.jsx(kt,{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(vo,{open:Z,onOpenChange:F,sharing:be,stopping:je,shareResult:Be,onShare:async Ee=>{if(!l)return null;oe(!0);try{const J=await W(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;m(!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{m(!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(L,{onClick:de,className:"mt-6 rounded-full px-5",children:[e.jsx(qt,{className:"h-4 w-4"}),"Start or load chat"]}),k&&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:k})]})})]})}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 _o({onToggleTasks:t,desktopTasksOpen:a,mobileTasksPanelOpen:r,operationsOpen:n,onToggleOperations:d,cluster:o,sseConnected:u,defaultMode:f,onCancel:p,onCreated:g}){var h,k,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,N=w.value===v;return e.jsxs("button",{type:"button",onClick:()=>l(w.value),"aria-pressed":N,className:A("flex items-center gap-1.5 rounded-full px-2 py-1 transition-colors",N?"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(go,{nodes:(o==null?void 0:o.nodes)??[],currentNodeRole:(h=o==null?void 0:o.self)==null?void 0:h.role,currentNodeId:((k=o==null?void 0:o.self)==null?void 0:k.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(L,{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(L,{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(pn,{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:h,leavePending:k,onLeaveCluster:S,onToggleNodeDevTunnel:w,devTunnelNodeId:y,onClose:N}){var E,V,W;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,P=Za((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"&&P.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(L,{variant:"ghost",size:"icon",onClick:N,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(qe,{label:"Term",value:String((t==null?void 0:t.term)??0)}),e.jsx(qe,{label:"Nodes",value:String((t==null?void 0:t.nodes.length)??0)}),e.jsx(qe,{label:"Pending",value:String((t==null?void 0:t.taskSummary.pending)??0)}),e.jsx(qe,{label:"Running",value:String((t==null?void 0:t.taskSummary.running)??0)}),e.jsx(qe,{label:"Completed",value:String((t==null?void 0:t.taskSummary.completed)??0)}),e.jsx(qe,{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:((W=t==null?void 0:t.leader)==null?void 0:W.name)??"None"}),e.jsx(Le,{label:"Leader URL",value:D??"Unavailable",mono:!0,action:D?e.jsx(tt,{label:"Copy leader URL",onClick:()=>void We(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(L,{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(L,{variant:"outline",size:"sm",onClick:h,className:"h-7 rounded-full px-2.5 text-[11px]",children:"Join node"}):pe?e.jsxs(L,{variant:"outline",size:"sm",onClick:S,disabled:k,className:"h-7 rounded-full px-2.5 text-[11px]",children:[k&&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 (",P.length,")"]}),P.length>0?e.jsx("div",{className:"space-y-2",children:P.map(R=>e.jsx(Eo,{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(er,{className:A("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(tr,{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,h=Hs(t,a==null?void 0:a.transportType),k=Wt(t,a==null?void 0:a.transportType),S=k&&Je((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(st,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(et,{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(tt,{label:"Copy dashboard URL",onClick:()=>void We(g,"Dashboard URL copied")})}),e.jsx(Le,{label:"Node URL",value:v,mono:!0,action:e.jsx(tt,{label:"Copy node URL",onClick:()=>void We(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:h}),a&&e.jsx(Dt,{label:"Uptime",value:sr(a.uptime),mono:!0})]}),e.jsx(Bs,{capabilities:t.capabilities,action:o&&S?e.jsxs(L,{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"}),k?"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 Eo({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),h=r>0;return e.jsxs("div",{className:"rounded-[20px] border border-border/60 bg-background/45",children:[e.jsxs("button",{type:"button",onClick:()=>u(k=>!k),className:"w-full px-3 py-2 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[o?e.jsx(st,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(et,{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:k=>k.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(tt,{label:"Copy dashboard URL",onClick:()=>void We(f,"Dashboard URL copied")})}),e.jsx(Le,{label:"Node URL",value:p,mono:!0,action:e.jsx(tt,{label:"Copy node URL",onClick:()=>void We(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(L,{variant:"outline",size:"sm",onClick:()=>d(t),disabled:n===t.id||h,className:"h-7 rounded-full px-2.5 text-[11px]",title:h?"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&&h&&e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[r," active task",r===1?"":"s"," on this node."]})]})]})}function tt({label:t,onClick:a}){return e.jsx(L,{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 To(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",[Do]=lr(ut),[Mo,Jt]=Do(ut);function Ao(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,h]=rr({prop:r,defaultProp:d??!1,onChange:p,caller:ut}),[k,S]=s.useState(null),[w,y]=s.useState(null),N=s.useRef(!1),X=k?!!u||!!k.closest("form"):!0,O={checked:c,disabled:o,setChecked:h,control:k,setControl:S,name:f,form:u,value:v,hasConsumerStoppedPropagationRef:N,required:g,defaultChecked:$e(d)?!1:d,isFormControl:X,bubbleInput:w,setBubbleInput:y};return e.jsx(Mo,{scope:a,...O,children:Lo(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:h,bubbleInput:k}=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 N=()=>l(w.current);return y.addEventListener("reset",N),()=>y.removeEventListener("reset",N)}},[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(N=>$e(N)?!0:!N),k&&h&&(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(Ao,{__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(ar,{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:h}=Jt(na,t),k=Rs(r,h),S=nr(o),w=or(n);s.useEffect(()=>{const N=c;if(!N)return;const X=window.HTMLInputElement.prototype,T=Object.getOwnPropertyDescriptor(X,"checked").set,ee=!d.current;if(S!==o&&T){const P=new Event("click",{bubbles:ee});N.indeterminate=$e(o),T.call(N,$e(o)?!1:o),N.dispatchEvent(P)}},[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:k,style:{...a.style,...w,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});oa.displayName=na;function Lo(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:A("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:A("flex items-center justify-center text-current"),children:e.jsx(He,{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:h,allVisibleTasksSelected:k,someVisibleTasksSelected:S,canBatchArchive:w,onSearchChange:y,onScopeChange:N,onAgentFilterChange:X,onNodeFilterChange:O,onTaskKindFilterChange:T,onToggleTaskSelected:ee,onToggleAllVisibleTasks:P,onBatchArchive:U,onBatchDelete:D,onCreateTask:B,onSelectTask:pe,onClose:E}){const[V,W]=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=h.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(()=>ir(t,l),[t,l]),oe=be.length===1,je=!oe||le||ne,m=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&&W(!0)},[c]),s.useEffect(()=>{var j;V&&((j=re.current)==null||j.focus())},[V]),s.useEffect(()=>{if(!V)return;const j=te=>{var Ne;const fe=te.target;fe instanceof Node&&((Ne=ce.current)!=null&&Ne.contains(fe)||W(!1))},z=te=>{te.key==="Escape"&&W(!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 Ne;const fe=te.target;fe instanceof Node&&((Ne=I.current)!=null&&Ne.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(L,{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:A("relative flex items-stretch transition-[flex] duration-200",V?"flex-[2]":"flex-1"),children:[e.jsxs(L,{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(L,{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(st,{className:A("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(L,{variant:"outline",size:"icon",onClick:()=>W(!1),className:"rounded-full border-border/70 bg-background/60",children:e.jsx(dr,{className:"h-4 w-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(L,{variant:"outline",onClick:()=>W(!0),className:A("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(L,{variant:R||le?"secondary":"outline",size:"icon",onClick:()=>de(j=>!j),className:A("shrink-0 rounded-full border-border/70 bg-background/60",le&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(sn,{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=>N(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:cr.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:ur.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&&!k?"indeterminate":k,onCheckedChange:j=>P(j===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Select all"})]}),Q>0&&e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>P(!1),className:"h-7 rounded-full px-2 text-[11px]",children:"Clear"})]}),be.map(j=>{const z=j.nodeId??"__unassigned__",te=je&&!m&&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 bg-gradient-to-r from-primary/8 to-muted/20 px-2 py-1.5 text-left text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsx(et,{className:A("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!te&&"rotate-90")}),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,Ne)=>fe+Ne.tasks.length,0)})]}),e.jsx("div",{className:A("grid transition-[grid-template-rows] duration-300 ease-in-out",te?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:j.dirs.map(fe=>{const Ne=`${z}::${fe.path}`,M=Z.has(Ne),se=xr(fe.path);return e.jsxs("div",{className:A("space-y-0.5 rounded-xl",je&&"pl-3"),children:[e.jsxs("button",{type:"button",onClick:()=>$(Ne),"aria-expanded":!M,title:fe.path,className:"flex w-full items-center gap-1.5 rounded-lg bg-muted/15 px-2 py-1 text-left text-[10px] font-medium text-muted-foreground/70 transition-all duration-150 hover:bg-muted/30 hover:text-foreground active:scale-[0.98] active:bg-muted/40",children:[e.jsx(et,{className:A("h-3 w-3 shrink-0 transition-transform duration-200",!M&&"rotate-90")}),e.jsx("span",{className:"truncate font-mono",children:se}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/40",children:fe.tasks.length})]}),e.jsx("div",{className:A("grid transition-[grid-template-rows] duration-300 ease-in-out",M?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:A("overflow-hidden",je?"pl-2":"pl-0"),children:e.jsx("div",{className:"space-y-1.5 border-l border-border/35 py-1 pl-2.5 ml-1.5",children:fe.tasks.map(H=>e.jsxs("div",{className:A("flex items-center gap-1.5 rounded-[18px] border px-2.5 py-1.5 transition-all duration-200","hover:-translate-y-px",H.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 hover:shadow-[0_4px_16px_-6px_rgba(0,0,0,0.25)]"),children:[d&&e.jsx("div",{className:"flex shrink-0",onClick:Re=>Re.stopPropagation(),children:e.jsx(Bt,{checked:h.has(H.id),onCheckedChange:Re=>ee(H.id,Re===!0),"aria-label":`Select ${H.title}`})}),e.jsxs("button",{type:"button",onClick:()=>pe(H.id),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:A("h-1.5 w-1.5 shrink-0 rounded-full",mr(H.status),(H.status==="running"||H.status==="assigned")&&"animate-pulse")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:H.title}),e.jsx("span",{className:"ml-1 shrink-0 tabular-nums text-[10px] text-muted-foreground/55",children:hr(H.updatedAt)})]}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1 pl-3",children:[e.jsx(Ds,{status:H.status}),e.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/60",children:H.agent}),H.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"}),H.activeShare&&e.jsx(Pe,{variant:"outline",className:"border-primary/25 bg-primary/10 text-[10px] text-primary",children:"shared"}),H.assignedNodeAvailable===!1&&e.jsx(Pe,{variant:"outline",className:"border-destructive/25 bg-destructive/10 text-[10px] text-destructive",children:"unavailable"})]})]})]},H.id))})})})]},Ne)})})})]},z)})]}):r?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(j=>e.jsx("div",{className:"rounded-[24px] border border-border/40 bg-background/30 px-3 py-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"mt-1 h-2.5 w-2.5 shrink-0 animate-pulse rounded-full bg-muted-foreground/20"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-2.5 animate-pulse rounded-full bg-muted-foreground/15",style:{width:`${60+j*12}%`,animationDelay:`${j*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${j*120+60}ms`}})]})]})},j))}):e.jsx("div",{className:"rounded-[24px] border border-dashed border-border/70 bg-background/35 px-3 py-5 text-[11px] text-muted-foreground",children: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(kt,{children:[e.jsx(ls,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",disabled:!w,className:"rounded-full",children:[e.jsx(Yr,{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(kt,{children:[e.jsx(ls,{asChild:!0,children:e.jsxs(L,{variant:"destructive",size:"sm",className:"rounded-full",children:[e.jsx(Dn,{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 Po(t,a){var r,n;try{const d=await pr(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 Ro(t){try{return await fr(t),xe.success("Shared link stopped"),!0}catch(a){return xe.error(a instanceof Error?a.message:"Failed to stop shared link"),!1}}function Fo(t,a,r){const n=s.useCallback(()=>{a(),r()},[a,r]),d=s.useCallback(async u=>{if(!t)return;const f=await Po(t.id,u);return f&&n(),f},[t,n]),o=s.useCallback(async()=>{if(!t)return!1;const u=await Ro(t.id);return u&&n(),u},[t,n]);return{handleShareTask:d,handleStopShareTask:o}}function Ns(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,N;const c=l.changedTouches[0];if(!c)return;const h=c.clientX-u;Math.abs(c.clientY-f)>100||Math.abs(h)<50||(h>0?(w=(S=n.current).onSwipeRight)==null||w.call(S):(N=(y=n.current).onSwipeLeft)==null||N.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 Io="(min-width: 1024px)",$o="(min-width: 1280px)";function ks(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 Bo(){const[t,a]=s.useState(!0),[r,n]=s.useState(!1),[d,o]=s.useState(()=>ks($o)),u=s.useRef(null),f=s.useRef(null);Ns(u,{onSwipeLeft:()=>n(!1)}),Ns(f,{onSwipeRight:()=>o(!1)});const p=s.useCallback(()=>{if(ks(Io)){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 Oo({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 br({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 gr(g,1e4),s.useEffect(()=>{g()},[g]),s.useEffect(()=>r("task",g),[r,g]),{fetchTasks:g,setTasks:d,tasks:n,tasksError:f,tasksLoading:o}}function zo(t,a){return a.data.nodeId===t.self.id||a.data.name===t.self.name||a.data.endpoint===t.self.endpoint}function Uo({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=zo(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 Vo=[0,300,1e3,2e3];function Ko({task:t,getActiveTaskId:a,setLogs:r,setPendingMessages:n}){t.conversationKind==="nativeSession"&&(async()=>{for(const d of Vo){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 qo(){var ts,ss,as;const{id:t}=vr(),a=jr(),r=Nr(),{cluster:n,systemInfo:d,events:o,sseConnected:u,subscribe:f,refresh:p,loading:g,error:v}=kr(),l=s.useMemo(()=>yr(a.state),[a.state]),[c,h]=s.useState(null),[k,S]=s.useState("active"),[w,y]=s.useState("all"),[N,X]=s.useState("all"),[O,T]=s.useState("all"),[ee,P]=s.useState(""),U=s.useDeferredValue(ee),{desktopTasksOpen:D,mobileTasksPanelOpen:B,mobileTasksPanelRef:pe,operationsOpen:E,operationsPanelRef:V,setMobileTasksPanelOpen:W,setOperationsOpen:R,toggleTasksPanel:de}=Bo(),[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,m]=s.useState(null),[_,$]=s.useState([]),[j,z]=s.useState([]),[te,fe]=s.useState(!1),[Ne,M]=s.useState(null),[se,H]=s.useState(new Set),[Re,Ve]=s.useState(!1),[ke,Ye]=s.useState(!1),[rt,Xe]=s.useState(null),Qe=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;Uo({cluster:n,subscribe:f});const{fetchTasks:J,setTasks:De,tasks:Me,tasksError:ia,tasksLoading:xt}=Oo({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=An(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=>!wr(i,k)||w!=="all"&&i.agent!==w||!Cr(i,O)||N==="unassigned"&&i.assignedTo||N!=="all"&&N!=="unassigned"&&Sr(i.assignedTo,n==null?void 0:n.nodes,i.assignedNodeName)!==N?!1:U.trim()?_r(i,U):!0),[ge,k,w,O,N,U]);s.useEffect(()=>{H(i=>{const b=$n(i,Ae.map(C=>C.id));return b.size===i.size?i:b})},[Ae]),s.useEffect(()=>{Be||H(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]),mt=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]),ma=Ae.length>0&&Ae.every(i=>se.has(i.id)),ha=Ae.some(i=>se.has(i.id)),pa=Bn(Ae,se);s.useEffect(()=>{l!=null&&l.draftNewTask&&(q(!0),Q({route:l.returnRoute??"/",taskId:l.returnTaskId??null}))},[l]),s.useEffect(()=>{Z!=="all"&&!mt.includes(Z)&&F("all")},[Z,mt]),s.useEffect(()=>{xs(t,K)&&!c&&ge[0]&&h(ge[0].id)},[t,K,c,ge]),s.useEffect(()=>{var i;xs(t,K)&&(c&&Me.some(b=>b.id===c)||h(((i=ge[0])==null?void 0:i.id)??null))},[t,K,c,ge,Me]);const ae=Pn({routeTaskId:t,creatingTask:K,internalSelectedTaskId:c,sortedTaskIds:ge.map(i=>i.id)}),Ke=s.useMemo(()=>Me.find(i=>i.id===ae)??null,[Me,ae]);s.useEffect(()=>{Fe.current=ae??null},[ae]);const nt=s.useCallback(()=>{m(null),$([]),z([]),M(null)},[]),_e=s.useCallback(async()=>{const i=ae;if(i)try{const b=await Er(i);if(Fe.current!==i)return;m(b),M(null)}catch(b){if(Fe.current!==i)return;m(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){m(null),$([]),z([]),M(null),fe(!1);return}x("transcript"),m(Ke),$([]),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;h(i),nt(),s.startTransition(()=>{r(i?`/tasks/${i}`:"/",{state:null})})},[ae,nt,K,r,ge,Me,xt]),s.useEffect(()=>{Ke&&m(i=>!i||i.id!==Ke.id?i:{...i,...Ke})},[Ke]),s.useEffect(()=>f("task.updated",i=>{De(b=>Fn(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=>Ur(Y,C));const ue=cs(C);ue&&z(Y=>Vr(Y,ue))}}i.type==="task.updated"&&_e(),i.type==="task.status"&&(_e(),ot())}})},[f,ae,_e,ot]),s.useEffect(()=>{var i;ie==="transcript"&&((i=Qe.current)==null||i.scrollIntoView({behavior:"smooth"}))},[_,j,ie]);const G=je??Ke,fa=G!=null&&G.assignedTo?(n==null?void 0:n.nodes.find(i=>i.id===G.assignedTo))??null:null,ht=j.length>0,ba=G?Tr.has(G.agent):!1,pt=(G==null?void 0:G.status)==="running",ga=G?ct.has(G.status):!1,va=G?ct.has(G.status)||Dr.has(G.status):!1,ja=!!(G&&Be&&G.status==="failed"),ft=s.useMemo(()=>To(G,n,ht,!!pt),[G,n,ht,pt]),bt=s.useMemo(()=>Kr([..._,...j.map(i=>Nt(i.content,i.timestamp))]),[_,j]),lt=s.useMemo(()=>{if(!G||G.conversationKind==="nativeSession")return null;const i=qr(G);if(i.length>0)return Nt(i,new Date(G.createdAt).toISOString());if(bt.length>0)return null;const b=Hr(G.description||G.title);return b.length>0?Nt(b,new Date(G.createdAt).toISOString()):null},[G,bt]),gt=s.useMemo(()=>lt?cs(lt):null,[lt]),Na=s.useMemo(()=>gt?Wr(_,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]),ka=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),h(i),s.startTransition(()=>{r((I==null?void 0:I.route)??"/",{state:null})})},[I,ge,r]),Qt=s.useCallback(i=>{q(!1),Q(null),h(i),s.startTransition(()=>{r(`/tasks/${i}`,{state:null})})},[r]),ya=s.useCallback(i=>{Fe.current=i.id,q(!1),Q(null),De(b=>Rn(b,i)),m(i),$([]),z([]),M(null),fe(!1),x("transcript"),h(i.id),Ko({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 Mr(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(G)try{await Ar(G.id),_e(),J()}catch(i){xe.error(i instanceof Error?i.message:"Failed to cancel task")}},[G,_e,J]),{handleShareTask:_a,handleStopShareTask:Ea}=Fo(G,_e,J),Ta=s.useCallback(async()=>{if(G)try{await Lr(G.id),_e(),J()}catch(i){xe.error(i instanceof Error?i.message:"Failed to retry task")}},[G,_e,J]),dt=s.useCallback((i,b=!1)=>{const C=On(Ae,i);return h(C),(b||!C)&&nt(),s.startTransition(()=>{r(C?`/tasks/${C}`:"/",{state:null})}),C},[nt,Ae,r]),Da=s.useCallback((i,b)=>{H(C=>{const ue=new Set(C);return b?ue.add(i):ue.delete(i),ue})},[]),Ma=s.useCallback(i=>{if(!i){H(new Set);return}H(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 Pr(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)`),H(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 Rr(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)`),H(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()=>{Ve(!0);try{await Fr(),p()}catch(i){xe.error(i instanceof Error?i.message:"Failed to promote node")}finally{Ve(!1)}},[p]),Ra=s.useCallback(async()=>{Ye(!0);try{await Ir(),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{Ye(!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&&Je(ue);Xe(i.id);try{Y?await $r("direct"):await Br(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{Xe(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:k,agentFilter:w,nodeFilter:N,taskKindFilter:O,agentOptions:ca,nodeOptions:ua,nodeNameById:Xt,searchQuery:ee,selectedTaskIds:se,allVisibleTasksSelected:ma,someVisibleTasksSelected:ha,canBatchArchive:pa,onSearchChange:P,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:mt,filteredEvents:xa,sseConnected:u,clusterLoading:g,clusterError:v,promotePending:Re,onPromote:Pa,onAddNode:()=>ne(!0),leavePending:ke,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:A("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(So,{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:G,assignedNode:fa,taskLoading:te,taskError:Ne,displayEvents:bt,initialPromptAlreadyInLogs:Na,initialPrompt:lt,supportsFollowUp:ba,taskUnavailable:ft.taskUnavailable,chatDisabled:ft.chatDisabled,chatDisabledReason:ft.chatDisabledReason,questionBypassEnabled:be,isRunning:!!pt,isStarting:ga,hasPendingFollowUp:ht,canCancel:!!va,canRetry:!!ja,onRetry:Ta,onCancel:Sa,onShareTask:_a,onStopShareTask:Ea,onStartCreateTask:vt,onCancelCreateTask:ka,onCreateTask:ya,onSendMessage:wa,onQuestionBypassChange:oe,onSubmitQuestionResponse:Ca,messagesEndRef:Qe})}),e.jsx("div",{className:A("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:()=>W(!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=>{W(!1),vt(i)},onSelectTask:i=>{W(!1),Qt(i)},onClose:()=>W(!1)})})]}),e.jsx(Ss,{open:le,onOpenChange:ne,children:e.jsx(qn,{onAdded:()=>{ne(!1),p()}})})]})}const Yo=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:qo},Symbol.toStringTag,{value:"Module"}));export{Yo as D,us as G};