meshy-node 0.10.4 → 0.10.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # meshy-node
2
2
 
3
- Version: 0.10.4
3
+ Version: 0.10.5
4
4
 
5
5
  This package contains the built Meshy standalone node runtime only.
6
6
  It intentionally excludes repository source files and TypeScript sources.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-DdNDe4Vy.js","assets/index-DtTy7Ax9.js","assets/index-DVIvShRC.css","assets/MarkdownPreviewFrame-DwALMk1j.js","assets/DashboardShared-BGkSTKYP.js","assets/file-Bp3lcXJZ.js","assets/PreviewTab-CLE4ZFIp.js","assets/DiffTab-CGRnl8EV.js"])))=>i.map(i=>d[i]);
2
- import{c as me,r as o,a as vs,f as Aa,m as Da,j as e,X as it,Q as jn,B as J,L as de,S as _a,b as Di,d as B,e as _i,g as Mi,h as Pi,I as ot,P as Ii,C as as,i as Ri,k as Ma,F as Li,l as Ft,n as Xe,o as Te,D as os,p as Bi,q as Oi,t as ce,s as De,u as _e,v as $e,w as Me,x as Pa,y as Qe,T as Fi,z as zi,A as nr,E as Ui,G as Ct,H as Tt,J as zt,K as Ia,M as Ra,N as Ts,O as Bn,R as $i,U as kt,V as qi,W as Nn,Y as Vi,Z as On,_ as La,$ as Hi,a0 as Ve,a1 as Ki,a2 as ut,a3 as Yt,a4 as Jt,a5 as Zt,a6 as Xt,a7 as es,a8 as ts,a9 as ss,aa as ns,ab as Fn,ac as Gi,ad as Es,ae as Ba,af as Wi,ag as rr,ah as ar,ai as Us,aj as Qi,ak as Yi,al as Ji,am as Zi,an as Xi,ao as As,ap as el,aq as tl,ar as Ds,as as sl,at as Oa,au as nl,av as rl,aw as al,ax as Fa,ay as zn,az as za,aA as ol,aB as ws,aC as il,aD as or,aE as ll,aF as Un,aG as cl,aH as dl,aI as ul,aJ as ml,aK as Ua,aL as is,aM as hl,aN as kn,aO as $a,aP as fl,aQ as xl,aR as pl,aS as gl,aT as ir,aU as bl,aV as vl,aW as $s,aX as wl,aY as lr,aZ as yl,a_ as jl,a$ as Nl,b0 as cr,b1 as kl,b2 as Sl,b3 as Sn,b4 as Cl,b5 as Tl,b6 as qa,b7 as dr,b8 as Va,b9 as El,ba as Al,bb as Dl,bc as _l,bd as Ml,be as Pl,bf as Il,bg as Rl,bh as Ll,bi as Bl,bj as Ol,bk as Fl,bl as zl,bm as Ul,bn as $l,bo as ql,bp as Vl,bq as Hl,br as Kl,bs as Gl,bt as Wl,bu as Ql,bv as Yl,bw as Jl,bx as Zl,by as Xl,bz as ec,bA as tc,bB as sc,bC as nc,bD as rc,bE as ac,bF as oc}from"./index-DtTy7Ax9.js";import{r as ur,e as ic,b as Ha,g as Ka,I as Ga,A as $n,a as Wa,c as Qa,T as Ya,d as lc,i as Ja,f as cc,p as Za,h as dc,t as uc,j as mr,k as hr,l as mc,m as hc,n as fc,C as fr,o as qs,q as Cn,D as It,s as Ze,M as Tn,L as xc,u as Xa,v as En,w as pc,x as gc,y as bc,z as Vs,B as vc,E as wc,F as yc}from"./DashboardShared-BGkSTKYP.js";import{E as jc,M as Nc}from"./MarkdownPreviewFrame-DwALMk1j.js";import{P as _s,D as hs,g as kc,a as Sc,b as Cc}from"./PreviewTab-CLE4ZFIp.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FilesTab-BlJn83X5.js","assets/index-B21dpk5D.js","assets/index-Bd5ODKX4.css","assets/MarkdownPreviewFrame-CrujIEck.js","assets/DashboardShared-vm6Ua9h6.js","assets/file-CBXlsD1A.js","assets/PreviewTab-C7vB52yS.js","assets/DiffTab-Bz1OAlIg.js"])))=>i.map(i=>d[i]);
2
+ import{c as me,r as o,a as vs,f as Aa,m as Da,j as e,X as it,Q as jn,B as J,L as de,S as _a,b as Di,d as B,e as _i,g as Mi,h as Pi,I as ot,P as Ii,C as as,i as Ri,k as Ma,F as Li,l as Ft,n as Xe,o as Te,D as os,p as Bi,q as Oi,t as ce,s as De,u as _e,v as $e,w as Me,x as Pa,y as Qe,T as Fi,z as zi,A as nr,E as Ui,G as Ct,H as Tt,J as zt,K as Ia,M as Ra,N as Ts,O as Bn,R as $i,U as kt,V as qi,W as Nn,Y as Vi,Z as On,_ as La,$ as Hi,a0 as Ve,a1 as Ki,a2 as ut,a3 as Yt,a4 as Jt,a5 as Zt,a6 as Xt,a7 as es,a8 as ts,a9 as ss,aa as ns,ab as Fn,ac as Gi,ad as Es,ae as Ba,af as Wi,ag as rr,ah as ar,ai as Us,aj as Qi,ak as Yi,al as Ji,am as Zi,an as Xi,ao as As,ap as el,aq as tl,ar as Ds,as as sl,at as Oa,au as nl,av as rl,aw as al,ax as Fa,ay as zn,az as za,aA as ol,aB as ws,aC as il,aD as or,aE as ll,aF as Un,aG as cl,aH as dl,aI as ul,aJ as ml,aK as Ua,aL as is,aM as hl,aN as kn,aO as $a,aP as fl,aQ as xl,aR as pl,aS as gl,aT as ir,aU as bl,aV as vl,aW as $s,aX as wl,aY as lr,aZ as yl,a_ as jl,a$ as Nl,b0 as cr,b1 as kl,b2 as Sl,b3 as Sn,b4 as Cl,b5 as Tl,b6 as qa,b7 as dr,b8 as Va,b9 as El,ba as Al,bb as Dl,bc as _l,bd as Ml,be as Pl,bf as Il,bg as Rl,bh as Ll,bi as Bl,bj as Ol,bk as Fl,bl as zl,bm as Ul,bn as $l,bo as ql,bp as Vl,bq as Hl,br as Kl,bs as Gl,bt as Wl,bu as Ql,bv as Yl,bw as Jl,bx as Zl,by as Xl,bz as ec,bA as tc,bB as sc,bC as nc,bD as rc,bE as ac,bF as oc}from"./index-B21dpk5D.js";import{r as ur,e as ic,b as Ha,g as Ka,I as Ga,A as $n,a as Wa,c as Qa,T as Ya,d as lc,i as Ja,f as cc,p as Za,h as dc,t as uc,j as mr,k as hr,l as mc,m as hc,n as fc,C as fr,o as qs,q as Cn,D as It,s as Ze,M as Tn,L as xc,u as Xa,v as En,w as pc,x as gc,y as bc,z as Vs,B as vc,E as wc,F as yc}from"./DashboardShared-vm6Ua9h6.js";import{E as jc,M as Nc}from"./MarkdownPreviewFrame-CrujIEck.js";import{P as _s,D as hs,g as kc,a as Sc,b as Cc}from"./PreviewTab-C7vB52yS.js";/**
3
3
  * @license lucide-react v1.7.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
@@ -156,7 +156,7 @@ import{c as me,r as o,a as vs,f as Aa,m as Da,j as e,X as it,Q as jn,B as J,L as
156
156
  * See the LICENSE file in the root directory of this source tree.
157
157
  */const gd=[["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"}]],bd=me("zoom-out",gd),vd=new Set(["assigned","running"]);function wd(t,s){return t.reduce((n,r)=>r.assignedTo===s&&vd.has(r.status)?n+1:n,0)}function $t(t){return t?.toLowerCase()==="devtunnel"}function yd(t){return t?$t(t)?"DevTunnel":t.charAt(0).toUpperCase()+t.slice(1):"Direct"}function Vn(t,s){return $t(s??t.transportType)||!!t.devtunnelEndpoint}function ao(t,s){return!$t(s??t.transportType)}function oo(t,s){const n=s??t.transportType;return $t(n)?"DevTunnel":t.devtunnelEndpoint?"Direct + DevTunnel":yd(n)}function gr(t,s){return!t&&!s}function jd({routeTaskId:t,creatingTask:s,internalSelectedTaskId:n,sortedTaskIds:r}){return t||(s?null:r[0]??n??null)}function Nd({activeTaskId:t,routeTaskId:s,creatingTask:n,tasksLoading:r,loadedTaskIds:a}){return!t||s||n||r?!1:!a.includes(t)}function kd(t,s){return[s,...t.filter(n=>n.id!==s.id)]}function io(t,s){const n=t.findIndex(r=>r.id===s.id);return n===-1?[...t,s]:t.map((r,a)=>a===n?s:r)}const Sd=new Set(["completed","failed","cancelled","archived"]);function Cd(t,s){const n=new Set(s);return new Set(Array.from(t).filter(r=>n.has(r)))}function Td(t,s){const n=new Set(s);if(n.size===0)return!1;const r=t.filter(a=>n.has(a.id));return r.length===n.size&&r.every(a=>Sd.has(a.status))}function Ed(t,s){const n=new Set(s);return t.find(r=>!n.has(r.id))?.id??null}function lo(){const[t,s]=o.useState([]),[n,r]=o.useState(null),a=o.useRef(null),i=o.useCallback(()=>{a.current?.click()},[]),l=o.useCallback(async p=>{const u=Array.from(p.target.files??[]);if(u.length!==0)try{const h=await ur(u);s(x=>[...x,...h]),r(null)}catch(h){r(h instanceof Error?h.message:"Failed to attach image")}finally{p.target.value=""}},[]),c=o.useCallback(async p=>{const u=ic(p.clipboardData);if(u.length!==0){p.preventDefault();try{const h=await ur(u);s(x=>[...x,...h]),r(null)}catch(h){r(h instanceof Error?h.message:"Failed to attach image")}}},[]),d=o.useCallback(p=>{s(u=>u.filter((h,x)=>x!==p))},[]),m=o.useCallback(()=>{s([]),r(null)},[]);return{images:t,error:n,fileInputRef:a,pickImages:i,handleFileChange:l,handlePaste:c,removeImage:d,clearImages:m}}function Ad(t){const s=t.map(a=>({...a,displayValue:Dd(a)})),n=s.findIndex(a=>a.label.toLowerCase()==="working dir"),r=n>=0?n:0;return{primary:s[r],secondary:s.filter((a,i)=>i!==r)}}function Dd(t){return t.label.toLowerCase()==="agent"?Wa(t.value):t.value}function br(t){switch(t.toLowerCase()){case"branch":return js;case"node":return _a;default:return Ms}}function _d({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 Md({contentLength:t,disabled:s=!1}){return t>0&&!s}function Pd({onSend:t,disabled:s,disabledReason:n="Chat is waiting on the agent.",placeholder:r="Send a follow-up message...",contextItems:a=[],agent:i,model:l,running:c=!1,onStop:d,quickChats:m=[]}){const[p,u]=o.useState(""),[h,x]=o.useState(0),[k,j]=o.useState(0),A=o.useRef(null),{images:f,error:E,fileInputRef:y,pickImages:v,handleFileChange:b,handlePaste:C,removeImage:T,clearImages:P}=lo(),S=o.useCallback(()=>{A.current&&(A.current.style.height="auto")},[]),I=o.useCallback(()=>{A.current&&(A.current.style.height="auto",A.current.style.height=`${Math.min(A.current.scrollHeight,220)}px`)},[]);o.useEffect(()=>{x(0)},[p,m]);const _=o.useCallback(O=>{u(O.prompt);const g=()=>{A.current?.focus(),I()};typeof requestAnimationFrame=="function"?requestAnimationFrame(g):g()},[I]),D=o.useCallback(()=>{const O=vs(p,m,h);if(O){_(O);return}const g=Ha(p,f);Md({contentLength:g.length,disabled:s})&&(j($=>$+1),t(g),u(""),P(),S())},[p,f,s,t,P,S,m,h,_]),R=o.useCallback(O=>{const g=Aa(p,m);if(g.length>0&&(O.key==="ArrowDown"||O.key==="ArrowUp")){O.preventDefault(),x($=>Da($,g.length,O.key==="ArrowDown"?1:-1));return}if(O.key==="Enter"&&!O.shiftKey){O.preventDefault();const $=vs(p,m,h);$?_($):D()}},[_,D,m,h,p]),F=p.trim().length>0||f.length>0,Y=_d({disabled:s,running:c,canStop:c&&!!d,hasContent:F}),ee=Ad(a),Z=ee.primary?br(ee.primary.label):Ms,te=i?Ka(i,l):null,V=c?F?"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:y,type:"file",accept:"image/*",multiple:!0,onChange:b,className:"hidden"}),ee.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(Z,{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:ee.primary.value,children:ee.primary.displayValue})]})}),f.length>0&&e.jsx("div",{className:"px-2 pt-2.5 sm:px-5 sm:pt-4",children:e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map((O,g)=>e.jsxs("div",{className:"relative",children:[e.jsx(Ga,{image:O,alt:O.filename??`attachment ${g+1}`,thumbnailClassName:"h-24 w-24 border border-border/70",imageClassName:"h-full w-full"}),e.jsx("button",{type:"button",onClick:()=>T(g),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 ${O.filename??`image ${g+1}`}`,children:e.jsx(it,{className:"h-3 w-3"})})]},`${O.filename??"image"}-${g}`))})}),e.jsx("div",{className:"px-2 pb-0 pt-1 sm:px-5 sm:pt-1.5",children:e.jsx("textarea",{ref:A,"data-chat-input-textarea":"true",value:p,onChange:O=>u(O.target.value),onKeyDown:R,onPaste:C,onInput:I,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(jn,{query:p,quickChats:m,selectedIndex:h,onActiveIndexChange:x,onSelect:_}),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:[ee.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:ee.secondary.map(O=>{const g=br(O.label),$=O.label.toLowerCase()==="agent";return e.jsxs("span",{title:`${O.label}: ${O.value}`,className:"inline-flex min-w-0 max-w-[12rem] items-center gap-1 truncate",children:[$?e.jsx($n,{agent:O.value,className:"h-2.5 w-2.5 shrink-0 text-primary/50"}):e.jsx(g,{"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 ${O.mono?"font-mono":""}`,children:O.displayValue})]},`${O.label}:${O.value}`)})}):e.jsx("div",{className:"min-w-0 flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[te&&e.jsxs("span",{"data-chat-input-model-display":"true","aria-label":`Model: ${te}`,title:`Model: ${te}`,className:"inline-flex h-7 max-w-[9rem] shrink-0 items-center gap-1.5 truncate rounded-sm px-2 text-[10px] text-muted-foreground",children:[e.jsx(to,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),te]}),e.jsxs(J,{type:"button",variant:"ghost",onClick:v,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(An,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Images"})]}),e.jsx("span",{title:V,children:e.jsx(J,{onClick:Y.primaryAction==="stop"?d:D,disabled:Y.primaryDisabled,size:"icon","data-chat-send-button":"true","aria-label":Y.primaryAction==="stop"?"Stop running task":c?"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:Y.primaryAction==="stop"?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ro,{className:`h-3.5 w-3.5 ${k>0?"animate-chat-send-flight":""}`},k)})})]})]}),E&&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:E})]})})})}var Id=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Rd=Id.reduce((t,s)=>{const n=Di(`Primitive.${s}`),r=o.forwardRef((a,i)=>{const{asChild:l,...c}=a,d=l?n:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(d,{...c,ref:i})});return r.displayName=`Primitive.${s}`,{...t,[s]:r}},{}),Ld="Label",co=o.forwardRef((t,s)=>e.jsx(Rd.label,{...t,ref:s,onMouseDown:n=>{n.target.closest("button, input, select, textarea")||(t.onMouseDown?.(n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));co.displayName=Ld;var uo=co;const Bd=_i("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ke=o.forwardRef(({className:t,...s},n)=>e.jsx(uo,{ref:n,className:B(Bd(),t),...s}));Ke.displayName=uo.displayName;function vr({agent:t,query:s,onSelect:n}){const r=Qa(t,s);return r?e.jsx("div",{"data-codex-goal-command":"true",className:"mx-2 mb-0.5 rounded-sm bg-background/70 p-0.5 shadow-none sm:mx-5",children:e.jsx("div",{role:"listbox","aria-label":"Codex commands",children:e.jsxs("button",{type:"button",role:"option","aria-selected":"true",onClick:n,className:"flex h-8 w-full min-w-0 items-center gap-2 rounded-sm px-2 text-left transition-colors hover:bg-muted/50 hover:text-foreground",children:[e.jsx("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-sm bg-primary/10 text-primary",children:e.jsx(Ya,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx("span",{className:"shrink-0 text-[11px] font-medium text-foreground",children:r.label}),e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:r.description})]})})}):null}function Od(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function Fd(t){return t.trim()||"."}function zd(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 $d(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 zd(1e3),s=await Ri(s.id)}throw new Error("Timed out waiting for branch creation")}function wr({value:t,onChange:s,project:n,assignTo:r,nodes:a,assignableNodes:i,layout:l="default",chipClassName:c,chipActiveClassName:d,chipInactiveClassName:m,labelClassName:p,triggerClassName:u}){const[h,x]=o.useState(!1),[k,j]=o.useState(null),[A,f]=o.useState(""),[E,y]=o.useState(!1),[v,b]=o.useState(!1),[C,T]=o.useState(!1),[P,S]=o.useState(null),[I,_]=o.useState(""),[D,R]=o.useState(""),[F,Q]=o.useState(""),[Y,ee]=o.useState(!1),Z=o.useRef(null),te=o.useRef(0),V=o.useMemo(()=>Od(r,a,i),[r,a,i]),O=V?.id,g=o.useMemo(()=>Fd(n),[n]),$=o.useMemo(()=>O?`${O}
158
158
  ${g}`:"",[O,g]),N=o.useCallback(async(ae=0,G=!1)=>{const M=te.current+1,ne=$;if(te.current=M,!O){j(null),f("");return}S(null),G||f(""),G?b(!0):y(!0);try{const H=await Mi(O,{path:g,limit:20,offset:ae,allowAbsolute:!0});if(M!==te.current)return;f(ne),j(re=>G&&re?{...H,branches:[...re.branches,...H.branches]}:H)}catch(H){if(M!==te.current)return;S(H instanceof Error?H.message:"Failed to load branch info"),G||(j(null),f(""))}finally{M===te.current&&(y(!1),b(!1))}},[O,$,g]);o.useEffect(()=>{if(!O){te.current+=1,j(null),f(""),S(null);return}N()},[O,g,N]),o.useEffect(()=>{const ae=t.trim(),G=A===$?k:null,M=G?.available&&G.currentBranch?G.currentBranch:"";ae!==M&&s(M)},[k,$,A,s,t]),o.useEffect(()=>{if(!h)return;const ae=M=>{Z.current&&(Z.current.contains(M.target)||x(!1))},G=M=>{M.key==="Escape"&&x(!1)};return document.addEventListener("mousedown",ae),document.addEventListener("keydown",G),()=>{document.removeEventListener("mousedown",ae),document.removeEventListener("keydown",G)}},[h]),o.useEffect(()=>{h&&(R(""),Q(""),ee(!1))},[h,O,g]);const q=o.useCallback(async()=>{if(!O)return;const ae=I.trim(),G=Y?F.trim():D.trim();if(!(!ae||!G)){T(!0),S(null);try{const M=await Pi(O,{path:g,branchName:ae,startPoint:G,limit:20,offset:0,allowAbsolute:!0}),ne=await $d(M);f($),j(ne),s(ne.currentBranch??ne.createdBranch),_(""),R(""),Q(""),ee(!1),x(!1)}catch(M){S(M instanceof Error?M.message:"Failed to create branch")}finally{T(!1)}}},[O,$,g,Y,F,I,s,D]),z=A===$?k:null,W=o.useCallback(()=>{z?.hasMore&&N(z.branches.length,!0)},[z,N]),L=t.trim()||z?.currentBranch||(z&&!z.available?"No git repo":"Branch"),oe=Y?F.trim():D.trim(),ie=!!(z?.available&&I.trim()&&oe&&!C),he=l==="composer"?e.jsxs(J,{type:"button",variant:"ghost",onClick:()=>x(ae=>!ae),title:L,"aria-label":`Branch: ${L}`,className:B(c,u,"min-w-0 max-w-full",t.trim()?d:m),children:[E&&!z?e.jsx(de,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(js,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:B("min-w-0 truncate",p),children:L})]}):e.jsxs(J,{type:"button",variant:"outline",onClick:()=>x(ae=>!ae),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:L,children:[e.jsx("span",{className:B("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:L}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:V?V.name:"Manual"})]});return e.jsxs("div",{className:B("relative inline-block",l==="composer"?"min-w-0 shrink-0":"w-full"),ref:Z,children:[l==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[10px] font-medium",children:"Branch"}),he]}):he,h&&e.jsxs("div",{className:B("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",l==="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(js,{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:z?.repoRoot?`${z.currentBranch??L} · ${z.repoRoot}`:z?.currentBranch??L,children:z?.currentBranch??L}),E?e.jsx(de,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}):null]}),V?E&&!z?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(de,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):z&&!z.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(ot,{value:I,onChange:ae=>_(ae.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(J,{type:"button",size:"sm",onClick:()=>{q()},disabled:!ie,title:ie?"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:C?e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ii,{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"}),!Y&&e.jsxs("button",{type:"button",onClick:()=>ee(!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(Ut,{className:"h-2.5 w-2.5"}),"Manual"]})]}),Y?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ot,{value:F,onChange:ae=>Q(ae.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:()=>{ee(!1),Q("")},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(it,{className:"h-3.5 w-3.5"})})]}):z?.branches.length?e.jsxs("div",{className:"max-h-44 overflow-y-auto rounded-sm border border-border/40 bg-background/40",children:[z.branches.map(ae=>{const G=D===ae.ref,M=ae.branch==="main"||ae.branch==="master";return e.jsxs("button",{type:"button",onClick:()=>R(ae.ref),className:B("flex w-full items-center gap-2 border-b border-border/20 px-2.5 py-1.5 text-left text-[11px] last:border-b-0 hover:bg-background/60",G&&"bg-background/70"),title:ae.ref,children:[e.jsx("span",{className:B("shrink-0 text-[10px]",M?"text-amber-500 dark:text-amber-400":"text-muted-foreground/60"),"aria-hidden":!0,children:M?"★":"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-foreground",children:ae.ref}),G?e.jsx(as,{className:"h-3 w-3 shrink-0 text-primary"}):null]},ae.ref)}),z.hasMore&&e.jsxs("button",{type:"button",onClick:W,disabled:v,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:[v?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Ns,{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."}),P&&e.jsx("div",{className:"border-t border-destructive/20 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive",children:P})]})]})}const qd=20,Vd=3,Dn="meshy-working-dir-recents-by-node";function Hd(t){return t.startsWith("/")||t.startsWith("\\\\")||/^[A-Za-z]:[\\/]/.test(t)}function Kd(t){const s=t.trim();return s||"."}function _n(t){const s=[],n=new Set;for(const r of t){const a=r.trim();if(!(!a||n.has(a))&&(n.add(a),s.push(a),s.length===Vd))break}return s}function Gd(t,s){const n=s.trim();return _n(n?[n,...t]:t)}function mo(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 a=r.filter(l=>typeof l=="string"),i=_n(a);i.length>0&&(s[n]=i)}return s}function Wd(t,s,n){if(!s)return t;const r=t[s]??[],a=Gd(r,n);if(a.length===0){if(!(s in t))return t;const{[s]:i,...l}=t;return l}return{...t,[s]:a}}function Qd(t,s){return s?t[s]?.[0]??"":""}function ho(t){if(!t||typeof window>"u")return"";try{const s=window.localStorage.getItem(Dn);return s?Qd(mo(JSON.parse(s)),t):""}catch{return""}}function Yd(t,s,n){return t!=="auto"?s.find(r=>r.id===t)??null:n.length===1?n[0]??null:null}function Jd(t,s){const n=s.trim();return n?Hd(n)||!t?n:`${t.replace(/[/\\]+$/,"")}/${n}`:""}function Zd(t,s){return t?t.isAbsolute?t.currentPath:t.currentPath==="."||t.currentPath===""?t.rootPath||s?.workDir||"Node root":t.currentPath:s?.workDir??"Node root"}function Ss({value:t,onChange:s,assignTo:n,nodes:r,assignableNodes:a,layout:i="default",chipClassName:l,chipActiveClassName:c,chipInactiveClassName:d,labelClassName:m,triggerClassName:p,popoverPlacement:u="bottom",popoverAlign:h="start"}){const[x,k]=o.useState(!1),[j,A]=o.useState(null),[f,E]=o.useState(!1),[y,v]=o.useState(!1),[b,C]=o.useState(null),[T,P]=o.useState(""),[S,I]=o.useState(!1),[_,D]=o.useState({}),R=o.useRef(null),F=o.useMemo(()=>Yd(n,r,a),[n,r,a]),Q=F?.id,Y=o.useMemo(()=>Q?_[Q]??[]:[],[_,Q]),ee=o.useMemo(()=>t.trim()?Jd(F?.workDir,t):"Use node default",[t,F?.workDir]);o.useEffect(()=>{if(!(typeof window>"u"))try{const L=window.localStorage.getItem(Dn);if(!L)return;const oe=JSON.parse(L);D(mo(oe))}catch{}},[]);const Z=o.useCallback(L=>{Q&&D(oe=>{const ie=Wd(oe,Q,L);if(ie===oe)return oe;if(typeof window<"u")try{window.localStorage.setItem(Dn,JSON.stringify(ie))}catch{}return ie})},[Q]),te=o.useCallback((L,oe=!0)=>{const ie=L.trim();s(ie),oe&&ie&&Z(ie),k(!1)},[s,Z]),V=o.useCallback(async(L,oe=0,ie=!1)=>{if(Q){C(null),ie?v(!0):E(!0);try{const he=await Ma(Q,{path:L,limit:qd,offset:oe,directoriesOnly:!0,allowAbsolute:!0});A(ae=>ie&&ae?{...he,entries:[...ae.entries,...he.entries]}:he)}catch(he){C(he instanceof Error?he.message:"Failed to browse directories"),ie||A(null)}finally{E(!1),v(!1)}}},[Q]),O=o.useRef(t);O.current=t;const g=o.useRef(V);g.current=V,o.useEffect(()=>{if(!x)return;const L=O.current;P(L),I(!1),A(null),C(null),Q&&g.current(Kd(L))},[x,Q]),o.useEffect(()=>{if(!x)return;const L=ie=>{R.current&&(R.current.contains(ie.target)||k(!1))},oe=ie=>{ie.key==="Escape"&&k(!1)};return document.addEventListener("mousedown",L),document.addEventListener("keydown",oe),()=>{document.removeEventListener("mousedown",L),document.removeEventListener("keydown",oe)}},[x]);const $=o.useCallback(L=>{V(L)},[V]),N=o.useCallback(()=>{j&&V(j.currentPath,j.entries.length,!0)},[j,V]),q=i==="composer"?e.jsxs(J,{type:"button",variant:"ghost",onClick:()=>k(L=>!L),title:ee,"aria-label":`Working directory: ${ee}`,className:B(l,p,"min-w-0 max-w-full",t.trim()?c:d),children:[e.jsx(Li,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:B("min-w-0 truncate",m),children:ee})]}):e.jsxs(J,{type:"button",variant:"outline",onClick:()=>k(L=>!L),className:"h-7 w-full justify-between rounded-sm border-border/70 bg-background/70 px-2.5 text-[11px] shadow-none",title:ee,children:[e.jsx("span",{className:B("truncate",t.trim()?"font-mono text-foreground":"text-muted-foreground"),children:ee}),e.jsx("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground",children:F?F.name:"Manual"})]}),z=Zd(j,F),W=!!j?.parentPath;return e.jsxs("div",{className:B("relative inline-block",i==="composer"?"min-w-0 max-w-[60%] shrink":"w-full"),"data-workdir-popover-placement":u,"data-workdir-popover-align":h,ref:R,children:[i==="default"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[10px] font-medium",children:"Working directory"}),q]}):q,x&&e.jsxs("div",{className:B("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",u==="top"?"bottom-full mb-2":"top-full mt-2",i==="composer"?h==="end"?"right-0":"left-0":h==="end"?"right-0 w-auto min-w-[240px]":"left-0 right-0 w-auto min-w-[240px]"),children:[Y.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(Ns,{className:"h-2.5 w-2.5"}),"Recent"]}),e.jsx("div",{className:"flex flex-col",children:Y.map(L=>e.jsx("button",{type:"button",onClick:()=>te(L),className:"truncate rounded-sm px-1.5 py-0.5 text-left font-mono text-[11px] text-foreground hover:bg-background/60",title:L,children:L},L))})]}),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:()=>j?.parentPath&&$(j.parentPath),disabled:!W||f,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(eo,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground",title:z,children:z}),j&&e.jsx("button",{type:"button",onClick:()=>te(j.isAbsolute?j.currentPath:j.currentPath==="."?"":j.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:[F?f?e.jsxs("div",{className:"flex items-center justify-center px-3 py-4 text-[11px] text-muted-foreground",children:[e.jsx(de,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Loading..."]}):j&&j.entries.length>0?e.jsxs(e.Fragment,{children:[j.entries.map(L=>e.jsxs("div",{className:"group flex items-stretch border-b border-border/30 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>te(L.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 ${L.path}`,children:[e.jsx(Ft,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate text-[11px] text-foreground",children:L.name})]}),e.jsx("button",{type:"button",onClick:()=>$(L.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 ${L.name}`,children:e.jsx(Xe,{className:"h-3.5 w-3.5"})})]},L.path)),j.hasMore&&e.jsxs("button",{type:"button",onClick:N,disabled:y,className:"flex w-full items-center justify-center gap-1 border-t border-border/40 py-1 text-[10px] text-muted-foreground hover:bg-background/60 hover:text-foreground disabled:opacity-50",children:[y?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(Ns,{className:"h-3 w-3"}),"Load more"]})]}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:b??"No subfolders."}):e.jsx("div",{className:"px-3 py-4 text-center text-[11px] text-muted-foreground",children:"Select a node to browse."}),b&&j&&j.entries.length>0&&e.jsx("div",{className:"border-t border-border/60 px-3 py-1.5 text-[11px] text-destructive",children:b})]}),e.jsx("div",{className:"flex items-center gap-1 border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:S?e.jsxs(e.Fragment,{children:[e.jsx(ot,{value:T,onChange:L=>P(L.target.value),onKeyDown:L=>{L.key==="Enter"&&T.trim()?(L.preventDefault(),te(T)):L.key==="Escape"&&(L.preventDefault(),I(!1),P(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:()=>te(T),disabled:!T.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(as,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{I(!1),P(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(it,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>{P(t),I(!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(Ut,{className:"h-3 w-3"})]})})]})]})}function fo(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 Hn({isCurrent:t}){return t?e.jsx(Wc,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500 dark:text-emerald-400","aria-label":"current node"}):e.jsx(Vc,{className:"h-3.5 w-3.5 shrink-0 text-sky-500 dark:text-sky-400","aria-label":"remote follower node"})}function Mn(t,s){return t.map(n=>{const r=!!s&&n.id===s;return e.jsx(Te,{value:n.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Hn,{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 Xd(t){const s=t.sessionId.trim(),n=t.cwd.trim();return!s||!n||!t.assignTo?null:{title:t.title.trim()||t.defaultTitle?.trim()||void 0,agent:t.agent,sessionId:s,cwd:n,assignTo:t.assignTo,priority:t.priority,mode:t.mode??os}}function eu(){return Fi.map(t=>e.jsx(Te,{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 tu(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 yr(t){if(!t.updatedAt)return 0;const s=Date.parse(t.updatedAt);return Number.isNaN(s)?0:s}function su(t,s){return yr(s)-yr(t)||t.sessionId.localeCompare(s.sessionId)}function nu(t){const s=t.trim().replace(/[\\/]+$/,"");return s?s.split(/[\\/]+/).filter(Boolean).at(-1)??s:"Unknown project"}function ru(t){const s=new Map;for(const n of[...t].sort(su)){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:nu(n),cwd:n,sessions:r}))}function au(t,s){const n=new Set(t);return n.has(s)?n.delete(s):n.add(s),n}function ou({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:a,onCancel:i,className:l,footerClassName:c,submitLabel:d="Load session",cancelLabel:m="Cancel",autoFocus:p=!1}){const u=o.useMemo(()=>fo(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),h=o.useMemo(()=>n&&u.some(M=>M.id===n)?n:u[0]?.id??"",[u,n]),[x,k]=o.useState(""),[j,A]=o.useState("codex"),[f,E]=o.useState(""),[y,v]=o.useState(""),[b,C]=o.useState(""),[T,P]=o.useState(h),[S,I]=o.useState(os),[_,D]=o.useState(!1),[R,F]=o.useState([]),[Q,Y]=o.useState(!1),[ee,Z]=o.useState(null),te=o.useMemo(()=>R.find(M=>M.sessionId===f)??null,[R,f]);o.useEffect(()=>{T&&u.some(M=>M.id===T)||P(h)},[T,u,h]),o.useEffect(()=>{E(""),v(""),C("")},[j,T]),o.useEffect(()=>{let M=!1;return T?(Y(!0),Z(null),Bi(T,{agent:j,limit:50}).then(ne=>{M||F(ne.sessions)}).catch(ne=>{M||(F([]),Z(ne instanceof Error?ne.message:"Failed to load native sessions"))}).finally(()=>{M||Y(!1)}),()=>{M=!0}):(F([]),Z(null),Y(!1),()=>{M=!0})},[j,T]),o.useEffect(()=>{te&&(v(te.sessionId),C(te.cwd))},[te]);const V=o.useCallback(async M=>{M.preventDefault();const ne=Xd({title:x,defaultTitle:te?.summary,agent:j,sessionId:y,cwd:b,assignTo:T,priority:"normal",mode:S});if(ne){D(!0);try{const H=await Oi(ne);a(H)}catch(H){ce.error(H instanceof Error?H.message:"Failed to load native session")}finally{D(!1)}}},[x,te,j,y,b,T,S,a]),O=!!(y.trim()&&b.trim()&&T),[g,$]=o.useState(!1),[N,q]=o.useState(""),[z,W]=o.useState(()=>new Set),L=u.find(M=>M.id===T)??null,oe=!!(n&&L?.id===n),ie=o.useMemo(()=>{const M=N.trim().toLowerCase();return M?R.filter(ne=>ne.summary.toLowerCase().includes(M)||ne.sessionId.toLowerCase().includes(M)||ne.cwd.toLowerCase().includes(M)):R},[R,N]),he=o.useMemo(()=>ru(ie),[ie]),ae=o.useCallback(M=>{W(ne=>au(ne,M))},[]),G="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:V,className:B("space-y-4",l),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(De,{value:T,onValueChange:P,children:[e.jsx(_e,{className:B(G),"aria-label":"Node",children:L?e.jsxs(e.Fragment,{children:[e.jsx(Hn,{isCurrent:oe}),e.jsx("span",{className:"max-w-[10rem] truncate",children:L.name})]}):e.jsx($e,{placeholder:"Node"})}),e.jsx(Me,{children:Mn(u,n)})]}),e.jsxs(De,{value:j,onValueChange:M=>A(M),children:[e.jsxs(_e,{className:B(G),"aria-label":"Agent",children:[e.jsx($n,{agent:j}),e.jsx("span",{children:j})]}),e.jsx(Me,{children:lc()})]}),e.jsxs("div",{className:"relative ml-auto min-w-0 flex-1 sm:max-w-56",children:[e.jsx(Pa,{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(ot,{value:N,onChange:M=>q(M.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(Ke,{className:"text-[10px] font-medium uppercase tracking-[0.2em] text-muted-foreground",children:Q?"Loading...":`${ie.length} session${ie.length===1?"":"s"}`})}),e.jsxs("div",{className:"relative h-88 overflow-hidden rounded-sm",children:[Q&&e.jsx("div",{className:"absolute inset-x-0 top-0 z-10 h-0.5 overflow-hidden bg-primary/10",children:e.jsx("div",{className:"h-full w-1/3 animate-indeterminate-bar bg-primary/70"})}),e.jsxs("div",{className:"h-full space-y-1.5 overflow-y-auto pr-1",children:[!T&&e.jsx("div",{className:"rounded-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."}),T&&!Q&&ie.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:R.length===0?"No recent sessions on this node. Use Manual session ID under More options.":"No sessions match your filter."}),he.map(M=>e.jsxs("section",{className:"space-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>ae(M.cwd),"aria-expanded":!z.has(M.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(Qe,{className:B("h-3.5 w-3.5 shrink-0 transition-transform",z.has(M.cwd)&&"-rotate-90")}),e.jsx(Ms,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:M.folderName}),e.jsxs("span",{className:"shrink-0 uppercase tracking-[0.16em]",children:[M.sessions.length," session",M.sessions.length===1?"":"s"]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-right font-mono",children:M.cwd})]}),!z.has(M.cwd)&&M.sessions.map(ne=>{const H=ne.sessionId===f;return e.jsxs("button",{type:"button",onClick:()=>E(ne.sessionId),className:B("flex w-full flex-col gap-1 rounded-sm border px-2.5 py-2 text-left transition-colors duration-200",H?"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:B("h-2 w-2 shrink-0 rounded-full",H?"bg-primary":"bg-border")}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-foreground",children:ne.summary}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:tu(ne.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:ne.sessionId.slice(0,12)}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-border"}),e.jsx("span",{className:"truncate font-mono",children:ne.cwd})]})]},ne.sessionId)})]},M.cwd))]})]}),ee&&e.jsx("p",{className:"px-1 pt-2 text-[11px] text-destructive",children:ee})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>$(M=>!M),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":g,children:[e.jsx("span",{className:"shrink-0",children:g?"Less options":"More options"}),e.jsx(Qe,{className:B("h-3.5 w-3.5 shrink-0 transition-transform",g&&"rotate-180")})]}),g&&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(Ke,{htmlFor:"native-session-id",className:"text-[10px] font-medium text-muted-foreground",children:"Session ID"}),e.jsx(ot,{id:"native-session-id",type:"text",value:y,onChange:M=>{E(""),v(M.target.value)},placeholder:"ses_..., thread_..., or UUID",autoFocus:p,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(Ke,{htmlFor:"native-session-title",className:"text-[10px] font-medium text-muted-foreground",children:"Task title"}),e.jsx(ot,{id:"native-session-title",type:"text",value:x,onChange:M=>k(M.target.value),placeholder:"Optional",className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none"})]})]}),e.jsx(Ss,{value:b,onChange:M=>{E(""),C(M)},assignTo:T,nodes:t,assignableNodes:u}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Ke,{className:"text-[10px] font-medium text-muted-foreground",children:"Mode"}),e.jsxs(De,{value:S,onValueChange:M=>I(M),children:[e.jsx(_e,{className:"h-7 rounded-sm border-border/70 bg-background/70 text-[11px] shadow-none",children:e.jsx($e,{placeholder:"Select mode"})}),e.jsx(Me,{children:eu()})]})]})]})]}),e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",c),children:[i&&e.jsx(J,{type:"button",variant:"ghost",onClick:i,className:"rounded-sm",children:m}),e.jsx(J,{type:"submit",disabled:!O||_,className:"rounded-sm px-5",children:_?e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-4 w-4 animate-spin"})," Loading..."]}):d})]})]})}const Hs="__agent-default__";function xo({agent:t,value:s,onChange:n,triggerClassName:r,contentClassName:a="max-h-80",chip:i=!1}){const l=Ka(t,s);return o.useEffect(()=>{s&&!Ja(t,s)&&n("")},[t,s,n]),e.jsxs(De,{value:s||Hs,onValueChange:c=>n(c===Hs?"":c),children:[e.jsx(_e,{"aria-label":`Model: ${l}`,title:`Model: ${l}`,className:r,children:i?e.jsxs(e.Fragment,{children:[e.jsx(to,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:l})]}):e.jsx($e,{placeholder:"Agent default"})}),e.jsxs(Me,{className:a,children:[e.jsx(Te,{value:Hs,className:"py-1 text-[11px]",children:"Agent default"}),cc(t)]})]})}function iu(t){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[11px] font-medium",children:"Model"}),e.jsx(xo,{...t,triggerClassName:"h-8 rounded-sm border-border/70 bg-background/70"})]})}function po(t,s,n=!1){const r=t.trim();if(r)return r;const a=s.trim().split(`
159
- `).map(i=>i.trim()).find(Boolean);return a?a.length>72?`${a.slice(0,69).trimEnd()}...`:a:n?"Image task":""}function lu(t){const s=t.title.trim(),n=Za(t.agent,t.description),r=n.prompt,a=po(t.title,r,t.images.length>0),i=r.trim()||a,l=t.mode??os,c=t.model?.trim(),d=c&&Ja(t.agent,c)?c:"",m=n.isGoal?n.commandPrompt:r,p=Ha(m,t.images);return!a||!i||!t.agent?null:{title:a,description:i,agent:t.agent,project:t.project.trim()||null,branch:t.branch?.trim()||null,payload:{initialMessage:p,mode:l,...d?{model:d}:{},...n.isGoal?{goal:!0}:{},titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function cu({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,className:d,footerClassName:m,submitLabel:p="Create chat",cancelLabel:u="Cancel",autoFocus:h=!1,layout:x="default",quickChats:k=[]}){const[j,A]=o.useState(""),[f,E]=o.useState(""),[y,v]=o.useState(0),[b,C]=o.useState(nr),[T,P]=o.useState(""),[S,I]=o.useState(os),[_,D]=o.useState(i?.trim()??""),R=o.useRef(i!==void 0),[F,Q]=o.useState(""),Y=o.useMemo(()=>fo(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),ee=o.useMemo(()=>a&&Y.some(X=>X.id===a)?a:n&&Y.some(X=>X.id===n)?n:Y[0]?.id??"",[Y,n,a]),[Z,te]=o.useState(ee),[V,O]=o.useState(!1),[g,$]=o.useState(!1),{images:N,error:q,fileInputRef:z,pickImages:W,handleFileChange:L,handlePaste:oe,removeImage:ie}=lo(),he=o.useRef(null),ae=o.useMemo(()=>Y.find(X=>X.id===Z)??null,[Z,Y]),G=!!(n&&ae?.id===n),M=Wa(b),ne=dc(S),H=o.useMemo(()=>Za(b,f),[b,f]),re=o.useMemo(()=>Qa(b,f),[b,f]),ve=H.prompt,fe=o.useMemo(()=>H.isGoal||re?[]:k,[H.isGoal,re,k]);o.useEffect(()=>{Z&&Y.some(X=>X.id===Z)||te(ee)},[Z,Y,ee]),o.useEffect(()=>{if(R.current){R.current=!1;return}D(ho(Z)),Q("")},[Z]),o.useEffect(()=>{Q("")},[_]),o.useEffect(()=>{v(0)},[f,k,b]);const Pe=o.useCallback(X=>{E(X.prompt)},[]),ke=o.useCallback(()=>{E(re?.value??"/goal "),v(0),!(typeof window>"u")&&window.setTimeout(()=>{const X=he.current;X?.focus();const we=X?.value.length??0;X?.setSelectionRange(we,we)},0)},[re]),mt=o.useCallback(async X=>{if(X.preventDefault(),re){ke();return}const we=vs(f,fe,y);if(we){Pe(we);return}const Re=lu({title:j,description:f,agent:b,model:T,project:_,branch:F,priority:"normal",assignTo:Z,mode:S,images:N});if(Re){O(!0);try{const Fe=await Ui(Re);l(Fe)}catch(Fe){ce.error(Fe instanceof Error?Fe.message:"Failed to create task")}finally{O(!1)}}},[j,f,b,T,_,F,Z,S,N,l,fe,y,Pe,re,ke]),Be=po(j,ve,N.length>0),et=!re&&!!(Be&&b&&Z&&(ve.trim()||N.length>0)),je=o.useCallback(X=>{if(X.nativeEvent.isComposing)return;if(re&&(X.key==="ArrowDown"||X.key==="ArrowUp")){X.preventDefault();return}const we=Aa(f,fe);if(we.length>0&&(X.key==="ArrowDown"||X.key==="ArrowUp")){X.preventDefault(),v(Re=>Da(Re,we.length,X.key==="ArrowDown"?1:-1));return}if(X.key==="Enter"){if(re&&!X.shiftKey){X.preventDefault(),ke();return}const Re=vs(f,fe,y);if(Re&&!X.shiftKey){X.preventDefault(),Pe(Re);return}}X.key==="Enter"&&(X.ctrlKey||X.metaKey)&&et&&!V&&(X.preventDefault(),X.currentTarget.form?.requestSubmit())},[ke,Pe,fe,et,f,re,y,V]),He=N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:N.map((X,we)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:uc(X),alt:X.filename??`attachment ${we+1}`,className:"h-20 w-20 rounded-sm border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>ie(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 ${X.filename??`image ${we+1}`}`,children:e.jsx(it,{className:"h-3.5 w-3.5"})})]},`${X.filename??"image"}-${we}`))}),Ye=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[11px] font-medium",children:"Assign to"}),e.jsxs(De,{value:Z,onValueChange:te,children:[e.jsx(_e,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select node"})}),e.jsx(Me,{children:Mn(Y,n)})]})]}),Oe=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[11px] font-medium",children:"Agent"}),e.jsxs(De,{value:b,onValueChange:C,children:[e.jsx(_e,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select agent"})}),e.jsx(Me,{children:mr()})]})]}),Ie=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[11px] font-medium",children:"Mode"}),e.jsxs(De,{value:S,onValueChange:X=>I(X),children:[e.jsx(_e,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select mode"})}),e.jsx(Me,{children:hr()})]})]}),pt=e.jsx(Ss,{value:_,onChange:D,assignTo:Z,nodes:t,assignableNodes:Y}),ht=e.jsx(wr,{value:F,onChange:Q,project:_,assignTo:Z,nodes:t,assignableNodes:Y});return x==="composer"?e.jsxs("form",{onSubmit:mt,className:B("space-y-4",d),children:[e.jsx("input",{ref:z,type:"file",accept:"image/*",multiple:!0,onChange:L,className:"hidden"}),(()=>{const X="chat-composer__chip h-9 min-w-0 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors [&>span]:min-w-0",we="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",Re="border-border/70 bg-background/55 text-foreground",Fe=b===nr,Ee=S===os;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(De,{value:Z,onValueChange:te,children:[e.jsx(_e,{className:B(X,Re,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${ae?.name??"unassigned"}`,"aria-label":`Assigned node: ${ae?.name??"unassigned"}`,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(Hn,{isCurrent:G}),e.jsx("span",{className:"min-w-0 truncate",children:ae.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:G?"current":"remote"})]}):e.jsx($e,{placeholder:"Select node"})}),e.jsx(Me,{children:Mn(Y,n)})]}),g?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{id:"task-title-composer",type:"text",value:j,onChange:ye=>A(ye.target.value),onKeyDown:ye=>{(ye.key==="Enter"||ye.key==="Escape")&&(ye.preventDefault(),$(!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(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>$(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(as,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>$(!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:Be||"Title","aria-label":Be?`Edit title: ${Be}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:Be||"Title"}),e.jsx(Ut,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",ref:he,value:f,onChange:ye=>E(ye.target.value),onKeyDown:je,onPaste:oe,placeholder:"Ask anything...",rows:4,autoFocus:h,"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(vr,{agent:b,query:f,onSelect:ke}),e.jsx(jn,{query:f,quickChats:fe,selectedIndex:y,onActiveIndexChange:v,onSelect:Pe}),e.jsxs("div",{className:"chat-composer__rail flex min-w-0 flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:W,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(An,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(De,{value:b,onValueChange:C,children:[e.jsxs(_e,{className:B(X,"chat-composer__icon-trigger",Fe?we:Re),title:`Agent: ${M}`,"aria-label":`Agent: ${M}`,children:[e.jsx($n,{agent:b}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:M})]}),e.jsx(Me,{children:mr()})]}),e.jsx(xo,{agent:b,value:T,onChange:P,chip:!0,triggerClassName:B(X,"chat-composer__icon-trigger",T?Re:we),contentClassName:"max-h-80 shadow-none"}),e.jsxs(De,{value:S,onValueChange:ye=>I(ye),children:[e.jsxs(_e,{className:B(X,"chat-composer__icon-trigger",Ee?we:Re),title:`Mode: ${ne}`,"aria-label":`Mode: ${ne}`,children:[e.jsx(cd,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:ne})]}),e.jsx(Me,{children:hr()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[c&&e.jsxs(J,{type:"button",variant:"ghost",size:"sm",onClick:c,"aria-label":u,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(it,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:u})]}),e.jsxs(J,{type:"submit",size:"icon",disabled:!et||V,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[V?e.jsx(de,{className:"h-4 w-4 animate-spin"}):e.jsx(ro,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:V?"Creating chat":p})]})]})]})]}),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(Ss,{value:_,onChange:D,assignTo:Z,nodes:t,assignableNodes:Y,layout:"composer",chipClassName:X,chipActiveClassName:ye,chipInactiveClassName:ye,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(wr,{value:F,onChange:Q,project:_,assignTo:Z,nodes:t,assignableNodes:Y,layout:"composer",chipClassName:X,chipActiveClassName:ye,chipInactiveClassName:ye,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(He||q)&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/45 p-2.5",children:[He,q&&e.jsx("div",{className:"text-[11px] text-destructive",children:q}),!q&&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:mt,className:B("space-y-4",d),children:[e.jsx("input",{ref:z,type:"file",accept:"image/*",multiple:!0,onChange:L,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{htmlFor:"task-description",className:"text-[11px] font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",ref:he,value:f,onChange:X=>E(X.target.value),onKeyDown:je,onPaste:oe,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:h,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(vr,{agent:b,query:f,onSelect:ke}),e.jsx(jn,{query:f,quickChats:fe,selectedIndex:y,onActiveIndexChange:v,onSelect:Pe}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(J,{type:"button",variant:"outline",onClick:W,className:"rounded-sm",children:[e.jsx(An,{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."})]}),He,q&&e.jsx("p",{className:"text-[11px] text-destructive",children:q})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_170px_190px_150px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{htmlFor:"task-title",className:"text-[11px] font-medium",children:"Chat title"}),e.jsx(ot,{id:"task-title",type:"text",value:j,onChange:X=>A(X.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:Be?`Will appear as: ${Be}`:"A title will be generated from the first line of the prompt."})]}),Oe,e.jsx(iu,{agent:b,value:T,onChange:P}),Ie]}),pt,ht,Ye,e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",m),children:[c&&e.jsx(J,{type:"button",variant:"ghost",onClick:c,className:"rounded-sm",children:u}),e.jsx(J,{type:"submit",disabled:!et||V,className:"rounded-sm px-5",children:V?"Creating...":p})]})]})}function du({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,defaultMode:d="chat",mode:m,onModeChange:p,layout:u="default",className:h,footerClassName:x,autoFocus:k=!1,quickChats:j=[]}){const[A,f]=o.useState(d),E=m!==void 0,y=E?m:A,v=b=>{E||f(b),p?.(b)};return e.jsxs("div",{className:B("space-y-4",h),children:[!E&&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(J,{type:"button",variant:y==="chat"?"default":"ghost",onClick:()=>v("chat"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(zi,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(J,{type:"button",variant:y==="native"?"default":"ghost",onClick:()=>v("native"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(qn,{className:"h-4 w-4"}),"Load session"]})]}),y==="chat"?e.jsx(cu,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,footerClassName:x,submitLabel:u==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:k,layout:u,quickChats:j},`${a??""}:${i??""}`):e.jsx(ou,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:l,onCancel:c,footerClassName:x,autoFocus:k})]})}function uu({onClick:t,running:s}){return e.jsxs(J,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:B("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(Ut,{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 jr({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 mu({hasVisibleTranscriptEvents:t,hasTranscriptProgress:s,inputCollapsed:n}){return{collapsedButtonRunning:s&&t&&n,showDockedProgress:s&&t&&!n,showInlineProgress:s&&!t}}const Lt="72f988bf-86f1-41af-91ab-2d7cd011db47",go=`${Lt} (MSIT)`;function hu({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i=!1,shareResult:l}){return e.jsx(Ct,{open:t,onOpenChange:s,children:e.jsxs(Tt,{className:"max-w-md rounded-sm p-4",children:[e.jsx(zt,{className:"sr-only",children:"Share conversation"}),e.jsx(fu,{onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i,shareResult:l})]})})}function fu({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:a=!1,shareResult:i}){const[l,c]=o.useState(i?.tenant??Lt),[d,m]=o.useState(i?.scope??"chat"),p=i?.url?Ia(i.url):null,u=r||a;return o.useEffect(()=>{c(i?.tenant??Lt),m(i?.scope??"chat")},[i?.shareId,i?.tenant,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(xu,{value:l,onChange:c,disabled:u}),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(Nr,{active:d==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>m("chat")}),e.jsx(Nr,{active:d==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>m("filesPreview")})]})]}),p&&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:p,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>{Ts(p,"Shared link copied")},"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ra,{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(J,{variant:"outline",onClick:()=>t(!1),disabled:u,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(J,{variant:"outline",onClick:()=>{n()},disabled:u,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[a&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(J,{onClick:()=>{s({tenant:l,scope:d})},disabled:u,className:"h-8 text-xs",children:[r&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function xu({value:t,onChange:s,disabled:n}){const[r,a]=o.useState(!1),[i,l]=o.useState(!1),[c,d]=o.useState(t),m=o.useRef(null);o.useEffect(()=>{d(t)},[t]),o.useEffect(()=>{if(!r)return;const u=x=>{const k=x.target;k instanceof Node&&(m.current?.contains(k)||(a(!1),l(!1)))},h=x=>{x.key==="Escape"&&(a(!1),l(!1))};return document.addEventListener("mousedown",u),document.addEventListener("keydown",h),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",h)}},[r]);const p=u=>{const h=u.trim();h&&(s(h),d(h),l(!1),a(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:m,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&a(u=>!u),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:pu(t)}),e.jsx(Qe,{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:()=>p(Lt),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:go}),t===Lt&&e.jsx(as,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]}),e.jsx("div",{className:"border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:i?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:c,onChange:u=>d(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),p(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:()=>p(c),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(as,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{d(t),l(!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(it,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>l(!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(Ut,{className:"h-3 w-3"})]})})]})]})]})}function pu(t){return t===Lt?go:t}function Nr({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 gu(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 bu({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(Jc,{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 a=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:gu(n.content)}),a.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:a.map((i,l)=>e.jsx(Ga,{image:i,alt:i.filename??`queued attachment ${l+1}`,thumbnailClassName:"h-14 w-14 border border-border/65",imageClassName:"h-full w-full"},`${i.filename??"image"}-${l}`))})]}),s&&e.jsx(J,{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(it,{className:"h-3 w-3"})})]},n.id)})})]})})}const vu="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",wu=[{value:"transcript",label:"Transcript",icon:$i},{value:"files",label:"Files",icon:Ft,activeIcon:Ms},{value:"diff",label:"Diff",icon:js},{value:"preview",label:"Preview",icon:jc}];function yu({activeTab:t}){return e.jsx(Bn,{className:"h-auto max-w-full justify-start gap-2 overflow-x-auto rounded-sm !bg-muted/40 !p-0.5 !shadow-none",children:wu.map(s=>{const n=s.value===t&&s.activeIcon?s.activeIcon:s.icon;return e.jsx(kt,{value:s.value,title:s.label,"aria-label":s.label,className:vu,children:e.jsx(n,{className:"h-3.5 w-3.5","aria-hidden":"true"})},s.value)})})}const bo="pointer-events-auto h-5 w-5 shrink-0 rounded-sm bg-muted/65 text-muted-foreground hover:bg-muted hover:text-foreground",Cs="h-3.5 w-3.5";function Pn({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,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(vo,{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(wo,{operationsOpen:r,onToggleOperations:a,className:"xl:hidden"})]})}function vo({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){const a=globalThis.window?.matchMedia("(min-width: 1024px)")?.matches?s:n;return e.jsx(J,{variant:"ghost",size:"icon",onClick:r,title:a?"Hide tasks":"Show tasks","aria-label":a?"Hide tasks":"Show tasks",className:B(bo,t),children:a?e.jsx(ys,{className:Cs}):e.jsx(Xe,{className:Cs})})}function wo({className:t,operationsOpen:s,onToggleOperations:n}){return e.jsx(J,{variant:"ghost",size:"icon",onClick:n,title:s?"Hide cluster":"Show cluster","aria-label":s?"Hide cluster":"Show cluster",className:B(bo,t),children:s?e.jsx(Xe,{className:Cs}):e.jsx(ys,{className:Cs})})}const kr="h-7 w-7 rounded-sm border-0 bg-primary/10 text-primary backdrop-blur hover:bg-primary/20 hover:text-primary";function ju({active:t,onScrollToBottom:s,onScrollToTop:n}){return e.jsxs("div",{className:B("pointer-events-none absolute right-3 top-1/2 z-10 flex -translate-y-1/2 flex-col gap-2 opacity-0 transition-opacity duration-200 group-hover:pointer-events-auto group-hover:opacity-100",t&&"pointer-events-auto opacity-100"),children:[e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:kr,onClick:n,"aria-label":"Scroll to top",title:"Scroll to top",children:e.jsx(qi,{className:"h-4 w-4"})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:kr,onClick:s,"aria-label":"Scroll to bottom",title:"Scroll to bottom",children:e.jsx(Qe,{className:"h-4 w-4"})})]})}const Sr="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",Nt={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:`${Sr} mt-0`,action:Sr},Nu=30,ku=1600;function Su({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Ks(t){return t.scrollHeight-t.scrollTop-t.clientHeight<Nu}function Cr({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function Gs(t,s){return!!(s&&(t===s||t.contains(s)))}function Ws(t){const s=t.ownerDocument.getSelection();if(!s||s.isCollapsed||s.rangeCount===0)return!1;if(Gs(t,s.anchorNode)||Gs(t,s.focusNode))return!0;for(let n=0;n<s.rangeCount;n+=1)if(Gs(t,s.getRangeAt(n).commonAncestorContainer))return!0;return!1}function Cu({atTop:t,inputCollapseDisabled:s,scrollingUp:n}){return!s&&(n||t)}function Tu({activeTab:t,activeTaskId:s,contentVersion:n,inputCollapseDisabled:r=!1,setActiveTab:a,setInputCollapsed:i}){const l=o.useRef(null),c=o.useRef(s),d=o.useRef(!1),m=o.useRef(0),p=o.useRef(new Map),u=o.useRef(0),h=o.useRef(!0),x=o.useCallback((v=c.current)=>{const b=l.current;!b||!v||(p.current.set(v,b.scrollTop),m.current=b.scrollTop,h.current=Ks(b))},[]),k=o.useCallback((v=c.current)=>{const b=l.current;!b||!v||(b.scrollTop=Su({savedScrollTop:p.current.get(v),scrollHeight:b.scrollHeight,clientHeight:b.clientHeight}),m.current=b.scrollTop,h.current=Ks(b))},[]),j=o.useCallback((v,b=c.current)=>{v.scrollTop=v.scrollHeight,m.current=v.scrollTop,h.current=!0,b&&p.current.set(b,v.scrollTop)},[]),A=o.useCallback((v=c.current)=>{const b=l.current;u.current=Date.now()+ku,b&&(j(b,v),requestAnimationFrame(()=>{j(b,v),requestAnimationFrame(()=>j(b,v))}))},[j]),f=o.useCallback((v=c.current)=>{const b=l.current;u.current=0,b&&(b.scrollTop=0,m.current=0,h.current=!1,v&&p.current.set(v,0))},[]),E=o.useCallback(v=>{const b=v.currentTarget,C=m.current,T=b.scrollTop<C&&C-b.scrollTop>10,P=b.scrollTop<=0,S=Ws(b);if(x(),S){u.current=0;return}if(!d.current){if(Ks(b)){i(!1),d.current=!0,setTimeout(()=>{d.current=!1},300);return}(T||P)&&(u.current=0,Cu({atTop:P,inputCollapseDisabled:r,scrollingUp:T})&&i(!0))}},[r,x,i]),y=o.useCallback(v=>{t==="transcript"&&x(),a(v),v==="transcript"&&requestAnimationFrame(()=>k())},[t,k,x,a]);return o.useLayoutEffect(()=>{r&&i(!1)},[r,i]),o.useLayoutEffect(()=>{const v=c.current;v&&v!==s&&x(v),c.current=s,t==="transcript"&&requestAnimationFrame(()=>k(s))},[s,t,k,x]),o.useLayoutEffect(()=>{const v=l.current;if(!v||t!=="transcript"||!s)return;const b=Cr({explicitBottomStickUntil:u.current,now:Date.now(),wasAtBottom:h.current});if(Ws(v)){u.current=0,x(s);return}b&&j(v,s),x(s)},[s,t,n,x,j]),o.useLayoutEffect(()=>{const v=l.current,b=v?.firstElementChild;if(!v||!b||t!=="transcript"||typeof ResizeObserver>"u")return;const C=new ResizeObserver(()=>{if(Ws(v)){u.current=0,x();return}Cr({explicitBottomStickUntil:u.current,now:Date.now(),wasAtBottom:h.current})?j(v):x()});return C.observe(v),C.observe(b),()=>C.disconnect()},[t,s,x,j]),{handleTranscriptScroll:E,handleTranscriptTabChange:y,scrollTranscriptToBottom:A,scrollTranscriptToTop:f,transcriptScrollRef:l}}function yo(t=700){const[s,n]=o.useState(!1),r=o.useRef(null),a=o.useCallback(()=>{n(!0),r.current!==null&&clearTimeout(r.current),r.current=setTimeout(()=>{n(!1),r.current=null},t)},[t]);return o.useEffect(()=>()=>{r.current!==null&&clearTimeout(r.current)},[]),{markScrollbarActive:a,scrollbarActive:s}}const Eu=o.lazy(async()=>({default:(await Fn(()=>import("./FilesTab-DdNDe4Vy.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Au=o.lazy(async()=>({default:(await Fn(()=>import("./PreviewTab-CLE4ZFIp.js").then(s=>s.c),__vite__mapDeps([6,1,2]))).PreviewTab})),Du=o.lazy(async()=>({default:(await Fn(()=>import("./DiffTab-CGRnl8EV.js"),__vite__mapDeps([7,1,2,5,4,3,6]))).DiffTab}));function _u({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,activeTab:l,setActiveTab:c,creatingTask:d,createMode:m,createDefaults:p,activeTask:u,assignedNode:h,taskLoading:x,transcriptLoading:k,taskError:j,displayEvents:A,initialPromptAlreadyInLogs:f,initialPrompt:E,supportsFollowUp:y,taskUnavailable:v,chatDisabled:b,chatDisabledReason:C,questionBypassEnabled:T,isRunning:P,isStarting:S,hasPendingFollowUp:I,canCancel:_,canRetry:D,onRetry:R,onCancel:F,onReloadNativeTranscript:Q,onShareTask:Y,onStopShareTask:ee,onStartCreateTask:Z,onCancelCreateTask:te,onCreateTask:V,onSendMessage:O,onCancelQueuedMessage:g,onQuestionBypassChange:$,onSubmitQuestionResponse:N,quickChats:q=[]}){const[z,W]=o.useState(!1),[L,oe]=o.useState(!1),[ie,he]=o.useState(!1),[ae,G]=o.useState(!1),[M,ne]=o.useState(!1),[H,re]=o.useState({}),[ve,fe]=o.useState(new Set),[Pe,ke]=o.useState(new Set),[mt,Be]=o.useState(null),et=u?.effectiveProjectPath??u?.project??"default workspace",je=u?h?.name??Nn(u.assignedTo,i?.nodes,u.assignedNodeName):"unassigned",He=u?.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:je}),"..."]}):"Connecting session to an available node...",Ye=u?[{label:"Working dir",value:et,mono:!0},...u.branch?[{label:"Branch",value:u.branch,mono:!0}]:[],{label:"Agent",value:u.agent,mono:!0},{label:"Node",value:je}]:[],Oe=!!(E&&!f),Ie=Oe||A.length>0,pt=P&&Ie,ht=(S||I||P)&&!pt,X=pt?"The agent is still working on this conversation.":ht?He:null,{collapsedButtonRunning:we,showDockedProgress:Re,showInlineProgress:Fe}=mu({hasTranscriptProgress:!!X,hasVisibleTranscriptEvents:Ie,inputCollapsed:z}),Ee=u?.conversationKind==="nativeSession",ye=mc(u),Se=k?"Loading transcript":Ee?"No transcript imported":"Transcript is warming up",Dt=k?"Loading transcript...":Ee?"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.",_t=u?.queuedMessages??[],ft=o.useMemo(()=>hc(A),[A]),K=o.useMemo(()=>ft.findIndex(({event:pe})=>Mu(pe)),[ft]),Le=o.useMemo(()=>fc("transcript",ft.map(pe=>pe.event)),[ft]),Ce=u&&!ve.has(u.id)?H[u.id]??u.activeShare??null:null,xt=u?.id??null,qt=`${xt??"none"}:${A.length}:${_t.length}:${Oe?1:0}:${k?1:0}:${Fe?1:0}`,{handleTranscriptScroll:Mt,handleTranscriptTabChange:Ae,scrollTranscriptToBottom:qe,scrollTranscriptToTop:wt,transcriptScrollRef:yt}=Tu({activeTab:l,activeTaskId:xt,contentVersion:qt,inputCollapseDisabled:!!X,setActiveTab:c,setInputCollapsed:W}),{markScrollbarActive:tt,scrollbarActive:jt}=yo(),ze=o.useCallback(pe=>{tt(),Mt(pe)},[Mt,tt]),lt=o.useCallback(pe=>{Be(ge=>({path:pe,requestId:(ge?.requestId??0)+1})),Ae("files")},[Ae]),Ne=o.useCallback(pe=>{qe(),O(pe)},[O,qe]);return o.useEffect(()=>{Be(null)},[xt]),d?e.jsx(Pu,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,defaultMode:m,createDefaults:p,onCancel:te,onCreated:V,quickChats:q}):!u&&x?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(Pn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a})}),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(de,{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(de,{className:"h-3.5 w-3.5 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):u?e.jsxs(On,{value:l,onValueChange:Ae,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(vo,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(wo,{operationsOpen:r,onToggleOperations:a,className:"xl:hidden"})]}),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:u.title,children:u.title}),e.jsx(La,{status:u.status,isNative:Ee}),ye&&e.jsxs("span",{"data-task-goal-label":"true",title:"Codex goal",className:"inline-flex h-5 shrink-0 items-center gap-1 rounded-sm bg-primary/10 px-1.5 text-[9px] font-semibold uppercase tracking-[0.12em] text-primary",children:[e.jsx(Ya,{className:"h-3 w-3","aria-hidden":"true"}),"Goal"]}),u.priority!=="normal"&&e.jsx(Hi,{priority:u.priority})]}),j&&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:j}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx(yu,{activeTab:l}),v&&e.jsx(Ve,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"hidden rounded-sm bg-muted/65 px-1.5 py-0.5 tabular-nums sm:inline-flex",children:Ki(u.updatedAt)}),D&&e.jsxs(J,{variant:"ghost",size:"sm",onClick:R,"aria-label":"Retry task",title:"Retry task",className:"h-7 shrink-0 rounded-sm border-0 bg-primary/10 px-2 text-[10px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[e.jsx(rd,{className:"h-3.5 w-3.5"}),"Retry"]}),Ee&&Q&&e.jsx(J,{variant:"ghost",size:"icon",onClick:Q,disabled:k,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(no,{className:B("h-3.5 w-3.5",k&&"animate-spin")})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",disabled:v,title:v?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":v?"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:()=>he(!0),children:e.jsx(ks,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(ut,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"group 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:yt,"data-transcript-scroll":"true",className:B("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",jt&&"scrollbar-line-active"),onScroll:ze,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[Oe&&E&&e.jsx(fr,{event:E,agent:u.agent,sentAsGoal:ye,taskRootPath:u.effectiveProjectPath,onOpenFilePath:lt,questionBypassEnabled:T,onQuestionBypassChange:$,onSubmitQuestionResponse:N,questionResponseDisabled:!y||b}),ft.map(({event:pe,subItems:ge},Ge)=>e.jsx(fr,{event:pe,agent:u.agent,subItems:ge,sentAsGoal:ye&&!Oe&&Ge===K,taskRootPath:u.effectiveProjectPath,onOpenFilePath:lt,questionBypassEnabled:T,onQuestionBypassChange:$,onSubmitQuestionResponse:N,questionResponseDisabled:!y||b},Le[Ge])),!Ie&&!ht&&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:Se}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Dt})]}),(!y&&u.result||u.error)&&e.jsxs("div",{className:"space-y-3",children:[!y&&u.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(u.result,null,2)})]}),u.error&&!Pe.has(u.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:()=>ke(pe=>new Set(pe).add(u.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(it,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5",children:u.error})]})]}),Fe&&X&&e.jsx(jr,{children:X})]})})}),e.jsx(ju,{active:jt,onScrollToBottom:()=>qe(),onScrollToTop:()=>wt()}),Re&&X&&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(jr,{children:X})})}),y?e.jsxs(e.Fragment,{children:[z&&e.jsx(uu,{running:we,onClick:()=>{W(!1),qe(),requestAnimationFrame(()=>document.querySelector('[data-chat-input-textarea="true"]')?.focus())}}),e.jsxs("div",{className:`shrink-0 ${z?"hidden":""}`,children:[e.jsx(bu,{messages:_t,onCancelMessage:g}),e.jsx(Pd,{onSend:Ne,disabled:b,disabledReason:C,contextItems:Ye,agent:u.agent,model:typeof u.payload.model=="string"?u.payload.model:null,placeholder:b?C:P?"Queue a message for the next turn...":"Continue the conversation...",running:P||I,onStop:_?()=>oe(!0):void 0,quickChats:q})]})]}):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(ut,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading files..."}),children:e.jsx(Eu,{taskId:u.id,requestedFilePath:mt?.path??null,requestedFileRequestId:mt?.requestId??0})})}),e.jsx(ut,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading preview..."}),children:e.jsx(Au,{taskId:u.id})})}),e.jsx(ut,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading diff..."}),children:e.jsx(Du,{taskId:u.id})})}),e.jsx(Yt,{open:L,onOpenChange:oe,children:e.jsxs(Jt,{className:Nt.content,children:[e.jsxs(Zt,{className:Nt.header,children:[e.jsx(Xt,{className:Nt.title,children:"Stop this task?"}),e.jsx(es,{className:Nt.description,children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ts,{className:Nt.footer,children:[e.jsx(ss,{className:Nt.cancel,children:"Keep running"}),e.jsx(ns,{className:Nt.action,onClick:F,children:"Stop task"})]})]})}),e.jsx(hu,{open:ie,onOpenChange:he,sharing:ae,stopping:M,shareResult:Ce,onShare:async pe=>{if(!u)return null;G(!0);try{const ge=await Y(pe);return ge?.url&&(re(Ge=>({...Ge,[u.id]:ge})),fe(Ge=>{const ct=new Set(Ge);return ct.delete(u.id),ct})),ge}finally{G(!1)}},onStopShare:async()=>{if(!u)return!1;ne(!0);try{const pe=await ee();return pe!==!1&&(re(ge=>{const Ge={...ge};return delete Ge[u.id],Ge}),fe(ge=>new Set(ge).add(u.id))),pe}finally{ne(!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(Pn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a})}),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(Vi,{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(J,{onClick:()=>Z(),className:"mt-4 h-8 rounded-sm px-3",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),"Start or load chat"]}),j&&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:j})]})})]})}function Mu(t){return t.type!=="user"||t.isMeta===!0||t.isSidechain===!0?!1:!!Cn(t)?.some(n=>n.type==="text"||n.type==="image")}function Pu({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,defaultMode:l,createDefaults:c,onCancel:d,onCreated:m,quickChats:p}){const[u,h]=o.useState(l??"chat");o.useEffect(()=>{l&&h(l)},[l]);const x=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:Ps},{value:"native",label:"Load session",icon:qn}].map(k=>{const j=k.icon,A=k.value===u;return e.jsxs("button",{type:"button",onClick:()=>h(k.value),"aria-pressed":A,className:B("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",A?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(j,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:k.label})]},k.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(Pn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,centerSlot:x})}),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(du,{nodes:i?.nodes??[],currentNodeRole:i?.self?.role,currentNodeId:i?.self?.id??null,leaderNodeId:i?.leader?.id??null,initialAssignTo:c?.assignTo,initialProject:c?.project,mode:u,onModeChange:h,onCreated:m,onCancel:d,autoFocus:!0,layout:"composer",quickChats:p})})})]})}function Iu({onAdded:t}){const[s,n]=o.useState(""),[r,a]=o.useState(!1),[i,l]=o.useState(null),c=o.useCallback(async d=>{if(d.preventDefault(),!!s.trim()){a(!0),l(null);try{await Gi({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(m){l(m instanceof Error?m.message:"Failed to join node")}finally{a(!1)}}},[s,t]);return e.jsx(Tt,{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(Es,{className:"space-y-1 text-left",children:[e.jsx(zt,{className:"text-sm tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Verify the remote leader's DevTunnel Node URL, 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(Ke,{htmlFor:"leader-endpoint",children:"Leader Node URL"}),e.jsx(Ve,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(ot,{id:"leader-endpoint",type:"url",value:s,onChange:d=>n(d.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(Ba,{className:"border-t border-border/60 pt-3",children:e.jsx(J,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function Ru({open:t,onOpenChange:s,onAdded:n}){return e.jsx(Ct,{open:t,onOpenChange:s,children:e.jsx(Iu,{onAdded:()=>{s(!1),n()}})})}const Lu="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",Bu="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",Ou="h-2.5 w-2.5";function jo({className:t,label:s,orientation:n,panel:r,panelResize:a}){return e.jsx("button",{type:"button","aria-label":s,"aria-orientation":n,"data-dashboard-resize-handle":r,onPointerDown:i=>a.onPointerDown(r,i),onWheel:i=>a.onWheel(r,i),className:B("group absolute z-20 hidden touch-none rounded-sm bg-transparent outline-none transition-colors hover:bg-primary/12 focus-visible:bg-primary/12 focus-visible:ring-2 focus-visible:ring-ring/70 lg:block",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 Fu({className:t,label:s,onToggle:n,side:r,visible:a}){const i=r==="left"?a?ys:Xe:a?Xe:ys;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:B(Lu,t),children:e.jsx("span",{className:Bu,"aria-hidden":"true",children:e.jsx(i,{className:Ou,strokeWidth:2.1})})})}function Tr({className:t,label:s,onToggle:n,panel:r,panelResize:a,screen:i,side:l,visible:c}){const d=i==="lg"?"lg:block":"xl:block",m=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:B("group absolute top-0 z-30 hidden h-full w-4",d,t),children:[r&&e.jsx(jo,{panel:r,orientation:"vertical",label:`Resize ${r} panel`,panelResize:a,className:"left-1/2 top-0 h-full w-2 -translate-x-1/2 cursor-col-resize"}),e.jsx(Fu,{side:l,visible:c,label:s,onToggle:n,className:B(m,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function zu({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:a,operationsOpen:i,operationsPanelRef:l,operationsSidecar:c,panelResize:d,taskSidebar:m,terminalPanel:p,onCloseOperations:u,onCloseTaskList:h,onToggleOperations:x,onToggleTasks:k}){const j={"--dashboard-tasks-width":d.sizes.tasks,"--dashboard-operations-width":d.sizes.operations,"--dashboard-terminal-height":d.sizes.terminal};return e.jsxs("div",{className:"dashboard-workspace flex h-full min-h-0 flex-col overflow-hidden",style:j,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(Tr,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:k,panel:s?"tasks":void 0,panelResize:d,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:B("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&&m}),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}),p&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(jo,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:d,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),p]})]}),e.jsx(Tr,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:x,panel:i?"operations":void 0,panelResize:d,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:B("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:u,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:l,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:h,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:a,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 Uu=10,St="__all__";function Je(t){return"session"in t}function Er(t,s){return s&&t.some(n=>n.id===s)?s:t[0]?.id??""}function Qs(t){return t&&(ho(t.id)||t.workDir)||""}function fs(t,s,n){let r=!1;const a=t.map(i=>Je(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return In(r?a:[...a,{id:`session-${n.id}`,nodeName:s,session:n}])}function No(t,s){return t.filter(Je).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function $u(t){const s=t.filter(Je).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 qu(t,s){return!!(t&&s&&!t.contains(s))}function Vu(t,s,n){if(n===St)return n;const r=No(t,s);return r.some(a=>a.session.id===n)?n:r[0]?.session.id??St}function Hu(t,s,n){return n===St?t.filter(r=>!Je(r)||r.session.nodeId===s):t.filter(r=>Je(r)&&r.session.nodeId===s&&r.session.id===n)}function In(t){const s=t.map((r,a)=>({entry:r,index:a})).filter(({entry:r})=>Je(r)&&r.session.status!=="running").sort((r,a)=>!Je(r.entry)||!Je(a.entry)?0:a.entry.session.startedAt-r.entry.session.startedAt||a.index-r.index),n=new Set(s.slice(0,Uu).map(({entry:r})=>Je(r)?r.session.id:""));return t.filter(r=>!Je(r)||r.session.status==="running"||n.has(r.session.id))}function Rn(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 Ku(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${Rn(t.session)} - ${s}`}function ko(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function Gu(t,s){return s===St?"All sessions":t?ko(t.session.command,34):"Command session"}function Ar(t){return t.status==="stopped"?"":t.stderr}function Wu({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[a,i]=o.useState(()=>Er(t,s)),l=o.useMemo(()=>t.find(N=>N.id===a)??t[0]??null,[t,a]),[c,d]=o.useState(()=>Qs(l)),[m,p]=o.useState(""),[u,h]=o.useState(()=>In(r)),[x,k]=o.useState(St),[j,A]=o.useState(!1),[f,E]=o.useState(!1),[y,v]=o.useState(!1),[b,C]=o.useState(!1),[T,P]=o.useState(!1),S=o.useRef(null),I=o.useRef(null),_=o.useMemo(()=>t.find(N=>N.id===a)??t[0]??null,[t,a]),D=o.useMemo(()=>No(u,_?.id??""),[u,_]),R=o.useMemo(()=>$u(D),[D]),F=o.useMemo(()=>D.find(N=>N.session.id===x),[x,D]),Q=o.useMemo(()=>Hu(u,_?.id??"",x),[u,_,x]),Y=o.useRef(_?.id??"");o.useEffect(()=>{a&&t.some(N=>N.id===a)||i(Er(t,s))},[s,t,a]),o.useEffect(()=>{const N=_?.id??"";Y.current!==N&&(Y.current=N,d(Qs(_)))},[_]),o.useEffect(()=>{k(N=>Vu(u,_?.id??"",j?N:""))},[u,_,j]),o.useEffect(()=>{S.current?.scrollTo({top:S.current.scrollHeight})},[u]),o.useEffect(()=>{let N=!1;async function q(){const z=await Promise.allSettled(t.map(async W=>({node:W,response:await Qi(W.id)})));N||h(W=>z.reduce((L,oe)=>oe.status!=="fulfilled"?L:oe.value.response.sessions.reduce((ie,he)=>fs(ie,oe.value.node.name,he),L),W))}return t.length>0&&q(),()=>{N=!0}},[t]),o.useEffect(()=>{const N=u.filter(Je).filter(z=>z.session.status==="running");if(N.length===0)return;const q=window.setInterval(()=>{for(const z of N)Wi(z.session.nodeId,z.session.id).then(W=>h(L=>fs(L,z.nodeName,W))).catch(()=>{})},1e3);return()=>window.clearInterval(q)},[u]);const ee=o.useRef(null);async function Z(N){if(N.preventDefault(),!_||!m.trim()||T)return;const q=m.trim(),z=_.name;P(!0),p("");try{const W=await Ji(_.id,{command:q,...c.trim()?{cwd:c.trim()}:{}});h(L=>fs(L,z,W)),k(W.id),A(!0)}catch(W){h(L=>[...L,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:z,command:q,error:W instanceof Error?W.message:"Command failed"}])}finally{P(!1)}}async function te(N,q){N.stopPropagation();const z=await Yi(q.session.nodeId,q.session.id);h(W=>fs(W,q.nodeName,z))}function V(N){k(N),A(!0),E(!1)}function O(N){f&&qu(I.current,N.target)&&E(!1)}function g(N,q,z,W,L){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:W,"aria-label":`Toggle ${N} sessions`,"aria-expanded":!z,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:N}),e.jsx(Qe,{className:B("h-3 w-3 transition-transform",z&&"-rotate-90")})]}),!z&&(q.length>0?q.map($):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:L}))]})}function $(N){const q=x===N.session.id,z=N.session.status==="running";return e.jsxs("div",{className:B("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",q&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>V(N.session.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:B("flex h-4 w-4 shrink-0 items-center justify-center",z?"text-primary":N.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:z?e.jsx(de,{className:"h-3 w-3 animate-spin"}):N.session.status==="exited"?e.jsx(ar,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:ko(N.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[N.nodeName," · ",Rn(N.session)]})]})]}),z&&e.jsx("button",{type:"button",onClick:W=>{te(W,N)},"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(pr,{className:"h-3 w-3"})})]},N.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:O,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(it,{className:"h-3.5 w-3.5"})}):e.jsx(rr,{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:I,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":f,title:F?Ku(F):"All sessions",onClick:()=>E(N=>!N),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:Gu(F,x)}),e.jsx(Qe,{className:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform",f&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!f,className:B("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!f&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>V(St),className:B("node-terminal__control flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",x===St&&"bg-primary/10 text-primary"),children:[e.jsx(rr,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),g("Active",R.active,y,()=>v(N=>!N),"No active sessions"),g("Completed",R.completed,b,()=>C(N=>!N),"No completed sessions")]})})]}),e.jsx("select",{value:_?.id??"",onChange:N=>{i(N.target.value),A(!1),d(Qs(t.find(q=>q.id===N.target.value)??null))},disabled:T||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(N=>e.jsx("option",{value:N.id,className:"bg-background text-foreground",children:N.name},N.id))}),e.jsx(Ss,{value:c,onChange:d,assignTo:_?.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:S,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>ee.current?.focus(),children:[Q.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:Q.map(N=>Je(N)?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:[N.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:N.session.command}),e.jsxs("span",{className:B("inline-flex items-center gap-1",N.session.status==="running"||N.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[N.session.status==="running"?e.jsx(de,{className:"h-3 w-3 animate-spin"}):N.session.status==="exited"?e.jsx(ar,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"}),Rn(N.session)]}),N.session.status==="running"&&e.jsx("button",{type:"button",onClick:q=>{te(q,N)},"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(pr,{className:"h-3 w-3"})})]}),N.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:N.session.stdout}),Ar(N.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Ar(N.session)}),(N.session.stdoutTruncated||N.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},N.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:[N.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:N.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(Us,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:N.error})]},N.id))}),e.jsxs("form",{onSubmit:Z,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:_?`${_.name}$`:"$"}),e.jsx("input",{ref:ee,value:m,onChange:N=>p(N.target.value),disabled:!_||T,placeholder:_?"":"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:!_||!m.trim()||T,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:text-muted-foreground disabled:opacity-50",children:T?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(_s,{className:"h-3 w-3"})})]})]})]})})}var Rt={},Ys,Dr;function Qu(){return Dr||(Dr=1,Ys=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Ys}var Js={},bt={},_r;function Et(){if(_r)return bt;_r=1;let t;const s=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return bt.getSymbolSize=function(r){if(!r)throw new Error('"version" cannot be null or undefined');if(r<1||r>40)throw new Error('"version" should be in range from 1 to 40');return r*4+17},bt.getSymbolTotalCodewords=function(r){return s[r]},bt.getBCHDigit=function(n){let r=0;for(;n!==0;)r++,n>>>=1;return r},bt.setToSJISFunction=function(r){if(typeof r!="function")throw new Error('"toSJISFunc" is not a valid function.');t=r},bt.isKanjiModeEnabled=function(){return typeof t<"u"},bt.toSJIS=function(r){return t(r)},bt}var Zs={},Mr;function Kn(){return Mr||(Mr=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function s(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+n)}}t.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},t.from=function(r,a){if(t.isValid(r))return r;try{return s(r)}catch{return a}}})(Zs)),Zs}var Xs,Pr;function Yu(){if(Pr)return Xs;Pr=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(s){const n=Math.floor(s/8);return(this.buffer[n]>>>7-s%8&1)===1},put:function(s,n){for(let r=0;r<n;r++)this.putBit((s>>>n-r-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(s){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),s&&(this.buffer[n]|=128>>>this.length%8),this.length++}},Xs=t,Xs}var en,Ir;function Ju(){if(Ir)return en;Ir=1;function t(s){if(!s||s<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=s,this.data=new Uint8Array(s*s),this.reservedBit=new Uint8Array(s*s)}return t.prototype.set=function(s,n,r,a){const i=s*this.size+n;this.data[i]=r,a&&(this.reservedBit[i]=!0)},t.prototype.get=function(s,n){return this.data[s*this.size+n]},t.prototype.xor=function(s,n,r){this.data[s*this.size+n]^=r},t.prototype.isReserved=function(s,n){return this.reservedBit[s*this.size+n]},en=t,en}var tn={},Rr;function Zu(){return Rr||(Rr=1,(function(t){const s=Et().getSymbolSize;t.getRowColCoords=function(r){if(r===1)return[];const a=Math.floor(r/7)+2,i=s(r),l=i===145?26:Math.ceil((i-13)/(2*a-2))*2,c=[i-7];for(let d=1;d<a-1;d++)c[d]=c[d-1]-l;return c.push(6),c.reverse()},t.getPositions=function(r){const a=[],i=t.getRowColCoords(r),l=i.length;for(let c=0;c<l;c++)for(let d=0;d<l;d++)c===0&&d===0||c===0&&d===l-1||c===l-1&&d===0||a.push([i[c],i[d]]);return a}})(tn)),tn}var sn={},Lr;function Xu(){if(Lr)return sn;Lr=1;const t=Et().getSymbolSize,s=7;return sn.getPositions=function(r){const a=t(r);return[[0,0],[a-s,0],[0,a-s]]},sn}var nn={},Br;function em(){return Br||(Br=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const s={N1:3,N2:3,N3:40,N4:10};t.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},t.from=function(a){return t.isValid(a)?parseInt(a,10):void 0},t.getPenaltyN1=function(a){const i=a.size;let l=0,c=0,d=0,m=null,p=null;for(let u=0;u<i;u++){c=d=0,m=p=null;for(let h=0;h<i;h++){let x=a.get(u,h);x===m?c++:(c>=5&&(l+=s.N1+(c-5)),m=x,c=1),x=a.get(h,u),x===p?d++:(d>=5&&(l+=s.N1+(d-5)),p=x,d=1)}c>=5&&(l+=s.N1+(c-5)),d>=5&&(l+=s.N1+(d-5))}return l},t.getPenaltyN2=function(a){const i=a.size;let l=0;for(let c=0;c<i-1;c++)for(let d=0;d<i-1;d++){const m=a.get(c,d)+a.get(c,d+1)+a.get(c+1,d)+a.get(c+1,d+1);(m===4||m===0)&&l++}return l*s.N2},t.getPenaltyN3=function(a){const i=a.size;let l=0,c=0,d=0;for(let m=0;m<i;m++){c=d=0;for(let p=0;p<i;p++)c=c<<1&2047|a.get(m,p),p>=10&&(c===1488||c===93)&&l++,d=d<<1&2047|a.get(p,m),p>=10&&(d===1488||d===93)&&l++}return l*s.N3},t.getPenaltyN4=function(a){let i=0;const l=a.data.length;for(let d=0;d<l;d++)i+=a.data[d];return Math.abs(Math.ceil(i*100/l/5)-10)*s.N4};function n(r,a,i){switch(r){case t.Patterns.PATTERN000:return(a+i)%2===0;case t.Patterns.PATTERN001:return a%2===0;case t.Patterns.PATTERN010:return i%3===0;case t.Patterns.PATTERN011:return(a+i)%3===0;case t.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(i/3))%2===0;case t.Patterns.PATTERN101:return a*i%2+a*i%3===0;case t.Patterns.PATTERN110:return(a*i%2+a*i%3)%2===0;case t.Patterns.PATTERN111:return(a*i%3+(a+i)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}t.applyMask=function(a,i){const l=i.size;for(let c=0;c<l;c++)for(let d=0;d<l;d++)i.isReserved(d,c)||i.xor(d,c,n(a,d,c))},t.getBestMask=function(a,i){const l=Object.keys(t.Patterns).length;let c=0,d=1/0;for(let m=0;m<l;m++){i(m),t.applyMask(m,a);const p=t.getPenaltyN1(a)+t.getPenaltyN2(a)+t.getPenaltyN3(a)+t.getPenaltyN4(a);t.applyMask(m,a),p<d&&(d=p,c=m)}return c}})(nn)),nn}var xs={},Or;function So(){if(Or)return xs;Or=1;const t=Kn(),s=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],n=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return xs.getBlocksCount=function(a,i){switch(i){case t.L:return s[(a-1)*4+0];case t.M:return s[(a-1)*4+1];case t.Q:return s[(a-1)*4+2];case t.H:return s[(a-1)*4+3];default:return}},xs.getTotalCodewordsCount=function(a,i){switch(i){case t.L:return n[(a-1)*4+0];case t.M:return n[(a-1)*4+1];case t.Q:return n[(a-1)*4+2];case t.H:return n[(a-1)*4+3];default:return}},xs}var rn={},Wt={},Fr;function tm(){if(Fr)return Wt;Fr=1;const t=new Uint8Array(512),s=new Uint8Array(256);return(function(){let r=1;for(let a=0;a<255;a++)t[a]=r,s[r]=a,r<<=1,r&256&&(r^=285);for(let a=255;a<512;a++)t[a]=t[a-255]})(),Wt.log=function(r){if(r<1)throw new Error("log("+r+")");return s[r]},Wt.exp=function(r){return t[r]},Wt.mul=function(r,a){return r===0||a===0?0:t[s[r]+s[a]]},Wt}var zr;function sm(){return zr||(zr=1,(function(t){const s=tm();t.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let l=0;l<r.length;l++)for(let c=0;c<a.length;c++)i[l+c]^=s.mul(r[l],a[c]);return i},t.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const l=i[0];for(let d=0;d<a.length;d++)i[d]^=s.mul(a[d],l);let c=0;for(;c<i.length&&i[c]===0;)c++;i=i.slice(c)}return i},t.generateECPolynomial=function(r){let a=new Uint8Array([1]);for(let i=0;i<r;i++)a=t.mul(a,new Uint8Array([1,s.exp(i)]));return a}})(rn)),rn}var an,Ur;function nm(){if(Ur)return an;Ur=1;const t=sm();function s(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return s.prototype.initialize=function(r){this.degree=r,this.genPoly=t.generateECPolynomial(this.degree)},s.prototype.encode=function(r){if(!this.genPoly)throw new Error("Encoder not initialized");const a=new Uint8Array(r.length+this.degree);a.set(r);const i=t.mod(a,this.genPoly),l=this.degree-i.length;if(l>0){const c=new Uint8Array(this.degree);return c.set(i,l),c}return i},an=s,an}var on={},ln={},cn={},$r;function Co(){return $r||($r=1,cn.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),cn}var dt={},qr;function To(){if(qr)return dt;qr=1;const t="[0-9]+",s="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const r="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
159
+ `).map(i=>i.trim()).find(Boolean);return a?a.length>72?`${a.slice(0,69).trimEnd()}...`:a:n?"Image task":""}function lu(t){const s=t.title.trim(),n=Za(t.agent,t.description),r=n.prompt,a=po(t.title,r,t.images.length>0),i=r.trim()||a,l=t.mode??os,c=t.model?.trim(),d=c&&Ja(t.agent,c)?c:"",m=n.isGoal?n.commandPrompt:r,p=Ha(m,t.images);return!a||!i||!t.agent?null:{title:a,description:i,agent:t.agent,project:t.project.trim()||null,branch:t.branch?.trim()||null,payload:{initialMessage:p,mode:l,...d?{model:d}:{},...n.isGoal?{goal:!0}:{},titleSource:s?"manual":"derived"},priority:t.priority,assignTo:t.assignTo==="auto"?void 0:t.assignTo}}function cu({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,className:d,footerClassName:m,submitLabel:p="Create chat",cancelLabel:u="Cancel",autoFocus:h=!1,layout:x="default",quickChats:k=[]}){const[j,A]=o.useState(""),[f,E]=o.useState(""),[y,v]=o.useState(0),[b,C]=o.useState(nr),[T,P]=o.useState(""),[S,I]=o.useState(os),[_,D]=o.useState(i?.trim()??""),R=o.useRef(i!==void 0),[F,Q]=o.useState(""),Y=o.useMemo(()=>fo(t,{currentNodeRole:s,leaderNodeId:r}),[t,s,r]),ee=o.useMemo(()=>a&&Y.some(X=>X.id===a)?a:n&&Y.some(X=>X.id===n)?n:Y[0]?.id??"",[Y,n,a]),[Z,te]=o.useState(ee),[V,O]=o.useState(!1),[g,$]=o.useState(!1),{images:N,error:q,fileInputRef:z,pickImages:W,handleFileChange:L,handlePaste:oe,removeImage:ie}=lo(),he=o.useRef(null),ae=o.useMemo(()=>Y.find(X=>X.id===Z)??null,[Z,Y]),G=!!(n&&ae?.id===n),M=Wa(b),ne=dc(S),H=o.useMemo(()=>Za(b,f),[b,f]),re=o.useMemo(()=>Qa(b,f),[b,f]),ve=H.prompt,fe=o.useMemo(()=>H.isGoal||re?[]:k,[H.isGoal,re,k]);o.useEffect(()=>{Z&&Y.some(X=>X.id===Z)||te(ee)},[Z,Y,ee]),o.useEffect(()=>{if(R.current){R.current=!1;return}D(ho(Z)),Q("")},[Z]),o.useEffect(()=>{Q("")},[_]),o.useEffect(()=>{v(0)},[f,k,b]);const Pe=o.useCallback(X=>{E(X.prompt)},[]),ke=o.useCallback(()=>{E(re?.value??"/goal "),v(0),!(typeof window>"u")&&window.setTimeout(()=>{const X=he.current;X?.focus();const we=X?.value.length??0;X?.setSelectionRange(we,we)},0)},[re]),mt=o.useCallback(async X=>{if(X.preventDefault(),re){ke();return}const we=vs(f,fe,y);if(we){Pe(we);return}const Re=lu({title:j,description:f,agent:b,model:T,project:_,branch:F,priority:"normal",assignTo:Z,mode:S,images:N});if(Re){O(!0);try{const Fe=await Ui(Re);l(Fe)}catch(Fe){ce.error(Fe instanceof Error?Fe.message:"Failed to create task")}finally{O(!1)}}},[j,f,b,T,_,F,Z,S,N,l,fe,y,Pe,re,ke]),Be=po(j,ve,N.length>0),et=!re&&!!(Be&&b&&Z&&(ve.trim()||N.length>0)),je=o.useCallback(X=>{if(X.nativeEvent.isComposing)return;if(re&&(X.key==="ArrowDown"||X.key==="ArrowUp")){X.preventDefault();return}const we=Aa(f,fe);if(we.length>0&&(X.key==="ArrowDown"||X.key==="ArrowUp")){X.preventDefault(),v(Re=>Da(Re,we.length,X.key==="ArrowDown"?1:-1));return}if(X.key==="Enter"){if(re&&!X.shiftKey){X.preventDefault(),ke();return}const Re=vs(f,fe,y);if(Re&&!X.shiftKey){X.preventDefault(),Pe(Re);return}}X.key==="Enter"&&(X.ctrlKey||X.metaKey)&&et&&!V&&(X.preventDefault(),X.currentTarget.form?.requestSubmit())},[ke,Pe,fe,et,f,re,y,V]),He=N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:N.map((X,we)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:uc(X),alt:X.filename??`attachment ${we+1}`,className:"h-20 w-20 rounded-sm border border-border/70 object-cover"}),e.jsx("button",{type:"button",onClick:()=>ie(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 ${X.filename??`image ${we+1}`}`,children:e.jsx(it,{className:"h-3.5 w-3.5"})})]},`${X.filename??"image"}-${we}`))}),Ye=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[11px] font-medium",children:"Assign to"}),e.jsxs(De,{value:Z,onValueChange:te,children:[e.jsx(_e,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select node"})}),e.jsx(Me,{children:Mn(Y,n)})]})]}),Oe=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[11px] font-medium",children:"Agent"}),e.jsxs(De,{value:b,onValueChange:C,children:[e.jsx(_e,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select agent"})}),e.jsx(Me,{children:mr()})]})]}),Ie=e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{className:"text-[11px] font-medium",children:"Mode"}),e.jsxs(De,{value:S,onValueChange:X=>I(X),children:[e.jsx(_e,{className:"h-8 rounded-sm border-border/70 bg-background/70",children:e.jsx($e,{placeholder:"Select mode"})}),e.jsx(Me,{children:hr()})]})]}),pt=e.jsx(Ss,{value:_,onChange:D,assignTo:Z,nodes:t,assignableNodes:Y}),ht=e.jsx(wr,{value:F,onChange:Q,project:_,assignTo:Z,nodes:t,assignableNodes:Y});return x==="composer"?e.jsxs("form",{onSubmit:mt,className:B("space-y-4",d),children:[e.jsx("input",{ref:z,type:"file",accept:"image/*",multiple:!0,onChange:L,className:"hidden"}),(()=>{const X="chat-composer__chip h-9 min-w-0 w-auto gap-1.5 rounded-sm px-3.5 text-xs shadow-none transition-colors [&>span]:min-w-0",we="border-transparent bg-transparent text-muted-foreground hover:bg-background/40 hover:text-foreground",Re="border-border/70 bg-background/55 text-foreground",Fe=b===nr,Ee=S===os;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(De,{value:Z,onValueChange:te,children:[e.jsx(_e,{className:B(X,Re,"chat-composer__node-trigger border-transparent bg-transparent hover:bg-background/40"),title:`Assigned node: ${ae?.name??"unassigned"}`,"aria-label":`Assigned node: ${ae?.name??"unassigned"}`,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(Hn,{isCurrent:G}),e.jsx("span",{className:"min-w-0 truncate",children:ae.name}),e.jsx("span",{className:"chat-composer__header-meta shrink-0 text-[10px] uppercase tracking-[0.18em] text-muted-foreground",children:G?"current":"remote"})]}):e.jsx($e,{placeholder:"Select node"})}),e.jsx(Me,{children:Mn(Y,n)})]}),g?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{id:"task-title-composer",type:"text",value:j,onChange:ye=>A(ye.target.value),onKeyDown:ye=>{(ye.key==="Enter"||ye.key==="Escape")&&(ye.preventDefault(),$(!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(J,{type:"button",variant:"ghost",size:"icon",onClick:()=>$(!1),"aria-label":"Save title",className:"h-8 w-8 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(as,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>$(!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:Be||"Title","aria-label":Be?`Edit title: ${Be}`:"Edit title",children:[e.jsx("span",{className:"chat-composer__title-text max-w-[220px] truncate",children:Be||"Title"}),e.jsx(Ut,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx("textarea",{id:"task-description",ref:he,value:f,onChange:ye=>E(ye.target.value),onKeyDown:je,onPaste:oe,placeholder:"Ask anything...",rows:4,autoFocus:h,"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(vr,{agent:b,query:f,onSelect:ke}),e.jsx(jn,{query:f,quickChats:fe,selectedIndex:y,onActiveIndexChange:v,onSelect:Pe}),e.jsxs("div",{className:"chat-composer__rail flex min-w-0 flex-nowrap items-center gap-2 px-3 pb-3",children:[e.jsx(J,{type:"button",variant:"ghost",size:"icon",onClick:W,"aria-label":"Add images",className:"h-9 w-9 shrink-0 rounded-sm text-muted-foreground hover:text-foreground",children:e.jsx(An,{className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-border/60","aria-hidden":!0}),e.jsxs(De,{value:b,onValueChange:C,children:[e.jsxs(_e,{className:B(X,"chat-composer__icon-trigger",Fe?we:Re),title:`Agent: ${M}`,"aria-label":`Agent: ${M}`,children:[e.jsx($n,{agent:b}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:M})]}),e.jsx(Me,{children:mr()})]}),e.jsx(xo,{agent:b,value:T,onChange:P,chip:!0,triggerClassName:B(X,"chat-composer__icon-trigger",T?Re:we),contentClassName:"max-h-80 shadow-none"}),e.jsxs(De,{value:S,onValueChange:ye=>I(ye),children:[e.jsxs(_e,{className:B(X,"chat-composer__icon-trigger",Ee?we:Re),title:`Mode: ${ne}`,"aria-label":`Mode: ${ne}`,children:[e.jsx(cd,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label truncate",children:ne})]}),e.jsx(Me,{children:hr()})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2",children:[c&&e.jsxs(J,{type:"button",variant:"ghost",size:"sm",onClick:c,"aria-label":u,className:"chat-composer__cancel h-9 rounded-sm px-4 text-xs text-muted-foreground",children:[e.jsx(it,{className:"chat-composer__cancel-icon h-4 w-4 shrink-0"}),e.jsx("span",{className:"chat-composer__footer-label",children:u})]}),e.jsxs(J,{type:"submit",size:"icon",disabled:!et||V,className:"h-10 w-10 rounded-sm shadow-[0_8px_30px_-8px_hsl(var(--primary)/0.6)]",children:[V?e.jsx(de,{className:"h-4 w-4 animate-spin"}):e.jsx(ro,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:V?"Creating chat":p})]})]})]})]}),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(Ss,{value:_,onChange:D,assignTo:Z,nodes:t,assignableNodes:Y,layout:"composer",chipClassName:X,chipActiveClassName:ye,chipInactiveClassName:ye,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"}),e.jsx(wr,{value:F,onChange:Q,project:_,assignTo:Z,nodes:t,assignableNodes:Y,layout:"composer",chipClassName:X,chipActiveClassName:ye,chipInactiveClassName:ye,triggerClassName:"chat-composer__icon-trigger",labelClassName:"chat-composer__location-label"})]})})()})]})})(),(He||q)&&e.jsxs("div",{className:"space-y-2 rounded-sm border border-border/60 bg-background/45 p-2.5",children:[He,q&&e.jsx("div",{className:"text-[11px] text-destructive",children:q}),!q&&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:mt,className:B("space-y-4",d),children:[e.jsx("input",{ref:z,type:"file",accept:"image/*",multiple:!0,onChange:L,className:"hidden"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{htmlFor:"task-description",className:"text-[11px] font-medium",children:"Opening prompt"}),e.jsx("textarea",{id:"task-description",ref:he,value:f,onChange:X=>E(X.target.value),onKeyDown:je,onPaste:oe,placeholder:"Describe what the agent should do. This becomes the first message in the chat.",rows:6,autoFocus:h,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(vr,{agent:b,query:f,onSelect:ke}),e.jsx(jn,{query:f,quickChats:fe,selectedIndex:y,onActiveIndexChange:v,onSelect:Pe}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(J,{type:"button",variant:"outline",onClick:W,className:"rounded-sm",children:[e.jsx(An,{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."})]}),He,q&&e.jsx("p",{className:"text-[11px] text-destructive",children:q})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_170px_190px_150px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ke,{htmlFor:"task-title",className:"text-[11px] font-medium",children:"Chat title"}),e.jsx(ot,{id:"task-title",type:"text",value:j,onChange:X=>A(X.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:Be?`Will appear as: ${Be}`:"A title will be generated from the first line of the prompt."})]}),Oe,e.jsx(iu,{agent:b,value:T,onChange:P}),Ie]}),pt,ht,Ye,e.jsxs("div",{className:B("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",m),children:[c&&e.jsx(J,{type:"button",variant:"ghost",onClick:c,className:"rounded-sm",children:u}),e.jsx(J,{type:"submit",disabled:!et||V,className:"rounded-sm px-5",children:V?"Creating...":p})]})]})}function du({nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,defaultMode:d="chat",mode:m,onModeChange:p,layout:u="default",className:h,footerClassName:x,autoFocus:k=!1,quickChats:j=[]}){const[A,f]=o.useState(d),E=m!==void 0,y=E?m:A,v=b=>{E||f(b),p?.(b)};return e.jsxs("div",{className:B("space-y-4",h),children:[!E&&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(J,{type:"button",variant:y==="chat"?"default":"ghost",onClick:()=>v("chat"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(zi,{className:"h-4 w-4"}),"New chat"]}),e.jsxs(J,{type:"button",variant:y==="native"?"default":"ghost",onClick:()=>v("native"),className:"h-7 flex-1 rounded-sm shadow-none",children:[e.jsx(qn,{className:"h-4 w-4"}),"Load session"]})]}),y==="chat"?e.jsx(cu,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,initialAssignTo:a,initialProject:i,onCreated:l,onCancel:c,footerClassName:x,submitLabel:u==="composer"?"Start chat":"Create chat",cancelLabel:"Cancel",autoFocus:k,layout:u,quickChats:j},`${a??""}:${i??""}`):e.jsx(ou,{nodes:t,currentNodeRole:s,currentNodeId:n,leaderNodeId:r,onCreated:l,onCancel:c,footerClassName:x,autoFocus:k})]})}function uu({onClick:t,running:s}){return e.jsxs(J,{size:"icon",onClick:t,"aria-label":s?"Open composer - task running":"Open composer",title:s?"Task running - open composer":"Open composer",className:B("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(Ut,{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 jr({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 mu({hasVisibleTranscriptEvents:t,hasTranscriptProgress:s,inputCollapsed:n}){return{collapsedButtonRunning:s&&t&&n,showDockedProgress:s&&t&&!n,showInlineProgress:s&&!t}}const Lt="72f988bf-86f1-41af-91ab-2d7cd011db47",go=`${Lt} (MSIT)`;function hu({open:t,onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i=!1,shareResult:l}){return e.jsx(Ct,{open:t,onOpenChange:s,children:e.jsxs(Tt,{className:"max-w-md rounded-sm p-4",children:[e.jsx(zt,{className:"sr-only",children:"Share conversation"}),e.jsx(fu,{onOpenChange:s,onShare:n,onStopShare:r,sharing:a,stopping:i,shareResult:l})]})})}function fu({onOpenChange:t,onShare:s,onStopShare:n,sharing:r,stopping:a=!1,shareResult:i}){const[l,c]=o.useState(i?.tenant??Lt),[d,m]=o.useState(i?.scope??"chat"),p=i?.url?Ia(i.url):null,u=r||a;return o.useEffect(()=>{c(i?.tenant??Lt),m(i?.scope??"chat")},[i?.shareId,i?.tenant,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(xu,{value:l,onChange:c,disabled:u}),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(Nr,{active:d==="chat",title:"Chat only",description:"Conversation transcript and opening prompt.",onClick:()=>m("chat")}),e.jsx(Nr,{active:d==="filesPreview",title:"Chat, files and preview",description:"Transcript plus task output files and HTML preview.",onClick:()=>m("filesPreview")})]})]}),p&&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:p,className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-foreground outline-none","aria-label":"Shared link"}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 rounded-sm text-muted-foreground",onClick:()=>{Ts(p,"Shared link copied")},"aria-label":"Copy shared link",title:"Copy shared link",children:e.jsx(Ra,{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(J,{variant:"outline",onClick:()=>t(!1),disabled:u,className:"h-8 text-xs",children:i?"Done":"Cancel"}),i&&n&&e.jsxs(J,{variant:"outline",onClick:()=>{n()},disabled:u,className:"h-8 border-destructive/30 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive",children:[a&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),"Stop share"]}),e.jsxs(J,{onClick:()=>{s({tenant:l,scope:d})},disabled:u,className:"h-8 text-xs",children:[r&&e.jsx(de,{className:"h-3.5 w-3.5 animate-spin"}),i?"Update link":"Share link"]})]})]})}function xu({value:t,onChange:s,disabled:n}){const[r,a]=o.useState(!1),[i,l]=o.useState(!1),[c,d]=o.useState(t),m=o.useRef(null);o.useEffect(()=>{d(t)},[t]),o.useEffect(()=>{if(!r)return;const u=x=>{const k=x.target;k instanceof Node&&(m.current?.contains(k)||(a(!1),l(!1)))},h=x=>{x.key==="Escape"&&(a(!1),l(!1))};return document.addEventListener("mousedown",u),document.addEventListener("keydown",h),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",h)}},[r]);const p=u=>{const h=u.trim();h&&(s(h),d(h),l(!1),a(!1))};return e.jsxs("div",{className:"space-y-2 text-xs",ref:m,children:[e.jsx("div",{className:"font-medium text-foreground",children:"Tenant"}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>!n&&a(u=>!u),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:pu(t)}),e.jsx(Qe,{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:()=>p(Lt),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:go}),t===Lt&&e.jsx(as,{className:"h-3.5 w-3.5 shrink-0 text-primary"})]}),e.jsx("div",{className:"border-t border-border/60 bg-background/40 px-2.5 py-1.5",children:i?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:c,onChange:u=>d(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),p(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:()=>p(c),className:"flex h-7 w-7 items-center justify-center rounded-sm hover:bg-background/60",children:e.jsx(as,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{d(t),l(!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(it,{className:"h-3.5 w-3.5"})})]}):e.jsxs("button",{type:"button",onClick:()=>l(!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(Ut,{className:"h-3 w-3"})]})})]})]})]})}function pu(t){return t===Lt?go:t}function Nr({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 gu(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 bu({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(Jc,{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 a=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:gu(n.content)}),a.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:a.map((i,l)=>e.jsx(Ga,{image:i,alt:i.filename??`queued attachment ${l+1}`,thumbnailClassName:"h-14 w-14 border border-border/65",imageClassName:"h-full w-full"},`${i.filename??"image"}-${l}`))})]}),s&&e.jsx(J,{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(it,{className:"h-3 w-3"})})]},n.id)})})]})})}const vu="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",wu=[{value:"transcript",label:"Transcript",icon:$i},{value:"files",label:"Files",icon:Ft,activeIcon:Ms},{value:"diff",label:"Diff",icon:js},{value:"preview",label:"Preview",icon:jc}];function yu({activeTab:t}){return e.jsx(Bn,{className:"h-auto max-w-full justify-start gap-2 overflow-x-auto rounded-sm !bg-muted/40 !p-0.5 !shadow-none",children:wu.map(s=>{const n=s.value===t&&s.activeIcon?s.activeIcon:s.icon;return e.jsx(kt,{value:s.value,title:s.label,"aria-label":s.label,className:vu,children:e.jsx(n,{className:"h-3.5 w-3.5","aria-hidden":"true"})},s.value)})})}const bo="pointer-events-auto h-5 w-5 shrink-0 rounded-sm bg-muted/65 text-muted-foreground hover:bg-muted hover:text-foreground",Cs="h-3.5 w-3.5";function Pn({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,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(vo,{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(wo,{operationsOpen:r,onToggleOperations:a,className:"xl:hidden"})]})}function vo({className:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:r}){const a=globalThis.window?.matchMedia("(min-width: 1024px)")?.matches?s:n;return e.jsx(J,{variant:"ghost",size:"icon",onClick:r,title:a?"Hide tasks":"Show tasks","aria-label":a?"Hide tasks":"Show tasks",className:B(bo,t),children:a?e.jsx(ys,{className:Cs}):e.jsx(Xe,{className:Cs})})}function wo({className:t,operationsOpen:s,onToggleOperations:n}){return e.jsx(J,{variant:"ghost",size:"icon",onClick:n,title:s?"Hide cluster":"Show cluster","aria-label":s?"Hide cluster":"Show cluster",className:B(bo,t),children:s?e.jsx(Xe,{className:Cs}):e.jsx(ys,{className:Cs})})}const kr="h-7 w-7 rounded-sm border-0 bg-primary/10 text-primary backdrop-blur hover:bg-primary/20 hover:text-primary";function ju({active:t,onScrollToBottom:s,onScrollToTop:n}){return e.jsxs("div",{className:B("pointer-events-none absolute right-3 top-1/2 z-10 flex -translate-y-1/2 flex-col gap-2 opacity-0 transition-opacity duration-200 group-hover:pointer-events-auto group-hover:opacity-100",t&&"pointer-events-auto opacity-100"),children:[e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:kr,onClick:n,"aria-label":"Scroll to top",title:"Scroll to top",children:e.jsx(qi,{className:"h-4 w-4"})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",className:kr,onClick:s,"aria-label":"Scroll to bottom",title:"Scroll to bottom",children:e.jsx(Qe,{className:"h-4 w-4"})})]})}const Sr="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",Nt={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:`${Sr} mt-0`,action:Sr},Nu=30,ku=1600;function Su({savedScrollTop:t,scrollHeight:s,clientHeight:n}){const r=Math.max(0,s-n);return Math.min(Math.max(0,t??r),r)}function Ks(t){return t.scrollHeight-t.scrollTop-t.clientHeight<Nu}function Cr({explicitBottomStickUntil:t,now:s,wasAtBottom:n}){return n||t>s}function Gs(t,s){return!!(s&&(t===s||t.contains(s)))}function Ws(t){const s=t.ownerDocument.getSelection();if(!s||s.isCollapsed||s.rangeCount===0)return!1;if(Gs(t,s.anchorNode)||Gs(t,s.focusNode))return!0;for(let n=0;n<s.rangeCount;n+=1)if(Gs(t,s.getRangeAt(n).commonAncestorContainer))return!0;return!1}function Cu({atTop:t,inputCollapseDisabled:s,scrollingUp:n}){return!s&&(n||t)}function Tu({activeTab:t,activeTaskId:s,contentVersion:n,inputCollapseDisabled:r=!1,setActiveTab:a,setInputCollapsed:i}){const l=o.useRef(null),c=o.useRef(s),d=o.useRef(!1),m=o.useRef(0),p=o.useRef(new Map),u=o.useRef(0),h=o.useRef(!0),x=o.useCallback((v=c.current)=>{const b=l.current;!b||!v||(p.current.set(v,b.scrollTop),m.current=b.scrollTop,h.current=Ks(b))},[]),k=o.useCallback((v=c.current)=>{const b=l.current;!b||!v||(b.scrollTop=Su({savedScrollTop:p.current.get(v),scrollHeight:b.scrollHeight,clientHeight:b.clientHeight}),m.current=b.scrollTop,h.current=Ks(b))},[]),j=o.useCallback((v,b=c.current)=>{v.scrollTop=v.scrollHeight,m.current=v.scrollTop,h.current=!0,b&&p.current.set(b,v.scrollTop)},[]),A=o.useCallback((v=c.current)=>{const b=l.current;u.current=Date.now()+ku,b&&(j(b,v),requestAnimationFrame(()=>{j(b,v),requestAnimationFrame(()=>j(b,v))}))},[j]),f=o.useCallback((v=c.current)=>{const b=l.current;u.current=0,b&&(b.scrollTop=0,m.current=0,h.current=!1,v&&p.current.set(v,0))},[]),E=o.useCallback(v=>{const b=v.currentTarget,C=m.current,T=b.scrollTop<C&&C-b.scrollTop>10,P=b.scrollTop<=0,S=Ws(b);if(x(),S){u.current=0;return}if(!d.current){if(Ks(b)){i(!1),d.current=!0,setTimeout(()=>{d.current=!1},300);return}(T||P)&&(u.current=0,Cu({atTop:P,inputCollapseDisabled:r,scrollingUp:T})&&i(!0))}},[r,x,i]),y=o.useCallback(v=>{t==="transcript"&&x(),a(v),v==="transcript"&&requestAnimationFrame(()=>k())},[t,k,x,a]);return o.useLayoutEffect(()=>{r&&i(!1)},[r,i]),o.useLayoutEffect(()=>{const v=c.current;v&&v!==s&&x(v),c.current=s,t==="transcript"&&requestAnimationFrame(()=>k(s))},[s,t,k,x]),o.useLayoutEffect(()=>{const v=l.current;if(!v||t!=="transcript"||!s)return;const b=Cr({explicitBottomStickUntil:u.current,now:Date.now(),wasAtBottom:h.current});if(Ws(v)){u.current=0,x(s);return}b&&j(v,s),x(s)},[s,t,n,x,j]),o.useLayoutEffect(()=>{const v=l.current,b=v?.firstElementChild;if(!v||!b||t!=="transcript"||typeof ResizeObserver>"u")return;const C=new ResizeObserver(()=>{if(Ws(v)){u.current=0,x();return}Cr({explicitBottomStickUntil:u.current,now:Date.now(),wasAtBottom:h.current})?j(v):x()});return C.observe(v),C.observe(b),()=>C.disconnect()},[t,s,x,j]),{handleTranscriptScroll:E,handleTranscriptTabChange:y,scrollTranscriptToBottom:A,scrollTranscriptToTop:f,transcriptScrollRef:l}}function yo(t=700){const[s,n]=o.useState(!1),r=o.useRef(null),a=o.useCallback(()=>{n(!0),r.current!==null&&clearTimeout(r.current),r.current=setTimeout(()=>{n(!1),r.current=null},t)},[t]);return o.useEffect(()=>()=>{r.current!==null&&clearTimeout(r.current)},[]),{markScrollbarActive:a,scrollbarActive:s}}const Eu=o.lazy(async()=>({default:(await Fn(()=>import("./FilesTab-BlJn83X5.js"),__vite__mapDeps([0,1,2,3,4,5]))).FilesTab})),Au=o.lazy(async()=>({default:(await Fn(()=>import("./PreviewTab-C7vB52yS.js").then(s=>s.c),__vite__mapDeps([6,1,2]))).PreviewTab})),Du=o.lazy(async()=>({default:(await Fn(()=>import("./DiffTab-Bz1OAlIg.js"),__vite__mapDeps([7,1,2,5,4,3,6]))).DiffTab}));function _u({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,activeTab:l,setActiveTab:c,creatingTask:d,createMode:m,createDefaults:p,activeTask:u,assignedNode:h,taskLoading:x,transcriptLoading:k,taskError:j,displayEvents:A,initialPromptAlreadyInLogs:f,initialPrompt:E,supportsFollowUp:y,taskUnavailable:v,chatDisabled:b,chatDisabledReason:C,questionBypassEnabled:T,isRunning:P,isStarting:S,hasPendingFollowUp:I,canCancel:_,canRetry:D,onRetry:R,onCancel:F,onReloadNativeTranscript:Q,onShareTask:Y,onStopShareTask:ee,onStartCreateTask:Z,onCancelCreateTask:te,onCreateTask:V,onSendMessage:O,onCancelQueuedMessage:g,onQuestionBypassChange:$,onSubmitQuestionResponse:N,quickChats:q=[]}){const[z,W]=o.useState(!1),[L,oe]=o.useState(!1),[ie,he]=o.useState(!1),[ae,G]=o.useState(!1),[M,ne]=o.useState(!1),[H,re]=o.useState({}),[ve,fe]=o.useState(new Set),[Pe,ke]=o.useState(new Set),[mt,Be]=o.useState(null),et=u?.effectiveProjectPath??u?.project??"default workspace",je=u?h?.name??Nn(u.assignedTo,i?.nodes,u.assignedNodeName):"unassigned",He=u?.assignedTo?e.jsxs(e.Fragment,{children:["Connecting session on node ",e.jsx("span",{className:"font-semibold",children:je}),"..."]}):"Connecting session to an available node...",Ye=u?[{label:"Working dir",value:et,mono:!0},...u.branch?[{label:"Branch",value:u.branch,mono:!0}]:[],{label:"Agent",value:u.agent,mono:!0},{label:"Node",value:je}]:[],Oe=!!(E&&!f),Ie=Oe||A.length>0,pt=P&&Ie,ht=(S||I||P)&&!pt,X=pt?"The agent is still working on this conversation.":ht?He:null,{collapsedButtonRunning:we,showDockedProgress:Re,showInlineProgress:Fe}=mu({hasTranscriptProgress:!!X,hasVisibleTranscriptEvents:Ie,inputCollapsed:z}),Ee=u?.conversationKind==="nativeSession",ye=mc(u),Se=k?"Loading transcript":Ee?"No transcript imported":"Transcript is warming up",Dt=k?"Loading transcript...":Ee?"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.",_t=u?.queuedMessages??[],ft=o.useMemo(()=>hc(A),[A]),K=o.useMemo(()=>ft.findIndex(({event:pe})=>Mu(pe)),[ft]),Le=o.useMemo(()=>fc("transcript",ft.map(pe=>pe.event)),[ft]),Ce=u&&!ve.has(u.id)?H[u.id]??u.activeShare??null:null,xt=u?.id??null,qt=`${xt??"none"}:${A.length}:${_t.length}:${Oe?1:0}:${k?1:0}:${Fe?1:0}`,{handleTranscriptScroll:Mt,handleTranscriptTabChange:Ae,scrollTranscriptToBottom:qe,scrollTranscriptToTop:wt,transcriptScrollRef:yt}=Tu({activeTab:l,activeTaskId:xt,contentVersion:qt,inputCollapseDisabled:!!X,setActiveTab:c,setInputCollapsed:W}),{markScrollbarActive:tt,scrollbarActive:jt}=yo(),ze=o.useCallback(pe=>{tt(),Mt(pe)},[Mt,tt]),lt=o.useCallback(pe=>{Be(ge=>({path:pe,requestId:(ge?.requestId??0)+1})),Ae("files")},[Ae]),Ne=o.useCallback(pe=>{qe(),O(pe)},[O,qe]);return o.useEffect(()=>{Be(null)},[xt]),d?e.jsx(Pu,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,defaultMode:m,createDefaults:p,onCancel:te,onCreated:V,quickChats:q}):!u&&x?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(Pn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a})}),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(de,{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(de,{className:"h-3.5 w-3.5 animate-spin"}),"Fetching the selected chat thread..."]})]})]})})]}):u?e.jsxs(On,{value:l,onValueChange:Ae,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(vo,{desktopTasksOpen:s,mobileTasksPanelOpen:n,onToggleTasks:t,className:"lg:hidden"}),e.jsx(wo,{operationsOpen:r,onToggleOperations:a,className:"xl:hidden"})]}),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:u.title,children:u.title}),e.jsx(La,{status:u.status,isNative:Ee}),ye&&e.jsxs("span",{"data-task-goal-label":"true",title:"Codex goal",className:"inline-flex h-5 shrink-0 items-center gap-1 rounded-sm bg-primary/10 px-1.5 text-[9px] font-semibold uppercase tracking-[0.12em] text-primary",children:[e.jsx(Ya,{className:"h-3 w-3","aria-hidden":"true"}),"Goal"]}),u.priority!=="normal"&&e.jsx(Hi,{priority:u.priority})]}),j&&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:j}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 pl-5 sm:pl-6 lg:pl-0",children:[e.jsx(yu,{activeTab:l}),v&&e.jsx(Ve,{variant:"outline",className:"hidden rounded-sm border-destructive/25 bg-destructive/10 text-destructive sm:inline-flex",children:"Unavailable"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"hidden rounded-sm bg-muted/65 px-1.5 py-0.5 tabular-nums sm:inline-flex",children:Ki(u.updatedAt)}),D&&e.jsxs(J,{variant:"ghost",size:"sm",onClick:R,"aria-label":"Retry task",title:"Retry task",className:"h-7 shrink-0 rounded-sm border-0 bg-primary/10 px-2 text-[10px] text-primary shadow-none hover:bg-primary/15 hover:text-primary",children:[e.jsx(rd,{className:"h-3.5 w-3.5"}),"Retry"]}),Ee&&Q&&e.jsx(J,{variant:"ghost",size:"icon",onClick:Q,disabled:k,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(no,{className:B("h-3.5 w-3.5",k&&"animate-spin")})}),e.jsx(J,{type:"button",variant:"ghost",size:"icon",disabled:v,title:v?"Unavailable tasks cannot be shared.":"Share conversation","aria-label":v?"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:()=>he(!0),children:e.jsx(ks,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsx(ut,{value:"transcript",className:"mt-0 min-h-0 flex-1",children:e.jsxs("div",{className:"group 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:yt,"data-transcript-scroll":"true",className:B("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",jt&&"scrollbar-line-active"),onScroll:ze,children:e.jsxs("div",{"data-transcript-scroll-content":"true",className:"mx-auto flex max-w-[72rem] flex-col gap-4",children:[Oe&&E&&e.jsx(fr,{event:E,agent:u.agent,sentAsGoal:ye,taskRootPath:u.effectiveProjectPath,onOpenFilePath:lt,questionBypassEnabled:T,onQuestionBypassChange:$,onSubmitQuestionResponse:N,questionResponseDisabled:!y||b}),ft.map(({event:pe,subItems:ge},Ge)=>e.jsx(fr,{event:pe,agent:u.agent,subItems:ge,sentAsGoal:ye&&!Oe&&Ge===K,taskRootPath:u.effectiveProjectPath,onOpenFilePath:lt,questionBypassEnabled:T,onQuestionBypassChange:$,onSubmitQuestionResponse:N,questionResponseDisabled:!y||b},Le[Ge])),!Ie&&!ht&&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:Se}),e.jsx("div",{className:"mt-2 text-[11px] leading-6 text-muted-foreground",children:Dt})]}),(!y&&u.result||u.error)&&e.jsxs("div",{className:"space-y-3",children:[!y&&u.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(u.result,null,2)})]}),u.error&&!Pe.has(u.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:()=>ke(pe=>new Set(pe).add(u.id)),className:"rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(it,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"mt-3 overflow-x-auto whitespace-pre-wrap text-[11px] leading-5",children:u.error})]})]}),Fe&&X&&e.jsx(jr,{children:X})]})})}),e.jsx(ju,{active:jt,onScrollToBottom:()=>qe(),onScrollToTop:()=>wt()}),Re&&X&&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(jr,{children:X})})}),y?e.jsxs(e.Fragment,{children:[z&&e.jsx(uu,{running:we,onClick:()=>{W(!1),qe(),requestAnimationFrame(()=>document.querySelector('[data-chat-input-textarea="true"]')?.focus())}}),e.jsxs("div",{className:`shrink-0 ${z?"hidden":""}`,children:[e.jsx(bu,{messages:_t,onCancelMessage:g}),e.jsx(Pd,{onSend:Ne,disabled:b,disabledReason:C,contextItems:Ye,agent:u.agent,model:typeof u.payload.model=="string"?u.payload.model:null,placeholder:b?C:P?"Queue a message for the next turn...":"Continue the conversation...",running:P||I,onStop:_?()=>oe(!0):void 0,quickChats:q})]})]}):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(ut,{value:"files",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading files..."}),children:e.jsx(Eu,{taskId:u.id,requestedFilePath:mt?.path??null,requestedFileRequestId:mt?.requestId??0})})}),e.jsx(ut,{value:"preview",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading preview..."}),children:e.jsx(Au,{taskId:u.id})})}),e.jsx(ut,{value:"diff",className:"mt-0 min-h-0 flex-1 overflow-hidden",children:e.jsx(o.Suspense,{fallback:e.jsx(qs,{label:"Loading diff..."}),children:e.jsx(Du,{taskId:u.id})})}),e.jsx(Yt,{open:L,onOpenChange:oe,children:e.jsxs(Jt,{className:Nt.content,children:[e.jsxs(Zt,{className:Nt.header,children:[e.jsx(Xt,{className:Nt.title,children:"Stop this task?"}),e.jsx(es,{className:Nt.description,children:"The task will stop and move to a cancelled state."})]}),e.jsxs(ts,{className:Nt.footer,children:[e.jsx(ss,{className:Nt.cancel,children:"Keep running"}),e.jsx(ns,{className:Nt.action,onClick:F,children:"Stop task"})]})]})}),e.jsx(hu,{open:ie,onOpenChange:he,sharing:ae,stopping:M,shareResult:Ce,onShare:async pe=>{if(!u)return null;G(!0);try{const ge=await Y(pe);return ge?.url&&(re(Ge=>({...Ge,[u.id]:ge})),fe(Ge=>{const ct=new Set(Ge);return ct.delete(u.id),ct})),ge}finally{G(!1)}},onStopShare:async()=>{if(!u)return!1;ne(!0);try{const pe=await ee();return pe!==!1&&(re(ge=>{const Ge={...ge};return delete Ge[u.id],Ge}),fe(ge=>new Set(ge).add(u.id))),pe}finally{ne(!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(Pn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a})}),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(Vi,{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(J,{onClick:()=>Z(),className:"mt-4 h-8 rounded-sm px-3",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),"Start or load chat"]}),j&&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:j})]})})]})}function Mu(t){return t.type!=="user"||t.isMeta===!0||t.isSidechain===!0?!1:!!Cn(t)?.some(n=>n.type==="text"||n.type==="image")}function Pu({onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,cluster:i,defaultMode:l,createDefaults:c,onCancel:d,onCreated:m,quickChats:p}){const[u,h]=o.useState(l??"chat");o.useEffect(()=>{l&&h(l)},[l]);const x=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:Ps},{value:"native",label:"Load session",icon:qn}].map(k=>{const j=k.icon,A=k.value===u;return e.jsxs("button",{type:"button",onClick:()=>h(k.value),"aria-pressed":A,className:B("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",A?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:[e.jsx(j,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:k.label})]},k.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(Pn,{onToggleTasks:t,desktopTasksOpen:s,mobileTasksPanelOpen:n,operationsOpen:r,onToggleOperations:a,centerSlot:x})}),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(du,{nodes:i?.nodes??[],currentNodeRole:i?.self?.role,currentNodeId:i?.self?.id??null,leaderNodeId:i?.leader?.id??null,initialAssignTo:c?.assignTo,initialProject:c?.project,mode:u,onModeChange:h,onCreated:m,onCancel:d,autoFocus:!0,layout:"composer",quickChats:p})})})]})}function Iu({onAdded:t}){const[s,n]=o.useState(""),[r,a]=o.useState(!1),[i,l]=o.useState(null),c=o.useCallback(async d=>{if(d.preventDefault(),!!s.trim()){a(!0),l(null);try{await Gi({leaderEndpoint:s.trim(),transport:"devtunnel"}),t()}catch(m){l(m instanceof Error?m.message:"Failed to join node")}finally{a(!1)}}},[s,t]);return e.jsx(Tt,{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(Es,{className:"space-y-1 text-left",children:[e.jsx(zt,{className:"text-sm tracking-tight",children:"Join node"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Verify the remote leader's DevTunnel Node URL, 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(Ke,{htmlFor:"leader-endpoint",children:"Leader Node URL"}),e.jsx(Ve,{variant:"outline",className:"rounded-sm border-border/70 bg-background/60 text-[10px] uppercase tracking-[0.16em]",children:"DevTunnel only"})]}),e.jsx(ot,{id:"leader-endpoint",type:"url",value:s,onChange:d=>n(d.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(Ba,{className:"border-t border-border/60 pt-3",children:e.jsx(J,{type:"submit",disabled:!s.trim()||r,className:"rounded-sm",children:r?"Joining...":"Join node"})})]})]})})}function Ru({open:t,onOpenChange:s,onAdded:n}){return e.jsx(Ct,{open:t,onOpenChange:s,children:e.jsx(Iu,{onAdded:()=>{s(!1),n()}})})}const Lu="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",Bu="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",Ou="h-2.5 w-2.5";function jo({className:t,label:s,orientation:n,panel:r,panelResize:a}){return e.jsx("button",{type:"button","aria-label":s,"aria-orientation":n,"data-dashboard-resize-handle":r,onPointerDown:i=>a.onPointerDown(r,i),onWheel:i=>a.onWheel(r,i),className:B("group absolute z-20 hidden touch-none rounded-sm bg-transparent outline-none transition-colors hover:bg-primary/12 focus-visible:bg-primary/12 focus-visible:ring-2 focus-visible:ring-ring/70 lg:block",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 Fu({className:t,label:s,onToggle:n,side:r,visible:a}){const i=r==="left"?a?ys:Xe:a?Xe:ys;return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:n,className:B(Lu,t),children:e.jsx("span",{className:Bu,"aria-hidden":"true",children:e.jsx(i,{className:Ou,strokeWidth:2.1})})})}function Tr({className:t,label:s,onToggle:n,panel:r,panelResize:a,screen:i,side:l,visible:c}){const d=i==="lg"?"lg:block":"xl:block",m=i==="lg"?"lg:flex":"xl:flex";return e.jsxs("div",{className:B("group absolute top-0 z-30 hidden h-full w-4",d,t),children:[r&&e.jsx(jo,{panel:r,orientation:"vertical",label:`Resize ${r} panel`,panelResize:a,className:"left-1/2 top-0 h-full w-2 -translate-x-1/2 cursor-col-resize"}),e.jsx(Fu,{side:l,visible:c,label:s,onToggle:n,className:B(m,"left-1/2 -translate-x-1/2 group-hover:opacity-100")})]})}function zu({conversationPanel:t,desktopTasksOpen:s,mobileTaskSidebar:n,mobileTasksPanelOpen:r,mobileTasksPanelRef:a,operationsOpen:i,operationsPanelRef:l,operationsSidecar:c,panelResize:d,taskSidebar:m,terminalPanel:p,onCloseOperations:u,onCloseTaskList:h,onToggleOperations:x,onToggleTasks:k}){const j={"--dashboard-tasks-width":d.sizes.tasks,"--dashboard-operations-width":d.sizes.operations,"--dashboard-terminal-height":d.sizes.terminal};return e.jsxs("div",{className:"dashboard-workspace flex h-full min-h-0 flex-col overflow-hidden",style:j,children:[e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[e.jsx(Tr,{screen:"lg",side:"left",visible:s,label:s?"Hide tasks":"Show tasks",onToggle:k,panel:s?"tasks":void 0,panelResize:d,className:s?"left-[var(--dashboard-tasks-width)] -translate-x-1/2":"left-0"}),e.jsx("div",{className:B("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&&m}),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}),p&&e.jsxs("div",{className:"relative h-[var(--dashboard-terminal-height)] min-h-0 shrink-0",children:[e.jsx(jo,{panel:"terminal",orientation:"horizontal",label:"Resize terminal panel",panelResize:d,className:"-top-1 left-0 h-2 w-full cursor-row-resize"}),p]})]}),e.jsx(Tr,{screen:"xl",side:"right",visible:i,label:i?"Hide cluster":"Show cluster",onToggle:x,panel:i?"operations":void 0,panelResize:d,className:i?"right-[var(--dashboard-operations-width)] translate-x-1/2":"right-0"}),e.jsx("div",{className:B("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:u,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm xl:hidden"}),e.jsx("div",{ref:l,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:h,className:"fixed inset-0 z-30 bg-black/45 backdrop-blur-sm lg:hidden"}),e.jsx("div",{ref:a,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 Uu=10,St="__all__";function Je(t){return"session"in t}function Er(t,s){return s&&t.some(n=>n.id===s)?s:t[0]?.id??""}function Qs(t){return t&&(ho(t.id)||t.workDir)||""}function fs(t,s,n){let r=!1;const a=t.map(i=>Je(i)&&i.session.id===n.id?(r=!0,{...i,nodeName:s,session:n}):i);return In(r?a:[...a,{id:`session-${n.id}`,nodeName:s,session:n}])}function No(t,s){return t.filter(Je).filter(n=>n.session.nodeId===s).sort((n,r)=>r.session.startedAt-n.session.startedAt)}function $u(t){const s=t.filter(Je).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 qu(t,s){return!!(t&&s&&!t.contains(s))}function Vu(t,s,n){if(n===St)return n;const r=No(t,s);return r.some(a=>a.session.id===n)?n:r[0]?.session.id??St}function Hu(t,s,n){return n===St?t.filter(r=>!Je(r)||r.session.nodeId===s):t.filter(r=>Je(r)&&r.session.nodeId===s&&r.session.id===n)}function In(t){const s=t.map((r,a)=>({entry:r,index:a})).filter(({entry:r})=>Je(r)&&r.session.status!=="running").sort((r,a)=>!Je(r.entry)||!Je(a.entry)?0:a.entry.session.startedAt-r.entry.session.startedAt||a.index-r.index),n=new Set(s.slice(0,Uu).map(({entry:r})=>Je(r)?r.session.id:""));return t.filter(r=>!Je(r)||r.session.status==="running"||n.has(r.session.id))}function Rn(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 Ku(t){const s=t.session.command.length>48?`${t.session.command.slice(0,45)}...`:t.session.command;return`${t.nodeName} - ${Rn(t.session)} - ${s}`}function ko(t,s=48){return t.length>s?`${t.slice(0,s-3)}...`:t}function Gu(t,s){return s===St?"All sessions":t?ko(t.session.command,34):"Command session"}function Ar(t){return t.status==="stopped"?"":t.stderr}function Wu({nodes:t,defaultNodeId:s,onClose:n,initialHistory:r=[]}){const[a,i]=o.useState(()=>Er(t,s)),l=o.useMemo(()=>t.find(N=>N.id===a)??t[0]??null,[t,a]),[c,d]=o.useState(()=>Qs(l)),[m,p]=o.useState(""),[u,h]=o.useState(()=>In(r)),[x,k]=o.useState(St),[j,A]=o.useState(!1),[f,E]=o.useState(!1),[y,v]=o.useState(!1),[b,C]=o.useState(!1),[T,P]=o.useState(!1),S=o.useRef(null),I=o.useRef(null),_=o.useMemo(()=>t.find(N=>N.id===a)??t[0]??null,[t,a]),D=o.useMemo(()=>No(u,_?.id??""),[u,_]),R=o.useMemo(()=>$u(D),[D]),F=o.useMemo(()=>D.find(N=>N.session.id===x),[x,D]),Q=o.useMemo(()=>Hu(u,_?.id??"",x),[u,_,x]),Y=o.useRef(_?.id??"");o.useEffect(()=>{a&&t.some(N=>N.id===a)||i(Er(t,s))},[s,t,a]),o.useEffect(()=>{const N=_?.id??"";Y.current!==N&&(Y.current=N,d(Qs(_)))},[_]),o.useEffect(()=>{k(N=>Vu(u,_?.id??"",j?N:""))},[u,_,j]),o.useEffect(()=>{S.current?.scrollTo({top:S.current.scrollHeight})},[u]),o.useEffect(()=>{let N=!1;async function q(){const z=await Promise.allSettled(t.map(async W=>({node:W,response:await Qi(W.id)})));N||h(W=>z.reduce((L,oe)=>oe.status!=="fulfilled"?L:oe.value.response.sessions.reduce((ie,he)=>fs(ie,oe.value.node.name,he),L),W))}return t.length>0&&q(),()=>{N=!0}},[t]),o.useEffect(()=>{const N=u.filter(Je).filter(z=>z.session.status==="running");if(N.length===0)return;const q=window.setInterval(()=>{for(const z of N)Wi(z.session.nodeId,z.session.id).then(W=>h(L=>fs(L,z.nodeName,W))).catch(()=>{})},1e3);return()=>window.clearInterval(q)},[u]);const ee=o.useRef(null);async function Z(N){if(N.preventDefault(),!_||!m.trim()||T)return;const q=m.trim(),z=_.name;P(!0),p("");try{const W=await Ji(_.id,{command:q,...c.trim()?{cwd:c.trim()}:{}});h(L=>fs(L,z,W)),k(W.id),A(!0)}catch(W){h(L=>[...L,{id:`${Date.now()}-${Math.random().toString(16).slice(2)}`,nodeName:z,command:q,error:W instanceof Error?W.message:"Command failed"}])}finally{P(!1)}}async function te(N,q){N.stopPropagation();const z=await Yi(q.session.nodeId,q.session.id);h(W=>fs(W,q.nodeName,z))}function V(N){k(N),A(!0),E(!1)}function O(N){f&&qu(I.current,N.target)&&E(!1)}function g(N,q,z,W,L){return e.jsxs("div",{className:"border-t border-border/60 py-1",children:[e.jsxs("button",{type:"button",onClick:W,"aria-label":`Toggle ${N} sessions`,"aria-expanded":!z,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:N}),e.jsx(Qe,{className:B("h-3 w-3 transition-transform",z&&"-rotate-90")})]}),!z&&(q.length>0?q.map($):e.jsx("div",{className:"node-terminal__control px-2 py-1 text-muted-foreground",children:L}))]})}function $(N){const q=x===N.session.id,z=N.session.status==="running";return e.jsxs("div",{className:B("node-terminal__control group flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65",q&&"bg-primary/10 text-primary"),children:[e.jsxs("button",{type:"button",onClick:()=>V(N.session.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",children:[e.jsx("span",{className:B("flex h-4 w-4 shrink-0 items-center justify-center",z?"text-primary":N.session.status==="exited"?"text-emerald-600 dark:text-emerald-300":"text-amber-600 dark:text-amber-300"),children:z?e.jsx(de,{className:"h-3 w-3 animate-spin"}):N.session.status==="exited"?e.jsx(ar,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-foreground",children:ko(N.session.command,44)}),e.jsxs("span",{className:"node-terminal__small block truncate text-muted-foreground",children:[N.nodeName," · ",Rn(N.session)]})]})]}),z&&e.jsx("button",{type:"button",onClick:W=>{te(W,N)},"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(pr,{className:"h-3 w-3"})})]},N.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:O,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(it,{className:"h-3.5 w-3.5"})}):e.jsx(rr,{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:I,className:"relative min-w-0",children:[e.jsxs("button",{type:"button","aria-label":"Command session","aria-expanded":f,title:F?Ku(F):"All sessions",onClick:()=>E(N=>!N),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:Gu(F,x)}),e.jsx(Qe,{className:B("h-3 w-3 shrink-0 text-muted-foreground transition-transform",f&&"rotate-180")})]}),e.jsx("div",{"aria-hidden":!f,className:B("absolute right-0 bottom-9 z-30 w-[19rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-xl",!f&&"hidden"),children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsxs("button",{type:"button",onClick:()=>V(St),className:B("node-terminal__control flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70",x===St&&"bg-primary/10 text-primary"),children:[e.jsx(rr,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:"All sessions"})]}),g("Active",R.active,y,()=>v(N=>!N),"No active sessions"),g("Completed",R.completed,b,()=>C(N=>!N),"No completed sessions")]})})]}),e.jsx("select",{value:_?.id??"",onChange:N=>{i(N.target.value),A(!1),d(Qs(t.find(q=>q.id===N.target.value)??null))},disabled:T||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(N=>e.jsx("option",{value:N.id,className:"bg-background text-foreground",children:N.name},N.id))}),e.jsx(Ss,{value:c,onChange:d,assignTo:_?.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:S,className:"node-terminal__body min-h-0 flex-1 overflow-y-auto bg-muted/22 px-3 py-2 font-mono cursor-text",onClick:()=>ee.current?.focus(),children:[Q.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:Q.map(N=>Je(N)?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:[N.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:N.session.command}),e.jsxs("span",{className:B("inline-flex items-center gap-1",N.session.status==="running"||N.session.status==="exited"?"text-primary":"text-amber-600 dark:text-amber-300"),children:[N.session.status==="running"?e.jsx(de,{className:"h-3 w-3 animate-spin"}):N.session.status==="exited"?e.jsx(ar,{className:"h-3 w-3"}):e.jsx(Us,{className:"h-3 w-3"}),Rn(N.session)]}),N.session.status==="running"&&e.jsx("button",{type:"button",onClick:q=>{te(q,N)},"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(pr,{className:"h-3 w-3"})})]}),N.session.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-foreground",children:N.session.stdout}),Ar(N.session)&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:Ar(N.session)}),(N.session.stdoutTruncated||N.session.stderrTruncated)&&e.jsx("div",{className:"text-muted-foreground",children:"Output truncated to the latest output."})]},N.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:[N.nodeName,"$"]}),e.jsx("span",{className:"break-all text-foreground",children:N.command}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-destructive",children:[e.jsx(Us,{className:"h-3 w-3"}),"error"]})]}),e.jsx("pre",{className:"whitespace-pre-wrap break-words text-destructive",children:N.error})]},N.id))}),e.jsxs("form",{onSubmit:Z,className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0 text-primary select-none",children:_?`${_.name}$`:"$"}),e.jsx("input",{ref:ee,value:m,onChange:N=>p(N.target.value),disabled:!_||T,placeholder:_?"":"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:!_||!m.trim()||T,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-md text-primary transition-colors hover:bg-muted/65 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/70 disabled:pointer-events-none disabled:text-muted-foreground disabled:opacity-50",children:T?e.jsx(de,{className:"h-3 w-3 animate-spin"}):e.jsx(_s,{className:"h-3 w-3"})})]})]})]})})}var Rt={},Ys,Dr;function Qu(){return Dr||(Dr=1,Ys=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Ys}var Js={},bt={},_r;function Et(){if(_r)return bt;_r=1;let t;const s=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return bt.getSymbolSize=function(r){if(!r)throw new Error('"version" cannot be null or undefined');if(r<1||r>40)throw new Error('"version" should be in range from 1 to 40');return r*4+17},bt.getSymbolTotalCodewords=function(r){return s[r]},bt.getBCHDigit=function(n){let r=0;for(;n!==0;)r++,n>>>=1;return r},bt.setToSJISFunction=function(r){if(typeof r!="function")throw new Error('"toSJISFunc" is not a valid function.');t=r},bt.isKanjiModeEnabled=function(){return typeof t<"u"},bt.toSJIS=function(r){return t(r)},bt}var Zs={},Mr;function Kn(){return Mr||(Mr=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function s(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+n)}}t.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},t.from=function(r,a){if(t.isValid(r))return r;try{return s(r)}catch{return a}}})(Zs)),Zs}var Xs,Pr;function Yu(){if(Pr)return Xs;Pr=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(s){const n=Math.floor(s/8);return(this.buffer[n]>>>7-s%8&1)===1},put:function(s,n){for(let r=0;r<n;r++)this.putBit((s>>>n-r-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(s){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),s&&(this.buffer[n]|=128>>>this.length%8),this.length++}},Xs=t,Xs}var en,Ir;function Ju(){if(Ir)return en;Ir=1;function t(s){if(!s||s<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=s,this.data=new Uint8Array(s*s),this.reservedBit=new Uint8Array(s*s)}return t.prototype.set=function(s,n,r,a){const i=s*this.size+n;this.data[i]=r,a&&(this.reservedBit[i]=!0)},t.prototype.get=function(s,n){return this.data[s*this.size+n]},t.prototype.xor=function(s,n,r){this.data[s*this.size+n]^=r},t.prototype.isReserved=function(s,n){return this.reservedBit[s*this.size+n]},en=t,en}var tn={},Rr;function Zu(){return Rr||(Rr=1,(function(t){const s=Et().getSymbolSize;t.getRowColCoords=function(r){if(r===1)return[];const a=Math.floor(r/7)+2,i=s(r),l=i===145?26:Math.ceil((i-13)/(2*a-2))*2,c=[i-7];for(let d=1;d<a-1;d++)c[d]=c[d-1]-l;return c.push(6),c.reverse()},t.getPositions=function(r){const a=[],i=t.getRowColCoords(r),l=i.length;for(let c=0;c<l;c++)for(let d=0;d<l;d++)c===0&&d===0||c===0&&d===l-1||c===l-1&&d===0||a.push([i[c],i[d]]);return a}})(tn)),tn}var sn={},Lr;function Xu(){if(Lr)return sn;Lr=1;const t=Et().getSymbolSize,s=7;return sn.getPositions=function(r){const a=t(r);return[[0,0],[a-s,0],[0,a-s]]},sn}var nn={},Br;function em(){return Br||(Br=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const s={N1:3,N2:3,N3:40,N4:10};t.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},t.from=function(a){return t.isValid(a)?parseInt(a,10):void 0},t.getPenaltyN1=function(a){const i=a.size;let l=0,c=0,d=0,m=null,p=null;for(let u=0;u<i;u++){c=d=0,m=p=null;for(let h=0;h<i;h++){let x=a.get(u,h);x===m?c++:(c>=5&&(l+=s.N1+(c-5)),m=x,c=1),x=a.get(h,u),x===p?d++:(d>=5&&(l+=s.N1+(d-5)),p=x,d=1)}c>=5&&(l+=s.N1+(c-5)),d>=5&&(l+=s.N1+(d-5))}return l},t.getPenaltyN2=function(a){const i=a.size;let l=0;for(let c=0;c<i-1;c++)for(let d=0;d<i-1;d++){const m=a.get(c,d)+a.get(c,d+1)+a.get(c+1,d)+a.get(c+1,d+1);(m===4||m===0)&&l++}return l*s.N2},t.getPenaltyN3=function(a){const i=a.size;let l=0,c=0,d=0;for(let m=0;m<i;m++){c=d=0;for(let p=0;p<i;p++)c=c<<1&2047|a.get(m,p),p>=10&&(c===1488||c===93)&&l++,d=d<<1&2047|a.get(p,m),p>=10&&(d===1488||d===93)&&l++}return l*s.N3},t.getPenaltyN4=function(a){let i=0;const l=a.data.length;for(let d=0;d<l;d++)i+=a.data[d];return Math.abs(Math.ceil(i*100/l/5)-10)*s.N4};function n(r,a,i){switch(r){case t.Patterns.PATTERN000:return(a+i)%2===0;case t.Patterns.PATTERN001:return a%2===0;case t.Patterns.PATTERN010:return i%3===0;case t.Patterns.PATTERN011:return(a+i)%3===0;case t.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(i/3))%2===0;case t.Patterns.PATTERN101:return a*i%2+a*i%3===0;case t.Patterns.PATTERN110:return(a*i%2+a*i%3)%2===0;case t.Patterns.PATTERN111:return(a*i%3+(a+i)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}t.applyMask=function(a,i){const l=i.size;for(let c=0;c<l;c++)for(let d=0;d<l;d++)i.isReserved(d,c)||i.xor(d,c,n(a,d,c))},t.getBestMask=function(a,i){const l=Object.keys(t.Patterns).length;let c=0,d=1/0;for(let m=0;m<l;m++){i(m),t.applyMask(m,a);const p=t.getPenaltyN1(a)+t.getPenaltyN2(a)+t.getPenaltyN3(a)+t.getPenaltyN4(a);t.applyMask(m,a),p<d&&(d=p,c=m)}return c}})(nn)),nn}var xs={},Or;function So(){if(Or)return xs;Or=1;const t=Kn(),s=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],n=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return xs.getBlocksCount=function(a,i){switch(i){case t.L:return s[(a-1)*4+0];case t.M:return s[(a-1)*4+1];case t.Q:return s[(a-1)*4+2];case t.H:return s[(a-1)*4+3];default:return}},xs.getTotalCodewordsCount=function(a,i){switch(i){case t.L:return n[(a-1)*4+0];case t.M:return n[(a-1)*4+1];case t.Q:return n[(a-1)*4+2];case t.H:return n[(a-1)*4+3];default:return}},xs}var rn={},Wt={},Fr;function tm(){if(Fr)return Wt;Fr=1;const t=new Uint8Array(512),s=new Uint8Array(256);return(function(){let r=1;for(let a=0;a<255;a++)t[a]=r,s[r]=a,r<<=1,r&256&&(r^=285);for(let a=255;a<512;a++)t[a]=t[a-255]})(),Wt.log=function(r){if(r<1)throw new Error("log("+r+")");return s[r]},Wt.exp=function(r){return t[r]},Wt.mul=function(r,a){return r===0||a===0?0:t[s[r]+s[a]]},Wt}var zr;function sm(){return zr||(zr=1,(function(t){const s=tm();t.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let l=0;l<r.length;l++)for(let c=0;c<a.length;c++)i[l+c]^=s.mul(r[l],a[c]);return i},t.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const l=i[0];for(let d=0;d<a.length;d++)i[d]^=s.mul(a[d],l);let c=0;for(;c<i.length&&i[c]===0;)c++;i=i.slice(c)}return i},t.generateECPolynomial=function(r){let a=new Uint8Array([1]);for(let i=0;i<r;i++)a=t.mul(a,new Uint8Array([1,s.exp(i)]));return a}})(rn)),rn}var an,Ur;function nm(){if(Ur)return an;Ur=1;const t=sm();function s(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return s.prototype.initialize=function(r){this.degree=r,this.genPoly=t.generateECPolynomial(this.degree)},s.prototype.encode=function(r){if(!this.genPoly)throw new Error("Encoder not initialized");const a=new Uint8Array(r.length+this.degree);a.set(r);const i=t.mod(a,this.genPoly),l=this.degree-i.length;if(l>0){const c=new Uint8Array(this.degree);return c.set(i,l),c}return i},an=s,an}var on={},ln={},cn={},$r;function Co(){return $r||($r=1,cn.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),cn}var dt={},qr;function To(){if(qr)return dt;qr=1;const t="[0-9]+",s="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const r="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
160
160
  ]))+`;dt.KANJI=new RegExp(n,"g"),dt.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),dt.BYTE=new RegExp(r,"g"),dt.NUMERIC=new RegExp(t,"g"),dt.ALPHANUMERIC=new RegExp(s,"g");const a=new RegExp("^"+n+"$"),i=new RegExp("^"+t+"$"),l=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return dt.testKanji=function(d){return a.test(d)},dt.testNumeric=function(d){return i.test(d)},dt.testAlphanumeric=function(d){return l.test(d)},dt}var Vr;function At(){return Vr||(Vr=1,(function(t){const s=Co(),n=To();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(i,l){if(!i.ccBits)throw new Error("Invalid mode: "+i);if(!s.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?i.ccBits[0]:l<27?i.ccBits[1]:i.ccBits[2]},t.getBestModeForData=function(i){return n.testNumeric(i)?t.NUMERIC:n.testAlphanumeric(i)?t.ALPHANUMERIC:n.testKanji(i)?t.KANJI:t.BYTE},t.toString=function(i){if(i&&i.id)return i.id;throw new Error("Invalid mode")},t.isValid=function(i){return i&&i.bit&&i.ccBits};function r(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+a)}}t.from=function(i,l){if(t.isValid(i))return i;try{return r(i)}catch{return l}}})(ln)),ln}var Hr;function rm(){return Hr||(Hr=1,(function(t){const s=Et(),n=So(),r=Kn(),a=At(),i=Co(),l=7973,c=s.getBCHDigit(l);function d(h,x,k){for(let j=1;j<=40;j++)if(x<=t.getCapacity(j,k,h))return j}function m(h,x){return a.getCharCountIndicator(h,x)+4}function p(h,x){let k=0;return h.forEach(function(j){const A=m(j.mode,x);k+=A+j.getBitsLength()}),k}function u(h,x){for(let k=1;k<=40;k++)if(p(h,k)<=t.getCapacity(k,x,a.MIXED))return k}t.from=function(x,k){return i.isValid(x)?parseInt(x,10):k},t.getCapacity=function(x,k,j){if(!i.isValid(x))throw new Error("Invalid QR Code version");typeof j>"u"&&(j=a.BYTE);const A=s.getSymbolTotalCodewords(x),f=n.getTotalCodewordsCount(x,k),E=(A-f)*8;if(j===a.MIXED)return E;const y=E-m(j,x);switch(j){case a.NUMERIC:return Math.floor(y/10*3);case a.ALPHANUMERIC:return Math.floor(y/11*2);case a.KANJI:return Math.floor(y/13);case a.BYTE:default:return Math.floor(y/8)}},t.getBestVersionForData=function(x,k){let j;const A=r.from(k,r.M);if(Array.isArray(x)){if(x.length>1)return u(x,A);if(x.length===0)return 1;j=x[0]}else j=x;return d(j.mode,j.getLength(),A)},t.getEncodedBits=function(x){if(!i.isValid(x)||x<7)throw new Error("Invalid QR Code version");let k=x<<12;for(;s.getBCHDigit(k)-c>=0;)k^=l<<s.getBCHDigit(k)-c;return x<<12|k}})(on)),on}var dn={},Kr;function am(){if(Kr)return dn;Kr=1;const t=Et(),s=1335,n=21522,r=t.getBCHDigit(s);return dn.getEncodedBits=function(i,l){const c=i.bit<<3|l;let d=c<<10;for(;t.getBCHDigit(d)-r>=0;)d^=s<<t.getBCHDigit(d)-r;return(c<<10|d)^n},dn}var un={},mn,Gr;function om(){if(Gr)return mn;Gr=1;const t=At();function s(n){this.mode=t.NUMERIC,this.data=n.toString()}return s.getBitsLength=function(r){return 10*Math.floor(r/3)+(r%3?r%3*3+1:0)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(r){let a,i,l;for(a=0;a+3<=this.data.length;a+=3)i=this.data.substr(a,3),l=parseInt(i,10),r.put(l,10);const c=this.data.length-a;c>0&&(i=this.data.substr(a),l=parseInt(i,10),r.put(l,c*3+1))},mn=s,mn}var hn,Wr;function im(){if(Wr)return hn;Wr=1;const t=At(),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function n(r){this.mode=t.ALPHANUMERIC,this.data=r}return n.getBitsLength=function(a){return 11*Math.floor(a/2)+6*(a%2)},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(a){let i;for(i=0;i+2<=this.data.length;i+=2){let l=s.indexOf(this.data[i])*45;l+=s.indexOf(this.data[i+1]),a.put(l,11)}this.data.length%2&&a.put(s.indexOf(this.data[i]),6)},hn=n,hn}var fn,Qr;function lm(){if(Qr)return fn;Qr=1;const t=At();function s(n){this.mode=t.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}return s.getBitsLength=function(r){return r*8},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(n){for(let r=0,a=this.data.length;r<a;r++)n.put(this.data[r],8)},fn=s,fn}var xn,Yr;function cm(){if(Yr)return xn;Yr=1;const t=At(),s=Et();function n(r){this.mode=t.KANJI,this.data=r}return n.getBitsLength=function(a){return a*13},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(r){let a;for(a=0;a<this.data.length;a++){let i=s.toSJIS(this.data[a]);if(i>=33088&&i<=40956)i-=33088;else if(i>=57408&&i<=60351)i-=49472;else throw new Error("Invalid SJIS character: "+this.data[a]+`
161
161
  Make sure your charset is UTF-8`);i=(i>>>8&255)*192+(i&255),r.put(i,13)}},xn=n,xn}var pn={exports:{}},Jr;function dm(){return Jr||(Jr=1,(function(t){var s={single_source_shortest_paths:function(n,r,a){var i={},l={};l[r]=0;var c=s.PriorityQueue.make();c.push(r,0);for(var d,m,p,u,h,x,k,j,A;!c.empty();){d=c.pop(),m=d.value,u=d.cost,h=n[m]||{};for(p in h)h.hasOwnProperty(p)&&(x=h[p],k=u+x,j=l[p],A=typeof l[p]>"u",(A||j>k)&&(l[p]=k,c.push(p,k),i[p]=m))}if(typeof a<"u"&&typeof l[a]>"u"){var f=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(f)}return i},extract_shortest_path_from_predecessor_list:function(n,r){for(var a=[],i=r;i;)a.push(i),n[i],i=n[i];return a.reverse(),a},find_path:function(n,r,a){var i=s.single_source_shortest_paths(n,r,a);return s.extract_shortest_path_from_predecessor_list(i,a)},PriorityQueue:{make:function(n){var r=s.PriorityQueue,a={},i;n=n||{};for(i in r)r.hasOwnProperty(i)&&(a[i]=r[i]);return a.queue=[],a.sorter=n.sorter||r.default_sorter,a},default_sorter:function(n,r){return n.cost-r.cost},push:function(n,r){var a={value:n,cost:r};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=s})(pn)),pn.exports}var Zr;function um(){return Zr||(Zr=1,(function(t){const s=At(),n=om(),r=im(),a=lm(),i=cm(),l=To(),c=Et(),d=dm();function m(f){return unescape(encodeURIComponent(f)).length}function p(f,E,y){const v=[];let b;for(;(b=f.exec(y))!==null;)v.push({data:b[0],index:b.index,mode:E,length:b[0].length});return v}function u(f){const E=p(l.NUMERIC,s.NUMERIC,f),y=p(l.ALPHANUMERIC,s.ALPHANUMERIC,f);let v,b;return c.isKanjiModeEnabled()?(v=p(l.BYTE,s.BYTE,f),b=p(l.KANJI,s.KANJI,f)):(v=p(l.BYTE_KANJI,s.BYTE,f),b=[]),E.concat(y,v,b).sort(function(T,P){return T.index-P.index}).map(function(T){return{data:T.data,mode:T.mode,length:T.length}})}function h(f,E){switch(E){case s.NUMERIC:return n.getBitsLength(f);case s.ALPHANUMERIC:return r.getBitsLength(f);case s.KANJI:return i.getBitsLength(f);case s.BYTE:return a.getBitsLength(f)}}function x(f){return f.reduce(function(E,y){const v=E.length-1>=0?E[E.length-1]:null;return v&&v.mode===y.mode?(E[E.length-1].data+=y.data,E):(E.push(y),E)},[])}function k(f){const E=[];for(let y=0;y<f.length;y++){const v=f[y];switch(v.mode){case s.NUMERIC:E.push([v,{data:v.data,mode:s.ALPHANUMERIC,length:v.length},{data:v.data,mode:s.BYTE,length:v.length}]);break;case s.ALPHANUMERIC:E.push([v,{data:v.data,mode:s.BYTE,length:v.length}]);break;case s.KANJI:E.push([v,{data:v.data,mode:s.BYTE,length:m(v.data)}]);break;case s.BYTE:E.push([{data:v.data,mode:s.BYTE,length:m(v.data)}])}}return E}function j(f,E){const y={},v={start:{}};let b=["start"];for(let C=0;C<f.length;C++){const T=f[C],P=[];for(let S=0;S<T.length;S++){const I=T[S],_=""+C+S;P.push(_),y[_]={node:I,lastCount:0},v[_]={};for(let D=0;D<b.length;D++){const R=b[D];y[R]&&y[R].node.mode===I.mode?(v[R][_]=h(y[R].lastCount+I.length,I.mode)-h(y[R].lastCount,I.mode),y[R].lastCount+=I.length):(y[R]&&(y[R].lastCount=I.length),v[R][_]=h(I.length,I.mode)+4+s.getCharCountIndicator(I.mode,E))}}b=P}for(let C=0;C<b.length;C++)v[b[C]].end=0;return{map:v,table:y}}function A(f,E){let y;const v=s.getBestModeForData(f);if(y=s.from(E,v),y!==s.BYTE&&y.bit<v.bit)throw new Error('"'+f+'" cannot be encoded with mode '+s.toString(y)+`.
162
162
  Suggested mode is: `+s.toString(v));switch(y===s.KANJI&&!c.isKanjiModeEnabled()&&(y=s.BYTE),y){case s.NUMERIC:return new n(f);case s.ALPHANUMERIC:return new r(f);case s.KANJI:return new i(f);case s.BYTE:return new a(f)}}t.fromArray=function(E){return E.reduce(function(y,v){return typeof v=="string"?y.push(A(v,null)):v.data&&y.push(A(v.data,v.mode)),y},[])},t.fromString=function(E,y){const v=u(E,c.isKanjiModeEnabled()),b=k(v),C=j(b,y),T=d.find_path(C.map,"start","end"),P=[];for(let S=1;S<T.length-1;S++)P.push(C.table[T[S]].node);return t.fromArray(x(P))},t.rawSplit=function(E){return t.fromArray(u(E,c.isKanjiModeEnabled()))}})(un)),un}var Xr;function mm(){if(Xr)return Js;Xr=1;const t=Et(),s=Kn(),n=Yu(),r=Ju(),a=Zu(),i=Xu(),l=em(),c=So(),d=nm(),m=rm(),p=am(),u=At(),h=um();function x(C,T){const P=C.size,S=i.getPositions(T);for(let I=0;I<S.length;I++){const _=S[I][0],D=S[I][1];for(let R=-1;R<=7;R++)if(!(_+R<=-1||P<=_+R))for(let F=-1;F<=7;F++)D+F<=-1||P<=D+F||(R>=0&&R<=6&&(F===0||F===6)||F>=0&&F<=6&&(R===0||R===6)||R>=2&&R<=4&&F>=2&&F<=4?C.set(_+R,D+F,!0,!0):C.set(_+R,D+F,!1,!0))}}function k(C){const T=C.size;for(let P=8;P<T-8;P++){const S=P%2===0;C.set(P,6,S,!0),C.set(6,P,S,!0)}}function j(C,T){const P=a.getPositions(T);for(let S=0;S<P.length;S++){const I=P[S][0],_=P[S][1];for(let D=-2;D<=2;D++)for(let R=-2;R<=2;R++)D===-2||D===2||R===-2||R===2||D===0&&R===0?C.set(I+D,_+R,!0,!0):C.set(I+D,_+R,!1,!0)}}function A(C,T){const P=C.size,S=m.getEncodedBits(T);let I,_,D;for(let R=0;R<18;R++)I=Math.floor(R/3),_=R%3+P-8-3,D=(S>>R&1)===1,C.set(I,_,D,!0),C.set(_,I,D,!0)}function f(C,T,P){const S=C.size,I=p.getEncodedBits(T,P);let _,D;for(_=0;_<15;_++)D=(I>>_&1)===1,_<6?C.set(_,8,D,!0):_<8?C.set(_+1,8,D,!0):C.set(S-15+_,8,D,!0),_<8?C.set(8,S-_-1,D,!0):_<9?C.set(8,15-_-1+1,D,!0):C.set(8,15-_-1,D,!0);C.set(S-8,8,1,!0)}function E(C,T){const P=C.size;let S=-1,I=P-1,_=7,D=0;for(let R=P-1;R>0;R-=2)for(R===6&&R--;;){for(let F=0;F<2;F++)if(!C.isReserved(I,R-F)){let Q=!1;D<T.length&&(Q=(T[D]>>>_&1)===1),C.set(I,R-F,Q),_--,_===-1&&(D++,_=7)}if(I+=S,I<0||P<=I){I-=S,S=-S;break}}}function y(C,T,P){const S=new n;P.forEach(function(F){S.put(F.mode.bit,4),S.put(F.getLength(),u.getCharCountIndicator(F.mode,C)),F.write(S)});const I=t.getSymbolTotalCodewords(C),_=c.getTotalCodewordsCount(C,T),D=(I-_)*8;for(S.getLengthInBits()+4<=D&&S.put(0,4);S.getLengthInBits()%8!==0;)S.putBit(0);const R=(D-S.getLengthInBits())/8;for(let F=0;F<R;F++)S.put(F%2?17:236,8);return v(S,C,T)}function v(C,T,P){const S=t.getSymbolTotalCodewords(T),I=c.getTotalCodewordsCount(T,P),_=S-I,D=c.getBlocksCount(T,P),R=S%D,F=D-R,Q=Math.floor(S/D),Y=Math.floor(_/D),ee=Y+1,Z=Q-Y,te=new d(Z);let V=0;const O=new Array(D),g=new Array(D);let $=0;const N=new Uint8Array(C.buffer);for(let oe=0;oe<D;oe++){const ie=oe<F?Y:ee;O[oe]=N.slice(V,V+ie),g[oe]=te.encode(O[oe]),V+=ie,$=Math.max($,ie)}const q=new Uint8Array(S);let z=0,W,L;for(W=0;W<$;W++)for(L=0;L<D;L++)W<O[L].length&&(q[z++]=O[L][W]);for(W=0;W<Z;W++)for(L=0;L<D;L++)q[z++]=g[L][W];return q}function b(C,T,P,S){let I;if(Array.isArray(C))I=h.fromArray(C);else if(typeof C=="string"){let Q=T;if(!Q){const Y=h.rawSplit(C);Q=m.getBestVersionForData(Y,P)}I=h.fromString(C,Q||40)}else throw new Error("Invalid data");const _=m.getBestVersionForData(I,P);if(!_)throw new Error("The amount of data is too big to be stored in a QR Code");if(!T)T=_;else if(T<_)throw new Error(`