meshy-node 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-CYA4YD9M.js","assets/index-Dcj0nR-j.js","assets/index-CXPXpidI.css","assets/folder-BMmcfsyZ.js","assets/file-BduJ6PU6.js","assets/DashboardShared-BohLaqeo.js","assets/PreviewTab-Cz-QrEJn.js","assets/play-Dc8Adtxz.js","assets/DiffTab-CPqcA12G.js"])))=>i.map(i=>d[i]);
2
- import{c as me,r as a,j as e,X as Ge,B as O,S as ra,a as yn,b as I,d as kn,g as Sn,e as Cn,I as He,C as us,f as _n,h as En,F as Dn,i as ms,k as we,D as xs,l as Tn,m as Mn,t as oe,n as ye,o as ke,p as Pe,q as Se,s as Ze,T as An,u as Ln,v as Bn,w as it,x as lt,y as dt,z as oa,A as ia,E as ns,G as la,H as Pn,J as da,K as Te,L as ca,P as $n,M as ua,N as Je,O as Rn,Q as Ye,R as zs,U as Us,V as Vs,W as qs,Y as Hs,Z as Ks,_ as Ws,$ as Gs,a0 as ct,a1 as In,a2 as ma,a3 as xa,a4 as On,a5 as Rs,a6 as Bt,a7 as ys,a8 as Fn,a9 as zn,aa as Un,ab as Vn,ac as qn,ad as Hn,ae as Kn,af as Wn,ag as ha,ah as fa,ai as pa,aj as Gn,ak as ks,al as Qn,am as Jn,an as Yn,ao as Qs,ap as Xn,aq as Zn,ar as er,as as Pt,at as sr,au as tr,av as ar,aw as nr,ax as rr,ay as or,az as ir,aA as lr,aB as ga,aC as dr,aD as cr,aE as ur,aF as $t,aG as ba,aH as mr,aI as xr,aJ as hr,aK as fr,aL as pr,aM as gr,aN as br,aO as vr,aP as jr,aQ as Nr,aR as wr,aS as yr,aT as kr,aU as Sr,aV as Cr,aW as _r,aX as Er,aY as Dr,aZ as Tr,a_ as Mr,a$ as Ar,b0 as Lr,b1 as Br,b2 as Pr,b3 as $r,b4 as Rr}from"./index-Dcj0nR-j.js";import{r as Rt,e as Ir,b as va,t as ja,A as ut,L as ue,g as Na,a as Or,c as Fr,d as It,f as Ot,h as zr,i as Ur,C as Ft,T as Is,D as as,I as qe,M as Js,j as wa,m as ya,k as ka,l as Vr,n as zt,o as qr,p as Hr,q as Os,s as Kr,u as Wr,v as Gr}from"./DashboardShared-BohLaqeo.js";import{F as Sa}from"./folder-BMmcfsyZ.js";import{P as mt}from"./play-Dc8Adtxz.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-CnNoF4D7.js","assets/index-XMBEftiF.js","assets/index-DG1iTjAc.css","assets/folder-DzQ8M7ZQ.js","assets/file-BAIQcMRk.js","assets/DashboardShared-HvdlVE0E.js","assets/PreviewTab-CMAZG5kO.js","assets/play-BN9wGxuQ.js","assets/DiffTab-CpVpmtju.js"])))=>i.map(i=>d[i]);
2
+ import{c as me,r as a,j as e,X as Ge,B as O,S as ra,a as yn,b as I,d as kn,g as Sn,e as Cn,I as He,C as us,f as _n,h as En,F as Dn,i as ms,k as we,D as xs,l as Tn,m as Mn,t as oe,n as ye,o as ke,p as Pe,q as Se,s as Ze,T as An,u as Ln,v as Bn,w as it,x as lt,y as dt,z as oa,A as ia,E as ns,G as la,H as Pn,J as da,K as Te,L as ca,P as $n,M as ua,N as Je,O as Rn,Q as Ye,R as zs,U as Us,V as Vs,W as qs,Y as Hs,Z as Ks,_ as Ws,$ as Gs,a0 as ct,a1 as In,a2 as ma,a3 as xa,a4 as On,a5 as Rs,a6 as Bt,a7 as ys,a8 as Fn,a9 as zn,aa as Un,ab as Vn,ac as qn,ad as Hn,ae as Kn,af as Wn,ag as ha,ah as fa,ai as pa,aj as Gn,ak as ks,al as Qn,am as Jn,an as Yn,ao as Qs,ap as Xn,aq as Zn,ar as er,as as Pt,at as sr,au as tr,av as ar,aw as nr,ax as rr,ay as or,az as ir,aA as lr,aB as ga,aC as dr,aD as cr,aE as ur,aF as $t,aG as ba,aH as mr,aI as xr,aJ as hr,aK as fr,aL as pr,aM as gr,aN as br,aO as vr,aP as jr,aQ as Nr,aR as wr,aS as yr,aT as kr,aU as Sr,aV as Cr,aW as _r,aX as Er,aY as Dr,aZ as Tr,a_ as Mr,a$ as Ar,b0 as Lr,b1 as Br,b2 as Pr,b3 as $r,b4 as Rr}from"./index-XMBEftiF.js";import{r as Rt,e as Ir,b as va,t as ja,A as ut,L as ue,g as Na,a as Or,c as Fr,d as It,f as Ot,h as zr,i as Ur,C as Ft,T as Is,D as as,I as qe,M as Js,j as wa,m as ya,k as ka,l as Vr,n as zt,o as qr,p as Hr,q as Os,s as Kr,u as Wr,v as Gr}from"./DashboardShared-HvdlVE0E.js";import{F as Sa}from"./folder-DzQ8M7ZQ.js";import{P as mt}from"./play-BN9wGxuQ.js";/**
3
3
  * @license lucide-react v1.7.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -136,4 +136,4 @@ import{c as me,r as a,j as e,X as Ge,B as O,S as ra,a as yn,b as I,d as kn,g as
136
136
  * See the LICENSE file in the root directory of this source tree.
137
137
  */const Po=[["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"}]],$o=me("trash-2",Po),Ro=new Set(["assigned","running"]);function Io(s,t){return s.reduce((n,o)=>o.assignedTo===t&&Ro.has(o.status)?n+1:n,0)}function ds(s){return(s==null?void 0:s.toLowerCase())==="devtunnel"}function Oo(s){return s?ds(s)?"DevTunnel":s.charAt(0).toUpperCase()+s.slice(1):"Direct"}function pt(s,t){return ds(t??s.transportType)||!!s.devtunnelEndpoint}function Ta(s,t){return!ds(t??s.transportType)}function Ma(s,t){const n=t??s.transportType;return ds(n)?"DevTunnel":s.devtunnelEndpoint?"Direct + DevTunnel":Oo(n)}function Vt(s,t){return!s&&!t}function Fo({routeTaskId:s,creatingTask:t,internalSelectedTaskId:n,sortedTaskIds:o}){return s||(t?null:n??o[0]??null)}function zo(s,t){return[t,...s.filter(n=>n.id!==t.id)]}const Uo=new Set(["completed","failed","cancelled","archived"]);function Vo(s,t){const n=new Set(t);return new Set(Array.from(s).filter(o=>n.has(o)))}function qo(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=>Uo.has(r.status))}function Ho(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 Aa(){const[s,t]=a.useState([]),[n,o]=a.useState(null),r=a.useRef(null),i=a.useCallback(()=>{var h;(h=r.current)==null||h.click()},[]),g=a.useCallback(async h=>{const l=Array.from(h.target.files??[]);if(l.length!==0)try{const u=await Rt(l);t(b=>[...b,...u]),o(null)}catch(u){o(u instanceof Error?u.message:"Failed to attach image")}finally{h.target.value=""}},[]),j=a.useCallback(async h=>{const l=Ir(h.clipboardData);if(l.length!==0){h.preventDefault();try{const u=await Rt(l);t(b=>[...b,...u]),o(null)}catch(u){o(u instanceof Error?u.message:"Failed to attach image")}}},[]),N=a.useCallback(h=>{t(l=>l.filter((u,b)=>b!==h))},[]),f=a.useCallback(()=>{t([]),o(null)},[]);return{images:s,error:n,fileInputRef:r,pickImages:i,handleFileChange:g,handlePaste:j,removeImage:N,clearImages:f}}function Ko(s){const t=s.map(r=>({...r,displayValue:Wo(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 Wo(s){return s.label.toLowerCase()==="agent"?Na(s.value):s.value}function qt(s){switch(s.toLowerCase()){case"branch":return Ys;case"node":return ra;case"working dir":default:return Ca}}function Go({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 Qo({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[j,N]=a.useState(""),f=a.useRef(null),{images:h,error:l,fileInputRef:u,pickImages:b,handleFileChange:S,handlePaste:p,removeImage:M,clearImages:x}=Aa(),w=a.useCallback(()=>{f.current&&(f.current.style.height="auto")},[]),T=a.useCallback(()=>{const _=va(j,h);_.length===0||t||(s(_),N(""),x(),w())},[j,h,t,s,x,w]),U=a.useCallback(_=>{_.key==="Enter"&&!_.shiftKey&&(_.preventDefault(),T())},[T]),B=a.useCallback(()=>{f.current&&(f.current.style.height="auto",f.current.style.height=`${Math.min(f.current.scrollHeight,220)}px`)},[]),K=j.trim().length>0||h.length>0,F=Go({disabled:t,running:i,canStop:i&&!!g,hasContent:K}),P=Ko(r),E=P.primary?qt(P.primary.label):Ca,A=i?K?"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",{className:"animate-composer-settle border-t border-border/45 bg-background/42 px-2 py-2 backdrop-blur-xl sm:px-4 sm:py-3",children:e.jsxs("div",{"data-chat-input-card":"true",className:"overflow-hidden rounded-xl border border-border/65 bg-card/88 shadow-[0_30px_92px_-62px_rgba(15,23,42,0.55)] backdrop-blur-xl sm:rounded-xl dark:shadow-[0_30px_92px_-62px_rgba(0,0,0,0.95)]",children:[e.jsx("input",{ref:u,type:"file",accept:"image/*",multiple:!0,onChange:S,className:"hidden"}),P.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:"inline-flex max-w-full items-center gap-1.5 rounded-sm border border-border/55 bg-muted/35 px-1.5 py-0.5",children:[e.jsx(E,{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:P.primary.value,children:P.primary.displayValue})]})}),h.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:h.map((_,Q)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:ja(_),alt:_.filename??`attachment ${Q+1}`,className:"h-24 w-24 rounded-xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>M(Q),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 ${_.filename??`image ${Q+1}`}`,children:e.jsx(Ge,{className:"h-3.5 w-3.5"})})]},`${_.filename??"image"}-${Q}`))})}),e.jsx("div",{className:"px-2 pb-0 pt-1 sm:px-5 sm:pt-1.5",children:e.jsx("textarea",{ref:f,value:j,onChange:_=>N(_.target.value),onKeyDown:U,onPaste:p,onInput:B,placeholder:o,disabled:t,rows:1,className:"min-h-[1.35rem] w-full resize-none 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:[P.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:P.secondary.map(_=>{const Q=qt(_.label),V=_.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${_.label}: ${_.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[V?e.jsx(ut,{agent:_.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(Q,{"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 ${_.mono?"font-mono":""}`,children:_.displayValue})]},`${_.label}:${_.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(O,{type:"button",variant:"ghost",onClick:b,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(Zs,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:A,children:e.jsx(O,{onClick:F.primaryAction==="stop"?g:T,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(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Da,{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 Jo=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Yo=Jo.reduce((s,t)=>{const n=yn(`Primitive.${t}`),o=a.forwardRef((r,i)=>{const{asChild:g,...j}=r,N=g?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(N,{...j,ref:i})});return o.displayName=`Primitive.${t}`,{...s,[t]:o}},{}),Xo="Label",La=a.forwardRef((s,t)=>e.jsx(Yo.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())}}));La.displayName=Xo;var Ba=La;const Zo=kn("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Me=a.forwardRef(({className:s,...t},n)=>e.jsx(Ba,{ref:n,className:I(Zo(),s),...t}));Me.displayName=Ba.displayName;function ei(s,t,n){return s!=="auto"?t.find(o=>o.id===s)??null:n.length===1?n[0]??null:null}function si(s){return s.trim()||"."}function ti(s){return new Promise(t=>window.setTimeout(t,s))}function ai(s){return!!s&&typeof s=="object"&&typeof s.createdBranch=="string"&&typeof s.currentBranch<"u"}async function ni(s){let t=s;for(let n=0;n<60;n++){if(t.status==="succeeded"){if(ai(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 ti(1e3),t=await _n(t.id)}throw new Error("Timed out waiting for branch creation")}function Ht({value:s,onChange:t,project:n,assignTo:o,nodes:r,assignableNodes:i,layout:g="default",chipClassName:j,chipActiveClassName:N,chipInactiveClassName:f,labelClassName:h,triggerClassName:l}){const[u,b]=a.useState(!1),[S,p]=a.useState(null),[M,x]=a.useState(""),[w,T]=a.useState(!1),[U,B]=a.useState(!1),[K,D]=a.useState(!1),[F,P]=a.useState(null),[E,A]=a.useState(""),[_,Q]=a.useState(""),[V,G]=a.useState(""),[ie,ae]=a.useState(!1),ee=a.useRef(null),J=a.useRef(0),H=a.useMemo(()=>ei(o,r,i),[o,r,i]),W=H==null?void 0:H.id,Y=a.useMemo(()=>si(n),[n]),de=a.useMemo(()=>W?`${W}
138
138
  ${Y}`:"",[W,Y]),m=a.useCallback(async(v=0,R=!1)=>{const te=J.current+1,ge=de;if(J.current=te,!W){p(null),x("");return}P(null),R||x(""),R?B(!0):T(!0);try{const Ce=await Sn(W,{path:Y,limit:20,offset:v,allowAbsolute:!0});if(te!==J.current)return;x(ge),p(be=>R&&be?{...Ce,branches:[...be.branches,...Ce.branches]}:Ce)}catch(Ce){if(te!==J.current)return;P(Ce instanceof Error?Ce.message:"Failed to load branch info"),R||(p(null),x(""))}finally{te===J.current&&(T(!1),B(!1))}},[W,de,Y]);a.useEffect(()=>{if(!W){J.current+=1,p(null),x(""),P(null);return}m()},[W,Y,m]),a.useEffect(()=>{const v=s.trim(),R=M===de?S:null,te=R!=null&&R.available&&R.currentBranch?R.currentBranch:"";v!==te&&t(te)},[S,de,M,t,s]),a.useEffect(()=>{if(!u)return;const v=te=>{ee.current&&(ee.current.contains(te.target)||b(!1))},R=te=>{te.key==="Escape"&&b(!1)};return document.addEventListener("mousedown",v),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",R)}},[u]),a.useEffect(()=>{u&&(Q(""),G(""),ae(!1))},[u,W,Y]);const $=a.useCallback(async()=>{if(!W)return;const v=E.trim(),R=ie?V.trim():_.trim();if(!(!v||!R)){D(!0),P(null);try{const te=await Cn(W,{path:Y,branchName:v,startPoint:R,limit:20,offset:0,allowAbsolute:!0}),ge=await ni(te);x(de),p(ge),t(ge.currentBranch??ge.createdBranch),A(""),Q(""),G(""),ae(!1),b(!1)}catch(te){P(te instanceof Error?te.message:"Failed to create branch")}finally{D(!1)}}},[W,de,Y,ie,V,E,t,_]),y=M===de?S:null,X=a.useCallback(()=>{y!=null&&y.hasMore&&m(y.branches.length,!0)},[y,m]),c=s.trim()||(y==null?void 0:y.currentBranch)||(y&&!y.available?"No git repo":"Branch"),L=ie?V.trim():_.trim(),z=!!(y!=null&&y.available&&E.trim()&&L&&!K),re=g==="composer"?e.jsxs(O,{type:"button",variant:"ghost",onClick:()=>b(v=>!v),title:c,"aria-label":`Branch: ${c}`,className:I(j,l,"min-w-0 max-w-full",s.trim()?N:f),children:[w&&!y?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(Ys,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:I("min-w-0 truncate",h),children:c})]}):e.jsxs(O,{type:"button",variant:"outline",onClick:()=>b(v=>!v),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:c,children:[e.jsx("span",{className:I("truncate",s.trim()?"font-mono text-foreground":"text-muted-foreground"),children:c}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:H?H.name:"Manual"})]});return e.jsxs("div",{className:I("relative inline-block",g==="composer"?"min-w-0 shrink-0":"w-full"),ref:ee,children:[g==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Branch"}),re]}):re,u&&e.jsxs("div",{className:I("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(Ys,{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:y!=null&&y.repoRoot?`${y.currentBranch??c} · ${y.repoRoot}`:(y==null?void 0:y.currentBranch)??c,children:(y==null?void 0:y.currentBranch)??c}),w?e.jsx(ue,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),H?w&&!y?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):y&&!y.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(He,{value:E,onChange:v=>A(v.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(O,{type:"button",size:"sm",onClick:()=>void $(),disabled:!z,title:z?"Create branch":"Enter a name and pick a base","aria-label":"Create branch",className:"h-8 w-8 shrink-0 rounded-md p-0",children:K?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(So,{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"}),!ie&&e.jsxs("button",{type:"button",onClick:()=>ae(!0),className:"flex items-center gap-1 rounded px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx(ls,{className:"h-2.5 w-2.5"}),"Manual"]})]}),ie?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(He,{value:V,onChange:v=>G(v.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-md border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{ae(!1),G("")},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(Ge,{className:"h-3.5 w-3.5"})})]}):y!=null&&y.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-md border border-border/40 bg-background/40",children:[y.branches.map(v=>{const R=_===v.ref,te=v.branch==="main"||v.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>Q(v.ref),className:I("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",R&&"bg-background/70"),title:v.ref,children:[e.jsx("span",{className:I("shrink-0 text-[10px]",te?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:te?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:v.ref}),R?e.jsx(us,{className:"h-3 w-3 shrink-0 text-primary"}):null]},v.ref)}),y.hasMore&&e.jsxs("button",{type:"button",onClick:X,disabled:U,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:[U?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Xs,{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 ri=20,oi=3,st="meshy-working-dir-recents-by-node";function ii(s){return s.startsWith("/")||s.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(s)}function li(s){const t=s.trim();return t||"."}function tt(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===oi))break}return t}function di(s,t){const n=t.trim();return tt(n?[n,...s]:s)}function Pa(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=tt(r);i.length>0&&(t[n]=i)}return t}function ci(s,t,n){if(!t)return s;const o=s[t]??[],r=di(o,n);if(r.length===0){if(!(t in s))return s;const{[t]:i,...g}=s;return g}return{...s,[t]:r}}function ui(s,t){var n;return t?((n=s[t])==null?void 0:n[0])??"":""}function $a(s){if(!s||typeof window>"u")return"";try{const t=window.localStorage.getItem(st);return t?ui(Pa(JSON.parse(t)),s):""}catch{return""}}function mi(s,t,n){return s!=="auto"?t.find(o=>o.id===s)??null:n.length===1?n[0]??null:null}function xi(s,t){const n=t.trim();return n?ii(n)||!s?n:`${s.replace(/[/\\]+$/,"")}/${n}`:""}function hi(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 Ss({value:s,onChange:t,assignTo:n,nodes:o,assignableNodes:r,layout:i="default",chipClassName:g,chipActiveClassName:j,chipInactiveClassName:N,labelClassName:f,triggerClassName:h,popoverPlacement:l="bottom",popoverAlign:u="start"}){const[b,S]=a.useState(!1),[p,M]=a.useState(null),[x,w]=a.useState(!1),[T,U]=a.useState(!1),[B,K]=a.useState(null),[D,F]=a.useState(""),[P,E]=a.useState(!1),[A,_]=a.useState({}),Q=a.useRef(null),V=a.useMemo(()=>mi(n,o,r),[n,o,r]),G=V==null?void 0:V.id,ie=a.useMemo(()=>G?A[G]??[]:[],[A,G]),ae=a.useMemo(()=>s.trim()?xi(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 c=window.localStorage.getItem(st);if(!c)return;const L=JSON.parse(c);_(Pa(L))}catch{}},[]);const ee=a.useCallback(c=>{G&&_(L=>{const z=ci(L,G,c);if(z===L)return L;if(typeof window<"u")try{window.localStorage.setItem(st,JSON.stringify(z))}catch{}return z})},[G]),J=a.useCallback((c,L=!0)=>{const z=c.trim();t(z),L&&z&&ee(z),S(!1)},[t,ee]),H=a.useCallback(async(c,L=0,z=!1)=>{if(G){K(null),z?U(!0):w(!0);try{const re=await En(G,{path:c,limit:ri,offset:L,directoriesOnly:!0,allowAbsolute:!0});M(v=>z&&v?{...re,entries:[...v.entries,...re.entries]}:re)}catch(re){K(re instanceof Error?re.message:"Failed to browse directories"),z||M(null)}finally{w(!1),U(!1)}}},[G]),W=a.useRef(s);W.current=s;const Y=a.useRef(H);Y.current=H,a.useEffect(()=>{if(!b)return;const c=W.current;F(c),E(!1),M(null),K(null),G&&Y.current(li(c))},[b,G]),a.useEffect(()=>{if(!b)return;const c=z=>{Q.current&&(Q.current.contains(z.target)||S(!1))},L=z=>{z.key==="Escape"&&S(!1)};return document.addEventListener("mousedown",c),document.addEventListener("keydown",L),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",L)}},[b]);const de=a.useCallback(c=>{H(c)},[H]),m=a.useCallback(()=>{p&&H(p.currentPath,p.entries.length,!0)},[p,H]),$=i==="composer"?e.jsxs(O,{type:"button",variant:"ghost",onClick:()=>S(c=>!c),title:ae,"aria-label":`Working directory: ${ae}`,className:I(g,h,"min-w-0 max-w-full",s.trim()?j:N),children:[e.jsx(Dn,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:I("min-w-0 truncate",f),children:ae})]}):e.jsxs(O,{type:"button",variant:"outline",onClick:()=>S(c=>!c),className:"h-11 w-full justify-between rounded-2xl border-border/70 bg-background/70 px-4",title:ae,children:[e.jsx("span",{className:I("truncate",s.trim()?"font-mono text-foreground":"text-muted-foreground"),children:ae}),e.jsx("span",{className:"ml-3 shrink-0 text-xs text-muted-foreground",children:V?V.name:"Manual"})]}),y=hi(p,V),X=!!(p!=null&&p.parentPath);return e.jsxs("div",{className:I("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:Q,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Working directory"}),$]}):$,b&&e.jsxs("div",{className:I("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:[ie.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(Xs,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:ie.map(c=>e.jsx("button",{type:"button",onClick:()=>J(c),className:"truncate rounded px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:c,children:c},c))})]}),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:()=>(p==null?void 0:p.parentPath)&&de(p.parentPath),disabled:!X||x,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md border border-border/60 text-muted-foreground transition-colors hover:bg-background/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(Xr,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:y,children:y}),p&&e.jsx("button",{type:"button",onClick:()=>J(p.isAbsolute?p.currentPath:p.currentPath==="."?"":p.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?x?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):p&&p.entries.length>0?e.jsxs(e.Fragment,{children:[p.entries.map(c=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>J(c.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 ${c.path}`,children:[e.jsx(Sa,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:c.name})]}),e.jsx("button",{type:"button",onClick:()=>de(c.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 ${c.name}`,children:e.jsx(ms,{className:"h-3.5 w-3.5"})})]},c.path)),p.hasMore&&e.jsxs("button",{type:"button",onClick:m,disabled:T,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:[T?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Xs,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:B??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),B&&p&&p.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:B})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:P?e.jsxs(e.Fragment,{children:[e.jsx(He,{value:D,onChange:c=>F(c.target.value),onKeyDown:c=>{c.key==="Enter"&&D.trim()?(c.preventDefault(),J(D)):c.key==="Escape"&&(c.preventDefault(),E(!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:()=>J(D),disabled:!D.trim(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-foreground hover:bg-background/60 disabled:opacity-40",title:"Apply","aria-label":"Apply manual path",children:e.jsx(us,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{E(!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(Ge,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{F(s),E(!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(ls,{className:"h-3 w-3"})]})})]})]})}function Ra(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 gt({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(lo,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function at(s,t){return s.map(n=>{const o=!!t&&n.id===t;return e.jsx(we,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(gt,{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 fi(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??xs}}function pi(){return An.map(s=>e.jsx(we,{value:s.value,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:s.label}),s.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:s.description})]})},s.value))}function gi(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 bi({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,className:g,footerClassName:j,submitLabel:N="Load session",cancelLabel:f="Cancel",autoFocus:h=!1}){const l=a.useMemo(()=>Ra(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),u=a.useMemo(()=>{var v;return n&&l.some(R=>R.id===n)?n:((v=l[0])==null?void 0:v.id)??""},[l,n]),[b,S]=a.useState(""),[p,M]=a.useState("codex"),[x,w]=a.useState(""),[T,U]=a.useState(""),[B,K]=a.useState(""),[D,F]=a.useState(u),[P,E]=a.useState("normal"),[A,_]=a.useState(xs),[Q,V]=a.useState(!1),[G,ie]=a.useState([]),[ae,ee]=a.useState(!1),[J,H]=a.useState(null),W=a.useMemo(()=>G.find(v=>v.sessionId===x)??null,[G,x]);a.useEffect(()=>{D&&l.some(v=>v.id===D)||F(u)},[D,l,u]),a.useEffect(()=>{w(""),U(""),K("")},[p,D]),a.useEffect(()=>{let v=!1;return D?(ee(!0),H(null),Tn(D,{agent:p,limit:50}).then(R=>{v||ie(R.sessions)}).catch(R=>{v||(ie([]),H(R instanceof Error?R.message:"Failed to load native sessions"))}).finally(()=>{v||ee(!1)}),()=>{v=!0}):(ie([]),H(null),ee(!1),()=>{v=!0})},[p,D]),a.useEffect(()=>{W&&(U(W.sessionId),K(W.cwd))},[W]);const Y=a.useCallback(async v=>{v.preventDefault();const R=fi({title:b,defaultTitle:W==null?void 0:W.summary,agent:p,sessionId:T,cwd:B,assignTo:D,priority:P,mode:A});if(R){V(!0);try{const te=await Mn(R);r(te)}catch(te){oe.error(te instanceof Error?te.message:"Failed to load native session")}finally{V(!1)}}},[b,W,p,T,B,D,P,A,r]),de=!!(T.trim()&&B.trim()&&D),[m,$]=a.useState(!1),[y,X]=a.useState(""),c=l.find(v=>v.id===D)??null,L=!!(n&&(c==null?void 0:c.id)===n),z=a.useMemo(()=>{const v=y.trim().toLowerCase();return v?G.filter(R=>R.summary.toLowerCase().includes(v)||R.sessionId.toLowerCase().includes(v)||R.cwd.toLowerCase().includes(v)):G},[G,y]),re="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:Y,className:I("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(ye,{value:D,onValueChange:F,children:[e.jsx(ke,{className:I(re),"aria-label":"Node",children:c?e.jsxs(e.Fragment,{children:[e.jsx(gt,{isCurrent:L}),e.jsx("span",{className:"max-w-[10rem] truncate",children:c.name})]}):e.jsx(Pe,{placeholder:"Node"})}),e.jsx(Se,{children:at(l,n)})]}),e.jsxs(ye,{value:p,onValueChange:v=>M(v),children:[e.jsxs(ke,{className:I(re),"aria-label":"Agent",children:[e.jsx(ut,{agent:p}),e.jsx("span",{children:p})]}),e.jsx(Se,{children:Or()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(et,{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(He,{value:y,onChange:v=>X(v.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(Me,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:ae?"Loading...":`${z.length} session${z.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-lg",children:[ae&&e.jsx("div",{className:"absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden bg-primary/10",children:e.jsx("div",{className:"h-full w-1/3 animate-indeterminate-bar bg-primary/70"})}),e.jsxs("div",{className:"h-full space-y-1.5 overflow-y-auto pr-1 pt-1",children:[!D&&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."}),D&&!ae&&z.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:G.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),z.map(v=>{const R=v.sessionId===x;return e.jsxs("button",{type:"button",onClick:()=>w(v.sessionId),className:I("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",R?"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:I("h-2 w-2 shrink-0 rounded-full",R?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-foreground",children:v.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:gi(v.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:v.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:v.cwd})]})]},v.sessionId)})]})]}),J&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:J})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:()=>$(v=>!v),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":m,children:[e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0}),e.jsx("span",{className:"shrink-0",children:m?"Less options":"More options"}),e.jsx(Ze,{className:I("h-3.5 w-3.5 shrink-0 transition-transform",m&&"rotate-180")}),e.jsx("span",{className:"h-px flex-1 bg-border/60","aria-hidden":!0})]}),m&&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(Me,{htmlFor:"native-session-id",className:"text-xs font-medium text-muted-foreground",children:"Session ID"}),e.jsx(He,{id:"native-session-id",type:"text",value:T,onChange:v=>{w(""),U(v.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:h,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(Me,{htmlFor:"native-session-title",className:"text-xs font-medium text-muted-foreground",children:"Task title"}),e.jsx(He,{id:"native-session-title",type:"text",value:b,onChange:v=>S(v.target.value),placeholder:"Optional",className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm"})]})]}),e.jsx(Ss,{value:B,onChange:v=>{w(""),K(v)},assignTo:D,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(Me,{className:"text-xs font-medium text-muted-foreground",children:"Mode"}),e.jsxs(ye,{value:A,onValueChange:v=>_(v),children:[e.jsx(ke,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Pe,{placeholder:"Select mode"})}),e.jsx(Se,{children:pi()})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Me,{className:"text-xs font-medium text-muted-foreground",children:"Priority"}),e.jsxs(ye,{value:P,onValueChange:E,children:[e.jsx(ke,{className:"h-10 rounded-sm border-border/70 bg-background/70 text-sm",children:e.jsx(Pe,{placeholder:"Select priority"})}),e.jsxs(Se,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]})]})]})]})]}),e.jsxs("div",{className:I("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",j),children:[i&&e.jsx(O,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:f}),e.jsx(O,{type:"submit",disabled:!de||Q,className:"rounded-sm px-5",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"})," Loading..."]}):N})]})]})}function Ia(s,t,n=!1){const o=s.trim();if(o)return o;const r=t.trim().split(`
139
- `).map(i=>i.trim()).find(Boolean);return r?r.length>72?`${r.slice(0,69).trimEnd()}...`:r:n?"Image task":""}function vi(s){var g;const t=s.title.trim(),n=Ia(s.title,s.description,s.images.length>0),o=s.description.trim()||n,r=s.mode??xs,i=va(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 ji({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,className:g,footerClassName:j,submitLabel:N="Create chat",cancelLabel:f="Cancel",autoFocus:h=!1,layout:l="default"}){const[u,b]=a.useState(""),[S,p]=a.useState(""),[M,x]=a.useState("claudecode"),[w,T]=a.useState(xs),[U,B]=a.useState(""),[K,D]=a.useState(""),[F,P]=a.useState("normal"),E=a.useMemo(()=>Ra(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),A=a.useMemo(()=>{var se;return n&&E.some(ce=>ce.id===n)?n:((se=E[0])==null?void 0:se.id)??""},[E,n]),[_,Q]=a.useState(A),[V,G]=a.useState(!1),[ie,ae]=a.useState(!1),{images:ee,error:J,fileInputRef:H,pickImages:W,handleFileChange:Y,handlePaste:de,removeImage:m}=Aa(),$=a.useMemo(()=>E.find(se=>se.id===_)??null,[_,E]),y=!!(n&&($==null?void 0:$.id)===n),X=Na(M),c=Fr(w);a.useEffect(()=>{_&&E.some(se=>se.id===_)||Q(A)},[_,E,A]),a.useEffect(()=>{B($a(_)),D("")},[_]),a.useEffect(()=>{D("")},[U]);const L=a.useCallback(async se=>{se.preventDefault();const ce=vi({title:u,description:S,agent:M,project:U,branch:K,priority:F,assignTo:_,mode:w,images:ee});if(ce){G(!0);try{const he=await Bn(ce);r(he)}catch(he){oe.error(he instanceof Error?he.message:"Failed to create task")}finally{G(!1)}}},[u,S,M,U,K,F,_,w,ee,r]),z=Ia(u,S,ee.length>0),re=!!(z&&M&&_&&(S.trim()||ee.length>0)),v=a.useCallback(se=>{var ce;se.nativeEvent.isComposing||se.key==="Enter"&&(se.ctrlKey||se.metaKey)&&re&&!V&&(se.preventDefault(),(ce=se.currentTarget.form)==null||ce.requestSubmit())},[re,V]),R=ee.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:ee.map((se,ce)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:ja(se),alt:se.filename??`attachment ${ce+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>m(ce),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 ${se.filename??`image ${ce+1}`}`,children:e.jsx(Ge,{className:"h-3.5 w-3.5"})})]},`${se.filename??"image"}-${ce}`))}),te=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Assign to"}),e.jsxs(ye,{value:_,onValueChange:Q,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select node"})}),e.jsx(Se,{children:at(E,n)})]})]}),ge=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Agent"}),e.jsxs(ye,{value:M,onValueChange:x,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select agent"})}),e.jsx(Se,{children:It()})]})]}),Ce=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Mode"}),e.jsxs(ye,{value:w,onValueChange:se=>T(se),children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select mode"})}),e.jsx(Se,{children:Ot()})]})]}),be=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Priority"}),e.jsxs(ye,{value:F,onValueChange:P,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select priority"})}),e.jsxs(Se,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]})]}),Ke=e.jsx(Ss,{value:U,onChange:B,assignTo:_,nodes:s,assignableNodes:E}),$e=e.jsx(Ht,{value:K,onChange:D,project:U,assignTo:_,nodes:s,assignableNodes:E});return l==="composer"?e.jsxs("form",{onSubmit:L,className:I("space-y-4",g),children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:Y,className:"hidden"}),(()=>{const se="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",ce="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",he="border-border/70 bg-background/55 text-foreground",k=M==="claudecode",Ne=w===xs;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(ye,{value:_,onValueChange:Q,children:[e.jsx(ke,{className:I(se,he,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${($==null?void 0:$.name)??"unassigned"}`,"aria-label":`Assigned node: ${($==null?void 0:$.name)??"unassigned"}`,children:$?e.jsxs(e.Fragment,{children:[e.jsx(gt,{isCurrent:y}),e.jsx("span",{className:"min-w-0 truncate",children:$.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:y?"current":"remote"})]}):e.jsx(Pe,{placeholder:"Select node"})}),e.jsx(Se,{children:at(E,n)})]}),ie?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(He,{id:"task-title-composer",type:"text",value:u,onChange:Z=>b(Z.target.value),onKeyDown:Z=>{(Z.key==="Enter"||Z.key==="Escape")&&(Z.preventDefault(),ae(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(O,{type:"button",variant:"ghost",size:"icon",onClick:()=>ae(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(us,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>ae(!0),className:"chat-composer__title-button flex min-w-0 items-center gap-1.5 rounded-sm px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-background/55 hover:text-foreground",title:z||"Title","aria-label":z?`Edit title: ${z}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:z||"Title"}),e.jsx(ls,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:S,onChange:Z=>p(Z.target.value),onKeyDown:v,onPaste:de,placeholder:"Ask anything...",rows:4,autoFocus:h,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none rounded-xl bg-transparent px-5 pt-2 pb-2 text-[15px] leading-7 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsxs("div",{className:"chat-composer__rail flex flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(O,{type:"button",variant:"ghost",size:"icon",onClick:W,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Zs,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(ye,{value:M,onValueChange:x,children:[e.jsxs(ke,{className:I(se,"chat-composer__icon-trigger",k?ce:he),title:`Agent: ${X}`,"aria-label":`Agent: ${X}`,children:[e.jsx(ut,{agent:M}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:X})]}),e.jsx(Se,{children:It()})]}),e.jsxs(ye,{value:w,onValueChange:Z=>T(Z),children:[e.jsxs(ke,{className:I(se,"chat-composer__icon-trigger",Ne?ce:he),title:`Mode: ${c}`,"aria-label":`Mode: ${c}`,children:[e.jsx(Lo,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:c})]}),e.jsx(Se,{children:Ot()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(ye,{value:F,onValueChange:P,children:[e.jsx(ke,{"aria-label":`Priority: ${F}`,title:`Priority: ${F}`,className:I("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(to,{className:I("h-4 w-4",F==="critical"&&"fill-destructive/20")})}),e.jsxs(Se,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]}),i&&e.jsxs(O,{type:"button",variant:"ghost",size:"sm",onClick:i,"aria-label":f,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(Ge,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:f})]}),e.jsxs(O,{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(ue,{className:"h-4 w-4 animate-spin"}):e.jsx(Da,{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 Z="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Ss,{value:U,onChange:B,assignTo:_,nodes:s,assignableNodes:E,layout:"composer",chipClassName:se,chipActiveClassName:Z,chipInactiveClassName:Z,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(Ht,{value:K,onChange:D,project:U,assignTo:_,nodes:s,assignableNodes:E,layout:"composer",chipClassName:se,chipActiveClassName:Z,chipInactiveClassName:Z,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(R||J)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 bg-background/45 p-4",children:[R,J&&e.jsx("div",{className:"text-xs text-destructive",children:J}),!J&&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:L,className:I("space-y-5",g),children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:Y,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{htmlFor:"task-description",className:"text-sm font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:S,onChange:se=>p(se.target.value),onKeyDown:v,onPaste:de,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:h,className:"flex min-h-[144px] w-full resize-none 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(O,{type:"button",variant:"outline",onClick:W,className:"rounded-sm",children:[e.jsx(Zs,{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."})]}),R,J&&e.jsx("p",{className:"text-xs text-destructive",children:J})]}),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(Me,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(He,{id:"task-title",type:"text",value:u,onChange:se=>b(se.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:z?`Will appear as: ${z}`:"A title will be generated from the first line of the prompt."})]}),ge,Ce]}),Ke,$e,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[be,te]}),e.jsxs("div",{className:I("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",j),children:[i&&e.jsx(O,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:f}),e.jsx(O,{type:"submit",disabled:!re||V,className:"rounded-sm px-5",children:V?"Creating...":N})]})]})}function Ni({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,defaultMode:g="chat",mode:j,onModeChange:N,layout:f="default",className:h,footerClassName:l,autoFocus:u=!1}){const[b,S]=a.useState(g),p=j!==void 0,M=p?j:b,x=w=>{p||S(w),N==null||N(w)};return e.jsxs("div",{className:I("space-y-4",h),children:[!p&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 bg-background/45 p-1",children:[e.jsxs(O,{type:"button",variant:M==="chat"?"default":"ghost",onClick:()=>x("chat"),className:"flex-1 rounded-sm",children:[e.jsx(Ln,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(O,{type:"button",variant:M==="native"?"default":"ghost",onClick:()=>x("native"),className:"flex-1 rounded-sm",children:[e.jsx(xt,{className:"h-4 w-4"}),"Load session"]})]}),M==="chat"?e.jsx(ji,{nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,footerClassName:l,submitLabel:f==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:u,layout:f}):e.jsx(bi,{nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,footerClassName:l,autoFocus:u})]})}const rs="72f988bf-86f1-41af-91ab-2d7cd011db47",Oa=`${rs} (MSIT)`;function wi({open:s,onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i=!1,shareResult:g}){return e.jsx(it,{open:s,onOpenChange:t,children:e.jsxs(lt,{className:"max-w-md rounded-xl p-5",children:[e.jsx(dt,{className:"sr-only",children:"Share conversation"}),e.jsx(yi,{onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i,shareResult:g})]})})}function yi({onOpenChange:s,onShare:t,onStopShare:n,sharing:o,stopping:r=!1,shareResult:i}){const[g,j]=a.useState((i==null?void 0:i.tenant)??rs),[N,f]=a.useState((i==null?void 0:i.scope)??"chat"),h=i!=null&&i.url?oa(i.url):null,l=o||r;return a.useEffect(()=>{j((i==null?void 0:i.tenant)??rs),f((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(ki,{value:g,onChange:j,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(Kt,{active:N==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>f("chat")}),e.jsx(Kt,{active:N==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>f("filesPreview")})]})]}),h&&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:h,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(O,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void ns(h,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(ia,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e.jsx(O,{variant:"outline",onClick:()=>s(!1),disabled:l,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(O,{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(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(O,{onClick:()=>void t({tenant:g,scope:N}),disabled:l,className:"h-8 text-xs",children:[o&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function ki({value:s,onChange:t,disabled:n}){const[o,r]=a.useState(!1),[i,g]=a.useState(!1),[j,N]=a.useState(s),f=a.useRef(null);a.useEffect(()=>{N(s)},[s]),a.useEffect(()=>{if(!o)return;const l=b=>{var p;const S=b.target;S instanceof Node&&((p=f.current)!=null&&p.contains(S)||(r(!1),g(!1)))},u=b=>{b.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 h=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:f,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:Si(s)}),e.jsx(Ze,{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:()=>h(rs),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:Oa}),s===rs&&e.jsx(us,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]}),e.jsx("div",{className:"border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:i?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:j,onChange:l=>N(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),h(j))},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:()=>h(j),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(us,{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(Ge,{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(ls,{className:"h-3 w-3"})]})})]})]})]})}function Si(s){return s===rs?Oa:s}function Kt({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 Ci(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 _i({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(po,{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:Ci(n.content)}),t&&e.jsx(O,{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(Ge,{className:"h-3 w-3"})})]},n.id))})]})})}const Ei=a.lazy(async()=>({default:(await ct(()=>import("./FilesTab-CYA4YD9M.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Di=a.lazy(async()=>({default:(await ct(()=>import("./PreviewTab-Cz-QrEJn.js"),__vite__mapDeps([6,1,2,7]))).PreviewTab})),Ti=a.lazy(async()=>({default:(await ct(()=>import("./DiffTab-CPqcA12G.js"),__vite__mapDeps([8,1,2,4,3,5,7]))).DiffTab}));function Mi({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,activeTab:j,setActiveTab:N,creatingTask:f,createMode:h,activeTask:l,assignedNode:u,taskLoading:b,taskError:S,displayEvents:p,initialPromptAlreadyInLogs:M,initialPrompt:x,supportsFollowUp:w,taskUnavailable:T,chatDisabled:U,chatDisabledReason:B,questionBypassEnabled:K,isRunning:D,isStarting:F,hasPendingFollowUp:P,canCancel:E,canRetry:A,onRetry:_,onCancel:Q,onShareTask:V,onStopShareTask:G,onStartCreateTask:ie,onCancelCreateTask:ae,onCreateTask:ee,onSendMessage:J,onCancelQueuedMessage:H,onQuestionBypassChange:W,onSubmitQuestionResponse:Y,messagesEndRef:de}){const[m,$]=a.useState(!1),[y,X]=a.useState(!1),[c,L]=a.useState(!1),[z,re]=a.useState(!1),[v,R]=a.useState(!1),[te,ge]=a.useState({}),[Ce,be]=a.useState(new Set),[Ke,$e]=a.useState(new Set),se=a.useRef(0),ce=a.useRef(!1),he=a.useRef(null),k=a.useRef(0),Ne=a.useCallback(Ee=>{const ve=Ee.currentTarget,Be=se.current;if(se.current=ve.scrollTop,ce.current)return;if(ve.scrollHeight-ve.scrollTop-ve.clientHeight<30){$(!1),ce.current=!0,setTimeout(()=>{ce.current=!1},300);return}ve.scrollTop<Be&&Be-ve.scrollTop>10&&$(!0),ve.scrollTop<=0&&$(!0)},[]),Z=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",Ae=l?(u==null?void 0:u.name)??la(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",Fe=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:Ae}),"..."]}):"Connecting session to an available node...",cs=l?[{label:"Working dir",value:Z,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:Ae}]:[],Re=!!(x&&!M),Ue=Re||p.length>0,Le=D&&Ue,_e=(F||P||D)&&!Le,fe=(l==null?void 0:l.conversationKind)==="nativeSession",Qe=(l==null?void 0:l.queuedMessages)??[],es=a.useMemo(()=>zr(p),[p]),_s=a.useMemo(()=>Ur("transcript",es.map(Ee=>Ee.event)),[es]),Es=l&&!Ce.has(l.id)?te[l.id]??l.activeShare??null:null;return f?e.jsx(Ai,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,defaultMode:h,onCancel:ae,onCreated:ee}):!l&&b?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(nt,{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(ue,{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(ue,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(da,{value:j,onValueChange:Ee=>{j==="transcript"&&he.current&&(k.current=he.current.scrollTop),N(Ee),Ee==="transcript"&&requestAnimationFrame(()=>{he.current&&(he.current.scrollTop=k.current)})},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(Fa,{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}),fe&&e.jsx(Te,{variant:"outline",className:"shrink-0 rounded-sm border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",children:"Native session"}),e.jsx(ca,{status:l.status}),e.jsx($n,{priority:l.priority}),e.jsx(O,{variant:"outline",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:"ml-auto h-7 w-7 shrink-0 rounded-sm border-border/70 bg-background/68",children:o?e.jsx(ft,{className:"h-4 w-4"}):e.jsx(Ea,{className:"h-4 w-4"})})]}),S&&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:S}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsxs(ua,{className:"h-auto max-w-full overflow-x-auto rounded-sm bg-muted/70 p-0.5",children:[e.jsx(Je,{value:"transcript",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Transcript"}),e.jsx(Je,{value:"files",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Files"}),e.jsx(Je,{value:"preview",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Preview"}),e.jsx(Je,{value:"diff",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Diff"})]}),D&&e.jsx(Te,{variant:"outline",className:"hidden rounded-sm border-amber-500/30 bg-amber-500/10 text-amber-700 sm:inline-flex dark:text-amber-300",children:"Working"}),T&&e.jsx(Te,{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-2 text-[10px] text-muted-foreground",children:[e.jsxs("span",{className:"hidden sm:inline",children:["updated ",Rn(l.updatedAt)]}),e.jsx("span",{className:"font-mono",children:l.id.slice(0,8)}),A&&e.jsxs(O,{variant:"outline",size:"sm",onClick:_,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(_o,{className:"h-3.5 w-3.5"}),"Retry"]}),e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:T,title:T?"Unavailable tasks cannot be shared.":"Share conversation",className:"h-7 shrink-0 rounded-sm border-primary/30 bg-primary/10 px-2 text-[11px] text-primary hover:bg-primary/15 hover:text-primary disabled:border-border/60 disabled:bg-muted/40 disabled:text-muted-foreground",onClick:()=>L(!0),children:[e.jsx(Mo,{className:"h-3.5 w-3.5"}),"Share"]})]})]})]}),e.jsx(Ye,{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:he,className:"min-h-0 flex-1 touch-pan-y overflow-x-hidden overflow-y-auto overscroll-x-none bg-gradient-to-b from-background/15 via-transparent to-background/35 px-3 py-5 sm:px-5",onScroll:Ne,children:e.jsxs("div",{className:"mx-auto flex max-w-[72rem] flex-col gap-5",children:[Re&&x&&e.jsx(Ft,{event:x,agent:l.agent,questionBypassEnabled:K,onQuestionBypassChange:W,onSubmitQuestionResponse:Y,questionResponseDisabled:!w||U}),es.map(({event:Ee,subItems:ve},Be)=>e.jsx(Ft,{event:Ee,agent:l.agent,subItems:ve,questionBypassEnabled:K,onQuestionBypassChange:W,onSubmitQuestionResponse:Y,questionResponseDisabled:!w||U},_s[Be])),!Ue&&!_e&&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:"Transcript is warming up"}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:b?"Fetching task output...":fe?"This native session is attached. Transcript starts after the next message you send from Meshy.":"The opening prompt has been stored, but the agent has not emitted conversation output yet."})]}),(!w&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!w&&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&&!Ke.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:()=>$e(Ee=>new Set(Ee).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(Ge,{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})]})]}),_e&&e.jsx(Wt,{children:Fe}),Le&&e.jsx(Wt,{children:"The agent is still working on this conversation."}),e.jsx("div",{ref:de})]})}),w?e.jsxs(e.Fragment,{children:[m&&e.jsx(O,{size:"icon",onClick:()=>$(!1),className:"absolute bottom-4 right-4 z-10 h-12 w-12 rounded-lg shadow-lg",children:e.jsx(ls,{className:"h-4 w-4"})}),e.jsxs("div",{className:`shrink-0 ${m?"hidden":""}`,children:[e.jsx(_i,{messages:Qe,onCancelMessage:H}),e.jsx("div",{className:"mx-auto w-full max-w-[72rem]",children:e.jsx(Qo,{onSend:J,disabled:U,disabledReason:B,contextItems:cs,placeholder:U?B:D?"Queue a message for the next turn...":"Continue the conversation...",running:D||P,onStop:E?()=>X(!0):void 0})})]})]}):e.jsx("div",{className:"shrink-0 border-t border-border/60 px-3 py-3 text-[11px] text-muted-foreground sm:px-5",children:"This task does not expose follow-up chat messages. Use Files, Preview, or Diff to inspect the result."})]})}),e.jsx(Ye,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Is,{label:"Loading files..."}),children:e.jsx(Ei,{taskId:l.id})})}),e.jsx(Ye,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Is,{label:"Loading preview..."}),children:e.jsx(Di,{taskId:l.id})})}),e.jsx(Ye,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Is,{label:"Loading diff..."}),children:e.jsx(Ti,{taskId:l.id})})}),e.jsx(zs,{open:y,onOpenChange:X,children:e.jsxs(Us,{children:[e.jsxs(Vs,{children:[e.jsx(qs,{children:"Stop this task?"}),e.jsx(Hs,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(Ks,{children:[e.jsx(Ws,{children:"Keep running"}),e.jsx(Gs,{onClick:Q,children:"Stop task"})]})]})}),e.jsx(wi,{open:c,onOpenChange:L,sharing:z,stopping:v,shareResult:Es,onShare:async Ee=>{if(!l)return null;re(!0);try{const ve=await V(Ee);return ve!=null&&ve.url&&(ge(Be=>({...Be,[l.id]:ve})),be(Be=>{const ss=new Set(Be);return ss.delete(l.id),ss})),ve}finally{re(!1)}},onStopShare:async()=>{if(!l)return!1;R(!0);try{const Ee=await G();return Ee!==!1&&(ge(ve=>{const Be={...ve};return delete Be[l.id],Be}),be(ve=>new Set(ve).add(l.id))),Ee}finally{R(!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(nt,{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(Pn,{className:"h-7 w-7"})}),e.jsx("h2",{className:"mt-5 text-xl font-semibold tracking-tight text-foreground sm:text-3xl",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-3 max-w-xl text-[11px] leading-6 text-muted-foreground",children:"Open a task from the left sidebar to continue the conversation, or start a new task or load a native session."}),e.jsxs(O,{onClick:ie,className:"mt-6 rounded-lg px-5",children:[e.jsx(ht,{className:"h-4 w-4"}),"Start or load chat"]}),S&&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:S})]})})]})}function Wt({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 Ai({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,defaultMode:j,onCancel:N,onCreated:f}){var b,S,p;const[h,l]=a.useState(j??"chat");a.useEffect(()=>{j&&l(j)},[j]);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:ht},{value:"native",label:"Load session",icon:xt}].map(M=>{const x=M.icon,w=M.value===h;return e.jsxs("button",{type:"button",onClick:()=>l(M.value),"aria-pressed":w,className:I("flex items-center gap-1.5 rounded-sm px-2 py-1 transition-all duration-200",w?"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(x,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:M.label})]},M.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(nt,{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(Ni,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(b=i==null?void 0:i.self)==null?void 0:b.role,currentNodeId:((S=i==null?void 0:i.self)==null?void 0:S.id)??null,leaderNodeId:((p=i==null?void 0:i.leader)==null?void 0:p.id)??null,mode:h,onModeChange:l,onCreated:f,onCancel:N,autoFocus:!0,layout:"composer"})})})]})}function nt({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(Fa,{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(O,{variant:"outline",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:"h-7 w-7 shrink-0 rounded-sm border-border/70 bg-background/68",children:o?e.jsx(ft,{className:"h-4 w-4"}):e.jsx(Ea,{className:"h-4 w-4"})})]})}function Fa({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(O,{variant:"outline",size:"icon",onClick:n,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:"h-7 w-7 shrink-0 rounded-sm border-border/70 bg-background/68",children:o?e.jsx(_a,{className:"h-4 w-4"}):e.jsx(jo,{className:"h-4 w-4"})})}function Li({onAdded:s}){const[t,n]=a.useState(""),[o,r]=a.useState(!1),[i,g]=a.useState(null),j=a.useCallback(async N=>{if(N.preventDefault(),!!t.trim()){r(!0),g(null);try{await In({leaderEndpoint:t.trim(),transport:"devtunnel"}),s()}catch(f){g(f instanceof Error?f.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(ma,{className:"space-y-2 text-left",children:[e.jsx(dt,{className:"text-2xl tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Verify the remote leader's DevTunnel endpoint, sync this node's tasks to that leader, and join the cluster as a follower."})]})}),e.jsxs("form",{onSubmit:j,className:"space-y-4 px-6 py-5",children:[i&&e.jsx("div",{className:"rounded-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(Me,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Te,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(He,{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(xa,{className:"border-t border-border/60 pt-4",children:e.jsx(O,{type:"submit",disabled:!t.trim()||o,className:"rounded-sm",children:o?"Joining...":"Join node"})})]})]})})}function Bi({open:s,onOpenChange:t,onAdded:n}){return e.jsx(it,{open:s,onOpenChange:t,children:e.jsx(Li,{onAdded:()=>{t(!1),n()}})})}const Pi=10,Xe="__all__";function ze(s){return"session"in s}function Gt(s,t){var n;return t&&s.some(o=>o.id===t)?t:((n=s[0])==null?void 0:n.id)??""}function Fs(s){return s&&($a(s.id)||s.workDir)||""}function js(s,t,n){let o=!1;const r=s.map(i=>ze(i)&&i.session.id===n.id?(o=!0,{...i,nodeName:t,session:n}):i);return rt(o?r:[...r,{id:`session-${n.id}`,nodeName:t,session:n}])}function za(s,t){return s.filter(ze).filter(n=>n.session.nodeId===t).sort((n,o)=>o.session.startedAt-n.session.startedAt)}function $i(s){const t=s.filter(ze).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 Ri(s,t){return!!(s&&t&&!s.contains(t))}function Ii(s,t,n){var r;if(n===Xe)return n;const o=za(s,t);return o.some(i=>i.session.id===n)?n:((r=o[0])==null?void 0:r.session.id)??Xe}function Oi(s,t,n){return n===Xe?s.filter(o=>!ze(o)||o.session.nodeId===t):s.filter(o=>ze(o)&&o.session.nodeId===t&&o.session.id===n)}function rt(s){const t=s.map((o,r)=>({entry:o,index:r})).filter(({entry:o})=>ze(o)&&o.session.status!=="running").sort((o,r)=>!ze(o.entry)||!ze(r.entry)?0:r.entry.session.startedAt-o.entry.session.startedAt||r.index-o.index),n=new Set(t.slice(0,Pi).map(({entry:o})=>ze(o)?o.session.id:""));return s.filter(o=>!ze(o)||o.session.status==="running"||n.has(o.session.id))}function ot(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 Fi(s){const t=s.session.command.length>48?`${s.session.command.slice(0,45)}...`:s.session.command;return`${s.nodeName} - ${ot(s.session)} - ${t}`}function Ua(s,t=48){return s.length>t?`${s.slice(0,t-3)}...`:s}function zi(s,t){return t===Xe?"All sessions":s?Ua(s.session.command,34):"Command session"}function Qt(s){return s.status==="stopped"?"":s.stderr}function Ui({nodes:s,defaultNodeId:t,onClose:n,initialHistory:o=[]}){const[r,i]=a.useState(()=>Gt(s,t)),g=a.useMemo(()=>s.find(m=>m.id===r)??s[0]??null,[s,r]),[j,N]=a.useState(()=>Fs(g)),[f,h]=a.useState(""),[l,u]=a.useState(()=>rt(o)),[b,S]=a.useState(Xe),[p,M]=a.useState(!1),[x,w]=a.useState(!1),[T,U]=a.useState(!1),[B,K]=a.useState(!1),[D,F]=a.useState(!1),P=a.useRef(null),E=a.useRef(null),A=a.useMemo(()=>s.find(m=>m.id===r)??s[0]??null,[s,r]),_=a.useMemo(()=>za(l,(A==null?void 0:A.id)??""),[l,A]),Q=a.useMemo(()=>$i(_),[_]),V=a.useMemo(()=>_.find(m=>m.session.id===b),[b,_]),G=a.useMemo(()=>Oi(l,(A==null?void 0:A.id)??"",b),[l,A,b]),ie=a.useRef((A==null?void 0:A.id)??"");a.useEffect(()=>{r&&s.some(m=>m.id===r)||i(Gt(s,t))},[t,s,r]),a.useEffect(()=>{const m=(A==null?void 0:A.id)??"";ie.current!==m&&(ie.current=m,N(Fs(A)))},[A]),a.useEffect(()=>{S(m=>Ii(l,(A==null?void 0:A.id)??"",p?m:""))},[l,A,p]),a.useEffect(()=>{var m;(m=P.current)==null||m.scrollTo({top:P.current.scrollHeight})},[l]),a.useEffect(()=>{let m=!1;async function $(){const y=await Promise.allSettled(s.map(async X=>({node:X,response:await Fn(X.id)})));m||u(X=>y.reduce((c,L)=>L.status!=="fulfilled"?c:L.value.response.sessions.reduce((z,re)=>js(z,L.value.node.name,re),c),X))}return s.length>0&&$(),()=>{m=!0}},[s]),a.useEffect(()=>{const m=l.filter(ze).filter(y=>y.session.status==="running");if(m.length===0)return;const $=window.setInterval(()=>{for(const y of m)On(y.session.nodeId,y.session.id).then(X=>u(c=>js(c,y.nodeName,X))).catch(()=>{})},1e3);return()=>window.clearInterval($)},[l]);const ae=a.useRef(null);async function ee(m){if(m.preventDefault(),!A||!f.trim()||D)return;const $=f.trim(),y=A.name;F(!0),h("");try{const X=await Un(A.id,{command:$,...j.trim()?{cwd:j.trim()}:{}});u(c=>js(c,y,X)),S(X.id),M(!0)}catch(X){u(c=>[...c,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:y,command:$,error:X instanceof Error?X.message:"Command failed"}])}finally{F(!1)}}async function J(m,$){m.stopPropagation();const y=await zn($.session.nodeId,$.session.id);u(X=>js(X,$.nodeName,y))}function H(m){S(m),M(!0),w(!1)}function W(m){x&&Ri(E.current,m.target)&&w(!1)}function Y(m,$,y,X,c){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:X,"aria-label":`Toggle ${m} sessions`,"aria-expanded":!y,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:m}),e.jsx(Ze,{className:I("h-3 w-3 transition-transform",y&&"-rotate-90")})]}),!y&&($.length>0?$.map(de):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:c}))]})}function de(m){const $=b===m.session.id,y=m.session.status==="running";return e.jsxs("div",{className:I("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",$&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>H(m.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:I("flex h-4 w-4 shrink-0 items-center justify-center",y?"text-primary":m.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:y?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):m.session.status==="exited"?e.jsx(Bt,{className:"h-3 w-3"}):e.jsx(ys,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:Ua(m.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[m.nodeName," · ",ot(m.session)]})]})]}),y&&e.jsx("button",{type:"button",onClick:X=>void J(X,m),"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(Ut,{className:"h-3 w-3"})})]},m.session.id)}return e.jsx("section",{className:"dashboard-panel node-terminal animate-composer-settle shrink-0 overflow-visible rounded-xl","aria-label":"Node terminal",onClick:W,children:e.jsxs("div",{className:"flex w-full flex-col overflow-visible rounded-[inherit] bg-card/72 text-card-foreground",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"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(Rs,{className:"h-3.5 w-3.5"})}):e.jsx(Rs,{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:E,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":x,title:V?Fi(V):"All sessions",onClick:()=>w(m=>!m),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:zi(V,b)}),e.jsx(Ze,{className:I("h-3 w-3 shrink-0 text-muted-foreground transition-transform",x&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!x,className:I("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!x&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>H(Xe),className:I("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",b===Xe&&"bg-primary/10 text-primary"),children:[e.jsx(Rs,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),Y("Active",Q.active,T,()=>U(m=>!m),"No active sessions"),Y("Completed",Q.completed,B,()=>K(m=>!m),"No completed sessions")]})})]}),e.jsx("select",{value:(A==null?void 0:A.id)??"",onChange:m=>{i(m.target.value),M(!1),N(Fs(s.find($=>$.id===m.target.value)??null))},disabled:D||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(m=>e.jsx("option",{value:m.id,className:"bg-background text-foreground",children:m.name},m.id))}),e.jsx(Ss,{value:j,onChange:N,assignTo:(A==null?void 0:A.id)??"",nodes:s,assignableNodes:s,layout:"composer",chipClassName:"node-terminal__control h-7 max-w-[18rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground hover:bg-muted/65",chipActiveClassName:"font-mono",chipInactiveClassName:"text-muted-foreground",labelClassName:"node-terminal__control",triggerClassName:"terminal-workdir-trigger",popoverPlacement:"top",popoverAlign:"end"})]})]}),e.jsxs("div",{ref:P,className:"node-terminal__body max-h-64 min-h-[8rem] overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>{var m;return(m=ae.current)==null?void 0:m.focus()},children:[G.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:G.map(m=>ze(m)?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:[m.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:m.session.command}),e.jsxs("span",{className:I("inline-flex items-center gap-1",m.session.status==="running"||m.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[m.session.status==="running"?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):m.session.status==="exited"?e.jsx(Bt,{className:"h-3 w-3"}):e.jsx(ys,{className:"h-3 w-3"}),ot(m.session)]}),m.session.status==="running"&&e.jsx("button",{type:"button",onClick:$=>void J($,m),"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(Ut,{className:"h-3 w-3"})})]}),m.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:m.session.stdout}),Qt(m.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Qt(m.session)}),(m.session.stdoutTruncated||m.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},m.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:[m.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:m.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(ys,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:m.error})]},m.id))}),e.jsxs("form",{onSubmit:ee,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:A?`${A.name}$`:"$"}),e.jsx("input",{ref:ae,value:f,onChange:m=>h(m.target.value),disabled:!A||D,placeholder:A?"":"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:!A||!f.trim()||D,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:text-muted-foreground disabled:opacity-50",children:D?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(mt,{className:"h-3 w-3"})})]})]})]})})}function bt({nodeId:s,nodeName:t,onOpenSettings:n,onOpenDevBox:o,onStartDevBox:r,showConfigureDevBox:i,showStartDevBox:g,startDevBoxPending:j,className:N}){const[f,h]=a.useState(!1),l=a.useRef(null),u=j?"Starting":"Start DevBox";return a.useEffect(()=>{if(!f)return;const b=p=>{var x;const M=p.target;M instanceof Node&&((x=l.current)!=null&&x.contains(M)||h(!1))},S=p=>{p.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",b),document.addEventListener("keydown",S),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",S)}},[f]),e.jsxs("div",{ref:l,className:I("relative shrink-0",N),onClick:b=>b.stopPropagation(),children:[e.jsx(O,{type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${t}`,"aria-haspopup":"menu","aria-expanded":f,title:`More actions for ${t}`,onClick:()=>h(b=>!b),className:I("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",f&&"bg-background/80 text-primary"),children:e.jsx(eo,{className:"h-3.5 w-3.5"})}),f&&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:()=>{h(!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(Vn,{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:()=>{j||(h(!1),r(s))},disabled:j,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:[j?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(mt,{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:()=>{h(!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(qn,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Configure DevBox"})]})]})]})}const Vi=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),qi=new Set(["startinprogress","starting"]);function os(s){return!!(s!=null&&s.enabled&&s.name)}function Hi(s){const t=s==null?void 0:s.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(t&&Vi.has(t))}function is(s){const t=s==null?void 0:s.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(t&&qi.has(t))}function Cs(s,t,n){return s==="offline"&&Hi(t)&&os(n)}function Jt(s,t){return s==="offline"&&os(t)}function Yt(s){return!os(s)}function Ki({nodeStatus:s,status:t,current:n,selected:o}){const r=o??n;return r&&Cs(s,t,r)?r:null}function De(s){return s.scope||`name:${s.name??""}`}function Wi({previousKey:s,baseDevBox:t,listed:n}){if(s&&n.some(i=>De(i)===s))return s;if(!os(t))return n[0]?De(n[0]):"";const o=De(t),r=n.find(i=>De(i)===o)??n.find(i=>i.name===t.name);return r?De(r):o}function Xt({cluster:s,systemInfo:t,nodeNameById:n,nodeBlockingTaskCounts:o,eventTypeFilter:r,onEventTypeFilterChange:i,eventTypeOptions:g,filteredEvents:j,sseConnected:N,clusterLoading:f,clusterError:h,promotePending:l,onPromote:u,onAddNode:b,leavePending:S,onLeaveCluster:p,onToggleNodeDevTunnel:M,devTunnelNodeId:x,devBoxStartNodeId:w,devBoxStartingNodeIds:T=new Set,onOpenNodeSettings:U,onOpenDevBox:B,onStartDevBox:K,onClose:D}){var ae,ee,J;const F=((ae=s==null?void 0:s.self)==null?void 0:ae.role)==="leader",P=((ee=s==null?void 0:s.self)==null?void 0:ee.role)==="follower"&&!(s!=null&&s.leader),E=(s==null?void 0:s.self)??null,_=Hn((s==null?void 0:s.nodes)??[],E==null?void 0:E.id).filter(H=>H.id!==(E==null?void 0:E.id)),Q=s!=null&&s.leader?s.nodes.find(H=>{var W;return H.id===((W=s.leader)==null?void 0:W.id)})??null:null,V=s!=null&&s.leader?s.leader.dashboardOrigin??(Q==null?void 0:Q.dashboardOrigin)??(t&&s.leader.id===(t.nodeId??t.id)?t.dashboardOrigin:void 0)??s.leader.endpoint:null,G=(E==null?void 0:E.role)==="leader"&&_.length===0,ie=(E==null?void 0:E.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(da,{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(O,{variant:"ghost",size:"icon",onClick:D,className:"h-6 w-6 rounded-sm",children:e.jsx(ft,{className:"h-3.5 w-3.5"})})]}),e.jsxs(ua,{className:"mt-1.5 grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(Je,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(Je,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(Je,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})]}),e.jsx(Ye,{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:[E&&e.jsx(Zt,{node:E,systemInfo:t,blockingTaskCount:o.get(E.id)??0,devTunnelNodeId:x,onToggleNodeDevTunnel:M,showActions:!1,defaultExpanded:!1,onOpenDevBox:B,devBoxStartingNodeIds:T}),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(Te,{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"})]}),f&&!s?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):h&&!s?e.jsx("div",{className:"rounded-sm bg-destructive/10 px-2 py-1.5 text-[10px] text-destructive shadow-sm",children:h}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(as,{label:"Term",value:String((s==null?void 0:s.term)??0)}),e.jsx(as,{label:"Nodes",value:String((s==null?void 0:s.nodes.length)??0)}),e.jsx(as,{label:"Pending",value:String((s==null?void 0:s.taskSummary.pending)??0)}),e.jsx(as,{label:"Running",value:String((s==null?void 0:s.taskSummary.running)??0)}),e.jsx(as,{label:"Completed",value:String((s==null?void 0:s.taskSummary.completed)??0)}),e.jsx(as,{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:((J=s==null?void 0:s.leader)==null?void 0:J.name)??"None"}),e.jsx(qe,{label:"Leader URL",value:V??"Unavailable",mono:!0,action:V?e.jsx(hs,{label:"Copy leader URL",onClick:()=>void ns(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:P&&e.jsxs(O,{variant:"outline",size:"sm",onClick:u,disabled:l,className:"h-6 rounded-sm px-2 text-[10px]",children:[l&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(Ye,{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"}),G?e.jsx(O,{variant:"outline",size:"sm",onClick:b,className:"h-6 rounded-sm px-2 text-[10px]",children:"Join node"}):ie?e.jsxs(O,{variant:"outline",size:"sm",onClick:p,disabled:S,className:"h-6 rounded-sm px-2 text-[10px]",children:[S&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),E&&e.jsx(Zt,{node:E,systemInfo:t,blockingTaskCount:o.get(E.id)??0,devTunnelNodeId:x,onToggleNodeDevTunnel:M,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:F?U:void 0,onOpenDevBox:F?B:void 0,onStartDevBox:F?K:void 0,devBoxStartNodeId:w,devBoxStartingNodeIds:T})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",_.length,")"]}),_.length>0?e.jsx("div",{className:"space-y-1.5",children:_.map(H=>e.jsx(Gi,{node:H,isLeader:!!F,blockingTaskCount:o.get(H.id)??0,devTunnelNodeId:x,onToggleNodeDevTunnel:M,onOpenNodeSettings:F?U:void 0,onOpenDevBox:F?B:void 0,onStartDevBox:F?K:void 0,devBoxStartNodeId:w,devBoxStartingNodeIds:T},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(Ye,{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(Kn,{className:I("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(ye,{value:r,onValueChange:i,children:[e.jsx(ke,{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(Pe,{placeholder:"Event type"})}),e.jsx(Se,{children:g.map(H=>e.jsx(we,{value:H,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:H==="all"?"All event types":H},H))})]}),e.jsx(Te,{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(Wn,{events:j,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 Zt({node:s,systemInfo:t,blockingTaskCount:n,devTunnelNodeId:o,onToggleNodeDevTunnel:r,showActions:i=!0,defaultExpanded:g=!1,onOpenNodeSettings:j,onOpenDevBox:N,onStartDevBox:f,devBoxStartNodeId:h,devBoxStartingNodeIds:l}){var K,D,F,P;const[u,b]=a.useState(g),S=(t==null?void 0:t.dashboardOrigin)??s.dashboardOrigin,p=s.devtunnelEndpoint??s.endpoint,M=S??s.endpoint,x=(t==null?void 0:t.workDir)??s.workDir,w=Ma(s,t==null?void 0:t.transportType),T=pt(s,t==null?void 0:t.transportType),U=T&&ds((t==null?void 0:t.transportType)??s.transportType)?!0:Ta(s,t==null?void 0:t.transportType),B=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:()=>b(E=>!E),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[u?e.jsx(Ze,{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(ha,{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:M,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(fa,{className:"h-3 w-3"})}),j&&e.jsx(bt,{nodeId:s.id,nodeName:s.name,onOpenSettings:j,onOpenDevBox:N,onStartDevBox:f,showConfigureDevBox:(K=s.devbox)==null?void 0:K.enabled,showStartDevBox:Cs(s.status,(D=s.devbox)==null?void 0:D.lastStatus,s.devbox)||is((F=s.devbox)==null?void 0:F.lastStatus)||l.has(s.id),startDevBoxPending:h===s.id||is((P=s.devbox)==null?void 0:P.lastStatus)||l.has(s.id)})]}),e.jsxs("button",{type:"button",onClick:()=>b(E=>!E),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(pa,{role:s.role,size:"compact"}),e.jsx(Te,{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(hs,{label:"Copy dashboard URL",onClick:()=>void ns(S,"Dashboard URL copied")})}),e.jsx(qe,{label:"Node URL",value:p,mono:!0,action:e.jsx(hs,{label:"Copy node URL",onClick:()=>void ns(p,"Node URL copied")})}),x&&e.jsx(qe,{label:"Workspace",value:x,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Js,{label:"Transport",value:w}),t&&e.jsx(Js,{label:"Uptime",value:Gn(t.uptime),mono:!0})]}),e.jsx(wa,{capabilities:s.capabilities,action:i&&U?e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>r(s),disabled:o===s.id||B,className:"h-6 rounded-sm px-2 text-[10px]",title:B?"Finish assigned or running tasks before changing remote access":void 0,children:[o===s.id&&e.jsx(ue,{className:"h-3 w-3 animate-spin"}),T?"Disable Remote Access":"Enable Remote Access"]}):void 0}),i&&U&&B&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Gi({node:s,isLeader:t,blockingTaskCount:n,devTunnelNodeId:o,onToggleNodeDevTunnel:r,onOpenNodeSettings:i,onOpenDevBox:g,onStartDevBox:j,devBoxStartNodeId:N,devBoxStartingNodeIds:f}){var T,U,B,K;const[h,l]=a.useState(!1),u=s.dashboardOrigin,b=s.devtunnelEndpoint??s.endpoint,S=u??s.endpoint,p=Ma(s),M=pt(s),x=Ta(s),w=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(D=>!D),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[h?e.jsx(Ze,{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(ha,{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(fa,{className:"h-3 w-3"})}),t&&i&&e.jsx(bt,{nodeId:s.id,nodeName:s.name,onOpenSettings:i,onOpenDevBox:g,onStartDevBox:j,showConfigureDevBox:(T=s.devbox)==null?void 0:T.enabled,showStartDevBox:Cs(s.status,(U=s.devbox)==null?void 0:U.lastStatus,s.devbox)||is((B=s.devbox)==null?void 0:B.lastStatus)||f.has(s.id),startDevBoxPending:N===s.id||is((K=s.devbox)==null?void 0:K.lastStatus)||f.has(s.id)})]}),e.jsxs("button",{type:"button",onClick:()=>l(D=>!D),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(pa,{role:s.role,size:"compact"}),e.jsx(Te,{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})]})]}),h&&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(hs,{label:"Copy dashboard URL",onClick:()=>void ns(u,"Dashboard URL copied")})}),e.jsx(qe,{label:"Node URL",value:b,mono:!0,action:e.jsx(hs,{label:"Copy node URL",onClick:()=>void ns(b,"Node URL copied")})}),s.workDir&&e.jsx(qe,{label:"Workspace",value:s.workDir,mono:!0}),e.jsx(Js,{label:"Transport",value:p})]}),e.jsx(wa,{capabilities:s.capabilities,action:t&&x?e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>r(s),disabled:o===s.id||w,className:"h-6 rounded-sm px-2 text-[10px]",title:w?"Finish assigned or running tasks before changing remote access":void 0,children:[o===s.id&&e.jsx(ue,{className:"h-3 w-3 animate-spin"}),M?"Disable Remote Access":"Enable Remote Access"]}):void 0}),t&&x&&w&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function hs({label:s,onClick:t}){return e.jsx(O,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground",onClick:t,"aria-label":s,title:s,children:e.jsx(ia,{className:"h-3 w-3"})})}function Qi(s,t,n,o){var g;if(!s)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const r=((g=t==null?void 0:t.self)==null?void 0:g.role)==="follower";return s.assignedTo!==null&&s.assignedNodeAvailable===!1?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${s.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}: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..."}:ks.has(s.status)||s.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:ks.has(s.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const Ns="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",ws="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function ea({toolbarTasks:s,activeTaskId:t,tasksLoading:n,tasksError:o,isLeader:r,scope:i,agentFilter:g,nodeFilter:j,taskKindFilter:N,agentOptions:f,nodeOptions:h,nodeNameById:l,nodeStatusById:u,devBoxNodeIds:b=new Set,devBoxStartNodeIds:S=new Set,devBoxStartingNodeIds:p=new Set,leaderNodeId:M,searchQuery:x,selectedTaskIds:w,allVisibleTasksSelected:T,someVisibleTasksSelected:U,canBatchArchive:B,onSearchChange:K,onScopeChange:D,onAgentFilterChange:F,onNodeFilterChange:P,onTaskKindFilterChange:E,onToggleTaskSelected:A,onToggleAllVisibleTasks:_,onBatchArchive:Q,onBatchDelete:V,onCreateTask:G,onOpenNodeSettings:ie,onOpenDevBox:ae,onStartDevBox:ee,onSelectTask:J,onClose:H}){const[W,Y]=a.useState(!!x),[de,m]=a.useState(!1),[$,y]=a.useState(!1),X=a.useRef(null),c=a.useRef(null),L=a.useRef(null),z=w.size,re=i!=="active"||j!=="all"||g!=="all"||N!=="all",v=x.trim().length>0,[R,te]=a.useState(new Set),[ge,Ce]=a.useState(new Set),be=a.useMemo(()=>Qn(s,l,M),[s,l,M]),Ke=be.length===1,$e=!Ke||re||v,se=Ke&&(re||v),ce=a.useCallback(k=>{te(Ne=>{const Z=new Set(Ne);return Z.has(k)?Z.delete(k):Z.add(k),Z})},[]),he=a.useCallback(k=>{Ce(Ne=>{const Z=new Set(Ne);return Z.has(k)?Z.delete(k):Z.add(k),Z})},[]);return a.useEffect(()=>{x&&Y(!0)},[x]),a.useEffect(()=>{var k;W&&((k=X.current)==null||k.focus())},[W]),a.useEffect(()=>{if(!W)return;const k=Z=>{var Fe;const Ae=Z.target;Ae instanceof Node&&((Fe=c.current)!=null&&Fe.contains(Ae)||Y(!1))},Ne=Z=>{Z.key==="Escape"&&Y(!1)};return document.addEventListener("mousedown",k),document.addEventListener("keydown",Ne),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",Ne)}},[W]),a.useEffect(()=>{if(!$)return;const k=Z=>{var Fe;const Ae=Z.target;Ae instanceof Node&&((Fe=L.current)!=null&&Fe.contains(Ae)||y(!1))},Ne=Z=>{Z.key==="Escape"&&y(!1)};return document.addEventListener("mousedown",k),document.addEventListener("keydown",Ne),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",Ne)}},[$]),e.jsxs("aside",{className:"dashboard-panel dashboard-panel-muted 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/24 px-3 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-lg font-semibold tracking-tight text-foreground",children:"Tasks"}),e.jsx(O,{variant:"ghost",size:"icon",onClick:H,className:"rounded-sm",children:e.jsx(_a,{className:"h-4 w-4"})})]}),e.jsxs("div",{ref:c,className:"mt-4 flex items-center gap-1.5",children:[e.jsxs("div",{ref:L,className:I("relative flex items-stretch transition-[flex] duration-200",W?"flex-[2]":"flex-1"),children:[e.jsxs(O,{onClick:()=>{y(!1),G("chat")},className:"h-10 flex-1 justify-start rounded-l-sm rounded-r-none px-3 text-left shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(ht,{className:"h-4 w-4"}),"New chat"]}),e.jsx(O,{onClick:()=>y(k=>!k),"aria-label":"More chat options","aria-haspopup":"menu","aria-expanded":$,className:"h-10 w-8 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(Ze,{className:I("h-3.5 w-3.5 transition-transform",$&&"rotate-180")})}),$&&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:()=>{y(!1),G("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(xt,{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"})]})})]}),W?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(et,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(He,{ref:X,value:x,onChange:k=>K(k.target.value),placeholder:"Search tasks",className:"h-11 rounded-lg border-border/70 bg-background/68 pl-11 text-[11px]"})]}),e.jsx(O,{variant:"outline",size:"icon",onClick:()=>Y(!1),className:"rounded-sm border-border/70 bg-background/68",children:e.jsx(ys,{className:"h-4 w-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(O,{variant:"outline",onClick:()=>Y(!0),className:I("rounded-sm border-border/70 bg-background/68 px-3 text-[11px]",x&&"border-primary/40 bg-primary/8 text-primary"),children:[e.jsx(et,{className:"h-4 w-4"}),"Search"]}),e.jsx(O,{variant:de||re?"secondary":"outline",size:"icon",onClick:()=>m(k=>!k),className:I("shrink-0 rounded-sm border-border/70 bg-background/68",re&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(ro,{className:"h-4 w-4"})})]})]}),(de||re)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(ye,{value:i,onValueChange:k=>D(k),children:[e.jsx(ke,{className:Ns,children:e.jsx(Pe,{})}),e.jsx(Se,{children:Jn.map(k=>e.jsx(we,{value:k.value,className:ws,children:k.label},k.value))})]}),e.jsxs(ye,{value:j,onValueChange:P,children:[e.jsx(ke,{className:Ns,children:e.jsx(Pe,{placeholder:"Node"})}),e.jsx(Se,{children:h.map(k=>e.jsx(we,{value:k.value,className:ws,children:k.label},k.value))})]}),e.jsxs(ye,{value:g,onValueChange:F,children:[e.jsx(ke,{className:Ns,children:e.jsx(Pe,{placeholder:"Agent"})}),e.jsx(Se,{children:f.map(k=>e.jsx(we,{value:k,className:ws,children:k==="all"?"All agents":k},k))})]}),e.jsxs(ye,{value:N,onValueChange:k=>E(k),children:[e.jsx(ke,{className:Ns,children:e.jsx(Pe,{placeholder:"Type"})}),e.jsx(Se,{children:Yn.map(k=>e.jsx(we,{value:k.value,className:ws,children:k.label},k.value))})]})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-1.5 py-2",children:be.length>0?e.jsxs("div",{className:"space-y-1",children:[r&&e.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 py-0.5",children:[e.jsxs("label",{className:"flex items-center gap-[5px] text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/75",children:[e.jsx(Qs,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:U&&!T?"indeterminate":T,onCheckedChange:k=>_(k===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Select all"})]}),z>0&&e.jsx(O,{variant:"ghost",size:"sm",onClick:()=>_(!1),className:"h-5 rounded-sm px-1.5 text-[10px]",children:"Clear"})]}),be.map(k=>{const Ne=k.nodeId??"__unassigned__",Z=k.dirs.reduce((Re,Ue)=>Re+Ue.tasks.length,0),Ae=$e&&!se&&R.has(Ne),Fe=k.nodeId!==null&&u.get(k.nodeId)==="offline",cs=!!(r&&k.nodeId&&ie);return e.jsxs("div",{className:"space-y-1",children:[$e&&e.jsxs("div",{className:"flex w-full items-center gap-1.5 rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 px-2 py-1.5 text-left text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsxs("button",{type:"button",onClick:()=>ce(Ne),"aria-expanded":!Ae,className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[e.jsx(ms,{className:I("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!Ae&&"rotate-90")}),e.jsx(ra,{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:k.nodeName}),e.jsxs(Te,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-border/60 bg-background/55 px-1.5 py-0 text-[8px] font-semibold leading-4 text-muted-foreground shadow-none normal-case tracking-normal",children:[Z," task",Z===1?"":"s"]})]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[Fe&&e.jsx(Te,{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"}),k.nodeId===M&&e.jsx(Te,{variant:"outline",className:"rounded-sm border-primary/25 bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"}),cs&&k.nodeId&&ie&&e.jsx(bt,{nodeId:k.nodeId,nodeName:k.nodeName,onOpenSettings:ie,onOpenDevBox:ae,onStartDevBox:ee,showConfigureDevBox:b.has(k.nodeId),showStartDevBox:S.has(k.nodeId)||p.has(k.nodeId),startDevBoxPending:p.has(k.nodeId)})]})]}),e.jsx("div",{className:I("grid transition-[grid-template-rows] duration-300 ease-in-out",Ae?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:k.dirs.map(Re=>{const Ue=`${Ne}::${Re.path}`,Le=ge.has(Ue),_e=Xn(Re.path);return e.jsxs("div",{className:I("space-y-0.5 rounded-xl",$e&&"pl-2.5"),children:[e.jsxs("button",{type:"button",onClick:()=>he(Ue),"aria-expanded":!Le,title:Re.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:I("h-3 w-3 shrink-0 transition-transform duration-200",!Le&&"rotate-90")}),e.jsx(Sa,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"truncate font-mono",children:_e}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/40",children:Re.tasks.length})]}),e.jsx("div",{className:I("grid transition-[grid-template-rows] duration-300 ease-in-out",Le?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:I("overflow-hidden",$e?"pl-2":"pl-0"),children:e.jsx("div",{className:"space-y-px py-0.5",children:Re.tasks.map(fe=>e.jsxs("div",{className:I("flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",fe.id===t?"bg-muted/50":"hover:bg-muted/40"),children:[r&&e.jsx("div",{className:"flex shrink-0",onClick:Qe=>Qe.stopPropagation(),children:e.jsx(Qs,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:w.has(fe.id),onCheckedChange:Qe=>A(fe.id,Qe===!0),"aria-label":`Select ${fe.title}`})}),e.jsxs("button",{type:"button",onClick:()=>J(fe.id),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:I("h-1.5 w-1.5 shrink-0 rounded-full",Zn(fe.status),(fe.status==="running"||fe.status==="assigned")&&"animate-soft-status-pulse")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-medium leading-4 text-foreground/80",children:fe.title}),e.jsx("span",{className:"ml-1 shrink-0 tabular-nums text-[10px] text-muted-foreground/55",children:er(fe.updatedAt)}),fe.id===t&&e.jsx("span",{className:"ml-1 h-1.5 w-1.5 shrink-0 rounded-full bg-primary/70"})]}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5 pl-3",children:[e.jsx(ca,{status:fe.status,size:"compact"}),e.jsx("span",{className:"font-mono text-[8px] leading-3 text-muted-foreground/55",children:fe.agent}),fe.conversationKind==="nativeSession"&&e.jsx(Te,{variant:"outline",className:"rounded-sm border-sky-500/25 bg-sky-500/8 px-1 py-0 text-[8px] leading-3 text-sky-700 shadow-none dark:text-sky-300",children:"native"}),fe.activeShare&&e.jsx(Te,{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"}),fe.assignedNodeAvailable===!1&&e.jsx(Te,{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"})]})]})]},fe.id))})})})]},Ue)})})})]},Ne)})]}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(k=>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+k*12}%`,animationDelay:`${k*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${k*120+60}ms`}})]})]})},k))}):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."})}),r&&z>0?e.jsxs("div",{className:"shrink-0 border-t border-border/60 px-3 py-3",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:"Batch actions"}),e.jsxs("div",{className:"mt-2 text-[10px] font-semibold text-foreground",children:[z," task",z!==1?"s":""," selected"]}),!B&&e.jsx("div",{className:"mt-2 text-[10px] leading-4 text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[e.jsxs(zs,{children:[e.jsx(Pt,{asChild:!0,children:e.jsxs(O,{variant:"outline",size:"sm",disabled:!B,className:"h-7 gap-1.5 rounded-sm px-2 text-[10px] [&_svg]:size-3.5",children:[e.jsx(Jr,{}),"Archive"]})}),e.jsxs(Us,{children:[e.jsxs(Vs,{children:[e.jsxs(qs,{children:["Archive ",z," task",z!==1?"s":"","?"]}),e.jsx(Hs,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(Ks,{children:[e.jsx(Ws,{children:"Cancel"}),e.jsx(Gs,{onClick:Q,disabled:!B,children:"Archive"})]})]})]}),e.jsxs(zs,{children:[e.jsx(Pt,{asChild:!0,children:e.jsxs(O,{variant:"destructive",size:"sm",className:"h-7 gap-1.5 rounded-sm px-2 text-[10px] [&_svg]:size-3.5",children:[e.jsx($o,{}),"Delete"]})}),e.jsxs(Us,{children:[e.jsxs(Vs,{children:[e.jsxs(qs,{children:["Delete ",z," task",z!==1?"s":"","?"]}),e.jsx(Hs,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(Ks,{children:[e.jsx(Ws,{children:"Cancel"}),e.jsx(Gs,{onClick:V,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]}):null]})}async function Ji(s,t){var n,o;try{const r=await sr(s,t),i={...r,url:oa(r.url)};if((o=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&o.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),oe.success("Shared link copied")}catch{oe.success("Shared link created")}else oe.success("Shared link created");return i}catch(r){oe.error(r instanceof Error?r.message:"Failed to create shared link");return}}async function Yi(s){try{return await tr(s),oe.success("Shared link stopped"),!0}catch(t){return oe.error(t instanceof Error?t.message:"Failed to stop shared link"),!1}}function Xi(s,t,n){const o=a.useCallback(()=>{t(),n()},[t,n]),r=a.useCallback(async g=>{if(!s)return;const j=await Ji(s.id,g);return j&&o(),j},[s,o]),i=a.useCallback(async()=>{if(!s)return!1;const g=await Yi(s.id);return g&&o(),g},[s,o]);return{handleShareTask:r,handleStopShareTask:i}}function sa(s,t,n){const o=a.useRef(t);o.current=t,a.useEffect(()=>{let g=0,j=0;const N=l=>{const u=l.touches[0];u&&(g=u.clientX,j=u.clientY)},f=l=>{var p,M,x,w;const u=l.changedTouches[0];if(!u)return;const b=u.clientX-g;Math.abs(u.clientY-j)>100||Math.abs(b)<50||(b>0?(M=(p=o.current).onSwipeRight)==null||M.call(p):(w=(x=o.current).onSwipeLeft)==null||w.call(x))},h=(s==null?void 0:s.current)??document;return h.addEventListener("touchstart",N,{passive:!0}),h.addEventListener("touchend",f,{passive:!0}),()=>{h.removeEventListener("touchstart",N),h.removeEventListener("touchend",f)}},[s,n==null?void 0:n.threshold,n==null?void 0:n.maxVertical])}const Zi="(min-width: 1024px)",el="(min-width: 1800px)";function ta(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 sl(){const[s,t]=a.useState(!0),[n,o]=a.useState(!1),[r,i]=a.useState(()=>ta(el)),g=a.useRef(null),j=a.useRef(null);sa(g,{onSwipeLeft:()=>o(!1)}),sa(j,{onSwipeRight:()=>i(!1)});const N=a.useCallback(()=>{if(ta(Zi)){t(f=>!f);return}o(f=>!f)},[]);return{desktopTasksOpen:s,mobileTasksPanelOpen:n,mobileTasksPanelRef:g,operationsOpen:r,operationsPanelRef:j,setMobileTasksPanelOpen:o,setOperationsOpen:i,toggleTasksPanel:N}}function tl(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 al({isLeader:s,selfId:t}){return{assignedTo:!s&&t?t:void 0}}function nl({isLeader:s,selfId:t,sseConnected:n,subscribe:o}){const[r,i]=a.useState([]),[g,j]=a.useState(!0),[N,f]=a.useState(null),h=a.useRef(null),l=a.useCallback(async()=>{try{const b=await ar(al({isLeader:s,selfId:t}));i(b),f(null)}catch(b){f(b instanceof Error?b.message:"Failed to load tasks")}finally{j(!1)}},[s,t]),u=a.useCallback(()=>{h.current===null&&(h.current=window.setTimeout(()=>{h.current=null,l()},nr))},[l]);return rr(l,lr(n)),a.useEffect(()=>()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),a.useEffect(()=>{const b=[o("task.updated",S=>{i(p=>tl(p,S.data))}),o("task.status",S=>{i(p=>or(p,S.data))}),o("task",S=>{ir(S.type)&&u()})];return()=>b.forEach(S=>S())},[o,u]),{fetchTasks:l,setTasks:i,tasks:r,tasksError:N,tasksLoading:g}}function rl(s,t){return t.data.nodeId===s.self.id||t.data.name===s.self.name||t.data.endpoint===s.self.endpoint}function ol({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=rl(s,o);o.type==="node.joined"&&!i&&oe.success(`${r} joined the cluster`),o.type==="node.left"&&!i&&oe.message(`${r} left the cluster`)})},[s,t])}const il=[0,300,1e3,2e3];function ll({task:s,getActiveTaskId:t,setLogs:n,setPendingMessages:o}){s.conversationKind==="nativeSession"&&(async()=>{for(const r of il){if(r>0&&await new Promise(i=>setTimeout(i,r)),t()!==s.id)return;try{const i=await ga(s.id);if(t()!==s.id||(n(g=>ya(g,i.logs)),o(g=>ka(g,i.logs)),i.total>0))return}catch{}}})()}function dl(s,t){return De(s??{})===De(t??{})}function cl(s){return s&&"status"in s&&typeof s.status=="string"?s.status:void 0}function aa(s,t){return{...s,enabled:!0,alwaysOnline:t}}function Va(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 ul({operationStarting:s,loading:t,refreshing:n,savedStatus:o,fallbackStatus:r}){return s?"Starting":t?"Listing DevBoxes":n?"Refreshing":o??r}function na({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:Va(s)})]})}function ml({node:s,open:t,startInProgress:n=!1,onOpenChange:o,onRefresh:r}){const i=(s==null?void 0:s.id)??null,g=t&&!n&&Jt(s==null?void 0:s.status,(s==null?void 0:s.devbox)??null),[j,N]=a.useState([]),[f,h]=a.useState(()=>s!=null&&s.devbox?De(s.devbox):""),[l,u]=a.useState(()=>(s==null?void 0:s.devbox)??null),[b,S]=a.useState(()=>Yt((s==null?void 0:s.devbox)??null)),[p,M]=a.useState(!1),[x,w]=a.useState(g),[T,U]=a.useState(!1),[B,K]=a.useState(!1),[D,F]=a.useState(()=>{var c;return((c=s==null?void 0:s.devbox)==null?void 0:c.alwaysOnline)===!0}),P=a.useMemo(()=>{const c=j.find(L=>De(L)===f);return c||(os(l)&&De(l)===f?l:void 0)},[l,j,f]),E=cl(P??void 0),A=b?E??(l==null?void 0:l.lastStatus):(l==null?void 0:l.lastStatus)??E,_=(s==null?void 0:s.status)==="online"||(s==null?void 0:s.status)==="busy"?"Running":"Unknown",Q=B||n,V=ul({operationStarting:Q,loading:p,refreshing:x,savedStatus:A,fallbackStatus:_}),G=b&&!!P&&!dl(l,P),ie=(l==null?void 0:l.alwaysOnline)===!0!==D,ae=Ki({nodeStatus:s==null?void 0:s.status,status:V,current:l,selected:P}),ee=!!ae,J=!!P&&(G||ie)&&!ee,H=P??l,W=a.useCallback(async()=>{if(i){w(!0);try{const c=await dr(i);u(c.devbox),h(De(c.devbox))}catch(c){oe.error(c instanceof Error?c.message:"Failed to refresh DevBox status")}finally{w(!1)}}},[i]),Y=a.useCallback(async c=>{M(!0);try{const L=await cr();N(L),h(z=>Wi({previousKey:z,baseDevBox:c,listed:L}))}catch(L){oe.error(L instanceof Error?L.message:"Failed to load DevBoxes")}finally{M(!1)}},[]);a.useEffect(()=>{if(!t||!i)return;let c=!1;const L=(s==null?void 0:s.devbox)??null,z=Yt(L),re=!n&&Jt(s==null?void 0:s.status,L);M(!1),w(re),S(z),u(L),F((L==null?void 0:L.alwaysOnline)===!0),h(os(L)?De(L):""),N([]);async function v(){re&&await W(),!c&&z&&await Y(L)}return v(),()=>{c=!0}},[Y,s==null?void 0:s.devbox,s==null?void 0:s.status,i,t,W,n]);async function de(){S(!0),j.length===0&&await Y(l)}async function m(){if(!(!s||!P)){U(!0);try{const c=await $t(s.id,aa(P,D));u(c.node.devbox??null),c.node.devbox&&h(De(c.node.devbox)),S(!1),oe.success(`Configured DevBox for ${s.name}`),await(r==null?void 0:r())}catch(c){oe.error(c instanceof Error?c.message:"Failed to configure DevBox")}finally{U(!1)}}}async function $(){if(!(!s||!ae)){K(!0);try{if(P&&(G||ie)){const L=await $t(s.id,aa(P,D));u(L.node.devbox??null),L.node.devbox&&h(De(L.node.devbox)),S(!1)}const{operation:c}=await ba(s.id);u(L=>L&&{...L,lastStatus:"Starting",checkedAt:Date.now(),operationId:c.id}),oe.success(`Start requested for ${s.name}`),await(r==null?void 0:r())}catch(c){oe.error(c instanceof Error?c.message:"Failed to start DevBox")}finally{K(!1)}}}const y=p?"Loading DevBoxes...":j.length===0?"No DevBoxes available":"Select a DevBox",X=V==="Running"&&(s==null?void 0:s.status)==="offline";return e.jsx(it,{open:t,onOpenChange:o,children:e.jsxs(lt,{className:"max-w-md gap-4 rounded-lg p-5",children:[e.jsxs(ma,{className:"space-y-1",children:[e.jsx(dt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(ur,{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:[(b||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:b?e.jsxs(ye,{value:f,onValueChange:h,disabled:p||T||B||j.length===0,children:[e.jsx(ke,{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:p&&!P?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),y]}):P?e.jsx(na,{devbox:P}):e.jsx(Pe,{placeholder:y})}),e.jsx(Se,{children:j.map(c=>e.jsx(we,{value:De(c),textValue:`${c.name} ${c.projectName??""} ${Va(c)}`,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(na,{devbox:c,showStatus:!0})},De(c)))})]}):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(Te,{variant:"outline",className:"rounded-full px-2 py-0.5 text-[10px]",children:[(p||x)&&e.jsx(ue,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),V]}),(l==null?void 0:l.name)&&e.jsx(O,{type:"button",variant:"ghost",size:"icon",onClick:()=>{de()},disabled:p||T||Q||b,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-full text-muted-foreground hover:text-foreground",children:p&&b?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(ls,{className:"h-3 w-3"})})]})]}),X&&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(Qs,{checked:D,onCheckedChange:c=>F(c===!0),disabled:T||B||Q,"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(xa,{className:"gap-2 sm:space-x-0",children:[e.jsx(O,{variant:"ghost",size:"sm",onClick:()=>o(!1),disabled:T||B,className:"h-8 rounded-xl text-xs",children:"Close"}),ee&&e.jsxs(O,{size:"sm",onClick:$,disabled:B,className:"h-8 rounded-xl text-xs",children:[B?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(mt,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!ee&&e.jsxs(O,{size:"sm",onClick:m,disabled:!J||T,className:"h-8 rounded-xl text-xs",children:[T&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function xl(s,t=mr){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 hl({cluster:s,refresh:t}){const[n,o]=a.useState(null),[r,i]=a.useState(null),[g,j]=a.useState(()=>new Set),[N,f]=a.useState(()=>new Set),h=a.useMemo(()=>(s==null?void 0:s.nodes.find(x=>x.id===n))??null,[s==null?void 0:s.nodes,n]),l=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(x=>{var w;return(w=x.devbox)==null?void 0:w.enabled}).map(x=>x.id)),[s==null?void 0:s.nodes]),u=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(x=>{var w;return Cs(x.status,(w=x.devbox)==null?void 0:w.lastStatus,x.devbox)}).map(x=>x.id)),[s==null?void 0:s.nodes]),b=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(x=>{var w;return is((w=x.devbox)==null?void 0:w.lastStatus)}).map(x=>x.id)),[s==null?void 0:s.nodes]),S=a.useMemo(()=>{const x=new Set(g);r&&x.add(r);for(const w of N)x.add(w);for(const w of b)x.add(w);return x},[N,r,g,b]);a.useEffect(()=>{let x=!1;const w=[...l];async function T(){try{const U=await xl(w);x||f(U)}catch{x||f(new Set)}}return T(),()=>{x=!0}},[l]),a.useEffect(()=>{j(x=>{var U;let w=!1;const T=new Set(x);for(const B of x){const K=s==null?void 0:s.nodes.find(D=>D.id===B);(K==null?void 0:K.status)!=="online"&&(!((U=K==null?void 0:K.devbox)!=null&&U.lastStatus)||is(K.devbox.lastStatus))||(T.delete(B),w=!0)}return w?T:x})},[s==null?void 0:s.nodes]);const p=a.useCallback(async x=>{const w=s==null?void 0:s.nodes.find(T=>T.id===x);if(w){i(x),j(T=>new Set(T).add(x));try{await ba(x),oe.success(`Start requested for ${w.name}`),t()}catch(T){j(U=>{const B=new Set(U);return B.delete(x),B}),oe.error(T instanceof Error?T.message:"Failed to start DevBox")}finally{i(null)}}},[s==null?void 0:s.nodes,t]);return{devBoxDialog:e.jsx(ml,{node:h,open:n!==null,startInProgress:h?S.has(h.id):!1,onOpenChange:x=>{x||o(null)},onRefresh:t}),devBoxNodeIds:l,devBoxStartNodeId:r,devBoxStartNodeIds:u,devBoxStartingNodeIds:S,openDevBox:o,startDevBox:p}}function fl(s){const[t,n]=a.useState(null),o=a.useCallback(i=>{s&&n(i)},[s]);return{nodeSettingsDialog:e.jsx(xr,{open:t!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:t??void 0,showTrigger:!1}),openNodeSettings:o}}function pl({activeTaskId:s,fetchActiveTask:t,setPendingMessages:n,setTask:o,setTasks:r}){const i=a.useCallback((N,f)=>{o(h=>h&&h.id===N?{...h,queuedMessages:f}:h),r(h=>h.map(l=>l.id===N?{...l,queuedMessages:f}:l))},[o,r]),g=a.useCallback(async N=>{if(!s)return!1;const f=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`;n(h=>[...h,{id:f,content:N,timestamp:new Date().toISOString()}]);try{const h=await hr(s,N);return h.queued&&(n(l=>l.filter(u=>u.id!==f)),h.queuedMessages&&i(s,h.queuedMessages)),t(),!0}catch(h){return n(l=>l.filter(u=>u.id!==f)),oe.error(h instanceof Error?h.message:"Failed to send message"),!1}},[s,t,n,i]);return{cancelQueuedMessage:a.useCallback(async N=>{if(s)try{const f=await fr(s,N);i(s,f.queuedMessages),t()}catch(f){oe.error(f instanceof Error?f.message:"Failed to cancel queued message")}},[s,t,i]),queueFollowUpMessage:g}}function gl(){var Ct,_t,Et,Dt,Tt,Mt;const{id:s}=pr(),t=gr(),n=br(),o=vr(),{cluster:r,systemInfo:i,events:g,sseConnected:j,subscribe:N,refresh:f,loading:h,error:l}=jr(),u=a.useMemo(()=>Nr(t.state),[t.state]),[b,S]=a.useState(null),[p,M]=a.useState("active"),[x,w]=a.useState("all"),[T,U]=a.useState("all"),[B,K]=a.useState("all"),[D,F]=a.useState(""),P=a.useDeferredValue(D),{desktopTasksOpen:E,mobileTasksPanelOpen:A,mobileTasksPanelRef:_,operationsOpen:Q,operationsPanelRef:V,setMobileTasksPanelOpen:G,setOperationsOpen:ie,toggleTasksPanel:ae}=sl(),[ee,J]=a.useState(()=>!!(u!=null&&u.draftNewTask)),[H,W]=a.useState(()=>(u==null?void 0:u.createMode)??"chat"),[Y,de]=a.useState(()=>u!=null&&u.draftNewTask?{route:u.returnRoute??"/",taskId:u.returnTaskId??null}:null),[m,$]=a.useState(!1),[y,X]=a.useState("transcript"),[c,L]=a.useState("all"),[z,re]=a.useState(!1),[v,R]=a.useState(null),[te,ge]=a.useState([]),[Ce,be]=a.useState([]),[Ke,$e]=a.useState(!1),[se,ce]=a.useState(null),[he,k]=a.useState(new Set),[Ne,Z]=a.useState(!1),[Ae,Fe]=a.useState(!1),[cs,Re]=a.useState(null),Ue=a.useRef(null),Le=a.useRef(null),_e=((Ct=r==null?void 0:r.self)==null?void 0:Ct.role)==="leader",fe=(_t=r==null?void 0:r.self)==null?void 0:_t.id;ol({cluster:r,subscribe:N});const{nodeSettingsDialog:Qe,openNodeSettings:es}=fl(_e),{devBoxDialog:_s,devBoxNodeIds:Es,devBoxStartNodeId:Ee,devBoxStartNodeIds:ve,devBoxStartingNodeIds:Be,openDevBox:ss,startDevBox:vt}=hl({cluster:r,refresh:f}),{fetchTasks:Ie,setTasks:jt,tasks:We,tasksError:qa,tasksLoading:Ds}=nl({isLeader:_e,selfId:fe,sseConnected:j,subscribe:N}),je=a.useMemo(()=>[...We].sort((d,C)=>C.updatedAt-d.updatedAt),[We]),Ha=a.useMemo(()=>{const d=new Map;for(const C of(r==null?void 0:r.nodes)??[]){const q=Io(je,C.id);q>0&&d.set(C.id,q)}return d},[r==null?void 0:r.nodes,je]),Ve=a.useMemo(()=>je.filter(d=>!wr(d,r==null?void 0:r.nodes,r==null?void 0:r.self)||!yr(d,p)||x!=="all"&&d.agent!==x||!kr(d,B)||T==="unassigned"&&d.assignedTo||T!=="all"&&T!=="unassigned"&&Sr(d.assignedTo,r==null?void 0:r.nodes,d.assignedNodeName)!==T?!1:P.trim()?Cr(d,P):!0),[je,r==null?void 0:r.nodes,r==null?void 0:r.self,p,x,B,T,P]);a.useEffect(()=>{k(d=>{const C=Vo(d,Ve.map(q=>q.id));return C.size===d.size?d:C})},[Ve]),a.useEffect(()=>{_e||k(new Set)},[_e]);const Ka=a.useMemo(()=>["all",...Array.from(new Set(je.map(d=>d.agent))).sort()],[je]),Wa=a.useMemo(()=>{const C=Array.from(new Set(je.map(q=>q.assignedTo).filter(q=>!!q))).map(q=>{const pe=je.find(le=>le.assignedTo===q);return(r==null?void 0:r.nodes.find(le=>le.id===q))??{id:q,name:la(q,r==null?void 0:r.nodes,pe==null?void 0:pe.assignedNodeName)}}).sort((q,pe)=>q.name.localeCompare(pe.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...C.map(q=>({value:q.name.toLowerCase(),label:q.name}))]},[je,r==null?void 0:r.nodes]),Nt=a.useMemo(()=>{const d=new Map;for(const C of(r==null?void 0:r.nodes)??[])d.set(C.id,C.name);for(const C of je)C.assignedTo&&C.assignedNodeName&&!d.has(C.assignedTo)&&d.set(C.assignedTo,C.assignedNodeName);return d},[r==null?void 0:r.nodes,je]),Ga=a.useMemo(()=>{const d=new Map;for(const C of(r==null?void 0:r.nodes)??[])d.set(C.id,C.status);return r!=null&&r.self&&d.set(r.self.id,r.self.status),d},[r]),wt=a.useMemo(()=>{const d=new Map;for(const C of(r==null?void 0:r.nodes)??[])C.status!=="offline"&&d.set(C.id,C);return r!=null&&r.self&&r.self.status!=="offline"&&d.set(r.self.id,r.self),Array.from(d.values())},[r]),Qa=((Et=r==null?void 0:r.self)==null?void 0:Et.id)??((Dt=wt[0])==null?void 0:Dt.id)??null,Ts=a.useMemo(()=>["all",...Array.from(new Set(g.map(d=>d.type))).sort()],[g]),Ja=a.useMemo(()=>c==="all"?g:g.filter(d=>d.type===c),[g,c]),Ya=Ve.length>0&&Ve.every(d=>he.has(d.id)),Xa=Ve.some(d=>he.has(d.id)),Za=qo(Ve,he);a.useEffect(()=>{u!=null&&u.draftNewTask&&(J(!0),de({route:u.returnRoute??"/",taskId:u.returnTaskId??null}))},[u]),a.useEffect(()=>{c!=="all"&&!Ts.includes(c)&&L("all")},[c,Ts]),a.useEffect(()=>{Vt(s,ee)&&!b&&je[0]&&S(je[0].id)},[s,ee,b,je]),a.useEffect(()=>{var d;Vt(s,ee)&&(b&&We.some(C=>C.id===b)||S(((d=je[0])==null?void 0:d.id)??null))},[s,ee,b,je,We]);const xe=Fo({routeTaskId:s,creatingTask:ee,internalSelectedTaskId:b,sortedTaskIds:je.map(d=>d.id)}),ts=a.useMemo(()=>We.find(d=>d.id===xe)??null,[We,xe]);a.useEffect(()=>{Le.current=xe??null},[xe]);const fs=a.useCallback(()=>{R(null),ge([]),be([]),ce(null)},[]),Oe=a.useCallback(async()=>{const d=xe;if(d)try{const C=await _r(d);if(Le.current!==d)return;R(C),ce(null)}catch(C){if(Le.current!==d)return;R(null),ge([]),be([]),ce(C instanceof Error?C.message:"Failed to load task")}finally{Le.current===d&&$e(!1)}},[xe]),ps=a.useCallback(async()=>{const d=xe;if(d)try{const C=await ga(d);if(Le.current!==d)return;ge(q=>ya(q,C.logs)),be(q=>ka(q,C.logs))}catch{}},[xe]);a.useEffect(()=>{if(!xe){R(null),ge([]),be([]),ce(null),$e(!1);return}X("transcript"),R(ts),ge([]),be([]),ce(null),$e(!0),Oe(),ps()},[xe,ps,Oe]),a.useEffect(()=>{var C;if(!xe||ee||Ds||We.some(q=>q.id===xe))return;const d=((C=je[0])==null?void 0:C.id)??null;S(d),fs(),a.startTransition(()=>{n(d?`/tasks/${d}`:"/",{state:null})})},[xe,fs,ee,n,je,We,Ds]),a.useEffect(()=>{ts&&R(d=>!d||d.id!==ts.id?d:{...d,...ts})},[ts]),a.useEffect(()=>{if(xe)return N("task",d=>{const C=d.data.taskId;if(!(typeof C!="string"||C!==xe)){if(d.type==="task.output"){const q=d.data.event;if(q){ge(le=>Vr(le,q));const pe=zt(q);pe&&be(le=>qr(le,pe))}}d.type==="task.updated"&&Oe(),d.type==="task.status"&&(Oe(),ps())}})},[N,xe,Oe,ps]),a.useEffect(()=>{var d;y==="transcript"&&((d=Ue.current)==null||d.scrollIntoView({behavior:"smooth"}))},[te,Ce,y]);const ne=v??ts,en=ne!=null&&ne.assignedTo?(r==null?void 0:r.nodes.find(d=>d.id===ne.assignedTo))??null:null,Ms=Ce.length>0,sn=ne?Er.has(ne.agent):!1,As=(ne==null?void 0:ne.status)==="running",tn=ne?ks.has(ne.status):!1,an=ne?ks.has(ne.status)||Dr.has(ne.status):!1,nn=!!(ne&&_e&&ne.status==="failed"),Ls=a.useMemo(()=>Qi(ne,r,Ms,!!As),[ne,r,Ms,As]),Bs=a.useMemo(()=>Hr([...te,...Ce.map(d=>Os(d.content,d.timestamp))]),[te,Ce]),gs=a.useMemo(()=>{if(!ne||ne.conversationKind==="nativeSession")return null;const d=Kr(ne);if(d.length>0)return Os(d,new Date(ne.createdAt).toISOString());if(Bs.length>0)return null;const C=Wr(ne.description||ne.title);return C.length>0?Os(C,new Date(ne.createdAt).toISOString()):null},[ne,Bs]),Ps=a.useMemo(()=>gs?zt(gs):null,[gs]),rn=a.useMemo(()=>Ps?Gr(te,Ps):!1,[te,Ps]),$s=a.useCallback((d="chat")=>{const C={route:s?`/tasks/${s}`:"/",taskId:xe};de(C),W(d),J(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:C.route,returnTaskId:C.taskId,createMode:d}})})},[s,xe,n]),on=a.useCallback(()=>{var C;const d=(Y==null?void 0:Y.taskId)??((C=je[0])==null?void 0:C.id)??null;J(!1),de(null),S(d),a.startTransition(()=>{n((Y==null?void 0:Y.route)??"/",{state:null})})},[Y,je,n]),yt=a.useCallback(d=>{J(!1),de(null),S(d),a.startTransition(()=>{n(`/tasks/${d}`,{state:null})})},[n]),ln=a.useCallback(d=>{Le.current=d.id,J(!1),de(null),jt(C=>zo(C,d)),R(d),ge([]),be([]),ce(null),$e(!1),X("transcript"),S(d.id),ll({task:d,getActiveTaskId:()=>Le.current,setLogs:ge,setPendingMessages:be}),Ie(),a.startTransition(()=>{n(`/tasks/${d.id}`,{state:null})})},[Ie,n]),{cancelQueuedMessage:dn,queueFollowUpMessage:bs}=pl({activeTaskId:xe,fetchActiveTask:Oe,setPendingMessages:be,setTask:R,setTasks:jt}),cn=a.useCallback(d=>{bs(d)},[bs]),un=a.useCallback(d=>bs(d),[bs]),mn=a.useCallback(async()=>{if(ne)try{await Tr(ne.id),Oe(),Ie()}catch(d){oe.error(d instanceof Error?d.message:"Failed to cancel task")}},[ne,Oe,Ie]),{handleShareTask:xn,handleStopShareTask:hn}=Xi(ne,Oe,Ie),fn=a.useCallback(async()=>{if(ne)try{await Mr(ne.id),Oe(),Ie()}catch(d){oe.error(d instanceof Error?d.message:"Failed to retry task")}},[ne,Oe,Ie]),vs=a.useCallback((d,C=!1)=>{const q=Ho(Ve,d);return S(q),(C||!q)&&fs(),a.startTransition(()=>{n(q?`/tasks/${q}`:"/",{state:null})}),q},[fs,Ve,n]),pn=a.useCallback((d,C)=>{k(q=>{const pe=new Set(q);return C?pe.add(d):pe.delete(d),pe})},[]),gn=a.useCallback(d=>{if(!d){k(new Set);return}k(new Set(Ve.map(C=>C.id)))},[Ve]),bn=a.useCallback(async()=>{const d=Array.from(he);if(d.length!==0)try{const{results:C}=await Ar(d),q=C.filter(le=>!le.ok),pe=C.filter(le=>le.ok).map(le=>le.id);xe&&pe.includes(xe)&&vs(pe),q.length>0?oe.error(`Failed to archive ${q.length} task(s): ${q.map(le=>le.error??le.id).join(", ")}`):oe.success(`Archived ${pe.length} task(s)`),k(new Set(q.map(le=>le.id))),Ie()}catch(C){oe.error(C instanceof Error?C.message:"Failed to archive tasks")}},[xe,Ie,vs,he]),vn=a.useCallback(async()=>{const d=Array.from(he);if(d.length!==0)try{const{results:C}=await Lr(d),q=C.filter(le=>!le.ok),pe=C.filter(le=>le.ok).map(le=>le.id);xe&&pe.includes(xe)&&vs(pe,!0),q.length>0?oe.error(`Failed to delete ${q.length} task(s): ${q.map(le=>le.error??le.id).join(", ")}`):oe.success(`Deleted ${pe.length} task(s)`),k(new Set(q.map(le=>le.id))),Ie()}catch(C){oe.error(C instanceof Error?C.message:"Failed to delete tasks")}},[xe,Ie,vs,he]),jn=a.useCallback(async()=>{Z(!0);try{await Br(),f()}catch(d){oe.error(d instanceof Error?d.message:"Failed to promote node")}finally{Z(!1)}},[f]),Nn=a.useCallback(async()=>{Fe(!0);try{await Pr(),oe.success("This node left the remote cluster and is leading itself again."),Ie(),Oe(),f()}catch(d){oe.error(d instanceof Error?d.message:"Failed to leave cluster")}finally{Fe(!1)}},[Oe,Ie,f]),wn=a.useCallback(async d=>{var At;const C=!pt(d),q=d.id===((At=r==null?void 0:r.self)==null?void 0:At.id),pe=q?(i==null?void 0:i.transportType)??d.transportType:d.transportType,le=q&&!C&&ds(pe);Re(d.id);try{le?await $r("direct"):await Rr(d.id,C),oe.success(C?`Enabled remote access on ${d.name}`:`Disabled remote access on ${d.name}`),f()}catch(Lt){oe.error(Lt instanceof Error?Lt.message:"Failed to update remote access")}finally{Re(null)}},[(Tt=r==null?void 0:r.self)==null?void 0:Tt.id,f,i==null?void 0:i.transportType]),kt={toolbarTasks:Ve,activeTaskId:xe,tasksLoading:Ds,tasksError:qa,isLeader:_e,scope:p,agentFilter:x,nodeFilter:T,taskKindFilter:B,agentOptions:Ka,nodeOptions:Wa,nodeNameById:Nt,nodeStatusById:Ga,leaderNodeId:((Mt=r==null?void 0:r.leader)==null?void 0:Mt.id)??null,searchQuery:D,devBoxNodeIds:Es,devBoxStartNodeIds:ve,devBoxStartingNodeIds:Be,selectedTaskIds:he,allVisibleTasksSelected:Ya,someVisibleTasksSelected:Xa,canBatchArchive:Za,onSearchChange:F,onScopeChange:M,onAgentFilterChange:w,onNodeFilterChange:U,onTaskKindFilterChange:K,onToggleTaskSelected:pn,onToggleAllVisibleTasks:gn,onBatchArchive:bn,onBatchDelete:vn,onCreateTask:$s,onOpenNodeSettings:_e?es:void 0,onOpenDevBox:_e?ss:void 0,onStartDevBox:_e?vt:void 0,onSelectTask:yt,onClose:ae},St={cluster:r,systemInfo:i,nodeNameById:Nt,nodeBlockingTaskCounts:Ha,eventTypeFilter:c,onEventTypeFilterChange:L,eventTypeOptions:Ts,filteredEvents:Ja,sseConnected:j,clusterLoading:h,clusterError:l,promotePending:Ne,onPromote:jn,onAddNode:()=>$(!0),leavePending:Ae,onLeaveCluster:Nn,onToggleNodeDevTunnel:wn,devTunnelNodeId:cs,devBoxStartNodeId:Ee,devBoxStartingNodeIds:Be,onOpenNodeSettings:_e?es:void 0,onOpenDevBox:_e?ss:void 0,onStartDevBox:_e?vt:void 0,onClose:()=>ie(!1)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsx("div",{className:I("hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",E?"lg:mr-2 lg:w-[24rem]":"lg:w-0 lg:overflow-hidden"),children:E&&e.jsx(ea,{...kt})}),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:e.jsx(Mi,{onToggleTasks:ae,desktopTasksOpen:E,mobileTasksPanelOpen:A,operationsOpen:Q,onToggleOperations:()=>ie(d=>!d),cluster:r,sseConnected:j,activeTab:y,setActiveTab:X,creatingTask:ee,createMode:H,activeTask:ne,assignedNode:en,taskLoading:Ke,taskError:se,displayEvents:Bs,initialPromptAlreadyInLogs:rn,initialPrompt:gs,supportsFollowUp:sn,taskUnavailable:Ls.taskUnavailable,chatDisabled:Ls.chatDisabled,chatDisabledReason:Ls.chatDisabledReason,questionBypassEnabled:z,isRunning:!!As,isStarting:tn,hasPendingFollowUp:Ms,canCancel:!!an,canRetry:!!nn,onRetry:fn,onCancel:mn,onShareTask:xn,onStopShareTask:hn,onStartCreateTask:$s,onCancelCreateTask:on,onCreateTask:ln,onSendMessage:cn,onCancelQueuedMessage:dn,onQuestionBypassChange:re,onSubmitQuestionResponse:un,messagesEndRef:Ue})}),(o==null?void 0:o.terminalOpen)&&e.jsx(Ui,{nodes:wt,defaultNodeId:Qa,onClose:()=>o==null?void 0:o.setTerminalOpen(!1)})]}),e.jsx("div",{className:I("hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",Q?"xl:ml-2 xl:w-[26rem]":"xl:w-0 xl:overflow-hidden"),children:Q&&e.jsx(Xt,{...St})})]}),Q&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:()=>ie(!1),className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:V,className:"fixed inset-y-0 right-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:e.jsx(Xt,{...St})})]}),A&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:()=>G(!1),className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:_,className:"fixed inset-y-0 left-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:e.jsx(ea,{...kt,onCreateTask:d=>{G(!1),$s(d)},onSelectTask:d=>{G(!1),yt(d)},onClose:()=>G(!1)})})]}),e.jsx(Bi,{open:m,onOpenChange:$,onAdded:f}),Qe,_s]})}const wl=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:gl},Symbol.toStringTag,{value:"Module"}));export{wl as D,Ys as G};
139
+ `).map(i=>i.trim()).find(Boolean);return r?r.length>72?`${r.slice(0,69).trimEnd()}...`:r:n?"Image task":""}function vi(s){var g;const t=s.title.trim(),n=Ia(s.title,s.description,s.images.length>0),o=s.description.trim()||n,r=s.mode??xs,i=va(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 ji({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,className:g,footerClassName:j,submitLabel:N="Create chat",cancelLabel:f="Cancel",autoFocus:h=!1,layout:l="default"}){const[u,b]=a.useState(""),[S,p]=a.useState(""),[M,x]=a.useState("claudecode"),[w,T]=a.useState(xs),[U,B]=a.useState(""),[K,D]=a.useState(""),[F,P]=a.useState("normal"),E=a.useMemo(()=>Ra(s,{currentNodeRole:t,leaderNodeId:o}),[s,t,o]),A=a.useMemo(()=>{var se;return n&&E.some(ce=>ce.id===n)?n:((se=E[0])==null?void 0:se.id)??""},[E,n]),[_,Q]=a.useState(A),[V,G]=a.useState(!1),[ie,ae]=a.useState(!1),{images:ee,error:J,fileInputRef:H,pickImages:W,handleFileChange:Y,handlePaste:de,removeImage:m}=Aa(),$=a.useMemo(()=>E.find(se=>se.id===_)??null,[_,E]),y=!!(n&&($==null?void 0:$.id)===n),X=Na(M),c=Fr(w);a.useEffect(()=>{_&&E.some(se=>se.id===_)||Q(A)},[_,E,A]),a.useEffect(()=>{B($a(_)),D("")},[_]),a.useEffect(()=>{D("")},[U]);const L=a.useCallback(async se=>{se.preventDefault();const ce=vi({title:u,description:S,agent:M,project:U,branch:K,priority:F,assignTo:_,mode:w,images:ee});if(ce){G(!0);try{const he=await Bn(ce);r(he)}catch(he){oe.error(he instanceof Error?he.message:"Failed to create task")}finally{G(!1)}}},[u,S,M,U,K,F,_,w,ee,r]),z=Ia(u,S,ee.length>0),re=!!(z&&M&&_&&(S.trim()||ee.length>0)),v=a.useCallback(se=>{var ce;se.nativeEvent.isComposing||se.key==="Enter"&&(se.ctrlKey||se.metaKey)&&re&&!V&&(se.preventDefault(),(ce=se.currentTarget.form)==null||ce.requestSubmit())},[re,V]),R=ee.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:ee.map((se,ce)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:ja(se),alt:se.filename??`attachment ${ce+1}`,className:"h-24 w-24 rounded-2xl border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>m(ce),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 ${se.filename??`image ${ce+1}`}`,children:e.jsx(Ge,{className:"h-3.5 w-3.5"})})]},`${se.filename??"image"}-${ce}`))}),te=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Assign to"}),e.jsxs(ye,{value:_,onValueChange:Q,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select node"})}),e.jsx(Se,{children:at(E,n)})]})]}),ge=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Agent"}),e.jsxs(ye,{value:M,onValueChange:x,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select agent"})}),e.jsx(Se,{children:It()})]})]}),Ce=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Mode"}),e.jsxs(ye,{value:w,onValueChange:se=>T(se),children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select mode"})}),e.jsx(Se,{children:Ot()})]})]}),be=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{className:"text-sm font-medium",children:"Priority"}),e.jsxs(ye,{value:F,onValueChange:P,children:[e.jsx(ke,{className:"h-11 rounded-lg border-border/70 bg-background/70",children:e.jsx(Pe,{placeholder:"Select priority"})}),e.jsxs(Se,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]})]}),Ke=e.jsx(Ss,{value:U,onChange:B,assignTo:_,nodes:s,assignableNodes:E}),$e=e.jsx(Ht,{value:K,onChange:D,project:U,assignTo:_,nodes:s,assignableNodes:E});return l==="composer"?e.jsxs("form",{onSubmit:L,className:I("space-y-4",g),children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:Y,className:"hidden"}),(()=>{const se="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",ce="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",he="border-border/70 bg-background/55 text-foreground",k=M==="claudecode",Ne=w===xs;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(ye,{value:_,onValueChange:Q,children:[e.jsx(ke,{className:I(se,he,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${($==null?void 0:$.name)??"unassigned"}`,"aria-label":`Assigned node: ${($==null?void 0:$.name)??"unassigned"}`,children:$?e.jsxs(e.Fragment,{children:[e.jsx(gt,{isCurrent:y}),e.jsx("span",{className:"min-w-0 truncate",children:$.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:y?"current":"remote"})]}):e.jsx(Pe,{placeholder:"Select node"})}),e.jsx(Se,{children:at(E,n)})]}),ie?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(He,{id:"task-title-composer",type:"text",value:u,onChange:Z=>b(Z.target.value),onKeyDown:Z=>{(Z.key==="Enter"||Z.key==="Escape")&&(Z.preventDefault(),ae(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(O,{type:"button",variant:"ghost",size:"icon",onClick:()=>ae(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(us,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>ae(!0),className:"chat-composer__title-button flex min-w-0 items-center gap-1.5 rounded-sm px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-background/55 hover:text-foreground",title:z||"Title","aria-label":z?`Edit title: ${z}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:z||"Title"}),e.jsx(ls,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:S,onChange:Z=>p(Z.target.value),onKeyDown:v,onPaste:de,placeholder:"Ask anything...",rows:4,autoFocus:h,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none rounded-xl bg-transparent px-5 pt-2 pb-2 text-[15px] leading-7 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsxs("div",{className:"chat-composer__rail flex flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(O,{type:"button",variant:"ghost",size:"icon",onClick:W,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Zs,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(ye,{value:M,onValueChange:x,children:[e.jsxs(ke,{className:I(se,"chat-composer__icon-trigger",k?ce:he),title:`Agent: ${X}`,"aria-label":`Agent: ${X}`,children:[e.jsx(ut,{agent:M}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:X})]}),e.jsx(Se,{children:It()})]}),e.jsxs(ye,{value:w,onValueChange:Z=>T(Z),children:[e.jsxs(ke,{className:I(se,"chat-composer__icon-trigger",Ne?ce:he),title:`Mode: ${c}`,"aria-label":`Mode: ${c}`,children:[e.jsx(Lo,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:c})]}),e.jsx(Se,{children:Ot()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(ye,{value:F,onValueChange:P,children:[e.jsx(ke,{"aria-label":`Priority: ${F}`,title:`Priority: ${F}`,className:I("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(to,{className:I("h-4 w-4",F==="critical"&&"fill-destructive/20")})}),e.jsxs(Se,{children:[e.jsx(we,{value:"low",children:"Low"}),e.jsx(we,{value:"normal",children:"Normal"}),e.jsx(we,{value:"high",children:"High"}),e.jsx(we,{value:"critical",children:"Critical"})]})]}),i&&e.jsxs(O,{type:"button",variant:"ghost",size:"sm",onClick:i,"aria-label":f,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(Ge,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:f})]}),e.jsxs(O,{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(ue,{className:"h-4 w-4 animate-spin"}):e.jsx(Da,{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 Z="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(Ss,{value:U,onChange:B,assignTo:_,nodes:s,assignableNodes:E,layout:"composer",chipClassName:se,chipActiveClassName:Z,chipInactiveClassName:Z,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(Ht,{value:K,onChange:D,project:U,assignTo:_,nodes:s,assignableNodes:E,layout:"composer",chipClassName:se,chipActiveClassName:Z,chipInactiveClassName:Z,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(R||J)&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/60 bg-background/45 p-4",children:[R,J&&e.jsx("div",{className:"text-xs text-destructive",children:J}),!J&&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:L,className:I("space-y-5",g),children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",multiple:!0,onChange:Y,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{htmlFor:"task-description",className:"text-sm font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:S,onChange:se=>p(se.target.value),onKeyDown:v,onPaste:de,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:h,className:"flex min-h-[144px] w-full resize-none 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(O,{type:"button",variant:"outline",onClick:W,className:"rounded-sm",children:[e.jsx(Zs,{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."})]}),R,J&&e.jsx("p",{className:"text-xs text-destructive",children:J})]}),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(Me,{htmlFor:"task-title",className:"text-sm font-medium",children:"Chat title"}),e.jsx(He,{id:"task-title",type:"text",value:u,onChange:se=>b(se.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:z?`Will appear as: ${z}`:"A title will be generated from the first line of the prompt."})]}),ge,Ce]}),Ke,$e,e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[be,te]}),e.jsxs("div",{className:I("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",j),children:[i&&e.jsx(O,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:f}),e.jsx(O,{type:"submit",disabled:!re||V,className:"rounded-sm px-5",children:V?"Creating...":N})]})]})}function Ni({nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,defaultMode:g="chat",mode:j,onModeChange:N,layout:f="default",className:h,footerClassName:l,autoFocus:u=!1}){const[b,S]=a.useState(g),p=j!==void 0,M=p?j:b,x=w=>{p||S(w),N==null||N(w)};return e.jsxs("div",{className:I("space-y-4",h),children:[!p&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 bg-background/45 p-1",children:[e.jsxs(O,{type:"button",variant:M==="chat"?"default":"ghost",onClick:()=>x("chat"),className:"flex-1 rounded-sm",children:[e.jsx(Ln,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(O,{type:"button",variant:M==="native"?"default":"ghost",onClick:()=>x("native"),className:"flex-1 rounded-sm",children:[e.jsx(xt,{className:"h-4 w-4"}),"Load session"]})]}),M==="chat"?e.jsx(ji,{nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,footerClassName:l,submitLabel:f==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:u,layout:f}):e.jsx(bi,{nodes:s,currentNodeRole:t,currentNodeId:n,leaderNodeId:o,onCreated:r,onCancel:i,footerClassName:l,autoFocus:u})]})}const rs="72f988bf-86f1-41af-91ab-2d7cd011db47",Oa=`${rs} (MSIT)`;function wi({open:s,onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i=!1,shareResult:g}){return e.jsx(it,{open:s,onOpenChange:t,children:e.jsxs(lt,{className:"max-w-md rounded-xl p-5",children:[e.jsx(dt,{className:"sr-only",children:"Share conversation"}),e.jsx(yi,{onOpenChange:t,onShare:n,onStopShare:o,sharing:r,stopping:i,shareResult:g})]})})}function yi({onOpenChange:s,onShare:t,onStopShare:n,sharing:o,stopping:r=!1,shareResult:i}){const[g,j]=a.useState((i==null?void 0:i.tenant)??rs),[N,f]=a.useState((i==null?void 0:i.scope)??"chat"),h=i!=null&&i.url?oa(i.url):null,l=o||r;return a.useEffect(()=>{j((i==null?void 0:i.tenant)??rs),f((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(ki,{value:g,onChange:j,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(Kt,{active:N==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>f("chat")}),e.jsx(Kt,{active:N==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>f("filesPreview")})]})]}),h&&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:h,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(O,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void ns(h,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(ia,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e.jsx(O,{variant:"outline",onClick:()=>s(!1),disabled:l,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(O,{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(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(O,{onClick:()=>void t({tenant:g,scope:N}),disabled:l,className:"h-8 text-xs",children:[o&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function ki({value:s,onChange:t,disabled:n}){const[o,r]=a.useState(!1),[i,g]=a.useState(!1),[j,N]=a.useState(s),f=a.useRef(null);a.useEffect(()=>{N(s)},[s]),a.useEffect(()=>{if(!o)return;const l=b=>{var p;const S=b.target;S instanceof Node&&((p=f.current)!=null&&p.contains(S)||(r(!1),g(!1)))},u=b=>{b.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 h=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:f,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:Si(s)}),e.jsx(Ze,{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:()=>h(rs),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:Oa}),s===rs&&e.jsx(us,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]}),e.jsx("div",{className:"border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:i?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:j,onChange:l=>N(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),h(j))},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:()=>h(j),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(us,{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(Ge,{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(ls,{className:"h-3 w-3"})]})})]})]})]})}function Si(s){return s===rs?Oa:s}function Kt({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 Ci(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 _i({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(po,{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:Ci(n.content)}),t&&e.jsx(O,{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(Ge,{className:"h-3 w-3"})})]},n.id))})]})})}const Ei=a.lazy(async()=>({default:(await ct(()=>import("./FilesTab-CnNoF4D7.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Di=a.lazy(async()=>({default:(await ct(()=>import("./PreviewTab-CMAZG5kO.js"),__vite__mapDeps([6,1,2,7]))).PreviewTab})),Ti=a.lazy(async()=>({default:(await ct(()=>import("./DiffTab-CpVpmtju.js"),__vite__mapDeps([8,1,2,4,3,5,7]))).DiffTab}));function Mi({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,activeTab:j,setActiveTab:N,creatingTask:f,createMode:h,activeTask:l,assignedNode:u,taskLoading:b,taskError:S,displayEvents:p,initialPromptAlreadyInLogs:M,initialPrompt:x,supportsFollowUp:w,taskUnavailable:T,chatDisabled:U,chatDisabledReason:B,questionBypassEnabled:K,isRunning:D,isStarting:F,hasPendingFollowUp:P,canCancel:E,canRetry:A,onRetry:_,onCancel:Q,onShareTask:V,onStopShareTask:G,onStartCreateTask:ie,onCancelCreateTask:ae,onCreateTask:ee,onSendMessage:J,onCancelQueuedMessage:H,onQuestionBypassChange:W,onSubmitQuestionResponse:Y,messagesEndRef:de}){const[m,$]=a.useState(!1),[y,X]=a.useState(!1),[c,L]=a.useState(!1),[z,re]=a.useState(!1),[v,R]=a.useState(!1),[te,ge]=a.useState({}),[Ce,be]=a.useState(new Set),[Ke,$e]=a.useState(new Set),se=a.useRef(0),ce=a.useRef(!1),he=a.useRef(null),k=a.useRef(0),Ne=a.useCallback(Ee=>{const ve=Ee.currentTarget,Be=se.current;if(se.current=ve.scrollTop,ce.current)return;if(ve.scrollHeight-ve.scrollTop-ve.clientHeight<30){$(!1),ce.current=!0,setTimeout(()=>{ce.current=!1},300);return}ve.scrollTop<Be&&Be-ve.scrollTop>10&&$(!0),ve.scrollTop<=0&&$(!0)},[]),Z=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",Ae=l?(u==null?void 0:u.name)??la(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",Fe=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:Ae}),"..."]}):"Connecting session to an available node...",cs=l?[{label:"Working dir",value:Z,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:Ae}]:[],Re=!!(x&&!M),Ue=Re||p.length>0,Le=D&&Ue,_e=(F||P||D)&&!Le,fe=(l==null?void 0:l.conversationKind)==="nativeSession",Qe=(l==null?void 0:l.queuedMessages)??[],es=a.useMemo(()=>zr(p),[p]),_s=a.useMemo(()=>Ur("transcript",es.map(Ee=>Ee.event)),[es]),Es=l&&!Ce.has(l.id)?te[l.id]??l.activeShare??null:null;return f?e.jsx(Ai,{onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,defaultMode:h,onCancel:ae,onCreated:ee}):!l&&b?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(nt,{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(ue,{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(ue,{className:"h-4 w-4 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(da,{value:j,onValueChange:Ee=>{j==="transcript"&&he.current&&(k.current=he.current.scrollTop),N(Ee),Ee==="transcript"&&requestAnimationFrame(()=>{he.current&&(he.current.scrollTop=k.current)})},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(Fa,{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}),fe&&e.jsx(Te,{variant:"outline",className:"shrink-0 rounded-sm border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",children:"Native session"}),e.jsx(ca,{status:l.status}),e.jsx($n,{priority:l.priority}),e.jsx(O,{variant:"outline",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:"ml-auto h-7 w-7 shrink-0 rounded-sm border-border/70 bg-background/68",children:o?e.jsx(ft,{className:"h-4 w-4"}):e.jsx(Ea,{className:"h-4 w-4"})})]}),S&&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:S}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsxs(ua,{className:"h-auto max-w-full overflow-x-auto rounded-sm bg-muted/70 p-0.5",children:[e.jsx(Je,{value:"transcript",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Transcript"}),e.jsx(Je,{value:"files",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Files"}),e.jsx(Je,{value:"preview",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Preview"}),e.jsx(Je,{value:"diff",className:"rounded-sm px-2 py-0.5 text-[11px] sm:px-2.5",children:"Diff"})]}),D&&e.jsx(Te,{variant:"outline",className:"hidden rounded-sm border-amber-500/30 bg-amber-500/10 text-amber-700 sm:inline-flex dark:text-amber-300",children:"Working"}),T&&e.jsx(Te,{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-2 text-[10px] text-muted-foreground",children:[e.jsxs("span",{className:"hidden sm:inline",children:["updated ",Rn(l.updatedAt)]}),e.jsx("span",{className:"font-mono",children:l.id.slice(0,8)}),A&&e.jsxs(O,{variant:"outline",size:"sm",onClick:_,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(_o,{className:"h-3.5 w-3.5"}),"Retry"]}),e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:T,title:T?"Unavailable tasks cannot be shared.":"Share conversation",className:"h-7 shrink-0 rounded-sm border-primary/30 bg-primary/10 px-2 text-[11px] text-primary hover:bg-primary/15 hover:text-primary disabled:border-border/60 disabled:bg-muted/40 disabled:text-muted-foreground",onClick:()=>L(!0),children:[e.jsx(Mo,{className:"h-3.5 w-3.5"}),"Share"]})]})]})]}),e.jsx(Ye,{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:he,className:"min-h-0 flex-1 touch-pan-y overflow-x-hidden overflow-y-auto overscroll-x-none bg-gradient-to-b from-background/15 via-transparent to-background/35 px-3 py-5 sm:px-5",onScroll:Ne,children:e.jsxs("div",{className:"mx-auto flex max-w-[72rem] flex-col gap-5",children:[Re&&x&&e.jsx(Ft,{event:x,agent:l.agent,questionBypassEnabled:K,onQuestionBypassChange:W,onSubmitQuestionResponse:Y,questionResponseDisabled:!w||U}),es.map(({event:Ee,subItems:ve},Be)=>e.jsx(Ft,{event:Ee,agent:l.agent,subItems:ve,questionBypassEnabled:K,onQuestionBypassChange:W,onSubmitQuestionResponse:Y,questionResponseDisabled:!w||U},_s[Be])),!Ue&&!_e&&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:"Transcript is warming up"}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:b?"Fetching task output...":fe?"This native session is attached. Transcript starts after the next message you send from Meshy.":"The opening prompt has been stored, but the agent has not emitted conversation output yet."})]}),(!w&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!w&&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&&!Ke.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:()=>$e(Ee=>new Set(Ee).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(Ge,{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})]})]}),_e&&e.jsx(Wt,{children:Fe}),Le&&e.jsx(Wt,{children:"The agent is still working on this conversation."}),e.jsx("div",{ref:de})]})}),w?e.jsxs(e.Fragment,{children:[m&&e.jsx(O,{size:"icon",onClick:()=>$(!1),className:"absolute bottom-4 right-4 z-10 h-12 w-12 rounded-lg shadow-lg",children:e.jsx(ls,{className:"h-4 w-4"})}),e.jsxs("div",{className:`shrink-0 ${m?"hidden":""}`,children:[e.jsx(_i,{messages:Qe,onCancelMessage:H}),e.jsx("div",{className:"mx-auto w-full max-w-[72rem]",children:e.jsx(Qo,{onSend:J,disabled:U,disabledReason:B,contextItems:cs,placeholder:U?B:D?"Queue a message for the next turn...":"Continue the conversation...",running:D||P,onStop:E?()=>X(!0):void 0})})]})]}):e.jsx("div",{className:"shrink-0 border-t border-border/60 px-3 py-3 text-[11px] text-muted-foreground sm:px-5",children:"This task does not expose follow-up chat messages. Use Files, Preview, or Diff to inspect the result."})]})}),e.jsx(Ye,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Is,{label:"Loading files..."}),children:e.jsx(Ei,{taskId:l.id})})}),e.jsx(Ye,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Is,{label:"Loading preview..."}),children:e.jsx(Di,{taskId:l.id})})}),e.jsx(Ye,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Is,{label:"Loading diff..."}),children:e.jsx(Ti,{taskId:l.id})})}),e.jsx(zs,{open:y,onOpenChange:X,children:e.jsxs(Us,{children:[e.jsxs(Vs,{children:[e.jsx(qs,{children:"Stop this task?"}),e.jsx(Hs,{children:"The task will stop and move to a cancelled state."})]}),e.jsxs(Ks,{children:[e.jsx(Ws,{children:"Keep running"}),e.jsx(Gs,{onClick:Q,children:"Stop task"})]})]})}),e.jsx(wi,{open:c,onOpenChange:L,sharing:z,stopping:v,shareResult:Es,onShare:async Ee=>{if(!l)return null;re(!0);try{const ve=await V(Ee);return ve!=null&&ve.url&&(ge(Be=>({...Be,[l.id]:ve})),be(Be=>{const ss=new Set(Be);return ss.delete(l.id),ss})),ve}finally{re(!1)}},onStopShare:async()=>{if(!l)return!1;R(!0);try{const Ee=await G();return Ee!==!1&&(ge(ve=>{const Be={...ve};return delete Be[l.id],Be}),be(ve=>new Set(ve).add(l.id))),Ee}finally{R(!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(nt,{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(Pn,{className:"h-7 w-7"})}),e.jsx("h2",{className:"mt-5 text-xl font-semibold tracking-tight text-foreground sm:text-3xl",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-3 max-w-xl text-[11px] leading-6 text-muted-foreground",children:"Open a task from the left sidebar to continue the conversation, or start a new task or load a native session."}),e.jsxs(O,{onClick:ie,className:"mt-6 rounded-lg px-5",children:[e.jsx(ht,{className:"h-4 w-4"}),"Start or load chat"]}),S&&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:S})]})})]})}function Wt({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 Ai({onToggleTasks:s,desktopTasksOpen:t,mobileTasksPanelOpen:n,operationsOpen:o,onToggleOperations:r,cluster:i,sseConnected:g,defaultMode:j,onCancel:N,onCreated:f}){var b,S,p;const[h,l]=a.useState(j??"chat");a.useEffect(()=>{j&&l(j)},[j]);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:ht},{value:"native",label:"Load session",icon:xt}].map(M=>{const x=M.icon,w=M.value===h;return e.jsxs("button",{type:"button",onClick:()=>l(M.value),"aria-pressed":w,className:I("flex items-center gap-1.5 rounded-sm px-2 py-1 transition-all duration-200",w?"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(x,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:M.label})]},M.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(nt,{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(Ni,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(b=i==null?void 0:i.self)==null?void 0:b.role,currentNodeId:((S=i==null?void 0:i.self)==null?void 0:S.id)??null,leaderNodeId:((p=i==null?void 0:i.leader)==null?void 0:p.id)??null,mode:h,onModeChange:l,onCreated:f,onCancel:N,autoFocus:!0,layout:"composer"})})})]})}function nt({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(Fa,{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(O,{variant:"outline",size:"icon",onClick:r,title:o?"Hide cluster":"Show cluster","aria-label":o?"Hide cluster":"Show cluster",className:"h-7 w-7 shrink-0 rounded-sm border-border/70 bg-background/68",children:o?e.jsx(ft,{className:"h-4 w-4"}):e.jsx(Ea,{className:"h-4 w-4"})})]})}function Fa({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(O,{variant:"outline",size:"icon",onClick:n,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:"h-7 w-7 shrink-0 rounded-sm border-border/70 bg-background/68",children:o?e.jsx(_a,{className:"h-4 w-4"}):e.jsx(jo,{className:"h-4 w-4"})})}function Li({onAdded:s}){const[t,n]=a.useState(""),[o,r]=a.useState(!1),[i,g]=a.useState(null),j=a.useCallback(async N=>{if(N.preventDefault(),!!t.trim()){r(!0),g(null);try{await In({leaderEndpoint:t.trim(),transport:"devtunnel"}),s()}catch(f){g(f instanceof Error?f.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(ma,{className:"space-y-2 text-left",children:[e.jsx(dt,{className:"text-2xl tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Verify the remote leader's DevTunnel endpoint, sync this node's tasks to that leader, and join the cluster as a follower."})]})}),e.jsxs("form",{onSubmit:j,className:"space-y-4 px-6 py-5",children:[i&&e.jsx("div",{className:"rounded-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(Me,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Te,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(He,{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(xa,{className:"border-t border-border/60 pt-4",children:e.jsx(O,{type:"submit",disabled:!t.trim()||o,className:"rounded-sm",children:o?"Joining...":"Join node"})})]})]})})}function Bi({open:s,onOpenChange:t,onAdded:n}){return e.jsx(it,{open:s,onOpenChange:t,children:e.jsx(Li,{onAdded:()=>{t(!1),n()}})})}const Pi=10,Xe="__all__";function ze(s){return"session"in s}function Gt(s,t){var n;return t&&s.some(o=>o.id===t)?t:((n=s[0])==null?void 0:n.id)??""}function Fs(s){return s&&($a(s.id)||s.workDir)||""}function js(s,t,n){let o=!1;const r=s.map(i=>ze(i)&&i.session.id===n.id?(o=!0,{...i,nodeName:t,session:n}):i);return rt(o?r:[...r,{id:`session-${n.id}`,nodeName:t,session:n}])}function za(s,t){return s.filter(ze).filter(n=>n.session.nodeId===t).sort((n,o)=>o.session.startedAt-n.session.startedAt)}function $i(s){const t=s.filter(ze).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 Ri(s,t){return!!(s&&t&&!s.contains(t))}function Ii(s,t,n){var r;if(n===Xe)return n;const o=za(s,t);return o.some(i=>i.session.id===n)?n:((r=o[0])==null?void 0:r.session.id)??Xe}function Oi(s,t,n){return n===Xe?s.filter(o=>!ze(o)||o.session.nodeId===t):s.filter(o=>ze(o)&&o.session.nodeId===t&&o.session.id===n)}function rt(s){const t=s.map((o,r)=>({entry:o,index:r})).filter(({entry:o})=>ze(o)&&o.session.status!=="running").sort((o,r)=>!ze(o.entry)||!ze(r.entry)?0:r.entry.session.startedAt-o.entry.session.startedAt||r.index-o.index),n=new Set(t.slice(0,Pi).map(({entry:o})=>ze(o)?o.session.id:""));return s.filter(o=>!ze(o)||o.session.status==="running"||n.has(o.session.id))}function ot(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 Fi(s){const t=s.session.command.length>48?`${s.session.command.slice(0,45)}...`:s.session.command;return`${s.nodeName} - ${ot(s.session)} - ${t}`}function Ua(s,t=48){return s.length>t?`${s.slice(0,t-3)}...`:s}function zi(s,t){return t===Xe?"All sessions":s?Ua(s.session.command,34):"Command session"}function Qt(s){return s.status==="stopped"?"":s.stderr}function Ui({nodes:s,defaultNodeId:t,onClose:n,initialHistory:o=[]}){const[r,i]=a.useState(()=>Gt(s,t)),g=a.useMemo(()=>s.find(m=>m.id===r)??s[0]??null,[s,r]),[j,N]=a.useState(()=>Fs(g)),[f,h]=a.useState(""),[l,u]=a.useState(()=>rt(o)),[b,S]=a.useState(Xe),[p,M]=a.useState(!1),[x,w]=a.useState(!1),[T,U]=a.useState(!1),[B,K]=a.useState(!1),[D,F]=a.useState(!1),P=a.useRef(null),E=a.useRef(null),A=a.useMemo(()=>s.find(m=>m.id===r)??s[0]??null,[s,r]),_=a.useMemo(()=>za(l,(A==null?void 0:A.id)??""),[l,A]),Q=a.useMemo(()=>$i(_),[_]),V=a.useMemo(()=>_.find(m=>m.session.id===b),[b,_]),G=a.useMemo(()=>Oi(l,(A==null?void 0:A.id)??"",b),[l,A,b]),ie=a.useRef((A==null?void 0:A.id)??"");a.useEffect(()=>{r&&s.some(m=>m.id===r)||i(Gt(s,t))},[t,s,r]),a.useEffect(()=>{const m=(A==null?void 0:A.id)??"";ie.current!==m&&(ie.current=m,N(Fs(A)))},[A]),a.useEffect(()=>{S(m=>Ii(l,(A==null?void 0:A.id)??"",p?m:""))},[l,A,p]),a.useEffect(()=>{var m;(m=P.current)==null||m.scrollTo({top:P.current.scrollHeight})},[l]),a.useEffect(()=>{let m=!1;async function $(){const y=await Promise.allSettled(s.map(async X=>({node:X,response:await Fn(X.id)})));m||u(X=>y.reduce((c,L)=>L.status!=="fulfilled"?c:L.value.response.sessions.reduce((z,re)=>js(z,L.value.node.name,re),c),X))}return s.length>0&&$(),()=>{m=!0}},[s]),a.useEffect(()=>{const m=l.filter(ze).filter(y=>y.session.status==="running");if(m.length===0)return;const $=window.setInterval(()=>{for(const y of m)On(y.session.nodeId,y.session.id).then(X=>u(c=>js(c,y.nodeName,X))).catch(()=>{})},1e3);return()=>window.clearInterval($)},[l]);const ae=a.useRef(null);async function ee(m){if(m.preventDefault(),!A||!f.trim()||D)return;const $=f.trim(),y=A.name;F(!0),h("");try{const X=await Un(A.id,{command:$,...j.trim()?{cwd:j.trim()}:{}});u(c=>js(c,y,X)),S(X.id),M(!0)}catch(X){u(c=>[...c,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:y,command:$,error:X instanceof Error?X.message:"Command failed"}])}finally{F(!1)}}async function J(m,$){m.stopPropagation();const y=await zn($.session.nodeId,$.session.id);u(X=>js(X,$.nodeName,y))}function H(m){S(m),M(!0),w(!1)}function W(m){x&&Ri(E.current,m.target)&&w(!1)}function Y(m,$,y,X,c){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:X,"aria-label":`Toggle ${m} sessions`,"aria-expanded":!y,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:m}),e.jsx(Ze,{className:I("h-3 w-3 transition-transform",y&&"-rotate-90")})]}),!y&&($.length>0?$.map(de):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:c}))]})}function de(m){const $=b===m.session.id,y=m.session.status==="running";return e.jsxs("div",{className:I("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",$&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>H(m.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:I("flex h-4 w-4 shrink-0 items-center justify-center",y?"text-primary":m.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:y?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):m.session.status==="exited"?e.jsx(Bt,{className:"h-3 w-3"}):e.jsx(ys,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:Ua(m.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[m.nodeName," · ",ot(m.session)]})]})]}),y&&e.jsx("button",{type:"button",onClick:X=>void J(X,m),"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(Ut,{className:"h-3 w-3"})})]},m.session.id)}return e.jsx("section",{className:"dashboard-panel node-terminal animate-composer-settle shrink-0 overflow-visible rounded-xl","aria-label":"Node terminal",onClick:W,children:e.jsxs("div",{className:"flex w-full flex-col overflow-visible rounded-[inherit] bg-card/72 text-card-foreground",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"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(Rs,{className:"h-3.5 w-3.5"})}):e.jsx(Rs,{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:E,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":x,title:V?Fi(V):"All sessions",onClick:()=>w(m=>!m),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:zi(V,b)}),e.jsx(Ze,{className:I("h-3 w-3 shrink-0 text-muted-foreground transition-transform",x&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!x,className:I("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!x&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>H(Xe),className:I("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",b===Xe&&"bg-primary/10 text-primary"),children:[e.jsx(Rs,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),Y("Active",Q.active,T,()=>U(m=>!m),"No active sessions"),Y("Completed",Q.completed,B,()=>K(m=>!m),"No completed sessions")]})})]}),e.jsx("select",{value:(A==null?void 0:A.id)??"",onChange:m=>{i(m.target.value),M(!1),N(Fs(s.find($=>$.id===m.target.value)??null))},disabled:D||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(m=>e.jsx("option",{value:m.id,className:"bg-background text-foreground",children:m.name},m.id))}),e.jsx(Ss,{value:j,onChange:N,assignTo:(A==null?void 0:A.id)??"",nodes:s,assignableNodes:s,layout:"composer",chipClassName:"node-terminal__control h-7 max-w-[18rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground hover:bg-muted/65",chipActiveClassName:"font-mono",chipInactiveClassName:"text-muted-foreground",labelClassName:"node-terminal__control",triggerClassName:"terminal-workdir-trigger",popoverPlacement:"top",popoverAlign:"end"})]})]}),e.jsxs("div",{ref:P,className:"node-terminal__body max-h-64 min-h-[8rem] overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>{var m;return(m=ae.current)==null?void 0:m.focus()},children:[G.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:G.map(m=>ze(m)?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:[m.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:m.session.command}),e.jsxs("span",{className:I("inline-flex items-center gap-1",m.session.status==="running"||m.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[m.session.status==="running"?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):m.session.status==="exited"?e.jsx(Bt,{className:"h-3 w-3"}):e.jsx(ys,{className:"h-3 w-3"}),ot(m.session)]}),m.session.status==="running"&&e.jsx("button",{type:"button",onClick:$=>void J($,m),"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(Ut,{className:"h-3 w-3"})})]}),m.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:m.session.stdout}),Qt(m.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Qt(m.session)}),(m.session.stdoutTruncated||m.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},m.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:[m.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:m.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(ys,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:m.error})]},m.id))}),e.jsxs("form",{onSubmit:ee,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:A?`${A.name}$`:"$"}),e.jsx("input",{ref:ae,value:f,onChange:m=>h(m.target.value),disabled:!A||D,placeholder:A?"":"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:!A||!f.trim()||D,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:text-muted-foreground disabled:opacity-50",children:D?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(mt,{className:"h-3 w-3"})})]})]})]})})}function bt({nodeId:s,nodeName:t,onOpenSettings:n,onOpenDevBox:o,onStartDevBox:r,showConfigureDevBox:i,showStartDevBox:g,startDevBoxPending:j,className:N}){const[f,h]=a.useState(!1),l=a.useRef(null),u=j?"Starting":"Start DevBox";return a.useEffect(()=>{if(!f)return;const b=p=>{var x;const M=p.target;M instanceof Node&&((x=l.current)!=null&&x.contains(M)||h(!1))},S=p=>{p.key==="Escape"&&h(!1)};return document.addEventListener("mousedown",b),document.addEventListener("keydown",S),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",S)}},[f]),e.jsxs("div",{ref:l,className:I("relative shrink-0",N),onClick:b=>b.stopPropagation(),children:[e.jsx(O,{type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${t}`,"aria-haspopup":"menu","aria-expanded":f,title:`More actions for ${t}`,onClick:()=>h(b=>!b),className:I("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",f&&"bg-background/80 text-primary"),children:e.jsx(eo,{className:"h-3.5 w-3.5"})}),f&&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:()=>{h(!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(Vn,{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:()=>{j||(h(!1),r(s))},disabled:j,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:[j?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(mt,{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:()=>{h(!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(qn,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Configure DevBox"})]})]})]})}const Vi=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),qi=new Set(["startinprogress","starting"]);function os(s){return!!(s!=null&&s.enabled&&s.name)}function Hi(s){const t=s==null?void 0:s.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(t&&Vi.has(t))}function is(s){const t=s==null?void 0:s.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(t&&qi.has(t))}function Cs(s,t,n){return s==="offline"&&Hi(t)&&os(n)}function Jt(s,t){return s==="offline"&&os(t)}function Yt(s){return!os(s)}function Ki({nodeStatus:s,status:t,current:n,selected:o}){const r=o??n;return r&&Cs(s,t,r)?r:null}function De(s){return s.scope||`name:${s.name??""}`}function Wi({previousKey:s,baseDevBox:t,listed:n}){if(s&&n.some(i=>De(i)===s))return s;if(!os(t))return n[0]?De(n[0]):"";const o=De(t),r=n.find(i=>De(i)===o)??n.find(i=>i.name===t.name);return r?De(r):o}function Xt({cluster:s,systemInfo:t,nodeNameById:n,nodeBlockingTaskCounts:o,eventTypeFilter:r,onEventTypeFilterChange:i,eventTypeOptions:g,filteredEvents:j,sseConnected:N,clusterLoading:f,clusterError:h,promotePending:l,onPromote:u,onAddNode:b,leavePending:S,onLeaveCluster:p,onToggleNodeDevTunnel:M,devTunnelNodeId:x,devBoxStartNodeId:w,devBoxStartingNodeIds:T=new Set,onOpenNodeSettings:U,onOpenDevBox:B,onStartDevBox:K,onClose:D}){var ae,ee,J;const F=((ae=s==null?void 0:s.self)==null?void 0:ae.role)==="leader",P=((ee=s==null?void 0:s.self)==null?void 0:ee.role)==="follower"&&!(s!=null&&s.leader),E=(s==null?void 0:s.self)??null,_=Hn((s==null?void 0:s.nodes)??[],E==null?void 0:E.id).filter(H=>H.id!==(E==null?void 0:E.id)),Q=s!=null&&s.leader?s.nodes.find(H=>{var W;return H.id===((W=s.leader)==null?void 0:W.id)})??null:null,V=s!=null&&s.leader?s.leader.dashboardOrigin??(Q==null?void 0:Q.dashboardOrigin)??(t&&s.leader.id===(t.nodeId??t.id)?t.dashboardOrigin:void 0)??s.leader.endpoint:null,G=(E==null?void 0:E.role)==="leader"&&_.length===0,ie=(E==null?void 0:E.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(da,{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(O,{variant:"ghost",size:"icon",onClick:D,className:"h-6 w-6 rounded-sm",children:e.jsx(ft,{className:"h-3.5 w-3.5"})})]}),e.jsxs(ua,{className:"mt-1.5 grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(Je,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(Je,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(Je,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})]}),e.jsx(Ye,{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:[E&&e.jsx(Zt,{node:E,systemInfo:t,blockingTaskCount:o.get(E.id)??0,devTunnelNodeId:x,onToggleNodeDevTunnel:M,showActions:!1,defaultExpanded:!1,onOpenDevBox:B,devBoxStartingNodeIds:T}),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(Te,{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"})]}),f&&!s?e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"}),"Loading cluster state..."]}):h&&!s?e.jsx("div",{className:"rounded-sm bg-destructive/10 px-2 py-1.5 text-[10px] text-destructive shadow-sm",children:h}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(as,{label:"Term",value:String((s==null?void 0:s.term)??0)}),e.jsx(as,{label:"Nodes",value:String((s==null?void 0:s.nodes.length)??0)}),e.jsx(as,{label:"Pending",value:String((s==null?void 0:s.taskSummary.pending)??0)}),e.jsx(as,{label:"Running",value:String((s==null?void 0:s.taskSummary.running)??0)}),e.jsx(as,{label:"Completed",value:String((s==null?void 0:s.taskSummary.completed)??0)}),e.jsx(as,{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:((J=s==null?void 0:s.leader)==null?void 0:J.name)??"None"}),e.jsx(qe,{label:"Leader URL",value:V??"Unavailable",mono:!0,action:V?e.jsx(hs,{label:"Copy leader URL",onClick:()=>void ns(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:P&&e.jsxs(O,{variant:"outline",size:"sm",onClick:u,disabled:l,className:"h-6 rounded-sm px-2 text-[10px]",children:[l&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(Ye,{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"}),G?e.jsx(O,{variant:"outline",size:"sm",onClick:b,className:"h-6 rounded-sm px-2 text-[10px]",children:"Join node"}):ie?e.jsxs(O,{variant:"outline",size:"sm",onClick:p,disabled:S,className:"h-6 rounded-sm px-2 text-[10px]",children:[S&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),E&&e.jsx(Zt,{node:E,systemInfo:t,blockingTaskCount:o.get(E.id)??0,devTunnelNodeId:x,onToggleNodeDevTunnel:M,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:F?U:void 0,onOpenDevBox:F?B:void 0,onStartDevBox:F?K:void 0,devBoxStartNodeId:w,devBoxStartingNodeIds:T})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",_.length,")"]}),_.length>0?e.jsx("div",{className:"space-y-1.5",children:_.map(H=>e.jsx(Gi,{node:H,isLeader:!!F,blockingTaskCount:o.get(H.id)??0,devTunnelNodeId:x,onToggleNodeDevTunnel:M,onOpenNodeSettings:F?U:void 0,onOpenDevBox:F?B:void 0,onStartDevBox:F?K:void 0,devBoxStartNodeId:w,devBoxStartingNodeIds:T},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(Ye,{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(Kn,{className:I("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(ye,{value:r,onValueChange:i,children:[e.jsx(ke,{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(Pe,{placeholder:"Event type"})}),e.jsx(Se,{children:g.map(H=>e.jsx(we,{value:H,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:H==="all"?"All event types":H},H))})]}),e.jsx(Te,{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(Wn,{events:j,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 Zt({node:s,systemInfo:t,blockingTaskCount:n,devTunnelNodeId:o,onToggleNodeDevTunnel:r,showActions:i=!0,defaultExpanded:g=!1,onOpenNodeSettings:j,onOpenDevBox:N,onStartDevBox:f,devBoxStartNodeId:h,devBoxStartingNodeIds:l}){var K,D,F,P;const[u,b]=a.useState(g),S=(t==null?void 0:t.dashboardOrigin)??s.dashboardOrigin,p=s.devtunnelEndpoint??s.endpoint,M=S??s.endpoint,x=(t==null?void 0:t.workDir)??s.workDir,w=Ma(s,t==null?void 0:t.transportType),T=pt(s,t==null?void 0:t.transportType),U=T&&ds((t==null?void 0:t.transportType)??s.transportType)?!0:Ta(s,t==null?void 0:t.transportType),B=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:()=>b(E=>!E),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[u?e.jsx(Ze,{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(ha,{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:M,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(fa,{className:"h-3 w-3"})}),j&&e.jsx(bt,{nodeId:s.id,nodeName:s.name,onOpenSettings:j,onOpenDevBox:N,onStartDevBox:f,showConfigureDevBox:(K=s.devbox)==null?void 0:K.enabled,showStartDevBox:Cs(s.status,(D=s.devbox)==null?void 0:D.lastStatus,s.devbox)||is((F=s.devbox)==null?void 0:F.lastStatus)||l.has(s.id),startDevBoxPending:h===s.id||is((P=s.devbox)==null?void 0:P.lastStatus)||l.has(s.id)})]}),e.jsxs("button",{type:"button",onClick:()=>b(E=>!E),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(pa,{role:s.role,size:"compact"}),e.jsx(Te,{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(hs,{label:"Copy dashboard URL",onClick:()=>void ns(S,"Dashboard URL copied")})}),e.jsx(qe,{label:"Node URL",value:p,mono:!0,action:e.jsx(hs,{label:"Copy node URL",onClick:()=>void ns(p,"Node URL copied")})}),x&&e.jsx(qe,{label:"Workspace",value:x,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Js,{label:"Transport",value:w}),t&&e.jsx(Js,{label:"Uptime",value:Gn(t.uptime),mono:!0})]}),e.jsx(wa,{capabilities:s.capabilities,action:i&&U?e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>r(s),disabled:o===s.id||B,className:"h-6 rounded-sm px-2 text-[10px]",title:B?"Finish assigned or running tasks before changing remote access":void 0,children:[o===s.id&&e.jsx(ue,{className:"h-3 w-3 animate-spin"}),T?"Disable Remote Access":"Enable Remote Access"]}):void 0}),i&&U&&B&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Gi({node:s,isLeader:t,blockingTaskCount:n,devTunnelNodeId:o,onToggleNodeDevTunnel:r,onOpenNodeSettings:i,onOpenDevBox:g,onStartDevBox:j,devBoxStartNodeId:N,devBoxStartingNodeIds:f}){var T,U,B,K;const[h,l]=a.useState(!1),u=s.dashboardOrigin,b=s.devtunnelEndpoint??s.endpoint,S=u??s.endpoint,p=Ma(s),M=pt(s),x=Ta(s),w=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(D=>!D),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[h?e.jsx(Ze,{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(ha,{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(fa,{className:"h-3 w-3"})}),t&&i&&e.jsx(bt,{nodeId:s.id,nodeName:s.name,onOpenSettings:i,onOpenDevBox:g,onStartDevBox:j,showConfigureDevBox:(T=s.devbox)==null?void 0:T.enabled,showStartDevBox:Cs(s.status,(U=s.devbox)==null?void 0:U.lastStatus,s.devbox)||is((B=s.devbox)==null?void 0:B.lastStatus)||f.has(s.id),startDevBoxPending:N===s.id||is((K=s.devbox)==null?void 0:K.lastStatus)||f.has(s.id)})]}),e.jsxs("button",{type:"button",onClick:()=>l(D=>!D),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(pa,{role:s.role,size:"compact"}),e.jsx(Te,{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})]})]}),h&&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(hs,{label:"Copy dashboard URL",onClick:()=>void ns(u,"Dashboard URL copied")})}),e.jsx(qe,{label:"Node URL",value:b,mono:!0,action:e.jsx(hs,{label:"Copy node URL",onClick:()=>void ns(b,"Node URL copied")})}),s.workDir&&e.jsx(qe,{label:"Workspace",value:s.workDir,mono:!0}),e.jsx(Js,{label:"Transport",value:p})]}),e.jsx(wa,{capabilities:s.capabilities,action:t&&x?e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>r(s),disabled:o===s.id||w,className:"h-6 rounded-sm px-2 text-[10px]",title:w?"Finish assigned or running tasks before changing remote access":void 0,children:[o===s.id&&e.jsx(ue,{className:"h-3 w-3 animate-spin"}),M?"Disable Remote Access":"Enable Remote Access"]}):void 0}),t&&x&&w&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function hs({label:s,onClick:t}){return e.jsx(O,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground",onClick:t,"aria-label":s,title:s,children:e.jsx(ia,{className:"h-3 w-3"})})}function Qi(s,t,n,o){var g;if(!s)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const r=((g=t==null?void 0:t.self)==null?void 0:g.role)==="follower";return s.assignedTo!==null&&s.assignedNodeAvailable===!1?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${s.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}: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..."}:ks.has(s.status)||s.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:ks.has(s.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const Ns="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",ws="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function ea({toolbarTasks:s,activeTaskId:t,tasksLoading:n,tasksError:o,isLeader:r,scope:i,agentFilter:g,nodeFilter:j,taskKindFilter:N,agentOptions:f,nodeOptions:h,nodeNameById:l,nodeStatusById:u,devBoxNodeIds:b=new Set,devBoxStartNodeIds:S=new Set,devBoxStartingNodeIds:p=new Set,leaderNodeId:M,searchQuery:x,selectedTaskIds:w,allVisibleTasksSelected:T,someVisibleTasksSelected:U,canBatchArchive:B,onSearchChange:K,onScopeChange:D,onAgentFilterChange:F,onNodeFilterChange:P,onTaskKindFilterChange:E,onToggleTaskSelected:A,onToggleAllVisibleTasks:_,onBatchArchive:Q,onBatchDelete:V,onCreateTask:G,onOpenNodeSettings:ie,onOpenDevBox:ae,onStartDevBox:ee,onSelectTask:J,onClose:H}){const[W,Y]=a.useState(!!x),[de,m]=a.useState(!1),[$,y]=a.useState(!1),X=a.useRef(null),c=a.useRef(null),L=a.useRef(null),z=w.size,re=i!=="active"||j!=="all"||g!=="all"||N!=="all",v=x.trim().length>0,[R,te]=a.useState(new Set),[ge,Ce]=a.useState(new Set),be=a.useMemo(()=>Qn(s,l,M),[s,l,M]),Ke=be.length===1,$e=!Ke||re||v,se=Ke&&(re||v),ce=a.useCallback(k=>{te(Ne=>{const Z=new Set(Ne);return Z.has(k)?Z.delete(k):Z.add(k),Z})},[]),he=a.useCallback(k=>{Ce(Ne=>{const Z=new Set(Ne);return Z.has(k)?Z.delete(k):Z.add(k),Z})},[]);return a.useEffect(()=>{x&&Y(!0)},[x]),a.useEffect(()=>{var k;W&&((k=X.current)==null||k.focus())},[W]),a.useEffect(()=>{if(!W)return;const k=Z=>{var Fe;const Ae=Z.target;Ae instanceof Node&&((Fe=c.current)!=null&&Fe.contains(Ae)||Y(!1))},Ne=Z=>{Z.key==="Escape"&&Y(!1)};return document.addEventListener("mousedown",k),document.addEventListener("keydown",Ne),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",Ne)}},[W]),a.useEffect(()=>{if(!$)return;const k=Z=>{var Fe;const Ae=Z.target;Ae instanceof Node&&((Fe=L.current)!=null&&Fe.contains(Ae)||y(!1))},Ne=Z=>{Z.key==="Escape"&&y(!1)};return document.addEventListener("mousedown",k),document.addEventListener("keydown",Ne),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",Ne)}},[$]),e.jsxs("aside",{className:"dashboard-panel dashboard-panel-muted 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/24 px-3 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-1.5",children:[e.jsx("div",{className:"text-lg font-semibold tracking-tight text-foreground",children:"Tasks"}),e.jsx(O,{variant:"ghost",size:"icon",onClick:H,className:"rounded-sm",children:e.jsx(_a,{className:"h-4 w-4"})})]}),e.jsxs("div",{ref:c,className:"mt-4 flex items-center gap-1.5",children:[e.jsxs("div",{ref:L,className:I("relative flex items-stretch transition-[flex] duration-200",W?"flex-[2]":"flex-1"),children:[e.jsxs(O,{onClick:()=>{y(!1),G("chat")},className:"h-10 flex-1 justify-start rounded-l-sm rounded-r-none px-3 text-left shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(ht,{className:"h-4 w-4"}),"New chat"]}),e.jsx(O,{onClick:()=>y(k=>!k),"aria-label":"More chat options","aria-haspopup":"menu","aria-expanded":$,className:"h-10 w-8 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(Ze,{className:I("h-3.5 w-3.5 transition-transform",$&&"rotate-180")})}),$&&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:()=>{y(!1),G("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(xt,{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"})]})})]}),W?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(et,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(He,{ref:X,value:x,onChange:k=>K(k.target.value),placeholder:"Search tasks",className:"h-11 rounded-lg border-border/70 bg-background/68 pl-11 text-[11px]"})]}),e.jsx(O,{variant:"outline",size:"icon",onClick:()=>Y(!1),className:"rounded-sm border-border/70 bg-background/68",children:e.jsx(ys,{className:"h-4 w-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(O,{variant:"outline",onClick:()=>Y(!0),className:I("rounded-sm border-border/70 bg-background/68 px-3 text-[11px]",x&&"border-primary/40 bg-primary/8 text-primary"),children:[e.jsx(et,{className:"h-4 w-4"}),"Search"]}),e.jsx(O,{variant:de||re?"secondary":"outline",size:"icon",onClick:()=>m(k=>!k),className:I("shrink-0 rounded-sm border-border/70 bg-background/68",re&&"border-primary/40 bg-primary/8 text-primary"),title:"Filters",children:e.jsx(ro,{className:"h-4 w-4"})})]})]}),(de||re)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(ye,{value:i,onValueChange:k=>D(k),children:[e.jsx(ke,{className:Ns,children:e.jsx(Pe,{})}),e.jsx(Se,{children:Jn.map(k=>e.jsx(we,{value:k.value,className:ws,children:k.label},k.value))})]}),e.jsxs(ye,{value:j,onValueChange:P,children:[e.jsx(ke,{className:Ns,children:e.jsx(Pe,{placeholder:"Node"})}),e.jsx(Se,{children:h.map(k=>e.jsx(we,{value:k.value,className:ws,children:k.label},k.value))})]}),e.jsxs(ye,{value:g,onValueChange:F,children:[e.jsx(ke,{className:Ns,children:e.jsx(Pe,{placeholder:"Agent"})}),e.jsx(Se,{children:f.map(k=>e.jsx(we,{value:k,className:ws,children:k==="all"?"All agents":k},k))})]}),e.jsxs(ye,{value:N,onValueChange:k=>E(k),children:[e.jsx(ke,{className:Ns,children:e.jsx(Pe,{placeholder:"Type"})}),e.jsx(Se,{children:Yn.map(k=>e.jsx(we,{value:k.value,className:ws,children:k.label},k.value))})]})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-1.5 py-2",children:be.length>0?e.jsxs("div",{className:"space-y-1",children:[r&&e.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 py-0.5",children:[e.jsxs("label",{className:"flex items-center gap-[5px] text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/75",children:[e.jsx(Qs,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:U&&!T?"indeterminate":T,onCheckedChange:k=>_(k===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Select all"})]}),z>0&&e.jsx(O,{variant:"ghost",size:"sm",onClick:()=>_(!1),className:"h-5 rounded-sm px-1.5 text-[10px]",children:"Clear"})]}),be.map(k=>{const Ne=k.nodeId??"__unassigned__",Z=k.dirs.reduce((Re,Ue)=>Re+Ue.tasks.length,0),Ae=$e&&!se&&R.has(Ne),Fe=k.nodeId!==null&&u.get(k.nodeId)==="offline",cs=!!(r&&k.nodeId&&ie);return e.jsxs("div",{className:"space-y-1",children:[$e&&e.jsxs("div",{className:"flex w-full items-center gap-1.5 rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 px-2 py-1.5 text-left text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsxs("button",{type:"button",onClick:()=>ce(Ne),"aria-expanded":!Ae,className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[e.jsx(ms,{className:I("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!Ae&&"rotate-90")}),e.jsx(ra,{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:k.nodeName}),e.jsxs(Te,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-border/60 bg-background/55 px-1.5 py-0 text-[8px] font-semibold leading-4 text-muted-foreground shadow-none normal-case tracking-normal",children:[Z," task",Z===1?"":"s"]})]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[Fe&&e.jsx(Te,{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"}),k.nodeId===M&&e.jsx(Te,{variant:"outline",className:"rounded-sm border-primary/25 bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"}),cs&&k.nodeId&&ie&&e.jsx(bt,{nodeId:k.nodeId,nodeName:k.nodeName,onOpenSettings:ie,onOpenDevBox:ae,onStartDevBox:ee,showConfigureDevBox:b.has(k.nodeId),showStartDevBox:S.has(k.nodeId)||p.has(k.nodeId),startDevBoxPending:p.has(k.nodeId)})]})]}),e.jsx("div",{className:I("grid transition-[grid-template-rows] duration-300 ease-in-out",Ae?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:k.dirs.map(Re=>{const Ue=`${Ne}::${Re.path}`,Le=ge.has(Ue),_e=Xn(Re.path);return e.jsxs("div",{className:I("space-y-0.5 rounded-xl",$e&&"pl-2.5"),children:[e.jsxs("button",{type:"button",onClick:()=>he(Ue),"aria-expanded":!Le,title:Re.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:I("h-3 w-3 shrink-0 transition-transform duration-200",!Le&&"rotate-90")}),e.jsx(Sa,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"truncate font-mono",children:_e}),e.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-muted-foreground/40",children:Re.tasks.length})]}),e.jsx("div",{className:I("grid transition-[grid-template-rows] duration-300 ease-in-out",Le?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:I("overflow-hidden",$e?"pl-2":"pl-0"),children:e.jsx("div",{className:"space-y-px py-0.5",children:Re.tasks.map(fe=>e.jsxs("div",{className:I("flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",fe.id===t?"bg-muted/50":"hover:bg-muted/40"),children:[r&&e.jsx("div",{className:"flex shrink-0",onClick:Qe=>Qe.stopPropagation(),children:e.jsx(Qs,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:w.has(fe.id),onCheckedChange:Qe=>A(fe.id,Qe===!0),"aria-label":`Select ${fe.title}`})}),e.jsxs("button",{type:"button",onClick:()=>J(fe.id),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:I("h-1.5 w-1.5 shrink-0 rounded-full",Zn(fe.status),(fe.status==="running"||fe.status==="assigned")&&"animate-soft-status-pulse")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-medium leading-4 text-foreground/80",children:fe.title}),e.jsx("span",{className:"ml-1 shrink-0 tabular-nums text-[10px] text-muted-foreground/55",children:er(fe.updatedAt)}),fe.id===t&&e.jsx("span",{className:"ml-1 h-1.5 w-1.5 shrink-0 rounded-full bg-primary/70"})]}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5 pl-3",children:[e.jsx(ca,{status:fe.status,size:"compact"}),e.jsx("span",{className:"font-mono text-[8px] leading-3 text-muted-foreground/55",children:fe.agent}),fe.conversationKind==="nativeSession"&&e.jsx(Te,{variant:"outline",className:"rounded-sm border-sky-500/25 bg-sky-500/8 px-1 py-0 text-[8px] leading-3 text-sky-700 shadow-none dark:text-sky-300",children:"native"}),fe.activeShare&&e.jsx(Te,{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"}),fe.assignedNodeAvailable===!1&&e.jsx(Te,{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"})]})]})]},fe.id))})})})]},Ue)})})})]},Ne)})]}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map(k=>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+k*12}%`,animationDelay:`${k*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${k*120+60}ms`}})]})]})},k))}):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."})}),r&&z>0?e.jsxs("div",{className:"shrink-0 border-t border-border/60 px-3 py-3",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:"Batch actions"}),e.jsxs("div",{className:"mt-2 text-[10px] font-semibold text-foreground",children:[z," task",z!==1?"s":""," selected"]}),!B&&e.jsx("div",{className:"mt-2 text-[10px] leading-4 text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[e.jsxs(zs,{children:[e.jsx(Pt,{asChild:!0,children:e.jsxs(O,{variant:"outline",size:"sm",disabled:!B,className:"h-7 gap-1.5 rounded-sm px-2 text-[10px] [&_svg]:size-3.5",children:[e.jsx(Jr,{}),"Archive"]})}),e.jsxs(Us,{children:[e.jsxs(Vs,{children:[e.jsxs(qs,{children:["Archive ",z," task",z!==1?"s":"","?"]}),e.jsx(Hs,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(Ks,{children:[e.jsx(Ws,{children:"Cancel"}),e.jsx(Gs,{onClick:Q,disabled:!B,children:"Archive"})]})]})]}),e.jsxs(zs,{children:[e.jsx(Pt,{asChild:!0,children:e.jsxs(O,{variant:"destructive",size:"sm",className:"h-7 gap-1.5 rounded-sm px-2 text-[10px] [&_svg]:size-3.5",children:[e.jsx($o,{}),"Delete"]})}),e.jsxs(Us,{children:[e.jsxs(Vs,{children:[e.jsxs(qs,{children:["Delete ",z," task",z!==1?"s":"","?"]}),e.jsx(Hs,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(Ks,{children:[e.jsx(Ws,{children:"Cancel"}),e.jsx(Gs,{onClick:V,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]})]}):null]})}async function Ji(s,t){var n,o;try{const r=await sr(s,t),i={...r,url:oa(r.url)};if((o=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&o.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),oe.success("Shared link copied")}catch{oe.success("Shared link created")}else oe.success("Shared link created");return i}catch(r){oe.error(r instanceof Error?r.message:"Failed to create shared link");return}}async function Yi(s){try{return await tr(s),oe.success("Shared link stopped"),!0}catch(t){return oe.error(t instanceof Error?t.message:"Failed to stop shared link"),!1}}function Xi(s,t,n){const o=a.useCallback(()=>{t(),n()},[t,n]),r=a.useCallback(async g=>{if(!s)return;const j=await Ji(s.id,g);return j&&o(),j},[s,o]),i=a.useCallback(async()=>{if(!s)return!1;const g=await Yi(s.id);return g&&o(),g},[s,o]);return{handleShareTask:r,handleStopShareTask:i}}function sa(s,t,n){const o=a.useRef(t);o.current=t,a.useEffect(()=>{let g=0,j=0;const N=l=>{const u=l.touches[0];u&&(g=u.clientX,j=u.clientY)},f=l=>{var p,M,x,w;const u=l.changedTouches[0];if(!u)return;const b=u.clientX-g;Math.abs(u.clientY-j)>100||Math.abs(b)<50||(b>0?(M=(p=o.current).onSwipeRight)==null||M.call(p):(w=(x=o.current).onSwipeLeft)==null||w.call(x))},h=(s==null?void 0:s.current)??document;return h.addEventListener("touchstart",N,{passive:!0}),h.addEventListener("touchend",f,{passive:!0}),()=>{h.removeEventListener("touchstart",N),h.removeEventListener("touchend",f)}},[s,n==null?void 0:n.threshold,n==null?void 0:n.maxVertical])}const Zi="(min-width: 1024px)",el="(min-width: 1800px)";function ta(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 sl(){const[s,t]=a.useState(!0),[n,o]=a.useState(!1),[r,i]=a.useState(()=>ta(el)),g=a.useRef(null),j=a.useRef(null);sa(g,{onSwipeLeft:()=>o(!1)}),sa(j,{onSwipeRight:()=>i(!1)});const N=a.useCallback(()=>{if(ta(Zi)){t(f=>!f);return}o(f=>!f)},[]);return{desktopTasksOpen:s,mobileTasksPanelOpen:n,mobileTasksPanelRef:g,operationsOpen:r,operationsPanelRef:j,setMobileTasksPanelOpen:o,setOperationsOpen:i,toggleTasksPanel:N}}function tl(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 al({isLeader:s,selfId:t}){return{assignedTo:!s&&t?t:void 0}}function nl({isLeader:s,selfId:t,sseConnected:n,subscribe:o}){const[r,i]=a.useState([]),[g,j]=a.useState(!0),[N,f]=a.useState(null),h=a.useRef(null),l=a.useCallback(async()=>{try{const b=await ar(al({isLeader:s,selfId:t}));i(b),f(null)}catch(b){f(b instanceof Error?b.message:"Failed to load tasks")}finally{j(!1)}},[s,t]),u=a.useCallback(()=>{h.current===null&&(h.current=window.setTimeout(()=>{h.current=null,l()},nr))},[l]);return rr(l,lr(n)),a.useEffect(()=>()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),a.useEffect(()=>{const b=[o("task.updated",S=>{i(p=>tl(p,S.data))}),o("task.status",S=>{i(p=>or(p,S.data))}),o("task",S=>{ir(S.type)&&u()})];return()=>b.forEach(S=>S())},[o,u]),{fetchTasks:l,setTasks:i,tasks:r,tasksError:N,tasksLoading:g}}function rl(s,t){return t.data.nodeId===s.self.id||t.data.name===s.self.name||t.data.endpoint===s.self.endpoint}function ol({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=rl(s,o);o.type==="node.joined"&&!i&&oe.success(`${r} joined the cluster`),o.type==="node.left"&&!i&&oe.message(`${r} left the cluster`)})},[s,t])}const il=[0,300,1e3,2e3];function ll({task:s,getActiveTaskId:t,setLogs:n,setPendingMessages:o}){s.conversationKind==="nativeSession"&&(async()=>{for(const r of il){if(r>0&&await new Promise(i=>setTimeout(i,r)),t()!==s.id)return;try{const i=await ga(s.id);if(t()!==s.id||(n(g=>ya(g,i.logs)),o(g=>ka(g,i.logs)),i.total>0))return}catch{}}})()}function dl(s,t){return De(s??{})===De(t??{})}function cl(s){return s&&"status"in s&&typeof s.status=="string"?s.status:void 0}function aa(s,t){return{...s,enabled:!0,alwaysOnline:t}}function Va(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 ul({operationStarting:s,loading:t,refreshing:n,savedStatus:o,fallbackStatus:r}){return s?"Starting":t?"Listing DevBoxes":n?"Refreshing":o??r}function na({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:Va(s)})]})}function ml({node:s,open:t,startInProgress:n=!1,onOpenChange:o,onRefresh:r}){const i=(s==null?void 0:s.id)??null,g=t&&!n&&Jt(s==null?void 0:s.status,(s==null?void 0:s.devbox)??null),[j,N]=a.useState([]),[f,h]=a.useState(()=>s!=null&&s.devbox?De(s.devbox):""),[l,u]=a.useState(()=>(s==null?void 0:s.devbox)??null),[b,S]=a.useState(()=>Yt((s==null?void 0:s.devbox)??null)),[p,M]=a.useState(!1),[x,w]=a.useState(g),[T,U]=a.useState(!1),[B,K]=a.useState(!1),[D,F]=a.useState(()=>{var c;return((c=s==null?void 0:s.devbox)==null?void 0:c.alwaysOnline)===!0}),P=a.useMemo(()=>{const c=j.find(L=>De(L)===f);return c||(os(l)&&De(l)===f?l:void 0)},[l,j,f]),E=cl(P??void 0),A=b?E??(l==null?void 0:l.lastStatus):(l==null?void 0:l.lastStatus)??E,_=(s==null?void 0:s.status)==="online"||(s==null?void 0:s.status)==="busy"?"Running":"Unknown",Q=B||n,V=ul({operationStarting:Q,loading:p,refreshing:x,savedStatus:A,fallbackStatus:_}),G=b&&!!P&&!dl(l,P),ie=(l==null?void 0:l.alwaysOnline)===!0!==D,ae=Ki({nodeStatus:s==null?void 0:s.status,status:V,current:l,selected:P}),ee=!!ae,J=!!P&&(G||ie)&&!ee,H=P??l,W=a.useCallback(async()=>{if(i){w(!0);try{const c=await dr(i);u(c.devbox),h(De(c.devbox))}catch(c){oe.error(c instanceof Error?c.message:"Failed to refresh DevBox status")}finally{w(!1)}}},[i]),Y=a.useCallback(async c=>{M(!0);try{const L=await cr();N(L),h(z=>Wi({previousKey:z,baseDevBox:c,listed:L}))}catch(L){oe.error(L instanceof Error?L.message:"Failed to load DevBoxes")}finally{M(!1)}},[]);a.useEffect(()=>{if(!t||!i)return;let c=!1;const L=(s==null?void 0:s.devbox)??null,z=Yt(L),re=!n&&Jt(s==null?void 0:s.status,L);M(!1),w(re),S(z),u(L),F((L==null?void 0:L.alwaysOnline)===!0),h(os(L)?De(L):""),N([]);async function v(){re&&await W(),!c&&z&&await Y(L)}return v(),()=>{c=!0}},[Y,s==null?void 0:s.devbox,s==null?void 0:s.status,i,t,W,n]);async function de(){S(!0),j.length===0&&await Y(l)}async function m(){if(!(!s||!P)){U(!0);try{const c=await $t(s.id,aa(P,D));u(c.node.devbox??null),c.node.devbox&&h(De(c.node.devbox)),S(!1),oe.success(`Configured DevBox for ${s.name}`),await(r==null?void 0:r())}catch(c){oe.error(c instanceof Error?c.message:"Failed to configure DevBox")}finally{U(!1)}}}async function $(){if(!(!s||!ae)){K(!0);try{if(P&&(G||ie)){const L=await $t(s.id,aa(P,D));u(L.node.devbox??null),L.node.devbox&&h(De(L.node.devbox)),S(!1)}const{operation:c}=await ba(s.id);u(L=>L&&{...L,lastStatus:"Starting",checkedAt:Date.now(),operationId:c.id}),oe.success(`Start requested for ${s.name}`),await(r==null?void 0:r())}catch(c){oe.error(c instanceof Error?c.message:"Failed to start DevBox")}finally{K(!1)}}}const y=p?"Loading DevBoxes...":j.length===0?"No DevBoxes available":"Select a DevBox",X=V==="Running"&&(s==null?void 0:s.status)==="offline";return e.jsx(it,{open:t,onOpenChange:o,children:e.jsxs(lt,{className:"max-w-md gap-4 rounded-lg p-5",children:[e.jsxs(ma,{className:"space-y-1",children:[e.jsx(dt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(ur,{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:[(b||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:b?e.jsxs(ye,{value:f,onValueChange:h,disabled:p||T||B||j.length===0,children:[e.jsx(ke,{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:p&&!P?e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),y]}):P?e.jsx(na,{devbox:P}):e.jsx(Pe,{placeholder:y})}),e.jsx(Se,{children:j.map(c=>e.jsx(we,{value:De(c),textValue:`${c.name} ${c.projectName??""} ${Va(c)}`,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(na,{devbox:c,showStatus:!0})},De(c)))})]}):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(Te,{variant:"outline",className:"rounded-full px-2 py-0.5 text-[10px]",children:[(p||x)&&e.jsx(ue,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),V]}),(l==null?void 0:l.name)&&e.jsx(O,{type:"button",variant:"ghost",size:"icon",onClick:()=>{de()},disabled:p||T||Q||b,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-full text-muted-foreground hover:text-foreground",children:p&&b?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(ls,{className:"h-3 w-3"})})]})]}),X&&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(Qs,{checked:D,onCheckedChange:c=>F(c===!0),disabled:T||B||Q,"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(xa,{className:"gap-2 sm:space-x-0",children:[e.jsx(O,{variant:"ghost",size:"sm",onClick:()=>o(!1),disabled:T||B,className:"h-8 rounded-xl text-xs",children:"Close"}),ee&&e.jsxs(O,{size:"sm",onClick:$,disabled:B,className:"h-8 rounded-xl text-xs",children:[B?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(mt,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!ee&&e.jsxs(O,{size:"sm",onClick:m,disabled:!J||T,className:"h-8 rounded-xl text-xs",children:[T&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function xl(s,t=mr){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 hl({cluster:s,refresh:t}){const[n,o]=a.useState(null),[r,i]=a.useState(null),[g,j]=a.useState(()=>new Set),[N,f]=a.useState(()=>new Set),h=a.useMemo(()=>(s==null?void 0:s.nodes.find(x=>x.id===n))??null,[s==null?void 0:s.nodes,n]),l=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(x=>{var w;return(w=x.devbox)==null?void 0:w.enabled}).map(x=>x.id)),[s==null?void 0:s.nodes]),u=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(x=>{var w;return Cs(x.status,(w=x.devbox)==null?void 0:w.lastStatus,x.devbox)}).map(x=>x.id)),[s==null?void 0:s.nodes]),b=a.useMemo(()=>new Set(((s==null?void 0:s.nodes)??[]).filter(x=>{var w;return is((w=x.devbox)==null?void 0:w.lastStatus)}).map(x=>x.id)),[s==null?void 0:s.nodes]),S=a.useMemo(()=>{const x=new Set(g);r&&x.add(r);for(const w of N)x.add(w);for(const w of b)x.add(w);return x},[N,r,g,b]);a.useEffect(()=>{let x=!1;const w=[...l];async function T(){try{const U=await xl(w);x||f(U)}catch{x||f(new Set)}}return T(),()=>{x=!0}},[l]),a.useEffect(()=>{j(x=>{var U;let w=!1;const T=new Set(x);for(const B of x){const K=s==null?void 0:s.nodes.find(D=>D.id===B);(K==null?void 0:K.status)!=="online"&&(!((U=K==null?void 0:K.devbox)!=null&&U.lastStatus)||is(K.devbox.lastStatus))||(T.delete(B),w=!0)}return w?T:x})},[s==null?void 0:s.nodes]);const p=a.useCallback(async x=>{const w=s==null?void 0:s.nodes.find(T=>T.id===x);if(w){i(x),j(T=>new Set(T).add(x));try{await ba(x),oe.success(`Start requested for ${w.name}`),t()}catch(T){j(U=>{const B=new Set(U);return B.delete(x),B}),oe.error(T instanceof Error?T.message:"Failed to start DevBox")}finally{i(null)}}},[s==null?void 0:s.nodes,t]);return{devBoxDialog:e.jsx(ml,{node:h,open:n!==null,startInProgress:h?S.has(h.id):!1,onOpenChange:x=>{x||o(null)},onRefresh:t}),devBoxNodeIds:l,devBoxStartNodeId:r,devBoxStartNodeIds:u,devBoxStartingNodeIds:S,openDevBox:o,startDevBox:p}}function fl(s){const[t,n]=a.useState(null),o=a.useCallback(i=>{s&&n(i)},[s]);return{nodeSettingsDialog:e.jsx(xr,{open:t!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:t??void 0,showTrigger:!1}),openNodeSettings:o}}function pl({activeTaskId:s,fetchActiveTask:t,setPendingMessages:n,setTask:o,setTasks:r}){const i=a.useCallback((N,f)=>{o(h=>h&&h.id===N?{...h,queuedMessages:f}:h),r(h=>h.map(l=>l.id===N?{...l,queuedMessages:f}:l))},[o,r]),g=a.useCallback(async N=>{if(!s)return!1;const f=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`;n(h=>[...h,{id:f,content:N,timestamp:new Date().toISOString()}]);try{const h=await hr(s,N);return h.queued&&(n(l=>l.filter(u=>u.id!==f)),h.queuedMessages&&i(s,h.queuedMessages)),t(),!0}catch(h){return n(l=>l.filter(u=>u.id!==f)),oe.error(h instanceof Error?h.message:"Failed to send message"),!1}},[s,t,n,i]);return{cancelQueuedMessage:a.useCallback(async N=>{if(s)try{const f=await fr(s,N);i(s,f.queuedMessages),t()}catch(f){oe.error(f instanceof Error?f.message:"Failed to cancel queued message")}},[s,t,i]),queueFollowUpMessage:g}}function gl(){var Ct,_t,Et,Dt,Tt,Mt;const{id:s}=pr(),t=gr(),n=br(),o=vr(),{cluster:r,systemInfo:i,events:g,sseConnected:j,subscribe:N,refresh:f,loading:h,error:l}=jr(),u=a.useMemo(()=>Nr(t.state),[t.state]),[b,S]=a.useState(null),[p,M]=a.useState("active"),[x,w]=a.useState("all"),[T,U]=a.useState("all"),[B,K]=a.useState("all"),[D,F]=a.useState(""),P=a.useDeferredValue(D),{desktopTasksOpen:E,mobileTasksPanelOpen:A,mobileTasksPanelRef:_,operationsOpen:Q,operationsPanelRef:V,setMobileTasksPanelOpen:G,setOperationsOpen:ie,toggleTasksPanel:ae}=sl(),[ee,J]=a.useState(()=>!!(u!=null&&u.draftNewTask)),[H,W]=a.useState(()=>(u==null?void 0:u.createMode)??"chat"),[Y,de]=a.useState(()=>u!=null&&u.draftNewTask?{route:u.returnRoute??"/",taskId:u.returnTaskId??null}:null),[m,$]=a.useState(!1),[y,X]=a.useState("transcript"),[c,L]=a.useState("all"),[z,re]=a.useState(!1),[v,R]=a.useState(null),[te,ge]=a.useState([]),[Ce,be]=a.useState([]),[Ke,$e]=a.useState(!1),[se,ce]=a.useState(null),[he,k]=a.useState(new Set),[Ne,Z]=a.useState(!1),[Ae,Fe]=a.useState(!1),[cs,Re]=a.useState(null),Ue=a.useRef(null),Le=a.useRef(null),_e=((Ct=r==null?void 0:r.self)==null?void 0:Ct.role)==="leader",fe=(_t=r==null?void 0:r.self)==null?void 0:_t.id;ol({cluster:r,subscribe:N});const{nodeSettingsDialog:Qe,openNodeSettings:es}=fl(_e),{devBoxDialog:_s,devBoxNodeIds:Es,devBoxStartNodeId:Ee,devBoxStartNodeIds:ve,devBoxStartingNodeIds:Be,openDevBox:ss,startDevBox:vt}=hl({cluster:r,refresh:f}),{fetchTasks:Ie,setTasks:jt,tasks:We,tasksError:qa,tasksLoading:Ds}=nl({isLeader:_e,selfId:fe,sseConnected:j,subscribe:N}),je=a.useMemo(()=>[...We].sort((d,C)=>C.updatedAt-d.updatedAt),[We]),Ha=a.useMemo(()=>{const d=new Map;for(const C of(r==null?void 0:r.nodes)??[]){const q=Io(je,C.id);q>0&&d.set(C.id,q)}return d},[r==null?void 0:r.nodes,je]),Ve=a.useMemo(()=>je.filter(d=>!wr(d,r==null?void 0:r.nodes,r==null?void 0:r.self)||!yr(d,p)||x!=="all"&&d.agent!==x||!kr(d,B)||T==="unassigned"&&d.assignedTo||T!=="all"&&T!=="unassigned"&&Sr(d.assignedTo,r==null?void 0:r.nodes,d.assignedNodeName)!==T?!1:P.trim()?Cr(d,P):!0),[je,r==null?void 0:r.nodes,r==null?void 0:r.self,p,x,B,T,P]);a.useEffect(()=>{k(d=>{const C=Vo(d,Ve.map(q=>q.id));return C.size===d.size?d:C})},[Ve]),a.useEffect(()=>{_e||k(new Set)},[_e]);const Ka=a.useMemo(()=>["all",...Array.from(new Set(je.map(d=>d.agent))).sort()],[je]),Wa=a.useMemo(()=>{const C=Array.from(new Set(je.map(q=>q.assignedTo).filter(q=>!!q))).map(q=>{const pe=je.find(le=>le.assignedTo===q);return(r==null?void 0:r.nodes.find(le=>le.id===q))??{id:q,name:la(q,r==null?void 0:r.nodes,pe==null?void 0:pe.assignedNodeName)}}).sort((q,pe)=>q.name.localeCompare(pe.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...C.map(q=>({value:q.name.toLowerCase(),label:q.name}))]},[je,r==null?void 0:r.nodes]),Nt=a.useMemo(()=>{const d=new Map;for(const C of(r==null?void 0:r.nodes)??[])d.set(C.id,C.name);for(const C of je)C.assignedTo&&C.assignedNodeName&&!d.has(C.assignedTo)&&d.set(C.assignedTo,C.assignedNodeName);return d},[r==null?void 0:r.nodes,je]),Ga=a.useMemo(()=>{const d=new Map;for(const C of(r==null?void 0:r.nodes)??[])d.set(C.id,C.status);return r!=null&&r.self&&d.set(r.self.id,r.self.status),d},[r]),wt=a.useMemo(()=>{const d=new Map;for(const C of(r==null?void 0:r.nodes)??[])C.status!=="offline"&&d.set(C.id,C);return r!=null&&r.self&&r.self.status!=="offline"&&d.set(r.self.id,r.self),Array.from(d.values())},[r]),Qa=((Et=r==null?void 0:r.self)==null?void 0:Et.id)??((Dt=wt[0])==null?void 0:Dt.id)??null,Ts=a.useMemo(()=>["all",...Array.from(new Set(g.map(d=>d.type))).sort()],[g]),Ja=a.useMemo(()=>c==="all"?g:g.filter(d=>d.type===c),[g,c]),Ya=Ve.length>0&&Ve.every(d=>he.has(d.id)),Xa=Ve.some(d=>he.has(d.id)),Za=qo(Ve,he);a.useEffect(()=>{u!=null&&u.draftNewTask&&(J(!0),de({route:u.returnRoute??"/",taskId:u.returnTaskId??null}))},[u]),a.useEffect(()=>{c!=="all"&&!Ts.includes(c)&&L("all")},[c,Ts]),a.useEffect(()=>{Vt(s,ee)&&!b&&je[0]&&S(je[0].id)},[s,ee,b,je]),a.useEffect(()=>{var d;Vt(s,ee)&&(b&&We.some(C=>C.id===b)||S(((d=je[0])==null?void 0:d.id)??null))},[s,ee,b,je,We]);const xe=Fo({routeTaskId:s,creatingTask:ee,internalSelectedTaskId:b,sortedTaskIds:je.map(d=>d.id)}),ts=a.useMemo(()=>We.find(d=>d.id===xe)??null,[We,xe]);a.useEffect(()=>{Le.current=xe??null},[xe]);const fs=a.useCallback(()=>{R(null),ge([]),be([]),ce(null)},[]),Oe=a.useCallback(async()=>{const d=xe;if(d)try{const C=await _r(d);if(Le.current!==d)return;R(C),ce(null)}catch(C){if(Le.current!==d)return;R(null),ge([]),be([]),ce(C instanceof Error?C.message:"Failed to load task")}finally{Le.current===d&&$e(!1)}},[xe]),ps=a.useCallback(async()=>{const d=xe;if(d)try{const C=await ga(d);if(Le.current!==d)return;ge(q=>ya(q,C.logs)),be(q=>ka(q,C.logs))}catch{}},[xe]);a.useEffect(()=>{if(!xe){R(null),ge([]),be([]),ce(null),$e(!1);return}X("transcript"),R(ts),ge([]),be([]),ce(null),$e(!0),Oe(),ps()},[xe,ps,Oe]),a.useEffect(()=>{var C;if(!xe||ee||Ds||We.some(q=>q.id===xe))return;const d=((C=je[0])==null?void 0:C.id)??null;S(d),fs(),a.startTransition(()=>{n(d?`/tasks/${d}`:"/",{state:null})})},[xe,fs,ee,n,je,We,Ds]),a.useEffect(()=>{ts&&R(d=>!d||d.id!==ts.id?d:{...d,...ts})},[ts]),a.useEffect(()=>{if(xe)return N("task",d=>{const C=d.data.taskId;if(!(typeof C!="string"||C!==xe)){if(d.type==="task.output"){const q=d.data.event;if(q){ge(le=>Vr(le,q));const pe=zt(q);pe&&be(le=>qr(le,pe))}}d.type==="task.updated"&&Oe(),d.type==="task.status"&&(Oe(),ps())}})},[N,xe,Oe,ps]),a.useEffect(()=>{var d;y==="transcript"&&((d=Ue.current)==null||d.scrollIntoView({behavior:"smooth"}))},[te,Ce,y]);const ne=v??ts,en=ne!=null&&ne.assignedTo?(r==null?void 0:r.nodes.find(d=>d.id===ne.assignedTo))??null:null,Ms=Ce.length>0,sn=ne?Er.has(ne.agent):!1,As=(ne==null?void 0:ne.status)==="running",tn=ne?ks.has(ne.status):!1,an=ne?ks.has(ne.status)||Dr.has(ne.status):!1,nn=!!(ne&&_e&&ne.status==="failed"),Ls=a.useMemo(()=>Qi(ne,r,Ms,!!As),[ne,r,Ms,As]),Bs=a.useMemo(()=>Hr([...te,...Ce.map(d=>Os(d.content,d.timestamp))]),[te,Ce]),gs=a.useMemo(()=>{if(!ne||ne.conversationKind==="nativeSession")return null;const d=Kr(ne);if(d.length>0)return Os(d,new Date(ne.createdAt).toISOString());if(Bs.length>0)return null;const C=Wr(ne.description||ne.title);return C.length>0?Os(C,new Date(ne.createdAt).toISOString()):null},[ne,Bs]),Ps=a.useMemo(()=>gs?zt(gs):null,[gs]),rn=a.useMemo(()=>Ps?Gr(te,Ps):!1,[te,Ps]),$s=a.useCallback((d="chat")=>{const C={route:s?`/tasks/${s}`:"/",taskId:xe};de(C),W(d),J(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:C.route,returnTaskId:C.taskId,createMode:d}})})},[s,xe,n]),on=a.useCallback(()=>{var C;const d=(Y==null?void 0:Y.taskId)??((C=je[0])==null?void 0:C.id)??null;J(!1),de(null),S(d),a.startTransition(()=>{n((Y==null?void 0:Y.route)??"/",{state:null})})},[Y,je,n]),yt=a.useCallback(d=>{J(!1),de(null),S(d),a.startTransition(()=>{n(`/tasks/${d}`,{state:null})})},[n]),ln=a.useCallback(d=>{Le.current=d.id,J(!1),de(null),jt(C=>zo(C,d)),R(d),ge([]),be([]),ce(null),$e(!1),X("transcript"),S(d.id),ll({task:d,getActiveTaskId:()=>Le.current,setLogs:ge,setPendingMessages:be}),Ie(),a.startTransition(()=>{n(`/tasks/${d.id}`,{state:null})})},[Ie,n]),{cancelQueuedMessage:dn,queueFollowUpMessage:bs}=pl({activeTaskId:xe,fetchActiveTask:Oe,setPendingMessages:be,setTask:R,setTasks:jt}),cn=a.useCallback(d=>{bs(d)},[bs]),un=a.useCallback(d=>bs(d),[bs]),mn=a.useCallback(async()=>{if(ne)try{await Tr(ne.id),Oe(),Ie()}catch(d){oe.error(d instanceof Error?d.message:"Failed to cancel task")}},[ne,Oe,Ie]),{handleShareTask:xn,handleStopShareTask:hn}=Xi(ne,Oe,Ie),fn=a.useCallback(async()=>{if(ne)try{await Mr(ne.id),Oe(),Ie()}catch(d){oe.error(d instanceof Error?d.message:"Failed to retry task")}},[ne,Oe,Ie]),vs=a.useCallback((d,C=!1)=>{const q=Ho(Ve,d);return S(q),(C||!q)&&fs(),a.startTransition(()=>{n(q?`/tasks/${q}`:"/",{state:null})}),q},[fs,Ve,n]),pn=a.useCallback((d,C)=>{k(q=>{const pe=new Set(q);return C?pe.add(d):pe.delete(d),pe})},[]),gn=a.useCallback(d=>{if(!d){k(new Set);return}k(new Set(Ve.map(C=>C.id)))},[Ve]),bn=a.useCallback(async()=>{const d=Array.from(he);if(d.length!==0)try{const{results:C}=await Ar(d),q=C.filter(le=>!le.ok),pe=C.filter(le=>le.ok).map(le=>le.id);xe&&pe.includes(xe)&&vs(pe),q.length>0?oe.error(`Failed to archive ${q.length} task(s): ${q.map(le=>le.error??le.id).join(", ")}`):oe.success(`Archived ${pe.length} task(s)`),k(new Set(q.map(le=>le.id))),Ie()}catch(C){oe.error(C instanceof Error?C.message:"Failed to archive tasks")}},[xe,Ie,vs,he]),vn=a.useCallback(async()=>{const d=Array.from(he);if(d.length!==0)try{const{results:C}=await Lr(d),q=C.filter(le=>!le.ok),pe=C.filter(le=>le.ok).map(le=>le.id);xe&&pe.includes(xe)&&vs(pe,!0),q.length>0?oe.error(`Failed to delete ${q.length} task(s): ${q.map(le=>le.error??le.id).join(", ")}`):oe.success(`Deleted ${pe.length} task(s)`),k(new Set(q.map(le=>le.id))),Ie()}catch(C){oe.error(C instanceof Error?C.message:"Failed to delete tasks")}},[xe,Ie,vs,he]),jn=a.useCallback(async()=>{Z(!0);try{await Br(),f()}catch(d){oe.error(d instanceof Error?d.message:"Failed to promote node")}finally{Z(!1)}},[f]),Nn=a.useCallback(async()=>{Fe(!0);try{await Pr(),oe.success("This node left the remote cluster and is leading itself again."),Ie(),Oe(),f()}catch(d){oe.error(d instanceof Error?d.message:"Failed to leave cluster")}finally{Fe(!1)}},[Oe,Ie,f]),wn=a.useCallback(async d=>{var At;const C=!pt(d),q=d.id===((At=r==null?void 0:r.self)==null?void 0:At.id),pe=q?(i==null?void 0:i.transportType)??d.transportType:d.transportType,le=q&&!C&&ds(pe);Re(d.id);try{le?await $r("direct"):await Rr(d.id,C),oe.success(C?`Enabled remote access on ${d.name}`:`Disabled remote access on ${d.name}`),f()}catch(Lt){oe.error(Lt instanceof Error?Lt.message:"Failed to update remote access")}finally{Re(null)}},[(Tt=r==null?void 0:r.self)==null?void 0:Tt.id,f,i==null?void 0:i.transportType]),kt={toolbarTasks:Ve,activeTaskId:xe,tasksLoading:Ds,tasksError:qa,isLeader:_e,scope:p,agentFilter:x,nodeFilter:T,taskKindFilter:B,agentOptions:Ka,nodeOptions:Wa,nodeNameById:Nt,nodeStatusById:Ga,leaderNodeId:((Mt=r==null?void 0:r.leader)==null?void 0:Mt.id)??null,searchQuery:D,devBoxNodeIds:Es,devBoxStartNodeIds:ve,devBoxStartingNodeIds:Be,selectedTaskIds:he,allVisibleTasksSelected:Ya,someVisibleTasksSelected:Xa,canBatchArchive:Za,onSearchChange:F,onScopeChange:M,onAgentFilterChange:w,onNodeFilterChange:U,onTaskKindFilterChange:K,onToggleTaskSelected:pn,onToggleAllVisibleTasks:gn,onBatchArchive:bn,onBatchDelete:vn,onCreateTask:$s,onOpenNodeSettings:_e?es:void 0,onOpenDevBox:_e?ss:void 0,onStartDevBox:_e?vt:void 0,onSelectTask:yt,onClose:ae},St={cluster:r,systemInfo:i,nodeNameById:Nt,nodeBlockingTaskCounts:Ha,eventTypeFilter:c,onEventTypeFilterChange:L,eventTypeOptions:Ts,filteredEvents:Ja,sseConnected:j,clusterLoading:h,clusterError:l,promotePending:Ne,onPromote:jn,onAddNode:()=>$(!0),leavePending:Ae,onLeaveCluster:Nn,onToggleNodeDevTunnel:wn,devTunnelNodeId:cs,devBoxStartNodeId:Ee,devBoxStartingNodeIds:Be,onOpenNodeSettings:_e?es:void 0,onOpenDevBox:_e?ss:void 0,onStartDevBox:_e?vt:void 0,onClose:()=>ie(!1)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsx("div",{className:I("hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",E?"lg:mr-2 lg:w-[24rem]":"lg:w-0 lg:overflow-hidden"),children:E&&e.jsx(ea,{...kt})}),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:e.jsx(Mi,{onToggleTasks:ae,desktopTasksOpen:E,mobileTasksPanelOpen:A,operationsOpen:Q,onToggleOperations:()=>ie(d=>!d),cluster:r,sseConnected:j,activeTab:y,setActiveTab:X,creatingTask:ee,createMode:H,activeTask:ne,assignedNode:en,taskLoading:Ke,taskError:se,displayEvents:Bs,initialPromptAlreadyInLogs:rn,initialPrompt:gs,supportsFollowUp:sn,taskUnavailable:Ls.taskUnavailable,chatDisabled:Ls.chatDisabled,chatDisabledReason:Ls.chatDisabledReason,questionBypassEnabled:z,isRunning:!!As,isStarting:tn,hasPendingFollowUp:Ms,canCancel:!!an,canRetry:!!nn,onRetry:fn,onCancel:mn,onShareTask:xn,onStopShareTask:hn,onStartCreateTask:$s,onCancelCreateTask:on,onCreateTask:ln,onSendMessage:cn,onCancelQueuedMessage:dn,onQuestionBypassChange:re,onSubmitQuestionResponse:un,messagesEndRef:Ue})}),(o==null?void 0:o.terminalOpen)&&e.jsx(Ui,{nodes:wt,defaultNodeId:Qa,onClose:()=>o==null?void 0:o.setTerminalOpen(!1)})]}),e.jsx("div",{className:I("hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",Q?"xl:ml-2 xl:w-[26rem]":"xl:w-0 xl:overflow-hidden"),children:Q&&e.jsx(Xt,{...St})})]}),Q&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:()=>ie(!1),className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:V,className:"fixed inset-y-0 right-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:e.jsx(Xt,{...St})})]}),A&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:()=>G(!1),className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:_,className:"fixed inset-y-0 left-0 z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:e.jsx(ea,{...kt,onCreateTask:d=>{G(!1),$s(d)},onSelectTask:d=>{G(!1),yt(d)},onClose:()=>G(!1)})})]}),e.jsx(Bi,{open:m,onOpenChange:$,onAdded:f}),Qe,_s]})}const wl=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:gl},Symbol.toStringTag,{value:"Module"}));export{wl as D,Ys as G};