meshy-node 0.9.9 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dashboard/assets/{DashboardPage-DbD4Z2U0.js → DashboardPage-DL4PakzK.js} +3 -3
- package/dashboard/assets/{DashboardShared-1UhBYL1-.js → DashboardShared-DfyXgvZj.js} +1 -1
- package/dashboard/assets/{DiffTab-BygUE807.js → DiffTab-3q3jwsm4.js} +1 -1
- package/dashboard/assets/{FilesTab-C67Dnkts.js → FilesTab-jB5PuAMB.js} +1 -1
- package/dashboard/assets/{MarkdownPreviewFrame-CH3rgET1.js → MarkdownPreviewFrame-B1baNbJd.js} +1 -1
- package/dashboard/assets/{PreviewTab-C5m4cFxf.js → PreviewTab-5-N4l7V3.js} +1 -1
- package/dashboard/assets/{SharedConversationPage-CtQLabVf.js → SharedConversationPage-D8TaynWN.js} +2 -2
- package/dashboard/assets/{file-Ef280xPz.js → file-BO3_w-is.js} +1 -1
- package/dashboard/assets/index-C8zHV8VY.js +341 -0
- package/dashboard/assets/index-Dsqqe-oH.css +1 -0
- package/dashboard/index.html +2 -2
- package/main.cjs +1 -0
- package/package.json +1 -1
- package/runtime-metadata.json +4 -4
- package/dashboard/assets/index-C7-ljTCx.js +0 -341
- package/dashboard/assets/index-CcOCgrkm.css +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-
|
|
2
|
-
import{c as he,r as a,a as os,f as Na,m as ka,j as e,X as tt,Q as $s,B as Z,L as ue,S as Sa,b as oo,d as P,e as io,g as lo,h as co,I as et,P as uo,C as Ht,i as mo,k as Ca,F as xo,l as Pt,n as He,o as xe,D as qt,p as ho,q as po,t as de,s as ke,u as Se,v as Be,w as Ce,x as Ta,y as st,T as fo,z as go,A as Tn,E as bo,G as Lt,H as It,J as Yt,K as _a,M as Ea,N as _t,O as Js,R as vo,U as bt,V as Os,W as jo,Y as en,Z as Da,_ as wo,$ as Fe,a0 as yo,a1 as ot,a2 as is,a3 as ls,a4 as ds,a5 as cs,a6 as us,a7 as ms,a8 as xs,a9 as hs,aa as tn,ab as No,ac as sn,ad as Aa,ae as ko,af as _n,ag as En,ah as Ds,ai as So,aj as Co,ak as To,al as _o,am as Eo,an as vs,ao as Do,ap as Ma,aq as Ao,ar as Mo,as as Po,at as Pa,au as nn,av as La,aw as Lo,ax as ps,ay as Io,az as Dn,aA as an,aB as Bo,aC as rn,aD as Ro,aE as $o,aF as Oo,aG as Ia,aH as Kt,aI as Fo,aJ as Fs,aK as Ba,aL as zo,aM as Uo,aN as Vo,aO as Ho,aP as An,aQ as qo,aR as Ko,aS as As,aT as Wo,aU as Mn,aV as Go,aW as Yo,aX as Qo,aY as Pn,aZ as Zo,a_ as Xo,a$ as zs,b0 as Jo,b1 as ei,b2 as Ln,b3 as Ra,b4 as ti,b5 as si,b6 as ni,b7 as ai,b8 as ri,b9 as oi,ba as ii,bb as li,bc as di,bd as ci,be as ui,bf as mi,bg as xi,bh as hi,bi as pi,bj as fi,bk as gi,bl as bi,bm as vi,bn as ji,bo as wi,bp as yi,bq as Ni,br as ki,bs as Si,bt as Ci,bu as Ti,bv as _i,bw as Ei,bx as Di,by as Ai,bz as Mi,bA as Pi}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-jB5PuAMB.js","assets/index-C8zHV8VY.js","assets/index-Dsqqe-oH.css","assets/MarkdownPreviewFrame-B1baNbJd.js","assets/DashboardShared-DfyXgvZj.js","assets/file-BO3_w-is.js","assets/PreviewTab-5-N4l7V3.js","assets/DiffTab-3q3jwsm4.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as he,r as a,a as os,f as Na,m as ka,j as e,X as tt,Q as $s,B as Z,L as ue,S as Sa,b as oo,d as P,e as io,g as lo,h as co,I as et,P as uo,C as Ht,i as mo,k as Ca,F as xo,l as Pt,n as He,o as xe,D as qt,p as ho,q as po,t as de,s as ke,u as Se,v as Be,w as Ce,x as Ta,y as st,T as fo,z as go,A as Tn,E as bo,G as Lt,H as It,J as Yt,K as _a,M as Ea,N as _t,O as Js,R as vo,U as bt,V as Os,W as jo,Y as en,Z as Da,_ as wo,$ as Fe,a0 as yo,a1 as ot,a2 as is,a3 as ls,a4 as ds,a5 as cs,a6 as us,a7 as ms,a8 as xs,a9 as hs,aa as tn,ab as No,ac as sn,ad as Aa,ae as ko,af as _n,ag as En,ah as Ds,ai as So,aj as Co,ak as To,al as _o,am as Eo,an as vs,ao as Do,ap as Ma,aq as Ao,ar as Mo,as as Po,at as Pa,au as nn,av as La,aw as Lo,ax as ps,ay as Io,az as Dn,aA as an,aB as Bo,aC as rn,aD as Ro,aE as $o,aF as Oo,aG as Ia,aH as Kt,aI as Fo,aJ as Fs,aK as Ba,aL as zo,aM as Uo,aN as Vo,aO as Ho,aP as An,aQ as qo,aR as Ko,aS as As,aT as Wo,aU as Mn,aV as Go,aW as Yo,aX as Qo,aY as Pn,aZ as Zo,a_ as Xo,a$ as zs,b0 as Jo,b1 as ei,b2 as Ln,b3 as Ra,b4 as ti,b5 as si,b6 as ni,b7 as ai,b8 as ri,b9 as oi,ba as ii,bb as li,bc as di,bd as ci,be as ui,bf as mi,bg as xi,bh as hi,bi as pi,bj as fi,bk as gi,bl as bi,bm as vi,bn as ji,bo as wi,bp as yi,bq as Ni,br as ki,bs as Si,bt as Ci,bu as Ti,bv as _i,bw as Ei,bx as Di,by as Ai,bz as Mi,bA as Pi}from"./index-C8zHV8VY.js";import{r as In,e as Li,b as $a,I as Oa,A as on,g as Fa,a as Ii,c as Bi,t as Ri,d as Bn,f as Rn,h as $i,i as Oi,C as $n,T as Ms,D as Tt,j as Je,M as Us,L as Fi,m as za,k as Vs,l as zi,n as On,o as Ui,p as Vi,q as Ps,s as Hi,u as qi,v as Ki}from"./DashboardShared-DfyXgvZj.js";import{E as Wi,M as Gi}from"./MarkdownPreviewFrame-B1baNbJd.js";import{P as js,D as ts,g as Yi,a as Qi,b as Zi}from"./PreviewTab-5-N4l7V3.js";/**
|
|
3
3
|
* @license lucide-react v1.7.0 - ISC
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the ISC license.
|
|
@@ -151,4 +151,4 @@ import{c as he,r as a,a as os,f as Na,m as ka,j as e,X as tt,Q as $s,B as Z,L as
|
|
|
151
151
|
* See the LICENSE file in the root directory of this source tree.
|
|
152
152
|
*/const zl=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["line",{x1:"21",x2:"16.65",y1:"21",y2:"16.65",key:"13gj7c"}],["line",{x1:"8",x2:"14",y1:"11",y2:"11",key:"durymu"}]],Ul=he("zoom-out",zl),Vl=new Set(["assigned","running"]);function Hl(t,s){return t.reduce((n,r)=>r.assignedTo===s&&Vl.has(r.status)?n+1:n,0)}function Rt(t){return(t==null?void 0:t.toLowerCase())==="devtunnel"}function ql(t){return t?Rt(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function dn(t,s){return Rt(s??t.transportType)||!!t.devtunnelEndpoint}function Ka(t,s){return!Rt(s??t.transportType)}function Wa(t,s){const n=s??t.transportType;return Rt(n)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":ql(n)}function Un(t,s){return!t&&!s}function Kl({routeTaskId:t,creatingTask:s,internalSelectedTaskId:n,sortedTaskIds:r}){return t||(s?null:r[0]??n??null)}function Wl({activeTaskId:t,routeTaskId:s,creatingTask:n,tasksLoading:r,loadedTaskIds:o}){return!t||s||n||r?!1:!o.includes(t)}function Gl(t,s){return[s,...t.filter(n=>n.id!==s.id)]}function Ga(t,s){const n=t.findIndex(r=>r.id===s.id);return n===-1?[...t,s]:t.map((r,o)=>o===n?s:r)}const Yl=new Set(["completed","failed","cancelled","archived"]);function Ql(t,s){const n=new Set(s);return new Set(Array.from(t).filter(r=>n.has(r)))}function Zl(t,s){const n=new Set(s);if(n.size===0)return!1;const r=t.filter(o=>n.has(o.id));return r.length===n.size&&r.every(o=>Yl.has(o.status))}function Xl(t,s){var r;const n=new Set(s);return((r=t.find(o=>!n.has(o.id)))==null?void 0:r.id)??null}function Ya(){const[t,s]=a.useState([]),[n,r]=a.useState(null),o=a.useRef(null),i=a.useCallback(()=>{var y;(y=o.current)==null||y.click()},[]),d=a.useCallback(async y=>{const g=Array.from(y.target.files??[]);if(g.length!==0)try{const l=await In(g);s(N=>[...N,...l]),r(null)}catch(l){r(l instanceof Error?l.message:"Failed to attach image")}finally{y.target.value=""}},[]),c=a.useCallback(async y=>{const g=Li(y.clipboardData);if(g.length!==0){y.preventDefault();try{const l=await In(g);s(N=>[...N,...l]),r(null)}catch(l){r(l instanceof Error?l.message:"Failed to attach image")}}},[]),f=a.useCallback(y=>{s(g=>g.filter((l,N)=>N!==y))},[]),h=a.useCallback(()=>{s([]),r(null)},[]);return{images:t,error:n,fileInputRef:o,pickImages:i,handleFileChange:d,handlePaste:c,removeImage:f,clearImages:h}}function Jl(t){const s=t.map(o=>({...o,displayValue:ed(o)})),n=s.findIndex(o=>o.label.toLowerCase()==="working dir"),r=n>=0?n:0;return{primary:s[r],secondary:s.filter((o,i)=>i!==r)}}function ed(t){return t.label.toLowerCase()==="agent"?Fa(t.value):t.value}function Vn(t){switch(t.toLowerCase()){case"branch":return fs;case"node":return Sa;case"working dir":default:return ws}}function td({disabled:t=!1,running:s=!1,canStop:n=!1,hasContent:r=!1}){return s&&!r?{primaryAction:"stop",primaryDisabled:t||!n}:{primaryAction:"send",primaryDisabled:t||!r}}function sd({contentLength:t,disabled:s=!1}){return t>0&&!s}function nd({onSend:t,disabled:s,disabledReason:n="Chat is waiting on the agent.",placeholder:r="Send a follow-up message...",contextItems:o=[],running:i=!1,onStop:d,quickChats:c=[]}){const[f,h]=a.useState(""),[y,g]=a.useState(0),[l,N]=a.useState(0),C=a.useRef(null),{images:v,error:A,fileInputRef:p,pickImages:S,handleFileChange:b,handlePaste:j,removeImage:w,clearImages:T}=Ya(),D=a.useCallback(()=>{C.current&&(C.current.style.height="auto")},[]),U=a.useCallback(()=>{C.current&&(C.current.style.height="auto",C.current.style.height=`${Math.min(C.current.scrollHeight,220)}px`)},[]);a.useEffect(()=>{g(0)},[f,c]);const E=a.useCallback(L=>{h(L.prompt);const K=()=>{var _;(_=C.current)==null||_.focus(),U()};typeof requestAnimationFrame=="function"?requestAnimationFrame(K):K()},[U]),F=a.useCallback(()=>{const L=os(f,c,y);if(L){E(L);return}const K=$a(f,v);sd({contentLength:K.length,disabled:s})&&(N(_=>_+1),t(K),h(""),T(),D())},[f,v,s,t,T,D,c,y,E]),B=a.useCallback(L=>{const K=Na(f,c);if(K.length>0&&(L.key==="ArrowDown"||L.key==="ArrowUp")){L.preventDefault(),g(_=>ka(_,K.length,L.key==="ArrowDown"?1:-1));return}if(L.key==="Enter"&&!L.shiftKey){L.preventDefault();const _=os(f,c,y);_?E(_):F()}},[E,F,c,y,f]),Q=f.trim().length>0||v.length>0,V=td({disabled:s,running:i,canStop:i&&!!d,hasContent:Q}),H=Jl(o),se=H.primary?Vn(H.primary.label):ws,ie=i?Q?"Enter queues this message for the next turn":d?"Task is running - type to queue, empty button stops task":"Task is running - type to queue a message":s?n:"Enter sends, Shift+Enter adds a line";return e.jsx("div",{"data-chat-input-shell":"true",className:"chat-input-shell animate-composer-settle w-full bg-background/35 px-2 pb-2 pt-0 sm:px-4 sm:pb-3",children:e.jsx("div",{"data-chat-input-column":"true",className:"mx-auto w-full max-w-[72rem]",children:e.jsxs("div",{"data-chat-input-card":"true",className:"chat-input-card overflow-hidden rounded-xl border border-border/65 bg-card/88 transition-[border-color,box-shadow] duration-200 focus-within:border-primary/50 focus-within:ring-2 focus-within:ring-primary/15 sm:rounded-xl",children:[e.jsx("input",{ref:p,type:"file",accept:"image/*",multiple:!0,onChange:b,className:"hidden"}),H.primary&&e.jsx("div",{"data-chat-input-primary-context":"true",className:"px-2.5 pt-1.5 sm:px-5 sm:pt-2",children:e.jsxs("div",{className:"-ml-1.5 inline-flex max-w-full items-center gap-1.5 rounded-sm bg-muted/45 px-1.5 py-0.5 shadow-[0_10px_28px_-18px_rgba(15,23,42,0.72)] sm:-ml-2 dark:shadow-[0_10px_28px_-18px_rgba(0,0,0,0.95)]",children:[e.jsx(se,{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:H.primary.value,children:H.primary.displayValue})]})}),v.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:v.map((L,K)=>e.jsxs("div",{className:"relative",children:[e.jsx(Oa,{image:L,alt:L.filename??`attachment ${K+1}`,thumbnailClassName:"h-24 w-24 border border-border/70",imageClassName:"h-full w-full"}),e.jsx("button",{type:"button",onClick:()=>w(K),className:"absolute -right-1.5 -top-1.5 flex h-5 w-5 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 ${L.filename??`image ${K+1}`}`,children:e.jsx(tt,{className:"h-3 w-3"})})]},`${L.filename??"image"}-${K}`))})}),e.jsx("div",{className:"px-2 pb-0 pt-1 sm:px-5 sm:pt-1.5",children:e.jsx("textarea",{ref:C,"data-chat-input-textarea":"true",value:f,onChange:L=>h(L.target.value),onKeyDown:B,onPaste:j,onInput:U,placeholder:r,disabled:s,rows:1,className:"min-h-[1.35rem] w-full resize-none overflow-x-hidden overflow-y-auto bg-transparent px-0 py-0 text-[11px] leading-[1.35rem] text-foreground placeholder:text-[10px] placeholder:text-muted-foreground/65 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50"})}),e.jsx($s,{query:f,quickChats:c,selectedIndex:y,onActiveIndexChange:g,onSelect:E}),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:[H.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:H.secondary.map(L=>{const K=Vn(L.label),_=L.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${L.label}: ${L.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[_?e.jsx(on,{agent:L.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(K,{"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 ${L.mono?"font-mono":""}`,children:L.displayValue})]},`${L.label}:${L.value}`)})}):e.jsx("div",{className:"min-w-0 flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Z,{type:"button",variant:"ghost",onClick:S,disabled:s,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(qs,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:ie,children:e.jsx(Z,{onClick:V.primaryAction==="stop"?d:F,disabled:V.primaryDisabled,size:"icon","data-chat-send-button":"true","aria-label":V.primaryAction==="stop"?"Stop running task":i?"Queue message":"Send message",className:"chat-send-button h-7 w-9 shrink-0 rounded-sm bg-primary/90 text-primary-foreground shadow-[0_12px_30px_-18px_hsl(var(--primary)/0.95)] transition-transform duration-150 hover:bg-primary active:scale-95",children:V.primaryAction==="stop"?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(qa,{className:`h-3.5 w-3.5 ${l>0?"animate-chat-send-flight":""}`},l)})})]})]}),A&&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:A})]})})})}var ad=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],rd=ad.reduce((t,s)=>{const n=oo(`Primitive.${s}`),r=a.forwardRef((o,i)=>{const{asChild:d,...c}=o,f=d?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(f,{...c,ref:i})});return r.displayName=`Primitive.${s}`,{...t,[s]:r}},{}),od="Label",Qa=a.forwardRef((t,s)=>e.jsx(rd.label,{...t,ref:s,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=t.onMouseDown)==null||o.call(t,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Qa.displayName=od;var Za=Qa;const id=io("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Oe=a.forwardRef(({className:t,...s},n)=>e.jsx(Za,{ref:n,className:P(id(),t),...s}));Oe.displayName=Za.displayName;function ld(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function dd(t){return t.trim()||"."}function cd(t){return new Promise(s=>window.setTimeout(s,t))}function ud(t){return!!t&&typeof t=="object"&&typeof t.createdBranch=="string"&&typeof t.currentBranch<"u"}async function md(t){let s=t;for(let n=0;n<60;n++){if(s.status==="succeeded"){if(ud(s.result))return s.result;throw new Error("Branch creation completed without branch details")}if(s.status==="failed")throw new Error(s.error||"Branch creation failed");await cd(1e3),s=await mo(s.id)}throw new Error("Timed out waiting for branch creation")}function Hn({value:t,onChange:s,project:n,assignTo:r,nodes:o,assignableNodes:i,layout:d="default",chipClassName:c,chipActiveClassName:f,chipInactiveClassName:h,labelClassName:y,triggerClassName:g}){const[l,N]=a.useState(!1),[C,v]=a.useState(null),[A,p]=a.useState(""),[S,b]=a.useState(!1),[j,w]=a.useState(!1),[T,D]=a.useState(!1),[U,E]=a.useState(null),[F,B]=a.useState(""),[Q,ee]=a.useState(""),[V,H]=a.useState(""),[se,ie]=a.useState(!1),L=a.useRef(null),K=a.useRef(0),_=a.useMemo(()=>ld(r,o,i),[r,o,i]),W=_==null?void 0:_.id,x=a.useMemo(()=>dd(n),[n]),z=a.useMemo(()=>W?`${W}
|
|
153
153
|
${x}`:"",[W,x]),m=a.useCallback(async(J=0,O=!1)=>{const te=K.current+1,le=z;if(K.current=te,!W){v(null),p("");return}E(null),O||p(""),O?w(!0):b(!0);try{const R=await lo(W,{path:x,limit:20,offset:J,allowAbsolute:!0});if(te!==K.current)return;p(le),v(ae=>O&&ae?{...R,branches:[...ae.branches,...R.branches]}:R)}catch(R){if(te!==K.current)return;E(R instanceof Error?R.message:"Failed to load branch info"),O||(v(null),p(""))}finally{te===K.current&&(b(!1),w(!1))}},[W,z,x]);a.useEffect(()=>{if(!W){K.current+=1,v(null),p(""),E(null);return}m()},[W,x,m]),a.useEffect(()=>{const J=t.trim(),O=A===z?C:null,te=O!=null&&O.available&&O.currentBranch?O.currentBranch:"";J!==te&&s(te)},[C,z,A,s,t]),a.useEffect(()=>{if(!l)return;const J=te=>{L.current&&(L.current.contains(te.target)||N(!1))},O=te=>{te.key==="Escape"&&N(!1)};return document.addEventListener("mousedown",J),document.addEventListener("keydown",O),()=>{document.removeEventListener("mousedown",J),document.removeEventListener("keydown",O)}},[l]),a.useEffect(()=>{l&&(ee(""),H(""),ie(!1))},[l,W,x]);const G=a.useCallback(async()=>{if(!W)return;const J=F.trim(),O=se?V.trim():Q.trim();if(!(!J||!O)){D(!0),E(null);try{const te=await co(W,{path:x,branchName:J,startPoint:O,limit:20,offset:0,allowAbsolute:!0}),le=await md(te);p(z),v(le),s(le.currentBranch??le.createdBranch),B(""),ee(""),H(""),ie(!1),N(!1)}catch(te){E(te instanceof Error?te.message:"Failed to create branch")}finally{D(!1)}}},[W,z,x,se,V,F,s,Q]),M=A===z?C:null,q=a.useCallback(()=>{M!=null&&M.hasMore&&m(M.branches.length,!0)},[M,m]),k=t.trim()||(M==null?void 0:M.currentBranch)||(M&&!M.available?"No git repo":"Branch"),X=se?V.trim():Q.trim(),re=!!(M!=null&&M.available&&F.trim()&&X&&!T),ce=d==="composer"?e.jsxs(Z,{type:"button",variant:"ghost",onClick:()=>N(J=>!J),title:k,"aria-label":`Branch: ${k}`,className:P(c,g,"min-w-0 max-w-full",t.trim()?f:h),children:[S&&!M?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(fs,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:P("min-w-0 truncate",y),children:k})]}):e.jsxs(Z,{type:"button",variant:"outline",onClick:()=>N(J=>!J),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:k,children:[e.jsx("span",{className:P("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:k}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:_?_.name:"Manual"})]});return e.jsxs("div",{className:P("relative inline-block",d==="composer"?"min-w-0 shrink-0":"w-full"),ref:L,children:[d==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[10px] font-medium",children:"Branch"}),ce]}):ce,l&&e.jsxs("div",{className:P("absolute z-50 mt-2 w-[240px] overflow-hidden rounded-sm border border-border/60 bg-background/95 shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",d==="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(fs,{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:M!=null&&M.repoRoot?`${M.currentBranch??k} · ${M.repoRoot}`:(M==null?void 0:M.currentBranch)??k,children:(M==null?void 0:M.currentBranch)??k}),S?e.jsx(ue,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),_?S&&!M?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..."]}):M&&!M.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(et,{value:F,onChange:J=>B(J.target.value),placeholder:"New branch name",className:"h-8 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx(Z,{type:"button",size:"sm",onClick:()=>void G(),disabled:!re,title:re?"Create branch":"Enter a name and pick a base","aria-label":"Create branch",className:"h-8 w-8 shrink-0 rounded-sm p-0",children:T?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(uo,{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"}),!se&&e.jsxs("button",{type:"button",onClick:()=>ie(!0),className:"flex items-center gap-1 rounded-sm px-1 py-0.5 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground",children:[e.jsx(Bt,{className:"h-2.5 w-2.5"}),"Manual"]})]}),se?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(et,{value:V,onChange:J=>H(J.target.value),placeholder:"upstream/release/1.0",className:"h-8 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>{ie(!1),H("")},className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel manual input","aria-label":"Cancel manual input",children:e.jsx(tt,{className:"h-3.5 w-3.5"})})]}):M!=null&&M.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-sm border border-border/40 bg-background/40",children:[M.branches.map(J=>{const O=Q===J.ref,te=J.branch==="main"||J.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>ee(J.ref),className:P("flex w-full items-center gap-2 border-b border-border/20 px-2.5 py-1.5 text-left text-[11px] last:border-b-0 hover:bg-background/60",O&&"bg-background/70"),title:J.ref,children:[e.jsx("span",{className:P("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:J.ref}),O?e.jsx(Ht,{className:"h-3 w-3 shrink-0 text-primary"}):null]},J.ref)}),M.hasMore&&e.jsxs("button",{type:"button",onClick:q,disabled:j,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:[j?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Hs,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"rounded-sm border border-dashed border-border/40 px-2.5 py-2 text-[11px] text-muted-foreground",children:"No remote branches found."})]})]})}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a specific node first."}),U&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:U})]})]})}const xd=20,hd=3,Ks="meshy-working-dir-recents-by-node";function pd(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function fd(t){const s=t.trim();return s||"."}function Ws(t){const s=[],n=new Set;for(const r of t){const o=r.trim();if(!(!o||n.has(o))&&(n.add(o),s.push(o),s.length===hd))break}return s}function gd(t,s){const n=s.trim();return Ws(n?[n,...t]:t)}function Xa(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const s={};for(const[n,r]of Object.entries(t)){if(!n||!Array.isArray(r))continue;const o=r.filter(d=>typeof d=="string"),i=Ws(o);i.length>0&&(s[n]=i)}return s}function bd(t,s,n){if(!s)return t;const r=t[s]??[],o=gd(r,n);if(o.length===0){if(!(s in t))return t;const{[s]:i,...d}=t;return d}return{...t,[s]:o}}function vd(t,s){var n;return s?((n=t[s])==null?void 0:n[0])??"":""}function Ja(t){if(!t||typeof window>"u")return"";try{const s=window.localStorage.getItem(Ks);return s?vd(Xa(JSON.parse(s)),t):""}catch{return""}}function jd(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function wd(t,s){const n=s.trim();return n?pd(n)||!t?n:`${t.replace(/[/\\]+$/,"")}/${n}`:""}function yd(t,s){return t?t.isAbsolute?t.currentPath:t.currentPath==="."||t.currentPath===""?t.rootPath||(s==null?void 0:s.workDir)||"Node root":t.currentPath:(s==null?void 0:s.workDir)??"Node root"}function bs({value:t,onChange:s,assignTo:n,nodes:r,assignableNodes:o,layout:i="default",chipClassName:d,chipActiveClassName:c,chipInactiveClassName:f,labelClassName:h,triggerClassName:y,popoverPlacement:g="bottom",popoverAlign:l="start"}){const[N,C]=a.useState(!1),[v,A]=a.useState(null),[p,S]=a.useState(!1),[b,j]=a.useState(!1),[w,T]=a.useState(null),[D,U]=a.useState(""),[E,F]=a.useState(!1),[B,Q]=a.useState({}),ee=a.useRef(null),V=a.useMemo(()=>jd(n,r,o),[n,r,o]),H=V==null?void 0:V.id,se=a.useMemo(()=>H?B[H]??[]:[],[B,H]),ie=a.useMemo(()=>t.trim()?wd(V==null?void 0:V.workDir,t):"Use node default",[t,V==null?void 0:V.workDir]);a.useEffect(()=>{if(!(typeof window>"u"))try{const k=window.localStorage.getItem(Ks);if(!k)return;const X=JSON.parse(k);Q(Xa(X))}catch{}},[]);const L=a.useCallback(k=>{H&&Q(X=>{const re=bd(X,H,k);if(re===X)return X;if(typeof window<"u")try{window.localStorage.setItem(Ks,JSON.stringify(re))}catch{}return re})},[H]),K=a.useCallback((k,X=!0)=>{const re=k.trim();s(re),X&&re&&L(re),C(!1)},[s,L]),_=a.useCallback(async(k,X=0,re=!1)=>{if(H){T(null),re?j(!0):S(!0);try{const ce=await Ca(H,{path:k,limit:xd,offset:X,directoriesOnly:!0,allowAbsolute:!0});A(J=>re&&J?{...ce,entries:[...J.entries,...ce.entries]}:ce)}catch(ce){T(ce instanceof Error?ce.message:"Failed to browse directories"),re||A(null)}finally{S(!1),j(!1)}}},[H]),W=a.useRef(t);W.current=t;const x=a.useRef(_);x.current=_,a.useEffect(()=>{if(!N)return;const k=W.current;U(k),F(!1),A(null),T(null),H&&x.current(fd(k))},[N,H]),a.useEffect(()=>{if(!N)return;const k=re=>{ee.current&&(ee.current.contains(re.target)||C(!1))},X=re=>{re.key==="Escape"&&C(!1)};return document.addEventListener("mousedown",k),document.addEventListener("keydown",X),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",X)}},[N]);const z=a.useCallback(k=>{_(k)},[_]),m=a.useCallback(()=>{v&&_(v.currentPath,v.entries.length,!0)},[v,_]),G=i==="composer"?e.jsxs(Z,{type:"button",variant:"ghost",onClick:()=>C(k=>!k),title:ie,"aria-label":`Working directory: ${ie}`,className:P(d,y,"min-w-0 max-w-full",t.trim()?c:f),children:[e.jsx(xo,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:P("min-w-0 truncate",h),children:ie})]}):e.jsxs(Z,{type:"button",variant:"outline",onClick:()=>C(k=>!k),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:ie,children:[e.jsx("span",{className:P("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:ie}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:V?V.name:"Manual"})]}),M=yd(v,V),q=!!(v!=null&&v.parentPath);return e.jsxs("div",{className:P("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":g,"data-workdir-popover-align":l,ref:ee,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[10px] font-medium",children:"Working directory"}),G]}):G,N&&e.jsxs("div",{className:P("absolute z-50 flex max-h-[min(28rem,calc(100vh-5rem))] w-[240px] flex-col overflow-hidden rounded-sm border border-border/60 bg-background/95 shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",g==="top"?"bottom-full mb-2":"top-full mt-2",i==="composer"?l==="end"?"right-0":"left-0":l==="end"?"right-0 w-auto min-w-[240px]":"left-0 right-0 w-auto min-w-[240px]"),children:[se.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(Hs,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:se.map(k=>e.jsx("button",{type:"button",onClick:()=>K(k),className:"truncate rounded-sm px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:k,children:k},k))})]}),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:()=>(v==null?void 0:v.parentPath)&&z(v.parentPath),disabled:!q||p,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-sm 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(Ua,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:M,children:M}),v&&e.jsx("button",{type:"button",onClick:()=>K(v.isAbsolute?v.currentPath:v.currentPath==="."?"":v.currentPath),className:"shrink-0 rounded-sm 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?p?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..."]}):v&&v.entries.length>0?e.jsxs(e.Fragment,{children:[v.entries.map(k=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>K(k.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 ${k.path}`,children:[e.jsx(Pt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:k.name})]}),e.jsx("button",{type:"button",onClick:()=>z(k.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 ${k.name}`,children:e.jsx(He,{className:"h-3.5 w-3.5"})})]},k.path)),v.hasMore&&e.jsxs("button",{type:"button",onClick:m,disabled:b,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:[b?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Hs,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:w??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),w&&v&&v.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:w})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:E?e.jsxs(e.Fragment,{children:[e.jsx(et,{value:D,onChange:k=>U(k.target.value),onKeyDown:k=>{k.key==="Enter"&&D.trim()?(k.preventDefault(),K(D)):k.key==="Escape"&&(k.preventDefault(),F(!1),U(t))},autoFocus:!0,placeholder:"Path (relative or absolute)",className:"h-7 flex-1 rounded-sm border-border/60 bg-background/70 font-mono text-[11px]"}),e.jsx("button",{type:"button",onClick:()=>K(D),disabled:!D.trim(),className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-foreground hover:bg-background/60 disabled:opacity-40",title:"Apply","aria-label":"Apply manual path",children:e.jsx(Ht,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{F(!1),U(t)},className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-background/60 hover:text-foreground",title:"Cancel","aria-label":"Cancel manual path",children:e.jsx(tt,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{U(t),F(!0)},className:"flex h-7 flex-1 items-center justify-between rounded-sm 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(Bt,{className:"h-3 w-3"})]})})]})]})}function er(t,s={}){const n=t.filter(r=>r.status==="online");return s.currentNodeRole!=="follower"||!s.leaderNodeId?n:n.filter(r=>r.id!==s.leaderNodeId)}function cn({isCurrent:t}){return t?e.jsx(jl,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(fl,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function Gs(t,s){return t.map(n=>{const r=!!s&&n.id===s;return e.jsx(xe,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(cn,{isCurrent:r}),e.jsx("span",{className:"truncate",children:n.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:r?"current":"remote"})]})},n.id)})}function Nd(t){var r;const s=t.sessionId.trim(),n=t.cwd.trim();return!s||!n||!t.assignTo?null:{title:t.title.trim()||((r=t.defaultTitle)==null?void 0:r.trim())||void 0,agent:t.agent,sessionId:s,cwd:n,assignTo:t.assignTo,priority:t.priority,mode:t.mode??qt}}function kd(){return fo.map(t=>e.jsx(xe,{value:t.value,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{children:t.label}),t.description&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:t.description})]})},t.value))}function Sd(t){if(!t)return"unknown time";const s=Date.parse(t);return Number.isNaN(s)?t:new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(s)}function qn(t){if(!t.updatedAt)return 0;const s=Date.parse(t.updatedAt);return Number.isNaN(s)?0:s}function Cd(t,s){return qn(s)-qn(t)||t.sessionId.localeCompare(s.sessionId)}function Td(t){const s=t.trim().replace(/[\\/]+$/,"");return s?s.split(/[\\/]+/).filter(Boolean).at(-1)??s:"Unknown project"}function _d(t){const s=new Map;for(const n of[...t].sort(Cd)){const r=s.get(n.cwd);if(r){r.push(n);continue}s.set(n.cwd,[n])}return Array.from(s.entries()).map(([n,r])=>({folderName:Td(n),cwd:n,sessions:r}))}function Ed(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function Dd({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:o,onCancel:i,className:d,footerClassName:c,submitLabel:f="Load session",cancelLabel:h="Cancel",autoFocus:y=!1}){const g=a.useMemo(()=>er(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),l=a.useMemo(()=>{var R;return n&&g.some(ae=>ae.id===n)?n:((R=g[0])==null?void 0:R.id)??""},[g,n]),[N,C]=a.useState(""),[v,A]=a.useState("codex"),[p,S]=a.useState(""),[b,j]=a.useState(""),[w,T]=a.useState(""),[D,U]=a.useState(l),[E,F]=a.useState("normal"),[B,Q]=a.useState(qt),[ee,V]=a.useState(!1),[H,se]=a.useState([]),[ie,L]=a.useState(!1),[K,_]=a.useState(null),W=a.useMemo(()=>H.find(R=>R.sessionId===p)??null,[H,p]);a.useEffect(()=>{D&&g.some(R=>R.id===D)||U(l)},[D,g,l]),a.useEffect(()=>{S(""),j(""),T("")},[v,D]),a.useEffect(()=>{let R=!1;return D?(L(!0),_(null),ho(D,{agent:v,limit:50}).then(ae=>{R||se(ae.sessions)}).catch(ae=>{R||(se([]),_(ae instanceof Error?ae.message:"Failed to load native sessions"))}).finally(()=>{R||L(!1)}),()=>{R=!0}):(se([]),_(null),L(!1),()=>{R=!0})},[v,D]),a.useEffect(()=>{W&&(j(W.sessionId),T(W.cwd))},[W]);const x=a.useCallback(async R=>{R.preventDefault();const ae=Nd({title:N,defaultTitle:W==null?void 0:W.summary,agent:v,sessionId:b,cwd:w,assignTo:D,priority:E,mode:B});if(ae){V(!0);try{const ve=await po(ae);o(ve)}catch(ve){de.error(ve instanceof Error?ve.message:"Failed to load native session")}finally{V(!1)}}},[N,W,v,b,w,D,E,B,o]),z=!!(b.trim()&&w.trim()&&D),[m,G]=a.useState(!1),[M,q]=a.useState(""),[k,X]=a.useState(()=>new Set),re=g.find(R=>R.id===D)??null,ce=!!(n&&(re==null?void 0:re.id)===n),J=a.useMemo(()=>{const R=M.trim().toLowerCase();return R?H.filter(ae=>ae.summary.toLowerCase().includes(R)||ae.sessionId.toLowerCase().includes(R)||ae.cwd.toLowerCase().includes(R)):H},[H,M]),O=a.useMemo(()=>_d(J),[J]),te=a.useCallback(R=>{X(ae=>Ed(ae,R))},[]),le="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:x,className:P("space-y-4",d),children:[e.jsxs("div",{className:"rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/50 px-3 py-2.5",children:[e.jsxs(ke,{value:D,onValueChange:U,children:[e.jsx(Se,{className:P(le),"aria-label":"Node",children:re?e.jsxs(e.Fragment,{children:[e.jsx(cn,{isCurrent:ce}),e.jsx("span",{className:"max-w-[10rem] truncate",children:re.name})]}):e.jsx(Be,{placeholder:"Node"})}),e.jsx(Ce,{children:Gs(g,n)})]}),e.jsxs(ke,{value:v,onValueChange:R=>A(R),children:[e.jsxs(Se,{className:P(le),"aria-label":"Agent",children:[e.jsx(on,{agent:v}),e.jsx("span",{children:v})]}),e.jsx(Ce,{children:Ii()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(Ta,{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(et,{value:M,onChange:R=>q(R.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(Oe,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:ie?"Loading...":`${J.length} session${J.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-sm",children:[ie&&e.jsx("div",{className:"absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden bg-primary/10",children:e.jsx("div",{className:"h-full w-1/3 animate-indeterminate-bar bg-primary/70"})}),e.jsxs("div",{className:"h-full space-y-1.5 overflow-y-auto pr-1",children:[!D&&e.jsx("div",{className:"rounded-sm border border-dashed border-border/60 bg-background/35 px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Pick a node to load its recent sessions."}),D&&!ie&&J.length===0&&e.jsx("div",{className:"rounded-sm border border-dashed border-border/60 bg-background/35 px-3 py-4 text-center text-[11px] text-muted-foreground",children:H.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),O.map(R=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>te(R.cwd),"aria-expanded":!k.has(R.cwd),className:"sticky top-0 z-[1] flex w-full items-center gap-2 border-b border-border/50 bg-background/95 px-1 py-1.5 text-left text-[10px] text-muted-foreground backdrop-blur transition-colors hover:bg-background",children:[e.jsx(st,{className:P("h-3.5 w-3.5 shrink-0 transition-transform",k.has(R.cwd)&&"-rotate-90")}),e.jsx(ws,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:R.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[R.sessions.length," session",R.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:R.cwd})]}),!k.has(R.cwd)&&R.sessions.map(ae=>{const ve=ae.sessionId===p;return e.jsxs("button",{type:"button",onClick:()=>S(ae.sessionId),className:P("flex w-full flex-col gap-1 rounded-sm border px-2.5 py-2 text-left transition-colors duration-200",ve?"border-primary/45 bg-primary/9 shadow-none":"border-border/55 bg-background/40 hover:border-border hover:bg-background/65"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:P("h-2 w-2 shrink-0 rounded-full",ve?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:ae.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:Sd(ae.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:ae.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:ae.cwd})]})]},ae.sessionId)})]},R.cwd))]})]}),K&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:K})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>G(R=>!R),className:"inline-flex h-6 items-center gap-1.5 rounded-sm px-1.5 text-[10px] font-medium uppercase tracking-[0.16em] text-muted-foreground transition-colors hover:bg-muted/45 hover:text-foreground","aria-expanded":m,children:[e.jsx("span",{className:"shrink-0",children:m?"Less options":"More options"}),e.jsx(st,{className:P("h-3.5 w-3.5 shrink-0 transition-transform",m&&"rotate-180")})]}),m&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/30 p-2.5",children:[e.jsxs("div",{className:"grid gap-2.5 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Oe,{htmlFor:"native-session-id",className:"text-[10px] font-medium text-muted-foreground",children:"Session ID"}),e.jsx(et,{id:"native-session-id",type:"text",value:b,onChange:R=>{S(""),j(R.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:y,className:"h-7 rounded-sm border-border/70 bg-background/70 font-mono text-[11px] shadow-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Oe,{htmlFor:"native-session-title",className:"text-[10px] font-medium text-muted-foreground",children:"Task title"}),e.jsx(et,{id:"native-session-title",type:"text",value:N,onChange:R=>C(R.target.value),placeholder:"Optional",className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none"})]})]}),e.jsx(bs,{value:w,onChange:R=>{S(""),T(R)},assignTo:D,nodes:t,assignableNodes:g}),e.jsxs("div",{className:"grid gap-2.5 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Oe,{className:"text-[10px] font-medium text-muted-foreground",children:"Mode"}),e.jsxs(ke,{value:B,onValueChange:R=>Q(R),children:[e.jsx(Se,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx(Be,{placeholder:"Select mode"})}),e.jsx(Ce,{children:kd()})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Oe,{className:"text-[10px] font-medium text-muted-foreground",children:"Priority"}),e.jsxs(ke,{value:E,onValueChange:F,children:[e.jsx(Se,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx(Be,{placeholder:"Select priority"})}),e.jsxs(Ce,{children:[e.jsx(xe,{value:"low",children:"Low"}),e.jsx(xe,{value:"normal",children:"Normal"}),e.jsx(xe,{value:"high",children:"High"}),e.jsx(xe,{value:"critical",children:"Critical"})]})]})]})]})]})]}),e.jsxs("div",{className:P("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",c),children:[i&&e.jsx(Z,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:h}),e.jsx(Z,{type:"submit",disabled:!z||ee,className:"rounded-sm px-5",children:ee?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"h-4 w-4 animate-spin"})," Loading..."]}):f})]})]})}function tr(t,s,n=!1){const r=t.trim();if(r)return r;const o=s.trim().split(`
|
|
154
|
-
`).map(i=>i.trim()).find(Boolean);return o?o.length>72?`${o.slice(0,69).trimEnd()}...`:o:n?"Image task":""}function Ad(t){var d;const s=t.title.trim(),n=tr(t.title,t.description,t.images.length>0),r=t.description.trim()||n,o=t.mode??qt,i=$a(t.description,t.images);return!n||!r||!t.agent?null:{title:n,description:r,agent:t.agent,project:t.project.trim()||null,branch:((d=t.branch)==null?void 0:d.trim())||null,payload:{initialMessage:i,mode:o,titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function Md({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,className:f,footerClassName:h,submitLabel:y="Create chat",cancelLabel:g="Cancel",autoFocus:l=!1,layout:N="default",quickChats:C=[]}){const[v,A]=a.useState(""),[p,S]=a.useState(""),[b,j]=a.useState(0),[w,T]=a.useState(Tn),[D,U]=a.useState(qt),[E,F]=a.useState((i==null?void 0:i.trim())??""),B=a.useRef(i!==void 0),[Q,ee]=a.useState(""),[V,H]=a.useState("normal"),se=a.useMemo(()=>er(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),ie=a.useMemo(()=>{var ne;return o&&se.some(we=>we.id===o)?o:n&&se.some(we=>we.id===n)?n:((ne=se[0])==null?void 0:ne.id)??""},[se,n,o]),[L,K]=a.useState(ie),[_,W]=a.useState(!1),[x,z]=a.useState(!1),{images:m,error:G,fileInputRef:M,pickImages:q,handleFileChange:k,handlePaste:X,removeImage:re}=Ya(),ce=a.useMemo(()=>se.find(ne=>ne.id===L)??null,[L,se]),J=!!(n&&(ce==null?void 0:ce.id)===n),O=Fa(w),te=Bi(D);a.useEffect(()=>{L&&se.some(ne=>ne.id===L)||K(ie)},[L,se,ie]),a.useEffect(()=>{if(B.current){B.current=!1;return}F(Ja(L)),ee("")},[L]),a.useEffect(()=>{ee("")},[E]),a.useEffect(()=>{j(0)},[p,C]);const le=a.useCallback(ne=>{S(ne.prompt)},[]),R=a.useCallback(async ne=>{ne.preventDefault();const we=os(p,C,b);if(we){le(we);return}const Pe=Ad({title:v,description:p,agent:w,project:E,branch:Q,priority:V,assignTo:L,mode:D,images:m});if(Pe){W(!0);try{const De=await bo(Pe);d(De)}catch(De){de.error(De instanceof Error?De.message:"Failed to create task")}finally{W(!1)}}},[v,p,w,E,Q,V,L,D,m,d,C,b,le]),ae=tr(v,p,m.length>0),ve=!!(ae&&w&&L&&(p.trim()||m.length>0)),Ee=a.useCallback(ne=>{var Pe;if(ne.nativeEvent.isComposing)return;const we=Na(p,C);if(we.length>0&&(ne.key==="ArrowDown"||ne.key==="ArrowUp")){ne.preventDefault(),j(De=>ka(De,we.length,ne.key==="ArrowDown"?1:-1));return}if(ne.key==="Enter"){const De=os(p,C,b);if(De&&!ne.shiftKey){ne.preventDefault(),le(De);return}}ne.key==="Enter"&&(ne.ctrlKey||ne.metaKey)&&ve&&!_&&(ne.preventDefault(),(Pe=ne.currentTarget.form)==null||Pe.requestSubmit())},[le,ve,p,C,b,_]),nt=m.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:m.map((ne,we)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Ri(ne),alt:ne.filename??`attachment ${we+1}`,className:"h-20 w-20 rounded-sm border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>re(we),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 ${ne.filename??`image ${we+1}`}`,children:e.jsx(tt,{className:"h-3.5 w-3.5"})})]},`${ne.filename??"image"}-${we}`))}),at=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[11px] font-medium",children:"Assign to"}),e.jsxs(ke,{value:L,onValueChange:K,children:[e.jsx(Se,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Be,{placeholder:"Select node"})}),e.jsx(Ce,{children:Gs(se,n)})]})]}),Ue=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[11px] font-medium",children:"Agent"}),e.jsxs(ke,{value:w,onValueChange:T,children:[e.jsx(Se,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Be,{placeholder:"Select agent"})}),e.jsx(Ce,{children:Bn()})]})]}),je=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[11px] font-medium",children:"Mode"}),e.jsxs(ke,{value:D,onValueChange:ne=>U(ne),children:[e.jsx(Se,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Be,{placeholder:"Select mode"})}),e.jsx(Ce,{children:Rn()})]})]}),it=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[11px] font-medium",children:"Priority"}),e.jsxs(ke,{value:V,onValueChange:H,children:[e.jsx(Se,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Be,{placeholder:"Select priority"})}),e.jsxs(Ce,{children:[e.jsx(xe,{value:"low",children:"Low"}),e.jsx(xe,{value:"normal",children:"Normal"}),e.jsx(xe,{value:"high",children:"High"}),e.jsx(xe,{value:"critical",children:"Critical"})]})]})]}),We=e.jsx(bs,{value:E,onChange:F,assignTo:L,nodes:t,assignableNodes:se}),Me=e.jsx(Hn,{value:Q,onChange:ee,project:E,assignTo:L,nodes:t,assignableNodes:se});return N==="composer"?e.jsxs("form",{onSubmit:R,className:P("space-y-4",f),children:[e.jsx("input",{ref:M,type:"file",accept:"image/*",multiple:!0,onChange:k,className:"hidden"}),(()=>{const ne="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",we="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",Pe="border-border/70 bg-background/55 text-foreground",De=w===Tn,lt=D===qt;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"chat-composer__card rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",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(ke,{value:L,onValueChange:K,children:[e.jsx(Se,{className:P(ne,Pe,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${(ce==null?void 0:ce.name)??"unassigned"}`,"aria-label":`Assigned node: ${(ce==null?void 0:ce.name)??"unassigned"}`,children:ce?e.jsxs(e.Fragment,{children:[e.jsx(cn,{isCurrent:J}),e.jsx("span",{className:"min-w-0 truncate",children:ce.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:J?"current":"remote"})]}):e.jsx(Be,{placeholder:"Select node"})}),e.jsx(Ce,{children:Gs(se,n)})]}),x?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(et,{id:"task-title-composer",type:"text",value:v,onChange:ye=>A(ye.target.value),onKeyDown:ye=>{(ye.key==="Enter"||ye.key==="Escape")&&(ye.preventDefault(),z(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",onClick:()=>z(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Ht,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>z(!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:ae||"Title","aria-label":ae?`Edit title: ${ae}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:ae||"Title"}),e.jsx(Bt,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:p,onChange:ye=>S(ye.target.value),onKeyDown:Ee,onPaste:X,placeholder:"Ask anything...",rows:4,autoFocus:l,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm bg-transparent px-5 pt-2 pb-2 text-xs leading-5 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsx($s,{query:p,quickChats:C,selectedIndex:b,onActiveIndexChange:j,onSelect:le}),e.jsxs("div",{className:"chat-composer__rail flex flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(Z,{type:"button",variant:"ghost",size:"icon",onClick:q,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(qs,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(ke,{value:w,onValueChange:T,children:[e.jsxs(Se,{className:P(ne,"chat-composer__icon-trigger",De?we:Pe),title:`Agent: ${O}`,"aria-label":`Agent: ${O}`,children:[e.jsx(on,{agent:w}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:O})]}),e.jsx(Ce,{children:Bn()})]}),e.jsxs(ke,{value:D,onValueChange:ye=>U(ye),children:[e.jsxs(Se,{className:P(ne,"chat-composer__icon-trigger",lt?we:Pe),title:`Mode: ${te}`,"aria-label":`Mode: ${te}`,children:[e.jsx(Pl,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:te})]}),e.jsx(Ce,{children:Rn()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(ke,{value:V,onValueChange:H,children:[e.jsx(Se,{"aria-label":`Priority: ${V}`,title:`Priority: ${V}`,className:P("h-9 w-9 justify-center gap-0 rounded-sm p-0 text-xs shadow-none [&>svg:last-child]:hidden",V==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",V==="critical"&&"text-destructive",V==="high"&&"text-amber-600 dark:text-amber-400",V==="low"&&"text-muted-foreground"),children:e.jsx(cl,{className:P("h-4 w-4",V==="critical"&&"fill-destructive/20")})}),e.jsxs(Ce,{children:[e.jsx(xe,{value:"low",children:"Low"}),e.jsx(xe,{value:"normal",children:"Normal"}),e.jsx(xe,{value:"high",children:"High"}),e.jsx(xe,{value:"critical",children:"Critical"})]})]}),c&&e.jsxs(Z,{type:"button",variant:"ghost",size:"sm",onClick:c,"aria-label":g,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(tt,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:g})]}),e.jsxs(Z,{type:"submit",size:"icon",disabled:!ve||_,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[_?e.jsx(ue,{className:"h-4 w-4 animate-spin"}):e.jsx(qa,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:_?"Creating chat":y})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const ye="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(bs,{value:E,onChange:F,assignTo:L,nodes:t,assignableNodes:se,layout:"composer",chipClassName:ne,chipActiveClassName:ye,chipInactiveClassName:ye,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(Hn,{value:Q,onChange:ee,project:E,assignTo:L,nodes:t,assignableNodes:se,layout:"composer",chipClassName:ne,chipActiveClassName:ye,chipInactiveClassName:ye,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(nt||G)&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/45 p-2.5",children:[nt,G&&e.jsx("div",{className:"text-[11px] text-destructive",children:G}),!G&&e.jsx("div",{className:"text-[11px] 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:R,className:P("space-y-4",f),children:[e.jsx("input",{ref:M,type:"file",accept:"image/*",multiple:!0,onChange:k,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{htmlFor:"task-description",className:"text-[11px] font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:p,onChange:ne=>S(ne.target.value),onKeyDown:Ee,onPaste:X,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:l,className:"flex min-h-[128px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm border border-border/70 bg-background/70 px-3 py-2 text-xs leading-5 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.jsx($s,{query:p,quickChats:C,selectedIndex:b,onActiveIndexChange:j,onSelect:le}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Z,{type:"button",variant:"outline",onClick:q,className:"rounded-sm",children:[e.jsx(qs,{className:"h-4 w-4"}),"Add images"]}),e.jsx("p",{className:"text-[11px] 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."})]}),nt,G&&e.jsx("p",{className:"text-[11px] text-destructive",children:G})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_190px_190px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{htmlFor:"task-title",className:"text-[11px] font-medium",children:"Chat title"}),e.jsx(et,{id:"task-title",type:"text",value:v,onChange:ne=>A(ne.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-8 rounded-sm border-border/70 bg-background/70"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:ae?`Will appear as: ${ae}`:"A title will be generated from the first line of the prompt."})]}),Ue,je]}),We,Me,e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[it,at]}),e.jsxs("div",{className:P("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",h),children:[c&&e.jsx(Z,{type:"button",variant:"ghost",onClick:c,className:"rounded-sm",children:g}),e.jsx(Z,{type:"submit",disabled:!ve||_,className:"rounded-sm px-5",children:_?"Creating...":y})]})]})}function Pd({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,defaultMode:f="chat",mode:h,onModeChange:y,layout:g="default",className:l,footerClassName:N,autoFocus:C=!1,quickChats:v=[]}){const[A,p]=a.useState(f),S=h!==void 0,b=S?h:A,j=w=>{S||p(w),y==null||y(w)};return e.jsxs("div",{className:P("space-y-4",l),children:[!S&&e.jsxs("div",{className:"flex h-8 items-center gap-0.5 rounded-sm border border-border/60 bg-background/45 p-0.5",children:[e.jsxs(Z,{type:"button",variant:b==="chat"?"default":"ghost",onClick:()=>j("chat"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(go,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(Z,{type:"button",variant:b==="native"?"default":"ghost",onClick:()=>j("native"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(ln,{className:"h-4 w-4"}),"Load session"]})]}),b==="chat"?e.jsx(Md,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,footerClassName:N,submitLabel:g==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:C,layout:g,quickChats:v},`${o??""}:${i??""}`):e.jsx(Dd,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:d,onCancel:c,footerClassName:N,autoFocus:C})]})}function Ld({onClick:t,running:s}){return e.jsxs(Z,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:P("absolute bottom-4 right-4 z-10 h-12 w-12 overflow-visible rounded-lg shadow-lg",s&&"animate-soft-status-pulse bg-primary/90 text-primary-foreground hover:bg-primary"),children:[e.jsx(Bt,{className:"h-4 w-4"}),s&&e.jsx("span",{"aria-hidden":"true","data-running-indicator":"true",className:"pointer-events-none absolute right-1.5 top-1.5 h-2 w-2 rounded-full bg-primary-foreground shadow-[0_0_0_2px_hsl(var(--primary))]"})]})}function Kn({children:t}){return e.jsxs("div",{className:"agent-progress-banner animate-message-receive 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:t})]})}function Id({hasVisibleTranscriptEvents:t,hasTranscriptProgress:s,inputCollapsed:n}){return{collapsedButtonRunning:s&&t&&n,showDockedProgress:s&&t&&!n,showInlineProgress:s&&!t}}const Et="72f988bf-86f1-41af-91ab-2d7cd011db47",sr=`${Et} (MSIT)`;function Bd({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:o,stopping:i=!1,shareResult:d}){return e.jsx(Lt,{open:t,onOpenChange:s,children:e.jsxs(It,{className:"max-w-md rounded-sm p-4",children:[e.jsx(Yt,{className:"sr-only",children:"Share conversation"}),e.jsx(Rd,{onOpenChange:s,onShare:n,onStopShare:r,sharing:o,stopping:i,shareResult:d})]})})}function Rd({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:o=!1,shareResult:i}){const[d,c]=a.useState((i==null?void 0:i.tenant)??Et),[f,h]=a.useState((i==null?void 0:i.scope)??"chat"),y=i!=null&&i.url?_a(i.url):null,g=r||o;return a.useEffect(()=>{c((i==null?void 0:i.tenant)??Et),h((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-sm 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($d,{value:d,onChange:c,disabled:g}),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(Wn,{active:f==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>h("chat")}),e.jsx(Wn,{active:f==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>h("filesPreview")})]})]}),y&&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:y,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void _t(y,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ea,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e.jsx(Z,{variant:"outline",onClick:()=>t(!1),disabled:g,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(Z,{variant:"outline",onClick:()=>void n(),disabled:g,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[o&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(Z,{onClick:()=>void s({tenant:d,scope:f}),disabled:g,className:"h-8 text-xs",children:[r&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function $d({value:t,onChange:s,disabled:n}){const[r,o]=a.useState(!1),[i,d]=a.useState(!1),[c,f]=a.useState(t),h=a.useRef(null);a.useEffect(()=>{f(t)},[t]),a.useEffect(()=>{if(!r)return;const g=N=>{var v;const C=N.target;C instanceof Node&&((v=h.current)!=null&&v.contains(C)||(o(!1),d(!1)))},l=N=>{N.key==="Escape"&&(o(!1),d(!1))};return document.addEventListener("mousedown",g),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",l)}},[r]);const y=g=>{const l=g.trim();l&&(s(l),f(l),d(!1),o(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:h,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&o(g=>!g),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:Od(t)}),e.jsx(st,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),r&&e.jsxs("div",{className:"absolute left-0 right-0 z-50 mt-2 overflow-hidden rounded-sm border border-border/60 bg-background/95 text-xs shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",children:[e.jsxs("button",{type:"button",onClick:()=>y(Et),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:sr}),t===Et&&e.jsx(Ht,{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:c,onChange:g=>f(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),y(c))},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:()=>y(c),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(Ht,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{f(t),d(!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(tt,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>d(!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(Bt,{className:"h-3 w-3"})]})})]})]})]})}function Od(t){return t===Et?sr:t}function Wn({active:t,title:s,description:n,onClick:r}){return e.jsxs("button",{type:"button",onClick:r,className:t?"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:s}),e.jsx("div",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:n})]})}function Fd(t){const s=t.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 s?s.length>160?`${s.slice(0,157)}...`:s:"Queued follow-up"}function zd({messages:t,onCancelMessage:s}){return t.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(Nl,{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:t.length})]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:t.map((n,r)=>{const o=n.content.filter(i=>i.type==="image");return 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:r+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"break-words [overflow-wrap:anywhere]",children:Fd(n.content)}),o.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:o.map((i,d)=>e.jsx(Oa,{image:i,alt:i.filename??`queued attachment ${d+1}`,thumbnailClassName:"h-14 w-14 border border-border/65",imageClassName:"h-full w-full"},`${i.filename??"image"}-${d}`))})]}),s&&e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground hover:text-destructive",title:"Cancel queued message","aria-label":"Cancel queued message",onClick:()=>s(n.id),children:e.jsx(tt,{className:"h-3 w-3"})})]},n.id)})})]})})}const Ud="h-6 w-6 rounded-none border-b border-transparent !bg-transparent p-0 text-muted-foreground !shadow-none hover:text-foreground data-[state=active]:border-primary data-[state=active]:!bg-transparent data-[state=active]:text-primary data-[state=active]:!shadow-none",Vd=[{value:"transcript",label:"Transcript",icon:vo},{value:"files",label:"Files",icon:Pt,activeIcon:ws},{value:"diff",label:"Diff",icon:fs},{value:"preview",label:"Preview",icon:Wi}];function Hd({activeTab:t}){return e.jsx(Js,{className:"h-auto max-w-full justify-start gap-2 overflow-x-auto rounded-sm !bg-muted/40 !p-0.5 !shadow-none",children:Vd.map(s=>{const n=s.value===t&&s.activeIcon?s.activeIcon:s.icon;return e.jsx(bt,{value:s.value,title:s.label,"aria-label":s.label,className:Ud,children:e.jsx(n,{className:"h-3.5 w-3.5","aria-hidden":"true"})},s.value)})})}const Gn="h-[1.625rem] rounded-sm !border-0 !bg-transparent px-2 text-[10.5px] font-medium text-primary !shadow-none hover:!bg-transparent hover:text-primary/80 focus-visible:ring-1 focus-visible:ring-ring/50 focus-visible:ring-offset-0",gt={content:"max-w-[20rem] gap-2.5 rounded-lg border-0 p-3.5 shadow-[0_18px_70px_-44px_rgba(0,0,0,0.72)] sm:max-w-[20rem]",header:"space-y-1 text-left",title:"text-[13px] leading-4",description:"text-[11px] leading-4",footer:"gap-1 pt-0 sm:space-x-1",cancel:`${Gn} mt-0`,action:Gn},qd=30,Kd=1600;function Wd({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Ls(t){return t.scrollHeight-t.scrollTop-t.clientHeight<qd}function Yn({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function Gd({atTop:t,inputCollapseDisabled:s,scrollingUp:n}){return!s&&(n||t)}function Yd({activeTab:t,activeTaskId:s,contentVersion:n,inputCollapseDisabled:r=!1,setActiveTab:o,setInputCollapsed:i}){const d=a.useRef(null),c=a.useRef(s),f=a.useRef(!1),h=a.useRef(0),y=a.useRef(new Map),g=a.useRef(0),l=a.useRef(!0),N=a.useCallback((b=c.current)=>{const j=d.current;!j||!b||(y.current.set(b,j.scrollTop),h.current=j.scrollTop,l.current=Ls(j))},[]),C=a.useCallback((b=c.current)=>{const j=d.current;!j||!b||(j.scrollTop=Wd({savedScrollTop:y.current.get(b),scrollHeight:j.scrollHeight,clientHeight:j.clientHeight}),h.current=j.scrollTop,l.current=Ls(j))},[]),v=a.useCallback((b,j=c.current)=>{b.scrollTop=b.scrollHeight,h.current=b.scrollTop,l.current=!0,j&&y.current.set(j,b.scrollTop)},[]),A=a.useCallback((b=c.current)=>{const j=d.current;g.current=Date.now()+Kd,j&&(v(j,b),requestAnimationFrame(()=>{v(j,b),requestAnimationFrame(()=>v(j,b))}))},[v]),p=a.useCallback(b=>{const j=b.currentTarget,w=h.current,T=j.scrollTop<w&&w-j.scrollTop>10,D=j.scrollTop<=0;if(N(),!f.current){if(Ls(j)){i(!1),f.current=!0,setTimeout(()=>{f.current=!1},300);return}(T||D)&&(g.current=0,Gd({atTop:D,inputCollapseDisabled:r,scrollingUp:T})&&i(!0))}},[r,N,i]),S=a.useCallback(b=>{t==="transcript"&&N(),o(b),b==="transcript"&&requestAnimationFrame(()=>C())},[t,C,N,o]);return a.useLayoutEffect(()=>{r&&i(!1)},[r,i]),a.useLayoutEffect(()=>{const b=c.current;b&&b!==s&&N(b),c.current=s,t==="transcript"&&requestAnimationFrame(()=>C(s))},[s,t,C,N]),a.useLayoutEffect(()=>{const b=d.current;if(!b||t!=="transcript"||!s)return;Yn({explicitBottomStickUntil:g.current,now:Date.now(),wasAtBottom:l.current})&&v(b,s),N(s)},[s,t,n,N,v]),a.useLayoutEffect(()=>{const b=d.current,j=b==null?void 0:b.firstElementChild;if(!b||!j||t!=="transcript"||typeof ResizeObserver>"u")return;const w=new ResizeObserver(()=>{Yn({explicitBottomStickUntil:g.current,now:Date.now(),wasAtBottom:l.current})?v(b):N()});return w.observe(b),w.observe(j),()=>w.disconnect()},[t,s,N,v]),{handleTranscriptScroll:p,handleTranscriptTabChange:S,scrollTranscriptToBottom:A,transcriptScrollRef:d}}function nr(t=700){const[s,n]=a.useState(!1),r=a.useRef(null),o=a.useCallback(()=>{n(!0),r.current!==null&&clearTimeout(r.current),r.current=setTimeout(()=>{n(!1),r.current=null},t)},[t]);return a.useEffect(()=>()=>{r.current!==null&&clearTimeout(r.current)},[]),{markScrollbarActive:o,scrollbarActive:s}}const un="pointer-events-auto h-5 w-5 shrink-0 rounded-full bg-muted/65 text-muted-foreground hover:bg-muted hover:text-foreground",Dt="h-3.5 w-3.5",Qd=a.lazy(async()=>({default:(await tn(()=>import("./FilesTab-C67Dnkts.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Zd=a.lazy(async()=>({default:(await tn(()=>import("./PreviewTab-C5m4cFxf.js").then(s=>s.c),__vite__mapDeps([6,1,2]))).PreviewTab})),Xd=a.lazy(async()=>({default:(await tn(()=>import("./DiffTab-BygUE807.js"),__vite__mapDeps([7,1,2,5,4,3,6]))).DiffTab}));function Jd({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,activeTab:c,setActiveTab:f,creatingTask:h,createMode:y,createDefaults:g,activeTask:l,assignedNode:N,taskLoading:C,transcriptLoading:v,taskError:A,displayEvents:p,initialPromptAlreadyInLogs:S,initialPrompt:b,supportsFollowUp:j,taskUnavailable:w,chatDisabled:T,chatDisabledReason:D,questionBypassEnabled:U,isRunning:E,isStarting:F,hasPendingFollowUp:B,canCancel:Q,canRetry:ee,onRetry:V,onCancel:H,onReloadNativeTranscript:se,onShareTask:ie,onStopShareTask:L,onStartCreateTask:K,onCancelCreateTask:_,onCreateTask:W,onSendMessage:x,onCancelQueuedMessage:z,onQuestionBypassChange:m,onSubmitQuestionResponse:G,quickChats:M=[]}){const[q,k]=a.useState(!1),[X,re]=a.useState(!1),[ce,J]=a.useState(!1),[O,te]=a.useState(!1),[le,R]=a.useState(!1),[ae,ve]=a.useState({}),[Ee,nt]=a.useState(new Set),[at,Ue]=a.useState(new Set),[je,it]=a.useState(null),We=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",Me=l?(N==null?void 0:N.name)??Os(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",ne=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:Me}),"..."]}):"Connecting session to an available node...",we=l?[{label:"Working dir",value:We,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:Me}]:[],Pe=!!(b&&!S),De=Pe||p.length>0,lt=E&&De,ye=(F||B||E)&&!lt,qe=lt?"The agent is still working on this conversation.":ye?ne:null,{collapsedButtonRunning:$e,showDockedProgress:jt,showInlineProgress:Te}=Id({hasTranscriptProgress:!!qe,hasVisibleTranscriptEvents:De,inputCollapsed:q}),$=(l==null?void 0:l.conversationKind)==="nativeSession",Le=v?"Loading transcript":$?"No transcript imported":"Transcript is warming up",Ae=v?"Loading transcript...":$?"Meshy could not find imported history for this native session yet.":"The opening prompt has been stored, but the agent has not emitted conversation output yet.",dt=(l==null?void 0:l.queuedMessages)??[],pt=a.useMemo(()=>$i(p),[p]),wt=a.useMemo(()=>Oi("transcript",pt.map(fe=>fe.event)),[pt]),Ie=l&&!Ee.has(l.id)?ae[l.id]??l.activeShare??null:null,ze=(l==null?void 0:l.id)??null,yt=`${ze??"none"}:${p.length}:${dt.length}:${Pe?1:0}:${v?1:0}:${Te?1:0}`,{handleTranscriptScroll:ft,handleTranscriptTabChange:Ge,scrollTranscriptToBottom:mt,transcriptScrollRef:Nt}=Yd({activeTab:c,activeTaskId:ze,contentVersion:yt,inputCollapseDisabled:!!qe,setActiveTab:f,setInputCollapsed:k}),{markScrollbarActive:ct,scrollbarActive:Ne}=nr(),_e=a.useCallback(fe=>{ct(),ft(fe)},[ft,ct]),ut=a.useCallback(fe=>{it(be=>({path:fe,requestId:((be==null?void 0:be.requestId)??0)+1})),Ge("files")},[Ge]),kt=a.useCallback(fe=>{mt(),x(fe)},[x,mt]);return a.useEffect(()=>{it(null)},[ze]),h?e.jsx(ec,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,defaultMode:y,createDefaults:g,onCancel:_,onCreated:W,quickChats:M}):!l&&C?e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ys,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"space-y-3 text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(ue,{className:"h-5 w-5 animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm 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-3.5 w-3.5 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(en,{value:c,onValueChange:Ge,className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"dashboard-conversation-panel__header relative shrink-0 bg-card/28 px-3 pb-0.5 pt-1 sm:px-5 sm:pt-1.5",children:[e.jsxs("div",{className:"pointer-events-none absolute left-1 right-1 top-2 flex items-center justify-between sm:left-1.5 sm:right-1.5 sm:top-2.5",children:[e.jsx(ar,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:o,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:P(un,"xl:hidden"),children:r?e.jsx(He,{className:Dt}):e.jsx(Wt,{className:Dt})})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx("h2",{className:"min-w-0 truncate text-[13px] font-semibold leading-5 text-foreground sm:text-[15px]",title:l.title,children:l.title}),e.jsx(Da,{status:l.status,isNative:$}),l.priority!=="normal"&&e.jsx(wo,{priority:l.priority})]}),A&&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:A}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx(Hd,{activeTab:c}),w&&e.jsx(Fe,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"hidden rounded-sm bg-muted/65 px-1.5 py-0.5 tabular-nums sm:inline-flex",children:yo(l.updatedAt)}),ee&&e.jsxs(Z,{variant:"outline",size:"sm",onClick:V,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(_l,{className:"h-3.5 w-3.5"}),"Retry"]}),$&&se&&e.jsx(Z,{variant:"ghost",size:"icon",onClick:se,disabled:v,title:"Reload native session transcript","aria-label":"Reload native session transcript",className:"h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",children:e.jsx(Ha,{className:P("h-3.5 w-3.5",v&&"animate-spin")})}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",disabled:w,title:w?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":w?"Unavailable tasks cannot be shared.":"Share conversation",className:"h-6 w-6 shrink-0 rounded-sm text-primary hover:bg-primary/10 hover:text-primary disabled:bg-transparent disabled:text-muted-foreground",onClick:()=>J(!0),children:e.jsx(gs,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(ot,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"relative min-h-0 flex-1",children:e.jsx("div",{ref:Nt,"data-transcript-scroll":"true",className:P("scrollbar-line h-full min-h-0 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 pb-4 pt-4 sm:px-5",Ne&&"scrollbar-line-active"),onScroll:_e,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[Pe&&b&&e.jsx($n,{event:b,agent:l.agent,taskRootPath:l.effectiveProjectPath,onOpenFilePath:ut,questionBypassEnabled:U,onQuestionBypassChange:m,onSubmitQuestionResponse:G,questionResponseDisabled:!j||T}),pt.map(({event:fe,subItems:be},rt)=>e.jsx($n,{event:fe,agent:l.agent,subItems:be,taskRootPath:l.effectiveProjectPath,onOpenFilePath:ut,questionBypassEnabled:U,onQuestionBypassChange:m,onSubmitQuestionResponse:G,questionResponseDisabled:!j||T},wt[rt])),!De&&!ye&&e.jsxs("div",{className:"rounded-sm border border-dashed border-border/70 bg-background/35 px-3 py-4 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:Le}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Ae})]}),(!j&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!j&&l.result&&e.jsxs("div",{className:"rounded-sm 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&&!at.has(l.id)&&e.jsxs("div",{className:"rounded-sm 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:()=>Ue(fe=>new Set(fe).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(tt,{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})]})]}),Te&&qe&&e.jsx(Kn,{children:qe})]})})}),jt&&qe&&e.jsx("div",{"data-docked-progress":"true",className:"shrink-0 bg-background/35 px-3 py-1 sm:px-5",children:e.jsx("div",{className:"mx-auto max-w-[72rem]",children:e.jsx(Kn,{children:qe})})}),j?e.jsxs(e.Fragment,{children:[q&&e.jsx(Ld,{running:$e,onClick:()=>{k(!1),mt(),requestAnimationFrame(()=>{var fe;return(fe=document.querySelector('[data-chat-input-textarea="true"]'))==null?void 0:fe.focus()})}}),e.jsxs("div",{className:`shrink-0 ${q?"hidden":""}`,children:[e.jsx(zd,{messages:dt,onCancelMessage:z}),e.jsx(nd,{onSend:kt,disabled:T,disabledReason:D,contextItems:we,placeholder:T?D:E?"Queue a message for the next turn...":"Continue the conversation...",running:E||B,onStop:Q?()=>re(!0):void 0,quickChats:M})]})]}):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(ot,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ms,{label:"Loading files..."}),children:e.jsx(Qd,{taskId:l.id,requestedFilePath:(je==null?void 0:je.path)??null,requestedFileRequestId:(je==null?void 0:je.requestId)??0})})}),e.jsx(ot,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ms,{label:"Loading preview..."}),children:e.jsx(Zd,{taskId:l.id})})}),e.jsx(ot,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ms,{label:"Loading diff..."}),children:e.jsx(Xd,{taskId:l.id})})}),e.jsx(is,{open:X,onOpenChange:re,children:e.jsxs(ls,{className:gt.content,children:[e.jsxs(ds,{className:gt.header,children:[e.jsx(cs,{className:gt.title,children:"Stop this task?"}),e.jsx(us,{className:gt.description,children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ms,{className:gt.footer,children:[e.jsx(xs,{className:gt.cancel,children:"Keep running"}),e.jsx(hs,{className:gt.action,onClick:H,children:"Stop task"})]})]})}),e.jsx(Bd,{open:ce,onOpenChange:J,sharing:O,stopping:le,shareResult:Ie,onShare:async fe=>{if(!l)return null;te(!0);try{const be=await ie(fe);return be!=null&&be.url&&(ve(rt=>({...rt,[l.id]:be})),nt(rt=>{const St=new Set(rt);return St.delete(l.id),St})),be}finally{te(!1)}},onStopShare:async()=>{if(!l)return!1;R(!0);try{const fe=await L();return fe!==!1&&(ve(be=>{const rt={...be};return delete rt[l.id],rt}),nt(be=>new Set(be).add(l.id))),fe}finally{R(!1)}}})]}):e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ys,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"w-full max-w-lg text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(jo,{className:"h-5 w-5"})}),e.jsx("h2",{className:"mt-3 text-sm font-semibold tracking-tight text-foreground sm:text-[15px]",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-2 max-w-md text-[11px] leading-5 text-muted-foreground",children:"Open a task from the left sidebar to continue the conversation, or start a new task or load a native session."}),e.jsxs(Z,{onClick:()=>K(),className:"mt-4 h-8 rounded-sm px-3",children:[e.jsx(ys,{className:"h-3.5 w-3.5"}),"Start or load chat"]}),A&&e.jsx("div",{className:"mx-auto mt-3 max-w-md rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:A})]})})]})}function ec({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,defaultMode:c,createDefaults:f,onCancel:h,onCreated:y,quickChats:g}){var v,A,p;const[l,N]=a.useState(c??"chat");a.useEffect(()=>{c&&N(c)},[c]);const C=e.jsx("div",{className:"flex h-8 items-center gap-0.5 overflow-hidden rounded-sm border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-none",children:[{value:"chat",label:"New chat",icon:ys},{value:"native",label:"Load session",icon:ln}].map(S=>{const b=S.icon,j=S.value===l;return e.jsxs("button",{type:"button",onClick:()=>N(S.value),"aria-pressed":j,className:P("flex h-7 min-w-28 items-center justify-center gap-1.5 rounded-sm border border-transparent px-2.5 transition-colors duration-150",j?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(b,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:S.label})]},S.value)})});return e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ys,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,centerSlot:C})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(Pd,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(v=i==null?void 0:i.self)==null?void 0:v.role,currentNodeId:((A=i==null?void 0:i.self)==null?void 0:A.id)??null,leaderNodeId:((p=i==null?void 0:i.leader)==null?void 0:p.id)??null,initialAssignTo:f==null?void 0:f.assignTo,initialProject:f==null?void 0:f.project,mode:l,onModeChange:N,onCreated:y,onCancel:h,autoFocus:!0,layout:"composer",quickChats:g})})})]})}function Ys({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,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(ar,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"})}),i&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",children:e.jsx("div",{className:"pointer-events-auto",children:i})}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:o,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:P(un,"xl:hidden"),children:r?e.jsx(He,{className:Dt}):e.jsx(Wt,{className:Dt})})]})}function ar({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){var i,d;const o=(d=(i=globalThis.window)==null?void 0:i.matchMedia("(min-width: 1024px)"))!=null&&d.matches?s:n;return e.jsx(Z,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:P(un,t),children:o?e.jsx(Wt,{className:Dt}):e.jsx(He,{className:Dt})})}function tc({onAdded:t}){const[s,n]=a.useState(""),[r,o]=a.useState(!1),[i,d]=a.useState(null),c=a.useCallback(async f=>{if(f.preventDefault(),!!s.trim()){o(!0),d(null);try{await No({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(h){d(h instanceof Error?h.message:"Failed to join node")}finally{o(!1)}}},[s,t]);return e.jsx(It,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-sm border border-border/60 bg-background/95 p-0 shadow-[0_28px_90px_-58px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-3.5 py-2.5",children:e.jsxs(sn,{className:"space-y-1 text-left",children:[e.jsx(Yt,{className:"text-sm tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-[11px] 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:c,className:"space-y-3 px-3.5 py-3",children:[i&&e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] 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(Oe,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Fe,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(et,{id:"leader-endpoint",type:"url",value:s,onChange:f=>n(f.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-8 rounded-sm border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-sm border border-border/60 bg-background/45 px-3 py-2 text-[11px] 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(Aa,{className:"border-t border-border/60 pt-3",children:e.jsx(Z,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function sc({open:t,onOpenChange:s,onAdded:n}){return e.jsx(Lt,{open:t,onOpenChange:s,children:e.jsx(tc,{onAdded:()=>{s(!1),n()}})})}const nc="absolute top-1/2 z-30 hidden h-10 w-4 -translate-y-1/2 items-center justify-center rounded-full text-muted-foreground opacity-0 outline-none transition-opacity duration-150 hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/55",ac="flex h-7 w-3.5 items-center justify-center rounded-full bg-muted/85 shadow-[0_12px_24px_-20px_rgba(0,0,0,0.9)] backdrop-blur-sm transition-colors hover:bg-card hover:text-foreground",rc="h-2.5 w-2.5";function rr({className:t,label:s,orientation:n,panel:r,panelResize:o}){return e.jsx("button",{type:"button","aria-label":s,"aria-orientation":n,"data-dashboard-resize-handle":r,onPointerDown:i=>o.onPointerDown(r,i),onWheel:i=>o.onWheel(r,i),className:P("group absolute z-20 hidden touch-none rounded-sm bg-transparent outline-none transition-colors hover:bg-primary/12 focus-visible:bg-primary/12 focus-visible:ring-2 focus-visible:ring-ring/70 lg:block",t),children:e.jsx("span",{className:"pointer-events-none absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"})})}function oc({className:t,label:s,onToggle:n,side:r,visible:o}){const i=r==="left"?o?Wt:He:o?He:Wt;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:P(nc,t),children:e.jsx("span",{className:ac,"aria-hidden":"true",children:e.jsx(i,{className:rc,strokeWidth:2.1})})})}function Qn({className:t,label:s,onToggle:n,panel:r,panelResize:o,screen:i,side:d,visible:c}){const f=i==="lg"?"lg:block":"xl:block",h=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:P("group absolute top-0 z-30 hidden h-full w-4",f,t),children:[r&&e.jsx(rr,{panel:r,orientation:"vertical",label:`Resize ${r} panel`,panelResize:o,className:"left-1/2 top-0 h-full w-2 -translate-x-1/2 cursor-col-resize"}),e.jsx(oc,{side:d,visible:c,label:s,onToggle:n,className:P(h,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function ic({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:o,operationsOpen:i,operationsPanelRef:d,operationsSidecar:c,panelResize:f,taskSidebar:h,terminalPanel:y,onCloseOperations:g,onCloseTaskList:l,onToggleOperations:N,onToggleTasks:C}){const v={"--dashboard-tasks-width":f.sizes.tasks,"--dashboard-operations-width":f.sizes.operations,"--dashboard-terminal-height":f.sizes.terminal};return e.jsxs("div",{className:"dashboard-workspace flex h-full min-h-0 flex-col overflow-hidden",style:v,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(Qn,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:C,panel:s?"tasks":void 0,panelResize:f,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:P("dashboard-workspace__tasks-panel relative hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",s?"lg:mr-2 lg:w-[var(--dashboard-tasks-width)]":"lg:w-0 lg:overflow-hidden"),children:s&&h}),e.jsxs("section",{className:"dashboard-workspace__primary flex min-h-0 min-w-0 flex-1 flex-col gap-2",children:[e.jsx("div",{className:"min-h-0 flex-1",children:t}),y&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(rr,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:f,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),y]})]}),e.jsx(Qn,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:N,panel:i?"operations":void 0,panelResize:f,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:P("dashboard-workspace__operations-panel relative hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",i?"xl:ml-2 xl:w-[var(--dashboard-operations-width)]":"xl:w-0 xl:overflow-hidden"),children:i&&c})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:g,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:d,className:"fixed bottom-0 right-0 top-[var(--dashboard-mobile-overlay-top)] z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:c})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:l,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:o,className:"fixed bottom-0 left-0 top-[var(--dashboard-mobile-overlay-top)] z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:n})]})]})}const lc=10,vt="__all__";function Ke(t){return"session"in t}function Zn(t,s){var n;return s&&t.some(r=>r.id===s)?s:((n=t[0])==null?void 0:n.id)??""}function Is(t){return t&&(Ja(t.id)||t.workDir)||""}function ss(t,s,n){let r=!1;const o=t.map(i=>Ke(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return Qs(r?o:[...o,{id:`session-${n.id}`,nodeName:s,session:n}])}function or(t,s){return t.filter(Ke).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function dc(t){const s=t.filter(Ke).sort((n,r)=>r.session.startedAt-n.session.startedAt);return{active:s.filter(n=>n.session.status==="running"),completed:s.filter(n=>n.session.status!=="running")}}function cc(t,s){return!!(t&&s&&!t.contains(s))}function uc(t,s,n){var o;if(n===vt)return n;const r=or(t,s);return r.some(i=>i.session.id===n)?n:((o=r[0])==null?void 0:o.session.id)??vt}function mc(t,s,n){return n===vt?t.filter(r=>!Ke(r)||r.session.nodeId===s):t.filter(r=>Ke(r)&&r.session.nodeId===s&&r.session.id===n)}function Qs(t){const s=t.map((r,o)=>({entry:r,index:o})).filter(({entry:r})=>Ke(r)&&r.session.status!=="running").sort((r,o)=>!Ke(r.entry)||!Ke(o.entry)?0:o.entry.session.startedAt-r.entry.session.startedAt||o.index-r.index),n=new Set(s.slice(0,lc).map(({entry:r})=>Ke(r)?r.session.id:""));return t.filter(r=>!Ke(r)||r.session.status==="running"||n.has(r.session.id))}function Zs(t){return t.status==="running"?t.pid?`running pid ${t.pid}`:"running":t.status==="exited"?`exit ${t.exitCode??0}`:t.status==="stopped"?"stopped":t.signal?`failed ${t.signal}`:`exit ${t.exitCode??"failed"}`}function xc(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${Zs(t.session)} - ${s}`}function ir(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function hc(t,s){return s===vt?"All sessions":t?ir(t.session.command,34):"Command session"}function Xn(t){return t.status==="stopped"?"":t.stderr}function pc({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[o,i]=a.useState(()=>Zn(t,s)),d=a.useMemo(()=>t.find(m=>m.id===o)??t[0]??null,[t,o]),[c,f]=a.useState(()=>Is(d)),[h,y]=a.useState(""),[g,l]=a.useState(()=>Qs(r)),[N,C]=a.useState(vt),[v,A]=a.useState(!1),[p,S]=a.useState(!1),[b,j]=a.useState(!1),[w,T]=a.useState(!1),[D,U]=a.useState(!1),E=a.useRef(null),F=a.useRef(null),B=a.useMemo(()=>t.find(m=>m.id===o)??t[0]??null,[t,o]),Q=a.useMemo(()=>or(g,(B==null?void 0:B.id)??""),[g,B]),ee=a.useMemo(()=>dc(Q),[Q]),V=a.useMemo(()=>Q.find(m=>m.session.id===N),[N,Q]),H=a.useMemo(()=>mc(g,(B==null?void 0:B.id)??"",N),[g,B,N]),se=a.useRef((B==null?void 0:B.id)??"");a.useEffect(()=>{o&&t.some(m=>m.id===o)||i(Zn(t,s))},[s,t,o]),a.useEffect(()=>{const m=(B==null?void 0:B.id)??"";se.current!==m&&(se.current=m,f(Is(B)))},[B]),a.useEffect(()=>{C(m=>uc(g,(B==null?void 0:B.id)??"",v?m:""))},[g,B,v]),a.useEffect(()=>{var m;(m=E.current)==null||m.scrollTo({top:E.current.scrollHeight})},[g]),a.useEffect(()=>{let m=!1;async function G(){const M=await Promise.allSettled(t.map(async q=>({node:q,response:await So(q.id)})));m||l(q=>M.reduce((k,X)=>X.status!=="fulfilled"?k:X.value.response.sessions.reduce((re,ce)=>ss(re,X.value.node.name,ce),k),q))}return t.length>0&&G(),()=>{m=!0}},[t]),a.useEffect(()=>{const m=g.filter(Ke).filter(M=>M.session.status==="running");if(m.length===0)return;const G=window.setInterval(()=>{for(const M of m)ko(M.session.nodeId,M.session.id).then(q=>l(k=>ss(k,M.nodeName,q))).catch(()=>{})},1e3);return()=>window.clearInterval(G)},[g]);const ie=a.useRef(null);async function L(m){if(m.preventDefault(),!B||!h.trim()||D)return;const G=h.trim(),M=B.name;U(!0),y("");try{const q=await To(B.id,{command:G,...c.trim()?{cwd:c.trim()}:{}});l(k=>ss(k,M,q)),C(q.id),A(!0)}catch(q){l(k=>[...k,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:M,command:G,error:q instanceof Error?q.message:"Command failed"}])}finally{U(!1)}}async function K(m,G){m.stopPropagation();const M=await Co(G.session.nodeId,G.session.id);l(q=>ss(q,G.nodeName,M))}function _(m){C(m),A(!0),S(!1)}function W(m){p&&cc(F.current,m.target)&&S(!1)}function x(m,G,M,q,k){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:q,"aria-label":`Toggle ${m} sessions`,"aria-expanded":!M,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(st,{className:P("h-3 w-3 transition-transform",M&&"-rotate-90")})]}),!M&&(G.length>0?G.map(z):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:k}))]})}function z(m){const G=N===m.session.id,M=m.session.status==="running";return e.jsxs("div",{className:P("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",G&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>_(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:P("flex h-4 w-4 shrink-0 items-center justify-center",M?"text-primary":m.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:M?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):m.session.status==="exited"?e.jsx(En,{className:"h-3 w-3"}):e.jsx(Ds,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:ir(m.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[m.nodeName," · ",Zs(m.session)]})]})]}),M&&e.jsx("button",{type:"button",onClick:q=>void K(q,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(zn,{className:"h-3 w-3"})})]},m.session.id)}return e.jsx("section",{className:"dashboard-panel node-terminal animate-composer-settle flex h-full min-h-0 shrink-0 overflow-visible rounded-xl","aria-label":"Node terminal",onClick:W,children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-visible rounded-[inherit] bg-card/72 text-card-foreground",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"node-terminal__header flex min-w-0 items-center gap-2 font-medium",children:[n?e.jsx("button",{type:"button",onClick:n,"aria-label":"Close terminal",title:"Close terminal",className:"flex h-6 w-6 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(tt,{className:"h-3.5 w-3.5"})}):e.jsx(_n,{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:F,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":p,title:V?xc(V):"All sessions",onClick:()=>S(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:hc(V,N)}),e.jsx(st,{className:P("h-3 w-3 shrink-0 text-muted-foreground transition-transform",p&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!p,className:P("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!p&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>_(vt),className:P("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",N===vt&&"bg-primary/10 text-primary"),children:[e.jsx(_n,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),x("Active",ee.active,b,()=>j(m=>!m),"No active sessions"),x("Completed",ee.completed,w,()=>T(m=>!m),"No completed sessions")]})})]}),e.jsx("select",{value:(B==null?void 0:B.id)??"",onChange:m=>{i(m.target.value),A(!1),f(Is(t.find(G=>G.id===m.target.value)??null))},disabled:D||t.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:t.map(m=>e.jsx("option",{value:m.id,className:"bg-background text-foreground",children:m.name},m.id))}),e.jsx(bs,{value:c,onChange:f,assignTo:(B==null?void 0:B.id)??"",nodes:t,assignableNodes:t,layout:"composer",chipClassName:"node-terminal__control h-7 max-w-[18rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground hover:bg-muted/65",chipActiveClassName:"font-mono",chipInactiveClassName:"text-muted-foreground",labelClassName:"node-terminal__workdir",triggerClassName:"terminal-workdir-trigger",popoverPlacement:"top",popoverAlign:"end"})]})]}),e.jsxs("div",{ref:E,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>{var m;return(m=ie.current)==null?void 0:m.focus()},children:[H.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:H.map(m=>Ke(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:P("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(En,{className:"h-3 w-3"}):e.jsx(Ds,{className:"h-3 w-3"}),Zs(m.session)]}),m.session.status==="running"&&e.jsx("button",{type:"button",onClick:G=>void K(G,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(zn,{className:"h-3 w-3"})})]}),m.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:m.session.stdout}),Xn(m.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Xn(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(Ds,{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:L,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:B?`${B.name}$`:"$"}),e.jsx("input",{ref:ie,value:h,onChange:m=>y(m.target.value),disabled:!B||D,placeholder:B?"":"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:!B||!h.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(js,{className:"h-3 w-3"})})]})]})]})})}function mn({nodeId:t,nodeName:s,onOpenSettings:n,onOpenServicePreview:r,onOpenCapabilities:o,onOpenDevBox:i,onStartDevBox:d,onToggleRemoteAccess:c,remoteAccessLabel:f,remoteAccessPending:h,remoteAccessDisabled:y,remoteAccessDisabledReason:g,showConfigureDevBox:l,showStartDevBox:N,startDevBoxPending:C,className:v}){const[A,p]=a.useState(!1),[S,b]=a.useState(null),j=a.useRef(null),w=a.useRef(null),T=C?"Starting":"Start DevBox",D=f!=null&&f.startsWith("Disable")?_o:$l;a.useLayoutEffect(()=>{if(!A){b(null);return}const E=()=>{const F=w.current,B=j.current;if(!F||!B)return;const Q=F.getBoundingClientRect(),ee=B.getBoundingClientRect();b(gc({left:Q.left,right:Q.right,bottom:Q.bottom,top:Q.top},{width:ee.width,height:ee.height},{width:window.innerWidth,height:window.innerHeight},bc()))};return E(),window.addEventListener("resize",E),window.addEventListener("scroll",E,!0),()=>{window.removeEventListener("resize",E),window.removeEventListener("scroll",E,!0)}},[A]),a.useEffect(()=>{if(!A)return;const E=B=>{var ee,V;const Q=B.target;Q instanceof Node&&!((ee=j.current)!=null&&ee.contains(Q))&&!((V=w.current)!=null&&V.contains(Q))&&p(!1)},F=B=>{B.key==="Escape"&&p(!1)};return document.addEventListener("mousedown",E),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",F)}},[A]);const U=A?e.jsxs("div",{ref:j,"data-node-action-menu-portal":"true",role:"menu",style:fc(S),onClick:E=>E.stopPropagation(),onPointerDown:E=>E.stopPropagation(),className:"fixed z-[130] 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:[n&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} settings`,title:`Open ${s} settings`,onClick:E=>{E.stopPropagation(),p(!1),n(t)},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(Eo,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Settings"})]}),r&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Preview service on ${s}`,title:`Preview service on ${s}`,onClick:E=>{E.stopPropagation(),p(!1),r(t)},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(Va,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Preview service"})]}),o&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} capabilities`,title:`Open ${s} capabilities`,onClick:E=>{E.stopPropagation(),p(!1),o(t)},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(vs,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Capabilities"})]}),f&&c&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${f} for ${s}`,title:g??`${f} for ${s}`,onClick:E=>{E.stopPropagation(),!(h||y)&&(p(!1),c())},disabled:h||y,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:[h?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(D,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:f})]}),N&&d&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${T} for ${s}`,title:`${T} for ${s}`,onClick:E=>{E.stopPropagation(),!C&&(p(!1),d(t))},disabled:C,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:[C?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(js,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:T})]}),l&&i&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${s}`,title:`Configure DevBox for ${s}`,onClick:E=>{E.stopPropagation(),p(!1),i(t)},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(Do,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Configure DevBox"})]})]}):null;return e.jsxs("div",{"data-node-action-menu":"true",className:P("relative shrink-0",A&&"z-[120]",v),onClick:E=>E.stopPropagation(),onPointerDown:E=>E.stopPropagation(),children:[e.jsx(Z,{ref:w,type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${s}`,"aria-haspopup":"menu","aria-expanded":A,title:`More actions for ${s}`,onClick:E=>{E.stopPropagation(),p(F=>(F||b(null),!F))},className:P("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",A&&"bg-background/80 text-primary"),children:e.jsx(ol,{className:"h-3.5 w-3.5"})}),U&&(typeof document>"u"?U:Ma.createPortal(U,document.body))]})}function fc(t){return t?{left:t.left,top:t.top}:{left:0,top:0,visibility:"hidden"}}function gc(t,s,n,r=1){const d=s.width||160,c=s.height||0,f=Number.isFinite(r)&&r>0?r:1,h=Math.max(8,Math.min(t.right-d,n.width-d-8)),y=t.bottom+4,g=(t.top??t.bottom)-c-4,l=y+c>n.height-8&&g>=8?g:y;return{left:Math.round(h/f),top:Math.round(l/f)}}function bc(){if(typeof window>"u"||typeof document>"u")return 1;const t=window.getComputedStyle(document.documentElement),s=t.zoom||t.getPropertyValue("--ui-zoom"),n=Number.parseFloat(s);return Number.isFinite(n)&&n>0?n:1}const vc=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),jc=new Set(["startinprogress","starting"]);function At(t){return!!(t!=null&&t.enabled&&t.name)}function wc(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&vc.has(s))}function Mt(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&jc.has(s))}function Ns(t,s,n){return t==="offline"&&wc(s)&&At(n)}function Jn(t,s){return t==="offline"&&At(s)}function ea(t){return!At(t)}function yc({nodeStatus:t,status:s,current:n,selected:r}){const o=r??n;return o&&Ns(t,s,o)?o:null}function Re(t){return t.scope||`name:${t.name??""}`}function Nc({previousKey:t,baseDevBox:s,listed:n}){if(t&&n.some(i=>Re(i)===t))return t;if(!At(s))return n[0]?Re(n[0]):"";const r=Re(s),o=n.find(i=>Re(i)===r)??n.find(i=>i.name===s.name);return o?Re(o):r}function kc({cluster:t,systemInfo:s,nodeNameById:n,nodeBlockingTaskCounts:r,eventTypeFilter:o,onEventTypeFilterChange:i,eventTypeOptions:d,filteredEvents:c,sseConnected:f,clusterLoading:h,clusterError:y,promotePending:g,onPromote:l,onAddNode:N,leavePending:C,onLeaveCluster:v,onToggleNodeDevTunnel:A,devTunnelNodeId:p,devBoxStartNodeId:S,devBoxStartingNodeIds:b=new Set,onOpenNodeSettings:j,onOpenNodeCapabilities:w,onOpenDevBox:T,onStartDevBox:D}){var ie,L,K;const U=((ie=t==null?void 0:t.self)==null?void 0:ie.role)==="leader",E=((L=t==null?void 0:t.self)==null?void 0:L.role)==="follower"&&!(t!=null&&t.leader),F=(t==null?void 0:t.self)??null,Q=Ao((t==null?void 0:t.nodes)??[],F==null?void 0:F.id).filter(_=>_.id!==(F==null?void 0:F.id)),ee=t!=null&&t.leader?t.nodes.find(_=>{var W;return _.id===((W=t.leader)==null?void 0:W.id)})??null:null,V=t!=null&&t.leader?t.leader.dashboardOrigin??(ee==null?void 0:ee.dashboardOrigin)??(s&&t.leader.id===(s.nodeId??s.id)?s.dashboardOrigin:void 0)??t.leader.endpoint:null,H=(F==null?void 0:F.role)==="leader"&&Q.length===0,se=(F==null?void 0:F.role)==="follower";return e.jsx("aside",{className:"dashboard-operations-sidecar dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:e.jsxs(en,{defaultValue:"overview",className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"dashboard-operations-sidecar__header shrink-0 bg-card/24 px-2.5 py-2",children:e.jsxs(Js,{className:"grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(bt,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(bt,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(bt,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})}),e.jsx(ot,{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:[F&&e.jsx(ta,{node:F,systemInfo:s,blockingTaskCount:r.get(F.id)??0,devTunnelNodeId:p,onToggleNodeDevTunnel:A,showActions:!1,defaultExpanded:!1,onOpenDevBox:T,devBoxStartingNodeIds:b}),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(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:f?"Connected":"Reconnecting"})]}),h&&!t?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..."]}):y&&!t?e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-2 py-1.5 text-[10px] text-destructive shadow-none",children:y}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(Tt,{label:"Term",value:String((t==null?void 0:t.term)??0)}),e.jsx(Tt,{label:"Nodes",value:String((t==null?void 0:t.nodes.length)??0)}),e.jsx(Tt,{label:"Pending",value:String((t==null?void 0:t.taskSummary.pending)??0)}),e.jsx(Tt,{label:"Running",value:String((t==null?void 0:t.taskSummary.running)??0)}),e.jsx(Tt,{label:"Completed",value:String((t==null?void 0:t.taskSummary.completed)??0)}),e.jsx(Tt,{label:"Failed",value:String((t==null?void 0:t.taskSummary.failed)??0)})]}),e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-muted/45 px-2 py-2 shadow-none",children:[e.jsx(Je,{label:"Leader",value:((K=t==null?void 0:t.leader)==null?void 0:K.name)??"None"}),e.jsx(Je,{label:"Leader URL",value:V??"Unavailable",mono:!0,action:V?e.jsx(Gt,{label:"Copy leader URL",onClick:()=>void _t(V,"Leader URL copied")}):void 0}),e.jsx(Je,{label:"Feed",value:f?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:E&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:l,disabled:g,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[g&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(ot,{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"}),H?e.jsxs(Z,{variant:"secondary",size:"sm",onClick:N,className:"h-6 border-0 bg-primary px-2 text-[10px] text-primary-foreground shadow-none hover:bg-primary/90",children:[e.jsx(Bl,{className:"h-3 w-3"}),"Join node"]}):se?e.jsxs(Z,{variant:"secondary",size:"sm",onClick:v,disabled:C,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[C&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),F&&e.jsx(ta,{node:F,systemInfo:s,blockingTaskCount:r.get(F.id)??0,devTunnelNodeId:p,onToggleNodeDevTunnel:A,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:U?j:void 0,onOpenNodeCapabilities:U?w:void 0,onOpenDevBox:U?T:void 0,onStartDevBox:U?D:void 0,devBoxStartNodeId:S,devBoxStartingNodeIds:b})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",Q.length,")"]}),Q.length>0?e.jsx("div",{className:"space-y-1.5",children:Q.map(_=>e.jsx(Sc,{node:_,isLeader:!!U,blockingTaskCount:r.get(_.id)??0,devTunnelNodeId:p,onToggleNodeDevTunnel:A,onOpenNodeSettings:U?j:void 0,onOpenNodeCapabilities:U?w:void 0,onOpenDevBox:U?T:void 0,onStartDevBox:U?D:void 0,devBoxStartNodeId:S,devBoxStartingNodeIds:b},_.id))}):e.jsx("div",{className:"rounded-sm bg-muted/45 px-2 py-2 text-[10px] text-muted-foreground shadow-none",children:"No peer nodes are connected yet."})]})]})})}),e.jsx(ot,{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(Mo,{className:P("h-3.5 w-3.5",f?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(ke,{value:o,onValueChange:i,children:[e.jsx(Se,{className:"h-6 min-w-[10rem] flex-1 rounded-sm border-0 bg-muted/60 text-[10px] shadow-none sm:max-w-[14rem] [&>svg]:h-3 [&>svg]:w-3",children:e.jsx(Be,{placeholder:"Event type"})}),e.jsx(Ce,{className:"shadow-none",children:d.map(_=>e.jsx(xe,{value:_,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:_==="all"?"All event types":_},_))})]}),e.jsx(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:f?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Po,{events:c,maxHeight:"100%",emptyTitle:o==="all"?"No live events yet":"No matching events",emptyDescription:o==="all"?"Cluster activity appears here as it happens.":`No "${o}" events are in the current stream.`,nodeNameById:n,density:"compact"})})]})})]})})}function ta({node:t,systemInfo:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:o,showActions:i=!0,defaultExpanded:d=!1,onOpenNodeSettings:c,onOpenNodeCapabilities:f,onOpenDevBox:h,onStartDevBox:y,devBoxStartNodeId:g,devBoxStartingNodeIds:l}){var D,U,E,F;const[N,C]=a.useState(d),v=(s==null?void 0:s.dashboardOrigin)??t.dashboardOrigin,A=t.devtunnelEndpoint??t.endpoint,p=v??t.endpoint,S=(s==null?void 0:s.workDir)??t.workDir,b=Wa(t,s==null?void 0:s.transportType),j=dn(t,s==null?void 0:s.transportType),w=j&&Rt((s==null?void 0:s.transportType)??t.transportType)?!0:Ka(t,s==null?void 0:s.transportType),T=n>0;return e.jsxs("section",{className:"dashboard-operations-node-card bg-primary/8 shadow-none",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:()=>C(B=>!B),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[N?e.jsx(st,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(He,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(Pa,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Current node"})]}),e.jsx("a",{href:p,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(nn,{className:"h-3 w-3"})}),(c||f||i&&w)&&e.jsx(mn,{nodeId:t.id,nodeName:t.name,onOpenSettings:c,onOpenCapabilities:f,onOpenDevBox:h,onStartDevBox:y,onToggleRemoteAccess:i&&w?()=>o(t):void 0,remoteAccessLabel:i&&w?j?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:T,remoteAccessDisabledReason:T?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:(D=t.devbox)==null?void 0:D.enabled,showStartDevBox:Ns(t.status,(U=t.devbox)==null?void 0:U.lastStatus,t.devbox)||Mt((E=t.devbox)==null?void 0:E.lastStatus)||l.has(t.id),startDevBoxPending:g===t.id||Mt((F=t.devbox)==null?void 0:F.lastStatus)||l.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>C(B=>!B),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:t.name}),e.jsx(La,{role:t.role,size:"compact"}),e.jsx(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),N&&e.jsxs("div",{className:"space-y-2 bg-primary/5 px-2.5 pb-2.5 pt-1.5",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-muted/45 px-2 py-1.5 shadow-none",children:[e.jsx(Je,{label:"Node ID",value:t.id,mono:!0}),v&&e.jsx(Je,{label:"Dashboard",value:v,mono:!0,action:e.jsx(Gt,{label:"Copy dashboard URL",onClick:()=>void _t(v,"Dashboard URL copied")})}),e.jsx(Je,{label:"Node URL",value:A,mono:!0,action:e.jsx(Gt,{label:"Copy node URL",onClick:()=>void _t(A,"Node URL copied")})}),S&&e.jsx(Je,{label:"Workspace",value:S,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Us,{label:"Transport",value:b}),s&&e.jsx(Us,{label:"Uptime",value:Lo(s.uptime),mono:!0})]}),i&&f&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:()=>f(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(vs,{className:"h-3 w-3"}),"Capabilities"]}),i&&w&&T&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Sc({node:t,isLeader:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:o,onOpenNodeSettings:i,onOpenNodeCapabilities:d,onOpenDevBox:c,onStartDevBox:f,devBoxStartNodeId:h,devBoxStartingNodeIds:y}){var j,w,T,D;const[g,l]=a.useState(!1),N=t.dashboardOrigin,C=t.devtunnelEndpoint??t.endpoint,v=N??t.endpoint,A=Wa(t),p=dn(t),S=Ka(t),b=n>0;return e.jsxs("div",{className:"dashboard-operations-node-card bg-muted/45 shadow-none",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(U=>!U),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[g?e.jsx(st,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(He,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Pa,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Peer node"})]}),e.jsx("a",{href:v,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(nn,{className:"h-3 w-3"})}),s&&(i||d||S)&&e.jsx(mn,{nodeId:t.id,nodeName:t.name,onOpenSettings:i,onOpenCapabilities:d,onOpenDevBox:c,onStartDevBox:f,onToggleRemoteAccess:S?()=>o(t):void 0,remoteAccessLabel:S?p?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:b,remoteAccessDisabledReason:b?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:(j=t.devbox)==null?void 0:j.enabled,showStartDevBox:Ns(t.status,(w=t.devbox)==null?void 0:w.lastStatus,t.devbox)||Mt((T=t.devbox)==null?void 0:T.lastStatus)||y.has(t.id),startDevBoxPending:h===t.id||Mt((D=t.devbox)==null?void 0:D.lastStatus)||y.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>l(U=>!U),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:t.name}),e.jsx(La,{role:t.role,size:"compact"}),e.jsx(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),g&&e.jsxs("div",{className:"space-y-2 bg-muted/35 px-2.5 pb-2.5 pt-1.5",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/55 px-2 py-1.5 shadow-none",children:[e.jsx(Je,{label:"Node ID",value:t.id,mono:!0}),N&&e.jsx(Je,{label:"Dashboard",value:N,mono:!0,action:e.jsx(Gt,{label:"Copy dashboard URL",onClick:()=>void _t(N,"Dashboard URL copied")})}),e.jsx(Je,{label:"Node URL",value:C,mono:!0,action:e.jsx(Gt,{label:"Copy node URL",onClick:()=>void _t(C,"Node URL copied")})}),t.workDir&&e.jsx(Je,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(Us,{label:"Transport",value:A})]}),s&&d&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:()=>d(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(vs,{className:"h-3 w-3"}),"Capabilities"]}),s&&S&&b&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Gt({label:t,onClick:s}){return e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-4 w-4 shrink-0 rounded-sm p-0 text-muted-foreground opacity-70 hover:bg-muted/45 hover:opacity-100 [&_svg]:size-2.5",onClick:s,"aria-label":t,title:t,children:e.jsx(Ea,{className:"h-3 w-3"})})}function Cc(t,s,n,r){var c,f;if(!t)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const o=((c=s==null?void 0:s.self)==null?void 0:c.role)==="follower",i=t.assignedTo?((f=s==null?void 0:s.self)==null?void 0:f.id)===t.assignedTo?s.self:s==null?void 0:s.nodes.find(h=>h.id===t.assignedTo):void 0;return t.assignedTo!==null&&(i?i.status==="offline":s?t.assignedNodeAvailable===!1||!s.nodes.some(h=>h.id===t.assignedTo):t.assignedNodeAvailable===!1)?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${t.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}:o?{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..."}:r?{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Queue a message for the next turn..."}:ps.has(t.status)||t.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:ps.has(t.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const lr=.5,dr=1.75,sa=.1;function Tc({node:t,open:s,onOpenChange:n}){const[r,o]=a.useState(ts),[i,d]=a.useState(null),[c,f]=a.useState(1),[h,y]=a.useState(!1),[g,l]=a.useState(null);a.useEffect(()=>{o(ts),d(null),f(1),y(!1),l(null)},[t==null?void 0:t.id,s]);const N=a.useCallback(async b=>{if(!t)return;const j=b??Number.parseInt(r.trim()||ts,10);if(!Number.isInteger(j)||j<1||j>65535){l("Enter a port between 1 and 65535");return}y(!0),l(null);try{const w=await Io(t.id,{port:j});d(w),o(String(j)),Dn("preview.created",{result:"success",previewType:"service-port"})}catch(w){l(w instanceof Error?w.message:"Failed to create service preview"),Dn("preview.failed",{result:"failed",previewType:"service-port"})}finally{y(!1)}},[t,r]),C=a.useCallback(()=>{typeof(i==null?void 0:i.port)=="number"&&N(i.port)},[i==null?void 0:i.port,N]);a.useEffect(()=>{if(!i)return;const b=i.expiresAt-Date.now()-5e3;if(b<=0){C();return}const j=window.setTimeout(C,b);return()=>window.clearTimeout(j)},[C,i]);const v=i?Yi(i):null,A=(t==null?void 0:t.name)??"Node",p=_c(c),S={width:`${100/c}%`,height:`${100/c}%`,transform:`scale(${c})`,transformOrigin:"top left"};return e.jsx(Lt,{open:s,onOpenChange:n,children:e.jsxs(It,{onOpenAutoFocus:b=>b.preventDefault(),className:"flex h-[min(82vh,44rem)] max-w-[min(92vw,72rem)] flex-col gap-0 overflow-hidden p-0",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border/60 px-3 py-2 pr-9",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(Yt,{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold text-foreground",children:[e.jsx(Va,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0",children:"Preview service"}),e.jsx("span",{className:"min-w-0 truncate font-mono text-[10px] font-medium text-muted-foreground",children:A})]}),e.jsx(an,{className:"sr-only",children:"Preview a service port running on the selected node."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("form",{className:"flex items-center gap-1.5",onSubmit:b=>{b.preventDefault(),N()},children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:["Port",e.jsx(et,{type:"text",min:1,max:65535,inputMode:"numeric",value:r,onChange:b=>o(b.target.value),placeholder:ts,"aria-label":"Node service preview port",className:"h-6 w-20 rounded-sm border-0 bg-muted/55 px-2 text-[11px] shadow-none focus:bg-muted/55 focus:outline-none focus-visible:border-0 focus-visible:bg-muted/55 focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsxs(Z,{type:"submit",variant:"ghost",size:"sm",disabled:h,className:"h-6 rounded-sm border-0 bg-primary/10 px-2 text-[11px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[h?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(js,{className:"h-3.5 w-3.5"}),"Preview"]})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden shrink-0 text-[10px] text-muted-foreground sm:inline",children:Ec(i.expiresAt)}),e.jsxs("div",{className:"flex h-6 shrink-0 items-center overflow-hidden rounded-sm border border-border/55 bg-muted/35",children:[e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>f(b=>na(b,-sa)),disabled:c<=lr,title:"Zoom out","aria-label":"Zoom out preview",children:e.jsx(Ul,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>f(1),className:"h-6 min-w-11 border-x border-border/45 px-1.5 text-center font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted/55 hover:text-foreground",title:"Reset zoom","aria-label":"Reset preview zoom",children:p}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>f(b=>na(b,sa)),disabled:c>=dr,title:"Zoom in","aria-label":"Zoom in preview",children:e.jsx(Fl,{className:"h-3.5 w-3.5"})})]}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:C,title:"Refresh",children:e.jsx(Bo,{className:"h-3.5 w-3.5"})}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",asChild:!0,title:"Open in new tab",children:e.jsx("a",{href:v??i.previewUrl,target:"_blank",rel:"noopener noreferrer",children:e.jsx(nn,{className:"h-3.5 w-3.5"})})})]})]})]}),g&&e.jsx("div",{className:"shrink-0 border-b border-destructive/20 bg-destructive/5 px-3 py-1.5 text-[11px] text-destructive",children:g}),e.jsx("div",{className:"min-h-0 flex-1 p-2",children:i?e.jsx("div",{className:"h-full overflow-hidden rounded-sm border border-border/60 bg-white shadow-none",children:e.jsx("iframe",{src:Zi(i),style:S,className:"h-full w-full border-0",sandbox:Qi(i),title:`${A} Service Preview`})}):e.jsx("div",{className:"flex h-full min-h-56 items-center justify-center rounded-sm border border-dashed border-border/65 bg-background/35 px-3 text-center text-[11px] text-muted-foreground",children:"No service preview running."})})]})})}function na(t,s){return cr(Math.round((t+s)*100)/100)}function cr(t){return Number.isFinite(t)?Math.min(dr,Math.max(lr,t)):1}function _c(t){return`${Math.round(cr(t)*100)}%`}function Ec(t){const s=Math.max(0,Math.round((t-Date.now())/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60),r=s%60;return`${n}m ${r}s`}function Dc({dirPath:t,label:s,taskCount:n,collapsed:r,onToggle:o,onCreateTask:i,onOpenCapabilities:d}){return e.jsxs("div",{className:"group/project-row flex w-full items-stretch rounded-sm bg-muted/15 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.jsxs("button",{type:"button",onClick:o,"aria-expanded":!r,title:t,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-l-sm px-2 py-1 text-left",children:[e.jsx(He,{className:P("h-3 w-3 shrink-0 transition-transform duration-200",!r&&"rotate-90")}),e.jsx(Pt,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:s}),e.jsx("span",{className:"ml-2 shrink-0 rounded-sm bg-background/55 px-1 py-0 tabular-nums text-[8px] font-medium leading-3 text-muted-foreground/45",children:n})]}),d&&e.jsx("button",{type:"button",onClick:d,"aria-label":`Capabilities for ${t}`,title:`Capabilities for ${t}`,className:"pointer-events-none mr-0.5 flex h-4 w-4 shrink-0 translate-y-px self-center items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-all hover:bg-primary/10 hover:text-primary focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/project-row:pointer-events-auto group-hover/project-row:opacity-100",children:e.jsx(vs,{className:"h-2.5 w-2.5"})}),e.jsx("button",{type:"button",onClick:i,"aria-label":`New chat in ${t}`,title:`New chat in ${t}`,className:"pointer-events-none ml-auto flex h-4 w-4 shrink-0 translate-y-px self-center items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-all hover:bg-primary/10 hover:text-primary focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/project-row:pointer-events-auto group-hover/project-row:opacity-100",children:e.jsx(ys,{className:"h-2.5 w-2.5"})})]})}const ur="meshy-task-sidebar-tree-state";function aa(t){return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Bs(){var t;try{return((t=globalThis.window)==null?void 0:t.localStorage)??globalThis.localStorage??null}catch{return null}}function ra(t){if(!t)return{collapsedNodes:[],collapsedDirs:[]};try{const s=t.getItem(ur);if(!s)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(s);return{collapsedNodes:aa(n.collapsedNodes),collapsedDirs:aa(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Ac(t,s){if(t)try{t.setItem(ur,JSON.stringify(s))}catch{}}function oa(t,s){if(!t.has(s))return t;const n=new Set(t);return n.delete(s),n}function Mc(t,s){if(!s)return null;for(const n of t){const r=n.nodeId??"__unassigned__";for(const o of n.dirs)if(o.tasks.some(i=>i.id===s))return{nodeKey:r,dirKey:`${r}::${o.path}`}}return null}function ia(t,s,n){return n?{collapsedNodes:oa(t,n.nodeKey),collapsedDirs:oa(s,n.dirKey)}:{collapsedNodes:t,collapsedDirs:s}}function Pc(t,s,n){const r=t.filter(c=>c.status==="completed"),o=new Set((s?r:[...r].sort((c,f)=>f.updatedAt-c.updatedAt).slice(0,rn)).map(c=>c.id));n&&r.some(c=>c.id===n)&&o.add(n);const i=t.filter(c=>c.status!=="completed"||o.has(c.id)),d=r.length-o.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,d)}}const ns="h-6 rounded-sm border-0 bg-muted/45 px-2 py-0 text-[10px] leading-none text-foreground shadow-none hover:bg-muted/65 focus:bg-muted/65 focus:ring-0 focus:ring-offset-0 [&>svg]:h-3 [&>svg]:w-3",as="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function la({toolbarTasks:t,activeTaskId:s,tasksLoading:n,tasksError:r,isLeader:o,scope:i,agentFilter:d,nodeFilter:c,taskKindFilter:f,agentOptions:h,nodeOptions:y,nodeNameById:g,nodeWorkDirById:l,nodeStatusById:N,completedGroupByKey:C,devBoxNodeIds:v=new Set,devBoxStartNodeIds:A=new Set,devBoxStartingNodeIds:p=new Set,leaderNodeId:S,searchQuery:b,selectedTaskIds:j,allVisibleTasksSelected:w,someVisibleTasksSelected:T,canBatchArchive:D,onScopeChange:U,onAgentFilterChange:E,onNodeFilterChange:F,onTaskKindFilterChange:B,onToggleTaskSelected:Q,onToggleAllVisibleTasks:ee,onBatchArchive:V,onBatchDelete:H,onCreateTask:se,onOpenNodeSettings:ie,onOpenNodeCapabilities:L,onOpenProjectCapabilities:K,onOpenDevBox:_,onStartDevBox:W,onLoadCompletedTasks:x,onSelectTask:z}){const[m,G]=a.useState(!1),[M,q]=a.useState(()=>j.size>0),[k,X]=a.useState(null),{markScrollbarActive:re,scrollbarActive:ce}=nr(),J=j.size,O=!!(o&&(M||J>0)),te=i!=="active"||c!=="all"||d!=="all"||f!=="all",le=b.trim().length>0,[R,ae]=a.useState(()=>new Set(ra(Bs()).collapsedNodes)),[ve,Ee]=a.useState(()=>new Set(ra(Bs()).collapsedDirs)),[nt,at]=a.useState(new Set),Ue=a.useMemo(()=>Ro(t,g,S,l),[t,g,S,l]),je=a.useMemo(()=>Mc(Ue,s),[Ue,s]),it=a.useRef(null),We=Ue.length===1,Me=Ue.length>0,ne=We&&(te||le),we=!!(o&&(Ue.length>0||J>0)),Pe=a.useCallback($=>{ae(Le=>{const Ae=new Set(Le);return Ae.has($)?Ae.delete($):Ae.add($),Ae})},[]),De=a.useCallback($=>{Ee(Le=>{const Ae=new Set(Le);return Ae.has($)?Ae.delete($):Ae.add($),Ae})},[]),lt=a.useCallback($=>{at(Le=>{const Ae=new Set(Le);return Ae.add($),Ae})},[]);a.useEffect(()=>{Ac(Bs(),{collapsedNodes:Array.from(R),collapsedDirs:Array.from(ve)})},[ve,R]),a.useEffect(()=>{if(!je||!s)return;const $=`${s}:${je.nodeKey}:${je.dirKey}`;it.current!==$&&(it.current=$,ae(Le=>ia(Le,new Set,je).collapsedNodes),Ee(Le=>ia(new Set,Le,je).collapsedDirs))},[s,je]);const ye=a.useCallback($=>{q(!0),ee($)},[ee]),qe=a.useCallback(()=>{ee(!1),q(!1)},[ee]);a.useEffect(()=>{o||q(!1)},[o]);const $e=O?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(Kt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:T&&!w?"indeterminate":w,onCheckedChange:$=>ye($===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Multi select"})]}):e.jsxs(Z,{variant:"ghost",size:"sm",onClick:()=>q(!0),className:"h-5 rounded-sm px-1.5 text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75 hover:text-foreground",children:[e.jsx(Fi,{className:"h-3 w-3"}),"Multi select"]}),jt=J>0?e.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"text-[9px] font-semibold leading-3 text-foreground",children:[J," task",J!==1?"s":""," selected"]}),!D&&e.jsx("div",{className:"max-w-48 text-[9px] leading-3.5 text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."})]}):null,Te=J>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(is,{children:[e.jsx(Fs,{asChild:!0,children:e.jsxs(Z,{variant:"ghost",size:"sm",disabled:!D,className:"h-5 gap-1 rounded-sm bg-muted/45 px-1.5 text-[8px] text-foreground/80 shadow-none hover:bg-muted/65 [&_svg]:size-3",children:[e.jsx(Ji,{}),"Archive"]})}),e.jsxs(ls,{children:[e.jsxs(ds,{children:[e.jsxs(cs,{children:["Archive ",J," task",J!==1?"s":"","?"]}),e.jsx(us,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(ms,{children:[e.jsx(xs,{children:"Cancel"}),e.jsx(hs,{onClick:V,disabled:!D,children:"Archive"})]})]})]}),e.jsxs(is,{children:[e.jsx(Fs,{asChild:!0,children:e.jsxs(Z,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(Ba,{}),"Delete"]})}),e.jsxs(ls,{children:[e.jsxs(ds,{children:[e.jsxs(cs,{children:["Delete ",J," task",J!==1?"s":"","?"]}),e.jsx(us,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(ms,{children:[e.jsx(xs,{children:"Cancel"}),e.jsx(hs,{onClick:H,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"dashboard-task-sidebar 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:"dashboard-task-sidebar__header shrink-0 bg-card/24 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex min-w-0 items-stretch gap-1.5",children:[e.jsxs(Z,{onClick:()=>se("chat"),className:"h-8 w-[6.75rem] justify-start rounded-sm px-2.5 text-left text-[11px] shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(ys,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsxs(Z,{variant:"outline",onClick:()=>se("native"),className:"h-8 w-[7.75rem] justify-start rounded-sm border-0 bg-muted/45 px-2.5 text-left text-[11px] text-foreground shadow-none hover:bg-muted/65 hover:text-foreground",children:[e.jsx(ln,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Load session"]})]}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>G($=>!$),className:P("ml-auto h-8 w-8 shrink-0 rounded-sm text-muted-foreground shadow-none hover:bg-muted/55 hover:text-foreground",(m||te)&&"bg-primary/8 text-primary hover:bg-primary/12 hover:text-primary"),title:"Filters",children:e.jsx(xl,{className:"h-3.5 w-3.5"})})]}),(m||te)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(ke,{value:i,onValueChange:$=>U($),children:[e.jsx(Se,{className:ns,children:e.jsx(Be,{})}),e.jsx(Ce,{children:$o.map($=>e.jsx(xe,{value:$.value,className:as,children:$.label},$.value))})]}),e.jsxs(ke,{value:c,onValueChange:F,children:[e.jsx(Se,{className:ns,children:e.jsx(Be,{placeholder:"Node"})}),e.jsx(Ce,{children:y.map($=>e.jsx(xe,{value:$.value,className:as,children:$.label},$.value))})]}),e.jsxs(ke,{value:d,onValueChange:E,children:[e.jsx(Se,{className:ns,children:e.jsx(Be,{placeholder:"Agent"})}),e.jsx(Ce,{children:h.map($=>e.jsx(xe,{value:$,className:as,children:$==="all"?"All agents":$},$))})]}),e.jsxs(ke,{value:f,onValueChange:$=>B($),children:[e.jsx(Se,{className:ns,children:e.jsx(Be,{placeholder:"Type"})}),e.jsx(Ce,{children:Oo.map($=>e.jsx(xe,{value:$.value,className:as,children:$.label},$.value))})]})]})]}),e.jsx("div",{className:P("scrollbar-line min-h-0 flex-1 overflow-y-auto pl-2.5 pr-1.5 py-2",ce&&"scrollbar-line-active"),onScroll:re,children:Ue.length>0?e.jsx("div",{className:"space-y-1",children:Ue.map($=>{const Le=$.nodeId??"__unassigned__",Ae=$.dirs.reduce((Ie,ze)=>Ie+ze.tasks.length,0),dt=Me&&!ne&&R.has(Le),pt=$.nodeId!==null&&N.get($.nodeId)==="offline",wt=!!(o&&$.nodeId);return e.jsxs("div",{className:"space-y-1",children:[Me&&e.jsxs("div",{className:"flex w-full items-stretch rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 text-left text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsxs("button",{type:"button",onClick:()=>Pe(Le),"aria-expanded":!dt,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(He,{className:P("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!dt&&"rotate-90")}),e.jsx(Sa,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:$.nodeName}),e.jsxs(Fe,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-transparent bg-background/55 px-1.5 py-0 text-[7px] font-semibold leading-3.5 text-muted-foreground shadow-none normal-case tracking-normal",children:[Ae," task",Ae===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[pt&&e.jsx(Fe,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/10 px-1 py-0 text-[8px] font-semibold leading-3 text-destructive shadow-none",children:"offline"}),$.nodeId===S&&e.jsx(Fe,{variant:"outline",className:"rounded-sm border-transparent bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"})]})]}),wt&&$.nodeId&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(mn,{nodeId:$.nodeId,nodeName:$.nodeName,onOpenSettings:ie,onOpenServicePreview:()=>X({id:$.nodeId,name:$.nodeName}),onOpenCapabilities:L,onOpenDevBox:_,onStartDevBox:W,showConfigureDevBox:v.has($.nodeId),showStartDevBox:A.has($.nodeId)||p.has($.nodeId),startDevBoxPending:p.has($.nodeId)})})]}),e.jsx("div",{className:P("grid transition-[grid-template-rows] duration-300 ease-in-out",dt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:$.dirs.map(Ie=>{const ze=`${Le}::${Ie.path}`,yt=ve.has(ze),ft=Ia(Ie.path),Ge=C==null?void 0:C.get(ze),mt=Ge?{visibleTasks:Ie.tasks,hiddenCompletedCount:Math.max(0,Ge.total-Ge.returned)}:Pc(Ie.tasks,nt.has(ze),s),{visibleTasks:Nt,hiddenCompletedCount:ct}=mt;return e.jsxs("div",{className:P("space-y-0.5 rounded-xl",Me&&"pl-2.5"),children:[e.jsx(Dc,{dirPath:Ie.path,label:ft,taskCount:Ie.tasks.length,collapsed:yt,onToggle:()=>De(ze),onCreateTask:()=>se("chat",{assignTo:$.nodeId,project:Ie.path==="default workspace"?"":Ie.path}),onOpenCapabilities:$.nodeId&&K?()=>K($.nodeId,Ie.path==="default workspace"?(l==null?void 0:l.get($.nodeId))??Ie.path:Ie.path):void 0}),e.jsx("div",{className:P("grid transition-[grid-template-rows] duration-300 ease-in-out",yt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:P("overflow-hidden",Me?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[Nt.map(Ne=>{const _e=Ne.id===s,ut=Ne.assignedTo?N.get(Ne.assignedTo):void 0,kt=!!Ne.assignedTo&&(ut?ut==="offline":Ne.assignedNodeAvailable===!1);return e.jsxs("div",{className:P("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",_e?'bg-primary/10 before:absolute before:left-0 before:top-1/2 before:h-1/2 before:w-[2px] before:-translate-y-1/2 before:rounded-full before:bg-primary before:content-[""]':"hover:bg-muted/40"),children:[O&&e.jsx("div",{className:"flex shrink-0",onClick:fe=>fe.stopPropagation(),children:e.jsx(Kt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:j.has(Ne.id),onCheckedChange:fe=>Q(Ne.id,fe===!0),"aria-label":`Select ${Ne.title}`})}),e.jsxs("button",{type:"button",onClick:()=>z(Ne.id),"aria-current":_e?"page":void 0,className:"relative min-w-0 flex-1 pr-8 text-left",children:[e.jsx("div",{className:"flex items-center gap-1.5 pr-1",children:e.jsx("span",{className:P("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",_e?"text-foreground":"text-foreground/80"),children:Ne.title})}),e.jsx("span",{className:P("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",_e?"text-primary/75":"text-muted-foreground/55"),children:Fo(Ne.updatedAt)}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5",children:[e.jsx("span",{className:"rounded-sm bg-muted/35 px-1 py-0 font-mono text-[8px] leading-3 text-muted-foreground/65",children:Ne.agent}),Ne.activeShare&&e.jsx(Fe,{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"}),kt&&e.jsx(Fe,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/8 px-1 py-0 text-[8px] leading-3 text-destructive shadow-none",children:"unavailable"})]}),e.jsx(Da,{status:Ne.status,isNative:Ne.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},Ne.id)}),ct>0&&e.jsxs("button",{type:"button",onClick:()=>{Ge&&x?x(Ge):lt(ze)},className:"mt-1 flex w-full items-center justify-center gap-1 rounded-sm border border-dashed border-border/55 bg-background/35 px-2 py-1 text-[9px] font-medium text-muted-foreground transition-colors hover:border-primary/35 hover:bg-primary/8 hover:text-primary","aria-label":`Load ${ct} more completed tasks in ${ft}`,children:[e.jsx(st,{className:"h-3 w-3"}),"Load ",ct," more completed"]})]})})})]},ze)})})})]},Le)})}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map($=>e.jsx("div",{className:"rounded-xl border border-border/40 bg-background/30 px-3 py-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"mt-1 h-2.5 w-2.5 shrink-0 animate-pulse rounded-full bg-muted-foreground/20"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-2.5 animate-pulse rounded-full bg-muted-foreground/15",style:{width:`${60+$*12}%`,animationDelay:`${$*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${$*120+60}ms`}})]})]})},$))}):e.jsx("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-3 py-5 text-[11px] text-muted-foreground",children:r||"No tasks match this view."})}),we?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:O&&J>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[jt,e.jsx(Z,{variant:"ghost",size:"sm",onClick:qe,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Clear"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:$e}),Te]})]}):e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:$e}),O&&e.jsx(Z,{variant:"ghost",size:"sm",onClick:qe,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]}),e.jsx(Tc,{node:k,open:k!==null,onOpenChange:$=>{$||X(null)}})]})}async function Lc(t,s){var n,r;try{const o=await zo(t,s),i={...o,url:_a(o.url)};if((r=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&r.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),de.success("Shared link copied")}catch{de.success("Shared link created")}else de.success("Shared link created");return i}catch(o){de.error(o instanceof Error?o.message:"Failed to create shared link");return}}async function Ic(t){try{return await Uo(t),de.success("Shared link stopped"),!0}catch(s){return de.error(s instanceof Error?s.message:"Failed to stop shared link"),!1}}function Bc(t,s,n){const r=a.useCallback(()=>{s(),n()},[s,n]),o=a.useCallback(async d=>{if(!t)return;const c=await Lc(t.id,d);return c&&r(),c},[t,r]),i=a.useCallback(async()=>{if(!t)return!1;const d=await Ic(t.id);return d&&r(),d},[t,r]);return{handleShareTask:o,handleStopShareTask:i}}function da(t,s,n){const r=a.useRef(s);r.current=s,a.useEffect(()=>{let d=0,c=0;const f=g=>{const l=g.touches[0];l&&(d=l.clientX,c=l.clientY)},h=g=>{var v,A,p,S;const l=g.changedTouches[0];if(!l)return;const N=l.clientX-d;Math.abs(l.clientY-c)>100||Math.abs(N)<50||(N>0?(A=(v=r.current).onSwipeRight)==null||A.call(v):(S=(p=r.current).onSwipeLeft)==null||S.call(p))},y=(t==null?void 0:t.current)??document;return y.addEventListener("touchstart",f,{passive:!0}),y.addEventListener("touchend",h,{passive:!0}),()=>{y.removeEventListener("touchstart",f),y.removeEventListener("touchend",h)}},[t,n==null?void 0:n.threshold,n==null?void 0:n.maxVertical])}const Rc="(min-width: 1024px)",$c="(min-width: 1800px)";function ca(t){var s,n,r;return((r=(n=(s=globalThis.window)==null?void 0:s.matchMedia)==null?void 0:n.call(s,t))==null?void 0:r.matches)??!1}function Oc(){var n,r;const t=(n=globalThis.document)==null?void 0:n.documentElement;if(!t||!((r=globalThis.window)!=null&&r.getComputedStyle))return 16;const s=Number.parseFloat(globalThis.window.getComputedStyle(t).fontSize);return Number.isFinite(s)&&s>0?s:16}function Fc(){const[t,s]=a.useState(()=>Vo(An(),Ho({operationsOpen:ca($c)}))),[n,r]=a.useState(!1),o=a.useRef(null),i=a.useRef(null),d=a.useRef(null),c=t.layout.desktopTasksOpen,f=t.layout.operationsOpen,h=t.sizes;a.useEffect(()=>{qo(An(),t)},[t]);const y=a.useCallback((A,p)=>{s(S=>{const b=S.layout[A],j=typeof p=="function"?p(b):p;return j===b?S:{...S,layout:{...S.layout,[A]:j}}})},[]),g=a.useCallback(A=>{y("desktopTasksOpen",A)},[y]),l=a.useCallback(A=>{y("operationsOpen",A)},[y]);da(i,{onSwipeLeft:()=>r(!1)}),da(d,{onSwipeRight:()=>l(!1)});const N=a.useCallback(()=>{if(ca(Rc)){g(A=>!A);return}r(A=>!A)},[g]);a.useEffect(()=>{var S,b,j;const A=w=>{const T=o.current;if(!T)return;w.preventDefault();const D=Wo(T.panel,T.startSize,T.startClientX,T.startClientY,w.clientX,w.clientY,T.rootFontSize);s(U=>({...U,sizes:{...U.sizes,[T.panel]:D}}))},p=()=>{o.current=null};return(S=globalThis.window)==null||S.addEventListener("pointermove",A),(b=globalThis.window)==null||b.addEventListener("pointerup",p),(j=globalThis.window)==null||j.addEventListener("pointercancel",p),()=>{var w,T,D;(w=globalThis.window)==null||w.removeEventListener("pointermove",A),(T=globalThis.window)==null||T.removeEventListener("pointerup",p),(D=globalThis.window)==null||D.removeEventListener("pointercancel",p)}},[]);const C=a.useCallback((A,p)=>{var S,b;p.preventDefault(),(b=(S=p.currentTarget).setPointerCapture)==null||b.call(S,p.pointerId),o.current={panel:A,startSize:h[A],startClientX:p.clientX,startClientY:p.clientY,rootFontSize:Oc()}},[h]),v=a.useCallback((A,p)=>{p.preventDefault(),s(S=>({...S,sizes:{...S.sizes,[A]:Ko(A,S.sizes[A],p.deltaY)}}))},[]);return{desktopTasksOpen:c,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:f,operationsPanelRef:d,panelResize:{sizes:{tasks:As(h.tasks),operations:As(h.operations),terminal:As(h.terminal)},onPointerDown:C,onWheel:v},setMobileTasksPanelOpen:r,setOperationsOpen:l,toggleTasksPanel:N}}function zc(t,s){const n=s.taskId,r=s.updates;return typeof n!="string"||!r||typeof r!="object"?t:t.map(o=>o.id===n?{...o,...r}:o)}const Uc="notify_desktop_task";function Vc(t=mr()){var n,r;const s=(r=(n=t==null?void 0:t.__TAURI__)==null?void 0:n.core)==null?void 0:r.invoke;return typeof s=="function"?s:null}async function Hc(t,s=mr()){const n=Vc(s);return n?(await n(Uc,t),!0):!1}function qc(t,s){const n=[];for(const r of s){const o=Kc(r.status);if(!o)continue;const i=t.get(r.id);!i||i.status===r.status||n.push({taskId:r.id,title:r.title.trim()||"Meshy task",status:o,assignedNodeName:r.assignedNodeName??null,projectPath:r.effectiveProjectPath??r.project??null})}return n}function Kc(t){return t==="completed"||t==="failed"?t:null}function mr(){return typeof window>"u"?null:window}function Wc({isLeader:t,selfId:s}){return{...!t&&s?{assignedTo:s}:{},completedLimitPerProject:rn}}function Xs(t){return`${t.assignedTo??"__unassigned__"}::${t.projectPath}`}function Gc(t,s){const n=new Map(t.map(r=>[r.id,r]));for(const r of s)n.set(r.id,r);return Array.from(n.values())}function Yc(t,s,n=new Set){return!s||n.has(s.id)||t.some(r=>r.id===s.id)?t:Ga(t,s)}function Qc({isLeader:t,selfId:s,sseConnected:n,preservedTask:r,subscribe:o}){const[i,d]=a.useState([]),[c,f]=a.useState([]),[h,y]=a.useState(!0),[g,l]=a.useState(null),N=a.useRef(new Set),C=a.useRef(null),v=a.useRef(null),A=a.useCallback(async()=>{try{const j=await Mn(Wc({isLeader:t,selfId:s}));d(Yc(j.tasks,r,N.current)),f(j.completedGroups??[]),l(null)}catch(j){l(j instanceof Error?j.message:"Failed to load tasks")}finally{y(!1)}},[t,r,s]),p=a.useCallback(async j=>{if(!j.hasMore||!j.nextCursor)return;const w=await Mn({status:"completed",assignedTo:j.assignedTo??"__unassigned__",projectPath:j.projectPath,cursor:j.nextCursor,limit:rn});d(T=>Gc(T,w.tasks)),f(T=>T.map(D=>Xs(D)===Xs(j)?{...D,returned:Math.min(D.total,D.returned+w.tasks.length),hasMore:w.hasMore===!0,nextCursor:w.nextCursor??null}:D))},[]),S=a.useCallback(()=>{v.current===null&&(v.current=window.setTimeout(()=>{v.current=null,A()},Go))},[A]),b=a.useCallback(j=>{const w=new Set(j);if(w.size!==0){for(const T of w)N.current.add(T);d(T=>T.filter(D=>!w.has(D.id)))}},[]);return Yo(A,Xo(n)),a.useEffect(()=>()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]),a.useEffect(()=>{const j=C.current;if(j)for(const w of qc(j,i))Hc(w).catch(()=>{});C.current=new Map(i.map(w=>[w.id,w]))},[i]),a.useEffect(()=>{const j=[o("task.updated",w=>{d(T=>zc(T,w.data))}),o("task.status",w=>{d(T=>Qo(T,w.data))}),o("node",w=>{Pn(w.type)&&S()}),o("task",w=>{if(w.type==="task.deleted"){const T=w.data.taskId;typeof T=="string"&&N.current.add(T),d(D=>Zo(D,w.data))}Pn(w.type)&&S()})];return()=>j.forEach(w=>w())},[o,S]),{completedGroups:c,fetchTasks:A,loadCompletedTasksPage:p,removeTasksFromList:b,setTasks:d,tasks:i,tasksError:g,tasksLoading:h}}function xr(t){return t.map(s=>({...s}))}function Zc(t,s){const n=s.get(t);return{logs:n?xr(n.logs):[],transcriptLoading:(n==null?void 0:n.loaded)!==!0}}function Xc(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function Jc(t,s){const n=t.data.name;if(typeof n=="string"&&n.length>0)return n;const r=t.data.nodeId;return typeof r=="string"?(s==null?void 0:s.get(r))??r:"node"}function eu({cluster:t,subscribe:s}){a.useEffect(()=>{var r;if(((r=t==null?void 0:t.self)==null?void 0:r.role)!=="leader")return;const n=new Map(t.nodes.map(o=>[o.id,o.name]));return n.set(t.self.id,t.self.name),s("node",o=>{const i=Jc(o,n),d=Xc(t,o);o.type==="node.joined"&&!d&&de.success(`${i} joined the cluster`),o.type==="node.left"&&!d&&de.message(`${i} left the cluster`)})},[t,s])}const tu=[0,300,1e3,2e3];function su({task:t,getActiveTaskId:s,setLogs:n,setPendingMessages:r,setTranscriptLoading:o}){t.conversationKind==="nativeSession"&&(async()=>{try{for(const i of tu){if(i>0&&await new Promise(d=>setTimeout(d,i)),s()!==t.id)return;try{const d=await zs(t.id);if(s()!==t.id||(n(c=>za(c,d.logs)),r(c=>Vs(c,d.logs)),d.total>0))return}catch{}}}finally{s()===t.id&&(o==null||o(!1))}})()}function nu(t,s){return Re(t??{})===Re(s??{})}function au(t){return t&&"status"in t&&typeof t.status=="string"?t.status:void 0}function ua(t,s){return{...t,enabled:!0,alwaysOnline:s}}function hr(t){var s,n;return((s=t==null?void 0:t.status)==null?void 0:s.trim())||((n=t==null?void 0:t.lastStatus)==null?void 0:n.trim())||"Unknown"}function ru({operationStarting:t,loading:s,refreshing:n,savedStatus:r,fallbackStatus:o}){return t?"Starting":s?"Listing DevBoxes":n?"Refreshing":r??o}function ma({devbox:t,showStatus:s=!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:t.name}),t.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",t.projectName]})]}),s&&e.jsx("span",{className:"ml-auto shrink-0 rounded-sm border border-border/70 bg-background/70 px-1.5 py-0 text-[10px] leading-none text-muted-foreground",children:hr(t)})]})}function ou({node:t,open:s,startInProgress:n=!1,onOpenChange:r,onRefresh:o}){const i=(t==null?void 0:t.id)??null,d=s&&!n&&Jn(t==null?void 0:t.status,(t==null?void 0:t.devbox)??null),[c,f]=a.useState([]),[h,y]=a.useState(()=>t!=null&&t.devbox?Re(t.devbox):""),[g,l]=a.useState(()=>(t==null?void 0:t.devbox)??null),[N,C]=a.useState(()=>ea((t==null?void 0:t.devbox)??null)),[v,A]=a.useState(!1),[p,S]=a.useState(d),[b,j]=a.useState(!1),[w,T]=a.useState(!1),[D,U]=a.useState(()=>{var k;return((k=t==null?void 0:t.devbox)==null?void 0:k.alwaysOnline)===!0}),E=a.useMemo(()=>{const k=c.find(X=>Re(X)===h);return k||(At(g)&&Re(g)===h?g:void 0)},[g,c,h]),F=au(E??void 0),B=N?F??(g==null?void 0:g.lastStatus):(g==null?void 0:g.lastStatus)??F,Q=(t==null?void 0:t.status)==="online"||(t==null?void 0:t.status)==="busy"?"Running":"Unknown",ee=w||n,V=ru({operationStarting:ee,loading:v,refreshing:p,savedStatus:B,fallbackStatus:Q}),H=N&&!!E&&!nu(g,E),se=(g==null?void 0:g.alwaysOnline)===!0!==D,ie=yc({nodeStatus:t==null?void 0:t.status,status:V,current:g,selected:E}),L=!!ie,K=!!E&&(H||se)&&!L,_=E??g,W=a.useCallback(async()=>{if(i){S(!0);try{const k=await Jo(i);l(k.devbox),y(Re(k.devbox))}catch(k){de.error(k instanceof Error?k.message:"Failed to refresh DevBox status")}finally{S(!1)}}},[i]),x=a.useCallback(async k=>{A(!0);try{const X=await ei();f(X),y(re=>Nc({previousKey:re,baseDevBox:k,listed:X}))}catch(X){de.error(X instanceof Error?X.message:"Failed to load DevBoxes")}finally{A(!1)}},[]);a.useEffect(()=>{if(!s||!i)return;let k=!1;const X=(t==null?void 0:t.devbox)??null,re=ea(X),ce=!n&&Jn(t==null?void 0:t.status,X);A(!1),S(ce),C(re),l(X),U((X==null?void 0:X.alwaysOnline)===!0),y(At(X)?Re(X):""),f([]);async function J(){ce&&await W(),!k&&re&&await x(X)}return J(),()=>{k=!0}},[x,t==null?void 0:t.devbox,t==null?void 0:t.status,i,s,W,n]);async function z(){C(!0),c.length===0&&await x(g)}async function m(){if(!(!t||!E)){j(!0);try{const k=await Ln(t.id,ua(E,D));l(k.node.devbox??null),k.node.devbox&&y(Re(k.node.devbox)),C(!1),de.success(`Configured DevBox for ${t.name}`),await(o==null?void 0:o())}catch(k){de.error(k instanceof Error?k.message:"Failed to configure DevBox")}finally{j(!1)}}}async function G(){if(!(!t||!ie)){T(!0);try{if(E&&(H||se)){const X=await Ln(t.id,ua(E,D));l(X.node.devbox??null),X.node.devbox&&y(Re(X.node.devbox)),C(!1)}const{operation:k}=await Ra(t.id);l(X=>X&&{...X,lastStatus:"Starting",checkedAt:Date.now(),operationId:k.id}),de.success(`Start requested for ${t.name}`),await(o==null?void 0:o())}catch(k){de.error(k instanceof Error?k.message:"Failed to start DevBox")}finally{T(!1)}}}const M=v?"Loading DevBoxes...":c.length===0?"No DevBoxes available":"Select a DevBox",q=V==="Running"&&(t==null?void 0:t.status)==="offline";return e.jsx(Lt,{open:s,onOpenChange:r,children:e.jsxs(It,{className:"max-w-md gap-3 rounded-sm p-4",children:[e.jsxs(sn,{className:"space-y-1",children:[e.jsx(Yt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(an,{className:"text-xs",children:["Bind ",t!=null&&t.name?e.jsx("span",{className:"font-medium text-foreground",children:t.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:[(N||_)&&e.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 rounded-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:N?e.jsxs(ke,{value:h,onValueChange:y,disabled:v||b||w||c.length===0,children:[e.jsx(Se,{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:v&&!E?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"}),M]}):E?e.jsx(ma,{devbox:E}):e.jsx(Be,{placeholder:M})}),e.jsx(Ce,{children:c.map(k=>e.jsx(xe,{value:Re(k),textValue:`${k.name} ${k.projectName??""} ${hr(k)}`,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(ma,{devbox:k,showStatus:!0})},Re(k)))})]}):_&&e.jsxs("div",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:_.name}),_.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",_.projectName]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Fe,{variant:"outline",className:"rounded-sm px-1.5 py-0 text-[10px]",children:[(v||p)&&e.jsx(ue,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),V]}),(g==null?void 0:g.name)&&e.jsx(Z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{z()},disabled:v||b||ee||N,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-sm text-muted-foreground hover:text-foreground",children:v&&N?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Bt,{className:"h-3 w-3"})})]})]}),q&&e.jsx("div",{className:"rounded-sm 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-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(Kt,{checked:D,onCheckedChange:k=>U(k===!0),disabled:b||w||ee,"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(Aa,{className:"gap-2 sm:space-x-0",children:[e.jsx(Z,{variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:b||w,className:"h-8 rounded-sm text-xs",children:"Close"}),L&&e.jsxs(Z,{size:"sm",onClick:G,disabled:w,className:"h-8 rounded-sm text-xs",children:[w?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(js,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!L&&e.jsxs(Z,{size:"sm",onClick:m,disabled:!K||b,className:"h-8 rounded-sm text-xs",children:[b&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function iu(t,s=ti){if(t.length===0)return new Set;const n=new Set(t),[r,o]=await Promise.all([s({kind:"devbox.start",status:"queued"}),s({kind:"devbox.start",status:"running"})]);return new Set([...r,...o].filter(i=>n.has(i.nodeId)).map(i=>i.nodeId))}function lu({cluster:t,refresh:s}){const[n,r]=a.useState(null),[o,i]=a.useState(null),[d,c]=a.useState(()=>new Set),[f,h]=a.useState(()=>new Set),y=a.useMemo(()=>(t==null?void 0:t.nodes.find(p=>p.id===n))??null,[t==null?void 0:t.nodes,n]),g=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(p=>{var S;return(S=p.devbox)==null?void 0:S.enabled}).map(p=>p.id)),[t==null?void 0:t.nodes]),l=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(p=>{var S;return Ns(p.status,(S=p.devbox)==null?void 0:S.lastStatus,p.devbox)}).map(p=>p.id)),[t==null?void 0:t.nodes]),N=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(p=>{var S;return Mt((S=p.devbox)==null?void 0:S.lastStatus)}).map(p=>p.id)),[t==null?void 0:t.nodes]),C=a.useMemo(()=>{const p=new Set(d);o&&p.add(o);for(const S of f)p.add(S);for(const S of N)p.add(S);return p},[f,o,d,N]);a.useEffect(()=>{let p=!1;const S=[...g];async function b(){try{const j=await iu(S);p||h(j)}catch{p||h(new Set)}}return b(),()=>{p=!0}},[g]),a.useEffect(()=>{c(p=>{var j;let S=!1;const b=new Set(p);for(const w of p){const T=t==null?void 0:t.nodes.find(D=>D.id===w);(T==null?void 0:T.status)!=="online"&&(!((j=T==null?void 0:T.devbox)!=null&&j.lastStatus)||Mt(T.devbox.lastStatus))||(b.delete(w),S=!0)}return S?b:p})},[t==null?void 0:t.nodes]);const v=a.useCallback(async p=>{const S=t==null?void 0:t.nodes.find(b=>b.id===p);if(S){i(p),c(b=>new Set(b).add(p));try{await Ra(p),de.success(`Start requested for ${S.name}`),s()}catch(b){c(j=>{const w=new Set(j);return w.delete(p),w}),de.error(b instanceof Error?b.message:"Failed to start DevBox")}finally{i(null)}}},[t==null?void 0:t.nodes,s]);return{devBoxDialog:e.jsx(ou,{node:y,open:n!==null,startInProgress:y?C.has(y.id):!1,onOpenChange:p=>{p||r(null)},onRefresh:s}),devBoxNodeIds:g,devBoxStartNodeId:o,devBoxStartNodeIds:l,devBoxStartingNodeIds:C,openDevBox:r,startDevBox:v}}function du(t){const[s,n]=a.useState(null),r=a.useCallback(i=>{t&&n(i)},[t]);return{nodeSettingsDialog:e.jsx(si,{open:s!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:s??void 0,showTrigger:!1}),openNodeSettings:r}}function cu(t=!1){return!t}function uu({activeTaskId:t,fetchActiveTask:s,isRunning:n=!1,setPendingMessages:r,setTask:o,setTasks:i}){const d=a.useCallback((h,y)=>{o(g=>g&&g.id===h?{...g,queuedMessages:y}:g),i(g=>g.map(l=>l.id===h?{...l,queuedMessages:y}:l))},[o,i]),c=a.useCallback(async h=>{if(!t)return!1;const y=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`,g=cu(n);g&&r(l=>[...l,{id:y,content:h,timestamp:new Date().toISOString()}]);try{const l=await ni(t,h);return l.queued&&(g&&r(N=>N.filter(C=>C.id!==y)),l.queuedMessages&&d(t,l.queuedMessages)),s(),!0}catch(l){return g&&r(N=>N.filter(C=>C.id!==y)),de.error(l instanceof Error?l.message:"Failed to send message"),!1}},[t,s,n,r,d]);return{cancelQueuedMessage:a.useCallback(async h=>{if(t)try{const y=await ai(t,h);d(t,y.queuedMessages),s()}catch(y){de.error(y instanceof Error?y.message:"Failed to cancel queued message")}},[t,s,d]),queueFollowUpMessage:c}}const xa="grid-cols-[1.5rem_5.25rem_4rem_minmax(8rem,1fr)_4rem_4rem_6rem]",mu={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function xu(t,s){const n=s.search.trim().toLowerCase();return t.filter(r=>s.agent!=="all"&&r.agent!==s.agent||s.kind!=="all"&&r.kind!==s.kind?!1:n?[r.name,r.description,r.source,r.version,r.agent,r.kind].some(o=>o==null?void 0:o.toLowerCase().includes(n)):!0)}function pr(t){return t.kind==="mcp"?"-":t.sizeBytes<1024?`${t.sizeBytes} B`:t.sizeBytes<1024*1024?`${Math.round(t.sizeBytes/1024)} KB`:`${(t.sizeBytes/1024/1024).toFixed(1)} MB`}function hu({items:t,selectedIds:s,activeId:n,onToggleSelected:r,onOpenDetail:o}){return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden rounded-sm border border-border/60 bg-card/35",children:[e.jsxs("div",{className:P("grid shrink-0 gap-2 border-b border-border/55 bg-primary/6 px-2 py-1.5 text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",xa),children:[e.jsx("span",{}),e.jsx("span",{children:"Agent"}),e.jsx("span",{children:"Kind"}),e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Ver"}),e.jsx("span",{children:"Size"}),e.jsx("span",{children:"Source"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:t.length>0?t.map(i=>e.jsxs("button",{type:"button",onClick:()=>o(i),className:P("grid h-7 w-full items-center gap-2 border-b border-border/30 px-2 text-left text-[10px] transition-colors hover:bg-primary/6",xa,n===i.id&&"bg-primary/10 text-primary shadow-[inset_2px_0_0_hsl(var(--primary))]"),children:[e.jsx("span",{onClick:d=>d.stopPropagation(),children:e.jsx(Kt,{className:"h-3 w-3",checked:s.has(i.id),onCheckedChange:d=>r(i.id,d===!0),"aria-label":`Select ${i.name}`})}),e.jsx(pu,{agent:i.agent}),e.jsx("span",{children:i.kind}),e.jsx("span",{className:"truncate font-medium text-foreground",children:i.name}),e.jsx("span",{className:"truncate text-muted-foreground",children:i.version??"-"}),e.jsx("span",{className:"truncate text-muted-foreground",children:pr(i)}),e.jsx("span",{className:"truncate text-muted-foreground",children:i.source??"local"})]},i.id)):e.jsx("div",{className:"px-3 py-8 text-center text-[11px] text-muted-foreground",children:"No capabilities match this view."})})]})}function pu({agent:t}){const s=mu[t];return e.jsx("span",{className:"block min-w-0 truncate text-[10px] font-medium leading-3 text-muted-foreground",title:s,children:s})}const ha=320,pa=560,fr=384,fa=360;function fu(t,s=pa+fa){const n=Math.max(ha,Math.min(pa,s-fa));return Math.min(Math.max(Math.round(t),ha),n)}function gu(t,s,n,r){return fu(t+s-n,r)}function bu({detail:t,deleting:s=!1,onDelete:n,desktopWidth:r=fr,pending:o=!1}){const i={"--capability-detail-width":`${r}px`};if(!t)return e.jsx("aside",{"data-capability-detail-panel":"true",style:i,className:"hidden min-h-0 shrink-0 animate-panel-settle bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-3 text-[11px] text-muted-foreground lg:block lg:w-[var(--capability-detail-width)]",children:o?"Loading capability metadata...":"No capability selected."});const d=t.kind==="mcp"?"mcp":"files";return e.jsxs("aside",{"data-capability-detail-panel":"true",style:i,className:"flex min-h-0 w-full shrink-0 animate-panel-settle flex-col bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-2.5 lg:w-[var(--capability-detail-width)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold leading-5 text-foreground",children:t.name}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-1",children:[e.jsx(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary",children:t.agent}),e.jsx(Fe,{variant:"outline",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary/90",children:t.kind})]})]}),n&&e.jsxs(is,{children:[e.jsx(Fs,{asChild:!0,children:e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground hover:text-destructive","aria-label":"Delete capability",title:"Delete capability",disabled:s,children:e.jsx(Ba,{className:"h-3.5 w-3.5"})})}),e.jsxs(ls,{className:"max-w-[22rem] gap-2 rounded-xl p-4",children:[e.jsxs(ds,{className:"space-y-1",children:[e.jsxs(cs,{className:"text-sm",children:["Delete ",t.name,"?"]}),e.jsxs(us,{className:"text-[11px] leading-4",children:["This removes the selected ",t.kind," from ",t.scope.kind==="global"?"the user profile":"this project","."]})]}),e.jsxs(ms,{className:"gap-1 pt-0 sm:space-x-1",children:[e.jsx(xs,{className:"h-7 rounded-lg px-2 text-[11px]",children:"Cancel"}),e.jsx(hs,{className:"h-7 rounded-lg px-2 text-[11px]",onClick:n,disabled:s,children:"Delete"})]})]})]})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-1 text-[9px]",children:[e.jsx(rs,{label:"Version",value:t.version??"-"}),e.jsx(rs,{label:"Size",value:pr(t)}),e.jsx(rs,{label:"Files",value:String(t.fileCount)}),e.jsx(rs,{label:"Source",value:t.source??"local"})]}),e.jsxs(en,{defaultValue:d,className:"mt-2 flex min-h-0 flex-1 flex-col",children:[e.jsxs(Js,{className:"grid h-auto grid-cols-2 rounded-sm bg-primary/8 p-0.5",children:[t.kind==="mcp"?e.jsx(bt,{value:"mcp",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"MCP"}):e.jsx(bt,{value:"files",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"Files"}),e.jsx(bt,{value:"readme",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"README"})]}),t.kind==="mcp"?e.jsx(ot,{value:"mcp",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(vu,{detail:t})}):e.jsx(ot,{value:"files",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(ju,{detail:t})}),e.jsx(ot,{value:"readme",className:"mt-2 min-h-0 flex-1 overflow-auto",children:t.readmeMarkdown?e.jsx(Gi,{content:t.readmeMarkdown,className:"overflow-hidden rounded-sm border-0 bg-background/70 shadow-none [&>div:first-child>div]:border-0 [&>div:first-child]:border-b-0",previewClassName:"px-3 py-2 text-[11px] leading-5",rawClassName:"text-[10px] leading-4"}):e.jsx(xn,{children:"No README content."})})]},t.id)]})}function vu({detail:t}){const s=t.mcpPreview??[];return s.length===0?e.jsx(xn,{children:"No MCP entries."}):e.jsx("div",{className:"space-y-1.5",children:s.map(n=>e.jsxs("div",{className:"rounded-sm bg-card/72 p-2 text-[10px] shadow-none",children:[e.jsx("div",{className:"font-semibold text-foreground",children:n.serverName}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto rounded-sm bg-background/55 px-2 py-1 whitespace-pre-wrap break-all font-mono text-[9px] leading-4 text-muted-foreground",children:JSON.stringify(n.config,null,2)})]},n.serverName))})}function ju({detail:t}){const s=t.fileTree??[];return s.length===0?e.jsx(xn,{children:"No files."}):e.jsx("div",{className:"space-y-1 overflow-auto rounded-sm bg-card/72 p-2 font-mono text-[9px] leading-4 text-muted-foreground shadow-none",children:s.map(n=>e.jsx("div",{children:n.relPath},n.relPath))})}function xn({children:t}){return e.jsx("div",{className:"rounded-sm bg-primary/5 px-2 py-6 text-center text-[10px] text-muted-foreground",children:t})}function rs({label:t,value:s}){return e.jsxs("div",{className:"rounded-sm bg-card/72 px-2 py-0.5 shadow-none",children:[e.jsx("div",{className:"text-[7px] uppercase tracking-[0.14em] text-muted-foreground",children:t}),e.jsx("div",{className:"truncate text-[9px] font-medium text-foreground",children:s})]})}const wu=20,yu=288,Nu=360,ku=440;function Su(){if(typeof window>"u"||typeof document>"u")return 1;const t=window.getComputedStyle(document.documentElement),s=t.zoom||t.getPropertyValue("--ui-zoom"),n=Number.parseFloat(s);return Number.isFinite(n)&&n>0?n:1}function Cu({triggerRect:t,targetRect:s,viewportRect:n,compact:r,browserOpen:o=!1,portalAlign:i,cssZoom:d=1}){const c=Number.isFinite(d)&&d>0?d:1,f=8,h=n.top+f,y=n.bottom-f,g=n.left+f,l=n.right-f,N=Math.max(0,y-t.bottom-4),C=Math.max(0,t.top-h-4),v=r?C<140&&N>C:N>=220||N>=C,A=v?N:C,p=Math.max(140,y-h),S=r&&o,w=Math.min(p,S?ku:320,Math.max(S?Nu:140,A)),T=yu*c,D=i==="end"?t.right-T:t.left,E=(Math.max(g,Math.min(D,l-T))-s.left)/c;if(!v&&!S)return{left:E,bottom:(s.bottom-(t.top-4))/c,maxHeight:w/c};const F=v?t.bottom+4:t.top-w-4,B=Math.max(h,Math.min(F,y-w));return{left:E,top:(B-s.top)/c,maxHeight:w/c}}function hn(t){if(!t.workDir)return[];const s=[],n=new Set,r=o=>{!o||n.has(o)||(n.add(o),s.push(o))};r(t.workDir);for(const o of t.workDirFolders??[])r(br(o)?o:vr(t.workDir,o));return s}function Tu(t,s){if(t.kind==="global")return{nodeId:s.id,scope:{kind:"global"}};const n=hn(s),r=n.find(o=>o===t.projectPath);return r?{nodeId:s.id,scope:{kind:"project",projectPath:r}}:n[0]?{nodeId:s.id,scope:{kind:"project",projectPath:n[0]}}:{nodeId:s.id,scope:{kind:"global"}}}function _u(t,s){return{nodeId:t,scope:s}}function ga(t,s,n){const r=s.trim();return!r||r==="."?t.workDir??r:n||br(r)?r:t.workDir?vr(t.workDir,r):r}function Eu({node:t,scope:s,clusterNodes:n,onSelectionChange:r}){const o=a.useMemo(()=>Pu(n,t),[n,t]),i=a.useMemo(()=>hn(t),[t]),d=a.useMemo(()=>o.map(c=>({value:c.id,label:c.name,description:`${c.role} · ${c.status}`,status:c.status})),[o]);return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-2",children:[e.jsx(Mu,{ariaLabel:"Capability node",value:t.name,description:`${t.role} · ${t.status}`,options:d,selectedValue:t.id,onSelect:c=>{const f=o.find(h=>h.id===c);f&&(r==null||r(Tu(s,f)))}}),e.jsx(gr,{node:t,projectPaths:i,selectedScope:s,onSelect:c=>r==null?void 0:r(_u(t.id,c))}),e.jsx(Du,{node:t})]})}function Du({node:t}){return e.jsxs("div",{"data-capability-node-meta":"true",className:"flex min-w-0 items-center gap-1 border-0 bg-transparent px-0.5 text-[8px] leading-3 text-muted-foreground",title:`${t.role} · ${t.status}`,children:[e.jsx("span",{className:"truncate capitalize",children:t.role}),e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(t.status))})]})}function gr({node:t,projectPaths:s,selectedScope:n,onSelect:r,compact:o=!1,portal:i=!1,portalAlign:d="start"}){const[c,f]=a.useState(!1),[h,y]=a.useState(null),[g,l]=a.useState(!1),[N,C]=a.useState(!1),[v,A]=a.useState(null),[p,S]=a.useState(!1),[b,j]=a.useState(null),w=a.useRef(null),T=a.useRef(null),D=a.useRef(null),U=a.useMemo(()=>s.map(_=>({value:_,label:va(_),description:_})),[s]),E=n.kind==="project"?n.projectPath:void 0,F=n.kind==="global"?"Global":va(n.projectPath),B=n.kind==="global"?"Global":n.projectPath,Q=a.useCallback(()=>{var _;return!i||typeof document>"u"?null:((_=T.current)==null?void 0:_.closest('[data-capability-share-dialog="true"]'))??document.body},[i]),ee=a.useCallback(()=>{if(!i||!T.current||typeof window>"u")return;const _=T.current.getBoundingClientRect(),W=Q(),x=W&&W!==document.body?W.getBoundingClientRect():{left:0,top:0,bottom:window.innerHeight};j(Cu({triggerRect:_,targetRect:x,viewportRect:{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},compact:o,browserOpen:p,portalAlign:d,cssZoom:Su()}))},[p,o,Q,i,d]);a.useEffect(()=>{c||S(!1)},[c]),a.useEffect(()=>{if(!c)return;const _=W=>{if(!(W.target instanceof Node))return;const x=W.composedPath(),z=w.current?x.includes(w.current):!1,m=D.current?x.includes(D.current):W.target instanceof Element&&!!W.target.closest('[data-capability-scope-menu="true"]');!z&&!m&&f(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[c]),a.useEffect(()=>{if(!(!c||!i))return ee(),window.addEventListener("resize",ee),window.addEventListener("scroll",ee,!0),()=>{window.removeEventListener("resize",ee),window.removeEventListener("scroll",ee,!0)}},[c,i,ee]);const V=async(_,W=0,x=!1)=>{if(t.workDir){A(null),x?C(!0):l(!0);try{const z=await Ca(t.id,{path:_||".",limit:wu,offset:W,directoriesOnly:!0,allowAbsolute:!0});y(m=>x&&m?{...z,entries:[...m.entries,...z.entries]}:z)}catch(z){A(z instanceof Error?z.message:"Failed to browse folders"),x||y(null)}finally{l(!1),C(!1)}}};a.useEffect(()=>{!c||!p||!t.workDir||(y(null),A(null),V(E||"."))},[p,c,t.id,t.workDir,E]);const H=(_,W=!1)=>{r({kind:"project",projectPath:ga(t,_,W)}),f(!1)},se=()=>{r({kind:"global"}),f(!1)},ie=h?ga(t,h.currentPath,h.isAbsolute):E??t.workDir??"",L=i?Q():null,K=e.jsxs("div",{ref:D,"data-capability-scope-menu":"true","aria-hidden":!c,onClick:_=>_.stopPropagation(),onMouseDown:_=>_.stopPropagation(),onPointerDown:_=>_.stopPropagation(),style:i&&b?{left:b.left,top:b.top,bottom:b.bottom,height:o&&p?b.maxHeight:void 0,maxHeight:b.maxHeight}:void 0,className:P(i?"absolute z-[80] flex w-72 flex-col overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none pointer-events-auto":"absolute left-0 z-50 flex max-h-[28rem] w-72 flex-col overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!i&&(o?"top-7":"top-9"),!c&&"hidden"),children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 p-1",children:[e.jsx("div",{className:P("px-2 text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",o?"pb-0.5 pt-0.5 leading-3":"pb-1 pt-1"),children:"Scope"}),e.jsxs("div",{className:P("overflow-y-auto pr-0.5",o?"max-h-32":"max-h-40"),children:[e.jsx(ba,{icon:"global",label:"Global",selected:n.kind==="global",onSelect:se,compact:o}),U.length>0?U.map(_=>e.jsx(ba,{icon:"folder",label:_.label,description:_.description,selected:E===_.value,onSelect:()=>H(_.value,!0),compact:o},_.value)):e.jsx("div",{className:P("flex items-center px-2 text-muted-foreground",o?"h-7 text-[9px]":"h-8 text-[10px]"),children:"No known projects"})]})]}),e.jsxs("div",{className:P("border-b border-border/55",p?"flex min-h-0 flex-1 flex-col":"shrink-0"),children:[e.jsxs("button",{type:"button","aria-expanded":p,onClick:()=>S(_=>!_),className:P("flex w-full items-center gap-1 px-2 text-left text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground transition-colors hover:bg-muted/45 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",o?"py-1 leading-3":"py-1.5"),children:[e.jsx(Pt,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Browse folders"}),e.jsx(st,{className:P("h-3 w-3 shrink-0 transition-transform duration-200",p&&"rotate-180")})]}),p&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"shrink-0 px-2 pb-1.5",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>(h==null?void 0:h.parentPath)&&void V(h.parentPath),disabled:!(h!=null&&h.parentPath)||g,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(Ua,{className:"h-2.5 w-2.5"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[9px] text-muted-foreground",title:ie,children:ie}),h&&e.jsx("button",{type:"button",onClick:()=>H(h.currentPath,h.isAbsolute),className:"shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium text-foreground hover:bg-muted/60",title:"Use this folder",children:"Use"})]})}),e.jsxs("div",{className:P("min-h-0 flex-1 overflow-y-auto",o?"min-h-[8.25rem]":"max-h-56"),children:[t.workDir?g?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[9px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading folders..."]}):h&&h.entries.length>0?e.jsxs(e.Fragment,{children:[h.entries.map(_=>e.jsx(Au,{entry:_,onSelect:()=>H(_.path,h.isAbsolute),onOpen:()=>void V(_.path)},_.path)),h.hasMore&&e.jsxs("button",{type:"button",onClick:()=>void V(h.currentPath,h.entries.length,!0),disabled:N,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[9px] text-muted-foreground hover:bg-muted/60 hover:text-foreground disabled:opacity-50",children:[N?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(ll,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:v??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:"This node has no working directory."}),v&&h&&h.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[9px] text-destructive",children:v})]})]})]})]});return e.jsxs("div",{ref:w,className:"relative min-w-0",children:[e.jsxs("button",{ref:T,type:"button","aria-label":"Capability location","aria-expanded":c,title:B,onClick:()=>f(_=>(_||(S(!1),ee()),!_)),className:P("flex min-w-0 items-center gap-1.5 rounded-sm border-0 bg-muted/55 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",o?"h-5 w-24 max-w-28 px-1.5":"h-7 min-w-32 max-w-56 px-2"),children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:P("block truncate font-medium text-foreground",o?"text-[9px] leading-3":"text-[10px] leading-4"),children:F})}),e.jsx(st,{className:P(o?"h-2.5 w-2.5":"h-3 w-3","shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),i&&L?Ma.createPortal(K,L):K]})}function ba({icon:t,label:s,description:n,selected:r,onSelect:o,compact:i=!1}){const d=t==="global"?al:Pt;return e.jsxs("button",{type:"button",onClick:o,className:P(i?"flex h-7 w-full items-center gap-1.5 rounded-md px-2 text-left text-[9px]":"flex h-8 w-full items-center gap-1.5 rounded-md px-2 text-left text-[10px]","transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",r&&"bg-primary/10 text-primary"),children:[e.jsx(d,{className:P("shrink-0 text-muted-foreground",i?"h-2.5 w-2.5":"h-3 w-3",r&&"text-primary")}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col justify-center",children:[e.jsx("span",{className:"block truncate font-medium leading-3",children:s}),n&&e.jsx("span",{className:P("block truncate text-muted-foreground",i?"text-[7px] leading-3":"text-[8px] leading-3"),children:n})]})]})}function Au({entry:t,onOpen:s,onSelect:n}){return e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:n,className:"flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1 text-left text-[9px] hover:bg-muted/55",title:`Use ${t.path}`,children:[e.jsx(Pt,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-foreground",children:t.name})]}),e.jsx("button",{type:"button",onClick:s,className:"flex w-7 shrink-0 items-center justify-center border-l border-border/30 text-muted-foreground hover:bg-muted/65 hover:text-foreground",title:"Open subfolder","aria-label":`Open ${t.name}`,children:e.jsx(He,{className:"h-3 w-3"})})]})}function Mu({ariaLabel:t,value:s,description:n,options:r,selectedValue:o,onSelect:i}){const[d,c]=a.useState(!1),f=a.useRef(null);return a.useEffect(()=>{if(!d)return;const h=y=>{f.current&&y.target instanceof Node&&!f.current.contains(y.target)&&c(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[d]),e.jsxs("div",{ref:f,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":t,"aria-expanded":d,title:n??s,onClick:()=>c(h=>!h),className:"flex h-7 min-w-32 max-w-56 items-center gap-1.5 rounded-sm border-0 bg-muted/55 px-2 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:"block truncate text-[10px] font-medium leading-4 text-foreground",children:s})}),e.jsx(st,{className:P("h-3 w-3 shrink-0 text-muted-foreground transition-transform",d&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!d,className:P("absolute left-0 top-9 z-50 w-64 overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!d&&"hidden"),children:e.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:r.length>0?r.map(h=>e.jsxs("button",{type:"button",onClick:()=>{i(h.value),c(!1)},className:P("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[11px] transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",h.value===o&&"bg-primary/10 text-primary"),children:[h.status&&e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(h.status))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:h.label}),h.description&&e.jsx("span",{className:"block truncate text-[9px] text-muted-foreground",children:h.description})]})]},h.value)):e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No projects"})})})]})}function Pu(t,s){const n=new Map;for(const r of t)n.set(r.id,r);return n.set(s.id,s),Array.from(n.values())}function Vt(t){return t==="online"?"bg-emerald-500":t==="offline"?"bg-muted-foreground/45":"bg-amber-500"}function va(t){return t.split(/[\\/]+/).filter(Boolean).at(-1)??t}function br(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)}function vr(t,s){return`${t.replace(/[\\/]+$/,"")}/${s.replace(/^[\\/]+/,"")}`}const Lu="h-6 w-24 rounded-sm px-2 text-[10px] shadow-none",Rs="text-[10px]",jr=["claudecode","codex","copilot"],Ut={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Iu({open:t,sourceNode:s,targetNodes:n,selectedCapabilities:r,previewResults:o=[],embedded:i=!1,onClose:d,onPreviewTargetsChange:c,onShare:f}){const[h,y]=a.useState(()=>new Set(o.length>0?o.map(x=>Xe(x.nodeId,x.targetAgent)):Ru(s.id,n,r))),[g,l]=a.useState(()=>Object.fromEntries($u(s.id,n,r))),[N,C]=a.useState({}),[v,A]=a.useState(!1),[p,S]=a.useState(()=>new Set),[b,j]=a.useState(()=>new Set),w=r.some(x=>x.kind==="plugin"),T=a.useMemo(()=>pn(r).map(x=>({key:Xe(s.id,x),nodeId:s.id,node:s,label:`Install into ${Ut[x]}`,agentLabel:Ut[x],defaultScope:yr(r),disabled:!1,targetAgent:x})),[r,s]),D=a.useMemo(()=>n.flatMap(x=>{const z={kind:"global"},m=x.status==="offline",G=wr(r);return G.length===0?[{key:Xe(x.id),nodeId:x.id,node:x,label:x.name,defaultScope:z,disabled:m}]:G.map(M=>({key:Xe(x.id,M),nodeId:x.id,node:x,label:`${x.name} / ${Ut[M]}`,agentLabel:Ut[M],defaultScope:z,disabled:m,targetAgent:M}))}),[r,n]),U=a.useMemo(()=>[...T,...D],[T,D]),E=a.useMemo(()=>n.map(x=>({node:x,options:D.filter(z=>z.nodeId===x.id)})).filter(x=>x.options.length>0),[n,D]),F=a.useMemo(()=>new Map(o.filter(x=>x.capabilityId).map(x=>[ja(x.nodeId,x.capabilityId,x.targetAgent),x])),[o]),B=a.useMemo(()=>new Map(o.map(x=>[Xe(x.nodeId,x.targetAgent),x])),[o]),Q=a.useMemo(()=>U.filter(x=>h.has(x.key)),[h,U]),ee=a.useMemo(()=>Q.map(x=>({nodeId:x.nodeId,scope:g[x.key]??x.defaultScope,...x.targetAgent?{targetAgent:x.targetAgent}:{}})),[Q,g]),V=a.useMemo(()=>{const x=[],z=new Map;for(const m of Q){if(!z.has(m.nodeId)){const G=m.nodeId===s.id?s:n.find(M=>M.id===m.nodeId);z.set(m.nodeId,{nodeId:m.nodeId,node:G,name:(G==null?void 0:G.name)??m.nodeId,options:[]}),x.push(m.nodeId)}z.get(m.nodeId).options.push(m)}return x.map(m=>z.get(m))},[Q,s,n]),H=a.useMemo(()=>{const x=Array.from(new Set(r.map(m=>m.agent))),[z]=x;if(z)return x.length===1?Ut[z]:`${x.length} agents`},[r]),se=E.length+1;a.useEffect(()=>{let x=!1;const z={...g};for(const m of U)z[m.key]||(z[m.key]=m.defaultScope,x=!0);x&&l(z)},[U,g]),a.useEffect(()=>{t&&(c==null||c(ee))},[t,c,ee]),a.useEffect(()=>{t&&(S(new Set),j(new Set))},[t,s.id]),a.useEffect(()=>{if(!i||!t)return;const x=z=>{z.key==="Escape"&&d()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[i,d,t]);const ie=x=>{C(Object.fromEntries(Q.map(z=>[z.key,x])))},L=async()=>{A(!0);try{await f(Q.map(x=>({nodeId:x.nodeId,scope:g[x.key]??x.defaultScope,...x.targetAgent?{targetAgent:x.targetAgent}:{},conflictStrategy:N[x.key]??"overwrite"})))}finally{A(!1)}},K=x=>{const z=g[x.key]??x.defaultScope,m=`capability-share-target-${Bu(x.key)}`,G=h.has(x.key);return e.jsxs("div",{"data-target-agent":x.targetAgent,className:"flex min-h-6 items-center gap-2 px-2 py-0.5 transition-colors hover:bg-muted/35 data-[disabled=true]:opacity-55","data-disabled":x.disabled?"true":void 0,children:[e.jsx(Kt,{id:m,disabled:x.disabled,checked:G,onCheckedChange:M=>y(q=>{const k=new Set(q);return M===!0?k.add(x.key):k.delete(x.key),k}),"aria-label":`Select ${x.label} as a share target`,"data-share-target-checkbox":!0,className:"h-3.5 w-3.5 border-border/70 bg-background/80 shadow-none data-[state=checked]:border-primary data-[state=checked]:bg-primary [&_svg]:h-3 [&_svg]:w-3"}),e.jsx("label",{htmlFor:m,className:"min-w-0 flex-1 cursor-pointer truncate text-[10px] font-medium leading-4 text-foreground data-[disabled=true]:cursor-not-allowed","data-disabled":x.disabled?"true":void 0,children:x.agentLabel??x.label}),e.jsx("div",{className:"flex w-28 shrink-0 justify-end",children:G&&!x.disabled&&e.jsx(gr,{node:x.node,projectPaths:hn(x.node),selectedScope:z,onSelect:M=>l(q=>({...q,[x.key]:M})),compact:!0,portal:!0,portalAlign:"end"})})]},x.key)},_=(x,z,m,G)=>{const M=p.has(x.id),q=Q.filter(k=>k.nodeId===x.id).length;return e.jsxs("div",{className:"overflow-hidden rounded-sm border border-border/45 bg-muted/15",children:[e.jsxs("button",{type:"button","aria-expanded":M,onClick:()=>S(k=>wa(k,x.id)),className:"flex w-full items-center gap-2 border-b border-border/35 bg-primary/5 px-2 py-1.5 text-left transition-colors hover:bg-primary/10",children:[e.jsx(He,{className:P("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",M&&"rotate-90")}),e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(x.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold text-foreground",title:x.name,children:x.name}),q>0&&e.jsxs("span",{className:"shrink-0 text-[8px] font-medium text-primary",children:[q," selected"]}),e.jsx("span",{className:"shrink-0 text-[8px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:z?"this node":"remote"}),x.status==="offline"&&e.jsx(Fe,{variant:"outline",className:"rounded-sm px-1 py-0 text-[8px]",children:"offline"}),G>0&&e.jsxs("span",{className:"sr-only",children:[G," agents"]})]}),e.jsx("div",{className:P("grid transition-[grid-template-rows] duration-200 ease-out",M?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsx("div",{className:"divide-y divide-border/25",children:m})})})]},x.id)},W=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-b border-border/55 px-4 py-3 text-left",children:[e.jsxs("h2",{id:"capability-share-title",className:"flex items-center gap-2 text-sm font-semibold leading-none tracking-tight",children:[e.jsx(gs,{className:"h-4 w-4 text-primary"}),"Share ",r.length," ",r.length===1?"capability":"capabilities"]}),e.jsx("p",{id:"capability-share-description",className:"mt-1.5 text-[11px] text-muted-foreground",children:"Copies each capability into the matching agent on the selected targets. Plugins install into their matching agent."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2.5 gap-y-1 border-b border-border/55 bg-muted/15 px-4 py-2 text-[11px]",children:[e.jsx("span",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Source"}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(s.status))}),e.jsx("span",{className:"truncate font-semibold text-foreground",title:s.name,children:s.name}),H&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:["· ",H]})]}),e.jsx(Fn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Targets"}),e.jsxs("span",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:Q.length})," selected · ",se," ",se===1?"node":"nodes"]})]}),e.jsxs("div",{className:"grid gap-4 p-4 lg:grid-cols-[17rem_minmax(0,1fr)]",children:[e.jsx("section",{className:"min-w-0",children:e.jsxs("div",{className:"max-h-[56vh] space-y-2 overflow-y-auto pr-0.5",children:[_(s,!0,w?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"Cross-agent plugin installs are not supported."}):T.length===0?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No alternate agents available for this selection."}):T.map(K),T.length),E.map(x=>_(x.node,!1,x.options.map(K),x.options.length))]})}),e.jsxs("section",{className:"min-w-0",children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Conflict preview"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[8px] uppercase tracking-[0.12em] text-muted-foreground/70",children:"Set all"}),e.jsx("div",{className:"inline-flex items-center rounded-sm border border-border/55 bg-muted/20 p-px",children:["overwrite","skip","abort"].map(x=>e.jsx("button",{type:"button",onClick:()=>ie(x),className:"h-5 rounded-[3px] px-1.5 text-[9px] capitalize text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground",children:x},x))})]})]}),e.jsx("div",{className:"max-h-[56vh] min-h-32 overflow-y-auto rounded-sm border border-border/55 bg-background/45 p-2",children:Q.length===0?e.jsx("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"Select a target to preview conflicts."}):V.map(x=>{const z=!b.has(x.nodeId);return e.jsxs("div",{className:"mb-1.5 overflow-hidden rounded-sm border border-border/35 bg-muted/10 last:mb-0",children:[e.jsxs("button",{type:"button","aria-expanded":z,onClick:()=>j(m=>wa(m,x.nodeId)),className:"flex w-full items-center gap-1.5 border-b border-border/30 bg-primary/5 px-2 py-1 text-left transition-colors hover:bg-primary/10",children:[e.jsx(He,{className:P("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",z&&"rotate-90")}),x.node&&e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(x.node.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-semibold text-foreground",children:x.name}),e.jsxs("span",{className:"shrink-0 text-[8px] text-muted-foreground",children:[x.options.length," ",x.options.length===1?"agent":"agents"]})]}),e.jsx("div",{className:P("grid transition-[grid-template-rows] duration-200 ease-out",z?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsx("div",{className:"space-y-1 p-1.5",children:x.options.map(m=>{const G=N[m.key]??"overwrite";return e.jsxs("div",{className:"rounded-sm bg-background/45 px-2 py-1",children:[e.jsxs("div",{className:"mb-0.5 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[9px] font-medium leading-4 text-foreground",children:m.agentLabel??"Matching agent"}),e.jsxs(ke,{value:G,onValueChange:M=>C(q=>({...q,[m.key]:M})),children:[e.jsx(Se,{className:Lu,children:e.jsx(Be,{})}),e.jsxs(Ce,{className:"shadow-none",children:[e.jsx(xe,{value:"overwrite",className:Rs,children:"Overwrite"}),e.jsx(xe,{value:"skip",className:Rs,children:"Skip"}),e.jsx(xe,{value:"abort",className:Rs,children:"Abort"})]})]})]}),e.jsx("div",{className:"space-y-px",children:r.map(M=>{const q=F.get(ja(m.nodeId,M.id,m.targetAgent))??(r.length===1?B.get(m.key):void 0);return e.jsxs("div",{className:"flex items-center gap-1.5 text-[9px] leading-4",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:M.name}),e.jsx("span",{className:q!=null&&q.conflict?"text-amber-500":q?"text-emerald-500":"text-muted-foreground",children:q?q.conflict?`exists${q.currentVersion?` v${q.currentVersion}`:""}`:"new install":"checking"}),(q==null?void 0:q.sourceVersion)&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[e.jsx(Fn,{className:"inline h-2.5 w-2.5"})," v",q.sourceVersion]})]},M.id)})})]},m.key)})})})})]},x.nodeId)})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-border/55 px-4 py-3",children:[e.jsx(Z,{variant:"ghost",onClick:d,className:"h-7 rounded-sm px-3 text-[11px]",children:"Cancel"}),e.jsxs(Z,{onClick:L,disabled:v||Q.length===0,className:"h-7 rounded-sm px-3 text-[11px]",children:[v?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(gs,{className:"h-3.5 w-3.5"}),"Share"]})]})]});return i?t?e.jsx("div",{className:"absolute inset-0 z-[80] flex items-center justify-center bg-background/70 p-4 backdrop-blur-[2px]",onMouseDown:x=>{x.target===x.currentTarget&&d()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"capability-share-title","aria-describedby":"capability-share-description","data-capability-share-dialog":"true",className:"relative grid w-full max-w-3xl gap-0 overflow-visible rounded-xl border-0 bg-background text-foreground shadow-[0_34px_110px_-54px_rgba(0,0,0,0.55)]",onMouseDown:x=>x.stopPropagation(),children:[W,e.jsxs("button",{type:"button",onClick:d,className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:[e.jsx(tt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})}):null:e.jsx(Lt,{open:t,onOpenChange:x=>{x||d()},children:e.jsx(It,{"aria-labelledby":"capability-share-title","aria-describedby":"capability-share-description","data-capability-share-dialog":"true",className:"max-w-3xl gap-0 overflow-visible rounded-xl border-0 p-0",children:W})})}function Xe(t,s){return s?`agent:${t}:${s}`:`node:${t}`}function Bu(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-")}function ja(t,s,n){return`${Xe(t,n)}\0${s}`}function wa(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function Ru(t,s,n){const r=s.find(i=>i.status!=="offline");if(r)return[Xe(r.id,Ou(n))];const o=pn(n)[0];return o?[Xe(t,o)]:[]}function $u(t,s,n){const r=wr(n);return[...s.flatMap(o=>r.length===0?[[Xe(o.id),{kind:"global"}]]:r.map(i=>[Xe(o.id,i),{kind:"global"}])),...pn(n).map(o=>[Xe(t,o),yr(n)])]}function wr(t){return t.length===0||t.some(s=>s.kind==="plugin")?[]:jr}function Ou(t){var s;if(!(t.length===0||t.some(n=>n.kind==="plugin")))return(s=t[0])==null?void 0:s.agent}function pn(t){if(t.length===0||t.some(n=>n.kind==="plugin"))return[];const s=new Set(t.map(n=>n.agent));return jr.filter(n=>!s.has(n))}function yr(t){var s;return((s=t[0])==null?void 0:s.scope)??{kind:"global"}}const ya="h-7 rounded-sm border-0 bg-muted/55 px-2 text-[9px] leading-none shadow-none hover:bg-muted/70 [&>svg]:h-3 [&>svg]:w-3",ht="py-0.5 pl-6 pr-1.5 text-[9px] leading-4 [&_svg]:h-3 [&_svg]:w-3",Nr="h-5 rounded-sm bg-muted/55 px-1.5 text-[9px] font-medium text-foreground shadow-none border-0 hover:bg-muted/75 hover:text-foreground disabled:text-muted-foreground [&_svg]:size-2.5",Fu="h-5 rounded-sm bg-primary px-2 text-[9px] font-medium text-primary-foreground shadow-none border-0 hover:bg-primary/90 hover:text-primary-foreground disabled:bg-primary/45 disabled:text-primary-foreground/80 [&_svg]:size-2.5";function zu(t,s,n,r){return n.map(o=>({sourceNodeId:t,capabilityId:o.id,sourceScope:s,targets:r.map(i=>({nodeId:i.nodeId,scope:i.scope,...i.targetAgent?{targetAgent:i.targetAgent}:{}}))}))}function Uu(t,s,n,r){return n.map(o=>({sourceNodeId:t,capabilityId:o.id,sourceScope:s,targets:r}))}function Vu({loading:t,onRefresh:s}){return e.jsxs(Z,{variant:"ghost",onClick:s,disabled:t,"aria-busy":t,className:P(Nr,"min-w-[4.5rem]"),children:[e.jsx(Ha,{className:P("h-2.5 w-2.5",t&&"animate-spin")}),t?"Refreshing":"Refresh"]})}function Hu({selectedCount:t,loading:s,onClearSelection:n,onRefresh:r,onShare:o}){return e.jsxs("div",{className:"flex items-center justify-between gap-2 bg-card/15 px-0.5 pt-1.5 text-[9px] text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(Z,{type:"button",variant:"ghost",onClick:n,disabled:t===0,className:Nr,children:[e.jsx(tt,{className:"h-2.5 w-2.5"}),"Selected: ",t," / Clear"]})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Vu,{loading:s,onRefresh:r}),e.jsxs(Z,{type:"button",variant:"ghost",onClick:o,disabled:t===0,className:Fu,children:[e.jsx(gs,{className:"h-2.5 w-2.5"}),"Share"]})]})]})}function qu({onBeginResize:t,onFold:s}){const n=r=>{r.key!=="Enter"&&r.key!==" "||(r.preventDefault(),s())};return e.jsx("div",{role:"separator","aria-label":"Fold capability detail panel","aria-orientation":"vertical",title:"Fold details",tabIndex:0,onClick:s,onKeyDown:n,onPointerDown:t,className:"hidden w-1 shrink-0 cursor-col-resize items-center justify-center bg-primary/10 transition-colors hover:bg-primary/22 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 lg:flex",children:e.jsx("span",{className:"h-8 w-px rounded-full bg-primary/45"})})}function Ku({visible:t}){return t?e.jsx("div",{className:"absolute inset-2.5 z-10 flex items-center justify-center rounded-sm border border-border/60 bg-background/85 shadow-sm backdrop-blur-sm",children:e.jsxs("div",{className:"flex w-full max-w-80 flex-col items-center gap-3 px-5 text-center",children:[e.jsxs("div",{className:"relative flex h-10 w-10 items-center justify-center rounded-full border border-primary/25 bg-primary/8",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border border-primary/20 animate-ping"}),e.jsx(ue,{className:"relative h-4 w-4 animate-spin text-primary"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:"Loading capabilities"}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Reading agent skills, plugins, and MCP servers for this selection."})]}),e.jsxs("div",{className:"grid w-full gap-1.5","aria-hidden":"true",children:[e.jsx("span",{className:"h-1.5 rounded-full bg-muted animate-pulse"}),e.jsx("span",{className:"mx-auto h-1.5 w-3/4 rounded-full bg-muted/70 animate-pulse"})]})]})}):null}function Wu({open:t,node:s,scope:n,clusterNodes:r,onOpenChange:o,onSelectionChange:i}){const[d,c]=a.useState([]),[f,h]=a.useState([]),[y,g]=a.useState(!1),[l,N]=a.useState(""),[C,v]=a.useState("all"),[A,p]=a.useState("all"),[S,b]=a.useState(new Set),[j,w]=a.useState(null),[T,D]=a.useState(null),[U,E]=a.useState(!1),[F,B]=a.useState(null),[Q,ee]=a.useState(!1),[V,H]=a.useState([]),[se,ie]=a.useState(fr),[L,K]=a.useState(null),_=a.useMemo(()=>xu(d,{search:l,agent:C,kind:A}),[C,d,A,l]),W=a.useMemo(()=>d.filter(O=>S.has(O.id)),[d,S]),x=a.useMemo(()=>r.filter(O=>O.id!==s.id),[r,s.id]),z=n.kind==="project"?n.projectPath:"global",m=async()=>{g(!0);try{const O=await oi(s.id,{scope:n});c(O.items),h((O.errors??[]).map(te=>`${te.agent}: ${te.message}`))}catch(O){h([O instanceof Error?O.message:"Failed to load capabilities"])}finally{g(!1)}};a.useEffect(()=>{t&&(b(new Set),w(null),D(null),E(!1),H([]),c([]),h([]),m())},[t,s.id,n.kind,z]),a.useEffect(()=>{if(!L)return;const O=le=>{ie(gu(L.startWidth,L.startClientX,le.clientX,window.innerWidth))},te=()=>K(null);return window.addEventListener("pointermove",O),window.addEventListener("pointerup",te),()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",te)}},[L]);const G=O=>{O.preventDefault(),K({startClientX:O.clientX,startWidth:se})},M=()=>{K(null),E(!1),w(null),D(null)},q=()=>{b(new Set),H([])},k=async O=>{w(O.id),E(!0),D(null);const te=await ii(s.id,O.id,n);D(te.detail)},X=a.useCallback(async O=>{if(W.length===0||O.length===0){H([]);return}H([]);try{const te=zu(s.id,n,W,O),le=await Promise.all(te.map(R=>ri(R)));H(le.flatMap((R,ae)=>R.results.map(ve=>{var Ee;return{...ve,capabilityId:(Ee=te[ae])==null?void 0:Ee.capabilityId}})))}catch{H([])}},[s.id,n,W]),re=()=>{H([]),ee(!0)},ce=async O=>{const te=Uu(s.id,n,W,O);te.length!==0&&(await Promise.all(te.map(le=>di(le))),de.success(`${te.length} capability share request${te.length===1?"":"s"} completed`),ee(!1))},J=async()=>{if(!(!T||F)){B(T.id);try{const O=await li(s.id,T.id,n);O.status==="deleted"?(de.success(`Deleted ${T.name}`),c(te=>te.filter(le=>le.id!==T.id)),b(te=>{const le=new Set(te);return le.delete(T.id),le}),w(null),D(null),E(!1),await m()):(de.info(O.message??"Capability was not found"),w(null),D(null),E(!1),await m())}catch(O){de.error(O instanceof Error?O.message:"Failed to delete capability")}finally{B(null)}}};return e.jsx(e.Fragment,{children:e.jsx(Lt,{open:t,onOpenChange:o,children:e.jsxs(It,{className:"dashboard-panel animate-panel-settle flex h-[min(62vh,33rem)] w-[min(94vw,72rem)] max-w-[min(94vw,72rem)] flex-col gap-0 overflow-hidden rounded-xl p-0",children:[e.jsxs(sn,{className:"border-b border-border/55 bg-card/28 px-4 py-2.5 text-left",children:[e.jsx(Yt,{className:"sr-only",children:"Capabilities"}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-x-4 gap-y-1 pr-10",children:[e.jsx(Eu,{node:s,scope:n,clusterNodes:r,onSelectionChange:i}),e.jsxs(an,{"data-capability-selection-help":"true",className:"ml-auto max-w-[min(32rem,38vw)] space-y-0.5 pt-0.5 text-right text-[9px] leading-[11px] text-muted-foreground",children:[e.jsx("span",{className:"block truncate whitespace-nowrap",children:"Sharing copies into selected agents on target nodes."}),n.kind==="project"&&e.jsx("span",{"data-capability-selection-path":"true",className:"block truncate font-mono text-[7px] leading-[10px] text-muted-foreground/80",title:n.projectPath,children:n.projectPath})]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:flex-row",children:[e.jsxs("main",{className:"relative flex min-w-0 flex-1 flex-col gap-2 bg-gradient-to-b from-primary/4 via-background/20 to-background/40 p-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-44 flex-1",children:[e.jsx(Ta,{className:"pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),e.jsx(et,{value:l,onChange:O=>N(O.target.value),placeholder:"Search capabilities",className:"h-7 rounded-sm border-0 bg-muted/55 pl-6 text-[10px] shadow-none"})]}),e.jsxs(ke,{value:C,onValueChange:O=>v(O),children:[e.jsx(Se,{className:P("w-28",ya),children:e.jsx(Be,{})}),e.jsxs(Ce,{className:"shadow-none",children:[e.jsx(xe,{value:"all",className:ht,children:"Agent: All"}),e.jsx(xe,{value:"claudecode",className:ht,children:"Claude Code"}),e.jsx(xe,{value:"codex",className:ht,children:"Codex"}),e.jsx(xe,{value:"copilot",className:ht,children:"Copilot"})]})]}),e.jsxs(ke,{value:A,onValueChange:O=>p(O),children:[e.jsx(Se,{className:P("w-24",ya),children:e.jsx(Be,{})}),e.jsxs(Ce,{className:"shadow-none",children:[e.jsx(xe,{value:"all",className:ht,children:"Kind: All"}),e.jsx(xe,{value:"skill",className:ht,children:"Skill"}),e.jsx(xe,{value:"plugin",className:ht,children:"Plugin"}),e.jsx(xe,{value:"mcp",className:ht,children:"MCP"})]})]})]}),f.length>0&&e.jsx("div",{className:"rounded-sm bg-amber-500/10 px-2 py-1 text-[10px] text-amber-600",children:f.join(" · ")}),e.jsx(hu,{items:_,selectedIds:S,activeId:j,onToggleSelected:(O,te)=>b(le=>{const R=new Set(le);return te?R.add(O):R.delete(O),R}),onOpenDetail:k}),e.jsx(Hu,{selectedCount:S.size,loading:y,onClearSelection:q,onRefresh:m,onShare:re}),e.jsx(Ku,{visible:y&&d.length===0})]}),U&&e.jsxs(e.Fragment,{children:[e.jsx(qu,{onBeginResize:G,onFold:M}),e.jsx(bu,{detail:T,deleting:F===(T==null?void 0:T.id),desktopWidth:se,onDelete:T?J:void 0,pending:!T})]})]}),Q&&e.jsx(Iu,{open:Q,sourceNode:s,targetNodes:x,selectedCapabilities:W,previewResults:V,embedded:!0,onClose:()=>ee(!1),onPreviewTargetsChange:X,onShare:ce})]})})})}function Gu(t){const[s,n]=a.useState(null),r=a.useMemo(()=>s?(t==null?void 0:t.nodes.find(f=>f.id===s.nodeId))??((t==null?void 0:t.self.id)===s.nodeId?t.self:null)??null:null,[t,s]),o=a.useCallback(f=>{n({nodeId:f,scope:{kind:"global"}})},[]),i=a.useCallback((f,h)=>{n({nodeId:f,scope:{kind:"project",projectPath:h}})},[]),d=a.useCallback(f=>{n(f)},[]);return{capabilitiesDialog:s&&r&&t?e.jsx(Wu,{open:!0,node:r,scope:s.scope,clusterNodes:t.nodes,onOpenChange:f=>{f||n(null)},onSelectionChange:d}):null,openNodeCapabilities:o,openProjectCapabilities:i}}function Yu(){var jn,wn,yn,Nn,kn,Sn;const{id:t}=ci(),s=ui(),n=mi(),r=xi(),{cluster:o,systemInfo:i,events:d,sseConnected:c,subscribe:f,refresh:h,loading:y,error:g}=hi(),l=a.useMemo(()=>pi(s.state),[s.state]),[N,C]=a.useState(null),[v,A]=a.useState("active"),[p,S]=a.useState("all"),[b,j]=a.useState("all"),[w,T]=a.useState("all"),D=(r==null?void 0:r.headerSearchQuery)??"",U=a.useDeferredValue(D),{desktopTasksOpen:E,mobileTasksPanelOpen:F,mobileTasksPanelRef:B,operationsOpen:Q,operationsPanelRef:ee,panelResize:V,setMobileTasksPanelOpen:H,setOperationsOpen:se,toggleTasksPanel:ie}=Fc(),[L,K]=a.useState(()=>!!(l!=null&&l.draftNewTask)),[_,W]=a.useState(()=>(l==null?void 0:l.createMode)??"chat"),[x,z]=a.useState(()=>(l==null?void 0:l.createDefaults)??null),[m,G]=a.useState(()=>l!=null&&l.draftNewTask?{route:l.returnRoute??"/",taskId:l.returnTaskId??null}:null),[M,q]=a.useState(!1),[k,X]=a.useState("transcript"),[re,ce]=a.useState("all"),[J,O]=a.useState(!1),[te,le]=a.useState(null),[R,ae]=a.useState([]),[ve,Ee]=a.useState([]),[nt,at]=a.useState(!1),[Ue,je]=a.useState(!1),[it,We]=a.useState(null),[Me,ne]=a.useState(new Set),[we,Pe]=a.useState(!1),[De,lt]=a.useState(!1),[ye,qe]=a.useState(null),$e=a.useRef(null),jt=a.useRef(new Map),Te=((jn=o==null?void 0:o.self)==null?void 0:jn.role)==="leader",$=(wn=o==null?void 0:o.self)==null?void 0:wn.id,{quickChats:Le}=fi();eu({cluster:o,subscribe:f});const{nodeSettingsDialog:Ae,openNodeSettings:dt}=du(Te),{capabilitiesDialog:pt,openNodeCapabilities:wt,openProjectCapabilities:Ie}=Gu(o),{devBoxDialog:ze,devBoxNodeIds:yt,devBoxStartNodeId:ft,devBoxStartNodeIds:Ge,devBoxStartingNodeIds:mt,openDevBox:Nt,startDevBox:ct}=lu({cluster:o,refresh:h}),{completedGroups:Ne=[],fetchTasks:_e,loadCompletedTasksPage:ut,removeTasksFromList:kt,setTasks:fe,tasks:be,tasksError:rt,tasksLoading:St}=Qc({isLeader:Te,selfId:$,sseConnected:c,preservedTask:te,subscribe:f}),Ye=a.useMemo(()=>[...be].sort((u,I)=>I.updatedAt-u.updatedAt),[be]),Qe=a.useMemo(()=>{var u;return((u=[...be].sort((I,Y)=>Y.createdAt-I.createdAt||Y.updatedAt-I.updatedAt)[0])==null?void 0:u.id)??null},[be]),kr=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[]){const Y=Hl(Ye,I.id);Y>0&&u.set(I.id,Y)}return u},[o==null?void 0:o.nodes,Ye]),Ze=a.useMemo(()=>Ye.filter(u=>!gi(u,o==null?void 0:o.nodes,o==null?void 0:o.self)||!bi(u,v)||p!=="all"&&u.agent!==p||!vi(u,w)||b==="unassigned"&&u.assignedTo||b!=="all"&&b!=="unassigned"&&ji(u.assignedTo,o==null?void 0:o.nodes,u.assignedNodeName)!==b?!1:U.trim()?wi(u,U):!0),[Ye,o==null?void 0:o.nodes,o==null?void 0:o.self,v,p,w,b,U]);a.useEffect(()=>{ne(u=>{const I=Ql(u,Ze.map(Y=>Y.id));return I.size===u.size?u:I})},[Ze]),a.useEffect(()=>{Te||ne(new Set)},[Te]);const Sr=a.useMemo(()=>["all",...Array.from(new Set(Ye.map(u=>u.agent))).sort()],[Ye]),Cr=a.useMemo(()=>{const I=Array.from(new Set(Ye.map(Y=>Y.assignedTo).filter(Y=>!!Y))).map(Y=>{const ge=Ye.find(me=>me.assignedTo===Y);return(o==null?void 0:o.nodes.find(me=>me.id===Y))??{id:Y,name:Os(Y,o==null?void 0:o.nodes,ge==null?void 0:ge.assignedNodeName)}}).sort((Y,ge)=>Y.name.localeCompare(ge.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...I.map(Y=>({value:Y.name.toLowerCase(),label:Y.name}))]},[Ye,o==null?void 0:o.nodes]),fn=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])u.set(I.id,I.name);for(const I of Ye)I.assignedTo&&I.assignedNodeName&&!u.has(I.assignedTo)&&u.set(I.assignedTo,I.assignedNodeName);return u},[o==null?void 0:o.nodes,Ye]),Tr=a.useMemo(()=>{var I;const u=new Map;for(const Y of(o==null?void 0:o.nodes)??[])Y.workDir&&u.set(Y.id,Y.workDir);return(I=o==null?void 0:o.self)!=null&&I.workDir&&u.set(o.self.id,o.self.workDir),u},[o]),_r=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])u.set(I.id,I.status);return o!=null&&o.self&&u.set(o.self.id,o.self.status),u},[o]),Er=a.useMemo(()=>new Map(Ne.map(u=>[Xs(u),u])),[Ne]),gn=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])I.status!=="offline"&&u.set(I.id,I);return o!=null&&o.self&&o.self.status!=="offline"&&u.set(o.self.id,o.self),Array.from(u.values())},[o]),Dr=((yn=o==null?void 0:o.self)==null?void 0:yn.id)??((Nn=gn[0])==null?void 0:Nn.id)??null,$t=a.useMemo(()=>d.filter(yi),[d]),ks=a.useMemo(()=>["all",...Array.from(new Set($t.map(u=>u.type))).sort()],[$t]),Ar=a.useMemo(()=>re==="all"?$t:$t.filter(u=>u.type===re),[$t,re]),Mr=Ze.length>0&&Ze.every(u=>Me.has(u.id)),Pr=Ze.some(u=>Me.has(u.id)),Lr=Zl(Ze,Me);a.useEffect(()=>{l!=null&&l.draftNewTask&&(K(!0),W(l.createMode??"chat"),z(l.createDefaults??null),G({route:l.returnRoute??"/",taskId:l.returnTaskId??null}))},[l]),a.useEffect(()=>{re!=="all"&&!ks.includes(re)&&ce("all")},[re,ks]),a.useEffect(()=>{Un(t,L)&&!N&&Qe&&C(Qe)},[t,L,N,Qe]),a.useEffect(()=>{Un(t,L)&&(N&&be.some(u=>u.id===N)||C(Qe))},[t,L,N,Qe,be]);const pe=Kl({routeTaskId:t,creatingTask:L,internalSelectedTaskId:N,sortedTaskIds:Qe?[Qe]:[]}),Ct=a.useMemo(()=>be.find(u=>u.id===pe)??null,[be,pe]);a.useEffect(()=>{$e.current=pe??null},[pe]);const xt=a.useCallback(()=>{le(null),ae([]),Ee([]),We(null),je(!1)},[]),Ot=a.useCallback((u,I,Y=!0)=>{jt.current.set(u,{logs:xr(I),loaded:Y})},[]),Ve=a.useCallback(async()=>{const u=pe;if(u)try{const I=await Ni(u);if($e.current!==u)return;le(I),fe(Y=>Ga(Y,I)),We(null)}catch(I){if($e.current!==u)return;xt(),We(I instanceof Error?I.message:"Failed to load task")}finally{$e.current===u&&at(!1)}},[pe,xt,fe]),Qt=a.useCallback(async()=>{const u=pe;if(u)try{const I=await zs(u);if($e.current!==u)return;ae(Y=>{const ge=za(Y,I.logs);return Ot(u,ge),ge}),Ee(Y=>Vs(Y,I.logs))}catch{}finally{$e.current===u&&je(!1)}},[pe,Ot]);a.useEffect(()=>{if(!pe){xt(),at(!1);return}X("transcript"),le(Ct);const u=Zc(pe,jt.current);ae(u.logs),Ee([]),We(null),at(!0),je(u.transcriptLoading),Ve(),Qt()},[pe,xt,Qt,Ve]),a.useEffect(()=>{if(!Wl({activeTaskId:pe,routeTaskId:t,creatingTask:L,tasksLoading:St,loadedTaskIds:be.map(I=>I.id)}))return;const u=Qe;C(u),xt(),a.startTransition(()=>{n(u?`/tasks/${u}`:"/",{state:null})})},[pe,xt,L,Qe,n,t,be,St]),a.useEffect(()=>{Ct&&le(u=>!u||u.id!==Ct.id?u:{...u,...Ct})},[Ct]),a.useEffect(()=>{if(pe)return f("task",u=>{const I=u.data.taskId;if(!(typeof I!="string"||I!==pe)){if(u.type==="task.output"){const Y=u.data.event;if(Y){ae(me=>{const zt=zi(me,Y);return Ot(pe,zt),zt}),je(!1);const ge=On(Y);ge&&Ee(me=>Ui(me,ge))}}u.type==="task.updated"&&Ve(),u.type==="task.status"&&(Ve(),Qt())}})},[f,pe,Ve,Qt]);const oe=te??Ct,Ir=oe!=null&&oe.assignedTo?(o==null?void 0:o.nodes.find(u=>u.id===oe.assignedTo))??null:null,Ft=r==null?void 0:r.setHeaderTaskContext;a.useEffect(()=>{if(!Ft)return;if(!oe){Ft(null);return}const u=oe.effectiveProjectPath??oe.project??"default workspace";return Ft({taskId:oe.id,taskTitle:oe.title,nodeName:Os(oe.assignedTo,o==null?void 0:o.nodes,oe.assignedNodeName),projectLabel:Ia(u),projectPath:u}),()=>Ft(null)},[oe,o==null?void 0:o.nodes,Ft]);const Ss=ve.length>0,Br=oe?ki.has(oe.agent):!1,Zt=(oe==null?void 0:oe.status)==="running",Rr=oe?ps.has(oe.status):!1,$r=oe?ps.has(oe.status)||Si.has(oe.status):!1,Or=!!(oe&&Te&&oe.status==="failed"),Cs=a.useMemo(()=>Cc(oe,o,Ss,!!Zt),[oe,o,Ss,Zt]),Ts=a.useMemo(()=>Vi([...R,...ve.map(u=>Ps(u.content,u.timestamp))]),[R,ve]),Xt=a.useMemo(()=>{if(!oe||oe.conversationKind==="nativeSession")return null;const u=Hi(oe);if(u.length>0)return Ps(u,new Date(oe.createdAt).toISOString());if(Ts.length>0)return null;const I=qi(oe.description||oe.title);return I.length>0?Ps(I,new Date(oe.createdAt).toISOString()):null},[oe,Ts]),_s=a.useMemo(()=>Xt?On(Xt):null,[Xt]),Fr=a.useMemo(()=>_s?Ki(R,_s):!1,[R,_s]),Es=a.useCallback((u="chat",I)=>{const Y={route:t?`/tasks/${t}`:"/",taskId:pe};G(Y),W(u),z(I??null),K(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:Y.route,returnTaskId:Y.taskId,createMode:u,createDefaults:I}})})},[t,pe,n]),zr=a.useCallback(()=>{const u=(m==null?void 0:m.taskId)??Qe;K(!1),G(null),z(null),C(u),a.startTransition(()=>{n((m==null?void 0:m.route)??"/",{state:null})})},[m,Qe,n]),bn=a.useCallback(u=>{K(!1),G(null),z(null),C(u),a.startTransition(()=>{n(`/tasks/${u}`,{state:null})})},[n]),Ur=a.useCallback(u=>{$e.current=u.id,K(!1),G(null),z(null),fe(I=>Gl(I,u)),le(u),ae([]),Ee([]),We(null),at(!1),je(u.conversationKind==="nativeSession"),X("transcript"),C(u.id),su({task:u,getActiveTaskId:()=>$e.current,setLogs:ae,setPendingMessages:Ee,setTranscriptLoading:je}),_e(),a.startTransition(()=>{n(`/tasks/${u.id}`,{state:null})})},[_e,n]),{cancelQueuedMessage:Vr,queueFollowUpMessage:Jt}=uu({activeTaskId:pe,fetchActiveTask:Ve,isRunning:Zt,setPendingMessages:Ee,setTask:le,setTasks:fe}),Hr=a.useCallback(u=>{Jt(u)},[Jt]),qr=a.useCallback(async()=>{const u=pe;if(!(!u||(oe==null?void 0:oe.conversationKind)!=="nativeSession")){je(!0);try{const I=await zs(u);if($e.current!==u)return;ae(I.logs),Ot(u,I.logs),Ee(Y=>Vs(Y,I.logs))}catch(I){de.error(I instanceof Error?I.message:"Failed to reload transcript")}finally{$e.current===u&&je(!1)}}},[oe==null?void 0:oe.conversationKind,pe,Ot]),Kr=a.useCallback(u=>Jt(u),[Jt]),Wr=a.useCallback(async()=>{if(oe)try{await Ci(oe.id),Ve(),_e()}catch(u){de.error(u instanceof Error?u.message:"Failed to cancel task")}},[oe,Ve,_e]),{handleShareTask:Gr,handleStopShareTask:Yr}=Bc(oe,Ve,_e),Qr=a.useCallback(async()=>{if(oe)try{await Ti(oe.id),Ve(),_e()}catch(u){de.error(u instanceof Error?u.message:"Failed to retry task")}},[oe,Ve,_e]),es=a.useCallback((u,I=!1)=>{const Y=Xl(Ze,u);return C(Y),(I||!Y)&&xt(),a.startTransition(()=>{n(Y?`/tasks/${Y}`:"/",{state:null})}),Y},[xt,Ze,n]),Zr=a.useCallback((u,I)=>{ne(Y=>{const ge=new Set(Y);return I?ge.add(u):ge.delete(u),ge})},[]),Xr=a.useCallback(u=>{if(!u){ne(new Set);return}ne(new Set(Ze.map(I=>I.id)))},[Ze]),Jr=a.useCallback(async()=>{const u=Array.from(Me);if(u.length!==0)try{const{results:I}=await _i(u),Y=I.filter(me=>!me.ok),ge=I.filter(me=>me.ok).map(me=>me.id);pe&&ge.includes(pe)&&es(ge),Y.length>0?de.error(`Failed to archive ${Y.length} task(s): ${Y.map(me=>me.error??me.id).join(", ")}`):de.success(`Archived ${ge.length} task(s)`),ne(new Set(Y.map(me=>me.id))),_e()}catch(I){de.error(I instanceof Error?I.message:"Failed to archive tasks")}},[pe,_e,es,Me]),eo=a.useCallback(async()=>{const u=Array.from(Me);if(u.length!==0)try{const{results:I}=await Ei(u),Y=I.filter(me=>!me.ok),ge=I.filter(me=>me.ok).map(me=>me.id);ge.length>0&&kt(ge),pe&&ge.includes(pe)&&es(ge,!0),Y.length>0?de.error(`Failed to delete ${Y.length} task(s): ${Y.map(me=>me.error??me.id).join(", ")}`):de.success(`Deleted ${ge.length} task(s)`),ne(new Set(Y.map(me=>me.id))),_e()}catch(I){de.error(I instanceof Error?I.message:"Failed to delete tasks")}},[pe,_e,es,kt,Me]),to=a.useCallback(async()=>{Pe(!0);try{await Di(),h()}catch(u){de.error(u instanceof Error?u.message:"Failed to promote node")}finally{Pe(!1)}},[h]),so=a.useCallback(async()=>{lt(!0);try{await Ai(),de.success("This node left the remote cluster and is leading itself again."),_e(),Ve(),h()}catch(u){de.error(u instanceof Error?u.message:"Failed to leave cluster")}finally{lt(!1)}},[Ve,_e,h]),no=a.useCallback(async u=>{var zt;const I=!dn(u),Y=u.id===((zt=o==null?void 0:o.self)==null?void 0:zt.id),ge=Y?(i==null?void 0:i.transportType)??u.transportType:u.transportType,me=Y&&!I&&Rt(ge);qe(u.id);try{me?await Mi("direct"):await Pi(u.id,I),de.success(I?`Enabled remote access on ${u.name}`:`Disabled remote access on ${u.name}`),h()}catch(Cn){de.error(Cn instanceof Error?Cn.message:"Failed to update remote access")}finally{qe(null)}},[(kn=o==null?void 0:o.self)==null?void 0:kn.id,h,i==null?void 0:i.transportType]),ao=a.useCallback(u=>{ut&&ut(u).catch(I=>{de.error(I instanceof Error?I.message:"Failed to load completed tasks")})},[ut]),vn={toolbarTasks:Ze,activeTaskId:pe,tasksLoading:St,tasksError:rt,isLeader:Te,scope:v,agentFilter:p,nodeFilter:b,taskKindFilter:w,agentOptions:Sr,nodeOptions:Cr,nodeNameById:fn,nodeWorkDirById:Tr,nodeStatusById:_r,leaderNodeId:((Sn=o==null?void 0:o.leader)==null?void 0:Sn.id)??null,searchQuery:D,completedGroupByKey:Er,devBoxNodeIds:yt,devBoxStartNodeIds:Ge,devBoxStartingNodeIds:mt,selectedTaskIds:Me,allVisibleTasksSelected:Mr,someVisibleTasksSelected:Pr,canBatchArchive:Lr,onScopeChange:A,onAgentFilterChange:S,onNodeFilterChange:j,onTaskKindFilterChange:T,onToggleTaskSelected:Zr,onToggleAllVisibleTasks:Xr,onBatchArchive:Jr,onBatchDelete:eo,onCreateTask:Es,onOpenNodeSettings:Te?dt:void 0,onOpenNodeCapabilities:Te?wt:void 0,onOpenProjectCapabilities:Te?Ie:void 0,onOpenDevBox:Te?Nt:void 0,onStartDevBox:Te?ct:void 0,onLoadCompletedTasks:ao,onSelectTask:bn},ro={cluster:o,systemInfo:i,nodeNameById:fn,nodeBlockingTaskCounts:kr,eventTypeFilter:re,onEventTypeFilterChange:ce,eventTypeOptions:ks,filteredEvents:Ar,sseConnected:c,clusterLoading:y,clusterError:g,promotePending:we,onPromote:to,onAddNode:()=>q(!0),leavePending:De,onLeaveCluster:so,onToggleNodeDevTunnel:no,devTunnelNodeId:ye,devBoxStartNodeId:ft,devBoxStartingNodeIds:mt,onOpenNodeSettings:Te?dt:void 0,onOpenNodeCapabilities:Te?wt:void 0,onOpenDevBox:Te?Nt:void 0,onStartDevBox:Te?ct:void 0};return e.jsxs(e.Fragment,{children:[e.jsx(ic,{desktopTasksOpen:E,mobileTasksPanelOpen:F,mobileTasksPanelRef:B,operationsOpen:Q,operationsPanelRef:ee,panelResize:V,taskSidebar:e.jsx(la,{...vn}),operationsSidecar:e.jsx(kc,{...ro}),terminalPanel:r!=null&&r.terminalOpen?e.jsx(pc,{nodes:gn,defaultNodeId:Dr,onClose:()=>r==null?void 0:r.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(Jd,{onToggleTasks:ie,desktopTasksOpen:E,mobileTasksPanelOpen:F,operationsOpen:Q,onToggleOperations:()=>se(u=>!u),cluster:o,sseConnected:c,activeTab:k,setActiveTab:X,creatingTask:L,createMode:_,createDefaults:x,activeTask:oe,assignedNode:Ir,taskLoading:nt,transcriptLoading:Ue,taskError:it,displayEvents:Ts,initialPromptAlreadyInLogs:Fr,initialPrompt:Xt,supportsFollowUp:Br,taskUnavailable:Cs.taskUnavailable,chatDisabled:Cs.chatDisabled,chatDisabledReason:Cs.chatDisabledReason,questionBypassEnabled:J,isRunning:!!Zt,isStarting:Rr,hasPendingFollowUp:Ss,canCancel:!!$r,canRetry:!!Or,onRetry:Qr,onCancel:Wr,onReloadNativeTranscript:qr,onShareTask:Gr,onStopShareTask:Yr,onStartCreateTask:Es,onCancelCreateTask:zr,onCreateTask:Ur,onSendMessage:Hr,onCancelQueuedMessage:Vr,onQuestionBypassChange:O,onSubmitQuestionResponse:Kr,quickChats:Le}),mobileTaskSidebar:e.jsx(la,{...vn,onCreateTask:(u,I)=>{H(!1),Es(u,I)},onSelectTask:u=>{H(!1),bn(u)}}),onCloseOperations:()=>se(!1),onCloseTaskList:()=>H(!1),onToggleOperations:()=>se(u=>!u),onToggleTasks:ie}),e.jsx(sc,{open:M,onOpenChange:q,onAdded:h}),Ae,ze,pt]})}const em=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:Yu},Symbol.toStringTag,{value:"Module"}));export{Ua as A,em as D,fs as G};
|
|
154
|
+
`).map(i=>i.trim()).find(Boolean);return o?o.length>72?`${o.slice(0,69).trimEnd()}...`:o:n?"Image task":""}function Ad(t){var d;const s=t.title.trim(),n=tr(t.title,t.description,t.images.length>0),r=t.description.trim()||n,o=t.mode??qt,i=$a(t.description,t.images);return!n||!r||!t.agent?null:{title:n,description:r,agent:t.agent,project:t.project.trim()||null,branch:((d=t.branch)==null?void 0:d.trim())||null,payload:{initialMessage:i,mode:o,titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function Md({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,className:f,footerClassName:h,submitLabel:y="Create chat",cancelLabel:g="Cancel",autoFocus:l=!1,layout:N="default",quickChats:C=[]}){const[v,A]=a.useState(""),[p,S]=a.useState(""),[b,j]=a.useState(0),[w,T]=a.useState(Tn),[D,U]=a.useState(qt),[E,F]=a.useState((i==null?void 0:i.trim())??""),B=a.useRef(i!==void 0),[Q,ee]=a.useState(""),[V,H]=a.useState("normal"),se=a.useMemo(()=>er(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),ie=a.useMemo(()=>{var ne;return o&&se.some(we=>we.id===o)?o:n&&se.some(we=>we.id===n)?n:((ne=se[0])==null?void 0:ne.id)??""},[se,n,o]),[L,K]=a.useState(ie),[_,W]=a.useState(!1),[x,z]=a.useState(!1),{images:m,error:G,fileInputRef:M,pickImages:q,handleFileChange:k,handlePaste:X,removeImage:re}=Ya(),ce=a.useMemo(()=>se.find(ne=>ne.id===L)??null,[L,se]),J=!!(n&&(ce==null?void 0:ce.id)===n),O=Fa(w),te=Bi(D);a.useEffect(()=>{L&&se.some(ne=>ne.id===L)||K(ie)},[L,se,ie]),a.useEffect(()=>{if(B.current){B.current=!1;return}F(Ja(L)),ee("")},[L]),a.useEffect(()=>{ee("")},[E]),a.useEffect(()=>{j(0)},[p,C]);const le=a.useCallback(ne=>{S(ne.prompt)},[]),R=a.useCallback(async ne=>{ne.preventDefault();const we=os(p,C,b);if(we){le(we);return}const Pe=Ad({title:v,description:p,agent:w,project:E,branch:Q,priority:V,assignTo:L,mode:D,images:m});if(Pe){W(!0);try{const De=await bo(Pe);d(De)}catch(De){de.error(De instanceof Error?De.message:"Failed to create task")}finally{W(!1)}}},[v,p,w,E,Q,V,L,D,m,d,C,b,le]),ae=tr(v,p,m.length>0),ve=!!(ae&&w&&L&&(p.trim()||m.length>0)),Ee=a.useCallback(ne=>{var Pe;if(ne.nativeEvent.isComposing)return;const we=Na(p,C);if(we.length>0&&(ne.key==="ArrowDown"||ne.key==="ArrowUp")){ne.preventDefault(),j(De=>ka(De,we.length,ne.key==="ArrowDown"?1:-1));return}if(ne.key==="Enter"){const De=os(p,C,b);if(De&&!ne.shiftKey){ne.preventDefault(),le(De);return}}ne.key==="Enter"&&(ne.ctrlKey||ne.metaKey)&&ve&&!_&&(ne.preventDefault(),(Pe=ne.currentTarget.form)==null||Pe.requestSubmit())},[le,ve,p,C,b,_]),nt=m.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:m.map((ne,we)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:Ri(ne),alt:ne.filename??`attachment ${we+1}`,className:"h-20 w-20 rounded-sm border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>re(we),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 ${ne.filename??`image ${we+1}`}`,children:e.jsx(tt,{className:"h-3.5 w-3.5"})})]},`${ne.filename??"image"}-${we}`))}),at=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[11px] font-medium",children:"Assign to"}),e.jsxs(ke,{value:L,onValueChange:K,children:[e.jsx(Se,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Be,{placeholder:"Select node"})}),e.jsx(Ce,{children:Gs(se,n)})]})]}),Ue=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[11px] font-medium",children:"Agent"}),e.jsxs(ke,{value:w,onValueChange:T,children:[e.jsx(Se,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Be,{placeholder:"Select agent"})}),e.jsx(Ce,{children:Bn()})]})]}),je=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[11px] font-medium",children:"Mode"}),e.jsxs(ke,{value:D,onValueChange:ne=>U(ne),children:[e.jsx(Se,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Be,{placeholder:"Select mode"})}),e.jsx(Ce,{children:Rn()})]})]}),it=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{className:"text-[11px] font-medium",children:"Priority"}),e.jsxs(ke,{value:V,onValueChange:H,children:[e.jsx(Se,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx(Be,{placeholder:"Select priority"})}),e.jsxs(Ce,{children:[e.jsx(xe,{value:"low",children:"Low"}),e.jsx(xe,{value:"normal",children:"Normal"}),e.jsx(xe,{value:"high",children:"High"}),e.jsx(xe,{value:"critical",children:"Critical"})]})]})]}),We=e.jsx(bs,{value:E,onChange:F,assignTo:L,nodes:t,assignableNodes:se}),Me=e.jsx(Hn,{value:Q,onChange:ee,project:E,assignTo:L,nodes:t,assignableNodes:se});return N==="composer"?e.jsxs("form",{onSubmit:R,className:P("space-y-4",f),children:[e.jsx("input",{ref:M,type:"file",accept:"image/*",multiple:!0,onChange:k,className:"hidden"}),(()=>{const ne="chat-composer__chip h-9 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors",we="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",Pe="border-border/70 bg-background/55 text-foreground",De=w===Tn,lt=D===qt;return e.jsxs("div",{className:"chat-composer space-y-2",children:[e.jsxs("div",{className:"chat-composer__card rounded-sm border border-border/60 bg-background/54 shadow-none backdrop-blur-xl",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(ke,{value:L,onValueChange:K,children:[e.jsx(Se,{className:P(ne,Pe,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${(ce==null?void 0:ce.name)??"unassigned"}`,"aria-label":`Assigned node: ${(ce==null?void 0:ce.name)??"unassigned"}`,children:ce?e.jsxs(e.Fragment,{children:[e.jsx(cn,{isCurrent:J}),e.jsx("span",{className:"min-w-0 truncate",children:ce.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:J?"current":"remote"})]}):e.jsx(Be,{placeholder:"Select node"})}),e.jsx(Ce,{children:Gs(se,n)})]}),x?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(et,{id:"task-title-composer",type:"text",value:v,onChange:ye=>A(ye.target.value),onKeyDown:ye=>{(ye.key==="Enter"||ye.key==="Escape")&&(ye.preventDefault(),z(!1))},autoFocus:!0,placeholder:"Chat title",className:"h-8 w-48 min-w-0 rounded-sm border-border/70 bg-background/55 px-3 text-xs shadow-none"}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",onClick:()=>z(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(Ht,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>z(!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:ae||"Title","aria-label":ae?`Edit title: ${ae}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:ae||"Title"}),e.jsx(Bt,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",value:p,onChange:ye=>S(ye.target.value),onKeyDown:Ee,onPaste:X,placeholder:"Ask anything...",rows:4,autoFocus:l,"aria-label":"Opening prompt",className:"min-h-[140px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm bg-transparent px-5 pt-2 pb-2 text-xs leading-5 text-foreground ring-offset-background placeholder:text-muted-foreground/70 focus-visible:outline-none"}),e.jsx($s,{query:p,quickChats:C,selectedIndex:b,onActiveIndexChange:j,onSelect:le}),e.jsxs("div",{className:"chat-composer__rail flex flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(Z,{type:"button",variant:"ghost",size:"icon",onClick:q,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(qs,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(ke,{value:w,onValueChange:T,children:[e.jsxs(Se,{className:P(ne,"chat-composer__icon-trigger",De?we:Pe),title:`Agent: ${O}`,"aria-label":`Agent: ${O}`,children:[e.jsx(on,{agent:w}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:O})]}),e.jsx(Ce,{children:Bn()})]}),e.jsxs(ke,{value:D,onValueChange:ye=>U(ye),children:[e.jsxs(Se,{className:P(ne,"chat-composer__icon-trigger",lt?we:Pe),title:`Mode: ${te}`,"aria-label":`Mode: ${te}`,children:[e.jsx(Pl,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:te})]}),e.jsx(Ce,{children:Rn()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[e.jsxs(ke,{value:V,onValueChange:H,children:[e.jsx(Se,{"aria-label":`Priority: ${V}`,title:`Priority: ${V}`,className:P("h-9 w-9 justify-center gap-0 rounded-sm p-0 text-xs shadow-none [&>svg:last-child]:hidden",V==="normal"?"border-transparent bg-transparent text-muted-foreground hover:bg-background/40":"border-border/70 bg-background/55",V==="critical"&&"text-destructive",V==="high"&&"text-amber-600 dark:text-amber-400",V==="low"&&"text-muted-foreground"),children:e.jsx(cl,{className:P("h-4 w-4",V==="critical"&&"fill-destructive/20")})}),e.jsxs(Ce,{children:[e.jsx(xe,{value:"low",children:"Low"}),e.jsx(xe,{value:"normal",children:"Normal"}),e.jsx(xe,{value:"high",children:"High"}),e.jsx(xe,{value:"critical",children:"Critical"})]})]}),c&&e.jsxs(Z,{type:"button",variant:"ghost",size:"sm",onClick:c,"aria-label":g,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(tt,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:g})]}),e.jsxs(Z,{type:"submit",size:"icon",disabled:!ve||_,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[_?e.jsx(ue,{className:"h-4 w-4 animate-spin"}):e.jsx(qa,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:_?"Creating chat":y})]})]})]})]}),e.jsx("div",{className:"chat-composer__location flex flex-wrap items-center gap-2 px-1",children:(()=>{const ye="border-border/40 bg-muted/40 text-foreground/80 hover:bg-muted/60 hover:text-foreground";return e.jsxs(e.Fragment,{children:[e.jsx(bs,{value:E,onChange:F,assignTo:L,nodes:t,assignableNodes:se,layout:"composer",chipClassName:ne,chipActiveClassName:ye,chipInactiveClassName:ye,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(Hn,{value:Q,onChange:ee,project:E,assignTo:L,nodes:t,assignableNodes:se,layout:"composer",chipClassName:ne,chipActiveClassName:ye,chipInactiveClassName:ye,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(nt||G)&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/45 p-2.5",children:[nt,G&&e.jsx("div",{className:"text-[11px] text-destructive",children:G}),!G&&e.jsx("div",{className:"text-[11px] 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:R,className:P("space-y-4",f),children:[e.jsx("input",{ref:M,type:"file",accept:"image/*",multiple:!0,onChange:k,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{htmlFor:"task-description",className:"text-[11px] font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",value:p,onChange:ne=>S(ne.target.value),onKeyDown:Ee,onPaste:X,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:l,className:"flex min-h-[128px] w-full resize-none overflow-x-hidden overflow-y-auto rounded-sm border border-border/70 bg-background/70 px-3 py-2 text-xs leading-5 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.jsx($s,{query:p,quickChats:C,selectedIndex:b,onActiveIndexChange:j,onSelect:le}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Z,{type:"button",variant:"outline",onClick:q,className:"rounded-sm",children:[e.jsx(qs,{className:"h-4 w-4"}),"Add images"]}),e.jsx("p",{className:"text-[11px] 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."})]}),nt,G&&e.jsx("p",{className:"text-[11px] text-destructive",children:G})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_190px_190px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{htmlFor:"task-title",className:"text-[11px] font-medium",children:"Chat title"}),e.jsx(et,{id:"task-title",type:"text",value:v,onChange:ne=>A(ne.target.value),placeholder:"Optional. Leave blank to derive it from the prompt.",className:"h-8 rounded-sm border-border/70 bg-background/70"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:ae?`Will appear as: ${ae}`:"A title will be generated from the first line of the prompt."})]}),Ue,je]}),We,Me,e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[it,at]}),e.jsxs("div",{className:P("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",h),children:[c&&e.jsx(Z,{type:"button",variant:"ghost",onClick:c,className:"rounded-sm",children:g}),e.jsx(Z,{type:"submit",disabled:!ve||_,className:"rounded-sm px-5",children:_?"Creating...":y})]})]})}function Pd({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,defaultMode:f="chat",mode:h,onModeChange:y,layout:g="default",className:l,footerClassName:N,autoFocus:C=!1,quickChats:v=[]}){const[A,p]=a.useState(f),S=h!==void 0,b=S?h:A,j=w=>{S||p(w),y==null||y(w)};return e.jsxs("div",{className:P("space-y-4",l),children:[!S&&e.jsxs("div",{className:"flex h-8 items-center gap-0.5 rounded-sm border border-border/60 bg-background/45 p-0.5",children:[e.jsxs(Z,{type:"button",variant:b==="chat"?"default":"ghost",onClick:()=>j("chat"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(go,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(Z,{type:"button",variant:b==="native"?"default":"ghost",onClick:()=>j("native"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(ln,{className:"h-4 w-4"}),"Load session"]})]}),b==="chat"?e.jsx(Md,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:o,initialProject:i,onCreated:d,onCancel:c,footerClassName:N,submitLabel:g==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:C,layout:g,quickChats:v},`${o??""}:${i??""}`):e.jsx(Dd,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:d,onCancel:c,footerClassName:N,autoFocus:C})]})}function Ld({onClick:t,running:s}){return e.jsxs(Z,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:P("absolute bottom-4 right-4 z-10 h-12 w-12 overflow-visible rounded-lg shadow-lg",s&&"animate-soft-status-pulse bg-primary/90 text-primary-foreground hover:bg-primary"),children:[e.jsx(Bt,{className:"h-4 w-4"}),s&&e.jsx("span",{"aria-hidden":"true","data-running-indicator":"true",className:"pointer-events-none absolute right-1.5 top-1.5 h-2 w-2 rounded-full bg-primary-foreground shadow-[0_0_0_2px_hsl(var(--primary))]"})]})}function Kn({children:t}){return e.jsxs("div",{className:"agent-progress-banner animate-message-receive 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:t})]})}function Id({hasVisibleTranscriptEvents:t,hasTranscriptProgress:s,inputCollapsed:n}){return{collapsedButtonRunning:s&&t&&n,showDockedProgress:s&&t&&!n,showInlineProgress:s&&!t}}const Et="72f988bf-86f1-41af-91ab-2d7cd011db47",sr=`${Et} (MSIT)`;function Bd({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:o,stopping:i=!1,shareResult:d}){return e.jsx(Lt,{open:t,onOpenChange:s,children:e.jsxs(It,{className:"max-w-md rounded-sm p-4",children:[e.jsx(Yt,{className:"sr-only",children:"Share conversation"}),e.jsx(Rd,{onOpenChange:s,onShare:n,onStopShare:r,sharing:o,stopping:i,shareResult:d})]})})}function Rd({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:o=!1,shareResult:i}){const[d,c]=a.useState((i==null?void 0:i.tenant)??Et),[f,h]=a.useState((i==null?void 0:i.scope)??"chat"),y=i!=null&&i.url?_a(i.url):null,g=r||o;return a.useEffect(()=>{c((i==null?void 0:i.tenant)??Et),h((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-sm 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($d,{value:d,onChange:c,disabled:g}),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(Wn,{active:f==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>h("chat")}),e.jsx(Wn,{active:f==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>h("filesPreview")})]})]}),y&&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:y,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>void _t(y,"Shared link copied"),"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ea,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e.jsx(Z,{variant:"outline",onClick:()=>t(!1),disabled:g,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(Z,{variant:"outline",onClick:()=>void n(),disabled:g,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[o&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(Z,{onClick:()=>void s({tenant:d,scope:f}),disabled:g,className:"h-8 text-xs",children:[r&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function $d({value:t,onChange:s,disabled:n}){const[r,o]=a.useState(!1),[i,d]=a.useState(!1),[c,f]=a.useState(t),h=a.useRef(null);a.useEffect(()=>{f(t)},[t]),a.useEffect(()=>{if(!r)return;const g=N=>{var v;const C=N.target;C instanceof Node&&((v=h.current)!=null&&v.contains(C)||(o(!1),d(!1)))},l=N=>{N.key==="Escape"&&(o(!1),d(!1))};return document.addEventListener("mousedown",g),document.addEventListener("keydown",l),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",l)}},[r]);const y=g=>{const l=g.trim();l&&(s(l),f(l),d(!1),o(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:h,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&o(g=>!g),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:Od(t)}),e.jsx(st,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),r&&e.jsxs("div",{className:"absolute left-0 right-0 z-50 mt-2 overflow-hidden rounded-sm border border-border/60 bg-background/95 text-xs shadow-[0_16px_48px_-34px_rgba(0,0,0,0.45)] backdrop-blur",children:[e.jsxs("button",{type:"button",onClick:()=>y(Et),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:sr}),t===Et&&e.jsx(Ht,{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:c,onChange:g=>f(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),y(c))},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:()=>y(c),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(Ht,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{f(t),d(!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(tt,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>d(!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(Bt,{className:"h-3 w-3"})]})})]})]})]})}function Od(t){return t===Et?sr:t}function Wn({active:t,title:s,description:n,onClick:r}){return e.jsxs("button",{type:"button",onClick:r,className:t?"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:s}),e.jsx("div",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:n})]})}function Fd(t){const s=t.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 s?s.length>160?`${s.slice(0,157)}...`:s:"Queued follow-up"}function zd({messages:t,onCancelMessage:s}){return t.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(Nl,{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:t.length})]}),e.jsx("div",{className:"mt-2 space-y-1.5",children:t.map((n,r)=>{const o=n.content.filter(i=>i.type==="image");return 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:r+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"break-words [overflow-wrap:anywhere]",children:Fd(n.content)}),o.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:o.map((i,d)=>e.jsx(Oa,{image:i,alt:i.filename??`queued attachment ${d+1}`,thumbnailClassName:"h-14 w-14 border border-border/65",imageClassName:"h-full w-full"},`${i.filename??"image"}-${d}`))})]}),s&&e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 rounded-sm text-muted-foreground hover:text-destructive",title:"Cancel queued message","aria-label":"Cancel queued message",onClick:()=>s(n.id),children:e.jsx(tt,{className:"h-3 w-3"})})]},n.id)})})]})})}const Ud="h-6 w-6 rounded-none border-b border-transparent !bg-transparent p-0 text-muted-foreground !shadow-none hover:text-foreground data-[state=active]:border-primary data-[state=active]:!bg-transparent data-[state=active]:text-primary data-[state=active]:!shadow-none",Vd=[{value:"transcript",label:"Transcript",icon:vo},{value:"files",label:"Files",icon:Pt,activeIcon:ws},{value:"diff",label:"Diff",icon:fs},{value:"preview",label:"Preview",icon:Wi}];function Hd({activeTab:t}){return e.jsx(Js,{className:"h-auto max-w-full justify-start gap-2 overflow-x-auto rounded-sm !bg-muted/40 !p-0.5 !shadow-none",children:Vd.map(s=>{const n=s.value===t&&s.activeIcon?s.activeIcon:s.icon;return e.jsx(bt,{value:s.value,title:s.label,"aria-label":s.label,className:Ud,children:e.jsx(n,{className:"h-3.5 w-3.5","aria-hidden":"true"})},s.value)})})}const Gn="h-[1.625rem] rounded-sm !border-0 !bg-transparent px-2 text-[10.5px] font-medium text-primary !shadow-none hover:!bg-transparent hover:text-primary/80 focus-visible:ring-1 focus-visible:ring-ring/50 focus-visible:ring-offset-0",gt={content:"max-w-[20rem] gap-2.5 rounded-lg border-0 p-3.5 shadow-[0_18px_70px_-44px_rgba(0,0,0,0.72)] sm:max-w-[20rem]",header:"space-y-1 text-left",title:"text-[13px] leading-4",description:"text-[11px] leading-4",footer:"gap-1 pt-0 sm:space-x-1",cancel:`${Gn} mt-0`,action:Gn},qd=30,Kd=1600;function Wd({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Ls(t){return t.scrollHeight-t.scrollTop-t.clientHeight<qd}function Yn({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function Gd({atTop:t,inputCollapseDisabled:s,scrollingUp:n}){return!s&&(n||t)}function Yd({activeTab:t,activeTaskId:s,contentVersion:n,inputCollapseDisabled:r=!1,setActiveTab:o,setInputCollapsed:i}){const d=a.useRef(null),c=a.useRef(s),f=a.useRef(!1),h=a.useRef(0),y=a.useRef(new Map),g=a.useRef(0),l=a.useRef(!0),N=a.useCallback((b=c.current)=>{const j=d.current;!j||!b||(y.current.set(b,j.scrollTop),h.current=j.scrollTop,l.current=Ls(j))},[]),C=a.useCallback((b=c.current)=>{const j=d.current;!j||!b||(j.scrollTop=Wd({savedScrollTop:y.current.get(b),scrollHeight:j.scrollHeight,clientHeight:j.clientHeight}),h.current=j.scrollTop,l.current=Ls(j))},[]),v=a.useCallback((b,j=c.current)=>{b.scrollTop=b.scrollHeight,h.current=b.scrollTop,l.current=!0,j&&y.current.set(j,b.scrollTop)},[]),A=a.useCallback((b=c.current)=>{const j=d.current;g.current=Date.now()+Kd,j&&(v(j,b),requestAnimationFrame(()=>{v(j,b),requestAnimationFrame(()=>v(j,b))}))},[v]),p=a.useCallback(b=>{const j=b.currentTarget,w=h.current,T=j.scrollTop<w&&w-j.scrollTop>10,D=j.scrollTop<=0;if(N(),!f.current){if(Ls(j)){i(!1),f.current=!0,setTimeout(()=>{f.current=!1},300);return}(T||D)&&(g.current=0,Gd({atTop:D,inputCollapseDisabled:r,scrollingUp:T})&&i(!0))}},[r,N,i]),S=a.useCallback(b=>{t==="transcript"&&N(),o(b),b==="transcript"&&requestAnimationFrame(()=>C())},[t,C,N,o]);return a.useLayoutEffect(()=>{r&&i(!1)},[r,i]),a.useLayoutEffect(()=>{const b=c.current;b&&b!==s&&N(b),c.current=s,t==="transcript"&&requestAnimationFrame(()=>C(s))},[s,t,C,N]),a.useLayoutEffect(()=>{const b=d.current;if(!b||t!=="transcript"||!s)return;Yn({explicitBottomStickUntil:g.current,now:Date.now(),wasAtBottom:l.current})&&v(b,s),N(s)},[s,t,n,N,v]),a.useLayoutEffect(()=>{const b=d.current,j=b==null?void 0:b.firstElementChild;if(!b||!j||t!=="transcript"||typeof ResizeObserver>"u")return;const w=new ResizeObserver(()=>{Yn({explicitBottomStickUntil:g.current,now:Date.now(),wasAtBottom:l.current})?v(b):N()});return w.observe(b),w.observe(j),()=>w.disconnect()},[t,s,N,v]),{handleTranscriptScroll:p,handleTranscriptTabChange:S,scrollTranscriptToBottom:A,transcriptScrollRef:d}}function nr(t=700){const[s,n]=a.useState(!1),r=a.useRef(null),o=a.useCallback(()=>{n(!0),r.current!==null&&clearTimeout(r.current),r.current=setTimeout(()=>{n(!1),r.current=null},t)},[t]);return a.useEffect(()=>()=>{r.current!==null&&clearTimeout(r.current)},[]),{markScrollbarActive:o,scrollbarActive:s}}const un="pointer-events-auto h-5 w-5 shrink-0 rounded-full bg-muted/65 text-muted-foreground hover:bg-muted hover:text-foreground",Dt="h-3.5 w-3.5",Qd=a.lazy(async()=>({default:(await tn(()=>import("./FilesTab-jB5PuAMB.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Zd=a.lazy(async()=>({default:(await tn(()=>import("./PreviewTab-5-N4l7V3.js").then(s=>s.c),__vite__mapDeps([6,1,2]))).PreviewTab})),Xd=a.lazy(async()=>({default:(await tn(()=>import("./DiffTab-3q3jwsm4.js"),__vite__mapDeps([7,1,2,5,4,3,6]))).DiffTab}));function Jd({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,activeTab:c,setActiveTab:f,creatingTask:h,createMode:y,createDefaults:g,activeTask:l,assignedNode:N,taskLoading:C,transcriptLoading:v,taskError:A,displayEvents:p,initialPromptAlreadyInLogs:S,initialPrompt:b,supportsFollowUp:j,taskUnavailable:w,chatDisabled:T,chatDisabledReason:D,questionBypassEnabled:U,isRunning:E,isStarting:F,hasPendingFollowUp:B,canCancel:Q,canRetry:ee,onRetry:V,onCancel:H,onReloadNativeTranscript:se,onShareTask:ie,onStopShareTask:L,onStartCreateTask:K,onCancelCreateTask:_,onCreateTask:W,onSendMessage:x,onCancelQueuedMessage:z,onQuestionBypassChange:m,onSubmitQuestionResponse:G,quickChats:M=[]}){const[q,k]=a.useState(!1),[X,re]=a.useState(!1),[ce,J]=a.useState(!1),[O,te]=a.useState(!1),[le,R]=a.useState(!1),[ae,ve]=a.useState({}),[Ee,nt]=a.useState(new Set),[at,Ue]=a.useState(new Set),[je,it]=a.useState(null),We=(l==null?void 0:l.effectiveProjectPath)??(l==null?void 0:l.project)??"default workspace",Me=l?(N==null?void 0:N.name)??Os(l.assignedTo,i==null?void 0:i.nodes,l.assignedNodeName):"unassigned",ne=l!=null&&l.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:Me}),"..."]}):"Connecting session to an available node...",we=l?[{label:"Working dir",value:We,mono:!0},...l.branch?[{label:"Branch",value:l.branch,mono:!0}]:[],{label:"Agent",value:l.agent,mono:!0},{label:"Node",value:Me}]:[],Pe=!!(b&&!S),De=Pe||p.length>0,lt=E&&De,ye=(F||B||E)&&!lt,qe=lt?"The agent is still working on this conversation.":ye?ne:null,{collapsedButtonRunning:$e,showDockedProgress:jt,showInlineProgress:Te}=Id({hasTranscriptProgress:!!qe,hasVisibleTranscriptEvents:De,inputCollapsed:q}),$=(l==null?void 0:l.conversationKind)==="nativeSession",Le=v?"Loading transcript":$?"No transcript imported":"Transcript is warming up",Ae=v?"Loading transcript...":$?"Meshy could not find imported history for this native session yet.":"The opening prompt has been stored, but the agent has not emitted conversation output yet.",dt=(l==null?void 0:l.queuedMessages)??[],pt=a.useMemo(()=>$i(p),[p]),wt=a.useMemo(()=>Oi("transcript",pt.map(fe=>fe.event)),[pt]),Ie=l&&!Ee.has(l.id)?ae[l.id]??l.activeShare??null:null,ze=(l==null?void 0:l.id)??null,yt=`${ze??"none"}:${p.length}:${dt.length}:${Pe?1:0}:${v?1:0}:${Te?1:0}`,{handleTranscriptScroll:ft,handleTranscriptTabChange:Ge,scrollTranscriptToBottom:mt,transcriptScrollRef:Nt}=Yd({activeTab:c,activeTaskId:ze,contentVersion:yt,inputCollapseDisabled:!!qe,setActiveTab:f,setInputCollapsed:k}),{markScrollbarActive:ct,scrollbarActive:Ne}=nr(),_e=a.useCallback(fe=>{ct(),ft(fe)},[ft,ct]),ut=a.useCallback(fe=>{it(be=>({path:fe,requestId:((be==null?void 0:be.requestId)??0)+1})),Ge("files")},[Ge]),kt=a.useCallback(fe=>{mt(),x(fe)},[x,mt]);return a.useEffect(()=>{it(null)},[ze]),h?e.jsx(ec,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,defaultMode:y,createDefaults:g,onCancel:_,onCreated:W,quickChats:M}):!l&&C?e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ys,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"space-y-3 text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(ue,{className:"h-5 w-5 animate-spin"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm 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-3.5 w-3.5 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):l?e.jsxs(en,{value:c,onValueChange:Ge,className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsxs("div",{className:"dashboard-conversation-panel__header relative shrink-0 bg-card/28 px-3 pb-0.5 pt-1 sm:px-5 sm:pt-1.5",children:[e.jsxs("div",{className:"pointer-events-none absolute left-1 right-1 top-2 flex items-center justify-between sm:left-1.5 sm:right-1.5 sm:top-2.5",children:[e.jsx(ar,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:o,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:P(un,"xl:hidden"),children:r?e.jsx(He,{className:Dt}):e.jsx(Wt,{className:Dt})})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx("h2",{className:"min-w-0 truncate text-[13px] font-semibold leading-5 text-foreground sm:text-[15px]",title:l.title,children:l.title}),e.jsx(Da,{status:l.status,isNative:$}),l.priority!=="normal"&&e.jsx(wo,{priority:l.priority})]}),A&&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:A}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx(Hd,{activeTab:c}),w&&e.jsx(Fe,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"hidden rounded-sm bg-muted/65 px-1.5 py-0.5 tabular-nums sm:inline-flex",children:yo(l.updatedAt)}),ee&&e.jsxs(Z,{variant:"outline",size:"sm",onClick:V,className:"h-7 shrink-0 rounded-sm px-2 text-[11px]",children:[e.jsx(_l,{className:"h-3.5 w-3.5"}),"Retry"]}),$&&se&&e.jsx(Z,{variant:"ghost",size:"icon",onClick:se,disabled:v,title:"Reload native session transcript","aria-label":"Reload native session transcript",className:"h-6 w-6 shrink-0 rounded-sm text-muted-foreground hover:bg-muted/55 hover:text-foreground",children:e.jsx(Ha,{className:P("h-3.5 w-3.5",v&&"animate-spin")})}),e.jsx(Z,{type:"button",variant:"ghost",size:"icon",disabled:w,title:w?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":w?"Unavailable tasks cannot be shared.":"Share conversation",className:"h-6 w-6 shrink-0 rounded-sm text-primary hover:bg-primary/10 hover:text-primary disabled:bg-transparent disabled:text-muted-foreground",onClick:()=>J(!0),children:e.jsx(gs,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(ot,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"relative min-h-0 flex-1",children:e.jsx("div",{ref:Nt,"data-transcript-scroll":"true",className:P("scrollbar-line h-full min-h-0 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 pb-4 pt-4 sm:px-5",Ne&&"scrollbar-line-active"),onScroll:_e,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[Pe&&b&&e.jsx($n,{event:b,agent:l.agent,taskRootPath:l.effectiveProjectPath,onOpenFilePath:ut,questionBypassEnabled:U,onQuestionBypassChange:m,onSubmitQuestionResponse:G,questionResponseDisabled:!j||T}),pt.map(({event:fe,subItems:be},rt)=>e.jsx($n,{event:fe,agent:l.agent,subItems:be,taskRootPath:l.effectiveProjectPath,onOpenFilePath:ut,questionBypassEnabled:U,onQuestionBypassChange:m,onSubmitQuestionResponse:G,questionResponseDisabled:!j||T},wt[rt])),!De&&!ye&&e.jsxs("div",{className:"rounded-sm border border-dashed border-border/70 bg-background/35 px-3 py-4 text-center",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:Le}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Ae})]}),(!j&&l.result||l.error)&&e.jsxs("div",{className:"space-y-3",children:[!j&&l.result&&e.jsxs("div",{className:"rounded-sm 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&&!at.has(l.id)&&e.jsxs("div",{className:"rounded-sm 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:()=>Ue(fe=>new Set(fe).add(l.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(tt,{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})]})]}),Te&&qe&&e.jsx(Kn,{children:qe})]})})}),jt&&qe&&e.jsx("div",{"data-docked-progress":"true",className:"shrink-0 bg-background/35 px-3 py-1 sm:px-5",children:e.jsx("div",{className:"mx-auto max-w-[72rem]",children:e.jsx(Kn,{children:qe})})}),j?e.jsxs(e.Fragment,{children:[q&&e.jsx(Ld,{running:$e,onClick:()=>{k(!1),mt(),requestAnimationFrame(()=>{var fe;return(fe=document.querySelector('[data-chat-input-textarea="true"]'))==null?void 0:fe.focus()})}}),e.jsxs("div",{className:`shrink-0 ${q?"hidden":""}`,children:[e.jsx(zd,{messages:dt,onCancelMessage:z}),e.jsx(nd,{onSend:kt,disabled:T,disabledReason:D,contextItems:we,placeholder:T?D:E?"Queue a message for the next turn...":"Continue the conversation...",running:E||B,onStop:Q?()=>re(!0):void 0,quickChats:M})]})]}):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(ot,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ms,{label:"Loading files..."}),children:e.jsx(Qd,{taskId:l.id,requestedFilePath:(je==null?void 0:je.path)??null,requestedFileRequestId:(je==null?void 0:je.requestId)??0})})}),e.jsx(ot,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ms,{label:"Loading preview..."}),children:e.jsx(Zd,{taskId:l.id})})}),e.jsx(ot,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(a.Suspense,{fallback:e.jsx(Ms,{label:"Loading diff..."}),children:e.jsx(Xd,{taskId:l.id})})}),e.jsx(is,{open:X,onOpenChange:re,children:e.jsxs(ls,{className:gt.content,children:[e.jsxs(ds,{className:gt.header,children:[e.jsx(cs,{className:gt.title,children:"Stop this task?"}),e.jsx(us,{className:gt.description,children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ms,{className:gt.footer,children:[e.jsx(xs,{className:gt.cancel,children:"Keep running"}),e.jsx(hs,{className:gt.action,onClick:H,children:"Stop task"})]})]})}),e.jsx(Bd,{open:ce,onOpenChange:J,sharing:O,stopping:le,shareResult:Ie,onShare:async fe=>{if(!l)return null;te(!0);try{const be=await ie(fe);return be!=null&&be.url&&(ve(rt=>({...rt,[l.id]:be})),nt(rt=>{const St=new Set(rt);return St.delete(l.id),St})),be}finally{te(!1)}},onStopShare:async()=>{if(!l)return!1;R(!0);try{const fe=await L();return fe!==!1&&(ve(be=>{const rt={...be};return delete rt[l.id],rt}),nt(be=>new Set(be).add(l.id))),fe}finally{R(!1)}}})]}):e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ys,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsxs("div",{className:"w-full max-w-lg text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-sm border border-primary/20 bg-primary/10 text-primary shadow-none",children:e.jsx(jo,{className:"h-5 w-5"})}),e.jsx("h2",{className:"mt-3 text-sm font-semibold tracking-tight text-foreground sm:text-[15px]",children:"No chat selected"}),e.jsx("p",{className:"mx-auto mt-2 max-w-md text-[11px] leading-5 text-muted-foreground",children:"Open a task from the left sidebar to continue the conversation, or start a new task or load a native session."}),e.jsxs(Z,{onClick:()=>K(),className:"mt-4 h-8 rounded-sm px-3",children:[e.jsx(ys,{className:"h-3.5 w-3.5"}),"Start or load chat"]}),A&&e.jsx("div",{className:"mx-auto mt-3 max-w-md rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] text-destructive",children:A})]})})]})}function ec({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,defaultMode:c,createDefaults:f,onCancel:h,onCreated:y,quickChats:g}){var v,A,p;const[l,N]=a.useState(c??"chat");a.useEffect(()=>{c&&N(c)},[c]);const C=e.jsx("div",{className:"flex h-8 items-center gap-0.5 overflow-hidden rounded-sm border border-border/60 bg-background/65 p-0.5 text-[11px] font-medium shadow-none",children:[{value:"chat",label:"New chat",icon:ys},{value:"native",label:"Load session",icon:ln}].map(S=>{const b=S.icon,j=S.value===l;return e.jsxs("button",{type:"button",onClick:()=>N(S.value),"aria-pressed":j,className:P("flex h-7 min-w-28 items-center justify-center gap-1.5 rounded-sm border border-transparent px-2.5 transition-colors duration-150",j?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(b,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:S.label})]},S.value)})});return e.jsxs("div",{className:"dashboard-conversation-panel dashboard-panel animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:[e.jsx("div",{className:"dashboard-conversation-panel__header shrink-0 bg-card/28 px-3 py-3 sm:px-5",children:e.jsx(Ys,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,cluster:i,sseConnected:d,centerSlot:C})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-6 sm:px-6",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsx(Pd,{nodes:(i==null?void 0:i.nodes)??[],currentNodeRole:(v=i==null?void 0:i.self)==null?void 0:v.role,currentNodeId:((A=i==null?void 0:i.self)==null?void 0:A.id)??null,leaderNodeId:((p=i==null?void 0:i.leader)==null?void 0:p.id)??null,initialAssignTo:f==null?void 0:f.assignTo,initialProject:f==null?void 0:f.project,mode:l,onModeChange:N,onCreated:y,onCancel:h,autoFocus:!0,layout:"composer",quickChats:g})})})]})}function Ys({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:o,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(ar,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"})}),i&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",children:e.jsx("div",{className:"pointer-events-auto",children:i})}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:o,title:r?"Hide cluster":"Show cluster","aria-label":r?"Hide cluster":"Show cluster",className:P(un,"xl:hidden"),children:r?e.jsx(He,{className:Dt}):e.jsx(Wt,{className:Dt})})]})}function ar({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){var i,d;const o=(d=(i=globalThis.window)==null?void 0:i.matchMedia("(min-width: 1024px)"))!=null&&d.matches?s:n;return e.jsx(Z,{variant:"ghost",size:"icon",onClick:r,title:o?"Hide tasks":"Show tasks","aria-label":o?"Hide tasks":"Show tasks",className:P(un,t),children:o?e.jsx(Wt,{className:Dt}):e.jsx(He,{className:Dt})})}function tc({onAdded:t}){const[s,n]=a.useState(""),[r,o]=a.useState(!1),[i,d]=a.useState(null),c=a.useCallback(async f=>{if(f.preventDefault(),!!s.trim()){o(!0),d(null);try{await No({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(h){d(h instanceof Error?h.message:"Failed to join node")}finally{o(!1)}}},[s,t]);return e.jsx(It,{className:"overflow-hidden border-border/60 bg-transparent p-0 shadow-none sm:max-w-xl",children:e.jsxs("div",{className:"overflow-hidden rounded-sm border border-border/60 bg-background/95 p-0 shadow-[0_28px_90px_-58px_rgba(0,0,0,0.88)] backdrop-blur-xl",children:[e.jsx("div",{className:"border-b border-border/60 px-3.5 py-2.5",children:e.jsxs(sn,{className:"space-y-1 text-left",children:[e.jsx(Yt,{className:"text-sm tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-[11px] 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:c,className:"space-y-3 px-3.5 py-3",children:[i&&e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-3 py-2 text-[11px] 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(Oe,{htmlFor:"leader-endpoint",children:"Leader endpoint"}),e.jsx(Fe,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(et,{id:"leader-endpoint",type:"url",value:s,onChange:f=>n(f.target.value),placeholder:"https://your-leader.devtunnels.ms",className:"h-8 rounded-sm border-border/70 bg-background/70"})]}),e.jsx("div",{className:"rounded-sm border border-border/60 bg-background/45 px-3 py-2 text-[11px] 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(Aa,{className:"border-t border-border/60 pt-3",children:e.jsx(Z,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function sc({open:t,onOpenChange:s,onAdded:n}){return e.jsx(Lt,{open:t,onOpenChange:s,children:e.jsx(tc,{onAdded:()=>{s(!1),n()}})})}const nc="absolute top-1/2 z-30 hidden h-10 w-4 -translate-y-1/2 items-center justify-center rounded-full text-muted-foreground opacity-0 outline-none transition-opacity duration-150 hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/55",ac="flex h-7 w-3.5 items-center justify-center rounded-full bg-muted/85 shadow-[0_12px_24px_-20px_rgba(0,0,0,0.9)] backdrop-blur-sm transition-colors hover:bg-card hover:text-foreground",rc="h-2.5 w-2.5";function rr({className:t,label:s,orientation:n,panel:r,panelResize:o}){return e.jsx("button",{type:"button","aria-label":s,"aria-orientation":n,"data-dashboard-resize-handle":r,onPointerDown:i=>o.onPointerDown(r,i),onWheel:i=>o.onWheel(r,i),className:P("group absolute z-20 hidden touch-none rounded-sm bg-transparent outline-none transition-colors hover:bg-primary/12 focus-visible:bg-primary/12 focus-visible:ring-2 focus-visible:ring-ring/70 lg:block",t),children:e.jsx("span",{className:"pointer-events-none absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100"})})}function oc({className:t,label:s,onToggle:n,side:r,visible:o}){const i=r==="left"?o?Wt:He:o?He:Wt;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:P(nc,t),children:e.jsx("span",{className:ac,"aria-hidden":"true",children:e.jsx(i,{className:rc,strokeWidth:2.1})})})}function Qn({className:t,label:s,onToggle:n,panel:r,panelResize:o,screen:i,side:d,visible:c}){const f=i==="lg"?"lg:block":"xl:block",h=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:P("group absolute top-0 z-30 hidden h-full w-4",f,t),children:[r&&e.jsx(rr,{panel:r,orientation:"vertical",label:`Resize ${r} panel`,panelResize:o,className:"left-1/2 top-0 h-full w-2 -translate-x-1/2 cursor-col-resize"}),e.jsx(oc,{side:d,visible:c,label:s,onToggle:n,className:P(h,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function ic({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:o,operationsOpen:i,operationsPanelRef:d,operationsSidecar:c,panelResize:f,taskSidebar:h,terminalPanel:y,onCloseOperations:g,onCloseTaskList:l,onToggleOperations:N,onToggleTasks:C}){const v={"--dashboard-tasks-width":f.sizes.tasks,"--dashboard-operations-width":f.sizes.operations,"--dashboard-terminal-height":f.sizes.terminal};return e.jsxs("div",{className:"dashboard-workspace flex h-full min-h-0 flex-col overflow-hidden",style:v,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(Qn,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:C,panel:s?"tasks":void 0,panelResize:f,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:P("dashboard-workspace__tasks-panel relative hidden lg:block lg:shrink-0 lg:transition-all lg:duration-300",s?"lg:mr-2 lg:w-[var(--dashboard-tasks-width)]":"lg:w-0 lg:overflow-hidden"),children:s&&h}),e.jsxs("section",{className:"dashboard-workspace__primary flex min-h-0 min-w-0 flex-1 flex-col gap-2",children:[e.jsx("div",{className:"min-h-0 flex-1",children:t}),y&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(rr,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:f,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),y]})]}),e.jsx(Qn,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:N,panel:i?"operations":void 0,panelResize:f,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:P("dashboard-workspace__operations-panel relative hidden xl:block xl:shrink-0 xl:transition-all xl:duration-300",i?"xl:ml-2 xl:w-[var(--dashboard-operations-width)]":"xl:w-0 xl:overflow-hidden"),children:i&&c})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close operations panel",onClick:g,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:d,className:"fixed bottom-0 right-0 top-[var(--dashboard-mobile-overlay-top)] z-40 w-full p-2 sm:max-w-sm sm:p-3 xl:hidden",children:c})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"Close task list",onClick:l,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:o,className:"fixed bottom-0 left-0 top-[var(--dashboard-mobile-overlay-top)] z-40 w-full p-2 sm:max-w-sm sm:p-3 lg:hidden",children:n})]})]})}const lc=10,vt="__all__";function Ke(t){return"session"in t}function Zn(t,s){var n;return s&&t.some(r=>r.id===s)?s:((n=t[0])==null?void 0:n.id)??""}function Is(t){return t&&(Ja(t.id)||t.workDir)||""}function ss(t,s,n){let r=!1;const o=t.map(i=>Ke(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return Qs(r?o:[...o,{id:`session-${n.id}`,nodeName:s,session:n}])}function or(t,s){return t.filter(Ke).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function dc(t){const s=t.filter(Ke).sort((n,r)=>r.session.startedAt-n.session.startedAt);return{active:s.filter(n=>n.session.status==="running"),completed:s.filter(n=>n.session.status!=="running")}}function cc(t,s){return!!(t&&s&&!t.contains(s))}function uc(t,s,n){var o;if(n===vt)return n;const r=or(t,s);return r.some(i=>i.session.id===n)?n:((o=r[0])==null?void 0:o.session.id)??vt}function mc(t,s,n){return n===vt?t.filter(r=>!Ke(r)||r.session.nodeId===s):t.filter(r=>Ke(r)&&r.session.nodeId===s&&r.session.id===n)}function Qs(t){const s=t.map((r,o)=>({entry:r,index:o})).filter(({entry:r})=>Ke(r)&&r.session.status!=="running").sort((r,o)=>!Ke(r.entry)||!Ke(o.entry)?0:o.entry.session.startedAt-r.entry.session.startedAt||o.index-r.index),n=new Set(s.slice(0,lc).map(({entry:r})=>Ke(r)?r.session.id:""));return t.filter(r=>!Ke(r)||r.session.status==="running"||n.has(r.session.id))}function Zs(t){return t.status==="running"?t.pid?`running pid ${t.pid}`:"running":t.status==="exited"?`exit ${t.exitCode??0}`:t.status==="stopped"?"stopped":t.signal?`failed ${t.signal}`:`exit ${t.exitCode??"failed"}`}function xc(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${Zs(t.session)} - ${s}`}function ir(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function hc(t,s){return s===vt?"All sessions":t?ir(t.session.command,34):"Command session"}function Xn(t){return t.status==="stopped"?"":t.stderr}function pc({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[o,i]=a.useState(()=>Zn(t,s)),d=a.useMemo(()=>t.find(m=>m.id===o)??t[0]??null,[t,o]),[c,f]=a.useState(()=>Is(d)),[h,y]=a.useState(""),[g,l]=a.useState(()=>Qs(r)),[N,C]=a.useState(vt),[v,A]=a.useState(!1),[p,S]=a.useState(!1),[b,j]=a.useState(!1),[w,T]=a.useState(!1),[D,U]=a.useState(!1),E=a.useRef(null),F=a.useRef(null),B=a.useMemo(()=>t.find(m=>m.id===o)??t[0]??null,[t,o]),Q=a.useMemo(()=>or(g,(B==null?void 0:B.id)??""),[g,B]),ee=a.useMemo(()=>dc(Q),[Q]),V=a.useMemo(()=>Q.find(m=>m.session.id===N),[N,Q]),H=a.useMemo(()=>mc(g,(B==null?void 0:B.id)??"",N),[g,B,N]),se=a.useRef((B==null?void 0:B.id)??"");a.useEffect(()=>{o&&t.some(m=>m.id===o)||i(Zn(t,s))},[s,t,o]),a.useEffect(()=>{const m=(B==null?void 0:B.id)??"";se.current!==m&&(se.current=m,f(Is(B)))},[B]),a.useEffect(()=>{C(m=>uc(g,(B==null?void 0:B.id)??"",v?m:""))},[g,B,v]),a.useEffect(()=>{var m;(m=E.current)==null||m.scrollTo({top:E.current.scrollHeight})},[g]),a.useEffect(()=>{let m=!1;async function G(){const M=await Promise.allSettled(t.map(async q=>({node:q,response:await So(q.id)})));m||l(q=>M.reduce((k,X)=>X.status!=="fulfilled"?k:X.value.response.sessions.reduce((re,ce)=>ss(re,X.value.node.name,ce),k),q))}return t.length>0&&G(),()=>{m=!0}},[t]),a.useEffect(()=>{const m=g.filter(Ke).filter(M=>M.session.status==="running");if(m.length===0)return;const G=window.setInterval(()=>{for(const M of m)ko(M.session.nodeId,M.session.id).then(q=>l(k=>ss(k,M.nodeName,q))).catch(()=>{})},1e3);return()=>window.clearInterval(G)},[g]);const ie=a.useRef(null);async function L(m){if(m.preventDefault(),!B||!h.trim()||D)return;const G=h.trim(),M=B.name;U(!0),y("");try{const q=await To(B.id,{command:G,...c.trim()?{cwd:c.trim()}:{}});l(k=>ss(k,M,q)),C(q.id),A(!0)}catch(q){l(k=>[...k,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:M,command:G,error:q instanceof Error?q.message:"Command failed"}])}finally{U(!1)}}async function K(m,G){m.stopPropagation();const M=await Co(G.session.nodeId,G.session.id);l(q=>ss(q,G.nodeName,M))}function _(m){C(m),A(!0),S(!1)}function W(m){p&&cc(F.current,m.target)&&S(!1)}function x(m,G,M,q,k){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:q,"aria-label":`Toggle ${m} sessions`,"aria-expanded":!M,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(st,{className:P("h-3 w-3 transition-transform",M&&"-rotate-90")})]}),!M&&(G.length>0?G.map(z):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:k}))]})}function z(m){const G=N===m.session.id,M=m.session.status==="running";return e.jsxs("div",{className:P("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",G&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>_(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:P("flex h-4 w-4 shrink-0 items-center justify-center",M?"text-primary":m.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:M?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):m.session.status==="exited"?e.jsx(En,{className:"h-3 w-3"}):e.jsx(Ds,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:ir(m.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[m.nodeName," · ",Zs(m.session)]})]})]}),M&&e.jsx("button",{type:"button",onClick:q=>void K(q,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(zn,{className:"h-3 w-3"})})]},m.session.id)}return e.jsx("section",{className:"dashboard-panel node-terminal animate-composer-settle flex h-full min-h-0 shrink-0 overflow-visible rounded-xl","aria-label":"Node terminal",onClick:W,children:e.jsxs("div",{className:"flex h-full min-h-0 w-full flex-col overflow-visible rounded-[inherit] bg-card/72 text-card-foreground",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"node-terminal__header flex min-w-0 items-center gap-2 font-medium",children:[n?e.jsx("button",{type:"button",onClick:n,"aria-label":"Close terminal",title:"Close terminal",className:"flex h-6 w-6 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:e.jsx(tt,{className:"h-3.5 w-3.5"})}):e.jsx(_n,{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:F,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":p,title:V?xc(V):"All sessions",onClick:()=>S(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:hc(V,N)}),e.jsx(st,{className:P("h-3 w-3 shrink-0 text-muted-foreground transition-transform",p&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!p,className:P("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!p&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>_(vt),className:P("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",N===vt&&"bg-primary/10 text-primary"),children:[e.jsx(_n,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),x("Active",ee.active,b,()=>j(m=>!m),"No active sessions"),x("Completed",ee.completed,w,()=>T(m=>!m),"No completed sessions")]})})]}),e.jsx("select",{value:(B==null?void 0:B.id)??"",onChange:m=>{i(m.target.value),A(!1),f(Is(t.find(G=>G.id===m.target.value)??null))},disabled:D||t.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:t.map(m=>e.jsx("option",{value:m.id,className:"bg-background text-foreground",children:m.name},m.id))}),e.jsx(bs,{value:c,onChange:f,assignTo:(B==null?void 0:B.id)??"",nodes:t,assignableNodes:t,layout:"composer",chipClassName:"node-terminal__control h-7 max-w-[18rem] rounded-sm border border-border/70 bg-background/70 px-2 text-foreground hover:bg-muted/65",chipActiveClassName:"font-mono",chipInactiveClassName:"text-muted-foreground",labelClassName:"node-terminal__workdir",triggerClassName:"terminal-workdir-trigger",popoverPlacement:"top",popoverAlign:"end"})]})]}),e.jsxs("div",{ref:E,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>{var m;return(m=ie.current)==null?void 0:m.focus()},children:[H.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:H.map(m=>Ke(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:P("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(En,{className:"h-3 w-3"}):e.jsx(Ds,{className:"h-3 w-3"}),Zs(m.session)]}),m.session.status==="running"&&e.jsx("button",{type:"button",onClick:G=>void K(G,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(zn,{className:"h-3 w-3"})})]}),m.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:m.session.stdout}),Xn(m.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Xn(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(Ds,{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:L,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:B?`${B.name}$`:"$"}),e.jsx("input",{ref:ie,value:h,onChange:m=>y(m.target.value),disabled:!B||D,placeholder:B?"":"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:!B||!h.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(js,{className:"h-3 w-3"})})]})]})]})})}function mn({nodeId:t,nodeName:s,onOpenSettings:n,onOpenServicePreview:r,onOpenCapabilities:o,onOpenDevBox:i,onStartDevBox:d,onToggleRemoteAccess:c,remoteAccessLabel:f,remoteAccessPending:h,remoteAccessDisabled:y,remoteAccessDisabledReason:g,showConfigureDevBox:l,showStartDevBox:N,startDevBoxPending:C,className:v}){const[A,p]=a.useState(!1),[S,b]=a.useState(null),j=a.useRef(null),w=a.useRef(null),T=C?"Starting":"Start DevBox",D=f!=null&&f.startsWith("Disable")?_o:$l;a.useLayoutEffect(()=>{if(!A){b(null);return}const E=()=>{const F=w.current,B=j.current;if(!F||!B)return;const Q=F.getBoundingClientRect(),ee=B.getBoundingClientRect();b(gc({left:Q.left,right:Q.right,bottom:Q.bottom,top:Q.top},{width:ee.width,height:ee.height},{width:window.innerWidth,height:window.innerHeight},bc()))};return E(),window.addEventListener("resize",E),window.addEventListener("scroll",E,!0),()=>{window.removeEventListener("resize",E),window.removeEventListener("scroll",E,!0)}},[A]),a.useEffect(()=>{if(!A)return;const E=B=>{var ee,V;const Q=B.target;Q instanceof Node&&!((ee=j.current)!=null&&ee.contains(Q))&&!((V=w.current)!=null&&V.contains(Q))&&p(!1)},F=B=>{B.key==="Escape"&&p(!1)};return document.addEventListener("mousedown",E),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",F)}},[A]);const U=A?e.jsxs("div",{ref:j,"data-node-action-menu-portal":"true",role:"menu",style:fc(S),onClick:E=>E.stopPropagation(),onPointerDown:E=>E.stopPropagation(),className:"fixed z-[130] 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:[n&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} settings`,title:`Open ${s} settings`,onClick:E=>{E.stopPropagation(),p(!1),n(t)},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(Eo,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Settings"})]}),r&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Preview service on ${s}`,title:`Preview service on ${s}`,onClick:E=>{E.stopPropagation(),p(!1),r(t)},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(Va,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Preview service"})]}),o&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Open ${s} capabilities`,title:`Open ${s} capabilities`,onClick:E=>{E.stopPropagation(),p(!1),o(t)},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(vs,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Capabilities"})]}),f&&c&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${f} for ${s}`,title:g??`${f} for ${s}`,onClick:E=>{E.stopPropagation(),!(h||y)&&(p(!1),c())},disabled:h||y,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:[h?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(D,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:f})]}),N&&d&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`${T} for ${s}`,title:`${T} for ${s}`,onClick:E=>{E.stopPropagation(),!C&&(p(!1),d(t))},disabled:C,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:[C?e.jsx(ue,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-primary"}):e.jsx(js,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:T})]}),l&&i&&e.jsxs("button",{type:"button",role:"menuitem","aria-label":`Configure DevBox for ${s}`,title:`Configure DevBox for ${s}`,onClick:E=>{E.stopPropagation(),p(!1),i(t)},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(Do,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{children:"Configure DevBox"})]})]}):null;return e.jsxs("div",{"data-node-action-menu":"true",className:P("relative shrink-0",A&&"z-[120]",v),onClick:E=>E.stopPropagation(),onPointerDown:E=>E.stopPropagation(),children:[e.jsx(Z,{ref:w,type:"button",variant:"ghost",size:"icon","aria-label":`More actions for ${s}`,"aria-haspopup":"menu","aria-expanded":A,title:`More actions for ${s}`,onClick:E=>{E.stopPropagation(),p(F=>(F||b(null),!F))},className:P("h-6 w-6 rounded-sm text-muted-foreground hover:bg-background/70 hover:text-foreground",A&&"bg-background/80 text-primary"),children:e.jsx(ol,{className:"h-3.5 w-3.5"})}),U&&(typeof document>"u"?U:Ma.createPortal(U,document.body))]})}function fc(t){return t?{left:t.left,top:t.top}:{left:0,top:0,visibility:"hidden"}}function gc(t,s,n,r=1){const d=s.width||160,c=s.height||0,f=Number.isFinite(r)&&r>0?r:1,h=Math.max(8,Math.min(t.right-d,n.width-d-8)),y=t.bottom+4,g=(t.top??t.bottom)-c-4,l=y+c>n.height-8&&g>=8?g:y;return{left:Math.round(h/f),top:Math.round(l/f)}}function bc(){if(typeof window>"u"||typeof document>"u")return 1;const t=window.getComputedStyle(document.documentElement),s=t.zoom||t.getPropertyValue("--ui-zoom"),n=Number.parseFloat(s);return Number.isFinite(n)&&n>0?n:1}const vc=new Set(["deallocated","hibernate","hibernated","sleep","sleeping","stopped"]),jc=new Set(["startinprogress","starting"]);function At(t){return!!(t!=null&&t.enabled&&t.name)}function wc(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&vc.has(s))}function Mt(t){const s=t==null?void 0:t.trim().toLowerCase().replace(/[\s_-]+/gu,"");return!!(s&&jc.has(s))}function Ns(t,s,n){return t==="offline"&&wc(s)&&At(n)}function Jn(t,s){return t==="offline"&&At(s)}function ea(t){return!At(t)}function yc({nodeStatus:t,status:s,current:n,selected:r}){const o=r??n;return o&&Ns(t,s,o)?o:null}function Re(t){return t.scope||`name:${t.name??""}`}function Nc({previousKey:t,baseDevBox:s,listed:n}){if(t&&n.some(i=>Re(i)===t))return t;if(!At(s))return n[0]?Re(n[0]):"";const r=Re(s),o=n.find(i=>Re(i)===r)??n.find(i=>i.name===s.name);return o?Re(o):r}function kc({cluster:t,systemInfo:s,nodeNameById:n,nodeBlockingTaskCounts:r,eventTypeFilter:o,onEventTypeFilterChange:i,eventTypeOptions:d,filteredEvents:c,sseConnected:f,clusterLoading:h,clusterError:y,promotePending:g,onPromote:l,onAddNode:N,leavePending:C,onLeaveCluster:v,onToggleNodeDevTunnel:A,devTunnelNodeId:p,devBoxStartNodeId:S,devBoxStartingNodeIds:b=new Set,onOpenNodeSettings:j,onOpenNodeCapabilities:w,onOpenDevBox:T,onStartDevBox:D}){var ie,L,K;const U=((ie=t==null?void 0:t.self)==null?void 0:ie.role)==="leader",E=((L=t==null?void 0:t.self)==null?void 0:L.role)==="follower"&&!(t!=null&&t.leader),F=(t==null?void 0:t.self)??null,Q=Ao((t==null?void 0:t.nodes)??[],F==null?void 0:F.id).filter(_=>_.id!==(F==null?void 0:F.id)),ee=t!=null&&t.leader?t.nodes.find(_=>{var W;return _.id===((W=t.leader)==null?void 0:W.id)})??null:null,V=t!=null&&t.leader?t.leader.dashboardOrigin??(ee==null?void 0:ee.dashboardOrigin)??(s&&t.leader.id===(s.nodeId??s.id)?s.dashboardOrigin:void 0)??t.leader.endpoint:null,H=(F==null?void 0:F.role)==="leader"&&Q.length===0,se=(F==null?void 0:F.role)==="follower";return e.jsx("aside",{className:"dashboard-operations-sidecar dashboard-panel dashboard-panel-muted animate-panel-settle flex h-full min-h-0 flex-col overflow-hidden rounded-xl",children:e.jsxs(en,{defaultValue:"overview",className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"dashboard-operations-sidecar__header shrink-0 bg-card/24 px-2.5 py-2",children:e.jsxs(Js,{className:"grid h-auto w-full grid-cols-3 rounded-sm bg-muted/55 p-0.5",children:[e.jsx(bt,{value:"overview",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Overview"}),e.jsx(bt,{value:"nodes",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Nodes"}),e.jsx(bt,{value:"events",className:"rounded-sm px-2 py-0.5 text-[10px]",children:"Live events"})]})}),e.jsx(ot,{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:[F&&e.jsx(ta,{node:F,systemInfo:s,blockingTaskCount:r.get(F.id)??0,devTunnelNodeId:p,onToggleNodeDevTunnel:A,showActions:!1,defaultExpanded:!1,onOpenDevBox:T,devBoxStartingNodeIds:b}),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(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:f?"Connected":"Reconnecting"})]}),h&&!t?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..."]}):y&&!t?e.jsx("div",{className:"rounded-sm border border-destructive/20 bg-destructive/10 px-2 py-1.5 text-[10px] text-destructive shadow-none",children:y}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(Tt,{label:"Term",value:String((t==null?void 0:t.term)??0)}),e.jsx(Tt,{label:"Nodes",value:String((t==null?void 0:t.nodes.length)??0)}),e.jsx(Tt,{label:"Pending",value:String((t==null?void 0:t.taskSummary.pending)??0)}),e.jsx(Tt,{label:"Running",value:String((t==null?void 0:t.taskSummary.running)??0)}),e.jsx(Tt,{label:"Completed",value:String((t==null?void 0:t.taskSummary.completed)??0)}),e.jsx(Tt,{label:"Failed",value:String((t==null?void 0:t.taskSummary.failed)??0)})]}),e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-muted/45 px-2 py-2 shadow-none",children:[e.jsx(Je,{label:"Leader",value:((K=t==null?void 0:t.leader)==null?void 0:K.name)??"None"}),e.jsx(Je,{label:"Leader URL",value:V??"Unavailable",mono:!0,action:V?e.jsx(Gt,{label:"Copy leader URL",onClick:()=>void _t(V,"Leader URL copied")}):void 0}),e.jsx(Je,{label:"Feed",value:f?"Receiving live updates":"Reconnecting to event stream"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:E&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:l,disabled:g,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[g&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Promote self"]})})]})]})]})})}),e.jsx(ot,{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"}),H?e.jsxs(Z,{variant:"secondary",size:"sm",onClick:N,className:"h-6 border-0 bg-primary px-2 text-[10px] text-primary-foreground shadow-none hover:bg-primary/90",children:[e.jsx(Bl,{className:"h-3 w-3"}),"Join node"]}):se?e.jsxs(Z,{variant:"secondary",size:"sm",onClick:v,disabled:C,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[C&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Leave cluster"]}):null]}),F&&e.jsx(ta,{node:F,systemInfo:s,blockingTaskCount:r.get(F.id)??0,devTunnelNodeId:p,onToggleNodeDevTunnel:A,showActions:!0,defaultExpanded:!0,onOpenNodeSettings:U?j:void 0,onOpenNodeCapabilities:U?w:void 0,onOpenDevBox:U?T:void 0,onStartDevBox:U?D:void 0,devBoxStartNodeId:S,devBoxStartingNodeIds:b})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"text-[10px] font-medium text-foreground",children:["Peer nodes (",Q.length,")"]}),Q.length>0?e.jsx("div",{className:"space-y-1.5",children:Q.map(_=>e.jsx(Sc,{node:_,isLeader:!!U,blockingTaskCount:r.get(_.id)??0,devTunnelNodeId:p,onToggleNodeDevTunnel:A,onOpenNodeSettings:U?j:void 0,onOpenNodeCapabilities:U?w:void 0,onOpenDevBox:U?T:void 0,onStartDevBox:U?D:void 0,devBoxStartNodeId:S,devBoxStartingNodeIds:b},_.id))}):e.jsx("div",{className:"rounded-sm bg-muted/45 px-2 py-2 text-[10px] text-muted-foreground shadow-none",children:"No peer nodes are connected yet."})]})]})})}),e.jsx(ot,{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(Mo,{className:P("h-3.5 w-3.5",f?"text-emerald-500":"text-destructive")}),"Live events"]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsxs(ke,{value:o,onValueChange:i,children:[e.jsx(Se,{className:"h-6 min-w-[10rem] flex-1 rounded-sm border-0 bg-muted/60 text-[10px] shadow-none sm:max-w-[14rem] [&>svg]:h-3 [&>svg]:w-3",children:e.jsx(Be,{placeholder:"Event type"})}),e.jsx(Ce,{className:"shadow-none",children:d.map(_=>e.jsx(xe,{value:_,className:"py-1 pl-6 pr-1.5 text-[10px] leading-4",children:_==="all"?"All event types":_},_))})]}),e.jsx(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-muted/60 px-1.5 py-0 text-[9px] leading-4 shadow-none",children:f?"Connected":"Reconnecting"})]})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Po,{events:c,maxHeight:"100%",emptyTitle:o==="all"?"No live events yet":"No matching events",emptyDescription:o==="all"?"Cluster activity appears here as it happens.":`No "${o}" events are in the current stream.`,nodeNameById:n,density:"compact"})})]})})]})})}function ta({node:t,systemInfo:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:o,showActions:i=!0,defaultExpanded:d=!1,onOpenNodeSettings:c,onOpenNodeCapabilities:f,onOpenDevBox:h,onStartDevBox:y,devBoxStartNodeId:g,devBoxStartingNodeIds:l}){var D,U,E,F;const[N,C]=a.useState(d),v=(s==null?void 0:s.dashboardOrigin)??t.dashboardOrigin,A=t.devtunnelEndpoint??t.endpoint,p=v??t.endpoint,S=(s==null?void 0:s.workDir)??t.workDir,b=Wa(t,s==null?void 0:s.transportType),j=dn(t,s==null?void 0:s.transportType),w=j&&Rt((s==null?void 0:s.transportType)??t.transportType)?!0:Ka(t,s==null?void 0:s.transportType),T=n>0;return e.jsxs("section",{className:"dashboard-operations-node-card bg-primary/8 shadow-none",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:()=>C(B=>!B),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[N?e.jsx(st,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(He,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(Pa,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Current node"})]}),e.jsx("a",{href:p,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(nn,{className:"h-3 w-3"})}),(c||f||i&&w)&&e.jsx(mn,{nodeId:t.id,nodeName:t.name,onOpenSettings:c,onOpenCapabilities:f,onOpenDevBox:h,onStartDevBox:y,onToggleRemoteAccess:i&&w?()=>o(t):void 0,remoteAccessLabel:i&&w?j?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:T,remoteAccessDisabledReason:T?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:(D=t.devbox)==null?void 0:D.enabled,showStartDevBox:Ns(t.status,(U=t.devbox)==null?void 0:U.lastStatus,t.devbox)||Mt((E=t.devbox)==null?void 0:E.lastStatus)||l.has(t.id),startDevBoxPending:g===t.id||Mt((F=t.devbox)==null?void 0:F.lastStatus)||l.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>C(B=>!B),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:t.name}),e.jsx(La,{role:t.role,size:"compact"}),e.jsx(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),N&&e.jsxs("div",{className:"space-y-2 bg-primary/5 px-2.5 pb-2.5 pt-1.5",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-muted/45 px-2 py-1.5 shadow-none",children:[e.jsx(Je,{label:"Node ID",value:t.id,mono:!0}),v&&e.jsx(Je,{label:"Dashboard",value:v,mono:!0,action:e.jsx(Gt,{label:"Copy dashboard URL",onClick:()=>void _t(v,"Dashboard URL copied")})}),e.jsx(Je,{label:"Node URL",value:A,mono:!0,action:e.jsx(Gt,{label:"Copy node URL",onClick:()=>void _t(A,"Node URL copied")})}),S&&e.jsx(Je,{label:"Workspace",value:S,mono:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1",children:[e.jsx(Us,{label:"Transport",value:b}),s&&e.jsx(Us,{label:"Uptime",value:Lo(s.uptime),mono:!0})]}),i&&f&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:()=>f(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(vs,{className:"h-3 w-3"}),"Capabilities"]}),i&&w&&T&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Sc({node:t,isLeader:s,blockingTaskCount:n,devTunnelNodeId:r,onToggleNodeDevTunnel:o,onOpenNodeSettings:i,onOpenNodeCapabilities:d,onOpenDevBox:c,onStartDevBox:f,devBoxStartNodeId:h,devBoxStartingNodeIds:y}){var j,w,T,D;const[g,l]=a.useState(!1),N=t.dashboardOrigin,C=t.devtunnelEndpoint??t.endpoint,v=N??t.endpoint,A=Wa(t),p=dn(t),S=Ka(t),b=n>0;return e.jsxs("div",{className:"dashboard-operations-node-card bg-muted/45 shadow-none",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(U=>!U),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left",children:[g?e.jsx(st,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(He,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Pa,{status:t.status}),e.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Peer node"})]}),e.jsx("a",{href:v,target:"_blank",rel:"noreferrer",className:"ml-auto shrink-0 text-muted-foreground transition-colors hover:text-primary",title:"Open Dashboard",children:e.jsx(nn,{className:"h-3 w-3"})}),s&&(i||d||S)&&e.jsx(mn,{nodeId:t.id,nodeName:t.name,onOpenSettings:i,onOpenCapabilities:d,onOpenDevBox:c,onStartDevBox:f,onToggleRemoteAccess:S?()=>o(t):void 0,remoteAccessLabel:S?p?"Disable Remote Access":"Enable Remote Access":void 0,remoteAccessPending:r===t.id,remoteAccessDisabled:b,remoteAccessDisabledReason:b?"Finish assigned or running tasks before changing remote access":void 0,showConfigureDevBox:(j=t.devbox)==null?void 0:j.enabled,showStartDevBox:Ns(t.status,(w=t.devbox)==null?void 0:w.lastStatus,t.devbox)||Mt((T=t.devbox)==null?void 0:T.lastStatus)||y.has(t.id),startDevBoxPending:h===t.id||Mt((D=t.devbox)==null?void 0:D.lastStatus)||y.has(t.id)})]}),e.jsxs("button",{type:"button",onClick:()=>l(U=>!U),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:t.name}),e.jsx(La,{role:t.role,size:"compact"}),e.jsx(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-background/65 px-1.5 py-0 text-[9px] leading-4 capitalize shadow-none",children:t.status})]})]}),g&&e.jsxs("div",{className:"space-y-2 bg-muted/35 px-2.5 pb-2.5 pt-1.5",children:[e.jsxs("div",{className:"space-y-1.5 rounded-sm bg-background/55 px-2 py-1.5 shadow-none",children:[e.jsx(Je,{label:"Node ID",value:t.id,mono:!0}),N&&e.jsx(Je,{label:"Dashboard",value:N,mono:!0,action:e.jsx(Gt,{label:"Copy dashboard URL",onClick:()=>void _t(N,"Dashboard URL copied")})}),e.jsx(Je,{label:"Node URL",value:C,mono:!0,action:e.jsx(Gt,{label:"Copy node URL",onClick:()=>void _t(C,"Node URL copied")})}),t.workDir&&e.jsx(Je,{label:"Workspace",value:t.workDir,mono:!0}),e.jsx(Us,{label:"Transport",value:A})]}),s&&d&&e.jsxs(Z,{variant:"secondary",size:"sm",onClick:()=>d(t.id),"aria-label":`Open ${t.name} capabilities`,className:"h-6 border-0 bg-muted/70 px-2 text-[10px] shadow-none hover:bg-muted",children:[e.jsx(vs,{className:"h-3 w-3"}),"Capabilities"]}),s&&S&&b&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n," active task",n===1?"":"s"," on this node."]})]})]})}function Gt({label:t,onClick:s}){return e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-4 w-4 shrink-0 rounded-sm p-0 text-muted-foreground opacity-70 hover:bg-muted/45 hover:opacity-100 [&_svg]:size-2.5",onClick:s,"aria-label":t,title:t,children:e.jsx(Ea,{className:"h-3 w-3"})})}function Cc(t,s,n,r){var c,f;if(!t)return{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:"Select a task to continue the conversation."};const o=((c=s==null?void 0:s.self)==null?void 0:c.role)==="follower",i=t.assignedTo?((f=s==null?void 0:s.self)==null?void 0:f.id)===t.assignedTo?s.self:s==null?void 0:s.nodes.find(h=>h.id===t.assignedTo):void 0;return t.assignedTo!==null&&(i?i.status==="offline":s?t.assignedNodeAvailable===!1||!s.nodes.some(h=>h.id===t.assignedTo):t.assignedNodeAvailable===!1)?{taskUnavailable:!0,chatDisabled:!0,chatDisabledReason:`${t.assignedNodeName??"Assigned node"} is unavailable. Leave the cluster on that node or re-run the task elsewhere.`}:o?{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..."}:r?{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Queue a message for the next turn..."}:ps.has(t.status)||t.status==="archived"?{taskUnavailable:!1,chatDisabled:!0,chatDisabledReason:ps.has(t.status)?"Task has not started yet...":"Archived tasks are read-only."}:{taskUnavailable:!1,chatDisabled:!1,chatDisabledReason:"Continue the conversation..."}}const lr=.5,dr=1.75,sa=.1;function Tc({node:t,open:s,onOpenChange:n}){const[r,o]=a.useState(ts),[i,d]=a.useState(null),[c,f]=a.useState(1),[h,y]=a.useState(!1),[g,l]=a.useState(null);a.useEffect(()=>{o(ts),d(null),f(1),y(!1),l(null)},[t==null?void 0:t.id,s]);const N=a.useCallback(async b=>{if(!t)return;const j=b??Number.parseInt(r.trim()||ts,10);if(!Number.isInteger(j)||j<1||j>65535){l("Enter a port between 1 and 65535");return}y(!0),l(null);try{const w=await Io(t.id,{port:j});d(w),o(String(j)),Dn("preview.created",{result:"success",previewType:"service-port"})}catch(w){l(w instanceof Error?w.message:"Failed to create service preview"),Dn("preview.failed",{result:"failed",previewType:"service-port"})}finally{y(!1)}},[t,r]),C=a.useCallback(()=>{typeof(i==null?void 0:i.port)=="number"&&N(i.port)},[i==null?void 0:i.port,N]);a.useEffect(()=>{if(!i)return;const b=i.expiresAt-Date.now()-5e3;if(b<=0){C();return}const j=window.setTimeout(C,b);return()=>window.clearTimeout(j)},[C,i]);const v=i?Yi(i):null,A=(t==null?void 0:t.name)??"Node",p=_c(c),S={width:`${100/c}%`,height:`${100/c}%`,transform:`scale(${c})`,transformOrigin:"top left"};return e.jsx(Lt,{open:s,onOpenChange:n,children:e.jsxs(It,{onOpenAutoFocus:b=>b.preventDefault(),className:"flex h-[min(82vh,44rem)] max-w-[min(92vw,72rem)] flex-col gap-0 overflow-hidden p-0",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-2 border-b border-border/60 px-3 py-2 pr-9",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(Yt,{className:"flex min-w-0 items-center gap-1.5 text-[12px] font-semibold text-foreground",children:[e.jsx(Va,{className:"h-3.5 w-3.5 shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0",children:"Preview service"}),e.jsx("span",{className:"min-w-0 truncate font-mono text-[10px] font-medium text-muted-foreground",children:A})]}),e.jsx(an,{className:"sr-only",children:"Preview a service port running on the selected node."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("form",{className:"flex items-center gap-1.5",onSubmit:b=>{b.preventDefault(),N()},children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:["Port",e.jsx(et,{type:"text",min:1,max:65535,inputMode:"numeric",value:r,onChange:b=>o(b.target.value),placeholder:ts,"aria-label":"Node service preview port",className:"h-6 w-20 rounded-sm border-0 bg-muted/55 px-2 text-[11px] shadow-none focus:bg-muted/55 focus:outline-none focus-visible:border-0 focus-visible:bg-muted/55 focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsxs(Z,{type:"submit",variant:"ghost",size:"sm",disabled:h,className:"h-6 rounded-sm border-0 bg-primary/10 px-2 text-[11px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[h?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(js,{className:"h-3.5 w-3.5"}),"Preview"]})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden shrink-0 text-[10px] text-muted-foreground sm:inline",children:Ec(i.expiresAt)}),e.jsxs("div",{className:"flex h-6 shrink-0 items-center overflow-hidden rounded-sm border border-border/55 bg-muted/35",children:[e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>f(b=>na(b,-sa)),disabled:c<=lr,title:"Zoom out","aria-label":"Zoom out preview",children:e.jsx(Ul,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>f(1),className:"h-6 min-w-11 border-x border-border/45 px-1.5 text-center font-mono text-[10px] text-muted-foreground transition-colors hover:bg-muted/55 hover:text-foreground",title:"Reset zoom","aria-label":"Reset preview zoom",children:p}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-none",onClick:()=>f(b=>na(b,sa)),disabled:c>=dr,title:"Zoom in","aria-label":"Zoom in preview",children:e.jsx(Fl,{className:"h-3.5 w-3.5"})})]}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",onClick:C,title:"Refresh",children:e.jsx(Bo,{className:"h-3.5 w-3.5"})}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-6 w-6 rounded-sm",asChild:!0,title:"Open in new tab",children:e.jsx("a",{href:v??i.previewUrl,target:"_blank",rel:"noopener noreferrer",children:e.jsx(nn,{className:"h-3.5 w-3.5"})})})]})]})]}),g&&e.jsx("div",{className:"shrink-0 border-b border-destructive/20 bg-destructive/5 px-3 py-1.5 text-[11px] text-destructive",children:g}),e.jsx("div",{className:"min-h-0 flex-1 p-2",children:i?e.jsx("div",{className:"h-full overflow-hidden rounded-sm border border-border/60 bg-white shadow-none",children:e.jsx("iframe",{src:Zi(i),style:S,className:"h-full w-full border-0",sandbox:Qi(i),title:`${A} Service Preview`})}):e.jsx("div",{className:"flex h-full min-h-56 items-center justify-center rounded-sm border border-dashed border-border/65 bg-background/35 px-3 text-center text-[11px] text-muted-foreground",children:"No service preview running."})})]})})}function na(t,s){return cr(Math.round((t+s)*100)/100)}function cr(t){return Number.isFinite(t)?Math.min(dr,Math.max(lr,t)):1}function _c(t){return`${Math.round(cr(t)*100)}%`}function Ec(t){const s=Math.max(0,Math.round((t-Date.now())/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60),r=s%60;return`${n}m ${r}s`}function Dc({dirPath:t,label:s,taskCount:n,collapsed:r,onToggle:o,onCreateTask:i,onOpenCapabilities:d}){return e.jsxs("div",{className:"group/project-row flex w-full items-stretch rounded-sm bg-muted/15 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.jsxs("button",{type:"button",onClick:o,"aria-expanded":!r,title:t,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-l-sm px-2 py-1 text-left",children:[e.jsx(He,{className:P("h-3 w-3 shrink-0 transition-transform duration-200",!r&&"rotate-90")}),e.jsx(Pt,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:s}),e.jsx("span",{className:"ml-2 shrink-0 rounded-sm bg-background/55 px-1 py-0 tabular-nums text-[8px] font-medium leading-3 text-muted-foreground/45",children:n})]}),d&&e.jsx("button",{type:"button",onClick:d,"aria-label":`Capabilities for ${t}`,title:`Capabilities for ${t}`,className:"pointer-events-none mr-0.5 flex h-4 w-4 shrink-0 translate-y-px self-center items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-all hover:bg-primary/10 hover:text-primary focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/project-row:pointer-events-auto group-hover/project-row:opacity-100",children:e.jsx(vs,{className:"h-2.5 w-2.5"})}),e.jsx("button",{type:"button",onClick:i,"aria-label":`New chat in ${t}`,title:`New chat in ${t}`,className:"pointer-events-none ml-auto flex h-4 w-4 shrink-0 translate-y-px self-center items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-all hover:bg-primary/10 hover:text-primary focus-visible:pointer-events-auto focus-visible:opacity-100 group-hover/project-row:pointer-events-auto group-hover/project-row:opacity-100",children:e.jsx(ys,{className:"h-2.5 w-2.5"})})]})}const ur="meshy-task-sidebar-tree-state";function aa(t){return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Bs(){var t;try{return((t=globalThis.window)==null?void 0:t.localStorage)??globalThis.localStorage??null}catch{return null}}function ra(t){if(!t)return{collapsedNodes:[],collapsedDirs:[]};try{const s=t.getItem(ur);if(!s)return{collapsedNodes:[],collapsedDirs:[]};const n=JSON.parse(s);return{collapsedNodes:aa(n.collapsedNodes),collapsedDirs:aa(n.collapsedDirs)}}catch{return{collapsedNodes:[],collapsedDirs:[]}}}function Ac(t,s){if(t)try{t.setItem(ur,JSON.stringify(s))}catch{}}function oa(t,s){if(!t.has(s))return t;const n=new Set(t);return n.delete(s),n}function Mc(t,s){if(!s)return null;for(const n of t){const r=n.nodeId??"__unassigned__";for(const o of n.dirs)if(o.tasks.some(i=>i.id===s))return{nodeKey:r,dirKey:`${r}::${o.path}`}}return null}function ia(t,s,n){return n?{collapsedNodes:oa(t,n.nodeKey),collapsedDirs:oa(s,n.dirKey)}:{collapsedNodes:t,collapsedDirs:s}}function Pc(t,s,n){const r=t.filter(c=>c.status==="completed"),o=new Set((s?r:[...r].sort((c,f)=>f.updatedAt-c.updatedAt).slice(0,rn)).map(c=>c.id));n&&r.some(c=>c.id===n)&&o.add(n);const i=t.filter(c=>c.status!=="completed"||o.has(c.id)),d=r.length-o.size;return{visibleTasks:i,hiddenCompletedCount:Math.max(0,d)}}const ns="h-6 rounded-sm border-0 bg-muted/45 px-2 py-0 text-[10px] leading-none text-foreground shadow-none hover:bg-muted/65 focus:bg-muted/65 focus:ring-0 focus:ring-offset-0 [&>svg]:h-3 [&>svg]:w-3",as="py-1 pl-6 pr-1.5 text-[10px] leading-4 [&_svg]:h-3 [&_svg]:w-3";function la({toolbarTasks:t,activeTaskId:s,tasksLoading:n,tasksError:r,isLeader:o,scope:i,agentFilter:d,nodeFilter:c,taskKindFilter:f,agentOptions:h,nodeOptions:y,nodeNameById:g,nodeWorkDirById:l,nodeStatusById:N,completedGroupByKey:C,devBoxNodeIds:v=new Set,devBoxStartNodeIds:A=new Set,devBoxStartingNodeIds:p=new Set,leaderNodeId:S,searchQuery:b,selectedTaskIds:j,allVisibleTasksSelected:w,someVisibleTasksSelected:T,canBatchArchive:D,onScopeChange:U,onAgentFilterChange:E,onNodeFilterChange:F,onTaskKindFilterChange:B,onToggleTaskSelected:Q,onToggleAllVisibleTasks:ee,onBatchArchive:V,onBatchDelete:H,onCreateTask:se,onOpenNodeSettings:ie,onOpenNodeCapabilities:L,onOpenProjectCapabilities:K,onOpenDevBox:_,onStartDevBox:W,onLoadCompletedTasks:x,onSelectTask:z}){const[m,G]=a.useState(!1),[M,q]=a.useState(()=>j.size>0),[k,X]=a.useState(null),{markScrollbarActive:re,scrollbarActive:ce}=nr(),J=j.size,O=!!(o&&(M||J>0)),te=i!=="active"||c!=="all"||d!=="all"||f!=="all",le=b.trim().length>0,[R,ae]=a.useState(()=>new Set(ra(Bs()).collapsedNodes)),[ve,Ee]=a.useState(()=>new Set(ra(Bs()).collapsedDirs)),[nt,at]=a.useState(new Set),Ue=a.useMemo(()=>Ro(t,g,S,l),[t,g,S,l]),je=a.useMemo(()=>Mc(Ue,s),[Ue,s]),it=a.useRef(null),We=Ue.length===1,Me=Ue.length>0,ne=We&&(te||le),we=!!(o&&(Ue.length>0||J>0)),Pe=a.useCallback($=>{ae(Le=>{const Ae=new Set(Le);return Ae.has($)?Ae.delete($):Ae.add($),Ae})},[]),De=a.useCallback($=>{Ee(Le=>{const Ae=new Set(Le);return Ae.has($)?Ae.delete($):Ae.add($),Ae})},[]),lt=a.useCallback($=>{at(Le=>{const Ae=new Set(Le);return Ae.add($),Ae})},[]);a.useEffect(()=>{Ac(Bs(),{collapsedNodes:Array.from(R),collapsedDirs:Array.from(ve)})},[ve,R]),a.useEffect(()=>{if(!je||!s)return;const $=`${s}:${je.nodeKey}:${je.dirKey}`;it.current!==$&&(it.current=$,ae(Le=>ia(Le,new Set,je).collapsedNodes),Ee(Le=>ia(new Set,Le,je).collapsedDirs))},[s,je]);const ye=a.useCallback($=>{q(!0),ee($)},[ee]),qe=a.useCallback(()=>{ee(!1),q(!1)},[ee]);a.useEffect(()=>{o||q(!1)},[o]);const $e=O?e.jsxs("label",{className:"flex items-center gap-[5px] text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75",children:[e.jsx(Kt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:T&&!w?"indeterminate":w,onCheckedChange:$=>ye($===!0),"aria-label":"Select all visible tasks"}),e.jsx("span",{children:"Multi select"})]}):e.jsxs(Z,{variant:"ghost",size:"sm",onClick:()=>q(!0),className:"h-5 rounded-sm px-1.5 text-[9px] font-medium uppercase tracking-[0.12em] text-muted-foreground/75 hover:text-foreground",children:[e.jsx(Fi,{className:"h-3 w-3"}),"Multi select"]}),jt=J>0?e.jsxs("div",{className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"text-[9px] font-semibold leading-3 text-foreground",children:[J," task",J!==1?"s":""," selected"]}),!D&&e.jsx("div",{className:"max-w-48 text-[9px] leading-3.5 text-muted-foreground",children:"Only completed, failed, cancelled, or archived tasks can be archived."})]}):null,Te=J>0?e.jsxs("div",{className:"flex flex-wrap justify-end gap-1",children:[e.jsxs(is,{children:[e.jsx(Fs,{asChild:!0,children:e.jsxs(Z,{variant:"ghost",size:"sm",disabled:!D,className:"h-5 gap-1 rounded-sm bg-muted/45 px-1.5 text-[8px] text-foreground/80 shadow-none hover:bg-muted/65 [&_svg]:size-3",children:[e.jsx(Ji,{}),"Archive"]})}),e.jsxs(ls,{children:[e.jsxs(ds,{children:[e.jsxs(cs,{children:["Archive ",J," task",J!==1?"s":"","?"]}),e.jsx(us,{children:"Archived tasks stay hidden from the default task view and can be reopened from the archived scope."})]}),e.jsxs(ms,{children:[e.jsx(xs,{children:"Cancel"}),e.jsx(hs,{onClick:V,disabled:!D,children:"Archive"})]})]})]}),e.jsxs(is,{children:[e.jsx(Fs,{asChild:!0,children:e.jsxs(Z,{variant:"destructive",size:"sm",className:"h-5 gap-1 rounded-sm px-1.5 text-[8px] [&_svg]:size-3",children:[e.jsx(Ba,{}),"Delete"]})}),e.jsxs(ls,{children:[e.jsxs(ds,{children:[e.jsxs(cs,{children:["Delete ",J," task",J!==1?"s":"","?"]}),e.jsx(us,{children:"This removes the selected tasks and their saved logs."})]}),e.jsxs(ms,{children:[e.jsx(xs,{children:"Cancel"}),e.jsx(hs,{onClick:H,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]})]}):null;return e.jsxs(e.Fragment,{children:[e.jsxs("aside",{className:"dashboard-task-sidebar 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:"dashboard-task-sidebar__header shrink-0 bg-card/24 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex min-w-0 items-stretch gap-1.5",children:[e.jsxs(Z,{onClick:()=>se("chat"),className:"h-8 w-[6.75rem] justify-start rounded-sm px-2.5 text-left text-[11px] shadow-[0_10px_24px_-18px_hsl(var(--primary)/0.9)]",children:[e.jsx(ys,{className:"h-3.5 w-3.5"}),"New chat"]}),e.jsxs(Z,{variant:"outline",onClick:()=>se("native"),className:"h-8 w-[7.75rem] justify-start rounded-sm border-0 bg-muted/45 px-2.5 text-left text-[11px] text-foreground shadow-none hover:bg-muted/65 hover:text-foreground",children:[e.jsx(ln,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Load session"]})]}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>G($=>!$),className:P("ml-auto h-8 w-8 shrink-0 rounded-sm text-muted-foreground shadow-none hover:bg-muted/55 hover:text-foreground",(m||te)&&"bg-primary/8 text-primary hover:bg-primary/12 hover:text-primary"),title:"Filters",children:e.jsx(xl,{className:"h-3.5 w-3.5"})})]}),(m||te)&&e.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-1 sm:grid-cols-2",children:[e.jsxs(ke,{value:i,onValueChange:$=>U($),children:[e.jsx(Se,{className:ns,children:e.jsx(Be,{})}),e.jsx(Ce,{children:$o.map($=>e.jsx(xe,{value:$.value,className:as,children:$.label},$.value))})]}),e.jsxs(ke,{value:c,onValueChange:F,children:[e.jsx(Se,{className:ns,children:e.jsx(Be,{placeholder:"Node"})}),e.jsx(Ce,{children:y.map($=>e.jsx(xe,{value:$.value,className:as,children:$.label},$.value))})]}),e.jsxs(ke,{value:d,onValueChange:E,children:[e.jsx(Se,{className:ns,children:e.jsx(Be,{placeholder:"Agent"})}),e.jsx(Ce,{children:h.map($=>e.jsx(xe,{value:$,className:as,children:$==="all"?"All agents":$},$))})]}),e.jsxs(ke,{value:f,onValueChange:$=>B($),children:[e.jsx(Se,{className:ns,children:e.jsx(Be,{placeholder:"Type"})}),e.jsx(Ce,{children:Oo.map($=>e.jsx(xe,{value:$.value,className:as,children:$.label},$.value))})]})]})]}),e.jsx("div",{className:P("scrollbar-line min-h-0 flex-1 overflow-y-auto pl-2.5 pr-1.5 py-2",ce&&"scrollbar-line-active"),onScroll:re,children:Ue.length>0?e.jsx("div",{className:"space-y-1",children:Ue.map($=>{const Le=$.nodeId??"__unassigned__",Ae=$.dirs.reduce((Ie,ze)=>Ie+ze.tasks.length,0),dt=Me&&!ne&&R.has(Le),pt=$.nodeId!==null&&N.get($.nodeId)==="offline",wt=!!(o&&$.nodeId);return e.jsxs("div",{className:"space-y-1",children:[Me&&e.jsxs("div",{className:"flex w-full items-stretch rounded-sm bg-gradient-to-r from-primary/8 to-muted/20 text-left text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground transition-all duration-150 hover:from-primary/12 hover:to-muted/30 hover:text-foreground active:scale-[0.99] active:from-primary/15",children:[e.jsxs("button",{type:"button",onClick:()=>Pe(Le),"aria-expanded":!dt,className:"flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-2 py-1.5 text-left",children:[e.jsx(He,{className:P("h-3.5 w-3.5 shrink-0 transition-transform duration-200",!dt&&"rotate-90")}),e.jsx(Sa,{className:"h-3 w-3 shrink-0 text-muted-foreground/55"}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:$.nodeName}),e.jsxs(Fe,{variant:"outline",className:"shrink-0 whitespace-nowrap rounded-sm border-transparent bg-background/55 px-1.5 py-0 text-[7px] font-semibold leading-3.5 text-muted-foreground shadow-none normal-case tracking-normal",children:[Ae," task",Ae===1?"":"s"]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[pt&&e.jsx(Fe,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/10 px-1 py-0 text-[8px] font-semibold leading-3 text-destructive shadow-none",children:"offline"}),$.nodeId===S&&e.jsx(Fe,{variant:"outline",className:"rounded-sm border-transparent bg-primary/8 px-1 py-0 text-[8px] font-medium leading-3.5 text-primary shadow-none",children:"leader"})]})]}),wt&&$.nodeId&&e.jsx("span",{className:"flex shrink-0 items-center pr-1.5",children:e.jsx(mn,{nodeId:$.nodeId,nodeName:$.nodeName,onOpenSettings:ie,onOpenServicePreview:()=>X({id:$.nodeId,name:$.nodeName}),onOpenCapabilities:L,onOpenDevBox:_,onStartDevBox:W,showConfigureDevBox:v.has($.nodeId),showStartDevBox:A.has($.nodeId)||p.has($.nodeId),startDevBoxPending:p.has($.nodeId)})})]}),e.jsx("div",{className:P("grid transition-[grid-template-rows] duration-300 ease-in-out",dt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:"overflow-hidden",children:$.dirs.map(Ie=>{const ze=`${Le}::${Ie.path}`,yt=ve.has(ze),ft=Ia(Ie.path),Ge=C==null?void 0:C.get(ze),mt=Ge?{visibleTasks:Ie.tasks,hiddenCompletedCount:Math.max(0,Ge.total-Ge.returned)}:Pc(Ie.tasks,nt.has(ze),s),{visibleTasks:Nt,hiddenCompletedCount:ct}=mt;return e.jsxs("div",{className:P("space-y-0.5 rounded-xl",Me&&"pl-2.5"),children:[e.jsx(Dc,{dirPath:Ie.path,label:ft,taskCount:Ie.tasks.length,collapsed:yt,onToggle:()=>De(ze),onCreateTask:()=>se("chat",{assignTo:$.nodeId,project:Ie.path==="default workspace"?"":Ie.path}),onOpenCapabilities:$.nodeId&&K?()=>K($.nodeId,Ie.path==="default workspace"?(l==null?void 0:l.get($.nodeId))??Ie.path:Ie.path):void 0}),e.jsx("div",{className:P("grid transition-[grid-template-rows] duration-300 ease-in-out",yt?"grid-rows-[0fr]":"grid-rows-[1fr]"),children:e.jsx("div",{className:P("overflow-hidden",Me?"pl-2":"pl-0"),children:e.jsxs("div",{className:"space-y-px py-0.5",children:[Nt.map(Ne=>{const _e=Ne.id===s,ut=Ne.assignedTo?N.get(Ne.assignedTo):void 0,kt=!!Ne.assignedTo&&(ut?ut==="offline":Ne.assignedNodeAvailable===!1);return e.jsxs("div",{className:P("animate-task-row-reveal relative flex items-center gap-1.5 rounded-sm px-2 py-1.5 transition-all duration-150",_e?'bg-primary/10 before:absolute before:left-0 before:top-1/2 before:h-1/2 before:w-[2px] before:-translate-y-1/2 before:rounded-full before:bg-primary before:content-[""]':"hover:bg-muted/40"),children:[O&&e.jsx("div",{className:"flex shrink-0",onClick:fe=>fe.stopPropagation(),children:e.jsx(Kt,{className:"h-3 w-3 [&_svg]:h-2.5 [&_svg]:w-2.5",checked:j.has(Ne.id),onCheckedChange:fe=>Q(Ne.id,fe===!0),"aria-label":`Select ${Ne.title}`})}),e.jsxs("button",{type:"button",onClick:()=>z(Ne.id),"aria-current":_e?"page":void 0,className:"relative min-w-0 flex-1 pr-8 text-left",children:[e.jsx("div",{className:"flex items-center gap-1.5 pr-1",children:e.jsx("span",{className:P("min-w-0 flex-1 truncate text-[10px] font-medium leading-4",_e?"text-foreground":"text-foreground/80"),children:Ne.title})}),e.jsx("span",{className:P("absolute right-0 top-0 shrink-0 tabular-nums text-[8px] leading-4",_e?"text-primary/75":"text-muted-foreground/55"),children:Fo(Ne.updatedAt)}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-0.5",children:[e.jsx("span",{className:"rounded-sm bg-muted/35 px-1 py-0 font-mono text-[8px] leading-3 text-muted-foreground/65",children:Ne.agent}),Ne.activeShare&&e.jsx(Fe,{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"}),kt&&e.jsx(Fe,{variant:"outline",className:"rounded-sm border-destructive/25 bg-destructive/8 px-1 py-0 text-[8px] leading-3 text-destructive shadow-none",children:"unavailable"})]}),e.jsx(Da,{status:Ne.status,isNative:Ne.conversationKind==="nativeSession",size:"compact",className:"absolute bottom-1 right-0"})]})]},Ne.id)}),ct>0&&e.jsxs("button",{type:"button",onClick:()=>{Ge&&x?x(Ge):lt(ze)},className:"mt-1 flex w-full items-center justify-center gap-1 rounded-sm border border-dashed border-border/55 bg-background/35 px-2 py-1 text-[9px] font-medium text-muted-foreground transition-colors hover:border-primary/35 hover:bg-primary/8 hover:text-primary","aria-label":`Load ${ct} more completed tasks in ${ft}`,children:[e.jsx(st,{className:"h-3 w-3"}),"Load ",ct," more completed"]})]})})})]},ze)})})})]},Le)})}):n?e.jsx("div",{className:"space-y-2 px-1",children:[1,2,3].map($=>e.jsx("div",{className:"rounded-xl border border-border/40 bg-background/30 px-3 py-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("div",{className:"mt-1 h-2.5 w-2.5 shrink-0 animate-pulse rounded-full bg-muted-foreground/20"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-2.5 animate-pulse rounded-full bg-muted-foreground/15",style:{width:`${60+$*12}%`,animationDelay:`${$*120}ms`}}),e.jsx("div",{className:"h-2 w-24 animate-pulse rounded-full bg-muted-foreground/10",style:{animationDelay:`${$*120+60}ms`}})]})]})},$))}):e.jsx("div",{className:"rounded-xl border border-dashed border-border/70 bg-background/35 px-3 py-5 text-[11px] text-muted-foreground",children:r||"No tasks match this view."})}),we?e.jsx("div",{className:"shrink-0 px-2.5 pb-2.5 pt-1.5",children:O&&J>0?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[jt,e.jsx(Z,{variant:"ghost",size:"sm",onClick:qe,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Clear"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:$e}),Te]})]}):e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsx("div",{className:"flex min-w-0 shrink-0 items-center",children:$e}),O&&e.jsx(Z,{variant:"ghost",size:"sm",onClick:qe,className:"h-5 shrink-0 rounded-sm px-1.5 text-[9px]",children:"Done"})]})}):null]}),e.jsx(Tc,{node:k,open:k!==null,onOpenChange:$=>{$||X(null)}})]})}async function Lc(t,s){var n,r;try{const o=await zo(t,s),i={...o,url:_a(o.url)};if((r=(n=globalThis.navigator)==null?void 0:n.clipboard)!=null&&r.writeText)try{await globalThis.navigator.clipboard.writeText(i.url),de.success("Shared link copied")}catch{de.success("Shared link created")}else de.success("Shared link created");return i}catch(o){de.error(o instanceof Error?o.message:"Failed to create shared link");return}}async function Ic(t){try{return await Uo(t),de.success("Shared link stopped"),!0}catch(s){return de.error(s instanceof Error?s.message:"Failed to stop shared link"),!1}}function Bc(t,s,n){const r=a.useCallback(()=>{s(),n()},[s,n]),o=a.useCallback(async d=>{if(!t)return;const c=await Lc(t.id,d);return c&&r(),c},[t,r]),i=a.useCallback(async()=>{if(!t)return!1;const d=await Ic(t.id);return d&&r(),d},[t,r]);return{handleShareTask:o,handleStopShareTask:i}}function da(t,s,n){const r=a.useRef(s);r.current=s,a.useEffect(()=>{let d=0,c=0;const f=g=>{const l=g.touches[0];l&&(d=l.clientX,c=l.clientY)},h=g=>{var v,A,p,S;const l=g.changedTouches[0];if(!l)return;const N=l.clientX-d;Math.abs(l.clientY-c)>100||Math.abs(N)<50||(N>0?(A=(v=r.current).onSwipeRight)==null||A.call(v):(S=(p=r.current).onSwipeLeft)==null||S.call(p))},y=(t==null?void 0:t.current)??document;return y.addEventListener("touchstart",f,{passive:!0}),y.addEventListener("touchend",h,{passive:!0}),()=>{y.removeEventListener("touchstart",f),y.removeEventListener("touchend",h)}},[t,n==null?void 0:n.threshold,n==null?void 0:n.maxVertical])}const Rc="(min-width: 1024px)",$c="(min-width: 1800px)";function ca(t){var s,n,r;return((r=(n=(s=globalThis.window)==null?void 0:s.matchMedia)==null?void 0:n.call(s,t))==null?void 0:r.matches)??!1}function Oc(){var n,r;const t=(n=globalThis.document)==null?void 0:n.documentElement;if(!t||!((r=globalThis.window)!=null&&r.getComputedStyle))return 16;const s=Number.parseFloat(globalThis.window.getComputedStyle(t).fontSize);return Number.isFinite(s)&&s>0?s:16}function Fc(){const[t,s]=a.useState(()=>Vo(An(),Ho({operationsOpen:ca($c)}))),[n,r]=a.useState(!1),o=a.useRef(null),i=a.useRef(null),d=a.useRef(null),c=t.layout.desktopTasksOpen,f=t.layout.operationsOpen,h=t.sizes;a.useEffect(()=>{qo(An(),t)},[t]);const y=a.useCallback((A,p)=>{s(S=>{const b=S.layout[A],j=typeof p=="function"?p(b):p;return j===b?S:{...S,layout:{...S.layout,[A]:j}}})},[]),g=a.useCallback(A=>{y("desktopTasksOpen",A)},[y]),l=a.useCallback(A=>{y("operationsOpen",A)},[y]);da(i,{onSwipeLeft:()=>r(!1)}),da(d,{onSwipeRight:()=>l(!1)});const N=a.useCallback(()=>{if(ca(Rc)){g(A=>!A);return}r(A=>!A)},[g]);a.useEffect(()=>{var S,b,j;const A=w=>{const T=o.current;if(!T)return;w.preventDefault();const D=Wo(T.panel,T.startSize,T.startClientX,T.startClientY,w.clientX,w.clientY,T.rootFontSize);s(U=>({...U,sizes:{...U.sizes,[T.panel]:D}}))},p=()=>{o.current=null};return(S=globalThis.window)==null||S.addEventListener("pointermove",A),(b=globalThis.window)==null||b.addEventListener("pointerup",p),(j=globalThis.window)==null||j.addEventListener("pointercancel",p),()=>{var w,T,D;(w=globalThis.window)==null||w.removeEventListener("pointermove",A),(T=globalThis.window)==null||T.removeEventListener("pointerup",p),(D=globalThis.window)==null||D.removeEventListener("pointercancel",p)}},[]);const C=a.useCallback((A,p)=>{var S,b;p.preventDefault(),(b=(S=p.currentTarget).setPointerCapture)==null||b.call(S,p.pointerId),o.current={panel:A,startSize:h[A],startClientX:p.clientX,startClientY:p.clientY,rootFontSize:Oc()}},[h]),v=a.useCallback((A,p)=>{p.preventDefault(),s(S=>({...S,sizes:{...S.sizes,[A]:Ko(A,S.sizes[A],p.deltaY)}}))},[]);return{desktopTasksOpen:c,mobileTasksPanelOpen:n,mobileTasksPanelRef:i,operationsOpen:f,operationsPanelRef:d,panelResize:{sizes:{tasks:As(h.tasks),operations:As(h.operations),terminal:As(h.terminal)},onPointerDown:C,onWheel:v},setMobileTasksPanelOpen:r,setOperationsOpen:l,toggleTasksPanel:N}}function zc(t,s){const n=s.taskId,r=s.updates;return typeof n!="string"||!r||typeof r!="object"?t:t.map(o=>o.id===n?{...o,...r}:o)}const Uc="notify_desktop_task";function Vc(t=mr()){var n,r;const s=(r=(n=t==null?void 0:t.__TAURI__)==null?void 0:n.core)==null?void 0:r.invoke;return typeof s=="function"?s:null}async function Hc(t,s=mr()){const n=Vc(s);return n?(await n(Uc,t),!0):!1}function qc(t,s){const n=[];for(const r of s){const o=Kc(r.status);if(!o)continue;const i=t.get(r.id);!i||i.status===r.status||n.push({taskId:r.id,title:r.title.trim()||"Meshy task",status:o,assignedNodeName:r.assignedNodeName??null,projectPath:r.effectiveProjectPath??r.project??null})}return n}function Kc(t){return t==="completed"||t==="failed"?t:null}function mr(){return typeof window>"u"?null:window}function Wc({isLeader:t,selfId:s}){return{...!t&&s?{assignedTo:s}:{},completedLimitPerProject:rn}}function Xs(t){return`${t.assignedTo??"__unassigned__"}::${t.projectPath}`}function Gc(t,s){const n=new Map(t.map(r=>[r.id,r]));for(const r of s)n.set(r.id,r);return Array.from(n.values())}function Yc(t,s,n=new Set){return!s||n.has(s.id)||t.some(r=>r.id===s.id)?t:Ga(t,s)}function Qc({isLeader:t,selfId:s,sseConnected:n,preservedTask:r,subscribe:o}){const[i,d]=a.useState([]),[c,f]=a.useState([]),[h,y]=a.useState(!0),[g,l]=a.useState(null),N=a.useRef(new Set),C=a.useRef(null),v=a.useRef(null),A=a.useCallback(async()=>{try{const j=await Mn(Wc({isLeader:t,selfId:s}));d(Yc(j.tasks,r,N.current)),f(j.completedGroups??[]),l(null)}catch(j){l(j instanceof Error?j.message:"Failed to load tasks")}finally{y(!1)}},[t,r,s]),p=a.useCallback(async j=>{if(!j.hasMore||!j.nextCursor)return;const w=await Mn({status:"completed",assignedTo:j.assignedTo??"__unassigned__",projectPath:j.projectPath,cursor:j.nextCursor,limit:rn});d(T=>Gc(T,w.tasks)),f(T=>T.map(D=>Xs(D)===Xs(j)?{...D,returned:Math.min(D.total,D.returned+w.tasks.length),hasMore:w.hasMore===!0,nextCursor:w.nextCursor??null}:D))},[]),S=a.useCallback(()=>{v.current===null&&(v.current=window.setTimeout(()=>{v.current=null,A()},Go))},[A]),b=a.useCallback(j=>{const w=new Set(j);if(w.size!==0){for(const T of w)N.current.add(T);d(T=>T.filter(D=>!w.has(D.id)))}},[]);return Yo(A,Xo(n)),a.useEffect(()=>()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]),a.useEffect(()=>{const j=C.current;if(j)for(const w of qc(j,i))Hc(w).catch(()=>{});C.current=new Map(i.map(w=>[w.id,w]))},[i]),a.useEffect(()=>{const j=[o("task.updated",w=>{d(T=>zc(T,w.data))}),o("task.status",w=>{d(T=>Qo(T,w.data))}),o("node",w=>{Pn(w.type)&&S()}),o("task",w=>{if(w.type==="task.deleted"){const T=w.data.taskId;typeof T=="string"&&N.current.add(T),d(D=>Zo(D,w.data))}Pn(w.type)&&S()})];return()=>j.forEach(w=>w())},[o,S]),{completedGroups:c,fetchTasks:A,loadCompletedTasksPage:p,removeTasksFromList:b,setTasks:d,tasks:i,tasksError:g,tasksLoading:h}}function xr(t){return t.map(s=>({...s}))}function Zc(t,s){const n=s.get(t);return{logs:n?xr(n.logs):[],transcriptLoading:(n==null?void 0:n.loaded)!==!0}}function Xc(t,s){return s.data.nodeId===t.self.id||s.data.name===t.self.name||s.data.endpoint===t.self.endpoint}function Jc(t,s){const n=t.data.name;if(typeof n=="string"&&n.length>0)return n;const r=t.data.nodeId;return typeof r=="string"?(s==null?void 0:s.get(r))??r:"node"}function eu({cluster:t,subscribe:s}){a.useEffect(()=>{var r;if(((r=t==null?void 0:t.self)==null?void 0:r.role)!=="leader")return;const n=new Map(t.nodes.map(o=>[o.id,o.name]));return n.set(t.self.id,t.self.name),s("node",o=>{const i=Jc(o,n),d=Xc(t,o);o.type==="node.joined"&&!d&&de.success(`${i} joined the cluster`),o.type==="node.left"&&!d&&de.message(`${i} left the cluster`)})},[t,s])}const tu=[0,300,1e3,2e3];function su({task:t,getActiveTaskId:s,setLogs:n,setPendingMessages:r,setTranscriptLoading:o}){t.conversationKind==="nativeSession"&&(async()=>{try{for(const i of tu){if(i>0&&await new Promise(d=>setTimeout(d,i)),s()!==t.id)return;try{const d=await zs(t.id);if(s()!==t.id||(n(c=>za(c,d.logs)),r(c=>Vs(c,d.logs)),d.total>0))return}catch{}}}finally{s()===t.id&&(o==null||o(!1))}})()}function nu(t,s){return Re(t??{})===Re(s??{})}function au(t){return t&&"status"in t&&typeof t.status=="string"?t.status:void 0}function ua(t,s){return{...t,enabled:!0,alwaysOnline:s}}function hr(t){var s,n;return((s=t==null?void 0:t.status)==null?void 0:s.trim())||((n=t==null?void 0:t.lastStatus)==null?void 0:n.trim())||"Unknown"}function ru({operationStarting:t,loading:s,refreshing:n,savedStatus:r,fallbackStatus:o}){return t?"Starting":s?"Listing DevBoxes":n?"Refreshing":r??o}function ma({devbox:t,showStatus:s=!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:t.name}),t.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",t.projectName]})]}),s&&e.jsx("span",{className:"ml-auto shrink-0 rounded-sm border border-border/70 bg-background/70 px-1.5 py-0 text-[10px] leading-none text-muted-foreground",children:hr(t)})]})}function ou({node:t,open:s,startInProgress:n=!1,onOpenChange:r,onRefresh:o}){const i=(t==null?void 0:t.id)??null,d=s&&!n&&Jn(t==null?void 0:t.status,(t==null?void 0:t.devbox)??null),[c,f]=a.useState([]),[h,y]=a.useState(()=>t!=null&&t.devbox?Re(t.devbox):""),[g,l]=a.useState(()=>(t==null?void 0:t.devbox)??null),[N,C]=a.useState(()=>ea((t==null?void 0:t.devbox)??null)),[v,A]=a.useState(!1),[p,S]=a.useState(d),[b,j]=a.useState(!1),[w,T]=a.useState(!1),[D,U]=a.useState(()=>{var k;return((k=t==null?void 0:t.devbox)==null?void 0:k.alwaysOnline)===!0}),E=a.useMemo(()=>{const k=c.find(X=>Re(X)===h);return k||(At(g)&&Re(g)===h?g:void 0)},[g,c,h]),F=au(E??void 0),B=N?F??(g==null?void 0:g.lastStatus):(g==null?void 0:g.lastStatus)??F,Q=(t==null?void 0:t.status)==="online"||(t==null?void 0:t.status)==="busy"?"Running":"Unknown",ee=w||n,V=ru({operationStarting:ee,loading:v,refreshing:p,savedStatus:B,fallbackStatus:Q}),H=N&&!!E&&!nu(g,E),se=(g==null?void 0:g.alwaysOnline)===!0!==D,ie=yc({nodeStatus:t==null?void 0:t.status,status:V,current:g,selected:E}),L=!!ie,K=!!E&&(H||se)&&!L,_=E??g,W=a.useCallback(async()=>{if(i){S(!0);try{const k=await Jo(i);l(k.devbox),y(Re(k.devbox))}catch(k){de.error(k instanceof Error?k.message:"Failed to refresh DevBox status")}finally{S(!1)}}},[i]),x=a.useCallback(async k=>{A(!0);try{const X=await ei();f(X),y(re=>Nc({previousKey:re,baseDevBox:k,listed:X}))}catch(X){de.error(X instanceof Error?X.message:"Failed to load DevBoxes")}finally{A(!1)}},[]);a.useEffect(()=>{if(!s||!i)return;let k=!1;const X=(t==null?void 0:t.devbox)??null,re=ea(X),ce=!n&&Jn(t==null?void 0:t.status,X);A(!1),S(ce),C(re),l(X),U((X==null?void 0:X.alwaysOnline)===!0),y(At(X)?Re(X):""),f([]);async function J(){ce&&await W(),!k&&re&&await x(X)}return J(),()=>{k=!0}},[x,t==null?void 0:t.devbox,t==null?void 0:t.status,i,s,W,n]);async function z(){C(!0),c.length===0&&await x(g)}async function m(){if(!(!t||!E)){j(!0);try{const k=await Ln(t.id,ua(E,D));l(k.node.devbox??null),k.node.devbox&&y(Re(k.node.devbox)),C(!1),de.success(`Configured DevBox for ${t.name}`),await(o==null?void 0:o())}catch(k){de.error(k instanceof Error?k.message:"Failed to configure DevBox")}finally{j(!1)}}}async function G(){if(!(!t||!ie)){T(!0);try{if(E&&(H||se)){const X=await Ln(t.id,ua(E,D));l(X.node.devbox??null),X.node.devbox&&y(Re(X.node.devbox)),C(!1)}const{operation:k}=await Ra(t.id);l(X=>X&&{...X,lastStatus:"Starting",checkedAt:Date.now(),operationId:k.id}),de.success(`Start requested for ${t.name}`),await(o==null?void 0:o())}catch(k){de.error(k instanceof Error?k.message:"Failed to start DevBox")}finally{T(!1)}}}const M=v?"Loading DevBoxes...":c.length===0?"No DevBoxes available":"Select a DevBox",q=V==="Running"&&(t==null?void 0:t.status)==="offline";return e.jsx(Lt,{open:s,onOpenChange:r,children:e.jsxs(It,{className:"max-w-md gap-3 rounded-sm p-4",children:[e.jsxs(sn,{className:"space-y-1",children:[e.jsx(Yt,{className:"text-sm",children:"Configure DevBox"}),e.jsxs(an,{className:"text-xs",children:["Bind ",t!=null&&t.name?e.jsx("span",{className:"font-medium text-foreground",children:t.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:[(N||_)&&e.jsxs("div",{className:"flex min-h-9 items-center justify-between gap-3 rounded-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs",children:[e.jsx("div",{className:"min-w-0 flex-1",children:N?e.jsxs(ke,{value:h,onValueChange:y,disabled:v||b||w||c.length===0,children:[e.jsx(Se,{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:v&&!E?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"}),M]}):E?e.jsx(ma,{devbox:E}):e.jsx(Be,{placeholder:M})}),e.jsx(Ce,{children:c.map(k=>e.jsx(xe,{value:Re(k),textValue:`${k.name} ${k.projectName??""} ${hr(k)}`,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(ma,{devbox:k,showStatus:!0})},Re(k)))})]}):_&&e.jsxs("div",{className:"min-w-0 truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:_.name}),_.projectName&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",_.projectName]})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(Fe,{variant:"outline",className:"rounded-sm px-1.5 py-0 text-[10px]",children:[(v||p)&&e.jsx(ue,{className:"mr-1 h-2.5 w-2.5 animate-spin"}),V]}),(g==null?void 0:g.name)&&e.jsx(Z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{z()},disabled:v||b||ee||N,"aria-label":"Edit DevBox binding",title:"Edit DevBox binding",className:"h-6 w-6 rounded-sm text-muted-foreground hover:text-foreground",children:v&&N?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(Bt,{className:"h-3 w-3"})})]})]}),q&&e.jsx("div",{className:"rounded-sm 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-sm border border-border/60 bg-muted/20 px-3 py-2 text-xs text-foreground",children:[e.jsx(Kt,{checked:D,onCheckedChange:k=>U(k===!0),disabled:b||w||ee,"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(Aa,{className:"gap-2 sm:space-x-0",children:[e.jsx(Z,{variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:b||w,className:"h-8 rounded-sm text-xs",children:"Close"}),L&&e.jsxs(Z,{size:"sm",onClick:G,disabled:w,className:"h-8 rounded-sm text-xs",children:[w?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(js,{className:"h-3.5 w-3.5"}),"Start DevBox"]}),!L&&e.jsxs(Z,{size:"sm",onClick:m,disabled:!K||b,className:"h-8 rounded-sm text-xs",children:[b&&e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}async function iu(t,s=ti){if(t.length===0)return new Set;const n=new Set(t),[r,o]=await Promise.all([s({kind:"devbox.start",status:"queued"}),s({kind:"devbox.start",status:"running"})]);return new Set([...r,...o].filter(i=>n.has(i.nodeId)).map(i=>i.nodeId))}function lu({cluster:t,refresh:s}){const[n,r]=a.useState(null),[o,i]=a.useState(null),[d,c]=a.useState(()=>new Set),[f,h]=a.useState(()=>new Set),y=a.useMemo(()=>(t==null?void 0:t.nodes.find(p=>p.id===n))??null,[t==null?void 0:t.nodes,n]),g=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(p=>{var S;return(S=p.devbox)==null?void 0:S.enabled}).map(p=>p.id)),[t==null?void 0:t.nodes]),l=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(p=>{var S;return Ns(p.status,(S=p.devbox)==null?void 0:S.lastStatus,p.devbox)}).map(p=>p.id)),[t==null?void 0:t.nodes]),N=a.useMemo(()=>new Set(((t==null?void 0:t.nodes)??[]).filter(p=>{var S;return Mt((S=p.devbox)==null?void 0:S.lastStatus)}).map(p=>p.id)),[t==null?void 0:t.nodes]),C=a.useMemo(()=>{const p=new Set(d);o&&p.add(o);for(const S of f)p.add(S);for(const S of N)p.add(S);return p},[f,o,d,N]);a.useEffect(()=>{let p=!1;const S=[...g];async function b(){try{const j=await iu(S);p||h(j)}catch{p||h(new Set)}}return b(),()=>{p=!0}},[g]),a.useEffect(()=>{c(p=>{var j;let S=!1;const b=new Set(p);for(const w of p){const T=t==null?void 0:t.nodes.find(D=>D.id===w);(T==null?void 0:T.status)!=="online"&&(!((j=T==null?void 0:T.devbox)!=null&&j.lastStatus)||Mt(T.devbox.lastStatus))||(b.delete(w),S=!0)}return S?b:p})},[t==null?void 0:t.nodes]);const v=a.useCallback(async p=>{const S=t==null?void 0:t.nodes.find(b=>b.id===p);if(S){i(p),c(b=>new Set(b).add(p));try{await Ra(p),de.success(`Start requested for ${S.name}`),s()}catch(b){c(j=>{const w=new Set(j);return w.delete(p),w}),de.error(b instanceof Error?b.message:"Failed to start DevBox")}finally{i(null)}}},[t==null?void 0:t.nodes,s]);return{devBoxDialog:e.jsx(ou,{node:y,open:n!==null,startInProgress:y?C.has(y.id):!1,onOpenChange:p=>{p||r(null)},onRefresh:s}),devBoxNodeIds:g,devBoxStartNodeId:o,devBoxStartNodeIds:l,devBoxStartingNodeIds:C,openDevBox:r,startDevBox:v}}function du(t){const[s,n]=a.useState(null),r=a.useCallback(i=>{t&&n(i)},[t]);return{nodeSettingsDialog:e.jsx(si,{open:s!==null,onOpenChange:i=>{i||n(null)},initialSelectedNodeId:s??void 0,showTrigger:!1}),openNodeSettings:r}}function cu(t=!1){return!t}function uu({activeTaskId:t,fetchActiveTask:s,isRunning:n=!1,setPendingMessages:r,setTask:o,setTasks:i}){const d=a.useCallback((h,y)=>{o(g=>g&&g.id===h?{...g,queuedMessages:y}:g),i(g=>g.map(l=>l.id===h?{...l,queuedMessages:y}:l))},[o,i]),c=a.useCallback(async h=>{if(!t)return!1;const y=`local-${Date.now()}-${Math.random().toString(16).slice(2)}`,g=cu(n);g&&r(l=>[...l,{id:y,content:h,timestamp:new Date().toISOString()}]);try{const l=await ni(t,h);return l.queued&&(g&&r(N=>N.filter(C=>C.id!==y)),l.queuedMessages&&d(t,l.queuedMessages)),s(),!0}catch(l){return g&&r(N=>N.filter(C=>C.id!==y)),de.error(l instanceof Error?l.message:"Failed to send message"),!1}},[t,s,n,r,d]);return{cancelQueuedMessage:a.useCallback(async h=>{if(t)try{const y=await ai(t,h);d(t,y.queuedMessages),s()}catch(y){de.error(y instanceof Error?y.message:"Failed to cancel queued message")}},[t,s,d]),queueFollowUpMessage:c}}const xa="grid-cols-[1.5rem_5.25rem_4rem_minmax(8rem,1fr)_4rem_4rem_6rem]",mu={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function xu(t,s){const n=s.search.trim().toLowerCase();return t.filter(r=>s.agent!=="all"&&r.agent!==s.agent||s.kind!=="all"&&r.kind!==s.kind?!1:n?[r.name,r.description,r.source,r.version,r.agent,r.kind].some(o=>o==null?void 0:o.toLowerCase().includes(n)):!0)}function pr(t){return t.kind==="mcp"?"-":t.sizeBytes<1024?`${t.sizeBytes} B`:t.sizeBytes<1024*1024?`${Math.round(t.sizeBytes/1024)} KB`:`${(t.sizeBytes/1024/1024).toFixed(1)} MB`}function hu({items:t,selectedIds:s,activeId:n,onToggleSelected:r,onOpenDetail:o}){return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden rounded-sm border border-border/60 bg-card/35",children:[e.jsxs("div",{className:P("grid shrink-0 gap-2 border-b border-border/55 bg-primary/6 px-2 py-1.5 text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",xa),children:[e.jsx("span",{}),e.jsx("span",{children:"Agent"}),e.jsx("span",{children:"Kind"}),e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Ver"}),e.jsx("span",{children:"Size"}),e.jsx("span",{children:"Source"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:t.length>0?t.map(i=>e.jsxs("button",{type:"button",onClick:()=>o(i),className:P("grid h-7 w-full items-center gap-2 border-b border-border/30 px-2 text-left text-[10px] transition-colors hover:bg-primary/6",xa,n===i.id&&"bg-primary/10 text-primary shadow-[inset_2px_0_0_hsl(var(--primary))]"),children:[e.jsx("span",{onClick:d=>d.stopPropagation(),children:e.jsx(Kt,{className:"h-3 w-3",checked:s.has(i.id),onCheckedChange:d=>r(i.id,d===!0),"aria-label":`Select ${i.name}`})}),e.jsx(pu,{agent:i.agent}),e.jsx("span",{children:i.kind}),e.jsx("span",{className:"truncate font-medium text-foreground",children:i.name}),e.jsx("span",{className:"truncate text-muted-foreground",children:i.version??"-"}),e.jsx("span",{className:"truncate text-muted-foreground",children:pr(i)}),e.jsx("span",{className:"truncate text-muted-foreground",children:i.source??"local"})]},i.id)):e.jsx("div",{className:"px-3 py-8 text-center text-[11px] text-muted-foreground",children:"No capabilities match this view."})})]})}function pu({agent:t}){const s=mu[t];return e.jsx("span",{className:"block min-w-0 truncate text-[10px] font-medium leading-3 text-muted-foreground",title:s,children:s})}const ha=320,pa=560,fr=384,fa=360;function fu(t,s=pa+fa){const n=Math.max(ha,Math.min(pa,s-fa));return Math.min(Math.max(Math.round(t),ha),n)}function gu(t,s,n,r){return fu(t+s-n,r)}function bu({detail:t,deleting:s=!1,onDelete:n,desktopWidth:r=fr,pending:o=!1}){const i={"--capability-detail-width":`${r}px`};if(!t)return e.jsx("aside",{"data-capability-detail-panel":"true",style:i,className:"hidden min-h-0 shrink-0 animate-panel-settle bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-3 text-[11px] text-muted-foreground lg:block lg:w-[var(--capability-detail-width)]",children:o?"Loading capability metadata...":"No capability selected."});const d=t.kind==="mcp"?"mcp":"files";return e.jsxs("aside",{"data-capability-detail-panel":"true",style:i,className:"flex min-h-0 w-full shrink-0 animate-panel-settle flex-col bg-gradient-to-b from-primary/6 via-card/28 to-background/60 px-3 py-2.5 lg:w-[var(--capability-detail-width)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[e.jsx("div",{className:"truncate text-[13px] font-semibold leading-5 text-foreground",children:t.name}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-1",children:[e.jsx(Fe,{variant:"secondary",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary",children:t.agent}),e.jsx(Fe,{variant:"outline",className:"rounded-sm border-0 bg-card/72 px-1.5 py-0 text-[8px] text-primary/90",children:t.kind})]})]}),n&&e.jsxs(is,{children:[e.jsx(Fs,{asChild:!0,children:e.jsx(Z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground hover:text-destructive","aria-label":"Delete capability",title:"Delete capability",disabled:s,children:e.jsx(Ba,{className:"h-3.5 w-3.5"})})}),e.jsxs(ls,{className:"max-w-[22rem] gap-2 rounded-xl p-4",children:[e.jsxs(ds,{className:"space-y-1",children:[e.jsxs(cs,{className:"text-sm",children:["Delete ",t.name,"?"]}),e.jsxs(us,{className:"text-[11px] leading-4",children:["This removes the selected ",t.kind," from ",t.scope.kind==="global"?"the user profile":"this project","."]})]}),e.jsxs(ms,{className:"gap-1 pt-0 sm:space-x-1",children:[e.jsx(xs,{className:"h-7 rounded-lg px-2 text-[11px]",children:"Cancel"}),e.jsx(hs,{className:"h-7 rounded-lg px-2 text-[11px]",onClick:n,disabled:s,children:"Delete"})]})]})]})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-1 text-[9px]",children:[e.jsx(rs,{label:"Version",value:t.version??"-"}),e.jsx(rs,{label:"Size",value:pr(t)}),e.jsx(rs,{label:"Files",value:String(t.fileCount)}),e.jsx(rs,{label:"Source",value:t.source??"local"})]}),e.jsxs(en,{defaultValue:d,className:"mt-2 flex min-h-0 flex-1 flex-col",children:[e.jsxs(Js,{className:"grid h-auto grid-cols-2 rounded-sm bg-primary/8 p-0.5",children:[t.kind==="mcp"?e.jsx(bt,{value:"mcp",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"MCP"}):e.jsx(bt,{value:"files",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"Files"}),e.jsx(bt,{value:"readme",className:"rounded-sm px-2 py-0.5 text-[9px]",children:"README"})]}),t.kind==="mcp"?e.jsx(ot,{value:"mcp",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(vu,{detail:t})}):e.jsx(ot,{value:"files",className:"mt-2 min-h-0 flex-1 overflow-auto",children:e.jsx(ju,{detail:t})}),e.jsx(ot,{value:"readme",className:"mt-2 min-h-0 flex-1 overflow-auto",children:t.readmeMarkdown?e.jsx(Gi,{content:t.readmeMarkdown,className:"overflow-hidden rounded-sm border-0 bg-background/70 shadow-none [&>div:first-child>div]:border-0 [&>div:first-child]:border-b-0",previewClassName:"px-3 py-2 text-[11px] leading-5",rawClassName:"text-[10px] leading-4"}):e.jsx(xn,{children:"No README content."})})]},t.id)]})}function vu({detail:t}){const s=t.mcpPreview??[];return s.length===0?e.jsx(xn,{children:"No MCP entries."}):e.jsx("div",{className:"space-y-1.5",children:s.map(n=>e.jsxs("div",{className:"rounded-sm bg-card/72 p-2 text-[10px] shadow-none",children:[e.jsx("div",{className:"font-semibold text-foreground",children:n.serverName}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto rounded-sm bg-background/55 px-2 py-1 whitespace-pre-wrap break-all font-mono text-[9px] leading-4 text-muted-foreground",children:JSON.stringify(n.config,null,2)})]},n.serverName))})}function ju({detail:t}){const s=t.fileTree??[];return s.length===0?e.jsx(xn,{children:"No files."}):e.jsx("div",{className:"space-y-1 overflow-auto rounded-sm bg-card/72 p-2 font-mono text-[9px] leading-4 text-muted-foreground shadow-none",children:s.map(n=>e.jsx("div",{children:n.relPath},n.relPath))})}function xn({children:t}){return e.jsx("div",{className:"rounded-sm bg-primary/5 px-2 py-6 text-center text-[10px] text-muted-foreground",children:t})}function rs({label:t,value:s}){return e.jsxs("div",{className:"rounded-sm bg-card/72 px-2 py-0.5 shadow-none",children:[e.jsx("div",{className:"text-[7px] uppercase tracking-[0.14em] text-muted-foreground",children:t}),e.jsx("div",{className:"truncate text-[9px] font-medium text-foreground",children:s})]})}const wu=20,yu=288,Nu=360,ku=440;function Su(){if(typeof window>"u"||typeof document>"u")return 1;const t=window.getComputedStyle(document.documentElement),s=t.zoom||t.getPropertyValue("--ui-zoom"),n=Number.parseFloat(s);return Number.isFinite(n)&&n>0?n:1}function Cu({triggerRect:t,targetRect:s,viewportRect:n,compact:r,browserOpen:o=!1,portalAlign:i,cssZoom:d=1}){const c=Number.isFinite(d)&&d>0?d:1,f=8,h=n.top+f,y=n.bottom-f,g=n.left+f,l=n.right-f,N=Math.max(0,y-t.bottom-4),C=Math.max(0,t.top-h-4),v=r?C<140&&N>C:N>=220||N>=C,A=v?N:C,p=Math.max(140,y-h),S=r&&o,w=Math.min(p,S?ku:320,Math.max(S?Nu:140,A)),T=yu*c,D=i==="end"?t.right-T:t.left,E=(Math.max(g,Math.min(D,l-T))-s.left)/c;if(!v&&!S)return{left:E,bottom:(s.bottom-(t.top-4))/c,maxHeight:w/c};const F=v?t.bottom+4:t.top-w-4,B=Math.max(h,Math.min(F,y-w));return{left:E,top:(B-s.top)/c,maxHeight:w/c}}function hn(t){if(!t.workDir)return[];const s=[],n=new Set,r=o=>{!o||n.has(o)||(n.add(o),s.push(o))};r(t.workDir);for(const o of t.workDirFolders??[])r(br(o)?o:vr(t.workDir,o));return s}function Tu(t,s){if(t.kind==="global")return{nodeId:s.id,scope:{kind:"global"}};const n=hn(s),r=n.find(o=>o===t.projectPath);return r?{nodeId:s.id,scope:{kind:"project",projectPath:r}}:n[0]?{nodeId:s.id,scope:{kind:"project",projectPath:n[0]}}:{nodeId:s.id,scope:{kind:"global"}}}function _u(t,s){return{nodeId:t,scope:s}}function ga(t,s,n){const r=s.trim();return!r||r==="."?t.workDir??r:n||br(r)?r:t.workDir?vr(t.workDir,r):r}function Eu({node:t,scope:s,clusterNodes:n,onSelectionChange:r}){const o=a.useMemo(()=>Pu(n,t),[n,t]),i=a.useMemo(()=>hn(t),[t]),d=a.useMemo(()=>o.map(c=>({value:c.id,label:c.name,description:`${c.role} · ${c.status}`,status:c.status})),[o]);return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-2",children:[e.jsx(Mu,{ariaLabel:"Capability node",value:t.name,description:`${t.role} · ${t.status}`,options:d,selectedValue:t.id,onSelect:c=>{const f=o.find(h=>h.id===c);f&&(r==null||r(Tu(s,f)))}}),e.jsx(gr,{node:t,projectPaths:i,selectedScope:s,onSelect:c=>r==null?void 0:r(_u(t.id,c))}),e.jsx(Du,{node:t})]})}function Du({node:t}){return e.jsxs("div",{"data-capability-node-meta":"true",className:"flex min-w-0 items-center gap-1 border-0 bg-transparent px-0.5 text-[8px] leading-3 text-muted-foreground",title:`${t.role} · ${t.status}`,children:[e.jsx("span",{className:"truncate capitalize",children:t.role}),e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(t.status))})]})}function gr({node:t,projectPaths:s,selectedScope:n,onSelect:r,compact:o=!1,portal:i=!1,portalAlign:d="start"}){const[c,f]=a.useState(!1),[h,y]=a.useState(null),[g,l]=a.useState(!1),[N,C]=a.useState(!1),[v,A]=a.useState(null),[p,S]=a.useState(!1),[b,j]=a.useState(null),w=a.useRef(null),T=a.useRef(null),D=a.useRef(null),U=a.useMemo(()=>s.map(_=>({value:_,label:va(_),description:_})),[s]),E=n.kind==="project"?n.projectPath:void 0,F=n.kind==="global"?"Global":va(n.projectPath),B=n.kind==="global"?"Global":n.projectPath,Q=a.useCallback(()=>{var _;return!i||typeof document>"u"?null:((_=T.current)==null?void 0:_.closest('[data-capability-share-dialog="true"]'))??document.body},[i]),ee=a.useCallback(()=>{if(!i||!T.current||typeof window>"u")return;const _=T.current.getBoundingClientRect(),W=Q(),x=W&&W!==document.body?W.getBoundingClientRect():{left:0,top:0,bottom:window.innerHeight};j(Cu({triggerRect:_,targetRect:x,viewportRect:{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight},compact:o,browserOpen:p,portalAlign:d,cssZoom:Su()}))},[p,o,Q,i,d]);a.useEffect(()=>{c||S(!1)},[c]),a.useEffect(()=>{if(!c)return;const _=W=>{if(!(W.target instanceof Node))return;const x=W.composedPath(),z=w.current?x.includes(w.current):!1,m=D.current?x.includes(D.current):W.target instanceof Element&&!!W.target.closest('[data-capability-scope-menu="true"]');!z&&!m&&f(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[c]),a.useEffect(()=>{if(!(!c||!i))return ee(),window.addEventListener("resize",ee),window.addEventListener("scroll",ee,!0),()=>{window.removeEventListener("resize",ee),window.removeEventListener("scroll",ee,!0)}},[c,i,ee]);const V=async(_,W=0,x=!1)=>{if(t.workDir){A(null),x?C(!0):l(!0);try{const z=await Ca(t.id,{path:_||".",limit:wu,offset:W,directoriesOnly:!0,allowAbsolute:!0});y(m=>x&&m?{...z,entries:[...m.entries,...z.entries]}:z)}catch(z){A(z instanceof Error?z.message:"Failed to browse folders"),x||y(null)}finally{l(!1),C(!1)}}};a.useEffect(()=>{!c||!p||!t.workDir||(y(null),A(null),V(E||"."))},[p,c,t.id,t.workDir,E]);const H=(_,W=!1)=>{r({kind:"project",projectPath:ga(t,_,W)}),f(!1)},se=()=>{r({kind:"global"}),f(!1)},ie=h?ga(t,h.currentPath,h.isAbsolute):E??t.workDir??"",L=i?Q():null,K=e.jsxs("div",{ref:D,"data-capability-scope-menu":"true","aria-hidden":!c,onClick:_=>_.stopPropagation(),onMouseDown:_=>_.stopPropagation(),onPointerDown:_=>_.stopPropagation(),style:i&&b?{left:b.left,top:b.top,bottom:b.bottom,height:o&&p?b.maxHeight:void 0,maxHeight:b.maxHeight}:void 0,className:P(i?"absolute z-[80] flex w-72 flex-col overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none pointer-events-auto":"absolute left-0 z-50 flex max-h-[28rem] w-72 flex-col overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!i&&(o?"top-7":"top-9"),!c&&"hidden"),children:[e.jsxs("div",{className:"shrink-0 border-b border-border/55 p-1",children:[e.jsx("div",{className:P("px-2 text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",o?"pb-0.5 pt-0.5 leading-3":"pb-1 pt-1"),children:"Scope"}),e.jsxs("div",{className:P("overflow-y-auto pr-0.5",o?"max-h-32":"max-h-40"),children:[e.jsx(ba,{icon:"global",label:"Global",selected:n.kind==="global",onSelect:se,compact:o}),U.length>0?U.map(_=>e.jsx(ba,{icon:"folder",label:_.label,description:_.description,selected:E===_.value,onSelect:()=>H(_.value,!0),compact:o},_.value)):e.jsx("div",{className:P("flex items-center px-2 text-muted-foreground",o?"h-7 text-[9px]":"h-8 text-[10px]"),children:"No known projects"})]})]}),e.jsxs("div",{className:P("border-b border-border/55",p?"flex min-h-0 flex-1 flex-col":"shrink-0"),children:[e.jsxs("button",{type:"button","aria-expanded":p,onClick:()=>S(_=>!_),className:P("flex w-full items-center gap-1 px-2 text-left text-[8px] font-semibold uppercase tracking-[0.14em] text-muted-foreground transition-colors hover:bg-muted/45 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",o?"py-1 leading-3":"py-1.5"),children:[e.jsx(Pt,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Browse folders"}),e.jsx(st,{className:P("h-3 w-3 shrink-0 transition-transform duration-200",p&&"rotate-180")})]}),p&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"shrink-0 px-2 pb-1.5",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:()=>(h==null?void 0:h.parentPath)&&void V(h.parentPath),disabled:!(h!=null&&h.parentPath)||g,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground disabled:opacity-40",title:"Parent directory",children:e.jsx(Ua,{className:"h-2.5 w-2.5"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[9px] text-muted-foreground",title:ie,children:ie}),h&&e.jsx("button",{type:"button",onClick:()=>H(h.currentPath,h.isAbsolute),className:"shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium text-foreground hover:bg-muted/60",title:"Use this folder",children:"Use"})]})}),e.jsxs("div",{className:P("min-h-0 flex-1 overflow-y-auto",o?"min-h-[8.25rem]":"max-h-56"),children:[t.workDir?g?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[9px] text-muted-foreground",children:[e.jsx(ue,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading folders..."]}):h&&h.entries.length>0?e.jsxs(e.Fragment,{children:[h.entries.map(_=>e.jsx(Au,{entry:_,onSelect:()=>H(_.path,h.isAbsolute),onOpen:()=>void V(_.path)},_.path)),h.hasMore&&e.jsxs("button",{type:"button",onClick:()=>void V(h.currentPath,h.entries.length,!0),disabled:N,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[9px] text-muted-foreground hover:bg-muted/60 hover:text-foreground disabled:opacity-50",children:[N?e.jsx(ue,{className:"h-3 w-3 animate-spin"}):e.jsx(ll,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:v??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[9px] text-muted-foreground",children:"This node has no working directory."}),v&&h&&h.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[9px] text-destructive",children:v})]})]})]})]});return e.jsxs("div",{ref:w,className:"relative min-w-0",children:[e.jsxs("button",{ref:T,type:"button","aria-label":"Capability location","aria-expanded":c,title:B,onClick:()=>f(_=>(_||(S(!1),ee()),!_)),className:P("flex min-w-0 items-center gap-1.5 rounded-sm border-0 bg-muted/55 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",o?"h-5 w-24 max-w-28 px-1.5":"h-7 min-w-32 max-w-56 px-2"),children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:P("block truncate font-medium text-foreground",o?"text-[9px] leading-3":"text-[10px] leading-4"),children:F})}),e.jsx(st,{className:P(o?"h-2.5 w-2.5":"h-3 w-3","shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),i&&L?Ma.createPortal(K,L):K]})}function ba({icon:t,label:s,description:n,selected:r,onSelect:o,compact:i=!1}){const d=t==="global"?al:Pt;return e.jsxs("button",{type:"button",onClick:o,className:P(i?"flex h-7 w-full items-center gap-1.5 rounded-md px-2 text-left text-[9px]":"flex h-8 w-full items-center gap-1.5 rounded-md px-2 text-left text-[10px]","transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",r&&"bg-primary/10 text-primary"),children:[e.jsx(d,{className:P("shrink-0 text-muted-foreground",i?"h-2.5 w-2.5":"h-3 w-3",r&&"text-primary")}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col justify-center",children:[e.jsx("span",{className:"block truncate font-medium leading-3",children:s}),n&&e.jsx("span",{className:P("block truncate text-muted-foreground",i?"text-[7px] leading-3":"text-[8px] leading-3"),children:n})]})]})}function Au({entry:t,onOpen:s,onSelect:n}){return e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:n,className:"flex min-w-0 flex-1 items-center gap-1.5 px-2 py-1 text-left text-[9px] hover:bg-muted/55",title:`Use ${t.path}`,children:[e.jsx(Pt,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-foreground",children:t.name})]}),e.jsx("button",{type:"button",onClick:s,className:"flex w-7 shrink-0 items-center justify-center border-l border-border/30 text-muted-foreground hover:bg-muted/65 hover:text-foreground",title:"Open subfolder","aria-label":`Open ${t.name}`,children:e.jsx(He,{className:"h-3 w-3"})})]})}function Mu({ariaLabel:t,value:s,description:n,options:r,selectedValue:o,onSelect:i}){const[d,c]=a.useState(!1),f=a.useRef(null);return a.useEffect(()=>{if(!d)return;const h=y=>{f.current&&y.target instanceof Node&&!f.current.contains(y.target)&&c(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[d]),e.jsxs("div",{ref:f,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":t,"aria-expanded":d,title:n??s,onClick:()=>c(h=>!h),className:"flex h-7 min-w-32 max-w-56 items-center gap-1.5 rounded-sm border-0 bg-muted/55 px-2 text-left shadow-none transition-colors hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{className:"block truncate text-[10px] font-medium leading-4 text-foreground",children:s})}),e.jsx(st,{className:P("h-3 w-3 shrink-0 text-muted-foreground transition-transform",d&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!d,className:P("absolute left-0 top-9 z-50 w-64 overflow-hidden rounded-lg border border-border/70 bg-popover text-popover-foreground shadow-none",!d&&"hidden"),children:e.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:r.length>0?r.map(h=>e.jsxs("button",{type:"button",onClick:()=>{i(h.value),c(!1)},className:P("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-[11px] transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",h.value===o&&"bg-primary/10 text-primary"),children:[h.status&&e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(h.status))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:h.label}),h.description&&e.jsx("span",{className:"block truncate text-[9px] text-muted-foreground",children:h.description})]})]},h.value)):e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No projects"})})})]})}function Pu(t,s){const n=new Map;for(const r of t)n.set(r.id,r);return n.set(s.id,s),Array.from(n.values())}function Vt(t){return t==="online"?"bg-emerald-500":t==="offline"?"bg-muted-foreground/45":"bg-amber-500"}function va(t){return t.split(/[\\/]+/).filter(Boolean).at(-1)??t}function br(t){return t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t)}function vr(t,s){return`${t.replace(/[\\/]+$/,"")}/${s.replace(/^[\\/]+/,"")}`}const Lu="h-6 w-24 rounded-sm px-2 text-[10px] shadow-none",Rs="text-[10px]",jr=["claudecode","codex","copilot"],Ut={claudecode:"Claude Code",codex:"Codex",copilot:"Copilot"};function Iu({open:t,sourceNode:s,targetNodes:n,selectedCapabilities:r,previewResults:o=[],embedded:i=!1,onClose:d,onPreviewTargetsChange:c,onShare:f}){const[h,y]=a.useState(()=>new Set(o.length>0?o.map(x=>Xe(x.nodeId,x.targetAgent)):Ru(s.id,n,r))),[g,l]=a.useState(()=>Object.fromEntries($u(s.id,n,r))),[N,C]=a.useState({}),[v,A]=a.useState(!1),[p,S]=a.useState(()=>new Set),[b,j]=a.useState(()=>new Set),w=r.some(x=>x.kind==="plugin"),T=a.useMemo(()=>pn(r).map(x=>({key:Xe(s.id,x),nodeId:s.id,node:s,label:`Install into ${Ut[x]}`,agentLabel:Ut[x],defaultScope:yr(r),disabled:!1,targetAgent:x})),[r,s]),D=a.useMemo(()=>n.flatMap(x=>{const z={kind:"global"},m=x.status==="offline",G=wr(r);return G.length===0?[{key:Xe(x.id),nodeId:x.id,node:x,label:x.name,defaultScope:z,disabled:m}]:G.map(M=>({key:Xe(x.id,M),nodeId:x.id,node:x,label:`${x.name} / ${Ut[M]}`,agentLabel:Ut[M],defaultScope:z,disabled:m,targetAgent:M}))}),[r,n]),U=a.useMemo(()=>[...T,...D],[T,D]),E=a.useMemo(()=>n.map(x=>({node:x,options:D.filter(z=>z.nodeId===x.id)})).filter(x=>x.options.length>0),[n,D]),F=a.useMemo(()=>new Map(o.filter(x=>x.capabilityId).map(x=>[ja(x.nodeId,x.capabilityId,x.targetAgent),x])),[o]),B=a.useMemo(()=>new Map(o.map(x=>[Xe(x.nodeId,x.targetAgent),x])),[o]),Q=a.useMemo(()=>U.filter(x=>h.has(x.key)),[h,U]),ee=a.useMemo(()=>Q.map(x=>({nodeId:x.nodeId,scope:g[x.key]??x.defaultScope,...x.targetAgent?{targetAgent:x.targetAgent}:{}})),[Q,g]),V=a.useMemo(()=>{const x=[],z=new Map;for(const m of Q){if(!z.has(m.nodeId)){const G=m.nodeId===s.id?s:n.find(M=>M.id===m.nodeId);z.set(m.nodeId,{nodeId:m.nodeId,node:G,name:(G==null?void 0:G.name)??m.nodeId,options:[]}),x.push(m.nodeId)}z.get(m.nodeId).options.push(m)}return x.map(m=>z.get(m))},[Q,s,n]),H=a.useMemo(()=>{const x=Array.from(new Set(r.map(m=>m.agent))),[z]=x;if(z)return x.length===1?Ut[z]:`${x.length} agents`},[r]),se=E.length+1;a.useEffect(()=>{let x=!1;const z={...g};for(const m of U)z[m.key]||(z[m.key]=m.defaultScope,x=!0);x&&l(z)},[U,g]),a.useEffect(()=>{t&&(c==null||c(ee))},[t,c,ee]),a.useEffect(()=>{t&&(S(new Set),j(new Set))},[t,s.id]),a.useEffect(()=>{if(!i||!t)return;const x=z=>{z.key==="Escape"&&d()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[i,d,t]);const ie=x=>{C(Object.fromEntries(Q.map(z=>[z.key,x])))},L=async()=>{A(!0);try{await f(Q.map(x=>({nodeId:x.nodeId,scope:g[x.key]??x.defaultScope,...x.targetAgent?{targetAgent:x.targetAgent}:{},conflictStrategy:N[x.key]??"overwrite"})))}finally{A(!1)}},K=x=>{const z=g[x.key]??x.defaultScope,m=`capability-share-target-${Bu(x.key)}`,G=h.has(x.key);return e.jsxs("div",{"data-target-agent":x.targetAgent,className:"flex min-h-6 items-center gap-2 px-2 py-0.5 transition-colors hover:bg-muted/35 data-[disabled=true]:opacity-55","data-disabled":x.disabled?"true":void 0,children:[e.jsx(Kt,{id:m,disabled:x.disabled,checked:G,onCheckedChange:M=>y(q=>{const k=new Set(q);return M===!0?k.add(x.key):k.delete(x.key),k}),"aria-label":`Select ${x.label} as a share target`,"data-share-target-checkbox":!0,className:"h-3.5 w-3.5 border-border/70 bg-background/80 shadow-none data-[state=checked]:border-primary data-[state=checked]:bg-primary [&_svg]:h-3 [&_svg]:w-3"}),e.jsx("label",{htmlFor:m,className:"min-w-0 flex-1 cursor-pointer truncate text-[10px] font-medium leading-4 text-foreground data-[disabled=true]:cursor-not-allowed","data-disabled":x.disabled?"true":void 0,children:x.agentLabel??x.label}),e.jsx("div",{className:"flex w-28 shrink-0 justify-end",children:G&&!x.disabled&&e.jsx(gr,{node:x.node,projectPaths:hn(x.node),selectedScope:z,onSelect:M=>l(q=>({...q,[x.key]:M})),compact:!0,portal:!0,portalAlign:"end"})})]},x.key)},_=(x,z,m,G)=>{const M=p.has(x.id),q=Q.filter(k=>k.nodeId===x.id).length;return e.jsxs("div",{className:"overflow-hidden rounded-sm border border-border/45 bg-muted/15",children:[e.jsxs("button",{type:"button","aria-expanded":M,onClick:()=>S(k=>wa(k,x.id)),className:"flex w-full items-center gap-2 border-b border-border/35 bg-primary/5 px-2 py-1.5 text-left transition-colors hover:bg-primary/10",children:[e.jsx(He,{className:P("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",M&&"rotate-90")}),e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(x.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-semibold text-foreground",title:x.name,children:x.name}),q>0&&e.jsxs("span",{className:"shrink-0 text-[8px] font-medium text-primary",children:[q," selected"]}),e.jsx("span",{className:"shrink-0 text-[8px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:z?"this node":"remote"}),x.status==="offline"&&e.jsx(Fe,{variant:"outline",className:"rounded-sm px-1 py-0 text-[8px]",children:"offline"}),G>0&&e.jsxs("span",{className:"sr-only",children:[G," agents"]})]}),e.jsx("div",{className:P("grid transition-[grid-template-rows] duration-200 ease-out",M?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsx("div",{className:"divide-y divide-border/25",children:m})})})]},x.id)},W=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-b border-border/55 px-4 py-3 text-left",children:[e.jsxs("h2",{id:"capability-share-title",className:"flex items-center gap-2 text-sm font-semibold leading-none tracking-tight",children:[e.jsx(gs,{className:"h-4 w-4 text-primary"}),"Share ",r.length," ",r.length===1?"capability":"capabilities"]}),e.jsx("p",{id:"capability-share-description",className:"mt-1.5 text-[11px] text-muted-foreground",children:"Copies each capability into the matching agent on the selected targets. Plugins install into their matching agent."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2.5 gap-y-1 border-b border-border/55 bg-muted/15 px-4 py-2 text-[11px]",children:[e.jsx("span",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Source"}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(s.status))}),e.jsx("span",{className:"truncate font-semibold text-foreground",title:s.name,children:s.name}),H&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:["· ",H]})]}),e.jsx(Fn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Targets"}),e.jsxs("span",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:Q.length})," selected · ",se," ",se===1?"node":"nodes"]})]}),e.jsxs("div",{className:"grid gap-4 p-4 lg:grid-cols-[17rem_minmax(0,1fr)]",children:[e.jsx("section",{className:"min-w-0",children:e.jsxs("div",{className:"max-h-[56vh] space-y-2 overflow-y-auto pr-0.5",children:[_(s,!0,w?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"Cross-agent plugin installs are not supported."}):T.length===0?e.jsx("div",{className:"px-2 py-2 text-[10px] text-muted-foreground",children:"No alternate agents available for this selection."}):T.map(K),T.length),E.map(x=>_(x.node,!1,x.options.map(K),x.options.length))]})}),e.jsxs("section",{className:"min-w-0",children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[8px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:"Conflict preview"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[8px] uppercase tracking-[0.12em] text-muted-foreground/70",children:"Set all"}),e.jsx("div",{className:"inline-flex items-center rounded-sm border border-border/55 bg-muted/20 p-px",children:["overwrite","skip","abort"].map(x=>e.jsx("button",{type:"button",onClick:()=>ie(x),className:"h-5 rounded-[3px] px-1.5 text-[9px] capitalize text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground",children:x},x))})]})]}),e.jsx("div",{className:"max-h-[56vh] min-h-32 overflow-y-auto rounded-sm border border-border/55 bg-background/45 p-2",children:Q.length===0?e.jsx("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"Select a target to preview conflicts."}):V.map(x=>{const z=!b.has(x.nodeId);return e.jsxs("div",{className:"mb-1.5 overflow-hidden rounded-sm border border-border/35 bg-muted/10 last:mb-0",children:[e.jsxs("button",{type:"button","aria-expanded":z,onClick:()=>j(m=>wa(m,x.nodeId)),className:"flex w-full items-center gap-1.5 border-b border-border/30 bg-primary/5 px-2 py-1 text-left transition-colors hover:bg-primary/10",children:[e.jsx(He,{className:P("h-3 w-3 shrink-0 text-muted-foreground transition-transform duration-200",z&&"rotate-90")}),x.node&&e.jsx("span",{className:P("h-1.5 w-1.5 shrink-0 rounded-full",Vt(x.node.status))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px] font-semibold text-foreground",children:x.name}),e.jsxs("span",{className:"shrink-0 text-[8px] text-muted-foreground",children:[x.options.length," ",x.options.length===1?"agent":"agents"]})]}),e.jsx("div",{className:P("grid transition-[grid-template-rows] duration-200 ease-out",z?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:e.jsx("div",{className:"space-y-1 p-1.5",children:x.options.map(m=>{const G=N[m.key]??"overwrite";return e.jsxs("div",{className:"rounded-sm bg-background/45 px-2 py-1",children:[e.jsxs("div",{className:"mb-0.5 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[9px] font-medium leading-4 text-foreground",children:m.agentLabel??"Matching agent"}),e.jsxs(ke,{value:G,onValueChange:M=>C(q=>({...q,[m.key]:M})),children:[e.jsx(Se,{className:Lu,children:e.jsx(Be,{})}),e.jsxs(Ce,{className:"shadow-none",children:[e.jsx(xe,{value:"overwrite",className:Rs,children:"Overwrite"}),e.jsx(xe,{value:"skip",className:Rs,children:"Skip"}),e.jsx(xe,{value:"abort",className:Rs,children:"Abort"})]})]})]}),e.jsx("div",{className:"space-y-px",children:r.map(M=>{const q=F.get(ja(m.nodeId,M.id,m.targetAgent))??(r.length===1?B.get(m.key):void 0);return e.jsxs("div",{className:"flex items-center gap-1.5 text-[9px] leading-4",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:M.name}),e.jsx("span",{className:q!=null&&q.conflict?"text-amber-500":q?"text-emerald-500":"text-muted-foreground",children:q?q.conflict?`exists${q.currentVersion?` v${q.currentVersion}`:""}`:"new install":"checking"}),(q==null?void 0:q.sourceVersion)&&e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[e.jsx(Fn,{className:"inline h-2.5 w-2.5"})," v",q.sourceVersion]})]},M.id)})})]},m.key)})})})})]},x.nodeId)})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t border-border/55 px-4 py-3",children:[e.jsx(Z,{variant:"ghost",onClick:d,className:"h-7 rounded-sm px-3 text-[11px]",children:"Cancel"}),e.jsxs(Z,{onClick:L,disabled:v||Q.length===0,className:"h-7 rounded-sm px-3 text-[11px]",children:[v?e.jsx(ue,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(gs,{className:"h-3.5 w-3.5"}),"Share"]})]})]});return i?t?e.jsx("div",{className:"absolute inset-0 z-[80] flex items-center justify-center bg-background/70 p-4 backdrop-blur-[2px]",onMouseDown:x=>{x.target===x.currentTarget&&d()},children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"capability-share-title","aria-describedby":"capability-share-description","data-capability-share-dialog":"true",className:"relative grid w-full max-w-3xl gap-0 overflow-visible rounded-xl border-0 bg-background text-foreground shadow-[0_34px_110px_-54px_rgba(0,0,0,0.55)]",onMouseDown:x=>x.stopPropagation(),children:[W,e.jsxs("button",{type:"button",onClick:d,className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",children:[e.jsx(tt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})}):null:e.jsx(Lt,{open:t,onOpenChange:x=>{x||d()},children:e.jsx(It,{"aria-labelledby":"capability-share-title","aria-describedby":"capability-share-description","data-capability-share-dialog":"true",className:"max-w-3xl gap-0 overflow-visible rounded-xl border-0 p-0",children:W})})}function Xe(t,s){return s?`agent:${t}:${s}`:`node:${t}`}function Bu(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-")}function ja(t,s,n){return`${Xe(t,n)}\0${s}`}function wa(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function Ru(t,s,n){const r=s.find(i=>i.status!=="offline");if(r)return[Xe(r.id,Ou(n))];const o=pn(n)[0];return o?[Xe(t,o)]:[]}function $u(t,s,n){const r=wr(n);return[...s.flatMap(o=>r.length===0?[[Xe(o.id),{kind:"global"}]]:r.map(i=>[Xe(o.id,i),{kind:"global"}])),...pn(n).map(o=>[Xe(t,o),yr(n)])]}function wr(t){return t.length===0||t.some(s=>s.kind==="plugin")?[]:jr}function Ou(t){var s;if(!(t.length===0||t.some(n=>n.kind==="plugin")))return(s=t[0])==null?void 0:s.agent}function pn(t){if(t.length===0||t.some(n=>n.kind==="plugin"))return[];const s=new Set(t.map(n=>n.agent));return jr.filter(n=>!s.has(n))}function yr(t){var s;return((s=t[0])==null?void 0:s.scope)??{kind:"global"}}const ya="h-7 rounded-sm border-0 bg-muted/55 px-2 text-[9px] leading-none shadow-none hover:bg-muted/70 [&>svg]:h-3 [&>svg]:w-3",ht="py-0.5 pl-6 pr-1.5 text-[9px] leading-4 [&_svg]:h-3 [&_svg]:w-3",Nr="h-5 rounded-sm bg-muted/55 px-1.5 text-[9px] font-medium text-foreground shadow-none border-0 hover:bg-muted/75 hover:text-foreground disabled:text-muted-foreground [&_svg]:size-2.5",Fu="h-5 rounded-sm bg-primary px-2 text-[9px] font-medium text-primary-foreground shadow-none border-0 hover:bg-primary/90 hover:text-primary-foreground disabled:bg-primary/45 disabled:text-primary-foreground/80 [&_svg]:size-2.5";function zu(t,s,n,r){return n.map(o=>({sourceNodeId:t,capabilityId:o.id,sourceScope:s,targets:r.map(i=>({nodeId:i.nodeId,scope:i.scope,...i.targetAgent?{targetAgent:i.targetAgent}:{}}))}))}function Uu(t,s,n,r){return n.map(o=>({sourceNodeId:t,capabilityId:o.id,sourceScope:s,targets:r}))}function Vu({loading:t,onRefresh:s}){return e.jsxs(Z,{variant:"ghost",onClick:s,disabled:t,"aria-busy":t,className:P(Nr,"min-w-[4.5rem]"),children:[e.jsx(Ha,{className:P("h-2.5 w-2.5",t&&"animate-spin")}),t?"Refreshing":"Refresh"]})}function Hu({selectedCount:t,loading:s,onClearSelection:n,onRefresh:r,onShare:o}){return e.jsxs("div",{className:"flex items-center justify-between gap-2 bg-card/15 px-0.5 pt-1.5 text-[9px] text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs(Z,{type:"button",variant:"ghost",onClick:n,disabled:t===0,className:Nr,children:[e.jsx(tt,{className:"h-2.5 w-2.5"}),"Selected: ",t," / Clear"]})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Vu,{loading:s,onRefresh:r}),e.jsxs(Z,{type:"button",variant:"ghost",onClick:o,disabled:t===0,className:Fu,children:[e.jsx(gs,{className:"h-2.5 w-2.5"}),"Share"]})]})]})}function qu({onBeginResize:t,onFold:s}){const n=r=>{r.key!=="Enter"&&r.key!==" "||(r.preventDefault(),s())};return e.jsx("div",{role:"separator","aria-label":"Fold capability detail panel","aria-orientation":"vertical",title:"Fold details",tabIndex:0,onClick:s,onKeyDown:n,onPointerDown:t,className:"hidden w-1 shrink-0 cursor-col-resize items-center justify-center bg-primary/10 transition-colors hover:bg-primary/22 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 lg:flex",children:e.jsx("span",{className:"h-8 w-px rounded-full bg-primary/45"})})}function Ku({visible:t}){return t?e.jsx("div",{className:"absolute inset-2.5 z-10 flex items-center justify-center rounded-sm border border-border/60 bg-background/85 shadow-sm backdrop-blur-sm",children:e.jsxs("div",{className:"flex w-full max-w-80 flex-col items-center gap-3 px-5 text-center",children:[e.jsxs("div",{className:"relative flex h-10 w-10 items-center justify-center rounded-full border border-primary/25 bg-primary/8",children:[e.jsx("span",{className:"absolute inset-0 rounded-full border border-primary/20 animate-ping"}),e.jsx(ue,{className:"relative h-4 w-4 animate-spin text-primary"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] font-medium text-foreground",children:"Loading capabilities"}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Reading agent skills, plugins, and MCP servers for this selection."})]}),e.jsxs("div",{className:"grid w-full gap-1.5","aria-hidden":"true",children:[e.jsx("span",{className:"h-1.5 rounded-full bg-muted animate-pulse"}),e.jsx("span",{className:"mx-auto h-1.5 w-3/4 rounded-full bg-muted/70 animate-pulse"})]})]})}):null}function Wu({open:t,node:s,scope:n,clusterNodes:r,onOpenChange:o,onSelectionChange:i}){const[d,c]=a.useState([]),[f,h]=a.useState([]),[y,g]=a.useState(!1),[l,N]=a.useState(""),[C,v]=a.useState("all"),[A,p]=a.useState("all"),[S,b]=a.useState(new Set),[j,w]=a.useState(null),[T,D]=a.useState(null),[U,E]=a.useState(!1),[F,B]=a.useState(null),[Q,ee]=a.useState(!1),[V,H]=a.useState([]),[se,ie]=a.useState(fr),[L,K]=a.useState(null),_=a.useMemo(()=>xu(d,{search:l,agent:C,kind:A}),[C,d,A,l]),W=a.useMemo(()=>d.filter(O=>S.has(O.id)),[d,S]),x=a.useMemo(()=>r.filter(O=>O.id!==s.id),[r,s.id]),z=n.kind==="project"?n.projectPath:"global",m=async()=>{g(!0);try{const O=await oi(s.id,{scope:n});c(O.items),h((O.errors??[]).map(te=>`${te.agent}: ${te.message}`))}catch(O){h([O instanceof Error?O.message:"Failed to load capabilities"])}finally{g(!1)}};a.useEffect(()=>{t&&(b(new Set),w(null),D(null),E(!1),H([]),c([]),h([]),m())},[t,s.id,n.kind,z]),a.useEffect(()=>{if(!L)return;const O=le=>{ie(gu(L.startWidth,L.startClientX,le.clientX,window.innerWidth))},te=()=>K(null);return window.addEventListener("pointermove",O),window.addEventListener("pointerup",te),()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",te)}},[L]);const G=O=>{O.preventDefault(),K({startClientX:O.clientX,startWidth:se})},M=()=>{K(null),E(!1),w(null),D(null)},q=()=>{b(new Set),H([])},k=async O=>{w(O.id),E(!0),D(null);const te=await ii(s.id,O.id,n);D(te.detail)},X=a.useCallback(async O=>{if(W.length===0||O.length===0){H([]);return}H([]);try{const te=zu(s.id,n,W,O),le=await Promise.all(te.map(R=>ri(R)));H(le.flatMap((R,ae)=>R.results.map(ve=>{var Ee;return{...ve,capabilityId:(Ee=te[ae])==null?void 0:Ee.capabilityId}})))}catch{H([])}},[s.id,n,W]),re=()=>{H([]),ee(!0)},ce=async O=>{const te=Uu(s.id,n,W,O);te.length!==0&&(await Promise.all(te.map(le=>di(le))),de.success(`${te.length} capability share request${te.length===1?"":"s"} completed`),ee(!1))},J=async()=>{if(!(!T||F)){B(T.id);try{const O=await li(s.id,T.id,n);O.status==="deleted"?(de.success(`Deleted ${T.name}`),c(te=>te.filter(le=>le.id!==T.id)),b(te=>{const le=new Set(te);return le.delete(T.id),le}),w(null),D(null),E(!1),await m()):(de.info(O.message??"Capability was not found"),w(null),D(null),E(!1),await m())}catch(O){de.error(O instanceof Error?O.message:"Failed to delete capability")}finally{B(null)}}};return e.jsx(e.Fragment,{children:e.jsx(Lt,{open:t,onOpenChange:o,children:e.jsxs(It,{className:"dashboard-panel animate-panel-settle flex h-[min(62vh,33rem)] w-[min(94vw,72rem)] max-w-[min(94vw,72rem)] flex-col gap-0 overflow-hidden rounded-xl p-0",children:[e.jsxs(sn,{className:"border-b border-border/55 bg-card/28 px-4 py-2.5 text-left",children:[e.jsx(Yt,{className:"sr-only",children:"Capabilities"}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-x-4 gap-y-1 pr-10",children:[e.jsx(Eu,{node:s,scope:n,clusterNodes:r,onSelectionChange:i}),e.jsxs(an,{"data-capability-selection-help":"true",className:"ml-auto max-w-[min(32rem,38vw)] space-y-0.5 pt-0.5 text-right text-[9px] leading-[11px] text-muted-foreground",children:[e.jsx("span",{className:"block truncate whitespace-nowrap",children:"Sharing copies into selected agents on target nodes."}),n.kind==="project"&&e.jsx("span",{"data-capability-selection-path":"true",className:"block truncate font-mono text-[7px] leading-[10px] text-muted-foreground/80",title:n.projectPath,children:n.projectPath})]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:flex-row",children:[e.jsxs("main",{className:"relative flex min-w-0 flex-1 flex-col gap-2 bg-gradient-to-b from-primary/4 via-background/20 to-background/40 p-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-44 flex-1",children:[e.jsx(Ta,{className:"pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),e.jsx(et,{value:l,onChange:O=>N(O.target.value),placeholder:"Search capabilities",className:"h-7 rounded-sm border-0 bg-muted/55 pl-6 text-[10px] shadow-none"})]}),e.jsxs(ke,{value:C,onValueChange:O=>v(O),children:[e.jsx(Se,{className:P("w-28",ya),children:e.jsx(Be,{})}),e.jsxs(Ce,{className:"shadow-none",children:[e.jsx(xe,{value:"all",className:ht,children:"Agent: All"}),e.jsx(xe,{value:"claudecode",className:ht,children:"Claude Code"}),e.jsx(xe,{value:"codex",className:ht,children:"Codex"}),e.jsx(xe,{value:"copilot",className:ht,children:"Copilot"})]})]}),e.jsxs(ke,{value:A,onValueChange:O=>p(O),children:[e.jsx(Se,{className:P("w-24",ya),children:e.jsx(Be,{})}),e.jsxs(Ce,{className:"shadow-none",children:[e.jsx(xe,{value:"all",className:ht,children:"Kind: All"}),e.jsx(xe,{value:"skill",className:ht,children:"Skill"}),e.jsx(xe,{value:"plugin",className:ht,children:"Plugin"}),e.jsx(xe,{value:"mcp",className:ht,children:"MCP"})]})]})]}),f.length>0&&e.jsx("div",{className:"rounded-sm bg-amber-500/10 px-2 py-1 text-[10px] text-amber-600",children:f.join(" · ")}),e.jsx(hu,{items:_,selectedIds:S,activeId:j,onToggleSelected:(O,te)=>b(le=>{const R=new Set(le);return te?R.add(O):R.delete(O),R}),onOpenDetail:k}),e.jsx(Hu,{selectedCount:S.size,loading:y,onClearSelection:q,onRefresh:m,onShare:re}),e.jsx(Ku,{visible:y&&d.length===0})]}),U&&e.jsxs(e.Fragment,{children:[e.jsx(qu,{onBeginResize:G,onFold:M}),e.jsx(bu,{detail:T,deleting:F===(T==null?void 0:T.id),desktopWidth:se,onDelete:T?J:void 0,pending:!T})]})]}),Q&&e.jsx(Iu,{open:Q,sourceNode:s,targetNodes:x,selectedCapabilities:W,previewResults:V,embedded:!0,onClose:()=>ee(!1),onPreviewTargetsChange:X,onShare:ce})]})})})}function Gu(t){const[s,n]=a.useState(null),r=a.useMemo(()=>s?(t==null?void 0:t.nodes.find(f=>f.id===s.nodeId))??((t==null?void 0:t.self.id)===s.nodeId?t.self:null)??null:null,[t,s]),o=a.useCallback(f=>{n({nodeId:f,scope:{kind:"global"}})},[]),i=a.useCallback((f,h)=>{n({nodeId:f,scope:{kind:"project",projectPath:h}})},[]),d=a.useCallback(f=>{n(f)},[]);return{capabilitiesDialog:s&&r&&t?e.jsx(Wu,{open:!0,node:r,scope:s.scope,clusterNodes:t.nodes,onOpenChange:f=>{f||n(null)},onSelectionChange:d}):null,openNodeCapabilities:o,openProjectCapabilities:i}}function Yu(){var jn,wn,yn,Nn,kn,Sn;const{id:t}=ci(),s=ui(),n=mi(),r=xi(),{cluster:o,systemInfo:i,events:d,sseConnected:c,subscribe:f,refresh:h,loading:y,error:g}=hi(),l=a.useMemo(()=>pi(s.state),[s.state]),[N,C]=a.useState(null),[v,A]=a.useState("active"),[p,S]=a.useState("all"),[b,j]=a.useState("all"),[w,T]=a.useState("all"),D=(r==null?void 0:r.headerSearchQuery)??"",U=a.useDeferredValue(D),{desktopTasksOpen:E,mobileTasksPanelOpen:F,mobileTasksPanelRef:B,operationsOpen:Q,operationsPanelRef:ee,panelResize:V,setMobileTasksPanelOpen:H,setOperationsOpen:se,toggleTasksPanel:ie}=Fc(),[L,K]=a.useState(()=>!!(l!=null&&l.draftNewTask)),[_,W]=a.useState(()=>(l==null?void 0:l.createMode)??"chat"),[x,z]=a.useState(()=>(l==null?void 0:l.createDefaults)??null),[m,G]=a.useState(()=>l!=null&&l.draftNewTask?{route:l.returnRoute??"/",taskId:l.returnTaskId??null}:null),[M,q]=a.useState(!1),[k,X]=a.useState("transcript"),[re,ce]=a.useState("all"),[J,O]=a.useState(!1),[te,le]=a.useState(null),[R,ae]=a.useState([]),[ve,Ee]=a.useState([]),[nt,at]=a.useState(!1),[Ue,je]=a.useState(!1),[it,We]=a.useState(null),[Me,ne]=a.useState(new Set),[we,Pe]=a.useState(!1),[De,lt]=a.useState(!1),[ye,qe]=a.useState(null),$e=a.useRef(null),jt=a.useRef(new Map),Te=((jn=o==null?void 0:o.self)==null?void 0:jn.role)==="leader",$=(wn=o==null?void 0:o.self)==null?void 0:wn.id,{quickChats:Le}=fi();eu({cluster:o,subscribe:f});const{nodeSettingsDialog:Ae,openNodeSettings:dt}=du(Te),{capabilitiesDialog:pt,openNodeCapabilities:wt,openProjectCapabilities:Ie}=Gu(o),{devBoxDialog:ze,devBoxNodeIds:yt,devBoxStartNodeId:ft,devBoxStartNodeIds:Ge,devBoxStartingNodeIds:mt,openDevBox:Nt,startDevBox:ct}=lu({cluster:o,refresh:h}),{completedGroups:Ne=[],fetchTasks:_e,loadCompletedTasksPage:ut,removeTasksFromList:kt,setTasks:fe,tasks:be,tasksError:rt,tasksLoading:St}=Qc({isLeader:Te,selfId:$,sseConnected:c,preservedTask:te,subscribe:f}),Ye=a.useMemo(()=>[...be].sort((u,I)=>I.updatedAt-u.updatedAt),[be]),Qe=a.useMemo(()=>{var u;return((u=[...be].sort((I,Y)=>Y.createdAt-I.createdAt||Y.updatedAt-I.updatedAt)[0])==null?void 0:u.id)??null},[be]),kr=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[]){const Y=Hl(Ye,I.id);Y>0&&u.set(I.id,Y)}return u},[o==null?void 0:o.nodes,Ye]),Ze=a.useMemo(()=>Ye.filter(u=>!gi(u,o==null?void 0:o.nodes,o==null?void 0:o.self)||!bi(u,v)||p!=="all"&&u.agent!==p||!vi(u,w)||b==="unassigned"&&u.assignedTo||b!=="all"&&b!=="unassigned"&&ji(u.assignedTo,o==null?void 0:o.nodes,u.assignedNodeName)!==b?!1:U.trim()?wi(u,U):!0),[Ye,o==null?void 0:o.nodes,o==null?void 0:o.self,v,p,w,b,U]);a.useEffect(()=>{ne(u=>{const I=Ql(u,Ze.map(Y=>Y.id));return I.size===u.size?u:I})},[Ze]),a.useEffect(()=>{Te||ne(new Set)},[Te]);const Sr=a.useMemo(()=>["all",...Array.from(new Set(Ye.map(u=>u.agent))).sort()],[Ye]),Cr=a.useMemo(()=>{const I=Array.from(new Set(Ye.map(Y=>Y.assignedTo).filter(Y=>!!Y))).map(Y=>{const ge=Ye.find(me=>me.assignedTo===Y);return(o==null?void 0:o.nodes.find(me=>me.id===Y))??{id:Y,name:Os(Y,o==null?void 0:o.nodes,ge==null?void 0:ge.assignedNodeName)}}).sort((Y,ge)=>Y.name.localeCompare(ge.name));return[{value:"all",label:"All nodes"},{value:"unassigned",label:"Unassigned"},...I.map(Y=>({value:Y.name.toLowerCase(),label:Y.name}))]},[Ye,o==null?void 0:o.nodes]),fn=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])u.set(I.id,I.name);for(const I of Ye)I.assignedTo&&I.assignedNodeName&&!u.has(I.assignedTo)&&u.set(I.assignedTo,I.assignedNodeName);return u},[o==null?void 0:o.nodes,Ye]),Tr=a.useMemo(()=>{var I;const u=new Map;for(const Y of(o==null?void 0:o.nodes)??[])Y.workDir&&u.set(Y.id,Y.workDir);return(I=o==null?void 0:o.self)!=null&&I.workDir&&u.set(o.self.id,o.self.workDir),u},[o]),_r=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])u.set(I.id,I.status);return o!=null&&o.self&&u.set(o.self.id,o.self.status),u},[o]),Er=a.useMemo(()=>new Map(Ne.map(u=>[Xs(u),u])),[Ne]),gn=a.useMemo(()=>{const u=new Map;for(const I of(o==null?void 0:o.nodes)??[])I.status!=="offline"&&u.set(I.id,I);return o!=null&&o.self&&o.self.status!=="offline"&&u.set(o.self.id,o.self),Array.from(u.values())},[o]),Dr=((yn=o==null?void 0:o.self)==null?void 0:yn.id)??((Nn=gn[0])==null?void 0:Nn.id)??null,$t=a.useMemo(()=>d.filter(yi),[d]),ks=a.useMemo(()=>["all",...Array.from(new Set($t.map(u=>u.type))).sort()],[$t]),Ar=a.useMemo(()=>re==="all"?$t:$t.filter(u=>u.type===re),[$t,re]),Mr=Ze.length>0&&Ze.every(u=>Me.has(u.id)),Pr=Ze.some(u=>Me.has(u.id)),Lr=Zl(Ze,Me);a.useEffect(()=>{l!=null&&l.draftNewTask&&(K(!0),W(l.createMode??"chat"),z(l.createDefaults??null),G({route:l.returnRoute??"/",taskId:l.returnTaskId??null}))},[l]),a.useEffect(()=>{re!=="all"&&!ks.includes(re)&&ce("all")},[re,ks]),a.useEffect(()=>{Un(t,L)&&!N&&Qe&&C(Qe)},[t,L,N,Qe]),a.useEffect(()=>{Un(t,L)&&(N&&be.some(u=>u.id===N)||C(Qe))},[t,L,N,Qe,be]);const pe=Kl({routeTaskId:t,creatingTask:L,internalSelectedTaskId:N,sortedTaskIds:Qe?[Qe]:[]}),Ct=a.useMemo(()=>be.find(u=>u.id===pe)??null,[be,pe]);a.useEffect(()=>{$e.current=pe??null},[pe]);const xt=a.useCallback(()=>{le(null),ae([]),Ee([]),We(null),je(!1)},[]),Ot=a.useCallback((u,I,Y=!0)=>{jt.current.set(u,{logs:xr(I),loaded:Y})},[]),Ve=a.useCallback(async()=>{const u=pe;if(u)try{const I=await Ni(u);if($e.current!==u)return;le(I),fe(Y=>Ga(Y,I)),We(null)}catch(I){if($e.current!==u)return;xt(),We(I instanceof Error?I.message:"Failed to load task")}finally{$e.current===u&&at(!1)}},[pe,xt,fe]),Qt=a.useCallback(async()=>{const u=pe;if(u)try{const I=await zs(u);if($e.current!==u)return;ae(Y=>{const ge=za(Y,I.logs);return Ot(u,ge),ge}),Ee(Y=>Vs(Y,I.logs))}catch{}finally{$e.current===u&&je(!1)}},[pe,Ot]);a.useEffect(()=>{if(!pe){xt(),at(!1);return}X("transcript"),le(Ct);const u=Zc(pe,jt.current);ae(u.logs),Ee([]),We(null),at(!0),je(u.transcriptLoading),Ve(),Qt()},[pe,xt,Qt,Ve]),a.useEffect(()=>{if(!Wl({activeTaskId:pe,routeTaskId:t,creatingTask:L,tasksLoading:St,loadedTaskIds:be.map(I=>I.id)}))return;const u=Qe;C(u),xt(),a.startTransition(()=>{n(u?`/tasks/${u}`:"/",{state:null})})},[pe,xt,L,Qe,n,t,be,St]),a.useEffect(()=>{Ct&&le(u=>!u||u.id!==Ct.id?u:{...u,...Ct})},[Ct]),a.useEffect(()=>{if(pe)return f("task",u=>{const I=u.data.taskId;if(!(typeof I!="string"||I!==pe)){if(u.type==="task.output"){const Y=u.data.event;if(Y){ae(me=>{const zt=zi(me,Y);return Ot(pe,zt),zt}),je(!1);const ge=On(Y);ge&&Ee(me=>Ui(me,ge))}}u.type==="task.updated"&&Ve(),u.type==="task.status"&&(Ve(),Qt())}})},[f,pe,Ve,Qt]);const oe=te??Ct,Ir=oe!=null&&oe.assignedTo?(o==null?void 0:o.nodes.find(u=>u.id===oe.assignedTo))??null:null,Ft=r==null?void 0:r.setHeaderTaskContext;a.useEffect(()=>{if(!Ft)return;if(!oe){Ft(null);return}const u=oe.effectiveProjectPath??oe.project??"default workspace";return Ft({taskId:oe.id,taskTitle:oe.title,nodeName:Os(oe.assignedTo,o==null?void 0:o.nodes,oe.assignedNodeName),projectLabel:Ia(u),projectPath:u}),()=>Ft(null)},[oe,o==null?void 0:o.nodes,Ft]);const Ss=ve.length>0,Br=oe?ki.has(oe.agent):!1,Zt=(oe==null?void 0:oe.status)==="running",Rr=oe?ps.has(oe.status):!1,$r=oe?ps.has(oe.status)||Si.has(oe.status):!1,Or=!!(oe&&Te&&oe.status==="failed"),Cs=a.useMemo(()=>Cc(oe,o,Ss,!!Zt),[oe,o,Ss,Zt]),Ts=a.useMemo(()=>Vi([...R,...ve.map(u=>Ps(u.content,u.timestamp))]),[R,ve]),Xt=a.useMemo(()=>{if(!oe||oe.conversationKind==="nativeSession")return null;const u=Hi(oe);if(u.length>0)return Ps(u,new Date(oe.createdAt).toISOString());if(Ts.length>0)return null;const I=qi(oe.description||oe.title);return I.length>0?Ps(I,new Date(oe.createdAt).toISOString()):null},[oe,Ts]),_s=a.useMemo(()=>Xt?On(Xt):null,[Xt]),Fr=a.useMemo(()=>_s?Ki(R,_s):!1,[R,_s]),Es=a.useCallback((u="chat",I)=>{const Y={route:t?`/tasks/${t}`:"/",taskId:pe};G(Y),W(u),z(I??null),K(!0),a.startTransition(()=>{n("/",{state:{draftNewTask:!0,returnRoute:Y.route,returnTaskId:Y.taskId,createMode:u,createDefaults:I}})})},[t,pe,n]),zr=a.useCallback(()=>{const u=(m==null?void 0:m.taskId)??Qe;K(!1),G(null),z(null),C(u),a.startTransition(()=>{n((m==null?void 0:m.route)??"/",{state:null})})},[m,Qe,n]),bn=a.useCallback(u=>{K(!1),G(null),z(null),C(u),a.startTransition(()=>{n(`/tasks/${u}`,{state:null})})},[n]),Ur=a.useCallback(u=>{$e.current=u.id,K(!1),G(null),z(null),fe(I=>Gl(I,u)),le(u),ae([]),Ee([]),We(null),at(!1),je(u.conversationKind==="nativeSession"),X("transcript"),C(u.id),su({task:u,getActiveTaskId:()=>$e.current,setLogs:ae,setPendingMessages:Ee,setTranscriptLoading:je}),_e(),a.startTransition(()=>{n(`/tasks/${u.id}`,{state:null})})},[_e,n]),{cancelQueuedMessage:Vr,queueFollowUpMessage:Jt}=uu({activeTaskId:pe,fetchActiveTask:Ve,isRunning:Zt,setPendingMessages:Ee,setTask:le,setTasks:fe}),Hr=a.useCallback(u=>{Jt(u)},[Jt]),qr=a.useCallback(async()=>{const u=pe;if(!(!u||(oe==null?void 0:oe.conversationKind)!=="nativeSession")){je(!0);try{const I=await zs(u);if($e.current!==u)return;ae(I.logs),Ot(u,I.logs),Ee(Y=>Vs(Y,I.logs))}catch(I){de.error(I instanceof Error?I.message:"Failed to reload transcript")}finally{$e.current===u&&je(!1)}}},[oe==null?void 0:oe.conversationKind,pe,Ot]),Kr=a.useCallback(u=>Jt(u),[Jt]),Wr=a.useCallback(async()=>{if(oe)try{await Ci(oe.id),Ve(),_e()}catch(u){de.error(u instanceof Error?u.message:"Failed to cancel task")}},[oe,Ve,_e]),{handleShareTask:Gr,handleStopShareTask:Yr}=Bc(oe,Ve,_e),Qr=a.useCallback(async()=>{if(oe)try{await Ti(oe.id),Ve(),_e()}catch(u){de.error(u instanceof Error?u.message:"Failed to retry task")}},[oe,Ve,_e]),es=a.useCallback((u,I=!1)=>{const Y=Xl(Ze,u);return C(Y),(I||!Y)&&xt(),a.startTransition(()=>{n(Y?`/tasks/${Y}`:"/",{state:null})}),Y},[xt,Ze,n]),Zr=a.useCallback((u,I)=>{ne(Y=>{const ge=new Set(Y);return I?ge.add(u):ge.delete(u),ge})},[]),Xr=a.useCallback(u=>{if(!u){ne(new Set);return}ne(new Set(Ze.map(I=>I.id)))},[Ze]),Jr=a.useCallback(async()=>{const u=Array.from(Me);if(u.length!==0)try{const{results:I}=await _i(u),Y=I.filter(me=>!me.ok),ge=I.filter(me=>me.ok).map(me=>me.id);pe&&ge.includes(pe)&&es(ge),Y.length>0?de.error(`Failed to archive ${Y.length} task(s): ${Y.map(me=>me.error??me.id).join(", ")}`):de.success(`Archived ${ge.length} task(s)`),ne(new Set(Y.map(me=>me.id))),_e()}catch(I){de.error(I instanceof Error?I.message:"Failed to archive tasks")}},[pe,_e,es,Me]),eo=a.useCallback(async()=>{const u=Array.from(Me);if(u.length!==0)try{const{results:I}=await Ei(u),Y=I.filter(me=>!me.ok),ge=I.filter(me=>me.ok).map(me=>me.id);ge.length>0&&kt(ge),pe&&ge.includes(pe)&&es(ge,!0),Y.length>0?de.error(`Failed to delete ${Y.length} task(s): ${Y.map(me=>me.error??me.id).join(", ")}`):de.success(`Deleted ${ge.length} task(s)`),ne(new Set(Y.map(me=>me.id))),_e()}catch(I){de.error(I instanceof Error?I.message:"Failed to delete tasks")}},[pe,_e,es,kt,Me]),to=a.useCallback(async()=>{Pe(!0);try{await Di(),h()}catch(u){de.error(u instanceof Error?u.message:"Failed to promote node")}finally{Pe(!1)}},[h]),so=a.useCallback(async()=>{lt(!0);try{await Ai(),de.success("This node left the remote cluster and is leading itself again."),_e(),Ve(),h()}catch(u){de.error(u instanceof Error?u.message:"Failed to leave cluster")}finally{lt(!1)}},[Ve,_e,h]),no=a.useCallback(async u=>{var zt;const I=!dn(u),Y=u.id===((zt=o==null?void 0:o.self)==null?void 0:zt.id),ge=Y?(i==null?void 0:i.transportType)??u.transportType:u.transportType,me=Y&&!I&&Rt(ge);qe(u.id);try{me?await Mi("direct"):await Pi(u.id,I),de.success(I?`Enabled remote access on ${u.name}`:`Disabled remote access on ${u.name}`),h()}catch(Cn){de.error(Cn instanceof Error?Cn.message:"Failed to update remote access")}finally{qe(null)}},[(kn=o==null?void 0:o.self)==null?void 0:kn.id,h,i==null?void 0:i.transportType]),ao=a.useCallback(u=>{ut&&ut(u).catch(I=>{de.error(I instanceof Error?I.message:"Failed to load completed tasks")})},[ut]),vn={toolbarTasks:Ze,activeTaskId:pe,tasksLoading:St,tasksError:rt,isLeader:Te,scope:v,agentFilter:p,nodeFilter:b,taskKindFilter:w,agentOptions:Sr,nodeOptions:Cr,nodeNameById:fn,nodeWorkDirById:Tr,nodeStatusById:_r,leaderNodeId:((Sn=o==null?void 0:o.leader)==null?void 0:Sn.id)??null,searchQuery:D,completedGroupByKey:Er,devBoxNodeIds:yt,devBoxStartNodeIds:Ge,devBoxStartingNodeIds:mt,selectedTaskIds:Me,allVisibleTasksSelected:Mr,someVisibleTasksSelected:Pr,canBatchArchive:Lr,onScopeChange:A,onAgentFilterChange:S,onNodeFilterChange:j,onTaskKindFilterChange:T,onToggleTaskSelected:Zr,onToggleAllVisibleTasks:Xr,onBatchArchive:Jr,onBatchDelete:eo,onCreateTask:Es,onOpenNodeSettings:Te?dt:void 0,onOpenNodeCapabilities:Te?wt:void 0,onOpenProjectCapabilities:Te?Ie:void 0,onOpenDevBox:Te?Nt:void 0,onStartDevBox:Te?ct:void 0,onLoadCompletedTasks:ao,onSelectTask:bn},ro={cluster:o,systemInfo:i,nodeNameById:fn,nodeBlockingTaskCounts:kr,eventTypeFilter:re,onEventTypeFilterChange:ce,eventTypeOptions:ks,filteredEvents:Ar,sseConnected:c,clusterLoading:y,clusterError:g,promotePending:we,onPromote:to,onAddNode:()=>q(!0),leavePending:De,onLeaveCluster:so,onToggleNodeDevTunnel:no,devTunnelNodeId:ye,devBoxStartNodeId:ft,devBoxStartingNodeIds:mt,onOpenNodeSettings:Te?dt:void 0,onOpenNodeCapabilities:Te?wt:void 0,onOpenDevBox:Te?Nt:void 0,onStartDevBox:Te?ct:void 0};return e.jsxs(e.Fragment,{children:[e.jsx(ic,{desktopTasksOpen:E,mobileTasksPanelOpen:F,mobileTasksPanelRef:B,operationsOpen:Q,operationsPanelRef:ee,panelResize:V,taskSidebar:e.jsx(la,{...vn}),operationsSidecar:e.jsx(kc,{...ro}),terminalPanel:r!=null&&r.terminalOpen?e.jsx(pc,{nodes:gn,defaultNodeId:Dr,onClose:()=>r==null?void 0:r.setTerminalOpen(!1)}):void 0,conversationPanel:e.jsx(Jd,{onToggleTasks:ie,desktopTasksOpen:E,mobileTasksPanelOpen:F,operationsOpen:Q,onToggleOperations:()=>se(u=>!u),cluster:o,sseConnected:c,activeTab:k,setActiveTab:X,creatingTask:L,createMode:_,createDefaults:x,activeTask:oe,assignedNode:Ir,taskLoading:nt,transcriptLoading:Ue,taskError:it,displayEvents:Ts,initialPromptAlreadyInLogs:Fr,initialPrompt:Xt,supportsFollowUp:Br,taskUnavailable:Cs.taskUnavailable,chatDisabled:Cs.chatDisabled,chatDisabledReason:Cs.chatDisabledReason,questionBypassEnabled:J,isRunning:!!Zt,isStarting:Rr,hasPendingFollowUp:Ss,canCancel:!!$r,canRetry:!!Or,onRetry:Qr,onCancel:Wr,onReloadNativeTranscript:qr,onShareTask:Gr,onStopShareTask:Yr,onStartCreateTask:Es,onCancelCreateTask:zr,onCreateTask:Ur,onSendMessage:Hr,onCancelQueuedMessage:Vr,onQuestionBypassChange:O,onSubmitQuestionResponse:Kr,quickChats:Le}),mobileTaskSidebar:e.jsx(la,{...vn,onCreateTask:(u,I)=>{H(!1),Es(u,I)},onSelectTask:u=>{H(!1),bn(u)}}),onCloseOperations:()=>se(!1),onCloseTaskList:()=>H(!1),onToggleOperations:()=>se(u=>!u),onToggleTasks:ie}),e.jsx(sc,{open:M,onOpenChange:q,onAdded:h}),Ae,ze,pt]})}const em=Object.freeze(Object.defineProperty({__proto__:null,DashboardPage:Yu},Symbol.toStringTag,{value:"Module"}));export{Ua as A,em as D,fs as G};
|