@openchamber/web 1.18.0 → 1.18.1
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/{DiagramView-1-LZVuzn.js → DiagramView-DZmf30ko.js} +1 -1
- package/dist/assets/{FilesView-BDRX8vU2.js → FilesView-cJPeFhDe.js} +6 -6
- package/dist/assets/{MarkdownRendererImpl-fZSdR7PD.js → MarkdownRendererImpl-DZezL90a.js} +1 -1
- package/dist/assets/{OnboardingScreen-D81UrlA4.js → OnboardingScreen-ChYr0xqs.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-cSK3t3TR.js → SessionSwitcherDropdown-BV7FfPbT.js} +1 -1
- package/dist/assets/{SettingsWindow-CozowJLm.js → SettingsWindow-UybkBD1p.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-CQYNvKbk.js → contextPanelEmbeddedChat-DW3atb4h.js} +1 -1
- package/dist/assets/{de-C2n4oo1Z.js → de-rVJ-hXrd.js} +3 -3
- package/dist/assets/es-D7ZyOToq.js +15 -0
- package/dist/assets/{fr-DDFUp5jS.js → fr-hl5i-ZI0.js} +2 -2
- package/dist/assets/{index-BCCcokur.css → index-CL9MYe8V.css} +1 -1
- package/dist/assets/{ja-B7SxobKm.js → ja-DqakdvOp.js} +2 -2
- package/dist/assets/{ko-CWGq93SO.js → ko-dNl8A3Xf.js} +2 -2
- package/dist/assets/main-B5TIsU2y.js +209 -0
- package/dist/assets/{main-Cts0BwVk.js → main-_m6HD9-a.js} +2 -2
- package/dist/assets/{markdownCore-BqzEkymd.js → markdownCore-DpT1vbbv.js} +2 -2
- package/dist/assets/{miniChat-ChuQD2KK.js → miniChat-wYb8p9vG.js} +2 -2
- package/dist/assets/{mobile-c-CRD1Cz.js → mobile-ExXAVUcv.js} +2 -2
- package/dist/assets/{pl-DZmyxLo7.js → pl-C5HQx1Hf.js} +3 -3
- package/dist/assets/pt-BR-CNCoBDAM.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-9uaZAJjw.js → renderElectronMiniChatApp-DPDzIT8W.js} +2 -2
- package/dist/assets/{renderMobileApp-Dm1tmU2a.js → renderMobileApp-CzWvxR9e.js} +3 -3
- package/dist/assets/runtimeEndpointReset-DKzVWH1w.js +180 -0
- package/dist/assets/uk-Bn-3AMpk.js +15 -0
- package/dist/assets/{useAppFontEffects-pyTMaGQu.js → useAppFontEffects-DdvGxoPX.js} +133 -133
- package/dist/assets/zh-CN-BCwvQpZm.js +15 -0
- package/dist/assets/zh-TW-TRHrkN9l.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -2
- package/server/lib/openchamber-control/DOCUMENTATION.md +9 -1
- package/server/lib/openchamber-sessions/routes.js +117 -4
- package/server/lib/openchamber-sessions/routes.test.js +129 -16
- package/server/lib/opencode/DOCUMENTATION.md +2 -0
- package/server/lib/opencode/proxy.js +21 -3
- package/server/lib/small-model/DOCUMENTATION.md +11 -4
- package/server/lib/small-model/call.js +19 -3
- package/server/lib/small-model/call.test.js +9 -2
- package/server/lib/small-model/index.js +10 -1
- package/server/lib/small-model/index.test.js +20 -1
- package/server/lib/walkthrough/DOCUMENTATION.md +23 -0
- package/server/lib/walkthrough/index.js +17 -0
- package/server/lib/walkthrough/reproduce-2607.test.js +148 -0
- package/server/opencode-proxy.test.js +83 -0
- package/dist/assets/es-DP7jRKkr.js +0 -15
- package/dist/assets/main-Cqfcxvqq.js +0 -209
- package/dist/assets/pt-BR-BKR5oHQ7.js +0 -15
- package/dist/assets/runtimeEndpointReset-DL5z84w2.js +0 -180
- package/dist/assets/uk-D7oAI_Wc.js +0 -15
- package/dist/assets/zh-CN-Ddjz1_9w.js +0 -15
- package/dist/assets/zh-TW-D3X01YXj.js +0 -15
- /package/dist/assets/{index-ChZvuURI.js → index-DjZ4W8hy.js} +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiagramView-DZmf30ko.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-DjZ4W8hy.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/vendor-zustand-BAGL70zf.js","assets/index-CL9MYe8V.css","assets/useAppFontEffects-DdvGxoPX.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BuzaMvKv.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-DKpLs02S.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-DW3atb4h.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-pierre-diffs-B1TeaSIY.js","assets/vendor-lru_map-Tstukz9J.js","assets/vendor-pierre-theming-D_y07OK2.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-diff-C3JhlQdm.js","assets/vendor-shiki-DuWDB27E.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-CTJVwiVf.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-B3NPxZ-7.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-CWhyzlcb.js","assets/vendor-codemirror-lang-json-Bty2AtQK.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-D_jk9hVN.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-Dxy5thAH.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-dH8tblNV.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-o9e2Fm3f.js","assets/vendor-codemirror-lang-python-PETDP1TX.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-legacy-modes-DBXLFsoH.js","assets/vendor-codemirror-commands-eyb3xW_0.js","assets/vendor-framer-motion-CRSgBxjL.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/FilesView-cJPeFhDe.js","assets/runtimeEndpointReset-DKzVWH1w.js","assets/vendor-yaml-3778uTud.js","assets/vendor-codemirror-search-8kyQdB3f.js","assets/vendor-replit-codemirror-vim-D0xSkRWg.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/vendor-ghostty-web-CfpAcbEe.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/SettingsWindow-UybkBD1p.js","assets/OnboardingScreen-ChYr0xqs.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{f as ot,j as s,R as a,r as $e,h as Sh}from"./vendor-react-BUCujlKS.js";import{w as ur,x as ua,O as Ac,D as kh,y as Nh,z as Ku,r as us,m as fa,u as Ee,A as Ch,B as nr,C as Ah,E as _t,F as Zn,G as ma,H as Gu,e as Nr,I as Qi,J as qu,K as Yu,L as Ol,M as Cr,N as Xi,P as Dh,a as $n,Q as Ph,R as Ih,S as Rh,T as Qu,l as vr,q as Fn,U as Mh,V as Th,W as Xu,X as ha,Y as wo,k as vs,Z as Ll,_ as ul,o as Ju,d as jo,$ as Oi,a0 as Li,a1 as Eh,a2 as Fh,a3 as Oh,a4 as Lh,a5 as Dc,a6 as Pc,a7 as Ic,a8 as Rc,a9 as Bh,n as Mc,aa as $h,ab as _h,ac as zh,t as Vh,v as Wh}from"./index-DjZ4W8hy.js";import{_ as Bo}from"./vendor-vite-runtime-DD1OZmLC.js";import{I as A,f as ft,g as Pe,aI as is,aJ as tr,t as fe,aK as qs,aL as Ln,aM as Ys,aN as Qs,G as lo,R as _n,aO as Dr,o as io,aP as Tc,aQ as St,aR as kt,aS as Nt,aT as Zu,aU as ai,aV as Uh,v as Je,aW as Hh,aX as Kh,aY as ef,aZ as Gh,a_ as Bi,a$ as qh,b0 as Yh,F as tf,b1 as Qh,P as li,b2 as Ji,b3 as _r,q as ci,s as sf,k as Bl,b4 as nf,b5 as Co,i as rs,b6 as Xh,x as rf,u as gn,b as ds,af as Ar,b7 as of,b8 as $l,b9 as Jh,ba as Zh,bb as _l,bc as pa,bd as fl,ag as zl,be as ga,bf as so,bg as Ps,bh as Is,bi as Us,bj as Ls,bk as Hs,bl as rr,B as He,bm as af,bn as Fa,a8 as Cs,C as ep,bo as tp,bp as sp,a7 as Ao,bq as np,br as rp,bs as op,a6 as Vl,a0 as nn,a9 as $o,bt as lf,Y as Wr,_ as Wl,Z as _o,$ as Ul,h as ip,bu as Gn,bv as ap,bw as lp,bx as cp,by as no,bz as ml,bA as On,bB as dp,bC as up,bD as fp,bE as To,bF as ao,bG as xa,bH as ba,bI as ya,bJ as wa,bK as va,bL as Sr,bM as kr,bN as mp,bO as hp,L as sr,bP as pp,bQ as gp,bR as xp,bS as bp,bT as yp,bU as Hl,bV as wp,bW as vp,bX as jp,bY as Sp,bZ as kp,b_ as Np,b$ as Cp,c0 as xn,c1 as bn,c2 as rn,c3 as yn,c4 as ys,c5 as Ap,c6 as oo,c7 as Dp,c8 as Pp,c9 as ja,ca as Ip,cb as Rp,cc as Mp,cd as gi,a5 as Tp,V as Sa,ce as Ep,cf as Oa,cg as di,ch as Fp,ci as So,cj as Ec,M as ka,ck as Kl,cl as Gl,cm as cf,cn as Op,co as Lp,cp as xi,cq as Bp,cr as La,cs as df,ct as $p,O as ql,cu as ti,c as ui,d as Na,U as uf,cv as ff,cw as _p,r as Bn,cx as zp,S as Yl,cy as mf,cz as Vp,cA as Wp,cB as Fc,cC as hf,cD as Up,cE as pf,e as Eo,cF as Zi,cG as Hp,cH as Oc,cI as Vr,cJ as hl,cK as Kp,cL as Gp,cM as Lc,cN as kn,cO as gf,cP as qp,cQ as $i,cR as Yp,J as Ql,H as Xl,K as Jl,cS as Zl,cT as pl,cU as xf,cV as Qp,cW as Xp,D as Jp,cX as Zp,cY as Bc,cZ as eg,c_ as tg,c$ as bf,d0 as sg,d1 as ng,d2 as rg,d3 as og,d4 as $c,d5 as ig,y as ag,d6 as yf,z as lg,d7 as _c,d8 as cg,d9 as dg,da as ug,db as fg,dc as mg,dd as hg,de as Ca,a as Aa,df as pg,dg as Ba,A as ea,dh as gg,di as xg,dj as zc,ap as gl,dk as wf,W as bg,X as yg,as as wg,dl as vg,E as jg,dm as Sg,dn as kg,dp as vf,dq as jf,dr as Sf,ds as Ng,dt as Cg,du as Ag,dv as Dg,dw as Pg,dx as Ig,dy as Rg,dz as Mg,dA as Tg,dB as ta,dC as Eg,dD as Vc,dE as Fg,dF as Og,dG as Lg,dH as Da,dI as Bg,dJ as Wc,dK as $g,dL as _g,dM as zg,dN as Vg,dO as Wg,dP as Ug,dQ as Hg,dR as Kg,dS as Gg,dT as _i,dU as qg,dV as Yg,dW as Uc,dX as Qg,aj as Xg,ak as Jg,al as Zg,an as Hc,ao as Kc,aq as kf,ar as Nf,aD as ex,aE as tx,aF as sx,aG as nx,aH as rx,az as ox,aA as ix,aB as ax,aC as lx}from"./useAppFontEffects-DdvGxoPX.js";import{s as Gc,t as gs,v as cx,w as qc,x as yr,y as dx,z as $a,d as fi,U as sa,B as na,E as Fo,F as bi,G as Oo,g as Cf,i as Af,a as Ws,b as ux,Q as Df,H as fx,I as mx,J as hx,M as xl,K as Pf,P as ec,L as px,R as sn,V as If,W as gx,C as xx,c as bx,X as yi,Y as Rf,Z as yx,_ as Mf,$ as Tf,a0 as Ef,e as Ff,o as Of,T as Lf,a1 as wx,a2 as vx,a3 as jx,a4 as Bf,u as si,N as Sx,D as kx,a5 as Nx,a6 as Yc,a7 as Cx,k as Ax,q as Dx,n as bl,a8 as Px,a9 as Ix,f as Rx,aa as Mx,ab as Tx,ac as Ex,j as Fx,l as Ox,O as $f,m as Lx,ad as Bx}from"./runtimeEndpointReset-DKzVWH1w.js";import{u as _f,S as $x,C as _x,W as zf}from"./SessionSwitcherDropdown-BV7FfPbT.js";import{u as Yr,F as Vf}from"./FilesView-cJPeFhDe.js";import{c as zo,u as er,d as Wf,p as zx}from"./vendor-zustand-BAGL70zf.js";import{p as Vx,t as Wx,a as Ux,b as Hx}from"./vendor-pierre-diffs-B1TeaSIY.js";import{g as Kx,E as Gx,b as qx,i as Yx}from"./contextPanelEmbeddedChat-DW3atb4h.js";import{f as ra,h as Do,T as Qx,M as Xx,D as oa,j as ia,P as yl,b as Jx,d as Zx,k as wl,i as eb}from"./vendor-dnd-kit-core-BZknOX2w.js";import{a as Uf,S as vl,v as jl,u as tc,s as tb}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as sc}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{u as sb}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{M as Qc,a as Xc,b as Jc,C as nb,c as rb,d as ob,S as ib,e as ab,f as lb}from"./vendor-base-ui-BuzaMvKv.js";import{d as Hf}from"./vendor-cron-parser-CUcP7OfX.js";import{u as Zc,a as ed,m as td}from"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-CTJVwiVf.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-B3NPxZ-7.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CWhyzlcb.js";import"./vendor-codemirror-lang-json-Bty2AtQK.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-D_jk9hVN.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-Dxy5thAH.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-dH8tblNV.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-o9e2Fm3f.js";import"./vendor-codemirror-lang-python-PETDP1TX.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-legacy-modes-DBXLFsoH.js";import"./vendor-codemirror-commands-eyb3xW_0.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-yaml-3778uTud.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-D0xSkRWg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-ghostty-web-CfpAcbEe.js";import"./vendor-react-drawio-Ct3Q0DsD.js";import"./vendor-lru_map-Tstukz9J.js";import"./vendor-pierre-theming-D_y07OK2.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-diff-C3JhlQdm.js";import"./vendor-shiki-DuWDB27E.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";function Kf(t){const e=ot.c(5),{className:n}=t,o=`relative inline-block overflow-hidden rounded-[2px] ${n===void 0?"h-5 w-5":n}`;let i,c,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx("span",{className:"absolute left-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-error)]/25"}),c=s.jsx("span",{className:"absolute right-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-success)]/25"}),l=s.jsx(A,{name:"layout-column",className:"absolute inset-0 h-full w-full"}),e[0]=i,e[1]=c,e[2]=l):(i=e[0],c=e[1],l=e[2]);let d;return e[3]!==o?(d=s.jsxs("span",{"aria-hidden":"true",className:o,children:[i,c,l]}),e[3]=o,e[4]=d):d=e[4],d}function sd(t){const e=ot.c(14);let n,r,o,i;e[0]!==t?({size:o,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=i):(n=e[1],r=e[2],o=e[3],i=e[4]);const c=typeof o=="number"?`${o}px`:o,l=typeof o=="number"?`${o}px`:o;let d;e[5]!==i||e[6]!==c||e[7]!==l?(d={width:c,height:l,...i},e[5]=i,e[6]=c,e[7]=l,e[8]=d):d=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=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]=u):u=e[9];let h;return e[10]!==n||e[11]!==r||e[12]!==d?(h=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:u}),e[10]=n,e[11]=r,e[12]=d,e[13]=h):h=e[13],h}const cb="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",db="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",_a=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__==="darwin"?cb:t.id==="terminal"?db:void 0}),nd=t=>{const e=ot.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[i,c]=a.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const d=l,u=r||o;if(u&&!i){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>c(!0),e[2]=p):p=e[2];let x;return e[3]!==u?(x=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:p}),e[3]=u,e[4]=x):x=e[4],x}let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=Pe("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=h):h=e[5];let f;return e[6]!==d?(f=s.jsx("span",{className:h,children:d}),e[6]=d,e[7]=f):f=e[7],f},ub=t=>{const e=ot.c(75),{directory:n,className:r}=t,{t:o}=ft(),i=Yr(fb),c=Yr(mb),l=Yr(hb),d=Yr(pb),u=Yr(gb),h=Yr(xb),f=Yr(bb);let p,x;e[0]!==u?(p=()=>{u()},x=[u],e[0]=u,e[1]=p,e[2]=x):(p=e[1],x=e[2]),a.useEffect(p,x);const b=ur()&&ua();let S;e:{let Q;e[3]!==c||e[4]!==i?(Q=c.find(W=>W.id===i)??c.find(yb)??c[0]??Ac[0],e[3]=c,e[4]=i,e[5]=Q):Q=e[5];const Me=Q;if(Me){let W;e[6]!==Me?(W=_a(Me),e[6]=Me,e[7]=W):W=e[7],S=W;break e}let xe;e[8]===Symbol.for("react.memo_cache_sentinel")?(xe=_a(Ac[0]),e[8]=xe):xe=e[8],S=xe}const g=S;if(!b||!n||c.length===0)return null;let m;e[9]!==n?(m=async Q=>{await Nh(n,Q.id,Q.appName)||await Ku(n,Q.appName)},e[9]=n,e[10]=m):m=e[10];const y=m;let C;e[11]!==y||e[12]!==f?(C=async Q=>{await f(Q.id),await y(Q)},e[11]=y,e[12]=f,e[13]=C):C=e[13];const j=C;let w;e[14]!==n||e[15]!==o?(w=async()=>{(await tr(n)).ok&&fe.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=w):w=e[16];const N=w;let v;e[17]!==r?(v=Pe("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]=v):v=e[18];let D;e[19]!==y||e[20]!==g?(D=()=>{y(g)},e[19]=y,e[20]=g,e[21]=D):D=e[21];const F=d&&"animate-pulse";let k;e[22]!==F?(k=Pe("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",F),e[22]=F,e[23]=k):k=e[23];let E;e[24]!==g.label||e[25]!==o?(E=o("openInApp.actions.openInAria",{app:g.label}),e[24]=g.label,e[25]=o,e[26]=E):E=e[26];let O;e[27]!==g.fallbackIconDataUrl||e[28]!==g.iconDataUrl||e[29]!==g.label?(O=s.jsx(nd,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:g.fallbackIconDataUrl}),e[27]=g.fallbackIconDataUrl,e[28]=g.iconDataUrl,e[29]=g.label,e[30]=O):O=e[30];let M;e[31]!==k||e[32]!==E||e[33]!==O||e[34]!==D?(M=s.jsx("button",{type:"button",onClick:D,className:k,"aria-label":E,children:O}),e[31]=k,e[32]=E,e[33]=O,e[34]=D,e[35]=M):M=e[35];let B;e[36]===Symbol.for("react.memo_cache_sentinel")?(B=Pe("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[36]=B):B=e[36];let z;e[37]!==o?(z=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=z):z=e[38];let T;e[39]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=T):T=e[39];let I;e[40]!==z?(I=s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:B,"aria-label":z,children:T})}),e[40]=z,e[41]=I):I=e[41];let R;e[42]!==N?(R=()=>{N()},e[42]=N,e[43]=R):R=e[43];let L;e[44]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(A,{name:"file-copy",className:"h-4 w-4"}),e[44]=L):L=e[44];let P;e[45]!==o?(P=o("openInApp.actions.copyPath"),e[45]=o,e[46]=P):P=e[46];let G;e[47]!==P?(G=s.jsx("span",{className:"typography-ui-label text-foreground",children:P}),e[47]=P,e[48]=G):G=e[48];let X;e[49]!==R||e[50]!==G?(X=s.jsxs(is,{className:"flex items-center gap-2",onClick:R,children:[L,G]}),e[49]=R,e[50]=G,e[51]=X):X=e[51];let V;e[52]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(Ln,{}),e[52]=V):V=e[52];let te;if(e[53]!==c||e[54]!==j||e[55]!==g.id){let Q;e[57]!==j||e[58]!==g.id?(Q=Me=>{const xe=_a(Me);return s.jsxs(is,{className:"flex items-center gap-2",onClick:()=>{j(Me)},children:[s.jsx(nd,{label:Me.label,iconDataUrl:Me.iconDataUrl,fallbackIconDataUrl:xe.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Me.label}),g.id===Me.id?s.jsx(A,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},Me.id)},e[57]=j,e[58]=g.id,e[59]=Q):Q=e[59],te=c.map(Q),e[53]=c,e[54]=j,e[55]=g.id,e[56]=te}else te=e[56];let Z;e[60]!==l||e[61]!==h||e[62]!==o?(Z=l?s.jsxs(is,{className:"flex items-center gap-2",onClick:()=>{h(!0)},children:[s.jsx(A,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("openInApp.actions.refreshApps")})]}):null,e[60]=l,e[61]=h,e[62]=o,e[63]=Z):Z=e[63];let de;e[64]!==X||e[65]!==te||e[66]!==Z?(de=s.jsxs(Ys,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[X,V,te,Z]}),e[64]=X,e[65]=te,e[66]=Z,e[67]=de):de=e[67];let Fe;e[68]!==I||e[69]!==de?(Fe=s.jsxs(Qs,{children:[I,de]}),e[68]=I,e[69]=de,e[70]=Fe):Fe=e[70];let se;return e[71]!==M||e[72]!==Fe||e[73]!==v?(se=s.jsxs("div",{className:v,children:[M,Fe]}),e[71]=M,e[72]=Fe,e[73]=v,e[74]=se):se=e[74],se};function fb(t){return t.selectedAppId}function mb(t){return t.availableApps}function hb(t){return t.isCacheStale}function pb(t){return t.isScanning}function gb(t){return t.initialize}function xb(t){return t.loadInstalledApps}function bb(t){return t.selectApp}function yb(t){return t.id===kh}const wb=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],vb=["dev","start","preview","serve"];async function jb(t,e,n){if(!t)return null;const r=Nb(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const o=Cb(n);if(o){const i=await Ab(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await Sb(t)){const o=await kb(),i=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function Sb(t){const e=`${t}/index.html`,n=await aa(e,t);return typeof n=="string"&&n.trim().length>0}async function kb(){try{const t=await us("/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 Nb(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(vb.some(o=>n.includes(o)))return e}return null}function Cb(t){for(const{pattern:e}of wb)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Ab(t){const e=await aa(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),o=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(o.startsWith("bun@"))return"bun";if(o.startsWith("pnpm@"))return"pnpm";if(o.startsWith("yarn@"))return"yarn";if(o.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,o]of n){const i=await aa(`${t}/${r}`,t);if(typeof i=="string"&&i.trim().length>0)return o}return"npm"}async function aa(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await us(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=fa()?.files;if(n?.readFile)try{const r=await n.readFile(t,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await us(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Db(t){try{const e=await aa(`${t}/package.json`,t);if(e==null)return null;const r=JSON.parse(e).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const Pb=(t,e,n)=>new Promise(r=>{let o=!1,i=null,c=null;const l=d=>{o||(o=!0,c&&clearTimeout(c),i?.close(),r(d))};i=t.connect(e,{onEvent:d=>{(d.type==="exit"||d.type==="snapshot"&&d.status==="exited")&&l(!0)},onError:(d,u)=>{u&&l(!0)}}),o?i.close():c=setTimeout(()=>l(!1),n)}),Ib="\x1B",Rb=new RegExp(`${Ib}\\[[0-9;?]*[ -/]*[@-~]`,"g"),Mb=/https?:\/\/[^\s<>'"`]+/gi,Mn="__openchamber_auto_discover_preview__",Tb=15e3,Eb=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},Fb=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}},Ob=t=>{const n=t.replace(Rb,"").match(Mb);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const i of r)try{const c=new URL(i);c.port&&c.port.length>0&&o.push({raw:i,parsed:c})}catch{}if(o.length>0){const i=c=>{const{parsed:l}=c,d=l.hostname.toLowerCase(),u=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",h=l.pathname||"/",f=h.split("/").filter(Boolean).length,p=h==="/"||h==="",x=!!(l.search||l.hash);let b=0;return u&&(b+=50),p&&(b+=30),b-=Math.min(f*5,20),x&&(b-=10),b};return o.sort((c,l)=>i(l)-i(c)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Gf=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:i}=ft(),{currentTheme:c}=lo(),{terminal:l,runtime:d}=_n(),{isMobile:u}=Dr(),h=a.useMemo(()=>ur(),[]),f=Gc(ce=>ce.instances),p=Gc(ce=>ce.load),x=Ee(ce=>ce.terminalShell),b=Ee(ce=>ce.terminalLoginShells.includes(ce.terminalShell)),S=Ee(ce=>ce.setSettingsPage),g=Ee(ce=>ce.setSettingsDialogOpen),m=Ee(ce=>ce.setSettingsProjectsSelectedId),y=Ee(ce=>ce.openContextPreview),C=gs(ce=>ce.ensureDirectory),j=gs(ce=>ce.setTabLabel),w=gs(ce=>ce.setTabIconKey),N=gs(ce=>ce.setActiveTab),v=gs(ce=>ce.setConnecting),D=gs(ce=>ce.setTabSessionId),F=gs(ce=>ce.setTabPreviewUrl),k=gs(ce=>ce.projectActionRuns),E=gs(ce=>ce.setProjectActionRun),O=gs(ce=>ce.updateProjectActionRunStatus),M=gs(ce=>ce.removeProjectActionRun),[B,z]=a.useState([]),[T,I]=a.useState(null),[R,L]=a.useState(!1),P=a.useRef({}),G=a.useRef({}),X=a.useRef({}),V=a.useRef({}),te=a.useRef(new Set),Z=a.useRef(0),de=t?.id??null,Fe=t?.path??"",se=a.useMemo(()=>de?{id:de,path:Fe}:null,[de,Fe]);a.useEffect(()=>{h&&p().catch(()=>{})},[h,p]);const Q=a.useCallback(async ce=>{await io(ce)},[]),Me=a.useCallback(async()=>{if(!se)return;const ce=Z.current+1;Z.current=ce,L(!0);try{const he=await Tc(se);if(Z.current!==ce)return;const me=he.actions;z(me),I($=>$===Mn||$&&me.some(_=>_.id===$)?$:null)}catch{if(Z.current!==ce)return}finally{Z.current===ce&&L(!1)}},[se]),xe=a.useMemo(()=>cx(e||se?.path||""),[e,se?.path]),W=a.useMemo(()=>T?B.find(ce=>ce.id===T)??null:null,[B,T]),J=a.useMemo(()=>({id:Mn,name:i("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[i]),ne=!u,oe=a.useMemo(()=>ne?[J,...B]:B,[B,J,ne]);a.useEffect(()=>{Me()},[Me]),a.useEffect(()=>{if(typeof window>"u")return;const ce=he=>{const me=he.detail;de&&(me?.projectId&&me.projectId!==de||Me())};return window.addEventListener(qc,ce),()=>{window.removeEventListener(qc,ce)}},[Me,de]),a.useEffect(()=>{T&&(T===Mn&&ne||B.some(ce=>ce.id===T)||I(null))},[B,ne,T]),a.useEffect(()=>{const ce=()=>{const he=gs.getState(),me=he.sessions,$=he.projectActionRuns;for(const[_,ge]of Object.entries($)){const Re=me.get(ge.directory)?.tabs.find(yt=>yt.id===ge.tabId);if(!Re||Re.terminalSessionId!==ge.sessionId){M(_);continue}const Ke=G.current[_]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};G.current[_]=Ke;const nt=oe.find(yt=>yt.id===ge.actionId),ct=he.getBuffer(ge.directory,ge.tabId).chunks;if(!nt||ct.length===0)continue;const mt=ct.filter(yt=>Ke.lastSeenChunkId===null||yt.id>Ke.lastSeenChunkId);if(mt.length===0)continue;const gt=mt.map(yt=>yt.data).join(""),ht=`${Ke.tail}${gt}`,wt=!Ke.openedUrl&&nt.autoOpenUrl===!0?Ob(ht):null,bt=mt[mt.length-1]?.id??Ke.lastSeenChunkId;if(Ke.lastSeenChunkId=bt,Ke.tail=ht.slice(-512),wt)if(Ke.openedUrl=!0,Ke.openInPreview){const yt=$[_];yt&&(F(yt.directory,yt.tabId,wt,{locked:!1,autoOpened:!1}),yt.status==="waiting-for-preview"&&O(_,"running"),window.clearTimeout(V.current[_]),delete V.current[_],y(yt.directory,wt))}else Q(wt),fe.success(i("projectActions.toast.openedUrlFromOutput"));G.current[_]=Ke}for(const _ of Object.keys(G.current))$[_]||(delete G.current[_],window.clearTimeout(V.current[_]),delete V.current[_])};return ce(),gs.subscribe((he,me)=>{(he.sessions!==me.sessions||he.buffers!==me.buffers)&&ce()})},[oe,y,Q,k,M,F,i,O]);const ue=a.useCallback(async(ce,he={})=>{if(!xe)throw new Error(i("projectActions.error.noActiveDirectory"));const me=yr(xe,ce.id);C(xe);const $=gs.getState(),_=$.getDirectoryState(xe);let ge=P.current[me]||null;const Ie=ge?!!_?.tabs.some(nt=>nt.id===ge):!1;(!ge||!Ie)&&(ge=$.createTab(xe),P.current[me]=ge),j(xe,ge,`Action: ${ce.name}`),w(xe,ge,ce.icon||"play"),N(xe,ge),he.revealTerminal!==!1&&Ee.getState().openContextPanelTab(xe,{mode:"terminal"});const Ke=gs.getState().getDirectoryState(xe)?.tabs.find(nt=>nt.id===ge);return{key:me,tabId:ge,sessionId:Ke?.terminalSessionId??null}},[C,xe,N,w,j,i]),Ae=a.useCallback(async ce=>{if(d.isVSCode||!o&&u)return;if(!xe){fe.error(i("projectActions.error.noActiveDirectoryForAction"));return}const he=yr(xe,ce.id),me=k[he];if(!(me&&me.status==="running")&&!te.current.has(he)){te.current.add(he);try{const $=ce.id===Mn?await(async()=>{const[bt,yt]=await Promise.all([Tc({id:se?.id??"",path:xe}),Db(xe)]),Dt=await jb(xe,bt.actions,yt);if(!Dt)throw new Error(i("contextPanel.preview.noDevServer"));return{id:Mn,name:i("projectActions.actions.autoDiscover"),command:Dt.command,icon:"scan-2",autoOpenUrl:!0,openUrl:Dt.previewUrlHint||""}})():ce,_=$.autoOpenUrl===!0&&($.openUrl||"").trim().length>0,ge=!_&&ce.id!==Mn,{key:Ie,tabId:Re,sessionId:Ke}=await ue($,{revealTerminal:ge});let nt=Ke;if(!nt){v(xe,Re,!0);try{nt=(await l.createSession({cwd:xe,sessionId:Re,shell:x,loginShell:b,themeMode:c.metadata.variant==="light"?"light":"dark",terminalBackground:c.colors.surface.background,terminalForeground:c.colors.syntax.base.foreground})).sessionId,D(xe,Re,nt)}finally{v(xe,Re,!1)}}if(!nt)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));X.current[Ie]?.(),v(xe,Re,!0);const ct=l.connect(nt,{onEvent:bt=>{bt.type==="snapshot"&&(gs.getState().replaceBuffer(xe,Re,bt.data??"",bt.sequence??0),gs.getState().setConnecting(xe,Re,!1)),bt.type==="data"&&typeof bt.data=="string"&&bt.data.length>0&&gs.getState().appendToBuffer(xe,Re,bt.data,bt.sequence,bt.replayData),bt.type==="exit"&&(gs.getState().setTabLifecycle(xe,Re,"exited"),gs.getState().setConnecting(xe,Re,!1),gs.getState().removeProjectActionRun(Ie),delete G.current[Ie],X.current[Ie]?.(),delete X.current[Ie],window.clearTimeout(V.current[Ie]),delete V.current[Ie])},onError:(bt,yt)=>{gs.getState().setConnecting(xe,Re,!1),yt&&(gs.getState().setTabLifecycle(xe,Re,"exited"),gs.getState().setTabSessionId(xe,Re,null),gs.getState().removeProjectActionRun(Ie))}});X.current[Ie]=ct.close;const mt=$.autoOpenUrl===!0&&h&&($.desktopOpenSshForward||"").trim().length>0,gt=$.autoOpenUrl?Fb($.openUrl):null,ht=$.autoOpenUrl&&h?dx($.desktopOpenSshForward,f):null;E({key:Ie,directory:xe,actionId:$.id,tabId:Re,sessionId:nt,status:$.id===Mn&&!gt?"waiting-for-preview":"running"}),window.clearTimeout(V.current[Ie]),delete V.current[Ie],$.id===Mn&&!gt&&(V.current[Ie]=window.setTimeout(()=>{const bt=gs.getState(),yt=bt.projectActionRuns[Ie];bt.updateProjectActionRunStatus(Ie,"running"),yt&&(bt.setActiveTab(yt.directory,yt.tabId),Ee.getState().openContextPanelTab(yt.directory,{mode:"terminal"})),delete V.current[Ie]},Tb)),G.current[Ie]={lastSeenChunkId:null,openedUrl:!!ht||!!gt||_,tail:"",openInPreview:$.id===Mn};const wt=Eb($.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
+
`));await l.sendInput(nt,`${wt}\r`),ht?(F(xe,Re,null,{locked:!0}),Q(ht),fe.success(i("projectActions.toast.openedForwardedUrl"))):gt?(F(xe,Re,gt,{locked:!0,autoOpened:!0}),y(xe,gt),fe.success(i("projectActions.toast.openedActionUrl"))):_?(F(xe,Re,null,{locked:!0}),fe.error(i("projectActions.error.invalidCustomUrlFormat"))):mt?(F(xe,Re,null,{locked:!0}),fe.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):F(xe,Re,null,{locked:!1,autoOpened:!1})}catch($){M(he),delete G.current[he],X.current[he]?.(),delete X.current[he],window.clearTimeout(V.current[he]),delete V.current[he],fe.error($ instanceof Error?$.message:i("projectActions.error.failedToRunAction"))}finally{te.current.delete(he)}}},[c.colors.surface.background,c.colors.syntax.base.foreground,c.metadata.variant,f,ue,o,u,h,xe,b,x,Q,y,k,d.isVSCode,M,v,E,F,D,se?.id,i,l]),we=a.useCallback(async ce=>{const he=yr(xe,ce.id),me=k[he];if(!me)return;O(he,"stopping");const $=Pb(l,me.sessionId,1e3);try{await l.sendInput(me.sessionId,"")}catch{}const _=await $;if(gs.getState().getDirectoryState(me.directory)?.tabs.find(Re=>Re.id===me.tabId)?.terminalSessionId===me.sessionId&&!_){if(typeof l.forceKill=="function")try{await l.forceKill({sessionId:me.sessionId})}catch{}else try{await l.close(me.sessionId)}catch{}D(me.directory,me.tabId,null)}M(he),delete G.current[he],X.current[he]?.(),delete X.current[he],window.clearTimeout(V.current[he]),delete V.current[he]},[xe,k,M,D,l,O]),Se=a.useCallback(()=>{const ce=W??oe[0];if(!ce)return;const he=yr(xe,ce.id),me=k[he];if(me?.status!=="stopping"){if(me){we(ce);return}Ae(ce)}},[oe,xe,Ae,k,W,we]),Le=a.useCallback((ce,he=!1)=>{if(I(ce.id),!he){Ae(ce);return}const me=yr(xe,ce.id),$=k[me];if($?.status!=="stopping"){if($){we(ce);return}Ae(ce)}},[xe,Ae,k,we]),Ue=a.useCallback(()=>{se?.id&&(m(se.id),S("projects"),g(!0))},[g,S,m,se?.id]),be=W??oe[0]??null,q=be?k[yr(xe,be.id)]:null,Ne=gs(ce=>q?ce.sessions.get(q.directory)?.tabs.find(he=>he.id===q.tabId)?.previewUrl??null:null);if(d.isVSCode||!o&&u||!se||!xe)return null;const je=W??oe[0]??null;if(!je)return null;const ve=je.icon||"play",ie=je.id===Mn?"scan-2":$a[ve]||"play",ee=yr(xe,je.id),ke=k[ee],ae=ke?.status==="stopping",U=ke?.status==="waiting-for-preview",le=!!(ke&&Ne),_e=()=>{!ke||!Ne||y(ke.directory,Ne)},De=je.id===Mn;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:R||ae,className:Pe("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:Se,"aria-label":ke?i("projectActions.actions.stopNamedAria",{name:je.name}):i("projectActions.actions.runNamedAria",{name:je.name}),children:ae||U?s.jsx(A,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):ke?s.jsx(A,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(A,{name:ie,className:"h-5 w-5"})})}),De?s.jsx(Nt,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),le?s.jsxs(St,{children:[s.jsx(kt,{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":i("projectActions.actions.openPreview"),onClick:_e,children:s.jsx(A,{name:"global",className:"h-4 w-4"})})}),s.jsx(Nt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Qs,{children:[s.jsx(qs,{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":i("projectActions.actions.chooseActionAria"),children:s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Ys,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(is,{className:"flex items-center gap-2",onClick:Ue,children:[s.jsx(A,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Ln,{}),oe.map(ce=>{const he=ce.icon||"play",me=ce.id===Mn?"scan-2":$a[he]||"play",$=yr(xe,ce.id),_=k[$],ge=!!_,Ie=_?.status==="stopping";return s.jsxs(is,{className:"flex items-center gap-2",onClick:()=>{Le(ce,!0)},children:[s.jsx(A,{name:me,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ce.name}),Ie||_?.status==="waiting-for-preview"?s.jsx(A,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ge?s.jsx(A,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ce.id)})]})]})]}):s.jsxs("div",{className:Pe("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(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Se,disabled:R||ae,className:Pe("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":ke?i("projectActions.actions.stopNamedAria",{name:je.name}):i("projectActions.actions.runNamedAria",{name:je.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ae||U?s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):ke?s.jsx(A,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(A,{name:ie,className:"h-4 w-4"})})})}),De?s.jsx(Nt,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),le?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:_e,className:Pe(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":i("projectActions.actions.openPreview"),children:s.jsx(A,{name:"global",className:"h-4 w-4"})})}),s.jsx(Nt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Qs,{children:[s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe(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":i("projectActions.actions.chooseActionAria"),children:s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Ys,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(is,{className:"flex items-center gap-2",onClick:Ue,children:[s.jsx(A,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Ln,{}),oe.map(ce=>{const he=ce.icon||"play",me=ce.id===Mn?"scan-2":$a[he]||"play",$=yr(xe,ce.id),_=k[$],ge=!!_,Ie=_?.status==="stopping";return s.jsxs(is,{className:"flex items-center gap-2",onClick:()=>{Le(ce,!0)},children:[s.jsx(A,{name:me,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ce.name}),Ie||_?.status==="waiting-for-preview"?s.jsx(A,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ge?s.jsx(A,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ce.id)})]})]})]})};function Lb(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(ai(),{month:"short"}),r=e.getDate(),o=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),c=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${o}, ${i}:${c}`}function Bb(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function $b(t){const e=t.info.role==="user"?"User":"Assistant",n=Lb(t.info.time?.created),r=Bb(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
|
|
4
|
+
|
|
5
|
+
*${o}*`:`**${e}**`}function _b(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function qf(t){const e=$b(t),n=_b(t.parts).trim();return n?`${e}
|
|
6
|
+
|
|
7
|
+
${n}`:""}function Yf(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",o=`${n} Sub-agent: ${t.title}${r}
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`,i=t.records.map(qf).filter(Boolean).join(`
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
`),c=[o+i];for(const l of t.children)c.push(Yf(l,e+1));return c.join(`
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
`)}function Qf(t,e,n){const r=e?.trim()||"Session",o=new Date().toISOString().split("T")[0],i=`# ${r}
|
|
20
|
+
|
|
21
|
+
*Exported on ${o}*
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
`,c=t.map(qf).filter(Boolean).join(`
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
`);let l=i+c;if(n&&n.length>0){const d=n.map(u=>Yf(u,1)).join(`
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
`);l+=`
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
`+d}return l}function Xf(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}async function Jf(t,e){const n=await Ch(e,t);if(n)return n;if(!nr())return null;try{const r=await fa()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const o=typeof r.path=="string"?r.path.trim():"";return o.length>0?o:null}catch{return null}}async function zb(t){const e=fa()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Ah(t)?!0:Ku(t)}function Vb(){return Zu()}function Zf(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",o=new Date().toISOString().split("T")[0];return`${r}-${o}.md`}const nc=zo(()=>({pendingSessionIds:new Set})),em=t=>{const e=ot.c(2);let n;return e[0]!==t?(n=r=>r.pendingSessionIds.has(t),e[0]=t,e[1]=n):n=e[1],nc(n)},rd=(t,e)=>{nc.setState(n=>{if(n.pendingSessionIds.has(t)===e)return n;const r=new Set(n.pendingSessionIds);return e?r.add(t):r.delete(t),{pendingSessionIds:r}})},Wb=async(t,e)=>{try{const d=(await Yh(t,{mode:"light"})).current?.trim();if(d)return d}catch{}const n=_t(t),r=_t(e)??e,o=Je.getState().availableWorktreesByProject,c=(o.get(r)??o.get(e)??[]).find(l=>_t(l.path)===n)?.branch?.trim();if(c)return c;throw new Error("Unable to determine the current branch")},od=(t,e)=>{const n=qh(e);if(!n)throw new Error("Session status is unavailable");const r=n.session_status;if(t.some(i=>{const c=r[i.id]?.type;return c==="busy"||c==="retry"}))throw new Error("Session is not idle")},Ub=async(t,e,n,r,o)=>{const i=[];for(const c of[...t].reverse())try{await ef(c,r,n,c.id===e),Je.getState().setWorktreeMetadata(c.id,o.get(c.id)??null)}catch(l){i.push(l)}return i},Hb=async(t,e,n)=>{try{await tf(t,e,{deleteLocalBranch:!0})}catch{const r=n instanceof Error?n.message:String(n);throw new Error(`Session move failed and the new worktree could not be removed: ${r}`)}throw n},Kb=async t=>{if(nc.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");rd(t.root.id,!0);try{const e=Uh(t.sourceDirectory);if(!e)throw new Error("Unable to find the project for this session");const n=[t.root,...t.descendants],r=new Map(n.map(l=>[l.id,Je.getState().getWorktreeMetadata(l.id)]));od(n,t.sourceDirectory);const o=await Wb(t.sourceDirectory,e.path),i=await Hh(e,{startRef:o}),c=[];try{await Kh(i.path),od(n,t.sourceDirectory);for(const[l,d]of n.entries())await ef(d,t.sourceDirectory,i.path,l===0),c.push(d),Je.getState().setWorktreeMetadata(d.id,Gh(i))}catch(l){if((await Ub(c,t.root.id,t.sourceDirectory,i.path,r)).length>0)throw new Error(`Session move partially failed and could not be fully rolled back: ${l instanceof Error?l.message:String(l)}`);return Hb(e,i,l)}try{await Bi([t.sourceDirectory,i.path])}catch(l){console.warn("[session-worktree-move] Failed to refresh moved sessions",l)}return i.path}finally{rd(t.root.id,!1)}},tm=t=>{Kb(t).then(()=>fe.success(t.successMessage)).catch(e=>fe.error(t.failureMessage,{description:e instanceof Error?e.message:String(e)}))},Pa="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",Gb="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",qb=a.memo(function(e){const n=ot.c(17),{visible:r,title:o,ariaLabel:i,onClick:c,className:l,Icon:d,iconClassName:u,pressed:h}=e,f=r===void 0?!0:r,p=h===void 0?!1:h;if(!f)return null;const x=l??Pa,b=p&&"bg-interactive-selection text-interactive-selection-foreground";let S;n[0]!==x||n[1]!==b?(S=Pe(x,b),n[0]=x,n[1]=b,n[2]=S):S=n[2];const g=u??"h-[18px] w-[18px]";let m;n[3]!==d||n[4]!==g?(m=s.jsx(A,{name:d,className:g}),n[3]=d,n[4]=g,n[5]=m):m=n[5];let y;n[6]!==i||n[7]!==c||n[8]!==p||n[9]!==S||n[10]!==m?(y=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":i,"aria-pressed":p,className:S,children:m})}),n[6]=i,n[7]=c,n[8]=p,n[9]=S,n[10]=m,n[11]=y):y=n[11];let C;n[12]!==o?(C=s.jsx(Nt,{children:s.jsx("p",{children:o})}),n[12]=o,n[13]=C):C=n[13];let j;return n[14]!==y||n[15]!==C?(j=s.jsxs(St,{children:[y,C]}),n[14]=y,n[15]=C,n[16]=j):j=n[16],j}),Yb=a.memo(function(e){const n=ot.c(42),{isMobile:r,githubAuthStatus:o,githubAccounts:i,githubAvatarUrl:c,githubLogin:l,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:u}=e,{t:h}=ft();if(!o?.connected||r)return null;if(i.length>1){let b;n[0]===Symbol.for("react.memo_cache_sentinel")?(b=Pe(Pa,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=b):b=n[0];let S;n[1]!==l||n[2]!==h?(S=l?h("header.github.connectedWithLogin",{login:l}):h("header.github.connected"),n[1]=l,n[2]=h,n[3]=S):S=n[3];let g;n[4]!==c||n[5]!==l||n[6]!==h?(g=c?s.jsx("img",{src:c,alt:l?h("header.github.avatarWithLogin",{login:l}):h("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=c,n[5]=l,n[6]=h,n[7]=g):g=n[7];let m;n[8]!==d||n[9]!==S||n[10]!==g?(m=s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:b,title:S,disabled:d,children:g})}),n[8]=d,n[9]=S,n[10]=g,n[11]=m):m=n[11];let y;n[12]!==h?(y=h("header.github.accountsTitle"),n[12]=h,n[13]=y):y=n[13];let C;n[14]!==y?(C=s.jsx(Co,{className:"typography-ui-header font-semibold text-foreground",children:y}),n[14]=y,n[15]=C):C=n[15];let j;n[16]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Ln,{}),n[16]=j):j=n[16];let w;if(n[17]!==i||n[18]!==u||n[19]!==d||n[20]!==h){let D;n[22]!==u||n[23]!==d||n[24]!==h?(D=F=>{const k=F.user,E=!!F.current,O=F.source==="gh-cli"?h("header.github.accountSource.cli"):h("header.github.accountSource.oauth");return s.jsxs(is,{className:"gap-2",disabled:d,onSelect:()=>{E||u(F.id)},children:[k?.avatarUrl?s.jsx("img",{src:k.avatarUrl,alt:k.login?h("header.github.avatarWithLogin",{login:k.login}):h("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(A,{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:k?.name?.trim()||k?.login||"GitHub"}),k?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:k.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:O})]}):null]}),E?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]},F.id)},n[22]=u,n[23]=d,n[24]=h,n[25]=D):D=n[25],w=i.map(D),n[17]=i,n[18]=u,n[19]=d,n[20]=h,n[21]=w}else w=n[21];let N;n[26]!==C||n[27]!==w?(N=s.jsxs(Ys,{align:"end",className:"w-64",children:[C,j,w]}),n[26]=C,n[27]=w,n[28]=N):N=n[28];let v;return n[29]!==m||n[30]!==N?(v=s.jsxs(Qs,{children:[m,N]}),n[29]=m,n[30]=N,n[31]=v):v=n[31],v}let f;n[32]!==l||n[33]!==h?(f=l?h("header.github.connectedWithLogin",{login:l}):h("header.github.connected"),n[32]=l,n[33]=h,n[34]=f):f=n[34];let p;n[35]!==c||n[36]!==l||n[37]!==h?(p=c?s.jsx("img",{src:c,alt:l?h("header.github.avatarWithLogin",{login:l}):h("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(A,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=c,n[36]=l,n[37]=h,n[38]=p):p=n[38];let x;return n[39]!==f||n[40]!==p?(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:f,children:p}),n[39]=f,n[40]=p,n[41]=x):x=n[41],x}),Qb=a.memo(function(e){const n=ot.c(84),{isDesktopApp:r,currentInstanceLabel:o,compactCurrentInstanceLabel:i,currentInstanceIsLocal:c,isDesktopServicesOpen:l,setIsDesktopServicesOpen:d,refreshCurrentInstanceLabel:u,desktopServicesTab:h,setDesktopServicesTab:f,quotaResultsLength:p,fetchAllQuotas:x,servicesTabItems:b,quotaLastUpdated:S,quotaDisplayMode:g,quotaDisplayTabItems:m,handleDisplayModeChange:y,handleUsageRefresh:C,isQuotaLoading:j,isUsageRefreshSpinning:w,hasRateLimits:N,rateLimitGroups:v,expandedFamilies:D,toggleFamilyExpanded:F,shortcutLabel:k,showDevShutdown:E,isDevShutdownInFlight:O,onDevShutdown:M,remoteUpdateInfo:B,remoteUpdateChecking:z,remoteUpdateError:T,onOpenRemoteUpdate:I,showPredValues:R,timeFormatPreference:L}=e,{t:P}=ft();let G;n[0]!==h||n[1]!==x||n[2]!==p||n[3]!==u||n[4]!==d?(G=Se=>{d(Se),Se&&(u(),h==="usage"&&p===0&&x())},n[0]=h,n[1]=x,n[2]=p,n[3]=u,n[4]=d,n[5]=G):G=n[5];let X;n[6]!==o||n[7]!==r||n[8]!==P?(X=r?P("header.services.openWithCurrent",{current:o}):P("header.services.open"),n[6]=o,n[7]=r,n[8]=P,n[9]=X):X=n[9];const V=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let te;n[10]!==V?(te=Pe(Pa,V),n[10]=V,n[11]=te):te=n[11];let Z;n[12]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(A,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=Z):Z=n[12];let de;n[13]!==i||n[14]!==r?(de=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=de):de=n[15];let Fe;n[16]!==X||n[17]!==te||n[18]!==de?(Fe=s.jsx(kt,{asChild:!0,children:s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":X,className:te,children:[Z,de]})})}),n[16]=X,n[17]=te,n[18]=de,n[19]=Fe):Fe=n[19];let se;n[20]!==o||n[21]!==r||n[22]!==k||n[23]!==P?(se=r?P("header.services.tooltip.currentInstanceWithShortcuts",{current:o,toggle:k("toggle_services_menu"),nextTab:k("cycle_services_tab")}):P("header.services.tooltip.servicesWithShortcuts",{toggle:k("toggle_services_menu"),nextTab:k("cycle_services_tab")}),n[20]=o,n[21]=r,n[22]=k,n[23]=P,n[24]=se):se=n[24];let Q;n[25]!==se?(Q=s.jsx(Nt,{children:s.jsx("p",{children:se})}),n[25]=se,n[26]=Q):Q=n[26];let Me;n[27]!==Fe||n[28]!==Q?(Me=s.jsxs(St,{children:[Fe,Q]}),n[27]=Fe,n[28]=Q,n[29]=Me):Me=n[29];let xe;n[30]!==x||n[31]!==p||n[32]!==f?(xe=Se=>{const Le=Se;f(Le),Le==="usage"&&p===0&&x()},n[30]=x,n[31]=p,n[32]=f,n[33]=xe):xe=n[33];let W;n[34]!==h||n[35]!==b||n[36]!==xe?(W=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(fi,{items:b,activeId:h,onSelect:xe,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=h,n[35]=b,n[36]=xe,n[37]=W):W=n[37];let J;n[38]!==c||n[39]!==h||n[40]!==r||n[41]!==l||n[42]!==I||n[43]!==z||n[44]!==T||n[45]!==B||n[46]!==d||n[47]!==P?(J=r&&h==="instance"?s.jsxs("div",{children:[c?null:s.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:P("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:B?.available?P("header.services.remoteUpdate.available",{version:B.version||""}):z?P("header.services.remoteUpdate.checking"):T||P("header.services.remoteUpdate.upToDate")})]}),B?.available?s.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:I,children:P("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(Qh,{embedded:!0,open:l&&h==="instance",onOpenChange:Zb,onHostSwitched:()=>d(!1)})]}):null,n[38]=c,n[39]=h,n[40]=r,n[41]=l,n[42]=I,n[43]=z,n[44]=T,n[45]=B,n[46]=d,n[47]=P,n[48]=J):J=n[48];let ne;n[49]!==h||n[50]!==l?(ne=h==="mcp"?s.jsx(Af,{active:l&&h==="mcp"}):null,n[49]=h,n[50]=l,n[51]=ne):ne=n[51];let oe;n[52]!==h||n[53]!==D||n[54]!==y||n[55]!==C||n[56]!==N||n[57]!==j||n[58]!==w||n[59]!==g||n[60]!==m||n[61]!==S||n[62]!==v||n[63]!==R||n[64]!==P||n[65]!==L||n[66]!==F?(oe=h==="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:P("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:sm(S,L)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(fi,{items:m,activeId:g,onSelect:Se=>{y(Se)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:Pe("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:C,disabled:j||w,"aria-label":P("header.services.refreshRateLimitsAria"),children:s.jsx(A,{name:"refresh",className:Pe("h-4 w-4",w&&"animate-spin")})})]})]}),N?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:P("header.services.noRateLimits")})}),s.jsx("div",{className:"space-y-2 px-3 py-2.5",children:v.map(Se=>{const Le=D[Se.providerId]??[];return s.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[s.jsx(li,{providerId:Se.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Se.providerName})]}),Se.entries.length===0&&(!Se.modelFamilies||Se.modelFamilies.length===0)?s.jsx("div",{children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Se.error??P("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3",children:[Se.entries.map(Ue=>{const[be,q]=Ue,Ne=g==="remaining"?q.remainingPercent:q.usedPercent,je=Ji(q.usedPercent,q.resetAt,q.windowSeconds,be),ve=je?.dailyAllocationPercent!=null?g==="remaining"?100-_r(je.elapsedRatio):_r(je.elapsedRatio):null,ie=ci(q.valueLabel,Ne),ee=sf(q.resetAt,q.resetAfterFormatted??q.resetAtFormatted,L);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:Bl(be)}),ee?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:ee}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ie==="-"?"":ie})]}),s.jsx(sa,{percent:Ne,tonePercent:q.usedPercent,className:"h-1.5",expectedMarkerPercent:ve}),je&&R?s.jsx(na,{paceInfo:je,compact:!0}):null]},`${Se.providerId}-${be}`)}),Se.modelFamilies&&Se.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:Se.modelFamilies.map(Ue=>{const be=Ue.familyId??"other",q=Le.includes(be);return s.jsxs(Fo,{open:q,onOpenChange:()=>F(Se.providerId,be),children:[s.jsxs(bi,{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:Ue.familyLabel}),q?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(Oo,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Ue.models.map(Ne=>{const[je,ve]=Ne,ie=g==="remaining"?ve.remainingPercent:ve.usedPercent,ee=Ji(ve.usedPercent,ve.resetAt,ve.windowSeconds),ke=ee?.dailyAllocationPercent!=null?g==="remaining"?100-_r(ee.elapsedRatio):_r(ee.elapsedRatio):null,ae=ci(ve.valueLabel,ie);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:Cf(je)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ae==="-"?"":ae})]}),s.jsx(sa,{percent:ie,tonePercent:ve.usedPercent,className:"h-1.5",expectedMarkerPercent:ke}),ee&&R?s.jsx(na,{paceInfo:ee,compact:!0}):null]},`${Se.providerId}-${je}`)})})})]},be)})}):null]})]},Se.providerId)})})]}):null,n[52]=h,n[53]=D,n[54]=y,n[55]=C,n[56]=N,n[57]=j,n[58]=w,n[59]=g,n[60]=m,n[61]=S,n[62]=v,n[63]=R,n[64]=P,n[65]=L,n[66]=F,n[67]=oe):oe=n[67];let ue;n[68]!==O||n[69]!==M||n[70]!==E||n[71]!==P?(ue=E?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(is,{disabled:O,onSelect:()=>{M()},children:P("header.services.shutdownDev")})})]}):null,n[68]=O,n[69]=M,n[70]=E,n[71]=P,n[72]=ue):ue=n[72];let Ae;n[73]!==W||n[74]!==J||n[75]!==ne||n[76]!==oe||n[77]!==ue?(Ae=s.jsxs(Ys,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[W,J,ne,oe,ue]}),n[73]=W,n[74]=J,n[75]=ne,n[76]=oe,n[77]=ue,n[78]=Ae):Ae=n[78];let we;return n[79]!==l||n[80]!==G||n[81]!==Me||n[82]!==Ae?(we=s.jsxs(Qs,{open:l,onOpenChange:G,children:[Me,Ae]}),n[79]=l,n[80]=G,n[81]=Me,n[82]=Ae,n[83]=we):we=n[83],we}),Xb=(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??""),Jb=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),i=`${r} ${o}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},sm=(t,e)=>{if(!t)return"-";try{return nf(t,e,{fallback:"-"})}catch{return"-"}},Xn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},za=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,id=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{Zn("ui.header.render");const{t:o}=ft(),i=Ee(H=>H.setSessionSwitcherOpen),c=Ee(H=>H.toggleSidebar),l=Ee(H=>H.isSidebarOpen),d=Ee(H=>H.openContextOverview),u=Ee(H=>H.openContextPlan),h=Ee(H=>H.closeContextPanel),f=Ee(H=>H.activeMainTab),p=Ee(H=>H.setActiveMainTab),x=Ee(H=>H.shortcutOverrides),b=Ee(H=>H.timeFormatPreference),S=rs(H=>H.getCurrentModel),g=_n(),[m,y]=a.useState(!1),C=Je(H=>H.getContextUsage),j=Je(H=>!!H.newSessionDraft?.open),w=Je(H=>H.currentSessionId),N=Xh(w??""),v=rf(w??""),D=em(w??""),F=gn(er(a.useCallback(H=>{if(!w)return null;const Ge=H.activeSessions.find(vt=>vt.id===w);if(!Ge)return null;const rt=Ge;return{title:Ge.title??null,directory:rt.directory??null,created:Ge.time?.created??null,slug:rt.slug??null,shareUrl:Ge.share?.url??null,parentId:Ge.parentID??null}},[w]))),k=ds(er(H=>{if(!H.activeProjectId)return null;const Ge=H.projects.find(rt=>rt.id===H.activeProjectId);return Ge?{id:Ge.id,path:Ge.path,label:Ge.label}:null})),E=a.useMemo(()=>{if(!k)return null;const H=k.label?.trim();if(H)return H;const Ge=k.path.split(/[\\/]/).filter(Boolean);return Ge[Ge.length-1]??null},[k]),O=Ws(H=>H.results),M=Ws(H=>H.fetchAllQuotas),B=Ws(H=>H.isLoading),z=Ws(H=>H.lastUpdated),T=Ws(H=>H.displayMode),I=Ws(H=>H.showPredValues),R=Ws(H=>H.dropdownProviderIds),L=Ws(H=>H.loadSettings),P=Ws(H=>H.setDisplayMode),{isMobile:G}=Dr(),X=Ar(H=>H.status),V=Ar(H=>H.setStatus),te=a.useRef(null),[Z,de]=a.useState(()=>typeof window>"u"?!1:ur()),Fe=a.useMemo(()=>ma(),[]),se=of(),[Q,Me]=a.useState(!1),xe=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:W,side:J}=_f(),ne=a.useMemo(()=>{if(typeof window>"u")return null;const H=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof H=="number"&&Number.isFinite(H)&&H>0)return H;if(typeof navigator>"u")return null;const Ge=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Ge)return null;const rt=Number.parseInt(Ge[1],10),vt=Number.parseInt(Ge[2],10);return Number.isNaN(rt)?null:rt===10?vt:rt},[]);$e.useEffect(()=>{typeof window>"u"||de(ur())},[]);const oe=S(),ue=oe&&typeof oe.limit=="object"&&oe.limit!==null?oe.limit:null,Ae=ue&&typeof ue.context=="number"?ue.context:0,we=ue&&typeof ue.output=="number"?ue.output:0,Se=C(Ae,we),[Le,Ue]=a.useState(null),be=!w||N;$e.useEffect(()=>{if(!w){Ue(H=>H===null?H:null);return}if(Se&&Se.totalTokens>0){Ue(H=>Xb(H,Se)?H:Se);return}be&&Ue(H=>H===null?H:null)},[Se,w,be]);const q=Ee(H=>H.isSessionSwitcherOpen),Ne=X?.connected?X.user?.avatarUrl??null:null,je=X?.connected?X.user?.login??null:null,ve=X?.accounts??[],[ie,ee]=a.useState(!1),[ke,ae]=a.useState(!1),[U,le]=a.useState(!1),[_e,De]=a.useState(!1),[ce,he]=a.useState("Local"),[me,$]=a.useState(!0),[_,ge]=a.useState(!1),[Ie,Re]=a.useState(null),[Ke,nt]=a.useState(!1),[ct,mt]=a.useState(null),gt=a.useMemo(()=>Jb(ce),[ce]),[ht,wt]=a.useState(Z?"instance":"usage"),[bt,yt]=a.useState("usage");$e.useEffect(()=>{!Z&&ht==="instance"&&wt("usage")},[ht,Z]);const Dt=a.useMemo(()=>nr(),[]),Kt=!Dt&&f==="chat"&&!!Le&&Le.totalTokens>0,Ut=Le&&Le.contextLimit>0?Math.min(999,Le.totalTokens/Le.contextLimit*100):0,Lt=a.useCallback(async()=>{if(!(typeof window>"u"||!Z))try{if(ua()){he("Local"),$(!0);return}$(!1);const H=await Gu(),Ge=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,rt=Nr();if(rt&&Qi(rt,Ge)){he("Local"),$(!0);return}const vt=H.hosts.find(es=>rt?Qi(rt,qu(es)):!1);if(vt?.label?.trim()){he(Yu(vt.label.trim()));return}he("Instance")}catch{he("Local"),$(!0)}},[Z]);$e.useEffect(()=>{Lt()},[Lt]);const Bt=a.useCallback(async()=>{if(me){Re(null),mt(null);return}nt(!0),mt(null);try{const H=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),Ge=await us(`/api/openchamber/update-check?${H.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!Ge.ok)throw new Error(`Server responded with ${Ge.status}`);const rt=await Ge.json();Re({available:rt.available??!1,version:rt.version,currentVersion:rt.currentVersion??"unknown",body:rt.body,nextSuggestedCheckInSec:typeof rt.nextSuggestedCheckInSec=="number"?rt.nextSuggestedCheckInSec:void 0,packageManager:rt.packageManager,updateCommand:rt.updateCommand})}catch(H){Re(null),mt(H instanceof Error?H.message:o("header.services.remoteUpdate.error"))}finally{nt(!1)}},[me,o]);a.useEffect(()=>{Re(null),mt(null),ge(!1)},[me,ce]),a.useEffect(()=>{if(!Z||me)return;const H=3e3,Ge=3600*1e3;let rt=!1,vt=null;const es=ns=>{vt=window.setTimeout(()=>{if(rt||typeof document<"u"&&document.visibilityState!=="visible"){es(Ge);return}Bt().finally(()=>{rt||es(Ge)})},ns)};return es(H),()=>{rt=!0,vt!==null&&window.clearTimeout(vt)}},[Bt,me,ce,Z]);const et=a.useCallback(()=>{if(Ie?.available){ge(!0);return}Bt()},[Bt,Ie?.available]);ux();const Ht=Ws(H=>H.selectedModels),It=Ws(H=>H.expandedFamilies),We=Ws(H=>H.toggleFamilyExpanded),pt=a.useMemo(()=>{const H=[];for(const Ge of Df){if(!R.includes(Ge.id))continue;const rt=O.find(bs=>bs.providerId===Ge.id),vt=rt?.usage?.windows??{},es=rt?.usage?.models,ns=Object.entries(vt),os={providerId:Ge.id,providerName:Ge.name,entries:ns,error:rt&&!rt.ok&&rt.configured?rt.error:void 0};if(es&&Object.keys(es).length>0){const bs=Ht[Ge.id]??[],Ts=bs.length>0,Gs=fx(es,Ge.id),Es=mx(Ge.id),Mr=hx(Es);os.modelFamilies=[];for(const jn of Mr){const Rn=Gs.get(jn.id)??[];if(Rn.length===0)continue;const lr=Ts?Rn.filter(gr=>bs.includes(gr)):Rn;if(lr.length===0)continue;const Un=[];for(const gr of lr){const qr=es[gr];if(qr?.windows){const xr=Object.entries(qr.windows);xr.length>0&&Un.push([gr,xr[0][1]])}}Un.length>0&&os.modelFamilies.push({familyId:jn.id,familyLabel:jn.label,models:Un})}const Gr=Gs.get(null)??[],hn=Ts?Gr.filter(jn=>bs.includes(jn)):Gr;if(hn.length>0){const jn=[];for(const Rn of hn){const lr=es[Rn];if(lr?.windows){const Un=Object.entries(lr.windows);Un.length>0&&jn.push([Rn,Un[0][1]])}}jn.length>0&&os.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:jn})}}(ns.length>0||os.modelFamilies&&os.modelFamilies.length>0||os.error)&&H.push(os)}return H},[R,O,Ht,o]),Mt=pt.length>0;a.useEffect(()=>{L()},[L]);const Et=a.useCallback(async H=>{P(H);try{await Ol({usageDisplayMode:H})}catch(Ge){console.warn("Failed to update usage display mode:",Ge)}},[P]),tt=a.useCallback(()=>{if(_e)return;De(!0);const H=new Promise(Ge=>setTimeout(Ge,500));Promise.all([M(),H]).finally(()=>{De(!1)})},[M,_e]),pe=w?F??null:null,Oe=a.useRef(null),[Te,it]=a.useState(0);a.useEffect(()=>{if(!w){Oe.current&&(Oe.current=null,it(vt=>vt+1));return}if(pe){Oe.current={sessionId:w,session:pe,expiresAt:Date.now()+2e3};return}const H=Oe.current;if(!H||H.sessionId!==w)return;const Ge=H.expiresAt-Date.now();if(Ge<=0){Oe.current=null,it(vt=>vt+1);return}const rt=window.setTimeout(()=>{Oe.current?.sessionId===w&&(Oe.current=null),it(vt=>vt+1)},Ge);return()=>{window.clearTimeout(rt)}},[w,pe]);const ut=(()=>{if(pe)return pe;if(!w)return null;const H=Oe.current;return H&&H.sessionId===w&&H.expiresAt>Date.now()?H.session:null})(),Gt=Je(H=>w?H.worktreeMetadata.get(w)?.path??"":""),Ft=Je(H=>w?H.worktreeMetadata.get(w)?.branch?.trim()??null:null),ze=$l(H=>w?H.getAttachment(w):void 0),Qe=a.useMemo(()=>ze?Jh(ze,{pending:o("gitView.empty.worktreeSetupInProgress")}):null,[o,ze]),st=a.useMemo(()=>ze?ze.legacy?"legacy":ze.degraded?"degraded":ze.worktreeStatus==="pending"?"pending":ze.worktreeStatus==="missing"?"missing":ze.worktreeStatus==="invalid"?"invalid":ze.attentionReason?"attention":null:null,[ze]),at=a.useMemo(()=>Xn(Gt||""),[Gt]),Ze=a.useMemo(()=>{const H=typeof ut?.directory=="string"?ut.directory:"";return Xn(H||"")},[ut?.directory]),At=Je(H=>H.newSessionDraft?.open?Xn(H.newSessionDraft.bootstrapPendingDirectory??H.newSessionDraft.directoryOverride??""):""),Rt=a.useMemo(()=>at||Ze||At,[At,Ze,at]),Zt=Ee(a.useCallback(H=>{const Ge=Xn(Rt||"");return Ge?za(H.contextPanelByDirectory[Ge]):null},[Rt])),fs=Je(H=>{const Ge=Xn(at||Ze||"");if(!Ge)return null;for(const rt of H.availableWorktreesByProject.values()){const es=rt.find(ns=>Xn(ns.path)===Ge)?.branch?.trim();if(es)return es}return null}),Ot=Zh(Rt||null)||Ft||fs,$t=a.useMemo(()=>{if(!w)return E??"OpenChamber";const H=ut?.title?.trim();return H&&H.length>0?H:"Untitled Session"},[E,ut?.title,w]),Pt=_l(Rt||void 0,{bootstrap:!1}),ms=pa(),Ks=Je(H=>H.updateSessionTitle),Yt=Je(H=>H.shareSession),ws=Je(H=>H.unshareSession),Xs=Je(H=>H.archiveSessions),An=Je(H=>H.deleteSessions),[ts,Js]=a.useState(!1),[or,zn]=a.useState(!1),dn=a.useRef(!1),[un,wn]=a.useState(""),[Bs,Fs]=a.useState(null),fn=a.useRef(null);a.useEffect(()=>{dn.current=!1,zn(!1),Js(!1),wn(""),Fs(null)},[w]);const Dn=a.useCallback(()=>{w&&(wn(ut?.title?.trim()||$t),Js(!0))},[ut?.title,w,$t]),on=a.useCallback(async()=>{if(!w)return;const H=un.trim();H&&H!==ut?.title?.trim()&&await Ks(w,H),Js(!1)},[ut?.title,w,un,Ks]);a.useEffect(()=>{if(!ts)return;const H=Ge=>{const rt=Ge.target;(!rt||!fn.current?.contains(rt))&&on()};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[ts,on]);const fr=a.useCallback(()=>{w&&tr(w).then(H=>{fe[H.ok?"success":"error"](o(H.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>fe.error(o("sessions.sidebar.session.copyId.error")))},[w,o]),Pn=a.useCallback(async()=>{if(!w)return;const H=await Yt(w);if(H?.share?.url){const Ge=await tr(H.share.url);fe[Ge.ok?"success":"warning"](o("sessions.sidebar.session.share.successTitle"),{description:o(Ge.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}fe.error(o("sessions.sidebar.session.share.error"))},[w,Yt,o]),Pr=a.useCallback(()=>{const H=ut?.shareUrl;H&&tr(H).then(Ge=>{fe[Ge.ok?"success":"error"](o(Ge.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>fe.error(o("sessions.sidebar.session.share.copyUrlError")))},[ut?.shareUrl,o]),js=a.useCallback(async()=>{if(!w)return;const H=await ws(w);fe[H?"success":"error"](o(H?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[w,o,ws]),re=a.useCallback(async()=>{if(!w||!Rt){fe.error(o("sessions.sidebar.session.export.nothingToExport"));return}try{await ms.loadCompleteHistory(w,Rt)}catch{fe.error(o("sessions.sidebar.session.export.failedLoadHistory"));return}const H=fl(Pt.getState(),w).list;if(H.length===0){fe.error(o("sessions.sidebar.session.export.nothingToExport"));return}const Ge=Qf(H,ut?.title??null),rt=Zf(ut?.title??null);await Jf(Ge,rt)||Xf(Ge,rt),fe.success(o("sessions.sidebar.session.export.success"))},[ut?.title,w,Pt,Rt,ms,o]),qe=v?.type==="busy"||v?.type==="retry",lt=a.useCallback(()=>{if(!w||!Ze||qe||D)return;const H=gn.getState().activeSessions,Ge=H.find(es=>es.id===w);if(!Ge)return;const rt=[],vt=[w];for(let es=0;es<vt.length;es+=1){const ns=vt[es];for(const os of H)os.parentID===ns&&(rt.push(os),vt.push(os.id))}tm({root:Ge,descendants:rt,sourceDirectory:Ze,successMessage:o("sessions.sidebar.session.moveToWorktree.success"),failureMessage:o("sessions.sidebar.session.moveToWorktree.failed")})},[w,qe,D,Ze,o]),xt=a.useCallback(async()=>{if(!w||!Bs)return;const H=gn.getState().activeSessions,Ge=[w];for(let ns=0;ns<Ge.length;ns+=1){const os=Ge[ns];for(const bs of H)bs.parentID===os&&!Ge.includes(bs.id)&&Ge.push(bs.id)}const rt=Bs;if(Fs(null),(rt==="archive"?await Xs(Ge):await An(Ge)).failedIds.length>0){fe.error(o(rt==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}fe.success(o(rt==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[Xs,w,An,Bs,o]),qt=Ee(H=>H.isScheduledTasksDialogOpen),Tt=Ee(H=>H.isArchivePageOpen),Ct=Ee(H=>H.worktreesPageProjectId),xs=Ee(H=>H.isMultiRunLauncherOpen),As=ds(H=>{if(!Ct)return null;const Ge=H.projects.find(rt=>rt.id===Ct);return Ge?.label?.trim()||Ge?.path?.split("/").pop()||null}),as=a.useMemo(()=>qt?{title:o("sessions.scheduledTasks.dialog.title"),subtitle:null}:Tt?{title:o("sessions.archivePage.title"),subtitle:null}:Ct?{title:o("sessions.worktreesPage.title",{project:As??""}),subtitle:null}:xs?{title:o("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[Tt,xs,qt,o,Ct,As]),Ss=a.useMemo(()=>Xn(Rt||k?.path||""),[k?.path,Rt]),Rs=a.useMemo(()=>k?{id:k.id,path:k.path}:null,[k]),Os=a.useRef(null);a.useEffect(()=>{!Rs||!Ss||(Os.current={projectRef:Rs,directory:Ss})},[Ss,Rs]);const ks=a.useMemo(()=>Rs&&Ss?{projectRef:Rs,directory:Ss}:Os.current,[Ss,Rs]),Be=zl(H=>H.planModeEnabled),Wt=Je(H=>H.isSessionPlanAvailable),ss=Be&&w?Wt(w):!1,hs=ss,Ns=a.useRef("");a.useEffect(()=>{if(!Be){Ee.getState().activeMainTab==="plan"&&Ee.getState().setActiveMainTab("chat");return}if(!w)return;const H=`${w||"none"}:${Ze||"none"}:${ut?.created||0}:${ut?.slug||"none"}`;Ns.current!==H&&(Ns.current=H),!ss&&Ee.getState().activeMainTab==="plan"&&Ee.getState().setActiveMainTab("chat")},[Be,ss,ut?.slug,ut?.created,w,Ze]);const Ds=a.useCallback(async H=>{if(!(!H||ie)){ee(!0);try{const Ge=g.github?await g.github.authActivate(H):await(async()=>{const rt=await us("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:H})}),vt=await rt.json().catch(()=>null);if(!rt.ok||!vt)throw new Error(vt?.error||rt.statusText);return vt})();V(Ge)}catch(Ge){console.error("Failed to switch GitHub account:",Ge)}finally{ee(!1)}}},[ie,g.github,V]),$s=a.useCallback(()=>{if(typeof document>"u")return;const H=document.activeElement;if(!H)return;const Ge=H.tagName;(Ge==="INPUT"||Ge==="TEXTAREA"||Ge==="SELECT"||H.isContentEditable)&&H.blur()},[]),Zs=a.useCallback(()=>{if(G){$s(),i(!q);return}c()},[$s,G,q,i,c]),an=a.useCallback(()=>{Cr("desktop_open_draft_mini_chat_window",{directory:Xn(Rt||k?.path||""),projectId:k?.id??null,apiBaseUrl:Nr(),clientToken:Xi()}).catch(H=>{console.warn("[header] failed to open draft mini chat window",H)})},[k?.id,k?.path,Rt]),Vn=a.useCallback(()=>{if(j){an();return}w&&Cr("desktop_open_session_mini_chat_window",{sessionId:w,directory:Xn(Rt||k?.path||""),apiBaseUrl:Nr(),clientToken:Xi()}).catch(H=>{console.warn("[header] failed to open session mini chat window",H)})},[k?.path,w,an,j,Rt]),zt=a.useCallback(()=>{const H=Xn(Rt||"");if(!H)return;const Ge=Ee.getState().contextPanelByDirectory[H];if(za(Ge)==="context"){h(H);return}d(H)},[h,d,Rt]),Xt=Zt==="context",mn=a.useCallback(()=>{const H=Xn(Rt||"");if(!H)return;const Ge=Ee.getState().contextPanelByDirectory[H];if(za(Ge)==="plan"){h(H);return}u(H)},[h,u,Rt]),In=Pa,_s=Gb,ir=a.useMemo(()=>ke?"services":n?"sessions":r?"git":f,[f,ke,n,r]),Ir=a.useCallback(()=>{ae(!1),n&&t&&t(),r&&e&&e(),!t&&q&&i(!1)},[q,n,t,e,r,i]),co=a.useCallback(()=>{n||ae(!1),t?.()},[n,t]),Uo=a.useCallback(()=>{r||ae(!1),e?.()},[e,r]),Rr=a.useMemo(()=>Z&&xe&&!Q?"5.5rem":se?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!Z||W)&&!Dt?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[Z,Q,xe,se,Dt,W]);$e.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",Rr)},[Rr]);const uo=l?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Ur=l?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";$e.useEffect(()=>{if(!Z||!xe){Me(!1);return}let H=!1;const Ge=async()=>{try{const vt=await Cr("desktop_is_window_fullscreen");H||Me(vt===!0)}catch{H||Me(!1)}},rt=()=>{Ge()};return Ge(),window.addEventListener("openchamber:window-resized",rt),()=>{H=!0,window.removeEventListener("openchamber:window-resized",rt)}},[Z,xe]);const fo=a.useMemo(()=>!Z||!xe||ne===null?"":ne>=26?"h-12":ne<=15?"h-14":"",[Z,xe,ne]),Ho=a.useMemo(()=>{if(!(Z&&!W||Dt))return{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))"}},[Z,Dt,W]),mr=a.useCallback(()=>{if(typeof document>"u")return;const H=te.current?.getBoundingClientRect().height;H&&document.documentElement.style.setProperty("--oc-header-height",`${H}px`)},[]);$e.useEffect(()=>{if(typeof window>"u")return;mr();const H=te.current;if(!H||typeof ResizeObserver>"u")return()=>{};let Ge=0;const rt=()=>{Ge||(Ge=requestAnimationFrame(()=>{Ge=0,mr()}))},vt=new ResizeObserver(rt);return vt.observe(H),window.addEventListener("resize",rt),window.addEventListener("orientationchange",rt),()=>{Ge&&cancelAnimationFrame(Ge),vt.disconnect(),window.removeEventListener("resize",rt),window.removeEventListener("orientationchange",rt)}},[mr]),$e.useEffect(()=>{mr()},[mr,G,fo]);const Ko=a.useCallback(async H=>{const Ge=H.target;Ge.closest(".app-region-no-drag")||Ge.closest("button, a, input, select, textarea")||H.button===0&&Z&&await Dh()},[Z]),vn=a.useMemo(()=>{if(G){const H=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return hs&&H.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),H.push({id:"diff",label:o("layout.mainTab.diff"),icon:"diff"},{id:"files",label:o("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:o("layout.mainTab.terminal"),icon:"terminal-box"},{id:"context",label:o("layout.mainTab.context"),icon:"file-list-2"},{id:"diagram",label:o("layout.mainTab.diagram"),icon:"file"}),H}return[]},[G,hs,o]),Wn=a.useCallback(H=>ga(so(H,x)),[x]);$e.useEffect(()=>{!G&&f!=="chat"&&f!=="terminal"&&f!=="diagram"&&p("chat")},[f,G,p]);const zs=a.useMemo(()=>{const H=[];return Z&&H.push({value:"instance",label:o("layout.services.instance"),icon:s.jsx(A,{name:"server",className:"h-3.5 w-3.5"})}),H.push({value:"usage",label:o("layout.services.usage"),icon:s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"})},{value:"mcp",label:"MCP",icon:s.jsx(xl,{className:"h-3.5 w-3.5"})}),H},[Z,o]),qn=a.useMemo(()=>zs.map(H=>({id:H.value,label:H.label,icon:H.icon})),[zs]),Hr=a.useMemo(()=>{if(typeof window>"u"||Z||Dt)return!1;const H=window.location.hostname;return H==="localhost"||H==="127.0.0.1"||H==="::1"},[Z,Dt]),mo=a.useCallback(async()=>{if(m)return;y(!0),le(!1);const H=[];let Ge=!1;try{try{for(const[,rt]of gs.getState().sessions.entries())for(const vt of rt.tabs)vt.previewUrl&&H.push(vt.previewUrl)}catch{}try{await g.terminal.forceKill?.({})}catch{}try{(await us("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:H})})).ok?Ge=!0:Ge=(await us("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Ge||y(!1)}},[m,g.terminal,le]),hr=a.useMemo(()=>[{value:"usage",label:o("header.services.used")},{value:"remaining",label:o("header.services.remaining")}],[o]),ho=a.useMemo(()=>hr.map(H=>({id:H.value,label:H.label})),[hr]),po=a.useMemo(()=>[{id:"usage",label:o("layout.services.usage"),icon:s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(xl,{className:"h-3.5 w-3.5"})}],[o]);$e.useEffect(()=>{const H=Ge=>{if(af(Ge)&&!Ge.shiftKey&&!Ge.altKey){const rt=parseInt(Ge.key,10);rt>=1&&rt<=vn.length&&(Ge.preventDefault(),G&&($s(),Ir()),p(vn[rt-1].id))}};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[$s,Ir,G,p,vn]),$e.useEffect(()=>{const H=Ge=>{const rt=so("toggle_services_menu",x);if(Fa(Ge,rt)){Ge.preventDefault(),U?le(!1):(le(!0),Lt(),ht==="usage"&&O.length===0&&M());return}const vt=so("cycle_services_tab",x);if(Fa(Ge,vt)){Ge.preventDefault();const ns=zs.map(Gs=>Gs.value);if(ns.length===0)return;const os=ns.indexOf(ht),bs=os===-1?0:(os+1)%ns.length,Ts=ns[bs];wt(Ts),le(!0),Lt(),Ts==="usage"&&O.length===0&&M();return}const es=so("toggle_context_plan",x);Fa(Ge,es)&&(Ge.preventDefault(),mn())};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[x,U,ht,zs,O.length,M,Lt,mn]);const ar=H=>{const Ge=f===H.id,rt=H.icon==="diff",vt=rt?null:H.icon,es=H.id==="chat",ns=bs=>rt?s.jsx(sd,{size:bs}):vt?s.jsx(A,{name:vt,className:`h-${bs/4} w-${bs/4}`}):null,os=s.jsxs("button",{type:"button",onClick:()=>p(H.id),className:Pe("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Ge?"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",es&&!G&&"min-w-[100px] justify-center"),"aria-label":H.label,"aria-selected":Ge,role:"tab",children:[G?ns(20):s.jsxs(s.Fragment,{children:[ns(16),s.jsx("span",{className:"header-tab-label",children:H.label})]}),H.badge!==void 0&&H.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:H.badge})]});return s.jsx(a.Fragment,{children:os},H.id)},Go=s.jsxs(s.Fragment,{children:[s.jsx(ub,{directory:Ss,className:"mr-1"}),s.jsx(Qb,{isDesktopApp:Z,currentInstanceLabel:ce,compactCurrentInstanceLabel:gt,currentInstanceIsLocal:me,isDesktopServicesOpen:U,setIsDesktopServicesOpen:le,refreshCurrentInstanceLabel:Lt,desktopServicesTab:ht,setDesktopServicesTab:wt,quotaResultsLength:O.length,fetchAllQuotas:M,servicesTabItems:qn,quotaLastUpdated:z,quotaDisplayMode:T,showPredValues:I,quotaDisplayTabItems:ho,handleDisplayModeChange:Et,handleUsageRefresh:tt,isQuotaLoading:B,isUsageRefreshSpinning:_e,hasRateLimits:Mt,rateLimitGroups:pt,expandedFamilies:It,toggleFamilyExpanded:We,shortcutLabel:Wn,showDevShutdown:Hr,isDevShutdownInFlight:m,onDevShutdown:mo,remoteUpdateInfo:Ie,remoteUpdateChecking:Ke,remoteUpdateError:ct,onOpenRemoteUpdate:et,timeFormatPreference:b}),s.jsx(Yb,{isMobile:G,githubAuthStatus:X,githubAccounts:ve,githubAvatarUrl:Ne,githubLogin:je,isSwitchingGitHubAccount:ie,handleGitHubAccountSwitch:Ds})]}),Kr=Fe&&(j||!!w),Ms=()=>s.jsxs("div",{onMouseDown:Ko,className:Pe("app-region-drag relative flex h-12 select-none items-center pr-3",fo),style:Ho,role:"tablist","aria-label":o("header.navigation.mainAria"),children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:uo}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:Ur}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[as?s.jsxs("div",{className:"mr-3 flex min-w-0 flex-col items-start px-1 py-0.5 -my-0.5 text-left",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:as.title}),as.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:as.subtitle}):null]}):s.jsxs("div",{className:"app-region-no-drag mr-3 flex min-w-0 max-w-full items-center gap-0.5 py-0.5 -my-0.5 text-left",children:[l?null:s.jsx($x,{align:"start",children:s.jsx("button",{type:"button",className:In,"aria-label":o("sessions.switcher.openAria"),children:s.jsx(A,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsxs("div",{className:"flex min-w-0 flex-col justify-center px-1",children:[ts?s.jsxs("form",{ref:fn,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:H=>{H.preventDefault(),on()},children:[s.jsx("input",{value:un,onChange:H=>wn(H.target.value),autoFocus:!0,onKeyDown:H=>{H.stopPropagation(),H.key==="Escape"&&Js(!1)},placeholder:o("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent typography-ui-label text-[14px] font-normal leading-tight outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":o("sessions.sidebar.session.rename.save"),title:o("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>Js(!1),"aria-label":o("sessions.sidebar.session.rename.cancel"),title:o("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:j?o("sessions.switcher.draftTitle"):$t}),E||Ot||!j&&st?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:[E?s.jsx("span",{className:"truncate",children:E}):null,Ot?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:Ot})]}):null,!j&&st?s.jsxs("span",{className:Pe("inline-flex min-w-0 items-center gap-0.5",st==="attention"||st==="invalid"||st==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(A,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Qe})]}):null]}):null]}),s.jsx("div",{className:"flex h-[18px] shrink-0 items-center justify-center self-start",children:w&&!j&&!ts?s.jsxs(Qs,{open:or,onOpenChange:zn,onOpenChangeComplete:H=>{!H&&dn.current&&(dn.current=!1,Dn())},children:[s.jsx(qs,{asChild:!0,children:s.jsx(He,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":o("header.sessionActions.openAria"),children:s.jsx(A,{name:"more",className:"size-4"})})}),s.jsxs(Ys,{align:"end",className:"min-w-[190px]",children:[s.jsxs(is,{onClick:()=>{dn.current=!0},children:[s.jsx(A,{name:"pencil-ai",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.rename")]}),s.jsxs(is,{onClick:fr,children:[s.jsx(A,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyId")]}),s.jsx(Ln,{}),ut?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs(is,{onClick:Pr,children:[s.jsx(A,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(is,{onClick:()=>{js()},children:[s.jsx(A,{name:"link-unlink-m",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(is,{onClick:()=>{Pn()},children:[s.jsx(A,{name:"share-2",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.share")]}),s.jsxs(is,{onClick:()=>{re()},children:[s.jsx(A,{name:"download",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.exportMarkdown")]}),!Dt&&ut&&!ut.parentId?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(is,{disabled:!Ze||qe||D,onClick:lt,className:"w-full",children:[s.jsx(A,{name:"folder-shared",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(Nt,{side:"right",className:"max-w-72",children:o(D?"sessions.sidebar.session.moveToWorktree.tooltipMoving":qe?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(Ln,{}),s.jsxs(is,{onClick:()=>Fs("archive"),children:[s.jsx(A,{name:"inbox-archive",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.archive")]}),s.jsxs(is,{className:"text-destructive focus:text-destructive",onClick:()=>Fs("delete"),children:[s.jsx(A,{name:"delete-bin",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.delete")]})]})]}):null})]}),vn.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:vn.map(H=>ar(H))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Kt&&Le?s.jsx(_x,{totalTokens:Le.totalTokens,percentage:Ut,colorPercentage:Le.percentage,contextLimit:Le.contextLimit,outputLimit:Le.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:zt,pressed:Xt,className:Kr?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx(qb,{visible:Kr,title:o(j?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(j?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Vn,className:Pe(In,"mr-1"),Icon:"picture-in-picture-2"}),Go,s.jsx(zf,{visible:W&&J==="right",position:"right"})]})]})]}),pr=()=>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:co,className:Pe(_s,ir==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":o(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(A,{name:"layout-left",className:"h-5 w-5"})}):q?s.jsx("button",{type:"button",onClick:()=>i(!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":o("header.actions.backAria"),children:s.jsx(A,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:Zs,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":o("header.actions.openSessionsAria"),children:s.jsx(A,{name:"play-list-add",className:"h-5 w-5"})}),!t&&q&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!q||!!t)&&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":o("header.navigation.mainAria"),children:vn.map(H=>{const Ge=f===H.id,rt=H.icon==="diff",vt=rt?null:H.icon;return s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{G&&($s(),Ir()),p(H.id)},"aria-label":H.label,"aria-selected":Ge,role:"tab",className:Pe(_s,"relative rounded-lg",ir===H.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[rt?s.jsx(sd,{className:"h-5 w-5"}):vt?s.jsx(A,{name:vt,className:"h-5 w-5"}):null,H.badge!==void 0&&H.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:H.badge}),H.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":o("header.changes.availableAria")})]})}),s.jsx(Nt,{children:s.jsx("p",{children:H.label})})]},H.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[ks&&s.jsx(Gf,{projectRef:ks.projectRef,directory:ks.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(Qs,{open:ke,onOpenChange:H=>{H&&(n&&t&&t(),r&&e&&e()),ae(H),H&&O.length===0&&M()},children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:Pe(_s,ir==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(A,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Nt,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(Ys,{align:"end",sideOffset:0,positionerClassName:"!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none",className:"h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 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(fi,{items:po,activeId:bt,onSelect:H=>{const Ge=H;yt(Ge),Ge==="usage"&&O.length===0&&M()},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:()=>ae(!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":o("header.services.closeAria"),children:s.jsx(A,{name:"close",className:"h-5 w-5"})})]})}),bt==="mcp"&&s.jsx(Af,{active:ke&&bt==="mcp"}),bt==="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:o("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:sm(z,b)})]}),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:()=>Et("usage"),className:Pe("typography-ui-label px-1 pb-0.5 transition-colors",T==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Et("remaining"),className:Pe("typography-ui-label px-1 pb-0.5 transition-colors",T==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.remaining")})]}),s.jsx("button",{type:"button",className:Pe("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:tt,disabled:B||_e,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(A,{name:"refresh",className:Pe("h-4 w-4",_e&&"animate-spin")})})]})]})}),!Mt&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:o("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:pt.map((H,Ge)=>s.jsxs(a.Fragment,{children:[Ge>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(li,{providerId:H.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:H.providerName})]}),H.entries.length===0&&(!H.modelFamilies||H.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:H.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[H.entries.map(([rt,vt])=>{const es=T==="remaining"?vt.remainingPercent:vt.usedPercent,ns=Ji(vt.usedPercent,vt.resetAt,vt.windowSeconds,rt),os=ns?.dailyAllocationPercent!=null?T==="remaining"?100-_r(ns.elapsedRatio):_r(ns.elapsedRatio):null,bs=ci(vt.valueLabel,es),Ts=sf(vt.resetAt,vt.resetAfterFormatted??vt.resetAtFormatted,b);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:Bl(rt)}),Ts?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Ts}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:bs==="-"?"":bs})]}),s.jsx(sa,{percent:es,tonePercent:vt.usedPercent,className:"h-1.5",expectedMarkerPercent:os}),ns&&I?s.jsx(na,{paceInfo:ns,compact:!0}):null]},`${H.providerId}-${rt}`)}),H.modelFamilies&&H.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:H.modelFamilies.map(rt=>{const es=(It[H.providerId]??[]).includes(rt.familyId??"other");return s.jsxs(Fo,{open:es,onOpenChange:()=>We(H.providerId,rt.familyId??"other"),children:[s.jsxs(bi,{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:rt.familyLabel}),es?s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(Oo,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:rt.models.map(([ns,os])=>{const bs=T==="remaining"?os.remainingPercent:os.usedPercent,Ts=Ji(os.usedPercent,os.resetAt,os.windowSeconds),Gs=Ts?.dailyAllocationPercent!=null?T==="remaining"?100-_r(Ts.elapsedRatio):_r(Ts.elapsedRatio):null,Es=ci(os.valueLabel,bs);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:Cf(ns)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Es==="-"?"":Es})]}),s.jsx(sa,{percent:bs,tonePercent:os.usedPercent,className:"h-1.5",expectedMarkerPercent:Gs}),Ts&&I?s.jsx(na,{paceInfo:Ts,compact:!0}):null]},`${H.providerId}-${ns}`)})})})]},rt.familyId??"other")})})]})]},H.providerId))})]})]})})]}),e?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Uo,className:Pe(_s,"relative",ir==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(A,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Nt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Yn=Pe("header-safe-area relative z-10 bg-background",G&&"border-b border-border/50");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:te,className:Yn,style:{"--padding-scale":"1"},children:G?pr():Ms()}),s.jsx(Ps,{open:Bs!==null,onOpenChange:H=>{H||Fs(null)},children:s.jsxs(Is,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Us,{children:[s.jsx(Ls,{children:o(Bs==="delete"?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(Hs,{children:Bs==="delete"?o("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:$t}):o("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:$t})})]}),s.jsxs(rr,{children:[s.jsx(He,{variant:"outline",size:"sm",onClick:()=>Fs(null),children:o("sessions.sidebar.dialogs.cancel")}),s.jsx(He,{variant:"destructive",size:"sm",onClick:()=>{xt()},children:o(Bs==="delete"?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(Pf,{open:_,onOpenChange:ge,info:Ie,downloading:!1,downloaded:!1,progress:null,error:ct,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function Zb(){}const ad=280,ld=280,cd=500,ey=({isOpen:t,isMobile:e,children:n,className:r,topBar:o})=>{const{t:i}=ft(),c=Ee(v=>v.sidebarWidth),l=Ee(v=>v.setSidebarWidth),[d,u]=a.useState(!1),h=a.useRef(0),f=a.useRef(c||ad),p=a.useRef(null),x=a.useRef(null),b=a.useRef(null),S=a.useCallback(v=>Math.min(cd,Math.max(ld,v)),[]),g=a.useCallback(v=>{const D=b.current;D&&(D.style.width=`${v}px`,D.style.minWidth=`${v}px`,D.style.maxWidth=`${v}px`,D.style.setProperty("--oc-left-sidebar-width",`${v}px`))},[]);if(a.useEffect(()=>{e&&d&&u(!1)},[e,d]),a.useEffect(()=>{d||(p.current=null,x.current=null)},[d]),e)return null;const m=Math.min(cd,Math.max(ld,c||ad)),y=t?m:0,C=v=>{if(t){try{v.currentTarget.setPointerCapture(v.pointerId)}catch{}x.current=v.pointerId,u(!0),h.current=v.clientX,f.current=y,p.current=y,g(y),v.preventDefault()}},j=v=>{if(e||!d||x.current!==v.pointerId)return;const D=v.clientX-h.current,F=S(f.current+D);p.current!==F&&(p.current=F,g(F))},w=v=>{if(x.current!==v.pointerId||e)return;try{v.currentTarget.releasePointerCapture(v.pointerId)}catch{}const D=S(p.current??y);x.current=null,p.current=null,u(!1),l(D)},N=d?p.current??y:y;return s.jsxs("aside",{ref:b,className:Pe("relative flex h-full overflow-hidden border-r border-border will-change-[width] motion-reduce:transition-none","bg-sidebar oc-vibrancy-surface",t&&"shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]",!t&&"border-r-0",r),style:{width:`${N}px`,minWidth:`${N}px`,maxWidth:`${N}px`,"--oc-left-sidebar-width":`${d?N:m}px`,overflowX:"clip",transitionProperty:d?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||y===0,children:[t&&s.jsx("div",{className:Pe("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",d&&"bg-[var(--interactive-border)]"),onPointerDown:C,onPointerMove:j,onPointerUp:w,onPointerCancel:w,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:Pe("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",d&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[o,s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx(Cs,{children:n})})]})]})},ty=()=>{const t=ot.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={height:"var(--oc-header-height, 3rem)"},t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("div",{className:"app-region-drag shrink-0",style:{width:"var(--oc-titlebar-left-inset, 0.75rem)"}}),t[1]=n):n=t[1];let r;return t[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs("div",{"aria-hidden":!0,className:"flex shrink-0",style:e,children:[n,s.jsx("div",{className:"app-region-no-drag shrink-0",style:{width:"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)"}}),s.jsx("div",{className:"app-region-drag flex-1"})]}),t[2]=r):r=t[2],r},ji=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function sy(){const t=ds(f=>f.activeProjectId?f.projects.find(p=>p.id===f.activeProjectId)??null:null),e=Je(f=>f.currentSessionId),n=ep(e??null),r=Je(f=>e?f.worktreeMetadata.get(e)?.path??"":""),o=Je(f=>f.newSessionDraft?.open?ji(f.newSessionDraft.bootstrapPendingDirectory??f.newSessionDraft.directoryOverride??""):""),i=a.useMemo(()=>ji(r||""),[r]),c=a.useMemo(()=>{const f=typeof n?.directory=="string"?n.directory:"";return ji(f||"")},[n?.directory]),l=i||c||o,d=a.useMemo(()=>ji(l||t?.path||""),[t?.path,l]),u=a.useMemo(()=>t?{id:t.id,path:t.path}:null,[t]),h=a.useRef(null);return a.useEffect(()=>{u&&d&&(h.current={projectRef:u,directory:d})},[d,u]),a.useMemo(()=>u&&d?{projectRef:u,directory:d}:h.current,[u,d])}const dd="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 hover:bg-interactive-hover transition-colors",ny=()=>{const t=ot.c(36),{t:e}=ft(),n=Ee(ry),r=Ee(oy),o=Ee(iy),i=sy(),c=a.useRef(null),l=ga(so("toggle_sidebar",o)),{usesFramelessChrome:d,side:u}=_f(),h=ly;let f,p;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{if(typeof document>"u")return;const z=c.current;if(!z)return;const T=()=>{const R=Math.max(z.getBoundingClientRect().width,z.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(R)}px`)};if(T(),typeof ResizeObserver>"u")return;const I=new ResizeObserver(T);return I.observe(z),()=>{I.disconnect()}},p=[],t[0]=f,t[1]=p):(f=t[0],p=t[1]),a.useEffect(f,p);const x="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let b;t[2]===Symbol.for("react.memo_cache_sentinel")?(b={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=b):b=t[2];const S="flex items-center gap-2";let g;t[3]!==d||t[4]!==u?(g=d&&u==="left"?s.jsx(zf,{visible:!0,position:"left"}):null,t[3]=d,t[4]=u,t[5]=g):g=t[5];let m;t[6]!==e||t[7]!==d?(m=d?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,"aria-label":e("header.actions.openAppMenuAria"),className:Pe(dd,"shrink-0"),children:s.jsx(A,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(Nt,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=d,t[8]=m):m=t[8];const y=St;let C;t[9]!==e?(C=e("header.actions.openSessionsAria"),t[9]=e,t[10]=C):C=t[10];let j,w;t[11]===Symbol.for("react.memo_cache_sentinel")?(j=Pe(dd,"shrink-0"),w=s.jsx(A,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=j,t[12]=w):(j=t[11],w=t[12]);let N;t[13]!==C||t[14]!==n?(N=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":C,className:j,children:w})}),t[13]=C,t[14]=n,t[15]=N):N=t[15];const v=Nt,D=e("header.actions.openSessionsWithShortcut",{shortcut:l});let F;t[16]!==D?(F=s.jsx("p",{children:D}),t[16]=D,t[17]=F):F=t[17];let k;t[18]!==v||t[19]!==F?(k=s.jsx(v,{children:F}),t[18]=v,t[19]=F,t[20]=k):k=t[20];let E;t[21]!==y||t[22]!==N||t[23]!==k?(E=s.jsxs(y,{children:[N,k]}),t[21]=y,t[22]=N,t[23]=k,t[24]=E):E=t[24];let O;t[25]!==r||t[26]!==i?(O=i?s.jsx(Gf,{projectRef:i.projectRef,directory:i.directory,className:r?"oc-vibrancy-pill":void 0}):null,t[25]=r,t[26]=i,t[27]=O):O=t[27];let M;t[28]!==E||t[29]!==O||t[30]!==g||t[31]!==m?(M=s.jsxs("div",{ref:c,className:S,children:[g,m,E,O]}),t[28]=E,t[29]=O,t[30]=g,t[31]=m,t[32]=M):M=t[32];let B;return t[33]!==M||t[34]!==b?(B=s.jsx("div",{className:x,style:b,children:M}),t[33]=M,t[34]=b,t[35]=B):B=t[35],B};function ry(t){return t.toggleSidebar}function oy(t){return t.isSidebarOpen}function iy(t){return t.shortcutOverrides}function ay(t){console.warn("[titlebar] failed to open app menu",t)}function ly(t){const e=t.currentTarget.getBoundingClientRect();Cr("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(ay)}const Sl=5e3,cy=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},Si=(t,e)=>rp(op.getState().dictionary,t,e),dy=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},uy=async(t,e,n)=>{if(t.readFile)return(await t.readFile(e,{optional:!0,directory:n?.directory})).content??"";const r=new URLSearchParams({path:e,optional:"true"});n?.directory&&r.set("directory",n.directory);const o=await us(`/api/fs/read?${r.toString()}`,{cache:"no-store",headers:n?.directory?{"x-opencode-directory":n.directory}:void 0});if(!o.ok){const i=await o.json().catch(()=>({error:o.statusText}));throw new Error(i.error||"Failed to read file")}return o.text()},rc=async(t,e,n)=>{if(tp(e)||sp(e)||Ao(e))return{ok:!0};try{const r=await uy(t,e,n);return np(r)?{ok:!1,reason:"binary"}:cy(r,Sl)>Sl?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:dy(r)}}},oc=t=>{if(t==="too-large"){const e=Sl.toLocaleString(ai());return Si("contextFileOpen.failure.tooLarge",{count:e})}return Si(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},ud=(t,e)=>{if(e.length===0)return null;let n=null,r=null;for(const i of e)i.top<=t?(!n||i.top>n.top)&&(n=i):(!r||i.top<r.top)&&(r=i);const o=n??r;return o?{path:o.path,topOffset:o.top-t}:null},fy=(t,e,n,r)=>Math.min(Math.max(0,r),Math.max(0,t+n-e)),my=64,hy=3,Qr=new Map,nm=(t,e,n=hy)=>{const r=`${t}\0${n}\0${e}`,o=Qr.get(r);if(o)return Qr.delete(r),Qr.set(r,o),o;const i=gy(e),c=i?Vx(Wx(e,n),{oldFile:{name:t,contents:i.before},newFile:{name:t,contents:i.after}})??md(t):Ux(py(t,e))[0]?.files[0]??md(t);for(Qr.set(r,c);Qr.size>my;){const l=Qr.keys().next().value;if(!l)break;Qr.delete(l)}return c},py=(t,e)=>!e.trim()||e.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(e)?e:`Index: ${t}
|
|
38
|
+
===================================================================
|
|
39
|
+
--- ${t}
|
|
40
|
+
+++ ${t}
|
|
41
|
+
${e}`,gy=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const e=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(e.length!==1)return;const n=e[0],r=Number.parseInt(n[1]??"",10),o=Number.parseInt(n[2]??"",10);if(r>1||o>1||!Number.isFinite(r)||!Number.isFinite(o))return;const i=(n.index??0)+n[0].length,c=t.slice(i),l=[],d=[];let u;for(const h of c.split(/\r?\n/)){if(h.startsWith("diff --git ")||h.startsWith("@@ "))break;if(h.startsWith("\\")){if(u==="-"||u===" "){const f=l.at(-1);f&&(f.newline=!1)}if(u==="+"||u===" "){const f=d.at(-1);f&&(f.newline=!1)}continue}if(h.startsWith("-")){l.push({text:h.slice(1),newline:!0}),u="-";continue}if(h.startsWith("+")){d.push({text:h.slice(1),newline:!0}),u="+";continue}h.startsWith(" ")&&(l.push({text:h.slice(1),newline:!0}),d.push({text:h.slice(1),newline:!0}),u=" ")}return{before:fd(l),after:fd(d)}},fd=t=>t.map(e=>e.text+(e.newline?`
|
|
42
|
+
`:"")).join(""),md=t=>Hx({name:t,contents:""},{name:t,contents:""}),ic="border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)] hover:text-[var(--status-info)]";class Ia extends Error{code;model;requiredChars;availableChars;constructor(e,n={}){super(e),this.name="WalkthroughError",this.code=n.code,this.model=n.model,this.requiredChars=n.requiredChars,this.availableChars=n.availableChars}}const Ra="/api/walkthrough",rm=t=>/^application\/(?:[\w.+-]+\+)?json\b/i.test(t.headers.get("content-type")??""),om=()=>new Ia("This OpenChamber server has no walkthrough API",{code:"server-unsupported"}),xy=t=>!rm(t)&&(t.ok||t.status===404),ac=async(t,e)=>{if(xy(t))throw om();const n=await t.json().catch(()=>null);throw new Ia(typeof n?.error=="string"?n.error:e,{code:typeof n?.code=="string"?n.code:void 0,model:n?.model??void 0,requiredChars:typeof n?.requiredChars=="number"?n.requiredChars:void 0,availableChars:typeof n?.availableChars=="number"?n.availableChars:void 0})},im=async t=>{if(!rm(t))throw om();try{return await t.json()}catch{throw new Ia("The server returned a malformed walkthrough response")}};async function by(t,e,n={}){const r=await us(Ra,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?im(r):ac(r,"Failed to load walkthrough")}async function yy(t,e,n={}){const r=await us(`${Ra}/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e,force:n.force===!0,...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}}),signal:n.signal});return r.ok?im(r):ac(r,"Failed to generate walkthrough")}async function wy(t,e){const n=await us(`${Ra}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await ac(n,"Failed to cancel walkthrough generation")}async function vy(t,e,n){const r=await us(`${Ra}/progress`,{query:{directory:t,source:JSON.stringify(e)},signal:n});if(!r.ok)return null;const o=await r.json().catch(()=>null);return typeof o?.stage=="string"?o.stage:null}const Qo={status:"idle",stage:null,result:null,readiness:null,error:null},jy=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:`pr:${t.number}`,Or=(t,e)=>`${$n()}\0${t}\0${jy(e)}`,hd=t=>t instanceof Ia?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},Hn=new Map,Xo=new Map,Sy=1e3,Tn=zo()(Wf((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,o)=>{const i=Or(n,r);t(c=>{const l={...c.selectedLanguage};return o?l[i]=o:delete l[i],{selectedLanguage:l}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[Or(n,r)],selectModel:(n,r,o)=>{const i=Or(n,r);t(c=>{const l={...c.selectedModel};return o?l[i]=o:delete l[i],{selectedModel:l}})},getSelectedModel:(n,r)=>e().selectedModel[Or(n,r)],requestSource:(n,r)=>{t(o=>({requestedSource:{...o.requestedSource,[n]:r}}))},clearRequestedSource:n=>{t(r=>{if(!r.requestedSource[n])return r;const o={...r.requestedSource};return delete o[n],{requestedSource:o}})},getEntry:(n,r)=>e().entries[Or(n,r)]??Qo,load:async(n,r,o={})=>{if(!n)return;const i=Or(n,r);if(e().entries[i]?.status==="generating")return;Hn.get(i)?.abort();const l=new AbortController;Hn.set(i,l),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??Qo,status:"loading",error:null}}}));try{const d=await by(n,r,{model:e().selectedModel[i],language:o.language,signal:l.signal});if(l.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{status:"ready",stage:null,result:d,readiness:d.readiness??null,error:null}}})),d.generating&&e().generate(n,r,{language:o.language})}catch(d){if(l.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{...u.entries[i]??Qo,status:"error",stage:null,error:hd(d)}}}))}finally{Hn.get(i)===l&&Hn.delete(i)}},generate:async(n,r,o={})=>{if(!n)return;const i=Or(n,r);Hn.get(i)?.abort();const c=new AbortController;Hn.set(i,c),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??Qo,status:"generating",stage:"collecting",error:null}}}));const l=()=>{const d=Xo.get(i);d!==void 0&&(clearInterval(d),Xo.delete(i))};l(),Xo.set(i,setInterval(()=>{vy(n,r).then(d=>{!d||c.signal.aborted||t(u=>{const h=u.entries[i];return!h||h.status!=="generating"||h.stage===d?u:{entries:{...u.entries,[i]:{...h,stage:d}}}})}).catch(()=>{})},Sy));try{const d=await yy(n,r,{force:o.force,model:e().selectedModel[i],language:o.language,signal:c.signal});if(c.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{status:"ready",stage:null,result:d,readiness:u.entries[i]?.readiness??null,error:null}}}))}catch(d){if(c.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{...u.entries[i]??Qo,status:"error",stage:null,error:hd(d)}}}))}finally{l(),Hn.get(i)===c&&Hn.delete(i)}},cancel:(n,r)=>{const o=Or(n,r);wy(n,r).catch(()=>{}),Hn.get(o)?.abort(),Hn.delete(o),t(i=>{const c=i.entries[o];return c?{entries:{...i.entries,[o]:{...c,status:c.result?"ready":"idle",stage:null,error:null}}}:i})},reset:()=>{for(const n of Hn.values())n.abort();Hn.clear();for(const n of Xo.values())clearInterval(n);Xo.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),pd=t=>{if(!t)return null;const e=t.split(`
|
|
43
|
+
`);let n=null;for(const r of e){const o=r.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(o){const i=Number.parseInt(o[1]??"",10);n=Number.isFinite(i)&&i>=1?i:null;continue}if(n!==null){if(r.startsWith(" ")){n+=1;continue}if(r.startsWith("+"))return n;if(r.startsWith("-"))return Math.max(1,n)}}return null},ky=1100,Ny=15e3,gd=500,xd=300,Cy=1e6,Ay=3,Dy=t=>t<=6?t:t<=12?6:t<=25?4:2,Py=a.memo(()=>{const t=ot.c(4),{t:e}=ft();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),am={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},Iy=am.M,Ry=t=>{const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"},lm=t=>{const e=Ry(t);return am[e]??Iy},My=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},bd=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},yd=t=>!!t.working_dir?.trim()||t.index==="?",Ty=(t,e)=>cp(t,e),wd=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),vd=(t,e)=>{const n=t.split(`
|
|
44
|
+
`),r=e.split(`
|
|
45
|
+
`),o=Math.min(n.length,r.length);for(let i=0;i<o;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},Ey=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),Fy=t=>Array.isArray(t)?t.filter(e=>!e||typeof e!="object"?!1:typeof e.file=="string"):[],Oy=t=>t==="added"?"A":t==="deleted"?"D":"M",cm=(t,e,n)=>Ey(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:n}:{original:"",modified:"",patch:e,fileDiff:nm(t,e),contextMode:n},dm=(t,e,n)=>{const r=t??0,o=e??0;return!r&&!o?null:s.jsxs("span",{className:Pe("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",n?.className),children:[r?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",r]}):null,o?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",o]}):null]})},Ly=a.memo(t=>{const e=ot.c(53),{scope:n,workingCount:r,stagedCount:o,turnCount:i,onScopeChange:c}=t,{t:l}=ft(),[d,u]=a.useState(!1),h=n==="staged"?o:n==="turn"?i:r;let f;e[0]!==n||e[1]!==l?(f=l(n==="staged"?"diffView.scope.staged":n==="turn"?"diffView.scope.lastTurn":"diffView.scope.changed"),e[0]=n,e[1]=l,e[2]=f):f=e[2];const p=f;let x;e[3]!==l?(x=l("diffView.scope.selectorAria"),e[3]=l,e[4]=x):x=e[4];let b;e[5]!==h?(b=s.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",h]}),e[5]=h,e[6]=b):b=e[6];let S;e[7]!==p||e[8]!==b?(S=s.jsxs("span",{className:"whitespace-nowrap",children:[p,b]}),e[7]=p,e[8]=b,e[9]=S):S=e[9];let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=g):g=e[10];let m;e[11]!==x||e[12]!==S?(m=s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":x,children:[S,g]})}),e[11]=x,e[12]=S,e[13]=m):m=e[13];let y;e[14]!==c?(y=I=>{(I==="working"||I==="staged"||I==="turn")&&(c?.(I),u(!1))},e[14]=c,e[15]=y):y=e[15];let C;e[16]!==l?(C=l("diffView.scope.changed"),e[16]=l,e[17]=C):C=e[17];let j;e[18]!==C?(j=s.jsx("span",{children:C}),e[18]=C,e[19]=j):j=e[19];let w;e[20]!==r?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:r}),e[20]=r,e[21]=w):w=e[21];let N;e[22]!==w||e[23]!==j?(N=s.jsx(no,{value:"working",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[j,w]})}),e[22]=w,e[23]=j,e[24]=N):N=e[24];let v;e[25]!==l?(v=l("diffView.scope.staged"),e[25]=l,e[26]=v):v=e[26];let D;e[27]!==v?(D=s.jsx("span",{children:v}),e[27]=v,e[28]=D):D=e[28];let F;e[29]!==o?(F=s.jsx("span",{className:"typography-meta text-muted-foreground",children:o}),e[29]=o,e[30]=F):F=e[30];let k;e[31]!==D||e[32]!==F?(k=s.jsx(no,{value:"staged",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[D,F]})}),e[31]=D,e[32]=F,e[33]=k):k=e[33];let E;e[34]!==l?(E=l("diffView.scope.lastTurn"),e[34]=l,e[35]=E):E=e[35];let O;e[36]!==E?(O=s.jsx("span",{children:E}),e[36]=E,e[37]=O):O=e[37];let M;e[38]!==i?(M=s.jsx("span",{className:"typography-meta text-muted-foreground",children:i}),e[38]=i,e[39]=M):M=e[39];let B;e[40]!==O||e[41]!==M?(B=s.jsx(no,{value:"turn",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[O,M]})}),e[40]=O,e[41]=M,e[42]=B):B=e[42];let z;e[43]!==n||e[44]!==N||e[45]!==k||e[46]!==B||e[47]!==y?(z=s.jsx(Ys,{align:"start",className:"w-40",children:s.jsxs(ml,{value:n,onValueChange:y,children:[N,k,B]})}),e[43]=n,e[44]=N,e[45]=k,e[46]=B,e[47]=y,e[48]=z):z=e[48];let T;return e[49]!==d||e[50]!==z||e[51]!==m?(T=s.jsxs(Qs,{open:d,onOpenChange:u,children:[m,z]}),e[49]=d,e[50]=z,e[51]=m,e[52]=T):T=e[52],T}),By=a.memo(t=>{const e=ot.c(11),{changedFiles:n,selectedFile:r,onSelectFile:o}=t,{t:i}=ft();if(n.length===0)return null;let c;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i){let d;e[5]!==o||e[6]!==r||e[7]!==i?(d=u=>{const h=lm(u),f=r===u.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>o(u.path),className:Pe("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",f?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx($o,{filePath:u.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:h.color},title:i(h.descriptionKey),"aria-label":i(h.descriptionKey),children:h.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:u.path,children:u.path}),dm(u.insertions,u.deletions)]})},u.path)},e[5]=o,e[6]=r,e[7]=i,e[8]=d):d=e[8],c=n.map(d),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=c}else c=e[4];let l;return e[9]!==c?(l=s.jsx(On,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:c})}),e[9]=c,e[10]=l):l=e[10],l}),$y=a.memo(t=>{const e=ot.c(20),{filePath:n,diff:r,renderSideBySide:o}=t,{t:i}=ft(),c=r.original.length>0,l=r.modified.length>0,d=o?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",u=o?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={contain:"layout"},e[0]=h):h=e[0];let f;e[1]!==r.original||e[2]!==n||e[3]!==c||e[4]!==u||e[5]!==o||e[6]!==i?(f=c&&s.jsxs("div",{className:u,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=c,e[4]=u,e[5]=o,e[6]=i,e[7]=f):f=e[7];let p;e[8]!==r.modified||e[9]!==n||e[10]!==l||e[11]!==c||e[12]!==u||e[13]!==o||e[14]!==i?(p=l&&s.jsxs("div",{className:u,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=l,e[11]=c,e[12]=u,e[13]=o,e[14]=i,e[15]=p):p=e[15];let x;return e[16]!==d||e[17]!==f||e[18]!==p?(x=s.jsx("div",{className:"w-full overflow-auto p-4",style:h,children:s.jsxs("div",{className:d,children:[f,p]})}),e[16]=d,e[17]=f,e[18]=p,e[19]=x):x=e[19],x}),_y=a.memo(t=>{const e=ot.c(16),{filePath:n,diff:r,renderSideBySide:o,wrapLines:i}=t;let c;e[0]!==n?(c=Vl(n)||"text",e[0]=n,e[1]=c):c=e[1];const l=c;if(r.isBinary){let h;return e[2]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Py,{}),e[2]=h):h=e[2],h}if(Ao(n)){let h;return e[3]!==r||e[4]!==n||e[5]!==o?(h=s.jsx($y,{filePath:n,diff:r,renderSideBySide:o}),e[3]=r,e[4]=n,e[5]=o,e[6]=h):h=e[6],h}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let u;return e[8]!==r.fileDiff||e[9]!==r.modified||e[10]!==r.original||e[11]!==n||e[12]!==l||e[13]!==o||e[14]!==i?(u=s.jsx("div",{className:"w-full",style:d,children:s.jsx(ec,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:l,fileName:n,renderSideBySide:o,wrapLines:i,layout:"inline"})}),e[8]=r.fileDiff,e[9]=r.modified,e[10]=r.original,e[11]=n,e[12]=l,e[13]=o,e[14]=i,e[15]=u):u=e[15],u}),zy=a.memo(t=>{const e=ot.c(7),{filePath:n,staged:r,busyAction:o,disabled:i,onAction:c}=t,{t:l}=ft();let d;return e[0]!==o||e[1]!==i||e[2]!==n||e[3]!==c||e[4]!==r||e[5]!==l?(d=s.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-lg backdrop-blur-md",children:r?s.jsx(Va,{label:l("gitView.changes.unstageFileAria",{path:n}),icon:"arrow-go-back",loading:o==="unstage",disabled:i,onClick:()=>c("unstage")}):s.jsxs(s.Fragment,{children:[s.jsx(Va,{label:l("gitView.changes.revertFileAria",{path:n}),icon:"arrow-go-back",loading:o==="discard",disabled:i,tone:"failure",onClick:()=>c("discard")}),s.jsx(Va,{label:l("gitView.changes.stageFileAria",{path:n}),icon:"add",loading:o==="stage",disabled:i,tone:"success",onClick:()=>c("stage")})]})}),e[0]=o,e[1]=i,e[2]=n,e[3]=c,e[4]=r,e[5]=l,e[6]=d):d=e[6],d}),Va=t=>{const e=ot.c(14),{label:n,icon:r,loading:o,disabled:i,tone:c,onClick:l}=t,d=c==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",u=c==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]";let h;e[0]!==d||e[1]!==u?(h=Pe("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",d,u),e[0]=d,e[1]=u,e[2]=h):h=e[2];let f;e[3]!==l?(f=b=>{b.stopPropagation(),l()},e[3]=l,e[4]=f):f=e[4];let p;e[5]!==r||e[6]!==o?(p=o?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:r,className:r==="add"?"size-4":"size-3.5"}),e[5]=r,e[6]=o,e[7]=p):p=e[7];let x;return e[8]!==i||e[9]!==n||e[10]!==h||e[11]!==f||e[12]!==p?(x=s.jsx(He,{variant:"ghost",size:"sm",className:h,disabled:i,title:n,"aria-label":n,onClick:f,children:p}),e[8]=i,e[9]=n,e[10]=h,e[11]=f,e[12]=p,e[13]=x):x=e[13],x},Vy=a.memo(({directory:t,file:e,layout:n,wrapLines:r,isSelected:o,isExpanded:i,isMounted:c,onSelect:l,onExpandedChange:d,registerSectionRef:u,showOpenInEditorAction:h=!1,isOpeningInEditor:f=!1,onOpenInEditor:p,staged:x=!1,loadFullFiles:b=!1,initialDiffData:S=null})=>{const{t:g}=ft(),{git:m}=_n(),y=nn(a.useCallback(J=>J.directories.get(t)?.diffCache.get(e.path)??null,[t,e.path])),C=nn(J=>J.setDiff),j=nn(J=>J.fetchStatus),w=Ee(J=>J.setDiffFileLayout),[N,v]=a.useState(0),[D,F]=a.useState(null),[k,E]=a.useState(!1),[O,M]=a.useState(null),[B,z]=a.useState(!1),[T,I]=a.useState(null),[R,L]=a.useState(null),P=a.useRef(null),G=a.useRef(null),X=a.useMemo(()=>lm(e),[e]),V=n==="side-by-side",te=b?"full":"patch",Z=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,de=a.useMemo(()=>S||(x?R:T||(y?{original:y.original,modified:y.modified,isBinary:y.isBinary,contextMode:"full"}:null)),[y,S,T,x,R]),Fe=de?.contextMode===te,se=a.useCallback(J=>{G.current=J,u(e.path,J)},[e.path,u]),Q=a.useCallback(J=>{d(e.path,J)},[e.path,d]),Me=a.useCallback(()=>{l(e.path)},[e.path,l]);a.useEffect(()=>{x?L(null):I(null),F(null),P.current=null},[Z,x]),a.useEffect(()=>{if(!i||!c)return;if(!t||S||de&&Fe){P.current=null,E(!1);return}const J=`${t}::${e.path}::${x?"staged":"unstaged"}::${Z}::${te}::${N}`;if(P.current===J)return;P.current=J,F(null),E(!0);let ne=!1;const oe=$n(),ue=b?Cy:Ay,Ae=Ao(e.path)?m.getGitFileDiff(t,{path:e.path,staged:x}):m.getGitDiff(t,{path:e.path,staged:x,contextLines:ue}),we=Ny,Se=new Promise((Le,Ue)=>{setTimeout(()=>Ue(new Error(`Timed out after ${we}ms`)),we)});return Promise.race([Ae,Se]).then(Le=>{if(!ne){if("diff"in Le){const Ue=cm(e.path,Le.diff,te);x?L(Ue):I(Ue)}else{const Ue={original:Le.original??"",modified:Le.modified??"",isBinary:Le.isBinary,contextMode:"full"};x?L(Ue):C(t,e.path,Ue,oe)}E(!1)}}).catch(Le=>{if(ne)return;const Ue=Le instanceof Error?Le.message:String(Le);F(Ue),E(!1)}),()=>{ne=!0,P.current===J&&(P.current=null)}},[te,de,Fe,N,t,e.path,Z,m,S,i,c,b,C,x]);const xe=a.useCallback(()=>{Q(!i),Me()},[Q,Me,i]),W=a.useCallback(async J=>{if(!(!t||O!==null)){M(J);try{J==="stage"?await m.stageGitFile(t,e.path):J==="unstage"?await m.unstageGitFile(t,e.path):await m.revertGitFile(t,e.path,{scope:"working"}),v(ne=>ne+1),await j(t,m)}catch(ne){const oe=J==="unstage"?"gitView.toast.unstageFileFailed":J==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.revertFailed";fe.error(ne instanceof Error?ne.message:g(oe))}finally{M(ne=>ne===J?null:ne)}}},[t,j,e.path,O,m,g]);return s.jsxs("div",{ref:se,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[s.jsx("div",{className:"sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:s.jsxs("div",{role:"button",tabIndex:0,onClick:xe,onKeyDown:J=>{J.target===J.currentTarget&&(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),xe())},className:Pe("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",o?"bg-[var(--interactive-selection)]/35":null),children:[s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:i?s.jsx(A,{name:"arrow-down-s",className:"size-4"}):s.jsx(A,{name:"arrow-right-s",className:"size-4"})}),s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:X.color},title:g(X.descriptionKey),"aria-label":g(X.descriptionKey),children:X.code}),s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[s.jsx($o,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const J=e.path.lastIndexOf("/");if(J===-1)return s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const ne=e.path.slice(0,J),oe=e.path.slice(J+1);return s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:ne}),s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[s.jsx("span",{className:"text-muted-foreground",children:"/"}),s.jsx("span",{className:"text-foreground",children:oe})]})]})})()]})})]}),s.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[dm(e.insertions,e.deletions),h&&p?s.jsx(He,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:g("diffView.actions.openFileInEditorAtChange"),onClick:J=>{J.stopPropagation(),p(e.path,de)},disabled:f,children:f?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"edit",className:"size-3.5"})}):null,s.jsx(lf,{mode:V?"side-by-side":"unified",onModeChange:J=>{const ne=J==="side-by-side"?"side-by-side":"inline";w(e.path,ne)},className:"opacity-70"})]})]})}),i&&s.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!c&&!D?s.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,D?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:g("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:D}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>v(J=>J+1),children:g("diffView.actions.retry")})]}):null,c&&k&&!de&&!D?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),g("diffView.state.loadingDiff")]}):null,c&&de&&!B&&e.insertions+e.deletions>gd?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:g("diffView.state.largeDiff",{count:e.insertions+e.deletions})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:g("diffView.state.largeDiffDescription")}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>z(!0),children:g("diffView.actions.renderAnyway")})]}):null,c&&de&&(B||e.insertions+e.deletions<=gd)?s.jsxs(s.Fragment,{children:[s.jsx(_y,{filePath:e.path,diff:de,renderSideBySide:V,wrapLines:r}),s.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:s.jsx("div",{className:"pointer-events-auto",children:s.jsx(zy,{filePath:e.path,staged:x,busyAction:O,disabled:O!==null,onAction:W})})})]}):null]})]})}),um=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:n=!1,showOpenInEditorAction:r=!1,diffScope:o="all",onDiffScopeChange:i,targetFilePath:c=null,flushContent:l=!1})=>{const{t:d}=ft(),{git:u,files:h}=_n(),f=Wr(),p=Ee(pe=>pe.openContextSurface),x=Tn(pe=>pe.requestSource),{screenWidth:b,isMobile:S}=Dr(),g=Wl(f??null),m=_o(f??null),y=Ul(f??null),C=nn(pe=>pe.setActiveDirectory),j=nn(pe=>pe.ensureStatus),w=nn(pe=>pe.fetchStatus),N=nn(pe=>pe.clearDiffCache),v=nn(pe=>pe.setDiff),[D,F]=a.useState(null),[k,E]=a.useState(!1),[O,M]=a.useState(null),[B,z]=a.useState(()=>new Set),[T,I]=a.useState(()=>new Set),[R,L]=a.useState(!1),[P,G]=a.useState(0),[X,V]=a.useState(()=>new Map),[te,Z]=a.useState(!1),[de,Fe]=a.useState(!1),[se,Q]=a.useState(o);a.useEffect(()=>{Q(o)},[o]);const Me=Ee(pe=>pe.pendingDiffFile),xe=Ee(pe=>pe.pendingDiffStaged),W=Ee(pe=>pe.pendingDiffScope),J=Ee(pe=>pe.setPendingDiffFile),ne=Ee(pe=>pe.diffLayoutPreference),oe=Ee(pe=>pe.diffFileLayout),ue=Ee(pe=>pe.setDiffFileLayout),Ae=Ee(pe=>pe.diffWrapLines),we=Ee(pe=>pe.setDiffWrapLines),Se=Ee(pe=>pe.openContextFileAtLine),Le=Je(pe=>pe.currentSessionId),Ue=ip(Le??"",f??void 0),be=Ae,q=se==="staged"?!0:se==="working"?!1:null,Ne=q??k,je=S||b<=768,ve=!!Le&&se!=="turn"&&!je&&!nr(),ie=se!=="turn"&&!je&&!nr(),ee=!t&&!je&&b>=1024,ke=a.useRef(null),ae=a.useRef(new Map),U=a.useRef(null),le=a.useRef(null),_e=a.useRef(!1),De=a.useRef(null),ce=a.useRef(null),he=a.useRef(null),me=a.useRef(null),$=a.useCallback(()=>{const pe=ke.current;if(!pe)return null;const Oe=pe.getBoundingClientRect().top,Te=[];for(const[it,ut]of ae.current)ut&&Te.push({path:it,top:ut.getBoundingClientRect().top});return ud(Oe,Te)},[]),_=a.useCallback(()=>{U.current=null,_e.current=!1,M(null),le.current!==null&&(window.cancelAnimationFrame(le.current),le.current=null)},[]),ge=a.useCallback(pe=>{z(Oe=>{if(Oe.has(pe))return Oe;const Te=new Set(Oe);return Te.add(pe),Te})},[]),Ie=a.useMemo(()=>{for(let pe=Ue.length-1;pe>=0;pe-=1){const Oe=Ue[pe];if(Oe.role==="user")return Fy(Oe.summary?.diffs)}return[]},[Ue]),Re=a.useMemo(()=>{const pe=new Map;for(const Oe of Ie)if(Oe.file){if(typeof Oe.patch=="string"){pe.set(Oe.file,cm(Oe.file,Oe.patch,"patch"));continue}pe.set(Oe.file,{original:Oe.before??"",modified:Oe.after??"",contextMode:"full"})}return pe},[Ie]),Ke=a.useMemo(()=>{if(se==="turn")return Ie.map(Te=>({path:Te.file??"",index:"",working_dir:Oy(Te.status),insertions:Te.additions??0,deletions:Te.deletions??0,isNew:Te.status==="added"})).filter(Te=>Te.path).sort((Te,it)=>Te.path.localeCompare(it.path));if(!m?.files)return[];const pe=m.diffStats??{},Oe=se==="staged"?bd:se==="working"?yd:()=>!0;return m.files.filter(Oe).map(Te=>({...Te,insertions:pe[Te.path]?.insertions??0,deletions:pe[Te.path]?.deletions??0,isNew:My(Te)})).sort((Te,it)=>Te.path.localeCompare(it.path))},[se,Ie,m]),nt=a.useMemo(()=>m?.files?m.files.filter(yd).length:0,[m]),ct=a.useMemo(()=>m?.files?m.files.filter(bd).length:0,[m]),mt=Ie.length,gt=a.useMemo(()=>Ke.map(pe=>pe.path).join("\0"),[Ke]);a.useEffect(()=>{const pe=gt?gt.split("\0"):[],Oe=new Set(pe),Te=`${f??""}:${se}:${e?"collapsed":"default"}`,it=ce.current!==Te;ce.current=Te,z(ut=>{if(it){const ze=e?0:Dy(pe.length);return new Set(pe.slice(0,ze))}let Gt=!1;const Ft=new Set;for(const ze of ut){if(!Oe.has(ze)){Gt=!0;continue}Ft.add(ze)}return Gt?Ft:ut}),I(ut=>{if(it)return new Set;let Gt=!1;const Ft=new Set;for(const ze of ut){if(!Oe.has(ze)){Gt=!0;continue}Ft.add(ze)}return Gt?Ft:ut})},[se,gt,f,e]);const ht=a.useCallback(()=>{De.current=null;const pe=ke.current;if(!pe)return;const Oe=pe.getBoundingClientRect(),Te=Oe.top-xd,it=Oe.bottom+xd,ut={},Gt=[];for(const[Ft,ze]of ae.current){if(!ze)continue;const Qe=ze.getBoundingClientRect();Gt.push({path:Ft,top:Qe.top}),B.has(Ft)&&(Qe.bottom<Te||Qe.top>it||(ut[Ft]=!0))}he.current=ud(Oe.top,Gt),I(Ft=>{let ze=!1;const Qe=new Set(Ft);for(const st of Object.keys(ut))Qe.has(st)||(Qe.add(st),ze=!0);return ze?Qe:Ft})},[B]),wt=a.useCallback(()=>{typeof window>"u"||De.current===null&&(De.current=window.requestAnimationFrame(ht))},[ht]);a.useEffect(()=>{const pe=ke.current;if(pe)return wt(),pe.addEventListener("scroll",wt,{passive:!0}),window.addEventListener("resize",wt),()=>{pe.removeEventListener("scroll",wt),window.removeEventListener("resize",wt),De.current!==null&&(window.cancelAnimationFrame(De.current),De.current=null)}},[Ke,B,wt]);const bt=a.useCallback(pe=>{const Oe=oe[pe.path];if(Oe)return Oe;if(ne==="inline")return"inline";if(ne==="side-by-side")return"side-by-side";const Te=b<ky;return pe.isNew||Te?"inline":"side-by-side"},[oe,ne,b]),yt=a.useMemo(()=>Ke.length===0?null:Ke.every(pe=>bt(pe)==="side-by-side")?"side-by-side":"inline",[Ke,bt]);a.useEffect(()=>{f&&(C(f),j(f,u))},[f,C,j,u]),a.useEffect(()=>{if(f)return Gn.onGitRefreshHint(pe=>{wd(pe.directory)===wd(f)&&(pe.paths?.length&&(me.current=$()??he.current,N(f,pe.paths),V(Oe=>{const Te=new Map(Oe);for(const it of pe.paths??[])Te.set(it,(Te.get(it)??0)+1);return Te})),w(f,u,{silent:!0}))})},[$,N,f,w,u]),a.useLayoutEffect(()=>{const pe=me.current;if(!pe)return;me.current=null;const Oe=ke.current,Te=ae.current.get(pe.path);if(!Oe||!Te)return;const it=Oe.getBoundingClientRect().top,ut=Te.getBoundingClientRect().top-it;Oe.scrollTop=fy(Oe.scrollTop,pe.topOffset,ut,Oe.scrollHeight-Oe.clientHeight),he.current=pe},[X]),a.useEffect(()=>{se!=="all"&&!W||Me&&(W&&Q(W),F(Me),E(W==="staged"||!W&&xe),J(null),_e.current=!0,U.current=Me,ge(Me),G(pe=>pe+1))},[se,ge,Me,W,xe,J]),a.useEffect(()=>{if(se==="all")return;const pe=c?.trim();pe&&(F(pe),E(se==="staged"),_e.current=!0,U.current=pe,ge(pe),G(Oe=>Oe+1))},[se,ge,c]),a.useEffect(()=>{if(!D)return;Ke.some(Oe=>Oe.path===D)||(F(null),E(!1))},[Ke,D]);const Dt=a.useCallback((pe,Oe)=>{const Te=ae.current;Oe?Te.set(pe,Oe):Te.delete(pe),wt()},[wt]),Kt=a.useCallback((pe,Oe)=>{_(),z(Te=>{const it=Te.has(pe);if(Oe===it)return Te;const ut=new Set(Te);return Oe?ut.add(pe):ut.delete(pe),ut}),Oe||I(Te=>{if(!Te.has(pe))return Te;const it=new Set(Te);return it.delete(pe),it}),wt()},[_,wt]),Ut=a.useCallback(()=>{_(),z(pe=>pe.size>0?new Set:new Set(Ke.map(Oe=>Oe.path))),I(new Set),wt()},[_,Ke,wt]),Lt=a.useCallback(async pe=>{if(!Le)return;const Oe=Je.getState().getDirectoryForSession(Le)||f||"";if(!Oe){fe.error(d("diffView.reviewDialog.toast.noSessionDirectory"));return}Fe(!0);try{await ap({originalSessionID:Le,directory:Oe,providerID:pe.providerID,modelID:pe.modelID,agent:pe.agent||void 0,variant:pe.variant||void 0,generateHandoff:pe.generateHandoff,returnAfterHandoffRequest:pe.generateHandoff,autoReview:pe.autoReview}),Z(!1)}catch(Te){console.error("[review-flow] failed to start review flow",Te),fe.error(Te instanceof Error?Te.message:d("diffView.reviewDialog.toast.startFailed"))}finally{Fe(!1)}},[Le,f,d]),Bt=a.useCallback(pe=>{const Oe=ae.current.get(pe),Te=ke.current;if(!Oe||!Te)return!1;const it=Oe.getBoundingClientRect().top-Te.getBoundingClientRect().top;return Te.scrollTo({top:Te.scrollTop+it,behavior:"auto"}),!0},[]);a.useEffect(()=>{if(!U.current)return;let Oe=0;const Te=20;let it=!1;const ut=(Ft=!0)=>{it||(it=!0,U.current=null,_e.current=!1,Ft&&M(null),le.current!==null&&(window.cancelAnimationFrame(le.current),le.current=null))},Gt=()=>{if(it){le.current=null;return}const Ft=U.current;if(!Ft){ut(),le.current=null;return}if(!Bt(Ft)){Oe+=1,Oe<Te?le.current=window.requestAnimationFrame(Gt):(ut(),le.current=null);return}if(n&&_e.current){M(Ft),ut(!1);return}ut()};return le.current=window.requestAnimationFrame(Gt),()=>{it=!0,le.current!==null&&(window.cancelAnimationFrame(le.current),le.current=null)}},[n,P,Bt]);const et=a.useCallback(pe=>{},[]),Ht=a.useCallback(pe=>{_(),F(pe),E(!1),_e.current=!0,U.current=pe,ge(pe),G(Oe=>Oe+1),Bt(pe)},[_,ge,Bt]),It=a.useCallback(pe=>{const Oe=pe==="side-by-side"?"side-by-side":"inline";Ke.forEach(Te=>{ue(Te.path,Oe)})},[Ke,ue]),[We,pt]=a.useState(null),Mt=a.useCallback(async(pe,Oe)=>{if(!f||!pe)return;pt(pe);const Te=$n();try{let it=null;if(Oe?.patch&&!Oe.isBinary&&!Ao(pe)?it=pd(Oe.patch):Oe&&Oe.contextMode==="full"&&!Oe.isBinary&&!Ao(pe)&&(it=vd(Oe.original,Oe.modified)),it===null)try{const Qe=await u.getGitDiff(f,{path:pe,staged:Ne,contextLines:3});it=pd(Qe.diff)}catch{it=null}let ut=Oe;if(it===null||!ut){const Qe=await u.getGitFileDiff(f,{path:pe,staged:Ne});ut={original:Qe.original??"",modified:Qe.modified??"",isBinary:Qe.isBinary},Ne||v(f,pe,ut,Te)}const Gt=it??(ut.isBinary||Ao(pe)?1:vd(ut.original,ut.modified)),Ft=Ty(f,pe),ze=await rc(h,Ft,{directory:f});if(!ze.ok){fe.error(oc(ze.reason));return}Se(f,Ft,Gt,1)}finally{pt(it=>it===pe?null:it)}},[Ne,f,h,u,Se,v]),Et=()=>{if(!f)return null;const pe=Oe=>q!==null?q:k&&Oe===D;return s.jsxs("div",{className:Pe("flex min-w-0 flex-1 min-h-0 h-full",l?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[ee&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:d("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ke.length})]}),s.jsx(By,{changedFiles:Ke,selectedFile:null,onSelectFile:Ht})]}),s.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:s.jsx(On,{ref:ke,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:s.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:Ke.map(Oe=>s.jsx(Vy,{directory:f,file:Oe,layout:bt(Oe),wrapLines:be,isSelected:!1,isExpanded:B.has(Oe.path),isMounted:T.has(Oe.path)||Oe.path===O,onSelect:et,onExpandedChange:Kt,registerSectionRef:Dt,showOpenInEditorAction:r&&se!=="turn",isOpeningInEditor:We===Oe.path,onOpenInEditor:(Te,it)=>{Mt(Te,it)},staged:pe(Oe.path),loadFullFiles:R,initialDiffData:se==="turn"?Re.get(Oe.path)??null:null},`${Oe.path}:${X.get(Oe.path)??0}`))})})})]})},tt=()=>f?se!=="turn"&&y&&!m?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),d("diffView.state.loadingRepositoryStatus")]}):se!=="turn"&&g===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.notGitRepository")}):Ke.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d(se==="turn"?"diffView.state.noLastTurnChanges":"diffView.state.cleanWorkingTree")}):Et():s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[!S&&(se==="working"||se==="staged"||se==="turn"?s.jsx(Ly,{scope:se,workingCount:nt,stagedCount:ct,turnCount:mt,onScopeChange:pe=>{Q(pe),i?.(pe)}}):s.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:y&&!m?d("diffView.state.loadingChanges"):Ke.length===1?d("diffView.summary.changedFilesSingle",{count:Ke.length}):d("diffView.summary.changedFilesPlural",{count:Ke.length})})})),Ke.length>0&&s.jsxs(He,{variant:"ghost",size:"sm",onClick:Ut,className:Pe("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:B.size>0?d("diffView.actions.collapseAll"):d("diffView.actions.expandAll"),children:[s.jsx(A,{name:"expand-up-down",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:B.size>0?d("diffView.actions.collapseAll"):d("diffView.actions.expandAll")})]}),Ke.length>0&&ve&&s.jsxs(He,{variant:"default",size:"sm",onClick:()=>Z(!0),disabled:de,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":d("diffView.actions.reviewAria"),children:[de?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"search-eye",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:d("diffView.actions.review")})]}),Ke.length>0&&ie&&s.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{const pe=f??"";x(pe,{kind:"working-tree",scope:se==="staged"||se==="working"?se:"all"}),p(pe,"walkthrough")},className:Pe("diff-toolbar__walkthrough-button h-7 flex-shrink-0 gap-1.5 px-2",ic),"aria-label":d("walkthrough.action.open"),children:[s.jsx(A,{name:"route",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__walkthrough-label typography-ui-label",children:d("walkthrough.action.open")})]}),Ke.length>0&&s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>L(pe=>!pe),"aria-pressed":R,"aria-label":d(R?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:Pe("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",R&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(A,{name:"file-download",className:"size-4"})})}),s.jsx(Nt,{children:s.jsx("p",{children:d(R?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),Ke.length>0&&s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>we(!Ae),className:Pe("h-5 w-5 p-0 transition-opacity",be?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:d(be?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(A,{name:"text-wrap",className:"size-4"})}),yt&&s.jsx(lf,{mode:yt==="side-by-side"?"side-by-side":"unified",onModeChange:It})]}),s.jsx(lp,{open:te,onOpenChange:Z,projectDirectory:f??null,submitting:de,onConfirm:Lt}),tt()]})},fm=12,Wy=[{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"}],Uy=t=>{const e=ot.c(18),{isActive:n,burstKey:r,className:o,durationMs:i,bursts:c,onComplete:l}=t,d=r===void 0?0:r,u=i===void 0?900:i,h=c===void 0?Wy:c,f=$e.useRef(!1);let p,x;e[0]!==n||e[1]!==l?(p=()=>{!n&&f.current&&l?.(),n&&(f.current=!0)},x=[n,l],e[0]=n,e[1]=l,e[2]=p,e[3]=x):(p=e[2],x=e[3]),$e.useEffect(p,x);let b;e[4]===Symbol.for("react.memo_cache_sentinel")?(b=Array.from({length:fm},Hy),e[4]=b):b=e[4];const S=b;if(!n)return null;let g;e[5]!==o?(g=Pe("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=g):g=e[6];let m;if(e[7]!==d||e[8]!==h||e[9]!==u){let C;e[11]!==d||e[12]!==u?(C=j=>{const w={"--burst-delay":`${j.delay}ms`,"--burst-x":`${j.x}%`,"--burst-y":`${j.y}%`,"--firework-color":`var(${j.colorVar})`,"--firework-duration":`${u}ms`};return s.jsx("div",{className:"firework-burst",style:w,children:S.map((N,v)=>{const D=N.x*j.radius,F=N.y*j.radius,k={"--translate-x":`${D}px`,"--translate-y":`${F}px`,"--particle-delay":`${N.delay}ms`,color:`var(${j.colorVar})`};return s.jsx("span",{className:"firework-particle",style:k},`${j.id}-${v}-${d}`)})},`${j.id}-${d}`)},e[11]=d,e[12]=u,e[13]=C):C=e[13],m=h.map(C),e[7]=d,e[8]=h,e[9]=u,e[10]=m}else m=e[10];let y;return e[14]!==d||e[15]!==g||e[16]!==m?(y=s.jsx("div",{className:g,"aria-hidden":"true","data-burst-key":d,children:m}),e[14]=d,e[15]=g,e[16]=m,e[17]=y):y=e[17],y};function Hy(t,e){const n=Math.PI*2*e/fm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Ky=t=>{const e=ot.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,o=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[c,l]=$e.useState(i),d=$e.useRef(null);let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=u):u=e[3];const h=u;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{h(),l(Gy)},e[4]=f):f=e[4];const p=f;let x;e[5]!==o?(x=()=>{h(),l(qy),d.current=window.setTimeout(()=>{l(Yy),d.current=null},o)},e[5]=o,e[6]=x):x=e[6];const b=x;let S,g;e[7]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>h(),g=[h],e[7]=S,e[8]=g):(S=e[7],g=e[8]),$e.useEffect(S,g);let m;return e[9]!==c.cycle||e[10]!==c.isActive||e[11]!==b?(m={isActive:c.isActive,burstKey:c.cycle,triggerFireworks:b,dismissFireworks:p},e[9]=c.cycle,e[10]=c.isActive,e[11]=b,e[12]=m):m=e[12],m};function Gy(t){return t.isActive?{...t,isActive:!1}:t}function qy(t){return{isActive:!0,cycle:t.cycle+1}}function Yy(t){return t.isActive?{...t,isActive:!1}:t}const mm=a.createContext(void 0),Qy=t=>{const e=ot.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:i,dismissFireworks:c}=Ky();let l;e[0]!==c||e[1]!==i?(l={triggerFireworks:i,dismissFireworks:c},e[0]=c,e[1]=i,e[2]=l):l=e[2];const d=l;let u;e[3]!==o||e[4]!==r?(u=s.jsx(Uy,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=u):u=e[5];let h;return e[6]!==n||e[7]!==u||e[8]!==d?(h=s.jsxs(mm.Provider,{value:d,children:[n,u]}),e[6]=n,e[7]=u,e[8]=d,e[9]=h):h=e[9],h},Xy=()=>{const t=a.useContext(mm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},hm="gitmojiCache",Jy=1e3*60*60*24*7,pm="1",Zy="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",gm=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Wa=()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem(hm);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==pm||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(gm),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},ew=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:pm};window.localStorage.setItem(hm,JSON.stringify(e))}catch{return}},jd=t=>Date.now()-t.fetchedAt<Jy;let ki=null;const ni=new Set,Sd=async()=>{if(ki)return ki;const t=(async()=>{try{const e=await fetch(Zy);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(gm):[];return ew(r),ni.forEach(o=>o(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return ni.forEach(r=>r(n)),n}finally{ki=null}})();return ki=t,t},tw=t=>{const[e,n]=a.useState(()=>t?Wa()?.gitmojis??[]:[]),[r,o]=a.useState(!1),i=a.useRef(t);i.current=t,a.useEffect(()=>{if(!t){ni.delete(n),n([]),o(!1);return}const l=Wa();if(l&&(n(l.gitmojis),jd(l)))return;ni.add(n),o(!0);let d=!1;return Sd().finally(()=>{!d&&i.current&&o(!1)}),()=>{d=!0,ni.delete(n)}},[t]);const c=a.useCallback(async()=>{if(!i.current)return[];if(e.length>0)return e;const l=Wa();return l&&jd(l)?l.gitmojis:Sd()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:c}},kd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function xm(t,e,n){const r=ot.c(5),[o,i]=a.useState();let c,l;return r[0]!==n||r[1]!==t||r[2]!==e?(c=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[u,h]=await Promise.all([dp(t),up(t)]).catch(sw);if(d)return;const f=kd(u),p=kd(h);if(!f||!p||p===f)return;const x=n||"",b=p.split("/").filter(Boolean).pop()||p;i({source:"sdk",path:p,projectDirectory:f,branch:x,label:x||b,name:b,worktreeRoot:p,worktreeStatus:"ready",headState:x?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},l=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=c,r[4]=l):(c=r[3],l=r[4]),a.useEffect(c,l),e??o}function sw(){return["",""]}const Vo=async(t,e)=>{const n=await us(`/api/git/integrate/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function Jo(t){return Vo("plan",t)}async function nw(t){return Vo("conflict-details",{tempWorktreePath:t})}async function rw(t){return(await Vo("cherry-pick-status",{tempWorktreePath:t})).inProgress}async function ow(t){return Vo("run",{plan:t})}async function iw(t){await Vo("abort",{state:t})}async function aw(t){return Vo("continue",{state:t})}const lw=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:o,refreshKey:i,onRefresh:c,showHeader:l=!0})=>{const{t:d}=ft(),u=Je(P=>P.currentSessionId),h=Ee(P=>P.setActiveMainTab),[f,p]=$e.useState(!1),x=$e.useRef(null),[b,S]=$e.useState(o);$e.useEffect(()=>{S(o)},[o]),$e.useEffect(()=>{if(f){const P=setTimeout(()=>{x.current?.focus()},0);return()=>clearTimeout(P)}},[f]);const g=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[m,y]=$e.useState({kind:"idle"}),[C,j]=$e.useState(!1),[w,N]=$e.useState([]),v=$e.useMemo(()=>u?`openchamber.integrate.conflict:${u}`:null,[u]);$e.useEffect(()=>{if(!v||typeof window>"u")return;const P=window.localStorage.getItem(v);if(!P)return;let G=!1;try{const X=JSON.parse(P);if(!X?.tempWorktreePath||X.repoRoot!==t){window.localStorage.removeItem(v);return}(async()=>{const V=await rw(X.tempWorktreePath).catch(()=>!1);if(G)return;if(!V){window.localStorage.removeItem(v);return}const te=await nw(X.tempWorktreePath).catch(()=>null);G||te&&y({kind:"conflict",state:X,details:te})})()}catch{window.localStorage.removeItem(v)}return()=>{G=!0}},[v,t]),$e.useEffect(()=>{if(!g){y({kind:"idle"});return}let P=!1;return y({kind:"loading"}),(async()=>{try{const G=await Jo({repoRoot:t,sourceBranch:e,targetBranch:b});if(P)return;if(y({kind:"ready",plan:G}),G.commits.length>0){const V=G.commits.slice(-50).reverse(),te=await fp(t,V);P||(N(te),j(!1))}else P||(N([]),j(!1))}catch{P||y({kind:"idle"})}})(),()=>{P=!0}},[g,t,e,b,i]);const D=$e.useCallback(P=>{u&&Je.getState().setWorktreeMetadata(u,{...n,createdFromBranch:P})},[u,n]),F=Je(P=>P.openNewSessionDraft),k=$e.useCallback(async P=>{const G=await To("git.integrate.cherrypick.resolve.visible",{current_commit:P.state.currentCommit,target_branch:P.state.targetBranch}),X=await To("git.integrate.cherrypick.resolve.instructions",{repo_root:P.state.repoRoot,temp_worktree_path:P.state.tempWorktreePath,source_branch:P.state.sourceBranch,target_branch:P.state.targetBranch,current_commit:P.state.currentCommit}),V=`Cherry-pick conflict context (JSON)
|
|
46
|
+
${JSON.stringify({repoRoot:P.state.repoRoot,tempWorktreePath:P.state.tempWorktreePath,sourceBranch:P.state.sourceBranch,targetBranch:P.state.targetBranch,currentCommit:P.state.currentCommit,remainingCommits:P.state.remainingCommits,statusPorcelain:P.details.statusPorcelain,unmergedFiles:P.details.unmergedFiles,currentPatchMeta:P.details.currentPatchMeta,currentPatch:P.details.currentPatch,diff:P.details.diff},null,2)}`;return{visibleText:G,instructionsText:X,payloadText:V}},[]),E=ao(P=>P.setPendingInputText),O=ao(P=>P.setPendingSyntheticParts),M=$e.useCallback(async(P,G)=>{const X=await k(P);if(G){F({directoryOverride:P.state.tempWorktreePath,initialPrompt:X.visibleText,syntheticParts:[{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]}),h("chat");return}if(!u){fe.error(d("gitView.integrate.noActiveSession"),{description:d("gitView.integrate.noActiveSessionDescription")});return}E(X.visibleText,"replace"),O([{text:X.instructionsText,synthetic:!0},{text:X.payloadText,synthetic:!0}]),h("chat")},[u,h,k,F,E,O,d]),B=$e.useCallback(async()=>{if(m.kind==="ready"){if(m.plan.commits.length===0){fe.message(d("gitView.integrate.noCommitsToMoveToast"));return}y({kind:"running",plan:m.plan});try{const P=await ow(m.plan);if(P.kind==="success"){fe.success(d("gitView.integrate.commitsMovedToast"),{description:P.moved===1?d("gitView.integrate.commitsMovedDescriptionSingle",{count:P.moved,branch:m.plan.targetBranch}):d("gitView.integrate.commitsMovedDescriptionPlural",{count:P.moved,branch:m.plan.targetBranch})});const G=await Jo(m.plan);y({kind:"ready",plan:G}),c?.();return}P.kind==="conflict"&&(fe.error(d("gitView.integrate.cherryPickConflictToast"),{description:d("gitView.integrate.cherryPickConflictDescription")}),y({kind:"conflict",state:P.state,details:P.details}),v&&typeof window<"u"&&window.localStorage.setItem(v,JSON.stringify(P.state)))}catch(P){const G=P instanceof Error?P.message:String(P);fe.error(d("gitView.integrate.failedToMoveToast"),{description:G});const X=await Jo({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);y(X?{kind:"ready",plan:X}:{kind:"idle"})}}},[m,c,t,e,b,v,d]),z=$e.useCallback(async()=>{if(m.kind==="conflict")try{await iw(m.state),fe.message(d("gitView.integrate.cherryPickAbortedToast")),v&&typeof window<"u"&&window.localStorage.removeItem(v)}finally{const P=await Jo({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);y(P?{kind:"ready",plan:P}:{kind:"idle"})}},[m,t,e,b,v,d]),T=$e.useCallback(async()=>{if(m.kind==="conflict")try{const P=await aw(m.state);if(P.kind==="success"){fe.success(d("gitView.integrate.cherryPickFinishedToast"));const G=await Jo({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);y(G?{kind:"ready",plan:G}:{kind:"idle"}),v&&typeof window<"u"&&window.localStorage.removeItem(v),c?.();return}P.kind==="conflict"&&(y({kind:"conflict",state:P.state,details:P.details}),v&&typeof window<"u"&&window.localStorage.setItem(v,JSON.stringify(P.state)))}catch(P){const G=P instanceof Error?P.message:String(P);fe.error(d("gitView.integrate.cherryPickContinueFailedToast"),{description:G})}},[m,t,e,b,c,v,d]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[l?s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(A,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:d("gitView.integrate.title")}),m.kind==="ready"&&m.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:d("gitView.integrate.toMoveCount",{count:m.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:m.kind==="loading"||m.kind==="running"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}):null,s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:d("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",b]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(Qs,{open:f,onOpenChange:p,children:[s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:xa({size:"default"}),children:[d("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:b}),s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(Ys,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(ba,{className:"h-full min-h-0",children:[s.jsx(ya,{ref:x,placeholder:d("gitView.branch.searchPlaceholder"),onKeyDown:P=>P.stopPropagation()}),s.jsxs(wa,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(va,{children:d("gitView.branch.empty")}),s.jsx(Sr,{heading:d("gitView.branch.localBranches"),children:r.map(P=>s.jsx(kr,{value:P,onSelect:()=>{S(P),D(P),p(!1)},children:P},P))})]})]})})]}),m.kind==="ready"?s.jsx(He,{size:"sm",onClick:()=>{B()},disabled:!g||m.plan.commits.length===0,children:d("gitView.integrate.move")}):m.kind==="loading"?s.jsx(He,{size:"sm",variant:"outline",disabled:!0,children:d("gitView.integrate.checking")}):m.kind==="running"?s.jsx(He,{size:"sm",variant:"outline",disabled:!0,children:d("gitView.integrate.moving")}):null]}),m.kind==="ready"&&m.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:d("gitView.integrate.noCommitsToMove")}),m.kind==="ready"&&m.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[d("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",m.plan.commits.length,")"]})]}),w.length>0&&m.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>j(P=>!P),className:"typography-micro text-muted-foreground hover:text-foreground",children:d(C?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(C?w:w.slice(0,5)).map(P=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:P.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:P.subject||P.sha})]},P.sha)),w.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:d("gitView.integrate.previewUnavailable")}),m.plan.commits.length>w.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:d("gitView.integrate.showingFirstCommits",{count:w.length})})]})]}),m.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:d("gitView.integrate.conflictsInFiles",{count:m.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[d("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:m.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[m.details.unmergedFiles.slice(0,6).map(P=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:P},P)),m.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:d("gitView.integrate.moreFiles",{count:m.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(He,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{z()},children:d("gitView.operation.abort")}),s.jsxs(He,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!u,onClick:()=>{M({state:m.state,details:m.details},!1)},children:[s.jsx(A,{name:"sparkling",className:"size-3.5"}),d("gitView.integrate.currentSession")]}),s.jsxs(He,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{M({state:m.state,details:m.details},!0)},children:[s.jsx(A,{name:"sparkling",className:"size-3.5"}),d("gitView.integrate.newSession")]}),s.jsx(He,{size:"sm",className:"typography-meta",onClick:()=>{T()},children:d("gitView.operation.continue")})]})]})]})]})},cw=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:o=!1,uncommittedFileCount:i,onChanged:c})=>{const{t:l}=ft(),[d,u]=a.useState([]),[h,f]=a.useState(!1),[p,x]=a.useState(""),[b,S]=a.useState(""),[g,m]=a.useState(null),[y,C]=a.useState({}),j=a.useCallback(async()=>{if(n){f(!0);try{const k=await mp(n);u(k.stashes),C({})}catch(k){fe.error(k instanceof Error?k.message:l("gitView.stashes.toast.loadFailed"))}finally{f(!1)}}},[n,l]);a.useEffect(()=>{t&&j()},[j,t]),a.useEffect(()=>{if(!t||!n||d.length===0)return;let k=!1;const E=d.map(O=>O.ref);return hp(n,E).then(O=>{k||C(O.counts)}).catch(()=>{}),()=>{k=!0}},[n,t,d]);const w=a.useMemo(()=>{const k=p.trim().toLowerCase();return k?d.filter(E=>`${E.ref} ${E.message} ${E.relativeTime}`.toLowerCase().includes(k)):d},[p,d]),N=a.useCallback(async k=>{await j(),await c?.(k)},[j,c]),v=async()=>{if(!(!n||g)){m("create");try{const k=await pp(n,{message:b.trim()||void 0});k.created?(fe.success(l("gitView.stashes.toast.created")),S("")):fe.info(l("gitView.stashes.toast.noChanges")),await N({affectsIndex:!!(k.created&&o)})}catch(k){fe.error(k instanceof Error?k.message:l("gitView.stashes.toast.createFailed"))}finally{m(null)}}},D=async(k,E)=>{if(!(!n||g)&&!(E==="drop"&&!window.confirm(l("gitView.stashes.confirm.drop",{ref:k.ref})))){m(`${E}:${k.ref}`);try{E==="apply"&&await gp(n,{ref:k.ref}),E==="pop"&&await xp(n,{ref:k.ref}),E==="drop"&&await bp(n,{ref:k.ref});const O=E==="apply"?"gitView.stashes.toast.applySuccess":E==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";fe.success(l(O)),await N({affectsIndex:E!=="drop"})}catch(O){const M=E==="apply"?"gitView.stashes.toast.applyFailed":E==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";fe.error(O instanceof Error?O.message:l(M)),await N({affectsIndex:E!=="drop"})}finally{m(null)}}},F=g!==null;return s.jsx(Ps,{open:t,onOpenChange:e,children:s.jsxs(Is,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(Us,{children:[s.jsxs(Ls,{className:"flex items-center gap-2",children:[s.jsx(A,{name:"archive-stack",className:"h-5 w-5"}),l("gitView.stashes.title")]}),s.jsx(Hs,{children:l("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(sr,{value:b,onChange:k=>S(k.target.value),placeholder:l("gitView.stashes.messagePlaceholder"),disabled:F||!r,className:"flex-1"}),s.jsxs(He,{onClick:v,disabled:!r||F||!n,children:[g==="create"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"inbox-archive",className:"size-4"}),l("gitView.stashes.actions.stashCurrentWithCount",{count:i})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:l("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(A,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(sr,{value:p,onChange:k=>x(k.target.value),placeholder:l("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:h?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(A,{name:"loader-4",className:"size-5 animate-spin"})}):w.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:l(p?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):w.map((k,E)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:k.message||l("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{children:E===0&&!p.trim()?l("gitView.stashes.latestLabel"):l("gitView.stashes.itemNumber",{number:E+1})})}),s.jsx(Nt,{sideOffset:6,children:k.ref})]})," · ",k.relativeTime," · ",typeof y[k.ref]=="number"?l("gitView.stashes.fileCount",{count:y[k.ref]}):l("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(Ua,{label:l("gitView.stashes.actions.apply"),loading:g===`apply:${k.ref}`,onClick:()=>D(k,"apply"),disabled:F,children:s.jsx(A,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(Ua,{label:l("gitView.stashes.actions.pop"),loading:g===`pop:${k.ref}`,onClick:()=>D(k,"pop"),disabled:F,children:s.jsx(A,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(Ua,{label:l("gitView.stashes.actions.drop"),loading:g===`drop:${k.ref}`,onClick:()=>D(k,"drop"),disabled:F,destructive:!0,children:s.jsx(A,{name:"delete-bin",className:"size-4"})})]})]},k.ref))})]})})},Ua=t=>{const e=ot.c(17),{label:n,loading:r,disabled:o,destructive:i,onClick:c,children:l}=t,d=r||void 0,u=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let h;e[0]!==u?(h=Pe("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",u),e[0]=u,e[1]=h):h=e[1];let f;e[2]!==l||e[3]!==r?(f=r?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):l,e[2]=l,e[3]=r,e[4]=f):f=e[4];let p;e[5]!==o||e[6]!==n||e[7]!==c||e[8]!==d||e[9]!==h||e[10]!==f?(p=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:h,onClick:c,disabled:o,children:f})}),e[5]=o,e[6]=n,e[7]=c,e[8]=d,e[9]=h,e[10]=f,e[11]=p):p=e[11];let x;e[12]!==n?(x=s.jsx(Nt,{sideOffset:6,children:n}),e[12]=n,e[13]=x):x=e[13];let b;return e[14]!==p||e[15]!==x?(b=s.jsxs(St,{children:[p,x]}),e[14]=p,e[15]=x,e[16]=b):b=e[16],b},dw=t=>{const e=ot.c(16),{onOpenStashes:n}=t,{t:r}=ft();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(A,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=o):o=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let c;e[3]!==i?(c=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=c):c=e[4];let l;e[5]!==r?(l=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=l):l=e[6];let d;e[7]!==l?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:l}),e[7]=l,e[8]=d):d=e[8];let u;e[9]!==n||e[10]!==r?(u=n?s.jsxs(He,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(A,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=u):u=e[11];let h;return e[12]!==c||e[13]!==d||e[14]!==u?(h=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[o,c,d,u]}),e[12]=c,e[13]=d,e[14]=u,e[15]=h):h=e[15],h},Lr=8,uw=t=>{const e=ot.c(18),{laned:n,totalLanes:r,isExpanded:o}=t,{lane:i,color:c,connectors:l}=n,u=Math.max(r,i+1)*Lr+Lr/2,h=a.useRef(null),f=a.useRef(null);let p;e[0]!==c||e[1]!==l||e[2]!==i||e[3]!==u?(p=()=>{const m=h.current,y=f.current;if(!m||!y)return;const C=m.offsetHeight;if(C===0)return;const j=window.devicePixelRatio||1;y.width=u*j,y.height=C*j;const w=y.getContext("2d");if(!w)return;w.scale(j,j),w.clearRect(0,0,u,C);const N=C/2,v=i*Lr+Lr/2,D=getComputedStyle(y),F=D.getPropertyValue("--surface-muted-foreground").trim()||D.color,k=M=>{if(!M.startsWith("var("))return M;const B=M.slice(4,-1).trim();return D.getPropertyValue(B).trim()||F},E=[...l].sort(mw);for(const M of E){const B=M.fromLane*Lr+Lr/2,z=M.toLane*Lr+Lr/2,T=M.type==="passing"?.72:M.type==="branch-out"||M.type==="merge-in"?.95:1;w.beginPath(),w.strokeStyle=k(M.color),w.globalAlpha=T,w.lineWidth=1.25,w.lineCap="round";e:switch(M.type){case"passing":case"commit-lane":{w.moveTo(B,0),w.lineTo(B,C);break e}case"top-stub":{w.moveTo(B,0),w.lineTo(B,N);break e}case"bottom-stub":{w.moveTo(B,N),w.lineTo(B,C);break e}case"branch-out":{const I=(N+C)/2;w.moveTo(v,N),w.bezierCurveTo(v,I,z,I,z,C);break e}case"merge-in":{const I=N/2;w.moveTo(B,0),w.bezierCurveTo(B,I,v,I,v,N);break e}default:continue}w.stroke(),w.globalAlpha=1}const O=D.getPropertyValue("--background").trim()||D.getPropertyValue("--surface-background").trim();w.beginPath(),w.arc(v,N,4,0,Math.PI*2),w.fillStyle=k(c),w.fill(),w.beginPath(),w.arc(v,N,5,0,Math.PI*2),w.strokeStyle=O||F,w.lineWidth=2,w.stroke()},e[0]=c,e[1]=l,e[2]=i,e[3]=u,e[4]=p):p=e[4];let x;e[5]!==c||e[6]!==l||e[7]!==o||e[8]!==i||e[9]!==n||e[10]!==r||e[11]!==u?(x=[n,i,c,l,r,o,u],e[5]=c,e[6]=l,e[7]=o,e[8]=i,e[9]=n,e[10]=r,e[11]=u,e[12]=x):x=e[12],a.useLayoutEffect(p,x);let b;e[13]!==u?(b={width:u,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=u,e[14]=b):b=e[14];let S;e[15]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx("canvas",{ref:f,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=S):S=e[15];let g;return e[16]!==b?(g=s.jsx("div",{ref:h,style:b,children:S}),e[16]=b,e[17]=g):g=e[17],g};function fw(t){return t==="branch-out"||t==="merge-in"}function mw(t,e){const n=fw;return(n(t.type)?1:0)-(n(e.type)?1:0)}const Nd=15e3,Cd=500,Ad=12,Dd=8*1024*1024,Pd=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Id=t=>{if(t.size<=Ad){let o=0;for(const i of t.values())o+=Pd(i);if(o<=Dd)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[o,i]of e){if(n.size>=Ad)continue;const c=Pd(i);r+c>Dd&&n.size>0||(n.set(o,i),r+=c)}return new Map(Array.from(n.entries()).reverse())};function Rd(t,e){const n=new Date(t);return Number.isNaN(n.getTime())?t:Hl(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function hw(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function pw(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const gw=a.memo(({entry:t,mode:e="history",laned:n,totalLanes:r,isExpanded:o,onToggle:i,files:c,isLoadingFiles:l,onCopyHash:d,directory:u,onConflict:h,onActionSuccess:f})=>{const{t:p}=ft(),x=Ee(V=>V.timeFormatPreference),b=e==="graph",[S,g]=a.useState(null),[m,y]=a.useState(!1),[C,j]=a.useState(""),[w,N]=a.useState(null),[v,D]=a.useState(new Set),[F,k]=a.useState(new Map),[E,O]=a.useState(new Set),M=async()=>{if(u){g("checkout");try{await Cp(u,t.hash),fe.success(p("gitView.history.actions.detachedHead")),f?.()}catch(V){fe.error(String(V.message))}finally{g(null)}}},B=async()=>{if(!(!u||!C.trim())){g("createBranch");try{await wp(u,C.trim(),t.hash),y(!1),j(""),f?.()}catch(V){fe.error(String(V.message))}finally{g(null)}}},z=async()=>{if(u){g("cherryPick");try{const V=await Np(u,t.hash);V.conflict?h?.({conflict:!0,conflictFiles:V.conflictFiles,operation:"cherry-pick"}):f?.()}catch(V){fe.error(String(V.message))}finally{g(null)}}},T=async()=>{if(u){g("revert");try{const V=await kp(u,t.hash);V.conflict?h?.({conflict:!0,conflictFiles:V.conflictFiles,operation:"revert"}):f?.()}catch(V){fe.error(String(V.message))}finally{g(null)}}},I=async(V,te=!1)=>{if(!(!u||S!==null)){g("reset");try{await vp(u,t.hash,V,te),f?.()}catch(Z){fe.error(String(Z.message))}finally{g(null)}}},R=async()=>{if(!w)return;const V=w;switch(N(null),V){case"checkout":return M();case"cherryPick":return z();case"revert":return T();case"merge":return L();case"rebase":return P();case"resetSoft":return I("soft");case"resetMixed":return I("mixed");case"resetHard":return I("hard",!0)}},L=async()=>{if(u){g("merge");try{const V=await Sp(u,{branch:t.hash});V.conflict?h?.({conflict:!0,conflictFiles:V.conflictFiles,operation:"merge"}):f?.()}catch(V){fe.error(String(V.message))}finally{g(null)}}},P=async()=>{if(u){g("rebase");try{const V=await jp(u,{onto:t.hash});V.conflict?h?.({conflict:!0,conflictFiles:V.conflictFiles,operation:"rebase"}):f?.()}catch(V){fe.error(String(V.message))}finally{g(null)}}},G=a.useCallback(async V=>{const te=V.path;if(!u){k(Z=>new Map(Z).set(te,"error"));return}k(Z=>Id(new Map(Z).set(te,"loading")));try{const Z=yp(u,t.hash,V.path,!1),de=new Promise((se,Q)=>{setTimeout(()=>Q(new Error(`Timed out after ${Nd}ms`)),Nd)}),Fe=await Promise.race([Z,de]);k(se=>Id(new Map(se).set(te,Fe)))}catch{k(Z=>new Map(Z).set(te,"error"))}},[u,t.hash]),X=a.useCallback(async V=>{const te=V.path;if(V.changeType==="R"||V.isBinary){D(se=>{const Q=new Set(se);return Q.has(te)?Q.delete(te):Q.add(te),Q});return}const Z=F.get(te);if(v.has(te)&&Z&&Z!=="error"){D(se=>{const Q=new Set(se);return Q.delete(te),Q});return}D(se=>{const Q=new Set(se);return Q.add(te),Q}),!(Z&&Z!=="error"||V.insertions+V.deletions>Cd&&!E.has(te))&&await G(V)},[F,E,G,v]);return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:i,className:Pe("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",b?"hover:bg-[var(--interactive-hover)]/40":o?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[b&&n&&r!==void 0?s.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:s.jsx(uw,{laned:n,totalLanes:r,isExpanded:o})}):s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[b?(()=>{const V=pw(t.refs);return V.length>0?s.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:V.map(te=>s.jsx("span",{className:Pe("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",te.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":te.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:te.label},te.label))}):null})():null,s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:t.message}),s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[s.jsx("span",{className:"truncate min-w-[3ch]",title:t.author_name,children:t.author_name}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("span",{className:"truncate min-w-0",title:Rd(t.date,x),children:Rd(t.date,x)})]}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("code",{className:"shrink-0 font-mono",children:t.hash.slice(0,8)}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:V=>{V.stopPropagation(),d(t.hash)},children:s.jsx(A,{name:"file-copy",className:"size-3"})})}),s.jsx(Nt,{sideOffset:8,children:p("gitView.history.copySha")})]})]})]})]}),o&&s.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[b&&w?s.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:p(`gitView.history.actions.${w}Confirm`)}),s.jsxs(He,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:S!==null,onClick:V=>{V.stopPropagation(),R()},children:[S!==null?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.confirmButton")]}),s.jsx(He,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:S!==null,onClick:V=>{V.stopPropagation(),N(null)},children:p("gitView.history.actions.cancelButton")})]}):b?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:V=>{V.stopPropagation(),N("checkout")},children:p("gitView.history.actions.checkout")}),m?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("input",{autoFocus:!0,value:C,onChange:V=>j(V.target.value),onKeyDown:V=>{V.key==="Enter"&&B(),V.key==="Escape"&&(y(!1),j(""))},placeholder:p("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),s.jsxs(He,{variant:"outline",size:"xs",className:"h-6",disabled:!C.trim()||S!==null,onClick:V=>{V.stopPropagation(),B()},children:[S==="createBranch"?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.createBranchConfirm")]})]}):s.jsx(He,{variant:"outline",size:"xs",className:"h-6",onClick:V=>{V.stopPropagation(),y(!0)},children:p("gitView.history.actions.createBranch")}),s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:V=>{V.stopPropagation(),N("cherryPick")},children:p("gitView.history.actions.cherryPick")}),s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:V=>{V.stopPropagation(),N("revert")},children:p("gitView.history.actions.revert")}),s.jsxs(Qs,{children:[s.jsx(qs,{asChild:!0,children:s.jsxs(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:V=>V.stopPropagation(),children:[S==="reset"?s.jsx(A,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.reset")]})}),s.jsx(Ys,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(V=>s.jsx(is,{disabled:S!==null,onSelect:te=>{te.stopPropagation(),N(`reset${V.charAt(0).toUpperCase()+V.slice(1)}`)},children:p(`gitView.history.actions.reset${V.charAt(0).toUpperCase()+V.slice(1)}`)},V))})]}),s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:V=>{V.stopPropagation(),N("merge")},children:p("gitView.history.actions.merge")}),s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:V=>{V.stopPropagation(),N("rebase")},children:p("gitView.history.actions.rebase")})]}):null,l?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p("gitView.history.loadingFiles")})]}):c.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:p("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:c.map(V=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>X(V),className:Pe("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",v.has(V.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:Pe("font-semibold w-3 text-center shrink-0",hw(V.changeType)),children:V.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:V.path,children:V.path}),!V.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",V.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",V.deletions]})]}),V.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("gitView.history.binary")}),s.jsx(A,{name:v.has(V.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),v.has(V.path)&&s.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:V.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.renamedNoDiff")}):V.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const te=V.insertions+V.deletions;if(!E.has(V.path)&&te>Cd)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:p("gitView.history.largeDiffTitle",{count:te})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(He,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{O(de=>new Set(de).add(V.path)),G(V)},children:p("gitView.history.renderDiffAnyway")})]});const Z=F.get(V.path);return Z==="loading"||Z===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):Z==="error"?s.jsx("button",{type:"button",onClick:()=>X(V),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:p("gitView.history.diffError")}):s.jsx(ec,{original:Z.original,modified:Z.modified,language:Vl(V.path)||"",fileName:V.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},V.path))})]})]})}),Md=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function Ni(t){return Md[t%Md.length]}function xw(t){if(t.length===0)return[];const e=[],n=[];for(let r=0;r<t.length;r++){const o=t[r],i=[];for(let x=0;x<e.length;x++)e[x]===o.hash&&i.push(x);let c=i.length>0?i[0]:-1;if(c===-1){const x=e.indexOf(null);x!==-1?c=x:(c=e.length,e.push(null))}const l=i.slice(1),d=Ni(c),u=e[c]===o.hash,h=o.parents.length>0;h?e[c]=o.parents[0]:e[c]=null;const f=[];for(let x=1;x<o.parents.length;x++){const b=o.parents[x],S=e.indexOf(b);if(S!==-1)f.push(S);else{const g=e.indexOf(null),m=g!==-1?g:e.length;e[m]=b,m===e.length&&e.push(b),f.push(m)}}const p=[];u&&h?p.push({fromLane:c,toLane:c,color:d,type:"commit-lane"}):u&&!h?p.push({fromLane:c,toLane:c,color:d,type:"top-stub"}):!u&&h&&p.push({fromLane:c,toLane:c,color:d,type:"bottom-stub"});for(const x of l)p.push({fromLane:x,toLane:c,color:Ni(x),type:"merge-in"}),e[x]=null;for(const x of f)p.push({fromLane:c,toLane:x,color:Ni(x),type:"branch-out"});for(let x=0;x<e.length;x++)e[x]!==null&&x!==c&&(f.includes(x)||p.push({fromLane:x,toLane:x,color:Ni(x),type:"passing"}));n.push({commit:o,lane:c,color:d,connectors:p})}return n}const bw=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],yw=t=>{const e=ot.c(84),{mode:n,log:r,isLogLoading:o,logMaxCount:i,onLogMaxCountChange:c,expandedCommitHashes:l,onToggleCommit:d,commitFilesMap:u,loadingCommitHashes:h,onCopyHash:f,directory:p,showHeader:x,contentMaxHeightClassName:b,branchDivider:S,onConflict:g,onActionSuccess:m}=t,y=n===void 0?"history":n,C=x===void 0?!0:x,j=b===void 0?"max-h-[50vh]":b,w=S===void 0?null:S,{t:N}=ft(),[v,D]=a.useState(!0),F=y==="graph";let k;e[0]!==F||e[1]!==r?(k=F&&r?xw(r.all):[],e[0]=F,e[1]=r,e[2]=k):k=e[2];const E=k;let O;e[3]!==E?(O=Math.max(1,...E.map(ww)),e[3]=E,e[4]=O):O=e[4];const M=O;let B;e[5]!==E?(B=new Map(E.map(vw)),e[5]=E,e[6]=B):B=e[6];const z=B;if(!r)return null;const T=w!==null&&w.insertBeforeIndex>0&&w.insertBeforeIndex<r.all.length,I=w!==null&&w.insertBeforeIndex===r.all.length,R=T||I;let L;e[7]!==w||e[8]!==T||e[9]!==I||e[10]!==r.all?(L=T?r.all.slice(0,w.insertBeforeIndex):I?r.all:[],e[7]=w,e[8]=T,e[9]=I,e[10]=r.all,e[11]=L):L=e[11];const P=L;let G;if(e[12]!==w||e[13]!==u||e[14]!==j||e[15]!==p||e[16]!==l||e[17]!==T||e[18]!==R||e[19]!==F||e[20]!==o||e[21]!==z||e[22]!==h||e[23]!==r.all||e[24]!==i||e[25]!==M||e[26]!==y||e[27]!==m||e[28]!==g||e[29]!==f||e[30]!==c||e[31]!==d||e[32]!==N||e[33]!==P){const xe=T?r.all.slice(w.insertBeforeIndex):[];let W;e[35]!==w?.direction?(W=w?.direction==="down"?s.jsx(A,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(A,{name:"arrow-up",className:"size-3.5"}),e[35]=w?.direction,e[36]=W):W=e[36];const J=W;let ne;e[37]!==u||e[38]!==p||e[39]!==l||e[40]!==F||e[41]!==z||e[42]!==h||e[43]!==M||e[44]!==y||e[45]!==m||e[46]!==g||e[47]!==f||e[48]!==d?(ne=we=>s.jsx("ul",{className:"divide-y divide-border/60",children:we.map(Se=>s.jsx(gw,{entry:Se,mode:y,laned:F?z.get(Se.hash):void 0,totalLanes:F?M:void 0,isExpanded:l.has(Se.hash),onToggle:()=>d(Se.hash),files:u.get(Se.hash)??[],isLoadingFiles:h.has(Se.hash),onCopyHash:f,directory:p,onConflict:g,onActionSuccess:m},Se.hash))}),e[37]=u,e[38]=p,e[39]=l,e[40]=F,e[41]=z,e[42]=h,e[43]=M,e[44]=y,e[45]=m,e[46]=g,e[47]=f,e[48]=d,e[49]=ne):ne=e[49];const oe=ne;let ue;e[50]!==o||e[51]!==r.all.length||e[52]!==i||e[53]!==c||e[54]!==N?(ue=r.all.length>=i?s.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:s.jsx(He,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(i+25),disabled:o,className:"px-3 text-muted-foreground hover:text-foreground",children:o?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(A,{name:"loader-4",className:"size-3 animate-spin"}),N("gitView.history.loadingMore")]}):N("gitView.history.loadMore")})}):null,e[50]=o,e[51]=r.all.length,e[52]=i,e[53]=c,e[54]=N,e[55]=ue):ue=e[55];const Ae=ue;G=s.jsx(On,{outerClassName:`min-h-0 ${j}`,className:"h-full w-full",children:r.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:N("gitView.history.noCommits")})}):R&&w?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-0",children:[P.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:oe(P)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:w.branchName,children:w.branchName}),J]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),xe.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:oe(xe)}):null]}),Ae]}):s.jsxs(s.Fragment,{children:[oe(r.all),Ae]})}),e[12]=w,e[13]=u,e[14]=j,e[15]=p,e[16]=l,e[17]=T,e[18]=R,e[19]=F,e[20]=o,e[21]=z,e[22]=h,e[23]=r.all,e[24]=i,e[25]=M,e[26]=y,e[27]=m,e[28]=g,e[29]=f,e[30]=c,e[31]=d,e[32]=N,e[33]=P,e[34]=G}else G=e[34];const X=G;if(!C){if(R){let W;return e[56]!==X?(W=s.jsx("section",{className:"h-full min-h-0",children:X}),e[56]=X,e[57]=W):W=e[57],W}let xe;return e[58]!==X?(xe=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:X}),e[58]=X,e[59]=xe):xe=e[59],xe}let V;e[60]!==N?(V=N("gitView.history.title"),e[60]=N,e[61]=V):V=e[61];let te;e[62]!==V?(te=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:V}),e[62]=V,e[63]=te):te=e[63];let Z;e[64]!==o||e[65]!==v||e[66]!==i||e[67]!==c||e[68]!==N?(Z=v&&s.jsx("div",{onClick:jw,onPointerDown:Sw,children:s.jsxs(xn,{value:String(i),onValueChange:xe=>c(Number(xe)),disabled:o,children:[s.jsx(bn,{size:"sm",className:"w-auto",disabled:o,children:s.jsx(rn,{placeholder:N("gitView.history.commitsPlaceholder")})}),s.jsx(yn,{children:bw.map(xe=>s.jsx(ys,{value:String(xe.value),children:N(xe.labelKey)},xe.value))})]})}),e[64]=o,e[65]=v,e[66]=i,e[67]=c,e[68]=N,e[69]=Z):Z=e[69];let de;e[70]!==v?(de=v?s.jsx(A,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(A,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=v,e[71]=de):de=e[71];let Fe;e[72]!==Z||e[73]!==de?(Fe=s.jsxs("div",{className:"flex items-center gap-2",children:[Z,de]}),e[72]=Z,e[73]=de,e[74]=Fe):Fe=e[74];let se;e[75]!==te||e[76]!==Fe?(se=s.jsxs(bi,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[te,Fe]}),e[75]=te,e[76]=Fe,e[77]=se):se=e[77];let Q;e[78]!==X?(Q=s.jsx(Oo,{children:X}),e[78]=X,e[79]=Q):Q=e[79];let Me;return e[80]!==v||e[81]!==se||e[82]!==Q?(Me=s.jsxs(Fo,{open:v,onOpenChange:D,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[se,Q]}),e[80]=v,e[81]=se,e[82]=Q,e[83]=Me):Me=e[83],Me};function ww(t){return t.lane+1}function vw(t){return[t.commit.hash,t]}function jw(t){return t.stopPropagation()}function Sw(t){return t.stopPropagation()}const kw=t=>{const e=ot.c(150),{open:n,onOpenChange:r,conflictFiles:o,directory:i,operation:c,onAbort:l,onClearState:d}=t;let u;e[0]!==o?(u=o===void 0?[]:o,e[0]=o,e[1]=u):u=e[1];const h=u,{t:f}=ft(),p=Je(Nw),x=Je(Cw),b=ao(Aw),S=ao(Dw),g=Ee(Pw),[m,y]=a.useState(!1),[C,j]=a.useState(null),[w,N]=a.useState(null);let v,D;e[2]!==i||e[3]!==n||e[4]!==f?(v=()=>{!n||!i||(y(!0),N(null),j(null),Ap(i).then(ie=>{j(ie)}).catch(ie=>{const ee=ie instanceof Error?ie.message:f("gitView.conflict.loadFailed");N(ee)}).finally(()=>{y(!1)}))},D=[n,i,f],e[2]=i,e[3]=n,e[4]=f,e[5]=v,e[6]=D):(v=e[5],D=e[6]),a.useEffect(v,D);let F;e[7]!==C||e[8]!==i||e[9]!==c?(F=async()=>{if(!C)return null;const ie=c==="merge"?"merge":"rebase",ee=C.headInfo||(c==="merge"?"MERGE_HEAD":"REBASE_HEAD"),ke=c==="merge"?"git commit --no-edit":"git rebase --continue",ae=await To("git.conflict.resolve.visible",{operation_label:ie,head_ref:ee}),U=await To("git.conflict.resolve.instructions",{operation_label:ie,directory:i,operation:c,head_info:C.headInfo||"N/A",continue_cmd:ke}),le=`${ie} conflict context (JSON)
|
|
47
|
+
${JSON.stringify({directory:i,operation:C.operation,headInfo:C.headInfo,statusPorcelain:C.statusPorcelain,unmergedFiles:C.unmergedFiles,diff:C.diff},null,2)}`;return{visibleText:ae,instructionsText:U,payloadText:le}},e[7]=C,e[8]=i,e[9]=c,e[10]=F):F=e[10];const k=F;let E;e[11]!==l||e[12]!==r?(E=()=>{l(),r(!1)},e[11]=l,e[12]=r,e[13]=E):E=e[13];const O=E;let M;e[14]!==d||e[15]!==r?(M=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=M):M=e[16];const B=M;let z;e[17]!==k||e[18]!==x||e[19]!==d||e[20]!==r||e[21]!==g||e[22]!==b||e[23]!==S||e[24]!==f?(z=async()=>{const ie=await k();if(!ie){fe.error(f("gitView.conflict.noDetailsAvailable"));return}if(!x){fe.error(f("gitView.conflict.noActiveSession"),{description:f("gitView.conflict.noActiveSessionDescription")});return}b(ie.visibleText,"replace"),S([{text:ie.instructionsText,synthetic:!0},{text:ie.payloadText,synthetic:!0}]),g("chat"),d?.(),r(!1)},e[17]=k,e[18]=x,e[19]=d,e[20]=r,e[21]=g,e[22]=b,e[23]=S,e[24]=f,e[25]=z):z=e[25];const T=z;let I;e[26]!==k||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==p||e[31]!==g||e[32]!==f?(I=async()=>{const ie=await k();if(!ie){fe.error(f("gitView.conflict.noDetailsAvailable"));return}p({directoryOverride:i,initialPrompt:ie.visibleText,syntheticParts:[{text:ie.instructionsText,synthetic:!0},{text:ie.payloadText,synthetic:!0}]}),g("chat"),d?.(),r(!1)},e[26]=k,e[27]=i,e[28]=d,e[29]=r,e[30]=p,e[31]=g,e[32]=f,e[33]=I):I=e[33];const R=I;let L,P,G,X,V,te,Z,de,Fe,se,Q,Me,xe,W,J,ne,oe,ue,Ae,we,Se,Le;if(e[34]!==C||e[35]!==h||e[36]!==x||e[37]!==O||e[38]!==B||e[39]!==T||e[40]!==R||e[41]!==m||e[42]!==w||e[43]!==r||e[44]!==n||e[45]!==c||e[46]!==f){const ie=f(c==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),ee=C?.unmergedFiles||h;G=Ps,Se=n,Le=r,P=Is,we="max-w-md w-[calc(100vw-2rem)]",W="flex flex-col gap-4 overflow-hidden";let ke;e[69]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx(A,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=ke):ke=e[69];const ae=s.jsxs("div",{className:"flex items-center gap-2",children:[ke,s.jsx(Ls,{children:f("gitView.conflict.detectedTitle",{operation:ie})})]});let U;e[70]!==c||e[71]!==f?(U=f("gitView.conflict.detectedDescription",{operation:c}),e[70]=c,e[71]=f,e[72]=U):U=e[72];let le;e[73]!==U?(le=s.jsx(Hs,{children:U}),e[73]=U,e[74]=le):le=e[74],e[75]!==ae||e[76]!==le?(J=s.jsxs(Us,{children:[ae,le]}),e[75]=ae,e[76]=le,e[77]=J):J=e[77],e[78]!==m||e[79]!==f?(ne=m&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:f("gitView.conflict.loading")})]}),e[78]=m,e[79]=f,e[80]=ne):ne=e[80],e[81]!==w||e[82]!==f?(oe=w&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:f("gitView.conflict.errorLoadingDetails",{message:w})}),e[81]=w,e[82]=f,e[83]=oe):oe=e[83],e[84]!==ee||e[85]!==f?(ue=ee.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:ee.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:ee.map(Iw)})})]}),e[84]=ee,e[85]=f,e[86]=ue):ue=e[86],e[87]!==C||e[88]!==f?(Ae=C?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:C.headInfo})]}),e[87]=C,e[88]=f,e[89]=Ae):Ae=e[89],Q="flex flex-col gap-2 pt-2";let _e;e[90]!==R?(_e=()=>{R()},e[90]=R,e[91]=_e):_e=e[91];const De=m||!C;let ce;e[92]!==m?(ce=m?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"add",className:"size-4"}),e[92]=m,e[93]=ce):ce=e[93];let he;e[94]!==f?(he=f("gitView.conflict.resolveNewSession"),e[94]=f,e[95]=he):he=e[95],e[96]!==_e||e[97]!==De||e[98]!==ce||e[99]!==he?(Me=s.jsxs(He,{variant:"default",onClick:_e,disabled:De,className:"w-full gap-2",children:[ce,he]}),e[96]=_e,e[97]=De,e[98]=ce,e[99]=he,e[100]=Me):Me=e[100];let me;e[101]!==T?(me=()=>{T()},e[101]=T,e[102]=me):me=e[102];const $=m||!C||!x;let _;e[103]!==m?(_=m?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"chat-1",className:"size-4"}),e[103]=m,e[104]=_):_=e[104];let ge;e[105]!==f?(ge=f("gitView.conflict.resolveCurrentSession"),e[105]=f,e[106]=ge):ge=e[106],e[107]!==me||e[108]!==$||e[109]!==_||e[110]!==ge?(xe=s.jsxs(He,{variant:"outline",onClick:me,disabled:$,className:"w-full gap-2",children:[_,ge]}),e[107]=me,e[108]=$,e[109]=_,e[110]=ge,e[111]=xe):xe=e[111],Fe="flex gap-2 pt-1";let Ie;e[112]!==f?(Ie=f("gitView.conflict.continueLater"),e[112]=f,e[113]=Ie):Ie=e[113],e[114]!==B||e[115]!==Ie?(se=s.jsx(He,{variant:"ghost",size:"sm",onClick:B,className:"flex-1",children:Ie}),e[114]=B,e[115]=Ie,e[116]=se):se=e[116],L=He,X="destructive",V="sm",te=O,Z="flex-1",de=f("gitView.conflict.abortOperation",{operation:ie}),e[34]=C,e[35]=h,e[36]=x,e[37]=O,e[38]=B,e[39]=T,e[40]=R,e[41]=m,e[42]=w,e[43]=r,e[44]=n,e[45]=c,e[46]=f,e[47]=L,e[48]=P,e[49]=G,e[50]=X,e[51]=V,e[52]=te,e[53]=Z,e[54]=de,e[55]=Fe,e[56]=se,e[57]=Q,e[58]=Me,e[59]=xe,e[60]=W,e[61]=J,e[62]=ne,e[63]=oe,e[64]=ue,e[65]=Ae,e[66]=we,e[67]=Se,e[68]=Le}else L=e[47],P=e[48],G=e[49],X=e[50],V=e[51],te=e[52],Z=e[53],de=e[54],Fe=e[55],se=e[56],Q=e[57],Me=e[58],xe=e[59],W=e[60],J=e[61],ne=e[62],oe=e[63],ue=e[64],Ae=e[65],we=e[66],Se=e[67],Le=e[68];let Ue;e[117]!==L||e[118]!==X||e[119]!==V||e[120]!==te||e[121]!==Z||e[122]!==de?(Ue=s.jsx(L,{variant:X,size:V,onClick:te,className:Z,children:de}),e[117]=L,e[118]=X,e[119]=V,e[120]=te,e[121]=Z,e[122]=de,e[123]=Ue):Ue=e[123];let be;e[124]!==Fe||e[125]!==se||e[126]!==Ue?(be=s.jsxs("div",{className:Fe,children:[se,Ue]}),e[124]=Fe,e[125]=se,e[126]=Ue,e[127]=be):be=e[127];let q;e[128]!==Q||e[129]!==Me||e[130]!==xe||e[131]!==be?(q=s.jsxs("div",{className:Q,children:[Me,xe,be]}),e[128]=Q,e[129]=Me,e[130]=xe,e[131]=be,e[132]=q):q=e[132];let Ne;e[133]!==W||e[134]!==J||e[135]!==ne||e[136]!==oe||e[137]!==ue||e[138]!==Ae||e[139]!==q?(Ne=s.jsxs("div",{className:W,children:[J,ne,oe,ue,Ae,q]}),e[133]=W,e[134]=J,e[135]=ne,e[136]=oe,e[137]=ue,e[138]=Ae,e[139]=q,e[140]=Ne):Ne=e[140];let je;e[141]!==P||e[142]!==we||e[143]!==Ne?(je=s.jsx(P,{className:we,children:Ne}),e[141]=P,e[142]=we,e[143]=Ne,e[144]=je):je=e[144];let ve;return e[145]!==G||e[146]!==Se||e[147]!==Le||e[148]!==je?(ve=s.jsx(G,{open:Se,onOpenChange:Le,children:je}),e[145]=G,e[146]=Se,e[147]=Le,e[148]=je,e[149]=ve):ve=e[149],ve};function Nw(t){return t.openNewSessionDraft}function Cw(t){return t.currentSessionId}function Aw(t){return t.setPendingInputText}function Dw(t){return t.setPendingSyntheticParts}function Pw(t){return t.setActiveMainTab}function Iw(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const Rw=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:o})=>{const{t:i}=ft(),[c,l]=a.useState(!0),[d,u]=a.useState(!1),h=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),f=async()=>{u(!0);try{await o(c),e(!1)}catch(x){const b=x instanceof Error?x.message:`Failed to ${n}`;fe.error(b)}finally{u(!1)}},p=()=>{d||e(!1)};return s.jsx(Ps,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(Is,{className:"max-w-md",children:[s.jsxs(Us,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(Ls,{children:i("gitView.stash.title")})]}),s.jsx(Hs,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),c&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(oo,{checked:c,onChange:l,disabled:d,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&l(!c),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(rr,{className:"gap-2",children:[s.jsx(He,{variant:"ghost",size:"sm",onClick:p,disabled:d,children:i("gitView.common.cancel")}),s.jsx(He,{variant:"default",size:"sm",onClick:f,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:h})})]})]})})},Mw=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:o,conflictCount:i=0,isLoading:c=!1})=>{const{t:l}=ft(),[d,u]=a.useState(null),h=t&&t.head,f=e&&(e.headName||e.onto),p=h?"merge":f?"rebase":null;if(!p)return null;const x=async()=>{u("continue");try{await n()}finally{u(null)}},b=async()=>{u("abort");try{await r()}finally{u(null)}},S=d!==null,g=i>0,m=l(p==="merge"?"gitView.operation.merge":"gitView.operation.rebase");let y="";t?y=t.message?l("gitView.operation.mergingMessage",{message:t.message}):l("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(y=e.headName?l("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):l("gitView.operation.rebaseInProgress"));const C=g?i===1?l("gitView.operation.inProgressTitleOneConflict",{operation:m,count:i}):l("gitView.operation.inProgressTitleManyConflicts",{operation:m,count:i}):l("gitView.operation.inProgressTitle",{operation:m}),j=l(g?"gitView.operation.resolveConflictsHint":"gitView.operation.readyToContinueHint");return s.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:s.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:C}),y&&s.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:y})]}),s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[s.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:j}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[s.jsxs(He,{variant:"ghost",size:"sm",onClick:b,disabled:S||c,className:"gap-1.5",children:[d==="abort"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"close",className:"size-4"}),l("gitView.operation.abort")]}),g?o&&s.jsx(He,{variant:"default",size:"sm",onClick:o,disabled:S||c,children:l("gitView.operation.resolveWithAi")}):s.jsxs(He,{variant:"default",size:"sm",onClick:x,disabled:S||c,className:"gap-1.5",children:[d==="continue"?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"check",className:"size-4"}),l("gitView.operation.continue")]})]})]})]})})},Tw=t=>{const e=ot.c(104),{currentBranch:n,localBranches:r,remoteBranches:o,onMerge:i,onRebase:c,disabled:l,isOperating:d,operationLogs:u,onOperationComplete:h,mode:f,defaultTargetBranch:p}=t,x=l===void 0?!1:l,b=d===void 0?!1:d,S=u===void 0?[]:u,g=f===void 0?"dialog":f,{t:m}=ft(),[y,C]=a.useState(!1),[j,w]=a.useState("merge"),[N,v]=a.useState(null),[D,F]=a.useState(!1),[k,E]=a.useState(""),O=a.useRef(null),M=a.useRef(null),B=x||b,z=n||m("gitView.branch.currentBranchFallback"),T=S.length>0&&S.every(Ew),I=S.some(Fw);let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},e[0]=R):R=e[0],a.useEffect(R,[S]);let L;if(e[1]!==k||e[2]!==n||e[3]!==r||e[4]!==o){e:{const me=k.toLowerCase();let $;e[6]!==o?($=new Set(o.map(Ow).filter(Boolean)),e[6]=o,e[7]=$):$=e[7];const _=$;let ge;e[8]!==n||e[9]!==_?(ge=Re=>Re!==n&&!_.has(Re),e[8]=n,e[9]=_,e[10]=ge):ge=e[10];const Ie=r.filter(ge);if(!me){L=Ie;break e}L=Ie.filter(Re=>Re.toLowerCase().includes(me))}e[1]=k,e[2]=n,e[3]=r,e[4]=o,e[5]=L}else L=e[5];const P=L;let G;if(e[11]!==k||e[12]!==o){e:{const me=k.toLowerCase();if(!me){G=o;break e}G=o.filter($=>$.toLowerCase().includes(me))}e[11]=k,e[12]=o,e[13]=G}else G=e[13];const X=G;let V;e[14]!==p||e[15]!==r||e[16]!==o?(V=()=>p&&(o.includes(p)||r.includes(p))?p:null,e[14]=p,e[15]=r,e[16]=o,e[17]=V):V=e[17];const te=V;let Z;e[18]!==te||e[19]!==C?(Z=()=>{C(!0),v(te()),w("merge"),E("")},e[18]=te,e[19]=C,e[20]=Z):Z=e[20];const de=Z;let Fe;e[21]===Symbol.for("react.memo_cache_sentinel")?(Fe=me=>{v(me),F(!1),E("")},e[21]=Fe):Fe=e[21];const se=Fe;let Q;e[22]!==i||e[23]!==c||e[24]!==j||e[25]!==N?(Q=()=>{N&&(j==="merge"?i(N):c(N))},e[22]=i,e[23]=c,e[24]=j,e[25]=N,e[26]=Q):Q=e[26];const Me=Q;let xe;e[27]!==b||e[28]!==C?(xe=()=>{b||(v(null),w("merge"),E(""),C(!1))},e[27]=b,e[28]=C,e[29]=xe):xe=e[29];const W=xe,J=()=>{b&&!T||(T&&h?.(),v(null),w("merge"),E(""),C(!1))};let ne,oe;e[30]!==D?(ne=()=>{D||E("")},oe=[D],e[30]=D,e[31]=ne,e[32]=oe):(ne=e[31],oe=e[32]),a.useEffect(ne,oe);let ue,Ae;e[33]!==g||e[34]!==te||e[35]!==N?(ue=()=>{g==="dialog"||N||v(te())},Ae=[g,te,N],e[33]=g,e[34]=te,e[35]=N,e[36]=ue,e[37]=Ae):(ue=e[36],Ae=e[37]),a.useEffect(ue,Ae);const Le=b?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:M,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:S.map(Lw)})}),T?g==="dialog"?s.jsx(rr,{children:s.jsx(He,{variant:"default",size:"sm",onClick:J,children:m(I?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(He,{variant:"default",size:"sm",onClick:J,children:m(I?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:m("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>w("merge"),className:Pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",j==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-merge",className:Pe("size-4",j==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Pe("typography-ui-label",j==="merge"?"text-foreground":"text-muted-foreground"),children:m("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:m("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>w("rebase"),className:Pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",j==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{name:"git-branch",className:Pe("size-4",j==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:Pe("typography-ui-label",j==="rebase"?"text-foreground":"text-muted-foreground"),children:m("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:m("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:j==="merge"?m("gitView.branch.branchToMergeInto",{branch:z}):m("gitView.branch.branchToRebaseOnto")}),s.jsxs(Qs,{open:D,onOpenChange:F,modal:!1,children:[s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:Pe(xa({size:"default"}),"w-full"),children:[s.jsx("span",{className:Pe("truncate",!N&&"text-muted-foreground"),children:N||m("gitView.branch.selectBranch")}),s.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Ys,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(ba,{className:"h-full min-h-0",children:[s.jsx(ya,{ref:O,placeholder:m("gitView.branch.searchPlaceholder"),value:k,onValueChange:E,onKeyDown:Bw}),s.jsxs(wa,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(va,{children:m("gitView.branch.empty")}),P.length>0&&s.jsx(Sr,{heading:m("gitView.branch.localBranches"),children:P.map(me=>s.jsx(kr,{onSelect:()=>se(me),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:me})},`local-${me}`))}),P.length>0&&X.length>0?s.jsx(Dp,{}):null,X.length>0&&s.jsx(Sr,{heading:m("gitView.branch.remoteBranches"),children:X.map(me=>s.jsx(kr,{onSelect:()=>se(me),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:me})},`remote-${me}`))})]})]})})]})]}),N?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:j==="merge"?s.jsxs(s.Fragment,{children:[m("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:N})," ",m("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:z})]}):s.jsxs(s.Fragment,{children:[m("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:z})," ",m("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:N})]})})}):null,g==="dialog"?s.jsxs(rr,{className:"gap-2 pt-1",children:[s.jsx(He,{variant:"ghost",size:"sm",onClick:W,children:m("gitView.common.cancel")}),s.jsx(He,{variant:"default",size:"sm",onClick:Me,disabled:!N,className:"gap-1.5",children:j==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-merge",className:"size-4"}),m("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"git-branch",className:"size-4"}),m("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(He,{variant:"destructive",size:"sm",onClick:W,disabled:B,children:m("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(He,{variant:"default",size:"sm",onClick:Me,disabled:B||!N,children:m(j==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(g==="bare")return Le;if(g==="inline"){let me;e[38]!==m?(me=m("gitView.branch.updateTitle"),e[38]=m,e[39]=me):me=e[39];let $;e[40]!==me?($=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:me}),e[40]=me,e[41]=$):$=e[41];let _;e[42]!==m?(_=m("gitView.branch.updateDescriptionPrefix"),e[42]=m,e[43]=_):_=e[43];let ge;e[44]!==z?(ge=s.jsx("span",{className:"font-mono text-foreground",children:z}),e[44]=z,e[45]=ge):ge=e[45];let Ie;e[46]!==_||e[47]!==ge?(Ie=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[_," ",ge,"."]}),e[46]=_,e[47]=ge,e[48]=Ie):Ie=e[48];let Re;e[49]!==$||e[50]!==Ie?(Re=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[$,Ie]})}),e[49]=$,e[50]=Ie,e[51]=Re):Re=e[51];let Ke;e[52]!==Le?(Ke=s.jsx("div",{className:"pt-3",children:Le}),e[52]=Le,e[53]=Ke):Ke=e[53];let nt;return e[54]!==Re||e[55]!==Ke?(nt=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Re,Ke]}),e[54]=Re,e[55]=Ke,e[56]=nt):nt=e[56],nt}let Ue;e[57]!==b?(Ue=b?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-merge",className:"size-4"}),e[57]=b,e[58]=Ue):Ue=e[58];let be;e[59]!==m?(be=m("gitView.branch.mergeRebase"),e[59]=m,e[60]=be):be=e[60];let q;e[61]!==be?(q=s.jsx("span",{children:be}),e[61]=be,e[62]=q):q=e[62];let Ne;e[63]!==de||e[64]!==B||e[65]!==Ue||e[66]!==q?(Ne=s.jsx(kt,{asChild:!0,children:s.jsxs(He,{variant:"outline",size:"sm",className:"gap-1.5",onClick:de,disabled:B,children:[Ue,q]})}),e[63]=de,e[64]=B,e[65]=Ue,e[66]=q,e[67]=Ne):Ne=e[67];let je;e[68]!==m?(je=m("gitView.branch.mergeRebaseTooltip"),e[68]=m,e[69]=je):je=e[69];let ve;e[70]!==je?(ve=s.jsx(Nt,{sideOffset:8,children:je}),e[70]=je,e[71]=ve):ve=e[71];let ie;e[72]!==Ne||e[73]!==ve?(ie=s.jsxs(St,{children:[Ne,ve]}),e[72]=Ne,e[73]=ve,e[74]=ie):ie=e[74];let ee;e[75]!==J||e[76]!==C?(ee=me=>{me?C(!0):J()},e[75]=J,e[76]=C,e[77]=ee):ee=e[77];let ke;e[78]!==m?(ke=m("gitView.branch.updateTitle"),e[78]=m,e[79]=ke):ke=e[79];let ae;e[80]!==ke?(ae=s.jsx(Ls,{children:ke}),e[80]=ke,e[81]=ae):ae=e[81];let U;e[82]!==I||e[83]!==b||e[84]!==j||e[85]!==T||e[86]!==m||e[87]!==z?(U=b?m(T?I?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":j==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[m("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:z}),"."]}),e[82]=I,e[83]=b,e[84]=j,e[85]=T,e[86]=m,e[87]=z,e[88]=U):U=e[88];let le;e[89]!==U?(le=s.jsx(Hs,{children:U}),e[89]=U,e[90]=le):le=e[90];let _e;e[91]!==ae||e[92]!==le?(_e=s.jsxs(Us,{children:[ae,le]}),e[91]=ae,e[92]=le,e[93]=_e):_e=e[93];let De;e[94]!==Le||e[95]!==_e?(De=s.jsxs(Is,{className:"max-w-md",children:[_e,Le]}),e[94]=Le,e[95]=_e,e[96]=De):De=e[96];let ce;e[97]!==y||e[98]!==ee||e[99]!==De?(ce=s.jsx(Ps,{open:y,onOpenChange:ee,children:De}),e[97]=y,e[98]=ee,e[99]=De,e[100]=ce):ce=e[100];let he;return e[101]!==ie||e[102]!==ce?(he=s.jsxs(s.Fragment,{children:[ie,ce]}),e[101]=ie,e[102]=ce,e[103]=he):he=e[103],he};function Ew(t){return t.status==="done"||t.status==="error"}function Fw(t){return t.status==="error"}function Ow(t){return t.slice(t.indexOf("/")+1)}function Lw(t,e){return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"mt-0.5 shrink-0",children:[t.status==="running"&&s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(A,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(A,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:Pe("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function Bw(t){return t.stopPropagation()}const lc=t=>{const{remoteNames:e,localBranches:n,worktreeCreatedFromBranch:r,rootBranchHint:o}=t,i=d=>{if(!d)return"";let u=d.trim();if(!u||u==="HEAD")return"";if(n.includes(u))return u;u.startsWith("refs/heads/")&&(u=u.slice(11)),u.startsWith("heads/")&&(u=u.slice(6)),u.startsWith("remotes/")&&(u=u.slice(8));const h=u.indexOf("/");if(h>0){const f=u.slice(0,h);if(e.has(f)){const p=u.slice(h+1).trim();p&&(u=p)}}return u},c=i(typeof r=="string"?r:"");if(c)return c;const l=i(typeof o=="string"?o:"");return l||(n.includes("main")?"main":n.includes("master")?"master":n.includes("develop")?"develop":"main")},$w=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:o})=>{const i=[];let c=!1;return{enqueue:d=>{const u=i[i.length-1];if(u?.directory===d.directory&&u.direction===d.direction){d.paths.forEach(h=>u.paths.add(h));return}i.push(d)},flush:()=>{if(c)return;const d=i.shift();if(!d)return;c=!0;const u={directory:d.directory,direction:d.direction,paths:Array.from(d.paths),rollback:d.rollback};(async()=>{try{await t(u),e(u)}catch(h){n(u,h)}finally{r(u.paths),c=!1,i.length>0&&o()}})()},clear:()=>{i.length=0},size:()=>i.length,isRunning:()=>c}},_w=15e3,zw=40,Vw=20,Td={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Ww=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,o=n.match(r);if(o){const l=o[1],d=Td[l];if(d)return e.find(u=>u.code===d)||null}const i=n.split(" ")[0],c=Td[i];return c&&e.find(l=>l.code===c)||null},Uw=20,vo=new Map,Hw=(t,e)=>{if(vo.delete(t),vo.set(t,e),vo.size>Uw){const n=vo.keys().next().value;n!==void 0&&vo.delete(n)}},wr=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Ed=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Kw=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},kl=({isActive:t})=>{const{t:e}=ft(),{git:n}=_n(),r=Wr(),[o,i]=a.useState(null),[c,l]=a.useState(!1),d=Je(K=>K.currentSessionId),u=Je(K=>K.newSessionDraft),h=Je(K=>K.setDraftBootstrapPendingDirectory),f=Je(K=>K.worktreeMetadata),p=Je(K=>K.availableWorktrees),x=wr(r),b=a.useMemo(()=>{if(!x)return;const K=p.find(ye=>wr(ye.path)===x);if(K)return K;for(const ye of f.values())if(wr(ye.path)===x)return ye},[p,x,f]),S=a.useMemo(()=>{if(d)return f.get(d)??b;if(u?.open)return b},[d,b,u?.open,f]),{profiles:g,globalIdentity:m,defaultGitIdentityId:y,loadProfiles:C,loadGlobalIdentity:j,loadDefaultGitIdentityId:w}=px(er(K=>({profiles:K.profiles,globalIdentity:K.globalIdentity,defaultGitIdentityId:K.defaultGitIdentityId,loadProfiles:K.loadProfiles,loadGlobalIdentity:K.loadGlobalIdentity,loadDefaultGitIdentityId:K.loadDefaultGitIdentityId}))),N=Wl(r??null),v=_o(r??null),D=$l(K=>d?K.getAttachment(d):void 0),F=D?Pp(D):[],k=D&&!D.degraded&&!D.legacy?D.worktreeRoot??void 0:void 0,E=xm(r,S,v?.current??void 0),O=ja(r??null),M=Ip(r??null),B=Rp(r??null),z=Ul(r??null),T=Mp(r??null),{setActiveDirectory:I,fetchAll:R,ensureAll:L,fetchStatus:P,fetchBranches:G,fetchLog:X,setLogMaxCount:V,fetchIdentity:te,prefetchDiffs:Z,clearDiffCache:de,moveStatusPathsOptimistically:Fe,restoreStatus:se,bumpIndexRevision:Q}=nn(er(K=>({setActiveDirectory:K.setActiveDirectory,fetchAll:K.fetchAll,ensureAll:K.ensureAll,fetchStatus:K.fetchStatus,fetchBranches:K.fetchBranches,fetchLog:K.fetchLog,setLogMaxCount:K.setLogMaxCount,fetchIdentity:K.fetchIdentity,prefetchDiffs:K.prefetchDiffs,clearDiffCache:K.clearDiffCache,moveStatusPathsOptimistically:K.moveStatusPathsOptimistically,restoreStatus:K.restoreStatus,bumpIndexRevision:K.bumpIndexRevision}))),Me=Ee(K=>K.isMobile),xe=Ee(K=>K.openContextDiff),W=Ee(K=>K.openContextSurface),J=v?.current??null,ne=sn(K=>!r||!J?null:If(K.entries,r,J)),oe=Ee(K=>K.navigateToDiff),ue=a.useRef(null),Ae=a.useRef(null),we=a.useRef(null),Se=a.useRef(null),Le=a.useRef(!0);a.useEffect(()=>()=>{Le.current=!1},[]);const Ue=a.useCallback(()=>{Ae.current!==null&&(window.clearTimeout(Ae.current),Ae.current=null)},[]),be=a.useCallback(K=>{Ue(),Ae.current=window.setTimeout(()=>{Ae.current=null,wr(K)===wr(r)&&P(K,n,{silent:!0})},_w)},[Ue,r,P,n]);a.useEffect(()=>Ue,[Ue]);const q=a.useCallback(()=>{we.current!==null&&(window.clearTimeout(we.current),we.current=null)},[]),Ne=a.useCallback(()=>{we.current===null&&(we.current=window.setTimeout(()=>{we.current=null,Se.current?.()},0))},[]),je=a.useCallback(async(K,ye,Ce)=>{if(ye==="stage"){if(n.stageGitFiles){await n.stageGitFiles(K,Ce);return}await Promise.all(Ce.map(Ve=>n.stageGitFile(K,Ve)));return}if(n.unstageGitFiles){await n.unstageGitFiles(K,Ce);return}await Promise.all(Ce.map(Ve=>n.unstageGitFile(K,Ve)))},[n]),ve=a.useMemo(()=>$w({runMutation:({directory:K,direction:ye,paths:Ce})=>je(K,ye,Ce),onMutationComplete:({directory:K})=>{Q(K),be(K)},onMutationError:({directory:K,direction:ye,rollback:Ce},Ve)=>{Ce?.(),Q(K),be(K);const dt=e(ye==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");fe.error(Ve instanceof Error?Ve.message:dt)},onPathsComplete:K=>{pt(ye=>{const Ce=new Set(ye);return K.forEach(Ve=>Ce.delete(Ve)),Ce})},scheduleFlush:Ne}),[Q,je,Ne,be,e]);a.useEffect(()=>(Se.current=ve.flush,()=>{Se.current=null}),[ve]),a.useEffect(()=>()=>ve.clear(),[ve]),a.useEffect(()=>q,[q]),a.useEffect(()=>{if(!t)return;if(!r){i(null),l(!1);return}let K=!1,ye=null;const Ce=async()=>{try{const Ve=await Ep(r);if(K)return;i(Ve.status),Ve.status==="pending"&&(ye=window.setTimeout(()=>{Ce()},500))}catch{K||i(null)}};return Ce(),()=>{K=!0,ye!==null&&window.clearTimeout(ye)}},[t,r]),a.useEffect(()=>{const K=ue.current;ue.current=o,!(!r||!n)&&(K==="pending"&&o==="ready"&&(l(!0),R(r,n).finally(()=>{window.setTimeout(()=>{l(!1)},1200)})),o==="failed"&&(h(null),l(!1)))},[r,R,n,h,o]);const ie=wr(u?.bootstrapPendingDirectory??null),ee=!!(r&&ie&&ie===wr(r)),ae=!!(r&&(o==="pending"||ee))||c,U=a.useMemo(()=>r?vo.get(r)??null:null,[r]),le=rs(K=>K.settingsGitmojiEnabled),[_e,De]=a.useState(null),{gitmojis:ce}=tw(le);a.useEffect(()=>{const K=k||E?.projectDirectory;if(!K){De(null);return}let ye=!1;return gi(K).then(Ce=>{if(ye)return;const Ve=Ce.trim();De(Ve&&Ve!=="HEAD"?Ve:null)}).catch(()=>{ye||De(null)}),()=>{ye=!0}},[k,E?.projectDirectory]);const[he,me]=a.useState(U?.commitMessage??""),[$,_]=a.useState([]),[ge,Ie]=a.useState(!1),Re=a.useRef(null),[Ke,nt]=a.useState(null),[ct,mt]=a.useState(!1),[gt,ht]=a.useState(null),[wt,bt]=a.useState(25),[yt,Dt]=a.useState(!1),{triggerFireworks:Kt}=Xy(),Ut=a.useRef(new Map),Lt=a.useRef(0),Bt=a.useCallback(()=>{Lt.current+=1,Le.current&&Dt(!0)},[]),et=a.useCallback(()=>{Lt.current=Math.max(0,Lt.current-1),Le.current&&Lt.current===0&&Dt(!1)},[]),[Ht,It]=a.useState(new Set),[We,pt]=a.useState(new Set),[Mt,Et]=a.useState(!1),[tt,pe]=a.useState(0),[Oe,Te]=a.useState(!1),[it,ut]=a.useState(U?.generatedHighlights??[]),Gt=We.size>0||ve.size()>0||ve.isRunning(),Ft=a.useCallback(()=>{const K=Re.current;K&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{K.scrollTo({top:K.scrollHeight,behavior:"smooth"})})})},[]),ze=k||E?.projectDirectory||null,Qe=v?.current||null,st=a.useMemo(()=>{const K=v?.tracking;return K?K.startsWith("origin/"):!0},[v?.tracking]),at=a.useMemo(()=>{const K=E?.createdFromBranch,ye=typeof K=="string"?K.trim():"",Ce=typeof v?.current=="string"?v.current.trim():"",Ve=typeof _e=="string"?_e.trim():"";return ye?ye===Ce&&ye.startsWith("opencode/")&&Ve.length>0&&Ve!==ye?Ve:ye:Ve||Ce||"HEAD"},[E?.createdFromBranch,v,_e]),Ze=a.useCallback(()=>{ut([])},[]),[At,Rt]=a.useState(new Set),[Zt,fs]=a.useState(new Map),[ls,Ot]=a.useState(new Set),$t=a.useRef(Zt),Pt=a.useRef(ls),[ms,Ks]=a.useState(null),[Yt,ws]=a.useState(null),[Xs,An]=a.useState(""),[ts,Js]=a.useState(null),[or,zn]=a.useState(!1),[dn,un]=a.useState(!1),[wn,Bs]=a.useState([]),[Fs,fn]=a.useState(null),[Dn,on]=a.useState(null),[fr,Pn]=a.useState([]),[Pr,js]=a.useState(!1),[re,qe]=a.useState([]),[lt,xt]=a.useState("merge"),[qt,Tt]=a.useState(null),[Ct,xs]=a.useState(!1),[As,as]=a.useState(100),[Ss,Rs]=a.useState(0),Os=a.useMemo(()=>d?`openchamber.conflict:${d}`:null,[d]),ks=a.useCallback((K,ye,Ce)=>{if(!Os||typeof window>"u")return;const Ve={directory:K,conflictFiles:ye,operation:Ce};window.localStorage.setItem(Os,JSON.stringify(Ve))},[Os]),Be=a.useCallback(()=>{!Os||typeof window>"u"||window.localStorage.removeItem(Os)},[Os]);a.useEffect(()=>{if(!Os||typeof window>"u"||!r)return;const K=window.localStorage.getItem(Os);if(K)try{const ye=JSON.parse(K);if(ye.directory!==r){window.localStorage.removeItem(Os);return}qe(ye.conflictFiles??[]),xt(ye.operation??"merge"),js(!0)}catch{window.localStorage.removeItem(Os)}},[Os,r]);const[Wt,ss]=a.useState(!1),[hs,Ns]=a.useState("merge"),[Ds,$s]=a.useState(""),Zs=a.useCallback(K=>{tr(K).then(ye=>{if(ye.ok){fe.success(e("gitView.toast.commitHashCopied"));return}fe.error(e("gitView.toast.copyFailed"))})},[e]),an=a.useCallback(K=>{Rt(ye=>{const Ce=new Set(ye);return Ce.has(K)?Ce.delete(K):Ce.add(K),Ce})},[]);a.useEffect(()=>{$t.current=Zt},[Zt]),a.useEffect(()=>{Pt.current=ls},[ls]),a.useEffect(()=>{if(!r||!n)return;const K=Array.from(At).filter(Ce=>!$t.current.has(Ce)&&!Pt.current.has(Ce));if(K.length===0)return;let ye=!1;return Ot(Ce=>{const Ve=new Set(Ce);for(const dt of K)Ve.add(dt);return Pt.current=Ve,Ve}),Promise.all(K.map(Ce=>n.getCommitFiles(r,Ce).then(Ve=>({hash:Ce,files:Ve.files})).catch(Ve=>(console.error("Failed to fetch commit files:",Ve),{hash:Ce,files:[]})))).then(Ce=>{ye||(fs(Ve=>{const dt=new Map(Ve);for(const{hash:Vt,files:ps}of Ce)dt.set(Vt,ps);return $t.current=dt,dt}),Ot(Ve=>{const dt=new Set(Ve);for(const{hash:Vt}of Ce)dt.delete(Vt);return Pt.current=dt,dt}))}),()=>{ye=!0,Ot(Ce=>{let Ve=!1;const dt=new Set(Ce);for(const Vt of K)dt.delete(Vt)&&(Ve=!0);return Ve?(Pt.current=dt,dt):Ce})}},[At,r,n]),a.useEffect(()=>{r&&Hw(r,{directory:r,commitMessage:he,generatedHighlights:it})},[he,r,it]),a.useEffect(()=>{t&&(C(),j(),w())},[t,C,j,w]),a.useEffect(()=>{if(!t)return;if(!r||!n?.getRemoteUrl){ws(null);return}let K=!1;return n.getRemoteUrl(r).then(ye=>{K||ws(ye)}).catch(()=>{K||ws(null)}),()=>{K=!0}},[t,r,n]);const Vn=a.useCallback(async()=>{if(!r||!n?.getRemotes){Bs([]);return}try{const K=await n.getRemotes(r);Le.current&&Bs(K)}catch{Le.current&&Bs([])}},[r,n]);a.useEffect(()=>{t&&Vn()},[t,Vn]),a.useEffect(()=>{t&&r&&(I(r),L(r,n))},[t,r,I,L,n]),a.useEffect(()=>{if(t&&r)return Gn.onGitRefreshHint(K=>{wr(K.directory)===wr(r)&&(K.paths?.length&&de(r,K.paths),P(r,n,{silent:!0}))})},[t,de,r,P,n]);const zt=a.useCallback(async(K=!0)=>{if(r)try{await Promise.all([P(r,n),G(r,n)])}catch(ye){if(K){const Ce=ye instanceof Error?ye.message:e("gitView.toast.refreshRepositoryFailed");fe.error(Ce)}}},[r,n,P,G,e]),Xt=a.useCallback(async()=>{r&&await X(r,n,wt)},[r,n,X,wt]),mn=a.useCallback(async()=>{r&&await te(r,n)},[r,n,te]);a.useEffect(()=>{if(!t||!r||!n?.hasLocalIdentity||N!==!0)return;const K=typeof y=="string"?y.trim():"";if(!K||K==="global"||Ut.current.get(r)===K)return;let Ce=!1;return(async()=>{try{const dt=await n.hasLocalIdentity?.(r);if(Ce||dt===!0)return;Bt(),await n.setGitIdentity(r,K),Ut.current.set(r,K),await mn()}catch(dt){console.warn("Failed to auto-apply default git identity:",dt)}finally{Ce||et()}})(),()=>{Ce=!0}},[t,Bt,r,y,et,n,N,mn]);const In=a.useMemo(()=>v?[...v.files??[]].sort((ye,Ce)=>ye.path.localeCompare(Ce.path)):[],[v]),_s=a.useMemo(()=>In.filter(Ed),[In]),ir=a.useMemo(()=>In.filter(Kw),[In]);a.useEffect(()=>{if(!r||In.length===0)return;const K=[],ye=new Set,Ce=dt=>{!dt||ye.has(dt)||(ye.add(dt),K.push(dt))};if(_s.forEach(dt=>Ce(dt.path)),$.forEach(Ce),In.slice(0,Vw).forEach(dt=>Ce(dt.path)),K.length===0)return;const Ve=window.setTimeout(()=>{Z(r,n,K,{maxFiles:zw})},120);return()=>{window.clearTimeout(Ve)}},[In,r,n,Z,_s,$]);const Ir=K=>K?.pushed[0]?.remote||v?.tracking?.split("/")[0]||zs.find(ye=>ye.name==="origin")?.name||zs[0]?.name||"origin",co=async(K,ye)=>{if(r){nt(K);try{const Ce=Ve=>{const dt=`${Ve.name}/`,Vt=v?.tracking?.startsWith(dt)?v.tracking.slice(dt.length):void 0;return{remote:Ve.name,branch:Vt,rebase:!0}};if(K==="fetch"){if(!ye)throw new Error("No remote available for fetch");await n.gitFetch(r,{remote:ye.name}),fe.success(e("gitView.toast.fetchedFromRemote",{name:ye.name}))}else if(K==="pull"){if(!ye)throw new Error("No remote available for pull");const Ve=await n.gitPull(r,Ce(ye));fe.success(Ve.files.length===1?e("gitView.toast.pulledFilesSingle",{count:Ve.files.length,name:ye.name}):e("gitView.toast.pulledFilesPlural",{count:Ve.files.length,name:ye.name}))}else if(K==="push"){const Ve=await n.gitPush(r);fe.success(e("gitView.toast.pushedToUpstream",{name:Ir(Ve)}))}else if(K==="sync"){if(!ye)throw new Error("No remote available for sync");let Ve=0,dt=!1;await n.gitFetch(r,{remote:ye.name});const Vt=await n.getGitStatus(r);if((Vt.behind??0)>0){if((Vt.files?.length??0)>0){fe.error(e("gitView.toast.commitOrStashBeforeSync"));return}Ve=(await n.gitPull(r,Ce(ye))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),dt=!0),Ve>0&&dt?fe.success(Ve===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:Ve,name:ye.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:Ve,name:ye.name})):Ve>0?fe.success(Ve===1?e("gitView.toast.pulledFilesSingle",{count:Ve,name:ye.name}):e("gitView.toast.pulledFilesPlural",{count:Ve,name:ye.name})):dt?fe.success(e("gitView.toast.pushedToUpstream",{name:ye.name})):fe.success(e("gitView.toast.alreadyUpToDate"))}await zt(!1),await Xt()}catch(Ce){const Ve=Ce instanceof Error?Ce.message:e("gitView.toast.syncActionFailed",{action:K==="sync"?e("gitView.sync.syncChanges"):K==="pull"?e("gitView.sync.pull"):K});fe.error(Ve)}finally{nt(null)}}},Uo=a.useCallback(async K=>{if(!r)return;const ye=K.name.trim();if(!ye){fe.error(e("gitView.toast.remoteNameRequired"));return}if(ye==="origin"){fe.error(e("gitView.toast.cannotRemoveOriginRemote"));return}fn(ye);try{await n.removeRemote(r,{remote:ye}),fe.success(e("gitView.toast.removedRemote",{name:ye})),await Promise.all([zt(!1),Vn()])}catch(Ce){const Ve=Ce instanceof Error?Ce.message:`Failed to remove ${ye}`;fe.error(Ve)}finally{fn(null)}},[r,n,Vn,zt,e]),Rr=async(K={})=>{if(!r)return;if(!he.trim()){fe.error(e("gitView.toast.enterCommitMessage"));return}const ye=_s.map(Ve=>Ve.path).sort();if(ye.length===0){fe.error(e("gitView.toast.stageFileToCommit"));return}const Ce=K.pushAfter?"commitAndPush":"commit";ht(Ce);try{if(await n.createGitCommit(r,he.trim(),{files:ye,stageFiles:[]}),Q(r),fe.success(e("gitView.toast.commitCreated")),me(""),Ze(),await zt(),K.pushAfter){const Ve=v?.tracking?.split("/")[0],dt=zs.find(xo=>xo.name===Ve)??zs[0];if(!dt)throw new Error(e("mobile.changes.noRemote"));nt("sync");const Vt=`${dt.name}/`,ps=v?.tracking?.startsWith(Vt)?v.tracking.slice(Vt.length):void 0;await n.gitFetch(r,{remote:dt.name});const Qt=await n.getGitStatus(r);if((Qt.behind??0)>0){if((Qt.files?.length??0)>0){fe.error(e("gitView.toast.commitOrStashBeforeSync")),await zt(!1);return}await n.gitPull(r,{remote:dt.name,branch:ps,rebase:!0})}const en=await n.getGitStatus(r);let cr;(en.ahead??0)>0&&(cr=await n.gitPush(r)),fe.success(e("gitView.toast.pushedToUpstream",{name:Ir(cr)})),Kt(),await zt(!1)}else await zt(!1);await Xt(),pe(Ve=>Ve+1)}catch(Ve){const dt=Ve instanceof Error?Ve.message:e("gitView.toast.createCommitFailed");fe.error(dt)}finally{ht(null),K.pushAfter&&nt(null)}},uo=a.useCallback(async()=>{if(!r)return;const K=_s.map(ye=>ye.path).sort();if(K.length===0){fe.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:K.length}),Te(!0);try{const{message:ye}=await Tp(r,K),Ce=ye.subject?.trim()??"",Ve=Array.isArray(ye.highlights)?ye.highlights:[];if(Ce){let dt=Ce;if(le&&ce.length>0){const Vt=Ww(Ce,ce);if(Vt){const{code:ps,emoji:Qt}=Vt;!Ce.startsWith(ps)&&!Ce.startsWith(Qt)&&(dt=`${ps} ${Ce}`)}}me(dt)}ut(Ve),Ft()}catch(ye){console.error("[git-generation][browser] GitView generate handler failed",{message:ye instanceof Error?ye.message:String(ye),error:ye});const Ce=ye instanceof Error?ye.message:e("gitView.toast.generateCommitMessageFailed");fe.error(Ce)}finally{Te(!1)}},[r,_s,le,ce,Ft,e]),Ur=K=>K.reason==="attention"?`${K.attentionReason} in progress`:K.reason==="missing"?"worktree is missing":"worktree is invalid",fo=async(K,ye)=>{if(!r||!v)return;const Ce=Oa(D);if(Ce.length>0){fe.error(e("gitView.toast.cannotCreateBranch",{reason:Ur(Ce[0])}));return}const Ve=v.current??null,dt=ye?.name??"origin";try{await n.createBranch(r,K,Ve??"HEAD"),fe.success(e("gitView.toast.createdBranch",{name:K})),await n.checkoutBranch(r,K);let Vt=!1;try{await n.gitPush(r,{remote:dt,branch:K,options:["--set-upstream"]}),Vt=!0}catch(ps){const Qt=ps instanceof Error?ps.message:`Unable to push new branch to ${dt}.`;fe.warning(e("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Qt]})})}await zt(),await Xt(),Vt&&fe.success(e("gitView.toast.upstreamSet",{branch:K,remote:dt}))}catch(Vt){const ps=Vt instanceof Error?Vt.message:e("gitView.toast.createBranchFailed");throw fe.error(ps),Vt}},Ho=async(K,ye)=>{if(!r)return;const Ce=Oa(D);if(Ce.length>0){fe.error(e("gitView.toast.cannotRenameBranch",{reason:Ur(Ce[0])}));return}try{await n.renameBranch(r,K,ye),fe.success(e("gitView.toast.renamedBranch",{oldName:K,newName:ye})),await zt(),await Xt()}catch(Ve){const dt=Ve instanceof Error?Ve.message:e("gitView.toast.renameBranchFailed",{oldName:K,newName:ye});fe.error(dt)}},mr=async K=>{if(!r)return;const ye=Oa(D);if(ye.length>0){fe.error(e("gitView.toast.cannotCheckout",{reason:Ur(ye[0])}));return}const Ce=K.replace(/^remotes\//,"");if(v?.current!==Ce)try{await n.checkoutBranch(r,Ce),fe.success(e("gitView.toast.checkedOut",{name:Ce})),await zt(),await Xt()}catch(Ve){const dt=Ve instanceof Error?Ve.message:e("gitView.toast.checkoutFailed",{name:Ce});fe.error(dt)}},Ko=async K=>{if(r){Bt();try{await n.setGitIdentity(r,K.id),fe.success(e("gitView.toast.appliedIdentity",{name:K.name})),await mn()}catch(ye){const Ce=ye instanceof Error?ye.message:e("gitView.toast.applyIdentityFailed");fe.error(Ce)}finally{et()}}},vn=a.useMemo(()=>O?.all?O.all.filter(K=>!K.startsWith("remotes/")).sort():[],[O]),Wn=a.useMemo(()=>O?.all?O.all.filter(K=>K.startsWith("remotes/")).map(K=>K.replace(/^remotes\//,"")).sort():[],[O]),zs=a.useMemo(()=>{if(wn.length>0)return wn;const K=new Set,ye=v?.tracking?.trim();ye&&ye.includes("/")&&K.add(ye.split("/")[0]);for(const Ce of Wn){const Ve=Ce.indexOf("/");Ve>0&&K.add(Ce.slice(0,Ve))}return K.size===0&&Yt&&K.add("origin"),Array.from(K).map(Ce=>({name:Ce,fetchUrl:Yt??"",pushUrl:Yt??""}))},[wn,Wn,Yt,v?.tracking]),qn=a.useMemo(()=>lc({remoteNames:new Set(zs.map(K=>K.name)),localBranches:vn,worktreeCreatedFromBranch:E?.createdFromBranch,rootBranchHint:_e}),[zs,vn,_e,E?.createdFromBranch]),Hr=a.useMemo(()=>zs.map(Ce=>Ce.name).map(Ce=>`${Ce}/${qn}`).find(Ce=>Wn.includes(Ce))??qn,[qn,zs,Wn]),mo=a.useMemo(()=>{const K=new Map;m&&K.set(m.id,m);let ye=null;if(Yt)try{let Ce=Yt.trim();Ce.startsWith("git@")&&(Ce=`https://${Ce.slice(4).replace(":","/")}`),Ce.endsWith(".git")&&(Ce=Ce.slice(0,-4));const Ve=new URL(Ce);ye=Ve.hostname+Ve.pathname}catch{}for(const Ce of g){if(Ce.authType!=="token"){K.set(Ce.id,Ce);continue}const Ve=Ce.host;if(!Ve){K.set(Ce.id,Ce);continue}if(!Ve.includes("/")){K.set(Ce.id,Ce);continue}ye&&ye===Ve&&K.set(Ce.id,Ce)}return Array.from(K.values())},[g,m,Yt]),hr=a.useMemo(()=>{if(B?.userName&&B?.userEmail){const K=g.find(ye=>ye.userName===B.userName&&ye.userEmail===B.userEmail);return K||(m&&m.userName===B.userName&&m.userEmail===B.userEmail?m:{id:"local-config",name:B.userName,userName:B.userName,userEmail:B.userEmail,sshKey:B.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return m??null},[B,g,m]),ho=_s.length,po=z||Ke!==null||gt!==null,ar=v?.current??null,Go=!!(E&&ze&&Qe&&st),Kr=!!ar,Ms=Go&&ze&&Qe&&E?{repoRoot:ze,sourceBranch:Qe,worktreeMetadata:E}:null;a.useEffect(()=>{if(!r||!n||!M?.all?.length||!ar||!qn||ar===qn){Ks(null);return}let K=!1;return(async()=>{try{const Ce=await n.getGitLog(r,{from:qn,to:"HEAD",maxCount:wt});if(K)return;const Ve=new Set((Ce?.all??[]).map(Vt=>Vt.hash).filter(Vt=>typeof Vt=="string"&&Vt.length>0));if(Ve.size===0){Ks(null);return}const dt=M.all.findIndex(Vt=>!Ve.has(Vt.hash));if(dt===0){Ks(null);return}if(dt===-1){Ks({insertBeforeIndex:M.all.length,branchName:ar,direction:"up"});return}Ks({insertBeforeIndex:dt,branchName:ar,direction:"up"})}catch{K||Ks(null)}})(),()=>{K=!0}},[qn,ar,r,n,M,wt]),a.useEffect(()=>{Tt(null)},[r]),a.useEffect(()=>{if(ts!=="graph"||!r){ts!=="graph"&&Tt(null);return}let K=!1;return xs(!0),n.getGitLog(r,{maxCount:As,all:!0}).then(ye=>{K||Tt(ye)}).catch(ye=>{console.error("Failed to fetch graph log:",ye)}).finally(()=>{K||xs(!1)}),()=>{K=!0}},[ts,r,As,Ss,n]);const pr=a.useCallback((K,ye)=>{if(!r||K.length===0)return;const Ce=Array.from(new Set(K));pt(dt=>{const Vt=new Set(dt);return Ce.forEach(ps=>Vt.add(ps)),Vt});const Ve=Fe(r,Ce,ye);ve.enqueue({directory:r,direction:ye,paths:new Set(Ce),rollback:()=>se(r,Ve)}),Ne()},[r,ve,Fe,se,Ne]),Yn=a.useCallback(async K=>{if(r){It(ye=>{const Ce=new Set(ye);return Ce.add(K),Ce});try{await n.revertGitFile(r,K,{scope:"working"}),fe.success(e("gitView.toast.revertedFile",{path:K})),await zt(!1)}catch(ye){const Ce=ye instanceof Error?ye.message:e("gitView.toast.revertFailed");fe.error(Ce)}finally{It(ye=>{const Ce=new Set(ye);return Ce.delete(K),Ce})}}},[r,zt,n,e]),H=a.useCallback(async(K,ye,Ce="all")=>{if(!r||K.length===0)return;const Ve=Array.from(new Set(K));if(Mt||Ve.some(Qt=>Ht.has(Qt)))return;const dt=new Set(_s.map(Qt=>Qt.path)),Vt=Ce==="all"&&Ve.some(Qt=>dt.has(Qt));ye&&Et(!0),It(Qt=>{const en=new Set(Qt);return Ve.forEach(cr=>en.add(cr)),en});const ps=[];try{if(await Promise.all(Ve.map(async Qt=>{try{await n.revertGitFile(r,Qt,{scope:Ce})}catch(en){ps.push({path:Qt,message:en instanceof Error?en.message:e("gitView.toast.revertFailed")})}})),Vt&&ps.length<Ve.length&&Q(r),await zt(!1),ps.length===0)fe.success(Ve.length===1?e("gitView.toast.revertedFilesSingle",{count:Ve.length}):e("gitView.toast.revertedFilesPlural",{count:Ve.length}));else if(ps.length===Ve.length)fe.error(ps[0]?.message||e("gitView.toast.revertFailed"));else{const Qt=Ve.length-ps.length;fe.warning(Qt===1?e("gitView.toast.revertedSomeSingle",{success:Qt,failed:ps.length}):e("gitView.toast.revertedSomePlural",{success:Qt,failed:ps.length}))}}finally{It(Qt=>{const en=new Set(Qt);return Ve.forEach(cr=>en.delete(cr)),en}),ye&&Et(!1)}},[Q,r,n,Mt,zt,Ht,_s,e]),Ge=a.useCallback(async K=>{await H(K,!0)},[H]),rt=a.useCallback(async K=>{await H(K,!1,"working")},[H]),vt=a.useCallback((K,ye)=>{if(r&&!Me){xe(r,K,ye);return}oe(K,ye)},[r,Me,oe,xe]),es=a.useCallback(()=>mt(!0),[]),ns=a.useMemo(()=>{const K=[];return _s.length>0&&K.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:_s,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:ye=>e("gitView.changes.unstageFileAria",{path:ye}),onActionFile:ye=>{pr([ye],"unstage")},onActionAll:ye=>{pr(ye,"unstage")},onViewDiff:ye=>vt(ye,!0),onRevertFile:Yn,showRevertActions:!1,accent:!0}),ir.length>0&&K.push({id:"unstaged",title:e("gitView.changes.title"),entries:ir,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:ye=>e("gitView.changes.stageFileAria",{path:ye}),onActionFile:ye=>{pr([ye],"stage")},onActionAll:ye=>{pr(ye,"stage")},onViewDiff:ye=>vt(ye,!1),onRevertFile:Yn}),K},[Yn,vt,pr,_s,e,ir]),os=a.useCallback(K=>{if(K.length===0)return;const ye=K.map(Ce=>Ce.trim()).filter(Boolean);if(ye.length===0){Ze();return}me(Ce=>{const Ve=Ce.trim(),dt=Ve.length>0?`
|
|
48
|
+
|
|
49
|
+
`:"";return`${Ve}${dt}${ye.join(`
|
|
50
|
+
`)}`.trim()}),Ze()},[Ze]),bs=a.useCallback((K,ye)=>{const Ce=ye||K;me(Ve=>{const dt=Ve.trimStart();return dt.startsWith(K)||ye&&dt.startsWith(ye)?Ve:`${Ce.endsWith(" ")?Ce:`${Ce} `}${Ve}`.trimStart()}),An(""),Ie(!1)},[]),Ts=a.useCallback(K=>{const ye=K instanceof Error?K.message.toLowerCase():"";return ye.includes("uncommitted changes")||ye.includes("local changes")||ye.includes("your local changes would be overwritten")||ye.includes("please commit your changes or stash them")||ye.includes("cannot rebase: you have unstaged changes")||ye.includes("error: cannot pull with rebase")},[]),Gs=a.useCallback((K,ye)=>{Pn(Ce=>[...Ce,{message:K,status:ye,timestamp:Date.now()}])},[]),Es=a.useCallback((K,ye)=>{Pn(Ce=>{if(Ce.length===0)return Ce;const Ve=[...Ce];return Ve[Ve.length-1]={...Ve[Ve.length-1],status:K,...ye?{message:ye}:{}},Ve})},[]),Mr=a.useCallback(()=>{Pn([])},[]),Gr=a.useCallback(()=>{Pn([]),on(null)},[]),hn=a.useCallback(K=>{const ye=K.trim(),Ce=new Set(zs.map(dt=>dt.name)),Ve=ye.indexOf("/");if(Ve>0){const dt=ye.slice(0,Ve),Vt=ye.slice(Ve+1);if(Ce.has(dt)&&Vt)return{branch:ye,remote:dt,remoteBranch:Vt}}for(const dt of zs){const Vt=`${dt.name}/${ye}`;if(Wn.includes(Vt))return{branch:Vt,remote:dt.name,remoteBranch:ye}}return{branch:ye,remote:null,remoteBranch:null}},[zs,Wn]),jn=a.useCallback(async K=>{if(!r)return;on("merge"),Mr();const ye=v?.current,Ce=hn(K);try{Ce.remote&&Ce.remoteBranch&&(Gs(`Fetching ${Ce.remote}/${Ce.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:Ce.remote,branch:Ce.remoteBranch}),Es("done",`Fetched ${Ce.remote}/${Ce.remoteBranch}`)),Gs(`Merging ${Ce.branch} into ${ye}...`,"running");const Ve=await n.merge(r,{branch:Ce.branch});Ve.conflict?(Es("error","Merge conflicts detected"),qe(Ve.conflictFiles??[]),xt("merge"),js(!0),ks(r,Ve.conflictFiles??[],"merge")):(Es("done",`Merged ${Ce.branch} into ${ye}`),Be(),Gs("Refreshing repository status...","running"),await zt(),await Xt(),Es("done","Repository status updated"))}catch(Ve){if(Ts(Ve))Es("error","Uncommitted changes detected"),Ns("merge"),$s(Ce.branch),ss(!0);else{const dt=Ve instanceof Error?Ve.message:`Failed to merge ${Ce.branch}`;Es("error",dt)}}},[r,n,v,hn,zt,Xt,Ts,ks,Be,Gs,Es,Mr]),Rn=a.useCallback(async K=>{if(!r)return;on("rebase"),Mr();const ye=v?.current,Ce=hn(K);try{Ce.remote&&Ce.remoteBranch&&(Gs(`Fetching ${Ce.remote}/${Ce.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:Ce.remote,branch:Ce.remoteBranch}),Es("done",`Fetched ${Ce.remote}/${Ce.remoteBranch}`)),Gs(`Rebasing ${ye} onto ${Ce.branch}...`,"running");const Ve=await n.rebase(r,{onto:Ce.branch});Ve.conflict?(Es("error","Rebase conflicts detected"),qe(Ve.conflictFiles??[]),xt("rebase"),js(!0),ks(r,Ve.conflictFiles??[],"rebase")):(Es("done",`Rebased ${ye} onto ${Ce.branch}`),Be(),Gs("Refreshing repository status...","running"),await zt(),await Xt(),Es("done","Repository status updated"))}catch(Ve){if(Ts(Ve))Es("error","Uncommitted changes detected"),Ns("rebase"),$s(Ce.branch),ss(!0);else{const dt=Ve instanceof Error?Ve.message:`Failed to rebase onto ${Ce.branch}`;Es("error",dt)}}},[r,n,v,hn,zt,Xt,Ts,ks,Be,Gs,Es,Mr]),lr=a.useCallback(async()=>{if(r)try{lt==="merge"?(await n.abortMerge(r),fe.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),fe.success(e("gitView.toast.rebaseAborted"))),Be(),await zt(),await Xt()}catch(K){const ye=K instanceof Error?K.message:`Failed to abort ${lt}`;fe.error(ye)}},[r,n,lt,zt,Xt,Be,e]),Un=a.useMemo(()=>v?.files?v.files.filter(K=>K.index==="U"||K.working_dir==="U"||K.index==="A"&&K.working_dir==="A"||K.index==="D"&&K.working_dir==="D").length:0,[v?.files]),gr=a.useCallback(async()=>{if(r)try{const K=!!v?.mergeInProgress?.head,ye=!!(v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto);if(K){const Ce=await n.continueMerge(r);Ce.conflict?(qe(Ce.conflictFiles??[]),xt("merge"),js(!0),ks(r,Ce.conflictFiles??[],"merge"),fe.error(e("gitView.toast.mergeConflictsDetected"))):(Be(),fe.success(e("gitView.toast.mergeCompleted")),await zt(),await Xt())}else if(ye){const Ce=await n.continueRebase(r);Ce.conflict?(qe(Ce.conflictFiles??[]),xt("rebase"),js(!0),ks(r,Ce.conflictFiles??[],"rebase"),fe.error(e("gitView.toast.rebaseConflictsDetected"))):(Be(),fe.success(e("gitView.toast.rebaseStepCompleted")),await zt(),await Xt())}}catch(K){const ye=K instanceof Error?K.message:e("gitView.toast.continueOperationFailed");fe.error(ye)}},[r,n,v,zt,Xt,ks,Be,e]),qr=a.useCallback(async()=>{if(r)try{!!v?.mergeInProgress?.head?(await n.abortMerge(r),fe.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),fe.success(e("gitView.toast.rebaseAborted"))),Be(),await zt(),await Xt()}catch(K){const ye=K instanceof Error?K.message:e("gitView.toast.abortOperationFailed");fe.error(ye)}},[r,n,v,zt,Xt,Be,e]),xr=a.useCallback(()=>{if(!r)return;const ye=!!v?.mergeInProgress?.head?"merge":"rebase",Ce=v?.files?.filter(Ve=>Ve.index==="U"||Ve.working_dir==="U").map(Ve=>Ve.path)??[];Ce.length>0&&qe(Ce),xt(ye),js(!0)},[r,v]),go=a.useCallback(async K=>{if(!r)return;const ye=v?.current,Ce=hs,Ve=Ds,dt=(v?.files??[]).some(Ed);try{await n.stash(r,{message:`Auto-stash before ${Ce} with ${Ve}`,includeUntracked:!0}),dt&&Q(r)}catch(Qt){const en=Qt instanceof Error?Qt.message:"Failed to stash changes";fe.error(en);return}let Vt=!1,ps=!1;try{if(Ce==="merge"){const Qt=await n.merge(r,{branch:Ve});Qt.conflict?(ps=!0,qe(Qt.conflictFiles??[]),xt("merge"),js(!0)):(Vt=!0,fe.success(e("gitView.toast.mergedIntoBranch",{branch:Ve,currentBranch:ye||""})))}else{const Qt=await n.rebase(r,{onto:Ve});Qt.conflict?(ps=!0,qe(Qt.conflictFiles??[]),xt("rebase"),js(!0)):(Vt=!0,fe.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:ye||"",branch:Ve})))}if(K&&Vt)try{await n.stashPop(r),Q(r),fe.success(e("gitView.toast.stashedRestored"))}catch(Qt){const en=Qt instanceof Error?Qt.message:e("gitView.toast.restoreStashFailed");fe.error(en)}else K&&ps&&fe.info(e("gitView.toast.restoreStashManually"));await zt(),await Xt()}catch(Qt){if(K)try{await n.stashPop(r),Q(r)}catch{}throw Qt}},[Q,r,n,v,hs,Ds,zt,Xt,e]),qo=a.useCallback(K=>{bt(K),r&&(V(r,K),X(r,n,K))},[r,X,n,V]),wi=a.useCallback(K=>{as(K)},[]),vi=a.useCallback(()=>{Js(null),r&&(P(r,n),G(r,n),X(r,n,wt))},[r,P,G,X,wt,n]),Ta=a.useCallback(K=>{if(K.conflict){if(K.operation==="cherry-pick"||K.operation==="revert"){fe.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:K.conflictFiles?.join(", ")??"unknown files"})}),r&&(P(r,n),G(r,n),X(r,n,wt));return}qe(K.conflictFiles??[]),xt(K.operation),js(!0),r&&ks(r,K.conflictFiles??[],K.operation)}},[e,qe,xt,js,ks,r,P,G,X,wt,n]);return r?N===null||N===!0&&!v?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):N===!1?ae?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(A,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(A,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.notGitRepositoryDescription")}),F.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:Pe("flex h-full flex-col overflow-hidden"),children:[s.jsx(gx,{status:v,localBranches:vn,remoteBranches:Wn,branchInfo:O?.branches,syncAction:Ke,remotes:zs,onFetch:K=>co("fetch",K),onSync:K=>co("sync",K),onRemoveRemote:Uo,removingRemoteName:Fs,onCheckoutBranch:mr,onCreateBranch:fo,onRenameBranch:Ho,activeIdentityProfile:hr,availableIdentities:mo,onSelectIdentity:Ko,isApplyingIdentity:yt,isWorktreeMode:!!E,onOpenHistory:()=>Js("history"),onOpenGraph:()=>Js("graph"),onOpenStashes:es,onOpenUpdateBranch:Kr?()=>zn(!0):void 0,onOpenReintegrateCommits:Ms?()=>un(!0):void 0,pullRequest:ne?.pr??null,prChecks:ne?.checks??null,onOpenPullRequest:r?()=>W(r,"pr"):void 0}),r&&(v?.mergeInProgress?.head||v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto)&&s.jsx(Mw,{mergeInProgress:v?.mergeInProgress,rebaseInProgress:v?.rebaseInProgress,onContinue:gr,onAbort:qr,onResolveWithAI:xr,conflictCount:Un,isLoading:z}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:Pe("min-w-0 min-h-0 h-full flex flex-col"),children:s.jsx(On,{as:Sa,ref:Re,outerClassName:"flex-1 min-h-0",className:Pe("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:s.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(In?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(xx,{groups:ns,diffStats:v?.diffStats,revertingPaths:Ht,isRevertingAll:Mt,onVisiblePathsChange:_,onRevertAll:Ge,onRevertDirectory:rt,headerBackgroundClassName:"bg-background"})}),s.jsx(bx,{stagedCount:ho,commitMessage:he,onCommitMessageChange:me,generatedHighlights:it,onInsertHighlights:os,onGenerateMessage:uo,isGeneratingMessage:Oe,onCommit:()=>Rr({pushAfter:!1}),onCommitAndPush:()=>Rr({pushAfter:!0}),commitAction:gt,hasPendingIndexMutation:Gt,gitmojiEnabled:le,onOpenGitmojiPicker:()=>Ie(!0)})]}):s.jsx(dw,{onOpenStashes:()=>mt(!0)})})})})})}),s.jsx(Ps,{open:or,onOpenChange:K=>{!K&&Dn!==null||zn(K)},children:s.jsxs(Is,{className:"max-w-2xl min-h-[26rem]",children:[s.jsxs(Us,{children:[s.jsx(Ls,{children:e("gitView.branch.updateTitle")}),s.jsxs(Hs,{children:[e("gitView.branch.updateDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:v?.current??""}),"."]})]}),Kr?s.jsx(Tw,{mode:"bare",currentBranch:v?.current,localBranches:vn,remoteBranches:Wn,defaultTargetBranch:Hr,onMerge:jn,onRebase:Rn,disabled:po,isOperating:Dn!==null,operationLogs:fr,onOperationComplete:Gr}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),s.jsx(Ps,{open:dn,onOpenChange:un,children:s.jsxs(Is,{className:"max-w-2xl min-h-[26rem]",children:[s.jsxs(Us,{children:[s.jsx(Ls,{children:e("gitView.integrate.title")}),s.jsx(Hs,{children:Ms?s.jsxs("span",{className:"font-mono text-foreground",children:[Ms.sourceBranch," → ",at]}):null})]}),Ms?s.jsx(lw,{repoRoot:Ms.repoRoot,sourceBranch:Ms.sourceBranch,worktreeMetadata:Ms.worktreeMetadata,localBranches:vn,defaultTargetBranch:at,refreshKey:tt,showHeader:!1,onRefresh:()=>{r&&(P(r,n),G(r,n),X(r,n,wt))}},Ms.worktreeMetadata.path):null]})}),s.jsx(Ps,{open:ts!==null,onOpenChange:K=>{K||Js(null)},children:s.jsxs(Is,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Us,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx(Ls,{children:e(ts==="graph"?"gitView.graph.title":"gitView.history.title")}),s.jsxs(He,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(ts==="graph"){Rs(K=>K+1);return}r&&X(r,n,wt)},disabled:ts==="graph"?Ct:T,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[s.jsx(A,{name:"refresh",className:Pe("size-4",(ts==="graph"?Ct:T)&&"animate-spin")}),e("gitView.history.refresh")]})]}),s.jsx(Hs,{children:e("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(yw,{mode:ts==="graph"?"graph":"history",log:ts==="graph"?qt??M:M,isLogLoading:ts==="graph"&&Ct||T,logMaxCount:ts==="graph"?As:wt,onLogMaxCountChange:ts==="graph"?wi:qo,expandedCommitHashes:At,onToggleCommit:an,commitFilesMap:Zt,loadingCommitHashes:ls,onCopyHash:Zs,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ts==="graph"?null:ms,onConflict:ts==="graph"?Ta:void 0,onActionSuccess:ts==="graph"?vi:void 0})})]})}),s.jsx(cw,{open:ct,onOpenChange:mt,directory:r,hasUncommittedChanges:(v?.files?.length??0)>0,hasStagedChanges:_s.length>0,uncommittedFileCount:v?.files?.length??0,onChanged:async K=>{r&&K?.affectsIndex&&Q(r),await zt(!1),await Xt()}}),s.jsx(Ps,{open:ge,onOpenChange:Ie,children:s.jsxs(Is,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Us,{className:"px-4 pt-4",children:s.jsx(Ls,{children:e("gitView.gitmoji.title")})}),s.jsxs(ba,{className:"h-[420px]",children:[s.jsx(ya,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:Xs,onValueChange:An}),s.jsxs(wa,{children:[s.jsx(va,{children:e("gitView.gitmoji.empty")}),s.jsx(Sr,{children:(ce.length===0?[]:ce.filter(K=>{const ye=Xs.trim().toLowerCase();return ye?K.emoji.includes(ye)||K.code.toLowerCase().includes(ye)||K.description.toLowerCase().includes(ye):!0})).map(K=>s.jsxs(kr,{onSelect:()=>bs(K.emoji,K.code),children:[s.jsx("span",{className:"text-lg",children:K.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:K.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:K.description})]},K.code))})]})]})]})}),r&&s.jsx(kw,{open:Pr,onOpenChange:js,conflictFiles:re,directory:r,operation:lt,onAbort:lr,onClearState:Be}),s.jsx(Rw,{open:Wt,onOpenChange:ss,operation:hs,targetBranch:Ds,onConfirm:go})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})},Gw=3e4,Fd=20,bm=(t,e)=>JSON.stringify([$n(),t,e]),qw=t=>{try{const e=JSON.parse(t);if(!Array.isArray(e)||e.length!==3)return null;const[n,r,o]=e;return typeof n!="string"||typeof r!="string"||typeof o!="number"?null:{runtimeKey:n,directory:r,number:o}}catch{return null}},Od=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),Ci=new Map,Yw=t=>{const e=Object.entries(t);return e.length<=Fd?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,Fd))},Ld=zo()((t,e)=>({entries:{},ensure:async(n,r,o,i)=>{const c=bm(r,o),l=i?.includeCheckDetails??!1,d=e().entries[c],u=d&&d.result&&Date.now()-d.fetchedAt<Gw&&(d.hasCheckDetails||!l);if(!i?.force&&u)return d.result;const h=`${c}::${l?"details":"plain"}`,p=Ci.get(`${c}::details`)??(l?null:Ci.get(h));if(p&&!i?.force)return p;const x=(async()=>{t(b=>({entries:{...b.entries,[c]:{...b.entries[c]??Od(),isLoading:!0,error:null}}}));try{const b=await n.prContext(r,o,{includeDiff:!1,includeCheckDetails:l,sourceRepo:i?.sourceRepo??null});return t(S=>({entries:Yw({...S.entries,[c]:{result:b,hasCheckDetails:l,fetchedAt:Date.now(),isLoading:!1,error:null}})})),b}catch(b){const S=b instanceof Error?b.message:"Failed to load pull request context";return t(g=>({entries:{...g.entries,[c]:{...g.entries[c]??Od(),isLoading:!1,error:S}}})),null}finally{Ci.delete(h)}})();return Ci.set(h,x),x},invalidate:(n,r)=>{t(o=>{const i={};for(const[c,l]of Object.entries(o.entries)){const d=qw(c);d&&d.directory===n&&(r==null||d.number===r)||(i[c]=l)}return{entries:i}})}})),Qw=t=>{const e={success:0,failure:0,pending:0,inProgress:0,queued:0};let n;for(const i of t){if(i.status==="in_progress"){e.pending+=1,e.inProgress+=1,i.startedAt&&(!n||i.startedAt<n)&&(n=i.startedAt);continue}if(i.status==="queued"){e.pending+=1,e.queued+=1;continue}const c=typeof i.conclusion=="string"?i.conclusion.toLowerCase():"";if(!c){e.pending+=1;continue}c==="success"||c==="neutral"||c==="skipped"?e.success+=1:e.failure+=1}const r=e.success+e.failure+e.pending;return{state:e.failure>0?"failure":e.pending>0?"pending":r>0?"success":"unknown",total:r,...e,...n?{startedAt:n}:{}}},Xw=35e3,Ha=(t,e,n)=>{if(!t)return null;const r=Date.parse(t);if(!Number.isFinite(r))return null;const o=e?Date.parse(e):n??Date.now();if(!Number.isFinite(o)||o<=r)return null;const i=Math.floor((o-r)/6e4);if(i<1)return"<1m";if(i<60)return`${i}m`;const c=Math.floor(i/60),l=i%60;return l>0?`${c}h ${l}m`:`${c}h`},Ka=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},Bd=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},Jw=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",o=e.mergeable===!1||r==="blocked"||r==="dirty";return n||o?"blocked":"open"},Zw=[2e3,5e3],$d=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),$r=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},ev=(t,e)=>{const n=$r(t);if(!n||n.includes("->"))return"";if(e){const o=`${e}/`;return n.startsWith(o)?n.slice(o.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},tv=(t,e)=>`${t}::${e}`,cc=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},Ga=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(c=>c.name===n);if(i)return i}const r=cc(e.trackingBranch);if(r){const i=r==="origin"?t.find(l=>l.name==="upstream"):null;if(i)return i;const c=t.find(l=>l.name===r);if(c)return c}const o=t.find(i=>i.name==="origin");return o||(t[0]??null)},sv=t=>t.startsWith("pr-"),nv=(t,e)=>{const n=cc(e),r=new Map(t.map(c=>[c.name,c])),o=[],i=c=>{c&&(o.some(l=>l.name===c.name)||o.push(c))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(c=>!sv(c.name)).forEach(c=>i(c)),t.forEach(c=>i(c)),o},Zo=new Map,qa=io;function rv(t,e){const[n,r]=a.useState(null),[o,i]=a.useState([]),c=a.useRef(null);return a.useEffect(()=>{r(null),i([])},[t]),a.useEffect(()=>{if(!t||!e?.repoUpstream||c.current===t)return;c.current=t;let l=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(l||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const u=await e.repoBranches(d.upstream.owner,d.upstream.repo);l||i(u)}catch{}}catch{}})(),()=>{l=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:o}}const ov=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:i=[],onGeneratedDescription:c})=>{const{t:l}=ft(),d=Ee(re=>re.timeFormatPreference),{github:u}=_n(),h=Ar(re=>re.status),f=Ar(re=>re.hasChecked),p=Ee(re=>re.setSettingsDialogOpen),x=Ee(re=>re.setSettingsPage),b=Ee(re=>re.setActiveMainTab),S=Je(re=>re.currentSessionId),g=Je(re=>!!re.newSessionDraft?.open),{isMobile:m,hasTouchInput:y,screenWidth:C}=Dr(),j=Ee(re=>re.openContextSurface),w=Tn(re=>re.requestSource),N=!m&&C>=768&&!nr(),v=a.useCallback(()=>{x("github"),p(!0)},[p,x]),D=a.useMemo(()=>tv(t,e),[t,e]),F=a.useMemo(()=>Zo.get(D)??null,[D]),k=sn(re=>re.ensureEntry),E=sn(re=>re.setParams),O=sn(re=>re.startWatching),M=sn(re=>re.stopWatching),B=sn(re=>re.refresh),z=sn(re=>re.updateStatus),[T,I]=a.useState(()=>F?.title??$d(e)),[R,L]=a.useState(()=>F?.body??""),[P,G]=a.useState(()=>F?.draft??!1),[X,V]=a.useState(()=>F?.additionalContext??""),[te,Z]=a.useState(()=>{const re=typeof F?.targetBaseBranch=="string"?$r(F.targetBaseBranch):"";return re||$r(n)}),[de,Fe]=a.useState("squash"),[se,Q]=a.useState(!1),[Me,xe]=a.useState(!1),[W,J]=a.useState(!1),[ne,oe]=a.useState(!1),[ue,Ae]=a.useState(!1),[we,Se]=a.useState(!1),[Le,Ue]=a.useState(null),[be,q]=a.useState(""),[Ne,je]=a.useState(""),[ve,ie]=a.useState(!1),[ee,ke]=a.useState(!1),[ae,U]=a.useState(()=>Ga(o,{selectedRemoteName:F?.selectedRemoteName,trackingBranch:r})),[le,_e]=a.useState(!1),{detectedUpstream:De,upstreamBranches:ce}=rv(t,u);a.useEffect(()=>{_e(!1)},[t]);const he=o.some(re=>re.name==="upstream"),$=!!(t&&e&&n&&(e!==n||(he||De!==null))),_=a.useMemo(()=>yi(t,e,ae?.name??null),[t,e,ae?.name]),ge=sn(re=>re.entries[_]),Ie=ge?.isLoading??!1,Re=ge?.status??null,Ke=ge?.error??null,nt=ge?.isInitialStatusResolved??!1,ct=a.useMemo(()=>{const re=le?null:ae?.name?.trim()||null,qe=new Set;for(const qt of i){const Tt=ev(qt,re);!Tt||Tt==="HEAD"||qe.add(Tt)}if(le)for(const qt of ce)qt&&qt!=="HEAD"&&qe.add(qt);const lt=$r(n);lt&<!=="HEAD"&&qe.add(lt);const xt=$r(te);return xt&&xt!=="HEAD"&&qe.add(xt),Array.from(qe).sort((qt,Tt)=>qt.localeCompare(Tt))},[n,i,ae?.name,te,ce,le]);a.useEffect(()=>{if(o.length===0){ae&&U(null);return}(!ae||!o.some(re=>re.name===ae.name))&&U(Ga(o,{selectedRemoteName:F?.selectedRemoteName,trackingBranch:r}))},[F?.selectedRemoteName,o,ae,r]),a.useEffect(()=>{const re=$r(n);if(!te&&re){Z(re);return}if(ct.length!==0&&!ct.includes(te)){const qe=ct.includes(re)?re:ct[0];qe&&Z(qe)}},[ct,n,te]);const[mt,gt]=a.useState(()=>F?.activeSegment??"overview"),[ht,wt]=a.useState(new Set),[bt,yt]=a.useState(new Set),Dt=a.useRef(new Set),Kt=a.useRef(null),Ut=a.useRef(!1),Lt=a.useRef(new Set),Bt=a.useRef([]);a.useEffect(()=>{De&&!he&&_e(!0)},[De,he]),a.useEffect(()=>{le&&De?.defaultBranch&&Z(De.defaultBranch)},[le,De?.defaultBranch]);const et=Re?.pr??null,Ht=et?bm(t,et.number):null,It=Ld(re=>Ht?re.entries[Ht]:void 0),We=Ld(re=>re.ensure),pt=It?.result??null,Mt=It?.isLoading??!1,Et=a.useCallback(re=>{gt(re);const qe=Zo.get(D);qe&&Zo.set(D,{...qe,activeSegment:re})},[D]);a.useEffect(()=>{!et||!u?.prContext||mt==="overview"||We(u,t,et.number,{includeCheckDetails:mt==="checks",sourceRepo:Re?.repo??null})},[mt,t,We,u,et,Re?.repo]);const tt=Re?.checks??null,pe=(tt?.pending??0)>0,Oe=pt?.checkRuns??null,Te=pt?.fetchedAt;a.useEffect(()=>{if(!Oe||Oe.length===0)return;const re=Qw(Oe);z(_,qe=>{if(!qe?.pr||typeof Te=="number"&&typeof qe.fetchedAt=="number"&&Te<qe.fetchedAt)return qe;const lt=qe.checks;return lt&<.state===re.state&<.total===re.total&<.success===re.success&<.failure===re.failure&<.pending===re.pending&<.inProgress===re.inProgress&<.queued===re.queued&<.startedAt===re.startedAt?qe:{...qe,checks:re,...typeof Te=="number"?{fetchedAt:Te}:{}}})},[Oe,Te,_,z]),a.useEffect(()=>{if(mt!=="checks"||!pe||!et||!u?.prContext)return;const re=window.setInterval(()=>{We(u,t,et.number,{includeCheckDetails:!0,sourceRepo:Re?.repo??null,force:!0})},Xw);return()=>window.clearInterval(re)},[mt,pe,t,We,u,et,Re?.repo]);const[it,ut]=a.useState(()=>Date.now());a.useEffect(()=>{if(!pe)return;ut(Date.now());const re=window.setInterval(()=>ut(Date.now()),3e4);return()=>window.clearInterval(re)},[pe]);const Gt=et?`${t}#${et.number}`:null,Ft=!!(Gt&&Le===Gt);a.useEffect(()=>{if(!u?.prContext||!et||typeof et.body=="string"&&et.body.length>0)return;const re=`${t}#${et.number}`;if(Dt.current.has(re))return;Dt.current.add(re),Ue(re);let qe=!1;return We(u,t,et.number,{sourceRepo:Re?.repo??null}).then(lt=>{if(qe)return;const xt=lt?.pr;xt&&z(_,qt=>!qt?.pr||qt.pr.number!==et.number?qt:{...qt,pr:{...qt.pr,body:xt.body||""}})}).catch(()=>{}).finally(()=>{qe||Ue(lt=>lt===re?null:lt)}),()=>{qe=!0}},[t,We,u,et,_,Re?.repo,z]),a.useEffect(()=>{if(!et){Se(!1),q(""),je(""),Kt.current=null;return}const re=Kt.current!==null&&Kt.current!==et.number;re&&Se(!1),(!we||re)&&(q(et.title||""),je(et.body||"")),Kt.current=et.number},[we,et]);const ze=a.useCallback(re=>{if(!re)return"";const qe=Date.parse(re);return Number.isFinite(qe)?Hl(qe,d,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):re},[d]),Qe=a.useMemo(()=>{const re=h?.user?.login;return typeof re=="string"?re.trim():""},[h]),st=a.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),at=a.useCallback(re=>{const qe=Qe.toLowerCase(),lt=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return re.replace(lt,(xt,qt,Tt)=>{const Ct=`@${Tt}`,xs=Tt.toLowerCase();return`${qt}[${Ct}](https://github.com/${xs}${qe&&xs===qe?"?oc-self-mention=1":""})`})},[Qe]),Ze=a.useMemo(()=>{const re=(pt?.issueComments??[]).map(xt=>({id:`issue-${xt.id}`,body:xt.body||"",authorName:xt.author?.name||xt.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:xt.author?.login||null,avatarUrl:xt.author?.avatarUrl||null,createdAt:xt.createdAt,context:l("gitView.pr.comments.generalContext"),path:null,line:null})),qe=(pt?.reviewComments??[]).map(xt=>({id:`review-${xt.id}`,body:xt.body||"",authorName:xt.author?.name||xt.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:xt.author?.login||null,avatarUrl:xt.author?.avatarUrl||null,createdAt:xt.createdAt,context:l("gitView.pr.comments.reviewContext"),path:xt.path||null,line:xt.line??null})),lt=[...re,...qe];return lt.sort((xt,qt)=>{const Tt=xt.createdAt?Date.parse(xt.createdAt):0,Ct=qt.createdAt?Date.parse(qt.createdAt):0,xs=Number.isFinite(Tt)?Tt:0,As=Number.isFinite(Ct)?Ct:0;return xs-As}),lt},[pt,l]),At=a.useCallback(()=>{const re=S??(g?"draft":null);return re?{directory:t,sessionKey:re}:(fe.error(l("gitView.pr.toast.noActiveSession"),{description:l("gitView.pr.toast.noActiveSessionDescription")}),null)},[S,t,g,l]),Rt=a.useCallback((re,qe)=>{const lt=qe.authorLogin?`@${qe.authorLogin}`:qe.authorName,xt=qe.path?` · ${qe.path}${qe.line?`:${qe.line}`:""}`:"";di.getState().addDraft(re,{source:"pr-comment",fileLabel:`PR #${et?.number??""} ${lt}${xt}`,startLine:qe.line??0,endLine:qe.line??0,code:qe.body,language:"markdown",text:""})},[et?.number]),Zt=a.useCallback((re,qe)=>{const lt=re.status||"unknown",xt=re.conclusion??void 0,qt=xt?`${lt} / ${xt}`:lt,Tt=re.app?.name||re.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:qe?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[qe?.hideHeader?null:s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:re.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Tt?`${Tt} · ${qt}`:qt})]}),re.detailsUrl?s.jsx(He,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:re.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),re.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:re.output.title}):null,re.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:re.output.summary}):null,re.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap break-words max-h-48 overflow-y-auto",children:re.output.text}):null,Array.isArray(re.annotations)&&re.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",re.annotations.length>20?` (showing 20/${re.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:re.annotations.slice(0,20).map((Ct,xs)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro break-words text-[var(--status-error)]",children:[Ct.title||Ct.level||"Issue",Ct.path?` · ${Ct.path}`:"",typeof Ct.startLine=="number"?`:${Ct.startLine}`:"",typeof Ct.endLine=="number"&&Ct.endLine!==Ct.startLine?`-${Ct.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:Ct.message}),Ct.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:Ct.rawDetails}):null]},`${Ct.path||"file"}:${Ct.startLine||xs}:${xs}`))})]}):null,re.job?.steps&&re.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:re.job.steps.map((Ct,xs)=>{const As=(Ct.conclusion||"").toLowerCase(),as=As&&!["success","neutral","skipped"].includes(As),Ss=`${re.id??"run"}:${re.job?.jobId??"job"}:${Ct.number??xs}:${Ct.name}`,Rs=ht.has(Ss);return as?s.jsxs(Fo,{open:Rs,children:[s.jsxs("button",{type:"button",onClick:()=>{wt(Os=>{const ks=new Set(Os);return ks.has(Ss)?ks.delete(Ss):ks.add(Ss),ks})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(as?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Rs?s.jsx(A,{name:"arrow-down-s",className:"size-4"}):s.jsx(A,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:Ct.name}),Ct.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ct.conclusion}):null]}),s.jsx(Oo,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof Ct.number=="number"?s.jsxs("div",{children:[l("gitView.pr.checks.stepLabel"),": ",Ct.number]}):null,Ct.status?s.jsxs("div",{children:[l("gitView.pr.checks.statusLabel"),": ",Ct.status]}):null,Ct.conclusion?s.jsxs("div",{children:[l("gitView.pr.checks.conclusionLabel"),": ",Ct.conclusion]}):null,Ct.startedAt?s.jsxs("div",{children:[l("gitView.pr.checks.startedLabel"),": ",ze(Ct.startedAt)]}):null,Ct.completedAt?s.jsxs("div",{children:[l("gitView.pr.checks.completedLabel"),": ",ze(Ct.completedAt)]}):null]})})]},Ss):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:Ct.name}),Ct.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ct.conclusion}):null]},Ss)})})]}):null]})},[ht,ze,l]),[fs,ls]=a.useState(!1),[Ot,$t]=a.useState(!1),Pt=a.useCallback(async()=>{if(!u?.prContext){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!et)return;const re=At();if(re){ls(!0);try{const qe=await We(u,t,et.number,{includeCheckDetails:!0,sourceRepo:Re?.repo??null});if(!qe){fe.error(l("gitView.pr.toast.loadChecksFailed"));return}const xt=(qe.checkRuns??[]).filter(Tt=>Ka(Tt.conclusion));if(xt.length===0){fe.message(l("gitView.pr.toast.noFailedChecks"));return}const qt=di.getState();for(const Tt of xt){const Ct=(Tt.annotations??[]).map(as=>[[as.level,as.title].filter(Boolean).join(" "),as.path?`${as.path}${typeof as.startLine=="number"?`:${as.startLine}`:""}`:null,as.message,as.rawDetails].filter(Boolean).join(`
|
|
51
|
+
`)),xs=(Tt.job?.steps??[]).filter(as=>Ka(as.conclusion)).map(as=>`step ${as.number??"?"}: ${as.name} → ${as.conclusion}`),As=[`check: ${Tt.job?.workflowName?`${Tt.job.workflowName} / ${Tt.name}`:Tt.name}`,`status: ${Tt.status??"unknown"} / ${Tt.conclusion??"unknown"}`,Tt.detailsUrl?`url: ${Tt.detailsUrl}`:null,Tt.output?.title?`title: ${Tt.output.title}`:null,Tt.output?.summary?`summary:
|
|
52
|
+
${Tt.output.summary}`:null,xs.length>0?`failed steps:
|
|
53
|
+
${xs.join(`
|
|
54
|
+
`)}`:null,Ct.length>0?`annotations:
|
|
55
|
+
${Ct.join(`
|
|
56
|
+
---
|
|
57
|
+
`)}`:null].filter(Boolean).join(`
|
|
58
|
+
|
|
59
|
+
`);qt.addDraft(re,{source:"pr-check",fileLabel:`PR #${et.number} · ${Tt.name}`,startLine:0,endLine:0,code:As,language:"text",text:""})}b("chat")}catch(qe){const lt=qe instanceof Error?qe.message:String(qe);fe.error(l("gitView.pr.toast.loadChecksFailed"),{description:lt})}finally{ls(!1)}}},[t,We,u,et,At,b,Re?.repo,l]),ms=a.useCallback(async()=>{if(!u?.prContext){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!et)return;const re=At();if(re){$t(!0);try{if(!await We(u,t,et.number,{sourceRepo:Re?.repo??null})){fe.error(l("gitView.pr.toast.loadPrCommentsFailed"));return}if(Ze.length===0){fe.message(l("gitView.pr.toast.noPrComments"));return}for(const lt of Ze)Rt(re,lt);b("chat")}catch(qe){const lt=qe instanceof Error?qe.message:String(qe);fe.error(l("gitView.pr.toast.loadPrCommentsFailed"),{description:lt})}finally{$t(!1)}}},[Rt,t,We,u,et,At,b,Re?.repo,l,Ze]),Ks=a.useCallback(async re=>{const qe=At();qe&&(Rt(qe,re),b("chat"))},[Rt,At,b]),Yt=a.useCallback(async re=>{await B(_,re)},[_,B]),ws=a.useCallback(()=>{Bt.current.forEach(re=>{window.clearTimeout(re)}),Bt.current=Zw.map(re=>window.setTimeout(()=>{Yt({force:!0,silent:!0,markInitialResolved:!0})},re))},[Yt]);a.useEffect(()=>{if(!u?.prStatus||!$||o.length<=1||Ut.current||Re?.pr)return;const re=`${D}::${ae?.name??""}`;if(Lt.current.has(re))return;Lt.current.add(re);const qe=nv(o,r).filter(qt=>qt.name!==ae?.name);if(qe.length===0)return;let lt=!1;return(async()=>{for(const qt of qe){if(lt)return;try{if(!(await u.prStatus(t,e,qt.name))?.pr)continue;if(lt)return;U(Ct=>Ct?.name===qt.name?Ct:qt);return}catch{}}})(),()=>{lt=!0}},[e,$,t,u,o,ae?.name,D,Re?.pr,r]),a.useEffect(()=>{k(_),E(_,{directory:t,branch:e,remoteName:ae?.name??null,canShow:$,github:u,githubAuthChecked:f,githubConnected:h?.connected??null})},[e,$,t,k,u,f,h?.connected,_,ae?.name,E]),a.useEffect(()=>(O(_),()=>{M(_)}),[_,O,M]),a.useEffect(()=>{const re=Zo.get(D)??null;I(re?.title??$d(e)),L(re?.body??""),G(re?.draft??!1),Z(re?.targetBaseBranch?$r(re.targetBaseBranch):$r(n));const qe=Ga(o,{selectedRemoteName:re?.selectedRemoteName,trackingBranch:r});U(lt=>lt?.name===qe?.name?lt:qe)},[n,e,o,D,r]),a.useEffect(()=>{Yt({markInitialResolved:!0})},[_,Yt]),a.useEffect(()=>{!$||!ae?.name||Yt({force:!0,silent:!0,markInitialResolved:!0})},[$,Yt,ae?.name]),a.useEffect(()=>{const re=Re?.resolvedRemoteName?.trim();if(!re||Ut.current)return;const qe=o.find(lt=>lt.name===re);qe&&U(lt=>lt?.name===qe.name?lt:qe)},[o,Re?.resolvedRemoteName]),a.useEffect(()=>{const re=Re?.pr?.state==="closed"||Re?.pr?.state==="merged",qe=ge?.lastRefreshAt??0,lt=Date.now()-qe>6e4,xt=!re&<,qt=()=>{xt&&Yt({force:!0,silent:!0})},Tt=()=>{document.visibilityState==="visible"&&xt&&Yt({force:!0,silent:!0})};return window.addEventListener("focus",qt),document.addEventListener("visibilitychange",Tt),()=>{window.removeEventListener("focus",qt),document.removeEventListener("visibilitychange",Tt)}},[Yt,Re?.pr?.state,ge?.lastRefreshAt]),a.useEffect(()=>{f&&h?.connected===!1&&Yt({force:!0,silent:!0,markInitialResolved:!0})},[f,h,Yt]),a.useEffect(()=>{!t||!e||Zo.set(D,{title:T,body:R,draft:P,additionalContext:X,targetBaseBranch:te,selectedRemoteName:ae?.name,activeSegment:mt})},[D,T,R,P,X,te,ae?.name,t,e,mt]),a.useEffect(()=>{const re=Bt.current;return()=>{re.forEach(qe=>{window.clearTimeout(qe)}),Bt.current=[]}},[]);const Xs=a.useCallback(async()=>{if(!se&&t){Q(!0);try{const qe={base:le&&De?.defaultBranchSha?De.defaultBranchSha:te,head:e};X&&(qe.context=X);const lt=await Fp(t,qe);lt.title?.trim()&&I(lt.title.trim()),lt.body?.trim()&&L(lt.body.trim()),c?.()}catch(re){const qe=re instanceof Error?re.message:String(re);fe.error(l("gitView.pr.toast.generateDescriptionFailed"),{description:qe})}finally{Q(!1)}}},[X,e,De?.defaultBranchSha,t,se,c,te,l,le]),An=a.useCallback(async()=>{if(!u?.prCreate){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}const re=T.trim();if(!re){fe.error(l("gitView.pr.toast.titleRequired"));return}const qe=te.trim();if(!qe){fe.error(l("gitView.pr.toast.baseBranchRequired"));return}if(!le&&qe===e){fe.error(l("gitView.pr.toast.baseMustDifferFromHead"));return}xe(!0);try{const lt=cc(r),xt=le&&De,qt=await u.prCreate({directory:t,title:re,head:e,base:qe,...R.trim()?{body:R}:{},draft:P,...xt?{targetRepo:{owner:De.owner,repo:De.repo},headRemote:"origin"}:{...ae?{remote:ae.name}:{},...lt&<!==ae?.name?{headRemote:lt}:{}}});fe.success(l("gitView.pr.toast.prCreated")),z(_,Tt=>Tt&&{...Tt,pr:qt}),await Yt({force:!0}),ws()}catch(lt){const xt=lt instanceof Error?lt.message:String(lt);fe.error(l("gitView.pr.toast.createPrFailed"),{description:xt})}finally{xe(!1)}},[R,e,De,t,P,u,_,Yt,ws,ae,te,T,r,z,le,l]),ts=a.useCallback(async re=>{if(!u?.prMerge){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}oe(!0);try{const qe=await u.prMerge({directory:t,number:re.number,method:de});qe.merged?fe.success(l("gitView.pr.toast.prMerged")):fe.message(l("gitView.pr.toast.prNotMerged"),{description:qe.message||l("gitView.pr.notMergeable")}),await Yt({force:!0}),ws()}catch(qe){const lt=qe instanceof Error?qe.message:String(qe);fe.error(l("gitView.pr.toast.mergeFailed"),{description:lt}),re.url&&qa(re.url)}finally{oe(!1)}},[t,u,de,Yt,ws,l]),Js=a.useCallback(async re=>{if(!u?.prReady){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}Ae(!0);try{await u.prReady({directory:t,number:re.number}),fe.success(l("gitView.pr.toast.markedReady")),await Yt({force:!0}),ws()}catch(qe){const lt=qe instanceof Error?qe.message:String(qe);fe.error(l("gitView.pr.toast.markReadyFailed"),{description:lt}),re.url&&qa(re.url)}finally{Ae(!1)}},[t,u,Yt,ws,l]),or=a.useCallback(async re=>{if(!u?.prUpdate){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}const qe=be.trim();if(!qe){fe.error(l("gitView.pr.toast.titleRequired"));return}J(!0);try{const lt=await u.prUpdate({directory:t,number:re.number,title:qe,body:Ne});z(_,xt=>xt&&{...xt,pr:{...xt.pr??re,...lt}}),Se(!1),fe.success(l("gitView.pr.toast.prUpdated")),await Yt({force:!0}),ws()}catch(lt){const xt=lt instanceof Error?lt.message:String(lt);fe.error(l("gitView.pr.toast.updatePrFailed"),{description:xt})}finally{J(!1)}},[t,Ne,be,u,_,Yt,ws,z,l]);if(!$)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:l("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pullRequest.availableOnFeatureBranches")})]})});const zn=Re?.repo?.url||null,dn=le&&De?.url?De.url:zn,un=!!Re?.canMerge,wn=!!Re?.connected,Bs=f&&Re?.connected===!1,Fs=Jw(Re),fn=Fs?`var(--pr-${Fs})`:"var(--status-info)",Dn=Fs==="draft"?"git-pr-draft":Fs==="merged"?"git-merge":Fs==="closed"?"git-close-pull-request":"git-pull-request",on=et?[`${et.state}${et.draft?" (draft)":""}`,et.mergeable===!1?l("gitView.pr.notMergeable"):null,et.state==="open"&&typeof et.mergeableState=="string"&&et.mergeableState&&et.mergeableState!=="unknown"?et.mergeableState:null].filter(Boolean).join(" · "):"",fr=tt?tt.total>0?`${tt.success}/${tt.total} ${l("gitView.pr.checks.label")}`:`${tt.state} ${l("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[et?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{qa(et.url)},"aria-label":l("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(A,{name:Dn,className:"size-4 shrink-0",style:{color:fn}})})}),s.jsx(Nt,{children:s.jsx("p",{children:l("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(A,{name:Dn,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:l("gitView.pullRequest.title")}),et?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",et.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ie?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:Ie,onClick:()=>{Yt({force:!0})},"aria-label":l("gitView.pr.actions.refreshAria"),children:s.jsx(A,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(Nt,{children:s.jsx("p",{children:l("gitView.pr.actions.refresh")})})]})]})]}),et?s.jsxs("div",{className:"@container/pr-actions flex min-w-0 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:fn},children:on}),tt?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Bd(tt.state)}`}),fr]}):null,r&&ae&&r.split("/")[0]!==ae.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",ae.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[N?s.jsxs(He,{variant:"outline",size:"sm",className:Pe("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",ic),onClick:()=>{w(t,{kind:"pr",number:et.number}),j(t,"walkthrough")},"aria-label":l("walkthrough.action.open"),children:[s.jsx(A,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:l("walkthrough.action.open")})]}):null,un&&et.draft&&et.state==="open"?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Js(et),disabled:ue||ne||W||we,"aria-label":l("gitView.pr.actions.markReadyAria"),children:ue?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(Nt,{children:s.jsx("p",{children:l("gitView.pr.actions.markReady")})})]}):null,un?s.jsxs(s.Fragment,{children:[s.jsxs(xn,{value:de,onValueChange:re=>Fe(re),disabled:ne||et.state!=="open",children:[s.jsx(bn,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(rn,{})}),s.jsxs(yn,{children:[s.jsx(ys,{value:"squash",children:l("gitView.pr.mergeMethod.squash")}),s.jsx(ys,{value:"merge",children:l("gitView.pr.mergeMethod.merge")}),s.jsx(ys,{value:"rebase",children:l("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ts(et),disabled:ne||ue||et.state!=="open"||et.draft||W||we,"aria-label":l("gitView.pr.actions.mergePrAria"),children:ne?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-merge",className:"size-4"})})}),s.jsx(Nt,{children:s.jsx("p",{children:l("gitView.pr.actions.mergePr")})})]})]}):null]})]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Bs?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:l("gitView.pr.githubNotConnected")}),s.jsx(He,{variant:"outline",size:"sm",onClick:v,className:"w-fit",children:l("gitView.pr.actions.openSettings")})]}):null,Ke?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:Ke}),dn?s.jsx(He,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:dn,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!et&&!nt&&!Ke&&!Bs?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),l("gitView.pr.checkingStatus")]}):et?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(fi,{className:"h-full",items:[{id:"overview",label:l("gitView.pr.segment.overview")},{id:"checks",label:tt&&tt.total>0?`${l("gitView.pr.segment.checks")} ${tt.success}/${tt.total}`:l("gitView.pr.segment.checks"),icon:tt?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Bd(tt.state)}`}):void 0},{id:"comments",label:pt?`${l("gitView.pr.segment.comments")} ${(pt.issueComments?.length??0)+(pt.reviewComments?.length??0)}`:l("gitView.pr.segment.comments")}],activeId:mt,onSelect:re=>Et(re),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),mt==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[un&&et.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.draftMustBeReady")}):null,un?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.noMergePermission")}),s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:we?s.jsx(sr,{value:be,onChange:re=>q(re.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y}):s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:et.title})}),et.state==="open"?s.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:we?s.jsxs(s.Fragment,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{variant:"outline",size:"sm",className:"h-9 w-9 px-0",onClick:()=>{Se(!1),q(et.title||""),je(et.body||"")},disabled:W,"aria-label":l("gitView.pr.actions.cancelEditingAria"),children:s.jsx(A,{name:"close",className:"size-4"})})}),s.jsx(Nt,{children:s.jsx("p",{children:l("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{size:"sm",className:"h-9 w-9 px-0",onClick:()=>or(et),disabled:W||!be.trim(),"aria-label":l("gitView.pr.actions.savePrAria"),children:W?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"check",className:"size-4"})})}),s.jsx(Nt,{children:s.jsx("p",{children:l("gitView.pr.actions.savePr")})})]})]}):s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Se(!0),"aria-label":l("gitView.pr.actions.editPrAria"),children:s.jsx(A,{name:"edit",className:"size-4"})})}),s.jsx(Nt,{children:s.jsx("p",{children:l("gitView.pr.actions.editPr")})})]})}):null]}),we?s.jsx(So,{value:Ne,onChange:re=>je(re.target.value),outerClassName:"min-h-[60vh]",placeholder:l("gitView.pr.placeholder.description"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y}):null,we?null:et.body?.trim()?s.jsx(Ec,{content:et.body,className:"typography-markdown-body min-w-0 text-muted-foreground break-words",enableFileReferences:!1}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:l(Ft?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,mt==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[tt&&tt.total>0?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-muted/40",children:[tt.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${tt.success/tt.total*100}%`}}):null,tt.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${tt.failure/tt.total*100}%`}}):null,tt.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${tt.pending/tt.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[tt.success,"/",tt.total," ",l("gitView.pr.checks.label")]}),(tt.inProgress??0)>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 typography-micro text-[var(--status-warning)]",children:[s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}),Ha(tt.startedAt,void 0,it)]}):null]}):null,tt?.failure?s.jsxs(He,{variant:"outline",size:"sm",className:"w-fit gap-1.5 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:Pt,disabled:fs,"aria-label":l("gitView.pr.actions.resolveFailedChecksAria"),children:[fs?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"ai-generate-2",className:"size-4"}),l("gitView.pr.actions.resolveFailedChecks")]}):null,(pt?.checkRuns?.length??0)>0?s.jsx("div",{className:"flex flex-col gap-1.5",children:(pt?.checkRuns??[]).map((re,qe)=>{const lt=`${re.id??"run"}:${re.name}:${qe}`,xt=re.status==="in_progress",qt=re.status==="queued",Tt=Ka(re.conclusion),Ct=bt.has(lt),xs=!!(re.output?.title||re.output?.summary||re.output?.text||(re.annotations?.length??0)>0||(re.job?.steps?.length??0)>0||re.detailsUrl),As=re.job?.workflowName,as=xt?Ha(re.startedAt,void 0,it):Ha(re.startedAt,re.completedAt);return s.jsxs("div",{className:Pe("rounded-md border border-border/40",Tt&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!xs,onClick:()=>{yt(Ss=>{const Rs=new Set(Ss);return Rs.has(lt)?Rs.delete(lt):Rs.add(lt),Rs})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[xt?s.jsx(A,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):qt?s.jsx(A,{name:"time",className:"size-4 shrink-0 text-muted-foreground"}):Tt?s.jsx(A,{name:"close-circle",className:"size-4 shrink-0 text-[var(--status-error)]"}):s.jsx(A,{name:"checkbox-circle",className:"size-4 shrink-0 text-[var(--status-success)]"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:As&&As!==re.name?`${As} / ${re.name}`:re.name}),as?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:as}):null,xs?s.jsx(A,{name:"arrow-down-s",className:Pe("size-4 shrink-0 text-muted-foreground transition-transform",Ct&&"rotate-180")}):null]}),Ct&&xs?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:Zt(re,{hideHeader:!0})}):null]},lt)})}):Mt?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),l("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:l("gitView.pr.checkDetails.empty")})]}):null,mt==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Ze.length>0?s.jsx("div",{className:"flex items-center justify-end",children:s.jsxs(He,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)]",onClick:ms,disabled:Ot,"aria-label":l("gitView.pr.actions.shareCommentsAria"),children:[Ot?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(A,{name:"ai-generate-2",className:"size-3.5"}),l("gitView.pr.comments.addAll")]})}):null,Ze.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Ze.map((re,qe)=>{const lt=(re.authorName||"?").charAt(0).toUpperCase(),xt=qe===Ze.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[xt?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:re.avatarUrl?s.jsx("img",{src:re.avatarUrl,alt:re.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:lt})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[re.authorName,re.authorLogin&&re.authorLogin!==re.authorName?` · @${re.authorLogin}`:""]}),re.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:ze(re.createdAt)}):null,s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs(He,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{Ks(re)},"aria-label":l("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(A,{name:"ai-generate-2",className:"size-3.5"}),l("gitView.pr.actions.sendToAgent")]})}),s.jsx(Nt,{children:s.jsx("p",{children:l("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[re.context,re.path?` · ${re.path}`:"",re.line?`:${re.line}`:""]}),s.jsx(Ec,{content:at(re.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",st].filter(Boolean).join(" "),enableFileReferences:!1})]})]},re.id)})})}):Mt&&!pt?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),l("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:l("gitView.pr.comments.empty")})]}):null]}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",te," ",s.jsxs("span",{className:"opacity-60",children:["(",le&&De?"upstream":"remote",")"]})]})]}),dn?s.jsx(He,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:dn,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(A,{name:"external-link",className:"size-4"}),l("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.title")}),s.jsx(sr,{value:T,onChange:re=>I(re.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.baseBranch")}),ct.length>0?s.jsxs(xn,{value:te,onValueChange:Z,children:[s.jsx(bn,{size:"lg",children:s.jsx(rn,{placeholder:l("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(yn,{children:ct.map(re=>s.jsx(ys,{value:re,children:re},re))})]}):s.jsx(sr,{value:te,onChange:re=>Z(re.target.value),placeholder:l("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.description")}),s.jsx(So,{value:R,onChange:re=>L(re.target.value),className:"min-h-[110px]",placeholder:l("gitView.pr.placeholder.whatChanged"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":P,onClick:()=>G(re=>!re),onKeyDown:re=>{(re.key===" "||re.key==="Enter")&&(re.preventDefault(),G(qe=>!qe))},children:[s.jsx(oo,{size:"sm",checked:P,onChange:re=>G(re),ariaLabel:l("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:l("gitView.pr.field.draft")})]}),m?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.optional")}),s.jsx(He,{variant:"outline",size:"sm",onClick:()=>ke(!0),children:X.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),X.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:l("gitView.pr.additionalContext.added")})})]}):s.jsxs(Fo,{open:ve,onOpenChange:ie,children:[s.jsxs(bi,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:ve?l("gitView.pr.actions.hide"):X.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),s.jsx(Oo,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(So,{value:X,onChange:re=>V(re.target.value),className:"min-h-[100px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(ka,{open:ee,onClose:()=>ke(!1),title:l("gitView.pr.additionalContext.title"),footer:s.jsx(He,{size:"sm",onClick:()=>ke(!1),className:"w-full",children:l("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(So,{value:X,onChange:re=>V(re.target.value),className:"min-h-[200px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(He,{variant:"outline",size:"sm",onClick:Xs,disabled:se||Me,children:[se?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"ai-generate-2",className:"size-4 text-primary"}),l("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(He,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:An,disabled:Me||!wn||!te.trim()||!le&&te.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:Me?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(A,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:l("gitView.pr.actions.createPr")})]})]})]})]})]})},Ya=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Ai=new Map,Di=new Map,Br=t=>`${$n()}::${t}`,iv=()=>{const t=ot.c(80),{t:e}=ft(),{git:n}=_n(),r=Wr(),o=_o(r??null),i=ja(r??null),{ensureAll:c}=nn(er(av)),l=Je(lv),d=Je(cv),u=Je(dv),h=Je(uv);let f;t[0]!==r?(f=Ya(r),t[0]=r,t[1]=f):f=t[1];const p=f;let x;if(t[2]!==h||t[3]!==p||t[4]!==u){e:{if(!p){x=void 0;break e}let oe;if(t[6]!==h||t[7]!==p){let Ae;t[9]!==p?(Ae=we=>Ya(we.path)===p,t[9]=p,t[10]=Ae):Ae=t[10],oe=h.find(Ae),t[6]=h,t[7]=p,t[8]=oe}else oe=t[8];const ue=oe;if(ue){x=ue;break e}for(const Ae of u.values())if(Ya(Ae.path)===p){x=Ae;break e}x=void 0}t[2]=h,t[3]=p,t[4]=u,t[5]=x}else x=t[5];const b=x;let S;t[11]!==l||t[12]!==b||t[13]!==d?.open||t[14]!==u?(S=()=>{if(l)return u.get(l)??b;if(d?.open)return b},t[11]=l,t[12]=b,t[13]=d?.open,t[14]=u,t[15]=S):S=t[15],d?.open;let g;t[16]!==S?(g=S(),t[16]=S,t[17]=g):g=t[17];const m=g;let y;t[18]!==l?(y=oe=>l?oe.getAttachment(l):void 0,t[18]=l,t[19]=y):y=t[19];const C=$l(y),j=C&&!C.degraded&&!C.legacy?C.worktreeRoot??void 0:void 0,w=xm(r,m,o?.current??void 0);let N,v;t[20]!==r||t[21]!==c||t[22]!==n?(N=()=>{!r||!n||c(r,n)},v=[r,c,n],t[20]=r,t[21]=c,t[22]=n,t[23]=N,t[24]=v):(N=t[23],v=t[24]),a.useEffect(N,v);const[D,F]=a.useState(null);let k;t[25]!==j||t[26]!==w?.projectDirectory?(k=()=>{const oe=j||w?.projectDirectory;if(!oe){F(null);return}let ue=!1;return gi(oe).then(Ae=>{if(ue)return;const we=Ae.trim();F(we&&we!=="HEAD"?we:null)}).catch(()=>{ue||F(null)}),()=>{ue=!0}},t[25]=j,t[26]=w?.projectDirectory,t[27]=k):k=t[27];const E=w?.projectDirectory;let O;t[28]!==j||t[29]!==E?(O=[j,E],t[28]=j,t[29]=E,t[30]=O):O=t[30],a.useEffect(k,O);let M;t[31]!==r?(M=()=>(r?Ai.get(Br(r)):void 0)??[],t[31]=r,t[32]=M):M=t[32];const[B,z]=a.useState(M);let T;t[33]!==r?(T=()=>(r?Di.get(Br(r)):void 0)??null,t[33]=r,t[34]=T):T=t[34];const[I,R]=a.useState(T);let L,P;t[35]!==r||t[36]!==n?(L=()=>{if(!r||!n?.getRemotes){z([]);return}z(Ai.get(Br(r))??[]);let oe=!1;return n.getRemotes(r).then(ue=>{oe||(Ai.set(Br(r),ue??[]),z(ue??[]))}).catch(()=>{oe||z(Ai.get(Br(r))??[])}),()=>{oe=!0}},P=[r,n],t[35]=r,t[36]=n,t[37]=L,t[38]=P):(L=t[37],P=t[38]),a.useEffect(L,P);let G,X;t[39]!==r||t[40]!==n?(G=()=>{if(!r||!n?.getRemoteUrl){R(null);return}R(Di.get(Br(r))??null);let oe=!1;return n.getRemoteUrl(r).then(ue=>{oe||(Di.set(Br(r),ue),R(ue))}).catch(()=>{oe||R(Di.get(Br(r))??null)}),()=>{oe=!0}},X=[r,n],t[39]=r,t[40]=n,t[41]=G,t[42]=X):(G=t[41],X=t[42]),a.useEffect(G,X);let V;e:{if(!i?.all){let ue;t[43]===Symbol.for("react.memo_cache_sentinel")?(ue=[],t[43]=ue):ue=t[43],V=ue;break e}let oe;t[44]!==i.all?(oe=i.all.filter(fv).sort(),t[44]=i.all,t[45]=oe):oe=t[45],V=oe}const te=V;let Z;e:{if(!i?.all){let ue;t[46]===Symbol.for("react.memo_cache_sentinel")?(ue=[],t[46]=ue):ue=t[46],Z=ue;break e}let oe;t[47]!==i.all?(oe=i.all.filter(mv).map(hv).sort(),t[47]=i.all,t[48]=oe):oe=t[48],Z=oe}const de=Z;let Fe;t[49]!==de||t[50]!==I||t[51]!==B||t[52]!==o?.tracking?(Fe=()=>{if(B.length>0)return B;const oe=new Set,ue=o?.tracking?.trim();ue&&ue.includes("/")&&oe.add(ue.split("/")[0]);for(const Ae of de){const we=Ae.indexOf("/");we>0&&oe.add(Ae.slice(0,we))}return oe.size===0&&I&&oe.add("origin"),Array.from(oe).map(Ae=>({name:Ae,fetchUrl:I??"",pushUrl:I??""}))},t[49]=de,t[50]=I,t[51]=B,t[52]=o?.tracking,t[53]=Fe):Fe=t[53],o?.tracking;let se;t[54]!==Fe?(se=Fe(),t[54]=Fe,t[55]=se):se=t[55];const Q=se;w?.createdFromBranch;let Me;t[56]!==Q||t[57]!==te||t[58]!==D||t[59]!==w?.createdFromBranch?(Me=lc({remoteNames:new Set(Q.map(pv)),localBranches:te,worktreeCreatedFromBranch:w?.createdFromBranch,rootBranchHint:D}),t[56]=Q,t[57]=te,t[58]=D,t[59]=w?.createdFromBranch,t[60]=Me):Me=t[60];const xe=Me,W=o?.current??null;if(!r||!W){let oe;t[61]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(A,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[61]=oe):oe=t[61];let ue;t[62]!==e?(ue=e("gitView.pullRequest.title"),t[62]=e,t[63]=ue):ue=t[63];let Ae;t[64]!==ue?(Ae=s.jsx("div",{className:"typography-ui-header text-foreground",children:ue}),t[64]=ue,t[65]=Ae):Ae=t[65];let we;t[66]!==e?(we=e("gitView.pullRequest.createHint"),t[66]=e,t[67]=we):we=t[67];let Se;t[68]!==we?(Se=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:we}),t[68]=we,t[69]=Se):Se=t[69];let Le;return t[70]!==Ae||t[71]!==Se?(Le=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[oe,Ae,Se]}),t[70]=Ae,t[71]=Se,t[72]=Le):Le=t[72],Le}const J=o?.tracking??void 0;let ne;return t[73]!==xe||t[74]!==W||t[75]!==r||t[76]!==de||t[77]!==B||t[78]!==J?(ne=s.jsx(On,{as:Sa,outerClassName:"h-full min-h-0",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(ov,{directory:r,branch:W,baseBranch:xe,trackingBranch:J,remotes:B,remoteBranches:de})}),t[73]=xe,t[74]=W,t[75]=r,t[76]=de,t[77]=B,t[78]=J,t[79]=ne):ne=t[79],ne};function av(t){return{ensureAll:t.ensureAll}}function lv(t){return t.currentSessionId}function cv(t){return t.newSessionDraft}function dv(t){return t.worktreeMetadata}function uv(t){return t.availableWorktrees}function fv(t){return!t.startsWith("remotes/")}function mv(t){return t.startsWith("remotes/")}function hv(t){return t.replace(/^remotes\//,"")}function pv(t){return t.name}const gv=t=>{if(!t?.walkthrough)return null;const e=new Map(t.hunks.map(i=>[i.id,i])),n=new Set,r=[],o=[];for(const[i,c]of t.walkthrough.chapters.entries()){const l=[];for(const d of c.stops){const u=[],h=[];for(const p of d.hunkIds){const x=e.get(p);x?(u.push(x),n.add(p)):h.push(p)}const f={stop:d,chapter:c,chapterIndex:i,position:r.length+1,hunks:u,missingHunkIds:h,isStale:h.length>0};r.push(f),l.push(f)}o.push({chapter:c,stops:l})}return{walkthrough:t.walkthrough,stops:r,chapters:o,uncoveredHunks:t.hunks.filter(i=>!n.has(i.id)),staleStopCount:r.filter(i=>i.isStale).length,isStale:r.some(i=>i.isStale)}},xv=t=>{const e=new Map;for(const n of t){const r=e.get(n.path);if(r){r.added+=n.added,r.deleted+=n.deleted;continue}e.set(n.path,{path:n.path,added:n.added,deleted:n.deleted})}return[...e.values()]},ym=t=>{const e=[];for(const n of t){const r=e.at(-1);if(r&&r.path===n.path){r.hunks.push(n);continue}e.push({path:n.path,hunks:[n]})}return e},bv=t=>{if(t.length===0)return"";if(t.length===1)return t[0].patch;const e=t[0].patch,n=e.indexOf(`
|
|
60
|
+
@@`);if(n===-1)return e;const r=e.slice(0,n),o=t.map(i=>{const c=i.patch.indexOf(`
|
|
61
|
+
@@`);return c===-1?"":i.patch.slice(c+1)});return`${r}
|
|
62
|
+
${o.join("")}`},yv=t=>t?`${t.providerID}/${t.modelID}`:"",wv=({reason:t,model:e,requiredChars:n,availableChars:r,onRetry:o})=>{const{t:i}=ft(),c=rs(m=>m.modelsMetadata),[l,d]=$e.useState(void 0),[u,h]=$e.useState(!1),f=t==="context-too-small"||t==="structured-output-unsupported"||t==="output-exhausted";$e.useEffect(()=>{if(!f||l!==void 0)return;let m=!1;return(async()=>{try{const y=await us("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!y.ok)return;const C=await y.json().catch(()=>null);!m&&Array.isArray(C?.authenticatedProviders)&&d(C.authenticatedProviders.filter(j=>typeof j=="string"))}catch{}})(),()=>{m=!0}},[f,l]);const p=$e.useCallback(async(m,y)=>{if(!m||!y||u)return;const C=`${m}/${y}`;h(!0);try{await Ol({walkthroughModelOverride:C}),o()}catch(j){console.warn("Failed to save small model override:",j)}finally{h(!1)}},[o,u]),x=$e.useCallback((m,y)=>c.get(`${m}/${y}`)?.structured_output!==!1,[c]),b=yv(e),S=()=>{if(t==="no-model")return i("walkthrough.blocked.noModel.description");if(t==="empty-diff")return i("walkthrough.blocked.emptyDiff.description");if(t==="only-generated")return i("walkthrough.blocked.onlyGenerated.description");if(t==="server-unsupported")return i("walkthrough.blocked.serverUnsupported.description");if(t==="output-exhausted")return b?i("walkthrough.blocked.outputExhausted.description",{model:b}):i("walkthrough.blocked.outputExhausted.descriptionUnknownModel");if(t==="structured-output-unsupported")return b?i("walkthrough.blocked.structuredOutput.description",{model:b}):i("walkthrough.blocked.structuredOutput.descriptionUnknownModel");const m=Math.ceil((n??0)/1e3),y=Math.ceil((r??0)/1e3);return b?i("walkthrough.blocked.contextTooSmall.description",{model:b,required:m,available:y}):i("walkthrough.blocked.contextTooSmall.descriptionUnknownModel",{required:m,available:y})},g=()=>i(t==="no-model"?"walkthrough.blocked.noModel.title":t==="empty-diff"?"walkthrough.blocked.emptyDiff.title":t==="only-generated"?"walkthrough.blocked.onlyGenerated.title":t==="server-unsupported"?"walkthrough.blocked.serverUnsupported.title":t==="output-exhausted"?"walkthrough.blocked.outputExhausted.title":t==="structured-output-unsupported"?"walkthrough.blocked.structuredOutput.title":"walkthrough.blocked.contextTooSmall.title");return s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:[s.jsx(A,{name:t==="empty-diff"||t==="only-generated"?"information":"error-warning",className:"size-6 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:g()}),s.jsx("p",{className:"typography-meta max-w-md text-muted-foreground",children:S()}),f&&s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("walkthrough.blocked.chooseModel")}),s.jsx(Kl,{providerId:e?.providerID??"",modelId:e?.modelID??"",onChange:(m,y)=>{p(m,y)},allowedProviderIds:l??[],isModelAllowed:x})]}),(t==="empty-diff"||t==="only-generated"||t==="server-unsupported")&&s.jsx(He,{type:"button",variant:"outline",size:"sm",onClick:o,children:i("walkthrough.action.refresh")})]})},vv=[{labelKey:"walkthrough.stage.collecting"},{labelKey:"walkthrough.stage.asking"},{labelKey:"walkthrough.stage.assembling"}],jv=t=>{const e=ot.c(6),{progress:n}=t,{t:r}=ft(),{completedCount:o,activeIndex:i}=n;let c;e[0]!==i||e[1]!==o||e[2]!==r?(c=vv.map((d,u)=>{const h=u<o,f=i===u;return s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:h?s.jsx(A,{name:"check",className:"size-3.5 text-status-success"}):f?s.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin text-[var(--status-info)]"}):s.jsx("span",{className:"size-1.5 rounded-full bg-surface-muted"})}),s.jsx("span",{className:Pe("typography-meta",f?"text-foreground":h?"text-muted-foreground":"text-muted-foreground/60"),children:r(d.labelKey)})]},d.labelKey)}),e[0]=i,e[1]=o,e[2]=r,e[3]=c):c=e[3];let l;return e[4]!==c?(l=s.jsx("ul",{className:"flex flex-col gap-2 text-left",children:c}),e[4]=c,e[5]=l):l=e[5],l},ko=["collecting","asking","assembling"],Qa=450,Sv=t=>t==="retrying"?ko.indexOf("asking"):t?ko.indexOf(t):-1,kv=(t,e)=>Math.min(t+1,e),Nv=(t,e)=>{const n=ot.c(17),[r,o]=$e.useState(-1),i=$e.useRef(0);let c;n[0]!==e||n[1]!==r||n[2]!==t?(c=e?Math.max(Sv(t),0):r<0?-1:ko.length,n[0]=e,n[1]=r,n[2]=t,n[3]=c):c=n[3];const l=c;let d,u;n[4]!==e||n[5]!==r||n[6]!==l?(d=()=>{if(l<=r){l<r&&e&&(o(l),i.current=Date.now());return}const m=Date.now()-i.current,y=()=>{i.current=Date.now(),o(j=>kv(j,l))};if(r<0||m>=Qa){y();return}const C=setTimeout(y,Qa-m);return()=>clearTimeout(C)},u=[e,r,l],n[4]=e,n[5]=r,n[6]=l,n[7]=d,n[8]=u):(d=n[7],u=n[8]),$e.useEffect(d,u);let h,f;n[9]!==e||n[10]!==r?(h=()=>{if(e||r<ko.length)return;const m=setTimeout(()=>o(-1),Qa);return()=>clearTimeout(m)},f=[e,r],n[9]=e,n[10]=r,n[11]=h,n[12]=f):(h=n[11],f=n[12]),$e.useEffect(h,f);const p=r>=ko.length,x=Math.max(0,Math.min(r,ko.length)),b=p||r<0?null:r,S=!e&&r>=0;let g;return n[13]!==x||n[14]!==b||n[15]!==S?(g={completedCount:x,activeIndex:b,holding:S},n[13]=x,n[14]=b,n[15]=S,n[16]=g):g=n[16],g},wm=$e.memo(function(e){const n=ot.c(11),{path:r,hunks:o,renderSideBySide:i,wrapLines:c}=e;let l;if(n[0]!==o||n[1]!==r){const f=bv(o);l=f?nm(r,f):void 0,n[0]=o,n[1]=r,n[2]=l}else l=n[2];const d=l;if(!d)return null;let u;n[3]!==r?(u=Vl(r)||"",n[3]=r,n[4]=u):u=n[4];let h;return n[5]!==d||n[6]!==r||n[7]!==i||n[8]!==u||n[9]!==c?(h=s.jsx(ec,{original:"",modified:"",fileDiff:d,language:u,fileName:r,renderSideBySide:i,wrapLines:c,layout:"inline"}),n[5]=d,n[6]=r,n[7]=i,n[8]=u,n[9]=c,n[10]=h):h=n[10],h}),Xa=t=>`walkthrough-stop-${t}`,Cv={critical:"border border-[var(--interactive-border)] font-medium text-foreground",normal:"bg-surface-muted text-muted-foreground",context:"bg-surface-muted text-muted-foreground"},Av=t=>{const e=ot.c(22),{stopView:n}=t,{t:r}=ft(),{stop:o}=n;let i;e[0]!==n.position?(i=s.jsx("span",{className:"typography-micro flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full bg-surface-muted px-1.5 tabular-nums text-muted-foreground",children:n.position}),e[0]=n.position,e[1]=i):i=e[1];let c;e[2]!==o.title?(c=s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:o.title}),e[2]=o.title,e[3]=c):c=e[3];let l;e[4]!==o.importance||e[5]!==r?(l=o.importance!=="normal"&&s.jsxs(St,{children:[s.jsx(kt,{className:Pe("typography-micro flex h-5 items-center rounded px-1.5 leading-none",Cv[o.importance]),children:o.importance==="critical"?r("walkthrough.importance.critical"):r("walkthrough.importance.context")}),s.jsx(Nt,{className:"max-w-64",children:s.jsx("p",{className:"typography-micro leading-tight",children:o.importance==="critical"?r("walkthrough.importance.criticalHint"):r("walkthrough.importance.contextHint")})})]}),e[4]=o.importance,e[5]=r,e[6]=l):l=e[6];let d;e[7]!==i||e[8]!==c||e[9]!==l?(d=s.jsxs("div",{className:"flex items-center gap-2",children:[i,c,l]}),e[7]=i,e[8]=c,e[9]=l,e[10]=d):d=e[10];let u;e[11]!==o.prose?(u=s.jsx("p",{className:"typography-body text-muted-foreground",children:o.prose}),e[11]=o.prose,e[12]=u):u=e[12];let h;e[13]!==n.hunks||e[14]!==n.isStale||e[15]!==n.missingHunkIds||e[16]!==r?(h=n.isStale&&s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-status-warning",children:[s.jsx(A,{name:"error-warning",className:"size-3.5 shrink-0"}),n.hunks.length===0?r("walkthrough.stop.staleAll"):r("walkthrough.stop.stalePartial",{count:n.missingHunkIds.length})]}),e[13]=n.hunks,e[14]=n.isStale,e[15]=n.missingHunkIds,e[16]=r,e[17]=h):h=e[17];let f;return e[18]!==d||e[19]!==u||e[20]!==h?(f=s.jsxs("header",{className:"flex flex-col gap-2 px-4 pt-5 pb-3",children:[d,u,h]}),e[18]=d,e[19]=u,e[20]=h,e[21]=f):f=e[21],f},vm=t=>{const e=ot.c(2),{path:n}=t;let r;return e[0]!==n?(r=s.jsxs("div",{className:"sticky top-0 z-10 flex items-center gap-1.5 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 px-4 py-1.5 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:[s.jsx($o,{filePath:n,className:"size-3.5 shrink-0"}),s.jsx("span",{className:"typography-meta truncate font-mono text-foreground",children:n})]}),e[0]=n,e[1]=r):r=e[1],r},Dv=t=>{const e=ot.c(11),{hunks:n,renderSideBySide:r,wrapLines:o}=t;let i;e[0]!==n?(i=ym(n),e[0]=n,e[1]=i):i=e[1];const c=i;let l;if(e[2]!==r||e[3]!==c||e[4]!==o){let u;e[6]!==r||e[7]!==o?(u=(h,f)=>s.jsxs("div",{children:[s.jsx(vm,{path:h.path}),s.jsx(wm,{path:h.path,hunks:h.hunks,renderSideBySide:r,wrapLines:o})]},`${h.path}-${f}`),e[6]=r,e[7]=o,e[8]=u):u=e[8],l=c.map(u),e[2]=r,e[3]=c,e[4]=o,e[5]=l}else l=e[5];let d;return e[9]!==l?(d=s.jsx(s.Fragment,{children:l}),e[9]=l,e[10]=d):d=e[10],d},Pv=$e.memo(function(e){const n=ot.c(35),{view:r,activeStopId:o,scrollToStopId:i,onActiveStopChange:c,onScrollHandled:l,renderSideBySide:d,wrapLines:u}=e,{t:h}=ft(),f=$e.useRef(null),[p,x]=$e.useState(!1),b=$e.useRef(null),S=$e.useRef(null);let g,m;n[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{S.current!==null&&window.clearTimeout(S.current)},m=[],n[0]=g,n[1]=m):(g=n[0],m=n[1]),$e.useEffect(g,m);let y,C;n[2]!==l||n[3]!==i?(y=()=>{if(!i)return;const M=document.getElementById(Xa(i));M&&(b.current=i,M.scrollIntoView({behavior:"auto",block:"start"}),S.current!==null&&window.clearTimeout(S.current),S.current=window.setTimeout(()=>{b.current=null,S.current=null},250)),l()},C=[i,l],n[2]=l,n[3]=i,n[4]=y,n[5]=C):(y=n[4],C=n[5]),$e.useEffect(y,C);let j;n[6]!==c?(j=M=>{const B=M.filter(Iv).sort(Rv)[0];if(!B)return;const z=B.target.getAttribute("data-stop-id");if(!z)return;const T=b.current;if(T){z===T&&(b.current=null);return}c(z)},n[6]=c,n[7]=j):j=n[7];const w=j;let N,v;n[8]!==w||n[9]!==r.stops?(N=()=>{const M=f.current;if(!M)return;const B=new IntersectionObserver(w,{root:M,rootMargin:"0px 0px -70% 0px",threshold:0});for(const z of r.stops){const T=document.getElementById(Xa(z.stop.id));T&&B.observe(T)}return()=>B.disconnect()},v=[w,r.stops],n[8]=w,n[9]=r.stops,n[10]=N,n[11]=v):(N=n[10],v=n[11]),$e.useEffect(N,v);let D;n[12]!==r.uncoveredHunks?(D=ym(r.uncoveredHunks),n[12]=r.uncoveredHunks,n[13]=D):D=n[13];const F=D;let k;if(n[14]!==o||n[15]!==d||n[16]!==h||n[17]!==r.stops||n[18]!==u){let M;n[20]!==o||n[21]!==d||n[22]!==h||n[23]!==u?(M=B=>s.jsxs("section",{id:Xa(B.stop.id),"data-stop-id":B.stop.id,className:Pe("border-b border-border/60",o===B.stop.id&&"bg-interactive-selection/5"),children:[s.jsx(Av,{stopView:B}),B.hunks.length>0?s.jsx(Dv,{hunks:B.hunks,renderSideBySide:d,wrapLines:u}):s.jsx("p",{className:"typography-meta px-4 pb-4 text-muted-foreground",children:h("walkthrough.stop.noCode")})]},B.stop.id),n[20]=o,n[21]=d,n[22]=h,n[23]=u,n[24]=M):M=n[24],k=r.stops.map(M),n[14]=o,n[15]=d,n[16]=h,n[17]=r.stops,n[18]=u,n[19]=k}else k=n[19];let E;n[25]!==d||n[26]!==h||n[27]!==p||n[28]!==F||n[29]!==r.uncoveredHunks.length||n[30]!==u?(E=r.uncoveredHunks.length>0&&s.jsxs("section",{className:"border-b border-border/60",children:[s.jsxs(He,{type:"button",variant:"ghost",className:"h-auto w-full justify-start gap-2 px-4 py-3",onClick:()=>x(Mv),"aria-expanded":p,children:[s.jsx(A,{name:p?"arrow-down-s":"arrow-right-s",className:"size-4 shrink-0"}),s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:h("walkthrough.uncovered.title",{count:r.uncoveredHunks.length})})]}),!p&&s.jsx("p",{className:"typography-meta px-4 pb-3 pl-10 text-muted-foreground",children:h("walkthrough.uncovered.description")}),p&&F.map((M,B)=>s.jsxs("div",{children:[s.jsx(vm,{path:M.path}),s.jsx(wm,{path:M.path,hunks:M.hunks,renderSideBySide:d,wrapLines:u})]},`${M.path}-${B}`))]}),n[25]=d,n[26]=h,n[27]=p,n[28]=F,n[29]=r.uncoveredHunks.length,n[30]=u,n[31]=E):E=n[31];let O;return n[32]!==E||n[33]!==k?(O=s.jsxs("div",{ref:f,className:"min-h-0 flex-1 overflow-y-auto","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[k,E]}),n[32]=E,n[33]=k,n[34]=O):O=n[34],O});function Iv(t){return t.isIntersecting}function Rv(t,e){return t.boundingClientRect.top-e.boundingClientRect.top}function Mv(t){return!t}const Tv={bug:"bug",wrench:"tools",path:"compass-3",flask:"flask",doc:"file-text",gear:"settings-3"},Ev=t=>{const e=ot.c(30),{stopView:n,isActive:r,isVisited:o,onSelect:i,activeRef:c}=t,{t:l}=ft();let d;if(e[0]!==c||e[1]!==r||e[2]!==o||e[3]!==i||e[4]!==n.hunks||e[5]!==n.isStale||e[6]!==n.position||e[7]!==n.stop.title||e[8]!==l){const u=xv(n.hunks),h=r&&"bg-interactive-selection text-interactive-selection-foreground";let f;e[10]!==h?(f=Pe("flex w-full flex-col gap-1 rounded px-2 py-1.5 text-left transition-colors","hover:bg-interactive-hover",h),e[10]=h,e[11]=f):f=e[11];const p=r?"bg-interactive-selection-foreground/20":o?"bg-status-success/15 text-status-success":"bg-surface-muted text-muted-foreground";let x;e[12]!==p?(x=Pe("typography-micro flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full px-1 tabular-nums",p),e[12]=p,e[13]=x):x=e[13];let b;e[14]!==r||e[15]!==o||e[16]!==n.position?(b=o&&!r?s.jsx(A,{name:"check",className:"size-2.5"}):n.position,e[14]=r,e[15]=o,e[16]=n.position,e[17]=b):b=e[17];let S;e[18]!==x||e[19]!==b?(S=s.jsx("span",{className:x,children:b}),e[18]=x,e[19]=b,e[20]=S):S=e[20];let g;e[21]!==n.stop.title?(g=s.jsx("span",{className:"typography-meta truncate font-medium",children:n.stop.title}),e[21]=n.stop.title,e[22]=g):g=e[22];let m;e[23]!==n.isStale||e[24]!==l?(m=n.isStale&&s.jsx(A,{name:"error-warning",className:"size-3 shrink-0 text-status-warning","aria-label":l("walkthrough.stop.staleShort")}),e[23]=n.isStale,e[24]=l,e[25]=m):m=e[25];let y;e[26]!==S||e[27]!==g||e[28]!==m?(y=s.jsxs("span",{className:"flex items-center gap-2",children:[S,g,m]}),e[26]=S,e[27]=g,e[28]=m,e[29]=y):y=e[29],d=s.jsx("li",{children:s.jsxs("button",{ref:r?c:void 0,type:"button",onClick:i,"aria-current":r?"step":void 0,className:f,children:[y,u.length>0&&s.jsxs("span",{className:"typography-micro flex flex-col gap-0.5 pl-6 text-muted-foreground",children:[u.slice(0,3).map(Ov),u.length>3&&s.jsx("span",{children:l("walkthrough.toc.moreFiles",{count:u.length-3})})]})]})}),e[0]=c,e[1]=r,e[2]=o,e[3]=i,e[4]=n.hunks,e[5]=n.isStale,e[6]=n.position,e[7]=n.stop.title,e[8]=l,e[9]=d}else d=e[9];return d},Fv=$e.memo(function(e){const n=ot.c(20),{view:r,activeStopId:o,visitedStopIds:i,onSelectStop:c,width:l}=e,{t:d}=ft(),u=$e.useRef(null);let h;n[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{u.current?.scrollIntoView({block:"nearest"})},n[0]=h):h=n[0];let f;n[1]!==o?(f=[o],n[1]=o,n[2]=f):f=n[2],$e.useEffect(h,f);let p;n[3]!==l?(p={width:l},n[3]=l,n[4]=p):p=n[4];let x;n[5]!==r.walkthrough.focus?(x=r.walkthrough.focus&&s.jsx("p",{className:"typography-meta px-2 pb-3 pt-1 text-muted-foreground",children:r.walkthrough.focus}),n[5]=r.walkthrough.focus,n[6]=x):x=n[6];let b;n[7]!==o||n[8]!==c||n[9]!==r.chapters||n[10]!==i?(b=r.chapters.map(m=>{const{chapter:y,stops:C}=m;return s.jsxs("section",{className:"pb-3",children:[s.jsxs("h4",{className:"typography-micro flex items-center gap-1.5 px-2 py-1 font-semibold uppercase tracking-wide text-muted-foreground",children:[s.jsx(A,{name:Tv[y.icon]??"file-text",className:"size-3 shrink-0"}),s.jsx("span",{className:"truncate",children:y.title})]}),s.jsx("ul",{className:"flex flex-col gap-0.5",children:C.map(j=>s.jsx(Ev,{stopView:j,isActive:o===j.stop.id,isVisited:i.has(j.stop.id),onSelect:()=>c(j.stop.id),activeRef:u},j.stop.id))})]},y.id)}),n[7]=o,n[8]=c,n[9]=r.chapters,n[10]=i,n[11]=b):b=n[11];let S;n[12]!==d||n[13]!==r.uncoveredHunks.length?(S=r.uncoveredHunks.length>0&&s.jsx("p",{className:"typography-micro mt-auto px-2 pt-3 text-muted-foreground",children:d("walkthrough.toc.uncovered",{count:r.uncoveredHunks.length})}),n[12]=d,n[13]=r.uncoveredHunks.length,n[14]=S):S=n[14];let g;return n[15]!==p||n[16]!==x||n[17]!==b||n[18]!==S?(g=s.jsxs("nav",{className:"flex shrink-0 flex-col overflow-y-auto border-r border-border/60 p-2",style:p,children:[x,b,S]}),n[15]=p,n[16]=x,n[17]=b,n[18]=S,n[19]=g):g=n[19],g});function Ov(t){return s.jsx("span",{className:"truncate font-mono",children:t.path},t.path)}const Lv=["all","staged","working"],Bv="https://docs.openchamber.dev/walkthrough/",Ja="typography-meta font-normal text-muted-foreground",_d=720,yo=180,Za=.5,$v=680,_v=({directory:t})=>{const{t:e,locale:n,locales:r,label:o}=ft(),i=$e.useRef(null),[c,l]=$e.useState(0);$e.useEffect(()=>{const We=i.current;if(!We||typeof ResizeObserver>"u")return;const pt=new ResizeObserver(Mt=>{l(Mt[0]?.contentRect.width??0)});return pt.observe(We),()=>pt.disconnect()},[]);const d=Ee(We=>We.walkthroughTocWidth),u=Ee(We=>We.setWalkthroughTocWidth),[h,f]=$e.useState(!1),p=c===0||c>=_d,x=c>0&&c<$v,b=Math.min(Math.max(d,yo),Math.max(yo,(c||_d)*Za)),S=$e.useCallback(We=>{We.preventDefault();const pt=We.clientX,Mt=b,Et=Math.max(yo,(i.current?.clientWidth??0)*Za);f(!0);const tt=Oe=>{const Te=Math.min(Et,Math.max(yo,Mt+Oe.clientX-pt));u(Te)},pe=()=>{f(!1),window.removeEventListener("pointermove",tt),window.removeEventListener("pointerup",pe),window.removeEventListener("pointercancel",pe)};window.addEventListener("pointermove",tt),window.addEventListener("pointerup",pe),window.addEventListener("pointercancel",pe)},[u,b]),g=$e.useCallback(We=>{const pt=We.shiftKey?40:10,Mt=We.key==="ArrowLeft"?-pt:We.key==="ArrowRight"?pt:0;if(Mt===0)return;We.preventDefault();const Et=Math.max(yo,(i.current?.clientWidth??0)*Za);u(Math.min(Et,Math.max(yo,b+Mt)))},[u,b]),[m,y]=$e.useState("all"),[C,j]=$e.useState(null),[w,N]=$e.useState(null),[v,D]=$e.useState(()=>new Set),F=Ee(We=>We.diffLayoutPreference),k=Ee(We=>We.diffWrapLines),E=F==="side-by-side",O=Tn(We=>We.requestedSource[t]),M=Tn(We=>We.clearRequestedSource),B=_o(t||null),z=ja(t||null),T=B?.current??null,I=$e.useMemo(()=>{const We=T;if(!We)return null;const pt=z?.all??[],Mt=pt.filter(pe=>!pe.startsWith("remotes/")),Et=new Set(pt.filter(pe=>pe.startsWith("remotes/")).map(pe=>pe.slice(8).split("/")[0]).filter(Boolean)),tt=lc({remoteNames:Et,localBranches:Mt});return!tt||tt===We?null:{kind:"branch",baseRef:tt,headRef:We}},[z,T]),{github:R}=_n(),L=Ar(We=>We.status?.connected??!1),P=Ar(We=>We.hasChecked),G=sn(We=>We.ensureEntry),X=sn(We=>We.setParams),V=sn(We=>We.refreshTargets);$e.useEffect(()=>{if(!t||!T||!P||!L)return;const We=yi(t,T);G(We),X(We,{directory:t,branch:T,remoteName:null,canShow:!0,github:R,githubAuthChecked:P,githubConnected:L}),V([{directory:t,branch:T,remoteName:null}])},[T,t,G,R,P,L,V,X]);const te=sn(We=>t&&T?If(We.entries,t,T)?.pr?.number??null:null),Z=$e.useMemo(()=>O??{kind:"working-tree",scope:m},[O,m]),de=$e.useMemo(()=>Z.kind==="pr"?Z:te?{kind:"pr",number:te}:null,[te,Z]),Fe=$e.useCallback(We=>{M(t),y(We)},[M,t]),se=Tn(We=>We.getEntry(t,Z)),Q=Tn(We=>We.load),Me=Tn(We=>We.generate),xe=Tn(We=>We.cancel),W=Tn(We=>We.requestSource),J=Tn(We=>We.selectModel),ne=Tn(We=>We.getSelectedModel(t,Z)),oe=Tn(We=>We.selectLanguage),ue=Tn(We=>We.getSelectedLanguage(t,Z)),Ae=se.result?.language,we=ue&&r.includes(ue)?ue:Ae&&r.includes(Ae)?Ae:n;$e.useEffect(()=>{Q(t,Z,{language:we})},[we,t,Q,Z,ne]);const Se=$e.useMemo(()=>gv(se.result),[se.result]),Le=se.result?.generatedAt,Ue=$e.useRef(void 0);$e.useEffect(()=>{Ue.current!==Le&&(Ue.current=Le,D(new Set),j(Se?.stops[0]?.stop.id??null))},[Le,Se]);const be=$e.useCallback(We=>{j(We),D(pt=>{if(pt.has(We))return pt;const Mt=new Set(pt);return Mt.add(We),Mt})},[]),q=$e.useCallback(We=>{be(We),N(We)},[be]),Ne=$e.useCallback(We=>{if(!Se||Se.stops.length===0)return;const pt=Se.stops.findIndex(Et=>Et.stop.id===C),Mt=Math.min(Se.stops.length-1,Math.max(0,(pt<0?0:pt)+We));q(Se.stops[Mt].stop.id)},[C,q,Se]),[je,ve]=$e.useState(!1),[ie,ee]=$e.useState(!1),ke=Z.kind==="working-tree"?Z.scope:Z.kind,ae=Z.kind==="branch"?e("walkthrough.scope.branch"):Z.kind==="pr"?e("walkthrough.scope.pullRequest",{number:Z.number}):e(m==="all"?"walkthrough.scope.all":m==="staged"?"walkthrough.scope.staged":"walkthrough.scope.working"),U=rs(We=>We.modelsMetadata),[le,_e]=$e.useState(void 0),De=We=>!We||le===void 0?!1:le.includes(We),ce=se.readiness?.model&&se.readiness.model.hasLogin!==!1&&De(se.readiness.model.providerID)?`${se.readiness.model.providerID}/${se.readiness.model.modelID}`:void 0,he=se.result?.model&&De(se.result.model.providerID)?`${se.result.model.providerID}/${se.result.model.modelID}`:void 0,$=(ne&&De(ne.split("/")[0])?ne:void 0)??he??ce,[_,...ge]=($??"").split("/"),Ie=ge.join("/");$e.useEffect(()=>{if(le!==void 0)return;let We=!1;return(async()=>{try{const pt=await us("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!pt.ok)return;const Mt=await pt.json().catch(()=>null);!We&&Array.isArray(Mt?.authenticatedProviders)&&_e(Mt.authenticatedProviders.filter(Et=>typeof Et=="string"))}catch{}})(),()=>{We=!0}},[le]);const Re=$e.useCallback((We,pt)=>U.get(`${We}/${pt}`)?.structured_output!==!1,[U]),Ke=se.status==="generating",nt=se.result?.model?`${se.result.model.providerID}/${se.result.model.modelID}`:void 0,ct=se.result?.language,mt=ct&&r.includes(ct)?ct:void 0,gt=se.status==="ready"&&!!Se,ht=gt&&!!mt&&mt!==we,wt=gt&&!!nt&&!!$&&nt!==$,bt=Nv(se.stage,se.status==="generating"),yt=$e.useRef(!1),Dt=$e.useRef(se.status);$e.useEffect(()=>{Dt.current!=="generating"&&se.status==="generating"&&(yt.current=!Se),Dt.current=se.status},[se.status,Se]);const Kt=yt.current&&(se.status==="generating"||bt.holding),Ut=se.error?.code==="context-too-small"||se.error?.code==="structured-output-unsupported"||se.error?.code==="no-model"||se.error?.code==="empty-diff"||se.error?.code==="only-generated"||se.error?.code==="output-exhausted"||se.error?.code==="server-unsupported"?se.error.code:se.readiness&&!se.readiness.ready&&!Se&&se.readiness.reason!=="no-provider-login"?se.readiness.reason:void 0,Lt=se.error?.model??se.readiness?.model,Bt=se.error?.requiredChars??se.readiness?.requiredChars,et=se.error?.availableChars??se.readiness?.availableChars,Ht=!$||!!(se.readiness&&!se.readiness.ready),It=$e.useCallback(We=>{Ht||Me(t,Z,{force:We,language:we})},[we,t,Me,Ht,Z]);return s.jsxs("div",{ref:i,className:"flex h-full min-h-0 flex-col",children:[s.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[s.jsxs(Qs,{open:je,onOpenChange:ve,children:[s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-8 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("walkthrough.scope.selectorAria"),children:[s.jsx("span",{className:"whitespace-nowrap",children:ae}),s.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"})]})}),s.jsx(Ys,{align:"start",className:"w-48",children:s.jsxs(ml,{value:ke,onValueChange:We=>{if(ve(!1),We==="branch"){I&&W(t,I);return}if(We==="pr"){de&&W(t,de);return}Fe(We)},children:[s.jsx(Co,{className:Ja,children:e("walkthrough.scope.group.workingTree")}),Lv.map(We=>s.jsx(no,{value:We,children:e(We==="all"?"walkthrough.scope.all":We==="staged"?"walkthrough.scope.staged":"walkthrough.scope.working")},We)),(I||de)&&s.jsxs(s.Fragment,{children:[s.jsx(Ln,{}),s.jsx(Co,{className:Ja,children:e("walkthrough.scope.group.committed")})]}),I&&s.jsx(no,{value:"branch",children:e("walkthrough.scope.branch")}),de&&s.jsx(no,{value:"pr",children:e("walkthrough.scope.pullRequest",{number:de.number})})]})})]}),s.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-1",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{type:"button",variant:"ghost",size:"sm","aria-label":e("walkthrough.help.guide"),onClick:()=>{io(Bv)},children:s.jsx(A,{name:"question",className:"size-4"})})}),s.jsx(Nt,{children:s.jsx("p",{className:"typography-micro leading-tight",children:e("walkthrough.help.guide")})})]}),s.jsxs(Qs,{open:ie,onOpenChange:ee,children:[s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-8 min-w-0 flex-shrink items-center gap-1.5 rounded-md px-2 typography-ui-label text-muted-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("walkthrough.language.selectorAria"),title:x?o(we):void 0,children:[s.jsx(A,{name:"global",className:"size-4 flex-shrink-0 opacity-70"}),!x&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"truncate",children:o(we)}),s.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"})]})]})}),s.jsxs(Ys,{align:"end",className:"w-48",children:[s.jsx(Co,{className:Ja,children:e("walkthrough.language.menuLabel")}),s.jsx(ml,{value:we,onValueChange:We=>{ee(!1),oe(t,Z,We)},children:r.map(We=>s.jsx(no,{value:We,children:o(We)},We))})]})]}),s.jsx(Kl,{providerId:_??"",modelId:Ie,onChange:(We,pt)=>{J(t,Z,We&&pt?`${We}/${pt}`:null)},allowedProviderIds:le??[],isModelAllowed:Re,tooltipsEnabled:!1,dropdownPortalToBody:!0,compact:x,className:Pe("h-8 min-w-0",!x&&"max-w-48")}),Se&&s.jsxs(s.Fragment,{children:[s.jsx(He,{type:"button",variant:"ghost",size:"sm","aria-label":e("walkthrough.action.previous"),onClick:()=>Ne(-1),children:s.jsx(A,{name:"arrow-right-s",className:"size-4 rotate-180"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm","aria-label":e("walkthrough.action.next"),onClick:()=>Ne(1),children:s.jsx(A,{name:"arrow-right-s",className:"size-4"})})]}),Ke?s.jsx(He,{type:"button",variant:"outline",size:"sm","aria-label":x?e("walkthrough.action.cancel"):void 0,title:x?e("walkthrough.action.cancel"):void 0,onClick:()=>xe(t,Z),children:x?s.jsx(A,{name:"stop",className:"size-3.5"}):e("walkthrough.action.cancel")}):s.jsxs(He,{type:"button",variant:"outline",size:"sm",className:Ht?"border-border text-muted-foreground":ic,disabled:Ht,"aria-label":x?e(Se?"walkthrough.action.regenerate":"walkthrough.action.generate"):void 0,title:x?e(Se?"walkthrough.action.regenerate":"walkthrough.action.generate"):void 0,onClick:()=>It(!!Se),children:[s.jsx(A,{name:Se?"refresh":"route",className:"size-3.5"}),!x&&e(Se?"walkthrough.action.regenerate":"walkthrough.action.generate")]})]})]}),se.status==="generating"&&Se&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-[var(--status-info-background)] px-3 py-2",children:[s.jsx(A,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-info)]"}),s.jsx("span",{className:"typography-meta text-foreground",children:se.stage==="collecting"?e("walkthrough.stage.collecting"):se.stage==="assembling"?e("walkthrough.stage.assembling"):e("walkthrough.stage.asking")})]}),(ht||wt)&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-[var(--status-info-background)] px-3 py-2",children:[s.jsx(A,{name:"information",className:"size-4 shrink-0 text-[var(--status-info)]"}),s.jsx("span",{className:"typography-meta text-foreground",children:ht&&wt?e("walkthrough.missing.languageAndModel"):ht?e("walkthrough.missing.language",{requested:o(we),shown:o(mt)}):e("walkthrough.missing.model",{model:Ie})}),s.jsx(He,{type:"button",variant:"ghost",size:"xs",className:"ml-auto",disabled:Ht,onClick:()=>It(!1),children:e("walkthrough.action.generate")})]}),Se?.isStale&&se.status!=="generating"&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-status-warning/10 px-3 py-2",children:[s.jsx(A,{name:"error-warning",className:"size-4 shrink-0 text-status-warning"}),s.jsx("span",{className:"typography-meta text-foreground",children:e("walkthrough.stale.banner",{count:Se.staleStopCount})}),s.jsx(He,{type:"button",variant:"ghost",size:"xs",className:"ml-auto",disabled:Ke,onClick:()=>It(!0),children:e("walkthrough.action.regenerate")})]}),se.error&&!Ut&&se.error.code!=="no-provider-login"&&s.jsxs("div",{className:"flex shrink-0 items-start gap-2 border-b border-border/60 bg-status-error/10 px-3 py-2",children:[s.jsx(A,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-status-error"}),s.jsx("span",{className:"typography-meta line-clamp-2 text-foreground",title:se.error.message,children:se.error.message})]}),s.jsx("div",{className:Pe("flex min-h-0 flex-1",p?"flex-row":"flex-col"),children:Ut?s.jsx(wv,{reason:Ut,model:Lt,requiredChars:Bt,availableChars:et,onRetry:()=>{Q(t,Z)}}):Kt?s.jsx("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8",children:s.jsx(jv,{progress:bt})}):Se?s.jsxs(s.Fragment,{children:[p&&s.jsxs(s.Fragment,{children:[s.jsx(Fv,{view:Se,activeStopId:C,visitedStopIds:v,onSelectStop:q,width:b}),s.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":e("walkthrough.toc.resize"),tabIndex:0,onPointerDown:S,onKeyDown:g,className:Pe("group relative w-1 shrink-0 cursor-col-resize","before:absolute before:inset-y-0 before:-left-1 before:-right-1 before:content-['']","hover:bg-interactive-selection focus-visible:bg-interactive-selection focus-visible:outline-none",h&&"bg-interactive-selection")})]}),s.jsx(Pv,{view:Se,activeStopId:C,scrollToStopId:w,onActiveStopChange:be,onScrollHandled:()=>N(null),renderSideBySide:E,wrapLines:k})]}):s.jsx("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:se.status==="loading"?s.jsx(A,{name:"loader-4",className:"size-6 animate-spin text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"route",className:"size-6 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:e("walkthrough.empty.title")}),s.jsx("p",{className:"typography-meta max-w-md text-muted-foreground",children:e("walkthrough.empty.description")})]})})})]})},zv=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),tn=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},jm=(t,e)=>{const n=tn(e),r=tn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Vv=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Wv=new Set(["node_modules"]),Uv=t=>Wv.has(t),Hv=t=>{const e=tn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Kv=8,dr=new Map,dc=t=>JSON.stringify([$n(),t]),Gv=t=>{const e=dc(t),n=dr.get(e);return n?(n.touchedAt=Date.now(),dr.delete(e),dr.set(e,n),n):null},el=t=>{const e=dc(t),n=dr.get(e);if(n)return n.touchedAt=Date.now(),n;if(dr.size>=Kv){const o=dr.keys().next().value;o!==void 0&&dr.delete(o)}const r={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return dr.set(e,r),r},qv=t=>{dr.delete(dc(t))},Sm=(t,e)=>s.jsx($o,{filePath:t,extension:e}),Yv=t=>{const e=ot.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let i;return e[1]!==o?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=i):i=e[2],i},Qv=t=>{const e=ot.c(66),{node:n,root:r,isExpanded:o,isActive:i,isBrowserClient:c,status:l,badge:d,permissions:u,downloadFile:h,onSelect:f,onToggle:p,onRevealPath:x,onOpenDialog:b}=t,{t:S}=ft(),g=n.type==="directory",{canRename:m,canCreateFile:y,canCreateFolder:C,canDelete:j,canReveal:w}=u,N=!g&&!!h,v=w&&!c,D=m||y||C||j||N||v,[F,k]=a.useState(!1),[E,O]=a.useState(!1);let M;e[0]!==D?(M=oe=>{D&&(oe?.preventDefault(),O(!0))},e[0]=D,e[1]=M):M=e[1];const B=M;let z;e[2]!==g||e[3]!==n||e[4]!==f||e[5]!==p?(z=()=>{g?p(n.path):f(n)},e[2]=g,e[3]=n,e[4]=f,e[5]=p,e[6]=z):z=e[6];const T=z;let I;e[7]===Symbol.for("react.memo_cache_sentinel")?(I=oe=>{oe.stopPropagation(),O(!1),k(!0)},e[7]=I):I=e[7];const R=I;let L;e[8]!==y||e[9]!==C||e[10]!==j||e[11]!==m||e[12]!==v||e[13]!==h||e[14]!==c||e[15]!==g||e[16]!==n||e[17]!==b||e[18]!==x||e[19]!==S?(L=oe=>{const{Item:ue,Separator:Ae}=oe;return s.jsxs(s.Fragment,{children:[m&&s.jsxs(ue,{onClick:we=>{we.stopPropagation(),b("rename",n)},children:[s.jsx(A,{name:"edit",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.rename")]}),s.jsxs(ue,{onClick:we=>{we.stopPropagation(),tr(n.path).then(Se=>{if(Se.ok){fe.success(S("sidebarFilesTree.toast.pathCopied"));return}fe.error(S("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(A,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.copyPath")]}),!g&&h&&s.jsxs(ue,{onClick:we=>{we.stopPropagation(),h(n.path).catch(Se=>{console.error("Download failed:",Se),fe.error(S("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(A,{name:"download",className:"mr-2 h-4 w-4"})," ",S(c?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),v&&s.jsxs(ue,{onClick:we=>{we.stopPropagation(),x(n.path)},children:[s.jsx(A,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",S(Zu())]}),g&&(y||C)&&s.jsxs(s.Fragment,{children:[s.jsx(Ae,{}),y&&s.jsxs(ue,{onClick:we=>{we.stopPropagation(),b("createFile",n)},children:[s.jsx(A,{name:"file-add",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.newFile")]}),C&&s.jsxs(ue,{onClick:we=>{we.stopPropagation(),b("createFolder",n)},children:[s.jsx(A,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.newFolder")]})]}),j&&s.jsxs(s.Fragment,{children:[s.jsx(Ae,{}),s.jsxs(ue,{onClick:we=>{we.stopPropagation(),b("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.delete")]})]})]})},e[8]=y,e[9]=C,e[10]=j,e[11]=m,e[12]=v,e[13]=h,e[14]=c,e[15]=g,e[16]=n,e[17]=b,e[18]=x,e[19]=S,e[20]=L):L=e[20];const P=L;let G;e[21]!==n.path||e[22]!==r?(G=oe=>{const ue=jm(r,n.path);!ue||ue==="."||(oe.dataTransfer.setData("application/x-openchamber-file-path",ue),oe.dataTransfer.effectAllowed="copy")},e[21]=n.path,e[22]=r,e[23]=G):G=e[23];const X=G;let V;e[24]!==B?(V=s.jsx("div",{className:"group relative flex items-center",onContextMenu:B}),e[24]=B,e[25]=V):V=e[25];const te=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Z;e[26]!==te?(Z=Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",te,"cursor-grab active:cursor-grabbing"),e[26]=te,e[27]=Z):Z=e[27];let de;e[28]!==g||e[29]!==o||e[30]!==n.extension||e[31]!==n.path?(de=g?o?s.jsx(A,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):s.jsx(A,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):Sm(n.path,n.extension),e[28]=g,e[29]=o,e[30]=n.extension,e[31]=n.path,e[32]=de):de=e[32];let Fe;e[33]!==n.name||e[34]!==n.path?(Fe=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[33]=n.name,e[34]=n.path,e[35]=Fe):Fe=e[35];let se;e[36]!==g||e[37]!==l?(se=!g&&l&&s.jsx(Yv,{status:l}),e[36]=g,e[37]=l,e[38]=se):se=e[38];let Q;e[39]!==d||e[40]!==g?(Q=g&&d&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[d.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",d.modified]}),d.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",d.added]})]}),e[39]=d,e[40]=g,e[41]=Q):Q=e[41];let Me;e[42]!==B||e[43]!==X||e[44]!==T||e[45]!==Fe||e[46]!==se||e[47]!==Q||e[48]!==Z||e[49]!==de?(Me=s.jsxs("button",{type:"button",onClick:T,onContextMenu:B,draggable:!0,onDragStart:X,className:Z,children:[de,Fe,se,Q]}),e[42]=B,e[43]=X,e[44]=T,e[45]=Fe,e[46]=se,e[47]=Q,e[48]=Z,e[49]=de,e[50]=Me):Me=e[50];let xe;e[51]!==F||e[52]!==D||e[53]!==P||e[54]!==S?(xe=D&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(Qs,{open:F,onOpenChange:k,children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(qs,{asChild:!0,children:s.jsx(He,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:R,title:S("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":S("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(A,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(Nt,{side:"bottom",sideOffset:6,children:S("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(Ys,{align:"end",side:"bottom",onCloseAutoFocus:()=>k(!1),children:P({Item:is,Separator:Ln})})]})}),e[51]=F,e[52]=D,e[53]=P,e[54]=S,e[55]=xe):xe=e[55];let W;e[56]!==Me||e[57]!==xe||e[58]!==V?(W=s.jsxs(Tf,{render:V,children:[Me,xe]}),e[56]=Me,e[57]=xe,e[58]=V,e[59]=W):W=e[59];let J;e[60]!==P?(J=s.jsx(Rf,{className:"min-w-[180px]",children:P({Item:Mf,Separator:yx})}),e[60]=P,e[61]=J):J=e[61];let ne;return e[62]!==E||e[63]!==W||e[64]!==J?(ne=s.jsxs(Ef,{open:E,onOpenChange:O,children:[W,J]}),e[62]=E,e[63]=W,e[64]=J,e[65]=ne):ne=e[65],ne},Xv=(t,e)=>t.node===e.node&&t.root===e.root&&t.isExpanded===e.isExpanded&&t.isActive===e.isActive&&t.isBrowserClient===e.isBrowserClient&&t.status===e.status&&t.badge===e.badge&&t.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog,Jv=a.memo(Qv,Xv),Zv=()=>{const{t}=ft(),{files:e,runtime:n}=_n(),r=Ph(n.platform),o=Wr()??"",i=tn(o.trim()),c=Ih(),l=Rh(),d=Qu(U=>U.searchFiles),u=Ee(U=>U.openContextFile),h=_o(o),[f,p]=a.useState(""),x=Gl(f,200),b=a.useRef(null),[S,g]=a.useState([]),[m,y]=a.useState(!1),[C,j]=a.useState({}),[w,N]=a.useState({}),v=a.useRef(new Set),D=a.useRef(new Set),F=a.useRef(null);a.useEffect(()=>{if(!i){j({}),N({}),v.current=new Set;return}const U=Gv(i);U?(j({...U.childrenByDir}),N({...U.loadErrorsByDir}),v.current=new Set(U.loadedDirs)):(j({}),N({}),v.current=new Set)},[i]),a.useEffect(()=>{if(!i)return;const U=el(i);U.childrenByDir=C},[i,C]),a.useEffect(()=>{if(!i)return;const U=el(i);U.loadErrorsByDir=w},[i,w]),a.useEffect(()=>{if(!i)return;const U=el(i);U.loadedDirs=new Set(v.current)},[i,C,w]),a.useEffect(()=>()=>{if(!i)return;const U=dr.get(i);U&&U.loadedDirs.size===0&&Object.keys(U.childrenByDir).length===0&&qv(i)},[i]);const k=a.useMemo(()=>[],[]),E=a.useMemo(()=>[],[]),O=vr(U=>i?U.byRoot[i]?.expandedPaths??k:k),M=vr(U=>i?U.byRoot[i]?.selectedPath??null:null),B=vr(U=>U.setSelectedPath),z=vr(U=>U.addOpenPath),T=vr(U=>U.removeOpenPathsByPrefix),I=vr(U=>U.toggleExpandedPath),R=vr(U=>U.collapseAllExpandedPaths),L=Ee(U=>i?U.contextPanelByDirectory[i]?.tabs??E:E),P=a.useMemo(()=>new Set(L.map(U=>U.mode==="file"?U.targetPath:null).filter(U=>typeof U=="string"&&U.length>0).map(U=>tn(U))),[L]),[G,X]=a.useState(null),[V,te]=a.useState(null),[Z,de]=a.useState(""),[Fe,se]=a.useState(!1),Q=!!e.writeFile,Me=!!e.createDirectory,xe=!!e.rename,W=!!e.delete,J=!!e.revealPath,ne=a.useMemo(()=>({canRename:xe,canCreateFile:Q,canCreateFolder:Me,canDelete:W,canReveal:J}),[xe,Q,Me,W,J]),oe=a.useCallback(U=>{e.revealPath&&e.revealPath(U).catch(()=>{fe.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),ue=a.useCallback((U,le)=>{X(U),te(le),de(U==="rename"&&le.name||""),se(!1)},[]),Ae=a.useCallback((U,le)=>{const _e=le.filter(De=>De&&typeof De.name=="string"&&De.name.length>0).filter(De=>c||!De.name.startsWith(".")).filter(De=>l||!Uv(De.name)).map(De=>{const ce=De.name,he=tn(De.path||""),me=he?Vv(he)?he:tn(`${U}/${he}`):tn(`${U}/${ce}`),$=De.isDirectory?"directory":"file",_=$==="file"&&ce.includes(".")?ce.split(".").pop()?.toLowerCase():void 0;return{name:ce,path:me,type:$,extension:_}});return zv(_e)},[l,c]),we=a.useCallback(async(U,le)=>{const _e=tn(U.trim());if(!_e||v.current.has(_e)||D.current.has(_e))return;D.current=new Set(D.current),D.current.add(_e);const De=e.listDirectory?e.listDirectory(_e).then(ce=>ce.entries.map(he=>({name:he.name,path:he.path,isDirectory:he.isDirectory}))):Fn.listLocalDirectory(_e).then(ce=>ce.map(he=>({name:he.name,path:he.path,isDirectory:he.isDirectory})));try{const ce=await De;if(le?.())return;const he=Ae(_e,ce);v.current=new Set(v.current),v.current.add(_e),N(me=>{if(!me[_e])return me;const $={...me};return delete $[_e],$}),j(me=>({...me,[_e]:he}))}catch(ce){if(le?.())return;const he=ce instanceof Error?ce.message:String(ce??"");console.error("Failed to load sidebar directory:",ce),N(me=>({...me,[_e]:he}))}finally{D.current=new Set(D.current),D.current.delete(_e)}},[e,Ae]),Se=a.useCallback(async()=>{if(!i)return;F.current?.abort();const U=new AbortController;F.current=U;try{const _e=(vr.getState().byRoot[i]?.expandedPaths??[]).map(he=>tn(he)).filter(he=>!!he&&he!==i&&he.startsWith(`${i}/`)),De=[i,..._e];v.current=new Set(v.current);for(const he of De)v.current.delete(he);N(he=>{if(Object.keys(he).length===0)return he;const me={...he};let $=!1;for(const _ of De)_ in me&&(delete me[_],$=!0);return $?me:he});const ce=()=>U.signal.aborted;await we(i,ce);for(let he=0;he<_e.length&&!U.signal.aborted;he+=3){const me=_e.slice(he,he+3);await Promise.all(me.map($=>we($,ce)))}}catch(le){if(U.signal.aborted)return;console.error("Failed to refresh sidebar tree:",le)}finally{F.current===U&&(F.current=null)}},[we,i]),Le=a.useCallback(async U=>{if(!U){await Se();return}const le=tn(U);v.current=new Set(v.current),v.current.delete(le),D.current=new Set(D.current),D.current.delete(le),await we(le)},[we,Se]);a.useEffect(()=>{i&&(F.current?.abort(),v.current=new Set,D.current=new Set,N({}),j(U=>Object.keys(U).length===0?U:{}),we(i))},[we,i,c,l]),a.useEffect(()=>{if(!i||O.length===0)return;const U=O.map(De=>tn(De)).filter(De=>!!De&&De!==i&&De.startsWith(`${i}/`)&&!v.current.has(De)&&!D.current.has(De)).sort((De,ce)=>De.split("/").length-ce.split("/").length);if(U.length===0)return;let le=!1;const _e=()=>le;return(async()=>{for(let De=0;De<U.length&&!le;De+=3){const ce=U.slice(De,De+3);await Promise.all(ce.map(he=>we(he,_e)))}})(),()=>{le=!0}},[O,we,i]),a.useEffect(()=>{if(!o){g([]),y(!1);return}const U=x.trim();if(!U){g([]),y(!1);return}let le=!1;return y(!0),d(o,U,150,{includeHidden:c,respectGitignore:!l,type:"file"}).then(_e=>{if(le)return;const ce=_e.filter(he=>l||!Hv(he.path)).map(he=>({name:he.name,path:tn(he.path),type:"file",extension:he.extension,relativePath:he.relativePath}));g(ce)}).catch(()=>{le||g([])}).finally(()=>{le||y(!1)}),()=>{le=!0}},[o,x,d,c,l]);const Ue=a.useMemo(()=>{const U=new Map;if(!h?.files)return U;for(const le of h.files)le.index==="A"||le.working_dir==="?"?U.set(le.path,"git-added"):le.index==="D"?U.set(le.path,"git-deleted"):(le.index==="M"||le.working_dir==="M")&&U.set(le.path,"git-modified");return U},[h]),be=a.useMemo(()=>{const U=new Map;if(!h?.files||!i)return U;for(const le of h.files){const _e=le.index==="M"||le.working_dir==="M",De=le.index==="A"||le.working_dir==="?";if(!_e&&!De)continue;const ce=le.path.split("/");if(ce.length<=1)continue;let he=i;for(let me=0;me<ce.length-1;me++){he=`${he}/${ce[me]}`;let $=U.get(he);$||($={modified:0,added:0},U.set(he,$)),_e&&$.modified++,De&&$.added++}}return U},[h,i]),q=a.useCallback(U=>{if(P.has(U))return"open";if(Ue.size===0)return null;const le=U.startsWith(i+"/")?U.slice(i.length+1):U;return Ue.get(le)??null},[P,Ue,i]),Ne=a.useCallback(U=>{if(be.size===0)return null;const le=be.get(U);return le&&le.modified+le.added>0?le:null},[be]),je=a.useCallback(async U=>{if(!i)return;const le=await rc(e,U.path,{directory:i});if(!le.ok){fe.error(oc(le.reason));return}B(i,U.path),z(i,U.path),u(i,U.path)},[z,e,u,i,B]),ve=a.useCallback(async U=>{const le=tn(U);i&&(I(i,le),v.current.has(le)||await we(le))},[we,i,I]),ie=a.useCallback(async U=>{if(U?.preventDefault(),!V||!G)return;se(!0);const le=()=>se(!1),_e=()=>X(null);if(G==="createFile"){if(!Z.trim()){fe.error(t("sidebarFilesTree.toast.filenameRequired")),le();return}if(!e.writeFile){fe.error(t("sidebarFilesTree.toast.writeNotSupported")),le();return}const De=V.path,ce=De?`${De}/`:"",he=tn(`${ce}${Z.trim()}`);await e.writeFile(he,"").then(async me=>{me.success&&(fe.success(t("sidebarFilesTree.toast.fileCreated")),await Le(De)),_e()}).catch(()=>fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(le);return}if(G==="createFolder"){if(!Z.trim()){fe.error(t("sidebarFilesTree.toast.folderNameRequired")),le();return}const De=V.path,ce=De?`${De}/`:"",he=tn(`${ce}${Z.trim()}`);await e.createDirectory(he).then(async me=>{me.success&&(fe.success(t("sidebarFilesTree.toast.folderCreated")),await Le(De)),_e()}).catch(()=>fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(le);return}if(G==="rename"){if(!Z.trim()){fe.error(t("sidebarFilesTree.toast.nameRequired")),le();return}if(!e.rename){fe.error(t("sidebarFilesTree.toast.renameNotSupported")),le();return}const De=V.path,ce=De.split("/").slice(0,-1).join("/"),he=ce?`${ce}/`:"",me=tn(`${he}${Z.trim()}`);await e.rename(De,me).then(async $=>{$.success&&(fe.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await Le(ce),i&&T(i,De),(M===De||M&&M.startsWith(`${De}/`))&&B(i,null)),_e()}).catch(()=>fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(le);return}if(G==="delete"){if(!e.delete){fe.error(t("sidebarFilesTree.toast.deleteNotSupported")),le();return}const De=V.path,ce=De.split("/").slice(0,-1).join("/");await e.delete(De).then(async he=>{he.success&&(fe.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await Le(ce),i&&T(i,De),(M===De||M&&M.startsWith(De+"/"))&&B(i,null)),_e()}).catch(()=>fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(le);return}le()},[G,V,Z,e,Le,T,i,M,B,t]);function ee(U,le){const _e=C[U]??[];return _e.map((De,ce)=>{const he=De.type==="directory",me=he&&O.includes(De.path),$=M===De.path,_=ce===_e.length-1;return s.jsxs("li",{className:"relative",children:[le>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),_&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(Jv,{node:De,root:i,isExpanded:me,isActive:$,isBrowserClient:r,status:he?void 0:q(De.path),badge:he?Ne(De.path):void 0,permissions:ne,downloadFile:e.downloadFile,onSelect:je,onToggle:ve,onRevealPath:oe,onOpenDialog:ue}),he&&me&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[w[De.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:w[De.path],children:w[De.path]}),s.jsxs(He,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Le(De.path)},children:[s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,ee(De.path,le+1)]})]},De.path)})}const ke=!!(i&&C[i]),ae=i?w[i]:null;return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[Q&&s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>ue("createFile",{path:o,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFileTitle"),"aria-label":t("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(A,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(Nt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),Me&&s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>ue("createFolder",{path:o,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFolderTitle"),"aria-label":t("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(A,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(Nt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>{Se()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(A,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(Nt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>{i&&R(i)},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.collapseAllTitle"),"aria-label":t("sidebarFilesTree.actions.collapseAllTitle"),children:s.jsx(A,{name:"collapse-vertical",className:"h-4 w-4"})})})}),s.jsx(Nt,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.collapseAllTitle")})]})]}),s.jsxs("div",{className:"relative min-w-0",children:[s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(sr,{ref:b,value:f,onChange:U=>p(U.target.value),placeholder:t("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),f.trim().length>0?s.jsx("button",{type:"button","aria-label":t("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{p(""),b.current?.focus()},children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null]})]}),s.jsx(On,{outerClassName:"flex-1 min-h-0",className:"p-2",children:s.jsx("ul",{className:"flex flex-col",children:m?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("sidebarFilesTree.state.searching")]}):S.length>0?S.map(U=>{const le=M===U.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>je(U),draggable:!0,onDragStart:_e=>{const De=U.relativePath||jm(i??"",U.path);!De||De==="."||(_e.dataTransfer.setData("application/x-openchamber-file-path",De),_e.dataTransfer.effectAllowed="copy")},className:Pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",le?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:U.path,children:[Sm(U.path,U.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:U.relativePath??U.path})]})},U.path)}):ae?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:ae}),s.jsxs(He,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{Se()},children:[s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):ke&&i?ee(i,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),s.jsx(Ps,{open:!!G,onOpenChange:U=>!U&&X(null),children:s.jsxs(Is,{children:[s.jsxs(Us,{children:[s.jsxs(Ls,{children:[G==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),G==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),G==="rename"&&t("sidebarFilesTree.dialog.rename.title"),G==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(Hs,{children:[G==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:V?.path??t("sidebarFilesTree.dialog.rootFallback")}),G==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:V?.path??t("sidebarFilesTree.dialog.rootFallback")}),G==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:V?.name??""}),G==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:V?.name??""})]})]}),G!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(sr,{value:Z,onChange:U=>de(U.target.value),placeholder:t(G==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:U=>{U.key==="Enter"&&ie()},autoFocus:!0})}),s.jsxs(rr,{children:[s.jsx(He,{variant:"outline",onClick:()=>X(null),disabled:Fe,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(He,{variant:G==="delete"?"destructive":"default",onClick:()=>{ie()},disabled:Fe||G!=="delete"&&!Z.trim(),children:Fe?s.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):t(G==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},uc=t=>t,Nl=t=>{const e=uc(t).type;return typeof e=="string"?e:""},e1=t=>{const e=uc(t).tool;return typeof e=="string"?e:""},t1=t=>{const e=uc(t).text;return typeof e=="string"?e:""},s1=t=>{const e=Nl(t);return e==="tool"?e1(t).trim().toLowerCase()||"tool":e||"unknown"},n1=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=s1(n);e.includes(r)||e.push(r)}return e.join(" + ")},r1=t=>t.replace(/\s+/g," ").trim(),o1=t=>{for(const n of t)if(Nl(n)==="text"){const r=r1(t1(n));if(r.length===0)continue;return r}const e=t.filter(n=>Nl(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},i1=(t,e,n)=>`${n(t)} / ${n(e)}`,a1=t=>{if(t==="12h")return!0;if(t==="24h")return!1},l1=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=a1(e);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:n===!1?"2-digit":"numeric",minute:"2-digit",...n===void 0?{}:{hour12:n}})},Cl={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},zi={user:0,assistant:0,tool:0,other:0},Zr=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,tl=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(u=>u.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Cl,total:Zr(n)};if(!n||typeof n!="object")return Cl;const r=n,o=Zr(r.input),i=Zr(r.output),c=Zr(r.reasoning),l=Zr(r.cache?.read),d=Zr(r.cache?.write);return{input:o,output:i,reasoning:c,cacheRead:l,cacheWrite:d,total:o+i+c+l+d}},c1=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},En=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+En(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+En(n),0):0,d1=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...zi,assistant:En(n.text)+En(n.content)};const o=c1(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:En(n.input)+En(n.output)+En(n.error)+En(n.call?.input)+En(n.call?.output)+En(n.call?.error)+En(n.raw)+Math.round(En(n.metadata)*.25)+Math.round(En(n.state)*.1),other:0}:e==="user"?{user:o.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},zd=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),u1=t=>{const e=xi(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},f1=(t,e)=>{if(t.length===0)return{...zi};const n=t.reduce((r,o)=>{const i=u1(o);let c={...zi};for(const l of o.parts)c=zd(c,d1(l,i));return zd(r,c)},{...zi});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},eo=t=>t.toLocaleString(ai()),m1=t=>!Number.isFinite(t)||t<=0?new Intl.NumberFormat(ai(),{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(ai(),{style:"currency",currency:"USD",minimumFractionDigits:t<.01?4:2,maximumFractionDigits:t<.01?4:2}).format(t),h1=(t,e)=>!t||!Number.isFinite(t)?"-":Hl(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),p1=(t,e,n)=>{const r=t.find(i=>i.id===e),o=r?.models?.find(i=>i.id===n);return{providerName:r?.name||e||"-",modelName:o?.name||n||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},g1=()=>{const t=ot.c(203),{t:e}=ft(),n=Ee(x1);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[o,i]=a.useState(r),[c,l]=a.useState(null),d=a.useRef(null),u=Je(b1),h=Je(y1),f=cf(h??void 0),p=Op(u??"",h??void 0),x=rs(w1);let b;t[1]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null),i(v1),l(null)},t[1]=b):b=t[1];let S;t[2]!==h||t[3]!==u?(S=[h,u],t[2]=h,t[3]=u,t[4]=S):S=t[4],a.useEffect(b,S);let g,m;t[5]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},m=[],t[5]=g,t[6]=m):(g=t[5],m=t[6]),a.useEffect(g,m);let y;t[7]===Symbol.for("react.memo_cache_sentinel")?(y=async(tt,pe)=>{(await tr(pe)).ok?(l(tt),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{l(Te=>Te===tt?null:Te),d.current=null},2e3)):l(null)},t[7]=y):y=t[7];const C=y;let j;t[8]!==u||t[9]!==f?(j=u?f.find(tt=>tt.id===u)??null:null,t[8]=u,t[9]=f,t[10]=j):j=t[10];const w=j;let N,v,D,F,k,E;if(t[11]!==x||t[12]!==p){N=p.filter(j1);let tt;t[19]!==p?(tt=p.filter(S1),t[19]=p,t[20]=tt):tt=t[20],E=tt;let pe=null;for(let Te=N.length-1;Te>=0;Te=Te-1,Te){const it=N[Te];if(tl(it).total>0){pe=it;break}}F=pe?tl(pe):Cl,v=Lp({input:F.input,cache:{read:F.cacheRead,write:F.cacheWrite}}),k=N.reduce(k1,0);const Oe=pe?.info??null;D=p1(x,Oe?.providerID||"",Oe?.modelID||""),t[11]=x,t[12]=p,t[13]=N,t[14]=v,t[15]=D,t[16]=F,t[17]=k,t[18]=E}else N=t[13],v=t[14],D=t[15],F=t[16],k=t[17],E=t[18];const O=D,M=O.contextLimit,B=M&&M>0?Math.min(999,F.total/M*100):0;let z;if(t[21]!==p){const tt=[...p].reverse().find(N1)?.info?.system||"";z=f1(p,tt),t[21]=p,t[22]=z}else z=t[22];const T=z,I=T.user,R=T.assistant,L=T.tool,P=Math.max(0,F.input-I-R-L),G=I+R+L+P,X=p[0]?.info?.time?.created,V=p.length>0?p[p.length-1]?.info?.time?.created:null;let te;t[23]!==w?.title||t[24]!==e?(te=w?.title||e("contextSidebar.session.untitled"),t[23]=w?.title,t[24]=e,t[25]=te):te=t[25];const Z=w?.time?.created??X??null,de=V??w?.time?.created??null;let Fe;t[26]!==R||t[27]!==P||t[28]!==L||t[29]!==I?(Fe={user:I,assistant:R,tool:L,other:P},t[26]=R,t[27]=P,t[28]=L,t[29]=I,t[30]=Fe):Fe=t[30];let se;t[31]!==N.length||t[32]!==G||t[33]!==v||t[34]!==M||t[35]!==O||t[36]!==p.length||t[37]!==Z||t[38]!==de||t[39]!==Fe||t[40]!==te||t[41]!==F||t[42]!==k||t[43]!==B||t[44]!==E.length?(se={sessionTitle:te,messagesCount:p.length,userMessagesCount:E.length,assistantMessagesCount:N.length,createdAt:Z,lastActivityAt:de,providerModel:O,tokenBreakdown:F,usagePercent:B,cacheHitRate:v,totalAssistantCost:k,contextLimit:M,breakdown:Fe,breakdownTotal:G},t[31]=N.length,t[32]=G,t[33]=v,t[34]=M,t[35]=O,t[36]=p.length,t[37]=Z,t[38]=de,t[39]=Fe,t[40]=te,t[41]=F,t[42]=k,t[43]=B,t[44]=E.length,t[45]=se):se=t[45];const Q=se;if(!u){let tt;t[46]!==e?(tt=e("contextSidebar.empty.openSession"),t[46]=e,t[47]=tt):tt=t[47];let pe;return t[48]!==tt?(pe=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:tt}),t[48]=tt,t[49]=pe):pe=t[49],pe}let Me;t[50]!==e?(Me=e("contextSidebar.breakdown.user"),t[50]=e,t[51]=Me):Me=t[51];let xe;t[52]!==Me||t[53]!==Q.breakdown.user?(xe={key:"user",label:Me,value:Q.breakdown.user,color:"var(--status-success)"},t[52]=Me,t[53]=Q.breakdown.user,t[54]=xe):xe=t[54];let W;t[55]!==e?(W=e("contextSidebar.breakdown.assistant"),t[55]=e,t[56]=W):W=t[56];let J;t[57]!==W||t[58]!==Q.breakdown.assistant?(J={key:"assistant",label:W,value:Q.breakdown.assistant,color:"var(--primary-base)"},t[57]=W,t[58]=Q.breakdown.assistant,t[59]=J):J=t[59];let ne;t[60]!==e?(ne=e("contextSidebar.breakdown.toolCalls"),t[60]=e,t[61]=ne):ne=t[61];let oe;t[62]!==ne||t[63]!==Q.breakdown.tool?(oe={key:"tool",label:ne,value:Q.breakdown.tool,color:"var(--status-warning)"},t[62]=ne,t[63]=Q.breakdown.tool,t[64]=oe):oe=t[64];let ue;t[65]!==e?(ue=e("contextSidebar.breakdown.other"),t[65]=e,t[66]=ue):ue=t[66];let Ae;t[67]!==ue||t[68]!==Q.breakdown.other?(Ae={key:"other",label:ue,value:Q.breakdown.other,color:"var(--surface-muted-foreground)"},t[67]=ue,t[68]=Q.breakdown.other,t[69]=Ae):Ae=t[69];let we;t[70]!==xe||t[71]!==J||t[72]!==oe||t[73]!==Ae?(we=[xe,J,oe,Ae],t[70]=xe,t[71]=J,t[72]=oe,t[73]=Ae,t[74]=we):we=t[74];const Se=we;let Le;t[75]!==Q.sessionTitle?(Le=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Q.sessionTitle}),t[75]=Q.sessionTitle,t[76]=Le):Le=t[76];let Ue;t[77]!==Q.providerModel.modelName||t[78]!==Q.providerModel.providerName?(Ue=s.jsxs("span",{children:[Q.providerModel.providerName," / ",Q.providerModel.modelName]}),t[77]=Q.providerModel.modelName,t[78]=Q.providerModel.providerName,t[79]=Ue):Ue=t[79];let be;t[80]!==n||t[81]!==Q.createdAt?(be=Q.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:h1(Q.createdAt,n)})]}),t[80]=n,t[81]=Q.createdAt,t[82]=be):be=t[82];let q;t[83]!==Ue||t[84]!==be?(q=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[Ue,be]}),t[83]=Ue,t[84]=be,t[85]=q):q=t[85];let Ne;t[86]!==Le||t[87]!==q?(Ne=s.jsxs("div",{className:"mb-6",children:[Le,q]}),t[86]=Le,t[87]=q,t[88]=Ne):Ne=t[88];let je;t[89]!==e?(je=e("contextSidebar.section.context"),t[89]=e,t[90]=je):je=t[90];let ve;t[91]!==je?(ve=s.jsx("span",{className:"typography-micro text-muted-foreground",children:je}),t[91]=je,t[92]=ve):ve=t[92];let ie;t[93]!==Q.tokenBreakdown.total?(ie=eo(Q.tokenBreakdown.total),t[93]=Q.tokenBreakdown.total,t[94]=ie):ie=t[94];let ee;t[95]!==Q.contextLimit?(ee=Q.contextLimit?` / ${eo(Q.contextLimit)}`:"",t[95]=Q.contextLimit,t[96]=ee):ee=t[96];let ke;t[97]!==ie||t[98]!==ee?(ke=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ie,ee]}),t[97]=ie,t[98]=ee,t[99]=ke):ke=t[99];let ae;t[100]!==ve||t[101]!==ke?(ae=s.jsxs("div",{className:"flex items-baseline justify-between",children:[ve,ke]}),t[100]=ve,t[101]=ke,t[102]=ae):ae=t[102];let U;t[103]!==Q.usagePercent?(U=Q.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,Q.usagePercent)}%`,backgroundColor:Q.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[103]=Q.usagePercent,t[104]=U):U=t[104];let le;t[105]!==U?(le=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:U}),t[105]=U,t[106]=le):le=t[106];let _e;t[107]!==e||t[108]!==Q.usagePercent?(_e=e("contextSidebar.context.percentUsed",{percent:Q.usagePercent.toFixed(1)}),t[107]=e,t[108]=Q.usagePercent,t[109]=_e):_e=t[109];let De;t[110]!==_e?(De=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:_e}),t[110]=_e,t[111]=De):De=t[111];let ce;t[112]!==ae||t[113]!==le||t[114]!==De?(ce=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[ae,le,De]}),t[112]=ae,t[113]=le,t[114]=De,t[115]=ce):ce=t[115];let he;t[116]!==e?(he=e("contextSidebar.stats.messages"),t[116]=e,t[117]=he):he=t[117];let me;t[118]!==Q.messagesCount?(me=eo(Q.messagesCount),t[118]=Q.messagesCount,t[119]=me):me=t[119];let $;t[120]!==he||t[121]!==me?($={label:he,value:me},t[120]=he,t[121]=me,t[122]=$):$=t[122];let _;t[123]!==e?(_=e("contextSidebar.stats.user"),t[123]=e,t[124]=_):_=t[124];let ge;t[125]!==Q.userMessagesCount?(ge=eo(Q.userMessagesCount),t[125]=Q.userMessagesCount,t[126]=ge):ge=t[126];let Ie;t[127]!==_||t[128]!==ge?(Ie={label:_,value:ge},t[127]=_,t[128]=ge,t[129]=Ie):Ie=t[129];let Re;t[130]!==e?(Re=e("contextSidebar.stats.assistant"),t[130]=e,t[131]=Re):Re=t[131];let Ke;t[132]!==Q.assistantMessagesCount?(Ke=eo(Q.assistantMessagesCount),t[132]=Q.assistantMessagesCount,t[133]=Ke):Ke=t[133];let nt;t[134]!==Re||t[135]!==Ke?(nt={label:Re,value:Ke},t[134]=Re,t[135]=Ke,t[136]=nt):nt=t[136];let ct;t[137]!==e?(ct=e("contextSidebar.stats.cost"),t[137]=e,t[138]=ct):ct=t[138];let mt;t[139]!==Q.totalAssistantCost?(mt=m1(Q.totalAssistantCost),t[139]=Q.totalAssistantCost,t[140]=mt):mt=t[140];let gt;t[141]!==ct||t[142]!==mt?(gt={label:ct,value:mt},t[141]=ct,t[142]=mt,t[143]=gt):gt=t[143];let ht;t[144]!==$||t[145]!==Ie||t[146]!==nt||t[147]!==gt?(ht=[$,Ie,nt,gt],t[144]=$,t[145]=Ie,t[146]=nt,t[147]=gt,t[148]=ht):ht=t[148];const wt=ht;let bt;t[149]!==wt?(bt=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:wt.map(C1)}),t[149]=wt,t[150]=bt):bt=t[150];let yt;t[151]!==e?(yt=e("contextSidebar.section.lastAssistantMessage"),t[151]=e,t[152]=yt):yt=t[152];let Dt;t[153]!==yt?(Dt=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:yt}),t[153]=yt,t[154]=Dt):Dt=t[154];let Kt;t[155]!==e||t[156]!==Q.cacheHitRate.hasInput||t[157]!==Q.cacheHitRate.percent||t[158]!==Q.tokenBreakdown.cacheRead||t[159]!==Q.tokenBreakdown.cacheWrite||t[160]!==Q.tokenBreakdown.input||t[161]!==Q.tokenBreakdown.output||t[162]!==Q.tokenBreakdown.reasoning?(Kt=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:Q.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:Q.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:Q.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:Q.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:Q.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:Q.cacheHitRate.hasInput?Q.cacheHitRate.percent:null,format:"percent"}].map(A1)}),t[155]=e,t[156]=Q.cacheHitRate.hasInput,t[157]=Q.cacheHitRate.percent,t[158]=Q.tokenBreakdown.cacheRead,t[159]=Q.tokenBreakdown.cacheWrite,t[160]=Q.tokenBreakdown.input,t[161]=Q.tokenBreakdown.output,t[162]=Q.tokenBreakdown.reasoning,t[163]=Kt):Kt=t[163];let Ut;t[164]!==Dt||t[165]!==Kt?(Ut=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Dt,Kt]}),t[164]=Dt,t[165]=Kt,t[166]=Ut):Ut=t[166];let Lt;t[167]!==Se||t[168]!==Q.breakdownTotal?(Lt=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Se.map(tt=>tt.value<=0||Q.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${tt.value/Q.breakdownTotal*100}%`,backgroundColor:tt.color}},tt.key))}),t[167]=Se,t[168]=Q.breakdownTotal,t[169]=Lt):Lt=t[169];let Bt;t[170]!==Se||t[171]!==Q.breakdownTotal?(Bt=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:Se.map(tt=>{const pe=Q.breakdownTotal>0?tt.value/Q.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:tt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[tt.label," ",s.jsxs("span",{className:"tabular-nums",children:[pe.toFixed(0),"%"]})]})]},tt.key)})}),t[170]=Se,t[171]=Q.breakdownTotal,t[172]=Bt):Bt=t[172];let et;t[173]!==Lt||t[174]!==Bt?(et=s.jsxs("div",{className:"mb-6",children:[Lt,Bt]}),t[173]=Lt,t[174]=Bt,t[175]=et):et=t[175];let Ht;t[176]!==e?(Ht=e("contextSidebar.section.rawMessages"),t[176]=e,t[177]=Ht):Ht=t[177];let It;t[178]!==Ht?(It=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ht}),t[178]=Ht,t[179]=It):It=t[179];let We;if(t[180]!==c||t[181]!==o||t[182]!==p||t[183]!==e||t[184]!==n){let tt;t[186]!==c||t[187]!==o||t[188]!==e||t[189]!==n?(tt=pe=>{const Te=xi(pe.info).role,it=Te==="assistant",ut=Te==="user",Gt=o[pe.info.id]===!0,Ft=c===pe.info.id,ze=pe.info.time?.created??null,Qe=n1(pe.parts),st=it?tl({info:pe.info,parts:pe.parts}):null,at=ut?o1(pe.parts):"",Ze=l1(ze,n),At=Qe||"—",Rt=st?i1(st.input,st.output,eo):"",Zt=Te||"unknown",fs=Qe?`${Zt}: ${Qe}`:Zt,ls=Gt?JSON.stringify({info:pe.info,parts:pe.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":Gt,onClick:()=>{i(Ot=>({...Ot,[pe.info.id]:Ot[pe.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:it?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[ut?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",at]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:it?At:fs}),it&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Rt})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:Ze})]})}),Gt&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:Ot=>{Ot.stopPropagation(),C(pe.info.id,ls)},"aria-label":e(Ft?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Ft?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Ft?s.jsx(A,{name:"check",className:"size-3.5"}):s.jsx(A,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Bp,{language:"json",code:ls,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},pe.info.id)},t[186]=c,t[187]=o,t[188]=e,t[189]=n,t[190]=tt):tt=t[190],We=[...p].reverse().map(tt),t[180]=c,t[181]=o,t[182]=p,t[183]=e,t[184]=n,t[185]=We}else We=t[185];let pt;t[191]!==We?(pt=s.jsx("div",{className:"mt-2.5 space-y-1",children:We}),t[191]=We,t[192]=pt):pt=t[192];let Mt;t[193]!==It||t[194]!==pt?(Mt=s.jsxs("div",{children:[It,pt]}),t[193]=It,t[194]=pt,t[195]=Mt):Mt=t[195];let Et;return t[196]!==Ne||t[197]!==ce||t[198]!==bt||t[199]!==Ut||t[200]!==et||t[201]!==Mt?(Et=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Ne,ce,bt,Ut,et,Mt]})}),t[196]=Ne,t[197]=ce,t[198]=bt,t[199]=Ut,t[200]=et,t[201]=Mt,t[202]=Et):Et=t[202],Et};function x1(t){return t.timeFormatPreference}function b1(t){return t.currentSessionId}function y1(t){return t.currentSessionDirectory}function w1(t){return t.providers}function v1(t){return Object.keys(t).length>0?{}:t}function j1(t){return xi(t.info).role==="assistant"}function S1(t){return xi(t.info).isUser}function k1(t,e){const n=Zr(e.info.cost);return t+n}function N1(t){return xi(t.info).isUser&&typeof t.info.system=="string"}function C1(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function A1(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value!==null&&t.value!==void 0?t.format==="percent"?`${t.value.toFixed(1)}%`:eo(t.value):"—"})]},t.label)}const D1="x-openchamber-preview-target-error",P1=t=>{const e=t.get(D1);return e==="missing"||e==="expired"||e==="invalid-token"?e:null},I1=(t,e)=>P1(t)?e?"stop-retrying":"retry-registration":"none",fc=[{id:"context",descriptionKey:"contextRail.surface.context.description",defaultWidthFraction:.45,mode:"context",icon:"donut-chart-fill",labelKey:"contextPanel.mode.context",availability:"always"},{id:"git",descriptionKey:"contextRail.surface.git.description",defaultWidthFraction:2/5,mode:"git",icon:"git-branch",labelKey:"layout.rightSidebar.git",availability:"always"},{id:"pr",descriptionKey:"contextRail.surface.pr.description",defaultWidthFraction:.45,mode:"pr",icon:"github",labelKey:"contextPanel.mode.pr",availability:"always"},{id:"diff",descriptionKey:"contextRail.surface.diff.description",defaultWidthFraction:3/5,mode:"diff",icon:"arrow-left-right",labelKey:"contextPanel.mode.diff",availability:"always"},{id:"walkthrough",descriptionKey:"contextRail.surface.walkthrough.description",defaultWidthFraction:3/5,mode:"walkthrough",icon:"route",labelKey:"contextPanel.mode.walkthrough",availability:"always"},{id:"editor",descriptionKey:"contextRail.surface.editor.description",defaultWidthFraction:3/5,mode:"file",icon:"braces",labelKey:"contextPanel.mode.files",availability:"always"},{id:"terminal",descriptionKey:"contextRail.surface.terminal.description",defaultWidthFraction:3/5,mode:"terminal",icon:"terminal-box",labelKey:"layout.mainTab.terminal",availability:"always"},{id:"notes",descriptionKey:"contextRail.surface.notes.description",defaultWidthFraction:1/3,mode:"notes",icon:"sticky-note",labelKey:"contextRail.surface.notes",availability:"always"},{id:"plan",descriptionKey:"contextRail.surface.plan.description",defaultWidthFraction:.45,mode:"plan",icon:"file-text",labelKey:"contextPanel.mode.plan",availability:"always"},{id:"browser",descriptionKey:"contextRail.surface.browser.description",defaultWidthFraction:.45,mode:"browser",icon:"global",labelKey:"contextPanel.mode.browser",availability:"always"},{id:"preview",descriptionKey:"contextRail.surface.preview.description",defaultWidthFraction:.45,mode:"preview",icon:"window",labelKey:"contextPanel.mode.preview",availability:"has-content"},{id:"chat",descriptionKey:"contextRail.surface.chat.description",defaultWidthFraction:.45,mode:"chat",icon:"chat-4",labelKey:"contextPanel.mode.chat",availability:"has-content"}],km=new Map(fc.map(t=>[t.id,t])),R1=new Map(fc.map(t=>[t.mode,t.defaultWidthFraction])),M1=t=>R1.get(t)??1/2,T1=t=>typeof t=="string"&&km.has(t),Vd=t=>{const e=[],n=new Set;for(const r of t){if(!T1(r)||n.has(r))continue;const o=km.get(r);o&&(n.add(r),e.push(o))}for(const r of fc)n.has(r.id)||e.push(r);return e},E1=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.x=="number"&&typeof e.y=="number"},Wd=t=>!t||typeof t!="object"?!1:Object.values(t).every(e=>typeof e=="string"),Po=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.text=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"&&E1(e.center)&&Wd(e.attributes)&&Wd(e.computedStyle)&&Array.isArray(e.ancestry)},mc=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:o,intro:i})=>{const c=r.text.trim(),l=Object.entries(r.attributes).map(([x,b])=>`${x}="${b}"`).join(" "),d=r.computedStyle,u=r.bounds,h=r.center,f=i.replace(/[.:]+$/g,""),p=r.ancestry.map(x=>x.selectorPart).join(" > ");return[`${f}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${r.tag}`,c?`Text: ${c}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,p?`- Ancestry: ${p}`:null,l?`- Attributes: ${l}`:null,`- Bounds: x=${Math.round(u.x)}, y=${Math.round(u.y)}, width=${Math.round(u.width)}, height=${Math.round(u.height)}`,`- Center: x=${Math.round(h.x)}, y=${Math.round(h.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(x=>typeof x=="string").join(`
|
|
63
|
+
`)},Nm=async(t,e)=>{if(typeof window<"u")try{const n=t.getBoundingClientRect(),r=await Cr("desktop_capture_page_rect",{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw new Error("Desktop screenshot capture is not available");const o=new Image;await new Promise((b,S)=>{o.onload=()=>b(),o.onerror=()=>S(new Error("Failed to load desktop preview screenshot")),o.src=`data:${r.mime};base64,${r.base64}`});const i=Math.max(1,o.naturalWidth||r.width||Math.floor(n.width)),c=Math.max(1,o.naturalHeight||r.height||Math.floor(n.height)),d=Math.min(1,1200/i),u=document.createElement("canvas");u.width=Math.floor(i*d),u.height=Math.floor(c*d);const h=u.getContext("2d");if(!h)return null;h.scale(d,d),h.drawImage(o,0,0,i,c);const f=i/Math.max(1,n.width),p=c/Math.max(1,n.height);h.fillStyle="rgba(37, 99, 235, 0.28)",h.strokeStyle="rgb(37, 99, 235)",h.lineWidth=Math.max(2,2*f),h.fillRect(e.bounds.x*f,e.bounds.y*p,e.bounds.width*f,e.bounds.height*p),h.strokeRect(e.bounds.x*f,e.bounds.y*p,e.bounds.width*f,e.bounds.height*p);const x=await new Promise(b=>u.toBlob(b,"image/jpeg",.82));return x?new File([x],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(n){return console.warn("[preview] failed to capture annotation screenshot:",n),null}return await Y1(t,e)},hc=async(t,e,n,r,o,i)=>{if(!t)return null;try{const c=new Image;await new Promise((g,m)=>{c.onload=()=>g(),c.onerror=()=>m(new Error("Failed to load desktop browser screenshot")),c.src=`data:image/jpeg;base64,${t}`});const l=Math.max(1,c.naturalWidth||e),d=Math.max(1,c.naturalHeight||n),h=Math.min(1,1200/l),f=document.createElement("canvas");f.width=Math.floor(l*h),f.height=Math.floor(d*h);const p=f.getContext("2d");if(!p)return null;p.scale(h,h),p.drawImage(c,0,0,l,d);const x=l/Math.max(1,r||l),b=d/Math.max(1,o||d);p.fillStyle="rgba(37, 99, 235, 0.14)",p.strokeStyle="rgb(37, 99, 235)",p.lineWidth=Math.max(2,2*x),p.fillRect(i.bounds.x*x,i.bounds.y*b,i.bounds.width*x,i.bounds.height*b),p.strokeRect(i.bounds.x*x,i.bounds.y*b,i.bounds.width*x,i.bounds.height*b);const S=await new Promise(g=>f.toBlob(g,"image/jpeg",.82));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Io="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",Cn=new Map,sl=new Map,F1=3e4,pc=t=>{const e=Cn.get(t);return e?e.expiresAt-Date.now()<=F1?(Cn.delete(t),null):e:null},O1=t=>{try{return new URL(t).origin}catch{return t}};function Cm(t){const e="#ffffff",n=t.defaultView??window;try{const r=t.body?n.getComputedStyle(t.body).backgroundColor:"";if(r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent")return r;const o=n.getComputedStyle(t.documentElement).backgroundColor;if(o&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent")return o}catch{}return e}const Am=t=>new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(typeof r.result=="string"?r.result:Io),r.onerror=()=>n(r.error??new Error("Failed to read image blob")),r.readAsDataURL(t)}),L1=async(t,e=.82)=>{const n=await new Promise(r=>t.toBlob(r,"image/jpeg",e));return n&&(await Am(n)).split(",",2)[1]||""},B1=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Vi=(...t)=>{B1()&&console.info("[preview-capture]",...t)},Dm=(t,e=8)=>{const n=[];try{const r=t.querySelectorAll("*");for(const o of r){const i=o.scrollTop||0,c=o.scrollLeft||0;if(i<=0&&c<=0)continue;const l=o.tagName.toLowerCase(),d=o.id?`#${o.id}`:"",u=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(n.push({selector:`${l}${d}${u}`,scrollTop:i,scrollLeft:c,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),n.length>=e)break}}catch{}return n},ri="data-oc-fixed-pin",$1=(t,e,n)=>{if(e<=0&&n<=0)return()=>{};const r=t.defaultView;if(!r)return()=>{};const o=[],i=[];try{for(const c of t.querySelectorAll("*")){if(r.getComputedStyle(c).position!=="fixed")continue;const l=c.getBoundingClientRect();if(!(l.width>0&&l.height>0))continue;c.setAttribute(ri,JSON.stringify({top:l.top+n,left:l.left+e,width:l.width,height:l.height})),o.push(c);const d=c.tagName.toLowerCase(),u=typeof c.className=="string"&&c.className?`.${c.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";i.push({selector:`${d}${u}`,top:Math.round(l.top),left:Math.round(l.left),width:Math.round(l.width),height:Math.round(l.height)})}}catch{}return Vi("tagged fixed elements",i),()=>{for(const c of o)try{c.removeAttribute(ri)}catch{}}},_1={name:"oc-fixed-pin",afterClone(t){const e=t?.clone;if(!(!e||typeof e.querySelectorAll!="function"))for(const n of e.querySelectorAll(`[${ri}]`)){let r;try{r=JSON.parse(n.getAttribute(ri)||"")}catch{continue}n.style.setProperty("position","absolute","important"),n.style.setProperty("top",`${r.top}px`,"important"),n.style.setProperty("left",`${r.left}px`,"important"),n.style.setProperty("right","auto","important"),n.style.setProperty("bottom","auto","important"),n.style.setProperty("width",`${r.width}px`,"important"),n.style.setProperty("height",`${r.height}px`,"important"),n.removeAttribute(ri)}}},No="data-oc-scroll-pin",z1=t=>{const e=[],n=Dm(t,64);try{const i=t.documentElement,c=t.body;for(const l of t.querySelectorAll("*")){const d=l.scrollTop||0,u=l.scrollLeft||0;if(d<=0&&u<=0)continue;const h=l!==i&&l!==c;h&&l.setAttribute(No,JSON.stringify({top:d,left:u})),e.push({el:l,top:d,left:u,tagged:h})}}catch{}return{reapply:()=>{for(const i of e)try{i.el.scrollHeight,i.el.scrollTop!==i.top&&(i.el.scrollTop=i.top),i.el.scrollLeft!==i.left&&(i.el.scrollLeft=i.left)}catch{}},cleanup:()=>{for(const i of e)if(i.tagged)try{i.el.removeAttribute(No)}catch{}},snapshot:n}},V1={name:"oc-nested-scroll",afterClone(t){const e=t?.clone;if(!e||typeof e.querySelectorAll!="function")return;const n=e.ownerDocument;if(n)for(const r of e.querySelectorAll(`[${No}]`)){let o;try{o=JSON.parse(r.getAttribute(No)||"")}catch{r.removeAttribute(No);continue}const i=`translate(${-o.left}px, ${-o.top}px)`,c=r.children.length===1&&r.firstElementChild instanceof HTMLElement&&r.firstElementChild.style.willChange==="transform"?r.firstElementChild:null;if(c)c.style.transform=i;else{r.style.overflow="hidden";const l=n.createElement("div");for(l.style.transform=i,l.style.willChange="transform",l.style.display="inline-block",l.style.width="100%";r.firstChild;)l.appendChild(r.firstChild);r.appendChild(l)}r.removeAttribute(No)}}},nl=async(t,e)=>{try{const n=await fetch(t,{credentials:e});return n.ok?await Am(await n.blob()):null}catch{return null}},W1=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const e=t.origin,n=pc(e);if(n)return`${n.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const r=sl.get(e),o=r??(async()=>{try{const c=await us("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!c.ok)return Cn.delete(e),null;const l=await c.json(),d=typeof l.proxyBasePath=="string"?l.proxyBasePath:"",u=typeof l.expiresAt=="number"?l.expiresAt:0;if(!d)return Cn.delete(e),null;const h={proxyBasePath:d,expiresAt:u};return Cn.set(e,h),h}catch{return Cn.delete(e),null}finally{sl.delete(e)}})();r||sl.set(e,o);const i=await o;return i?`${i.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},Pm=async(t,e)=>{if(!t||t.startsWith("data:"))return t;try{const n=new URL(t,e.baseURI);if(n.origin===window.location.origin||n.protocol!=="http:"&&n.protocol!=="https:")return await nl(n.toString(),"include")??Io;const r=await W1(n),o=r?await nl(r,"include"):null;return o||(await nl(n.toString(),"omit")??Io)}catch{return Io}},U1=async(t,e)=>{if(!t||t==="none"||!t.includes("url("))return t;const n=Array.from(t.matchAll(/url\((['"]?)(.*?)\1\)/g));let r=t;for(const o of n){const i=o[2]||"";if(!i||i.startsWith("data:"))continue;const c=await Pm(i,e);r=r.replace(o[0],`url("${c}")`)}return r},Ud=t=>t.complete?Promise.resolve():new Promise(e=>{t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0})}),Im=t=>{const e=t.style.cssText;return()=>{t.style.cssText=e}},H1=t=>{const e=Number.parseFloat(t.lineHeight);if(Number.isFinite(e)&&e>0)return e;const n=Number.parseFloat(t.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},K1=(t,e,n)=>{const r=[],o=t.defaultView??window,c=Array.from(t.querySelectorAll('button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *'));for(const l of c){const d=l.textContent?.replace(/\s+/g," ").trim()??"";if(!d||!d.includes(" "))continue;const u=l.getBoundingClientRect();if(u.width<=0||u.height<=0||u.right<0||u.bottom<0||u.left>e||u.top>n)continue;const h=o.getComputedStyle(l);if(h.display==="none"||h.visibility==="hidden"||Number(h.opacity)===0)continue;const f=h.getPropertyValue("text-wrap"),p=h.getPropertyValue("text-wrap-mode"),x=h.whiteSpace.includes("nowrap")||f==="nowrap"||p==="nowrap",b=u.height<=H1(h)*1.7;!x&&(!b||u.width>e*.72)||(r.push(Im(l)),l.style.whiteSpace="nowrap",l.style.overflowWrap="normal",l.style.wordBreak="normal",l.style.setProperty("text-wrap","nowrap"),l.style.setProperty("text-wrap-mode","nowrap"))}return()=>{for(let l=r.length-1;l>=0;l-=1)r[l]?.()}},G1=(t,e,n,r)=>{const o=[],i=t.defaultView??window,c=i.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,l=i.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,d=Array.from(t.querySelectorAll("*")).filter(u=>{const h=i.getComputedStyle(u);if(h.position!=="fixed"||h.display==="none"||h.visibility==="hidden"||Number(h.opacity)===0)return!1;const f=u.getBoundingClientRect();return f.width>0&&f.height>0&&f.right>=0&&f.bottom>=0&&f.left<=e&&f.top<=n}).filter((u,h,f)=>!f.some((p,x)=>x<h&&p.contains(u)));for(const u of d){const h=u.getBoundingClientRect(),f=i.getComputedStyle(u),p=Math.ceil(h.width)+8,x=Math.ceil(h.height)+2;r?.add(u),o.push(Im(u)),u.style.position="absolute",u.style.top=`${h.top+l}px`,u.style.left=`${h.left+c}px`,u.style.right="auto",u.style.bottom="auto",u.style.width=`${p}px`,u.style.minWidth=`${p}px`,u.style.height=`${x}px`,u.style.minHeight=`${x}px`,u.style.margin="0",u.style.boxSizing="border-box",u.style.transform="none",f.zIndex!=="auto"&&(u.style.zIndex=f.zIndex)}return()=>{for(let u=o.length-1;u>=0;u-=1)o[u]?.()}},Rm=async(t,e,n,r={})=>{const o=[],i=t.defaultView??window,c=f=>{if(f===t.documentElement||f===t.body)return!0;try{const p=f.getBoundingClientRect();return p.width>0&&p.height>0&&p.right>=0&&p.bottom>=0&&p.left<=e&&p.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){const f=new WeakSet;o.push(G1(t,e,n,f)),o.push(K1(t,e,n))}const l=new Map;for(const f of Array.from(t.images))l.set(f,f.currentSrc||f.src||f.getAttribute("src")||"");const d=Array.from(t.querySelectorAll("picture"));for(const f of d){const p=Array.from(f.querySelectorAll("source"));if(p.length===0)continue;const x=p.map(b=>({source:b,srcset:b.getAttribute("srcset"),sizes:b.getAttribute("sizes")}));o.push(()=>{for(const b of x)b.srcset===null?b.source.removeAttribute("srcset"):b.source.setAttribute("srcset",b.srcset),b.sizes===null?b.source.removeAttribute("sizes"):b.source.setAttribute("sizes",b.sizes)});for(const b of p)b.removeAttribute("srcset"),b.removeAttribute("sizes")}const u=Array.from(t.images).filter(f=>c(f));await Promise.all(u.map(async f=>{const p=l.get(f)||f.currentSrc||f.src||f.getAttribute("src")||"";if(!p)return;await Ud(f);const x=await Pm(p,t),b={src:f.getAttribute("src"),srcset:f.getAttribute("srcset"),sizes:f.getAttribute("sizes")};o.push(()=>{b.src===null?f.removeAttribute("src"):f.setAttribute("src",b.src),b.srcset===null?f.removeAttribute("srcset"):f.setAttribute("srcset",b.srcset),b.sizes===null?f.removeAttribute("sizes"):f.setAttribute("sizes",b.sizes)}),f.removeAttribute("srcset"),f.removeAttribute("sizes"),f.setAttribute("src",x||Io),await Ud(f)}));const h=Array.from(t.querySelectorAll("*")).filter(c);return await Promise.all(h.map(async f=>{const p=i.getComputedStyle(f).backgroundImage;if(!p||p==="none"||!p.includes("url("))return;const x=await U1(p,t);if(x===p)return;const b=f.style.backgroundImage;o.push(()=>{f.style.backgroundImage=b}),f.style.backgroundImage=x})),()=>{for(let f=o.length-1;f>=0;f-=1)try{o[f]?.()}catch{}}};async function q1(t,e){try{const n=t.contentWindow,r=t.contentDocument??n?.document,o=r?.documentElement;if(!n||!r||!o)return null;const i=t.getBoundingClientRect(),c=Math.max(1,Math.ceil(n.innerWidth||t.clientWidth||i.width)),l=Math.max(1,Math.ceil(n.innerHeight||t.clientHeight||i.height)),d=r.body,u=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,h=n.scrollX||0,f=n.scrollY||0,p=n.pageXOffset||0,x=n.pageYOffset||0,b=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,S=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,g=o.scrollLeft||0,m=o.scrollTop||0,y=d?.scrollLeft||0,C=d?.scrollTop||0,j=u?.scrollLeft||0,w=u?.scrollTop||0,N=Math.max(h,p,b,g,y,j),v=Math.max(f,x,S,m,C,w);Vi("scroll sources",{windowScrollX:h,windowScrollY:f,pageScrollX:p,pageScrollY:x,visualViewportScrollX:b,visualViewportScrollY:S,rootScrollX:g,rootScrollY:m,bodyScrollX:y,bodyScrollY:C,scrollingElementScrollX:j,scrollingElementScrollY:w,scrollingElementTag:u?.tagName?.toLowerCase()??null,resolvedScrollX:N,resolvedScrollY:v,nestedScrolledElements:Dm(r)});const D=Math.max(c,o.scrollWidth||0,d?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),F=Math.max(l,o.scrollHeight||0,d?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),k=Math.min(2,Math.max(1,window.devicePixelRatio||1)),E=o.style.scrollBehavior,O=d?.style.scrollBehavior??"";o.style.scrollBehavior="auto",d&&(d.style.scrollBehavior="auto");const M=z1(r);Vi("nested scroll snapshot",M.snapshot);let B=()=>{},z=()=>{};try{await r.fonts?.ready.catch(()=>{}),B=await Rm(r,c,l,{applyLayoutWorkarounds:!1}),n.scrollTo(N,v),z=$1(r,N,v),M.reapply();const{snapdom:T}=await Bo(async()=>{const{snapdom:xe}=await import("./vendor-zumer-snapdom-Btyu_Xi2.js");return{snapdom:xe}},[]),I={backgroundColor:Cm(r),cache:"disabled",dpr:k,embedFonts:!0,fast:!1,height:F,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[_1,V1],quality:.82,width:D},L=await(await T(o,I)).toCanvas();if(!L.width||!L.height)return null;const P=L.width/Math.max(1,D),G=L.height/Math.max(1,F),X=Math.min(L.width,Math.max(1,Math.round(c*P))),V=Math.min(L.height,Math.max(1,Math.round(l*G))),te=Math.max(0,L.width-X),Z=Math.max(0,L.height-V),de=Math.min(te,Math.max(0,Math.round(N*P))),Fe=Math.min(Z,Math.max(0,Math.round(v*G)));Vi("capture geometry",{viewportWidth:c,viewportHeight:l,captureWidth:D,captureHeight:F,canvasWidth:L.width,canvasHeight:L.height,xScale:P,yScale:G,sourceX:de,sourceY:Fe,sourceWidth:X,sourceHeight:V});const se=r.createElement("canvas");se.width=X,se.height=V;const Q=se.getContext("2d");if(!Q)return null;Q.drawImage(L,de,Fe,X,V,0,0,X,V);const Me=await L1(se,.82);return Me?await hc(Me,c,l,c,l,e):null}finally{z(),M.cleanup(),B(),n.scrollTo(N,v),M.reapply(),o.style.scrollBehavior=E,d&&(d.style.scrollBehavior=O)}}catch(n){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",n),null}}async function Y1(t,e){const n=await q1(t,e);if(n)return n;try{const r=t.contentWindow,o=t.contentDocument??r?.document,i=o?.documentElement;if(!r||!o||!i)return null;const c=t.getBoundingClientRect(),l=Math.max(1,Math.ceil(r.innerWidth||t.clientWidth||c.width)),d=Math.max(1,Math.ceil(r.innerHeight||t.clientHeight||c.height)),u=r.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,h=r.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,f=o.body,p=Math.max(d,i.scrollHeight||0,f?.scrollHeight||0),x=Math.min(2,Math.max(1,window.devicePixelRatio||1)),b=i.style.scrollBehavior,S=f?.style.scrollBehavior??"";i.style.scrollBehavior="auto",f&&(f.style.scrollBehavior="auto");let g="",m=()=>{};try{await o.fonts?.ready.catch(()=>{}),m=await Rm(o,l,d,{applyLayoutWorkarounds:!0}),r.scrollTo(u,h);const{getFontEmbedCSS:C,toJpeg:j}=await Bo(async()=>{const{getFontEmbedCSS:N,toJpeg:v}=await import("./vendor-html-to-image-BeoRn2gJ.js");return{getFontEmbedCSS:N,toJpeg:v}},[]),w=await C(i).catch(()=>"");g=await j(i,{quality:.82,pixelRatio:x,width:l,height:d,backgroundColor:Cm(o),imagePlaceholder:Io,fontEmbedCSS:w||void 0,style:{transform:`translate(${-u}px, ${-h}px)`,transformOrigin:"top left",minWidth:`${l}px`,minHeight:`${p}px`},cacheBust:!0})}finally{m(),r.scrollTo(u,h),i.style.scrollBehavior=b,f&&(f.style.scrollBehavior=S)}const y=g.split(",",2)[1]||"";return y?await hc(y,l,d,l,d,e):null}catch(r){return console.warn("[preview] failed to capture iframe DOM screenshot:",r),null}}const Q1=380,X1=1400,Mm=600,J1=100,Z1=24,la=new Map,Hd=200,ej=(t,e)=>e==="all"?!0:e==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":e==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",tj=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},Kd=t=>Number.isFinite(t)?Math.min(X1,Math.max(Q1,Math.round(t))):Mm,sj=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},nj=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},Tm=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="walkthrough"?"contextPanel.mode.walkthrough":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":t==="browser"?"contextPanel.mode.browser":t==="git"?"layout.rightSidebar.git":t==="pr"?"contextPanel.mode.pr":t==="notes"?"contextRail.surface.notes":t==="terminal"?"layout.mainTab.terminal":"contextPanel.mode.context"),rj=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},oj=(t,e,n)=>{if(t.mode==="chat"){const r=Wi(t.dedupeKey);if(r){const i=e.get(r)?.trim();if(i)return i}const o=t.sessionTitleFallback?.trim();return o||n("contextPanel.mode.chat")}if(t.label)return t.label;if(t.mode==="file")return rj(t.targetPath)||n("contextPanel.mode.files");if(t.mode==="preview"){const r=t.targetPath;if(r)try{const o=new URL(r);return o.host||o.hostname||n("contextPanel.mode.preview")}catch{}return n("contextPanel.mode.preview")}return t.mode==="diff"?n("contextPanel.mode.diff"):Tm(t.mode,n)},Gd=t=>{if(t.mode==="file")return t.targetPath?s.jsx($o,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(Kf,{className:"h-3.5 w-3.5"});if(t.mode==="walkthrough")return s.jsx(A,{name:"route",className:"h-3.5 w-3.5"});if(t.mode==="git")return s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5"});if(t.mode==="pr")return s.jsx(A,{name:"github",className:"h-3.5 w-3.5"});if(t.mode==="notes")return s.jsx(A,{name:"sticky-note",className:"h-3.5 w-3.5"});if(t.mode==="terminal")return s.jsx(A,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(A,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(A,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(A,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(A,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(A,{name:"global",className:"h-3.5 w-3.5"})},ij=200,aj=480,lj=({visible:t})=>{const{t:e}=ft(),n=Ee(m=>m.contextEditorTreeWidth),r=Ee(m=>m.setContextEditorTreeWidth),[o,i]=a.useState(!1),c=a.useRef(0),l=a.useRef(n),d=a.useRef(null),u=a.useRef(null),h=a.useRef(null),f=a.useCallback(m=>Math.min(aj,Math.max(ij,Math.round(m))),[]),p=a.useCallback(m=>{const y=h.current;y&&(y.style.width=`${m}px`,y.style.setProperty("--oc-editor-tree-width",`${m}px`))},[]),x=m=>{if(t){try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}u.current=m.pointerId,i(!0),c.current=m.clientX,l.current=n,d.current=n,m.preventDefault()}},b=m=>{if(!o||u.current!==m.pointerId)return;const y=c.current-m.clientX,C=f(l.current+y);d.current!==C&&(d.current=C,p(C))},S=m=>{if(u.current!==m.pointerId)return;try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}const y=f(d.current??n);u.current=null,d.current=null,i(!1),r(y)},g=t?n:0;return s.jsxs("div",{ref:h,className:Pe("relative h-full flex-shrink-0 overflow-hidden border-l border-border bg-background will-change-[width] motion-reduce:transition-none",!t&&"border-l-0"),style:{width:`${o?d.current??g:g}px`,"--oc-editor-tree-width":`${o?d.current??n:n}px`,overflowX:"clip",transitionProperty:o?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t,children:[t&&s.jsx("div",{className:Pe("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",o&&"bg-[var(--interactive-border)]"),onPointerDown:x,onPointerMove:b,onPointerUp:S,onPointerCancel:S,role:"separator","aria-orientation":"vertical","aria-label":e("contextPanel.actions.resizePanelAria")}),s.jsx("div",{className:Pe("relative z-10 h-full shrink-0 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",o&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-editor-tree-width)"},"aria-hidden":!t,children:s.jsx(Zv,{})})]})},Wi=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,cj=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},dj=(t,e)=>{if(e.length===0)return la;const n=new Set(e),r=new Map;for(const o of t){if(!n.has(o.id))continue;const i=o.title?.trim();i&&r.set(o.id,i)}return r.size===0?la:r},uj=(t,e)=>{const n=_l(t),r=a.useRef(la),o=a.useRef(e);return o.current=e,a.useSyncExternalStore(n.subscribe,a.useCallback(()=>{const i=dj(n.getState().session,o.current);return cj(r.current,i)?r.current:(r.current=i,i)},[n]),()=>la)},Em=`new Promise((resolve) => {
|
|
64
|
+
const existing = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
65
|
+
if (existing) existing.remove();
|
|
66
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
67
|
+
try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
|
|
68
|
+
}
|
|
69
|
+
const overlay = document.createElement('div');
|
|
70
|
+
overlay.id = '__openchamber_desktop_browser_overlay';
|
|
71
|
+
overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
|
|
72
|
+
document.documentElement.appendChild(overlay);
|
|
73
|
+
const cssEscape = (value) => {
|
|
74
|
+
try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
|
|
75
|
+
};
|
|
76
|
+
const selectorPart = (element) => {
|
|
77
|
+
const tag = element.tagName.toLowerCase();
|
|
78
|
+
if (element.id) return tag + '#' + cssEscape(element.id);
|
|
79
|
+
const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
|
|
80
|
+
return tag + className;
|
|
81
|
+
};
|
|
82
|
+
const metadata = (element) => {
|
|
83
|
+
const rect = element.getBoundingClientRect();
|
|
84
|
+
const style = getComputedStyle(element);
|
|
85
|
+
const ancestry = [];
|
|
86
|
+
let current = element;
|
|
87
|
+
while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
|
|
88
|
+
ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
|
|
89
|
+
current = current.parentElement;
|
|
90
|
+
}
|
|
91
|
+
const attrs = {};
|
|
92
|
+
for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
|
|
93
|
+
const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
|
|
94
|
+
return {
|
|
95
|
+
frame: 'top',
|
|
96
|
+
tag: element.tagName.toLowerCase(),
|
|
97
|
+
text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
|
|
98
|
+
selector: element.id ? '#' + cssEscape(element.id) : path,
|
|
99
|
+
path,
|
|
100
|
+
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
101
|
+
center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
|
|
102
|
+
attributes: attrs,
|
|
103
|
+
computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
|
|
104
|
+
ancestry,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const move = (event) => {
|
|
108
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
109
|
+
if (!element || element === overlay || element === document.documentElement || element === document.body) return;
|
|
110
|
+
const rect = element.getBoundingClientRect();
|
|
111
|
+
overlay.style.display = 'block';
|
|
112
|
+
overlay.style.left = rect.left + 'px';
|
|
113
|
+
overlay.style.top = rect.top + 'px';
|
|
114
|
+
overlay.style.width = rect.width + 'px';
|
|
115
|
+
overlay.style.height = rect.height + 'px';
|
|
116
|
+
};
|
|
117
|
+
const cleanup = () => {
|
|
118
|
+
window.removeEventListener('mousemove', move, true);
|
|
119
|
+
window.removeEventListener('click', click, true);
|
|
120
|
+
window.removeEventListener('keydown', keydown, true);
|
|
121
|
+
if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
|
|
122
|
+
delete window.__openchamberDesktopBrowserCancelInspect;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const cancel = () => {
|
|
126
|
+
cleanup();
|
|
127
|
+
overlay.remove();
|
|
128
|
+
resolve(null);
|
|
129
|
+
};
|
|
130
|
+
const click = (event) => {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
event.stopPropagation();
|
|
133
|
+
const element = document.elementFromPoint(event.clientX, event.clientY);
|
|
134
|
+
const result = element ? metadata(element) : null;
|
|
135
|
+
cleanup();
|
|
136
|
+
overlay.remove();
|
|
137
|
+
resolve(result);
|
|
138
|
+
};
|
|
139
|
+
const keydown = (event) => {
|
|
140
|
+
if (event.key !== 'Escape') return;
|
|
141
|
+
cancel();
|
|
142
|
+
};
|
|
143
|
+
window.__openchamberDesktopBrowserCancelInspect = cancel;
|
|
144
|
+
window.addEventListener('mousemove', move, true);
|
|
145
|
+
window.addEventListener('click', click, true);
|
|
146
|
+
window.addEventListener('keydown', keydown, true);
|
|
147
|
+
});`,Ui=`(() => {
|
|
148
|
+
if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
|
|
149
|
+
window.__openchamberDesktopBrowserCancelInspect();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
|
|
153
|
+
if (overlay) overlay.remove();
|
|
154
|
+
})()`,fj=`(() => {
|
|
155
|
+
if (window.__openchamberSameWebviewNavigationInstalled) return;
|
|
156
|
+
window.__openchamberSameWebviewNavigationInstalled = true;
|
|
157
|
+
|
|
158
|
+
const navigate = (rawUrl) => {
|
|
159
|
+
if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
|
|
160
|
+
try {
|
|
161
|
+
const url = new URL(rawUrl, window.location.href);
|
|
162
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
|
|
163
|
+
window.location.assign(url.href);
|
|
164
|
+
return true;
|
|
165
|
+
} catch (_error) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const originalOpen = window.open.bind(window);
|
|
171
|
+
window.open = (url, target, features) => {
|
|
172
|
+
if (navigate(url)) return null;
|
|
173
|
+
return originalOpen(url, target, features);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
document.addEventListener('click', (event) => {
|
|
177
|
+
if (event.defaultPrevented) return;
|
|
178
|
+
const target = event.target;
|
|
179
|
+
if (!(target instanceof Element)) return;
|
|
180
|
+
const anchor = target.closest('a[target="_blank"][href]');
|
|
181
|
+
if (!(anchor instanceof HTMLAnchorElement)) return;
|
|
182
|
+
if (!navigate(anchor.href)) return;
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
event.stopPropagation();
|
|
185
|
+
}, true);
|
|
186
|
+
})()`,oi=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},qd=async(t,e)=>{const n=t.contentWindow;if(!n)throw new Error("Iframe window is not available");const o=n.eval.call(n,e);return await Promise.resolve(o)},mj=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Fm=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},Yd=(t,e,n)=>{const r=Fm(e);t.postMessage(n,r)},hj=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},Qd=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("ocPreview"),e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},pj=({rawUrl:t,onNavigate:e})=>{const{t:n}=ft(),{currentTheme:r}=lo(),[o,i]=a.useReducer(q=>q+1,0),[c,l]=a.useReducer(q=>q+1,0),[d,u]=a.useState({status:"idle"}),[h,f]=a.useState(""),p=a.useRef(null),x=a.useRef(1),[b,S]=a.useState(!1),[g,m]=a.useState(!1),[y,C]=a.useState("all"),[j,w]=a.useState([]),[N,v]=a.useState(!1),[D,F]=a.useState(null),k=Je(q=>q.currentSessionId),E=Je(q=>q.newSessionDraft?.open),O=Wr(),M=di(q=>q.addDraft),B=ao(q=>q.addAttachedFile);let z=null;try{z=t?new URL(t):null}catch{z=null}const T=z?z.hostname==="localhost"||z.hostname==="127.0.0.1"||z.hostname==="::1"||z.hostname==="[::1]"||z.hostname==="0.0.0.0":!1,I=z?z.hostname==="0.0.0.0"?new URL(z.toString().replace("0.0.0.0","127.0.0.1")):z:null,R=I?I.toString():"",L=R?`${Nr()||"same-origin"}|${R}`:"",P=r.metadata.variant;a.useEffect(()=>{if(!R||!T){u({status:"idle"});return}const q=pc(L);if(q?.previewToken){u({status:"ready",proxyBasePath:q.proxyBasePath,previewToken:q.previewToken,expiresAt:q.expiresAt});return}q&&Cn.delete(L);let Ne=!1;return u({status:"loading"}),(async()=>{try{const je=await us("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:R})});if(!je.ok){Cn.delete(L);const ae=await je.json().catch(()=>({})),U=typeof ae?.error=="string"?ae.error:`HTTP ${je.status}`;Ne||u({status:"error",message:U});return}const ve=await je.json(),ie=typeof ve.proxyBasePath=="string"?ve.proxyBasePath:"",ee=typeof ve.previewToken=="string"?ve.previewToken:"",ke=typeof ve.expiresAt=="number"?ve.expiresAt:0;if(!ie||!ee){Cn.delete(L),Ne||u({status:"error",message:n("contextPanel.preview.proxyError")});return}Cn.set(L,{proxyBasePath:ie,previewToken:ee,expiresAt:ke}),Ne||u({status:"ready",proxyBasePath:ie,previewToken:ee,expiresAt:ke})}catch(je){if(Cn.delete(L),!Ne){const ve=je instanceof Error?je.message:String(je);u({status:"error",message:ve})}}})(),()=>{Ne=!0}},[T,L,c,n,R]);const G=I&&(I.protocol==="http:"||I.protocol==="https:")?I.toString():"",X=T&&d.status==="ready"?`${d.proxyBasePath}|${d.previewToken||""}|${o}`:"";a.useEffect(()=>{if(!X){f("");return}let q=!1;return f(""),Xu(Nr()).then(Ne=>{!q&&Ne&&f(X)}).catch(()=>{}),()=>{q=!0}},[X]);const V=T&&d.status==="ready"&&I&&h===X?(()=>{const q=I.pathname||"/",Ne=new URLSearchParams(I.search);Ne.delete("oc_url_token"),Ne.delete("oc_client_token"),Ne.set("ocPreview",String(o)),Ne.set("oc_preview_token",d.previewToken||"");const je=Ne.toString(),ve=I.hash||"";return ha().authenticatedAsset(`${d.proxyBasePath}${q}${je?`?${je}`:""}${ve}`)})():"",te=T?V:G,Z=T?hj(V):G,de=T&&(d.status==="loading"||d.status==="idle"||h!==X),Fe=T&&d.status==="error",se=a.useCallback(q=>{const Ne=k??(E?"draft":null);if(!Ne||!O){fe.error(n("contextPanel.preview.inspect.attachNoSession"));return}const je=t||te||"",ve=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},ie=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let ee=!1;try{const ke=p.current,ae=ke?await Nm(ke,q):null;ae&&(await B(ae),ee=!0)}catch{ee=!1}M({directory:O,sessionKey:Ne},{source:"preview-annotation",fileLabel:je||"preview",startLine:1,endLine:1,code:mc({pageUrl:je,viewport:ve,devicePixelRatio:ie,target:q,screenshotAttached:ee,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),fe.success(n("contextPanel.preview.inspect.attached"))})()},[B,M,k,O,te,E,t,n]);a.useEffect(()=>{S(!1),w([]),m(!1),C("all"),v(!1),F(null),x.current=1},[te]),a.useEffect(()=>{const q=p.current?.contentWindow;!b||!q||Yd(q,V,{source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:N})},[b,N,V]),a.useEffect(()=>{const q=p.current?.contentWindow;!b||!q||Yd(q,V,{source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:P})},[b,P,V]),a.useEffect(()=>{if(!N||typeof window>"u")return;const q=Ne=>{Ne.key==="Escape"&&(Ne.preventDefault(),Ne.stopImmediatePropagation(),v(!1))};return window.addEventListener("keydown",q,!0),()=>window.removeEventListener("keydown",q,!0)},[N]),a.useEffect(()=>{if(!T||typeof window>"u")return;const q=ve=>{if(typeof ve=="string")return ve;if(ve==null)return"";try{return JSON.stringify(ve)}catch{return String(ve)}},Ne=ve=>{const ie=x.current;x.current+=1,w(ee=>{const ke=[...ee,{...ve,id:ie}];return ke.length>Hd?ke.slice(ke.length-Hd):ke})},je=ve=>{if(ve.source!==p.current?.contentWindow)return;const ie=ve.data;if(!(!ie||ie.source!=="openchamber-preview-bridge"||ie.version!==1)){if(ie.type==="ready"){S(!0);return}if(ie.type==="console"){const ee=ie.level==="error"||ie.level==="warn"||ie.level==="info"||ie.level==="debug"?ie.level:"log",ke=Array.isArray(ie.args)?ie.args.map(q).filter(Boolean):[];Ne({level:ee,message:ke.join(" "),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="runtime-error"){const ee=q(ie.filename),ke=typeof ie.line=="number"?ie.line:null,ae=typeof ie.column=="number"?ie.column:null,U=ee?`${ee}${ke!==null?`:${ke}${ae!==null?`:${ae}`:""}`:""}`:"",le=q(ie.stack);Ne({level:"runtime",message:q(ie.message)||n("contextPanel.preview.console.runtimeError"),details:[U,le].filter(Boolean).join(`
|
|
187
|
+
`),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="resource-error"){const ee=q(ie.tag)||"resource",ke=q(ie.url);Ne({level:"resource",message:ke?`${ee}: ${ke}`:ee,details:q(ie.outerHTML),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="hover"){F(Po(ie.target)?ie.target:null);return}if(ie.type==="select"&&Po(ie.target)){F(ie.target),v(!1),se(ie.target);return}if(ie.type==="navigate-preview"){const ee=typeof ie.url=="string"?ie.url:"",ke=ie.navigation==="external"?"external":"proxy";if(ee&&ke==="external"){io(ee);return}ee&&e(ee)}}};return window.addEventListener("message",je),()=>{window.removeEventListener("message",je)}},[se,T,e,n]);const Q=j.filter(q=>q.level==="error"||q.level==="runtime"||q.level==="resource").length,Me=j.filter(q=>ej(q,y)),xe=a.useCallback(()=>{const q=[`Preview URL: ${t||te||""}`,`Events: ${j.length}`,""].join(`
|
|
188
|
+
`),Ne=j.map(je=>{const ve=new Date(je.ts).toISOString(),ie=je.details?`
|
|
189
|
+
${je.details}`:"";return`[${ve}] [${je.level}] ${je.message}${ie}`}).join(`
|
|
190
|
+
`);tr(`${q}${Ne}`).then(je=>{je.ok?fe.success(n("contextPanel.preview.console.copied")):fe.error(n("contextPanel.preview.console.copyFailed"))})},[j,te,t,n]),W=a.useCallback(()=>{const q=k??(E?"draft":null);if(!q||!O){fe.error(n("contextPanel.preview.console.attachNoSession"));return}const Ne=[`Preview URL: ${t||te||""}`,`Events: ${j.length}`,""].join(`
|
|
191
|
+
`),je=j.map(ve=>{const ie=new Date(ve.ts).toISOString(),ee=ve.details?`
|
|
192
|
+
${ve.details}`:"";return`[${ie}] [${ve.level}] ${ve.message}${ee}`}).join(`
|
|
193
|
+
`);M({directory:O,sessionKey:q},{source:"preview-console",fileLabel:t||te||"preview",startLine:1,endLine:Math.max(1,j.length),code:`${Ne}${je}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),fe.success(n("contextPanel.preview.console.attached"))},[M,j,k,O,te,E,t,n]),[J,ne]=a.useState("unknown"),oe=a.useRef(0),ue=a.useRef(0),Ae=a.useRef(""),we=a.useRef(""),Se=15e3;a.useEffect(()=>{if(!V){ne("unknown"),Ae.current="",oe.current=0,ue.current=0;return}let q=!1,Ne=null;Ae.current!==L&&(Ae.current=L,oe.current=Date.now(),ue.current=0);const je=ve=>{Ne=setTimeout(()=>{q||i()},ve)};return ne("unknown"),(async()=>{const ie=await(async()=>{try{return await us(V,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(q)return;if(!ie){ne("unreachable"),je(5e3);return}const ee=I1(ie.headers,we.current===L);if(ee!=="none"){if(Cn.delete(L),ee==="retry-registration")we.current=L,u({status:"loading"}),l();else{const U=await ie.json().catch(()=>({}));if(q)return;const le=typeof U?.error=="string"?U.error:`HTTP ${ie.status}`;u({status:"error",message:le})}return}if(ie.status!==502){we.current="",ne("reachable");return}const ke=oe.current||Date.now();if(Date.now()-ke<Se){ne("starting"),ue.current+=1;const U=ue.current,le=Math.min(2e3,250*Math.pow(2,Math.min(4,U)));je(le);return}ne("unreachable"),je(5e3)})(),()=>{q=!0,Ne&&clearTimeout(Ne)}},[L,V,o]);const Le=T&&d.status==="ready"&&(J==="unknown"||J==="starting"),Ue=T&&d.status==="ready"&&J==="unreachable",be=a.useCallback(q=>{if(!T||d.status!=="ready"||typeof window>"u")return;const Ne=q.currentTarget.contentWindow;if(Ne)try{const je=Ne.location,ve=Fm(V);if(je.origin!==ve||je.pathname.startsWith(d.proxyBasePath))return;const ie=`${d.proxyBasePath}${je.pathname}${je.search}${je.hash}`;Ne.location.replace(ie)}catch{}},[T,V,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:Z||t,children:Z||t||n("contextPanel.preview.empty")}),s.jsx(He,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!te,children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{G&&io(G)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!G,children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})}),T?s.jsx(He,{type:"button",size:"sm",variant:N?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(q=>!q),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!b,children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}):null,T?s.jsxs(He,{type:"button",size:"sm",variant:g?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>m(q=>!q),title:n(b?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(b?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!b&&j.length===0,children:[s.jsx(A,{name:"terminal-box",className:"h-3.5 w-3.5"}),Q>0?s.jsx("span",{className:"typography-micro text-status-error",children:Q}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[Le?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):Ue?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(He,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):te&&(!T||J==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:p,src:te,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:P},onLoad:be,sandbox:T?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${te}:${o}`),N&&D?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:D.bounds.x,top:D.bounds.y,width:D.bounds.width,height:D.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[D.tag,D.text?` · ${D.text}`:""]})}):null]}):de?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):Fe?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),g?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(He,{type:"button",size:"xs",variant:"ghost",onClick:W,disabled:j.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(He,{type:"button",size:"xs",variant:"ghost",onClick:xe,disabled:j.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(He,{type:"button",size:"xs",variant:"ghost",onClick:()=>w([]),disabled:j.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(q=>s.jsx(He,{type:"button",size:"xs",variant:y===q?"secondary":"ghost",onClick:()=>C(q),children:n(q==="all"?"contextPanel.preview.console.filter.all":q==="errors"?"contextPanel.preview.console.filter.errors":q==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},q))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:j.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):Me.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):Me.map(q=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:Pe("shrink-0 uppercase",q.level==="error"||q.level==="runtime"||q.level==="resource"?"text-status-error":q.level==="warn"?"text-status-warning":"text-muted-foreground"),children:q.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:q.message})]})},q.id))})]}):null]})]})},gj=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,xj=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=ft(),o=a.useRef(null),i=Ee(W=>W.setContextPanelTabTargetPath),c=oi(t),l=c!=="about:blank"?c:"",[d,u]=a.useState(l),[h,f]=a.useState(l),[p,x]=a.useState(l),[b,S]=a.useState(()=>l?[l]:[]),[g,m]=a.useState(()=>l?0:-1),[y,C]=a.useReducer(W=>W+1,0),[j,w]=a.useState(!!l),[N,v]=a.useState(!1),[D,F]=a.useState(null),[k,E]=a.useState({status:"idle"}),[O,M]=a.useState(""),B=Je(W=>W.currentSessionId),z=Je(W=>W.newSessionDraft?.open),T=di(W=>W.addDraft),I=ao(W=>W.addAttachedFile),R=a.useCallback(W=>{!W||W==="about:blank"||!e||!n||i(e,n,W)},[e,n,i]),L=a.useCallback((W,J)=>{const ne=oi(W),oe=ne!=="about:blank"?ne:"";f(oe),u(oe),J?.inFrame?w(!1):(x(oe),w(!!oe)),R(oe),S(ue=>{if(!oe)return m(-1),[];if(J?.replaceHistory)return ue;const Ae=g>=0?ue.slice(0,g+1):[];if(Ae[Ae.length-1]===oe)return m(Ae.length-1),Ae;const Se=[...Ae,oe];return m(Se.length-1),Se})},[g,R]),P=a.useCallback(W=>{const J=b[W];J&&(m(W),f(J),x(J),u(J),w(!0),R(J))},[b,R]),G=a.useCallback(()=>{if(h){w(!0);try{o.current?.contentWindow?.location.reload()}catch{C()}}},[h]);a.useEffect(()=>{if(!p){E({status:"idle"});return}const W=O1(p),J=pc(W);if(J?.previewToken){E({status:"ready",proxyBasePath:J.proxyBasePath,previewToken:J.previewToken,expiresAt:J.expiresAt});return}J&&Cn.delete(W);let ne=!1;return E({status:"loading"}),w(!0),(async()=>{try{const oe=await us("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:p,allowExternal:!0})});if(!oe.ok){const Le=await oe.json().catch(()=>({})),Ue=typeof Le?.error=="string"?Le.error:`HTTP ${oe.status}`;ne||E({status:"error",message:Ue});return}const ue=await oe.json(),Ae=typeof ue.proxyBasePath=="string"?ue.proxyBasePath:"",we=typeof ue.previewToken=="string"?ue.previewToken:"",Se=typeof ue.expiresAt=="number"?ue.expiresAt:0;if(!Ae||!we){ne||E({status:"error",message:r("contextPanel.preview.proxyError")});return}Cn.set(W,{proxyBasePath:Ae,previewToken:we,expiresAt:Se}),ne||E({status:"ready",proxyBasePath:Ae,previewToken:we,expiresAt:Se})}catch(oe){if(!ne){const ue=oe instanceof Error?oe.message:String(oe);E({status:"error",message:ue})}}})(),()=>{ne=!0}},[p,r]);const X=p&&k.status==="ready"?`${k.proxyBasePath}|${k.previewToken||""}|${y}`:"";a.useEffect(()=>{if(!X){M("");return}let W=!1;return M(""),Xu(Nr()).then(J=>{!W&&J&&M(X)}).catch(()=>{}),()=>{W=!0}},[X]);const V=a.useMemo(()=>{if(O!==X||!p||k.status!=="ready")return"";try{const W=new URL(p),J=W.pathname||"/",ne=new URLSearchParams(W.search);ne.delete("oc_url_token"),ne.delete("oc_client_token"),ne.set("ocPreview",String(y)),ne.set("oc_preview_token",k.previewToken||"");const oe=ne.toString();return ha().authenticatedAsset(`${k.proxyBasePath}${J}${oe?`?${oe}`:""}${W.hash}`)}catch{return""}},[p,k,X,y,O]),te=V||(k.status==="error"?p:""),Z=a.useCallback(W=>{if(!W||!p||k.status!=="ready")return"";try{const J=new URL(W,window.location.origin),ne=k.proxyBasePath.endsWith("/")?k.proxyBasePath.slice(0,-1):k.proxyBasePath;if(J.origin!==window.location.origin||!J.pathname.startsWith(ne))return"";const oe=J.pathname.slice(ne.length)||"/",ue=new URL(p).origin;return Qd(new URL(`${oe}${J.search}${J.hash}`,ue).toString())}catch{return""}},[p,k]),de=a.useCallback(W=>{if(!W||!p||k.status!=="ready")return"";try{const J=new URL(W,window.location.origin),ne=new URL(p).origin;if(J.origin!==window.location.origin||ne===window.location.origin)return"";const oe=k.proxyBasePath.endsWith("/")?k.proxyBasePath.slice(0,-1):k.proxyBasePath;return J.pathname.startsWith(oe)?"":Qd(new URL(`${J.pathname}${J.search}${J.hash}`,ne).toString())}catch{return""}},[p,k]),Fe=a.useCallback(W=>{const J=o.current?.contentWindow;J&&J.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:W},window.location.origin)},[]),se=a.useCallback(async W=>{const J=B??(z?"draft":null);if(!J){fe.error(r("contextPanel.preview.inspect.attachNoSession"));return}const ne=o.current,oe=ne?.contentWindow,ue=ne?.getBoundingClientRect(),Ae={width:Number.isFinite(oe?.innerWidth)?oe?.innerWidth??ue?.width??0:ue?.width??0,height:Number.isFinite(oe?.innerHeight)?oe?.innerHeight??ue?.height??0:ue?.height??0},we=ne?await Nm(ne,W):null,Se=!!we;we&&await I(we),T({directory:e,sessionKey:J},{source:"preview-annotation",fileLabel:h||"browser",startLine:1,endLine:1,code:mc({pageUrl:h,viewport:Ae,devicePixelRatio:window.devicePixelRatio||1,target:W,screenshotAttached:Se,intro:r(Se?"contextPanel.preview.inspect.attachAnnotationWithScreenshot":"contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),fe.success(r("contextPanel.preview.inspect.attached"))},[I,T,B,h,e,z,r]),Q=a.useCallback(()=>{const W=o.current;F(null),Fe(!1),W&&qd(W,Ui).catch(()=>{})},[Fe]);a.useEffect(()=>{if(!N)return;const W=J=>{J.key==="Escape"&&(J.preventDefault(),J.stopImmediatePropagation(),v(!1),Q())};return window.addEventListener("keydown",W,!0),()=>window.removeEventListener("keydown",W,!0)},[Q,N]),a.useEffect(()=>()=>Q(),[Q]),a.useEffect(()=>{const W=J=>{if(J.source!==o.current?.contentWindow)return;const ne=J.data;if(!(!ne||ne.source!=="openchamber-preview-bridge"||ne.version!==1)){if(ne.type==="ready"){const oe=typeof ne.url=="string"?ne.url:"",ue=Z(oe);ue&&ue!==h&&L(ue,{inFrame:!0});return}if(ne.type==="hover"){F(Po(ne.target)?ne.target:null);return}if(ne.type==="select"&&Po(ne.target)){F(null),v(!1),Fe(!1),se(ne.target);return}if(ne.type==="navigate-preview"){const oe=typeof ne.url=="string"?ne.url:"",ue=de(oe);if(ue){L(ue);return}oe&&L(oe)}}};return window.addEventListener("message",W),()=>window.removeEventListener("message",W)},[L,se,h,Z,de,Fe]);const Me=a.useCallback(()=>{const W=o.current;if(!(!W||!h)){if(N){v(!1),Q();return}if(V){F(null),v(!0),Fe(!0);return}v(!0),(async()=>{try{const J=await qd(W,Em);if(v(!1),!J||!Po(J))return;await se(J)}catch{v(!1),fe.error(r("contextPanel.browser.inspectUnavailable"))}})()}},[se,Q,h,N,Fe,V,r]),xe=a.useCallback(()=>{try{const W=o.current?.contentWindow?.location.href||"",J=de(W);if(J){L(J,{inFrame:!0});return}}catch{}w(!1),N&&V&&Fe(!0)},[L,de,N,Fe,V]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:g<=0,onClick:()=>P(g-1),children:s.jsx(A,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:g<0||g>=b.length-1,onClick:()=>P(g+1),children:s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!h,onClick:G,children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:W=>{W.preventDefault(),L(d)},children:s.jsx("input",{value:d,onChange:W=>u(W.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(He,{type:"button",variant:N?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!h,onClick:Me,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!h,onClick:()=>{io(h)},children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[te?s.jsxs("div",{className:"absolute inset-0",children:[s.jsx("iframe",{ref:o,src:te,title:r("contextPanel.browser.empty"),className:"absolute inset-0 h-full w-full border-0 bg-background",allow:"clipboard-read; clipboard-write; fullscreen",allowFullScreen:!0,onLoad:xe},`${n}:${y}`),N&&D?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:D.bounds.x,top:D.bounds.y,width:D.bounds.width,height:D.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[D.tag,D.text?` · ${D.text}`:""]})}):null]}):s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(ql,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")}),s.jsx("span",{className:"max-w-sm typography-micro text-muted-foreground",children:r("contextPanel.browser.emptyHint")}),s.jsx("span",{className:"max-w-md typography-micro leading-relaxed text-status-warning/70",children:r("contextPanel.browser.trustNotice")})]}),j?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},bj=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=ft(),o=a.useRef(null),i=Ee(k=>k.setContextPanelTabTargetPath),c=oi(t),l=c!=="about:blank"?c:"",d=a.useRef(oi(t)),[u,h]=a.useState(l),[f,p]=a.useState(l),[x,b]=a.useState(!1),[S,g]=a.useState(!0),m=a.useRef(null),y=S,C=a.useCallback(k=>{!k||k==="about:blank"||!e||!n||i(e,n,k)},[e,n,i]),j=Je(k=>k.currentSessionId),w=Je(k=>k.newSessionDraft?.open),N=di(k=>k.addDraft),v=ao(k=>k.addAttachedFile);a.useEffect(()=>{const k=o.current;if(!k)return;const E=()=>{try{const I=k.getURL();I&&I!=="about:blank"&&(p(I),h(I),C(I))}catch{}},O=I=>{const R=I.detail;typeof R?.url=="string"&&R.url&&(p(R.url),h(R.url),C(R.url))},M=()=>{m.current&&clearTimeout(m.current),m.current=setTimeout(()=>g(!0),200)},B=()=>{m.current&&clearTimeout(m.current),g(!1),E()},z=I=>{const R=I.detail;if(R?.disposition==="new-window"||R?.disposition==="foreground-tab"||R?.disposition==="background-tab"){I.preventDefault();const L=o.current;typeof L?.loadURL=="function"&&R.url&&L.loadURL(R.url)}},T=()=>{try{k.executeJavaScript?.(fj,!0).catch(()=>{})}catch{}};k.addEventListener("did-navigate",O),k.addEventListener("did-navigate-in-page",O),k.addEventListener("did-start-loading",M),k.addEventListener("did-stop-loading",B),k.addEventListener("new-window",z),k.addEventListener("dom-ready",T);try{k.isLoading()||(g(!1),E())}catch{}return T(),()=>{m.current&&clearTimeout(m.current),k.removeEventListener("did-navigate",O),k.removeEventListener("did-navigate-in-page",O),k.removeEventListener("did-start-loading",M),k.removeEventListener("did-stop-loading",B),k.removeEventListener("new-window",z),k.removeEventListener("dom-ready",T)}},[C]),a.useEffect(()=>{const k=setTimeout(()=>g(!1),3e4);return()=>clearTimeout(k)},[]),a.useEffect(()=>{if(!x)return;const k=E=>{if(E.key!=="Escape")return;E.preventDefault(),E.stopImmediatePropagation(),b(!1);const O=o.current;try{O?.executeJavaScript?.(Ui).catch(()=>{})}catch{}};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[x]),a.useEffect(()=>{const k=o.current;return()=>{try{const E=k?.getURL?.();E&&E!=="about:blank"&&i(e,n,E)}catch{}try{k?.executeJavaScript?.(Ui).catch(()=>{})}catch{}}},[e,n,i]);const D=a.useCallback(k=>{const E=o.current;if(typeof E?.loadURL!="function")return;const O=oi(k);try{E.loadURL(O)}catch{}},[]),F=a.useCallback(()=>{const k=o.current;if(k){if(x){b(!1);try{k.executeJavaScript?.(Ui).catch(()=>{})}catch{}return}b(!0),k.executeJavaScript?.(Em,!0).then(async E=>{if(b(!1),!E||!Po(E))return;const O=j??(w?"draft":null);if(!O){fe.error(r("contextPanel.preview.inspect.attachNoSession"));return}const M=typeof k.getWebContentsId=="function"?k.getWebContentsId():null;if(M==null)return;const B=await $p("desktop_browser_capture_page",{webContentsId:M}),z=await k.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),T=Number.isFinite(z?.width)?z.width:B.width,I=Number.isFinite(z?.height)?z.height:B.height,R=await hc(B.base64,B.width,B.height,T,I,E),L=!!R;R&&await v(R),N({directory:e,sessionKey:O},{source:"preview-annotation",fileLabel:f||"browser",startLine:1,endLine:1,code:mc({pageUrl:f,viewport:{width:T,height:I},devicePixelRatio:window.devicePixelRatio||1,target:E,screenshotAttached:L,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),fe.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[v,N,j,f,e,x,w,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goBack?.()}catch{}},children:s.jsx(A,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goForward?.()}catch{}},children:s.jsx(A,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.reload?.()}catch{}},children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:k=>{k.preventDefault(),D(u)},children:s.jsx("input",{value:u,onChange:k=>h(k.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(He,{type:"button",variant:x?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:F,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(A,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{io(f)},children:s.jsx(A,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:o,src:d.current,partition:"persist:openchamber-browser",allowpopups:!0,style:{width:"100%",height:"100%",border:"none"}}),(!f||f==="about:blank")&&!S?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(ql,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,y?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},yj=()=>{const{t}=ft(),e=Wr()??"",n=a.useMemo(()=>tj(e),[e]),r=Ee(_=>n?_.contextPanelByDirectory[n]:void 0),o=Ee(_=>_.closeContextPanel),i=Ee(_=>_.closeContextPanelTab),c=Ee(_=>_.openContextPanelTab),l=Ee(_=>_.toggleContextPanelExpanded),d=Ee(_=>_.setContextPanelWidth),u=Ee(_=>_.setActiveContextPanelTab),h=Ee(_=>_.reorderContextPanelTabs),f=vr(_=>_.setSelectedPath),p=Ee(_=>_.openContextPreview),x=Ee(_=>_.contextEditorTreeVisible),b=Ee(_=>_.toggleContextEditorTree),S=Ee(_=>_.allowPromptingSubagentSessions),{themeMode:g,setThemeMode:m,lightThemeId:y,darkThemeId:C,currentTheme:j}=lo(),w=a.useMemo(()=>r?.tabs??[],[r?.tabs]),N=w.find(_=>_.id===r?.activeTabId)??w[w.length-1]??null,v=!!(r?.isOpen&&N),D=!!(v&&r?.expanded),[F,k]=a.useState(null),E=N?.mode??null,O=E?r?.widthByMode?.[E]:void 0,M=E?M1(E):.5,B=F??(typeof window<"u"?window.innerWidth:Mm*2),z=Kd(O??Math.round(M*B)),T=a.useMemo(()=>{const _=[];for(const ge of w){if(ge.mode!=="chat")continue;const Ie=Wi(ge.dedupeKey);Ie&&!_.includes(Ie)&&_.push(Ie)}return _},[w]),I=uj(n||void 0,T),[R,L]=a.useState(!1),P=a.useRef(0),G=a.useRef(z),X=a.useRef(null),V=a.useRef(null),te=a.useRef(null),Z=a.useRef(new Map),de=a.useRef(new Map),Fe=a.useRef(!1);a.useLayoutEffect(()=>{const _=te.current?.parentElement;if(!_||typeof ResizeObserver>"u")return;const ge=new ResizeObserver(()=>{k(_.clientWidth||null)});return ge.observe(_),k(_.clientWidth||null),()=>ge.disconnect()},[]),a.useEffect(()=>{if(!v||Fe.current){Fe.current=v;return}const _=window.requestAnimationFrame(()=>{te.current?.focus({preventScroll:!0})});return Fe.current=!0,()=>window.cancelAnimationFrame(_)},[v]);const se=a.useRef(null),Q=a.useRef(null),Me=a.useCallback(()=>{Q.current=null;const _=te.current,ge=X.current;!_||ge===null||_.style.setProperty("--oc-context-panel-width",`${ge}px`)},[]);a.useEffect(()=>()=>{Q.current!==null&&clearTimeout(Q.current)},[]);const xe=a.useCallback(_=>{const ge=Kd(_),Ie=se.current;return Ie===null?ge:Math.min(ge,Math.max(1,Ie))},[]),W=a.useCallback(_=>{!v||D||!n||(V.current=_.pointerId,L(!0),P.current=_.clientX,G.current=z,X.current=z,se.current=sj(te.current),document.documentElement.style.cursor="col-resize",_.preventDefault())},[n,D,v,z]),J=a.useCallback(()=>{const _=xe(X.current??z);X.current=null,se.current=null,Q.current!==null&&(clearTimeout(Q.current),Q.current=null),document.documentElement.style.cursor="",n&&E&&d(n,E,_),L(!1),V.current=null},[E,xe,n,d,z]);a.useEffect(()=>{if(!R)return;const _=Re=>{if(V.current!==Re.pointerId)return;const Ke=P.current-Re.clientX,nt=xe(G.current+Ke);X.current!==nt&&(X.current=nt,Q.current===null&&(Q.current=setTimeout(Me,J1)))},ge=Re=>{V.current===Re.pointerId&&J()},Ie=()=>{J()};return window.addEventListener("pointermove",_),window.addEventListener("pointerup",ge),window.addEventListener("pointercancel",ge),window.addEventListener("blur",Ie),()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",ge),window.removeEventListener("pointercancel",ge),window.removeEventListener("blur",Ie)}},[Me,xe,J,R]),a.useEffect(()=>{R||(X.current=null,document.documentElement.style.cursor="")},[R]);const ne=a.useCallback(()=>{n&&o(n)},[o,n]),oe=a.useCallback(()=>{n&&l(n)},[n,l]),ue=a.useCallback(_=>{_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),ne())},[ne]);a.useEffect(()=>{if(!(!n||!N)&&N.mode==="file"&&N.targetPath){f(n,N.targetPath,{allowOutsideRoot:!0});return}},[N,n,f]);const Ae=N?.mode==="chat"?N.id:null,we=N?.mode==="chat"?Wi(N.dedupeKey):null;a.useEffect(()=>{if(!v||!n||!we||typeof window>"u")return;const _=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){La(n,we,!1);return}df(we),La(n,we,!0)};_();const ge=window.setInterval(_,1e4);return window.addEventListener("focus",_),window.addEventListener("blur",_),document.addEventListener("visibilitychange",_),()=>{window.clearInterval(ge),window.removeEventListener("focus",_),window.removeEventListener("blur",_),document.removeEventListener("visibilitychange",_),La(n,we,!1)}},[we,n,v]);const Se=a.useCallback((_,ge,Ie)=>Kx(de.current,_,ge,n||null,Ie,{mode:g,lightThemeId:y,darkThemeId:C,currentTheme:j}),[j,C,n,y,g]);a.useEffect(()=>{const _=new Set(w.map(ge=>ge.id));for(const ge of de.current.keys())_.has(ge)||de.current.delete(ge)},[w]);const Le=a.useCallback(_=>{!n||N?.mode!=="diff"||c(n,{mode:"diff",targetPath:N.targetPath,stagedDiff:_==="staged",diffScope:_})},[N,n,c]),Ue=a.useCallback(()=>{if(typeof window>"u")return;const _={themeMode:g,lightThemeId:y,darkThemeId:C,currentTheme:j};for(const ge of Z.current.values()){const Ie=ge.contentWindow;Ie&&Ie.postMessage({type:"openchamber:theme-sync",payload:_},window.location.origin)}},[j,C,y,g]),be=a.useCallback(()=>{if(typeof window>"u")return;const _={allowPromptingSubagentSessions:S};for(const ge of Z.current.values()){const Ie=ge.contentWindow;Ie&&Ie.postMessage({type:"openchamber:chat-settings-sync",payload:_},window.location.origin)}},[S]),q=a.useCallback(()=>{if(!(typeof window>"u"))for(const[_,ge]of Z.current.entries()){const Ie=ge.contentWindow;if(!Ie)continue;const Re={visible:Ae===_};Ie.postMessage({type:"openchamber:embedded-visibility",payload:Re},window.location.origin)}},[Ae]);a.useEffect(()=>{if(typeof window>"u")return;const _=ge=>{if(ge.origin!==window.location.origin||!Array.from(Z.current.values()).some(mt=>mt.contentWindow===ge.source))return;const Re=ge.data;if(Re?.type===Gx){if(typeof Re.requestId!="string"||!Re.requestId)return;const mt=$n(),gt={apiBaseUrl:Nr(),clientToken:Xi(),localOrigin:typeof window.__OPENCHAMBER_LOCAL_ORIGIN__=="string"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"",runtimeHeaders:Th(),relayHostId:mt.startsWith("host:")?mt.slice(5):"",relay:Mh()??void 0};ge.source?.postMessage({type:qx,requestId:Re.requestId,payload:gt},ge.origin);return}if(Re?.type==="openchamber:theme-sync-request"){Ue();return}if(Re?.type==="openchamber:chat-settings-request"){be();return}if(Re?.type!=="openchamber:cycle-theme-request")return;const Ke=["light","dark","system"],ct=(Ke.indexOf(g)+1)%Ke.length;m(Ke[ct])};return window.addEventListener("message",_),()=>window.removeEventListener("message",_)},[be,Ue,m,g]),a.useLayoutEffect(()=>{w.some(ge=>ge.mode==="chat")&&(Ue(),be(),q())},[C,y,be,q,Ue,w,g]);const Ne=N?.mode==="file"||N?.mode==="chat"||N?.mode==="preview",je=a.useMemo(()=>N?w.filter(_=>_.mode===N.mode):[],[N,w]),ve=a.useMemo(()=>je.map(_=>{const ge=oj(_,I,t),Ie=mj(ge,Z1),Re=nj(_.targetPath,e);return{id:_.id,label:Ie,icon:Gd(_),title:Re?`${ge}: ${Re}`:ge,closeLabel:t("contextPanel.tab.closeTabAria",{label:Ie})}}),[je,e,I,t]),ie=N?.mode==="context"?s.jsx(g1,{}):N?.mode==="git"?s.jsx(kl,{isActive:v}):N?.mode==="pr"?s.jsx(iv,{}):N?.mode==="notes"?s.jsx(Ff,{}):N?.mode==="plan"?s.jsx(Of,{targetPath:N.targetPath}):N?.mode==="preview"?s.jsx(pj,{rawUrl:N.targetPath??"",onNavigate:_=>p(e,_)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(A,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),ee=a.useMemo(()=>w.filter(_=>_.mode==="chat"),[w]),ke=a.useMemo(()=>w.filter(_=>_.mode==="browser"),[w]),ae=a.useMemo(()=>w.filter(_=>_.mode==="diff"),[w]),U=a.useMemo(()=>w.some(_=>_.mode==="terminal"),[w]),le=a.useMemo(()=>w.some(_=>_.mode==="walkthrough"),[w]),_e=gj()?bj:xj,De=a.useMemo(()=>w.some(_=>_.mode==="file"),[w]),ce=a.useMemo(()=>w.some(_=>_.mode==="file"&&_.targetPath),[w]),he=N?.mode==="file",me=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[Ne?s.jsx(fi,{items:ve,activeId:N?.id??null,onSelect:_=>{n&&u(n,_)},onClose:_=>{n&&i(n,_)},onReorder:(_,ge)=>{n&&h(n,_,ge)},layoutMode:"scrollable",variant:"default"}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[N?Gd(N):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:N?Tm(N.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[he?s.jsx(He,{type:"button",variant:"ghost",size:"sm",onClick:b,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":x,children:s.jsx(A,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,s.jsx(He,{type:"button",variant:"ghost",size:"sm",onClick:oe,className:"h-7 w-7 p-0",title:t(D?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(D?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:D?s.jsx(A,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",onClick:ne,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),$=v?D?{"--oc-context-panel-width":F!==null?`${F}px`:"100%",width:F!==null?`${F}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${z}px`}:{"--oc-context-panel-width":`${z}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:te,"data-context-panel":"true",tabIndex:-1,inert:!v||void 0,className:Pe("flex min-h-0 flex-col overflow-hidden bg-background",D?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!v&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:ue,style:$,children:[v&&!D&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),v&&s.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!D&&s.jsx("div",{className:Pe("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",R&&"bg-[var(--interactive-border)]"),onPointerDown:W,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),s.jsxs("div",{className:Pe("relative z-10 flex h-full min-h-0 shrink-0 flex-col duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none","transition-[width,opacity]",!v&&"pointer-events-none select-none opacity-0"),style:{width:D?F!==null?`${F}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!v,children:[me,s.jsxs("div",{className:Pe("relative min-h-0 flex-1 overflow-hidden",R&&"pointer-events-none"),children:[De?s.jsxs("div",{className:Pe("absolute inset-0 flex",he?"flex":"hidden"),children:[s.jsx("div",{className:"h-full min-w-0 flex-1",children:ce?s.jsx(Vf,{mode:"editor-only"}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(A,{name:"file-code",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.editorEmpty.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.editorEmpty.description")})]})}),s.jsx(lj,{visible:x})]}):null,ee.map(_=>{const ge=Wi(_.dedupeKey);if(!ge)return null;const Ie=Se(_.id,ge,_.readOnly);return Ie?s.jsx("iframe",{ref:Re=>{if(!Re){Z.current.delete(_.id);return}Z.current.set(_.id,Re)},src:Ie,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ge}),className:Pe("absolute inset-0 h-full w-full border-0 bg-background",Ae===_.id?"block":"hidden"),onLoad:()=>{Ue(),be(),q()}},_.id):null}),ke.map(_=>s.jsx("div",{className:Pe("absolute inset-0",N?.id!==_.id&&"hidden"),children:s.jsx(_e,{initialUrl:_.targetPath??"",directory:n,tabID:_.id})},_.id)),ae.map(_=>s.jsx("div",{className:Pe("absolute inset-0",N?.id!==_.id&&"hidden"),children:s.jsx(um,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:_.diffScope??(_.stagedDiff?"staged":"working"),onDiffScopeChange:Le,targetFilePath:_.targetPath,flushContent:!0})},_.id)),U?s.jsx("div",{className:Pe("absolute inset-0",N?.mode==="terminal"?"block":"hidden"),children:s.jsx(Lf,{visible:v&&N?.mode==="terminal"})}):null,le?s.jsx("div",{className:Pe("absolute inset-0",N?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(_v,{directory:e})}):null,N?.mode!=="chat"&&!he&&N?.mode!=="browser"&&N?.mode!=="diff"&&N?.mode!=="terminal"&&N?.mode!=="walkthrough"?ie:null]})]})]})},wj=150,vj=768,jj=[],Sj=t=>{const e=ot.c(43),{surface:n,isActive:r,showActivityDot:o,label:i,description:c,onSelect:l}=t;let d;e[0]!==n.id?(d={id:n.id},e[0]=n.id,e[1]=d):d=e[1];const{attributes:u,listeners:h,setNodeRef:f,transform:p,transition:x,isDragging:b}=tc(d);let S;e[2]!==p?(S=sc.Translate.toString(p),e[2]=p,e[3]=S):S=e[3];let g;e[4]!==S||e[5]!==x?(g={transform:S,transition:x},e[4]=S,e[5]=x,e[6]=g):g=e[6];const m=b&&"z-10 opacity-70";let y;e[7]!==m?(y=Pe("relative",m),e[7]=m,e[8]=y):y=e[8];let C;e[9]!==l||e[10]!==n?(C=()=>l(n),e[9]=l,e[10]=n,e[11]=C):C=e[11];const j=r?"text-primary":"text-muted-foreground hover:text-foreground";let w;e[12]!==j?(w=Pe("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",j),e[12]=j,e[13]=w):w=e[13];let N;e[14]!==n.icon||e[15]!==n.id?(N=n.id==="diff"?s.jsx(Kf,{}):s.jsx(A,{name:n.icon,className:"h-[18px] w-[18px]"}),e[14]=n.icon,e[15]=n.id,e[16]=N):N=e[16];let v;e[17]!==o?(v=o?s.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null,e[17]=o,e[18]=v):v=e[18];let D;e[19]!==u||e[20]!==r||e[21]!==i||e[22]!==h||e[23]!==v||e[24]!==C||e[25]!==w||e[26]!==N?(D=s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",...u,...h,onClick:C,"aria-label":i,"aria-pressed":r,className:w,children:[N,v]})}),e[19]=u,e[20]=r,e[21]=i,e[22]=h,e[23]=v,e[24]=C,e[25]=w,e[26]=N,e[27]=D):D=e[27];let F;e[28]!==i?(F=s.jsx("span",{children:i}),e[28]=i,e[29]=F):F=e[29];let k;e[30]!==c?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:c}),e[30]=c,e[31]=k):k=e[31];let E;e[32]!==F||e[33]!==k?(E=s.jsx(Nt,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[F,k]})}),e[32]=F,e[33]=k,e[34]=E):E=e[34];let O;e[35]!==D||e[36]!==E?(O=s.jsxs(St,{delayDuration:wj,children:[D,E]}),e[35]=D,e[36]=E,e[37]=O):O=e[37];let M;return e[38]!==f||e[39]!==O||e[40]!==g||e[41]!==y?(M=s.jsx("div",{ref:f,style:g,className:y,children:O}),e[38]=f,e[39]=O,e[40]=g,e[41]=y,e[42]=M):M=e[42],M},kj=()=>{const t=ot.c(47),{t:e}=ft(),n=Wr();let r;t[0]!==n?(r=n?wo(n):"",t[0]=n,t[1]=r):r=t[1];const o=r;let i;t[2]!==o?(i=z=>o?z.contextPanelByDirectory[o]:void 0,t[2]=o,t[3]=i):i=t[3];const c=Ee(i),l=Ee(Nj),d=Ee(Cj),u=Ee(Aj),h=zl(Dj),{screenWidth:f}=Dr(),p=_o(o||null);let x;t[4]===Symbol.for("react.memo_cache_sentinel")?(x={activationConstraint:{distance:8}},t[4]=x):x=t[4];let b;t[5]===Symbol.for("react.memo_cache_sentinel")?(b={activationConstraint:{delay:200,tolerance:6}},t[5]=b):b=t[5];const S=ra(Do(Xx,x),Do(Qx,b)),g=c?.tabs??jj;let m;t[6]!==c?.activeTabId||t[7]!==g?(m=g.find(z=>z.id===c?.activeTabId)??null,t[6]=c?.activeTabId,t[7]=g,t[8]=m):m=t[8];const y=m,C=c?.isOpen?y?.mode??null:null,j=p?.files.length??0;let w;if(t[9]!==l||t[10]!==h||t[11]!==f||t[12]!==g){let z;t[14]!==h||t[15]!==f||t[16]!==g?(z=T=>T.id==="plan"&&!h||T.id==="walkthrough"&&(nr()||f<vj)?!1:T.availability==="has-content"?g.some(I=>I.mode===T.mode):!0,t[14]=h,t[15]=f,t[16]=g,t[17]=z):z=t[17],w=Vd(l).filter(z),t[9]=l,t[10]=h,t[11]=f,t[12]=g,t[13]=w}else w=t[13];const N=w;let v;t[18]!==d?(v=z=>{const{active:T,over:I}=z;if(!I||T.id===I.id)return;const R=Vd(Ee.getState().contextRailOrder).map(Pj),L=R.indexOf(T.id),P=R.indexOf(I.id);L===-1||P===-1||d(Uf(R,L,P))},t[18]=d,t[19]=v):v=t[19];const D=v;if(!o)return null;let F;t[20]!==e?(F=e("contextRail.aria.rail"),t[20]=e,t[21]=F):F=t[21];let k;t[22]!==N?(k=N.map(Ij),t[22]=N,t[23]=k):k=t[23];let E;if(t[24]!==C||t[25]!==j||t[26]!==o||t[27]!==u||t[28]!==N||t[29]!==e){let z;t[31]!==C||t[32]!==j||t[33]!==o||t[34]!==u||t[35]!==e?(z=T=>s.jsx(Sj,{surface:T,isActive:C===T.mode,showActivityDot:T.id==="git"&&j>0,label:e(T.labelKey),description:e(T.descriptionKey),onSelect:I=>u(o,I.mode)},T.id),t[31]=C,t[32]=j,t[33]=o,t[34]=u,t[35]=e,t[36]=z):z=t[36],E=N.map(z),t[24]=C,t[25]=j,t[26]=o,t[27]=u,t[28]=N,t[29]=e,t[30]=E}else E=t[30];let O;t[37]!==k||t[38]!==E?(O=s.jsx(vl,{items:k,strategy:jl,children:E}),t[37]=k,t[38]=E,t[39]=O):O=t[39];let M;t[40]!==D||t[41]!==S||t[42]!==O?(M=s.jsx(oa,{sensors:S,collisionDetection:ia,onDragEnd:D,children:O}),t[40]=D,t[41]=S,t[42]=O,t[43]=M):M=t[43];let B;return t[44]!==M||t[45]!==F?(B=s.jsx("nav",{"aria-label":F,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:M}),t[44]=M,t[45]=F,t[46]=B):B=t[46],B};function Nj(t){return t.contextRailOrder}function Cj(t){return t.setContextRailOrder}function Aj(t){return t.openContextSurface}function Dj(t){return t.planModeEnabled}function Pj(t){return t.id}function Ij(t){return t.id}const Rj=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),Mj=(t,e,n,r)=>!n||r!==n||t.length===0?[]:ti(t,e,o=>o.name,{limit:10,threshold:.4}),Tj=new Set,Ej=[],Al=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const o=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!o&&!i&&(r=r.replace(/\/+$/,"")),r},Fj=()=>{const t=ot.c(178),{t:e}=ft(),n=Ee(Oj),r=Ee(Lj),o=Ee(Bj),i=Ee($j),c=Ee(_j),l=Ee(zj),d=Ee(Vj),u=Ee(Wj),h=Ee(Uj),f=Ee(Hj),p=Ee(Kj),x=Je(Gj),b=Je(qj);let S;t[0]!==n?(S=Oe=>n?Oe.activeSessions:Ej,t[0]=n,t[1]=S):S=t[1];const g=gn(S);let m;t[2]!==n?(m=Oe=>n?Oe.ids:Tj,t[2]=n,t[3]=m):m=t[3];const y=ui(m);let C;t[4]!==n?(C=Oe=>n?Oe.rankById:Yl,t[4]=n,t[5]=C):C=t[5];const j=Na(C),w=vs(Yj),N=ds(Qj),v=ds(Xj),D=Wr(),F=Qu(Jj),{files:k,git:E}=_n(),O=nn(Zj),{isMobile:M}=Dr();let B;t[6]!==D?(B=D?Al(D):null,t[6]=D,t[7]=B):B=t[7];const z=B,[T,I]=a.useState(""),L=Gl(T,200).trim();let P;t[8]!==T?(P=T.trim(),t[8]=T,t[9]=P):P=t[9];const G=P;let X,V;t[10]!==n?(X=()=>{n&&I("")},V=[n],t[10]=n,t[11]=X,t[12]=V):(X=t[11],V=t[12]),a.useEffect(X,V);let te,Z;t[13]!==g||t[14]!==O||t[15]!==E||t[16]!==n?(te=()=>{if(!n||!E)return;const Oe=setTimeout(()=>{const Te=new Set;for(const it of g){const ut=Bn(it);!ut||Te.has(ut)||(Te.add(ut),O(ut,E))}},0);return()=>clearTimeout(Oe)},Z=[n,g,E,O],t[13]=g,t[14]=O,t[15]=E,t[16]=n,t[17]=te,t[18]=Z):(te=t[17],Z=t[18]),a.useEffect(te,Z);let de;t[19]!==r?(de=()=>r(!1),t[19]=r,t[20]=de):de=t[20];const Fe=de;let se;t[21]!==Fe?(se=Oe=>()=>{Fe(),Oe()},t[21]=Fe,t[22]=se):se=t[22];const Q=se;let Me;t[23]!==N?.id||t[24]!==N?.path||t[25]!==w||t[26]!==M||t[27]!==u||t[28]!==h||t[29]!==x||t[30]!==Q||t[31]!==o||t[32]!==l||t[33]!==i||t[34]!==e||t[35]!==d?(Me=()=>{const Oe=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(A,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:Q(()=>{o("chat"),l(!1),x()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(A,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:Q(e0)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(A,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:Q(t0)},{id:"toggle-sidebar",title:e(M?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(A,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(M?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:Q(()=>{if(M){const{isSessionSwitcherOpen:Te}=Ee.getState();l(!Te)}else d()})},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(A,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:Q(()=>{w&&h(w,"terminal")})},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(A,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:Q(()=>{w&&u(w)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(A,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:Q(()=>i(!0))}];return ma()&&Oe.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(A,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:Q(()=>{Cr("desktop_open_draft_mini_chat_window",{directory:Al(w||N?.path||""),projectId:N?.id??null}).catch(s0)})}),Oe},t[23]=N?.id,t[24]=N?.path,t[25]=w,t[26]=M,t[27]=u,t[28]=h,t[29]=x,t[30]=Q,t[31]=o,t[32]=l,t[33]=i,t[34]=e,t[35]=d,t[36]=Me):Me=t[36],N?.id,N?.path;let xe;t[37]!==Me?(xe=Me(),t[37]=Me,t[38]=xe):xe=t[38];const W=xe;let J;t[39]===Symbol.for("react.memo_cache_sentinel")?(J=ur(),t[39]=J):J=t[39];const ne=J;let oe,ue;t[40]===Symbol.for("react.memo_cache_sentinel")?(oe=nr(),ue=!ne&&Ll(),t[40]=oe,t[41]=ue):(oe=t[40],ue=t[41]);let Ae;t[42]!==M?(Ae={isVSCode:oe,isWeb:ue,isDesktop:ne,isMobile:M},t[42]=M,t[43]=Ae):Ae=t[43];const we=Ae;let Se;if(t[44]!==Q||t[45]!==i||t[46]!==c||t[47]!==we){let Oe;t[49]!==we?(Oe=it=>it.isAvailable?it.isAvailable(we):!0,t[49]=we,t[50]=Oe):Oe=t[50];let Te;t[51]!==Q||t[52]!==i||t[53]!==c?(Te=it=>{const ut=vx(it.slug)??"settings-3",Gt=(it.keywords??[]).join(" ");return{id:`settings:${it.slug}`,title:it.title,icon:it.slug==="mcp"?s.jsx(xl,{className:"mr-2 h-4 w-4"}):s.jsx(A,{name:ut,className:"mr-2 h-4 w-4"}),searchText:`${it.title} ${it.group} ${Gt}`,onSelect:Q(()=>{c(it.slug),i(!0)})}},t[51]=Q,t[52]=i,t[53]=c,t[54]=Te):Te=t[54],Se=wx.filter(n0).filter(Oe).map(Te),t[44]=Q,t[45]=i,t[46]=c,t[47]=we,t[48]=Se}else Se=t[48];const Le=Se;let Ue;t[55]!==g||t[56]!==y||t[57]!==j?(Ue=uf(g,y,j),t[55]=g,t[56]=y,t[57]=j,t[58]=Ue):Ue=t[58];const be=Ue,q=ff(),Ne=Je(r0);let je;t[59]!==q||t[60]!==Ne?(je=(Oe,Te)=>{const it=Ne.get(Oe);return it?.branch?it.branch.trim()||null:Te&&q.get(Te)?.trim()||null},t[59]=q,t[60]=Ne,t[61]=je):je=t[61];const ve=je;let ie;t[62]===Symbol.for("react.memo_cache_sentinel")?(ie=[],t[62]=ie):ie=t[62];const[ee,ke]=a.useState(ie),[ae,U]=a.useState(""),le=Rj(z,L);let _e;t[63]!==z||t[64]!==le||t[65]!==n||t[66]!==F||t[67]!==ke||t[68]!==U||t[69]!==L?(_e=()=>{if(!n){ke([]),U("");return}if(!le){ke([]),U("");return}if(!z){ke([]),U("");return}let Oe=!1;return F(z,L,10,{type:"file"}).then(Te=>{Oe||(ke(Te.map(o0)),U(le))}).catch(()=>{Oe||(ke([]),U(le))}),()=>{Oe=!0}},t[63]=z,t[64]=le,t[65]=n,t[66]=F,t[67]=ke,t[68]=U,t[69]=L,t[70]=_e):_e=t[70];let De;t[71]!==z||t[72]!==le||t[73]!==n||t[74]!==F||t[75]!==L?(De=[n,z,L,le,F],t[71]=z,t[72]=le,t[73]=n,t[74]=F,t[75]=L,t[76]=De):De=t[76],a.useEffect(_e,De);const ce=G.length>0;let he;e:{if(!ce){let Te;t[77]!==W?(Te=W.map(i0),t[77]=W,t[78]=Te):Te=t[78],he=Te;break e}let Oe;t[79]!==W||t[80]!==G?(Oe=ti(W,G,a0,{limit:7,noFuzzy:!0}),t[79]=W,t[80]=G,t[81]=Oe):Oe=t[81],he=Oe}const me=he;let $;e:{if(!ce){let Te;t[82]===Symbol.for("react.memo_cache_sentinel")?(Te=[],t[82]=Te):Te=t[82],$=Te;break e}let Oe;t[83]!==G||t[84]!==Le?(Oe=ti(Le,G,l0,{limit:7,noFuzzy:!0}),t[83]=G,t[84]=Le,t[85]=Oe):Oe=t[85],$=Oe}const _=$;let ge;e:{if(!ce){let Te;t[86]!==be?(Te=be.slice(0,5).map(c0),t[86]=be,t[87]=Te):Te=t[87],ge=Te;break e}let Oe;t[88]!==G||t[89]!==be?(Oe=ti(be,G,d0,{limit:7,threshold:.2}),t[88]=G,t[89]=be,t[90]=Oe):Oe=t[90],ge=Oe}const Ie=ge;let Re;e:{if(!n){let Te;t[91]===Symbol.for("react.memo_cache_sentinel")?(Te=[],t[91]=Te):Te=t[91],Re=Te;break e}let Oe;t[92]!==ee||t[93]!==ae||t[94]!==le||t[95]!==L?(Oe=Mj(ee,L,le,ae),t[92]=ee,t[93]=ae,t[94]=le,t[95]=L,t[96]=Oe):Oe=t[96],Re=Oe}const Ke=Re,nt=n&&le.length>0&&ae!==le;let ct;e:{if(!ce){let Te;t[97]===Symbol.for("react.memo_cache_sentinel")?(Te=[],t[97]=Te):Te=t[97],ct=Te;break e}let Oe;if(t[98]!==G||t[99]!==v){const Te=v.map(u0);Oe=ti(Te,G,f0,{limit:7,threshold:.4}),t[98]=G,t[99]=v,t[100]=Oe}else Oe=t[100];ct=Oe}const mt=ct;let gt,ht,wt,bt,yt,Dt,Kt,Ut,Lt,Bt,et,Ht,It,We;if(t[101]!==ve||t[102]!==Fe||t[103]!==z||t[104]!==k||t[105]!==ce||t[106]!==n||t[107]!==f||t[108]!==x||t[109]!==T||t[110]!==me||t[111]!==Ke||t[112]!==mt||t[113]!==Ie||t[114]!==_||t[115]!==r||t[116]!==b||t[117]!==p||t[118]!==e){const Oe=me.map(m0),Te=_.map(h0),it=Ie.map(p0),ut=ce?Ke.map(g0):[],Gt=ce?mt.map(x0):[];let Ft;e:{if(!ce){Ft=["commands","sessions"];break e}const $t=b0,Pt=[{key:"commands",score:$t(me)},{key:"settings",score:$t(_)},{key:"sessions",score:$t(Ie)},{key:"files",score:$t(Ke)},{key:"projects",score:$t(mt)}];Pt.sort(y0),Ft=Pt.map(w0)}const ze=Ft,Qe=$t=>{Fe(),b($t.id,Bn($t))},st=async $t=>{if(!z)return;const Pt=await rc(k,$t,{directory:z});if(!Pt.ok){fe.error(oc(Pt.reason));return}f(z,$t),Fe()},at=($t,Pt)=>{Fe(),x({selectedProjectId:$t,directoryOverride:Pt})},Ze=$t=>ga(so($t,p));bt=Ps,Ht=n,It=r;let At;t[133]!==e?(At=e("commandPalette.title"),t[133]=e,t[134]=At):At=t[134];let Rt;t[135]!==At?(Rt=s.jsx(Ls,{children:At}),t[135]=At,t[136]=Rt):Rt=t[136];let Zt;t[137]!==e?(Zt=e("commandPalette.description"),t[137]=e,t[138]=Zt):Zt=t[138];let fs;t[139]!==Zt?(fs=s.jsx(Hs,{children:Zt}),t[139]=Zt,t[140]=fs):fs=t[140],t[141]!==Rt||t[142]!==fs?(We=s.jsxs(Us,{className:"sr-only",children:[Rt,fs]}),t[141]=Rt,t[142]=fs,t[143]=We):We=t[143],wt=Is,Bt="overflow-hidden p-0",et=!0,ht=ba,Kt=!1,Ut="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let ls;t[144]!==e?(ls=e("commandPalette.input.placeholder"),t[144]=e,t[145]=ls):ls=t[145],t[146]!==T||t[147]!==ls?(Lt=s.jsx(ya,{value:T,onValueChange:I,placeholder:ls}),t[146]=T,t[147]=ls,t[148]=Lt):Lt=t[148],gt=wa;let Ot;t[149]!==e?(Ot=e("commandPalette.empty.noResults"),t[149]=e,t[150]=Ot):Ot=t[150],t[151]!==Ot?(yt=s.jsx(va,{children:Ot}),t[151]=Ot,t[152]=yt):yt=t[152],Dt=ze.map($t=>$t==="commands"&&Oe.length>0?s.jsx(Sr,{children:Oe.map(Pt=>s.jsxs(kr,{value:Pt.id,onSelect:Pt.onSelect,children:[Pt.icon,s.jsx("span",{children:Pt.title}),Pt.shortcutId?s.jsx(_p,{children:Ze(Pt.shortcutId)}):null]},Pt.id))},"commands"):$t==="settings"&&Te.length>0?s.jsx(Sr,{children:Te.map(v0)},"settings"):$t==="sessions"&&it.length>0?s.jsx(Sr,{children:it.map(Pt=>{const ms=Pt.title||e("commandPalette.session.untitled"),Ks=Bn(Pt),Yt=ve(Pt.id,Ks);return s.jsxs(kr,{value:`session:${Pt.id}`,onSelect:()=>Qe(Pt),children:[s.jsx(A,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:ms}),Yt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Yt})]}):null]},Pt.id)})},"sessions"):$t==="files"&&ut.length>0?s.jsx(Sr,{children:ut.map(Pt=>{const ms=zp(Pt.relativePath||Pt.name,{maxLength:80});return s.jsxs(kr,{value:`file:${Pt.path}`,onSelect:()=>{st(Pt.path)},children:[s.jsx($o,{filePath:Pt.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Pt.relativePath,children:ms})]},`file:${Pt.path}`)})},"files"):$t==="projects"&&Gt.length>0?s.jsx(Sr,{children:Gt.map(Pt=>{const ms=Pt.displayName;return s.jsxs(kr,{value:`project:${Pt.id}`,onSelect:()=>at(Pt.id,Pt.path),children:[s.jsx(A,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:ms}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:Pt.path})]},`project:${Pt.id}`)})},"projects"):null),t[101]=ve,t[102]=Fe,t[103]=z,t[104]=k,t[105]=ce,t[106]=n,t[107]=f,t[108]=x,t[109]=T,t[110]=me,t[111]=Ke,t[112]=mt,t[113]=Ie,t[114]=_,t[115]=r,t[116]=b,t[117]=p,t[118]=e,t[119]=gt,t[120]=ht,t[121]=wt,t[122]=bt,t[123]=yt,t[124]=Dt,t[125]=Kt,t[126]=Ut,t[127]=Lt,t[128]=Bt,t[129]=et,t[130]=Ht,t[131]=It,t[132]=We}else gt=t[119],ht=t[120],wt=t[121],bt=t[122],yt=t[123],Dt=t[124],Kt=t[125],Ut=t[126],Lt=t[127],Bt=t[128],et=t[129],Ht=t[130],It=t[131],We=t[132];let pt;t[153]!==nt||t[154]!==e?(pt=nt?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[153]=nt,t[154]=e,t[155]=pt):pt=t[155];let Mt;t[156]!==gt||t[157]!==yt||t[158]!==Dt||t[159]!==pt?(Mt=s.jsxs(gt,{children:[yt,Dt,pt]}),t[156]=gt,t[157]=yt,t[158]=Dt,t[159]=pt,t[160]=Mt):Mt=t[160];let Et;t[161]!==ht||t[162]!==Kt||t[163]!==Ut||t[164]!==Lt||t[165]!==Mt?(Et=s.jsxs(ht,{shouldFilter:Kt,className:Ut,children:[Lt,Mt]}),t[161]=ht,t[162]=Kt,t[163]=Ut,t[164]=Lt,t[165]=Mt,t[166]=Et):Et=t[166];let tt;t[167]!==wt||t[168]!==Bt||t[169]!==et||t[170]!==Et?(tt=s.jsx(wt,{className:Bt,showCloseButton:et,children:Et}),t[167]=wt,t[168]=Bt,t[169]=et,t[170]=Et,t[171]=tt):tt=t[171];let pe;return t[172]!==bt||t[173]!==Ht||t[174]!==It||t[175]!==We||t[176]!==tt?(pe=s.jsxs(bt,{open:Ht,onOpenChange:It,children:[We,tt]}),t[172]=bt,t[173]=Ht,t[174]=It,t[175]=We,t[176]=tt,t[177]=pe):pe=t[177],pe};function Oj(t){return t.isCommandPaletteOpen}function Lj(t){return t.setCommandPaletteOpen}function Bj(t){return t.setActiveMainTab}function $j(t){return t.setSettingsDialogOpen}function _j(t){return t.setSettingsPage}function zj(t){return t.setSessionSwitcherOpen}function Vj(t){return t.toggleSidebar}function Wj(t){return t.openContextOverview}function Uj(t){return t.openContextSurface}function Hj(t){return t.openContextFile}function Kj(t){return t.shortcutOverrides}function Gj(t){return t.openNewSessionDraft}function qj(t){return t.setCurrentSession}function Yj(t){return t.currentDirectory}function Qj(t){return t.getActiveProject()}function Xj(t){return t.projects}function Jj(t){return t.searchFiles}function Zj(t){return t.ensureStatus}function e0(){mf()}function t0(){Gn.requestDirectoryDialog()}function s0(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function n0(t){return t.slug!=="home"}function r0(t){return t.worktreeMetadata}function o0(t){return{path:Al(t.path),name:t.name,relativePath:t.relativePath}}function i0(t){return{item:t,score:0}}function a0(t){return t.searchText}function l0(t){return t.searchText}function c0(t){return{item:t,score:0}}function d0(t){return t.title||""}function u0(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function f0(t){return t.searchText}function m0(t){return t.item}function h0(t){return t.item}function p0(t){return t.item}function g0(t){return t.item}function x0(t){return t.item}function b0(t){return t.length?t[0].score:1/0}function y0(t,e){return t.score-e.score}function w0(t){return t.key}function v0(t){return s.jsxs(kr,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Xd=(t,e,n)=>Wp(t)?ga(so(t,n)):e,j0=()=>{const t=ot.c(69),{t:e}=ft(),n=Ee(S0),r=Ee(k0),o=Ee(N0);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=Vp(),t[0]=i):i=t[0];const c=i;let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=nr(),t[1]=l):l=t[1];const d=l;let u,h,f,p,x,b,S,g,m;if(t[2]!==n||t[3]!==r||t[4]!==o||t[5]!==e){const I=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"helpDialog.item.addSelectionToChat",icon:"add",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${c} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"toggle_prompt_navigator",descriptionKey:"helpDialog.item.togglePromptNavigator",icon:"list-unordered",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${c} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];h=Ps,g=n,m=r,u=Is,b="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let R;t[15]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(A,{name:"settings-3",className:"h-5 w-5"}),t[15]=R):R=t[15];let L;t[16]!==e?(L=e("helpDialog.title"),t[16]=e,t[17]=L):L=t[17];let P;t[18]!==L?(P=s.jsxs(Ls,{className:"flex items-center gap-2",children:[R,L]}),t[18]=L,t[19]=P):P=t[19];let G;t[20]!==e?(G=e("helpDialog.description"),t[20]=e,t[21]=G):G=t[21];let X;t[22]!==G?(X=s.jsx(Hs,{children:G}),t[22]=G,t[23]=X):X=t[23],t[24]!==P||t[25]!==X?(S=s.jsxs(Us,{children:[P,X]}),t[24]=P,t[25]=X,t[26]=S):S=t[26],x="flex-1 overflow-y-auto mt-3 pr-1",f="space-y-4",p=I.map(V=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(V.categoryKey)}),s.jsx("div",{className:"space-y-1",children:V.items.filter(te=>!(d&&te.id==="toggle_prompt_navigator")).map(te=>{const Z=te.id?Xd(te.id,Array.isArray(te.keys)?te.keys[0]:te.keys,o):Array.isArray(te.keys)?te.keys:te.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[te.icon&&s.jsx(A,{name:te.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(te.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(Z)?Z:[Z]).map((de,Fe)=>s.jsxs(a.Fragment,{children:[Fe>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:de})]},`${de}-${Fe}`))})]},te.id||te.descriptionKey)})})]},V.categoryKey)),t[2]=n,t[3]=r,t[4]=o,t[5]=e,t[6]=u,t[7]=h,t[8]=f,t[9]=p,t[10]=x,t[11]=b,t[12]=S,t[13]=g,t[14]=m}else u=t[6],h=t[7],f=t[8],p=t[9],x=t[10],b=t[11],S=t[12],g=t[13],m=t[14];let y;t[27]!==f||t[28]!==p?(y=s.jsx("div",{className:f,children:p}),t[27]=f,t[28]=p,t[29]=y):y=t[29];let C;t[30]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(A,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[30]=C):C=t[30];let j;t[31]!==e?(j=e("helpDialog.proTips.title"),t[31]=e,t[32]=j):j=t[32];let w;t[33]!==j?(w=s.jsx("p",{className:"font-medium mb-1",children:j}),t[33]=j,t[34]=w):w=t[34];let N;t[35]!==o||t[36]!==e?(N=e("helpDialog.proTips.commandPalette",{shortcut:Xd("open_command_palette",`${c} P`,o)}),t[35]=o,t[36]=e,t[37]=N):N=t[37];let v;t[38]!==N?(v=s.jsxs("li",{children:["• ",N]}),t[38]=N,t[39]=v):v=t[39];let D;t[40]!==e?(D=e("helpDialog.proTips.recentSessions"),t[40]=e,t[41]=D):D=t[41];let F;t[42]!==D?(F=s.jsxs("li",{children:["• ",D]}),t[42]=D,t[43]=F):F=t[43];let k;t[44]!==e?(k=e("helpDialog.proTips.themeCycling"),t[44]=e,t[45]=k):k=t[45];let E;t[46]!==k?(E=s.jsxs("li",{children:["• ",k]}),t[46]=k,t[47]=E):E=t[47];let O;t[48]!==v||t[49]!==F||t[50]!==E?(O=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[v,F,E]}),t[48]=v,t[49]=F,t[50]=E,t[51]=O):O=t[51];let M;t[52]!==w||t[53]!==O?(M=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[C,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[w,O]})]})}),t[52]=w,t[53]=O,t[54]=M):M=t[54];let B;t[55]!==M||t[56]!==x||t[57]!==y?(B=s.jsxs("div",{className:x,children:[y,M]}),t[55]=M,t[56]=x,t[57]=y,t[58]=B):B=t[58];let z;t[59]!==u||t[60]!==B||t[61]!==b||t[62]!==S?(z=s.jsxs(u,{className:b,children:[S,B]}),t[59]=u,t[60]=B,t[61]=b,t[62]=S,t[63]=z):z=t[63];let T;return t[64]!==h||t[65]!==z||t[66]!==g||t[67]!==m?(T=s.jsx(h,{open:g,onOpenChange:m,children:z}),t[64]=h,t[65]=z,t[66]=g,t[67]=m,t[68]=T):T=t[68],T};function S0(t){return t.isHelpDialogOpen}function k0(t){return t.setHelpDialogOpen}function N0(t){return t.shortcutOverrides}const C0=()=>{const t=ot.c(32),{t:e}=ft(),n=Ee(A0),r=Ee(D0),o=Ee(P0);let i;t[0]!==o||t[1]!==e?(i=async()=>{if(!o)return;if((await tr(o)).ok){fe.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}fe.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=o,t[1]=e,t[2]=i):i=t[2];const c=i;let l;t[3]!==e?(l=e("openCodeStatusDialog.title"),t[3]=e,t[4]=l):l=t[4];let d;t[5]!==l?(d=s.jsx(Ls,{children:l}),t[5]=l,t[6]=d):d=t[6];let u;t[7]!==e?(u=e("openCodeStatusDialog.description"),t[7]=e,t[8]=u):u=t[8];let h;t[9]!==u?(h=s.jsx(Hs,{children:u}),t[9]=u,t[10]=h):h=t[10];let f;t[11]!==d||t[12]!==h?(f=s.jsxs(Us,{children:[d,h]}),t[11]=d,t[12]=h,t[13]=f):f=t[13];let p;t[14]!==e?(p=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=p):p=t[15];let x;t[16]!==c||t[17]!==p?(x=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:c,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:p})}),t[16]=c,t[17]=p,t[18]=x):x=t[18];let b;t[19]!==o||t[20]!==e?(b=o||e("openCodeStatusDialog.empty.noData"),t[19]=o,t[20]=e,t[21]=b):b=t[21];let S;t[22]!==b?(S=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:b}),t[22]=b,t[23]=S):S=t[23];let g;t[24]!==f||t[25]!==x||t[26]!==S?(g=s.jsxs(Is,{className:"max-w-2xl",children:[f,x,S]}),t[24]=f,t[25]=x,t[26]=S,t[27]=g):g=t[27];let m;return t[28]!==n||t[29]!==r||t[30]!==g?(m=s.jsx(Ps,{open:n,onOpenChange:r,children:g}),t[28]=n,t[29]=r,t[30]=g,t[31]=m):m=t[31],m};function A0(t){return t.isOpenCodeStatusDialogOpen}function D0(t){return t.setOpenCodeStatusDialogOpen}function P0(t){return t.openCodeStatusText}const I0=180,Jd=600,R0=1,M0=6,T0=t=>{const e=t?.directory;return typeof e=="string"&&e.trim()?e:null},E0=({enabled:t=!0,currentSessionId:e,sortedSessions:n,recentSessions:r=[],prefetchSession:o})=>{const i=a.useRef(new Map),c=a.useRef([]),l=a.useRef(new Set),d=a.useRef(0),u=a.useMemo(()=>nr(),[]),h=a.useCallback(b=>`${b.directory}
|
|
194
|
+
${b.sessionId}`,[]),f=a.useCallback(()=>{d.current+=1,c.current=[],i.current.forEach(b=>window.clearTimeout(b)),i.current.clear()},[]),p=a.useCallback(()=>{if(!(!t||u||typeof window>"u"))for(;l.current.size<R0&&c.current.length>0;){const b=c.current.shift();if(!b)break;if(b.generation!==d.current||Je.getState().currentSessionId===b.sessionId||Fc(b.sessionId,b.directory).renderable)continue;const g=h(b);l.current.add(g),o(b.sessionId,b.directory).catch(()=>{}).finally(()=>{l.current.delete(g),p()})}},[t,u,o,h]),x=a.useCallback(b=>{const S=b?.id,g=T0(b);if(!t||u||!S||!g||S===e||typeof window>"u")return;const m={sessionId:S,directory:g,generation:d.current},y=h(m);if(Fc(S,g).renderable||l.current.has(y)||c.current.some(w=>h(w)===y))return;const C=i.current.get(y);C!==void 0&&window.clearTimeout(C);const j=window.setTimeout(()=>{if(i.current.delete(y),m.generation!==d.current)return;const w=c.current;w.length>=M0&&w.shift(),w.push(m),p()},I0);i.current.set(y,j)},[e,t,u,p,h]);a.useEffect(()=>{f()},[f,e,t,u]),a.useEffect(()=>{if(!t||u||!e||n.length===0)return;const b=window.setTimeout(()=>{const S=n.findIndex(g=>g.id===e);S<0||(x(n[S-1]),x(n[S+1]))},Jd);return()=>window.clearTimeout(b)},[e,t,u,x,n]),a.useEffect(()=>{if(!t||u||!e||r.length===0)return;const b=window.setTimeout(()=>{const S=r.findIndex(g=>g.id===e);S<0||(x(r[S-1]),x(r[S+1]))},Jd);return()=>window.clearTimeout(b)},[e,t,u,r,x]),a.useEffect(()=>f,[f])},F0=t=>{const e=ot.c(3),n=Je(O0);let r;return e[0]!==t||e[1]!==n?(r={...t,currentSessionId:n},e[0]=t,e[1]=n,e[2]=r):r=e[2],E0(r),null};function O0(t){return t.currentSessionId}const L0=t=>{const e=ot.c(12),{normalizedProjects:n,enabled:r,ownership:o,isSessionsLoading:i,hasAuthoritativeGlobalSessions:c,isWorktreeTopologyLoading:l,unresolvedWorktreeProjectPaths:d,foldersMap:u,createFolder:h,addSessionToFolder:f}=t,p=r===void 0?!0:r;let x,b;e[0]!==f||e[1]!==h||e[2]!==p||e[3]!==u||e[4]!==c||e[5]!==i||e[6]!==l||e[7]!==n||e[8]!==o||e[9]!==d?(x=()=>{!p||i||!c||l||n.forEach(S=>{if(d.has(S.normalizedPath))return;const g=hf(S.normalizedPath),m=o.archivedSessionsByProject.get(S.id)??[],y=u[g]??[],C=new Map(y.map(B0));m.forEach(j=>{const w=Up(j,S.normalizedPath),N=w.toLowerCase();let v=C.get(N);v||(v=h(g,w),C.set(N,v)),v.sessionIds.includes(j.id)||f(g,v.id,j.id)})})},b=[n,p,o,i,c,l,d,u,h,f],e[0]=f,e[1]=h,e[2]=p,e[3]=u,e[4]=c,e[5]=i,e[6]=l,e[7]=n,e[8]=o,e[9]=d,e[10]=x,e[11]=b):(x=e[10],b=e[11]),a.useEffect(x,b)};function B0(t){return[t.name.toLowerCase(),t]}const $0=t=>{const e=ot.c(4);let n;e[0]!==t?(n=(i,c)=>{const l=t.get(i);if(!l||l.length===0)return c;const d=new Map(c.map(_0)),u=[];l.forEach(p=>{const x=d.get(p);x&&(u.push(x),d.delete(p))});const h=[],f=[];return c.forEach(p=>{d.has(p.id)&&(p.isArchivedBucket?f.push(p):h.push(p))}),[...h,...u,...f]},e[0]=t,e[1]=n):n=e[1];const r=n;let o;return e[2]!==r?(o={getOrderedGroups:r},e[2]=r,e[3]=o):o=e[3],o};function _0(t){return[t.id,t]}const z0=[],V0=t=>{const{normalizedProjects:e,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:o,projectRepoStatus:i,projectRootBranches:c,lastRepoStatus:l,buildGroupedSessions:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,filterSessionNodesForSearch:f,buildGroupSearchText:p,foldersMap:x}=t,b=a.useRef(new Map),S=a.useMemo(()=>{const v=b.current,D=new Map;let F=0,k=0;const E=(M,B)=>M.length===B.length&&M.every((z,T)=>z===B[T]),O=e.map(M=>{const B=n(M.id),z=r(M.id),T=o.get(M.normalizedPath)??z0,I=i.has(M.id)?!!i.get(M.id):l,R=c.get(M.id)??null,L=v.get(M.id);if(L&&L.project===M&&E(L.activeSessions,B)&&E(L.archivedSessions,z)&&L.availableWorktrees===T&&L.rootBranch===R&&L.isRepo===I&&L.buildGroupedSessions===d)return F+=1,D.set(M.id,L),L.section;k+=1;const P=pf([...B,...z]),G=d(P,M.normalizedPath,T,R,I),X={project:M,groups:G};return D.set(M.id,{project:M,activeSessions:B,archivedSessions:z,availableWorktrees:T,rootBranch:R,isRepo:I,buildGroupedSessions:d,section:X}),X});return b.current=D,F>0&&Zn("ui.sidebar.project_section.reused",F),k>0&&Zn("ui.sidebar.project_section.rebuilt",k),O},[e,n,r,o,i,l,d,c]),g=a.useMemo(()=>S,[S]),m=a.useMemo(()=>{const v=new WeakMap;if(!u)return v;const D=F=>F.reduce((k,E)=>k+1+D(E.children),0);return g.forEach(F=>{F.groups.forEach(k=>{const E=f(k.sessions,h),O=D(E),M=p(k).includes(h),B=_t(k.directory??null),T=(B?x[B]??[]:[]).filter(I=>I.name.toLowerCase().includes(h)).length;v.set(k,{filteredNodes:E,matchedSessionCount:O,folderNameMatchCount:T,groupMatches:M,hasMatch:M||O>0||T>0})})}),v},[u,g,f,h,p,x]),y=a.useMemo(()=>u?g.map(v=>({...v,groups:v.groups.filter(D=>m.get(D)?.hasMatch===!0)})).filter(v=>v.groups.length>0):g,[u,g,m]),C=u?y:g,j=a.useRef(new WeakMap),w=a.useMemo(()=>{const v=j.current;return C.map(D=>{const F=v.get(D);if(F&&F.query===h)return F.section;const k=D.groups.filter(I=>!I.isArchivedBucket),E=D.groups.filter(I=>I.isArchivedBucket),O=k.flatMap(I=>u?m.get(I)?.filteredNodes??[]:I.sessions),M=k.map(I=>({scopeKey:I.folderScopeKey??_t(I.directory??null),directory:I.directory??null})).filter(I=>!!I.scopeKey),B=k.find(I=>I.isMain)??null,z={id:"flat",label:B?.label??"",branch:B?.branch??null,description:B?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:B?.directory??D.project.normalizedPath,folderScopeKey:B?.folderScopeKey??D.project.normalizedPath,folderScopes:M,sessions:O};if(u){const I=k.map(R=>m.get(R)).filter(R=>!!R);m.set(z,{filteredNodes:O,matchedSessionCount:I.reduce((R,L)=>R+L.matchedSessionCount,0),folderNameMatchCount:I.reduce((R,L)=>R+L.folderNameMatchCount,0),groupMatches:I.some(R=>R.groupMatches),hasMatch:I.some(R=>R.hasMatch)})}const T={project:D.project,groups:[z,...E]};return v.set(D,{query:h,section:T}),T})},[m,u,h,C]),N=a.useMemo(()=>u?C.reduce((v,D)=>v+D.groups.reduce((F,k)=>{const E=m.get(k);if(!E)return F;const O=E.folderNameMatchCount+(E.groupMatches?1:0);return F+E.matchedSessionCount+O},0),0):0,[u,C,m]);return{projectSections:S,visibleProjectSections:g,groupSearchDataByGroup:m,searchableProjectSections:y,sectionsForRender:C,flatSectionsForRender:w,searchMatchCount:N}},W0=t=>{const e=ot.c(26),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:i,currentSessionId:c,handleSessionSelect:l,newSessionDraftOpen:d,mobileVariant:u,openNewSessionDraft:h,setActiveMainTab:f,setSessionSwitcherOpen:p}=t;let x,b;if(e[0]!==n){b=new Map,x=new Map;const N=(v,D,F,k)=>{b.has(v)||b.set(v,new Map);const E=b.get(v);k.forEach(O=>{const M=_t(O.worktree?.path??O.session.directory??F??D);E.set(O.session.id,{directory:M}),x.has(v)||x.set(v,{id:O.session.id,directory:M}),O.children.length>0&&N(v,D,M,O.children)})};n.forEach(v=>{v.groups.forEach(D=>{N(v.project.id,v.project.normalizedPath,D.directory,D.sessions)})}),e[0]=n,e[1]=x,e[2]=b}else x=e[1],b=e[2];let S;e[3]!==x||e[4]!==b?(S={metaByProject:b,firstSessionByProject:x},e[3]=x,e[4]=b,e[5]=S):S=e[5];const g=S,m=a.useRef(null);let y,C;e[6]!==r||e[7]!==o||e[8]!==c||e[9]!==l||e[10]!==u||e[11]!==d||e[12]!==h||e[13]!==n||e[14]!==g||e[15]!==f||e[16]!==i||e[17]!==p?(y=()=>{if(!r||d||Ee.getState().isNewWorktreeDialogOpen||m.current===r)return;const N=n.find(M=>M.project.id===r);if(!N)return;m.current=r;const v=g.metaByProject.get(r);if(c&&v&&v.has(c)){i(M=>{if(M.get(r)===c)return M;const B=new Map(M);return B.set(r,c),B});return}if(c&&v)return;if(!v||v.size===0){f("chat"),u&&p(!1),h({selectedProjectId:N.project.id,directoryOverride:N.project.normalizedPath});return}const D=o.get(r),F=D&&v.has(D)?D:null,k=g.firstSessionByProject.get(r)?.id??null,E=F??k;if(!E||E===c)return;const O=v.get(E)?.directory??null;l(E,O)},C=[r,o,c,l,d,u,h,n,g,f,p,i],e[6]=r,e[7]=o,e[8]=c,e[9]=l,e[10]=u,e[11]=d,e[12]=h,e[13]=n,e[14]=g,e[15]=f,e[16]=i,e[17]=p,e[18]=y,e[19]=C):(y=e[18],C=e[19]),a.useLayoutEffect(y,C);let j,w;e[20]!==r||e[21]!==c||e[22]!==g||e[23]!==i?(j=()=>{if(!r||!c)return;const N=g.metaByProject.get(r);!N||!N.has(c)||i(v=>{if(v.get(r)===c)return v;const D=new Map(v);return D.set(r,c),D})},w=[r,c,g,i],e[20]=r,e[21]=c,e[22]=g,e[23]=i,e[24]=j,e[25]=w):(j=e[24],w=e[25]),a.useEffect(j,w)},U0=t=>{const e=ot.c(15);let n,r,o;e[0]!==t?({initialActiveSessionByProject:r,persistActiveSessionByProject:o,...n}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);const i=Je(H0),c=Je(K0);let l;e[4]!==r?(l=()=>new Map(r),e[4]=r,e[5]=l):l=e[5];const[d,u]=a.useState(l);let h;e[6]!==d||e[7]!==n||e[8]!==i||e[9]!==c?(h={...n,activeSessionByProject:d,setActiveSessionByProject:u,currentSessionId:i,newSessionDraftOpen:c},e[6]=d,e[7]=n,e[8]=i,e[9]=c,e[10]=h):h=e[10],W0(h);let f,p;return e[11]!==d||e[12]!==o?(f=()=>{o(d)},p=[d,o],e[11]=d,e[12]=o,e[13]=f,e[14]=p):(f=e[13],p=e[14]),a.useEffect(f,p),null};function H0(t){return t.currentSessionId}function K0(t){return!!t.newSessionDraft?.open}const Dl=new Map,G0=(t,e)=>{for(const n of t){const r=_t(n??null);r&&!Dl.has(r)&&Dl.set(r,e)}},Zd=t=>{const e=_t(t??null);return e?Dl.get(e)??0:0},Pi=t=>!!t.time?.archived,q0=t=>{const{t:e}=ft(),n=a.useCallback(c=>[c.label,c.branch??"",c.description??"",c.directory??""].join(" ").toLowerCase(),[]),r=a.useCallback(c=>{const l=_t(c.directory??null)??"";return`${(c.title||e("sessions.sidebar.session.untitled")).trim()} ${l}`.toLowerCase()},[e]),o=a.useCallback((c,l)=>l?c.flatMap(d=>{if(r(d.session).includes(l))return[d];const h=o(d.children,l);return h.length===0?[]:[{...d,children:h}]}):c,[r]),i=a.useCallback((c,l,d,u,h)=>{const f=_t(l??null),p=pf(c).sort((O,M)=>Eo(O,M,t.pinnedSessionIds,t.sessionOrderRanks)),x=new Map(p.map(O=>[O.id,O])),b=new Map;p.forEach(O=>{const M=O.parentID;if(!M)return;const B=x.get(M);if(!B||Pi(B)!==Pi(O))return;const z=b.get(M)??[];z.push(O),b.set(M,z)}),b.forEach(O=>O.sort((M,B)=>Eo(M,B,t.pinnedSessionIds,t.sessionOrderRanks)));const S=new Map;d.forEach(O=>{if(O.path){const M=_t(O.path)??O.path;S.set(M,O)}});const g=O=>{const M=_t(O.directory??null),B=t.worktreeMetadata.get(O.id)??null;if(B)return B;if(M){const z=S.get(M)??null;if(z&&M!==f)return z}return null},m=O=>{const M=b.get(O.id)??[];return{session:O,children:M.map(B=>m(B)),worktree:g(O)}},y=p.filter(O=>{const M=O.parentID;if(!M)return!0;const B=x.get(M);return B?Pi(B)!==Pi(O):!0}),C=new Map,j="__archived__",w=O=>{if(O.time?.archived)return j;if(t.isVSCode)return f??"__project_root__";const B=_t(t.worktreeMetadata.get(O.id)?.path??null)??Bn(O);return B?B!==f&&S.has(B)?B:B===f?f??"__project_root__":j:j};y.forEach(O=>{const M=m(O),B=w(O);C.has(B)||C.set(B,[]),C.get(B)?.push(M)});const N=f??"__project_root__",v=[{id:"root",label:h&&u&&u!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:u}):e("sessions.sidebar.grouping.projectRoot"),branch:u??null,description:f?Zi(f,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:C.get(N)??[]}],D=new Map;d.forEach(O=>{const M=_t(O.path)??O.path,B=C.get(M)??[],z=B.length>0,T=B.reduce((I,R)=>{const L=Hp(R.session,t.sessionOrderRanks);return Number.isFinite(L)?Math.max(I,L):I},0);D.set(M,{hasActiveSession:z,lastUpdatedAt:T})});const F=[...d].sort((O,M)=>{const B=_t(O.path)??O.path,z=_t(M.path)??M.path,T=D.get(B)??{hasActiveSession:!1,lastUpdatedAt:0},I=D.get(z)??{hasActiveSession:!1,lastUpdatedAt:0};if(T.hasActiveSession!==I.hasActiveSession)return T.hasActiveSession?-1:1;if(T.hasActiveSession&&I.hasActiveSession)return I.lastUpdatedAt-T.lastUpdatedAt;const R=Zd(O.path),L=Zd(M.path);if(R!==L)return L-R;const P=(O.label||O.branch||O.name||O.path||"").toLowerCase(),G=(M.label||M.branch||M.name||M.path||"").toLowerCase();return P.localeCompare(G)});(t.isVSCode?[]:F).forEach(O=>{const M=_t(O.path)??O.path,B=t.gitBranches.get(M)?.trim()||null,z=O.branch?.trim()||null,I=!!(B&&z&&O.label&&Oc(O.label)===Oc(z))?B:O.label||O.name||Vr(M,t.homeDirectory)||M;v.push({id:`worktree:${M}`,label:I,branch:B||z,description:Zi(M,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:O,directory:M,folderScopeKey:M,sessions:C.get(M)??[]})});const E=C.get(j)??[];return E.length>0&&v.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&f?hf(f):null,sessions:E}),v},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.sessionOrderRanks,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:i}},Y0=t=>{const e=ot.c(11),{enabled:n,isSessionSearchOpen:r,setIsSessionSearchOpen:o,sessionSearchInputRef:i,sessionSearchContainerRef:c}=t,l=n===void 0?!0:n;let d,u;e[0]!==l||e[1]!==r||e[2]!==i?(d=()=>{if(!l||!r||typeof window>"u")return;const p=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(p)},u=[l,r,i],e[0]=l,e[1]=r,e[2]=i,e[3]=d,e[4]=u):(d=e[3],u=e[4]),a.useEffect(d,u);let h,f;e[5]!==l||e[6]!==r||e[7]!==c||e[8]!==o?(h=()=>{if(!l||!r||typeof document>"u")return;const p=x=>{c.current&&(c.current.contains(x.target)||o(!1))};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},f=[l,r,o,c],e[5]=l,e[6]=r,e[7]=c,e[8]=o,e[9]=h,e[10]=f):(h=e[9],f=e[10]),a.useEffect(h,f)},Q0=t=>{const e=ot.c(50),{t:n}=ft(),[r,o]=a.useState(null),i=a.useRef(null);let c,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{i.current&&clearTimeout(i.current)},l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),a.useEffect(c,l);let d;e[2]!==t?(d=(X,V)=>{ul("navigation.session_select"),Ee.getState().closeMainSurfaces();const te=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),X===Je.getState().currentSessionId){t.allowReselect&&t.onSessionSelected?.(X),te();return}ul("navigation.session_state_set"),t.setCurrentSession(X,V??null),t.onSessionSelected?.(X),te()},e[2]=t,e[3]=d):d=e[3];const u=d;let h;e[4]!==t?(h=(X,V)=>{t.setEditingId(X),t.setEditTitle(V)},e[4]=t,e[5]=h):h=e[5];const f=h;let p;e[6]!==t?(p=async X=>{if(!t.editingId)return;const V=(X??t.editTitle).trim();V&&await t.updateSessionTitle(t.editingId,V),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=p):p=e[7];const x=p;let b;e[8]!==t?(b=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=b):b=e[9];const S=b;let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=async(X,V)=>{try{return(await tr(X)).ok?(o(V),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{o(null),i.current=null},2e3),!0):!1}catch{return!1}},e[10]=g):g=e[10];const m=g;let y;e[11]!==t||e[12]!==n?(y=async X=>{const V=await t.shareSession(X.id);if(!V?.share?.url){fe.error(n("sessions.sidebar.session.share.error"));return}const te=await m(V.share.url,X.id);fe[te?"success":"warning"](n("sessions.sidebar.session.share.successTitle"),{description:n(te?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},e[11]=t,e[12]=n,e[13]=y):y=e[13];const C=y;let j;e[14]!==n?(j=(X,V)=>{m(X,V).then(te=>{te||fe.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[14]=n,e[15]=j):j=e[15];const w=j;let N;e[16]!==n?(N=X=>{tr(X).then(V=>{if(V.ok){fe.success(n("sessions.sidebar.session.copyId.success"));return}fe.error(n("sessions.sidebar.session.copyId.error"))}).catch(()=>fe.error(n("sessions.sidebar.session.copyId.error")))},e[16]=n,e[17]=N):N=e[17];const v=N;let D;e[18]!==t||e[19]!==n?(D=async X=>{await t.unshareSession(X)?fe.success(n("sessions.sidebar.session.unshare.success")):fe.error(n("sessions.sidebar.session.unshare.error"))},e[18]=t,e[19]=n,e[20]=D):D=e[20];const F=D;let k;e[21]!==t.childrenMap?(k=X=>{const V=[],te=Z=>{(t.childrenMap.get(Z)??[]).forEach(Fe=>{V.push(Fe),te(Fe.id)})};return te(X),V},e[21]=t.childrenMap,e[22]=k):k=e[22];const E=k,O=J0;let M;e[23]!==t||e[24]!==E||e[25]!==n?(M=async(X,V,te)=>{const Z=V?.archivedBucket===!0||V?.hardDelete===!0,de=te?.descendantIds??O(E(X.id),Z).map(Z0);if(de.length===0){(Z?await t.deleteSession(X.id):await t.archiveSession(X.id))?fe.success(n(Z?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):fe.error(n(Z?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const Fe=[X.id,...de];if(Z){const{deletedIds:Me,failedIds:xe}=await t.deleteSessions(Fe);if(xe.length===0){const W=Me.length;fe.success(W===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:W}):n("sessions.sidebar.bulkActions.deletedPlural",{count:W}))}else fe.error(n("sessions.sidebar.session.delete.error"));return}const{archivedIds:se,failedIds:Q}=await t.archiveSessions(Fe);se.length>0&&fe.success(se.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:se.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:se.length})),Q.length>0&&fe.error(Q.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Q.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:Q.length}))},e[23]=t,e[24]=E,e[25]=n,e[26]=M):M=e[26];const B=M;let z;e[27]!==t||e[28]!==E||e[29]!==B?(z=(X,V)=>{const te=V?.archivedBucket===!0||V?.hardDelete===!0,Z=O(E(X.id),te).map(eS);if(!t.showDeletionDialog||V?.skipConfirm===!0){B(X,V,{descendantIds:Z});return}t.setDeleteSessionConfirm({session:X,descendantCount:Z.length,descendantIds:Z,archivedBucket:te})},e[27]=t,e[28]=E,e[29]=B,e[30]=z):z=e[30];const T=z;let I;e[31]!==t||e[32]!==B?(I=async()=>{if(!t.deleteSessionConfirm)return;const{session:X,archivedBucket:V,descendantIds:te}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await B(X,{archivedBucket:V},{descendantIds:te})},e[31]=t,e[32]=B,e[33]=I):I=e[33];const R=I;let L;e[34]!==t||e[35]!==n?(L=async X=>{await t.unarchiveSession(X.id)?fe.success(n("sessions.sidebar.session.restore.success")):fe.error(n("sessions.sidebar.session.restore.error"))},e[34]=t,e[35]=n,e[36]=L):L=e[36];const P=L;let G;return e[37]!==R||e[38]!==r||e[39]!==S||e[40]!==v||e[41]!==w||e[42]!==T||e[43]!==P||e[44]!==x||e[45]!==f||e[46]!==u||e[47]!==C||e[48]!==F?(G={copiedSessionId:r,handleSessionSelect:u,handleSessionDoubleClick:f,handleSaveEdit:x,handleCancelEdit:S,handleShareSession:C,handleCopyShareUrl:w,handleCopySessionId:v,handleUnshareSession:F,handleDeleteSession:T,handleRestoreSession:P,confirmDeleteSession:R},e[37]=R,e[38]=r,e[39]=S,e[40]=v,e[41]=w,e[42]=T,e[43]=P,e[44]=x,e[45]=f,e[46]=u,e[47]=C,e[48]=F,e[49]=G):G=e[49],G};function X0(t){return!t.time?.archived}function J0(t,e){return e?t:t.filter(X0)}function Z0(t){return t.id}function eS(t){return t.id}const tS=t=>{const e=ot.c(26),{isVSCode:n,safeStorage:r,keys:o,groupOrderByProject:i,collapsedGroups:c,setExpandedParents:l,setCollapsedProjects:d}=t,u=a.useRef(null),h=a.useRef(null);let f;e[0]!==n?(f=()=>{if(n)return;const D=h.current;if(h.current=null,u.current=null,!D)return;const{projects:F}=ds.getState(),k=F.map(E=>({...E,sidebarCollapsed:D.has(E.id)}));Ol({projects:k}).catch(sS)},e[0]=n,e[1]=f):f=e[1];const p=f;let x;e[2]!==p||e[3]!==n?(x=D=>{typeof window>"u"||n||(h.current=D,u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{p()},700))},e[2]=p,e[3]=n,e[4]=x):x=e[4];const b=x;let S,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>{typeof window<"u"&&u.current!==null&&window.clearTimeout(u.current),u.current=null,h.current=null},g=[],e[5]=S,e[6]=g):(S=e[5],g=e[6]),a.useEffect(S,g);let m,y;e[7]!==o.projectCollapse||e[8]!==o.sessionExpanded||e[9]!==r||e[10]!==d||e[11]!==l?(m=()=>{try{const D=r.getItem(o.sessionExpanded);if(D){const k=JSON.parse(D);Array.isArray(k)&&l(new Set(k.filter(nS)))}const F=r.getItem(o.projectCollapse);if(F){const k=JSON.parse(F);Array.isArray(k)&&d(new Set(k.filter(rS)))}}catch{}},y=[o.projectCollapse,o.sessionExpanded,r,d,l],e[7]=o.projectCollapse,e[8]=o.sessionExpanded,e[9]=r,e[10]=d,e[11]=l,e[12]=m,e[13]=y):(m=e[12],y=e[13]),a.useEffect(m,y);let C,j;e[14]!==i||e[15]!==o.groupOrder||e[16]!==r?(C=()=>{try{const D=Object.fromEntries(i.entries());r.setItem(o.groupOrder,JSON.stringify(D))}catch{}},j=[i,o.groupOrder,r],e[14]=i,e[15]=o.groupOrder,e[16]=r,e[17]=C,e[18]=j):(C=e[17],j=e[18]),a.useEffect(C,j);let w,N;e[19]!==c||e[20]!==o.groupCollapse||e[21]!==r?(w=()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(c)))}catch{}},N=[c,o.groupCollapse,r],e[19]=c,e[20]=o.groupCollapse,e[21]=r,e[22]=w,e[23]=N):(w=e[22],N=e[23]),a.useEffect(w,N);let v;return e[24]!==b?(v={scheduleCollapsedProjectsPersist:b},e[24]=b,e[25]=v):v=e[25],v};function sS(){}function nS(t){return typeof t=="string"}function rS(t){return typeof t=="string"}const oS=5*6e4,iS=t=>{const e=ot.c(31),{normalizedProjects:n,enabled:r,gitRepoStatus:o,setProjectRepoStatus:i,setProjectRootBranches:c}=t,l=r===void 0?!0:r,{git:d}=_n(),u=nn(aS);let h,f;e[0]!==l||e[1]!==u||e[2]!==d||e[3]!==n||e[4]!==i?(h=()=>{if(!l||!d||n.length===0){i(new Map);return}n.forEach(N=>{hl(()=>u(N.normalizedPath,d))})},f=[l,n,d,u,i],e[0]=l,e[1]=u,e[2]=d,e[3]=n,e[4]=i,e[5]=h,e[6]=f):(h=e[5],f=e[6]),a.useEffect(h,f);let p,x;e[7]!==l||e[8]!==o||e[9]!==n||e[10]!==i?(p=()=>{if(!l)return;const N=new Map;n.forEach(v=>{N.set(v.id,o.get(v.normalizedPath)?.isGitRepo??null)}),i(N)},x=[l,n,o,i],e[7]=l,e[8]=o,e[9]=n,e[10]=i,e[11]=p,e[12]=x):(p=e[11],x=e[12]),a.useEffect(p,x);let b;if(e[13]!==o||e[14]!==n){let N;e[16]!==o?(N=v=>{const D=o.get(v.normalizedPath)?.branch??"";return`${v.id}:${D}`},e[16]=o,e[17]=N):N=e[17],b=n.map(N).join("|"),e[13]=o,e[14]=n,e[15]=b}else b=e[15];const S=b;let g;e[18]===Symbol.for("react.memo_cache_sentinel")?(g=new Map,e[18]=g):g=e[18];const m=a.useRef(g);let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=new Map,e[19]=y):y=e[19];const C=a.useRef(y);let j;e[20]!==l||e[21]!==o||e[22]!==n||e[23]!==c?(j=()=>{if(!l)return;let N=!1;const v=setTimeout(()=>{(async()=>{const F=new Set(n.map(lS));for(const z of m.current.keys())F.has(z)||(m.current.delete(z),C.current.delete(z));const k=Date.now(),E=n.filter(z=>{const T=o.get(z.normalizedPath);if(T?.isGitRepo===!1)return m.current.delete(z.id),C.current.delete(z.id),!1;if(T?.isGitRepo!==!0||T.branch===null)return!1;const I=T.branch.trim(),R=`${z.normalizedPath}\0${I}`,L=m.current.get(z.id);if(L===R){const P=C.current.get(z.id);return P&&(P.at=k),!1}return!(L!==void 0&&k-(C.current.get(z.id)?.at??0)<oS)});if(E.length===0)return;const O=await Kp(E,2,async z=>{const T=o.get(z.normalizedPath)?.branch?.trim()??"",I=`${z.normalizedPath}\0${T}`,R=await hl(()=>gi(z.normalizedPath,T?{knownBranch:T}:void 0)).catch(cS);return{id:z.id,inputKey:I,branch:R}});if(N)return;const M=O.filter(dS);if(M.length===0)return;const B=Date.now();c(z=>{const T=new Map(z);return M.forEach(I=>{const{id:R,branch:L}=I;L&&T.set(R,L)}),T}),M.forEach(z=>{const{id:T,inputKey:I,branch:R}=z;m.current.set(T,I),R&&C.current.set(T,{branch:R,at:B})})})()},150);return()=>{N=!0,clearTimeout(v)}},e[20]=l,e[21]=o,e[22]=n,e[23]=c,e[24]=j):j=e[24];let w;e[25]!==l||e[26]!==o||e[27]!==n||e[28]!==S||e[29]!==c?(w=[l,n,S,o,c],e[25]=l,e[26]=o,e[27]=n,e[28]=S,e[29]=c,e[30]=w):w=e[30],a.useEffect(j,w)};function aS(t){return t.ensureStatus}function lS(t){return t.id}function cS(){return null}function dS(t){return t.branch}const uS=t=>{const e=ot.c(7),{ownership:n}=t;let r;e[0]!==n?(r=d=>n.sessionsByProject.get(d)??[],e[0]=n,e[1]=r):r=e[1];const o=r;let i;e[2]!==n?(i=d=>n.archivedSessionsByProject.get(d)??[],e[2]=n,e[3]=i):i=e[3];const c=i;let l;return e[4]!==c||e[5]!==o?(l={getSessionsForProject:o,getArchivedSessionsForProject:c},e[4]=c,e[5]=o,e[6]=l):l=e[6],l},fS=t=>{const e=new Map;for(const n of t){const r=Bn(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},mS=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,o)=>{e.has(o)||n.push(r)}),n},hS=t=>{const e=ot.c(5),{enabled:n,hasAuthoritativeGlobalSessions:r,sessions:o}=t,i=n===void 0?!0:n,c=a.useRef(null);let l,d;e[0]!==i||e[1]!==r||e[2]!==o?(l=()=>{if(!i||!r)return;const u=$n(),h=fS(o),f=c.current?.runtimeKey===u?c.current.identities:null;for(const p of mS(f,h))Gp({runtimeKey:u,...p});c.current={runtimeKey:u,identities:h}},d=[i,r,o],e[0]=i,e[1]=r,e[2]=o,e[3]=l,e[4]=d):(l=e[3],d=e[4]),a.useEffect(l,d)},pS=(t,e)=>t?e.kind!==t.kind?e.kind==="project":e.projectRoot.length!==t.projectRoot.length?e.projectRoot.length>t.projectRoot.length:e.projectId.localeCompare(t.projectId)<0:!0,eu=(t,e,n)=>{pS(t.get(e),n)&&t.set(e,n)},gS=t=>{const e=t;return _t(e.directory)??_t(e.project?.worktree)},xS=t=>{if(t==="/"||/^[A-Z]:$/.test(t))return null;const e=t.lastIndexOf("/");return e<0?null:e===0?"/":e===2&&/^[A-Z]:\//.test(t)?t.slice(0,2):t.slice(0,e)},bS=(t,e,n,r,o=[])=>{const i=new Map,c=new Map;for(const b of e){const S=_t(b.normalizedPath);if(!S)continue;const g=c.get(S);(!g||b.id.localeCompare(g.id)<0)&&c.set(S,b),eu(i,S,{projectId:b.id,projectRoot:S,scopeDirectory:S,kind:"project"})}if(!r)for(const[b,S]of n){const g=_t(b),m=g?c.get(g):void 0;if(!(!m||!g))for(const y of S){const C=_t(y.path);C&&eu(i,C,{projectId:m.id,projectRoot:g,scopeDirectory:C,kind:"worktree"})}}const l=new Map,d=new Map,u=new Map,h=new Map,f=new Map,p=b=>{if(!b)return null;if(l.has(b))return l.get(b)??null;if(r){const y=i.get(b)??null;return l.set(b,y),y}const S=[];let g=b,m=null;for(;g;){if(l.has(g)){m=l.get(g)??null;break}if(S.push(g),m=i.get(g)??null,m)break;g=xS(g)}for(const y of S)l.set(y,m);return m},x=(b,S,g)=>{for(const m of b){const y=p(gS(m));if(!y)continue;d.set(m.id,y);const C=S.get(y.projectId);if(C?C.push(m):S.set(y.projectId,[m]),!g)continue;const j=g.get(y.scopeDirectory);j?j.add(m.id):g.set(y.scopeDirectory,new Set([m.id]))}};return x(t,u,f),x(o,h),{bySessionId:d,sessionsByProject:u,archivedSessionsByProject:h,sessionsByScope:f,directoryResolutions:l.size}},yS=t=>{const e=ot.c(10),{enabled:n,isDesktopShellRuntime:r,projectSections:o,projectHeaderSentinelRefs:i}=t,c=n===void 0?!0:n;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=new Set,e[0]=l):l=e[0];const[d,u]=a.useState(l);let h;e[1]!==c||e[2]!==r||e[3]!==i?(h=()=>{if(!c||!r){u(wS);return}const x=Array.from(i.current.values()).find(vS)?.closest(".oc-sidebar-scroller")??null;if(!x)return;const b=new IntersectionObserver(S=>{u(g=>{const m=new Set(g);let y=!1;for(const C of S){const j=C.target.dataset.projectId;if(!j)continue;const w=C.rootBounds?.top??x.getBoundingClientRect().top,N=!C.isIntersecting&&C.boundingClientRect.top<w;m.has(j)!==N&&(y=!0,N?m.add(j):m.delete(j))}return y?m:g})},{root:x,threshold:0});return i.current.forEach(S=>{S&&b.observe(S)}),()=>b.disconnect()},e[1]=c,e[2]=r,e[3]=i,e[4]=h):h=e[4];let f;return e[5]!==c||e[6]!==r||e[7]!==i||e[8]!==o?(f=[c,r,i,o],e[5]=c,e[6]=r,e[7]=i,e[8]=o,e[9]=f):f=e[9],a.useEffect(h,f),d};function wS(t){return t.size===0?t:new Set}function vS(t){return t!==null}const jS=t=>{const e=ot.c(10),{open:n,onOpenChange:r,project:o,onSave:i}=t;let c;e[0]!==i||e[1]!==n||e[2]!==o?(c=n&&o?s.jsx(jx,{project:o,onIdentitySave:i,showWorktrees:!1}):null,e[0]=i,e[1]=n,e[2]=o,e[3]=c):c=e[3];let l;e[4]!==c?(l=s.jsx(Is,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(On,{outerClassName:"max-h-[min(90vh,48rem)]",className:"w-full bg-background",children:s.jsx("div",{className:"w-full p-3 sm:p-6 sm:pt-8",children:c})})}),e[4]=c,e[5]=l):l=e[5];let d;return e[6]!==r||e[7]!==n||e[8]!==l?(d=s.jsx(Ps,{open:n,onOpenChange:r,children:l}),e[6]=r,e[7]=n,e[8]=l,e[9]=d):d=e[9],d};function Om(t){const e=ot.c(10),{state:n,activeLabel:r,unreadLabel:o,className:i}=t,c=n==="active"?r:o;if(n==="active"){let u;e[0]!==i?(u=Pe("h-3 w-3 shrink-0 animate-spin text-primary",i),e[0]=i,e[1]=u):u=e[1];let h;return e[2]!==c||e[3]!==u?(h=s.jsx(A,{name:"loader-4",className:u,"aria-label":c}),e[2]=c,e[3]=u,e[4]=h):h=e[4],h}let l;e[5]!==i?(l=Pe("h-1.5 w-1.5 shrink-0 rounded-full","bg-[var(--status-info)]",i),e[5]=i,e[6]=l):l=e[6];let d;return e[7]!==c||e[8]!==l?(d=s.jsx("span",{className:l,"aria-label":c,title:c}),e[7]=c,e[8]=l,e[9]=d):d=e[9],d}const SS=t=>{const e=ot.c(86),{folder:n,displayName:r,sessions:o,subFolderItems:i,isCollapsed:c,collapsedActivityState:l,onToggle:d,onRename:u,onDelete:h,renderSessionNode:f,getRenderExtras:p,groupDirectory:x,projectId:b,mobileVariant:S,alwaysShowActions:g,isRenaming:m,renameDraft:y,onRenameDraftChange:C,onRenameSave:j,onRenameCancel:w,droppableRef:N,isDropTarget:v,onNewSession:D,depth:F,hideActions:k,archivedBucket:E}=t,O=l===void 0?null:l,B=g===void 0?S===void 0?!1:S:g,z=m===void 0?!1:m,T=y===void 0?"":y,I=v===void 0?!1:v,R=k===void 0?!1:k,L=E===void 0?!1:E,{t:P}=ft(),[G,X]=a.useState(!1),[V,te]=a.useState(""),Z=a.useRef(null),de=z||G,Fe=z?T:V;let se;e[0]!==n.name?(se=()=>{te(n.name),X(!0)},e[0]=n.name,e[1]=se):se=e[1];const Q=se;let Me;e[2]!==Fe||e[3]!==n.name||e[4]!==z||e[5]!==u||e[6]!==j?(Me=()=>{const me=Fe.trim();me&&me!==n.name&&u(me),z&&j&&j(),X(!1),te("")},e[2]=Fe,e[3]=n.name,e[4]=z,e[5]=u,e[6]=j,e[7]=Me):Me=e[7];const xe=Me;let W;e[8]!==z||e[9]!==w?(W=()=>{z&&w&&w(),X(!1),te("")},e[8]=z,e[9]=w,e[10]=W):W=e[10];const J=W;let ne;e[11]!==z||e[12]!==C?(ne=me=>{z&&C?C(me):te(me)},e[11]=z,e[12]=C,e[13]=ne):ne=e[13];const oe=ne;let ue,Ae;e[14]!==z?(ue=()=>{if(!z)return;const me=()=>{const ge=Z.current;ge&&(ge.focus(),ge.select())},$=requestAnimationFrame(me),_=window.setTimeout(me,0);return()=>{cancelAnimationFrame($),window.clearTimeout(_)}},Ae=[z],e[14]=z,e[15]=ue,e[16]=Ae):(ue=e[15],Ae=e[16]),a.useEffect(ue,Ae);const we=c?"folder":"folder-open",Se=I&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let Le;e[17]!==Se?(Le=Pe("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Se),e[17]=Se,e[18]=Le):Le=e[18];let Ue;e[19]!==d||e[20]!==de?(Ue=de?void 0:me=>{me.currentTarget.blur(),d()},e[19]=d,e[20]=de,e[21]=Ue):Ue=e[21];const be=de?void 0:"button",q=de?void 0:0;let Ne;e[22]!==d||e[23]!==de?(Ne=de?void 0:me=>{(me.key==="Enter"||me.key===" ")&&(me.preventDefault(),d())},e[22]=d,e[23]=de,e[24]=Ne):Ne=e[24];let je;e[25]!==n.name||e[26]!==c||e[27]!==P?(je=c?P("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):P("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=c,e[27]=P,e[28]=je):je=e[28];const ve=L?B?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":B?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20";let ie;e[29]!==ve?(ie=Pe("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ve),e[29]=ve,e[30]=ie):ie=e[30];const ee=I?"text-primary":"text-muted-foreground";let ke;e[31]!==ee?(ke=Pe("h-3.5 w-3.5 flex-shrink-0",ee),e[31]=ee,e[32]=ke):ke=e[32];let ae;e[33]!==we||e[34]!==ke?(ae=s.jsx(A,{name:we,className:ke}),e[33]=we,e[34]=ke,e[35]=ae):ae=e[35];let U;e[36]!==O||e[37]!==r||e[38]!==Fe||e[39]!==n.name||e[40]!==J||e[41]!==oe||e[42]!==xe||e[43]!==c||e[44]!==I||e[45]!==de||e[46]!==o||e[47]!==P?(U=de?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:NS,onMouseDown:CS,onSubmit:me=>{me.preventDefault(),xe()},children:[s.jsx("input",{ref:Z,value:Fe,onChange:me=>oe(me.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:P("sessions.sidebar.folderItem.namePlaceholder"),onClick:AS,onPointerDown:DS,onMouseDown:PS,onKeyDown:me=>{if(me.key==="Escape"){me.stopPropagation(),J();return}(me.key===" "||me.key==="Enter")&&me.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:IS,onPointerDown:RS,onMouseDown:MS,children:s.jsx(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),J()},onPointerDown:TS,onMouseDown:ES,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:Pe("typography-ui-label font-semibold truncate",I?"text-primary":"text-muted-foreground"),children:r??n.name})}),s.jsx(Nt,{side:"right",sideOffset:8,className:"max-w-xs",children:r??n.name})]}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",o.length]}),O?s.jsx(Om,{state:O,activeLabel:P("sessions.sidebar.session.status.active"),unreadLabel:P("sessions.sidebar.session.status.unread")}):null,c?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[36]=O,e[37]=r,e[38]=Fe,e[39]=n.name,e[40]=J,e[41]=oe,e[42]=xe,e[43]=c,e[44]=I,e[45]=de,e[46]=o,e[47]=P,e[48]=U):U=e[48];let le;e[49]!==ie||e[50]!==ae||e[51]!==U?(le=s.jsxs("div",{className:ie,children:[ae,U]}),e[49]=ie,e[50]=ae,e[51]=U,e[52]=le):le=e[52];let _e;e[53]!==B||e[54]!==L||e[55]!==n.name||e[56]!==Q||e[57]!==R||e[58]!==h||e[59]!==D||e[60]!==de||e[61]!==P?(_e=!de&&(!R||L)?s.jsx("div",{className:Pe("absolute right-0.5 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",B?"opacity-100":"opacity-0 pointer-events-none group-hover/folder:opacity-100 group-hover/folder:pointer-events-auto group-focus-within/folder:opacity-100 group-focus-within/folder:pointer-events-auto"),children:s.jsxs("div",{className:"flex items-center gap-0.5",children:[!L&&D?s.jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),D()},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":P("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:P("sessions.sidebar.project.actions.newSession"),children:s.jsx(A,{name:"add",className:"h-3.5 w-3.5"})}):null,L?null:s.jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),Q()},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":P("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(A,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:me=>{me.stopPropagation(),h()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":L?P("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):P("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=B,e[54]=L,e[55]=n.name,e[56]=Q,e[57]=R,e[58]=h,e[59]=D,e[60]=de,e[61]=P,e[62]=_e):_e=e[62];let De;e[63]!==N||e[64]!==Le||e[65]!==Ue||e[66]!==be||e[67]!==q||e[68]!==Ne||e[69]!==je||e[70]!==le||e[71]!==_e?(De=s.jsxs("div",{ref:N,className:Le,onClick:Ue,role:be,tabIndex:q,onKeyDown:Ne,"aria-label":je,children:[le,_e]}),e[63]=N,e[64]=Le,e[65]=Ue,e[66]=be,e[67]=q,e[68]=Ne,e[69]=je,e[70]=le,e[71]=_e,e[72]=De):De=e[72];let ce;e[73]!==L||e[74]!==p||e[75]!==x||e[76]!==c||e[77]!==b||e[78]!==f||e[79]!==o||e[80]!==i||e[81]!==P?(ce=c?null:s.jsxs("div",{className:"pb-1",children:[i,o.length>0?o.map(me=>f(me,0,x??null,b??null,L,void 0,"project",p?.(me))):i?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:P("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=L,e[74]=p,e[75]=x,e[76]=c,e[77]=b,e[78]=f,e[79]=o,e[80]=i,e[81]=P,e[82]=ce):ce=e[82];let he;return e[83]!==De||e[84]!==ce?(he=s.jsxs("div",{className:"oc-folder",children:[De,ce]}),e[83]=De,e[84]=ce,e[85]=he):he=e[85],he},kS=a.memo(SS);function NS(t){return t.stopPropagation()}function CS(t){return t.stopPropagation()}function AS(t){return t.stopPropagation()}function DS(t){return t.stopPropagation()}function PS(t){return t.stopPropagation()}function IS(t){return t.stopPropagation()}function RS(t){return t.stopPropagation()}function MS(t){return t.stopPropagation()}function TS(t){return t.stopPropagation()}function ES(t){return t.stopPropagation()}const FS=t=>{const e=ot.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:i}=t,c=`session-drag:${n}`;let l;e[0]!==r||e[1]!==n||e[2]!==o?(l={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=l):l=e[3];let d;e[4]!==c||e[5]!==l?(d={id:c,data:l},e[4]=c,e[5]=l,e[6]=d):d=e[6];const{attributes:u,listeners:h,setNodeRef:f,isDragging:p}=Zx(d);let x;e[7]!==h?(x=m=>{m.stopPropagation(),h?.onPointerDown&&h.onPointerDown(m)},e[7]=h,e[8]=x):x=e[8];const b=x,S=p?"opacity-30":void 0;let g;return e[9]!==u||e[10]!==i||e[11]!==b||e[12]!==f||e[13]!==S?(g=s.jsx("div",{ref:f,...u,onPointerDown:b,className:S,children:i}),e[9]=u,e[10]=i,e[11]=b,e[12]=f,e[13]=S,e[14]=g):g=e[14],g},OS=t=>{const e=ot.c(11),{folderId:n,children:r}=t,o=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let c;e[2]!==o||e[3]!==i?(c={id:o,data:i},e[2]=o,e[3]=i,e[4]=c):c=e[4];const{setNodeRef:l,isOver:d}=Jx(c);let u;e[5]!==r||e[6]!==d||e[7]!==l?(u=r(l,d),e[5]=r,e[6]=d,e[7]=l,e[8]=u):u=e[8];let h;return e[9]!==u?(h=s.jsx(s.Fragment,{children:u}),e[9]=u,e[10]=h):h=e[10],h},LS=t=>{const e=ot.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:i}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[0]=c):c=e[0];const l=ra(Do(yl,c)),[d,u]=a.useState(null),[h,f]=a.useState("Session"),[p,x]=a.useState(null),[b,S]=a.useState(null);if(!n){let v;return e[1]!==i?(v=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=v):v=e[2],v}let g;e[3]!==o?(g=v=>{u(null),x(null),S(null);const{active:D,over:F}=v;if(!F)return;const k=D.data.current,E=F.data.current;k?.type==="session"&&k.sessionId&&E?.type==="folder"&&E.folderId&&o(k.sessionId,E.folderId)},e[3]=o,e[4]=g):g=e[4];const m=g;let y,C;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=v=>{const D=v.active.data.current;if(D?.type==="session"&&D.sessionId){u(D.sessionId),f(D.sessionTitle??"Session");const F=v.active.rect.current.initial?.width,k=v.active.rect.current.initial?.height;x(typeof F=="number"?F:null),S(typeof k=="number"?k:null)}},C=()=>{u(null),x(null),S(null)},e[5]=y,e[6]=C):(y=e[5],C=e[6]);let j;e[7]!==b||e[8]!==d||e[9]!==h||e[10]!==p||e[11]!==r?(j=d&&r?s.jsxs("div",{style:{width:p?`${p}px`:"auto",height:b?`${b}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(A,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:h})]}):null,e[7]=b,e[8]=d,e[9]=h,e[10]=p,e[11]=r,e[12]=j):j=e[12];let w;e[13]!==j?(w=s.jsx(wl,{children:j}),e[13]=j,e[14]=w):w=e[14];let N;return e[15]!==i||e[16]!==m||e[17]!==l||e[18]!==w?(N=s.jsxs(oa,{sensors:l,collisionDetection:ia,onDragStart:y,onDragCancel:C,onDragEnd:m,children:[i,w]}),e[15]=i,e[16]=m,e[17]=l,e[18]=w,e[19]=N):N=e[19],N},Pl=(t,e,n)=>{if(!e)return;const r=o=>{let i=o.session.id===e;for(const c of o.children)i=r(c)||i;return i&&n.add(o.session.id),i};for(const o of t)r(o)},jr=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(jr(n,e))return!0;return!1},BS=(t,e)=>{const n=new Set(t);return t.map(r=>e.get(r)).filter(r=>{if(!r)return!1;const o=new Set;let i=r.session.parentID??null;for(;i&&!o.has(i);){if(n.has(i)&&e.has(i))return!1;o.add(i),i=e.get(i)?.session?.parentID??null}return!0})},tu=new WeakMap;let su=1;const $S=t=>{const e=tu.get(t);if(e!==void 0)return e;const n=su;return su+=1,tu.set(t,n),n},ca=t=>t.children.length===0?"":t.children.map(n=>{const r=$S(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${ca(n)}`}).join("|"),Lm=(t,e,n,r,o,i)=>{const c=$n(),l=(d,u)=>{if(d.session.id!==u.session.id||d.children.length!==u.children.length)return!0;const h=d.session.directory??o,f=u.session.directory??i,p=Lc(c,h??"",d.session.id),x=Lc(c,f??"",u.session.id);return(p?n.has(p):!1)!==(x?r.has(x):!1)?!0:d.children.some((b,S)=>l(b,u.children[S]))};return l(t,e)},mi=(t,e,n,r)=>{if(!e)return null;const o=r?"archived":"active";let i=null;const c=l=>{if(`${n}:${o}:${l.session.id}`===e)return i=l.session.id,!0;for(const u of l.children)if(c(u))return!0;return!1};return t.forEach(l=>c(l)),i},gc=(t,e)=>t==="active"||e==="active"?"active":t==="unread"||e==="unread"?"unread":null,Bm=(t,e,n,r)=>{if(e.has(t.session.id))return"active";let o=null;const i=!!t.session.parentID;n.has(t.session.id)&&(r||!i)&&(o="unread");for(const c of t.children)if(o=gc(o,Bm(c,e,n,r)),o==="active")return o;return o},nu=(t,e,n,r)=>{let o=null;for(const i of t)if(o=gc(o,Bm(i,e,n,r)),o==="active")return o;return o},_S=50,zS=28,Ii=(t,e)=>e?t.sessions.some(n=>jr(n,e)):!1,VS=(t,e,n)=>t.sessions.some(r=>Lm(r,r,e,n,t.directory,t.directory)),WS=(t,e,n)=>{const r=o=>{const i=o.session.id;return e.get(i)!==n.get(i)?!0:o.children.some(r)};return t.sessions.some(r)},ru=(t,e,n)=>{const r=o=>e.has(o.session.id)!==n.has(o.session.id)?!0:o.children.some(r);return t.sessions.some(r)},US=(t,e)=>{const n=r=>e.has(r.session.id)?!0:r.children.some(n);return t.sessions.some(n)},HS=(t,e,n)=>{const r=t.isArchivedBucket?"archived":"active",o=i=>{const c=`project:${r}:${i.session.id}`;return e.has(c)!==n.has(c)?!0:i.children.some(o)};return t.sessions.some(o)},KS=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.pinnedSessionIds!==e.pinnedSessionIds&&VS(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.expandedParents!==e.expandedParents&&HS(e.group,t.expandedParents,e.expandedParents)||t.sessionOrderIndex!==e.sessionOrderIndex&&WS(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.editingId!==e.editingId&&(Ii(t.group,t.editingId)||Ii(e.group,e.editingId))||t.editTitle!==e.editTitle&&(Ii(t.group,t.editingId)||Ii(e.group,e.editingId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=mi(t.group.sessions,t.openSidebarMenuKey,"project",!!t.group.isArchivedBucket),r=mi(e.group.sessions,e.openSidebarMenuKey,"project",!!e.group.isArchivedBucket);if(n||r)return!1}return t.activeActivitySessionIds!==e.activeActivitySessionIds&&ru(e.group,t.activeActivitySessionIds,e.activeActivitySessionIds)||t.unreadActivitySessionIds!==e.unreadActivitySessionIds&&ru(e.group,t.unreadActivitySessionIds,e.unreadActivitySessionIds)||t.notifyOnSubtasks!==e.notifyOnSubtasks&&US(e.group,e.unreadActivitySessionIds)?!1:t.hasSessionSearchQuery===e.hasSessionSearchQuery&&t.normalizedSessionSearchQuery===e.normalizedSessionSearchQuery&&t.hideDirectoryControls===e.hideDirectoryControls&&t.collapsedFolderIds===e.collapsedFolderIds&&t.toggleFolderCollapse===e.toggleFolderCollapse&&t.renameFolder===e.renameFolder&&t.deleteFolder===e.deleteFolder&&t.showDeletionDialog===e.showDeletionDialog&&t.setDeleteFolderConfirm===e.setDeleteFolderConfirm&&t.renderSessionNode===e.renderSessionNode&&t.showMoreGroupSessions===e.showMoreGroupSessions&&t.resetGroupSessionLimit===e.resetGroupSessionLimit&&t.mobileVariant===e.mobileVariant&&t.alwaysShowActions===e.alwaysShowActions&&t.activeProjectId===e.activeProjectId&&t.setActiveProjectIdOnly===e.setActiveProjectIdOnly&&t.setActiveMainTab===e.setActiveMainTab&&t.setSessionSwitcherOpen===e.setSessionSwitcherOpen&&t.openNewSessionDraft===e.openNewSessionDraft&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.renamingFolderId===e.renamingFolderId&&t.renameFolderDraft===e.renameFolderDraft&&t.setRenameFolderDraft===e.setRenameFolderDraft&&t.setRenamingFolderId===e.setRenamingFolderId&&t.onToggleCollapsedGroup===e.onToggleCollapsedGroup&&t.dragHandleProps===e.dragHandleProps&&t.scrollContainerRef===e.scrollContainerRef};function GS(t){const{t:e}=ft(),{group:n,groupKey:r,projectId:o,hideGroupLabel:i,hasSessionSearchQuery:c,normalizedSessionSearchQuery:l,groupSearchDataByGroup:d,visibleSessionCount:u,collapsedGroups:h,hideDirectoryControls:f,collapsedFolderIds:p,toggleFolderCollapse:x,renameFolder:b,deleteFolder:S,showDeletionDialog:g,setDeleteFolderConfirm:m,renderSessionNode:y,showMoreGroupSessions:C,resetGroupSessionLimit:j,mobileVariant:w,alwaysShowActions:N,activeProjectId:v,setActiveProjectIdOnly:D,setActiveMainTab:F,setSessionSwitcherOpen:k,openNewSessionDraft:E,addSessionToFolder:O,createFolderAndStartRename:M,renamingFolderId:B,renameFolderDraft:z,setRenameFolderDraft:T,setRenamingFolderId:I,pinnedSessionIds:R,expandedParents:L,sessionOrderIndex:P,editingId:G,openSidebarMenuKey:X,activeActivitySessionIds:V,unreadActivitySessionIds:te,notifyOnSubtasks:Z,onToggleCollapsedGroup:de,dragHandleProps:Fe,compactBodyPadding:se=!1,scrollContainerRef:Q}=t,Me=a.useCallback((ze,Qe)=>{const st=P.get(ze.session.id),at=P.get(Qe.session.id);if(st!==void 0||at!==void 0){if(st===void 0)return 1;if(at===void 0)return-1;if(st!==at)return st-at}return Eo(ze.session,Qe.session,R,Yl)},[R,P]),xe=c?d.get(n):null,W=kn(ze=>ze.foldersMap),J=c?!1:h.has(r),ne=a.useMemo(()=>{if(n.isMain||n.isArchivedBucket||i)return null;const ze=_t(n.directory??null),Qe=n.branch?.trim();return ze&&Qe?yi(ze,Qe):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,i]),oe=Bf(ne),ue=oe?`var(--pr-${oe.visualState})`:void 0,Ae=gf(),we=_t(n.directory??null),Se=a.useSyncExternalStore(a.useCallback(ze=>we?Ae.subscribeBootstrap(ze):()=>{},[we,Ae]),a.useCallback(()=>we?Ae.getBootstrapState(we):void 0,[we,Ae]),a.useCallback(()=>{},[])),Le=f?10:5,Ue=Math.max(Le,u??Le),be=c?xe?.groupMatches===!0:!1,q=c,Ne=a.useMemo(()=>[...q?xe?.filteredNodes??[]:n.sessions].sort(Me),[Me,n.sessions,xe?.filteredNodes,q]),je=n.folderScopeKey??_t(n.directory??null),ve=a.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:je?[{scopeKey:je,directory:n.directory??null}]:[],[je,n.directory,n.folderScopes]),ie=a.useMemo(()=>ve.flatMap(({scopeKey:ze,directory:Qe})=>(W[ze]??[]).map(st=>({folder:st,scopeKey:ze,scopeDirectory:Qe}))),[ve,W]),ee=a.useMemo(()=>{const ze=new Map,Qe=st=>{st.forEach(at=>{ze.set(at.session.id,at),at.children.length>0&&Qe(at.children)})};return Qe(Ne),ze},[Ne]),ke=a.useMemo(()=>ie.map(({folder:ze,scopeKey:Qe,scopeDirectory:st})=>{const at=BS(ze.sessionIds,ee).sort(Me);return{folder:ze,scopeKey:Qe,scopeDirectory:st,nodes:at}}),[ie,ee,Me]),ae=a.useMemo(()=>{const ze=new Map(ke.map(Ze=>[Ze.folder.id,Ze])),Qe=new Map;for(const{folder:Ze}of ke){if(!Ze.parentId)continue;const At=Qe.get(Ze.parentId);At?At.push(Ze.id):Qe.set(Ze.parentId,[Ze.id])}const st=new Map,at=Ze=>{const At=st.get(Ze);if(At!==void 0)return At;const Rt=ze.get(Ze);if(!Rt)return st.set(Ze,!1),!1;const Zt=Qe.get(Ze)??[];if(n.isArchivedBucket&&Rt.nodes.length===0){const Ot=Zt.some($t=>at($t));return st.set(Ze,Ot),Ot}if(!c||Rt.folder.name.toLowerCase().includes(l)||Rt.nodes.length>0)return st.set(Ze,!0),!0;const ls=Zt.some(Ot=>at(Ot));return st.set(Ze,ls),ls};return ke.filter(({folder:Ze})=>at(Ze.id))},[ke,n.isArchivedBucket,c,l]),U=a.useMemo(()=>new Set(ae.flatMap(ze=>ze.folder.sessionIds)),[ae]),le=a.useMemo(()=>Ne.filter(ze=>!U.has(ze.session.id)),[Ne,U]),_e=a.useMemo(()=>ae.filter(({folder:ze})=>!ze.parentId),[ae]),De=a.useMemo(()=>{const ze=new Map;return ae.forEach(Qe=>{if(!Qe.folder.parentId)return;const st=ze.get(Qe.folder.parentId)??[];st.push(Qe),ze.set(Qe.folder.parentId,st)}),ze},[ae]),ce=a.useMemo(()=>{const ze=new Map(ae.map(at=>[at.folder.id,at])),Qe=new Map,st=(at,Ze)=>{const At=Qe.get(at);if(At!==void 0)return At;if(Ze.has(at))return null;Ze.add(at);const Rt=ze.get(at);let Zt=Rt?nu(Rt.nodes,V,te,Z):null;for(const fs of De.get(at)??[])if(Zt=gc(Zt,st(fs.folder.id,Ze)),Zt==="active")break;return Qe.set(at,Zt),Zt};return ae.forEach(({folder:at})=>st(at.id,new Set)),Qe},[V,ae,De,Z,te]),he="project",me=a.useMemo(()=>{const ze=new Set;return Pl(Ne,G,ze),ae.forEach(({nodes:Qe})=>{Pl(Qe,G,ze)}),ze},[Ne,ae,G]),$=a.useMemo(()=>{if(!X)return null;const ze=mi(Ne,X,he,!!n.isArchivedBucket);if(ze)return ze;for(const{nodes:Qe}of ae){const st=mi(Qe,X,he,!!n.isArchivedBucket);if(st)return st}return null},[X,Ne,ae,n.isArchivedBucket]),_=a.useCallback(ze=>{const Qe=new WeakMap,st=at=>{Qe.set(at,ca(at));for(const Ze of at.children)st(Ze)};return ze.forEach(st),Qe},[]),ge=a.useMemo(()=>_(Ne),[_,Ne]),Ie=a.useMemo(()=>{const ze=new WeakMap;return ae.forEach(({nodes:Qe})=>{Qe.forEach(st=>ze.set(st,ca(st)))}),ze},[ae]),Re=a.useCallback(ze=>ge.get(ze)??Ie.get(ze)??"",[ge,Ie]),Ke=a.useCallback(ze=>({subtreeContainsEditing:me,menuOpenSessionId:$,nodeStructureKey:Re(ze)}),[me,$,Re]),nt=le.length,ct=n.isArchivedBucket||c?le:le.slice(0,Ue),mt=nt-ct.length,gt=!n.isArchivedBucket&&!c&&nt>Le&&mt===0,ht=n.isArchivedBucket===!0&&!c&&ct.length>=_S,wt=n.isArchivedBucket?"archived":"active",bt=ht&&ct.some(ze=>{if(ze.children.length===0)return!1;const Qe=`project:${wt}:${ze.session.id}`;return L.has(Qe)}),yt=a.useRef(null),[Dt,Kt]=a.useState(null),[Ut,Lt]=a.useState(0),[,Bt]=a.useState(0);a.useEffect(()=>{if(!ht)return;const ze=yt.current;if(!ze||typeof ResizeObserver>"u")return;const Qe=new ResizeObserver(()=>Bt(st=>st+1));return Qe.observe(ze),()=>Qe.disconnect()},[ht]),a.useLayoutEffect(()=>{if(!ht){Dt!==null&&Kt(null),Ut!==0&&Lt(0);return}const ze=yt.current;if(!ze)return;let Qe=Dt;const st=Q?.current??null;if(st&&st.contains(ze)){if(Qe=st,Qe!==Dt){Kt(Qe);return}}else if(!Qe||!Qe.contains(ze)){let Ze=ze.parentElement;for(;Ze;){const At=window.getComputedStyle(Ze);if(At.overflowY==="auto"||At.overflowY==="scroll"){Qe=Ze;break}Ze=Ze.parentElement}if(Qe!==Dt){Kt(Qe);return}}if(!Qe)return;const at=ze.getBoundingClientRect().top-Qe.getBoundingClientRect().top+Qe.scrollTop;Lt(Ze=>Math.abs(Ze-at)<1?Ze:at)});const et=ht&&Dt!==null,Ht=sb({count:ct.length,enabled:et,getScrollElement:()=>Dt,initialOffset:()=>Dt?.scrollTop??0,estimateSize:()=>zS,overscan:bt?20:8,scrollMargin:Ut,getItemKey:ze=>ct[ze]?.session.id??ze}),It=a.useCallback(ze=>{const Qe=[],st=at=>{at.forEach(Ze=>{Qe.push(Ze.session),Ze.children.length>0&&st(Ze.children)})};return st(ze),Qe},[]),We=a.useMemo(()=>It(Ne),[It,Ne]),pt=a.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const ze=new Map,Qe=new Map;for(const{folder:at}of ae){if(!at.parentId)continue;const Ze=Qe.get(at.parentId)??[];Ze.push(at.id),Qe.set(at.parentId,Ze)}const st=(at,Ze)=>{if(Ze.has(at))return[];Ze.add(at);const At=ae.find(({folder:fs})=>fs.id===at),Rt=At?It(At.nodes):[],Zt=Qe.get(at)??[];for(const fs of Zt)Rt.push(...st(fs,Ze));return Rt};for(const{folder:at}of ae)ze.set(at.id,st(at.id,new Set));return ze},[ae,It,n.isArchivedBucket]);if(c&&!be&&_e.length===0&&le.length===0)return null;const Mt=!n.isMain&&!!n.branch,Et=n.branch&&qp(n.branch,n.label)?{label:n.branch}:null,tt=J?nu(Ne,V,te,Z):null,pe=tt?s.jsx(Om,{state:tt,activeLabel:e("sessions.sidebar.session.status.active"),unreadLabel:e("sessions.sidebar.session.status.unread")}):null,Oe=(ze,Qe)=>{const{folder:st,scopeKey:at,scopeDirectory:Ze,nodes:At}=ze,Rt=pt.get(st.id)??[],Zt=c?!1:p.has(st.id);return s.jsx(OS,{folderId:st.id,children:(fs,ls)=>s.jsx(kS,{folder:st,displayName:Qe,sessions:At,isCollapsed:Zt,collapsedActivityState:Zt?ce.get(st.id)??null:null,onToggle:()=>x(st.id),onRename:Ot=>{b(at,st.id,Ot)},onDelete:()=>{if(n.isArchivedBucket){Gn.requestDelete({sessions:Rt,mode:"session"});return}if(!g){S(at,st.id);return}const Ot=ae.filter(({folder:Pt})=>Pt.parentId===st.id).length,$t=At.length;m({scopeKey:at,folderId:st.id,folderName:st.name,subFolderCount:Ot,sessionCount:$t})},renderSessionNode:y,getRenderExtras:Re?Ot=>({subtreeContainsEditing:me,menuOpenSessionId:$,nodeStructureKey:Re(Ot),childRenderExtrasFor:Ke}):void 0,groupDirectory:Ze??n.directory,projectId:o,mobileVariant:w,alwaysShowActions:N,isRenaming:B===st.id,renameDraft:B===st.id?z:void 0,onRenameDraftChange:Ot=>T(Ot),onRenameSave:()=>{const Ot=z.trim();Ot&&b(at,st.id,Ot),I(null),T("")},onRenameCancel:()=>{I(null),T("")},droppableRef:fs,isDropTarget:ls,depth:0,onNewSession:()=>{o&&o!==v&&D(o),F("chat"),w&&k(!1),E({selectedProjectId:o,directoryOverride:Ze??n.directory,targetFolderId:st.id})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},st.id)},Te=()=>{const ze=new Map;for(const at of ae){const Ze=at.folder.parentId;if(!Ze)continue;const At=ze.get(Ze);At?At.push(at):ze.set(Ze,[at])}const Qe=[],st=(at,Ze)=>{const At=Ze?`${Ze} / ${at.folder.name}`:at.folder.name;Qe.push(Oe(at,At)),!(!c&&p.has(at.folder.id))&&(ze.get(at.folder.id)??[]).forEach(Zt=>st(Zt,At))};return _e.forEach(at=>st(at,"")),Qe},it=!!(!n.isMain&&n.worktree),ut=N?it?"pr-14":"pr-7":it?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2 group-hover/gh:pr-7 group-focus-within/gh:pr-7",Gt=s.jsxs(LS,{scopeKey:ve[0]?.scopeKey??je,hasFolders:ae.length>0,onSessionDroppedOnFolder:(ze,Qe)=>{const st=ae.find(({folder:Ze})=>Ze.id===Qe);if(!st)return;const at=kn.getState();for(const{scopeKey:Ze}of ve)Ze!==st.scopeKey&&at.getSessionFolderId(Ze,ze)&&at.removeSessionFromFolder(Ze,ze);O(st.scopeKey,Qe,ze)},children:[Te(),ht?s.jsx("div",{ref:yt,children:et?s.jsx("div",{style:{height:Ht.getTotalSize(),position:"relative"},children:Ht.getVirtualItems().map(ze=>{const Qe=ct[ze.index];return Qe?s.jsx("div",{"data-index":ze.index,ref:Ht.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${ze.start-Ut}px)`},children:y(Qe,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:me,menuOpenSessionId:$,nodeStructureKey:Re(Qe),childRenderExtrasFor:Ke})},Qe.session.id):null})}):ct.map(ze=>y(ze,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:me,menuOpenSessionId:$,nodeStructureKey:Re(ze),childRenderExtrasFor:Ke}))}):ct.map(ze=>y(ze,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:me,menuOpenSessionId:$,nodeStructureKey:Re(ze),childRenderExtrasFor:Ke})),nt===0&&ae.length===0?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):Se==="queued"||Se==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(A,{name:"loader-4",className:"size-3 animate-spin"}),e("sessions.sidebar.group.empty.loadingSessions")]}):Se==="failed"&&we?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e("sessions.sidebar.group.empty.loadFailed"),s.jsx("button",{type:"button",className:"text-foreground hover:underline",onClick:()=>Ae.requestBootstrap({directory:we,priority:J?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0}),children:e("sessions.sidebar.group.empty.retry")})]}):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,mt>0?s.jsx("button",{type:"button",onClick:()=>C(r,ct.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,gt?s.jsx("button",{type:"button",onClick:()=>j(r),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),Ft="pb-2";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:Pe("oc-group-body",Ft),children:Gt})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:Pe("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>de(r),role:"button",tabIndex:0,onKeyDown:ze=>{(ze.key==="Enter"||ze.key===" ")&&(ze.preventDefault(),de(r))},"aria-label":J?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!J,children:[s.jsx("div",{ref:Fe?.setActivatorNodeRef,className:Pe("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",ut),...Fe?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"archive",className:Pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:Pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:J?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:$i(n.label,l)}),pe]}):!n.isMain||n.worktree?s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(A,{name:"git-branch",className:Pe("h-3.5 w-3.5 shrink-0",!ue&&"text-muted-foreground",N?"hidden":"group-hover/gh:hidden"),style:ue?{color:ue}:void 0}),s.jsx("span",{className:Pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:J?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 truncate typography-ui-label font-semibold text-muted-foreground",children:$i(n.label,l)}),pe,oe?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:ue?{color:ue}:void 0,children:["#",oe.number]}):null]}):s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"min-w-0 truncate",children:$i(n.label,l)}),pe]})}),Mt&&Et?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(A,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(A,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-muted-foreground/80",children:Et.label})]}):null]})}),n.isArchivedBucket&&We.length>0?s.jsx("div",{className:Pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ze=>{ze.stopPropagation(),Gn.requestDelete({sessions:We,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:Pe("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ze=>{ze.stopPropagation(),Gn.requestDelete({sessions:We,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:Pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ze=>{ze.stopPropagation(),o&&o!==v&&D(o),F("chat"),w&&k(!1),E({selectedProjectId:o,directoryOverride:n.directory})},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":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})}),s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),J?null:s.jsx("div",{className:Pe("oc-group-body",Ft),children:Gt})]})}const qS=a.memo(GS,KS),YS=(t,e)=>{const n=t??{};return e<2&&(n.projectSortOrder="manual"),e<3&&n.projectSortOrder==="recent"&&(n.projectSortOrder="manual"),e<4&&delete n.displayMode,n},cn=zo()(zx(t=>({sessionGroupingMode:"by-worktree",setSessionGroupingMode:e=>t({sessionGroupingMode:e}),stickyZoneHeaders:!0,toggleStickyZoneHeaders:()=>t(e=>({stickyZoneHeaders:!e.stickyZoneHeaders})),showRecentSection:!0,showArchivedSessions:!1,projectSortOrder:"manual",setShowRecentSection:e=>t({showRecentSection:e}),setShowArchivedSessions:e=>t({showArchivedSessions:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection})),toggleArchivedSessions:()=>t(e=>({showArchivedSessions:!e.showArchivedSessions})),setProjectSortOrder:e=>t({projectSortOrder:e})}),{name:"session-display-mode",version:4,migrate:YS}));function QS(t){const e=ot.c(219),{t:n}=ft(),{hideDirectoryControls:r,showRecentControls:o,handleOpenDirectoryDialog:i,onOpenScheduled:c,onOpenMultiRun:l,canOpenMultiRun:d,onOpenArchive:u,headerActionIconClass:h,headerActionButtonClass:f,isSessionSearchOpen:p,setIsSessionSearchOpen:x,sessionSearchInputRef:b,sessionSearchQuery:S,setSessionSearchQuery:g,hasSessionSearchQuery:m,searchMatchCount:y,collapseAllProjects:C,expandAllProjects:j,selectionModeEnabled:w,onToggleSelectionMode:N}=t,v=cn(ok),D=cn(rk),F=cn(nk),k=cn(sk),E=cn(tk),O=cn(ek),M=cn(ZS),B=cn(JS);if(r)return null;let z;e[0]!==f?(z=Pe(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=f,e[1]=z):z=e[1];let T;e[2]!==n?(T=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=T):T=e[3];let I;e[4]!==h?(I=s.jsx(A,{name:"folder-add",className:h}),e[4]=h,e[5]=I):I=e[5];let R;e[6]!==i||e[7]!==z||e[8]!==T||e[9]!==I?(R=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:z,"aria-label":T,children:I})}),e[6]=i,e[7]=z,e[8]=T,e[9]=I,e[10]=R):R=e[10];let L;e[11]!==n?(L=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=L):L=e[12];let P;e[13]!==L?(P=s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:L})}),e[13]=L,e[14]=P):P=e[14];let G;e[15]!==R||e[16]!==P?(G=s.jsxs(St,{children:[R,P]}),e[15]=R,e[16]=P,e[17]=G):G=e[17];let X;e[18]!==f?(X=Pe(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=f,e[19]=X):X=e[19];let V;e[20]!==n?(V=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=V):V=e[21];let te;e[22]!==h?(te=s.jsx(A,{name:"calendar-schedule",className:h}),e[22]=h,e[23]=te):te=e[23];let Z;e[24]!==c||e[25]!==X||e[26]!==V||e[27]!==te?(Z=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:X,"aria-label":V,children:te})}),e[24]=c,e[25]=X,e[26]=V,e[27]=te,e[28]=Z):Z=e[28];let de;e[29]!==n?(de=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=de):de=e[30];let Fe;e[31]!==de?(Fe=s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:de})}),e[31]=de,e[32]=Fe):Fe=e[32];let se;e[33]!==Z||e[34]!==Fe?(se=s.jsxs(St,{children:[Z,Fe]}),e[33]=Z,e[34]=Fe,e[35]=se):se=e[35];let Q;e[36]!==f?(Q=Pe(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=f,e[37]=Q):Q=e[37];let Me;e[38]!==n?(Me=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=Me):Me=e[39];const xe=!d;let W;e[40]!==h?(W=s.jsx(Yp,{className:h}),e[40]=h,e[41]=W):W=e[41];let J;e[42]!==l||e[43]!==Q||e[44]!==Me||e[45]!==xe||e[46]!==W?(J=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,className:Q,"aria-label":Me,disabled:xe,children:W})}),e[42]=l,e[43]=Q,e[44]=Me,e[45]=xe,e[46]=W,e[47]=J):J=e[47];let ne;e[48]!==n?(ne=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=ne):ne=e[49];let oe;e[50]!==ne?(oe=s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ne})}),e[50]=ne,e[51]=oe):oe=e[51];let ue;e[52]!==J||e[53]!==oe?(ue=s.jsxs(St,{children:[J,oe]}),e[52]=J,e[53]=oe,e[54]=ue):ue=e[54];let Ae;e[55]!==f?(Ae=Pe(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=f,e[56]=Ae):Ae=e[56];let we;e[57]!==n?(we=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=we):we=e[58];let Se;e[59]!==h?(Se=s.jsx(A,{name:"archive",className:h}),e[59]=h,e[60]=Se):Se=e[60];let Le;e[61]!==u||e[62]!==Ae||e[63]!==we||e[64]!==Se?(Le=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:Ae,"aria-label":we,children:Se})}),e[61]=u,e[62]=Ae,e[63]=we,e[64]=Se,e[65]=Le):Le=e[65];let Ue;e[66]!==n?(Ue=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=Ue):Ue=e[67];let be;e[68]!==Ue?(be=s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ue})}),e[68]=Ue,e[69]=be):be=e[69];let q;e[70]!==Le||e[71]!==be?(q=s.jsxs(St,{children:[Le,be]}),e[70]=Le,e[71]=be,e[72]=q):q=e[72];let Ne;e[73]!==se||e[74]!==ue||e[75]!==q||e[76]!==G?(Ne=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[G,se,ue,q]}),e[73]=se,e[74]=ue,e[75]=q,e[76]=G,e[77]=Ne):Ne=e[77];let je;e[78]!==x?(je=()=>x(XS),e[78]=x,e[79]=je):je=e[79];let ve;e[80]!==f?(ve=Pe(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[80]=f,e[81]=ve):ve=e[81];let ie;e[82]!==n?(ie=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=ie):ie=e[83];let ee;e[84]!==h?(ee=s.jsx(A,{name:"search",className:h}),e[84]=h,e[85]=ee):ee=e[85];let ke;e[86]!==p||e[87]!==je||e[88]!==ve||e[89]!==ie||e[90]!==ee?(ke=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:je,className:ve,"aria-label":ie,"aria-expanded":p,children:ee})}),e[86]=p,e[87]=je,e[88]=ve,e[89]=ie,e[90]=ee,e[91]=ke):ke=e[91];let ae;e[92]!==n?(ae=n("sessions.sidebar.header.actions.searchSessions"),e[92]=n,e[93]=ae):ae=e[93];let U;e[94]!==ae?(U=s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ae})}),e[94]=ae,e[95]=U):U=e[95];let le;e[96]!==ke||e[97]!==U?(le=s.jsxs(St,{children:[ke,U]}),e[96]=ke,e[97]=U,e[98]=le):le=e[98];const _e=w&&"bg-interactive-hover text-primary";let De;e[99]!==f||e[100]!==_e?(De=Pe(f,"text-muted-foreground hover:text-foreground hover:bg-transparent",_e),e[99]=f,e[100]=_e,e[101]=De):De=e[101];let ce;e[102]!==w||e[103]!==n?(ce=n(w?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[102]=w,e[103]=n,e[104]=ce):ce=e[104];let he;e[105]!==h?(he=s.jsx(A,{name:"checkbox-multiple",className:h}),e[105]=h,e[106]=he):he=e[106];let me;e[107]!==N||e[108]!==w||e[109]!==De||e[110]!==ce||e[111]!==he?(me=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:N,className:De,"aria-label":ce,"aria-pressed":w,children:he})}),e[107]=N,e[108]=w,e[109]=De,e[110]=ce,e[111]=he,e[112]=me):me=e[112];let $;e[113]!==w||e[114]!==n?($=n(w?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[113]=w,e[114]=n,e[115]=$):$=e[115];let _;e[116]!==$?(_=s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:$})}),e[116]=$,e[117]=_):_=e[117];let ge;e[118]!==me||e[119]!==_?(ge=s.jsxs(St,{children:[me,_]}),e[118]=me,e[119]=_,e[120]=ge):ge=e[120];let Ie;e[121]!==f?(Ie=Pe(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[121]=f,e[122]=Ie):Ie=e[122];let Re;e[123]!==n?(Re=n("sessions.sidebar.header.displayMode.label"),e[123]=n,e[124]=Re):Re=e[124];let Ke;e[125]!==h?(Ke=s.jsx(A,{name:"equalizer-2",className:h}),e[125]=h,e[126]=Ke):Ke=e[126];let nt;e[127]!==Ie||e[128]!==Re||e[129]!==Ke?(nt=s.jsx(kt,{asChild:!0,children:s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Ie,"aria-label":Re,children:Ke})})}),e[127]=Ie,e[128]=Re,e[129]=Ke,e[130]=nt):nt=e[130];let ct;e[131]!==n?(ct=n("sessions.sidebar.header.displayMode.label"),e[131]=n,e[132]=ct):ct=e[132];let mt;e[133]!==ct?(mt=s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ct})}),e[133]=ct,e[134]=mt):mt=e[134];let gt;e[135]!==nt||e[136]!==mt?(gt=s.jsxs(St,{children:[nt,mt]}),e[135]=nt,e[136]=mt,e[137]=gt):gt=e[137];let ht;e[138]!==n?(ht=n("sessions.sidebar.header.actions.sortProjects"),e[138]=n,e[139]=ht):ht=e[139];let wt;e[140]!==ht?(wt=s.jsx(Co,{children:ht}),e[140]=ht,e[141]=wt):wt=e[141];let bt;e[142]!==F||e[143]!==k||e[144]!==n?(bt=[["manual","sessions.sidebar.header.projectSort.manual"],["a-z","sessions.sidebar.header.projectSort.aToZ"],["z-a","sessions.sidebar.header.projectSort.zToA"],["date-added","sessions.sidebar.header.projectSort.dateAdded"],["recent","sessions.sidebar.header.projectSort.recent"]].map(Ze=>{const[At,Rt]=Ze;return s.jsxs(is,{onClick:()=>k(At),className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Rt)}),F===At?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]},At)}),e[142]=F,e[143]=k,e[144]=n,e[145]=bt):bt=e[145];let yt;e[146]===Symbol.for("react.memo_cache_sentinel")?(yt=s.jsx(Ln,{}),e[146]=yt):yt=e[146];let Dt;e[147]!==n?(Dt=n("sessions.sidebar.header.grouping.label"),e[147]=n,e[148]=Dt):Dt=e[148];let Kt;e[149]!==Dt?(Kt=s.jsx(Co,{children:Dt}),e[149]=Dt,e[150]=Kt):Kt=e[150];let Ut;e[151]!==E||e[152]!==O||e[153]!==n?(Ut=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(Ze=>{const[At,Rt]=Ze;return s.jsxs(is,{onClick:()=>O(At),className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Rt)}),E===At?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]},At)}),e[151]=E,e[152]=O,e[153]=n,e[154]=Ut):Ut=e[154];let Lt;e[155]===Symbol.for("react.memo_cache_sentinel")?(Lt=s.jsx(Ln,{}),e[155]=Lt):Lt=e[155];let Bt;e[156]!==o||e[157]!==v||e[158]!==n||e[159]!==D?(Bt=o?s.jsxs(is,{onClick:D,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),v?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[156]=o,e[157]=v,e[158]=n,e[159]=D,e[160]=Bt):Bt=e[160];let et;e[161]!==n?(et=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[161]=n,e[162]=et):et=e[162];let Ht;e[163]!==et?(Ht=s.jsx("span",{children:et}),e[163]=et,e[164]=Ht):Ht=e[164];let It;e[165]!==M?(It=M?s.jsx(A,{name:"check",className:"h-4 w-4 text-primary"}):null,e[165]=M,e[166]=It):It=e[166];let We;e[167]!==Ht||e[168]!==It||e[169]!==B?(We=s.jsxs(is,{onClick:B,className:"flex items-center justify-between",children:[Ht,It]}),e[167]=Ht,e[168]=It,e[169]=B,e[170]=We):We=e[170];let pt;e[171]===Symbol.for("react.memo_cache_sentinel")?(pt=s.jsx(Ln,{}),e[171]=pt):pt=e[171];let Mt;e[172]===Symbol.for("react.memo_cache_sentinel")?(Mt=s.jsx(A,{name:"contract-up-down",className:"h-4 w-4"}),e[172]=Mt):Mt=e[172];let Et;e[173]!==n?(Et=n("sessions.sidebar.header.displayMode.collapseAll"),e[173]=n,e[174]=Et):Et=e[174];let tt;e[175]!==Et?(tt=s.jsx("span",{children:Et}),e[175]=Et,e[176]=tt):tt=e[176];let pe;e[177]!==C||e[178]!==tt?(pe=s.jsxs(is,{onClick:C,className:"flex items-center gap-2",children:[Mt,tt]}),e[177]=C,e[178]=tt,e[179]=pe):pe=e[179];let Oe;e[180]===Symbol.for("react.memo_cache_sentinel")?(Oe=s.jsx(A,{name:"expand-up-down",className:"h-4 w-4"}),e[180]=Oe):Oe=e[180];let Te;e[181]!==n?(Te=n("sessions.sidebar.header.displayMode.expandAll"),e[181]=n,e[182]=Te):Te=e[182];let it;e[183]!==Te?(it=s.jsx("span",{children:Te}),e[183]=Te,e[184]=it):it=e[184];let ut;e[185]!==j||e[186]!==it?(ut=s.jsxs(is,{onClick:j,className:"flex items-center gap-2",children:[Oe,it]}),e[185]=j,e[186]=it,e[187]=ut):ut=e[187];let Gt;e[188]!==wt||e[189]!==bt||e[190]!==Kt||e[191]!==Ut||e[192]!==Bt||e[193]!==We||e[194]!==pe||e[195]!==ut?(Gt=s.jsxs(Ys,{align:"end",className:"min-w-[180px]",children:[wt,bt,yt,Kt,Ut,Lt,Bt,We,pt,pe,ut]}),e[188]=wt,e[189]=bt,e[190]=Kt,e[191]=Ut,e[192]=Bt,e[193]=We,e[194]=pe,e[195]=ut,e[196]=Gt):Gt=e[196];let Ft;e[197]!==gt||e[198]!==Gt?(Ft=s.jsxs(Qs,{children:[gt,Gt]}),e[197]=gt,e[198]=Gt,e[199]=Ft):Ft=e[199];let ze;e[200]!==le||e[201]!==ge||e[202]!==Ft?(ze=s.jsxs("div",{className:"flex items-center gap-1.5",children:[le,ge,Ft]}),e[200]=le,e[201]=ge,e[202]=Ft,e[203]=ze):ze=e[203];let Qe;e[204]!==Ne||e[205]!==ze?(Qe=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[Ne,ze]}),e[204]=Ne,e[205]=ze,e[206]=Qe):Qe=e[206];let st;e[207]!==m||e[208]!==p||e[209]!==y||e[210]!==b||e[211]!==S||e[212]!==x||e[213]!==g||e[214]!==n?(st=p?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[m?s.jsx("span",{children:y===1?n("sessions.sidebar.header.search.matchCountSingle",{count:y}):n("sessions.sidebar.header.search.matchCountPlural",{count:y})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:b,value:S,onChange:Ze=>g(Ze.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:Ze=>{Ze.key==="Escape"&&(Ze.stopPropagation(),m?g(""):x(!1))}}),S.length>0?s.jsx("button",{type:"button",onClick:()=>g(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[207]=m,e[208]=p,e[209]=y,e[210]=b,e[211]=S,e[212]=x,e[213]=g,e[214]=n,e[215]=st):st=e[215];let at;return e[216]!==Qe||e[217]!==st?(at=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[Qe,st]})}),e[216]=Qe,e[217]=st,e[218]=at):at=e[218],at}function XS(t){return!t}function JS(t){return t.toggleStickyZoneHeaders}function ZS(t){return t.stickyZoneHeaders}function ek(t){return t.setSessionGroupingMode}function tk(t){return t.sessionGroupingMode}function sk(t){return t.setProjectSortOrder}function nk(t){return t.projectSortOrder}function rk(t){return t.toggleRecentSection}function ok(t){return t.showRecentSection}function ik(t){const e=ot.c(8),{t:n}=ft(),r=t.onNewSession;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(A,{name:"chat-new",className:"h-4 w-4 flex-shrink-0"}),e[0]=o):o=e[0];let i;e[1]!==n?(i=n("sessions.sidebar.header.actions.newSession"),e[1]=n,e[2]=i):i=e[2];let c;e[3]!==i?(c=s.jsx("span",{className:"truncate",children:i}),e[3]=i,e[4]=c):c=e[4];let l;return e[5]!==t.onNewSession||e[6]!==c?(l=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 pt-1.5",children:s.jsxs("button",{type:"button",onClick:r,className:"flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1 text-left typography-ui-label font-normal text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[o,c]})}),e[5]=t.onNewSession,e[6]=c,e[7]=l):l=e[7],l}const ou=7;function ak(t){const{sections:e,renderSessionNode:n,editingId:r,openSidebarMenuKey:o,variant:i="section",initialVisibleCount:c=ou,batchSize:l=ou}=t,{t:d}=ft(),u=cn(j=>j.stickyZoneHeaders),[h,f]=a.useState(new Set),[p,x]=a.useState(new Map),b=i==="flat",S=a.useCallback(j=>{x(w=>{if(!w.has(j))return w;const N=new Map(w);return N.delete(j),N})},[]),g=a.useCallback(j=>{S(j),f(w=>{const N=new Set(w);return N.has(j)?N.delete(j):N.add(j),N})},[S]),m=a.useCallback((j,w,N)=>{x(v=>{const D=Math.min(N,w+l),F=new Map(v);return F.set(j,D),F})},[l]),y=a.useCallback(j=>{const w=new Set;Pl(j,r,w);const N=mi(j,o,"recent",!1),v=new WeakMap,D=k=>{v.set(k,ca(k)),k.children.forEach(D)};j.forEach(D);const F=k=>({subtreeContainsEditing:w,menuOpenSessionId:N,nodeStructureKey:v.get(k)??"",childRenderExtrasFor:F});return k=>({subtreeContainsEditing:w,menuOpenSessionId:N,nodeStructureKey:v.get(k)??"",childRenderExtrasFor:F})},[r,o]),C=e.filter(j=>j.items.length>0);return C.length===0?null:s.jsx("div",{className:Pe(b?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:C.map(j=>{const w=h.has(j.key),N=Math.max(c,p.get(j.key)??c),v=j.items.slice(0,N),D=j.items.length-v.length,F=!b&&j.items.length>c&&D===0,k=y(v.map(O=>O.node)),E=O=>n(O.node,0,O.groupDirectory,O.projectId,!1,O.secondaryMeta,"recent",k(O.node));return b?s.jsxs("div",{className:"space-y-0.5",children:[v.map(E),D>0?s.jsx("button",{type:"button",onClick:()=>m(j.key,v.length,j.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showMore")}):null]},j.key):s.jsxs("div",{className:"relative space-y-1",children:[s.jsx("div",{className:Pe("-ml-2.5 -mr-2",u&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":u?"true":void 0,children:s.jsxs("button",{type:"button",onClick:()=>g(j.key),className:"group flex w-full items-center gap-1.5 py-1 pl-4 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!w,children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center",children:[s.jsx(A,{name:"history",className:Pe("h-3.5 w-3.5 text-muted-foreground/80","group-hover:hidden")}),s.jsx("span",{className:"hidden h-3.5 w-3.5 items-center justify-center text-muted-foreground group-hover:inline-flex",children:w?s.jsx(A,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(A,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"text-[14px] font-semibold lowercase text-foreground",children:j.title})]})}),w?null:s.jsxs("div",{className:Pe("space-y-0.5"),children:[v.map(E),D>0?s.jsx("button",{type:"button",onClick:()=>m(j.key,v.length,j.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showMore")}):null,F?s.jsx("button",{type:"button",onClick:()=>S(j.key),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showFewer")}):null]})]},j.key)})})}const rl="inline-flex h-8 w-8 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";function lk(t){const e=ot.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:i,showRuntimeButtons:c,showUpdateButton:l}=t,d=c===void 0?!0:c,u=l===void 0?!0:l,{t:h}=ft();if(!d&&!u)return null;let f;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==h?(f=d?s.jsxs(s.Fragment,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:rl,"aria-label":h("sessions.sidebar.footer.actions.settings"),children:s.jsx(A,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(Nt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:rl,"aria-label":h("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(A,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(Nt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:rl,"aria-label":h("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(A,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(Nt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=h,e[5]=f):f=e[5];let p;e[6]!==i||e[7]!==u||e[8]!==h?(p=u?s.jsx(He,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:h("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=u,e[8]=h,e[9]=p):p=e[9];let x;return e[10]!==f||e[11]!==p?(x=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[f,p]}),e[10]=f,e[11]=p,e[12]=x):x=e[12],x}const $m=t=>{const e=ot.c(22),{id:n,projectLabel:r,projectIcon:o,projectColor:i,projectIconImage:c,projectIconBackground:l,isCollapsed:d,alwaysShowActions:u}=t,h=u===void 0?!1:u,{currentTheme:f}=lo(),p=o?Ql[o]:null,x=i?Xl[i]??null:null,b=d!==void 0,S=b?h?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let g;e[0]!==h||e[1]!==b||e[2]!==d?(g=b?s.jsx("span",{className:Pe("h-3.5 w-3.5 items-center justify-center text-muted-foreground",h?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:s.jsx(A,{name:d?"arrow-right-s":"arrow-down-s",className:"h-3.5 w-3.5"})}):null,e[0]=h,e[1]=b,e[2]=d,e[3]=g):g=e[3];let m;e[4]!==h||e[5]!==f||e[6]!==b||e[7]!==x||e[8]!==S||e[9]!==n||e[10]!==l||e[11]!==c||e[12]!==p?(m=c?s.jsx("span",{className:Pe("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",b&&h?"hidden":"inline-flex",S),style:l?{backgroundColor:l}:void 0,children:s.jsx(Jl,{project:{id:n,iconImage:c},options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",fallback:p?s.jsx(A,{name:p,className:"h-3.5 w-3.5",style:x?{color:x}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:x?{color:x}:void 0})})}):p?s.jsx(A,{name:p,className:Pe("h-3.5 w-3.5",S),style:x?{color:x}:void 0}):s.jsx(A,{name:"folder",className:Pe("h-3.5 w-3.5 text-muted-foreground/80",S),style:x?{color:x}:void 0}),e[4]=h,e[5]=f,e[6]=b,e[7]=x,e[8]=S,e[9]=n,e[10]=l,e[11]=c,e[12]=p,e[13]=m):m=e[13];let y;e[14]!==g||e[15]!==m?(y=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[g,m]}),e[14]=g,e[15]=m,e[16]=y):y=e[16];let C;e[17]!==r?(C=s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=C):C=e[18];let j;return e[19]!==y||e[20]!==C?(j=s.jsxs(s.Fragment,{children:[y,C]}),e[19]=y,e[20]=C,e[21]=j):j=e[21],j},ck=t=>{const e=ot.c(59),{id:n,disabled:r,projectLabel:o,projectDescription:i,projectIcon:c,projectColor:l,projectIconImage:d,projectIconBackground:u,isCollapsed:h,isRepo:f,isDesktopShell:p,hideDirectoryControls:x,alwaysShowActions:b,onToggle:S,onNewSession:g,onNewWorktreeSession:m,onManageWorktrees:y,onRenameStart:C,onClose:j,sentinelRef:w,children:N,showCreateButtons:v,hideHeader:D,openSidebarMenuKey:F,setOpenSidebarMenuKey:k,statusIndicator:E}=t,O=r===void 0?!1:r,M=v===void 0?!0:v,B=D===void 0?!1:D,z=E===void 0?null:E,{t:T}=ft(),I=cn(fk);let R;e[0]!==O||e[1]!==n?(R={id:n,disabled:O},e[0]=O,e[1]=n,e[2]=R):R=e[2];const{attributes:L,listeners:P,setNodeRef:G,transform:X,transition:V,isDragging:te}=tc(R),Z=a.useRef(!1),de=`project:${n}`,Fe=F===de,[se,Q]=a.useState(!1);let Me;e[3]!==de||e[4]!==k?(Me=ie=>{ie&&Q(!1),k(ie?de:null)},e[3]=de,e[4]=k,e[5]=Me):Me=e[5];const xe=Me;let W;e[6]!==x||e[7]!==f||e[8]!==j||e[9]!==y||e[10]!==g||e[11]!==C||e[12]!==M||e[13]!==T?(W=ie=>s.jsxs(s.Fragment,{children:[M&&!f&&!x&&g&&s.jsxs(ie,{onClick:g,children:[s.jsx(A,{name:"add",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.newSession")]}),f&&!x&&y&&s.jsxs(ie,{onClick:y,children:[s.jsx(A,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs(ie,{onClick:C,children:[s.jsx(A,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.edit")]}),s.jsxs(ie,{onClick:j,className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=x,e[7]=f,e[8]=j,e[9]=y,e[10]=g,e[11]=C,e[12]=M,e[13]=T,e[14]=W):W=e[14];const J=W,ne=mk,oe=hk,ue=pk;let Ae;e[15]===Symbol.for("react.memo_cache_sentinel")?(Ae=ie=>{(ie.button===2||ie.button===0&&ie.ctrlKey)&&(Z.current=!0)},e[15]=Ae):Ae=e[15];const we=Ae;let Se;e[16]!==S?(Se=ie=>{if(ie.currentTarget.blur(),Z.current){Z.current=!1;return}S()},e[16]=S,e[17]=Se):Se=e[17];const Le=Se;let Ue;e[18]!==X?(Ue=sc.Transform.toString(X),e[18]=X,e[19]=Ue):Ue=e[19];let be;e[20]!==Ue||e[21]!==V?(be={transform:Ue,transition:V},e[20]=Ue,e[21]=V,e[22]=be):be=e[22];const q=te&&"opacity-30";let Ne;e[23]!==q?(Ne=Pe("relative",q),e[23]=q,e[24]=Ne):Ne=e[24];let je;e[25]!==b||e[26]!==L||e[27]!==xe||e[28]!==Le||e[29]!==x||e[30]!==B||e[31]!==n||e[32]!==h||e[33]!==se||e[34]!==p||e[35]!==Fe||e[36]!==f||e[37]!==P||e[38]!==g||e[39]!==m||e[40]!==l||e[41]!==i||e[42]!==c||e[43]!==u||e[44]!==d||e[45]!==o||e[46]!==J||e[47]!==w||e[48]!==M||e[49]!==z||e[50]!==I||e[51]!==T?(je=B?null:s.jsxs(s.Fragment,{children:[p&&s.jsx("div",{ref:w,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(Ef,{open:se,onOpenChange:Q,children:[s.jsx(Tf,{render:s.jsx("div",{className:Pe("-ml-2.5 -mr-2 text-left group/project select-none",I&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":I?"true":void 0,onContextMenu:ie=>{x||(ie.preventDefault(),Q(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...L,children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:we,onClick:Le,...P,className:Pe("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",f&&!x?b?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":b?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx($m,{id:n,projectLabel:o,projectIcon:c,projectColor:l,projectIconImage:d,projectIconBackground:u,isCollapsed:h,alwaysShowActions:b}),z?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:z}):null]})}),s.jsx(Nt,{side:"right",sideOffset:8,children:i})]}),s.jsxs("div",{className:Pe("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",M?"right-7":"right-0.5"),children:[M&&f&&!x&&m?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),m()},className:Pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",b?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(A,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,x?null:s.jsxs(Qs,{open:Fe,onOpenChange:xe,children:[s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",Fe?"opacity-100 pointer-events-auto":b?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T("sessions.sidebar.project.actions.projectMenu"),onPointerDown:oe,onMouseDown:ue,onClick:ne,children:s.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ys,{align:"end",className:"min-w-[180px]",children:J(is)})]})]}),M&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),g()},className:Pe("inline-flex h-6 w-6 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",b?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":T(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(A,{name:"add",className:"h-4 w-4"})})}),s.jsx(Nt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(Rf,{className:"min-w-[180px]",children:J(Mf)})]})]}),e[25]=b,e[26]=L,e[27]=xe,e[28]=Le,e[29]=x,e[30]=B,e[31]=n,e[32]=h,e[33]=se,e[34]=p,e[35]=Fe,e[36]=f,e[37]=P,e[38]=g,e[39]=m,e[40]=l,e[41]=i,e[42]=c,e[43]=u,e[44]=d,e[45]=o,e[46]=J,e[47]=w,e[48]=M,e[49]=z,e[50]=I,e[51]=T,e[52]=je):je=e[52];let ve;return e[53]!==N||e[54]!==G||e[55]!==be||e[56]!==Ne||e[57]!==je?(ve=s.jsxs("div",{ref:G,style:be,className:Ne,children:[je,N]}),e[53]=N,e[54]=G,e[55]=be,e[56]=Ne,e[57]=je,e[58]=ve):ve=e[58],ve},dk=t=>{const e=ot.c(21),{id:n,disabled:r,children:o}=t,i=r===void 0?!1:r;let c;e[0]!==i||e[1]!==n?(c={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=c):c=e[2];const{listeners:l,setNodeRef:d,setActivatorNodeRef:u,transform:h,transition:f,isDragging:p}=tc(c);let x;e[3]!==l||e[4]!==u?(x={listeners:l,setActivatorNodeRef:u},e[3]=l,e[4]=u,e[5]=x):x=e[5];const b=x;let S;e[6]!==h?(S=sc.Transform.toString(h),e[6]=h,e[7]=S):S=e[7];let g;e[8]!==S||e[9]!==f?(g={transform:S,transition:f},e[8]=S,e[9]=f,e[10]=g):g=e[10];const m=p&&"opacity-50";let y;e[11]!==m?(y=Pe("space-y-0.5 rounded-md",m),e[11]=m,e[12]=y):y=e[12];let C;e[13]!==o||e[14]!==b?(C=typeof o=="function"?o(b):o,e[13]=o,e[14]=b,e[15]=C):C=e[15];let j;return e[16]!==d||e[17]!==g||e[18]!==y||e[19]!==C?(j=s.jsx("div",{ref:d,style:g,className:y,children:C}),e[16]=d,e[17]=g,e[18]=y,e[19]=C,e[20]=j):j=e[20],j},uk=a.memo(dk);function fk(t){return t.stickyZoneHeaders}function mk(t){t.stopPropagation()}function hk(t){t.stopPropagation()}function pk(t){t.stopPropagation()}const gk=48,xk=32,bk=24,iu=(t,e)=>Zl(t.label?.trim()||Vr(t.normalizedPath,e)||t.normalizedPath);function yk(t){Zn("ui.sidebar_projects_list.render");const{t:e}=ft(),n=t.isDesktopShellRuntime&&t.stickyZoneHeaders,r=ra(Do(yl,{activationConstraint:{distance:8}}),Do(eb,{coordinateGetter:tb})),o=ra(Do(yl,{activationConstraint:{distance:8}})),i=a.useRef(new Map),c=a.useRef(t.getOrderedGroups);c.current!==t.getOrderedGroups&&(c.current=t.getOrderedGroups,i.current.clear());const l=(g,m)=>{const y=i.current,C=y.get(g);if(C&&C.groups===m)return C.ordered;const j=t.getOrderedGroups(g,m);if(y.set(g,{groups:m,ordered:j}),y.size>256){const w=y.keys().next().value;w!==void 0&&y.delete(w)}return j},d=a.useRef(null),u=a.useRef(0),h=a.useCallback(g=>{const y=g.scrollTop>1?Math.min(xk+g.scrollTop,gk):0;u.current=y,g.style.setProperty("--scroll-shadow-top-size",`${y}px`),g.style.setProperty("--scroll-shadow-top-clear-size",`${Math.min(Math.max(y-8,0),bk)}px`)},[]),f=a.useCallback(g=>{g.target.closest("[data-overlay-scrollbar-thumb], [data-sidebar-sticky-header]")||g.clientY-g.currentTarget.getBoundingClientRect().top>=u.current||(g.preventDefault(),g.stopPropagation())},[]),p=t.projectSections.length>0&&t.sectionsForRender.length>0;a.useLayoutEffect(()=>{n&&p&&d.current&&h(d.current)},[n,p,h]);let x=null;for(const g of t.projectSections)t.stuckProjectHeaders.has(g.project.id)&&(x=g.project);const b=x??(t.hasSharedSessions?null:t.sectionsForRender[0]?.project??null),S=b?iu(b,t.homeDirectory):null;return t.sharedSessionsOnly?s.jsxs(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Pe("space-y-1 pb-1 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.hasSharedSessions?null:t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState]}):t.projectSections.length===0?s.jsxs(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Pe("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.emptyState]}):t.sectionsForRender.length===0?s.jsx(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Pe("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:t.searchEmptyState}):s.jsxs("div",{className:"oc-sticky-fade-root relative flex min-h-0 flex-1",onPointerDownCapture:n?f:void 0,onClickCapture:n?f:void 0,onContextMenuCapture:n?f:void 0,children:[s.jsxs(On,{ref:d,useScrollShadow:!0,hideTopScrollShadow:!n,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:Pe("oc-sidebar-scroller space-y-1.5 pb-1 pl-2.5 pr-2 [overflow-anchor:none]",(t.mobileVariant,"")),style:n?{"--scroll-shadow-top-size":"0px"}:void 0,onScroll:n?g=>h(g.currentTarget):void 0,children:[t.topContent,t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const g=t.sectionsForRender.find(j=>j.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!g)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const m=g.groups.find(j=>j.isMain&&j.sessions.length>0)??g.groups.find(j=>j.sessions.length>0)??g.groups.find(j=>j.isMain)??g.groups[0];if(!m)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")});const y=g.groups.find(j=>j.isArchivedBucket);return[m,...y&&y.id!==m.id?[y]:[]].map(j=>{const w=`${g.project.id}:${j.id}`,N=j.id===m.id;return s.jsx(a.Fragment,{children:t.renderGroupSessions(j,w,g.project.id,N,null,!0,d)},w)})})()}):s.jsxs(oa,{sensors:r,collisionDetection:ia,onDragEnd:g=>{if(t.isInlineEditing||t.projectSortOrder!=="manual")return;const{active:m,over:y}=g;if(!y||m.id===y.id)return;const C=t.sectionsForRender.findIndex(w=>w.project.id===m.id),j=t.sectionsForRender.findIndex(w=>w.project.id===y.id);C===-1||j===-1||C===j||t.reorderProjects(C,j)},children:[s.jsx(vl,{items:t.sectionsForRender.map(g=>g.project.id),strategy:jl,children:t.sectionsForRender.map(g=>{const m=g.project,y=m.id,C=iu(m,t.homeDirectory),j=Zi(m.normalizedPath,t.homeDirectory),w=t.collapsedProjects.has(y),N=t.projectRepoStatus.get(y);return s.jsx(ck,{id:y,disabled:t.projectSortOrder!=="manual",projectLabel:C,projectDescription:j,projectIcon:m.icon,projectColor:m.color,projectIconImage:m.iconImage,projectIconBackground:m.iconBackground,isCollapsed:w,isRepo:!!N,isDesktopShell:t.isDesktopShellRuntime,hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,statusIndicator:w?t.renderProjectStatusIndicator?.(y,g.groups):null,onToggle:()=>t.toggleProject(y),onNewSession:()=>{y!==t.activeProjectId&&t.setActiveProjectIdOnly(y),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({selectedProjectId:y,directoryOverride:m.normalizedPath})},onNewWorktreeSession:()=>{y!==t.activeProjectId&&t.setActiveProjectIdOnly(y),t.setActiveMainTab("chat"),t.openNewWorktreeDialog()},onManageWorktrees:()=>t.openWorktreesPage(y),onRenameStart:()=>t.openProjectEditDialog(y),onClose:()=>t.removeProject(y),sentinelRef:v=>{t.projectHeaderSentinelRefs.current.set(y,v)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:w?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const v=l(y,g.groups),D=v.find(k=>k.isMain)??null,F=D?v.filter(k=>k.id!==D.id):v;return s.jsxs(oa,{sensors:o,collisionDetection:ia,onDragEnd:k=>{if(t.isInlineEditing)return;const{active:E,over:O}=k;if(!O||E.id===O.id)return;const M=F.findIndex(I=>I.id===E.id),B=F.findIndex(I=>I.id===O.id);if(M===-1||B===-1||M===B)return;const z=Uf(F,M,B).map(I=>I.id),T=D?[D.id,...z]:z;t.setGroupOrderByProject(I=>{const R=new Map(I);return R.set(y,T),R})},children:[D?t.renderGroupSessions(D,`${y}:${D.id}`,y,!0,null,void 0,d):null,s.jsx(vl,{items:F.map(k=>k.id),strategy:jl,children:F.map(k=>{const E=`${y}:${k.id}`;return s.jsx(uk,{id:k.id,disabled:t.isInlineEditing,children:O=>t.renderGroupSessions(k,E,y,!1,O,void 0,d)},k.id)})}),s.jsx(wl,{dropAnimation:null})]})})()})},y)})}),s.jsx(wl,{dropAnimation:null})]})]}),n&&(b||t.hasSharedSessions)?s.jsx("div",{className:"oc-sticky-fade-overlay pointer-events-none absolute inset-x-0 top-0 z-30 flex items-center gap-1.5 py-1 pl-4 pr-5","aria-hidden":"true",children:b&&S?s.jsx($m,{id:b.id,projectLabel:S,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground}):s.jsxs(s.Fragment,{children:[s.jsx(A,{name:"history",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:e("sessions.sidebar.activity.recentTitle")})]})}):null]})}const wk=a.memo(yk),vk=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const o of t){r.has(o)||(r.add(o),n.push(o));const i=e.get(o);if(i)for(const c of i)r.has(c)||(r.add(c),n.push(c))}return n},ln=zo()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,o)=>{const i=e(),c=new Set(i.selectedIds);let l=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(c.clear(),l=r,d=null):l===null&&r!==null&&(l=r);const h=o&&o.length>0?[n,...o]:[n];if(c.has(n)){for(const p of h)c.delete(p);d===n&&(d=null)}else{for(const p of h)c.add(p);d=n}c.size===0?t({selectedIds:c,scopeKey:null,anchorId:null}):t({selectedIds:c,scopeKey:l,anchorId:d})},setRange:(n,r,o,i,c)=>{const l=e();if(o.length===0)return;const d=n&&o.includes(n)?n:o[0],u=o.indexOf(d),h=o.indexOf(r);if(u<0||h<0)return;const[f,p]=u<=h?[u,h]:[h,u],x=o.slice(f,p+1),b=vk(x,c),g=i!==null&&l.scopeKey!==null&&i!==l.scopeKey?new Set:new Set(l.selectedIds);for(const m of b)g.add(m);t({selectedIds:g,scopeKey:i??l.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const o=new Set(r.selectedIds);for(const i of n)o.delete(i);o.size!==r.selectedIds.size&&(o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o}))}}));let Il=!1;const Rl=new Set;let au=!1;function jk(){for(const t of Rl)t()}function xc(t){Il!==t&&(Il=t,jk())}function Sk(t){t.key==="Shift"&&xc(!0)}function kk(t){t.key==="Shift"&&xc(!1)}function Nk(){xc(!1)}function Ck(){au||typeof window>"u"||(au=!0,window.addEventListener("keydown",Sk),window.addEventListener("keyup",kk),window.addEventListener("blur",Nk))}function Ak(t){return Ck(),Rl.add(t),()=>{Rl.delete(t)}}function Dk(){return Il}function Pk(){return!1}function Ik(){return $e.useSyncExternalStore(Ak,Dk,Pk)}const Rk=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,_m=/^g[1-9]\d*$/,ei=(t,e,n,r,o)=>{if(!Rk.test(t)||e!==void 0&&!_m.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(o===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(o==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(o))return null;const i=Number.parseInt(o,10);return!Number.isSafeInteger(i)||i<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:i,fusion:!1}},Hi=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return ei(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,l,d,u]=e;return _m.test(l)?ei(n,l,d,u,void 0):ei(n,void 0,l,d,u)}const[,r,o,i,c]=e;return r===""?ei(n,void 0,o,i,c):ei(n,r,o,i,c)},Mk=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},Tk=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},zm=t=>{const e=ot.c(36),{value:n,onChange:r,className:o,disabled:i,id:c,portalToBody:l}=t,{t:d}=ft(),u=rs(Ek),h=rs(Fk),f=rs(Ok);let p;e[0]!==u?(p=u(),e[0]=u,e[1]=p):p=e[1];const x=p;let b;e[2]!==x?(b=x.filter(Lk),e[2]=x,e[3]=b):b=e[3];const S=b;let g,m;e[4]!==x.length||e[5]!==h?(g=()=>{x.length===0&&h()},m=[x.length,h],e[4]=x.length,e[5]=h,e[6]=g,e[7]=m):(g=e[6],m=e[7]),a.useEffect(g,m);let y,C;e[8]!==f||e[9]!==i||e[10]!==r||e[11]!==S||e[12]!==n?(y=()=>{if(i)return;const O=n.trim();if(O.length>0&&S.some(z=>z.name===O))return;const M=typeof f=="string"&&f.trim().length>0?f.trim():null;if(M&&S.some(z=>z.name===M)){r(M);return}const B=S[0]?.name;B&&r(B)},C=[f,i,r,S,n],e[8]=f,e[9]=i,e[10]=r,e[11]=S,e[12]=n,e[13]=y,e[14]=C):(y=e[13],C=e[14]),a.useEffect(y,C);const j=n.trim().length>0?n:void 0;let w;e[15]!==o?(w=Pe("max-w-full",o),e[15]=o,e[16]=w):w=e[16];let N;e[17]!==d?(N=d("multirun.agentSelector.placeholder"),e[17]=d,e[18]=N):N=e[18];let v;e[19]!==N?(v=s.jsx(rn,{placeholder:N}),e[19]=N,e[20]=v):v=e[20];let D;e[21]!==c||e[22]!==w||e[23]!==v?(D=s.jsx(bn,{id:c,size:"lg",className:w,children:v}),e[21]=c,e[22]=w,e[23]=v,e[24]=D):D=e[24];let F;e[25]!==S?(F=S.length>0&&s.jsx(pl,{children:S.map(Bk)}),e[25]=S,e[26]=F):F=e[26];let k;e[27]!==l||e[28]!==F?(k=s.jsx(yn,{fitContent:!0,portalToBody:l,children:F}),e[27]=l,e[28]=F,e[29]=k):k=e[29];let E;return e[30]!==i||e[31]!==r||e[32]!==j||e[33]!==D||e[34]!==k?(E=s.jsxs(xn,{value:j,onValueChange:r,disabled:i,children:[D,k]}),e[30]=i,e[31]=r,e[32]=j,e[33]=D,e[34]=k,e[35]=E):E=e[35],E};function Ek(t){return t.getVisibleAgents}function Fk(t){return t.loadAgents}function Ok(t){return t.currentAgentName}function Lk(t){return xf(t.mode)}function Bk(t){return s.jsx(ys,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const $k="h-7",ii=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,_k=t=>{const e=ot.c(12),{model:n,instanceIndex:r,totalSameModel:o,onRemove:i}=t,c=n.displayName||`${n.providerID}/${n.modelID}`,l=o>1?`${c} (${r})`:c;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=Pe("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",$k),e[0]=d):d=e[0];let u;e[1]!==n.providerID?(u=s.jsx(li,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=u):u=e[2];let h;e[3]!==l?(h=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:l}),e[3]=l,e[4]=h):h=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(A,{name:"close",className:"h-3.5 w-3.5"}),e[5]=f):f=e[5];let p;e[6]!==i?(p=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=i,e[7]=p):p=e[7];let x;return e[8]!==u||e[9]!==h||e[10]!==p?(x=s.jsxs("div",{className:d,children:[u,h,p]}),e[8]=u,e[9]=h,e[10]=p,e[11]=x):x=e[11],x},Vm=t=>{const e=ot.c(120),{selectedModels:n,onAdd:r,onRemove:o,onUpdate:i,minModels:c,addButtonLabel:l,showChips:d,maxModels:u,addButtonClassName:h,dropdownSide:f,dropdownClassName:p,containerClassName:x,triggerIcon:b}=t,S=d===void 0?!0:d,g=f===void 0?"top":f,{t:m}=ft(),y=rs(zk),C=rs(Vk),j=Ee(Wk),w=Ee(Uk),{favoriteModelsList:N,recentModelsList:v}=Qp(),D=Ee(Hk),F=Ee(Kk),[k,E]=a.useState(!1),[O,M]=a.useState(""),[B,z]=a.useState(null),T=a.useRef(null),I=a.useRef(null),R=u===1,L=u===void 0||n.length<u||R;let P;if(e[0]!==n){P=new Map;for(const Ie of n){const Re=`${Ie.providerID}:${Ie.modelID}`;P.set(Re,(P.get(Re)||0)+1)}e[0]=n,e[1]=P}else P=e[1];const G=P;let X;e[2]!==n?(X=Ie=>n.filter(Ke=>Ke.providerID===Ie.providerID&&Ke.modelID===Ie.modelID).findIndex(Ke=>Ke.instanceId===Ie.instanceId)+1,e[2]=n,e[3]=X):X=e[3];const V=X;let te,Z;e[4]!==g||e[5]!==k?(te=()=>{if(!k||!I.current)return;const Ie=I.current.getBoundingClientRect();if(g==="bottom"){const gt=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-Ie.bottom-16-112;z(Math.max(160,Math.min(320,gt)));return}let Re=I.current.parentElement;for(;Re&&!(Re.getAttribute("role")==="dialog"||Re.hasAttribute("data-scroll-shadow"));){const ct=getComputedStyle(Re);if(ct.overflow==="auto"||ct.overflow==="hidden"||ct.overflowY==="auto"||ct.overflowY==="hidden")break;Re=Re.parentElement}const Ke=Re?Re.getBoundingClientRect().top:0,nt=Ie.top-Ke-16;z(Math.max(150,Math.min(300,nt)))},Z=[g,k],e[4]=g,e[5]=k,e[6]=te,e[7]=Z):(te=e[6],Z=e[7]),a.useEffect(te,Z);let de,Fe;e[8]!==L||e[9]!==k?(de=()=>{!L&&k&&(E(!1),M(""))},Fe=[L,k],e[8]=L,e[9]=k,e[10]=de,e[11]=Fe):(de=e[10],Fe=e[11]),a.useEffect(de,Fe);let se,Q;e[12]!==k?(se=()=>{if(!k)return;const Ie=Re=>{T.current&&!T.current.contains(Re.target)&&(E(!1),M(""))};return document.addEventListener("mousedown",Ie),()=>document.removeEventListener("mousedown",Ie)},Q=[k],e[12]=k,e[13]=se,e[14]=Q):(se=e[13],Q=e[14]),a.useEffect(se,Q);let Me;e[15]!==R||e[16]!==r||e[17]!==i||e[18]!==n.length?(Me=Ie=>{const Re={providerID:Ie.providerID,modelID:Ie.modelID,displayName:Ie.model.name||Ie.modelID,instanceId:ii()};R&&n.length>0&&i?i(0,Re):r(Re),R&&(E(!1),M(""))},e[15]=R,e[16]=r,e[17]=i,e[18]=n.length,e[19]=Me):Me=e[19];const xe=Me;let W;e[20]!==m?(W=m("multirun.modelMultiSelect.search.placeholder"),e[20]=m,e[21]=W):W=e[21];let J;e[22]!==m?(J=m("multirun.modelMultiSelect.search.noResults"),e[22]=m,e[23]=J):J=e[23];let ne;e[24]!==m?(ne=m("multirun.modelMultiSelect.sections.favorites"),e[24]=m,e[25]=ne):ne=e[25];let oe;e[26]!==m?(oe=m("multirun.modelMultiSelect.sections.recent"),e[26]=m,e[27]=oe):oe=e[27];let ue;e[28]!==m?(ue=m("multirun.modelMultiSelect.keyboard.hint"),e[28]=m,e[29]=ue):ue=e[29];let Ae;e[30]!==m?(Ae=m("settings.agents.modelSelector.actions.favorite"),e[30]=m,e[31]=Ae):Ae=e[31];let we;e[32]!==m?(we=m("settings.agents.modelSelector.actions.unfavorite"),e[32]=m,e[33]=we):we=e[33];let Se;e[34]!==m?(Se=m("chat.modelControls.capabilities"),e[34]=m,e[35]=Se):Se=e[35];let Le;e[36]!==m?(Le=m("chat.modelControls.capability.toolCalling"),e[36]=m,e[37]=Le):Le=e[37];let Ue;e[38]!==m?(Ue=m("chat.modelControls.capability.reasoning"),e[38]=m,e[39]=Ue):Ue=e[39];let be;e[40]!==m?(be=m("chat.modelControls.input"),e[40]=m,e[41]=be):be=e[41];let q;e[42]!==m?(q=m("chat.modelControls.output"),e[42]=m,e[43]=q):q=e[43];let Ne;e[44]!==m?(Ne=m("chat.modelControls.costPerMillion"),e[44]=m,e[45]=Ne):Ne=e[45];let je;e[46]!==W||e[47]!==J||e[48]!==ne||e[49]!==oe||e[50]!==ue||e[51]!==Ae||e[52]!==we||e[53]!==Se||e[54]!==Le||e[55]!==Ue||e[56]!==be||e[57]!==q||e[58]!==Ne?(je={searchPlaceholder:W,noResults:J,favorites:ne,recent:oe,keyboardHint:ue,favorite:Ae,unfavorite:we,capabilities:Se,capabilityToolCalling:Le,capabilityReasoning:Ue,input:be,output:q,costPerMillion:Ne},e[46]=W,e[47]=J,e[48]=ne,e[49]=oe,e[50]=ue,e[51]=Ae,e[52]=we,e[53]=Se,e[54]=Le,e[55]=Ue,e[56]=be,e[57]=q,e[58]=Ne,e[59]=je):je=e[59];const ve=je;let ie;e[60]!==x?(ie=Pe("relative",x),e[60]=x,e[61]=ie):ie=e[61];const ee=k?"":void 0;let ke;e[62]!==h?(ke=Pe(xa({size:"default"}),"w-fit",h),e[62]=h,e[63]=ke):ke=e[63];const ae=!L;let U;e[64]!==k?(U=()=>{E(!k)},e[64]=k,e[65]=U):U=e[65];let le;e[66]!==b?(le=b??s.jsx(A,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=b,e[67]=le):le=e[67];let _e;e[68]!==l||e[69]!==m?(_e=l??m("multirun.modelMultiSelect.actions.addModel"),e[68]=l,e[69]=m,e[70]=_e):_e=e[70];let De;e[71]!==ee||e[72]!==ke||e[73]!==ae||e[74]!==U||e[75]!==le||e[76]!==_e?(De=s.jsxs("button",{ref:I,type:"button","data-popup-open":ee,className:ke,disabled:ae,onClick:U,children:[le,_e]}),e[71]=ee,e[72]=ke,e[73]=ae,e[74]=U,e[75]=le,e[76]=_e,e[77]=De):De=e[77];let ce;e[78]!==B||e[79]!==L||e[80]!==p||e[81]!==g||e[82]!==N||e[83]!==xe||e[84]!==D||e[85]!==w||e[86]!==k||e[87]!==ve||e[88]!==G||e[89]!==C||e[90]!==F||e[91]!==y||e[92]!==v||e[93]!==O||e[94]!==j?(ce=k?s.jsx("div",{className:Pe("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",g==="top"?"bottom-full mb-1":"top-full mt-1",p),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(Xp,{providers:y,providerOrder:F,favoriteModels:N,recentModels:v,modelsMetadata:C,hiddenModels:D,searchQuery:O,onSearchQueryChange:M,onSelect:xe,labels:ve,selectionCount:Ie=>G.get(`${Ie.providerID}:${Ie.modelID}`)||0,disabled:!L,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:B?`${B}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:k,isFavorite:Ie=>w(Ie.providerID,Ie.modelID),onToggleFavorite:Ie=>j(Ie.providerID,Ie.modelID),onEscape:()=>{E(!1),M("")}})}):null,e[78]=B,e[79]=L,e[80]=p,e[81]=g,e[82]=N,e[83]=xe,e[84]=D,e[85]=w,e[86]=k,e[87]=ve,e[88]=G,e[89]=C,e[90]=F,e[91]=y,e[92]=v,e[93]=O,e[94]=j,e[95]=ce):ce=e[95];let he;e[96]!==ie||e[97]!==De||e[98]!==ce?(he=s.jsxs("div",{className:ie,ref:T,children:[De,ce]}),e[96]=ie,e[97]=De,e[98]=ce,e[99]=he):he=e[99];let me;e[100]!==V||e[101]!==G||e[102]!==o||e[103]!==i||e[104]!==y||e[105]!==n||e[106]!==S||e[107]!==m?(me=S&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((Ie,Re)=>{const Ke=`${Ie.providerID}:${Ie.modelID}`,nt=G.get(Ke)||1,ct=V(Ie),gt=y.find(yt=>yt.id===Ie.providerID)?.models?.find(yt=>yt.id===Ie.modelID),ht=gt?.variants?Object.keys(gt.variants):[],wt=ht.length>0,bt=Ie.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(_k,{model:Ie,instanceIndex:ct,totalSameModel:nt,onRemove:()=>o(Re)}),wt&&s.jsxs(xn,{value:bt,onValueChange:yt=>{if(!i)return;i(Re,{...Ie,variant:yt==="__default__"?void 0:yt})},children:[s.jsxs(bn,{size:"sm",className:"gap-1.5",children:[s.jsx(A,{name:"brain-ai-3",className:Pe("h-3.5 w-3.5 flex-shrink-0",bt==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(rn,{placeholder:m("multirun.modelMultiSelect.variant.placeholder"),children:yt=>yt==="__default__"?m("multirun.modelMultiSelect.variant.default"):yt})]}),s.jsxs(yn,{fitContent:!0,children:[s.jsx(ys,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:m("multirun.modelMultiSelect.variant.default")}),ht.map(Gk)]})]})]},Ie.instanceId)})}),e[100]=V,e[101]=G,e[102]=o,e[103]=i,e[104]=y,e[105]=n,e[106]=S,e[107]=m,e[108]=me):me=e[108];let $;e[109]!==he||e[110]!==me?($=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[he,me]}),e[109]=he,e[110]=me,e[111]=$):$=e[111];let _;e[112]!==u||e[113]!==c||e[114]!==n.length||e[115]!==m?(_=c!==void 0&&n.length<c&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:u!==void 0?m("multirun.modelMultiSelect.validation.minToMax",{min:c,max:u}):m("multirun.modelMultiSelect.validation.minOnly",{min:c})}),e[112]=u,e[113]=c,e[114]=n.length,e[115]=m,e[116]=_):_=e[116];let ge;return e[117]!==$||e[118]!==_?(ge=s.jsxs("div",{className:"space-y-2",children:[$,_]}),e[117]=$,e[118]=_,e[119]=ge):ge=e[119],ge};function zk(t){return t.providers}function Vk(t){return t.modelsMetadata}function Wk(t){return t.toggleFavoriteModel}function Uk(t){return t.isFavoriteModel}function Hk(t){return t.hiddenModels}function Kk(t){return t.providerOrder}function Gk(t){return s.jsx(ys,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const qk=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
|
|
195
|
+
|
|
196
|
+
--- RESULT ${n+1}: ${r} ---
|
|
197
|
+
${e.trim()}
|
|
198
|
+
--- END RESULT ${n+1} ---`},lu=(t,e)=>Je.getState().getWorktreeMetadata(t)?.projectDirectory??e,Yk=async t=>{const e=t.directory??void 0,n=Zp(t.session.id,e);if(n.length===0&&t.directory){const o=(await Fn.withDirectory(t.directory,()=>Fn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=o.length-1;i>=0;i-=1){const c=o[i];if(c.info?.role==="assistant")return Bc(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return Bc(eg(o.id,e)).trim()}return""};function Qk({session:t,open:e,onOpenChange:n}){const{t:r}=ft(),o=Jp(),i=gn(R=>R.activeSessions),c=gn(R=>R.archivedSessions),l=rs(R=>R.providers),d=rs(R=>R.currentProviderId),u=rs(R=>R.currentModelId),h=rs(R=>R.currentAgentName),[f,p]=a.useState(d??""),[x,b]=a.useState(u??""),[S,g]=a.useState(()=>d&&u?[{providerID:d,modelID:u,instanceId:ii()}]:[]),[m,y]=a.useState(""),[C,j]=a.useState(h??""),[w,N]=a.useState([]),[v,D]=a.useState(!1),F=a.useMemo(()=>Hi(t.title),[t.title]),k=a.useMemo(()=>{const R=new Map;for(const L of o)R.set(L.id,L);for(const L of i)R.set(L.id,L);for(const L of c)R.set(L.id,L);return t.id&&R.set(t.id,t),Array.from(R.values())},[i,c,o,t]);a.useEffect(()=>{if(!e||!F)return;const R=Je.getState().getDirectoryForSession(t.id),L=lu(t.id,R),P=k.map(G=>{const X=Hi(G.title);if(!X||X.groupSlug!==F.groupSlug||X.fusion||(X.runGroup??null)!==(F.runGroup??null))return null;const V=Je.getState().getDirectoryForSession(G.id)??Bn(G),te=lu(G.id,V);return L&&te&&L!==te?null:{session:G,directory:V,projectDirectory:te}}).filter(G=>G!==null).sort((G,X)=>(G.session.time?.created??0)-(X.session.time?.created??0));N(P)},[k,e,F,t.id]);const O=l.find(R=>R.id===f)?.models.find(R=>R.id===x),M=O?.variants?Object.keys(O.variants):[],B=!!(F&&f&&x&&w.length>0&&!v),z=a.useCallback(R=>{g([R]),p(R.providerID),b(R.modelID),y("")},[]),T=S[0]?.displayName||S[0]?.modelID||r("multirun.fusion.model.placeholder"),I=async()=>{if(!(!F||!f||!x)){D(!0);try{const R=await Promise.all(w.map(Z=>Yk(Z))),L=w.map((Z,de)=>({source:Z,text:R[de]??""})).filter(Z=>Z.text.trim().length>0);if(L.length===0){fe.error(r("multirun.fusion.toast.noOutputs"));return}const P=w[0]?.projectDirectory??w[0]?.directory??null,G=Tk(F.groupSlug,f,x,F.runGroup),[X,V]=await Promise.all([To("session.fusion.visible"),To("session.fusion.instructions")]),te=await Je.getState().createSession(G,P,null);if(!te)throw new Error("Failed to create fusion session");Je.getState().setCurrentSession(te.id,P),n(!1),await Fn.sendMessage({id:te.id,providerID:f,modelID:x,variant:m||void 0,agent:C||void 0,text:X,additionalParts:[{text:V,synthetic:!0},...L.map((Z,de)=>({text:qk(Z.source,Z.text,de),synthetic:!0})),{text:`
|
|
199
|
+
|
|
200
|
+
--- FUSION INPUTS END ---
|
|
201
|
+
Now write the final fused answer.`,synthetic:!0}],directory:P??Fn.getDirectory()})}catch(R){console.error("[MultiRunFusion] Failed to start fusion",R),fe.error(r("multirun.fusion.toast.failed"))}finally{D(!1)}}};return s.jsx(Ps,{open:e,onOpenChange:n,children:s.jsxs(Is,{className:"max-w-xl overflow-visible",children:[s.jsxs(Us,{children:[s.jsx(Ls,{children:r("multirun.fusion.title")}),s.jsx(Hs,{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(Vm,{selectedModels:S,onAdd:z,onUpdate:(R,L)=>z(L),onRemove:()=>{g([]),p(""),b(""),y("")},maxModels:1,addButtonLabel:T,showChips:!1,addButtonClassName:"w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:f?s.jsx(li,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(xn,{value:m||"__default__",onValueChange:R=>y(R==="__default__"?"":R),children:[s.jsxs(bn,{size:"lg",className:"w-fit",children:[s.jsx(A,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(rn,{children:R=>R==="__default__"?r("multirun.modelMultiSelect.variant.default"):R})]}),s.jsxs(yn,{fitContent:!0,portalToBody:!0,children:[s.jsx(ys,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map(R=>s.jsx(ys,{value:R,children:R},R))]})]}):null,s.jsx(zm,{value:C,onChange:j,portalToBody:!0})]}),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:w.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:w.map(R=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(li,{providerId:Hi(R.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:R.session.title||R.session.id}),s.jsx("button",{type:"button",onClick:()=>N(L=>L.filter(P=>P.session.id!==R.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(A,{name:"close",className:"h-4 w-4"})})]},R.session.id))})]}),s.jsxs(rr,{children:[s.jsx(He,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(He,{onClick:I,disabled:!B,children:r(v?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function Xk(t){const e=ot.c(7);let n,r,o,i,c;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"}),o=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),c=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=o,e[3]=i,e[4]=c):(n=e[0],r=e[1],o=e[2],i=e[3],c=e[4]);let l;return e[5]!==t?(l=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,o,i,c]}),e[5]=t,e[6]=l):l=e[6],l}const Ml=6,Ri=14,cu=Ml+14+6,ol=new WeakMap,Jk=t=>{if(typeof window>"u")return;const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;ol.get(n)?.();const r=e.getBoundingClientRect().top;let o=3,i=!1,c=null;const l=()=>{i=!0,c!==null&&window.cancelAnimationFrame(c),c=null,ol.delete(n),n.removeEventListener("wheel",l),n.removeEventListener("touchstart",l)},d=()=>{if(i||!e.isConnected||!n.isConnected){l();return}const u=e.getBoundingClientRect().top-r;if(Math.abs(u)>.5&&(n.scrollTop+=u,Zn("ui.sidebar.selection_scroll_anchor_adjustment")),o-=1,o<=0){l();return}c=window.requestAnimationFrame(d)};n.addEventListener("wheel",l,{passive:!0}),n.addEventListener("touchstart",l,{passive:!0}),ol.set(n,l),c=window.requestAnimationFrame(d)},Zk=a.memo(function(e){const n=ot.c(22),{archiveLabel:r,deleteLabel:o,buttonSizeClass:i,iconSizeClass:c,onPointerDown:l,onMouseDown:d,onArchive:u,onDelete:h}=e,f=Ik(),p=f?o:r;let x;n[0]!==u||n[1]!==h||n[2]!==f?(x=N=>{if(f||N.shiftKey){h(N);return}u(N)},n[0]=u,n[1]=h,n[2]=f,n[3]=x):x=n[3];const b=x,S=f?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let g;n[4]!==i||n[5]!==S?(g=Pe("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",S,i),n[4]=i,n[5]=S,n[6]=g):g=n[6];const m=f?"delete-bin":"archive";let y;n[7]!==c||n[8]!==m?(y=s.jsx(A,{name:m,className:c}),n[7]=c,n[8]=m,n[9]=y):y=n[9];let C;n[10]!==b||n[11]!==p||n[12]!==d||n[13]!==l||n[14]!==g||n[15]!==y?(C=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:g,"aria-label":p,onPointerDown:l,onMouseDown:d,onClick:b,onKeyDown:i2,children:y})}),n[10]=b,n[11]=p,n[12]=d,n[13]=l,n[14]=g,n[15]=y,n[16]=C):C=n[16];let j;n[17]!==p?(j=s.jsx(Nt,{side:"left",sideOffset:8,children:p}),n[17]=p,n[18]=j):j=n[18];let w;return n[19]!==C||n[20]!==j?(w=s.jsxs(St,{children:[C,j]}),n[19]=C,n[20]=j,n[21]=w):w=n[21],w});function e2(t){Zn("ui.sidebar_session_node.render");const{t:e}=ft(),{node:n,depth:r=0,groupDirectory:o,projectId:i,archivedBucket:c=!1,pinnedSessionIds:l,expandedParents:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,notifyOnSubtasks:f,editingId:p,setEditingId:x,editTitle:b,setEditTitle:S,handleSaveEdit:g,handleCancelEdit:m,toggleParent:y,handleSessionSelect:C,handleSessionDoubleClick:j,togglePinnedSession:w,handleShareSession:N,copiedSessionId:v,handleCopyShareUrl:D,handleCopySessionId:F,handleUnshareSession:k,openSidebarMenuKey:E,setOpenSidebarMenuKey:O,renamingFolderId:M,getFoldersForScope:B,getSessionFolderId:z,removeSessionFromFolder:T,addSessionToFolder:I,createFolderAndStartRename:R,openContextPanelTab:L,handleDeleteSession:P,handleRestoreSession:G,mobileVariant:X,alwaysShowActions:V,renderSessionNode:te,secondaryMeta:Z,renderContext:de="project",subtreeContainsEditing:Fe,menuOpenSessionId:se,childRenderExtrasFor:Q}=t,Me=a.useMemo(()=>nr(),[]),xe=a.useMemo(()=>ma(),[]),W=a.useContext(tg),J=Me?"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",ne=Me?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",oe=Me,ue=!c&&!X,Ae=Me?ue&&oe?"group-hover:pr-18":ue||oe?"group-hover:pr-14":"group-hover:pr-8":ue?"group-hover:pr-7 group-focus-within:pr-7":"group-hover:pr-3 group-focus-within:pr-3",we=ue?"pr-13":"pr-7",Se=a.useRef(!1),[Le,Ue]=a.useState(!1),be=a.useRef(p);be.current=p;const q=a.useRef(null),Ne=a.useRef(g);Ne.current=g;const[je,ve]=a.useState(b),ie=a.useRef(je);ie.current=je;const ee=a.useRef(null),ke=a.useRef(null),ae=n.session,U=ae,le=ds(a.useCallback(Be=>{if(Z?.projectLabel||!i)return null;const Wt=Be.projects.find(ss=>ss.id===i);return Wt?Wt.label?.trim()||Vr(_t(Wt.path)??Wt.path,null)||Wt.path:null},[i,Z?.projectLabel])),_e=Z?.projectLabel??(le?Zl(le):null),De=Z?.branchLabel??n.worktree?.branch??null,ce=a.useMemo(()=>{if(Me)return null;const Be=n.worktree?.branch?.trim(),Wt=_t(n.worktree?.path??null);return Be&&Wt?yi(Wt,Be):null},[Me,n.worktree]),he=Bf(ce),me=he?`var(--pr-${he.visualState})`:void 0,$=cn(Be=>Be.sessionGroupingMode),_=!!De&&(de==="recent"||$==="flat"),ge=a.useMemo(()=>{if(!he)return null;switch(he.visualState){case"merged":return e("sessions.sidebar.group.pr.status.merged");case"open":return he.canMerge===!0||he.mergeableState==="clean"||he.checks?.state==="success"?e("sessions.sidebar.group.pr.status.readyToMerge"):e("sessions.sidebar.group.pr.status.open");case"blocked":return he.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked");case"draft":return e("sessions.sidebar.group.pr.status.draft");case"closed":return e("sessions.sidebar.group.pr.status.closed");default:return null}},[he,e]),Ie=Je(Be=>Be.currentSessionId===ae.id),Re=_t(ae.directory??null)??_t(o??null),Ke=i??Re??null,nt=_l(Re??void 0,{bootstrap:!1}),ct=pa(),mt=ln(Be=>Be.enabled),gt=ln(a.useCallback(Be=>Be.selectedIds.has(ae.id),[ae.id])),ht=ln(Be=>Be.toggleSelected),wt=ln(Be=>Be.setRange),bt=a.useCallback(Be=>{const Wt=[],ss=hs=>{hs.children.forEach(Ns=>{Wt.push(Ns.session.id),ss(Ns)})};return ss(Be),Wt},[]),yt=a.useCallback(Be=>{const Wt=[],ss=hs=>{hs.children.forEach(Ns=>{Wt.push(Ns.session),ss(Ns)})};return ss(Be),Wt},[]),[Dt,Kt]=a.useState(!1),[Ut,Lt]=a.useState(!0),Bt=`${de}:${c?"archived":"active"}:${ae.id}`,et=bf(a.useCallback(Be=>!!Be.sessionMemoryState.get(sg(ae.id))?.isZombie,[ae.id])),Ht=rf(ae.id),It=em(ae.id),We=ng(ae.id,Re??void 0,{bootstrap:!1}),pt=rg(U),Mt=pt?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e($c[pt.status]),"aria-label":e($c[pt.status]),children:s.jsx(A,{name:"target",className:"h-3 w-3",style:{color:og[pt.status]}})}):null,Et=U.title||e("sessions.sidebar.session.untitled"),tt=n.children.length>0,pe=ig(l,Re,ae.id),Oe=Bt,Te=u?!0:d.has(Oe),it=!!U.parentID,Gt=ag(ae.id)>0&&(!it||f),Ft=U.time?.updated||U.time?.created||Date.now(),ze=yf(Ft),Qe=lg(Ft),st=E===Bt,[at,Ze]=a.useState(!1),At=st||at,Rt=a.useMemo(()=>Hi(U.title)!==null,[U.title]),[Zt,fs]=a.useState(!1),ls=a.useMemo(()=>bt(n).length,[bt,n]),Ot=a.useCallback(async Be=>{const Wt=[];let ss=0;for(const hs of Be)try{if(!Re)throw new Error("Session directory is required for export");await ct.loadCompleteHistory(hs.session.id,Re);const Ns=fl(nt.getState(),hs.session.id).list,Ds=hs.session.title||e("sessions.sidebar.session.export.untitledSubagent"),$s=hs.session.agent,Zs=await Ot(hs.children);ss+=Zs.skipped,Wt.push({title:Ds,agent:$s,records:Ns,children:Zs.children})}catch{ss+=bt(hs).length+1}return{children:Wt,skipped:ss}},[bt,nt,Re,ct,e]),$t=a.useCallback(Be=>{Be<=0||fe.warning(Be===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Be}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Be}))},[e]),Pt=a.useCallback(async Be=>{if(!Re){fe.error(e("sessions.sidebar.session.export.nothingToExport"));return}try{await ct.loadCompleteHistory(ae.id,Re)}catch{fe.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}const Wt=fl(nt.getState(),ae.id).list;if(Wt.length===0){fe.error(e("sessions.sidebar.session.export.nothingToExport"));return}let ss,hs=0;if(Be&&n.children.length>0){const Zs=await Ot(n.children);ss=Zs.children,hs=Zs.skipped}const Ns=Qf(Wt,U.title??null,ss),Ds=Zf(U.title??null),$s=await Jf(Ns,Ds);if($s){fe.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Vb()),onClick:()=>{zb($s).then(Zs=>{Zs||fe.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),$t(hs);return}Xf(Ns,Ds),fe.success(e("sessions.sidebar.session.export.success")),$t(hs)},[Ot,nt,n.children,U.title,ae.id,Re,$t,ct,e]),ms=a.useCallback(async()=>{if(n.children.length>0){Lt(!0),Kt(!0);return}await Pt(!1)},[Pt,n.children.length]),Ks=a.useCallback(()=>{Re&&Cr("desktop_open_session_mini_chat_window",{sessionId:ae.id,directory:Re,apiBaseUrl:Nr(),clientToken:Xi()}).catch(Be=>{console.warn("[session-sidebar] failed to open mini chat window",Be)})},[ae.id,Re]);if(a.useEffect(()=>{if(p!==ae.id)return;const Be=Wt=>{const hs=Wt.target?.closest?.(`[data-session-rename-form="${CSS.escape(ae.id)}"]`);ke.current&&!hs&&Ne.current(ie.current)};return document.addEventListener("mousedown",Be),()=>document.removeEventListener("mousedown",Be)},[p,ae.id]),a.useLayoutEffect(()=>{if(p!==ae.id){ee.current===ae.id&&(ee.current=null);return}ee.current!==ae.id&&(ee.current=ae.id,ve(b))},[p,b,ae.id]),p===ae.id)return s.jsx("div",{style:{paddingLeft:cu+r*Ri},className:"group relative my-0.5 flex items-center rounded-sm py-1 pr-1.5",children:s.jsx("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:s.jsxs("form",{ref:ke,"data-session-rename-form":ae.id,className:"flex w-full items-center gap-2",onSubmit:Be=>{Be.preventDefault(),g(je)},children:[s.jsx("input",{value:je,onChange:Be=>ve(Be.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:Be=>{if(Be.stopPropagation(),Be.key==="Escape"){m();return}}}),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(A,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:m,"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(A,{name:"close",className:"size-4"})})]})})},ae.id);const Yt=Ht?.type??"idle",ws=Yt==="busy"||Yt==="retry",Xs=We.length,ts=ws||!It&&!ws&&Gt&&!Ie,Js=ws?s.jsx(A,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":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")}),or=!V&&tt&&(It||ts||pe),zn=pe&&!It&&!ts,dn=s.jsx(A,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),un=It||ts||zn?s.jsx("span",{style:{left:Ml+r*Ri},className:Pe("pointer-events-none absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center transition-opacity",or?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:It?s.jsx(A,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.movingToWorktree")}):ts?Js:zn?dn:null}):null,wn=tt&&!V&&(It||ts||pe),Bs=tt?s.jsx("span",{role:"button",tabIndex:0,onClick:Be=>{Be.stopPropagation(),Be.currentTarget.blur(),y(Oe)},onKeyDown:Be=>{(Be.key==="Enter"||Be.key===" ")&&(Be.preventDefault(),Be.stopPropagation(),y(Oe))},style:{minWidth:14,minHeight:14,left:Ml+r*Ri},className:Pe("absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 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",wn?"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(Te?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Te?s.jsx(A,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(A,{name:"arrow-right-s",className:"h-3 w-3"})}):null,Fs=et?s.jsx(A,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,fn=Be=>{Be&&Ze(!1),O(Be?Bt:null)},Dn=Be=>{if(!Be&&q.current){const{id:Wt,title:ss}=q.current;q.current=null,x(Wt),S(ss)}},on=Be=>{Ze(Be)},fr=Be=>{Be.preventDefault(),Be.stopPropagation(),O(st?null:Bt)},Pn=Be=>{Be.preventDefault(),Be.stopPropagation()},Pr=Be=>{Be.preventDefault(),Be.stopPropagation()},js=Be=>{Be.preventDefault(),Be.stopPropagation()},re=Be=>{Be.preventDefault(),Be.stopPropagation()},qe=Be=>{Be.preventDefault(),Be.stopPropagation(),O(null),P(ae,{archivedBucket:c})},lt=Be=>{Be.preventDefault(),Be.stopPropagation(),O(null),P(ae,{archivedBucket:c,hardDelete:!0,skipConfirm:!0})},xt=Be=>{Be.preventDefault(),Be.stopPropagation()},qt=Be=>{Be.preventDefault(),Be.stopPropagation()},Tt=Be=>{Be.preventDefault(),Be.stopPropagation(),W?.vscode?.executeCommand("openchamber.openSessionInEditor",ae.id,Et)},Ct=Be=>{if(Se.current){Se.current=!1;return}if(mt){if(Be?.preventDefault(),Be?.stopPropagation(),Be?.shiftKey){const ss=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(Ds=>Ds.getAttribute("data-session-row")).filter(Ds=>typeof Ds=="string"&&Ds.length>0),hs=ln.getState().anchorId,Ns=new Map;Ns.set(ae.id,bt(n)),wt(hs,ae.id,ss,Ke,Ns);return}ht(ae.id,Ke,bt(n));return}Be?.currentTarget&&Jk(Be.currentTarget),C(ae.id,Re)},xs=Be=>{Be.defaultPrevented||Be.target?.closest('button, a, input, [role="menuitem"], [role="menu"]')||Ct(Be)},As=Be=>{(Be.button===2||Be.button===0&&Be.ctrlKey&&!mt)&&(Se.current=!0)},as=Be=>{X&&Be.pointerType==="touch"&&Ue(!0)},Ss=Be=>{X&&Be.pointerType==="touch"&&Ue(!1)},Rs=({Item:Be,Separator:Wt,Sub:ss,SubTrigger:hs,SubContent:Ns})=>s.jsxs(s.Fragment,{children:[s.jsxs(Be,{onClick:()=>{q.current={id:ae.id,title:Et}},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(Be,{onClick:()=>F(ae.id),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyId")]}),s.jsxs(Be,{onClick:()=>Re&&w({directory:Re,sessionId:ae.id}),className:"[&>svg]:mr-1",children:[pe?s.jsx(A,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(A,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(pe?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),U.share?s.jsxs(s.Fragment,{children:[s.jsx(Be,{onClick:()=>{U.share?.url&&D(U.share.url,ae.id)},className:"[&>svg]:mr-1",children:v===ae.id?s.jsxs(s.Fragment,{children:[s.jsx(A,{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(A,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Be,{onClick:()=>k(ae.id),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Be,{onClick:()=>N(U),className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Be,{onClick:()=>{ms()},className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),!it&&!c&&!Me?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Be,{disabled:!Re||ws||It,onClick:()=>{!Re||ws||It||tm({root:U,descendants:yt(n),sourceDirectory:Re,successMessage:e("sessions.sidebar.session.moveToWorktree.success"),failureMessage:e("sessions.sidebar.session.moveToWorktree.failed")})},className:"w-full [&>svg]:mr-1",children:[s.jsx(A,{name:"folder-shared",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(Nt,{side:"right",className:"max-w-72",children:e(It?"sessions.sidebar.session.moveToWorktree.tooltipMoving":ws?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,Rt?s.jsxs(Be,{onClick:()=>fs(!0),className:"[&>svg]:mr-1",children:[s.jsx(Xk,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Re&&!c?(()=>{const Ds=[],$s=zt=>{const Xt=_t(zt??null);Xt&&!Ds.includes(Xt)&&Ds.push(Xt)};if(i&&!Me){const zt=ds.getState().projects.find(mn=>mn.id===i),Xt=_t(zt?.path??null);$s(Xt),Xt&&(Je.getState().availableWorktreesByProject.get(Xt)??[]).forEach(mn=>$s(mn.path))}$s(Re);const Zs=Ds.flatMap(zt=>B(zt).map(Xt=>({scope:zt,folder:Xt}))),an=Zs.find(({scope:zt,folder:Xt})=>z(zt,ae.id)===Xt.id)??null,Vn=Ds[0]??Re;return s.jsxs(s.Fragment,{children:[s.jsx(Wt,{}),s.jsxs(ss,{children:[s.jsxs(hs,{className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ns,{className:"min-w-[180px]",children:[Zs.length===0?s.jsx(Be,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Zs.map(({scope:zt,folder:Xt})=>{const mn=an?.folder.id===Xt.id;return s.jsxs(Be,{onClick:()=>{if(mn){T(zt,ae.id);return}an&&an.scope!==zt&&T(an.scope,ae.id),I(zt,Xt.id,ae.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Xt.name}),mn?s.jsx(A,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Xt.id)}),s.jsx(Wt,{}),s.jsxs(Be,{onClick:()=>{const zt=R(Vn);zt&&(an&&an.scope!==Vn&&T(an.scope,ae.id),I(Vn,zt.id,ae.id))},children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),an?s.jsxs(Be,{onClick:()=>{T(an.scope,ae.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,Me?null:s.jsxs(Be,{disabled:!Re,onClick:()=>{Re&&L(Re,{mode:"chat",dedupeKey:`session:${ae.id}`,label:Et,sessionTitleFallback:Et})},className:"[&>svg]:mr-1",children:[s.jsx(A,{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")})]}),xe?s.jsxs(Be,{disabled:!Re,onClick:Ks,className:"[&>svg]:mr-1",children:[s.jsx(A,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Wt,{}),c?null:s.jsxs(Be,{className:"[&>svg]:mr-1",onClick:()=>P(ae,{archivedBucket:c}),children:[s.jsx(A,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),c?s.jsxs(Be,{className:"[&>svg]:mr-1",onClick:()=>G(ae),children:[s.jsx(A,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.restore")]}):null,s.jsxs(Be,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>P(ae,{archivedBucket:c,hardDelete:!0}),children:[s.jsx(A,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),Os=s.jsx(Ys,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(M||be.current),children:Rs({Item:is,Separator:Ln,Sub:fg,SubTrigger:mg,SubContent:hg})}),ks=s.jsx(Qc,{children:s.jsx(Xc,{className:"app-region-no-drag z-50",children:s.jsx(Jc,{"data-slot":"dropdown-menu-content",finalFocus:()=>!(M||be.current),style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Pe(_c,"min-w-[180px]"),children:Rs({Item:({className:Be,...Wt})=>s.jsx(ob,{className:Pe(cg,Be),...Wt}),Separator:({className:Be,...Wt})=>s.jsx(ib,{className:Pe(dg,Be),...Wt}),Sub:ab,SubTrigger:({className:Be,children:Wt,...ss})=>s.jsxs(lb,{className:Pe(ug,Be),...ss,children:[Wt,s.jsx(A,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:Be,children:Wt,...ss})=>s.jsx(Qc,{children:s.jsx(Xc,{className:"app-region-no-drag z-50",children:s.jsx(Jc,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:Pe(_c,Be),...ss,children:Wt})})})})})})});return s.jsxs(a.Fragment,{children:[s.jsx(FS,{sessionId:ae.id,sessionDirectory:Re??null,sessionTitle:Et,children:s.jsxs(nb,{open:at,onOpenChange:on,onOpenChangeComplete:Dn,children:[s.jsxs(rb,{render:s.jsx("div",{"data-session-row":ae.id,"data-session-scope":Ke??"","data-session-archived":c?"1":"0",onClick:xs,style:{paddingLeft:cu+r*Ri},className:Pe("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5",Ie&&!gt&&"bg-primary/10",gt&&"bg-interactive-selection")}),children:[un,Bs,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:as,onPointerUp:Ss,onPointerCancel:Ss,onMouseDown:As,onClick:Be=>Ct(Be),onDoubleClick:Be=>{Be.stopPropagation(),j(ae.id,Et)},className:Pe("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",Le&&"bg-interactive-hover/70",V?Me?Ae:we:Ae),children:s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden",children:[s.jsx("div",{className:Pe("block min-w-0 flex-1 truncate typography-ui-label font-normal",Ie?"text-primary":Gt?"text-foreground":"text-foreground/80"),children:$i(Et,h)}),V?s.jsxs("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 text-[0.72rem] text-muted-foreground/75",children:[Mt,_?s.jsx(A,{name:"git-branch",className:Pe("h-3 w-3",!me&&"text-muted-foreground/60"),style:me?{color:me}:void 0}):null,Qe]}):Mt||_?s.jsx("div",{className:"relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",children:s.jsxs("span",{className:Pe("inline-flex items-center gap-1 whitespace-nowrap text-right transition-opacity duration-150",At?"opacity-0":ne),children:[Mt,_?s.jsx(A,{name:"git-branch",className:Pe("h-3 w-3",!me&&"text-muted-foreground/60"),style:me?{color:me}:void 0}):null]})}):null,Xs>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(A,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Xs})]}):null]})})}),Me?null:s.jsx(Nt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex min-w-44 flex-col gap-1.5 text-left text-xs",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:Et}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:ze,children:Qe})]}),_e?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"folder",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 truncate",children:_e})]}):null,De?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(A,{name:"git-branch",className:"h-3 w-3 flex-shrink-0",style:me?{color:me}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:De})]}):null,he&&ge?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(A,{name:"git-pull-request",className:"h-3 w-3 flex-shrink-0",style:me?{color:me}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:me?{color:me}:void 0,children:["#",he.number," · ",ge]})]}):null]})})]})}),Fs&&!X?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:Fs}):null,s.jsxs("div",{className:Pe("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",At||V&&!Me?"opacity-100":Pe("opacity-0",J)),children:[ue?s.jsx(Zk,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:V?"h-6 w-6":"h-4 w-4",iconSizeClass:V?"h-3.5 w-3.5":"h-2.5 w-2.5",onPointerDown:js,onMouseDown:re,onArchive:qe,onDelete:lt}):null,oe?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("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",V?"h-6 w-6":"h-4 w-4"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:xt,onMouseDown:qt,onClick:Tt,onKeyDown:Be=>Be.stopPropagation(),children:s.jsx(A,{name:"external-link",className:Pe(V?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),s.jsx(Nt,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(Qs,{open:st,onOpenChange:fn,onOpenChangeComplete:Dn,children:[s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe("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",V?"h-6 w-6 opacity-100":At?"h-4 w-4 opacity-100":Pe("h-4 w-4 opacity-0",J)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Pn,onMouseDown:Pr,onClick:fr,onKeyDown:Be=>Be.stopPropagation(),children:s.jsx(A,{name:"more-2",className:Pe(V?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),Os]})]})]}),ks]})}),tt&&Te?n.children.map(Be=>{const Wt=Q?Q(Be):{subtreeContainsEditing:Fe,menuOpenSessionId:se,nodeStructureKey:""};return te(Be,r+1,Re??o,i,c,void 0,de,Wt)}):null,s.jsx(Ps,{open:Dt,onOpenChange:Kt,children:s.jsxs(Is,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Us,{children:[s.jsx(Ls,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Hs,{children:ls===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:ls}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:ls})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Ut,onChange:Be=>Lt(Be.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(rr,{children:[s.jsx(He,{type:"button",onClick:()=>Kt(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(He,{type:"button",onClick:()=>{Kt(!1),Pt(Ut)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Rt?s.jsx(Qk,{session:U,open:Zt,onOpenChange:fs}):null]},ae.id)}const du=t=>_t(t.session.directory??null),t2=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),s2=t=>{if(!t.openSidebarMenuKey)return null;const e=t.archivedBucket?"archived":"active",n=`${t.renderContext??"project"}:${e}:`;return t.openSidebarMenuKey.startsWith(n)?t.openSidebarMenuKey.slice(n.length):null},Mi=t=>t.menuOpenSessionId??s2(t),Ti=(t,e,n)=>e?n.has(t.node.session.id)?!0:jr(t.node,e):!1,Tl=(t,e,n,r,o)=>{if(t.session.id!==e.session.id)return!0;const i=o(t);if(n.has(i)!==r.has(i)||t.children.length!==e.children.length)return!0;for(let c=0;c<t.children.length;c+=1)if(Tl(t.children[c],e.children[c],n,r,o))return!0;return!1},n2=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return Tl(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${t.renderContext??"project"}:${n}:${o.session.id}`)||Tl(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${e.renderContext??"project"}:${r}:${o.session.id}`)},r2=(t,e)=>{if(t.node.session.id!==e.node.session.id||t.node.session!==e.node.session||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket||(t.renderContext??"project")!==(e.renderContext??"project")||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks||t.nodeStructureKey!==e.nodeStructureKey||du(t.node)!==du(e.node)||!t2(t.secondaryMeta,e.secondaryMeta)||t.pinnedSessionIds!==e.pinnedSessionIds&&Lm(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory)||t.expandedParents!==e.expandedParents&&n2(t,e)||t.editingId!==e.editingId&&(Ti(t,t.editingId,t.subtreeContainsEditing)||Ti(e,e.editingId,e.subtreeContainsEditing))||t.editTitle!==e.editTitle&&(Ti(t,t.editingId,t.subtreeContainsEditing)||Ti(e,e.editingId,e.subtreeContainsEditing))||t.copiedSessionId!==e.copiedSessionId&&(jr(t.node,t.copiedSessionId)||jr(e.node,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=Mi(t),r=Mi(e);if(jr(t.node,n)||jr(e.node,r))return!1}if(t.renamingFolderId!==e.renamingFolderId){const n=Mi(t),r=Mi(e);if(jr(t.node,n)||jr(e.node,r))return!1}return t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.handleSaveEdit===e.handleSaveEdit&&t.handleCancelEdit===e.handleCancelEdit&&t.toggleParent===e.toggleParent&&t.handleSessionSelect===e.handleSessionSelect&&t.handleSessionDoubleClick===e.handleSessionDoubleClick&&t.togglePinnedSession===e.togglePinnedSession&&t.handleShareSession===e.handleShareSession&&t.handleCopyShareUrl===e.handleCopyShareUrl&&t.handleCopySessionId===e.handleCopySessionId&&t.handleUnshareSession===e.handleUnshareSession&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.getFoldersForScope===e.getFoldersForScope&&t.getSessionFolderId===e.getSessionFolderId&&t.removeSessionFromFolder===e.removeSessionFromFolder&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.openContextPanelTab===e.openContextPanelTab&&t.handleDeleteSession===e.handleDeleteSession&&t.handleRestoreSession===e.handleRestoreSession&&t.renderSessionNode===e.renderSessionNode},o2=a.memo(e2,r2);function i2(t){return t.stopPropagation()}function a2(t){const e=ot.c(71),{t:n}=ft(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:l}=t;let d,u,h,f,p,x,b,S,g,m;if(e[0]!==o||e[1]!==n||e[2]!==r){const L=n("sessions.sidebar.session.untitled");f=Ps,g=!!r,e[13]!==o?(m=G=>{G||o(null)},e[13]=o,e[14]=m):m=e[14],h=Is,b=!1,S="max-w-sm gap-5",u=Us;let P;e[15]!==n||e[16]!==r?.archivedBucket?(P=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=P):P=e[17],e[18]!==P?(x=s.jsx(Ls,{children:P}),e[18]=P,e[19]=x):x=e[19],d=Hs,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||L,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||L,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||L,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||L,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||L}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||L}),e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=u,e[5]=h,e[6]=f,e[7]=p,e[8]=x,e[9]=b,e[10]=S,e[11]=g,e[12]=m}else d=e[3],u=e[4],h=e[5],f=e[6],p=e[7],x=e[8],b=e[9],S=e[10],g=e[11],m=e[12];let y;e[20]!==d||e[21]!==p?(y=s.jsx(d,{children:p}),e[20]=d,e[21]=p,e[22]=y):y=e[22];let C;e[23]!==u||e[24]!==x||e[25]!==y?(C=s.jsxs(u,{children:[x,y]}),e[23]=u,e[24]=x,e[25]=y,e[26]=C):C=e[26];let j;e[27]!==c||e[28]!==i?(j=()=>c(!i),e[27]=c,e[28]=i,e[29]=j):j=e[29];const w=!i;let N;e[30]!==i?(N=i?s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=N):N=e[31];let v;e[32]!==n?(v=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=v):v=e[33];let D;e[34]!==N||e[35]!==v||e[36]!==j||e[37]!==w?(D=s.jsxs("button",{type:"button",onClick:j,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":w,children:[N,v]}),e[34]=N,e[35]=v,e[36]=j,e[37]=w,e[38]=D):D=e[38];let F;e[39]!==o?(F=()=>o(null),e[39]=o,e[40]=F):F=e[40];let k;e[41]!==n?(k=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=k):k=e[42];let E;e[43]!==F||e[44]!==k?(E=s.jsx("button",{type:"button",onClick:F,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:k}),e[43]=F,e[44]=k,e[45]=E):E=e[45];let O;e[46]!==l?(O=()=>{l()},e[46]=l,e[47]=O):O=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 B;e[51]!==O||e[52]!==M?(B=s.jsx("button",{type:"button",onClick:O,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]=O,e[52]=M,e[53]=B):B=e[53];let z;e[54]!==E||e[55]!==B?(z=s.jsxs("div",{className:"flex items-center gap-2",children:[E,B]}),e[54]=E,e[55]=B,e[56]=z):z=e[56];let T;e[57]!==D||e[58]!==z?(T=s.jsxs(rr,{className:"w-full sm:items-center sm:justify-between",children:[D,z]}),e[57]=D,e[58]=z,e[59]=T):T=e[59];let I;e[60]!==h||e[61]!==b||e[62]!==T||e[63]!==S||e[64]!==C?(I=s.jsxs(h,{showCloseButton:b,className:S,children:[C,T]}),e[60]=h,e[61]=b,e[62]=T,e[63]=S,e[64]=C,e[65]=I):I=e[65];let R;return e[66]!==f||e[67]!==I||e[68]!==g||e[69]!==m?(R=s.jsx(f,{open:g,onOpenChange:m,children:I}),e[66]=f,e[67]=I,e[68]=g,e[69]=m,e[70]=R):R=e[70],R}function l2(t){const e=ot.c(57),{t:n}=ft(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:l}=t,d=r?.archivedBucket===!0,u=r?.sessionCount??0;let h;e[0]!==d||e[1]!==u||e[2]!==n?(h=n(d?u===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":u===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=u,e[2]=n,e[3]=h):h=e[3];const f=h;let p;e[4]!==d||e[5]!==u||e[6]!==n?(p=d?u===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:u}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:u}):u===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:u}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:u}),e[4]=d,e[5]=u,e[6]=n,e[7]=p):p=e[7];const x=p,b=!!r;let S;e[8]!==o?(S=R=>{R||o(null)},e[8]=o,e[9]=S):S=e[9];let g;e[10]!==f?(g=s.jsx(Ls,{children:f}),e[10]=f,e[11]=g):g=e[11];let m;e[12]!==x?(m=s.jsx(Hs,{children:x}),e[12]=x,e[13]=m):m=e[13];let y;e[14]!==g||e[15]!==m?(y=s.jsxs(Us,{children:[g,m]}),e[14]=g,e[15]=m,e[16]=y):y=e[16];let C;e[17]!==c||e[18]!==i?(C=()=>c(!i),e[17]=c,e[18]=i,e[19]=C):C=e[19];const j=!i;let w;e[20]!==i?(w=i?s.jsx(A,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(A,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=w):w=e[21];let N;e[22]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=N):N=e[23];let v;e[24]!==N||e[25]!==C||e[26]!==j||e[27]!==w?(v=s.jsxs("button",{type:"button",onClick:C,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":j,children:[w,N]}),e[24]=N,e[25]=C,e[26]=j,e[27]=w,e[28]=v):v=e[28];let D;e[29]!==o?(D=()=>o(null),e[29]=o,e[30]=D):D=e[30];let F;e[31]!==n?(F=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=F):F=e[32];let k;e[33]!==D||e[34]!==F?(k=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:F}),e[33]=D,e[34]=F,e[35]=k):k=e[35];let E;e[36]!==l?(E=()=>{l()},e[36]=l,e[37]=E):E=e[37];let O;e[38]!==d||e[39]!==n?(O=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=O):O=e[40];let M;e[41]!==E||e[42]!==O?(M=s.jsx("button",{type:"button",onClick:E,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:O}),e[41]=E,e[42]=O,e[43]=M):M=e[43];let B;e[44]!==k||e[45]!==M?(B=s.jsxs("div",{className:"flex items-center gap-2",children:[k,M]}),e[44]=k,e[45]=M,e[46]=B):B=e[46];let z;e[47]!==v||e[48]!==B?(z=s.jsxs(rr,{className:"w-full sm:items-center sm:justify-between",children:[v,B]}),e[47]=v,e[48]=B,e[49]=z):z=e[49];let T;e[50]!==z||e[51]!==y?(T=s.jsxs(Is,{showCloseButton:!1,className:"max-w-sm gap-5",children:[y,z]}),e[50]=z,e[51]=y,e[52]=T):T=e[52];let I;return e[53]!==b||e[54]!==T||e[55]!==S?(I=s.jsx(Ps,{open:b,onOpenChange:S,children:T}),e[53]=b,e[54]=T,e[55]=S,e[56]=I):I=e[56],I}function c2(t){const e=ot.c(36),{t:n}=ft(),{value:r,setValue:o,onConfirm:i}=t,c=!!r;let l;e[0]!==o?(l=w=>{w||o(null)},e[0]=o,e[1]=l):l=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let u;e[4]!==d?(u=s.jsx(Ls,{children:d}),e[4]=d,e[5]=u):u=e[5];let h;e[6]!==n||e[7]!==r?(h=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]=h):h=e[8];let f;e[9]!==h?(f=s.jsx(Hs,{children:h}),e[9]=h,e[10]=f):f=e[10];let p;e[11]!==u||e[12]!==f?(p=s.jsxs(Us,{children:[u,f]}),e[11]=u,e[12]=f,e[13]=p):p=e[13];let x;e[14]!==o?(x=()=>o(null),e[14]=o,e[15]=x):x=e[15];let b;e[16]!==n?(b=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=b):b=e[17];let S;e[18]!==x||e[19]!==b?(S=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:b}),e[18]=x,e[19]=b,e[20]=S):S=e[20];let g;e[21]!==n?(g=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=g):g=e[22];let m;e[23]!==i||e[24]!==g?(m=s.jsx("button",{type:"button",onClick:i,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:g}),e[23]=i,e[24]=g,e[25]=m):m=e[25];let y;e[26]!==m||e[27]!==S?(y=s.jsxs(rr,{children:[S,m]}),e[26]=m,e[27]=S,e[28]=y):y=e[28];let C;e[29]!==y||e[30]!==p?(C=s.jsxs(Is,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,y]}),e[29]=y,e[30]=p,e[31]=C):C=e[31];let j;return e[32]!==c||e[33]!==l||e[34]!==C?(j=s.jsx(Ps,{open:c,onOpenChange:l,children:C}),e[32]=c,e[33]=l,e[34]=C,e[35]=j):j=e[35],j}const d2=t=>{const e=ot.c(51),{selectedCount:n,scopeKey:r,scopeFolders:o,archivedBucket:i,onMoveToFolder:c,onCreateFolderAndMove:l,onRemoveFromFolder:d,canRemoveFromFolder:u,onRestore:h,onDelete:f,onDone:p}=t,{t:x}=ft(),b=!!r&&!i;let S;e[0]!==i||e[1]!==x?(S=x(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=x,e[2]=S):S=e[2];const g=S;let m;e[3]!==n||e[4]!==x?(m=x("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=x,e[5]=m):m=e[5];let y;e[6]!==m?(y=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:m}),e[6]=m,e[7]=y):y=e[7];let C;e[8]!==b||e[9]!==u||e[10]!==l||e[11]!==c||e[12]!==d||e[13]!==o||e[14]!==x?(C=b?s.jsxs(Qs,{children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(qs,{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":x("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(A,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Nt,{side:"top",sideOffset:4,children:s.jsx("p",{children:x("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Ys,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(is,{disabled:!0,className:"text-muted-foreground",children:x("sessions.sidebar.folders.none")}):o.map(R=>s.jsx(is,{onClick:()=>c(R.id),children:s.jsx("span",{className:"flex-1 truncate",children:R.name})},R.id)),s.jsx(Ln,{}),s.jsxs(is,{onClick:l,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"}),x("sessions.sidebar.folders.newFolderEllipsis")]}),u?s.jsxs(is,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(A,{name:"close",className:"mr-1 h-4 w-4"}),x("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=b,e[9]=u,e[10]=l,e[11]=c,e[12]=d,e[13]=o,e[14]=x,e[15]=C):C=e[15];let j;e[16]!==i||e[17]!==h||e[18]!==x?(j=i?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,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":x("sessions.sidebar.bulkActions.restore"),children:s.jsx(A,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(Nt,{side:"top",sideOffset:4,children:s.jsx("p",{children:x("sessions.sidebar.bulkActions.restore")})})]}):null,e[16]=i,e[17]=h,e[18]=x,e[19]=j):j=e[19];let w;e[20]===Symbol.for("react.memo_cache_sentinel")?(w=Pe("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[20]=w):w=e[20];let N;e[21]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(A,{name:"delete-bin",className:"h-4 w-4"}),e[21]=N):N=e[21];let v;e[22]!==g||e[23]!==f?(v=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:w,"aria-label":g,children:N})}),e[22]=g,e[23]=f,e[24]=v):v=e[24];let D;e[25]!==g?(D=s.jsx(Nt,{side:"top",sideOffset:4,children:s.jsx("p",{children:g})}),e[25]=g,e[26]=D):D=e[26];let F;e[27]!==v||e[28]!==D?(F=s.jsxs(St,{children:[v,D]}),e[27]=v,e[28]=D,e[29]=F):F=e[29];let k;e[30]!==x?(k=x("sessions.sidebar.header.actions.exitSelection"),e[30]=x,e[31]=k):k=e[31];let E;e[32]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(A,{name:"close",className:"h-4 w-4"}),e[32]=E):E=e[32];let O;e[33]!==p||e[34]!==k?(O=s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:p,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":k,children:E})}),e[33]=p,e[34]=k,e[35]=O):O=e[35];let M;e[36]!==x?(M=x("sessions.sidebar.header.actions.exitSelection"),e[36]=x,e[37]=M):M=e[37];let B;e[38]!==M?(B=s.jsx(Nt,{side:"top",sideOffset:4,children:s.jsx("p",{children:M})}),e[38]=M,e[39]=B):B=e[39];let z;e[40]!==O||e[41]!==B?(z=s.jsxs(St,{children:[O,B]}),e[40]=O,e[41]=B,e[42]=z):z=e[42];let T;e[43]!==F||e[44]!==z||e[45]!==C||e[46]!==j?(T=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[C,j,F,z]}),e[43]=F,e[44]=z,e[45]=C,e[46]=j,e[47]=T):T=e[47];let I;return e[48]!==T||e[49]!==y?(I=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[y,T]}),e[48]=T,e[49]=y,e[50]=I):I=e[50],I},u2=t=>{const{t:e}=ft(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:o,folderScopesByProject:i,addSessionsToFolder:c,removeSessionsFromFolders:l,createFolderAndStartRename:d,archiveSessions:u,unarchiveSessions:h,deleteSessions:f,setBulkDeleteConfirm:p}=t,x=ln(R=>R.enabled),b=ln(R=>R.selectedIds.size),S=b>0,g=ln(R=>R.selectedIds),m=ln(R=>R.scopeKey),y=a.useCallback(()=>{ln.getState().toggleMode()},[]),C=a.useCallback(()=>{ln.getState().disable()},[]),j=a.useMemo(()=>{if(!S||typeof document>"u")return!1;let R=!1,L=!1;for(const P of g){const G=document.querySelectorAll(`[data-session-row="${CSS.escape(P)}"]`);for(const X of G)X.getAttribute("data-session-archived")==="1"?L=!0:R=!0}return L&&!R},[S,g]),w=a.useMemo(()=>{if(m)return m;if(!S||typeof document>"u")return null;for(const R of g){const P=document.querySelector(`[data-session-row="${CSS.escape(R)}"]`)?.getAttribute("data-session-scope");if(P&&P.length>0)return P}return null},[S,g,m]),N=a.useMemo(()=>{if(!w)return[];const R=i.get(w);return R&&R.length>0?R.map(L=>L.scopeKey):[w]},[w,i]),v=a.useMemo(()=>N.flatMap(R=>o[R]??[]),[o,N]),D=a.useCallback(R=>{for(const L of N)if((o[L]??[]).some(P=>P.id===R))return L;return null},[o,N]),F=a.useMemo(()=>{if(!S)return!1;for(const R of N)for(const L of o[R]??[])for(const P of L.sessionIds)if(g.has(P))return!0;return!1},[o,N,S,g]),k=a.useCallback((R,L)=>{const P=Array.from(g);for(const G of N)G!==R&&l(G,P);c(R,L,P)},[c,l,g,N]),E=a.useCallback(R=>{if(!S)return;const L=D(R);L&&k(L,R)},[S,k,D]),O=a.useCallback(()=>{const R=N[0];if(!R||!S)return;const L=d(R);L&&k(R,L.id)},[d,S,k,N]),M=a.useCallback(()=>{if(!S)return;const R=Array.from(g);for(const L of N)l(L,R)},[l,g,N,S]),B=a.useCallback(async()=>{const R=Array.from(g);if(R.length!==0){if(j){const{deletedIds:L,failedIds:P}=await f(R);L.length>0&&fe.success(L.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:L.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:L.length})),P.length>0&&fe.error(P.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:P.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:P.length}))}else{const{archivedIds:L,failedIds:P}=await u(R);L.length>0&&fe.success(L.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:L.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:L.length})),P.length>0&&fe.error(P.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:P.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:P.length}))}ln.getState().clear()}},[u,j,f,g,e]),z=a.useCallback(()=>{if(!S)return;const R=g.size;if(!r){B();return}p({sessionCount:R,archivedBucket:j})},[j,B,g,r,p,S]),T=a.useCallback(async()=>{if(!S||!j)return;const R=Array.from(g),{restoredIds:L,failedIds:P}=await h(R);L.length>0&&fe.success(L.length===1?e("sessions.sidebar.bulkActions.restoredSingle",{count:L.length}):e("sessions.sidebar.bulkActions.restoredPlural",{count:L.length})),P.length>0&&fe.error(P.length===1?e("sessions.sidebar.bulkActions.failedRestoreSingle",{count:P.length}):e("sessions.sidebar.bulkActions.failedRestorePlural",{count:P.length})),ln.getState().clear()},[j,S,g,e,h]),I=a.useCallback(async()=>{p(null),await B()},[B]);return a.useEffect(()=>{if(!x)return;const R=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),L=P=>{if(n)return;const G=P.target;if(G&&(G.tagName==="INPUT"||G.tagName==="TEXTAREA"||G.isContentEditable))return;const X=R?P.metaKey:P.ctrlKey;if(P.key==="Escape"){P.preventDefault(),ln.getState().disable();return}if(X&&P.key==="Backspace"){P.preventDefault(),z();return}if(X&&(P.key==="a"||P.key==="A")){const V=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(V.length===0)return;P.preventDefault();const Z=ln.getState().scopeKey??V[0]?.getAttribute("data-session-scope")??null,de=se=>Z?se.getAttribute("data-session-scope")===Z:!0,Fe=V.filter(de).map(se=>se.getAttribute("data-session-row")).filter(se=>typeof se=="string"&&se.length>0);if(Fe.length===0)return;ln.getState().replaceAll(Fe,Z||null)}};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[z,n,x]),{selectionModeEnabled:x,hasSelection:S,selectedIdsSize:b,bulkScopeIsArchived:j,derivedSelectionScope:w,bulkScopeFolders:v,bulkCanRemoveFromFolder:F,handleToggleSelectionMode:y,handleExitSelectionMode:C,handleBulkMoveToFolder:E,handleBulkCreateFolderAndMove:O,handleBulkRemoveFromFolder:M,handleBulkDelete:z,handleBulkRestore:T,confirmBulkDelete:I}},f2=2880*60*1e3,m2=t=>!!t.parentID,h2=t=>!!t.time?.archived,p2=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},g2=(t,e,n=Date.now())=>{const r=n-f2;return t.filter(o=>h2(o)||m2(o)?!1:e.has(o.id)||p2(o)>=r)};let Ro=null,Mo=null,Ki=null,hi=0,da=null;const zr=new Set,x2=3e4,b2=45e3,Wm=()=>{Ki&&(clearTimeout(Ki),Ki=null)},Um=()=>{if(Mo||zr.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(hi,5)),x2);Mo=setTimeout(()=>{Mo=null,hi+=1,bc()},t)},pi=()=>{Wm(),Ro&&Ro.close(),Ro=null},uu=()=>{Wm(),zr.size!==0&&(Ki=setTimeout(()=>{pi(),Um()},b2))},y2=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},fu=t=>!t||typeof t!="object"?null:t,w2=t=>{if(t.type==="openchamber:event-stream-ready"){hi=0;return}if(t.type==="openchamber:heartbeat")return;if(t.type==="openchamber:session-created"){const d=fu(t.properties),u=typeof d?.sessionId=="string"?d.sessionId:"",h=typeof d?.directory=="string"?d.directory:"";if(!u||!h)return;const f={type:"session-created",sessionId:u,directory:h,createdAt:typeof d?.createdAt=="number"?d.createdAt:Date.now(),promptDispatched:d?.promptDispatched===!0,dispatchedAsCommand:d?.dispatchedAsCommand===!0,...typeof d?.projectId=="string"&&d.projectId.length>0?{projectId:d.projectId}:{}};for(const p of zr)p(f);return}if(t.type!=="openchamber:scheduled-task-ran")return;const e=fu(t.properties),n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",o=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,c=i==="running"||i==="error"?i:"success";if(!n||!r)return;const l={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:o,status:c,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of zr)d(l)},bc=()=>{if(typeof window>"u"||zr.size===0||typeof EventSource!="function"||Ro&&Ro.readyState!==EventSource.CLOSED)return;pi();const t=new EventSource(ha().sse("/api/openchamber/events"));t.onopen=()=>{uu()},t.onmessage=e=>{uu();const n=y2(e.data);n&&w2(n)},t.onerror=()=>{pi(),Um()},Ro=t},v2=()=>{da||typeof window>"u"||(da=Ju(()=>{pi(),hi=0,bc()}))},j2=()=>{da?.(),da=null},Hm=t=>(zr.add(t),v2(),bc(),()=>{zr.delete(t),zr.size===0&&(Mo&&(clearTimeout(Mo),Mo=null),hi=0,pi(),j2())}),mu={selected:0,"active-project":1,expanded:2,visible:3,background:4};function S2(t){const e=new Map,n=(r,o,i)=>{const c=_t(r??null);if(!c)return;const l=e.get(c);l&&mu[l.priority]<=mu[o]||e.set(c,{directory:c,priority:o,reason:i})};for(const r of t.projectSections){const o=!t.collapsedProjects.has(r.project.id);let i="background";r.project.id===t.activeProjectId?i="active-project":o&&(i="expanded"),n(r.project.normalizedPath,i,o?"project-expanded":"known-project");for(const c of r.groups){if(!c.directory||c.isArchivedBucket||c.isMain)continue;const l=o&&!t.collapsedGroups.has(`${r.project.id}:${c.id}`);let d="background";l?d="expanded":o&&(d="visible"),n(c.directory,d,l?"worktree-expanded":"known-worktree")}}return n(t.currentDirectory,"selected","current-directory"),n(t.currentSessionDirectory,"selected","selected-session"),[...e.values()]}const Ei="oc.sessions.projectCollapse",hu="oc.sessions.groupOrder",pu="oc.sessions.groupCollapse",gu="oc.sessions.activeSessionByProject",xu="oc.sessions.expandedParents.v3",k2=(t,e,n)=>{const r=new Set;for(const o of t){const i=_t(o.path)?.toLowerCase();i&&r.add(i)}if(n?.includeWorktrees===!1)return r;for(const o of e.values())for(const i of o){const c=_t(i.path)?.toLowerCase();c&&r.add(c)}return r},N2=(t,e,n)=>{if(t.time?.archived)return!0;const r=_t(Bn(t))?.toLowerCase();return r?e.size===0?n?.allowEmptyDirectorySet??!0:e.has(r):n?.allowUnknownDirectory??!0},C2=5*6e4,A2=new Set,il=[],Kn=t=>{const e=a.useRef(t);return e.current=t,a.useCallback((...n)=>e.current(...n),[])},D2=t=>{const e=ot.c(14),{owner:n,childStores:r,projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:l,currentDirectory:d}=t,u=Je(R2);let h,f;e[0]!==i||e[1]!==r||e[2]!==l||e[3]!==c||e[4]!==d||e[5]!==u||e[6]!==n||e[7]!==o?(h=()=>{r.setBootstrapDemand(n,S2({projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:l,currentDirectory:d,currentSessionDirectory:u}))},f=[i,r,l,c,d,u,n,o],e[0]=i,e[1]=r,e[2]=l,e[3]=c,e[4]=d,e[5]=u,e[6]=n,e[7]=o,e[8]=h,e[9]=f):(h=e[8],f=e[9]),a.useEffect(h,f);let p,x;return e[10]!==r||e[11]!==n?(p=()=>()=>r.clearBootstrapDemand(n),x=[r,n],e[10]=r,e[11]=n,e[12]=p,e[13]=x):(p=e[12],x=e[13]),a.useEffect(p,x),null},P2=t=>{const e=ot.c(17),{directories:n}=t,{t:r}=ft();let o;e[0]!==n?(o=new Set,n.forEach(h=>{const f=_t(h)?.toLowerCase();f&&o.add(f)}),e[0]=n,e[1]=o):o=e[1];const i=o;let c;e[2]!==i?(c=h=>{for(const f of h.statusById.values()){if(f.status.type!=="busy"&&f.status.type!=="retry")continue;const p=_t(f.directory)?.toLowerCase();if(p&&i.has(p))return!0}return!1},e[2]=i,e[3]=c):c=e[3];const l=Ca(c);let d;e[4]!==i?(d=h=>{for(const[f,p]of Object.entries(h.index.project.unseenCount)){if(!p)continue;const x=_t(f)?.toLowerCase();if(x&&i.has(x))return!0}return!1},e[4]=i,e[5]=d):d=e[5];const u=Aa(d);if(l){let h;e[6]!==r?(h=r("sessions.sidebar.session.status.active"),e[6]=r,e[7]=h):h=e[7];let f;return e[8]!==h?(f=s.jsx(A,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":h}),e[8]=h,e[9]=f):f=e[9],f}if(u){let h;e[10]!==r?(h=r("sessions.sidebar.session.status.unread"),e[10]=r,e[11]=h):h=e[11];let f;e[12]!==r?(f=r("sessions.sidebar.session.status.unread"),e[12]=r,e[13]=f):f=e[13];let p;return e[14]!==h||e[15]!==f?(p=s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":h,title:f}),e[14]=h,e[15]=f,e[16]=p):p=e[16],p}return null},I2=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:o=!1,showOnlyMainWorkspace:i=!1})=>{ul("react.session_sidebar_render"),Zn("ui.session_sidebar.render"),Zn(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),Zn(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:c}=ft(),[l,d]=a.useState(!1),[u,h]=a.useState(""),f=a.useRef(null),p=a.useRef(null),[x,b]=a.useState(null),[S,g]=a.useState(""),[m,y]=a.useState(null),[C,j]=a.useState(new Set),w=a.useMemo(()=>jo(),[]),[N,v]=a.useState(new Set),[D,F]=a.useState(new Map),[k,E]=a.useState(new Map),O=Ee(Y=>Y.isNewWorktreeDialogOpen),M=Ee(Y=>Y.setNewWorktreeDialogOpen),[B,z]=a.useState(!1),[T,I]=a.useState(null),[R,L]=a.useState(null),[P,G]=a.useState(""),[X,V]=a.useState(null),[te,Z]=a.useState(null),[de,Fe]=a.useState(null),se=ui(Y=>Y.ids),Q=Na(a.useCallback(Y=>t?Y.rankById:Yl,[t])),Me=Ca(er(Y=>t?[...Y.statusById.keys()].sort():il)),xe=a.useMemo(()=>new Set(Me),[Me]),W=Aa(er(Y=>t?Object.entries(Y.index.session.unseenCount).filter(([,Xe])=>Xe>0).map(([Xe])=>Xe).sort():il)),J=a.useMemo(()=>new Set(W),[W]),ne=ui(Y=>Y.toggle),[oe,ue]=a.useState(()=>{try{const Y=jo().getItem(pu);if(!Y)return new Set;const Xe=JSON.parse(Y);return new Set(Array.isArray(Xe)?Xe.filter(Ye=>typeof Ye=="string"):[])}catch{return new Set}}),[Ae,we]=a.useState(()=>{try{const Y=jo().getItem(hu);if(!Y)return new Map;const Xe=JSON.parse(Y),Ye=new Map;return Object.entries(Xe).forEach(([jt,Jt])=>{Array.isArray(Jt)&&Ye.set(jt,Jt.filter(cs=>typeof cs=="string"))}),Ye}catch{return new Map}}),Se=a.useMemo(()=>{try{const Y=jo().getItem(gu);if(!Y)return new Map;const Xe=JSON.parse(Y),Ye=new Map;return Object.entries(Xe).forEach(([jt,Jt])=>{typeof Jt=="string"&&Jt.length>0&&Ye.set(jt,Jt)}),Ye}catch{return new Map}},[]),Le=a.useCallback(Y=>{try{w.setItem(gu,JSON.stringify(Object.fromEntries(Y.entries())))}catch{}},[w]),[Ue,be]=a.useState(new Map),q=a.useRef(new Map),Ne=a.useRef(0),je=vs(Y=>Y.homeDirectory),ve=vs(Y=>Y.currentDirectory),ie=ds(Y=>Y.projects),ee=ds(Y=>Y.activeProjectId),ke=ds(Y=>Y.removeProject),ae=ds(Y=>Y.setActiveProjectIdOnly),U=ds(Y=>Y.updateProjectMeta),le=ds(Y=>Y.reorderProjects),_e=Ee(Y=>Y.setActiveMainTab),De=Ee(Y=>Y.openContextPanelTab),ce=Ee(Y=>Y.setSettingsDialogOpen),he=Ee(Y=>Y.toggleHelpDialog),me=Ee(Y=>Y.setAboutDialogOpen),$=Ee(Y=>Y.setSessionSwitcherOpen),_=Ee(Y=>Y.setScheduledTasksDialogOpen),ge=Ee(Y=>Y.setArchivePageOpen),Ie=Ee(Y=>Y.setWorktreesPageProjectId),Re=Ee(Y=>Y.openMultiRunLauncher),Ke=Ee(Y=>Y.notifyOnSubtasks),nt=Ee(Y=>Y.showDeletionDialog),ct=Ee(Y=>Y.setShowDeletionDialog),mt=Gl(u,120),gt=a.useMemo(()=>mt.trim().toLowerCase(),[mt]),ht=gt.length>0,wt=kn(Y=>Y.collapsedFolderIds),bt=kn(Y=>Y.foldersMap),yt=kn(Y=>Y.getFoldersForScope),Dt=kn(Y=>Y.createFolder),Kt=kn(Y=>Y.renameFolder),Ut=kn(Y=>Y.deleteFolder),Lt=kn(Y=>Y.addSessionToFolder),Bt=kn(Y=>Y.addSessionsToFolder),et=kn(Y=>Y.removeSessionFromFolder),Ht=kn(Y=>Y.removeSessionsFromFolders),It=kn(Y=>Y.toggleFolderCollapse),We=kn(Y=>Y.getSessionFolderId);Y0({enabled:t,isSessionSearchOpen:l,setIsSessionSearchOpen:d,sessionSearchInputRef:p,sessionSearchContainerRef:f});const pt=ff(t),Mt=pa(),Et=gf(),tt=`session-sidebar:${a.useId()}`,pe=pg(),Oe=a.useMemo(()=>Array.from(pe.values()),[pe]),Te=a.useMemo(()=>nr(),[]),it=gn(Y=>Y.status==="ready"),ut=gn(er(Y=>Y.activeSessions.map(Ba).sort())),Gt=gn(er(Y=>Y.archivedSessions.map(Ba).sort())),Ft=gn.getState(),ze=Ft.activeSessions,Qe=Ft.archivedSessions,st=a.useRef({signature:"",sessions:[]}),at=a.useMemo(()=>new Set(ze.map(Y=>Y.id)),[ze]),Ze=(()=>{const Y=Oe.filter(Ye=>!at.has(Ye.id)),Xe=Y.map(Ba).sort().join(`
|
|
202
|
+
`);return st.current.signature===Xe?st.current.sessions:(st.current={signature:Xe,sessions:Y},Y)})(),At=Je(Y=>Y.setCurrentSession),Rt=Je(Y=>Y.updateSessionTitle),Zt=Je(Y=>Y.shareSession),fs=Je(Y=>Y.unshareSession),ls=Je(Y=>Y.worktreeMetadata),Ot=Je(Y=>Y.availableWorktreesByProject),$t=Je(Y=>Y.openNewSessionDraft),Pt=a.useCallback(Y=>{Ee.getState().closeMainSurfaces(),$t(Y),Te&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[Te,$t]),ms=si(er(Y=>({checkForUpdates:Y.checkForUpdates,available:Y.available,runtimeType:Y.runtimeType,info:Y.info,downloading:Y.downloading,downloaded:Y.downloaded,progress:Y.progress,error:Y.error,downloadUpdate:Y.downloadUpdate,restartToUpdate:Y.restartToUpdate}))),Ks=a.useMemo(()=>k2(ie,Ot,{includeWorktrees:!Te}),[Ot,Te,ie]),Yt=a.useMemo(()=>{const Y=[...ze],Xe=new Set(Y.map(Ye=>Ye.id));return Ze.forEach(Ye=>{Xe.has(Ye.id)||Y.push(Ye)}),Y.filter(Ye=>N2(Ye,Ks,{allowUnknownDirectory:!Te,allowEmptyDirectorySet:!Te}))},[ze,Te,Ks,Ze]),ws=a.useMemo(()=>[...ze,...Qe],[Qe,ze]),Xs=a.useRef(Oe);a.useEffect(()=>{Xs.current=Oe},[Oe]);const An=$n(),ts=a.useMemo(()=>`${An}|${ie.map(Y=>`${Y.id}:${_t(Y.path)??""}`).join("|")}`,[ie,An]),[Js,or]=a.useState(Te?ts:null),[zn,dn]=a.useReducer(Y=>Y+1,0),un=!Te&&Js!==ts,[wn,Bs]=a.useState(new Set),Fs=a.useRef(!1);a.useEffect(()=>{Fs.current||(Fs.current=!0,ea(Xs.current))},[]),a.useEffect(()=>{let Y=!1;return(async()=>{const Ye=An,jt=ds.getState().projects;if(jt.length===0||Te){Y||(Bs(new Set),or(ts));return}const Jt=Je.getState().availableWorktreesByProject,cs=new Map(Jt),Sn=new Set,Vs=3;let Tr=0;const Qn=Array.from({length:Vs},async()=>{for(;;){const br=Tr;if(Tr+=1,br>=jt.length)return;const Cc=jt[br],Fr=_t(Cc.path);if(Fr)try{const Ea=await hl(async()=>nn.getState().directories.get(Fr)?.isGitRepo??await wf(Fr)?bg({id:Cc.id,path:Fr}):null);if(Ea===null){cs.delete(Fr);continue}if(Y)return;Ea.length===0?cs.delete(Fr):cs.set(Fr,Ea)}catch{Sn.add(Fr)}}});if(await Promise.all(Qn),Y||$n()!==Ye)return;const bo=new Set(jt.map(br=>_t(br.path)).filter(Boolean));for(const br of cs.keys())bo.has(br)||cs.delete(br);const Er=yg(jt,cs),Nc=[...Er.values()].flat();G0(Nc.map(br=>br.path),Date.now()),wg(Er,Jt)||Je.setState({availableWorktrees:Nc,availableWorktreesByProject:Er}),Bs(Sn),or(ts)})(),()=>{Y=!0}},[Te,ts,An,zn]),a.useEffect(()=>{let Y=null,Xe=!1;const Ye=new Set,jt=Hm(Jt=>{Jt.type==="scheduled-task-ran"?Xe=!0:(Ye.add(Jt.directory),dn()),Y&&clearTimeout(Y),Y=setTimeout(()=>{if(Y=null,Xe){Xe=!1,Ye.clear(),ea(Xs.current);return}const cs=[...Ye];Ye.clear(),cs.length>0&&Bi(cs,Xs.current)},500)});return()=>{Y&&clearTimeout(Y),jt()}},[]);const fn=a.useMemo(()=>ur(),[]),{isTablet:Dn}=Dr(),on=e||Dn,{buildGroupSearchText:fr,filterSessionNodesForSearch:Pn,buildGroupedSessions:Pr}=q0({homeDirectory:je,worktreeMetadata:ls,pinnedSessionIds:se,sessionOrderRanks:Q,gitBranches:pt,isVSCode:Te}),{scheduleCollapsedProjectsPersist:js}=tS({isVSCode:Te,safeStorage:w,keys:{sessionExpanded:xu,projectCollapse:Ei,groupOrder:hu,groupCollapse:pu},groupOrderByProject:Ae,collapsedGroups:oe,setExpandedParents:j,setCollapsedProjects:v}),re=a.useMemo(()=>uf(Yt,se,Q),[se,Q,Yt]),qe=a.useMemo(()=>re.map(Y=>Y.id).join("|"),[re]),lt=a.useRef(null),xt=a.useMemo(()=>{const Y=lt.current;if(Y&&Y.signature===qe)return Y.map;const Xe=new Map(re.map((Ye,jt)=>[Ye.id,jt]));return lt.current={signature:qe,map:Xe},Xe},[re,qe]),qt=a.useMemo(()=>{const Y=new Map;return re.forEach(Xe=>{const Ye=Xe.parentID;if(!Ye)return;const jt=Y.get(Ye)??[];jt.push(Xe),Y.set(Ye,jt)}),Y.forEach(Xe=>Xe.sort((Ye,jt)=>Eo(Ye,jt,se,Q))),Y},[re,se,Q]),Tt=a.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:c("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:c("sessions.sidebar.empty.noSessions.description")})]}),[c]),Ct=a.useMemo(()=>ie.find(Y=>Y.id===m)??null,[ie,m]),xs=a.useCallback(Y=>{m&&U(m,{label:Y.label,icon:Y.icon,color:Y.color,iconBackground:Y.iconBackground,defaultModel:Y.defaultModel??null})},[m,U]),As=a.useCallback(()=>{M(!0)},[M]),as=a.useCallback(()=>{const Y=si.getState();if(Y.available&&Y.info){z(!0);return}ms.checkForUpdates().then(()=>{const{available:Xe,error:Ye}=si.getState();if(Ye){fe.error(c("sessions.sidebar.updateCheck.errorTitle"),{description:Ye});return}if(!Xe){fe.success(c("sessions.sidebar.updateCheck.latestVersion"));return}z(!0)})},[c,ms]),Ss=a.useCallback(()=>{e&&$(!1),ce(!0)},[e,$,ce]),Rs=ms.available&&(ms.runtimeType==="desktop"||ms.runtimeType==="web"),Os=Je(Y=>Y.deleteSession),ks=Je(Y=>Y.deleteSessions),Be=Je(Y=>Y.archiveSession),Wt=Je(Y=>Y.archiveSessions),ss=Je(Y=>Y.unarchiveSession),hs=Je(Y=>Y.unarchiveSessions),{copiedSessionId:Ns,handleSessionSelect:Ds,handleSessionDoubleClick:$s,handleSaveEdit:Zs,handleCancelEdit:an,handleShareSession:Vn,handleCopyShareUrl:zt,handleCopySessionId:Xt,handleUnshareSession:mn,handleDeleteSession:In,handleRestoreSession:_s,confirmDeleteSession:ir}=Q0({mobileVariant:e,allowReselect:r,onSessionSelected:n,isSessionSearchOpen:l,sessionSearchQuery:u,setSessionSearchQuery:h,setIsSessionSearchOpen:d,setActiveMainTab:_e,setSessionSwitcherOpen:$,setCurrentSession:At,updateSessionTitle:Rt,shareSession:Zt,unshareSession:fs,deleteSession:Os,deleteSessions:ks,archiveSession:Be,archiveSessions:Wt,unarchiveSession:ss,childrenMap:qt,showDeletionDialog:nt,setDeleteSessionConfirm:V,deleteSessionConfirm:X,setEditingId:b,setEditTitle:g,editingId:x,editTitle:S}),Ir=a.useCallback(()=>{if(!te)return;const{scopeKey:Y,folderId:Xe}=te;Z(null),Ut(Y,Xe)},[te,Ut]),co=a.useCallback(()=>{Gn.requestDirectoryDialog()},[]),Uo=a.useCallback(Y=>{j(Xe=>{const Ye=gg(Xe,Y);try{w.setItem(xu,JSON.stringify(Array.from(Ye)))}catch{}return Ye})},[w]),Rr=a.useCallback((Y,Xe)=>{if(!Y)return null;Xe&&wt.has(Xe)&&It(Xe);const Ye=Dt(Y,c("sessions.sidebar.folder.newFolderName"),Xe);return L(Ye.id),G(Ye.name),Ye},[wt,It,Dt,c]),uo=Kn(Ds),Ur=Kn($s),fo=Kn(Zs),Ho=Kn(an),mr=Kn(Vn),Ko=Kn(zt),vn=Kn(Xt),Wn=Kn(mn),zs=Kn(In),qn=Kn(_s),Hr=Kn(Rr),mo=a.useCallback((Y,Xe)=>{E(Ye=>{const jt=new Map(Ye);return jt.set(Y,Xe+7),jt})},[]),hr=a.useCallback(Y=>{E(Xe=>{if(!Xe.has(Y))return Xe;const Ye=new Map(Xe);return Ye.delete(Y),Ye})},[]),ho=a.useCallback(Y=>{E(Xe=>{let Ye=!1;const jt=new Map(Xe),Jt=`${Y}:`;for(const cs of jt.keys())cs.startsWith(Jt)&&(jt.delete(cs),Ye=!0);return Ye?jt:Xe})},[]),po=a.useRef([]),ar=a.useCallback(()=>{Ne.current=Date.now()+150,E(new Map),ue(()=>{const Y=new Set;return po.current.forEach(Xe=>{Xe.groups.forEach(Ye=>{Ye.isMain||Y.add(`${Xe.project.id}:${Ye.id}`)})}),Y}),v(()=>{const Y=new Set(ie.map(Xe=>Xe.id));try{w.setItem(Ei,JSON.stringify(Array.from(Y)))}catch{}return Te||js(Y),Y})},[ie,Te,w,js]),Go=a.useCallback(()=>{Ne.current=Date.now()+150,E(new Map),ue(new Set),v(()=>{const Y=new Set;try{w.setItem(Ei,JSON.stringify([]))}catch{}return Te||js(Y),Y})},[Te,w,js]),Kr=a.useCallback(Y=>{Ne.current=Date.now()+150,ho(Y),v(Xe=>{const Ye=new Set(Xe);Ye.has(Y)?Ye.delete(Y):Ye.add(Y);try{w.setItem(Ei,JSON.stringify(Array.from(Ye)))}catch{}return Te||js(Ye),Ye})},[Te,ho,w,js]),Ms=a.useMemo(()=>ie.map(Y=>({...Y,normalizedPath:_t(Y.path)})).filter(Y=>!!Y.normalizedPath),[ie]),pr=a.useMemo(()=>Ms.map(Y=>Y.normalizedPath),[Ms]),Yn=a.useMemo(()=>{const Y=new Set(Ms.map(Xe=>Xe.normalizedPath));if(!Te)for(const Xe of Ot.values())for(const Ye of Xe){const jt=_t(Ye.path);jt&&Y.add(jt)}return[...Y].sort()},[Ot,Te,Ms]),H=a.useRef(null);a.useEffect(()=>{const Y=new Set(Yn),Xe=H.current;if(H.current=Y,!Xe){Te&&Yn.length>0&&Bi(Yn,Xs.current);return}const Ye=Yn.filter(jt=>!Xe.has(jt));Ye.length!==0&&Bi(Ye,Xs.current)},[Te,Yn]);const{github:Ge}=_n(),rt=Ar(Y=>Y.status),vt=Ar(Y=>Y.hasChecked),es=xg(t?pr:il),ns=sn(Y=>Y.ensureEntry),os=sn(Y=>Y.setParams),bs=sn(Y=>Y.refreshTargets);iS({enabled:t,normalizedProjects:Ms,gitRepoStatus:es,setProjectRepoStatus:F,setProjectRootBranches:be});const Ts=Je(Y=>Y.isLoading),Gs=a.useMemo(()=>bS(Yt,Ms,Ot,Te,Qe),[Qe,Ot,Te,Ms,Yt]);hS({enabled:t,hasAuthoritativeGlobalSessions:it,sessions:ws});const{getSessionsForProject:Es,getArchivedSessionsForProject:Mr}=uS({ownership:Gs});L0({enabled:t,normalizedProjects:Ms,ownership:Gs,isSessionsLoading:Ts,hasAuthoritativeGlobalSessions:it,isWorktreeTopologyLoading:un,unresolvedWorktreeProjectPaths:wn,foldersMap:bt,createFolder:Dt,addSessionToFolder:Lt});const Gr=a.useRef(!1);ee&&D.has(ee)&&(Gr.current=!!D.get(ee));const hn=cn(Y=>Y.showRecentSection),jn=cn(Y=>Y.showArchivedSessions),Rn=cn(Y=>Y.projectSortOrder),lr=cn(Y=>Y.stickyZoneHeaders),Un=ds(Y=>Y.manualProjectOrder),gr=a.useRef(new Set),qr=a.useRef(new Set),xr=zc(gr.current,C,"project"),go=zc(qr.current,C,"recent");gr.current=xr,qr.current=go;const qo={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:o,showOnlyMainWorkspace:i,t:c,isTablet:Dn,liveSessions:Oe,activeSessionStructure:ut,archivedSessionStructure:Gt,globalActiveSessions:ze,archivedSessions:Qe,projects:ie,activeProjectId:ee,manualProjectOrder:Un,currentDirectory:ve,worktreeMetadata:ls,availableWorktreesByProject:Ot,pinnedSessionIds:se,sessionOrderRanks:Q,foldersMap:bt,collapsedFolderIds:wt,gitBranches:pt,gitRepoStatus:es,githubAuthStatus:rt,githubAuthChecked:vt,updateStore:ms,showRecentSection:hn,showArchivedSessions:jn,projectSortOrder:Rn,projectRepoStatus:D,projectRootBranches:Ue,resolvedWorktreeTopologyKey:Js,unresolvedWorktreeProjectPaths:wn,isSessionSearchOpen:l,sessionSearchQuery:u,editingId:x,editTitle:S,editingProjectDialogId:m,expandedParents:C,collapsedProjects:N,visibleSessionCountByGroup:k,updateDialogOpen:B,openSidebarMenuKey:T,renamingFolderId:R,renameFolderDraft:P,deleteSessionConfirm:X,deleteFolderConfirm:te,bulkDeleteConfirm:de,collapsedGroups:oe},wi=a.useRef(null),vi=wi.current;if(vi){let Y=!1;for(const Xe of Object.keys(qo))Object.is(vi[Xe],qo[Xe])||(Zn(`ui.session_sidebar.source.${Xe}`),Y=!0);Y||Zn("ui.session_sidebar.source.parent_or_context")}wi.current=qo;const Ta=a.useMemo(()=>{const Y=[...Ms];switch(Rn){case"a-z":Y.sort((Xe,Ye)=>{const jt=(Xe.label||Xe.path).toLowerCase(),Jt=(Ye.label||Ye.path).toLowerCase();return jt.localeCompare(Jt)});break;case"z-a":Y.sort((Xe,Ye)=>{const jt=(Xe.label||Xe.path).toLowerCase();return(Ye.label||Ye.path).toLowerCase().localeCompare(jt)});break;case"date-added":Y.sort((Xe,Ye)=>(Ye.addedAt??0)-(Xe.addedAt??0));break;case"recent":Y.sort((Xe,Ye)=>(Ye.lastOpenedAt??0)-(Xe.lastOpenedAt??0));break;case"manual":{const Xe=new Map(Un.map((Ye,jt)=>[Ye,jt]));Y.sort((Ye,jt)=>{const Jt=Xe.get(Ye.id)??1/0,cs=Xe.get(jt.id)??1/0;return Jt-cs});break}}return Y},[Ms,Rn,Un]),{projectSections:K,groupSearchDataByGroup:ye,sectionsForRender:Ce,flatSectionsForRender:Ve,searchMatchCount:dt}=V0({normalizedProjects:Ta,getSessionsForProject:Es,getArchivedSessionsForProject:Mr,availableWorktreesByProject:Ot,projectRepoStatus:D,projectRootBranches:Ue,lastRepoStatus:Gr.current,buildGroupedSessions:Pr,hasSessionSearchQuery:ht,normalizedSessionSearchQuery:gt,filterSessionNodesForSearch:Pn,buildGroupSearchText:fr,foldersMap:bt});po.current=K;const Vt=a.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:c("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:c("sessions.sidebar.empty.noMatches.description")})]}),[c]),{getOrderedGroups:ps}=$0(Ae),Qt=a.useRef(!1);a.useEffect(()=>{if(Qt.current||K.length===0)return;const Y=K.flatMap(Xe=>Xe.groups.filter(Ye=>Ye.isArchivedBucket).map(Ye=>`${Xe.project.id}:${Ye.id}`));Y.length>0&&ue(Xe=>new Set([...Xe,...Y])),Qt.current=!0},[K]);const en=a.useMemo(()=>{const Y=new Map,Xe=new Map;return K.forEach(Ye=>{const jt=Zl(Ye.project.label?.trim()||Vr(Ye.project.normalizedPath,je)||Ye.project.normalizedPath);Ye.groups.forEach(Jt=>{const cs=Jt.branch&&Jt.branch!=="HEAD"&&Jt.branch!==jt?Jt.branch:null,Sn={projectLabel:jt,branchLabel:cs},Vs=Tr=>{Tr.forEach(Qn=>{const bo=Ye.project.normalizedPath.length,Er=Xe.get(Qn.session.id)??-1;bo<Er||(Y.set(Qn.session.id,{node:Qn,projectId:Ye.project.id,groupDirectory:Jt.directory,secondaryMeta:Sn}),Xe.set(Qn.session.id,bo),Qn.children.length>0&&Vs(Qn.children))})};Vs(Jt.sessions)})}),Y},[K,je]),cr=a.useMemo(()=>!hn||Te?[]:g2(Yt,xe).sort((Y,Xe)=>Eo(Y,Xe,se,Q)),[xe,Te,se,Q,Yt,hn]),xo=a.useMemo(()=>{if(Te||!hn)return[];const Y=Ye=>{const jt=en.get(Ye.id),Jt=_t(Ye.directory??null),cs=jt?.node??{session:Ye,children:[],worktree:null},Vs=(ht?Pn([cs],gt):[cs])[0];if(!Vs)return null;const Tr=jt?.secondaryMeta?{projectLabel:jt.secondaryMeta.projectLabel,branchLabel:Te?null:jt.secondaryMeta.branchLabel}:null;return{node:Vs,projectId:jt?.projectId??null,groupDirectory:jt?.groupDirectory??Jt,secondaryMeta:Tr}},Xe=cr.map(Y).filter(Ye=>Ye!==null);return[{key:"active-now",title:c("sessions.sidebar.activity.recentTitle"),items:Xe}]},[Pn,ht,Te,gt,cr,en,hn,c]),Jm=a.useMemo(()=>xo.some(Y=>Y.items.length>0),[xo]),yc=Te&&jn,wc=cn(Y=>Y.sessionGroupingMode)==="by-worktree"&&!Te,Zm=a.useMemo(()=>{const Y=wc?Ce:Ve;return yc?Y:Y.map(Xe=>Xe.groups.some(Ye=>Ye.isArchivedBucket)?{...Xe,groups:Xe.groups.filter(Ye=>!Ye.isArchivedBucket)}:Xe)},[Ve,Ce,yc,wc]),vc=a.useRef(new Set);a.useEffect(()=>{if(!t||!vt||!rt?.connected||!Ge)return;const Y=new Map,Xe=Date.now();K.forEach(Ye=>{N.has(Ye.project.id)||Ye.groups.forEach(jt=>{if(jt.isArchivedBucket||jt.isMain)return;const Jt=_t(jt.directory??null),cs=jt.branch?.trim()||pt.get(Jt||"")?.trim();if(!Jt||!cs)return;const Sn=yi(Jt,cs),Vs=sn.getState().entries[Sn],Tr=!!Vs?.status?.pr,Qn=`${Jt}::${cs}`,bo=Math.max(Vs?.lastRefreshAt??0,Vs?.lastDiscoveryPollAt??0),Er=!!(Vs?.isInitialStatusResolved&&!Tr&&(!vc.current.has(Qn)||Xe-bo>=C2));(!Vs||!Vs.isInitialStatusResolved||Er)&&(Er&&vc.current.add(Qn),Y.has(Sn)||Y.set(Sn,{directory:Jt,branch:cs}))})}),Y.size!==0&&(Y.forEach((Ye,jt)=>{ns(jt),os(jt,{directory:Ye.directory,branch:Ye.branch,remoteName:null,canShow:!0,github:Ge,githubAuthChecked:vt,githubConnected:rt.connected})}),bs([...Y.values()],{silent:!0,markInitialResolved:!0}))},[N,ns,Ge,vt,rt?.connected,t,pt,K,bs,os]);const eh=e?"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",th="h-4.5 w-4.5",sh=yS({enabled:t&&lr,isDesktopShellRuntime:fn,projectSections:K,projectHeaderSentinelRefs:q}),Yo=Kn((Y,Xe=0,Ye,jt,Jt=!1,cs,Sn="project",Vs)=>s.jsx(o2,{node:Y,depth:Xe,groupDirectory:Ye,projectId:jt,archivedBucket:Jt,pinnedSessionIds:se,expandedParents:Sn==="recent"?go:xr,hasSessionSearchQuery:ht,normalizedSessionSearchQuery:gt,notifyOnSubtasks:Ke,editingId:x,setEditingId:b,editTitle:S,setEditTitle:g,handleSaveEdit:fo,handleCancelEdit:Ho,toggleParent:Uo,handleSessionSelect:uo,handleSessionDoubleClick:Ur,togglePinnedSession:ne,handleShareSession:mr,copiedSessionId:Ns,handleCopyShareUrl:Ko,handleCopySessionId:vn,handleUnshareSession:Wn,openSidebarMenuKey:T,setOpenSidebarMenuKey:I,renamingFolderId:R,getFoldersForScope:yt,getSessionFolderId:We,removeSessionFromFolder:et,addSessionToFolder:Lt,createFolderAndStartRename:Hr,openContextPanelTab:De,handleDeleteSession:zs,handleRestoreSession:qn,mobileVariant:e,alwaysShowActions:on,renderSessionNode:Yo,secondaryMeta:cs,renderContext:Sn,subtreeContainsEditing:Vs?.subtreeContainsEditing??A2,menuOpenSessionId:Vs?.menuOpenSessionId??null,nodeStructureKey:Vs?.nodeStructureKey??"",childRenderExtrasFor:Vs?.childRenderExtrasFor})),nh=a.useMemo(()=>{const Y=new Map;return Ve.forEach(Xe=>{const Ye=Xe.groups.find(jt=>!jt.isArchivedBucket);Ye?.folderScopes&&Ye.folderScopes.length>0&&Y.set(Xe.project.id,Ye.folderScopes)}),Y},[Ve]),rh=a.useCallback((Y,Xe)=>{const Ye=[];return Xe.forEach(jt=>{jt.isArchivedBucket||(Ye.push(jt.directory),jt.folderScopes?.forEach(Jt=>Ye.push(Jt.directory)))}),s.jsx(P2,{directories:Ye})},[]),jc=a.useCallback(Y=>{hr(Y),ue(Xe=>{const Ye=new Set(Xe);return Ye.has(Y)?Ye.delete(Y):Ye.add(Y),Ye})},[hr]),oh=a.useCallback((Y,Xe,Ye,jt,Jt,cs,Sn)=>s.jsx(qS,{group:Y,groupKey:Xe,projectId:Ye,hideGroupLabel:jt,dragHandleProps:Jt,compactBodyPadding:cs,hasSessionSearchQuery:ht,normalizedSessionSearchQuery:gt,groupSearchDataByGroup:ye,visibleSessionCount:k.get(Xe),collapsedGroups:oe,hideDirectoryControls:o,collapsedFolderIds:wt,toggleFolderCollapse:It,renameFolder:Kt,deleteFolder:Ut,showDeletionDialog:nt,setDeleteFolderConfirm:Z,renderSessionNode:Yo,showMoreGroupSessions:mo,resetGroupSessionLimit:hr,mobileVariant:e,alwaysShowActions:on,activeProjectId:ee,setActiveProjectIdOnly:ae,setActiveMainTab:_e,setSessionSwitcherOpen:$,openNewSessionDraft:Pt,addSessionToFolder:Lt,createFolderAndStartRename:Hr,renamingFolderId:R,renameFolderDraft:P,setRenameFolderDraft:G,setRenamingFolderId:L,pinnedSessionIds:se,expandedParents:xr,sessionOrderIndex:xt,editingId:x,editTitle:S,openSidebarMenuKey:T,activeActivitySessionIds:xe,unreadActivitySessionIds:J,notifyOnSubtasks:Ke,onToggleCollapsedGroup:jc,scrollContainerRef:Sn}),[ht,gt,ye,k,oe,o,wt,It,Kt,Ut,nt,Yo,mo,hr,e,on,ee,ae,_e,$,Pt,Lt,Hr,R,P,se,xr,xt,x,S,T,xe,J,Ke,jc]),ih=a.useMemo(()=>!Te&&hn&&!ht?s.jsx(ak,{sections:xo,renderSessionNode:Yo,editingId:x,openSidebarMenuKey:T,expansionState:go,variant:"section",isDesktopShellRuntime:fn}):null,[xo,x,ht,fn,Te,T,go,Yo,hn]),Sc=!!(R||x||m),{selectionModeEnabled:kc,hasSelection:ah,selectedIdsSize:lh,bulkScopeIsArchived:ch,derivedSelectionScope:dh,bulkScopeFolders:uh,bulkCanRemoveFromFolder:fh,handleToggleSelectionMode:mh,handleExitSelectionMode:hh,handleBulkMoveToFolder:ph,handleBulkCreateFolderAndMove:gh,handleBulkRemoveFromFolder:xh,handleBulkDelete:bh,handleBulkRestore:yh,confirmBulkDelete:wh}=u2({isInlineEditing:Sc,showDeletionDialog:nt,foldersMap:bt,folderScopesByProject:nh,addSessionsToFolder:Bt,removeSessionsFromFolders:Ht,createFolderAndStartRename:Rr,archiveSessions:Wt,unarchiveSessions:hs,deleteSessions:ks,setBulkDeleteConfirm:Fe}),vh=a.useCallback(()=>{_e("chat"),e&&$(!1),Re()},[e,Re,_e,$]),jh=a.useCallback(()=>{Ee.getState().closeMainSurfaces(),_e("chat"),e&&$(!1),$t()},[e,$t,_e,$]);return s.jsx(gl,{delay:0,closeDelay:150,timeout:600,children:s.jsxs("div",{ref:f,className:Pe("relative flex h-full flex-col text-foreground overflow-x-hidden",e?"":"bg-transparent"),children:[s.jsx(D2,{owner:tt,childStores:Et,projectSections:K,activeProjectId:ee,collapsedProjects:N,collapsedGroups:oe,currentDirectory:ve}),s.jsx(U0,{projectSections:K,activeProjectId:ee,initialActiveSessionByProject:Se,persistActiveSessionByProject:Le,handleSessionSelect:uo,mobileVariant:e,openNewSessionDraft:$t,setActiveMainTab:_e,setSessionSwitcherOpen:$}),s.jsx(F0,{enabled:t,sortedSessions:re,recentSessions:cr,prefetchSession:Mt.prefetchSession}),!o&&!Te?s.jsx(ik,{onNewSession:jh}):null,s.jsx(QS,{hideDirectoryControls:o,showRecentControls:!Te,handleOpenDirectoryDialog:co,onOpenScheduled:()=>{e&&$(!1),_(!0)},onOpenMultiRun:vh,canOpenMultiRun:ie.length>0,onOpenArchive:()=>{e&&$(!1),ge(!0)},headerActionIconClass:th,headerActionButtonClass:eh,isSessionSearchOpen:l,setIsSessionSearchOpen:d,sessionSearchInputRef:p,sessionSearchQuery:u,setSessionSearchQuery:h,hasSessionSearchQuery:ht,searchMatchCount:dt,collapseAllProjects:ar,expandAllProjects:Go,selectionModeEnabled:kc,onToggleSelectionMode:mh}),t?s.jsx(wk,{topContent:ih,hasSharedSessions:Jm,sectionsForRender:Zm,projectSections:K,activeProjectId:ee,showOnlyMainWorkspace:i,hasSessionSearchQuery:ht,emptyState:Tt,searchEmptyState:Vt,renderGroupSessions:oh,homeDirectory:je,collapsedProjects:N,hideDirectoryControls:o,projectRepoStatus:D,isDesktopShellRuntime:fn,stickyZoneHeaders:lr,stuckProjectHeaders:sh,mobileVariant:e,alwaysShowActions:on,toggleProject:Kr,setActiveProjectIdOnly:ae,setActiveMainTab:_e,setSessionSwitcherOpen:$,openNewSessionDraft:Pt,openNewWorktreeDialog:As,openWorktreesPage:Y=>{e&&$(!1),Ie(Y)},openProjectEditDialog:y,removeProject:ke,projectHeaderSentinelRefs:q,reorderProjects:le,projectSortOrder:Rn,getOrderedGroups:ps,setGroupOrderByProject:we,renderProjectStatusIndicator:rh,openSidebarMenuKey:T,setOpenSidebarMenuKey:I,isInlineEditing:Sc}):null,kc&&ah?s.jsx(d2,{selectedCount:lh,scopeKey:dh,scopeFolders:uh,archivedBucket:ch,onMoveToFolder:ph,onCreateFolderAndMove:gh,onRemoveFromFolder:xh,canRemoveFromFolder:fh,onRestore:yh,onDelete:bh,onDone:hh}):null,s.jsx(lk,{onOpenSettings:Ss,onOpenShortcuts:he,onOpenAbout:()=>me(!0),onOpenUpdate:as,showRuntimeButtons:!Te,showUpdateButton:Rs}),s.jsx(Pf,{open:B,onOpenChange:z,info:ms.info,downloading:ms.downloading,downloaded:ms.downloaded,progress:ms.progress,error:ms.error,onDownload:ms.downloadUpdate,onRestart:ms.restartToUpdate,runtimeType:ms.runtimeType}),s.jsx(jS,{open:!!Ct,onOpenChange:Y=>{Y||y(null)},project:Ct,onSave:xs}),s.jsx(Sx,{open:O,onOpenChange:M,onWorktreeCreated:(Y,Xe)=>{if(_e("chat"),e&&$(!1),Xe?.sessionId){At(Xe.sessionId,Y);return}$t({directoryOverride:Y,preserveDirectoryOverride:!0})}}),s.jsx(a2,{value:X,setValue:V,showDeletionDialog:nt,setShowDeletionDialog:ct,onConfirm:ir}),s.jsx(c2,{value:te,setValue:Z,onConfirm:Ir}),s.jsx(l2,{value:de,setValue:Fe,showDeletionDialog:nt,setShowDeletionDialog:ct,onConfirm:wh})]})})},bu=a.memo(I2);function R2(t){return t.currentSessionDirectory}const Xr=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Jn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},M2=()=>{const{t}=ft(),[e,n]=a.useState(!1),[r,o]=a.useState(!1),[i,c]=a.useState(null),[l,d]=a.useState([]),[u,h]=a.useState(!1),[f,p]=a.useState(!1),[x,b]=a.useState(!1),[S,g]=a.useState(!1),[m,y]=a.useState(new Set),C=Je(q=>q.getWorktreeMetadata),j=Je(q=>q.newSessionDraft),w=Je(q=>q.setNewSessionDraftTarget),N=Je(q=>q.setDraftBootstrapPendingDirectory),v=vg,D=Sg,F=Je(q=>q.deleteSessions),k=Je(q=>q.archiveSessions),E=Ee(q=>q.showDeletionDialog),O=Ee(q=>q.setShowDeletionDialog),M=vs(q=>q.currentDirectory),B=vs(q=>q.homeDirectory),z=vs(q=>q.isHomeReady),T=ds(q=>q.projects),I=ds(q=>q.activeProjectId),{isMobile:R,isTablet:L,hasTouchInput:P}=Dr(),G=R||L||P,X=a.useMemo(()=>{const Ne=(I?T.find(je=>je.id===I)??null:null)?.path??M;return Jn(Ne)},[I,M,T]),V=a.useCallback(q=>{const je=Jn(q.projectDirectory)||X;return{id:(T.find(ie=>Jn(ie.path)===je)??null)?.id??`path:${je}`,path:je}},[X,T]),te=S&&m.size>0,Z=a.useMemo(()=>{const q=i?.worktree;return q&&typeof q.branch=="string"&&q.branch.trim().length>0?!0:l.length>0&&l.every(({metadata:Ne})=>typeof Ne.branch=="string"&&Ne.branch.trim().length>0)},[i?.worktree,l]),de=i?.mode==="worktree",Fe=de,se=x||!de||!Z,Q=x||!de;a.useEffect(()=>{r||!z||T.length>0||(o(!0),n(!0))},[r,z,T.length]);const Me=a.useCallback(q=>{c({sessions:q.sessions,dateLabel:q.dateLabel,mode:q.mode??"session",worktree:q.worktree??null})},[]),xe=a.useCallback(()=>{c(null),d([]),h(!1),p(!1),b(!1),g(!1),y(new Set)},[]),W=a.useCallback(async q=>{if(q.sessions.length===0)return;if(q.sessions.length===1){const ie=q.sessions[0];await v(ie.id)?fe.success(t("sessions.sidebar.session.delete.success")):fe.error(t("sessions.sidebar.session.delete.error"));return}const Ne=q.sessions.map(ie=>ie.id),{deletedIds:je,failedIds:ve}=await F(Ne);if(je.length>0){const ie=ve.length>0?ve.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ve.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ve.length}):q.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:q.dateLabel}):void 0;fe.success(je.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:je.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:je.length}),{description:Xr(ie)})}ve.length>0&&fe.error(ve.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ve.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ve.length}),{description:Xr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[v,F,t]);a.useEffect(()=>Gn.onDeleteRequest(q=>{if(!E&&(q.mode??"session")==="session"){W(q);return}Me(q)}),[Me,E,W]),a.useEffect(()=>Gn.onDirectoryRequest(()=>{n(!0)}),[]),a.useEffect(()=>{if(!i){d([]),h(!1),p(!1),g(!1),y(new Set);return}const q=i.sessions.map(ve=>{const ie=C(ve.id);return ie?{session:ve,metadata:ie}:null}).filter(ve=>!!ve);d(q),h(!1),g(!1),y(new Set);const Ne=new Map;if(i.worktree?.path&&Ne.set(Jn(i.worktree.path),i.worktree),q.forEach(({metadata:ve})=>{ve.path&&Ne.set(Jn(ve.path),ve)}),Ne.size===0){g(!0);return}let je=!1;return(async()=>{const ve=new Map,ie=new Set;await Promise.all(Array.from(Ne.entries()).map(async([ee,ke])=>{try{const ae=await jg(ke.path);ve.set(ee,ae),ae?.isDirty&&ie.add(ee)}catch{ke.status&&(ve.set(ee,ke.status),ke.status.isDirty&&ie.add(ee))}})).catch(ee=>{console.warn("Failed to inspect worktree status before deletion:",ee)}),!je&&(y(ie),g(!0),c(ee=>{if(!ee?.worktree?.path)return ee;const ke=Jn(ee.worktree.path),ae=ve.get(ke);if(!ae)return ee;const U=ee.worktree.status;return U?.isDirty===ae.isDirty&&U?.ahead===ae.ahead&&U?.behind===ae.behind&&U?.upstream===ae.upstream?ee:{...ee,worktree:{...ee.worktree,status:ae}}}),d(ee=>ee.map(ke=>{const ae=Jn(ke.metadata.path),U=ve.get(ae);return U?{session:ke.session,metadata:{...ke.metadata,status:U}}:ke})))})(),()=>{je=!0}},[i,C]),a.useEffect(()=>{Z||h(!1)},[Z]);const J=a.useCallback(async(q,Ne)=>{const je=u&&Z,ve=V(q),ie=Jn(q.path),ee=Jn(ve.path);try{await tf(ve,q,{deleteRemoteBranch:je,deleteLocalBranch:Ne});const ke=Jn(j?.directoryOverride);return j?.open&&ie&&ke===ie&&ee&&(N(null),w({projectId:ve.id,directoryOverride:ee},{force:!0})),Jn(M)===ie&&ee&&vs.getState().setDirectory(ee,{showOverlay:!1}),!0}catch(ke){return fe.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Xr(ke instanceof Error?ke.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[Z,M,u,V,j?.directoryOverride,j?.open,N,w,t]),ne=a.useCallback((q,Ne)=>{const je=u&&Z;(async()=>{if(!await J(q,Ne))return;const ie=t(je?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");fe.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Xr(ie)})})()},[Z,u,J,t]),oe=a.useCallback(async()=>{if(i){b(!0);try{const q=Fe,Ne=q&&u,je=q&&f;if(i.sessions.length===0&&de&&i.worktree){ne(i.worktree,je),xe();return}if(i.sessions.length===1){const ve=i.sessions[0];if(!(de?await D(ve.id):await v(ve.id))){fe.error(t(de?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),b(!1);return}const ee=!de&&q?t(Ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;fe.success(t(de?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Xr(ee),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const ve=i.sessions.map(ke=>ke.id);let ie=[],ee=[];if(de){const ke=await k(ve);ie=ke.archivedIds,ee=ke.failedIds}else{const ke=await F(ve);ie=ke.deletedIds,ee=ke.failedIds}if(de&&i.worktree&&ee.length===0&&ne(i.worktree,je),ie.length>0){const ke=!de&&q?t(Ne?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,U=[ee.length>0?de?ee.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:ee.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:ee.length}):ee.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ee.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ee.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,ke].filter(Boolean).join(" ");fe.success(de?ie.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:ie.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:ie.length}):ie.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ie.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ie.length}),{description:Xr(U||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ee.length>0&&(fe.error(de?ee.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ee.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:ee.length}):ee.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ee.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ee.length}),{description:Xr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),ie.length===0)){b(!1);return}}de&&i.sessions.length===1&&i.worktree&&ne(i.worktree,je),xe()}finally{b(!1)}}},[i,u,f,v,F,D,k,xe,Fe,de,ne,t]),ue=i?.worktree??l[0]?.metadata??null,Ae=i?i.mode==="worktree"?i.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):i.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:i.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:i.sessions.length}):i.sessions.length===1?i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:i.sessions.length,dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:i.sessions.length}):"",we=i?s.jsxs("div",{className:Pe(de?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:Pe(de?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[de&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:Pe(de?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(q=>s.jsxs("li",{className:Pe(de?"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:Pe(!de&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:q.title||t("sessions.sidebar.session.untitled")})]},q.id)),i.sessions.length>5&&s.jsx("li",{className:Pe(de?"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:i.sessions.length-5})})]})]}),de?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(A,{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")}),ue?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ue.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ue?Zi(ue.path,B):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),te&&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,Se=de?Z?s.jsxs("button",{type:"button",onClick:()=>{se||h(q=>!q)},disabled:se,className:Pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",se?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(A,{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,Le=de?s.jsxs("button",{type:"button",onClick:()=>{Q||p(q=>!q)},disabled:Q,className:Pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",Q?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(A,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Ue=de?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:[Le,Se]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{variant:"ghost",onClick:xe,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(He,{variant:"destructive",onClick:oe,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:()=>O(!E),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":!E,children:[E?s.jsx(A,{name:"checkbox-blank",className:"size-4"}):s.jsx(A,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{variant:"ghost",onClick:xe,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(He,{variant:"destructive",onClick:oe,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),be=de?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[G?s.jsx(ka,{open:!!i,onClose:()=>{x||xe()},title:be,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Ue}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[Ae&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:Ae}),we]})}):s.jsx(Ps,{open:!!i,onOpenChange:q=>{if(!q){if(x)return;xe()}},children:s.jsxs(Is,{className:Pe(de?"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(Us,{children:[s.jsxs(Ls,{className:Pe(de&&"flex items-center gap-2"),children:[de&&s.jsx(A,{name:"delete-bin",className:"h-5 w-5"}),be]}),Ae&&s.jsx(Hs,{children:Ae})]}),s.jsx("div",{className:Pe(de&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:we}),s.jsx(rr,{className:"mt-2 gap-2 pt-1 pb-1",children:Ue})]})}),s.jsx(kx,{open:e,onOpenChange:n})]})},Ma=async(t,e)=>{try{const n=await t.json();if(n&&typeof n.error=="string"&&n.error.trim().length>0)return n.error}catch{return e}return e},Lo=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},T2=async t=>{const e=Lo(t),n=await us(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Ma(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},yu=async(t,e)=>{const n=Lo(t),r=await us(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:e})});if(!r.ok)throw new Error(await Ma(r,"Failed to save scheduled task"));const o=await r.json().catch(()=>null);return!o||!Array.isArray(o.tasks)?[]:o.tasks},E2=async(t,e)=>{const n=Lo(t),r=Lo(e),o=await us(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Ma(o,"Failed to delete scheduled task"));const i=await o.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},F2=async(t,e)=>{const n=Lo(t),r=Lo(e),o=await us(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Ma(o,"Failed to run scheduled task"));const i=await o.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0}};function Km(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return Hf.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function O2(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},o=Hf.CronExpressionParser.parse(t,r),i=[];for(let c=0;c<n;c+=1){const l=o.next();l&&i.push(l.toDate())}return i}catch{return[]}}const L2=[{expression:"*/5 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.every5min"},{expression:"0 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.everyHour"},{expression:"0 9 * * 1",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.monday9am"},{expression:"0 9,17 * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.9am5pm"},{expression:"0 0 1 * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.firstOfMonth"}],B2={"Europe/Kiev":"Europe/Kyiv","Asia/Calcutta":"Asia/Kolkata","Asia/Saigon":"Asia/Ho_Chi_Minh","Asia/Rangoon":"Asia/Yangon","Asia/Katmandu":"Asia/Kathmandu","America/Godthab":"America/Nuuk","Atlantic/Faeroe":"Atlantic/Faroe","Pacific/Enderbury":"Pacific/Kanton"},ro=t=>B2[t]??t,Gm=[0,1,2,3,4,5,6],wu="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",El=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(ro))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],vu=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},Gi=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),o=Number(e[3]),i=new Date(n,r-1,o);return Number.isNaN(i.getTime())||i.getFullYear()!==n||i.getMonth()!==r-1||i.getDate()!==o?null:i},ju=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},$2=(t,e,n)=>{const r=Gi(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Su=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),_2=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),c=(new Date(n,r,1).getDay()-e+7)%7,l=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),u=[];for(let h=0;h<42;h+=1){const f=h-c+1;if(f<=0){const p=d+f;u.push({date:new Date(n,r-1,p),inCurrentMonth:!1});continue}if(f>l){u.push({date:new Date(n,r+1,f-l),inCurrentMonth:!1});continue}u.push({date:new Date(n,r,f),inCurrentMonth:!0})}return u},z2=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],o=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:o}},Jr=(t,e,n)=>{const r=Number(t),o=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,c=Number.isFinite(o)?Math.min(59,Math.max(0,o)):0;let l=i%12;return n==="PM"&&(l+=12),`${String(l).padStart(2,"0")}:${String(c).padStart(2,"0")}`},Wo=(t,e)=>{const{max:n,min:r=0,loop:o=!1}=e;let i=Number.parseInt(t,10);return Number.isFinite(i)?(o?(i>n&&(i=r),i<r&&(i=n)):(i>n&&(i=n),i<r&&(i=r)),String(i).padStart(2,"0")):"00"},ku=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:Wo(t,{min:1,max:12}),Fi=t=>/^[0-5][0-9]$/.test(t)?t:Wo(t,{max:59}),V2=(t,e)=>Wo(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Nu=(t,e)=>Wo(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),W2=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},U2=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},H2=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Gm.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},K2=(t,e)=>[...t.slice(e),...t.slice(0,e)],Nn=t=>{const e=ot.c(6),{htmlFor:n,required:r,children:o}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let c;return e[2]!==o||e[3]!==n||e[4]!==i?(c=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,i]})}),e[2]=o,e[3]=n,e[4]=i,e[5]=c):c=e[5],c},Cu=t=>{const e=ot.c(84),{value:n,onChange:r,use24Hour:o,hourAriaLabel:i,minuteAriaLabel:c,periodAriaLabel:l,amLabel:d,pmLabel:u}=t;let h;e[0]!==n?(h=z2(n),e[0]=n,e[1]=h):h=e[1];const f=h,p=$e.useRef(null),x=$e.useRef(null),[b,S]=$e.useState(null),[g,m]=$e.useState(null),y=$e.useRef(null),C=$e.useRef(null);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j=be=>{y.current=be,S(be)},e[2]=j):j=e[2];const w=j;let N;e[3]===Symbol.for("react.memo_cache_sentinel")?(N=be=>{C.current=be,m(be)},e[3]=N):N=e[3];const v=N,D=Z2,F=eN,k=tN;let E;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==o?(E=be=>{const q=be.replace(/\D/g,"").slice(0,2);w(q),q.length===2&&(r(o?k(D(q),f.minute):Jr(ku(q),f.minute,f.meridiem)),w(null),x.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=o,e[8]=E):E=e[8];const O=E;let M;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==o?(M=()=>{const be=y.current;if(be!==null&&(w(null),be.length!==0)){if(o){r(k(D(be.padStart(2,"0")),f.minute));return}r(Jr(ku(be.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=o,e[13]=M):M=e[13];const B=M;let z;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==o?(z=be=>{const q=be.replace(/\D/g,"").slice(0,2);v(q),q.length===2&&(r(o?k(f.hour24,Fi(q)):Jr(f.hour12,Fi(q),f.meridiem)),v(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=o,e[19]=z):z=e[19];const T=z;let I;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==o?(I=()=>{const be=C.current;be!==null&&(v(null),be.length!==0&&r(o?k(f.hour24,Fi(be.padStart(2,"0"))):Jr(f.hour12,Fi(be.padStart(2,"0")),f.meridiem)))},e[20]=r,e[21]=f.hour12,e[22]=f.hour24,e[23]=f.meridiem,e[24]=o,e[25]=I):I=e[25];const R=I;let L;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==o?(L=be=>r(o?k(F(f.hour24,be),f.minute):Jr(V2(f.hour12,be),f.minute,f.meridiem)),e[26]=r,e[27]=f.hour12,e[28]=f.hour24,e[29]=f.meridiem,e[30]=f.minute,e[31]=o,e[32]=L):L=e[32];const P=L;let G;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==o?(G=be=>r(o?k(f.hour24,Nu(f.minute,be)):Jr(f.hour12,Nu(f.minute,be),f.meridiem)),e[33]=r,e[34]=f.hour12,e[35]=f.hour24,e[36]=f.meridiem,e[37]=f.minute,e[38]=o,e[39]=G):G=e[39];const X=G;let V;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(V=be=>{be!==f.meridiem&&r(Jr(f.hour12,f.minute,be))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=V):V=e[44];const te=V;let Z;e[45]!==B||e[46]!==P?(Z=be=>{if(be.key==="ArrowRight"){be.preventDefault(),B(),x.current?.focus();return}(be.key==="ArrowUp"||be.key==="ArrowDown")&&(be.preventDefault(),w(null),P(be.key==="ArrowUp"?1:-1))},e[45]=B,e[46]=P,e[47]=Z):Z=e[47];const de=Z;let Fe;e[48]!==R||e[49]!==X?(Fe=be=>{if(be.key==="ArrowLeft"&&(be.currentTarget.selectionStart??0)===0){be.preventDefault(),R(),p.current?.focus();return}(be.key==="ArrowUp"||be.key==="ArrowDown")&&(be.preventDefault(),v(null),X(be.key==="ArrowUp"?1:-1))},e[48]=R,e[49]=X,e[50]=Fe):Fe=e[50];const se=Fe,Q=o?"px-2":"pl-2 pr-1";let Me;e[51]!==Q?(Me=Pe("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",Q),e[51]=Q,e[52]=Me):Me=e[52];const xe=b??(o?f.hour24:f.hour12);let W;e[53]!==O?(W=be=>O(be.target.value),e[53]=O,e[54]=W):W=e[54];let J;e[55]===Symbol.for("react.memo_cache_sentinel")?(J=()=>w(""),e[55]=J):J=e[55];let ne;e[56]!==B||e[57]!==i||e[58]!==de||e[59]!==xe||e[60]!==W?(ne=s.jsx("input",{ref:p,inputMode:"numeric",value:xe,onChange:W,onKeyDown:de,onFocus:J,onBlur:B,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=B,e[57]=i,e[58]=de,e[59]=xe,e[60]=W,e[61]=ne):ne=e[61];let oe;e[62]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=oe):oe=e[62];const ue=g??f.minute;let Ae;e[63]!==T?(Ae=be=>T(be.target.value),e[63]=T,e[64]=Ae):Ae=e[64];let we;e[65]===Symbol.for("react.memo_cache_sentinel")?(we=()=>v(""),e[65]=we):we=e[65];let Se;e[66]!==R||e[67]!==c||e[68]!==se||e[69]!==ue||e[70]!==Ae?(Se=s.jsx("input",{ref:x,inputMode:"numeric",value:ue,onChange:Ae,onKeyDown:se,onFocus:we,onBlur:R,maxLength:2,"aria-label":c,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=R,e[67]=c,e[68]=se,e[69]=ue,e[70]=Ae,e[71]=Se):Se=e[71];let Le;e[72]!==d||e[73]!==f.meridiem||e[74]!==l||e[75]!==u||e[76]!==te||e[77]!==o?(Le=o?null:s.jsxs(xn,{value:f.meridiem,onValueChange:be=>te(be),children:[s.jsx(bn,{"aria-label":l,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(rn,{})}),s.jsxs(yn,{children:[s.jsx(ys,{value:"AM",children:d}),s.jsx(ys,{value:"PM",children:u})]})]}),e[72]=d,e[73]=f.meridiem,e[74]=l,e[75]=u,e[76]=te,e[77]=o,e[78]=Le):Le=e[78];let Ue;return e[79]!==Me||e[80]!==ne||e[81]!==Se||e[82]!==Le?(Ue=s.jsxs("div",{className:Me,children:[ne,oe,Se,Le]}),e[79]=Me,e[80]=ne,e[81]=Se,e[82]=Le,e[83]=Ue):Ue=e[83],Ue},Au=t=>new Date(t.getFullYear(),t.getMonth(),1),G2=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Du=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),q2=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(o=>typeof o=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(o)).map(o=>o.trim()),r=Array.from(new Set(n)).sort((o,i)=>o.localeCompare(i));return r.length>0?r:["09:00"]},Pu=(t,e)=>{const n=ro(Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC");return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="cron"?"cron":t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:q2(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:vu(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:ro(t.schedule.timezone||n),cronExpression:t.schedule.kind==="cron"&&typeof t.schedule.cron=="string"?t.schedule.cron:""},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||"",goalEnabled:t.execution.goalEnabled===!0,goalTokenBudget:typeof t.execution.goalTokenBudget=="number"&&t.execution.goalTokenBudget>0?t.execution.goalTokenBudget:null,permissionAutoAccept:t.execution.permissionAutoAccept===!0},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:vu(),onceTime:"09:00",weekdays:[1],timezone:n,cronExpression:""},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent,goalEnabled:!1,goalTokenBudget:null,permissionAutoAccept:!1}}},Y2=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.kind==="cron"){if(!t.schedule.cronExpression.trim())return e("sessions.scheduledTasks.editor.validation.cronRequired");if(!Km(t.schedule.cronExpression).valid)return e("sessions.scheduledTasks.editor.validation.cronInvalid")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},Q2=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))},X2=t=>{const e=ot.c(64),{draft:n,setDraft:r,locale:o,t:i}=t,c=n.schedule.cronExpression;let l;e[0]!==c?(l=c.trim()?Km(c):null,e[0]=c,e[1]=l):l=e[1];const d=l;let u;e:{if(!d?.valid||!c.trim()){let L;e[2]===Symbol.for("react.memo_cache_sentinel")?(L=[],e[2]=L):L=e[2],u=L;break e}let R;e[3]!==c||e[4]!==n.schedule.timezone?(R=O2(c,n.schedule.timezone),e[3]=c,e[4]=n.schedule.timezone,e[5]=R):R=e[5],u=R}const h=u;let f;e[6]!==n.schedule.timezone||e[7]!==o?(f=R=>new Intl.DateTimeFormat(o,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(R),e[6]=n.schedule.timezone,e[7]=o,e[8]=f):f=e[8];const p=f;let x;e[9]!==i?(x=i("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=i,e[10]=x):x=e[10];let b;e[11]!==x?(b=s.jsx(Nn,{htmlFor:"sched-cron",required:!0,children:x}),e[11]=x,e[12]=b):b=e[12];let S;e[13]!==r?(S=R=>r(L=>({...L,schedule:{...L.schedule,cronExpression:R.target.value}})),e[13]=r,e[14]=S):S=e[14];let g;e[15]!==i?(g=i("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=i,e[16]=g):g=e[16];let m;e[17]!==c||e[18]!==S||e[19]!==g?(m=s.jsx(sr,{id:"sched-cron",value:c,onChange:S,placeholder:g,className:"w-full max-w-xs font-mono"}),e[17]=c,e[18]=S,e[19]=g,e[20]=m):m=e[20];let y;e[21]!==c||e[22]!==d||e[23]!==i?(y=d&&!d.valid&&c.trim()?s.jsx("span",{className:"typography-micro text-destructive",children:i("sessions.scheduledTasks.editor.validation.cronInvalid")}):null,e[21]=c,e[22]=d,e[23]=i,e[24]=y):y=e[24];let C;e[25]!==b||e[26]!==m||e[27]!==y?(C=s.jsxs("div",{className:"flex flex-col gap-1",children:[b,m,y]}),e[25]=b,e[26]=m,e[27]=y,e[28]=C):C=e[28];let j;e[29]!==p||e[30]!==h||e[31]!==i?(j=h.length>0?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("sessions.scheduledTasks.editor.cronExpression.nextRuns")}),s.jsx("span",{className:"typography-micro text-foreground",children:h.map(p).join(", ")})]}):null,e[29]=p,e[30]=h,e[31]=i,e[32]=j):j=e[32];let w;e[33]!==i?(w=i("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=i,e[34]=w):w=e[34];let N;e[35]!==w?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:w}),e[35]=w,e[36]=N):N=e[36];let v;e[37]!==r||e[38]!==i?(v=L2.map(R=>s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 typography-micro text-foreground hover:bg-interactive-hover",onClick:()=>r(L=>({...L,schedule:{...L.schedule,cronExpression:R.expression}})),children:[s.jsx("span",{className:"font-mono",children:R.expression}),s.jsx("span",{className:"text-muted-foreground",children:i(R.labelKey)})]},R.expression)),e[37]=r,e[38]=i,e[39]=v):v=e[39];let D;e[40]!==v?(D=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:v}),e[40]=v,e[41]=D):D=e[41];let F;e[42]!==N||e[43]!==D?(F=s.jsxs("div",{className:"flex flex-col gap-1",children:[N,D]}),e[42]=N,e[43]=D,e[44]=F):F=e[44];let k;e[45]!==i?(k=i("sessions.scheduledTasks.editor.timezone.label"),e[45]=i,e[46]=k):k=e[46];let E;e[47]!==k?(E=s.jsx(Nn,{children:k}),e[47]=k,e[48]=E):E=e[48];let O;e[49]!==r?(O=R=>{r(L=>({...L,schedule:{...L.schedule,timezone:R}}))},e[49]=r,e[50]=O):O=e[50];let M;e[51]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(bn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(rn,{})}),e[51]=M):M=e[51];let B;e[52]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(yn,{children:El.map(sN)}),e[52]=B):B=e[52];let z;e[53]!==n.schedule.timezone||e[54]!==O?(z=s.jsxs(xn,{value:n.schedule.timezone,onValueChange:O,children:[M,B]}),e[53]=n.schedule.timezone,e[54]=O,e[55]=z):z=e[55];let T;e[56]!==E||e[57]!==z?(T=s.jsxs("div",{className:"flex flex-col gap-1",children:[E,z]}),e[56]=E,e[57]=z,e[58]=T):T=e[58];let I;return e[59]!==C||e[60]!==j||e[61]!==F||e[62]!==T?(I=s.jsxs("div",{className:"flex flex-col gap-3",children:[C,j,F,T]}),e[59]=C,e[60]=j,e[61]=F,e[62]=T,e[63]=I):I=e[63],I};function J2(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:i,locale:c}=ft(),l=rs($=>$.loadProviders),d=rs($=>$.loadAgents),u=rs($=>$.providers),h=rs($=>$.currentProviderId),f=rs($=>$.currentModelId),p=rs($=>$.currentVariant||""),x=rs($=>$.currentAgentName||""),b=Ee($=>$.timeFormatPreference),S=Ee($=>$.weekStartPreference),g=Ee($=>$.isMobile),[m,y]=$e.useState(()=>Pu(n,{providerID:h,modelID:f,variant:p,agent:x})),[C,j]=$e.useState(!1),[w,N]=$e.useState(!1),[v,D]=$e.useState(!1),[F,k]=$e.useState(""),[E,O]=$e.useState(!1),[M,B]=$e.useState(""),[z,T]=$e.useState(!1),[I,R]=$e.useState(""),[L,P]=$e.useState(()=>{const $=Gi(n?.schedule?.date||"")||new Date;return new Date($.getFullYear(),$.getMonth(),1)}),G=$e.useRef(null),X=$e.useRef(null),V=$e.useRef(null),te=$e.useRef(null),Z=$e.useRef(null),de=$e.useMemo(()=>U2(c),[c]),Fe=$e.useMemo(()=>W2(c),[c]),se=$e.useMemo(()=>b==="24h"?!0:b==="12h"?!1:de,[b,de]),Q=$e.useMemo(()=>S==="sunday"?0:S==="monday"?1:Fe,[S,Fe]),Me=$e.useMemo(()=>{const $=H2(c);return K2(Gm.map(_=>({value:_,label:$[_]||""})),Q)},[c,Q]);$e.useEffect(()=>{e&&(l({source:"scheduledTaskEditor"}),d({source:"scheduledTaskEditor"}))},[e,l,d]),$e.useEffect(()=>{if(!e)return;y(Pu(n,{providerID:h,modelID:f,variant:p,agent:x}));const $=Gi(n?.schedule?.date||"")||new Date;P(new Date($.getFullYear(),$.getMonth(),1)),N(!1),O(!1),D(!1),B(""),k("")},[e,n,h,f,p,x]),$e.useEffect(()=>{if(!w)return;const $=_=>{G.current&&!G.current.contains(_.target)&&N(!1)};return document.addEventListener("mousedown",$),()=>{document.removeEventListener("mousedown",$)}},[w]);const xe=$e.useMemo(()=>{const _=u.find(ge=>ge.id===m.execution.providerID)?.models?.find(ge=>ge.id===m.execution.modelID);return _?.variants?Object.keys(_.variants):[]},[u,m.execution.providerID,m.execution.modelID]),W=xe.length>0,J=$e.useMemo(()=>!W||!m.execution.variant?"__default":xe.includes(m.execution.variant)?m.execution.variant:"__default",[m.execution.variant,W,xe]);$e.useEffect(()=>{W||!m.execution.variant||y($=>({...$,execution:{...$.execution,variant:""}}))},[W,m.execution.variant]);const ne=$e.useCallback(($,_)=>{y(ge=>{const Ie=new Set(ge.schedule.weekdays);return _?Ie.add($):Ie.delete($),{...ge,schedule:{...ge.schedule,weekdays:Array.from(Ie).sort((Re,Ke)=>Re-Ke)}}})},[]),oe=$e.useCallback(($,_)=>{y(ge=>{const Ie=ge.schedule.times.slice();return Ie[$]=_,{...ge,schedule:{...ge.schedule,times:Ie}}})},[]),ue=$e.useCallback($=>{y(_=>{const ge=_.schedule.times.filter((Ie,Re)=>Re!==$);return{..._,schedule:{..._.schedule,times:ge.length>0?ge:["09:00"]}}})},[]),Ae=$e.useCallback(()=>{y($=>({...$,schedule:{...$.schedule,times:[...$.schedule.times,"12:00"]}}))},[]),we=$e.useMemo(()=>G2(),[]),Se=$e.useMemo(()=>Au(we),[we]),Le=$e.useMemo(()=>{const $=Gi(m.schedule.onceDate);return $?Du($,we)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format($):null},[m.schedule.onceDate,c,i,we]),Ue=$e.useMemo(()=>Au(L).getTime()<=Se.getTime(),[L,Se]),be=$e.useMemo(()=>Me.map($=>$.label),[Me]),q=$e.useCallback($=>{y(_=>({..._,schedule:{..._.schedule,onceDate:$}}))},[]),Ne=$e.useCallback(($,_)=>{if($.startsWith("/")){const Ke=$.indexOf(" "),nt=$.indexOf(`
|
|
203
|
+
`),ct=Math.min(Ke===-1?$.length:Ke,nt===-1?$.length:nt);if(_<=ct&&Ke===-1){B($.substring(1,ct)),O(!0),D(!1),T(!1);return}}O(!1);const ge=$.substring(0,_),Ie=ge.lastIndexOf("#");if(Ie!==-1){const Ke=Ie>0?ge[Ie-1]:null,nt=ge.substring(Ie+1);if((!Ke||/\s/.test(Ke))&&!nt.includes(" ")&&!nt.includes(`
|
|
204
|
+
`)){R(nt),T(!0),D(!1);return}}T(!1);const Re=ge.lastIndexOf("@");if(Re!==-1){const Ke=Re>0?ge[Re-1]:null,nt=ge.substring(Re+1);(!Ke||/\s/.test(Ke))&&!nt.includes(" ")&&!nt.includes(`
|
|
205
|
+
`)?(k(nt),D(!0)):D(!1);return}D(!1)},[]),je=$e.useCallback($=>{y(_=>({..._,execution:{..._.execution,prompt:$}}))},[]),ve=$e.useCallback($=>{const _=m.execution.prompt,Ie=X.current?.selectionStart??_.length,Ke=_.substring(0,Ie).lastIndexOf("@"),nt=$.relativePath&&$.relativePath.trim().length>0?$.relativePath.trim():$.path||$.name,ct=Ke!==-1?Ke:Ie,mt=`${_.substring(0,ct)}@${nt} ${_.substring(Ie)}`,gt=ct+nt.length+2;je(mt),D(!1),k(""),requestAnimationFrame(()=>{const ht=X.current;ht&&(ht.selectionStart=gt,ht.selectionEnd=gt,ht.focus()),Ne(mt,gt)})},[m.execution.prompt,je,Ne]),ie=$e.useCallback($=>{const _=m.execution.prompt,Ie=X.current?.selectionStart??_.length,Ke=_.substring(0,Ie).lastIndexOf("@"),nt=Ke!==-1?Ke:Ie,ct=`${_.substring(0,nt)}@${$} ${_.substring(Ie)}`,mt=nt+$.length+2;je(ct),D(!1),k(""),requestAnimationFrame(()=>{const gt=X.current;gt&&(gt.selectionStart=mt,gt.selectionEnd=mt,gt.focus()),Ne(ct,mt)})},[m.execution.prompt,je,Ne]),ee=$e.useCallback($=>{const _=`/${$.name} `;je(_),O(!1),B(""),T(!1),requestAnimationFrame(()=>{const ge=X.current;ge&&(ge.focus(),ge.selectionStart=ge.value.length,ge.selectionEnd=ge.value.length),Ne(_,_.length)})},[je,Ne]),ke=$e.useCallback(($,_)=>{const ge=m.execution.prompt,Re=X.current?.selectionStart??ge.length,nt=ge.substring(0,Re).lastIndexOf("#"),ct=nt!==-1?nt:Re,mt=`${ge.substring(0,ct)}#${_} ${ge.substring(Re)}`,gt=ct+_.length+2;je(mt),T(!1),R(""),requestAnimationFrame(()=>{const ht=X.current;ht&&(ht.selectionStart=gt,ht.selectionEnd=gt,ht.focus()),Ne(mt,gt)})},[m.execution.prompt,je,Ne]),ae=$e.useCallback($=>{if(E&&te.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")){$.preventDefault(),te.current.handleKeyDown($.key);return}v&&V.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")&&($.preventDefault(),V.current.handleKeyDown($.key)),z&&Z.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")&&($.preventDefault(),Z.current.handleKeyDown($.key))},[E,v,z]),U=$e.useCallback(async()=>{const $=Y2(m,i);if($){fe.error($);return}const _={...m.id?{id:m.id}:{},name:m.name.trim(),enabled:m.enabled,schedule:{kind:m.schedule.kind,timezone:m.schedule.timezone.trim(),...m.schedule.kind==="cron"?{cron:m.schedule.cronExpression.trim()}:m.schedule.kind==="once"?{date:m.schedule.onceDate,time:m.schedule.onceTime}:{times:Q2(m.schedule.times),...m.schedule.kind==="weekly"?{weekdays:m.schedule.weekdays}:{}}},execution:{prompt:m.execution.prompt,providerID:m.execution.providerID,modelID:m.execution.modelID,...m.execution.variant.trim()?{variant:m.execution.variant.trim()}:{},...m.execution.agent.trim()?{agent:m.execution.agent.trim()}:{},...m.execution.permissionAutoAccept?{permissionAutoAccept:!0}:{},...m.execution.goalEnabled?{goalEnabled:!0}:{},...m.execution.goalEnabled&&m.execution.goalTokenBudget?{goalTokenBudget:m.execution.goalTokenBudget}:{}},...m.state?{state:m.state}:{}};j(!0);try{await o(_),r(!1)}catch(ge){fe.error(ge instanceof Error?ge.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{j(!1)}},[m,r,o,i]),le=$e.useId(),_e=$e.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]'),[]),De=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),ce=i("sessions.scheduledTasks.editor.description"),he=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Nn,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(sr,{id:"sched-name",value:m.name,onChange:$=>y(_=>({..._,name:$.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(xn,{value:m.schedule.kind,onValueChange:$=>{y(_=>({..._,schedule:{..._.schedule,kind:$,...$==="cron"&&!_.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(bn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(rn,{children:$=>i($==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":$==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":$==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(yn,{children:[s.jsx(ys,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(ys,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(ys,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(ys,{value:"cron",children:i("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),m.schedule.kind==="cron"?s.jsx(X2,{draft:m,setDraft:y,locale:c,t:i}):m.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:G,children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:Pe(xa({size:"default"}),"w-fit max-w-full"),onClick:()=>N($=>!$),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(A,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:$2(m.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),w?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>P($=>Su($,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:Ue,children:s.jsx(A,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}).format(L)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>P($=>Su($,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(A,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:be.map(($,_)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:$},`${$}-${_}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:_2(L,Q).map(({date:$,inCurrentMonth:_})=>{const ge=ju($),Ie=ge===m.schedule.onceDate,Re=Du($,we),Ke=$.getTime()<we.getTime(),nt=Ie?"bg-interactive-selection text-interactive-selection-foreground":Ke?"text-muted-foreground/40":_?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{Ke||(q(ge),N(!1))},disabled:Ke,className:["h-8 rounded-md typography-ui-label",nt,Re&&!Ie?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",Ke?"cursor-not-allowed opacity-45":""].join(" "),children:$.getDate()},ge)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:Le||""}),s.jsx(He,{type:"button",size:"xs",variant:"ghost",onClick:()=>{q(ju(we)),P(new Date(we.getFullYear(),we.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(Cu,{value:m.schedule.onceTime,use24Hour:se,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:$=>y(_=>({..._,schedule:{..._.schedule,onceTime:$}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(xn,{value:m.schedule.timezone,onValueChange:$=>{y(_=>({..._,schedule:{..._.schedule,timezone:$}}))},children:[s.jsx(bn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(rn,{})}),s.jsx(yn,{children:El.map($=>s.jsx(ys,{value:$,children:$},$))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[m.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:Me.map($=>{const _=m.schedule.weekdays.includes($.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",_?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(oo,{checked:_,onChange:ge=>ne($.value,ge),ariaLabel:$.label}),s.jsx("button",{type:"button",onClick:()=>ne($.value,!_),className:"group-hover:text-foreground",children:$.label})]},$.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:m.schedule.times.map(($,_)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Cu,{value:$,use24Hour:se,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:ge=>oe(_,ge)}),m.schedule.times.length>1?s.jsx(He,{type:"button",size:"icon",variant:"ghost",onClick:()=>ue(_),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null]},_))}),s.jsx("div",{children:s.jsxs(He,{type:"button",size:"sm",variant:"outline",onClick:Ae,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(xn,{value:m.schedule.timezone,onValueChange:$=>{y(_=>({..._,schedule:{..._.schedule,timezone:$}}))},children:[s.jsx(bn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(rn,{})}),s.jsx(yn,{children:El.map($=>s.jsx(ys,{value:$,children:$},$))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Nn,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Kl,{providerId:m.execution.providerID,modelId:m.execution.modelID,onChange:($,_)=>{y(ge=>({...ge,execution:{...ge.execution,providerID:$,modelID:_,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(xn,{value:J,disabled:!W,onValueChange:$=>{y(_=>({..._,execution:{..._.execution,variant:$==="__default"?"":$}}))},children:[s.jsx(bn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(rn,{children:$=>$==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):$})}),s.jsxs(yn,{children:[s.jsx(ys,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),xe.map($=>s.jsx(ys,{value:$,children:$},$))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Nn,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(kg,{agentName:m.execution.agent,filter:$=>xf($.mode),onChange:$=>y(_=>({..._,execution:{..._.execution,agent:$}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Nn,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(So,{id:"sched-prompt",ref:X,value:m.execution.prompt,onChange:$=>{const _=$.target.value;je(_);const ge=$.target.selectionStart??_.length;Ne(_,ge)},onKeyDown:ae,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),E?s.jsx(vf,{ref:te,searchQuery:M,onCommandSelect:ee,onClose:()=>O(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,v?s.jsx(jf,{ref:V,searchQuery:F,onFileSelect:ve,onAgentSelect:ie,onClose:()=>D(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,z?s.jsx(Sf,{ref:Z,searchQuery:I,onSnippetSelect:ke,onClose:()=>T(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]}),m.execution.goalEnabled?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-8 gap-y-2",children:[s.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[s.jsx(oo,{checked:m.execution.goalTokenBudget!==null,onChange:$=>y(_=>({..._,execution:{..._.execution,goalTokenBudget:$?2e5:null}})),ariaLabel:i("sessions.scheduledTasks.editor.goal.budgetAria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.goal.budgetLabel")})]}),m.execution.goalTokenBudget!==null?s.jsx(Ng,{value:m.execution.goalTokenBudget,onValueChange:$=>{typeof $=="number"&&Number.isFinite($)&&$>0&&y(_=>({..._,execution:{..._.execution,goalTokenBudget:Math.floor($)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),me=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(oo,{checked:m.enabled,onChange:$=>y(_=>({..._,enabled:$})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe(wu),onClick:()=>y($=>({...$,execution:{...$.execution,permissionAutoAccept:!$.execution.permissionAutoAccept}})),"aria-pressed":m.execution.permissionAutoAccept,"aria-label":i("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:m.execution.permissionAutoAccept?s.jsx(A,{name:"shield-check",className:"h-[18px] w-[18px]",style:{color:"var(--status-info)"},"aria-hidden":"true"}):s.jsx(A,{name:"shield-user",className:"h-[18px] w-[18px]","aria-hidden":"true"})})}),s.jsx(Nt,{side:"top",sideOffset:6,children:i("sessions.scheduledTasks.editor.permissionAutoAccept.label")})]}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",className:Pe(wu,m.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>y($=>({...$,execution:{...$.execution,goalEnabled:!$.execution.goalEnabled}})),"aria-pressed":m.execution.goalEnabled,"aria-label":i("sessions.scheduledTasks.editor.goal.aria"),children:m.execution.goalEnabled?s.jsx(A,{name:"target-fill",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"}):s.jsx(A,{name:"target",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"})})}),s.jsx(Nt,{side:"top",sideOffset:6,children:i("sessions.scheduledTasks.editor.goal.label")})]}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:C,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(He,{type:"button",size:"sm",onClick:U,disabled:C,children:i(C?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return g?s.jsx(ka,{open:e,title:De,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:$=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:De}),$]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:ce})]}),footer:me,children:he}):s.jsx(Ps,{open:e,onOpenChange:$=>{!$&&_e()||r($)},children:s.jsxs(Is,{"aria-describedby":le,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Hs,{id:le,className:"sr-only",children:ce}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(Ls,{className:"typography-ui-label font-medium text-foreground",children:De}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:ce})]})}),s.jsx(Sa,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:he})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:me})})]})})}function Z2(t){return Wo(t,{min:0,max:23})}function eN(t,e){return Wo(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function tN(t,e){const n=Number(t),r=Number(e),o=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,i=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(o).padStart(2,"0")}:${String(i).padStart(2,"0")}`}function sN(t){return s.jsx(ys,{value:t,children:t},t)}const nN=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,o)=>r.localeCompare(o))},rN=(t,e)=>{const n=nN(t).join(", ")||"--:--",r=o=>e(o===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":o===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":o===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":o===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":o===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":o===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":o===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:ro(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const o=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(i=>r(i)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:o,time:n,timezone:ro(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:o,time:n})}if(t.schedule.kind==="once"){const o=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),i=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:o,time:i,timezone:ro(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.once",{date:o,time:i})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:ro(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},oN=(t,e)=>!t||!Number.isFinite(t)?"":nf(t,e),Iu=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),o=6e4,i=60*o,c=24*i,l=n>=0;if(r<o)return e(l?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const f=Math.round(r/o);return l?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:f}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:f})}if(r<c){const f=Math.floor(r/i),p=Math.round(r%i/o),x=p>0?`${f}h ${p}m`:`${f}h`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:x}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:x})}const d=Math.floor(r/c),u=Math.round(r%c/i),h=u>0?`${d}d ${u}h`:`${d}d`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:h}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:h})},iN={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},aN=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function Ru(){const{t}=ft(),e=Ee(I=>I.isScheduledTasksDialogOpen),n=Ee(I=>I.setScheduledTasksDialogOpen),r=Ee(I=>I.isMobile),o=Ee(I=>I.timeFormatPreference),i=ds(I=>I.projects),c=ds(I=>I.getActiveProject()),l=vs(I=>I.homeDirectory),{currentTheme:d}=lo(),[u,h]=$e.useState(""),[f,p]=$e.useState([]),[x,b]=$e.useState(!0),[S,g]=$e.useState(!1),[m,y]=$e.useState(null),[C,j]=$e.useState(null),w=$e.useMemo(()=>i.find(I=>I.id===u)||null,[i,u]),N=$e.useCallback(I=>{const R=I.label?.trim()||Vr(I.path,l||void 0),L=I.icon?Ql[I.icon]:null,P=I.color?Xl[I.color]:void 0,G=L?s.jsx(A,{name:L,className:"h-3.5 w-3.5 shrink-0",style:P?{color:P}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:P?{color:P}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[I.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:I.iconBackground?{backgroundColor:I.iconBackground}:void 0,children:s.jsx(Jl,{project:{id:I.id,iconImage:I.iconImage??null},options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:G})}):G,s.jsx("span",{className:"truncate",children:R})]})},[l,d.metadata.variant,d.colors.surface.foreground]),v=$e.useCallback(async(I,R)=>{if(!I){p([]);return}R?.silent||b(!0);try{const L=await T2(I);L.sort((P,G)=>{if(P.enabled!==G.enabled)return P.enabled?-1:1;const X=P.name.localeCompare(G.name);return X!==0?X:(P.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(G.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),p(L)}catch(L){fe.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),R?.silent||p([])}finally{R?.silent||b(!1)}},[t]);$e.useEffect(()=>{if(!e)return;const I=c?.id||i[0]?.id||"";h(I),I?v(I):(p([]),b(!1))},[e,c,i,v]),$e.useEffect(()=>{if(!e)return;let I=null;const R=Hm(L=>{L.type==="scheduled-task-ran"&&L.projectId===u&&(I&&clearTimeout(I),I=setTimeout(()=>{v(u,{silent:!0})},400))});return()=>{I&&clearTimeout(I),R()}},[e,u,v]);const D=$e.useCallback(async I=>{if(!u)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await yu(u,I),await v(u),fe.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[u,v,t]),F=$e.useCallback(async(I,R)=>{if(u){j(I.id),p(L=>L.map(P=>P.id===I.id?{...P,enabled:R}:P));try{await yu(u,{...I,enabled:R}),await v(u,{silent:!0})}catch(L){fe.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await v(u,{silent:!0})}finally{j(null)}}},[u,v,t]),k=$e.useCallback(async I=>{if(!(!u||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:I.name})))){j(I.id);try{await E2(u,I.id),await v(u,{silent:!0}),fe.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(L){fe.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{j(null)}}},[u,v,t]),E=$e.useCallback(async I=>{if(u){j(I.id);try{const{sessionId:R}=await F2(u,I.id);if(await Promise.all([v(u,{silent:!0}),ea()]),fe.success(t("sessions.scheduledTasks.dialog.toast.started")),R){const L=i.find(P=>P.id===u);Je.getState().setCurrentSession(R,L?.path??null),Ee.getState().setActiveMainTab("chat")}}catch(R){fe.error(R instanceof Error?R.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{j(null)}}},[u,i,v,t]),O=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(xn,{value:u||"__none",onValueChange:I=>{const R=I==="__none"?"":I;h(R),R?v(R):p([])},children:[s.jsx(bn,{size:"lg",className:r?"w-full":void 0,children:w?s.jsx(rn,{children:N(w)}):s.jsx(rn,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(yn,{children:[i.length===0?s.jsx(ys,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(I=>s.jsx(ys,{value:I.id,children:N(I)},I.id))]})]})]}),M=()=>{y(null),g(!0)},B=I=>{h(I),I?v(I):p([])},z=s.jsx("div",{className:"min-h-[280px]",children:x?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(A,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):f.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(u?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:f.map(I=>{const R=C===I.id,L=I.state?.lastStatus||"idle",P=iN[L],G=t(L==="success"?"sessions.scheduledTasks.dialog.status.success":L==="error"?"sessions.scheduledTasks.dialog.status.error":L==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),X=I.state?.nextRunAt,V=I.state?.lastRunAt;return s.jsxs("div",{className:Pe("rounded-lg border border-border p-4 transition-opacity",!I.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:I.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:rN(I,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(A,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),X?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Iu(X,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:oN(X,o)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(A,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),L==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(A,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):V?s.jsxs(s.Fragment,{children:[P.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${P.tone})`},children:[s.jsx(A,{name:P.Icon,className:"h-3.5 w-3.5"}),G]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Iu(V,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),I.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:aN("error"),children:[s.jsx(A,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:I.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:Pe("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",I.enabled?"text-foreground":"text-muted-foreground",R&&"cursor-not-allowed opacity-50"),children:[s.jsx(oo,{checked:I.enabled,onChange:te=>{F(I,te)},ariaLabel:I.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:I.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:I.name}),disabled:R}),I.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{E(I)},disabled:R,children:[s.jsx(A,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{y(I),g(!0)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:I.name}),children:[s.jsx(A,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(He,{variant:"destructive",size:"sm",onClick:()=>{k(I)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:I.name}),children:s.jsx(A,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},I.id)})})}),T=s.jsxs("div",{className:"space-y-4",children:[O,z]});return s.jsxs(s.Fragment,{children:[r?s.jsx(ka,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:I=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),I]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(He,{className:"w-full",onClick:M,disabled:!u,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:T}):e?s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsx("div",{className:"flex w-60 flex-shrink-0 flex-col border-r border-border/50",children:s.jsx("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:i.length===0?s.jsx("div",{className:"px-2 py-2 typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.empty")}):i.map(I=>s.jsx("button",{type:"button",onClick:()=>B(I.id),className:Pe("flex w-full min-w-0 items-center rounded-md px-2 py-1.5 text-left typography-ui-label focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",u===I.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:N(I)},I.id))})}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("div",{className:"flex items-center px-6 pt-3",children:s.jsxs(He,{size:"sm",onClick:M,disabled:!u,children:[s.jsx(A,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-4",children:s.jsx("div",{className:"mx-auto w-full max-w-3xl",children:z})})]})]})}):null,s.jsx(J2,{open:S,task:m,onOpenChange:g,onSave:D})]})}const qi=100;function Mu(){const t=ot.c(105),{t:e}=ft(),n=Ee(gN),r=Ee(pN),o=Ee(hN),i=Je(mN),c=Je(fN),l=vs(uN);let d;t[0]!==n?(d=te=>n?te.archivedSessions:[],t[0]=n,t[1]=d):d=t[1];const u=gn(er(d)),[h,f]=a.useState(""),[p,x]=a.useState(null),[b,S]=a.useState(qi);let g;t[2]!==h?(g=h.trim().toLowerCase(),t[2]=h,t[3]=g):g=t[3];const m=g;let y;e:{if(!n){let Z;t[4]===Symbol.for("react.memo_cache_sentinel")?(Z=[],t[4]=Z):Z=t[4],y=Z;break e}let te;t[5]!==u?(te=[...u].sort(dN),t[5]=u,t[6]=te):te=t[6],y=te}const C=y;let j;if(t[7]!==l||t[8]!==C||t[9]!==e){const te=new Map;for(const Z of C){const de=_t(Bn(Z))??"",Fe=te.get(de);if(Fe){Fe.sessions.push(Z);continue}te.set(de,{directory:de,label:de?Vr(de,l)||de:e("sessions.archivePage.otherProjects"),sessions:[Z]})}j=[...te.values()].sort(cN),t[7]=l,t[8]=C,t[9]=e,t[10]=j}else j=t[10];const w=j;let N;e:{if(m){let Z;if(t[11]!==m||t[12]!==C){let de;t[14]!==m?(de=Fe=>(Fe.title??"").toLowerCase().includes(m),t[14]=m,t[15]=de):de=t[15],Z=C.filter(de),t[11]=m,t[12]=C,t[13]=Z}else Z=t[13];N=Z;break e}if(p===null){N=C;break e}let te;t[16]!==w||t[17]!==p?(te=w.find(Z=>Z.directory===p)?.sessions??[],t[16]=w,t[17]=p,t[18]=te):te=t[18],N=te}const v=N;let D,F,k,E,O,M,B,z,T,I;if(t[19]!==u.length||t[20]!==w||t[21]!==v||t[22]!==l||t[23]!==m||t[24]!==n||t[25]!==h||t[26]!==p||t[27]!==o||t[28]!==i||t[29]!==r||t[30]!==e||t[31]!==c||t[32]!==b){O=Symbol.for("react.early_return_sentinel");e:{const te=v.slice(0,b);D=v.length-te.length;const Z=u.length;let de;t[43]===Symbol.for("react.memo_cache_sentinel")?(de=be=>{x(be),S(qi)},t[43]=de):de=t[43];const Fe=de;let se;t[44]!==o||t[45]!==i||t[46]!==r?(se=be=>{const q=_t(Bn(be));i(be.id,q??void 0),o("chat"),r(!1)},t[44]=o,t[45]=i,t[46]=r,t[47]=se):se=t[47];const Q=se;let Me;t[48]!==e||t[49]!==c?(Me=be=>{c(be.id).then(q=>{q?fe.success(e("sessions.sidebar.session.restore.success")):fe.error(e("sessions.sidebar.session.restore.error"))})},t[48]=e,t[49]=c,t[50]=Me):Me=t[50];const xe=Me;if(!n){O=null;break e}let W;t[51]!==e?(W=(be,q,Ne,je,ve,ie,ee)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:ve,title:ie,className:Pe("flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left typography-ui-label transition-[padding] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",ee?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",je?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:q}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:Ne})]}),ee?s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>Gn.requestDelete({sessions:ee,mode:"session"}),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteProjectAria",{label:q}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(Nt,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},be),t[51]=e,t[52]=W):W=t[52];const J=W;E="absolute inset-0 z-10 flex flex-col bg-background",F="flex min-h-0 flex-1";let ne;if(t[53]!==J||t[54]!==p||t[55]!==e||t[56]!==Z){let be;t[58]===Symbol.for("react.memo_cache_sentinel")?(be=()=>Fe(null),t[58]=be):be=t[58],ne=J("__all__",e("sessions.archivePage.allDirectories"),Z,p===null,be),t[53]=J,t[54]=p,t[55]=e,t[56]=Z,t[57]=ne}else ne=t[57];let oe;if(t[59]!==w||t[60]!==J||t[61]!==p){let be;t[63]!==J||t[64]!==p?(be=q=>J(q.directory||"__none__",q.label,q.sessions.length,p===q.directory,()=>Fe(q.directory),q.directory||void 0,q.sessions),t[63]=J,t[64]=p,t[65]=be):be=t[65],oe=w.map(be),t[59]=w,t[60]=J,t[61]=p,t[62]=oe}else oe=t[62];t[66]!==ne||t[67]!==oe?(k=s.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50",children:s.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[ne,oe]})}),t[66]=ne,t[67]=oe,t[68]=k):k=t[68],T="flex min-w-0 flex-1 flex-col";let ue;t[69]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx(A,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t[69]=ue):ue=t[69];let Ae;t[70]===Symbol.for("react.memo_cache_sentinel")?(Ae=be=>{f(be.target.value),S(qi)},t[70]=Ae):Ae=t[70];let we;t[71]!==e?(we=e("sessions.archivePage.searchPlaceholder"),t[71]=e,t[72]=we):we=t[72];let Se;t[73]!==h||t[74]!==we?(Se=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[ue,s.jsx("input",{value:h,onChange:Ae,placeholder:we,className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),t[73]=h,t[74]=we,t[75]=Se):Se=t[75];let Le;t[76]!==v.length||t[77]!==e?(Le=v.length===1?e("sessions.archivePage.countSingle",{count:v.length}):e("sessions.archivePage.countPlural",{count:v.length}),t[76]=v.length,t[77]=e,t[78]=Le):Le=t[78];let Ue;t[79]!==Le?(Ue=s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:Le}),t[79]=Le,t[80]=Ue):Ue=t[80],t[81]!==Se||t[82]!==Ue?(I=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[Se,Ue]}),t[81]=Se,t[82]=Ue,t[83]=I):I=t[83],z="min-h-0 flex-1 overflow-y-auto px-6 py-3",M="mx-auto w-full max-w-3xl space-y-0.5",B=te.length===0?s.jsx("div",{className:"py-10 text-center text-muted-foreground",children:s.jsx("p",{className:"typography-ui-label font-semibold",children:e(m?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived")})}):te.map(be=>{const q=_t(Bn(be))??"",Ne=q?Vr(q,l)||q:null;return s.jsxs("div",{className:"group relative flex cursor-pointer items-center gap-3 rounded-md py-1 pl-2 pr-2 transition-[padding] hover:bg-interactive-hover/40 hover:pr-14 focus-within:pr-14",onClick:()=>Q(be),role:"button",tabIndex:0,onKeyDown:je=>{(je.key==="Enter"||je.key===" ")&&(je.preventDefault(),Q(be))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:be.title||e("sessions.sidebar.session.untitled")}),m&&Ne?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:q,children:Ne}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:yf(be.time?.archived??be.time?.updated??be.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:je=>{je.stopPropagation(),xe(be)},className:"absolute right-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.restoreSessionAria",{title:be.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(A,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:je=>{je.stopPropagation(),Gn.requestDelete({sessions:[be],mode:"session"})},className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteSessionAria",{title:be.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(A,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},be.id)})}t[19]=u.length,t[20]=w,t[21]=v,t[22]=l,t[23]=m,t[24]=n,t[25]=h,t[26]=p,t[27]=o,t[28]=i,t[29]=r,t[30]=e,t[31]=c,t[32]=b,t[33]=D,t[34]=F,t[35]=k,t[36]=E,t[37]=O,t[38]=M,t[39]=B,t[40]=z,t[41]=T,t[42]=I}else D=t[33],F=t[34],k=t[35],E=t[36],O=t[37],M=t[38],B=t[39],z=t[40],T=t[41],I=t[42];if(O!==Symbol.for("react.early_return_sentinel"))return O;let R;t[84]!==D||t[85]!==e?(R=D>0?s.jsx("button",{type:"button",onClick:()=>S(lN),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,t[84]=D,t[85]=e,t[86]=R):R=t[86];let L;t[87]!==R||t[88]!==M||t[89]!==B?(L=s.jsxs("div",{className:M,children:[B,R]}),t[87]=R,t[88]=M,t[89]=B,t[90]=L):L=t[90];let P;t[91]!==L||t[92]!==z?(P=s.jsx("div",{className:z,children:L}),t[91]=L,t[92]=z,t[93]=P):P=t[93];let G;t[94]!==P||t[95]!==T||t[96]!==I?(G=s.jsxs("div",{className:T,children:[I,P]}),t[94]=P,t[95]=T,t[96]=I,t[97]=G):G=t[97];let X;t[98]!==F||t[99]!==k||t[100]!==G?(X=s.jsxs("div",{className:F,children:[k,G]}),t[98]=F,t[99]=k,t[100]=G,t[101]=X):X=t[101];let V;return t[102]!==E||t[103]!==X?(V=s.jsx("div",{className:E,children:X}),t[102]=E,t[103]=X,t[104]=V):V=t[104],V}function lN(t){return t+qi}function cN(t,e){return e.sessions.length-t.sessions.length}function dN(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function uN(t){return t.homeDirectory}function fN(t){return t.unarchiveSession}function mN(t){return t.setCurrentSession}function hN(t){return t.setActiveMainTab}function pN(t){return t.setArchivePageOpen}function gN(t){return t.isArchivePageOpen}function Tu(){const t=ot.c(18),{t:e}=ft(),n=Ee(yN),r=Ee(bN),o=ds(xN);let i;t[0]!==n?(i=x=>x.projects.find(b=>b.id===n)??null,t[0]=n,t[1]=i):i=t[1];const c=ds(i);if(!n||!c)return null;let l;t[2]!==c.id||t[3]!==o||t[4]!==r?(l=()=>{o(c.id),r(!0)},t[2]=c.id,t[3]=o,t[4]=r,t[5]=l):l=t[5];let d;t[6]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(A,{name:"node-tree",className:"mr-1 h-3.5 w-3.5"}),t[6]=d):d=t[6];let u;t[7]!==e?(u=e("sessions.sidebar.project.actions.newWorktree"),t[7]=e,t[8]=u):u=t[8];let h;t[9]!==l||t[10]!==u?(h=s.jsx("div",{className:"flex items-center",children:s.jsxs(He,{size:"sm",onClick:l,children:[d,u]})}),t[9]=l,t[10]=u,t[11]=h):h=t[11];let f;t[12]!==c.id||t[13]!==c.path?(f=s.jsx(Nx,{projectRef:{id:c.id,path:c.path},sections:"list-only"}),t[12]=c.id,t[13]=c.path,t[14]=f):f=t[14];let p;return t[15]!==h||t[16]!==f?(p=s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-4",children:[h,f]})})}),t[15]=h,t[16]=f,t[17]=p):p=t[17],p}function xN(t){return t.setActiveProjectIdOnly}function bN(t){return t.setNewWorktreeDialogOpen}function yN(t){return t.worktreesPageProjectId}const Fl=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),wN=(t,e)=>{const n=Fl(t),r=Fl(e);return`${n}-${r}`.substring(0,60)},Eu=(t,e)=>`${t}/${e}`,vN=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Fu=(t,e)=>{const n=vN(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Tg(t.id,n),Je.getState().markSessionAsOpenChamberCreated(t.id),gn.getState().upsertSession(o);try{ta().ensureChild(n,{bootstrap:!1}).setState(c=>{const l=c.session.findIndex(u=>u.id===t.id);if(l>=0&&c.session[l]===o)return c;const d=l>=0?c.session.map((u,h)=>h===l?o:u):[...c.session,o].sort((u,h)=>u.id.localeCompare(h.id));return{session:d,sessionTotal:Math.max(c.sessionTotal,d.length),limit:Math.max(c.limit,d.length)}})}catch{}return o},jN=()=>{const t=ds.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(o=>o.id===e);if(n?.path)return{id:n.id,path:n.path};const r=vs.getState().currentDirectory??null;if(r&&r.trim().length>0){const o=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${o}`,path:o}}return null},al=zo()(Wf(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:o,files:i,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let l=0;l<r.length;l++){if(!r[l].prompt.trim())return t({error:`Group ${l+1}: prompt is required`}),null;if(r[l].models.length<1)return t({error:`Group ${l+1}: select at least 1 model`}),null;if(r[l].models.length>5)return t({error:`Group ${l+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const l=jN();if(!l)return t({error:"Select a project",isLoading:!1}),null;const d=l.path,h=await wf(d)&&e.isolateRuns!==!1,f=Fl(n),p=h?await gi(d):void 0,x=h?await Cg(d):null,b=[],S=c?.filter(j=>j.trim().length>0)??[];for(let j=0;j<r.length;j++){const w=r[j],N=w.prompt,v=new Map;for(const F of w.models){const k=`${F.providerID}:${F.modelID}`;v.set(k,(v.get(k)||0)+1)}const D=new Map;for(const F of w.models){const k=`${F.providerID}:${F.modelID}`,E=v.get(k)||1,O=(D.get(k)||0)+1;D.set(k,O);const M=wN(F.providerID,F.modelID),B=r.length>1?`g${j+1}`:void 0,z=E>1?Eu(f,`${M}/${O}`):Eu(f,M),T=B?`${B}/${z}`:z,I=Mk({groupSlug:f,runGroup:B,providerID:F.providerID,modelID:F.modelID,index:E>1?O:void 0});try{if(!h){const G=await Fn.withDirectory(d,()=>Fn.createSession({title:I}));Fu(G,d),b.push({sessionId:G.id,worktreePath:d,providerID:F.providerID,modelID:F.modelID,variant:F.variant,prompt:N});continue}const R=await Ag(l,{preferredName:T,mode:"new",branchName:T,worktreeName:T,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:S,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:x}),L={...R,createdFromBranch:p,kind:"standard"};await Dg(l)&&await Pg(R.path);const P=await Fn.withDirectory(R.path,()=>Fn.createSession({title:I}));Fu(P,R.path),Je.getState().setWorktreeMetadata(P.id,L),b.push({sessionId:P.id,worktreePath:R.path,providerID:F.providerID,modelID:F.modelID,variant:F.variant,prompt:N})}catch(R){console.warn("[MultiRun] Failed to create session:",R)}}}const g=c?.filter(j=>j.trim().length>0)??[];g.length>0&&Ig(l,g).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const m=b.map(j=>j.sessionId),y=b[0]?.sessionId??null;if(m.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const C=i?.map(j=>({type:"file",mime:j.mime,filename:j.filename,url:j.url}));return(async()=>{try{const j=Rg.getState().expandText;await Promise.allSettled(b.map(async w=>{try{const N=await j(w.prompt).catch(()=>w.prompt);await Mg({sessionId:w.sessionId,directory:w.worktreePath,content:N,providerID:w.providerID,modelID:w.modelID,variant:w.variant,agent:o,files:C})}catch(N){console.warn("[MultiRun] Failed to start run:",N)}}))}catch(j){console.warn("[MultiRun] Failed to start runs:",j)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:m,firstSessionId:y}}catch(l){return t({error:l instanceof Error?l.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"}));function qm(t){const e=ot.c(30),{git:n}=_n(),r=ja(t),o=Wl(t),i=Ul(t),c=Eg(t),l=nn(AN),d=nn(CN);let u,h;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==o||e[4]!==i?(u=()=>{!t||!n||o!==null||i||d(t,n,{silent:!0})},h=[t,n,d,o,i],e[0]=t,e[1]=d,e[2]=n,e[3]=o,e[4]=i,e[5]=u,e[6]=h):(u=e[5],h=e[6]),a.useEffect(u,h);let f;e[7]!==r?.all||e[8]!==t||e[9]!==l||e[10]!==n||e[11]!==o?(f=()=>{!t||!n||o===!0&&(r?.all||l(t,n))},e[7]=r?.all,e[8]=t,e[9]=l,e[10]=n,e[11]=o,e[12]=f):f=e[12];const p=r?.all;let x;e[13]!==t||e[14]!==l||e[15]!==n||e[16]!==o||e[17]!==p?(x=[t,n,o,p,l],e[13]=t,e[14]=l,e[15]=n,e[16]=o,e[17]=p,e[18]=x):x=e[18],a.useEffect(f,x);const b=i||o===!0&&c;let S;e:{if(!r?.all){let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v=[],e[19]=v):v=e[19],S=v;break e}let N;e[20]!==r.all?(N=r.all.filter(NN).sort(),e[20]=r.all,e[21]=N):N=e[21],S=N}const g=S;let m;e:{if(!r?.all){let v;e[22]===Symbol.for("react.memo_cache_sentinel")?(v=[],e[22]=v):v=e[22],m=v;break e}let N;e[23]!==r.all?(N=r.all.filter(kN).map(SN).sort(),e[23]=r.all,e[24]=N):N=e[24],m=N}const y=m;let C;e:{if(!t){C=null;break e}if(o!==null){C=o;break e}if(b){C=null;break e}C=r?.all?!0:null}const j=C;let w;return e[25]!==j||e[26]!==b||e[27]!==g||e[28]!==y?(w={localBranches:g,remoteBranches:y,isLoading:b,isGitRepository:j},e[25]=j,e[26]=b,e[27]=g,e[28]=y,e[29]=w):w=e[29],w}function SN(t){return t.replace(/^remotes\//,"")}function kN(t){return t.startsWith("remotes/")}function NN(t){return!t.startsWith("remotes/")}function CN(t){return t.fetchStatus}function AN(t){return t.fetchBranches}const DN=({directory:t,value:e,onChange:n,className:r,disabled:o,id:i})=>{const{t:c}=ft(),{localBranches:l,remoteBranches:d,isLoading:u,isGitRepository:h}=qm(t),f=a.useMemo(()=>[...l,...d.map(x=>`remotes/${x}`)],[l,d]);a.useEffect(()=>{if(o||u||f.length===0||e&&f.includes(e))return;const x=e;let b=!1;return(async()=>{try{const g=t?await gi(t).catch(()=>null):null;if(b)return;const m=localStorage.getItem(Yc),{sourceBranch:y,shouldClearSavedSourceBranch:C}=Cx({branches:f,savedSourceBranch:m,rootBranch:g});if(C&&localStorage.removeItem(Yc),b||x&&f.includes(x))return;y&&n(y)}catch{}})(),()=>{b=!0}},[f,t,o,u,n,e]);const p=o||!h||u;return s.jsxs("div",{children:[s.jsxs(xn,{value:e,onValueChange:n,disabled:p,children:[s.jsx(bn,{id:i,size:"lg",className:Pe("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(rn,{placeholder:c(u?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(yn,{className:"max-h-[280px] max-w-[320px]",children:u?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.loadingBranches")}):l.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[l.length>0&&s.jsxs(pl,{children:[s.jsx(Vc,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),l.map(x=>s.jsx(ys,{value:x,className:"whitespace-normal break-all",children:x},x))]}),l.length>0&&d.length>0&&s.jsx(Fg,{}),d.length>0&&s.jsxs(pl,{children:[s.jsx(Vc,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),d.map(x=>s.jsx(ys,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),h===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},PN=10*1024*1024,ll=5,Yi=t=>{const e=ot.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(kt,{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(A,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let o;return e[1]!==n?(o=s.jsxs(St,{children:[r,s.jsx(Nt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=o):o=e[2],o},to=t=>{const e=ot.c(9),{htmlFor:n,required:r,children:o,info:i}=t;let c;e[0]!==r?(c=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=c):c=e[1];let l;e[2]!==o||e[3]!==n||e[4]!==c?(l=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,c]}),e[2]=o,e[3]=n,e[4]=c,e[5]=l):l=e[5];const d=i&&i;let u;return e[6]!==l||e[7]!==d?(u=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,d]}),e[6]=l,e[7]=d,e[8]=u):u=e[8],u},Ou=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=ft(),[i,c]=a.useState(""),[l,d]=a.useState(()=>[{id:ii(),prompt:"",models:[]}]),[u,h]=a.useState(""),[f,p]=a.useState([]),[x,b]=a.useState(!1),[S,g]=a.useState([]),[m,y]=a.useState(!1),[C,j]=a.useState(!1),[w,N]=a.useState(!0),v=a.useRef(null),D=vs(ee=>ee.currentDirectory??null),F=vs(ee=>ee.homeDirectory??null),k=a.useMemo(()=>{if(typeof window>"u")return null;const ee=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof ee=="string"&&ee.trim().length>0?ee.trim():null},[]),E=ds(ee=>ee.activeProjectId),O=ds(ee=>ee.setActiveProjectIdOnly),M=ds(ee=>ee.projects),[B,z]=a.useState(()=>E??null);a.useEffect(()=>{if(E){z(E);return}!B&&M.length>0&&z(M[0].id)},[E,M,B]);const T=a.useMemo(()=>B?M.find(ee=>ee.id===B)??null:null,[M,B]),I=T?.path??D,R=a.useCallback(ee=>{z(ee),ee!==E&&O(ee)},[E,O]),{currentTheme:L}=lo(),P=a.useCallback(ee=>{const ke=ee.label?.trim()||Vr(ee.path,F),ae=ee.icon?Ql[ee.icon]:null,U=ee.color?Xl[ee.color]:void 0,le=ae?s.jsx(A,{name:ae,className:"h-3.5 w-3.5 shrink-0",style:U?{color:U}:void 0}):s.jsx(A,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:U?{color:U}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[ee.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:ee.iconBackground?{backgroundColor:ee.iconBackground}:void 0,children:s.jsx(Jl,{project:{id:ee.id,iconImage:ee.iconImage??null},options:{themeVariant:L.metadata.variant,iconColor:L.colors.surface.foreground},className:"h-full w-full object-contain",fallback:le})}):le,s.jsx("span",{className:"truncate",children:ke})]})},[F,L.metadata.variant,L.colors.surface.foreground]),G=a.useMemo(()=>{if(T?.path)return{id:T.id,path:T.path};const ee=D??k;return ee?{id:`path:${ee}`,path:ee}:null},[T,D,k]),[X]=a.useState(()=>typeof window<"u"?ur():!1),V=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),te=of(),Z=a.useMemo(()=>{if(typeof window>"u")return null;const ee=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof ee=="number"&&Number.isFinite(ee)&&ee>0)return ee;if(typeof navigator>"u")return null;const ke=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ke)return null;const ae=Number.parseInt(ke[1],10),U=Number.parseInt(ke[2],10);return Number.isNaN(ae)?null:ae===10?U:ae},[]),de=a.useMemo(()=>X&&V||te?"pl-[5.5rem]":"pl-3",[X,V,te]),Fe=a.useMemo(()=>!X||!V||Z===null?"":Z>=26?"h-12":Z<=15?"h-14":"",[X,V,Z]),se=a.useCallback(async ee=>{ee.target.closest("button, a, input, select, textarea")||ee.button===0&&X&&await Og()},[X]);a.useEffect(()=>{if(!n)return;const ee=ke=>{ke.key==="Escape"&&(ke.preventDefault(),ke.stopPropagation(),n())};return window.addEventListener("keydown",ee,!0),()=>window.removeEventListener("keydown",ee,!0)},[n]);const[Q,Me]=a.useState(""),{isLoading:xe,isGitRepository:W}=qm(I),J=a.useRef(!1),ne=W===!0,oe=ne&&w;a.useEffect(()=>{if(W===!1){J.current=!0,N(!1);return}W===!0&&J.current&&(J.current=!1,N(!0))},[W]);const ue=al(ee=>ee.createMultiRun),Ae=al(ee=>ee.error),we=al(ee=>ee.clearError);a.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(ee=>{const ke=[...ee];return ke.length>0&&!ke[0].prompt.trim()&&(ke[0]={...ke[0],prompt:t}),ke})},[t]),a.useEffect(()=>{if(!G)return;let ee=!1;return j(!0),(async()=>{try{const ke=await Lg(G);ee||g(ke)}catch{}finally{ee||j(!1)}})(),()=>{ee=!0}},[G]);const Se=a.useCallback((ee,ke)=>{d(ae=>ae.map(U=>U.id===ee?{...U,...ke}:U))},[]),Le=a.useCallback(ee=>{d(ke=>ke.filter(ae=>ae.id!==ee))},[]),Ue=a.useCallback(()=>{d(ee=>[...ee,{id:ii(),prompt:"",models:[]}])},[]),be=async ee=>{const ke=ee.target.files;if(!ke)return;let ae=0;for(let U=0;U<ke.length;U++){const le=ke[U];if(le.size>PN){fe.error(o("multirun.launcher.toast.fileTooLarge",{fileName:le.name}));continue}try{const _e=await new Promise((De,ce)=>{const he=new FileReader;he.onload=()=>De(he.result),he.onerror=ce,he.readAsDataURL(le)});p(De=>[...De,{id:ii(),filename:le.name,mimeType:le.type||"application/octet-stream",size:le.size,dataUrl:_e}]),ae++}catch(_e){console.error("File attach failed",_e),fe.error(o("multirun.launcher.toast.attachFailed",{fileName:le.name}))}}ae>0&&fe.success(ae===1?o("multirun.launcher.toast.attachedSingle",{count:ae}):o("multirun.launcher.toast.attachedPlural",{count:ae})),v.current&&(v.current.value="")},q=ee=>{p(ke=>ke.filter(ae=>ae.id!==ee))},Ne=a.useMemo(()=>l.reduce((ee,ke)=>ee+ke.models.length,0),[l]),je=async ee=>{ee.preventDefault();const ke=l.filter(ae=>ae.prompt.trim()&&ae.models.length>=1);if(ke.length!==0&&!(Ne<1)){b(!0),we();try{B&&B!==E&&O(B);const ae=f.map(ce=>({mime:ce.mimeType,filename:ce.filename,url:ce.dataUrl})),U=S.filter(ce=>ce.trim().length>0),le=ke.map(ce=>({prompt:ce.prompt.trim(),models:ce.models.map(he=>({providerID:he.providerID,modelID:he.modelID,displayName:he.displayName,variant:he.variant}))})),_e={name:i.trim(),groups:le,agent:u||void 0,worktreeBaseBranch:oe?Q:void 0,isolateRuns:oe,files:ae.length>0?ae:void 0,setupCommands:U.length>0?U:void 0},De=await ue(_e);De&&(De.firstSessionId&&Je.getState().setCurrentSession(De.firstSessionId),e?.())}finally{b(!1)}}},ve=!!(i.trim()&&l.some(ee=>ee.prompt.trim()&&ee.models.length>=1)&&Ne>=1&&I&&!xe&&(W===!1||!oe||Q)),ie=S.filter(ee=>ee.trim()).length;return s.jsxs("form",{onSubmit:je,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:Pe("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",de,Fe),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:o("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":o("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(A,{name:"close",className:"h-5 w-5"})})}),s.jsx(Nt,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Sa,{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(to,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),M.length>0?s.jsxs(xn,{value:B??void 0,onValueChange:R,children:[s.jsx(bn,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:T?s.jsx(rn,{children:P(T)}):s.jsx(rn,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx(yn,{fitContent:!0,children:M.map(ee=>s.jsx(ys,{value:ee.id,className:"max-w-[24rem]",children:P(ee)},ee.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:o("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(to,{htmlFor:"group-name",required:!0,info:s.jsx(Yi,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(sr,{id:"group-name",value:i,onChange:ee=>c(ee.target.value),placeholder:o("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(to,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Yi,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(DN,{directory:I,value:Q,onChange:Me,disabled:!oe,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(oo,{checked:w,onChange:N,disabled:!ne,ariaLabel:o("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:o("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(to,{htmlFor:"multirun-agent",info:s.jsx(Yi,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(zm,{value:u,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(Fo,{open:m,onOpenChange:y,children:[s.jsxs(bi,{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(A,{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:o("multirun.launcher.setupCommands.label")}),ie>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:ie}),s.jsx(A,{name:"arrow-down-s",className:Pe("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",m&&"rotate-180")})]}),s.jsx(Oo,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:C?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:o("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[S.map((ee,ke)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(sr,{value:ee,onChange:ae=>{const U=[...S];U[ke]=ae.target.value,g(U)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>g(S.filter((ae,U)=>U!==ke)),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":o("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]},`${ee}-${ke}`)),s.jsxs("button",{type:"button",onClick:()=>g([...S,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(A,{name:"add",className:"h-3 w-3"}),o("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(to,{htmlFor:"prompt",required:!0,children:o("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:v,type:"file",multiple:!0,className:"hidden",onChange:be,accept:"*/*"}),s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>v.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(A,{name:"attachment-2",className:"h-3 w-3"}),o("multirun.launcher.attachments.attach")]})}),s.jsx(Nt,{children:o("multirun.launcher.attachments.tooltip")})]}),f.map(ee=>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:[ee.mimeType.startsWith("image/")?s.jsx(A,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(A,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:ee.filename,children:ee.filename}),s.jsx("button",{type:"button",onClick:()=>q(ee.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(A,{name:"close",className:"h-3 w-3"})})]},ee.id))]})]}),l.map((ee,ke)=>s.jsx(IN,{group:ee,groupIndex:ke,canRemove:l.length>1,onUpdate:Se,onRemove:Le},ee.id)),s.jsxs("button",{type:"button",onClick:Ue,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),o("multirun.launcher.groups.addGroup")]}),Ae&&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:Ae})]})})}),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:[!oe&&W!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(A,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:o("multirun.launcher.project.gitRequired")})]}):null,!r&&n?s.jsx(He,{type:"button",variant:"ghost",size:"sm",onClick:n,children:o("multirun.launcher.actions.cancel")}):null,s.jsx(He,{type:"submit",size:"sm",disabled:!ve||x,children:x?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:Ne})})})]})})]})},IN=t=>{const e=ot.c(99),{group:n,groupIndex:r,canRemove:o,onUpdate:i,onRemove:c}=t,{t:l}=ft(),[d,u]=a.useState(!1),[h,f]=a.useState(""),[p,x]=a.useState(!1),[b,S]=a.useState(""),[g,m]=a.useState(!1),[y,C]=a.useState(""),j=a.useRef(null),w=a.useRef(null),N=a.useRef(null),v=a.useRef(null);let D;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(D=U=>{n.models.length>=ll||i(n.id,{models:[...n.models,U]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=D):D=e[3];const F=D;let k;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(k=U=>{i(n.id,{models:n.models.filter((le,_e)=>_e!==U)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=k):k=e[7];const E=k;let O;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(O=(U,le)=>{i(n.id,{models:n.models.map((_e,De)=>De===U?le:_e)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=O):O=e[11];const M=O;let B;e[12]===Symbol.for("react.memo_cache_sentinel")?(B=(U,le)=>{if(U.startsWith("/")){const he=U.indexOf(" "),me=U.indexOf(`
|
|
206
|
+
`),$=Math.min(he===-1?U.length:he,me===-1?U.length:me);if(le<=$&&he===-1){S(U.substring(1,$)),x(!0),u(!1),m(!1);return}}x(!1);const _e=U.substring(0,le),De=_e.lastIndexOf("#");if(De!==-1){const he=De>0?_e[De-1]:null,me=_e.substring(De+1);if((!he||/\s/.test(he))&&!me.includes(" ")&&!me.includes(`
|
|
207
|
+
`)){C(me),m(!0),u(!1);return}}m(!1);const ce=_e.lastIndexOf("@");if(ce!==-1){const he=ce>0?_e[ce-1]:null,me=_e.substring(ce+1);(!he||/\s/.test(he))&&!me.includes(" ")&&!me.includes(`
|
|
208
|
+
`)?(f(me),u(!0)):u(!1);return}u(!1)},e[12]=B):B=e[12];const z=B;let T;e[13]!==n.id||e[14]!==i?(T=U=>{i(n.id,{prompt:U})},e[13]=n.id,e[14]=i,e[15]=T):T=e[15];const I=T;let R;e[16]!==n.prompt||e[17]!==I?(R=U=>{const le=n.prompt,De=j.current?.selectionStart??le.length,he=le.substring(0,De).lastIndexOf("@"),me=U.relativePath&&U.relativePath.trim().length>0?U.relativePath.trim():U.path||U.name,$=he!==-1?he:De,_=`${le.substring(0,$)}@${me} ${le.substring(De)}`,ge=$+me.length+2;I(_),u(!1),f(""),requestAnimationFrame(()=>{const Ie=j.current;Ie&&(Ie.selectionStart=ge,Ie.selectionEnd=ge,Ie.focus()),z(_,ge)})},e[16]=n.prompt,e[17]=I,e[18]=R):R=e[18];const L=R;let P;e[19]!==n.prompt||e[20]!==I?(P=U=>{const le=n.prompt,De=j.current?.selectionStart??le.length,he=le.substring(0,De).lastIndexOf("@"),me=he!==-1?he:De,$=`${le.substring(0,me)}@${U} ${le.substring(De)}`,_=me+U.length+2;I($),u(!1),f(""),requestAnimationFrame(()=>{const ge=j.current;ge&&(ge.selectionStart=_,ge.selectionEnd=_,ge.focus()),z($,_)})},e[19]=n.prompt,e[20]=I,e[21]=P):P=e[21];const G=P;let X;e[22]!==I?(X=U=>{const le=`/${U.name} `;I(le),x(!1),S(""),m(!1),requestAnimationFrame(()=>{const _e=j.current;_e&&(_e.focus(),_e.selectionStart=_e.value.length,_e.selectionEnd=_e.value.length),z(le,le.length)})},e[22]=I,e[23]=X):X=e[23];const V=X;let te;e[24]!==n.prompt||e[25]!==I?(te=(U,le)=>{const _e=n.prompt,ce=j.current?.selectionStart??_e.length,me=_e.substring(0,ce).lastIndexOf("#"),$=me!==-1?me:ce,_=`${_e.substring(0,$)}#${le} ${_e.substring(ce)}`,ge=$+le.length+2;I(_),m(!1),C(""),requestAnimationFrame(()=>{const Ie=j.current;Ie&&(Ie.selectionStart=ge,Ie.selectionEnd=ge,Ie.focus()),z(_,ge)})},e[24]=n.prompt,e[25]=I,e[26]=te):te=e[26];const Z=te;let de;e[27]!==p||e[28]!==d||e[29]!==g?(de=U=>{if(p&&N.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")){U.preventDefault(),N.current.handleKeyDown(U.key);return}d&&w.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),w.current.handleKeyDown(U.key)),g&&v.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),v.current.handleKeyDown(U.key))},e[27]=p,e[28]=d,e[29]=g,e[30]=de):de=e[30];const Fe=de,se=r+1;let Q;e[31]!==l||e[32]!==se?(Q=l("multirun.launcher.groups.groupLabel",{index:se}),e[31]=l,e[32]=se,e[33]=Q):Q=e[33];let Me;e[34]!==Q?(Me=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:Q}),e[34]=Q,e[35]=Me):Me=e[35];let xe;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==l?(xe=o&&s.jsx("button",{type:"button",onClick:()=>c(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":l("multirun.launcher.groups.removeGroup"),children:s.jsx(A,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=o,e[37]=n.id,e[38]=c,e[39]=l,e[40]=xe):xe=e[40];let W;e[41]!==Me||e[42]!==xe?(W=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Me,xe]}),e[41]=Me,e[42]=xe,e[43]=W):W=e[43];let J;e[44]!==l?(J=l("multirun.launcher.groups.prompt.label"),e[44]=l,e[45]=J):J=e[45];let ne;e[46]!==J?(ne=s.jsx(to,{required:!0,children:J}),e[46]=J,e[47]=ne):ne=e[47];const oe=n.prompt;let ue;e[48]!==I?(ue=U=>{const le=U.target.value;I(le);const _e=U.target.selectionStart??le.length;z(le,_e)},e[48]=I,e[49]=ue):ue=e[49];let Ae;e[50]!==l?(Ae=l("multirun.launcher.groups.prompt.placeholder"),e[50]=l,e[51]=Ae):Ae=e[51];let we;e[52]!==n.prompt||e[53]!==Fe||e[54]!==ue||e[55]!==Ae?(we=s.jsx(So,{ref:j,value:oe,onChange:ue,onKeyDown:Fe,placeholder:Ae,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=Fe,e[54]=ue,e[55]=Ae,e[56]=we):we=e[56];let Se;e[57]!==b||e[58]!==V||e[59]!==p?(Se=p?s.jsx(vf,{ref:N,searchQuery:b,onCommandSelect:V,onClose:()=>x(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=b,e[58]=V,e[59]=p,e[60]=Se):Se=e[60];let Le;e[61]!==G||e[62]!==L||e[63]!==h||e[64]!==d?(Le=d?s.jsx(jf,{ref:w,searchQuery:h,onFileSelect:L,onAgentSelect:G,onClose:()=>u(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=G,e[62]=L,e[63]=h,e[64]=d,e[65]=Le):Le=e[65];let Ue;e[66]!==Z||e[67]!==g||e[68]!==y?(Ue=g?s.jsx(Sf,{ref:v,searchQuery:y,onSnippetSelect:Z,onClose:()=>m(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=Z,e[67]=g,e[68]=y,e[69]=Ue):Ue=e[69];let be;e[70]!==we||e[71]!==Se||e[72]!==Le||e[73]!==Ue?(be=s.jsxs("div",{className:"relative",children:[we,Se,Le,Ue]}),e[70]=we,e[71]=Se,e[72]=Le,e[73]=Ue,e[74]=be):be=e[74];let q;e[75]!==ne||e[76]!==be?(q=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ne,be]}),e[75]=ne,e[76]=be,e[77]=q):q=e[77];let Ne;e[78]!==l?(Ne=l("multirun.launcher.models.info",{max:ll}),e[78]=l,e[79]=Ne):Ne=e[79];let je;e[80]!==Ne?(je=s.jsx(Yi,{children:Ne}),e[80]=Ne,e[81]=je):je=e[81];let ve;e[82]!==l?(ve=l("multirun.launcher.models.label"),e[82]=l,e[83]=ve):ve=e[83];let ie;e[84]!==je||e[85]!==ve?(ie=s.jsx(to,{required:!0,info:je,children:ve}),e[84]=je,e[85]=ve,e[86]=ie):ie=e[86];let ee;e[87]!==n.models||e[88]!==F||e[89]!==E||e[90]!==M?(ee=s.jsx(Vm,{selectedModels:n.models,onAdd:F,onRemove:E,onUpdate:M,minModels:1,maxModels:ll}),e[87]=n.models,e[88]=F,e[89]=E,e[90]=M,e[91]=ee):ee=e[91];let ke;e[92]!==ie||e[93]!==ee?(ke=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ie,ee]}),e[92]=ie,e[93]=ee,e[94]=ke):ke=e[94];let ae;return e[95]!==W||e[96]!==q||e[97]!==ke?(ae=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[W,q,ke]}),e[95]=W,e[96]=q,e[97]=ke,e[98]=ae):ae=e[98],ae},RN=a.createContext(null),MN=t=>{const e=ot.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(RN.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},TN=Da(()=>Bo(()=>import("./DiagramView-DZmf30ko.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117])).then(t=>({default:t.DiagramView}))),EN=Da(()=>Bo(()=>import("./runtimeEndpointReset-DKzVWH1w.js").then(t=>t.al),__vite__mapDeps([110,1,2,8,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,111,112,113,114,115,116])).then(t=>({default:t.SettingsView}))),FN=Da(()=>Bo(()=>import("./SettingsWindow-UybkBD1p.js"),__vite__mapDeps([118,1,2,8,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,110,111,112,113,114,115,116])).then(t=>({default:t.SettingsWindow}))),ON=()=>{const t=Ee(T=>T.isSidebarOpen),e=Ee(T=>T.activeMainTab),n=Ee(T=>T.setIsMobile),r=Ee(T=>T.isSessionSwitcherOpen),o=Ee(T=>T.isSettingsDialogOpen),i=Ee(T=>T.setSettingsDialogOpen),c=Ee(T=>T.isMultiRunLauncherOpen),l=Ee(T=>T.setMultiRunLauncherOpen),d=Ee(T=>T.multiRunLauncherPrefillPrompt),u=Ee(T=>T.isScheduledTasksDialogOpen),h=Ee(T=>T.isArchivePageOpen),f=Ee(T=>T.worktreesPageProjectId),p=u||h||!!f||c;a.useEffect(()=>{const T=()=>Ee.getState().closeMainSurfaces(),I=Je.subscribe((L,P)=>{const G=!!L.currentSessionId&&L.currentSessionId!==P.currentSessionId,X=!!L.newSessionDraft?.open&&L.newSessionDraft!==P.newSessionDraft;(G||X)&&T()}),R=Ee.subscribe((L,P)=>{L.activeMainTab!==P.activeMainTab&&T()});return()=>{I(),R()}},[]);const{isMobile:x}=Dr(),b=a.useRef(!1),[S,g]=a.useState(!1),[m,y]=a.useState(!1),[C,j]=a.useState(!1),[w,N]=a.useState(!1),v=a.useCallback(T=>{g(T),Ee.getState().setSessionSwitcherOpen(T)},[]),D=a.useRef(typeof window>"u"?0:window.innerWidth),F=Zc(-D.current),k=$e.useRef(0),E=Zc(D.current),O=$e.useRef(0);$e.useEffect(()=>{x&&(k.current=window.innerWidth,O.current=window.innerWidth)},[x]),$e.useEffect(()=>{if(!x){j(!1);return}S&&j(!0),ed(F,S?0:-k.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[S,x,F]),$e.useEffect(()=>{if(!x){N(!1);return}m&&N(!0),ed(E,m?0:O.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[x,m,E]),$e.useEffect(()=>{if(x)return F.on("change",T=>{const I=k.current||D.current,R=S||T>-I+.5;j(L=>L===R?L:R)})},[x,F,S]),$e.useEffect(()=>{if(x)return E.on("change",T=>{const I=O.current||D.current,R=m||T<I-.5;N(L=>L===R?L:R)})},[x,m,E]),$e.useEffect(()=>{x&&!r&&S&&v(!1)},[r,x,S,v]),$e.useEffect(()=>{if(!x){b.current=!1;return}b.current||(b.current=!0,v(!1),y(!1))},[x,v]),$e.useEffect(()=>{if(!x||e!=="chat"||S||m||o)return;let T=!1,I;const R=L=>{I=window.setTimeout(()=>{if(T)return;const P=Je.getState(),G=Ee.getState();if(!(G.activeMainTab!=="chat"||G.isSettingsDialogOpen||P.currentSessionId||P.newSessionDraft?.open)){if(P.isLoading){R(250);return}P.openNewSessionDraft({automatic:!0})}},L)};return R(500),()=>{T=!0,I!==void 0&&window.clearTimeout(I)}},[e,x,o,S,m]),$e.useEffect(()=>{!x||!o||(v(!1),y(!1))},[x,o,v]),Ax(),a.useEffect(()=>{Ee.getState().isMobile!==x&&n(x)},[x,n]);const M=a.useCallback(()=>{S&&v(!1),y(!m)},[S,m,v]),B=a.useMemo(()=>{if(!x&&e!=="terminal"&&e!=="diagram")return null;switch(e){case"plan":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(Of,{})});case"git":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(kl,{isActive:!m})});case"diff":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(um,{})});case"terminal":return s.jsx(Lf,{});case"files":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(Vf,{})});case"context":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(Ff,{})});case"diagram":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(TN,{})});default:return null}},[e,x,m]),z=e==="chat";return s.jsx(Dx,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:Pe("main-content-safe-area",x?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[s.jsx(Fj,{}),s.jsx(j0,{}),s.jsx(C0,{}),s.jsx(M2,{}),x?s.jsxs(MN,{value:{leftDrawerOpen:S,rightDrawerOpen:m,toggleLeftDrawer:()=>{const T=!S;m&&y(!1),v(T)},toggleRightDrawer:M,leftDrawerX:F,rightDrawerX:E,leftDrawerWidth:k,rightDrawerWidth:O,setMobileLeftDrawerOpen:v,setRightSidebarOpen:y},children:[!o&&s.jsx(id,{onToggleLeftDrawer:()=>{const T=!S;m&&y(!1),v(T)},onToggleRightDrawer:()=>{M()},leftDrawerOpen:S,rightDrawerOpen:m}),s.jsx("div",{"data-page-scroll-lock":"true",className:Pe("flex flex-1 overflow-hidden relative",o&&"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:Pe("absolute inset-0",(!z||p)&&"invisible"),children:s.jsx(Cs,{children:s.jsx(bl,{active:z&&!o&&!p})})}),B&&s.jsx("div",{className:Pe("absolute inset-0",p&&"invisible"),children:s.jsx(Cs,{children:B})}),c&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Cs,{children:s.jsx(Ou,{initialPrompt:d,onCreated:()=>l(!1),onCancel:()=>l(!1)})})}),s.jsx(Cs,{children:s.jsx(Ru,{})}),s.jsx(Cs,{children:s.jsx(Mu,{})}),s.jsx(Cs,{children:s.jsx(Tu,{})}),s.jsx(td.div,{className:Pe("absolute inset-0 z-20 bg-sidebar",!C&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:F},"aria-hidden":!S,children:s.jsx(Cs,{children:s.jsx(bu,{mobileVariant:!0,isVisible:C})})}),w&&s.jsx(td.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:E},"aria-hidden":!m,children:s.jsx(Cs,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(kl,{isActive:m})})})})]})}),o&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Cs,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(EN,{onClose:()=>i(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx(ny,{}),s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsx(ey,{isOpen:t,isMobile:x,className:"border-border",topBar:s.jsx(ty,{}),children:s.jsx(bu,{isVisible:t})}),s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsx(id,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","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:Pe("absolute inset-0",(!z||p)&&"invisible"),children:s.jsx(Cs,{children:s.jsx(bl,{active:z&&!o&&!p})})}),B&&s.jsx("div",{className:Pe("absolute inset-0",p&&"invisible"),children:s.jsx(Cs,{children:B})}),c&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Cs,{children:s.jsx(Ou,{isWindowed:!0,initialPrompt:d,onCreated:()=>l(!1),onCancel:()=>l(!1)})})}),s.jsx(Cs,{children:s.jsx(Ru,{})}),s.jsx(Cs,{children:s.jsx(Mu,{})}),s.jsx(Cs,{children:s.jsx(Tu,{})})]}),s.jsx(yj,{})]})})}),s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(Cs,{children:s.jsx(kj,{})})})]})]})]}),s.jsx(a.Suspense,{fallback:null,children:s.jsx(FN,{open:o,onOpenChange:i})})]})]})})},LN=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`},pn=t=>{const e=ot.c(8),{label:n,value:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=o):o=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let c;e[3]!==r?(c=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=c):c=e[4];let l;return e[5]!==i||e[6]!==c?(l=s.jsxs("div",{className:"rounded-md p-2",style:o,children:[i,c]}),e[5]=i,e[6]=c,e[7]=l):l=e[7],l},Lu=t=>{const e=ot.c(43),{title:n,snapshot:r,emptyLabel:o}=t,{t:i}=ft();let c;if(e[0]!==o||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const l=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(_N,0),e[8]=r.entries,e[9]=d):d=e[9];const u=d;let h;e[10]!==n?(h=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=h):h=e[11];let f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(f=r.startedAt?LN(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=f):f=e[15];let p;e[16]!==f?(p=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:f}),e[16]=f,e[17]=p):p=e[17];let x;e[18]!==h||e[19]!==p?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h,p]}),e[18]=h,e[19]=p,e[20]=x):x=e[20];let b;e[21]!==i?(b=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=b):b=e[22];let S;e[23]!==r.entries.length||e[24]!==b?(S=s.jsx(pn,{label:b,value:r.entries.length}),e[23]=r.entries.length,e[24]=b,e[25]=S):S=e[25];let g;e[26]!==i?(g=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=g):g=e[27];let m;e[28]!==g||e[29]!==u?(m=s.jsx(pn,{label:g,value:u}),e[28]=g,e[29]=u,e[30]=m):m=e[30];let y;e[31]!==i?(y=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=y):y=e[32];let C;e[33]!==r.lastUpdatedAt||e[34]!==i?(C=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=C):C=e[35];let j;e[36]!==y||e[37]!==C?(j=s.jsx(pn,{label:y,value:C}),e[36]=y,e[37]=C,e[38]=j):j=e[38];let w;e[39]!==m||e[40]!==j||e[41]!==S?(w=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[S,m,j]}),e[39]=m,e[40]=j,e[41]=S,e[42]=w):w=e[42],c=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,w,l.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:o}):s.jsx(On,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:l.map(N=>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:N.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:i("memoryDebugPanel.metric.countValue",{value:N.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:N.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:N.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:N.total})})]})]},N.metric))})})]}),e[0]=o,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=c}else c=e[7];return c},BN=t=>{const e=ot.c(99),{onClose:n}=t,{t:r}=ft(),[o,i]=a.useState("memory"),[c,l]=a.useState("idle"),d=Je(zN),u=bf(VN),h=cf(),f=Bg(WN),p=sn(UN),[x,b]=a.useState(HN),[S,g]=a.useState(KN);let m;e[0]!==x.entries?(m=new Map,x.entries.forEach(ve=>{m.set(ve.metric,ve.count)}),e[0]=x.entries,e[1]=m):m=e[1];let y;e[2]!==m?(y=m.get("ui.message_list.render")??0,e[2]=m,e[3]=y):y=e[3];let C;e[4]!==m?(C=m.get("ui.message_list.render.streaming")??0,e[4]=m,e[5]=C):C=e[5];let j;e[6]!==m?(j=m.get("ui.chat_message.render")??0,e[6]=m,e[7]=j):j=e[7];let w;e[8]!==m?(w=m.get("ui.chat_message.render.streaming")??0,e[8]=m,e[9]=w):w=e[9];let N;e[10]!==m?(N=m.get("ui.chat_message.render.static_during_stream")??0,e[10]=m,e[11]=N):N=e[11];let v;e[12]!==m?(v=m.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=m,e[13]=v):v=e[13];let D;e[14]!==y||e[15]!==C||e[16]!==j||e[17]!==w||e[18]!==N||e[19]!==v?(D={messageListRender:y,messageListRenderStreaming:C,chatMessageRender:j,chatMessageRenderStreaming:w,chatMessageRenderStaticDuringStream:N,chatMessageRenderStaticOutsideActiveTurnDuringStream:v},e[14]=y,e[15]=C,e[16]=j,e[17]=w,e[18]=N,e[19]=v,e[20]=D):D=e[20];const F=D;let k,E;e[21]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const ve=()=>{b(Oi()),g(Li())};ve();const ie=window.setInterval(ve,500);return()=>window.clearInterval(ie)},E=[],e[21]=k,e[22]=E):(k=e[21],E=e[22]),a.useEffect(k,E);let O,M;e[23]!==c?(O=()=>{if(c==="idle")return;const ve=window.setTimeout(()=>{l("idle")},1500);return()=>window.clearTimeout(ve)},M=[c],e[23]=c,e[24]=O,e[25]=M):(O=e[24],M=e[25]),a.useEffect(O,M);let B=0,z=0,T=0;for(const ve of Object.keys(f)){const ie=f[ve]??[];z=z+ie.length;for(const ee of ie)ee.role==="user"?T=T+1:ee.role==="assistant"&&(B=B+1)}let I;e[26]!==B||e[27]!==z||e[28]!==T?(I={assistant:B,total:z,user:T},e[26]=B,e[27]=z,e[28]=T,e[29]=I):I=e[29];const R=I;let L;if(e[30]!==d||e[31]!==f||e[32]!==u||e[33]!==h||e[34]!==r){let ve;e[36]!==d||e[37]!==f||e[38]!==u||e[39]!==r?(ve=ie=>{const ee=f[ie.id]??[];let ke=0,ae=0;for(const le of ee)le.role==="user"?ae=ae+1:le.role==="assistant"&&(ke=ke+1);const U=u.get(ie.id);return{id:ie.id,title:ie.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:ke,messageCount:ee.length,userMessageCount:ae,isStreaming:U?.isStreaming||!1,isZombie:U?.isZombie||!1,backgroundCount:U?.backgroundMessageCount||0,lastAccessed:U?.lastAccessedAt||0,isCurrent:ie.id===d}},e[36]=d,e[37]=f,e[38]=u,e[39]=r,e[40]=ve):ve=e[40],L=h.map(ve).sort(GN),e[30]=d,e[31]=f,e[32]=u,e[33]=h,e[34]=r,e[35]=L}else L=e[35];const P=L;let G;e[41]!==f?(G=Object.keys(f),e[41]=f,e[42]=G):G=e[42];const X=G.length;let V;e[43]===Symbol.for("react.memo_cache_sentinel")?(V=async()=>{try{const ve={generatedAt:new Date().toISOString(),ui:Oi(),vscode:Li()};await navigator.clipboard.writeText(JSON.stringify(ve,null,2)),l("copied")}catch{l("error")}},e[43]=V):V=e[43];const te=V;let Z;e[44]===Symbol.for("react.memo_cache_sentinel")?(Z={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[44]=Z):Z=e[44];let de;e[45]!==o?(de=o==="memory"?s.jsx(A,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(A,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[45]=o,e[46]=de):de=e[46];let Fe;e[47]!==r?(Fe=r("memoryDebugPanel.title"),e[47]=r,e[48]=Fe):Fe=e[48];let se;e[49]!==Fe?(se=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:Fe}),e[49]=Fe,e[50]=se):se=e[50];let Q;e[51]!==de||e[52]!==se?(Q=s.jsxs("div",{className:"flex items-center gap-2",children:[de,se]}),e[51]=de,e[52]=se,e[53]=Q):Q=e[53];let Me;e[54]!==o?(Me=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(He,{size:"xs",variant:"ghost",onClick:te,children:s.jsx(A,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(He,{size:"xs",variant:"ghost",onClick:()=>{Eh(),b(Oi()),g(Li())},children:s.jsx(A,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[54]=o,e[55]=Me):Me=e[55];let xe;e[56]!==n?(xe=n?s.jsx(He,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(A,{name:"close",className:"h-4 w-4"})}):null,e[56]=n,e[57]=xe):xe=e[57];let W;e[58]!==Me||e[59]!==xe?(W=s.jsxs("div",{className:"flex items-center gap-1",children:[Me,xe]}),e[58]=Me,e[59]=xe,e[60]=W):W=e[60];let J;e[61]!==Q||e[62]!==W?(J=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[Q,W]}),e[61]=Q,e[62]=W,e[63]=J):J=e[63];let ne;e[64]===Symbol.for("react.memo_cache_sentinel")?(ne={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[64]=ne):ne=e[64];const oe=o==="memory"?"secondary":"ghost";let ue;e[65]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>i("memory"),e[65]=ue):ue=e[65];let Ae;e[66]!==r?(Ae=r("memoryDebugPanel.tabs.memory"),e[66]=r,e[67]=Ae):Ae=e[67];let we;e[68]!==oe||e[69]!==Ae?(we=s.jsx(He,{size:"sm",variant:oe,className:"flex-1",onClick:ue,children:Ae}),e[68]=oe,e[69]=Ae,e[70]=we):we=e[70];const Se=o==="streaming"?"secondary":"ghost";let Le;e[71]===Symbol.for("react.memo_cache_sentinel")?(Le=()=>i("streaming"),e[71]=Le):Le=e[71];let Ue;e[72]!==r?(Ue=r("memoryDebugPanel.tabs.streaming"),e[72]=r,e[73]=Ue):Ue=e[73];let be;e[74]!==Se||e[75]!==Ue?(be=s.jsx(He,{size:"sm",variant:Se,className:"flex-1",onClick:Le,children:Ue}),e[74]=Se,e[75]=Ue,e[76]=be):be=e[76];let q;e[77]!==we||e[78]!==be?(q=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:ne,children:[we,be]}),e[77]=we,e[78]=be,e[79]=q):q=e[79];let Ne;e[80]!==o||e[81]!==X||e[82]!==c||e[83]!==d||e[84]!==f||e[85]!==R||e[86]!==u||e[87]!==P||e[88]!==h||e[89]!==F||e[90]!==x||e[91]!==r||e[92]!==p||e[93]!==S?(Ne=o==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(pn,{label:r("memoryDebugPanel.metric.totalMessages"),value:R.total}),s.jsx(pn,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${X} / ${Wc.MAX_SESSIONS}`}),s.jsx(pn,{label:r("memoryDebugPanel.metric.userMessages"),value:R.user}),s.jsx(pn,{label:r("memoryDebugPanel.metric.assistantMessages"),value:R.assistant})]}),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:$g()})})]}),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:Wc.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:p})]})]}),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(On,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:P.map(ve=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:ve.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:ve.title}),ve.isStreaming?s.jsx(A,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,ve.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-muted-foreground)]",children:r("memoryDebugPanel.metric.roleMsgsValue",{assistant:ve.assistantMessageCount,user:ve.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:ve.messageCount})}),ve.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",ve.backgroundCount]}):null]})]},ve.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(St,{children:[s.jsx(kt,{asChild:!0,children:s.jsx(He,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:h.map(qN),currentSessionId:d,cachedSessions:Object.keys(f),messageRoleCounts:R,sessionMessageRoleCounts:P.map(YN),memoryStates:Object.fromEntries(u)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Nt,{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(c==="copied"?"memoryDebugPanel.streaming.copy.copied":c==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(He,{size:"xs",variant:"outline",onClick:te,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(pn,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(pn,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:S.entries.length}),s.jsx(pn,{label:r("memoryDebugPanel.metric.messageListRenders"),value:F.messageListRender}),s.jsx(pn,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:F.messageListRenderStreaming}),s.jsx(pn,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:F.chatMessageRender}),s.jsx(pn,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:F.chatMessageRenderStreaming}),s.jsx(pn,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:F.chatMessageRenderStaticDuringStream}),s.jsx(pn,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:F.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Lu,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),S.entries.length>0?s.jsx(Lu,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:S,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[80]=o,e[81]=X,e[82]=c,e[83]=d,e[84]=f,e[85]=R,e[86]=u,e[87]=P,e[88]=h,e[89]=F,e[90]=x,e[91]=r,e[92]=p,e[93]=S,e[94]=Ne):Ne=e[94];let je;return e[95]!==J||e[96]!==q||e[97]!==Ne?(je=s.jsxs(_g,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:Z,children:[J,q,Ne]}),e[95]=J,e[96]=q,e[97]=Ne,e[98]=je):je=e[98],je},$N=BN;function _N(t,e){return t+e.count}function zN(t){return t.currentSessionId}function VN(t){return t.sessionMemoryState}function WN(t){return t.message}function UN(t){return t.totalRequestCount}function HN(){return Oi()}function KN(){return Li()}function GN(t,e){return e.lastAccessed-t.lastAccessed}function qN(t){return{id:t.id,title:t.title}}function YN(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}const QN=()=>{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()??"":""},XN=async()=>{const t=QN()||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")},Bu="openchamber:menu-action",cl="openchamber:check-for-updates",JN=t=>{const e=Je(y=>y.openNewSessionDraft),n=Ee(y=>y.toggleCommandPalette),r=Ee(y=>y.setCommandPaletteOpen),o=Ee(y=>y.toggleHelpDialog),i=Ee(y=>y.toggleSidebar),c=Ee(y=>y.setSessionSwitcherOpen),l=Ee(y=>y.setActiveMainTab),d=Ee(y=>y.setSettingsDialogOpen),u=Ee(y=>y.setAboutDialogOpen),h=si(y=>y.checkForUpdates),{setThemeMode:f}=lo(),p=a.useRef(!1),x=a.useCallback(()=>{p.current||(p.current=!0,h().then(()=>{const{available:y,error:C}=si.getState();if(C){fe.error("Failed to check for updates",{description:C});return}y||fe.success("You are on the latest version")}).finally(()=>{p.current=!1}))},[h]),b=a.useCallback(()=>{Gn.requestDirectoryDialog()},[]),S=a.useCallback(y=>{const C=zg();if(C.length===0)return;const j=Je.getState().currentSessionId,w=C.findIndex(D=>D.id===j);let N=y>0?0:C.length-1;w>=0&&(N=(w+y+C.length)%C.length);const v=C[N];v&&(l("chat"),c(!1),Je.getState().setCurrentSession(v.id))},[l,c]),g=a.useCallback(y=>{const{activeProjectId:C,projects:j,setActiveProject:w}=ds.getState();if(j.length===0)return;const N=j.findIndex(F=>F.id===C);let v=y>0?0:j.length-1;N>=0&&(v=(N+y+j.length)%j.length);const D=j[v];D&&w(D.id)},[]),m=a.useCallback(y=>{switch(y){case"about":u(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":l("chat"),c(!1),e();break;case"new-worktree-session":l("chat"),c(!1),mf();break;case"change-workspace":b();break;case"toggle-right-sidebar":{const C=vs.getState().currentDirectory;if(!C)break;const j=Ee.getState(),w=wo(C),N=j.contextPanelByDirectory[w];N?.isOpen?j.closeContextPanel(w):N?.activeTabId?j.setActiveContextPanelTab(w,N.activeTabId):j.openContextSurface(w,"git");break}case"open-right-sidebar-git":{const C=vs.getState().currentDirectory;if(!C)break;Ee.getState().openContextSurface(wo(C),"git");break}case"open-right-sidebar-files":{const C=vs.getState().currentDirectory;if(!C)break;Ee.getState().openContextSurface(wo(C),"file");break}case"toggle-terminal":{const C=vs.getState().currentDirectory;if(!C)break;Ee.getState().openContextSurface(wo(C),"terminal");break}case"toggle-terminal-expanded":{const C=vs.getState().currentDirectory;if(!C)break;const j=wo(C),w=Ee.getState(),N=w.contextPanelByDirectory[j];(N?.isOpen?N.tabs.find(D=>D.id===N.activeTabId)?.mode:null)!=="terminal"&&w.openContextSurface(j,"terminal"),w.toggleContextPanelExpanded(j);break}case"copy":{const C=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(C)||XN();break}case"theme-light":f("light");break;case"theme-dark":f("dark");break;case"theme-system":f("system");break;case"add-selection-to-chat":Wg();break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"go-back":vs.getState().goBack();break;case"go-forward":vs.getState().goForward();break;case"previous-session":S(-1);break;case"next-session":S(1);break;case"previous-project":g(-1);break;case"next-project":g(1);break;case"help-dialog":o();break;case"download-logs":{Vg().catch(()=>{fe.error("Failed to collect OpenCode status")});break}}},[b,g,S,t,e,u,l,c,r,d,f,n,o,i]);a.useEffect(()=>{const y=j=>{const w=j.detail;w&&m(w)},C=()=>{x()};return window.addEventListener(Bu,y),window.addEventListener(cl,C),()=>{window.removeEventListener(Bu,y),window.removeEventListener(cl,C)}},[m,x]),a.useEffect(()=>{if(typeof window>"u")return;const C=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof C!="function")return;let j=null,w=null;return C("openchamber:menu-action",N=>{const v=N?.payload;typeof v=="string"&&m(v)}).then(N=>{j=N}).catch(()=>{}),C("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(cl))}).then(N=>{w=N}).catch(()=>{}),()=>{(async()=>{try{const v=j?.();v instanceof Promise&&await v}catch{}try{const v=w?.();v instanceof Promise&&await v}catch{}})()}},[m])},ZN="openchamber:tray-action",$u=5e3,eC=500,tC=45e3,Ym=20,_u=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},zu=()=>typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.trayEnabled!==!1,sC=t=>{const e=typeof t.permission=="string"?t.permission:"Permission",n=Array.isArray(t.patterns)?t.patterns.find(r=>typeof r=="string"&&r.trim()):"";return n?`${e}: ${n}`:e},nC=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},Qm=(t,e)=>Eo(t,e,ui.getState().ids,Na.getState().rankById),rC=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},oC=(t,e,n,r,o)=>{if(!t)return"";const i=qg(n,r,t),c=e.project?.name,l=i?.label?.trim()||c?.trim()||rC(t),d=_i(t);let u=d&&o.get(d)||"";if(!u){for(const[h,f]of nn.getState().directories)if(_i(h)===d){u=f.status?.current??"";break}}if(!u)for(const h of r.values()){const f=h.find(p=>_i(p.path)===d);if(f?.branch){u=f.branch;break}}return u?`${l} · ${u}`:l},iC=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=Ws.getState(),r=n==="remaining"?"remaining":"usage";if(!e.length)return{mode:r,groups:[]};const o=new Map(t.map(c=>[c.providerId,c])),i=[];for(const c of Df){if(!e.includes(c.id))continue;const l=o.get(c.id);if(!l||l.configured!==!0)continue;const d=[];for(const[h,f]of Object.entries(l.usage?.windows??{})){const p=r==="remaining"?f.remainingPercent:f.usedPercent;d.push({label:Bl(h),value:ci(f.valueLabel,p)})}const u=!l.ok&&l.error?l.error:d.length===0?"No rate limits reported":null;i.push({provider:c.name,rows:d,status:u})}return{mode:r,groups:i}},aC=async()=>{try{if(ua())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=Nr();if(e&&Qi(e,t))return"Local OpenChamber";const r=(await Gu()).hosts.find(o=>e?Qi(e,qu(o)):!1);return r?.label?.trim()?Yu(r.label.trim()):"Instance"}catch{return""}},lC=()=>{const t=new Map,e=new Map,n=[],r=new Map;let o;try{o=ta()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[i,c]of o.children.entries()){const l=c.getState();l.vcs?.branch&&e.set(_i(i)??i,l.vcs.branch);for(const d of l.session)d?.id&&r.set(d.id,d.title);for(const[d,u]of Object.entries(l.session_status??{})){const h=u?.type,f=h==="busy"?"busy":h==="retry"?"retry":"idle",p=t.get(d);(!p||p==="idle")&&t.set(d,f)}for(const[d,u]of Object.entries(l.permission??{}))for(const h of u??[]){if(!h?.id)continue;const f=h.sessionID||d;n.push({kind:"permission",id:h.id,sessionId:f,sessionTitle:"",label:sC(h),directory:i})}for(const[d,u]of Object.entries(l.question??{}))for(const h of u??[]){if(!h?.id)continue;const f=h.sessionID||d;n.push({kind:"question",id:h.id,sessionId:f,sessionTitle:"",label:nC(h),directory:i})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},cC=()=>{const t=gn.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(Qm).slice(0,Ym).forEach(r=>{const o=Bn(r);o&&e.add(o)});const n=new Map;for(const r of t){if(!r?.id)continue;const o=Bn(r);if(!o||!e.has(o))continue;const i=n.get(o)??[];i.push(r.id),n.set(o,i)}return n},dC=t=>{const e=lC(),n=Aa.getState().index.session,r=gn.getState().activeSessions,o=new Map(e.titleById),i=new Map;for(const g of r)if(g?.id&&(g.title&&o.set(g.id,g.title),g.parentID)){const m=i.get(g.parentID)??[];m.push(g.id),i.set(g.parentID,m)}const c=g=>{const m=[],y=[...i.get(g)??[]],C=new Set;for(;y.length;){const j=y.pop();C.has(j)||(C.add(j),m.push(j),y.push(...i.get(j)??[]))}return m},l=Ca.getState().statusById,d=g=>{const m=e.statusById.get(g);return m&&m!=="idle"?m:l.get(g)?.status.type??m??"idle"},u=g=>{const m=g.map(y=>d(y));return m.includes("busy")?"busy":m.includes("retry")?"retry":"idle"},h=ds.getState().projects,f=Je.getState().availableWorktreesByProject,p=r.filter(g=>g?.id&&!g.parentID).slice().sort(Qm).slice(0,Ym).map(g=>{const m=[g.id,...c(g.id)],y=Bn(g)??"";return{id:g.id,title:g.title||"Untitled session",status:u(m),branch:y?e.branchByDirectory.get(y)??"":"",unseen:m.reduce((C,j)=>C+(n.unseenCount[j]??0),0),hasError:m.some(C=>n.unseenHasError[C]??!1),directory:y,subtitle:oC(y,g,h,f,e.branchByDirectory)}}),x=e.approvals.map(g=>({...g,sessionTitle:o.get(g.sessionId)||""})),b=Ee.getState();let S=0;if(b.dockBadgeEnabled)for(const g of r){if(!g?.id||g.parentID)continue;let m=n.unseenCount[g.id]??0;m===0&&b.notifyOnSubtasks&&(m=c(g.id).reduce((y,C)=>y+(n.unseenCount[C]??0),0)),m>0&&(S+=1)}return{sessions:p,approvals:x,instanceName:t,usage:iC(),dockBadgeCount:S}},uC=()=>{a.useEffect(()=>{if(!_u()||!zu()||!ma())return;let t=!1,e="",n=null,r="";const o=()=>{if(t)return;const D=dC(r),F=JSON.stringify(D);F!==e&&(e=F,Cr("desktop_tray_update",D))};aC().then(D=>{t||(r=D,o())});const i=async()=>{const D=cC();await Promise.all([...D.entries()].map(async([F,k])=>{const E=await Fn.getSessionStatusForDirectory(F).catch(()=>null);t||E===null||Kg(F,E,k)}))},c=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,o()},eC))},l=new Map,d=()=>{if(t)return;let D;try{D=ta()}catch{return}const F=new Set;for(const[k,E]of D.children.entries())F.add(k),l.has(k)||l.set(k,E.subscribe(()=>c()));for(const[k,E]of l)F.has(k)||(E(),l.delete(k))};let u=null;try{u=ta().subscribeRegistry(()=>{d(),c()})}catch{}d();const h=Aa.subscribe(()=>c()),f=gn.subscribe(()=>c()),p=ds.subscribe(()=>c()),x=Je.subscribe(()=>c()),b=nn.subscribe(()=>c()),S=Ee.subscribe(()=>c()),g=Ca.subscribe(()=>c()),m=Na.subscribe(()=>c()),y=ui.subscribe(()=>c());Ug(Hg());const C=window.setInterval(()=>{ea()},tC);i();const j=window.setInterval(()=>{i()},$u),w=Ws.subscribe(()=>c());Ws.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:D,results:F}=Ws.getState();D.length>0&&D.some(E=>!F.some(O=>O.providerId===E))&&Ws.getState().fetchAllQuotas()});const N=window.setInterval(()=>{const D=Ws.getState();D.autoRefresh&&D.dropdownProviderIds.length>0&&D.fetchAllQuotas()},Math.max(3e4,Ws.getState().refreshIntervalMs||6e4)),v=window.setInterval(()=>{d(),o()},$u);return o(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(v),window.clearInterval(C),window.clearInterval(j),window.clearInterval(N),h(),f(),p(),x(),b(),S(),g(),m(),y(),w(),u?.();for(const D of l.values())D();l.clear()}},[]),a.useEffect(()=>{if(!_u()||!zu()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=o=>{o.type==="respond-permission"&&Gg(o.sessionId,o.id,o.response).catch(()=>{fe.error("Failed to respond to permission request")})};let r=null;return e(ZN,o=>{const i=o?.payload;!i||typeof i!="object"||typeof i.type!="string"||n(i)}).then(o=>{r=o}).catch(()=>{}),()=>{try{const o=r?.();o instanceof Promise&&o.catch(()=>{})}catch{}}},[])},fC="/api/notifications/stream",mC=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),hC=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},pC=t=>{const e=ot.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||ur()||!Ll()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(ha().sse(fC));return i.onmessage=gC,()=>{i.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),a.useEffect(r,o)};function gC(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Ee.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&mC())return;const r=hC(e);if(!r)return;fa()?.notifications?.notifyAgentCompletion(r)}const Vu="pwa-install-toast-shown",Wu="pwa-install-toast-dismissed",xC=()=>{const t=ot.c(6),{browserTab:e}=Px(),{t:n}=ft(),r=a.useRef(n);let o,i;t[0]!==n?(o=()=>{r.current=n},i=[n],t[0]=n,t[1]=o,t[2]=i):(o=t[1],i=t[2]),a.useEffect(o,i);let c,l;t[3]!==e?(c=()=>{if(typeof window>"u"||!Ll()||!e)return;let d=null,u=null;const h=()=>{u!==null&&(fe.dismiss(u),u=null)},f=async()=>{if(!d)return;const b=d;d=null,h(),await b.prompt();const{outcome:S}=await b.userChoice;S==="accepted"&&fe.success(r.current("pwa.installPrompt.started"))},p=b=>{const S=b;if(typeof S.prompt!="function")return;S.preventDefault(),d=S;const g=jo(),m=Fh();Ix({dismissed:g.getItem(Wu),sessionShown:m.getItem(Vu),hasActiveToast:u!==null})&&(m.setItem(Vu,"true"),u=fe.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{f()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{jo().setItem(Wu,"true"),h()}}}))},x=()=>{d=null,h(),fe.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",p),window.addEventListener("appinstalled",x),()=>{h(),window.removeEventListener("beforeinstallprompt",p),window.removeEventListener("appinstalled",x)}},l=[e],t[3]=e,t[4]=c,t[5]=l):(c=t[4],l=t[5]),a.useEffect(c,l)},bC=({open:t,onOpenChange:e})=>{const{t:n}=ft(),r=!1,[o,i]=a.useState(null),[c,l]=a.useState(null),[d,u]=a.useState(!1),[h,f]=a.useState(!1),[p,x]=a.useState(null),[b,S]=a.useState(!1);a.useCallback(async()=>{},[p,d,r,n]),a.useEffect(()=>{if(!t)return;(async()=>{try{const y=await us("/api/system/info");if(y.ok){const C=await y.json();if(typeof C.openchamberVersion=="string"&&C.openchamberVersion.trim()){i(C.openchamberVersion);return}}}catch{}i(await Yg())})()},[t]),a.useEffect(()=>{if(!t)return;let m=!1;return(async()=>{try{const C=await us("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!C.ok)return;const j=await C.json().catch(()=>null),w=typeof j?.currentVersion=="string"?j.currentVersion.trim():"";!m&&w&&l(w)}catch{}})(),()=>{m=!0}},[t]),a.useEffect(()=>{{x(null),S(!1);return}},[t,r]);const g=o;return s.jsx(Ps,{open:t,onOpenChange:e,children:s.jsx(Is,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(ql,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[g&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:g})}),c&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:c})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/openchamber/openchamber",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(A,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",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(A,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",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(A,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},dl=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},yC=(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 OpenChamber and click Authorize again.":n},wC=()=>{const t=Rx(i=>i.completeAuth),[e,n]=a.useState("working"),[r,o]=a.useState("Completing MCP authorization...");return a.useEffect(()=>{if(typeof window>"u"){n("error"),o("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),c=dl(i,"code"),l=Mx(i),d=Tx(i),u=dl(i,"error"),h=dl(i,"error_description");if(u){d&&us(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(h??u);return}(async()=>{try{if(!c)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let f=l;if(!f&&d){const p=await us(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(p.ok){const x=await p.json().catch(()=>null);x?.name?.trim()&&(f={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!f?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(f.name,c,f.directory),d&&await us(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),o("Authorization completed. You can close this tab and return to OpenChamber.")}catch(f){d&&await us(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(yC(f,"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("h1",{className:Ex,children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"}),s.jsx("p",{className:Pe("typography-body",e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]"),children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(He,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},Uu=Da(()=>Bo(()=>import("./OnboardingScreen-ChYr0xqs.js"),__vite__mapDeps([119,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108])).then(t=>({default:t.OnboardingScreen}))),vC=()=>{const t=ot.c(3),e=Ee(AC),n=Ee(DC);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(bC,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},jC=t=>{const e=ot.c(21),{onRetry:n,isRetrying:r}=t,{t:o}=ft();let i;e[0]!==o?(i=o("startup.initRecovery.title"),e[0]=o,e[1]=i):i=e[1];let c;e[2]!==i?(c=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let l;e[4]!==o?(l=o("startup.initRecovery.description"),e[4]=o,e[5]=l):l=e[5];let d;e[6]!==l?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:l}),e[6]=l,e[7]=d):d=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsxs("div",{className:"flex flex-col gap-2",children:[c,d]}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let h;e[11]!==r||e[12]!==o?(h=o(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=o,e[13]=h):h=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==h?(f=s.jsx(He,{type:"button",onClick:n,disabled:r,children:h}),e[14]=r,e[15]=n,e[16]=h,e[17]=f):f=e[17];let p;return e[18]!==u||e[19]!==f?(p=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:[u,f]})}),e[18]=u,e[19]=f,e[20]=p):p=e[20],p},Hu=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",SC=()=>{if(typeof window>"u"||!Yx())return null;const t=new URLSearchParams(window.location.search),e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),o=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:o,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true"}},kC=()=>typeof window>"u"?!1:window.location.pathname===Bx,NC=t=>{const e=ot.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,i=vs(PC),c=Je(IC),l=Je(RC),d=pa(),u=a.useRef(null);let h;e[0]!==n.directory?(h=Hu(n.directory),e[0]=n.directory,e[1]=h):h=e[1];const f=h;let p;e[2]!==i?(p=Hu(i),e[2]=i,e[3]=p):p=e[3];const x=p;let b,S;if(e[4]!==x||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==l||e[11]!==d?(b=()=>{if(r||f&&x!==f)return;const w=`${f}
|
|
209
|
+
${n.sessionId}`;u.current===w&&c||(u.current=w,l(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},S=[x,c,n.directory,n.sessionId,f,r,l,d],e[4]=x,e[5]=c,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=l,e[11]=d,e[12]=b,e[13]=S):(b=e[12],S=e[13]),a.useEffect(b,S),f&&x!==f)return null;let g;e[14]!==o?(g=s.jsx(kf,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=g):g=e[15];let m;e[16]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx($f,{}),e[16]=m):m=e[16];let y;e[17]!==n.readOnly?(y=s.jsx(bl,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=y):y=e[18];let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Nf,{}),e[19]=C):C=e[19];let j;return e[20]!==g||e[21]!==y?(j=s.jsxs(s.Fragment,{children:[g,m,y,C]}),e[20]=g,e[21]=y,e[22]=j):j=e[22],j};function CC({apis:t}){a.useEffect(()=>{Oh("App:mounted"),Lh()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=rs(W=>W.initializeApp),n=rs(W=>W.isInitialized),r=rs(W=>W.isConnected),o=rs(W=>W.providers.length),i=rs(W=>W.agents.length),c=rs(W=>W.loadProviders),l=rs(W=>W.loadAgents),d=Je(W=>W.error),u=Je(W=>W.clearError),h=vs(W=>W.currentDirectory),f=vs(W=>W.setDirectory),p=vs(W=>W.isSwitchingDirectory),[x,b]=a.useState(!1),S=Ar(W=>W.refreshStatus),[g,m]=a.useState(()=>t.runtime.isVSCode),[y,C]=a.useState(!0),[j,w]=a.useState(!1),[N,v]=a.useState(0),[D,F]=a.useState(0),[k,E]=a.useState(!1),O=Ee(W=>W.wideChatLayoutEnabled),M=Ee(W=>W.mobileKeyboardMode),B=a.useMemo(()=>ur(),[]),z=zl(W=>W.setPlanModeEnabled),[T,I]=a.useState(()=>Dc()),[R,L]=a.useState(()=>{const W=Pc();return W!==null?Ic({isDesktopShell:!0,bootOutcome:W}):null}),P=a.useRef(!1),G=a.useMemo(()=>SC(),[]),X=!G||y,V=a.useMemo(()=>kC(),[]);a.useEffect(()=>(Rc(x),()=>{Rc(!1)}),[x]),a.useEffect(()=>{Bh(M)},[M]),a.useEffect(()=>{m(t.runtime.isVSCode)},[t.runtime.isVSCode]),a.useEffect(()=>Ju(W=>{Fx(W),F(J=>J+1),w(!1),v(J=>J+1)}),[]);const te=Uc(W=>{const J=$n();return Object.values(W.runsByOriginalSessionID).filter(ne=>ne.status==="running"&&ne.runtimeKey===J).map(ne=>`${ne.originalSessionID}:${ne.phase}:${ne.lastForwardedMessageID??""}:${ne.expectedAssistantParentID??""}`).sort().join("|")});a.useEffect(()=>{if(G)return;const W=$n(),J=Object.values(Uc.getState().runsByOriginalSessionID).filter(ne=>ne.status==="running"&&ne.runtimeKey===W);for(const ne of J)Qg(ne.originalSessionID)},[te,G,D]),a.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",O),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[O]),a.useEffect(()=>(Mc(t),()=>Mc(null)),[t]),a.useEffect(()=>{G||S(t.github,{force:!0})},[t.github,G,S]),Xg();const Z=T==="valid",de=R?.screen==="main";a.useEffect(()=>{if(!$h({isDesktopShell:B,isInitialized:n,bootOutcomeKnown:Z,bootViewIsMain:de}))return;const W=setTimeout(()=>{const J=document.getElementById("initial-loading");J&&(J.classList.add("fade-out"),setTimeout(()=>{J.remove()},300))},150);return()=>clearTimeout(W)},[B,n,Z,de]),a.useEffect(()=>{if(!B||T!=="malformed")return;const W=document.getElementById("initial-loading");W&&(W.textContent="Desktop startup failed — please restart the app.")},[B,T]),a.useEffect(()=>{if(B)return;const W=setTimeout(()=>{const J=document.getElementById("initial-loading");J&&!n&&(J.classList.add("fade-out"),setTimeout(()=>{J.remove()},300))},5e3);return()=>clearTimeout(W)},[B,n]),a.useEffect(()=>{let W=!1;return(async()=>{const ne=await us("/health",{method:"GET"}).catch(()=>null);if(!ne||!ne.ok||W)return;const oe=await ne.json().catch(()=>null);if(!oe||W)return;const ue=oe.planModeExperimentalEnabled;z(ue===!0||ue===1||ue==="1"||ue==="true")})(),()=>{W=!0}},[z]),a.useEffect(()=>{g||e()},[e,g]),a.useEffect(()=>{if(g||n)return;let W=!0,J,ne=0;const oe=10,ue=1e3,Ae=async()=>{if(!W)return;if(ne>=oe){w(!0);return}const we=rs.getState();if(we.isInitialized){w(!1);return}ne+=1,await we.initializeApp();const Se=rs.getState();if(!W)return;if(Se.isInitialized){w(!1);return}if(ne>=oe){w(!0);return}const Le=Math.min(ue*Math.pow(2,ne-1),16e3);J=setTimeout(Ae,Le)};return J=setTimeout(Ae,ue),()=>{W=!1,J&&clearTimeout(J)}},[N,n,g]),a.useEffect(()=>{n&&w(!1)},[n]),a.useEffect(()=>{if(!j)return;const W=document.getElementById("initial-loading");W&&(W.classList.add("fade-out"),setTimeout(()=>{W.remove()},300))},[j]),a.useEffect(()=>{if(g||!r||o>0&&i>0)return;let W=!0,J=0;const ne=15,oe=async()=>{const Ae=rs.getState();if(!(Ae.providers.length>0&&Ae.agents.length>0))try{Ae.providers.length===0&&await c({source:"startupRecovery"}),rs.getState().agents.length===0&&await l({source:"startupRecovery"})}catch{}};oe();const ue=setInterval(()=>{if(W){if(++J>=ne){clearInterval(ue);return}oe()}},2e3);return()=>{W=!1,clearInterval(ue)}},[r,g,l,c,o,i]),a.useEffect(()=>{p||g||r&&Fn.setDirectory(h)},[h,p,r,g]),a.useEffect(()=>{if(!G||typeof window>"u")return;const W=oe=>{const ue=oe?.visible===!0;C(ue)},J=oe=>{if(oe.origin!==window.location.origin)return;const ue=oe.data;ue?.type==="openchamber:embedded-visibility"&&W(ue.payload)},ne=window;return ne.__openchamberSetEmbeddedVisibility=W,window.addEventListener("message",J),()=>{window.removeEventListener("message",J),ne.__openchamberSetEmbeddedVisibility===W&&delete ne.__openchamberSetEmbeddedVisibility}},[G]),a.useEffect(()=>{!G?.directory||g||h!==G.directory&&f(G.directory,{showOverlay:!1})},[h,G,g,f]),a.useEffect(()=>{if(!G||typeof window>"u")return;const W=J=>{J.storageArea===window.localStorage&&J.key==="ui-store"&&Ee.persist.rehydrate()};return window.addEventListener("storage",W),()=>{window.removeEventListener("storage",W)}},[G]),a.useEffect(()=>{if(typeof window>"u")return;const W=J=>{const ne=J.detail,oe=typeof ne?.sessionId=="string"?ne.sessionId.trim():"";if(!oe)return;const ue=typeof ne?.directory=="string"&&ne.directory.trim().length>0?ne.directory.trim():null;Ee.getState().setActiveMainTab("chat"),Je.getState().setCurrentSession(oe,ue)};return window.addEventListener("openchamber:open-session",W),()=>window.removeEventListener("openchamber:open-session",W)},[]),a.useEffect(()=>{if(typeof window>"u")return;const W=()=>{const J=vs.getState().currentDirectory,{activeProjectId:ne,projects:oe}=ds.getState(),ue=oe.find(Ae=>Ae.id===ne)??null;Cr("desktop_open_draft_mini_chat_window",{directory:J||ue?.path||"",projectId:ue?.id??null})};return window.addEventListener("openchamber:open-mini-chat",W),()=>window.removeEventListener("openchamber:open-mini-chat",W)},[]),a.useEffect(()=>{if(typeof window>"u")return;const W=()=>{const J=Je.getState().currentSessionId;J&&df(J)};return window.addEventListener("focus",W),()=>window.removeEventListener("focus",W)},[]),a.useEffect(()=>{if(typeof window>"u")return;const W=J=>{const ne=J.detail,oe=typeof ne?.directory=="string"&&ne.directory.trim().length>0?ne.directory.trim():null,ue=typeof ne?.projectId=="string"&&ne.projectId.trim().length>0?ne.projectId.trim():null;Ee.getState().setActiveMainTab("chat"),Ee.getState().setSessionSwitcherOpen(!1),Je.getState().openNewSessionDraft({selectedProjectId:ue,directoryOverride:oe,preserveDirectoryOverride:!!oe})};return window.addEventListener("openchamber:open-draft-session",W),()=>window.removeEventListener("openchamber:open-draft-session",W)},[]),a.useEffect(()=>{typeof window>"u"||!n||p||P.current||(P.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,p]),Jg({enabled:X}),pC({enabled:X}),xC(),Zg(),Ox();const Fe=a.useCallback(()=>{b(W=>!W)},[]);JN(Fe),uC(),a.useEffect(()=>{if(G)return;const W=J=>{af(J)&&J.shiftKey&&!J.altKey&&(J.code==="KeyD"||J.key.toLowerCase()==="d")&&(J.preventDefault(),b(oe=>!oe))};return window.addEventListener("keydown",W,!0),()=>window.removeEventListener("keydown",W,!0)},[G]),a.useEffect(()=>{G||d&&setTimeout(()=>u(),5e3)},[u,G,d]),a.useEffect(()=>{if(!B||T!=="not-injected")return;let W=!1,J=0;const ne=200,oe=2e3,ue=50,Ae=()=>{if(W)return;J++;const we=Dc();if(we!=="not-injected"){if(W=!0,I(we),we==="valid"){const Le=Pc();Le&&L(Ic({isDesktopShell:!0,bootOutcome:Le}))}return}const Se=Math.min(ne*Math.pow(1.1,J),oe);if(J>=ue){const Le=document.getElementById("initial-loading");Le&&!Le.textContent?.includes("taking longer")&&(Le.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(Ae,Se)};return window.setTimeout(Ae,ne),()=>{W=!0}},[B,T]);const se=a.useCallback(async()=>{if(_h({isDesktopShell:ur(),isDesktopLocalOriginActive:ua()})){await zh();return}window.location.reload()},[]),Q=a.useCallback(async()=>{if(!k){w(!1),E(!0);try{await rs.getState().initializeApp()}finally{E(!1)}rs.getState().isInitialized||v(W=>W+1)}},[k]),Me=W=>{if(W.screen==="recovery")return W.variant};if(B&&R&&R.screen!=="main"){if(R.screen==="chooser")return s.jsx(Cs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(a.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Uu,{mode:"first-launch",localAvailable:R.localAvailable!==!1,onCliAvailable:se,onChooseRemote:()=>{}})})})});const W=Me(R),J=R.screen==="recovery"&&"url"in R?R.url:void 0;return s.jsx(Cs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(a.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Uu,{mode:"recovery",recoveryVariant:W,recoveryHostUrl:J,recoveryHostLabel:void 0,localAvailable:R.localAvailable!==!1,onCliAvailable:se})})})})}if(G)return s.jsx(Cs,{children:s.jsx(Hc,{sdk:Fn.getSdkClient(),directory:h||"",children:s.jsx(Kc,{apis:t,children:s.jsx(gl,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(NC,{embeddedSessionChat:G,isVSCodeRuntime:g,embeddedBackgroundWorkEnabled:X})})})})},D)});if(V)return s.jsx(Cs,{children:s.jsx(wC,{})});if(j&&!n&&!g&&!G)return s.jsx(Cs,{children:s.jsx(jC,{onRetry:()=>{Q()},isRetrying:k})});const xe=!n&&!B;return s.jsx(Cs,{children:s.jsx(Hc,{sdk:Fn.getSdkClient(),directory:h||"",children:s.jsx(Kc,{apis:t,children:s.jsx(Qy,{children:s.jsx(gl,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:B?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(kf,{embeddedBackgroundWorkEnabled:X}),s.jsx($f,{}),s.jsx(ON,{}),s.jsx(Nf,{}),!xe&&s.jsxs(s.Fragment,{children:[s.jsx(Lx,{}),s.jsx(vC,{}),x&&s.jsx($N,{onClose:()=>b(!1)})]})]})})})})},D)})}function AC(t){return t.isAboutDialogOpen}function DC(t){return t.setAboutDialogOpen}function PC(t){return t.currentDirectory}function IC(t){return t.currentSessionId}function RC(t){return t.setCurrentSession}const MC=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();ex();Vh().then(()=>{Promise.all([Wh(),tx()]).catch(t=>{console.error("[main] settings init failed:",t)}),sx(),nx(),rx()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Xm=document.getElementById("root");if(!Xm)throw new Error("Root element not found");Sh.createRoot(Xm).render(s.jsx($e.StrictMode,{children:s.jsx(ox,{children:s.jsx(ix,{children:s.jsx(ax,{children:s.jsx(lx,{children:s.jsx(CC,{apis:MC})})})})})}));
|