meshy-node 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dashboard/assets/{DashboardPage-D1wM2m_k.js → DashboardPage-ChLMJEx-.js} +3 -3
- package/dashboard/assets/{DashboardShared-BL_KNSdm.js → DashboardShared-DfFmE9OZ.js} +1 -1
- package/dashboard/assets/{DiffTab-W3q-F9LR.js → DiffTab-D9EMDOWs.js} +1 -1
- package/dashboard/assets/{FilesTab-Dk8SrJcE.js → FilesTab-UdncGsMa.js} +1 -1
- package/dashboard/assets/{PreviewTab-nzxEnO7P.js → PreviewTab-lu08ISli.js} +1 -1
- package/dashboard/assets/{SharedConversationPage-bBCU_UoC.js → SharedConversationPage-rLdor30V.js} +3 -3
- package/dashboard/assets/{file-C8r7XihN.js → file-B2d5h01r.js} +1 -1
- package/dashboard/assets/index-DJQVK04P.js +316 -0
- package/dashboard/assets/{play-vKjOF6T8.js → play-DVVA11Ah.js} +1 -1
- package/dashboard/index.html +1 -1
- package/package.json +1 -1
- package/runtime-metadata.json +4 -4
- package/dashboard/assets/index-wRjK5-z7.js +0 -316
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-
|
|
2
|
-
import{c as fe,r as a,j as e,X as Xe,B as z,S as Fa,a as rr,b as B,d as or,g as ir,e as lr,I as Ge,C as As,f as dr,h as cr,F as ur,i as Ia,k as Ms,l as ye,D as Ls,m as mr,n as xr,t as ae,o as _e,p as Ee,q as Ie,s as De,u as lt,v as Je,T as hr,w as fr,x as na,y as pr,z as Mt,A as Lt,E as Pt,G as za,H as Ua,J as vs,K as dt,L as gr,M as Va,N as Ha,P as br,O as Ka,Q as ls,R as Ve,U as vr,V as ds,W as ct,Y as ut,Z as mt,_ as xt,$ as ht,a0 as ft,a1 as pt,a2 as gt,a3 as Bt,a4 as jr,a5 as qa,a6 as Wa,a7 as Nr,a8 as ra,a9 as oa,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 Ga,ak as Qa,al as Ya,am as Tr,an as Vs,ao as Rt,ap as Ar,aq as Mr,ar as Lr,as as Xa,at as bt,au as Pr,av as ia,aw as Br,ax as Rr,ay as $r,az as Or,aA as la,aB as Fr,aC as Ir,aD as st,aE as zr,aF as da,aG as Ur,aH as Vr,aI as Hr,aJ as ca,aK as Kr,aL as vt,aM as qr,aN as Wr,aO as Gr,aP as ua,aQ as Ja,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-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-UdncGsMa.js","assets/index-DJQVK04P.js","assets/index-BUg_sIQ1.css","assets/file-B2d5h01r.js","assets/DashboardShared-DfFmE9OZ.js","assets/PreviewTab-lu08ISli.js","assets/play-DVVA11Ah.js","assets/DiffTab-D9EMDOWs.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as fe,r as a,j as e,X as Xe,B as z,S as Fa,a as rr,b as B,d as or,g as ir,e as lr,I as Ge,C as As,f as dr,h as cr,F as ur,i as Ia,k as Ms,l as ye,D as Ls,m as mr,n as xr,t as ae,o as _e,p as Ee,q as Ie,s as De,u as lt,v as Je,T as hr,w as fr,x as na,y as pr,z as Mt,A as Lt,E as Pt,G as za,H as Ua,J as vs,K as dt,L as gr,M as Va,N as Ha,P as br,O as Ka,Q as ls,R as Ve,U as vr,V as ds,W as ct,Y as ut,Z as mt,_ as xt,$ as ht,a0 as ft,a1 as pt,a2 as gt,a3 as Bt,a4 as jr,a5 as qa,a6 as Wa,a7 as Nr,a8 as ra,a9 as oa,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 Ga,ak as Qa,al as Ya,am as Tr,an as Vs,ao as Rt,ap as Ar,aq as Mr,ar as Lr,as as Xa,at as bt,au as Pr,av as ia,aw as Br,ax as Rr,ay as $r,az as Or,aA as la,aB as Fr,aC as Ir,aD as st,aE as zr,aF as da,aG as Ur,aH as Vr,aI as Hr,aJ as ca,aK as Kr,aL as vt,aM as qr,aN as Wr,aO as Gr,aP as ua,aQ as Ja,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-DJQVK04P.js";import{r as ma,e as wo,b as Za,t as en,A as $t,L as xe,g as sn,a as yo,c as ko,d as xa,f as ha,h as So,i as Co,C as fa,T as tt,D as bs,I as qe,M as jt,j as tn,k as _o,m as an,l as Nt,n as Eo,o as pa,p as Do,q as To,s as at,u as Ao,v as Mo,w as Lo}from"./DashboardShared-DfFmE9OZ.js";import{P as Ot}from"./play-DVVA11Ah.js";/**
|
|
3
3
|
* @license lucide-react v1.7.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -131,4 +131,4 @@ import{c as fe,r as a,j as e,X as Xe,B as z,S as Fa,a as rr,b as B,d as or,g as
|
|
|
131
131
|
* See the LICENSE file in the root directory of this source tree.
|
|
132
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=fe("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 Ss(s){return(s==null?void 0:s.toLowerCase())==="devtunnel"}function Ni(s){return s?Ss(s)?"DevTunnel":s.charAt(0).toUpperCase()+s.slice(1):"Direct"}function Vt(s,t){return Ss(t??s.transportType)||!!s.devtunnelEndpoint}function ln(s,t){return!Ss(t??s.transportType)}function dn(s,t){const n=t??s.transportType;return Ss(n)?"DevTunnel":s.devtunnelEndpoint?"Direct + DevTunnel":Ni(n)}function va(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 cn(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 un(){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 ma(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 ma(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"?sn(s.value):s.value}function ja(s){switch(s.toLowerCase()){case"branch":return wt;case"node":return Fa;case"working dir":default:return Ft}}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}=un(),p=a.useCallback(()=>{v.current&&(v.current.style.height="auto")},[]),k=a.useCallback(()=>{const E=Za(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?ja(U.primary.label):Ft,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:en(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(Xe,{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=ja(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($t,{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(kt,{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(xe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(on,{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",mn=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())}}));mn.displayName=Bi;var xn=mn;const Ri=or("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),$e=a.forwardRef(({className:s,...t},n)=>e.jsx(xn,{ref:n,className:B(Ri(),s),...t}));$e.displayName=xn.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 Na({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(""),[ue,ne]=a.useState(!1),se=a.useRef(null),Z=a.useRef(0),H=a.useMemo(()=>$i(o,r,i),[o,r,i]),K=H==null?void 0:H.id,oe=a.useMemo(()=>Oi(n),[n]),he=a.useMemo(()=>K?`${K}
|
|
133
133
|
${oe}`:"",[K,oe]),h=a.useCallback(async(W=0,le=!1)=>{const ie=Z.current+1,Te=he;if(Z.current=ie,!K){x(null),c("");return}U(null),le||c(""),le?L(!0):k(!0);try{const D=await ir(K,{path:oe,limit:20,offset:W,allowAbsolute:!0});if(ie!==Z.current)return;c(Te),x(Q=>le&&Q?{...D,branches:[...Q.branches,...D.branches]}:D)}catch(D){if(ie!==Z.current)return;U(D instanceof Error?D.message:"Failed to load branch info"),le||(x(null),c(""))}finally{ie===Z.current&&(k(!1),L(!1))}},[K,he,oe]);a.useEffect(()=>{if(!K){Z.current+=1,x(null),c(""),U(null);return}h()},[K,oe,h]),a.useEffect(()=>{const W=s.trim(),le=j===he?S:null,ie=le!=null&&le.available&&le.currentBranch?le.currentBranch:"";W!==ie&&t(ie)},[S,he,j,t,s]),a.useEffect(()=>{if(!u)return;const W=ie=>{se.current&&(se.current.contains(ie.target)||w(!1))},le=ie=>{ie.key==="Escape"&&w(!1)};return document.addEventListener("mousedown",W),document.addEventListener("keydown",le),()=>{document.removeEventListener("mousedown",W),document.removeEventListener("keydown",le)}},[u]),a.useEffect(()=>{u&&(J(""),X(""),ne(!1))},[u,K,oe]);const I=a.useCallback(async()=>{if(!K)return;const W=M.trim(),le=ue?V.trim():E.trim();if(!(!W||!le)){T(!0),U(null);try{const ie=await lr(K,{path:oe,branchName:W,startPoint:le,limit:20,offset:0,allowAbsolute:!0}),Te=await zi(ie);c(he),x(Te),t(Te.currentBranch??Te.createdBranch),P(""),J(""),X(""),ne(!1),w(!1)}catch(ie){U(ie instanceof Error?ie.message:"Failed to create branch")}finally{T(!1)}}},[K,he,oe,ue,V,M,t,E]),C=j===he?S:null,te=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"),$=ue?V.trim():E.trim(),q=!!(C!=null&&C.available&&M.trim()&&$&&!O),re=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(xe,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(wt,{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:se,children:[g==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{className:"text-sm font-medium",children:"Branch"}),re]}):re,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(wt,{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(xe,{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(xe,{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(Ge,{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(xe,{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"}),!ue&&e.jsxs("button",{type:"button",onClick:()=>ne(!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(ks,{className:"h-2.5 w-2.5"}),"Manual"]})]}),ue?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ge,{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:()=>{ne(!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(Xe,{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 le=E===W.ref,ie=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",le&&"bg-background/70"),title:W.ref,children:[e.jsx("span",{className:B("shrink-0 text-[10px]",ie?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:ie?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:W.ref}),le?e.jsx(As,{className:"h-3 w-3 shrink-0 text-primary"}):null]},W.ref)}),C.hasMore&&e.jsxs("button",{type:"button",onClick:te,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(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(yt,{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,St="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 Ct(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 Ct(n?[n,...s]:s)}function hn(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=Ct(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 fn(s){if(!s||typeof window>"u")return"";try{const t=window.localStorage.getItem(St);return t?Gi(hn(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,ue=a.useMemo(()=>X?P[X]??[]:[],[P,X]),ne=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(St);if(!m)return;const $=JSON.parse(m);E(hn($))}catch{}},[]);const se=a.useCallback(m=>{X&&E($=>{const q=Wi($,X,m);if(q===$)return $;if(typeof window<"u")try{window.localStorage.setItem(St,JSON.stringify(q))}catch{}return q})},[X]),Z=a.useCallback((m,$=!0)=>{const q=m.trim();t(q),$&&q&&se(q),S(!1)},[t,se]),H=a.useCallback(async(m,$=0,q=!1)=>{if(X){O(null),q?A(!0):p(!0);try{const re=await cr(X,{path:m,limit:Ui,offset:$,directoriesOnly:!0,allowAbsolute:!0});j(W=>q&&W?{...re,entries:[...W.entries,...re.entries]}:re)}catch(re){O(re instanceof Error?re.message:"Failed to browse directories"),q||j(null)}finally{p(!1),A(!1)}}},[X]),K=a.useRef(s);K.current=s;const oe=a.useRef(H);oe.current=H,a.useEffect(()=>{if(!w)return;const m=K.current;F(m),M(!1),j(null),O(null),X&&oe.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 he=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:ne,"aria-label":`Working directory: ${ne}`,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:ne})]}):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:ne,children:[e.jsx("span",{className:B("truncate",s.trim()?"font-mono text-foreground":"text-muted-foreground"),children:ne}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:V?V.name:"Manual"})]}),C=Xi(x,V),te=!!(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($e,{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:[ue.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(yt,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:ue.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)&&he(x.parentPath),disabled:!te||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(xe,{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(Ia,{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:()=>he(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(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(yt,{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(Ge,{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(Xe,{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(ks,{className:"h-3 w-3"})]})})]})]})}function pn(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 Ht({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 _t(s,t){return s.map(n=>{const o=!!t&&n.id===t;return e.jsx(ye,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Ht,{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(ye,{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 wa(s){if(!s.updatedAt)return 0;const t=Date.parse(s.updatedAt);return Number.isNaN(t)?0:t}function sl(s,t){return wa(t)-wa(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(()=>pn(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,ue]=a.useState([]),[ne,se]=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?(se(!0),H(null),mr(T,{agent:x,limit:50}).then(Q=>{D||ue(Q.sessions)}).catch(Q=>{D||(ue([]),H(Q instanceof Error?Q.message:"Failed to load native sessions"))}).finally(()=>{D||se(!1)}),()=>{D=!0}):(ue([]),H(null),se(!1),()=>{D=!0})},[x,T]),a.useEffect(()=>{K&&(A(K.sessionId),O(K.cwd))},[K]);const oe=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 pe=await xr(Q);r(pe)}catch(pe){ae.error(pe instanceof Error?pe.message:"Failed to load native session")}finally{V(!1)}}},[w,K,x,k,L,T,U,P,r]),he=!!(k.trim()&&L.trim()&&T),[h,I]=a.useState(!1),[C,te]=a.useState(""),[m,$]=a.useState(()=>new Set),q=l.find(D=>D.id===T)??null,re=!!(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]),le=a.useMemo(()=>al(W),[W]),ie=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:oe,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(Ht,{isCurrent:re}),e.jsx("span",{className:"max-w-[10rem] truncate",children:q.name})]}):e.jsx(Ie,{placeholder:"Node"})}),e.jsx(De,{children:_t(l,n)})]}),e.jsxs(_e,{value:x,onValueChange:D=>j(D),children:[e.jsxs(Ee,{className:B(Te),"aria-label":"Agent",children:[e.jsx($t,{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(lt,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(Ge,{value:C,onChange:D=>te(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($e,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:ne?"Loading...":`${W.length} session${W.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-lg",children:[ne&&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&&!ne&&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."}),le.map(D=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>ie(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(Je,{className:B("h-3.5 w-3.5 shrink-0 transition-transform",m.has(D.cwd)&&"-rotate-90")}),e.jsx(Ft,{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 pe=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",pe?"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",pe?"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(Je,{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($e,{htmlFor:"native-session-id",className:"text-xs font-medium text-muted-foreground",children:"Session ID"}),e.jsx(Ge,{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($e,{htmlFor:"native-session-title",className:"text-xs font-medium text-muted-foreground",children:"Task title"}),e.jsx(Ge,{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($e,{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($e,{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(ye,{value:"low",children:"Low"}),e.jsx(ye,{value:"normal",children:"Normal"}),e.jsx(ye,{value:"high",children:"High"}),e.jsx(ye,{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:!he||J,className:"rounded-sm px-5",children:J?e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-4 w-4 animate-spin"})," Loading..."]}):N})]})]})}function gn(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=gn(s.title,s.description,s.images.length>0),o=s.description.trim()||n,r=s.mode??Ls,i=Za(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(na),[p,k]=a.useState(Ls),[A,L]=a.useState(""),[O,T]=a.useState(""),[F,U]=a.useState("normal"),M=a.useMemo(()=>pn(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),P=a.useMemo(()=>{var Y;return n&&M.some(je=>je.id===n)?n:((Y=M[0])==null?void 0:Y.id)??""},[M,n]),[E,J]=a.useState(P),[V,X]=a.useState(!1),[ue,ne]=a.useState(!1),{images:se,error:Z,fileInputRef:H,pickImages:K,handleFileChange:oe,handlePaste:he,removeImage:h}=un(),I=a.useMemo(()=>M.find(Y=>Y.id===E)??null,[E,M]),C=!!(n&&(I==null?void 0:I.id)===n),te=sn(j),m=ko(p);a.useEffect(()=>{E&&M.some(Y=>Y.id===E)||J(P)},[E,M,P]),a.useEffect(()=>{L(fn(E)),T("")},[E]),a.useEffect(()=>{T("")},[A]);const $=a.useCallback(async Y=>{Y.preventDefault();const je=ol({title:u,description:S,agent:j,project:A,branch:O,priority:F,assignTo:E,mode:p,images:se});if(je){X(!0);try{const ke=await pr(je);r(ke)}catch(ke){ae.error(ke instanceof Error?ke.message:"Failed to create task")}finally{X(!1)}}},[u,S,j,A,O,F,E,p,se,r]),q=gn(u,S,se.length>0),re=!!(q&&j&&E&&(S.trim()||se.length>0)),W=a.useCallback(Y=>{var je;Y.nativeEvent.isComposing||Y.key==="Enter"&&(Y.ctrlKey||Y.metaKey)&&re&&!V&&(Y.preventDefault(),(je=Y.currentTarget.form)==null||je.requestSubmit())},[re,V]),le=se.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:se.map((Y,je)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:en(Y),alt:Y.filename??`attachment ${je+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>h(je),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 ${je+1}`}`,children:e.jsx(Xe,{className:"h-3.5 w-3.5"})})]},`${Y.filename??"image"}-${je}`))}),ie=e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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:_t(M,n)})]})]}),Te=e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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:xa()})]})]}),D=e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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:ha()})]})]}),Q=e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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(ye,{value:"low",children:"Low"}),e.jsx(ye,{value:"normal",children:"Normal"}),e.jsx(ye,{value:"high",children:"High"}),e.jsx(ye,{value:"critical",children:"Critical"})]})]})]}),pe=e.jsx(Hs,{value:A,onChange:L,assignTo:E,nodes:s,assignableNodes:M}),Ue=e.jsx(Na,{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:oe,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",je="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",ke="border-border/70 bg-background/55 text-foreground",Qe=j===na,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,ke,"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(Ht,{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:_t(M,n)})]}),ue?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ge,{id:"task-title-composer",type:"text",value:u,onChange:Ne=>w(Ne.target.value),onKeyDown:Ne=>{(Ne.key==="Enter"||Ne.key==="Escape")&&(Ne.preventDefault(),ne(!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:()=>ne(!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:()=>ne(!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(ks,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:S,onChange:Ne=>x(Ne.target.value),onKeyDown:W,onPaste:he,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(kt,{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",Qe?je:ke),title:`Agent: ${te}`,"aria-label":`Agent: ${te}`,children:[e.jsx($t,{agent:j}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:te})]}),e.jsx(De,{children:xa()})]}),e.jsxs(_e,{value:p,onValueChange:Ne=>k(Ne),children:[e.jsxs(Ee,{className:B(Y,"chat-composer__icon-trigger",Be?je:ke),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:ha()})]}),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(ye,{value:"low",children:"Low"}),e.jsx(ye,{value:"normal",children:"Normal"}),e.jsx(ye,{value:"high",children:"High"}),e.jsx(ye,{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(Xe,{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:!re||V,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[V?e.jsx(xe,{className:"h-4 w-4 animate-spin"}):e.jsx(on,{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 Ne="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{value:A,onChange:L,assignTo:E,nodes:s,assignableNodes:M,layout:"composer",chipClassName:Y,chipActiveClassName:Ne,chipInactiveClassName:Ne,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(Na,{value:O,onChange:T,project:A,assignTo:E,nodes:s,assignableNodes:M,layout:"composer",chipClassName:Y,chipActiveClassName:Ne,chipInactiveClassName:Ne,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(le||Z)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 bg-background/45 p-4",children:[le,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:oe,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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:he,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(kt,{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."})]}),le,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($e,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(Ge,{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]}),pe,Ue,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[Q,ie]}),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:!re||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(It,{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 js="72f988bf-86f1-41af-91ab-2d7cd011db47",bn=`${js} (MSIT)`;function dl({open:s,onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i=!1,shareResult:g}){return e.jsx(Mt,{open:s,onOpenChange:t,children:e.jsxs(Lt,{className:"max-w-md rounded-xl p-5",children:[e.jsx(Pt,{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)??js),[N,v]=a.useState((i==null?void 0:i.scope)??"chat"),f=i!=null&&i.url?za(i.url):null,l=o||r;return a.useEffect(()=>{b((i==null?void 0:i.tenant)??js),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(ya,{active:N==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>v("chat")}),e.jsx(ya,{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 vs(f,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ua,{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(xe,{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(xe,{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(Je,{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(js),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:bn}),s===js&&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(Xe,{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(ks,{className:"h-3 w-3"})]})})]})]})]})}function ml(s){return s===js?bn:s}function ya({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(Xe,{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 nt(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=nt(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=nt(j))},[]),w=a.useCallback(x=>{const j=x.currentTarget,c=N.current;if(l(),!b.current){if(nt(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 vn(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 Kt="h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",Ns="h-3.5 w-3.5",bl=a.lazy(async()=>({default:(await Bt(()=>import("./FilesTab-Dk8SrJcE.js"),__vite__mapDeps([0,1,2,3,4]))).FilesTab})),vl=a.lazy(async()=>({default:(await Bt(()=>import("./PreviewTab-nzxEnO7P.js"),__vite__mapDeps([5,1,2,6]))).PreviewTab})),jl=a.lazy(async()=>({default:(await Bt(()=>import("./DiffTab-W3q-F9LR.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:ue,onStopShareTask:ne,onStartCreateTask:se,onCancelCreateTask:Z,onCreateTask:H,onSendMessage:K,onCancelQueuedMessage:oe,onQuestionBypassChange:he,onSubmitQuestionResponse:h}){const[I,C]=a.useState(!1),[te,m]=a.useState(!1),[$,q]=a.useState(!1),[re,W]=a.useState(!1),[le,ie]=a.useState(!1),[Te,D]=a.useState({}),[Q,pe]=a.useState(new Set),[Ue,Y]=a.useState(new Set),je=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",ke=l?(u==null?void 0:u.name)??dt(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",Qe=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:ke}),"..."]}):"Connecting session to an available node...",Be=l?[{label:"Working dir",value:je,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:ke}]:[],Ne=!!(p&&!c),We=Ne||j.length>0,Se=F&&We,Ae=(U||M||F)&&!Se,Ye=(l==null?void 0:l.conversationKind)==="nativeSession",us=S?"Loading transcript":Ye?"No transcript imported":"Transcript is warming up",Ze=S?"Loading transcript...":Ye?"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.",ss=(l==null?void 0:l.queuedMessages)??[],ts=a.useMemo(()=>So(j),[j]),ms=a.useMemo(()=>Co("transcript",ts.map(ee=>ee.event)),[ts]),Oe=l&&!Q.has(l.id)?Te[l.id]??l.activeShare??null:null,as=(l==null?void 0:l.id)??null,Me=`${as??"none"}:${j.length}:${ss.length}:${Ne?1:0}:${S?1:0}`,{handleTranscriptScroll:ns,handleTranscriptTabChange:xs,transcriptScrollRef:hs}=gl({activeTab:b,activeTaskId:as,contentVersion:Me,setActiveTab:N,setInputCollapsed:C}),{markScrollbarActive:fs,scrollbarActive:_}=vn(),be=a.useCallback(ee=>{fs(),ns(ee)},[ns,fs]);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(Et,{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(xe,{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(xe,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(Va,{value:b,onValueChange:xs,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(jn,{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(Ha,{status:l.status,isNative:Ye}),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",Kt),children:o?e.jsx(Ut,{className:Ns}):e.jsx(rn,{className:Ns})})]}),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(Ka,{className:"h-auto max-w-full overflow-x-auto rounded-sm bg-muted/70 p-0.5",children:[e.jsx(ls,{value:"transcript",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Transcript"}),e.jsx(ls,{value:"files",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Files"}),e.jsx(ls,{value:"preview",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Preview"}),e.jsx(ls,{value:"diff",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Diff"})]}),A&&e.jsx(Ve,{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(ga,{className:"h-3.5 w-3.5"}),"Retry"]}),Ye&&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(ga,{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(ds,{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:hs,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",_&&"scrollbar-line-active"),onScroll:be,children:e.jsxs("div",{className:"mx-auto flex max-w-[72rem] flex-col gap-5",children:[Ne&&p&&e.jsx(fa,{event:p,agent:l.agent,questionBypassEnabled:T,onQuestionBypassChange:he,onSubmitQuestionResponse:h,questionResponseDisabled:!k||L}),ts.map(({event:ee,subItems:ve},Ce)=>e.jsx(fa,{event:ee,agent:l.agent,subItems:ve,questionBypassEnabled:T,onQuestionBypassChange:he,onSubmitQuestionResponse:h,questionResponseDisabled:!k||L},ms[Ce])),!We&&!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:us}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Ze})]}),(!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&&!Ue.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(ee=>new Set(ee).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(Xe,{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(ka,{children:Qe}),Se&&e.jsx(ka,{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(ks,{className:"h-4 w-4"})}),e.jsxs("div",{className:`shrink-0 ${I?"hidden":""}`,children:[e.jsx(hl,{messages:ss,onCancelMessage:oe}),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(ds,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(tt,{label:"Loading files..."}),children:e.jsx(bl,{taskId:l.id})})}),e.jsx(ds,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(tt,{label:"Loading preview..."}),children:e.jsx(vl,{taskId:l.id})})}),e.jsx(ds,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(tt,{label:"Loading diff..."}),children:e.jsx(jl,{taskId:l.id})})}),e.jsx(ct,{open:te,onOpenChange:m,children:e.jsxs(ut,{children:[e.jsxs(mt,{children:[e.jsx(xt,{children:"Stop this task?"}),e.jsx(ht,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ft,{children:[e.jsx(pt,{children:"Keep running"}),e.jsx(gt,{onClick:V,children:"Stop task"})]})]})}),e.jsx(dl,{open:$,onOpenChange:q,sharing:re,stopping:le,shareResult:Oe,onShare:async ee=>{if(!l)return null;W(!0);try{const ve=await ue(ee);return ve!=null&&ve.url&&(D(Ce=>({...Ce,[l.id]:ve})),pe(Ce=>{const rs=new Set(Ce);return rs.delete(l.id),rs})),ve}finally{W(!1)}},onStopShare:async()=>{if(!l)return!1;ie(!0);try{const ee=await ne();return ee!==!1&&(D(ve=>{const Ce={...ve};return delete Ce[l.id],Ce}),pe(ve=>new Set(ve).add(l.id))),ee}finally{ie(!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(Et,{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:se,className:"mt-6 rounded-lg px-5",children:[e.jsx(zt,{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 ka({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:zt},{value:"native",label:"Load session",icon:It}].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(Et,{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 Et({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(jn,{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:Kt,children:o?e.jsx(Ut,{className:Ns}):e.jsx(rn,{className:Ns})})]})}function jn({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:Kt,children:o?e.jsx(nn,{className:Ns}):e.jsx(ni,{className:Ns})})}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(Lt,{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(qa,{className:"space-y-2 text-left",children:[e.jsx(Pt,{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($e,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Ve,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(Ge,{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(Wa,{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(Mt,{open:s,onOpenChange:t,children:e.jsx(yl,{onAdded:()=>{t(!1),n()}})})}function rt({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(rt,{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(rt,{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(rt,{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,cs="__all__";function He(s){return"session"in s}function Sa(s,t){var n;return t&&s.some(o=>o.id===t)?t:((n=s[0])==null?void 0:n.id)??""}function ot(s){return s&&(fn(s.id)||s.workDir)||""}function Fs(s,t,n){let o=!1;const r=s.map(i=>He(i)&&i.session.id===n.id?(o=!0,{...i,nodeName:t,session:n}):i);return Dt(o?r:[...r,{id:`session-${n.id}`,nodeName:t,session:n}])}function Nn(s,t){return s.filter(He).filter(n=>n.session.nodeId===t).sort((n,o)=>o.session.startedAt-n.session.startedAt)}function _l(s){const t=s.filter(He).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===cs)return n;const o=Nn(s,t);return o.some(i=>i.session.id===n)?n:((r=o[0])==null?void 0:r.session.id)??cs}function Tl(s,t,n){return n===cs?s.filter(o=>!He(o)||o.session.nodeId===t):s.filter(o=>He(o)&&o.session.nodeId===t&&o.session.id===n)}function Dt(s){const t=s.map((o,r)=>({entry:o,index:r})).filter(({entry:o})=>He(o)&&o.session.status!=="running").sort((o,r)=>!He(o.entry)||!He(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})=>He(o)?o.session.id:""));return s.filter(o=>!He(o)||o.session.status==="running"||n.has(o.session.id))}function Tt(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} - ${Tt(s.session)} - ${t}`}function wn(s,t=48){return s.length>t?`${s.slice(0,t-3)}...`:s}function Ml(s,t){return t===cs?"All sessions":s?wn(s.session.command,34):"Command session"}function Ca(s){return s.status==="stopped"?"":s.stderr}function Ll({nodes:s,defaultNodeId:t,onClose:n,initialHistory:o=[]}){const[r,i]=a.useState(()=>Sa(s,t)),g=a.useMemo(()=>s.find(h=>h.id===r)??s[0]??null,[s,r]),[b,N]=a.useState(()=>ot(g)),[v,f]=a.useState(""),[l,u]=a.useState(()=>Dt(o)),[w,S]=a.useState(cs),[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(()=>Nn(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]),ue=a.useRef((P==null?void 0:P.id)??"");a.useEffect(()=>{r&&s.some(h=>h.id===r)||i(Sa(s,t))},[t,s,r]),a.useEffect(()=>{const h=(P==null?void 0:P.id)??"";ue.current!==h&&(ue.current=h,N(ot(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 te=>({node:te,response:await wr(te.id)})));h||u(te=>C.reduce((m,$)=>$.status!=="fulfilled"?m:$.value.response.sessions.reduce((q,re)=>Fs(q,$.value.node.name,re),m),te))}return s.length>0&&I(),()=>{h=!0}},[s]),a.useEffect(()=>{const h=l.filter(He).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(te=>u(m=>Fs(m,C.nodeName,te))).catch(()=>{})},1e3);return()=>window.clearInterval(I)},[l]);const ne=a.useRef(null);async function se(h){if(h.preventDefault(),!P||!v.trim()||T)return;const I=v.trim(),C=P.name;F(!0),f("");try{const te=await kr(P.id,{command:I,...b.trim()?{cwd:b.trim()}:{}});u(m=>Fs(m,C,te)),S(te.id),j(!0)}catch(te){u(m=>[...m,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:C,command:I,error:te instanceof Error?te.message:"Command failed"}])}finally{F(!1)}}async function Z(h,I){h.stopPropagation();const C=await yr(I.session.nodeId,I.session.id);u(te=>Fs(te,I.nodeName,C))}function H(h){S(h),j(!0),p(!1)}function K(h){c&&El(M.current,h.target)&&p(!1)}function oe(h,I,C,te,m){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:te,"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(Je,{className:B("h-3 w-3 transition-transform",C&&"-rotate-90")})]}),!C&&(I.length>0?I.map(he):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:m}))]})}function he(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(xe,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(oa,{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:wn(h.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[h.nodeName," · ",Tt(h.session)]})]})]}),C&&e.jsx("button",{type:"button",onClick:te=>void Z(te,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(ba,{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(Xe,{className:"h-3.5 w-3.5"})}):e.jsx(ra,{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(Je,{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(cs),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===cs&&"bg-primary/10 text-primary"),children:[e.jsx(ra,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),oe("Active",J.active,k,()=>A(h=>!h),"No active sessions"),oe("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(ot(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=ne.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=>He(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(xe,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(oa,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"}),Tt(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(ba,{className:"h-3 w-3"})})]}),h.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:h.session.stdout}),Ca(h.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Ca(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:se,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:ne,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(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(Ot,{className:"h-3 w-3"})})]})]})]})})}function qt({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(xe,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(Ot,{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 ws(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 ys(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)&&ws(n)}function _a(s,t){return s==="offline"&&ws(t)}function Ea(s){return!ws(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(!ws(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 ne,se,Z;const F=((ne=s==null?void 0:s.self)==null?void 0:ne.role)==="leader",U=((se=s==null?void 0:s.self)==null?void 0:se.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,ue=(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(Va,{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(Ut,{className:"h-3.5 w-3.5"})})]}),e.jsxs(Ka,{className:"mt-1.5 grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(ls,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(ls,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(ls,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})]}),e.jsx(ds,{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(Da,{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(Ve,{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(xe,{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(bs,{label:"Term",value:String((s==null?void 0:s.term)??0)}),e.jsx(bs,{label:"Nodes",value:String((s==null?void 0:s.nodes.length)??0)}),e.jsx(bs,{label:"Pending",value:String((s==null?void 0:s.taskSummary.pending)??0)}),e.jsx(bs,{label:"Running",value:String((s==null?void 0:s.taskSummary.running)??0)}),e.jsx(bs,{label:"Completed",value:String((s==null?void 0:s.taskSummary.completed)??0)}),e.jsx(bs,{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 vs(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(xe,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(ds,{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"}):ue?e.jsxs(z,{variant:"outline",size:"sm",onClick:x,disabled:S,className:"h-6 rounded-sm px-2 text-[10px]",children:[S&&e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),M&&e.jsx(Da,{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(ds,{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(ye,{value:H,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:H==="all"?"All event types":H},H))})]}),e.jsx(Ve,{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 Da({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=dn(s,t==null?void 0:t.transportType),k=Vt(s,t==null?void 0:t.transportType),A=k&&Ss((t==null?void 0:t.transportType)??s.transportType)?!0:ln(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(Je,{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(Ga,{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(Qa,{className:"h-3 w-3"})}),b&&e.jsx(qt,{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)||ys((F=s.devbox)==null?void 0:F.lastStatus)||l.has(s.id),startDevBoxPending:f===s.id||ys((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(Ya,{role:s.role,size:"compact"}),e.jsx(Ve,{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 vs(S,"Dashboard URL copied")})}),e.jsx(qe,{label:"Node URL",value:x,mono:!0,action:e.jsx(Ps,{label:"Copy node URL",onClick:()=>void vs(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(jt,{label:"Transport",value:p}),t&&e.jsx(jt,{label:"Uptime",value:Tr(t.uptime),mono:!0})]}),e.jsx(tn,{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(xe,{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=dn(s),j=Vt(s),c=ln(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(Je,{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(Ga,{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(Qa,{className:"h-3 w-3"})}),t&&i&&e.jsx(qt,{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)||ys((L=s.devbox)==null?void 0:L.lastStatus)||v.has(s.id),startDevBoxPending:N===s.id||ys((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(Ya,{role:s.role,size:"compact"}),e.jsx(Ve,{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 vs(u,"Dashboard URL copied")})}),e.jsx(qe,{label:"Node URL",value:w,mono:!0,action:e.jsx(Ps,{label:"Copy node URL",onClick:()=>void vs(w,"Node URL copied")})}),s.workDir&&e.jsx(qe,{label:"Workspace",value:s.workDir,mono:!0}),e.jsx(jt,{label:"Transport",value:x})]}),e.jsx(tn,{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(xe,{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(Ua,{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 yn="meshy-task-sidebar-tree-state";function Ta(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"):[]}function it(){var s;try{return((s=globalThis.window)==null?void 0:s.localStorage)??globalThis.localStorage??null}catch{return null}}function Aa(s){if(!s)return{collapsedNodes:[],collapsedDirs:[]};try{const t=s.getItem(yn);if(!t)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(t);return{collapsedNodes:Ta(n.collapsedNodes),collapsedDirs:Ta(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Ul(s,t){if(s)try{s.setItem(yn,JSON.stringify(t))}catch{}}function Ma(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 La(s,t,n){return n?{collapsedNodes:Ma(s,n.nodeKey),collapsedDirs:Ma(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,Rt)).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 Pa({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:ue,onCreateTask:ne,onOpenNodeSettings:se,onOpenDevBox:Z,onStartDevBox:H,onLoadCompletedTasks:K,onSelectTask:oe,onClose:he}){const[h,I]=a.useState(!!k),[C,te]=a.useState(!1),[m,$]=a.useState(!1),q=a.useRef(null),re=a.useRef(null),W=a.useRef(null),[le,ie]=a.useState(()=>A.size>0),{markScrollbarActive:Te,scrollbarActive:D}=vn(),Q=A.size,pe=!!(r&&(le||Q>0)),Ue=i!=="active"||b!=="all"||g!=="all"||N!=="all",Y=k.trim().length>0,[je,ke]=a.useState(()=>new Set(Aa(it()).collapsedNodes)),[Qe,Be]=a.useState(()=>new Set(Aa(it()).collapsedDirs)),[Ne,We]=a.useState(new Set),Se=a.useMemo(()=>Ar(s,l,p,u),[s,l,p,u]),Ae=a.useMemo(()=>Vl(Se,t),[Se,t]),Ye=a.useRef(null),us=Se.length===1,Ze=Se.length>0,ss=us&&(Ue||Y),ts=!!(r&&(Se.length>0||Q>0)),ms=a.useCallback(_=>{ke(be=>{const ee=new Set(be);return ee.has(_)?ee.delete(_):ee.add(_),ee})},[]),Oe=a.useCallback(_=>{Be(be=>{const ee=new Set(be);return ee.has(_)?ee.delete(_):ee.add(_),ee})},[]),as=a.useCallback(_=>{We(be=>{const ee=new Set(be);return ee.add(_),ee})},[]);a.useEffect(()=>{Ul(it(),{collapsedNodes:Array.from(je),collapsedDirs:Array.from(Qe)})},[Qe,je]),a.useEffect(()=>{if(!Ae||!t)return;const _=`${t}:${Ae.nodeKey}:${Ae.dirKey}`;Ye.current!==_&&(Ye.current=_,ke(be=>La(be,new Set,Ae).collapsedNodes),Be(be=>La(new Set,be,Ae).collapsedDirs))},[t,Ae]);const Me=a.useCallback(_=>{ie(!0),V(_)},[V]),ns=a.useCallback(()=>{V(!1),ie(!1)},[V]);a.useEffect(()=>{r||ie(!1)},[r]),a.useEffect(()=>{k&&I(!0)},[k]),a.useEffect(()=>{var _;h&&((_=q.current)==null||_.focus())},[h]),a.useEffect(()=>{if(!h)return;const _=ee=>{var Ce;const ve=ee.target;ve instanceof Node&&((Ce=re.current)!=null&&Ce.contains(ve)||I(!1))},be=ee=>{ee.key==="Escape"&&I(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",be),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",be)}},[h]),a.useEffect(()=>{if(!m)return;const _=ee=>{var Ce;const ve=ee.target;ve instanceof Node&&((Ce=W.current)!=null&&Ce.contains(ve)||$(!1))},be=ee=>{ee.key==="Escape"&&$(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",be),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",be)}},[m]);const xs=pe?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(bt,{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:()=>ie(!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"]}),hs=Q>0?e.jsxs("div",{className:"min-w-0 flex-1 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."})]}):null,fs=Q>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(ct,{children:[e.jsx(ia,{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(ut,{children:[e.jsxs(mt,{children:[e.jsxs(xt,{children:["Archive ",Q," task",Q!==1?"s":"","?"]}),e.jsx(ht,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(ft,{children:[e.jsx(pt,{children:"Cancel"}),e.jsx(gt,{onClick:X,disabled:!T,children:"Archive"})]})]})]}),e.jsxs(ct,{children:[e.jsx(ia,{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(ut,{children:[e.jsxs(mt,{children:[e.jsxs(xt,{children:["Delete ",Q," task",Q!==1?"s":"","?"]}),e.jsx(ht,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(ft,{children:[e.jsx(pt,{children:"Cancel"}),e.jsx(gt,{onClick:ue,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return 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:he,className:"h-6 w-6 rounded-sm",children:e.jsx(nn,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{ref:re,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),ne("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(zt,{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(Je,{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),ne("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(It,{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(lt,{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(Ge,{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(lt,{className:"h-3.5 w-3.5"}),"Search"]}),e.jsx(z,{variant:C||Ue?"secondary":"outline",size:"icon",onClick:()=>te(_=>!_),className:B("h-8 w-8 shrink-0 rounded-sm border-border/70 bg-background/68 shadow-none",Ue&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(Ho,{className:"h-3.5 w-3.5"})})]})]}),(C||Ue)&&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(ye,{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(ye,{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(ye,{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(ye,{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:Se.length>0?e.jsx("div",{className:"space-y-1",children:Se.map(_=>{const be=_.nodeId??"__unassigned__",ee=_.dirs.reduce((Ke,we)=>Ke+we.tasks.length,0),ve=Ze&&!ss&&je.has(be),Ce=_.nodeId!==null&&w.get(_.nodeId)==="offline",rs=!!(r&&_.nodeId&&se);return e.jsxs("div",{className:"space-y-1",children:[Ze&&e.jsxs("div",{className:"flex w-full items-stretch rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 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:()=>ms(be),"aria-expanded":!ve,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(Ms,{className:B("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!ve&&"rotate-90")}),e.jsx(Fa,{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(Ve,{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:[ee," task",ee===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[Ce&&e.jsx(Ve,{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(Ve,{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"})]})]}),rs&&_.nodeId&&se&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(qt,{nodeId:_.nodeId,nodeName:_.nodeName,onOpenSettings:se,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",ve?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:_.dirs.map(Ke=>{const we=`${be}::${Ke.path}`,os=Qe.has(we),is=Xa(Ke.path),Le=S==null?void 0:S.get(we),qs=Le?{visibleTasks:Ke.tasks,hiddenCompletedCount:Math.max(0,Le.total-Le.returned)}:Hl(Ke.tasks,Ne.has(we),t),{visibleTasks:Cs,hiddenCompletedCount:Re}=qs;return e.jsxs("div",{className:B("space-y-0.5 rounded-xl",Ze&&"pl-2.5"),children:[e.jsxs("button",{type:"button",onClick:()=>Oe(we),"aria-expanded":!os,title:Ke.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",!os&&"rotate-90")}),e.jsx(Ia,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"truncate font-mono",children:is}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/40",children:Ke.tasks.length})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-300 ease-in-out",os?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:B("overflow-hidden",Ze?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[Cs.map(me=>{const ps=me.id===t,Fe=me.assignedTo?w.get(me.assignedTo):void 0,Ws=!!me.assignedTo&&(Fe?Fe==="offline":me.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",ps?'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:[pe&&e.jsx("div",{className:"flex shrink-0",onClick:_s=>_s.stopPropagation(),children:e.jsx(bt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:A.has(me.id),onCheckedChange:_s=>J(me.id,_s===!0),"aria-label":`Select ${me.title}`})}),e.jsxs("button",{type:"button",onClick:()=>oe(me.id),"aria-current":ps?"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",ps?"text-foreground":"text-foreground/80"),children:me.title})}),e.jsx("span",{className:B("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",ps?"text-primary/75":"text-muted-foreground/55"),children:Pr(me.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:me.agent}),me.activeShare&&e.jsx(Ve,{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"}),Ws&&e.jsx(Ve,{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(Ha,{status:me.status,isNative:me.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},me.id)}),Re>0&&e.jsxs("button",{type:"button",onClick:()=>{Le&&K?K(Le):as(we)},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 ${Re} more completed tasks in ${is}`,children:[e.jsx(Je,{className:"h-3 w-3"}),"Load ",Re," more completed"]})]})})})]},we)})})})]},be)})}):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."})}),ts?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:pe&&Q>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[hs,e.jsx(z,{variant:"ghost",size:"sm",onClick:ns,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Clear"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:xs}),fs]})]}):e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:xs}),pe&&e.jsx(z,{variant:"ghost",size:"sm",onClick:ns,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]})}async function Kl(s,t){var n,o;try{const r=await Br(s,t),i={...r,url:za(r.url)};if((o=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&o.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),ae.success("Shared link copied")}catch{ae.success("Shared link created")}else ae.success("Shared link created");return i}catch(r){ae.error(r instanceof Error?r.message:"Failed to create shared link");return}}async function ql(s){try{return await Rr(s),ae.success("Shared link stopped"),!0}catch(t){return ae.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 Ba(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 Ra(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(la(),Or({operationsOpen:Ra(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(la(),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]);Ba(i,{onSwipeLeft:()=>o(!1)}),Ba(g,{onSwipeRight:()=>u(!1)});const w=a.useCallback(()=>{if(Ra(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:st(v.tasks),operations:st(v.operations),terminal:st(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:Rt}}function At(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?cn(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 da(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 da({status:"completed",assignedTo:c.assignedTo??"__unassigned__",projectPath:c.projectPath,cursor:c.nextCursor,limit:Rt});g(k=>ed(k,p.tasks)),N(k=>k.map(A=>At(A)===At(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=>{ca(p.type)&&j()}),r("task",p=>{ca(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 kn(s){return s.map(t=>({...t}))}function ad(s,t){const n=t.get(s);return{logs:n?kn(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&&ae.success(`${r} joined the cluster`),o.type==="node.left"&&!i&&ae.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 vt(s.id);if(t()!==s.id||(n(b=>an(b,g.logs)),o(b=>Nt(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 $a(s,t){return{...s,enabled:!0,alwaysOnline:t}}function Sn(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 Oa({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:Sn(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&&_a(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(()=>Ea((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||(ws(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),ue=(l==null?void 0:l.alwaysOnline)===!0!==T,ne=$l({nodeStatus:s==null?void 0:s.status,status:V,current:l,selected:U}),se=!!ne,Z=!!U&&(X||ue)&&!se,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){ae.error(m instanceof Error?m.message:"Failed to refresh DevBox status")}finally{p(!1)}}},[i]),oe=a.useCallback(async m=>{j(!0);try{const $=await Wr();N($),f(q=>Ol({previousKey:q,baseDevBox:m,listed:$}))}catch($){ae.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=Ea($),re=!n&&_a(s==null?void 0:s.status,$);j(!1),p(re),S(q),u($),F(($==null?void 0:$.alwaysOnline)===!0),f(ws($)?Pe($):""),N([]);async function W(){re&&await K(),!m&&q&&await oe($)}return W(),()=>{m=!0}},[oe,s==null?void 0:s.devbox,s==null?void 0:s.status,i,t,K,n]);async function he(){S(!0),b.length===0&&await oe(l)}async function h(){if(!(!s||!U)){A(!0);try{const m=await ua(s.id,$a(U,T));u(m.node.devbox??null),m.node.devbox&&f(Pe(m.node.devbox)),S(!1),ae.success(`Configured DevBox for ${s.name}`),await(r==null?void 0:r())}catch(m){ae.error(m instanceof Error?m.message:"Failed to configure DevBox")}finally{A(!1)}}}async function I(){if(!(!s||!ne)){O(!0);try{if(U&&(X||ue)){const $=await ua(s.id,$a(U,T));u($.node.devbox??null),$.node.devbox&&f(Pe($.node.devbox)),S(!1)}const{operation:m}=await Ja(s.id);u($=>$&&{...$,lastStatus:"Starting",checkedAt:Date.now(),operationId:m.id}),ae.success(`Start requested for ${s.name}`),await(r==null?void 0:r())}catch(m){ae.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",te=V==="Running"&&(s==null?void 0:s.status)==="offline";return e.jsx(Mt,{open:t,onOpenChange:o,children:e.jsxs(Lt,{className:"max-w-md gap-4 rounded-lg p-5",children:[e.jsxs(qa,{className:"space-y-1",children:[e.jsx(Pt,{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(xe,{className:"h-3.5 w-3.5 animate-spin"}),C]}):U?e.jsx(Oa,{devbox:U}):e.jsx(Ie,{placeholder:C})}),e.jsx(De,{children:b.map(m=>e.jsx(ye,{value:Pe(m),textValue:`${m.name} ${m.projectName??""} ${Sn(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(Oa,{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(Ve,{variant:"outline",className:"rounded-full px-2 py-0.5 text-[10px]",children:[(x||c)&&e.jsx(xe,{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:()=>{he()},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(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(ks,{className:"h-3 w-3"})})]})]}),te&&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(bt,{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(Wa,{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"}),se&&e.jsxs(z,{size:"sm",onClick:I,disabled:L,className:"h-8 rounded-xl text-xs",children:[L?e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ot,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!se&&e.jsxs(z,{size:"sm",onClick:h,disabled:!Z||k,className:"h-8 rounded-xl text-xs",children:[k&&e.jsx(xe,{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 ys((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)||ys(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 Ja(c),ae.success(`Start requested for ${p.name}`),t()}catch(k){b(A=>{const L=new Set(A);return L.delete(c),L}),ae.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)),ae.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){ae.error(v instanceof Error?v.message:"Failed to cancel queued message")}},[s,t,i]),queueFollowUpMessage:g}}function pd(){var Xt,Jt,Zt,ea,sa,ta;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:ue,panelResize:ne,setMobileTasksPanelOpen:se,setOperationsOpen:Z,toggleTasksPanel:H}=Xl(),[K,oe]=a.useState(()=>!!(u!=null&&u.draftNewTask)),[he,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),[te,m]=a.useState(!1),[$,q]=a.useState("transcript"),[re,W]=a.useState("all"),[le,ie]=a.useState(!1),[Te,D]=a.useState(null),[Q,pe]=a.useState([]),[Ue,Y]=a.useState([]),[je,ke]=a.useState(!1),[Qe,Be]=a.useState(!1),[Ne,We]=a.useState(null),[Se,Ae]=a.useState(new Set),[Ye,us]=a.useState(!1),[Ze,ss]=a.useState(!1),[ts,ms]=a.useState(null),Oe=a.useRef(null),as=a.useRef(new Map),Me=((Xt=r==null?void 0:r.self)==null?void 0:Xt.role)==="leader",ns=(Jt=r==null?void 0:r.self)==null?void 0:Jt.id;rd({cluster:r,subscribe:N});const{nodeSettingsDialog:xs,openNodeSettings:hs}=hd(Me),{devBoxDialog:fs,devBoxNodeIds:_,devBoxStartNodeId:be,devBoxStartNodeIds:ee,devBoxStartingNodeIds:ve,openDevBox:Ce,startDevBox:rs}=xd({cluster:r,refresh:v}),{completedGroups:Ke=[],fetchTasks:we,loadCompletedTasksPage:os,setTasks:is,tasks:Le,tasksError:qs,tasksLoading:Cs}=td({isLeader:Me,selfId:ns,sseConnected:b,preservedTask:Te,subscribe:N}),Re=a.useMemo(()=>[...Le].sort((d,y)=>y.updatedAt-d.updatedAt),[Le]),me=a.useMemo(()=>{var d;return((d=[...Le].sort((y,R)=>R.createdAt-y.createdAt||R.updatedAt-y.updatedAt)[0])==null?void 0:d.id)??null},[Le]),ps=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[]){const R=ji(Re,y.id);R>0&&d.set(y.id,R)}return d},[r==null?void 0:r.nodes,Re]),Fe=a.useMemo(()=>Re.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),[Re,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,Fe.map(R=>R.id));return y.size===d.size?d:y})},[Fe]),a.useEffect(()=>{Me||Ae(new Set)},[Me]);const Ws=a.useMemo(()=>["all",...Array.from(new Set(Re.map(d=>d.agent))).sort()],[Re]),_s=a.useMemo(()=>{const y=Array.from(new Set(Re.map(R=>R.assignedTo).filter(R=>!!R))).map(R=>{const ge=Re.find(de=>de.assignedTo===R);return(r==null?void 0:r.nodes.find(de=>de.id===R))??{id:R,name:dt(R,r==null?void 0:r.nodes,ge==null?void 0:ge.assignedNodeName)}}).sort((R,ge)=>R.name.localeCompare(ge.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...y.map(R=>({value:R.name.toLowerCase(),label:R.name}))]},[Re,r==null?void 0:r.nodes]),Wt=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 Re)y.assignedTo&&y.assignedNodeName&&!d.has(y.assignedTo)&&d.set(y.assignedTo,y.assignedNodeName);return d},[r==null?void 0:r.nodes,Re]),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(Ke.map(d=>[At(d),d])),[Ke]),Gt=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=((Zt=r==null?void 0:r.self)==null?void 0:Zt.id)??((ea=Gt[0])==null?void 0:ea.id)??null,Gs=a.useMemo(()=>["all",...Array.from(new Set(g.map(d=>d.type))).sort()],[g]),Tn=a.useMemo(()=>re==="all"?g:g.filter(d=>d.type===re),[g,re]),An=Fe.length>0&&Fe.every(d=>Se.has(d.id)),Mn=Fe.some(d=>Se.has(d.id)),Ln=_i(Fe,Se);a.useEffect(()=>{u!=null&&u.draftNewTask&&(oe(!0),C({route:u.returnRoute??"/",taskId:u.returnTaskId??null}))},[u]),a.useEffect(()=>{re!=="all"&&!Gs.includes(re)&&W("all")},[re,Gs]),a.useEffect(()=>{va(s,K)&&!w&&me&&S(me)},[s,K,w,me]),a.useEffect(()=>{va(s,K)&&(w&&Le.some(d=>d.id===w)||S(me))},[s,K,w,me,Le]);const ce=wi({routeTaskId:s,creatingTask:K,internalSelectedTaskId:w,sortedTaskIds:me?[me]:[]}),gs=a.useMemo(()=>Le.find(d=>d.id===ce)??null,[Le,ce]);a.useEffect(()=>{Oe.current=ce??null},[ce]);const es=a.useCallback(()=>{D(null),pe([]),Y([]),We(null),Be(!1)},[]),Es=a.useCallback((d,y,R=!0)=>{as.current.set(d,{logs:kn(y),loaded:R})},[]),ze=a.useCallback(async()=>{const d=ce;if(d)try{const y=await uo(d);if(Oe.current!==d)return;D(y),is(R=>cn(R,y)),We(null)}catch(y){if(Oe.current!==d)return;es(),We(y instanceof Error?y.message:"Failed to load task")}finally{Oe.current===d&&ke(!1)}},[ce,es,is]),Bs=a.useCallback(async()=>{const d=ce;if(d)try{const y=await vt(d);if(Oe.current!==d)return;pe(R=>{const ge=an(R,y.logs);return Es(d,ge),ge}),Y(R=>Nt(R,y.logs))}catch{}finally{Oe.current===d&&Be(!1)}},[ce,Es]);a.useEffect(()=>{if(!ce){es(),ke(!1);return}q("transcript"),D(gs);const d=ad(ce,as.current);pe(d.logs),Y([]),We(null),ke(!0),Be(d.transcriptLoading),ze(),Bs()},[ce,es,Bs,ze]),a.useEffect(()=>{if(!yi({activeTaskId:ce,routeTaskId:s,creatingTask:K,tasksLoading:Cs,loadedTaskIds:Le.map(y=>y.id)}))return;const d=me;S(d),es(),a.startTransition(()=>{n(d?`/tasks/${d}`:"/",{state:null})})},[ce,es,K,me,n,s,Le,Cs]),a.useEffect(()=>{gs&&D(d=>!d||d.id!==gs.id?d:{...d,...gs})},[gs]),a.useEffect(()=>{if(ce)return N("task",d=>{const y=d.data.taskId;if(!(typeof y!="string"||y!==ce)){if(d.type==="task.output"){const R=d.data.event;if(R){pe(de=>{const Ts=Eo(de,R);return Es(ce,Ts),Ts}),Be(!1);const ge=pa(R);ge&&Y(de=>Do(de,ge))}}d.type==="task.updated"&&ze(),d.type==="task.status"&&(ze(),Bs())}})},[N,ce,ze,Bs]);const G=Te??gs,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:dt(G.assignedTo,r==null?void 0:r.nodes,G.assignedNodeName),projectLabel:Xa(d),projectPath:d}),()=>Ds(null)},[G,r==null?void 0:r.nodes,Ds]);const Qs=Ue.length>0,Bn=G?mo.has(G.agent):!1,Ys=(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"),Xs=a.useMemo(()=>zl(G,r,Qs,!!Ys),[G,r,Qs,Ys]),Js=a.useMemo(()=>To([...Q,...Ue.map(d=>at(d.content,d.timestamp))]),[Q,Ue]),Rs=a.useMemo(()=>{if(!G||G.conversationKind==="nativeSession")return null;const d=Ao(G);if(d.length>0)return at(d,new Date(G.createdAt).toISOString());if(Js.length>0)return null;const y=Mo(G.description||G.title);return y.length>0?at(y,new Date(G.createdAt).toISOString()):null},[G,Js]),Zs=a.useMemo(()=>Rs?pa(Rs):null,[Rs]),Fn=a.useMemo(()=>Zs?Lo(Q,Zs):!1,[Q,Zs]),et=a.useCallback((d="chat")=>{const y={route:s?`/tasks/${s}`:"/",taskId:ce};C(y),h(d),oe(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:y.route,returnTaskId:y.taskId,createMode:d}})})},[s,ce,n]),In=a.useCallback(()=>{const d=(I==null?void 0:I.taskId)??me;oe(!1),C(null),S(d),a.startTransition(()=>{n((I==null?void 0:I.route)??"/",{state:null})})},[I,me,n]),Qt=a.useCallback(d=>{oe(!1),C(null),S(d),a.startTransition(()=>{n(`/tasks/${d}`,{state:null})})},[n]),zn=a.useCallback(d=>{Oe.current=d.id,oe(!1),C(null),is(y=>ki(y,d)),D(d),pe([]),Y([]),We(null),ke(!1),Be(d.conversationKind==="nativeSession"),q("transcript"),S(d.id),id({task:d,getActiveTaskId:()=>Oe.current,setLogs:pe,setPendingMessages:Y,setTranscriptLoading:Be}),we(),a.startTransition(()=>{n(`/tasks/${d.id}`,{state:null})})},[we,n]),{cancelQueuedMessage:Un,queueFollowUpMessage:$s}=fd({activeTaskId:ce,fetchActiveTask:ze,setPendingMessages:Y,setTask:D,setTasks:is}),Vn=a.useCallback(d=>{$s(d)},[$s]),Hn=a.useCallback(async()=>{const d=ce;if(!(!d||(G==null?void 0:G.conversationKind)!=="nativeSession")){Be(!0);try{const y=await vt(d);if(Oe.current!==d)return;pe(y.logs),Es(d,y.logs),Y(R=>Nt(R,y.logs))}catch(y){ae.error(y instanceof Error?y.message:"Failed to reload transcript")}finally{Oe.current===d&&Be(!1)}}},[G==null?void 0:G.conversationKind,ce,Es]),Kn=a.useCallback(d=>$s(d),[$s]),qn=a.useCallback(async()=>{if(G)try{await ho(G.id),ze(),we()}catch(d){ae.error(d instanceof Error?d.message:"Failed to cancel task")}},[G,ze,we]),{handleShareTask:Wn,handleStopShareTask:Gn}=Wl(G,ze,we),Qn=a.useCallback(async()=>{if(G)try{await fo(G.id),ze(),we()}catch(d){ae.error(d instanceof Error?d.message:"Failed to retry task")}},[G,ze,we]),Os=a.useCallback((d,y=!1)=>{const R=Ei(Fe,d);return S(R),(y||!R)&&es(),a.startTransition(()=>{n(R?`/tasks/${R}`:"/",{state:null})}),R},[es,Fe,n]),Yn=a.useCallback((d,y)=>{Ae(R=>{const ge=new Set(R);return y?ge.add(d):ge.delete(d),ge})},[]),Xn=a.useCallback(d=>{if(!d){Ae(new Set);return}Ae(new Set(Fe.map(y=>y.id)))},[Fe]),Jn=a.useCallback(async()=>{const d=Array.from(Se);if(d.length!==0)try{const{results:y}=await po(d),R=y.filter(de=>!de.ok),ge=y.filter(de=>de.ok).map(de=>de.id);ce&&ge.includes(ce)&&Os(ge),R.length>0?ae.error(`Failed to archive ${R.length} task(s): ${R.map(de=>de.error??de.id).join(", ")}`):ae.success(`Archived ${ge.length} task(s)`),Ae(new Set(R.map(de=>de.id))),we()}catch(y){ae.error(y instanceof Error?y.message:"Failed to archive tasks")}},[ce,we,Os,Se]),Zn=a.useCallback(async()=>{const d=Array.from(Se);if(d.length!==0)try{const{results:y}=await go(d),R=y.filter(de=>!de.ok),ge=y.filter(de=>de.ok).map(de=>de.id);ce&&ge.includes(ce)&&Os(ge,!0),R.length>0?ae.error(`Failed to delete ${R.length} task(s): ${R.map(de=>de.error??de.id).join(", ")}`):ae.success(`Deleted ${ge.length} task(s)`),Ae(new Set(R.map(de=>de.id))),we()}catch(y){ae.error(y instanceof Error?y.message:"Failed to delete tasks")}},[ce,we,Os,Se]),er=a.useCallback(async()=>{us(!0);try{await bo(),v()}catch(d){ae.error(d instanceof Error?d.message:"Failed to promote node")}finally{us(!1)}},[v]),sr=a.useCallback(async()=>{ss(!0);try{await vo(),ae.success("This node left the remote cluster and is leading itself again."),we(),ze(),v()}catch(d){ae.error(d instanceof Error?d.message:"Failed to leave cluster")}finally{ss(!1)}},[ze,we,v]),tr=a.useCallback(async d=>{var Ts;const y=!Vt(d),R=d.id===((Ts=r==null?void 0:r.self)==null?void 0:Ts.id),ge=R?(i==null?void 0:i.transportType)??d.transportType:d.transportType,de=R&&!y&&Ss(ge);ms(d.id);try{de?await jo("direct"):await No(d.id,y),ae.success(y?`Enabled remote access on ${d.name}`:`Disabled remote access on ${d.name}`),v()}catch(aa){ae.error(aa instanceof Error?aa.message:"Failed to update remote access")}finally{ms(null)}},[(sa=r==null?void 0:r.self)==null?void 0:sa.id,v,i==null?void 0:i.transportType]),ar=a.useCallback(d=>{os&&os(d).catch(y=>{ae.error(y instanceof Error?y.message:"Failed to load completed tasks")})},[os]),Yt={toolbarTasks:Fe,activeTaskId:ce,tasksLoading:Cs,tasksError:qs,isLeader:Me,scope:x,agentFilter:c,nodeFilter:k,taskKindFilter:L,agentOptions:Ws,nodeOptions:_s,nodeNameById:Wt,nodeWorkDirById:Cn,nodeStatusById:_n,leaderNodeId:((ta=r==null?void 0:r.leader)==null?void 0:ta.id)??null,searchQuery:U,completedGroupByKey:En,devBoxNodeIds:_,devBoxStartNodeIds:ee,devBoxStartingNodeIds:ve,selectedTaskIds:Se,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:et,onOpenNodeSettings:Me?hs:void 0,onOpenDevBox:Me?Ce:void 0,onStartDevBox:Me?rs:void 0,onLoadCompletedTasks:ar,onSelectTask:Qt,onClose:H},nr={cluster:r,systemInfo:i,nodeNameById:Wt,nodeBlockingTaskCounts:ps,eventTypeFilter:re,onEventTypeFilterChange:W,eventTypeOptions:Gs,filteredEvents:Tn,sseConnected:b,clusterLoading:f,clusterError:l,promotePending:Ye,onPromote:er,onAddNode:()=>m(!0),leavePending:Ze,onLeaveCluster:sr,onToggleNodeDevTunnel:tr,devTunnelNodeId:ts,devBoxStartNodeId:be,devBoxStartingNodeIds:ve,onOpenNodeSettings:Me?hs:void 0,onOpenDevBox:Me?Ce:void 0,onStartDevBox:Me?rs:void 0,onClose:()=>Z(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Sl,{desktopTasksOpen:E,mobileTasksPanelOpen:J,mobileTasksPanelRef:V,operationsOpen:X,operationsPanelRef:ue,panelResize:ne,taskSidebar:e.jsx(Pa,{...Yt}),operationsSidecar:e.jsx(Fl,{...nr}),terminalPanel:o!=null&&o.terminalOpen?e.jsx(Ll,{nodes:Gt,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:he,activeTask:G,assignedNode:Pn,taskLoading:je,transcriptLoading:Qe,taskError:Ne,displayEvents:Js,initialPromptAlreadyInLogs:Fn,initialPrompt:Rs,supportsFollowUp:Bn,taskUnavailable:Xs.taskUnavailable,chatDisabled:Xs.chatDisabled,chatDisabledReason:Xs.chatDisabledReason,questionBypassEnabled:le,isRunning:!!Ys,isStarting:Rn,hasPendingFollowUp:Qs,canCancel:!!$n,canRetry:!!On,onRetry:Qn,onCancel:qn,onReloadNativeTranscript:Hn,onShareTask:Wn,onStopShareTask:Gn,onStartCreateTask:et,onCancelCreateTask:In,onCreateTask:zn,onSendMessage:Vn,onCancelQueuedMessage:Un,onQuestionBypassChange:ie,onSubmitQuestionResponse:Kn}),mobileTaskSidebar:e.jsx(Pa,{...Yt,onCreateTask:d=>{se(!1),et(d)},onSelectTask:d=>{se(!1),Qt(d)},onClose:()=>se(!1)}),onCloseOperations:()=>Z(!1),onCloseTaskList:()=>se(!1)}),e.jsx(kl,{open:te,onOpenChange:m,onAdded:v}),xs,fs]})}const jd=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:pd},Symbol.toStringTag,{value:"Module"}));export{jd as D,wt as G};
|
|
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=gn(s.title,s.description,s.images.length>0),o=s.description.trim()||n,r=s.mode??Ls,i=Za(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(na),[p,k]=a.useState(Ls),[A,L]=a.useState(""),[O,T]=a.useState(""),[F,U]=a.useState("normal"),M=a.useMemo(()=>pn(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),P=a.useMemo(()=>{var Y;return n&&M.some(je=>je.id===n)?n:((Y=M[0])==null?void 0:Y.id)??""},[M,n]),[E,J]=a.useState(P),[V,X]=a.useState(!1),[ue,ne]=a.useState(!1),{images:se,error:Z,fileInputRef:H,pickImages:K,handleFileChange:oe,handlePaste:he,removeImage:h}=un(),I=a.useMemo(()=>M.find(Y=>Y.id===E)??null,[E,M]),C=!!(n&&(I==null?void 0:I.id)===n),te=sn(j),m=ko(p);a.useEffect(()=>{E&&M.some(Y=>Y.id===E)||J(P)},[E,M,P]),a.useEffect(()=>{L(fn(E)),T("")},[E]),a.useEffect(()=>{T("")},[A]);const $=a.useCallback(async Y=>{Y.preventDefault();const je=ol({title:u,description:S,agent:j,project:A,branch:O,priority:F,assignTo:E,mode:p,images:se});if(je){X(!0);try{const ke=await pr(je);r(ke)}catch(ke){ae.error(ke instanceof Error?ke.message:"Failed to create task")}finally{X(!1)}}},[u,S,j,A,O,F,E,p,se,r]),q=gn(u,S,se.length>0),re=!!(q&&j&&E&&(S.trim()||se.length>0)),W=a.useCallback(Y=>{var je;Y.nativeEvent.isComposing||Y.key==="Enter"&&(Y.ctrlKey||Y.metaKey)&&re&&!V&&(Y.preventDefault(),(je=Y.currentTarget.form)==null||je.requestSubmit())},[re,V]),le=se.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:se.map((Y,je)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:en(Y),alt:Y.filename??`attachment ${je+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>h(je),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 ${je+1}`}`,children:e.jsx(Xe,{className:"h-3.5 w-3.5"})})]},`${Y.filename??"image"}-${je}`))}),ie=e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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:_t(M,n)})]})]}),Te=e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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:xa()})]})]}),D=e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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:ha()})]})]}),Q=e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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(ye,{value:"low",children:"Low"}),e.jsx(ye,{value:"normal",children:"Normal"}),e.jsx(ye,{value:"high",children:"High"}),e.jsx(ye,{value:"critical",children:"Critical"})]})]})]}),pe=e.jsx(Hs,{value:A,onChange:L,assignTo:E,nodes:s,assignableNodes:M}),Ue=e.jsx(Na,{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:oe,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",je="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",ke="border-border/70 bg-background/55 text-foreground",Qe=j===na,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,ke,"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(Ht,{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:_t(M,n)})]}),ue?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ge,{id:"task-title-composer",type:"text",value:u,onChange:Ne=>w(Ne.target.value),onKeyDown:Ne=>{(Ne.key==="Enter"||Ne.key==="Escape")&&(Ne.preventDefault(),ne(!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:()=>ne(!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:()=>ne(!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(ks,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:S,onChange:Ne=>x(Ne.target.value),onKeyDown:W,onPaste:he,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(kt,{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",Qe?je:ke),title:`Agent: ${te}`,"aria-label":`Agent: ${te}`,children:[e.jsx($t,{agent:j}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:te})]}),e.jsx(De,{children:xa()})]}),e.jsxs(_e,{value:p,onValueChange:Ne=>k(Ne),children:[e.jsxs(Ee,{className:B(Y,"chat-composer__icon-trigger",Be?je:ke),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:ha()})]}),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(ye,{value:"low",children:"Low"}),e.jsx(ye,{value:"normal",children:"Normal"}),e.jsx(ye,{value:"high",children:"High"}),e.jsx(ye,{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(Xe,{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:!re||V,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[V?e.jsx(xe,{className:"h-4 w-4 animate-spin"}):e.jsx(on,{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 Ne="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{value:A,onChange:L,assignTo:E,nodes:s,assignableNodes:M,layout:"composer",chipClassName:Y,chipActiveClassName:Ne,chipInactiveClassName:Ne,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(Na,{value:O,onChange:T,project:A,assignTo:E,nodes:s,assignableNodes:M,layout:"composer",chipClassName:Y,chipActiveClassName:Ne,chipInactiveClassName:Ne,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(le||Z)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 bg-background/45 p-4",children:[le,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:oe,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx($e,{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:he,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(kt,{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."})]}),le,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($e,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(Ge,{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]}),pe,Ue,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[Q,ie]}),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:!re||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(It,{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 js="72f988bf-86f1-41af-91ab-2d7cd011db47",bn=`${js} (MSIT)`;function dl({open:s,onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i=!1,shareResult:g}){return e.jsx(Mt,{open:s,onOpenChange:t,children:e.jsxs(Lt,{className:"max-w-md rounded-xl p-5",children:[e.jsx(Pt,{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)??js),[N,v]=a.useState((i==null?void 0:i.scope)??"chat"),f=i!=null&&i.url?za(i.url):null,l=o||r;return a.useEffect(()=>{b((i==null?void 0:i.tenant)??js),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(ya,{active:N==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>v("chat")}),e.jsx(ya,{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 vs(f,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ua,{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(xe,{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(xe,{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(Je,{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(js),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:bn}),s===js&&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(Xe,{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(ks,{className:"h-3 w-3"})]})})]})]})]})}function ml(s){return s===js?bn:s}function ya({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(Xe,{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 nt(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=nt(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=nt(j))},[]),w=a.useCallback(x=>{const j=x.currentTarget,c=N.current;if(l(),!b.current){if(nt(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 vn(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 Kt="h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",Ns="h-3.5 w-3.5",bl=a.lazy(async()=>({default:(await Bt(()=>import("./FilesTab-UdncGsMa.js"),__vite__mapDeps([0,1,2,3,4]))).FilesTab})),vl=a.lazy(async()=>({default:(await Bt(()=>import("./PreviewTab-lu08ISli.js"),__vite__mapDeps([5,1,2,6]))).PreviewTab})),jl=a.lazy(async()=>({default:(await Bt(()=>import("./DiffTab-D9EMDOWs.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:ue,onStopShareTask:ne,onStartCreateTask:se,onCancelCreateTask:Z,onCreateTask:H,onSendMessage:K,onCancelQueuedMessage:oe,onQuestionBypassChange:he,onSubmitQuestionResponse:h}){const[I,C]=a.useState(!1),[te,m]=a.useState(!1),[$,q]=a.useState(!1),[re,W]=a.useState(!1),[le,ie]=a.useState(!1),[Te,D]=a.useState({}),[Q,pe]=a.useState(new Set),[Ue,Y]=a.useState(new Set),je=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",ke=l?(u==null?void 0:u.name)??dt(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",Qe=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:ke}),"..."]}):"Connecting session to an available node...",Be=l?[{label:"Working dir",value:je,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:ke}]:[],Ne=!!(p&&!c),We=Ne||j.length>0,Se=F&&We,Ae=(U||M||F)&&!Se,Ye=(l==null?void 0:l.conversationKind)==="nativeSession",us=S?"Loading transcript":Ye?"No transcript imported":"Transcript is warming up",Ze=S?"Loading transcript...":Ye?"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.",ss=(l==null?void 0:l.queuedMessages)??[],ts=a.useMemo(()=>So(j),[j]),ms=a.useMemo(()=>Co("transcript",ts.map(ee=>ee.event)),[ts]),Oe=l&&!Q.has(l.id)?Te[l.id]??l.activeShare??null:null,as=(l==null?void 0:l.id)??null,Me=`${as??"none"}:${j.length}:${ss.length}:${Ne?1:0}:${S?1:0}`,{handleTranscriptScroll:ns,handleTranscriptTabChange:xs,transcriptScrollRef:hs}=gl({activeTab:b,activeTaskId:as,contentVersion:Me,setActiveTab:N,setInputCollapsed:C}),{markScrollbarActive:fs,scrollbarActive:_}=vn(),be=a.useCallback(ee=>{fs(),ns(ee)},[ns,fs]);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(Et,{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(xe,{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(xe,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(Va,{value:b,onValueChange:xs,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(jn,{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(Ha,{status:l.status,isNative:Ye}),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",Kt),children:o?e.jsx(Ut,{className:Ns}):e.jsx(rn,{className:Ns})})]}),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(Ka,{className:"h-auto max-w-full overflow-x-auto rounded-sm bg-muted/70 p-0.5",children:[e.jsx(ls,{value:"transcript",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Transcript"}),e.jsx(ls,{value:"files",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Files"}),e.jsx(ls,{value:"preview",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Preview"}),e.jsx(ls,{value:"diff",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Diff"})]}),A&&e.jsx(Ve,{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(ga,{className:"h-3.5 w-3.5"}),"Retry"]}),Ye&&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(ga,{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(ds,{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:hs,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",_&&"scrollbar-line-active"),onScroll:be,children:e.jsxs("div",{className:"mx-auto flex max-w-[72rem] flex-col gap-5",children:[Ne&&p&&e.jsx(fa,{event:p,agent:l.agent,questionBypassEnabled:T,onQuestionBypassChange:he,onSubmitQuestionResponse:h,questionResponseDisabled:!k||L}),ts.map(({event:ee,subItems:ve},Ce)=>e.jsx(fa,{event:ee,agent:l.agent,subItems:ve,questionBypassEnabled:T,onQuestionBypassChange:he,onSubmitQuestionResponse:h,questionResponseDisabled:!k||L},ms[Ce])),!We&&!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:us}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Ze})]}),(!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&&!Ue.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(ee=>new Set(ee).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(Xe,{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(ka,{children:Qe}),Se&&e.jsx(ka,{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(ks,{className:"h-4 w-4"})}),e.jsxs("div",{className:`shrink-0 ${I?"hidden":""}`,children:[e.jsx(hl,{messages:ss,onCancelMessage:oe}),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(ds,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(tt,{label:"Loading files..."}),children:e.jsx(bl,{taskId:l.id})})}),e.jsx(ds,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(tt,{label:"Loading preview..."}),children:e.jsx(vl,{taskId:l.id})})}),e.jsx(ds,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(tt,{label:"Loading diff..."}),children:e.jsx(jl,{taskId:l.id})})}),e.jsx(ct,{open:te,onOpenChange:m,children:e.jsxs(ut,{children:[e.jsxs(mt,{children:[e.jsx(xt,{children:"Stop this task?"}),e.jsx(ht,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ft,{children:[e.jsx(pt,{children:"Keep running"}),e.jsx(gt,{onClick:V,children:"Stop task"})]})]})}),e.jsx(dl,{open:$,onOpenChange:q,sharing:re,stopping:le,shareResult:Oe,onShare:async ee=>{if(!l)return null;W(!0);try{const ve=await ue(ee);return ve!=null&&ve.url&&(D(Ce=>({...Ce,[l.id]:ve})),pe(Ce=>{const rs=new Set(Ce);return rs.delete(l.id),rs})),ve}finally{W(!1)}},onStopShare:async()=>{if(!l)return!1;ie(!0);try{const ee=await ne();return ee!==!1&&(D(ve=>{const Ce={...ve};return delete Ce[l.id],Ce}),pe(ve=>new Set(ve).add(l.id))),ee}finally{ie(!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(Et,{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:se,className:"mt-6 rounded-lg px-5",children:[e.jsx(zt,{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 ka({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:zt},{value:"native",label:"Load session",icon:It}].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(Et,{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 Et({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(jn,{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:Kt,children:o?e.jsx(Ut,{className:Ns}):e.jsx(rn,{className:Ns})})]})}function jn({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:Kt,children:o?e.jsx(nn,{className:Ns}):e.jsx(ni,{className:Ns})})}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(Lt,{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(qa,{className:"space-y-2 text-left",children:[e.jsx(Pt,{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($e,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Ve,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(Ge,{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(Wa,{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(Mt,{open:s,onOpenChange:t,children:e.jsx(yl,{onAdded:()=>{t(!1),n()}})})}function rt({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(rt,{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(rt,{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(rt,{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,cs="__all__";function He(s){return"session"in s}function Sa(s,t){var n;return t&&s.some(o=>o.id===t)?t:((n=s[0])==null?void 0:n.id)??""}function ot(s){return s&&(fn(s.id)||s.workDir)||""}function Fs(s,t,n){let o=!1;const r=s.map(i=>He(i)&&i.session.id===n.id?(o=!0,{...i,nodeName:t,session:n}):i);return Dt(o?r:[...r,{id:`session-${n.id}`,nodeName:t,session:n}])}function Nn(s,t){return s.filter(He).filter(n=>n.session.nodeId===t).sort((n,o)=>o.session.startedAt-n.session.startedAt)}function _l(s){const t=s.filter(He).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===cs)return n;const o=Nn(s,t);return o.some(i=>i.session.id===n)?n:((r=o[0])==null?void 0:r.session.id)??cs}function Tl(s,t,n){return n===cs?s.filter(o=>!He(o)||o.session.nodeId===t):s.filter(o=>He(o)&&o.session.nodeId===t&&o.session.id===n)}function Dt(s){const t=s.map((o,r)=>({entry:o,index:r})).filter(({entry:o})=>He(o)&&o.session.status!=="running").sort((o,r)=>!He(o.entry)||!He(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})=>He(o)?o.session.id:""));return s.filter(o=>!He(o)||o.session.status==="running"||n.has(o.session.id))}function Tt(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} - ${Tt(s.session)} - ${t}`}function wn(s,t=48){return s.length>t?`${s.slice(0,t-3)}...`:s}function Ml(s,t){return t===cs?"All sessions":s?wn(s.session.command,34):"Command session"}function Ca(s){return s.status==="stopped"?"":s.stderr}function Ll({nodes:s,defaultNodeId:t,onClose:n,initialHistory:o=[]}){const[r,i]=a.useState(()=>Sa(s,t)),g=a.useMemo(()=>s.find(h=>h.id===r)??s[0]??null,[s,r]),[b,N]=a.useState(()=>ot(g)),[v,f]=a.useState(""),[l,u]=a.useState(()=>Dt(o)),[w,S]=a.useState(cs),[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(()=>Nn(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]),ue=a.useRef((P==null?void 0:P.id)??"");a.useEffect(()=>{r&&s.some(h=>h.id===r)||i(Sa(s,t))},[t,s,r]),a.useEffect(()=>{const h=(P==null?void 0:P.id)??"";ue.current!==h&&(ue.current=h,N(ot(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 te=>({node:te,response:await wr(te.id)})));h||u(te=>C.reduce((m,$)=>$.status!=="fulfilled"?m:$.value.response.sessions.reduce((q,re)=>Fs(q,$.value.node.name,re),m),te))}return s.length>0&&I(),()=>{h=!0}},[s]),a.useEffect(()=>{const h=l.filter(He).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(te=>u(m=>Fs(m,C.nodeName,te))).catch(()=>{})},1e3);return()=>window.clearInterval(I)},[l]);const ne=a.useRef(null);async function se(h){if(h.preventDefault(),!P||!v.trim()||T)return;const I=v.trim(),C=P.name;F(!0),f("");try{const te=await kr(P.id,{command:I,...b.trim()?{cwd:b.trim()}:{}});u(m=>Fs(m,C,te)),S(te.id),j(!0)}catch(te){u(m=>[...m,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:C,command:I,error:te instanceof Error?te.message:"Command failed"}])}finally{F(!1)}}async function Z(h,I){h.stopPropagation();const C=await yr(I.session.nodeId,I.session.id);u(te=>Fs(te,I.nodeName,C))}function H(h){S(h),j(!0),p(!1)}function K(h){c&&El(M.current,h.target)&&p(!1)}function oe(h,I,C,te,m){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:te,"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(Je,{className:B("h-3 w-3 transition-transform",C&&"-rotate-90")})]}),!C&&(I.length>0?I.map(he):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:m}))]})}function he(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(xe,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(oa,{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:wn(h.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[h.nodeName," · ",Tt(h.session)]})]})]}),C&&e.jsx("button",{type:"button",onClick:te=>void Z(te,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(ba,{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(Xe,{className:"h-3.5 w-3.5"})}):e.jsx(ra,{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(Je,{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(cs),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===cs&&"bg-primary/10 text-primary"),children:[e.jsx(ra,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),oe("Active",J.active,k,()=>A(h=>!h),"No active sessions"),oe("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(ot(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=ne.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=>He(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(xe,{className:"h-3 w-3 animate-spin"}):h.session.status==="exited"?e.jsx(oa,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"}),Tt(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(ba,{className:"h-3 w-3"})})]}),h.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:h.session.stdout}),Ca(h.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Ca(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:se,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:ne,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(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(Ot,{className:"h-3 w-3"})})]})]})]})})}function qt({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(xe,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(Ot,{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 ws(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 ys(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)&&ws(n)}function _a(s,t){return s==="offline"&&ws(t)}function Ea(s){return!ws(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(!ws(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 ne,se,Z;const F=((ne=s==null?void 0:s.self)==null?void 0:ne.role)==="leader",U=((se=s==null?void 0:s.self)==null?void 0:se.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,ue=(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(Va,{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(Ut,{className:"h-3.5 w-3.5"})})]}),e.jsxs(Ka,{className:"mt-1.5 grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(ls,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(ls,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(ls,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})]}),e.jsx(ds,{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(Da,{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(Ve,{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(xe,{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(bs,{label:"Term",value:String((s==null?void 0:s.term)??0)}),e.jsx(bs,{label:"Nodes",value:String((s==null?void 0:s.nodes.length)??0)}),e.jsx(bs,{label:"Pending",value:String((s==null?void 0:s.taskSummary.pending)??0)}),e.jsx(bs,{label:"Running",value:String((s==null?void 0:s.taskSummary.running)??0)}),e.jsx(bs,{label:"Completed",value:String((s==null?void 0:s.taskSummary.completed)??0)}),e.jsx(bs,{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 vs(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(xe,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(ds,{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"}):ue?e.jsxs(z,{variant:"outline",size:"sm",onClick:x,disabled:S,className:"h-6 rounded-sm px-2 text-[10px]",children:[S&&e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),M&&e.jsx(Da,{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(ds,{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(ye,{value:H,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:H==="all"?"All event types":H},H))})]}),e.jsx(Ve,{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 Da({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=dn(s,t==null?void 0:t.transportType),k=Vt(s,t==null?void 0:t.transportType),A=k&&Ss((t==null?void 0:t.transportType)??s.transportType)?!0:ln(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(Je,{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(Ga,{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(Qa,{className:"h-3 w-3"})}),b&&e.jsx(qt,{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)||ys((F=s.devbox)==null?void 0:F.lastStatus)||l.has(s.id),startDevBoxPending:f===s.id||ys((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(Ya,{role:s.role,size:"compact"}),e.jsx(Ve,{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 vs(S,"Dashboard URL copied")})}),e.jsx(qe,{label:"Node URL",value:x,mono:!0,action:e.jsx(Ps,{label:"Copy node URL",onClick:()=>void vs(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(jt,{label:"Transport",value:p}),t&&e.jsx(jt,{label:"Uptime",value:Tr(t.uptime),mono:!0})]}),e.jsx(tn,{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(xe,{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=dn(s),j=Vt(s),c=ln(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(Je,{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(Ga,{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(Qa,{className:"h-3 w-3"})}),t&&i&&e.jsx(qt,{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)||ys((L=s.devbox)==null?void 0:L.lastStatus)||v.has(s.id),startDevBoxPending:N===s.id||ys((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(Ya,{role:s.role,size:"compact"}),e.jsx(Ve,{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 vs(u,"Dashboard URL copied")})}),e.jsx(qe,{label:"Node URL",value:w,mono:!0,action:e.jsx(Ps,{label:"Copy node URL",onClick:()=>void vs(w,"Node URL copied")})}),s.workDir&&e.jsx(qe,{label:"Workspace",value:s.workDir,mono:!0}),e.jsx(jt,{label:"Transport",value:x})]}),e.jsx(tn,{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(xe,{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(Ua,{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 yn="meshy-task-sidebar-tree-state";function Ta(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"):[]}function it(){var s;try{return((s=globalThis.window)==null?void 0:s.localStorage)??globalThis.localStorage??null}catch{return null}}function Aa(s){if(!s)return{collapsedNodes:[],collapsedDirs:[]};try{const t=s.getItem(yn);if(!t)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(t);return{collapsedNodes:Ta(n.collapsedNodes),collapsedDirs:Ta(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Ul(s,t){if(s)try{s.setItem(yn,JSON.stringify(t))}catch{}}function Ma(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 La(s,t,n){return n?{collapsedNodes:Ma(s,n.nodeKey),collapsedDirs:Ma(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,Rt)).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 Pa({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:ue,onCreateTask:ne,onOpenNodeSettings:se,onOpenDevBox:Z,onStartDevBox:H,onLoadCompletedTasks:K,onSelectTask:oe,onClose:he}){const[h,I]=a.useState(!!k),[C,te]=a.useState(!1),[m,$]=a.useState(!1),q=a.useRef(null),re=a.useRef(null),W=a.useRef(null),[le,ie]=a.useState(()=>A.size>0),{markScrollbarActive:Te,scrollbarActive:D}=vn(),Q=A.size,pe=!!(r&&(le||Q>0)),Ue=i!=="active"||b!=="all"||g!=="all"||N!=="all",Y=k.trim().length>0,[je,ke]=a.useState(()=>new Set(Aa(it()).collapsedNodes)),[Qe,Be]=a.useState(()=>new Set(Aa(it()).collapsedDirs)),[Ne,We]=a.useState(new Set),Se=a.useMemo(()=>Ar(s,l,p,u),[s,l,p,u]),Ae=a.useMemo(()=>Vl(Se,t),[Se,t]),Ye=a.useRef(null),us=Se.length===1,Ze=Se.length>0,ss=us&&(Ue||Y),ts=!!(r&&(Se.length>0||Q>0)),ms=a.useCallback(_=>{ke(be=>{const ee=new Set(be);return ee.has(_)?ee.delete(_):ee.add(_),ee})},[]),Oe=a.useCallback(_=>{Be(be=>{const ee=new Set(be);return ee.has(_)?ee.delete(_):ee.add(_),ee})},[]),as=a.useCallback(_=>{We(be=>{const ee=new Set(be);return ee.add(_),ee})},[]);a.useEffect(()=>{Ul(it(),{collapsedNodes:Array.from(je),collapsedDirs:Array.from(Qe)})},[Qe,je]),a.useEffect(()=>{if(!Ae||!t)return;const _=`${t}:${Ae.nodeKey}:${Ae.dirKey}`;Ye.current!==_&&(Ye.current=_,ke(be=>La(be,new Set,Ae).collapsedNodes),Be(be=>La(new Set,be,Ae).collapsedDirs))},[t,Ae]);const Me=a.useCallback(_=>{ie(!0),V(_)},[V]),ns=a.useCallback(()=>{V(!1),ie(!1)},[V]);a.useEffect(()=>{r||ie(!1)},[r]),a.useEffect(()=>{k&&I(!0)},[k]),a.useEffect(()=>{var _;h&&((_=q.current)==null||_.focus())},[h]),a.useEffect(()=>{if(!h)return;const _=ee=>{var Ce;const ve=ee.target;ve instanceof Node&&((Ce=re.current)!=null&&Ce.contains(ve)||I(!1))},be=ee=>{ee.key==="Escape"&&I(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",be),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",be)}},[h]),a.useEffect(()=>{if(!m)return;const _=ee=>{var Ce;const ve=ee.target;ve instanceof Node&&((Ce=W.current)!=null&&Ce.contains(ve)||$(!1))},be=ee=>{ee.key==="Escape"&&$(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",be),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",be)}},[m]);const xs=pe?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(bt,{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:()=>ie(!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"]}),hs=Q>0?e.jsxs("div",{className:"min-w-0 flex-1 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."})]}):null,fs=Q>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(ct,{children:[e.jsx(ia,{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(ut,{children:[e.jsxs(mt,{children:[e.jsxs(xt,{children:["Archive ",Q," task",Q!==1?"s":"","?"]}),e.jsx(ht,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(ft,{children:[e.jsx(pt,{children:"Cancel"}),e.jsx(gt,{onClick:X,disabled:!T,children:"Archive"})]})]})]}),e.jsxs(ct,{children:[e.jsx(ia,{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(ut,{children:[e.jsxs(mt,{children:[e.jsxs(xt,{children:["Delete ",Q," task",Q!==1?"s":"","?"]}),e.jsx(ht,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(ft,{children:[e.jsx(pt,{children:"Cancel"}),e.jsx(gt,{onClick:ue,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return 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:he,className:"h-6 w-6 rounded-sm",children:e.jsx(nn,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{ref:re,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),ne("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(zt,{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(Je,{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),ne("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(It,{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(lt,{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(Ge,{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(lt,{className:"h-3.5 w-3.5"}),"Search"]}),e.jsx(z,{variant:C||Ue?"secondary":"outline",size:"icon",onClick:()=>te(_=>!_),className:B("h-8 w-8 shrink-0 rounded-sm border-border/70 bg-background/68 shadow-none",Ue&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(Ho,{className:"h-3.5 w-3.5"})})]})]}),(C||Ue)&&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(ye,{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(ye,{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(ye,{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(ye,{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:Se.length>0?e.jsx("div",{className:"space-y-1",children:Se.map(_=>{const be=_.nodeId??"__unassigned__",ee=_.dirs.reduce((Ke,we)=>Ke+we.tasks.length,0),ve=Ze&&!ss&&je.has(be),Ce=_.nodeId!==null&&w.get(_.nodeId)==="offline",rs=!!(r&&_.nodeId&&se);return e.jsxs("div",{className:"space-y-1",children:[Ze&&e.jsxs("div",{className:"flex w-full items-stretch rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 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:()=>ms(be),"aria-expanded":!ve,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(Ms,{className:B("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!ve&&"rotate-90")}),e.jsx(Fa,{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(Ve,{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:[ee," task",ee===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[Ce&&e.jsx(Ve,{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(Ve,{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"})]})]}),rs&&_.nodeId&&se&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(qt,{nodeId:_.nodeId,nodeName:_.nodeName,onOpenSettings:se,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",ve?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:_.dirs.map(Ke=>{const we=`${be}::${Ke.path}`,os=Qe.has(we),is=Xa(Ke.path),Le=S==null?void 0:S.get(we),qs=Le?{visibleTasks:Ke.tasks,hiddenCompletedCount:Math.max(0,Le.total-Le.returned)}:Hl(Ke.tasks,Ne.has(we),t),{visibleTasks:Cs,hiddenCompletedCount:Re}=qs;return e.jsxs("div",{className:B("space-y-0.5 rounded-xl",Ze&&"pl-2.5"),children:[e.jsxs("button",{type:"button",onClick:()=>Oe(we),"aria-expanded":!os,title:Ke.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",!os&&"rotate-90")}),e.jsx(Ia,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"truncate font-mono",children:is}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/40",children:Ke.tasks.length})]}),e.jsx("div",{className:B("grid transition-[grid-template-rows] duration-300 ease-in-out",os?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:B("overflow-hidden",Ze?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[Cs.map(me=>{const ps=me.id===t,Fe=me.assignedTo?w.get(me.assignedTo):void 0,Ws=!!me.assignedTo&&(Fe?Fe==="offline":me.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",ps?'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:[pe&&e.jsx("div",{className:"flex shrink-0",onClick:_s=>_s.stopPropagation(),children:e.jsx(bt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:A.has(me.id),onCheckedChange:_s=>J(me.id,_s===!0),"aria-label":`Select ${me.title}`})}),e.jsxs("button",{type:"button",onClick:()=>oe(me.id),"aria-current":ps?"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",ps?"text-foreground":"text-foreground/80"),children:me.title})}),e.jsx("span",{className:B("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",ps?"text-primary/75":"text-muted-foreground/55"),children:Pr(me.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:me.agent}),me.activeShare&&e.jsx(Ve,{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"}),Ws&&e.jsx(Ve,{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(Ha,{status:me.status,isNative:me.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},me.id)}),Re>0&&e.jsxs("button",{type:"button",onClick:()=>{Le&&K?K(Le):as(we)},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 ${Re} more completed tasks in ${is}`,children:[e.jsx(Je,{className:"h-3 w-3"}),"Load ",Re," more completed"]})]})})})]},we)})})})]},be)})}):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."})}),ts?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:pe&&Q>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[hs,e.jsx(z,{variant:"ghost",size:"sm",onClick:ns,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Clear"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:xs}),fs]})]}):e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:xs}),pe&&e.jsx(z,{variant:"ghost",size:"sm",onClick:ns,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]})}async function Kl(s,t){var n,o;try{const r=await Br(s,t),i={...r,url:za(r.url)};if((o=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&o.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),ae.success("Shared link copied")}catch{ae.success("Shared link created")}else ae.success("Shared link created");return i}catch(r){ae.error(r instanceof Error?r.message:"Failed to create shared link");return}}async function ql(s){try{return await Rr(s),ae.success("Shared link stopped"),!0}catch(t){return ae.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 Ba(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 Ra(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(la(),Or({operationsOpen:Ra(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(la(),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]);Ba(i,{onSwipeLeft:()=>o(!1)}),Ba(g,{onSwipeRight:()=>u(!1)});const w=a.useCallback(()=>{if(Ra(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:st(v.tasks),operations:st(v.operations),terminal:st(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:Rt}}function At(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?cn(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 da(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 da({status:"completed",assignedTo:c.assignedTo??"__unassigned__",projectPath:c.projectPath,cursor:c.nextCursor,limit:Rt});g(k=>ed(k,p.tasks)),N(k=>k.map(A=>At(A)===At(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=>{ca(p.type)&&j()}),r("task",p=>{ca(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 kn(s){return s.map(t=>({...t}))}function ad(s,t){const n=t.get(s);return{logs:n?kn(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&&ae.success(`${r} joined the cluster`),o.type==="node.left"&&!i&&ae.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 vt(s.id);if(t()!==s.id||(n(b=>an(b,g.logs)),o(b=>Nt(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 $a(s,t){return{...s,enabled:!0,alwaysOnline:t}}function Sn(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 Oa({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:Sn(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&&_a(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(()=>Ea((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||(ws(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),ue=(l==null?void 0:l.alwaysOnline)===!0!==T,ne=$l({nodeStatus:s==null?void 0:s.status,status:V,current:l,selected:U}),se=!!ne,Z=!!U&&(X||ue)&&!se,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){ae.error(m instanceof Error?m.message:"Failed to refresh DevBox status")}finally{p(!1)}}},[i]),oe=a.useCallback(async m=>{j(!0);try{const $=await Wr();N($),f(q=>Ol({previousKey:q,baseDevBox:m,listed:$}))}catch($){ae.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=Ea($),re=!n&&_a(s==null?void 0:s.status,$);j(!1),p(re),S(q),u($),F(($==null?void 0:$.alwaysOnline)===!0),f(ws($)?Pe($):""),N([]);async function W(){re&&await K(),!m&&q&&await oe($)}return W(),()=>{m=!0}},[oe,s==null?void 0:s.devbox,s==null?void 0:s.status,i,t,K,n]);async function he(){S(!0),b.length===0&&await oe(l)}async function h(){if(!(!s||!U)){A(!0);try{const m=await ua(s.id,$a(U,T));u(m.node.devbox??null),m.node.devbox&&f(Pe(m.node.devbox)),S(!1),ae.success(`Configured DevBox for ${s.name}`),await(r==null?void 0:r())}catch(m){ae.error(m instanceof Error?m.message:"Failed to configure DevBox")}finally{A(!1)}}}async function I(){if(!(!s||!ne)){O(!0);try{if(U&&(X||ue)){const $=await ua(s.id,$a(U,T));u($.node.devbox??null),$.node.devbox&&f(Pe($.node.devbox)),S(!1)}const{operation:m}=await Ja(s.id);u($=>$&&{...$,lastStatus:"Starting",checkedAt:Date.now(),operationId:m.id}),ae.success(`Start requested for ${s.name}`),await(r==null?void 0:r())}catch(m){ae.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",te=V==="Running"&&(s==null?void 0:s.status)==="offline";return e.jsx(Mt,{open:t,onOpenChange:o,children:e.jsxs(Lt,{className:"max-w-md gap-4 rounded-lg p-5",children:[e.jsxs(qa,{className:"space-y-1",children:[e.jsx(Pt,{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(xe,{className:"h-3.5 w-3.5 animate-spin"}),C]}):U?e.jsx(Oa,{devbox:U}):e.jsx(Ie,{placeholder:C})}),e.jsx(De,{children:b.map(m=>e.jsx(ye,{value:Pe(m),textValue:`${m.name} ${m.projectName??""} ${Sn(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(Oa,{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(Ve,{variant:"outline",className:"rounded-full px-2 py-0.5 text-[10px]",children:[(x||c)&&e.jsx(xe,{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:()=>{he()},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(xe,{className:"h-3 w-3 animate-spin"}):e.jsx(ks,{className:"h-3 w-3"})})]})]}),te&&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(bt,{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(Wa,{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"}),se&&e.jsxs(z,{size:"sm",onClick:I,disabled:L,className:"h-8 rounded-xl text-xs",children:[L?e.jsx(xe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ot,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!se&&e.jsxs(z,{size:"sm",onClick:h,disabled:!Z||k,className:"h-8 rounded-xl text-xs",children:[k&&e.jsx(xe,{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 ys((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)||ys(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 Ja(c),ae.success(`Start requested for ${p.name}`),t()}catch(k){b(A=>{const L=new Set(A);return L.delete(c),L}),ae.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)),ae.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){ae.error(v instanceof Error?v.message:"Failed to cancel queued message")}},[s,t,i]),queueFollowUpMessage:g}}function pd(){var Xt,Jt,Zt,ea,sa,ta;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:ue,panelResize:ne,setMobileTasksPanelOpen:se,setOperationsOpen:Z,toggleTasksPanel:H}=Xl(),[K,oe]=a.useState(()=>!!(u!=null&&u.draftNewTask)),[he,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),[te,m]=a.useState(!1),[$,q]=a.useState("transcript"),[re,W]=a.useState("all"),[le,ie]=a.useState(!1),[Te,D]=a.useState(null),[Q,pe]=a.useState([]),[Ue,Y]=a.useState([]),[je,ke]=a.useState(!1),[Qe,Be]=a.useState(!1),[Ne,We]=a.useState(null),[Se,Ae]=a.useState(new Set),[Ye,us]=a.useState(!1),[Ze,ss]=a.useState(!1),[ts,ms]=a.useState(null),Oe=a.useRef(null),as=a.useRef(new Map),Me=((Xt=r==null?void 0:r.self)==null?void 0:Xt.role)==="leader",ns=(Jt=r==null?void 0:r.self)==null?void 0:Jt.id;rd({cluster:r,subscribe:N});const{nodeSettingsDialog:xs,openNodeSettings:hs}=hd(Me),{devBoxDialog:fs,devBoxNodeIds:_,devBoxStartNodeId:be,devBoxStartNodeIds:ee,devBoxStartingNodeIds:ve,openDevBox:Ce,startDevBox:rs}=xd({cluster:r,refresh:v}),{completedGroups:Ke=[],fetchTasks:we,loadCompletedTasksPage:os,setTasks:is,tasks:Le,tasksError:qs,tasksLoading:Cs}=td({isLeader:Me,selfId:ns,sseConnected:b,preservedTask:Te,subscribe:N}),Re=a.useMemo(()=>[...Le].sort((d,y)=>y.updatedAt-d.updatedAt),[Le]),me=a.useMemo(()=>{var d;return((d=[...Le].sort((y,R)=>R.createdAt-y.createdAt||R.updatedAt-y.updatedAt)[0])==null?void 0:d.id)??null},[Le]),ps=a.useMemo(()=>{const d=new Map;for(const y of(r==null?void 0:r.nodes)??[]){const R=ji(Re,y.id);R>0&&d.set(y.id,R)}return d},[r==null?void 0:r.nodes,Re]),Fe=a.useMemo(()=>Re.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),[Re,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,Fe.map(R=>R.id));return y.size===d.size?d:y})},[Fe]),a.useEffect(()=>{Me||Ae(new Set)},[Me]);const Ws=a.useMemo(()=>["all",...Array.from(new Set(Re.map(d=>d.agent))).sort()],[Re]),_s=a.useMemo(()=>{const y=Array.from(new Set(Re.map(R=>R.assignedTo).filter(R=>!!R))).map(R=>{const ge=Re.find(de=>de.assignedTo===R);return(r==null?void 0:r.nodes.find(de=>de.id===R))??{id:R,name:dt(R,r==null?void 0:r.nodes,ge==null?void 0:ge.assignedNodeName)}}).sort((R,ge)=>R.name.localeCompare(ge.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...y.map(R=>({value:R.name.toLowerCase(),label:R.name}))]},[Re,r==null?void 0:r.nodes]),Wt=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 Re)y.assignedTo&&y.assignedNodeName&&!d.has(y.assignedTo)&&d.set(y.assignedTo,y.assignedNodeName);return d},[r==null?void 0:r.nodes,Re]),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(Ke.map(d=>[At(d),d])),[Ke]),Gt=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=((Zt=r==null?void 0:r.self)==null?void 0:Zt.id)??((ea=Gt[0])==null?void 0:ea.id)??null,Gs=a.useMemo(()=>["all",...Array.from(new Set(g.map(d=>d.type))).sort()],[g]),Tn=a.useMemo(()=>re==="all"?g:g.filter(d=>d.type===re),[g,re]),An=Fe.length>0&&Fe.every(d=>Se.has(d.id)),Mn=Fe.some(d=>Se.has(d.id)),Ln=_i(Fe,Se);a.useEffect(()=>{u!=null&&u.draftNewTask&&(oe(!0),C({route:u.returnRoute??"/",taskId:u.returnTaskId??null}))},[u]),a.useEffect(()=>{re!=="all"&&!Gs.includes(re)&&W("all")},[re,Gs]),a.useEffect(()=>{va(s,K)&&!w&&me&&S(me)},[s,K,w,me]),a.useEffect(()=>{va(s,K)&&(w&&Le.some(d=>d.id===w)||S(me))},[s,K,w,me,Le]);const ce=wi({routeTaskId:s,creatingTask:K,internalSelectedTaskId:w,sortedTaskIds:me?[me]:[]}),gs=a.useMemo(()=>Le.find(d=>d.id===ce)??null,[Le,ce]);a.useEffect(()=>{Oe.current=ce??null},[ce]);const es=a.useCallback(()=>{D(null),pe([]),Y([]),We(null),Be(!1)},[]),Es=a.useCallback((d,y,R=!0)=>{as.current.set(d,{logs:kn(y),loaded:R})},[]),ze=a.useCallback(async()=>{const d=ce;if(d)try{const y=await uo(d);if(Oe.current!==d)return;D(y),is(R=>cn(R,y)),We(null)}catch(y){if(Oe.current!==d)return;es(),We(y instanceof Error?y.message:"Failed to load task")}finally{Oe.current===d&&ke(!1)}},[ce,es,is]),Bs=a.useCallback(async()=>{const d=ce;if(d)try{const y=await vt(d);if(Oe.current!==d)return;pe(R=>{const ge=an(R,y.logs);return Es(d,ge),ge}),Y(R=>Nt(R,y.logs))}catch{}finally{Oe.current===d&&Be(!1)}},[ce,Es]);a.useEffect(()=>{if(!ce){es(),ke(!1);return}q("transcript"),D(gs);const d=ad(ce,as.current);pe(d.logs),Y([]),We(null),ke(!0),Be(d.transcriptLoading),ze(),Bs()},[ce,es,Bs,ze]),a.useEffect(()=>{if(!yi({activeTaskId:ce,routeTaskId:s,creatingTask:K,tasksLoading:Cs,loadedTaskIds:Le.map(y=>y.id)}))return;const d=me;S(d),es(),a.startTransition(()=>{n(d?`/tasks/${d}`:"/",{state:null})})},[ce,es,K,me,n,s,Le,Cs]),a.useEffect(()=>{gs&&D(d=>!d||d.id!==gs.id?d:{...d,...gs})},[gs]),a.useEffect(()=>{if(ce)return N("task",d=>{const y=d.data.taskId;if(!(typeof y!="string"||y!==ce)){if(d.type==="task.output"){const R=d.data.event;if(R){pe(de=>{const Ts=Eo(de,R);return Es(ce,Ts),Ts}),Be(!1);const ge=pa(R);ge&&Y(de=>Do(de,ge))}}d.type==="task.updated"&&ze(),d.type==="task.status"&&(ze(),Bs())}})},[N,ce,ze,Bs]);const G=Te??gs,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:dt(G.assignedTo,r==null?void 0:r.nodes,G.assignedNodeName),projectLabel:Xa(d),projectPath:d}),()=>Ds(null)},[G,r==null?void 0:r.nodes,Ds]);const Qs=Ue.length>0,Bn=G?mo.has(G.agent):!1,Ys=(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"),Xs=a.useMemo(()=>zl(G,r,Qs,!!Ys),[G,r,Qs,Ys]),Js=a.useMemo(()=>To([...Q,...Ue.map(d=>at(d.content,d.timestamp))]),[Q,Ue]),Rs=a.useMemo(()=>{if(!G||G.conversationKind==="nativeSession")return null;const d=Ao(G);if(d.length>0)return at(d,new Date(G.createdAt).toISOString());if(Js.length>0)return null;const y=Mo(G.description||G.title);return y.length>0?at(y,new Date(G.createdAt).toISOString()):null},[G,Js]),Zs=a.useMemo(()=>Rs?pa(Rs):null,[Rs]),Fn=a.useMemo(()=>Zs?Lo(Q,Zs):!1,[Q,Zs]),et=a.useCallback((d="chat")=>{const y={route:s?`/tasks/${s}`:"/",taskId:ce};C(y),h(d),oe(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:y.route,returnTaskId:y.taskId,createMode:d}})})},[s,ce,n]),In=a.useCallback(()=>{const d=(I==null?void 0:I.taskId)??me;oe(!1),C(null),S(d),a.startTransition(()=>{n((I==null?void 0:I.route)??"/",{state:null})})},[I,me,n]),Qt=a.useCallback(d=>{oe(!1),C(null),S(d),a.startTransition(()=>{n(`/tasks/${d}`,{state:null})})},[n]),zn=a.useCallback(d=>{Oe.current=d.id,oe(!1),C(null),is(y=>ki(y,d)),D(d),pe([]),Y([]),We(null),ke(!1),Be(d.conversationKind==="nativeSession"),q("transcript"),S(d.id),id({task:d,getActiveTaskId:()=>Oe.current,setLogs:pe,setPendingMessages:Y,setTranscriptLoading:Be}),we(),a.startTransition(()=>{n(`/tasks/${d.id}`,{state:null})})},[we,n]),{cancelQueuedMessage:Un,queueFollowUpMessage:$s}=fd({activeTaskId:ce,fetchActiveTask:ze,setPendingMessages:Y,setTask:D,setTasks:is}),Vn=a.useCallback(d=>{$s(d)},[$s]),Hn=a.useCallback(async()=>{const d=ce;if(!(!d||(G==null?void 0:G.conversationKind)!=="nativeSession")){Be(!0);try{const y=await vt(d);if(Oe.current!==d)return;pe(y.logs),Es(d,y.logs),Y(R=>Nt(R,y.logs))}catch(y){ae.error(y instanceof Error?y.message:"Failed to reload transcript")}finally{Oe.current===d&&Be(!1)}}},[G==null?void 0:G.conversationKind,ce,Es]),Kn=a.useCallback(d=>$s(d),[$s]),qn=a.useCallback(async()=>{if(G)try{await ho(G.id),ze(),we()}catch(d){ae.error(d instanceof Error?d.message:"Failed to cancel task")}},[G,ze,we]),{handleShareTask:Wn,handleStopShareTask:Gn}=Wl(G,ze,we),Qn=a.useCallback(async()=>{if(G)try{await fo(G.id),ze(),we()}catch(d){ae.error(d instanceof Error?d.message:"Failed to retry task")}},[G,ze,we]),Os=a.useCallback((d,y=!1)=>{const R=Ei(Fe,d);return S(R),(y||!R)&&es(),a.startTransition(()=>{n(R?`/tasks/${R}`:"/",{state:null})}),R},[es,Fe,n]),Yn=a.useCallback((d,y)=>{Ae(R=>{const ge=new Set(R);return y?ge.add(d):ge.delete(d),ge})},[]),Xn=a.useCallback(d=>{if(!d){Ae(new Set);return}Ae(new Set(Fe.map(y=>y.id)))},[Fe]),Jn=a.useCallback(async()=>{const d=Array.from(Se);if(d.length!==0)try{const{results:y}=await po(d),R=y.filter(de=>!de.ok),ge=y.filter(de=>de.ok).map(de=>de.id);ce&&ge.includes(ce)&&Os(ge),R.length>0?ae.error(`Failed to archive ${R.length} task(s): ${R.map(de=>de.error??de.id).join(", ")}`):ae.success(`Archived ${ge.length} task(s)`),Ae(new Set(R.map(de=>de.id))),we()}catch(y){ae.error(y instanceof Error?y.message:"Failed to archive tasks")}},[ce,we,Os,Se]),Zn=a.useCallback(async()=>{const d=Array.from(Se);if(d.length!==0)try{const{results:y}=await go(d),R=y.filter(de=>!de.ok),ge=y.filter(de=>de.ok).map(de=>de.id);ce&&ge.includes(ce)&&Os(ge,!0),R.length>0?ae.error(`Failed to delete ${R.length} task(s): ${R.map(de=>de.error??de.id).join(", ")}`):ae.success(`Deleted ${ge.length} task(s)`),Ae(new Set(R.map(de=>de.id))),we()}catch(y){ae.error(y instanceof Error?y.message:"Failed to delete tasks")}},[ce,we,Os,Se]),er=a.useCallback(async()=>{us(!0);try{await bo(),v()}catch(d){ae.error(d instanceof Error?d.message:"Failed to promote node")}finally{us(!1)}},[v]),sr=a.useCallback(async()=>{ss(!0);try{await vo(),ae.success("This node left the remote cluster and is leading itself again."),we(),ze(),v()}catch(d){ae.error(d instanceof Error?d.message:"Failed to leave cluster")}finally{ss(!1)}},[ze,we,v]),tr=a.useCallback(async d=>{var Ts;const y=!Vt(d),R=d.id===((Ts=r==null?void 0:r.self)==null?void 0:Ts.id),ge=R?(i==null?void 0:i.transportType)??d.transportType:d.transportType,de=R&&!y&&Ss(ge);ms(d.id);try{de?await jo("direct"):await No(d.id,y),ae.success(y?`Enabled remote access on ${d.name}`:`Disabled remote access on ${d.name}`),v()}catch(aa){ae.error(aa instanceof Error?aa.message:"Failed to update remote access")}finally{ms(null)}},[(sa=r==null?void 0:r.self)==null?void 0:sa.id,v,i==null?void 0:i.transportType]),ar=a.useCallback(d=>{os&&os(d).catch(y=>{ae.error(y instanceof Error?y.message:"Failed to load completed tasks")})},[os]),Yt={toolbarTasks:Fe,activeTaskId:ce,tasksLoading:Cs,tasksError:qs,isLeader:Me,scope:x,agentFilter:c,nodeFilter:k,taskKindFilter:L,agentOptions:Ws,nodeOptions:_s,nodeNameById:Wt,nodeWorkDirById:Cn,nodeStatusById:_n,leaderNodeId:((ta=r==null?void 0:r.leader)==null?void 0:ta.id)??null,searchQuery:U,completedGroupByKey:En,devBoxNodeIds:_,devBoxStartNodeIds:ee,devBoxStartingNodeIds:ve,selectedTaskIds:Se,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:et,onOpenNodeSettings:Me?hs:void 0,onOpenDevBox:Me?Ce:void 0,onStartDevBox:Me?rs:void 0,onLoadCompletedTasks:ar,onSelectTask:Qt,onClose:H},nr={cluster:r,systemInfo:i,nodeNameById:Wt,nodeBlockingTaskCounts:ps,eventTypeFilter:re,onEventTypeFilterChange:W,eventTypeOptions:Gs,filteredEvents:Tn,sseConnected:b,clusterLoading:f,clusterError:l,promotePending:Ye,onPromote:er,onAddNode:()=>m(!0),leavePending:Ze,onLeaveCluster:sr,onToggleNodeDevTunnel:tr,devTunnelNodeId:ts,devBoxStartNodeId:be,devBoxStartingNodeIds:ve,onOpenNodeSettings:Me?hs:void 0,onOpenDevBox:Me?Ce:void 0,onStartDevBox:Me?rs:void 0,onClose:()=>Z(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Sl,{desktopTasksOpen:E,mobileTasksPanelOpen:J,mobileTasksPanelRef:V,operationsOpen:X,operationsPanelRef:ue,panelResize:ne,taskSidebar:e.jsx(Pa,{...Yt}),operationsSidecar:e.jsx(Fl,{...nr}),terminalPanel:o!=null&&o.terminalOpen?e.jsx(Ll,{nodes:Gt,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:he,activeTask:G,assignedNode:Pn,taskLoading:je,transcriptLoading:Qe,taskError:Ne,displayEvents:Js,initialPromptAlreadyInLogs:Fn,initialPrompt:Rs,supportsFollowUp:Bn,taskUnavailable:Xs.taskUnavailable,chatDisabled:Xs.chatDisabled,chatDisabledReason:Xs.chatDisabledReason,questionBypassEnabled:le,isRunning:!!Ys,isStarting:Rn,hasPendingFollowUp:Qs,canCancel:!!$n,canRetry:!!On,onRetry:Qn,onCancel:qn,onReloadNativeTranscript:Hn,onShareTask:Wn,onStopShareTask:Gn,onStartCreateTask:et,onCancelCreateTask:In,onCreateTask:zn,onSendMessage:Vn,onCancelQueuedMessage:Un,onQuestionBypassChange:ie,onSubmitQuestionResponse:Kn}),mobileTaskSidebar:e.jsx(Pa,{...Yt,onCreateTask:d=>{se(!1),et(d)},onSelectTask:d=>{se(!1),Qt(d)},onClose:()=>se(!1)}),onCloseOperations:()=>Z(!1),onCloseTaskList:()=>se(!1)}),e.jsx(kl,{open:te,onOpenChange:m,onAdded:v}),xs,fs]})}const jd=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:pd},Symbol.toStringTag,{value:"Module"}));export{jd as D,wt as G};
|