@thevinci/web 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{JsonTreeView-Bp2NfTlR.js → JsonTreeView-CoBDQpso.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-BY9quCNq.js → MarkdownRendererImpl-Vl8hQ3Xn.js} +1 -1
- package/dist/assets/{MultiRunWindow-kgAi2Tz_.js → MultiRunWindow-I3lRPicR.js} +1 -1
- package/dist/assets/{OnboardingScreen-DrP7yZEP.js → OnboardingScreen-1fIy0izk.js} +1 -1
- package/dist/assets/{SettingsWindow-CqBF9kRR.js → SettingsWindow-I9We0AUb.js} +1 -1
- package/dist/assets/{TerminalView-ul8_wWze.js → TerminalView-CykGfmvO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BaCyTzxc.js → ToolOutputDialog-BKJtJOAa.js} +1 -1
- package/dist/assets/{main-C6wwuWRQ.js → main-Bk_xH4dF.js} +2 -2
- package/dist/assets/{main-fW2C0D6j.js → main-cStTDcer.js} +4 -4
- package/dist/assets/{miniChat-HDPP8AS3.js → miniChat-C8-PCBCV.js} +2 -2
- package/dist/assets/{modelPrefsAutoSave-DuvP8x_e.js → modelPrefsAutoSave-z_3gcNaV.js} +4 -4
- package/dist/assets/{renderElectronMiniChatApp-BGJAK42I.js → renderElectronMiniChatApp-Dm0XClv3.js} +2 -2
- package/dist/index.html +1 -1
- package/dist/mini-chat.html +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-B9l0ZNi2.js","assets/vendor--DBfsbEis.css","assets/modelPrefsAutoSave-
|
|
2
|
-
import{aI as at,Z as o,bF as Ja,bE as oa,b5 as s,bH as Dl,C as Tl,Q as Xa,ac as cl,a_ as Jg,p as dl,o as Za,aG as eo,aL as gr,aS as Na,bh as Be,ag as Xg,af as Zg,bd as mo,aM as Ml,d as ex,e as tx,c as sx,ax as kr,bg as Wa,aB as Ef,bK as Hc,ay as Hi,bJ as Rf,aw as nx,av as rx,aq as ix,s as ax,ar as ox,bG as Br,q as lx,r as Xn,aV as cx,f as Sa,b8 as mu,aY as dx,b0 as ux,b6 as Ql,b1 as mx,aR as px,aZ as fx,bq as pu,bo as fu,ap as hx,Y as Ff,g as Lf,ad as gx,bp as hu,aT as xx,bc as bx,aF as yx,au as vx,E as wx,ae as jx,br as Nx,be as Of,b9 as Sx,a$ as Gc,aO as $f,b4 as Bf,b3 as ra,bv as Ba,H as qc,bw as ot,L as zf,b7 as Vf,aQ as kx,aD as Cx,F as Px,aJ as Ix,aX as Ax,X as Dx,bB as Tx,bC as Mx,K as Ex,bs as Rx,bD as gu,az as xu,bb as Jl,aE as Fx}from"./vendor-.bun-B9l0ZNi2.js";import{g as Lx,h as Ox,w as $x}from"./index-DgiFEKGN.js";import{ew as ut,eZ as Ie,e6 as rn,aG as ce,P,dW as ks,cF as mn,bY as pr,c2 as pi,dI as Xl,d4 as Zl,bh as ec,eE as As,cY as Zs,e8 as $s,ao as Pt,ar as It,ap as Dt,cE as pa,cp as Bi,bc as bu,x as $t,cW as Bx,cV as ul,aI as _n,dS as H,J as Es,F as Cn,w as Rs,v as Fs,c1 as _f,b0 as yu,a$ as zx,b3 as Vx,b6 as vu,b1 as _x,b2 as Ux,cM as Wx,aK as Kx,eG as Pn,cq as gn,cX as rr,bV as Yc,a0 as vn,y as Ka,m as Hx,e3 as xt,eQ as Ot,eN as Gx,eI as Uf,ev as Ei,d_ as Ad,el as Hn,aD as Dd,eX as El,aZ as qx,cN as wu,d3 as Yx,bx as Qx,eS as Wf,bq as Jx,ei as Xx,dr as Kf,ec as Td,ch as ml,dJ as Hf,br as Rl,bI as Zr,cd as Md,ba as Yo,af as Zx,k as eb,K as Xs,eC as Gf,eB as qf,Q as Bt,a5 as Cs,T as $r,dZ as fa,bg as tb,cA as Yf,r as bs,s as gs,B as ge,o as fs,n as hs,ey as zi,dy as sb,bW as nb,_ as Co,de as wn,aP as Qf,bs as Jf,eH as Fl,aV as rb,di as Xf,ce as ju,Z as Nu,ak as hn,i as ds,d2 as ib,aU as ab,dX as ob,aL as lb,b7 as cb,bM as db,bK as ub,bb as zs,cK as mb,aJ as pb,p as Is,dN as fb,aw as hb,d1 as gb,b8 as xb,N as Zn,a4 as po,U as bb,q as Vs,eD as Ll,ex as ia,bF as ha,b9 as ga,bZ as Su,bO as xa,bA as yb,a6 as is,ac as as,ad as us,a7 as os,a9 as Ft,bv as vb,ag as to,bC as wb,eb as Ir,ez as Ed,es as Ol,c3 as jb,ej as Rd,eq as Nb,em as Sb,ep as Fd,eo as kb,et as tn,c0 as fo,dB as Sr,bu as Cb,bL as Pb,bS as tc,e7 as $l,ee as Ld,ed as Bl,e5 as ho,ef as Bn,b$ as Od,bk as Vi,z as pl,E as fl,cv as so,t as Zf,ek as Ib,eY as Ar,cU as Ab,cm as Db,cl as Tb,cG as Mb,cz as Eb,bN as ku,bQ as hl,eT as zl,bw as eh,c_ as Rb,eL as Fb,aX as go,ci as Lb,A as $d,ck as Ob,cj as aa,cx as no,ea as th,cZ as ba,cB as sh,a1 as $b,b_ as Bb,e2 as Bd,eV as fi,co as la,eU as Ri,Y as Vl,bX as xo,W as bo,cL as Qc,aF as nh,ca as zd,dz as rh,bm as ro,dx as zb,V as Vb,X as _b,b4 as Ub,b5 as Wb,d8 as Fi,bE as sc,dl as Cu,dw as Kb,dk as Hb,bP as Gb,bd as qb,a2 as ta,dD as nc,bT as Yb,eA as Pu,cH as Li,dQ as Qb,as as Iu,l as Au,C as Du,D as Tu,dC as Qo,cR as Mu,eJ as Jb,aT as Xb,bU as Zb,bf as ey,be as rc,aE as Eu,d6 as ty,cy as sy,du as ny,dj as ry,e1 as iy,aB as ic,aA as ay,av as Ru,f1 as za,bH as oy,ds as ih,bD as ly,cO as sa,cI as cy,cC as Fu,at as dy,bj as uy,eh as ah,dA as Po,dp as Ha,dU as my,aO as oh,bR as py,c4 as fy,c8 as Lu,d0 as Ou,f0 as lh,en as ch,bt as ac,e4 as Io,f2 as hy,aN as gy,aM as xy,dY as by,j as dh,M as uh,d5 as Jc,by as Vd,dn as yy,cS as xs,cD as io,aS as ya,aH as ca,cP as $u,eK as Yn,cn as vy,dc as Ga,a as wy,bn as mh,dv as jy,dt as Ny,a8 as Xc,cu as Sy,c6 as ky,bi as Bu,c7 as Cy,e9 as Py,eW as _d,e_ as ph,eu as Iy,eO as Ay,eR as Dy,bp as Ty,aC as zu,G as My,I as Ey,H as Ry,bo as Fy,eP as oc,d$ as Ly,dK as fh,er as Oy,$ as $y,cr as By,cT as zy,dh as Vy,dG as _y,dO as Uy,aW as Wy,cb as Ky,d9 as Hy,az as Gy,dq as qy,aQ as Yy,aa as Vu,ab as Qy,c as hh,e as Jy,f as Xy,d as Zy,g as ev,cJ as si,u as tv,S as _u,bz as sv,c5 as Jo,c9 as Xo,dm as nv,dF as rv,bB as iv,dP as av,aR as Uu,bG as ov,dE as Wu,ax as lv,d7 as Ku,e0 as cv,eF as dv,e$ as uv,ai as Hu,a3 as Gu,aq as qu,au as mv,ah as gh,an as xh,cg as pv,cf as fv,dR as hv,ay as gv,dH as xv,dL as bv,dM as yv,O as vv,am as wv,al as jv,ae as Nv}from"./modelPrefsAutoSave-DuvP8x_e.js";import{J as Sv}from"./JsonTreeView-Bp2NfTlR.js";const kv=({transform:t})=>({...t,y:0}),Cv=t=>{const e=at.c(18),{id:n,children:r,className:i}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:l,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=Dl(a);let h;e[2]!==p?(h=Tl.Transform.toString(p),e[2]=p,e[3]=h):h=e[3];let x;e[4]!==h||e[5]!==m?(x={transform:h,transition:m},e[4]=h,e[5]=m,e[6]=x):x=e[6];const f=u&&"opacity-50";let v;e[7]!==i||e[8]!==f?(v=ce("h-full rounded-md",i,f),e[7]=i,e[8]=f,e[9]=v):v=e[9];let y;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==x||e[16]!==v?(y=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:x,className:v,...l,...c,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=x,e[16]=v,e[17]=y):y=e[17],y},Pv=t=>{const e=at.c(6),{id:n,children:r,className:i}=t;let a;e[0]!==i?(a=ce("h-full",i),e[0]=i,e[1]=a):a=e[1];let l;return e[2]!==r||e[3]!==n||e[4]!==a?(l=s.jsx("div",{className:a,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=a,e[5]=l):l=e[5],l},Cr=t=>{const e=at.c(121),{items:n,activeId:r,onSelect:i,onClose:a,onReorder:l,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:h,animateActivePill:x,activePillLowercase:f,className:v}=t,y=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,b=h===void 0?!1:h,k=f===void 0?!0:f,{t:I}=ut(),j=Ie(Iv),{isTablet:N}=rn(),D=j||N,E=o.useRef(null);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T={left:!1,right:!1},e[0]=T):T=e[0];const[C,S]=o.useState(T);let M;e[1]!==n?(M=n.map(Av),e[1]=n,e[2]=M):M=e[2];const A=M,R=y==="scrollable",z=g==="default",B=g==="active-pill",V=g==="animated",$=B||V,_=z,X=$||_,O=B&&R,J=$,Q=x??V,ne=typeof l=="function",G=ne?Cv:Pv;let le;e[3]===Symbol.for("react.memo_cache_sentinel")?(le=new Map,e[3]=le):le=e[3];const oe=o.useRef(le),[F,U]=o.useState(null);let W;e[4]===Symbol.for("react.memo_cache_sentinel")?(W={activationConstraint:{distance:8}},e[4]=W):W=e[4];const te=Ja(oa(Xa,W)),K=Dv;let ae;e[5]===Symbol.for("react.memo_cache_sentinel")?(ae=(Qe,he)=>{if(he){oe.current.set(Qe,he);return}oe.current.delete(Qe)},e[5]=ae):ae=e[5];const ve=ae;let re;e[6]!==r||e[7]!==X?(re=()=>{if(!X||!r){U(Tv);return}const Qe=E.current,he=oe.current.get(r);if(!Qe||!he){U(Mv);return}let Ge=0,Ve=0,it=he;for(;it&&it!==Qe;)Ge=Ge+it.offsetLeft,Ve=Ve+it.offsetTop,it=it.offsetParent;const dt={left:Ge,top:Ve,width:he.offsetWidth,height:he.offsetHeight};U(Ye=>K(Ye,dt)?Ye:dt)},e[6]=r,e[7]=X,e[8]=re):re=e[8];const be=re;let pe;e[9]!==R?(pe=()=>{if(!R){S({left:!1,right:!1});return}const Qe=E.current;if(!Qe){S({left:!1,right:!1});return}S({left:Qe.scrollLeft>2,right:Qe.scrollLeft+Qe.clientWidth<Qe.scrollWidth-2})},e[9]=R,e[10]=pe):pe=e[10];const ye=pe;let ie;e[11]!==R||e[12]!==ye?(ie=()=>{if(!R){S({left:!1,right:!1});return}const Qe=E.current;if(!Qe)return;ye(),Qe.addEventListener("scroll",ye,{passive:!0});const he=new ResizeObserver(ye);return he.observe(Qe),()=>{Qe.removeEventListener("scroll",ye),he.disconnect()}},e[11]=R,e[12]=ye,e[13]=ie):ie=e[13];let ue;e[14]!==R||e[15]!==n.length||e[16]!==ye?(ue=[R,n.length,ye],e[14]=R,e[15]=n.length,e[16]=ye,e[17]=ue):ue=e[17],o.useEffect(ie,ue);let se;e[18]!==r||e[19]!==be||e[20]!==X?(se=()=>{if(!X){U(null);return}be();const Qe=E.current;if(!Qe)return;const he=new ResizeObserver(be);if(he.observe(Qe),r){const Ge=oe.current.get(r);Ge&&he.observe(Ge)}return()=>{he.disconnect()}},e[18]=r,e[19]=be,e[20]=X,e[21]=se):se=e[21];let Ne;e[22]!==r||e[23]!==n.length||e[24]!==be||e[25]!==X?(Ne=[r,n.length,be,X],e[22]=r,e[23]=n.length,e[24]=be,e[25]=X,e[26]=Ne):Ne=e[26],o.useEffect(se,Ne);let Ce;e[27]!==be?(Ce=()=>{be()},e[27]=be,e[28]=Ce):Ce=e[28],o.useLayoutEffect(Ce);let je;e[29]!==r||e[30]!==R||e[31]!==ye?(je=()=>{if(!R||!r)return;const Qe=E.current;if(!Qe)return;const he=window.requestAnimationFrame(()=>{const Ge=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),Ve=Qe.querySelector(`[data-sortable-tab-id="${Ge}"]`);Ve&&(Ve.scrollIntoView({block:"nearest",inline:"nearest"}),ye())});return()=>{window.cancelAnimationFrame(he)}},e[29]=r,e[30]=R,e[31]=ye,e[32]=je):je=e[32];let we;e[33]!==r||e[34]!==R||e[35]!==n.length||e[36]!==ye?(we=[r,R,n.length,ye],e[33]=r,e[34]=R,e[35]=n.length,e[36]=ye,e[37]=we):we=e[37],o.useEffect(je,we);let ke;e[38]!==l?(ke=Qe=>{if(!l)return;const{active:he,over:Ge}=Qe;!Ge||he.id===Ge.id||l(String(he.id),String(Ge.id))},e[38]=l,e[39]=ke):ke=e[39];const xe=ke;let me;e[40]!==v?(me=ce("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=me):me=e[41];let Me;e[42]!==R||e[43]!==C||e[44]!==$?(Me=R&&C.left?s.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=R,e[43]=C,e[44]=$,e[45]=Me):Me=e[45];let Ue;e[46]!==R||e[47]!==C||e[48]!==$?(Ue=R&&C.right?s.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=R,e[47]=C,e[48]=$,e[49]=Ue):Ue=e[49];const q=$?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Se=$&&"@container/pill-tabs",$e=$&&"pill-tabs__track",Pe=$&&(p??"gap-0.5 py-0.5"),fe=_&&"items-center overflow-y-hidden",L=J&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",Z=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Y;e[50]!==q||e[51]!==Se||e[52]!==$e||e[53]!==Pe||e[54]!==fe||e[55]!==L||e[56]!==Z?(Y=ce("relative flex h-full min-w-0 flex-1",q,Se,$e,Pe,fe,L,Z),e[50]=q,e[51]=Se,e[52]=$e,e[53]=Pe,e[54]=fe,e[55]=L,e[56]=Z,e[57]=Y):Y=e[57];let Ee;e[58]!==R?(Ee=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=Ee):Ee=e[59];let Ae;e[60]!==I?(Ae=I("sortableTabsStrip.aria.tabs"),e[60]=I,e[61]=Ae):Ae=e[61];let Je;e[62]!==F||e[63]!==Q||e[64]!==$?(Je=$&&F?s.jsx("div",{className:ce("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${F.left}px, ${F.top}px, 0)`,width:`${F.width}px`,height:`${F.height}px`,transition:Q?"transform 300ms cubic-bezier(0.65, 0, 0.35, 1), width 300ms cubic-bezier(0.65, 0, 0.35, 1), height 300ms cubic-bezier(0.65, 0, 0.35, 1)":void 0}}):null,e[62]=F,e[63]=Q,e[64]=$,e[65]=Je):Je=e[65];let de;e[66]!==F||e[67]!==_?(de=_&&F?s.jsx("div",{className:"pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",style:{transform:`translate3d(${F.left}px, 0, 0)`,width:`${F.width}px`},"aria-hidden":!0}):null,e[66]=F,e[67]=_,e[68]=de):de=e[68];let ze;if(e[69]!==G||e[70]!==r||e[71]!==m||e[72]!==k||e[73]!==D||e[74]!==b||e[75]!==w||e[76]!==B||e[77]!==j||e[78]!==R||e[79]!==n||e[80]!==a||e[81]!==i||e[82]!==O||e[83]!==$){let Qe;e[85]!==G||e[86]!==r||e[87]!==m||e[88]!==k||e[89]!==D||e[90]!==b||e[91]!==w||e[92]!==B||e[93]!==j||e[94]!==R||e[95]!==a||e[96]!==i||e[97]!==O||e[98]!==$?(Qe=he=>{const Ge=he.id===r,Ve=w&&$&&!Ge&&!!he.icon,it=!Ve,dt=!!he.icon&&(!b||Ge),Ye=w&&$&&Ge&&!R&&!O,_e=he.closable!==!1&&!!a,et=_e&&!!he.icon,gt=R||O?void 0:$?Ye?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",Lt=_e?mt=>{mt.button===1&&(mt.preventDefault(),mt.stopPropagation(),a?.(he.id))}:void 0,Ut=_e?Ev:void 0;return s.jsx(G,{id:he.id,className:gt,children:s.jsxs("div",{ref:mt=>ve(he.id,mt),onAuxClick:Lt,onMouseDown:Ut,className:ce("group flex h-full min-w-0 flex-nowrap items-center",R||O?"shrink-0":$?"w-full":"w-full min-w-0",$?"relative z-10 bg-transparent":Ge?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":Ge,"aria-label":Ve?he.title??he.label:void 0,onClick:()=>i(he.id),className:ce($?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",$&&k?"lowercase":null,$&&(Ve?"gap-0":"gap-1.5"),$?O?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":Ve?"px-2 !min-w-0 text-center":Ye?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",$?m??(B?j?"h-[38px]":"h-[31px]":"h-7"):null,$?Ge?"text-foreground":"text-muted-foreground hover:text-foreground":null,$?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:he.title??he.label,children:$?s.jsxs(s.Fragment,{children:[dt?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:ce("flex items-center justify-center transition-opacity",et&&(D?"opacity-0":"group-hover:opacity-0")),children:he.icon}),et?s.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Rv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,it?s.jsx("span",{className:"animated-tabs__label truncate",children:he.label}):null]}):s.jsxs("span",{className:ce("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[dt?s.jsxs("span",{className:ce("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ge?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:ce("flex items-center justify-center transition-opacity",et&&(D?"opacity-0":"group-hover:opacity-0")),children:he.icon}),et?s.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Fv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:he.label})]})}),_e&&!et?s.jsx("button",{type:"button",onPointerDown:Lv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},className:ce("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",$?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",$?Ge?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ge?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3 w-3"})}):null]})},he.id)},e[85]=G,e[86]=r,e[87]=m,e[88]=k,e[89]=D,e[90]=b,e[91]=w,e[92]=B,e[93]=j,e[94]=R,e[95]=a,e[96]=i,e[97]=O,e[98]=$,e[99]=Qe):Qe=e[99],ze=n.map(Qe),e[69]=G,e[70]=r,e[71]=m,e[72]=k,e[73]=D,e[74]=b,e[75]=w,e[76]=B,e[77]=j,e[78]=R,e[79]=n,e[80]=a,e[81]=i,e[82]=O,e[83]=$,e[84]=ze}else ze=e[84];let rt;e[100]!==Y||e[101]!==Ee||e[102]!==Ae||e[103]!==Je||e[104]!==de||e[105]!==ze?(rt=s.jsxs("div",{ref:E,className:Y,style:Ee,role:"tablist","aria-label":Ae,children:[Je,de,ze]}),e[100]=Y,e[101]=Ee,e[102]=Ae,e[103]=Je,e[104]=de,e[105]=ze,e[106]=rt):rt=e[106];let Re;e[107]!==me||e[108]!==Me||e[109]!==Ue||e[110]!==rt?(Re=s.jsxs("div",{className:me,children:[Me,Ue,rt]}),e[107]=me,e[108]=Me,e[109]=Ue,e[110]=rt,e[111]=Re):Re=e[111];const Xe=Re;if(!ne)return Xe;let qe;e[112]===Symbol.for("react.memo_cache_sentinel")?(qe=[kv],e[112]=qe):qe=e[112];let Te;e[113]!==A||e[114]!==Xe?(Te=s.jsx(cl,{items:A,strategy:Jg,children:Xe}),e[113]=A,e[114]=Xe,e[115]=Te):Te=e[115];let We;e[116]===Symbol.for("react.memo_cache_sentinel")?(We=s.jsx(dl,{dropAnimation:null}),e[116]=We):We=e[116];let Ze;return e[117]!==xe||e[118]!==te||e[119]!==Te?(Ze=s.jsxs(Za,{sensors:te,collisionDetection:eo,onDragEnd:xe,modifiers:qe,children:[Te,We]}),e[117]=xe,e[118]=te,e[119]=Te,e[120]=Ze):Ze=e[120],Ze};function Iv(t){return t.isMobile}function Av(t){return t.id}function Dv(t,e){return!t||!e?t===e:Math.abs(t.left-e.left)<.5&&Math.abs(t.top-e.top)<.5&&Math.abs(t.width-e.width)<.5&&Math.abs(t.height-e.height)<.5}function Tv(t){return t===null?t:null}function Mv(t){return t===null?t:null}function Ev(t){t.button===1&&t.preventDefault()}function Rv(t){t.stopPropagation()}function Fv(t){t.stopPropagation()}function Lv(t){t.stopPropagation()}function Yu(t){const e=at.c(14);let n,r,i,a;e[0]!==t?({size:i,className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(n=e[1],r=e[2],i=e[3],a=e[4]);const l=typeof i=="number"?`${i}px`:i,c=typeof i=="number"?`${i}px`:i;let d;e[5]!==a||e[6]!==l||e[7]!==c?(d={width:l,height:c,...a},e[5]=a,e[6]=l,e[7]=c,e[8]=d):d=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=p):p=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:p}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Hr=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"zhipuai-coding-plan",name:"ZhipuAI"}];Hr.reduce((t,e)=>(t[e.id]=e,t),{});const Ov=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),$v=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,ao=(t,e)=>t??$v(e),Ud=(t,e)=>{if(!t)return e??"";try{const n=new Date(t);if(!Number.isFinite(n.getTime()))return e??"";const r=new Date;return n.toDateString()===r.toDateString()?n.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):n.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit"})}catch{return e??""}},bh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Wd=t=>t==="5h"?"5-Hour":t==="7d"?"7-Day Limit":t==="7d-sonnet"?"7-Day Sonnet Limit":t==="7d-opus"?"7-Day Opus Limit":t==="weekly"?"Weekly Limit":t==="daily"?"Daily":t==="monthly"?"Monthly Limit":t==="credits"?"Credits":t==="session"?"Session":t==="premium"?"Premium Interactions":t==="chat"?"Chat Requests":t==="completions"?"Completions":t==="premium_interactions"?"Premium interactions":t,Bv=t=>{const e=t.toLowerCase().trim();if(e==="5h")return 5*3600;if(e==="7d"||e==="weekly"||e==="7d-sonnet"||e==="7d-opus")return 7*86400;if(e==="monthly")return 30*86400;if(e==="24h"||e==="daily")return 86400;if(e==="1h")return 3600;const n=e.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;const r=e.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},oo=(t,e,n,r)=>{let i=n;if(i===null&&r&&(i=Bv(r)),t===null||e===null||i===null||i<=0)return null;const a=Date.now(),l=Math.max(0,(e-a)/1e3),c=Math.max(0,Math.min(i,i-l)),d=Math.max(0,Math.min(1,c/i)),p=t/100,m=t>=100&&l>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let h;m?h="exhausted":p<=d?h="on-track":u<=130?h="slightly-fast":h="too-fast";const x=i>=120*3600,f=x?86400:3600,v=x?"d":"h",y=i/f,g=Math.max(c/f,y*.01),w=t/g,b=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${v}`:"-",k=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let I=null;const j=i/86400;return j>=7&&(I=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:l,isExhausted:m,elapsedSeconds:c,totalSeconds:i,status:h,paceRateText:b,predictText:k,dailyAllocationPercent:I}},zv=t=>{switch(t){case"exhausted":case"too-fast":return"var(--status-error)";case"slightly-fast":return"var(--status-warning)";case"on-track":return"var(--status-success)"}},Qu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),i=Math.floor(r/24),a=r%24,l=n%60;return i>0?`${i}d ${a}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},ei=t=>Math.min(100,Math.max(0,t*100));function gl(t){const e=t.indexOf("/");if(e!==-1){const n=t.substring(0,e);if(n==="gemini"||n==="antigravity")return t.substring(e+1)}return t}const Vv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],yh={google:Vv};function vh(t,e){const n=yh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function wh(t){return yh[t]??[]}function jh(t){return[...t].sort((e,n)=>e.order-n.order)}function _v(t,e){const n=new Map;for(const r of Object.keys(t)){const a=vh(r,e)?.id??null;n.has(a)||n.set(a,[]),n.get(a).push(r)}return n}function Uv(t,e,n){const r=new Map;for(const i of t){const a=e(i),c=vh(a,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(i)}return r}function Wv(t,e){return e.filter(n=>{const r=n.toLowerCase(),i=r.includes("/")?r.split("/")[1]:r;return!!(i.startsWith("gemini-3-")||i.startsWith("claude-"))})}const Kd=6e4,Ju=t=>{const e=Hr.map(u=>u.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):Kd,i=t?.usageDisplayMode==="remaining"?"remaining":"usage",a=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,l=a?a.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,h]of Object.entries(d))Array.isArray(h)&&(c[u]=h.filter(x=>typeof x=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,h]of Object.entries(m))Array.isArray(h)&&(p[u]=h.filter(x=>typeof x=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:i,dropdownProviderIds:l,selectedModels:c,expandedFamilies:p}},Kv=async()=>{const t=pr()?.settings;if(t)try{const n=(await t.load())?.settings;return Ju(n??null)}catch{}if(!mn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Ju(n)}}return{autoRefresh:!1,refreshIntervalMs:Kd,displayMode:"usage",dropdownProviderIds:Hr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ms=gr()(Na((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Kd,displayMode:"usage",dropdownProviderIds:Hr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Kv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Hr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const i=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:i})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),i=await r.json().catch(()=>null);if(!r.ok)throw new Error(i?.error||"Failed to fetch quota");const a=i;t(l=>{const c=l.results.filter(d=>d.providerId!==n);return c.push(a),{results:c,error:null}})}catch(r){const i=r instanceof Error?r.message:"Failed to fetch quota",a={providerId:n,providerName:n,ok:!1,configured:!1,error:i,usage:null,fetchedAt:Date.now()};t(l=>{const c=l.results.filter(d=>d.providerId!==n);return c.push(a),{results:c,error:i}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(i=>({selectedModels:{...i.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(i=>{const a=i.selectedModels[n]??[],c=a.includes(r)?a.filter(d=>d!==r):[...a,r];return{selectedModels:{...i.selectedModels,[n]:c}}})},setExpandedFamilies:(n,r)=>{t(i=>({expandedFamilies:{...i.expandedFamilies,[n]:r}})),ks({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(i=>{const a=i.expandedFamilies[n]??[],c=a.includes(r)?a.filter(d=>d!==r):[...a,r];return{expandedFamilies:{...i.expandedFamilies,[n]:c}}}),ks({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const a=Wv(n,r);a.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:a}})),ks({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Nh=()=>{const t=at.c(5),e=Ms(Hv),n=Ms(Gv),r=Ms(qv);let i,a;t[0]!==e||t[1]!==r||t[2]!==n?(i=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},a=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=a):(i=t[3],a=t[4]),o.useEffect(i,a)};function Hv(t){return t.autoRefresh}function Gv(t){return t.refreshIntervalMs}function qv(t){return t.fetchAllQuotas}const xl=Be.forwardRef((t,e)=>{const n=at.c(11);let r,i;n[0]!==t?({className:r,...i}=t,n[0]=t,n[1]=r,n[2]=i):(r=n[1],i=n[2]);let a;n[3]!==r?(a=ce("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=a):a=n[4];let l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Xg,{className:ce("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=c):c=n[6];let d;return n[7]!==i||n[8]!==e||n[9]!==a?(d=s.jsx(Zg,{className:a,style:l,...i,ref:e,children:c}),n[7]=i,n[8]=e,n[9]=a,n[10]=d):d=n[10],d});xl.displayName="Switch";const Ao=()=>{try{const e=As.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Zs.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},Xu=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],Zu=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Do=t=>typeof t!="string"?void 0:t.trim()||void 0,lc=800,Yv=5e3,Qv="__default__",Zc=new Map,cc=new Map,Sh=t=>t?.trim()||Qv,dc=t=>{Zc.delete(Sh(t))},lo=gr()(Na(mo((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=Ao(),i=Sh(r),a=Date.now(),l=Zc.get(i)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&a-l<Yv)return!0;const d=cc.get(i);if(!n?.force&&d)return d;const p=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",u=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const h=await u.json();return t({mcpServers:h,isLoading:!1}),Zc.set(i,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();cc.set(i,p);try{return await p}finally{cc.delete(i)}},createMcp:async n=>{Xl("Creating MCP server configuration…");let r=!1;try{const i=em(n),a=Ao(),l=a?`?directory=${encodeURIComponent(a)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-opencode-directory":a}:{}},body:JSON.stringify(i)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return dc(a),d?.requiresReload?(r=!0,await Zl({message:d.message,delayMs:d.reloadDelayMs??lc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(i){return console.error("[McpConfigStore] Failed to create MCP:",i),{ok:!1}}finally{r||ec()}},updateMcp:async(n,r)=>{Xl("Updating MCP server configuration…");let i=!1;try{const a=em(r),l=Ao(),c=l?`?directory=${encodeURIComponent(l)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(a)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return dc(l),p?.requiresReload?(i=!0,await Zl({message:p.message,delayMs:p.reloadDelayMs??lc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning})}catch(a){throw console.error("[McpConfigStore] Failed to update MCP:",a),a}finally{i||ec()}},deleteMcp:async n=>{Xl("Deleting MCP server configuration…");let r=!1;try{const i=Ao(),a=i?`?directory=${encodeURIComponent(i)}`:"",l=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${a}`,{method:"DELETE",headers:i?{"x-opencode-directory":i}:void 0}),c=await l.json().catch(()=>null);if(!l.ok)throw new Error(c?.error||"Failed to delete MCP server");return dc(i),c?.requiresReload&&(r=!0,await Zl({message:c.message,delayMs:c.reloadDelayMs??lc,scopes:["all"]})),e().selectedMcpName===n&&t({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(i){return console.error("[McpConfigStore] Failed to delete MCP:",i),{ok:!1}}finally{r||ec()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:Ml(()=>pi()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function em(t){const e={};if(t.scope!==void 0&&(e.scope=t.scope),t.type!==void 0&&(e.type=t.type),(t.type==="local"||t.command!==void 0)&&(e.command=(t.command??[]).filter(n=>n.trim())),(t.type==="remote"||t.url!==void 0)&&(e.url=t.url?.trim()??""),t.environment!==void 0&&(e.environment=Zu(t.environment)??{}),t.headers!==void 0&&(e.headers=Zu(t.headers)??{}),t.oauthEnabled!==void 0||t.oauthClientId!==void 0||t.oauthClientSecret!==void 0||t.oauthScope!==void 0||t.oauthRedirectUri!==void 0)if(t.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:Do(t.oauthClientId),clientSecret:Do(t.oauthClientSecret),scope:Do(t.oauthScope),redirectUri:Do(t.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:t.oauthEnabled?e.oauth={}:e.oauth=!1}if(t.timeout!==void 0){const n=Number(t.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return t.enabled!==void 0&&(e.enabled=t.enabled),e}const Jv={},Xv={},Xr=t=>{if(typeof t!="string")return null;const e=t.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},Ji=t=>Xr(t)??"__global__",wi=t=>{const e=Xr(t);return e?Zs.getScopedApiClient(e):Zs.getApiClient()},yn=gr()(Na((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().byDirectory[r]??Jv},getDiagnosticForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Xv},getErrorForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Xr(n?.directory??$s.getState().currentDirectory),i=Ji(r);n?.silent||t(a=>({loadingKeys:{...a.loadingKeys,[i]:!0},lastErrorKeys:{...a.lastErrorKeys,[i]:null}}));try{const c=(await wi(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[i]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[i]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[i]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[i]:!1},lastErrorKeys:{...d.lastErrorKeys,[i]:null}}))}catch(a){const l=a instanceof Error?a.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[i]:!1},lastErrorKeys:{...c.lastErrorKeys,[i]:l}}))}},connect:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),a=Ji(i),l=wi(i);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(p=>({diagnosticsByDirectory:{...p.diagnosticsByDirectory,[a]:{...p.diagnosticsByDirectory[a]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:i,silent:!0})},disconnect:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory);await wi(i).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},startAuth:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),c=(await wi(i).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,r,i)=>{const a=Xr(i??$s.getState().currentDirectory);await wi(a).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},clearAuth:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory);await wi(i).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},testConnection:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),a=Ji(i),l=wi(i),d=e().getStatusForDirectory(i)[n]?.status==="connected";let p,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(x){p=x instanceof Error?x.message:"Connection failed",t(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[a]:{...f.diagnosticsByDirectory[a]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:i,silent:!0});const u=e().getStatusForDirectory(i)[n],h=u;if(!d&&u?.status==="connected"){try{await l.mcp.disconnect({name:n},{throwOnError:!0})}catch(x){m=`Connection test succeeded, but cleanup disconnect failed: ${x instanceof Error?x.message:"Disconnect failed"}`}await e().refresh({directory:i,silent:!0})}return{status:h??e().getStatusForDirectory(i)[n],error:p,warning:m}}})));function Zv(t){const e=at.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let i;return e[2]!==t?(i=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=i):i=e[3],i}const ew=(t,e)=>{if(!t)return e("mcpDropdown.status.unknown");switch(t.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:t.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:t.error||""});default:return t.status}},tw=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},kh=({active:t,className:e})=>{const{t:n}=ut(),i=$s(g=>g.currentDirectory)??null,a=yn(g=>g.getStatusForDirectory(i)),l=yn(g=>g.refresh),c=yn(g=>g.connect),d=yn(g=>g.disconnect),p=lo(g=>g.mcpServers),m=lo(g=>g.loadMcpConfigs),[u,h]=o.useState(!1),[x,f]=o.useState(null);o.useEffect(()=>{l({directory:i,silent:!0})},[l,i]),o.useEffect(()=>{m({force:!0})},[m]),o.useEffect(()=>{t&&Promise.all([l({directory:i,silent:!0}),m({force:!0})])},[t,l,i,m]);const v=o.useMemo(()=>{const g=new Set(Object.keys(a));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,b)=>w.localeCompare(b))},[p,a]),y=o.useCallback(g=>{if(g?.preventDefault(),u)return;h(!0);const w=new Promise(b=>setTimeout(b,500));Promise.all([l({directory:i}),w]).finally(()=>{h(!1)})},[u,l,i]);return s.jsxs("div",{className:ce("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),i&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:i.split("/").pop()||i})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:u,onClick:y,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(P,{name:"refresh",className:ce("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[v.map(g=>{const w=a[g],b=tw(w),k=w?.status==="connected",I=x===g,j=ew(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:ce("h-2 w-2 rounded-full flex-shrink-0",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Dt,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(xl,{checked:k,disabled:I,className:"data-[checked]:bg-status-info",onCheckedChange:async N=>{f(g);try{N?await c(g,i):await d(g,i)}finally{f(null)}}})]},g)}),v.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},co=t=>{const e=at.c(20),{percent:n,tonePercent:r,className:i,expectedMarkerPercent:a}=t;let l;e[0]!==n?(l=Ov(n)??0,e[0]=n,e[1]=l):l=e[1];const c=l,d=r??n;let p;e[2]!==d?(p=bh(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=a!=null?Math.max(0,Math.min(100,a)):null;let h;e[4]!==m?(h=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=h):h=e[5];const x=h;let f;e[6]!==i?(f=ce("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=f):f=e[7];const v=`${c}%`;let y;e[8]!==x||e[9]!==v?(y={...x,width:v},e[8]=x,e[9]=v,e[10]=y):y=e[10];let g;e[11]!==c||e[12]!==y?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:y,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=y,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let b;return e[16]!==f||e[17]!==g||e[18]!==w?(b=s.jsxs("div",{className:f,children:[g,w]}),e[16]=f,e[17]=g,e[18]=w,e[19]=b):b=e[19],b},uo=t=>{const e=at.c(67),{paceInfo:n,className:r,compact:i}=t,a=i===void 0?!1:i,{t:l}=ut();let c;e[0]!==n.status?(c=zv(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let N;e[2]!==l?(N=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=N):N=e[3],p=N;break e}case"slightly-fast":{let N;e[4]!==l?(N=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=N):N=e[5],p=N;break e}case"too-fast":{let N;e[6]!==l?(N=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=N):N=e[7],p=N;break e}case"exhausted":{let N;e[8]!==l?(N=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=N):N=e[9],p=N;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==l?(u=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=u):u=e[12];const h=u;if(a){let N;e[13]!==r?(N=ce("flex items-center gap-1.5",r),e[13]=r,e[14]=N):N=e[14];let D;e[15]!==d?(D={backgroundColor:d},e[15]=d,e[16]=D):D=e[16];let E;e[17]!==m||e[18]!==D?(E=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:D,title:m}),e[17]=m,e[18]=D,e[19]=E):E=e[19];let T;e[20]!==d?(T={color:d},e[20]=d,e[21]=T):T=e[21];const C=n.isExhausted?void 0:h;let S;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(S=n.isExhausted?s.jsx(s.Fragment,{children:l("settings.usage.pace.wait",{duration:Qu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=S):S=e[26];let M;e[27]!==S||e[28]!==T||e[29]!==C?(M=s.jsx("span",{className:"typography-micro tabular-nums",style:T,title:C,children:S}),e[27]=S,e[28]=T,e[29]=C,e[30]=M):M=e[30];let A;return e[31]!==M||e[32]!==N||e[33]!==E?(A=s.jsxs("div",{className:N,children:[E,M]}),e[31]=M,e[32]=N,e[33]=E,e[34]=A):A=e[34],A}let x;e[35]!==r?(x=ce("flex items-center justify-between gap-2",r),e[35]=r,e[36]=x):x=e[36];let f;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(f=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=f):f=e[40];let v;e[41]!==f?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:f}),e[41]=f,e[42]=v):v=e[42];let y;e[43]!==d?(y={color:d},e[43]=d,e[44]=y):y=e[44];let g;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==h||e[49]!==m||e[50]!==l?(g=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:Qu(n.remainingSeconds)})]}):s.jsxs("span",{title:h,children:[s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=h,e[49]=m,e[50]=l,e[51]=g):g=e[51];let w;e[52]!==y||e[53]!==g?(w=s.jsx("span",{className:"typography-micro tabular-nums",style:y,children:g}),e[52]=y,e[53]=g,e[54]=w):w=e[54];let b;e[55]!==d?(b={backgroundColor:d},e[55]=d,e[56]=b):b=e[56];let k;e[57]!==m||e[58]!==b?(k=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:b,title:m}),e[57]=m,e[58]=b,e[59]=k):k=e[59];let I;e[60]!==w||e[61]!==k?(I=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,k]}),e[60]=w,e[61]=k,e[62]=I):I=e[62];let j;return e[63]!==I||e[64]!==x||e[65]!==v?(j=s.jsxs("div",{className:x,children:[v,I]}),e[63]=I,e[64]=x,e[65]=v,e[66]=j):j=e[66],j},fr=ex,Pr=t=>{const e=at.c(14);let n,r,i,a;e[0]!==t?({className:i,asChild:n,children:r,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(n=e[1],r=e[2],i=e[3],a=e[4]);let l;e[5]!==n||e[6]!==r?(l=n&&Be.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=l):l=e[7];const c=l;let d;e[8]!==i?(d=ce("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",i),e[8]=i,e[9]=d):d=e[9];let p;return e[10]!==a||e[11]!==c||e[12]!==d?(p=s.jsx(tx,{className:d,...a,...c}),e[10]=a,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},hr=t=>{const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(sx,{className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a},hi=[{id:"finder",label:"Finder",appName:"Finder"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm"},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"xcode",label:"Xcode",appName:"Xcode"},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"zed",label:"Zed",appName:"Zed"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"kiro",label:"Kiro",appName:"Kiro"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],ed="finder",td=new Set(["finder","terminal"]),sd=t=>t?hi.find(e=>e.id===t)??null:null,uc=()=>hi.filter(t=>td.has(t.id)).map(t=>({...t})),sw=()=>{if(typeof window>"u")return ed;const t=window.localStorage.getItem("openInAppId");return t&&sd(t)?t:ed};let mc=!1,Xi=!1,ci=!1,di=0,qa=null;const tm=()=>{qa&&(clearTimeout(qa),qa=null)},Lr=gr()((t,e)=>({selectedAppId:sw(),availableApps:uc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(mc||typeof window>"u")return;mc=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:uc(),hasLoadedApps:p});return}const m=new Set(d.map(f=>f.name)),u=new Map(d.map(f=>[f.name,f.iconDataUrl??void 0])),x=hi.filter(f=>m.has(f.appName)||td.has(f.id)).map(f=>({...f,iconDataUrl:u.get(f.appName)}));t({availableApps:x,hasLoadedApps:!0})},r=async d=>{if(!pa()||!Bi()||Xi||e().hasLoadedApps&&!d)return;const m=hi.map(u=>u.appName);tm(),Xi=!0,ci=!1,t({isScanning:!0});try{const{apps:u,success:h,hasCache:x,isCacheStale:f}=await bu(m,d),v=h&&!x&&u.length===0&&di<3;if(t({isCacheStale:x?f:!1}),n(u,h?!v:!1),h){if(v){const g=[800,1600,3200][di]??3200;di+=1,ci=!0,qa=setTimeout(()=>{r()},g);return}di=0,ci=!1;return}if(di<3){const g=[1e3,3e3,7e3][di]??7e3;di+=1,ci=!0,qa=setTimeout(()=>{r()},g)}}finally{Xi=!1,ci||t({isScanning:!1})}};r();const i=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&sd(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},a=()=>{r()},l=d=>{const p=d.detail;Array.isArray(p)&&(di=3,ci=!1,t({isScanning:!1,isCacheStale:!1}),n(p))};window.addEventListener("vinci:settings-synced",i),window.addEventListener("vinci:app-ready",a),window.addEventListener("vinci:installed-apps-updated",l),window.__vinciAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(mc||e().initialize(),!pa()||!Bi()||Xi||e().hasLoadedApps&&!n)return;const i=hi.map(a=>a.appName);tm(),n&&t({hasLoadedApps:!1}),Xi=!0,ci=!1,t({isScanning:!0});try{const{apps:a,hasCache:l,isCacheStale:c}=await bu(i,n),d=new Set(a.map(h=>h.name)),p=new Map(a.map(h=>[h.name,h.iconDataUrl??void 0])),u=hi.filter(h=>d.has(h.appName)||td.has(h.id)).map(h=>({...h,iconDataUrl:p.get(h.appName)}));t({availableApps:u.length>0?u:uc(),hasLoadedApps:u.length>0,isCacheStale:l?c:!1})}finally{Xi=!1,ci||t({isScanning:!1})}},selectApp:async n=>{sd(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ks({openInAppId:n}))}})),nw="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",rw="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",pc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?nw:t.id==="terminal"?rw:void 0}),sm=t=>{const e=at.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=t,[a,l]=o.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||i;if(p&&!a){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>l(!0),e[2]=h):h=e[2];let x;return e[3]!==p?(x=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:h}),e[3]=p,e[4]=x):x=e[4],x}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=ce("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},iw=t=>{const e=at.c(82),{directory:n,className:r}=t,{t:i}=ut(),a=Lr(aw),l=Lr(ow),c=Lr(lw),d=Lr(cw),p=Lr(dw),m=Lr(uw),u=Lr(mw);let h,x;e[0]!==p?(h=()=>{p()},x=[p],e[0]=p,e[1]=h,e[2]=x):(h=e[1],x=e[2]),o.useEffect(h,x);const f=pa()&&Bi();let v;e:{let K;e[3]!==l||e[4]!==a?(K=l.find(re=>re.id===a)??l.find(pw)??l[0]??hi[0],e[3]=l,e[4]=a,e[5]=K):K=e[5];const ae=K;if(ae){let re;e[6]!==ae?(re=pc(ae),e[6]=ae,e[7]=re):re=e[7],v=re;break e}let ve;e[8]===Symbol.for("react.memo_cache_sentinel")?(ve=pc(hi[0]),e[8]=ve):ve=e[8],v=ve}const y=v;if(!f||!n||l.length===0)return null;let g;e[9]!==n?(g=async K=>{await Bx(n,K.id,K.appName)||await ul(n,K.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let b;e[11]!==w||e[12]!==u?(b=async K=>{await u(K.id),await w(K)},e[11]=w,e[12]=u,e[13]=b):b=e[13];const k=b;let I;e[14]!==n||e[15]!==i?(I=async()=>{(await _n(n)).ok&&H.success(i("openInApp.toast.pathCopied"))},e[14]=n,e[15]=i,e[16]=I):I=e[16];const j=I;let N;e[17]!==r?(N=ce("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=N):N=e[18];let D;e[19]!==w||e[20]!==y?(D=()=>{w(y)},e[19]=w,e[20]=y,e[21]=D):D=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=ce("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=E):E=e[22];let T;e[23]!==y.label||e[24]!==i?(T=i("openInApp.actions.openInAria",{app:y.label}),e[23]=y.label,e[24]=i,e[25]=T):T=e[25];let C;e[26]!==y.fallbackIconDataUrl||e[27]!==y.iconDataUrl||e[28]!==y.label?(C=s.jsx(sm,{label:y.label,iconDataUrl:y.iconDataUrl,fallbackIconDataUrl:y.fallbackIconDataUrl}),e[26]=y.fallbackIconDataUrl,e[27]=y.iconDataUrl,e[28]=y.label,e[29]=C):C=e[29];const S=d?"animate-pulse text-muted-foreground":void 0;let M;e[30]!==S?(M=ce("header-open-label",S),e[30]=S,e[31]=M):M=e[31];let A;e[32]!==i?(A=i("openInApp.actions.open"),e[32]=i,e[33]=A):A=e[33];let R;e[34]!==M||e[35]!==A?(R=s.jsx("span",{className:M,children:A}),e[34]=M,e[35]=A,e[36]=R):R=e[36];let z;e[37]!==T||e[38]!==C||e[39]!==R||e[40]!==D?(z=s.jsxs("button",{type:"button",onClick:D,className:E,"aria-label":T,children:[C,R]}),e[37]=T,e[38]=C,e[39]=R,e[40]=D,e[41]=z):z=e[41];let B;e[42]===Symbol.for("react.memo_cache_sentinel")?(B=ce("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[42]=B):B=e[42];let V;e[43]!==i?(V=i("openInApp.actions.chooseAppAria"),e[43]=i,e[44]=V):V=e[44];let $;e[45]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4"}),e[45]=$):$=e[45];let _;e[46]!==V?(_=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:B,"aria-label":V,children:$})}),e[46]=V,e[47]=_):_=e[47];let X;e[48]===Symbol.for("react.memo_cache_sentinel")?(X={translate:"-30px 0"},e[48]=X):X=e[48];let O;e[49]!==j?(O=()=>{j()},e[49]=j,e[50]=O):O=e[50];let J;e[51]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(P,{name:"file-copy",className:"h-4 w-4"}),e[51]=J):J=e[51];let Q;e[52]!==i?(Q=i("openInApp.actions.copyPath"),e[52]=i,e[53]=Q):Q=e[53];let ne;e[54]!==Q?(ne=s.jsx("span",{className:"typography-ui-label text-foreground",children:Q}),e[54]=Q,e[55]=ne):ne=e[55];let G;e[56]!==O||e[57]!==ne?(G=s.jsxs($t,{className:"flex items-center gap-2",onClick:O,children:[J,ne]}),e[56]=O,e[57]=ne,e[58]=G):G=e[58];let le;e[59]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(Cn,{}),e[59]=le):le=e[59];let oe;if(e[60]!==l||e[61]!==k||e[62]!==y.id){let K;e[64]!==k||e[65]!==y.id?(K=ae=>{const ve=pc(ae);return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{k(ae)},children:[s.jsx(sm,{label:ae.label,iconDataUrl:ae.iconDataUrl,fallbackIconDataUrl:ve.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ae.label}),y.id===ae.id?s.jsx(P,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ae.id)},e[64]=k,e[65]=y.id,e[66]=K):K=e[66],oe=l.map(K),e[60]=l,e[61]=k,e[62]=y.id,e[63]=oe}else oe=e[63];let F;e[67]!==c||e[68]!==m||e[69]!==i?(F=c?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(P,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=i,e[70]=F):F=e[70];let U;e[71]!==G||e[72]!==oe||e[73]!==F?(U=s.jsxs(Rs,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:X,children:[G,le,oe,F]}),e[71]=G,e[72]=oe,e[73]=F,e[74]=U):U=e[74];let W;e[75]!==_||e[76]!==U?(W=s.jsxs(Fs,{children:[_,U]}),e[75]=_,e[76]=U,e[77]=W):W=e[77];let te;return e[78]!==z||e[79]!==W||e[80]!==N?(te=s.jsxs("div",{className:N,children:[z,W]}),e[78]=z,e[79]=W,e[80]=N,e[81]=te):te=e[81],te};function aw(t){return t.selectedAppId}function ow(t){return t.availableApps}function lw(t){return t.isCacheStale}function cw(t){return t.isScanning}function dw(t){return t.initialize}function uw(t){return t.loadInstalledApps}function mw(t){return t.selectApp}function pw(t){return t.id===ed}const fw=1e6,hw="terminal-store";let nm=!1;const fc=t=>typeof t=="object"&&t!==null,gw=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Wn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const hc=(t,e)=>({id:t,terminalSessionId:null,lifecycle:"idle",label:e,iconKey:null,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Ch=/\x1b\[[0-9;]*m/g,xw=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,bw=new Set([".",",",";",":","!","?"]),yw=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",i=e.slice(0,-1),a=(i.match(new RegExp(`\\${r}`,"g"))||[]).length,l=(i.match(new RegExp(`\\${n}`,"g"))||[]).length;if(a>l)break;e=i;continue}if(bw.has(n)){e=e.slice(0,-1);continue}break}return e},vw=t=>{if(!t)return null;const n=t.replace(Ch,"").match(xw);if(!n?.[1])return null;let r=yw(n[1]);return r=r.replace("0.0.0.0","127.0.0.1"),r=r.replace("[::1]","127.0.0.1"),r=r.replace("[::]","127.0.0.1"),r},ww=t=>{if(!t)return null;const n=t.replace(Ch,"").match(/Serving HTTP on .*? port (\d{2,5})/i);if(!n?.[1])return null;const r=Number.parseInt(n[1],10);return!Number.isFinite(r)||r<=0||r>65535?null:`http://127.0.0.1:${r}/`},gc=t=>({tabs:[t],activeTabId:t.id}),Rr=(t,e)=>t.tabs.findIndex(n=>n.id===e),on=gr()(Na(mo((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Wn(n);r&&t(i=>{if(i.sessions.has(r))return i;const a=new Map(i.sessions),l=`tab-${i.nextTabId}`,c=hc(l,"Terminal");return a.set(r,gc(c)),{sessions:a,nextTabId:i.nextTabId+1}})},getDirectoryState:n=>{const r=Wn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Wn(n),i=e().sessions.get(r);if(!i)return;const a=i.activeTabId;return a?i.tabs.find(l=>l.id===a)??i.tabs[0]:i.tabs[0]},createTab:n=>{const r=Wn(n);if(!r)return"tab-invalid";const i=`tab-${e().nextTabId}`;return t(a=>{const l=new Map(a.sessions),c=l.get(r),d=a.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=hc(i,m);return c?l.set(r,{...c,tabs:[...c.tabs,u]}):l.set(r,gc(u)),{sessions:l,nextTabId:d}}),i},setActiveTab:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);return!c||c.activeTabId===r||Rr(c,r)<0?a:(l.set(i,{...c,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,i)=>{const a=Wn(n),l=i.trim();l&&t(c=>{const d=new Map(c.sessions),p=d.get(a);if(!p)return c;const m=Rr(p,r);if(m<0||p.tabs[m]?.label===l)return c;const u=[...p.tabs];return u[m]={...u[m],label:l},d.set(a,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=i?.trim()||null;if(d.tabs[p]?.iconKey===m)return l;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(a,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const i=Wn(n),c=e().sessions.get(i)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await Lx(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(i);if(!m)return d;const u=Rr(m,r);if(u<0)return d;const h=m.tabs.filter(y=>y.id!==r),x=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,y])=>!(y.directory===i&&y.tabId===r))),f=Object.keys(x).length!==Object.keys(d.projectActionRuns).length;if(h.length===0){const y=`tab-${d.nextTabId}`,g=hc(y,"Terminal");return p.set(i,gc(g)),{sessions:p,nextTabId:d.nextTabId+1,...f?{projectActionRuns:x}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=h[Math.min(u,h.length-1)]?.id??h[0]?.id??null),p.set(i,{...m,tabs:h,activeTabId:v}),{sessions:p,...f?{projectActionRuns:x}:{}}})},setTabSessionId:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=d.tabs[p],u=i!==null&&m.terminalSessionId!==i,h=i?"running":m.terminalSessionId?"exited":m.lifecycle,x={...m,terminalSessionId:i,lifecycle:h,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},f=[...d.tabs];return f[p]=x,c.set(a,{...d,tabs:f}),{sessions:c}})},setTabLifecycle:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=[...d.tabs];return m[p]={...m[p],lifecycle:i,isConnecting:!1},c.set(a,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=[...d.tabs];return m[p]={...m[p],isConnecting:i},c.set(a,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,i)=>{if(!i)return;const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=d.tabs[p],u=l.nextChunkId,h={id:u,data:i},x=[...m.bufferChunks,h];let f=m.bufferLength+i.length;for(;f>fw&&x.length>1;){const w=x.shift();if(!w)break;f-=w.data.length}const v=m.previewUrlLocked?null:vw(i)??ww(i),y=!!(v&&v!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:x,bufferLength:f,...y?{previewUrl:v,previewAutoOpened:!1}:null},c.set(a,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,i,a={})=>{const l=Wn(n);t(c=>{const d=new Map(c.sessions),p=d.get(l);if(!p)return c;const m=Rr(p,r);if(m<0)return c;const u=p.tabs[m],h=a.autoOpened??u.previewAutoOpened,x=a.locked??u.previewUrlLocked;if(u.previewUrl===i&&u.previewAutoOpened===h&&u.previewUrlLocked===x)return c;const f=[...p.tabs];return f[m]={...u,previewUrl:i,previewAutoOpened:h,previewUrlLocked:x},d.set(l,{...p,tabs:f}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);if(!c)return a;const d=Rr(c,r);if(d<0)return a;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return a;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},l.set(i,{...c,tabs:m}),{sessions:l}})},setProjectActionRun:n=>{t(r=>{const i=r.projectActionRuns[n.key];return i&&i.directory===n.directory&&i.actionId===n.actionId&&i.tabId===n.tabId&&i.sessionId===n.sessionId&&i.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(i=>{const a=i.projectActionRuns[n];return!a||a.status===r?i:{projectActionRuns:{...i.projectActionRuns,[n]:{...a,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const i={...r.projectActionRuns};return delete i[n],{projectActionRuns:i}})},clearBuffer:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);if(!c)return a;const d=Rr(c,r);if(d<0)return a;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},l.set(i,{...c,tabs:p}),{sessions:l}})},removeDirectory:n=>{const r=Wn(n);t(i=>{const a=new Map(i.sessions);a.delete(r);const l=Object.fromEntries(Object.entries(i.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:a,projectActionRuns:l}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:hw,storage:Ml(()=>_f()),partialize:t=>({sessions:Array.from(t.sessions.entries()).map(([e,n])=>[e,{activeTabId:n.activeTabId,tabs:n.tabs.map(r=>({id:r.id,label:r.label,iconKey:r.iconKey,terminalSessionId:r.terminalSessionId,lifecycle:r.lifecycle,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!fc(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let i=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,p]=c;if(typeof d!="string"||!fc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const f of m){if(!fc(f))continue;const v=typeof f.id=="string"?f.id:null;if(!v)continue;const y=gw(v);y!==null&&(i=Math.max(i,y));const g=typeof f.terminalSessionId=="string"||f.terminalSessionId===null?f.terminalSessionId:null,w=f.lifecycle,b=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:v,label:typeof f.label=="string"?f.label:"Terminal",iconKey:typeof f.iconKey=="string"?f.iconKey:null,terminalSessionId:g,lifecycle:b,createdAt:typeof f.createdAt=="number"?f.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const h=typeof p.activeTabId=="string"?p.activeTabId:null,x=h?u.some(f=>f.id===h):!1;r.set(d,{tabs:u,activeTabId:x?h:u[0].id})}const a=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,l=Math.max(e.nextTabId,a,i+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!nm){nm=!0;const t=on.persist,e=()=>{on.getState().hasHydrated||on.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const rm=(t,e)=>e.updatedAtMs-t.updatedAtMs,Ys=gr((t,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){t({isLoading:!0,error:null});try{const[n,r]=await Promise.all([Ux(),vu()]),i={};for(const a of r.sort(rm))i[a.id]=a;e().listenerReady||await Wx(a=>{t(l=>({statusesById:{...l.statusesById,[a.id]:a}}))}),t({instances:n.instances,statusesById:i,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await _x();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await vu(),r={};for(const i of n.sort(rm))r[i.id]=i;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await Vx({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,i=r.some(a=>a.id===n.id)?r.map(a=>a.id===n.id?n:a):[n,...r];await e().setInstances(i)},createFromCommand:async(n,r,i)=>{const a=Kx(n,r);i&&i.trim()&&(a.nickname=i.trim()),await e().upsertInstance(a)},removeInstance:async n=>{await yu(n).catch(()=>{});const r=e().instances.filter(i=>i.id!==n);await e().setInstances(r),t(i=>{const a={...i.statusesById};return delete a[n],{statusesById:a}})},connect:async n=>{t({error:null});try{await zx(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{t({error:null});try{await yu(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>t({error:null})})),Ph=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],Zo=Object.fromEntries(Ph.map(t=>[t.key,t.Icon])),nd="vinci:project-actions-updated",Ih=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ui=(t,e)=>`${Ih(t)}::${e}`,jw=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},im=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},Nw=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=im(e.localPort),r=im(e.remotePort);if(!n||!r)return null;const i=jw(e.localHost||t.localForward.bindHost||"127.0.0.1"),a=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${i}:${n} -> ${a}:${r}`,url:`http://${i}:${n}`}},Ah=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const i=Nw(n,r);i&&e.push(i)}return e},Sw=(t,e)=>{const n=(t||"").trim();return n&&Ah(e).find(a=>a.id===n)?.url||null},kw=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Cw=["dev","start","preview","serve"];async function Pw(t,e,n){if(!t)return null;const r=Dw(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const i=Tw(n);if(i){const a=await Mw(t);return{command:`${a==="npm"?"npm run":a==="yarn"?"yarn":a==="pnpm"?"pnpm":a==="bun"?"bun run --shell=bun":"npm run"} ${i}`,label:`Start (${i})`}}}if(await Iw(t)){const i=await Aw(),a=typeof i=="number"&&Number.isFinite(i)&&i>0?i:8e3;return{command:`python3 -m http.server ${a}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${a}/`}}return null}async function Iw(t){const e=`${t}/index.html`,n=await bl(e);return typeof n=="string"&&n.trim().length>0}async function Aw(){try{const t=await fetch("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Dw(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Cw.some(i=>n.includes(i)))return e}return null}function Tw(t){for(const{pattern:e}of kw)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Mw(t){const e=await bl(`${t}/package.json`);if(e)try{const r=JSON.parse(e),i=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(i.startsWith("bun@"))return"bun";if(i.startsWith("pnpm@"))return"pnpm";if(i.startsWith("yarn@"))return"yarn";if(i.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,i]of n){const a=await bl(`${t}/${r}`);if(typeof a=="string"&&a.trim().length>0)return i}return"npm"}async function bl(t){const e=pr()?.files;if(e?.readFile)try{const n=await e.readFile(t,{optional:!0});return typeof n?.content=="string"?n.content:null}catch{return null}try{const n=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return n.ok?n.text():null}catch{return null}}async function Ew(t){try{const e=await bl(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const Rw=t=>new Promise(e=>{window.setTimeout(e,t)}),Fw="\x1B",Lw=new RegExp(`${Fw}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Ow=/https?:\/\/[^\s<>'"`]+/gi,or="__vinci_auto_discover_preview__",$w=15e3,Bw=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},zw=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},Vw=t=>{const n=t.replace(Lw,"").match(Ow);if(!n||n.length===0)return null;const r=n.map(a=>a.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const i=[];for(const a of r)try{const l=new URL(a);l.port&&l.port.length>0&&i.push({raw:a,parsed:l})}catch{}if(i.length>0){const a=l=>{const{parsed:c}=l,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,h=m==="/"||m==="",x=!!(c.search||c.hash);let f=0;return p&&(f+=50),h&&(f+=30),f-=Math.min(u*5,20),x&&(f-=10),f};return i.sort((l,c)=>a(c)-a(l)),i[0]?.parsed.origin??i[0]?.raw??null}return r[0]??null},_w=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const i=r[0],a=r[1].slice(0,3),l=`${i} ${a}`.trim();return r.length>2||l.length<n.length?`${l}...`:l}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},am=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:i=!1})=>{const{t:a}=ut(),{terminal:l,runtime:c}=Pn(),{isMobile:d}=rn(),p=o.useMemo(()=>gn(),[]),m=Ys(q=>q.instances),u=Ys(q=>q.load),h=Ie(q=>q.setBottomTerminalOpen),x=Ie(q=>q.setActiveMainTab),f=Ie(q=>q.setSettingsPage),v=Ie(q=>q.setSettingsDialogOpen),y=Ie(q=>q.setSettingsProjectsSelectedId),g=Ie(q=>q.openContextPreview),w=on(q=>q.sessions),b=on(q=>q.ensureDirectory),k=on(q=>q.setTabLabel),I=on(q=>q.setTabIconKey),j=on(q=>q.setActiveTab),N=on(q=>q.setConnecting),D=on(q=>q.setTabSessionId),E=on(q=>q.setTabPreviewUrl),T=on(q=>q.projectActionRuns),C=on(q=>q.setProjectActionRun),S=on(q=>q.updateProjectActionRunStatus),M=on(q=>q.removeProjectActionRun),[A,R]=o.useState([]),[z,B]=o.useState(null),[V,$]=o.useState(!1),_=o.useRef({}),X=o.useRef({}),O=o.useRef({}),J=o.useRef({}),Q=o.useRef(0),ne=t?.id??null,G=t?.path??"",le=o.useMemo(()=>ne?{id:ne,path:G}:null,[ne,G]);o.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const oe=o.useCallback(async q=>{await rr(q)},[]),F=o.useCallback(async()=>{if(!le)return;const q=Q.current+1;Q.current=q,$(!0);try{const Se=await Yc(le);if(Q.current!==q)return;const $e=Se.actions;R($e),B(Pe=>Pe===or||Pe&&$e.some(fe=>fe.id===Pe)?Pe:null)}catch{if(Q.current!==q)return}finally{Q.current===q&&$(!1)}},[le]),U=o.useMemo(()=>Ih(e||le?.path||""),[e,le?.path]),W=o.useMemo(()=>z?A.find(q=>q.id===z)??null:null,[A,z]),te=o.useMemo(()=>({id:or,name:a("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[a]),K=!d,ae=o.useMemo(()=>K?[te,...A]:A,[A,te,K]);o.useEffect(()=>{F()},[F]),o.useEffect(()=>{if(typeof window>"u")return;const q=Se=>{const $e=Se.detail;ne&&($e?.projectId&&$e.projectId!==ne||F())};return window.addEventListener(nd,q),()=>{window.removeEventListener(nd,q)}},[F,ne]),o.useEffect(()=>{z&&(z===or&&K||A.some(q=>q.id===z)||B(null))},[A,K,z]),o.useEffect(()=>{for(const[q,Se]of Object.entries(T)){const Pe=w.get(Se.directory)?.tabs.find(fe=>fe.id===Se.tabId);(!Pe||Pe.terminalSessionId!==Se.sessionId)&&M(q)}},[T,M,w]),o.useEffect(()=>{for(const[q,Se]of Object.entries(T)){const $e=X.current[q]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};X.current[q]=$e;const Pe=ae.find(de=>de.id===Se.actionId);if(!Pe)continue;const L=w.get(Se.directory)?.tabs.find(de=>de.id===Se.tabId);if(!L||!Array.isArray(L.bufferChunks)||L.bufferChunks.length===0)continue;const Z=L.bufferChunks.filter(de=>$e.lastSeenChunkId===null?!0:de.id>$e.lastSeenChunkId);if(Z.length===0)continue;const Y=Z.map(de=>de.data).join(""),Ee=`${$e.tail}${Y}`,Ae=!$e.openedUrl&&Pe.autoOpenUrl===!0?Vw(Ee):null,Je=Z[Z.length-1]?.id??$e.lastSeenChunkId;if($e.lastSeenChunkId=Je,$e.tail=Ee.slice(-512),Ae)if($e.openedUrl=!0,$e.openInPreview){const de=T[q];de&&(E(de.directory,de.tabId,Ae,{locked:!1,autoOpened:!1}),de.status==="waiting-for-preview"&&S(q,"running"),window.clearTimeout(J.current[q]),delete J.current[q],g(de.directory,Ae))}else oe(Ae),H.success(a("projectActions.toast.openedUrlFromOutput"));X.current[q]=$e}for(const q of Object.keys(X.current))T[q]||(delete X.current[q],window.clearTimeout(J.current[q]),delete J.current[q])},[ae,g,oe,T,E,a,w,S]);const ve=o.useCallback(async(q,Se={})=>{if(!U)throw new Error(a("projectActions.error.noActiveDirectory"));const $e=ui(U,q.id);b(U);const Pe=on.getState(),fe=Pe.getDirectoryState(U);let L=_.current[$e]||null;const Z=L?!!fe?.tabs.some(Ae=>Ae.id===L):!1;(!L||!Z)&&(L=Pe.createTab(U),_.current[$e]=L),k(U,L,`Action: ${q.name}`),I(U,L,q.icon||"play"),Se.revealTerminal!==!1&&(j(U,L),h(!0),x("terminal"));const Ee=on.getState().getDirectoryState(U)?.tabs.find(Ae=>Ae.id===L);return{key:$e,tabId:L,sessionId:Ee?.terminalSessionId??null}},[b,U,x,j,h,I,k,a]),re=o.useCallback(async q=>{if(c.isVSCode||!i&&d)return;if(!U){H.error(a("projectActions.error.noActiveDirectoryForAction"));return}const Se=ui(U,q.id),$e=T[Se];if(!($e&&$e.status==="running"))try{const Pe=q.id===or?await(async()=>{const[Re,Xe]=await Promise.all([Yc({id:le?.id??"",path:U}),Ew(U)]),qe=await Pw(U,Re.actions,Xe);if(!qe)throw new Error(a("contextPanel.preview.noDevServer"));return{id:or,name:a("projectActions.actions.autoDiscover"),command:qe.command,icon:"search",autoOpenUrl:!0,openUrl:qe.previewUrlHint||""}})():q,fe=Pe.autoOpenUrl===!0&&(Pe.openUrl||"").trim().length>0,{key:L,tabId:Z,sessionId:Y}=await ve(Pe,{revealTerminal:!fe&&q.id!==or});let Ee=Y,Ae=!1;if(!Ee){N(U,Z,!0);try{Ee=(await l.createSession({cwd:U})).sessionId,Ae=!0,D(U,Z,Ee)}finally{N(U,Z,!1)}}if(!Ee)throw new Error(a("projectActions.error.failedToCreateTerminalSession"));Ae&&await Rw(350),Pe.id===or&&(O.current[L]?.(),N(U,Z,!0),O.current[L]=Ox(Ee,Re=>{Re.type==="data"&&typeof Re.data=="string"&&Re.data.length>0&&on.getState().appendToBuffer(U,Z,Re.data),Re.type==="exit"&&(on.getState().setTabLifecycle(U,Z,"exited"),on.getState().setConnecting(U,Z,!1),on.getState().removeProjectActionRun(L),delete X.current[L],O.current[L]?.(),delete O.current[L],window.clearTimeout(J.current[L]),delete J.current[L])},()=>{on.getState().setConnecting(U,Z,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Je=Pe.autoOpenUrl===!0&&p&&(Pe.desktopOpenSshForward||"").trim().length>0,de=Pe.autoOpenUrl?zw(Pe.openUrl):null,ze=Pe.autoOpenUrl&&p?Sw(Pe.desktopOpenSshForward,m):null;C({key:L,directory:U,actionId:Pe.id,tabId:Z,sessionId:Ee,status:Pe.id===or&&!de?"waiting-for-preview":"running"}),window.clearTimeout(J.current[L]),delete J.current[L],Pe.id===or&&!de&&(J.current[L]=window.setTimeout(()=>{on.getState().updateProjectActionRunStatus(L,"running"),delete J.current[L]},$w)),ze?(E(U,Z,null,{locked:!0}),oe(ze),H.success(a("projectActions.toast.openedForwardedUrl"))):de?(E(U,Z,de,{locked:!0,autoOpened:!0}),g(U,de),H.success(a("projectActions.toast.openedActionUrl"))):fe?(E(U,Z,null,{locked:!0}),H.error(a("projectActions.error.invalidCustomUrlFormat"))):Je?(E(U,Z,null,{locked:!0}),H.error(a("projectActions.error.selectedDesktopSshForwardUnavailable"))):E(U,Z,null,{locked:!1,autoOpened:!1}),X.current[L]={lastSeenChunkId:null,openedUrl:!!ze||!!de||fe,tail:"",openInPreview:Pe.id===or};const rt=Bw(Pe.command.trim().replace(/\r\n|\r/g,`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-B9l0ZNi2.js","assets/vendor--DBfsbEis.css","assets/modelPrefsAutoSave-z_3gcNaV.js","assets/index-DgiFEKGN.js","assets/index-DLTDToSP.css","assets/TerminalView-CykGfmvO.js","assets/JsonTreeView-CoBDQpso.js","assets/SettingsWindow-I9We0AUb.js","assets/MultiRunWindow-I3lRPicR.js","assets/OnboardingScreen-1fIy0izk.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{aI as at,Z as o,bF as Ja,bE as oa,b5 as s,bH as Dl,C as Tl,Q as Xa,ac as cl,a_ as Jg,p as dl,o as Za,aG as eo,aL as gr,aS as Na,bh as Be,ag as Xg,af as Zg,bd as mo,aM as Ml,d as ex,e as tx,c as sx,ax as kr,bg as Wa,aB as Ef,bK as Hc,ay as Hi,bJ as Rf,aw as nx,av as rx,aq as ix,s as ax,ar as ox,bG as Br,q as lx,r as Xn,aV as cx,f as Sa,b8 as mu,aY as dx,b0 as ux,b6 as Ql,b1 as mx,aR as px,aZ as fx,bq as pu,bo as fu,ap as hx,Y as Ff,g as Lf,ad as gx,bp as hu,aT as xx,bc as bx,aF as yx,au as vx,E as wx,ae as jx,br as Nx,be as Of,b9 as Sx,a$ as Gc,aO as $f,b4 as Bf,b3 as ra,bv as Ba,H as qc,bw as ot,L as zf,b7 as Vf,aQ as kx,aD as Cx,F as Px,aJ as Ix,aX as Ax,X as Dx,bB as Tx,bC as Mx,K as Ex,bs as Rx,bD as gu,az as xu,bb as Jl,aE as Fx}from"./vendor-.bun-B9l0ZNi2.js";import{g as Lx,h as Ox,w as $x}from"./index-DgiFEKGN.js";import{ew as ut,eZ as Ie,e6 as rn,aG as ce,P,dW as ks,cF as mn,bY as pr,c2 as pi,dI as Xl,d4 as Zl,bh as ec,eE as As,cY as Zs,e8 as $s,ao as Pt,ar as It,ap as Dt,cE as pa,cp as Bi,bc as bu,x as $t,cW as Bx,cV as ul,aI as _n,dS as H,J as Es,F as Cn,w as Rs,v as Fs,c1 as _f,b0 as yu,a$ as zx,b3 as Vx,b6 as vu,b1 as _x,b2 as Ux,cM as Wx,aK as Kx,eG as Pn,cq as gn,cX as rr,bV as Yc,a0 as vn,y as Ka,m as Hx,e3 as xt,eQ as Ot,eN as Gx,eI as Uf,ev as Ei,d_ as Ad,el as Hn,aD as Dd,eX as El,aZ as qx,cN as wu,d3 as Yx,bx as Qx,eS as Wf,bq as Jx,ei as Xx,dr as Kf,ec as Td,ch as ml,dJ as Hf,br as Rl,bI as Zr,cd as Md,ba as Yo,af as Zx,k as eb,K as Xs,eC as Gf,eB as qf,Q as Bt,a5 as Cs,T as $r,dZ as fa,bg as tb,cA as Yf,r as bs,s as gs,B as ge,o as fs,n as hs,ey as zi,dy as sb,bW as nb,_ as Co,de as wn,aP as Qf,bs as Jf,eH as Fl,aV as rb,di as Xf,ce as ju,Z as Nu,ak as hn,i as ds,d2 as ib,aU as ab,dX as ob,aL as lb,b7 as cb,bM as db,bK as ub,bb as zs,cK as mb,aJ as pb,p as Is,dN as fb,aw as hb,d1 as gb,b8 as xb,N as Zn,a4 as po,U as bb,q as Vs,eD as Ll,ex as ia,bF as ha,b9 as ga,bZ as Su,bO as xa,bA as yb,a6 as is,ac as as,ad as us,a7 as os,a9 as Ft,bv as vb,ag as to,bC as wb,eb as Ir,ez as Ed,es as Ol,c3 as jb,ej as Rd,eq as Nb,em as Sb,ep as Fd,eo as kb,et as tn,c0 as fo,dB as Sr,bu as Cb,bL as Pb,bS as tc,e7 as $l,ee as Ld,ed as Bl,e5 as ho,ef as Bn,b$ as Od,bk as Vi,z as pl,E as fl,cv as so,t as Zf,ek as Ib,eY as Ar,cU as Ab,cm as Db,cl as Tb,cG as Mb,cz as Eb,bN as ku,bQ as hl,eT as zl,bw as eh,c_ as Rb,eL as Fb,aX as go,ci as Lb,A as $d,ck as Ob,cj as aa,cx as no,ea as th,cZ as ba,cB as sh,a1 as $b,b_ as Bb,e2 as Bd,eV as fi,co as la,eU as Ri,Y as Vl,bX as xo,W as bo,cL as Qc,aF as nh,ca as zd,dz as rh,bm as ro,dx as zb,V as Vb,X as _b,b4 as Ub,b5 as Wb,d8 as Fi,bE as sc,dl as Cu,dw as Kb,dk as Hb,bP as Gb,bd as qb,a2 as ta,dD as nc,bT as Yb,eA as Pu,cH as Li,dQ as Qb,as as Iu,l as Au,C as Du,D as Tu,dC as Qo,cR as Mu,eJ as Jb,aT as Xb,bU as Zb,bf as ey,be as rc,aE as Eu,d6 as ty,cy as sy,du as ny,dj as ry,e1 as iy,aB as ic,aA as ay,av as Ru,f1 as za,bH as oy,ds as ih,bD as ly,cO as sa,cI as cy,cC as Fu,at as dy,bj as uy,eh as ah,dA as Po,dp as Ha,dU as my,aO as oh,bR as py,c4 as fy,c8 as Lu,d0 as Ou,f0 as lh,en as ch,bt as ac,e4 as Io,f2 as hy,aN as gy,aM as xy,dY as by,j as dh,M as uh,d5 as Jc,by as Vd,dn as yy,cS as xs,cD as io,aS as ya,aH as ca,cP as $u,eK as Yn,cn as vy,dc as Ga,a as wy,bn as mh,dv as jy,dt as Ny,a8 as Xc,cu as Sy,c6 as ky,bi as Bu,c7 as Cy,e9 as Py,eW as _d,e_ as ph,eu as Iy,eO as Ay,eR as Dy,bp as Ty,aC as zu,G as My,I as Ey,H as Ry,bo as Fy,eP as oc,d$ as Ly,dK as fh,er as Oy,$ as $y,cr as By,cT as zy,dh as Vy,dG as _y,dO as Uy,aW as Wy,cb as Ky,d9 as Hy,az as Gy,dq as qy,aQ as Yy,aa as Vu,ab as Qy,c as hh,e as Jy,f as Xy,d as Zy,g as ev,cJ as si,u as tv,S as _u,bz as sv,c5 as Jo,c9 as Xo,dm as nv,dF as rv,bB as iv,dP as av,aR as Uu,bG as ov,dE as Wu,ax as lv,d7 as Ku,e0 as cv,eF as dv,e$ as uv,ai as Hu,a3 as Gu,aq as qu,au as mv,ah as gh,an as xh,cg as pv,cf as fv,dR as hv,ay as gv,dH as xv,dL as bv,dM as yv,O as vv,am as wv,al as jv,ae as Nv}from"./modelPrefsAutoSave-z_3gcNaV.js";import{J as Sv}from"./JsonTreeView-CoBDQpso.js";const kv=({transform:t})=>({...t,y:0}),Cv=t=>{const e=at.c(18),{id:n,children:r,className:i}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:l,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=Dl(a);let h;e[2]!==p?(h=Tl.Transform.toString(p),e[2]=p,e[3]=h):h=e[3];let x;e[4]!==h||e[5]!==m?(x={transform:h,transition:m},e[4]=h,e[5]=m,e[6]=x):x=e[6];const f=u&&"opacity-50";let v;e[7]!==i||e[8]!==f?(v=ce("h-full rounded-md",i,f),e[7]=i,e[8]=f,e[9]=v):v=e[9];let y;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==x||e[16]!==v?(y=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:x,className:v,...l,...c,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=x,e[16]=v,e[17]=y):y=e[17],y},Pv=t=>{const e=at.c(6),{id:n,children:r,className:i}=t;let a;e[0]!==i?(a=ce("h-full",i),e[0]=i,e[1]=a):a=e[1];let l;return e[2]!==r||e[3]!==n||e[4]!==a?(l=s.jsx("div",{className:a,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=a,e[5]=l):l=e[5],l},Cr=t=>{const e=at.c(121),{items:n,activeId:r,onSelect:i,onClose:a,onReorder:l,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:h,animateActivePill:x,activePillLowercase:f,className:v}=t,y=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,b=h===void 0?!1:h,k=f===void 0?!0:f,{t:I}=ut(),j=Ie(Iv),{isTablet:N}=rn(),D=j||N,E=o.useRef(null);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T={left:!1,right:!1},e[0]=T):T=e[0];const[C,S]=o.useState(T);let M;e[1]!==n?(M=n.map(Av),e[1]=n,e[2]=M):M=e[2];const A=M,R=y==="scrollable",z=g==="default",B=g==="active-pill",V=g==="animated",$=B||V,_=z,X=$||_,O=B&&R,J=$,Q=x??V,ne=typeof l=="function",G=ne?Cv:Pv;let le;e[3]===Symbol.for("react.memo_cache_sentinel")?(le=new Map,e[3]=le):le=e[3];const oe=o.useRef(le),[F,U]=o.useState(null);let W;e[4]===Symbol.for("react.memo_cache_sentinel")?(W={activationConstraint:{distance:8}},e[4]=W):W=e[4];const te=Ja(oa(Xa,W)),K=Dv;let ae;e[5]===Symbol.for("react.memo_cache_sentinel")?(ae=(Qe,he)=>{if(he){oe.current.set(Qe,he);return}oe.current.delete(Qe)},e[5]=ae):ae=e[5];const ve=ae;let re;e[6]!==r||e[7]!==X?(re=()=>{if(!X||!r){U(Tv);return}const Qe=E.current,he=oe.current.get(r);if(!Qe||!he){U(Mv);return}let Ge=0,Ve=0,it=he;for(;it&&it!==Qe;)Ge=Ge+it.offsetLeft,Ve=Ve+it.offsetTop,it=it.offsetParent;const dt={left:Ge,top:Ve,width:he.offsetWidth,height:he.offsetHeight};U(Ye=>K(Ye,dt)?Ye:dt)},e[6]=r,e[7]=X,e[8]=re):re=e[8];const be=re;let pe;e[9]!==R?(pe=()=>{if(!R){S({left:!1,right:!1});return}const Qe=E.current;if(!Qe){S({left:!1,right:!1});return}S({left:Qe.scrollLeft>2,right:Qe.scrollLeft+Qe.clientWidth<Qe.scrollWidth-2})},e[9]=R,e[10]=pe):pe=e[10];const ye=pe;let ie;e[11]!==R||e[12]!==ye?(ie=()=>{if(!R){S({left:!1,right:!1});return}const Qe=E.current;if(!Qe)return;ye(),Qe.addEventListener("scroll",ye,{passive:!0});const he=new ResizeObserver(ye);return he.observe(Qe),()=>{Qe.removeEventListener("scroll",ye),he.disconnect()}},e[11]=R,e[12]=ye,e[13]=ie):ie=e[13];let ue;e[14]!==R||e[15]!==n.length||e[16]!==ye?(ue=[R,n.length,ye],e[14]=R,e[15]=n.length,e[16]=ye,e[17]=ue):ue=e[17],o.useEffect(ie,ue);let se;e[18]!==r||e[19]!==be||e[20]!==X?(se=()=>{if(!X){U(null);return}be();const Qe=E.current;if(!Qe)return;const he=new ResizeObserver(be);if(he.observe(Qe),r){const Ge=oe.current.get(r);Ge&&he.observe(Ge)}return()=>{he.disconnect()}},e[18]=r,e[19]=be,e[20]=X,e[21]=se):se=e[21];let Ne;e[22]!==r||e[23]!==n.length||e[24]!==be||e[25]!==X?(Ne=[r,n.length,be,X],e[22]=r,e[23]=n.length,e[24]=be,e[25]=X,e[26]=Ne):Ne=e[26],o.useEffect(se,Ne);let Ce;e[27]!==be?(Ce=()=>{be()},e[27]=be,e[28]=Ce):Ce=e[28],o.useLayoutEffect(Ce);let je;e[29]!==r||e[30]!==R||e[31]!==ye?(je=()=>{if(!R||!r)return;const Qe=E.current;if(!Qe)return;const he=window.requestAnimationFrame(()=>{const Ge=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),Ve=Qe.querySelector(`[data-sortable-tab-id="${Ge}"]`);Ve&&(Ve.scrollIntoView({block:"nearest",inline:"nearest"}),ye())});return()=>{window.cancelAnimationFrame(he)}},e[29]=r,e[30]=R,e[31]=ye,e[32]=je):je=e[32];let we;e[33]!==r||e[34]!==R||e[35]!==n.length||e[36]!==ye?(we=[r,R,n.length,ye],e[33]=r,e[34]=R,e[35]=n.length,e[36]=ye,e[37]=we):we=e[37],o.useEffect(je,we);let ke;e[38]!==l?(ke=Qe=>{if(!l)return;const{active:he,over:Ge}=Qe;!Ge||he.id===Ge.id||l(String(he.id),String(Ge.id))},e[38]=l,e[39]=ke):ke=e[39];const xe=ke;let me;e[40]!==v?(me=ce("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=me):me=e[41];let Me;e[42]!==R||e[43]!==C||e[44]!==$?(Me=R&&C.left?s.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=R,e[43]=C,e[44]=$,e[45]=Me):Me=e[45];let Ue;e[46]!==R||e[47]!==C||e[48]!==$?(Ue=R&&C.right?s.jsx("div",{className:ce("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",$?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=R,e[47]=C,e[48]=$,e[49]=Ue):Ue=e[49];const q=$?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Se=$&&"@container/pill-tabs",$e=$&&"pill-tabs__track",Pe=$&&(p??"gap-0.5 py-0.5"),fe=_&&"items-center overflow-y-hidden",L=J&&"rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[color-mix(in_srgb,var(--foreground)_2%,transparent)] p-0.5 gap-0.5",Z=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Y;e[50]!==q||e[51]!==Se||e[52]!==$e||e[53]!==Pe||e[54]!==fe||e[55]!==L||e[56]!==Z?(Y=ce("relative flex h-full min-w-0 flex-1",q,Se,$e,Pe,fe,L,Z),e[50]=q,e[51]=Se,e[52]=$e,e[53]=Pe,e[54]=fe,e[55]=L,e[56]=Z,e[57]=Y):Y=e[57];let Ee;e[58]!==R?(Ee=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=Ee):Ee=e[59];let Ae;e[60]!==I?(Ae=I("sortableTabsStrip.aria.tabs"),e[60]=I,e[61]=Ae):Ae=e[61];let Je;e[62]!==F||e[63]!==Q||e[64]!==$?(Je=$&&F?s.jsx("div",{className:ce("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${F.left}px, ${F.top}px, 0)`,width:`${F.width}px`,height:`${F.height}px`,transition:Q?"transform 300ms cubic-bezier(0.65, 0, 0.35, 1), width 300ms cubic-bezier(0.65, 0, 0.35, 1), height 300ms cubic-bezier(0.65, 0, 0.35, 1)":void 0}}):null,e[62]=F,e[63]=Q,e[64]=$,e[65]=Je):Je=e[65];let de;e[66]!==F||e[67]!==_?(de=_&&F?s.jsx("div",{className:"pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",style:{transform:`translate3d(${F.left}px, 0, 0)`,width:`${F.width}px`},"aria-hidden":!0}):null,e[66]=F,e[67]=_,e[68]=de):de=e[68];let ze;if(e[69]!==G||e[70]!==r||e[71]!==m||e[72]!==k||e[73]!==D||e[74]!==b||e[75]!==w||e[76]!==B||e[77]!==j||e[78]!==R||e[79]!==n||e[80]!==a||e[81]!==i||e[82]!==O||e[83]!==$){let Qe;e[85]!==G||e[86]!==r||e[87]!==m||e[88]!==k||e[89]!==D||e[90]!==b||e[91]!==w||e[92]!==B||e[93]!==j||e[94]!==R||e[95]!==a||e[96]!==i||e[97]!==O||e[98]!==$?(Qe=he=>{const Ge=he.id===r,Ve=w&&$&&!Ge&&!!he.icon,it=!Ve,dt=!!he.icon&&(!b||Ge),Ye=w&&$&&Ge&&!R&&!O,_e=he.closable!==!1&&!!a,et=_e&&!!he.icon,gt=R||O?void 0:$?Ye?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",Lt=_e?mt=>{mt.button===1&&(mt.preventDefault(),mt.stopPropagation(),a?.(he.id))}:void 0,Ut=_e?Ev:void 0;return s.jsx(G,{id:he.id,className:gt,children:s.jsxs("div",{ref:mt=>ve(he.id,mt),onAuxClick:Lt,onMouseDown:Ut,className:ce("group flex h-full min-w-0 flex-nowrap items-center",R||O?"shrink-0":$?"w-full":"w-full min-w-0",$?"relative z-10 bg-transparent":Ge?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":Ge,"aria-label":Ve?he.title??he.label:void 0,onClick:()=>i(he.id),className:ce($?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",$&&k?"lowercase":null,$&&(Ve?"gap-0":"gap-1.5"),$?O?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":Ve?"px-2 !min-w-0 text-center":Ye?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",$?m??(B?j?"h-[38px]":"h-[31px]":"h-7"):null,$?Ge?"text-foreground":"text-muted-foreground hover:text-foreground":null,$?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:he.title??he.label,children:$?s.jsxs(s.Fragment,{children:[dt?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:ce("flex items-center justify-center transition-opacity",et&&(D?"opacity-0":"group-hover:opacity-0")),children:he.icon}),et?s.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Rv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,it?s.jsx("span",{className:"animated-tabs__label truncate",children:he.label}):null]}):s.jsxs("span",{className:ce("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[dt?s.jsxs("span",{className:ce("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ge?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:ce("flex items-center justify-center transition-opacity",et&&(D?"opacity-0":"group-hover:opacity-0")),children:he.icon}),et?s.jsx("span",{role:"button",tabIndex:-1,className:ce("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",D?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:Fv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:he.label})]})}),_e&&!et?s.jsx("button",{type:"button",onPointerDown:Lv,onClick:mt=>{mt.stopPropagation(),a?.(he.id)},className:ce("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",$?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",$?Ge?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ge?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":he.closeLabel??`Close ${he.label} tab`,title:he.closeLabel??`Close ${he.label} tab`,children:s.jsx(P,{name:"close",className:"h-3 w-3"})}):null]})},he.id)},e[85]=G,e[86]=r,e[87]=m,e[88]=k,e[89]=D,e[90]=b,e[91]=w,e[92]=B,e[93]=j,e[94]=R,e[95]=a,e[96]=i,e[97]=O,e[98]=$,e[99]=Qe):Qe=e[99],ze=n.map(Qe),e[69]=G,e[70]=r,e[71]=m,e[72]=k,e[73]=D,e[74]=b,e[75]=w,e[76]=B,e[77]=j,e[78]=R,e[79]=n,e[80]=a,e[81]=i,e[82]=O,e[83]=$,e[84]=ze}else ze=e[84];let rt;e[100]!==Y||e[101]!==Ee||e[102]!==Ae||e[103]!==Je||e[104]!==de||e[105]!==ze?(rt=s.jsxs("div",{ref:E,className:Y,style:Ee,role:"tablist","aria-label":Ae,children:[Je,de,ze]}),e[100]=Y,e[101]=Ee,e[102]=Ae,e[103]=Je,e[104]=de,e[105]=ze,e[106]=rt):rt=e[106];let Re;e[107]!==me||e[108]!==Me||e[109]!==Ue||e[110]!==rt?(Re=s.jsxs("div",{className:me,children:[Me,Ue,rt]}),e[107]=me,e[108]=Me,e[109]=Ue,e[110]=rt,e[111]=Re):Re=e[111];const Xe=Re;if(!ne)return Xe;let qe;e[112]===Symbol.for("react.memo_cache_sentinel")?(qe=[kv],e[112]=qe):qe=e[112];let Te;e[113]!==A||e[114]!==Xe?(Te=s.jsx(cl,{items:A,strategy:Jg,children:Xe}),e[113]=A,e[114]=Xe,e[115]=Te):Te=e[115];let We;e[116]===Symbol.for("react.memo_cache_sentinel")?(We=s.jsx(dl,{dropAnimation:null}),e[116]=We):We=e[116];let Ze;return e[117]!==xe||e[118]!==te||e[119]!==Te?(Ze=s.jsxs(Za,{sensors:te,collisionDetection:eo,onDragEnd:xe,modifiers:qe,children:[Te,We]}),e[117]=xe,e[118]=te,e[119]=Te,e[120]=Ze):Ze=e[120],Ze};function Iv(t){return t.isMobile}function Av(t){return t.id}function Dv(t,e){return!t||!e?t===e:Math.abs(t.left-e.left)<.5&&Math.abs(t.top-e.top)<.5&&Math.abs(t.width-e.width)<.5&&Math.abs(t.height-e.height)<.5}function Tv(t){return t===null?t:null}function Mv(t){return t===null?t:null}function Ev(t){t.button===1&&t.preventDefault()}function Rv(t){t.stopPropagation()}function Fv(t){t.stopPropagation()}function Lv(t){t.stopPropagation()}function Yu(t){const e=at.c(14);let n,r,i,a;e[0]!==t?({size:i,className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(n=e[1],r=e[2],i=e[3],a=e[4]);const l=typeof i=="number"?`${i}px`:i,c=typeof i=="number"?`${i}px`:i;let d;e[5]!==a||e[6]!==l||e[7]!==c?(d={width:l,height:c,...a},e[5]=a,e[6]=l,e[7]=c,e[8]=d):d=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=p):p=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:p}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Hr=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"zhipuai-coding-plan",name:"ZhipuAI"}];Hr.reduce((t,e)=>(t[e.id]=e,t),{});const Ov=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),$v=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,ao=(t,e)=>t??$v(e),Ud=(t,e)=>{if(!t)return e??"";try{const n=new Date(t);if(!Number.isFinite(n.getTime()))return e??"";const r=new Date;return n.toDateString()===r.toDateString()?n.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):n.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit"})}catch{return e??""}},bh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Wd=t=>t==="5h"?"5-Hour":t==="7d"?"7-Day Limit":t==="7d-sonnet"?"7-Day Sonnet Limit":t==="7d-opus"?"7-Day Opus Limit":t==="weekly"?"Weekly Limit":t==="daily"?"Daily":t==="monthly"?"Monthly Limit":t==="credits"?"Credits":t==="session"?"Session":t==="premium"?"Premium Interactions":t==="chat"?"Chat Requests":t==="completions"?"Completions":t==="premium_interactions"?"Premium interactions":t,Bv=t=>{const e=t.toLowerCase().trim();if(e==="5h")return 5*3600;if(e==="7d"||e==="weekly"||e==="7d-sonnet"||e==="7d-opus")return 7*86400;if(e==="monthly")return 30*86400;if(e==="24h"||e==="daily")return 86400;if(e==="1h")return 3600;const n=e.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;const r=e.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},oo=(t,e,n,r)=>{let i=n;if(i===null&&r&&(i=Bv(r)),t===null||e===null||i===null||i<=0)return null;const a=Date.now(),l=Math.max(0,(e-a)/1e3),c=Math.max(0,Math.min(i,i-l)),d=Math.max(0,Math.min(1,c/i)),p=t/100,m=t>=100&&l>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let h;m?h="exhausted":p<=d?h="on-track":u<=130?h="slightly-fast":h="too-fast";const x=i>=120*3600,f=x?86400:3600,v=x?"d":"h",y=i/f,g=Math.max(c/f,y*.01),w=t/g,b=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${v}`:"-",k=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let I=null;const j=i/86400;return j>=7&&(I=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:l,isExhausted:m,elapsedSeconds:c,totalSeconds:i,status:h,paceRateText:b,predictText:k,dailyAllocationPercent:I}},zv=t=>{switch(t){case"exhausted":case"too-fast":return"var(--status-error)";case"slightly-fast":return"var(--status-warning)";case"on-track":return"var(--status-success)"}},Qu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),i=Math.floor(r/24),a=r%24,l=n%60;return i>0?`${i}d ${a}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},ei=t=>Math.min(100,Math.max(0,t*100));function gl(t){const e=t.indexOf("/");if(e!==-1){const n=t.substring(0,e);if(n==="gemini"||n==="antigravity")return t.substring(e+1)}return t}const Vv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],yh={google:Vv};function vh(t,e){const n=yh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function wh(t){return yh[t]??[]}function jh(t){return[...t].sort((e,n)=>e.order-n.order)}function _v(t,e){const n=new Map;for(const r of Object.keys(t)){const a=vh(r,e)?.id??null;n.has(a)||n.set(a,[]),n.get(a).push(r)}return n}function Uv(t,e,n){const r=new Map;for(const i of t){const a=e(i),c=vh(a,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(i)}return r}function Wv(t,e){return e.filter(n=>{const r=n.toLowerCase(),i=r.includes("/")?r.split("/")[1]:r;return!!(i.startsWith("gemini-3-")||i.startsWith("claude-"))})}const Kd=6e4,Ju=t=>{const e=Hr.map(u=>u.id),n=typeof t?.usageAutoRefresh=="boolean"?t.usageAutoRefresh:!1,r=typeof t?.usageRefreshIntervalMs=="number"&&Number.isFinite(t.usageRefreshIntervalMs)?Math.max(3e4,Math.min(3e5,Math.round(t.usageRefreshIntervalMs))):Kd,i=t?.usageDisplayMode==="remaining"?"remaining":"usage",a=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,l=a?a.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,h]of Object.entries(d))Array.isArray(h)&&(c[u]=h.filter(x=>typeof x=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,h]of Object.entries(m))Array.isArray(h)&&(p[u]=h.filter(x=>typeof x=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:i,dropdownProviderIds:l,selectedModels:c,expandedFamilies:p}},Kv=async()=>{const t=pr()?.settings;if(t)try{const n=(await t.load())?.settings;return Ju(n??null)}catch{}if(!mn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Ju(n)}}return{autoRefresh:!1,refreshIntervalMs:Kd,displayMode:"usage",dropdownProviderIds:Hr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ms=gr()(Na((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Kd,displayMode:"usage",dropdownProviderIds:Hr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Kv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Hr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const i=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:i})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),i=await r.json().catch(()=>null);if(!r.ok)throw new Error(i?.error||"Failed to fetch quota");const a=i;t(l=>{const c=l.results.filter(d=>d.providerId!==n);return c.push(a),{results:c,error:null}})}catch(r){const i=r instanceof Error?r.message:"Failed to fetch quota",a={providerId:n,providerName:n,ok:!1,configured:!1,error:i,usage:null,fetchedAt:Date.now()};t(l=>{const c=l.results.filter(d=>d.providerId!==n);return c.push(a),{results:c,error:i}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(i=>({selectedModels:{...i.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(i=>{const a=i.selectedModels[n]??[],c=a.includes(r)?a.filter(d=>d!==r):[...a,r];return{selectedModels:{...i.selectedModels,[n]:c}}})},setExpandedFamilies:(n,r)=>{t(i=>({expandedFamilies:{...i.expandedFamilies,[n]:r}})),ks({usageExpandedFamilies:e().expandedFamilies})},toggleFamilyExpanded:(n,r)=>{t(i=>{const a=i.expandedFamilies[n]??[],c=a.includes(r)?a.filter(d=>d!==r):[...a,r];return{expandedFamilies:{...i.expandedFamilies,[n]:c}}}),ks({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const a=Wv(n,r);a.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:a}})),ks({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Nh=()=>{const t=at.c(5),e=Ms(Hv),n=Ms(Gv),r=Ms(qv);let i,a;t[0]!==e||t[1]!==r||t[2]!==n?(i=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},a=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=a):(i=t[3],a=t[4]),o.useEffect(i,a)};function Hv(t){return t.autoRefresh}function Gv(t){return t.refreshIntervalMs}function qv(t){return t.fetchAllQuotas}const xl=Be.forwardRef((t,e)=>{const n=at.c(11);let r,i;n[0]!==t?({className:r,...i}=t,n[0]=t,n[1]=r,n[2]=i):(r=n[1],i=n[2]);let a;n[3]!==r?(a=ce("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=a):a=n[4];let l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Xg,{className:ce("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=c):c=n[6];let d;return n[7]!==i||n[8]!==e||n[9]!==a?(d=s.jsx(Zg,{className:a,style:l,...i,ref:e,children:c}),n[7]=i,n[8]=e,n[9]=a,n[10]=d):d=n[10],d});xl.displayName="Switch";const Ao=()=>{try{const e=As.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Zs.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},Xu=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],Zu=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Do=t=>typeof t!="string"?void 0:t.trim()||void 0,lc=800,Yv=5e3,Qv="__default__",Zc=new Map,cc=new Map,Sh=t=>t?.trim()||Qv,dc=t=>{Zc.delete(Sh(t))},lo=gr()(Na(mo((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=Ao(),i=Sh(r),a=Date.now(),l=Zc.get(i)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&a-l<Yv)return!0;const d=cc.get(i);if(!n?.force&&d)return d;const p=(async()=>{t({isLoading:!0});try{const m=r?`?directory=${encodeURIComponent(r)}`:"",u=await fetch(`/api/config/mcp${m}`,{headers:r?{"x-opencode-directory":r}:void 0});if(!u.ok)throw new Error("Failed to load MCP configs");const h=await u.json();return t({mcpServers:h,isLoading:!1}),Zc.set(i,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();cc.set(i,p);try{return await p}finally{cc.delete(i)}},createMcp:async n=>{Xl("Creating MCP server configuration…");let r=!1;try{const i=em(n),a=Ao(),l=a?`?directory=${encodeURIComponent(a)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-opencode-directory":a}:{}},body:JSON.stringify(i)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return dc(a),d?.requiresReload?(r=!0,await Zl({message:d.message,delayMs:d.reloadDelayMs??lc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(i){return console.error("[McpConfigStore] Failed to create MCP:",i),{ok:!1}}finally{r||ec()}},updateMcp:async(n,r)=>{Xl("Updating MCP server configuration…");let i=!1;try{const a=em(r),l=Ao(),c=l?`?directory=${encodeURIComponent(l)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(a)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return dc(l),p?.requiresReload?(i=!0,await Zl({message:p.message,delayMs:p.reloadDelayMs??lc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:p?.reloadFailed===!0,message:p?.message,warning:p?.warning})}catch(a){throw console.error("[McpConfigStore] Failed to update MCP:",a),a}finally{i||ec()}},deleteMcp:async n=>{Xl("Deleting MCP server configuration…");let r=!1;try{const i=Ao(),a=i?`?directory=${encodeURIComponent(i)}`:"",l=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${a}`,{method:"DELETE",headers:i?{"x-opencode-directory":i}:void 0}),c=await l.json().catch(()=>null);if(!l.ok)throw new Error(c?.error||"Failed to delete MCP server");return dc(i),c?.requiresReload&&(r=!0,await Zl({message:c.message,delayMs:c.reloadDelayMs??lc,scopes:["all"]})),e().selectedMcpName===n&&t({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(i){return console.error("[McpConfigStore] Failed to delete MCP:",i),{ok:!1}}finally{r||ec()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:Ml(()=>pi()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function em(t){const e={};if(t.scope!==void 0&&(e.scope=t.scope),t.type!==void 0&&(e.type=t.type),(t.type==="local"||t.command!==void 0)&&(e.command=(t.command??[]).filter(n=>n.trim())),(t.type==="remote"||t.url!==void 0)&&(e.url=t.url?.trim()??""),t.environment!==void 0&&(e.environment=Zu(t.environment)??{}),t.headers!==void 0&&(e.headers=Zu(t.headers)??{}),t.oauthEnabled!==void 0||t.oauthClientId!==void 0||t.oauthClientSecret!==void 0||t.oauthScope!==void 0||t.oauthRedirectUri!==void 0)if(t.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:Do(t.oauthClientId),clientSecret:Do(t.oauthClientSecret),scope:Do(t.oauthScope),redirectUri:Do(t.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:t.oauthEnabled?e.oauth={}:e.oauth=!1}if(t.timeout!==void 0){const n=Number(t.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return t.enabled!==void 0&&(e.enabled=t.enabled),e}const Jv={},Xv={},Xr=t=>{if(typeof t!="string")return null;const e=t.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},Ji=t=>Xr(t)??"__global__",wi=t=>{const e=Xr(t);return e?Zs.getScopedApiClient(e):Zs.getApiClient()},yn=gr()(Na((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().byDirectory[r]??Jv},getDiagnosticForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Xv},getErrorForDirectory:n=>{const r=Ji(n??$s.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Xr(n?.directory??$s.getState().currentDirectory),i=Ji(r);n?.silent||t(a=>({loadingKeys:{...a.loadingKeys,[i]:!0},lastErrorKeys:{...a.lastErrorKeys,[i]:null}}));try{const c=(await wi(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[i]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[i]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[i]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[i]:!1},lastErrorKeys:{...d.lastErrorKeys,[i]:null}}))}catch(a){const l=a instanceof Error?a.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[i]:!1},lastErrorKeys:{...c.lastErrorKeys,[i]:l}}))}},connect:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),a=Ji(i),l=wi(i);try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(p=>({diagnosticsByDirectory:{...p.diagnosticsByDirectory,[a]:{...p.diagnosticsByDirectory[a]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:i,silent:!0})},disconnect:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory);await wi(i).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},startAuth:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),c=(await wi(i).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,r,i)=>{const a=Xr(i??$s.getState().currentDirectory);await wi(a).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},clearAuth:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory);await wi(i).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},testConnection:async(n,r)=>{const i=Xr(r??$s.getState().currentDirectory),a=Ji(i),l=wi(i),d=e().getStatusForDirectory(i)[n]?.status==="connected";let p,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(x){p=x instanceof Error?x.message:"Connection failed",t(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[a]:{...f.diagnosticsByDirectory[a]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:i,silent:!0});const u=e().getStatusForDirectory(i)[n],h=u;if(!d&&u?.status==="connected"){try{await l.mcp.disconnect({name:n},{throwOnError:!0})}catch(x){m=`Connection test succeeded, but cleanup disconnect failed: ${x instanceof Error?x.message:"Disconnect failed"}`}await e().refresh({directory:i,silent:!0})}return{status:h??e().getStatusForDirectory(i)[n],error:p,warning:m}}})));function Zv(t){const e=at.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let i;return e[2]!==t?(i=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=i):i=e[3],i}const ew=(t,e)=>{if(!t)return e("mcpDropdown.status.unknown");switch(t.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:t.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:t.error||""});default:return t.status}},tw=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},kh=({active:t,className:e})=>{const{t:n}=ut(),i=$s(g=>g.currentDirectory)??null,a=yn(g=>g.getStatusForDirectory(i)),l=yn(g=>g.refresh),c=yn(g=>g.connect),d=yn(g=>g.disconnect),p=lo(g=>g.mcpServers),m=lo(g=>g.loadMcpConfigs),[u,h]=o.useState(!1),[x,f]=o.useState(null);o.useEffect(()=>{l({directory:i,silent:!0})},[l,i]),o.useEffect(()=>{m({force:!0})},[m]),o.useEffect(()=>{t&&Promise.all([l({directory:i,silent:!0}),m({force:!0})])},[t,l,i,m]);const v=o.useMemo(()=>{const g=new Set(Object.keys(a));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,b)=>w.localeCompare(b))},[p,a]),y=o.useCallback(g=>{if(g?.preventDefault(),u)return;h(!0);const w=new Promise(b=>setTimeout(b,500));Promise.all([l({directory:i}),w]).finally(()=>{h(!1)})},[u,l,i]);return s.jsxs("div",{className:ce("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),i&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:i.split("/").pop()||i})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:u,onClick:y,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(P,{name:"refresh",className:ce("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[v.map(g=>{const w=a[g],b=tw(w),k=w?.status==="connected",I=x===g,j=ew(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:ce("h-2 w-2 rounded-full flex-shrink-0",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Dt,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(xl,{checked:k,disabled:I,className:"data-[checked]:bg-status-info",onCheckedChange:async N=>{f(g);try{N?await c(g,i):await d(g,i)}finally{f(null)}}})]},g)}),v.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},co=t=>{const e=at.c(20),{percent:n,tonePercent:r,className:i,expectedMarkerPercent:a}=t;let l;e[0]!==n?(l=Ov(n)??0,e[0]=n,e[1]=l):l=e[1];const c=l,d=r??n;let p;e[2]!==d?(p=bh(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=a!=null?Math.max(0,Math.min(100,a)):null;let h;e[4]!==m?(h=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=h):h=e[5];const x=h;let f;e[6]!==i?(f=ce("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=f):f=e[7];const v=`${c}%`;let y;e[8]!==x||e[9]!==v?(y={...x,width:v},e[8]=x,e[9]=v,e[10]=y):y=e[10];let g;e[11]!==c||e[12]!==y?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:y,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=y,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let b;return e[16]!==f||e[17]!==g||e[18]!==w?(b=s.jsxs("div",{className:f,children:[g,w]}),e[16]=f,e[17]=g,e[18]=w,e[19]=b):b=e[19],b},uo=t=>{const e=at.c(67),{paceInfo:n,className:r,compact:i}=t,a=i===void 0?!1:i,{t:l}=ut();let c;e[0]!==n.status?(c=zv(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let N;e[2]!==l?(N=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=N):N=e[3],p=N;break e}case"slightly-fast":{let N;e[4]!==l?(N=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=N):N=e[5],p=N;break e}case"too-fast":{let N;e[6]!==l?(N=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=N):N=e[7],p=N;break e}case"exhausted":{let N;e[8]!==l?(N=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=N):N=e[9],p=N;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==l?(u=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=u):u=e[12];const h=u;if(a){let N;e[13]!==r?(N=ce("flex items-center gap-1.5",r),e[13]=r,e[14]=N):N=e[14];let D;e[15]!==d?(D={backgroundColor:d},e[15]=d,e[16]=D):D=e[16];let E;e[17]!==m||e[18]!==D?(E=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:D,title:m}),e[17]=m,e[18]=D,e[19]=E):E=e[19];let T;e[20]!==d?(T={color:d},e[20]=d,e[21]=T):T=e[21];const C=n.isExhausted?void 0:h;let S;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(S=n.isExhausted?s.jsx(s.Fragment,{children:l("settings.usage.pace.wait",{duration:Qu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=S):S=e[26];let M;e[27]!==S||e[28]!==T||e[29]!==C?(M=s.jsx("span",{className:"typography-micro tabular-nums",style:T,title:C,children:S}),e[27]=S,e[28]=T,e[29]=C,e[30]=M):M=e[30];let A;return e[31]!==M||e[32]!==N||e[33]!==E?(A=s.jsxs("div",{className:N,children:[E,M]}),e[31]=M,e[32]=N,e[33]=E,e[34]=A):A=e[34],A}let x;e[35]!==r?(x=ce("flex items-center justify-between gap-2",r),e[35]=r,e[36]=x):x=e[36];let f;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(f=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=f):f=e[40];let v;e[41]!==f?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:f}),e[41]=f,e[42]=v):v=e[42];let y;e[43]!==d?(y={color:d},e[43]=d,e[44]=y):y=e[44];let g;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==h||e[49]!==m||e[50]!==l?(g=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:Qu(n.remainingSeconds)})]}):s.jsxs("span",{title:h,children:[s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=h,e[49]=m,e[50]=l,e[51]=g):g=e[51];let w;e[52]!==y||e[53]!==g?(w=s.jsx("span",{className:"typography-micro tabular-nums",style:y,children:g}),e[52]=y,e[53]=g,e[54]=w):w=e[54];let b;e[55]!==d?(b={backgroundColor:d},e[55]=d,e[56]=b):b=e[56];let k;e[57]!==m||e[58]!==b?(k=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:b,title:m}),e[57]=m,e[58]=b,e[59]=k):k=e[59];let I;e[60]!==w||e[61]!==k?(I=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,k]}),e[60]=w,e[61]=k,e[62]=I):I=e[62];let j;return e[63]!==I||e[64]!==x||e[65]!==v?(j=s.jsxs("div",{className:x,children:[v,I]}),e[63]=I,e[64]=x,e[65]=v,e[66]=j):j=e[66],j},fr=ex,Pr=t=>{const e=at.c(14);let n,r,i,a;e[0]!==t?({className:i,asChild:n,children:r,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a):(n=e[1],r=e[2],i=e[3],a=e[4]);let l;e[5]!==n||e[6]!==r?(l=n&&Be.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=l):l=e[7];const c=l;let d;e[8]!==i?(d=ce("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",i),e[8]=i,e[9]=d):d=e[9];let p;return e[10]!==a||e[11]!==c||e[12]!==d?(p=s.jsx(tx,{className:d,...a,...c}),e[10]=a,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},hr=t=>{const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(sx,{className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a},hi=[{id:"finder",label:"Finder",appName:"Finder"},{id:"terminal",label:"Terminal",appName:"Terminal"},{id:"iterm2",label:"iTerm2",appName:"iTerm"},{id:"ghostty",label:"Ghostty",appName:"Ghostty"},{id:"vscode",label:"VS Code",appName:"Visual Studio Code"},{id:"intellij",label:"IntelliJ",appName:"IntelliJ IDEA"},{id:"visual-studio",label:"Visual Studio",appName:"Visual Studio"},{id:"cursor",label:"Cursor",appName:"Cursor"},{id:"android-studio",label:"Android Studio",appName:"Android Studio"},{id:"pycharm",label:"PyCharm",appName:"PyCharm"},{id:"xcode",label:"Xcode",appName:"Xcode"},{id:"sublime-text",label:"Sublime",appName:"Sublime Text"},{id:"webstorm",label:"WebStorm",appName:"WebStorm"},{id:"rider",label:"Rider",appName:"Rider"},{id:"zed",label:"Zed",appName:"Zed"},{id:"phpstorm",label:"PhpStorm",appName:"PhpStorm"},{id:"eclipse",label:"Eclipse",appName:"Eclipse"},{id:"windsurf",label:"Windsurf",appName:"Windsurf"},{id:"vscodium",label:"VSCodium",appName:"VSCodium"},{id:"rustrover",label:"RustRover",appName:"RustRover"},{id:"kiro",label:"Kiro",appName:"Kiro"},{id:"antigravity",label:"Antigravity",appName:"Antigravity"},{id:"trae",label:"Trae",appName:"Trae"}],ed="finder",td=new Set(["finder","terminal"]),sd=t=>t?hi.find(e=>e.id===t)??null:null,uc=()=>hi.filter(t=>td.has(t.id)).map(t=>({...t})),sw=()=>{if(typeof window>"u")return ed;const t=window.localStorage.getItem("openInAppId");return t&&sd(t)?t:ed};let mc=!1,Xi=!1,ci=!1,di=0,qa=null;const tm=()=>{qa&&(clearTimeout(qa),qa=null)},Lr=gr()((t,e)=>({selectedAppId:sw(),availableApps:uc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(mc||typeof window>"u")return;mc=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:uc(),hasLoadedApps:p});return}const m=new Set(d.map(f=>f.name)),u=new Map(d.map(f=>[f.name,f.iconDataUrl??void 0])),x=hi.filter(f=>m.has(f.appName)||td.has(f.id)).map(f=>({...f,iconDataUrl:u.get(f.appName)}));t({availableApps:x,hasLoadedApps:!0})},r=async d=>{if(!pa()||!Bi()||Xi||e().hasLoadedApps&&!d)return;const m=hi.map(u=>u.appName);tm(),Xi=!0,ci=!1,t({isScanning:!0});try{const{apps:u,success:h,hasCache:x,isCacheStale:f}=await bu(m,d),v=h&&!x&&u.length===0&&di<3;if(t({isCacheStale:x?f:!1}),n(u,h?!v:!1),h){if(v){const g=[800,1600,3200][di]??3200;di+=1,ci=!0,qa=setTimeout(()=>{r()},g);return}di=0,ci=!1;return}if(di<3){const g=[1e3,3e3,7e3][di]??7e3;di+=1,ci=!0,qa=setTimeout(()=>{r()},g)}}finally{Xi=!1,ci||t({isScanning:!1})}};r();const i=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&sd(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},a=()=>{r()},l=d=>{const p=d.detail;Array.isArray(p)&&(di=3,ci=!1,t({isScanning:!1,isCacheStale:!1}),n(p))};window.addEventListener("vinci:settings-synced",i),window.addEventListener("vinci:app-ready",a),window.addEventListener("vinci:installed-apps-updated",l),window.__vinciAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(mc||e().initialize(),!pa()||!Bi()||Xi||e().hasLoadedApps&&!n)return;const i=hi.map(a=>a.appName);tm(),n&&t({hasLoadedApps:!1}),Xi=!0,ci=!1,t({isScanning:!0});try{const{apps:a,hasCache:l,isCacheStale:c}=await bu(i,n),d=new Set(a.map(h=>h.name)),p=new Map(a.map(h=>[h.name,h.iconDataUrl??void 0])),u=hi.filter(h=>d.has(h.appName)||td.has(h.id)).map(h=>({...h,iconDataUrl:p.get(h.appName)}));t({availableApps:u.length>0?u:uc(),hasLoadedApps:u.length>0,isCacheStale:l?c:!1})}finally{Xi=!1,ci||t({isScanning:!1})}},selectApp:async n=>{sd(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await ks({openInAppId:n}))}})),nw="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",rw="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",pc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?nw:t.id==="terminal"?rw:void 0}),sm=t=>{const e=at.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:i}=t,[a,l]=o.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||i;if(p&&!a){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>l(!0),e[2]=h):h=e[2];let x;return e[3]!==p?(x=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:h}),e[3]=p,e[4]=x):x=e[4],x}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=ce("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},iw=t=>{const e=at.c(82),{directory:n,className:r}=t,{t:i}=ut(),a=Lr(aw),l=Lr(ow),c=Lr(lw),d=Lr(cw),p=Lr(dw),m=Lr(uw),u=Lr(mw);let h,x;e[0]!==p?(h=()=>{p()},x=[p],e[0]=p,e[1]=h,e[2]=x):(h=e[1],x=e[2]),o.useEffect(h,x);const f=pa()&&Bi();let v;e:{let K;e[3]!==l||e[4]!==a?(K=l.find(re=>re.id===a)??l.find(pw)??l[0]??hi[0],e[3]=l,e[4]=a,e[5]=K):K=e[5];const ae=K;if(ae){let re;e[6]!==ae?(re=pc(ae),e[6]=ae,e[7]=re):re=e[7],v=re;break e}let ve;e[8]===Symbol.for("react.memo_cache_sentinel")?(ve=pc(hi[0]),e[8]=ve):ve=e[8],v=ve}const y=v;if(!f||!n||l.length===0)return null;let g;e[9]!==n?(g=async K=>{await Bx(n,K.id,K.appName)||await ul(n,K.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let b;e[11]!==w||e[12]!==u?(b=async K=>{await u(K.id),await w(K)},e[11]=w,e[12]=u,e[13]=b):b=e[13];const k=b;let I;e[14]!==n||e[15]!==i?(I=async()=>{(await _n(n)).ok&&H.success(i("openInApp.toast.pathCopied"))},e[14]=n,e[15]=i,e[16]=I):I=e[16];const j=I;let N;e[17]!==r?(N=ce("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=N):N=e[18];let D;e[19]!==w||e[20]!==y?(D=()=>{w(y)},e[19]=w,e[20]=y,e[21]=D):D=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=ce("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=E):E=e[22];let T;e[23]!==y.label||e[24]!==i?(T=i("openInApp.actions.openInAria",{app:y.label}),e[23]=y.label,e[24]=i,e[25]=T):T=e[25];let C;e[26]!==y.fallbackIconDataUrl||e[27]!==y.iconDataUrl||e[28]!==y.label?(C=s.jsx(sm,{label:y.label,iconDataUrl:y.iconDataUrl,fallbackIconDataUrl:y.fallbackIconDataUrl}),e[26]=y.fallbackIconDataUrl,e[27]=y.iconDataUrl,e[28]=y.label,e[29]=C):C=e[29];const S=d?"animate-pulse text-muted-foreground":void 0;let M;e[30]!==S?(M=ce("header-open-label",S),e[30]=S,e[31]=M):M=e[31];let A;e[32]!==i?(A=i("openInApp.actions.open"),e[32]=i,e[33]=A):A=e[33];let R;e[34]!==M||e[35]!==A?(R=s.jsx("span",{className:M,children:A}),e[34]=M,e[35]=A,e[36]=R):R=e[36];let z;e[37]!==T||e[38]!==C||e[39]!==R||e[40]!==D?(z=s.jsxs("button",{type:"button",onClick:D,className:E,"aria-label":T,children:[C,R]}),e[37]=T,e[38]=C,e[39]=R,e[40]=D,e[41]=z):z=e[41];let B;e[42]===Symbol.for("react.memo_cache_sentinel")?(B=ce("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[42]=B):B=e[42];let V;e[43]!==i?(V=i("openInApp.actions.chooseAppAria"),e[43]=i,e[44]=V):V=e[44];let $;e[45]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4"}),e[45]=$):$=e[45];let _;e[46]!==V?(_=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:B,"aria-label":V,children:$})}),e[46]=V,e[47]=_):_=e[47];let X;e[48]===Symbol.for("react.memo_cache_sentinel")?(X={translate:"-30px 0"},e[48]=X):X=e[48];let O;e[49]!==j?(O=()=>{j()},e[49]=j,e[50]=O):O=e[50];let J;e[51]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(P,{name:"file-copy",className:"h-4 w-4"}),e[51]=J):J=e[51];let Q;e[52]!==i?(Q=i("openInApp.actions.copyPath"),e[52]=i,e[53]=Q):Q=e[53];let ne;e[54]!==Q?(ne=s.jsx("span",{className:"typography-ui-label text-foreground",children:Q}),e[54]=Q,e[55]=ne):ne=e[55];let G;e[56]!==O||e[57]!==ne?(G=s.jsxs($t,{className:"flex items-center gap-2",onClick:O,children:[J,ne]}),e[56]=O,e[57]=ne,e[58]=G):G=e[58];let le;e[59]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(Cn,{}),e[59]=le):le=e[59];let oe;if(e[60]!==l||e[61]!==k||e[62]!==y.id){let K;e[64]!==k||e[65]!==y.id?(K=ae=>{const ve=pc(ae);return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{k(ae)},children:[s.jsx(sm,{label:ae.label,iconDataUrl:ae.iconDataUrl,fallbackIconDataUrl:ve.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ae.label}),y.id===ae.id?s.jsx(P,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ae.id)},e[64]=k,e[65]=y.id,e[66]=K):K=e[66],oe=l.map(K),e[60]=l,e[61]=k,e[62]=y.id,e[63]=oe}else oe=e[63];let F;e[67]!==c||e[68]!==m||e[69]!==i?(F=c?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(P,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=i,e[70]=F):F=e[70];let U;e[71]!==G||e[72]!==oe||e[73]!==F?(U=s.jsxs(Rs,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:X,children:[G,le,oe,F]}),e[71]=G,e[72]=oe,e[73]=F,e[74]=U):U=e[74];let W;e[75]!==_||e[76]!==U?(W=s.jsxs(Fs,{children:[_,U]}),e[75]=_,e[76]=U,e[77]=W):W=e[77];let te;return e[78]!==z||e[79]!==W||e[80]!==N?(te=s.jsxs("div",{className:N,children:[z,W]}),e[78]=z,e[79]=W,e[80]=N,e[81]=te):te=e[81],te};function aw(t){return t.selectedAppId}function ow(t){return t.availableApps}function lw(t){return t.isCacheStale}function cw(t){return t.isScanning}function dw(t){return t.initialize}function uw(t){return t.loadInstalledApps}function mw(t){return t.selectApp}function pw(t){return t.id===ed}const fw=1e6,hw="terminal-store";let nm=!1;const fc=t=>typeof t=="object"&&t!==null,gw=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Wn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const hc=(t,e)=>({id:t,terminalSessionId:null,lifecycle:"idle",label:e,iconKey:null,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Ch=/\x1b\[[0-9;]*m/g,xw=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,bw=new Set([".",",",";",":","!","?"]),yw=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",i=e.slice(0,-1),a=(i.match(new RegExp(`\\${r}`,"g"))||[]).length,l=(i.match(new RegExp(`\\${n}`,"g"))||[]).length;if(a>l)break;e=i;continue}if(bw.has(n)){e=e.slice(0,-1);continue}break}return e},vw=t=>{if(!t)return null;const n=t.replace(Ch,"").match(xw);if(!n?.[1])return null;let r=yw(n[1]);return r=r.replace("0.0.0.0","127.0.0.1"),r=r.replace("[::1]","127.0.0.1"),r=r.replace("[::]","127.0.0.1"),r},ww=t=>{if(!t)return null;const n=t.replace(Ch,"").match(/Serving HTTP on .*? port (\d{2,5})/i);if(!n?.[1])return null;const r=Number.parseInt(n[1],10);return!Number.isFinite(r)||r<=0||r>65535?null:`http://127.0.0.1:${r}/`},gc=t=>({tabs:[t],activeTabId:t.id}),Rr=(t,e)=>t.tabs.findIndex(n=>n.id===e),on=gr()(Na(mo((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Wn(n);r&&t(i=>{if(i.sessions.has(r))return i;const a=new Map(i.sessions),l=`tab-${i.nextTabId}`,c=hc(l,"Terminal");return a.set(r,gc(c)),{sessions:a,nextTabId:i.nextTabId+1}})},getDirectoryState:n=>{const r=Wn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Wn(n),i=e().sessions.get(r);if(!i)return;const a=i.activeTabId;return a?i.tabs.find(l=>l.id===a)??i.tabs[0]:i.tabs[0]},createTab:n=>{const r=Wn(n);if(!r)return"tab-invalid";const i=`tab-${e().nextTabId}`;return t(a=>{const l=new Map(a.sessions),c=l.get(r),d=a.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=hc(i,m);return c?l.set(r,{...c,tabs:[...c.tabs,u]}):l.set(r,gc(u)),{sessions:l,nextTabId:d}}),i},setActiveTab:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);return!c||c.activeTabId===r||Rr(c,r)<0?a:(l.set(i,{...c,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,i)=>{const a=Wn(n),l=i.trim();l&&t(c=>{const d=new Map(c.sessions),p=d.get(a);if(!p)return c;const m=Rr(p,r);if(m<0||p.tabs[m]?.label===l)return c;const u=[...p.tabs];return u[m]={...u[m],label:l},d.set(a,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=i?.trim()||null;if(d.tabs[p]?.iconKey===m)return l;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(a,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const i=Wn(n),c=e().sessions.get(i)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await Lx(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(i);if(!m)return d;const u=Rr(m,r);if(u<0)return d;const h=m.tabs.filter(y=>y.id!==r),x=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,y])=>!(y.directory===i&&y.tabId===r))),f=Object.keys(x).length!==Object.keys(d.projectActionRuns).length;if(h.length===0){const y=`tab-${d.nextTabId}`,g=hc(y,"Terminal");return p.set(i,gc(g)),{sessions:p,nextTabId:d.nextTabId+1,...f?{projectActionRuns:x}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=h[Math.min(u,h.length-1)]?.id??h[0]?.id??null),p.set(i,{...m,tabs:h,activeTabId:v}),{sessions:p,...f?{projectActionRuns:x}:{}}})},setTabSessionId:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=d.tabs[p],u=i!==null&&m.terminalSessionId!==i,h=i?"running":m.terminalSessionId?"exited":m.lifecycle,x={...m,terminalSessionId:i,lifecycle:h,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},f=[...d.tabs];return f[p]=x,c.set(a,{...d,tabs:f}),{sessions:c}})},setTabLifecycle:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=[...d.tabs];return m[p]={...m[p],lifecycle:i,isConnecting:!1},c.set(a,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,i)=>{const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=[...d.tabs];return m[p]={...m[p],isConnecting:i},c.set(a,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,i)=>{if(!i)return;const a=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(a);if(!d)return l;const p=Rr(d,r);if(p<0)return l;const m=d.tabs[p],u=l.nextChunkId,h={id:u,data:i},x=[...m.bufferChunks,h];let f=m.bufferLength+i.length;for(;f>fw&&x.length>1;){const w=x.shift();if(!w)break;f-=w.data.length}const v=m.previewUrlLocked?null:vw(i)??ww(i),y=!!(v&&v!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:x,bufferLength:f,...y?{previewUrl:v,previewAutoOpened:!1}:null},c.set(a,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,i,a={})=>{const l=Wn(n);t(c=>{const d=new Map(c.sessions),p=d.get(l);if(!p)return c;const m=Rr(p,r);if(m<0)return c;const u=p.tabs[m],h=a.autoOpened??u.previewAutoOpened,x=a.locked??u.previewUrlLocked;if(u.previewUrl===i&&u.previewAutoOpened===h&&u.previewUrlLocked===x)return c;const f=[...p.tabs];return f[m]={...u,previewUrl:i,previewAutoOpened:h,previewUrlLocked:x},d.set(l,{...p,tabs:f}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);if(!c)return a;const d=Rr(c,r);if(d<0)return a;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return a;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},l.set(i,{...c,tabs:m}),{sessions:l}})},setProjectActionRun:n=>{t(r=>{const i=r.projectActionRuns[n.key];return i&&i.directory===n.directory&&i.actionId===n.actionId&&i.tabId===n.tabId&&i.sessionId===n.sessionId&&i.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(i=>{const a=i.projectActionRuns[n];return!a||a.status===r?i:{projectActionRuns:{...i.projectActionRuns,[n]:{...a,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const i={...r.projectActionRuns};return delete i[n],{projectActionRuns:i}})},clearBuffer:(n,r)=>{const i=Wn(n);t(a=>{const l=new Map(a.sessions),c=l.get(i);if(!c)return a;const d=Rr(c,r);if(d<0)return a;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},l.set(i,{...c,tabs:p}),{sessions:l}})},removeDirectory:n=>{const r=Wn(n);t(i=>{const a=new Map(i.sessions);a.delete(r);const l=Object.fromEntries(Object.entries(i.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:a,projectActionRuns:l}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:hw,storage:Ml(()=>_f()),partialize:t=>({sessions:Array.from(t.sessions.entries()).map(([e,n])=>[e,{activeTabId:n.activeTabId,tabs:n.tabs.map(r=>({id:r.id,label:r.label,iconKey:r.iconKey,terminalSessionId:r.terminalSessionId,lifecycle:r.lifecycle,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!fc(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let i=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,p]=c;if(typeof d!="string"||!fc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const f of m){if(!fc(f))continue;const v=typeof f.id=="string"?f.id:null;if(!v)continue;const y=gw(v);y!==null&&(i=Math.max(i,y));const g=typeof f.terminalSessionId=="string"||f.terminalSessionId===null?f.terminalSessionId:null,w=f.lifecycle,b=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:v,label:typeof f.label=="string"?f.label:"Terminal",iconKey:typeof f.iconKey=="string"?f.iconKey:null,terminalSessionId:g,lifecycle:b,createdAt:typeof f.createdAt=="number"?f.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const h=typeof p.activeTabId=="string"?p.activeTabId:null,x=h?u.some(f=>f.id===h):!1;r.set(d,{tabs:u,activeTabId:x?h:u[0].id})}const a=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,l=Math.max(e.nextTabId,a,i+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!nm){nm=!0;const t=on.persist,e=()=>{on.getState().hasHydrated||on.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const rm=(t,e)=>e.updatedAtMs-t.updatedAtMs,Ys=gr((t,e)=>({instances:[],statusesById:{},importCandidates:[],isLoading:!1,isSaving:!1,isImportsLoading:!1,initialized:!1,listenerReady:!1,error:null,load:async()=>{if(!e().isLoading){t({isLoading:!0,error:null});try{const[n,r]=await Promise.all([Ux(),vu()]),i={};for(const a of r.sort(rm))i[a.id]=a;e().listenerReady||await Wx(a=>{t(l=>({statusesById:{...l.statusesById,[a.id]:a}}))}),t({instances:n.instances,statusesById:i,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await _x();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await vu(),r={};for(const i of n.sort(rm))r[i.id]=i;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await Vx({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,i=r.some(a=>a.id===n.id)?r.map(a=>a.id===n.id?n:a):[n,...r];await e().setInstances(i)},createFromCommand:async(n,r,i)=>{const a=Kx(n,r);i&&i.trim()&&(a.nickname=i.trim()),await e().upsertInstance(a)},removeInstance:async n=>{await yu(n).catch(()=>{});const r=e().instances.filter(i=>i.id!==n);await e().setInstances(r),t(i=>{const a={...i.statusesById};return delete a[n],{statusesById:a}})},connect:async n=>{t({error:null});try{await zx(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{t({error:null});try{await yu(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>t({error:null})})),Ph=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],Zo=Object.fromEntries(Ph.map(t=>[t.key,t.Icon])),nd="vinci:project-actions-updated",Ih=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ui=(t,e)=>`${Ih(t)}::${e}`,jw=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},im=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},Nw=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=im(e.localPort),r=im(e.remotePort);if(!n||!r)return null;const i=jw(e.localHost||t.localForward.bindHost||"127.0.0.1"),a=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${i}:${n} -> ${a}:${r}`,url:`http://${i}:${n}`}},Ah=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const i=Nw(n,r);i&&e.push(i)}return e},Sw=(t,e)=>{const n=(t||"").trim();return n&&Ah(e).find(a=>a.id===n)?.url||null},kw=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],Cw=["dev","start","preview","serve"];async function Pw(t,e,n){if(!t)return null;const r=Dw(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const i=Tw(n);if(i){const a=await Mw(t);return{command:`${a==="npm"?"npm run":a==="yarn"?"yarn":a==="pnpm"?"pnpm":a==="bun"?"bun run --shell=bun":"npm run"} ${i}`,label:`Start (${i})`}}}if(await Iw(t)){const i=await Aw(),a=typeof i=="number"&&Number.isFinite(i)&&i>0?i:8e3;return{command:`python3 -m http.server ${a}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${a}/`}}return null}async function Iw(t){const e=`${t}/index.html`,n=await bl(e);return typeof n=="string"&&n.trim().length>0}async function Aw(){try{const t=await fetch("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Dw(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(Cw.some(i=>n.includes(i)))return e}return null}function Tw(t){for(const{pattern:e}of kw)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Mw(t){const e=await bl(`${t}/package.json`);if(e)try{const r=JSON.parse(e),i=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(i.startsWith("bun@"))return"bun";if(i.startsWith("pnpm@"))return"pnpm";if(i.startsWith("yarn@"))return"yarn";if(i.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,i]of n){const a=await bl(`${t}/${r}`);if(typeof a=="string"&&a.trim().length>0)return i}return"npm"}async function bl(t){const e=pr()?.files;if(e?.readFile)try{const n=await e.readFile(t,{optional:!0});return typeof n?.content=="string"?n.content:null}catch{return null}try{const n=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return n.ok?n.text():null}catch{return null}}async function Ew(t){try{const e=await bl(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const Rw=t=>new Promise(e=>{window.setTimeout(e,t)}),Fw="\x1B",Lw=new RegExp(`${Fw}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Ow=/https?:\/\/[^\s<>'"`]+/gi,or="__vinci_auto_discover_preview__",$w=15e3,Bw=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},zw=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},Vw=t=>{const n=t.replace(Lw,"").match(Ow);if(!n||n.length===0)return null;const r=n.map(a=>a.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const i=[];for(const a of r)try{const l=new URL(a);l.port&&l.port.length>0&&i.push({raw:a,parsed:l})}catch{}if(i.length>0){const a=l=>{const{parsed:c}=l,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,h=m==="/"||m==="",x=!!(c.search||c.hash);let f=0;return p&&(f+=50),h&&(f+=30),f-=Math.min(u*5,20),x&&(f-=10),f};return i.sort((l,c)=>a(c)-a(l)),i[0]?.parsed.origin??i[0]?.raw??null}return r[0]??null},_w=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const i=r[0],a=r[1].slice(0,3),l=`${i} ${a}`.trim();return r.length>2||l.length<n.length?`${l}...`:l}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},am=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:i=!1})=>{const{t:a}=ut(),{terminal:l,runtime:c}=Pn(),{isMobile:d}=rn(),p=o.useMemo(()=>gn(),[]),m=Ys(q=>q.instances),u=Ys(q=>q.load),h=Ie(q=>q.setBottomTerminalOpen),x=Ie(q=>q.setActiveMainTab),f=Ie(q=>q.setSettingsPage),v=Ie(q=>q.setSettingsDialogOpen),y=Ie(q=>q.setSettingsProjectsSelectedId),g=Ie(q=>q.openContextPreview),w=on(q=>q.sessions),b=on(q=>q.ensureDirectory),k=on(q=>q.setTabLabel),I=on(q=>q.setTabIconKey),j=on(q=>q.setActiveTab),N=on(q=>q.setConnecting),D=on(q=>q.setTabSessionId),E=on(q=>q.setTabPreviewUrl),T=on(q=>q.projectActionRuns),C=on(q=>q.setProjectActionRun),S=on(q=>q.updateProjectActionRunStatus),M=on(q=>q.removeProjectActionRun),[A,R]=o.useState([]),[z,B]=o.useState(null),[V,$]=o.useState(!1),_=o.useRef({}),X=o.useRef({}),O=o.useRef({}),J=o.useRef({}),Q=o.useRef(0),ne=t?.id??null,G=t?.path??"",le=o.useMemo(()=>ne?{id:ne,path:G}:null,[ne,G]);o.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const oe=o.useCallback(async q=>{await rr(q)},[]),F=o.useCallback(async()=>{if(!le)return;const q=Q.current+1;Q.current=q,$(!0);try{const Se=await Yc(le);if(Q.current!==q)return;const $e=Se.actions;R($e),B(Pe=>Pe===or||Pe&&$e.some(fe=>fe.id===Pe)?Pe:null)}catch{if(Q.current!==q)return}finally{Q.current===q&&$(!1)}},[le]),U=o.useMemo(()=>Ih(e||le?.path||""),[e,le?.path]),W=o.useMemo(()=>z?A.find(q=>q.id===z)??null:null,[A,z]),te=o.useMemo(()=>({id:or,name:a("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[a]),K=!d,ae=o.useMemo(()=>K?[te,...A]:A,[A,te,K]);o.useEffect(()=>{F()},[F]),o.useEffect(()=>{if(typeof window>"u")return;const q=Se=>{const $e=Se.detail;ne&&($e?.projectId&&$e.projectId!==ne||F())};return window.addEventListener(nd,q),()=>{window.removeEventListener(nd,q)}},[F,ne]),o.useEffect(()=>{z&&(z===or&&K||A.some(q=>q.id===z)||B(null))},[A,K,z]),o.useEffect(()=>{for(const[q,Se]of Object.entries(T)){const Pe=w.get(Se.directory)?.tabs.find(fe=>fe.id===Se.tabId);(!Pe||Pe.terminalSessionId!==Se.sessionId)&&M(q)}},[T,M,w]),o.useEffect(()=>{for(const[q,Se]of Object.entries(T)){const $e=X.current[q]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};X.current[q]=$e;const Pe=ae.find(de=>de.id===Se.actionId);if(!Pe)continue;const L=w.get(Se.directory)?.tabs.find(de=>de.id===Se.tabId);if(!L||!Array.isArray(L.bufferChunks)||L.bufferChunks.length===0)continue;const Z=L.bufferChunks.filter(de=>$e.lastSeenChunkId===null?!0:de.id>$e.lastSeenChunkId);if(Z.length===0)continue;const Y=Z.map(de=>de.data).join(""),Ee=`${$e.tail}${Y}`,Ae=!$e.openedUrl&&Pe.autoOpenUrl===!0?Vw(Ee):null,Je=Z[Z.length-1]?.id??$e.lastSeenChunkId;if($e.lastSeenChunkId=Je,$e.tail=Ee.slice(-512),Ae)if($e.openedUrl=!0,$e.openInPreview){const de=T[q];de&&(E(de.directory,de.tabId,Ae,{locked:!1,autoOpened:!1}),de.status==="waiting-for-preview"&&S(q,"running"),window.clearTimeout(J.current[q]),delete J.current[q],g(de.directory,Ae))}else oe(Ae),H.success(a("projectActions.toast.openedUrlFromOutput"));X.current[q]=$e}for(const q of Object.keys(X.current))T[q]||(delete X.current[q],window.clearTimeout(J.current[q]),delete J.current[q])},[ae,g,oe,T,E,a,w,S]);const ve=o.useCallback(async(q,Se={})=>{if(!U)throw new Error(a("projectActions.error.noActiveDirectory"));const $e=ui(U,q.id);b(U);const Pe=on.getState(),fe=Pe.getDirectoryState(U);let L=_.current[$e]||null;const Z=L?!!fe?.tabs.some(Ae=>Ae.id===L):!1;(!L||!Z)&&(L=Pe.createTab(U),_.current[$e]=L),k(U,L,`Action: ${q.name}`),I(U,L,q.icon||"play"),Se.revealTerminal!==!1&&(j(U,L),h(!0),x("terminal"));const Ee=on.getState().getDirectoryState(U)?.tabs.find(Ae=>Ae.id===L);return{key:$e,tabId:L,sessionId:Ee?.terminalSessionId??null}},[b,U,x,j,h,I,k,a]),re=o.useCallback(async q=>{if(c.isVSCode||!i&&d)return;if(!U){H.error(a("projectActions.error.noActiveDirectoryForAction"));return}const Se=ui(U,q.id),$e=T[Se];if(!($e&&$e.status==="running"))try{const Pe=q.id===or?await(async()=>{const[Re,Xe]=await Promise.all([Yc({id:le?.id??"",path:U}),Ew(U)]),qe=await Pw(U,Re.actions,Xe);if(!qe)throw new Error(a("contextPanel.preview.noDevServer"));return{id:or,name:a("projectActions.actions.autoDiscover"),command:qe.command,icon:"search",autoOpenUrl:!0,openUrl:qe.previewUrlHint||""}})():q,fe=Pe.autoOpenUrl===!0&&(Pe.openUrl||"").trim().length>0,{key:L,tabId:Z,sessionId:Y}=await ve(Pe,{revealTerminal:!fe&&q.id!==or});let Ee=Y,Ae=!1;if(!Ee){N(U,Z,!0);try{Ee=(await l.createSession({cwd:U})).sessionId,Ae=!0,D(U,Z,Ee)}finally{N(U,Z,!1)}}if(!Ee)throw new Error(a("projectActions.error.failedToCreateTerminalSession"));Ae&&await Rw(350),Pe.id===or&&(O.current[L]?.(),N(U,Z,!0),O.current[L]=Ox(Ee,Re=>{Re.type==="data"&&typeof Re.data=="string"&&Re.data.length>0&&on.getState().appendToBuffer(U,Z,Re.data),Re.type==="exit"&&(on.getState().setTabLifecycle(U,Z,"exited"),on.getState().setConnecting(U,Z,!1),on.getState().removeProjectActionRun(L),delete X.current[L],O.current[L]?.(),delete O.current[L],window.clearTimeout(J.current[L]),delete J.current[L])},()=>{on.getState().setConnecting(U,Z,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Je=Pe.autoOpenUrl===!0&&p&&(Pe.desktopOpenSshForward||"").trim().length>0,de=Pe.autoOpenUrl?zw(Pe.openUrl):null,ze=Pe.autoOpenUrl&&p?Sw(Pe.desktopOpenSshForward,m):null;C({key:L,directory:U,actionId:Pe.id,tabId:Z,sessionId:Ee,status:Pe.id===or&&!de?"waiting-for-preview":"running"}),window.clearTimeout(J.current[L]),delete J.current[L],Pe.id===or&&!de&&(J.current[L]=window.setTimeout(()=>{on.getState().updateProjectActionRunStatus(L,"running"),delete J.current[L]},$w)),ze?(E(U,Z,null,{locked:!0}),oe(ze),H.success(a("projectActions.toast.openedForwardedUrl"))):de?(E(U,Z,de,{locked:!0,autoOpened:!0}),g(U,de),H.success(a("projectActions.toast.openedActionUrl"))):fe?(E(U,Z,null,{locked:!0}),H.error(a("projectActions.error.invalidCustomUrlFormat"))):Je?(E(U,Z,null,{locked:!0}),H.error(a("projectActions.error.selectedDesktopSshForwardUnavailable"))):E(U,Z,null,{locked:!1,autoOpened:!1}),X.current[L]={lastSeenChunkId:null,openedUrl:!!ze||!!de||fe,tail:"",openInPreview:Pe.id===or};const rt=Bw(Pe.command.trim().replace(/\r\n|\r/g,`
|
|
3
3
|
`));await l.sendInput(Ee,`${rt}\r`)}catch(Pe){M(Se),delete X.current[Se],O.current[Se]?.(),delete O.current[Se],window.clearTimeout(J.current[Se]),delete J.current[Se],H.error(Pe instanceof Error?Pe.message:a("projectActions.error.failedToRunAction"))}},[m,ve,i,d,p,U,oe,g,T,c.isVSCode,M,N,C,E,D,le?.id,a,l]),be=o.useCallback(async q=>{const Se=ui(U,q.id),$e=T[Se];if(!$e)return;S(Se,"stopping");try{await l.sendInput($e.sessionId,"")}catch{}if(await new Promise(L=>{window.setTimeout(L,1e3)}),on.getState().getDirectoryState($e.directory)?.tabs.find(L=>L.id===$e.tabId)?.terminalSessionId===$e.sessionId){if(typeof l.forceKill=="function")try{await l.forceKill({sessionId:$e.sessionId})}catch{}else try{await l.close($e.sessionId)}catch{}D($e.directory,$e.tabId,null)}M(Se),delete X.current[Se],O.current[Se]?.(),delete O.current[Se],window.clearTimeout(J.current[Se]),delete J.current[Se]},[U,T,M,D,l,S]),pe=o.useCallback(()=>{const q=W??ae[0];if(!q)return;const Se=ui(U,q.id),$e=T[Se];if($e?.status!=="stopping"){if($e){be(q);return}re(q)}},[ae,U,re,T,W,be]),ye=o.useCallback((q,Se=!1)=>{if(B(q.id),!Se){re(q);return}const $e=ui(U,q.id),Pe=T[$e];if(Pe?.status!=="stopping"){if(Pe){be(q);return}re(q)}},[U,re,T,be]),ie=o.useCallback(()=>{le?.id&&(y(le.id),f("projects"),v(!0))},[v,f,y,le?.id]);if(c.isVSCode||!i&&d||!le||!U)return null;const ue=W??ae[0]??null;if(!ue)return null;const se=ue.icon||"play",Ne=ue.id===or?"search":Zo[se]||"play",Ce=_w(ue.name,a("projectActions.label.fallbackAction")),je=ui(U,ue.id),we=T[je],ke=we?.status==="stopping",xe=we?.status==="waiting-for-preview",me=we?w.get(we.directory)?.tabs.find(q=>q.id===we.tabId)?.previewUrl??null:null,Me=!!(we&&me),Ue=()=>{!we||!me||g(we.directory,me)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:V||ke,className:ce("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:pe,"aria-label":we?a("projectActions.actions.stopNamedAria",{name:ue.name}):a("projectActions.actions.runNamedAria",{name:ue.name}),children:ke||xe?s.jsx(P,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):we?s.jsx(P,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(P,{name:Ne,className:"h-5 w-5"})}),Me?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":a("projectActions.actions.openPreview"),onClick:Ue,children:s.jsx(P,{name:"global",className:"h-4 w-4"})})}),s.jsx(Dt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":a("projectActions.actions.chooseActionAria"),children:s.jsx(P,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Rs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:ie,children:[s.jsx(P,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx(Cn,{}),ae.map(q=>{const Se=q.icon||"play",$e=q.id===or?"search":Zo[Se]||"play",Pe=ui(U,q.id),fe=T[Pe],L=!!fe,Z=fe?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{ye(q,!0)},children:[s.jsx(P,{name:$e,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),Z||fe?.status==="waiting-for-preview"?s.jsx(P,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):L?s.jsx(P,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]}):s.jsxs("div",{className:ce("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsxs("button",{type:"button",onClick:pe,disabled:V||ke,className:ce("inline-flex h-full items-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 justify-center px-0":"gap-2 px-3","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":we?a("projectActions.actions.stopNamedAria",{name:ue.name}):a("projectActions.actions.runNamedAria",{name:ue.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ke||xe?s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):we?s.jsx(P,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(P,{name:Ne,className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Ce})]}),Me?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ue,className:ce(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":a("projectActions.actions.openPreview"),children:s.jsx(P,{name:"global",className:"h-4 w-4"})})}),s.jsx(Dt,{sideOffset:6,children:a("projectActions.actions.openPreview")})]}):null,s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ce(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":a("projectActions.actions.chooseActionAria"),children:s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Rs,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:ie,children:[s.jsx(P,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("projectActions.actions.addNewAction")})]}),s.jsx(Cn,{}),ae.map(q=>{const Se=q.icon||"play",$e=q.id===or?"search":Zo[Se]||"play",Pe=ui(U,q.id),fe=T[Pe],L=!!fe,Z=fe?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{ye(q)},children:[s.jsx(P,{name:$e,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q.name}),Z||fe?.status==="waiting-for-preview"?s.jsx(P,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):L?s.jsx(P,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},q.id)})]})]})]})},_l="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:bg-interactive-hover transition-colors",Uw="app-region-no-drag inline-flex h-9 w-9 items-center justify-center gap-2 p-2 rounded-md typography-ui-label font-medium text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:text-foreground hover:bg-interactive-hover transition-colors",Ta=o.memo(function(e){const n=at.c(13),{visible:r,title:i,ariaLabel:a,onClick:l,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??_l,h=p??"h-[18px] w-[18px]";let x;n[0]!==d||n[1]!==h?(x=s.jsx(P,{name:d,className:h}),n[0]=d,n[1]=h,n[2]=x):x=n[2];let f;n[3]!==a||n[4]!==l||n[5]!==u||n[6]!==x?(f=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,"aria-label":a,className:u,children:x})}),n[3]=a,n[4]=l,n[5]=u,n[6]=x,n[7]=f):f=n[7];let v;n[8]!==i?(v=s.jsx(Dt,{children:s.jsx("p",{children:i})}),n[8]=i,n[9]=v):v=n[9];let y;return n[10]!==f||n[11]!==v?(y=s.jsxs(Pt,{children:[f,v]}),n[10]=f,n[11]=v,n[12]=y):y=n[12],y}),Ww=o.memo(function(e){const n=at.c(42),{isMobile:r,githubAuthStatus:i,githubAccounts:a,githubAvatarUrl:l,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=ut();if(!i?.connected||r)return null;if(a.length>1){let f;n[0]===Symbol.for("react.memo_cache_sentinel")?(f=ce(_l,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=f):f=n[0];let v;n[1]!==c||n[2]!==m?(v=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=v):v=n[3];let y;n[4]!==l||n[5]!==c||n[6]!==m?(y=l?s.jsx("img",{src:l,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(P,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=l,n[5]=c,n[6]=m,n[7]=y):y=n[7];let g;n[8]!==d||n[9]!==v||n[10]!==y?(g=s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:f,title:v,disabled:d,children:y})}),n[8]=d,n[9]=v,n[10]=y,n[11]=g):g=n[11];let w;n[12]!==m?(w=m("header.github.accountsTitle"),n[12]=m,n[13]=w):w=n[13];let b;n[14]!==w?(b=s.jsx(Ka,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=b):b=n[15];let k;n[16]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(Cn,{}),n[16]=k):k=n[16];let I;if(n[17]!==a||n[18]!==p||n[19]!==d||n[20]!==m){let D;n[22]!==p||n[23]!==d||n[24]!==m?(D=E=>{const T=E.user,C=!!E.current;return s.jsxs($t,{className:"gap-2",disabled:C||d,onSelect:()=>{C||p(E.id)},children:[T?.avatarUrl?s.jsx("img",{src:T.avatarUrl,alt:T.login?m("header.github.avatarWithLogin",{login:T.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(P,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:T?.name?.trim()||T?.login||"GitHub"}),T?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:T.login}):null]}),C?s.jsx(P,{name:"check",className:"h-4 w-4 text-primary"}):null]},E.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=D):D=n[25],I=a.map(D),n[17]=a,n[18]=p,n[19]=d,n[20]=m,n[21]=I}else I=n[21];let j;n[26]!==b||n[27]!==I?(j=s.jsxs(Rs,{align:"end",className:"w-64",children:[b,k,I]}),n[26]=b,n[27]=I,n[28]=j):j=n[28];let N;return n[29]!==g||n[30]!==j?(N=s.jsxs(Fs,{children:[g,j]}),n[29]=g,n[30]=j,n[31]=N):N=n[31],N}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let h;n[35]!==l||n[36]!==c||n[37]!==m?(h=l?s.jsx("img",{src:l,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(P,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=l,n[36]=c,n[37]=m,n[38]=h):h=n[38];let x;return n[39]!==u||n[40]!==h?(x=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:u,children:h}),n[39]=u,n[40]=h,n[41]=x):x=n[41],x}),Kw=o.memo(function(e){const n=at.c(76),{isDesktopApp:r,currentInstanceLabel:i,compactCurrentInstanceLabel:a,isDesktopServicesOpen:l,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:h,servicesTabItems:x,quotaLastUpdated:f,quotaDisplayMode:v,quotaDisplayTabItems:y,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:b,isUsageRefreshSpinning:k,hasRateLimits:I,rateLimitGroups:j,expandedFamilies:N,toggleFamilyExpanded:D,shortcutLabel:E,showDevShutdown:T,isDevShutdownInFlight:C,onDevShutdown:S}=e,{t:M}=ut();let A;n[0]!==p||n[1]!==h||n[2]!==u||n[3]!==d||n[4]!==c?(A=te=>{c(te),te&&(d(),p==="usage"&&u===0&&h())},n[0]=p,n[1]=h,n[2]=u,n[3]=d,n[4]=c,n[5]=A):A=n[5];let R;n[6]!==i||n[7]!==r||n[8]!==M?(R=r?M("header.services.openWithCurrent",{current:i}):M("header.services.open"),n[6]=i,n[7]=r,n[8]=M,n[9]=R):R=n[9];const z=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let B;n[10]!==z?(B=ce(_l,z),n[10]=z,n[11]=B):B=n[11];let V;n[12]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(P,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=V):V=n[12];let $;n[13]!==a||n[14]!==r?($=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:a}):null,n[13]=a,n[14]=r,n[15]=$):$=n[15];let _;n[16]!==R||n[17]!==B||n[18]!==$?(_=s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":R,className:B,children:[V,$]})})}),n[16]=R,n[17]=B,n[18]=$,n[19]=_):_=n[19];let X;n[20]!==i||n[21]!==r||n[22]!==E||n[23]!==M?(X=r?M("header.services.tooltip.currentInstanceWithShortcuts",{current:i,toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}):M("header.services.tooltip.servicesWithShortcuts",{toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}),n[20]=i,n[21]=r,n[22]=E,n[23]=M,n[24]=X):X=n[24];let O;n[25]!==X?(O=s.jsx(Dt,{children:s.jsx("p",{children:X})}),n[25]=X,n[26]=O):O=n[26];let J;n[27]!==_||n[28]!==O?(J=s.jsxs(Pt,{children:[_,O]}),n[27]=_,n[28]=O,n[29]=J):J=n[29];let Q;n[30]!==h||n[31]!==u||n[32]!==m?(Q=te=>{const K=te;m(K),K==="usage"&&u===0&&h()},n[30]=h,n[31]=u,n[32]=m,n[33]=Q):Q=n[33];let ne;n[34]!==p||n[35]!==x||n[36]!==Q?(ne=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(Cr,{items:x,activeId:p,onSelect:Q,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=p,n[35]=x,n[36]=Q,n[37]=ne):ne=n[37];let G;n[38]!==p||n[39]!==r||n[40]!==l||n[41]!==c?(G=r&&p==="instance"?s.jsx(Hx,{embedded:!0,open:l&&p==="instance",onOpenChange:qw,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=l,n[41]=c,n[42]=G):G=n[42];let le;n[43]!==p||n[44]!==l?(le=p==="mcp"?s.jsx(kh,{active:l&&p==="mcp"}):null,n[43]=p,n[44]=l,n[45]=le):le=n[45];let oe;n[46]!==p||n[47]!==N||n[48]!==g||n[49]!==w||n[50]!==I||n[51]!==b||n[52]!==k||n[53]!==v||n[54]!==y||n[55]!==f||n[56]!==j||n[57]!==M||n[58]!==D?(oe=p==="usage"?s.jsxs("div",{className:"overflow-x-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:M("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Dh(f)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Cr,{items:y,activeId:v,onSelect:te=>{g(te)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:ce("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:b||k,"aria-label":M("header.services.refreshRateLimitsAria"),children:s.jsx(P,{name:"refresh",className:ce("h-4 w-4",k&&"animate-spin")})})]})]}),I?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:M("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:j.map((te,K)=>{const ae=N[te.providerId]??[];return s.jsxs(o.Fragment,{children:[K>0?s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(vn,{providerId:te.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:te.providerName})]}),te.entries.length===0&&(!te.modelFamilies||te.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:te.error??M("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[te.entries.map(ve=>{const[re,be]=ve,pe=v==="remaining"?be.remainingPercent:be.usedPercent,ye=oo(be.usedPercent,be.resetAt,be.windowSeconds,re),ie=ye?.dailyAllocationPercent!=null?v==="remaining"?100-ei(ye.elapsedRatio):ei(ye.elapsedRatio):null,ue=ao(be.valueLabel,pe),se=Ud(be.resetAt,be.resetAfterFormatted??be.resetAtFormatted);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Wd(re)}),se?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:se}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ue==="-"?"":ue})]}),s.jsx(co,{percent:pe,tonePercent:be.usedPercent,className:"h-1.5",expectedMarkerPercent:ie}),ye?s.jsx(uo,{paceInfo:ye,compact:!0}):null]},`${te.providerId}-${re}`)}),te.modelFamilies&&te.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:te.modelFamilies.map(ve=>{const re=ve.familyId??"other",be=ae.includes(re);return s.jsxs(fr,{open:be,onOpenChange:()=>D(te.providerId,re),children:[s.jsxs(Pr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:ve.familyLabel}),be?s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(hr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ve.models.map(pe=>{const[ye,ie]=pe,ue=v==="remaining"?ie.remainingPercent:ie.usedPercent,se=oo(ie.usedPercent,ie.resetAt,ie.windowSeconds),Ne=se?.dailyAllocationPercent!=null?v==="remaining"?100-ei(se.elapsedRatio):ei(se.elapsedRatio):null,Ce=ao(ie.valueLabel,ue);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:gl(ye)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ce==="-"?"":Ce})]}),s.jsx(co,{percent:ue,tonePercent:ie.usedPercent,className:"h-1.5",expectedMarkerPercent:Ne}),se?s.jsx(uo,{paceInfo:se,compact:!0}):null]},`${te.providerId}-${ye}`)})})})]},re)})}):null]})]},te.providerId)})})]}):null,n[46]=p,n[47]=N,n[48]=g,n[49]=w,n[50]=I,n[51]=b,n[52]=k,n[53]=v,n[54]=y,n[55]=f,n[56]=j,n[57]=M,n[58]=D,n[59]=oe):oe=n[59];let F;n[60]!==C||n[61]!==S||n[62]!==T||n[63]!==M?(F=T?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx($t,{disabled:C,onSelect:()=>{S()},children:M("header.services.shutdownDev")})})]}):null,n[60]=C,n[61]=S,n[62]=T,n[63]=M,n[64]=F):F=n[64];let U;n[65]!==ne||n[66]!==G||n[67]!==le||n[68]!==oe||n[69]!==F?(U=s.jsxs(Rs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ne,G,le,oe,F]}),n[65]=ne,n[66]=G,n[67]=le,n[68]=oe,n[69]=F,n[70]=U):U=n[70];let W;return n[71]!==l||n[72]!==A||n[73]!==J||n[74]!==U?(W=s.jsxs(Fs,{open:l,onOpenChange:A,children:[J,U]}),n[71]=l,n[72]=A,n[73]=J,n[74]=U,n[75]=W):W=n[75],W}),Hw=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),Gw=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],i=n[1].slice(0,3),a=`${r} ${i}`.trim();return n.length>2||a.length<e.length?`${a}...`:a}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},Dh=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},lr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},To=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,om=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:i=null})=>{const{t:a}=ut(),l=Ie(Fe=>Fe.setSessionSwitcherOpen),c=Ie(Fe=>Fe.toggleSidebar),d=Ie(Fe=>Fe.isSidebarOpen),p=Ie(Fe=>Fe.isRightSidebarOpen),m=Ie(Fe=>Fe.toggleBottomTerminal),u=Ie(Fe=>Fe.toggleRightSidebar),h=Ie(Fe=>Fe.openContextOverview),x=Ie(Fe=>Fe.openContextPlan),f=Ie(Fe=>Fe.openContextBrowser),v=Ie(Fe=>Fe.closeContextPanel),y=Ie(Fe=>Fe.contextPanelByDirectory),g=Ie(Fe=>Fe.activeMainTab),w=Ie(Fe=>Fe.setActiveMainTab),b=Ie(Fe=>Fe.shortcutOverrides),k=xt(Fe=>Fe.getCurrentModel),I=Pn(),[j,N]=o.useState(!1),D=Ot(Fe=>Fe.getContextUsage),E=Ot(Fe=>Fe.openNewSessionDraft),T=Ot(Fe=>!!Fe.newSessionDraft?.open),C=Ot(Fe=>Fe.currentSessionId),S=Gx(C??""),M=Uf(C??null),A=Ei(Fe=>Fe.activeSessions),R=Ad(),z=As(Fe=>Fe.activeProjectId?Fe.projects.find(Ct=>Ct.id===Fe.activeProjectId)??null:null),B=o.useMemo(()=>{if(!z)return null;const Fe=z.label?.trim();if(Fe)return Fe;const Ct=z.path.split(/[\\/]/).filter(Boolean);return Ct[Ct.length-1]??null},[z]),V=Ms(Fe=>Fe.results),$=Ms(Fe=>Fe.fetchAllQuotas),_=Ms(Fe=>Fe.isLoading),X=Ms(Fe=>Fe.lastUpdated),O=Ms(Fe=>Fe.displayMode),J=Ms(Fe=>Fe.dropdownProviderIds),Q=Ms(Fe=>Fe.loadSettings),ne=Ms(Fe=>Fe.setDisplayMode),{isMobile:G}=rn(),le=Hn(Fe=>Fe.status),oe=Hn(Fe=>Fe.setStatus),F=o.useRef(null),[U,W]=o.useState(()=>typeof window>"u"?!1:gn()),te=o.useMemo(()=>Dd(),[]),K=El(),[ae,ve]=o.useState(!1),re=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),be=o.useMemo(()=>{if(typeof window>"u")return null;const Fe=window.__APP_MACOS_MAJOR__;if(typeof Fe=="number"&&Number.isFinite(Fe)&&Fe>0)return Fe;if(typeof navigator>"u")return null;const Ct=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Ct)return null;const Zt=Number.parseInt(Ct[1],10),ls=Number.parseInt(Ct[2],10);return Number.isNaN(Zt)?null:Zt===10?ls:Zt},[]);Be.useEffect(()=>{typeof window>"u"||W(gn())},[]);const pe=k(),ye=pe&&typeof pe.limit=="object"&&pe.limit!==null?pe.limit:null,ie=ye&&typeof ye.context=="number"?ye.context:0,ue=ye&&typeof ye.output=="number"?ye.output:0,se=D(ie,ue),[Ne,Ce]=o.useState(null),je=!C||S;Be.useEffect(()=>{if(!C){Ce(Fe=>Fe===null?Fe:null);return}if(se&&se.totalTokens>0){Ce(Fe=>Hw(Fe,se)?Fe:se);return}je&&Ce(Fe=>Fe===null?Fe:null)},[se,C,je]);const we=Ie(Fe=>Fe.isSessionSwitcherOpen),ke=le?.connected?le.user?.avatarUrl??null:null,xe=le?.connected?le.user?.login??null:null,me=le?.accounts??[],[Me,Ue]=o.useState(!1),[q,Se]=o.useState(!1),[$e,Pe]=o.useState(!1),[fe,L]=o.useState(!1),[Z,Y]=o.useState("Local"),Ee=o.useMemo(()=>Gw(Z),[Z]),[Ae,Je]=o.useState(U?"instance":"usage"),[de,ze]=o.useState("usage");Be.useEffect(()=>{!U&&Ae==="instance"&&Je("usage")},[Ae,U]);const rt=o.useMemo(()=>mn(),[]),Re=o.useMemo(()=>G?typeof t=="function"?!!n:we:d,[G,we,d,n,t]),Xe=!rt&&g==="chat"&&!!Ne&&Ne.totalTokens>0,qe=Ne&&Ne.contextLimit>0?Math.min(999,Ne.totalTokens/Ne.contextLimit*100):0,Te=o.useCallback(async()=>{if(!(typeof window>"u"||!U))try{const Fe=await qx(),Ct=window.location.href,Zt=window.__APP_LOCAL_ORIGIN__||window.location.origin;if(wu(Ct,Zt)){Y("Local");return}const ls=Fe.hosts.find(Bs=>wu(Ct,Bs.url));if(ls?.label?.trim()){Y(Yx(ls.label.trim()));return}Y("Instance")}catch{Y("Local")}},[U]);Be.useEffect(()=>{Te()},[Te]),Nh();const We=Ms(Fe=>Fe.selectedModels),Ze=Ms(Fe=>Fe.expandedFamilies),Qe=Ms(Fe=>Fe.toggleFamilyExpanded),he=o.useMemo(()=>{const Fe=[];for(const Ct of Hr){if(!J.includes(Ct.id))continue;const Zt=V.find(en=>en.providerId===Ct.id),ls=Zt?.usage?.windows??{},Bs=Zt?.usage?.models,Js=Object.entries(ls),ws={providerId:Ct.id,providerName:Ct.name,entries:Js,error:Zt&&!Zt.ok&&Zt.configured?Zt.error:void 0};if(Bs&&Object.keys(Bs).length>0){const en=We[Ct.id]??[],nn=en.length>0,Rn=_v(Bs,Ct.id),Fn=wh(Ct.id),Ur=jh(Fn);ws.modelFamilies=[];for(const Ln of Ur){const er=Rn.get(Ln.id)??[];if(er.length===0)continue;const br=nn?er.filter(dn=>en.includes(dn)):er;if(br.length===0)continue;const ar=[];for(const dn of br){const On=Bs[dn];if(On?.windows){const bn=Object.entries(On.windows);bn.length>0&&ar.push([dn,bn[0][1]])}}ar.length>0&&ws.modelFamilies.push({familyId:Ln.id,familyLabel:Ln.label,models:ar})}const xr=Rn.get(null)??[],Wr=nn?xr.filter(Ln=>en.includes(Ln)):xr;if(Wr.length>0){const Ln=[];for(const er of Wr){const br=Bs[er];if(br?.windows){const ar=Object.entries(br.windows);ar.length>0&&Ln.push([er,ar[0][1]])}}Ln.length>0&&ws.modelFamilies.push({familyId:null,familyLabel:a("header.services.modelFamily.other"),models:Ln})}}(Js.length>0||ws.modelFamilies&&ws.modelFamilies.length>0||ws.error)&&Fe.push(ws)}return Fe},[J,V,We,a]),Ge=he.length>0;o.useEffect(()=>{Q()},[Q]);const Ve=o.useCallback(async Fe=>{ne(Fe);try{await ks({usageDisplayMode:Fe})}catch(Ct){console.warn("Failed to update usage display mode:",Ct)}},[ne]),it=o.useCallback(()=>{if(fe)return;L(!0);const Fe=new Promise(Ct=>setTimeout(Ct,500));Promise.all([$(),Fe]).finally(()=>{L(!1)})},[$,fe]),dt=o.useMemo(()=>C?R.find(Fe=>Fe.id===C)??A.find(Fe=>Fe.id===C)??M??Qx().find(Fe=>Fe.id===C)??null:null,[C,M,A,R]),Ye=o.useRef(null),[_e,et]=o.useState(0);o.useEffect(()=>{if(!C){Ye.current&&(Ye.current=null,et(ls=>ls+1));return}if(dt){Ye.current={sessionId:C,session:dt,expiresAt:Date.now()+2e3};return}const Fe=Ye.current;if(!Fe||Fe.sessionId!==C)return;const Ct=Fe.expiresAt-Date.now();if(Ct<=0){Ye.current=null,et(ls=>ls+1);return}const Zt=window.setTimeout(()=>{Ye.current?.sessionId===C&&(Ye.current=null),et(ls=>ls+1)},Ct);return()=>{window.clearTimeout(Zt)}},[C,dt]);const gt=(()=>{if(dt)return dt;if(!C)return null;const Fe=Ye.current;return Fe&&Fe.sessionId===C&&Fe.expiresAt>Date.now()?Fe.session:null})(),Lt=Ot(Fe=>C?Fe.worktreeMetadata.get(C)?.path??"":""),Ut=Ot(Fe=>C?Fe.worktreeMetadata.get(C)?.branch?.trim()??null:null),mt=Wf(Fe=>C?Fe.getAttachment(C):void 0),Nt=o.useMemo(()=>mt?Jx(mt):null,[mt]),Xt=o.useMemo(()=>mt?mt.legacy?"legacy":mt.degraded?"degraded":mt.worktreeStatus==="missing"?"missing":mt.worktreeStatus==="invalid"?"invalid":mt.attentionReason?"attention":null:null,[mt]),_t=o.useMemo(()=>lr(Lt||""),[Lt]),Gt=o.useMemo(()=>{const Fe=typeof gt?.directory=="string"?gt.directory:"";return lr(Fe||"")},[gt?.directory]),lt=Ot(Fe=>Fe.newSessionDraft?.open?lr(Fe.newSessionDraft.bootstrapPendingDirectory??Fe.newSessionDraft.directoryOverride??""):""),Tt=o.useMemo(()=>_t||Gt||lt,[lt,Gt,_t]),rs=Ot(Fe=>{const Ct=lr(_t||Gt||"");if(!Ct)return null;for(const Zt of Fe.availableWorktreesByProject.values()){const Bs=Zt.find(Js=>lr(Js.path)===Ct)?.branch?.trim();if(Bs)return Bs}return null}),ys=Xx(Tt||null)||Ut||rs,vs=o.useMemo(()=>{if(!C)return B??"Vinci";const Fe=gt?.title?.trim();return Fe&&Fe.length>0?Fe:"Untitled Session"},[B,gt?.title,C]),Wt=o.useMemo(()=>Kf(gt?.summary),[gt?.summary]),He=o.useMemo(()=>Wt||{additions:0,deletions:0},[Wt]),kt=He.additions>0||He.deletions>0,Kt=o.useMemo(()=>lr(Tt||z?.path||""),[z?.path,Tt]),wt=o.useMemo(()=>z?{id:z.id,path:z.path}:null,[z]),Qt=o.useRef(null);o.useEffect(()=>{!wt||!Kt||(Qt.current={projectRef:wt,directory:Kt})},[Kt,wt]);const cs=o.useMemo(()=>wt&&Kt?{projectRef:wt,directory:Kt}:Qt.current,[Kt,wt]),Ls=Td(Fe=>Fe.planModeEnabled),Ss=Ot(Fe=>Fe.isSessionPlanAvailable),ns=Ls&&C?Ss(C):!1,Os=ns,Ks=o.useRef("");o.useEffect(()=>{if(!Ls){Ie.getState().activeMainTab==="plan"&&Ie.getState().setActiveMainTab("chat");return}if(!C)return;const Fe=`${C||"none"}:${Gt||"none"}:${gt?.time?.created||0}:${gt?.slug||"none"}`;Ks.current!==Fe&&(Ks.current=Fe),!ns&&Ie.getState().activeMainTab==="plan"&&Ie.getState().setActiveMainTab("chat")},[Ls,ns,gt?.slug,gt?.time?.created,C,Gt]);const bt=o.useCallback(async Fe=>{if(!(!Fe||Me)){Ue(!0);try{const Ct=I.github?await I.github.authActivate(Fe):await(async()=>{const Zt=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Fe})}),ls=await Zt.json().catch(()=>null);if(!Zt.ok||!ls)throw new Error(ls?.error||Zt.statusText);return ls})();oe(Ct)}catch(Ct){console.error("Failed to switch GitHub account:",Ct)}finally{Ue(!1)}}},[Me,I.github,oe]),Mt=o.useCallback(()=>{if(typeof document>"u")return;const Fe=document.activeElement;if(!Fe)return;const Ct=Fe.tagName;(Ct==="INPUT"||Ct==="TEXTAREA"||Ct==="SELECT"||Fe.isContentEditable)&&Fe.blur()},[]),At=o.useCallback(()=>{if(G){Mt(),l(!we);return}c()},[Mt,G,we,l,c]),ee=o.useCallback(()=>{w("chat"),l(!1),E()},[E,w,l]),ht=o.useCallback(()=>{ml("desktop_open_draft_mini_chat_window",{directory:lr(Tt||z?.path||""),projectId:z?.id??null}).catch(Fe=>{console.warn("[header] failed to open draft mini chat window",Fe)})},[z?.id,z?.path,Tt]),St=o.useCallback(()=>{if(T){ht();return}C&&ml("desktop_open_session_mini_chat_window",{sessionId:C,directory:lr(Tt||z?.path||"")}).catch(Fe=>{console.warn("[header] failed to open session mini chat window",Fe)})},[z?.path,C,ht,T,Tt]),qt=o.useCallback(()=>{const Fe=lr(Tt||"");if(!Fe)return;const Ct=y[Fe];if(To(Ct)==="context"){v(Fe);return}h(Fe)},[v,y,h,Tt]),ms=o.useMemo(()=>{const Fe=lr(Tt||"");if(!Fe)return!1;const Ct=y[Fe];return To(Ct)==="context"},[y,Tt]),Ds=o.useCallback(()=>{const Fe=lr(Tt||"");if(!Fe)return;const Ct=y[Fe];if(To(Ct)==="plan"){v(Fe);return}x(Fe)},[v,y,x,Tt]),Ke=o.useCallback(()=>{const Fe=lr(Tt||"");Fe&&f(Fe)},[f,Tt]),yt=o.useMemo(()=>{const Fe=lr(Tt||"");if(!Fe)return!1;const Ct=y[Fe];return To(Ct)==="plan"},[y,Tt]),Et=_l,Ht=Uw,ss=o.useMemo(()=>!d&&(U&&re&&!ae||K)?"pl-[5.5rem]":"pl-3",[U,ae,re,d,K]);Be.useEffect(()=>{if(!U||!re){ve(!1);return}let Fe=!1,Ct=null;const Zt=async()=>{try{const{getCurrentWindow:Bs}=await kr(async()=>{const{getCurrentWindow:en}=await import("./vendor-.bun-B9l0ZNi2.js").then(nn=>nn.bM);return{getCurrentWindow:en}},__vite__mapDeps([0,1])),ws=await Bs().isFullscreen();Fe||ve(ws)}catch{Fe||ve(!1)}},ls=async()=>{try{const{getCurrentWindow:Bs}=await kr(async()=>{const{getCurrentWindow:ws}=await import("./vendor-.bun-B9l0ZNi2.js").then(en=>en.bM);return{getCurrentWindow:ws}},__vite__mapDeps([0,1]));Ct=await Bs().onResized(()=>{Zt()})}catch{}};return Zt(),ls(),()=>{Fe=!0,Ct&&Ct()}},[U,re]);const Rt=o.useMemo(()=>!U||!re||be===null?"":be>=26?"h-12":be<=15?"h-14":"",[U,re,be]),Ps=o.useMemo(()=>{if(!(U||rt))return{paddingLeft:K&&!d?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[U,d,K,rt]),Qs=o.useCallback(()=>{if(typeof document>"u")return;const Fe=F.current?.getBoundingClientRect().height;Fe&&document.documentElement.style.setProperty("--oc-header-height",`${Fe}px`)},[]);Be.useEffect(()=>{if(typeof window>"u")return;Qs();const Fe=F.current;if(!Fe||typeof ResizeObserver>"u")return()=>{};let Ct=0;const Zt=()=>{Ct||(Ct=requestAnimationFrame(()=>{Ct=0,Qs()}))},ls=new ResizeObserver(Zt);return ls.observe(Fe),window.addEventListener("resize",Zt),window.addEventListener("orientationchange",Zt),()=>{Ct&&cancelAnimationFrame(Ct),ls.disconnect(),window.removeEventListener("resize",Zt),window.removeEventListener("orientationchange",Zt)}},[Qs]),Be.useEffect(()=>{Qs()},[Qs,G,Rt]);const Hs=o.useCallback(async Fe=>{const Ct=Fe.target;Ct.closest(".app-region-no-drag")||Ct.closest("button, a, input, select, textarea")||Fe.button===0&&U&&await Hf()},[U]),ts=o.useMemo(()=>{if(G){const Fe=[{id:"chat",label:a("layout.mainTab.chat"),icon:"chat-4"}];return Os&&Fe.push({id:"plan",label:a("layout.mainTab.plan"),icon:"file-text"}),Fe.push({id:"diff",label:a("layout.mainTab.diff"),icon:"diff"},{id:"files",label:a("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:a("layout.mainTab.terminal"),icon:"terminal-box"}),Fe}return[]},[G,Os,a]),Ns=o.useCallback(Fe=>Rl(Zr(Fe,b)),[b]);Be.useEffect(()=>{!G&&(g==="git"||g==="terminal"||g==="diff"||g==="files")&&w("chat")},[g,G,w]);const jn=o.useMemo(()=>{const Fe=[];return U&&Fe.push({value:"instance",label:a("layout.services.instance"),icon:"server"}),Fe.push({value:"usage",label:a("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:Zv}),Fe},[U,a]),sn=o.useMemo(()=>jn.map(Fe=>({id:Fe.value,label:Fe.label,icon:s.jsx(P,{name:Fe.icon,className:"h-3.5 w-3.5"})})),[jn]),Dr=o.useMemo(()=>{if(typeof window>"u"||U||rt)return!1;const Fe=window.location.hostname;return Fe==="localhost"||Fe==="127.0.0.1"||Fe==="::1"},[U,rt]),Tr=o.useCallback(async()=>{if(j)return;N(!0),Pe(!1);const Fe=[];let Ct=!1;try{try{for(const[,Zt]of on.getState().sessions.entries())for(const ls of Zt.tabs)ls.previewUrl&&Fe.push(ls.previewUrl)}catch{}try{await $x({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Fe})})).ok?Ct=!0:Ct=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Ct||N(!1)}},[j,Pe]),zr=o.useMemo(()=>[{value:"usage",label:a("header.services.used")},{value:"remaining",label:a("header.services.remaining")}],[a]),Vr=o.useMemo(()=>zr.map(Fe=>({id:Fe.value,label:Fe.label})),[zr]),Gs=o.useMemo(()=>[{id:"usage",label:a("layout.services.usage"),icon:s.jsx(P,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(P,{name:"command",className:"h-3.5 w-3.5"})}],[a]);Be.useEffect(()=>{const Fe=Ct=>{if(Md(Ct)&&!Ct.shiftKey&&!Ct.altKey){const Zt=parseInt(Ct.key,10);Zt>=1&&Zt<=ts.length&&(Ct.preventDefault(),w(ts[Zt-1].id))}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[ts,w]),Be.useEffect(()=>{const Fe=Ct=>{const Zt=Zr("toggle_services_menu",b);if(Yo(Ct,Zt)){Ct.preventDefault(),$e?Pe(!1):(Pe(!0),Te(),Ae==="usage"&&V.length===0&&$());return}const ls=Zr("cycle_services_tab",b);if(Yo(Ct,ls)){Ct.preventDefault();const Js=jn.map(Rn=>Rn.value);if(Js.length===0)return;const ws=Js.indexOf(Ae),en=ws===-1?0:(ws+1)%Js.length,nn=Js[en];Je(nn),Pe(!0),Te(),nn==="usage"&&V.length===0&&$();return}const Bs=Zr("toggle_context_plan",b);Yo(Ct,Bs)&&(Ct.preventDefault(),Ds())};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[b,$e,Ae,jn,V.length,$,Te,Ds]);const Mn=Fe=>{const Ct=g===Fe.id,Zt=Fe.icon==="diff",ls=Zt?null:Fe.icon,Bs=Fe.id==="chat",Js=en=>Zt?s.jsx(Yu,{size:en}):ls?s.jsx(P,{name:ls,className:`h-${en/4} w-${en/4}`}):null,ws=s.jsxs("button",{type:"button",onClick:()=>w(Fe.id),className:ce("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Ct?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",Bs&&!G&&"min-w-[100px] justify-center"),"aria-label":Fe.label,"aria-selected":Ct,role:"tab",children:[G?Js(20):s.jsxs(s.Fragment,{children:[Js(16),s.jsx("span",{className:"header-tab-label",children:Fe.label})]}),Fe.badge!==void 0&&Fe.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Fe.badge})]});return s.jsx(o.Fragment,{children:ws},Fe.id)},ir=s.jsxs(s.Fragment,{children:[Os&&s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.openPlanAria"),onClick:Ds,className:ce(Et,yt&&"bg-[var(--interactive-hover)]"),children:s.jsx(P,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("header.actions.planWithShortcut",{shortcut:Ns("toggle_context_plan")})})})]}),s.jsx(iw,{directory:Kt,className:"mr-1"}),s.jsx(Kw,{isDesktopApp:U,currentInstanceLabel:Z,compactCurrentInstanceLabel:Ee,isDesktopServicesOpen:$e,setIsDesktopServicesOpen:Pe,refreshCurrentInstanceLabel:Te,desktopServicesTab:Ae,setDesktopServicesTab:Je,quotaResultsLength:V.length,fetchAllQuotas:$,servicesTabItems:sn,quotaLastUpdated:X,quotaDisplayMode:O,quotaDisplayTabItems:Vr,handleDisplayModeChange:Ve,handleUsageRefresh:it,isQuotaLoading:_,isUsageRefreshSpinning:fe,hasRateLimits:Ge,rateLimitGroups:he,expandedFamilies:Ze,toggleFamilyExpanded:Qe,shortcutLabel:Ns,showDevShutdown:Dr,isDevShutdownInFlight:j,onDevShutdown:Tr}),s.jsx(Ta,{title:a("header.actions.terminalPanelWithShortcut",{shortcut:Ns("toggle_terminal")}),ariaLabel:a("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:"terminal-box"}),te?s.jsx(Ta,{title:a("contextPanel.browser.open"),ariaLabel:a("contextPanel.browser.open"),onClick:Ke,Icon:"global"}):null,s.jsx(Ta,{title:a("header.actions.rightSidebarWithShortcut",{shortcut:Ns("toggle_right_sidebar")}),ariaLabel:a("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx(Ww,{isMobile:G,githubAuthStatus:le,githubAccounts:me,githubAvatarUrl:ke,githubLogin:xe,isSwitchingGitHubAccount:Me,handleGitHubAccountSwitch:bt})]}),En=!p||!i,_r=te&&(T||!!C),In=()=>s.jsxs("div",{onMouseDown:Hs,className:ce("app-region-drag relative flex h-12 select-none items-center pr-3",ss,Rt),style:Ps,role:"tablist","aria-label":a("header.navigation.mainAria"),children:[s.jsx(Ta,{visible:!d,title:a("header.actions.openSessionsWithShortcut",{shortcut:Ns("toggle_sidebar")}),ariaLabel:a("header.actions.openSessionsAria"),onClick:At,className:`${Et} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:ce("flex min-w-0 flex-1 items-center",!d&&"pl-3"),children:[Re?null:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.newSessionAria"),onClick:ee,className:ce(Et,"mr-6 shrink-0"),children:s.jsx(P,{name:"chat-new",className:"h-[18px] w-[18px]"})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("header.actions.newSessionWithShortcut",{shortcut:Ns("new_chat")})})})]}),cs&&s.jsx(am,{projectRef:cs.projectRef,directory:cs.directory,className:"mr-2"}),s.jsx(Zx,{children:s.jsxs("button",{type:"button","aria-label":a("sessions.switcher.openAria"),className:"app-region-no-drag mr-3 flex min-w-0 flex-col items-start rounded-md px-1 py-0.5 -my-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:T?a("sessions.switcher.draftTitle"):vs}),B||ys||!T&&(kt||Xt)?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[B?s.jsx("span",{className:"truncate",children:B}):null,ys?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ys})]}):null,!T&&kt?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",He.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",He.deletions]})]}):null,!T&&Xt?s.jsxs("span",{className:ce("inline-flex min-w-0 items-center gap-0.5",Xt==="attention"||Xt==="invalid"||Xt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(P,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Nt})]}):null]}):null]})}),ts.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:ts.map(Fe=>Mn(Fe))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Xe&&Ne?s.jsx(eb,{totalTokens:Ne.totalTokens,percentage:qe,colorPercentage:Ne.percentage,contextLimit:Ne.contextLimit,outputLimit:Ne.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:qt,pressed:ms,className:En&&!_r?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ta,{visible:_r,title:a(T?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:a(T?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:St,className:ce(Et,En&&Xe?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),En?ir:null,!En&&i?Wa.createPortal(ir,i):null]})]})]}),ln=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:t,className:ce(Ht,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":a(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(P,{name:"layout-left",className:"h-5 w-5"})}):we?s.jsx("button",{type:"button",onClick:()=>l(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":a("header.actions.backAria"),children:s.jsx(P,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:At,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":a("header.actions.openSessionsAria"),children:s.jsx(P,{name:"play-list-add",className:"h-5 w-5"})}),we&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:a("header.sessions.title")})]}),!we&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":a("header.navigation.mainAria"),children:ts.map(Fe=>{const Ct=g===Fe.id,Zt=Fe.icon==="diff",ls=Zt?null:Fe.icon;return s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{G&&Mt(),w(Fe.id)},"aria-label":Fe.label,"aria-selected":Ct,role:"tab",className:ce(Ht,"relative rounded-lg",Ct&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Zt?s.jsx(Yu,{className:"h-5 w-5"}):ls?s.jsx(P,{name:ls,className:"h-5 w-5"}):null,Fe.badge!==void 0&&Fe.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Fe.badge}),Fe.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":a("header.changes.availableAria")})]})}),s.jsx(Dt,{children:s.jsx("p",{children:Fe.label})})]},Fe.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[cs&&s.jsx(am,{projectRef:cs.projectRef,directory:cs.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(Fs,{open:q,onOpenChange:Fe=>{Se(Fe),Fe&&V.length===0&&$()},children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.services.viewAria"),className:Ht,children:s.jsx(P,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("header.services.title")})})]}),s.jsx(Rs,{align:"end",sideOffset:0,className:"h-dvh w-[100vw] max-h-none rounded-none border-0 p-0 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(Cr,{items:Gs,activeId:de,onSelect:Fe=>{const Ct=Fe;ze(Ct),Ct==="usage"&&V.length===0&&$()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>Se(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":a("header.services.closeAria"),children:s.jsx(P,{name:"close",className:"h-5 w-5"})})]})}),de==="mcp"&&s.jsx(kh,{active:q&&de==="mcp"}),de==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:a("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Dh(X)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>Ve("usage"),className:ce("typography-ui-label px-1 pb-0.5 transition-colors",O==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Ve("remaining"),className:ce("typography-ui-label px-1 pb-0.5 transition-colors",O==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:a("header.services.remaining")})]}),s.jsx("button",{type:"button",className:ce("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:it,disabled:_||fe,"aria-label":a("header.services.refreshRateLimitsAria"),children:s.jsx(P,{name:"refresh",className:ce("h-4 w-4",fe&&"animate-spin")})})]})]})}),!Ge&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:a("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:he.map((Fe,Ct)=>s.jsxs(o.Fragment,{children:[Ct>0?s.jsx("div",{className:"mx-4 my-1 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(vn,{providerId:Fe.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Fe.providerName})]}),Fe.entries.length===0&&(!Fe.modelFamilies||Fe.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Fe.error??a("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Fe.entries.map(([Zt,ls])=>{const Bs=O==="remaining"?ls.remainingPercent:ls.usedPercent,Js=oo(ls.usedPercent,ls.resetAt,ls.windowSeconds,Zt),ws=Js?.dailyAllocationPercent!=null?O==="remaining"?100-ei(Js.elapsedRatio):ei(Js.elapsedRatio):null,en=ao(ls.valueLabel,Bs),nn=Ud(ls.resetAt,ls.resetAfterFormatted??ls.resetAtFormatted);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Wd(Zt)}),nn?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:nn}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:en==="-"?"":en})]}),s.jsx(co,{percent:Bs,tonePercent:ls.usedPercent,className:"h-1.5",expectedMarkerPercent:ws}),Js?s.jsx(uo,{paceInfo:Js,compact:!0}):null]},`${Fe.providerId}-${Zt}`)}),Fe.modelFamilies&&Fe.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Fe.modelFamilies.map(Zt=>{const Bs=(Ze[Fe.providerId]??[]).includes(Zt.familyId??"other");return s.jsxs(fr,{open:Bs,onOpenChange:()=>Qe(Fe.providerId,Zt.familyId??"other"),children:[s.jsxs(Pr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Zt.familyLabel}),Bs?s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(P,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(hr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Zt.models.map(([Js,ws])=>{const en=O==="remaining"?ws.remainingPercent:ws.usedPercent,nn=oo(ws.usedPercent,ws.resetAt,ws.windowSeconds),Rn=nn?.dailyAllocationPercent!=null?O==="remaining"?100-ei(nn.elapsedRatio):ei(nn.elapsedRatio):null,Fn=ao(ws.valueLabel,en);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:gl(Js)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Fn==="-"?"":Fn})]}),s.jsx(co,{percent:en,tonePercent:ws.usedPercent,className:"h-1.5",expectedMarkerPercent:Rn}),nn?s.jsx(uo,{paceInfo:nn,compact:!0}):null]},`${Fe.providerId}-${Js}`)})})})]},Zt.familyId??"other")})})]})]},Fe.providerId))})]})]})})]}),e?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:ce(Ht,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(P,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Dt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),an=ce("header-safe-area relative z-10",G&&"border-b border-border/50","bg-background");return s.jsx("header",{ref:F,className:an,style:{"--padding-scale":"1"},children:G?ln():In()})};function qw(){}const lm=180,cm=640,Yw=110,Qw=t=>{const e=at.c(44),{isOpen:n,isMobile:r,children:i}=t,{t:a}=ut(),l=Ie(Jw),c=Ie(Xw),d=Ie(Zw),p=Ie(e1),[m,u]=o.useState(null),[h,x]=o.useState(!1),f=o.useRef(null),v=o.useRef(0),y=o.useRef(l||300),g=Math.min(cm,Math.max(lm,l||300));let w,b;e[0]!==n?(w=()=>{n||(u(null),x(!1))},b=[n],e[0]=n,e[1]=w,e[2]=b):(w=e[1],b=e[2]),o.useEffect(w,b);let k,I;e[3]!==c||e[4]!==r||e[5]!==n?(k=()=>{if(r||!n||!c)return;const Q=()=>{const le=f.current?.parentElement?.getBoundingClientRect().height;if(!le||le<=0)return;const oe=Math.max(0,Math.round(le));u(F=>F===oe?F:oe)};Q();const ne=f.current?.parentElement;if(!ne)return;const G=new ResizeObserver(Q);return G.observe(ne),()=>{G.disconnect()}},I=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=k,e[7]=I):(k=e[6],I=e[7]),o.useEffect(k,I);let j,N;if(e[8]!==c||e[9]!==r||e[10]!==h||e[11]!==d||e[12]!==p?(j=()=>{if(r||!h||c)return;const Q=G=>{const le=v.current-G.clientY,oe=Math.min(cm,Math.max(lm,y.current+le));d(oe)},ne=()=>{x(!1),Ie.getState().bottomTerminalHeight<=Yw&&p(!1)};return window.addEventListener("pointermove",Q),window.addEventListener("pointerup",ne,{once:!0}),()=>{window.removeEventListener("pointermove",Q),window.removeEventListener("pointerup",ne)}},N=[c,r,h,d,p],e[8]=c,e[9]=r,e[10]=h,e[11]=d,e[12]=p,e[13]=j,e[14]=N):(j=e[13],N=e[14]),o.useEffect(j,N),r)return null;const D=n?c?Math.max(0,m??g):g:0,E=n&&c;let T;e[15]!==D||e[16]!==c||e[17]!==n?(T=Q=>{!n||c||(x(!0),v.current=Q.clientY,y.current=D,Q.preventDefault())},e[15]=D,e[16]=c,e[17]=n,e[18]=T):T=e[18];const C=T,S=E?"absolute inset-x-0 bottom-0 z-40":"relative",M=h?"transition-none":"transition-[height] duration-300 ease-in-out",A=!n&&"border-t-0";let R;e[19]!==A||e[20]!==S||e[21]!==M?(R=ce("flex overflow-hidden border-t border-border bg-sidebar",S,M,A),e[19]=A,e[20]=S,e[21]=M,e[22]=R):R=e[22];let z;e[23]!==D||e[24]!==E?(z=E?{top:"var(--oc-header-height, 48px)"}:{height:`${D}px`,minHeight:`${D}px`,maxHeight:`${D}px`},e[23]=D,e[24]=E,e[25]=z):z=e[25];const B=!n||!c&&D===0;let V;e[26]!==C||e[27]!==c||e[28]!==n||e[29]!==h||e[30]!==a?(V=n&&!c&&s.jsx("div",{className:ce("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",h&&"bg-[var(--interactive-border)]"),onPointerDown:C,role:"separator","aria-orientation":"horizontal","aria-label":a("terminalView.bottomDock.resizeAria")}),e[26]=C,e[27]=c,e[28]=n,e[29]=h,e[30]=a,e[31]=V):V=e[31];const $=!n&&"pointer-events-none select-none opacity-0";let _;e[32]!==$?(_=ce("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",$),e[32]=$,e[33]=_):_=e[33];const X=!n;let O;e[34]!==i||e[35]!==_||e[36]!==X?(O=s.jsx("div",{className:_,"aria-hidden":X,children:i}),e[34]=i,e[35]=_,e[36]=X,e[37]=O):O=e[37];let J;return e[38]!==R||e[39]!==z||e[40]!==B||e[41]!==V||e[42]!==O?(J=s.jsxs("section",{ref:f,className:R,style:z,"aria-hidden":B,children:[V,O]}),e[38]=R,e[39]=z,e[40]=B,e[41]=V,e[42]=O,e[43]=J):J=e[43],J};function Jw(t){return t.bottomTerminalHeight}function Xw(t){return t.isBottomTerminalExpanded}function Zw(t){return t.setBottomTerminalHeight}function e1(t){return t.setBottomTerminalOpen}const rd=280,dm=280,um=500,t1=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:i}=ut(),a=Ie(k=>k.sidebarWidth),l=Ie(k=>k.setSidebarWidth),[c,d]=o.useState(!1),p=o.useRef(0),m=o.useRef(a||rd),u=o.useRef(null),h=o.useRef(null),x=o.useRef(null),f=o.useCallback(k=>Math.min(um,Math.max(dm,k)),[]),v=o.useCallback(k=>{const I=x.current;I&&I.style.setProperty("--oc-left-sidebar-width",`${k}px`)},[]);if(o.useEffect(()=>{e&&c&&d(!1)},[e,c]),o.useEffect(()=>{c||(u.current=null,h.current=null)},[c]),e)return null;const y=t?Math.min(um,Math.max(dm,a||rd)):0,g=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}h.current=k.pointerId,d(!0),p.current=k.clientX,m.current=y,u.current=y,v(y),k.preventDefault()}},w=k=>{if(e||!c||h.current!==k.pointerId)return;const I=k.clientX-p.current,j=f(m.current+I);u.current!==j&&(u.current=j,v(j))},b=k=>{if(h.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const I=f(u.current??y);h.current=null,u.current=null,d(!1),l(I)};return s.jsxs("aside",{ref:x,className:ce("relative flex h-full overflow-hidden border-r border-border/40","bg-sidebar",c?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-r-0",r),style:{width:"var(--oc-left-sidebar-width)",minWidth:"var(--oc-left-sidebar-width)",maxWidth:"var(--oc-left-sidebar-width)","--oc-left-sidebar-width":`${c?u.current??y:y}px`,overflowX:"clip"},"aria-hidden":!t||y===0,children:[t&&s.jsx("div",{className:ce("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:g,onPointerMove:w,onPointerUp:b,onPointerCancel:b,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:ce("relative z-10 flex h-full flex-col transition-opacity duration-300 ease-in-out",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Xs,{children:n})})})]})},Th=420,mm=400,pm=860,s1=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:i}=ut(),a=Ie(E=>E.rightSidebarWidth),l=Ie(E=>E.setRightSidebarWidth),c=o.useMemo(()=>gn(),[]),d=o.useMemo(()=>mn(),[]),p=El(),[m,u]=o.useState(!1),h=o.useRef(0),x=o.useRef(a||420),f=o.useRef(null),v=o.useRef(null),y=o.useRef(null),g=o.useCallback(E=>Math.min(pm,Math.max(mm,E)),[]),w=o.useCallback(E=>{const T=y.current;T&&T.style.setProperty("--oc-right-sidebar-width",`${E}px`)},[]),b=t?Math.min(pm,Math.max(mm,a||Th)):0,k=E=>{if(t){try{E.currentTarget.setPointerCapture(E.pointerId)}catch{}v.current=E.pointerId,u(!0),h.current=E.clientX,x.current=b,f.current=b,w(b),E.preventDefault()}},I=E=>{if(!m||v.current!==E.pointerId)return;const T=h.current-E.clientX,C=g(x.current+T);f.current!==C&&(f.current=C,w(C))},j=E=>{if(v.current!==E.pointerId)return;try{E.currentTarget.releasePointerCapture(E.pointerId)}catch{}const T=g(f.current??b);v.current=null,f.current=null,u(!1),l(T)};o.useEffect(()=>{m||(f.current=null,v.current=null)},[m]),o.useEffect(()=>{t||r?.(null)},[t,r]);const N=o.useCallback(async E=>{const T=E.target;T.closest(".app-region-no-drag")||T.closest("button, a, input, select, textarea")||E.button===0&&c&&await Hf()},[c]),D=o.useMemo(()=>{if(!(c||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...p?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[c,p,d]);return s.jsxs("aside",{ref:y,className:ce("relative flex h-full overflow-hidden border-l border-border/40","bg-sidebar",m?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-l-0",n),style:{width:"var(--oc-right-sidebar-width)",minWidth:"var(--oc-right-sidebar-width)",maxWidth:"var(--oc-right-sidebar-width)","--oc-right-sidebar-width":`${m?f.current??b:b}px`,overflowX:"clip"},"aria-hidden":!t||b===0,children:[t?s.jsx("div",{onMouseDown:N,className:ce("app-region-drag absolute inset-x-0 top-0 z-20 flex items-center justify-end px-3","h-[var(--oc-header-height,56px)]"),style:D,"aria-hidden":!0,children:s.jsx("div",{ref:r,className:"app-region-no-drag flex items-center gap-1"})}):null,t&&s.jsx("div",{className:ce("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",m&&"bg-[var(--interactive-border)]"),onPointerDown:k,onPointerMove:I,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:ce("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",m&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:t?{paddingTop:"var(--oc-header-height, 56px)"}:void 0,"aria-hidden":!t,children:t?e:null})]})},n1=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),r1=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=n1.format(t);return e.endsWith(".0")?e.slice(0,-2):e},yo=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:i,placeholder:a})=>{const{t:l}=ut(),{isReady:c,isUnavailable:d}=Gf(),p=xt(F=>F.providers),m=xt(F=>F.modelsMetadata),u=Ie(F=>F.isMobile),h=Ie(F=>F.hiddenModels),x=Ie(F=>F.toggleFavoriteModel),f=Ie(F=>F.isFavoriteModel),v=Ie(F=>F.addRecentModel),{favoriteModelsList:y,recentModelsList:g}=qf(),{isMobile:w}=rn(),b=u||w,[k,I]=o.useState(!1),[j,N]=o.useState(new Set),[D,E]=o.useState(!1),[T,C]=o.useState(""),[S,M]=o.useState(0),A=o.useRef([]),R=o.useMemo(()=>!Array.isArray(i)||i.length===0?null:new Set(i),[i]),z=o.useMemo(()=>(R?p.filter(U=>R.has(String(U.id))):p).map(U=>{const te=(Array.isArray(U.models)?U.models:[]).filter(K=>{const ae=typeof K?.id=="string"?K.id:"";return!h.some(ve=>ve.providerID===String(U.id)&&ve.modelID===ae)});return{...U,models:te}}).filter(U=>U.models.length>0),[p,R,h]),B=()=>I(!1),V=F=>{N(U=>{const W=new Set(U);return W.has(F)?W.delete(F):W.add(F),W})};o.useEffect(()=>{D||(C(""),M(0))},[D]),o.useEffect(()=>{M(0)},[T]);const $=F=>{const U=F?.name||F?.id||"",W=String(U);return W.length>40?W.substring(0,37)+"...":W},_=(F,U)=>{const W=`${F}/${U}`;return m.get(W)},X=(F,U)=>{n(F,U),F&&U&&v(F,U),E(!1)},O=(F,U)=>{if(!T.trim())return!0;const W=T.toLowerCase();return F.toLowerCase().includes(W)||U.toLowerCase().includes(W)},J=(F,U,W,te,K,ae)=>{const ve=_(U,W),re=r1(ve?.limit?.context),be=t===U&&e===W,pe=f(U,W),ye=te==="fav"||te==="recent";return s.jsxs($t,{ref:ie=>{A.current[K]=ie},className:ce("group flex items-center gap-2",ae&&"bg-interactive-selection"),onSelect:()=>X(U,W),onMouseEnter:()=>M(K),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[ye&&s.jsx(vn,{providerId:U,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)}),re?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:re}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[be&&s.jsx(P,{name:"check",className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:ie=>{ie.preventDefault(),ie.stopPropagation(),x(U,W)},className:ce("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",pe?"text-primary":"text-muted-foreground"),"aria-label":l(pe?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:l(pe?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:pe?s.jsx(P,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(P,{name:"star",className:"h-3.5 w-3.5"})})]})]},`${te}-${U}-${W}`)},Q=y.filter(({model:F,providerID:U})=>{if(R&&!R.has(U))return!1;const te=p.find(ae=>ae.id===U)?.name||U,K=$(F);return O(K,te)}),ne=g.filter(({model:F,providerID:U})=>{if(R&&!R.has(U))return!1;const te=p.find(ae=>ae.id===U)?.name||U,K=$(F);return O(K,te)}),G=z.map(F=>{const W=(Array.isArray(F.models)?F.models:[]).filter(te=>{const K=$(te);return O(K,F.name||F.id||"")});return{...F,models:W}}).filter(F=>F.models.length>0),le=Q.length>0||ne.length>0||G.length>0,oe=()=>b?s.jsx($r,{open:k,onClose:B,title:l("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[y.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:l("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:y.map(({model:F,providerID:U,modelID:W})=>{const te=U===t&&W===e;return s.jsxs("div",{className:ce("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",te?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{X(U,W),B()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vn,{providerId:U,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)})]})}),s.jsx("button",{onClick:K=>{K.preventDefault(),K.stopPropagation(),x(U,W)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-primary hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":l("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(P,{name:"star-fill",className:"h-4 w-4"})})]},`fav-mobile-${U}-${W}`)})})]}),g.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:l("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:g.map(({model:F,providerID:U,modelID:W})=>{const te=U===t&&W===e;return s.jsxs("div",{className:ce("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",te?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{X(U,W),B()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vn,{providerId:U,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:$(F)})]})}),s.jsx("button",{onClick:K=>{K.preventDefault(),K.stopPropagation(),x(U,W)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-muted-foreground/50 hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":l("settings.agents.modelSelector.actions.favorite"),children:s.jsx(P,{name:"star",className:"h-4 w-4"})})]},`recent-mobile-${U}-${W}`)})})]}),z.map(F=>{const U=Array.isArray(F.models)?F.models:[];if(U.length===0)return null;const W=F.id===t,te=j.has(F.id);return s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)]",children:[s.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-1.5 px-2 py-1.5 text-left",onClick:()=>V(F.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(vn,{providerId:F.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:F.name}),W&&s.jsx("span",{className:"typography-micro text-primary/80",children:l("settings.agents.modelSelector.badge.current")})]}),te?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3 text-muted-foreground"})]}),te&&s.jsx("div",{className:"border-t border-border/20",children:U.map(K=>{const ae=F.id===t&&K.id===e;return s.jsxs("div",{className:ce("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",ae?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{X(F.id,K.id),B()},children:s.jsx("span",{className:"font-medium truncate",children:$(K)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:ve=>{ve.preventDefault(),ve.stopPropagation(),x(F.id,K.id)},className:ce("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",f(F.id,K.id)?"text-primary":"text-muted-foreground/50"),"aria-label":f(F.id,K.id)?l("settings.agents.modelSelector.actions.unfavorite"):l("settings.agents.modelSelector.actions.favorite"),children:f(F.id,K.id)?s.jsx(P,{name:"star-fill",className:"h-4 w-4"}):s.jsx(P,{name:"star",className:"h-4 w-4"})}),ae&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},K.id)})})]},F.id)}),s.jsx("button",{type:"button",className:"flex w-full items-center justify-between rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",onClick:()=>{X("",""),B()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:a||l("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[b?s.jsxs("button",{type:"button",onClick:c?()=>I(!0):void 0,disabled:!c,className:ce("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",r),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[c?t?s.jsx(vn,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(P,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),c&&s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t&&e?`${t}/${e}`:a||l("settings.agents.modelSelector.selectPlaceholder")})]}),s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(Fs,{open:c&&D,onOpenChange:c?E:void 0,children:[s.jsx(Es,{asChild:!0,children:s.jsxs("div",{className:ce("border-input data-[placeholder]:text-muted-foreground flex items-center justify-between gap-2 rounded-lg border bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover data-[popup-open]:bg-interactive-active h-6 w-fit",r),children:[c?s.jsxs(s.Fragment,{children:[t?s.jsxs(s.Fragment,{children:[s.jsx(vn,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(P,{name:"pencil-ai",className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(P,{name:"pencil-ai",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-foreground",children:t&&e?`${t}/${e}`:a||l("settings.agents.modelSelector.notSelected")})]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal whitespace-nowrap text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),s.jsx(P,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx(Rs,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const F=[];Q.forEach(({model:K,providerID:ae,modelID:ve})=>{F.push({model:K,providerID:ae,modelID:ve,section:"fav"})}),ne.forEach(({model:K,providerID:ae,modelID:ve})=>{F.push({model:K,providerID:ae,modelID:ve,section:"recent"})}),G.forEach(K=>{K.models.forEach(ae=>{F.push({model:ae,providerID:K.id,modelID:ae.id,section:"provider"})})});const U=F.length,W=K=>{if(K.stopPropagation(),K.key==="ArrowDown"){K.preventDefault();const ae=(S+1)%Math.max(1,U);M(ae),setTimeout(()=>{A.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(K.key==="ArrowUp"){K.preventDefault();const ae=(S-1+Math.max(1,U))%Math.max(1,U);M(ae),setTimeout(()=>{A.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(K.key==="Enter"){K.preventDefault();const ae=F[S];ae&&X(ae.providerID,ae.modelID)}else K.key==="Escape"&&(K.preventDefault(),E(!1))};let te=0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(P,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{type:"text",placeholder:l("settings.agents.modelSelector.searchPlaceholder"),value:T,onChange:K=>C(K.target.value),onKeyDown:W,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(Cs,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs($t,{className:ce("flex items-center gap-2"),onSelect:()=>X("",""),children:[s.jsx(P,{name:"close",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-muted-foreground",children:a||l("settings.agents.modelSelector.notSelected")}),!t&&!e&&s.jsx(P,{name:"check",className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(Cn,{}),!le&&T&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("settings.agents.modelSelector.state.noModelsFound")}),Q.length>0&&s.jsxs("div",{children:[s.jsxs(Ka,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(P,{name:"star-fill",className:"h-4 w-4 text-primary"}),l("settings.agents.modelSelector.section.favorites")]}),Q.map(({model:K,providerID:ae,modelID:ve})=>{const re=te++;return J(K,ae,ve,"fav",re,S===re)})]}),ne.length>0&&s.jsxs("div",{children:[Q.length>0&&s.jsx(Cn,{}),s.jsxs(Ka,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(P,{name:"time",className:"h-4 w-4"}),l("settings.agents.modelSelector.section.recent")]}),ne.map(({model:K,providerID:ae,modelID:ve})=>{const re=te++;return J(K,ae,ve,"recent",re,S===re)})]}),(Q.length>0||ne.length>0)&&G.length>0&&s.jsx(Cn,{}),G.map((K,ae)=>s.jsxs("div",{children:[ae>0&&s.jsx(Cn,{}),s.jsxs(Ka,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(vn,{providerId:K.id,className:"h-4 w-4 flex-shrink-0"}),K.name]}),K.models.map(ve=>{const re=te++;return J(ve,K.id,ve.id,"provider",re,S===re)})]},K.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:l("settings.agents.modelSelector.keyboardHints")})]})})()})]}),oe()]})},Ul=t=>{const e=at.c(34),{agentName:n,onChange:r,className:i,filter:a}=t,{t:l}=ut(),{isReady:c,isUnavailable:d}=Gf(),p=xt(i1),m=fa(a1),u=fa(o1),h=xt(l1);let x;e:{if(Array.isArray(p)&&p.length>0){x=p;break e}let B;e[0]!==m?(B=Array.isArray(m)?m:[],e[0]=m,e[1]=B):B=e[1],x=B}const f=x;let v;if(e[2]!==a||e[3]!==f){const B=tb(f);v=a?B.filter(a):B,e[2]=a,e[3]=f,e[4]=v}else v=e[4];const y=v,g=Ie(c1),{isMobile:w}=rn(),b=g||w,[k,I]=o.useState(!1);let j,N;e[5]!==u||e[6]!==h||e[7]!==f.length?(j=()=>{f.length>0||(h(),u())},N=[f.length,h,u],e[5]=u,e[6]=h,e[7]=f.length,e[8]=j,e[9]=N):(j=e[8],N=e[9]),o.useEffect(j,N);let D;e[10]===Symbol.for("react.memo_cache_sentinel")?(D=()=>I(!1),e[10]=D):D=e[10];const E=D;let T;e[11]!==r?(T=B=>{r(B)},e[11]=r,e[12]=T):T=e[12];const C=T;let S;e[13]!==n||e[14]!==y||e[15]!==C||e[16]!==b||e[17]!==k||e[18]!==l?(S=()=>b?s.jsx($r,{open:k,onClose:E,title:l("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:ce("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",n?"text-foreground":"bg-primary/10 text-primary"),onClick:()=>{C(""),E()},children:[s.jsx("span",{className:ce("typography-meta",n?"text-muted-foreground":"font-medium"),children:l("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),y.map(B=>{const V=B.name===n;return s.jsxs("button",{type:"button",className:ce("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",V?"bg-primary/10 text-primary":"text-foreground"),onClick:()=>{C(B.name),E()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:B.name}),B.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:B.description})]}),V&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},B.name)})]})}):null,e[13]=n,e[14]=y,e[15]=C,e[16]=b,e[17]=k,e[18]=l,e[19]=S):S=e[19];const M=S;let A;e[20]!==n||e[21]!==y||e[22]!==i||e[23]!==C||e[24]!==b||e[25]!==c||e[26]!==d||e[27]!==l?(A=b?s.jsxs("button",{type:"button",onClick:c?()=>I(!0):void 0,disabled:!c,className:ce("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",i),children:[s.jsx("div",{className:"flex items-center gap-2",children:c?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"robot-2",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||l("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]})}),s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsxs("div",{className:ce("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit",i),children:[s.jsx(P,{name:"robot-2",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||l("settings.commands.agentSelector.notSelected")}),s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Rs,{className:"max-w-[300px]",children:[s.jsx($t,{className:"typography-meta",onSelect:()=>C(""),children:s.jsx("span",{className:"text-muted-foreground",children:l("settings.commands.agentSelector.notSelected")})}),y.map(B=>s.jsx($t,{className:"typography-meta",onSelect:()=>C(B.name),children:s.jsx("span",{className:"font-medium",children:B.name})},B.name))]})]}):s.jsxs("div",{className:ce("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60",i),children:[s.jsx(P,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=y,e[22]=i,e[23]=C,e[24]=b,e[25]=c,e[26]=d,e[27]=l,e[28]=A):A=e[28];let R;e[29]!==M?(R=M(),e[29]=M,e[30]=R):R=e[30];let z;return e[31]!==A||e[32]!==R?(z=s.jsxs(s.Fragment,{children:[A,R]}),e[31]=A,e[32]=R,e[33]=z):z=e[33],z};function i1(t){return t.agents}function a1(t){return t.agents}function o1(t){return t.loadAgents}function l1(t){return t.loadAgents}function c1(t){return t.isMobile}const fm=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),d1=t=>{const e=at.c(38),{value:n,options:r,disabled:i,onChange:a}=t,{t:l}=ut();let c;e[0]!==l||e[1]!==n?(c=n||l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=l,e[1]=n,e[2]=c):c=e[2];const d=c,p=i?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==p?(m=ce("flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2",p),e[3]=p,e[4]=m):m=e[4];let u;e[5]!==d?(u=s.jsx("span",{className:"typography-micro whitespace-nowrap font-medium capitalize",children:d}),e[5]=d,e[6]=u):u=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=h):h=e[7];let x;e[8]!==m||e[9]!==u?(x=s.jsxs("div",{className:m,children:[u,h]}),e[8]=m,e[9]=u,e[10]=x):x=e[10];const f=x;if(i)return f;let v;e[11]!==f?(v=s.jsx(Es,{asChild:!0,children:f}),e[11]=f,e[12]=v):v=e[12];let y;e[13]!==a?(y=()=>a(""),e[13]=a,e[14]=y):y=e[14];const g=!n&&"text-primary";let w;e[15]!==g?(w=ce("font-medium",g),e[15]=g,e[16]=w):w=e[16];let b;e[17]!==l?(b=l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=l,e[18]=b):b=e[18];let k;e[19]!==w||e[20]!==b?(k=s.jsx("span",{className:w,children:b}),e[19]=w,e[20]=b,e[21]=k):k=e[21];let I;e[22]!==k||e[23]!==y?(I=s.jsx($t,{className:"typography-meta",onSelect:y,children:k}),e[22]=k,e[23]=y,e[24]=I):I=e[24];let j;if(e[25]!==a||e[26]!==r||e[27]!==n){let E;e[29]!==a||e[30]!==n?(E=T=>s.jsx($t,{className:"typography-meta",onSelect:()=>a(T),children:s.jsx("span",{className:ce("font-medium capitalize",n===T&&"text-primary"),children:T})},T),e[29]=a,e[30]=n,e[31]=E):E=e[31],j=r.map(E),e[25]=a,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let N;e[32]!==I||e[33]!==j?(N=s.jsxs(Rs,{align:"start",className:"max-w-[220px]",children:[I,j]}),e[32]=I,e[33]=j,e[34]=N):N=e[34];let D;return e[35]!==N||e[36]!==v?(D=s.jsxs(Fs,{children:[v,N]}),e[35]=N,e[36]=v,e[37]=D):D=e[37],D};function Mh(t){const e=at.c(99),{t:n}=ut(),{open:r,onOpenChange:i,target:a,projectDirectory:l,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=xt(v1),u=xt(y1),h=fa(b1),x=xt(x1),f=xt(g1),v=xt(h1),y=xt(f1),g=xt(p1);let w;e[0]!==g||e[1]!==v||e[2]!==f||e[3]!==y?(w=()=>fm({providerID:f,modelID:v,variant:y,agent:g}),e[0]=g,e[1]=v,e[2]=f,e[3]=y,e[4]=w):w=e[4];const[b,k]=o.useState(w);let I,j;e[5]!==h||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==l?(I=()=>{r&&(m({directory:l}),u({directory:l}),h())},j=[r,m,u,h,l],e[5]=h,e[6]=u,e[7]=m,e[8]=r,e[9]=l,e[10]=I,e[11]=j):(I=e[10],j=e[11]),o.useEffect(I,j);let N,D;e[12]!==g||e[13]!==v||e[14]!==f||e[15]!==y||e[16]!==r?(N=()=>{r&&k(fm({providerID:f,modelID:v,variant:y,agent:g}))},D=[r,f,v,y,g],e[12]=g,e[13]=v,e[14]=f,e[15]=y,e[16]=r,e[17]=N,e[18]=D):(N=e[17],D=e[18]),o.useEffect(N,D);let E,T;e[19]!==b.modelID||e[20]!==b.providerID||e[21]!==r||e[22]!==x?(E=()=>{if(!r||x.length===0)return;const we=x.find(Me=>Me.id===b.providerID)??x[0],ke=Array.isArray(we?.models)?we.models:[],xe=ke.some(Me=>Me.id===b.modelID),me=ke[0]?.id??"";we?.id===b.providerID&&xe||k(Me=>({...Me,providerID:we?.id??"",modelID:xe?Me.modelID:me,variant:""}))},T=[r,x,b.providerID,b.modelID],e[19]=b.modelID,e[20]=b.providerID,e[21]=r,e[22]=x,e[23]=E,e[24]=T):(E=e[23],T=e[24]),o.useEffect(E,T);const C=m1;let S;if(e[25]!==b.modelID||e[26]!==b.providerID||e[27]!==x){let we;e[29]!==b.providerID?(we=xe=>xe.id===b.providerID,e[29]=b.providerID,e[30]=we):we=e[30],S=x.find(we)?.models?.find(xe=>xe.id===b.modelID),e[25]=b.modelID,e[26]=b.providerID,e[27]=x,e[28]=S}else S=e[28];const M=S;let A;e[31]!==M?(A=M?.variants?Object.keys(M.variants):[],e[31]=M,e[32]=A):A=e[32];const R=A,z=R.length>0;let B,V;e[33]!==b.variant||e[34]!==z?(B=()=>{z||!b.variant||k(u1)},V=[z,b.variant],e[33]=b.variant,e[34]=z,e[35]=B,e[36]=V):(B=e[35],V=e[36]),o.useEffect(B,V);let $;e[37]!==b.modelID||e[38]!==b.providerID?($=b.providerID.trim().length>0&&b.modelID.trim().length>0,e[37]=b.modelID,e[38]=b.providerID,e[39]=$):$=e[39];const _=$;let X;e[40]!==_||e[41]!==b||e[42]!==d||e[43]!==p?(X=()=>{!_||p||d(b)},e[40]=_,e[41]=b,e[42]=d,e[43]=p,e[44]=X):X=e[44];const O=X;let J,Q;e[45]!==O||e[46]!==r?(J=()=>{if(!r)return;const we=ke=>{(ke.metaKey||ke.ctrlKey)&&ke.key==="Enter"&&(ke.preventDefault(),O())};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},Q=[r,O],e[45]=O,e[46]=r,e[47]=J,e[48]=Q):(J=e[47],Q=e[48]),o.useEffect(J,Q);let ne;e[49]!==n||e[50]!==a?(ne=n(a==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=a,e[51]=ne):ne=e[51];const G=ne;let le;e[52]!==i||e[53]!==p?(le=we=>{p||i(we)},e[52]=i,e[53]=p,e[54]=le):le=e[54];let oe;e[55]!==G?(oe=s.jsx(bs,{children:s.jsx(gs,{children:G})}),e[55]=G,e[56]=oe):oe=e[56];let F;e[57]===Symbol.for("react.memo_cache_sentinel")?(F=(we,ke)=>{k(xe=>({...xe,providerID:we,modelID:ke,variant:""}))},e[57]=F):F=e[57];let U;e[58]!==b.modelID||e[59]!==b.providerID?(U=s.jsx(yo,{providerId:b.providerID,modelId:b.modelID,onChange:F}),e[58]=b.modelID,e[59]=b.providerID,e[60]=U):U=e[60];const W=!z;let te;e[61]===Symbol.for("react.memo_cache_sentinel")?(te=we=>k(ke=>({...ke,variant:we})),e[61]=te):te=e[61];let K;e[62]!==b.variant||e[63]!==W||e[64]!==R?(K=s.jsx(d1,{value:b.variant,options:R,disabled:W,onChange:te}),e[62]=b.variant,e[63]=W,e[64]=R,e[65]=K):K=e[65];let ae;e[66]===Symbol.for("react.memo_cache_sentinel")?(ae=we=>k(ke=>({...ke,agent:we})),e[66]=ae):ae=e[66];let ve;e[67]!==b.agent?(ve=s.jsx(Ul,{agentName:b.agent,filter:C,onChange:ae}),e[67]=b.agent,e[68]=ve):ve=e[68];let re;e[69]!==U||e[70]!==K||e[71]!==ve?(re=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[U,K,ve]}),e[69]=U,e[70]=K,e[71]=ve,e[72]=re):re=e[72];let be;e[73]!==i?(be=()=>i(!1),e[73]=i,e[74]=be):be=e[74];let pe;e[75]!==n?(pe=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=pe):pe=e[76];let ye;e[77]!==p||e[78]!==be||e[79]!==pe?(ye=s.jsx(ge,{variant:"ghost",size:"sm",onClick:be,disabled:p,children:pe}),e[77]=p,e[78]=be,e[79]=pe,e[80]=ye):ye=e[80];const ie=!_||p;let ue;e[81]!==p||e[82]!==n?(ue=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=ue):ue=e[83];let se;e[84]!==O||e[85]!==ie||e[86]!==ue?(se=s.jsx(ge,{size:"sm",onClick:O,disabled:ie,children:ue}),e[84]=O,e[85]=ie,e[86]=ue,e[87]=se):se=e[87];let Ne;e[88]!==ye||e[89]!==se?(Ne=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ye,se]}),e[88]=ye,e[89]=se,e[90]=Ne):Ne=e[90];let Ce;e[91]!==oe||e[92]!==re||e[93]!==Ne?(Ce=s.jsxs(fs,{className:"max-w-lg",children:[oe,re,Ne]}),e[91]=oe,e[92]=re,e[93]=Ne,e[94]=Ce):Ce=e[94];let je;return e[95]!==r||e[96]!==le||e[97]!==Ce?(je=s.jsx(hs,{open:r,onOpenChange:le,children:Ce}),e[95]=r,e[96]=le,e[97]=Ce,e[98]=je):je=e[98],je}function u1(t){return{...t,variant:""}}function m1(t){return Yf(t.mode)}function p1(t){return t.currentAgentName||""}function f1(t){return t.currentVariant||""}function h1(t){return t.currentModelId}function g1(t){return t.currentProviderId}function x1(t){return t.providers}function b1(t){return t.loadAgents}function y1(t){return t.loadAgents}function v1(t){return t.loadProviders}const id=5,Eh=15,el=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},w1=(t,e)=>{const n=el(e);return Math.max(n*id,Math.min(n*Eh,n*t))},j1=async(t,e)=>{const n=await ib(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},N1=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,S1=t=>{const e=at.c(20),{id:n,children:r}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:a,listeners:l,setNodeRef:c,setActivatorNodeRef:d,transform:p,transition:m,isDragging:u}=Dl(i);let h;e[2]!==p?(h=Tl.Transform.toString(p),e[2]=p,e[3]=h):h=e[3];let x;e[4]!==h||e[5]!==m?(x={transform:h,transition:m},e[4]=h,e[5]=m,e[6]=x):x=e[6];const f=u&&"opacity-60";let v;e[7]!==f?(v=ce(f),e[7]=f,e[8]=v):v=e[8];let y;e[9]!==a||e[10]!==r||e[11]!==u||e[12]!==l||e[13]!==d?(y=r({attributes:a,listeners:l,setActivatorNodeRef:d,isDragging:u}),e[9]=a,e[10]=r,e[11]=u,e[12]=l,e[13]=d,e[14]=y):y=e[14];let g;return e[15]!==c||e[16]!==x||e[17]!==v||e[18]!==y?(g=s.jsx("li",{ref:c,style:x,className:v,children:y}),e[15]=c,e[16]=x,e[17]=v,e[18]=y,e[19]=g):g=e[19],g},k1=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:i})=>{const{t:a}=ut(),[l,c]=o.useState(!1),[d,p]=o.useState(""),[m,u]=o.useState([]),[h,x]=o.useState(""),[f,v]=o.useState(null),[y,g]=o.useState(()=>new Set),[w,b]=o.useState([]),[k,I]=o.useState(null),[j,N]=o.useState(!1),[D,E]=o.useState(0),T=o.useRef(!1),C=o.useRef(""),S=Ie(L=>L.todoPanelHeight),M=Ie(L=>L.setTodoPanelHeight),A=Ie(L=>L.notesPanelHeight),R=Ie(L=>L.setNotesPanelHeight),[z,B]=o.useState(!1),V=o.useRef(0),$=o.useRef(S),_=Ot(L=>L.currentSessionId),X=Ot(L=>L.createSession),O=Ot(L=>L.initializeNewSession),J=Ot(L=>L.sendMessage),Q=Ot(L=>L.setCurrentSession),ne=zi(L=>L.setPendingInputText),G=$s(L=>L.currentDirectory),le=Ie(L=>L.openContextPanelTab),oe=Ie(L=>L.setActiveMainTab),F=Ie(L=>L.setSessionSwitcherOpen),U=Ie(L=>L.padding),W=o.useCallback(async(L,Z)=>{if(!t)return!1;const Y=await sb(t,{notes:L,todos:Z});return Y||H.error(a("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),Y},[t,a]);o.useEffect(()=>{if(!t){p(""),u([]),b([]),x(""),g(new Set);return}let L=!1;return c(!0),(async()=>{try{const Z=await nb(t),Y=await Promise.all(Z.plans.map(Ee=>j1(Ee,a("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(L)return;p(Z.notes),u(Z.todos),b(Y),C.current=Z.notes,T.current=!0,x(""),g(new Set)}catch{L||(H.error(a("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),b([]),C.current="",T.current=!0)}finally{L||c(!1)}})(),()=>{L=!0}},[D,t,a]),o.useEffect(()=>{if(!t)return;const L=Z=>{const Y=Z.detail;Y?.projectId&&Y.projectId!==t.id||E(Ee=>Ee+1)};return window.addEventListener("vinci:project-plan-saved",L),window.addEventListener("vinci:project-notes-updated",L),()=>{window.removeEventListener("vinci:project-plan-saved",L),window.removeEventListener("vinci:project-notes-updated",L)}},[t]),o.useEffect(()=>{if(m.length<7)return;const L=w1(m.length,U),Z=el(U)*id;(S<Z||S>L)&&M(L)},[m.length,U,S,M]),o.useEffect(()=>{if(!z)return;const L=Y=>{const Ee=Y.clientY-V.current,Ae=Math.min(el(U)*Eh,Math.max(el(U)*id,$.current+Ee));M(Ae)},Z=()=>{B(!1)};return window.addEventListener("pointermove",L),window.addEventListener("pointerup",Z,{once:!0}),window.addEventListener("pointercancel",Z,{once:!0}),()=>{window.removeEventListener("pointermove",L),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z)}},[z,U,M]);const te=o.useCallback(L=>{B(!0),V.current=L.clientY,$.current=S,L.preventDefault()},[S]),K=o.useCallback(()=>{C.current=d,W(d,m)},[d,W,m]);o.useEffect(()=>{if(!t||!T.current||d===C.current)return;const L=window.setTimeout(()=>{C.current=d,W(d,m)},400);return()=>{window.clearTimeout(L)}},[d,W,t,m]);const ae=o.useCallback(()=>{const L=h.trim();if(!L)return;const Z=[...m,{id:N1(),text:L.slice(0,Co),completed:!1,createdAt:Date.now()}];u(Z),x(""),W(d,Z)},[h,d,W,m]),ve=o.useCallback(L=>{g(Z=>{const Y=new Set(Z);return Y.has(L)?Y.delete(L):Y.add(L),Y})},[]),re=o.useCallback((L,Z)=>{const Y=m.map(Ee=>Ee.id===L?{...Ee,completed:Z}:Ee);u(Y),W(d,Y)},[d,W,m]),be=o.useCallback(L=>{const Z=m.filter(Y=>Y.id!==L);u(Z),W(d,Z)},[d,W,m]),pe=o.useCallback(()=>{const L=m.filter(Z=>!Z.completed);L.length!==m.length&&(u(L),W(d,L))},[d,W,m]),ye=o.useCallback(L=>{const{active:Z,over:Y}=L;if(!Y||Z.id===Y.id)return;const Ee=m.findIndex(de=>de.id===Z.id),Ae=m.findIndex(de=>de.id===Y.id);if(Ee===-1||Ae===-1)return;const Je=Ef(m,Ee,Ae);u(Je),W(d,Je)},[d,W,m]),ie=Ja(oa(Xa,{activationConstraint:{distance:8}})),ue=h.slice(0,Co),se=m.reduce((L,Z)=>L+(Z.completed?1:0),0),Ne=o.useCallback(()=>{oe("chat"),F(!1)},[oe,F]),Ce=o.useCallback((L,Z)=>{!t||f||I({kind:"session",todoId:L,todoText:Z})},[t,f]),je=o.useCallback(L=>{if(!_){H.error(a("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Ne();const Z=`\`\`\`md
|
|
4
4
|
${L}
|
|
5
5
|
\`\`\``;ne(Z,"append"),H.success(a("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[_,r,Ne,ne,a]),we=o.useCallback((L,Z)=>{if(!(!t||f)){if(!n){H.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}I({kind:"worktree",todoId:L,todoText:Z})}},[n,t,f,a]),ke=o.useCallback(async L=>{if(!t||!k)return;const Z=await wn("plan.todo.visible",{todo_text:k.todoText}),Ee=[{synthetic:!0,text:await wn("plan.todo.instructions",{todo_text:k.todoText})}];N(!0),v(k.todoId);try{Ne();let Ae=null,Je=t.path;if(k.kind==="worktree"){if(!n){H.error(a("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const ze=await Qf(t.path,Jf());if(!ze?.id)return;Ae=ze.id,Je=null}else{const ze=await X(void 0,t.path,null);if(!ze?.id){H.error(a("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Ae=ze.id,Je=ze.directory??t.path,O(ze.id,xt.getState().agents??[])}if(!Ae)return;const de=Fl.getState();de.saveSessionModelSelection(Ae,L.providerID,L.modelID),L.agent.trim()&&(de.saveSessionAgentSelection(Ae,L.agent),de.saveAgentModelForSession(Ae,L.agent,L.providerID,L.modelID),de.saveAgentModelVariantForSession(Ae,L.agent,L.providerID,L.modelID,L.variant||void 0)),Q(Ae,Je),await J(Z,L.providerID,L.modelID,L.agent.trim()||void 0,void 0,void 0,Ee,L.variant||void 0),H.success(k.kind==="worktree"?a("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):a("rightSidebar.contextNotesTodo.toast.sentToNewSession")),I(null),r?.()}catch(Ae){const Je=Ae instanceof Error?Ae.message:void 0;H.error(a("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Je?{description:Je}:void 0)}finally{N(!1),v(null)}},[n,X,O,r,k,t,Ne,J,Q,a]),xe=o.useRef(null),[me,Me]=o.useState(!1),[Ue,q]=o.useState(null),Se=o.useCallback(async L=>{if(!(!t||Ue)){q(L);try{if(!await rb(t,L)){H.error(a("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}b(Y=>Y.filter(Ee=>Ee.id!==L)),window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}}))}finally{q(null)}}},[Ue,t,a]),$e=o.useCallback(async()=>{if(!t||me)return;const L=await Xf({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(L.success&&L.path){Me(!0);try{const Z=new URLSearchParams({path:L.path,allowOutsideWorkspace:"true"}),Y=await fetch(`/api/fs/read?${Z.toString()}`,{cache:"no-store"});if(!Y.ok){H.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Ee=await Y.text();if(!Ee.trim()){H.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Ae=L.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await ju(t,Ee,Ae)){H.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}})),H.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(Z){const Y=Z instanceof Error?Z.message:void 0;H.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Y?{description:Y}:void 0)}finally{Me(!1)}}else L.error==="Native file picker not available"&&xe.current?.click()},[me,t,a]),Pe=o.useCallback(async L=>{if(!(!t||!L)){Me(!0);try{const Z=await L.text();if(!Z.trim()){H.error(a("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Y=L.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await ju(t,Z,Y)){H.error(a("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("vinci:project-plan-saved",{detail:{projectId:t.id}})),H.success(a("rightSidebar.contextNotesTodo.toast.planImported"))}catch(Z){const Y=Z instanceof Error?Z.message:void 0;H.error(a("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),Y?{description:Y}:void 0)}finally{Me(!1)}}},[t,a]),fe=o.useCallback(L=>{const Z=t?.path?.trim(),Y=G?.trim()||Z;Y&&le(Y,{mode:"plan",targetPath:L.path,dedupeKey:L.path,label:L.title})},[G,le,t]);return t?s.jsxs("div",{className:ce("w-full min-w-0 space-y-3 p-3",i),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:a("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d.length,"/",Nu]})]}),s.jsx(hn,{value:d,onChange:L=>p(L.target.value.slice(0,Nu)),onBlur:K,placeholder:a("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:A,onResizeHeightChange:R,useScrollShadow:!0,scrollShadowSize:56,disabled:l})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:a("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?a("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):a("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:pe,disabled:l||se===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:a("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[ue.length,"/",Co]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{value:ue,onChange:L=>x(L.target.value.slice(0,Co)),onKeyDown:L=>{L.key==="Enter"&&(L.preventDefault(),ae())},placeholder:a("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:l,className:"h-8"}),s.jsx("button",{type:"button",onClick:ae,disabled:l||ue.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":a("rightSidebar.contextNotesTodo.todo.addAria"),title:a("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(P,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:ce("overflow-y-auto rounded-lg border border-border/60 bg-background/40",z&&"transition-none"),style:m.length<7?void 0:{height:`${S}px`,maxHeight:`${S}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(Za,{sensors:ie,collisionDetection:eo,onDragEnd:ye,children:s.jsx(cl,{items:m.map(L=>L.id),strategy:Hc,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(L=>{const Z=y.has(L.id);return s.jsx(S1,{id:L.id,children:Y=>s.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("button",{type:"button",ref:Y.setActivatorNodeRef,...Y.attributes,...Y.listeners,onClick:Ee=>{Ee.preventDefault(),Ee.stopPropagation()},className:"flex h-6 w-4 flex-shrink-0 touch-none items-center justify-center text-muted-foreground hover:text-foreground","aria-label":a("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:L.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:L.text}),children:s.jsx(P,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(ds,{checked:L.completed,onChange:Ee=>re(L.id,Ee),ariaLabel:a("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:L.text})})}),s.jsx("button",{type:"button",onClick:()=>ve(L.id),className:ce("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",Z?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",L.completed&&"text-muted-foreground line-through"),title:Z?void 0:L.text,"aria-label":Z?a("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:L.text}):a("rightSidebar.contextNotesTodo.todo.actions.expand",{text:L.text}),children:L.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>be(L.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:L.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.delete",{text:L.text}),children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(Fs,{children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",disabled:f===L.id,className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":a("rightSidebar.contextNotesTodo.todo.actions.send",{text:L.text}),title:a("rightSidebar.contextNotesTodo.todo.actions.send",{text:L.text}),children:s.jsx(P,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(Rs,{align:"end",className:"w-56",children:[s.jsx($t,{onClick:()=>je(L.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx($t,{onClick:()=>Ce(L.id,L.text),children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx($t,{onClick:()=>{we(L.id,L.text)},disabled:!n,children:a("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},L.id)})})})})}),m.length>=7&&s.jsx("div",{className:ce("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",z&&"bg-[var(--interactive-border)]"),onPointerDown:te,role:"separator","aria-orientation":"horizontal","aria-label":a("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:a("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:w.length===1?a("rightSidebar.contextNotesTodo.plans.filesSingle",{count:w.length}):a("rightSidebar.contextNotesTodo.plans.filesPlural",{count:w.length})})]}),s.jsx("input",{ref:xe,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:L=>{const Z=L.target.files?.[0]??null;Pe(Z),L.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:$e,disabled:!t||me,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":a("rightSidebar.contextNotesTodo.plans.importFromFile"),title:a("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(P,{name:"add",className:"h-3.5 w-3.5"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:w.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:w.map(L=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>fe(L),className:"flex min-w-0 flex-1 items-center justify-between gap-3 rounded-md px-1.5 py-1 text-left hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-foreground",children:L.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(L.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Se(L.id)},disabled:Ue===L.id,className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",title:a("rightSidebar.contextNotesTodo.plans.deletePlan"),"aria-label":a("rightSidebar.contextNotesTodo.plans.deletePlanWithTitle",{title:L.title}),children:s.jsx(P,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},L.id))})})]}),s.jsx(Mh,{open:k!==null,onOpenChange:L=>{!L&&!j&&I(null)},target:k?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:ke})]}):s.jsx("div",{className:ce("w-full min-w-0 p-3",i),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("rightSidebar.contextNotesTodo.empty.selectProject")})})},Rh=12,C1=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],P1=t=>{const e=at.c(18),{isActive:n,burstKey:r,className:i,durationMs:a,bursts:l,onComplete:c}=t,d=r===void 0?0:r,p=a===void 0?900:a,m=l===void 0?C1:l,u=Be.useRef(!1);let h,x;e[0]!==n||e[1]!==c?(h=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},x=[n,c],e[0]=n,e[1]=c,e[2]=h,e[3]=x):(h=e[2],x=e[3]),Be.useEffect(h,x);let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=Array.from({length:Rh},I1),e[4]=f):f=e[4];const v=f;if(!n)return null;let y;e[5]!==i?(y=ce("fireworks-overlay pointer-events-none",i),e[5]=i,e[6]=y):y=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let b;e[11]!==d||e[12]!==p?(b=k=>{const I={"--burst-delay":`${k.delay}ms`,"--burst-x":`${k.x}%`,"--burst-y":`${k.y}%`,"--firework-color":`var(${k.colorVar})`,"--firework-duration":`${p}ms`};return s.jsx("div",{className:"firework-burst",style:I,children:v.map((j,N)=>{const D=j.x*k.radius,E=j.y*k.radius,T={"--translate-x":`${D}px`,"--translate-y":`${E}px`,"--particle-delay":`${j.delay}ms`,color:`var(${k.colorVar})`};return s.jsx("span",{className:"firework-particle",style:T},`${k.id}-${N}-${d}`)})},`${k.id}-${d}`)},e[11]=d,e[12]=p,e[13]=b):b=e[13],g=m.map(b),e[7]=d,e[8]=m,e[9]=p,e[10]=g}else g=e[10];let w;return e[14]!==d||e[15]!==y||e[16]!==g?(w=s.jsx("div",{className:y,"aria-hidden":"true","data-burst-key":d,children:g}),e[14]=d,e[15]=y,e[16]=g,e[17]=w):w=e[17],w};function I1(t,e){const n=Math.PI*2*e/Rh;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const A1=t=>{const e=at.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,i=r===void 0?3400:r;let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={isActive:!1,cycle:0},e[2]=a):a=e[2];const[l,c]=Be.useState(a),d=Be.useRef(null);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=p):p=e[3];const m=p;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(D1)},e[4]=u):u=e[4];const h=u;let x;e[5]!==i?(x=()=>{m(),c(T1),d.current=window.setTimeout(()=>{c(M1),d.current=null},i)},e[5]=i,e[6]=x):x=e[6];const f=x;let v,y;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),y=[m],e[7]=v,e[8]=y):(v=e[7],y=e[8]),Be.useEffect(v,y);let g;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==f?(g={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:f,dismissFireworks:h},e[9]=l.cycle,e[10]=l.isActive,e[11]=f,e[12]=g):g=e[12],g};function D1(t){return t.isActive?{...t,isActive:!1}:t}function T1(t){return{isActive:!0,cycle:t.cycle+1}}function M1(t){return t.isActive?{...t,isActive:!1}:t}const Fh=o.createContext(void 0),E1=t=>{const e=at.c(10),{children:n}=t,{isActive:r,burstKey:i,triggerFireworks:a,dismissFireworks:l}=A1();let c;e[0]!==l||e[1]!==a?(c={triggerFireworks:a,dismissFireworks:l},e[0]=l,e[1]=a,e[2]=c):c=e[2];const d=c;let p;e[3]!==i||e[4]!==r?(p=s.jsx(P1,{isActive:r,burstKey:i}),e[3]=i,e[4]=r,e[5]=p):p=e[5];let m;return e[6]!==n||e[7]!==p||e[8]!==d?(m=s.jsxs(Fh.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},R1=()=>{const t=o.useContext(Fh);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Qn=gr()(Na(mo((t,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{t({selectedProfileId:n})},loadProfiles:async()=>{t({isLoading:!0});const n=e().profiles;try{const r=await ub();return t({profiles:r,isLoading:!1}),!0}catch(r){return console.error("Failed to load git identity profiles:",r),t({profiles:n,isLoading:!1}),!1}},loadGlobalIdentity:async()=>{try{const n=await db();if(n&&n.userName&&n.userEmail){const r={id:"global",name:"Global Identity",userName:n.userName,userEmail:n.userEmail,authType:n.sshCommand?"ssh":void 0,sshKey:n.sshCommand?n.sshCommand.replace("ssh -i ",""):null,color:"info",icon:"house"};t({globalIdentity:r})}else t({globalIdentity:null});return!0}catch(n){return console.error("Failed to load global git identity:",n),t({globalIdentity:null}),!1}},loadDiscoveredCredentials:async()=>{try{const n=await cb();return t({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),t({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const i=r.trim();return i.length>0?i:null};try{let r=null;if(r===null){const i=pr()?.settings;if(i)try{const l=(await i.load())?.settings||{};r=n(l.defaultGitIdentityId)}catch{}}if(r===null)try{const i=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(i.ok){const a=await i.json().catch(()=>null);r=n(a?.defaultGitIdentityId)}}catch{}return t({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",i=r.length>0?r:"";return await ks({defaultGitIdentityId:i}),t({defaultGitIdentityId:i.length>0?i:null}),!0}catch(r){return console.error("Failed to save default git identity setting:",r),!1}},createProfile:async n=>{try{const r={...n,id:n.id||`profile-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,color:n.color||"keyword",icon:n.icon||"branch"};return await lb(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const i=e().profiles.find(l=>l.id===n);if(!i)throw new Error("Profile not found");const a={...i,...r};return await ob(n,a),await e().loadProfiles(),!0}catch(i){return console.error("Failed to update git identity profile:",i),!1}},deleteProfile:async n=>{try{return await ab(n),e().selectedProfileId===n&&t({selectedProfileId:null}),await e().loadProfiles(),!0}catch(r){return console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:i}=e();return n==="global"?i||void 0:r.find(a=>a.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=e();return r.filter(i=>!n.some(a=>a.authType==="token"&&a.host===i.host))}}),{name:"git-identities-store",storage:Ml(()=>pi()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Qn);function _i(t){const e=at.c(12);let n,r,i;e[0]!==t?({className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i):(n=e[1],r=e[2],i=e[3]);let a;e[4]!==i?(a={color:"var(--surface-elevated-foreground)",...i},e[4]=i,e[5]=a):a=e[5];let l;e[6]!==n?(l=ce("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=l):l=e[7];let c;return e[8]!==r||e[9]!==a||e[10]!==l?(c=s.jsx(Hi,{"data-slot":"command",style:a,className:l,...r}),e[8]=r,e[9]=a,e[10]=l,e[11]=c):c=e[11],c}const xi=Be.forwardRef((t,e)=>{const n=at.c(10);let r,i;n[0]!==t?({className:r,...i}=t,n[0]=t,n[1]=r,n[2]=i):(r=n[1],i=n[2]);let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(P,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=a):a=n[3];let l;n[4]!==r?(l=ce("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=l):l=n[5];let c;return n[6]!==i||n[7]!==e||n[8]!==l?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[a,s.jsx(Hi.Input,{ref:e,"data-slot":"command-input",className:l,...i})]}),n[6]=i,n[7]=e,n[8]=l,n[9]=c):c=n[9],c});xi.displayName="CommandInput";function Ui(t){const e=at.c(14);let n,r,i,a,l;e[0]!==t?({className:r,children:n,scrollbarClassName:l,disableHorizontal:i,...a}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a,e[5]=l):(n=e[1],r=e[2],i=e[3],a=e[4],l=e[5]);let c;e[6]!==r?(c=ce("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=l??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",p=i??!0;let m;return e[8]!==n||e[9]!==a||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(Cs,{as:Hi.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:c,scrollbarClassName:d,disableHorizontal:p,...a,children:n}),e[8]=n,e[9]=a,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function Wi(t){const e=at.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(Hi.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function zn(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Hi.Group,{"data-slot":"command-group",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function Ti(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("bg-border -mx-1 h-px",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Hi.Separator,{"data-slot":"command-separator",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function kn(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let i;e[3]!==n?(i=ce("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==i?(a=s.jsx(Hi.Item,{"data-slot":"command-item",className:i,...r}),e[5]=r,e[6]=i,e[7]=a):a=e[7],a}function F1(t){const e=at.c(12);let n,r,i,a;if(e[0]!==t){const{className:c,...d}=t,p=O1,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(L1).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=ce("text-muted-foreground ml-auto flex items-center gap-1 typography-meta",c),e[5]=c,e[6]=r):r=e[6],i=d,a=u.length>0?u.map((h,x)=>s.jsxs(Be.Fragment,{children:[x>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(h)]},`${h}-${x}`)):d.children,e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a}else n=e[1],r=e[2],i=e[3],a=e[4];let l;return e[7]!==n||e[8]!==r||e[9]!==i||e[10]!==a?(l=s.jsx("span",{"data-slot":n,className:r,...i,children:a}),e[7]=n,e[8]=r,e[9]=i,e[10]=a,e[11]=l):l=e[11],l}function L1(t){return t.trim()}function O1(t){const e=t.trim().toLowerCase();return e==="ctrl"||e==="control"?s.jsx("span",{className:"text-xs font-medium",children:"ctrl"}):e==="cmd"||e==="⌘"||e==="command"||e==="meta"?s.jsx(P,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(P,{name:"arrow-up",className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const ad=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},$1=t=>{const e=ad(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function B1(t,e,n){const r=at.c(5),[i,a]=o.useState();let l,c;return r[0]!==n||r[1]!==t||r[2]!==e?(l=()=>{if(e){a(void 0);return}if(!t){a(void 0);return}a(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([zs("git rev-parse --absolute-git-dir",t),zs("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=ad((p.stdout||"").trim()),h=$1(u);if(!h)return;const x=ad((m.stdout||"").trim());if(!x||x===h)return;const f=n||"",v=x.split("/").filter(Boolean).pop()||x;a({source:"sdk",path:x,projectDirectory:h,branch:f,label:f||v,name:v,worktreeRoot:x,worktreeStatus:"ready",headState:f?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=l,r[4]=c):(l=r[3],c=r[4]),o.useEffect(l,c),e??i}const Jn=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},va=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),ti=t=>!!t.success,Wl=t=>(t.stdout||"").trim(),Oi=t=>(t.stderr||"").trim();async function z1(t){const n=((await zs("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let i=null;for(const a of n){if(a.startsWith("worktree ")){i&&r.push(i),i={path:a.slice(9).trim(),branchRef:null};continue}i&&a.startsWith("branch ")&&(i.branchRef=a.slice(7).trim())}return i&&r.push(i),r.filter(a=>!!a.path)}async function V1(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),i=(await z1(t.repoRoot)).filter(l=>l.branchRef===e).map(l=>l.path).filter(l=>l&&!n.has(l)),a=[];for(const l of i){const c=await zs("git status --porcelain",l);Wl(c)||a.push(l)}return a}async function Lh(t,e){for(const n of e)await zs("git reset --hard",n).catch(()=>{})}async function _1(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await zs(`git show-ref --verify --quiet ${Jn(`refs/heads/${n}`)}`,t);if(ti(r))return n;if(n.startsWith("remotes/")){const l=n.slice(8).split("/"),c=l[0]||"origin",d=l.slice(1).join("/");if(d)return await zs(`git branch --track ${Jn(d)} ${Jn(`${c}/${d}`)}`,t),d}const i=await zs(`git show-ref --verify --quiet ${Jn(`refs/remotes/origin/${n}`)}`,t);return ti(i)&&await zs(`git branch --track ${Jn(n)} ${Jn(`origin/${n}`)}`,t),n}async function Ma(t){const e=t.repoRoot,n=t.sourceBranch.trim(),r=t.targetBranch.trim();if(!n||!r)return{repoRoot:e,sourceBranch:n,targetBranch:r,commits:[]};const i=await _1(e,r),a=await zs(`git cherry ${Jn(i)} ${Jn(n)}`,e),l=va(a.stdout),c=new Set;for(const u of l){const h=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);h&&c.add(h[1])}const d=await zs(`git rev-list --reverse ${Jn(`${i}..${n}`)}`,e),m=va(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:i,commits:m}}async function U1(t,e){const n=await zs('mkdir -p "$HOME/.config/vinci/tmp"',t);if(!ti(n))throw new Error(Oi(n)||"Failed to create temp directory parent");const r=await zs('mktemp -d "$HOME/.config/vinci/tmp/vinci-integrate-XXXXXX"',t),i=Wl(r);if(!i)throw new Error(Oi(r)||"Failed to create temp directory");const a=await zs(`git worktree add --force ${Jn(i)} ${Jn(e)}`,t);if(!ti(a))throw new Error(Oi(a)||"Failed to create temp worktree");return i}async function yl(t,e){await zs(`git worktree remove --force ${Jn(e)}`,t).catch(()=>{}),await zs("git worktree prune",t).catch(()=>{})}async function W1(t){const e=await zs("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Wl(e);if(!n)return;await zs("git fetch",t);const r=await zs(`git merge --ff-only ${Jn(n)}`,t);if(!ti(r))throw new Error(Oi(r)||"Fast-forward failed")}async function vl(t){const e=await zs("git status --porcelain",t),n=await zs("git diff --name-only --diff-filter=U",t),r=await zs("git diff",t),i=await zs("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),a=await zs("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:va(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:i.stdout||i.stderr||"",currentPatch:a.stdout||a.stderr||""}}async function K1(t){return vl(t)}async function H1(t){const e=await zs("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return ti(e)}async function G1(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await U1(t.repoRoot,t.targetBranch);let n=[];try{await W1(e);const r=await zs("git status --porcelain",e);if(Wl(r))throw new Error("Target branch has local changes; abort integration and retry");const i=await V1({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const a=n[0],l=await zs(`git cherry-pick ${Jn(a)}`,e);if(ti(l)){n.shift();continue}const c=await zs("git diff --name-only --diff-filter=U",e);if(va(c.stdout).length>0){const p=await vl(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:i,remainingCommits:n,currentCommit:a},details:p}}throw new Error(Oi(l)||"Cherry-pick failed")}return await yl(t.repoRoot,e),await Lh(t.repoRoot,i).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await yl(t.repoRoot,e).catch(()=>{}),r}}async function q1(t){await zs("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await yl(t.repoRoot,t.tempWorktreePath)}async function Y1(t){const e=await zs("git cherry-pick --continue",t.tempWorktreePath);if(!ti(e)){const a=await zs("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(va(a.stdout).length>0){const c=await vl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Oi(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const i=[...r];for(;i.length>0;){const a=i[0],l=await zs(`git cherry-pick ${Jn(a)}`,n);if(ti(l)){i.shift();continue}const c=await zs("git diff --name-only --diff-filter=U",n);if(va(c.stdout).length>0){const p=await vl(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:i,currentCommit:a},details:p}}throw new Error(Oi(l)||"Cherry-pick failed")}return await yl(t.repoRoot,t.tempWorktreePath),await Lh(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Q1=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:i,refreshKey:a,onRefresh:l})=>{const{t:c}=ut(),d=Ot($=>$.currentSessionId),p=Ie($=>$.setActiveMainTab),[m,u]=Be.useState(!1),h=Be.useRef(null),[x,f]=Be.useState(i);Be.useEffect(()=>{f(i)},[i]),Be.useEffect(()=>{if(m){const $=setTimeout(()=>{h.current?.focus()},0);return()=>clearTimeout($)}},[m]);const v=!!(t&&e&&x&&x!=="HEAD"&&e!==x),[y,g]=Be.useState({kind:"idle"}),[w,b]=Be.useState(!1),[k,I]=Be.useState([]),j=Be.useMemo(()=>d?`vinci.integrate.conflict:${d}`:null,[d]);Be.useEffect(()=>{if(!j||typeof window>"u")return;const $=window.localStorage.getItem(j);if(!$)return;let _=!1;try{const X=JSON.parse($);if(!X?.tempWorktreePath||X.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const O=await H1(X.tempWorktreePath).catch(()=>!1);if(_)return;if(!O){window.localStorage.removeItem(j);return}const J=await K1(X.tempWorktreePath).catch(()=>null);_||J&&g({kind:"conflict",state:X,details:J})})()}catch{window.localStorage.removeItem(j)}return()=>{_=!0}},[j,t]),Be.useEffect(()=>{if(!v){g({kind:"idle"});return}let $=!1;return g({kind:"loading"}),(async()=>{try{const _=await Ma({repoRoot:t,sourceBranch:e,targetBranch:x});if($)return;if(g({kind:"ready",plan:_}),_.commits.length>0){const J=_.commits.slice(-50).reverse().map(le=>JSON.stringify(le)).join(" "),ne=((await zs(`git show -s --format=%H%x09%h%x09%s ${J}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),G=[];for(const le of ne){const[oe,F,U]=le.split(" ");!oe||!F||G.push({sha:oe,short:F,subject:U||""})}$||(I(G),b(!1))}else $||(I([]),b(!1))}catch{$||g({kind:"idle"})}})(),()=>{$=!0}},[v,t,e,x,a]);const N=Be.useCallback($=>{d&&Ot.getState().setWorktreeMetadata(d,{...n,createdFromBranch:$})},[d,n]),D=Ot($=>$.openNewSessionDraft),E=Be.useCallback(async $=>{const _=await wn("git.integrate.cherrypick.resolve.visible",{current_commit:$.state.currentCommit,target_branch:$.state.targetBranch}),X=await wn("git.integrate.cherrypick.resolve.instructions",{repo_root:$.state.repoRoot,temp_worktree_path:$.state.tempWorktreePath,source_branch:$.state.sourceBranch,target_branch:$.state.targetBranch,current_commit:$.state.currentCommit}),O=`Cherry-pick conflict context (JSON)
|
|
@@ -220,7 +220,7 @@ ${e.trim()}
|
|
|
220
220
|
--- END RESULT ${n+1} ---`},mf=(t,e)=>Ot.getState().getWorktreeMetadata(t)?.projectDirectory??e,hA=async t=>{const e=t.directory??void 0,n=ky(t.session.id,e);if(n.length===0&&t.directory){const i=(await Zs.withDirectory(t.directory,()=>Zs.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let a=i.length-1;a>=0;a-=1){const l=i[a];if(l.info?.role==="assistant")return Bu(l.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const i=n[r];if(i.role==="assistant")return Bu(Cy(i.id,e)).trim()}return""};function gA({session:t,open:e,onOpenChange:n}){const{t:r}=ut(),i=Ad(),a=Ei(V=>V.activeSessions),l=Ei(V=>V.archivedSessions),c=xt(V=>V.providers),d=xt(V=>V.currentProviderId),p=xt(V=>V.currentModelId),m=xt(V=>V.currentAgentName),[u,h]=o.useState(d??""),[x,f]=o.useState(p??""),[v,y]=o.useState(()=>d&&p?[{providerID:d,modelID:p,instanceId:Il()}]:[]),[g,w]=o.useState(""),[b,k]=o.useState(m??""),[I,j]=o.useState([]),[N,D]=o.useState(!1),E=o.useMemo(()=>ll(t.title),[t.title]),T=o.useMemo(()=>{const V=new Map;for(const $ of i)V.set($.id,$);for(const $ of a)V.set($.id,$);for(const $ of l)V.set($.id,$);return t.id&&V.set(t.id,t),Array.from(V.values())},[a,l,i,t]);o.useEffect(()=>{if(!e||!E)return;const V=Ot.getState().getDirectoryForSession(t.id),$=mf(t.id,V),_=T.map(X=>{const O=ll(X.title);if(!O||O.groupSlug!==E.groupSlug||O.fusion)return null;const J=Ot.getState().getDirectoryForSession(X.id)??Ha(X),Q=mf(X.id,J);return $&&Q&&$!==Q?null:{session:X,directory:J,projectDirectory:Q}}).filter(X=>X!==null).sort((X,O)=>(X.session.time?.created??0)-(O.session.time?.created??0));j(_)},[T,e,E,t.id]);const S=c.find(V=>V.id===u)?.models.find(V=>V.id===x),M=S?.variants?Object.keys(S.variants):[],A=!!(E&&u&&x&&I.length>0&&!N),R=o.useCallback(V=>{y([V]),h(V.providerID),f(V.modelID),w("")},[]),z=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),B=async()=>{if(!(!E||!u||!x)){D(!0);try{const V=await Promise.all(I.map(ne=>hA(ne))),$=I.map((ne,G)=>({source:ne,text:V[G]??""})).filter(ne=>ne.text.trim().length>0);if($.length===0){H.error(r("multirun.fusion.toast.noOutputs"));return}const _=I[0]?.projectDirectory??I[0]?.directory??null,X=iA(E.groupSlug,u,x),[O,J]=await Promise.all([wn("session.fusion.visible"),wn("session.fusion.instructions")]),Q=await Ot.getState().createSession(X,_,null);if(!Q)throw new Error("Failed to create fusion session");Ot.getState().setCurrentSession(Q.id,_),n(!1),await Zs.withDirectory(_??Zs.getDirectory(),()=>Zs.sendMessage({id:Q.id,providerID:u,modelID:x,variant:g||void 0,agent:b||void 0,text:O,additionalParts:[{text:J,synthetic:!0},...$.map((ne,G)=>({text:fA(ne.source,ne.text,G),synthetic:!0})),{text:`
|
|
221
221
|
|
|
222
222
|
--- FUSION INPUTS END ---
|
|
223
|
-
Now write the final fused answer.`,synthetic:!0}]}))}catch(V){console.error("[MultiRunFusion] Failed to start fusion",V),H.error(r("multirun.fusion.toast.failed"))}finally{D(!1)}}};return s.jsx(hs,{open:e,onOpenChange:n,children:s.jsxs(fs,{className:"max-w-xl overflow-visible",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:r("multirun.fusion.title")}),s.jsx(Is,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx($g,{selectedModels:v,onAdd:R,onUpdate:(V,$)=>R($),onRemove:()=>{y([]),h(""),f(""),w("")},maxModels:1,addButtonLabel:z,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:u?s.jsx(vn,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(is,{value:g||"__default__",onValueChange:V=>w(V==="__default__"?"":V),children:[s.jsxs(as,{size:"lg",className:"h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5",children:[s.jsx(P,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(us,{children:V=>V==="__default__"?r("multirun.modelMultiSelect.variant.default"):V})]}),s.jsxs(os,{fitContent:!0,portalToBody:!0,children:[s.jsx(Ft,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map(V=>s.jsx(Ft,{value:V,children:V},V))]})]}):null,s.jsx(Lg,{value:b,onChange:k,portalToBody:!0,className:"h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:I.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:I.map(V=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(vn,{providerId:ll(V.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.session.title||V.session.id}),s.jsx("button",{type:"button",onClick:()=>j($=>$.filter(_=>_.session.id!==V.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]},V.session.id))})]}),s.jsxs(Vs,{children:[s.jsx(ge,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(ge,{onClick:B,disabled:!A,children:r(N?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function xA(t){const e=at.c(7);let n,r,i,a,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),i=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),a=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=i,e[3]=a,e[4]=l):(n=e[0],r=e[1],i=e[2],a=e[3],l=e[4]);let c;return e[5]!==t?(c=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,i,a,l]}),e[5]=t,e[6]=c):c=e[6],c}const pf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),Ii=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Ii(n,e))return!0;return!1},Sd=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const a of t.children)if(Sd(a,e,n,r))return!0;return!1},bA=(t,e)=>{const n=t.node.session,r=e.node.session,i=n.id,a=r.id;if(i!==a||t.node.session!==e.node.session||pf(t.node)!==pf(e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket)return!1;if(t.currentSessionId!==e.currentSessionId){const m=Ii(t.node,t.currentSessionId),u=Ii(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(i)!==e.pinnedSessionIds.has(a))return!1;{const m=t.renderContext??"project",u=e.renderContext??"project",h=t.archivedBucket??!1,x=e.archivedBucket??!1,f=`${m}:${h?"archived":"active"}:${i}`,v=`${u}:${x?"archived":"active"}:${a}`;if(t.expandedParents.has(f)!==e.expandedParents.has(v))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=Ii(t.node,t.editingId),u=Ii(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=Ii(t.node,t.editingId),u=Ii(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===i!=(e.copiedSessionId===a))return!1;const l=Sd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=Sd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(l!==c)return!1;const d=xs(n.directory??null)??xs(t.groupDirectory??null),p=xs(r.directory??null)??xs(e.groupDirectory??null);return!(d!==p||(d?t.directoryStatus.get(d):null)!==(p?e.directoryStatus.get(p):null)||(t.secondaryMeta?.projectLabel??null)!==(e.secondaryMeta?.projectLabel??null)||(t.secondaryMeta?.branchLabel??null)!==(e.secondaryMeta?.branchLabel??null)||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||(t.renderContext??"project")!==(e.renderContext??"project")||t.renamingFolderId!==e.renamingFolderId)};function yA(t){const{t:e}=ut(),{node:n,depth:r=0,groupDirectory:i,projectId:a,archivedBucket:l=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,notifyOnSubtasks:x,editingId:f,setEditingId:v,editTitle:y,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:b,toggleParent:k,handleSessionSelect:I,handleSessionDoubleClick:j,togglePinnedSession:N,handleShareSession:D,copiedSessionId:E,handleCopyShareUrl:T,handleUnshareSession:C,openSidebarMenuKey:S,setOpenSidebarMenuKey:M,renamingFolderId:A,getFoldersForScope:R,getSessionFolderId:z,removeSessionFromFolder:B,addSessionToFolder:V,createFolderAndStartRename:$,openContextPanelTab:_,handleDeleteSession:X,mobileVariant:O,alwaysShowActions:J,renderSessionNode:Q,secondaryMeta:ne,renderContext:G="project"}=t,le=!!ne?.projectLabel,oe=!!ne?.branchLabel,U=Mi(bt=>bt.displayMode)==="minimal",W=o.useMemo(()=>mn(),[]),te=o.useMemo(()=>Dd(),[]),K=W?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",ae=W?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",ve=!l&&!O,re=U?W?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":W?ve?"group-hover:pr-12":"group-hover:pr-5":ve?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",be=ve?"pr-13":"pr-7",pe=o.useRef(!1),[ye,ie]=o.useState(!1),ue=n.session,Ne=Uf(ue.id)??ue,Ce=xs(ue.directory??null)??xs(i??null),je=Py(Ce??void 0),we=_d(),ke=ur(bt=>bt.enabled),xe=ur(o.useCallback(bt=>bt.selectedIds.has(ue.id),[ue.id])),me=ur(bt=>bt.toggleSelected),Me=ur(bt=>bt.setRange),Ue=o.useCallback(bt=>{const Mt=[],At=ee=>{ee.children.forEach(ht=>{Mt.push(ht.session.id),At(ht)})};return At(bt),Mt},[]),[q,Se]=o.useState(!1),[$e,Pe]=o.useState(!0),fe=`${G}:${l?"archived":"active"}:${ue.id}`,L=ph(o.useCallback(bt=>!!bt.sessionMemoryState.get(ue.id)?.isZombie,[ue.id])),Z=Iy(ue.id),Y=Ay(ue.id,Ce??void 0),Ae=(Ce?c.get(Ce):null)==="missing",Je=d===ue.id,de=Ne.title||e("sessions.sidebar.session.untitled"),ze=n.children.length>0,rt=p.has(ue.id),Re=fe,Xe=u?!0:m.has(Re),qe=!!Ne.parentID,We=Dy(ue.id)>0&&(!qe||x),Ze=Ne.summary,Qe=Kf(Ze),he=Ne.time?.updated||Ne.time?.created||Date.now(),Ge=Ty(he),Ve=Fy(he),it=S===fe,dt=o.useMemo(()=>ll(Ne.title)!==null,[Ne.title]),[Ye,_e]=o.useState(!1),et=o.useMemo(()=>Ue(n).length,[Ue,n]),gt=o.useCallback(async bt=>{const Mt=[];let At=0;for(const ee of bt)try{await we.ensureSessionRenderable(ee.session.id);const ht=zu(je.getState(),ee.session.id).list,St=ee.session.title||e("sessions.sidebar.session.export.untitledSubagent"),qt=ee.session.agent,ms=await gt(ee.children);At+=ms.skipped,Mt.push({title:St,agent:qt,records:ht,children:ms.children})}catch{At+=Ue(ee).length+1}return{children:Mt,skipped:At}},[Ue,je,we,e]),Lt=o.useCallback(bt=>{bt<=0||H.warning(bt===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:bt}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:bt}))},[e]),Ut=o.useCallback(async bt=>{if(!Ce){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}await we.ensureSessionRenderable(ue.id);const Mt=zu(je.getState(),ue.id).list;if(Mt.length===0){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}let At,ee=0;if(bt&&n.children.length>0){const ms=await gt(n.children);At=ms.children,ee=ms.skipped}const ht=JI(Mt,Ne.title??null,At),St=sA(Ne.title??null),qt=await ZI(ht,St);if(qt){H.success(e("sessions.sidebar.session.export.success"),{action:{label:e(tA()),onClick:()=>{eA(qt).then(ms=>{ms||H.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Lt(ee);return}XI(ht,St),H.success(e("sessions.sidebar.session.export.success")),Lt(ee)},[gt,je,n.children,Ne.title,ue.id,Ce,Lt,we,e]),mt=o.useCallback(async()=>{if(n.children.length>0){Pe(!0),Se(!0);return}await Ut(!1)},[Ut,n.children.length]),Nt=o.useCallback(()=>{Ce&&ml("desktop_open_session_mini_chat_window",{sessionId:ue.id,directory:Ce}).catch(bt=>{console.warn("[session-sidebar] failed to open mini chat window",bt)})},[ue.id,Ce]);if(f===ue.id)return s.jsx("div",{className:ce("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:bt=>{bt.preventDefault(),w()},children:[s.jsx("input",{value:y,onChange:bt=>g(bt.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:bt=>{if(bt.key==="Escape"){bt.stopPropagation(),b();return}(bt.key===" "||bt.key==="Enter")&&bt.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:b,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"size-4"})})]}),U?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[ze?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Xe?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:Ge}),Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Qe.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Qe.deletions]})]}):null,le?s.jsx("span",{className:"truncate",children:ne?.projectLabel}):null,oe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ne?.branchLabel})]}):null]})})]})},ue.id);const Xt=Z?.type??"idle",_t=Xt==="busy"||Xt==="retry",Gt=Y.length,Tt=_t||!_t&&We&&!Je,rs=_t?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-busy-pulse","aria-label":e("sessions.sidebar.session.status.active"),title:e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),js=Tt||rt?s.jsxs("span",{className:ce("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",U?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",Tt&&rt?"left-[-18px] w-6":"left-[-10px] w-3.5",ze&&!J?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[Tt?rs:null,rt?s.jsx(P,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,ys=ze?s.jsx("span",{role:"button",tabIndex:0,onClick:bt=>{bt.stopPropagation(),k(Re)},onKeyDown:bt=>{(bt.key==="Enter"||bt.key===" ")&&(bt.preventDefault(),bt.stopPropagation(),k(Re))},className:ce("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",U&&Tt&&!J?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Xe?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Xe?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3"})}):null,vs=L?s.jsx(P,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Wt=bt=>{M(bt?fe:null)},He=bt=>{bt.preventDefault(),bt.stopPropagation(),M(it?null:fe)},kt=bt=>{bt.preventDefault(),bt.stopPropagation()},Kt=bt=>{bt.preventDefault(),bt.stopPropagation()},wt=bt=>{bt.preventDefault(),bt.stopPropagation()},Qt=bt=>{bt.preventDefault(),bt.stopPropagation()},cs=bt=>{bt.preventDefault(),bt.stopPropagation(),M(null),X(ue,{archivedBucket:l})},Ls=bt=>{if(pe.current){pe.current=!1;return}if(ke){if(bt?.preventDefault(),bt?.stopPropagation(),bt?.shiftKey){const At=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(St=>St.getAttribute("data-session-row")).filter(St=>typeof St=="string"&&St.length>0),ee=ur.getState().anchorId,ht=new Map;ht.set(ue.id,Ue(n)),Me(ee,ue.id,At,Ce??null,ht);return}me(ue.id,Ce??null,Ue(n));return}I(ue.id,Ce,Ae,a)},Ss=bt=>{(bt.button===2||bt.button===0&&bt.ctrlKey&&!ke)&&(pe.current=!0)},ns=bt=>{O&&bt.pointerType==="touch"&&ie(!0)},Os=bt=>{O&&bt.pointerType==="touch"&&ie(!1)},Ks=s.jsxs(Rs,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:bt=>{A&&bt.preventDefault()},children:[s.jsxs($t,{onClick:()=>{v(ue.id),g(de)},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:()=>N(ue.id),className:"[&>svg]:mr-1",children:[rt?s.jsx(P,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(P,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(rt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ne.share?s.jsxs(s.Fragment,{children:[s.jsx($t,{onClick:()=>{Ne.share?.url&&T(Ne.share.url,ue.id)},className:"[&>svg]:mr-1",children:E===ue.id?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs($t,{onClick:()=>C(ue.id),className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs($t,{onClick:()=>D(Ne),className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs($t,{onClick:()=>{mt()},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),dt?s.jsxs($t,{onClick:()=>_e(!0),className:"[&>svg]:mr-1",children:[s.jsx(xA,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ce&&!l?(()=>{const bt=R(Ce),Mt=z(Ce,ue.id);return s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),s.jsxs(My,{children:[s.jsxs(Ey,{className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ry,{className:"min-w-[180px]",children:[bt.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):bt.map(At=>s.jsxs($t,{onClick:()=>{Mt===At.id?B(Ce,ue.id):V(Ce,At.id,ue.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:At.name}),Mt===At.id?s.jsx(P,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},At.id)),s.jsx(Cn,{}),s.jsxs($t,{onClick:()=>{const At=$(Ce);At&&V(Ce,At.id,ue.id)},children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Mt?s.jsxs($t,{onClick:()=>{B(Ce,ue.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,W?null:s.jsxs($t,{disabled:!Ce,onClick:()=>{Ce&&_(Ce,{mode:"chat",dedupeKey:`session:${ue.id}`,label:de})},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),te?s.jsxs($t,{disabled:!Ce,onClick:Nt,className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Cn,{}),s.jsxs($t,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>X(ue,{archivedBucket:l}),children:[s.jsx(P,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(l?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(o.Fragment,{children:[s.jsx(xI,{sessionId:ue.id,sessionDirectory:Ce??null,sessionTitle:de,children:s.jsxs("div",{"data-session-row":ue.id,"data-session-scope":Ce??"","data-session-archived":l?"1":"0",className:ce("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",Ae?"opacity-75":"",r>0&&"pl-[20px]",xe&&"bg-primary/15"),children:[js,ys,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:U?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",disabled:Ae,onPointerDown:ns,onPointerUp:Os,onPointerCancel:Os,onMouseDown:Ss,onClick:bt=>Ls(bt),onDoubleClick:bt=>{bt.stopPropagation(),j()},className:ce("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ye&&"bg-interactive-hover/70",J?W?re:be:re),children:s.jsxs("div",{className:ce("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ce("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:Ga(de,h)}),J?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Ve}):null,J?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:ce("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",it?"opacity-0":ae),children:Ve})}),Gt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(P,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Gt})]}):null]})})}),s.jsx(Dt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:ce("flex items-center gap-3 text-left text-muted-foreground",ne?.projectLabel?"justify-between":"justify-start"),children:[ne?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ne.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:Ge})]}),ne?.branchLabel||Qe?s.jsxs("div",{className:ce("flex items-center gap-3 text-left text-muted-foreground",ne?.branchLabel?"justify-between":"justify-start"),children:[ne?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ne.branchLabel})]})}):null,Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Qe.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Qe.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:Ae,onPointerDown:ns,onPointerUp:Os,onPointerCancel:Os,onMouseDown:Ss,onClick:bt=>Ls(bt),onDoubleClick:bt=>{bt.stopPropagation(),j()},className:ce("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ye&&"bg-interactive-hover/70",J?W?re:be:re),children:[s.jsxs("div",{className:ce("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ce("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:Ga(de,h)}),Gt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(P,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Gt})]}):null]}),U?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:Ge}),Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Qe.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Qe.deletions]})]}):null,le?s.jsx("span",{className:"truncate",children:ne?.projectLabel}):null,oe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ne?.branchLabel})]}):null]})})]})}),vs&&!O?s.jsx("div",{className:ce("absolute top-1/2 -translate-y-1/2 z-10",U?"right-0":"right-[30px]"),children:vs}):null,s.jsxs("div",{className:ce("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",it||J&&!W?"opacity-100":ce("opacity-0",K)),children:[ve?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:ce("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:wt,onMouseDown:Qt,onClick:cs,onKeyDown:bt=>bt.stopPropagation(),children:s.jsx(P,{name:"archive",className:ce(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Dt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(Fs,{open:it,onOpenChange:Wt,children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ce("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U&&!J?it?"h-4 w-4 opacity-100":ce("h-4 w-4 opacity-0",K):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:kt,onMouseDown:Kt,onClick:He,onKeyDown:bt=>bt.stopPropagation(),children:s.jsx(P,{name:"more-2",className:ce(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Ks]})]})]})}),ze&&Xe?n.children.map(bt=>Q(bt,r+1,Ce??i,a,l,void 0,G)):null,s.jsx(hs,{open:q,onOpenChange:Se,children:s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Is,{children:et===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:et}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:et})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$e,onChange:bt=>Pe(bt.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Vs,{children:[s.jsx(ge,{type:"button",onClick:()=>Se(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{type:"button",onClick:()=>{Se(!1),Ut($e)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),dt?s.jsx(gA,{session:Ne,open:Ye,onOpenChange:_e}):null]},ue.id)}const vA=o.memo(yA,bA);function wA(t){const e=at.c(71),{t:n}=ut(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:l,onConfirm:c}=t;let d,p,m,u,h,x,f,v,y,g;if(e[0]!==i||e[1]!==n||e[2]!==r){const $=n("sessions.sidebar.session.untitled");u=hs,y=!!r,e[13]!==i?(g=X=>{X||i(null)},e[13]=i,e[14]=g):g=e[14],m=fs,f=!1,v="max-w-sm gap-5",p=bs;let _;e[15]!==n||e[16]!==r?.archivedBucket?(_=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=_):_=e[17],e[18]!==_?(x=s.jsx(gs,{children:_}),e[18]=_,e[19]=x):x=e[19],d=Is,h=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||$}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||$}),e[0]=i,e[1]=n,e[2]=r,e[3]=d,e[4]=p,e[5]=m,e[6]=u,e[7]=h,e[8]=x,e[9]=f,e[10]=v,e[11]=y,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],h=e[7],x=e[8],f=e[9],v=e[10],y=e[11],g=e[12];let w;e[20]!==d||e[21]!==h?(w=s.jsx(d,{children:h}),e[20]=d,e[21]=h,e[22]=w):w=e[22];let b;e[23]!==p||e[24]!==x||e[25]!==w?(b=s.jsxs(p,{children:[x,w]}),e[23]=p,e[24]=x,e[25]=w,e[26]=b):b=e[26];let k;e[27]!==l||e[28]!==a?(k=()=>l(!a),e[27]=l,e[28]=a,e[29]=k):k=e[29];const I=!a;let j;e[30]!==a?(j=a?s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=a,e[31]=j):j=e[31];let N;e[32]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=N):N=e[33];let D;e[34]!==j||e[35]!==N||e[36]!==k||e[37]!==I?(D=s.jsxs("button",{type:"button",onClick:k,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":I,children:[j,N]}),e[34]=j,e[35]=N,e[36]=k,e[37]=I,e[38]=D):D=e[38];let E;e[39]!==i?(E=()=>i(null),e[39]=i,e[40]=E):E=e[40];let T;e[41]!==n?(T=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=T):T=e[42];let C;e[43]!==E||e[44]!==T?(C=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:T}),e[43]=E,e[44]=T,e[45]=C):C=e[45];let S;e[46]!==c?(S=()=>{c()},e[46]=c,e[47]=S):S=e[47];let M;e[48]!==n||e[49]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=M):M=e[50];let A;e[51]!==S||e[52]!==M?(A=s.jsx("button",{type:"button",onClick:S,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:M}),e[51]=S,e[52]=M,e[53]=A):A=e[53];let R;e[54]!==C||e[55]!==A?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[C,A]}),e[54]=C,e[55]=A,e[56]=R):R=e[56];let z;e[57]!==D||e[58]!==R?(z=s.jsxs(Vs,{className:"w-full sm:items-center sm:justify-between",children:[D,R]}),e[57]=D,e[58]=R,e[59]=z):z=e[59];let B;e[60]!==m||e[61]!==f||e[62]!==z||e[63]!==v||e[64]!==b?(B=s.jsxs(m,{showCloseButton:f,className:v,children:[b,z]}),e[60]=m,e[61]=f,e[62]=z,e[63]=v,e[64]=b,e[65]=B):B=e[65];let V;return e[66]!==u||e[67]!==B||e[68]!==y||e[69]!==g?(V=s.jsx(u,{open:y,onOpenChange:g,children:B}),e[66]=u,e[67]=B,e[68]=y,e[69]=g,e[70]=V):V=e[70],V}function jA(t){const e=at.c(57),{t:n}=ut(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:l,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let h;e[4]!==d||e[5]!==p||e[6]!==n?(h=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=h):h=e[7];const x=h,f=!!r;let v;e[8]!==i?(v=V=>{V||i(null)},e[8]=i,e[9]=v):v=e[9];let y;e[10]!==u?(y=s.jsx(gs,{children:u}),e[10]=u,e[11]=y):y=e[11];let g;e[12]!==x?(g=s.jsx(Is,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==y||e[15]!==g?(w=s.jsxs(bs,{children:[y,g]}),e[14]=y,e[15]=g,e[16]=w):w=e[16];let b;e[17]!==l||e[18]!==a?(b=()=>l(!a),e[17]=l,e[18]=a,e[19]=b):b=e[19];const k=!a;let I;e[20]!==a?(I=a?s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=a,e[21]=I):I=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let N;e[24]!==j||e[25]!==b||e[26]!==k||e[27]!==I?(N=s.jsxs("button",{type:"button",onClick:b,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":k,children:[I,j]}),e[24]=j,e[25]=b,e[26]=k,e[27]=I,e[28]=N):N=e[28];let D;e[29]!==i?(D=()=>i(null),e[29]=i,e[30]=D):D=e[30];let E;e[31]!==n?(E=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=E):E=e[32];let T;e[33]!==D||e[34]!==E?(T=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:E}),e[33]=D,e[34]=E,e[35]=T):T=e[35];let C;e[36]!==c?(C=()=>{c()},e[36]=c,e[37]=C):C=e[37];let S;e[38]!==d||e[39]!==n?(S=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=S):S=e[40];let M;e[41]!==C||e[42]!==S?(M=s.jsx("button",{type:"button",onClick:C,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:S}),e[41]=C,e[42]=S,e[43]=M):M=e[43];let A;e[44]!==T||e[45]!==M?(A=s.jsxs("div",{className:"flex items-center gap-2",children:[T,M]}),e[44]=T,e[45]=M,e[46]=A):A=e[46];let R;e[47]!==N||e[48]!==A?(R=s.jsxs(Vs,{className:"w-full sm:items-center sm:justify-between",children:[N,A]}),e[47]=N,e[48]=A,e[49]=R):R=e[49];let z;e[50]!==R||e[51]!==w?(z=s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,R]}),e[50]=R,e[51]=w,e[52]=z):z=e[52];let B;return e[53]!==f||e[54]!==z||e[55]!==v?(B=s.jsx(hs,{open:f,onOpenChange:v,children:z}),e[53]=f,e[54]=z,e[55]=v,e[56]=B):B=e[56],B}function NA(t){const e=at.c(36),{t:n}=ut(),{value:r,setValue:i,onConfirm:a}=t,l=!!r;let c;e[0]!==i?(c=I=>{I||i(null)},e[0]=i,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(gs,{children:d}),e[4]=d,e[5]=p):p=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let u;e[9]!==m?(u=s.jsx(Is,{children:m}),e[9]=m,e[10]=u):u=e[10];let h;e[11]!==p||e[12]!==u?(h=s.jsxs(bs,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=h):h=e[13];let x;e[14]!==i?(x=()=>i(null),e[14]=i,e[15]=x):x=e[15];let f;e[16]!==n?(f=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=f):f=e[17];let v;e[18]!==x||e[19]!==f?(v=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:f}),e[18]=x,e[19]=f,e[20]=v):v=e[20];let y;e[21]!==n?(y=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=y):y=e[22];let g;e[23]!==a||e[24]!==y?(g=s.jsx("button",{type:"button",onClick:a,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:y}),e[23]=a,e[24]=y,e[25]=g):g=e[25];let w;e[26]!==g||e[27]!==v?(w=s.jsxs(Vs,{children:[v,g]}),e[26]=g,e[27]=v,e[28]=w):w=e[28];let b;e[29]!==w||e[30]!==h?(b=s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[h,w]}),e[29]=w,e[30]=h,e[31]=b):b=e[31];let k;return e[32]!==l||e[33]!==c||e[34]!==b?(k=s.jsx(hs,{open:l,onOpenChange:c,children:b}),e[32]=l,e[33]=c,e[34]=b,e[35]=k):k=e[35],k}const SA=t=>{const e=at.c(46),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:a,onMoveToFolder:l,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:h}=ut(),x=!!r&&!a;let f;e[0]!==a||e[1]!==h?(f=h(a?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=a,e[1]=h,e[2]=f):f=e[2];const v=f;let y;e[3]!==n||e[4]!==h?(y=h("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=h,e[5]=y):y=e[5];let g;e[6]!==y?(g=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:y}),e[6]=y,e[7]=g):g=e[7];let w;e[8]!==x||e[9]!==p||e[10]!==c||e[11]!==l||e[12]!==d||e[13]!==i||e[14]!==h?(w=x?s.jsxs(Fs,{children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":h("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(P,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Rs,{align:"end",className:"min-w-[180px]",children:[i.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:h("sessions.sidebar.folders.none")}):i.map(z=>s.jsx($t,{onClick:()=>l(z.id),children:s.jsx("span",{className:"flex-1 truncate",children:z.name})},z.id)),s.jsx(Cn,{}),s.jsxs($t,{onClick:c,children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"}),h("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs($t,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-1 h-4 w-4"}),h("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=x,e[9]=p,e[10]=c,e[11]=l,e[12]=d,e[13]=i,e[14]=h,e[15]=w):w=e[15];let b;e[16]===Symbol.for("react.memo_cache_sentinel")?(b=ce("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=b):b=e[16];let k;e[17]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(P,{name:"delete-bin",className:"h-4 w-4"}),e[17]=k):k=e[17];let I;e[18]!==v||e[19]!==m?(I=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:b,"aria-label":v,children:k})}),e[18]=v,e[19]=m,e[20]=I):I=e[20];let j;e[21]!==v?(j=s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=j):j=e[22];let N;e[23]!==I||e[24]!==j?(N=s.jsxs(Pt,{children:[I,j]}),e[23]=I,e[24]=j,e[25]=N):N=e[25];let D;e[26]!==h?(D=h("sessions.sidebar.header.actions.exitSelection"),e[26]=h,e[27]=D):D=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(P,{name:"close",className:"h-4 w-4"}),e[28]=E):E=e[28];let T;e[29]!==u||e[30]!==D?(T=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":D,children:E})}),e[29]=u,e[30]=D,e[31]=T):T=e[31];let C;e[32]!==h?(C=h("sessions.sidebar.header.actions.exitSelection"),e[32]=h,e[33]=C):C=e[33];let S;e[34]!==C?(S=s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:C})}),e[34]=C,e[35]=S):S=e[35];let M;e[36]!==T||e[37]!==S?(M=s.jsxs(Pt,{children:[T,S]}),e[36]=T,e[37]=S,e[38]=M):M=e[38];let A;e[39]!==M||e[40]!==w||e[41]!==N?(A=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,N,M]}),e[39]=M,e[40]=w,e[41]=N,e[42]=A):A=e[42];let R;return e[43]!==A||e[44]!==g?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,A]}),e[43]=A,e[44]=g,e[45]=R):R=e[45],R},Bg="oc.sessions.activeNow",kA=2160*60*1e3,zg=t=>!!t.parentID,nu=t=>!!t.time?.archived,kd=t=>{const e=t.time?.updated,n=t.time?.created;return typeof e=="number"&&Number.isFinite(e)?e:typeof n=="number"&&Number.isFinite(n)?n:0},CA=t=>{try{const e=t.getItem(Bg);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,i=[];return n.forEach(a=>{const l=typeof a=="string"?a:a&&typeof a=="object"&&"sessionId"in a&&typeof a.sessionId=="string"?a.sessionId:null;!l||r.has(l)||(r.add(l),i.push({sessionId:l}))}),i}catch{return[]}},Bc=(t,e)=>{try{t.setItem(Bg,JSON.stringify(e))}catch{}},PA=(t,e,n=Date.now())=>{const r=n-kA;return t.filter(i=>{const a=e.get(i.sessionId);return a?nu(a)?!1:kd(a)>=r:!0})},IA=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Vg=t=>[...t].sort((e,n)=>kd(n)-kd(e)),AA=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!nu(r)).filter(r=>!zg(r));return Vg(n)},DA=(t,e)=>{const n=t.filter(r=>{if(nu(r)||zg(r))return!1;const i=e[r.id];return i?.type==="busy"||i?.type==="retry"});return Vg(n)},Uo=pi(),zc=gr((t,e)=>({entries:CA(Uo),setEntries:n=>{n!==e().entries&&(t({entries:n}),Bc(Uo,n))},addSession:n=>{const r=IA(e().entries,n);r!==e().entries&&(t({entries:r}),Bc(Uo,r))},prune:n=>{const r=e().entries,i=PA(r,n);i.length===r.length&&i.every((a,l)=>a.sessionId===r[l]?.sessionId)||(t({entries:i}),Bc(Uo,i))}})),Wo="oc.sessions.projectCollapse",ff="oc.sessions.groupOrder",hf="oc.sessions.groupCollapse",gf="oc.sessions.activeSessionByProject",Vc="oc.sessions.expandedParents.v2",TA="oc.sessions.expandedParents",MA="oc.sessions.pinned",EA=(t,e)=>{const n=new Set;for(const r of t){const i=xs(r.path)?.toLowerCase();i&&n.add(i)}for(const r of e.values())for(const i of r){const a=xs(i.path)?.toLowerCase();a&&n.add(a)}return n},RA=(t,e)=>{if(t.time?.archived)return!0;const n=xs(Ha(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},FA=5*6e4,xf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:i=!1})=>{const{t:a}=ut(),[l,c]=o.useState(!1),[d,p]=o.useState(""),m=o.useRef(null),u=o.useRef(null),h=o.useRef(new Set),[x,f]=o.useState(null),[v,y]=o.useState(""),[g,w]=o.useState(null),[b,k]=o.useState(new Set),[I]=o.useState(()=>new Map),j=o.useMemo(()=>pi(),[]),N=zc(Le=>Le.entries),D=zc(Le=>Le.addSession),E=zc(Le=>Le.prune),[T,C]=o.useState(new Set),[S,M]=o.useState(new Map),[A,R]=o.useState(new Set),[z,B]=o.useState(!1),[V,$]=o.useState(null),[_,X]=o.useState(null),[O,J]=o.useState(""),[Q,ne]=o.useState(null),[G,le]=o.useState(null),[oe,F]=o.useState(null),U=oc(Le=>Le.ids),W=oc(Le=>Le.setIds),te=oc(Le=>Le.toggle),[K,ae]=o.useState(()=>{try{const Le=pi().getItem(hf);if(!Le)return new Set;const vt=JSON.parse(Le);return new Set(Array.isArray(vt)?vt.filter(ft=>typeof ft=="string"):[])}catch{return new Set}}),[ve,re]=o.useState(()=>{try{const Le=pi().getItem(ff);if(!Le)return new Map;const vt=JSON.parse(Le),ft=new Map;return Object.entries(vt).forEach(([Yt,ps])=>{Array.isArray(ps)&&ft.set(Yt,ps.filter(Ws=>typeof Ws=="string"))}),ft}catch{return new Map}}),[be,pe]=o.useState(()=>{try{const Le=pi().getItem(gf);if(!Le)return new Map;const vt=JSON.parse(Le),ft=new Map;return Object.entries(vt).forEach(([Yt,ps])=>{typeof ps=="string"&&ps.length>0&&ft.set(Yt,ps)}),ft}catch{return new Map}}),[ye,ie]=o.useState(new Map),ue=o.useRef(new Map),se=o.useRef(0),Ne=$s(Le=>Le.homeDirectory),Ce=$s(Le=>Le.currentDirectory),je=$s(Le=>Le.setDirectory),we=As(Le=>Le.projects),ke=As(Le=>Le.activeProjectId),xe=As(Le=>Le.removeProject),me=As(Le=>Le.setActiveProjectIdOnly),Me=As(Le=>Le.updateProjectMeta),Ue=As(Le=>Le.reorderProjects),q=Ie(Le=>Le.setActiveMainTab),Se=Ie(Le=>Le.openContextPanelTab),$e=Ie(Le=>Le.setSettingsDialogOpen),Pe=Ie(Le=>Le.toggleHelpDialog),fe=Ie(Le=>Le.setAboutDialogOpen),L=Ie(Le=>Le.setSessionSwitcherOpen),Z=Ie(Le=>Le.setScheduledTasksDialogOpen),Y=Ie(Le=>Le.toggleSidebar),Ee=Ie(Le=>Le.openMultiRunLauncher),Ae=Ie(Le=>Le.notifyOnSubtasks),Je=Ie(Le=>Le.showDeletionDialog),de=Ie(Le=>Le.setShowDeletionDialog),ze=ho(d,120),rt=o.useMemo(()=>ze.trim().toLowerCase(),[ze]),Re=rt.length>0,Xe=Yn(Le=>Le.collapsedFolderIds),qe=Yn(Le=>Le.foldersMap),Te=Yn(Le=>Le.getFoldersForScope),We=Yn(Le=>Le.createFolder),Ze=Yn(Le=>Le.renameFolder),Qe=Yn(Le=>Le.deleteFolder),he=Yn(Le=>Le.addSessionToFolder),Ge=Yn(Le=>Le.addSessionsToFolder),Ve=Yn(Le=>Le.removeSessionFromFolder),it=Yn(Le=>Le.removeSessionsFromFolders),dt=Yn(Le=>Le.toggleFolderCollapse),Ye=Yn(Le=>Le.cleanupSessions),_e=Yn(Le=>Le.getSessionFolderId);LP({isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const et=ah(),gt=_d(),Lt=Ad(),Ut=Ly(),mt=Ei(Le=>Le.hasLoaded),Nt=Ei(Le=>Le.activeSessions),Xt=Ei(Le=>Le.archivedSessions),_t=Ot(Le=>Le.currentSessionId),Gt=Ot(Le=>!!Le.newSessionDraft?.open),lt=Ot(Le=>Le.setCurrentSession),Tt=Ot(Le=>Le.updateSessionTitle),rs=Ot(Le=>Le.shareSession),js=Ot(Le=>Le.unshareSession),ys=Ot(Le=>Le.worktreeMetadata),vs=Ot(Le=>Le.availableWorktreesByProject),Wt=Ot(Le=>Le.openNewSessionDraft),He=o.useMemo(()=>EA(we,vs),[vs,we]),kt=o.useMemo(()=>{const Le=new Map(Lt.map(Yt=>[Yt.id,Yt])),vt=Nt.map(Yt=>Le.get(Yt.id)??Yt),ft=new Set(vt.map(Yt=>Yt.id));return Lt.forEach(Yt=>{ft.has(Yt.id)||vt.push(Yt)}),vt.filter(Yt=>RA(Yt,He))},[Nt,He,Lt]),Kt=o.useMemo(()=>Lt.map(Le=>{const vt=xs(Le.directory??null)??"";return`${Le.id}:${Le.title??""}:${Le.time?.archived?1:0}:${vt}`}).join("|"),[Lt]),wt=o.useRef(Lt);o.useEffect(()=>{wt.current=Lt},[Kt,Lt]),o.useEffect(()=>{let Le=!1;const vt=async()=>{const ft=As.getState().projects;if(ft.length===0)return;const Yt=new Map,ps=[];await Promise.all(ft.map(async Ws=>{const Dn=xs(Ws.path);if(Dn)try{if(!(tn.getState().directories.get(Dn)?.isGitRepo??await kr(()=>import("./modelPrefsAutoSave-DuvP8x_e.js").then(un=>un.cc),__vite__mapDeps([2,0,1,3,4])).then(un=>un.checkIsGitRepository(Dn))))return;const Tn=await Qc({id:Ws.id,path:Dn});if(Le||Tn.length===0)return;Yt.set(Dn,Tn),ps.push(...Tn)}catch{}})),!Le&&Ot.setState({availableWorktrees:ps,availableWorktreesByProject:Yt})};return Jc(wt.current),vt(),()=>{Le=!0}},[Ce,Kt,we]),o.useEffect(()=>{let Le=null;const vt=Mg(ft=>{ft.type==="scheduled-task-ran"&&(Le&&clearTimeout(Le),Le=setTimeout(()=>{Jc(wt.current)},500))});return()=>{Le&&clearTimeout(Le),vt()}},[]);const Qt=o.useMemo(()=>gn(),[]),cs=El(),[Ls,Ss]=o.useState(!1),ns=o.useMemo(()=>mn(),[]),{isTablet:Os}=rn(),Ks=t||Os,bt=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Mt=!t&&!ns&&!Qt,At=!t&&!ns&&!Mt,ee=Qt&&bt&&!Ls||cs?"pl-[5.5rem]":"pl-3",ht="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";o.useEffect(()=>{if(!Qt||!bt){Ss(!1);return}let Le=!1,vt=null;const ft=async()=>{try{const ps=await By();Le||Ss(ps)}catch{Le||Ss(!1)}},Yt=async()=>{try{vt=zy(()=>{ft()})}catch{}};return ft(),Yt(),()=>{Le=!0,vt&&vt()}},[Qt,bt]);const St=o.useCallback(async Le=>{const vt=Le.target;vt.closest(".app-region-no-drag")||vt.closest("button, a, input, select, textarea")||Le.button===0&&Qt&&await fh()},[Qt]),{buildGroupSearchText:qt,filterSessionNodesForSearch:ms,buildGroupedSessions:Ds}=FP({homeDirectory:Ne,worktreeMetadata:ys,pinnedSessionIds:U,gitBranches:et,isVSCode:ns}),{scheduleCollapsedProjectsPersist:Ke}=UP({isVSCode:ns,hasLoadedGlobalSessions:mt,safeStorage:j,keys:{sessionExpanded:Vc,sessionExpandedLegacy:TA,projectCollapse:Wo,sessionPinned:MA,groupOrder:ff,projectActiveSession:gf,groupCollapse:hf},sessions:kt,setPinnedSessionIds:W,groupOrderByProject:ve,activeSessionByProject:be,collapsedGroups:K,setExpandedParents:k,setCollapsedProjects:C}),yt=o.useMemo(()=>[...kt].sort((Le,vt)=>ca(Le,vt,U)),[kt,U]),Et=o.useMemo(()=>new Map(yt.map((Le,vt)=>[Le.id,vt])),[yt]),Ht=o.useMemo(()=>{const Le=new Map;return yt.forEach(vt=>{const ft=vt.parentID;if(!ft)return;const Yt=Le.get(ft)??[];Yt.push(vt),Le.set(ft,Yt)}),Le.forEach(vt=>vt.sort((ft,Yt)=>ca(ft,Yt,U))),Le},[yt,U]),ss=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noSessions.description")})]}),Rt=o.useMemo(()=>we.find(Le=>Le.id===g)??null,[we,g]),Ps=o.useCallback(Le=>{g&&(Me(g,Le),w(null))},[g,Me]),Qs=o.useCallback(()=>{B(!0)},[]),Hs=o.useCallback(()=>{t&&L(!1),$e(!0)},[t,L,$e]),ts=Ot(Le=>Le.deleteSession),Ns=Ot(Le=>Le.deleteSessions),jn=Ot(Le=>Le.archiveSession),sn=Ot(Le=>Le.archiveSessions),{copiedSessionId:Dr,handleSessionSelect:Tr,handleSessionDoubleClick:zr,handleSaveEdit:Vr,handleCancelEdit:Gs,handleShareSession:Mn,handleCopyShareUrl:ir,handleUnshareSession:En,handleDeleteSession:_r,confirmDeleteSession:In}=OP({activeProjectId:ke,currentDirectory:Ce,currentSessionId:_t,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:l,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:me,setDirectory:je,setActiveMainTab:q,setSessionSwitcherOpen:L,setCurrentSession:lt,updateSessionTitle:Tt,shareSession:rs,unshareSession:js,deleteSession:ts,deleteSessions:Ns,archiveSession:jn,archiveSessions:sn,childrenMap:Ht,showDeletionDialog:Je,setDeleteSessionConfirm:ne,deleteSessionConfirm:Q,setEditingId:f,setEditTitle:y,editingId:x,editTitle:v}),ln=o.useCallback(()=>{if(!G)return;const{scopeKey:Le,folderId:vt}=G;le(null),Qe(Le,vt)},[G,Qe]),an=o.useCallback(()=>{Sr.requestDirectoryDialog()},[]);o.useEffect(()=>{if(!_t)return;const vt=kt.find(Yt=>Yt.id===_t)?.parentID;if(!vt)return;const ft=[`project:active:${vt}`,`project:archived:${vt}`,`recent:active:${vt}`,`recent:archived:${vt}`];k(Yt=>{if(ft.every(Ws=>Yt.has(Ws)))return Yt;const ps=new Set(Yt);ft.forEach(Ws=>ps.add(Ws));try{j.setItem(Vc,JSON.stringify(Array.from(ps)))}catch{}return ps})},[_t,kt,j]);const Fe=o.useCallback(Le=>{k(vt=>{const ft=new Set(vt);ft.has(Le)?ft.delete(Le):ft.add(Le);try{j.setItem(Vc,JSON.stringify(Array.from(ft)))}catch{}return ft})},[j]),Ct=o.useCallback((Le,vt)=>{if(!Le)return null;vt&&Xe.has(vt)&&dt(vt);const ft=We(Le,a("sessions.sidebar.folder.newFolderName"),vt);return X(ft.id),J(ft.name),ft},[Xe,dt,We,a]),Zt=o.useCallback(Le=>{R(vt=>{const ft=new Set(vt);return ft.has(Le)?ft.delete(Le):ft.add(Le),ft})},[]),ls=o.useCallback(()=>{se.current=Date.now()+150,C(()=>{const Le=new Set(we.map(vt=>vt.id));try{j.setItem(Wo,JSON.stringify(Array.from(Le)))}catch{}return ns||Ke(Le),Le})},[we,ns,j,Ke]),Bs=o.useCallback(()=>{se.current=Date.now()+150,C(()=>{const Le=new Set;try{j.setItem(Wo,JSON.stringify([]))}catch{}return ns||Ke(Le),Le})},[ns,j,Ke]),Js=o.useCallback(Le=>{se.current=Date.now()+150,C(vt=>{const ft=new Set(vt);ft.has(Le)?ft.delete(Le):ft.add(Le);try{j.setItem(Wo,JSON.stringify(Array.from(ft)))}catch{}return ns||Ke(ft),ft})},[ns,j,Ke]),ws=o.useMemo(()=>we.map(Le=>({...Le,normalizedPath:xs(Le.path)})).filter(Le=>!!Le.normalizedPath),[we]),en=o.useMemo(()=>ws.map(Le=>Le.normalizedPath),[ws]),{github:nn}=Pn(),Rn=Hn(Le=>Le.status),Fn=Hn(Le=>Le.hasChecked),Ur=Oy(en),xr=mr(Le=>Le.ensureEntry),Wr=mr(Le=>Le.setParams),Ln=mr(Le=>Le.refreshTargets);KP({normalizedProjects:ws,gitRepoStatus:Ur,setProjectRepoStatus:M,setProjectRootBranches:ie});const er=Ot(Le=>Le.isLoading);eI({isSessionsLoading:er,sessions:kt,archivedSessions:Xt,normalizedProjects:ws,isVSCode:ns,availableWorktreesByProject:vs,cleanupSessions:Ye});const{getSessionsForProject:br,getArchivedSessionsForProject:ar}=YP({isVSCode:ns,sessions:kt,archivedSessions:Xt,availableWorktreesByProject:vs});PP({normalizedProjects:ws,sessions:kt,archivedSessions:Xt,availableWorktreesByProject:vs,isVSCode:ns,isSessionsLoading:er,foldersMap:qe,createFolder:We,addSessionToFolder:he,cleanupSessions:Ye});const dn=o.useRef(!1);ke&&S.has(ke)&&(dn.current=!!S.get(ke));const{projectSections:On,groupSearchDataByGroup:bn,sectionsForRender:Gn,searchMatchCount:Nn}=DP({normalizedProjects:ws,getSessionsForProject:br,getArchivedSessionsForProject:ar,availableWorktreesByProject:vs,projectRepoStatus:S,projectRootBranches:ye,lastRepoStatus:dn.current,buildGroupedSessions:Ds,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,filterSessionNodesForSearch:ms,buildGroupSearchText:qt,foldersMap:qe}),ni=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noMatches.description")})]}),Gi=!0,{currentSessionDirectory:tr}=MP({projectSections:On,activeProjectId:ke,activeSessionByProject:be,setActiveSessionByProject:pe,currentSessionId:_t,handleSessionSelect:Tr,newSessionDraftOpen:Gt,mobileVariant:t,openNewSessionDraft:Wt,setActiveMainTab:q,setSessionSwitcherOpen:L,sessions:kt,worktreeMetadata:ys}),{getOrderedGroups:bi}=EP(ve),Sn=o.useRef(!1);o.useEffect(()=>{if(Sn.current||On.length===0)return;const Le=On.flatMap(vt=>vt.groups.filter(ft=>ft.isArchivedBucket).map(ft=>`${vt.project.id}:${ft.id}`));Le.length>0&&ae(vt=>new Set([...vt,...Le])),Sn.current=!0},[On]);const yr=o.useMemo(()=>{const Le=new Map,vt=new Map;return On.forEach(ft=>{const Yt=mh(ft.project.label?.trim()||Vi(ft.project.normalizedPath,Ne)||ft.project.normalizedPath);ft.groups.forEach(ps=>{const Ws=ps.branch&&ps.branch!=="HEAD"&&ps.branch!==Yt?ps.branch:null,Dn={projectLabel:Yt,branchLabel:Ws},wr=nr=>{nr.forEach(Tn=>{const un=ft.project.normalizedPath.length,Aa=vt.get(Tn.session.id)??-1;un<Aa||(Le.set(Tn.session.id,{node:Tn,projectId:ft.project.id,groupDirectory:ps.directory,secondaryMeta:Dn}),vt.set(Tn.session.id,un),Tn.children.length>0&&wr(Tn.children))})};wr(ps.sessions)})}),Le},[On,Ne]),qn=Mi(Le=>Le.showRecentSection),Gr=o.useMemo(()=>qn?AA(N,new Map(kt.map(Le=>[Le.id,Le]))).sort((Le,vt)=>ca(Le,vt,U)):[],[N,U,kt,qn]),Kr=o.useMemo(()=>qn?DA(kt,Ut):[],[Ut,kt,qn]);o.useEffect(()=>{!qn||Kr.length===0||Kr.forEach(Le=>D(Le.id))},[D,Kr,qn]),o.useEffect(()=>{if(!qn)return;const Le=new Map;[...kt,...Xt].forEach(vt=>{Le.set(vt.id,vt)}),E(Le)},[Xt,E,kt,qn]);const qi=o.useMemo(()=>{if(!qn)return[];const Le=vt=>{const ft=yr.get(vt.id),Yt=xs(vt.directory??null);return{node:ft?.node??{session:vt,children:[],worktree:null},projectId:ft?.projectId??null,groupDirectory:ft?.groupDirectory??Yt,secondaryMeta:ft?.secondaryMeta??null}};return[{key:"active-now",title:a("sessions.sidebar.activity.recentTitle"),items:Gr.map(Le)}]},[Gr,yr,qn,a]),cn=o.useMemo(()=>new Set(Gr.map(Le=>Le.id)),[Gr]),Oe=o.useMemo(()=>[...cn],[cn]);K4({currentSessionId:_t,sortedSessions:yt,recentSessionIds:Oe,ensureSessionRenderable:gt.ensureSessionRenderable});const tt=o.useMemo(()=>{if(!ns||Re||cn.size===0)return Gn;const Le=vt=>vt.reduce((ft,Yt)=>{if(cn.has(Yt.session.id))return ft;const ps=Le(Yt.children);return ps.length===Yt.children.length?(ft.push(Yt),ft):(ft.push({...Yt,children:ps}),ft)},[]);return Gn.map(vt=>({...vt,groups:vt.groups.map(ft=>({...ft,sessions:Le(ft.sessions)}))}))},[ns,Re,cn,Gn]),nt=o.useMemo(()=>{const Le=new Set;return tt.forEach(vt=>{vt.groups.forEach(ft=>{const Yt=xs(ft.directory??null),ps=ft.branch?.trim()||et.get(Yt||"")?.trim();!Yt||!ps||Le.add(Ya(Yt,ps))})}),[...Le]},[et,tt]),ct=j0(nt);o.useEffect(()=>{if(!Fn||!Rn?.connected||!nn)return;const Le=[],vt=Date.now();if(tt.forEach(Yt=>{T.has(Yt.project.id)||Yt.groups.forEach(ps=>{const Ws=xs(ps.directory??null),Dn=ps.branch?.trim()||et.get(Ws||"")?.trim();if(!Ws||!Dn)return;const wr=Ya(Ws,Dn),nr=mr.getState().entries[wr],Tn=!!nr?.status?.pr,un=`${Ws}::${Dn}`,Aa=Math.max(nr?.lastRefreshAt??0,nr?.lastDiscoveryPollAt??0),So=!!(nr?.isInitialStatusResolved&&!Tn&&(!h.current.has(un)||vt-Aa>=FA));(!nr||!nr.isInitialStatusResolved||So)&&(So&&h.current.add(un),Le.push({directory:Ws,branch:Dn}))})}),Le.length===0)return;const ft=new Map;Le.forEach(Yt=>{const ps=Ya(Yt.directory,Yt.branch,Yt.remoteName??null);ft.has(ps)||ft.set(ps,Yt)}),ft.forEach((Yt,ps)=>{xr(ps),Wr(ps,{directory:Yt.directory,branch:Yt.branch,remoteName:Yt.remoteName??null,canShow:!0,github:nn,githubAuthChecked:Fn,githubConnected:Rn.connected})}),Ln([...ft.values()],{force:!0,silent:!0,markInitialResolved:!0})},[T,xr,nn,Fn,Rn?.connected,et,Ln,tt,Wr]);const _s=t?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",pn="h-4.5 w-4.5",Mr=rI({isDesktopShellRuntime:Qt,projectSections:On,projectHeaderSentinelRefs:ue}),An=o.useCallback((Le,vt=0,ft,Yt,ps=!1,Ws,Dn="project")=>s.jsx(vA,{node:Le,depth:vt,groupDirectory:ft,projectId:Yt,archivedBucket:ps,directoryStatus:I,currentSessionId:_t,pinnedSessionIds:U,expandedParents:b,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,notifyOnSubtasks:Ae,editingId:x,setEditingId:f,editTitle:v,setEditTitle:y,handleSaveEdit:Vr,handleCancelEdit:Gs,toggleParent:Fe,handleSessionSelect:Tr,handleSessionDoubleClick:zr,togglePinnedSession:te,handleShareSession:Mn,copiedSessionId:Dr,handleCopyShareUrl:ir,handleUnshareSession:En,openSidebarMenuKey:V,setOpenSidebarMenuKey:$,renamingFolderId:_,getFoldersForScope:Te,getSessionFolderId:_e,removeSessionFromFolder:Ve,addSessionToFolder:he,createFolderAndStartRename:Ct,openContextPanelTab:Se,handleDeleteSession:_r,mobileVariant:t,alwaysShowActions:Ks,renderSessionNode:An,secondaryMeta:Ws,renderContext:Dn}),[I,_t,U,b,Re,rt,Ae,x,f,v,y,Vr,Gs,Fe,Tr,zr,te,Mn,Dr,ir,En,V,$,_,Te,_e,Ve,he,Ct,Se,_r,t,Ks]),qr=o.useCallback(Le=>{ae(vt=>{const ft=new Set(vt);return ft.has(Le)?ft.delete(Le):ft.add(Le),ft})},[]),vr=o.useMemo(()=>{const Le=new Map;for(const[vt,ft]of ct)Le.set(vt,{visualState:ft.visualState,number:ft.number,url:ft.url,state:ft.prState,draft:ft.draft,title:ft.title,base:ft.base,head:ft.head,checks:ft.checks,canMerge:ft.canMerge,mergeableState:ft.mergeableState,repo:ft.repo});return Le},[ct]),ri=o.useCallback((Le,vt,ft,Yt,ps,Ws)=>s.jsx(jI,{group:Le,groupKey:vt,projectId:ft,hideGroupLabel:Yt,compactBodyPadding:Ws,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,groupSearchDataByGroup:bn,expandedSessionGroups:A,collapsedGroups:K,hideDirectoryControls:r,collapsedFolderIds:Xe,toggleFolderCollapse:dt,renameFolder:Ze,deleteFolder:Qe,showDeletionDialog:Je,setDeleteFolderConfirm:le,renderSessionNode:An,currentSessionDirectory:tr,projectRepoStatus:S,lastRepoStatus:dn.current,toggleGroupSessionLimit:Zt,mobileVariant:t,alwaysShowActions:Ks,activeProjectId:ke,setActiveProjectIdOnly:me,setActiveMainTab:q,setSessionSwitcherOpen:L,openNewSessionDraft:Wt,addSessionToFolder:he,createFolderAndStartRename:Ct,renamingFolderId:_,renameFolderDraft:O,setRenameFolderDraft:J,setRenamingFolderId:X,pinnedSessionIds:U,sessionOrderIndex:Et,prVisualStateByDirectoryBranch:vr,onToggleCollapsedGroup:qr,dragHandleProps:ps}),[Re,rt,bn,A,K,r,Xe,dt,Ze,Qe,Je,An,tr,S,Zt,t,Ks,ke,me,q,L,Wt,he,Ct,_,O,U,Et,vr,qr]),ii=qn&&!Re?s.jsx(AI,{sections:qi,renderSessionNode:An}):null,ai=!!(_||x||g),yi=ur(Le=>Le.enabled),Us=ur(Le=>Le.selectedIds),oi=ur(Le=>Le.scopeKey),Ca=ur,Hl=o.useCallback(()=>{ur.getState().toggleMode()},[]),sr=o.useCallback(()=>{ur.getState().disable()},[]),Er=o.useMemo(()=>{if(Us.size===0||typeof document>"u")return!1;let Le=!1,vt=!1;for(const ft of Us){const Yt=document.querySelectorAll(`[data-session-row="${CSS.escape(ft)}"]`);for(const ps of Yt)ps.getAttribute("data-session-archived")==="1"?vt=!0:Le=!0}return vt&&!Le},[Us]),xn=o.useMemo(()=>{if(oi)return oi;if(Us.size===0||typeof document>"u")return null;for(const Le of Us){const ft=document.querySelector(`[data-session-row="${CSS.escape(Le)}"]`)?.getAttribute("data-session-scope");if(ft&&ft.length>0)return ft}return null},[Us,oi]),Pa=o.useMemo(()=>xn?qe[xn]??[]:[],[qe,xn]),ou=o.useMemo(()=>{if(!xn||Us.size===0)return!1;const Le=qe[xn]??[];for(const vt of Le)for(const ft of vt.sessionIds)if(Us.has(ft))return!0;return!1},[qe,xn,Us]),Ia=o.useCallback(Le=>{!xn||Us.size===0||Ge(xn,Le,Array.from(Us))},[Ge,Us,xn]),Yi=o.useCallback(()=>{if(!xn||Us.size===0)return;const Le=Ct(xn);Le&&Ge(xn,Le.id,Array.from(Us))},[Ge,Ct,Us,xn]),wo=o.useCallback(()=>{!xn||Us.size===0||it(xn,Array.from(Us))},[it,Us,xn]),li=o.useCallback(async()=>{const Le=Array.from(Us);if(Le.length!==0){if(Er){const{deletedIds:vt,failedIds:ft}=await Ns(Le);vt.length>0&&H.success(vt.length===1?a("sessions.sidebar.bulkActions.deletedSingle",{count:vt.length}):a("sessions.sidebar.bulkActions.deletedPlural",{count:vt.length})),ft.length>0&&H.error(ft.length===1?a("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ft.length}):a("sessions.sidebar.bulkActions.failedDeletePlural",{count:ft.length}))}else{const{archivedIds:vt,failedIds:ft}=await sn(Le);vt.length>0&&H.success(vt.length===1?a("sessions.sidebar.bulkActions.archivedSingle",{count:vt.length}):a("sessions.sidebar.bulkActions.archivedPlural",{count:vt.length})),ft.length>0&&H.error(ft.length===1?a("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ft.length}):a("sessions.sidebar.bulkActions.failedArchivePlural",{count:ft.length}))}ur.getState().clear()}},[sn,Er,Ns,Us,a]),Qi=o.useCallback(()=>{const Le=Us.size;if(Le!==0){if(!Je){li();return}F({sessionCount:Le,archivedBucket:Er})}},[Er,li,Us,Je]),jo=o.useCallback(async()=>{F(null),await li()},[li]);o.useEffect(()=>{if(!yi)return;const Le=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),vt=ft=>{if(ai)return;const Yt=ft.target;if(Yt&&(Yt.tagName==="INPUT"||Yt.tagName==="TEXTAREA"||Yt.isContentEditable))return;const ps=Le?ft.metaKey:ft.ctrlKey;if(ft.key==="Escape"){ft.preventDefault(),ur.getState().disable();return}if(ps&&ft.key==="Backspace"){ft.preventDefault(),Qi();return}if(ps&&(ft.key==="a"||ft.key==="A")){const Ws=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Ws.length===0)return;ft.preventDefault();const wr=Ca.getState().scopeKey??Ws[0]?.getAttribute("data-session-scope")??null,nr=un=>wr?un.getAttribute("data-session-scope")===wr:!0,Tn=Ws.filter(nr).map(un=>un.getAttribute("data-session-row")).filter(un=>typeof un=="string"&&un.length>0);if(Tn.length===0)return;Ca.getState().replaceAll(Tn,wr||null)}};return window.addEventListener("keydown",vt),()=>window.removeEventListener("keydown",vt)},[Qi,ai,Ca,yi]);const No=o.useCallback(()=>{q("chat"),t&&L(!1),Wt()},[t,Wt,q,L]),Gl=o.useCallback(()=>{q("chat"),t&&L(!1),Ee()},[t,Ee,q,L]);return s.jsxs("div",{ref:m,className:ce("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[At?s.jsx("div",{onMouseDown:St,className:ce("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",ee),children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Y,className:ht,"aria-label":a("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(P,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(NI,{hideDirectoryControls:r,handleOpenDirectoryDialog:an,handleNewSession:No,canOpenMultiRun:we.length>0,openMultiRunLauncher:Gl,headerActionIconClass:pn,reserveHeaderActionsSpace:Gi,headerActionButtonClass:_s,isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Re,searchMatchCount:Nn,collapseAllProjects:ls,expandAllProjects:Bs,openScheduledTasksDialog:()=>Z(!0),selectionModeEnabled:yi,onToggleSelectionMode:Hl,showSidebarToggle:Mt,onToggleSidebar:Y,avoidWindowControlsOverlay:cs}),s.jsx($I,{topContent:ii,sectionsForRender:tt,projectSections:On,activeProjectId:ke,showOnlyMainWorkspace:i,hasSessionSearchQuery:Re,emptyState:ss,searchEmptyState:ni,renderGroupSessions:ri,homeDirectory:Ne,collapsedProjects:T,hideDirectoryControls:r,projectRepoStatus:S,isDesktopShellRuntime:Qt,stuckProjectHeaders:Mr,mobileVariant:t,alwaysShowActions:Ks,toggleProject:Js,setActiveProjectIdOnly:me,setActiveMainTab:q,setSessionSwitcherOpen:L,openNewSessionDraft:Wt,openNewWorktreeDialog:Qs,openProjectEditDialog:w,removeProject:xe,projectHeaderSentinelRefs:ue,reorderProjects:Ue,getOrderedGroups:bi,setGroupOrderByProject:re,openSidebarMenuKey:V,setOpenSidebarMenuKey:$,isInlineEditing:ai}),yi&&Us.size>0?s.jsx(SA,{selectedCount:Us.size,scopeKey:xn,scopeFolders:Pa,archivedBucket:Er,onMoveToFolder:Ia,onCreateFolderAndMove:Yi,onRemoveFromFolder:wo,canRemoveFromFolder:ou,onDelete:Qi,onDone:sr}):null,s.jsx(TI,{onOpenSettings:Hs,onOpenShortcuts:Pe,onOpenAbout:()=>fe(!0),showRuntimeButtons:!ns}),Rt?s.jsx($y,{open:!!Rt,onOpenChange:Le=>{Le||w(null)},projectId:Rt.id,projectName:Rt.label||Vi(Rt.path,Ne),projectPath:Rt.path,initialIcon:Rt.icon,initialColor:Rt.color,initialIconBackground:Rt.iconBackground,onSave:Ps}):null,s.jsx(Q4,{open:z,onOpenChange:B,onWorktreeCreated:(Le,vt)=>{if(q("chat"),t&&L(!1),vt?.sessionId){lt(vt.sessionId);return}Wt({directoryOverride:Le})}}),s.jsx(kP,{}),s.jsx(wA,{value:Q,setValue:ne,showDeletionDialog:Je,setShowDeletionDialog:de,onConfirm:In}),s.jsx(NA,{value:G,setValue:le,onConfirm:ln}),s.jsx(jA,{value:oe,setValue:F,showDeletionDialog:Je,setShowDeletionDialog:de,onConfirm:jo})]})},LA=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Jr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");let n=e.replace(/\/+$/g,"");return n=n.replace(/\/+/g,"/"),n===""?e.startsWith("/")?"/":"":n},OA=()=>{const{t}=ut(),{runtime:e,files:n}=Pn(),r=Ir()??"",i=Jr(r.trim()),a=Bl(C=>C.searchFiles),l=Ie(C=>C.setSelectedMediaFilePath),c=Ie(C=>C.setCreativeRightSidebarTab),d=Ie(C=>C.setPreviewInfoOpen),[p,m]=o.useState(""),u=ho(p,200),h=o.useRef(null),[x,f]=o.useState([]),[v,y]=o.useState(!1),[g,w]=o.useState({}),[b,k]=o.useState(new Set),I=o.useRef(new Set),j=o.useRef(new Set),N=o.useCallback(async C=>{const S=Jr(C.trim());if(!S||I.current.has(S)||j.current.has(S))return;j.current=new Set(j.current),j.current.add(S),await(e.isDesktop?n.listDirectory(S,{respectGitignore:!0}).then(A=>A.entries.map(R=>({name:R.name,path:R.path,isDirectory:R.isDirectory}))):Zs.listLocalDirectory(S,{respectGitignore:!0})).then(A=>{const R=A.filter(B=>B.name&&!B.name.startsWith(".")).map(B=>{const V=B.name,$=Jr(B.path||"")||Jr(`${S}/${V}`),_=B.isDirectory?"directory":"file",X=_==="file"&&V.includes(".")?V.split(".").pop()?.toLowerCase():void 0;return{name:V,path:$,type:_,extension:X}}),z=LA(R);I.current=new Set(I.current),I.current.add(S),w(B=>({...B,[S]:z}))}).catch(()=>{w(A=>({...A,[S]:A[S]??[]}))}).finally(()=>{j.current=new Set(j.current),j.current.delete(S)})},[n,e.isDesktop]);o.useEffect(()=>{i&&(I.current=new Set,j.current=new Set,w({}),N(i))},[i]),o.useEffect(()=>{if(!i||b.size===0)return;const C=[...b].map(M=>Jr(M)).filter(M=>!!M&&M!==i&&M.startsWith(`${i}/`)&&!I.current.has(M)&&!j.current.has(M)).sort((M,A)=>M.split("/").length-A.split("/").length);if(C.length===0)return;let S=!1;return(async()=>{for(let M=0;M<C.length&&!S;M+=3){const A=C.slice(M,M+3);await Promise.all(A.map(R=>N(R)))}})(),()=>{S=!0}},[b,N,i]),o.useEffect(()=>{if(!r){f([]),y(!1);return}const C=u.trim();if(!C){f([]),y(!1);return}let S=!1;return y(!0),a(r,C,150,{includeHidden:!1,respectGitignore:!0,type:"file"}).then(M=>{if(S)return;const A=M.map(R=>({name:R.name,path:Jr(R.path),type:"file",extension:R.extension}));f(A)}).catch(()=>{S||f([])}).finally(()=>{S||y(!1)}),()=>{S=!0}},[r,u,a]);const D=o.useCallback(C=>{if(C.type==="directory"){const S=Jr(C.path);k(M=>{const A=new Set(M);return A.has(S)?A.delete(S):A.add(S),A}),I.current.has(S)||N(S);return}l(C.path),d(!1),c("preview")},[N,c,d,l]);function E(C,S){return(g[C]??[]).map(A=>{const R=A.type==="directory",z=R&&b.has(Jr(A.path));return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>D(A),className:ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors","hover:bg-interactive-hover/40 select-none"),title:A.path,children:[R?z?s.jsx(P,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(P,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(Zn,{filePath:A.path,extension:A.extension}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:A.name})]}),R&&z&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40",children:(()=>{const B=Jr(A.path),V=g[B];return I.current.has(B)&&(!V||V.length===0)?s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground italic",children:t("creative.mediaTree.empty")}):E(A.path)})()})]},A.path)})}const T=!!(i&&g[i]);return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[s.jsx("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:s.jsxs("div",{className:"relative min-w-0 flex-1",children:[s.jsx(P,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Bt,{ref:h,value:p,onChange:C=>m(C.target.value),placeholder:t("creative.mediaTree.searchPlaceholder"),className:"h-8 pl-8 pr-8 typography-meta"}),p.trim().length>0&&s.jsx("button",{type:"button","aria-label":"Clear search",className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{m(""),h.current?.focus()},children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]})}),s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"p-2",children:s.jsx("ul",{className:"flex flex-col",children:x.length>0?x.map(C=>s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>D(C),className:"flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors hover:bg-interactive-hover/40 select-none",title:C.path,children:[s.jsx(Zn,{filePath:C.path,extension:C.extension}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:C.name})]})},C.path)):v?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("creative.mediaTree.loading")]}):T?E(i):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground italic",children:t("creative.mediaTree.empty")})})})]})},$A=[{type:"all",icon:"stack",labelKey:"creative.preview.filter.all"},{type:"image",icon:"file-image",labelKey:"creative.preview.filter.image"},{type:"audio",icon:"music",labelKey:"creative.preview.filter.audio"},{type:"video",icon:"file-video",labelKey:"creative.preview.filter.video"},{type:"model",icon:"folder-3",labelKey:"creative.preview.filter.model"},{type:"document",icon:"file-text",labelKey:"creative.preview.filter.document"}],BA=["public","output"],zA={jpg:"image",jpeg:"image",png:"image",gif:"image",webp:"image",bmp:"image",tiff:"image",tif:"image",svg:"image",mp4:"video",webm:"video",mov:"video",avi:"video",mkv:"video",wmv:"video",flv:"video",m4v:"video",mp3:"audio",wav:"audio",ogg:"audio",flac:"audio",aac:"audio",wma:"audio",m4a:"audio",glb:"model",gltf:"model",obj:"model",stl:"model",fbx:"model",pdf:"document"},VA=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`,_A=t=>["mp4","webm","mov","avi","mkv","wmv","flv","m4v"].includes(t),UA=t=>["mp3","wav","ogg","flac","aac","wma","m4a"].includes(t),WA=t=>["jpg","jpeg","png","gif","webp","bmp","tiff","tif","svg"].includes(t),bf=t=>t.split(".").pop()?.toLowerCase()??"";function KA(t){const e=t.split("."),n=e.length>1?e.pop().toLowerCase():"",r=zA[n];return r?{mediaType:r,extension:n}:null}async function HA(t,e,n){const r=[],i=new Set,a=[];for(const l of e)a.push(`${t}/${l}`);for(;a.length>0;){const l=a.pop();try{const{entries:c}=await n(l,{respectGitignore:!0});for(const d of c){if(d.isDirectory){a.push(d.path);continue}const p=KA(d.name);p&&(i.has(d.path)||(i.add(d.path),r.push({name:d.name,path:d.path,mediaType:p.mediaType,extension:p.extension})))}}catch{}}return r}const GA=()=>{const t=at.c(46),{t:e}=ut(),n=Ie(qA),r=Ie(YA),i=Ie(QA),a=Ie(JA),l=Ir(),{files:c}=Pn(),[d,p]=o.useState(null),[m,u]=o.useState(!1),[h,x]=o.useState(!1);let f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=[],t[0]=f):f=t[0];const[v,y]=o.useState(f),[g,w]=o.useState(!1),[b,k]=o.useState("all");let I,j;t[1]!==l||t[2]!==c?(I=()=>{if(!l){y([]);return}let Q=!1;return w(!0),HA(l,BA,c.listDirectory.bind(c)).then(ne=>{Q||(y(ne),w(!1))}).catch(()=>{Q||w(!1)}),()=>{Q=!0}},j=[l,c],t[1]=l,t[2]=c,t[3]=I,t[4]=j):(I=t[3],j=t[4]),o.useEffect(I,j);let N,D;t[5]!==n?(N=()=>{if(!n){p(null),u(!1),x(!1);return}u(!0),x(!1),fetch(`/api/fs/stat?path=${encodeURIComponent(n)}`).then(XA).then(Q=>{const ne=bf(n);p({name:n.split("/").pop()??"",path:n,size:Q.size??0,type:Q.mime??ne.toUpperCase(),modified:Q.modified?new Date(Q.modified).toLocaleString():"-"}),u(!1)}).catch(()=>{x(!0),u(!1)})},D=[n],t[5]=n,t[6]=N,t[7]=D):(N=t[6],D=t[7]),o.useEffect(N,D);let E;e:{if(b==="all"){E=v;break e}let Q;if(t[8]!==b||t[9]!==v){let ne;t[11]!==b?(ne=G=>G.mediaType===b,t[11]=b,t[12]=ne):ne=t[12],Q=v.filter(ne),t[8]=b,t[9]=v,t[10]=Q}else Q=t[10];E=Q}const T=E;let C;t[13]!==a||t[14]!==r?(C=Q=>{r(Q.path),a(!1)},t[13]=a,t[14]=r,t[15]=C):C=t[15];const S=C;let M;t[16]!==b||t[17]!==e?(M=()=>s.jsx("div",{className:"flex gap-2 px-3 py-2 border-b border-border/40 overflow-x-auto shrink-0",children:$A.map(Q=>s.jsxs("button",{type:"button",onClick:()=>k(Q.type),className:ce("flex items-center gap-1.5 rounded-full px-2.5 py-1 typography-meta whitespace-nowrap transition-colors",b===Q.type?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40"),children:[s.jsx(P,{name:Q.icon,className:"h-3.5 w-3.5"}),e(Q.labelKey)]},Q.type))}),t[16]=b,t[17]=e,t[18]=M):M=t[18];const A=M;let R;t[19]!==T||t[20]!==S||t[21]!==g||t[22]!==n||t[23]!==e?(R=()=>g?s.jsx("div",{className:"flex items-center justify-center py-8",children:s.jsx(P,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}):T.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[s.jsx(P,{name:"file",className:"h-8 w-8 mb-2"}),s.jsx("p",{className:"typography-meta",children:e("creative.preview.noMediaFiles")})]}):s.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-1 p-2",children:T.map(Q=>s.jsxs("button",{type:"button",onClick:()=>S(Q),className:ce("flex flex-col items-center gap-1 rounded-md p-1.5 transition-colors text-left","hover:bg-interactive-hover/40 select-none",n===Q.path&&"bg-interactive-selection/50 ring-1 ring-primary/30"),title:Q.path,children:[s.jsx(Zn,{filePath:Q.path,extension:Q.extension,className:"h-8 w-8"}),s.jsx("span",{className:"w-full truncate text-center typography-small text-muted-foreground",children:Q.name})]},Q.path))}),t[19]=T,t[20]=S,t[21]=g,t[22]=n,t[23]=e,t[24]=R):R=t[24];const z=R;let B;t[25]!==h||t[26]!==d||t[27]!==i||t[28]!==m||t[29]!==n||t[30]!==a||t[31]!==r||t[32]!==e?(B=()=>{if(!n)return null;if(m)return s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx(P,{name:"loader-4",className:"h-6 w-6 animate-spin text-muted-foreground"})});if(h)return s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("p",{className:"typography-meta text-destructive",children:e("creative.preview.notFound")})});const Q=bf(n),ne=WA(Q),G=_A(Q),le=UA(Q);return s.jsxs("div",{className:"border-b border-border/40",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",children:[s.jsx("span",{className:"typography-small font-medium truncate flex-1",children:n.split("/").pop()}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",onClick:()=>a(!i),className:ce("flex h-6 w-6 items-center justify-center rounded-md transition-colors",i?"bg-interactive-selection/70 text-foreground":"text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40"),title:e("layout.rightSidebar.previewInfo"),children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:()=>r(null),className:"flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40 transition-colors",title:"Close preview",children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx("div",{className:"flex items-center justify-center p-3 max-h-[40vh] overflow-hidden",children:ne?s.jsx("img",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,alt:n.split("/").pop()??"",className:"max-h-full max-w-full object-contain rounded-md"}):G?s.jsx("video",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,controls:!0,className:"max-h-full max-w-full rounded-md"}):le?s.jsxs("div",{className:"flex flex-col items-center gap-3 w-full max-w-sm",children:[s.jsx(P,{name:"music",className:"h-10 w-10 text-muted-foreground"}),s.jsx("audio",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,controls:!0,className:"w-full"})]}):s.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground py-4",children:[s.jsx(P,{name:"file",className:"h-12 w-12"}),s.jsx("span",{className:"typography-meta",children:Q.toUpperCase()})]})}),i&&d&&s.jsxs("div",{className:"border-t border-border/40 bg-sidebar p-3 overflow-y-auto",children:[s.jsx("h4",{className:"typography-meta font-medium mb-2",children:e("creative.preview.info.title")}),s.jsxs("dl",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.name")}),s.jsx("dd",{className:"typography-meta text-right max-w-[60%] truncate",children:d.name})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.path")}),s.jsx("dd",{className:"typography-meta text-right max-w-[60%] truncate",title:d.path,children:d.path})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.size")}),s.jsx("dd",{className:"typography-meta text-right",children:VA(d.size)})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.type")}),s.jsx("dd",{className:"typography-meta text-right",children:d.type})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.modified")}),s.jsx("dd",{className:"typography-meta text-right",children:d.modified})]})]})]})]})},t[25]=h,t[26]=d,t[27]=i,t[28]=m,t[29]=n,t[30]=a,t[31]=r,t[32]=e,t[33]=B):B=t[33];const V=B;let $;t[34]!==A?($=A(),t[34]=A,t[35]=$):$=t[35];let _;t[36]!==V?(_=V(),t[36]=V,t[37]=_):_=t[37];let X;t[38]!==z?(X=z(),t[38]=z,t[39]=X):X=t[39];let O;t[40]!==_||t[41]!==X?(O=s.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[_,X]}),t[40]=_,t[41]=X,t[42]=O):O=t[42];let J;return t[43]!==$||t[44]!==O?(J=s.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:[$,O]}),t[43]=$,t[44]=O,t[45]=J):J=t[45],J};function qA(t){return t.selectedMediaFilePath}function YA(t){return t.setSelectedMediaFilePath}function QA(t){return t.isPreviewInfoOpen}function JA(t){return t.setPreviewInfoOpen}function XA(t){if(!t.ok)throw new Error("Not found");return t.json()}const ZA=()=>{const t=at.c(29),{t:e}=ut(),n=Ie(eD),r=Ie(tD);let i;t[0]!==e?(i=e("layout.rightSidebar.media"),t[0]=e,t[1]=i):i=t[1];let a;t[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(P,{name:"folder-3",className:"h-3.5 w-3.5"}),t[2]=a):a=t[2];let l;t[3]!==i?(l={id:"media",label:i,icon:a},t[3]=i,t[4]=l):l=t[4];let c;t[5]!==e?(c=e("layout.rightSidebar.preview"),t[5]=e,t[6]=c):c=t[6];let d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(P,{name:"eye",className:"h-3.5 w-3.5"}),t[7]=d):d=t[7];let p;t[8]!==c?(p={id:"preview",label:c,icon:d},t[8]=c,t[9]=p):p=t[9];let m;t[10]!==l||t[11]!==p?(m=[l,p],t[10]=l,t[11]=p,t[12]=m):m=t[12];const u=m;let h;t[13]!==r?(h=w=>r(w),t[13]=r,t[14]=h):h=t[14];let x;t[15]!==n||t[16]!==h||t[17]!==u?(x=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Cr,{items:u,activeId:n,onSelect:h,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[15]=n,t[16]=h,t[17]=u,t[18]=x):x=t[18];let f;t[19]!==n?(f=n==="media"&&s.jsx(OA,{}),t[19]=n,t[20]=f):f=t[20];let v;t[21]!==n?(v=n==="preview"&&s.jsx(GA,{}),t[21]=n,t[22]=v):v=t[22];let y;t[23]!==v||t[24]!==f?(y=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[f,v]}),t[23]=v,t[24]=f,t[25]=y):y=t[25];let g;return t[26]!==y||t[27]!==x?(g=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[x,y]}),t[26]=y,t[27]=x,t[28]=g):g=t[28],g};function eD(t){return t.creativeRightSidebarTab}function tD(t){return t.setCreativeRightSidebarTab}const sD=()=>{const t=at.c(13),[e,n]=Be.useState(!1);let r,i;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(gn())},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),Be.useEffect(r,i);let a;t[2]!==e?(a=async h=>e?await Vy(h):{success:!0,path:h},t[2]=e,t[3]=a):a=t[3];const l=a;let c;t[4]!==e?(c=async h=>e?await _y():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async h=>e?await Uy():{success:!0},t[6]=e,t[7]=p):p=t[7];const m=p;let u;return t[8]!==e||t[9]!==l||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:l,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=l,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},nD=t=>t==="/",Al=t=>t.replace(/\\/g,"/"),ru=t=>{if(!t||nD(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},ma=t=>t.endsWith("/"),rD=t=>{const e=t.trim();return!e||ma(e)?e:`${e}/`},iu=t=>t.lastIndexOf("/"),_g=t=>{if(ma(t))return t;const e=iu(t);return e<0?t:t.slice(0,e+1)},iD=t=>{const e=iu(t);return t.slice(e+1)},Ug=t=>{const e=ru(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=iu(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},aD=t=>ma(t)&&Ug(t)!==null,yf=(t,e)=>`${_g(t)}${e}/`,Zi=t=>{if(!t)return null;const e=ru(Al(t.trim()));return e?e.toLowerCase():null},vf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},oD=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,_c=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},lD=async()=>{try{const t=await fetch("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(t.ok){const e=await t.json();if(typeof e.home=="string"&&e.home.trim().length>0)return Al(e.home.trim())}}catch{}return Zs.getFilesystemHome().catch(()=>null)},cD=({open:t,onOpenChange:e})=>{const{t:n}=ut(),r=$s(Te=>Te.homeDirectory),i=As(Te=>Te.projects),a=As(Te=>Te.addProject),l=Qn(Te=>Te.profiles),c=Qn(Te=>Te.globalIdentity),d=Qn(Te=>Te.defaultGitIdentityId),p=Qn(Te=>Te.loadProfiles),m=Qn(Te=>Te.loadGlobalIdentity),u=Qn(Te=>Te.loadDefaultGitIdentityId),h=$l(),{isDesktop:x,requestAccess:f,startAccessing:v}=sD(),{isMobile:y}=rn(),g=o.useRef(null),w=o.useRef(null),b=o.useRef(new Map),[k,I]=o.useState(""),[j,N]=o.useState("~/"),[D,E]=o.useState([]),[T,C]=o.useState(!1),[S,M]=o.useState(!1),[A,R]=o.useState(0),[z,B]=o.useState(!1),[V,$]=o.useState(!1),[_,X]=o.useState(0),[O,J]=o.useState(!1),[Q,ne]=o.useState(""),[G,le]=o.useState(null),[oe,F]=o.useState(!1),[U,W]=o.useState(""),[te,K]=o.useState(!1),ae=k||r,ve=o.useMemo(()=>new Set(i.map(Te=>Zi(Te.path)).filter(Te=>!!Te)),[i]);o.useEffect(()=>{if(!t)return;N("~/"),E([]),R(0),B(!1),$(!1),J(!1),ne(""),le(null),F(!1),W(""),K(!1),requestAnimationFrame(()=>_c(g.current));let Te=!1;return(async()=>{const Ze=await lD();Te||(I(Ze||r||""),requestAnimationFrame(()=>_c(g.current)))})(),()=>{Te=!0}},[r,t]),o.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const re=o.useMemo(()=>{const Te=new Map;c&&Te.set(c.id,c);for(const We of l)Te.set(We.id,We);return Array.from(Te.values())},[l,c]);o.useEffect(()=>{if(!t||!O||G!==null)return;const Te=typeof d=="string"?d.trim():"";if(Te&&re.some(Ze=>Ze.id===Te)){le(Te);return}const We=re.find(Ze=>Ze.authType==="ssh"||Ze.sshKey);We&&le(We.id)},[re,d,O,t,G]);const be=o.useMemo(()=>re.find(Te=>Te.id===G)??null,[re,G]),pe=o.useMemo(()=>_g(j),[j]),ye=o.useMemo(()=>ma(j)?"":iD(j),[j]),ie=o.useMemo(()=>ae?vf(pe,ae):"",[pe,ae]);o.useEffect(()=>{if(!t||!ie){E([]);return}let Te=!1;return C(!0),M(!1),Zs.listLocalDirectory(ie).then(We=>{if(Te)return;M(!1);const Ze=We.filter(Qe=>Qe.isDirectory).map(Qe=>({name:Qe.name,path:Al(Qe.path)})).sort((Qe,he)=>Qe.name.localeCompare(he.name));E(Ze)}).catch(()=>{Te||(E([]),M(!0))}).finally(()=>{Te||C(!1)}),()=>{Te=!0}},[ie,t]);const ue=o.useMemo(()=>{const Te=ye.toLowerCase(),We=h||ye.startsWith(".");return D.filter(Ze=>Ze.name.toLowerCase().startsWith(Te)&&(We||!Ze.name.startsWith(".")))},[ye,D,h]),se=o.useMemo(()=>{const Te=[];aD(j)&&Te.push({type:"up",value:"browse:up",name:"..",path:Ug(j)});for(const We of ue){const Ze=Zi(We.path);Te.push({type:"directory",value:`browse:${We.path}`,name:We.name,path:We.path,disabled:!!(Ze&&ve.has(Ze))})}return Te},[ve,ue,j]);o.useEffect(()=>{R(0)},[j,se.length]);const Ne=o.useMemo(()=>ae?ru(vf(j,ae)):"",[ae,j]),Ce=Zi(Ne),je=!!(Ce&&ve.has(Ce)),we=o.useMemo(()=>ye?ue.find(Te=>Te.name===ye)??null:null,[ye,ue]),ke=!!(Ne&&!je&&(ma(j)&&S||!ma(j)&&ye.trim().length>0&&we===null)),xe=!z&&!V&&!je&&!!Ne,me=xe&&Q.trim().length>0,Me=se[A]??null,Ue=!!(Me&&(Me.type==="up"||Me.type==="directory"&&!Me.disabled)),q=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Se=n(je?"directoryExplorerDialog.actions.alreadyAdded":O?z?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":z?"directoryExplorerDialog.actions.adding":ke?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const Te=w.current;if(!Te)return;const We=()=>X(Math.ceil(Te.getBoundingClientRect().width));if(We(),typeof ResizeObserver>"u")return;const Ze=new ResizeObserver(We);return Ze.observe(Te),()=>Ze.disconnect()},[Se]),o.useLayoutEffect(()=>{const Te=g.current;Te&&(Te.scrollLeft=Te.scrollWidth)},[_,j]),o.useLayoutEffect(()=>{t&&_c(g.current)},[t]),o.useLayoutEffect(()=>{const Te=se[A];Te&&b.current.get(Te.value)?.scrollIntoView({block:"nearest"})},[A,se]);const $e=o.useCallback(()=>{e(!1)},[e]),Pe=o.useCallback(async Te=>{if(!Te||z)return;const We=Zi(Te);if(We&&ve.has(We))return;let Ze=Te;B(!0);try{const Qe=!O&&ke&&Zi(Te)===Zi(Ne);if(O){const Ge=Q.trim();if(!Ge){H.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ze=(await Zs.cloneRepository({remoteUrl:Ge,destinationPath:Te,gitIdentityId:be?.id??null})).path}else Qe&&await Zs.createDirectory(Te,{allowOutsideWorkspace:!0,initializeTemplate:!0});if(!a(Ze)){H.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}$e()}catch(Qe){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Qe instanceof Error?Qe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{B(!1)}},[a,ve,Q,$e,O,z,be?.id,ke,Ne,n]),fe=o.useCallback(Te=>{N(rD(Te))},[]),L=o.useCallback(Te=>{N(yf(j,Te.name))},[j]),Z=o.useCallback(Te=>{if(Te){if(Te.type==="up"){Te.path&&fe(Te.path);return}Te.disabled||L(Te)}},[fe,L]),Y=o.useCallback(async()=>{if(!(!x||V)){$(!0);try{const Te=await f(Ne);if(!Te.success||!Te.path){Te.error&&Te.error!=="Directory selection cancelled"&&H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te.error});return}const We=await v(Te.path);if(!We.success){H.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:We.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Pe(Te.path)}catch(Te){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te instanceof Error?Te.message:n("directoryExplorerDialog.toast.unknownError")})}finally{$(!1)}}},[Pe,x,V,f,v,n,Ne]),Ee=o.useCallback(Te=>{if(Te.key==="ArrowDown"){Te.preventDefault(),R(We=>Math.min(se.length-1,We+1));return}if(Te.key==="ArrowUp"){Te.preventDefault(),R(We=>Math.max(0,We-1));return}if(Te.key==="Enter"){if(Te.preventDefault(),oD(Te)){Pe(Ne);return}Ue&&Z(Me);return}Te.key==="Backspace"&&j===""&&(Te.preventDefault(),$e())},[Z,Pe,$e,Ue,Me,j,se.length,Ne]),Ae=o.useCallback(async()=>{const Te=U.trim();if(!(!Te||te)){K(!0);try{const We=`${ie}${Te}`;await Zs.createDirectory(We,{allowOutsideWorkspace:!0,initializeTemplate:!0}),H.success(n("directoryExplorerDialog.toast.folderCreated")),N(yf(j,Te)),F(!1),W("")}catch(We){H.error(n("directoryExplorerDialog.toast.failedToCreateFolder"),{description:We instanceof Error?We.message:n("directoryExplorerDialog.toast.unknownError")})}finally{K(!1)}}},[U,te,ie,j,n]),Je=o.useCallback(Te=>{Te.stopPropagation(),Te.key==="Enter"?(Te.preventDefault(),Ae()):Te.key==="Escape"&&(Te.preventDefault(),F(!1),W(""))},[Ae]),de=s.jsxs("button",{type:"button",onClick:()=>Qo(!h),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[h?s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),ze=s.jsxs("div",{className:"px-2.5 py-1.5",children:[O?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Bt,{value:Q,onChange:Te=>ne(Te.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx($h,{activeProfile:be,identities:re,onSelect:Te=>le(Te.id),isApplying:z,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(P,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(Bt,{ref:g,value:j,onChange:Te=>N(Al(Te.target.value)),onKeyDown:Ee,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!y&&_>0?{paddingRight:`${_+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),y?null:s.jsx(ge,{ref:w,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:O?!me:!xe,onMouseDown:Te=>Te.preventDefault(),onClick:()=>{Pe(Ne)},title:Se,children:Se})]})]}),rt=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsxs("div",{className:"flex items-center justify-between px-2 pb-1 pt-0.5",children:[s.jsx("div",{className:"typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),!O&&!oe&&s.jsxs("button",{type:"button",onClick:()=>{F(!0),W(""),K(!1)},className:"flex items-center gap-1 rounded px-1.5 py-0.5 typography-meta text-primary hover:bg-primary/10 transition-colors",children:[s.jsx(P,{name:"folder-add",className:"h-3.5 w-3.5"}),s.jsx("span",{children:n("directoryExplorerDialog.actions.newFolder")})]})]}),T?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):se.length===0&&!oe?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):s.jsxs("div",{className:"space-y-0.5",children:[oe&&s.jsxs("div",{className:"flex w-full items-center gap-2 rounded-lg px-2 py-1 border border-primary/40 bg-interactive-hover/30",children:[s.jsx(P,{name:"folder-add",className:"h-4 w-4 flex-shrink-0 text-primary"}),s.jsx("input",{type:"text",value:U,onChange:Te=>W(Te.target.value),onKeyDown:Je,placeholder:n("directoryExplorerDialog.newFolder.placeholder"),className:"min-w-0 flex-1 bg-transparent border-none outline-none font-mono typography-ui-label text-foreground placeholder:text-muted-foreground/60",autoFocus:!0,disabled:te}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",disabled:te||!U.trim(),onClick:Ae,title:n("directoryExplorerDialog.newFolder.confirm"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-primary",children:s.jsx(P,{name:"check",className:"h-4 w-4"})}),s.jsx("button",{type:"button",disabled:te,onClick:()=>{F(!1),W("")},title:n("directoryExplorerDialog.newFolder.cancel"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-muted-foreground",children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]})]}),se.map((Te,We)=>{const Ze=We===A;return s.jsxs("button",{ref:Qe=>{Qe?b.current.set(Te.value,Qe):b.current.delete(Te.value)},type:"button",disabled:Te.type==="directory"&&Te.disabled,onMouseEnter:()=>R(We),onMouseDown:Qe=>Qe.preventDefault(),onClick:()=>Z(Te),className:ce("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ze&&"bg-interactive-selection text-interactive-selection-foreground",!Ze&&"hover:bg-interactive-hover/50",Te.type==="directory"&&Te.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Te.type==="up"?s.jsx(P,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(P,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Te.name})}),Te.type==="directory"&&Te.disabled?s.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):null]},Te.value)})]})]})}),Re=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[ze,rt]}),Xe=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(P,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(P,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(P,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:q}),s.jsx(P,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),qe=()=>s.jsxs(s.Fragment,{children:[y?null:Xe,s.jsxs("div",{className:ce("flex w-full flex-row justify-end gap-2 sm:w-auto",y&&"justify-stretch"),children:[x?s.jsx(ge,{variant:"ghost",size:"xs",onClick:Y,disabled:z||V||O,children:n(V?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(ge,{variant:"ghost",size:"xs",onClick:()=>J(Te=>!Te),disabled:z||V,className:ce(y&&"flex-1"),children:n(O?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),y?s.jsx(ge,{size:"xs",onClick:()=>{Pe(Ne)},disabled:O?!me:!xe,className:"flex-1",children:Se}):null]})]});return y?s.jsx($r,{open:t,onClose:$e,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:qe()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:de}),Re]})}):s.jsx(hs,{open:t,onOpenChange:e,children:s.jsxs(fs,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(bs,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(gs,{children:n("directoryExplorerDialog.title")}),s.jsx(Is,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),de]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Re}),s.jsx(Vs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:qe()})]})})},Ci=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Fr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},dD=()=>{const{t}=ut(),[e,n]=o.useState(!1),[r,i]=o.useState(!1),[a,l]=o.useState(null),[c,d]=o.useState([]),[p,m]=o.useState(!1),[u,h]=o.useState(!1),[x,f]=o.useState(!1),[v,y]=o.useState(!1),[g,w]=o.useState(new Set),b=Ot(se=>se.getWorktreeMetadata),k=Ot(se=>se.newSessionDraft),I=Ot(se=>se.setNewSessionDraftTarget),j=Ot(se=>se.setDraftBootstrapPendingDirectory),N=Wy,D=Gy,E=Ot(se=>se.deleteSessions),T=Ot(se=>se.archiveSessions),C=Ie(se=>se.showDeletionDialog),S=Ie(se=>se.setShowDeletionDialog),M=$s(se=>se.currentDirectory),A=$s(se=>se.homeDirectory),R=$s(se=>se.isHomeReady),z=As(se=>se.projects),B=As(se=>se.activeProjectId),{isMobile:V,isTablet:$,hasTouchInput:_}=rn(),X=V||$||_,O=o.useMemo(()=>{const Ne=(B?z.find(Ce=>Ce.id===B)??null:null)?.path??M;return Fr(Ne)},[B,M,z]),J=o.useCallback(se=>{const Ce=Fr(se.projectDirectory)||O;return{id:(z.find(we=>Fr(we.path)===Ce)??null)?.id??`path:${Ce}`,path:Ce}},[O,z]),Q=v&&g.size>0,ne=o.useMemo(()=>{const se=a?.worktree;return se&&typeof se.branch=="string"&&se.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Ne})=>typeof Ne.branch=="string"&&Ne.branch.trim().length>0)},[a?.worktree,c]),G=a?.mode==="worktree",le=G,oe=x||!G||!ne,F=x||!G;o.useEffect(()=>{r||!R||z.length>0||(i(!0),n(!0))},[r,R,z.length]);const U=o.useCallback(se=>{l({sessions:se.sessions,dateLabel:se.dateLabel,mode:se.mode??"session",worktree:se.worktree??null})},[]),W=o.useCallback(()=>{l(null),d([]),m(!1),h(!1),f(!1),y(!1),w(new Set)},[]),te=o.useCallback(async se=>{if(se.sessions.length===0)return;if(se.sessions.length===1){const we=se.sessions[0];await N(we.id)?H.success(t("sessions.sidebar.session.delete.success")):H.error(t("sessions.sidebar.session.delete.error"));return}const Ne=se.sessions.map(we=>we.id),{deletedIds:Ce,failedIds:je}=await E(Ne);if(Ce.length>0){const we=je.length>0?je.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:je.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:je.length}):se.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:se.dateLabel}):void 0;H.success(Ce.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ce.length}),{description:Ci(we)})}je.length>0&&H.error(je.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:je.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:je.length}),{description:Ci(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[N,E,t]);o.useEffect(()=>Sr.onDeleteRequest(se=>{if(!C&&(se.mode??"session")==="session"){te(se);return}U(se)}),[U,C,te]),o.useEffect(()=>Sr.onDirectoryRequest(()=>{n(!0)}),[]),o.useEffect(()=>{if(!a){d([]),m(!1),h(!1),y(!1),w(new Set);return}const se=a.sessions.map(je=>{const we=b(je.id);return we?{session:je,metadata:we}:null}).filter(je=>!!je);d(se),m(!1),y(!1),w(new Set);const Ne=new Map;if(a.worktree?.path&&Ne.set(Fr(a.worktree.path),a.worktree),se.forEach(({metadata:je})=>{je.path&&Ne.set(Fr(je.path),je)}),Ne.size===0){y(!0);return}let Ce=!1;return(async()=>{const je=new Map,we=new Set;await Promise.all(Array.from(Ne.entries()).map(async([ke,xe])=>{try{const me=await Ky(xe.path);je.set(ke,me),me?.isDirty&&we.add(ke)}catch{xe.status&&(je.set(ke,xe.status),xe.status.isDirty&&we.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!Ce&&(w(we),y(!0),l(ke=>{if(!ke?.worktree?.path)return ke;const xe=Fr(ke.worktree.path),me=je.get(xe);if(!me)return ke;const Me=ke.worktree.status;return Me?.isDirty===me.isDirty&&Me?.ahead===me.ahead&&Me?.behind===me.behind&&Me?.upstream===me.upstream?ke:{...ke,worktree:{...ke.worktree,status:me}}}),d(ke=>ke.map(xe=>{const me=Fr(xe.metadata.path),Me=je.get(me);return Me?{session:xe.session,metadata:{...xe.metadata,status:Me}}:xe})))})(),()=>{Ce=!0}},[a,b]),o.useEffect(()=>{ne||m(!1)},[ne]);const K=o.useCallback(async(se,Ne)=>{const Ce=p&&ne,je=J(se),we=Fr(se.path),ke=Fr(je.path);try{await Hy(je,se,{deleteRemoteBranch:Ce,deleteLocalBranch:Ne});const xe=Fr(k?.directoryOverride);return k?.open&&we&&xe===we&&ke&&(j(null),I({projectId:je.id,directoryOverride:ke},{force:!0})),Fr(M)===we&&ke&&$s.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(xe){return H.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Ci(xe instanceof Error?xe.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ne,M,p,J,k?.directoryOverride,k?.open,j,I,t]),ae=o.useCallback(async()=>{if(a){f(!0);try{const se=le,Ne=se&&p,Ce=se&&u;if(a.sessions.length===0&&G&&a.worktree){if(!await K(a.worktree,Ce)){W();return}const ke=t(p&&ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");H.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Ci(ke)}),W();return}if(a.sessions.length===1){const je=a.sessions[0];if(!(G?await D(je.id):await N(je.id,{archiveWorktree:!1,deleteRemoteBranch:Ne,deleteLocalBranch:Ce}))){H.error(t(G?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),f(!1);return}const ke=!G&&se?t(Ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;H.success(t(G?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Ci(ke),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const je=a.sessions.map(xe=>xe.id);let we=[],ke=[];if(G){const xe=await T(je);we=xe.archivedIds,ke=xe.failedIds}else{const xe=await E(je);we=xe.deletedIds,ke=xe.failedIds}if(G&&a.worktree&&ke.length===0&&await K(a.worktree,Ce),we.length>0){const xe=!G&&se?t(Ne?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Me=[ke.length>0?G?ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:ke.length}):ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ke.length}):a.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:a.dateLabel}):void 0,xe].filter(Boolean).join(" ");H.success(G?we.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:we.length}):we.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:we.length}),{description:Ci(Me||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ke.length>0&&(H.error(G?ke.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:ke.length}):ke.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ke.length}),{description:Ci(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),we.length===0)){f(!1);return}}G&&a.sessions.length===1&&a.worktree&&await K(a.worktree,Ce),W()}finally{f(!1)}}},[a,p,u,N,E,D,T,W,le,G,ne,K,t]),ve=a?.worktree??c[0]?.metadata??null,re=a?a.mode==="worktree"?a.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):a.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:a.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:a.sessions.length}):a.sessions.length===1?a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:a.sessions.length,dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:a.sessions.length}):"",be=a?s.jsxs("div",{className:ce(G?"space-y-3":"space-y-2"),children:[a.sessions.length>0&&s.jsxs("div",{className:ce(G?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[G&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:a.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:a.sessions.length})]}),s.jsxs("ul",{className:ce(G?"mt-2 space-y-1":"space-y-0.5"),children:[a.sessions.slice(0,5).map(se=>s.jsxs("li",{className:ce(G?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:ce(!G&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:se.title||t("sessions.sidebar.session.untitled")})]},se.id)),a.sessions.length>5&&s.jsx("li",{className:ce(G?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:a.sessions.length-5})})]})]}),G?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),ve?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ve.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ve?ro(ve.path,A):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Q&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,pe=G?ne?s.jsxs("button",{type:"button",onClick:()=>{oe||m(se=>!se)},disabled:oe,className:ce("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",oe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,ye=G?s.jsxs("button",{type:"button",onClick:()=>{F||h(se=>!se)},disabled:F,className:ce("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",F?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ie=G?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[ye,pe]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"ghost",onClick:W,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{variant:"destructive",onClick:ae,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>S(!C),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!C,children:[C?s.jsx(P,{name:"checkbox-blank",className:"size-4"}):s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"ghost",onClick:W,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{variant:"destructive",onClick:ae,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ue=G?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[X?s.jsx($r,{open:!!a,onClose:()=>{x||W()},title:ue,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ie}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[re&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:re}),be]})}):s.jsx(hs,{open:!!a,onOpenChange:se=>{if(!se){if(x)return;W()}},children:s.jsxs(fs,{className:ce(G?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(bs,{children:[s.jsxs(gs,{className:ce(G&&"flex items-center gap-2"),children:[G&&s.jsx(P,{name:"delete-bin",className:"h-5 w-5"}),ue]}),re&&s.jsx(Is,{children:re})]}),s.jsx("div",{className:ce(G&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:be}),s.jsx(Vs,{className:"mt-2 gap-2 pt-1 pb-1",children:ie})]})}),s.jsx(cD,{open:e,onOpenChange:n})]})},Cd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),uD=(t,e)=>{const n=Cd(t),r=Cd(e);return`${n}-${r}`.substring(0,60)},wf=(t,e)=>`${t}/${e}`,mD=()=>{const t=As.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(i=>i.id===e);if(n?.path)return{id:n.id,path:n.path};const r=$s.getState().currentDirectory??null;if(r&&r.trim().length>0){const i=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${i}`,path:i}}return null},Uc=gr()(Na(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:i,agent:a,files:l,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(i.length<1)return t({error:"Select at least 1 model"}),null;if(i.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=mD();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path,u=await nh(p)&&e.isolateRuns!==!1,h=Cd(n),x=u?await fo(p):void 0,f=u?await qy(p):null,v=[],y=c?.filter(N=>N.trim().length>0)??[],g=new Map;for(const N of i){const D=`${N.providerID}:${N.modelID}`;g.set(D,(g.get(D)||0)+1)}const w=new Map;for(const N of i){const D=`${N.providerID}:${N.modelID}`,E=g.get(D)||1,T=(w.get(D)||0)+1;w.set(D,T);const C=uD(N.providerID,N.modelID),S=E>1?wf(h,`${C}/${T}`):wf(h,C);try{const M=E>1?`${h}/${N.providerID}/${N.modelID}/${T}`:`${h}/${N.providerID}/${N.modelID}`;if(!u){const B=await Zs.withDirectory(p,()=>Zs.createSession({title:M}));v.push({sessionId:B.id,worktreePath:p,providerID:N.providerID,modelID:N.modelID,variant:N.variant});continue}const A=await Yy(d,{preferredName:S,mode:"new",branchName:S,worktreeName:S,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:y},{resolvedRootTrackingRemote:f}),R={...A,createdFromBranch:x,kind:"standard"},z=await Zs.withDirectory(A.path,()=>Zs.createSession({title:M}));Ot.getState().setWorktreeMetadata(z.id,R),v.push({sessionId:z.id,worktreePath:A.path,providerID:N.providerID,modelID:N.modelID,variant:N.variant})}catch(M){console.warn("[MultiRun] Failed to create session:",M)}}const b=c?.filter(N=>N.trim().length>0)??[];b.length>0&&rh(d,b).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const k=v.map(N=>N.sessionId),I=v[0]?.sessionId??null;if(k.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=l?.map(N=>({type:"file",mime:N.mime,filename:N.filename,url:N.url}));return(async()=>{try{await Promise.allSettled(v.map(async N=>{try{await Zs.withDirectory(N.worktreePath,()=>Zs.sendMessage({id:N.sessionId,providerID:N.providerID,modelID:N.modelID,variant:N.variant,text:r,agent:a,files:j}))}catch(D){console.warn("[MultiRun] Failed to start run:",D)}}))}catch(N){console.warn("[MultiRun] Failed to start runs:",N)}})(),t({isLoading:!1}),{groupSlug:h,sessionIds:k,firstSessionId:I}}catch(d){return t({error:d instanceof Error?d.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),pD="oc:lastWorktreeSourceBranch";function Wg(t){const e=at.c(30),{git:n}=Pn(),r=Rd(t),i=Ed(t),a=Fd(t),l=ch(t),c=tn(bD),d=tn(xD);let p,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==i||e[4]!==a?(p=()=>{!t||!n||i!==null||a||d(t,n,{silent:!0})},m=[t,n,d,i,a],e[0]=t,e[1]=d,e[2]=n,e[3]=i,e[4]=a,e[5]=p,e[6]=m):(p=e[5],m=e[6]),o.useEffect(p,m);let u;e[7]!==r?.all||e[8]!==t||e[9]!==c||e[10]!==n||e[11]!==i?(u=()=>{!t||!n||i===!0&&(r?.all||c(t,n))},e[7]=r?.all,e[8]=t,e[9]=c,e[10]=n,e[11]=i,e[12]=u):u=e[12];const h=r?.all;let x;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==i||e[17]!==h?(x=[t,n,i,h,c],e[13]=t,e[14]=c,e[15]=n,e[16]=i,e[17]=h,e[18]=x):x=e[18],o.useEffect(u,x);const f=a||i===!0&&l;let v;e:{if(!r?.all){let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[19]=N):N=e[19],v=N;break e}let j;e[20]!==r.all?(j=r.all.filter(gD).sort(),e[20]=r.all,e[21]=j):j=e[21],v=j}const y=v;let g;e:{if(!r?.all){let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[22]=N):N=e[22],g=N;break e}let j;e[23]!==r.all?(j=r.all.filter(hD).map(fD).sort(),e[23]=r.all,e[24]=j):j=e[24],g=j}const w=g;let b;e:{if(!t){b=null;break e}if(i!==null){b=i;break e}if(f){b=null;break e}b=r?.all?!0:null}const k=b;let I;return e[25]!==k||e[26]!==f||e[27]!==y||e[28]!==w?(I={localBranches:y,remoteBranches:w,isLoading:f,isGitRepository:k},e[25]=k,e[26]=f,e[27]=y,e[28]=w,e[29]=I):I=e[29],I}function fD(t){return t.replace(/^remotes\//,"")}function hD(t){return t.startsWith("remotes/")}function gD(t){return!t.startsWith("remotes/")}function xD(t){return t.fetchStatus}function bD(t){return t.fetchBranches}const yD=({directory:t,value:e,onChange:n,className:r,disabled:i,id:a})=>{const{t:l}=ut(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=Wg(t),u=o.useMemo(()=>[...c,...d.map(x=>`remotes/${x}`)],[c,d]);o.useEffect(()=>{if(i||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const f=t?await fo(t).catch(()=>null):null,v=localStorage.getItem(pD);v&&u.includes(v)?n(v):f&&u.includes(f)?n(f):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,i,p,n,e]);const h=i||!m||p;return s.jsxs("div",{children:[s.jsxs(is,{value:e,onValueChange:n,disabled:h,children:[s.jsx(as,{id:a,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(us,{placeholder:l(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(os,{className:"max-h-[280px] max-w-[320px]",children:p?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.loadingBranches")}):c.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(Xc,{children:[s.jsx(Vu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),c.map(x=>s.jsx(Ft,{value:x,className:"whitespace-normal break-all",children:x},x))]}),c.length>0&&d.length>0&&s.jsx(Qy,{}),d.length>0&&s.jsxs(Xc,{children:[s.jsx(Vu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),d.map(x=>s.jsx(Ft,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:l("multiRun.branchSelector.status.notInGitRepository")})]})},vD=10*1024*1024,Wc=5,Ko=t=>{const e=at.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let i;return e[1]!==n?(i=s.jsxs(Pt,{children:[r,s.jsx(Dt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=i):i=e[2],i},ea=t=>{const e=at.c(9),{htmlFor:n,required:r,children:i,info:a}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let c;e[2]!==i||e[3]!==n||e[4]!==l?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,l]}),e[2]=i,e[3]=n,e[4]=l,e[5]=c):c=e[5];const d=a&&a;let p;return e[6]!==c||e[7]!==d?(p=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8],p},wD=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:i}=ut(),[a,l]=o.useState(""),[c,d]=o.useState(()=>t??""),[p,m]=o.useState([]),[u,h]=o.useState(""),[x,f]=o.useState([]),[v,y]=o.useState(!1),[g,w]=o.useState([]),[b,k]=o.useState(!1),[I,j]=o.useState(!1),[N,D]=o.useState(!0),[E,T]=o.useState(!1),[C,S]=o.useState(""),[M,A]=o.useState(!1),[R,z]=o.useState(""),B=o.useRef(null),V=o.useRef(null),$=o.useRef(null),_=o.useRef(null),X=$s(Re=>Re.currentDirectory??null),O=$s(Re=>Re.homeDirectory??null),J=o.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Re=="string"&&Re.trim().length>0?Re.trim():null},[]),Q=As(Re=>Re.activeProjectId),ne=As(Re=>Re.setActiveProjectIdOnly),G=As(Re=>Re.projects),[le,oe]=o.useState(()=>Q??null);o.useEffect(()=>{if(Q){oe(Q);return}!le&&G.length>0&&oe(G[0].id)},[Q,G,le]);const F=o.useMemo(()=>le?G.find(Re=>Re.id===le)??null:null,[G,le]),U=F?.path??X,W=o.useCallback(Re=>{oe(Re),Re!==Q&&ne(Re)},[Q,ne]),{currentTheme:te}=Ar(),K=o.useCallback(Re=>{const Xe=Re.label?.trim()||Vi(Re.path,O),qe=xo({id:Re.id,iconImage:Re.iconImage??null},{themeVariant:te.metadata.variant,iconColor:te.colors.surface.foreground}),Te=Re.icon?Vl[Re.icon]:null,We=Re.color?bo[Re.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[qe?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Re.iconBackground?{backgroundColor:Re.iconBackground}:void 0,children:s.jsx("img",{src:qe,alt:"",className:"h-full w-full object-contain",draggable:!1})}):Te?s.jsx(P,{name:Te,className:"h-3.5 w-3.5 shrink-0",style:We?{color:We}:void 0}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:We?{color:We}:void 0}),s.jsx("span",{className:"truncate",children:Xe})]})},[O,te.metadata.variant,te.colors.surface.foreground]),ae=o.useMemo(()=>{if(F?.path)return{id:F.id,path:F.path};const Re=X??J;return Re?{id:`path:${Re}`,path:Re}:null},[F,X,J]),[ve,re]=o.useState(()=>typeof window>"u"?!1:gn()),be=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),pe=El();o.useEffect(()=>{typeof window>"u"||re(gn())},[]);const ye=o.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__APP_MACOS_MAJOR__;if(typeof Re=="number"&&Number.isFinite(Re)&&Re>0)return Re;if(typeof navigator>"u")return null;const Xe=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Xe)return null;const qe=Number.parseInt(Xe[1],10),Te=Number.parseInt(Xe[2],10);return Number.isNaN(qe)?null:qe===10?Te:qe},[]),ie=o.useMemo(()=>ve&&be||pe?"pl-[5.5rem]":"pl-3",[ve,be,pe]),ue=o.useMemo(()=>!ve||!be||ye===null?"":ye>=26?"h-12":ye<=15?"h-14":"",[ve,be,ye]),se=o.useCallback(async Re=>{Re.target.closest("button, a, input, select, textarea")||Re.button===0&&ve&&await fh()},[ve]);o.useEffect(()=>{if(!n)return;const Re=Xe=>{Xe.key==="Escape"&&(Xe.preventDefault(),Xe.stopPropagation(),n())};return window.addEventListener("keydown",Re,!0),()=>window.removeEventListener("keydown",Re,!0)},[n]);const[Ne,Ce]=o.useState(""),{isLoading:je,isGitRepository:we}=Wg(U),ke=o.useRef(!1),xe=we===!0,me=xe&&N;o.useEffect(()=>{if(we===!1){ke.current=!0,D(!1);return}we===!0&&ke.current&&(ke.current=!1,D(!0))},[we]);const Me=Uc(Re=>Re.createMultiRun),Ue=Uc(Re=>Re.error),q=Uc(Re=>Re.clearError);o.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Re=>Re.trim().length>0?Re:t)},[t]),o.useEffect(()=>{if(!ae)return;let Re=!1;return j(!0),(async()=>{try{const Xe=await zd(ae);Re||w(Xe)}catch{}finally{Re||j(!1)}})(),()=>{Re=!0}},[ae]);const Se=Re=>{p.length>=Wc||(m(Xe=>[...Xe,Re]),q())},$e=Re=>{m(Xe=>Xe.filter((qe,Te)=>Te!==Re)),q()},Pe=o.useCallback((Re,Xe)=>{m(qe=>qe.map((Te,We)=>We===Re?Xe:Te))},[]),fe=async Re=>{const Xe=Re.target.files;if(!Xe)return;let qe=0;for(let Te=0;Te<Xe.length;Te++){const We=Xe[Te];if(We.size>vD){H.error(i("multirun.launcher.toast.fileTooLarge",{fileName:We.name}));continue}try{const Ze=await new Promise((he,Ge)=>{const Ve=new FileReader;Ve.onload=()=>he(Ve.result),Ve.onerror=Ge,Ve.readAsDataURL(We)}),Qe={id:Il(),filename:We.name,mimeType:We.type||"application/octet-stream",size:We.size,dataUrl:Ze};f(he=>[...he,Qe]),qe++}catch(Ze){console.error("File attach failed",Ze),H.error(i("multirun.launcher.toast.attachFailed",{fileName:We.name}))}}qe>0&&H.success(qe===1?i("multirun.launcher.toast.attachedSingle",{count:qe}):i("multirun.launcher.toast.attachedPlural",{count:qe})),B.current&&(B.current.value="")},L=Re=>{f(Xe=>Xe.filter(qe=>qe.id!==Re))},Z=o.useCallback((Re,Xe)=>{if(Re.startsWith("/")){const We=Re.indexOf(" "),Ze=Re.indexOf(`
|
|
223
|
+
Now write the final fused answer.`,synthetic:!0}]}))}catch(V){console.error("[MultiRunFusion] Failed to start fusion",V),H.error(r("multirun.fusion.toast.failed"))}finally{D(!1)}}};return s.jsx(hs,{open:e,onOpenChange:n,children:s.jsxs(fs,{className:"max-w-xl overflow-visible",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:r("multirun.fusion.title")}),s.jsx(Is,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx($g,{selectedModels:v,onAdd:R,onUpdate:(V,$)=>R($),onRemove:()=>{y([]),h(""),f(""),w("")},maxModels:1,addButtonLabel:z,showChips:!1,addButtonClassName:"h-8 w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:u?s.jsx(vn,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(is,{value:g||"__default__",onValueChange:V=>w(V==="__default__"?"":V),children:[s.jsxs(as,{size:"lg",className:"h-8 w-fit rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 typography-meta font-medium text-foreground px-3 py-1.5",children:[s.jsx(P,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(us,{children:V=>V==="__default__"?r("multirun.modelMultiSelect.variant.default"):V})]}),s.jsxs(os,{fitContent:!0,portalToBody:!0,children:[s.jsx(Ft,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map(V=>s.jsx(Ft,{value:V,children:V},V))]})]}):null,s.jsx(Lg,{value:b,onChange:k,portalToBody:!0,className:"h-8 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] px-3 py-1.5"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:I.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:I.map(V=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(vn,{providerId:ll(V.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.session.title||V.session.id}),s.jsx("button",{type:"button",onClick:()=>j($=>$.filter(_=>_.session.id!==V.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]},V.session.id))})]}),s.jsxs(Vs,{children:[s.jsx(ge,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(ge,{onClick:B,disabled:!A,children:r(N?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function xA(t){const e=at.c(7);let n,r,i,a,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),i=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),a=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=i,e[3]=a,e[4]=l):(n=e[0],r=e[1],i=e[2],a=e[3],l=e[4]);let c;return e[5]!==t?(c=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,i,a,l]}),e[5]=t,e[6]=c):c=e[6],c}const pf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),Ii=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Ii(n,e))return!0;return!1},Sd=(t,e,n,r)=>{if(!e)return!1;if(`${n}:${r?"archived":"active"}:${t.session.id}`===e)return!0;for(const a of t.children)if(Sd(a,e,n,r))return!0;return!1},bA=(t,e)=>{const n=t.node.session,r=e.node.session,i=n.id,a=r.id;if(i!==a||t.node.session!==e.node.session||pf(t.node)!==pf(e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket)return!1;if(t.currentSessionId!==e.currentSessionId){const m=Ii(t.node,t.currentSessionId),u=Ii(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(i)!==e.pinnedSessionIds.has(a))return!1;{const m=t.renderContext??"project",u=e.renderContext??"project",h=t.archivedBucket??!1,x=e.archivedBucket??!1,f=`${m}:${h?"archived":"active"}:${i}`,v=`${u}:${x?"archived":"active"}:${a}`;if(t.expandedParents.has(f)!==e.expandedParents.has(v))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=Ii(t.node,t.editingId),u=Ii(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=Ii(t.node,t.editingId),u=Ii(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===i!=(e.copiedSessionId===a))return!1;const l=Sd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=Sd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(l!==c)return!1;const d=xs(n.directory??null)??xs(t.groupDirectory??null),p=xs(r.directory??null)??xs(e.groupDirectory??null);return!(d!==p||(d?t.directoryStatus.get(d):null)!==(p?e.directoryStatus.get(p):null)||(t.secondaryMeta?.projectLabel??null)!==(e.secondaryMeta?.projectLabel??null)||(t.secondaryMeta?.branchLabel??null)!==(e.secondaryMeta?.branchLabel??null)||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||(t.renderContext??"project")!==(e.renderContext??"project")||t.renamingFolderId!==e.renamingFolderId)};function yA(t){const{t:e}=ut(),{node:n,depth:r=0,groupDirectory:i,projectId:a,archivedBucket:l=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,notifyOnSubtasks:x,editingId:f,setEditingId:v,editTitle:y,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:b,toggleParent:k,handleSessionSelect:I,handleSessionDoubleClick:j,togglePinnedSession:N,handleShareSession:D,copiedSessionId:E,handleCopyShareUrl:T,handleUnshareSession:C,openSidebarMenuKey:S,setOpenSidebarMenuKey:M,renamingFolderId:A,getFoldersForScope:R,getSessionFolderId:z,removeSessionFromFolder:B,addSessionToFolder:V,createFolderAndStartRename:$,openContextPanelTab:_,handleDeleteSession:X,mobileVariant:O,alwaysShowActions:J,renderSessionNode:Q,secondaryMeta:ne,renderContext:G="project"}=t,le=!!ne?.projectLabel,oe=!!ne?.branchLabel,U=Mi(bt=>bt.displayMode)==="minimal",W=o.useMemo(()=>mn(),[]),te=o.useMemo(()=>Dd(),[]),K=W?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",ae=W?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",ve=!l&&!O,re=U?W?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":W?ve?"group-hover:pr-12":"group-hover:pr-5":ve?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",be=ve?"pr-13":"pr-7",pe=o.useRef(!1),[ye,ie]=o.useState(!1),ue=n.session,Ne=Uf(ue.id)??ue,Ce=xs(ue.directory??null)??xs(i??null),je=Py(Ce??void 0),we=_d(),ke=ur(bt=>bt.enabled),xe=ur(o.useCallback(bt=>bt.selectedIds.has(ue.id),[ue.id])),me=ur(bt=>bt.toggleSelected),Me=ur(bt=>bt.setRange),Ue=o.useCallback(bt=>{const Mt=[],At=ee=>{ee.children.forEach(ht=>{Mt.push(ht.session.id),At(ht)})};return At(bt),Mt},[]),[q,Se]=o.useState(!1),[$e,Pe]=o.useState(!0),fe=`${G}:${l?"archived":"active"}:${ue.id}`,L=ph(o.useCallback(bt=>!!bt.sessionMemoryState.get(ue.id)?.isZombie,[ue.id])),Z=Iy(ue.id),Y=Ay(ue.id,Ce??void 0),Ae=(Ce?c.get(Ce):null)==="missing",Je=d===ue.id,de=Ne.title||e("sessions.sidebar.session.untitled"),ze=n.children.length>0,rt=p.has(ue.id),Re=fe,Xe=u?!0:m.has(Re),qe=!!Ne.parentID,We=Dy(ue.id)>0&&(!qe||x),Ze=Ne.summary,Qe=Kf(Ze),he=Ne.time?.updated||Ne.time?.created||Date.now(),Ge=Ty(he),Ve=Fy(he),it=S===fe,dt=o.useMemo(()=>ll(Ne.title)!==null,[Ne.title]),[Ye,_e]=o.useState(!1),et=o.useMemo(()=>Ue(n).length,[Ue,n]),gt=o.useCallback(async bt=>{const Mt=[];let At=0;for(const ee of bt)try{await we.ensureSessionRenderable(ee.session.id);const ht=zu(je.getState(),ee.session.id).list,St=ee.session.title||e("sessions.sidebar.session.export.untitledSubagent"),qt=ee.session.agent,ms=await gt(ee.children);At+=ms.skipped,Mt.push({title:St,agent:qt,records:ht,children:ms.children})}catch{At+=Ue(ee).length+1}return{children:Mt,skipped:At}},[Ue,je,we,e]),Lt=o.useCallback(bt=>{bt<=0||H.warning(bt===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:bt}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:bt}))},[e]),Ut=o.useCallback(async bt=>{if(!Ce){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}await we.ensureSessionRenderable(ue.id);const Mt=zu(je.getState(),ue.id).list;if(Mt.length===0){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}let At,ee=0;if(bt&&n.children.length>0){const ms=await gt(n.children);At=ms.children,ee=ms.skipped}const ht=JI(Mt,Ne.title??null,At),St=sA(Ne.title??null),qt=await ZI(ht,St);if(qt){H.success(e("sessions.sidebar.session.export.success"),{action:{label:e(tA()),onClick:()=>{eA(qt).then(ms=>{ms||H.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Lt(ee);return}XI(ht,St),H.success(e("sessions.sidebar.session.export.success")),Lt(ee)},[gt,je,n.children,Ne.title,ue.id,Ce,Lt,we,e]),mt=o.useCallback(async()=>{if(n.children.length>0){Pe(!0),Se(!0);return}await Ut(!1)},[Ut,n.children.length]),Nt=o.useCallback(()=>{Ce&&ml("desktop_open_session_mini_chat_window",{sessionId:ue.id,directory:Ce}).catch(bt=>{console.warn("[session-sidebar] failed to open mini chat window",bt)})},[ue.id,Ce]);if(f===ue.id)return s.jsx("div",{className:ce("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:bt=>{bt.preventDefault(),w()},children:[s.jsx("input",{value:y,onChange:bt=>g(bt.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:bt=>{if(bt.key==="Escape"){bt.stopPropagation(),b();return}(bt.key===" "||bt.key==="Enter")&&bt.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:b,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(P,{name:"close",className:"size-4"})})]}),U?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[ze?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Xe?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:Ge}),Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Qe.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Qe.deletions]})]}):null,le?s.jsx("span",{className:"truncate",children:ne?.projectLabel}):null,oe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ne?.branchLabel})]}):null]})})]})},ue.id);const Xt=Z?.type??"idle",_t=Xt==="busy"||Xt==="retry",Gt=Y.length,Tt=_t||!_t&&We&&!Je,rs=_t?s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-busy-pulse","aria-label":e("sessions.sidebar.session.status.active"),title:e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),js=Tt||rt?s.jsxs("span",{className:ce("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",U?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",Tt&&rt?"left-[-18px] w-6":"left-[-10px] w-3.5",ze&&!J?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[Tt?rs:null,rt?s.jsx(P,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,ys=ze?s.jsx("span",{role:"button",tabIndex:0,onClick:bt=>{bt.stopPropagation(),k(Re)},onKeyDown:bt=>{(bt.key==="Enter"||bt.key===" ")&&(bt.preventDefault(),bt.stopPropagation(),k(Re))},className:ce("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",U&&Tt&&!J?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Xe?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Xe?s.jsx(P,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(P,{name:"arrow-right-s",className:"h-3 w-3"})}):null,vs=L?s.jsx(P,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Wt=bt=>{M(bt?fe:null)},He=bt=>{bt.preventDefault(),bt.stopPropagation(),M(it?null:fe)},kt=bt=>{bt.preventDefault(),bt.stopPropagation()},Kt=bt=>{bt.preventDefault(),bt.stopPropagation()},wt=bt=>{bt.preventDefault(),bt.stopPropagation()},Qt=bt=>{bt.preventDefault(),bt.stopPropagation()},cs=bt=>{bt.preventDefault(),bt.stopPropagation(),M(null),X(ue,{archivedBucket:l})},Ls=bt=>{if(pe.current){pe.current=!1;return}if(ke){if(bt?.preventDefault(),bt?.stopPropagation(),bt?.shiftKey){const At=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(St=>St.getAttribute("data-session-row")).filter(St=>typeof St=="string"&&St.length>0),ee=ur.getState().anchorId,ht=new Map;ht.set(ue.id,Ue(n)),Me(ee,ue.id,At,Ce??null,ht);return}me(ue.id,Ce??null,Ue(n));return}I(ue.id,Ce,Ae,a)},Ss=bt=>{(bt.button===2||bt.button===0&&bt.ctrlKey&&!ke)&&(pe.current=!0)},ns=bt=>{O&&bt.pointerType==="touch"&&ie(!0)},Os=bt=>{O&&bt.pointerType==="touch"&&ie(!1)},Ks=s.jsxs(Rs,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:bt=>{A&&bt.preventDefault()},children:[s.jsxs($t,{onClick:()=>{v(ue.id),g(de)},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:()=>N(ue.id),className:"[&>svg]:mr-1",children:[rt?s.jsx(P,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(P,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(rt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ne.share?s.jsxs(s.Fragment,{children:[s.jsx($t,{onClick:()=>{Ne.share?.url&&T(Ne.share.url,ue.id)},className:"[&>svg]:mr-1",children:E===ue.id?s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(P,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs($t,{onClick:()=>C(ue.id),className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs($t,{onClick:()=>D(Ne),className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs($t,{onClick:()=>{mt()},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),dt?s.jsxs($t,{onClick:()=>_e(!0),className:"[&>svg]:mr-1",children:[s.jsx(xA,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ce&&!l?(()=>{const bt=R(Ce),Mt=z(Ce,ue.id);return s.jsxs(s.Fragment,{children:[s.jsx(Cn,{}),s.jsxs(My,{children:[s.jsxs(Ey,{className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ry,{className:"min-w-[180px]",children:[bt.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):bt.map(At=>s.jsxs($t,{onClick:()=>{Mt===At.id?B(Ce,ue.id):V(Ce,At.id,ue.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:At.name}),Mt===At.id?s.jsx(P,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},At.id)),s.jsx(Cn,{}),s.jsxs($t,{onClick:()=>{const At=$(Ce);At&&V(Ce,At.id,ue.id)},children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Mt?s.jsxs($t,{onClick:()=>{B(Ce,ue.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,W?null:s.jsxs($t,{disabled:!Ce,onClick:()=>{Ce&&_(Ce,{mode:"chat",dedupeKey:`session:${ue.id}`,label:de})},className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),te?s.jsxs($t,{disabled:!Ce,onClick:Nt,className:"[&>svg]:mr-1",children:[s.jsx(P,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Cn,{}),s.jsxs($t,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>X(ue,{archivedBucket:l}),children:[s.jsx(P,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(l?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(o.Fragment,{children:[s.jsx(xI,{sessionId:ue.id,sessionDirectory:Ce??null,sessionTitle:de,children:s.jsxs("div",{"data-session-row":ue.id,"data-session-scope":Ce??"","data-session-archived":l?"1":"0",className:ce("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",Ae?"opacity-75":"",r>0&&"pl-[20px]",xe&&"bg-primary/15"),children:[js,ys,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:U?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",disabled:Ae,onPointerDown:ns,onPointerUp:Os,onPointerCancel:Os,onMouseDown:Ss,onClick:bt=>Ls(bt),onDoubleClick:bt=>{bt.stopPropagation(),j()},className:ce("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ye&&"bg-interactive-hover/70",J?W?re:be:re),children:s.jsxs("div",{className:ce("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ce("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:Ga(de,h)}),J?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Ve}):null,J?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:ce("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",it?"opacity-0":ae),children:Ve})}),Gt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(P,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Gt})]}):null]})})}),s.jsx(Dt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:ce("flex items-center gap-3 text-left text-muted-foreground",ne?.projectLabel?"justify-between":"justify-start"),children:[ne?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ne.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:Ge})]}),ne?.branchLabel||Qe?s.jsxs("div",{className:ce("flex items-center gap-3 text-left text-muted-foreground",ne?.branchLabel?"justify-between":"justify-start"),children:[ne?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ne.branchLabel})]})}):null,Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Qe.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Qe.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:Ae,onPointerDown:ns,onPointerUp:Os,onPointerCancel:Os,onMouseDown:Ss,onClick:bt=>Ls(bt),onDoubleClick:bt=>{bt.stopPropagation(),j()},className:ce("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ye&&"bg-interactive-hover/70",J?W?re:be:re),children:[s.jsxs("div",{className:ce("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:ce("block min-w-0 flex-1 truncate typography-ui-label font-normal",Je?"text-primary":"text-foreground"),children:Ga(de,h)}),Gt>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(P,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Gt})]}):null]}),U?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:Ge}),Qe?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Qe.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Qe.deletions]})]}):null,le?s.jsx("span",{className:"truncate",children:ne?.projectLabel}):null,oe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(P,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ne?.branchLabel})]}):null]})})]})}),vs&&!O?s.jsx("div",{className:ce("absolute top-1/2 -translate-y-1/2 z-10",U?"right-0":"right-[30px]"),children:vs}):null,s.jsxs("div",{className:ce("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",it||J&&!W?"opacity-100":ce("opacity-0",K)),children:[ve?s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:ce("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U&&!J?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:wt,onMouseDown:Qt,onClick:cs,onKeyDown:bt=>bt.stopPropagation(),children:s.jsx(P,{name:"archive",className:ce(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Dt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(Fs,{open:it,onOpenChange:Wt,children:[s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:ce("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",U&&!J?it?"h-4 w-4 opacity-100":ce("h-4 w-4 opacity-0",K):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:kt,onMouseDown:Kt,onClick:He,onKeyDown:bt=>bt.stopPropagation(),children:s.jsx(P,{name:"more-2",className:ce(U&&!J?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Ks]})]})]})}),ze&&Xe?n.children.map(bt=>Q(bt,r+1,Ce??i,a,l,void 0,G)):null,s.jsx(hs,{open:q,onOpenChange:Se,children:s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(bs,{children:[s.jsx(gs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Is,{children:et===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:et}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:et})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$e,onChange:bt=>Pe(bt.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Vs,{children:[s.jsx(ge,{type:"button",onClick:()=>Se(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{type:"button",onClick:()=>{Se(!1),Ut($e)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),dt?s.jsx(gA,{session:Ne,open:Ye,onOpenChange:_e}):null]},ue.id)}const vA=o.memo(yA,bA);function wA(t){const e=at.c(71),{t:n}=ut(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:l,onConfirm:c}=t;let d,p,m,u,h,x,f,v,y,g;if(e[0]!==i||e[1]!==n||e[2]!==r){const $=n("sessions.sidebar.session.untitled");u=hs,y=!!r,e[13]!==i?(g=X=>{X||i(null)},e[13]=i,e[14]=g):g=e[14],m=fs,f=!1,v="max-w-sm gap-5",p=bs;let _;e[15]!==n||e[16]!==r?.archivedBucket?(_=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=_):_=e[17],e[18]!==_?(x=s.jsx(gs,{children:_}),e[18]=_,e[19]=x):x=e[19],d=Is,h=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||$,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||$,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||$}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||$}),e[0]=i,e[1]=n,e[2]=r,e[3]=d,e[4]=p,e[5]=m,e[6]=u,e[7]=h,e[8]=x,e[9]=f,e[10]=v,e[11]=y,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],h=e[7],x=e[8],f=e[9],v=e[10],y=e[11],g=e[12];let w;e[20]!==d||e[21]!==h?(w=s.jsx(d,{children:h}),e[20]=d,e[21]=h,e[22]=w):w=e[22];let b;e[23]!==p||e[24]!==x||e[25]!==w?(b=s.jsxs(p,{children:[x,w]}),e[23]=p,e[24]=x,e[25]=w,e[26]=b):b=e[26];let k;e[27]!==l||e[28]!==a?(k=()=>l(!a),e[27]=l,e[28]=a,e[29]=k):k=e[29];const I=!a;let j;e[30]!==a?(j=a?s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=a,e[31]=j):j=e[31];let N;e[32]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=N):N=e[33];let D;e[34]!==j||e[35]!==N||e[36]!==k||e[37]!==I?(D=s.jsxs("button",{type:"button",onClick:k,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":I,children:[j,N]}),e[34]=j,e[35]=N,e[36]=k,e[37]=I,e[38]=D):D=e[38];let E;e[39]!==i?(E=()=>i(null),e[39]=i,e[40]=E):E=e[40];let T;e[41]!==n?(T=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=T):T=e[42];let C;e[43]!==E||e[44]!==T?(C=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:T}),e[43]=E,e[44]=T,e[45]=C):C=e[45];let S;e[46]!==c?(S=()=>{c()},e[46]=c,e[47]=S):S=e[47];let M;e[48]!==n||e[49]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=M):M=e[50];let A;e[51]!==S||e[52]!==M?(A=s.jsx("button",{type:"button",onClick:S,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:M}),e[51]=S,e[52]=M,e[53]=A):A=e[53];let R;e[54]!==C||e[55]!==A?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[C,A]}),e[54]=C,e[55]=A,e[56]=R):R=e[56];let z;e[57]!==D||e[58]!==R?(z=s.jsxs(Vs,{className:"w-full sm:items-center sm:justify-between",children:[D,R]}),e[57]=D,e[58]=R,e[59]=z):z=e[59];let B;e[60]!==m||e[61]!==f||e[62]!==z||e[63]!==v||e[64]!==b?(B=s.jsxs(m,{showCloseButton:f,className:v,children:[b,z]}),e[60]=m,e[61]=f,e[62]=z,e[63]=v,e[64]=b,e[65]=B):B=e[65];let V;return e[66]!==u||e[67]!==B||e[68]!==y||e[69]!==g?(V=s.jsx(u,{open:y,onOpenChange:g,children:B}),e[66]=u,e[67]=B,e[68]=y,e[69]=g,e[70]=V):V=e[70],V}function jA(t){const e=at.c(57),{t:n}=ut(),{value:r,setValue:i,showDeletionDialog:a,setShowDeletionDialog:l,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let h;e[4]!==d||e[5]!==p||e[6]!==n?(h=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=h):h=e[7];const x=h,f=!!r;let v;e[8]!==i?(v=V=>{V||i(null)},e[8]=i,e[9]=v):v=e[9];let y;e[10]!==u?(y=s.jsx(gs,{children:u}),e[10]=u,e[11]=y):y=e[11];let g;e[12]!==x?(g=s.jsx(Is,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==y||e[15]!==g?(w=s.jsxs(bs,{children:[y,g]}),e[14]=y,e[15]=g,e[16]=w):w=e[16];let b;e[17]!==l||e[18]!==a?(b=()=>l(!a),e[17]=l,e[18]=a,e[19]=b):b=e[19];const k=!a;let I;e[20]!==a?(I=a?s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=a,e[21]=I):I=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let N;e[24]!==j||e[25]!==b||e[26]!==k||e[27]!==I?(N=s.jsxs("button",{type:"button",onClick:b,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":k,children:[I,j]}),e[24]=j,e[25]=b,e[26]=k,e[27]=I,e[28]=N):N=e[28];let D;e[29]!==i?(D=()=>i(null),e[29]=i,e[30]=D):D=e[30];let E;e[31]!==n?(E=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=E):E=e[32];let T;e[33]!==D||e[34]!==E?(T=s.jsx("button",{type:"button",onClick:D,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:E}),e[33]=D,e[34]=E,e[35]=T):T=e[35];let C;e[36]!==c?(C=()=>{c()},e[36]=c,e[37]=C):C=e[37];let S;e[38]!==d||e[39]!==n?(S=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=S):S=e[40];let M;e[41]!==C||e[42]!==S?(M=s.jsx("button",{type:"button",onClick:C,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:S}),e[41]=C,e[42]=S,e[43]=M):M=e[43];let A;e[44]!==T||e[45]!==M?(A=s.jsxs("div",{className:"flex items-center gap-2",children:[T,M]}),e[44]=T,e[45]=M,e[46]=A):A=e[46];let R;e[47]!==N||e[48]!==A?(R=s.jsxs(Vs,{className:"w-full sm:items-center sm:justify-between",children:[N,A]}),e[47]=N,e[48]=A,e[49]=R):R=e[49];let z;e[50]!==R||e[51]!==w?(z=s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,R]}),e[50]=R,e[51]=w,e[52]=z):z=e[52];let B;return e[53]!==f||e[54]!==z||e[55]!==v?(B=s.jsx(hs,{open:f,onOpenChange:v,children:z}),e[53]=f,e[54]=z,e[55]=v,e[56]=B):B=e[56],B}function NA(t){const e=at.c(36),{t:n}=ut(),{value:r,setValue:i,onConfirm:a}=t,l=!!r;let c;e[0]!==i?(c=I=>{I||i(null)},e[0]=i,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(gs,{children:d}),e[4]=d,e[5]=p):p=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let u;e[9]!==m?(u=s.jsx(Is,{children:m}),e[9]=m,e[10]=u):u=e[10];let h;e[11]!==p||e[12]!==u?(h=s.jsxs(bs,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=h):h=e[13];let x;e[14]!==i?(x=()=>i(null),e[14]=i,e[15]=x):x=e[15];let f;e[16]!==n?(f=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=f):f=e[17];let v;e[18]!==x||e[19]!==f?(v=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:f}),e[18]=x,e[19]=f,e[20]=v):v=e[20];let y;e[21]!==n?(y=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=y):y=e[22];let g;e[23]!==a||e[24]!==y?(g=s.jsx("button",{type:"button",onClick:a,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:y}),e[23]=a,e[24]=y,e[25]=g):g=e[25];let w;e[26]!==g||e[27]!==v?(w=s.jsxs(Vs,{children:[v,g]}),e[26]=g,e[27]=v,e[28]=w):w=e[28];let b;e[29]!==w||e[30]!==h?(b=s.jsxs(fs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[h,w]}),e[29]=w,e[30]=h,e[31]=b):b=e[31];let k;return e[32]!==l||e[33]!==c||e[34]!==b?(k=s.jsx(hs,{open:l,onOpenChange:c,children:b}),e[32]=l,e[33]=c,e[34]=b,e[35]=k):k=e[35],k}const SA=t=>{const e=at.c(46),{selectedCount:n,scopeKey:r,scopeFolders:i,archivedBucket:a,onMoveToFolder:l,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:h}=ut(),x=!!r&&!a;let f;e[0]!==a||e[1]!==h?(f=h(a?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=a,e[1]=h,e[2]=f):f=e[2];const v=f;let y;e[3]!==n||e[4]!==h?(y=h("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=h,e[5]=y):y=e[5];let g;e[6]!==y?(g=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:y}),e[6]=y,e[7]=g):g=e[7];let w;e[8]!==x||e[9]!==p||e[10]!==c||e[11]!==l||e[12]!==d||e[13]!==i||e[14]!==h?(w=x?s.jsxs(Fs,{children:[s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(Es,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":h("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(P,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Rs,{align:"end",className:"min-w-[180px]",children:[i.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:h("sessions.sidebar.folders.none")}):i.map(z=>s.jsx($t,{onClick:()=>l(z.id),children:s.jsx("span",{className:"flex-1 truncate",children:z.name})},z.id)),s.jsx(Cn,{}),s.jsxs($t,{onClick:c,children:[s.jsx(P,{name:"add",className:"mr-1 h-4 w-4"}),h("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs($t,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(P,{name:"close",className:"mr-1 h-4 w-4"}),h("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=x,e[9]=p,e[10]=c,e[11]=l,e[12]=d,e[13]=i,e[14]=h,e[15]=w):w=e[15];let b;e[16]===Symbol.for("react.memo_cache_sentinel")?(b=ce("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=b):b=e[16];let k;e[17]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(P,{name:"delete-bin",className:"h-4 w-4"}),e[17]=k):k=e[17];let I;e[18]!==v||e[19]!==m?(I=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:b,"aria-label":v,children:k})}),e[18]=v,e[19]=m,e[20]=I):I=e[20];let j;e[21]!==v?(j=s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=j):j=e[22];let N;e[23]!==I||e[24]!==j?(N=s.jsxs(Pt,{children:[I,j]}),e[23]=I,e[24]=j,e[25]=N):N=e[25];let D;e[26]!==h?(D=h("sessions.sidebar.header.actions.exitSelection"),e[26]=h,e[27]=D):D=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(P,{name:"close",className:"h-4 w-4"}),e[28]=E):E=e[28];let T;e[29]!==u||e[30]!==D?(T=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":D,children:E})}),e[29]=u,e[30]=D,e[31]=T):T=e[31];let C;e[32]!==h?(C=h("sessions.sidebar.header.actions.exitSelection"),e[32]=h,e[33]=C):C=e[33];let S;e[34]!==C?(S=s.jsx(Dt,{side:"top",sideOffset:4,children:s.jsx("p",{children:C})}),e[34]=C,e[35]=S):S=e[35];let M;e[36]!==T||e[37]!==S?(M=s.jsxs(Pt,{children:[T,S]}),e[36]=T,e[37]=S,e[38]=M):M=e[38];let A;e[39]!==M||e[40]!==w||e[41]!==N?(A=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,N,M]}),e[39]=M,e[40]=w,e[41]=N,e[42]=A):A=e[42];let R;return e[43]!==A||e[44]!==g?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,A]}),e[43]=A,e[44]=g,e[45]=R):R=e[45],R},Bg="oc.sessions.activeNow",kA=2160*60*1e3,zg=t=>!!t.parentID,nu=t=>!!t.time?.archived,kd=t=>{const e=t.time?.updated,n=t.time?.created;return typeof e=="number"&&Number.isFinite(e)?e:typeof n=="number"&&Number.isFinite(n)?n:0},CA=t=>{try{const e=t.getItem(Bg);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,i=[];return n.forEach(a=>{const l=typeof a=="string"?a:a&&typeof a=="object"&&"sessionId"in a&&typeof a.sessionId=="string"?a.sessionId:null;!l||r.has(l)||(r.add(l),i.push({sessionId:l}))}),i}catch{return[]}},Bc=(t,e)=>{try{t.setItem(Bg,JSON.stringify(e))}catch{}},PA=(t,e,n=Date.now())=>{const r=n-kA;return t.filter(i=>{const a=e.get(i.sessionId);return a?nu(a)?!1:kd(a)>=r:!0})},IA=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Vg=t=>[...t].sort((e,n)=>kd(n)-kd(e)),AA=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!nu(r)).filter(r=>!zg(r));return Vg(n)},DA=(t,e)=>{const n=t.filter(r=>{if(nu(r)||zg(r))return!1;const i=e[r.id];return i?.type==="busy"||i?.type==="retry"});return Vg(n)},Uo=pi(),zc=gr((t,e)=>({entries:CA(Uo),setEntries:n=>{n!==e().entries&&(t({entries:n}),Bc(Uo,n))},addSession:n=>{const r=IA(e().entries,n);r!==e().entries&&(t({entries:r}),Bc(Uo,r))},prune:n=>{const r=e().entries,i=PA(r,n);i.length===r.length&&i.every((a,l)=>a.sessionId===r[l]?.sessionId)||(t({entries:i}),Bc(Uo,i))}})),Wo="oc.sessions.projectCollapse",ff="oc.sessions.groupOrder",hf="oc.sessions.groupCollapse",gf="oc.sessions.activeSessionByProject",Vc="oc.sessions.expandedParents.v2",TA="oc.sessions.expandedParents",MA="oc.sessions.pinned",EA=(t,e)=>{const n=new Set;for(const r of t){const i=xs(r.path)?.toLowerCase();i&&n.add(i)}for(const r of e.values())for(const i of r){const a=xs(i.path)?.toLowerCase();a&&n.add(a)}return n},RA=(t,e)=>{if(t.time?.archived)return!0;const n=xs(Ha(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},FA=5*6e4,xf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:i=!1})=>{const{t:a}=ut(),[l,c]=o.useState(!1),[d,p]=o.useState(""),m=o.useRef(null),u=o.useRef(null),h=o.useRef(new Set),[x,f]=o.useState(null),[v,y]=o.useState(""),[g,w]=o.useState(null),[b,k]=o.useState(new Set),[I]=o.useState(()=>new Map),j=o.useMemo(()=>pi(),[]),N=zc(Le=>Le.entries),D=zc(Le=>Le.addSession),E=zc(Le=>Le.prune),[T,C]=o.useState(new Set),[S,M]=o.useState(new Map),[A,R]=o.useState(new Set),[z,B]=o.useState(!1),[V,$]=o.useState(null),[_,X]=o.useState(null),[O,J]=o.useState(""),[Q,ne]=o.useState(null),[G,le]=o.useState(null),[oe,F]=o.useState(null),U=oc(Le=>Le.ids),W=oc(Le=>Le.setIds),te=oc(Le=>Le.toggle),[K,ae]=o.useState(()=>{try{const Le=pi().getItem(hf);if(!Le)return new Set;const vt=JSON.parse(Le);return new Set(Array.isArray(vt)?vt.filter(ft=>typeof ft=="string"):[])}catch{return new Set}}),[ve,re]=o.useState(()=>{try{const Le=pi().getItem(ff);if(!Le)return new Map;const vt=JSON.parse(Le),ft=new Map;return Object.entries(vt).forEach(([Yt,ps])=>{Array.isArray(ps)&&ft.set(Yt,ps.filter(Ws=>typeof Ws=="string"))}),ft}catch{return new Map}}),[be,pe]=o.useState(()=>{try{const Le=pi().getItem(gf);if(!Le)return new Map;const vt=JSON.parse(Le),ft=new Map;return Object.entries(vt).forEach(([Yt,ps])=>{typeof ps=="string"&&ps.length>0&&ft.set(Yt,ps)}),ft}catch{return new Map}}),[ye,ie]=o.useState(new Map),ue=o.useRef(new Map),se=o.useRef(0),Ne=$s(Le=>Le.homeDirectory),Ce=$s(Le=>Le.currentDirectory),je=$s(Le=>Le.setDirectory),we=As(Le=>Le.projects),ke=As(Le=>Le.activeProjectId),xe=As(Le=>Le.removeProject),me=As(Le=>Le.setActiveProjectIdOnly),Me=As(Le=>Le.updateProjectMeta),Ue=As(Le=>Le.reorderProjects),q=Ie(Le=>Le.setActiveMainTab),Se=Ie(Le=>Le.openContextPanelTab),$e=Ie(Le=>Le.setSettingsDialogOpen),Pe=Ie(Le=>Le.toggleHelpDialog),fe=Ie(Le=>Le.setAboutDialogOpen),L=Ie(Le=>Le.setSessionSwitcherOpen),Z=Ie(Le=>Le.setScheduledTasksDialogOpen),Y=Ie(Le=>Le.toggleSidebar),Ee=Ie(Le=>Le.openMultiRunLauncher),Ae=Ie(Le=>Le.notifyOnSubtasks),Je=Ie(Le=>Le.showDeletionDialog),de=Ie(Le=>Le.setShowDeletionDialog),ze=ho(d,120),rt=o.useMemo(()=>ze.trim().toLowerCase(),[ze]),Re=rt.length>0,Xe=Yn(Le=>Le.collapsedFolderIds),qe=Yn(Le=>Le.foldersMap),Te=Yn(Le=>Le.getFoldersForScope),We=Yn(Le=>Le.createFolder),Ze=Yn(Le=>Le.renameFolder),Qe=Yn(Le=>Le.deleteFolder),he=Yn(Le=>Le.addSessionToFolder),Ge=Yn(Le=>Le.addSessionsToFolder),Ve=Yn(Le=>Le.removeSessionFromFolder),it=Yn(Le=>Le.removeSessionsFromFolders),dt=Yn(Le=>Le.toggleFolderCollapse),Ye=Yn(Le=>Le.cleanupSessions),_e=Yn(Le=>Le.getSessionFolderId);LP({isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const et=ah(),gt=_d(),Lt=Ad(),Ut=Ly(),mt=Ei(Le=>Le.hasLoaded),Nt=Ei(Le=>Le.activeSessions),Xt=Ei(Le=>Le.archivedSessions),_t=Ot(Le=>Le.currentSessionId),Gt=Ot(Le=>!!Le.newSessionDraft?.open),lt=Ot(Le=>Le.setCurrentSession),Tt=Ot(Le=>Le.updateSessionTitle),rs=Ot(Le=>Le.shareSession),js=Ot(Le=>Le.unshareSession),ys=Ot(Le=>Le.worktreeMetadata),vs=Ot(Le=>Le.availableWorktreesByProject),Wt=Ot(Le=>Le.openNewSessionDraft),He=o.useMemo(()=>EA(we,vs),[vs,we]),kt=o.useMemo(()=>{const Le=new Map(Lt.map(Yt=>[Yt.id,Yt])),vt=Nt.map(Yt=>Le.get(Yt.id)??Yt),ft=new Set(vt.map(Yt=>Yt.id));return Lt.forEach(Yt=>{ft.has(Yt.id)||vt.push(Yt)}),vt.filter(Yt=>RA(Yt,He))},[Nt,He,Lt]),Kt=o.useMemo(()=>Lt.map(Le=>{const vt=xs(Le.directory??null)??"";return`${Le.id}:${Le.title??""}:${Le.time?.archived?1:0}:${vt}`}).join("|"),[Lt]),wt=o.useRef(Lt);o.useEffect(()=>{wt.current=Lt},[Kt,Lt]),o.useEffect(()=>{let Le=!1;const vt=async()=>{const ft=As.getState().projects;if(ft.length===0)return;const Yt=new Map,ps=[];await Promise.all(ft.map(async Ws=>{const Dn=xs(Ws.path);if(Dn)try{if(!(tn.getState().directories.get(Dn)?.isGitRepo??await kr(()=>import("./modelPrefsAutoSave-z_3gcNaV.js").then(un=>un.cc),__vite__mapDeps([2,0,1,3,4])).then(un=>un.checkIsGitRepository(Dn))))return;const Tn=await Qc({id:Ws.id,path:Dn});if(Le||Tn.length===0)return;Yt.set(Dn,Tn),ps.push(...Tn)}catch{}})),!Le&&Ot.setState({availableWorktrees:ps,availableWorktreesByProject:Yt})};return Jc(wt.current),vt(),()=>{Le=!0}},[Ce,Kt,we]),o.useEffect(()=>{let Le=null;const vt=Mg(ft=>{ft.type==="scheduled-task-ran"&&(Le&&clearTimeout(Le),Le=setTimeout(()=>{Jc(wt.current)},500))});return()=>{Le&&clearTimeout(Le),vt()}},[]);const Qt=o.useMemo(()=>gn(),[]),cs=El(),[Ls,Ss]=o.useState(!1),ns=o.useMemo(()=>mn(),[]),{isTablet:Os}=rn(),Ks=t||Os,bt=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Mt=!t&&!ns&&!Qt,At=!t&&!ns&&!Mt,ee=Qt&&bt&&!Ls||cs?"pl-[5.5rem]":"pl-3",ht="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";o.useEffect(()=>{if(!Qt||!bt){Ss(!1);return}let Le=!1,vt=null;const ft=async()=>{try{const ps=await By();Le||Ss(ps)}catch{Le||Ss(!1)}},Yt=async()=>{try{vt=zy(()=>{ft()})}catch{}};return ft(),Yt(),()=>{Le=!0,vt&&vt()}},[Qt,bt]);const St=o.useCallback(async Le=>{const vt=Le.target;vt.closest(".app-region-no-drag")||vt.closest("button, a, input, select, textarea")||Le.button===0&&Qt&&await fh()},[Qt]),{buildGroupSearchText:qt,filterSessionNodesForSearch:ms,buildGroupedSessions:Ds}=FP({homeDirectory:Ne,worktreeMetadata:ys,pinnedSessionIds:U,gitBranches:et,isVSCode:ns}),{scheduleCollapsedProjectsPersist:Ke}=UP({isVSCode:ns,hasLoadedGlobalSessions:mt,safeStorage:j,keys:{sessionExpanded:Vc,sessionExpandedLegacy:TA,projectCollapse:Wo,sessionPinned:MA,groupOrder:ff,projectActiveSession:gf,groupCollapse:hf},sessions:kt,setPinnedSessionIds:W,groupOrderByProject:ve,activeSessionByProject:be,collapsedGroups:K,setExpandedParents:k,setCollapsedProjects:C}),yt=o.useMemo(()=>[...kt].sort((Le,vt)=>ca(Le,vt,U)),[kt,U]),Et=o.useMemo(()=>new Map(yt.map((Le,vt)=>[Le.id,vt])),[yt]),Ht=o.useMemo(()=>{const Le=new Map;return yt.forEach(vt=>{const ft=vt.parentID;if(!ft)return;const Yt=Le.get(ft)??[];Yt.push(vt),Le.set(ft,Yt)}),Le.forEach(vt=>vt.sort((ft,Yt)=>ca(ft,Yt,U))),Le},[yt,U]),ss=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noSessions.description")})]}),Rt=o.useMemo(()=>we.find(Le=>Le.id===g)??null,[we,g]),Ps=o.useCallback(Le=>{g&&(Me(g,Le),w(null))},[g,Me]),Qs=o.useCallback(()=>{B(!0)},[]),Hs=o.useCallback(()=>{t&&L(!1),$e(!0)},[t,L,$e]),ts=Ot(Le=>Le.deleteSession),Ns=Ot(Le=>Le.deleteSessions),jn=Ot(Le=>Le.archiveSession),sn=Ot(Le=>Le.archiveSessions),{copiedSessionId:Dr,handleSessionSelect:Tr,handleSessionDoubleClick:zr,handleSaveEdit:Vr,handleCancelEdit:Gs,handleShareSession:Mn,handleCopyShareUrl:ir,handleUnshareSession:En,handleDeleteSession:_r,confirmDeleteSession:In}=OP({activeProjectId:ke,currentDirectory:Ce,currentSessionId:_t,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:l,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:me,setDirectory:je,setActiveMainTab:q,setSessionSwitcherOpen:L,setCurrentSession:lt,updateSessionTitle:Tt,shareSession:rs,unshareSession:js,deleteSession:ts,deleteSessions:Ns,archiveSession:jn,archiveSessions:sn,childrenMap:Ht,showDeletionDialog:Je,setDeleteSessionConfirm:ne,deleteSessionConfirm:Q,setEditingId:f,setEditTitle:y,editingId:x,editTitle:v}),ln=o.useCallback(()=>{if(!G)return;const{scopeKey:Le,folderId:vt}=G;le(null),Qe(Le,vt)},[G,Qe]),an=o.useCallback(()=>{Sr.requestDirectoryDialog()},[]);o.useEffect(()=>{if(!_t)return;const vt=kt.find(Yt=>Yt.id===_t)?.parentID;if(!vt)return;const ft=[`project:active:${vt}`,`project:archived:${vt}`,`recent:active:${vt}`,`recent:archived:${vt}`];k(Yt=>{if(ft.every(Ws=>Yt.has(Ws)))return Yt;const ps=new Set(Yt);ft.forEach(Ws=>ps.add(Ws));try{j.setItem(Vc,JSON.stringify(Array.from(ps)))}catch{}return ps})},[_t,kt,j]);const Fe=o.useCallback(Le=>{k(vt=>{const ft=new Set(vt);ft.has(Le)?ft.delete(Le):ft.add(Le);try{j.setItem(Vc,JSON.stringify(Array.from(ft)))}catch{}return ft})},[j]),Ct=o.useCallback((Le,vt)=>{if(!Le)return null;vt&&Xe.has(vt)&&dt(vt);const ft=We(Le,a("sessions.sidebar.folder.newFolderName"),vt);return X(ft.id),J(ft.name),ft},[Xe,dt,We,a]),Zt=o.useCallback(Le=>{R(vt=>{const ft=new Set(vt);return ft.has(Le)?ft.delete(Le):ft.add(Le),ft})},[]),ls=o.useCallback(()=>{se.current=Date.now()+150,C(()=>{const Le=new Set(we.map(vt=>vt.id));try{j.setItem(Wo,JSON.stringify(Array.from(Le)))}catch{}return ns||Ke(Le),Le})},[we,ns,j,Ke]),Bs=o.useCallback(()=>{se.current=Date.now()+150,C(()=>{const Le=new Set;try{j.setItem(Wo,JSON.stringify([]))}catch{}return ns||Ke(Le),Le})},[ns,j,Ke]),Js=o.useCallback(Le=>{se.current=Date.now()+150,C(vt=>{const ft=new Set(vt);ft.has(Le)?ft.delete(Le):ft.add(Le);try{j.setItem(Wo,JSON.stringify(Array.from(ft)))}catch{}return ns||Ke(ft),ft})},[ns,j,Ke]),ws=o.useMemo(()=>we.map(Le=>({...Le,normalizedPath:xs(Le.path)})).filter(Le=>!!Le.normalizedPath),[we]),en=o.useMemo(()=>ws.map(Le=>Le.normalizedPath),[ws]),{github:nn}=Pn(),Rn=Hn(Le=>Le.status),Fn=Hn(Le=>Le.hasChecked),Ur=Oy(en),xr=mr(Le=>Le.ensureEntry),Wr=mr(Le=>Le.setParams),Ln=mr(Le=>Le.refreshTargets);KP({normalizedProjects:ws,gitRepoStatus:Ur,setProjectRepoStatus:M,setProjectRootBranches:ie});const er=Ot(Le=>Le.isLoading);eI({isSessionsLoading:er,sessions:kt,archivedSessions:Xt,normalizedProjects:ws,isVSCode:ns,availableWorktreesByProject:vs,cleanupSessions:Ye});const{getSessionsForProject:br,getArchivedSessionsForProject:ar}=YP({isVSCode:ns,sessions:kt,archivedSessions:Xt,availableWorktreesByProject:vs});PP({normalizedProjects:ws,sessions:kt,archivedSessions:Xt,availableWorktreesByProject:vs,isVSCode:ns,isSessionsLoading:er,foldersMap:qe,createFolder:We,addSessionToFolder:he,cleanupSessions:Ye});const dn=o.useRef(!1);ke&&S.has(ke)&&(dn.current=!!S.get(ke));const{projectSections:On,groupSearchDataByGroup:bn,sectionsForRender:Gn,searchMatchCount:Nn}=DP({normalizedProjects:ws,getSessionsForProject:br,getArchivedSessionsForProject:ar,availableWorktreesByProject:vs,projectRepoStatus:S,projectRootBranches:ye,lastRepoStatus:dn.current,buildGroupedSessions:Ds,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,filterSessionNodesForSearch:ms,buildGroupSearchText:qt,foldersMap:qe}),ni=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:a("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:a("sessions.sidebar.empty.noMatches.description")})]}),Gi=!0,{currentSessionDirectory:tr}=MP({projectSections:On,activeProjectId:ke,activeSessionByProject:be,setActiveSessionByProject:pe,currentSessionId:_t,handleSessionSelect:Tr,newSessionDraftOpen:Gt,mobileVariant:t,openNewSessionDraft:Wt,setActiveMainTab:q,setSessionSwitcherOpen:L,sessions:kt,worktreeMetadata:ys}),{getOrderedGroups:bi}=EP(ve),Sn=o.useRef(!1);o.useEffect(()=>{if(Sn.current||On.length===0)return;const Le=On.flatMap(vt=>vt.groups.filter(ft=>ft.isArchivedBucket).map(ft=>`${vt.project.id}:${ft.id}`));Le.length>0&&ae(vt=>new Set([...vt,...Le])),Sn.current=!0},[On]);const yr=o.useMemo(()=>{const Le=new Map,vt=new Map;return On.forEach(ft=>{const Yt=mh(ft.project.label?.trim()||Vi(ft.project.normalizedPath,Ne)||ft.project.normalizedPath);ft.groups.forEach(ps=>{const Ws=ps.branch&&ps.branch!=="HEAD"&&ps.branch!==Yt?ps.branch:null,Dn={projectLabel:Yt,branchLabel:Ws},wr=nr=>{nr.forEach(Tn=>{const un=ft.project.normalizedPath.length,Aa=vt.get(Tn.session.id)??-1;un<Aa||(Le.set(Tn.session.id,{node:Tn,projectId:ft.project.id,groupDirectory:ps.directory,secondaryMeta:Dn}),vt.set(Tn.session.id,un),Tn.children.length>0&&wr(Tn.children))})};wr(ps.sessions)})}),Le},[On,Ne]),qn=Mi(Le=>Le.showRecentSection),Gr=o.useMemo(()=>qn?AA(N,new Map(kt.map(Le=>[Le.id,Le]))).sort((Le,vt)=>ca(Le,vt,U)):[],[N,U,kt,qn]),Kr=o.useMemo(()=>qn?DA(kt,Ut):[],[Ut,kt,qn]);o.useEffect(()=>{!qn||Kr.length===0||Kr.forEach(Le=>D(Le.id))},[D,Kr,qn]),o.useEffect(()=>{if(!qn)return;const Le=new Map;[...kt,...Xt].forEach(vt=>{Le.set(vt.id,vt)}),E(Le)},[Xt,E,kt,qn]);const qi=o.useMemo(()=>{if(!qn)return[];const Le=vt=>{const ft=yr.get(vt.id),Yt=xs(vt.directory??null);return{node:ft?.node??{session:vt,children:[],worktree:null},projectId:ft?.projectId??null,groupDirectory:ft?.groupDirectory??Yt,secondaryMeta:ft?.secondaryMeta??null}};return[{key:"active-now",title:a("sessions.sidebar.activity.recentTitle"),items:Gr.map(Le)}]},[Gr,yr,qn,a]),cn=o.useMemo(()=>new Set(Gr.map(Le=>Le.id)),[Gr]),Oe=o.useMemo(()=>[...cn],[cn]);K4({currentSessionId:_t,sortedSessions:yt,recentSessionIds:Oe,ensureSessionRenderable:gt.ensureSessionRenderable});const tt=o.useMemo(()=>{if(!ns||Re||cn.size===0)return Gn;const Le=vt=>vt.reduce((ft,Yt)=>{if(cn.has(Yt.session.id))return ft;const ps=Le(Yt.children);return ps.length===Yt.children.length?(ft.push(Yt),ft):(ft.push({...Yt,children:ps}),ft)},[]);return Gn.map(vt=>({...vt,groups:vt.groups.map(ft=>({...ft,sessions:Le(ft.sessions)}))}))},[ns,Re,cn,Gn]),nt=o.useMemo(()=>{const Le=new Set;return tt.forEach(vt=>{vt.groups.forEach(ft=>{const Yt=xs(ft.directory??null),ps=ft.branch?.trim()||et.get(Yt||"")?.trim();!Yt||!ps||Le.add(Ya(Yt,ps))})}),[...Le]},[et,tt]),ct=j0(nt);o.useEffect(()=>{if(!Fn||!Rn?.connected||!nn)return;const Le=[],vt=Date.now();if(tt.forEach(Yt=>{T.has(Yt.project.id)||Yt.groups.forEach(ps=>{const Ws=xs(ps.directory??null),Dn=ps.branch?.trim()||et.get(Ws||"")?.trim();if(!Ws||!Dn)return;const wr=Ya(Ws,Dn),nr=mr.getState().entries[wr],Tn=!!nr?.status?.pr,un=`${Ws}::${Dn}`,Aa=Math.max(nr?.lastRefreshAt??0,nr?.lastDiscoveryPollAt??0),So=!!(nr?.isInitialStatusResolved&&!Tn&&(!h.current.has(un)||vt-Aa>=FA));(!nr||!nr.isInitialStatusResolved||So)&&(So&&h.current.add(un),Le.push({directory:Ws,branch:Dn}))})}),Le.length===0)return;const ft=new Map;Le.forEach(Yt=>{const ps=Ya(Yt.directory,Yt.branch,Yt.remoteName??null);ft.has(ps)||ft.set(ps,Yt)}),ft.forEach((Yt,ps)=>{xr(ps),Wr(ps,{directory:Yt.directory,branch:Yt.branch,remoteName:Yt.remoteName??null,canShow:!0,github:nn,githubAuthChecked:Fn,githubConnected:Rn.connected})}),Ln([...ft.values()],{force:!0,silent:!0,markInitialResolved:!0})},[T,xr,nn,Fn,Rn?.connected,et,Ln,tt,Wr]);const _s=t?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",pn="h-4.5 w-4.5",Mr=rI({isDesktopShellRuntime:Qt,projectSections:On,projectHeaderSentinelRefs:ue}),An=o.useCallback((Le,vt=0,ft,Yt,ps=!1,Ws,Dn="project")=>s.jsx(vA,{node:Le,depth:vt,groupDirectory:ft,projectId:Yt,archivedBucket:ps,directoryStatus:I,currentSessionId:_t,pinnedSessionIds:U,expandedParents:b,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,notifyOnSubtasks:Ae,editingId:x,setEditingId:f,editTitle:v,setEditTitle:y,handleSaveEdit:Vr,handleCancelEdit:Gs,toggleParent:Fe,handleSessionSelect:Tr,handleSessionDoubleClick:zr,togglePinnedSession:te,handleShareSession:Mn,copiedSessionId:Dr,handleCopyShareUrl:ir,handleUnshareSession:En,openSidebarMenuKey:V,setOpenSidebarMenuKey:$,renamingFolderId:_,getFoldersForScope:Te,getSessionFolderId:_e,removeSessionFromFolder:Ve,addSessionToFolder:he,createFolderAndStartRename:Ct,openContextPanelTab:Se,handleDeleteSession:_r,mobileVariant:t,alwaysShowActions:Ks,renderSessionNode:An,secondaryMeta:Ws,renderContext:Dn}),[I,_t,U,b,Re,rt,Ae,x,f,v,y,Vr,Gs,Fe,Tr,zr,te,Mn,Dr,ir,En,V,$,_,Te,_e,Ve,he,Ct,Se,_r,t,Ks]),qr=o.useCallback(Le=>{ae(vt=>{const ft=new Set(vt);return ft.has(Le)?ft.delete(Le):ft.add(Le),ft})},[]),vr=o.useMemo(()=>{const Le=new Map;for(const[vt,ft]of ct)Le.set(vt,{visualState:ft.visualState,number:ft.number,url:ft.url,state:ft.prState,draft:ft.draft,title:ft.title,base:ft.base,head:ft.head,checks:ft.checks,canMerge:ft.canMerge,mergeableState:ft.mergeableState,repo:ft.repo});return Le},[ct]),ri=o.useCallback((Le,vt,ft,Yt,ps,Ws)=>s.jsx(jI,{group:Le,groupKey:vt,projectId:ft,hideGroupLabel:Yt,compactBodyPadding:Ws,hasSessionSearchQuery:Re,normalizedSessionSearchQuery:rt,groupSearchDataByGroup:bn,expandedSessionGroups:A,collapsedGroups:K,hideDirectoryControls:r,collapsedFolderIds:Xe,toggleFolderCollapse:dt,renameFolder:Ze,deleteFolder:Qe,showDeletionDialog:Je,setDeleteFolderConfirm:le,renderSessionNode:An,currentSessionDirectory:tr,projectRepoStatus:S,lastRepoStatus:dn.current,toggleGroupSessionLimit:Zt,mobileVariant:t,alwaysShowActions:Ks,activeProjectId:ke,setActiveProjectIdOnly:me,setActiveMainTab:q,setSessionSwitcherOpen:L,openNewSessionDraft:Wt,addSessionToFolder:he,createFolderAndStartRename:Ct,renamingFolderId:_,renameFolderDraft:O,setRenameFolderDraft:J,setRenamingFolderId:X,pinnedSessionIds:U,sessionOrderIndex:Et,prVisualStateByDirectoryBranch:vr,onToggleCollapsedGroup:qr,dragHandleProps:ps}),[Re,rt,bn,A,K,r,Xe,dt,Ze,Qe,Je,An,tr,S,Zt,t,Ks,ke,me,q,L,Wt,he,Ct,_,O,U,Et,vr,qr]),ii=qn&&!Re?s.jsx(AI,{sections:qi,renderSessionNode:An}):null,ai=!!(_||x||g),yi=ur(Le=>Le.enabled),Us=ur(Le=>Le.selectedIds),oi=ur(Le=>Le.scopeKey),Ca=ur,Hl=o.useCallback(()=>{ur.getState().toggleMode()},[]),sr=o.useCallback(()=>{ur.getState().disable()},[]),Er=o.useMemo(()=>{if(Us.size===0||typeof document>"u")return!1;let Le=!1,vt=!1;for(const ft of Us){const Yt=document.querySelectorAll(`[data-session-row="${CSS.escape(ft)}"]`);for(const ps of Yt)ps.getAttribute("data-session-archived")==="1"?vt=!0:Le=!0}return vt&&!Le},[Us]),xn=o.useMemo(()=>{if(oi)return oi;if(Us.size===0||typeof document>"u")return null;for(const Le of Us){const ft=document.querySelector(`[data-session-row="${CSS.escape(Le)}"]`)?.getAttribute("data-session-scope");if(ft&&ft.length>0)return ft}return null},[Us,oi]),Pa=o.useMemo(()=>xn?qe[xn]??[]:[],[qe,xn]),ou=o.useMemo(()=>{if(!xn||Us.size===0)return!1;const Le=qe[xn]??[];for(const vt of Le)for(const ft of vt.sessionIds)if(Us.has(ft))return!0;return!1},[qe,xn,Us]),Ia=o.useCallback(Le=>{!xn||Us.size===0||Ge(xn,Le,Array.from(Us))},[Ge,Us,xn]),Yi=o.useCallback(()=>{if(!xn||Us.size===0)return;const Le=Ct(xn);Le&&Ge(xn,Le.id,Array.from(Us))},[Ge,Ct,Us,xn]),wo=o.useCallback(()=>{!xn||Us.size===0||it(xn,Array.from(Us))},[it,Us,xn]),li=o.useCallback(async()=>{const Le=Array.from(Us);if(Le.length!==0){if(Er){const{deletedIds:vt,failedIds:ft}=await Ns(Le);vt.length>0&&H.success(vt.length===1?a("sessions.sidebar.bulkActions.deletedSingle",{count:vt.length}):a("sessions.sidebar.bulkActions.deletedPlural",{count:vt.length})),ft.length>0&&H.error(ft.length===1?a("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ft.length}):a("sessions.sidebar.bulkActions.failedDeletePlural",{count:ft.length}))}else{const{archivedIds:vt,failedIds:ft}=await sn(Le);vt.length>0&&H.success(vt.length===1?a("sessions.sidebar.bulkActions.archivedSingle",{count:vt.length}):a("sessions.sidebar.bulkActions.archivedPlural",{count:vt.length})),ft.length>0&&H.error(ft.length===1?a("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ft.length}):a("sessions.sidebar.bulkActions.failedArchivePlural",{count:ft.length}))}ur.getState().clear()}},[sn,Er,Ns,Us,a]),Qi=o.useCallback(()=>{const Le=Us.size;if(Le!==0){if(!Je){li();return}F({sessionCount:Le,archivedBucket:Er})}},[Er,li,Us,Je]),jo=o.useCallback(async()=>{F(null),await li()},[li]);o.useEffect(()=>{if(!yi)return;const Le=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),vt=ft=>{if(ai)return;const Yt=ft.target;if(Yt&&(Yt.tagName==="INPUT"||Yt.tagName==="TEXTAREA"||Yt.isContentEditable))return;const ps=Le?ft.metaKey:ft.ctrlKey;if(ft.key==="Escape"){ft.preventDefault(),ur.getState().disable();return}if(ps&&ft.key==="Backspace"){ft.preventDefault(),Qi();return}if(ps&&(ft.key==="a"||ft.key==="A")){const Ws=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Ws.length===0)return;ft.preventDefault();const wr=Ca.getState().scopeKey??Ws[0]?.getAttribute("data-session-scope")??null,nr=un=>wr?un.getAttribute("data-session-scope")===wr:!0,Tn=Ws.filter(nr).map(un=>un.getAttribute("data-session-row")).filter(un=>typeof un=="string"&&un.length>0);if(Tn.length===0)return;Ca.getState().replaceAll(Tn,wr||null)}};return window.addEventListener("keydown",vt),()=>window.removeEventListener("keydown",vt)},[Qi,ai,Ca,yi]);const No=o.useCallback(()=>{q("chat"),t&&L(!1),Wt()},[t,Wt,q,L]),Gl=o.useCallback(()=>{q("chat"),t&&L(!1),Ee()},[t,Ee,q,L]);return s.jsxs("div",{ref:m,className:ce("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[At?s.jsx("div",{onMouseDown:St,className:ce("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",ee),children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Y,className:ht,"aria-label":a("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(P,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Dt,{children:s.jsx("p",{children:a("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(NI,{hideDirectoryControls:r,handleOpenDirectoryDialog:an,handleNewSession:No,canOpenMultiRun:we.length>0,openMultiRunLauncher:Gl,headerActionIconClass:pn,reserveHeaderActionsSpace:Gi,headerActionButtonClass:_s,isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Re,searchMatchCount:Nn,collapseAllProjects:ls,expandAllProjects:Bs,openScheduledTasksDialog:()=>Z(!0),selectionModeEnabled:yi,onToggleSelectionMode:Hl,showSidebarToggle:Mt,onToggleSidebar:Y,avoidWindowControlsOverlay:cs}),s.jsx($I,{topContent:ii,sectionsForRender:tt,projectSections:On,activeProjectId:ke,showOnlyMainWorkspace:i,hasSessionSearchQuery:Re,emptyState:ss,searchEmptyState:ni,renderGroupSessions:ri,homeDirectory:Ne,collapsedProjects:T,hideDirectoryControls:r,projectRepoStatus:S,isDesktopShellRuntime:Qt,stuckProjectHeaders:Mr,mobileVariant:t,alwaysShowActions:Ks,toggleProject:Js,setActiveProjectIdOnly:me,setActiveMainTab:q,setSessionSwitcherOpen:L,openNewSessionDraft:Wt,openNewWorktreeDialog:Qs,openProjectEditDialog:w,removeProject:xe,projectHeaderSentinelRefs:ue,reorderProjects:Ue,getOrderedGroups:bi,setGroupOrderByProject:re,openSidebarMenuKey:V,setOpenSidebarMenuKey:$,isInlineEditing:ai}),yi&&Us.size>0?s.jsx(SA,{selectedCount:Us.size,scopeKey:xn,scopeFolders:Pa,archivedBucket:Er,onMoveToFolder:Ia,onCreateFolderAndMove:Yi,onRemoveFromFolder:wo,canRemoveFromFolder:ou,onDelete:Qi,onDone:sr}):null,s.jsx(TI,{onOpenSettings:Hs,onOpenShortcuts:Pe,onOpenAbout:()=>fe(!0),showRuntimeButtons:!ns}),Rt?s.jsx($y,{open:!!Rt,onOpenChange:Le=>{Le||w(null)},projectId:Rt.id,projectName:Rt.label||Vi(Rt.path,Ne),projectPath:Rt.path,initialIcon:Rt.icon,initialColor:Rt.color,initialIconBackground:Rt.iconBackground,onSave:Ps}):null,s.jsx(Q4,{open:z,onOpenChange:B,onWorktreeCreated:(Le,vt)=>{if(q("chat"),t&&L(!1),vt?.sessionId){lt(vt.sessionId);return}Wt({directoryOverride:Le})}}),s.jsx(kP,{}),s.jsx(wA,{value:Q,setValue:ne,showDeletionDialog:Je,setShowDeletionDialog:de,onConfirm:In}),s.jsx(NA,{value:G,setValue:le,onConfirm:ln}),s.jsx(jA,{value:oe,setValue:F,showDeletionDialog:Je,setShowDeletionDialog:de,onConfirm:jo})]})},LA=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Jr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");let n=e.replace(/\/+$/g,"");return n=n.replace(/\/+/g,"/"),n===""?e.startsWith("/")?"/":"":n},OA=()=>{const{t}=ut(),{runtime:e,files:n}=Pn(),r=Ir()??"",i=Jr(r.trim()),a=Bl(C=>C.searchFiles),l=Ie(C=>C.setSelectedMediaFilePath),c=Ie(C=>C.setCreativeRightSidebarTab),d=Ie(C=>C.setPreviewInfoOpen),[p,m]=o.useState(""),u=ho(p,200),h=o.useRef(null),[x,f]=o.useState([]),[v,y]=o.useState(!1),[g,w]=o.useState({}),[b,k]=o.useState(new Set),I=o.useRef(new Set),j=o.useRef(new Set),N=o.useCallback(async C=>{const S=Jr(C.trim());if(!S||I.current.has(S)||j.current.has(S))return;j.current=new Set(j.current),j.current.add(S),await(e.isDesktop?n.listDirectory(S,{respectGitignore:!0}).then(A=>A.entries.map(R=>({name:R.name,path:R.path,isDirectory:R.isDirectory}))):Zs.listLocalDirectory(S,{respectGitignore:!0})).then(A=>{const R=A.filter(B=>B.name&&!B.name.startsWith(".")).map(B=>{const V=B.name,$=Jr(B.path||"")||Jr(`${S}/${V}`),_=B.isDirectory?"directory":"file",X=_==="file"&&V.includes(".")?V.split(".").pop()?.toLowerCase():void 0;return{name:V,path:$,type:_,extension:X}}),z=LA(R);I.current=new Set(I.current),I.current.add(S),w(B=>({...B,[S]:z}))}).catch(()=>{w(A=>({...A,[S]:A[S]??[]}))}).finally(()=>{j.current=new Set(j.current),j.current.delete(S)})},[n,e.isDesktop]);o.useEffect(()=>{i&&(I.current=new Set,j.current=new Set,w({}),N(i))},[i]),o.useEffect(()=>{if(!i||b.size===0)return;const C=[...b].map(M=>Jr(M)).filter(M=>!!M&&M!==i&&M.startsWith(`${i}/`)&&!I.current.has(M)&&!j.current.has(M)).sort((M,A)=>M.split("/").length-A.split("/").length);if(C.length===0)return;let S=!1;return(async()=>{for(let M=0;M<C.length&&!S;M+=3){const A=C.slice(M,M+3);await Promise.all(A.map(R=>N(R)))}})(),()=>{S=!0}},[b,N,i]),o.useEffect(()=>{if(!r){f([]),y(!1);return}const C=u.trim();if(!C){f([]),y(!1);return}let S=!1;return y(!0),a(r,C,150,{includeHidden:!1,respectGitignore:!0,type:"file"}).then(M=>{if(S)return;const A=M.map(R=>({name:R.name,path:Jr(R.path),type:"file",extension:R.extension}));f(A)}).catch(()=>{S||f([])}).finally(()=>{S||y(!1)}),()=>{S=!0}},[r,u,a]);const D=o.useCallback(C=>{if(C.type==="directory"){const S=Jr(C.path);k(M=>{const A=new Set(M);return A.has(S)?A.delete(S):A.add(S),A}),I.current.has(S)||N(S);return}l(C.path),d(!1),c("preview")},[N,c,d,l]);function E(C,S){return(g[C]??[]).map(A=>{const R=A.type==="directory",z=R&&b.has(Jr(A.path));return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>D(A),className:ce("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors","hover:bg-interactive-hover/40 select-none"),title:A.path,children:[R?z?s.jsx(P,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(P,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(Zn,{filePath:A.path,extension:A.extension}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:A.name})]}),R&&z&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40",children:(()=>{const B=Jr(A.path),V=g[B];return I.current.has(B)&&(!V||V.length===0)?s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground italic",children:t("creative.mediaTree.empty")}):E(A.path)})()})]},A.path)})}const T=!!(i&&g[i]);return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[s.jsx("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:s.jsxs("div",{className:"relative min-w-0 flex-1",children:[s.jsx(P,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Bt,{ref:h,value:p,onChange:C=>m(C.target.value),placeholder:t("creative.mediaTree.searchPlaceholder"),className:"h-8 pl-8 pr-8 typography-meta"}),p.trim().length>0&&s.jsx("button",{type:"button","aria-label":"Clear search",className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{m(""),h.current?.focus()},children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]})}),s.jsx(Cs,{outerClassName:"flex-1 min-h-0",className:"p-2",children:s.jsx("ul",{className:"flex flex-col",children:x.length>0?x.map(C=>s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>D(C),className:"flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors hover:bg-interactive-hover/40 select-none",title:C.path,children:[s.jsx(Zn,{filePath:C.path,extension:C.extension}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:C.name})]})},C.path)):v?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(P,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("creative.mediaTree.loading")]}):T?E(i):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground italic",children:t("creative.mediaTree.empty")})})})]})},$A=[{type:"all",icon:"stack",labelKey:"creative.preview.filter.all"},{type:"image",icon:"file-image",labelKey:"creative.preview.filter.image"},{type:"audio",icon:"music",labelKey:"creative.preview.filter.audio"},{type:"video",icon:"file-video",labelKey:"creative.preview.filter.video"},{type:"model",icon:"folder-3",labelKey:"creative.preview.filter.model"},{type:"document",icon:"file-text",labelKey:"creative.preview.filter.document"}],BA=["public","output"],zA={jpg:"image",jpeg:"image",png:"image",gif:"image",webp:"image",bmp:"image",tiff:"image",tif:"image",svg:"image",mp4:"video",webm:"video",mov:"video",avi:"video",mkv:"video",wmv:"video",flv:"video",m4v:"video",mp3:"audio",wav:"audio",ogg:"audio",flac:"audio",aac:"audio",wma:"audio",m4a:"audio",glb:"model",gltf:"model",obj:"model",stl:"model",fbx:"model",pdf:"document"},VA=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`,_A=t=>["mp4","webm","mov","avi","mkv","wmv","flv","m4v"].includes(t),UA=t=>["mp3","wav","ogg","flac","aac","wma","m4a"].includes(t),WA=t=>["jpg","jpeg","png","gif","webp","bmp","tiff","tif","svg"].includes(t),bf=t=>t.split(".").pop()?.toLowerCase()??"";function KA(t){const e=t.split("."),n=e.length>1?e.pop().toLowerCase():"",r=zA[n];return r?{mediaType:r,extension:n}:null}async function HA(t,e,n){const r=[],i=new Set,a=[];for(const l of e)a.push(`${t}/${l}`);for(;a.length>0;){const l=a.pop();try{const{entries:c}=await n(l,{respectGitignore:!0});for(const d of c){if(d.isDirectory){a.push(d.path);continue}const p=KA(d.name);p&&(i.has(d.path)||(i.add(d.path),r.push({name:d.name,path:d.path,mediaType:p.mediaType,extension:p.extension})))}}catch{}}return r}const GA=()=>{const t=at.c(46),{t:e}=ut(),n=Ie(qA),r=Ie(YA),i=Ie(QA),a=Ie(JA),l=Ir(),{files:c}=Pn(),[d,p]=o.useState(null),[m,u]=o.useState(!1),[h,x]=o.useState(!1);let f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=[],t[0]=f):f=t[0];const[v,y]=o.useState(f),[g,w]=o.useState(!1),[b,k]=o.useState("all");let I,j;t[1]!==l||t[2]!==c?(I=()=>{if(!l){y([]);return}let Q=!1;return w(!0),HA(l,BA,c.listDirectory.bind(c)).then(ne=>{Q||(y(ne),w(!1))}).catch(()=>{Q||w(!1)}),()=>{Q=!0}},j=[l,c],t[1]=l,t[2]=c,t[3]=I,t[4]=j):(I=t[3],j=t[4]),o.useEffect(I,j);let N,D;t[5]!==n?(N=()=>{if(!n){p(null),u(!1),x(!1);return}u(!0),x(!1),fetch(`/api/fs/stat?path=${encodeURIComponent(n)}`).then(XA).then(Q=>{const ne=bf(n);p({name:n.split("/").pop()??"",path:n,size:Q.size??0,type:Q.mime??ne.toUpperCase(),modified:Q.modified?new Date(Q.modified).toLocaleString():"-"}),u(!1)}).catch(()=>{x(!0),u(!1)})},D=[n],t[5]=n,t[6]=N,t[7]=D):(N=t[6],D=t[7]),o.useEffect(N,D);let E;e:{if(b==="all"){E=v;break e}let Q;if(t[8]!==b||t[9]!==v){let ne;t[11]!==b?(ne=G=>G.mediaType===b,t[11]=b,t[12]=ne):ne=t[12],Q=v.filter(ne),t[8]=b,t[9]=v,t[10]=Q}else Q=t[10];E=Q}const T=E;let C;t[13]!==a||t[14]!==r?(C=Q=>{r(Q.path),a(!1)},t[13]=a,t[14]=r,t[15]=C):C=t[15];const S=C;let M;t[16]!==b||t[17]!==e?(M=()=>s.jsx("div",{className:"flex gap-2 px-3 py-2 border-b border-border/40 overflow-x-auto shrink-0",children:$A.map(Q=>s.jsxs("button",{type:"button",onClick:()=>k(Q.type),className:ce("flex items-center gap-1.5 rounded-full px-2.5 py-1 typography-meta whitespace-nowrap transition-colors",b===Q.type?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40"),children:[s.jsx(P,{name:Q.icon,className:"h-3.5 w-3.5"}),e(Q.labelKey)]},Q.type))}),t[16]=b,t[17]=e,t[18]=M):M=t[18];const A=M;let R;t[19]!==T||t[20]!==S||t[21]!==g||t[22]!==n||t[23]!==e?(R=()=>g?s.jsx("div",{className:"flex items-center justify-center py-8",children:s.jsx(P,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}):T.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[s.jsx(P,{name:"file",className:"h-8 w-8 mb-2"}),s.jsx("p",{className:"typography-meta",children:e("creative.preview.noMediaFiles")})]}):s.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 gap-1 p-2",children:T.map(Q=>s.jsxs("button",{type:"button",onClick:()=>S(Q),className:ce("flex flex-col items-center gap-1 rounded-md p-1.5 transition-colors text-left","hover:bg-interactive-hover/40 select-none",n===Q.path&&"bg-interactive-selection/50 ring-1 ring-primary/30"),title:Q.path,children:[s.jsx(Zn,{filePath:Q.path,extension:Q.extension,className:"h-8 w-8"}),s.jsx("span",{className:"w-full truncate text-center typography-small text-muted-foreground",children:Q.name})]},Q.path))}),t[19]=T,t[20]=S,t[21]=g,t[22]=n,t[23]=e,t[24]=R):R=t[24];const z=R;let B;t[25]!==h||t[26]!==d||t[27]!==i||t[28]!==m||t[29]!==n||t[30]!==a||t[31]!==r||t[32]!==e?(B=()=>{if(!n)return null;if(m)return s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx(P,{name:"loader-4",className:"h-6 w-6 animate-spin text-muted-foreground"})});if(h)return s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("p",{className:"typography-meta text-destructive",children:e("creative.preview.notFound")})});const Q=bf(n),ne=WA(Q),G=_A(Q),le=UA(Q);return s.jsxs("div",{className:"border-b border-border/40",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",children:[s.jsx("span",{className:"typography-small font-medium truncate flex-1",children:n.split("/").pop()}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",onClick:()=>a(!i),className:ce("flex h-6 w-6 items-center justify-center rounded-md transition-colors",i?"bg-interactive-selection/70 text-foreground":"text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40"),title:e("layout.rightSidebar.previewInfo"),children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:()=>r(null),className:"flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/40 transition-colors",title:"Close preview",children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx("div",{className:"flex items-center justify-center p-3 max-h-[40vh] overflow-hidden",children:ne?s.jsx("img",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,alt:n.split("/").pop()??"",className:"max-h-full max-w-full object-contain rounded-md"}):G?s.jsx("video",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,controls:!0,className:"max-h-full max-w-full rounded-md"}):le?s.jsxs("div",{className:"flex flex-col items-center gap-3 w-full max-w-sm",children:[s.jsx(P,{name:"music",className:"h-10 w-10 text-muted-foreground"}),s.jsx("audio",{src:`/api/fs/raw?path=${encodeURIComponent(n)}`,controls:!0,className:"w-full"})]}):s.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground py-4",children:[s.jsx(P,{name:"file",className:"h-12 w-12"}),s.jsx("span",{className:"typography-meta",children:Q.toUpperCase()})]})}),i&&d&&s.jsxs("div",{className:"border-t border-border/40 bg-sidebar p-3 overflow-y-auto",children:[s.jsx("h4",{className:"typography-meta font-medium mb-2",children:e("creative.preview.info.title")}),s.jsxs("dl",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.name")}),s.jsx("dd",{className:"typography-meta text-right max-w-[60%] truncate",children:d.name})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.path")}),s.jsx("dd",{className:"typography-meta text-right max-w-[60%] truncate",title:d.path,children:d.path})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.size")}),s.jsx("dd",{className:"typography-meta text-right",children:VA(d.size)})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.type")}),s.jsx("dd",{className:"typography-meta text-right",children:d.type})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("dt",{className:"typography-meta text-muted-foreground",children:e("creative.preview.info.modified")}),s.jsx("dd",{className:"typography-meta text-right",children:d.modified})]})]})]})]})},t[25]=h,t[26]=d,t[27]=i,t[28]=m,t[29]=n,t[30]=a,t[31]=r,t[32]=e,t[33]=B):B=t[33];const V=B;let $;t[34]!==A?($=A(),t[34]=A,t[35]=$):$=t[35];let _;t[36]!==V?(_=V(),t[36]=V,t[37]=_):_=t[37];let X;t[38]!==z?(X=z(),t[38]=z,t[39]=X):X=t[39];let O;t[40]!==_||t[41]!==X?(O=s.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[_,X]}),t[40]=_,t[41]=X,t[42]=O):O=t[42];let J;return t[43]!==$||t[44]!==O?(J=s.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-sidebar",children:[$,O]}),t[43]=$,t[44]=O,t[45]=J):J=t[45],J};function qA(t){return t.selectedMediaFilePath}function YA(t){return t.setSelectedMediaFilePath}function QA(t){return t.isPreviewInfoOpen}function JA(t){return t.setPreviewInfoOpen}function XA(t){if(!t.ok)throw new Error("Not found");return t.json()}const ZA=()=>{const t=at.c(29),{t:e}=ut(),n=Ie(eD),r=Ie(tD);let i;t[0]!==e?(i=e("layout.rightSidebar.media"),t[0]=e,t[1]=i):i=t[1];let a;t[2]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(P,{name:"folder-3",className:"h-3.5 w-3.5"}),t[2]=a):a=t[2];let l;t[3]!==i?(l={id:"media",label:i,icon:a},t[3]=i,t[4]=l):l=t[4];let c;t[5]!==e?(c=e("layout.rightSidebar.preview"),t[5]=e,t[6]=c):c=t[6];let d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(P,{name:"eye",className:"h-3.5 w-3.5"}),t[7]=d):d=t[7];let p;t[8]!==c?(p={id:"preview",label:c,icon:d},t[8]=c,t[9]=p):p=t[9];let m;t[10]!==l||t[11]!==p?(m=[l,p],t[10]=l,t[11]=p,t[12]=m):m=t[12];const u=m;let h;t[13]!==r?(h=w=>r(w),t[13]=r,t[14]=h):h=t[14];let x;t[15]!==n||t[16]!==h||t[17]!==u?(x=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Cr,{items:u,activeId:n,onSelect:h,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[15]=n,t[16]=h,t[17]=u,t[18]=x):x=t[18];let f;t[19]!==n?(f=n==="media"&&s.jsx(OA,{}),t[19]=n,t[20]=f):f=t[20];let v;t[21]!==n?(v=n==="preview"&&s.jsx(GA,{}),t[21]=n,t[22]=v):v=t[22];let y;t[23]!==v||t[24]!==f?(y=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[f,v]}),t[23]=v,t[24]=f,t[25]=y):y=t[25];let g;return t[26]!==y||t[27]!==x?(g=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[x,y]}),t[26]=y,t[27]=x,t[28]=g):g=t[28],g};function eD(t){return t.creativeRightSidebarTab}function tD(t){return t.setCreativeRightSidebarTab}const sD=()=>{const t=at.c(13),[e,n]=Be.useState(!1);let r,i;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(gn())},i=[],t[0]=r,t[1]=i):(r=t[0],i=t[1]),Be.useEffect(r,i);let a;t[2]!==e?(a=async h=>e?await Vy(h):{success:!0,path:h},t[2]=e,t[3]=a):a=t[3];const l=a;let c;t[4]!==e?(c=async h=>e?await _y():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async h=>e?await Uy():{success:!0},t[6]=e,t[7]=p):p=t[7];const m=p;let u;return t[8]!==e||t[9]!==l||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:l,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=l,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},nD=t=>t==="/",Al=t=>t.replace(/\\/g,"/"),ru=t=>{if(!t||nD(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},ma=t=>t.endsWith("/"),rD=t=>{const e=t.trim();return!e||ma(e)?e:`${e}/`},iu=t=>t.lastIndexOf("/"),_g=t=>{if(ma(t))return t;const e=iu(t);return e<0?t:t.slice(0,e+1)},iD=t=>{const e=iu(t);return t.slice(e+1)},Ug=t=>{const e=ru(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=iu(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},aD=t=>ma(t)&&Ug(t)!==null,yf=(t,e)=>`${_g(t)}${e}/`,Zi=t=>{if(!t)return null;const e=ru(Al(t.trim()));return e?e.toLowerCase():null},vf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},oD=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,_c=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},lD=async()=>{try{const t=await fetch("/api/fs/home",{method:"GET",headers:{Accept:"application/json"}});if(t.ok){const e=await t.json();if(typeof e.home=="string"&&e.home.trim().length>0)return Al(e.home.trim())}}catch{}return Zs.getFilesystemHome().catch(()=>null)},cD=({open:t,onOpenChange:e})=>{const{t:n}=ut(),r=$s(Te=>Te.homeDirectory),i=As(Te=>Te.projects),a=As(Te=>Te.addProject),l=Qn(Te=>Te.profiles),c=Qn(Te=>Te.globalIdentity),d=Qn(Te=>Te.defaultGitIdentityId),p=Qn(Te=>Te.loadProfiles),m=Qn(Te=>Te.loadGlobalIdentity),u=Qn(Te=>Te.loadDefaultGitIdentityId),h=$l(),{isDesktop:x,requestAccess:f,startAccessing:v}=sD(),{isMobile:y}=rn(),g=o.useRef(null),w=o.useRef(null),b=o.useRef(new Map),[k,I]=o.useState(""),[j,N]=o.useState("~/"),[D,E]=o.useState([]),[T,C]=o.useState(!1),[S,M]=o.useState(!1),[A,R]=o.useState(0),[z,B]=o.useState(!1),[V,$]=o.useState(!1),[_,X]=o.useState(0),[O,J]=o.useState(!1),[Q,ne]=o.useState(""),[G,le]=o.useState(null),[oe,F]=o.useState(!1),[U,W]=o.useState(""),[te,K]=o.useState(!1),ae=k||r,ve=o.useMemo(()=>new Set(i.map(Te=>Zi(Te.path)).filter(Te=>!!Te)),[i]);o.useEffect(()=>{if(!t)return;N("~/"),E([]),R(0),B(!1),$(!1),J(!1),ne(""),le(null),F(!1),W(""),K(!1),requestAnimationFrame(()=>_c(g.current));let Te=!1;return(async()=>{const Ze=await lD();Te||(I(Ze||r||""),requestAnimationFrame(()=>_c(g.current)))})(),()=>{Te=!0}},[r,t]),o.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const re=o.useMemo(()=>{const Te=new Map;c&&Te.set(c.id,c);for(const We of l)Te.set(We.id,We);return Array.from(Te.values())},[l,c]);o.useEffect(()=>{if(!t||!O||G!==null)return;const Te=typeof d=="string"?d.trim():"";if(Te&&re.some(Ze=>Ze.id===Te)){le(Te);return}const We=re.find(Ze=>Ze.authType==="ssh"||Ze.sshKey);We&&le(We.id)},[re,d,O,t,G]);const be=o.useMemo(()=>re.find(Te=>Te.id===G)??null,[re,G]),pe=o.useMemo(()=>_g(j),[j]),ye=o.useMemo(()=>ma(j)?"":iD(j),[j]),ie=o.useMemo(()=>ae?vf(pe,ae):"",[pe,ae]);o.useEffect(()=>{if(!t||!ie){E([]);return}let Te=!1;return C(!0),M(!1),Zs.listLocalDirectory(ie).then(We=>{if(Te)return;M(!1);const Ze=We.filter(Qe=>Qe.isDirectory).map(Qe=>({name:Qe.name,path:Al(Qe.path)})).sort((Qe,he)=>Qe.name.localeCompare(he.name));E(Ze)}).catch(()=>{Te||(E([]),M(!0))}).finally(()=>{Te||C(!1)}),()=>{Te=!0}},[ie,t]);const ue=o.useMemo(()=>{const Te=ye.toLowerCase(),We=h||ye.startsWith(".");return D.filter(Ze=>Ze.name.toLowerCase().startsWith(Te)&&(We||!Ze.name.startsWith(".")))},[ye,D,h]),se=o.useMemo(()=>{const Te=[];aD(j)&&Te.push({type:"up",value:"browse:up",name:"..",path:Ug(j)});for(const We of ue){const Ze=Zi(We.path);Te.push({type:"directory",value:`browse:${We.path}`,name:We.name,path:We.path,disabled:!!(Ze&&ve.has(Ze))})}return Te},[ve,ue,j]);o.useEffect(()=>{R(0)},[j,se.length]);const Ne=o.useMemo(()=>ae?ru(vf(j,ae)):"",[ae,j]),Ce=Zi(Ne),je=!!(Ce&&ve.has(Ce)),we=o.useMemo(()=>ye?ue.find(Te=>Te.name===ye)??null:null,[ye,ue]),ke=!!(Ne&&!je&&(ma(j)&&S||!ma(j)&&ye.trim().length>0&&we===null)),xe=!z&&!V&&!je&&!!Ne,me=xe&&Q.trim().length>0,Me=se[A]??null,Ue=!!(Me&&(Me.type==="up"||Me.type==="directory"&&!Me.disabled)),q=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Se=n(je?"directoryExplorerDialog.actions.alreadyAdded":O?z?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":z?"directoryExplorerDialog.actions.adding":ke?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const Te=w.current;if(!Te)return;const We=()=>X(Math.ceil(Te.getBoundingClientRect().width));if(We(),typeof ResizeObserver>"u")return;const Ze=new ResizeObserver(We);return Ze.observe(Te),()=>Ze.disconnect()},[Se]),o.useLayoutEffect(()=>{const Te=g.current;Te&&(Te.scrollLeft=Te.scrollWidth)},[_,j]),o.useLayoutEffect(()=>{t&&_c(g.current)},[t]),o.useLayoutEffect(()=>{const Te=se[A];Te&&b.current.get(Te.value)?.scrollIntoView({block:"nearest"})},[A,se]);const $e=o.useCallback(()=>{e(!1)},[e]),Pe=o.useCallback(async Te=>{if(!Te||z)return;const We=Zi(Te);if(We&&ve.has(We))return;let Ze=Te;B(!0);try{const Qe=!O&&ke&&Zi(Te)===Zi(Ne);if(O){const Ge=Q.trim();if(!Ge){H.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}Ze=(await Zs.cloneRepository({remoteUrl:Ge,destinationPath:Te,gitIdentityId:be?.id??null})).path}else Qe&&await Zs.createDirectory(Te,{allowOutsideWorkspace:!0,initializeTemplate:!0});if(!a(Ze)){H.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}$e()}catch(Qe){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Qe instanceof Error?Qe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{B(!1)}},[a,ve,Q,$e,O,z,be?.id,ke,Ne,n]),fe=o.useCallback(Te=>{N(rD(Te))},[]),L=o.useCallback(Te=>{N(yf(j,Te.name))},[j]),Z=o.useCallback(Te=>{if(Te){if(Te.type==="up"){Te.path&&fe(Te.path);return}Te.disabled||L(Te)}},[fe,L]),Y=o.useCallback(async()=>{if(!(!x||V)){$(!0);try{const Te=await f(Ne);if(!Te.success||!Te.path){Te.error&&Te.error!=="Directory selection cancelled"&&H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te.error});return}const We=await v(Te.path);if(!We.success){H.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:We.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Pe(Te.path)}catch(Te){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Te instanceof Error?Te.message:n("directoryExplorerDialog.toast.unknownError")})}finally{$(!1)}}},[Pe,x,V,f,v,n,Ne]),Ee=o.useCallback(Te=>{if(Te.key==="ArrowDown"){Te.preventDefault(),R(We=>Math.min(se.length-1,We+1));return}if(Te.key==="ArrowUp"){Te.preventDefault(),R(We=>Math.max(0,We-1));return}if(Te.key==="Enter"){if(Te.preventDefault(),oD(Te)){Pe(Ne);return}Ue&&Z(Me);return}Te.key==="Backspace"&&j===""&&(Te.preventDefault(),$e())},[Z,Pe,$e,Ue,Me,j,se.length,Ne]),Ae=o.useCallback(async()=>{const Te=U.trim();if(!(!Te||te)){K(!0);try{const We=`${ie}${Te}`;await Zs.createDirectory(We,{allowOutsideWorkspace:!0,initializeTemplate:!0}),H.success(n("directoryExplorerDialog.toast.folderCreated")),N(yf(j,Te)),F(!1),W("")}catch(We){H.error(n("directoryExplorerDialog.toast.failedToCreateFolder"),{description:We instanceof Error?We.message:n("directoryExplorerDialog.toast.unknownError")})}finally{K(!1)}}},[U,te,ie,j,n]),Je=o.useCallback(Te=>{Te.stopPropagation(),Te.key==="Enter"?(Te.preventDefault(),Ae()):Te.key==="Escape"&&(Te.preventDefault(),F(!1),W(""))},[Ae]),de=s.jsxs("button",{type:"button",onClick:()=>Qo(!h),className:"flex flex-shrink-0 items-center gap-2 rounded-lg px-2 py-1 typography-meta text-muted-foreground transition-colors hover:bg-interactive-hover/40",children:[h?s.jsx(P,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),ze=s.jsxs("div",{className:"px-2.5 py-1.5",children:[O?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Bt,{value:Q,onChange:Te=>ne(Te.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx($h,{activeProfile:be,identities:re,onSelect:Te=>le(Te.id),isApplying:z,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(P,{name:"folder-add",className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/80"}),s.jsx(Bt,{ref:g,value:j,onChange:Te=>N(Al(Te.target.value)),onKeyDown:Ee,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!y&&_>0?{paddingRight:`${_+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),y?null:s.jsx(ge,{ref:w,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:O?!me:!xe,onMouseDown:Te=>Te.preventDefault(),onClick:()=>{Pe(Ne)},title:Se,children:Se})]})]}),rt=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsxs("div",{className:"flex items-center justify-between px-2 pb-1 pt-0.5",children:[s.jsx("div",{className:"typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),!O&&!oe&&s.jsxs("button",{type:"button",onClick:()=>{F(!0),W(""),K(!1)},className:"flex items-center gap-1 rounded px-1.5 py-0.5 typography-meta text-primary hover:bg-primary/10 transition-colors",children:[s.jsx(P,{name:"folder-add",className:"h-3.5 w-3.5"}),s.jsx("span",{children:n("directoryExplorerDialog.actions.newFolder")})]})]}),T?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):se.length===0&&!oe?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.empty")}):s.jsxs("div",{className:"space-y-0.5",children:[oe&&s.jsxs("div",{className:"flex w-full items-center gap-2 rounded-lg px-2 py-1 border border-primary/40 bg-interactive-hover/30",children:[s.jsx(P,{name:"folder-add",className:"h-4 w-4 flex-shrink-0 text-primary"}),s.jsx("input",{type:"text",value:U,onChange:Te=>W(Te.target.value),onKeyDown:Je,placeholder:n("directoryExplorerDialog.newFolder.placeholder"),className:"min-w-0 flex-1 bg-transparent border-none outline-none font-mono typography-ui-label text-foreground placeholder:text-muted-foreground/60",autoFocus:!0,disabled:te}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{type:"button",disabled:te||!U.trim(),onClick:Ae,title:n("directoryExplorerDialog.newFolder.confirm"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-primary",children:s.jsx(P,{name:"check",className:"h-4 w-4"})}),s.jsx("button",{type:"button",disabled:te,onClick:()=>{F(!1),W("")},title:n("directoryExplorerDialog.newFolder.cancel"),className:"flex h-6 w-6 items-center justify-center rounded hover:bg-interactive-hover transition-colors disabled:opacity-40 text-muted-foreground",children:s.jsx(P,{name:"close",className:"h-4 w-4"})})]})]}),se.map((Te,We)=>{const Ze=We===A;return s.jsxs("button",{ref:Qe=>{Qe?b.current.set(Te.value,Qe):b.current.delete(Te.value)},type:"button",disabled:Te.type==="directory"&&Te.disabled,onMouseEnter:()=>R(We),onMouseDown:Qe=>Qe.preventDefault(),onClick:()=>Z(Te),className:ce("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ze&&"bg-interactive-selection text-interactive-selection-foreground",!Ze&&"hover:bg-interactive-hover/50",Te.type==="directory"&&Te.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Te.type==="up"?s.jsx(P,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(P,{name:"folder-6",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:Te.name})}),Te.type==="directory"&&Te.disabled?s.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):null]},Te.value)})]})]})}),Re=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[ze,rt]}),Xe=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(P,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(P,{name:"arrow-down-s",className:"-ml-1 h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.navigate")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(P,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:q}),s.jsx(P,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),qe=()=>s.jsxs(s.Fragment,{children:[y?null:Xe,s.jsxs("div",{className:ce("flex w-full flex-row justify-end gap-2 sm:w-auto",y&&"justify-stretch"),children:[x?s.jsx(ge,{variant:"ghost",size:"xs",onClick:Y,disabled:z||V||O,children:n(V?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(ge,{variant:"ghost",size:"xs",onClick:()=>J(Te=>!Te),disabled:z||V,className:ce(y&&"flex-1"),children:n(O?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),y?s.jsx(ge,{size:"xs",onClick:()=>{Pe(Ne)},disabled:O?!me:!xe,className:"flex-1",children:Se}):null]})]});return y?s.jsx($r,{open:t,onClose:$e,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:qe()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:de}),Re]})}):s.jsx(hs,{open:t,onOpenChange:e,children:s.jsxs(fs,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(bs,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(gs,{children:n("directoryExplorerDialog.title")}),s.jsx(Is,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),de]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:Re}),s.jsx(Vs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:qe()})]})})},Ci=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Fr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},dD=()=>{const{t}=ut(),[e,n]=o.useState(!1),[r,i]=o.useState(!1),[a,l]=o.useState(null),[c,d]=o.useState([]),[p,m]=o.useState(!1),[u,h]=o.useState(!1),[x,f]=o.useState(!1),[v,y]=o.useState(!1),[g,w]=o.useState(new Set),b=Ot(se=>se.getWorktreeMetadata),k=Ot(se=>se.newSessionDraft),I=Ot(se=>se.setNewSessionDraftTarget),j=Ot(se=>se.setDraftBootstrapPendingDirectory),N=Wy,D=Gy,E=Ot(se=>se.deleteSessions),T=Ot(se=>se.archiveSessions),C=Ie(se=>se.showDeletionDialog),S=Ie(se=>se.setShowDeletionDialog),M=$s(se=>se.currentDirectory),A=$s(se=>se.homeDirectory),R=$s(se=>se.isHomeReady),z=As(se=>se.projects),B=As(se=>se.activeProjectId),{isMobile:V,isTablet:$,hasTouchInput:_}=rn(),X=V||$||_,O=o.useMemo(()=>{const Ne=(B?z.find(Ce=>Ce.id===B)??null:null)?.path??M;return Fr(Ne)},[B,M,z]),J=o.useCallback(se=>{const Ce=Fr(se.projectDirectory)||O;return{id:(z.find(we=>Fr(we.path)===Ce)??null)?.id??`path:${Ce}`,path:Ce}},[O,z]),Q=v&&g.size>0,ne=o.useMemo(()=>{const se=a?.worktree;return se&&typeof se.branch=="string"&&se.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Ne})=>typeof Ne.branch=="string"&&Ne.branch.trim().length>0)},[a?.worktree,c]),G=a?.mode==="worktree",le=G,oe=x||!G||!ne,F=x||!G;o.useEffect(()=>{r||!R||z.length>0||(i(!0),n(!0))},[r,R,z.length]);const U=o.useCallback(se=>{l({sessions:se.sessions,dateLabel:se.dateLabel,mode:se.mode??"session",worktree:se.worktree??null})},[]),W=o.useCallback(()=>{l(null),d([]),m(!1),h(!1),f(!1),y(!1),w(new Set)},[]),te=o.useCallback(async se=>{if(se.sessions.length===0)return;if(se.sessions.length===1){const we=se.sessions[0];await N(we.id)?H.success(t("sessions.sidebar.session.delete.success")):H.error(t("sessions.sidebar.session.delete.error"));return}const Ne=se.sessions.map(we=>we.id),{deletedIds:Ce,failedIds:je}=await E(Ne);if(Ce.length>0){const we=je.length>0?je.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:je.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:je.length}):se.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:se.dateLabel}):void 0;H.success(Ce.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ce.length}),{description:Ci(we)})}je.length>0&&H.error(je.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:je.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:je.length}),{description:Ci(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[N,E,t]);o.useEffect(()=>Sr.onDeleteRequest(se=>{if(!C&&(se.mode??"session")==="session"){te(se);return}U(se)}),[U,C,te]),o.useEffect(()=>Sr.onDirectoryRequest(()=>{n(!0)}),[]),o.useEffect(()=>{if(!a){d([]),m(!1),h(!1),y(!1),w(new Set);return}const se=a.sessions.map(je=>{const we=b(je.id);return we?{session:je,metadata:we}:null}).filter(je=>!!je);d(se),m(!1),y(!1),w(new Set);const Ne=new Map;if(a.worktree?.path&&Ne.set(Fr(a.worktree.path),a.worktree),se.forEach(({metadata:je})=>{je.path&&Ne.set(Fr(je.path),je)}),Ne.size===0){y(!0);return}let Ce=!1;return(async()=>{const je=new Map,we=new Set;await Promise.all(Array.from(Ne.entries()).map(async([ke,xe])=>{try{const me=await Ky(xe.path);je.set(ke,me),me?.isDirty&&we.add(ke)}catch{xe.status&&(je.set(ke,xe.status),xe.status.isDirty&&we.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!Ce&&(w(we),y(!0),l(ke=>{if(!ke?.worktree?.path)return ke;const xe=Fr(ke.worktree.path),me=je.get(xe);if(!me)return ke;const Me=ke.worktree.status;return Me?.isDirty===me.isDirty&&Me?.ahead===me.ahead&&Me?.behind===me.behind&&Me?.upstream===me.upstream?ke:{...ke,worktree:{...ke.worktree,status:me}}}),d(ke=>ke.map(xe=>{const me=Fr(xe.metadata.path),Me=je.get(me);return Me?{session:xe.session,metadata:{...xe.metadata,status:Me}}:xe})))})(),()=>{Ce=!0}},[a,b]),o.useEffect(()=>{ne||m(!1)},[ne]);const K=o.useCallback(async(se,Ne)=>{const Ce=p&&ne,je=J(se),we=Fr(se.path),ke=Fr(je.path);try{await Hy(je,se,{deleteRemoteBranch:Ce,deleteLocalBranch:Ne});const xe=Fr(k?.directoryOverride);return k?.open&&we&&xe===we&&ke&&(j(null),I({projectId:je.id,directoryOverride:ke},{force:!0})),Fr(M)===we&&ke&&$s.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(xe){return H.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Ci(xe instanceof Error?xe.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ne,M,p,J,k?.directoryOverride,k?.open,j,I,t]),ae=o.useCallback(async()=>{if(a){f(!0);try{const se=le,Ne=se&&p,Ce=se&&u;if(a.sessions.length===0&&G&&a.worktree){if(!await K(a.worktree,Ce)){W();return}const ke=t(p&&ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");H.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Ci(ke)}),W();return}if(a.sessions.length===1){const je=a.sessions[0];if(!(G?await D(je.id):await N(je.id,{archiveWorktree:!1,deleteRemoteBranch:Ne,deleteLocalBranch:Ce}))){H.error(t(G?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),f(!1);return}const ke=!G&&se?t(Ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;H.success(t(G?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Ci(ke),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const je=a.sessions.map(xe=>xe.id);let we=[],ke=[];if(G){const xe=await T(je);we=xe.archivedIds,ke=xe.failedIds}else{const xe=await E(je);we=xe.deletedIds,ke=xe.failedIds}if(G&&a.worktree&&ke.length===0&&await K(a.worktree,Ce),we.length>0){const xe=!G&&se?t(Ne?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Me=[ke.length>0?G?ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:ke.length}):ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ke.length}):a.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:a.dateLabel}):void 0,xe].filter(Boolean).join(" ");H.success(G?we.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:we.length}):we.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:we.length}),{description:Ci(Me||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ke.length>0&&(H.error(G?ke.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:ke.length}):ke.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ke.length}),{description:Ci(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),we.length===0)){f(!1);return}}G&&a.sessions.length===1&&a.worktree&&await K(a.worktree,Ce),W()}finally{f(!1)}}},[a,p,u,N,E,D,T,W,le,G,ne,K,t]),ve=a?.worktree??c[0]?.metadata??null,re=a?a.mode==="worktree"?a.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):a.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:a.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:a.sessions.length}):a.sessions.length===1?a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):a.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:a.sessions.length,dateLabel:a.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:a.sessions.length}):"",be=a?s.jsxs("div",{className:ce(G?"space-y-3":"space-y-2"),children:[a.sessions.length>0&&s.jsxs("div",{className:ce(G?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[G&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:a.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:a.sessions.length})]}),s.jsxs("ul",{className:ce(G?"mt-2 space-y-1":"space-y-0.5"),children:[a.sessions.slice(0,5).map(se=>s.jsxs("li",{className:ce(G?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:ce(!G&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:se.title||t("sessions.sidebar.session.untitled")})]},se.id)),a.sessions.length>5&&s.jsx("li",{className:ce(G?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:a.sessions.length-5})})]})]}),G?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),ve?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ve.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ve?ro(ve.path,A):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Q&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,pe=G?ne?s.jsxs("button",{type:"button",onClick:()=>{oe||m(se=>!se)},disabled:oe,className:ce("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",oe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,ye=G?s.jsxs("button",{type:"button",onClick:()=>{F||h(se=>!se)},disabled:F,className:ce("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",F?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(P,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ie=G?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[ye,pe]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"ghost",onClick:W,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{variant:"destructive",onClick:ae,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>S(!C),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!C,children:[C?s.jsx(P,{name:"checkbox-blank",className:"size-4"}):s.jsx(P,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ge,{variant:"ghost",onClick:W,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ge,{variant:"destructive",onClick:ae,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ue=G?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):a?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[X?s.jsx($r,{open:!!a,onClose:()=>{x||W()},title:ue,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ie}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[re&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:re}),be]})}):s.jsx(hs,{open:!!a,onOpenChange:se=>{if(!se){if(x)return;W()}},children:s.jsxs(fs,{className:ce(G?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(bs,{children:[s.jsxs(gs,{className:ce(G&&"flex items-center gap-2"),children:[G&&s.jsx(P,{name:"delete-bin",className:"h-5 w-5"}),ue]}),re&&s.jsx(Is,{children:re})]}),s.jsx("div",{className:ce(G&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:be}),s.jsx(Vs,{className:"mt-2 gap-2 pt-1 pb-1",children:ie})]})}),s.jsx(cD,{open:e,onOpenChange:n})]})},Cd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),uD=(t,e)=>{const n=Cd(t),r=Cd(e);return`${n}-${r}`.substring(0,60)},wf=(t,e)=>`${t}/${e}`,mD=()=>{const t=As.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(i=>i.id===e);if(n?.path)return{id:n.id,path:n.path};const r=$s.getState().currentDirectory??null;if(r&&r.trim().length>0){const i=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${i}`,path:i}}return null},Uc=gr()(Na(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:i,agent:a,files:l,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(i.length<1)return t({error:"Select at least 1 model"}),null;if(i.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=mD();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path,u=await nh(p)&&e.isolateRuns!==!1,h=Cd(n),x=u?await fo(p):void 0,f=u?await qy(p):null,v=[],y=c?.filter(N=>N.trim().length>0)??[],g=new Map;for(const N of i){const D=`${N.providerID}:${N.modelID}`;g.set(D,(g.get(D)||0)+1)}const w=new Map;for(const N of i){const D=`${N.providerID}:${N.modelID}`,E=g.get(D)||1,T=(w.get(D)||0)+1;w.set(D,T);const C=uD(N.providerID,N.modelID),S=E>1?wf(h,`${C}/${T}`):wf(h,C);try{const M=E>1?`${h}/${N.providerID}/${N.modelID}/${T}`:`${h}/${N.providerID}/${N.modelID}`;if(!u){const B=await Zs.withDirectory(p,()=>Zs.createSession({title:M}));v.push({sessionId:B.id,worktreePath:p,providerID:N.providerID,modelID:N.modelID,variant:N.variant});continue}const A=await Yy(d,{preferredName:S,mode:"new",branchName:S,worktreeName:S,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:y},{resolvedRootTrackingRemote:f}),R={...A,createdFromBranch:x,kind:"standard"},z=await Zs.withDirectory(A.path,()=>Zs.createSession({title:M}));Ot.getState().setWorktreeMetadata(z.id,R),v.push({sessionId:z.id,worktreePath:A.path,providerID:N.providerID,modelID:N.modelID,variant:N.variant})}catch(M){console.warn("[MultiRun] Failed to create session:",M)}}const b=c?.filter(N=>N.trim().length>0)??[];b.length>0&&rh(d,b).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const k=v.map(N=>N.sessionId),I=v[0]?.sessionId??null;if(k.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=l?.map(N=>({type:"file",mime:N.mime,filename:N.filename,url:N.url}));return(async()=>{try{await Promise.allSettled(v.map(async N=>{try{await Zs.withDirectory(N.worktreePath,()=>Zs.sendMessage({id:N.sessionId,providerID:N.providerID,modelID:N.modelID,variant:N.variant,text:r,agent:a,files:j}))}catch(D){console.warn("[MultiRun] Failed to start run:",D)}}))}catch(N){console.warn("[MultiRun] Failed to start runs:",N)}})(),t({isLoading:!1}),{groupSlug:h,sessionIds:k,firstSessionId:I}}catch(d){return t({error:d instanceof Error?d.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),pD="oc:lastWorktreeSourceBranch";function Wg(t){const e=at.c(30),{git:n}=Pn(),r=Rd(t),i=Ed(t),a=Fd(t),l=ch(t),c=tn(bD),d=tn(xD);let p,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==i||e[4]!==a?(p=()=>{!t||!n||i!==null||a||d(t,n,{silent:!0})},m=[t,n,d,i,a],e[0]=t,e[1]=d,e[2]=n,e[3]=i,e[4]=a,e[5]=p,e[6]=m):(p=e[5],m=e[6]),o.useEffect(p,m);let u;e[7]!==r?.all||e[8]!==t||e[9]!==c||e[10]!==n||e[11]!==i?(u=()=>{!t||!n||i===!0&&(r?.all||c(t,n))},e[7]=r?.all,e[8]=t,e[9]=c,e[10]=n,e[11]=i,e[12]=u):u=e[12];const h=r?.all;let x;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==i||e[17]!==h?(x=[t,n,i,h,c],e[13]=t,e[14]=c,e[15]=n,e[16]=i,e[17]=h,e[18]=x):x=e[18],o.useEffect(u,x);const f=a||i===!0&&l;let v;e:{if(!r?.all){let N;e[19]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[19]=N):N=e[19],v=N;break e}let j;e[20]!==r.all?(j=r.all.filter(gD).sort(),e[20]=r.all,e[21]=j):j=e[21],v=j}const y=v;let g;e:{if(!r?.all){let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[22]=N):N=e[22],g=N;break e}let j;e[23]!==r.all?(j=r.all.filter(hD).map(fD).sort(),e[23]=r.all,e[24]=j):j=e[24],g=j}const w=g;let b;e:{if(!t){b=null;break e}if(i!==null){b=i;break e}if(f){b=null;break e}b=r?.all?!0:null}const k=b;let I;return e[25]!==k||e[26]!==f||e[27]!==y||e[28]!==w?(I={localBranches:y,remoteBranches:w,isLoading:f,isGitRepository:k},e[25]=k,e[26]=f,e[27]=y,e[28]=w,e[29]=I):I=e[29],I}function fD(t){return t.replace(/^remotes\//,"")}function hD(t){return t.startsWith("remotes/")}function gD(t){return!t.startsWith("remotes/")}function xD(t){return t.fetchStatus}function bD(t){return t.fetchBranches}const yD=({directory:t,value:e,onChange:n,className:r,disabled:i,id:a})=>{const{t:l}=ut(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=Wg(t),u=o.useMemo(()=>[...c,...d.map(x=>`remotes/${x}`)],[c,d]);o.useEffect(()=>{if(i||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const f=t?await fo(t).catch(()=>null):null,v=localStorage.getItem(pD);v&&u.includes(v)?n(v):f&&u.includes(f)?n(f):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,i,p,n,e]);const h=i||!m||p;return s.jsxs("div",{children:[s.jsxs(is,{value:e,onValueChange:n,disabled:h,children:[s.jsx(as,{id:a,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(us,{placeholder:l(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(os,{className:"max-h-[280px] max-w-[320px]",children:p?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.loadingBranches")}):c.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(Xc,{children:[s.jsx(Vu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.localBranches")}),c.map(x=>s.jsx(Ft,{value:x,className:"whitespace-normal break-all",children:x},x))]}),c.length>0&&d.length>0&&s.jsx(Qy,{}),d.length>0&&s.jsxs(Xc,{children:[s.jsx(Vu,{className:"font-semibold text-foreground",children:l("multiRun.branchSelector.groups.remoteBranches")}),d.map(x=>s.jsx(Ft,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:l("multiRun.branchSelector.status.notInGitRepository")})]})},vD=10*1024*1024,Wc=5,Ko=t=>{const e=at.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(P,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let i;return e[1]!==n?(i=s.jsxs(Pt,{children:[r,s.jsx(Dt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=i):i=e[2],i},ea=t=>{const e=at.c(9),{htmlFor:n,required:r,children:i,info:a}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let c;e[2]!==i||e[3]!==n||e[4]!==l?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[i,l]}),e[2]=i,e[3]=n,e[4]=l,e[5]=c):c=e[5];const d=a&&a;let p;return e[6]!==c||e[7]!==d?(p=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8],p},wD=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:i}=ut(),[a,l]=o.useState(""),[c,d]=o.useState(()=>t??""),[p,m]=o.useState([]),[u,h]=o.useState(""),[x,f]=o.useState([]),[v,y]=o.useState(!1),[g,w]=o.useState([]),[b,k]=o.useState(!1),[I,j]=o.useState(!1),[N,D]=o.useState(!0),[E,T]=o.useState(!1),[C,S]=o.useState(""),[M,A]=o.useState(!1),[R,z]=o.useState(""),B=o.useRef(null),V=o.useRef(null),$=o.useRef(null),_=o.useRef(null),X=$s(Re=>Re.currentDirectory??null),O=$s(Re=>Re.homeDirectory??null),J=o.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Re=="string"&&Re.trim().length>0?Re.trim():null},[]),Q=As(Re=>Re.activeProjectId),ne=As(Re=>Re.setActiveProjectIdOnly),G=As(Re=>Re.projects),[le,oe]=o.useState(()=>Q??null);o.useEffect(()=>{if(Q){oe(Q);return}!le&&G.length>0&&oe(G[0].id)},[Q,G,le]);const F=o.useMemo(()=>le?G.find(Re=>Re.id===le)??null:null,[G,le]),U=F?.path??X,W=o.useCallback(Re=>{oe(Re),Re!==Q&&ne(Re)},[Q,ne]),{currentTheme:te}=Ar(),K=o.useCallback(Re=>{const Xe=Re.label?.trim()||Vi(Re.path,O),qe=xo({id:Re.id,iconImage:Re.iconImage??null},{themeVariant:te.metadata.variant,iconColor:te.colors.surface.foreground}),Te=Re.icon?Vl[Re.icon]:null,We=Re.color?bo[Re.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[qe?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Re.iconBackground?{backgroundColor:Re.iconBackground}:void 0,children:s.jsx("img",{src:qe,alt:"",className:"h-full w-full object-contain",draggable:!1})}):Te?s.jsx(P,{name:Te,className:"h-3.5 w-3.5 shrink-0",style:We?{color:We}:void 0}):s.jsx(P,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:We?{color:We}:void 0}),s.jsx("span",{className:"truncate",children:Xe})]})},[O,te.metadata.variant,te.colors.surface.foreground]),ae=o.useMemo(()=>{if(F?.path)return{id:F.id,path:F.path};const Re=X??J;return Re?{id:`path:${Re}`,path:Re}:null},[F,X,J]),[ve,re]=o.useState(()=>typeof window>"u"?!1:gn()),be=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),pe=El();o.useEffect(()=>{typeof window>"u"||re(gn())},[]);const ye=o.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__APP_MACOS_MAJOR__;if(typeof Re=="number"&&Number.isFinite(Re)&&Re>0)return Re;if(typeof navigator>"u")return null;const Xe=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Xe)return null;const qe=Number.parseInt(Xe[1],10),Te=Number.parseInt(Xe[2],10);return Number.isNaN(qe)?null:qe===10?Te:qe},[]),ie=o.useMemo(()=>ve&&be||pe?"pl-[5.5rem]":"pl-3",[ve,be,pe]),ue=o.useMemo(()=>!ve||!be||ye===null?"":ye>=26?"h-12":ye<=15?"h-14":"",[ve,be,ye]),se=o.useCallback(async Re=>{Re.target.closest("button, a, input, select, textarea")||Re.button===0&&ve&&await fh()},[ve]);o.useEffect(()=>{if(!n)return;const Re=Xe=>{Xe.key==="Escape"&&(Xe.preventDefault(),Xe.stopPropagation(),n())};return window.addEventListener("keydown",Re,!0),()=>window.removeEventListener("keydown",Re,!0)},[n]);const[Ne,Ce]=o.useState(""),{isLoading:je,isGitRepository:we}=Wg(U),ke=o.useRef(!1),xe=we===!0,me=xe&&N;o.useEffect(()=>{if(we===!1){ke.current=!0,D(!1);return}we===!0&&ke.current&&(ke.current=!1,D(!0))},[we]);const Me=Uc(Re=>Re.createMultiRun),Ue=Uc(Re=>Re.error),q=Uc(Re=>Re.clearError);o.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Re=>Re.trim().length>0?Re:t)},[t]),o.useEffect(()=>{if(!ae)return;let Re=!1;return j(!0),(async()=>{try{const Xe=await zd(ae);Re||w(Xe)}catch{}finally{Re||j(!1)}})(),()=>{Re=!0}},[ae]);const Se=Re=>{p.length>=Wc||(m(Xe=>[...Xe,Re]),q())},$e=Re=>{m(Xe=>Xe.filter((qe,Te)=>Te!==Re)),q()},Pe=o.useCallback((Re,Xe)=>{m(qe=>qe.map((Te,We)=>We===Re?Xe:Te))},[]),fe=async Re=>{const Xe=Re.target.files;if(!Xe)return;let qe=0;for(let Te=0;Te<Xe.length;Te++){const We=Xe[Te];if(We.size>vD){H.error(i("multirun.launcher.toast.fileTooLarge",{fileName:We.name}));continue}try{const Ze=await new Promise((he,Ge)=>{const Ve=new FileReader;Ve.onload=()=>he(Ve.result),Ve.onerror=Ge,Ve.readAsDataURL(We)}),Qe={id:Il(),filename:We.name,mimeType:We.type||"application/octet-stream",size:We.size,dataUrl:Ze};f(he=>[...he,Qe]),qe++}catch(Ze){console.error("File attach failed",Ze),H.error(i("multirun.launcher.toast.attachFailed",{fileName:We.name}))}}qe>0&&H.success(qe===1?i("multirun.launcher.toast.attachedSingle",{count:qe}):i("multirun.launcher.toast.attachedPlural",{count:qe})),B.current&&(B.current.value="")},L=Re=>{f(Xe=>Xe.filter(qe=>qe.id!==Re))},Z=o.useCallback((Re,Xe)=>{if(Re.startsWith("/")){const We=Re.indexOf(" "),Ze=Re.indexOf(`
|
|
224
224
|
`),Qe=Math.min(We===-1?Re.length:We,Ze===-1?Re.length:Ze);if(Xe<=Qe&&We===-1){z(Re.substring(1,Qe)),A(!0),T(!1);return}}A(!1);const qe=Re.substring(0,Xe),Te=qe.lastIndexOf("@");if(Te!==-1){const We=Te>0?qe[Te-1]:null,Ze=qe.substring(Te+1);(!We||/\s/.test(We))&&!Ze.includes(" ")&&!Ze.includes(`
|
|
225
|
-
`)?(S(Ze),T(!0)):T(!1);return}T(!1)},[]),Y=o.useCallback(Re=>{if(M&&_.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")){Re.preventDefault(),_.current.handleKeyDown(Re.key);return}E&&$.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")&&(Re.preventDefault(),$.current.handleKeyDown(Re.key))},[M,E]),Ee=o.useCallback(Re=>{const qe=V.current?.selectionStart??c.length,We=c.substring(0,qe).lastIndexOf("@"),Ze=Re.relativePath&&Re.relativePath.trim().length>0?Re.relativePath.trim():Re.path||Re.name,Qe=We!==-1?We:qe,he=`${c.substring(0,Qe)}@${Ze} ${c.substring(qe)}`,Ge=Qe+Ze.length+2;d(he),T(!1),S(""),requestAnimationFrame(()=>{const Ve=V.current;Ve&&(Ve.selectionStart=Ge,Ve.selectionEnd=Ge,Ve.focus()),Z(he,Ge)})},[c,Z]),Ae=o.useCallback(Re=>{const qe=V.current?.selectionStart??c.length,We=c.substring(0,qe).lastIndexOf("@"),Ze=We!==-1?We:qe,Qe=`${c.substring(0,Ze)}@${Re} ${c.substring(qe)}`,he=Ze+Re.length+2;d(Qe),T(!1),S(""),requestAnimationFrame(()=>{const Ge=V.current;Ge&&(Ge.selectionStart=he,Ge.selectionEnd=he,Ge.focus()),Z(Qe,he)})},[c,Z]),Je=o.useCallback(Re=>{const Xe=`/${Re.name} `;d(Xe),A(!1),z(""),requestAnimationFrame(()=>{const qe=V.current;qe&&(qe.focus(),qe.selectionStart=qe.value.length,qe.selectionEnd=qe.value.length),Z(Xe,Xe.length)})},[Z]),de=async Re=>{if(Re.preventDefault(),!!c.trim()&&!(p.length<2)){y(!0),q();try{le&&le!==Q&&ne(le);const Xe=p.map(({instanceId:Qe,...he})=>he),qe=x.map(Qe=>({mime:Qe.mimeType,filename:Qe.filename,url:Qe.dataUrl})),Te=g.filter(Qe=>Qe.trim().length>0),We={name:a.trim(),prompt:c.trim(),models:Xe,agent:u||void 0,worktreeBaseBranch:me?Ne:void 0,isolateRuns:me,files:qe.length>0?qe:void 0,setupCommands:Te.length>0?Te:void 0},Ze=await Me(We);Ze&&(Ze.firstSessionId&&Ot.getState().setCurrentSession(Ze.firstSessionId),e?.())}finally{y(!1)}}},ze=!!(a.trim()&&c.trim()&&p.length>=2&&U&&!je&&(we===!1||!me||Ne)),rt=g.filter(Re=>Re.trim()).length;return s.jsxs("form",{onSubmit:de,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:ce("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",ie,ue),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:i("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(P,{name:"close",className:"h-5 w-5"})})}),s.jsx(Dt,{children:s.jsx("p",{children:i("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(po,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-project",required:!0,children:i("multirun.launcher.project.label")}),G.length>0?s.jsxs(is,{value:le??void 0,onValueChange:W,children:[s.jsx(as,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:F?s.jsx(us,{children:K(F)}):s.jsx(us,{placeholder:i("multirun.launcher.project.placeholder")})}),s.jsx(os,{fitContent:!0,children:G.map(Re=>s.jsx(Ft,{value:Re.id,className:"max-w-[24rem]",children:K(Re)},Re.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:i("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"group-name",required:!0,info:s.jsx(Ko,{children:i("multirun.launcher.groupName.info")}),children:i("multirun.launcher.groupName.label")}),s.jsx(Bt,{id:"group-name",value:a,onChange:Re=>l(Re.target.value),placeholder:i("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Ko,{children:i("multirun.launcher.baseBranch.info")}),children:i("multirun.launcher.baseBranch.label")}),s.jsx(yD,{directory:U,value:Ne,onChange:Ce,disabled:!me,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(ds,{checked:N,onChange:D,disabled:!xe,ariaLabel:i("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:i("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-agent",info:s.jsx(Ko,{children:i("multirun.launcher.agent.info")}),children:i("multirun.launcher.agent.label")}),s.jsx(Lg,{value:u,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(fr,{open:b,onOpenChange:k,children:[s.jsxs(Pr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(P,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:i("multirun.launcher.setupCommands.label")}),rt>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:rt}),s.jsx(P,{name:"arrow-down-s",className:ce("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",b&&"rotate-180")})]}),s.jsx(hr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:I?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:i("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((Re,Xe)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Bt,{value:Re,onChange:qe=>{const Te=[...g];Te[Xe]=qe.target.value,w(Te)},placeholder:i("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const qe=g.filter((Te,We)=>We!==Xe);w(qe)},className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]},`${Re}-${Xe}`)),s.jsxs("button",{type:"button",onClick:()=>w([...g,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(P,{name:"add",className:"h-3 w-3"}),i("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(ea,{htmlFor:"prompt",required:!0,children:i("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(hn,{id:"prompt",ref:V,value:c,onChange:Re=>{const Xe=Re.target.value;d(Xe);const qe=Re.target.selectionStart??Xe.length;Z(Xe,qe)},onKeyDown:Y,placeholder:i("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),M?s.jsx(dh,{ref:_,searchQuery:R,onCommandSelect:Je,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,E?s.jsx(uh,{ref:$,searchQuery:C,onFileSelect:Ee,onAgentSelect:Ae,onClose:()=>T(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:B,type:"file",multiple:!0,className:"hidden",onChange:fe,accept:"*/*"}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>B.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(P,{name:"attachment-2",className:"h-3 w-3"}),i("multirun.launcher.attachments.attach")]})}),s.jsx(Dt,{children:i("multirun.launcher.attachments.tooltip")})]}),x.map(Re=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[Re.mimeType.startsWith("image/")?s.jsx(P,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(P,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Re.filename,children:Re.filename}),s.jsx("button",{type:"button",onClick:()=>L(Re.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(P,{name:"close",className:"h-3 w-3"})})]},Re.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(ea,{required:!0,info:s.jsx(Ko,{children:i("multirun.launcher.models.info",{max:Wc})}),children:i("multirun.launcher.models.label")}),s.jsx($g,{selectedModels:p,onAdd:Se,onRemove:$e,onUpdate:Pe,minModels:2,maxModels:Wc})]}),Ue&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:Ue})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!me&&we!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(P,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:i("multirun.launcher.project.gitRequired")})]}):null,s.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:n,children:i("multirun.launcher.actions.cancel")}),s.jsx(ge,{type:"submit",size:"sm",disabled:!ze||v,children:v?i("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:i("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})},jD=()=>typeof window>"u"?0:window.visualViewport?.height??window.innerHeight,ND=()=>{const t=at.c(2),[e,n]=o.useState(SD),r=o.useRef(null);let i,a;return t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{if(typeof window>"u"||!window.visualViewport)return;const l=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=window.visualViewport.height,p=Math.max(0,window.innerHeight-d);n(m=>m.height===d&&m.keyboardHeight===p?m:{height:d,keyboardHeight:p})}))};return window.visualViewport.addEventListener("resize",l),window.visualViewport.addEventListener("scroll",l,{passive:!0}),l(),()=>{r.current!==null&&cancelAnimationFrame(r.current),window.visualViewport?.removeEventListener("resize",l),window.visualViewport?.removeEventListener("scroll",l)}},a=[],t[0]=i,t[1]=a):(i=t[0],a=t[1]),o.useEffect(i,a),e};function SD(){return{height:jD(),keyboardHeight:0}}class kD extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(hh,{className:"w-full max-w-md",children:[s.jsx(Jy,{className:"text-center",children:s.jsxs(Xy,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(P,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Zy,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(ge,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(P,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function CD(t){const e=at.c(22),{t:n}=ut();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let i;e[2]!==n?(i=n("chat.errorBoundary.description"),e[2]=n,e[3]=i):i=e[3];let a;e[4]!==n?(a=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=a):a=e[5];let l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==i||e[14]!==a||e[15]!==l||e[16]!==c||e[17]!==d?(p={title:r,description:i,sessionLabel:a,detailsSummary:l,resetAction:c,persistentHint:d},e[12]=r,e[13]=i,e[14]=a,e[15]=l,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx(kD,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const Pd=t=>{const e=at.c(5),{readOnly:n}=t,r=n===void 0?!1:n,a=Ot(PD)||void 0;let l;e[0]!==r?(l=s.jsx(ev,{readOnly:r}),e[0]=r,e[1]=l):l=e[1];let c;return e[2]!==a||e[3]!==l?(c=s.jsx(CD,{sessionId:a,children:l}),e[2]=a,e[3]=l,e[4]=c):c=e[4],c};function PD(t){return t.currentSessionId}const ID=si(()=>kr(()=>Promise.resolve().then(()=>G2),void 0).then(t=>({default:t.PlanView}))),jf=si(()=>kr(()=>Promise.resolve().then(()=>sN),void 0).then(t=>({default:t.GitView}))),AD=si(()=>kr(()=>Promise.resolve().then(()=>f2),void 0).then(t=>({default:t.DiffView}))),Nf=si(()=>kr(()=>import("./TerminalView-ul8_wWze.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),DD=si(()=>kr(()=>Promise.resolve().then(()=>V2),void 0).then(t=>({default:t.FilesView}))),TD=si(()=>kr(()=>Promise.resolve().then(()=>HC),void 0).then(t=>({default:t.SettingsView}))),MD=si(()=>kr(()=>import("./SettingsWindow-CqBF9kRR.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),ED=si(()=>kr(()=>import("./MultiRunWindow-kgAi2Tz_.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),Ho=85,RD=250,FD=500,LD=400,OD=860,$D=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},BD=()=>{const{t}=ut(),e=1140,n=1220,r=640,i=700,a=Ie(F=>F.isSidebarOpen),l=Ie(F=>F.isCreativeMode),c=Ie(F=>F.isRightSidebarOpen),d=Ie(F=>F.isBottomTerminalOpen),p=Ie(F=>F.setRightSidebarOpen),m=Ie(F=>F.setBottomTerminalOpen),u=Ie(F=>F.activeMainTab),h=Ie(F=>F.setIsMobile),x=Ie(F=>F.isSessionSwitcherOpen),f=Ie(F=>F.isSettingsDialogOpen),v=Ie(F=>F.setSettingsDialogOpen),y=Ie(F=>F.isMultiRunLauncherOpen),g=Ie(F=>F.setMultiRunLauncherOpen),w=Ie(F=>F.multiRunLauncherPrefillPrompt),{isMobile:b,isTablet:k}=rn(),I=ND(),j=o.useMemo(()=>gn(),[]),N=Ie(F=>F.sidebarWidth),D=Ie(F=>F.rightSidebarWidth),[E,T]=o.useState(null),C=Ir()??"",S=o.useMemo(()=>$D(C),[C]),M=Ie(F=>{if(!S)return!1;const U=F.contextPanelByDirectory[S],W=U?.tabs??[],te=W.find(K=>K.id===U?.activeTabId)??W[W.length-1];return!!(U?.isOpen&&te)}),A=Ie(F=>F.setSidebarOpen),R=o.useRef(!1),z=o.useRef(!1),B=o.useRef(!1),[V,$]=o.useState(!1),_=o.useRef(!1),X=gu(0),O=Be.useRef(0),J=gu(0),Q=Be.useRef(0);Be.useEffect(()=>{b&&(O.current=window.innerWidth*(Ho/100),Q.current=window.innerWidth*(Ho/100))},[b]),Be.useEffect(()=>{if(!b)return;const F=V?0:-O.current;xu(X,F,{type:"spring",stiffness:400,damping:35,mass:.8})},[V,b,X]),Be.useEffect(()=>{if(!b)return;_.current=c;const F=c?0:Q.current;xu(J,F,{type:"spring",stiffness:400,damping:35,mass:.8})},[b,c,J]),Be.useEffect(()=>{b&&$(x)},[x,b]),Be.useEffect(()=>{!b||!f||($(!1),x&&Ie.getState().setSessionSwitcherOpen(!1),c&&p(!1))},[b,f,x,c,p]),Be.useEffect(()=>{b&&(_.current=c)},[c,b]),o.useEffect(()=>{Ie.getState().isMobile!==b&&h(b)},[b,h]),o.useEffect(()=>{if(typeof window>"u")return;let F;const U=()=>{F!==void 0&&window.clearTimeout(F),F=window.setTimeout(()=>{Ie.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",U),()=>{window.removeEventListener("resize",U),F!==void 0&&window.clearTimeout(F)}},[]),o.useEffect(()=>{if(M){Ie.getState().isSidebarOpen&&(A(!1),B.current=!0);return}B.current&&(A(!0),B.current=!1)},[M,A]),o.useEffect(()=>{if(typeof window>"u")return;let F;const U=()=>{const te=Ie.getState(),K=window.innerWidth,ae=window.innerHeight;if(!b&&!k){const ve=K<e,re=K>=n;ve?te.isRightSidebarOpen&&(p(!1),R.current=!0):re&&R.current&&(p(!0),R.current=!1);const be=ae<r,pe=ae>=i;be?te.isBottomTerminalOpen&&(m(!1),z.current=!0):pe&&z.current&&(m(!0),z.current=!1)}},W=()=>{F!==void 0&&window.clearTimeout(F),F=window.setTimeout(()=>{U()},100)};return U(),window.addEventListener("resize",W),()=>{window.removeEventListener("resize",W),F!==void 0&&window.clearTimeout(F)}},[b,k,m,p]),o.useEffect(()=>{if(typeof window>"u")return;const F=Ie.subscribe((U,W)=>{const te=window.innerWidth,K=window.innerHeight,ae=te>=n,ve=K>=i;U.isRightSidebarOpen!==W.isRightSidebarOpen&&ae&&(R.current=!1),U.isBottomTerminalOpen!==W.isBottomTerminalOpen&&ve&&(z.current=!1)});return()=>{F()}},[b,k,m,p]);const ne=o.useMemo(()=>{switch(u){case"plan":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(ID,{})});case"git":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(jf,{})});case"diff":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(AD,{})});case"terminal":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Nf,{})});case"files":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(DD,{})});default:return null}},[u]),G=u==="chat",le=o.useMemo(()=>Math.min(FD,Math.max(RD,N||rd)),[N]),oe=o.useMemo(()=>Math.min(OD,Math.max(LD,D||Th)),[D]);return s.jsx(_j,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:ce("main-content-safe-area",b?"flex flex-col":"flex h-[100dvh]","bg-background"),style:b&&I.height>0?{height:I.height}:void 0,children:[s.jsx(GC,{}),s.jsx(R4,{}),s.jsx($4,{}),s.jsx(dD,{}),b?s.jsxs(tv,{value:{leftDrawerOpen:V,rightDrawerOpen:c,toggleLeftDrawer:()=>{c&&p(!1),$(!V)},toggleRightDrawer:()=>{V&&$(!1),p(!c)},leftDrawerX:X,rightDrawerX:J,leftDrawerWidth:O,rightDrawerWidth:Q,setMobileLeftDrawerOpen:$,setRightSidebarOpen:p},children:[!f&&s.jsx(om,{onToggleLeftDrawer:()=>{c&&p(!1),$(!V)},onToggleRightDrawer:()=>{V&&$(!1),p(!c)},leftDrawerOpen:V,rightDrawerOpen:c}),s.jsx(Jl.button,{type:"button",initial:!1,animate:{opacity:V||c?1:0,pointerEvents:V||c?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{$(!1),p(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Jl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(O.current||window.innerWidth*.85),right:0},style:{width:`${Ho}%`,x:X},onDragEnd:(F,U)=>{const W=O.current||window.innerWidth*.85,te=W*.3,K=500,ae=X.get(),ve=U.offset.x<-te||U.velocity.x<-K,re=U.offset.x>te||U.velocity.x>K;ve?(X.set(-W),$(!1)):re?(X.set(0),$(!0)):ae>-W/2?X.set(0):X.set(-W)},className:ce("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!V,children:s.jsx("div",{"data-page-scroll-lock":"true",className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(xf,{mobileVariant:!0})})})})}),s.jsx(Jl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:Q.current||window.innerWidth*.85},style:{width:`${Ho}%`,x:J},onDragEnd:(F,U)=>{const W=Q.current||window.innerWidth*.85,te=W*.3,K=500,ae=J.get(),ve=U.offset.x>te||U.velocity.x>K,re=U.offset.x<-te||U.velocity.x<-K;ve?(J.set(W),p(!1)):re?(J.set(0),p(!0)):ae<W/2?J.set(0):J.set(W)},className:ce("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!c,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(jf,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:ce("flex flex-1 overflow-hidden relative",f&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ce("absolute inset-0",!G&&"invisible"),children:s.jsx(Xs,{children:s.jsx(Pd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:ne})}),y&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Xs,{children:s.jsx(wD,{initialPrompt:w,onCreated:()=>g(!1),onCancel:()=>g(!1)})})})]})}),f&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(TD,{onClose:()=>v(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:ce("absolute inset-0 flex overflow-hidden","bg-sidebar"),"data-page-scroll-lock":"true",children:[a?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${le}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${le}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}})]}):null,c?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${oe}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${oe}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}})]}):null,s.jsx(t1,{isOpen:a,isMobile:b,className:"border-0",children:s.jsx(xf,{})}),s.jsxs("div",{className:ce("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",a&&"border-l border-border/50 rounded-tl-[10px] rounded-bl-[10px]",c&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(om,{desktopRightSidebarActionsHost:E}),s.jsx("div",{className:ce("flex flex-1 min-h-0 overflow-hidden",a||G?"":"border-l border-border/50",c?"":"border-r border-border/50"),"data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ce("absolute inset-0",!G&&"invisible"),children:s.jsx(Xs,{children:s.jsx(Pd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:ne})})]}),s.jsx(ES,{})]})}),s.jsx(Qw,{isOpen:d,isMobile:b,children:d?s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Nf,{})})}):null})]}),s.jsx(s1,{isOpen:c,className:"border-0",onTopActionsHostChange:T,children:s.jsx(Xs,{children:l?s.jsx(ZA,{}):s.jsx(LN,{})})})]})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(MD,{open:f,onOpenChange:v})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(ED,{open:y,onOpenChange:g,initialPrompt:w})})]})]})})},zD=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},dr=t=>{const e=at.c(8),{label:n,value:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let a;e[1]!==n?(a=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=a):a=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let c;return e[5]!==a||e[6]!==l?(c=s.jsxs("div",{className:"rounded-md p-2",style:i,children:[a,l]}),e[5]=a,e[6]=l,e[7]=c):c=e[7],c},Sf=t=>{const e=at.c(43),{title:n,snapshot:r,emptyLabel:i}=t,{t:a}=ut();let l;if(e[0]!==i||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==a||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(UD,0),e[8]=r.entries,e[9]=d):d=e[9];const p=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let u;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==a?(u=r.startedAt?zD(r.durationMs):a("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=a,e[15]=u):u=e[15];let h;e[16]!==u?(h=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=h):h=e[17];let x;e[18]!==m||e[19]!==h?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,h]}),e[18]=m,e[19]=h,e[20]=x):x=e[20];let f;e[21]!==a?(f=a("memoryDebugPanel.metric.metrics"),e[21]=a,e[22]=f):f=e[22];let v;e[23]!==r.entries.length||e[24]!==f?(v=s.jsx(dr,{label:f,value:r.entries.length}),e[23]=r.entries.length,e[24]=f,e[25]=v):v=e[25];let y;e[26]!==a?(y=a("memoryDebugPanel.metric.samples"),e[26]=a,e[27]=y):y=e[27];let g;e[28]!==y||e[29]!==p?(g=s.jsx(dr,{label:y,value:p}),e[28]=y,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==a?(w=a("memoryDebugPanel.metric.lastUpdate"),e[31]=a,e[32]=w):w=e[32];let b;e[33]!==r.lastUpdatedAt||e[34]!==a?(b=r.lastUpdatedAt?a("memoryDebugPanel.common.live"):a("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=a,e[35]=b):b=e[35];let k;e[36]!==w||e[37]!==b?(k=s.jsx(dr,{label:w,value:b}),e[36]=w,e[37]=b,e[38]=k):k=e[38];let I;e[39]!==g||e[40]!==k||e[41]!==v?(I=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,g,k]}),e[39]=g,e[40]=k,e[41]=v,e[42]=I):I=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,I,c.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):s.jsx(Cs,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:a("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:a("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:a("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:a("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=i,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=a,e[6]=n,e[7]=l}else l=e[7];return l},VD=t=>{const e=at.c(101),{onClose:n}=t,{t:r}=ut(),[i,a]=o.useState("memory"),[l,c]=o.useState("idle"),d=Ot(WD),p=ph(KD),m=zl(),u=th(HD),h=mr(GD),[x,f]=o.useState(qD),[v,y]=o.useState(YD);let g;e[0]!==x.entries?(g=new Map,x.entries.forEach(Ce=>{g.set(Ce.metric,Ce.count)}),e[0]=x.entries,e[1]=g):g=e[1];let w;e[2]!==g?(w=g.get("ui.message_list.render")??0,e[2]=g,e[3]=w):w=e[3];let b;e[4]!==g?(b=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=b):b=e[5];let k;e[6]!==g?(k=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=k):k=e[7];let I;e[8]!==g?(I=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=I):I=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let N;e[12]!==g?(N=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=N):N=e[13];let D;e[14]!==w||e[15]!==b||e[16]!==k||e[17]!==I||e[18]!==j||e[19]!==N?(D={messageListRender:w,messageListRenderStreaming:b,chatMessageRender:k,chatMessageRenderStreaming:I,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:N},e[14]=w,e[15]=b,e[16]=k,e[17]=I,e[18]=j,e[19]=N,e[20]=D):D=e[20];const E=D;let T,C;e[21]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const Ce=()=>{f(Jo()),y(Xo())};Ce();const je=window.setInterval(Ce,500);return()=>window.clearInterval(je)},C=[],e[21]=T,e[22]=C):(T=e[21],C=e[22]),o.useEffect(T,C);let S,M;e[23]!==l?(S=()=>{if(l==="idle")return;const Ce=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ce)},M=[l],e[23]=l,e[24]=S,e[25]=M):(S=e[24],M=e[25]),o.useEffect(S,M);let A=0,R;if(e[26]!==u?(R=Object.keys(u),e[26]=u,e[27]=R):R=e[27],e[28]!==u||e[29]!==R||e[30]!==A){for(const Ce of R)A=A+(u[Ce]?.length??0);e[28]=u,e[29]=R,e[30]=A,e[31]=A}else A=e[31];const z=A;let B;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ce;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ce=je=>{const we=u[je.id]?.length||0,ke=p.get(je.id);return{id:je.id,title:je.title||r("memoryDebugPanel.common.untitled"),messageCount:we,isStreaming:ke?.isStreaming||!1,isZombie:ke?.isZombie||!1,backgroundCount:ke?.backgroundMessageCount||0,lastAccessed:ke?.lastAccessedAt||0,isCurrent:je.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ce):Ce=e[42],B=m.map(Ce).sort(QD),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=B}else B=e[37];const V=B;let $;e[43]!==u?($=Object.keys(u),e[43]=u,e[44]=$):$=e[44];const _=$.length;let X;e[45]===Symbol.for("react.memo_cache_sentinel")?(X=async()=>{try{const Ce={generatedAt:new Date().toISOString(),ui:Jo(),vscode:Xo()};await navigator.clipboard.writeText(JSON.stringify(Ce,null,2)),c("copied")}catch{c("error")}},e[45]=X):X=e[45];const O=X;let J;e[46]===Symbol.for("react.memo_cache_sentinel")?(J={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=J):J=e[46];let Q;e[47]!==i?(Q=i==="memory"?s.jsx(P,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(P,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=i,e[48]=Q):Q=e[48];let ne;e[49]!==r?(ne=r("memoryDebugPanel.title"),e[49]=r,e[50]=ne):ne=e[50];let G;e[51]!==ne?(G=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ne}),e[51]=ne,e[52]=G):G=e[52];let le;e[53]!==Q||e[54]!==G?(le=s.jsxs("div",{className:"flex items-center gap-2",children:[Q,G]}),e[53]=Q,e[54]=G,e[55]=le):le=e[55];let oe;e[56]!==i?(oe=i==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ge,{size:"xs",variant:"ghost",onClick:O,children:s.jsx(P,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ge,{size:"xs",variant:"ghost",onClick:()=>{nv(),f(Jo()),y(Xo())},children:s.jsx(P,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=i,e[57]=oe):oe=e[57];let F;e[58]!==n?(F=n?s.jsx(ge,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(P,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=F):F=e[59];let U;e[60]!==oe||e[61]!==F?(U=s.jsxs("div",{className:"flex items-center gap-1",children:[oe,F]}),e[60]=oe,e[61]=F,e[62]=U):U=e[62];let W;e[63]!==le||e[64]!==U?(W=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[le,U]}),e[63]=le,e[64]=U,e[65]=W):W=e[65];let te;e[66]===Symbol.for("react.memo_cache_sentinel")?(te={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=te):te=e[66];const K=i==="memory"?"secondary":"ghost";let ae;e[67]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>a("memory"),e[67]=ae):ae=e[67];let ve;e[68]!==r?(ve=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=ve):ve=e[69];let re;e[70]!==K||e[71]!==ve?(re=s.jsx(ge,{size:"sm",variant:K,className:"flex-1",onClick:ae,children:ve}),e[70]=K,e[71]=ve,e[72]=re):re=e[72];const be=i==="streaming"?"secondary":"ghost";let pe;e[73]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>a("streaming"),e[73]=pe):pe=e[73];let ye;e[74]!==r?(ye=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ye):ye=e[75];let ie;e[76]!==be||e[77]!==ye?(ie=s.jsx(ge,{size:"sm",variant:be,className:"flex-1",onClick:pe,children:ye}),e[76]=be,e[77]=ye,e[78]=ie):ie=e[78];let ue;e[79]!==re||e[80]!==ie?(ue=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:te,children:[re,ie]}),e[79]=re,e[80]=ie,e[81]=ue):ue=e[81];let se;e[82]!==i||e[83]!==_||e[84]!==l||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==V||e[89]!==m||e[90]!==E||e[91]!==x||e[92]!==r||e[93]!==h||e[94]!==z||e[95]!==v?(se=i==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.totalMessages"),value:z}),s.jsx(dr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${_} / ${_u.MAX_SESSIONS}`})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:sv()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:_u.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:h})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(Cs,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(Ce=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ce.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Ce.title}),Ce.isStreaming?s.jsx(P,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ce.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ce.messageCount})}),Ce.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ce.backgroundCount]}):null]})]},Ce.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(JD),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Dt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ge,{size:"xs",variant:"outline",onClick:O,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:E.messageListRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:E.messageListRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:E.chatMessageRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:E.chatMessageRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:E.chatMessageRenderStaticDuringStream}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:E.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Sf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(Sf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=i,e[83]=_,e[84]=l,e[85]=d,e[86]=u,e[87]=p,e[88]=V,e[89]=m,e[90]=E,e[91]=x,e[92]=r,e[93]=h,e[94]=z,e[95]=v,e[96]=se):se=e[96];let Ne;return e[97]!==W||e[98]!==ue||e[99]!==se?(Ne=s.jsxs(hh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:J,children:[W,ue,se]}),e[97]=W,e[98]=ue,e[99]=se,e[100]=Ne):Ne=e[100],Ne},_D=VD;function UD(t,e){return t+e.count}function WD(t){return t.currentSessionId}function KD(t){return t.sessionMemoryState}function HD(t){return t.message}function GD(t){return t.totalRequestCount}function qD(){return Jo()}function YD(){return Xo()}function QD(t,e){return e.lastAccessed-t.lastAccessed}function JD(t){return{id:t.id,title:t.title}}const XD=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},ZD=async()=>{const t=XD()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},kf="vinci:menu-action",e6=t=>{const e=Ot(x=>x.openNewSessionDraft),n=Ie(x=>x.toggleCommandPalette),r=Ie(x=>x.setCommandPaletteOpen),i=Ie(x=>x.toggleHelpDialog),a=Ie(x=>x.toggleSidebar),l=Ie(x=>x.setSessionSwitcherOpen),c=Ie(x=>x.setActiveMainTab),d=Ie(x=>x.setSettingsDialogOpen),p=Ie(x=>x.setAboutDialogOpen),{setThemeMode:m}=Ar(),u=o.useCallback(()=>{Sr.requestDirectoryDialog()},[]),h=o.useCallback(x=>{switch(x){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),l(!1),e();break;case"new-worktree-session":c("chat"),l(!1),oh();break;case"change-workspace":u();break;case"open-git-tab":{const{activeMainTab:f}=Ie.getState();c(f==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:f}=Ie.getState();c(f==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:f}=Ie.getState();c(f==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:f}=Ie.getState();c(f==="terminal"?"chat":"terminal");break}case"copy":{const f=new Event("vinci:copy",{cancelable:!0});!window.dispatchEvent(f)||ZD();break}case"theme-light":m("light");break;case"theme-dark":m("dark");break;case"theme-system":m("system");break;case"toggle-sidebar":a();break;case"toggle-memory-debug":t?.();break;case"help-dialog":i();break;case"download-logs":{rv().catch(()=>{H.error("Failed to collect OpenCode status")});break}}},[u,t,e,p,c,l,r,d,m,n,i,a]);o.useEffect(()=>{const x=f=>{const v=f.detail;v&&h(v)};return window.addEventListener(kf,x),()=>{window.removeEventListener(kf,x)}},[h]),o.useEffect(()=>{if(typeof window>"u")return;const f=window.__TAURI__?.event?.listen;if(typeof f!="function")return;let v=null;return f("vinci:menu-action",y=>{const g=y?.payload;typeof g=="string"&&h(g)}).then(y=>{v=y}).catch(()=>{}),()=>{(async()=>{try{const g=v?.();g instanceof Promise&&await g}catch{}})()}},[h])},t6=["chat","git","diff","terminal","files"],s6=["settings","agents","commands","skills","providers","usage","git-identities"],Nr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Cf(t){const e=n6();return{sessionId:r6(e),tab:i6(e),settingsPath:a6(e),diffFile:o6(e)}}function n6(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function r6(t){const e=t.get(Nr.SESSION);return!e||e.trim().length===0?null:e.trim()}function i6(t){const e=t.get(Nr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return t6.includes(n)?n:null}function a6(t){const e=t.get(Nr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="vinci"||n==="general"||n==="preferences"?"home":(s6.includes(n),n)}function o6(t){const e=t.get(Nr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Pf(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(Nr.SESSION)||t.has(Nr.TAB)||t.has(Nr.SETTINGS)||t.has(Nr.FILE)}catch{return!1}}const l6="chat";function Kg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(Nr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(Nr.SETTINGS,n),e}return t.tab!==l6&&e.set(Nr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(Nr.FILE,t.diffFile),e}function c6(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function d6(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Kg(t),r=[...e.entries()].sort((a,l)=>a[0].localeCompare(l[0])),i=[...n.entries()].sort((a,l)=>a[0].localeCompare(l[0]));if(r.length!==i.length)return!1;for(let a=0;a<r.length;a++)if(r[a][0]!==i[a][0]||r[a][1]!==i[a][1])return!1;return!0}catch{return!0}}function u6(t,e={}){if(!(typeof window>"u")&&!m6()&&!(!e.force&&d6(t)))try{const n=Kg(t),r=c6(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function m6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function p6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function f6(){const t=o.useMemo(()=>p6(),[]),e=o.useRef(!1),n=o.useRef(!1),r=Ot(u=>u.setCurrentSession),i=Ie(u=>u.setActiveMainTab),a=Ie(u=>u.setSettingsDialogOpen),l=Ie(u=>u.setSettingsPage),c=Ie(u=>u.navigateToDiff),d=o.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const h=Ot.getState().currentSessionId;u.sessionId!==h&&await r(u.sessionId)}if(u.settingsPath){l(lg(u.settingsPath)),a(!0);return}Ie.getState().isSettingsDialogOpen&&a(!1),u.tab&&i(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,i,a,l,c]),p=o.useCallback(()=>{const u=Ot.getState(),h=Ie.getState();return{sessionId:u.currentSessionId,tab:h.activeMainTab,isSettingsOpen:h.isSettingsDialogOpen,settingsPath:h.settingsPage,diffFile:h.pendingDiffFile}},[]),m=o.useCallback((u={})=>{if(t||n.current)return;const h=p();u6(h,u)},[t,p]);o.useEffect(()=>{if(e.current||(e.current=!0,!Pf()))return;const u=Cf();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),o.useEffect(()=>{if(t)return;let u=Ot.getState().currentSessionId;return Ot.subscribe(x=>{const f=x.currentSessionId;f===u||n.current||(u=f,m())})},[t,m]),o.useEffect(()=>{if(t)return;let u=Ie.getState().activeMainTab,h=Ie.getState().isSettingsDialogOpen,x=Ie.getState().settingsPage,f=Ie.getState().pendingDiffFile;return Ie.subscribe(y=>{if(n.current)return;const g=y.activeMainTab!==u,w=y.isSettingsDialogOpen!==h,b=y.settingsPage!==x,k=y.pendingDiffFile!==f&&y.activeMainTab==="diff";u=y.activeMainTab,h=y.isSettingsDialogOpen,x=y.settingsPage,f=y.pendingDiffFile,(g||w||b||k)&&m()})},[t,m]),o.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const h=Cf();if(Pf())d(h);else{const x=Ie.getState();x.isSettingsDialogOpen&&a(!1),x.activeMainTab!=="chat"&&i("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,i,a])}const If="pwa-install-toast-shown",h6=()=>{const t=at.c(6),{browserTab:e}=wg(),{t:n}=ut(),r=o.useRef(n);let i,a;t[0]!==n?(i=()=>{r.current=n},a=[n],t[0]=n,t[1]=i,t[2]=a):(i=t[1],a=t[2]),o.useEffect(i,a);let l,c;t[3]!==e?(l=()=>{if(typeof window>"u"||!Li()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(H.dismiss(p),p=null)},u=async()=>{if(!d)return;const f=d;d=null,m(),await f.prompt();const{outcome:v}=await f.userChoice;v==="accepted"&&H.success(r.current("pwa.installPrompt.started"))},h=f=>{const v=f;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const y=_f();y.getItem(If)!=="true"&&p===null&&(y.setItem(If,"true"),p=H.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}}}))},x=()=>{d=null,m(),H.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",h),window.addEventListener("appinstalled",x),()=>{m(),window.removeEventListener("beforeinstallprompt",h),window.removeEventListener("appinstalled",x)}},c=[e],t[3]=e,t[4]=l,t[5]=c):(l=t[4],c=t[5]),o.useEffect(l,c)},g6=["local","remote",null],x6=["ok","not-configured","unreachable","wrong-service","missing"];function Hg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!g6.includes(n)))return{valid:!1};if(typeof r!="string"||!x6.includes(r))return{valid:!1};if(n==="remote"||n==="local"){if(r==="ok"&&n==="local")return{valid:!0,outcome:{target:"local",status:"ok"}};if(r==="ok"&&n==="remote")return typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"ok",hostId:e.hostId,url:e.url}};if(r==="unreachable")return n==="local"?{valid:!0,outcome:{target:"local",status:"unreachable"}}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"unreachable",hostId:e.hostId,url:e.url}};if(r==="wrong-service")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"wrong-service",hostId:e.hostId,url:e.url}};if(r==="missing")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"missing",hostId:e.hostId}}}if(n===null){if(r==="not-configured")return{valid:!0,outcome:{target:null,status:"not-configured"}};if(r==="missing")return{valid:!1}}return{valid:!1}}function Af(t){if(!t.isDesktopShell)return null;const e=t.bootOutcome;if(!e)return null;if(e.status==="ok"){if(e.target==="local")return{screen:"main"};if(e.target==="remote")return{screen:"main",hostId:e.hostId,url:e.url}}if(e.target===null&&e.status==="not-configured")return{screen:"chooser"};if(e.target==="local"&&e.status==="unreachable")return{screen:"recovery",variant:"local-unavailable"};if(e.target==="remote"){if(e.status==="unreachable")return{screen:"recovery",variant:"remote-unreachable",hostId:e.hostId,url:e.url};if(e.status==="wrong-service")return{screen:"recovery",variant:"remote-wrong-service",hostId:e.hostId,url:e.url};if(e.status==="missing")return{screen:"recovery",variant:"remote-missing",hostId:e.hostId}}return null}function b6(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function y6(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Df(){if(Id()!=="valid")return null;const e=window.__APP_DESKTOP_BOOT_OUTCOME__,n=Hg(e);return n.valid?n.outcome:null}function Id(){if(typeof window>"u")return"not-injected";const t=window.__APP_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Hg(t).valid?"valid":"malformed"}const v6=()=>{const t=at.c(5),[e,n]=o.useState(w6),{isUpdating:r,message:i}=e;let a,l;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>av(n),l=[],t[0]=a,t[1]=l):(a=t[0],l=t[1]),o.useEffect(a,l),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx($d,{width:80,height:80}),t[2]=c):c=t[2];let d;return t[3]!==i?(d=s.jsxs("div",{className:"fixed inset-0 z-[9999] flex flex-col items-center justify-center gap-6 bg-background/90",children:[c,s.jsx("p",{className:"typography-body text-muted-foreground",children:i})]}),t[3]=i,t[4]=d):d=t[4],d};function w6(){return iv()}const j6=({open:t,onOpenChange:e})=>{const{t:n}=ut(),[r,i]=o.useState(null),[a,l]=o.useState(null),[c,d]=o.useState(!1),[p,m]=o.useState(!1),[u,h]=o.useState(null),[x,f]=o.useState(!1),v=o.useCallback(async()=>{if(!c){d(!0),m(!1);try{if(!u){H.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const g=await Uu.copyTextToClipboard(u);g.ok?(m(!0),H.success(n("aboutDialog.toast.diagnosticsCopied"))):H.error(n("aboutDialog.toast.copyFailed"),{description:g.error})}catch(g){H.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",g)}finally{d(!1)}}},[u,c,n]);o.useEffect(()=>{if(!t)return;(async()=>{try{const w=await fetch("/api/system/info");if(w.ok){const b=await w.json();if(typeof b.vinciVersion=="string"&&b.vinciVersion.trim()){i(b.vinciVersion);return}}}catch{}i(await ov())})()},[t]),o.useEffect(()=>{if(!t)return;let g=!1;return(async()=>{try{const b=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!b.ok)return;const k=await b.json().catch(()=>null),I=typeof k?.currentVersion=="string"?k.currentVersion.trim():"";!g&&I&&l(I)}catch{}})(),()=>{g=!0}},[t]),o.useEffect(()=>{if(!t){h(null),f(!1);return}let g=!1;return f(!0),Uu.buildDiagnosticsReport().then(w=>{g||h(w)}).catch(w=>{g||(console.error("Failed to prepare diagnostics:",w),h(null))}).finally(()=>{g||f(!1)}),()=>{g=!0}},[t]);const y=r;return s.jsx(hs,{open:t,onOpenChange:e,children:s.jsx(fs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx($d,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Vinci"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[y&&s.jsx("p",{children:n("aboutDialog.vinciVersionLabel",{version:y})}),a&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:a})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:v,disabled:c||x||!u,className:ce("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(p?"aboutDialog.actions.diagnosticsCopied":x?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[s.jsxs("a",{href:"https://github.com/jaygupta17/vinci",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/eSSmgeX8Q",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/guptajay17",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@guptajay17"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Kc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},N6=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to Vinci and click Authorize again.":n},S6=()=>{const t=yn(a=>a.completeAuth),[e,n]=o.useState("working"),[r,i]=o.useState("Completing MCP authorization...");return o.useEffect(()=>{if(typeof window>"u"){n("error"),i("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),l=Kc(a,"code"),c=pg(a),d=Zd(a),p=Kc(a,"error"),m=Kc(a,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),i(m??p);return}(async()=>{try{if(!l)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");let u=c;if(!u&&d){const h=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(h.ok){const x=await h.json().catch(()=>null);x?.name?.trim()&&(u={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");await t(u.name,l,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),i("Authorization completed. You can close this tab and return to Vinci.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),i(N6(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(ge,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to Vinci"})})]})})},Go="opencode-update-available",qo="opencode-upgrade-progress",k6=5e3,C6=[1e4,6e4],Gg=()=>{const{t}=ut(),e=Ie(l=>l.showOpenCodeUpdateNotifications),n=Be.useRef(new Set),r=Be.useRef(!1);Be.useEffect(()=>{e||H.dismiss(Go)},[e]);const i=Be.useCallback(()=>{H.dismiss(qo),Fi({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),a=Be.useCallback(async()=>{if(!r.current){r.current=!0,H.dismiss(Go),H.message(t("opencodeUpdate.toast.upgrading.title"),{id:qo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(P,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await l.json().catch(()=>null);if(!l.ok||c?.success===!1)throw new Error(c?.error||l.statusText||t("opencodeUpdate.toast.failed.description"));H.success(t("opencodeUpdate.toast.updated.title"),{id:qo,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(P,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:i}})}catch(l){H.error(t("opencodeUpdate.toast.failed.title"),{id:qo,description:l instanceof Error?l.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[i,t]);return Be.useEffect(()=>{const l=u=>{if(!Ie.getState().showOpenCodeUpdateNotifications){H.dismiss(Go);return}u&&(n.current.has(u)||(n.current.add(u),H.info(t("opencodeUpdate.toast.available.title"),{id:Go,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:a}})))},c=u=>{const h=typeof u.detail?.version=="string"?String(u.detail.version).trim():"";l(h)};let d=!1;const p=[],m=async u=>{try{const h=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!h.ok)throw new Error(h.statusText||"OpenCode upgrade status check failed");const x=await h.json().catch(()=>null),f=typeof x?.latestVersion=="string"?x.latestVersion.trim():"";!d&&x?.available===!0&&f&&l(f)}catch{const h=C6[u];!d&&h!==void 0&&p.push(setTimeout(()=>{m(u+1)},h))}};return e&&p.push(setTimeout(()=>{m(0)},k6)),window.addEventListener("vinci:opencode-update-available",c),()=>{d=!0;for(const u of p)clearTimeout(u);window.removeEventListener("vinci:opencode-update-available",c)}},[a,e,t]),null},Tf=si(()=>kr(()=>import("./OnboardingScreen-DrP7yZEP.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),P6=()=>{const t=at.c(3),e=Ie(E6),n=Ie(R6);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(j6,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},I6=t=>{const e=at.c(21),{onRetry:n,isRetrying:r}=t,{t:i}=ut();let a;e[0]!==i?(a=i("startup.initRecovery.title"),e[0]=i,e[1]=a):a=e[1];let l;e[2]!==a?(l=s.jsx("h1",{className:"typography-title text-foreground",children:a}),e[2]=a,e[3]=l):l=e[3];let c;e[4]!==i?(c=i("startup.initRecovery.description"),e[4]=i,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==l||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,d]}),e[8]=l,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==i?(m=i(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=i,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(ge,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let h;return e[18]!==p||e[19]!==u?(h=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=h):h=e[20],h},Mf=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",A6=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),i=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:i,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},D6=()=>typeof window>"u"?!1:window.location.pathname===mg,T6=t=>{const e=at.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=t,a=$s(F6),l=Ot(L6),c=Ot(O6),d=_d(),p=o.useRef(null);let m;e[0]!==n.directory?(m=Mf(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let h;e[2]!==a?(h=Mf(a),e[2]=a,e[3]=h):h=e[3];const x=h;let f,v;if(e[4]!==x||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(f=()=>{if(r||u&&x!==u)return;const I=`${u}
|
|
225
|
+
`)?(S(Ze),T(!0)):T(!1);return}T(!1)},[]),Y=o.useCallback(Re=>{if(M&&_.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")){Re.preventDefault(),_.current.handleKeyDown(Re.key);return}E&&$.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")&&(Re.preventDefault(),$.current.handleKeyDown(Re.key))},[M,E]),Ee=o.useCallback(Re=>{const qe=V.current?.selectionStart??c.length,We=c.substring(0,qe).lastIndexOf("@"),Ze=Re.relativePath&&Re.relativePath.trim().length>0?Re.relativePath.trim():Re.path||Re.name,Qe=We!==-1?We:qe,he=`${c.substring(0,Qe)}@${Ze} ${c.substring(qe)}`,Ge=Qe+Ze.length+2;d(he),T(!1),S(""),requestAnimationFrame(()=>{const Ve=V.current;Ve&&(Ve.selectionStart=Ge,Ve.selectionEnd=Ge,Ve.focus()),Z(he,Ge)})},[c,Z]),Ae=o.useCallback(Re=>{const qe=V.current?.selectionStart??c.length,We=c.substring(0,qe).lastIndexOf("@"),Ze=We!==-1?We:qe,Qe=`${c.substring(0,Ze)}@${Re} ${c.substring(qe)}`,he=Ze+Re.length+2;d(Qe),T(!1),S(""),requestAnimationFrame(()=>{const Ge=V.current;Ge&&(Ge.selectionStart=he,Ge.selectionEnd=he,Ge.focus()),Z(Qe,he)})},[c,Z]),Je=o.useCallback(Re=>{const Xe=`/${Re.name} `;d(Xe),A(!1),z(""),requestAnimationFrame(()=>{const qe=V.current;qe&&(qe.focus(),qe.selectionStart=qe.value.length,qe.selectionEnd=qe.value.length),Z(Xe,Xe.length)})},[Z]),de=async Re=>{if(Re.preventDefault(),!!c.trim()&&!(p.length<2)){y(!0),q();try{le&&le!==Q&&ne(le);const Xe=p.map(({instanceId:Qe,...he})=>he),qe=x.map(Qe=>({mime:Qe.mimeType,filename:Qe.filename,url:Qe.dataUrl})),Te=g.filter(Qe=>Qe.trim().length>0),We={name:a.trim(),prompt:c.trim(),models:Xe,agent:u||void 0,worktreeBaseBranch:me?Ne:void 0,isolateRuns:me,files:qe.length>0?qe:void 0,setupCommands:Te.length>0?Te:void 0},Ze=await Me(We);Ze&&(Ze.firstSessionId&&Ot.getState().setCurrentSession(Ze.firstSessionId),e?.())}finally{y(!1)}}},ze=!!(a.trim()&&c.trim()&&p.length>=2&&U&&!je&&(we===!1||!me||Ne)),rt=g.filter(Re=>Re.trim()).length;return s.jsxs("form",{onSubmit:de,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:ce("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",ie,ue),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:i("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(P,{name:"close",className:"h-5 w-5"})})}),s.jsx(Dt,{children:s.jsx("p",{children:i("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(po,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-project",required:!0,children:i("multirun.launcher.project.label")}),G.length>0?s.jsxs(is,{value:le??void 0,onValueChange:W,children:[s.jsx(as,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:F?s.jsx(us,{children:K(F)}):s.jsx(us,{placeholder:i("multirun.launcher.project.placeholder")})}),s.jsx(os,{fitContent:!0,children:G.map(Re=>s.jsx(Ft,{value:Re.id,className:"max-w-[24rem]",children:K(Re)},Re.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:i("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"group-name",required:!0,info:s.jsx(Ko,{children:i("multirun.launcher.groupName.info")}),children:i("multirun.launcher.groupName.label")}),s.jsx(Bt,{id:"group-name",value:a,onChange:Re=>l(Re.target.value),placeholder:i("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Ko,{children:i("multirun.launcher.baseBranch.info")}),children:i("multirun.launcher.baseBranch.label")}),s.jsx(yD,{directory:U,value:Ne,onChange:Ce,disabled:!me,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(ds,{checked:N,onChange:D,disabled:!xe,ariaLabel:i("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:i("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(ea,{htmlFor:"multirun-agent",info:s.jsx(Ko,{children:i("multirun.launcher.agent.info")}),children:i("multirun.launcher.agent.label")}),s.jsx(Lg,{value:u,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(fr,{open:b,onOpenChange:k,children:[s.jsxs(Pr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(P,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:i("multirun.launcher.setupCommands.label")}),rt>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:rt}),s.jsx(P,{name:"arrow-down-s",className:ce("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",b&&"rotate-180")})]}),s.jsx(hr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:I?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:i("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((Re,Xe)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Bt,{value:Re,onChange:qe=>{const Te=[...g];Te[Xe]=qe.target.value,w(Te)},placeholder:i("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const qe=g.filter((Te,We)=>We!==Xe);w(qe)},className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":i("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(P,{name:"close",className:"h-3.5 w-3.5"})})]},`${Re}-${Xe}`)),s.jsxs("button",{type:"button",onClick:()=>w([...g,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(P,{name:"add",className:"h-3 w-3"}),i("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(ea,{htmlFor:"prompt",required:!0,children:i("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(hn,{id:"prompt",ref:V,value:c,onChange:Re=>{const Xe=Re.target.value;d(Xe);const qe=Re.target.selectionStart??Xe.length;Z(Xe,qe)},onKeyDown:Y,placeholder:i("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),M?s.jsx(dh,{ref:_,searchQuery:R,onCommandSelect:Je,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,E?s.jsx(uh,{ref:$,searchQuery:C,onFileSelect:Ee,onAgentSelect:Ae,onClose:()=>T(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:B,type:"file",multiple:!0,className:"hidden",onChange:fe,accept:"*/*"}),s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>B.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(P,{name:"attachment-2",className:"h-3 w-3"}),i("multirun.launcher.attachments.attach")]})}),s.jsx(Dt,{children:i("multirun.launcher.attachments.tooltip")})]}),x.map(Re=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[Re.mimeType.startsWith("image/")?s.jsx(P,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(P,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Re.filename,children:Re.filename}),s.jsx("button",{type:"button",onClick:()=>L(Re.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(P,{name:"close",className:"h-3 w-3"})})]},Re.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(ea,{required:!0,info:s.jsx(Ko,{children:i("multirun.launcher.models.info",{max:Wc})}),children:i("multirun.launcher.models.label")}),s.jsx($g,{selectedModels:p,onAdd:Se,onRemove:$e,onUpdate:Pe,minModels:2,maxModels:Wc})]}),Ue&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:Ue})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!me&&we!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(P,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:i("multirun.launcher.project.gitRequired")})]}):null,s.jsx(ge,{type:"button",variant:"ghost",size:"sm",onClick:n,children:i("multirun.launcher.actions.cancel")}),s.jsx(ge,{type:"submit",size:"sm",disabled:!ze||v,children:v?i("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:i("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})},jD=()=>typeof window>"u"?0:window.visualViewport?.height??window.innerHeight,ND=()=>{const t=at.c(2),[e,n]=o.useState(SD),r=o.useRef(null);let i,a;return t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{if(typeof window>"u"||!window.visualViewport)return;const l=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=window.visualViewport.height,p=Math.max(0,window.innerHeight-d);n(m=>m.height===d&&m.keyboardHeight===p?m:{height:d,keyboardHeight:p})}))};return window.visualViewport.addEventListener("resize",l),window.visualViewport.addEventListener("scroll",l,{passive:!0}),l(),()=>{r.current!==null&&cancelAnimationFrame(r.current),window.visualViewport?.removeEventListener("resize",l),window.visualViewport?.removeEventListener("scroll",l)}},a=[],t[0]=i,t[1]=a):(i=t[0],a=t[1]),o.useEffect(i,a),e};function SD(){return{height:jD(),keyboardHeight:0}}class kD extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(hh,{className:"w-full max-w-md",children:[s.jsx(Jy,{className:"text-center",children:s.jsxs(Xy,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(P,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(Zy,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(ge,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(P,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),s.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function CD(t){const e=at.c(22),{t:n}=ut();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let i;e[2]!==n?(i=n("chat.errorBoundary.description"),e[2]=n,e[3]=i):i=e[3];let a;e[4]!==n?(a=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=a):a=e[5];let l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==i||e[14]!==a||e[15]!==l||e[16]!==c||e[17]!==d?(p={title:r,description:i,sessionLabel:a,detailsSummary:l,resetAction:c,persistentHint:d},e[12]=r,e[13]=i,e[14]=a,e[15]=l,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx(kD,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const Pd=t=>{const e=at.c(5),{readOnly:n}=t,r=n===void 0?!1:n,a=Ot(PD)||void 0;let l;e[0]!==r?(l=s.jsx(ev,{readOnly:r}),e[0]=r,e[1]=l):l=e[1];let c;return e[2]!==a||e[3]!==l?(c=s.jsx(CD,{sessionId:a,children:l}),e[2]=a,e[3]=l,e[4]=c):c=e[4],c};function PD(t){return t.currentSessionId}const ID=si(()=>kr(()=>Promise.resolve().then(()=>G2),void 0).then(t=>({default:t.PlanView}))),jf=si(()=>kr(()=>Promise.resolve().then(()=>sN),void 0).then(t=>({default:t.GitView}))),AD=si(()=>kr(()=>Promise.resolve().then(()=>f2),void 0).then(t=>({default:t.DiffView}))),Nf=si(()=>kr(()=>import("./TerminalView-CykGfmvO.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),DD=si(()=>kr(()=>Promise.resolve().then(()=>V2),void 0).then(t=>({default:t.FilesView}))),TD=si(()=>kr(()=>Promise.resolve().then(()=>HC),void 0).then(t=>({default:t.SettingsView}))),MD=si(()=>kr(()=>import("./SettingsWindow-I9We0AUb.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),ED=si(()=>kr(()=>import("./MultiRunWindow-I3lRPicR.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),Ho=85,RD=250,FD=500,LD=400,OD=860,$D=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},BD=()=>{const{t}=ut(),e=1140,n=1220,r=640,i=700,a=Ie(F=>F.isSidebarOpen),l=Ie(F=>F.isCreativeMode),c=Ie(F=>F.isRightSidebarOpen),d=Ie(F=>F.isBottomTerminalOpen),p=Ie(F=>F.setRightSidebarOpen),m=Ie(F=>F.setBottomTerminalOpen),u=Ie(F=>F.activeMainTab),h=Ie(F=>F.setIsMobile),x=Ie(F=>F.isSessionSwitcherOpen),f=Ie(F=>F.isSettingsDialogOpen),v=Ie(F=>F.setSettingsDialogOpen),y=Ie(F=>F.isMultiRunLauncherOpen),g=Ie(F=>F.setMultiRunLauncherOpen),w=Ie(F=>F.multiRunLauncherPrefillPrompt),{isMobile:b,isTablet:k}=rn(),I=ND(),j=o.useMemo(()=>gn(),[]),N=Ie(F=>F.sidebarWidth),D=Ie(F=>F.rightSidebarWidth),[E,T]=o.useState(null),C=Ir()??"",S=o.useMemo(()=>$D(C),[C]),M=Ie(F=>{if(!S)return!1;const U=F.contextPanelByDirectory[S],W=U?.tabs??[],te=W.find(K=>K.id===U?.activeTabId)??W[W.length-1];return!!(U?.isOpen&&te)}),A=Ie(F=>F.setSidebarOpen),R=o.useRef(!1),z=o.useRef(!1),B=o.useRef(!1),[V,$]=o.useState(!1),_=o.useRef(!1),X=gu(0),O=Be.useRef(0),J=gu(0),Q=Be.useRef(0);Be.useEffect(()=>{b&&(O.current=window.innerWidth*(Ho/100),Q.current=window.innerWidth*(Ho/100))},[b]),Be.useEffect(()=>{if(!b)return;const F=V?0:-O.current;xu(X,F,{type:"spring",stiffness:400,damping:35,mass:.8})},[V,b,X]),Be.useEffect(()=>{if(!b)return;_.current=c;const F=c?0:Q.current;xu(J,F,{type:"spring",stiffness:400,damping:35,mass:.8})},[b,c,J]),Be.useEffect(()=>{b&&$(x)},[x,b]),Be.useEffect(()=>{!b||!f||($(!1),x&&Ie.getState().setSessionSwitcherOpen(!1),c&&p(!1))},[b,f,x,c,p]),Be.useEffect(()=>{b&&(_.current=c)},[c,b]),o.useEffect(()=>{Ie.getState().isMobile!==b&&h(b)},[b,h]),o.useEffect(()=>{if(typeof window>"u")return;let F;const U=()=>{F!==void 0&&window.clearTimeout(F),F=window.setTimeout(()=>{Ie.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",U),()=>{window.removeEventListener("resize",U),F!==void 0&&window.clearTimeout(F)}},[]),o.useEffect(()=>{if(M){Ie.getState().isSidebarOpen&&(A(!1),B.current=!0);return}B.current&&(A(!0),B.current=!1)},[M,A]),o.useEffect(()=>{if(typeof window>"u")return;let F;const U=()=>{const te=Ie.getState(),K=window.innerWidth,ae=window.innerHeight;if(!b&&!k){const ve=K<e,re=K>=n;ve?te.isRightSidebarOpen&&(p(!1),R.current=!0):re&&R.current&&(p(!0),R.current=!1);const be=ae<r,pe=ae>=i;be?te.isBottomTerminalOpen&&(m(!1),z.current=!0):pe&&z.current&&(m(!0),z.current=!1)}},W=()=>{F!==void 0&&window.clearTimeout(F),F=window.setTimeout(()=>{U()},100)};return U(),window.addEventListener("resize",W),()=>{window.removeEventListener("resize",W),F!==void 0&&window.clearTimeout(F)}},[b,k,m,p]),o.useEffect(()=>{if(typeof window>"u")return;const F=Ie.subscribe((U,W)=>{const te=window.innerWidth,K=window.innerHeight,ae=te>=n,ve=K>=i;U.isRightSidebarOpen!==W.isRightSidebarOpen&&ae&&(R.current=!1),U.isBottomTerminalOpen!==W.isBottomTerminalOpen&&ve&&(z.current=!1)});return()=>{F()}},[b,k,m,p]);const ne=o.useMemo(()=>{switch(u){case"plan":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(ID,{})});case"git":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(jf,{})});case"diff":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(AD,{})});case"terminal":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Nf,{})});case"files":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(DD,{})});default:return null}},[u]),G=u==="chat",le=o.useMemo(()=>Math.min(FD,Math.max(RD,N||rd)),[N]),oe=o.useMemo(()=>Math.min(OD,Math.max(LD,D||Th)),[D]);return s.jsx(_j,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:ce("main-content-safe-area",b?"flex flex-col":"flex h-[100dvh]","bg-background"),style:b&&I.height>0?{height:I.height}:void 0,children:[s.jsx(GC,{}),s.jsx(R4,{}),s.jsx($4,{}),s.jsx(dD,{}),b?s.jsxs(tv,{value:{leftDrawerOpen:V,rightDrawerOpen:c,toggleLeftDrawer:()=>{c&&p(!1),$(!V)},toggleRightDrawer:()=>{V&&$(!1),p(!c)},leftDrawerX:X,rightDrawerX:J,leftDrawerWidth:O,rightDrawerWidth:Q,setMobileLeftDrawerOpen:$,setRightSidebarOpen:p},children:[!f&&s.jsx(om,{onToggleLeftDrawer:()=>{c&&p(!1),$(!V)},onToggleRightDrawer:()=>{V&&$(!1),p(!c)},leftDrawerOpen:V,rightDrawerOpen:c}),s.jsx(Jl.button,{type:"button",initial:!1,animate:{opacity:V||c?1:0,pointerEvents:V||c?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{$(!1),p(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Jl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(O.current||window.innerWidth*.85),right:0},style:{width:`${Ho}%`,x:X},onDragEnd:(F,U)=>{const W=O.current||window.innerWidth*.85,te=W*.3,K=500,ae=X.get(),ve=U.offset.x<-te||U.velocity.x<-K,re=U.offset.x>te||U.velocity.x>K;ve?(X.set(-W),$(!1)):re?(X.set(0),$(!0)):ae>-W/2?X.set(0):X.set(-W)},className:ce("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!V,children:s.jsx("div",{"data-page-scroll-lock":"true",className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(xf,{mobileVariant:!0})})})})}),s.jsx(Jl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:Q.current||window.innerWidth*.85},style:{width:`${Ho}%`,x:J},onDragEnd:(F,U)=>{const W=Q.current||window.innerWidth*.85,te=W*.3,K=500,ae=J.get(),ve=U.offset.x>te||U.velocity.x>K,re=U.offset.x<-te||U.velocity.x<-K;ve?(J.set(W),p(!1)):re?(J.set(0),p(!0)):ae<W/2?J.set(0):J.set(W)},className:ce("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!c,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(jf,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:ce("flex flex-1 overflow-hidden relative",f&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ce("absolute inset-0",!G&&"invisible"),children:s.jsx(Xs,{children:s.jsx(Pd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:ne})}),y&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Xs,{children:s.jsx(wD,{initialPrompt:w,onCreated:()=>g(!1),onCancel:()=>g(!1)})})})]})}),f&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(TD,{onClose:()=>v(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:ce("absolute inset-0 flex overflow-hidden","bg-sidebar"),"data-page-scroll-lock":"true",children:[a?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${le}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${le}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}})]}):null,c?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${oe}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:ce("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${oe}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}})]}):null,s.jsx(t1,{isOpen:a,isMobile:b,className:"border-0",children:s.jsx(xf,{})}),s.jsxs("div",{className:ce("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",a&&"border-l border-border/50 rounded-tl-[10px] rounded-bl-[10px]",c&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(om,{desktopRightSidebarActionsHost:E}),s.jsx("div",{className:ce("flex flex-1 min-h-0 overflow-hidden",a||G?"":"border-l border-border/50",c?"":"border-r border-border/50"),"data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ce("absolute inset-0",!G&&"invisible"),children:s.jsx(Xs,{children:s.jsx(Pd,{})})}),ne&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:ne})})]}),s.jsx(ES,{})]})}),s.jsx(Qw,{isOpen:d,isMobile:b,children:d?s.jsx(Xs,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Nf,{})})}):null})]}),s.jsx(s1,{isOpen:c,className:"border-0",onTopActionsHostChange:T,children:s.jsx(Xs,{children:l?s.jsx(ZA,{}):s.jsx(LN,{})})})]})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(MD,{open:f,onOpenChange:v})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(ED,{open:y,onOpenChange:g,initialPrompt:w})})]})]})})},zD=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},dr=t=>{const e=at.c(8),{label:n,value:r}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=i):i=e[0];let a;e[1]!==n?(a=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=a):a=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let c;return e[5]!==a||e[6]!==l?(c=s.jsxs("div",{className:"rounded-md p-2",style:i,children:[a,l]}),e[5]=a,e[6]=l,e[7]=c):c=e[7],c},Sf=t=>{const e=at.c(43),{title:n,snapshot:r,emptyLabel:i}=t,{t:a}=ut();let l;if(e[0]!==i||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==a||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(UD,0),e[8]=r.entries,e[9]=d):d=e[9];const p=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let u;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==a?(u=r.startedAt?zD(r.durationMs):a("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=a,e[15]=u):u=e[15];let h;e[16]!==u?(h=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=h):h=e[17];let x;e[18]!==m||e[19]!==h?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,h]}),e[18]=m,e[19]=h,e[20]=x):x=e[20];let f;e[21]!==a?(f=a("memoryDebugPanel.metric.metrics"),e[21]=a,e[22]=f):f=e[22];let v;e[23]!==r.entries.length||e[24]!==f?(v=s.jsx(dr,{label:f,value:r.entries.length}),e[23]=r.entries.length,e[24]=f,e[25]=v):v=e[25];let y;e[26]!==a?(y=a("memoryDebugPanel.metric.samples"),e[26]=a,e[27]=y):y=e[27];let g;e[28]!==y||e[29]!==p?(g=s.jsx(dr,{label:y,value:p}),e[28]=y,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==a?(w=a("memoryDebugPanel.metric.lastUpdate"),e[31]=a,e[32]=w):w=e[32];let b;e[33]!==r.lastUpdatedAt||e[34]!==a?(b=r.lastUpdatedAt?a("memoryDebugPanel.common.live"):a("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=a,e[35]=b):b=e[35];let k;e[36]!==w||e[37]!==b?(k=s.jsx(dr,{label:w,value:b}),e[36]=w,e[37]=b,e[38]=k):k=e[38];let I;e[39]!==g||e[40]!==k||e[41]!==v?(I=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,g,k]}),e[39]=g,e[40]=k,e[41]=v,e[42]=I):I=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,I,c.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:i}):s.jsx(Cs,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:a("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:a("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:a("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:a("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=i,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=a,e[6]=n,e[7]=l}else l=e[7];return l},VD=t=>{const e=at.c(101),{onClose:n}=t,{t:r}=ut(),[i,a]=o.useState("memory"),[l,c]=o.useState("idle"),d=Ot(WD),p=ph(KD),m=zl(),u=th(HD),h=mr(GD),[x,f]=o.useState(qD),[v,y]=o.useState(YD);let g;e[0]!==x.entries?(g=new Map,x.entries.forEach(Ce=>{g.set(Ce.metric,Ce.count)}),e[0]=x.entries,e[1]=g):g=e[1];let w;e[2]!==g?(w=g.get("ui.message_list.render")??0,e[2]=g,e[3]=w):w=e[3];let b;e[4]!==g?(b=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=b):b=e[5];let k;e[6]!==g?(k=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=k):k=e[7];let I;e[8]!==g?(I=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=I):I=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let N;e[12]!==g?(N=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=N):N=e[13];let D;e[14]!==w||e[15]!==b||e[16]!==k||e[17]!==I||e[18]!==j||e[19]!==N?(D={messageListRender:w,messageListRenderStreaming:b,chatMessageRender:k,chatMessageRenderStreaming:I,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:N},e[14]=w,e[15]=b,e[16]=k,e[17]=I,e[18]=j,e[19]=N,e[20]=D):D=e[20];const E=D;let T,C;e[21]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{const Ce=()=>{f(Jo()),y(Xo())};Ce();const je=window.setInterval(Ce,500);return()=>window.clearInterval(je)},C=[],e[21]=T,e[22]=C):(T=e[21],C=e[22]),o.useEffect(T,C);let S,M;e[23]!==l?(S=()=>{if(l==="idle")return;const Ce=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ce)},M=[l],e[23]=l,e[24]=S,e[25]=M):(S=e[24],M=e[25]),o.useEffect(S,M);let A=0,R;if(e[26]!==u?(R=Object.keys(u),e[26]=u,e[27]=R):R=e[27],e[28]!==u||e[29]!==R||e[30]!==A){for(const Ce of R)A=A+(u[Ce]?.length??0);e[28]=u,e[29]=R,e[30]=A,e[31]=A}else A=e[31];const z=A;let B;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ce;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ce=je=>{const we=u[je.id]?.length||0,ke=p.get(je.id);return{id:je.id,title:je.title||r("memoryDebugPanel.common.untitled"),messageCount:we,isStreaming:ke?.isStreaming||!1,isZombie:ke?.isZombie||!1,backgroundCount:ke?.backgroundMessageCount||0,lastAccessed:ke?.lastAccessedAt||0,isCurrent:je.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ce):Ce=e[42],B=m.map(Ce).sort(QD),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=B}else B=e[37];const V=B;let $;e[43]!==u?($=Object.keys(u),e[43]=u,e[44]=$):$=e[44];const _=$.length;let X;e[45]===Symbol.for("react.memo_cache_sentinel")?(X=async()=>{try{const Ce={generatedAt:new Date().toISOString(),ui:Jo(),vscode:Xo()};await navigator.clipboard.writeText(JSON.stringify(Ce,null,2)),c("copied")}catch{c("error")}},e[45]=X):X=e[45];const O=X;let J;e[46]===Symbol.for("react.memo_cache_sentinel")?(J={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=J):J=e[46];let Q;e[47]!==i?(Q=i==="memory"?s.jsx(P,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(P,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=i,e[48]=Q):Q=e[48];let ne;e[49]!==r?(ne=r("memoryDebugPanel.title"),e[49]=r,e[50]=ne):ne=e[50];let G;e[51]!==ne?(G=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ne}),e[51]=ne,e[52]=G):G=e[52];let le;e[53]!==Q||e[54]!==G?(le=s.jsxs("div",{className:"flex items-center gap-2",children:[Q,G]}),e[53]=Q,e[54]=G,e[55]=le):le=e[55];let oe;e[56]!==i?(oe=i==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ge,{size:"xs",variant:"ghost",onClick:O,children:s.jsx(P,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ge,{size:"xs",variant:"ghost",onClick:()=>{nv(),f(Jo()),y(Xo())},children:s.jsx(P,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=i,e[57]=oe):oe=e[57];let F;e[58]!==n?(F=n?s.jsx(ge,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(P,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=F):F=e[59];let U;e[60]!==oe||e[61]!==F?(U=s.jsxs("div",{className:"flex items-center gap-1",children:[oe,F]}),e[60]=oe,e[61]=F,e[62]=U):U=e[62];let W;e[63]!==le||e[64]!==U?(W=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[le,U]}),e[63]=le,e[64]=U,e[65]=W):W=e[65];let te;e[66]===Symbol.for("react.memo_cache_sentinel")?(te={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=te):te=e[66];const K=i==="memory"?"secondary":"ghost";let ae;e[67]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>a("memory"),e[67]=ae):ae=e[67];let ve;e[68]!==r?(ve=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=ve):ve=e[69];let re;e[70]!==K||e[71]!==ve?(re=s.jsx(ge,{size:"sm",variant:K,className:"flex-1",onClick:ae,children:ve}),e[70]=K,e[71]=ve,e[72]=re):re=e[72];const be=i==="streaming"?"secondary":"ghost";let pe;e[73]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>a("streaming"),e[73]=pe):pe=e[73];let ye;e[74]!==r?(ye=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ye):ye=e[75];let ie;e[76]!==be||e[77]!==ye?(ie=s.jsx(ge,{size:"sm",variant:be,className:"flex-1",onClick:pe,children:ye}),e[76]=be,e[77]=ye,e[78]=ie):ie=e[78];let ue;e[79]!==re||e[80]!==ie?(ue=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:te,children:[re,ie]}),e[79]=re,e[80]=ie,e[81]=ue):ue=e[81];let se;e[82]!==i||e[83]!==_||e[84]!==l||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==V||e[89]!==m||e[90]!==E||e[91]!==x||e[92]!==r||e[93]!==h||e[94]!==z||e[95]!==v?(se=i==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.totalMessages"),value:z}),s.jsx(dr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${_} / ${_u.MAX_SESSIONS}`})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:sv()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:_u.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:h})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx(Cs,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(Ce=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ce.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Ce.title}),Ce.isStreaming?s.jsx(P,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ce.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ce.messageCount})}),Ce.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ce.backgroundCount]}):null]})]},Ce.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Pt,{children:[s.jsx(It,{asChild:!0,children:s.jsx(ge,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(JD),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Dt,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ge,{size:"xs",variant:"outline",onClick:O,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:E.messageListRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:E.messageListRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:E.chatMessageRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:E.chatMessageRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:E.chatMessageRenderStaticDuringStream}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:E.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Sf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(Sf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=i,e[83]=_,e[84]=l,e[85]=d,e[86]=u,e[87]=p,e[88]=V,e[89]=m,e[90]=E,e[91]=x,e[92]=r,e[93]=h,e[94]=z,e[95]=v,e[96]=se):se=e[96];let Ne;return e[97]!==W||e[98]!==ue||e[99]!==se?(Ne=s.jsxs(hh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:J,children:[W,ue,se]}),e[97]=W,e[98]=ue,e[99]=se,e[100]=Ne):Ne=e[100],Ne},_D=VD;function UD(t,e){return t+e.count}function WD(t){return t.currentSessionId}function KD(t){return t.sessionMemoryState}function HD(t){return t.message}function GD(t){return t.totalRequestCount}function qD(){return Jo()}function YD(){return Xo()}function QD(t,e){return e.lastAccessed-t.lastAccessed}function JD(t){return{id:t.id,title:t.title}}const XD=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},ZD=async()=>{const t=XD()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},kf="vinci:menu-action",e6=t=>{const e=Ot(x=>x.openNewSessionDraft),n=Ie(x=>x.toggleCommandPalette),r=Ie(x=>x.setCommandPaletteOpen),i=Ie(x=>x.toggleHelpDialog),a=Ie(x=>x.toggleSidebar),l=Ie(x=>x.setSessionSwitcherOpen),c=Ie(x=>x.setActiveMainTab),d=Ie(x=>x.setSettingsDialogOpen),p=Ie(x=>x.setAboutDialogOpen),{setThemeMode:m}=Ar(),u=o.useCallback(()=>{Sr.requestDirectoryDialog()},[]),h=o.useCallback(x=>{switch(x){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),l(!1),e();break;case"new-worktree-session":c("chat"),l(!1),oh();break;case"change-workspace":u();break;case"open-git-tab":{const{activeMainTab:f}=Ie.getState();c(f==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:f}=Ie.getState();c(f==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:f}=Ie.getState();c(f==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:f}=Ie.getState();c(f==="terminal"?"chat":"terminal");break}case"copy":{const f=new Event("vinci:copy",{cancelable:!0});!window.dispatchEvent(f)||ZD();break}case"theme-light":m("light");break;case"theme-dark":m("dark");break;case"theme-system":m("system");break;case"toggle-sidebar":a();break;case"toggle-memory-debug":t?.();break;case"help-dialog":i();break;case"download-logs":{rv().catch(()=>{H.error("Failed to collect OpenCode status")});break}}},[u,t,e,p,c,l,r,d,m,n,i,a]);o.useEffect(()=>{const x=f=>{const v=f.detail;v&&h(v)};return window.addEventListener(kf,x),()=>{window.removeEventListener(kf,x)}},[h]),o.useEffect(()=>{if(typeof window>"u")return;const f=window.__TAURI__?.event?.listen;if(typeof f!="function")return;let v=null;return f("vinci:menu-action",y=>{const g=y?.payload;typeof g=="string"&&h(g)}).then(y=>{v=y}).catch(()=>{}),()=>{(async()=>{try{const g=v?.();g instanceof Promise&&await g}catch{}})()}},[h])},t6=["chat","git","diff","terminal","files"],s6=["settings","agents","commands","skills","providers","usage","git-identities"],Nr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Cf(t){const e=n6();return{sessionId:r6(e),tab:i6(e),settingsPath:a6(e),diffFile:o6(e)}}function n6(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function r6(t){const e=t.get(Nr.SESSION);return!e||e.trim().length===0?null:e.trim()}function i6(t){const e=t.get(Nr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return t6.includes(n)?n:null}function a6(t){const e=t.get(Nr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="vinci"||n==="general"||n==="preferences"?"home":(s6.includes(n),n)}function o6(t){const e=t.get(Nr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Pf(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(Nr.SESSION)||t.has(Nr.TAB)||t.has(Nr.SETTINGS)||t.has(Nr.FILE)}catch{return!1}}const l6="chat";function Kg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(Nr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(Nr.SETTINGS,n),e}return t.tab!==l6&&e.set(Nr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(Nr.FILE,t.diffFile),e}function c6(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function d6(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Kg(t),r=[...e.entries()].sort((a,l)=>a[0].localeCompare(l[0])),i=[...n.entries()].sort((a,l)=>a[0].localeCompare(l[0]));if(r.length!==i.length)return!1;for(let a=0;a<r.length;a++)if(r[a][0]!==i[a][0]||r[a][1]!==i[a][1])return!1;return!0}catch{return!0}}function u6(t,e={}){if(!(typeof window>"u")&&!m6()&&!(!e.force&&d6(t)))try{const n=Kg(t),r=c6(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function m6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function p6(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function f6(){const t=o.useMemo(()=>p6(),[]),e=o.useRef(!1),n=o.useRef(!1),r=Ot(u=>u.setCurrentSession),i=Ie(u=>u.setActiveMainTab),a=Ie(u=>u.setSettingsDialogOpen),l=Ie(u=>u.setSettingsPage),c=Ie(u=>u.navigateToDiff),d=o.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const h=Ot.getState().currentSessionId;u.sessionId!==h&&await r(u.sessionId)}if(u.settingsPath){l(lg(u.settingsPath)),a(!0);return}Ie.getState().isSettingsDialogOpen&&a(!1),u.tab&&i(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,i,a,l,c]),p=o.useCallback(()=>{const u=Ot.getState(),h=Ie.getState();return{sessionId:u.currentSessionId,tab:h.activeMainTab,isSettingsOpen:h.isSettingsDialogOpen,settingsPath:h.settingsPage,diffFile:h.pendingDiffFile}},[]),m=o.useCallback((u={})=>{if(t||n.current)return;const h=p();u6(h,u)},[t,p]);o.useEffect(()=>{if(e.current||(e.current=!0,!Pf()))return;const u=Cf();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),o.useEffect(()=>{if(t)return;let u=Ot.getState().currentSessionId;return Ot.subscribe(x=>{const f=x.currentSessionId;f===u||n.current||(u=f,m())})},[t,m]),o.useEffect(()=>{if(t)return;let u=Ie.getState().activeMainTab,h=Ie.getState().isSettingsDialogOpen,x=Ie.getState().settingsPage,f=Ie.getState().pendingDiffFile;return Ie.subscribe(y=>{if(n.current)return;const g=y.activeMainTab!==u,w=y.isSettingsDialogOpen!==h,b=y.settingsPage!==x,k=y.pendingDiffFile!==f&&y.activeMainTab==="diff";u=y.activeMainTab,h=y.isSettingsDialogOpen,x=y.settingsPage,f=y.pendingDiffFile,(g||w||b||k)&&m()})},[t,m]),o.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const h=Cf();if(Pf())d(h);else{const x=Ie.getState();x.isSettingsDialogOpen&&a(!1),x.activeMainTab!=="chat"&&i("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,i,a])}const If="pwa-install-toast-shown",h6=()=>{const t=at.c(6),{browserTab:e}=wg(),{t:n}=ut(),r=o.useRef(n);let i,a;t[0]!==n?(i=()=>{r.current=n},a=[n],t[0]=n,t[1]=i,t[2]=a):(i=t[1],a=t[2]),o.useEffect(i,a);let l,c;t[3]!==e?(l=()=>{if(typeof window>"u"||!Li()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(H.dismiss(p),p=null)},u=async()=>{if(!d)return;const f=d;d=null,m(),await f.prompt();const{outcome:v}=await f.userChoice;v==="accepted"&&H.success(r.current("pwa.installPrompt.started"))},h=f=>{const v=f;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const y=_f();y.getItem(If)!=="true"&&p===null&&(y.setItem(If,"true"),p=H.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}}}))},x=()=>{d=null,m(),H.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",h),window.addEventListener("appinstalled",x),()=>{m(),window.removeEventListener("beforeinstallprompt",h),window.removeEventListener("appinstalled",x)}},c=[e],t[3]=e,t[4]=l,t[5]=c):(l=t[4],c=t[5]),o.useEffect(l,c)},g6=["local","remote",null],x6=["ok","not-configured","unreachable","wrong-service","missing"];function Hg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!g6.includes(n)))return{valid:!1};if(typeof r!="string"||!x6.includes(r))return{valid:!1};if(n==="remote"||n==="local"){if(r==="ok"&&n==="local")return{valid:!0,outcome:{target:"local",status:"ok"}};if(r==="ok"&&n==="remote")return typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"ok",hostId:e.hostId,url:e.url}};if(r==="unreachable")return n==="local"?{valid:!0,outcome:{target:"local",status:"unreachable"}}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"unreachable",hostId:e.hostId,url:e.url}};if(r==="wrong-service")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"||typeof e.url!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"wrong-service",hostId:e.hostId,url:e.url}};if(r==="missing")return n!=="remote"?{valid:!1}:typeof e.hostId!="string"?{valid:!1}:{valid:!0,outcome:{target:"remote",status:"missing",hostId:e.hostId}}}if(n===null){if(r==="not-configured")return{valid:!0,outcome:{target:null,status:"not-configured"}};if(r==="missing")return{valid:!1}}return{valid:!1}}function Af(t){if(!t.isDesktopShell)return null;const e=t.bootOutcome;if(!e)return null;if(e.status==="ok"){if(e.target==="local")return{screen:"main"};if(e.target==="remote")return{screen:"main",hostId:e.hostId,url:e.url}}if(e.target===null&&e.status==="not-configured")return{screen:"chooser"};if(e.target==="local"&&e.status==="unreachable")return{screen:"recovery",variant:"local-unavailable"};if(e.target==="remote"){if(e.status==="unreachable")return{screen:"recovery",variant:"remote-unreachable",hostId:e.hostId,url:e.url};if(e.status==="wrong-service")return{screen:"recovery",variant:"remote-wrong-service",hostId:e.hostId,url:e.url};if(e.status==="missing")return{screen:"recovery",variant:"remote-missing",hostId:e.hostId}}return null}function b6(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function y6(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Df(){if(Id()!=="valid")return null;const e=window.__APP_DESKTOP_BOOT_OUTCOME__,n=Hg(e);return n.valid?n.outcome:null}function Id(){if(typeof window>"u")return"not-injected";const t=window.__APP_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Hg(t).valid?"valid":"malformed"}const v6=()=>{const t=at.c(5),[e,n]=o.useState(w6),{isUpdating:r,message:i}=e;let a,l;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>av(n),l=[],t[0]=a,t[1]=l):(a=t[0],l=t[1]),o.useEffect(a,l),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx($d,{width:80,height:80}),t[2]=c):c=t[2];let d;return t[3]!==i?(d=s.jsxs("div",{className:"fixed inset-0 z-[9999] flex flex-col items-center justify-center gap-6 bg-background/90",children:[c,s.jsx("p",{className:"typography-body text-muted-foreground",children:i})]}),t[3]=i,t[4]=d):d=t[4],d};function w6(){return iv()}const j6=({open:t,onOpenChange:e})=>{const{t:n}=ut(),[r,i]=o.useState(null),[a,l]=o.useState(null),[c,d]=o.useState(!1),[p,m]=o.useState(!1),[u,h]=o.useState(null),[x,f]=o.useState(!1),v=o.useCallback(async()=>{if(!c){d(!0),m(!1);try{if(!u){H.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const g=await Uu.copyTextToClipboard(u);g.ok?(m(!0),H.success(n("aboutDialog.toast.diagnosticsCopied"))):H.error(n("aboutDialog.toast.copyFailed"),{description:g.error})}catch(g){H.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",g)}finally{d(!1)}}},[u,c,n]);o.useEffect(()=>{if(!t)return;(async()=>{try{const w=await fetch("/api/system/info");if(w.ok){const b=await w.json();if(typeof b.vinciVersion=="string"&&b.vinciVersion.trim()){i(b.vinciVersion);return}}}catch{}i(await ov())})()},[t]),o.useEffect(()=>{if(!t)return;let g=!1;return(async()=>{try{const b=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!b.ok)return;const k=await b.json().catch(()=>null),I=typeof k?.currentVersion=="string"?k.currentVersion.trim():"";!g&&I&&l(I)}catch{}})(),()=>{g=!0}},[t]),o.useEffect(()=>{if(!t){h(null),f(!1);return}let g=!1;return f(!0),Uu.buildDiagnosticsReport().then(w=>{g||h(w)}).catch(w=>{g||(console.error("Failed to prepare diagnostics:",w),h(null))}).finally(()=>{g||f(!1)}),()=>{g=!0}},[t]);const y=r;return s.jsx(hs,{open:t,onOpenChange:e,children:s.jsx(fs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx($d,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"Vinci"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[y&&s.jsx("p",{children:n("aboutDialog.vinciVersionLabel",{version:y})}),a&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:a})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:v,disabled:c||x||!u,className:ce("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(p?"aboutDialog.actions.diagnosticsCopied":x?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[s.jsxs("a",{href:"https://github.com/jaygupta17/vinci",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/eSSmgeX8Q",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/guptajay17",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(P,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@guptajay17"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Kc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},N6=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to Vinci and click Authorize again.":n},S6=()=>{const t=yn(a=>a.completeAuth),[e,n]=o.useState("working"),[r,i]=o.useState("Completing MCP authorization...");return o.useEffect(()=>{if(typeof window>"u"){n("error"),i("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),l=Kc(a,"code"),c=pg(a),d=Zd(a),p=Kc(a,"error"),m=Kc(a,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),i(m??p);return}(async()=>{try{if(!l)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");let u=c;if(!u&&d){const h=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(h.ok){const x=await h.json().catch(()=>null);x?.name?.trim()&&(u={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into Vinci manually.");await t(u.name,l,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),i("Authorization completed. You can close this tab and return to Vinci.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),i(N6(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(ge,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to Vinci"})})]})})},Go="opencode-update-available",qo="opencode-upgrade-progress",k6=5e3,C6=[1e4,6e4],Gg=()=>{const{t}=ut(),e=Ie(l=>l.showOpenCodeUpdateNotifications),n=Be.useRef(new Set),r=Be.useRef(!1);Be.useEffect(()=>{e||H.dismiss(Go)},[e]);const i=Be.useCallback(()=>{H.dismiss(qo),Fi({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),a=Be.useCallback(async()=>{if(!r.current){r.current=!0,H.dismiss(Go),H.message(t("opencodeUpdate.toast.upgrading.title"),{id:qo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(P,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await l.json().catch(()=>null);if(!l.ok||c?.success===!1)throw new Error(c?.error||l.statusText||t("opencodeUpdate.toast.failed.description"));H.success(t("opencodeUpdate.toast.updated.title"),{id:qo,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(P,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:i}})}catch(l){H.error(t("opencodeUpdate.toast.failed.title"),{id:qo,description:l instanceof Error?l.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[i,t]);return Be.useEffect(()=>{const l=u=>{if(!Ie.getState().showOpenCodeUpdateNotifications){H.dismiss(Go);return}u&&(n.current.has(u)||(n.current.add(u),H.info(t("opencodeUpdate.toast.available.title"),{id:Go,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:a}})))},c=u=>{const h=typeof u.detail?.version=="string"?String(u.detail.version).trim():"";l(h)};let d=!1;const p=[],m=async u=>{try{const h=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!h.ok)throw new Error(h.statusText||"OpenCode upgrade status check failed");const x=await h.json().catch(()=>null),f=typeof x?.latestVersion=="string"?x.latestVersion.trim():"";!d&&x?.available===!0&&f&&l(f)}catch{const h=C6[u];!d&&h!==void 0&&p.push(setTimeout(()=>{m(u+1)},h))}};return e&&p.push(setTimeout(()=>{m(0)},k6)),window.addEventListener("vinci:opencode-update-available",c),()=>{d=!0;for(const u of p)clearTimeout(u);window.removeEventListener("vinci:opencode-update-available",c)}},[a,e,t]),null},Tf=si(()=>kr(()=>import("./OnboardingScreen-1fIy0izk.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),P6=()=>{const t=at.c(3),e=Ie(E6),n=Ie(R6);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(j6,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},I6=t=>{const e=at.c(21),{onRetry:n,isRetrying:r}=t,{t:i}=ut();let a;e[0]!==i?(a=i("startup.initRecovery.title"),e[0]=i,e[1]=a):a=e[1];let l;e[2]!==a?(l=s.jsx("h1",{className:"typography-title text-foreground",children:a}),e[2]=a,e[3]=l):l=e[3];let c;e[4]!==i?(c=i("startup.initRecovery.description"),e[4]=i,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==l||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,d]}),e[8]=l,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==i?(m=i(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=i,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(ge,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let h;return e[18]!==p||e[19]!==u?(h=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=h):h=e[20],h},Mf=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",A6=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search);if(t.get("ocPanel")!=="session-chat")return null;const e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),i=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:i,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},D6=()=>typeof window>"u"?!1:window.location.pathname===mg,T6=t=>{const e=at.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:i}=t,a=$s(F6),l=Ot(L6),c=Ot(O6),d=_d(),p=o.useRef(null);let m;e[0]!==n.directory?(m=Mf(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let h;e[2]!==a?(h=Mf(a),e[2]=a,e[3]=h):h=e[3];const x=h;let f,v;if(e[4]!==x||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(f=()=>{if(r||u&&x!==u)return;const I=`${u}
|
|
226
226
|
${n.sessionId}`;p.current===I&&l===n.sessionId||(p.current=I,c(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},v=[x,l,n.directory,n.sessionId,u,r,c,d],e[4]=x,e[5]=l,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=c,e[11]=d,e[12]=f,e[13]=v):(f=e[12],v=e[13]),o.useEffect(f,v),u&&x!==u)return null;let y;e[14]!==i?(y=s.jsx(gh,{embeddedBackgroundWorkEnabled:i}),e[14]=i,e[15]=y):y=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Gg,{}),e[16]=g):g=e[16];let w;e[17]!==n.readOnly?(w=s.jsx(Pd,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=w):w=e[18];let b;e[19]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(xh,{}),e[19]=b):b=e[19];let k;return e[20]!==y||e[21]!==w?(k=s.jsxs(s.Fragment,{children:[y,g,w,b]}),e[20]=y,e[21]=w,e[22]=k):k=e[22],k};function M6({apis:t}){console.log("[App] Rendering with apis:",!!t,"keys:",Object.keys(t||{}));const e=xt(F=>F.initializeApp),n=xt(F=>F.isInitialized),r=xt(F=>F.isConnected),i=xt(F=>F.providers.length),a=xt(F=>F.agents.length),l=xt(F=>F.loadProviders),c=xt(F=>F.loadAgents),d=Ot(F=>F.error),p=Ot(F=>F.clearError),m=$s(F=>F.currentDirectory),u=$s(F=>F.setDirectory),h=$s(F=>F.isSwitchingDirectory),[x,f]=o.useState(!1),v=Hn(F=>F.refreshStatus),[y,g]=o.useState(()=>t.runtime.isVSCode),[w,b]=o.useState(!0),[k,I]=o.useState(!1),[j,N]=o.useState(0),[D,E]=o.useState(!1),T=Ie(F=>F.wideChatLayoutEnabled),C=Ie(F=>F.mobileKeyboardMode),S=o.useMemo(()=>gn(),[]),M=Td(F=>F.setPlanModeEnabled),[A,R]=o.useState(()=>Id()),[z,B]=o.useState(()=>{const F=Df();return F!==null?Af({isDesktopShell:!0,bootOutcome:F}):null}),V=o.useRef(!1),$=o.useMemo(()=>A6(),[]),_=!$||w,X=o.useMemo(()=>D6(),[]);o.useEffect(()=>(Wu(x),()=>{Wu(!1)}),[x]),o.useEffect(()=>{lv(C)},[C]),o.useEffect(()=>{g(t.runtime.isVSCode)},[t.runtime.isVSCode]),o.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",T),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[T]),o.useEffect(()=>(Ku(t),()=>Ku(null)),[t]),o.useEffect(()=>{$||v(t.github,{force:!0})},[t.github,$,v]),cv();const O=A==="valid",J=z?.screen==="main";o.useEffect(()=>{if(!b6({isDesktopShell:S,isInitialized:n,bootOutcomeKnown:O,bootViewIsMain:J}))return;const F=setTimeout(()=>{const U=document.getElementById("initial-loading");U&&(U.classList.add("fade-out"),setTimeout(()=>{U.remove()},300))},150);return()=>clearTimeout(F)},[S,n,O,J]),o.useEffect(()=>{if(!S||A!=="malformed")return;const F=document.getElementById("initial-loading");F&&(F.textContent="Desktop startup failed — please restart the app.")},[S,A]),o.useEffect(()=>{if(S)return;const F=setTimeout(()=>{const U=document.getElementById("initial-loading");U&&!n&&(U.classList.add("fade-out"),setTimeout(()=>{U.remove()},300))},5e3);return()=>clearTimeout(F)},[S,n]),o.useEffect(()=>{let F=!1;return(async()=>{const W=await fetch("/health",{method:"GET"}).catch(()=>null);if(!W||!W.ok||F)return;const te=await W.json().catch(()=>null);if(!te||F)return;const K=te.planModeExperimentalEnabled;M(K===!0||K===1||K==="1"||K==="true")})(),()=>{F=!0}},[M]),o.useEffect(()=>{y||e()},[e,y]),o.useEffect(()=>{if(y||n)return;let F=!0,U,W=0;const te=10,K=1e3,ae=async()=>{if(!F)return;if(W>=te){I(!0);return}const ve=xt.getState();if(ve.isInitialized){I(!1);return}W+=1,await ve.initializeApp();const re=xt.getState();if(!F)return;if(re.isInitialized){I(!1);return}if(W>=te){I(!0);return}const be=Math.min(K*Math.pow(2,W-1),16e3);U=setTimeout(ae,be)};return U=setTimeout(ae,K),()=>{F=!1,U&&clearTimeout(U)}},[j,n,y]),o.useEffect(()=>{n&&I(!1)},[n]),o.useEffect(()=>{if(!k)return;const F=document.getElementById("initial-loading");F&&(F.classList.add("fade-out"),setTimeout(()=>{F.remove()},300))},[k]),o.useEffect(()=>{if(y||!r||i>0&&a>0)return;let F=!0,U=0;const W=15,te=async()=>{const ae=xt.getState();if(!(ae.providers.length>0&&ae.agents.length>0))try{ae.providers.length===0&&await l(),xt.getState().agents.length===0&&await c()}catch{}};te();const K=setInterval(()=>{if(F){if(++U>=W){clearInterval(K);return}te()}},2e3);return()=>{F=!1,clearInterval(K)}},[r,y,c,l,i,a]),o.useEffect(()=>{h||y||r&&Zs.setDirectory(m)},[m,h,r,y]),o.useEffect(()=>{if(!$||typeof window>"u")return;const F=te=>{const K=te?.visible===!0;b(K)},U=te=>{if(te.origin!==window.location.origin)return;const K=te.data;K?.type==="vinci:embedded-visibility"&&F(K.payload)},W=window;return W.__vinciSetEmbeddedVisibility=F,window.addEventListener("message",U),()=>{window.removeEventListener("message",U),W.__vinciSetEmbeddedVisibility===F&&delete W.__vinciSetEmbeddedVisibility}},[$]),o.useEffect(()=>{!$?.directory||y||m!==$.directory&&u($.directory,{showOverlay:!1})},[m,$,y,u]),o.useEffect(()=>{if(!$||typeof window>"u")return;const F=U=>{U.storageArea===window.localStorage&&U.key==="ui-store"&&Ie.persist.rehydrate()};return window.addEventListener("storage",F),()=>{window.removeEventListener("storage",F)}},[$]),o.useEffect(()=>{if(typeof window>"u")return;const F=U=>{const W=U.detail,te=typeof W?.sessionId=="string"?W.sessionId.trim():"";if(!te)return;const K=typeof W?.directory=="string"&&W.directory.trim().length>0?W.directory.trim():null;Ie.getState().setActiveMainTab("chat"),Ot.getState().setCurrentSession(te,K)};return window.addEventListener("vinci:open-session",F),()=>window.removeEventListener("vinci:open-session",F)},[]),o.useEffect(()=>{if(typeof window>"u")return;const F=U=>{const W=U.detail,te=typeof W?.directory=="string"&&W.directory.trim().length>0?W.directory.trim():null,K=typeof W?.projectId=="string"&&W.projectId.trim().length>0?W.projectId.trim():null;Ie.getState().setActiveMainTab("chat"),Ie.getState().setSessionSwitcherOpen(!1),Ot.getState().openNewSessionDraft({selectedProjectId:K,directoryOverride:te,preserveDirectoryOverride:!!te})};return window.addEventListener("vinci:open-draft-session",F),()=>window.removeEventListener("vinci:open-draft-session",F)},[]),o.useEffect(()=>{if(typeof window>"u")return;const F=U=>{const W=U.detail,te=typeof W?.projectPath=="string"?W.projectPath.trim():"";if(!te)return;const K=As.getState(),ae=K.projects.find(ve=>ve.path===te);ae?K.setActiveProject(ae.id):K.addProject(te)};return window.addEventListener("vinci:open-project",F),()=>window.removeEventListener("vinci:open-project",F)},[]),o.useEffect(()=>{typeof window>"u"||!n||h||V.current||(V.current=!0,window.__vinciAppReady=!0,window.dispatchEvent(new Event("vinci:app-ready")))},[n,h]),dv({enabled:_}),h6(),uv(),f6();const Q=o.useCallback(()=>{f(F=>!F)},[]);e6(Q),o.useEffect(()=>{if($)return;const F=U=>{Md(U)&&U.shiftKey&&!U.altKey&&(U.code==="KeyD"||U.key.toLowerCase()==="d")&&(U.preventDefault(),f(te=>!te))};return window.addEventListener("keydown",F,!0),()=>window.removeEventListener("keydown",F,!0)},[$]),o.useEffect(()=>{$||d&&setTimeout(()=>p(),5e3)},[p,$,d]),o.useEffect(()=>{if(!S||A!=="not-injected")return;let F=!1,U=0;const W=200,te=2e3,K=50,ae=()=>{if(F)return;U++;const ve=Id();if(ve!=="not-injected"){if(F=!0,R(ve),ve==="valid"){const be=Df();be&&B(Af({isDesktopShell:!0,bootOutcome:be}))}return}const re=Math.min(W*Math.pow(1.1,U),te);if(U>=K){const be=document.getElementById("initial-loading");be&&!be.textContent?.includes("taking longer")&&(be.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ae,re)};return window.setTimeout(ae,W),()=>{F=!0}},[S,A]);const ne=o.useCallback(async()=>{if(y6({isTauriShell:pa(),isDesktopLocalOriginActive:Bi()})){await ih();return}window.location.reload()},[]),G=o.useCallback(async()=>{if(!D){I(!1),E(!0);try{await xt.getState().initializeApp()}finally{E(!1)}xt.getState().isInitialized||N(F=>F+1)}},[D]),le=F=>{if(F.screen==="recovery")return F.variant};if(S&&z&&z.screen!=="main"){if(z.screen==="chooser")return s.jsx(Xs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Tf,{mode:"first-launch",onCliAvailable:ne,onChooseRemote:()=>{}})})})});const F=le(z),U=z.screen==="recovery"&&"url"in z?z.url:void 0;return s.jsx(Xs,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Tf,{mode:"recovery",recoveryVariant:F,recoveryHostUrl:U,recoveryHostLabel:void 0,onCliAvailable:ne})})})})}if($)return s.jsx(Xs,{children:s.jsx(Hu,{sdk:Zs.getSdkClient(),directory:m||"",children:s.jsx(Gu,{apis:t,children:s.jsx(qu,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(T6,{embeddedSessionChat:$,isVSCodeRuntime:y,embeddedBackgroundWorkEnabled:_})})})})})});if(X)return s.jsx(Xs,{children:s.jsx(S6,{})});if(k&&!n&&!y&&!$)return s.jsx(Xs,{children:s.jsx(I6,{onRetry:()=>{G()},isRetrying:D})});const oe=!n&&!S;return s.jsx(Xs,{children:s.jsx(Hu,{sdk:Zs.getSdkClient(),directory:m||"",children:s.jsx(Gu,{apis:t,children:s.jsx(E1,{children:s.jsx(mv,{children:s.jsx(qu,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:S?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(gh,{embeddedBackgroundWorkEnabled:_}),s.jsx(Gg,{}),s.jsx(BD,{}),s.jsx(xh,{}),!oe&&s.jsxs(s.Fragment,{children:[s.jsx(v6,{}),s.jsx(P6,{}),x&&s.jsx(_D,{onClose:()=>f(!1)})]})]})})})})})})})}function E6(t){return t.isAboutDialogOpen}function R6(t){return t.setAboutDialogOpen}function F6(t){return t.currentDirectory}function L6(t){return t.currentSessionId}function O6(t){return t.setCurrentSession}const au=typeof window<"u"&&window.__VINCI_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();console.log("[ui-main] Runtime APIs loaded:",!!au);console.log("[ui-main] Runtime keys:",Object.keys(au||{}));pv();fv().then(()=>{Promise.all([hv(),gv()]).catch(t=>{console.error("[main] settings init failed:",t)}),xv(),bv(),yv()}).catch(t=>{console.error("[main] appearance init failed:",t)});const qg=document.getElementById("root");if(!qg)throw new Error("Root element not found");Fx.createRoot(qg).render(s.jsx(Be.StrictMode,{children:s.jsx(vv,{children:s.jsx(wv,{children:s.jsx(jv,{children:s.jsx(Nv,{children:s.jsx(M6,{apis:au})})})})})}));const H6=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{wD as M,Zo as P,OC as S,Cr as a,H6 as m,on as u};
|