meshy-node 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab--hSaHvs5.js","assets/index-C0JpIJKq.js","assets/index-BNgc5Rxo.css","assets/file-DkQuix-3.js","assets/DashboardShared-DX6WQxCJ.js","assets/PreviewTab-Bw9zg0Zf.js","assets/play-DqkmpUz3.js","assets/DiffTab-DQ7FWefY.js"])))=>i.map(i=>d[i]);
2
- import{c as he,r as a,j as e,X as rs,B as z,S as $a,a as rr,b as B,d as or,g as ir,e as lr,I as Xe,C as As,f as dr,h as cr,F as ur,i as Oa,k as Ms,l as we,D as Ls,m as mr,n as xr,t as te,o as _e,p as Ee,q as Ie,s as De,u as it,v as ts,T as hr,w as fr,x as aa,y as pr,z as At,A as Mt,E as Lt,G as Fa,H as Ia,J as bs,K as lt,L as gr,M as za,N as Ua,P as br,O as Va,Q as ds,R as Ke,U as vr,V as cs,W as dt,Y as ct,Z as ut,_ as mt,$ as xt,a0 as ht,a1 as ft,a2 as pt,a3 as Pt,a4 as jr,a5 as Ha,a6 as Ka,a7 as Nr,a8 as Zs,a9 as na,aa as Us,ab as wr,ac as yr,ad as kr,ae as Sr,af as Cr,ag as _r,ah as Er,ai as Dr,aj as qa,ak as Wa,al as Ga,am as Tr,an as Vs,ao as Bt,ap as Ar,aq as Mr,ar as Lr,as as Qa,at as gt,au as Pr,av as ra,aw as Br,ax as Rr,ay as $r,az as Or,aA as oa,aB as Fr,aC as Ir,aD as et,aE as zr,aF as ia,aG as Ur,aH as Vr,aI as Hr,aJ as la,aK as Kr,aL as bt,aM as qr,aN as Wr,aO as Gr,aP as da,aQ as Ya,aR as Qr,aS as Yr,aT as Xr,aU as Jr,aV as Zr,aW as eo,aX as so,aY as to,aZ as ao,a_ as no,a$ as ro,b0 as oo,b1 as io,b2 as lo,b3 as co,b4 as uo,b5 as mo,b6 as xo,b7 as ho,b8 as fo,b9 as po,ba as go,bb as bo,bc as vo,bd as jo,be as No}from"./index-C0JpIJKq.js";import{r as ca,e as wo,b as Xa,t as Ja,A as Rt,L as me,g as Za,a as yo,c as ko,d as ua,f as ma,h as So,i as Co,C as xa,T as st,D as gs,I as Qe,M as vt,j as en,k as _o,m as sn,l as jt,n as Eo,o as ha,p as Do,q as To,s as tt,u as Ao,v as Mo,w as Lo}from"./DashboardShared-DX6WQxCJ.js";import{P as $t}from"./play-DqkmpUz3.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-Dav0BEeS.js","assets/index-uOXaVH-T.js","assets/index-Dcs2aXv5.css","assets/file-DwOudPZH.js","assets/DashboardShared-DxYXVvdm.js","assets/PreviewTab-C1dfVaAy.js","assets/play-BrbffmDU.js","assets/DiffTab-C1B_4d-N.js"])))=>i.map(i=>d[i]);
2
+ import{c as he,r as a,j as e,X as ss,B as z,S as $a,a as rr,b as B,d as or,g as ir,e as lr,I as Xe,C as As,f as dr,h as cr,F as ur,i as Oa,k as Ms,l as we,D as Ls,m as mr,n as xr,t as te,o as _e,p as Ee,q as Ie,s as De,u as ot,v as ts,T as hr,w as fr,x as ta,y as pr,z as Tt,A as At,E as Mt,G as Fa,H as Ia,J as bs,K as it,L as gr,M as za,N as Ua,P as br,O as Va,Q as ds,R as Ke,U as vr,V as cs,W as lt,Y as dt,Z as ct,_ as ut,$ as mt,a0 as xt,a1 as ht,a2 as ft,a3 as Lt,a4 as jr,a5 as Ha,a6 as Ka,a7 as Nr,a8 as aa,a9 as na,aa as Us,ab as wr,ac as yr,ad as kr,ae as Sr,af as Cr,ag as _r,ah as Er,ai as Dr,aj as qa,ak as Wa,al as Ga,am as Tr,an as Vs,ao as Pt,ap as Ar,aq as Mr,ar as Lr,as as Qa,at as pt,au as Pr,av as ra,aw as Br,ax as Rr,ay as $r,az as Or,aA as oa,aB as Fr,aC as Ir,aD as Zs,aE as zr,aF as ia,aG as Ur,aH as Vr,aI as Hr,aJ as la,aK as Kr,aL as gt,aM as qr,aN as Wr,aO as Gr,aP as da,aQ as Ya,aR as Qr,aS as Yr,aT as Xr,aU as Jr,aV as Zr,aW as eo,aX as so,aY as to,aZ as ao,a_ as no,a$ as ro,b0 as oo,b1 as io,b2 as lo,b3 as co,b4 as uo,b5 as mo,b6 as xo,b7 as ho,b8 as fo,b9 as po,ba as go,bb as bo,bc as vo,bd as jo,be as No}from"./index-uOXaVH-T.js";import{r as ca,e as wo,b as Xa,t as Ja,A as Bt,L as me,g as Za,a as yo,c as ko,d as ua,f as ma,h as So,i as Co,C as xa,T as et,D as gs,I as Qe,M as bt,j as en,k as _o,m as sn,l as vt,n as Eo,o as ha,p as Do,q as To,s as st,u as Ao,v as Mo,w as Lo}from"./DashboardShared-DxYXVvdm.js";import{P as Rt}from"./play-BrbffmDU.js";/**
3
3
  * @license lucide-react v1.7.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -24,7 +24,7 @@ import{c as he,r as a,j as e,X as rs,B as z,S as $a,a as rr,b as B,d as or,g as
24
24
  *
25
25
  * This source code is licensed under the ISC license.
26
26
  * See the LICENSE file in the root directory of this source tree.
27
- */const Uo=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],Ot=he("folder-open",Uo);/**
27
+ */const Uo=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],$t=he("folder-open",Uo);/**
28
28
  * @license lucide-react v1.7.0 - ISC
29
29
  *
30
30
  * This source code is licensed under the ISC license.
@@ -34,7 +34,7 @@ import{c as he,r as a,j as e,X as rs,B as z,S as $a,a as rr,b as B,d as or,g as
34
34
  *
35
35
  * This source code is licensed under the ISC license.
36
36
  * See the LICENSE file in the root directory of this source tree.
37
- */const Ko=[["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"}]],Nt=he("git-branch",Ko);/**
37
+ */const Ko=[["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"}]],jt=he("git-branch",Ko);/**
38
38
  * @license lucide-react v1.7.0 - ISC
39
39
  *
40
40
  * This source code is licensed under the ISC license.
@@ -44,12 +44,12 @@ import{c as he,r as a,j as e,X as rs,B as z,S as $a,a as rr,b as B,d as or,g as
44
44
  *
45
45
  * This source code is licensed under the ISC license.
46
46
  * See the LICENSE file in the root directory of this source tree.
47
- */const Go=[["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"}]],wt=he("history",Go);/**
47
+ */const Go=[["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"}]],Nt=he("history",Go);/**
48
48
  * @license lucide-react v1.7.0 - ISC
49
49
  *
50
50
  * This source code is licensed under the ISC license.
51
51
  * See the LICENSE file in the root directory of this source tree.
52
- */const Qo=[["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"}]],yt=he("image-plus",Qo);/**
52
+ */const Qo=[["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"}]],wt=he("image-plus",Qo);/**
53
53
  * @license lucide-react v1.7.0 - ISC
54
54
  *
55
55
  * This source code is licensed under the ISC license.
@@ -59,7 +59,7 @@ import{c as he,r as a,j as e,X as rs,B as z,S as $a,a as rr,b as B,d as or,g as
59
59
  *
60
60
  * This source code is licensed under the ISC license.
61
61
  * See the LICENSE file in the root directory of this source tree.
62
- */const Jo=[["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"}]],Ft=he("link-2",Jo);/**
62
+ */const Jo=[["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"}]],Ot=he("link-2",Jo);/**
63
63
  * @license lucide-react v1.7.0 - ISC
64
64
  *
65
65
  * This source code is licensed under the ISC license.
@@ -69,7 +69,7 @@ import{c as he,r as a,j as e,X as rs,B as z,S as $a,a as rr,b as B,d as or,g as
69
69
  *
70
70
  * This source code is licensed under the ISC license.
71
71
  * See the LICENSE file in the root directory of this source tree.
72
- */const si=[["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"}]],It=he("message-square-plus",si);/**
72
+ */const si=[["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"}]],Ft=he("message-square-plus",si);/**
73
73
  * @license lucide-react v1.7.0 - ISC
74
74
  *
75
75
  * This source code is licensed under the ISC license.
@@ -84,7 +84,7 @@ import{c as he,r as a,j as e,X as rs,B as z,S as $a,a as rr,b as B,d as or,g as
84
84
  *
85
85
  * This source code is licensed under the ISC license.
86
86
  * See the LICENSE file in the root directory of this source tree.
87
- */const ri=[["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"}]],zt=he("panel-right-close",ri);/**
87
+ */const ri=[["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"}]],It=he("panel-right-close",ri);/**
88
88
  * @license lucide-react v1.7.0 - ISC
89
89
  *
90
90
  * This source code is licensed under the ISC license.
@@ -129,6 +129,6 @@ import{c as he,r as a,j as e,X as rs,B as z,S as $a,a as rr,b as B,d as or,g as
129
129
  *
130
130
  * This source code is licensed under the ISC license.
131
131
  * See the LICENSE file in the root directory of this source tree.
132
- */const gi=[["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"}]],bi=he("trash-2",gi),vi=new Set(["assigned","running"]);function ji(s,t){return s.reduce((n,o)=>o.assignedTo===t&&vi.has(o.status)?n+1:n,0)}function ks(s){return(s==null?void 0:s.toLowerCase())==="devtunnel"}function Ni(s){return s?ks(s)?"DevTunnel":s.charAt(0).toUpperCase()+s.slice(1):"Direct"}function Ut(s,t){return ks(t??s.transportType)||!!s.devtunnelEndpoint}function rn(s,t){return!ks(t??s.transportType)}function on(s,t){const n=t??s.transportType;return ks(n)?"DevTunnel":s.devtunnelEndpoint?"Direct + DevTunnel":Ni(n)}function ga(s,t){return!s&&!t}function wi({routeTaskId:s,creatingTask:t,internalSelectedTaskId:n,sortedTaskIds:o}){return s||(t?null:o[0]??n??null)}function yi({activeTaskId:s,routeTaskId:t,creatingTask:n,tasksLoading:o,loadedTaskIds:r}){return!s||t||n||o?!1:!r.includes(s)}function ki(s,t){return[t,...s.filter(n=>n.id!==t.id)]}function ln(s,t){const n=s.findIndex(o=>o.id===t.id);return n===-1?[...s,t]:s.map((o,r)=>r===n?t:o)}const Si=new Set(["completed","failed","cancelled","archived"]);function Ci(s,t){const n=new Set(t);return new Set(Array.from(s).filter(o=>n.has(o)))}function _i(s,t){const n=new Set(t);if(n.size===0)return!1;const o=s.filter(r=>n.has(r.id));return o.length===n.size&&o.every(r=>Si.has(r.status))}function Ei(s,t){var o;const n=new Set(t);return((o=s.find(r=>!n.has(r.id)))==null?void 0:o.id)??null}function dn(){const[s,t]=a.useState([]),[n,o]=a.useState(null),r=a.useRef(null),i=a.useCallback(()=>{var f;(f=r.current)==null||f.click()},[]),g=a.useCallback(async f=>{const l=Array.from(f.target.files??[]);if(l.length!==0)try{const u=await ca(l);t(w=>[...w,...u]),o(null)}catch(u){o(u instanceof Error?u.message:"Failed to attach image")}finally{f.target.value=""}},[]),b=a.useCallback(async f=>{const l=wo(f.clipboardData);if(l.length!==0){f.preventDefault();try{const u=await ca(l);t(w=>[...w,...u]),o(null)}catch(u){o(u instanceof Error?u.message:"Failed to attach image")}}},[]),N=a.useCallback(f=>{t(l=>l.filter((u,w)=>w!==f))},[]),v=a.useCallback(()=>{t([]),o(null)},[]);return{images:s,error:n,fileInputRef:r,pickImages:i,handleFileChange:g,handlePaste:b,removeImage:N,clearImages:v}}function Di(s){const t=s.map(r=>({...r,displayValue:Ti(r)})),n=t.findIndex(r=>r.label.toLowerCase()==="working dir"),o=n>=0?n:0;return{primary:t[o],secondary:t.filter((r,i)=>i!==o)}}function Ti(s){return s.label.toLowerCase()==="agent"?Za(s.value):s.value}function ba(s){switch(s.toLowerCase()){case"branch":return Nt;case"node":return $a;case"working dir":default:return Ot}}function Ai({disabled:s=!1,running:t=!1,canStop:n=!1,hasContent:o=!1}){return t&&!o?{primaryAction:"stop",primaryDisabled:s||!n}:{primaryAction:"send",primaryDisabled:s||!o}}function Mi({onSend:s,disabled:t,disabledReason:n="Chat is waiting on the agent.",placeholder:o="Send a follow-up message...",contextItems:r=[],running:i=!1,onStop:g}){const[b,N]=a.useState(""),v=a.useRef(null),{images:f,error:l,fileInputRef:u,pickImages:w,handleFileChange:S,handlePaste:x,removeImage:j,clearImages:c}=dn(),p=a.useCallback(()=>{v.current&&(v.current.style.height="auto")},[]),k=a.useCallback(()=>{const E=Xa(b,f);E.length===0||t||(s(E),N(""),c(),p())},[b,f,t,s,c,p]),A=a.useCallback(E=>{E.key==="Enter"&&!E.shiftKey&&(E.preventDefault(),k())},[k]),L=a.useCallback(()=>{v.current&&(v.current.style.height="auto",v.current.style.height=`${Math.min(v.current.scrollHeight,220)}px`)},[]),O=b.trim().length>0||f.length>0,F=Ai({disabled:t,running:i,canStop:i&&!!g,hasContent:O}),U=Di(r),M=U.primary?ba(U.primary.label):Ot,P=i?O?"Enter queues this message for the next turn":g?"Task is running - type to queue, empty button stops task":"Task is running - type to queue a message":t?n:"Enter sends, Shift+Enter adds a line";return e.jsx("div",{"data-chat-input-shell":"true",className:"animate-composer-settle w-full border-t border-border/45 bg-background/42 px-2 py-2 backdrop-blur-xl sm:px-4 sm:py-3",children:e.jsx("div",{"data-chat-input-column":"true",className:"mx-auto w-full max-w-[72rem]",children:e.jsxs("div",{"data-chat-input-card":"true",className:"overflow-hidden rounded-xl border border-border/65 bg-card/88 shadow-[0_30px_92px_-62px_rgba(15,23,42,0.55)] backdrop-blur-xl sm:rounded-xl dark:shadow-[0_30px_92px_-62px_rgba(0,0,0,0.95)]",children:[e.jsx("input",{ref:u,type:"file",accept:"image/*",multiple:!0,onChange:S,className:"hidden"}),U.primary&&e.jsx("div",{"data-chat-input-primary-context":"true",className:"px-2.5 pt-1.5 sm:px-5 sm:pt-2",children:e.jsxs("div",{className:"-ml-1.5 inline-flex max-w-full items-center gap-1.5 rounded-sm bg-muted/45 px-1.5 py-0.5 shadow-[0_10px_28px_-18px_rgba(15,23,42,0.72)] sm:-ml-2 dark:shadow-[0_10px_28px_-18px_rgba(0,0,0,0.95)]",children:[e.jsx(M,{className:"h-2.5 w-2.5 shrink-0 text-primary/45","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[9px] leading-3 text-muted-foreground/72",title:U.primary.value,children:U.primary.displayValue})]})}),f.length>0&&e.jsx("div",{className:"px-2 pt-2.5 sm:px-5 sm:pt-4",children:e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map((E,J)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Ja(E),alt:E.filename??`attachment ${J+1}`,className:"h-24 w-24 rounded-xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>j(J),className:"absolute -top-2 -right-2 flex h-7 w-7 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${E.filename??`image ${J+1}`}`,children:e.jsx(rs,{className:"h-3.5 w-3.5"})})]},`${E.filename??"image"}-${J}`))})}),e.jsx("div",{className:"px-2 pb-0 pt-1 sm:px-5 sm:pt-1.5",children:e.jsx("textarea",{ref:v,value:b,onChange:E=>N(E.target.value),onKeyDown:A,onPaste:x,onInput:L,placeholder:o,disabled:t,rows:1,className:"min-h-[1.35rem] w-full resize-none overflow-x-hidden overflow-y-auto bg-transparent px-0 py-0 text-[11px] leading-[1.35rem] text-foreground placeholder:text-[10px] placeholder:text-muted-foreground/65 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50"})}),e.jsxs("div",{className:"flex items-end justify-between gap-2 px-2 pb-1.5 pt-0.5 sm:px-5 sm:pb-2.5",children:[U.secondary.length>0?e.jsx("div",{"data-chat-input-secondary-context":"true",className:"flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 pb-0.5 text-[9px] leading-3 text-muted-foreground/72 sm:text-[9px]",children:U.secondary.map(E=>{const J=ba(E.label),V=E.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${E.label}: ${E.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[V?e.jsx(Rt,{agent:E.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(J,{"data-chat-input-secondary-icon":"true",className:"h-2.5 w-2.5 shrink-0 text-primary/50","aria-hidden":"true"}),e.jsx("span",{className:`truncate ${E.mono?"font-mono":""}`,children:E.displayValue})]},`${E.label}:${E.value}`)})}):e.jsx("div",{className:"min-w-0 flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(z,{type:"button",variant:"ghost",onClick:w,disabled:t,className:"h-7 shrink-0 gap-1.5 rounded-sm px-2 text-[10px] text-muted-foreground hover:text-foreground sm:px-2",title:"Attach images",children:[e.jsx(yt,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:P,children:e.jsx(z,{onClick:F.primaryAction==="stop"?g:k,disabled:F.primaryDisabled,size:"icon","aria-label":F.primaryAction==="stop"?"Stop running task":i?"Queue message":"Send message",className:"h-7 w-9 shrink-0 rounded-sm bg-primary/90 text-primary-foreground shadow-[0_12px_30px_-18px_hsl(var(--primary)/0.95)] hover:bg-primary",children:F.primaryAction==="stop"?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(nn,{className:"h-3.5 w-3.5"})})})]})]}),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})]})})})}var Li=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Pi=Li.reduce((s,t)=>{const n=rr(`Primitive.${t}`),o=a.forwardRef((r,i)=>{const{asChild:g,...b}=r,N=g?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(N,{...b,ref:i})});return o.displayName=`Primitive.${t}`,{...s,[t]:o}},{}),Bi="Label",cn=a.forwardRef((s,t)=>e.jsx(Pi.label,{...s,ref:t,onMouseDown:n=>{var r;n.target.closest("button, input, select, textarea")||((r=s.onMouseDown)==null||r.call(s,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));cn.displayName=Bi;var un=cn;const Ri=or("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Re=a.forwardRef(({className:s,...t},n)=>e.jsx(un,{ref:n,className:B(Ri(),s),...t}));Re.displayName=un.displayName;function $i(s,t,n){return s!=="auto"?t.find(o=>o.id===s)??null:n.length===1?n[0]??null:null}function Oi(s){return s.trim()||"."}function Fi(s){return new Promise(t=>window.setTimeout(t,s))}function Ii(s){return!!s&&typeof s=="object"&&typeof s.createdBranch=="string"&&typeof s.currentBranch<"u"}async function zi(s){let t=s;for(let n=0;n<60;n++){if(t.status==="succeeded"){if(Ii(t.result))return t.result;throw new Error("Branch creation completed without branch details")}if(t.status==="failed")throw new Error(t.error||"Branch creation failed");await Fi(1e3),t=await dr(t.id)}throw new Error("Timed out waiting for branch creation")}function va({value:s,onChange:t,project:n,assignTo:o,nodes:r,assignableNodes:i,layout:g="default",chipClassName:b,chipActiveClassName:N,chipInactiveClassName:v,labelClassName:f,triggerClassName:l}){const[u,w]=a.useState(!1),[S,x]=a.useState(null),[j,c]=a.useState(""),[p,k]=a.useState(!1),[A,L]=a.useState(!1),[O,T]=a.useState(!1),[F,U]=a.useState(null),[M,P]=a.useState(""),[E,J]=a.useState(""),[V,X]=a.useState(""),[ce,ae]=a.useState(!1),ee=a.useRef(null),Z=a.useRef(0),H=a.useMemo(()=>$i(o,r,i),[o,r,i]),K=H==null?void 0:H.id,re=a.useMemo(()=>Oi(n),[n]),xe=a.useMemo(()=>K?`${K}
133
- ${re}`:"",[K,re]),h=a.useCallback(async(W=0,ie=!1)=>{const oe=Z.current+1,Te=xe;if(Z.current=oe,!K){x(null),c("");return}U(null),ie||c(""),ie?L(!0):k(!0);try{const D=await ir(K,{path:re,limit:20,offset:W,allowAbsolute:!0});if(oe!==Z.current)return;c(Te),x(Q=>ie&&Q?{...D,branches:[...Q.branches,...D.branches]}:D)}catch(D){if(oe!==Z.current)return;U(D instanceof Error?D.message:"Failed to load branch info"),ie||(x(null),c(""))}finally{oe===Z.current&&(k(!1),L(!1))}},[K,xe,re]);a.useEffect(()=>{if(!K){Z.current+=1,x(null),c(""),U(null);return}h()},[K,re,h]),a.useEffect(()=>{const W=s.trim(),ie=j===xe?S:null,oe=ie!=null&&ie.available&&ie.currentBranch?ie.currentBranch:"";W!==oe&&t(oe)},[S,xe,j,t,s]),a.useEffect(()=>{if(!u)return;const W=oe=>{ee.current&&(ee.current.contains(oe.target)||w(!1))},ie=oe=>{oe.key==="Escape"&&w(!1)};return document.addEventListener("mousedown",W),document.addEventListener("keydown",ie),()=>{document.removeEventListener("mousedown",W),document.removeEventListener("keydown",ie)}},[u]),a.useEffect(()=>{u&&(J(""),X(""),ae(!1))},[u,K,re]);const I=a.useCallback(async()=>{if(!K)return;const W=M.trim(),ie=ce?V.trim():E.trim();if(!(!W||!ie)){T(!0),U(null);try{const oe=await lr(K,{path:re,branchName:W,startPoint:ie,limit:20,offset:0,allowAbsolute:!0}),Te=await zi(oe);c(xe),x(Te),t(Te.currentBranch??Te.createdBranch),P(""),J(""),X(""),ae(!1),w(!1)}catch(oe){U(oe instanceof Error?oe.message:"Failed to create branch")}finally{T(!1)}}},[K,xe,re,ce,V,M,t,E]),C=j===xe?S:null,se=a.useCallback(()=>{C!=null&&C.hasMore&&h(C.branches.length,!0)},[C,h]),m=s.trim()||(C==null?void 0:C.currentBranch)||(C&&!C.available?"No git repo":"Branch"),$=ce?V.trim():E.trim(),q=!!(C!=null&&C.available&&M.trim()&&$&&!O),ne=g==="composer"?e.jsxs(z,{type:"button",variant:"ghost",onClick:()=>w(W=>!W),title:m,"aria-label":`Branch: ${m}`,className:B(b,l,"min-w-0 max-w-full",s.trim()?N:v),children:[p&&!C?e.jsx(me,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(Nt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:B("min-w-0 truncate",f),children:m})]}):e.jsxs(z,{type:"button",variant:"outline",onClick:()=>w(W=>!W),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:m,children:[e.jsx("span",{className:B("truncate",s.trim()?"font-mono text-foreground":"text-muted-foreground"),children:m}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:H?H.name:"Manual"})]});return e.jsxs("div",{className:B("relative inline-block",g==="composer"?"min-w-0 shrink-0":"w-full"),ref:ee,children:[g==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Branch"}),ne]}):ne,u&&e.jsxs("div",{className:B("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",g==="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(Nt,{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:C!=null&&C.repoRoot?`${C.currentBranch??m} · ${C.repoRoot}`:(C==null?void 0:C.currentBranch)??m,children:(C==null?void 0:C.currentBranch)??m}),p?e.jsx(me,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),H?p&&!C?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(me,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):C&&!C.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(Xe,{value:M,onChange:W=>P(W.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(z,{type:"button",size:"sm",onClick:()=>void I(),disabled:!q,title:q?"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:O?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(di,{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"}),!ce&&e.jsxs("button",{type:"button",onClick:()=>ae(!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(ys,{className:"h-2.5 w-2.5"}),"Manual"]})]}),ce?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Xe,{value:V,onChange:W=>X(W.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:()=>{ae(!1),X("")},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(rs,{className:"h-3.5 w-3.5"})})]}):C!=null&&C.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-md border border-border/40 bg-background/40",children:[C.branches.map(W=>{const ie=E===W.ref,oe=W.branch==="main"||W.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>J(W.ref),className:B("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",ie&&"bg-background/70"),title:W.ref,children:[e.jsx("span",{className:B("shrink-0 text-[10px]",oe?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:oe?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:W.ref}),ie?e.jsx(As,{className:"h-3 w-3 shrink-0 text-primary"}):null]},W.ref)}),C.hasMore&&e.jsxs("button",{type:"button",onClick:se,disabled:A,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:[A?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(wt,{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."}),F&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:F})]})]})}const Ui=20,Vi=3,kt="meshy-working-dir-recents-by-node";function Hi(s){return s.startsWith("/")||s.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(s)}function Ki(s){const t=s.trim();return t||"."}function St(s){const t=[],n=new Set;for(const o of s){const r=o.trim();if(!(!r||n.has(r))&&(n.add(r),t.push(r),t.length===Vi))break}return t}function qi(s,t){const n=t.trim();return St(n?[n,...s]:s)}function mn(s){if(!s||typeof s!="object"||Array.isArray(s))return{};const t={};for(const[n,o]of Object.entries(s)){if(!n||!Array.isArray(o))continue;const r=o.filter(g=>typeof g=="string"),i=St(r);i.length>0&&(t[n]=i)}return t}function Wi(s,t,n){if(!t)return s;const o=s[t]??[],r=qi(o,n);if(r.length===0){if(!(t in s))return s;const{[t]:i,...g}=s;return g}return{...s,[t]:r}}function Gi(s,t){var n;return t?((n=s[t])==null?void 0:n[0])??"":""}function xn(s){if(!s||typeof window>"u")return"";try{const t=window.localStorage.getItem(kt);return t?Gi(mn(JSON.parse(t)),s):""}catch{return""}}function Qi(s,t,n){return s!=="auto"?t.find(o=>o.id===s)??null:n.length===1?n[0]??null:null}function Yi(s,t){const n=t.trim();return n?Hi(n)||!s?n:`${s.replace(/[/\\]+$/,"")}/${n}`:""}function Xi(s,t){return s?s.isAbsolute?s.currentPath:s.currentPath==="."||s.currentPath===""?s.rootPath||(t==null?void 0:t.workDir)||"Node root":s.currentPath:(t==null?void 0:t.workDir)??"Node root"}function Hs({value:s,onChange:t,assignTo:n,nodes:o,assignableNodes:r,layout:i="default",chipClassName:g,chipActiveClassName:b,chipInactiveClassName:N,labelClassName:v,triggerClassName:f,popoverPlacement:l="bottom",popoverAlign:u="start"}){const[w,S]=a.useState(!1),[x,j]=a.useState(null),[c,p]=a.useState(!1),[k,A]=a.useState(!1),[L,O]=a.useState(null),[T,F]=a.useState(""),[U,M]=a.useState(!1),[P,E]=a.useState({}),J=a.useRef(null),V=a.useMemo(()=>Qi(n,o,r),[n,o,r]),X=V==null?void 0:V.id,ce=a.useMemo(()=>X?P[X]??[]:[],[P,X]),ae=a.useMemo(()=>s.trim()?Yi(V==null?void 0:V.workDir,s):"Use node default",[s,V==null?void 0:V.workDir]);a.useEffect(()=>{if(!(typeof window>"u"))try{const m=window.localStorage.getItem(kt);if(!m)return;const $=JSON.parse(m);E(mn($))}catch{}},[]);const ee=a.useCallback(m=>{X&&E($=>{const q=Wi($,X,m);if(q===$)return $;if(typeof window<"u")try{window.localStorage.setItem(kt,JSON.stringify(q))}catch{}return q})},[X]),Z=a.useCallback((m,$=!0)=>{const q=m.trim();t(q),$&&q&&ee(q),S(!1)},[t,ee]),H=a.useCallback(async(m,$=0,q=!1)=>{if(X){O(null),q?A(!0):p(!0);try{const ne=await cr(X,{path:m,limit:Ui,offset:$,directoriesOnly:!0,allowAbsolute:!0});j(W=>q&&W?{...ne,entries:[...W.entries,...ne.entries]}:ne)}catch(ne){O(ne instanceof Error?ne.message:"Failed to browse directories"),q||j(null)}finally{p(!1),A(!1)}}},[X]),K=a.useRef(s);K.current=s;const re=a.useRef(H);re.current=H,a.useEffect(()=>{if(!w)return;const m=K.current;F(m),M(!1),j(null),O(null),X&&re.current(Ki(m))},[w,X]),a.useEffect(()=>{if(!w)return;const m=q=>{J.current&&(J.current.contains(q.target)||S(!1))},$=q=>{q.key==="Escape"&&S(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",$),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",$)}},[w]);const xe=a.useCallback(m=>{H(m)},[H]),h=a.useCallback(()=>{x&&H(x.currentPath,x.entries.length,!0)},[x,H]),I=i==="composer"?e.jsxs(z,{type:"button",variant:"ghost",onClick:()=>S(m=>!m),title:ae,"aria-label":`Working directory: ${ae}`,className:B(g,f,"min-w-0 max-w-full",s.trim()?b:N),children:[e.jsx(ur,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:B("min-w-0 truncate",v),children:ae})]}):e.jsxs(z,{type:"button",variant:"outline",onClick:()=>S(m=>!m),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:ae,children:[e.jsx("span",{className:B("truncate",s.trim()?"font-mono text-foreground":"text-muted-foreground"),children:ae}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:V?V.name:"Manual"})]}),C=Xi(x,V),se=!!(x!=null&&x.parentPath);return e.jsxs("div",{className:B("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":l,"data-workdir-popover-align":u,ref:J,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Working directory"}),I]}):I,w&&e.jsxs("div",{className:B("absolute z-50 flex max-h-[min(28rem,calc(100vh-5rem))] w-[240px] flex-col overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",l==="top"?"bottom-full mb-2":"top-full mt-2",i==="composer"?u==="end"?"right-0":"left-0":u==="end"?"right-0 w-auto min-w-[240px]":"left-0 right-0 w-auto min-w-[240px]"),children:[ce.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(wt,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:ce.map(m=>e.jsx("button",{type:"button",onClick:()=>Z(m),className:"truncate rounded px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:m,children:m},m))})]}),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:()=>(x==null?void 0:x.parentPath)&&xe(x.parentPath),disabled:!se||c,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($o,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:C,children:C}),x&&e.jsx("button",{type:"button",onClick:()=>Z(x.isAbsolute?x.currentPath:x.currentPath==="."?"":x.currentPath),className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium text-foreground hover:bg-background/60",title:"Use this folder",children:"Use"})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[V?c?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(me,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):x&&x.entries.length>0?e.jsxs(e.Fragment,{children:[x.entries.map(m=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Z(m.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 ${m.path}`,children:[e.jsx(Oa,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:m.name})]}),e.jsx("button",{type:"button",onClick:()=>xe(m.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 ${m.name}`,children:e.jsx(Ms,{className:"h-3.5 w-3.5"})})]},m.path)),x.hasMore&&e.jsxs("button",{type:"button",onClick:h,disabled:k,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[k?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(wt,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:L??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),L&&x&&x.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:L})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:U?e.jsxs(e.Fragment,{children:[e.jsx(Xe,{value:T,onChange:m=>F(m.target.value),onKeyDown:m=>{m.key==="Enter"&&T.trim()?(m.preventDefault(),Z(T)):m.key==="Escape"&&(m.preventDefault(),M(!1),F(s))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>Z(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(As,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{M(!1),F(s)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(rs,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{F(s),M(!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(ys,{className:"h-3 w-3"})]})})]})]})}function hn(s,t={}){const n=s.filter(o=>o.status==="online");return t.currentNodeRole!=="follower"||!t.leaderNodeId?n:n.filter(o=>o.id!==t.leaderNodeId)}function Vt({isCurrent:s}){return s?e.jsx(Xo,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Wo,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function Ct(s,t){return s.map(n=>{const o=!!t&&n.id===t;return e.jsx(we,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Vt,{isCurrent:o}),e.jsx("span",{className:"truncate",children:n.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:o?"current":"remote"})]})},n.id)})}function Ji(s){var o;const t=s.sessionId.trim(),n=s.cwd.trim();return!t||!n||!s.assignTo?null:{title:s.title.trim()||((o=s.defaultTitle)==null?void 0:o.trim())||void 0,agent:s.agent,sessionId:t,cwd:n,assignTo:s.assignTo,priority:s.priority,mode:s.mode??Ls}}function Zi(){return hr.map(s=>e.jsx(we,{value:s.value,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:s.label}),s.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:s.description})]})},s.value))}function el(s){if(!s)return"unknown time";const t=Date.parse(s);return Number.isNaN(t)?s:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(t)}function ja(s){if(!s.updatedAt)return 0;const t=Date.parse(s.updatedAt);return Number.isNaN(t)?0:t}function sl(s,t){return ja(t)-ja(s)||s.sessionId.localeCompare(t.sessionId)}function tl(s){const t=s.trim().replace(/[\\/]+$/,"");return t?t.split(/[\\/]+/).filter(Boolean).at(-1)??t:"Unknown project"}function al(s){const t=new Map;for(const n of[...s].sort(sl)){const o=t.get(n.cwd);if(o){o.push(n);continue}t.set(n.cwd,[n])}return Array.from(t.entries()).map(([n,o])=>({folderName:tl(n),cwd:n,sessions:o}))}function nl(s,t){const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n}function rl({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,className:g,footerClassName:b,submitLabel:N="Load session",cancelLabel:v="Cancel",autoFocus:f=!1}){const l=a.useMemo(()=>hn(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),u=a.useMemo(()=>{var D;return n&&l.some(Q=>Q.id===n)?n:((D=l[0])==null?void 0:D.id)??""},[l,n]),[w,S]=a.useState(""),[x,j]=a.useState("codex"),[c,p]=a.useState(""),[k,A]=a.useState(""),[L,O]=a.useState(""),[T,F]=a.useState(u),[U,M]=a.useState("normal"),[P,E]=a.useState(Ls),[J,V]=a.useState(!1),[X,ce]=a.useState([]),[ae,ee]=a.useState(!1),[Z,H]=a.useState(null),K=a.useMemo(()=>X.find(D=>D.sessionId===c)??null,[X,c]);a.useEffect(()=>{T&&l.some(D=>D.id===T)||F(u)},[T,l,u]),a.useEffect(()=>{p(""),A(""),O("")},[x,T]),a.useEffect(()=>{let D=!1;return T?(ee(!0),H(null),mr(T,{agent:x,limit:50}).then(Q=>{D||ce(Q.sessions)}).catch(Q=>{D||(ce([]),H(Q instanceof Error?Q.message:"Failed to load native sessions"))}).finally(()=>{D||ee(!1)}),()=>{D=!0}):(ce([]),H(null),ee(!1),()=>{D=!0})},[x,T]),a.useEffect(()=>{K&&(A(K.sessionId),O(K.cwd))},[K]);const re=a.useCallback(async D=>{D.preventDefault();const Q=Ji({title:w,defaultTitle:K==null?void 0:K.summary,agent:x,sessionId:k,cwd:L,assignTo:T,priority:U,mode:P});if(Q){V(!0);try{const ge=await xr(Q);r(ge)}catch(ge){te.error(ge instanceof Error?ge.message:"Failed to load native session")}finally{V(!1)}}},[w,K,x,k,L,T,U,P,r]),xe=!!(k.trim()&&L.trim()&&T),[h,I]=a.useState(!1),[C,se]=a.useState(""),[m,$]=a.useState(()=>new Set),q=l.find(D=>D.id===T)??null,ne=!!(n&&(q==null?void 0:q.id)===n),W=a.useMemo(()=>{const D=C.trim().toLowerCase();return D?X.filter(Q=>Q.summary.toLowerCase().includes(D)||Q.sessionId.toLowerCase().includes(D)||Q.cwd.toLowerCase().includes(D)):X},[X,C]),ie=a.useMemo(()=>al(W),[W]),oe=a.useCallback(D=>{$(Q=>nl(Q,D))},[]),Te="h-9 w-auto gap-1.5 rounded-sm border-border/60 bg-background/60 px-3 text-xs shadow-none transition-colors hover:bg-background/80";return e.jsxs("form",{onSubmit:re,className:B("space-y-4",g),children:[e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/54 shadow-[0_24px_86px_-48px_rgba(15,23,42,0.55)] backdrop-blur-xl dark:shadow-[0_24px_86px_-48px_rgba(0,0,0,0.9)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/50 px-4 py-3",children:[e.jsxs(_e,{value:T,onValueChange:F,children:[e.jsx(Ee,{className:B(Te),"aria-label":"Node",children:q?e.jsxs(e.Fragment,{children:[e.jsx(Vt,{isCurrent:ne}),e.jsx("span",{className:"max-w-[10rem] truncate",children:q.name})]}):e.jsx(Ie,{placeholder:"Node"})}),e.jsx(De,{children:Ct(l,n)})]}),e.jsxs(_e,{value:x,onValueChange:D=>j(D),children:[e.jsxs(Ee,{className:B(Te),"aria-label":"Agent",children:[e.jsx(Rt,{agent:x}),e.jsx("span",{children:x})]}),e.jsx(De,{children:yo()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(it,{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(Xe,{value:C,onChange:D=>se(D.target.value),placeholder:"Filter sessions",className:"h-9 rounded-sm border-border/60 bg-background/60 pl-9 text-xs shadow-none"})]})]}),e.jsxs("div",{className:"px-3 py-3",children:[e.jsx("div",{className:"flex items-center justify-between px-1 pb-2",children:e.jsx(Re,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:ae?"Loading...":`${W.length} session${W.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-lg",children:[ae&&e.jsx("div",{className:"absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden bg-primary/10",children:e.jsx("div",{className:"h-full w-1/3 animate-indeterminate-bar bg-primary/70"})}),e.jsxs("div",{className:"h-full space-y-1.5 overflow-y-auto pr-1",children:[!T&&e.jsx("div",{className:"rounded-lg border border-dashed border-border/60 bg-background/35 px-4 py-6 text-center text-xs text-muted-foreground",children:"Pick a node to load its recent sessions."}),T&&!ae&&W.length===0&&e.jsx("div",{className:"rounded-lg border border-dashed border-border/60 bg-background/35 px-4 py-6 text-center text-xs text-muted-foreground",children:X.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),ie.map(D=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>oe(D.cwd),"aria-expanded":!m.has(D.cwd),className:"sticky top-0 z-[1] flex w-full items-center gap-2 border-b border-border/50 bg-background/95 px-1 py-1.5 text-left text-[10px] text-muted-foreground backdrop-blur transition-colors hover:bg-background",children:[e.jsx(ts,{className:B("h-3.5 w-3.5 shrink-0 transition-transform",m.has(D.cwd)&&"-rotate-90")}),e.jsx(Ot,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:D.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[D.sessions.length," session",D.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:D.cwd})]}),!m.has(D.cwd)&&D.sessions.map(Q=>{const ge=Q.sessionId===c;return e.jsxs("button",{type:"button",onClick:()=>p(Q.sessionId),className:B("flex w-full flex-col gap-1 rounded-lg border px-3 py-2.5 text-left transition-all duration-200 hover:-translate-y-px",ge?"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:B("h-2 w-2 shrink-0 rounded-full",ge?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:Q.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:el(Q.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:Q.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:Q.cwd})]})]},Q.sessionId)})]},D.cwd))]})]}),Z&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:Z})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:()=>I(D=>!D),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":h,children:[e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0}),e.jsx("span",{className:"shrink-0",children:h?"Less options":"More options"}),e.jsx(ts,{className:B("h-3.5 w-3.5 shrink-0 transition-transform",h&&"rotate-180")}),e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0})]}),h&&e.jsxs("div",{className:"space-y-4 rounded-xl border border-border/60 bg-background/35 p-4",children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Re,{htmlFor:"native-session-id",className:"text-xs font-medium text-muted-foreground",children:"Session ID"}),e.jsx(Xe,{id:"native-session-id",type:"text",value:k,onChange:D=>{p(""),A(D.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:f,className:"h-10 rounded-sm border-border/70 bg-background/70 font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Re,{htmlFor:"native-session-title",className:"text-xs font-medium text-muted-foreground",children:"Task title"}),e.jsx(Xe,{id:"native-session-title",type:"text",value:w,onChange:D=>S(D.target.value),placeholder:"Optional",className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm"})]})]}),e.jsx(Hs,{value:L,onChange:D=>{p(""),O(D)},assignTo:T,nodes:s,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(Re,{className:"text-xs font-medium text-muted-foreground",children:"Mode"}),e.jsxs(_e,{value:P,onValueChange:D=>E(D),children:[e.jsx(Ee,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Ie,{placeholder:"Select mode"})}),e.jsx(De,{children:Zi()})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Re,{className:"text-xs font-medium text-muted-foreground",children:"Priority"}),e.jsxs(_e,{value:U,onValueChange:M,children:[e.jsx(Ee,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Ie,{placeholder:"Select priority"})}),e.jsxs(De,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]})]})]})]})]}),e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",b),children:[i&&e.jsx(z,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:v}),e.jsx(z,{type:"submit",disabled:!xe||J,className:"rounded-sm px-5",children:J?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 animate-spin"})," Loading..."]}):N})]})]})}function fn(s,t,n=!1){const o=s.trim();if(o)return o;const r=t.trim().split(`
134
- `).map(i=>i.trim()).find(Boolean);return r?r.length>72?`${r.slice(0,69).trimEnd()}...`:r:n?"Image task":""}function ol(s){var g;const t=s.title.trim(),n=fn(s.title,s.description,s.images.length>0),o=s.description.trim()||n,r=s.mode??Ls,i=Xa(s.description,s.images);return!n||!o||!s.agent?null:{title:n,description:o,agent:s.agent,project:s.project.trim()||null,branch:((g=s.branch)==null?void 0:g.trim())||null,payload:{initialMessage:i,mode:r,titleSource:t?"manual":"derived"},priority:s.priority,assignTo:s.assignTo==="auto"?void 0:s.assignTo}}function il({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,className:g,footerClassName:b,submitLabel:N="Create chat",cancelLabel:v="Cancel",autoFocus:f=!1,layout:l="default"}){const[u,w]=a.useState(""),[S,x]=a.useState(""),[j,c]=a.useState(aa),[p,k]=a.useState(Ls),[A,L]=a.useState(""),[O,T]=a.useState(""),[F,U]=a.useState("normal"),M=a.useMemo(()=>hn(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),P=a.useMemo(()=>{var Y;return n&&M.some(be=>be.id===n)?n:((Y=M[0])==null?void 0:Y.id)??""},[M,n]),[E,J]=a.useState(P),[V,X]=a.useState(!1),[ce,ae]=a.useState(!1),{images:ee,error:Z,fileInputRef:H,pickImages:K,handleFileChange:re,handlePaste:xe,removeImage:h}=dn(),I=a.useMemo(()=>M.find(Y=>Y.id===E)??null,[E,M]),C=!!(n&&(I==null?void 0:I.id)===n),se=Za(j),m=ko(p);a.useEffect(()=>{E&&M.some(Y=>Y.id===E)||J(P)},[E,M,P]),a.useEffect(()=>{L(xn(E)),T("")},[E]),a.useEffect(()=>{T("")},[A]);const $=a.useCallback(async Y=>{Y.preventDefault();const be=ol({title:u,description:S,agent:j,project:A,branch:O,priority:F,assignTo:E,mode:p,images:ee});if(be){X(!0);try{const ye=await pr(be);r(ye)}catch(ye){te.error(ye instanceof Error?ye.message:"Failed to create task")}finally{X(!1)}}},[u,S,j,A,O,F,E,p,ee,r]),q=fn(u,S,ee.length>0),ne=!!(q&&j&&E&&(S.trim()||ee.length>0)),W=a.useCallback(Y=>{var be;Y.nativeEvent.isComposing||Y.key==="Enter"&&(Y.ctrlKey||Y.metaKey)&&ne&&!V&&(Y.preventDefault(),(be=Y.currentTarget.form)==null||be.requestSubmit())},[ne,V]),ie=ee.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:ee.map((Y,be)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Ja(Y),alt:Y.filename??`attachment ${be+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>h(be),className:"absolute -top-2 -right-2 flex h-6 w-6 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${Y.filename??`image ${be+1}`}`,children:e.jsx(rs,{className:"h-3.5 w-3.5"})})]},`${Y.filename??"image"}-${be}`))}),oe=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Assign to"}),e.jsxs(_e,{value:E,onValueChange:J,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ie,{placeholder:"Select node"})}),e.jsx(De,{children:Ct(M,n)})]})]}),Te=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Agent"}),e.jsxs(_e,{value:j,onValueChange:c,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ie,{placeholder:"Select agent"})}),e.jsx(De,{children:ua()})]})]}),D=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Mode"}),e.jsxs(_e,{value:p,onValueChange:Y=>k(Y),children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ie,{placeholder:"Select mode"})}),e.jsx(De,{children:ma()})]})]}),Q=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Priority"}),e.jsxs(_e,{value:F,onValueChange:U,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ie,{placeholder:"Select priority"})}),e.jsxs(De,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]})]}),ge=e.jsx(Hs,{value:A,onChange:L,assignTo:E,nodes:s,assignableNodes:M}),He=e.jsx(va,{value:O,onChange:T,project:A,assignTo:E,nodes:s,assignableNodes:M});return l==="composer"?e.jsxs("form",{onSubmit:$,className:B("space-y-4",g),children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:re,className:"hidden"}),(()=>{const Y="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",be="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",ye="border-border/70 bg-background/55 text-foreground",Je=j===aa,Be=p===Ls;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/54 shadow-[0_24px_86px_-48px_rgba(15,23,42,0.55)] backdrop-blur-xl dark:shadow-[0_24px_86px_-48px_rgba(0,0,0,0.9)]",children:[e.jsxs("div",{className:"chat-composer__header flex min-w-0 items-center justify-between gap-3 px-4 pt-3",children:[e.jsxs(_e,{value:E,onValueChange:J,children:[e.jsx(Ee,{className:B(Y,ye,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${(I==null?void 0:I.name)??"unassigned"}`,"aria-label":`Assigned node: ${(I==null?void 0:I.name)??"unassigned"}`,children:I?e.jsxs(e.Fragment,{children:[e.jsx(Vt,{isCurrent:C}),e.jsx("span",{className:"min-w-0 truncate",children:I.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:C?"current":"remote"})]}):e.jsx(Ie,{placeholder:"Select node"})}),e.jsx(De,{children:Ct(M,n)})]}),ce?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Xe,{id:"task-title-composer",type:"text",value:u,onChange:je=>w(je.target.value),onKeyDown:je=>{(je.key==="Enter"||je.key==="Escape")&&(je.preventDefault(),ae(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>ae(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(As,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>ae(!0),className:"chat-composer__title-button flex min-w-0 items-center gap-1.5 rounded-sm px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-background/55 hover:text-foreground",title:q||"Title","aria-label":q?`Edit title: ${q}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:q||"Title"}),e.jsx(ys,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:S,onChange:je=>x(je.target.value),onKeyDown:W,onPaste:xe,placeholder:"Ask anything...",rows:4,autoFocus:f,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-xl bg-transparent px-5 pt-2 pb-2 text-xs leading-5 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsxs("div",{className:"chat-composer__rail flex flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:K,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(yt,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(_e,{value:j,onValueChange:c,children:[e.jsxs(Ee,{className:B(Y,"chat-composer__icon-trigger",Je?be:ye),title:`Agent: ${se}`,"aria-label":`Agent: ${se}`,children:[e.jsx(Rt,{agent:j}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:se})]}),e.jsx(De,{children:ua()})]}),e.jsxs(_e,{value:p,onValueChange:je=>k(je),children:[e.jsxs(Ee,{className:B(Y,"chat-composer__icon-trigger",Be?be:ye),title:`Mode: ${m}`,"aria-label":`Mode: ${m}`,children:[e.jsx(fi,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:m})]}),e.jsx(De,{children:ma()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(_e,{value:F,onValueChange:U,children:[e.jsx(Ee,{"aria-label":`Priority: ${F}`,title:`Priority: ${F}`,className:B("h-9 w-9 justify-center gap-0 rounded-sm p-0 text-xs shadow-none [&>svg:last-child]:hidden",F==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",F==="critical"&&"text-destructive",F==="high"&&"text-amber-600 dark:text-amber-400",F==="low"&&"text-muted-foreground"),children:e.jsx(zo,{className:B("h-4 w-4",F==="critical"&&"fill-destructive/20")})}),e.jsxs(De,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]}),i&&e.jsxs(z,{type:"button",variant:"ghost",size:"sm",onClick:i,"aria-label":v,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(rs,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:v})]}),e.jsxs(z,{type:"submit",size:"icon",disabled:!ne||V,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[V?e.jsx(me,{className:"h-4 w-4 animate-spin"}):e.jsx(nn,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:V?"Creating chat":N})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const je="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{value:A,onChange:L,assignTo:E,nodes:s,assignableNodes:M,layout:"composer",chipClassName:Y,chipActiveClassName:je,chipInactiveClassName:je,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(va,{value:O,onChange:T,project:A,assignTo:E,nodes:s,assignableNodes:M,layout:"composer",chipClassName:Y,chipActiveClassName:je,chipInactiveClassName:je,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(ie||Z)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 bg-background/45 p-4",children:[ie,Z&&e.jsx("div",{className:"text-xs text-destructive",children:Z}),!Z&&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:$,className:B("space-y-5",g),children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:re,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{htmlFor:"task-description",className:"text-sm font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:S,onChange:Y=>x(Y.target.value),onKeyDown:W,onPaste:xe,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:f,className:"flex min-h-[144px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-xl border border-border/70 bg-background/70 px-4 py-3 text-sm leading-6 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(z,{type:"button",variant:"outline",onClick:K,className:"rounded-sm",children:[e.jsx(yt,{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."})]}),ie,Z&&e.jsx("p",{className:"text-xs text-destructive",children:Z})]}),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(Re,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(Xe,{id:"task-title",type:"text",value:u,onChange:Y=>w(Y.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-11 rounded-lg border-border/70 bg-background/70"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:q?`Will appear as: ${q}`:"A title will be generated from the first line of the prompt."})]}),Te,D]}),ge,He,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[Q,oe]}),e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",b),children:[i&&e.jsx(z,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:v}),e.jsx(z,{type:"submit",disabled:!ne||V,className:"rounded-sm px-5",children:V?"Creating...":N})]})]})}function ll({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,defaultMode:g="chat",mode:b,onModeChange:N,layout:v="default",className:f,footerClassName:l,autoFocus:u=!1}){const[w,S]=a.useState(g),x=b!==void 0,j=x?b:w,c=p=>{x||S(p),N==null||N(p)};return e.jsxs("div",{className:B("space-y-4",f),children:[!x&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 bg-background/45 p-1",children:[e.jsxs(z,{type:"button",variant:j==="chat"?"default":"ghost",onClick:()=>c("chat"),className:"flex-1 rounded-sm",children:[e.jsx(fr,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(z,{type:"button",variant:j==="native"?"default":"ghost",onClick:()=>c("native"),className:"flex-1 rounded-sm",children:[e.jsx(Ft,{className:"h-4 w-4"}),"Load session"]})]}),j==="chat"?e.jsx(il,{nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,footerClassName:l,submitLabel:v==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:u,layout:v}):e.jsx(rl,{nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,footerClassName:l,autoFocus:u})]})}const vs="72f988bf-86f1-41af-91ab-2d7cd011db47",pn=`${vs} (MSIT)`;function dl({open:s,onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i=!1,shareResult:g}){return e.jsx(At,{open:s,onOpenChange:t,children:e.jsxs(Mt,{className:"max-w-md rounded-xl p-5",children:[e.jsx(Lt,{className:"sr-only",children:"Share conversation"}),e.jsx(cl,{onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i,shareResult:g})]})})}function cl({onOpenChange:s,onShare:t,onStopShare:n,sharing:o,stopping:r=!1,shareResult:i}){const[g,b]=a.useState((i==null?void 0:i.tenant)??vs),[N,v]=a.useState((i==null?void 0:i.scope)??"chat"),f=i!=null&&i.url?Fa(i.url):null,l=o||r;return a.useEffect(()=>{b((i==null?void 0:i.tenant)??vs),v((i==null?void 0:i.scope)??"chat")},[i==null?void 0:i.shareId,i==null?void 0:i.tenant,i==null?void 0:i.scope]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-base font-semibold leading-none tracking-tight",children:"Share conversation"}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:"Create a tenant-gated link for this task."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(ul,{value:g,onChange:b,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(Na,{active:N==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>v("chat")}),e.jsx(Na,{active:N==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>v("filesPreview")})]})]}),f&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Shared link"}),e.jsxs("div",{className:"flex items-center gap-2 rounded-sm border border-border/70 bg-muted/30 px-3 py-2",children:[e.jsx("input",{readOnly:!0,value:f,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void bs(f,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ia,{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(z,{variant:"outline",onClick:()=>s(!1),disabled:l,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(z,{variant:"outline",onClick:()=>void n(),disabled:l,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[r&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(z,{onClick:()=>void t({tenant:g,scope:N}),disabled:l,className:"h-8 text-xs",children:[o&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function ul({value:s,onChange:t,disabled:n}){const[o,r]=a.useState(!1),[i,g]=a.useState(!1),[b,N]=a.useState(s),v=a.useRef(null);a.useEffect(()=>{N(s)},[s]),a.useEffect(()=>{if(!o)return;const l=w=>{var x;const S=w.target;S instanceof Node&&((x=v.current)!=null&&x.contains(S)||(r(!1),g(!1)))},u=w=>{w.key==="Escape"&&(r(!1),g(!1))};return document.addEventListener("mousedown",l),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",u)}},[o]);const f=l=>{const u=l.trim();u&&(t(u),N(u),g(!1),r(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:v,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&r(l=>!l),disabled:n,className:"flex h-9 w-full items-center justify-between gap-2 rounded-sm border border-border/70 bg-background/70 px-3 text-left text-xs text-foreground shadow-sm outline-none transition-colors hover:bg-background disabled:opacity-50",children:[e.jsx("span",{className:"min-w-0 truncate font-mono",children:ml(s)}),e.jsx(ts,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),o&&e.jsxs("div",{className:"absolute left-0 right-0 z-50 mt-2 overflow-hidden rounded-lg border border-border/60 bg-background/95 text-xs shadow-lg backdrop-blur",children:[e.jsxs("button",{type:"button",onClick:()=>f(vs),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:pn}),s===vs&&e.jsx(As,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]}),e.jsx("div",{className:"border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:i?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:b,onChange:l=>N(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),f(b))},autoFocus:!0,placeholder:"Tenant ID",className:"h-7 min-w-0 flex-1 rounded-sm border border-border/60 bg-background/70 px-2 font-mono text-[11px] outline-none focus:ring-2 focus:ring-ring"}),e.jsx("button",{type:"button",onClick:()=>f(b),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(As,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{N(s),g(!1)},className:"flex h-7 w-7 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",children:e.jsx(rs,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>g(!0),className:"flex h-7 w-full items-center justify-between rounded-sm px-1.5 text-[11px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx("span",{children:"Manual tenant ID"}),e.jsx(ys,{className:"h-3 w-3"})]})})]})]})]})}function ml(s){return s===vs?pn:s}function Na({active:s,title:t,description:n,onClick:o}){return e.jsxs("button",{type:"button",onClick:o,className:s?"rounded-sm border border-primary/45 bg-primary/10 px-3 py-2 text-left shadow-sm":"rounded-sm border border-border/70 bg-background px-3 py-2 text-left shadow-sm hover:bg-muted/50",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:t}),e.jsx("div",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:n})]})}function xl(s){const t=s.map(n=>n.type==="text"?n.text:n.type==="image"?n.filename?`Image: ${n.filename}`:"Image attachment":n.isError?`Tool result error: ${n.content}`:`Tool result: ${n.content}`).join(" ").replace(/\s+/g," ").trim();return t?t.length>160?`${t.slice(0,157)}...`:t:"Queued follow-up"}function hl({messages:s,onCancelMessage:t}){return s.length===0?null:e.jsx("div",{className:"border-t border-border/55 bg-card/30 px-3 py-2 sm:px-5",children:e.jsxs("div",{className:"mx-auto max-w-[72rem] rounded-sm border border-border/65 bg-background/58 px-3 py-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-medium text-foreground",children:[e.jsx(ei,{className:"h-3.5 w-3.5 text-primary"}),"Queued messages",e.jsx("span",{className:"ml-auto rounded-sm border border-border/60 bg-muted/60 px-1.5 py-0 text-[10px] text-muted-foreground",children:s.length})]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:s.map((n,o)=>e.jsxs("div",{className:"flex min-w-0 items-start gap-2 text-[11px] leading-5 text-muted-foreground",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-[10px] font-medium text-primary",children:o+1}),e.jsx("span",{className:"min-w-0 flex-1 break-words [overflow-wrap:anywhere]",children:xl(n.content)}),t&&e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground hover:text-destructive",title:"Cancel queued message","aria-label":"Cancel queued message",onClick:()=>t(n.id),children:e.jsx(rs,{className:"h-3 w-3"})})]},n.id))})]})})}const fl=30;function pl({savedScrollTop:s,scrollHeight:t,clientHeight:n}){const o=Math.max(0,t-n);return Math.min(Math.max(0,s??o),o)}function at(s){return s.scrollHeight-s.scrollTop-s.clientHeight<fl}function gl({activeTab:s,activeTaskId:t,contentVersion:n,setActiveTab:o,setInputCollapsed:r}){const i=a.useRef(null),g=a.useRef(t),b=a.useRef(!1),N=a.useRef(0),v=a.useRef(new Map),f=a.useRef(!0),l=a.useCallback((x=g.current)=>{const j=i.current;!j||!x||(v.current.set(x,j.scrollTop),N.current=j.scrollTop,f.current=at(j))},[]),u=a.useCallback((x=g.current)=>{const j=i.current;!j||!x||(j.scrollTop=pl({savedScrollTop:v.current.get(x),scrollHeight:j.scrollHeight,clientHeight:j.clientHeight}),N.current=j.scrollTop,f.current=at(j))},[]),w=a.useCallback(x=>{const j=x.currentTarget,c=N.current;if(l(),!b.current){if(at(j)){r(!1),b.current=!0,setTimeout(()=>{b.current=!1},300);return}j.scrollTop<c&&c-j.scrollTop>10&&r(!0),j.scrollTop<=0&&r(!0)}},[l,r]),S=a.useCallback(x=>{s==="transcript"&&l(),o(x),x==="transcript"&&requestAnimationFrame(()=>u())},[s,u,l,o]);return a.useLayoutEffect(()=>{const x=g.current;x&&x!==t&&l(x),g.current=t,s==="transcript"&&requestAnimationFrame(()=>u(t))},[t,s,u,l]),a.useLayoutEffect(()=>{const x=i.current;!x||s!=="transcript"||!t||(f.current&&(x.scrollTop=x.scrollHeight),l(t))},[t,s,n,l]),{handleTranscriptScroll:w,handleTranscriptTabChange:S,transcriptScrollRef:i}}function gn(s=700){const[t,n]=a.useState(!1),o=a.useRef(null),r=a.useCallback(()=>{n(!0),o.current!==null&&clearTimeout(o.current),o.current=setTimeout(()=>{n(!1),o.current=null},s)},[s]);return a.useEffect(()=>()=>{o.current!==null&&clearTimeout(o.current)},[]),{markScrollbarActive:r,scrollbarActive:t}}const Ht="h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",js="h-3.5 w-3.5",bl=a.lazy(async()=>({default:(await Pt(()=>import("./FilesTab--hSaHvs5.js"),__vite__mapDeps([0,1,2,3,4]))).FilesTab})),vl=a.lazy(async()=>({default:(await Pt(()=>import("./PreviewTab-Bw9zg0Zf.js"),__vite__mapDeps([5,1,2,6]))).PreviewTab})),jl=a.lazy(async()=>({default:(await Pt(()=>import("./DiffTab-DQ7FWefY.js"),__vite__mapDeps([7,1,2,3,4,6]))).DiffTab}));function Nl({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,activeTab:b,setActiveTab:N,creatingTask:v,createMode:f,activeTask:l,assignedNode:u,taskLoading:w,transcriptLoading:S,taskError:x,displayEvents:j,initialPromptAlreadyInLogs:c,initialPrompt:p,supportsFollowUp:k,taskUnavailable:A,chatDisabled:L,chatDisabledReason:O,questionBypassEnabled:T,isRunning:F,isStarting:U,hasPendingFollowUp:M,canCancel:P,canRetry:E,onRetry:J,onCancel:V,onReloadNativeTranscript:X,onShareTask:ce,onStopShareTask:ae,onStartCreateTask:ee,onCancelCreateTask:Z,onCreateTask:H,onSendMessage:K,onCancelQueuedMessage:re,onQuestionBypassChange:xe,onSubmitQuestionResponse:h}){const[I,C]=a.useState(!1),[se,m]=a.useState(!1),[$,q]=a.useState(!1),[ne,W]=a.useState(!1),[ie,oe]=a.useState(!1),[Te,D]=a.useState({}),[Q,ge]=a.useState(new Set),[He,Y]=a.useState(new Set),be=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",ye=l?(u==null?void 0:u.name)??lt(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",Je=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:ye}),"..."]}):"Connecting session to an available node...",Be=l?[{label:"Working dir",value:be,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:ye}]:[],je=!!(p&&!c),Ye=je||j.length>0,ke=F&&Ye,Ae=(U||M||F)&&!ke,Ze=(l==null?void 0:l.conversationKind)==="nativeSession",ms=S?"Loading transcript":Ze?"No transcript imported":"Transcript is warming up",as=S?"Loading transcript...":Ze?"Meshy could not find imported history for this native session yet.":"The opening prompt has been stored, but the agent has not emitted conversation output yet.",os=(l==null?void 0:l.queuedMessages)??[],is=a.useMemo(()=>So(j),[j]),xs=a.useMemo(()=>Co("transcript",is.map(Le=>Le.event)),[is]),$e=l&&!Q.has(l.id)?Te[l.id]??l.activeShare??null:null,ls=(l==null?void 0:l.id)??null,Me=`${ls??"none"}:${j.length}:${os.length}:${je?1:0}:${S?1:0}`,{handleTranscriptScroll:hs,handleTranscriptTabChange:_,transcriptScrollRef:fe}=gl({activeTab:b,activeTaskId:ls,contentVersion:Me,setActiveTab:N,setInputCollapsed:C}),{markScrollbarActive:ue,scrollbarActive:ze}=gn(),We=a.useCallback(Le=>{ue(),hs(Le)},[hs,ue]);return v?e.jsx(wl,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,defaultMode:f,onCancel:Z,onCreated:H}):!l&&w?e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(_t,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(me,{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(me,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(za,{value:b,onValueChange:_,className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(bn,{desktopTasksOpen:t,mobileTasksPanelOpen:n,onToggleTasks:s}),e.jsx("h2",{className:"min-w-0 truncate text-sm font-semibold tracking-tight text-foreground sm:text-lg",title:l.title,children:l.title}),e.jsx(Ua,{status:l.status,isNative:Ze}),l.priority!=="normal"&&e.jsx(br,{priority:l.priority}),e.jsx(z,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:B("ml-auto",Ht),children:o?e.jsx(zt,{className:js}):e.jsx(an,{className:js})})]}),x&&e.jsx("div",{className:"mt-2 w-fit rounded-sm border border-destructive/25 bg-destructive/10 px-2 py-1 text-[11px] text-destructive",children:x}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsxs(Va,{className:"h-auto max-w-full overflow-x-auto rounded-sm bg-muted/70 p-0.5",children:[e.jsx(ds,{value:"transcript",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Transcript"}),e.jsx(ds,{value:"files",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Files"}),e.jsx(ds,{value:"preview",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Preview"}),e.jsx(ds,{value:"diff",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Diff"})]}),A&&e.jsx(Ke,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsxs("span",{className:"hidden sm:inline",children:["updated ",vr(l.updatedAt)]}),e.jsx("span",{className:"font-mono",children:l.id.slice(0,8)}),E&&e.jsxs(z,{variant:"outline",size:"sm",onClick:J,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(fa,{className:"h-3.5 w-3.5"}),"Retry"]}),Ze&&X&&e.jsx(z,{variant:"ghost",size:"icon",onClick:X,disabled:S,title:"Reload native session transcript","aria-label":"Reload native session transcript",className:"h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",children:e.jsx(fa,{className:B("h-3.5 w-3.5",S&&"animate-spin")})}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",disabled:A,title:A?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":A?"Unavailable tasks cannot be shared.":"Share conversation",className:"h-6 w-6 shrink-0 rounded-sm text-primary hover:bg-primary/10 hover:text-primary disabled:bg-transparent disabled:text-muted-foreground",onClick:()=>q(!0),children:e.jsx(xi,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(cs,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{ref:fe,className:B("scrollbar-line min-h-0 flex-1 touch-pan-y overflow-x-hidden overflow-y-auto overscroll-x-none bg-gradient-to-b from-background/15 via-transparent to-background/35 px-3 py-5 sm:px-5",ze&&"scrollbar-line-active"),onScroll:We,children:e.jsxs("div",{className:"mx-auto flex max-w-[72rem] flex-col gap-5",children:[je&&p&&e.jsx(xa,{event:p,agent:l.agent,questionBypassEnabled:T,onQuestionBypassChange:xe,onSubmitQuestionResponse:h,questionResponseDisabled:!k||L}),is.map(({event:Le,subItems:ve},Ne)=>e.jsx(xa,{event:Le,agent:l.agent,subItems:ve,questionBypassEnabled:T,onQuestionBypassChange:xe,onSubmitQuestionResponse:h,questionResponseDisabled:!k||L},xs[Ne])),!Ye&&!Ae&&e.jsxs("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-5 py-8 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:ms}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:as})]}),(!k&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!k&&l.result&&e.jsxs("div",{className:"rounded-xl border border-border/70 bg-card/80 px-3 py-3",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:"Stored result"}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5 text-muted-foreground",children:JSON.stringify(l.result,null,2)})]}),l.error&&!He.has(l.id)&&e.jsxs("div",{className:"rounded-xl border border-destructive/20 bg-destructive/10 px-3 py-3 text-destructive",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em]",children:"Stored error"}),e.jsx("button",{onClick:()=>Y(Le=>new Set(Le).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(rs,{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})]})]}),Ae&&e.jsx(wa,{children:Je}),ke&&e.jsx(wa,{children:"The agent is still working on this conversation."})]})}),k?e.jsxs(e.Fragment,{children:[I&&e.jsx(z,{size:"icon",onClick:()=>C(!1),className:"absolute bottom-4 right-4 z-10 h-12 w-12 rounded-lg shadow-lg",children:e.jsx(ys,{className:"h-4 w-4"})}),e.jsxs("div",{className:`shrink-0 ${I?"hidden":""}`,children:[e.jsx(hl,{messages:os,onCancelMessage:re}),e.jsx(Mi,{onSend:K,disabled:L,disabledReason:O,contextItems:Be,placeholder:L?O:F?"Queue a message for the next turn...":"Continue the conversation...",running:F||M,onStop:P?()=>m(!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(cs,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(st,{label:"Loading files..."}),children:e.jsx(bl,{taskId:l.id})})}),e.jsx(cs,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(st,{label:"Loading preview..."}),children:e.jsx(vl,{taskId:l.id})})}),e.jsx(cs,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(st,{label:"Loading diff..."}),children:e.jsx(jl,{taskId:l.id})})}),e.jsx(dt,{open:se,onOpenChange:m,children:e.jsxs(ct,{children:[e.jsxs(ut,{children:[e.jsx(mt,{children:"Stop this task?"}),e.jsx(xt,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ht,{children:[e.jsx(ft,{children:"Keep running"}),e.jsx(pt,{onClick:V,children:"Stop task"})]})]})}),e.jsx(dl,{open:$,onOpenChange:q,sharing:ne,stopping:ie,shareResult:$e,onShare:async Le=>{if(!l)return null;W(!0);try{const ve=await ce(Le);return ve!=null&&ve.url&&(D(Ne=>({...Ne,[l.id]:ve})),ge(Ne=>{const es=new Set(Ne);return es.delete(l.id),es})),ve}finally{W(!1)}},onStopShare:async()=>{if(!l)return!1;oe(!0);try{const Le=await ae();return Le!==!1&&(D(ve=>{const Ne={...ve};return delete Ne[l.id],Ne}),ge(ve=>new Set(ve).add(l.id))),Le}finally{oe(!1)}}})]}):e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(_t,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(gr,{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(z,{onClick:ee,className:"mt-6 rounded-lg px-5",children:[e.jsx(It,{className:"h-4 w-4"}),"Start or load chat"]}),x&&e.jsx("div",{className:"mx-auto mt-4 max-w-lg rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:x})]})})]})}function wa({children:s}){return e.jsxs("div",{className:"agent-progress-banner flex items-center gap-1.5 rounded-lg bg-transparent px-1 py-1 text-[11px]",children:[e.jsx("span",{className:"agent-progress-terminal-spinner h-4 w-4 shrink-0","aria-hidden":"true"}),e.jsx("div",{className:"agent-progress-sweep-text min-w-0 leading-5",children:s})]})}function wl({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,defaultMode:b,onCancel:N,onCreated:v}){var w,S,x;const[f,l]=a.useState(b??"chat");a.useEffect(()=>{b&&l(b)},[b]);const u=e.jsx("div",{className:"flex items-center gap-1 rounded-lg border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-sm",children:[{value:"chat",label:"New chat",icon:It},{value:"native",label:"Load session",icon:Ft}].map(j=>{const c=j.icon,p=j.value===f;return e.jsxs("button",{type:"button",onClick:()=>l(j.value),"aria-pressed":p,className:B("flex items-center gap-1.5 rounded-sm px-2 py-1 transition-all duration-200",p?"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(c,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:j.label})]},j.value)})});return e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(_t,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,centerSlot:u})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(ll,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(w=i==null?void 0:i.self)==null?void 0:w.role,currentNodeId:((S=i==null?void 0:i.self)==null?void 0:S.id)??null,leaderNodeId:((x=i==null?void 0:i.leader)==null?void 0:x.id)??null,mode:f,onModeChange:l,onCreated:v,onCancel:N,autoFocus:!0,layout:"composer"})})})]})}function _t({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,centerSlot:i}){return e.jsxs("div",{className:"relative flex w-full items-center justify-between gap-1.5",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:e.jsx(bn,{desktopTasksOpen:t,mobileTasksPanelOpen:n,onToggleTasks:s})}),i&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",children:e.jsx("div",{className:"pointer-events-auto",children:i})}),e.jsx(z,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:Ht,children:o?e.jsx(zt,{className:js}):e.jsx(an,{className:js})})]})}function bn({desktopTasksOpen:s,mobileTasksPanelOpen:t,onToggleTasks:n}){var r,i;const o=(i=(r=globalThis.window)==null?void 0:r.matchMedia("(min-width: 1024px)"))!=null&&i.matches?s:t;return e.jsx(z,{variant:"ghost",size:"icon",onClick:n,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:Ht,children:o?e.jsx(tn,{className:js}):e.jsx(ni,{className:js})})}function yl({onAdded:s}){const[t,n]=a.useState(""),[o,r]=a.useState(!1),[i,g]=a.useState(null),b=a.useCallback(async N=>{if(N.preventDefault(),!!t.trim()){r(!0),g(null);try{await jr({leaderEndpoint:t.trim(),transport:"devtunnel"}),s()}catch(v){g(v instanceof Error?v.message:"Failed to join node")}finally{r(!1)}}},[t,s]);return e.jsx(Mt,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-xl border border-border/60 bg-background/95 p-0 shadow-[0_40px_120px_-60px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-6 py-5",children:e.jsxs(Ha,{className:"space-y-2 text-left",children:[e.jsx(Lt,{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:b,className:"space-y-4 px-6 py-5",children:[i&&e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Re,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(Xe,{id:"leader-endpoint",type:"url",value:t,onChange:N=>n(N.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-11 rounded-lg border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-lg border border-border/60 bg-background/45 px-4 py-3 text-sm text-muted-foreground",children:"This does not switch the local node transport or auto-enable a local DevTunnel. Leaving later will detach this node from the remote leader and make it leader of its own cluster again."}),e.jsx(Ka,{className:"border-t border-border/60 pt-4",children:e.jsx(z,{type:"submit",disabled:!t.trim()||o,className:"rounded-sm",children:o?"Joining...":"Join node"})})]})]})})}function kl({open:s,onOpenChange:t,onAdded:n}){return e.jsx(At,{open:s,onOpenChange:t,children:e.jsx(yl,{onAdded:()=>{t(!1),n()}})})}function nt({className:s,label:t,orientation:n,panel:o,panelResize:r}){return e.jsx("button",{type:"button","aria-label":t,"aria-orientation":n,"data-dashboard-resize-handle":o,onPointerDown:i=>r.onPointerDown(o,i),onWheel:i=>r.onWheel(o,i),className:B("group absolute z-20 hidden touch-none rounded-sm bg-transparent outline-none transition-colors hover:bg-primary/12 focus-visible:bg-primary/12 focus-visible:ring-2 focus-visible:ring-ring/70 lg:block",s),children:e.jsx("span",{className:"pointer-events-none absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"})})}function Sl({conversationPanel:s,desktopTasksOpen:t,mobileTaskSidebar:n,mobileTasksPanelOpen:o,mobileTasksPanelRef:r,operationsOpen:i,operationsPanelRef:g,operationsSidecar:b,panelResize:N,taskSidebar:v,terminalPanel:f,onCloseOperations:l,onCloseTaskList:u}){const w={"--dashboard-tasks-width":N.sizes.tasks,"--dashboard-operations-width":N.sizes.operations,"--dashboard-terminal-height":N.sizes.terminal};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",style:w,children:[e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsx("div",{className:B("relative hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",t?"lg:mr-2 lg:w-[var(--dashboard-tasks-width)]":"lg:w-0 lg:overflow-hidden"),children:t&&e.jsxs(e.Fragment,{children:[v,e.jsx(nt,{panel:"tasks",orientation:"vertical",label:"Resize tasks panel",panelResize:N,className:"-right-1 top-0 h-full w-2 cursor-col-resize"})]})}),e.jsxs("section",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-2",children:[e.jsx("div",{className:"min-h-0 flex-1",children:s}),f&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(nt,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:N,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),f]})]}),e.jsx("div",{className:B("relative hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",i?"xl:ml-2 xl:w-[var(--dashboard-operations-width)]":"xl:w-0 xl:overflow-hidden"),children:i&&e.jsxs(e.Fragment,{children:[e.jsx(nt,{panel:"operations",orientation:"vertical",label:"Resize operations panel",panelResize:N,className:"-left-1 top-0 h-full w-2 cursor-col-resize"}),b]})})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:l,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:g,className:"fixed inset-y-0 right-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:b})]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:u,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:r,className:"fixed inset-y-0 left-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:n})]})]})}const Cl=10,us="__all__";function qe(s){return"session"in s}function ya(s,t){var n;return t&&s.some(o=>o.id===t)?t:((n=s[0])==null?void 0:n.id)??""}function rt(s){return s&&(xn(s.id)||s.workDir)||""}function Fs(s,t,n){let o=!1;const r=s.map(i=>qe(i)&&i.session.id===n.id?(o=!0,{...i,nodeName:t,session:n}):i);return Et(o?r:[...r,{id:`session-${n.id}`,nodeName:t,session:n}])}function vn(s,t){return s.filter(qe).filter(n=>n.session.nodeId===t).sort((n,o)=>o.session.startedAt-n.session.startedAt)}function _l(s){const t=s.filter(qe).sort((n,o)=>o.session.startedAt-n.session.startedAt);return{active:t.filter(n=>n.session.status==="running"),completed:t.filter(n=>n.session.status!=="running")}}function El(s,t){return!!(s&&t&&!s.contains(t))}function Dl(s,t,n){var r;if(n===us)return n;const o=vn(s,t);return o.some(i=>i.session.id===n)?n:((r=o[0])==null?void 0:r.session.id)??us}function Tl(s,t,n){return n===us?s.filter(o=>!qe(o)||o.session.nodeId===t):s.filter(o=>qe(o)&&o.session.nodeId===t&&o.session.id===n)}function Et(s){const t=s.map((o,r)=>({entry:o,index:r})).filter(({entry:o})=>qe(o)&&o.session.status!=="running").sort((o,r)=>!qe(o.entry)||!qe(r.entry)?0:r.entry.session.startedAt-o.entry.session.startedAt||r.index-o.index),n=new Set(t.slice(0,Cl).map(({entry:o})=>qe(o)?o.session.id:""));return s.filter(o=>!qe(o)||o.session.status==="running"||n.has(o.session.id))}function Dt(s){return s.status==="running"?s.pid?`running pid ${s.pid}`:"running":s.status==="exited"?`exit ${s.exitCode??0}`:s.status==="stopped"?"stopped":s.signal?`failed ${s.signal}`:`exit ${s.exitCode??"failed"}`}function Al(s){const t=s.session.command.length>48?`${s.session.command.slice(0,45)}...`:s.session.command;return`${s.nodeName} - ${Dt(s.session)} - ${t}`}function jn(s,t=48){return s.length>t?`${s.slice(0,t-3)}...`:s}function Ml(s,t){return t===us?"All sessions":s?jn(s.session.command,34):"Command session"}function ka(s){return s.status==="stopped"?"":s.stderr}function Ll({nodes:s,defaultNodeId:t,onClose:n,initialHistory:o=[]}){const[r,i]=a.useState(()=>ya(s,t)),g=a.useMemo(()=>s.find(h=>h.id===r)??s[0]??null,[s,r]),[b,N]=a.useState(()=>rt(g)),[v,f]=a.useState(""),[l,u]=a.useState(()=>Et(o)),[w,S]=a.useState(us),[x,j]=a.useState(!1),[c,p]=a.useState(!1),[k,A]=a.useState(!1),[L,O]=a.useState(!1),[T,F]=a.useState(!1),U=a.useRef(null),M=a.useRef(null),P=a.useMemo(()=>s.find(h=>h.id===r)??s[0]??null,[s,r]),E=a.useMemo(()=>vn(l,(P==null?void 0:P.id)??""),[l,P]),J=a.useMemo(()=>_l(E),[E]),V=a.useMemo(()=>E.find(h=>h.session.id===w),[w,E]),X=a.useMemo(()=>Tl(l,(P==null?void 0:P.id)??"",w),[l,P,w]),ce=a.useRef((P==null?void 0:P.id)??"");a.useEffect(()=>{r&&s.some(h=>h.id===r)||i(ya(s,t))},[t,s,r]),a.useEffect(()=>{const h=(P==null?void 0:P.id)??"";ce.current!==h&&(ce.current=h,N(rt(P)))},[P]),a.useEffect(()=>{S(h=>Dl(l,(P==null?void 0:P.id)??"",x?h:""))},[l,P,x]),a.useEffect(()=>{var h;(h=U.current)==null||h.scrollTo({top:U.current.scrollHeight})},[l]),a.useEffect(()=>{let h=!1;async function I(){const C=await Promise.allSettled(s.map(async se=>({node:se,response:await wr(se.id)})));h||u(se=>C.reduce((m,$)=>$.status!=="fulfilled"?m:$.value.response.sessions.reduce((q,ne)=>Fs(q,$.value.node.name,ne),m),se))}return s.length>0&&I(),()=>{h=!0}},[s]),a.useEffect(()=>{const h=l.filter(qe).filter(C=>C.session.status==="running");if(h.length===0)return;const I=window.setInterval(()=>{for(const C of h)Nr(C.session.nodeId,C.session.id).then(se=>u(m=>Fs(m,C.nodeName,se))).catch(()=>{})},1e3);return()=>window.clearInterval(I)},[l]);const ae=a.useRef(null);async function ee(h){if(h.preventDefault(),!P||!v.trim()||T)return;const I=v.trim(),C=P.name;F(!0),f("");try{const se=await kr(P.id,{command:I,...b.trim()?{cwd:b.trim()}:{}});u(m=>Fs(m,C,se)),S(se.id),j(!0)}catch(se){u(m=>[...m,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:C,command:I,error:se instanceof Error?se.message:"Command failed"}])}finally{F(!1)}}async function Z(h,I){h.stopPropagation();const C=await yr(I.session.nodeId,I.session.id);u(se=>Fs(se,I.nodeName,C))}function H(h){S(h),j(!0),p(!1)}function K(h){c&&El(M.current,h.target)&&p(!1)}function re(h,I,C,se,m){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:se,"aria-label":`Toggle ${h} sessions`,"aria-expanded":!C,className:"node-terminal__small flex w-full items-center justify-between gap-2 px-2 pb-1 pt-0.5 text-left font-medium uppercase tracking-normal text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{children:h}),e.jsx(ts,{className:B("h-3 w-3 transition-transform",C&&"-rotate-90")})]}),!C&&(I.length>0?I.map(xe):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:m}))]})}function xe(h){const I=w===h.session.id,C=h.session.status==="running";return e.jsxs("div",{className:B("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",I&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>H(h.session.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:B("flex h-4 w-4 shrink-0 items-center justify-center",C?"text-primary":h.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:C?e.jsx(me,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(na,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:jn(h.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[h.nodeName," · ",Dt(h.session)]})]})]}),C&&e.jsx("button",{type:"button",onClick:se=>void Z(se,h),"aria-label":"Stop terminal session from selector",title:"Stop terminal session",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(pa,{className:"h-3 w-3"})})]},h.session.id)}return e.jsx("section",{className:"dashboard-panel node-terminal animate-composer-settle flex h-full min-h-0 shrink-0 overflow-visible rounded-xl","aria-label":"Node terminal",onClick:K,children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-visible rounded-[inherit] bg-card/72 text-card-foreground",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"node-terminal__header flex min-w-0 items-center gap-2 font-medium",children:[n?e.jsx("button",{type:"button",onClick:n,"aria-label":"Close terminal",title:"Close terminal",className:"flex h-6 w-6 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(Zs,{className:"h-3.5 w-3.5"})}):e.jsx(Zs,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{children:"Terminal"})]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-2",children:[e.jsxs("div",{ref:M,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":c,title:V?Al(V):"All sessions",onClick:()=>p(h=>!h),className:"node-terminal__control flex h-7 max-w-[14rem] list-none items-center gap-1.5 rounded-sm border border-border/70 bg-background/70 px-2 text-foreground outline-none transition-colors hover:bg-muted/65 focus-visible:ring-2 focus-visible:ring-ring/70 [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{className:"min-w-0 truncate",children:Ml(V,w)}),e.jsx(ts,{className:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!c,className:B("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!c&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>H(us),className:B("node-terminal__control flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",w===us&&"bg-primary/10 text-primary"),children:[e.jsx(Zs,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),re("Active",J.active,k,()=>A(h=>!h),"No active sessions"),re("Completed",J.completed,L,()=>O(h=>!h),"No completed sessions")]})})]}),e.jsx("select",{value:(P==null?void 0:P.id)??"",onChange:h=>{i(h.target.value),j(!1),N(rt(s.find(I=>I.id===h.target.value)??null))},disabled:T||s.length===0,"aria-label":"Terminal node",className:"node-terminal__control h-7 max-w-[11rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground outline-none transition-colors hover:bg-muted/65 disabled:opacity-50",children:s.map(h=>e.jsx("option",{value:h.id,className:"bg-background text-foreground",children:h.name},h.id))}),e.jsx(Hs,{value:b,onChange:N,assignTo:(P==null?void 0:P.id)??"",nodes:s,assignableNodes:s,layout:"composer",chipClassName:"node-terminal__control h-7 max-w-[18rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground hover:bg-muted/65",chipActiveClassName:"font-mono",chipInactiveClassName:"text-muted-foreground",labelClassName:"node-terminal__control",triggerClassName:"terminal-workdir-trigger",popoverPlacement:"top",popoverAlign:"end"})]})]}),e.jsxs("div",{ref:U,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>{var h;return(h=ae.current)==null?void 0:h.focus()},children:[X.length===0?e.jsx("div",{className:"text-muted-foreground mb-2",children:"Commands run on the selected node and stay visible while running or after exit."}):e.jsx("div",{className:"space-y-3 mb-2",children:X.map(h=>qe(h)?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"text-primary",children:[h.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:h.session.command}),e.jsxs("span",{className:B("inline-flex items-center gap-1",h.session.status==="running"||h.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[h.session.status==="running"?e.jsx(me,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(na,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"}),Dt(h.session)]}),h.session.status==="running"&&e.jsx("button",{type:"button",onClick:I=>void Z(I,h),"aria-label":"Stop terminal session",title:"Stop terminal session",className:"inline-flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/65 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(pa,{className:"h-3 w-3"})})]}),h.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:h.session.stdout}),ka(h.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:ka(h.session)}),(h.session.stdoutTruncated||h.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},h.id):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"text-primary",children:[h.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:h.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(Us,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:h.error})]},h.id))}),e.jsxs("form",{onSubmit:ee,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:P?`${P.name}$`:"$"}),e.jsx("input",{ref:ae,value:v,onChange:h=>f(h.target.value),disabled:!P||T,placeholder:P?"":"No online nodes available",className:"node-terminal__input flex-1 min-w-0 bg-transparent border-none outline-none text-foreground placeholder:text-muted-foreground font-mono caret-primary disabled:opacity-50",autoComplete:"off",spellCheck:!1}),e.jsx("button",{type:"submit","aria-label":"Run",title:"Run",disabled:!P||!v.trim()||T,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:text-muted-foreground disabled:opacity-50",children:T?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx($t,{className:"h-3 w-3"})})]})]})]})})}function Kt({nodeId:s,nodeName:t,onOpenSettings:n,onOpenDevBox:o,onStartDevBox:r,showConfigureDevBox:i,showStartDevBox:g,startDevBoxPending:b,className:N}){const[v,f]=a.useState(!1),l=a.useRef(null),u=b?"Starting":"Start DevBox";return a.useEffect(()=>{if(!v)return;const w=x=>{var c;const j=x.target;j instanceof Node&&((c=l.current)!=null&&c.contains(j)||f(!1))},S=x=>{x.key==="Escape"&&f(!1)};return document.addEventListener("mousedown",w),document.addEventListener("keydown",S),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",S)}},[v]),e.jsxs("div",{ref:l,className:B("relative shrink-0",N),onClick:w=>w.stopPropagation(),children:[e.jsx(z,{type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${t}`,"aria-haspopup":"menu","aria-expanded":v,title:`More actions for ${t}`,onClick:()=>f(w=>!w),className:B("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",v&&"bg-background/80 text-primary"),children:e.jsx(Fo,{className:"h-3.5 w-3.5"})}),v&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-full z-30 mt-1 min-w-40 overflow-hidden whitespace-nowrap rounded-sm border border-border/65 bg-popover/96 p-1 normal-case tracking-normal shadow-[0_18px_48px_-28px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:[e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${t} settings`,title:`Open ${t} settings`,onClick:()=>{f(!1),n(s)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Sr,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Settings"})]}),g&&r&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${u} for ${t}`,title:`${u} for ${t}`,onClick:()=>{b||(f(!1),r(s))},disabled:b,className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80 disabled:cursor-not-allowed disabled:opacity-60",children:[b?e.jsx(me,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx($t,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:u})]}),i&&o&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${t}`,title:`Configure DevBox for ${t}`,onClick:()=>{f(!1),o(s)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Cr,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Configure DevBox"})]})]})]})}const Pl=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),Bl=new Set(["startinprogress","starting"]);function Ns(s){return!!(s!=null&&s.enabled&&s.name)}function Rl(s){const t=s==null?void 0:s.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(t&&Pl.has(t))}function ws(s){const t=s==null?void 0:s.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(t&&Bl.has(t))}function Ks(s,t,n){return s==="offline"&&Rl(t)&&Ns(n)}function Sa(s,t){return s==="offline"&&Ns(t)}function Ca(s){return!Ns(s)}function $l({nodeStatus:s,status:t,current:n,selected:o}){const r=o??n;return r&&Ks(s,t,r)?r:null}function Pe(s){return s.scope||`name:${s.name??""}`}function Ol({previousKey:s,baseDevBox:t,listed:n}){if(s&&n.some(i=>Pe(i)===s))return s;if(!Ns(t))return n[0]?Pe(n[0]):"";const o=Pe(t),r=n.find(i=>Pe(i)===o)??n.find(i=>i.name===t.name);return r?Pe(r):o}function Fl({cluster:s,systemInfo:t,nodeNameById:n,nodeBlockingTaskCounts:o,eventTypeFilter:r,onEventTypeFilterChange:i,eventTypeOptions:g,filteredEvents:b,sseConnected:N,clusterLoading:v,clusterError:f,promotePending:l,onPromote:u,onAddNode:w,leavePending:S,onLeaveCluster:x,onToggleNodeDevTunnel:j,devTunnelNodeId:c,devBoxStartNodeId:p,devBoxStartingNodeIds:k=new Set,onOpenNodeSettings:A,onOpenDevBox:L,onStartDevBox:O,onClose:T}){var ae,ee,Z;const F=((ae=s==null?void 0:s.self)==null?void 0:ae.role)==="leader",U=((ee=s==null?void 0:s.self)==null?void 0:ee.role)==="follower"&&!(s!=null&&s.leader),M=(s==null?void 0:s.self)??null,E=_r((s==null?void 0:s.nodes)??[],M==null?void 0:M.id).filter(H=>H.id!==(M==null?void 0:M.id)),J=s!=null&&s.leader?s.nodes.find(H=>{var K;return H.id===((K=s.leader)==null?void 0:K.id)})??null:null,V=s!=null&&s.leader?s.leader.dashboardOrigin??(J==null?void 0:J.dashboardOrigin)??(t&&s.leader.id===(t.nodeId??t.id)?t.dashboardOrigin:void 0)??s.leader.endpoint:null,X=(M==null?void 0:M.role)==="leader"&&E.length===0,ce=(M==null?void 0:M.role)==="follower";return e.jsx("aside",{className:"dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl !border-0",children:e.jsxs(za,{defaultValue:"overview",className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"shrink-0 bg-card/24 px-2.5 py-2.5 shadow-[0_1px_0_hsl(var(--border)/0.22)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold tracking-tight",children:"Operations"}),e.jsx("p",{className:"mt-px text-[9px] text-muted-foreground",children:"Node, cluster, and live events."})]}),e.jsx(z,{variant:"ghost",size:"icon",onClick:T,className:"h-6 w-6 rounded-sm",children:e.jsx(zt,{className:"h-3.5 w-3.5"})})]}),e.jsxs(Va,{className:"mt-1.5 grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(ds,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(ds,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(ds,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})]}),e.jsx(cs,{value:"overview",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-2 py-2",children:e.jsxs("div",{className:"space-y-2.5",children:[M&&e.jsx(_a,{node:M,systemInfo:t,blockingTaskCount:o.get(M.id)??0,devTunnelNodeId:c,onToggleNodeDevTunnel:j,showActions:!1,defaultExpanded:!1,onOpenDevBox:L,devBoxStartingNodeIds:k}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"Cluster snapshot"}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 shadow-sm",children:N?"Connected":"Reconnecting"})]}),v&&!s?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(me,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):f&&!s?e.jsx("div",{className:"rounded-sm bg-destructive/10 px-2 py-1.5 text-[10px] text-destructive shadow-sm",children:f}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(gs,{label:"Term",value:String((s==null?void 0:s.term)??0)}),e.jsx(gs,{label:"Nodes",value:String((s==null?void 0:s.nodes.length)??0)}),e.jsx(gs,{label:"Pending",value:String((s==null?void 0:s.taskSummary.pending)??0)}),e.jsx(gs,{label:"Running",value:String((s==null?void 0:s.taskSummary.running)??0)}),e.jsx(gs,{label:"Completed",value:String((s==null?void 0:s.taskSummary.completed)??0)}),e.jsx(gs,{label:"Failed",value:String((s==null?void 0:s.taskSummary.failed)??0)})]}),e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/56 px-2 py-2 shadow-sm",children:[e.jsx(Qe,{label:"Leader",value:((Z=s==null?void 0:s.leader)==null?void 0:Z.name)??"None"}),e.jsx(Qe,{label:"Leader URL",value:V??"Unavailable",mono:!0,action:V?e.jsx(Ps,{label:"Copy leader URL",onClick:()=>void bs(V,"Leader URL copied")}):void 0}),e.jsx(Qe,{label:"Feed",value:N?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:U&&e.jsxs(z,{variant:"outline",size:"sm",onClick:u,disabled:l,className:"h-6 rounded-sm px-2 text-[10px]",children:[l&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(cs,{value:"nodes",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-2 py-2",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"This node"}),X?e.jsx(z,{variant:"outline",size:"sm",onClick:w,className:"h-6 rounded-sm px-2 text-[10px]",children:"Join node"}):ce?e.jsxs(z,{variant:"outline",size:"sm",onClick:x,disabled:S,className:"h-6 rounded-sm px-2 text-[10px]",children:[S&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),M&&e.jsx(_a,{node:M,systemInfo:t,blockingTaskCount:o.get(M.id)??0,devTunnelNodeId:c,onToggleNodeDevTunnel:j,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:F?A:void 0,onOpenDevBox:F?L:void 0,onStartDevBox:F?O:void 0,devBoxStartNodeId:p,devBoxStartingNodeIds:k})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",E.length,")"]}),E.length>0?e.jsx("div",{className:"space-y-1.5",children:E.map(H=>e.jsx(Il,{node:H,isLeader:!!F,blockingTaskCount:o.get(H.id)??0,devTunnelNodeId:c,onToggleNodeDevTunnel:j,onOpenNodeSettings:F?A:void 0,onOpenDevBox:F?L:void 0,onStartDevBox:F?O:void 0,devBoxStartNodeId:p,devBoxStartingNodeIds:k},H.id))}):e.jsx("div",{className:"rounded-sm bg-background/45 px-2 py-2 text-[10px] text-muted-foreground shadow-sm",children:"No peer nodes are connected yet."})]})]})})}),e.jsx(cs,{value:"events",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col px-2 py-2",children:[e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-foreground",children:[e.jsx(Er,{className:B("h-3.5 w-3.5",N?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(_e,{value:r,onValueChange:i,children:[e.jsx(Ee,{className:"h-6 min-w-[10rem] flex-1 rounded-sm border-border/70 bg-background/60 text-[10px] sm:max-w-[14rem] [&>svg]:h-3 [&>svg]:w-3",children:e.jsx(Ie,{placeholder:"Event type"})}),e.jsx(De,{children:g.map(H=>e.jsx(we,{value:H,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:H==="all"?"All event types":H},H))})]}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 shadow-sm",children:N?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Dr,{events:b,maxHeight:"100%",emptyTitle:r==="all"?"No live events yet":"No matching events",emptyDescription:r==="all"?"Cluster activity appears here as it happens.":`No "${r}" events are in the current stream.`,nodeNameById:n,density:"compact"})})]})})]})})}function _a({node:s,systemInfo:t,blockingTaskCount:n,devTunnelNodeId:o,onToggleNodeDevTunnel:r,showActions:i=!0,defaultExpanded:g=!1,onOpenNodeSettings:b,onOpenDevBox:N,onStartDevBox:v,devBoxStartNodeId:f,devBoxStartingNodeIds:l}){var O,T,F,U;const[u,w]=a.useState(g),S=(t==null?void 0:t.dashboardOrigin)??s.dashboardOrigin,x=s.devtunnelEndpoint??s.endpoint,j=S??s.endpoint,c=(t==null?void 0:t.workDir)??s.workDir,p=on(s,t==null?void 0:t.transportType),k=Ut(s,t==null?void 0:t.transportType),A=k&&ks((t==null?void 0:t.transportType)??s.transportType)?!0:rn(s,t==null?void 0:t.transportType),L=n>0;return e.jsxs("section",{className:"rounded-lg bg-primary/7 shadow-[0_18px_56px_-42px_hsl(var(--primary)/0.85)]",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>w(M=>!M),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[u?e.jsx(ts,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Ms,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(qa,{status:s.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Current node"})]}),e.jsx("a",{href:j,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Wa,{className:"h-3 w-3"})}),b&&e.jsx(Kt,{nodeId:s.id,nodeName:s.name,onOpenSettings:b,onOpenDevBox:N,onStartDevBox:v,showConfigureDevBox:(O=s.devbox)==null?void 0:O.enabled,showStartDevBox:Ks(s.status,(T=s.devbox)==null?void 0:T.lastStatus,s.devbox)||ws((F=s.devbox)==null?void 0:F.lastStatus)||l.has(s.id),startDevBoxPending:f===s.id||ws((U=s.devbox)==null?void 0:U.lastStatus)||l.has(s.id)})]}),e.jsxs("button",{type:"button",onClick:()=>w(M=>!M),className:"mt-1 flex min-w-0 items-center gap-1 pl-5 text-left",children:[e.jsx("span",{className:"text-[10px] font-semibold tracking-tight text-foreground",children:s.name}),e.jsx(Ga,{role:s.role,size:"compact"}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-sm",children:s.status})]})]}),u&&e.jsxs("div",{className:"space-y-2 px-2.5 pb-2.5 pt-1.5 shadow-[inset_0_1px_0_hsl(var(--primary)/0.12)]",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/70 px-2 py-1.5 shadow-sm",children:[e.jsx(Qe,{label:"Node ID",value:s.id,mono:!0}),S&&e.jsx(Qe,{label:"Dashboard",value:S,mono:!0,action:e.jsx(Ps,{label:"Copy dashboard URL",onClick:()=>void bs(S,"Dashboard URL copied")})}),e.jsx(Qe,{label:"Node URL",value:x,mono:!0,action:e.jsx(Ps,{label:"Copy node URL",onClick:()=>void bs(x,"Node URL copied")})}),c&&e.jsx(Qe,{label:"Workspace",value:c,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(vt,{label:"Transport",value:p}),t&&e.jsx(vt,{label:"Uptime",value:Tr(t.uptime),mono:!0})]}),e.jsx(en,{capabilities:s.capabilities,action:i&&A?e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>r(s),disabled:o===s.id||L,className:"h-6 rounded-sm px-2 text-[10px]",title:L?"Finish assigned or running tasks before changing remote access":void 0,children:[o===s.id&&e.jsx(me,{className:"h-3 w-3 animate-spin"}),k?"Disable Remote Access":"Enable Remote Access"]}):void 0}),i&&A&&L&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Il({node:s,isLeader:t,blockingTaskCount:n,devTunnelNodeId:o,onToggleNodeDevTunnel:r,onOpenNodeSettings:i,onOpenDevBox:g,onStartDevBox:b,devBoxStartNodeId:N,devBoxStartingNodeIds:v}){var k,A,L,O;const[f,l]=a.useState(!1),u=s.dashboardOrigin,w=s.devtunnelEndpoint??s.endpoint,S=u??s.endpoint,x=on(s),j=Ut(s),c=rn(s),p=n>0;return e.jsxs("div",{className:"rounded-sm bg-background/54 shadow-sm",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>l(T=>!T),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[f?e.jsx(ts,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(Ms,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(qa,{status:s.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Peer node"})]}),e.jsx("a",{href:S,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Wa,{className:"h-3 w-3"})}),t&&i&&e.jsx(Kt,{nodeId:s.id,nodeName:s.name,onOpenSettings:i,onOpenDevBox:g,onStartDevBox:b,showConfigureDevBox:(k=s.devbox)==null?void 0:k.enabled,showStartDevBox:Ks(s.status,(A=s.devbox)==null?void 0:A.lastStatus,s.devbox)||ws((L=s.devbox)==null?void 0:L.lastStatus)||v.has(s.id),startDevBoxPending:N===s.id||ws((O=s.devbox)==null?void 0:O.lastStatus)||v.has(s.id)})]}),e.jsxs("button",{type:"button",onClick:()=>l(T=>!T),className:"mt-1 flex min-w-0 items-center gap-1 pl-4 text-left",children:[e.jsx("span",{className:"text-[10px] font-semibold text-foreground",children:s.name}),e.jsx(Ga,{role:s.role,size:"compact"}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-sm",children:s.status})]})]}),f&&e.jsxs("div",{className:"space-y-2 px-2.5 pb-2.5 pt-1.5 shadow-[inset_0_1px_0_hsl(var(--border)/0.22)]",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Qe,{label:"Node ID",value:s.id,mono:!0}),u&&e.jsx(Qe,{label:"Dashboard",value:u,mono:!0,action:e.jsx(Ps,{label:"Copy dashboard URL",onClick:()=>void bs(u,"Dashboard URL copied")})}),e.jsx(Qe,{label:"Node URL",value:w,mono:!0,action:e.jsx(Ps,{label:"Copy node URL",onClick:()=>void bs(w,"Node URL copied")})}),s.workDir&&e.jsx(Qe,{label:"Workspace",value:s.workDir,mono:!0}),e.jsx(vt,{label:"Transport",value:x})]}),e.jsx(en,{capabilities:s.capabilities,action:t&&c?e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>r(s),disabled:o===s.id||p,className:"h-6 rounded-sm px-2 text-[10px]",title:p?"Finish assigned or running tasks before changing remote access":void 0,children:[o===s.id&&e.jsx(me,{className:"h-3 w-3 animate-spin"}),j?"Disable Remote Access":"Enable Remote Access"]}):void 0}),t&&c&&p&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Ps({label:s,onClick:t}){return e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground",onClick:t,"aria-label":s,title:s,children:e.jsx(Ia,{className:"h-3 w-3"})})}function zl(s,t,n,o){var b,N;if(!s)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const r=((b=t==null?void 0:t.self)==null?void 0:b.role)==="follower",i=s.assignedTo?((N=t==null?void 0:t.self)==null?void 0:N.id)===s.assignedTo?t.self:t==null?void 0:t.nodes.find(v=>v.id===s.assignedTo):void 0;return s.assignedTo!==null&&(i?i.status==="offline":t?s.assignedNodeAvailable===!1||!t.nodes.some(v=>v.id===s.assignedTo):s.assignedNodeAvailable===!1)?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${s.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}:r?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Follower nodes are read-only. Use the leader dashboard to manage chat, or leave the cluster first."}:n?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Sending message..."}:o?{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Queue a message for the next turn..."}:Vs.has(s.status)||s.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:Vs.has(s.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const Nn="meshy-task-sidebar-tree-state";function Ea(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"):[]}function ot(){var s;try{return((s=globalThis.window)==null?void 0:s.localStorage)??globalThis.localStorage??null}catch{return null}}function Da(s){if(!s)return{collapsedNodes:[],collapsedDirs:[]};try{const t=s.getItem(Nn);if(!t)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(t);return{collapsedNodes:Ea(n.collapsedNodes),collapsedDirs:Ea(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Ul(s,t){if(s)try{s.setItem(Nn,JSON.stringify(t))}catch{}}function Ta(s,t){if(!s.has(t))return s;const n=new Set(s);return n.delete(t),n}function Vl(s,t){if(!t)return null;for(const n of s){const o=n.nodeId??"__unassigned__";for(const r of n.dirs)if(r.tasks.some(i=>i.id===t))return{nodeKey:o,dirKey:`${o}::${r.path}`}}return null}function Aa(s,t,n){return n?{collapsedNodes:Ta(s,n.nodeKey),collapsedDirs:Ta(t,n.dirKey)}:{collapsedNodes:s,collapsedDirs:t}}function Hl(s,t,n){const o=s.filter(b=>b.status==="completed"),r=new Set((t?o:[...o].sort((b,N)=>N.updatedAt-b.updatedAt).slice(0,Bt)).map(b=>b.id));n&&o.some(b=>b.id===n)&&r.add(n);const i=s.filter(b=>b.status!=="completed"||r.has(b.id)),g=o.length-r.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,g)}}const Is="h-6 rounded-sm border-border/70 bg-background/60 px-2 py-0 text-[10px] leading-none shadow-sm [&>svg]:h-3 [&>svg]:w-3",zs="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function Ma({toolbarTasks:s,activeTaskId:t,tasksLoading:n,tasksError:o,isLeader:r,scope:i,agentFilter:g,nodeFilter:b,taskKindFilter:N,agentOptions:v,nodeOptions:f,nodeNameById:l,nodeWorkDirById:u,nodeStatusById:w,completedGroupByKey:S,devBoxNodeIds:x=new Set,devBoxStartNodeIds:j=new Set,devBoxStartingNodeIds:c=new Set,leaderNodeId:p,searchQuery:k,selectedTaskIds:A,allVisibleTasksSelected:L,someVisibleTasksSelected:O,canBatchArchive:T,onSearchChange:F,onScopeChange:U,onAgentFilterChange:M,onNodeFilterChange:P,onTaskKindFilterChange:E,onToggleTaskSelected:J,onToggleAllVisibleTasks:V,onBatchArchive:X,onBatchDelete:ce,onCreateTask:ae,onOpenNodeSettings:ee,onOpenDevBox:Z,onStartDevBox:H,onLoadCompletedTasks:K,onSelectTask:re,onClose:xe}){const[h,I]=a.useState(!!k),[C,se]=a.useState(!1),[m,$]=a.useState(!1),q=a.useRef(null),ne=a.useRef(null),W=a.useRef(null),[ie,oe]=a.useState(()=>A.size>0),{markScrollbarActive:Te,scrollbarActive:D}=gn(),Q=A.size,ge=!!(r&&(ie||Q>0)),He=i!=="active"||b!=="all"||g!=="all"||N!=="all",Y=k.trim().length>0,[be,ye]=a.useState(()=>new Set(Da(ot()).collapsedNodes)),[Je,Be]=a.useState(()=>new Set(Da(ot()).collapsedDirs)),[je,Ye]=a.useState(new Set),ke=a.useMemo(()=>Ar(s,l,p,u),[s,l,p,u]),Ae=a.useMemo(()=>Vl(ke,t),[ke,t]),Ze=a.useRef(null),ms=ke.length===1,as=ke.length>0,os=ms&&(He||Y),is=!!(r&&(ke.length>0||Q>0)),xs=a.useCallback(_=>{ye(fe=>{const ue=new Set(fe);return ue.has(_)?ue.delete(_):ue.add(_),ue})},[]),$e=a.useCallback(_=>{Be(fe=>{const ue=new Set(fe);return ue.has(_)?ue.delete(_):ue.add(_),ue})},[]),ls=a.useCallback(_=>{Ye(fe=>{const ue=new Set(fe);return ue.add(_),ue})},[]);a.useEffect(()=>{Ul(ot(),{collapsedNodes:Array.from(be),collapsedDirs:Array.from(Je)})},[Je,be]),a.useEffect(()=>{if(!Ae||!t)return;const _=`${t}:${Ae.nodeKey}:${Ae.dirKey}`;Ze.current!==_&&(Ze.current=_,ye(fe=>Aa(fe,new Set,Ae).collapsedNodes),Be(fe=>Aa(new Set,fe,Ae).collapsedDirs))},[t,Ae]);const Me=a.useCallback(_=>{oe(!0),V(_)},[V]),hs=a.useCallback(()=>{V(!1),oe(!1)},[V]);return a.useEffect(()=>{r||oe(!1)},[r]),a.useEffect(()=>{k&&I(!0)},[k]),a.useEffect(()=>{var _;h&&((_=q.current)==null||_.focus())},[h]),a.useEffect(()=>{if(!h)return;const _=ue=>{var We;const ze=ue.target;ze instanceof Node&&((We=ne.current)!=null&&We.contains(ze)||I(!1))},fe=ue=>{ue.key==="Escape"&&I(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",fe),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",fe)}},[h]),a.useEffect(()=>{if(!m)return;const _=ue=>{var We;const ze=ue.target;ze instanceof Node&&((We=W.current)!=null&&We.contains(ze)||$(!1))},fe=ue=>{ue.key==="Escape"&&$(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",fe),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",fe)}},[m]),e.jsxs("aside",{className:"dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl !border-t-0",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 bg-card/24 px-2.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-sm font-semibold tracking-tight text-foreground",children:"Tasks"}),e.jsx(z,{variant:"ghost",size:"icon",onClick:xe,className:"h-6 w-6 rounded-sm",children:e.jsx(tn,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{ref:ne,className:"mt-2 flex items-center gap-1.5",children:[e.jsxs("div",{ref:W,className:B("relative flex items-stretch transition-[flex] duration-200",h?"flex-[2]":"flex-1"),children:[e.jsxs(z,{onClick:()=>{$(!1),ae("chat")},className:"h-8 flex-1 justify-start rounded-l-sm rounded-r-none px-2.5 text-left text-[11px] shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(It,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsx(z,{onClick:()=>$(_=>!_),"aria-label":"More chat options","aria-haspopup":"menu","aria-expanded":m,className:"h-8 w-7 rounded-l-none rounded-r-sm border-l border-primary-foreground/20 px-0 shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:e.jsx(ts,{className:B("h-3 w-3 transition-transform",m&&"rotate-180")})}),m&&e.jsx("div",{role:"menu",className:"absolute left-0 right-0 top-full z-20 mt-2 overflow-hidden rounded-lg border border-border/60 bg-popover/96 p-1 shadow-[0_20px_60px_-30px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{$(!1),ae("native")},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-2 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Ft,{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"})]})})]}),h?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(it,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(Xe,{ref:q,value:k,onChange:_=>F(_.target.value),placeholder:"Search tasks",className:"h-8 rounded-sm border-border/70 bg-background/68 pl-8 text-[11px] shadow-none"})]}),e.jsx(z,{variant:"outline",size:"icon",onClick:()=>I(!1),className:"h-8 w-8 rounded-sm border-border/70 bg-background/68 shadow-none",children:e.jsx(Us,{className:"h-3.5 w-3.5"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(z,{variant:"outline",onClick:()=>I(!0),className:B("h-8 rounded-sm border-border/70 bg-background/68 px-2.5 text-[11px] shadow-none",k&&"border-primary/40 bg-primary/8 text-primary"),children:[e.jsx(it,{className:"h-3.5 w-3.5"}),"Search"]}),e.jsx(z,{variant:C||He?"secondary":"outline",size:"icon",onClick:()=>se(_=>!_),className:B("h-8 w-8 shrink-0 rounded-sm border-border/70 bg-background/68 shadow-none",He&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(Ho,{className:"h-3.5 w-3.5"})})]})]}),(C||He)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(_e,{value:i,onValueChange:_=>U(_),children:[e.jsx(Ee,{className:Is,children:e.jsx(Ie,{})}),e.jsx(De,{children:Mr.map(_=>e.jsx(we,{value:_.value,className:zs,children:_.label},_.value))})]}),e.jsxs(_e,{value:b,onValueChange:P,children:[e.jsx(Ee,{className:Is,children:e.jsx(Ie,{placeholder:"Node"})}),e.jsx(De,{children:f.map(_=>e.jsx(we,{value:_.value,className:zs,children:_.label},_.value))})]}),e.jsxs(_e,{value:g,onValueChange:M,children:[e.jsx(Ee,{className:Is,children:e.jsx(Ie,{placeholder:"Agent"})}),e.jsx(De,{children:v.map(_=>e.jsx(we,{value:_,className:zs,children:_==="all"?"All agents":_},_))})]}),e.jsxs(_e,{value:N,onValueChange:_=>E(_),children:[e.jsx(Ee,{className:Is,children:e.jsx(Ie,{placeholder:"Type"})}),e.jsx(De,{children:Lr.map(_=>e.jsx(we,{value:_.value,className:zs,children:_.label},_.value))})]})]})]}),e.jsx("div",{className:B("scrollbar-line min-h-0 flex-1 overflow-y-auto px-1.5 py-2",D&&"scrollbar-line-active"),onScroll:Te,children:ke.length>0?e.jsx("div",{className:"space-y-1",children:ke.map(_=>{const fe=_.nodeId??"__unassigned__",ue=_.dirs.reduce((ve,Ne)=>ve+Ne.tasks.length,0),ze=as&&!os&&be.has(fe),We=_.nodeId!==null&&w.get(_.nodeId)==="offline",Le=!!(r&&_.nodeId&&ee);return e.jsxs("div",{className:"space-y-1",children:[as&&e.jsxs("div",{className:"flex w-full items-center gap-1.5 rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 px-2 py-1.5 text-left text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsxs("button",{type:"button",onClick:()=>xs(fe),"aria-expanded":!ze,className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[e.jsx(Ms,{className:B("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!ze&&"rotate-90")}),e.jsx($a,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:_.nodeName}),e.jsxs(Ke,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-transparent bg-background/55 px-1.5 py-0 text-[7px] font-semibold leading-3.5 text-muted-foreground shadow-none normal-case tracking-normal",children:[ue," task",ue===1?"":"s"]})]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[We&&e.jsx(Ke,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/10 px-1 py-0 text-[8px] font-semibold leading-3 text-destructive shadow-none",children:"offline"}),_.nodeId===p&&e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"}),Le&&_.nodeId&&ee&&e.jsx(Kt,{nodeId:_.nodeId,nodeName:_.nodeName,onOpenSettings:ee,onOpenDevBox:Z,onStartDevBox:H,showConfigureDevBox:x.has(_.nodeId),showStartDevBox:j.has(_.nodeId)||c.has(_.nodeId),startDevBoxPending:c.has(_.nodeId)})]})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-300 ease-in-out",ze?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:_.dirs.map(ve=>{const Ne=`${fe}::${ve.path}`,es=Je.has(Ne),Ss=Qa(ve.path),Se=S==null?void 0:S.get(Ne),Cs=Se?{visibleTasks:ve.tasks,hiddenCompletedCount:Math.max(0,Se.total-Se.returned)}:Hl(ve.tasks,je.has(Ne),t),{visibleTasks:fs,hiddenCompletedCount:Oe}=Cs;return e.jsxs("div",{className:B("space-y-0.5 rounded-xl",as&&"pl-2.5"),children:[e.jsxs("button",{type:"button",onClick:()=>$e(Ne),"aria-expanded":!es,title:ve.path,className:"flex w-full items-center gap-1.5 rounded-sm bg-muted/15 px-2 py-1 text-left text-[9px] font-medium text-muted-foreground/70 transition-all duration-150 hover:bg-muted/30 hover:text-foreground active:scale-[0.98] active:bg-muted/40",children:[e.jsx(Ms,{className:B("h-3 w-3 shrink-0 transition-transform duration-200",!es&&"rotate-90")}),e.jsx(Oa,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"truncate font-mono",children:Ss}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/40",children:ve.tasks.length})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-300 ease-in-out",es?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:B("overflow-hidden",as?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[fs.map(Ce=>{const ss=Ce.id===t,Fe=Ce.assignedTo?w.get(Ce.assignedTo):void 0,Ue=!!Ce.assignedTo&&(Fe?Fe==="offline":Ce.assignedNodeAvailable===!1);return e.jsxs("div",{className:B("animate-task-row-reveal flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",ss?"bg-primary/10":"hover:bg-muted/40"),children:[ge&&e.jsx("div",{className:"flex shrink-0",onClick:_s=>_s.stopPropagation(),children:e.jsx(gt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:A.has(Ce.id),onCheckedChange:_s=>J(Ce.id,_s===!0),"aria-label":`Select ${Ce.title}`})}),e.jsxs("button",{type:"button",onClick:()=>re(Ce.id),"aria-current":ss?"page":void 0,className:"relative min-w-0 flex-1 pr-8 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5 pr-1",children:[e.jsx("span",{className:B("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",ss?"text-foreground":"text-foreground/80"),children:Ce.title}),ss&&e.jsx("span",{className:"ml-1 h-1.5 w-1.5 shrink-0 rounded-full bg-primary"})]}),e.jsx("span",{className:B("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",ss?"text-primary/75":"text-muted-foreground/55"),children:Pr(Ce.updatedAt)}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5",children:[e.jsx("span",{className:"rounded-sm bg-muted/35 px-1 py-0 font-mono text-[8px] leading-3 text-muted-foreground/65",children:Ce.agent}),Ce.activeShare&&e.jsx(Ke,{variant:"outline",className:"rounded-sm border-primary/25 bg-primary/8 px-1 py-0 text-[8px] leading-3 text-primary shadow-none",children:"shared"}),Ue&&e.jsx(Ke,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/8 px-1 py-0 text-[8px] leading-3 text-destructive shadow-none",children:"unavailable"})]}),e.jsx(Ua,{status:Ce.status,isNative:Ce.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},Ce.id)}),Oe>0&&e.jsxs("button",{type:"button",onClick:()=>{Se&&K?K(Se):ls(Ne)},className:"mt-1 flex w-full items-center justify-center gap-1 rounded-sm border border-dashed border-border/55 bg-background/35 px-2 py-1 text-[9px] font-medium text-muted-foreground transition-colors hover:border-primary/35 hover:bg-primary/8 hover:text-primary","aria-label":`Load ${Oe} more completed tasks in ${Ss}`,children:[e.jsx(ts,{className:"h-3 w-3"}),"Load ",Oe," more completed"]})]})})})]},Ne)})})})]},fe)})}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(_=>e.jsx("div",{className:"rounded-xl border border-border/40 bg-background/30 px-3 py-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"mt-1 h-2.5 w-2.5 shrink-0 animate-pulse rounded-full bg-muted-foreground/20"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-2.5 animate-pulse rounded-full bg-muted-foreground/15",style:{width:`${60+_*12}%`,animationDelay:`${_*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${_*120+60}ms`}})]})]})},_))}):e.jsx("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-3 py-5 text-[11px] text-muted-foreground",children:o||"No tasks match this view."})}),is?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 items-center",children:ge?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(gt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:O&&!L?"indeterminate":L,onCheckedChange:_=>Me(_===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Multi select"})]}):e.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>oe(!0),className:"h-5 rounded-sm px-1.5 text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75 hover:text-foreground",children:[e.jsx(_o,{className:"h-3 w-3"}),"Multi select"]})}),ge&&e.jsxs("div",{className:"ml-auto flex w-48 max-w-[65%] flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[Q>0?e.jsxs("div",{className:"min-w-0 text-left",children:[e.jsxs("div",{className:"text-[9px] font-semibold leading-3 text-foreground",children:[Q," task",Q!==1?"s":""," selected"]}),!T&&e.jsx("div",{className:"max-w-48 text-[9px] leading-3.5 text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."})]}):e.jsx("span",{}),e.jsx(z,{variant:"ghost",size:"sm",onClick:hs,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:Q>0?"Clear":"Done"})]}),Q>0&&e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(dt,{children:[e.jsx(ra,{asChild:!0,children:e.jsxs(z,{variant:"ghost",size:"sm",disabled:!T,className:"h-5 gap-1 rounded-sm bg-muted/45 px-1.5 text-[8px] text-foreground/80 shadow-none hover:bg-muted/65 [&_svg]:size-3",children:[e.jsx(Bo,{}),"Archive"]})}),e.jsxs(ct,{children:[e.jsxs(ut,{children:[e.jsxs(mt,{children:["Archive ",Q," task",Q!==1?"s":"","?"]}),e.jsx(xt,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(ht,{children:[e.jsx(ft,{children:"Cancel"}),e.jsx(pt,{onClick:X,disabled:!T,children:"Archive"})]})]})]}),e.jsxs(dt,{children:[e.jsx(ra,{asChild:!0,children:e.jsxs(z,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(bi,{}),"Delete"]})}),e.jsxs(ct,{children:[e.jsxs(ut,{children:[e.jsxs(mt,{children:["Delete ",Q," task",Q!==1?"s":"","?"]}),e.jsx(xt,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(ht,{children:[e.jsx(ft,{children:"Cancel"}),e.jsx(pt,{onClick:ce,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]})]})}):null]})}async function Kl(s,t){var n,o;try{const r=await Br(s,t),i={...r,url:Fa(r.url)};if((o=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&o.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),te.success("Shared link copied")}catch{te.success("Shared link created")}else te.success("Shared link created");return i}catch(r){te.error(r instanceof Error?r.message:"Failed to create shared link");return}}async function ql(s){try{return await Rr(s),te.success("Shared link stopped"),!0}catch(t){return te.error(t instanceof Error?t.message:"Failed to stop shared link"),!1}}function Wl(s,t,n){const o=a.useCallback(()=>{t(),n()},[t,n]),r=a.useCallback(async g=>{if(!s)return;const b=await Kl(s.id,g);return b&&o(),b},[s,o]),i=a.useCallback(async()=>{if(!s)return!1;const g=await ql(s.id);return g&&o(),g},[s,o]);return{handleShareTask:r,handleStopShareTask:i}}function La(s,t,n){const o=a.useRef(t);o.current=t,a.useEffect(()=>{let g=0,b=0;const N=l=>{const u=l.touches[0];u&&(g=u.clientX,b=u.clientY)},v=l=>{var x,j,c,p;const u=l.changedTouches[0];if(!u)return;const w=u.clientX-g;Math.abs(u.clientY-b)>100||Math.abs(w)<50||(w>0?(j=(x=o.current).onSwipeRight)==null||j.call(x):(p=(c=o.current).onSwipeLeft)==null||p.call(c))},f=(s==null?void 0:s.current)??document;return f.addEventListener("touchstart",N,{passive:!0}),f.addEventListener("touchend",v,{passive:!0}),()=>{f.removeEventListener("touchstart",N),f.removeEventListener("touchend",v)}},[s,n==null?void 0:n.threshold,n==null?void 0:n.maxVertical])}const Gl="(min-width: 1024px)",Ql="(min-width: 1800px)";function Pa(s){var t,n,o;return((o=(n=(t=globalThis.window)==null?void 0:t.matchMedia)==null?void 0:n.call(t,s))==null?void 0:o.matches)??!1}function Yl(){var n,o;const s=(n=globalThis.document)==null?void 0:n.documentElement;if(!s||!((o=globalThis.window)!=null&&o.getComputedStyle))return 16;const t=Number.parseFloat(globalThis.window.getComputedStyle(s).fontSize);return Number.isFinite(t)&&t>0?t:16}function Xl(){const[s,t]=a.useState(()=>$r(oa(),Or({operationsOpen:Pa(Ql)}))),[n,o]=a.useState(!1),r=a.useRef(null),i=a.useRef(null),g=a.useRef(null),b=s.layout.desktopTasksOpen,N=s.layout.operationsOpen,v=s.sizes;a.useEffect(()=>{Fr(oa(),s)},[s]);const f=a.useCallback((j,c)=>{t(p=>{const k=p.layout[j],A=typeof c=="function"?c(k):c;return A===k?p:{...p,layout:{...p.layout,[j]:A}}})},[]),l=a.useCallback(j=>{f("desktopTasksOpen",j)},[f]),u=a.useCallback(j=>{f("operationsOpen",j)},[f]);La(i,{onSwipeLeft:()=>o(!1)}),La(g,{onSwipeRight:()=>u(!1)});const w=a.useCallback(()=>{if(Pa(Gl)){l(j=>!j);return}o(j=>!j)},[l]);a.useEffect(()=>{var p,k,A;const j=L=>{const O=r.current;if(!O)return;L.preventDefault();const T=zr(O.panel,O.startSize,O.startClientX,O.startClientY,L.clientX,L.clientY,O.rootFontSize);t(F=>({...F,sizes:{...F.sizes,[O.panel]:T}}))},c=()=>{r.current=null};return(p=globalThis.window)==null||p.addEventListener("pointermove",j),(k=globalThis.window)==null||k.addEventListener("pointerup",c),(A=globalThis.window)==null||A.addEventListener("pointercancel",c),()=>{var L,O,T;(L=globalThis.window)==null||L.removeEventListener("pointermove",j),(O=globalThis.window)==null||O.removeEventListener("pointerup",c),(T=globalThis.window)==null||T.removeEventListener("pointercancel",c)}},[]);const S=a.useCallback((j,c)=>{var p,k;c.preventDefault(),(k=(p=c.currentTarget).setPointerCapture)==null||k.call(p,c.pointerId),r.current={panel:j,startSize:v[j],startClientX:c.clientX,startClientY:c.clientY,rootFontSize:Yl()}},[v]),x=a.useCallback((j,c)=>{c.preventDefault(),t(p=>({...p,sizes:{...p.sizes,[j]:Ir(j,p.sizes[j],c.deltaY)}}))},[]);return{desktopTasksOpen:b,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:N,operationsPanelRef:g,panelResize:{sizes:{tasks:et(v.tasks),operations:et(v.operations),terminal:et(v.terminal)},onPointerDown:S,onWheel:x},setMobileTasksPanelOpen:o,setOperationsOpen:u,toggleTasksPanel:w}}function Jl(s,t){const n=t.taskId,o=t.updates;return typeof n!="string"||!o||typeof o!="object"?s:s.map(r=>r.id===n?{...r,...o}:r)}function Zl({isLeader:s,selfId:t}){return{...!s&&t?{assignedTo:t}:{},completedLimitPerProject:Bt}}function Tt(s){return`${s.assignedTo??"__unassigned__"}::${s.projectPath}`}function ed(s,t){const n=new Map(s.map(o=>[o.id,o]));for(const o of t)n.set(o.id,o);return Array.from(n.values())}function sd(s,t){return t?ln(s,t):s}function td({isLeader:s,selfId:t,sseConnected:n,preservedTask:o,subscribe:r}){const[i,g]=a.useState([]),[b,N]=a.useState([]),[v,f]=a.useState(!0),[l,u]=a.useState(null),w=a.useRef(null),S=a.useCallback(async()=>{try{const c=await ia(Zl({isLeader:s,selfId:t}));g(sd(c.tasks,o)),N(c.completedGroups??[]),u(null)}catch(c){u(c instanceof Error?c.message:"Failed to load tasks")}finally{f(!1)}},[s,o,t]),x=a.useCallback(async c=>{if(!c.hasMore||!c.nextCursor)return;const p=await ia({status:"completed",assignedTo:c.assignedTo??"__unassigned__",projectPath:c.projectPath,cursor:c.nextCursor,limit:Bt});g(k=>ed(k,p.tasks)),N(k=>k.map(A=>Tt(A)===Tt(c)?{...A,returned:Math.min(A.total,A.returned+p.tasks.length),hasMore:p.hasMore===!0,nextCursor:p.nextCursor??null}:A))},[]),j=a.useCallback(()=>{w.current===null&&(w.current=window.setTimeout(()=>{w.current=null,S()},Ur))},[S]);return Vr(S,Kr(n)),a.useEffect(()=>()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),a.useEffect(()=>{const c=[r("task.updated",p=>{g(k=>Jl(k,p.data))}),r("task.status",p=>{g(k=>Hr(k,p.data))}),r("node",p=>{la(p.type)&&j()}),r("task",p=>{la(p.type)&&j()})];return()=>c.forEach(p=>p())},[r,j]),{completedGroups:b,fetchTasks:S,loadCompletedTasksPage:x,setTasks:g,tasks:i,tasksError:l,tasksLoading:v}}function wn(s){return s.map(t=>({...t}))}function ad(s,t){const n=t.get(s);return{logs:n?wn(n.logs):[],transcriptLoading:(n==null?void 0:n.loaded)!==!0}}function nd(s,t){return t.data.nodeId===s.self.id||t.data.name===s.self.name||t.data.endpoint===s.self.endpoint}function rd({cluster:s,subscribe:t}){a.useEffect(()=>{var n;if(((n=s==null?void 0:s.self)==null?void 0:n.role)==="leader")return t("node",o=>{const r=String(o.data.name??o.data.nodeId??"node"),i=nd(s,o);o.type==="node.joined"&&!i&&te.success(`${r} joined the cluster`),o.type==="node.left"&&!i&&te.message(`${r} left the cluster`)})},[s,t])}const od=[0,300,1e3,2e3];function id({task:s,getActiveTaskId:t,setLogs:n,setPendingMessages:o,setTranscriptLoading:r}){s.conversationKind==="nativeSession"&&(async()=>{try{for(const i of od){if(i>0&&await new Promise(g=>setTimeout(g,i)),t()!==s.id)return;try{const g=await bt(s.id);if(t()!==s.id||(n(b=>sn(b,g.logs)),o(b=>jt(b,g.logs)),g.total>0))return}catch{}}}finally{t()===s.id&&(r==null||r(!1))}})()}function ld(s,t){return Pe(s??{})===Pe(t??{})}function dd(s){return s&&"status"in s&&typeof s.status=="string"?s.status:void 0}function Ba(s,t){return{...s,enabled:!0,alwaysOnline:t}}function yn(s){var t,n;return((t=s==null?void 0:s.status)==null?void 0:t.trim())||((n=s==null?void 0:s.lastStatus)==null?void 0:n.trim())||"Unknown"}function cd({operationStarting:s,loading:t,refreshing:n,savedStatus:o,fallbackStatus:r}){return s?"Starting":t?"Listing DevBoxes":n?"Refreshing":o??r}function Ra({devbox:s,showStatus:t=!1}){return e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"font-medium",children:s.name}),s.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",s.projectName]})]}),t&&e.jsx("span",{className:"ml-auto shrink-0 rounded-full border border-border/70 bg-background/70 px-1.5 py-0.5 text-[10px] leading-none text-muted-foreground",children:yn(s)})]})}function ud({node:s,open:t,startInProgress:n=!1,onOpenChange:o,onRefresh:r}){const i=(s==null?void 0:s.id)??null,g=t&&!n&&Sa(s==null?void 0:s.status,(s==null?void 0:s.devbox)??null),[b,N]=a.useState([]),[v,f]=a.useState(()=>s!=null&&s.devbox?Pe(s.devbox):""),[l,u]=a.useState(()=>(s==null?void 0:s.devbox)??null),[w,S]=a.useState(()=>Ca((s==null?void 0:s.devbox)??null)),[x,j]=a.useState(!1),[c,p]=a.useState(g),[k,A]=a.useState(!1),[L,O]=a.useState(!1),[T,F]=a.useState(()=>{var m;return((m=s==null?void 0:s.devbox)==null?void 0:m.alwaysOnline)===!0}),U=a.useMemo(()=>{const m=b.find($=>Pe($)===v);return m||(Ns(l)&&Pe(l)===v?l:void 0)},[l,b,v]),M=dd(U??void 0),P=w?M??(l==null?void 0:l.lastStatus):(l==null?void 0:l.lastStatus)??M,E=(s==null?void 0:s.status)==="online"||(s==null?void 0:s.status)==="busy"?"Running":"Unknown",J=L||n,V=cd({operationStarting:J,loading:x,refreshing:c,savedStatus:P,fallbackStatus:E}),X=w&&!!U&&!ld(l,U),ce=(l==null?void 0:l.alwaysOnline)===!0!==T,ae=$l({nodeStatus:s==null?void 0:s.status,status:V,current:l,selected:U}),ee=!!ae,Z=!!U&&(X||ce)&&!ee,H=U??l,K=a.useCallback(async()=>{if(i){p(!0);try{const m=await qr(i);u(m.devbox),f(Pe(m.devbox))}catch(m){te.error(m instanceof Error?m.message:"Failed to refresh DevBox status")}finally{p(!1)}}},[i]),re=a.useCallback(async m=>{j(!0);try{const $=await Wr();N($),f(q=>Ol({previousKey:q,baseDevBox:m,listed:$}))}catch($){te.error($ instanceof Error?$.message:"Failed to load DevBoxes")}finally{j(!1)}},[]);a.useEffect(()=>{if(!t||!i)return;let m=!1;const $=(s==null?void 0:s.devbox)??null,q=Ca($),ne=!n&&Sa(s==null?void 0:s.status,$);j(!1),p(ne),S(q),u($),F(($==null?void 0:$.alwaysOnline)===!0),f(Ns($)?Pe($):""),N([]);async function W(){ne&&await K(),!m&&q&&await re($)}return W(),()=>{m=!0}},[re,s==null?void 0:s.devbox,s==null?void 0:s.status,i,t,K,n]);async function xe(){S(!0),b.length===0&&await re(l)}async function h(){if(!(!s||!U)){A(!0);try{const m=await da(s.id,Ba(U,T));u(m.node.devbox??null),m.node.devbox&&f(Pe(m.node.devbox)),S(!1),te.success(`Configured DevBox for ${s.name}`),await(r==null?void 0:r())}catch(m){te.error(m instanceof Error?m.message:"Failed to configure DevBox")}finally{A(!1)}}}async function I(){if(!(!s||!ae)){O(!0);try{if(U&&(X||ce)){const $=await da(s.id,Ba(U,T));u($.node.devbox??null),$.node.devbox&&f(Pe($.node.devbox)),S(!1)}const{operation:m}=await Ya(s.id);u($=>$&&{...$,lastStatus:"Starting",checkedAt:Date.now(),operationId:m.id}),te.success(`Start requested for ${s.name}`),await(r==null?void 0:r())}catch(m){te.error(m instanceof Error?m.message:"Failed to start DevBox")}finally{O(!1)}}}const C=x?"Loading DevBoxes...":b.length===0?"No DevBoxes available":"Select a DevBox",se=V==="Running"&&(s==null?void 0:s.status)==="offline";return e.jsx(At,{open:t,onOpenChange:o,children:e.jsxs(Mt,{className:"max-w-md gap-4 rounded-lg p-5",children:[e.jsxs(Ha,{className:"space-y-1",children:[e.jsx(Lt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(Gr,{className:"text-xs",children:["Bind ",s!=null&&s.name?e.jsx("span",{className:"font-medium text-foreground",children:s.name}):"this node"," to an Azure Dev Box. Meshy will start it when the node is offline."]})]}),e.jsxs("div",{className:"space-y-3",children:[(w||H)&&e.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 rounded-xl border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:w?e.jsxs(_e,{value:v,onValueChange:f,disabled:x||k||L||b.length===0,children:[e.jsx(Ee,{className:"h-7 justify-start gap-2 rounded-none border-0 bg-transparent px-0 text-xs shadow-none focus:ring-0 focus:ring-offset-0 [&>span]:!flex [&>span]:!min-w-0 [&>span]:!flex-1 [&>span]:!items-center",children:x&&!U?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),C]}):U?e.jsx(Ra,{devbox:U}):e.jsx(Ie,{placeholder:C})}),e.jsx(De,{children:b.map(m=>e.jsx(we,{value:Pe(m),textValue:`${m.name} ${m.projectName??""} ${yn(m)}`,className:"pl-2 pr-7 text-xs [&>span:first-child]:left-auto [&>span:first-child]:right-2 [&>span:last-child]:w-full",children:e.jsx(Ra,{devbox:m,showStatus:!0})},Pe(m)))})]}):H&&e.jsxs("div",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:H.name}),H.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",H.projectName]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Ke,{variant:"outline",className:"rounded-full px-2 py-0.5 text-[10px]",children:[(x||c)&&e.jsx(me,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),V]}),(l==null?void 0:l.name)&&e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{xe()},disabled:x||k||J||w,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-full text-muted-foreground hover:text-foreground",children:x&&w?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(ys,{className:"h-3 w-3"})})]})]}),se&&e.jsx("div",{className:"rounded-xl border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:"DevBox is running, but the Meshy node is not connected yet."}),e.jsxs("label",{className:"flex min-h-9 items-start gap-2 rounded-xl border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(gt,{checked:T,onCheckedChange:m=>F(m===!0),disabled:k||L||J,"aria-label":"Always online",className:"mt-0.5 h-3.5 w-3.5"}),e.jsxs("span",{className:"min-w-0 leading-4",children:[e.jsx("span",{className:"block",children:"Always online"}),e.jsx("span",{className:"block text-[10px] leading-3.5 text-muted-foreground",children:"Meshy will start the DevBox automatically when it is Hibernated or Stopped."})]})]})]}),e.jsxs(Ka,{className:"gap-2 sm:space-x-0",children:[e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>o(!1),disabled:k||L,className:"h-8 rounded-xl text-xs",children:"Close"}),ee&&e.jsxs(z,{size:"sm",onClick:I,disabled:L,className:"h-8 rounded-xl text-xs",children:[L?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx($t,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!ee&&e.jsxs(z,{size:"sm",onClick:h,disabled:!Z||k,className:"h-8 rounded-xl text-xs",children:[k&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function md(s,t=Qr){if(s.length===0)return new Set;const n=new Set(s),[o,r]=await Promise.all([t({kind:"devbox.start",status:"queued"}),t({kind:"devbox.start",status:"running"})]);return new Set([...o,...r].filter(i=>n.has(i.nodeId)).map(i=>i.nodeId))}function xd({cluster:s,refresh:t}){const[n,o]=a.useState(null),[r,i]=a.useState(null),[g,b]=a.useState(()=>new Set),[N,v]=a.useState(()=>new Set),f=a.useMemo(()=>(s==null?void 0:s.nodes.find(c=>c.id===n))??null,[s==null?void 0:s.nodes,n]),l=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(c=>{var p;return(p=c.devbox)==null?void 0:p.enabled}).map(c=>c.id)),[s==null?void 0:s.nodes]),u=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(c=>{var p;return Ks(c.status,(p=c.devbox)==null?void 0:p.lastStatus,c.devbox)}).map(c=>c.id)),[s==null?void 0:s.nodes]),w=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(c=>{var p;return ws((p=c.devbox)==null?void 0:p.lastStatus)}).map(c=>c.id)),[s==null?void 0:s.nodes]),S=a.useMemo(()=>{const c=new Set(g);r&&c.add(r);for(const p of N)c.add(p);for(const p of w)c.add(p);return c},[N,r,g,w]);a.useEffect(()=>{let c=!1;const p=[...l];async function k(){try{const A=await md(p);c||v(A)}catch{c||v(new Set)}}return k(),()=>{c=!0}},[l]),a.useEffect(()=>{b(c=>{var A;let p=!1;const k=new Set(c);for(const L of c){const O=s==null?void 0:s.nodes.find(T=>T.id===L);(O==null?void 0:O.status)!=="online"&&(!((A=O==null?void 0:O.devbox)!=null&&A.lastStatus)||ws(O.devbox.lastStatus))||(k.delete(L),p=!0)}return p?k:c})},[s==null?void 0:s.nodes]);const x=a.useCallback(async c=>{const p=s==null?void 0:s.nodes.find(k=>k.id===c);if(p){i(c),b(k=>new Set(k).add(c));try{await Ya(c),te.success(`Start requested for ${p.name}`),t()}catch(k){b(A=>{const L=new Set(A);return L.delete(c),L}),te.error(k instanceof Error?k.message:"Failed to start DevBox")}finally{i(null)}}},[s==null?void 0:s.nodes,t]);return{devBoxDialog:e.jsx(ud,{node:f,open:n!==null,startInProgress:f?S.has(f.id):!1,onOpenChange:c=>{c||o(null)},onRefresh:t}),devBoxNodeIds:l,devBoxStartNodeId:r,devBoxStartNodeIds:u,devBoxStartingNodeIds:S,openDevBox:o,startDevBox:x}}function hd(s){const[t,n]=a.useState(null),o=a.useCallback(i=>{s&&n(i)},[s]);return{nodeSettingsDialog:e.jsx(Yr,{open:t!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:t??void 0,showTrigger:!1}),openNodeSettings:o}}function fd({activeTaskId:s,fetchActiveTask:t,setPendingMessages:n,setTask:o,setTasks:r}){const i=a.useCallback((N,v)=>{o(f=>f&&f.id===N?{...f,queuedMessages:v}:f),r(f=>f.map(l=>l.id===N?{...l,queuedMessages:v}:l))},[o,r]),g=a.useCallback(async N=>{if(!s)return!1;const v=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`;n(f=>[...f,{id:v,content:N,timestamp:new Date().toISOString()}]);try{const f=await Xr(s,N);return f.queued&&(n(l=>l.filter(u=>u.id!==v)),f.queuedMessages&&i(s,f.queuedMessages)),t(),!0}catch(f){return n(l=>l.filter(u=>u.id!==v)),te.error(f instanceof Error?f.message:"Failed to send message"),!1}},[s,t,n,i]);return{cancelQueuedMessage:a.useCallback(async N=>{if(s)try{const v=await Jr(s,N);i(s,v.queuedMessages),t()}catch(v){te.error(v instanceof Error?v.message:"Failed to cancel queued message")}},[s,t,i]),queueFollowUpMessage:g}}function pd(){var Yt,Xt,Jt,Zt,ea,sa;const{id:s}=Zr(),t=eo(),n=so(),o=to(),{cluster:r,systemInfo:i,events:g,sseConnected:b,subscribe:N,refresh:v,loading:f,error:l}=ao(),u=a.useMemo(()=>no(t.state),[t.state]),[w,S]=a.useState(null),[x,j]=a.useState("active"),[c,p]=a.useState("all"),[k,A]=a.useState("all"),[L,O]=a.useState("all"),[T,F]=a.useState(""),U=(o==null?void 0:o.headerSearchQuery)??T,M=(o==null?void 0:o.setHeaderSearchQuery)??F,P=a.useDeferredValue(U),{desktopTasksOpen:E,mobileTasksPanelOpen:J,mobileTasksPanelRef:V,operationsOpen:X,operationsPanelRef:ce,panelResize:ae,setMobileTasksPanelOpen:ee,setOperationsOpen:Z,toggleTasksPanel:H}=Xl(),[K,re]=a.useState(()=>!!(u!=null&&u.draftNewTask)),[xe,h]=a.useState(()=>(u==null?void 0:u.createMode)??"chat"),[I,C]=a.useState(()=>u!=null&&u.draftNewTask?{route:u.returnRoute??"/",taskId:u.returnTaskId??null}:null),[se,m]=a.useState(!1),[$,q]=a.useState("transcript"),[ne,W]=a.useState("all"),[ie,oe]=a.useState(!1),[Te,D]=a.useState(null),[Q,ge]=a.useState([]),[He,Y]=a.useState([]),[be,ye]=a.useState(!1),[Je,Be]=a.useState(!1),[je,Ye]=a.useState(null),[ke,Ae]=a.useState(new Set),[Ze,ms]=a.useState(!1),[as,os]=a.useState(!1),[is,xs]=a.useState(null),$e=a.useRef(null),ls=a.useRef(new Map),Me=((Yt=r==null?void 0:r.self)==null?void 0:Yt.role)==="leader",hs=(Xt=r==null?void 0:r.self)==null?void 0:Xt.id;rd({cluster:r,subscribe:N});const{nodeSettingsDialog:_,openNodeSettings:fe}=hd(Me),{devBoxDialog:ue,devBoxNodeIds:ze,devBoxStartNodeId:We,devBoxStartNodeIds:Le,devBoxStartingNodeIds:ve,openDevBox:Ne,startDevBox:es}=xd({cluster:r,refresh:v}),{completedGroups:Ss=[],fetchTasks:Se,loadCompletedTasksPage:Cs,setTasks:fs,tasks:Oe,tasksError:Ce,tasksLoading:ss}=td({isLeader:Me,selfId:hs,sseConnected:b,preservedTask:Te,subscribe:N}),Fe=a.useMemo(()=>[...Oe].sort((d,y)=>y.updatedAt-d.updatedAt),[Oe]),Ue=a.useMemo(()=>{var d;return((d=[...Oe].sort((y,R)=>R.createdAt-y.createdAt||R.updatedAt-y.updatedAt)[0])==null?void 0:d.id)??null},[Oe]),_s=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[]){const R=ji(Fe,y.id);R>0&&d.set(y.id,R)}return d},[r==null?void 0:r.nodes,Fe]),Ge=a.useMemo(()=>Fe.filter(d=>!ro(d,r==null?void 0:r.nodes,r==null?void 0:r.self)||!oo(d,x)||c!=="all"&&d.agent!==c||!io(d,L)||k==="unassigned"&&d.assignedTo||k!=="all"&&k!=="unassigned"&&lo(d.assignedTo,r==null?void 0:r.nodes,d.assignedNodeName)!==k?!1:P.trim()?co(d,P):!0),[Fe,r==null?void 0:r.nodes,r==null?void 0:r.self,x,c,L,k,P]);a.useEffect(()=>{Ae(d=>{const y=Ci(d,Ge.map(R=>R.id));return y.size===d.size?d:y})},[Ge]),a.useEffect(()=>{Me||Ae(new Set)},[Me]);const kn=a.useMemo(()=>["all",...Array.from(new Set(Fe.map(d=>d.agent))).sort()],[Fe]),Sn=a.useMemo(()=>{const y=Array.from(new Set(Fe.map(R=>R.assignedTo).filter(R=>!!R))).map(R=>{const pe=Fe.find(le=>le.assignedTo===R);return(r==null?void 0:r.nodes.find(le=>le.id===R))??{id:R,name:lt(R,r==null?void 0:r.nodes,pe==null?void 0:pe.assignedNodeName)}}).sort((R,pe)=>R.name.localeCompare(pe.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...y.map(R=>({value:R.name.toLowerCase(),label:R.name}))]},[Fe,r==null?void 0:r.nodes]),qt=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[])d.set(y.id,y.name);for(const y of Fe)y.assignedTo&&y.assignedNodeName&&!d.has(y.assignedTo)&&d.set(y.assignedTo,y.assignedNodeName);return d},[r==null?void 0:r.nodes,Fe]),Cn=a.useMemo(()=>{var y;const d=new Map;for(const R of(r==null?void 0:r.nodes)??[])R.workDir&&d.set(R.id,R.workDir);return(y=r==null?void 0:r.self)!=null&&y.workDir&&d.set(r.self.id,r.self.workDir),d},[r]),_n=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[])d.set(y.id,y.status);return r!=null&&r.self&&d.set(r.self.id,r.self.status),d},[r]),En=a.useMemo(()=>new Map(Ss.map(d=>[Tt(d),d])),[Ss]),Wt=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[])y.status!=="offline"&&d.set(y.id,y);return r!=null&&r.self&&r.self.status!=="offline"&&d.set(r.self.id,r.self),Array.from(d.values())},[r]),Dn=((Jt=r==null?void 0:r.self)==null?void 0:Jt.id)??((Zt=Wt[0])==null?void 0:Zt.id)??null,qs=a.useMemo(()=>["all",...Array.from(new Set(g.map(d=>d.type))).sort()],[g]),Tn=a.useMemo(()=>ne==="all"?g:g.filter(d=>d.type===ne),[g,ne]),An=Ge.length>0&&Ge.every(d=>ke.has(d.id)),Mn=Ge.some(d=>ke.has(d.id)),Ln=_i(Ge,ke);a.useEffect(()=>{u!=null&&u.draftNewTask&&(re(!0),C({route:u.returnRoute??"/",taskId:u.returnTaskId??null}))},[u]),a.useEffect(()=>{ne!=="all"&&!qs.includes(ne)&&W("all")},[ne,qs]),a.useEffect(()=>{ga(s,K)&&!w&&Ue&&S(Ue)},[s,K,w,Ue]),a.useEffect(()=>{ga(s,K)&&(w&&Oe.some(d=>d.id===w)||S(Ue))},[s,K,w,Ue,Oe]);const de=wi({routeTaskId:s,creatingTask:K,internalSelectedTaskId:w,sortedTaskIds:Ue?[Ue]:[]}),ps=a.useMemo(()=>Oe.find(d=>d.id===de)??null,[Oe,de]);a.useEffect(()=>{$e.current=de??null},[de]);const ns=a.useCallback(()=>{D(null),ge([]),Y([]),Ye(null),Be(!1)},[]),Es=a.useCallback((d,y,R=!0)=>{ls.current.set(d,{logs:wn(y),loaded:R})},[]),Ve=a.useCallback(async()=>{const d=de;if(d)try{const y=await uo(d);if($e.current!==d)return;D(y),fs(R=>ln(R,y)),Ye(null)}catch(y){if($e.current!==d)return;ns(),Ye(y instanceof Error?y.message:"Failed to load task")}finally{$e.current===d&&ye(!1)}},[de,ns,fs]),Bs=a.useCallback(async()=>{const d=de;if(d)try{const y=await bt(d);if($e.current!==d)return;ge(R=>{const pe=sn(R,y.logs);return Es(d,pe),pe}),Y(R=>jt(R,y.logs))}catch{}finally{$e.current===d&&Be(!1)}},[de,Es]);a.useEffect(()=>{if(!de){ns(),ye(!1);return}q("transcript"),D(ps);const d=ad(de,ls.current);ge(d.logs),Y([]),Ye(null),ye(!0),Be(d.transcriptLoading),Ve(),Bs()},[de,ns,Bs,Ve]),a.useEffect(()=>{if(!yi({activeTaskId:de,routeTaskId:s,creatingTask:K,tasksLoading:ss,loadedTaskIds:Oe.map(y=>y.id)}))return;const d=Ue;S(d),ns(),a.startTransition(()=>{n(d?`/tasks/${d}`:"/",{state:null})})},[de,ns,K,Ue,n,s,Oe,ss]),a.useEffect(()=>{ps&&D(d=>!d||d.id!==ps.id?d:{...d,...ps})},[ps]),a.useEffect(()=>{if(de)return N("task",d=>{const y=d.data.taskId;if(!(typeof y!="string"||y!==de)){if(d.type==="task.output"){const R=d.data.event;if(R){ge(le=>{const Ts=Eo(le,R);return Es(de,Ts),Ts}),Be(!1);const pe=ha(R);pe&&Y(le=>Do(le,pe))}}d.type==="task.updated"&&Ve(),d.type==="task.status"&&(Ve(),Bs())}})},[N,de,Ve,Bs]);const G=Te??ps,Pn=G!=null&&G.assignedTo?(r==null?void 0:r.nodes.find(d=>d.id===G.assignedTo))??null:null,Ds=o==null?void 0:o.setHeaderTaskContext;a.useEffect(()=>{if(!Ds)return;if(!G){Ds(null);return}const d=G.effectiveProjectPath??G.project??"default workspace";return Ds({taskId:G.id,taskTitle:G.title,nodeName:lt(G.assignedTo,r==null?void 0:r.nodes,G.assignedNodeName),projectLabel:Qa(d),projectPath:d}),()=>Ds(null)},[G,r==null?void 0:r.nodes,Ds]);const Ws=He.length>0,Bn=G?mo.has(G.agent):!1,Gs=(G==null?void 0:G.status)==="running",Rn=G?Vs.has(G.status):!1,$n=G?Vs.has(G.status)||xo.has(G.status):!1,On=!!(G&&Me&&G.status==="failed"),Qs=a.useMemo(()=>zl(G,r,Ws,!!Gs),[G,r,Ws,Gs]),Ys=a.useMemo(()=>To([...Q,...He.map(d=>tt(d.content,d.timestamp))]),[Q,He]),Rs=a.useMemo(()=>{if(!G||G.conversationKind==="nativeSession")return null;const d=Ao(G);if(d.length>0)return tt(d,new Date(G.createdAt).toISOString());if(Ys.length>0)return null;const y=Mo(G.description||G.title);return y.length>0?tt(y,new Date(G.createdAt).toISOString()):null},[G,Ys]),Xs=a.useMemo(()=>Rs?ha(Rs):null,[Rs]),Fn=a.useMemo(()=>Xs?Lo(Q,Xs):!1,[Q,Xs]),Js=a.useCallback((d="chat")=>{const y={route:s?`/tasks/${s}`:"/",taskId:de};C(y),h(d),re(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:y.route,returnTaskId:y.taskId,createMode:d}})})},[s,de,n]),In=a.useCallback(()=>{const d=(I==null?void 0:I.taskId)??Ue;re(!1),C(null),S(d),a.startTransition(()=>{n((I==null?void 0:I.route)??"/",{state:null})})},[I,Ue,n]),Gt=a.useCallback(d=>{re(!1),C(null),S(d),a.startTransition(()=>{n(`/tasks/${d}`,{state:null})})},[n]),zn=a.useCallback(d=>{$e.current=d.id,re(!1),C(null),fs(y=>ki(y,d)),D(d),ge([]),Y([]),Ye(null),ye(!1),Be(d.conversationKind==="nativeSession"),q("transcript"),S(d.id),id({task:d,getActiveTaskId:()=>$e.current,setLogs:ge,setPendingMessages:Y,setTranscriptLoading:Be}),Se(),a.startTransition(()=>{n(`/tasks/${d.id}`,{state:null})})},[Se,n]),{cancelQueuedMessage:Un,queueFollowUpMessage:$s}=fd({activeTaskId:de,fetchActiveTask:Ve,setPendingMessages:Y,setTask:D,setTasks:fs}),Vn=a.useCallback(d=>{$s(d)},[$s]),Hn=a.useCallback(async()=>{const d=de;if(!(!d||(G==null?void 0:G.conversationKind)!=="nativeSession")){Be(!0);try{const y=await bt(d);if($e.current!==d)return;ge(y.logs),Es(d,y.logs),Y(R=>jt(R,y.logs))}catch(y){te.error(y instanceof Error?y.message:"Failed to reload transcript")}finally{$e.current===d&&Be(!1)}}},[G==null?void 0:G.conversationKind,de,Es]),Kn=a.useCallback(d=>$s(d),[$s]),qn=a.useCallback(async()=>{if(G)try{await ho(G.id),Ve(),Se()}catch(d){te.error(d instanceof Error?d.message:"Failed to cancel task")}},[G,Ve,Se]),{handleShareTask:Wn,handleStopShareTask:Gn}=Wl(G,Ve,Se),Qn=a.useCallback(async()=>{if(G)try{await fo(G.id),Ve(),Se()}catch(d){te.error(d instanceof Error?d.message:"Failed to retry task")}},[G,Ve,Se]),Os=a.useCallback((d,y=!1)=>{const R=Ei(Ge,d);return S(R),(y||!R)&&ns(),a.startTransition(()=>{n(R?`/tasks/${R}`:"/",{state:null})}),R},[ns,Ge,n]),Yn=a.useCallback((d,y)=>{Ae(R=>{const pe=new Set(R);return y?pe.add(d):pe.delete(d),pe})},[]),Xn=a.useCallback(d=>{if(!d){Ae(new Set);return}Ae(new Set(Ge.map(y=>y.id)))},[Ge]),Jn=a.useCallback(async()=>{const d=Array.from(ke);if(d.length!==0)try{const{results:y}=await po(d),R=y.filter(le=>!le.ok),pe=y.filter(le=>le.ok).map(le=>le.id);de&&pe.includes(de)&&Os(pe),R.length>0?te.error(`Failed to archive ${R.length} task(s): ${R.map(le=>le.error??le.id).join(", ")}`):te.success(`Archived ${pe.length} task(s)`),Ae(new Set(R.map(le=>le.id))),Se()}catch(y){te.error(y instanceof Error?y.message:"Failed to archive tasks")}},[de,Se,Os,ke]),Zn=a.useCallback(async()=>{const d=Array.from(ke);if(d.length!==0)try{const{results:y}=await go(d),R=y.filter(le=>!le.ok),pe=y.filter(le=>le.ok).map(le=>le.id);de&&pe.includes(de)&&Os(pe,!0),R.length>0?te.error(`Failed to delete ${R.length} task(s): ${R.map(le=>le.error??le.id).join(", ")}`):te.success(`Deleted ${pe.length} task(s)`),Ae(new Set(R.map(le=>le.id))),Se()}catch(y){te.error(y instanceof Error?y.message:"Failed to delete tasks")}},[de,Se,Os,ke]),er=a.useCallback(async()=>{ms(!0);try{await bo(),v()}catch(d){te.error(d instanceof Error?d.message:"Failed to promote node")}finally{ms(!1)}},[v]),sr=a.useCallback(async()=>{os(!0);try{await vo(),te.success("This node left the remote cluster and is leading itself again."),Se(),Ve(),v()}catch(d){te.error(d instanceof Error?d.message:"Failed to leave cluster")}finally{os(!1)}},[Ve,Se,v]),tr=a.useCallback(async d=>{var Ts;const y=!Ut(d),R=d.id===((Ts=r==null?void 0:r.self)==null?void 0:Ts.id),pe=R?(i==null?void 0:i.transportType)??d.transportType:d.transportType,le=R&&!y&&ks(pe);xs(d.id);try{le?await jo("direct"):await No(d.id,y),te.success(y?`Enabled remote access on ${d.name}`:`Disabled remote access on ${d.name}`),v()}catch(ta){te.error(ta instanceof Error?ta.message:"Failed to update remote access")}finally{xs(null)}},[(ea=r==null?void 0:r.self)==null?void 0:ea.id,v,i==null?void 0:i.transportType]),ar=a.useCallback(d=>{Cs&&Cs(d).catch(y=>{te.error(y instanceof Error?y.message:"Failed to load completed tasks")})},[Cs]),Qt={toolbarTasks:Ge,activeTaskId:de,tasksLoading:ss,tasksError:Ce,isLeader:Me,scope:x,agentFilter:c,nodeFilter:k,taskKindFilter:L,agentOptions:kn,nodeOptions:Sn,nodeNameById:qt,nodeWorkDirById:Cn,nodeStatusById:_n,leaderNodeId:((sa=r==null?void 0:r.leader)==null?void 0:sa.id)??null,searchQuery:U,completedGroupByKey:En,devBoxNodeIds:ze,devBoxStartNodeIds:Le,devBoxStartingNodeIds:ve,selectedTaskIds:ke,allVisibleTasksSelected:An,someVisibleTasksSelected:Mn,canBatchArchive:Ln,onSearchChange:M,onScopeChange:j,onAgentFilterChange:p,onNodeFilterChange:A,onTaskKindFilterChange:O,onToggleTaskSelected:Yn,onToggleAllVisibleTasks:Xn,onBatchArchive:Jn,onBatchDelete:Zn,onCreateTask:Js,onOpenNodeSettings:Me?fe:void 0,onOpenDevBox:Me?Ne:void 0,onStartDevBox:Me?es:void 0,onLoadCompletedTasks:ar,onSelectTask:Gt,onClose:H},nr={cluster:r,systemInfo:i,nodeNameById:qt,nodeBlockingTaskCounts:_s,eventTypeFilter:ne,onEventTypeFilterChange:W,eventTypeOptions:qs,filteredEvents:Tn,sseConnected:b,clusterLoading:f,clusterError:l,promotePending:Ze,onPromote:er,onAddNode:()=>m(!0),leavePending:as,onLeaveCluster:sr,onToggleNodeDevTunnel:tr,devTunnelNodeId:is,devBoxStartNodeId:We,devBoxStartingNodeIds:ve,onOpenNodeSettings:Me?fe:void 0,onOpenDevBox:Me?Ne:void 0,onStartDevBox:Me?es:void 0,onClose:()=>Z(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Sl,{desktopTasksOpen:E,mobileTasksPanelOpen:J,mobileTasksPanelRef:V,operationsOpen:X,operationsPanelRef:ce,panelResize:ae,taskSidebar:e.jsx(Ma,{...Qt}),operationsSidecar:e.jsx(Fl,{...nr}),terminalPanel:o!=null&&o.terminalOpen?e.jsx(Ll,{nodes:Wt,defaultNodeId:Dn,onClose:()=>o==null?void 0:o.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(Nl,{onToggleTasks:H,desktopTasksOpen:E,mobileTasksPanelOpen:J,operationsOpen:X,onToggleOperations:()=>Z(d=>!d),cluster:r,sseConnected:b,activeTab:$,setActiveTab:q,creatingTask:K,createMode:xe,activeTask:G,assignedNode:Pn,taskLoading:be,transcriptLoading:Je,taskError:je,displayEvents:Ys,initialPromptAlreadyInLogs:Fn,initialPrompt:Rs,supportsFollowUp:Bn,taskUnavailable:Qs.taskUnavailable,chatDisabled:Qs.chatDisabled,chatDisabledReason:Qs.chatDisabledReason,questionBypassEnabled:ie,isRunning:!!Gs,isStarting:Rn,hasPendingFollowUp:Ws,canCancel:!!$n,canRetry:!!On,onRetry:Qn,onCancel:qn,onReloadNativeTranscript:Hn,onShareTask:Wn,onStopShareTask:Gn,onStartCreateTask:Js,onCancelCreateTask:In,onCreateTask:zn,onSendMessage:Vn,onCancelQueuedMessage:Un,onQuestionBypassChange:oe,onSubmitQuestionResponse:Kn}),mobileTaskSidebar:e.jsx(Ma,{...Qt,onCreateTask:d=>{ee(!1),Js(d)},onSelectTask:d=>{ee(!1),Gt(d)},onClose:()=>ee(!1)}),onCloseOperations:()=>Z(!1),onCloseTaskList:()=>ee(!1)}),e.jsx(kl,{open:se,onOpenChange:m,onAdded:v}),_,ue]})}const jd=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:pd},Symbol.toStringTag,{value:"Module"}));export{jd as D,Nt as G};
132
+ */const gi=[["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"}]],bi=he("trash-2",gi),vi=new Set(["assigned","running"]);function ji(s,t){return s.reduce((n,o)=>o.assignedTo===t&&vi.has(o.status)?n+1:n,0)}function ks(s){return(s==null?void 0:s.toLowerCase())==="devtunnel"}function Ni(s){return s?ks(s)?"DevTunnel":s.charAt(0).toUpperCase()+s.slice(1):"Direct"}function zt(s,t){return ks(t??s.transportType)||!!s.devtunnelEndpoint}function rn(s,t){return!ks(t??s.transportType)}function on(s,t){const n=t??s.transportType;return ks(n)?"DevTunnel":s.devtunnelEndpoint?"Direct + DevTunnel":Ni(n)}function ga(s,t){return!s&&!t}function wi({routeTaskId:s,creatingTask:t,internalSelectedTaskId:n,sortedTaskIds:o}){return s||(t?null:o[0]??n??null)}function yi({activeTaskId:s,routeTaskId:t,creatingTask:n,tasksLoading:o,loadedTaskIds:r}){return!s||t||n||o?!1:!r.includes(s)}function ki(s,t){return[t,...s.filter(n=>n.id!==t.id)]}function ln(s,t){const n=s.findIndex(o=>o.id===t.id);return n===-1?[...s,t]:s.map((o,r)=>r===n?t:o)}const Si=new Set(["completed","failed","cancelled","archived"]);function Ci(s,t){const n=new Set(t);return new Set(Array.from(s).filter(o=>n.has(o)))}function _i(s,t){const n=new Set(t);if(n.size===0)return!1;const o=s.filter(r=>n.has(r.id));return o.length===n.size&&o.every(r=>Si.has(r.status))}function Ei(s,t){var o;const n=new Set(t);return((o=s.find(r=>!n.has(r.id)))==null?void 0:o.id)??null}function dn(){const[s,t]=a.useState([]),[n,o]=a.useState(null),r=a.useRef(null),i=a.useCallback(()=>{var f;(f=r.current)==null||f.click()},[]),g=a.useCallback(async f=>{const l=Array.from(f.target.files??[]);if(l.length!==0)try{const u=await ca(l);t(w=>[...w,...u]),o(null)}catch(u){o(u instanceof Error?u.message:"Failed to attach image")}finally{f.target.value=""}},[]),b=a.useCallback(async f=>{const l=wo(f.clipboardData);if(l.length!==0){f.preventDefault();try{const u=await ca(l);t(w=>[...w,...u]),o(null)}catch(u){o(u instanceof Error?u.message:"Failed to attach image")}}},[]),N=a.useCallback(f=>{t(l=>l.filter((u,w)=>w!==f))},[]),v=a.useCallback(()=>{t([]),o(null)},[]);return{images:s,error:n,fileInputRef:r,pickImages:i,handleFileChange:g,handlePaste:b,removeImage:N,clearImages:v}}function Di(s){const t=s.map(r=>({...r,displayValue:Ti(r)})),n=t.findIndex(r=>r.label.toLowerCase()==="working dir"),o=n>=0?n:0;return{primary:t[o],secondary:t.filter((r,i)=>i!==o)}}function Ti(s){return s.label.toLowerCase()==="agent"?Za(s.value):s.value}function ba(s){switch(s.toLowerCase()){case"branch":return jt;case"node":return $a;case"working dir":default:return $t}}function Ai({disabled:s=!1,running:t=!1,canStop:n=!1,hasContent:o=!1}){return t&&!o?{primaryAction:"stop",primaryDisabled:s||!n}:{primaryAction:"send",primaryDisabled:s||!o}}function Mi({onSend:s,disabled:t,disabledReason:n="Chat is waiting on the agent.",placeholder:o="Send a follow-up message...",contextItems:r=[],running:i=!1,onStop:g}){const[b,N]=a.useState(""),v=a.useRef(null),{images:f,error:l,fileInputRef:u,pickImages:w,handleFileChange:S,handlePaste:x,removeImage:j,clearImages:c}=dn(),p=a.useCallback(()=>{v.current&&(v.current.style.height="auto")},[]),k=a.useCallback(()=>{const E=Xa(b,f);E.length===0||t||(s(E),N(""),c(),p())},[b,f,t,s,c,p]),A=a.useCallback(E=>{E.key==="Enter"&&!E.shiftKey&&(E.preventDefault(),k())},[k]),L=a.useCallback(()=>{v.current&&(v.current.style.height="auto",v.current.style.height=`${Math.min(v.current.scrollHeight,220)}px`)},[]),O=b.trim().length>0||f.length>0,F=Ai({disabled:t,running:i,canStop:i&&!!g,hasContent:O}),U=Di(r),M=U.primary?ba(U.primary.label):$t,P=i?O?"Enter queues this message for the next turn":g?"Task is running - type to queue, empty button stops task":"Task is running - type to queue a message":t?n:"Enter sends, Shift+Enter adds a line";return e.jsx("div",{"data-chat-input-shell":"true",className:"chat-input-shell animate-composer-settle w-full bg-background/35 px-2 pb-2 pt-0 sm:px-4 sm:pb-3",children:e.jsx("div",{"data-chat-input-column":"true",className:"mx-auto w-full max-w-[72rem]",children:e.jsxs("div",{"data-chat-input-card":"true",className:"chat-input-card overflow-hidden rounded-xl border border-border/65 bg-card/88 sm:rounded-xl",children:[e.jsx("input",{ref:u,type:"file",accept:"image/*",multiple:!0,onChange:S,className:"hidden"}),U.primary&&e.jsx("div",{"data-chat-input-primary-context":"true",className:"px-2.5 pt-1.5 sm:px-5 sm:pt-2",children:e.jsxs("div",{className:"-ml-1.5 inline-flex max-w-full items-center gap-1.5 rounded-sm bg-muted/45 px-1.5 py-0.5 shadow-[0_10px_28px_-18px_rgba(15,23,42,0.72)] sm:-ml-2 dark:shadow-[0_10px_28px_-18px_rgba(0,0,0,0.95)]",children:[e.jsx(M,{className:"h-2.5 w-2.5 shrink-0 text-primary/45","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[9px] leading-3 text-muted-foreground/72",title:U.primary.value,children:U.primary.displayValue})]})}),f.length>0&&e.jsx("div",{className:"px-2 pt-2.5 sm:px-5 sm:pt-4",children:e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map((E,J)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Ja(E),alt:E.filename??`attachment ${J+1}`,className:"h-24 w-24 rounded-xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>j(J),className:"absolute -top-2 -right-2 flex h-7 w-7 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${E.filename??`image ${J+1}`}`,children:e.jsx(ss,{className:"h-3.5 w-3.5"})})]},`${E.filename??"image"}-${J}`))})}),e.jsx("div",{className:"px-2 pb-0 pt-1 sm:px-5 sm:pt-1.5",children:e.jsx("textarea",{ref:v,value:b,onChange:E=>N(E.target.value),onKeyDown:A,onPaste:x,onInput:L,placeholder:o,disabled:t,rows:1,className:"min-h-[1.35rem] w-full resize-none overflow-x-hidden overflow-y-auto bg-transparent px-0 py-0 text-[11px] leading-[1.35rem] text-foreground placeholder:text-[10px] placeholder:text-muted-foreground/65 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50"})}),e.jsxs("div",{className:"flex items-end justify-between gap-2 px-2 pb-1.5 pt-0.5 sm:px-5 sm:pb-2.5",children:[U.secondary.length>0?e.jsx("div",{"data-chat-input-secondary-context":"true",className:"flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 pb-0.5 text-[9px] leading-3 text-muted-foreground/72 sm:text-[9px]",children:U.secondary.map(E=>{const J=ba(E.label),V=E.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${E.label}: ${E.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[V?e.jsx(Bt,{agent:E.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(J,{"data-chat-input-secondary-icon":"true",className:"h-2.5 w-2.5 shrink-0 text-primary/50","aria-hidden":"true"}),e.jsx("span",{className:`truncate ${E.mono?"font-mono":""}`,children:E.displayValue})]},`${E.label}:${E.value}`)})}):e.jsx("div",{className:"min-w-0 flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(z,{type:"button",variant:"ghost",onClick:w,disabled:t,className:"h-7 shrink-0 gap-1.5 rounded-sm px-2 text-[10px] text-muted-foreground hover:text-foreground sm:px-2",title:"Attach images",children:[e.jsx(wt,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:P,children:e.jsx(z,{onClick:F.primaryAction==="stop"?g:k,disabled:F.primaryDisabled,size:"icon","aria-label":F.primaryAction==="stop"?"Stop running task":i?"Queue message":"Send message",className:"h-7 w-9 shrink-0 rounded-sm bg-primary/90 text-primary-foreground shadow-[0_12px_30px_-18px_hsl(var(--primary)/0.95)] hover:bg-primary",children:F.primaryAction==="stop"?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(nn,{className:"h-3.5 w-3.5"})})})]})]}),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})]})})})}var Li=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Pi=Li.reduce((s,t)=>{const n=rr(`Primitive.${t}`),o=a.forwardRef((r,i)=>{const{asChild:g,...b}=r,N=g?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(N,{...b,ref:i})});return o.displayName=`Primitive.${t}`,{...s,[t]:o}},{}),Bi="Label",cn=a.forwardRef((s,t)=>e.jsx(Pi.label,{...s,ref:t,onMouseDown:n=>{var r;n.target.closest("button, input, select, textarea")||((r=s.onMouseDown)==null||r.call(s,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));cn.displayName=Bi;var un=cn;const Ri=or("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Re=a.forwardRef(({className:s,...t},n)=>e.jsx(un,{ref:n,className:B(Ri(),s),...t}));Re.displayName=un.displayName;function $i(s,t,n){return s!=="auto"?t.find(o=>o.id===s)??null:n.length===1?n[0]??null:null}function Oi(s){return s.trim()||"."}function Fi(s){return new Promise(t=>window.setTimeout(t,s))}function Ii(s){return!!s&&typeof s=="object"&&typeof s.createdBranch=="string"&&typeof s.currentBranch<"u"}async function zi(s){let t=s;for(let n=0;n<60;n++){if(t.status==="succeeded"){if(Ii(t.result))return t.result;throw new Error("Branch creation completed without branch details")}if(t.status==="failed")throw new Error(t.error||"Branch creation failed");await Fi(1e3),t=await dr(t.id)}throw new Error("Timed out waiting for branch creation")}function va({value:s,onChange:t,project:n,assignTo:o,nodes:r,assignableNodes:i,layout:g="default",chipClassName:b,chipActiveClassName:N,chipInactiveClassName:v,labelClassName:f,triggerClassName:l}){const[u,w]=a.useState(!1),[S,x]=a.useState(null),[j,c]=a.useState(""),[p,k]=a.useState(!1),[A,L]=a.useState(!1),[O,T]=a.useState(!1),[F,U]=a.useState(null),[M,P]=a.useState(""),[E,J]=a.useState(""),[V,X]=a.useState(""),[ce,ae]=a.useState(!1),ee=a.useRef(null),Z=a.useRef(0),H=a.useMemo(()=>$i(o,r,i),[o,r,i]),K=H==null?void 0:H.id,re=a.useMemo(()=>Oi(n),[n]),xe=a.useMemo(()=>K?`${K}
133
+ ${re}`:"",[K,re]),h=a.useCallback(async(W=0,ie=!1)=>{const oe=Z.current+1,Te=xe;if(Z.current=oe,!K){x(null),c("");return}U(null),ie||c(""),ie?L(!0):k(!0);try{const D=await ir(K,{path:re,limit:20,offset:W,allowAbsolute:!0});if(oe!==Z.current)return;c(Te),x(Q=>ie&&Q?{...D,branches:[...Q.branches,...D.branches]}:D)}catch(D){if(oe!==Z.current)return;U(D instanceof Error?D.message:"Failed to load branch info"),ie||(x(null),c(""))}finally{oe===Z.current&&(k(!1),L(!1))}},[K,xe,re]);a.useEffect(()=>{if(!K){Z.current+=1,x(null),c(""),U(null);return}h()},[K,re,h]),a.useEffect(()=>{const W=s.trim(),ie=j===xe?S:null,oe=ie!=null&&ie.available&&ie.currentBranch?ie.currentBranch:"";W!==oe&&t(oe)},[S,xe,j,t,s]),a.useEffect(()=>{if(!u)return;const W=oe=>{ee.current&&(ee.current.contains(oe.target)||w(!1))},ie=oe=>{oe.key==="Escape"&&w(!1)};return document.addEventListener("mousedown",W),document.addEventListener("keydown",ie),()=>{document.removeEventListener("mousedown",W),document.removeEventListener("keydown",ie)}},[u]),a.useEffect(()=>{u&&(J(""),X(""),ae(!1))},[u,K,re]);const I=a.useCallback(async()=>{if(!K)return;const W=M.trim(),ie=ce?V.trim():E.trim();if(!(!W||!ie)){T(!0),U(null);try{const oe=await lr(K,{path:re,branchName:W,startPoint:ie,limit:20,offset:0,allowAbsolute:!0}),Te=await zi(oe);c(xe),x(Te),t(Te.currentBranch??Te.createdBranch),P(""),J(""),X(""),ae(!1),w(!1)}catch(oe){U(oe instanceof Error?oe.message:"Failed to create branch")}finally{T(!1)}}},[K,xe,re,ce,V,M,t,E]),C=j===xe?S:null,se=a.useCallback(()=>{C!=null&&C.hasMore&&h(C.branches.length,!0)},[C,h]),m=s.trim()||(C==null?void 0:C.currentBranch)||(C&&!C.available?"No git repo":"Branch"),$=ce?V.trim():E.trim(),q=!!(C!=null&&C.available&&M.trim()&&$&&!O),ne=g==="composer"?e.jsxs(z,{type:"button",variant:"ghost",onClick:()=>w(W=>!W),title:m,"aria-label":`Branch: ${m}`,className:B(b,l,"min-w-0 max-w-full",s.trim()?N:v),children:[p&&!C?e.jsx(me,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(jt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:B("min-w-0 truncate",f),children:m})]}):e.jsxs(z,{type:"button",variant:"outline",onClick:()=>w(W=>!W),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:m,children:[e.jsx("span",{className:B("truncate",s.trim()?"font-mono text-foreground":"text-muted-foreground"),children:m}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:H?H.name:"Manual"})]});return e.jsxs("div",{className:B("relative inline-block",g==="composer"?"min-w-0 shrink-0":"w-full"),ref:ee,children:[g==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Branch"}),ne]}):ne,u&&e.jsxs("div",{className:B("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",g==="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(jt,{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:C!=null&&C.repoRoot?`${C.currentBranch??m} · ${C.repoRoot}`:(C==null?void 0:C.currentBranch)??m,children:(C==null?void 0:C.currentBranch)??m}),p?e.jsx(me,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),H?p&&!C?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(me,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):C&&!C.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(Xe,{value:M,onChange:W=>P(W.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(z,{type:"button",size:"sm",onClick:()=>void I(),disabled:!q,title:q?"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:O?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(di,{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"}),!ce&&e.jsxs("button",{type:"button",onClick:()=>ae(!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(ys,{className:"h-2.5 w-2.5"}),"Manual"]})]}),ce?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Xe,{value:V,onChange:W=>X(W.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:()=>{ae(!1),X("")},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(ss,{className:"h-3.5 w-3.5"})})]}):C!=null&&C.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-md border border-border/40 bg-background/40",children:[C.branches.map(W=>{const ie=E===W.ref,oe=W.branch==="main"||W.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>J(W.ref),className:B("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",ie&&"bg-background/70"),title:W.ref,children:[e.jsx("span",{className:B("shrink-0 text-[10px]",oe?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:oe?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:W.ref}),ie?e.jsx(As,{className:"h-3 w-3 shrink-0 text-primary"}):null]},W.ref)}),C.hasMore&&e.jsxs("button",{type:"button",onClick:se,disabled:A,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:[A?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(Nt,{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."}),F&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:F})]})]})}const Ui=20,Vi=3,yt="meshy-working-dir-recents-by-node";function Hi(s){return s.startsWith("/")||s.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(s)}function Ki(s){const t=s.trim();return t||"."}function kt(s){const t=[],n=new Set;for(const o of s){const r=o.trim();if(!(!r||n.has(r))&&(n.add(r),t.push(r),t.length===Vi))break}return t}function qi(s,t){const n=t.trim();return kt(n?[n,...s]:s)}function mn(s){if(!s||typeof s!="object"||Array.isArray(s))return{};const t={};for(const[n,o]of Object.entries(s)){if(!n||!Array.isArray(o))continue;const r=o.filter(g=>typeof g=="string"),i=kt(r);i.length>0&&(t[n]=i)}return t}function Wi(s,t,n){if(!t)return s;const o=s[t]??[],r=qi(o,n);if(r.length===0){if(!(t in s))return s;const{[t]:i,...g}=s;return g}return{...s,[t]:r}}function Gi(s,t){var n;return t?((n=s[t])==null?void 0:n[0])??"":""}function xn(s){if(!s||typeof window>"u")return"";try{const t=window.localStorage.getItem(yt);return t?Gi(mn(JSON.parse(t)),s):""}catch{return""}}function Qi(s,t,n){return s!=="auto"?t.find(o=>o.id===s)??null:n.length===1?n[0]??null:null}function Yi(s,t){const n=t.trim();return n?Hi(n)||!s?n:`${s.replace(/[/\\]+$/,"")}/${n}`:""}function Xi(s,t){return s?s.isAbsolute?s.currentPath:s.currentPath==="."||s.currentPath===""?s.rootPath||(t==null?void 0:t.workDir)||"Node root":s.currentPath:(t==null?void 0:t.workDir)??"Node root"}function Hs({value:s,onChange:t,assignTo:n,nodes:o,assignableNodes:r,layout:i="default",chipClassName:g,chipActiveClassName:b,chipInactiveClassName:N,labelClassName:v,triggerClassName:f,popoverPlacement:l="bottom",popoverAlign:u="start"}){const[w,S]=a.useState(!1),[x,j]=a.useState(null),[c,p]=a.useState(!1),[k,A]=a.useState(!1),[L,O]=a.useState(null),[T,F]=a.useState(""),[U,M]=a.useState(!1),[P,E]=a.useState({}),J=a.useRef(null),V=a.useMemo(()=>Qi(n,o,r),[n,o,r]),X=V==null?void 0:V.id,ce=a.useMemo(()=>X?P[X]??[]:[],[P,X]),ae=a.useMemo(()=>s.trim()?Yi(V==null?void 0:V.workDir,s):"Use node default",[s,V==null?void 0:V.workDir]);a.useEffect(()=>{if(!(typeof window>"u"))try{const m=window.localStorage.getItem(yt);if(!m)return;const $=JSON.parse(m);E(mn($))}catch{}},[]);const ee=a.useCallback(m=>{X&&E($=>{const q=Wi($,X,m);if(q===$)return $;if(typeof window<"u")try{window.localStorage.setItem(yt,JSON.stringify(q))}catch{}return q})},[X]),Z=a.useCallback((m,$=!0)=>{const q=m.trim();t(q),$&&q&&ee(q),S(!1)},[t,ee]),H=a.useCallback(async(m,$=0,q=!1)=>{if(X){O(null),q?A(!0):p(!0);try{const ne=await cr(X,{path:m,limit:Ui,offset:$,directoriesOnly:!0,allowAbsolute:!0});j(W=>q&&W?{...ne,entries:[...W.entries,...ne.entries]}:ne)}catch(ne){O(ne instanceof Error?ne.message:"Failed to browse directories"),q||j(null)}finally{p(!1),A(!1)}}},[X]),K=a.useRef(s);K.current=s;const re=a.useRef(H);re.current=H,a.useEffect(()=>{if(!w)return;const m=K.current;F(m),M(!1),j(null),O(null),X&&re.current(Ki(m))},[w,X]),a.useEffect(()=>{if(!w)return;const m=q=>{J.current&&(J.current.contains(q.target)||S(!1))},$=q=>{q.key==="Escape"&&S(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",$),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",$)}},[w]);const xe=a.useCallback(m=>{H(m)},[H]),h=a.useCallback(()=>{x&&H(x.currentPath,x.entries.length,!0)},[x,H]),I=i==="composer"?e.jsxs(z,{type:"button",variant:"ghost",onClick:()=>S(m=>!m),title:ae,"aria-label":`Working directory: ${ae}`,className:B(g,f,"min-w-0 max-w-full",s.trim()?b:N),children:[e.jsx(ur,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:B("min-w-0 truncate",v),children:ae})]}):e.jsxs(z,{type:"button",variant:"outline",onClick:()=>S(m=>!m),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:ae,children:[e.jsx("span",{className:B("truncate",s.trim()?"font-mono text-foreground":"text-muted-foreground"),children:ae}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:V?V.name:"Manual"})]}),C=Xi(x,V),se=!!(x!=null&&x.parentPath);return e.jsxs("div",{className:B("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":l,"data-workdir-popover-align":u,ref:J,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Working directory"}),I]}):I,w&&e.jsxs("div",{className:B("absolute z-50 flex max-h-[min(28rem,calc(100vh-5rem))] w-[240px] flex-col overflow-hidden rounded-2xl border border-border/60 bg-background/95 shadow-lg backdrop-blur",l==="top"?"bottom-full mb-2":"top-full mt-2",i==="composer"?u==="end"?"right-0":"left-0":u==="end"?"right-0 w-auto min-w-[240px]":"left-0 right-0 w-auto min-w-[240px]"),children:[ce.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(Nt,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:ce.map(m=>e.jsx("button",{type:"button",onClick:()=>Z(m),className:"truncate rounded px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:m,children:m},m))})]}),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:()=>(x==null?void 0:x.parentPath)&&xe(x.parentPath),disabled:!se||c,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($o,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:C,children:C}),x&&e.jsx("button",{type:"button",onClick:()=>Z(x.isAbsolute?x.currentPath:x.currentPath==="."?"":x.currentPath),className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium text-foreground hover:bg-background/60",title:"Use this folder",children:"Use"})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[V?c?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(me,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):x&&x.entries.length>0?e.jsxs(e.Fragment,{children:[x.entries.map(m=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Z(m.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 ${m.path}`,children:[e.jsx(Oa,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:m.name})]}),e.jsx("button",{type:"button",onClick:()=>xe(m.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 ${m.name}`,children:e.jsx(Ms,{className:"h-3.5 w-3.5"})})]},m.path)),x.hasMore&&e.jsxs("button",{type:"button",onClick:h,disabled:k,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[k?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(Nt,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:L??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),L&&x&&x.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:L})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:U?e.jsxs(e.Fragment,{children:[e.jsx(Xe,{value:T,onChange:m=>F(m.target.value),onKeyDown:m=>{m.key==="Enter"&&T.trim()?(m.preventDefault(),Z(T)):m.key==="Escape"&&(m.preventDefault(),M(!1),F(s))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>Z(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(As,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{M(!1),F(s)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(ss,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{F(s),M(!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(ys,{className:"h-3 w-3"})]})})]})]})}function hn(s,t={}){const n=s.filter(o=>o.status==="online");return t.currentNodeRole!=="follower"||!t.leaderNodeId?n:n.filter(o=>o.id!==t.leaderNodeId)}function Ut({isCurrent:s}){return s?e.jsx(Xo,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Wo,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function St(s,t){return s.map(n=>{const o=!!t&&n.id===t;return e.jsx(we,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Ut,{isCurrent:o}),e.jsx("span",{className:"truncate",children:n.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:o?"current":"remote"})]})},n.id)})}function Ji(s){var o;const t=s.sessionId.trim(),n=s.cwd.trim();return!t||!n||!s.assignTo?null:{title:s.title.trim()||((o=s.defaultTitle)==null?void 0:o.trim())||void 0,agent:s.agent,sessionId:t,cwd:n,assignTo:s.assignTo,priority:s.priority,mode:s.mode??Ls}}function Zi(){return hr.map(s=>e.jsx(we,{value:s.value,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:s.label}),s.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:s.description})]})},s.value))}function el(s){if(!s)return"unknown time";const t=Date.parse(s);return Number.isNaN(t)?s:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(t)}function ja(s){if(!s.updatedAt)return 0;const t=Date.parse(s.updatedAt);return Number.isNaN(t)?0:t}function sl(s,t){return ja(t)-ja(s)||s.sessionId.localeCompare(t.sessionId)}function tl(s){const t=s.trim().replace(/[\\/]+$/,"");return t?t.split(/[\\/]+/).filter(Boolean).at(-1)??t:"Unknown project"}function al(s){const t=new Map;for(const n of[...s].sort(sl)){const o=t.get(n.cwd);if(o){o.push(n);continue}t.set(n.cwd,[n])}return Array.from(t.entries()).map(([n,o])=>({folderName:tl(n),cwd:n,sessions:o}))}function nl(s,t){const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n}function rl({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,className:g,footerClassName:b,submitLabel:N="Load session",cancelLabel:v="Cancel",autoFocus:f=!1}){const l=a.useMemo(()=>hn(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),u=a.useMemo(()=>{var D;return n&&l.some(Q=>Q.id===n)?n:((D=l[0])==null?void 0:D.id)??""},[l,n]),[w,S]=a.useState(""),[x,j]=a.useState("codex"),[c,p]=a.useState(""),[k,A]=a.useState(""),[L,O]=a.useState(""),[T,F]=a.useState(u),[U,M]=a.useState("normal"),[P,E]=a.useState(Ls),[J,V]=a.useState(!1),[X,ce]=a.useState([]),[ae,ee]=a.useState(!1),[Z,H]=a.useState(null),K=a.useMemo(()=>X.find(D=>D.sessionId===c)??null,[X,c]);a.useEffect(()=>{T&&l.some(D=>D.id===T)||F(u)},[T,l,u]),a.useEffect(()=>{p(""),A(""),O("")},[x,T]),a.useEffect(()=>{let D=!1;return T?(ee(!0),H(null),mr(T,{agent:x,limit:50}).then(Q=>{D||ce(Q.sessions)}).catch(Q=>{D||(ce([]),H(Q instanceof Error?Q.message:"Failed to load native sessions"))}).finally(()=>{D||ee(!1)}),()=>{D=!0}):(ce([]),H(null),ee(!1),()=>{D=!0})},[x,T]),a.useEffect(()=>{K&&(A(K.sessionId),O(K.cwd))},[K]);const re=a.useCallback(async D=>{D.preventDefault();const Q=Ji({title:w,defaultTitle:K==null?void 0:K.summary,agent:x,sessionId:k,cwd:L,assignTo:T,priority:U,mode:P});if(Q){V(!0);try{const ge=await xr(Q);r(ge)}catch(ge){te.error(ge instanceof Error?ge.message:"Failed to load native session")}finally{V(!1)}}},[w,K,x,k,L,T,U,P,r]),xe=!!(k.trim()&&L.trim()&&T),[h,I]=a.useState(!1),[C,se]=a.useState(""),[m,$]=a.useState(()=>new Set),q=l.find(D=>D.id===T)??null,ne=!!(n&&(q==null?void 0:q.id)===n),W=a.useMemo(()=>{const D=C.trim().toLowerCase();return D?X.filter(Q=>Q.summary.toLowerCase().includes(D)||Q.sessionId.toLowerCase().includes(D)||Q.cwd.toLowerCase().includes(D)):X},[X,C]),ie=a.useMemo(()=>al(W),[W]),oe=a.useCallback(D=>{$(Q=>nl(Q,D))},[]),Te="h-9 w-auto gap-1.5 rounded-sm border-border/60 bg-background/60 px-3 text-xs shadow-none transition-colors hover:bg-background/80";return e.jsxs("form",{onSubmit:re,className:B("space-y-4",g),children:[e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/54 shadow-[0_24px_86px_-48px_rgba(15,23,42,0.55)] backdrop-blur-xl dark:shadow-[0_24px_86px_-48px_rgba(0,0,0,0.9)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/50 px-4 py-3",children:[e.jsxs(_e,{value:T,onValueChange:F,children:[e.jsx(Ee,{className:B(Te),"aria-label":"Node",children:q?e.jsxs(e.Fragment,{children:[e.jsx(Ut,{isCurrent:ne}),e.jsx("span",{className:"max-w-[10rem] truncate",children:q.name})]}):e.jsx(Ie,{placeholder:"Node"})}),e.jsx(De,{children:St(l,n)})]}),e.jsxs(_e,{value:x,onValueChange:D=>j(D),children:[e.jsxs(Ee,{className:B(Te),"aria-label":"Agent",children:[e.jsx(Bt,{agent:x}),e.jsx("span",{children:x})]}),e.jsx(De,{children:yo()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(ot,{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(Xe,{value:C,onChange:D=>se(D.target.value),placeholder:"Filter sessions",className:"h-9 rounded-sm border-border/60 bg-background/60 pl-9 text-xs shadow-none"})]})]}),e.jsxs("div",{className:"px-3 py-3",children:[e.jsx("div",{className:"flex items-center justify-between px-1 pb-2",children:e.jsx(Re,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:ae?"Loading...":`${W.length} session${W.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-lg",children:[ae&&e.jsx("div",{className:"absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden bg-primary/10",children:e.jsx("div",{className:"h-full w-1/3 animate-indeterminate-bar bg-primary/70"})}),e.jsxs("div",{className:"h-full space-y-1.5 overflow-y-auto pr-1",children:[!T&&e.jsx("div",{className:"rounded-lg border border-dashed border-border/60 bg-background/35 px-4 py-6 text-center text-xs text-muted-foreground",children:"Pick a node to load its recent sessions."}),T&&!ae&&W.length===0&&e.jsx("div",{className:"rounded-lg border border-dashed border-border/60 bg-background/35 px-4 py-6 text-center text-xs text-muted-foreground",children:X.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),ie.map(D=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>oe(D.cwd),"aria-expanded":!m.has(D.cwd),className:"sticky top-0 z-[1] flex w-full items-center gap-2 border-b border-border/50 bg-background/95 px-1 py-1.5 text-left text-[10px] text-muted-foreground backdrop-blur transition-colors hover:bg-background",children:[e.jsx(ts,{className:B("h-3.5 w-3.5 shrink-0 transition-transform",m.has(D.cwd)&&"-rotate-90")}),e.jsx($t,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:D.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[D.sessions.length," session",D.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:D.cwd})]}),!m.has(D.cwd)&&D.sessions.map(Q=>{const ge=Q.sessionId===c;return e.jsxs("button",{type:"button",onClick:()=>p(Q.sessionId),className:B("flex w-full flex-col gap-1 rounded-lg border px-3 py-2.5 text-left transition-all duration-200 hover:-translate-y-px",ge?"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:B("h-2 w-2 shrink-0 rounded-full",ge?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:Q.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:el(Q.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:Q.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:Q.cwd})]})]},Q.sessionId)})]},D.cwd))]})]}),Z&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:Z})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:()=>I(D=>!D),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":h,children:[e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0}),e.jsx("span",{className:"shrink-0",children:h?"Less options":"More options"}),e.jsx(ts,{className:B("h-3.5 w-3.5 shrink-0 transition-transform",h&&"rotate-180")}),e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0})]}),h&&e.jsxs("div",{className:"space-y-4 rounded-xl border border-border/60 bg-background/35 p-4",children:[e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Re,{htmlFor:"native-session-id",className:"text-xs font-medium text-muted-foreground",children:"Session ID"}),e.jsx(Xe,{id:"native-session-id",type:"text",value:k,onChange:D=>{p(""),A(D.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:f,className:"h-10 rounded-sm border-border/70 bg-background/70 font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Re,{htmlFor:"native-session-title",className:"text-xs font-medium text-muted-foreground",children:"Task title"}),e.jsx(Xe,{id:"native-session-title",type:"text",value:w,onChange:D=>S(D.target.value),placeholder:"Optional",className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm"})]})]}),e.jsx(Hs,{value:L,onChange:D=>{p(""),O(D)},assignTo:T,nodes:s,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(Re,{className:"text-xs font-medium text-muted-foreground",children:"Mode"}),e.jsxs(_e,{value:P,onValueChange:D=>E(D),children:[e.jsx(Ee,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Ie,{placeholder:"Select mode"})}),e.jsx(De,{children:Zi()})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Re,{className:"text-xs font-medium text-muted-foreground",children:"Priority"}),e.jsxs(_e,{value:U,onValueChange:M,children:[e.jsx(Ee,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Ie,{placeholder:"Select priority"})}),e.jsxs(De,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]})]})]})]})]}),e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",b),children:[i&&e.jsx(z,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:v}),e.jsx(z,{type:"submit",disabled:!xe||J,className:"rounded-sm px-5",children:J?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 animate-spin"})," Loading..."]}):N})]})]})}function fn(s,t,n=!1){const o=s.trim();if(o)return o;const r=t.trim().split(`
134
+ `).map(i=>i.trim()).find(Boolean);return r?r.length>72?`${r.slice(0,69).trimEnd()}...`:r:n?"Image task":""}function ol(s){var g;const t=s.title.trim(),n=fn(s.title,s.description,s.images.length>0),o=s.description.trim()||n,r=s.mode??Ls,i=Xa(s.description,s.images);return!n||!o||!s.agent?null:{title:n,description:o,agent:s.agent,project:s.project.trim()||null,branch:((g=s.branch)==null?void 0:g.trim())||null,payload:{initialMessage:i,mode:r,titleSource:t?"manual":"derived"},priority:s.priority,assignTo:s.assignTo==="auto"?void 0:s.assignTo}}function il({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,className:g,footerClassName:b,submitLabel:N="Create chat",cancelLabel:v="Cancel",autoFocus:f=!1,layout:l="default"}){const[u,w]=a.useState(""),[S,x]=a.useState(""),[j,c]=a.useState(ta),[p,k]=a.useState(Ls),[A,L]=a.useState(""),[O,T]=a.useState(""),[F,U]=a.useState("normal"),M=a.useMemo(()=>hn(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),P=a.useMemo(()=>{var Y;return n&&M.some(be=>be.id===n)?n:((Y=M[0])==null?void 0:Y.id)??""},[M,n]),[E,J]=a.useState(P),[V,X]=a.useState(!1),[ce,ae]=a.useState(!1),{images:ee,error:Z,fileInputRef:H,pickImages:K,handleFileChange:re,handlePaste:xe,removeImage:h}=dn(),I=a.useMemo(()=>M.find(Y=>Y.id===E)??null,[E,M]),C=!!(n&&(I==null?void 0:I.id)===n),se=Za(j),m=ko(p);a.useEffect(()=>{E&&M.some(Y=>Y.id===E)||J(P)},[E,M,P]),a.useEffect(()=>{L(xn(E)),T("")},[E]),a.useEffect(()=>{T("")},[A]);const $=a.useCallback(async Y=>{Y.preventDefault();const be=ol({title:u,description:S,agent:j,project:A,branch:O,priority:F,assignTo:E,mode:p,images:ee});if(be){X(!0);try{const ye=await pr(be);r(ye)}catch(ye){te.error(ye instanceof Error?ye.message:"Failed to create task")}finally{X(!1)}}},[u,S,j,A,O,F,E,p,ee,r]),q=fn(u,S,ee.length>0),ne=!!(q&&j&&E&&(S.trim()||ee.length>0)),W=a.useCallback(Y=>{var be;Y.nativeEvent.isComposing||Y.key==="Enter"&&(Y.ctrlKey||Y.metaKey)&&ne&&!V&&(Y.preventDefault(),(be=Y.currentTarget.form)==null||be.requestSubmit())},[ne,V]),ie=ee.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:ee.map((Y,be)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Ja(Y),alt:Y.filename??`attachment ${be+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>h(be),className:"absolute -top-2 -right-2 flex h-6 w-6 items-center justify-center rounded-sm border border-border/70 bg-background text-muted-foreground shadow-sm transition-all hover:-translate-y-px hover:text-foreground","aria-label":`Remove ${Y.filename??`image ${be+1}`}`,children:e.jsx(ss,{className:"h-3.5 w-3.5"})})]},`${Y.filename??"image"}-${be}`))}),oe=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Assign to"}),e.jsxs(_e,{value:E,onValueChange:J,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ie,{placeholder:"Select node"})}),e.jsx(De,{children:St(M,n)})]})]}),Te=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Agent"}),e.jsxs(_e,{value:j,onValueChange:c,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ie,{placeholder:"Select agent"})}),e.jsx(De,{children:ua()})]})]}),D=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Mode"}),e.jsxs(_e,{value:p,onValueChange:Y=>k(Y),children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ie,{placeholder:"Select mode"})}),e.jsx(De,{children:ma()})]})]}),Q=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{className:"text-sm font-medium",children:"Priority"}),e.jsxs(_e,{value:F,onValueChange:U,children:[e.jsx(Ee,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Ie,{placeholder:"Select priority"})}),e.jsxs(De,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]})]}),ge=e.jsx(Hs,{value:A,onChange:L,assignTo:E,nodes:s,assignableNodes:M}),He=e.jsx(va,{value:O,onChange:T,project:A,assignTo:E,nodes:s,assignableNodes:M});return l==="composer"?e.jsxs("form",{onSubmit:$,className:B("space-y-4",g),children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:re,className:"hidden"}),(()=>{const Y="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",be="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",ye="border-border/70 bg-background/55 text-foreground",Je=j===ta,Be=p===Ls;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/54 shadow-[0_24px_86px_-48px_rgba(15,23,42,0.55)] backdrop-blur-xl dark:shadow-[0_24px_86px_-48px_rgba(0,0,0,0.9)]",children:[e.jsxs("div",{className:"chat-composer__header flex min-w-0 items-center justify-between gap-3 px-4 pt-3",children:[e.jsxs(_e,{value:E,onValueChange:J,children:[e.jsx(Ee,{className:B(Y,ye,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${(I==null?void 0:I.name)??"unassigned"}`,"aria-label":`Assigned node: ${(I==null?void 0:I.name)??"unassigned"}`,children:I?e.jsxs(e.Fragment,{children:[e.jsx(Ut,{isCurrent:C}),e.jsx("span",{className:"min-w-0 truncate",children:I.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:C?"current":"remote"})]}):e.jsx(Ie,{placeholder:"Select node"})}),e.jsx(De,{children:St(M,n)})]}),ce?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Xe,{id:"task-title-composer",type:"text",value:u,onChange:je=>w(je.target.value),onKeyDown:je=>{(je.key==="Enter"||je.key==="Escape")&&(je.preventDefault(),ae(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>ae(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(As,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>ae(!0),className:"chat-composer__title-button flex min-w-0 items-center gap-1.5 rounded-sm px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-background/55 hover:text-foreground",title:q||"Title","aria-label":q?`Edit title: ${q}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:q||"Title"}),e.jsx(ys,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:S,onChange:je=>x(je.target.value),onKeyDown:W,onPaste:xe,placeholder:"Ask anything...",rows:4,autoFocus:f,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-xl bg-transparent px-5 pt-2 pb-2 text-xs leading-5 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsxs("div",{className:"chat-composer__rail flex flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:K,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(wt,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(_e,{value:j,onValueChange:c,children:[e.jsxs(Ee,{className:B(Y,"chat-composer__icon-trigger",Je?be:ye),title:`Agent: ${se}`,"aria-label":`Agent: ${se}`,children:[e.jsx(Bt,{agent:j}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:se})]}),e.jsx(De,{children:ua()})]}),e.jsxs(_e,{value:p,onValueChange:je=>k(je),children:[e.jsxs(Ee,{className:B(Y,"chat-composer__icon-trigger",Be?be:ye),title:`Mode: ${m}`,"aria-label":`Mode: ${m}`,children:[e.jsx(fi,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:m})]}),e.jsx(De,{children:ma()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(_e,{value:F,onValueChange:U,children:[e.jsx(Ee,{"aria-label":`Priority: ${F}`,title:`Priority: ${F}`,className:B("h-9 w-9 justify-center gap-0 rounded-sm p-0 text-xs shadow-none [&>svg:last-child]:hidden",F==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",F==="critical"&&"text-destructive",F==="high"&&"text-amber-600 dark:text-amber-400",F==="low"&&"text-muted-foreground"),children:e.jsx(zo,{className:B("h-4 w-4",F==="critical"&&"fill-destructive/20")})}),e.jsxs(De,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]}),i&&e.jsxs(z,{type:"button",variant:"ghost",size:"sm",onClick:i,"aria-label":v,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(ss,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:v})]}),e.jsxs(z,{type:"submit",size:"icon",disabled:!ne||V,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[V?e.jsx(me,{className:"h-4 w-4 animate-spin"}):e.jsx(nn,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:V?"Creating chat":N})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const je="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{value:A,onChange:L,assignTo:E,nodes:s,assignableNodes:M,layout:"composer",chipClassName:Y,chipActiveClassName:je,chipInactiveClassName:je,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(va,{value:O,onChange:T,project:A,assignTo:E,nodes:s,assignableNodes:M,layout:"composer",chipClassName:Y,chipActiveClassName:je,chipInactiveClassName:je,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(ie||Z)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 bg-background/45 p-4",children:[ie,Z&&e.jsx("div",{className:"text-xs text-destructive",children:Z}),!Z&&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:$,className:B("space-y-5",g),children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:re,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Re,{htmlFor:"task-description",className:"text-sm font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:S,onChange:Y=>x(Y.target.value),onKeyDown:W,onPaste:xe,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:f,className:"flex min-h-[144px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-xl border border-border/70 bg-background/70 px-4 py-3 text-sm leading-6 ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(z,{type:"button",variant:"outline",onClick:K,className:"rounded-sm",children:[e.jsx(wt,{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."})]}),ie,Z&&e.jsx("p",{className:"text-xs text-destructive",children:Z})]}),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(Re,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(Xe,{id:"task-title",type:"text",value:u,onChange:Y=>w(Y.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-11 rounded-lg border-border/70 bg-background/70"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:q?`Will appear as: ${q}`:"A title will be generated from the first line of the prompt."})]}),Te,D]}),ge,He,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[Q,oe]}),e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",b),children:[i&&e.jsx(z,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:v}),e.jsx(z,{type:"submit",disabled:!ne||V,className:"rounded-sm px-5",children:V?"Creating...":N})]})]})}function ll({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,defaultMode:g="chat",mode:b,onModeChange:N,layout:v="default",className:f,footerClassName:l,autoFocus:u=!1}){const[w,S]=a.useState(g),x=b!==void 0,j=x?b:w,c=p=>{x||S(p),N==null||N(p)};return e.jsxs("div",{className:B("space-y-4",f),children:[!x&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 bg-background/45 p-1",children:[e.jsxs(z,{type:"button",variant:j==="chat"?"default":"ghost",onClick:()=>c("chat"),className:"flex-1 rounded-sm",children:[e.jsx(fr,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(z,{type:"button",variant:j==="native"?"default":"ghost",onClick:()=>c("native"),className:"flex-1 rounded-sm",children:[e.jsx(Ot,{className:"h-4 w-4"}),"Load session"]})]}),j==="chat"?e.jsx(il,{nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,footerClassName:l,submitLabel:v==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:u,layout:v}):e.jsx(rl,{nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,footerClassName:l,autoFocus:u})]})}const vs="72f988bf-86f1-41af-91ab-2d7cd011db47",pn=`${vs} (MSIT)`;function dl({open:s,onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i=!1,shareResult:g}){return e.jsx(Tt,{open:s,onOpenChange:t,children:e.jsxs(At,{className:"max-w-md rounded-xl p-5",children:[e.jsx(Mt,{className:"sr-only",children:"Share conversation"}),e.jsx(cl,{onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i,shareResult:g})]})})}function cl({onOpenChange:s,onShare:t,onStopShare:n,sharing:o,stopping:r=!1,shareResult:i}){const[g,b]=a.useState((i==null?void 0:i.tenant)??vs),[N,v]=a.useState((i==null?void 0:i.scope)??"chat"),f=i!=null&&i.url?Fa(i.url):null,l=o||r;return a.useEffect(()=>{b((i==null?void 0:i.tenant)??vs),v((i==null?void 0:i.scope)??"chat")},[i==null?void 0:i.shareId,i==null?void 0:i.tenant,i==null?void 0:i.scope]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-base font-semibold leading-none tracking-tight",children:"Share conversation"}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:"Create a tenant-gated link for this task."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(ul,{value:g,onChange:b,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(Na,{active:N==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>v("chat")}),e.jsx(Na,{active:N==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>v("filesPreview")})]})]}),f&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Shared link"}),e.jsxs("div",{className:"flex items-center gap-2 rounded-sm border border-border/70 bg-muted/30 px-3 py-2",children:[e.jsx("input",{readOnly:!0,value:f,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void bs(f,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ia,{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(z,{variant:"outline",onClick:()=>s(!1),disabled:l,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(z,{variant:"outline",onClick:()=>void n(),disabled:l,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[r&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(z,{onClick:()=>void t({tenant:g,scope:N}),disabled:l,className:"h-8 text-xs",children:[o&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function ul({value:s,onChange:t,disabled:n}){const[o,r]=a.useState(!1),[i,g]=a.useState(!1),[b,N]=a.useState(s),v=a.useRef(null);a.useEffect(()=>{N(s)},[s]),a.useEffect(()=>{if(!o)return;const l=w=>{var x;const S=w.target;S instanceof Node&&((x=v.current)!=null&&x.contains(S)||(r(!1),g(!1)))},u=w=>{w.key==="Escape"&&(r(!1),g(!1))};return document.addEventListener("mousedown",l),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",u)}},[o]);const f=l=>{const u=l.trim();u&&(t(u),N(u),g(!1),r(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:v,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&r(l=>!l),disabled:n,className:"flex h-9 w-full items-center justify-between gap-2 rounded-sm border border-border/70 bg-background/70 px-3 text-left text-xs text-foreground shadow-sm outline-none transition-colors hover:bg-background disabled:opacity-50",children:[e.jsx("span",{className:"min-w-0 truncate font-mono",children:ml(s)}),e.jsx(ts,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),o&&e.jsxs("div",{className:"absolute left-0 right-0 z-50 mt-2 overflow-hidden rounded-lg border border-border/60 bg-background/95 text-xs shadow-lg backdrop-blur",children:[e.jsxs("button",{type:"button",onClick:()=>f(vs),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:pn}),s===vs&&e.jsx(As,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]}),e.jsx("div",{className:"border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:i?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:b,onChange:l=>N(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),f(b))},autoFocus:!0,placeholder:"Tenant ID",className:"h-7 min-w-0 flex-1 rounded-sm border border-border/60 bg-background/70 px-2 font-mono text-[11px] outline-none focus:ring-2 focus:ring-ring"}),e.jsx("button",{type:"button",onClick:()=>f(b),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(As,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{N(s),g(!1)},className:"flex h-7 w-7 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",children:e.jsx(ss,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>g(!0),className:"flex h-7 w-full items-center justify-between rounded-sm px-1.5 text-[11px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx("span",{children:"Manual tenant ID"}),e.jsx(ys,{className:"h-3 w-3"})]})})]})]})]})}function ml(s){return s===vs?pn:s}function Na({active:s,title:t,description:n,onClick:o}){return e.jsxs("button",{type:"button",onClick:o,className:s?"rounded-sm border border-primary/45 bg-primary/10 px-3 py-2 text-left shadow-sm":"rounded-sm border border-border/70 bg-background px-3 py-2 text-left shadow-sm hover:bg-muted/50",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:t}),e.jsx("div",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:n})]})}function xl(s){const t=s.map(n=>n.type==="text"?n.text:n.type==="image"?n.filename?`Image: ${n.filename}`:"Image attachment":n.isError?`Tool result error: ${n.content}`:`Tool result: ${n.content}`).join(" ").replace(/\s+/g," ").trim();return t?t.length>160?`${t.slice(0,157)}...`:t:"Queued follow-up"}function hl({messages:s,onCancelMessage:t}){return s.length===0?null:e.jsx("div",{className:"border-t border-border/55 bg-card/30 px-3 py-2 sm:px-5",children:e.jsxs("div",{className:"mx-auto max-w-[72rem] rounded-sm border border-border/65 bg-background/58 px-3 py-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-medium text-foreground",children:[e.jsx(ei,{className:"h-3.5 w-3.5 text-primary"}),"Queued messages",e.jsx("span",{className:"ml-auto rounded-sm border border-border/60 bg-muted/60 px-1.5 py-0 text-[10px] text-muted-foreground",children:s.length})]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:s.map((n,o)=>e.jsxs("div",{className:"flex min-w-0 items-start gap-2 text-[11px] leading-5 text-muted-foreground",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-[10px] font-medium text-primary",children:o+1}),e.jsx("span",{className:"min-w-0 flex-1 break-words [overflow-wrap:anywhere]",children:xl(n.content)}),t&&e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground hover:text-destructive",title:"Cancel queued message","aria-label":"Cancel queued message",onClick:()=>t(n.id),children:e.jsx(ss,{className:"h-3 w-3"})})]},n.id))})]})})}const fl=30;function pl({savedScrollTop:s,scrollHeight:t,clientHeight:n}){const o=Math.max(0,t-n);return Math.min(Math.max(0,s??o),o)}function tt(s){return s.scrollHeight-s.scrollTop-s.clientHeight<fl}function gl({activeTab:s,activeTaskId:t,contentVersion:n,setActiveTab:o,setInputCollapsed:r}){const i=a.useRef(null),g=a.useRef(t),b=a.useRef(!1),N=a.useRef(0),v=a.useRef(new Map),f=a.useRef(!0),l=a.useCallback((x=g.current)=>{const j=i.current;!j||!x||(v.current.set(x,j.scrollTop),N.current=j.scrollTop,f.current=tt(j))},[]),u=a.useCallback((x=g.current)=>{const j=i.current;!j||!x||(j.scrollTop=pl({savedScrollTop:v.current.get(x),scrollHeight:j.scrollHeight,clientHeight:j.clientHeight}),N.current=j.scrollTop,f.current=tt(j))},[]),w=a.useCallback(x=>{const j=x.currentTarget,c=N.current;if(l(),!b.current){if(tt(j)){r(!1),b.current=!0,setTimeout(()=>{b.current=!1},300);return}j.scrollTop<c&&c-j.scrollTop>10&&r(!0),j.scrollTop<=0&&r(!0)}},[l,r]),S=a.useCallback(x=>{s==="transcript"&&l(),o(x),x==="transcript"&&requestAnimationFrame(()=>u())},[s,u,l,o]);return a.useLayoutEffect(()=>{const x=g.current;x&&x!==t&&l(x),g.current=t,s==="transcript"&&requestAnimationFrame(()=>u(t))},[t,s,u,l]),a.useLayoutEffect(()=>{const x=i.current;!x||s!=="transcript"||!t||(f.current&&(x.scrollTop=x.scrollHeight),l(t))},[t,s,n,l]),{handleTranscriptScroll:w,handleTranscriptTabChange:S,transcriptScrollRef:i}}function gn(s=700){const[t,n]=a.useState(!1),o=a.useRef(null),r=a.useCallback(()=>{n(!0),o.current!==null&&clearTimeout(o.current),o.current=setTimeout(()=>{n(!1),o.current=null},s)},[s]);return a.useEffect(()=>()=>{o.current!==null&&clearTimeout(o.current)},[]),{markScrollbarActive:r,scrollbarActive:t}}const Vt="h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",js="h-3.5 w-3.5",bl=a.lazy(async()=>({default:(await Lt(()=>import("./FilesTab-Dav0BEeS.js"),__vite__mapDeps([0,1,2,3,4]))).FilesTab})),vl=a.lazy(async()=>({default:(await Lt(()=>import("./PreviewTab-C1dfVaAy.js"),__vite__mapDeps([5,1,2,6]))).PreviewTab})),jl=a.lazy(async()=>({default:(await Lt(()=>import("./DiffTab-C1B_4d-N.js"),__vite__mapDeps([7,1,2,3,4,6]))).DiffTab}));function Nl({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,activeTab:b,setActiveTab:N,creatingTask:v,createMode:f,activeTask:l,assignedNode:u,taskLoading:w,transcriptLoading:S,taskError:x,displayEvents:j,initialPromptAlreadyInLogs:c,initialPrompt:p,supportsFollowUp:k,taskUnavailable:A,chatDisabled:L,chatDisabledReason:O,questionBypassEnabled:T,isRunning:F,isStarting:U,hasPendingFollowUp:M,canCancel:P,canRetry:E,onRetry:J,onCancel:V,onReloadNativeTranscript:X,onShareTask:ce,onStopShareTask:ae,onStartCreateTask:ee,onCancelCreateTask:Z,onCreateTask:H,onSendMessage:K,onCancelQueuedMessage:re,onQuestionBypassChange:xe,onSubmitQuestionResponse:h}){const[I,C]=a.useState(!1),[se,m]=a.useState(!1),[$,q]=a.useState(!1),[ne,W]=a.useState(!1),[ie,oe]=a.useState(!1),[Te,D]=a.useState({}),[Q,ge]=a.useState(new Set),[He,Y]=a.useState(new Set),be=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",ye=l?(u==null?void 0:u.name)??it(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",Je=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:ye}),"..."]}):"Connecting session to an available node...",Be=l?[{label:"Working dir",value:be,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:ye}]:[],je=!!(p&&!c),Ye=je||j.length>0,ke=F&&Ye,Ae=(U||M||F)&&!ke,Ze=(l==null?void 0:l.conversationKind)==="nativeSession",ms=S?"Loading transcript":Ze?"No transcript imported":"Transcript is warming up",as=S?"Loading transcript...":Ze?"Meshy could not find imported history for this native session yet.":"The opening prompt has been stored, but the agent has not emitted conversation output yet.",os=(l==null?void 0:l.queuedMessages)??[],is=a.useMemo(()=>So(j),[j]),xs=a.useMemo(()=>Co("transcript",is.map(Le=>Le.event)),[is]),$e=l&&!Q.has(l.id)?Te[l.id]??l.activeShare??null:null,ls=(l==null?void 0:l.id)??null,Me=`${ls??"none"}:${j.length}:${os.length}:${je?1:0}:${S?1:0}`,{handleTranscriptScroll:hs,handleTranscriptTabChange:_,transcriptScrollRef:fe}=gl({activeTab:b,activeTaskId:ls,contentVersion:Me,setActiveTab:N,setInputCollapsed:C}),{markScrollbarActive:ue,scrollbarActive:ze}=gn(),We=a.useCallback(Le=>{ue(),hs(Le)},[hs,ue]);return v?e.jsx(wl,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,defaultMode:f,onCancel:Z,onCreated:H}):!l&&w?e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ct,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(me,{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(me,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(za,{value:b,onValueChange:_,className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(bn,{desktopTasksOpen:t,mobileTasksPanelOpen:n,onToggleTasks:s}),e.jsx("h2",{className:"min-w-0 truncate text-sm font-semibold tracking-tight text-foreground sm:text-lg",title:l.title,children:l.title}),e.jsx(Ua,{status:l.status,isNative:Ze}),l.priority!=="normal"&&e.jsx(br,{priority:l.priority}),e.jsx(z,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:B("ml-auto",Vt),children:o?e.jsx(It,{className:js}):e.jsx(an,{className:js})})]}),x&&e.jsx("div",{className:"mt-2 w-fit rounded-sm border border-destructive/25 bg-destructive/10 px-2 py-1 text-[11px] text-destructive",children:x}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsxs(Va,{className:"h-auto max-w-full overflow-x-auto rounded-sm bg-muted/70 p-0.5",children:[e.jsx(ds,{value:"transcript",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Transcript"}),e.jsx(ds,{value:"files",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Files"}),e.jsx(ds,{value:"preview",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Preview"}),e.jsx(ds,{value:"diff",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Diff"})]}),A&&e.jsx(Ke,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsxs("span",{className:"hidden sm:inline",children:["updated ",vr(l.updatedAt)]}),e.jsx("span",{className:"font-mono",children:l.id.slice(0,8)}),E&&e.jsxs(z,{variant:"outline",size:"sm",onClick:J,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(fa,{className:"h-3.5 w-3.5"}),"Retry"]}),Ze&&X&&e.jsx(z,{variant:"ghost",size:"icon",onClick:X,disabled:S,title:"Reload native session transcript","aria-label":"Reload native session transcript",className:"h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",children:e.jsx(fa,{className:B("h-3.5 w-3.5",S&&"animate-spin")})}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",disabled:A,title:A?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":A?"Unavailable tasks cannot be shared.":"Share conversation",className:"h-6 w-6 shrink-0 rounded-sm text-primary hover:bg-primary/10 hover:text-primary disabled:bg-transparent disabled:text-muted-foreground",onClick:()=>q(!0),children:e.jsx(xi,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(cs,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{ref:fe,className:B("scrollbar-line min-h-0 flex-1 touch-pan-y overflow-x-hidden overflow-y-auto overscroll-x-none bg-gradient-to-b from-background/15 via-transparent to-background/35 px-3 py-5 sm:px-5",ze&&"scrollbar-line-active"),onScroll:We,children:e.jsxs("div",{className:"mx-auto flex max-w-[72rem] flex-col gap-5",children:[je&&p&&e.jsx(xa,{event:p,agent:l.agent,questionBypassEnabled:T,onQuestionBypassChange:xe,onSubmitQuestionResponse:h,questionResponseDisabled:!k||L}),is.map(({event:Le,subItems:ve},Ne)=>e.jsx(xa,{event:Le,agent:l.agent,subItems:ve,questionBypassEnabled:T,onQuestionBypassChange:xe,onSubmitQuestionResponse:h,questionResponseDisabled:!k||L},xs[Ne])),!Ye&&!Ae&&e.jsxs("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-5 py-8 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:ms}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:as})]}),(!k&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!k&&l.result&&e.jsxs("div",{className:"rounded-xl border border-border/70 bg-card/80 px-3 py-3",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em] text-muted-foreground",children:"Stored result"}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5 text-muted-foreground",children:JSON.stringify(l.result,null,2)})]}),l.error&&!He.has(l.id)&&e.jsxs("div",{className:"rounded-xl border border-destructive/20 bg-destructive/10 px-3 py-3 text-destructive",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.22em]",children:"Stored error"}),e.jsx("button",{onClick:()=>Y(Le=>new Set(Le).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(ss,{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})]})]}),Ae&&e.jsx(wa,{children:Je}),ke&&e.jsx(wa,{children:"The agent is still working on this conversation."})]})}),k?e.jsxs(e.Fragment,{children:[I&&e.jsx(z,{size:"icon",onClick:()=>C(!1),className:"absolute bottom-4 right-4 z-10 h-12 w-12 rounded-lg shadow-lg",children:e.jsx(ys,{className:"h-4 w-4"})}),e.jsxs("div",{className:`shrink-0 ${I?"hidden":""}`,children:[e.jsx(hl,{messages:os,onCancelMessage:re}),e.jsx(Mi,{onSend:K,disabled:L,disabledReason:O,contextItems:Be,placeholder:L?O:F?"Queue a message for the next turn...":"Continue the conversation...",running:F||M,onStop:P?()=>m(!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(cs,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(et,{label:"Loading files..."}),children:e.jsx(bl,{taskId:l.id})})}),e.jsx(cs,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(et,{label:"Loading preview..."}),children:e.jsx(vl,{taskId:l.id})})}),e.jsx(cs,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(et,{label:"Loading diff..."}),children:e.jsx(jl,{taskId:l.id})})}),e.jsx(lt,{open:se,onOpenChange:m,children:e.jsxs(dt,{children:[e.jsxs(ct,{children:[e.jsx(ut,{children:"Stop this task?"}),e.jsx(mt,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(xt,{children:[e.jsx(ht,{children:"Keep running"}),e.jsx(ft,{onClick:V,children:"Stop task"})]})]})}),e.jsx(dl,{open:$,onOpenChange:q,sharing:ne,stopping:ie,shareResult:$e,onShare:async Le=>{if(!l)return null;W(!0);try{const ve=await ce(Le);return ve!=null&&ve.url&&(D(Ne=>({...Ne,[l.id]:ve})),ge(Ne=>{const es=new Set(Ne);return es.delete(l.id),es})),ve}finally{W(!1)}},onStopShare:async()=>{if(!l)return!1;oe(!0);try{const Le=await ae();return Le!==!1&&(D(ve=>{const Ne={...ve};return delete Ne[l.id],Ne}),ge(ve=>new Set(ve).add(l.id))),Le}finally{oe(!1)}}})]}):e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ct,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary shadow-sm",children:e.jsx(gr,{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(z,{onClick:ee,className:"mt-6 rounded-lg px-5",children:[e.jsx(Ft,{className:"h-4 w-4"}),"Start or load chat"]}),x&&e.jsx("div",{className:"mx-auto mt-4 max-w-lg rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:x})]})})]})}function wa({children:s}){return e.jsxs("div",{className:"agent-progress-banner flex items-center gap-1.5 rounded-lg bg-transparent px-1 py-1 text-[11px]",children:[e.jsx("span",{className:"agent-progress-terminal-spinner h-4 w-4 shrink-0","aria-hidden":"true"}),e.jsx("div",{className:"agent-progress-sweep-text min-w-0 leading-5",children:s})]})}function wl({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,defaultMode:b,onCancel:N,onCreated:v}){var w,S,x;const[f,l]=a.useState(b??"chat");a.useEffect(()=>{b&&l(b)},[b]);const u=e.jsx("div",{className:"flex items-center gap-1 rounded-lg border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-sm",children:[{value:"chat",label:"New chat",icon:Ft},{value:"native",label:"Load session",icon:Ot}].map(j=>{const c=j.icon,p=j.value===f;return e.jsxs("button",{type:"button",onClick:()=>l(j.value),"aria-pressed":p,className:B("flex items-center gap-1.5 rounded-sm px-2 py-1 transition-all duration-200",p?"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(c,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:j.label})]},j.value)})});return e.jsxs("div",{className:"dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"shrink-0 border-b border-border/55 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ct,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,centerSlot:u})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-6 py-10 sm:px-8",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(ll,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(w=i==null?void 0:i.self)==null?void 0:w.role,currentNodeId:((S=i==null?void 0:i.self)==null?void 0:S.id)??null,leaderNodeId:((x=i==null?void 0:i.leader)==null?void 0:x.id)??null,mode:f,onModeChange:l,onCreated:v,onCancel:N,autoFocus:!0,layout:"composer"})})})]})}function Ct({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,centerSlot:i}){return e.jsxs("div",{className:"relative flex w-full items-center justify-between gap-1.5",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:e.jsx(bn,{desktopTasksOpen:t,mobileTasksPanelOpen:n,onToggleTasks:s})}),i&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",children:e.jsx("div",{className:"pointer-events-auto",children:i})}),e.jsx(z,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:Vt,children:o?e.jsx(It,{className:js}):e.jsx(an,{className:js})})]})}function bn({desktopTasksOpen:s,mobileTasksPanelOpen:t,onToggleTasks:n}){var r,i;const o=(i=(r=globalThis.window)==null?void 0:r.matchMedia("(min-width: 1024px)"))!=null&&i.matches?s:t;return e.jsx(z,{variant:"ghost",size:"icon",onClick:n,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:Vt,children:o?e.jsx(tn,{className:js}):e.jsx(ni,{className:js})})}function yl({onAdded:s}){const[t,n]=a.useState(""),[o,r]=a.useState(!1),[i,g]=a.useState(null),b=a.useCallback(async N=>{if(N.preventDefault(),!!t.trim()){r(!0),g(null);try{await jr({leaderEndpoint:t.trim(),transport:"devtunnel"}),s()}catch(v){g(v instanceof Error?v.message:"Failed to join node")}finally{r(!1)}}},[t,s]);return e.jsx(At,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-xl border border-border/60 bg-background/95 p-0 shadow-[0_40px_120px_-60px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-6 py-5",children:e.jsxs(Ha,{className:"space-y-2 text-left",children:[e.jsx(Mt,{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:b,className:"space-y-4 px-6 py-5",children:[i&&e.jsx("div",{className:"rounded-lg border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(Re,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(Xe,{id:"leader-endpoint",type:"url",value:t,onChange:N=>n(N.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-11 rounded-lg border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-lg border border-border/60 bg-background/45 px-4 py-3 text-sm text-muted-foreground",children:"This does not switch the local node transport or auto-enable a local DevTunnel. Leaving later will detach this node from the remote leader and make it leader of its own cluster again."}),e.jsx(Ka,{className:"border-t border-border/60 pt-4",children:e.jsx(z,{type:"submit",disabled:!t.trim()||o,className:"rounded-sm",children:o?"Joining...":"Join node"})})]})]})})}function kl({open:s,onOpenChange:t,onAdded:n}){return e.jsx(Tt,{open:s,onOpenChange:t,children:e.jsx(yl,{onAdded:()=>{t(!1),n()}})})}function at({className:s,label:t,orientation:n,panel:o,panelResize:r}){return e.jsx("button",{type:"button","aria-label":t,"aria-orientation":n,"data-dashboard-resize-handle":o,onPointerDown:i=>r.onPointerDown(o,i),onWheel:i=>r.onWheel(o,i),className:B("group absolute z-20 hidden touch-none rounded-sm bg-transparent outline-none transition-colors hover:bg-primary/12 focus-visible:bg-primary/12 focus-visible:ring-2 focus-visible:ring-ring/70 lg:block",s),children:e.jsx("span",{className:"pointer-events-none absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"})})}function Sl({conversationPanel:s,desktopTasksOpen:t,mobileTaskSidebar:n,mobileTasksPanelOpen:o,mobileTasksPanelRef:r,operationsOpen:i,operationsPanelRef:g,operationsSidecar:b,panelResize:N,taskSidebar:v,terminalPanel:f,onCloseOperations:l,onCloseTaskList:u}){const w={"--dashboard-tasks-width":N.sizes.tasks,"--dashboard-operations-width":N.sizes.operations,"--dashboard-terminal-height":N.sizes.terminal};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",style:w,children:[e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsx("div",{className:B("relative hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",t?"lg:mr-2 lg:w-[var(--dashboard-tasks-width)]":"lg:w-0 lg:overflow-hidden"),children:t&&e.jsxs(e.Fragment,{children:[v,e.jsx(at,{panel:"tasks",orientation:"vertical",label:"Resize tasks panel",panelResize:N,className:"-right-1 top-0 h-full w-2 cursor-col-resize"})]})}),e.jsxs("section",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-2",children:[e.jsx("div",{className:"min-h-0 flex-1",children:s}),f&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(at,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:N,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),f]})]}),e.jsx("div",{className:B("relative hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",i?"xl:ml-2 xl:w-[var(--dashboard-operations-width)]":"xl:w-0 xl:overflow-hidden"),children:i&&e.jsxs(e.Fragment,{children:[e.jsx(at,{panel:"operations",orientation:"vertical",label:"Resize operations panel",panelResize:N,className:"-left-1 top-0 h-full w-2 cursor-col-resize"}),b]})})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:l,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:g,className:"fixed inset-y-0 right-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:b})]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:u,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:r,className:"fixed inset-y-0 left-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:n})]})]})}const Cl=10,us="__all__";function qe(s){return"session"in s}function ya(s,t){var n;return t&&s.some(o=>o.id===t)?t:((n=s[0])==null?void 0:n.id)??""}function nt(s){return s&&(xn(s.id)||s.workDir)||""}function Fs(s,t,n){let o=!1;const r=s.map(i=>qe(i)&&i.session.id===n.id?(o=!0,{...i,nodeName:t,session:n}):i);return _t(o?r:[...r,{id:`session-${n.id}`,nodeName:t,session:n}])}function vn(s,t){return s.filter(qe).filter(n=>n.session.nodeId===t).sort((n,o)=>o.session.startedAt-n.session.startedAt)}function _l(s){const t=s.filter(qe).sort((n,o)=>o.session.startedAt-n.session.startedAt);return{active:t.filter(n=>n.session.status==="running"),completed:t.filter(n=>n.session.status!=="running")}}function El(s,t){return!!(s&&t&&!s.contains(t))}function Dl(s,t,n){var r;if(n===us)return n;const o=vn(s,t);return o.some(i=>i.session.id===n)?n:((r=o[0])==null?void 0:r.session.id)??us}function Tl(s,t,n){return n===us?s.filter(o=>!qe(o)||o.session.nodeId===t):s.filter(o=>qe(o)&&o.session.nodeId===t&&o.session.id===n)}function _t(s){const t=s.map((o,r)=>({entry:o,index:r})).filter(({entry:o})=>qe(o)&&o.session.status!=="running").sort((o,r)=>!qe(o.entry)||!qe(r.entry)?0:r.entry.session.startedAt-o.entry.session.startedAt||r.index-o.index),n=new Set(t.slice(0,Cl).map(({entry:o})=>qe(o)?o.session.id:""));return s.filter(o=>!qe(o)||o.session.status==="running"||n.has(o.session.id))}function Et(s){return s.status==="running"?s.pid?`running pid ${s.pid}`:"running":s.status==="exited"?`exit ${s.exitCode??0}`:s.status==="stopped"?"stopped":s.signal?`failed ${s.signal}`:`exit ${s.exitCode??"failed"}`}function Al(s){const t=s.session.command.length>48?`${s.session.command.slice(0,45)}...`:s.session.command;return`${s.nodeName} - ${Et(s.session)} - ${t}`}function jn(s,t=48){return s.length>t?`${s.slice(0,t-3)}...`:s}function Ml(s,t){return t===us?"All sessions":s?jn(s.session.command,34):"Command session"}function ka(s){return s.status==="stopped"?"":s.stderr}function Ll({nodes:s,defaultNodeId:t,onClose:n,initialHistory:o=[]}){const[r,i]=a.useState(()=>ya(s,t)),g=a.useMemo(()=>s.find(h=>h.id===r)??s[0]??null,[s,r]),[b,N]=a.useState(()=>nt(g)),[v,f]=a.useState(""),[l,u]=a.useState(()=>_t(o)),[w,S]=a.useState(us),[x,j]=a.useState(!1),[c,p]=a.useState(!1),[k,A]=a.useState(!1),[L,O]=a.useState(!1),[T,F]=a.useState(!1),U=a.useRef(null),M=a.useRef(null),P=a.useMemo(()=>s.find(h=>h.id===r)??s[0]??null,[s,r]),E=a.useMemo(()=>vn(l,(P==null?void 0:P.id)??""),[l,P]),J=a.useMemo(()=>_l(E),[E]),V=a.useMemo(()=>E.find(h=>h.session.id===w),[w,E]),X=a.useMemo(()=>Tl(l,(P==null?void 0:P.id)??"",w),[l,P,w]),ce=a.useRef((P==null?void 0:P.id)??"");a.useEffect(()=>{r&&s.some(h=>h.id===r)||i(ya(s,t))},[t,s,r]),a.useEffect(()=>{const h=(P==null?void 0:P.id)??"";ce.current!==h&&(ce.current=h,N(nt(P)))},[P]),a.useEffect(()=>{S(h=>Dl(l,(P==null?void 0:P.id)??"",x?h:""))},[l,P,x]),a.useEffect(()=>{var h;(h=U.current)==null||h.scrollTo({top:U.current.scrollHeight})},[l]),a.useEffect(()=>{let h=!1;async function I(){const C=await Promise.allSettled(s.map(async se=>({node:se,response:await wr(se.id)})));h||u(se=>C.reduce((m,$)=>$.status!=="fulfilled"?m:$.value.response.sessions.reduce((q,ne)=>Fs(q,$.value.node.name,ne),m),se))}return s.length>0&&I(),()=>{h=!0}},[s]),a.useEffect(()=>{const h=l.filter(qe).filter(C=>C.session.status==="running");if(h.length===0)return;const I=window.setInterval(()=>{for(const C of h)Nr(C.session.nodeId,C.session.id).then(se=>u(m=>Fs(m,C.nodeName,se))).catch(()=>{})},1e3);return()=>window.clearInterval(I)},[l]);const ae=a.useRef(null);async function ee(h){if(h.preventDefault(),!P||!v.trim()||T)return;const I=v.trim(),C=P.name;F(!0),f("");try{const se=await kr(P.id,{command:I,...b.trim()?{cwd:b.trim()}:{}});u(m=>Fs(m,C,se)),S(se.id),j(!0)}catch(se){u(m=>[...m,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:C,command:I,error:se instanceof Error?se.message:"Command failed"}])}finally{F(!1)}}async function Z(h,I){h.stopPropagation();const C=await yr(I.session.nodeId,I.session.id);u(se=>Fs(se,I.nodeName,C))}function H(h){S(h),j(!0),p(!1)}function K(h){c&&El(M.current,h.target)&&p(!1)}function re(h,I,C,se,m){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:se,"aria-label":`Toggle ${h} sessions`,"aria-expanded":!C,className:"node-terminal__small flex w-full items-center justify-between gap-2 px-2 pb-1 pt-0.5 text-left font-medium uppercase tracking-normal text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{children:h}),e.jsx(ts,{className:B("h-3 w-3 transition-transform",C&&"-rotate-90")})]}),!C&&(I.length>0?I.map(xe):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:m}))]})}function xe(h){const I=w===h.session.id,C=h.session.status==="running";return e.jsxs("div",{className:B("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",I&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>H(h.session.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:B("flex h-4 w-4 shrink-0 items-center justify-center",C?"text-primary":h.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:C?e.jsx(me,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(na,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:jn(h.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[h.nodeName," · ",Et(h.session)]})]})]}),C&&e.jsx("button",{type:"button",onClick:se=>void Z(se,h),"aria-label":"Stop terminal session from selector",title:"Stop terminal session",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(pa,{className:"h-3 w-3"})})]},h.session.id)}return e.jsx("section",{className:"dashboard-panel node-terminal animate-composer-settle flex h-full min-h-0 shrink-0 overflow-visible rounded-xl","aria-label":"Node terminal",onClick:K,children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-visible rounded-[inherit] bg-card/72 text-card-foreground",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"node-terminal__header flex min-w-0 items-center gap-2 font-medium",children:[n?e.jsx("button",{type:"button",onClick:n,"aria-label":"Close terminal",title:"Close terminal",className:"flex h-6 w-6 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(ss,{className:"h-3.5 w-3.5"})}):e.jsx(aa,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{children:"Terminal"})]}),e.jsxs("div",{className:"ml-auto flex min-w-0 flex-wrap items-center justify-end gap-2",children:[e.jsxs("div",{ref:M,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":c,title:V?Al(V):"All sessions",onClick:()=>p(h=>!h),className:"node-terminal__control flex h-7 max-w-[14rem] list-none items-center gap-1.5 rounded-sm border border-border/70 bg-background/70 px-2 text-foreground outline-none transition-colors hover:bg-muted/65 focus-visible:ring-2 focus-visible:ring-ring/70 [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{className:"min-w-0 truncate",children:Ml(V,w)}),e.jsx(ts,{className:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!c,className:B("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!c&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>H(us),className:B("node-terminal__control flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",w===us&&"bg-primary/10 text-primary"),children:[e.jsx(aa,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),re("Active",J.active,k,()=>A(h=>!h),"No active sessions"),re("Completed",J.completed,L,()=>O(h=>!h),"No completed sessions")]})})]}),e.jsx("select",{value:(P==null?void 0:P.id)??"",onChange:h=>{i(h.target.value),j(!1),N(nt(s.find(I=>I.id===h.target.value)??null))},disabled:T||s.length===0,"aria-label":"Terminal node",className:"node-terminal__control h-7 max-w-[11rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground outline-none transition-colors hover:bg-muted/65 disabled:opacity-50",children:s.map(h=>e.jsx("option",{value:h.id,className:"bg-background text-foreground",children:h.name},h.id))}),e.jsx(Hs,{value:b,onChange:N,assignTo:(P==null?void 0:P.id)??"",nodes:s,assignableNodes:s,layout:"composer",chipClassName:"node-terminal__control h-7 max-w-[18rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground hover:bg-muted/65",chipActiveClassName:"font-mono",chipInactiveClassName:"text-muted-foreground",labelClassName:"node-terminal__workdir",triggerClassName:"terminal-workdir-trigger",popoverPlacement:"top",popoverAlign:"end"})]})]}),e.jsxs("div",{ref:U,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>{var h;return(h=ae.current)==null?void 0:h.focus()},children:[X.length===0?e.jsx("div",{className:"text-muted-foreground mb-2",children:"Commands run on the selected node and stay visible while running or after exit."}):e.jsx("div",{className:"space-y-3 mb-2",children:X.map(h=>qe(h)?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"text-primary",children:[h.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:h.session.command}),e.jsxs("span",{className:B("inline-flex items-center gap-1",h.session.status==="running"||h.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[h.session.status==="running"?e.jsx(me,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(na,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"}),Et(h.session)]}),h.session.status==="running"&&e.jsx("button",{type:"button",onClick:I=>void Z(I,h),"aria-label":"Stop terminal session",title:"Stop terminal session",className:"inline-flex h-5 w-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/65 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(pa,{className:"h-3 w-3"})})]}),h.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:h.session.stdout}),ka(h.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:ka(h.session)}),(h.session.stdoutTruncated||h.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},h.id):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{className:"text-primary",children:[h.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:h.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(Us,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:h.error})]},h.id))}),e.jsxs("form",{onSubmit:ee,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:P?`${P.name}$`:"$"}),e.jsx("input",{ref:ae,value:v,onChange:h=>f(h.target.value),disabled:!P||T,placeholder:P?"":"No online nodes available",className:"node-terminal__input flex-1 min-w-0 bg-transparent border-none outline-none text-foreground placeholder:text-muted-foreground font-mono caret-primary disabled:opacity-50",autoComplete:"off",spellCheck:!1}),e.jsx("button",{type:"submit","aria-label":"Run",title:"Run",disabled:!P||!v.trim()||T,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:text-muted-foreground disabled:opacity-50",children:T?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(Rt,{className:"h-3 w-3"})})]})]})]})})}function Ht({nodeId:s,nodeName:t,onOpenSettings:n,onOpenDevBox:o,onStartDevBox:r,showConfigureDevBox:i,showStartDevBox:g,startDevBoxPending:b,className:N}){const[v,f]=a.useState(!1),l=a.useRef(null),u=b?"Starting":"Start DevBox";return a.useEffect(()=>{if(!v)return;const w=x=>{var c;const j=x.target;j instanceof Node&&((c=l.current)!=null&&c.contains(j)||f(!1))},S=x=>{x.key==="Escape"&&f(!1)};return document.addEventListener("mousedown",w),document.addEventListener("keydown",S),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",S)}},[v]),e.jsxs("div",{ref:l,className:B("relative shrink-0",N),onClick:w=>w.stopPropagation(),children:[e.jsx(z,{type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${t}`,"aria-haspopup":"menu","aria-expanded":v,title:`More actions for ${t}`,onClick:()=>f(w=>!w),className:B("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",v&&"bg-background/80 text-primary"),children:e.jsx(Fo,{className:"h-3.5 w-3.5"})}),v&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-full z-30 mt-1 min-w-40 overflow-hidden whitespace-nowrap rounded-sm border border-border/65 bg-popover/96 p-1 normal-case tracking-normal shadow-[0_18px_48px_-28px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:[e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${t} settings`,title:`Open ${t} settings`,onClick:()=>{f(!1),n(s)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Sr,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Settings"})]}),g&&r&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${u} for ${t}`,title:`${u} for ${t}`,onClick:()=>{b||(f(!1),r(s))},disabled:b,className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80 disabled:cursor-not-allowed disabled:opacity-60",children:[b?e.jsx(me,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(Rt,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:u})]}),i&&o&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${t}`,title:`Configure DevBox for ${t}`,onClick:()=>{f(!1),o(s)},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-1.5 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Cr,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Configure DevBox"})]})]})]})}const Pl=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),Bl=new Set(["startinprogress","starting"]);function Ns(s){return!!(s!=null&&s.enabled&&s.name)}function Rl(s){const t=s==null?void 0:s.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(t&&Pl.has(t))}function ws(s){const t=s==null?void 0:s.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(t&&Bl.has(t))}function Ks(s,t,n){return s==="offline"&&Rl(t)&&Ns(n)}function Sa(s,t){return s==="offline"&&Ns(t)}function Ca(s){return!Ns(s)}function $l({nodeStatus:s,status:t,current:n,selected:o}){const r=o??n;return r&&Ks(s,t,r)?r:null}function Pe(s){return s.scope||`name:${s.name??""}`}function Ol({previousKey:s,baseDevBox:t,listed:n}){if(s&&n.some(i=>Pe(i)===s))return s;if(!Ns(t))return n[0]?Pe(n[0]):"";const o=Pe(t),r=n.find(i=>Pe(i)===o)??n.find(i=>i.name===t.name);return r?Pe(r):o}function Fl({cluster:s,systemInfo:t,nodeNameById:n,nodeBlockingTaskCounts:o,eventTypeFilter:r,onEventTypeFilterChange:i,eventTypeOptions:g,filteredEvents:b,sseConnected:N,clusterLoading:v,clusterError:f,promotePending:l,onPromote:u,onAddNode:w,leavePending:S,onLeaveCluster:x,onToggleNodeDevTunnel:j,devTunnelNodeId:c,devBoxStartNodeId:p,devBoxStartingNodeIds:k=new Set,onOpenNodeSettings:A,onOpenDevBox:L,onStartDevBox:O,onClose:T}){var ae,ee,Z;const F=((ae=s==null?void 0:s.self)==null?void 0:ae.role)==="leader",U=((ee=s==null?void 0:s.self)==null?void 0:ee.role)==="follower"&&!(s!=null&&s.leader),M=(s==null?void 0:s.self)??null,E=_r((s==null?void 0:s.nodes)??[],M==null?void 0:M.id).filter(H=>H.id!==(M==null?void 0:M.id)),J=s!=null&&s.leader?s.nodes.find(H=>{var K;return H.id===((K=s.leader)==null?void 0:K.id)})??null:null,V=s!=null&&s.leader?s.leader.dashboardOrigin??(J==null?void 0:J.dashboardOrigin)??(t&&s.leader.id===(t.nodeId??t.id)?t.dashboardOrigin:void 0)??s.leader.endpoint:null,X=(M==null?void 0:M.role)==="leader"&&E.length===0,ce=(M==null?void 0:M.role)==="follower";return e.jsx("aside",{className:"dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl !border-0",children:e.jsxs(za,{defaultValue:"overview",className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"shrink-0 bg-card/24 px-2.5 py-2.5 shadow-[0_1px_0_hsl(var(--border)/0.22)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold tracking-tight",children:"Operations"}),e.jsx("p",{className:"mt-px text-[9px] text-muted-foreground",children:"Node, cluster, and live events."})]}),e.jsx(z,{variant:"ghost",size:"icon",onClick:T,className:"h-6 w-6 rounded-sm",children:e.jsx(It,{className:"h-3.5 w-3.5"})})]}),e.jsxs(Va,{className:"mt-1.5 grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(ds,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(ds,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(ds,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})]}),e.jsx(cs,{value:"overview",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-2 py-2",children:e.jsxs("div",{className:"space-y-2.5",children:[M&&e.jsx(_a,{node:M,systemInfo:t,blockingTaskCount:o.get(M.id)??0,devTunnelNodeId:c,onToggleNodeDevTunnel:j,showActions:!1,defaultExpanded:!1,onOpenDevBox:L,devBoxStartingNodeIds:k}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"Cluster snapshot"}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 shadow-sm",children:N?"Connected":"Reconnecting"})]}),v&&!s?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(me,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):f&&!s?e.jsx("div",{className:"rounded-sm bg-destructive/10 px-2 py-1.5 text-[10px] text-destructive shadow-sm",children:f}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(gs,{label:"Term",value:String((s==null?void 0:s.term)??0)}),e.jsx(gs,{label:"Nodes",value:String((s==null?void 0:s.nodes.length)??0)}),e.jsx(gs,{label:"Pending",value:String((s==null?void 0:s.taskSummary.pending)??0)}),e.jsx(gs,{label:"Running",value:String((s==null?void 0:s.taskSummary.running)??0)}),e.jsx(gs,{label:"Completed",value:String((s==null?void 0:s.taskSummary.completed)??0)}),e.jsx(gs,{label:"Failed",value:String((s==null?void 0:s.taskSummary.failed)??0)})]}),e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/56 px-2 py-2 shadow-sm",children:[e.jsx(Qe,{label:"Leader",value:((Z=s==null?void 0:s.leader)==null?void 0:Z.name)??"None"}),e.jsx(Qe,{label:"Leader URL",value:V??"Unavailable",mono:!0,action:V?e.jsx(Ps,{label:"Copy leader URL",onClick:()=>void bs(V,"Leader URL copied")}):void 0}),e.jsx(Qe,{label:"Feed",value:N?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:U&&e.jsxs(z,{variant:"outline",size:"sm",onClick:u,disabled:l,className:"h-6 rounded-sm px-2 text-[10px]",children:[l&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(cs,{value:"nodes",className:"mt-0 min-h-0 flex-1",children:e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-y-auto px-2 py-2",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:"This node"}),X?e.jsx(z,{variant:"outline",size:"sm",onClick:w,className:"h-6 rounded-sm px-2 text-[10px]",children:"Join node"}):ce?e.jsxs(z,{variant:"outline",size:"sm",onClick:x,disabled:S,className:"h-6 rounded-sm px-2 text-[10px]",children:[S&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),M&&e.jsx(_a,{node:M,systemInfo:t,blockingTaskCount:o.get(M.id)??0,devTunnelNodeId:c,onToggleNodeDevTunnel:j,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:F?A:void 0,onOpenDevBox:F?L:void 0,onStartDevBox:F?O:void 0,devBoxStartNodeId:p,devBoxStartingNodeIds:k})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",E.length,")"]}),E.length>0?e.jsx("div",{className:"space-y-1.5",children:E.map(H=>e.jsx(Il,{node:H,isLeader:!!F,blockingTaskCount:o.get(H.id)??0,devTunnelNodeId:c,onToggleNodeDevTunnel:j,onOpenNodeSettings:F?A:void 0,onOpenDevBox:F?L:void 0,onStartDevBox:F?O:void 0,devBoxStartNodeId:p,devBoxStartingNodeIds:k},H.id))}):e.jsx("div",{className:"rounded-sm bg-background/45 px-2 py-2 text-[10px] text-muted-foreground shadow-sm",children:"No peer nodes are connected yet."})]})]})})}),e.jsx(cs,{value:"events",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col px-2 py-2",children:[e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-foreground",children:[e.jsx(Er,{className:B("h-3.5 w-3.5",N?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(_e,{value:r,onValueChange:i,children:[e.jsx(Ee,{className:"h-6 min-w-[10rem] flex-1 rounded-sm border-border/70 bg-background/60 text-[10px] sm:max-w-[14rem] [&>svg]:h-3 [&>svg]:w-3",children:e.jsx(Ie,{placeholder:"Event type"})}),e.jsx(De,{children:g.map(H=>e.jsx(we,{value:H,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:H==="all"?"All event types":H},H))})]}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 shadow-sm",children:N?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Dr,{events:b,maxHeight:"100%",emptyTitle:r==="all"?"No live events yet":"No matching events",emptyDescription:r==="all"?"Cluster activity appears here as it happens.":`No "${r}" events are in the current stream.`,nodeNameById:n,density:"compact"})})]})})]})})}function _a({node:s,systemInfo:t,blockingTaskCount:n,devTunnelNodeId:o,onToggleNodeDevTunnel:r,showActions:i=!0,defaultExpanded:g=!1,onOpenNodeSettings:b,onOpenDevBox:N,onStartDevBox:v,devBoxStartNodeId:f,devBoxStartingNodeIds:l}){var O,T,F,U;const[u,w]=a.useState(g),S=(t==null?void 0:t.dashboardOrigin)??s.dashboardOrigin,x=s.devtunnelEndpoint??s.endpoint,j=S??s.endpoint,c=(t==null?void 0:t.workDir)??s.workDir,p=on(s,t==null?void 0:t.transportType),k=zt(s,t==null?void 0:t.transportType),A=k&&ks((t==null?void 0:t.transportType)??s.transportType)?!0:rn(s,t==null?void 0:t.transportType),L=n>0;return e.jsxs("section",{className:"rounded-lg bg-primary/7 shadow-[0_18px_56px_-42px_hsl(var(--primary)/0.85)]",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>w(M=>!M),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[u?e.jsx(ts,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Ms,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(qa,{status:s.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Current node"})]}),e.jsx("a",{href:j,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Wa,{className:"h-3 w-3"})}),b&&e.jsx(Ht,{nodeId:s.id,nodeName:s.name,onOpenSettings:b,onOpenDevBox:N,onStartDevBox:v,showConfigureDevBox:(O=s.devbox)==null?void 0:O.enabled,showStartDevBox:Ks(s.status,(T=s.devbox)==null?void 0:T.lastStatus,s.devbox)||ws((F=s.devbox)==null?void 0:F.lastStatus)||l.has(s.id),startDevBoxPending:f===s.id||ws((U=s.devbox)==null?void 0:U.lastStatus)||l.has(s.id)})]}),e.jsxs("button",{type:"button",onClick:()=>w(M=>!M),className:"mt-1 flex min-w-0 items-center gap-1 pl-5 text-left",children:[e.jsx("span",{className:"text-[10px] font-semibold tracking-tight text-foreground",children:s.name}),e.jsx(Ga,{role:s.role,size:"compact"}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-sm",children:s.status})]})]}),u&&e.jsxs("div",{className:"space-y-2 px-2.5 pb-2.5 pt-1.5 shadow-[inset_0_1px_0_hsl(var(--primary)/0.12)]",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/70 px-2 py-1.5 shadow-sm",children:[e.jsx(Qe,{label:"Node ID",value:s.id,mono:!0}),S&&e.jsx(Qe,{label:"Dashboard",value:S,mono:!0,action:e.jsx(Ps,{label:"Copy dashboard URL",onClick:()=>void bs(S,"Dashboard URL copied")})}),e.jsx(Qe,{label:"Node URL",value:x,mono:!0,action:e.jsx(Ps,{label:"Copy node URL",onClick:()=>void bs(x,"Node URL copied")})}),c&&e.jsx(Qe,{label:"Workspace",value:c,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(bt,{label:"Transport",value:p}),t&&e.jsx(bt,{label:"Uptime",value:Tr(t.uptime),mono:!0})]}),e.jsx(en,{capabilities:s.capabilities,action:i&&A?e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>r(s),disabled:o===s.id||L,className:"h-6 rounded-sm px-2 text-[10px]",title:L?"Finish assigned or running tasks before changing remote access":void 0,children:[o===s.id&&e.jsx(me,{className:"h-3 w-3 animate-spin"}),k?"Disable Remote Access":"Enable Remote Access"]}):void 0}),i&&A&&L&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Il({node:s,isLeader:t,blockingTaskCount:n,devTunnelNodeId:o,onToggleNodeDevTunnel:r,onOpenNodeSettings:i,onOpenDevBox:g,onStartDevBox:b,devBoxStartNodeId:N,devBoxStartingNodeIds:v}){var k,A,L,O;const[f,l]=a.useState(!1),u=s.dashboardOrigin,w=s.devtunnelEndpoint??s.endpoint,S=u??s.endpoint,x=on(s),j=zt(s),c=rn(s),p=n>0;return e.jsxs("div",{className:"rounded-sm bg-background/54 shadow-sm",children:[e.jsxs("div",{className:"w-full px-2.5 py-1.5 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>l(T=>!T),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[f?e.jsx(ts,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(Ms,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(qa,{status:s.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Peer node"})]}),e.jsx("a",{href:S,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(Wa,{className:"h-3 w-3"})}),t&&i&&e.jsx(Ht,{nodeId:s.id,nodeName:s.name,onOpenSettings:i,onOpenDevBox:g,onStartDevBox:b,showConfigureDevBox:(k=s.devbox)==null?void 0:k.enabled,showStartDevBox:Ks(s.status,(A=s.devbox)==null?void 0:A.lastStatus,s.devbox)||ws((L=s.devbox)==null?void 0:L.lastStatus)||v.has(s.id),startDevBoxPending:N===s.id||ws((O=s.devbox)==null?void 0:O.lastStatus)||v.has(s.id)})]}),e.jsxs("button",{type:"button",onClick:()=>l(T=>!T),className:"mt-1 flex min-w-0 items-center gap-1 pl-4 text-left",children:[e.jsx("span",{className:"text-[10px] font-semibold text-foreground",children:s.name}),e.jsx(Ga,{role:s.role,size:"compact"}),e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-background/60 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-sm",children:s.status})]})]}),f&&e.jsxs("div",{className:"space-y-2 px-2.5 pb-2.5 pt-1.5 shadow-[inset_0_1px_0_hsl(var(--border)/0.22)]",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Qe,{label:"Node ID",value:s.id,mono:!0}),u&&e.jsx(Qe,{label:"Dashboard",value:u,mono:!0,action:e.jsx(Ps,{label:"Copy dashboard URL",onClick:()=>void bs(u,"Dashboard URL copied")})}),e.jsx(Qe,{label:"Node URL",value:w,mono:!0,action:e.jsx(Ps,{label:"Copy node URL",onClick:()=>void bs(w,"Node URL copied")})}),s.workDir&&e.jsx(Qe,{label:"Workspace",value:s.workDir,mono:!0}),e.jsx(bt,{label:"Transport",value:x})]}),e.jsx(en,{capabilities:s.capabilities,action:t&&c?e.jsxs(z,{variant:"outline",size:"sm",onClick:()=>r(s),disabled:o===s.id||p,className:"h-6 rounded-sm px-2 text-[10px]",title:p?"Finish assigned or running tasks before changing remote access":void 0,children:[o===s.id&&e.jsx(me,{className:"h-3 w-3 animate-spin"}),j?"Disable Remote Access":"Enable Remote Access"]}):void 0}),t&&c&&p&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Ps({label:s,onClick:t}){return e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground",onClick:t,"aria-label":s,title:s,children:e.jsx(Ia,{className:"h-3 w-3"})})}function zl(s,t,n,o){var b,N;if(!s)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const r=((b=t==null?void 0:t.self)==null?void 0:b.role)==="follower",i=s.assignedTo?((N=t==null?void 0:t.self)==null?void 0:N.id)===s.assignedTo?t.self:t==null?void 0:t.nodes.find(v=>v.id===s.assignedTo):void 0;return s.assignedTo!==null&&(i?i.status==="offline":t?s.assignedNodeAvailable===!1||!t.nodes.some(v=>v.id===s.assignedTo):s.assignedNodeAvailable===!1)?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${s.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}:r?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Follower nodes are read-only. Use the leader dashboard to manage chat, or leave the cluster first."}:n?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Sending message..."}:o?{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Queue a message for the next turn..."}:Vs.has(s.status)||s.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:Vs.has(s.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const Nn="meshy-task-sidebar-tree-state";function Ea(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"):[]}function rt(){var s;try{return((s=globalThis.window)==null?void 0:s.localStorage)??globalThis.localStorage??null}catch{return null}}function Da(s){if(!s)return{collapsedNodes:[],collapsedDirs:[]};try{const t=s.getItem(Nn);if(!t)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(t);return{collapsedNodes:Ea(n.collapsedNodes),collapsedDirs:Ea(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Ul(s,t){if(s)try{s.setItem(Nn,JSON.stringify(t))}catch{}}function Ta(s,t){if(!s.has(t))return s;const n=new Set(s);return n.delete(t),n}function Vl(s,t){if(!t)return null;for(const n of s){const o=n.nodeId??"__unassigned__";for(const r of n.dirs)if(r.tasks.some(i=>i.id===t))return{nodeKey:o,dirKey:`${o}::${r.path}`}}return null}function Aa(s,t,n){return n?{collapsedNodes:Ta(s,n.nodeKey),collapsedDirs:Ta(t,n.dirKey)}:{collapsedNodes:s,collapsedDirs:t}}function Hl(s,t,n){const o=s.filter(b=>b.status==="completed"),r=new Set((t?o:[...o].sort((b,N)=>N.updatedAt-b.updatedAt).slice(0,Pt)).map(b=>b.id));n&&o.some(b=>b.id===n)&&r.add(n);const i=s.filter(b=>b.status!=="completed"||r.has(b.id)),g=o.length-r.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,g)}}const Is="h-6 rounded-sm border-border/70 bg-background/60 px-2 py-0 text-[10px] leading-none shadow-sm [&>svg]:h-3 [&>svg]:w-3",zs="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function Ma({toolbarTasks:s,activeTaskId:t,tasksLoading:n,tasksError:o,isLeader:r,scope:i,agentFilter:g,nodeFilter:b,taskKindFilter:N,agentOptions:v,nodeOptions:f,nodeNameById:l,nodeWorkDirById:u,nodeStatusById:w,completedGroupByKey:S,devBoxNodeIds:x=new Set,devBoxStartNodeIds:j=new Set,devBoxStartingNodeIds:c=new Set,leaderNodeId:p,searchQuery:k,selectedTaskIds:A,allVisibleTasksSelected:L,someVisibleTasksSelected:O,canBatchArchive:T,onSearchChange:F,onScopeChange:U,onAgentFilterChange:M,onNodeFilterChange:P,onTaskKindFilterChange:E,onToggleTaskSelected:J,onToggleAllVisibleTasks:V,onBatchArchive:X,onBatchDelete:ce,onCreateTask:ae,onOpenNodeSettings:ee,onOpenDevBox:Z,onStartDevBox:H,onLoadCompletedTasks:K,onSelectTask:re,onClose:xe}){const[h,I]=a.useState(!!k),[C,se]=a.useState(!1),[m,$]=a.useState(!1),q=a.useRef(null),ne=a.useRef(null),W=a.useRef(null),[ie,oe]=a.useState(()=>A.size>0),{markScrollbarActive:Te,scrollbarActive:D}=gn(),Q=A.size,ge=!!(r&&(ie||Q>0)),He=i!=="active"||b!=="all"||g!=="all"||N!=="all",Y=k.trim().length>0,[be,ye]=a.useState(()=>new Set(Da(rt()).collapsedNodes)),[Je,Be]=a.useState(()=>new Set(Da(rt()).collapsedDirs)),[je,Ye]=a.useState(new Set),ke=a.useMemo(()=>Ar(s,l,p,u),[s,l,p,u]),Ae=a.useMemo(()=>Vl(ke,t),[ke,t]),Ze=a.useRef(null),ms=ke.length===1,as=ke.length>0,os=ms&&(He||Y),is=!!(r&&(ke.length>0||Q>0)),xs=a.useCallback(_=>{ye(fe=>{const ue=new Set(fe);return ue.has(_)?ue.delete(_):ue.add(_),ue})},[]),$e=a.useCallback(_=>{Be(fe=>{const ue=new Set(fe);return ue.has(_)?ue.delete(_):ue.add(_),ue})},[]),ls=a.useCallback(_=>{Ye(fe=>{const ue=new Set(fe);return ue.add(_),ue})},[]);a.useEffect(()=>{Ul(rt(),{collapsedNodes:Array.from(be),collapsedDirs:Array.from(Je)})},[Je,be]),a.useEffect(()=>{if(!Ae||!t)return;const _=`${t}:${Ae.nodeKey}:${Ae.dirKey}`;Ze.current!==_&&(Ze.current=_,ye(fe=>Aa(fe,new Set,Ae).collapsedNodes),Be(fe=>Aa(new Set,fe,Ae).collapsedDirs))},[t,Ae]);const Me=a.useCallback(_=>{oe(!0),V(_)},[V]),hs=a.useCallback(()=>{V(!1),oe(!1)},[V]);return a.useEffect(()=>{r||oe(!1)},[r]),a.useEffect(()=>{k&&I(!0)},[k]),a.useEffect(()=>{var _;h&&((_=q.current)==null||_.focus())},[h]),a.useEffect(()=>{if(!h)return;const _=ue=>{var We;const ze=ue.target;ze instanceof Node&&((We=ne.current)!=null&&We.contains(ze)||I(!1))},fe=ue=>{ue.key==="Escape"&&I(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",fe),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",fe)}},[h]),a.useEffect(()=>{if(!m)return;const _=ue=>{var We;const ze=ue.target;ze instanceof Node&&((We=W.current)!=null&&We.contains(ze)||$(!1))},fe=ue=>{ue.key==="Escape"&&$(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",fe),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",fe)}},[m]),e.jsxs("aside",{className:"dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl !border-t-0",children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 bg-card/24 px-2.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-sm font-semibold tracking-tight text-foreground",children:"Tasks"}),e.jsx(z,{variant:"ghost",size:"icon",onClick:xe,className:"h-6 w-6 rounded-sm",children:e.jsx(tn,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{ref:ne,className:"mt-2 flex items-center gap-1.5",children:[e.jsxs("div",{ref:W,className:B("relative flex items-stretch transition-[flex] duration-200",h?"flex-[2]":"flex-1"),children:[e.jsxs(z,{onClick:()=>{$(!1),ae("chat")},className:"h-8 flex-1 justify-start rounded-l-sm rounded-r-none px-2.5 text-left text-[11px] shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(Ft,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsx(z,{onClick:()=>$(_=>!_),"aria-label":"More chat options","aria-haspopup":"menu","aria-expanded":m,className:"h-8 w-7 rounded-l-none rounded-r-sm border-l border-primary-foreground/20 px-0 shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:e.jsx(ts,{className:B("h-3 w-3 transition-transform",m&&"rotate-180")})}),m&&e.jsx("div",{role:"menu",className:"absolute left-0 right-0 top-full z-20 mt-2 overflow-hidden rounded-lg border border-border/60 bg-popover/96 p-1 shadow-[0_20px_60px_-30px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{$(!1),ae("native")},className:"flex w-full items-center gap-1.5 rounded-sm px-2 py-2 text-left text-[11px] font-medium text-foreground transition-colors hover:bg-muted/80",children:[e.jsx(Ot,{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"})]})})]}),h?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(ot,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(Xe,{ref:q,value:k,onChange:_=>F(_.target.value),placeholder:"Search tasks",className:"h-8 rounded-sm border-border/70 bg-background/68 pl-8 text-[11px] shadow-none"})]}),e.jsx(z,{variant:"outline",size:"icon",onClick:()=>I(!1),className:"h-8 w-8 rounded-sm border-border/70 bg-background/68 shadow-none",children:e.jsx(Us,{className:"h-3.5 w-3.5"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(z,{variant:"outline",onClick:()=>I(!0),className:B("h-8 rounded-sm border-border/70 bg-background/68 px-2.5 text-[11px] shadow-none",k&&"border-primary/40 bg-primary/8 text-primary"),children:[e.jsx(ot,{className:"h-3.5 w-3.5"}),"Search"]}),e.jsx(z,{variant:C||He?"secondary":"outline",size:"icon",onClick:()=>se(_=>!_),className:B("h-8 w-8 shrink-0 rounded-sm border-border/70 bg-background/68 shadow-none",He&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(Ho,{className:"h-3.5 w-3.5"})})]})]}),(C||He)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(_e,{value:i,onValueChange:_=>U(_),children:[e.jsx(Ee,{className:Is,children:e.jsx(Ie,{})}),e.jsx(De,{children:Mr.map(_=>e.jsx(we,{value:_.value,className:zs,children:_.label},_.value))})]}),e.jsxs(_e,{value:b,onValueChange:P,children:[e.jsx(Ee,{className:Is,children:e.jsx(Ie,{placeholder:"Node"})}),e.jsx(De,{children:f.map(_=>e.jsx(we,{value:_.value,className:zs,children:_.label},_.value))})]}),e.jsxs(_e,{value:g,onValueChange:M,children:[e.jsx(Ee,{className:Is,children:e.jsx(Ie,{placeholder:"Agent"})}),e.jsx(De,{children:v.map(_=>e.jsx(we,{value:_,className:zs,children:_==="all"?"All agents":_},_))})]}),e.jsxs(_e,{value:N,onValueChange:_=>E(_),children:[e.jsx(Ee,{className:Is,children:e.jsx(Ie,{placeholder:"Type"})}),e.jsx(De,{children:Lr.map(_=>e.jsx(we,{value:_.value,className:zs,children:_.label},_.value))})]})]})]}),e.jsx("div",{className:B("scrollbar-line min-h-0 flex-1 overflow-y-auto px-1.5 py-2",D&&"scrollbar-line-active"),onScroll:Te,children:ke.length>0?e.jsx("div",{className:"space-y-1",children:ke.map(_=>{const fe=_.nodeId??"__unassigned__",ue=_.dirs.reduce((ve,Ne)=>ve+Ne.tasks.length,0),ze=as&&!os&&be.has(fe),We=_.nodeId!==null&&w.get(_.nodeId)==="offline",Le=!!(r&&_.nodeId&&ee);return e.jsxs("div",{className:"space-y-1",children:[as&&e.jsxs("div",{className:"flex w-full items-center gap-1.5 rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 px-2 py-1.5 text-left text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsxs("button",{type:"button",onClick:()=>xs(fe),"aria-expanded":!ze,className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[e.jsx(Ms,{className:B("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!ze&&"rotate-90")}),e.jsx($a,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:_.nodeName}),e.jsxs(Ke,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-transparent bg-background/55 px-1.5 py-0 text-[7px] font-semibold leading-3.5 text-muted-foreground shadow-none normal-case tracking-normal",children:[ue," task",ue===1?"":"s"]})]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[We&&e.jsx(Ke,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/10 px-1 py-0 text-[8px] font-semibold leading-3 text-destructive shadow-none",children:"offline"}),_.nodeId===p&&e.jsx(Ke,{variant:"outline",className:"rounded-sm border-transparent bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"}),Le&&_.nodeId&&ee&&e.jsx(Ht,{nodeId:_.nodeId,nodeName:_.nodeName,onOpenSettings:ee,onOpenDevBox:Z,onStartDevBox:H,showConfigureDevBox:x.has(_.nodeId),showStartDevBox:j.has(_.nodeId)||c.has(_.nodeId),startDevBoxPending:c.has(_.nodeId)})]})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-300 ease-in-out",ze?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:_.dirs.map(ve=>{const Ne=`${fe}::${ve.path}`,es=Je.has(Ne),Ss=Qa(ve.path),Se=S==null?void 0:S.get(Ne),Cs=Se?{visibleTasks:ve.tasks,hiddenCompletedCount:Math.max(0,Se.total-Se.returned)}:Hl(ve.tasks,je.has(Ne),t),{visibleTasks:fs,hiddenCompletedCount:Oe}=Cs;return e.jsxs("div",{className:B("space-y-0.5 rounded-xl",as&&"pl-2.5"),children:[e.jsxs("button",{type:"button",onClick:()=>$e(Ne),"aria-expanded":!es,title:ve.path,className:"flex w-full items-center gap-1.5 rounded-sm bg-muted/15 px-2 py-1 text-left text-[9px] font-medium text-muted-foreground/70 transition-all duration-150 hover:bg-muted/30 hover:text-foreground active:scale-[0.98] active:bg-muted/40",children:[e.jsx(Ms,{className:B("h-3 w-3 shrink-0 transition-transform duration-200",!es&&"rotate-90")}),e.jsx(Oa,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"truncate font-mono",children:Ss}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/40",children:ve.tasks.length})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-300 ease-in-out",es?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:B("overflow-hidden",as?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[fs.map(Ce=>{const ns=Ce.id===t,Fe=Ce.assignedTo?w.get(Ce.assignedTo):void 0,Ue=!!Ce.assignedTo&&(Fe?Fe==="offline":Ce.assignedNodeAvailable===!1);return e.jsxs("div",{className:B("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",ns?'bg-primary/10 before:absolute before:left-0 before:top-1/2 before:h-1/2 before:w-[2px] before:-translate-y-1/2 before:rounded-full before:bg-primary before:content-[""]':"hover:bg-muted/40"),children:[ge&&e.jsx("div",{className:"flex shrink-0",onClick:_s=>_s.stopPropagation(),children:e.jsx(pt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:A.has(Ce.id),onCheckedChange:_s=>J(Ce.id,_s===!0),"aria-label":`Select ${Ce.title}`})}),e.jsxs("button",{type:"button",onClick:()=>re(Ce.id),"aria-current":ns?"page":void 0,className:"relative min-w-0 flex-1 pr-8 text-left",children:[e.jsx("div",{className:"flex items-center gap-1.5 pr-1",children:e.jsx("span",{className:B("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",ns?"text-foreground":"text-foreground/80"),children:Ce.title})}),e.jsx("span",{className:B("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",ns?"text-primary/75":"text-muted-foreground/55"),children:Pr(Ce.updatedAt)}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5",children:[e.jsx("span",{className:"rounded-sm bg-muted/35 px-1 py-0 font-mono text-[8px] leading-3 text-muted-foreground/65",children:Ce.agent}),Ce.activeShare&&e.jsx(Ke,{variant:"outline",className:"rounded-sm border-primary/25 bg-primary/8 px-1 py-0 text-[8px] leading-3 text-primary shadow-none",children:"shared"}),Ue&&e.jsx(Ke,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/8 px-1 py-0 text-[8px] leading-3 text-destructive shadow-none",children:"unavailable"})]}),e.jsx(Ua,{status:Ce.status,isNative:Ce.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},Ce.id)}),Oe>0&&e.jsxs("button",{type:"button",onClick:()=>{Se&&K?K(Se):ls(Ne)},className:"mt-1 flex w-full items-center justify-center gap-1 rounded-sm border border-dashed border-border/55 bg-background/35 px-2 py-1 text-[9px] font-medium text-muted-foreground transition-colors hover:border-primary/35 hover:bg-primary/8 hover:text-primary","aria-label":`Load ${Oe} more completed tasks in ${Ss}`,children:[e.jsx(ts,{className:"h-3 w-3"}),"Load ",Oe," more completed"]})]})})})]},Ne)})})})]},fe)})}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(_=>e.jsx("div",{className:"rounded-xl border border-border/40 bg-background/30 px-3 py-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"mt-1 h-2.5 w-2.5 shrink-0 animate-pulse rounded-full bg-muted-foreground/20"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-2.5 animate-pulse rounded-full bg-muted-foreground/15",style:{width:`${60+_*12}%`,animationDelay:`${_*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${_*120+60}ms`}})]})]})},_))}):e.jsx("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-3 py-5 text-[11px] text-muted-foreground",children:o||"No tasks match this view."})}),is?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 items-center",children:ge?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(pt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:O&&!L?"indeterminate":L,onCheckedChange:_=>Me(_===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Multi select"})]}):e.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>oe(!0),className:"h-5 rounded-sm px-1.5 text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75 hover:text-foreground",children:[e.jsx(_o,{className:"h-3 w-3"}),"Multi select"]})}),ge&&e.jsxs("div",{className:"ml-auto flex w-48 max-w-[65%] flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[Q>0?e.jsxs("div",{className:"min-w-0 text-left",children:[e.jsxs("div",{className:"text-[9px] font-semibold leading-3 text-foreground",children:[Q," task",Q!==1?"s":""," selected"]}),!T&&e.jsx("div",{className:"max-w-48 text-[9px] leading-3.5 text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."})]}):e.jsx("span",{}),e.jsx(z,{variant:"ghost",size:"sm",onClick:hs,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:Q>0?"Clear":"Done"})]}),Q>0&&e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(lt,{children:[e.jsx(ra,{asChild:!0,children:e.jsxs(z,{variant:"ghost",size:"sm",disabled:!T,className:"h-5 gap-1 rounded-sm bg-muted/45 px-1.5 text-[8px] text-foreground/80 shadow-none hover:bg-muted/65 [&_svg]:size-3",children:[e.jsx(Bo,{}),"Archive"]})}),e.jsxs(dt,{children:[e.jsxs(ct,{children:[e.jsxs(ut,{children:["Archive ",Q," task",Q!==1?"s":"","?"]}),e.jsx(mt,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(xt,{children:[e.jsx(ht,{children:"Cancel"}),e.jsx(ft,{onClick:X,disabled:!T,children:"Archive"})]})]})]}),e.jsxs(lt,{children:[e.jsx(ra,{asChild:!0,children:e.jsxs(z,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(bi,{}),"Delete"]})}),e.jsxs(dt,{children:[e.jsxs(ct,{children:[e.jsxs(ut,{children:["Delete ",Q," task",Q!==1?"s":"","?"]}),e.jsx(mt,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(xt,{children:[e.jsx(ht,{children:"Cancel"}),e.jsx(ft,{onClick:ce,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]})]})}):null]})}async function Kl(s,t){var n,o;try{const r=await Br(s,t),i={...r,url:Fa(r.url)};if((o=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&o.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),te.success("Shared link copied")}catch{te.success("Shared link created")}else te.success("Shared link created");return i}catch(r){te.error(r instanceof Error?r.message:"Failed to create shared link");return}}async function ql(s){try{return await Rr(s),te.success("Shared link stopped"),!0}catch(t){return te.error(t instanceof Error?t.message:"Failed to stop shared link"),!1}}function Wl(s,t,n){const o=a.useCallback(()=>{t(),n()},[t,n]),r=a.useCallback(async g=>{if(!s)return;const b=await Kl(s.id,g);return b&&o(),b},[s,o]),i=a.useCallback(async()=>{if(!s)return!1;const g=await ql(s.id);return g&&o(),g},[s,o]);return{handleShareTask:r,handleStopShareTask:i}}function La(s,t,n){const o=a.useRef(t);o.current=t,a.useEffect(()=>{let g=0,b=0;const N=l=>{const u=l.touches[0];u&&(g=u.clientX,b=u.clientY)},v=l=>{var x,j,c,p;const u=l.changedTouches[0];if(!u)return;const w=u.clientX-g;Math.abs(u.clientY-b)>100||Math.abs(w)<50||(w>0?(j=(x=o.current).onSwipeRight)==null||j.call(x):(p=(c=o.current).onSwipeLeft)==null||p.call(c))},f=(s==null?void 0:s.current)??document;return f.addEventListener("touchstart",N,{passive:!0}),f.addEventListener("touchend",v,{passive:!0}),()=>{f.removeEventListener("touchstart",N),f.removeEventListener("touchend",v)}},[s,n==null?void 0:n.threshold,n==null?void 0:n.maxVertical])}const Gl="(min-width: 1024px)",Ql="(min-width: 1800px)";function Pa(s){var t,n,o;return((o=(n=(t=globalThis.window)==null?void 0:t.matchMedia)==null?void 0:n.call(t,s))==null?void 0:o.matches)??!1}function Yl(){var n,o;const s=(n=globalThis.document)==null?void 0:n.documentElement;if(!s||!((o=globalThis.window)!=null&&o.getComputedStyle))return 16;const t=Number.parseFloat(globalThis.window.getComputedStyle(s).fontSize);return Number.isFinite(t)&&t>0?t:16}function Xl(){const[s,t]=a.useState(()=>$r(oa(),Or({operationsOpen:Pa(Ql)}))),[n,o]=a.useState(!1),r=a.useRef(null),i=a.useRef(null),g=a.useRef(null),b=s.layout.desktopTasksOpen,N=s.layout.operationsOpen,v=s.sizes;a.useEffect(()=>{Fr(oa(),s)},[s]);const f=a.useCallback((j,c)=>{t(p=>{const k=p.layout[j],A=typeof c=="function"?c(k):c;return A===k?p:{...p,layout:{...p.layout,[j]:A}}})},[]),l=a.useCallback(j=>{f("desktopTasksOpen",j)},[f]),u=a.useCallback(j=>{f("operationsOpen",j)},[f]);La(i,{onSwipeLeft:()=>o(!1)}),La(g,{onSwipeRight:()=>u(!1)});const w=a.useCallback(()=>{if(Pa(Gl)){l(j=>!j);return}o(j=>!j)},[l]);a.useEffect(()=>{var p,k,A;const j=L=>{const O=r.current;if(!O)return;L.preventDefault();const T=zr(O.panel,O.startSize,O.startClientX,O.startClientY,L.clientX,L.clientY,O.rootFontSize);t(F=>({...F,sizes:{...F.sizes,[O.panel]:T}}))},c=()=>{r.current=null};return(p=globalThis.window)==null||p.addEventListener("pointermove",j),(k=globalThis.window)==null||k.addEventListener("pointerup",c),(A=globalThis.window)==null||A.addEventListener("pointercancel",c),()=>{var L,O,T;(L=globalThis.window)==null||L.removeEventListener("pointermove",j),(O=globalThis.window)==null||O.removeEventListener("pointerup",c),(T=globalThis.window)==null||T.removeEventListener("pointercancel",c)}},[]);const S=a.useCallback((j,c)=>{var p,k;c.preventDefault(),(k=(p=c.currentTarget).setPointerCapture)==null||k.call(p,c.pointerId),r.current={panel:j,startSize:v[j],startClientX:c.clientX,startClientY:c.clientY,rootFontSize:Yl()}},[v]),x=a.useCallback((j,c)=>{c.preventDefault(),t(p=>({...p,sizes:{...p.sizes,[j]:Ir(j,p.sizes[j],c.deltaY)}}))},[]);return{desktopTasksOpen:b,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:N,operationsPanelRef:g,panelResize:{sizes:{tasks:Zs(v.tasks),operations:Zs(v.operations),terminal:Zs(v.terminal)},onPointerDown:S,onWheel:x},setMobileTasksPanelOpen:o,setOperationsOpen:u,toggleTasksPanel:w}}function Jl(s,t){const n=t.taskId,o=t.updates;return typeof n!="string"||!o||typeof o!="object"?s:s.map(r=>r.id===n?{...r,...o}:r)}function Zl({isLeader:s,selfId:t}){return{...!s&&t?{assignedTo:t}:{},completedLimitPerProject:Pt}}function Dt(s){return`${s.assignedTo??"__unassigned__"}::${s.projectPath}`}function ed(s,t){const n=new Map(s.map(o=>[o.id,o]));for(const o of t)n.set(o.id,o);return Array.from(n.values())}function sd(s,t){return t?ln(s,t):s}function td({isLeader:s,selfId:t,sseConnected:n,preservedTask:o,subscribe:r}){const[i,g]=a.useState([]),[b,N]=a.useState([]),[v,f]=a.useState(!0),[l,u]=a.useState(null),w=a.useRef(null),S=a.useCallback(async()=>{try{const c=await ia(Zl({isLeader:s,selfId:t}));g(sd(c.tasks,o)),N(c.completedGroups??[]),u(null)}catch(c){u(c instanceof Error?c.message:"Failed to load tasks")}finally{f(!1)}},[s,o,t]),x=a.useCallback(async c=>{if(!c.hasMore||!c.nextCursor)return;const p=await ia({status:"completed",assignedTo:c.assignedTo??"__unassigned__",projectPath:c.projectPath,cursor:c.nextCursor,limit:Pt});g(k=>ed(k,p.tasks)),N(k=>k.map(A=>Dt(A)===Dt(c)?{...A,returned:Math.min(A.total,A.returned+p.tasks.length),hasMore:p.hasMore===!0,nextCursor:p.nextCursor??null}:A))},[]),j=a.useCallback(()=>{w.current===null&&(w.current=window.setTimeout(()=>{w.current=null,S()},Ur))},[S]);return Vr(S,Kr(n)),a.useEffect(()=>()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),a.useEffect(()=>{const c=[r("task.updated",p=>{g(k=>Jl(k,p.data))}),r("task.status",p=>{g(k=>Hr(k,p.data))}),r("node",p=>{la(p.type)&&j()}),r("task",p=>{la(p.type)&&j()})];return()=>c.forEach(p=>p())},[r,j]),{completedGroups:b,fetchTasks:S,loadCompletedTasksPage:x,setTasks:g,tasks:i,tasksError:l,tasksLoading:v}}function wn(s){return s.map(t=>({...t}))}function ad(s,t){const n=t.get(s);return{logs:n?wn(n.logs):[],transcriptLoading:(n==null?void 0:n.loaded)!==!0}}function nd(s,t){return t.data.nodeId===s.self.id||t.data.name===s.self.name||t.data.endpoint===s.self.endpoint}function rd({cluster:s,subscribe:t}){a.useEffect(()=>{var n;if(((n=s==null?void 0:s.self)==null?void 0:n.role)==="leader")return t("node",o=>{const r=String(o.data.name??o.data.nodeId??"node"),i=nd(s,o);o.type==="node.joined"&&!i&&te.success(`${r} joined the cluster`),o.type==="node.left"&&!i&&te.message(`${r} left the cluster`)})},[s,t])}const od=[0,300,1e3,2e3];function id({task:s,getActiveTaskId:t,setLogs:n,setPendingMessages:o,setTranscriptLoading:r}){s.conversationKind==="nativeSession"&&(async()=>{try{for(const i of od){if(i>0&&await new Promise(g=>setTimeout(g,i)),t()!==s.id)return;try{const g=await gt(s.id);if(t()!==s.id||(n(b=>sn(b,g.logs)),o(b=>vt(b,g.logs)),g.total>0))return}catch{}}}finally{t()===s.id&&(r==null||r(!1))}})()}function ld(s,t){return Pe(s??{})===Pe(t??{})}function dd(s){return s&&"status"in s&&typeof s.status=="string"?s.status:void 0}function Ba(s,t){return{...s,enabled:!0,alwaysOnline:t}}function yn(s){var t,n;return((t=s==null?void 0:s.status)==null?void 0:t.trim())||((n=s==null?void 0:s.lastStatus)==null?void 0:n.trim())||"Unknown"}function cd({operationStarting:s,loading:t,refreshing:n,savedStatus:o,fallbackStatus:r}){return s?"Starting":t?"Listing DevBoxes":n?"Refreshing":o??r}function Ra({devbox:s,showStatus:t=!1}){return e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"font-medium",children:s.name}),s.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",s.projectName]})]}),t&&e.jsx("span",{className:"ml-auto shrink-0 rounded-full border border-border/70 bg-background/70 px-1.5 py-0.5 text-[10px] leading-none text-muted-foreground",children:yn(s)})]})}function ud({node:s,open:t,startInProgress:n=!1,onOpenChange:o,onRefresh:r}){const i=(s==null?void 0:s.id)??null,g=t&&!n&&Sa(s==null?void 0:s.status,(s==null?void 0:s.devbox)??null),[b,N]=a.useState([]),[v,f]=a.useState(()=>s!=null&&s.devbox?Pe(s.devbox):""),[l,u]=a.useState(()=>(s==null?void 0:s.devbox)??null),[w,S]=a.useState(()=>Ca((s==null?void 0:s.devbox)??null)),[x,j]=a.useState(!1),[c,p]=a.useState(g),[k,A]=a.useState(!1),[L,O]=a.useState(!1),[T,F]=a.useState(()=>{var m;return((m=s==null?void 0:s.devbox)==null?void 0:m.alwaysOnline)===!0}),U=a.useMemo(()=>{const m=b.find($=>Pe($)===v);return m||(Ns(l)&&Pe(l)===v?l:void 0)},[l,b,v]),M=dd(U??void 0),P=w?M??(l==null?void 0:l.lastStatus):(l==null?void 0:l.lastStatus)??M,E=(s==null?void 0:s.status)==="online"||(s==null?void 0:s.status)==="busy"?"Running":"Unknown",J=L||n,V=cd({operationStarting:J,loading:x,refreshing:c,savedStatus:P,fallbackStatus:E}),X=w&&!!U&&!ld(l,U),ce=(l==null?void 0:l.alwaysOnline)===!0!==T,ae=$l({nodeStatus:s==null?void 0:s.status,status:V,current:l,selected:U}),ee=!!ae,Z=!!U&&(X||ce)&&!ee,H=U??l,K=a.useCallback(async()=>{if(i){p(!0);try{const m=await qr(i);u(m.devbox),f(Pe(m.devbox))}catch(m){te.error(m instanceof Error?m.message:"Failed to refresh DevBox status")}finally{p(!1)}}},[i]),re=a.useCallback(async m=>{j(!0);try{const $=await Wr();N($),f(q=>Ol({previousKey:q,baseDevBox:m,listed:$}))}catch($){te.error($ instanceof Error?$.message:"Failed to load DevBoxes")}finally{j(!1)}},[]);a.useEffect(()=>{if(!t||!i)return;let m=!1;const $=(s==null?void 0:s.devbox)??null,q=Ca($),ne=!n&&Sa(s==null?void 0:s.status,$);j(!1),p(ne),S(q),u($),F(($==null?void 0:$.alwaysOnline)===!0),f(Ns($)?Pe($):""),N([]);async function W(){ne&&await K(),!m&&q&&await re($)}return W(),()=>{m=!0}},[re,s==null?void 0:s.devbox,s==null?void 0:s.status,i,t,K,n]);async function xe(){S(!0),b.length===0&&await re(l)}async function h(){if(!(!s||!U)){A(!0);try{const m=await da(s.id,Ba(U,T));u(m.node.devbox??null),m.node.devbox&&f(Pe(m.node.devbox)),S(!1),te.success(`Configured DevBox for ${s.name}`),await(r==null?void 0:r())}catch(m){te.error(m instanceof Error?m.message:"Failed to configure DevBox")}finally{A(!1)}}}async function I(){if(!(!s||!ae)){O(!0);try{if(U&&(X||ce)){const $=await da(s.id,Ba(U,T));u($.node.devbox??null),$.node.devbox&&f(Pe($.node.devbox)),S(!1)}const{operation:m}=await Ya(s.id);u($=>$&&{...$,lastStatus:"Starting",checkedAt:Date.now(),operationId:m.id}),te.success(`Start requested for ${s.name}`),await(r==null?void 0:r())}catch(m){te.error(m instanceof Error?m.message:"Failed to start DevBox")}finally{O(!1)}}}const C=x?"Loading DevBoxes...":b.length===0?"No DevBoxes available":"Select a DevBox",se=V==="Running"&&(s==null?void 0:s.status)==="offline";return e.jsx(Tt,{open:t,onOpenChange:o,children:e.jsxs(At,{className:"max-w-md gap-4 rounded-lg p-5",children:[e.jsxs(Ha,{className:"space-y-1",children:[e.jsx(Mt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(Gr,{className:"text-xs",children:["Bind ",s!=null&&s.name?e.jsx("span",{className:"font-medium text-foreground",children:s.name}):"this node"," to an Azure Dev Box. Meshy will start it when the node is offline."]})]}),e.jsxs("div",{className:"space-y-3",children:[(w||H)&&e.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 rounded-xl border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:w?e.jsxs(_e,{value:v,onValueChange:f,disabled:x||k||L||b.length===0,children:[e.jsx(Ee,{className:"h-7 justify-start gap-2 rounded-none border-0 bg-transparent px-0 text-xs shadow-none focus:ring-0 focus:ring-offset-0 [&>span]:!flex [&>span]:!min-w-0 [&>span]:!flex-1 [&>span]:!items-center",children:x&&!U?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),C]}):U?e.jsx(Ra,{devbox:U}):e.jsx(Ie,{placeholder:C})}),e.jsx(De,{children:b.map(m=>e.jsx(we,{value:Pe(m),textValue:`${m.name} ${m.projectName??""} ${yn(m)}`,className:"pl-2 pr-7 text-xs [&>span:first-child]:left-auto [&>span:first-child]:right-2 [&>span:last-child]:w-full",children:e.jsx(Ra,{devbox:m,showStatus:!0})},Pe(m)))})]}):H&&e.jsxs("div",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:H.name}),H.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",H.projectName]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Ke,{variant:"outline",className:"rounded-full px-2 py-0.5 text-[10px]",children:[(x||c)&&e.jsx(me,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),V]}),(l==null?void 0:l.name)&&e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{xe()},disabled:x||k||J||w,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-full text-muted-foreground hover:text-foreground",children:x&&w?e.jsx(me,{className:"h-3 w-3 animate-spin"}):e.jsx(ys,{className:"h-3 w-3"})})]})]}),se&&e.jsx("div",{className:"rounded-xl border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300",children:"DevBox is running, but the Meshy node is not connected yet."}),e.jsxs("label",{className:"flex min-h-9 items-start gap-2 rounded-xl border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(pt,{checked:T,onCheckedChange:m=>F(m===!0),disabled:k||L||J,"aria-label":"Always online",className:"mt-0.5 h-3.5 w-3.5"}),e.jsxs("span",{className:"min-w-0 leading-4",children:[e.jsx("span",{className:"block",children:"Always online"}),e.jsx("span",{className:"block text-[10px] leading-3.5 text-muted-foreground",children:"Meshy will start the DevBox automatically when it is Hibernated or Stopped."})]})]})]}),e.jsxs(Ka,{className:"gap-2 sm:space-x-0",children:[e.jsx(z,{variant:"ghost",size:"sm",onClick:()=>o(!1),disabled:k||L,className:"h-8 rounded-xl text-xs",children:"Close"}),ee&&e.jsxs(z,{size:"sm",onClick:I,disabled:L,className:"h-8 rounded-xl text-xs",children:[L?e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Rt,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!ee&&e.jsxs(z,{size:"sm",onClick:h,disabled:!Z||k,className:"h-8 rounded-xl text-xs",children:[k&&e.jsx(me,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function md(s,t=Qr){if(s.length===0)return new Set;const n=new Set(s),[o,r]=await Promise.all([t({kind:"devbox.start",status:"queued"}),t({kind:"devbox.start",status:"running"})]);return new Set([...o,...r].filter(i=>n.has(i.nodeId)).map(i=>i.nodeId))}function xd({cluster:s,refresh:t}){const[n,o]=a.useState(null),[r,i]=a.useState(null),[g,b]=a.useState(()=>new Set),[N,v]=a.useState(()=>new Set),f=a.useMemo(()=>(s==null?void 0:s.nodes.find(c=>c.id===n))??null,[s==null?void 0:s.nodes,n]),l=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(c=>{var p;return(p=c.devbox)==null?void 0:p.enabled}).map(c=>c.id)),[s==null?void 0:s.nodes]),u=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(c=>{var p;return Ks(c.status,(p=c.devbox)==null?void 0:p.lastStatus,c.devbox)}).map(c=>c.id)),[s==null?void 0:s.nodes]),w=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(c=>{var p;return ws((p=c.devbox)==null?void 0:p.lastStatus)}).map(c=>c.id)),[s==null?void 0:s.nodes]),S=a.useMemo(()=>{const c=new Set(g);r&&c.add(r);for(const p of N)c.add(p);for(const p of w)c.add(p);return c},[N,r,g,w]);a.useEffect(()=>{let c=!1;const p=[...l];async function k(){try{const A=await md(p);c||v(A)}catch{c||v(new Set)}}return k(),()=>{c=!0}},[l]),a.useEffect(()=>{b(c=>{var A;let p=!1;const k=new Set(c);for(const L of c){const O=s==null?void 0:s.nodes.find(T=>T.id===L);(O==null?void 0:O.status)!=="online"&&(!((A=O==null?void 0:O.devbox)!=null&&A.lastStatus)||ws(O.devbox.lastStatus))||(k.delete(L),p=!0)}return p?k:c})},[s==null?void 0:s.nodes]);const x=a.useCallback(async c=>{const p=s==null?void 0:s.nodes.find(k=>k.id===c);if(p){i(c),b(k=>new Set(k).add(c));try{await Ya(c),te.success(`Start requested for ${p.name}`),t()}catch(k){b(A=>{const L=new Set(A);return L.delete(c),L}),te.error(k instanceof Error?k.message:"Failed to start DevBox")}finally{i(null)}}},[s==null?void 0:s.nodes,t]);return{devBoxDialog:e.jsx(ud,{node:f,open:n!==null,startInProgress:f?S.has(f.id):!1,onOpenChange:c=>{c||o(null)},onRefresh:t}),devBoxNodeIds:l,devBoxStartNodeId:r,devBoxStartNodeIds:u,devBoxStartingNodeIds:S,openDevBox:o,startDevBox:x}}function hd(s){const[t,n]=a.useState(null),o=a.useCallback(i=>{s&&n(i)},[s]);return{nodeSettingsDialog:e.jsx(Yr,{open:t!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:t??void 0,showTrigger:!1}),openNodeSettings:o}}function fd({activeTaskId:s,fetchActiveTask:t,setPendingMessages:n,setTask:o,setTasks:r}){const i=a.useCallback((N,v)=>{o(f=>f&&f.id===N?{...f,queuedMessages:v}:f),r(f=>f.map(l=>l.id===N?{...l,queuedMessages:v}:l))},[o,r]),g=a.useCallback(async N=>{if(!s)return!1;const v=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`;n(f=>[...f,{id:v,content:N,timestamp:new Date().toISOString()}]);try{const f=await Xr(s,N);return f.queued&&(n(l=>l.filter(u=>u.id!==v)),f.queuedMessages&&i(s,f.queuedMessages)),t(),!0}catch(f){return n(l=>l.filter(u=>u.id!==v)),te.error(f instanceof Error?f.message:"Failed to send message"),!1}},[s,t,n,i]);return{cancelQueuedMessage:a.useCallback(async N=>{if(s)try{const v=await Jr(s,N);i(s,v.queuedMessages),t()}catch(v){te.error(v instanceof Error?v.message:"Failed to cancel queued message")}},[s,t,i]),queueFollowUpMessage:g}}function pd(){var Qt,Yt,Xt,Jt,Zt,ea;const{id:s}=Zr(),t=eo(),n=so(),o=to(),{cluster:r,systemInfo:i,events:g,sseConnected:b,subscribe:N,refresh:v,loading:f,error:l}=ao(),u=a.useMemo(()=>no(t.state),[t.state]),[w,S]=a.useState(null),[x,j]=a.useState("active"),[c,p]=a.useState("all"),[k,A]=a.useState("all"),[L,O]=a.useState("all"),[T,F]=a.useState(""),U=(o==null?void 0:o.headerSearchQuery)??T,M=(o==null?void 0:o.setHeaderSearchQuery)??F,P=a.useDeferredValue(U),{desktopTasksOpen:E,mobileTasksPanelOpen:J,mobileTasksPanelRef:V,operationsOpen:X,operationsPanelRef:ce,panelResize:ae,setMobileTasksPanelOpen:ee,setOperationsOpen:Z,toggleTasksPanel:H}=Xl(),[K,re]=a.useState(()=>!!(u!=null&&u.draftNewTask)),[xe,h]=a.useState(()=>(u==null?void 0:u.createMode)??"chat"),[I,C]=a.useState(()=>u!=null&&u.draftNewTask?{route:u.returnRoute??"/",taskId:u.returnTaskId??null}:null),[se,m]=a.useState(!1),[$,q]=a.useState("transcript"),[ne,W]=a.useState("all"),[ie,oe]=a.useState(!1),[Te,D]=a.useState(null),[Q,ge]=a.useState([]),[He,Y]=a.useState([]),[be,ye]=a.useState(!1),[Je,Be]=a.useState(!1),[je,Ye]=a.useState(null),[ke,Ae]=a.useState(new Set),[Ze,ms]=a.useState(!1),[as,os]=a.useState(!1),[is,xs]=a.useState(null),$e=a.useRef(null),ls=a.useRef(new Map),Me=((Qt=r==null?void 0:r.self)==null?void 0:Qt.role)==="leader",hs=(Yt=r==null?void 0:r.self)==null?void 0:Yt.id;rd({cluster:r,subscribe:N});const{nodeSettingsDialog:_,openNodeSettings:fe}=hd(Me),{devBoxDialog:ue,devBoxNodeIds:ze,devBoxStartNodeId:We,devBoxStartNodeIds:Le,devBoxStartingNodeIds:ve,openDevBox:Ne,startDevBox:es}=xd({cluster:r,refresh:v}),{completedGroups:Ss=[],fetchTasks:Se,loadCompletedTasksPage:Cs,setTasks:fs,tasks:Oe,tasksError:Ce,tasksLoading:ns}=td({isLeader:Me,selfId:hs,sseConnected:b,preservedTask:Te,subscribe:N}),Fe=a.useMemo(()=>[...Oe].sort((d,y)=>y.updatedAt-d.updatedAt),[Oe]),Ue=a.useMemo(()=>{var d;return((d=[...Oe].sort((y,R)=>R.createdAt-y.createdAt||R.updatedAt-y.updatedAt)[0])==null?void 0:d.id)??null},[Oe]),_s=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[]){const R=ji(Fe,y.id);R>0&&d.set(y.id,R)}return d},[r==null?void 0:r.nodes,Fe]),Ge=a.useMemo(()=>Fe.filter(d=>!ro(d,r==null?void 0:r.nodes,r==null?void 0:r.self)||!oo(d,x)||c!=="all"&&d.agent!==c||!io(d,L)||k==="unassigned"&&d.assignedTo||k!=="all"&&k!=="unassigned"&&lo(d.assignedTo,r==null?void 0:r.nodes,d.assignedNodeName)!==k?!1:P.trim()?co(d,P):!0),[Fe,r==null?void 0:r.nodes,r==null?void 0:r.self,x,c,L,k,P]);a.useEffect(()=>{Ae(d=>{const y=Ci(d,Ge.map(R=>R.id));return y.size===d.size?d:y})},[Ge]),a.useEffect(()=>{Me||Ae(new Set)},[Me]);const kn=a.useMemo(()=>["all",...Array.from(new Set(Fe.map(d=>d.agent))).sort()],[Fe]),Sn=a.useMemo(()=>{const y=Array.from(new Set(Fe.map(R=>R.assignedTo).filter(R=>!!R))).map(R=>{const pe=Fe.find(le=>le.assignedTo===R);return(r==null?void 0:r.nodes.find(le=>le.id===R))??{id:R,name:it(R,r==null?void 0:r.nodes,pe==null?void 0:pe.assignedNodeName)}}).sort((R,pe)=>R.name.localeCompare(pe.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...y.map(R=>({value:R.name.toLowerCase(),label:R.name}))]},[Fe,r==null?void 0:r.nodes]),Kt=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[])d.set(y.id,y.name);for(const y of Fe)y.assignedTo&&y.assignedNodeName&&!d.has(y.assignedTo)&&d.set(y.assignedTo,y.assignedNodeName);return d},[r==null?void 0:r.nodes,Fe]),Cn=a.useMemo(()=>{var y;const d=new Map;for(const R of(r==null?void 0:r.nodes)??[])R.workDir&&d.set(R.id,R.workDir);return(y=r==null?void 0:r.self)!=null&&y.workDir&&d.set(r.self.id,r.self.workDir),d},[r]),_n=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[])d.set(y.id,y.status);return r!=null&&r.self&&d.set(r.self.id,r.self.status),d},[r]),En=a.useMemo(()=>new Map(Ss.map(d=>[Dt(d),d])),[Ss]),qt=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[])y.status!=="offline"&&d.set(y.id,y);return r!=null&&r.self&&r.self.status!=="offline"&&d.set(r.self.id,r.self),Array.from(d.values())},[r]),Dn=((Xt=r==null?void 0:r.self)==null?void 0:Xt.id)??((Jt=qt[0])==null?void 0:Jt.id)??null,qs=a.useMemo(()=>["all",...Array.from(new Set(g.map(d=>d.type))).sort()],[g]),Tn=a.useMemo(()=>ne==="all"?g:g.filter(d=>d.type===ne),[g,ne]),An=Ge.length>0&&Ge.every(d=>ke.has(d.id)),Mn=Ge.some(d=>ke.has(d.id)),Ln=_i(Ge,ke);a.useEffect(()=>{u!=null&&u.draftNewTask&&(re(!0),C({route:u.returnRoute??"/",taskId:u.returnTaskId??null}))},[u]),a.useEffect(()=>{ne!=="all"&&!qs.includes(ne)&&W("all")},[ne,qs]),a.useEffect(()=>{ga(s,K)&&!w&&Ue&&S(Ue)},[s,K,w,Ue]),a.useEffect(()=>{ga(s,K)&&(w&&Oe.some(d=>d.id===w)||S(Ue))},[s,K,w,Ue,Oe]);const de=wi({routeTaskId:s,creatingTask:K,internalSelectedTaskId:w,sortedTaskIds:Ue?[Ue]:[]}),ps=a.useMemo(()=>Oe.find(d=>d.id===de)??null,[Oe,de]);a.useEffect(()=>{$e.current=de??null},[de]);const rs=a.useCallback(()=>{D(null),ge([]),Y([]),Ye(null),Be(!1)},[]),Es=a.useCallback((d,y,R=!0)=>{ls.current.set(d,{logs:wn(y),loaded:R})},[]),Ve=a.useCallback(async()=>{const d=de;if(d)try{const y=await uo(d);if($e.current!==d)return;D(y),fs(R=>ln(R,y)),Ye(null)}catch(y){if($e.current!==d)return;rs(),Ye(y instanceof Error?y.message:"Failed to load task")}finally{$e.current===d&&ye(!1)}},[de,rs,fs]),Bs=a.useCallback(async()=>{const d=de;if(d)try{const y=await gt(d);if($e.current!==d)return;ge(R=>{const pe=sn(R,y.logs);return Es(d,pe),pe}),Y(R=>vt(R,y.logs))}catch{}finally{$e.current===d&&Be(!1)}},[de,Es]);a.useEffect(()=>{if(!de){rs(),ye(!1);return}q("transcript"),D(ps);const d=ad(de,ls.current);ge(d.logs),Y([]),Ye(null),ye(!0),Be(d.transcriptLoading),Ve(),Bs()},[de,rs,Bs,Ve]),a.useEffect(()=>{if(!yi({activeTaskId:de,routeTaskId:s,creatingTask:K,tasksLoading:ns,loadedTaskIds:Oe.map(y=>y.id)}))return;const d=Ue;S(d),rs(),a.startTransition(()=>{n(d?`/tasks/${d}`:"/",{state:null})})},[de,rs,K,Ue,n,s,Oe,ns]),a.useEffect(()=>{ps&&D(d=>!d||d.id!==ps.id?d:{...d,...ps})},[ps]),a.useEffect(()=>{if(de)return N("task",d=>{const y=d.data.taskId;if(!(typeof y!="string"||y!==de)){if(d.type==="task.output"){const R=d.data.event;if(R){ge(le=>{const Ts=Eo(le,R);return Es(de,Ts),Ts}),Be(!1);const pe=ha(R);pe&&Y(le=>Do(le,pe))}}d.type==="task.updated"&&Ve(),d.type==="task.status"&&(Ve(),Bs())}})},[N,de,Ve,Bs]);const G=Te??ps,Pn=G!=null&&G.assignedTo?(r==null?void 0:r.nodes.find(d=>d.id===G.assignedTo))??null:null,Ds=o==null?void 0:o.setHeaderTaskContext;a.useEffect(()=>{if(!Ds)return;if(!G){Ds(null);return}const d=G.effectiveProjectPath??G.project??"default workspace";return Ds({taskId:G.id,taskTitle:G.title,nodeName:it(G.assignedTo,r==null?void 0:r.nodes,G.assignedNodeName),projectLabel:Qa(d),projectPath:d}),()=>Ds(null)},[G,r==null?void 0:r.nodes,Ds]);const Ws=He.length>0,Bn=G?mo.has(G.agent):!1,Gs=(G==null?void 0:G.status)==="running",Rn=G?Vs.has(G.status):!1,$n=G?Vs.has(G.status)||xo.has(G.status):!1,On=!!(G&&Me&&G.status==="failed"),Qs=a.useMemo(()=>zl(G,r,Ws,!!Gs),[G,r,Ws,Gs]),Ys=a.useMemo(()=>To([...Q,...He.map(d=>st(d.content,d.timestamp))]),[Q,He]),Rs=a.useMemo(()=>{if(!G||G.conversationKind==="nativeSession")return null;const d=Ao(G);if(d.length>0)return st(d,new Date(G.createdAt).toISOString());if(Ys.length>0)return null;const y=Mo(G.description||G.title);return y.length>0?st(y,new Date(G.createdAt).toISOString()):null},[G,Ys]),Xs=a.useMemo(()=>Rs?ha(Rs):null,[Rs]),Fn=a.useMemo(()=>Xs?Lo(Q,Xs):!1,[Q,Xs]),Js=a.useCallback((d="chat")=>{const y={route:s?`/tasks/${s}`:"/",taskId:de};C(y),h(d),re(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:y.route,returnTaskId:y.taskId,createMode:d}})})},[s,de,n]),In=a.useCallback(()=>{const d=(I==null?void 0:I.taskId)??Ue;re(!1),C(null),S(d),a.startTransition(()=>{n((I==null?void 0:I.route)??"/",{state:null})})},[I,Ue,n]),Wt=a.useCallback(d=>{re(!1),C(null),S(d),a.startTransition(()=>{n(`/tasks/${d}`,{state:null})})},[n]),zn=a.useCallback(d=>{$e.current=d.id,re(!1),C(null),fs(y=>ki(y,d)),D(d),ge([]),Y([]),Ye(null),ye(!1),Be(d.conversationKind==="nativeSession"),q("transcript"),S(d.id),id({task:d,getActiveTaskId:()=>$e.current,setLogs:ge,setPendingMessages:Y,setTranscriptLoading:Be}),Se(),a.startTransition(()=>{n(`/tasks/${d.id}`,{state:null})})},[Se,n]),{cancelQueuedMessage:Un,queueFollowUpMessage:$s}=fd({activeTaskId:de,fetchActiveTask:Ve,setPendingMessages:Y,setTask:D,setTasks:fs}),Vn=a.useCallback(d=>{$s(d)},[$s]),Hn=a.useCallback(async()=>{const d=de;if(!(!d||(G==null?void 0:G.conversationKind)!=="nativeSession")){Be(!0);try{const y=await gt(d);if($e.current!==d)return;ge(y.logs),Es(d,y.logs),Y(R=>vt(R,y.logs))}catch(y){te.error(y instanceof Error?y.message:"Failed to reload transcript")}finally{$e.current===d&&Be(!1)}}},[G==null?void 0:G.conversationKind,de,Es]),Kn=a.useCallback(d=>$s(d),[$s]),qn=a.useCallback(async()=>{if(G)try{await ho(G.id),Ve(),Se()}catch(d){te.error(d instanceof Error?d.message:"Failed to cancel task")}},[G,Ve,Se]),{handleShareTask:Wn,handleStopShareTask:Gn}=Wl(G,Ve,Se),Qn=a.useCallback(async()=>{if(G)try{await fo(G.id),Ve(),Se()}catch(d){te.error(d instanceof Error?d.message:"Failed to retry task")}},[G,Ve,Se]),Os=a.useCallback((d,y=!1)=>{const R=Ei(Ge,d);return S(R),(y||!R)&&rs(),a.startTransition(()=>{n(R?`/tasks/${R}`:"/",{state:null})}),R},[rs,Ge,n]),Yn=a.useCallback((d,y)=>{Ae(R=>{const pe=new Set(R);return y?pe.add(d):pe.delete(d),pe})},[]),Xn=a.useCallback(d=>{if(!d){Ae(new Set);return}Ae(new Set(Ge.map(y=>y.id)))},[Ge]),Jn=a.useCallback(async()=>{const d=Array.from(ke);if(d.length!==0)try{const{results:y}=await po(d),R=y.filter(le=>!le.ok),pe=y.filter(le=>le.ok).map(le=>le.id);de&&pe.includes(de)&&Os(pe),R.length>0?te.error(`Failed to archive ${R.length} task(s): ${R.map(le=>le.error??le.id).join(", ")}`):te.success(`Archived ${pe.length} task(s)`),Ae(new Set(R.map(le=>le.id))),Se()}catch(y){te.error(y instanceof Error?y.message:"Failed to archive tasks")}},[de,Se,Os,ke]),Zn=a.useCallback(async()=>{const d=Array.from(ke);if(d.length!==0)try{const{results:y}=await go(d),R=y.filter(le=>!le.ok),pe=y.filter(le=>le.ok).map(le=>le.id);de&&pe.includes(de)&&Os(pe,!0),R.length>0?te.error(`Failed to delete ${R.length} task(s): ${R.map(le=>le.error??le.id).join(", ")}`):te.success(`Deleted ${pe.length} task(s)`),Ae(new Set(R.map(le=>le.id))),Se()}catch(y){te.error(y instanceof Error?y.message:"Failed to delete tasks")}},[de,Se,Os,ke]),er=a.useCallback(async()=>{ms(!0);try{await bo(),v()}catch(d){te.error(d instanceof Error?d.message:"Failed to promote node")}finally{ms(!1)}},[v]),sr=a.useCallback(async()=>{os(!0);try{await vo(),te.success("This node left the remote cluster and is leading itself again."),Se(),Ve(),v()}catch(d){te.error(d instanceof Error?d.message:"Failed to leave cluster")}finally{os(!1)}},[Ve,Se,v]),tr=a.useCallback(async d=>{var Ts;const y=!zt(d),R=d.id===((Ts=r==null?void 0:r.self)==null?void 0:Ts.id),pe=R?(i==null?void 0:i.transportType)??d.transportType:d.transportType,le=R&&!y&&ks(pe);xs(d.id);try{le?await jo("direct"):await No(d.id,y),te.success(y?`Enabled remote access on ${d.name}`:`Disabled remote access on ${d.name}`),v()}catch(sa){te.error(sa instanceof Error?sa.message:"Failed to update remote access")}finally{xs(null)}},[(Zt=r==null?void 0:r.self)==null?void 0:Zt.id,v,i==null?void 0:i.transportType]),ar=a.useCallback(d=>{Cs&&Cs(d).catch(y=>{te.error(y instanceof Error?y.message:"Failed to load completed tasks")})},[Cs]),Gt={toolbarTasks:Ge,activeTaskId:de,tasksLoading:ns,tasksError:Ce,isLeader:Me,scope:x,agentFilter:c,nodeFilter:k,taskKindFilter:L,agentOptions:kn,nodeOptions:Sn,nodeNameById:Kt,nodeWorkDirById:Cn,nodeStatusById:_n,leaderNodeId:((ea=r==null?void 0:r.leader)==null?void 0:ea.id)??null,searchQuery:U,completedGroupByKey:En,devBoxNodeIds:ze,devBoxStartNodeIds:Le,devBoxStartingNodeIds:ve,selectedTaskIds:ke,allVisibleTasksSelected:An,someVisibleTasksSelected:Mn,canBatchArchive:Ln,onSearchChange:M,onScopeChange:j,onAgentFilterChange:p,onNodeFilterChange:A,onTaskKindFilterChange:O,onToggleTaskSelected:Yn,onToggleAllVisibleTasks:Xn,onBatchArchive:Jn,onBatchDelete:Zn,onCreateTask:Js,onOpenNodeSettings:Me?fe:void 0,onOpenDevBox:Me?Ne:void 0,onStartDevBox:Me?es:void 0,onLoadCompletedTasks:ar,onSelectTask:Wt,onClose:H},nr={cluster:r,systemInfo:i,nodeNameById:Kt,nodeBlockingTaskCounts:_s,eventTypeFilter:ne,onEventTypeFilterChange:W,eventTypeOptions:qs,filteredEvents:Tn,sseConnected:b,clusterLoading:f,clusterError:l,promotePending:Ze,onPromote:er,onAddNode:()=>m(!0),leavePending:as,onLeaveCluster:sr,onToggleNodeDevTunnel:tr,devTunnelNodeId:is,devBoxStartNodeId:We,devBoxStartingNodeIds:ve,onOpenNodeSettings:Me?fe:void 0,onOpenDevBox:Me?Ne:void 0,onStartDevBox:Me?es:void 0,onClose:()=>Z(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Sl,{desktopTasksOpen:E,mobileTasksPanelOpen:J,mobileTasksPanelRef:V,operationsOpen:X,operationsPanelRef:ce,panelResize:ae,taskSidebar:e.jsx(Ma,{...Gt}),operationsSidecar:e.jsx(Fl,{...nr}),terminalPanel:o!=null&&o.terminalOpen?e.jsx(Ll,{nodes:qt,defaultNodeId:Dn,onClose:()=>o==null?void 0:o.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(Nl,{onToggleTasks:H,desktopTasksOpen:E,mobileTasksPanelOpen:J,operationsOpen:X,onToggleOperations:()=>Z(d=>!d),cluster:r,sseConnected:b,activeTab:$,setActiveTab:q,creatingTask:K,createMode:xe,activeTask:G,assignedNode:Pn,taskLoading:be,transcriptLoading:Je,taskError:je,displayEvents:Ys,initialPromptAlreadyInLogs:Fn,initialPrompt:Rs,supportsFollowUp:Bn,taskUnavailable:Qs.taskUnavailable,chatDisabled:Qs.chatDisabled,chatDisabledReason:Qs.chatDisabledReason,questionBypassEnabled:ie,isRunning:!!Gs,isStarting:Rn,hasPendingFollowUp:Ws,canCancel:!!$n,canRetry:!!On,onRetry:Qn,onCancel:qn,onReloadNativeTranscript:Hn,onShareTask:Wn,onStopShareTask:Gn,onStartCreateTask:Js,onCancelCreateTask:In,onCreateTask:zn,onSendMessage:Vn,onCancelQueuedMessage:Un,onQuestionBypassChange:oe,onSubmitQuestionResponse:Kn}),mobileTaskSidebar:e.jsx(Ma,{...Gt,onCreateTask:d=>{ee(!1),Js(d)},onSelectTask:d=>{ee(!1),Wt(d)},onClose:()=>ee(!1)}),onCloseOperations:()=>Z(!1),onCloseTaskList:()=>ee(!1)}),e.jsx(kl,{open:se,onOpenChange:m,onAdded:v}),_,ue]})}const jd=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:pd},Symbol.toStringTag,{value:"Module"}));export{jd as D,jt as G};